@trpc/client 10.19.1 → 10.20.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 +8 -8
- package/dist/createTRPCClientProxy.d.ts.map +1 -1
- package/dist/{httpUtils-b67e2601.js → httpUtils-0c7ec827.js} +1 -3
- package/dist/{httpUtils-05eea0cb.js → httpUtils-0e44d50d.js} +0 -2
- package/dist/{httpUtils-9b676ab4.mjs → httpUtils-f08fd191.mjs} +1 -3
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/dist/internals/types.d.ts +4 -0
- package/dist/internals/types.d.ts.map +1 -1
- package/dist/links/httpBatchLink.d.ts +11 -3
- package/dist/links/httpBatchLink.d.ts.map +1 -1
- package/dist/links/httpBatchLink.js +13 -2
- package/dist/links/httpBatchLink.mjs +13 -2
- package/dist/links/httpLink.d.ts +11 -2
- package/dist/links/httpLink.d.ts.map +1 -1
- package/dist/links/httpLink.js +13 -2
- package/dist/links/httpLink.mjs +13 -2
- package/dist/links/internals/httpUtils.d.ts +12 -14
- package/dist/links/internals/httpUtils.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/createTRPCClientProxy.ts +23 -41
- package/src/internals/types.ts +5 -0
- package/src/links/httpBatchLink.ts +30 -12
- package/src/links/httpLink.ts +25 -2
- package/src/links/internals/httpUtils.ts +14 -16
|
@@ -6,26 +6,26 @@ import { TRPCClient } from './createTRPCClient';
|
|
|
6
6
|
import { CreateTRPCClientOptions } from './createTRPCUntypedClient';
|
|
7
7
|
import { TRPCSubscriptionObserver, UntypedClientProperties } from './internals/TRPCUntypedClient';
|
|
8
8
|
/** @public */
|
|
9
|
-
export declare type inferRouterProxyClient<TRouter extends AnyRouter> = DecoratedProcedureRecord<TRouter['_def']['record']
|
|
9
|
+
export declare type inferRouterProxyClient<TRouter extends AnyRouter> = DecoratedProcedureRecord<TRouter['_def']['record']>;
|
|
10
10
|
declare type Resolver<TProcedure extends AnyProcedure> = (...args: ProcedureArgs<TProcedure['_def']>) => Promise<inferTransformedProcedureOutput<TProcedure>>;
|
|
11
|
-
declare type SubscriptionResolver<TProcedure extends AnyProcedure
|
|
11
|
+
declare type SubscriptionResolver<TProcedure extends AnyProcedure> = (...args: [
|
|
12
12
|
input: ProcedureArgs<TProcedure['_def']>[0],
|
|
13
|
-
opts: ProcedureArgs<TProcedure['_def']>[1] & Partial<TRPCSubscriptionObserver<inferTransformedSubscriptionOutput<TProcedure>, TRPCClientError<
|
|
13
|
+
opts: ProcedureArgs<TProcedure['_def']>[1] & Partial<TRPCSubscriptionObserver<inferTransformedSubscriptionOutput<TProcedure>, TRPCClientError<TProcedure>>>
|
|
14
14
|
]) => Unsubscribable;
|
|
15
|
-
declare type DecorateProcedure<TProcedure extends AnyProcedure
|
|
15
|
+
declare type DecorateProcedure<TProcedure extends AnyProcedure> = TProcedure extends AnyQueryProcedure ? {
|
|
16
16
|
query: Resolver<TProcedure>;
|
|
17
17
|
} : TProcedure extends AnyMutationProcedure ? {
|
|
18
18
|
mutate: Resolver<TProcedure>;
|
|
19
19
|
} : TProcedure extends AnySubscriptionProcedure ? {
|
|
20
|
-
subscribe: SubscriptionResolver<TProcedure
|
|
20
|
+
subscribe: SubscriptionResolver<TProcedure>;
|
|
21
21
|
} : never;
|
|
22
22
|
/**
|
|
23
23
|
* @internal
|
|
24
24
|
*/
|
|
25
|
-
declare type DecoratedProcedureRecord<TProcedures extends ProcedureRouterRecord
|
|
26
|
-
[TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter ? DecoratedProcedureRecord<TProcedures[TKey]['_def']['record']
|
|
25
|
+
declare type DecoratedProcedureRecord<TProcedures extends ProcedureRouterRecord> = {
|
|
26
|
+
[TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter ? DecoratedProcedureRecord<TProcedures[TKey]['_def']['record']> : TProcedures[TKey] extends AnyProcedure ? DecorateProcedure<TProcedures[TKey]> : never;
|
|
27
27
|
};
|
|
28
|
-
export declare type CreateTRPCProxyClient<TRouter extends AnyRouter> = DecoratedProcedureRecord<TRouter['_def']['record']
|
|
28
|
+
export declare type CreateTRPCProxyClient<TRouter extends AnyRouter> = DecoratedProcedureRecord<TRouter['_def']['record']> extends infer TProcedureRecord ? UntypedClientProperties & keyof TProcedureRecord extends never ? TProcedureRecord : IntersectionError<UntypedClientProperties & keyof TProcedureRecord> : never;
|
|
29
29
|
/**
|
|
30
30
|
* @deprecated use `createTRPCProxyClient` instead
|
|
31
31
|
* @internal
|
|
@@ -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,cAAc;AACd,oBAAY,sBAAsB,CAAC,OAAO,SAAS,SAAS,IAC1D,wBAAwB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,
|
|
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,wBA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S,oBAAoB,GACvC;IACE,MAAM,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAC;CAC9B,GACD,UAAU,SAAS,wBAAwB,GAC3C;IACE,SAAS,EAAE,oBAAoB,CAAC,UAAU,CAAC,CAAC;CAC7C,GACD,KAAK,CAAC;AAEZ;;GAEG;AACH,aAAK,wBAAwB,CAAC,WAAW,SAAS,qBAAqB,IAAI;KACxE,IAAI,IAAI,MAAM,WAAW,GAAG,WAAW,CAAC,IAAI,CAAC,SAAS,SAAS,GAC5D,wBAAwB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,GAC7D,WAAW,CAAC,IAAI,CAAC,SAAS,YAAY,GACtC,iBAAiB,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,GACpC,KAAK;CACV,CAAC;AAQF,oBAAY,qBAAqB,CAAC,OAAO,SAAS,SAAS,IACzD,wBAAwB,CACtB,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAC1B,SAAS,MAAM,gBAAgB,GAC5B,uBAAuB,GAAG,MAAM,gBAAgB,SAAS,KAAK,GAC5D,gBAAgB,GAChB,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,kCAiB5B;AAED,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,SAAS,EAC7D,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,kCAKvC"}
|
|
@@ -32,12 +32,10 @@ function getAbortController(customAbortControllerImpl) {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
function resolveHTTPLinkOptions(opts) {
|
|
35
|
-
const headers = opts.headers || (()=>({}));
|
|
36
35
|
return {
|
|
37
36
|
url: opts.url,
|
|
38
37
|
fetch: getFetch(opts.fetch),
|
|
39
|
-
AbortController: getAbortController(opts.AbortController)
|
|
40
|
-
headers: typeof headers === 'function' ? headers : ()=>headers
|
|
38
|
+
AbortController: getAbortController(opts.AbortController)
|
|
41
39
|
};
|
|
42
40
|
}
|
|
43
41
|
// https://github.com/trpc/trpc/pull/669
|
|
@@ -30,12 +30,10 @@ function getAbortController(customAbortControllerImpl) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
function resolveHTTPLinkOptions(opts) {
|
|
33
|
-
const headers = opts.headers || (() => ({}));
|
|
34
33
|
return {
|
|
35
34
|
url: opts.url,
|
|
36
35
|
fetch: getFetch(opts.fetch),
|
|
37
36
|
AbortController: getAbortController(opts.AbortController),
|
|
38
|
-
headers: typeof headers === 'function' ? headers : () => headers,
|
|
39
37
|
};
|
|
40
38
|
}
|
|
41
39
|
// https://github.com/trpc/trpc/pull/669
|
|
@@ -30,12 +30,10 @@ function getAbortController(customAbortControllerImpl) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
function resolveHTTPLinkOptions(opts) {
|
|
33
|
-
const headers = opts.headers || (()=>({}));
|
|
34
33
|
return {
|
|
35
34
|
url: opts.url,
|
|
36
35
|
fetch: getFetch(opts.fetch),
|
|
37
|
-
AbortController: getAbortController(opts.AbortController)
|
|
38
|
-
headers: typeof headers === 'function' ? headers : ()=>headers
|
|
36
|
+
AbortController: getAbortController(opts.AbortController)
|
|
39
37
|
};
|
|
40
38
|
}
|
|
41
39
|
// https://github.com/trpc/trpc/pull/669
|
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-0c7ec827.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-f08fd191.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 +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,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,CAAC,aAAa,CAAC,CAAC;AAE5B,MAAM,WAAW,yBAAyB;IACxC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,MAAM,WAAW,YAAY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} from '../internals/types';
|
|
3
|
+
import { HTTPLinkBaseOptions } from './internals/httpUtils';
|
|
4
|
+
import { HTTPHeaders, Operation, TRPCLink } from './types';
|
|
5
|
+
export interface HttpBatchLinkOptions extends HTTPLinkBaseOptions {
|
|
5
6
|
maxURLLength?: number;
|
|
7
|
+
/**
|
|
8
|
+
* Headers to be set on outgoing requests or a callback that of said headers
|
|
9
|
+
* @link http://trpc.io/docs/client/headers
|
|
10
|
+
*/
|
|
11
|
+
headers?: HTTPHeaders | ((opts: {
|
|
12
|
+
opList: NonEmptyArray<Operation>;
|
|
13
|
+
}) => HTTPHeaders | Promise<HTTPHeaders>);
|
|
6
14
|
}
|
|
7
15
|
export declare function httpBatchLink<TRouter extends AnyRouter>(opts: HttpBatchLinkOptions): TRPCLink<TRouter>;
|
|
8
16
|
//# sourceMappingURL=httpBatchLink.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpBatchLink.d.ts","sourceRoot":"","sources":["../../src/links/httpBatchLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAiB,MAAM,cAAc,CAAC;AAIxD,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"httpBatchLink.d.ts","sourceRoot":"","sources":["../../src/links/httpBatchLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAiB,MAAM,cAAc,CAAC;AAIxD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EACL,mBAAmB,EAKpB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE3D,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAC/D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;OAGG;IACH,OAAO,CAAC,EACJ,WAAW,GACX,CAAC,CAAC,IAAI,EAAE;QACN,MAAM,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC;KAClC,KAAK,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;CAC/C;AAED,wBAAgB,aAAa,CAAC,OAAO,SAAS,SAAS,EACrD,IAAI,EAAE,oBAAoB,GACzB,QAAQ,CAAC,OAAO,CAAC,CA2GnB"}
|
|
@@ -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-0c7ec827.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.
|
|
@@ -157,7 +157,18 @@ function httpBatchLink(opts) {
|
|
|
157
157
|
runtime,
|
|
158
158
|
type,
|
|
159
159
|
path,
|
|
160
|
-
inputs
|
|
160
|
+
inputs,
|
|
161
|
+
headers () {
|
|
162
|
+
if (!opts.headers) {
|
|
163
|
+
return {};
|
|
164
|
+
}
|
|
165
|
+
if (typeof opts.headers === 'function') {
|
|
166
|
+
return opts.headers({
|
|
167
|
+
opList: batchOps
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
return opts.headers;
|
|
171
|
+
}
|
|
161
172
|
});
|
|
162
173
|
return {
|
|
163
174
|
promise: promise.then((res)=>{
|
|
@@ -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-f08fd191.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.
|
|
@@ -153,7 +153,18 @@ function httpBatchLink(opts) {
|
|
|
153
153
|
runtime,
|
|
154
154
|
type,
|
|
155
155
|
path,
|
|
156
|
-
inputs
|
|
156
|
+
inputs,
|
|
157
|
+
headers () {
|
|
158
|
+
if (!opts.headers) {
|
|
159
|
+
return {};
|
|
160
|
+
}
|
|
161
|
+
if (typeof opts.headers === 'function') {
|
|
162
|
+
return opts.headers({
|
|
163
|
+
opList: batchOps
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return opts.headers;
|
|
167
|
+
}
|
|
157
168
|
});
|
|
158
169
|
return {
|
|
159
170
|
promise: promise.then((res)=>{
|
package/dist/links/httpLink.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { AnyRouter } from '@trpc/server';
|
|
2
|
-
import {
|
|
3
|
-
import { TRPCLink } from './types';
|
|
2
|
+
import { HTTPLinkBaseOptions } from './internals/httpUtils';
|
|
3
|
+
import { HTTPHeaders, Operation, TRPCLink } from './types';
|
|
4
|
+
export interface HTTPLinkOptions extends HTTPLinkBaseOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Headers to be set on outgoing requests or a callback that of said headers
|
|
7
|
+
* @link http://trpc.io/docs/client/headers
|
|
8
|
+
*/
|
|
9
|
+
headers?: HTTPHeaders | ((opts: {
|
|
10
|
+
op: Operation;
|
|
11
|
+
}) => HTTPHeaders | Promise<HTTPHeaders>);
|
|
12
|
+
}
|
|
4
13
|
export declare function httpLink<TRouter extends AnyRouter>(opts: HTTPLinkOptions): TRPCLink<TRouter>;
|
|
5
14
|
//# sourceMappingURL=httpLink.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpLink.d.ts","sourceRoot":"","sources":["../../src/links/httpLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"httpLink.d.ts","sourceRoot":"","sources":["../../src/links/httpLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EACL,mBAAmB,EAGpB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE3D,MAAM,WAAW,eAAgB,SAAQ,mBAAmB;IAC1D;;;OAGG;IACH,OAAO,CAAC,EACJ,WAAW,GACX,CAAC,CAAC,IAAI,EAAE;QAAE,EAAE,EAAE,SAAS,CAAA;KAAE,KAAK,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;CACvE;AAED,wBAAgB,QAAQ,CAAC,OAAO,SAAS,SAAS,EAChD,IAAI,EAAE,eAAe,GACpB,QAAQ,CAAC,OAAO,CAAC,CAkDnB"}
|
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-0c7ec827.js');
|
|
8
8
|
|
|
9
9
|
function httpLink(opts) {
|
|
10
10
|
const resolvedOpts = httpUtils.resolveHTTPLinkOptions(opts);
|
|
@@ -15,7 +15,18 @@ function httpLink(opts) {
|
|
|
15
15
|
runtime,
|
|
16
16
|
type,
|
|
17
17
|
path,
|
|
18
|
-
input
|
|
18
|
+
input,
|
|
19
|
+
headers () {
|
|
20
|
+
if (!opts.headers) {
|
|
21
|
+
return {};
|
|
22
|
+
}
|
|
23
|
+
if (typeof opts.headers === 'function') {
|
|
24
|
+
return opts.headers({
|
|
25
|
+
op
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return opts.headers;
|
|
29
|
+
}
|
|
19
30
|
});
|
|
20
31
|
promise.then((res)=>{
|
|
21
32
|
const transformed = transformResult.transformResult(res.json, runtime);
|
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-f08fd191.mjs';
|
|
4
4
|
|
|
5
5
|
function httpLink(opts) {
|
|
6
6
|
const resolvedOpts = resolveHTTPLinkOptions(opts);
|
|
@@ -11,7 +11,18 @@ function httpLink(opts) {
|
|
|
11
11
|
runtime,
|
|
12
12
|
type,
|
|
13
13
|
path,
|
|
14
|
-
input
|
|
14
|
+
input,
|
|
15
|
+
headers () {
|
|
16
|
+
if (!opts.headers) {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
if (typeof opts.headers === 'function') {
|
|
20
|
+
return opts.headers({
|
|
21
|
+
op
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return opts.headers;
|
|
25
|
+
}
|
|
15
26
|
});
|
|
16
27
|
promise.then((res)=>{
|
|
17
28
|
const transformed = transformResult(res.json, runtime);
|
|
@@ -2,7 +2,10 @@ import { ProcedureType } from '@trpc/server';
|
|
|
2
2
|
import { TRPCResponse } from '@trpc/server/rpc';
|
|
3
3
|
import { AbortControllerEsque, FetchEsque, ResponseEsque } from '../../internals/types';
|
|
4
4
|
import { HTTPHeaders, PromiseAndCancel, TRPCClientRuntime } from '../types';
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export interface HTTPLinkBaseOptions {
|
|
6
9
|
url: string;
|
|
7
10
|
/**
|
|
8
11
|
* Add ponyfill for fetch
|
|
@@ -12,23 +15,13 @@ export interface HTTPLinkOptions {
|
|
|
12
15
|
* Add ponyfill for AbortController
|
|
13
16
|
*/
|
|
14
17
|
AbortController?: AbortControllerEsque | null;
|
|
15
|
-
/**
|
|
16
|
-
* Headers to be set on outgoing requests or a callback that of said headers
|
|
17
|
-
* @link http://trpc.io/docs/v10/header
|
|
18
|
-
*/
|
|
19
|
-
headers?: HTTPHeaders | (() => HTTPHeaders | Promise<HTTPHeaders>);
|
|
20
18
|
}
|
|
21
19
|
export interface ResolvedHTTPLinkOptions {
|
|
22
20
|
url: string;
|
|
23
21
|
fetch: FetchEsque;
|
|
24
22
|
AbortController: AbortControllerEsque | null;
|
|
25
|
-
/**
|
|
26
|
-
* Headers to be set on outgoing request
|
|
27
|
-
* @link http://trpc.io/docs/v10/header
|
|
28
|
-
*/
|
|
29
|
-
headers: () => HTTPHeaders | Promise<HTTPHeaders>;
|
|
30
23
|
}
|
|
31
|
-
export declare function resolveHTTPLinkOptions(opts:
|
|
24
|
+
export declare function resolveHTTPLinkOptions(opts: HTTPLinkBaseOptions): ResolvedHTTPLinkOptions;
|
|
32
25
|
export interface HTTPResult {
|
|
33
26
|
json: TRPCResponse;
|
|
34
27
|
meta: {
|
|
@@ -42,15 +35,20 @@ declare type GetInputOptions = {
|
|
|
42
35
|
} | {
|
|
43
36
|
input: unknown;
|
|
44
37
|
});
|
|
45
|
-
|
|
38
|
+
declare type GetUrlOptions = ResolvedHTTPLinkOptions & GetInputOptions & {
|
|
46
39
|
type: ProcedureType;
|
|
47
40
|
path: string;
|
|
48
41
|
};
|
|
49
|
-
export declare function getUrl(opts:
|
|
42
|
+
export declare function getUrl(opts: GetUrlOptions): string;
|
|
50
43
|
declare type GetBodyOptions = {
|
|
51
44
|
type: ProcedureType;
|
|
52
45
|
} & GetInputOptions;
|
|
53
46
|
export declare function getBody(opts: GetBodyOptions): string | undefined;
|
|
47
|
+
export declare type HTTPRequestOptions = ResolvedHTTPLinkOptions & GetInputOptions & {
|
|
48
|
+
type: ProcedureType;
|
|
49
|
+
path: string;
|
|
50
|
+
headers: () => HTTPHeaders | Promise<HTTPHeaders>;
|
|
51
|
+
};
|
|
54
52
|
export declare function httpRequest(opts: HTTPRequestOptions): PromiseAndCancel<HTTPResult>;
|
|
55
53
|
export {};
|
|
56
54
|
//# sourceMappingURL=httpUtils.d.ts.map
|
|
@@ -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,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,
|
|
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;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB;;OAEG;IACH,eAAe,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAAC;CAC/C;AAED,MAAM,WAAW,uBAAuB;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,UAAU,CAAC;IAClB,eAAe,EAAE,oBAAoB,GAAG,IAAI,CAAC;CAC9C;AAED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,mBAAmB,GACxB,uBAAuB,CAMzB;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,aAAK,aAAa,GAAG,uBAAuB,GAC1C,eAAe,GAAG;IAChB,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEJ,wBAAgB,MAAM,CAAC,IAAI,EAAE,aAAa,UAgBzC;AAED,aAAK,cAAc,GAAG;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GAAG,eAAe,CAAC;AAEhE,wBAAgB,OAAO,CAAC,IAAI,EAAE,cAAc,sBAM3C;AAED,oBAAY,kBAAkB,GAAG,uBAAuB,GACtD,eAAe,GAAG;IAChB,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CACnD,CAAC;AAEJ,wBAAgB,WAAW,CACzB,IAAI,EAAE,kBAAkB,GACvB,gBAAgB,CAAC,UAAU,CAAC,CAyC9B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/client",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.20.0",
|
|
4
4
|
"description": "tRPC Client lib",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -69,11 +69,11 @@
|
|
|
69
69
|
"links"
|
|
70
70
|
],
|
|
71
71
|
"peerDependencies": {
|
|
72
|
-
"@trpc/server": "10.
|
|
72
|
+
"@trpc/server": "10.20.0"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@testing-library/dom": "^9.0.0",
|
|
76
|
-
"@trpc/server": "10.
|
|
76
|
+
"@trpc/server": "10.20.0",
|
|
77
77
|
"@types/isomorphic-fetch": "^0.0.36",
|
|
78
78
|
"@types/node": "^18.7.20",
|
|
79
79
|
"eslint": "^8.30.0",
|
|
@@ -88,5 +88,5 @@
|
|
|
88
88
|
"publishConfig": {
|
|
89
89
|
"access": "public"
|
|
90
90
|
},
|
|
91
|
-
"gitHead": "
|
|
91
|
+
"gitHead": "eec22ebb70d14e28260aba58daa45a45e0f7790d"
|
|
92
92
|
}
|
|
@@ -28,66 +28,52 @@ import {
|
|
|
28
28
|
|
|
29
29
|
/** @public */
|
|
30
30
|
export type inferRouterProxyClient<TRouter extends AnyRouter> =
|
|
31
|
-
DecoratedProcedureRecord<TRouter['_def']['record']
|
|
31
|
+
DecoratedProcedureRecord<TRouter['_def']['record']>;
|
|
32
32
|
|
|
33
33
|
type Resolver<TProcedure extends AnyProcedure> = (
|
|
34
34
|
...args: ProcedureArgs<TProcedure['_def']>
|
|
35
35
|
) => Promise<inferTransformedProcedureOutput<TProcedure>>;
|
|
36
36
|
|
|
37
|
-
type SubscriptionResolver<
|
|
38
|
-
TProcedure extends AnyProcedure,
|
|
39
|
-
TRouter extends AnyRouter,
|
|
40
|
-
> = (
|
|
37
|
+
type SubscriptionResolver<TProcedure extends AnyProcedure> = (
|
|
41
38
|
...args: [
|
|
42
39
|
input: ProcedureArgs<TProcedure['_def']>[0],
|
|
43
40
|
opts: ProcedureArgs<TProcedure['_def']>[1] &
|
|
44
41
|
Partial<
|
|
45
42
|
TRPCSubscriptionObserver<
|
|
46
43
|
inferTransformedSubscriptionOutput<TProcedure>,
|
|
47
|
-
TRPCClientError<
|
|
44
|
+
TRPCClientError<TProcedure>
|
|
48
45
|
>
|
|
49
46
|
>,
|
|
50
47
|
]
|
|
51
48
|
) => Unsubscribable;
|
|
52
49
|
|
|
53
|
-
type DecorateProcedure<
|
|
54
|
-
TProcedure extends
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
: never;
|
|
50
|
+
type DecorateProcedure<TProcedure extends AnyProcedure> =
|
|
51
|
+
TProcedure extends AnyQueryProcedure
|
|
52
|
+
? {
|
|
53
|
+
query: Resolver<TProcedure>;
|
|
54
|
+
}
|
|
55
|
+
: TProcedure extends AnyMutationProcedure
|
|
56
|
+
? {
|
|
57
|
+
mutate: Resolver<TProcedure>;
|
|
58
|
+
}
|
|
59
|
+
: TProcedure extends AnySubscriptionProcedure
|
|
60
|
+
? {
|
|
61
|
+
subscribe: SubscriptionResolver<TProcedure>;
|
|
62
|
+
}
|
|
63
|
+
: never;
|
|
69
64
|
|
|
70
65
|
/**
|
|
71
66
|
* @internal
|
|
72
67
|
*/
|
|
73
|
-
type DecoratedProcedureRecord<
|
|
74
|
-
TProcedures extends ProcedureRouterRecord,
|
|
75
|
-
TRouter extends AnyRouter,
|
|
76
|
-
> = {
|
|
68
|
+
type DecoratedProcedureRecord<TProcedures extends ProcedureRouterRecord> = {
|
|
77
69
|
[TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter
|
|
78
|
-
? DecoratedProcedureRecord<
|
|
79
|
-
TProcedures[TKey]['_def']['record'],
|
|
80
|
-
TProcedures[TKey]
|
|
81
|
-
>
|
|
70
|
+
? DecoratedProcedureRecord<TProcedures[TKey]['_def']['record']>
|
|
82
71
|
: TProcedures[TKey] extends AnyProcedure
|
|
83
|
-
? DecorateProcedure<TProcedures[TKey]
|
|
72
|
+
? DecorateProcedure<TProcedures[TKey]>
|
|
84
73
|
: never;
|
|
85
74
|
};
|
|
86
75
|
|
|
87
|
-
const clientCallTypeMap: Record<
|
|
88
|
-
keyof DecorateProcedure<any, any>,
|
|
89
|
-
ProcedureType
|
|
90
|
-
> = {
|
|
76
|
+
const clientCallTypeMap: Record<keyof DecorateProcedure<any>, ProcedureType> = {
|
|
91
77
|
query: 'query',
|
|
92
78
|
mutate: 'mutation',
|
|
93
79
|
subscribe: 'subscription',
|
|
@@ -95,8 +81,7 @@ const clientCallTypeMap: Record<
|
|
|
95
81
|
|
|
96
82
|
export type CreateTRPCProxyClient<TRouter extends AnyRouter> =
|
|
97
83
|
DecoratedProcedureRecord<
|
|
98
|
-
TRouter['_def']['record']
|
|
99
|
-
TRouter
|
|
84
|
+
TRouter['_def']['record']
|
|
100
85
|
> extends infer TProcedureRecord
|
|
101
86
|
? UntypedClientProperties & keyof TProcedureRecord extends never
|
|
102
87
|
? TProcedureRecord
|
|
@@ -116,10 +101,7 @@ export function createTRPCClientProxy<TRouter extends AnyRouter>(
|
|
|
116
101
|
}
|
|
117
102
|
return createRecursiveProxy(({ path, args }) => {
|
|
118
103
|
const pathCopy = [key, ...path];
|
|
119
|
-
const clientCallType = pathCopy.pop()! as keyof DecorateProcedure<
|
|
120
|
-
any,
|
|
121
|
-
any
|
|
122
|
-
>;
|
|
104
|
+
const clientCallType = pathCopy.pop()! as keyof DecorateProcedure<any>;
|
|
123
105
|
|
|
124
106
|
const procedureType = clientCallTypeMap[clientCallType];
|
|
125
107
|
|
package/src/internals/types.ts
CHANGED
|
@@ -2,18 +2,28 @@ import { AnyRouter, ProcedureType } from '@trpc/server';
|
|
|
2
2
|
import { observable } from '@trpc/server/observable';
|
|
3
3
|
import { TRPCClientError } from '../TRPCClientError';
|
|
4
4
|
import { dataLoader } from '../internals/dataLoader';
|
|
5
|
+
import { NonEmptyArray } from '../internals/types';
|
|
5
6
|
import {
|
|
6
|
-
|
|
7
|
+
HTTPLinkBaseOptions,
|
|
7
8
|
HTTPResult,
|
|
8
9
|
getUrl,
|
|
9
10
|
httpRequest,
|
|
10
11
|
resolveHTTPLinkOptions,
|
|
11
12
|
} from './internals/httpUtils';
|
|
12
13
|
import { transformResult } from './internals/transformResult';
|
|
13
|
-
import { TRPCLink } from './types';
|
|
14
|
+
import { HTTPHeaders, Operation, TRPCLink } from './types';
|
|
14
15
|
|
|
15
|
-
export interface HttpBatchLinkOptions extends
|
|
16
|
+
export interface HttpBatchLinkOptions extends HTTPLinkBaseOptions {
|
|
16
17
|
maxURLLength?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Headers to be set on outgoing requests or a callback that of said headers
|
|
20
|
+
* @link http://trpc.io/docs/client/headers
|
|
21
|
+
*/
|
|
22
|
+
headers?:
|
|
23
|
+
| HTTPHeaders
|
|
24
|
+
| ((opts: {
|
|
25
|
+
opList: NonEmptyArray<Operation>;
|
|
26
|
+
}) => HTTPHeaders | Promise<HTTPHeaders>);
|
|
17
27
|
}
|
|
18
28
|
|
|
19
29
|
export function httpBatchLink<TRouter extends AnyRouter>(
|
|
@@ -22,12 +32,10 @@ export function httpBatchLink<TRouter extends AnyRouter>(
|
|
|
22
32
|
const resolvedOpts = resolveHTTPLinkOptions(opts);
|
|
23
33
|
// initialized config
|
|
24
34
|
return (runtime) => {
|
|
25
|
-
type BatchOperation = { id: number; path: string; input: unknown };
|
|
26
|
-
|
|
27
35
|
const maxURLLength = opts.maxURLLength || Infinity;
|
|
28
36
|
|
|
29
37
|
const batchLoader = (type: ProcedureType) => {
|
|
30
|
-
const validate = (batchOps:
|
|
38
|
+
const validate = (batchOps: Operation[]) => {
|
|
31
39
|
if (maxURLLength === Infinity) {
|
|
32
40
|
// escape hatch for quick calcs
|
|
33
41
|
return true;
|
|
@@ -42,10 +50,11 @@ export function httpBatchLink<TRouter extends AnyRouter>(
|
|
|
42
50
|
path,
|
|
43
51
|
inputs,
|
|
44
52
|
});
|
|
53
|
+
|
|
45
54
|
return url.length <= maxURLLength;
|
|
46
55
|
};
|
|
47
56
|
|
|
48
|
-
const fetch = (batchOps:
|
|
57
|
+
const fetch = (batchOps: Operation[]) => {
|
|
49
58
|
const path = batchOps.map((op) => op.path).join(',');
|
|
50
59
|
const inputs = batchOps.map((op) => op.input);
|
|
51
60
|
|
|
@@ -55,6 +64,17 @@ export function httpBatchLink<TRouter extends AnyRouter>(
|
|
|
55
64
|
type,
|
|
56
65
|
path,
|
|
57
66
|
inputs,
|
|
67
|
+
headers() {
|
|
68
|
+
if (!opts.headers) {
|
|
69
|
+
return {};
|
|
70
|
+
}
|
|
71
|
+
if (typeof opts.headers === 'function') {
|
|
72
|
+
return opts.headers({
|
|
73
|
+
opList: batchOps as NonEmptyArray<Operation>,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return opts.headers;
|
|
77
|
+
},
|
|
58
78
|
});
|
|
59
79
|
|
|
60
80
|
return {
|
|
@@ -77,11 +97,9 @@ export function httpBatchLink<TRouter extends AnyRouter>(
|
|
|
77
97
|
return { validate, fetch };
|
|
78
98
|
};
|
|
79
99
|
|
|
80
|
-
const query = dataLoader<
|
|
81
|
-
const mutation = dataLoader<
|
|
82
|
-
|
|
83
|
-
);
|
|
84
|
-
const subscription = dataLoader<BatchOperation, HTTPResult>(
|
|
100
|
+
const query = dataLoader<Operation, HTTPResult>(batchLoader('query'));
|
|
101
|
+
const mutation = dataLoader<Operation, HTTPResult>(batchLoader('mutation'));
|
|
102
|
+
const subscription = dataLoader<Operation, HTTPResult>(
|
|
85
103
|
batchLoader('subscription'),
|
|
86
104
|
);
|
|
87
105
|
|
package/src/links/httpLink.ts
CHANGED
|
@@ -2,12 +2,22 @@ import { AnyRouter } from '@trpc/server';
|
|
|
2
2
|
import { observable } from '@trpc/server/observable';
|
|
3
3
|
import { TRPCClientError } from '../TRPCClientError';
|
|
4
4
|
import {
|
|
5
|
-
|
|
5
|
+
HTTPLinkBaseOptions,
|
|
6
6
|
httpRequest,
|
|
7
7
|
resolveHTTPLinkOptions,
|
|
8
8
|
} from './internals/httpUtils';
|
|
9
9
|
import { transformResult } from './internals/transformResult';
|
|
10
|
-
import { TRPCLink } from './types';
|
|
10
|
+
import { HTTPHeaders, Operation, TRPCLink } from './types';
|
|
11
|
+
|
|
12
|
+
export interface HTTPLinkOptions extends HTTPLinkBaseOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Headers to be set on outgoing requests or a callback that of said headers
|
|
15
|
+
* @link http://trpc.io/docs/client/headers
|
|
16
|
+
*/
|
|
17
|
+
headers?:
|
|
18
|
+
| HTTPHeaders
|
|
19
|
+
| ((opts: { op: Operation }) => HTTPHeaders | Promise<HTTPHeaders>);
|
|
20
|
+
}
|
|
11
21
|
|
|
12
22
|
export function httpLink<TRouter extends AnyRouter>(
|
|
13
23
|
opts: HTTPLinkOptions,
|
|
@@ -17,13 +27,26 @@ export function httpLink<TRouter extends AnyRouter>(
|
|
|
17
27
|
({ op }) =>
|
|
18
28
|
observable((observer) => {
|
|
19
29
|
const { path, input, type } = op;
|
|
30
|
+
|
|
20
31
|
const { promise, cancel } = httpRequest({
|
|
21
32
|
...resolvedOpts,
|
|
22
33
|
runtime,
|
|
23
34
|
type,
|
|
24
35
|
path,
|
|
25
36
|
input,
|
|
37
|
+
headers() {
|
|
38
|
+
if (!opts.headers) {
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
if (typeof opts.headers === 'function') {
|
|
42
|
+
return opts.headers({
|
|
43
|
+
op,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return opts.headers;
|
|
47
|
+
},
|
|
26
48
|
});
|
|
49
|
+
|
|
27
50
|
promise
|
|
28
51
|
.then((res) => {
|
|
29
52
|
const transformed = transformResult(res.json, runtime);
|
|
@@ -9,7 +9,10 @@ import {
|
|
|
9
9
|
} from '../../internals/types';
|
|
10
10
|
import { HTTPHeaders, PromiseAndCancel, TRPCClientRuntime } from '../types';
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export interface HTTPLinkBaseOptions {
|
|
13
16
|
url: string;
|
|
14
17
|
/**
|
|
15
18
|
* Add ponyfill for fetch
|
|
@@ -19,33 +22,21 @@ export interface HTTPLinkOptions {
|
|
|
19
22
|
* Add ponyfill for AbortController
|
|
20
23
|
*/
|
|
21
24
|
AbortController?: AbortControllerEsque | null;
|
|
22
|
-
/**
|
|
23
|
-
* Headers to be set on outgoing requests or a callback that of said headers
|
|
24
|
-
* @link http://trpc.io/docs/v10/header
|
|
25
|
-
*/
|
|
26
|
-
headers?: HTTPHeaders | (() => HTTPHeaders | Promise<HTTPHeaders>);
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
export interface ResolvedHTTPLinkOptions {
|
|
30
28
|
url: string;
|
|
31
29
|
fetch: FetchEsque;
|
|
32
30
|
AbortController: AbortControllerEsque | null;
|
|
33
|
-
/**
|
|
34
|
-
* Headers to be set on outgoing request
|
|
35
|
-
* @link http://trpc.io/docs/v10/header
|
|
36
|
-
*/
|
|
37
|
-
headers: () => HTTPHeaders | Promise<HTTPHeaders>;
|
|
38
31
|
}
|
|
39
32
|
|
|
40
33
|
export function resolveHTTPLinkOptions(
|
|
41
|
-
opts:
|
|
34
|
+
opts: HTTPLinkBaseOptions,
|
|
42
35
|
): ResolvedHTTPLinkOptions {
|
|
43
|
-
const headers = opts.headers || (() => ({}));
|
|
44
36
|
return {
|
|
45
37
|
url: opts.url,
|
|
46
38
|
fetch: getFetch(opts.fetch),
|
|
47
39
|
AbortController: getAbortController(opts.AbortController),
|
|
48
|
-
headers: typeof headers === 'function' ? headers : () => headers,
|
|
49
40
|
};
|
|
50
41
|
}
|
|
51
42
|
|
|
@@ -83,13 +74,13 @@ function getInput(opts: GetInputOptions) {
|
|
|
83
74
|
);
|
|
84
75
|
}
|
|
85
76
|
|
|
86
|
-
|
|
77
|
+
type GetUrlOptions = ResolvedHTTPLinkOptions &
|
|
87
78
|
GetInputOptions & {
|
|
88
79
|
type: ProcedureType;
|
|
89
80
|
path: string;
|
|
90
81
|
};
|
|
91
82
|
|
|
92
|
-
export function getUrl(opts:
|
|
83
|
+
export function getUrl(opts: GetUrlOptions) {
|
|
93
84
|
let url = opts.url + '/' + opts.path;
|
|
94
85
|
const queryParts: string[] = [];
|
|
95
86
|
if ('inputs' in opts) {
|
|
@@ -117,6 +108,13 @@ export function getBody(opts: GetBodyOptions) {
|
|
|
117
108
|
return input !== undefined ? JSON.stringify(input) : undefined;
|
|
118
109
|
}
|
|
119
110
|
|
|
111
|
+
export type HTTPRequestOptions = ResolvedHTTPLinkOptions &
|
|
112
|
+
GetInputOptions & {
|
|
113
|
+
type: ProcedureType;
|
|
114
|
+
path: string;
|
|
115
|
+
headers: () => HTTPHeaders | Promise<HTTPHeaders>;
|
|
116
|
+
};
|
|
117
|
+
|
|
120
118
|
export function httpRequest(
|
|
121
119
|
opts: HTTPRequestOptions,
|
|
122
120
|
): PromiseAndCancel<HTTPResult> {
|