Skip to content

Commit

Permalink
feat: expose createTrpcClient in popup/options
Browse files Browse the repository at this point in the history
  • Loading branch information
tmkx committed Apr 19, 2024
1 parent cb31d23 commit 54c92e2
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"access": "public",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
"ignore": ["@webx-kit/app-*"]
}
6 changes: 6 additions & 0 deletions packages/messaging/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @webx-kit/messaging

## 0.0.2

### Patch Changes

- feat: expose `createTrpcClient` in popup/options

## 0.0.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/messaging/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@webx-kit/messaging",
"version": "0.0.1",
"version": "0.0.2",
"exports": {
".": {
"types": "./src/index.ts",
Expand Down
2 changes: 1 addition & 1 deletion packages/messaging/src/background.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AnyTRPCRouter } from '@trpc/server';
import type { AnyTRPCRouter } from '@trpc/server';
import { Port, RequestHandler, StreamHandler, createMessaging } from './core';
import { applyMessagingHandler } from './core/trpc';
import { WebxMessage, isWebxMessage } from './shared';
Expand Down
4 changes: 2 additions & 2 deletions packages/messaging/src/content-script.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AnyTRPCRouter } from '@trpc/server';
import { SetOptional } from 'type-fest';
import type { AnyTRPCRouter } from '@trpc/server';
import type { SetOptional } from 'type-fest';
import {
CustomHandlerOptions,
TrpcClientOptions,
Expand Down
2 changes: 1 addition & 1 deletion packages/messaging/src/core/trpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { TRPCResponseMessage, transformResult } from '@trpc/server/unstable-core-do-not-import';
import { isObservable, observable } from '@trpc/server/observable';
import { Operation, TRPCClientError, TRPCLink } from '@trpc/client';
import { CreateMessagingOptions, Messaging, Port, createMessaging } from './index';
import { Messaging, Port, createMessaging } from './index';

export interface MessagingHandlerOptions<TRouter extends AnyTRPCRouter> {
port: Port;
Expand Down
13 changes: 11 additions & 2 deletions packages/messaging/src/options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { SetOptional } from 'type-fest';
import { CustomHandlerOptions, createCustomHandler as internalCreateCustomHandler } from './client-base';
import type { AnyTRPCRouter } from '@trpc/server';
import type { SetOptional } from 'type-fest';
import {
CustomHandlerOptions,
TrpcClientOptions,
createCustomHandler as internalCreateCustomHandler,
createTrpcClient as internalCreateTrpcClient,
} from './client-base';

export const createCustomHandler = (options: SetOptional<CustomHandlerOptions, 'type'>) =>
internalCreateCustomHandler({ type: 'options', ...options });

export const createTrpcClient = <TRouter extends AnyTRPCRouter>(options: SetOptional<TrpcClientOptions, 'type'>) =>
internalCreateTrpcClient<TRouter>({ type: 'options', ...options });
13 changes: 11 additions & 2 deletions packages/messaging/src/popup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import { SetOptional } from 'type-fest';
import { CustomHandlerOptions, createCustomHandler as internalCreateCustomHandler } from './client-base';
import type { AnyTRPCRouter } from '@trpc/server';
import type { SetOptional } from 'type-fest';
import {
CustomHandlerOptions,
TrpcClientOptions,
createCustomHandler as internalCreateCustomHandler,
createTrpcClient as internalCreateTrpcClient,
} from './client-base';

export const createCustomHandler = (options: SetOptional<CustomHandlerOptions, 'type'>) =>
internalCreateCustomHandler({ type: 'popup', ...options });

export const createTrpcClient = <TRouter extends AnyTRPCRouter>(options: SetOptional<TrpcClientOptions, 'type'>) =>
internalCreateTrpcClient<TRouter>({ type: 'popup', ...options });
2 changes: 1 addition & 1 deletion packages/messaging/src/shared.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { LiteralUnion, Observer } from 'type-fest';
import { Messaging } from './core';
import type { Messaging } from './core';

export type ClientType = 'devtools' | 'popup' | 'options' | 'content-script';

Expand Down

0 comments on commit 54c92e2

Please sign in to comment.