@trpc/client 11.1.3-alpha-tmp-issues-6785.34 → 11.1.3-alpha-tmp-tsdown.24
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/TRPCClientError.d.mts +32 -0
- package/dist/TRPCClientError.d.mts.map +1 -0
- package/dist/TRPCClientError.d.ts +28 -25
- package/dist/TRPCClientError.d.ts.map +1 -1
- package/dist/TRPCClientError.js +48 -72
- package/dist/TRPCClientError.mjs +48 -71
- package/dist/TRPCClientError.mjs.map +1 -0
- package/dist/_virtual/rolldown_runtime.js +39 -0
- package/dist/_virtual/rolldown_runtime.mjs +27 -0
- package/dist/createTRPCClient.d.mts +69 -0
- package/dist/createTRPCClient.d.mts.map +1 -0
- package/dist/createTRPCClient.d.ts +34 -34
- package/dist/createTRPCClient.d.ts.map +1 -1
- package/dist/createTRPCClient.js +34 -34
- package/dist/createTRPCClient.mjs +33 -31
- package/dist/createTRPCClient.mjs.map +1 -0
- package/dist/createTRPCUntypedClient.d.mts +8 -0
- package/dist/createTRPCUntypedClient.d.mts.map +1 -0
- package/dist/createTRPCUntypedClient.d.ts +7 -6
- package/dist/createTRPCUntypedClient.d.ts.map +1 -1
- package/dist/createTRPCUntypedClient.js +5 -6
- package/dist/createTRPCUntypedClient.mjs +6 -3
- package/dist/createTRPCUntypedClient.mjs.map +1 -0
- package/dist/getFetch.d.mts +9 -0
- package/dist/getFetch.d.mts.map +1 -0
- package/dist/getFetch.d.ts +8 -2
- package/dist/getFetch.d.ts.map +1 -1
- package/dist/getFetch.js +8 -13
- package/dist/getFetch.mjs +8 -11
- package/dist/getFetch.mjs.map +1 -0
- package/dist/index.d.mts +21 -0
- package/dist/index.d.ts +21 -16
- package/dist/index.js +42 -42
- package/dist/index.mjs +19 -15
- package/dist/internals/TRPCUntypedClient.d.mts +45 -0
- package/dist/internals/TRPCUntypedClient.d.mts.map +1 -0
- package/dist/internals/TRPCUntypedClient.d.ts +39 -33
- package/dist/internals/TRPCUntypedClient.d.ts.map +1 -1
- package/dist/internals/TRPCUntypedClient.js +94 -113
- package/dist/internals/TRPCUntypedClient.mjs +93 -110
- package/dist/internals/TRPCUntypedClient.mjs.map +1 -0
- package/dist/internals/dataLoader.js +101 -112
- package/dist/internals/dataLoader.mjs +101 -110
- package/dist/internals/dataLoader.mjs.map +1 -0
- package/dist/internals/inputWithTrackedEventId.js +9 -12
- package/dist/internals/inputWithTrackedEventId.mjs +9 -10
- package/dist/internals/inputWithTrackedEventId.mjs.map +1 -0
- package/dist/internals/signals.js +39 -40
- package/dist/internals/signals.mjs +39 -39
- package/dist/internals/signals.mjs.map +1 -0
- package/dist/internals/transformer.d.mts +46 -0
- package/dist/internals/transformer.d.mts.map +1 -0
- package/dist/internals/transformer.d.ts +26 -22
- package/dist/internals/transformer.d.ts.map +1 -1
- package/dist/internals/transformer.js +25 -26
- package/dist/internals/transformer.mjs +25 -24
- package/dist/internals/transformer.mjs.map +1 -0
- package/dist/internals/types.d.mts +84 -0
- package/dist/internals/types.d.mts.map +1 -0
- package/dist/internals/types.d.ts +44 -42
- package/dist/internals/types.d.ts.map +1 -1
- package/dist/links/HTTPBatchLinkOptions.d.mts +25 -0
- package/dist/links/HTTPBatchLinkOptions.d.mts.map +1 -0
- package/dist/links/HTTPBatchLinkOptions.d.ts +23 -18
- package/dist/links/HTTPBatchLinkOptions.d.ts.map +1 -1
- package/dist/links/httpBatchLink.d.mts +15 -0
- package/dist/links/httpBatchLink.d.mts.map +1 -0
- package/dist/links/httpBatchLink.d.ts +11 -4
- package/dist/links/httpBatchLink.d.ts.map +1 -1
- package/dist/links/httpBatchLink.js +90 -106
- package/dist/links/httpBatchLink.mjs +89 -103
- package/dist/links/httpBatchLink.mjs.map +1 -0
- package/dist/links/httpBatchStreamLink.d.mts +19 -0
- package/dist/links/httpBatchStreamLink.d.mts.map +1 -0
- package/dist/links/httpBatchStreamLink.d.ts +12 -5
- package/dist/links/httpBatchStreamLink.d.ts.map +1 -1
- package/dist/links/httpBatchStreamLink.js +120 -144
- package/dist/links/httpBatchStreamLink.mjs +119 -141
- package/dist/links/httpBatchStreamLink.mjs.map +1 -0
- package/dist/links/httpLink.d.mts +23 -0
- package/dist/links/httpLink.d.mts.map +1 -0
- package/dist/links/httpLink.d.ts +18 -12
- package/dist/links/httpLink.d.ts.map +1 -1
- package/dist/links/httpLink.js +74 -90
- package/dist/links/httpLink.mjs +73 -87
- package/dist/links/httpLink.mjs.map +1 -0
- package/dist/links/httpSubscriptionLink.d.mts +29 -0
- package/dist/links/httpSubscriptionLink.d.mts.map +1 -0
- package/dist/links/httpSubscriptionLink.d.ts +20 -17
- package/dist/links/httpSubscriptionLink.d.ts.map +1 -1
- package/dist/links/httpSubscriptionLink.js +134 -179
- package/dist/links/httpSubscriptionLink.mjs +133 -176
- package/dist/links/httpSubscriptionLink.mjs.map +1 -0
- package/dist/links/internals/contentTypes.d.mts +9 -0
- package/dist/links/internals/contentTypes.d.mts.map +1 -0
- package/dist/links/internals/contentTypes.d.ts +8 -3
- package/dist/links/internals/contentTypes.d.ts.map +1 -1
- package/dist/links/internals/contentTypes.js +6 -6
- package/dist/links/internals/contentTypes.mjs +6 -4
- package/dist/links/internals/contentTypes.mjs.map +1 -0
- package/dist/links/internals/createChain.js +23 -23
- package/dist/links/internals/createChain.mjs +22 -20
- package/dist/links/internals/createChain.mjs.map +1 -0
- package/dist/links/internals/httpUtils.d.mts +25 -0
- package/dist/links/internals/httpUtils.d.mts.map +1 -0
- package/dist/links/internals/httpUtils.d.ts +20 -63
- package/dist/links/internals/httpUtils.d.ts.map +1 -1
- package/dist/links/internals/httpUtils.js +93 -116
- package/dist/links/internals/httpUtils.mjs +94 -113
- package/dist/links/internals/httpUtils.mjs.map +1 -0
- package/dist/links/internals/subscriptions.d.mts +19 -0
- package/dist/links/internals/subscriptions.d.mts.map +1 -0
- package/dist/links/internals/subscriptions.d.ts +10 -8
- package/dist/links/internals/subscriptions.d.ts.map +1 -1
- package/dist/links/internals/urlWithConnectionParams.d.mts +24 -0
- package/dist/links/internals/urlWithConnectionParams.d.mts.map +1 -0
- package/dist/links/internals/urlWithConnectionParams.d.ts +19 -18
- package/dist/links/internals/urlWithConnectionParams.d.ts.map +1 -1
- package/dist/links/internals/urlWithConnectionParams.js +8 -6
- package/dist/links/internals/urlWithConnectionParams.mjs +8 -4
- package/dist/links/internals/urlWithConnectionParams.mjs.map +1 -0
- package/dist/links/localLink.d.mts +21 -0
- package/dist/links/localLink.d.mts.map +1 -0
- package/dist/links/localLink.d.ts +21 -0
- package/dist/links/localLink.d.ts.map +1 -0
- package/dist/links/localLink.js +192 -0
- package/dist/links/localLink.mjs +193 -0
- package/dist/links/localLink.mjs.map +1 -0
- package/dist/links/loggerLink.d.mts +55 -0
- package/dist/links/loggerLink.d.mts.map +1 -0
- package/dist/links/loggerLink.d.ts +39 -36
- package/dist/links/loggerLink.d.ts.map +1 -1
- package/dist/links/loggerLink.js +113 -166
- package/dist/links/loggerLink.mjs +112 -163
- package/dist/links/loggerLink.mjs.map +1 -0
- package/dist/links/retryLink.d.mts +36 -0
- package/dist/links/retryLink.d.mts.map +1 -0
- package/dist/links/retryLink.d.ts +28 -25
- package/dist/links/retryLink.d.ts.map +1 -1
- package/dist/links/retryLink.js +60 -68
- package/dist/links/retryLink.mjs +59 -65
- package/dist/links/retryLink.mjs.map +1 -0
- package/dist/links/splitLink.d.mts +20 -0
- package/dist/links/splitLink.d.mts.map +1 -0
- package/dist/links/splitLink.d.ts +18 -12
- package/dist/links/splitLink.d.ts.map +1 -1
- package/dist/links/splitLink.js +20 -21
- package/dist/links/splitLink.mjs +19 -18
- package/dist/links/splitLink.mjs.map +1 -0
- package/dist/links/types.d.mts +68 -0
- package/dist/links/types.d.mts.map +1 -0
- package/dist/links/types.d.ts +34 -29
- package/dist/links/types.d.ts.map +1 -1
- package/dist/links/wsLink/createWsClient.d.mts +9 -0
- package/dist/links/wsLink/createWsClient.d.mts.map +1 -0
- package/dist/links/wsLink/createWsClient.d.ts +8 -5
- package/dist/links/wsLink/createWsClient.d.ts.map +1 -1
- package/dist/links/wsLink/createWsClient.js +5 -5
- package/dist/links/wsLink/createWsClient.mjs +5 -2
- package/dist/links/wsLink/createWsClient.mjs.map +1 -0
- package/dist/links/wsLink/wsClient/options.d.mts +69 -0
- package/dist/links/wsLink/wsClient/options.d.mts.map +1 -0
- package/dist/links/wsLink/wsClient/options.d.ts +53 -63
- package/dist/links/wsLink/wsClient/options.d.ts.map +1 -1
- package/dist/links/wsLink/wsClient/options.js +14 -12
- package/dist/links/wsLink/wsClient/options.mjs +14 -10
- package/dist/links/wsLink/wsClient/options.mjs.map +1 -0
- package/dist/links/wsLink/wsClient/requestManager.js +133 -140
- package/dist/links/wsLink/wsClient/requestManager.mjs +133 -137
- package/dist/links/wsLink/wsClient/requestManager.mjs.map +1 -0
- package/dist/links/wsLink/wsClient/utils.js +64 -81
- package/dist/links/wsLink/wsClient/utils.mjs +64 -78
- package/dist/links/wsLink/wsClient/utils.mjs.map +1 -0
- package/dist/links/wsLink/wsClient/wsClient.d.mts +101 -0
- package/dist/links/wsLink/wsClient/wsClient.d.mts.map +1 -0
- package/dist/links/wsLink/wsClient/wsClient.d.ts +95 -78
- package/dist/links/wsLink/wsClient/wsClient.d.ts.map +1 -1
- package/dist/links/wsLink/wsClient/wsClient.js +273 -322
- package/dist/links/wsLink/wsClient/wsClient.mjs +272 -319
- package/dist/links/wsLink/wsClient/wsClient.mjs.map +1 -0
- package/dist/links/wsLink/wsClient/wsConnection.js +155 -178
- package/dist/links/wsLink/wsClient/wsConnection.mjs +154 -175
- package/dist/links/wsLink/wsClient/wsConnection.mjs.map +1 -0
- package/dist/links/wsLink/wsLink.d.mts +14 -0
- package/dist/links/wsLink/wsLink.d.mts.map +1 -0
- package/dist/links/wsLink/wsLink.d.ts +12 -9
- package/dist/links/wsLink/wsLink.d.ts.map +1 -1
- package/dist/links/wsLink/wsLink.js +30 -31
- package/dist/links/wsLink/wsLink.mjs +29 -28
- package/dist/links/wsLink/wsLink.mjs.map +1 -0
- package/dist/links.js +11 -0
- package/dist/links.mjs +11 -0
- package/dist/node_modules/.pnpm/@oxc-project_runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js +68 -0
- package/dist/node_modules/.pnpm/@oxc-project_runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/usingCtx.mjs +66 -0
- package/dist/node_modules/.pnpm/@oxc-project_runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/usingCtx.mjs.map +1 -0
- package/dist/unstable-internals.d.mts +3 -0
- package/dist/unstable-internals.d.ts +3 -3
- package/dist/unstable-internals.js +2 -6
- package/dist/unstable-internals.mjs +3 -1
- package/links/httpBatchLink/package.json +1 -0
- package/links/httpLink/package.json +1 -0
- package/links/loggerLink/package.json +1 -0
- package/links/splitLink/package.json +1 -0
- package/links/wsLink/wsLink/package.json +1 -0
- package/package.json +63 -30
- package/src/TRPCClientError.ts +4 -9
- package/src/internals/signals.ts +16 -0
- package/src/links/httpSubscriptionLink.ts +3 -18
- package/src/links/localLink.ts +277 -0
- package/src/links.ts +1 -0
- package/unstable-internals/package.json +1 -0
- package/dist/bundle-analysis.json +0 -433
- package/dist/index.d.ts.map +0 -1
- package/dist/internals/dataLoader.d.ts +0 -13
- package/dist/internals/dataLoader.d.ts.map +0 -1
- package/dist/internals/inputWithTrackedEventId.d.ts +0 -2
- package/dist/internals/inputWithTrackedEventId.d.ts.map +0 -1
- package/dist/internals/signals.d.ts +0 -15
- package/dist/internals/signals.d.ts.map +0 -1
- package/dist/links/internals/createChain.d.ts +0 -8
- package/dist/links/internals/createChain.d.ts.map +0 -1
- package/dist/links/internals/dedupeLink.d.ts +0 -7
- package/dist/links/internals/dedupeLink.d.ts.map +0 -1
- package/dist/links/wsLink/wsClient/requestManager.d.ts +0 -106
- package/dist/links/wsLink/wsClient/requestManager.d.ts.map +0 -1
- package/dist/links/wsLink/wsClient/utils.d.ts +0 -38
- package/dist/links/wsLink/wsClient/utils.d.ts.map +0 -1
- package/dist/links/wsLink/wsClient/wsConnection.d.ts +0 -79
- package/dist/links/wsLink/wsClient/wsConnection.d.ts.map +0 -1
- package/dist/links.d.ts +0 -11
- package/dist/links.d.ts.map +0 -1
- package/dist/unstable-internals.d.ts.map +0 -1
- package/links/httpBatchLink/index.d.ts +0 -1
- package/links/httpBatchLink/index.js +0 -1
- package/links/httpLink/index.d.ts +0 -1
- package/links/httpLink/index.js +0 -1
- package/links/loggerLink/index.d.ts +0 -1
- package/links/loggerLink/index.js +0 -1
- package/links/splitLink/index.d.ts +0 -1
- package/links/splitLink/index.js +0 -1
- package/links/wsLink/wsLink/index.d.ts +0 -1
- package/links/wsLink/wsLink/index.js +0 -1
- package/unstable-internals/index.d.ts +0 -1
- package/unstable-internals/index.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpLink.d.ts","
|
|
1
|
+
{"version":3,"file":"httpLink.d.ts","names":[],"sources":["../../src/links/httpLink.ts"],"sourcesContent":[],"mappings":";;;;;KA0BY,8BAA8B,kBACxC,oBAAoB;;AADtB;;;EAAwD,OAClC,CAAA,EAMd,WANc,GAAA,CAAA,CAAA,IAAA,EAAA;IAApB,EAAA,EAOoB,SAPpB;EAAmB,CAAA,EAMb,GAC8B,WAD9B,GAC4C,OAD5C,CACoD,WADpD,CAAA,CAAA;CAAW;;;;AACwC,iBAwC3C,QAxC2C,CAAA,gBAwClB,SAxCkB,GAwCN,SAxCM,CAAA,CAAA,IAAA,EAyCnD,eAzCmD,CAyCnC,OAzCmC,CAAA,MAAA,CAAA,CAAA,SAAA,CAAA,CAAA,QAAA,CAAA,CAAA,CAAA,EA0CxD,QA1CwD,CA0C/C,OA1C+C,CAAA;AAwC3D"}
|
package/dist/links/httpLink.js
CHANGED
|
@@ -1,95 +1,79 @@
|
|
|
1
|
-
|
|
1
|
+
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
|
|
2
|
+
const require_TRPCClientError = require('../TRPCClientError.js');
|
|
3
|
+
const require_contentTypes = require('./internals/contentTypes.js');
|
|
4
|
+
const require_httpUtils = require('./internals/httpUtils.js');
|
|
5
|
+
const __trpc_server_observable = require_rolldown_runtime.__toESM(require("@trpc/server/observable"));
|
|
6
|
+
const __trpc_server_unstable_core_do_not_import = require_rolldown_runtime.__toESM(require("@trpc/server/unstable-core-do-not-import"));
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
return httpUtils.httpRequest({
|
|
29
|
-
...opts,
|
|
30
|
-
contentTypeHeader: 'application/octet-stream',
|
|
31
|
-
getUrl: httpUtils.getUrl,
|
|
32
|
-
getBody: ()=>input
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
return httpUtils.jsonHttpRequester(opts);
|
|
8
|
+
//#region src/links/httpLink.ts
|
|
9
|
+
const universalRequester = (opts) => {
|
|
10
|
+
if ("input" in opts) {
|
|
11
|
+
const { input } = opts;
|
|
12
|
+
if (require_contentTypes.isFormData(input)) {
|
|
13
|
+
if (opts.type !== "mutation" && opts.methodOverride !== "POST") throw new Error("FormData is only supported for mutations");
|
|
14
|
+
return require_httpUtils.httpRequest({
|
|
15
|
+
...opts,
|
|
16
|
+
contentTypeHeader: void 0,
|
|
17
|
+
getUrl: require_httpUtils.getUrl,
|
|
18
|
+
getBody: () => input
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
if (require_contentTypes.isOctetType(input)) {
|
|
22
|
+
if (opts.type !== "mutation" && opts.methodOverride !== "POST") throw new Error("Octet type input is only supported for mutations");
|
|
23
|
+
return require_httpUtils.httpRequest({
|
|
24
|
+
...opts,
|
|
25
|
+
contentTypeHeader: "application/octet-stream",
|
|
26
|
+
getUrl: require_httpUtils.getUrl,
|
|
27
|
+
getBody: () => input
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return require_httpUtils.jsonHttpRequester(opts);
|
|
37
32
|
};
|
|
38
33
|
/**
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
observer.complete();
|
|
82
|
-
}).catch((cause)=>{
|
|
83
|
-
observer.error(TRPCClientError.TRPCClientError.from(cause, {
|
|
84
|
-
meta
|
|
85
|
-
}));
|
|
86
|
-
});
|
|
87
|
-
return ()=>{
|
|
88
|
-
// noop
|
|
89
|
-
};
|
|
90
|
-
});
|
|
91
|
-
};
|
|
92
|
-
};
|
|
34
|
+
* @see https://trpc.io/docs/client/links/httpLink
|
|
35
|
+
*/
|
|
36
|
+
function httpLink(opts) {
|
|
37
|
+
const resolvedOpts = require_httpUtils.resolveHTTPLinkOptions(opts);
|
|
38
|
+
return () => {
|
|
39
|
+
return ({ op }) => {
|
|
40
|
+
return (0, __trpc_server_observable.observable)((observer) => {
|
|
41
|
+
const { path, input, type } = op;
|
|
42
|
+
/* istanbul ignore if -- @preserve */
|
|
43
|
+
if (type === "subscription") throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`");
|
|
44
|
+
const request = universalRequester({
|
|
45
|
+
...resolvedOpts,
|
|
46
|
+
type,
|
|
47
|
+
path,
|
|
48
|
+
input,
|
|
49
|
+
signal: op.signal,
|
|
50
|
+
headers() {
|
|
51
|
+
if (!opts.headers) return {};
|
|
52
|
+
if (typeof opts.headers === "function") return opts.headers({ op });
|
|
53
|
+
return opts.headers;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
let meta = void 0;
|
|
57
|
+
request.then((res) => {
|
|
58
|
+
meta = res.meta;
|
|
59
|
+
const transformed = (0, __trpc_server_unstable_core_do_not_import.transformResult)(res.json, resolvedOpts.transformer.output);
|
|
60
|
+
if (!transformed.ok) {
|
|
61
|
+
observer.error(require_TRPCClientError.TRPCClientError.from(transformed.error, { meta }));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
observer.next({
|
|
65
|
+
context: res.meta,
|
|
66
|
+
result: transformed.result
|
|
67
|
+
});
|
|
68
|
+
observer.complete();
|
|
69
|
+
}).catch((cause) => {
|
|
70
|
+
observer.error(require_TRPCClientError.TRPCClientError.from(cause, { meta }));
|
|
71
|
+
});
|
|
72
|
+
return () => {};
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
};
|
|
93
76
|
}
|
|
94
77
|
|
|
95
|
-
|
|
78
|
+
//#endregion
|
|
79
|
+
exports.httpLink = httpLink;
|
package/dist/links/httpLink.mjs
CHANGED
|
@@ -1,93 +1,79 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import { TRPCClientError } from "../TRPCClientError.mjs";
|
|
2
|
+
import { isFormData, isOctetType } from "./internals/contentTypes.mjs";
|
|
3
|
+
import { getUrl, httpRequest, jsonHttpRequester, resolveHTTPLinkOptions } from "./internals/httpUtils.mjs";
|
|
4
|
+
import { observable } from "@trpc/server/observable";
|
|
5
|
+
import { transformResult } from "@trpc/server/unstable-core-do-not-import";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
return jsonHttpRequester(opts);
|
|
7
|
+
//#region src/links/httpLink.ts
|
|
8
|
+
const universalRequester = (opts) => {
|
|
9
|
+
if ("input" in opts) {
|
|
10
|
+
const { input } = opts;
|
|
11
|
+
if (isFormData(input)) {
|
|
12
|
+
if (opts.type !== "mutation" && opts.methodOverride !== "POST") throw new Error("FormData is only supported for mutations");
|
|
13
|
+
return httpRequest({
|
|
14
|
+
...opts,
|
|
15
|
+
contentTypeHeader: void 0,
|
|
16
|
+
getUrl,
|
|
17
|
+
getBody: () => input
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
if (isOctetType(input)) {
|
|
21
|
+
if (opts.type !== "mutation" && opts.methodOverride !== "POST") throw new Error("Octet type input is only supported for mutations");
|
|
22
|
+
return httpRequest({
|
|
23
|
+
...opts,
|
|
24
|
+
contentTypeHeader: "application/octet-stream",
|
|
25
|
+
getUrl,
|
|
26
|
+
getBody: () => input
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return jsonHttpRequester(opts);
|
|
35
31
|
};
|
|
36
32
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
observer.complete();
|
|
80
|
-
}).catch((cause)=>{
|
|
81
|
-
observer.error(TRPCClientError.from(cause, {
|
|
82
|
-
meta
|
|
83
|
-
}));
|
|
84
|
-
});
|
|
85
|
-
return ()=>{
|
|
86
|
-
// noop
|
|
87
|
-
};
|
|
88
|
-
});
|
|
89
|
-
};
|
|
90
|
-
};
|
|
33
|
+
* @see https://trpc.io/docs/client/links/httpLink
|
|
34
|
+
*/
|
|
35
|
+
function httpLink(opts) {
|
|
36
|
+
const resolvedOpts = resolveHTTPLinkOptions(opts);
|
|
37
|
+
return () => {
|
|
38
|
+
return ({ op }) => {
|
|
39
|
+
return observable((observer) => {
|
|
40
|
+
const { path, input, type } = op;
|
|
41
|
+
/* istanbul ignore if -- @preserve */
|
|
42
|
+
if (type === "subscription") throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`");
|
|
43
|
+
const request = universalRequester({
|
|
44
|
+
...resolvedOpts,
|
|
45
|
+
type,
|
|
46
|
+
path,
|
|
47
|
+
input,
|
|
48
|
+
signal: op.signal,
|
|
49
|
+
headers() {
|
|
50
|
+
if (!opts.headers) return {};
|
|
51
|
+
if (typeof opts.headers === "function") return opts.headers({ op });
|
|
52
|
+
return opts.headers;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
let meta = void 0;
|
|
56
|
+
request.then((res) => {
|
|
57
|
+
meta = res.meta;
|
|
58
|
+
const transformed = transformResult(res.json, resolvedOpts.transformer.output);
|
|
59
|
+
if (!transformed.ok) {
|
|
60
|
+
observer.error(TRPCClientError.from(transformed.error, { meta }));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
observer.next({
|
|
64
|
+
context: res.meta,
|
|
65
|
+
result: transformed.result
|
|
66
|
+
});
|
|
67
|
+
observer.complete();
|
|
68
|
+
}).catch((cause) => {
|
|
69
|
+
observer.error(TRPCClientError.from(cause, { meta }));
|
|
70
|
+
});
|
|
71
|
+
return () => {};
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
};
|
|
91
75
|
}
|
|
92
76
|
|
|
77
|
+
//#endregion
|
|
93
78
|
export { httpLink };
|
|
79
|
+
//# sourceMappingURL=httpLink.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpLink.mjs","names":["universalRequester: Requester","opts: HTTPLinkOptions<TRouter['_def']['_config']['$types']>","meta: HTTPResult['meta'] | undefined"],"sources":["../../src/links/httpLink.ts"],"sourcesContent":["import { observable } from '@trpc/server/observable';\nimport type {\n AnyClientTypes,\n AnyRouter,\n} from '@trpc/server/unstable-core-do-not-import';\nimport { transformResult } from '@trpc/server/unstable-core-do-not-import';\nimport { TRPCClientError } from '../TRPCClientError';\nimport type {\n HTTPLinkBaseOptions,\n HTTPResult,\n Requester,\n} from './internals/httpUtils';\nimport {\n getUrl,\n httpRequest,\n jsonHttpRequester,\n resolveHTTPLinkOptions,\n} from './internals/httpUtils';\nimport {\n isFormData,\n isOctetType,\n type HTTPHeaders,\n type Operation,\n type TRPCLink,\n} from './types';\n\nexport type HTTPLinkOptions<TRoot extends AnyClientTypes> =\n HTTPLinkBaseOptions<TRoot> & {\n /**\n * Headers to be set on outgoing requests or a callback that of said headers\n * @see http://trpc.io/docs/client/headers\n */\n headers?:\n | HTTPHeaders\n | ((opts: { op: Operation }) => HTTPHeaders | Promise<HTTPHeaders>);\n };\n\nconst universalRequester: Requester = (opts) => {\n if ('input' in opts) {\n const { input } = opts;\n if (isFormData(input)) {\n if (opts.type !== 'mutation' && opts.methodOverride !== 'POST') {\n throw new Error('FormData is only supported for mutations');\n }\n\n return httpRequest({\n ...opts,\n // The browser will set this automatically and include the boundary= in it\n contentTypeHeader: undefined,\n getUrl,\n getBody: () => input,\n });\n }\n\n if (isOctetType(input)) {\n if (opts.type !== 'mutation' && opts.methodOverride !== 'POST') {\n throw new Error('Octet type input is only supported for mutations');\n }\n\n return httpRequest({\n ...opts,\n contentTypeHeader: 'application/octet-stream',\n getUrl,\n getBody: () => input,\n });\n }\n }\n\n return jsonHttpRequester(opts);\n};\n\n/**\n * @see https://trpc.io/docs/client/links/httpLink\n */\nexport function httpLink<TRouter extends AnyRouter = AnyRouter>(\n opts: HTTPLinkOptions<TRouter['_def']['_config']['$types']>,\n): TRPCLink<TRouter> {\n const resolvedOpts = resolveHTTPLinkOptions(opts);\n return () => {\n return ({ op }) => {\n return observable((observer) => {\n const { path, input, type } = op;\n /* istanbul ignore if -- @preserve */\n if (type === 'subscription') {\n throw new Error(\n 'Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`',\n );\n }\n\n const request = universalRequester({\n ...resolvedOpts,\n type,\n path,\n input,\n signal: op.signal,\n headers() {\n if (!opts.headers) {\n return {};\n }\n if (typeof opts.headers === 'function') {\n return opts.headers({\n op,\n });\n }\n return opts.headers;\n },\n });\n let meta: HTTPResult['meta'] | undefined = undefined;\n request\n .then((res) => {\n meta = res.meta;\n const transformed = transformResult(\n res.json,\n resolvedOpts.transformer.output,\n );\n\n if (!transformed.ok) {\n observer.error(\n TRPCClientError.from(transformed.error, {\n meta,\n }),\n );\n return;\n }\n observer.next({\n context: res.meta,\n result: transformed.result,\n });\n observer.complete();\n })\n .catch((cause) => {\n observer.error(TRPCClientError.from(cause, { meta }));\n });\n\n return () => {\n // noop\n };\n });\n };\n };\n}\n"],"mappings":";;;;;;;AAqCA,MAAMA,qBAAgC,CAAC,SAAS;AAC9C,KAAI,WAAW,MAAM;EACnB,MAAM,EAAE,OAAO,GAAG;AAClB,MAAI,WAAW,MAAM,EAAE;AACrB,OAAI,KAAK,SAAS,cAAc,KAAK,mBAAmB,OACtD,OAAM,IAAI,MAAM;AAGlB,UAAO,YAAY;IACjB,GAAG;IAEH;IACA;IACA,SAAS,MAAM;GAChB,EAAC;EACH;AAED,MAAI,YAAY,MAAM,EAAE;AACtB,OAAI,KAAK,SAAS,cAAc,KAAK,mBAAmB,OACtD,OAAM,IAAI,MAAM;AAGlB,UAAO,YAAY;IACjB,GAAG;IACH,mBAAmB;IACnB;IACA,SAAS,MAAM;GAChB,EAAC;EACH;CACF;AAED,QAAO,kBAAkB,KAAK;AAC/B;;;;AAKD,SAAgB,SACdC,MACmB;CACnB,MAAM,eAAe,uBAAuB,KAAK;AACjD,QAAO,MAAM;AACX,SAAO,CAAC,EAAE,IAAI,KAAK;AACjB,UAAO,WAAW,CAAC,aAAa;IAC9B,MAAM,EAAE,MAAM,OAAO,MAAM,GAAG;;AAE9B,QAAI,SAAS,eACX,OAAM,IAAI,MACR;IAIJ,MAAM,UAAU,mBAAmB;KACjC,GAAG;KACH;KACA;KACA;KACA,QAAQ,GAAG;KACX,UAAU;AACR,WAAK,KAAK,QACR,QAAO,CAAE;AAEX,iBAAW,KAAK,YAAY,WAC1B,QAAO,KAAK,QAAQ,EAClB,GACD,EAAC;AAEJ,aAAO,KAAK;KACb;IACF,EAAC;IACF,IAAIC;AACJ,YACG,KAAK,CAAC,QAAQ;AACb,YAAO,IAAI;KACX,MAAM,cAAc,gBAClB,IAAI,MACJ,aAAa,YAAY,OAC1B;AAED,UAAK,YAAY,IAAI;AACnB,eAAS,MACP,gBAAgB,KAAK,YAAY,OAAO,EACtC,KACD,EAAC,CACH;AACD;KACD;AACD,cAAS,KAAK;MACZ,SAAS,IAAI;MACb,QAAQ,YAAY;KACrB,EAAC;AACF,cAAS,UAAU;IACpB,EAAC,CACD,MAAM,CAAC,UAAU;AAChB,cAAS,MAAM,gBAAgB,KAAK,OAAO,EAAE,KAAM,EAAC,CAAC;IACtD,EAAC;AAEJ,WAAO,MAAM,CAEZ;GACF,EAAC;EACH;CACF;AACF"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Operation, TRPCLink } from "./types.mjs";
|
|
2
|
+
import { TransformerOptions } from "../internals/transformer.mjs";
|
|
3
|
+
import { UrlOptionsWithConnectionParams } from "./internals/urlWithConnectionParams.mjs";
|
|
4
|
+
import { AnyClientTypes, EventSourceLike, InferrableClientTypes, inferClientTypes } from "@trpc/server/unstable-core-do-not-import";
|
|
5
|
+
|
|
6
|
+
//#region src/links/httpSubscriptionLink.d.ts
|
|
7
|
+
type HTTPSubscriptionLinkOptions<TRoot extends AnyClientTypes, TEventSource extends EventSourceLike.AnyConstructor = typeof EventSource> = {
|
|
8
|
+
/**
|
|
9
|
+
* EventSource ponyfill
|
|
10
|
+
*/
|
|
11
|
+
EventSource?: TEventSource;
|
|
12
|
+
/**
|
|
13
|
+
* EventSource options or a callback that returns them
|
|
14
|
+
*/
|
|
15
|
+
eventSourceOptions?: EventSourceLike.InitDictOf<TEventSource> | ((opts: {
|
|
16
|
+
op: Operation;
|
|
17
|
+
}) => EventSourceLike.InitDictOf<TEventSource> | Promise<EventSourceLike.InitDictOf<TEventSource>>);
|
|
18
|
+
} & TransformerOptions<TRoot> & UrlOptionsWithConnectionParams;
|
|
19
|
+
/**
|
|
20
|
+
* @see https://trpc.io/docs/client/links/httpSubscriptionLink
|
|
21
|
+
*/
|
|
22
|
+
declare function httpSubscriptionLink<TInferrable extends InferrableClientTypes, TEventSource extends EventSourceLike.AnyConstructor>(opts: HTTPSubscriptionLinkOptions<inferClientTypes<TInferrable>, TEventSource>): TRPCLink<TInferrable>;
|
|
23
|
+
/**
|
|
24
|
+
* @deprecated use {@link httpSubscriptionLink} instead
|
|
25
|
+
*/
|
|
26
|
+
declare const unstable_httpSubscriptionLink: typeof httpSubscriptionLink;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { httpSubscriptionLink, unstable_httpSubscriptionLink };
|
|
29
|
+
//# sourceMappingURL=httpSubscriptionLink.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpSubscriptionLink.d.mts","names":[],"sources":["../../src/links/httpSubscriptionLink.ts"],"sourcesContent":[],"mappings":";;;;;;KAwCK,0CACW,qCACO,eAAA,CAAgB,wBAAwB;;AAnBZ;;EAiBnB,WAChB,CAAA,EAMA,YANA;EAAc;;;EAMF,kBAKK,CAAA,EAA3B,eAAA,CAAgB,UAAW,CAAA,YAAA,CAAA,GAAA,CAAA,CAAA,IAAA,EAAA;IAA3B,EAAA,EAEM,SAFN;EAA0B,CAAA,EAEpB,GAEF,eAAA,CAAgB,UAFd,CAEyB,YAFzB,CAAA,GAGF,OAHE,CAGM,eAAA,CAAgB,UAHtB,CAGiC,YAHjC,CAAA,CAAA,CAAA;CAAS,GAIjB,kBAFiC,CAEd,KAFc,CAAA,GAGnC,8BAHmC;;;;AAC3B,iBAOM,oBAPN,CAAA,oBAQY,qBARZ,EAAA,qBASa,eAAA,CAAgB,cAT7B,CAAA,CAAA,IAAA,EAWF,2BAXE,CAYN,gBAZM,CAYW,WAZX,CAAA,EAaN,YAbM,CAAA,CAAA,EAeP,QAfO,CAeE,WAfF,CAAA;;;;AAEsB,cAyLnB,6BAzLmB,EAAA,OAyLU,oBAzLV"}
|
|
@@ -1,26 +1,29 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
1
|
+
import { Operation, TRPCLink } from "./types.js";
|
|
2
|
+
import { TransformerOptions } from "../internals/transformer.js";
|
|
3
|
+
import { UrlOptionsWithConnectionParams } from "./internals/urlWithConnectionParams.js";
|
|
4
|
+
import { AnyClientTypes, EventSourceLike, InferrableClientTypes, inferClientTypes } from "@trpc/server/unstable-core-do-not-import";
|
|
5
|
+
|
|
6
|
+
//#region src/links/httpSubscriptionLink.d.ts
|
|
5
7
|
type HTTPSubscriptionLinkOptions<TRoot extends AnyClientTypes, TEventSource extends EventSourceLike.AnyConstructor = typeof EventSource> = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
/**
|
|
9
|
+
* EventSource ponyfill
|
|
10
|
+
*/
|
|
11
|
+
EventSource?: TEventSource;
|
|
12
|
+
/**
|
|
13
|
+
* EventSource options or a callback that returns them
|
|
14
|
+
*/
|
|
15
|
+
eventSourceOptions?: EventSourceLike.InitDictOf<TEventSource> | ((opts: {
|
|
16
|
+
op: Operation;
|
|
17
|
+
}) => EventSourceLike.InitDictOf<TEventSource> | Promise<EventSourceLike.InitDictOf<TEventSource>>);
|
|
16
18
|
} & TransformerOptions<TRoot> & UrlOptionsWithConnectionParams;
|
|
17
19
|
/**
|
|
18
20
|
* @see https://trpc.io/docs/client/links/httpSubscriptionLink
|
|
19
21
|
*/
|
|
20
|
-
|
|
22
|
+
declare function httpSubscriptionLink<TInferrable extends InferrableClientTypes, TEventSource extends EventSourceLike.AnyConstructor>(opts: HTTPSubscriptionLinkOptions<inferClientTypes<TInferrable>, TEventSource>): TRPCLink<TInferrable>;
|
|
21
23
|
/**
|
|
22
24
|
* @deprecated use {@link httpSubscriptionLink} instead
|
|
23
25
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
+
declare const unstable_httpSubscriptionLink: typeof httpSubscriptionLink;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { httpSubscriptionLink, unstable_httpSubscriptionLink };
|
|
26
29
|
//# sourceMappingURL=httpSubscriptionLink.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpSubscriptionLink.d.ts","
|
|
1
|
+
{"version":3,"file":"httpSubscriptionLink.d.ts","names":[],"sources":["../../src/links/httpSubscriptionLink.ts"],"sourcesContent":[],"mappings":";;;;;;KAwCK,0CACW,qCACO,eAAA,CAAgB,wBAAwB;;AAnBZ;;EAiBnB,WAChB,CAAA,EAMA,YANA;EAAc;;;EAMF,kBAKK,CAAA,EAA3B,eAAA,CAAgB,UAAW,CAAA,YAAA,CAAA,GAAA,CAAA,CAAA,IAAA,EAAA;IAA3B,EAAA,EAEM,SAFN;EAA0B,CAAA,EAEpB,GAEF,eAAA,CAAgB,UAFd,CAEyB,YAFzB,CAAA,GAGF,OAHE,CAGM,eAAA,CAAgB,UAHtB,CAGiC,YAHjC,CAAA,CAAA,CAAA;CAAS,GAIjB,kBAFiC,CAEd,KAFc,CAAA,GAGnC,8BAHmC;;;;AAC3B,iBAOM,oBAPN,CAAA,oBAQY,qBARZ,EAAA,qBASa,eAAA,CAAgB,cAT7B,CAAA,CAAA,IAAA,EAWF,2BAXE,CAYN,gBAZM,CAYW,WAZX,CAAA,EAaN,YAbM,CAAA,CAAA,EAeP,QAfO,CAeE,WAfF,CAAA;;;;AAEsB,cAyLnB,6BAzLmB,EAAA,OAyLU,oBAzLV"}
|