@trpc/client 11.18.1-canary.9 → 11.19.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/bin/intent.js +0 -0
- package/dist/TRPCClientError-CmHlBkPF.cjs +56 -0
- package/dist/{TRPCClientError-apv8gw59.mjs → TRPCClientError-CxFRO7Js.mjs} +11 -14
- package/dist/TRPCClientError-CxFRO7Js.mjs.map +1 -0
- package/dist/{httpBatchLink-LhidKAPw.mjs → httpBatchLink-BMtWxLJV.mjs} +25 -72
- package/dist/httpBatchLink-BMtWxLJV.mjs.map +1 -0
- package/dist/{httpBatchLink.d-7jyWtY5H.d.cts → httpBatchLink-Br-pzPXf.d.cts} +4 -8
- package/dist/httpBatchLink-Br-pzPXf.d.cts.map +1 -0
- package/dist/{httpBatchLink-BGZRsGNf.cjs → httpBatchLink-DO3WQoxu.cjs} +37 -104
- package/dist/{httpBatchLink.d-p8Y9QM8p.d.mts → httpBatchLink-nvc48L_N.d.mts} +4 -8
- package/dist/httpBatchLink-nvc48L_N.d.mts.map +1 -0
- package/dist/{httpLink.d-CjpPCq4q.d.mts → httpLink-D5FQijY2.d.cts} +4 -7
- package/dist/httpLink-D5FQijY2.d.cts.map +1 -0
- package/dist/{httpLink-B8Iv31Ee.cjs → httpLink-MDJTSlpi.cjs} +39 -38
- package/dist/{httpLink-lG_6juPY.mjs → httpLink-Tm93WWFA.mjs} +17 -14
- package/dist/httpLink-Tm93WWFA.mjs.map +1 -0
- package/dist/{httpLink.d-D5qR9haY.d.cts → httpLink-eSAq8J9S.d.mts} +4 -7
- package/dist/httpLink-eSAq8J9S.d.mts.map +1 -0
- package/dist/{httpUtils.d-BqmeKEGo.d.cts → httpUtils-C37jRVnj.d.mts} +4 -6
- package/dist/httpUtils-C37jRVnj.d.mts.map +1 -0
- package/dist/{httpUtils-pyf5RF99.mjs → httpUtils-CB_100ND.mjs} +51 -14
- package/dist/httpUtils-CB_100ND.mjs.map +1 -0
- package/dist/{httpUtils.d-C5t5to0D.d.mts → httpUtils-CUqAubVD.d.cts} +4 -6
- package/dist/httpUtils-CUqAubVD.d.cts.map +1 -0
- package/dist/{httpUtils-wv2o-njD.cjs → httpUtils-cggqcHz0.cjs} +102 -49
- package/dist/index.cjs +248 -309
- package/dist/index.d.cts +38 -41
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +38 -41
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +212 -272
- package/dist/index.mjs.map +1 -1
- package/dist/links/httpBatchLink.cjs +3 -7
- package/dist/links/httpBatchLink.d.cts +1 -5
- package/dist/links/httpBatchLink.d.mts +1 -5
- package/dist/links/httpBatchLink.mjs +2 -7
- package/dist/links/httpLink.cjs +3 -7
- package/dist/links/httpLink.d.cts +1 -5
- package/dist/links/httpLink.d.mts +1 -5
- package/dist/links/httpLink.mjs +2 -7
- package/dist/links/loggerLink.cjs +113 -4
- package/dist/links/loggerLink.d.cts +1 -3
- package/dist/links/loggerLink.d.mts +1 -3
- package/dist/links/loggerLink.mjs +113 -3
- package/dist/links/loggerLink.mjs.map +1 -0
- package/dist/links/splitLink.cjs +3 -3
- package/dist/links/splitLink.d.cts +1 -3
- package/dist/links/splitLink.d.mts +1 -3
- package/dist/links/splitLink.mjs +2 -3
- package/dist/links/wsLink/wsLink.cjs +3 -6
- package/dist/links/wsLink/wsLink.d.cts +2 -5
- package/dist/links/wsLink/wsLink.d.mts +2 -5
- package/dist/links/wsLink/wsLink.mjs +2 -6
- package/dist/{loggerLink.d-0ABgt7oh.d.mts → loggerLink-2o-uZ3r1.d.cts} +3 -4
- package/dist/loggerLink-2o-uZ3r1.d.cts.map +1 -0
- package/dist/{loggerLink.d-BxSIj5kx.d.cts → loggerLink-CFercTVc.d.mts} +3 -4
- package/dist/loggerLink-CFercTVc.d.mts.map +1 -0
- package/dist/objectSpread2-D-dJi1gK.cjs +73 -0
- package/dist/objectSpread2-weooBxVk.mjs +62 -0
- package/dist/{splitLink-B7Cuf2c_.mjs → splitLink-BZPioDdG.mjs} +6 -11
- package/dist/splitLink-BZPioDdG.mjs.map +1 -0
- package/dist/{splitLink.d-BBFK_mCw.d.cts → splitLink-CJdcmEmS.d.cts} +3 -6
- package/dist/splitLink-CJdcmEmS.d.cts.map +1 -0
- package/dist/{splitLink.d-CkHNg1Se.d.mts → splitLink-CixmF14P.d.mts} +3 -6
- package/dist/splitLink-CixmF14P.d.mts.map +1 -0
- package/dist/{splitLink-BMgxggng.cjs → splitLink-MXnaFlEb.cjs} +17 -24
- package/dist/{subscriptions.d-Ciljg_dH.d.cts → subscriptions-DcqRZc4h.d.cts} +2 -2
- package/dist/subscriptions-DcqRZc4h.d.cts.map +1 -0
- package/dist/{subscriptions.d-Dlr1nWGD.d.mts → subscriptions-DcqRZc4h.d.mts} +2 -2
- package/dist/subscriptions-DcqRZc4h.d.mts.map +1 -0
- package/dist/{types.d-CAr6snH0.d.mts → types-BxbMkv6C.d.cts} +4 -15
- package/dist/types-BxbMkv6C.d.cts.map +1 -0
- package/dist/{types.d-Dmmedc5G.d.cts → types-CAPs7vhA.d.mts} +4 -15
- package/dist/types-CAPs7vhA.d.mts.map +1 -0
- package/dist/{unstable-internals.d-BOmV7EK1.d.mts → unstable-internals-CE8gFBQ9.d.cts} +2 -4
- package/dist/unstable-internals-CE8gFBQ9.d.cts.map +1 -0
- package/dist/{unstable-internals.d-kWsZTlQq.d.cts → unstable-internals-CE8gFBQ9.d.mts} +2 -4
- package/dist/unstable-internals-CE8gFBQ9.d.mts.map +1 -0
- package/dist/unstable-internals.cjs +28 -3
- package/dist/unstable-internals.d.cts +2 -2
- package/dist/unstable-internals.d.mts +2 -2
- package/dist/unstable-internals.mjs +28 -2
- package/dist/unstable-internals.mjs.map +1 -0
- package/dist/{wsLink-DSf4KOdW.mjs → wsLink-Bm5LKL6z.mjs} +73 -94
- package/dist/wsLink-Bm5LKL6z.mjs.map +1 -0
- package/dist/{wsLink-CobRSm6C.cjs → wsLink-CKAsNP9P.cjs} +100 -123
- package/dist/{wsLink.d-pFN64NkG.d.mts → wsLink-DoiyfDgJ.d.cts} +11 -31
- package/dist/wsLink-DoiyfDgJ.d.cts.map +1 -0
- package/dist/{wsLink.d-DzZZZGZQ.d.cts → wsLink-U8pJ7LD2.d.mts} +11 -31
- package/dist/wsLink-U8pJ7LD2.d.mts.map +1 -0
- package/package.json +10 -10
- package/src/getFetch.ts +3 -2
- package/src/links/httpBatchLink.ts +12 -3
- package/src/links/httpBatchStreamLink.ts +7 -8
- package/src/links/httpLink.ts +9 -2
- package/src/links/httpSubscriptionLink.ts +1 -3
- package/src/links/internals/subscriptions.ts +3 -2
- package/src/links/types.ts +1 -2
- package/src/links/wsLink/wsClient/wsClient.ts +8 -1
- package/dist/TRPCClientError-CQrTQLrk.cjs +0 -61
- package/dist/TRPCClientError-apv8gw59.mjs.map +0 -1
- package/dist/chunk-DWy1uDak.cjs +0 -39
- package/dist/httpBatchLink-LhidKAPw.mjs.map +0 -1
- package/dist/httpBatchLink.d-7jyWtY5H.d.cts.map +0 -1
- package/dist/httpBatchLink.d-p8Y9QM8p.d.mts.map +0 -1
- package/dist/httpLink-lG_6juPY.mjs.map +0 -1
- package/dist/httpLink.d-CjpPCq4q.d.mts.map +0 -1
- package/dist/httpLink.d-D5qR9haY.d.cts.map +0 -1
- package/dist/httpUtils-pyf5RF99.mjs.map +0 -1
- package/dist/httpUtils.d-BqmeKEGo.d.cts.map +0 -1
- package/dist/httpUtils.d-C5t5to0D.d.mts.map +0 -1
- package/dist/loggerLink-CuYvRzyH.cjs +0 -123
- package/dist/loggerLink-ineCN1PO.mjs +0 -118
- package/dist/loggerLink-ineCN1PO.mjs.map +0 -1
- package/dist/loggerLink.d-0ABgt7oh.d.mts.map +0 -1
- package/dist/loggerLink.d-BxSIj5kx.d.cts.map +0 -1
- package/dist/objectSpread2-Bsvh_OqM.cjs +0 -100
- package/dist/objectSpread2-BvkFp-_Y.mjs +0 -114
- package/dist/objectSpread2-BvkFp-_Y.mjs.map +0 -1
- package/dist/splitLink-B7Cuf2c_.mjs.map +0 -1
- package/dist/splitLink.d-BBFK_mCw.d.cts.map +0 -1
- package/dist/splitLink.d-CkHNg1Se.d.mts.map +0 -1
- package/dist/subscriptions.d-Ciljg_dH.d.cts.map +0 -1
- package/dist/subscriptions.d-Dlr1nWGD.d.mts.map +0 -1
- package/dist/types.d-CAr6snH0.d.mts.map +0 -1
- package/dist/types.d-Dmmedc5G.d.cts.map +0 -1
- package/dist/unstable-internals-Bg7n9BBj.mjs +0 -29
- package/dist/unstable-internals-Bg7n9BBj.mjs.map +0 -1
- package/dist/unstable-internals-M84gUQCV.cjs +0 -34
- package/dist/unstable-internals.d-BOmV7EK1.d.mts.map +0 -1
- package/dist/unstable-internals.d-kWsZTlQq.d.cts.map +0 -1
- package/dist/wsLink-DSf4KOdW.mjs.map +0 -1
- package/dist/wsLink.d-DzZZZGZQ.d.cts.map +0 -1
- package/dist/wsLink.d-pFN64NkG.d.mts.map +0 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HTTPLinkBaseOptions } from "./httpUtils
|
|
1
|
+
import { n as Operation, t as HTTPHeaders, u as TRPCLink } from "./types-BxbMkv6C.cjs";
|
|
2
|
+
import { t as HTTPLinkBaseOptions } from "./httpUtils-CUqAubVD.cjs";
|
|
3
3
|
import { AnyClientTypes, AnyRouter } from "@trpc/server/unstable-core-do-not-import";
|
|
4
|
-
|
|
5
4
|
//#region src/links/httpLink.d.ts
|
|
6
5
|
type HTTPLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TRoot> & {
|
|
7
6
|
/**
|
|
@@ -16,8 +15,6 @@ type HTTPLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TRoot>
|
|
|
16
15
|
* @see https://trpc.io/docs/client/links/httpLink
|
|
17
16
|
*/
|
|
18
17
|
declare function httpLink<TRouter extends AnyRouter = AnyRouter>(opts: HTTPLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
|
|
19
|
-
//# sourceMappingURL=httpLink.d.ts.map
|
|
20
|
-
|
|
21
18
|
//#endregion
|
|
22
|
-
export {
|
|
23
|
-
//# sourceMappingURL=httpLink
|
|
19
|
+
export { httpLink as n, HTTPLinkOptions as t };
|
|
20
|
+
//# sourceMappingURL=httpLink-D5FQijY2.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpLink-D5FQijY2.d.cts","names":[],"sources":["../src/links/httpLink.ts"],"mappings":";;;;KA2BY,gBAAgB,cAAc,kBACxC,oBAAoB;;;;;EAKlB,UACI,gBACE;IAAQ,IAAI;QAAgB,cAAc,QAAQ;;;;;iBAwC5C,SAAS,gBAAgB,YAAY,WACnD,MAAM,gBAAgB,wCACrB,SAAS"}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const __trpc_server_unstable_core_do_not_import = require_chunk.__toESM(require("@trpc/server/unstable-core-do-not-import"));
|
|
7
|
-
|
|
1
|
+
const require_objectSpread2 = require("./objectSpread2-D-dJi1gK.cjs");
|
|
2
|
+
const require_TRPCClientError = require("./TRPCClientError-CmHlBkPF.cjs");
|
|
3
|
+
const require_httpUtils = require("./httpUtils-cggqcHz0.cjs");
|
|
4
|
+
let _trpc_server_observable = require("@trpc/server/observable");
|
|
5
|
+
let _trpc_server_unstable_core_do_not_import = require("@trpc/server/unstable-core-do-not-import");
|
|
8
6
|
//#region src/links/internals/contentTypes.ts
|
|
9
7
|
function isOctetType(input) {
|
|
10
8
|
return input instanceof Uint8Array || input instanceof Blob;
|
|
@@ -15,16 +13,14 @@ function isFormData(input) {
|
|
|
15
13
|
function isNonJsonSerializable(input) {
|
|
16
14
|
return isOctetType(input) || isFormData(input);
|
|
17
15
|
}
|
|
18
|
-
|
|
19
16
|
//#endregion
|
|
20
17
|
//#region src/links/httpLink.ts
|
|
21
|
-
var import_objectSpread2 = require_chunk.__toESM(require_objectSpread2$1.require_objectSpread2(), 1);
|
|
22
18
|
const universalRequester = (opts) => {
|
|
23
19
|
if ("input" in opts) {
|
|
24
20
|
const { input } = opts;
|
|
25
21
|
if (isFormData(input)) {
|
|
26
22
|
if (opts.type !== "mutation" && opts.methodOverride !== "POST") throw new Error("FormData is only supported for mutations");
|
|
27
|
-
return require_httpUtils.httpRequest(
|
|
23
|
+
return require_httpUtils.httpRequest(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, opts), {}, {
|
|
28
24
|
contentTypeHeader: void 0,
|
|
29
25
|
getUrl: require_httpUtils.getUrl,
|
|
30
26
|
getBody: () => input
|
|
@@ -32,7 +28,7 @@ const universalRequester = (opts) => {
|
|
|
32
28
|
}
|
|
33
29
|
if (isOctetType(input)) {
|
|
34
30
|
if (opts.type !== "mutation" && opts.methodOverride !== "POST") throw new Error("Octet type input is only supported for mutations");
|
|
35
|
-
return require_httpUtils.httpRequest(
|
|
31
|
+
return require_httpUtils.httpRequest(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, opts), {}, {
|
|
36
32
|
contentTypeHeader: "application/octet-stream",
|
|
37
33
|
getUrl: require_httpUtils.getUrl,
|
|
38
34
|
getBody: () => input
|
|
@@ -49,25 +45,28 @@ function httpLink(opts) {
|
|
|
49
45
|
return () => {
|
|
50
46
|
return (operationOpts) => {
|
|
51
47
|
const { op } = operationOpts;
|
|
52
|
-
return (0,
|
|
48
|
+
return (0, _trpc_server_observable.observable)((observer) => {
|
|
53
49
|
const { path, input, type } = op;
|
|
54
50
|
/* istanbul ignore if -- @preserve */
|
|
55
51
|
if (type === "subscription") throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`");
|
|
56
|
-
const
|
|
52
|
+
const ac = new AbortController();
|
|
53
|
+
const request = universalRequester(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, resolvedOpts), {}, {
|
|
57
54
|
type,
|
|
58
55
|
path,
|
|
59
56
|
input,
|
|
60
|
-
signal: op.signal,
|
|
57
|
+
signal: require_httpUtils.raceAbortSignals(op.signal, ac.signal),
|
|
61
58
|
headers() {
|
|
62
59
|
if (!opts.headers) return {};
|
|
63
60
|
if (typeof opts.headers === "function") return opts.headers({ op });
|
|
64
61
|
return opts.headers;
|
|
65
62
|
}
|
|
66
63
|
}));
|
|
64
|
+
let isDone = false;
|
|
67
65
|
let meta = void 0;
|
|
68
66
|
request.then((res) => {
|
|
67
|
+
isDone = true;
|
|
69
68
|
meta = res.meta;
|
|
70
|
-
const transformed = (0,
|
|
69
|
+
const transformed = (0, _trpc_server_unstable_core_do_not_import.transformResult)(res.json, resolvedOpts.transformer.output);
|
|
71
70
|
if (!transformed.ok) {
|
|
72
71
|
observer.error(require_TRPCClientError.TRPCClientError.from(transformed.error, { meta }));
|
|
73
72
|
return;
|
|
@@ -78,36 +77,38 @@ function httpLink(opts) {
|
|
|
78
77
|
});
|
|
79
78
|
observer.complete();
|
|
80
79
|
}).catch((cause) => {
|
|
80
|
+
isDone = true;
|
|
81
81
|
observer.error(require_TRPCClientError.TRPCClientError.from(cause, { meta }));
|
|
82
82
|
});
|
|
83
|
-
return () => {
|
|
83
|
+
return () => {
|
|
84
|
+
if (!isDone) ac.abort();
|
|
85
|
+
};
|
|
84
86
|
});
|
|
85
87
|
};
|
|
86
88
|
};
|
|
87
89
|
}
|
|
88
|
-
|
|
89
90
|
//#endregion
|
|
90
|
-
Object.defineProperty(exports,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
Object.defineProperty(exports, "httpLink", {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
get: function() {
|
|
94
|
+
return httpLink;
|
|
95
|
+
}
|
|
95
96
|
});
|
|
96
|
-
Object.defineProperty(exports,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
97
|
+
Object.defineProperty(exports, "isFormData", {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
get: function() {
|
|
100
|
+
return isFormData;
|
|
101
|
+
}
|
|
101
102
|
});
|
|
102
|
-
Object.defineProperty(exports,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
Object.defineProperty(exports, "isNonJsonSerializable", {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
get: function() {
|
|
106
|
+
return isNonJsonSerializable;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(exports, "isOctetType", {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function() {
|
|
112
|
+
return isOctetType;
|
|
113
|
+
}
|
|
107
114
|
});
|
|
108
|
-
Object.defineProperty(exports, 'isOctetType', {
|
|
109
|
-
enumerable: true,
|
|
110
|
-
get: function () {
|
|
111
|
-
return isOctetType;
|
|
112
|
-
}
|
|
113
|
-
});
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TRPCClientError } from "./TRPCClientError-
|
|
3
|
-
import {
|
|
1
|
+
import { t as _objectSpread2 } from "./objectSpread2-weooBxVk.mjs";
|
|
2
|
+
import { t as TRPCClientError } from "./TRPCClientError-CxFRO7Js.mjs";
|
|
3
|
+
import { a as jsonHttpRequester, i as httpRequest, l as raceAbortSignals, o as resolveHTTPLinkOptions, r as getUrl } from "./httpUtils-CB_100ND.mjs";
|
|
4
4
|
import { observable } from "@trpc/server/observable";
|
|
5
5
|
import { transformResult } from "@trpc/server/unstable-core-do-not-import";
|
|
6
|
-
|
|
7
6
|
//#region src/links/internals/contentTypes.ts
|
|
8
7
|
function isOctetType(input) {
|
|
9
8
|
return input instanceof Uint8Array || input instanceof Blob;
|
|
@@ -14,16 +13,14 @@ function isFormData(input) {
|
|
|
14
13
|
function isNonJsonSerializable(input) {
|
|
15
14
|
return isOctetType(input) || isFormData(input);
|
|
16
15
|
}
|
|
17
|
-
|
|
18
16
|
//#endregion
|
|
19
17
|
//#region src/links/httpLink.ts
|
|
20
|
-
var import_objectSpread2 = __toESM(require_objectSpread2(), 1);
|
|
21
18
|
const universalRequester = (opts) => {
|
|
22
19
|
if ("input" in opts) {
|
|
23
20
|
const { input } = opts;
|
|
24
21
|
if (isFormData(input)) {
|
|
25
22
|
if (opts.type !== "mutation" && opts.methodOverride !== "POST") throw new Error("FormData is only supported for mutations");
|
|
26
|
-
return httpRequest((
|
|
23
|
+
return httpRequest(_objectSpread2(_objectSpread2({}, opts), {}, {
|
|
27
24
|
contentTypeHeader: void 0,
|
|
28
25
|
getUrl,
|
|
29
26
|
getBody: () => input
|
|
@@ -31,7 +28,7 @@ const universalRequester = (opts) => {
|
|
|
31
28
|
}
|
|
32
29
|
if (isOctetType(input)) {
|
|
33
30
|
if (opts.type !== "mutation" && opts.methodOverride !== "POST") throw new Error("Octet type input is only supported for mutations");
|
|
34
|
-
return httpRequest((
|
|
31
|
+
return httpRequest(_objectSpread2(_objectSpread2({}, opts), {}, {
|
|
35
32
|
contentTypeHeader: "application/octet-stream",
|
|
36
33
|
getUrl,
|
|
37
34
|
getBody: () => input
|
|
@@ -52,19 +49,22 @@ function httpLink(opts) {
|
|
|
52
49
|
const { path, input, type } = op;
|
|
53
50
|
/* istanbul ignore if -- @preserve */
|
|
54
51
|
if (type === "subscription") throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`");
|
|
55
|
-
const
|
|
52
|
+
const ac = new AbortController();
|
|
53
|
+
const request = universalRequester(_objectSpread2(_objectSpread2({}, resolvedOpts), {}, {
|
|
56
54
|
type,
|
|
57
55
|
path,
|
|
58
56
|
input,
|
|
59
|
-
signal: op.signal,
|
|
57
|
+
signal: raceAbortSignals(op.signal, ac.signal),
|
|
60
58
|
headers() {
|
|
61
59
|
if (!opts.headers) return {};
|
|
62
60
|
if (typeof opts.headers === "function") return opts.headers({ op });
|
|
63
61
|
return opts.headers;
|
|
64
62
|
}
|
|
65
63
|
}));
|
|
64
|
+
let isDone = false;
|
|
66
65
|
let meta = void 0;
|
|
67
66
|
request.then((res) => {
|
|
67
|
+
isDone = true;
|
|
68
68
|
meta = res.meta;
|
|
69
69
|
const transformed = transformResult(res.json, resolvedOpts.transformer.output);
|
|
70
70
|
if (!transformed.ok) {
|
|
@@ -77,14 +77,17 @@ function httpLink(opts) {
|
|
|
77
77
|
});
|
|
78
78
|
observer.complete();
|
|
79
79
|
}).catch((cause) => {
|
|
80
|
+
isDone = true;
|
|
80
81
|
observer.error(TRPCClientError.from(cause, { meta }));
|
|
81
82
|
});
|
|
82
|
-
return () => {
|
|
83
|
+
return () => {
|
|
84
|
+
if (!isDone) ac.abort();
|
|
85
|
+
};
|
|
83
86
|
});
|
|
84
87
|
};
|
|
85
88
|
};
|
|
86
89
|
}
|
|
87
|
-
|
|
88
90
|
//#endregion
|
|
89
|
-
export {
|
|
90
|
-
|
|
91
|
+
export { isOctetType as i, isFormData as n, isNonJsonSerializable as r, httpLink as t };
|
|
92
|
+
|
|
93
|
+
//# sourceMappingURL=httpLink-Tm93WWFA.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpLink-Tm93WWFA.mjs","names":[],"sources":["../src/links/internals/contentTypes.ts","../src/links/httpLink.ts"],"sourcesContent":["export function isOctetType(\n input: unknown,\n): input is Uint8Array<ArrayBuffer> | Blob {\n return (\n input instanceof Uint8Array ||\n // File extends from Blob but is only available in nodejs from v20\n input instanceof Blob\n );\n}\n\nexport function isFormData(input: unknown) {\n return input instanceof FormData;\n}\n\nexport function isNonJsonSerializable(input: unknown) {\n return isOctetType(input) || isFormData(input);\n}\n","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 { raceAbortSignals } from '../internals/signals';\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 (operationOpts) => {\n const { op } = operationOpts;\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 ac = new AbortController();\n const request = universalRequester({\n ...resolvedOpts,\n type,\n path,\n input,\n signal: raceAbortSignals(op.signal, ac.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 isDone = false;\n let meta: HTTPResult['meta'] | undefined = undefined;\n request\n .then((res) => {\n isDone = true;\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 isDone = true;\n observer.error(TRPCClientError.from(cause, { meta }));\n });\n\n return () => {\n if (!isDone) {\n ac.abort();\n }\n };\n });\n };\n };\n}\n"],"mappings":";;;;;;AAAA,SAAgB,YACd,OACyC;CACzC,OACE,iBAAiB,cAEjB,iBAAiB;AAErB;AAEA,SAAgB,WAAW,OAAgB;CACzC,OAAO,iBAAiB;AAC1B;AAEA,SAAgB,sBAAsB,OAAgB;CACpD,OAAO,YAAY,KAAK,KAAK,WAAW,KAAK;AAC/C;;;ACsBA,MAAM,sBAAiC,SAAS;CAC9C,IAAI,WAAW,MAAM;EACnB,MAAM,EAAE,UAAU;EAClB,IAAI,WAAW,KAAK,GAAG;GACrB,IAAI,KAAK,SAAS,cAAc,KAAK,mBAAmB,QACtD,MAAM,IAAI,MAAM,0CAA0C;GAG5D,OAAO,YAAA,eAAA,eAAA,CAAA,GACF,IAAA,GAAA,CAAA,GAAA;IAEH,mBAAmB,KAAA;IACnB;IACA,eAAe;GACjB,CAAA,CAAC;EACH;EAEA,IAAI,YAAY,KAAK,GAAG;GACtB,IAAI,KAAK,SAAS,cAAc,KAAK,mBAAmB,QACtD,MAAM,IAAI,MAAM,kDAAkD;GAGpE,OAAO,YAAA,eAAA,eAAA,CAAA,GACF,IAAA,GAAA,CAAA,GAAA;IACH,mBAAmB;IACnB;IACA,eAAe;GACjB,CAAA,CAAC;EACH;CACF;CAEA,OAAO,kBAAkB,IAAI;AAC/B;;;;AAKA,SAAgB,SACd,MACmB;CACnB,MAAM,eAAe,uBAAuB,IAAI;CAChD,aAAa;EACX,QAAQ,kBAAkB;GACxB,MAAM,EAAE,OAAO;GACf,OAAO,YAAY,aAAa;IAC9B,MAAM,EAAE,MAAM,OAAO,SAAS;;IAE9B,IAAI,SAAS,gBACX,MAAM,IAAI,MACR,sFACF;IAGF,MAAM,KAAK,IAAI,gBAAgB;IAC/B,MAAM,UAAU,mBAAA,eAAA,eAAA,CAAA,GACX,YAAA,GAAA,CAAA,GAAA;KACH;KACA;KACA;KACA,QAAQ,iBAAiB,GAAG,QAAQ,GAAG,MAAM;KAC7C,UAAU;MACR,IAAI,CAAC,KAAK,SACR,OAAO,CAAC;MAEV,IAAI,OAAO,KAAK,YAAY,YAC1B,OAAO,KAAK,QAAQ,EAClB,GACF,CAAC;MAEH,OAAO,KAAK;KACd;IACF,CAAA,CAAC;IACD,IAAI,SAAS;IACb,IAAI,OAAuC,KAAA;IAC3C,QACG,MAAM,QAAQ;KACb,SAAS;KACT,OAAO,IAAI;KACX,MAAM,cAAc,gBAClB,IAAI,MACJ,aAAa,YAAY,MAC3B;KAEA,IAAI,CAAC,YAAY,IAAI;MACnB,SAAS,MACP,gBAAgB,KAAK,YAAY,OAAO,EACtC,KACF,CAAC,CACH;MACA;KACF;KACA,SAAS,KAAK;MACZ,SAAS,IAAI;MACb,QAAQ,YAAY;KACtB,CAAC;KACD,SAAS,SAAS;IACpB,CAAC,CAAC,CACD,OAAO,UAAU;KAChB,SAAS;KACT,SAAS,MAAM,gBAAgB,KAAK,OAAO,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;IAEH,aAAa;KACX,IAAI,CAAC,QACH,GAAG,MAAM;IAEb;GACF,CAAC;EACH;CACF;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HTTPLinkBaseOptions } from "./httpUtils
|
|
1
|
+
import { n as Operation, t as HTTPHeaders, u as TRPCLink } from "./types-CAPs7vhA.mjs";
|
|
2
|
+
import { t as HTTPLinkBaseOptions } from "./httpUtils-C37jRVnj.mjs";
|
|
3
3
|
import { AnyClientTypes, AnyRouter } from "@trpc/server/unstable-core-do-not-import";
|
|
4
|
-
|
|
5
4
|
//#region src/links/httpLink.d.ts
|
|
6
5
|
type HTTPLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TRoot> & {
|
|
7
6
|
/**
|
|
@@ -16,8 +15,6 @@ type HTTPLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TRoot>
|
|
|
16
15
|
* @see https://trpc.io/docs/client/links/httpLink
|
|
17
16
|
*/
|
|
18
17
|
declare function httpLink<TRouter extends AnyRouter = AnyRouter>(opts: HTTPLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
|
|
19
|
-
//# sourceMappingURL=httpLink.d.ts.map
|
|
20
|
-
|
|
21
18
|
//#endregion
|
|
22
|
-
export {
|
|
23
|
-
//# sourceMappingURL=httpLink
|
|
19
|
+
export { httpLink as n, HTTPLinkOptions as t };
|
|
20
|
+
//# sourceMappingURL=httpLink-eSAq8J9S.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpLink-eSAq8J9S.d.mts","names":[],"sources":["../src/links/httpLink.ts"],"mappings":";;;;KA2BY,gBAAgB,cAAc,kBACxC,oBAAoB;;;;;EAKlB,UACI,gBACE;IAAQ,IAAI;QAAgB,cAAc,QAAQ;;;;;iBAwC5C,SAAS,gBAAgB,YAAY,WACnD,MAAM,gBAAgB,wCACrB,SAAS"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { FetchEsque } from "./types
|
|
2
|
-
import { TransformerOptions } from "./unstable-internals
|
|
1
|
+
import { h as FetchEsque } from "./types-CAPs7vhA.mjs";
|
|
2
|
+
import { n as TransformerOptions } from "./unstable-internals-CE8gFBQ9.mjs";
|
|
3
3
|
import { AnyClientTypes, CombinedDataTransformer, Maybe, ProcedureType } from "@trpc/server/unstable-core-do-not-import";
|
|
4
|
-
|
|
5
4
|
//#region src/links/internals/httpUtils.d.ts
|
|
6
|
-
|
|
7
5
|
/**
|
|
8
6
|
* @internal
|
|
9
7
|
*/
|
|
@@ -21,5 +19,5 @@ type HTTPLinkBaseOptions<TRoot extends Pick<AnyClientTypes, 'transformer'>> = {
|
|
|
21
19
|
methodOverride?: 'POST';
|
|
22
20
|
} & TransformerOptions<TRoot>;
|
|
23
21
|
//#endregion
|
|
24
|
-
export { HTTPLinkBaseOptions };
|
|
25
|
-
//# sourceMappingURL=httpUtils
|
|
22
|
+
export { HTTPLinkBaseOptions as t };
|
|
23
|
+
//# sourceMappingURL=httpUtils-C37jRVnj.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpUtils-C37jRVnj.d.mts","names":[],"sources":["../src/links/internals/httpUtils.ts"],"mappings":";;;;;;;KAqBY,oBACV,cAAc,KAAK;EAEnB,cAAc;;;;EAId,QAAQ;;;;;;EAMR;IACE,mBAAmB"}
|
|
@@ -1,18 +1,56 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getTransformer } from "./unstable-internals
|
|
3
|
-
|
|
1
|
+
import { t as _objectSpread2 } from "./objectSpread2-weooBxVk.mjs";
|
|
2
|
+
import { getTransformer } from "./unstable-internals.mjs";
|
|
4
3
|
//#region src/getFetch.ts
|
|
5
4
|
const isFunction = (fn) => typeof fn === "function";
|
|
6
5
|
function getFetch(customFetchImpl) {
|
|
7
6
|
if (customFetchImpl) return customFetchImpl;
|
|
8
|
-
if (typeof window !== "undefined" && isFunction(window.fetch)) return window.fetch;
|
|
7
|
+
if (typeof window !== "undefined" && isFunction(window.fetch)) return window.fetch.bind(window);
|
|
9
8
|
if (typeof globalThis !== "undefined" && isFunction(globalThis.fetch)) return globalThis.fetch;
|
|
10
9
|
throw new Error("No fetch implementation found");
|
|
11
10
|
}
|
|
12
|
-
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/internals/signals.ts
|
|
13
|
+
/**
|
|
14
|
+
* Like `Promise.all()` but for abort signals
|
|
15
|
+
* - When all signals have been aborted, the merged signal will be aborted
|
|
16
|
+
* - If one signal is `null`, no signal will be aborted
|
|
17
|
+
*/
|
|
18
|
+
function allAbortSignals(...signals) {
|
|
19
|
+
const ac = new AbortController();
|
|
20
|
+
const count = signals.length;
|
|
21
|
+
let abortedCount = 0;
|
|
22
|
+
const onAbort = () => {
|
|
23
|
+
if (++abortedCount === count) ac.abort();
|
|
24
|
+
};
|
|
25
|
+
for (const signal of signals) if (signal === null || signal === void 0 ? void 0 : signal.aborted) onAbort();
|
|
26
|
+
else signal === null || signal === void 0 || signal.addEventListener("abort", onAbort, { once: true });
|
|
27
|
+
return ac.signal;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Like `Promise.race` but for abort signals
|
|
31
|
+
*
|
|
32
|
+
* Basically, a ponyfill for
|
|
33
|
+
* [`AbortSignal.any`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static).
|
|
34
|
+
*/
|
|
35
|
+
function raceAbortSignals(...signals) {
|
|
36
|
+
const ac = new AbortController();
|
|
37
|
+
for (const signal of signals) if (signal === null || signal === void 0 ? void 0 : signal.aborted) ac.abort();
|
|
38
|
+
else signal === null || signal === void 0 || signal.addEventListener("abort", () => ac.abort(), { once: true });
|
|
39
|
+
return ac.signal;
|
|
40
|
+
}
|
|
41
|
+
function abortSignalToPromise(signal) {
|
|
42
|
+
return new Promise((_, reject) => {
|
|
43
|
+
if (signal.aborted) {
|
|
44
|
+
reject(signal.reason);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
signal.addEventListener("abort", () => {
|
|
48
|
+
reject(signal.reason);
|
|
49
|
+
}, { once: true });
|
|
50
|
+
});
|
|
51
|
+
}
|
|
13
52
|
//#endregion
|
|
14
53
|
//#region src/links/internals/httpUtils.ts
|
|
15
|
-
var import_objectSpread2 = __toESM(require_objectSpread2(), 1);
|
|
16
54
|
function resolveHTTPLinkOptions(opts) {
|
|
17
55
|
return {
|
|
18
56
|
url: opts.url.toString(),
|
|
@@ -39,8 +77,7 @@ function getInput(opts) {
|
|
|
39
77
|
}
|
|
40
78
|
const getUrl = (opts) => {
|
|
41
79
|
const parts = opts.url.split("?");
|
|
42
|
-
|
|
43
|
-
let url = base + "/" + opts.path;
|
|
80
|
+
let url = parts[0].replace(/\/$/, "") + "/" + opts.path;
|
|
44
81
|
const queryParts = [];
|
|
45
82
|
if (parts[1]) queryParts.push(parts[1]);
|
|
46
83
|
if ("inputs" in opts) queryParts.push("batch=1");
|
|
@@ -52,12 +89,12 @@ const getUrl = (opts) => {
|
|
|
52
89
|
return url;
|
|
53
90
|
};
|
|
54
91
|
const getBody = (opts) => {
|
|
55
|
-
if (opts.type === "query" && opts.methodOverride !== "POST") return
|
|
92
|
+
if (opts.type === "query" && opts.methodOverride !== "POST") return;
|
|
56
93
|
const input = getInput(opts);
|
|
57
94
|
return input !== void 0 ? JSON.stringify(input) : void 0;
|
|
58
95
|
};
|
|
59
96
|
const jsonHttpRequester = (opts) => {
|
|
60
|
-
return httpRequest((
|
|
97
|
+
return httpRequest(_objectSpread2(_objectSpread2({}, opts), {}, {
|
|
61
98
|
contentTypeHeader: "application/json",
|
|
62
99
|
getUrl,
|
|
63
100
|
getBody
|
|
@@ -97,7 +134,7 @@ async function fetchHTTPResponse(opts) {
|
|
|
97
134
|
if (Symbol.iterator in heads) return Object.fromEntries(heads);
|
|
98
135
|
return heads;
|
|
99
136
|
})();
|
|
100
|
-
const headers = (
|
|
137
|
+
const headers = _objectSpread2(_objectSpread2(_objectSpread2({}, opts.contentTypeHeader && method !== "GET" ? { "content-type": opts.contentTypeHeader } : {}), opts.trpcAcceptHeader ? { [(_opts$trpcAcceptHeade = opts.trpcAcceptHeaderKey) !== null && _opts$trpcAcceptHeade !== void 0 ? _opts$trpcAcceptHeade : "trpc-accept"]: opts.trpcAcceptHeader } : void 0), resolvedHeaders);
|
|
101
138
|
return getFetch(opts.fetch)(url, {
|
|
102
139
|
method,
|
|
103
140
|
signal: opts.signal,
|
|
@@ -116,7 +153,7 @@ async function httpRequest(opts) {
|
|
|
116
153
|
meta
|
|
117
154
|
};
|
|
118
155
|
}
|
|
119
|
-
|
|
120
156
|
//#endregion
|
|
121
|
-
export {
|
|
122
|
-
|
|
157
|
+
export { jsonHttpRequester as a, allAbortSignals as c, httpRequest as i, raceAbortSignals as l, getBody as n, resolveHTTPLinkOptions as o, getUrl as r, abortSignalToPromise as s, fetchHTTPResponse as t, getFetch as u };
|
|
158
|
+
|
|
159
|
+
//# sourceMappingURL=httpUtils-CB_100ND.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpUtils-CB_100ND.mjs","names":[],"sources":["../src/getFetch.ts","../src/internals/signals.ts","../src/links/internals/httpUtils.ts"],"sourcesContent":["import type { FetchEsque, NativeFetchEsque } from './internals/types';\n\ntype AnyFn = (...args: any[]) => unknown;\n\nconst isFunction = (fn: unknown): fn is AnyFn => typeof fn === 'function';\n\nexport function getFetch(\n customFetchImpl?: FetchEsque | NativeFetchEsque,\n): FetchEsque {\n if (customFetchImpl) {\n return customFetchImpl as FetchEsque;\n }\n\n // eslint-disable-next-line @typescript-eslint/unbound-method\n if (typeof window !== 'undefined' && isFunction(window.fetch)) {\n return window.fetch.bind(window);\n }\n\n if (typeof globalThis !== 'undefined' && isFunction(globalThis.fetch)) {\n return globalThis.fetch;\n }\n\n throw new Error('No fetch implementation found');\n}\n","import type { Maybe } from '@trpc/server/unstable-core-do-not-import';\n\n/**\n * Like `Promise.all()` but for abort signals\n * - When all signals have been aborted, the merged signal will be aborted\n * - If one signal is `null`, no signal will be aborted\n */\nexport function allAbortSignals(...signals: Maybe<AbortSignal>[]): AbortSignal {\n const ac = new AbortController();\n\n const count = signals.length;\n\n let abortedCount = 0;\n\n const onAbort = () => {\n if (++abortedCount === count) {\n ac.abort();\n }\n };\n\n for (const signal of signals) {\n if (signal?.aborted) {\n onAbort();\n } else {\n signal?.addEventListener('abort', onAbort, {\n once: true,\n });\n }\n }\n\n return ac.signal;\n}\n\n/**\n * Like `Promise.race` but for abort signals\n *\n * Basically, a ponyfill for\n * [`AbortSignal.any`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static).\n */\nexport function raceAbortSignals(\n ...signals: Maybe<AbortSignal>[]\n): AbortSignal {\n const ac = new AbortController();\n\n for (const signal of signals) {\n if (signal?.aborted) {\n ac.abort();\n } else {\n signal?.addEventListener('abort', () => ac.abort(), { once: true });\n }\n }\n\n return ac.signal;\n}\n\nexport function abortSignalToPromise(signal: AbortSignal): Promise<never> {\n return new Promise((_, reject) => {\n if (signal.aborted) {\n reject(signal.reason);\n return;\n }\n signal.addEventListener(\n 'abort',\n () => {\n reject(signal.reason);\n },\n { once: true },\n );\n });\n}\n","import type {\n AnyClientTypes,\n CombinedDataTransformer,\n Maybe,\n ProcedureType,\n TRPCAcceptHeader,\n TRPCResponse,\n} from '@trpc/server/unstable-core-do-not-import';\nimport { getFetch } from '../../getFetch';\nimport type {\n FetchEsque,\n RequestInitEsque,\n ResponseEsque,\n} from '../../internals/types';\nimport type { TransformerOptions } from '../../unstable-internals';\nimport { getTransformer } from '../../unstable-internals';\nimport type { HTTPHeaders } from '../types';\n\n/**\n * @internal\n */\nexport type HTTPLinkBaseOptions<\n TRoot extends Pick<AnyClientTypes, 'transformer'>,\n> = {\n url: string | URL;\n /**\n * Add ponyfill for fetch\n */\n fetch?: FetchEsque;\n /**\n * Send all requests `as POST`s requests regardless of the procedure type\n * The HTTP handler must separately allow overriding the method. See:\n * @see https://trpc.io/docs/rpc\n */\n methodOverride?: 'POST';\n} & TransformerOptions<TRoot>;\n\nexport interface ResolvedHTTPLinkOptions {\n url: string;\n fetch?: FetchEsque;\n transformer: CombinedDataTransformer;\n methodOverride?: 'POST';\n}\n\nexport function resolveHTTPLinkOptions(\n opts: HTTPLinkBaseOptions<AnyClientTypes>,\n): ResolvedHTTPLinkOptions {\n return {\n url: opts.url.toString(),\n fetch: opts.fetch,\n transformer: getTransformer(opts.transformer),\n methodOverride: opts.methodOverride,\n };\n}\n\n// https://github.com/trpc/trpc/pull/669\nfunction arrayToDict(array: unknown[]) {\n const dict: Record<number, unknown> = {};\n for (let index = 0; index < array.length; index++) {\n const element = array[index];\n dict[index] = element;\n }\n return dict;\n}\n\nconst METHOD = {\n query: 'GET',\n mutation: 'POST',\n subscription: 'PATCH',\n} as const;\n\nexport interface HTTPResult {\n json: TRPCResponse;\n meta: {\n response: ResponseEsque;\n responseJSON?: unknown;\n };\n}\n\ntype GetInputOptions = {\n transformer: CombinedDataTransformer;\n} & ({ input: unknown } | { inputs: unknown[] });\n\nexport function getInput(opts: GetInputOptions) {\n return 'input' in opts\n ? opts.transformer.input.serialize(opts.input)\n : arrayToDict(\n opts.inputs.map((_input) => opts.transformer.input.serialize(_input)),\n );\n}\n\nexport type HTTPBaseRequestOptions = GetInputOptions &\n ResolvedHTTPLinkOptions & {\n type: ProcedureType;\n path: string;\n signal: Maybe<AbortSignal>;\n };\n\ntype GetUrl = (opts: HTTPBaseRequestOptions) => string;\ntype GetBody = (opts: HTTPBaseRequestOptions) => RequestInitEsque['body'];\n\nexport type ContentOptions = {\n trpcAcceptHeader?: TRPCAcceptHeader;\n trpcAcceptHeaderKey?: 'trpc-accept' | 'accept';\n contentTypeHeader?: string;\n getUrl: GetUrl;\n getBody: GetBody;\n};\n\nexport const getUrl: GetUrl = (opts) => {\n const parts = opts.url.split('?') as [string, string?];\n const base = parts[0].replace(/\\/$/, ''); // Remove any trailing slashes\n\n let url = base + '/' + opts.path;\n const queryParts: string[] = [];\n\n if (parts[1]) {\n queryParts.push(parts[1]);\n }\n if ('inputs' in opts) {\n queryParts.push('batch=1');\n }\n if (opts.type === 'query' || opts.type === 'subscription') {\n const input = getInput(opts);\n if (input !== undefined && opts.methodOverride !== 'POST') {\n queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`);\n }\n }\n if (queryParts.length) {\n url += '?' + queryParts.join('&');\n }\n return url;\n};\n\nexport const getBody: GetBody = (opts) => {\n if (opts.type === 'query' && opts.methodOverride !== 'POST') {\n return undefined;\n }\n const input = getInput(opts);\n return input !== undefined ? JSON.stringify(input) : undefined;\n};\n\nexport type Requester = (\n opts: HTTPBaseRequestOptions & {\n headers: () => HTTPHeaders | Promise<HTTPHeaders>;\n },\n) => Promise<HTTPResult>;\n\nexport const jsonHttpRequester: Requester = (opts) => {\n return httpRequest({\n ...opts,\n contentTypeHeader: 'application/json',\n getUrl,\n getBody,\n });\n};\n\n/**\n * Polyfill for DOMException with AbortError name\n */\nclass AbortError extends Error {\n constructor() {\n const name = 'AbortError';\n super(name);\n this.name = name;\n this.message = name;\n }\n}\n\nexport type HTTPRequestOptions = ContentOptions &\n HTTPBaseRequestOptions & {\n headers: () => HTTPHeaders | Promise<HTTPHeaders>;\n };\n\n/**\n * Polyfill for `signal.throwIfAborted()`\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/throwIfAborted\n */\nconst throwIfAborted = (signal: Maybe<AbortSignal>) => {\n if (!signal?.aborted) {\n return;\n }\n // If available, use the native implementation\n signal.throwIfAborted?.();\n\n // If we have `DOMException`, use it\n if (typeof DOMException !== 'undefined') {\n throw new DOMException('AbortError', 'AbortError');\n }\n\n // Otherwise, use our own implementation\n throw new AbortError();\n};\n\nexport async function fetchHTTPResponse(opts: HTTPRequestOptions) {\n throwIfAborted(opts.signal);\n\n const url = opts.getUrl(opts);\n const body = opts.getBody(opts);\n const method = opts.methodOverride ?? METHOD[opts.type];\n const resolvedHeaders = await (async () => {\n const heads = await opts.headers();\n if (Symbol.iterator in heads) {\n return Object.fromEntries(heads);\n }\n return heads;\n })();\n const headers = {\n ...(opts.contentTypeHeader && method !== 'GET'\n ? { 'content-type': opts.contentTypeHeader }\n : {}),\n ...(opts.trpcAcceptHeader\n ? { [opts.trpcAcceptHeaderKey ?? 'trpc-accept']: opts.trpcAcceptHeader }\n : undefined),\n ...resolvedHeaders,\n };\n\n return getFetch(opts.fetch)(url, {\n method,\n signal: opts.signal,\n body,\n headers,\n });\n}\n\nexport async function httpRequest(\n opts: HTTPRequestOptions,\n): Promise<HTTPResult> {\n const meta = {} as HTTPResult['meta'];\n\n const res = await fetchHTTPResponse(opts);\n meta.response = res;\n\n const json = await res.json();\n\n meta.responseJSON = json;\n\n return {\n json: json as TRPCResponse,\n meta,\n };\n}\n"],"mappings":"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"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { FetchEsque } from "./types
|
|
2
|
-
import { TransformerOptions } from "./unstable-internals
|
|
1
|
+
import { h as FetchEsque } from "./types-BxbMkv6C.cjs";
|
|
2
|
+
import { n as TransformerOptions } from "./unstable-internals-CE8gFBQ9.cjs";
|
|
3
3
|
import { AnyClientTypes, CombinedDataTransformer, Maybe, ProcedureType } from "@trpc/server/unstable-core-do-not-import";
|
|
4
|
-
|
|
5
4
|
//#region src/links/internals/httpUtils.d.ts
|
|
6
|
-
|
|
7
5
|
/**
|
|
8
6
|
* @internal
|
|
9
7
|
*/
|
|
@@ -21,5 +19,5 @@ type HTTPLinkBaseOptions<TRoot extends Pick<AnyClientTypes, 'transformer'>> = {
|
|
|
21
19
|
methodOverride?: 'POST';
|
|
22
20
|
} & TransformerOptions<TRoot>;
|
|
23
21
|
//#endregion
|
|
24
|
-
export { HTTPLinkBaseOptions };
|
|
25
|
-
//# sourceMappingURL=httpUtils
|
|
22
|
+
export { HTTPLinkBaseOptions as t };
|
|
23
|
+
//# sourceMappingURL=httpUtils-CUqAubVD.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpUtils-CUqAubVD.d.cts","names":[],"sources":["../src/links/internals/httpUtils.ts"],"mappings":";;;;;;;KAqBY,oBACV,cAAc,KAAK;EAEnB,cAAc;;;;EAId,QAAQ;;;;;;EAMR;IACE,mBAAmB"}
|