@trpc/client 10.29.1 → 10.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/createTRPCClientProxy.d.ts +16 -6
- package/dist/createTRPCClientProxy.d.ts.map +1 -1
- package/dist/createTRPCUntypedClient.d.ts +1 -1
- package/dist/createTRPCUntypedClient.d.ts.map +1 -1
- package/dist/index.js +11 -2
- package/dist/index.mjs +11 -3
- package/dist/internals/types.d.ts +8 -1
- package/dist/internals/types.d.ts.map +1 -1
- package/dist/links/internals/parseJSONStream.d.ts +2 -1
- package/dist/links/internals/parseJSONStream.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/createTRPCClientProxy.ts +31 -12
- package/src/createTRPCUntypedClient.ts +2 -3
- package/src/internals/types.ts +9 -1
- package/src/links/internals/parseJSONStream.ts +4 -4
|
@@ -3,10 +3,12 @@ import type { Unsubscribable } from '@trpc/server/observable';
|
|
|
3
3
|
import { inferTransformedProcedureOutput, inferTransformedSubscriptionOutput } from '@trpc/server/shared';
|
|
4
4
|
import { TRPCClient } from './createTRPCClient';
|
|
5
5
|
import { CreateTRPCClientOptions } from './createTRPCUntypedClient';
|
|
6
|
-
import { TRPCSubscriptionObserver, UntypedClientProperties } from './internals/TRPCUntypedClient';
|
|
6
|
+
import { TRPCSubscriptionObserver, TRPCUntypedClient, UntypedClientProperties } from './internals/TRPCUntypedClient';
|
|
7
7
|
import { TRPCClientError } from './TRPCClientError';
|
|
8
|
-
/**
|
|
9
|
-
|
|
8
|
+
/**
|
|
9
|
+
* @public
|
|
10
|
+
**/
|
|
11
|
+
export type inferRouterProxyClient<TRouter extends AnyRouter> = DecoratedProcedureRecord<TRouter, TRouter['_def']['record']>;
|
|
10
12
|
/** @internal */
|
|
11
13
|
export type Resolver<TProcedure extends AnyProcedure> = (...args: ProcedureArgs<TProcedure['_def']>) => Promise<inferTransformedProcedureOutput<TProcedure>>;
|
|
12
14
|
type SubscriptionResolver<TProcedure extends AnyProcedure> = (...args: [
|
|
@@ -23,17 +25,25 @@ type DecorateProcedure<TProcedure extends AnyProcedure> = TProcedure extends Any
|
|
|
23
25
|
/**
|
|
24
26
|
* @internal
|
|
25
27
|
*/
|
|
26
|
-
type DecoratedProcedureRecord<TProcedures extends ProcedureRouterRecord> = {
|
|
27
|
-
[TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter ? DecoratedProcedureRecord<TProcedures[TKey]['_def']['record']> : TProcedures[TKey] extends AnyProcedure ? DecorateProcedure<TProcedures[TKey]> : never;
|
|
28
|
+
type DecoratedProcedureRecord<TRouter extends AnyRouter, TProcedures extends ProcedureRouterRecord> = {
|
|
29
|
+
[TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter ? DecoratedProcedureRecord<TRouter, TProcedures[TKey]['_def']['record']> : TProcedures[TKey] extends AnyProcedure ? DecorateProcedure<TProcedures[TKey]> : never;
|
|
28
30
|
};
|
|
29
31
|
/** @internal */
|
|
30
32
|
export declare const clientCallTypeToProcedureType: (clientCallType: string) => ProcedureType;
|
|
31
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Creates a proxy client and shows type errors if you have query names that collide with built-in properties
|
|
35
|
+
*/
|
|
36
|
+
export type CreateTRPCProxyClient<TRouter extends AnyRouter> = inferRouterProxyClient<TRouter> extends infer $ProcedureRecord ? UntypedClientProperties & keyof $ProcedureRecord extends never ? inferRouterProxyClient<TRouter> : IntersectionError<UntypedClientProperties & keyof $ProcedureRecord> : never;
|
|
32
37
|
/**
|
|
33
38
|
* @deprecated use `createTRPCProxyClient` instead
|
|
34
39
|
* @internal
|
|
35
40
|
*/
|
|
36
41
|
export declare function createTRPCClientProxy<TRouter extends AnyRouter>(client: TRPCClient<TRouter>): CreateTRPCProxyClient<TRouter>;
|
|
37
42
|
export declare function createTRPCProxyClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): CreateTRPCProxyClient<TRouter>;
|
|
43
|
+
/**
|
|
44
|
+
* Get an untyped client from a proxy client
|
|
45
|
+
* @internal
|
|
46
|
+
*/
|
|
47
|
+
export declare function getUntypedClient<TRouter extends AnyRouter>(client: inferRouterProxyClient<TRouter>): TRPCUntypedClient<TRouter>;
|
|
38
48
|
export {};
|
|
39
49
|
//# sourceMappingURL=createTRPCClientProxy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTRPCClientProxy.d.ts","sourceRoot":"","sources":["../src/createTRPCClientProxy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,wBAAwB,EACxB,iBAAiB,EACjB,aAAa,EACb,qBAAqB,EACrB,aAAa,EACd,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAGL,+BAA+B,EAC/B,kCAAkC,EACnC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EACL,wBAAwB,
|
|
1
|
+
{"version":3,"file":"createTRPCClientProxy.d.ts","sourceRoot":"","sources":["../src/createTRPCClientProxy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,wBAAwB,EACxB,iBAAiB,EACjB,aAAa,EACb,qBAAqB,EACrB,aAAa,EACd,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAGL,+BAA+B,EAC/B,kCAAkC,EACnC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EACL,wBAAwB,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,IAAI,IAAI,MAAM,WAAW,GAAG,WAAW,CAAC,IAAI,CAAC,SAAS,SAAS,GAC5D,wBAAwB,CAAC,OAAO,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,GACtE,WAAW,CAAC,IAAI,CAAC,SAAS,YAAY,GACtC,iBAAiB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,GACpC,KAAK;CACV,CAAC;AAQF,gBAAgB;AAChB,eAAO,MAAM,6BAA6B,mBACxB,MAAM,KACrB,aAEF,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,CAAC,OAAO,SAAS,SAAS,IACzD,sBAAsB,CAAC,OAAO,CAAC,SAAS,MAAM,gBAAgB,GAC1D,uBAAuB,GAAG,MAAM,gBAAgB,SAAS,KAAK,GAC5D,sBAAsB,CAAC,OAAO,CAAC,GAC/B,iBAAiB,CAAC,uBAAuB,GAAG,MAAM,gBAAgB,CAAC,GACrE,KAAK,CAAC;AAEZ;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,SAAS,EAC7D,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,GAC1B,qBAAqB,CAAC,OAAO,CAAC,CAiBhC;AAED,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,SAAS,EAC7D,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,GACrC,qBAAqB,CAAC,OAAO,CAAC,CAIhC;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,SAAS,EACxD,MAAM,EAAE,sBAAsB,CAAC,OAAO,CAAC,GACtC,iBAAiB,CAAC,OAAO,CAAC,CAE5B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnyRouter } from '@trpc/server';
|
|
2
2
|
import { CreateTRPCClientOptions, TRPCUntypedClient } from './internals/TRPCUntypedClient';
|
|
3
|
-
export declare function createTRPCUntypedClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): TRPCUntypedClient<
|
|
3
|
+
export declare function createTRPCUntypedClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): TRPCUntypedClient<TRouter>;
|
|
4
4
|
export type { CreateTRPCClientOptions, TRPCRequestOptions, TRPCUntypedClient, } from './internals/TRPCUntypedClient';
|
|
5
5
|
//# sourceMappingURL=createTRPCUntypedClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTRPCUntypedClient.d.ts","sourceRoot":"","sources":["../src/createTRPCUntypedClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EAClB,MAAM,+BAA+B,CAAC;AAEvC,wBAAgB,uBAAuB,CAAC,OAAO,SAAS,SAAS,EAC/D,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"createTRPCUntypedClient.d.ts","sourceRoot":"","sources":["../src/createTRPCUntypedClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EACL,uBAAuB,EACvB,iBAAiB,EAClB,MAAM,+BAA+B,CAAC;AAEvC,wBAAgB,uBAAuB,CAAC,OAAO,SAAS,SAAS,EAC/D,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,GACrC,iBAAiB,CAAC,OAAO,CAAC,CAE5B;AAED,YAAY,EACV,uBAAuB,EACvB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,+BAA+B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -119,8 +119,7 @@ class TRPCUntypedClient {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
function createTRPCUntypedClient(opts) {
|
|
122
|
-
|
|
123
|
-
return client;
|
|
122
|
+
return new TRPCUntypedClient(opts);
|
|
124
123
|
}
|
|
125
124
|
|
|
126
125
|
/**
|
|
@@ -146,6 +145,9 @@ const clientCallTypeMap = {
|
|
|
146
145
|
if (client.hasOwnProperty(key)) {
|
|
147
146
|
return client[key];
|
|
148
147
|
}
|
|
148
|
+
if (key === '__untypedClient') {
|
|
149
|
+
return client;
|
|
150
|
+
}
|
|
149
151
|
return shared.createRecursiveProxy(({ path , args })=>{
|
|
150
152
|
const pathCopy = [
|
|
151
153
|
key,
|
|
@@ -162,6 +164,12 @@ function createTRPCProxyClient(opts) {
|
|
|
162
164
|
const proxy = createTRPCClientProxy(client);
|
|
163
165
|
return proxy;
|
|
164
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Get an untyped client from a proxy client
|
|
169
|
+
* @internal
|
|
170
|
+
*/ function getUntypedClient(client) {
|
|
171
|
+
return client.__untypedClient;
|
|
172
|
+
}
|
|
165
173
|
|
|
166
174
|
function getTextDecoder(customTextDecoder) {
|
|
167
175
|
if (customTextDecoder) {
|
|
@@ -363,4 +371,5 @@ exports.createTRPCClientProxy = createTRPCClientProxy;
|
|
|
363
371
|
exports.createTRPCProxyClient = createTRPCProxyClient;
|
|
364
372
|
exports.createTRPCUntypedClient = createTRPCUntypedClient;
|
|
365
373
|
exports.experimental_formDataLink = experimental_formDataLink;
|
|
374
|
+
exports.getUntypedClient = getUntypedClient;
|
|
366
375
|
exports.unstable_httpBatchStreamLink = unstable_httpBatchStreamLink;
|
package/dist/index.mjs
CHANGED
|
@@ -120,8 +120,7 @@ class TRPCUntypedClient {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
function createTRPCUntypedClient(opts) {
|
|
123
|
-
|
|
124
|
-
return client;
|
|
123
|
+
return new TRPCUntypedClient(opts);
|
|
125
124
|
}
|
|
126
125
|
|
|
127
126
|
/**
|
|
@@ -147,6 +146,9 @@ const clientCallTypeMap = {
|
|
|
147
146
|
if (client.hasOwnProperty(key)) {
|
|
148
147
|
return client[key];
|
|
149
148
|
}
|
|
149
|
+
if (key === '__untypedClient') {
|
|
150
|
+
return client;
|
|
151
|
+
}
|
|
150
152
|
return createRecursiveProxy(({ path , args })=>{
|
|
151
153
|
const pathCopy = [
|
|
152
154
|
key,
|
|
@@ -163,6 +165,12 @@ function createTRPCProxyClient(opts) {
|
|
|
163
165
|
const proxy = createTRPCClientProxy(client);
|
|
164
166
|
return proxy;
|
|
165
167
|
}
|
|
168
|
+
/**
|
|
169
|
+
* Get an untyped client from a proxy client
|
|
170
|
+
* @internal
|
|
171
|
+
*/ function getUntypedClient(client) {
|
|
172
|
+
return client.__untypedClient;
|
|
173
|
+
}
|
|
166
174
|
|
|
167
175
|
function getTextDecoder(customTextDecoder) {
|
|
168
176
|
if (customTextDecoder) {
|
|
@@ -349,4 +357,4 @@ const experimental_formDataLink = httpLinkFactory({
|
|
|
349
357
|
requester: formDataRequester
|
|
350
358
|
});
|
|
351
359
|
|
|
352
|
-
export { clientCallTypeToProcedureType, createTRPCClient, createTRPCClientProxy, createTRPCProxyClient, createTRPCUntypedClient, experimental_formDataLink, unstable_httpBatchStreamLink };
|
|
360
|
+
export { clientCallTypeToProcedureType, createTRPCClient, createTRPCClientProxy, createTRPCProxyClient, createTRPCUntypedClient, experimental_formDataLink, getUntypedClient, unstable_httpBatchStreamLink };
|
|
@@ -57,12 +57,19 @@ export interface RequestInitEsque {
|
|
|
57
57
|
*/
|
|
58
58
|
signal?: AbortSignal | null;
|
|
59
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* A subset of the standard ReadableStream properties needed by tRPC internally.
|
|
62
|
+
* @see ReadableStream from lib.dom.d.ts
|
|
63
|
+
*/
|
|
64
|
+
export type WebReadableStreamEsque = {
|
|
65
|
+
getReader: () => ReadableStreamDefaultReader<Uint8Array>;
|
|
66
|
+
};
|
|
60
67
|
/**
|
|
61
68
|
* A subset of the standard Response properties needed by tRPC internally.
|
|
62
69
|
* @see Response from lib.dom.d.ts
|
|
63
70
|
*/
|
|
64
71
|
export interface ResponseEsque {
|
|
65
|
-
readonly body?:
|
|
72
|
+
readonly body?: WebReadableStreamEsque | NodeJS.ReadableStream | null;
|
|
66
73
|
/**
|
|
67
74
|
* @remarks
|
|
68
75
|
* The built-in Response::json() method returns Promise<any>, but
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/internals/types.ts"],"names":[],"mappings":";AAAA,MAAM,WAAW,oBAAoB;IACnC,QAAQ,4BAA4B,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAE7B;;;OAGG;IACH,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,CACvB,KAAK,EAAE,WAAW,GAAG,GAAG,GAAG,MAAM,EACjC,IAAI,CAAC,EAAE,WAAW,GAAG,gBAAgB,KAClC,OAAO,CAAC,aAAa,CAAC,CAAC;AAE5B;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAC7B,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,IAAI,CAAC,EAAE,yBAAyB,KAC7B,OAAO,CAAC,aAAa,CAAC,CAAC;AAE5B,MAAM,WAAW,yBAAyB;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,cAAc,GAAG,QAAQ,GAAG,IAAI,CAAC;IAEjD;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEtD;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAA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,IAAI,CAAC,EAAE,sBAAsB,GAAG,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;IACtE;;;;;OAKG;IACH,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,KAAK,IAAI,CAAC,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import { WebReadableStreamEsque } from '../../internals/types';
|
|
2
3
|
import { HTTPHeaders } from '../types';
|
|
3
4
|
import { HTTPBaseRequestOptions, HTTPResult } from './httpUtils';
|
|
4
5
|
import { TextDecoderEsque } from './streamingUtils';
|
|
@@ -17,7 +18,7 @@ export declare function parseJSONStream<TReturn>(opts: {
|
|
|
17
18
|
/**
|
|
18
19
|
* As given by `(await fetch(url)).body`
|
|
19
20
|
*/
|
|
20
|
-
readableStream:
|
|
21
|
+
readableStream: WebReadableStreamEsque | NodeJS.ReadableStream;
|
|
21
22
|
/**
|
|
22
23
|
* Called for each line of the stream
|
|
23
24
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseJSONStream.d.ts","sourceRoot":"","sources":["../../../src/links/internals/parseJSONStream.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"parseJSONStream.d.ts","sourceRoot":"","sources":["../../../src/links/internals/parseJSONStream.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAIL,sBAAsB,EACtB,UAAU,EACX,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,IAAI,EAAE;IACnD;;OAEG;IACH,cAAc,EAAE,sBAAsB,GAAG,MAAM,CAAC,cAAc,CAAC;IAC/D;;OAEG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,KAAK,IAAI,CAAC;IAChD;;OAEG;IACH,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IAClC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,WAAW,EAAE,gBAAgB,CAAC;CAC/B,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBhB;AAwED,eAAO,MAAM,0BAA0B,SAC/B,sBAAsB,GAAG;IAC7B,OAAO,EAAE,MAAM,WAAW,GAAG,QAAQ,WAAW,CAAC,CAAC;IAClD,WAAW,EAAE,gBAAgB,CAAC;CAC/B,oBACiB,MAAM,OAAO,UAAU,KAAK,IAAI;;;CA8BnD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/client",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.31.0",
|
|
4
4
|
"description": "The tRPC client library",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -76,11 +76,11 @@
|
|
|
76
76
|
"!**/*.test.*"
|
|
77
77
|
],
|
|
78
78
|
"peerDependencies": {
|
|
79
|
-
"@trpc/server": "10.
|
|
79
|
+
"@trpc/server": "10.31.0"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
82
82
|
"@testing-library/dom": "^9.0.0",
|
|
83
|
-
"@trpc/server": "10.
|
|
83
|
+
"@trpc/server": "10.31.0",
|
|
84
84
|
"@types/isomorphic-fetch": "^0.0.36",
|
|
85
85
|
"@types/node": "^18.16.16",
|
|
86
86
|
"eslint": "^8.40.0",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"rollup": "^2.79.1",
|
|
91
91
|
"tsx": "^3.12.7",
|
|
92
92
|
"undici": "^5.14.0",
|
|
93
|
-
"vitest": "^0.
|
|
93
|
+
"vitest": "^0.32.0"
|
|
94
94
|
},
|
|
95
95
|
"publishConfig": {
|
|
96
96
|
"access": "public"
|
|
@@ -98,5 +98,5 @@
|
|
|
98
98
|
"funding": [
|
|
99
99
|
"https://trpc.io/sponsor"
|
|
100
100
|
],
|
|
101
|
-
"gitHead": "
|
|
101
|
+
"gitHead": "9cdac1b53f02cceefe2fb9b01e20599b6faced60"
|
|
102
102
|
}
|
|
@@ -26,9 +26,11 @@ import {
|
|
|
26
26
|
} from './internals/TRPCUntypedClient';
|
|
27
27
|
import { TRPCClientError } from './TRPCClientError';
|
|
28
28
|
|
|
29
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* @public
|
|
31
|
+
**/
|
|
30
32
|
export type inferRouterProxyClient<TRouter extends AnyRouter> =
|
|
31
|
-
DecoratedProcedureRecord<TRouter['_def']['record']>;
|
|
33
|
+
DecoratedProcedureRecord<TRouter, TRouter['_def']['record']>;
|
|
32
34
|
|
|
33
35
|
/** @internal */
|
|
34
36
|
export type Resolver<TProcedure extends AnyProcedure> = (
|
|
@@ -66,9 +68,12 @@ type DecorateProcedure<TProcedure extends AnyProcedure> =
|
|
|
66
68
|
/**
|
|
67
69
|
* @internal
|
|
68
70
|
*/
|
|
69
|
-
type DecoratedProcedureRecord<
|
|
71
|
+
type DecoratedProcedureRecord<
|
|
72
|
+
TRouter extends AnyRouter,
|
|
73
|
+
TProcedures extends ProcedureRouterRecord,
|
|
74
|
+
> = {
|
|
70
75
|
[TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter
|
|
71
|
-
? DecoratedProcedureRecord<TProcedures[TKey]['_def']['record']>
|
|
76
|
+
? DecoratedProcedureRecord<TRouter, TProcedures[TKey]['_def']['record']>
|
|
72
77
|
: TProcedures[TKey] extends AnyProcedure
|
|
73
78
|
? DecorateProcedure<TProcedures[TKey]>
|
|
74
79
|
: never;
|
|
@@ -87,13 +92,14 @@ export const clientCallTypeToProcedureType = (
|
|
|
87
92
|
return clientCallTypeMap[clientCallType as keyof typeof clientCallTypeMap];
|
|
88
93
|
};
|
|
89
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Creates a proxy client and shows type errors if you have query names that collide with built-in properties
|
|
97
|
+
*/
|
|
90
98
|
export type CreateTRPCProxyClient<TRouter extends AnyRouter> =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
? TProcedureRecord
|
|
96
|
-
: IntersectionError<UntypedClientProperties & keyof TProcedureRecord>
|
|
99
|
+
inferRouterProxyClient<TRouter> extends infer $ProcedureRecord
|
|
100
|
+
? UntypedClientProperties & keyof $ProcedureRecord extends never
|
|
101
|
+
? inferRouterProxyClient<TRouter>
|
|
102
|
+
: IntersectionError<UntypedClientProperties & keyof $ProcedureRecord>
|
|
97
103
|
: never;
|
|
98
104
|
|
|
99
105
|
/**
|
|
@@ -102,11 +108,14 @@ export type CreateTRPCProxyClient<TRouter extends AnyRouter> =
|
|
|
102
108
|
*/
|
|
103
109
|
export function createTRPCClientProxy<TRouter extends AnyRouter>(
|
|
104
110
|
client: TRPCClient<TRouter>,
|
|
105
|
-
) {
|
|
111
|
+
): CreateTRPCProxyClient<TRouter> {
|
|
106
112
|
return createFlatProxy<CreateTRPCProxyClient<TRouter>>((key) => {
|
|
107
113
|
if (client.hasOwnProperty(key)) {
|
|
108
114
|
return (client as any)[key as any];
|
|
109
115
|
}
|
|
116
|
+
if (key === '__untypedClient') {
|
|
117
|
+
return client;
|
|
118
|
+
}
|
|
110
119
|
return createRecursiveProxy(({ path, args }) => {
|
|
111
120
|
const pathCopy = [key, ...path];
|
|
112
121
|
const procedureType = clientCallTypeToProcedureType(pathCopy.pop()!);
|
|
@@ -120,8 +129,18 @@ export function createTRPCClientProxy<TRouter extends AnyRouter>(
|
|
|
120
129
|
|
|
121
130
|
export function createTRPCProxyClient<TRouter extends AnyRouter>(
|
|
122
131
|
opts: CreateTRPCClientOptions<TRouter>,
|
|
123
|
-
) {
|
|
132
|
+
): CreateTRPCProxyClient<TRouter> {
|
|
124
133
|
const client = new TRPCUntypedClient(opts);
|
|
125
134
|
const proxy = createTRPCClientProxy(client as TRPCClient<TRouter>);
|
|
126
135
|
return proxy;
|
|
127
136
|
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Get an untyped client from a proxy client
|
|
140
|
+
* @internal
|
|
141
|
+
*/
|
|
142
|
+
export function getUntypedClient<TRouter extends AnyRouter>(
|
|
143
|
+
client: inferRouterProxyClient<TRouter>,
|
|
144
|
+
): TRPCUntypedClient<TRouter> {
|
|
145
|
+
return (client as any).__untypedClient;
|
|
146
|
+
}
|
|
@@ -6,9 +6,8 @@ import {
|
|
|
6
6
|
|
|
7
7
|
export function createTRPCUntypedClient<TRouter extends AnyRouter>(
|
|
8
8
|
opts: CreateTRPCClientOptions<TRouter>,
|
|
9
|
-
) {
|
|
10
|
-
|
|
11
|
-
return client;
|
|
9
|
+
): TRPCUntypedClient<TRouter> {
|
|
10
|
+
return new TRPCUntypedClient(opts);
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
export type {
|
package/src/internals/types.ts
CHANGED
|
@@ -72,12 +72,20 @@ export interface RequestInitEsque {
|
|
|
72
72
|
signal?: AbortSignal | null;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* A subset of the standard ReadableStream properties needed by tRPC internally.
|
|
77
|
+
* @see ReadableStream from lib.dom.d.ts
|
|
78
|
+
*/
|
|
79
|
+
export type WebReadableStreamEsque = {
|
|
80
|
+
getReader: () => ReadableStreamDefaultReader<Uint8Array>;
|
|
81
|
+
};
|
|
82
|
+
|
|
75
83
|
/**
|
|
76
84
|
* A subset of the standard Response properties needed by tRPC internally.
|
|
77
85
|
* @see Response from lib.dom.d.ts
|
|
78
86
|
*/
|
|
79
87
|
export interface ResponseEsque {
|
|
80
|
-
readonly body?:
|
|
88
|
+
readonly body?: WebReadableStreamEsque | NodeJS.ReadableStream | null;
|
|
81
89
|
/**
|
|
82
90
|
* @remarks
|
|
83
91
|
* The built-in Response::json() method returns Promise<any>, but
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Stream parsing adapted from https://www.loginradius.com/blog/engineering/guest-post/http-streaming-with-nodejs-and-fetch-api/
|
|
2
|
-
|
|
3
2
|
import { TRPCResponse } from '@trpc/server/rpc';
|
|
3
|
+
import { WebReadableStreamEsque } from '../../internals/types';
|
|
4
4
|
import { HTTPHeaders } from '../types';
|
|
5
5
|
import {
|
|
6
6
|
fetchHTTPResponse,
|
|
@@ -26,7 +26,7 @@ export async function parseJSONStream<TReturn>(opts: {
|
|
|
26
26
|
/**
|
|
27
27
|
* As given by `(await fetch(url)).body`
|
|
28
28
|
*/
|
|
29
|
-
readableStream:
|
|
29
|
+
readableStream: WebReadableStreamEsque | NodeJS.ReadableStream;
|
|
30
30
|
/**
|
|
31
31
|
* Called for each line of the stream
|
|
32
32
|
*/
|
|
@@ -69,7 +69,7 @@ export async function parseJSONStream<TReturn>(opts: {
|
|
|
69
69
|
* @param onLine will be called for every line ('\n' delimited) in the stream
|
|
70
70
|
*/
|
|
71
71
|
async function readLines(
|
|
72
|
-
readableStream:
|
|
72
|
+
readableStream: WebReadableStreamEsque | NodeJS.ReadableStream,
|
|
73
73
|
onLine: (line: string) => void,
|
|
74
74
|
textDecoder: TextDecoderEsque,
|
|
75
75
|
) {
|
|
@@ -119,7 +119,7 @@ function readNodeChunks(
|
|
|
119
119
|
* Handle WebAPI stream
|
|
120
120
|
*/
|
|
121
121
|
async function readStandardChunks(
|
|
122
|
-
stream:
|
|
122
|
+
stream: WebReadableStreamEsque,
|
|
123
123
|
onChunk: (chunk: Uint8Array) => void,
|
|
124
124
|
) {
|
|
125
125
|
const reader = stream.getReader();
|