@trpc/client 11.0.0-next.91 → 11.0.0-rc.329
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/README.md +4 -4
- package/dist/TRPCClientError.d.ts +8 -7
- package/dist/TRPCClientError.d.ts.map +1 -1
- package/dist/{TRPCClientError-e224e397.js → TRPCClientError.js} +3 -3
- package/dist/{TRPCClientError-0de4d231.mjs → TRPCClientError.mjs} +4 -4
- package/dist/bundle-analysis.json +126 -155
- package/dist/createTRPCClient.d.ts +27 -19
- package/dist/createTRPCClient.d.ts.map +1 -1
- package/dist/createTRPCClient.js +50 -0
- package/dist/createTRPCClient.mjs +45 -0
- package/dist/createTRPCUntypedClient.d.ts +3 -2
- package/dist/createTRPCUntypedClient.d.ts.map +1 -1
- package/dist/createTRPCUntypedClient.js +10 -0
- package/dist/createTRPCUntypedClient.mjs +7 -0
- package/dist/getFetch.d.ts +1 -1
- package/dist/getFetch.d.ts.map +1 -1
- package/dist/getFetch.js +17 -0
- package/dist/getFetch.mjs +15 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -370
- package/dist/index.mjs +9 -354
- package/dist/internals/TRPCUntypedClient.d.ts +5 -30
- package/dist/internals/TRPCUntypedClient.d.ts.map +1 -1
- package/dist/internals/TRPCUntypedClient.js +85 -0
- package/dist/internals/TRPCUntypedClient.mjs +83 -0
- package/dist/internals/dataLoader.d.ts +1 -1
- package/dist/internals/dataLoader.d.ts.map +1 -1
- package/dist/{httpBatchLink-204206a5.mjs → internals/dataLoader.js} +2 -117
- package/dist/internals/dataLoader.mjs +131 -0
- package/dist/internals/getAbortController.d.ts +2 -2
- package/dist/internals/getAbortController.d.ts.map +1 -1
- package/dist/internals/getAbortController.js +18 -0
- package/dist/internals/getAbortController.mjs +16 -0
- package/dist/internals/transformer.d.ts +42 -0
- package/dist/internals/transformer.d.ts.map +1 -0
- package/dist/internals/transformer.js +30 -0
- package/dist/internals/transformer.mjs +28 -0
- package/dist/internals/types.d.ts +4 -2
- package/dist/internals/types.d.ts.map +1 -1
- package/dist/links/HTTPBatchLinkOptions.d.ts +6 -5
- package/dist/links/HTTPBatchLinkOptions.d.ts.map +1 -1
- package/dist/links/httpBatchLink.d.ts +2 -2
- package/dist/links/httpBatchLink.d.ts.map +1 -1
- package/dist/links/httpBatchLink.js +37 -9
- package/dist/links/httpBatchLink.mjs +39 -5
- package/dist/links/httpBatchStreamLink.d.ts +6 -5
- package/dist/links/httpBatchStreamLink.d.ts.map +1 -1
- package/dist/links/httpBatchStreamLink.js +43 -0
- package/dist/links/httpBatchStreamLink.mjs +41 -0
- package/dist/links/httpFormDataLink.d.ts +1 -1
- package/dist/links/httpFormDataLink.d.ts.map +1 -1
- package/dist/links/httpFormDataLink.js +31 -0
- package/dist/links/httpFormDataLink.mjs +29 -0
- package/dist/links/httpLink.d.ts +8 -8
- package/dist/links/httpLink.d.ts.map +1 -1
- package/dist/links/httpLink.js +6 -9
- package/dist/links/httpLink.mjs +6 -7
- package/dist/links/internals/createChain.d.ts +2 -2
- package/dist/links/internals/createChain.d.ts.map +1 -1
- package/dist/{splitLink-f29e84be.js → links/internals/createChain.js} +0 -22
- package/dist/{splitLink-4c75f7be.mjs → links/internals/createChain.mjs} +1 -22
- package/dist/links/internals/createHTTPBatchLink.d.ts +6 -6
- package/dist/links/internals/createHTTPBatchLink.d.ts.map +1 -1
- package/dist/links/internals/createHTTPBatchLink.js +85 -0
- package/dist/links/internals/createHTTPBatchLink.mjs +83 -0
- package/dist/links/internals/dedupeLink.d.ts +2 -2
- package/dist/links/internals/dedupeLink.d.ts.map +1 -1
- package/dist/links/internals/getTextDecoder.d.ts +1 -1
- package/dist/links/internals/getTextDecoder.d.ts.map +1 -1
- package/dist/links/internals/getTextDecoder.js +18 -0
- package/dist/links/internals/getTextDecoder.mjs +16 -0
- package/dist/links/internals/httpUtils.d.ts +19 -11
- package/dist/links/internals/httpUtils.d.ts.map +1 -1
- package/dist/{httpUtils-c0e7bf5a.js → links/internals/httpUtils.js} +20 -39
- package/dist/{httpUtils-f58ceda1.mjs → links/internals/httpUtils.mjs} +20 -38
- package/dist/links/internals/parseJSONStream.d.ts +5 -6
- package/dist/links/internals/parseJSONStream.d.ts.map +1 -1
- package/dist/links/internals/parseJSONStream.js +118 -0
- package/dist/links/internals/parseJSONStream.mjs +115 -0
- package/dist/links/internals/retryLink.d.ts +2 -2
- package/dist/links/internals/retryLink.d.ts.map +1 -1
- package/dist/links/loggerLink.d.ts +4 -4
- package/dist/links/loggerLink.d.ts.map +1 -1
- package/dist/links/loggerLink.js +6 -4
- package/dist/links/loggerLink.mjs +6 -2
- package/dist/links/splitLink.d.ts +2 -2
- package/dist/links/splitLink.d.ts.map +1 -1
- package/dist/links/splitLink.js +23 -6
- package/dist/links/splitLink.mjs +25 -2
- package/dist/links/types.d.ts +15 -14
- package/dist/links/types.d.ts.map +1 -1
- package/dist/links/wsLink.d.ts +44 -13
- package/dist/links/wsLink.d.ts.map +1 -1
- package/dist/links/wsLink.js +64 -24
- package/dist/links/wsLink.mjs +64 -22
- package/dist/links.d.ts +10 -0
- package/dist/links.d.ts.map +1 -0
- package/dist/unstable-internals.d.ts +2 -0
- package/dist/unstable-internals.d.ts.map +1 -0
- package/dist/unstable-internals.js +7 -0
- package/dist/unstable-internals.mjs +1 -0
- package/package.json +26 -28
- package/src/TRPCClientError.ts +24 -13
- package/src/createTRPCClient.ts +58 -51
- package/src/createTRPCUntypedClient.ts +3 -5
- package/src/getFetch.ts +1 -1
- package/src/index.ts +2 -0
- package/src/internals/TRPCUntypedClient.ts +14 -84
- package/src/internals/dataLoader.ts +1 -1
- package/src/internals/getAbortController.ts +2 -2
- package/src/internals/transformer.ts +76 -0
- package/src/internals/types.ts +8 -1
- package/src/links/HTTPBatchLinkOptions.ts +17 -15
- package/src/links/httpBatchLink.ts +9 -8
- package/src/links/httpBatchStreamLink.ts +17 -17
- package/src/links/httpFormDataLink.ts +11 -12
- package/src/links/httpLink.ts +27 -19
- package/src/links/internals/createChain.ts +6 -2
- package/src/links/internals/createHTTPBatchLink.ts +24 -16
- package/src/links/internals/dedupeLink.ts +4 -3
- package/src/links/internals/getTextDecoder.ts +1 -1
- package/src/links/internals/httpUtils.ts +42 -21
- package/src/links/internals/parseJSONStream.ts +12 -14
- package/src/links/internals/retryLink.ts +4 -3
- package/src/links/loggerLink.ts +5 -5
- package/src/links/splitLink.ts +2 -2
- package/src/links/types.ts +27 -22
- package/src/links/wsLink.ts +124 -36
- package/src/links.ts +14 -0
- package/src/unstable-internals.ts +1 -0
- package/unstable-internals/index.d.ts +1 -0
- package/unstable-internals/index.js +1 -0
- package/dist/TRPCClientError-23c8aa93.js +0 -61
- package/dist/httpBatchLink-64fceaac.js +0 -251
- package/dist/httpBatchLink-92dab48e.js +0 -247
- package/dist/httpUtils-35e50476.js +0 -145
- package/dist/internals/isObject.d.ts +0 -2
- package/dist/internals/isObject.d.ts.map +0 -1
- package/dist/internals/retryDelay.d.ts +0 -2
- package/dist/internals/retryDelay.d.ts.map +0 -1
- package/dist/links/index.d.ts +0 -10
- package/dist/links/index.d.ts.map +0 -1
- package/dist/shared/index.d.ts +0 -2
- package/dist/shared/index.d.ts.map +0 -1
- package/dist/shared/index.js +0 -9
- package/dist/shared/index.mjs +0 -1
- package/dist/shared/transformResult.d.ts +0 -34
- package/dist/shared/transformResult.d.ts.map +0 -1
- package/dist/splitLink-0df96fdc.js +0 -41
- package/dist/transformResult-ace864b8.mjs +0 -58
- package/dist/transformResult-c1422cb5.js +0 -60
- package/dist/transformResult-dfce8f15.js +0 -61
- package/shared/index.d.ts +0 -1
- package/shared/index.js +0 -1
- package/src/internals/isObject.ts +0 -4
- package/src/internals/retryDelay.ts +0 -3
- package/src/links/index.ts +0 -14
- package/src/shared/index.ts +0 -1
- package/src/shared/transformResult.ts +0 -79
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpUtils.d.ts","sourceRoot":"","sources":["../../../src/links/internals/httpUtils.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"httpUtils.d.ts","sourceRoot":"","sources":["../../../src/links/internals/httpUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,uBAAuB,EACvB,aAAa,EACb,YAAY,EACb,MAAM,0CAA0C,CAAC;AAGlD,OAAO,KAAK,EACV,oBAAoB,EACpB,4BAA4B,EAC5B,UAAU,EACV,gBAAgB,EAChB,aAAa,EACd,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAC7B,KAAK,SAAS,IAAI,CAAC,YAAY,EAAE,aAAa,CAAC,IAC7C;IACF,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;IAClB;;OAEG;IACH,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB;;OAEG;IACH,eAAe,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAC9C;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;AAE9B,MAAM,WAAW,uBAAuB;IACtC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,eAAe,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAC7C,WAAW,EAAE,uBAAuB,CAAC;IACrC,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,sBAAsB,CACpC,IAAI,EAAE,mBAAmB,CAAC,YAAY,CAAC,GACtC,uBAAuB,CAQzB;AAiBD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE;QACJ,QAAQ,EAAE,aAAa,CAAC;QACxB,YAAY,CAAC,EAAE,OAAO,CAAC;KACxB,CAAC;CACH;AAED,KAAK,eAAe,GAAG;IACrB,WAAW,EAAE,uBAAuB,CAAC;CACtC,GAAG,CAAC;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,MAAM,EAAE,OAAO,EAAE,CAAA;CAAE,CAAC,CAAC;AAUjD,MAAM,MAAM,sBAAsB,GAAG,eAAe,GAClD,uBAAuB,GAAG;IACxB,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEJ,KAAK,MAAM,GAAG,CAAC,IAAI,EAAE,sBAAsB,KAAK,MAAM,CAAC;AACvD,KAAK,OAAO,GAAG,CAAC,IAAI,EAAE,sBAAsB,KAAK,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAC1E,MAAM,MAAM,cAAc,GAAG;IAC3B,eAAe,CAAC,EAAE,QAAQ,CAAC;IAC3B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAEF,eAAO,MAAM,MAAM,EAAE,MAgBpB,CAAC;AAEF,eAAO,MAAM,OAAO,EAAE,OAMrB,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,CACtB,IAAI,EAAE,sBAAsB,GAAG;IAC7B,OAAO,EAAE,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;CACnD,KACE,gBAAgB,CAAC,UAAU,CAAC,CAAC;AAElC,eAAO,MAAM,iBAAiB,EAAE,SAO/B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,cAAc,GAC7C,sBAAsB,GAAG;IACvB,OAAO,EAAE,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAClD,WAAW,CAAC,EAAE,gBAAgB,CAAC;CAChC,CAAC;AAEJ,wBAAsB,iBAAiB,CACrC,IAAI,EAAE,kBAAkB,EACxB,EAAE,CAAC,EAAE,4BAA4B,GAAG,IAAI,0BAgCzC;AAED,wBAAgB,WAAW,CACzB,IAAI,EAAE,kBAAkB,GACvB,gBAAgB,CAAC,UAAU,CAAC,CA8B9B"}
|
|
@@ -1,41 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (customFetchImpl) {
|
|
8
|
-
return customFetchImpl;
|
|
9
|
-
}
|
|
10
|
-
if (typeof window !== 'undefined' && isFunction(window.fetch)) {
|
|
11
|
-
return window.fetch;
|
|
12
|
-
}
|
|
13
|
-
if (typeof globalThis !== 'undefined' && isFunction(globalThis.fetch)) {
|
|
14
|
-
return globalThis.fetch;
|
|
15
|
-
}
|
|
16
|
-
throw new Error('No fetch implementation found');
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function getAbortController(customAbortControllerImpl) {
|
|
20
|
-
if (customAbortControllerImpl) {
|
|
21
|
-
return customAbortControllerImpl;
|
|
22
|
-
}
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
|
24
|
-
if (typeof window !== 'undefined' && window.AbortController) {
|
|
25
|
-
return window.AbortController;
|
|
26
|
-
}
|
|
27
|
-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
|
28
|
-
if (typeof globalThis !== 'undefined' && globalThis.AbortController) {
|
|
29
|
-
return globalThis.AbortController;
|
|
30
|
-
}
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
3
|
+
var getFetch = require('../../getFetch.js');
|
|
4
|
+
var getAbortController = require('../../internals/getAbortController.js');
|
|
5
|
+
var TRPCClientError = require('../../TRPCClientError.js');
|
|
6
|
+
var transformer = require('../../internals/transformer.js');
|
|
33
7
|
|
|
34
8
|
function resolveHTTPLinkOptions(opts) {
|
|
35
9
|
return {
|
|
36
10
|
url: opts.url.toString().replace(/\/$/, ''),
|
|
37
11
|
fetch: opts.fetch,
|
|
38
|
-
AbortController: getAbortController(opts.AbortController)
|
|
12
|
+
AbortController: getAbortController.getAbortController(opts.AbortController),
|
|
13
|
+
transformer: transformer.getTransformer(opts.transformer),
|
|
14
|
+
methodOverride: opts.methodOverride
|
|
39
15
|
};
|
|
40
16
|
}
|
|
41
17
|
// https://github.com/trpc/trpc/pull/669
|
|
@@ -52,7 +28,7 @@ const METHOD = {
|
|
|
52
28
|
mutation: 'POST'
|
|
53
29
|
};
|
|
54
30
|
function getInput(opts) {
|
|
55
|
-
return 'input' in opts ? opts.
|
|
31
|
+
return 'input' in opts ? opts.transformer.input.serialize(opts.input) : arrayToDict(opts.inputs.map((_input)=>opts.transformer.input.serialize(_input)));
|
|
56
32
|
}
|
|
57
33
|
const getUrl = (opts)=>{
|
|
58
34
|
let url = opts.url + '/' + opts.path;
|
|
@@ -62,7 +38,7 @@ const getUrl = (opts)=>{
|
|
|
62
38
|
}
|
|
63
39
|
if (opts.type === 'query') {
|
|
64
40
|
const input = getInput(opts);
|
|
65
|
-
if (input !== undefined) {
|
|
41
|
+
if (input !== undefined && opts.methodOverride !== 'POST') {
|
|
66
42
|
queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`);
|
|
67
43
|
}
|
|
68
44
|
}
|
|
@@ -72,7 +48,7 @@ const getUrl = (opts)=>{
|
|
|
72
48
|
return url;
|
|
73
49
|
};
|
|
74
50
|
const getBody = (opts)=>{
|
|
75
|
-
if (opts.type === 'query') {
|
|
51
|
+
if (opts.type === 'query' && opts.methodOverride !== 'POST') {
|
|
76
52
|
return undefined;
|
|
77
53
|
}
|
|
78
54
|
const input = getInput(opts);
|
|
@@ -90,7 +66,13 @@ async function fetchHTTPResponse(opts, ac) {
|
|
|
90
66
|
const url = opts.getUrl(opts);
|
|
91
67
|
const body = opts.getBody(opts);
|
|
92
68
|
const { type } = opts;
|
|
93
|
-
const resolvedHeaders = await
|
|
69
|
+
const resolvedHeaders = await (async ()=>{
|
|
70
|
+
const heads = await opts.headers();
|
|
71
|
+
if (Symbol.iterator in heads) {
|
|
72
|
+
return Object.fromEntries(heads);
|
|
73
|
+
}
|
|
74
|
+
return heads;
|
|
75
|
+
})();
|
|
94
76
|
/* istanbul ignore if -- @preserve */ if (type === 'subscription') {
|
|
95
77
|
throw new Error('Subscriptions should use wsLink');
|
|
96
78
|
}
|
|
@@ -103,10 +85,10 @@ async function fetchHTTPResponse(opts, ac) {
|
|
|
103
85
|
} : {},
|
|
104
86
|
...resolvedHeaders
|
|
105
87
|
};
|
|
106
|
-
return getFetch(opts.fetch)(url, {
|
|
107
|
-
method: METHOD[type],
|
|
88
|
+
return getFetch.getFetch(opts.fetch)(url, {
|
|
89
|
+
method: opts.methodOverride ?? METHOD[type],
|
|
108
90
|
signal: ac?.signal,
|
|
109
|
-
body
|
|
91
|
+
body,
|
|
110
92
|
headers
|
|
111
93
|
});
|
|
112
94
|
}
|
|
@@ -145,7 +127,6 @@ function httpRequest(opts) {
|
|
|
145
127
|
|
|
146
128
|
exports.fetchHTTPResponse = fetchHTTPResponse;
|
|
147
129
|
exports.getBody = getBody;
|
|
148
|
-
exports.getFetch = getFetch;
|
|
149
130
|
exports.getUrl = getUrl;
|
|
150
131
|
exports.httpRequest = httpRequest;
|
|
151
132
|
exports.jsonHttpRequester = jsonHttpRequester;
|
|
@@ -1,39 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (customFetchImpl) {
|
|
6
|
-
return customFetchImpl;
|
|
7
|
-
}
|
|
8
|
-
if (typeof window !== 'undefined' && isFunction(window.fetch)) {
|
|
9
|
-
return window.fetch;
|
|
10
|
-
}
|
|
11
|
-
if (typeof globalThis !== 'undefined' && isFunction(globalThis.fetch)) {
|
|
12
|
-
return globalThis.fetch;
|
|
13
|
-
}
|
|
14
|
-
throw new Error('No fetch implementation found');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function getAbortController(customAbortControllerImpl) {
|
|
18
|
-
if (customAbortControllerImpl) {
|
|
19
|
-
return customAbortControllerImpl;
|
|
20
|
-
}
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
|
22
|
-
if (typeof window !== 'undefined' && window.AbortController) {
|
|
23
|
-
return window.AbortController;
|
|
24
|
-
}
|
|
25
|
-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
|
26
|
-
if (typeof globalThis !== 'undefined' && globalThis.AbortController) {
|
|
27
|
-
return globalThis.AbortController;
|
|
28
|
-
}
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
1
|
+
import { getFetch } from '../../getFetch.mjs';
|
|
2
|
+
import { getAbortController } from '../../internals/getAbortController.mjs';
|
|
3
|
+
import { TRPCClientError } from '../../TRPCClientError.mjs';
|
|
4
|
+
import { getTransformer } from '../../internals/transformer.mjs';
|
|
31
5
|
|
|
32
6
|
function resolveHTTPLinkOptions(opts) {
|
|
33
7
|
return {
|
|
34
8
|
url: opts.url.toString().replace(/\/$/, ''),
|
|
35
9
|
fetch: opts.fetch,
|
|
36
|
-
AbortController: getAbortController(opts.AbortController)
|
|
10
|
+
AbortController: getAbortController(opts.AbortController),
|
|
11
|
+
transformer: getTransformer(opts.transformer),
|
|
12
|
+
methodOverride: opts.methodOverride
|
|
37
13
|
};
|
|
38
14
|
}
|
|
39
15
|
// https://github.com/trpc/trpc/pull/669
|
|
@@ -50,7 +26,7 @@ const METHOD = {
|
|
|
50
26
|
mutation: 'POST'
|
|
51
27
|
};
|
|
52
28
|
function getInput(opts) {
|
|
53
|
-
return 'input' in opts ? opts.
|
|
29
|
+
return 'input' in opts ? opts.transformer.input.serialize(opts.input) : arrayToDict(opts.inputs.map((_input)=>opts.transformer.input.serialize(_input)));
|
|
54
30
|
}
|
|
55
31
|
const getUrl = (opts)=>{
|
|
56
32
|
let url = opts.url + '/' + opts.path;
|
|
@@ -60,7 +36,7 @@ const getUrl = (opts)=>{
|
|
|
60
36
|
}
|
|
61
37
|
if (opts.type === 'query') {
|
|
62
38
|
const input = getInput(opts);
|
|
63
|
-
if (input !== undefined) {
|
|
39
|
+
if (input !== undefined && opts.methodOverride !== 'POST') {
|
|
64
40
|
queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`);
|
|
65
41
|
}
|
|
66
42
|
}
|
|
@@ -70,7 +46,7 @@ const getUrl = (opts)=>{
|
|
|
70
46
|
return url;
|
|
71
47
|
};
|
|
72
48
|
const getBody = (opts)=>{
|
|
73
|
-
if (opts.type === 'query') {
|
|
49
|
+
if (opts.type === 'query' && opts.methodOverride !== 'POST') {
|
|
74
50
|
return undefined;
|
|
75
51
|
}
|
|
76
52
|
const input = getInput(opts);
|
|
@@ -88,7 +64,13 @@ async function fetchHTTPResponse(opts, ac) {
|
|
|
88
64
|
const url = opts.getUrl(opts);
|
|
89
65
|
const body = opts.getBody(opts);
|
|
90
66
|
const { type } = opts;
|
|
91
|
-
const resolvedHeaders = await
|
|
67
|
+
const resolvedHeaders = await (async ()=>{
|
|
68
|
+
const heads = await opts.headers();
|
|
69
|
+
if (Symbol.iterator in heads) {
|
|
70
|
+
return Object.fromEntries(heads);
|
|
71
|
+
}
|
|
72
|
+
return heads;
|
|
73
|
+
})();
|
|
92
74
|
/* istanbul ignore if -- @preserve */ if (type === 'subscription') {
|
|
93
75
|
throw new Error('Subscriptions should use wsLink');
|
|
94
76
|
}
|
|
@@ -102,9 +84,9 @@ async function fetchHTTPResponse(opts, ac) {
|
|
|
102
84
|
...resolvedHeaders
|
|
103
85
|
};
|
|
104
86
|
return getFetch(opts.fetch)(url, {
|
|
105
|
-
method: METHOD[type],
|
|
87
|
+
method: opts.methodOverride ?? METHOD[type],
|
|
106
88
|
signal: ac?.signal,
|
|
107
|
-
body
|
|
89
|
+
body,
|
|
108
90
|
headers
|
|
109
91
|
});
|
|
110
92
|
}
|
|
@@ -141,4 +123,4 @@ function httpRequest(opts) {
|
|
|
141
123
|
};
|
|
142
124
|
}
|
|
143
125
|
|
|
144
|
-
export {
|
|
126
|
+
export { fetchHTTPResponse, getBody, getUrl, httpRequest, jsonHttpRequester, resolveHTTPLinkOptions };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { TextDecoderEsque } from './streamingUtils';
|
|
1
|
+
import type { NodeJSReadableStreamEsque, WebReadableStreamEsque } from '../../internals/types';
|
|
2
|
+
import type { HTTPHeaders } from '../types';
|
|
3
|
+
import type { HTTPBaseRequestOptions, HTTPResult } from './httpUtils';
|
|
4
|
+
import type { TextDecoderEsque } from './streamingUtils';
|
|
6
5
|
/**
|
|
7
6
|
* @internal
|
|
8
7
|
* @description Take a stream of bytes and call `onLine` with
|
|
@@ -18,7 +17,7 @@ export declare function parseJSONStream<TReturn>(opts: {
|
|
|
18
17
|
/**
|
|
19
18
|
* As given by `(await fetch(url)).body`
|
|
20
19
|
*/
|
|
21
|
-
readableStream:
|
|
20
|
+
readableStream: NodeJSReadableStreamEsque | WebReadableStreamEsque;
|
|
22
21
|
/**
|
|
23
22
|
* Called for each line of the stream
|
|
24
23
|
*/
|
|
@@ -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,KAAK,EACV,yBAAyB,EACzB,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,KAAK,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEtE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,IAAI,EAAE;IACnD;;OAEG;IACH,cAAc,EAAE,yBAAyB,GAAG,sBAAsB,CAAC;IACnE;;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"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var httpUtils = require('./httpUtils.js');
|
|
4
|
+
|
|
5
|
+
// Stream parsing adapted from https://www.loginradius.com/blog/engineering/guest-post/http-streaming-with-nodejs-and-fetch-api/
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
* @description Take a stream of bytes and call `onLine` with
|
|
9
|
+
* a JSON object for each line in the stream. Expected stream
|
|
10
|
+
* format is:
|
|
11
|
+
* ```json
|
|
12
|
+
* {"1": {...}
|
|
13
|
+
* ,"0": {...}
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/ async function parseJSONStream(opts) {
|
|
17
|
+
const parse = opts.parse ?? JSON.parse;
|
|
18
|
+
const onLine = (line)=>{
|
|
19
|
+
if (opts.signal?.aborted) return;
|
|
20
|
+
if (!line || line === '}') {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* At this point, `line` can be one of two things:
|
|
25
|
+
* - The first line of the stream `{"2":{...}`
|
|
26
|
+
* - A line in the middle of the stream `,"2":{...}`
|
|
27
|
+
*/ const indexOfColon = line.indexOf(':');
|
|
28
|
+
const indexAsStr = line.substring(2, indexOfColon - 1);
|
|
29
|
+
const text = line.substring(indexOfColon + 1);
|
|
30
|
+
opts.onSingle(Number(indexAsStr), parse(text));
|
|
31
|
+
};
|
|
32
|
+
await readLines(opts.readableStream, onLine, opts.textDecoder);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Handle transforming a stream of bytes into lines of text.
|
|
36
|
+
* To avoid using AsyncIterators / AsyncGenerators,
|
|
37
|
+
* we use a callback for each line.
|
|
38
|
+
*
|
|
39
|
+
* @param readableStream can be a NodeJS stream or a WebAPI stream
|
|
40
|
+
* @param onLine will be called for every line ('\n' delimited) in the stream
|
|
41
|
+
*/ async function readLines(readableStream, onLine, textDecoder) {
|
|
42
|
+
let partOfLine = '';
|
|
43
|
+
const onChunk = (chunk)=>{
|
|
44
|
+
const chunkText = textDecoder.decode(chunk);
|
|
45
|
+
const chunkLines = chunkText.split('\n');
|
|
46
|
+
if (chunkLines.length === 1) {
|
|
47
|
+
partOfLine += chunkLines[0];
|
|
48
|
+
} else if (chunkLines.length > 1) {
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- length checked on line above
|
|
50
|
+
onLine(partOfLine + chunkLines[0]);
|
|
51
|
+
for(let i = 1; i < chunkLines.length - 1; i++){
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- length checked on line above
|
|
53
|
+
onLine(chunkLines[i]);
|
|
54
|
+
}
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- length doesn't change, so is necessarily > 1
|
|
56
|
+
partOfLine = chunkLines[chunkLines.length - 1];
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
// we handle 2 different types of streams, this if where we figure out which one we have
|
|
60
|
+
if ('getReader' in readableStream) {
|
|
61
|
+
await readStandardChunks(readableStream, onChunk);
|
|
62
|
+
} else {
|
|
63
|
+
await readNodeChunks(readableStream, onChunk);
|
|
64
|
+
}
|
|
65
|
+
onLine(partOfLine);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Handle NodeJS stream
|
|
69
|
+
*/ function readNodeChunks(stream, onChunk) {
|
|
70
|
+
return new Promise((resolve)=>{
|
|
71
|
+
stream.on('data', onChunk);
|
|
72
|
+
stream.on('end', resolve);
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Handle WebAPI stream
|
|
77
|
+
*/ async function readStandardChunks(stream, onChunk) {
|
|
78
|
+
const reader = stream.getReader();
|
|
79
|
+
let readResult = await reader.read();
|
|
80
|
+
while(!readResult.done){
|
|
81
|
+
onChunk(readResult.value);
|
|
82
|
+
readResult = await reader.read();
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const streamingJsonHttpRequester = (opts, onSingle)=>{
|
|
86
|
+
const ac = opts.AbortController ? new opts.AbortController() : null;
|
|
87
|
+
const responsePromise = httpUtils.fetchHTTPResponse({
|
|
88
|
+
...opts,
|
|
89
|
+
contentTypeHeader: 'application/json',
|
|
90
|
+
batchModeHeader: 'stream',
|
|
91
|
+
getUrl: httpUtils.getUrl,
|
|
92
|
+
getBody: httpUtils.getBody
|
|
93
|
+
}, ac);
|
|
94
|
+
const cancel = ()=>ac?.abort();
|
|
95
|
+
const promise = responsePromise.then(async (res)=>{
|
|
96
|
+
if (!res.body) throw new Error('Received response without body');
|
|
97
|
+
const meta = {
|
|
98
|
+
response: res
|
|
99
|
+
};
|
|
100
|
+
return parseJSONStream({
|
|
101
|
+
readableStream: res.body,
|
|
102
|
+
onSingle,
|
|
103
|
+
parse: (string)=>({
|
|
104
|
+
json: JSON.parse(string),
|
|
105
|
+
meta
|
|
106
|
+
}),
|
|
107
|
+
signal: ac?.signal,
|
|
108
|
+
textDecoder: opts.textDecoder
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
return {
|
|
112
|
+
cancel,
|
|
113
|
+
promise
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
exports.parseJSONStream = parseJSONStream;
|
|
118
|
+
exports.streamingJsonHttpRequester = streamingJsonHttpRequester;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { fetchHTTPResponse, getUrl, getBody } from './httpUtils.mjs';
|
|
2
|
+
|
|
3
|
+
// Stream parsing adapted from https://www.loginradius.com/blog/engineering/guest-post/http-streaming-with-nodejs-and-fetch-api/
|
|
4
|
+
/**
|
|
5
|
+
* @internal
|
|
6
|
+
* @description Take a stream of bytes and call `onLine` with
|
|
7
|
+
* a JSON object for each line in the stream. Expected stream
|
|
8
|
+
* format is:
|
|
9
|
+
* ```json
|
|
10
|
+
* {"1": {...}
|
|
11
|
+
* ,"0": {...}
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*/ async function parseJSONStream(opts) {
|
|
15
|
+
const parse = opts.parse ?? JSON.parse;
|
|
16
|
+
const onLine = (line)=>{
|
|
17
|
+
if (opts.signal?.aborted) return;
|
|
18
|
+
if (!line || line === '}') {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* At this point, `line` can be one of two things:
|
|
23
|
+
* - The first line of the stream `{"2":{...}`
|
|
24
|
+
* - A line in the middle of the stream `,"2":{...}`
|
|
25
|
+
*/ const indexOfColon = line.indexOf(':');
|
|
26
|
+
const indexAsStr = line.substring(2, indexOfColon - 1);
|
|
27
|
+
const text = line.substring(indexOfColon + 1);
|
|
28
|
+
opts.onSingle(Number(indexAsStr), parse(text));
|
|
29
|
+
};
|
|
30
|
+
await readLines(opts.readableStream, onLine, opts.textDecoder);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Handle transforming a stream of bytes into lines of text.
|
|
34
|
+
* To avoid using AsyncIterators / AsyncGenerators,
|
|
35
|
+
* we use a callback for each line.
|
|
36
|
+
*
|
|
37
|
+
* @param readableStream can be a NodeJS stream or a WebAPI stream
|
|
38
|
+
* @param onLine will be called for every line ('\n' delimited) in the stream
|
|
39
|
+
*/ async function readLines(readableStream, onLine, textDecoder) {
|
|
40
|
+
let partOfLine = '';
|
|
41
|
+
const onChunk = (chunk)=>{
|
|
42
|
+
const chunkText = textDecoder.decode(chunk);
|
|
43
|
+
const chunkLines = chunkText.split('\n');
|
|
44
|
+
if (chunkLines.length === 1) {
|
|
45
|
+
partOfLine += chunkLines[0];
|
|
46
|
+
} else if (chunkLines.length > 1) {
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- length checked on line above
|
|
48
|
+
onLine(partOfLine + chunkLines[0]);
|
|
49
|
+
for(let i = 1; i < chunkLines.length - 1; i++){
|
|
50
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- length checked on line above
|
|
51
|
+
onLine(chunkLines[i]);
|
|
52
|
+
}
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- length doesn't change, so is necessarily > 1
|
|
54
|
+
partOfLine = chunkLines[chunkLines.length - 1];
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
// we handle 2 different types of streams, this if where we figure out which one we have
|
|
58
|
+
if ('getReader' in readableStream) {
|
|
59
|
+
await readStandardChunks(readableStream, onChunk);
|
|
60
|
+
} else {
|
|
61
|
+
await readNodeChunks(readableStream, onChunk);
|
|
62
|
+
}
|
|
63
|
+
onLine(partOfLine);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Handle NodeJS stream
|
|
67
|
+
*/ function readNodeChunks(stream, onChunk) {
|
|
68
|
+
return new Promise((resolve)=>{
|
|
69
|
+
stream.on('data', onChunk);
|
|
70
|
+
stream.on('end', resolve);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Handle WebAPI stream
|
|
75
|
+
*/ async function readStandardChunks(stream, onChunk) {
|
|
76
|
+
const reader = stream.getReader();
|
|
77
|
+
let readResult = await reader.read();
|
|
78
|
+
while(!readResult.done){
|
|
79
|
+
onChunk(readResult.value);
|
|
80
|
+
readResult = await reader.read();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const streamingJsonHttpRequester = (opts, onSingle)=>{
|
|
84
|
+
const ac = opts.AbortController ? new opts.AbortController() : null;
|
|
85
|
+
const responsePromise = fetchHTTPResponse({
|
|
86
|
+
...opts,
|
|
87
|
+
contentTypeHeader: 'application/json',
|
|
88
|
+
batchModeHeader: 'stream',
|
|
89
|
+
getUrl,
|
|
90
|
+
getBody
|
|
91
|
+
}, ac);
|
|
92
|
+
const cancel = ()=>ac?.abort();
|
|
93
|
+
const promise = responsePromise.then(async (res)=>{
|
|
94
|
+
if (!res.body) throw new Error('Received response without body');
|
|
95
|
+
const meta = {
|
|
96
|
+
response: res
|
|
97
|
+
};
|
|
98
|
+
return parseJSONStream({
|
|
99
|
+
readableStream: res.body,
|
|
100
|
+
onSingle,
|
|
101
|
+
parse: (string)=>({
|
|
102
|
+
json: JSON.parse(string),
|
|
103
|
+
meta
|
|
104
|
+
}),
|
|
105
|
+
signal: ac?.signal,
|
|
106
|
+
textDecoder: opts.textDecoder
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
return {
|
|
110
|
+
cancel,
|
|
111
|
+
promise
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export { parseJSONStream, streamingJsonHttpRequester };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryLink.d.ts","sourceRoot":"","sources":["../../../src/links/internals/retryLink.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"retryLink.d.ts","sourceRoot":"","sources":["../../../src/links/internals/retryLink.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAC1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC;;GAEG;AACH,wBAAgB,SAAS,CAAC,OAAO,SAAS,SAAS,GAAG,SAAS,EAAE,IAAI,EAAE;IACrE,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,QAAQ,CAAC,OAAO,CAAC,CAwCpB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference lib="dom.iterable" />
|
|
2
|
-
import { AnyRouter } from '@trpc/server';
|
|
3
|
-
import { TRPCClientError } from '
|
|
4
|
-
import { Operation, OperationResultEnvelope, TRPCLink } from './types';
|
|
2
|
+
import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
|
|
3
|
+
import type { TRPCClientError } from '../TRPCClientError';
|
|
4
|
+
import type { Operation, OperationResultEnvelope, TRPCLink } from './types';
|
|
5
5
|
type ConsoleEsque = {
|
|
6
6
|
log: (...args: any[]) => void;
|
|
7
7
|
error: (...args: any[]) => void;
|
|
@@ -41,7 +41,7 @@ export interface LoggerLinkOptions<TRouter extends AnyRouter> {
|
|
|
41
41
|
colorMode?: 'ansi' | 'css';
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
44
|
-
* @
|
|
44
|
+
* @link https://trpc.io/docs/v11/client/links/loggerLink
|
|
45
45
|
*/
|
|
46
46
|
export declare function loggerLink<TRouter extends AnyRouter = AnyRouter>(opts?: LoggerLinkOptions<TRouter>): TRPCLink<TRouter>;
|
|
47
47
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loggerLink.d.ts","sourceRoot":"","sources":["../../src/links/loggerLink.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"loggerLink.d.ts","sourceRoot":"","sources":["../../src/links/loggerLink.ts"],"names":[],"mappings":";AAQA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAC1E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAC1D,OAAO,KAAK,EAAE,SAAS,EAAE,uBAAuB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAE5E,KAAK,YAAY,GAAG;IAClB,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;IAC9B,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;CACjC,CAAC;AAEF,KAAK,eAAe,CAAC,OAAO,SAAS,SAAS,IAC1C;IACE,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,uBAAuB,CAAC,OAAO,CAAC,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;CACrE,GACD,CAAC,SAAS,GAAG;IACX,SAAS,EAAE,IAAI,CAAC;CACjB,CAAC,CAAC;AACP,KAAK,SAAS,CAAC,OAAO,SAAS,SAAS,IAAI,CAC1C,IAAI,EAAE,eAAe,CAAC,OAAO,CAAC,KAC3B,OAAO,CAAC;AAEb,KAAK,mBAAmB,CAAC,OAAO,SAAS,SAAS,IAAI,SAAS,GAC7D,CACI;IACE;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,uBAAuB,CAAC,OAAO,CAAC,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;IACpE,SAAS,EAAE,MAAM,CAAC;CACnB,GACD;IACE;;OAEG;IACH,SAAS,EAAE,IAAI,CAAC;CACjB,CACJ,CAAC;AAEJ,KAAK,YAAY,CAAC,OAAO,SAAS,SAAS,IAAI,CAC7C,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC,KAC/B,IAAI,CAAC;AAEV,MAAM,WAAW,iBAAiB,CAAC,OAAO,SAAS,SAAS;IAC1D,MAAM,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAC7B;;OAEG;IACH,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CAC5B;AAsID;;GAEG;AACH,wBAAgB,UAAU,CAAC,OAAO,SAAS,SAAS,GAAG,SAAS,EAC9D,IAAI,GAAE,iBAAiB,CAAC,OAAO,CAAM,GACpC,QAAQ,CAAC,OAAO,CAAC,CA6CnB"}
|
package/dist/links/loggerLink.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var observable = require('@trpc/server/observable');
|
|
6
4
|
|
|
7
5
|
/// <reference lib="dom.iterable" />
|
|
6
|
+
// `dom.iterable` types are explicitly required for extracting `FormData` values,
|
|
7
|
+
// as all implementations of `Symbol.iterable` are separated from the main `dom` types.
|
|
8
|
+
// Using triple-slash directive makes sure that it will be available,
|
|
9
|
+
// even if end-user `tsconfig.json` omits it in the `lib` array.
|
|
8
10
|
function isFormData(value) {
|
|
9
11
|
if (typeof FormData === 'undefined') {
|
|
10
12
|
// FormData is not supported
|
|
@@ -89,7 +91,7 @@ function constructPartsAndArgs(opts) {
|
|
|
89
91
|
}
|
|
90
92
|
const [light, dark] = palettes.css[type];
|
|
91
93
|
const css = `
|
|
92
|
-
background-color: #${direction === 'up' ? light : dark};
|
|
94
|
+
background-color: #${direction === 'up' ? light : dark};
|
|
93
95
|
color: ${direction === 'up' ? 'black' : 'white'};
|
|
94
96
|
padding: 2px;
|
|
95
97
|
`;
|
|
@@ -128,7 +130,7 @@ const defaultLogger = ({ c =console , colorMode ='css' })=>(props)=>{
|
|
|
128
130
|
].concat(args));
|
|
129
131
|
};
|
|
130
132
|
/**
|
|
131
|
-
* @
|
|
133
|
+
* @link https://trpc.io/docs/v11/client/links/loggerLink
|
|
132
134
|
*/ function loggerLink(opts = {}) {
|
|
133
135
|
const { enabled =()=>true } = opts;
|
|
134
136
|
const colorMode = opts.colorMode ?? (typeof window === 'undefined' ? 'ansi' : 'css');
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { observable, tap } from '@trpc/server/observable';
|
|
2
2
|
|
|
3
3
|
/// <reference lib="dom.iterable" />
|
|
4
|
+
// `dom.iterable` types are explicitly required for extracting `FormData` values,
|
|
5
|
+
// as all implementations of `Symbol.iterable` are separated from the main `dom` types.
|
|
6
|
+
// Using triple-slash directive makes sure that it will be available,
|
|
7
|
+
// even if end-user `tsconfig.json` omits it in the `lib` array.
|
|
4
8
|
function isFormData(value) {
|
|
5
9
|
if (typeof FormData === 'undefined') {
|
|
6
10
|
// FormData is not supported
|
|
@@ -85,7 +89,7 @@ function constructPartsAndArgs(opts) {
|
|
|
85
89
|
}
|
|
86
90
|
const [light, dark] = palettes.css[type];
|
|
87
91
|
const css = `
|
|
88
|
-
background-color: #${direction === 'up' ? light : dark};
|
|
92
|
+
background-color: #${direction === 'up' ? light : dark};
|
|
89
93
|
color: ${direction === 'up' ? 'black' : 'white'};
|
|
90
94
|
padding: 2px;
|
|
91
95
|
`;
|
|
@@ -124,7 +128,7 @@ const defaultLogger = ({ c =console , colorMode ='css' })=>(props)=>{
|
|
|
124
128
|
].concat(args));
|
|
125
129
|
};
|
|
126
130
|
/**
|
|
127
|
-
* @
|
|
131
|
+
* @link https://trpc.io/docs/v11/client/links/loggerLink
|
|
128
132
|
*/ function loggerLink(opts = {}) {
|
|
129
133
|
const { enabled =()=>true } = opts;
|
|
130
134
|
const colorMode = opts.colorMode ?? (typeof window === 'undefined' ? 'ansi' : 'css');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AnyRouter } from '@trpc/server';
|
|
2
|
-
import { Operation, TRPCLink } from './types';
|
|
1
|
+
import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
|
|
2
|
+
import type { Operation, TRPCLink } from './types';
|
|
3
3
|
export declare function splitLink<TRouter extends AnyRouter = AnyRouter>(opts: {
|
|
4
4
|
condition: (op: Operation) => boolean;
|
|
5
5
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"splitLink.d.ts","sourceRoot":"","sources":["../../src/links/splitLink.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"splitLink.d.ts","sourceRoot":"","sources":["../../src/links/splitLink.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAE1E,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAKnD,wBAAgB,SAAS,CAAC,OAAO,SAAS,SAAS,GAAG,SAAS,EAAE,IAAI,EAAE;IACrE,SAAS,EAAE,CAAC,EAAE,EAAE,SAAS,KAAK,OAAO,CAAC;IACtC;;OAEG;IACH,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;IAC9C;;OAEG;IACH,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;CAChD,GAAG,QAAQ,CAAC,OAAO,CAAC,CAWpB"}
|
package/dist/links/splitLink.js
CHANGED
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
var observable = require('@trpc/server/observable');
|
|
4
|
+
var createChain = require('./internals/createChain.js');
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
function asArray(value) {
|
|
7
|
+
return Array.isArray(value) ? value : [
|
|
8
|
+
value
|
|
9
|
+
];
|
|
10
|
+
}
|
|
11
|
+
function splitLink(opts) {
|
|
12
|
+
return (runtime)=>{
|
|
13
|
+
const yes = asArray(opts.true).map((link)=>link(runtime));
|
|
14
|
+
const no = asArray(opts.false).map((link)=>link(runtime));
|
|
15
|
+
return (props)=>{
|
|
16
|
+
return observable.observable((observer)=>{
|
|
17
|
+
const links = opts.condition(props.op) ? yes : no;
|
|
18
|
+
return createChain.createChain({
|
|
19
|
+
op: props.op,
|
|
20
|
+
links
|
|
21
|
+
}).subscribe(observer);
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
}
|
|
7
26
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
exports.splitLink = links_splitLink.splitLink;
|
|
27
|
+
exports.splitLink = splitLink;
|