@trpc/client 11.23.0 → 11.23.1-canary.14.507382d73
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-CxFRO7Js.mjs → TRPCClientError-Byo7P4QG.mjs} +14 -1
- package/dist/TRPCClientError-Byo7P4QG.mjs.map +1 -0
- package/dist/{TRPCClientError-CmHlBkPF.cjs → TRPCClientError-CPEwAI4E.cjs} +13 -0
- package/dist/{httpBatchLink-DPypDRI1.mjs → httpBatchLink-B-gQhW2d.mjs} +6 -3
- package/dist/httpBatchLink-B-gQhW2d.mjs.map +1 -0
- package/dist/httpBatchLink-CRRfyw0c.d.cts +46 -0
- package/dist/httpBatchLink-CRRfyw0c.d.cts.map +1 -0
- package/dist/httpBatchLink-DFDg8cHu.d.mts +46 -0
- package/dist/httpBatchLink-DFDg8cHu.d.mts.map +1 -0
- package/dist/{httpBatchLink-Cmao5uUF.cjs → httpBatchLink-DfpTwHVx.cjs} +5 -2
- package/dist/{httpLink-eSAq8J9S.d.mts → httpLink-Bc4oLWCJ.d.cts} +12 -5
- package/dist/httpLink-Bc4oLWCJ.d.cts.map +1 -0
- package/dist/{httpLink-B6E1HSLY.cjs → httpLink-CTrye8t0.cjs} +11 -2
- package/dist/{httpLink--yqaZ9lA.mjs → httpLink-D1jF9wdN.mjs} +12 -3
- package/dist/httpLink-D1jF9wdN.mjs.map +1 -0
- package/dist/{httpLink-D5FQijY2.d.cts → httpLink-yX9QPwni.d.mts} +12 -5
- package/dist/httpLink-yX9QPwni.d.mts.map +1 -0
- package/dist/httpUtils-j-oJ4G4z.d.cts +25 -0
- package/dist/httpUtils-j-oJ4G4z.d.cts.map +1 -0
- package/dist/{httpUtils-CrSF2CZF.cjs → httpUtils-os0q2Zvy.cjs} +4 -0
- package/dist/{httpUtils-CAZsqwOQ.mjs → httpUtils-ttfajAo5.mjs} +5 -1
- package/dist/httpUtils-ttfajAo5.mjs.map +1 -0
- package/dist/httpUtils-v7O5xeam.d.mts +25 -0
- package/dist/httpUtils-v7O5xeam.d.mts.map +1 -0
- package/dist/index.cjs +55 -16
- package/dist/index.d.cts +150 -26
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +150 -26
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +55 -16
- 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 -1
- package/dist/links/httpLink.cjs +1 -1
- package/dist/links/httpLink.d.cts +1 -1
- package/dist/links/httpLink.d.mts +1 -1
- package/dist/links/httpLink.mjs +1 -1
- package/dist/links/loggerLink.cjs +4 -1
- package/dist/links/loggerLink.d.cts +1 -1
- package/dist/links/loggerLink.d.mts +1 -1
- package/dist/links/loggerLink.mjs +4 -1
- package/dist/links/loggerLink.mjs.map +1 -1
- package/dist/links/splitLink.cjs +1 -1
- package/dist/links/splitLink.d.cts +1 -1
- package/dist/links/splitLink.d.mts +1 -1
- package/dist/links/splitLink.mjs +1 -1
- 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 -1
- package/dist/{loggerLink-CFercTVc.d.mts → loggerLink-BEMtA7V5.d.cts} +20 -4
- package/dist/loggerLink-BEMtA7V5.d.cts.map +1 -0
- package/dist/{loggerLink-2o-uZ3r1.d.cts → loggerLink-Daki_B65.d.mts} +20 -4
- package/dist/loggerLink-Daki_B65.d.mts.map +1 -0
- package/dist/{splitLink-MXnaFlEb.cjs → splitLink-CL8W2Mit.cjs} +5 -0
- package/dist/{splitLink-BZPioDdG.mjs → splitLink-DcpFI5s5.mjs} +6 -1
- package/dist/splitLink-DcpFI5s5.mjs.map +1 -0
- package/dist/{splitLink-CJdcmEmS.d.cts → splitLink-i7EskO_m.d.cts} +10 -2
- package/dist/splitLink-i7EskO_m.d.cts.map +1 -0
- package/dist/{splitLink-CixmF14P.d.mts → splitLink-zyV5y7N1.d.mts} +10 -2
- package/dist/splitLink-zyV5y7N1.d.mts.map +1 -0
- package/dist/{types-BxbMkv6C.d.cts → types-BrCJd1zp.d.cts} +54 -6
- package/dist/types-BrCJd1zp.d.cts.map +1 -0
- package/dist/{types-CAPs7vhA.d.mts → types-DO-GCB2q.d.mts} +54 -6
- package/dist/types-DO-GCB2q.d.mts.map +1 -0
- package/dist/{unstable-internals-CE8gFBQ9.d.cts → unstable-internals-CNoyg7Yf.d.cts} +4 -4
- package/dist/{unstable-internals-CE8gFBQ9.d.cts.map → unstable-internals-CNoyg7Yf.d.cts.map} +1 -1
- package/dist/{unstable-internals-CE8gFBQ9.d.mts → unstable-internals-CNoyg7Yf.d.mts} +4 -4
- package/dist/{unstable-internals-CE8gFBQ9.d.mts.map → unstable-internals-CNoyg7Yf.d.mts.map} +1 -1
- package/dist/unstable-internals.d.cts +1 -1
- package/dist/unstable-internals.d.mts +1 -1
- package/dist/unstable-internals.mjs.map +1 -1
- package/dist/{wsLink-CQGBu_VZ.cjs → wsLink-Bl27m-y2.cjs} +18 -1
- package/dist/{wsLink--7trqYPG.mjs → wsLink-CDaUjHvu.mjs} +19 -2
- package/dist/wsLink-CDaUjHvu.mjs.map +1 -0
- package/dist/{wsLink-DnvK9sTv.d.mts → wsLink-CEgNu9Gj.d.mts} +39 -5
- package/dist/wsLink-CEgNu9Gj.d.mts.map +1 -0
- package/dist/{wsLink-C3hsDLsL.d.cts → wsLink-DZr_cFFg.d.cts} +39 -5
- package/dist/wsLink-DZr_cFFg.d.cts.map +1 -0
- package/package.json +4 -4
- package/skills/client-setup/SKILL.md +1 -1
- package/skills/links/SKILL.md +1 -1
- package/skills/superjson/SKILL.md +1 -1
- package/src/TRPCClientError.ts +27 -2
- package/src/createTRPCClient.ts +38 -7
- package/src/createTRPCUntypedClient.ts +4 -0
- package/src/getFetch.ts +4 -0
- package/src/internals/TRPCUntypedClient.ts +33 -2
- package/src/internals/transformer.ts +3 -3
- package/src/internals/types.ts +9 -1
- package/src/links/HTTPBatchLinkOptions.ts +17 -3
- package/src/links/httpBatchLink.ts +3 -0
- package/src/links/httpBatchStreamLink.ts +10 -1
- package/src/links/httpLink.ts +9 -2
- package/src/links/httpSubscriptionLink.ts +10 -3
- package/src/links/internals/contentTypes.ts +7 -0
- package/src/links/internals/httpUtils.ts +6 -4
- package/src/links/internals/urlWithConnectionParams.ts +1 -0
- package/src/links/localLink.ts +22 -3
- package/src/links/loggerLink.ts +18 -2
- package/src/links/retryLink.ts +4 -1
- package/src/links/splitLink.ts +8 -0
- package/src/links/types.ts +17 -2
- package/src/links/wsLink/createWsClient.ts +9 -0
- package/src/links/wsLink/wsClient/encoder.ts +3 -0
- package/src/links/wsLink/wsClient/options.ts +7 -2
- package/src/links/wsLink/wsClient/wsClient.ts +3 -0
- package/src/links/wsLink/wsLink.ts +13 -0
- package/src/safe.ts +11 -2
- package/dist/TRPCClientError-CxFRO7Js.mjs.map +0 -1
- package/dist/httpBatchLink-Br-pzPXf.d.cts +0 -29
- package/dist/httpBatchLink-Br-pzPXf.d.cts.map +0 -1
- package/dist/httpBatchLink-DPypDRI1.mjs.map +0 -1
- package/dist/httpBatchLink-nvc48L_N.d.mts +0 -29
- package/dist/httpBatchLink-nvc48L_N.d.mts.map +0 -1
- package/dist/httpLink--yqaZ9lA.mjs.map +0 -1
- package/dist/httpLink-D5FQijY2.d.cts.map +0 -1
- package/dist/httpLink-eSAq8J9S.d.mts.map +0 -1
- package/dist/httpUtils-C37jRVnj.d.mts +0 -23
- package/dist/httpUtils-C37jRVnj.d.mts.map +0 -1
- package/dist/httpUtils-CAZsqwOQ.mjs.map +0 -1
- package/dist/httpUtils-CUqAubVD.d.cts +0 -23
- package/dist/httpUtils-CUqAubVD.d.cts.map +0 -1
- package/dist/loggerLink-2o-uZ3r1.d.cts.map +0 -1
- package/dist/loggerLink-CFercTVc.d.mts.map +0 -1
- package/dist/splitLink-BZPioDdG.mjs.map +0 -1
- package/dist/splitLink-CJdcmEmS.d.cts.map +0 -1
- package/dist/splitLink-CixmF14P.d.mts.map +0 -1
- package/dist/types-BxbMkv6C.d.cts.map +0 -1
- package/dist/types-CAPs7vhA.d.mts.map +0 -1
- package/dist/wsLink--7trqYPG.mjs.map +0 -1
- package/dist/wsLink-C3hsDLsL.d.cts.map +0 -1
- package/dist/wsLink-DnvK9sTv.d.mts.map +0 -1
|
@@ -1,6 +1,10 @@
|
|
|
1
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
3
|
//#region src/TRPCClientError.ts
|
|
4
|
+
/**
|
|
5
|
+
* Whether a value is a `TRPCClientError`, typed for a router or procedure.
|
|
6
|
+
* @see https://trpc.io/docs/client/vanilla/error-handling#catching-a-thrown-error
|
|
7
|
+
*/
|
|
4
8
|
function isTRPCClientError(cause) {
|
|
5
9
|
return cause instanceof TRPCClientError;
|
|
6
10
|
}
|
|
@@ -12,6 +16,11 @@ function getMessageFromUnknownError(err, fallback) {
|
|
|
12
16
|
if (isObject(err) && typeof err["message"] === "string") return err["message"];
|
|
13
17
|
return fallback;
|
|
14
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* The error a client call throws, whether the server sent an error or the
|
|
21
|
+
* request failed.
|
|
22
|
+
* @see https://trpc.io/docs/client/vanilla/error-handling
|
|
23
|
+
*/
|
|
15
24
|
var TRPCClientError = class TRPCClientError extends Error {
|
|
16
25
|
constructor(message, opts) {
|
|
17
26
|
var _opts$result, _opts$result2;
|
|
@@ -28,6 +37,10 @@ var TRPCClientError = class TRPCClientError extends Error {
|
|
|
28
37
|
this.name = "TRPCClientError";
|
|
29
38
|
Object.setPrototypeOf(this, TRPCClientError.prototype);
|
|
30
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Turns an error response, an `Error` or another object into a
|
|
42
|
+
* `TRPCClientError`. A `TRPCClientError` is returned as it is.
|
|
43
|
+
*/
|
|
31
44
|
static from(_cause, opts = {}) {
|
|
32
45
|
const cause = _cause;
|
|
33
46
|
if (isTRPCClientError(cause)) {
|
|
@@ -44,4 +57,4 @@ var TRPCClientError = class TRPCClientError extends Error {
|
|
|
44
57
|
//#endregion
|
|
45
58
|
export { isTRPCClientError as n, TRPCClientError as t };
|
|
46
59
|
|
|
47
|
-
//# sourceMappingURL=TRPCClientError-
|
|
60
|
+
//# sourceMappingURL=TRPCClientError-Byo7P4QG.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TRPCClientError-Byo7P4QG.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,10 @@
|
|
|
1
1
|
const require_objectSpread2 = require("./objectSpread2-D-dJi1gK.cjs");
|
|
2
2
|
let _trpc_server_unstable_core_do_not_import = require("@trpc/server/unstable-core-do-not-import");
|
|
3
3
|
//#region src/TRPCClientError.ts
|
|
4
|
+
/**
|
|
5
|
+
* Whether a value is a `TRPCClientError`, typed for a router or procedure.
|
|
6
|
+
* @see https://trpc.io/docs/client/vanilla/error-handling#catching-a-thrown-error
|
|
7
|
+
*/
|
|
4
8
|
function isTRPCClientError(cause) {
|
|
5
9
|
return cause instanceof TRPCClientError;
|
|
6
10
|
}
|
|
@@ -12,6 +16,11 @@ function getMessageFromUnknownError(err, fallback) {
|
|
|
12
16
|
if ((0, _trpc_server_unstable_core_do_not_import.isObject)(err) && typeof err["message"] === "string") return err["message"];
|
|
13
17
|
return fallback;
|
|
14
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* The error a client call throws, whether the server sent an error or the
|
|
21
|
+
* request failed.
|
|
22
|
+
* @see https://trpc.io/docs/client/vanilla/error-handling
|
|
23
|
+
*/
|
|
15
24
|
var TRPCClientError = class TRPCClientError extends Error {
|
|
16
25
|
constructor(message, opts) {
|
|
17
26
|
var _opts$result, _opts$result2;
|
|
@@ -28,6 +37,10 @@ var TRPCClientError = class TRPCClientError extends Error {
|
|
|
28
37
|
this.name = "TRPCClientError";
|
|
29
38
|
Object.setPrototypeOf(this, TRPCClientError.prototype);
|
|
30
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Turns an error response, an `Error` or another object into a
|
|
42
|
+
* `TRPCClientError`. A `TRPCClientError` is returned as it is.
|
|
43
|
+
*/
|
|
31
44
|
static from(_cause, opts = {}) {
|
|
32
45
|
const cause = _cause;
|
|
33
46
|
if (isTRPCClientError(cause)) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as _objectSpread2 } from "./objectSpread2-weooBxVk.mjs";
|
|
2
|
-
import { t as TRPCClientError } from "./TRPCClientError-
|
|
3
|
-
import { a as jsonHttpRequester, c as allAbortSignals, l as raceAbortSignals, o as resolveHTTPLinkOptions, r as getUrl } from "./httpUtils-
|
|
2
|
+
import { t as TRPCClientError } from "./TRPCClientError-Byo7P4QG.mjs";
|
|
3
|
+
import { a as jsonHttpRequester, c as allAbortSignals, l as raceAbortSignals, o as resolveHTTPLinkOptions, r as getUrl } from "./httpUtils-ttfajAo5.mjs";
|
|
4
4
|
import { observable } from "@trpc/server/observable";
|
|
5
5
|
import { transformResult } from "@trpc/server/unstable-core-do-not-import";
|
|
6
6
|
//#region src/internals/dataLoader.ts
|
|
@@ -114,6 +114,9 @@ function dataLoader(batchLoader) {
|
|
|
114
114
|
//#endregion
|
|
115
115
|
//#region src/links/httpBatchLink.ts
|
|
116
116
|
/**
|
|
117
|
+
* A terminating link that batches calls made in the same tick into one HTTP
|
|
118
|
+
* request.
|
|
119
|
+
*
|
|
117
120
|
* @see https://trpc.io/docs/client/links/httpBatchLink
|
|
118
121
|
*/
|
|
119
122
|
function httpBatchLink(opts) {
|
|
@@ -197,4 +200,4 @@ function httpBatchLink(opts) {
|
|
|
197
200
|
//#endregion
|
|
198
201
|
export { dataLoader as n, httpBatchLink as t };
|
|
199
202
|
|
|
200
|
-
//# sourceMappingURL=httpBatchLink-
|
|
203
|
+
//# sourceMappingURL=httpBatchLink-B-gQhW2d.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpBatchLink-B-gQhW2d.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 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 * 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 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,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I,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;IAEb;GACF,CAAC;EACH;CACF;AACF"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { _ as NonEmptyArray, n as Operation, t as HTTPHeaders, u as TRPCLink } from "./types-BrCJd1zp.cjs";
|
|
2
|
+
import { t as HTTPLinkBaseOptions } from "./httpUtils-j-oJ4G4z.cjs";
|
|
3
|
+
import { AnyClientTypes } from "@trpc/server/unstable-core-do-not-import";
|
|
4
|
+
import { AnyRouter as AnyRouter$1 } from "@trpc/server";
|
|
5
|
+
//#region src/links/HTTPBatchLinkOptions.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* The options of `httpBatchLink`.
|
|
8
|
+
* @see https://trpc.io/docs/client/links/httpBatchLink#options
|
|
9
|
+
*/
|
|
10
|
+
type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TRoot> & {
|
|
11
|
+
/**
|
|
12
|
+
* The longest URL a batched GET request can have. Calls that would
|
|
13
|
+
* make it longer go in another batch. A call too long on its own
|
|
14
|
+
* fails.
|
|
15
|
+
* @see https://trpc.io/docs/client/links/httpBatchLink#setting-a-maximum-url-length
|
|
16
|
+
* @default Infinity
|
|
17
|
+
*/
|
|
18
|
+
maxURLLength?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Headers for each request: an object, or a function of the batch's
|
|
21
|
+
* operations that returns them.
|
|
22
|
+
* @see https://trpc.io/docs/client/headers
|
|
23
|
+
*/
|
|
24
|
+
headers?: HTTPHeaders | ((opts: {
|
|
25
|
+
opList: NonEmptyArray<Operation>;
|
|
26
|
+
}) => HTTPHeaders | Promise<HTTPHeaders>);
|
|
27
|
+
/**
|
|
28
|
+
* The most calls one batch can have. Set it to the server's
|
|
29
|
+
* `maxBatchSize` or lower.
|
|
30
|
+
* @see https://trpc.io/docs/client/links/httpBatchLink#limiting-batch-size
|
|
31
|
+
* @default Infinity
|
|
32
|
+
*/
|
|
33
|
+
maxItems?: number;
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/links/httpBatchLink.d.ts
|
|
37
|
+
/**
|
|
38
|
+
* A terminating link that batches calls made in the same tick into one HTTP
|
|
39
|
+
* request.
|
|
40
|
+
*
|
|
41
|
+
* @see https://trpc.io/docs/client/links/httpBatchLink
|
|
42
|
+
*/
|
|
43
|
+
declare function httpBatchLink<TRouter extends AnyRouter$1>(opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { HTTPBatchLinkOptions as n, httpBatchLink as t };
|
|
46
|
+
//# sourceMappingURL=httpBatchLink-CRRfyw0c.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpBatchLink-CRRfyw0c.d.cts","names":[],"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;;;;;;;;;;iBCbY,cAAc,gBAAgB,aAC5C,MAAM,qBAAqB,wCAC1B,SAAS"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { _ as NonEmptyArray, n as Operation, t as HTTPHeaders, u as TRPCLink } from "./types-DO-GCB2q.mjs";
|
|
2
|
+
import { t as HTTPLinkBaseOptions } from "./httpUtils-v7O5xeam.mjs";
|
|
3
|
+
import { AnyClientTypes } from "@trpc/server/unstable-core-do-not-import";
|
|
4
|
+
import { AnyRouter as AnyRouter$1 } from "@trpc/server";
|
|
5
|
+
//#region src/links/HTTPBatchLinkOptions.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* The options of `httpBatchLink`.
|
|
8
|
+
* @see https://trpc.io/docs/client/links/httpBatchLink#options
|
|
9
|
+
*/
|
|
10
|
+
type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TRoot> & {
|
|
11
|
+
/**
|
|
12
|
+
* The longest URL a batched GET request can have. Calls that would
|
|
13
|
+
* make it longer go in another batch. A call too long on its own
|
|
14
|
+
* fails.
|
|
15
|
+
* @see https://trpc.io/docs/client/links/httpBatchLink#setting-a-maximum-url-length
|
|
16
|
+
* @default Infinity
|
|
17
|
+
*/
|
|
18
|
+
maxURLLength?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Headers for each request: an object, or a function of the batch's
|
|
21
|
+
* operations that returns them.
|
|
22
|
+
* @see https://trpc.io/docs/client/headers
|
|
23
|
+
*/
|
|
24
|
+
headers?: HTTPHeaders | ((opts: {
|
|
25
|
+
opList: NonEmptyArray<Operation>;
|
|
26
|
+
}) => HTTPHeaders | Promise<HTTPHeaders>);
|
|
27
|
+
/**
|
|
28
|
+
* The most calls one batch can have. Set it to the server's
|
|
29
|
+
* `maxBatchSize` or lower.
|
|
30
|
+
* @see https://trpc.io/docs/client/links/httpBatchLink#limiting-batch-size
|
|
31
|
+
* @default Infinity
|
|
32
|
+
*/
|
|
33
|
+
maxItems?: number;
|
|
34
|
+
};
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/links/httpBatchLink.d.ts
|
|
37
|
+
/**
|
|
38
|
+
* A terminating link that batches calls made in the same tick into one HTTP
|
|
39
|
+
* request.
|
|
40
|
+
*
|
|
41
|
+
* @see https://trpc.io/docs/client/links/httpBatchLink
|
|
42
|
+
*/
|
|
43
|
+
declare function httpBatchLink<TRouter extends AnyRouter$1>(opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { HTTPBatchLinkOptions as n, httpBatchLink as t };
|
|
46
|
+
//# sourceMappingURL=httpBatchLink-DFDg8cHu.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpBatchLink-DFDg8cHu.d.mts","names":[],"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;;;;;;;;;;iBCbY,cAAc,gBAAgB,aAC5C,MAAM,qBAAqB,wCAC1B,SAAS"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_objectSpread2 = require("./objectSpread2-D-dJi1gK.cjs");
|
|
2
|
-
const require_TRPCClientError = require("./TRPCClientError-
|
|
3
|
-
const require_httpUtils = require("./httpUtils-
|
|
2
|
+
const require_TRPCClientError = require("./TRPCClientError-CPEwAI4E.cjs");
|
|
3
|
+
const require_httpUtils = require("./httpUtils-os0q2Zvy.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
|
//#region src/internals/dataLoader.ts
|
|
@@ -114,6 +114,9 @@ function dataLoader(batchLoader) {
|
|
|
114
114
|
//#endregion
|
|
115
115
|
//#region src/links/httpBatchLink.ts
|
|
116
116
|
/**
|
|
117
|
+
* A terminating link that batches calls made in the same tick into one HTTP
|
|
118
|
+
* request.
|
|
119
|
+
*
|
|
117
120
|
* @see https://trpc.io/docs/client/links/httpBatchLink
|
|
118
121
|
*/
|
|
119
122
|
function httpBatchLink(opts) {
|
|
@@ -1,20 +1,27 @@
|
|
|
1
|
-
import { n as Operation, t as HTTPHeaders, u as TRPCLink } from "./types-
|
|
2
|
-
import { t as HTTPLinkBaseOptions } from "./httpUtils-
|
|
1
|
+
import { n as Operation, t as HTTPHeaders, u as TRPCLink } from "./types-BrCJd1zp.cjs";
|
|
2
|
+
import { t as HTTPLinkBaseOptions } from "./httpUtils-j-oJ4G4z.cjs";
|
|
3
3
|
import { AnyClientTypes, AnyRouter } from "@trpc/server/unstable-core-do-not-import";
|
|
4
4
|
//#region src/links/httpLink.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The options of `httpLink`.
|
|
7
|
+
* @see https://trpc.io/docs/client/links/httpLink#httplink-options
|
|
8
|
+
*/
|
|
5
9
|
type HTTPLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TRoot> & {
|
|
6
10
|
/**
|
|
7
|
-
* Headers
|
|
8
|
-
*
|
|
11
|
+
* Headers for each request: an object, or a function of the operation
|
|
12
|
+
* that returns them.
|
|
13
|
+
* @see https://trpc.io/docs/client/headers
|
|
9
14
|
*/
|
|
10
15
|
headers?: HTTPHeaders | ((opts: {
|
|
11
16
|
op: Operation;
|
|
12
17
|
}) => HTTPHeaders | Promise<HTTPHeaders>);
|
|
13
18
|
};
|
|
14
19
|
/**
|
|
20
|
+
* A terminating link that sends each call in its own HTTP request. It can
|
|
21
|
+
* send `FormData` and binary inputs.
|
|
15
22
|
* @see https://trpc.io/docs/client/links/httpLink
|
|
16
23
|
*/
|
|
17
24
|
declare function httpLink<TRouter extends AnyRouter = AnyRouter>(opts: HTTPLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
|
|
18
25
|
//#endregion
|
|
19
26
|
export { httpLink as n, HTTPLinkOptions as t };
|
|
20
|
-
//# sourceMappingURL=httpLink-
|
|
27
|
+
//# sourceMappingURL=httpLink-Bc4oLWCJ.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpLink-Bc4oLWCJ.d.cts","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,15 +1,22 @@
|
|
|
1
1
|
const require_objectSpread2 = require("./objectSpread2-D-dJi1gK.cjs");
|
|
2
|
-
const require_TRPCClientError = require("./TRPCClientError-
|
|
3
|
-
const require_httpUtils = require("./httpUtils-
|
|
2
|
+
const require_TRPCClientError = require("./TRPCClientError-CPEwAI4E.cjs");
|
|
3
|
+
const require_httpUtils = require("./httpUtils-os0q2Zvy.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
|
//#region src/links/internals/contentTypes.ts
|
|
7
|
+
/** Whether an input is binary: a `Uint8Array`, `Blob` or `File`. */
|
|
7
8
|
function isOctetType(input) {
|
|
8
9
|
return input instanceof Uint8Array || input instanceof Blob;
|
|
9
10
|
}
|
|
11
|
+
/** Whether an input is `FormData`. */
|
|
10
12
|
function isFormData(input) {
|
|
11
13
|
return input instanceof FormData;
|
|
12
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Whether an input can't be sent as JSON: binary data or `FormData`. Use
|
|
17
|
+
* it in a `splitLink` to send such inputs with `httpLink`.
|
|
18
|
+
* @see https://trpc.io/docs/server/non-json-content-types#client-setup
|
|
19
|
+
*/
|
|
13
20
|
function isNonJsonSerializable(input) {
|
|
14
21
|
return isOctetType(input) || isFormData(input);
|
|
15
22
|
}
|
|
@@ -38,6 +45,8 @@ const universalRequester = (opts) => {
|
|
|
38
45
|
return require_httpUtils.jsonHttpRequester(opts);
|
|
39
46
|
};
|
|
40
47
|
/**
|
|
48
|
+
* A terminating link that sends each call in its own HTTP request. It can
|
|
49
|
+
* send `FormData` and binary inputs.
|
|
41
50
|
* @see https://trpc.io/docs/client/links/httpLink
|
|
42
51
|
*/
|
|
43
52
|
function httpLink(opts) {
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { t as _objectSpread2 } from "./objectSpread2-weooBxVk.mjs";
|
|
2
|
-
import { t as TRPCClientError } from "./TRPCClientError-
|
|
3
|
-
import { a as jsonHttpRequester, i as httpRequest, l as raceAbortSignals, o as resolveHTTPLinkOptions, r as getUrl } from "./httpUtils-
|
|
2
|
+
import { t as TRPCClientError } from "./TRPCClientError-Byo7P4QG.mjs";
|
|
3
|
+
import { a as jsonHttpRequester, i as httpRequest, l as raceAbortSignals, o as resolveHTTPLinkOptions, r as getUrl } from "./httpUtils-ttfajAo5.mjs";
|
|
4
4
|
import { observable } from "@trpc/server/observable";
|
|
5
5
|
import { transformResult } from "@trpc/server/unstable-core-do-not-import";
|
|
6
6
|
//#region src/links/internals/contentTypes.ts
|
|
7
|
+
/** Whether an input is binary: a `Uint8Array`, `Blob` or `File`. */
|
|
7
8
|
function isOctetType(input) {
|
|
8
9
|
return input instanceof Uint8Array || input instanceof Blob;
|
|
9
10
|
}
|
|
11
|
+
/** Whether an input is `FormData`. */
|
|
10
12
|
function isFormData(input) {
|
|
11
13
|
return input instanceof FormData;
|
|
12
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Whether an input can't be sent as JSON: binary data or `FormData`. Use
|
|
17
|
+
* it in a `splitLink` to send such inputs with `httpLink`.
|
|
18
|
+
* @see https://trpc.io/docs/server/non-json-content-types#client-setup
|
|
19
|
+
*/
|
|
13
20
|
function isNonJsonSerializable(input) {
|
|
14
21
|
return isOctetType(input) || isFormData(input);
|
|
15
22
|
}
|
|
@@ -38,6 +45,8 @@ const universalRequester = (opts) => {
|
|
|
38
45
|
return jsonHttpRequester(opts);
|
|
39
46
|
};
|
|
40
47
|
/**
|
|
48
|
+
* A terminating link that sends each call in its own HTTP request. It can
|
|
49
|
+
* send `FormData` and binary inputs.
|
|
41
50
|
* @see https://trpc.io/docs/client/links/httpLink
|
|
42
51
|
*/
|
|
43
52
|
function httpLink(opts) {
|
|
@@ -90,4 +99,4 @@ function httpLink(opts) {
|
|
|
90
99
|
//#endregion
|
|
91
100
|
export { isOctetType as i, isFormData as n, isNonJsonSerializable as r, httpLink as t };
|
|
92
101
|
|
|
93
|
-
//# sourceMappingURL=httpLink
|
|
102
|
+
//# sourceMappingURL=httpLink-D1jF9wdN.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpLink-D1jF9wdN.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 { raceAbortSignals } from '../internals/signals';\nimport { TRPCClientError } from '../TRPCClientError';\nimport type {\n HTTPLinkBaseOptions,\n HTTPResult,\n Requester,\n} from './internals/httpUtils';\nimport {\n getUrl,\n httpRequest,\n jsonHttpRequester,\n resolveHTTPLinkOptions,\n} from './internals/httpUtils';\nimport {\n isFormData,\n isOctetType,\n type HTTPHeaders,\n type Operation,\n type TRPCLink,\n} from './types';\n\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 request = universalRequester({\n ...resolvedOpts,\n type,\n path,\n input,\n signal: raceAbortSignals(op.signal, ac.signal),\n headers() {\n if (!opts.headers) {\n return {};\n }\n if (typeof opts.headers === 'function') {\n return opts.headers({\n op,\n });\n }\n return opts.headers;\n },\n });\n let isDone = false;\n let meta: HTTPResult['meta'] | undefined = undefined;\n request\n .then((res) => {\n isDone = true;\n meta = res.meta;\n const transformed = transformResult(\n res.json,\n resolvedOpts.transformer.output,\n );\n\n if (!transformed.ok) {\n observer.error(\n TRPCClientError.from(transformed.error, {\n meta,\n }),\n );\n return;\n }\n observer.next({\n context: res.meta,\n result: transformed.result,\n });\n observer.complete();\n })\n .catch((cause) => {\n isDone = true;\n observer.error(TRPCClientError.from(cause, { meta }));\n });\n\n return () => {\n if (!isDone) {\n ac.abort();\n }\n };\n });\n };\n };\n}\n"],"mappings":";;;;;;;AACA,SAAgB,YACd,OACyC;CACzC,OACE,iBAAiB,cAEjB,iBAAiB;AAErB;;AAGA,SAAgB,WAAW,OAAgB;CACzC,OAAO,iBAAiB;AAC1B;;;;;;AAOA,SAAgB,sBAAsB,OAAgB;CACpD,OAAO,YAAY,KAAK,KAAK,WAAW,KAAK;AAC/C;;;ACoBA,MAAM,sBAAiC,SAAS;CAC9C,IAAI,WAAW,MAAM;EACnB,MAAM,EAAE,UAAU;EAClB,IAAI,WAAW,KAAK,GAAG;GACrB,IAAI,KAAK,SAAS,cAAc,KAAK,mBAAmB,QACtD,MAAM,IAAI,MAAM,0CAA0C;GAG5D,OAAO,YAAA,eAAA,eAAA,CAAA,GACF,IAAA,GAAA,CAAA,GAAA;IAEH,mBAAmB,KAAA;IACnB;IACA,eAAe;GACjB,CAAA,CAAC;EACH;EAEA,IAAI,YAAY,KAAK,GAAG;GACtB,IAAI,KAAK,SAAS,cAAc,KAAK,mBAAmB,QACtD,MAAM,IAAI,MAAM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Eb;GACF,CAAC;EACH;CACF;AACF"}
|
|
@@ -1,20 +1,27 @@
|
|
|
1
|
-
import { n as Operation, t as HTTPHeaders, u as TRPCLink } from "./types-
|
|
2
|
-
import { t as HTTPLinkBaseOptions } from "./httpUtils-
|
|
1
|
+
import { n as Operation, t as HTTPHeaders, u as TRPCLink } from "./types-DO-GCB2q.mjs";
|
|
2
|
+
import { t as HTTPLinkBaseOptions } from "./httpUtils-v7O5xeam.mjs";
|
|
3
3
|
import { AnyClientTypes, AnyRouter } from "@trpc/server/unstable-core-do-not-import";
|
|
4
4
|
//#region src/links/httpLink.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The options of `httpLink`.
|
|
7
|
+
* @see https://trpc.io/docs/client/links/httpLink#httplink-options
|
|
8
|
+
*/
|
|
5
9
|
type HTTPLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TRoot> & {
|
|
6
10
|
/**
|
|
7
|
-
* Headers
|
|
8
|
-
*
|
|
11
|
+
* Headers for each request: an object, or a function of the operation
|
|
12
|
+
* that returns them.
|
|
13
|
+
* @see https://trpc.io/docs/client/headers
|
|
9
14
|
*/
|
|
10
15
|
headers?: HTTPHeaders | ((opts: {
|
|
11
16
|
op: Operation;
|
|
12
17
|
}) => HTTPHeaders | Promise<HTTPHeaders>);
|
|
13
18
|
};
|
|
14
19
|
/**
|
|
20
|
+
* A terminating link that sends each call in its own HTTP request. It can
|
|
21
|
+
* send `FormData` and binary inputs.
|
|
15
22
|
* @see https://trpc.io/docs/client/links/httpLink
|
|
16
23
|
*/
|
|
17
24
|
declare function httpLink<TRouter extends AnyRouter = AnyRouter>(opts: HTTPLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
|
|
18
25
|
//#endregion
|
|
19
26
|
export { httpLink as n, HTTPLinkOptions as t };
|
|
20
|
-
//# sourceMappingURL=httpLink-
|
|
27
|
+
//# sourceMappingURL=httpLink-yX9QPwni.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpLink-yX9QPwni.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"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { h as FetchEsque } from "./types-BrCJd1zp.cjs";
|
|
2
|
+
import { n as TransformerOptions } from "./unstable-internals-CNoyg7Yf.cjs";
|
|
3
|
+
import { AnyClientTypes, CombinedDataTransformer, Maybe, ProcedureType } from "@trpc/server/unstable-core-do-not-import";
|
|
4
|
+
//#region src/links/internals/httpUtils.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The options every HTTP link takes.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
type HTTPLinkBaseOptions<TRoot extends Pick<AnyClientTypes, 'transformer'>> = {
|
|
10
|
+
/** The URL of your tRPC endpoint, such as `http://localhost:3000/trpc`. */
|
|
11
|
+
url: string | URL;
|
|
12
|
+
/**
|
|
13
|
+
* The `fetch` to use, if not the global one.
|
|
14
|
+
*/
|
|
15
|
+
fetch?: FetchEsque;
|
|
16
|
+
/**
|
|
17
|
+
* Sends every call as a POST, whatever its type. The server must set
|
|
18
|
+
* `allowMethodOverride: true`.
|
|
19
|
+
* @see https://trpc.io/docs/rpc#overriding-the-default-http-method
|
|
20
|
+
*/
|
|
21
|
+
methodOverride?: 'POST';
|
|
22
|
+
} & TransformerOptions<TRoot>;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { HTTPLinkBaseOptions as t };
|
|
25
|
+
//# sourceMappingURL=httpUtils-j-oJ4G4z.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpUtils-j-oJ4G4z.d.cts","names":[],"sources":["../src/links/internals/httpUtils.ts"],"mappings":";;;;;;;;KAsBY,oBACV,cAAc,KAAK;;EAGnB,cAAc;;;;EAId,QAAQ;;;;;;EAMR;IACE,mBAAmB"}
|
|
@@ -2,6 +2,10 @@ const require_objectSpread2 = require("./objectSpread2-D-dJi1gK.cjs");
|
|
|
2
2
|
const require_unstable_internals = require("./unstable-internals.cjs");
|
|
3
3
|
//#region src/getFetch.ts
|
|
4
4
|
const isFunction = (fn) => typeof fn === "function";
|
|
5
|
+
/**
|
|
6
|
+
* The `fetch` to use: `customFetchImpl` if given, or else the global one.
|
|
7
|
+
* Throws if there's none.
|
|
8
|
+
*/
|
|
5
9
|
function getFetch(customFetchImpl) {
|
|
6
10
|
if (customFetchImpl) return customFetchImpl;
|
|
7
11
|
if (typeof window !== "undefined" && isFunction(window.fetch)) return window.fetch.bind(window);
|
|
@@ -2,6 +2,10 @@ import { t as _objectSpread2 } from "./objectSpread2-weooBxVk.mjs";
|
|
|
2
2
|
import { getTransformer } from "./unstable-internals.mjs";
|
|
3
3
|
//#region src/getFetch.ts
|
|
4
4
|
const isFunction = (fn) => typeof fn === "function";
|
|
5
|
+
/**
|
|
6
|
+
* The `fetch` to use: `customFetchImpl` if given, or else the global one.
|
|
7
|
+
* Throws if there's none.
|
|
8
|
+
*/
|
|
5
9
|
function getFetch(customFetchImpl) {
|
|
6
10
|
if (customFetchImpl) return customFetchImpl;
|
|
7
11
|
if (typeof window !== "undefined" && isFunction(window.fetch)) return window.fetch.bind(window);
|
|
@@ -157,4 +161,4 @@ async function httpRequest(opts) {
|
|
|
157
161
|
//#endregion
|
|
158
162
|
export { jsonHttpRequester as a, allAbortSignals as c, httpRequest as i, raceAbortSignals as l, getBody as n, resolveHTTPLinkOptions as o, getUrl as r, abortSignalToPromise as s, fetchHTTPResponse as t, getFetch as u };
|
|
159
163
|
|
|
160
|
-
//# sourceMappingURL=httpUtils-
|
|
164
|
+
//# sourceMappingURL=httpUtils-ttfajAo5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpUtils-ttfajAo5.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 const ac = new AbortController();\n\n for (const signal of signals) {\n if (signal?.aborted) {\n ac.abort();\n } else {\n signal?.addEventListener('abort', () => ac.abort(), { once: true });\n }\n }\n\n return ac.signal;\n}\n\nexport function abortSignalToPromise(signal: AbortSignal): Promise<never> {\n return new Promise((_, reject) => {\n if (signal.aborted) {\n reject(signal.reason);\n return;\n }\n signal.addEventListener(\n 'abort',\n () => {\n reject(signal.reason);\n },\n { once: true },\n );\n });\n}\n","import type {\n AnyClientTypes,\n CombinedDataTransformer,\n Maybe,\n ProcedureType,\n TRPCAcceptHeader,\n TRPCResponse,\n} from '@trpc/server/unstable-core-do-not-import';\nimport { getFetch } from '../../getFetch';\nimport type {\n FetchEsque,\n RequestInitEsque,\n ResponseEsque,\n} from '../../internals/types';\nimport type { TransformerOptions } from '../../unstable-internals';\nimport { getTransformer } from '../../unstable-internals';\nimport type { HTTPHeaders } from '../types';\n\n/**\n * 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} & TransformerOptions<TRoot>;\n\nexport interface ResolvedHTTPLinkOptions {\n url: string;\n fetch?: FetchEsque;\n transformer: CombinedDataTransformer;\n methodOverride?: 'POST';\n}\n\nexport function resolveHTTPLinkOptions(\n opts: HTTPLinkBaseOptions<AnyClientTypes>,\n): ResolvedHTTPLinkOptions {\n return {\n url: opts.url.toString(),\n fetch: opts.fetch,\n transformer: getTransformer(opts.transformer),\n methodOverride: opts.methodOverride,\n };\n}\n\n// https://github.com/trpc/trpc/pull/669\nfunction arrayToDict(array: unknown[]) {\n const dict: Record<number, unknown> = {};\n for (let index = 0; index < array.length; index++) {\n const element = array[index];\n dict[index] = element;\n }\n return dict;\n}\n\nconst METHOD = {\n query: 'GET',\n mutation: 'POST',\n subscription: 'PATCH',\n} as const;\n\nexport interface HTTPResult {\n json: TRPCResponse;\n meta: {\n response: ResponseEsque;\n responseJSON?: unknown;\n };\n}\n\ntype GetInputOptions = {\n transformer: CombinedDataTransformer;\n} & ({ input: unknown } | { inputs: unknown[] });\n\nexport function getInput(opts: GetInputOptions) {\n return 'input' in opts\n ? opts.transformer.input.serialize(opts.input)\n : arrayToDict(\n opts.inputs.map((_input) => opts.transformer.input.serialize(_input)),\n );\n}\n\nexport type HTTPBaseRequestOptions = GetInputOptions &\n ResolvedHTTPLinkOptions & {\n type: ProcedureType;\n path: string;\n signal: Maybe<AbortSignal>;\n };\n\ntype GetUrl = (opts: HTTPBaseRequestOptions) => string;\ntype GetBody = (opts: HTTPBaseRequestOptions) => RequestInitEsque['body'];\n\nexport type ContentOptions = {\n trpcAcceptHeader?: TRPCAcceptHeader;\n trpcAcceptHeaderKey?: 'trpc-accept' | 'accept';\n contentTypeHeader?: string;\n getUrl: GetUrl;\n getBody: GetBody;\n};\n\nexport const getUrl: GetUrl = (opts) => {\n const parts = opts.url.split('?') as [string, string?];\n const base = parts[0].replace(/\\/$/, ''); // Remove any trailing slashes\n\n let url = base + '/' + opts.path;\n const queryParts: string[] = [];\n\n if (parts[1]) {\n queryParts.push(parts[1]);\n }\n if ('inputs' in opts) {\n queryParts.push('batch=1');\n }\n if (opts.type === 'query' || opts.type === 'subscription') {\n const input = getInput(opts);\n if (input !== undefined && opts.methodOverride !== 'POST') {\n queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`);\n }\n }\n if (queryParts.length) {\n url += '?' + queryParts.join('&');\n }\n return url;\n};\n\nexport const getBody: GetBody = (opts) => {\n if (opts.type === 'query' && opts.methodOverride !== 'POST') {\n return undefined;\n }\n const input = getInput(opts);\n return input !== undefined ? JSON.stringify(input) : undefined;\n};\n\nexport type Requester = (\n opts: HTTPBaseRequestOptions & {\n headers: () => HTTPHeaders | Promise<HTTPHeaders>;\n },\n) => Promise<HTTPResult>;\n\nexport const jsonHttpRequester: Requester = (opts) => {\n return httpRequest({\n ...opts,\n contentTypeHeader: 'application/json',\n getUrl,\n getBody,\n });\n};\n\n/**\n * Polyfill for DOMException with AbortError name\n */\nclass AbortError extends Error {\n constructor() {\n const name = 'AbortError';\n super(name);\n this.name = name;\n this.message = name;\n }\n}\n\nexport type HTTPRequestOptions = ContentOptions &\n HTTPBaseRequestOptions & {\n headers: () => HTTPHeaders | Promise<HTTPHeaders>;\n };\n\n/**\n * Polyfill for `signal.throwIfAborted()`\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/throwIfAborted\n */\nconst throwIfAborted = (signal: Maybe<AbortSignal>) => {\n if (!signal?.aborted) {\n return;\n }\n // If available, use the native implementation\n signal.throwIfAborted?.();\n\n // If we have `DOMException`, use it\n if (typeof DOMException !== 'undefined') {\n throw new DOMException('AbortError', 'AbortError');\n }\n\n // Otherwise, use our own implementation\n throw new AbortError();\n};\n\nexport async function fetchHTTPResponse(opts: HTTPRequestOptions) {\n throwIfAborted(opts.signal);\n\n const url = opts.getUrl(opts);\n const body = opts.getBody(opts);\n const method = opts.methodOverride ?? METHOD[opts.type];\n const resolvedHeaders = await (async () => {\n const heads = await opts.headers();\n if (Symbol.iterator in heads) {\n return Object.fromEntries(heads);\n }\n return heads;\n })();\n // 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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AAK,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"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { h as FetchEsque } from "./types-DO-GCB2q.mjs";
|
|
2
|
+
import { n as TransformerOptions } from "./unstable-internals-CNoyg7Yf.mjs";
|
|
3
|
+
import { AnyClientTypes, CombinedDataTransformer, Maybe, ProcedureType } from "@trpc/server/unstable-core-do-not-import";
|
|
4
|
+
//#region src/links/internals/httpUtils.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* The options every HTTP link takes.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
type HTTPLinkBaseOptions<TRoot extends Pick<AnyClientTypes, 'transformer'>> = {
|
|
10
|
+
/** The URL of your tRPC endpoint, such as `http://localhost:3000/trpc`. */
|
|
11
|
+
url: string | URL;
|
|
12
|
+
/**
|
|
13
|
+
* The `fetch` to use, if not the global one.
|
|
14
|
+
*/
|
|
15
|
+
fetch?: FetchEsque;
|
|
16
|
+
/**
|
|
17
|
+
* Sends every call as a POST, whatever its type. The server must set
|
|
18
|
+
* `allowMethodOverride: true`.
|
|
19
|
+
* @see https://trpc.io/docs/rpc#overriding-the-default-http-method
|
|
20
|
+
*/
|
|
21
|
+
methodOverride?: 'POST';
|
|
22
|
+
} & TransformerOptions<TRoot>;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { HTTPLinkBaseOptions as t };
|
|
25
|
+
//# sourceMappingURL=httpUtils-v7O5xeam.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpUtils-v7O5xeam.d.mts","names":[],"sources":["../src/links/internals/httpUtils.ts"],"mappings":";;;;;;;;KAsBY,oBACV,cAAc,KAAK;;EAGnB,cAAc;;;;EAId,QAAQ;;;;;;EAMR;IACE,mBAAmB"}
|