artprompt-trpc-client
Advanced tools
Comparing version 10.0.0-proxy-alpha.54 to 10.0.0-proxy-alpha.74
@@ -1,4 +0,4 @@ | ||
import type { AnyRouter, OmitNeverKeys, Procedure, ProcedureArgs, ProcedureRouterRecord, inferProcedureOutput } from '@trpc/server'; | ||
import type { AnyRouter, Procedure, ProcedureArgs, ProcedureRouterRecord, inferProcedureOutput } from '@trpc/server'; | ||
import type { Unsubscribable, inferObservableValue } from '@trpc/server/observable'; | ||
import type { TRPCResultMessage } from '@trpc/server/rpc'; | ||
import { LegacyV9ProcedureTag } from '@trpc/server/shared'; | ||
import { TRPCClientError } from './TRPCClientError'; | ||
@@ -11,15 +11,17 @@ import { CreateTRPCClientOptions } from './createTRPCClient'; | ||
input: ProcedureArgs<TProcedure['_def']>[0], | ||
opts: ProcedureArgs<TProcedure['_def']>[1] & Partial<TRPCSubscriptionObserver<TRPCResultMessage<inferObservableValue<inferProcedureOutput<TProcedure>>>, TRPCClientError<TRouter>>> | ||
opts: ProcedureArgs<TProcedure['_def']>[1] & Partial<TRPCSubscriptionObserver<inferObservableValue<inferProcedureOutput<TProcedure>>, TRPCClientError<TRouter>>> | ||
]) => Unsubscribable; | ||
declare type DecorateProcedure<TProcedure extends Procedure<any>, TRouter extends AnyRouter> = OmitNeverKeys<{ | ||
query: TProcedure extends { | ||
_query: true; | ||
} ? Resolver<TProcedure> : never; | ||
mutate: TProcedure extends { | ||
_mutation: true; | ||
} ? Resolver<TProcedure> : never; | ||
subscribe: TProcedure extends { | ||
_subscription: true; | ||
} ? SubscriptionResolver<TProcedure, TRouter> : never; | ||
}>; | ||
declare type DecorateProcedure<TProcedure extends Procedure<any>, TRouter extends AnyRouter> = TProcedure extends { | ||
_type: 'query'; | ||
} ? { | ||
query: Resolver<TProcedure>; | ||
} : TProcedure extends { | ||
_type: 'mutation'; | ||
} ? { | ||
mutate: Resolver<TProcedure>; | ||
} : TProcedure extends { | ||
_type: 'subscription'; | ||
} ? { | ||
subscribe: SubscriptionResolver<TProcedure, TRouter>; | ||
} : never; | ||
declare type assertProcedure<T> = T extends Procedure<any> ? T : never; | ||
@@ -29,5 +31,5 @@ /** | ||
*/ | ||
declare type DecoratedProcedureRecord<TProcedures extends ProcedureRouterRecord, TRouter extends AnyRouter> = OmitNeverKeys<{ | ||
[TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter ? DecoratedProcedureRecord<TProcedures[TKey]['_def']['record'], TProcedures[TKey]> : assertProcedure<TProcedures[TKey]>['_def']['_old'] extends true ? never : DecorateProcedure<assertProcedure<TProcedures[TKey]>, TRouter>; | ||
}>; | ||
declare type DecoratedProcedureRecord<TProcedures extends ProcedureRouterRecord, TRouter extends AnyRouter> = { | ||
[TKey in keyof TProcedures]: TProcedures[TKey] extends LegacyV9ProcedureTag ? never : TProcedures[TKey] extends AnyRouter ? DecoratedProcedureRecord<TProcedures[TKey]['_def']['record'], TProcedures[TKey]> : DecorateProcedure<assertProcedure<TProcedures[TKey]>, TRouter>; | ||
}; | ||
/** | ||
@@ -37,5 +39,5 @@ * @deprecated use `createTRPCProxyClient` instead | ||
*/ | ||
export declare function createTRPCClientProxy<TRouter extends AnyRouter>(client: Client<TRouter>): inferRouterProxyClient<TRouter>; | ||
export declare function createTRPCProxyClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): inferRouterProxyClient<TRouter>; | ||
export declare function createTRPCClientProxy<TRouter extends AnyRouter>(client: Client<TRouter>): DecoratedProcedureRecord<TRouter["_def"]["record"], TRouter>; | ||
export declare function createTRPCProxyClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): DecoratedProcedureRecord<TRouter["_def"]["record"], TRouter>; | ||
export {}; | ||
//# sourceMappingURL=createTRPCClientProxy.d.ts.map |
@@ -13,3 +13,3 @@ 'use strict'; | ||
var links_wsLink = require('./links/wsLink.js'); | ||
require('./httpUtils-801112a6.js'); | ||
require('./httpUtils-0961d5e3.js'); | ||
@@ -167,24 +167,18 @@ function getWindow() { | ||
} | ||
query(path, ...args) { | ||
// FIXME: Should be inferred from `args` | ||
const context = args[1]?.context; | ||
const signal = args[1]?.signal; | ||
query(path, input, opts) { | ||
return this.requestAsPromise({ | ||
type: 'query', | ||
path, | ||
input: args[0], | ||
context, | ||
signal | ||
input: input, | ||
context: opts?.context, | ||
signal: opts?.signal | ||
}); | ||
} | ||
mutation(path, ...args) { | ||
// FIXME: Should be inferred from `args` | ||
const context = args[1]?.context; | ||
const signal = args[1]?.signal; | ||
mutation(path, input, opts) { | ||
return this.requestAsPromise({ | ||
type: 'mutation', | ||
path, | ||
input: args[0], | ||
context, | ||
signal | ||
input: input, | ||
context: opts?.context, | ||
signal: opts?.signal | ||
}); | ||
@@ -228,9 +222,13 @@ } | ||
} | ||
const transformer = opts.transformer ? 'input' in opts.transformer ? { | ||
serialize: opts.transformer.input.serialize, | ||
deserialize: opts.transformer.output.deserialize | ||
} : opts.transformer : { | ||
serialize: (data)=>data, | ||
deserialize: (data)=>data | ||
}; | ||
function getTransformer() { | ||
if (!opts.transformer) return { | ||
serialize: (data)=>data, | ||
deserialize: (data)=>data | ||
}; | ||
if ('input' in opts.transformer) return { | ||
serialize: opts.transformer.input.serialize, | ||
deserialize: opts.transformer.output.deserialize | ||
}; | ||
return opts.transformer; | ||
} | ||
this.runtime = { | ||
@@ -240,13 +238,15 @@ AbortController: AC, | ||
headers: getHeadersFn(), | ||
transformer | ||
transformer: getTransformer() | ||
}; | ||
if ('links' in opts) { | ||
this.links = opts.links.map((link)=>link(this.runtime)); | ||
} else { | ||
this.links = [ | ||
const getLinks = ()=>{ | ||
if (opts.links) { | ||
return opts.links.map((link)=>link(this.runtime)); | ||
} | ||
return [ | ||
links_httpBatchLink.httpBatchLink({ | ||
url: opts.url | ||
})(this.runtime), | ||
})(this.runtime) | ||
]; | ||
} | ||
}; | ||
this.links = getLinks(); | ||
} | ||
@@ -277,6 +277,2 @@ } | ||
const procedureType = clientCallTypeMap[clientCallType]; | ||
if (!procedureType) { | ||
// pass it on if we're being treated like a promise or something else | ||
throw new TypeError(`Unexpected call to "${path.join('.')}()" on TRPCProxyClient.`); | ||
} | ||
const fullPath = pathCopy.join('.'); | ||
@@ -283,0 +279,0 @@ return client[procedureType](fullPath, ...args); |
@@ -1,2 +0,2 @@ | ||
import { AnyRouter, ClientDataTransformerOptions, inferHandlerInput, inferProcedureInput, inferProcedureOutput, inferSubscriptionOutput } from '@trpc/server'; | ||
import { AnyRouter, ClientDataTransformerOptions, inferProcedureInput, inferProcedureOutput, inferSubscriptionOutput } from '@trpc/server'; | ||
import { ProcedureRecord } from '@trpc/server'; | ||
@@ -12,7 +12,8 @@ import { Unsubscribable } from '@trpc/server/observable'; | ||
/** | ||
* add ponyfill for AbortController | ||
* Add ponyfill for AbortController | ||
*/ | ||
AbortController?: typeof AbortController; | ||
/** | ||
* headers to be set on outgoing requests / callback that of said headers | ||
* Headers to be set on outgoing requests or a callback that of said headers | ||
* @link http://localhost:3000/docs/v10/header | ||
*/ | ||
@@ -26,16 +27,2 @@ headers?: HTTPHeaders | (() => HTTPHeaders | Promise<HTTPHeaders>); | ||
} | ||
/** @internal */ | ||
export interface CreateTRPCClientWithURLOptions extends CreateTRPCClientBaseOptions { | ||
/** | ||
* HTTP URL of API | ||
**/ | ||
url: string; | ||
} | ||
/** @internal */ | ||
export interface CreateTRPCClientWithLinksOptions<TRouter extends AnyRouter> extends CreateTRPCClientBaseOptions { | ||
/** | ||
* @link https://trpc.io/docs/links | ||
**/ | ||
links: TRPCLink<TRouter>[]; | ||
} | ||
export interface TRPCRequestOptions { | ||
@@ -55,4 +42,12 @@ /** | ||
} | ||
/** @internal */ | ||
export declare type CreateTRPCClientOptions<TRouter extends AnyRouter> = CreateTRPCClientWithLinksOptions<TRouter> | CreateTRPCClientWithURLOptions; | ||
/** | ||
* This type prohibits `url` from being provided along with `links` | ||
* @internal | ||
*/ | ||
export declare type CreateTRPCClientOptions<TRouter extends AnyRouter> = CreateTRPCClientBaseOptions & ({ | ||
links: TRPCLink<TRouter>[]; | ||
} | { | ||
url: string; | ||
links?: never; | ||
}); | ||
export declare type AssertType<T, K> = T extends K ? T : never; | ||
@@ -75,10 +70,4 @@ /** | ||
private requestAsPromise; | ||
query<TQueries extends AssertLegacyDef<TRouter>['queries'], TPath extends string & keyof TQueries>(path: TPath, ...args: [ | ||
...inferHandlerInput<AssertType<TQueries, ProcedureRecord>[TPath]>, | ||
TRPCRequestOptions? | ||
]): Promise<inferProcedureOutput<TQueries[TPath]>>; | ||
mutation<TMutations extends AssertLegacyDef<TRouter>['mutations'], TPath extends string & keyof TMutations>(path: TPath, ...args: [ | ||
...inferHandlerInput<AssertType<TMutations, ProcedureRecord>[TPath]>, | ||
TRPCRequestOptions? | ||
]): Promise<inferProcedureOutput<TMutations[TPath]>>; | ||
query<TQueries extends AssertLegacyDef<TRouter>['queries'], TPath extends string & keyof TQueries, TInput extends inferProcedureInput<AssertType<TQueries, ProcedureRecord>[TPath]>>(path: TPath, input?: TInput, opts?: TRPCRequestOptions): Promise<inferProcedureOutput<TQueries[TPath]>>; | ||
mutation<TMutations extends AssertLegacyDef<TRouter>['mutations'], TPath extends string & keyof TMutations, TInput extends inferProcedureInput<AssertType<TMutations, ProcedureRecord>[TPath]>>(path: TPath, input?: TInput, opts?: TRPCRequestOptions): Promise<inferProcedureOutput<TMutations[TPath]>>; | ||
subscription<TSubscriptions extends AssertLegacyDef<TRouter>['subscriptions'], TPath extends string & keyof TSubscriptions, TOutput extends inferSubscriptionOutput<TRouter, TPath>, TInput extends inferProcedureInput<AssertType<TSubscriptions, ProcedureRecord>[TPath]>>(path: TPath, input: TInput, opts: TRPCRequestOptions & Partial<TRPCSubscriptionObserver<TOutput, TRPCClientError<TRouter>>>): Unsubscribable; | ||
@@ -85,0 +74,0 @@ } |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var transformResult = require('../transformResult-e15ccdf6.js'); | ||
var httpUtils = require('../httpUtils-801112a6.js'); | ||
var httpUtils = require('../httpUtils-0961d5e3.js'); | ||
@@ -10,0 +10,0 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ /** |
@@ -7,3 +7,3 @@ 'use strict'; | ||
var transformResult = require('../transformResult-e15ccdf6.js'); | ||
var httpUtils = require('../httpUtils-801112a6.js'); | ||
var httpUtils = require('../httpUtils-0961d5e3.js'); | ||
@@ -10,0 +10,0 @@ function httpLink(opts) { |
@@ -18,3 +18,3 @@ import { AnyRouter, DataTransformer } from '@trpc/server'; | ||
}; | ||
export declare type HTTPHeaders = Record<string, string | string[]>; | ||
export declare type HTTPHeaders = Record<string, string | string[] | undefined>; | ||
/** | ||
@@ -21,0 +21,0 @@ * The default `fetch` implementation has an overloaded signature. By convention this library |
@@ -14,3 +14,5 @@ import { AnyRouter, inferRouterError } from '@trpc/server'; | ||
onOpen?: () => void; | ||
onClose?: () => void; | ||
onClose?: (cause?: { | ||
code?: number; | ||
}) => void; | ||
} | ||
@@ -17,0 +19,0 @@ export declare function createWSClient(opts: WebSocketClientOptions): { |
@@ -137,5 +137,7 @@ 'use strict'; | ||
}); | ||
conn.addEventListener('close', ()=>{ | ||
conn.addEventListener('close', ({ code })=>{ | ||
if (state === 'open') { | ||
onClose?.(); | ||
onClose?.({ | ||
code | ||
}); | ||
} | ||
@@ -142,0 +144,0 @@ if (activeConnection === conn) { |
{ | ||
"name": "artprompt-trpc-client", | ||
"version": "10.0.0-proxy-alpha.54", | ||
"version": "10.0.0-proxy-alpha.74", | ||
"description": "tRPC Client lib", | ||
@@ -69,3 +69,3 @@ "author": "KATT", | ||
"devDependencies": { | ||
"@trpc/server": "^10.0.0-proxy-alpha.54" | ||
"@trpc/server": "^10.0.0-proxy-alpha.74" | ||
}, | ||
@@ -72,0 +72,0 @@ "publishConfig": { |
@@ -10,3 +10,3 @@ <p align="center"> | ||
<p align="center"> | ||
<img src="https://user-images.githubusercontent.com/51714798/186850605-7cb9f6b2-2230-4eb7-981b-0b90ee1f8ffa.gif" alt="Demo" /> | ||
<img src="https://assets.trpc.io/www/v10/preview-dark.gif" alt="Demo" /> | ||
</p> | ||
@@ -26,9 +26,9 @@ | ||
# npm | ||
npm install @trpc/client | ||
npm install @trpc/client@next | ||
# Yarn | ||
yarn add @trpc/client | ||
yarn add @trpc/client@next | ||
# pnpm | ||
pnpm add @trpc/client | ||
pnpm add @trpc/client@next | ||
``` | ||
@@ -35,0 +35,0 @@ |
@@ -6,3 +6,2 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
AnyRouter, | ||
OmitNeverKeys, | ||
Procedure, | ||
@@ -18,4 +17,3 @@ ProcedureArgs, | ||
} from '@trpc/server/observable'; | ||
import type { TRPCResultMessage } from '@trpc/server/rpc'; | ||
import { createProxy } from '@trpc/server/shared'; | ||
import { LegacyV9ProcedureTag, createProxy } from '@trpc/server/shared'; | ||
import { TRPCClientError } from './TRPCClientError'; | ||
@@ -44,5 +42,3 @@ import { CreateTRPCClientOptions, createTRPCClient } from './createTRPCClient'; | ||
TRPCSubscriptionObserver< | ||
TRPCResultMessage< | ||
inferObservableValue<inferProcedureOutput<TProcedure>> | ||
>, | ||
inferObservableValue<inferProcedureOutput<TProcedure>>, | ||
TRPCClientError<TRouter> | ||
@@ -57,12 +53,16 @@ > | ||
TRouter extends AnyRouter, | ||
> = OmitNeverKeys<{ | ||
query: TProcedure extends { _query: true } ? Resolver<TProcedure> : never; | ||
> = TProcedure extends { _type: 'query' } | ||
? { | ||
query: Resolver<TProcedure>; | ||
} | ||
: TProcedure extends { _type: 'mutation' } | ||
? { | ||
mutate: Resolver<TProcedure>; | ||
} | ||
: TProcedure extends { _type: 'subscription' } | ||
? { | ||
subscribe: SubscriptionResolver<TProcedure, TRouter>; | ||
} | ||
: never; | ||
mutate: TProcedure extends { _mutation: true } ? Resolver<TProcedure> : never; | ||
subscribe: TProcedure extends { _subscription: true } | ||
? SubscriptionResolver<TProcedure, TRouter> | ||
: never; | ||
}>; | ||
type assertProcedure<T> = T extends Procedure<any> ? T : never; | ||
@@ -76,4 +76,6 @@ | ||
TRouter extends AnyRouter, | ||
> = OmitNeverKeys<{ | ||
[TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter | ||
> = { | ||
[TKey in keyof TProcedures]: TProcedures[TKey] extends LegacyV9ProcedureTag | ||
? never | ||
: TProcedures[TKey] extends AnyRouter | ||
? DecoratedProcedureRecord< | ||
@@ -83,6 +85,4 @@ TProcedures[TKey]['_def']['record'], | ||
> | ||
: assertProcedure<TProcedures[TKey]>['_def']['_old'] extends true | ||
? never | ||
: DecorateProcedure<assertProcedure<TProcedures[TKey]>, TRouter>; | ||
}>; | ||
}; | ||
@@ -109,8 +109,3 @@ const clientCallTypeMap: Record< | ||
const procedureType = clientCallTypeMap[clientCallType]; | ||
if (!procedureType) { | ||
// pass it on if we're being treated like a promise or something else | ||
throw new TypeError( | ||
`Unexpected call to "${path.join('.')}()" on TRPCProxyClient.`, | ||
); | ||
} | ||
const fullPath = pathCopy.join('.'); | ||
@@ -117,0 +112,0 @@ return (client as any)[procedureType](fullPath, ...args); |
@@ -5,3 +5,2 @@ import { | ||
DataTransformer, | ||
inferHandlerInput, | ||
inferProcedureInput, | ||
@@ -37,7 +36,8 @@ inferProcedureOutput, | ||
/** | ||
* add ponyfill for AbortController | ||
* Add ponyfill for AbortController | ||
*/ | ||
AbortController?: typeof AbortController; | ||
/** | ||
* headers to be set on outgoing requests / callback that of said headers | ||
* Headers to be set on outgoing requests or a callback that of said headers | ||
* @link http://localhost:3000/docs/v10/header | ||
*/ | ||
@@ -52,20 +52,2 @@ headers?: HTTPHeaders | (() => HTTPHeaders | Promise<HTTPHeaders>); | ||
/** @internal */ | ||
export interface CreateTRPCClientWithURLOptions | ||
extends CreateTRPCClientBaseOptions { | ||
/** | ||
* HTTP URL of API | ||
**/ | ||
url: string; | ||
} | ||
/** @internal */ | ||
export interface CreateTRPCClientWithLinksOptions<TRouter extends AnyRouter> | ||
extends CreateTRPCClientBaseOptions { | ||
/** | ||
* @link https://trpc.io/docs/links | ||
**/ | ||
links: TRPCLink<TRouter>[]; | ||
} | ||
type TRPCType = 'subscription' | 'query' | 'mutation'; | ||
@@ -88,6 +70,17 @@ export interface TRPCRequestOptions { | ||
/** @internal */ | ||
/** | ||
* This type prohibits `url` from being provided along with `links` | ||
* @internal | ||
*/ | ||
export type CreateTRPCClientOptions<TRouter extends AnyRouter> = | ||
| CreateTRPCClientWithLinksOptions<TRouter> | ||
| CreateTRPCClientWithURLOptions; | ||
| CreateTRPCClientBaseOptions & | ||
( | ||
| { | ||
links: TRPCLink<TRouter>[]; | ||
} | ||
| { | ||
url: string; | ||
links?: never; | ||
} | ||
); | ||
@@ -131,13 +124,15 @@ export type AssertType<T, K> = T extends K ? T : never; | ||
const transformer: DataTransformer = opts.transformer | ||
? 'input' in opts.transformer | ||
? { | ||
serialize: opts.transformer.input.serialize, | ||
deserialize: opts.transformer.output.deserialize, | ||
} | ||
: opts.transformer | ||
: { | ||
function getTransformer(): DataTransformer { | ||
if (!opts.transformer) | ||
return { | ||
serialize: (data) => data, | ||
deserialize: (data) => data, | ||
}; | ||
if ('input' in opts.transformer) | ||
return { | ||
serialize: opts.transformer.input.serialize, | ||
deserialize: opts.transformer.output.deserialize, | ||
}; | ||
return opts.transformer; | ||
} | ||
@@ -148,14 +143,13 @@ this.runtime = { | ||
headers: getHeadersFn(), | ||
transformer, | ||
transformer: getTransformer(), | ||
}; | ||
if ('links' in opts) { | ||
this.links = opts.links.map((link) => link(this.runtime)); | ||
} else { | ||
this.links = [ | ||
httpBatchLink({ | ||
url: opts.url, | ||
})(this.runtime), | ||
]; | ||
} | ||
const getLinks = (): OperationLink<TRouter>[] => { | ||
if (opts.links) { | ||
return opts.links.map((link) => link(this.runtime)); | ||
} | ||
return [httpBatchLink({ url: opts.url })(this.runtime)]; | ||
}; | ||
this.links = getLinks(); | ||
} | ||
@@ -214,22 +208,13 @@ | ||
TPath extends string & keyof TQueries, | ||
>( | ||
path: TPath, | ||
...args: [ | ||
...inferHandlerInput<AssertType<TQueries, ProcedureRecord>[TPath]>, | ||
TRPCRequestOptions?, | ||
] | ||
) { | ||
// FIXME: Should be inferred from `args` | ||
const context = (args[1] as TRPCRequestOptions | undefined)?.context; | ||
const signal = (args[1] as TRPCRequestOptions | undefined)?.signal; | ||
return this.requestAsPromise< | ||
inferHandlerInput<AssertType<TQueries, ProcedureRecord>[TPath]>, | ||
inferProcedureOutput<TQueries[TPath]> | ||
>({ | ||
TInput extends inferProcedureInput< | ||
AssertType<TQueries, ProcedureRecord>[TPath] | ||
>, | ||
>(path: TPath, input?: TInput, opts?: TRPCRequestOptions) { | ||
type TOutput = inferProcedureOutput<TQueries[TPath]>; | ||
return this.requestAsPromise<TInput, TOutput>({ | ||
type: 'query', | ||
path, | ||
input: args[0] as any, | ||
context, | ||
signal, | ||
input: input as TInput, | ||
context: opts?.context, | ||
signal: opts?.signal, | ||
}); | ||
@@ -240,22 +225,13 @@ } | ||
TPath extends string & keyof TMutations, | ||
>( | ||
path: TPath, | ||
...args: [ | ||
...inferHandlerInput<AssertType<TMutations, ProcedureRecord>[TPath]>, | ||
TRPCRequestOptions?, | ||
] | ||
) { | ||
// FIXME: Should be inferred from `args` | ||
const context = (args[1] as TRPCRequestOptions | undefined)?.context; | ||
const signal = (args[1] as TRPCRequestOptions | undefined)?.signal; | ||
return this.requestAsPromise< | ||
inferHandlerInput<AssertType<TMutations, ProcedureRecord>[TPath]>, | ||
inferProcedureOutput<TMutations[TPath]> | ||
>({ | ||
TInput extends inferProcedureInput< | ||
AssertType<TMutations, ProcedureRecord>[TPath] | ||
>, | ||
>(path: TPath, input?: TInput, opts?: TRPCRequestOptions) { | ||
type TOutput = inferProcedureOutput<TMutations[TPath]>; | ||
return this.requestAsPromise<TInput, TOutput>({ | ||
type: 'mutation', | ||
path, | ||
input: args[0] as any, | ||
context, | ||
signal, | ||
input: input as TInput, | ||
context: opts?.context, | ||
signal: opts?.signal, | ||
}); | ||
@@ -262,0 +238,0 @@ } |
@@ -22,3 +22,2 @@ import { ProcedureType } from '@trpc/server'; | ||
mutation: 'POST', | ||
subscription: 'PATCH', | ||
} as const; | ||
@@ -91,4 +90,7 @@ | ||
Promise.resolve(runtime.headers()) | ||
.then((headers) => | ||
runtime.fetch(url, { | ||
.then((headers) => { | ||
if (type === 'subscription') { | ||
throw new Error('Subscriptions should use wsLink'); | ||
} | ||
return runtime.fetch(url, { | ||
method: METHOD[type], | ||
@@ -101,4 +103,4 @@ signal: ac?.signal, | ||
}, | ||
}), | ||
) | ||
}); | ||
}) | ||
.then((_res) => { | ||
@@ -105,0 +107,0 @@ meta.response = _res; |
@@ -22,3 +22,3 @@ import { AnyRouter, DataTransformer } from '@trpc/server'; | ||
export type HTTPHeaders = Record<string, string | string[]>; | ||
export type HTTPHeaders = Record<string, string | string[] | undefined>; | ||
@@ -25,0 +25,0 @@ /** |
@@ -30,3 +30,3 @@ import { AnyRouter, ProcedureType, inferRouterError } from '@trpc/server'; | ||
onOpen?: () => void; | ||
onClose?: () => void; | ||
onClose?: (cause?: { code?: number }) => void; | ||
} | ||
@@ -202,5 +202,5 @@ | ||
conn.addEventListener('close', () => { | ||
conn.addEventListener('close', ({ code }) => { | ||
if (state === 'open') { | ||
onClose?.(); | ||
onClose?.({ code }); | ||
} | ||
@@ -207,0 +207,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
167060
4452