@trpc/client 11.18.1-canary.6 → 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
package/bin/intent.js
CHANGED
|
File without changes
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
const require_objectSpread2 = require("./objectSpread2-D-dJi1gK.cjs");
|
|
2
|
+
let _trpc_server_unstable_core_do_not_import = require("@trpc/server/unstable-core-do-not-import");
|
|
3
|
+
//#region src/TRPCClientError.ts
|
|
4
|
+
function isTRPCClientError(cause) {
|
|
5
|
+
return cause instanceof TRPCClientError;
|
|
6
|
+
}
|
|
7
|
+
function isTRPCErrorResponse(obj) {
|
|
8
|
+
return (0, _trpc_server_unstable_core_do_not_import.isObject)(obj) && (0, _trpc_server_unstable_core_do_not_import.isObject)(obj["error"]) && typeof obj["error"]["code"] === "number" && typeof obj["error"]["message"] === "string";
|
|
9
|
+
}
|
|
10
|
+
function getMessageFromUnknownError(err, fallback) {
|
|
11
|
+
if (typeof err === "string") return err;
|
|
12
|
+
if ((0, _trpc_server_unstable_core_do_not_import.isObject)(err) && typeof err["message"] === "string") return err["message"];
|
|
13
|
+
return fallback;
|
|
14
|
+
}
|
|
15
|
+
var TRPCClientError = class TRPCClientError extends Error {
|
|
16
|
+
constructor(message, opts) {
|
|
17
|
+
var _opts$result, _opts$result2;
|
|
18
|
+
const cause = opts === null || opts === void 0 ? void 0 : opts.cause;
|
|
19
|
+
super(message, { cause });
|
|
20
|
+
require_objectSpread2._defineProperty(this, "cause", void 0);
|
|
21
|
+
require_objectSpread2._defineProperty(this, "shape", void 0);
|
|
22
|
+
require_objectSpread2._defineProperty(this, "data", void 0);
|
|
23
|
+
require_objectSpread2._defineProperty(this, "meta", void 0);
|
|
24
|
+
this.meta = opts === null || opts === void 0 ? void 0 : opts.meta;
|
|
25
|
+
this.cause = cause;
|
|
26
|
+
this.shape = opts === null || opts === void 0 || (_opts$result = opts.result) === null || _opts$result === void 0 ? void 0 : _opts$result.error;
|
|
27
|
+
this.data = opts === null || opts === void 0 || (_opts$result2 = opts.result) === null || _opts$result2 === void 0 ? void 0 : _opts$result2.error.data;
|
|
28
|
+
this.name = "TRPCClientError";
|
|
29
|
+
Object.setPrototypeOf(this, TRPCClientError.prototype);
|
|
30
|
+
}
|
|
31
|
+
static from(_cause, opts = {}) {
|
|
32
|
+
const cause = _cause;
|
|
33
|
+
if (isTRPCClientError(cause)) {
|
|
34
|
+
if (opts.meta) cause.meta = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, cause.meta), opts.meta);
|
|
35
|
+
return cause;
|
|
36
|
+
}
|
|
37
|
+
if (isTRPCErrorResponse(cause)) return new TRPCClientError(cause.error.message, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, opts), {}, {
|
|
38
|
+
result: cause,
|
|
39
|
+
cause: opts.cause
|
|
40
|
+
}));
|
|
41
|
+
return new TRPCClientError(getMessageFromUnknownError(cause, "Unknown error"), require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, opts), {}, { cause }));
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
//#endregion
|
|
45
|
+
Object.defineProperty(exports, "TRPCClientError", {
|
|
46
|
+
enumerable: true,
|
|
47
|
+
get: function() {
|
|
48
|
+
return TRPCClientError;
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
Object.defineProperty(exports, "isTRPCClientError", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
get: function() {
|
|
54
|
+
return isTRPCClientError;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { n as _defineProperty, t as _objectSpread2 } from "./objectSpread2-weooBxVk.mjs";
|
|
2
2
|
import { isObject } from "@trpc/server/unstable-core-do-not-import";
|
|
3
|
-
|
|
4
3
|
//#region src/TRPCClientError.ts
|
|
5
|
-
var import_defineProperty = __toESM(require_defineProperty(), 1);
|
|
6
|
-
var import_objectSpread2 = __toESM(require_objectSpread2(), 1);
|
|
7
4
|
function isTRPCClientError(cause) {
|
|
8
5
|
return cause instanceof TRPCClientError;
|
|
9
6
|
}
|
|
@@ -20,10 +17,10 @@ var TRPCClientError = class TRPCClientError extends Error {
|
|
|
20
17
|
var _opts$result, _opts$result2;
|
|
21
18
|
const cause = opts === null || opts === void 0 ? void 0 : opts.cause;
|
|
22
19
|
super(message, { cause });
|
|
23
|
-
(
|
|
24
|
-
(
|
|
25
|
-
(
|
|
26
|
-
(
|
|
20
|
+
_defineProperty(this, "cause", void 0);
|
|
21
|
+
_defineProperty(this, "shape", void 0);
|
|
22
|
+
_defineProperty(this, "data", void 0);
|
|
23
|
+
_defineProperty(this, "meta", void 0);
|
|
27
24
|
this.meta = opts === null || opts === void 0 ? void 0 : opts.meta;
|
|
28
25
|
this.cause = cause;
|
|
29
26
|
this.shape = opts === null || opts === void 0 || (_opts$result = opts.result) === null || _opts$result === void 0 ? void 0 : _opts$result.error;
|
|
@@ -34,17 +31,17 @@ var TRPCClientError = class TRPCClientError extends Error {
|
|
|
34
31
|
static from(_cause, opts = {}) {
|
|
35
32
|
const cause = _cause;
|
|
36
33
|
if (isTRPCClientError(cause)) {
|
|
37
|
-
if (opts.meta) cause.meta = (
|
|
34
|
+
if (opts.meta) cause.meta = _objectSpread2(_objectSpread2({}, cause.meta), opts.meta);
|
|
38
35
|
return cause;
|
|
39
36
|
}
|
|
40
|
-
if (isTRPCErrorResponse(cause)) return new TRPCClientError(cause.error.message, (
|
|
37
|
+
if (isTRPCErrorResponse(cause)) return new TRPCClientError(cause.error.message, _objectSpread2(_objectSpread2({}, opts), {}, {
|
|
41
38
|
result: cause,
|
|
42
39
|
cause: opts.cause
|
|
43
40
|
}));
|
|
44
|
-
return new TRPCClientError(getMessageFromUnknownError(cause, "Unknown error"), (
|
|
41
|
+
return new TRPCClientError(getMessageFromUnknownError(cause, "Unknown error"), _objectSpread2(_objectSpread2({}, opts), {}, { cause }));
|
|
45
42
|
}
|
|
46
43
|
};
|
|
47
|
-
|
|
48
44
|
//#endregion
|
|
49
|
-
export {
|
|
50
|
-
|
|
45
|
+
export { isTRPCClientError as n, TRPCClientError as t };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=TRPCClientError-CxFRO7Js.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TRPCClientError-CxFRO7Js.mjs","names":[],"sources":["../src/TRPCClientError.ts"],"sourcesContent":["import type {\n inferClientTypes,\n InferrableClientTypes,\n Maybe,\n TRPCErrorResponse,\n} from '@trpc/server/unstable-core-do-not-import';\nimport {\n isObject,\n type DefaultErrorShape,\n} from '@trpc/server/unstable-core-do-not-import';\n\ntype inferErrorShape<TInferrable extends InferrableClientTypes> =\n inferClientTypes<TInferrable>['errorShape'];\nexport interface TRPCClientErrorBase<TShape extends DefaultErrorShape> {\n readonly message: string;\n readonly shape: Maybe<TShape>;\n readonly data: Maybe<TShape['data']>;\n}\nexport type TRPCClientErrorLike<TInferrable extends InferrableClientTypes> =\n TRPCClientErrorBase<inferErrorShape<TInferrable>>;\n\nexport function isTRPCClientError<TInferrable extends InferrableClientTypes>(\n cause: unknown,\n): cause is TRPCClientError<TInferrable> {\n return cause instanceof TRPCClientError;\n}\n\nfunction isTRPCErrorResponse(obj: unknown): obj is TRPCErrorResponse<any> {\n return (\n isObject(obj) &&\n isObject(obj['error']) &&\n typeof obj['error']['code'] === 'number' &&\n typeof obj['error']['message'] === 'string'\n );\n}\n\nfunction getMessageFromUnknownError(err: unknown, fallback: string): string {\n if (typeof err === 'string') {\n return err;\n }\n if (isObject(err) && typeof err['message'] === 'string') {\n return err['message'];\n }\n return fallback;\n}\n\nexport class TRPCClientError<TRouterOrProcedure extends InferrableClientTypes>\n extends Error\n implements TRPCClientErrorBase<inferErrorShape<TRouterOrProcedure>>\n{\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore override doesn't work in all environments due to \"This member cannot have an 'override' modifier because it is not declared in the base class 'Error'\"\n public override readonly cause;\n public readonly shape: Maybe<inferErrorShape<TRouterOrProcedure>>;\n public readonly data: Maybe<inferErrorShape<TRouterOrProcedure>['data']>;\n\n /**\n * Additional meta data about the error\n * In the case of HTTP-errors, we'll have `response` and potentially `responseJSON` here\n */\n public meta;\n\n constructor(\n message: string,\n opts?: {\n result?: Maybe<TRPCErrorResponse<inferErrorShape<TRouterOrProcedure>>>;\n cause?: Error;\n meta?: Record<string, unknown>;\n },\n ) {\n const cause = opts?.cause;\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore https://github.com/tc39/proposal-error-cause\n super(message, { cause });\n\n this.meta = opts?.meta;\n\n this.cause = cause;\n this.shape = opts?.result?.error;\n this.data = opts?.result?.error.data;\n this.name = 'TRPCClientError';\n\n Object.setPrototypeOf(this, TRPCClientError.prototype);\n }\n\n public static from<TRouterOrProcedure extends InferrableClientTypes>(\n _cause: Error | TRPCErrorResponse<any> | object,\n opts: { meta?: Record<string, unknown>; cause?: Error } = {},\n ): TRPCClientError<TRouterOrProcedure> {\n const cause = _cause as unknown;\n\n if (isTRPCClientError(cause)) {\n if (opts.meta) {\n // Decorate with meta error data\n cause.meta = {\n ...cause.meta,\n ...opts.meta,\n };\n }\n return cause;\n }\n if (isTRPCErrorResponse(cause)) {\n return new TRPCClientError(cause.error.message, {\n ...opts,\n result: cause,\n cause: opts.cause,\n });\n }\n return new TRPCClientError(\n getMessageFromUnknownError(cause, 'Unknown error'),\n {\n ...opts,\n cause: cause as any,\n },\n );\n }\n}\n"],"mappings":";;;AAqBA,SAAgB,kBACd,OACuC;CACvC,OAAO,iBAAiB;AAC1B;AAEA,SAAS,oBAAoB,KAA6C;CACxE,OACE,SAAS,GAAG,KACZ,SAAS,IAAI,QAAQ,KACrB,OAAO,IAAI,QAAQ,CAAC,YAAY,YAChC,OAAO,IAAI,QAAQ,CAAC,eAAe;AAEvC;AAEA,SAAS,2BAA2B,KAAc,UAA0B;CAC1E,IAAI,OAAO,QAAQ,UACjB,OAAO;CAET,IAAI,SAAS,GAAG,KAAK,OAAO,IAAI,eAAe,UAC7C,OAAO,IAAI;CAEb,OAAO;AACT;AAEA,IAAa,kBAAb,MAAa,wBACH,MAEV;CAaE,YACE,SACA,MAKA;;EACA,MAAM,QAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAAQ,KAAM;EAIpB,MAAM,SAAS,EAAE,MAAM,CAAC;EAtBD,gBAAA,MAAA,SAAA,KAAA,CAAA;EACT,gBAAA,MAAA,SAAA,KAAA,CAAA;EACA,gBAAA,MAAA,QAAA,KAAA,CAAA;EAMT,gBAAA,MAAA,QAAA,KAAA,CAAA;EAgBL,KAAK,OAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAAO,KAAM;EAElB,KAAK,QAAQ;EACb,KAAK,QAAA,SAAA,QAAA,SAAA,KAAA,MAAA,eAAQ,KAAM,YAAA,QAAA,iBAAA,KAAA,IAAA,KAAA,IAAA,aAAQ;EAC3B,KAAK,OAAA,SAAA,QAAA,SAAA,KAAA,MAAA,gBAAO,KAAM,YAAA,QAAA,kBAAA,KAAA,IAAA,KAAA,IAAA,cAAQ,MAAM;EAChC,KAAK,OAAO;EAEZ,OAAO,eAAe,MAAM,gBAAgB,SAAS;CACvD;CAEA,OAAc,KACZ,QACA,OAA0D,CAAC,GACtB;EACrC,MAAM,QAAQ;EAEd,IAAI,kBAAkB,KAAK,GAAG;GAC5B,IAAI,KAAK,MAEP,MAAM,OAAA,eAAA,eAAA,CAAA,GACD,MAAM,IAAA,GACN,KAAK,IACV;GAEF,OAAO;EACT;EACA,IAAI,oBAAoB,KAAK,GAC3B,OAAO,IAAI,gBAAgB,MAAM,MAAM,SAAA,eAAA,eAAA,CAAA,GAClC,IAAA,GAAA,CAAA,GAAA;GACH,QAAQ;GACR,OAAO,KAAK;EACd,CAAA,CAAC;EAEH,OAAO,IAAI,gBACT,2BAA2B,OAAO,eAAe,GAAA,eAAA,eAAA,CAAA,GAE5C,IAAA,GAAA,CAAA,GAAA,EACI,MAAA,CACT,CACF;CACF;AACF"}
|
|
@@ -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, c as allAbortSignals, 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/internals/dataLoader.ts
|
|
8
7
|
/**
|
|
9
8
|
* A function that should never be called unless we messed something up.
|
|
@@ -36,19 +35,18 @@ function dataLoader(batchLoader) {
|
|
|
36
35
|
const lastGroup = groupedItems[groupedItems.length - 1];
|
|
37
36
|
if (item.aborted) {
|
|
38
37
|
var _item$reject;
|
|
39
|
-
(_item$reject = item.reject) === null || _item$reject === void 0 || _item$reject.call(item, new Error("Aborted"));
|
|
38
|
+
(_item$reject = item.reject) === null || _item$reject === void 0 || _item$reject.call(item, /* @__PURE__ */ new Error("Aborted"));
|
|
40
39
|
index++;
|
|
41
40
|
continue;
|
|
42
41
|
}
|
|
43
|
-
|
|
44
|
-
if (isValid) {
|
|
42
|
+
if (batchLoader.validate(lastGroup.concat(item).map((it) => it.key))) {
|
|
45
43
|
lastGroup.push(item);
|
|
46
44
|
index++;
|
|
47
45
|
continue;
|
|
48
46
|
}
|
|
49
47
|
if (lastGroup.length === 0) {
|
|
50
48
|
var _item$reject2;
|
|
51
|
-
(_item$reject2 = item.reject) === null || _item$reject2 === void 0 || _item$reject2.call(item, new Error("Input is too big for a single dispatch"));
|
|
49
|
+
(_item$reject2 = item.reject) === null || _item$reject2 === void 0 || _item$reject2.call(item, /* @__PURE__ */ new Error("Input is too big for a single dispatch"));
|
|
52
50
|
index++;
|
|
53
51
|
continue;
|
|
54
52
|
}
|
|
@@ -63,8 +61,7 @@ function dataLoader(batchLoader) {
|
|
|
63
61
|
if (!items.length) continue;
|
|
64
62
|
const batch = { items };
|
|
65
63
|
for (const item of items) item.batch = batch;
|
|
66
|
-
|
|
67
|
-
promise.then(async (result) => {
|
|
64
|
+
batchLoader.fetch(batch.items.map((_item) => _item.key)).then(async (result) => {
|
|
68
65
|
await Promise.all(result.map(async (valueOrPromise, index) => {
|
|
69
66
|
const item = batch.items[index];
|
|
70
67
|
try {
|
|
@@ -81,7 +78,7 @@ function dataLoader(batchLoader) {
|
|
|
81
78
|
}));
|
|
82
79
|
for (const item of batch.items) {
|
|
83
80
|
var _item$reject4;
|
|
84
|
-
(_item$reject4 = item.reject) === null || _item$reject4 === void 0 || _item$reject4.call(item, new Error("Missing result"));
|
|
81
|
+
(_item$reject4 = item.reject) === null || _item$reject4 === void 0 || _item$reject4.call(item, /* @__PURE__ */ new Error("Missing result"));
|
|
85
82
|
item.batch = null;
|
|
86
83
|
}
|
|
87
84
|
}).catch((cause) => {
|
|
@@ -114,52 +111,8 @@ function dataLoader(batchLoader) {
|
|
|
114
111
|
}
|
|
115
112
|
return { load };
|
|
116
113
|
}
|
|
117
|
-
|
|
118
|
-
//#endregion
|
|
119
|
-
//#region src/internals/signals.ts
|
|
120
|
-
/**
|
|
121
|
-
* Like `Promise.all()` but for abort signals
|
|
122
|
-
* - When all signals have been aborted, the merged signal will be aborted
|
|
123
|
-
* - If one signal is `null`, no signal will be aborted
|
|
124
|
-
*/
|
|
125
|
-
function allAbortSignals(...signals) {
|
|
126
|
-
const ac = new AbortController();
|
|
127
|
-
const count = signals.length;
|
|
128
|
-
let abortedCount = 0;
|
|
129
|
-
const onAbort = () => {
|
|
130
|
-
if (++abortedCount === count) ac.abort();
|
|
131
|
-
};
|
|
132
|
-
for (const signal of signals) if (signal === null || signal === void 0 ? void 0 : signal.aborted) onAbort();
|
|
133
|
-
else signal === null || signal === void 0 || signal.addEventListener("abort", onAbort, { once: true });
|
|
134
|
-
return ac.signal;
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Like `Promise.race` but for abort signals
|
|
138
|
-
*
|
|
139
|
-
* Basically, a ponyfill for
|
|
140
|
-
* [`AbortSignal.any`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static).
|
|
141
|
-
*/
|
|
142
|
-
function raceAbortSignals(...signals) {
|
|
143
|
-
const ac = new AbortController();
|
|
144
|
-
for (const signal of signals) if (signal === null || signal === void 0 ? void 0 : signal.aborted) ac.abort();
|
|
145
|
-
else signal === null || signal === void 0 || signal.addEventListener("abort", () => ac.abort(), { once: true });
|
|
146
|
-
return ac.signal;
|
|
147
|
-
}
|
|
148
|
-
function abortSignalToPromise(signal) {
|
|
149
|
-
return new Promise((_, reject) => {
|
|
150
|
-
if (signal.aborted) {
|
|
151
|
-
reject(signal.reason);
|
|
152
|
-
return;
|
|
153
|
-
}
|
|
154
|
-
signal.addEventListener("abort", () => {
|
|
155
|
-
reject(signal.reason);
|
|
156
|
-
}, { once: true });
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
|
|
160
114
|
//#endregion
|
|
161
115
|
//#region src/links/httpBatchLink.ts
|
|
162
|
-
var import_objectSpread2 = __toESM(require_objectSpread2(), 1);
|
|
163
116
|
/**
|
|
164
117
|
* @see https://trpc.io/docs/client/links/httpBatchLink
|
|
165
118
|
*/
|
|
@@ -176,19 +129,18 @@ function httpBatchLink(opts) {
|
|
|
176
129
|
if (batchOps.length > maxItems) return false;
|
|
177
130
|
const path = batchOps.map((op) => op.path).join(",");
|
|
178
131
|
const inputs = batchOps.map((op) => op.input);
|
|
179
|
-
|
|
132
|
+
return getUrl(_objectSpread2(_objectSpread2({}, resolvedOpts), {}, {
|
|
180
133
|
type,
|
|
181
134
|
path,
|
|
182
135
|
inputs,
|
|
183
136
|
signal: null
|
|
184
|
-
}));
|
|
185
|
-
return url.length <= maxURLLength;
|
|
137
|
+
})).length <= maxURLLength;
|
|
186
138
|
},
|
|
187
139
|
async fetch(batchOps) {
|
|
188
140
|
const path = batchOps.map((op) => op.path).join(",");
|
|
189
141
|
const inputs = batchOps.map((op) => op.input);
|
|
190
142
|
const signal = allAbortSignals(...batchOps.map((op) => op.signal));
|
|
191
|
-
const res = await jsonHttpRequester((
|
|
143
|
+
const res = await jsonHttpRequester(_objectSpread2(_objectSpread2({}, resolvedOpts), {}, {
|
|
192
144
|
path,
|
|
193
145
|
inputs,
|
|
194
146
|
type,
|
|
@@ -199,29 +151,27 @@ function httpBatchLink(opts) {
|
|
|
199
151
|
},
|
|
200
152
|
signal
|
|
201
153
|
}));
|
|
202
|
-
|
|
203
|
-
const result = resJSON.map((item) => ({
|
|
154
|
+
return (Array.isArray(res.json) ? res.json : batchOps.map(() => res.json)).map((item) => ({
|
|
204
155
|
meta: res.meta,
|
|
205
156
|
json: item
|
|
206
157
|
}));
|
|
207
|
-
return result;
|
|
208
158
|
}
|
|
209
159
|
};
|
|
210
160
|
};
|
|
211
|
-
const query = dataLoader(batchLoader("query"));
|
|
212
|
-
const mutation = dataLoader(batchLoader("mutation"));
|
|
213
161
|
const loaders = {
|
|
214
|
-
query,
|
|
215
|
-
mutation
|
|
162
|
+
query: dataLoader(batchLoader("query")),
|
|
163
|
+
mutation: dataLoader(batchLoader("mutation"))
|
|
216
164
|
};
|
|
217
165
|
return ({ op }) => {
|
|
218
166
|
return observable((observer) => {
|
|
219
167
|
/* istanbul ignore if -- @preserve */
|
|
220
168
|
if (op.type === "subscription") throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`");
|
|
221
|
-
const
|
|
222
|
-
const promise =
|
|
169
|
+
const ac = new AbortController();
|
|
170
|
+
const promise = loaders[op.type].load(_objectSpread2(_objectSpread2({}, op), {}, { signal: raceAbortSignals(op.signal, ac.signal) }));
|
|
171
|
+
let isDone = false;
|
|
223
172
|
let _res = void 0;
|
|
224
173
|
promise.then((res) => {
|
|
174
|
+
isDone = true;
|
|
225
175
|
_res = res;
|
|
226
176
|
const transformed = transformResult(res.json, resolvedOpts.transformer.output);
|
|
227
177
|
if (!transformed.ok) {
|
|
@@ -234,14 +184,17 @@ function httpBatchLink(opts) {
|
|
|
234
184
|
});
|
|
235
185
|
observer.complete();
|
|
236
186
|
}).catch((err) => {
|
|
187
|
+
isDone = true;
|
|
237
188
|
observer.error(TRPCClientError.from(err, { meta: _res === null || _res === void 0 ? void 0 : _res.meta }));
|
|
238
189
|
});
|
|
239
|
-
return () => {
|
|
190
|
+
return () => {
|
|
191
|
+
if (!isDone) ac.abort();
|
|
192
|
+
};
|
|
240
193
|
});
|
|
241
194
|
};
|
|
242
195
|
};
|
|
243
196
|
}
|
|
244
|
-
|
|
245
197
|
//#endregion
|
|
246
|
-
export {
|
|
247
|
-
|
|
198
|
+
export { dataLoader as n, httpBatchLink as t };
|
|
199
|
+
|
|
200
|
+
//# sourceMappingURL=httpBatchLink-BMtWxLJV.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpBatchLink-BMtWxLJV.mjs","names":[],"sources":["../src/internals/dataLoader.ts","../src/links/httpBatchLink.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\ntype BatchItem<TKey, TValue> = {\n aborted: boolean;\n key: TKey;\n resolve: ((value: TValue) => void) | null;\n reject: ((error: Error) => void) | null;\n batch: Batch<TKey, TValue> | null;\n};\ntype Batch<TKey, TValue> = {\n items: BatchItem<TKey, TValue>[];\n};\nexport type BatchLoader<TKey, TValue> = {\n validate: (keys: TKey[]) => boolean;\n fetch: (keys: TKey[]) => Promise<TValue[] | Promise<TValue>[]>;\n};\n\n/**\n * A function that should never be called unless we messed something up.\n */\nconst throwFatalError = () => {\n throw new Error(\n 'Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new',\n );\n};\n\n/**\n * Dataloader that's very inspired by https://github.com/graphql/dataloader\n * Less configuration, no caching, and allows you to cancel requests\n * When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled\n */\nexport function dataLoader<TKey, TValue>(\n batchLoader: BatchLoader<TKey, TValue>,\n) {\n let pendingItems: BatchItem<TKey, TValue>[] | null = null;\n let dispatchTimer: ReturnType<typeof setTimeout> | null = null;\n\n const destroyTimerAndPendingItems = () => {\n clearTimeout(dispatchTimer as any);\n dispatchTimer = null;\n pendingItems = null;\n };\n\n /**\n * Iterate through the items and split them into groups based on the `batchLoader`'s validate function\n */\n function groupItems(items: BatchItem<TKey, TValue>[]) {\n const groupedItems: BatchItem<TKey, TValue>[][] = [[]];\n let index = 0;\n while (true) {\n const item = items[index];\n if (!item) {\n // we're done\n break;\n }\n const lastGroup = groupedItems[groupedItems.length - 1]!;\n\n if (item.aborted) {\n // Item was aborted before it was dispatched\n item.reject?.(new Error('Aborted'));\n index++;\n continue;\n }\n\n const isValid = batchLoader.validate(\n lastGroup.concat(item).map((it) => it.key),\n );\n\n if (isValid) {\n lastGroup.push(item);\n index++;\n continue;\n }\n\n if (lastGroup.length === 0) {\n item.reject?.(new Error('Input is too big for a single dispatch'));\n index++;\n continue;\n }\n // Create new group, next iteration will try to add the item to that\n groupedItems.push([]);\n }\n return groupedItems;\n }\n\n function dispatch() {\n const groupedItems = groupItems(pendingItems!);\n destroyTimerAndPendingItems();\n\n // Create batches for each group of items\n for (const items of groupedItems) {\n if (!items.length) {\n continue;\n }\n const batch: Batch<TKey, TValue> = {\n items,\n };\n for (const item of items) {\n item.batch = batch;\n }\n const promise = batchLoader.fetch(batch.items.map((_item) => _item.key));\n\n promise\n .then(async (result) => {\n await Promise.all(\n result.map(async (valueOrPromise, index) => {\n const item = batch.items[index]!;\n try {\n const value = await Promise.resolve(valueOrPromise);\n\n item.resolve?.(value);\n } catch (cause) {\n item.reject?.(cause as Error);\n }\n\n item.batch = null;\n item.reject = null;\n item.resolve = null;\n }),\n );\n\n for (const item of batch.items) {\n item.reject?.(new Error('Missing result'));\n item.batch = null;\n }\n })\n .catch((cause) => {\n for (const item of batch.items) {\n item.reject?.(cause);\n item.batch = null;\n }\n });\n }\n }\n function load(key: TKey): Promise<TValue> {\n const item: BatchItem<TKey, TValue> = {\n aborted: false,\n key,\n batch: null,\n resolve: throwFatalError,\n reject: throwFatalError,\n };\n\n const promise = new Promise<TValue>((resolve, reject) => {\n item.reject = reject;\n item.resolve = resolve;\n\n pendingItems ??= [];\n pendingItems.push(item);\n });\n\n dispatchTimer ??= setTimeout(dispatch);\n\n return promise;\n }\n\n return {\n load,\n };\n}\n","import type { AnyRouter, ProcedureType } from '@trpc/server';\nimport { observable } from '@trpc/server/observable';\nimport { transformResult } from '@trpc/server/unstable-core-do-not-import';\nimport type { BatchLoader } from '../internals/dataLoader';\nimport { dataLoader } from '../internals/dataLoader';\nimport { allAbortSignals, raceAbortSignals } from '../internals/signals';\nimport type { NonEmptyArray } from '../internals/types';\nimport { TRPCClientError } from '../TRPCClientError';\nimport type { HTTPBatchLinkOptions } from './HTTPBatchLinkOptions';\nimport type { HTTPResult } from './internals/httpUtils';\nimport {\n getUrl,\n jsonHttpRequester,\n resolveHTTPLinkOptions,\n} from './internals/httpUtils';\nimport type { Operation, TRPCLink } from './types';\n\n/**\n * @see https://trpc.io/docs/client/links/httpBatchLink\n */\nexport function httpBatchLink<TRouter extends AnyRouter>(\n opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>,\n): TRPCLink<TRouter> {\n const resolvedOpts = resolveHTTPLinkOptions(opts);\n const maxURLLength = opts.maxURLLength ?? Infinity;\n const maxItems = opts.maxItems ?? Infinity;\n\n return () => {\n const batchLoader = (\n type: ProcedureType,\n ): BatchLoader<Operation, HTTPResult> => {\n return {\n validate(batchOps) {\n if (maxURLLength === Infinity && maxItems === Infinity) {\n // escape hatch for quick calcs\n return true;\n }\n if (batchOps.length > maxItems) {\n return false;\n }\n const path = batchOps.map((op) => op.path).join(',');\n const inputs = batchOps.map((op) => op.input);\n\n const url = getUrl({\n ...resolvedOpts,\n type,\n path,\n inputs,\n signal: null,\n });\n\n return url.length <= maxURLLength;\n },\n async fetch(batchOps) {\n const path = batchOps.map((op) => op.path).join(',');\n const inputs = batchOps.map((op) => op.input);\n const signal = allAbortSignals(...batchOps.map((op) => op.signal));\n\n const res = await jsonHttpRequester({\n ...resolvedOpts,\n path,\n inputs,\n type,\n headers() {\n if (!opts.headers) {\n return {};\n }\n if (typeof opts.headers === 'function') {\n return opts.headers({\n opList: batchOps as NonEmptyArray<Operation>,\n });\n }\n return opts.headers;\n },\n signal,\n });\n const resJSON = Array.isArray(res.json)\n ? res.json\n : batchOps.map(() => res.json);\n const result = resJSON.map((item) => ({\n meta: res.meta,\n json: item,\n }));\n return result;\n },\n };\n };\n\n const query = dataLoader(batchLoader('query'));\n const mutation = dataLoader(batchLoader('mutation'));\n\n const loaders = { query, mutation };\n return ({ op }) => {\n return observable((observer) => {\n /* istanbul ignore if -- @preserve */\n if (op.type === 'subscription') {\n throw new Error(\n 'Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`',\n );\n }\n const ac = new AbortController();\n const loader = loaders[op.type];\n const promise = loader.load({\n ...op,\n signal: raceAbortSignals(op.signal, ac.signal),\n });\n\n let isDone = false;\n let _res = undefined as HTTPResult | undefined;\n promise\n .then((res) => {\n isDone = true;\n _res = res;\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: res.meta,\n }),\n );\n return;\n }\n observer.next({\n context: res.meta,\n result: transformed.result,\n });\n observer.complete();\n })\n .catch((err) => {\n isDone = true;\n observer.error(\n TRPCClientError.from(err, {\n meta: _res?.meta,\n }),\n );\n });\n\n return () => {\n if (!isDone) {\n ac.abort();\n }\n };\n });\n };\n };\n}\n"],"mappings":";;;;;;;;;AAoBA,MAAM,wBAAwB;CAC5B,MAAM,IAAI,MACR,yFACF;AACF;;;;;;AAOA,SAAgB,WACd,aACA;CACA,IAAI,eAAiD;CACrD,IAAI,gBAAsD;CAE1D,MAAM,oCAAoC;EACxC,aAAa,aAAoB;EACjC,gBAAgB;EAChB,eAAe;CACjB;;;;CAKA,SAAS,WAAW,OAAkC;EACpD,MAAM,eAA4C,CAAC,CAAC,CAAC;EACrD,IAAI,QAAQ;EACZ,OAAO,MAAM;GACX,MAAM,OAAO,MAAM;GACnB,IAAI,CAAC,MAEH;GAEF,MAAM,YAAY,aAAa,aAAa,SAAS;GAErD,IAAI,KAAK,SAAS;;IAEhB,CAAA,eAAA,KAAK,YAAA,QAAA,iBAAA,KAAA,KAAA,aAAA,KAAA,sBAAS,IAAI,MAAM,SAAS,CAAC;IAClC;IACA;GACF;GAMA,IAJgB,YAAY,SAC1B,UAAU,OAAO,IAAI,CAAC,CAAC,KAAK,OAAO,GAAG,GAAG,CAGjC,GAAG;IACX,UAAU,KAAK,IAAI;IACnB;IACA;GACF;GAEA,IAAI,UAAU,WAAW,GAAG;;IAC1B,CAAA,gBAAA,KAAK,YAAA,QAAA,kBAAA,KAAA,KAAA,cAAA,KAAA,sBAAS,IAAI,MAAM,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;KACX,IAAI,CAAC,QACH,GAAG,MAAM;IAEb;GACF,CAAC;EACH;CACF;AACF"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HTTPLinkBaseOptions } from "./httpUtils
|
|
1
|
+
import { _ as NonEmptyArray, 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 } from "@trpc/server/unstable-core-do-not-import";
|
|
4
4
|
import { AnyRouter as AnyRouter$1 } from "@trpc/server";
|
|
5
|
-
|
|
6
5
|
//#region src/links/HTTPBatchLinkOptions.d.ts
|
|
7
6
|
type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TRoot> & {
|
|
8
7
|
maxURLLength?: number;
|
|
@@ -19,15 +18,12 @@ type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TR
|
|
|
19
18
|
*/
|
|
20
19
|
maxItems?: number;
|
|
21
20
|
};
|
|
22
|
-
//# sourceMappingURL=HTTPBatchLinkOptions.d.ts.map
|
|
23
21
|
//#endregion
|
|
24
22
|
//#region src/links/httpBatchLink.d.ts
|
|
25
23
|
/**
|
|
26
24
|
* @see https://trpc.io/docs/client/links/httpBatchLink
|
|
27
25
|
*/
|
|
28
26
|
declare function httpBatchLink<TRouter extends AnyRouter$1>(opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
|
|
29
|
-
//# sourceMappingURL=httpBatchLink.d.ts.map
|
|
30
|
-
|
|
31
27
|
//#endregion
|
|
32
|
-
export { HTTPBatchLinkOptions, httpBatchLink };
|
|
33
|
-
//# sourceMappingURL=httpBatchLink
|
|
28
|
+
export { HTTPBatchLinkOptions as n, httpBatchLink as t };
|
|
29
|
+
//# sourceMappingURL=httpBatchLink-Br-pzPXf.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpBatchLink-Br-pzPXf.d.cts","names":[],"sources":["../src/links/HTTPBatchLinkOptions.ts","../src/links/httpBatchLink.ts"],"mappings":";;;;;KAKY,qBAAqB,cAAc,kBAC7C,oBAAoB;EAClB;;;;;EAKA,UACI,gBACE;IACA,QAAQ,cAAc;QAClB,cAAc,QAAQ;;;;;EAMhC;;;;;;;iBCFY,cAAc,gBAAgB,aAC5C,MAAM,qBAAqB,wCAC1B,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/internals/dataLoader.ts
|
|
9
7
|
/**
|
|
10
8
|
* A function that should never be called unless we messed something up.
|
|
@@ -37,19 +35,18 @@ function dataLoader(batchLoader) {
|
|
|
37
35
|
const lastGroup = groupedItems[groupedItems.length - 1];
|
|
38
36
|
if (item.aborted) {
|
|
39
37
|
var _item$reject;
|
|
40
|
-
(_item$reject = item.reject) === null || _item$reject === void 0 || _item$reject.call(item, new Error("Aborted"));
|
|
38
|
+
(_item$reject = item.reject) === null || _item$reject === void 0 || _item$reject.call(item, /* @__PURE__ */ new Error("Aborted"));
|
|
41
39
|
index++;
|
|
42
40
|
continue;
|
|
43
41
|
}
|
|
44
|
-
|
|
45
|
-
if (isValid) {
|
|
42
|
+
if (batchLoader.validate(lastGroup.concat(item).map((it) => it.key))) {
|
|
46
43
|
lastGroup.push(item);
|
|
47
44
|
index++;
|
|
48
45
|
continue;
|
|
49
46
|
}
|
|
50
47
|
if (lastGroup.length === 0) {
|
|
51
48
|
var _item$reject2;
|
|
52
|
-
(_item$reject2 = item.reject) === null || _item$reject2 === void 0 || _item$reject2.call(item, new Error("Input is too big for a single dispatch"));
|
|
49
|
+
(_item$reject2 = item.reject) === null || _item$reject2 === void 0 || _item$reject2.call(item, /* @__PURE__ */ new Error("Input is too big for a single dispatch"));
|
|
53
50
|
index++;
|
|
54
51
|
continue;
|
|
55
52
|
}
|
|
@@ -64,8 +61,7 @@ function dataLoader(batchLoader) {
|
|
|
64
61
|
if (!items.length) continue;
|
|
65
62
|
const batch = { items };
|
|
66
63
|
for (const item of items) item.batch = batch;
|
|
67
|
-
|
|
68
|
-
promise.then(async (result) => {
|
|
64
|
+
batchLoader.fetch(batch.items.map((_item) => _item.key)).then(async (result) => {
|
|
69
65
|
await Promise.all(result.map(async (valueOrPromise, index) => {
|
|
70
66
|
const item = batch.items[index];
|
|
71
67
|
try {
|
|
@@ -82,7 +78,7 @@ function dataLoader(batchLoader) {
|
|
|
82
78
|
}));
|
|
83
79
|
for (const item of batch.items) {
|
|
84
80
|
var _item$reject4;
|
|
85
|
-
(_item$reject4 = item.reject) === null || _item$reject4 === void 0 || _item$reject4.call(item, new Error("Missing result"));
|
|
81
|
+
(_item$reject4 = item.reject) === null || _item$reject4 === void 0 || _item$reject4.call(item, /* @__PURE__ */ new Error("Missing result"));
|
|
86
82
|
item.batch = null;
|
|
87
83
|
}
|
|
88
84
|
}).catch((cause) => {
|
|
@@ -115,52 +111,8 @@ function dataLoader(batchLoader) {
|
|
|
115
111
|
}
|
|
116
112
|
return { load };
|
|
117
113
|
}
|
|
118
|
-
|
|
119
|
-
//#endregion
|
|
120
|
-
//#region src/internals/signals.ts
|
|
121
|
-
/**
|
|
122
|
-
* Like `Promise.all()` but for abort signals
|
|
123
|
-
* - When all signals have been aborted, the merged signal will be aborted
|
|
124
|
-
* - If one signal is `null`, no signal will be aborted
|
|
125
|
-
*/
|
|
126
|
-
function allAbortSignals(...signals) {
|
|
127
|
-
const ac = new AbortController();
|
|
128
|
-
const count = signals.length;
|
|
129
|
-
let abortedCount = 0;
|
|
130
|
-
const onAbort = () => {
|
|
131
|
-
if (++abortedCount === count) ac.abort();
|
|
132
|
-
};
|
|
133
|
-
for (const signal of signals) if (signal === null || signal === void 0 ? void 0 : signal.aborted) onAbort();
|
|
134
|
-
else signal === null || signal === void 0 || signal.addEventListener("abort", onAbort, { once: true });
|
|
135
|
-
return ac.signal;
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Like `Promise.race` but for abort signals
|
|
139
|
-
*
|
|
140
|
-
* Basically, a ponyfill for
|
|
141
|
-
* [`AbortSignal.any`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static).
|
|
142
|
-
*/
|
|
143
|
-
function raceAbortSignals(...signals) {
|
|
144
|
-
const ac = new AbortController();
|
|
145
|
-
for (const signal of signals) if (signal === null || signal === void 0 ? void 0 : signal.aborted) ac.abort();
|
|
146
|
-
else signal === null || signal === void 0 || signal.addEventListener("abort", () => ac.abort(), { once: true });
|
|
147
|
-
return ac.signal;
|
|
148
|
-
}
|
|
149
|
-
function abortSignalToPromise(signal) {
|
|
150
|
-
return new Promise((_, reject) => {
|
|
151
|
-
if (signal.aborted) {
|
|
152
|
-
reject(signal.reason);
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
signal.addEventListener("abort", () => {
|
|
156
|
-
reject(signal.reason);
|
|
157
|
-
}, { once: true });
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
114
|
//#endregion
|
|
162
115
|
//#region src/links/httpBatchLink.ts
|
|
163
|
-
var import_objectSpread2 = require_chunk.__toESM(require_objectSpread2$1.require_objectSpread2(), 1);
|
|
164
116
|
/**
|
|
165
117
|
* @see https://trpc.io/docs/client/links/httpBatchLink
|
|
166
118
|
*/
|
|
@@ -177,19 +129,18 @@ function httpBatchLink(opts) {
|
|
|
177
129
|
if (batchOps.length > maxItems) return false;
|
|
178
130
|
const path = batchOps.map((op) => op.path).join(",");
|
|
179
131
|
const inputs = batchOps.map((op) => op.input);
|
|
180
|
-
|
|
132
|
+
return require_httpUtils.getUrl(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, resolvedOpts), {}, {
|
|
181
133
|
type,
|
|
182
134
|
path,
|
|
183
135
|
inputs,
|
|
184
136
|
signal: null
|
|
185
|
-
}));
|
|
186
|
-
return url.length <= maxURLLength;
|
|
137
|
+
})).length <= maxURLLength;
|
|
187
138
|
},
|
|
188
139
|
async fetch(batchOps) {
|
|
189
140
|
const path = batchOps.map((op) => op.path).join(",");
|
|
190
141
|
const inputs = batchOps.map((op) => op.input);
|
|
191
|
-
const signal = allAbortSignals(...batchOps.map((op) => op.signal));
|
|
192
|
-
const res = await require_httpUtils.jsonHttpRequester(
|
|
142
|
+
const signal = require_httpUtils.allAbortSignals(...batchOps.map((op) => op.signal));
|
|
143
|
+
const res = await require_httpUtils.jsonHttpRequester(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, resolvedOpts), {}, {
|
|
193
144
|
path,
|
|
194
145
|
inputs,
|
|
195
146
|
type,
|
|
@@ -200,31 +151,29 @@ function httpBatchLink(opts) {
|
|
|
200
151
|
},
|
|
201
152
|
signal
|
|
202
153
|
}));
|
|
203
|
-
|
|
204
|
-
const result = resJSON.map((item) => ({
|
|
154
|
+
return (Array.isArray(res.json) ? res.json : batchOps.map(() => res.json)).map((item) => ({
|
|
205
155
|
meta: res.meta,
|
|
206
156
|
json: item
|
|
207
157
|
}));
|
|
208
|
-
return result;
|
|
209
158
|
}
|
|
210
159
|
};
|
|
211
160
|
};
|
|
212
|
-
const query = dataLoader(batchLoader("query"));
|
|
213
|
-
const mutation = dataLoader(batchLoader("mutation"));
|
|
214
161
|
const loaders = {
|
|
215
|
-
query,
|
|
216
|
-
mutation
|
|
162
|
+
query: dataLoader(batchLoader("query")),
|
|
163
|
+
mutation: dataLoader(batchLoader("mutation"))
|
|
217
164
|
};
|
|
218
165
|
return ({ op }) => {
|
|
219
|
-
return (0,
|
|
166
|
+
return (0, _trpc_server_observable.observable)((observer) => {
|
|
220
167
|
/* istanbul ignore if -- @preserve */
|
|
221
168
|
if (op.type === "subscription") throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`");
|
|
222
|
-
const
|
|
223
|
-
const promise =
|
|
169
|
+
const ac = new AbortController();
|
|
170
|
+
const promise = loaders[op.type].load(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, op), {}, { signal: require_httpUtils.raceAbortSignals(op.signal, ac.signal) }));
|
|
171
|
+
let isDone = false;
|
|
224
172
|
let _res = void 0;
|
|
225
173
|
promise.then((res) => {
|
|
174
|
+
isDone = true;
|
|
226
175
|
_res = res;
|
|
227
|
-
const transformed = (0,
|
|
176
|
+
const transformed = (0, _trpc_server_unstable_core_do_not_import.transformResult)(res.json, resolvedOpts.transformer.output);
|
|
228
177
|
if (!transformed.ok) {
|
|
229
178
|
observer.error(require_TRPCClientError.TRPCClientError.from(transformed.error, { meta: res.meta }));
|
|
230
179
|
return;
|
|
@@ -235,42 +184,26 @@ function httpBatchLink(opts) {
|
|
|
235
184
|
});
|
|
236
185
|
observer.complete();
|
|
237
186
|
}).catch((err) => {
|
|
187
|
+
isDone = true;
|
|
238
188
|
observer.error(require_TRPCClientError.TRPCClientError.from(err, { meta: _res === null || _res === void 0 ? void 0 : _res.meta }));
|
|
239
189
|
});
|
|
240
|
-
return () => {
|
|
190
|
+
return () => {
|
|
191
|
+
if (!isDone) ac.abort();
|
|
192
|
+
};
|
|
241
193
|
});
|
|
242
194
|
};
|
|
243
195
|
};
|
|
244
196
|
}
|
|
245
|
-
|
|
246
197
|
//#endregion
|
|
247
|
-
Object.defineProperty(exports,
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
});
|
|
253
|
-
Object.defineProperty(exports, 'allAbortSignals', {
|
|
254
|
-
enumerable: true,
|
|
255
|
-
get: function () {
|
|
256
|
-
return allAbortSignals;
|
|
257
|
-
}
|
|
258
|
-
});
|
|
259
|
-
Object.defineProperty(exports, 'dataLoader', {
|
|
260
|
-
enumerable: true,
|
|
261
|
-
get: function () {
|
|
262
|
-
return dataLoader;
|
|
263
|
-
}
|
|
198
|
+
Object.defineProperty(exports, "dataLoader", {
|
|
199
|
+
enumerable: true,
|
|
200
|
+
get: function() {
|
|
201
|
+
return dataLoader;
|
|
202
|
+
}
|
|
264
203
|
});
|
|
265
|
-
Object.defineProperty(exports,
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
204
|
+
Object.defineProperty(exports, "httpBatchLink", {
|
|
205
|
+
enumerable: true,
|
|
206
|
+
get: function() {
|
|
207
|
+
return httpBatchLink;
|
|
208
|
+
}
|
|
270
209
|
});
|
|
271
|
-
Object.defineProperty(exports, 'raceAbortSignals', {
|
|
272
|
-
enumerable: true,
|
|
273
|
-
get: function () {
|
|
274
|
-
return raceAbortSignals;
|
|
275
|
-
}
|
|
276
|
-
});
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HTTPLinkBaseOptions } from "./httpUtils
|
|
1
|
+
import { _ as NonEmptyArray, 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 } from "@trpc/server/unstable-core-do-not-import";
|
|
4
4
|
import { AnyRouter as AnyRouter$1 } from "@trpc/server";
|
|
5
|
-
|
|
6
5
|
//#region src/links/HTTPBatchLinkOptions.d.ts
|
|
7
6
|
type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TRoot> & {
|
|
8
7
|
maxURLLength?: number;
|
|
@@ -19,15 +18,12 @@ type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TR
|
|
|
19
18
|
*/
|
|
20
19
|
maxItems?: number;
|
|
21
20
|
};
|
|
22
|
-
//# sourceMappingURL=HTTPBatchLinkOptions.d.ts.map
|
|
23
21
|
//#endregion
|
|
24
22
|
//#region src/links/httpBatchLink.d.ts
|
|
25
23
|
/**
|
|
26
24
|
* @see https://trpc.io/docs/client/links/httpBatchLink
|
|
27
25
|
*/
|
|
28
26
|
declare function httpBatchLink<TRouter extends AnyRouter$1>(opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
|
|
29
|
-
//# sourceMappingURL=httpBatchLink.d.ts.map
|
|
30
|
-
|
|
31
27
|
//#endregion
|
|
32
|
-
export { HTTPBatchLinkOptions, httpBatchLink };
|
|
33
|
-
//# sourceMappingURL=httpBatchLink
|
|
28
|
+
export { HTTPBatchLinkOptions as n, httpBatchLink as t };
|
|
29
|
+
//# sourceMappingURL=httpBatchLink-nvc48L_N.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpBatchLink-nvc48L_N.d.mts","names":[],"sources":["../src/links/HTTPBatchLinkOptions.ts","../src/links/httpBatchLink.ts"],"mappings":";;;;;KAKY,qBAAqB,cAAc,kBAC7C,oBAAoB;EAClB;;;;;EAKA,UACI,gBACE;IACA,QAAQ,cAAc;QAClB,cAAc,QAAQ;;;;;EAMhC;;;;;;;iBCFY,cAAc,gBAAgB,aAC5C,MAAM,qBAAqB,wCAC1B,SAAS"}
|