@trpc/client 11.25.2 → 11.25.3-canary.13.g1341462e1
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-Byo7P4QG.mjs → TRPCClientError-DE6-fd1n.mjs} +3 -4
- package/dist/{TRPCClientError-Byo7P4QG.mjs.map → TRPCClientError-DE6-fd1n.mjs.map} +1 -1
- package/dist/{TRPCClientError-CPEwAI4E.cjs → TRPCClientError-irOPxS6c.cjs} +2 -3
- package/dist/{httpBatchLink-aPx7u_sr.mjs → httpBatchLink-C3x3d8vz.mjs} +6 -8
- package/dist/{httpBatchLink-aPx7u_sr.mjs.map → httpBatchLink-C3x3d8vz.mjs.map} +1 -1
- package/dist/{httpBatchLink-VjOVPXkI.cjs → httpBatchLink-DL8mnpSC.cjs} +5 -7
- package/dist/{httpBatchLink-Dp4tIBfy.d.cts → httpBatchLink-DbD4ZGAM.d.cts} +3 -7
- package/dist/httpBatchLink-DbD4ZGAM.d.cts.map +1 -0
- package/dist/{httpBatchLink-Dxqsu9CE.d.mts → httpBatchLink-Dk3_n5pP.d.mts} +3 -7
- package/dist/httpBatchLink-Dk3_n5pP.d.mts.map +1 -0
- package/dist/{httpLink-CWd1U86f.mjs → httpLink-B7uIfNkv.mjs} +6 -8
- package/dist/{httpLink-CWd1U86f.mjs.map → httpLink-B7uIfNkv.mjs.map} +1 -1
- package/dist/{httpLink-Cd3n7PrK.d.mts → httpLink-BjZdBzr6.d.mts} +3 -5
- package/dist/httpLink-BjZdBzr6.d.mts.map +1 -0
- package/dist/{httpLink-CeszFCmc.cjs → httpLink-DuF7KiyZ.cjs} +5 -7
- package/dist/{httpUtils-5Hmhcy-z.mjs → httpUtils-CWtyfi2N.mjs} +5 -8
- package/dist/{httpUtils-5Hmhcy-z.mjs.map → httpUtils-CWtyfi2N.mjs.map} +1 -1
- package/dist/{httpUtils-BAwJ9mb3.d.mts → httpUtils-CxgZ3W-1.d.cts} +4 -6
- package/dist/httpUtils-CxgZ3W-1.d.cts.map +1 -0
- package/dist/{httpUtils-DbsdWXpN.cjs → httpUtils-ZrQjZ1_i.cjs} +4 -7
- package/dist/{httpUtils-CvL7UM_P.d.cts → httpUtils-gZ7bAQ6T.d.mts} +4 -6
- package/dist/httpUtils-gZ7bAQ6T.d.mts.map +1 -0
- package/dist/index.cjs +40 -66
- package/dist/index.d.cts +10 -40
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +9 -29
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +40 -66
- package/dist/index.mjs.map +1 -1
- package/dist/links/httpBatchLink.cjs +1 -1
- package/dist/links/httpBatchLink.d.cts +1 -1
- package/dist/links/httpBatchLink.d.mts +1 -1
- package/dist/links/httpBatchLink.mjs +1 -2
- package/dist/links/httpLink.cjs +1 -1
- package/dist/links/httpLink.d.cts +24 -2
- package/dist/links/httpLink.d.cts.map +1 -0
- package/dist/links/httpLink.d.mts +1 -1
- package/dist/links/httpLink.mjs +1 -2
- package/dist/links/loggerLink.cjs +2 -3
- package/dist/links/loggerLink.d.cts +67 -2
- package/dist/links/loggerLink.d.cts.map +1 -0
- package/dist/links/loggerLink.d.mts +1 -1
- package/dist/links/loggerLink.mjs +2 -3
- package/dist/links/splitLink.cjs +1 -1
- package/dist/links/splitLink.d.cts +22 -2
- package/dist/links/splitLink.d.cts.map +1 -0
- package/dist/links/splitLink.d.mts +1 -1
- package/dist/links/splitLink.mjs +1 -2
- package/dist/links/wsLink/wsLink.cjs +1 -1
- package/dist/links/wsLink/wsLink.d.cts +1 -1
- package/dist/links/wsLink/wsLink.d.mts +1 -1
- package/dist/links/wsLink/wsLink.mjs +1 -2
- package/dist/{loggerLink-BEMtA7V5.d.cts → loggerLink-CBPx95zm.d.mts} +2 -4
- package/dist/loggerLink-CBPx95zm.d.mts.map +1 -0
- package/dist/{objectSpread2-D-dJi1gK.cjs → objectSpread2-Xm0br5eL.cjs} +10 -15
- package/dist/{objectSpread2-weooBxVk.mjs → objectSpread2-pyA4QVO4.mjs} +10 -15
- package/dist/{splitLink-CL8W2Mit.cjs → splitLink-BBLj14Dv.cjs} +2 -4
- package/dist/{splitLink-zyV5y7N1.d.mts → splitLink-BtPz7lCB.d.mts} +2 -4
- package/dist/splitLink-BtPz7lCB.d.mts.map +1 -0
- package/dist/{splitLink-DcpFI5s5.mjs → splitLink-PFsRy7Mf.mjs} +3 -5
- package/dist/{splitLink-DcpFI5s5.mjs.map → splitLink-PFsRy7Mf.mjs.map} +1 -1
- package/dist/{subscriptions-DcqRZc4h.d.cts → subscriptions-CvJnusYO.d.cts} +1 -3
- package/dist/subscriptions-CvJnusYO.d.cts.map +1 -0
- package/dist/{subscriptions-DcqRZc4h.d.mts → subscriptions-CvJnusYO.d.mts} +1 -3
- package/dist/subscriptions-CvJnusYO.d.mts.map +1 -0
- package/dist/{types-BrCJd1zp.d.cts → types-BG-3kpeg.d.mts} +3 -9
- package/dist/types-BG-3kpeg.d.mts.map +1 -0
- package/dist/{types-DO-GCB2q.d.mts → types-BhHxuBsu.d.cts} +14 -10
- package/dist/types-BhHxuBsu.d.cts.map +1 -0
- package/dist/{unstable-internals-CNoyg7Yf.d.cts → unstable-internals-CnrO49lh.d.mts} +1 -3
- package/dist/unstable-internals-CnrO49lh.d.mts.map +1 -0
- package/dist/unstable-internals.cjs +1 -2
- package/dist/unstable-internals.d.cts +43 -3
- package/dist/unstable-internals.d.cts.map +1 -0
- package/dist/unstable-internals.d.mts +2 -2
- package/dist/unstable-internals.mjs +1 -2
- package/dist/{wsLink-l0dX0ah6.mjs → wsLink-BiIe_j6D.mjs} +12 -21
- package/dist/{wsLink-l0dX0ah6.mjs.map → wsLink-BiIe_j6D.mjs.map} +1 -1
- package/dist/{wsLink-BgncVFHX.cjs → wsLink-BriU1R12.cjs} +11 -20
- package/dist/{wsLink-Cpw-BznR.d.cts → wsLink-CBFXDQnx.d.cts} +4 -16
- package/dist/wsLink-CBFXDQnx.d.cts.map +1 -0
- package/dist/{wsLink-Cjetil1Z.d.mts → wsLink-DXfg9MiM.d.mts} +4 -16
- package/dist/wsLink-DXfg9MiM.d.mts.map +1 -0
- package/package.json +12 -12
- package/skills/client-setup/SKILL.md +1 -1
- package/skills/links/SKILL.md +1 -1
- package/skills/superjson/SKILL.md +1 -1
- package/dist/httpBatchLink-Dp4tIBfy.d.cts.map +0 -1
- package/dist/httpBatchLink-Dxqsu9CE.d.mts.map +0 -1
- package/dist/httpLink-Cd3n7PrK.d.mts.map +0 -1
- package/dist/httpLink-DpCm7qgx.d.cts +0 -27
- package/dist/httpLink-DpCm7qgx.d.cts.map +0 -1
- package/dist/httpUtils-BAwJ9mb3.d.mts.map +0 -1
- package/dist/httpUtils-CvL7UM_P.d.cts.map +0 -1
- package/dist/loggerLink-BEMtA7V5.d.cts.map +0 -1
- package/dist/loggerLink-Daki_B65.d.mts +0 -69
- package/dist/loggerLink-Daki_B65.d.mts.map +0 -1
- package/dist/splitLink-i7EskO_m.d.cts +0 -25
- package/dist/splitLink-i7EskO_m.d.cts.map +0 -1
- package/dist/splitLink-zyV5y7N1.d.mts.map +0 -1
- package/dist/subscriptions-DcqRZc4h.d.cts.map +0 -1
- package/dist/subscriptions-DcqRZc4h.d.mts.map +0 -1
- package/dist/types-BrCJd1zp.d.cts.map +0 -1
- package/dist/types-DO-GCB2q.d.mts.map +0 -1
- package/dist/unstable-internals-CNoyg7Yf.d.cts.map +0 -1
- package/dist/unstable-internals-CNoyg7Yf.d.mts +0 -44
- package/dist/unstable-internals-CNoyg7Yf.d.mts.map +0 -1
- package/dist/wsLink-Cjetil1Z.d.mts.map +0 -1
- package/dist/wsLink-Cpw-BznR.d.cts.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as _defineProperty, t as _objectSpread2 } from "./objectSpread2-
|
|
1
|
+
import { n as _defineProperty, t as _objectSpread2 } from "./objectSpread2-pyA4QVO4.mjs";
|
|
2
2
|
import { isObject } from "@trpc/server/unstable-core-do-not-import";
|
|
3
|
-
|
|
3
|
+
// src/TRPCClientError.ts
|
|
4
4
|
/**
|
|
5
5
|
* Whether a value is a `TRPCClientError`, typed for a router or procedure.
|
|
6
6
|
* @see https://trpc.io/docs/client/vanilla/error-handling#catching-a-thrown-error
|
|
@@ -54,7 +54,6 @@ var TRPCClientError = class TRPCClientError extends Error {
|
|
|
54
54
|
return new TRPCClientError(getMessageFromUnknownError(cause, "Unknown error"), _objectSpread2(_objectSpread2({}, opts), {}, { cause }));
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
|
-
//#endregion
|
|
58
57
|
export { isTRPCClientError as n, TRPCClientError as t };
|
|
59
58
|
|
|
60
|
-
//# sourceMappingURL=TRPCClientError-
|
|
59
|
+
//# sourceMappingURL=TRPCClientError-DE6-fd1n.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TRPCClientError-
|
|
1
|
+
{"version":3,"file":"TRPCClientError-DE6-fd1n.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'];\n/** What a client error has, whatever its router. */\nexport interface TRPCClientErrorBase<TShape extends DefaultErrorShape> {\n readonly message: string;\n /** The error as the server's error formatter shaped it, if it came from the server. */\n readonly shape: Maybe<TShape>;\n /** The shape's `data`, such as the tRPC code and HTTP status. */\n readonly data: Maybe<TShape['data']>;\n}\n/**\n * The shape of a client error for a router or procedure, without the\n * class. Use it to type errors you pass around, such as in React state.\n * @see https://trpc.io/docs/client/vanilla/infer-types#infer-trpcclienterror-types\n */\nexport type TRPCClientErrorLike<TInferrable extends InferrableClientTypes> =\n TRPCClientErrorBase<inferErrorShape<TInferrable>>;\n\n/**\n * Whether a value is a `TRPCClientError`, typed for a router or procedure.\n * @see https://trpc.io/docs/client/vanilla/error-handling#catching-a-thrown-error\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\n/**\n * The error a client call throws, whether the server sent an error or the\n * request failed.\n * @see https://trpc.io/docs/client/vanilla/error-handling\n */\nexport class TRPCClientError<TRouterOrProcedure extends InferrableClientTypes>\n extends Error\n implements TRPCClientErrorBase<inferErrorShape<TRouterOrProcedure>>\n{\n // oxlint-disable-next-line typescript/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 /** The error this one wraps, such as a network error. */\n public override readonly cause;\n /** The error as the server's error formatter shaped it, if it came from the server. */\n public readonly shape: Maybe<inferErrorShape<TRouterOrProcedure>>;\n /** The shape's `data`, such as the tRPC code and HTTP status. */\n public readonly data: Maybe<inferErrorShape<TRouterOrProcedure>['data']>;\n\n /**\n * More about the error, if any. HTTP errors may have the `response` and\n * its `responseJSON`; a failed fetch or unparsable response may have\n * neither.\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 // oxlint-disable-next-line typescript/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 /**\n * Turns an error response, an `Error` or another object into a\n * `TRPCClientError`. A `TRPCClientError` is returned as it is.\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":";;;;;;;AAiCA,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;;;;;;AAOA,IAAa,kBAAb,MAAa,wBACH,MAEV;CAiBE,YACE,SACA,MAKA;;EACA,MAAM,QAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAAQ,KAAM;EAIpB,MAAM,SAAS,EAAE,MAAM,CAAC;EAzBD,gBAAA,MAAA,SAAA,KAAA,CAAA;EAET,gBAAA,MAAA,SAAA,KAAA,CAAA;EAEA,gBAAA,MAAA,QAAA,KAAA,CAAA;EAOT,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;;;;;CAMA,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,6 +1,6 @@
|
|
|
1
|
-
const require_objectSpread2 = require("./objectSpread2-
|
|
1
|
+
const require_objectSpread2 = require("./objectSpread2-Xm0br5eL.cjs");
|
|
2
2
|
let _trpc_server_unstable_core_do_not_import = require("@trpc/server/unstable-core-do-not-import");
|
|
3
|
-
|
|
3
|
+
// src/TRPCClientError.ts
|
|
4
4
|
/**
|
|
5
5
|
* Whether a value is a `TRPCClientError`, typed for a router or procedure.
|
|
6
6
|
* @see https://trpc.io/docs/client/vanilla/error-handling#catching-a-thrown-error
|
|
@@ -54,7 +54,6 @@ var TRPCClientError = class TRPCClientError extends Error {
|
|
|
54
54
|
return new TRPCClientError(getMessageFromUnknownError(cause, "Unknown error"), require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, opts), {}, { cause }));
|
|
55
55
|
}
|
|
56
56
|
};
|
|
57
|
-
//#endregion
|
|
58
57
|
Object.defineProperty(exports, "TRPCClientError", {
|
|
59
58
|
enumerable: true,
|
|
60
59
|
get: function() {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as TRPCClientError } from "./TRPCClientError-
|
|
3
|
-
import {
|
|
1
|
+
import { a as jsonHttpRequester, c as allAbortSignals, o as resolveHTTPLinkOptions, r as getUrl, u as raceAbortSignalsWithCleanup } from "./httpUtils-CWtyfi2N.mjs";
|
|
2
|
+
import { t as TRPCClientError } from "./TRPCClientError-DE6-fd1n.mjs";
|
|
3
|
+
import { t as _objectSpread2 } from "./objectSpread2-pyA4QVO4.mjs";
|
|
4
4
|
import { observable } from "@trpc/server/observable";
|
|
5
5
|
import { transformResult } from "@trpc/server/unstable-core-do-not-import";
|
|
6
|
-
|
|
6
|
+
// src/internals/dataLoader.ts
|
|
7
7
|
/**
|
|
8
8
|
* A function that should never be called unless we messed something up.
|
|
9
9
|
*/
|
|
@@ -120,8 +120,7 @@ function dataLoader(batchLoader) {
|
|
|
120
120
|
}
|
|
121
121
|
return { load };
|
|
122
122
|
}
|
|
123
|
-
|
|
124
|
-
//#region src/links/httpBatchLink.ts
|
|
123
|
+
// src/links/httpBatchLink.ts
|
|
125
124
|
/**
|
|
126
125
|
* A terminating link that batches calls made in the same tick into one HTTP
|
|
127
126
|
* request.
|
|
@@ -208,7 +207,6 @@ function httpBatchLink(opts) {
|
|
|
208
207
|
};
|
|
209
208
|
};
|
|
210
209
|
}
|
|
211
|
-
//#endregion
|
|
212
210
|
export { dataLoader as n, httpBatchLink as t };
|
|
213
211
|
|
|
214
|
-
//# sourceMappingURL=httpBatchLink-
|
|
212
|
+
//# sourceMappingURL=httpBatchLink-C3x3d8vz.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpBatchLink-aPx7u_sr.mjs","names":[],"sources":["../src/internals/dataLoader.ts","../src/links/httpBatchLink.ts"],"sourcesContent":["/* oxlint-disable typescript/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 let isValid: boolean;\n try {\n isValid = batchLoader.validate(\n lastGroup.concat(item).map((it) => it.key),\n );\n } catch (cause) {\n item.reject?.(cause as Error);\n index++;\n continue;\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 {\n allAbortSignals,\n raceAbortSignalsWithCleanup,\n} 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 * A terminating link that batches calls made in the same tick into one HTTP\n * request.\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 { signal, cleanup } = raceAbortSignalsWithCleanup(\n op.signal,\n ac.signal,\n );\n const loader = loaders[op.type];\n const promise = loader.load({\n ...op,\n 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 cleanup();\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,iBAA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I,OAAO,KAAA;IACX,QACG,MAAM,QAAQ;KACb,SAAS;KACT,OAAO;KACP,MAAM,cAAc,gBAClB,IAAI,MACJ,aAAa,YAAY,MAC3B;KAEA,IAAI,CAAC,YAAY,IAAI;MACnB,SAAS,MACP,gBAAgB,KAAK,YAAY,OAAO,EACtC,MAAM,IAAI,KACZ,CAAC,CACH;MACA;KACF;KACA,SAAS,KAAK;MACZ,SAAS,IAAI;MACb,QAAQ,YAAY;KACtB,CAAC;KACD,SAAS,SAAS;IACpB,CAAC,CAAC,CACD,OAAO,QAAQ;KACd,SAAS;KACT,SAAS,MACP,gBAAgB,KAAK,KAAK,EACxB,MAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAAM,KAAM,KACd,CAAC,CACH;IACF,CAAC;IAEH,aAAa;KACX,IAAI,CAAC,QACH,GAAG,MAAM;KAEX,QAAQ;IACV;GACF,CAAC;EACH;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"httpBatchLink-C3x3d8vz.mjs","names":[],"sources":["../src/internals/dataLoader.ts","../src/links/httpBatchLink.ts"],"sourcesContent":["/* oxlint-disable typescript/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 let isValid: boolean;\n try {\n isValid = batchLoader.validate(\n lastGroup.concat(item).map((it) => it.key),\n );\n } catch (cause) {\n item.reject?.(cause as Error);\n index++;\n continue;\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 {\n allAbortSignals,\n raceAbortSignalsWithCleanup,\n} 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 * A terminating link that batches calls made in the same tick into one HTTP\n * request.\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 { signal, cleanup } = raceAbortSignalsWithCleanup(\n op.signal,\n ac.signal,\n );\n const loader = loaders[op.type];\n const promise = loader.load({\n ...op,\n 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 cleanup();\n };\n });\n };\n };\n}\n"],"mappings":";;;;;;;;;AAoBA,MAA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KA,MAAM,UAAU;GAAE,OAHJ,WAAW,YAAY,OAAO,CAGtB;GAAG,UAFR,WAAW,YAAY,UAAU,CAElB;EAAE;EAClC,QAAQ,EAAE,SAAS;GACjB,OAAO,YAAY,aAAa;;IAE9B,IAAI,GAAG,SAAS,gBACd,MAAM,IAAI,MACR,sFACF;IAEF,MAAM,KAAK,IAAI,gBAAgB;IAC/B,MAAM,EAAE,QAAQ,YAAY,4BAC1B,GAAG,QACH,GAAG,MACL;IAEA,MAAM,UADS,QAAQ,GAAG,KACJ,CAAC,KAAA,eAAA,eAAA,CAAA,GAClB,EAAA,GAAA,CAAA,GAAA,EACH,OAAA,CACF,CAAC;IAED,IAAI,SAAS;IACb,IAAI,OAAO,KAAA;IACX,QACG,MAAM,QAAQ;KACb,SAAS;KACT,OAAO;KACP,MAAM,cAAc,gBAClB,IAAI,MACJ,aAAa,YAAY,MAC3B;KAEA,IAAI,CAAC,YAAY,IAAI;MACnB,SAAS,MACP,gBAAgB,KAAK,YAAY,OAAO,EACtC,MAAM,IAAI,KACZ,CAAC,CACH;MACA;KACF;KACA,SAAS,KAAK;MACZ,SAAS,IAAI;MACb,QAAQ,YAAY;KACtB,CAAC;KACD,SAAS,SAAS;IACpB,CAAC,CAAC,CACD,OAAO,QAAQ;KACd,SAAS;KACT,SAAS,MACP,gBAAgB,KAAK,KAAK,EACxB,MAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAAM,KAAM,KACd,CAAC,CACH;IACF,CAAC;IAEH,aAAa;KACX,IAAI,CAAC,QACH,GAAG,MAAM;KAEX,QAAQ;IACV;GACF,CAAC;EACH;CACF;AACF"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_TRPCClientError = require("./TRPCClientError-
|
|
3
|
-
const
|
|
1
|
+
const require_httpUtils = require("./httpUtils-ZrQjZ1_i.cjs");
|
|
2
|
+
const require_TRPCClientError = require("./TRPCClientError-irOPxS6c.cjs");
|
|
3
|
+
const require_objectSpread2 = require("./objectSpread2-Xm0br5eL.cjs");
|
|
4
4
|
let _trpc_server_observable = require("@trpc/server/observable");
|
|
5
5
|
let _trpc_server_unstable_core_do_not_import = require("@trpc/server/unstable-core-do-not-import");
|
|
6
|
-
|
|
6
|
+
// src/internals/dataLoader.ts
|
|
7
7
|
/**
|
|
8
8
|
* A function that should never be called unless we messed something up.
|
|
9
9
|
*/
|
|
@@ -120,8 +120,7 @@ function dataLoader(batchLoader) {
|
|
|
120
120
|
}
|
|
121
121
|
return { load };
|
|
122
122
|
}
|
|
123
|
-
|
|
124
|
-
//#region src/links/httpBatchLink.ts
|
|
123
|
+
// src/links/httpBatchLink.ts
|
|
125
124
|
/**
|
|
126
125
|
* A terminating link that batches calls made in the same tick into one HTTP
|
|
127
126
|
* request.
|
|
@@ -208,7 +207,6 @@ function httpBatchLink(opts) {
|
|
|
208
207
|
};
|
|
209
208
|
};
|
|
210
209
|
}
|
|
211
|
-
//#endregion
|
|
212
210
|
Object.defineProperty(exports, "dataLoader", {
|
|
213
211
|
enumerable: true,
|
|
214
212
|
get: function() {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as HTTPLinkBaseOptions } from "./httpUtils-
|
|
1
|
+
import { b as NonEmptyArray, n as Operation, t as HTTPHeaders, u as TRPCLink } from "./types-BhHxuBsu.cjs";
|
|
2
|
+
import { t as HTTPLinkBaseOptions } from "./httpUtils-CxgZ3W-1.cjs";
|
|
3
3
|
import { AnyClientTypes } from "@trpc/server/unstable-core-do-not-import";
|
|
4
4
|
import { AnyRouter as AnyRouter$1 } from "@trpc/server";
|
|
5
|
-
//#region src/links/HTTPBatchLinkOptions.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* The options of `httpBatchLink`.
|
|
8
7
|
* @see https://trpc.io/docs/client/links/httpBatchLink#options
|
|
@@ -32,8 +31,6 @@ type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TR
|
|
|
32
31
|
*/
|
|
33
32
|
maxItems?: number;
|
|
34
33
|
};
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region src/links/httpBatchLink.d.ts
|
|
37
34
|
/**
|
|
38
35
|
* A terminating link that batches calls made in the same tick into one HTTP
|
|
39
36
|
* request.
|
|
@@ -41,6 +38,5 @@ type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TR
|
|
|
41
38
|
* @see https://trpc.io/docs/client/links/httpBatchLink
|
|
42
39
|
*/
|
|
43
40
|
declare function httpBatchLink<TRouter extends AnyRouter$1>(opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
|
|
44
|
-
//#endregion
|
|
45
41
|
export { HTTPBatchLinkOptions as n, httpBatchLink as t };
|
|
46
|
-
//# sourceMappingURL=httpBatchLink-
|
|
42
|
+
//# sourceMappingURL=httpBatchLink-DbD4ZGAM.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpBatchLink-DbD4ZGAM.d.cts","names":["AnyRouter"],"sources":["../src/links/HTTPBatchLinkOptions.ts","../src/links/httpBatchLink.ts"],"mappings":";;;;;;;;KASY,qBAAqB,cAAc,kBAC7C,oBAAoB;;;;;;;;EAQlB;;;;;;EAMA,UACI,gBACE;IACA,QAAQ,cAAc;QAClB,cAAc,QAAQ;;;;;;;EAQhC;;;;;;;;iBCVY,cAAc,gBAAgBA,aAC5C,MAAM,qBAAqB,wCAC1B,SAAS"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { _ as NonEmptyArray, n as Operation, t as HTTPHeaders, u as TRPCLink } from "./types-
|
|
2
|
-
import { t as HTTPLinkBaseOptions } from "./httpUtils-
|
|
1
|
+
import { _ as NonEmptyArray, n as Operation, t as HTTPHeaders, u as TRPCLink } from "./types-BG-3kpeg.mjs";
|
|
2
|
+
import { t as HTTPLinkBaseOptions } from "./httpUtils-gZ7bAQ6T.mjs";
|
|
3
3
|
import { AnyClientTypes } from "@trpc/server/unstable-core-do-not-import";
|
|
4
4
|
import { AnyRouter as AnyRouter$1 } from "@trpc/server";
|
|
5
|
-
//#region src/links/HTTPBatchLinkOptions.d.ts
|
|
6
5
|
/**
|
|
7
6
|
* The options of `httpBatchLink`.
|
|
8
7
|
* @see https://trpc.io/docs/client/links/httpBatchLink#options
|
|
@@ -32,8 +31,6 @@ type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TR
|
|
|
32
31
|
*/
|
|
33
32
|
maxItems?: number;
|
|
34
33
|
};
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region src/links/httpBatchLink.d.ts
|
|
37
34
|
/**
|
|
38
35
|
* A terminating link that batches calls made in the same tick into one HTTP
|
|
39
36
|
* request.
|
|
@@ -41,6 +38,5 @@ type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TR
|
|
|
41
38
|
* @see https://trpc.io/docs/client/links/httpBatchLink
|
|
42
39
|
*/
|
|
43
40
|
declare function httpBatchLink<TRouter extends AnyRouter$1>(opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
|
|
44
|
-
//#endregion
|
|
45
41
|
export { HTTPBatchLinkOptions as n, httpBatchLink as t };
|
|
46
|
-
//# sourceMappingURL=httpBatchLink-
|
|
42
|
+
//# sourceMappingURL=httpBatchLink-Dk3_n5pP.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpBatchLink-Dk3_n5pP.d.mts","names":["AnyRouter"],"sources":["../src/links/HTTPBatchLinkOptions.ts","../src/links/httpBatchLink.ts"],"mappings":";;;;;;;;KASY,qBAAqB,cAAc,kBAC7C,oBAAoB;;;;;;;;EAQlB;;;;;;EAMA,UACI,gBACE;IACA,QAAQ,cAAc;QAClB,cAAc,QAAQ;;;;;;;EAQhC;;;;;;;;iBCVY,cAAc,gBAAgBA,aAC5C,MAAM,qBAAqB,wCAC1B,SAAS"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as TRPCClientError } from "./TRPCClientError-
|
|
3
|
-
import {
|
|
1
|
+
import { a as jsonHttpRequester, i as httpRequest, o as resolveHTTPLinkOptions, r as getUrl, u as raceAbortSignalsWithCleanup } from "./httpUtils-CWtyfi2N.mjs";
|
|
2
|
+
import { t as TRPCClientError } from "./TRPCClientError-DE6-fd1n.mjs";
|
|
3
|
+
import { t as _objectSpread2 } from "./objectSpread2-pyA4QVO4.mjs";
|
|
4
4
|
import { observable } from "@trpc/server/observable";
|
|
5
5
|
import { transformResult } from "@trpc/server/unstable-core-do-not-import";
|
|
6
|
-
|
|
6
|
+
// src/links/internals/contentTypes.ts
|
|
7
7
|
/** Whether an input is binary: a `Uint8Array`, `Blob` or `File`. */
|
|
8
8
|
function isOctetType(input) {
|
|
9
9
|
return input instanceof Uint8Array || input instanceof Blob;
|
|
@@ -20,8 +20,7 @@ function isFormData(input) {
|
|
|
20
20
|
function isNonJsonSerializable(input) {
|
|
21
21
|
return isOctetType(input) || isFormData(input);
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
//#region src/links/httpLink.ts
|
|
23
|
+
// src/links/httpLink.ts
|
|
25
24
|
const universalRequester = (opts) => {
|
|
26
25
|
if ("input" in opts) {
|
|
27
26
|
const { input } = opts;
|
|
@@ -104,7 +103,6 @@ function httpLink(opts) {
|
|
|
104
103
|
};
|
|
105
104
|
};
|
|
106
105
|
}
|
|
107
|
-
//#endregion
|
|
108
106
|
export { isOctetType as i, isFormData as n, isNonJsonSerializable as r, httpLink as t };
|
|
109
107
|
|
|
110
|
-
//# sourceMappingURL=httpLink-
|
|
108
|
+
//# sourceMappingURL=httpLink-B7uIfNkv.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpLink-
|
|
1
|
+
{"version":3,"file":"httpLink-B7uIfNkv.mjs","names":[],"sources":["../src/links/internals/contentTypes.ts","../src/links/httpLink.ts"],"sourcesContent":["/** Whether an input is binary: a `Uint8Array`, `Blob` or `File`. */\nexport 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\n/** Whether an input is `FormData`. */\nexport function isFormData(input: unknown) {\n return input instanceof FormData;\n}\n\n/**\n * Whether an input can't be sent as JSON: binary data or `FormData`. Use\n * it in a `splitLink` to send such inputs with `httpLink`.\n * @see https://trpc.io/docs/server/non-json-content-types#client-setup\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 { raceAbortSignalsWithCleanup } 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\n/**\n * The options of `httpLink`.\n * @see https://trpc.io/docs/client/links/httpLink#httplink-options\n */\nexport type HTTPLinkOptions<TRoot extends AnyClientTypes> =\n HTTPLinkBaseOptions<TRoot> & {\n /**\n * Headers for each request: an object, or a function of the operation\n * that returns them.\n * @see https://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 * A terminating link that sends each call in its own HTTP request. It can\n * send `FormData` and binary inputs.\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 { signal, cleanup } = raceAbortSignalsWithCleanup(\n op.signal,\n ac.signal,\n );\n let request: Promise<HTTPResult>;\n try {\n request = universalRequester({\n ...resolvedOpts,\n type,\n path,\n input,\n 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 } catch (cause) {\n cleanup();\n throw cause;\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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AAA,GACL,YAAA,GAAA,CAAA,GAAA;MACH;MACA;MACA;MACA;MACA,UAAU;OACR,IAAI,CAAC,KAAK,SACR,OAAO,CAAC;OAEV,IAAI,OAAO,KAAK,YAAY,YAC1B,OAAO,KAAK,QAAQ,EAClB,GACF,CAAC;OAEH,OAAO,KAAK;MACd;KACF,CAAA,CAAC;IACH,SAAS,OAAO;KACd,QAAQ;KACR,MAAM;IACR;IACA,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;KAEX,QAAQ;IACV;GACF,CAAC;EACH;CACF;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as
|
|
1
|
+
import { t as HTTPLinkBaseOptions } from "./httpUtils-gZ7bAQ6T.mjs";
|
|
2
|
+
import { n as Operation, t as HTTPHeaders, u as TRPCLink } from "./types-BG-3kpeg.mjs";
|
|
3
3
|
import { AnyClientTypes, AnyRouter } from "@trpc/server/unstable-core-do-not-import";
|
|
4
|
-
//#region src/links/httpLink.d.ts
|
|
5
4
|
/**
|
|
6
5
|
* The options of `httpLink`.
|
|
7
6
|
* @see https://trpc.io/docs/client/links/httpLink#httplink-options
|
|
@@ -22,6 +21,5 @@ type HTTPLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TRoot>
|
|
|
22
21
|
* @see https://trpc.io/docs/client/links/httpLink
|
|
23
22
|
*/
|
|
24
23
|
declare function httpLink<TRouter extends AnyRouter = AnyRouter>(opts: HTTPLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
|
|
25
|
-
//#endregion
|
|
26
24
|
export { httpLink as n, HTTPLinkOptions as t };
|
|
27
|
-
//# sourceMappingURL=httpLink-
|
|
25
|
+
//# sourceMappingURL=httpLink-BjZdBzr6.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpLink-BjZdBzr6.d.mts","names":[],"sources":["../src/links/httpLink.ts"],"mappings":";;;;;;;KA+BY,gBAAgB,cAAc,kBACxC,oBAAoB;;;;;;EAMlB,UACI,gBACE;IAAQ,IAAI;QAAgB,cAAc,QAAQ;;;;;;;iBA0C5C,SAAS,gBAAgB,YAAY,WACnD,MAAM,gBAAgB,wCACrB,SAAS"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
const
|
|
2
|
-
const require_TRPCClientError = require("./TRPCClientError-
|
|
3
|
-
const
|
|
1
|
+
const require_httpUtils = require("./httpUtils-ZrQjZ1_i.cjs");
|
|
2
|
+
const require_TRPCClientError = require("./TRPCClientError-irOPxS6c.cjs");
|
|
3
|
+
const require_objectSpread2 = require("./objectSpread2-Xm0br5eL.cjs");
|
|
4
4
|
let _trpc_server_observable = require("@trpc/server/observable");
|
|
5
5
|
let _trpc_server_unstable_core_do_not_import = require("@trpc/server/unstable-core-do-not-import");
|
|
6
|
-
|
|
6
|
+
// src/links/internals/contentTypes.ts
|
|
7
7
|
/** Whether an input is binary: a `Uint8Array`, `Blob` or `File`. */
|
|
8
8
|
function isOctetType(input) {
|
|
9
9
|
return input instanceof Uint8Array || input instanceof Blob;
|
|
@@ -20,8 +20,7 @@ function isFormData(input) {
|
|
|
20
20
|
function isNonJsonSerializable(input) {
|
|
21
21
|
return isOctetType(input) || isFormData(input);
|
|
22
22
|
}
|
|
23
|
-
|
|
24
|
-
//#region src/links/httpLink.ts
|
|
23
|
+
// src/links/httpLink.ts
|
|
25
24
|
const universalRequester = (opts) => {
|
|
26
25
|
if ("input" in opts) {
|
|
27
26
|
const { input } = opts;
|
|
@@ -104,7 +103,6 @@ function httpLink(opts) {
|
|
|
104
103
|
};
|
|
105
104
|
};
|
|
106
105
|
}
|
|
107
|
-
//#endregion
|
|
108
106
|
Object.defineProperty(exports, "httpLink", {
|
|
109
107
|
enumerable: true,
|
|
110
108
|
get: function() {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as _objectSpread2 } from "./objectSpread2-
|
|
1
|
+
import { t as _objectSpread2 } from "./objectSpread2-pyA4QVO4.mjs";
|
|
2
2
|
import { getTransformer } from "./unstable-internals.mjs";
|
|
3
3
|
import { procedurePathToURLPath, resolvePathSeparator } from "@trpc/server/unstable-core-do-not-import";
|
|
4
|
-
|
|
4
|
+
// src/getFetch.ts
|
|
5
5
|
const isFunction = (fn) => typeof fn === "function";
|
|
6
6
|
/**
|
|
7
7
|
* The `fetch` to use: `customFetchImpl` if given, or else the global one.
|
|
@@ -13,8 +13,7 @@ function getFetch(customFetchImpl) {
|
|
|
13
13
|
if (typeof globalThis !== "undefined" && isFunction(globalThis.fetch)) return globalThis.fetch;
|
|
14
14
|
throw new Error("No fetch implementation found");
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
//#region src/internals/signals.ts
|
|
16
|
+
// src/internals/signals.ts
|
|
18
17
|
/**
|
|
19
18
|
* Like `Promise.all()` but for abort signals
|
|
20
19
|
* - When all signals have been aborted, the merged signal will be aborted
|
|
@@ -72,8 +71,7 @@ function abortSignalToPromise(signal) {
|
|
|
72
71
|
}, { once: true });
|
|
73
72
|
});
|
|
74
73
|
}
|
|
75
|
-
|
|
76
|
-
//#region src/links/internals/httpUtils.ts
|
|
74
|
+
// src/links/internals/httpUtils.ts
|
|
77
75
|
function resolveHTTPLinkOptions(opts) {
|
|
78
76
|
return {
|
|
79
77
|
url: opts.url.toString(),
|
|
@@ -178,7 +176,6 @@ async function httpRequest(opts) {
|
|
|
178
176
|
meta
|
|
179
177
|
};
|
|
180
178
|
}
|
|
181
|
-
//#endregion
|
|
182
179
|
export { jsonHttpRequester as a, allAbortSignals as c, getFetch as d, httpRequest as i, raceAbortSignals as l, getBody as n, resolveHTTPLinkOptions as o, getUrl as r, abortSignalToPromise as s, fetchHTTPResponse as t, raceAbortSignalsWithCleanup as u };
|
|
183
180
|
|
|
184
|
-
//# sourceMappingURL=httpUtils-
|
|
181
|
+
//# sourceMappingURL=httpUtils-CWtyfi2N.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpUtils-5Hmhcy-z.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\n/**\n * The `fetch` to use: `customFetchImpl` if given, or else the global one.\n * Throws if there's none.\n */\nexport function getFetch(\n customFetchImpl?: FetchEsque | NativeFetchEsque,\n): FetchEsque {\n if (customFetchImpl) {\n return customFetchImpl as FetchEsque;\n }\n\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 return raceAbortSignalsWithCleanup(...signals).signal;\n}\n\n// Completion can release input listeners without aborting a consumed response.\nexport function raceAbortSignalsWithCleanup(...signals: Maybe<AbortSignal>[]) {\n const ac = new AbortController();\n const cleanup = () => {\n for (const signal of signals) {\n signal?.removeEventListener('abort', onAbort);\n }\n };\n const onAbort = () => {\n cleanup();\n ac.abort();\n };\n\n for (const signal of signals) {\n if (signal?.aborted) {\n onAbort();\n break;\n }\n signal?.addEventListener('abort', onAbort, { once: true });\n }\n\n return { signal: ac.signal, cleanup };\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 PathSeparator,\n ProcedureType,\n TRPCAcceptHeader,\n TRPCResponse,\n} from '@trpc/server/unstable-core-do-not-import';\nimport {\n procedurePathToURLPath,\n resolvePathSeparator,\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 * The options every HTTP link takes.\n * @internal\n */\nexport type HTTPLinkBaseOptions<\n TRoot extends Pick<AnyClientTypes, 'transformer'>,\n> = {\n /** The URL of your tRPC endpoint, such as `http://localhost:3000/trpc`. */\n url: string | URL;\n /**\n * The `fetch` to use, if not the global one.\n */\n fetch?: FetchEsque;\n /**\n * Sends every call as a POST, whatever its type. The server must set\n * `allowMethodOverride: true`.\n * @see https://trpc.io/docs/rpc#overriding-the-default-http-method\n */\n methodOverride?: 'POST';\n /**\n * The character between a procedure path's segments in URLs. Must match\n * the server's `pathSeparator`.\n * @default '.'\n * @see https://trpc.io/docs/rpc#path-separator\n */\n pathSeparator?: PathSeparator;\n} & TransformerOptions<TRoot>;\n\nexport interface ResolvedHTTPLinkOptions {\n url: string;\n fetch?: FetchEsque;\n transformer: CombinedDataTransformer;\n methodOverride?: 'POST';\n pathSeparator: PathSeparator;\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 pathSeparator: resolvePathSeparator(opts.pathSeparator),\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 + '/' + procedurePathToURLPath(opts.path, opts.pathSeparator);\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 // Header names are case-insensitive, so a `Content-Type` set by the caller\n // replaces ours instead of being sent alongside it\n const hasContentType = Object.keys(resolvedHeaders).some(\n (key) => key.toLowerCase() === 'content-type',\n );\n const headers = {\n ...(opts.contentTypeHeader && method !== 'GET' && !hasContentType\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":";;;;AAIA,MAAM,cAAc,OAA6B,OAAO,OAAO;;;;;AAM/D,SAAgB,SACd,iBACY;CACZ,IAAI,iBACF,OAAO;CAGT,IAAI,OAAO,WAAW,eAAe,WAAW,OAAO,KAAK,GAC1D,OAAO,OAAO,MAAM,KAAK,MAAM;CAGjC,IAAI,OAAO,eAAe,eAAe,WAAW,WAAW,KAAK,GAClE,OAAO,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,CAAC,CAAA,GACD,KAAK,mBACL,IAAA,wBAAG,KAAK,yBAAA,QAAA,0BAAA,KAAA,IAAA,wBAAuB,gBAAgB,KAAK,iBAAiB,IACrE,KAAA,CAAA,GACD,eACL;CAEA,OAAO,SAAS,KAAK,KAAK,CAAC,CAAC,KAAK;EAC/B;EACA,QAAQ,KAAK;EACb;EACA;CACF,CAAC;AACH;AAEA,eAAsB,YACpB,MACqB;CACrB,MAAM,OAAO,CAAC;CAEd,MAAM,MAAM,MAAM,kBAAkB,IAAI;CACxC,KAAK,WAAW;CAEhB,MAAM,OAAO,MAAM,IAAI,KAAK;CAE5B,KAAK,eAAe;CAEpB,OAAO;EACC;EACN;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"httpUtils-CWtyfi2N.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\n/**\n * The `fetch` to use: `customFetchImpl` if given, or else the global one.\n * Throws if there's none.\n */\nexport function getFetch(\n customFetchImpl?: FetchEsque | NativeFetchEsque,\n): FetchEsque {\n if (customFetchImpl) {\n return customFetchImpl as FetchEsque;\n }\n\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 return raceAbortSignalsWithCleanup(...signals).signal;\n}\n\n// Completion can release input listeners without aborting a consumed response.\nexport function raceAbortSignalsWithCleanup(...signals: Maybe<AbortSignal>[]) {\n const ac = new AbortController();\n const cleanup = () => {\n for (const signal of signals) {\n signal?.removeEventListener('abort', onAbort);\n }\n };\n const onAbort = () => {\n cleanup();\n ac.abort();\n };\n\n for (const signal of signals) {\n if (signal?.aborted) {\n onAbort();\n break;\n }\n signal?.addEventListener('abort', onAbort, { once: true });\n }\n\n return { signal: ac.signal, cleanup };\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 PathSeparator,\n ProcedureType,\n TRPCAcceptHeader,\n TRPCResponse,\n} from '@trpc/server/unstable-core-do-not-import';\nimport {\n procedurePathToURLPath,\n resolvePathSeparator,\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 * The options every HTTP link takes.\n * @internal\n */\nexport type HTTPLinkBaseOptions<\n TRoot extends Pick<AnyClientTypes, 'transformer'>,\n> = {\n /** The URL of your tRPC endpoint, such as `http://localhost:3000/trpc`. */\n url: string | URL;\n /**\n * The `fetch` to use, if not the global one.\n */\n fetch?: FetchEsque;\n /**\n * Sends every call as a POST, whatever its type. The server must set\n * `allowMethodOverride: true`.\n * @see https://trpc.io/docs/rpc#overriding-the-default-http-method\n */\n methodOverride?: 'POST';\n /**\n * The character between a procedure path's segments in URLs. Must match\n * the server's `pathSeparator`.\n * @default '.'\n * @see https://trpc.io/docs/rpc#path-separator\n */\n pathSeparator?: PathSeparator;\n} & TransformerOptions<TRoot>;\n\nexport interface ResolvedHTTPLinkOptions {\n url: string;\n fetch?: FetchEsque;\n transformer: CombinedDataTransformer;\n methodOverride?: 'POST';\n pathSeparator: PathSeparator;\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 pathSeparator: resolvePathSeparator(opts.pathSeparator),\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 + '/' + procedurePathToURLPath(opts.path, opts.pathSeparator);\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 // Header names are case-insensitive, so a `Content-Type` set by the caller\n // replaces ours instead of being sent alongside it\n const hasContentType = Object.keys(resolvedHeaders).some(\n (key) => key.toLowerCase() === 'content-type',\n );\n const headers = {\n ...(opts.contentTypeHeader && method !== 'GET' && !hasContentType\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":";;;;AAIA,MAAM,cAAc,OAA6B,OAAO,OAAO;;;;;AAM/D,SAAgB,SACd,iBACY;CACZ,IAAI,iBACF,OAAO;CAGT,IAAI,OAAO,WAAW,eAAe,WAAW,OAAO,KAAK,GAC1D,OAAO,OAAO,MAAM,KAAK,MAAM;CAGjC,IAAI,OAAO,eAAe,eAAe,WAAW,WAAW,KAAK,GAClE,OAA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,CAAC,CAAA,GACD,KAAK,mBACL,IAAA,wBAAG,KAAK,yBAAA,QAAA,0BAAA,KAAA,IAAA,wBAAuB,gBAAgB,KAAK,iBAAiB,IACrE,KAAA,CAAA,GACD,eACL;CAEA,OAAO,SAAS,KAAK,KAAK,CAAC,CAAC,KAAK;EAC/B;EACA,QAAQ,KAAK;EACb;EACA;CACF,CAAC;AACH;AAEA,eAAsB,YACpB,MACqB;CACrB,MAAM,OAAO,CAAC;CAEd,MAAM,MAAM,MAAM,kBAAkB,IAAI;CACxC,KAAK,WAAW;CAEhB,MAAM,OAAO,MAAM,IAAI,KAAK;CAE5B,KAAK,eAAe;CAEpB,OAAO;EACC;EACN;CACF;AACF"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { AnyClientTypes,
|
|
4
|
-
//#region src/links/internals/httpUtils.d.ts
|
|
1
|
+
import { v as FetchEsque } from "./types-BhHxuBsu.cjs";
|
|
2
|
+
import { TransformerOptions } from "./unstable-internals.cjs";
|
|
3
|
+
import { AnyClientTypes, PathSeparator } from "@trpc/server/unstable-core-do-not-import";
|
|
5
4
|
/**
|
|
6
5
|
* The options every HTTP link takes.
|
|
7
6
|
* @internal
|
|
@@ -27,6 +26,5 @@ type HTTPLinkBaseOptions<TRoot extends Pick<AnyClientTypes, 'transformer'>> = {
|
|
|
27
26
|
*/
|
|
28
27
|
pathSeparator?: PathSeparator;
|
|
29
28
|
} & TransformerOptions<TRoot>;
|
|
30
|
-
//#endregion
|
|
31
29
|
export { HTTPLinkBaseOptions as t };
|
|
32
|
-
//# sourceMappingURL=httpUtils-
|
|
30
|
+
//# sourceMappingURL=httpUtils-CxgZ3W-1.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpUtils-CxgZ3W-1.d.cts","names":[],"sources":["../src/links/internals/httpUtils.ts"],"mappings":";;;;;;;KA2BY,oBACV,cAAc,KAAK;;EAGnB,cAAc;;;;EAId,QAAQ;;;;;;EAMR;;;;;;;EAOA,gBAAgB;IACd,mBAAmB"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
const require_objectSpread2 = require("./objectSpread2-
|
|
1
|
+
const require_objectSpread2 = require("./objectSpread2-Xm0br5eL.cjs");
|
|
2
2
|
const require_unstable_internals = require("./unstable-internals.cjs");
|
|
3
3
|
let _trpc_server_unstable_core_do_not_import = require("@trpc/server/unstable-core-do-not-import");
|
|
4
|
-
|
|
4
|
+
// src/getFetch.ts
|
|
5
5
|
const isFunction = (fn) => typeof fn === "function";
|
|
6
6
|
/**
|
|
7
7
|
* The `fetch` to use: `customFetchImpl` if given, or else the global one.
|
|
@@ -13,8 +13,7 @@ function getFetch(customFetchImpl) {
|
|
|
13
13
|
if (typeof globalThis !== "undefined" && isFunction(globalThis.fetch)) return globalThis.fetch;
|
|
14
14
|
throw new Error("No fetch implementation found");
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
//#region src/internals/signals.ts
|
|
16
|
+
// src/internals/signals.ts
|
|
18
17
|
/**
|
|
19
18
|
* Like `Promise.all()` but for abort signals
|
|
20
19
|
* - When all signals have been aborted, the merged signal will be aborted
|
|
@@ -72,8 +71,7 @@ function abortSignalToPromise(signal) {
|
|
|
72
71
|
}, { once: true });
|
|
73
72
|
});
|
|
74
73
|
}
|
|
75
|
-
|
|
76
|
-
//#region src/links/internals/httpUtils.ts
|
|
74
|
+
// src/links/internals/httpUtils.ts
|
|
77
75
|
function resolveHTTPLinkOptions(opts) {
|
|
78
76
|
return {
|
|
79
77
|
url: opts.url.toString(),
|
|
@@ -178,7 +176,6 @@ async function httpRequest(opts) {
|
|
|
178
176
|
meta
|
|
179
177
|
};
|
|
180
178
|
}
|
|
181
|
-
//#endregion
|
|
182
179
|
Object.defineProperty(exports, "abortSignalToPromise", {
|
|
183
180
|
enumerable: true,
|
|
184
181
|
get: function() {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { h as FetchEsque } from "./types-
|
|
2
|
-
import { n as TransformerOptions } from "./unstable-internals-
|
|
3
|
-
import { AnyClientTypes,
|
|
4
|
-
//#region src/links/internals/httpUtils.d.ts
|
|
1
|
+
import { h as FetchEsque } from "./types-BG-3kpeg.mjs";
|
|
2
|
+
import { n as TransformerOptions } from "./unstable-internals-CnrO49lh.mjs";
|
|
3
|
+
import { AnyClientTypes, PathSeparator } from "@trpc/server/unstable-core-do-not-import";
|
|
5
4
|
/**
|
|
6
5
|
* The options every HTTP link takes.
|
|
7
6
|
* @internal
|
|
@@ -27,6 +26,5 @@ type HTTPLinkBaseOptions<TRoot extends Pick<AnyClientTypes, 'transformer'>> = {
|
|
|
27
26
|
*/
|
|
28
27
|
pathSeparator?: PathSeparator;
|
|
29
28
|
} & TransformerOptions<TRoot>;
|
|
30
|
-
//#endregion
|
|
31
29
|
export { HTTPLinkBaseOptions as t };
|
|
32
|
-
//# sourceMappingURL=httpUtils-
|
|
30
|
+
//# sourceMappingURL=httpUtils-gZ7bAQ6T.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpUtils-gZ7bAQ6T.d.mts","names":[],"sources":["../src/links/internals/httpUtils.ts"],"mappings":";;;;;;;KA2BY,oBACV,cAAc,KAAK;;EAGnB,cAAc;;;;EAId,QAAQ;;;;;;EAMR;;;;;;;EAOA,gBAAgB;IACd,mBAAmB"}
|