@trpc/client 10.9.1 → 10.10.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 +2 -0
- package/dist/createTRPCClientProxy.d.ts.map +1 -1
- package/dist/getFetch.d.ts +2 -1
- package/dist/getFetch.d.ts.map +1 -1
- package/dist/{httpUtils-277fd63a.js → httpUtils-30a43613.js} +1 -1
- package/dist/{httpUtils-939364d7.mjs → httpUtils-9322dc79.mjs} +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/internals/fetchHelpers.d.ts +2 -1
- package/dist/internals/fetchHelpers.d.ts.map +1 -1
- package/dist/internals/types.d.ts +109 -0
- package/dist/internals/types.d.ts.map +1 -0
- package/dist/links/httpBatchLink.js +1 -1
- package/dist/links/httpBatchLink.mjs +1 -1
- package/dist/links/httpLink.js +1 -1
- package/dist/links/httpLink.mjs +1 -1
- package/dist/links/internals/httpUtils.d.ts +6 -5
- package/dist/links/internals/httpUtils.d.ts.map +1 -1
- package/dist/links/types.d.ts +2 -1
- package/dist/links/types.d.ts.map +1 -1
- package/package.json +10 -5
- package/src/createTRPCClientProxy.ts +4 -0
- package/src/getFetch.ts +8 -5
- package/src/internals/fetchHelpers.ts +3 -2
- package/src/internals/types.test.ts +56 -0
- package/src/internals/types.ts +142 -0
- package/src/links/internals/httpUtils.ts +11 -6
- package/src/links/types.ts +2 -1
|
@@ -5,6 +5,8 @@ import { TRPCClientError } from './TRPCClientError';
|
|
|
5
5
|
import { TRPCClient } from './createTRPCClient';
|
|
6
6
|
import { CreateTRPCClientOptions } from './createTRPCUntypedClient';
|
|
7
7
|
import { TRPCSubscriptionObserver, UntypedClientProperties } from './internals/TRPCUntypedClient';
|
|
8
|
+
/** @public */
|
|
9
|
+
export declare type inferRouterProxyClient<TRouter extends AnyRouter> = DecoratedProcedureRecord<TRouter['_def']['record'], TRouter>;
|
|
8
10
|
declare type Resolver<TProcedure extends AnyProcedure> = (...args: ProcedureArgs<TProcedure['_def']>) => Promise<inferTransformedProcedureOutput<TProcedure>>;
|
|
9
11
|
declare type SubscriptionResolver<TProcedure extends AnyProcedure, TRouter extends AnyRouter> = (...args: [
|
|
10
12
|
input: ProcedureArgs<TProcedure['_def']>[0],
|
|
@@ -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,EAEtB,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,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EACL,wBAAwB,EAExB,uBAAuB,EACxB,MAAM,+BAA+B,CAAC;AAEvC,aAAK,QAAQ,CAAC,UAAU,SAAS,YAAY,IAAI,CAC/C,GAAG,IAAI,EAAE,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,KACvC,OAAO,CAAC,+BAA+B,CAAC,UAAU,CAAC,CAAC,CAAC;AAE1D,aAAK,oBAAoB,CACvB,UAAU,SAAS,YAAY,EAC/B,OAAO,SAAS,SAAS,IACvB,CACF,GAAG,IAAI,EAAE;IACP,KAAK,EAAE,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3C,IAAI,EAAE,aAAa,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,GAC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AAM,gBAAgB,CAAC,GACrE,KAAK,CAAC;AAEZ;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,SAAS,EAC7D,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,kCAoB5B;AAED,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,SAAS,EAC7D,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,kCAKvC"}
|
package/dist/getFetch.d.ts
CHANGED
package/dist/getFetch.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFetch.d.ts","sourceRoot":"","sources":["../src/getFetch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getFetch.d.ts","sourceRoot":"","sources":["../src/getFetch.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAEjE,wBAAgB,QAAQ,CAAC,CAAC,CAAC,EAAE,UAAU,GAAG,gBAAgB,GAAG,UAAU,CAgBtE"}
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var observable = require('@trpc/server/observable');
|
|
|
6
6
|
var transformResult = require('./transformResult-e7a1e69e.js');
|
|
7
7
|
var links_splitLink = require('./splitLink-f29e84be.js');
|
|
8
8
|
var shared = require('@trpc/server/shared');
|
|
9
|
-
var httpUtils = require('./httpUtils-
|
|
9
|
+
var httpUtils = require('./httpUtils-30a43613.js');
|
|
10
10
|
var links_httpBatchLink = require('./links/httpBatchLink.js');
|
|
11
11
|
var links_httpLink = require('./links/httpLink.js');
|
|
12
12
|
var links_loggerLink = require('./links/loggerLink.js');
|
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ export { T as TRPCClientError } from './transformResult-6fb67924.mjs';
|
|
|
4
4
|
import { c as createChain } from './splitLink-4c75f7be.mjs';
|
|
5
5
|
export { s as splitLink } from './splitLink-4c75f7be.mjs';
|
|
6
6
|
import { createFlatProxy, createRecursiveProxy } from '@trpc/server/shared';
|
|
7
|
-
export { g as getFetch } from './httpUtils-
|
|
7
|
+
export { g as getFetch } from './httpUtils-9322dc79.mjs';
|
|
8
8
|
export { httpBatchLink } from './links/httpBatchLink.mjs';
|
|
9
9
|
export { httpLink } from './links/httpLink.mjs';
|
|
10
10
|
export { loggerLink } from './links/loggerLink.mjs';
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Maybe } from '@trpc/server';
|
|
2
|
+
import { AbortControllerEsque } from './types';
|
|
2
3
|
export declare function getWindow(): typeof globalThis;
|
|
3
|
-
export declare function getAbortController(ac: Maybe<
|
|
4
|
+
export declare function getAbortController(ac: Maybe<AbortControllerEsque>): AbortControllerEsque | null;
|
|
4
5
|
//# sourceMappingURL=fetchHelpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetchHelpers.d.ts","sourceRoot":"","sources":["../../src/internals/fetchHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"fetchHelpers.d.ts","sourceRoot":"","sources":["../../src/internals/fetchHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE/C,wBAAgB,SAAS,sBAKxB;AACD,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,KAAK,CAAC,oBAAoB,CAAC,GAC9B,oBAAoB,GAAG,IAAI,CAE7B"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
export interface AbortControllerEsque {
|
|
2
|
+
new (): AbortControllerInstanceEsque;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Allows you to abort one or more requests.
|
|
6
|
+
*/
|
|
7
|
+
export interface AbortControllerInstanceEsque {
|
|
8
|
+
/**
|
|
9
|
+
* The AbortSignal object associated with this object.
|
|
10
|
+
*/
|
|
11
|
+
readonly signal: AbortSignalEsque;
|
|
12
|
+
/**
|
|
13
|
+
* Sets this object's AbortSignal's aborted flag and signals to
|
|
14
|
+
* any observers that the associated activity is to be aborted.
|
|
15
|
+
*/
|
|
16
|
+
abort(): void;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Allows you to communicate with a request and abort it if required via an AbortController.
|
|
20
|
+
*/
|
|
21
|
+
export interface AbortSignalEsque {
|
|
22
|
+
/**
|
|
23
|
+
* Whether this signal's AbortController has signaled to abort.
|
|
24
|
+
*/
|
|
25
|
+
readonly aborted: boolean;
|
|
26
|
+
addEventListener<TEvent extends keyof AbortSignalEventMap>(type: TEvent, listener: (this: AbortSignal, ev: AbortSignalEventMap[TEvent]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A subset of the standard fetch function type needed by tRPC internally.
|
|
30
|
+
* @see fetch from lib.dom.d.ts
|
|
31
|
+
* @remarks
|
|
32
|
+
* If you need a property that you know exists but doesn't exist on this
|
|
33
|
+
* interface, go ahead and add it.
|
|
34
|
+
*/
|
|
35
|
+
export declare type FetchEsque = (input: RequestInfo | URL | string, init?: RequestInit | RequestInitEsque) => Promise<ResponseEsque>;
|
|
36
|
+
/**
|
|
37
|
+
* A simpler version of the native fetch function's type for packages with
|
|
38
|
+
* their own fetch types, such as undici and node-fetch.
|
|
39
|
+
*/
|
|
40
|
+
export declare type NativeFetchEsque = (url: string | URL, init?: NodeFetchRequestInitEsque) => Promise<ResponseEsque>;
|
|
41
|
+
export interface NodeFetchRequestInitEsque {
|
|
42
|
+
body?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* A subset of the standard Headers properties needed by tRPC internally.
|
|
46
|
+
* @see Headers from lib.dom.d.ts
|
|
47
|
+
* @remarks
|
|
48
|
+
* If you need a property that you know exists but doesn't exist on this
|
|
49
|
+
* interface, go ahead and add it.
|
|
50
|
+
*/
|
|
51
|
+
export interface HeadersEsque {
|
|
52
|
+
append(name: string, value: string): void;
|
|
53
|
+
delete(name: string): void;
|
|
54
|
+
get(name: string): string | null;
|
|
55
|
+
has(name: string): boolean;
|
|
56
|
+
set(name: string, value: string): void;
|
|
57
|
+
forEach(callbackfn: (value: string, key: string) => void, thisArg?: any): void;
|
|
58
|
+
}
|
|
59
|
+
export declare type ResponseType = 'basic' | 'cors' | 'default' | 'error' | 'opaque' | 'opaqueredirect';
|
|
60
|
+
/**
|
|
61
|
+
* A subset of the standard RequestInit properties needed by tRPC internally.
|
|
62
|
+
* @see RequestInit from lib.dom.d.ts
|
|
63
|
+
* @remarks
|
|
64
|
+
* If you need a property that you know exists but doesn't exist on this
|
|
65
|
+
* interface, go ahead and add it.
|
|
66
|
+
*/
|
|
67
|
+
export interface RequestInitEsque {
|
|
68
|
+
/**
|
|
69
|
+
* Sets the request's body.
|
|
70
|
+
*/
|
|
71
|
+
body?: string | ReadableStream | null;
|
|
72
|
+
/**
|
|
73
|
+
* Sets the request's associated headers.
|
|
74
|
+
*/
|
|
75
|
+
headers?: [string, string][] | Record<string, string>;
|
|
76
|
+
/**
|
|
77
|
+
* The request's HTTP-style method.
|
|
78
|
+
*/
|
|
79
|
+
method?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Sets the request's signal.
|
|
82
|
+
*/
|
|
83
|
+
signal?: AbortSignalEsque | null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* A subset of the standard Response properties needed by tRPC internally.
|
|
87
|
+
* @see Response from lib.dom.d.ts
|
|
88
|
+
* @remarks
|
|
89
|
+
* If you need a property that you know exists but doesn't exist on this
|
|
90
|
+
* interface, go ahead and add it.
|
|
91
|
+
*/
|
|
92
|
+
export interface ResponseEsque {
|
|
93
|
+
readonly headers: HeadersEsque;
|
|
94
|
+
readonly ok: boolean;
|
|
95
|
+
readonly redirected: boolean;
|
|
96
|
+
readonly status: number;
|
|
97
|
+
readonly statusText: string;
|
|
98
|
+
readonly type: ResponseType;
|
|
99
|
+
readonly url: string;
|
|
100
|
+
clone(): ResponseEsque;
|
|
101
|
+
/**
|
|
102
|
+
* @remarks
|
|
103
|
+
* The built-in Response::json() method returns Promise<any>, but
|
|
104
|
+
* that's not as type-safe as unknown. We use unknown because we're
|
|
105
|
+
* more type-safe. You do want more type safety, right? 😉
|
|
106
|
+
*/
|
|
107
|
+
json(): Promise<unknown>;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +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,gBAAgB,CAAC;IAElC;;;OAGG;IACH,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAE1B,gBAAgB,CAAC,MAAM,SAAS,MAAM,mBAAmB,EACvD,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,mBAAmB,CAAC,MAAM,CAAC,KAAK,GAAG,EACrE,OAAO,CAAC,EAAE,OAAO,GAAG,uBAAuB,GAC1C,IAAI,CAAC;CACT;AAED;;;;;;GAMG;AACH,oBAAY,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,oBAAY,gBAAgB,GAAG,CAC7B,GAAG,EAAE,MAAM,GAAG,GAAG,EACjB,IAAI,CAAC,EAAE,yBAAyB,KAC7B,OAAO,CAA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C7B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,YAAY,CAAC;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,KAAK,IAAI,aAAa,CAAC;IAEvB;;;;;OAKG;IACH,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1B"}
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var observable = require('@trpc/server/observable');
|
|
6
6
|
var transformResult = require('../transformResult-e7a1e69e.js');
|
|
7
|
-
var httpUtils = require('../httpUtils-
|
|
7
|
+
var httpUtils = require('../httpUtils-30a43613.js');
|
|
8
8
|
|
|
9
9
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */ /**
|
|
10
10
|
* A function that should never be called unless we messed something up.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { observable } from '@trpc/server/observable';
|
|
2
2
|
import { t as transformResult, T as TRPCClientError } from '../transformResult-6fb67924.mjs';
|
|
3
|
-
import { r as resolveHTTPLinkOptions, a as getUrl, h as httpRequest } from '../httpUtils-
|
|
3
|
+
import { r as resolveHTTPLinkOptions, a as getUrl, h as httpRequest } from '../httpUtils-9322dc79.mjs';
|
|
4
4
|
|
|
5
5
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */ /**
|
|
6
6
|
* A function that should never be called unless we messed something up.
|
package/dist/links/httpLink.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var observable = require('@trpc/server/observable');
|
|
6
6
|
var transformResult = require('../transformResult-e7a1e69e.js');
|
|
7
|
-
var httpUtils = require('../httpUtils-
|
|
7
|
+
var httpUtils = require('../httpUtils-30a43613.js');
|
|
8
8
|
|
|
9
9
|
function httpLink(opts) {
|
|
10
10
|
const resolvedOpts = httpUtils.resolveHTTPLinkOptions(opts);
|
package/dist/links/httpLink.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { observable } from '@trpc/server/observable';
|
|
2
2
|
import { t as transformResult, T as TRPCClientError } from '../transformResult-6fb67924.mjs';
|
|
3
|
-
import { r as resolveHTTPLinkOptions, h as httpRequest } from '../httpUtils-
|
|
3
|
+
import { r as resolveHTTPLinkOptions, h as httpRequest } from '../httpUtils-9322dc79.mjs';
|
|
4
4
|
|
|
5
5
|
function httpLink(opts) {
|
|
6
6
|
const resolvedOpts = resolveHTTPLinkOptions(opts);
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { ProcedureType } from '@trpc/server';
|
|
2
2
|
import { TRPCResponse } from '@trpc/server/rpc';
|
|
3
|
+
import { AbortControllerEsque, FetchEsque, ResponseEsque } from '../../internals/types';
|
|
3
4
|
import { HTTPHeaders, PromiseAndCancel, TRPCClientRuntime } from '../types';
|
|
4
5
|
export interface HTTPLinkOptions {
|
|
5
6
|
url: string;
|
|
6
7
|
/**
|
|
7
8
|
* Add ponyfill for fetch
|
|
8
9
|
*/
|
|
9
|
-
fetch?:
|
|
10
|
+
fetch?: FetchEsque;
|
|
10
11
|
/**
|
|
11
12
|
* Add ponyfill for AbortController
|
|
12
13
|
*/
|
|
13
|
-
AbortController?:
|
|
14
|
+
AbortController?: AbortControllerEsque | null;
|
|
14
15
|
/**
|
|
15
16
|
* Headers to be set on outgoing requests or a callback that of said headers
|
|
16
17
|
* @link http://trpc.io/docs/v10/header
|
|
@@ -19,8 +20,8 @@ export interface HTTPLinkOptions {
|
|
|
19
20
|
}
|
|
20
21
|
export interface ResolvedHTTPLinkOptions {
|
|
21
22
|
url: string;
|
|
22
|
-
fetch:
|
|
23
|
-
AbortController:
|
|
23
|
+
fetch: FetchEsque;
|
|
24
|
+
AbortController: AbortControllerEsque | null;
|
|
24
25
|
/**
|
|
25
26
|
* Headers to be set on outgoing request
|
|
26
27
|
* @link http://trpc.io/docs/v10/header
|
|
@@ -31,7 +32,7 @@ export declare function resolveHTTPLinkOptions(opts: HTTPLinkOptions): ResolvedH
|
|
|
31
32
|
export interface HTTPResult {
|
|
32
33
|
json: TRPCResponse;
|
|
33
34
|
meta: {
|
|
34
|
-
response:
|
|
35
|
+
response: ResponseEsque;
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
38
|
declare type GetInputOptions = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpUtils.d.ts","sourceRoot":"","sources":["../../../src/links/internals/httpUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE5E,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,KAAK,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"httpUtils.d.ts","sourceRoot":"","sources":["../../../src/links/internals/httpUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGhD,OAAO,EACL,oBAAoB,EACpB,UAAU,EACV,aAAa,EACd,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE5E,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB;;OAEG;IACH,eAAe,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAC9C;;;OAGG;IACH,OAAO,CAAC,EAAE,WAAW,GAAG,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;CACpE;AAED,MAAM,WAAW,uBAAuB;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,UAAU,CAAC;IAClB,eAAe,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAC7C;;;OAGG;IACH,OAAO,EAAE,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CACnD;AAED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,eAAe,GACpB,uBAAuB,CAQzB;AAiBD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE;QACJ,QAAQ,EAAE,aAAa,CAAC;KACzB,CAAC;CACH;AAED,aAAK,eAAe,GAAG;IACrB,OAAO,EAAE,iBAAiB,CAAC;CAC5B,GAAG,CAAC;IAAE,MAAM,EAAE,OAAO,EAAE,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAUjD,oBAAY,kBAAkB,GAAG,uBAAuB,GACtD,eAAe,GAAG;IAChB,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEJ,wBAAgB,MAAM,CAAC,IAAI,EAAE,kBAAkB,UAgB9C;AAED,aAAK,cAAc,GAAG;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GAAG,eAAe,CAAC;AAEhE,wBAAgB,OAAO,CAAC,IAAI,EAAE,cAAc,sBAM3C;AAED,wBAAgB,WAAW,CACzB,IAAI,EAAE,kBAAkB,GACvB,gBAAgB,CAAC,UAAU,CAAC,CAyC9B"}
|
package/dist/links/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { AnyRouter, DataTransformer } from '@trpc/server';
|
|
|
2
2
|
import { Observable, Observer } from '@trpc/server/observable';
|
|
3
3
|
import { TRPCResultMessage, TRPCSuccessResponse } from '@trpc/server/rpc';
|
|
4
4
|
import { TRPCClientError } from '../TRPCClientError';
|
|
5
|
+
import { ResponseEsque } from '../internals/types';
|
|
5
6
|
/**
|
|
6
7
|
* @internal
|
|
7
8
|
*/
|
|
@@ -35,7 +36,7 @@ export declare type HTTPHeaders = Record<string, string | string[] | undefined>;
|
|
|
35
36
|
* The default `fetch` implementation has an overloaded signature. By convention this library
|
|
36
37
|
* only uses the overload taking a string and options object.
|
|
37
38
|
*/
|
|
38
|
-
export declare type TRPCFetch = (url: string, options?: RequestInit) => Promise<
|
|
39
|
+
export declare type TRPCFetch = (url: string, options?: RequestInit) => Promise<ResponseEsque>;
|
|
39
40
|
export interface TRPCClientRuntime {
|
|
40
41
|
transformer: DataTransformer;
|
|
41
42
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/links/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/links/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,oBAAY,QAAQ,GAAG,MAAM,IAAI,CAAC;AAElC;;GAEG;AACH,oBAAY,gBAAgB,C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,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;AAEzE;;GAEG;AACH,oBAAY,aAAa,CACvB,OAAO,SAAS,SAAS,EACzB,MAAM,GAAG,OAAO,EAChB,OAAO,GAAG,OAAO,IACf,CAAC,IAAI,EAAE;IACT,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;IACtB,IAAI,EAAE,CAAC,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,KAAK,yBAAyB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;CAC9E,KAAK,yBAAyB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAElD;;GAEG;AACH,oBAAY,QAAQ,CAAC,OAAO,SAAS,SAAS,IAAI,CAChD,IAAI,EAAE,iBAAiB,KACpB,aAAa,CAAC,OAAO,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/client",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.10.0",
|
|
4
4
|
"description": "tRPC Client lib",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -69,18 +69,23 @@
|
|
|
69
69
|
"links"
|
|
70
70
|
],
|
|
71
71
|
"peerDependencies": {
|
|
72
|
-
"@trpc/server": "10.
|
|
72
|
+
"@trpc/server": "10.10.0"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@testing-library/dom": "^8.18.1",
|
|
76
|
-
"@trpc/server": "10.
|
|
76
|
+
"@trpc/server": "10.10.0",
|
|
77
|
+
"@types/isomorphic-fetch": "^0.0.36",
|
|
77
78
|
"@types/node": "^18.7.20",
|
|
79
|
+
"abort-controller": "^3.0.0",
|
|
78
80
|
"eslint": "^8.30.0",
|
|
81
|
+
"expect-type": "^0.15.0",
|
|
82
|
+
"isomorphic-fetch": "^3.0.0",
|
|
79
83
|
"rollup": "^2.79.1",
|
|
80
|
-
"tsx": "^3.9.0"
|
|
84
|
+
"tsx": "^3.9.0",
|
|
85
|
+
"undici": "^5.14.0"
|
|
81
86
|
},
|
|
82
87
|
"publishConfig": {
|
|
83
88
|
"access": "public"
|
|
84
89
|
},
|
|
85
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "ca69d4acfe7be286afcd06a39b652194ca6a87d9"
|
|
86
91
|
}
|
|
@@ -26,6 +26,10 @@ import {
|
|
|
26
26
|
UntypedClientProperties,
|
|
27
27
|
} from './internals/TRPCUntypedClient';
|
|
28
28
|
|
|
29
|
+
/** @public */
|
|
30
|
+
export type inferRouterProxyClient<TRouter extends AnyRouter> =
|
|
31
|
+
DecoratedProcedureRecord<TRouter['_def']['record'], TRouter>;
|
|
32
|
+
|
|
29
33
|
type Resolver<TProcedure extends AnyProcedure> = (
|
|
30
34
|
...args: ProcedureArgs<TProcedure['_def']>
|
|
31
35
|
) => Promise<inferTransformedProcedureOutput<TProcedure>>;
|
package/src/getFetch.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { getWindow } from './internals/fetchHelpers';
|
|
2
|
+
import { FetchEsque, NativeFetchEsque } from './internals/types';
|
|
2
3
|
|
|
3
|
-
export function getFetch(f?:
|
|
4
|
+
export function getFetch(f?: FetchEsque | NativeFetchEsque): FetchEsque {
|
|
4
5
|
if (f) {
|
|
5
|
-
return f;
|
|
6
|
+
return f as FetchEsque;
|
|
6
7
|
}
|
|
7
8
|
|
|
8
9
|
const win = getWindow();
|
|
9
10
|
const globalFetch = win.fetch;
|
|
10
11
|
if (globalFetch) {
|
|
11
|
-
return
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
return (
|
|
13
|
+
typeof globalFetch.bind === 'function'
|
|
14
|
+
? globalFetch.bind(win)
|
|
15
|
+
: globalFetch
|
|
16
|
+
) as FetchEsque;
|
|
14
17
|
}
|
|
15
18
|
|
|
16
19
|
throw new Error('No fetch implementation found');
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Maybe } from '@trpc/server';
|
|
2
|
+
import { AbortControllerEsque } from './types';
|
|
2
3
|
|
|
3
4
|
export function getWindow() {
|
|
4
5
|
if (typeof window !== 'undefined') {
|
|
@@ -7,7 +8,7 @@ export function getWindow() {
|
|
|
7
8
|
return globalThis;
|
|
8
9
|
}
|
|
9
10
|
export function getAbortController(
|
|
10
|
-
ac: Maybe<
|
|
11
|
-
):
|
|
11
|
+
ac: Maybe<AbortControllerEsque>,
|
|
12
|
+
): AbortControllerEsque | null {
|
|
12
13
|
return ac ?? getWindow().AbortController ?? null;
|
|
13
14
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { expectTypeOf } from 'expect-type';
|
|
2
|
+
import isomorphicFetch from 'isomorphic-fetch';
|
|
3
|
+
import nodeFetch from 'node-fetch';
|
|
4
|
+
import type { fetch as undiciFetch } from 'undici';
|
|
5
|
+
import { getFetch } from '../getFetch';
|
|
6
|
+
import { getAbortController } from './fetchHelpers';
|
|
7
|
+
import {
|
|
8
|
+
AbortControllerEsque,
|
|
9
|
+
AbortControllerInstanceEsque,
|
|
10
|
+
FetchEsque,
|
|
11
|
+
ResponseEsque,
|
|
12
|
+
} from './types';
|
|
13
|
+
|
|
14
|
+
describe('AbortController', () => {
|
|
15
|
+
test('AbortControllerEsque', () => {
|
|
16
|
+
expectTypeOf(
|
|
17
|
+
getAbortController,
|
|
18
|
+
).returns.toEqualTypeOf<AbortControllerEsque | null>();
|
|
19
|
+
|
|
20
|
+
getAbortController(
|
|
21
|
+
null as unknown as typeof import('abort-controller')['AbortController'],
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
expectTypeOf(() => {
|
|
25
|
+
const AbortController = getAbortController(undefined)!;
|
|
26
|
+
return new AbortController();
|
|
27
|
+
}).returns.toEqualTypeOf<AbortControllerInstanceEsque>();
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('fetch', () => {
|
|
32
|
+
test('FetchEsque', () => {
|
|
33
|
+
expectTypeOf(getFetch).returns.toEqualTypeOf<FetchEsque>();
|
|
34
|
+
|
|
35
|
+
expectTypeOf(() =>
|
|
36
|
+
getFetch()('', {
|
|
37
|
+
body: '',
|
|
38
|
+
headers: Math.random() > 0.5 ? [['a', 'b']] : { a: 'b' },
|
|
39
|
+
method: 'GET',
|
|
40
|
+
signal: new AbortSignal(),
|
|
41
|
+
}),
|
|
42
|
+
).returns.toEqualTypeOf<Promise<ResponseEsque>>();
|
|
43
|
+
|
|
44
|
+
getFetch({} as unknown as typeof fetch);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('NativeFetchEsque', () => {
|
|
48
|
+
getFetch(isomorphicFetch);
|
|
49
|
+
getFetch(nodeFetch);
|
|
50
|
+
|
|
51
|
+
// Passing in undiciFetch directly in Node v18.7.0 gives:
|
|
52
|
+
// ReferenceError: TextEncoder is not defined
|
|
53
|
+
// 🤷
|
|
54
|
+
getFetch({} as unknown as typeof undiciFetch);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
export interface AbortControllerEsque {
|
|
2
|
+
new (): AbortControllerInstanceEsque;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Allows you to abort one or more requests.
|
|
7
|
+
*/
|
|
8
|
+
export interface AbortControllerInstanceEsque {
|
|
9
|
+
/**
|
|
10
|
+
* The AbortSignal object associated with this object.
|
|
11
|
+
*/
|
|
12
|
+
readonly signal: AbortSignalEsque;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Sets this object's AbortSignal's aborted flag and signals to
|
|
16
|
+
* any observers that the associated activity is to be aborted.
|
|
17
|
+
*/
|
|
18
|
+
abort(): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Allows you to communicate with a request and abort it if required via an AbortController.
|
|
23
|
+
*/
|
|
24
|
+
export interface AbortSignalEsque {
|
|
25
|
+
/**
|
|
26
|
+
* Whether this signal's AbortController has signaled to abort.
|
|
27
|
+
*/
|
|
28
|
+
readonly aborted: boolean;
|
|
29
|
+
|
|
30
|
+
addEventListener<TEvent extends keyof AbortSignalEventMap>(
|
|
31
|
+
type: TEvent,
|
|
32
|
+
listener: (this: AbortSignal, ev: AbortSignalEventMap[TEvent]) => any,
|
|
33
|
+
options?: boolean | AddEventListenerOptions,
|
|
34
|
+
): void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A subset of the standard fetch function type needed by tRPC internally.
|
|
39
|
+
* @see fetch from lib.dom.d.ts
|
|
40
|
+
* @remarks
|
|
41
|
+
* If you need a property that you know exists but doesn't exist on this
|
|
42
|
+
* interface, go ahead and add it.
|
|
43
|
+
*/
|
|
44
|
+
export type FetchEsque = (
|
|
45
|
+
input: RequestInfo | URL | string,
|
|
46
|
+
init?: RequestInit | RequestInitEsque,
|
|
47
|
+
) => Promise<ResponseEsque>;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* A simpler version of the native fetch function's type for packages with
|
|
51
|
+
* their own fetch types, such as undici and node-fetch.
|
|
52
|
+
*/
|
|
53
|
+
export type NativeFetchEsque = (
|
|
54
|
+
url: string | URL,
|
|
55
|
+
init?: NodeFetchRequestInitEsque,
|
|
56
|
+
) => Promise<ResponseEsque>;
|
|
57
|
+
|
|
58
|
+
export interface NodeFetchRequestInitEsque {
|
|
59
|
+
body?: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* A subset of the standard Headers properties needed by tRPC internally.
|
|
64
|
+
* @see Headers from lib.dom.d.ts
|
|
65
|
+
* @remarks
|
|
66
|
+
* If you need a property that you know exists but doesn't exist on this
|
|
67
|
+
* interface, go ahead and add it.
|
|
68
|
+
*/
|
|
69
|
+
export interface HeadersEsque {
|
|
70
|
+
append(name: string, value: string): void;
|
|
71
|
+
delete(name: string): void;
|
|
72
|
+
get(name: string): string | null;
|
|
73
|
+
has(name: string): boolean;
|
|
74
|
+
set(name: string, value: string): void;
|
|
75
|
+
forEach(
|
|
76
|
+
callbackfn: (value: string, key: string) => void,
|
|
77
|
+
thisArg?: any,
|
|
78
|
+
): void;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export type ResponseType =
|
|
82
|
+
| 'basic'
|
|
83
|
+
| 'cors'
|
|
84
|
+
| 'default'
|
|
85
|
+
| 'error'
|
|
86
|
+
| 'opaque'
|
|
87
|
+
| 'opaqueredirect';
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* A subset of the standard RequestInit properties needed by tRPC internally.
|
|
91
|
+
* @see RequestInit from lib.dom.d.ts
|
|
92
|
+
* @remarks
|
|
93
|
+
* If you need a property that you know exists but doesn't exist on this
|
|
94
|
+
* interface, go ahead and add it.
|
|
95
|
+
*/
|
|
96
|
+
export interface RequestInitEsque {
|
|
97
|
+
/**
|
|
98
|
+
* Sets the request's body.
|
|
99
|
+
*/
|
|
100
|
+
body?: string | ReadableStream | null;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Sets the request's associated headers.
|
|
104
|
+
*/
|
|
105
|
+
headers?: [string, string][] | Record<string, string>;
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The request's HTTP-style method.
|
|
109
|
+
*/
|
|
110
|
+
method?: string;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Sets the request's signal.
|
|
114
|
+
*/
|
|
115
|
+
signal?: AbortSignalEsque | null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* A subset of the standard Response properties needed by tRPC internally.
|
|
120
|
+
* @see Response from lib.dom.d.ts
|
|
121
|
+
* @remarks
|
|
122
|
+
* If you need a property that you know exists but doesn't exist on this
|
|
123
|
+
* interface, go ahead and add it.
|
|
124
|
+
*/
|
|
125
|
+
export interface ResponseEsque {
|
|
126
|
+
readonly headers: HeadersEsque;
|
|
127
|
+
readonly ok: boolean;
|
|
128
|
+
readonly redirected: boolean;
|
|
129
|
+
readonly status: number;
|
|
130
|
+
readonly statusText: string;
|
|
131
|
+
readonly type: ResponseType;
|
|
132
|
+
readonly url: string;
|
|
133
|
+
clone(): ResponseEsque;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @remarks
|
|
137
|
+
* The built-in Response::json() method returns Promise<any>, but
|
|
138
|
+
* that's not as type-safe as unknown. We use unknown because we're
|
|
139
|
+
* more type-safe. You do want more type safety, right? 😉
|
|
140
|
+
*/
|
|
141
|
+
json(): Promise<unknown>;
|
|
142
|
+
}
|
|
@@ -2,6 +2,11 @@ import { ProcedureType } from '@trpc/server';
|
|
|
2
2
|
import { TRPCResponse } from '@trpc/server/rpc';
|
|
3
3
|
import { getFetch } from '../../getFetch';
|
|
4
4
|
import { getAbortController } from '../../internals/fetchHelpers';
|
|
5
|
+
import {
|
|
6
|
+
AbortControllerEsque,
|
|
7
|
+
FetchEsque,
|
|
8
|
+
ResponseEsque,
|
|
9
|
+
} from '../../internals/types';
|
|
5
10
|
import { HTTPHeaders, PromiseAndCancel, TRPCClientRuntime } from '../types';
|
|
6
11
|
|
|
7
12
|
export interface HTTPLinkOptions {
|
|
@@ -9,11 +14,11 @@ export interface HTTPLinkOptions {
|
|
|
9
14
|
/**
|
|
10
15
|
* Add ponyfill for fetch
|
|
11
16
|
*/
|
|
12
|
-
fetch?:
|
|
17
|
+
fetch?: FetchEsque;
|
|
13
18
|
/**
|
|
14
19
|
* Add ponyfill for AbortController
|
|
15
20
|
*/
|
|
16
|
-
AbortController?:
|
|
21
|
+
AbortController?: AbortControllerEsque | null;
|
|
17
22
|
/**
|
|
18
23
|
* Headers to be set on outgoing requests or a callback that of said headers
|
|
19
24
|
* @link http://trpc.io/docs/v10/header
|
|
@@ -23,8 +28,8 @@ export interface HTTPLinkOptions {
|
|
|
23
28
|
|
|
24
29
|
export interface ResolvedHTTPLinkOptions {
|
|
25
30
|
url: string;
|
|
26
|
-
fetch:
|
|
27
|
-
AbortController:
|
|
31
|
+
fetch: FetchEsque;
|
|
32
|
+
AbortController: AbortControllerEsque | null;
|
|
28
33
|
/**
|
|
29
34
|
* Headers to be set on outgoing request
|
|
30
35
|
* @link http://trpc.io/docs/v10/header
|
|
@@ -62,7 +67,7 @@ const METHOD = {
|
|
|
62
67
|
export interface HTTPResult {
|
|
63
68
|
json: TRPCResponse;
|
|
64
69
|
meta: {
|
|
65
|
-
response:
|
|
70
|
+
response: ResponseEsque;
|
|
66
71
|
};
|
|
67
72
|
}
|
|
68
73
|
|
|
@@ -145,7 +150,7 @@ export function httpRequest(
|
|
|
145
150
|
})
|
|
146
151
|
.then((json) => {
|
|
147
152
|
resolve({
|
|
148
|
-
json,
|
|
153
|
+
json: json as TRPCResponse,
|
|
149
154
|
meta,
|
|
150
155
|
});
|
|
151
156
|
})
|
package/src/links/types.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { AnyRouter, DataTransformer } from '@trpc/server';
|
|
|
2
2
|
import { Observable, Observer } from '@trpc/server/observable';
|
|
3
3
|
import { TRPCResultMessage, TRPCSuccessResponse } from '@trpc/server/rpc';
|
|
4
4
|
import { TRPCClientError } from '../TRPCClientError';
|
|
5
|
+
import { ResponseEsque } from '../internals/types';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* @internal
|
|
@@ -43,7 +44,7 @@ export type HTTPHeaders = Record<string, string | string[] | undefined>;
|
|
|
43
44
|
export type TRPCFetch = (
|
|
44
45
|
url: string,
|
|
45
46
|
options?: RequestInit,
|
|
46
|
-
) => Promise<
|
|
47
|
+
) => Promise<ResponseEsque>;
|
|
47
48
|
|
|
48
49
|
export interface TRPCClientRuntime {
|
|
49
50
|
transformer: DataTransformer;
|