@trpc/client
Advanced tools
| import { __toESM, require_objectSpread2 } from "./objectSpread2-BvkFp-_Y.mjs"; | ||
| import { TRPCClientError } from "./TRPCClientError-CjKyS10w.mjs"; | ||
| import { getUrl, jsonHttpRequester, resolveHTTPLinkOptions } from "./httpUtils-D61f8fkr.mjs"; | ||
| import { observable } from "@trpc/server/observable"; | ||
| import { transformResult } from "@trpc/server/unstable-core-do-not-import"; | ||
| //#region src/internals/dataLoader.ts | ||
| /** | ||
| * A function that should never be called unless we messed something up. | ||
| */ | ||
| const throwFatalError = () => { | ||
| throw new Error("Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new"); | ||
| }; | ||
| /** | ||
| * Dataloader that's very inspired by https://github.com/graphql/dataloader | ||
| * Less configuration, no caching, and allows you to cancel requests | ||
| * When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled | ||
| */ | ||
| function dataLoader(batchLoader) { | ||
| let pendingItems = null; | ||
| let dispatchTimer = null; | ||
| const destroyTimerAndPendingItems = () => { | ||
| clearTimeout(dispatchTimer); | ||
| dispatchTimer = null; | ||
| pendingItems = null; | ||
| }; | ||
| /** | ||
| * Iterate through the items and split them into groups based on the `batchLoader`'s validate function | ||
| */ | ||
| function groupItems(items) { | ||
| const groupedItems = [[]]; | ||
| let index = 0; | ||
| while (true) { | ||
| const item = items[index]; | ||
| if (!item) break; | ||
| const lastGroup = groupedItems[groupedItems.length - 1]; | ||
| if (item.aborted) { | ||
| var _item$reject; | ||
| (_item$reject = item.reject) === null || _item$reject === void 0 || _item$reject.call(item, new Error("Aborted")); | ||
| index++; | ||
| continue; | ||
| } | ||
| const isValid = batchLoader.validate(lastGroup.concat(item).map((it) => it.key)); | ||
| if (isValid) { | ||
| lastGroup.push(item); | ||
| index++; | ||
| continue; | ||
| } | ||
| if (lastGroup.length === 0) { | ||
| var _item$reject2; | ||
| (_item$reject2 = item.reject) === null || _item$reject2 === void 0 || _item$reject2.call(item, new Error("Input is too big for a single dispatch")); | ||
| index++; | ||
| continue; | ||
| } | ||
| groupedItems.push([]); | ||
| } | ||
| return groupedItems; | ||
| } | ||
| function dispatch() { | ||
| const groupedItems = groupItems(pendingItems); | ||
| destroyTimerAndPendingItems(); | ||
| for (const items of groupedItems) { | ||
| if (!items.length) continue; | ||
| const batch = { items }; | ||
| for (const item of items) item.batch = batch; | ||
| const promise = batchLoader.fetch(batch.items.map((_item) => _item.key)); | ||
| promise.then(async (result) => { | ||
| await Promise.all(result.map(async (valueOrPromise, index) => { | ||
| const item = batch.items[index]; | ||
| try { | ||
| var _item$resolve; | ||
| const value = await Promise.resolve(valueOrPromise); | ||
| (_item$resolve = item.resolve) === null || _item$resolve === void 0 || _item$resolve.call(item, value); | ||
| } catch (cause) { | ||
| var _item$reject3; | ||
| (_item$reject3 = item.reject) === null || _item$reject3 === void 0 || _item$reject3.call(item, cause); | ||
| } | ||
| item.batch = null; | ||
| item.reject = null; | ||
| item.resolve = null; | ||
| })); | ||
| for (const item of batch.items) { | ||
| var _item$reject4; | ||
| (_item$reject4 = item.reject) === null || _item$reject4 === void 0 || _item$reject4.call(item, new Error("Missing result")); | ||
| item.batch = null; | ||
| } | ||
| }).catch((cause) => { | ||
| for (const item of batch.items) { | ||
| var _item$reject5; | ||
| (_item$reject5 = item.reject) === null || _item$reject5 === void 0 || _item$reject5.call(item, cause); | ||
| item.batch = null; | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| function load(key) { | ||
| var _dispatchTimer; | ||
| const item = { | ||
| aborted: false, | ||
| key, | ||
| batch: null, | ||
| resolve: throwFatalError, | ||
| reject: throwFatalError | ||
| }; | ||
| const promise = new Promise((resolve, reject) => { | ||
| var _pendingItems; | ||
| item.reject = reject; | ||
| item.resolve = resolve; | ||
| (_pendingItems = pendingItems) !== null && _pendingItems !== void 0 || (pendingItems = []); | ||
| pendingItems.push(item); | ||
| }); | ||
| (_dispatchTimer = dispatchTimer) !== null && _dispatchTimer !== void 0 || (dispatchTimer = setTimeout(dispatch)); | ||
| return promise; | ||
| } | ||
| return { load }; | ||
| } | ||
| //#endregion | ||
| //#region src/internals/signals.ts | ||
| /** | ||
| * Like `Promise.all()` but for abort signals | ||
| * - When all signals have been aborted, the merged signal will be aborted | ||
| * - If one signal is `null`, no signal will be aborted | ||
| */ | ||
| function allAbortSignals(...signals) { | ||
| const ac = new AbortController(); | ||
| const count = signals.length; | ||
| let abortedCount = 0; | ||
| const onAbort = () => { | ||
| if (++abortedCount === count) ac.abort(); | ||
| }; | ||
| for (const signal of signals) if (signal === null || signal === void 0 ? void 0 : signal.aborted) onAbort(); | ||
| else signal === null || signal === void 0 || signal.addEventListener("abort", onAbort, { once: true }); | ||
| return ac.signal; | ||
| } | ||
| /** | ||
| * Like `Promise.race` but for abort signals | ||
| * | ||
| * Basically, a ponyfill for | ||
| * [`AbortSignal.any`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static). | ||
| */ | ||
| function raceAbortSignals(...signals) { | ||
| const ac = new AbortController(); | ||
| for (const signal of signals) if (signal === null || signal === void 0 ? void 0 : signal.aborted) ac.abort(); | ||
| else signal === null || signal === void 0 || signal.addEventListener("abort", () => ac.abort(), { once: true }); | ||
| return ac.signal; | ||
| } | ||
| function abortSignalToPromise(signal) { | ||
| return new Promise((_, reject) => { | ||
| if (signal.aborted) { | ||
| reject(signal.reason); | ||
| return; | ||
| } | ||
| signal.addEventListener("abort", () => { | ||
| reject(signal.reason); | ||
| }, { once: true }); | ||
| }); | ||
| } | ||
| //#endregion | ||
| //#region src/links/httpBatchLink.ts | ||
| var import_objectSpread2 = __toESM(require_objectSpread2(), 1); | ||
| /** | ||
| * @see https://trpc.io/docs/client/links/httpBatchLink | ||
| */ | ||
| function httpBatchLink(opts) { | ||
| var _opts$maxURLLength, _opts$maxItems; | ||
| const resolvedOpts = resolveHTTPLinkOptions(opts); | ||
| const maxURLLength = (_opts$maxURLLength = opts.maxURLLength) !== null && _opts$maxURLLength !== void 0 ? _opts$maxURLLength : Infinity; | ||
| const maxItems = (_opts$maxItems = opts.maxItems) !== null && _opts$maxItems !== void 0 ? _opts$maxItems : Infinity; | ||
| return () => { | ||
| const batchLoader = (type) => { | ||
| return { | ||
| validate(batchOps) { | ||
| if (maxURLLength === Infinity && maxItems === Infinity) return true; | ||
| if (batchOps.length > maxItems) return false; | ||
| const path = batchOps.map((op) => op.path).join(","); | ||
| const inputs = batchOps.map((op) => op.input); | ||
| const url = getUrl((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, resolvedOpts), {}, { | ||
| type, | ||
| path, | ||
| inputs, | ||
| signal: null | ||
| })); | ||
| return url.length <= maxURLLength; | ||
| }, | ||
| async fetch(batchOps) { | ||
| const path = batchOps.map((op) => op.path).join(","); | ||
| const inputs = batchOps.map((op) => op.input); | ||
| const signal = allAbortSignals(...batchOps.map((op) => op.signal)); | ||
| const res = await jsonHttpRequester((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, resolvedOpts), {}, { | ||
| path, | ||
| inputs, | ||
| type, | ||
| headers() { | ||
| if (!opts.headers) return {}; | ||
| if (typeof opts.headers === "function") return opts.headers({ opList: batchOps }); | ||
| return opts.headers; | ||
| }, | ||
| signal | ||
| })); | ||
| const resJSON = Array.isArray(res.json) ? res.json : batchOps.map(() => res.json); | ||
| const result = resJSON.map((item) => ({ | ||
| meta: res.meta, | ||
| json: item | ||
| })); | ||
| return result; | ||
| } | ||
| }; | ||
| }; | ||
| const query = dataLoader(batchLoader("query")); | ||
| const mutation = dataLoader(batchLoader("mutation")); | ||
| const loaders = { | ||
| query, | ||
| mutation | ||
| }; | ||
| return ({ op }) => { | ||
| return observable((observer) => { | ||
| /* istanbul ignore if -- @preserve */ | ||
| if (op.type === "subscription") throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`"); | ||
| const loader = loaders[op.type]; | ||
| const promise = loader.load(op); | ||
| let _res = void 0; | ||
| promise.then((res) => { | ||
| _res = res; | ||
| const transformed = transformResult(res.json, resolvedOpts.transformer.output); | ||
| if (!transformed.ok) { | ||
| observer.error(TRPCClientError.from(transformed.error, { meta: res.meta })); | ||
| return; | ||
| } | ||
| observer.next({ | ||
| context: res.meta, | ||
| result: transformed.result | ||
| }); | ||
| observer.complete(); | ||
| }).catch((err) => { | ||
| observer.error(TRPCClientError.from(err, { meta: _res === null || _res === void 0 ? void 0 : _res.meta })); | ||
| }); | ||
| return () => {}; | ||
| }); | ||
| }; | ||
| }; | ||
| } | ||
| //#endregion | ||
| export { abortSignalToPromise, allAbortSignals, dataLoader, httpBatchLink, raceAbortSignals }; | ||
| //# sourceMappingURL=httpBatchLink-B2CqKGTi.mjs.map |
| {"version":3,"file":"httpBatchLink-B2CqKGTi.mjs","names":["batchLoader: BatchLoader<TKey, TValue>","pendingItems: BatchItem<TKey, TValue>[] | null","dispatchTimer: ReturnType<typeof setTimeout> | null","items: BatchItem<TKey, TValue>[]","groupedItems: BatchItem<TKey, TValue>[][]","batch: Batch<TKey, TValue>","key: TKey","item: BatchItem<TKey, TValue>","signal: AbortSignal","opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>","type: ProcedureType"],"sources":["../src/internals/dataLoader.ts","../src/internals/signals.ts","../src/links/httpBatchLink.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\ntype BatchItem<TKey, TValue> = {\n aborted: boolean;\n key: TKey;\n resolve: ((value: TValue) => void) | null;\n reject: ((error: Error) => void) | null;\n batch: Batch<TKey, TValue> | null;\n};\ntype Batch<TKey, TValue> = {\n items: BatchItem<TKey, TValue>[];\n};\nexport type BatchLoader<TKey, TValue> = {\n validate: (keys: TKey[]) => boolean;\n fetch: (keys: TKey[]) => Promise<TValue[] | Promise<TValue>[]>;\n};\n\n/**\n * A function that should never be called unless we messed something up.\n */\nconst throwFatalError = () => {\n throw new Error(\n 'Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new',\n );\n};\n\n/**\n * Dataloader that's very inspired by https://github.com/graphql/dataloader\n * Less configuration, no caching, and allows you to cancel requests\n * When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled\n */\nexport function dataLoader<TKey, TValue>(\n batchLoader: BatchLoader<TKey, TValue>,\n) {\n let pendingItems: BatchItem<TKey, TValue>[] | null = null;\n let dispatchTimer: ReturnType<typeof setTimeout> | null = null;\n\n const destroyTimerAndPendingItems = () => {\n clearTimeout(dispatchTimer as any);\n dispatchTimer = null;\n pendingItems = null;\n };\n\n /**\n * Iterate through the items and split them into groups based on the `batchLoader`'s validate function\n */\n function groupItems(items: BatchItem<TKey, TValue>[]) {\n const groupedItems: BatchItem<TKey, TValue>[][] = [[]];\n let index = 0;\n while (true) {\n const item = items[index];\n if (!item) {\n // we're done\n break;\n }\n const lastGroup = groupedItems[groupedItems.length - 1]!;\n\n if (item.aborted) {\n // Item was aborted before it was dispatched\n item.reject?.(new Error('Aborted'));\n index++;\n continue;\n }\n\n const isValid = batchLoader.validate(\n lastGroup.concat(item).map((it) => it.key),\n );\n\n if (isValid) {\n lastGroup.push(item);\n index++;\n continue;\n }\n\n if (lastGroup.length === 0) {\n item.reject?.(new Error('Input is too big for a single dispatch'));\n index++;\n continue;\n }\n // Create new group, next iteration will try to add the item to that\n groupedItems.push([]);\n }\n return groupedItems;\n }\n\n function dispatch() {\n const groupedItems = groupItems(pendingItems!);\n destroyTimerAndPendingItems();\n\n // Create batches for each group of items\n for (const items of groupedItems) {\n if (!items.length) {\n continue;\n }\n const batch: Batch<TKey, TValue> = {\n items,\n };\n for (const item of items) {\n item.batch = batch;\n }\n const promise = batchLoader.fetch(batch.items.map((_item) => _item.key));\n\n promise\n .then(async (result) => {\n await Promise.all(\n result.map(async (valueOrPromise, index) => {\n const item = batch.items[index]!;\n try {\n const value = await Promise.resolve(valueOrPromise);\n\n item.resolve?.(value);\n } catch (cause) {\n item.reject?.(cause as Error);\n }\n\n item.batch = null;\n item.reject = null;\n item.resolve = null;\n }),\n );\n\n for (const item of batch.items) {\n item.reject?.(new Error('Missing result'));\n item.batch = null;\n }\n })\n .catch((cause) => {\n for (const item of batch.items) {\n item.reject?.(cause);\n item.batch = null;\n }\n });\n }\n }\n function load(key: TKey): Promise<TValue> {\n const item: BatchItem<TKey, TValue> = {\n aborted: false,\n key,\n batch: null,\n resolve: throwFatalError,\n reject: throwFatalError,\n };\n\n const promise = new Promise<TValue>((resolve, reject) => {\n item.reject = reject;\n item.resolve = resolve;\n\n pendingItems ??= [];\n pendingItems.push(item);\n });\n\n dispatchTimer ??= setTimeout(dispatch);\n\n return promise;\n }\n\n return {\n load,\n };\n}\n","import type { 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 { 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 } from '../internals/signals';\nimport type { NonEmptyArray } from '../internals/types';\nimport { TRPCClientError } from '../TRPCClientError';\nimport type { HTTPBatchLinkOptions } from './HTTPBatchLinkOptions';\nimport type { HTTPResult } from './internals/httpUtils';\nimport {\n getUrl,\n jsonHttpRequester,\n resolveHTTPLinkOptions,\n} from './internals/httpUtils';\nimport type { Operation, TRPCLink } from './types';\n\n/**\n * @see https://trpc.io/docs/client/links/httpBatchLink\n */\nexport function httpBatchLink<TRouter extends AnyRouter>(\n opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>,\n): TRPCLink<TRouter> {\n const resolvedOpts = resolveHTTPLinkOptions(opts);\n const maxURLLength = opts.maxURLLength ?? Infinity;\n const maxItems = opts.maxItems ?? Infinity;\n\n return () => {\n const batchLoader = (\n type: ProcedureType,\n ): BatchLoader<Operation, HTTPResult> => {\n return {\n validate(batchOps) {\n if (maxURLLength === Infinity && maxItems === Infinity) {\n // escape hatch for quick calcs\n return true;\n }\n if (batchOps.length > maxItems) {\n return false;\n }\n const path = batchOps.map((op) => op.path).join(',');\n const inputs = batchOps.map((op) => op.input);\n\n const url = getUrl({\n ...resolvedOpts,\n type,\n path,\n inputs,\n signal: null,\n });\n\n return url.length <= maxURLLength;\n },\n async fetch(batchOps) {\n const path = batchOps.map((op) => op.path).join(',');\n const inputs = batchOps.map((op) => op.input);\n const signal = allAbortSignals(...batchOps.map((op) => op.signal));\n\n const res = await jsonHttpRequester({\n ...resolvedOpts,\n path,\n inputs,\n type,\n headers() {\n if (!opts.headers) {\n return {};\n }\n if (typeof opts.headers === 'function') {\n return opts.headers({\n opList: batchOps as NonEmptyArray<Operation>,\n });\n }\n return opts.headers;\n },\n signal,\n });\n const resJSON = Array.isArray(res.json)\n ? res.json\n : batchOps.map(() => res.json);\n const result = resJSON.map((item) => ({\n meta: res.meta,\n json: item,\n }));\n return result;\n },\n };\n };\n\n const query = dataLoader(batchLoader('query'));\n const mutation = dataLoader(batchLoader('mutation'));\n\n const loaders = { query, mutation };\n return ({ op }) => {\n return observable((observer) => {\n /* istanbul ignore if -- @preserve */\n if (op.type === 'subscription') {\n throw new Error(\n 'Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`',\n );\n }\n const loader = loaders[op.type];\n const promise = loader.load(op);\n\n let _res = undefined as HTTPResult | undefined;\n promise\n .then((res) => {\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 observer.error(\n TRPCClientError.from(err, {\n meta: _res?.meta,\n }),\n );\n });\n\n return () => {\n // noop\n };\n });\n };\n };\n}\n"],"mappings":";;;;;;;;;;AAoBA,MAAM,kBAAkB,MAAM;AAC5B,OAAM,IAAI,MACR;AAEH;;;;;;AAOD,SAAgB,WACdA,aACA;CACA,IAAIC,eAAiD;CACrD,IAAIC,gBAAsD;CAE1D,MAAM,8BAA8B,MAAM;AACxC,eAAa,cAAqB;AAClC,kBAAgB;AAChB,iBAAe;CAChB;;;;CAKD,SAAS,WAAWC,OAAkC;EACpD,MAAMC,eAA4C,CAAC,CAAE,CAAC;EACtD,IAAI,QAAQ;AACZ,SAAO,MAAM;GACX,MAAM,OAAO,MAAM;AACnB,QAAK,KAEH;GAEF,MAAM,YAAY,aAAa,aAAa,SAAS;AAErD,OAAI,KAAK,SAAS;;AAEhB,yBAAK,+CAAL,wBAAc,IAAI,MAAM,WAAW;AACnC;AACA;GACD;GAED,MAAM,UAAU,YAAY,SAC1B,UAAU,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,GAAG,IAAI,CAC3C;AAED,OAAI,SAAS;AACX,cAAU,KAAK,KAAK;AACpB;AACA;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B,KAAK,YAAY,OAAO,EACtC,MAAM,IAAI,KACX,EAAC,CACH;AACD;KACD;AACD,cAAS,KAAK;MACZ,SAAS,IAAI;MACb,QAAQ,YAAY;KACrB,EAAC;AACF,cAAS,UAAU;IACpB,EAAC,CACD,MAAM,CAAC,QAAQ;AACd,cAAS,MACP,gBAAgB,KAAK,KAAK,EACxB,kDAAM,KAAM,KACb,EAAC,CACH;IACF,EAAC;AAEJ,WAAO,MAAM,CAEZ;GACF,EAAC;EACH;CACF;AACF"} |
| import { HTTPHeaders, NonEmptyArray, Operation, TRPCLink } from "./types.d-CAt1zKAY.mjs"; | ||
| import { HTTPLinkBaseOptions } from "./httpUtils.d-akze5l4u.mjs"; | ||
| import { AnyClientTypes } from "@trpc/server/unstable-core-do-not-import"; | ||
| import { AnyRouter as AnyRouter$1 } from "@trpc/server"; | ||
| //#region src/links/HTTPBatchLinkOptions.d.ts | ||
| type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TRoot> & { | ||
| maxURLLength?: number; | ||
| /** | ||
| * Headers to be set on outgoing requests or a callback that of said headers | ||
| * @see http://trpc.io/docs/client/headers | ||
| */ | ||
| headers?: HTTPHeaders | ((opts: { | ||
| opList: NonEmptyArray<Operation>; | ||
| }) => HTTPHeaders | Promise<HTTPHeaders>); | ||
| /** | ||
| * Maximum number of calls in a single batch request | ||
| * @default Infinity | ||
| */ | ||
| maxItems?: number; | ||
| }; | ||
| //# sourceMappingURL=HTTPBatchLinkOptions.d.ts.map | ||
| //#endregion | ||
| //#region src/links/httpBatchLink.d.ts | ||
| /** | ||
| * @see https://trpc.io/docs/client/links/httpBatchLink | ||
| */ | ||
| declare function httpBatchLink<TRouter extends AnyRouter$1>(opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>; | ||
| //# sourceMappingURL=httpBatchLink.d.ts.map | ||
| //#endregion | ||
| export { HTTPBatchLinkOptions, httpBatchLink }; | ||
| //# sourceMappingURL=httpBatchLink.d-B0jS5RCU.d.mts.map |
| {"version":3,"file":"httpBatchLink.d-B0jS5RCU.d.mts","names":[],"sources":["../src/links/HTTPBatchLinkOptions.ts","../src/links/httpBatchLink.ts"],"sourcesContent":[],"mappings":";;;;;;KAKY,mCAAmC,kBAC7C,oBAAoB;;EADV;;;;EACe,OAAzB,CAAA,EAOM,WAPN,GAAA,CAAA,CAAA,IAAA,EAAA;IAOM,MAAA,EAEU,aAFV,CAEwB,SAFxB,CAAA;EAAW,CAAA,EAEa,GAClB,WADkB,GACJ,OADI,CACI,WADJ,CAAA,CAAA;EAAS;;;;EACN,QAAA,CAAA,EAAA,MAAA;;;;;;;;AAXvB,iBCeI,aDfgB,CAAA,gBCec,WDfd,CAAA,CAAA,IAAA,ECgBxB,oBDhBwB,CCgBH,ODhBG,CAAA,MAAA,CAAA,CAAA,SAAA,CAAA,CAAA,QAAA,CAAA,CAAA,CAAA,ECiB7B,QDjB6B,CCiBpB,ODjBoB,CAAA"} |
| import { __toESM, require_objectSpread2 } from "./objectSpread2-BvkFp-_Y.mjs"; | ||
| import { TRPCClientError } from "./TRPCClientError-CjKyS10w.mjs"; | ||
| import { getUrl, httpRequest, jsonHttpRequester, resolveHTTPLinkOptions } from "./httpUtils-D61f8fkr.mjs"; | ||
| import { observable } from "@trpc/server/observable"; | ||
| import { transformResult } from "@trpc/server/unstable-core-do-not-import"; | ||
| //#region src/links/internals/contentTypes.ts | ||
| function isOctetType(input) { | ||
| return input instanceof Uint8Array || input instanceof Blob; | ||
| } | ||
| function isFormData(input) { | ||
| return input instanceof FormData; | ||
| } | ||
| function isNonJsonSerializable(input) { | ||
| return isOctetType(input) || isFormData(input); | ||
| } | ||
| //#endregion | ||
| //#region src/links/httpLink.ts | ||
| var import_objectSpread2 = __toESM(require_objectSpread2(), 1); | ||
| const universalRequester = (opts) => { | ||
| if ("input" in opts) { | ||
| const { input } = opts; | ||
| if (isFormData(input)) { | ||
| if (opts.type !== "mutation" && opts.methodOverride !== "POST") throw new Error("FormData is only supported for mutations"); | ||
| return httpRequest((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts), {}, { | ||
| contentTypeHeader: void 0, | ||
| getUrl, | ||
| getBody: () => input | ||
| })); | ||
| } | ||
| if (isOctetType(input)) { | ||
| if (opts.type !== "mutation" && opts.methodOverride !== "POST") throw new Error("Octet type input is only supported for mutations"); | ||
| return httpRequest((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts), {}, { | ||
| contentTypeHeader: "application/octet-stream", | ||
| getUrl, | ||
| getBody: () => input | ||
| })); | ||
| } | ||
| } | ||
| return jsonHttpRequester(opts); | ||
| }; | ||
| /** | ||
| * @see https://trpc.io/docs/client/links/httpLink | ||
| */ | ||
| function httpLink(opts) { | ||
| const resolvedOpts = resolveHTTPLinkOptions(opts); | ||
| return () => { | ||
| return (operationOpts) => { | ||
| const { op } = operationOpts; | ||
| return observable((observer) => { | ||
| const { path, input, type } = op; | ||
| /* istanbul ignore if -- @preserve */ | ||
| if (type === "subscription") throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`"); | ||
| const request = universalRequester((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, resolvedOpts), {}, { | ||
| type, | ||
| path, | ||
| input, | ||
| signal: op.signal, | ||
| headers() { | ||
| if (!opts.headers) return {}; | ||
| if (typeof opts.headers === "function") return opts.headers({ op }); | ||
| return opts.headers; | ||
| } | ||
| })); | ||
| let meta = void 0; | ||
| request.then((res) => { | ||
| meta = res.meta; | ||
| const transformed = transformResult(res.json, resolvedOpts.transformer.output); | ||
| if (!transformed.ok) { | ||
| observer.error(TRPCClientError.from(transformed.error, { meta })); | ||
| return; | ||
| } | ||
| observer.next({ | ||
| context: res.meta, | ||
| result: transformed.result | ||
| }); | ||
| observer.complete(); | ||
| }).catch((cause) => { | ||
| observer.error(TRPCClientError.from(cause, { meta })); | ||
| }); | ||
| return () => {}; | ||
| }); | ||
| }; | ||
| }; | ||
| } | ||
| //#endregion | ||
| export { httpLink, isFormData, isNonJsonSerializable, isOctetType }; | ||
| //# sourceMappingURL=httpLink-CBOGz9wP.mjs.map |
| {"version":3,"file":"httpLink-CBOGz9wP.mjs","names":["input: unknown","universalRequester: Requester","opts: HTTPLinkOptions<TRouter['_def']['_config']['$types']>","meta: HTTPResult['meta'] | undefined"],"sources":["../src/links/internals/contentTypes.ts","../src/links/httpLink.ts"],"sourcesContent":["export function isOctetType(\n input: unknown,\n): input is Uint8Array<ArrayBuffer> | Blob {\n return (\n input instanceof Uint8Array ||\n // File extends from Blob but is only available in nodejs from v20\n input instanceof Blob\n );\n}\n\nexport function isFormData(input: unknown) {\n return input instanceof FormData;\n}\n\nexport function isNonJsonSerializable(input: unknown) {\n return isOctetType(input) || isFormData(input);\n}\n","import { observable } from '@trpc/server/observable';\nimport type {\n AnyClientTypes,\n AnyRouter,\n} from '@trpc/server/unstable-core-do-not-import';\nimport { transformResult } from '@trpc/server/unstable-core-do-not-import';\nimport { TRPCClientError } from '../TRPCClientError';\nimport type {\n HTTPLinkBaseOptions,\n HTTPResult,\n Requester,\n} from './internals/httpUtils';\nimport {\n getUrl,\n httpRequest,\n jsonHttpRequester,\n resolveHTTPLinkOptions,\n} from './internals/httpUtils';\nimport {\n isFormData,\n isOctetType,\n type HTTPHeaders,\n type Operation,\n type TRPCLink,\n} from './types';\n\nexport type HTTPLinkOptions<TRoot extends AnyClientTypes> =\n HTTPLinkBaseOptions<TRoot> & {\n /**\n * Headers to be set on outgoing requests or a callback that of said headers\n * @see http://trpc.io/docs/client/headers\n */\n headers?:\n | HTTPHeaders\n | ((opts: { op: Operation }) => HTTPHeaders | Promise<HTTPHeaders>);\n };\n\nconst universalRequester: Requester = (opts) => {\n if ('input' in opts) {\n const { input } = opts;\n if (isFormData(input)) {\n if (opts.type !== 'mutation' && opts.methodOverride !== 'POST') {\n throw new Error('FormData is only supported for mutations');\n }\n\n return httpRequest({\n ...opts,\n // The browser will set this automatically and include the boundary= in it\n contentTypeHeader: undefined,\n getUrl,\n getBody: () => input,\n });\n }\n\n if (isOctetType(input)) {\n if (opts.type !== 'mutation' && opts.methodOverride !== 'POST') {\n throw new Error('Octet type input is only supported for mutations');\n }\n\n return httpRequest({\n ...opts,\n contentTypeHeader: 'application/octet-stream',\n getUrl,\n getBody: () => input,\n });\n }\n }\n\n return jsonHttpRequester(opts);\n};\n\n/**\n * @see https://trpc.io/docs/client/links/httpLink\n */\nexport function httpLink<TRouter extends AnyRouter = AnyRouter>(\n opts: HTTPLinkOptions<TRouter['_def']['_config']['$types']>,\n): TRPCLink<TRouter> {\n const resolvedOpts = resolveHTTPLinkOptions(opts);\n return () => {\n return (operationOpts) => {\n const { op } = operationOpts;\n return observable((observer) => {\n const { path, input, type } = op;\n /* istanbul ignore if -- @preserve */\n if (type === 'subscription') {\n throw new Error(\n 'Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`',\n );\n }\n\n const request = universalRequester({\n ...resolvedOpts,\n type,\n path,\n input,\n signal: op.signal,\n headers() {\n if (!opts.headers) {\n return {};\n }\n if (typeof opts.headers === 'function') {\n return opts.headers({\n op,\n });\n }\n return opts.headers;\n },\n });\n let meta: HTTPResult['meta'] | undefined = undefined;\n request\n .then((res) => {\n meta = res.meta;\n const transformed = transformResult(\n res.json,\n resolvedOpts.transformer.output,\n );\n\n if (!transformed.ok) {\n observer.error(\n TRPCClientError.from(transformed.error, {\n meta,\n }),\n );\n return;\n }\n observer.next({\n context: res.meta,\n result: transformed.result,\n });\n observer.complete();\n })\n .catch((cause) => {\n observer.error(TRPCClientError.from(cause, { meta }));\n });\n\n return () => {\n // noop\n };\n });\n };\n };\n}\n"],"mappings":";;;;;;;AAAA,SAAgB,YACdA,OACyC;AACzC,QACE,iBAAiB,cAEjB,iBAAiB;AAEpB;AAED,SAAgB,WAAWA,OAAgB;AACzC,QAAO,iBAAiB;AACzB;AAED,SAAgB,sBAAsBA,OAAgB;AACpD,QAAO,YAAY,MAAM,IAAI,WAAW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AC,UAAU;AAChB,cAAS,MAAM,gBAAgB,KAAK,OAAO,EAAE,KAAM,EAAC,CAAC;IACtD,EAAC;AAEJ,WAAO,MAAM,CAEZ;GACF,EAAC;EACH;CACF;AACF"} |
| import { HTTPHeaders, Operation, TRPCLink } from "./types.d-CAt1zKAY.mjs"; | ||
| import { HTTPLinkBaseOptions } from "./httpUtils.d-akze5l4u.mjs"; | ||
| import { AnyClientTypes, AnyRouter } from "@trpc/server/unstable-core-do-not-import"; | ||
| //#region src/links/httpLink.d.ts | ||
| type HTTPLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TRoot> & { | ||
| /** | ||
| * Headers to be set on outgoing requests or a callback that of said headers | ||
| * @see http://trpc.io/docs/client/headers | ||
| */ | ||
| headers?: HTTPHeaders | ((opts: { | ||
| op: Operation; | ||
| }) => HTTPHeaders | Promise<HTTPHeaders>); | ||
| }; | ||
| /** | ||
| * @see https://trpc.io/docs/client/links/httpLink | ||
| */ | ||
| declare function httpLink<TRouter extends AnyRouter = AnyRouter>(opts: HTTPLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>; | ||
| //# sourceMappingURL=httpLink.d.ts.map | ||
| //#endregion | ||
| export { HTTPLinkOptions, httpLink }; | ||
| //# sourceMappingURL=httpLink.d-BEC5B7OH.d.mts.map |
| {"version":3,"file":"httpLink.d-BEC5B7OH.d.mts","names":[],"sources":["../src/links/httpLink.ts"],"sourcesContent":[],"mappings":";;;;;KA0BY,8BAA8B,kBACxC,oBAAoB;;AADtB;;;EAAwD,OAClC,CAAA,EAMd,WANc,GAAA,CAAA,CAAA,IAAA,EAAA;IAApB,EAAA,EAOoB,SAPpB;EAAmB,CAAA,EAMb,GAC8B,WAD9B,GAC4C,OAD5C,CACoD,WADpD,CAAA,CAAA;CAAW;;;;AACwC,iBAwC3C,QAxC2C,CAAA,gBAwClB,SAxCkB,GAwCN,SAxCM,CAAA,CAAA,IAAA,EAyCnD,eAzCmD,CAyCnC,OAzCmC,CAAA,MAAA,CAAA,CAAA,SAAA,CAAA,CAAA,QAAA,CAAA,CAAA,CAAA,EA0CxD,QA1CwD,CA0C/C,OA1C+C,CAAA;AAwC3D"} |
| import { __toESM, require_objectSpread2 } from "./objectSpread2-BvkFp-_Y.mjs"; | ||
| import { getTransformer } from "./unstable-internals-Bg7n9BBj.mjs"; | ||
| //#region src/getFetch.ts | ||
| const isFunction = (fn) => typeof fn === "function"; | ||
| function getFetch(customFetchImpl) { | ||
| if (customFetchImpl) return customFetchImpl; | ||
| if (typeof window !== "undefined" && isFunction(window.fetch)) return window.fetch; | ||
| if (typeof globalThis !== "undefined" && isFunction(globalThis.fetch)) return globalThis.fetch; | ||
| throw new Error("No fetch implementation found"); | ||
| } | ||
| //#endregion | ||
| //#region src/links/internals/httpUtils.ts | ||
| var import_objectSpread2 = __toESM(require_objectSpread2()); | ||
| function resolveHTTPLinkOptions(opts) { | ||
| return { | ||
| url: opts.url.toString(), | ||
| fetch: opts.fetch, | ||
| transformer: getTransformer(opts.transformer), | ||
| methodOverride: opts.methodOverride | ||
| }; | ||
| } | ||
| function arrayToDict(array) { | ||
| const dict = {}; | ||
| for (let index = 0; index < array.length; index++) { | ||
| const element = array[index]; | ||
| dict[index] = element; | ||
| } | ||
| return dict; | ||
| } | ||
| const METHOD = { | ||
| query: "GET", | ||
| mutation: "POST", | ||
| subscription: "PATCH" | ||
| }; | ||
| function getInput(opts) { | ||
| return "input" in opts ? opts.transformer.input.serialize(opts.input) : arrayToDict(opts.inputs.map((_input) => opts.transformer.input.serialize(_input))); | ||
| } | ||
| const getUrl = (opts) => { | ||
| const parts = opts.url.split("?"); | ||
| const base = parts[0].replace(/\/$/, ""); | ||
| let url = base + "/" + opts.path; | ||
| const queryParts = []; | ||
| if (parts[1]) queryParts.push(parts[1]); | ||
| if ("inputs" in opts) queryParts.push("batch=1"); | ||
| if (opts.type === "query" || opts.type === "subscription") { | ||
| const input = getInput(opts); | ||
| if (input !== void 0 && opts.methodOverride !== "POST") queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`); | ||
| } | ||
| if (queryParts.length) url += "?" + queryParts.join("&"); | ||
| return url; | ||
| }; | ||
| const getBody = (opts) => { | ||
| if (opts.type === "query" && opts.methodOverride !== "POST") return void 0; | ||
| const input = getInput(opts); | ||
| return input !== void 0 ? JSON.stringify(input) : void 0; | ||
| }; | ||
| const jsonHttpRequester = (opts) => { | ||
| return httpRequest((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts), {}, { | ||
| contentTypeHeader: "application/json", | ||
| getUrl, | ||
| getBody | ||
| })); | ||
| }; | ||
| /** | ||
| * Polyfill for DOMException with AbortError name | ||
| */ | ||
| var AbortError = class extends Error { | ||
| constructor() { | ||
| const name = "AbortError"; | ||
| super(name); | ||
| this.name = name; | ||
| this.message = name; | ||
| } | ||
| }; | ||
| /** | ||
| * Polyfill for `signal.throwIfAborted()` | ||
| * | ||
| * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/throwIfAborted | ||
| */ | ||
| const throwIfAborted = (signal) => { | ||
| var _signal$throwIfAborte; | ||
| if (!(signal === null || signal === void 0 ? void 0 : signal.aborted)) return; | ||
| (_signal$throwIfAborte = signal.throwIfAborted) === null || _signal$throwIfAborte === void 0 || _signal$throwIfAborte.call(signal); | ||
| if (typeof DOMException !== "undefined") throw new DOMException("AbortError", "AbortError"); | ||
| throw new AbortError(); | ||
| }; | ||
| async function fetchHTTPResponse(opts) { | ||
| var _opts$methodOverride; | ||
| throwIfAborted(opts.signal); | ||
| const url = opts.getUrl(opts); | ||
| const body = opts.getBody(opts); | ||
| const method = (_opts$methodOverride = opts.methodOverride) !== null && _opts$methodOverride !== void 0 ? _opts$methodOverride : METHOD[opts.type]; | ||
| const resolvedHeaders = await (async () => { | ||
| const heads = await opts.headers(); | ||
| if (Symbol.iterator in heads) return Object.fromEntries(heads); | ||
| return heads; | ||
| })(); | ||
| const headers = (0, import_objectSpread2.default)((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts.contentTypeHeader && method !== "GET" ? { "content-type": opts.contentTypeHeader } : {}), opts.trpcAcceptHeader ? { "trpc-accept": opts.trpcAcceptHeader } : void 0), resolvedHeaders); | ||
| return getFetch(opts.fetch)(url, { | ||
| method, | ||
| signal: opts.signal, | ||
| body, | ||
| headers | ||
| }); | ||
| } | ||
| async function httpRequest(opts) { | ||
| const meta = {}; | ||
| const res = await fetchHTTPResponse(opts); | ||
| meta.response = res; | ||
| const json = await res.json(); | ||
| meta.responseJSON = json; | ||
| return { | ||
| json, | ||
| meta | ||
| }; | ||
| } | ||
| //#endregion | ||
| export { fetchHTTPResponse, getBody, getFetch, getUrl, httpRequest, jsonHttpRequester, resolveHTTPLinkOptions }; | ||
| //# sourceMappingURL=httpUtils-D61f8fkr.mjs.map |
| {"version":3,"file":"httpUtils-D61f8fkr.mjs","names":["fn: unknown","customFetchImpl?: FetchEsque | NativeFetchEsque","opts: HTTPLinkBaseOptions<AnyClientTypes>","array: unknown[]","dict: Record<number, unknown>","opts: GetInputOptions","getUrl: GetUrl","queryParts: string[]","getBody: GetBody","jsonHttpRequester: Requester","signal: Maybe<AbortSignal>","opts: HTTPRequestOptions"],"sources":["../src/getFetch.ts","../src/links/internals/httpUtils.ts"],"sourcesContent":["import type { FetchEsque, NativeFetchEsque } from './internals/types';\n\ntype AnyFn = (...args: any[]) => unknown;\n\nconst isFunction = (fn: unknown): fn is AnyFn => typeof fn === 'function';\n\nexport function getFetch(\n customFetchImpl?: FetchEsque | NativeFetchEsque,\n): FetchEsque {\n if (customFetchImpl) {\n return customFetchImpl as FetchEsque;\n }\n\n if (typeof window !== 'undefined' && isFunction(window.fetch)) {\n return window.fetch as FetchEsque;\n }\n\n if (typeof globalThis !== 'undefined' && isFunction(globalThis.fetch)) {\n return globalThis.fetch as FetchEsque;\n }\n\n throw new Error('No fetch implementation found');\n}\n","import type {\n AnyClientTypes,\n CombinedDataTransformer,\n Maybe,\n ProcedureType,\n TRPCAcceptHeader,\n TRPCResponse,\n} from '@trpc/server/unstable-core-do-not-import';\nimport { getFetch } from '../../getFetch';\nimport type {\n FetchEsque,\n RequestInitEsque,\n ResponseEsque,\n} from '../../internals/types';\nimport type { TransformerOptions } from '../../unstable-internals';\nimport { getTransformer } from '../../unstable-internals';\nimport type { HTTPHeaders } from '../types';\n\n/**\n * @internal\n */\nexport type HTTPLinkBaseOptions<\n TRoot extends Pick<AnyClientTypes, 'transformer'>,\n> = {\n url: string | URL;\n /**\n * Add ponyfill for fetch\n */\n fetch?: FetchEsque;\n /**\n * Send all requests `as POST`s requests regardless of the procedure type\n * The HTTP handler must separately allow overriding the method. See:\n * @see https://trpc.io/docs/rpc\n */\n methodOverride?: 'POST';\n} & TransformerOptions<TRoot>;\n\nexport interface ResolvedHTTPLinkOptions {\n url: string;\n fetch?: FetchEsque;\n transformer: CombinedDataTransformer;\n methodOverride?: 'POST';\n}\n\nexport function resolveHTTPLinkOptions(\n opts: HTTPLinkBaseOptions<AnyClientTypes>,\n): ResolvedHTTPLinkOptions {\n return {\n url: opts.url.toString(),\n fetch: opts.fetch,\n transformer: getTransformer(opts.transformer),\n methodOverride: opts.methodOverride,\n };\n}\n\n// https://github.com/trpc/trpc/pull/669\nfunction arrayToDict(array: unknown[]) {\n const dict: Record<number, unknown> = {};\n for (let index = 0; index < array.length; index++) {\n const element = array[index];\n dict[index] = element;\n }\n return dict;\n}\n\nconst METHOD = {\n query: 'GET',\n mutation: 'POST',\n subscription: 'PATCH',\n} as const;\n\nexport interface HTTPResult {\n json: TRPCResponse;\n meta: {\n response: ResponseEsque;\n responseJSON?: unknown;\n };\n}\n\ntype GetInputOptions = {\n transformer: CombinedDataTransformer;\n} & ({ input: unknown } | { inputs: unknown[] });\n\nexport function getInput(opts: GetInputOptions) {\n return 'input' in opts\n ? opts.transformer.input.serialize(opts.input)\n : arrayToDict(\n opts.inputs.map((_input) => opts.transformer.input.serialize(_input)),\n );\n}\n\nexport type HTTPBaseRequestOptions = GetInputOptions &\n ResolvedHTTPLinkOptions & {\n type: ProcedureType;\n path: string;\n signal: Maybe<AbortSignal>;\n };\n\ntype GetUrl = (opts: HTTPBaseRequestOptions) => string;\ntype GetBody = (opts: HTTPBaseRequestOptions) => RequestInitEsque['body'];\n\nexport type ContentOptions = {\n trpcAcceptHeader?: TRPCAcceptHeader;\n contentTypeHeader?: string;\n getUrl: GetUrl;\n getBody: GetBody;\n};\n\nexport const getUrl: GetUrl = (opts) => {\n const parts = opts.url.split('?') as [string, string?];\n const base = parts[0].replace(/\\/$/, ''); // Remove any trailing slashes\n\n let url = base + '/' + opts.path;\n const queryParts: string[] = [];\n\n if (parts[1]) {\n queryParts.push(parts[1]);\n }\n if ('inputs' in opts) {\n queryParts.push('batch=1');\n }\n if (opts.type === 'query' || opts.type === 'subscription') {\n const input = getInput(opts);\n if (input !== undefined && opts.methodOverride !== 'POST') {\n queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`);\n }\n }\n if (queryParts.length) {\n url += '?' + queryParts.join('&');\n }\n return url;\n};\n\nexport const getBody: GetBody = (opts) => {\n if (opts.type === 'query' && opts.methodOverride !== 'POST') {\n return undefined;\n }\n const input = getInput(opts);\n return input !== undefined ? JSON.stringify(input) : undefined;\n};\n\nexport type Requester = (\n opts: HTTPBaseRequestOptions & {\n headers: () => HTTPHeaders | Promise<HTTPHeaders>;\n },\n) => Promise<HTTPResult>;\n\nexport const jsonHttpRequester: Requester = (opts) => {\n return httpRequest({\n ...opts,\n contentTypeHeader: 'application/json',\n getUrl,\n getBody,\n });\n};\n\n/**\n * Polyfill for DOMException with AbortError name\n */\nclass AbortError extends Error {\n constructor() {\n const name = 'AbortError';\n super(name);\n this.name = name;\n this.message = name;\n }\n}\n\nexport type HTTPRequestOptions = ContentOptions &\n HTTPBaseRequestOptions & {\n headers: () => HTTPHeaders | Promise<HTTPHeaders>;\n };\n\n/**\n * Polyfill for `signal.throwIfAborted()`\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/throwIfAborted\n */\nconst throwIfAborted = (signal: Maybe<AbortSignal>) => {\n if (!signal?.aborted) {\n return;\n }\n // If available, use the native implementation\n signal.throwIfAborted?.();\n\n // If we have `DOMException`, use it\n if (typeof DOMException !== 'undefined') {\n throw new DOMException('AbortError', 'AbortError');\n }\n\n // Otherwise, use our own implementation\n throw new AbortError();\n};\n\nexport async function fetchHTTPResponse(opts: HTTPRequestOptions) {\n throwIfAborted(opts.signal);\n\n const url = opts.getUrl(opts);\n const body = opts.getBody(opts);\n const method = opts.methodOverride ?? METHOD[opts.type];\n const resolvedHeaders = await (async () => {\n const heads = await opts.headers();\n if (Symbol.iterator in heads) {\n return Object.fromEntries(heads);\n }\n return heads;\n })();\n const headers = {\n ...(opts.contentTypeHeader && method !== 'GET'\n ? { 'content-type': opts.contentTypeHeader }\n : {}),\n ...(opts.trpcAcceptHeader\n ? { '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,aAAa,CAACA,cAAoC,OAAO;AAE/D,SAAgB,SACdC,iBACY;AACZ,KAAI,gBACF,QAAO;AAGT,YAAW,WAAW,eAAe,WAAW,OAAO,MAAM,CAC3D,QAAO,OAAO;AAGhB,YAAW,eAAe,eAAe,WAAW,WAAW,MAAM,CACnE,QAAO,WAAW;AAGpB,OAAM,IAAI,MAAM;AACjB;;;;;ACsBD,SAAgB,uBACdC,MACyB;AACzB,QAAO;EACL,KAAK,KAAK,IAAI,UAAU;EACxB,OAAO,KAAK;EACZ,aAAa,eAAe,KAAK,YAAY;EAC7C,gBAAgB,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AAyB,MAAM;CAC7B,cAAc;EACZ,MAAM,OAAO;AACb,QAAM,KAAK;AACX,OAAK,OAAO;AACZ,OAAK,UAAU;CAChB;AACF;;;;;;AAYD,MAAM,iBAAiB,CAACC,WAA+B;;AACrD,uDAAK,OAAQ,SACX;AAGF,iCAAO,gEAAP,kCAAyB;AAGzB,YAAW,iBAAiB,YAC1B,OAAM,IAAI,aAAa,cAAc;AAIvC,OAAM,IAAI;AACX;AAED,eAAsB,kBAAkBC,MAA0B;;AAChE,gBAAe,KAAK,OAAO;CAE3B,MAAM,MAAM,KAAK,OAAO,KAAK;CAC7B,MAAM,OAAO,KAAK,QAAQ,KAAK;CAC/B,MAAM,iCAAS,KAAK,qFAAkB,OAAO,KAAK;CAClD,MAAM,kBAAkB,MAAM,CAAC,YAAY;EACzC,MAAM,QAAQ,MAAM,KAAK,SAAS;AAClC,MAAI,OAAO,YAAY,MACrB,QAAO,OAAO,YAAY,MAAM;AAElC,SAAO;CACR,IAAG;CACJ,MAAM,oHACA,KAAK,qBAAqB,WAAW,QACrC,EAAE,gBAAgB,KAAK,kBAAmB,IAC1C,CAAE,IACF,KAAK,mBACL,EAAE,eAAe,KAAK,iBAAkB,aAEzC;AAGL,QAAO,SAAS,KAAK,MAAM,CAAC,KAAK;EAC/B;EACA,QAAQ,KAAK;EACb;EACA;CACD,EAAC;AACH;AAED,eAAsB,YACpBA,MACqB;CACrB,MAAM,OAAO,CAAE;CAEf,MAAM,MAAM,MAAM,kBAAkB,KAAK;AACzC,MAAK,WAAW;CAEhB,MAAM,OAAO,MAAM,IAAI,MAAM;AAE7B,MAAK,eAAe;AAEpB,QAAO;EACC;EACN;CACD;AACF"} |
| import { FetchEsque } from "./types.d-CAt1zKAY.mjs"; | ||
| import { TransformerOptions } from "./unstable-internals.d-BOmV7EK1.mjs"; | ||
| import { AnyClientTypes, CombinedDataTransformer, Maybe, ProcedureType } from "@trpc/server/unstable-core-do-not-import"; | ||
| //#region src/links/internals/httpUtils.d.ts | ||
| /** | ||
| * @internal | ||
| */ | ||
| type HTTPLinkBaseOptions<TRoot extends Pick<AnyClientTypes, 'transformer'>> = { | ||
| url: string | URL; | ||
| /** | ||
| * Add ponyfill for fetch | ||
| */ | ||
| fetch?: FetchEsque; | ||
| /** | ||
| * Send all requests `as POST`s requests regardless of the procedure type | ||
| * The HTTP handler must separately allow overriding the method. See: | ||
| * @see https://trpc.io/docs/rpc | ||
| */ | ||
| methodOverride?: 'POST'; | ||
| } & TransformerOptions<TRoot>; | ||
| //#endregion | ||
| export { HTTPLinkBaseOptions }; | ||
| //# sourceMappingURL=httpUtils.d-akze5l4u.d.mts.map |
| {"version":3,"file":"httpUtils.d-akze5l4u.d.mts","names":[],"sources":["../src/links/internals/httpUtils.ts"],"sourcesContent":[],"mappings":";;;;;;;AAqBA;;AACqB,KADT,mBACS,CAAA,cAAL,IAAK,CAAA,cAAA,EAAA,aAAA,CAAA,CAAA,GAAA;EAAc,GAAnB,EAAA,MAAA,GAEA,GAFA;EAAI;;;EAaQ,KAAxB,CAAA,EAPM,UAON;EAAkB;;;;;;IAAlB,mBAAmB"} |
| import { Operation, OperationResultEnvelope, TRPCClientError, TRPCLink } from "./types.d-CAt1zKAY.mjs"; | ||
| import { AnyRouter, InferrableClientTypes } from "@trpc/server/unstable-core-do-not-import"; | ||
| //#region src/links/loggerLink.d.ts | ||
| type ConsoleEsque = { | ||
| log: (...args: any[]) => void; | ||
| error: (...args: any[]) => void; | ||
| }; | ||
| type EnableFnOptions<TRouter extends InferrableClientTypes> = { | ||
| direction: 'down'; | ||
| result: OperationResultEnvelope<unknown, TRPCClientError<TRouter>> | TRPCClientError<TRouter>; | ||
| } | (Operation & { | ||
| direction: 'up'; | ||
| }); | ||
| type EnabledFn<TRouter extends AnyRouter> = (opts: EnableFnOptions<TRouter>) => boolean; | ||
| type LoggerLinkFnOptions<TRouter extends AnyRouter> = Operation & ({ | ||
| /** | ||
| * Request result | ||
| */ | ||
| direction: 'down'; | ||
| result: OperationResultEnvelope<unknown, TRPCClientError<TRouter>> | TRPCClientError<TRouter>; | ||
| elapsedMs: number; | ||
| } | { | ||
| /** | ||
| * Request was just initialized | ||
| */ | ||
| direction: 'up'; | ||
| }); | ||
| type LoggerLinkFn<TRouter extends AnyRouter> = (opts: LoggerLinkFnOptions<TRouter>) => void; | ||
| type ColorMode = 'ansi' | 'css' | 'none'; | ||
| interface LoggerLinkOptions<TRouter extends AnyRouter> { | ||
| logger?: LoggerLinkFn<TRouter>; | ||
| enabled?: EnabledFn<TRouter>; | ||
| /** | ||
| * Used in the built-in defaultLogger | ||
| */ | ||
| console?: ConsoleEsque; | ||
| /** | ||
| * Color mode | ||
| * @default typeof window === 'undefined' ? 'ansi' : 'css' | ||
| */ | ||
| colorMode?: ColorMode; | ||
| /** | ||
| * Include context in the log - defaults to false unless `colorMode` is 'css' | ||
| */ | ||
| withContext?: boolean; | ||
| } | ||
| /** | ||
| * @see https://trpc.io/docs/v11/client/links/loggerLink | ||
| */ | ||
| declare function loggerLink<TRouter extends AnyRouter = AnyRouter>(opts?: LoggerLinkOptions<TRouter>): TRPCLink<TRouter>; | ||
| //#endregion | ||
| export { LoggerLinkOptions, loggerLink }; | ||
| //# sourceMappingURL=loggerLink.d-B_ylo7O3.d.mts.map |
| {"version":3,"file":"loggerLink.d-B_ylo7O3.d.mts","names":[],"sources":["../src/links/loggerLink.ts"],"sourcesContent":[],"mappings":";;;;KAeK,YAAA;EAAA,GAAA,EAAA,CAAA,GAAA,IAAA,EAAY,GAAA,EAAA,EAAA,GAAA,IAAA;EAKZ,KAAA,EAAA,CAAA,GAAA,IAAA,EAAA,GAAe,EAAA,EAAA,GAAA,IAAA;CAAA;KAAf,eAAgC,CAAA,gBAAA,qBAAA,CAAA,GAAA;EAAqB,SAIC,EAAA,MAAA;EAAO,MAAvB,EAAjC,uBAAiC,CAAA,OAAA,EAAA,eAAA,CAAgB,OAAhB,CAAA,CAAA,GACjC,eADiC,CACjB,OADiB,CAAA;CAAe,GAAA,CAGrD,SAHK,GAAA;EAAuB,SACP,EAAA,IAAA;CAAO,CAAA;KAK5B,SAHA,CAAA,gBAG0B,SAH1B,CAAA,GAAA,CAAA,IAAA,EAIG,eAJH,CAImB,OAJnB,CAAA,EAAA,GAAA,OAAA;AAAS,KAOT,mBAPS,CAAA,gBAO2B,SAP3B,CAAA,GAOwC,SAPxC,GAAA,CAAA;EAGT;;;EAAmC,SAChB,EAAA,MAAA;EAAO,MAAvB,EAWI,uBAXJ,CAAA,OAAA,EAWqC,eAXrC,CAWqD,OAXrD,CAAA,CAAA,GAYI,eAZJ,CAYoB,OAZpB,CAAA;EAAe,SAAA,EAAA,MAAA;AAAA,CAAA,GAGlB;EAAmB;;;EAAuC,SAQF,EAAA,IAAA;CAAO,CAAA;KAY/D,YAZO,CAAA,gBAYsB,SAZtB,CAAA,GAAA,CAAA,IAAA,EAaJ,mBAbI,CAagB,OAbhB,CAAA,EAAA,GAAA,IAAA;KAgBP,SAAA,GAfuB,MAAA,GAAA,KAAA,GAAA,MAAA;AAAhB,UAiBK,iBAjBL,CAAA,gBAiBuC,SAjBvC,CAAA,CAAA;EAAe,MAAA,CAAA,EAkBhB,YAlBgB,CAkBH,OAlBG,CAAA;EAWtB,OAAA,CAAA,EAQO,SARK,CAQK,OARL,CAAA;EAAA;;;EACkB,OAA3B,CAAA,EAWI,YAXJ;EAAmB;AAAA;AAK3B;;EAAkC,SAAiB,CAAA,EAWrC,SAXqC;EAAS;;;EAE/B,WAAjB,CAAA,EAAA,OAAA;;;AASW;AA8IvB;AAA0B,iBAAV,UAAU,CAAA,gBAAiB,SAAjB,GAA6B,SAA7B,CAAA,CAAA,IAAA,CAAA,EAClB,iBADkB,CACA,OADA,CAAA,CAAA,EAEvB,QAFuB,CAEd,OAFc,CAAA"} |
| import { Operation, TRPCLink } from "./types.d-CAt1zKAY.mjs"; | ||
| import { AnyRouter } from "@trpc/server/unstable-core-do-not-import"; | ||
| //#region src/links/splitLink.d.ts | ||
| declare function splitLink<TRouter extends AnyRouter = AnyRouter>(opts: { | ||
| condition: (op: Operation) => boolean; | ||
| /** | ||
| * The link to execute next if the test function returns `true`. | ||
| */ | ||
| true: TRPCLink<TRouter> | TRPCLink<TRouter>[]; | ||
| /** | ||
| * The link to execute next if the test function returns `false`. | ||
| */ | ||
| false: TRPCLink<TRouter> | TRPCLink<TRouter>[]; | ||
| }): TRPCLink<TRouter>; | ||
| //# sourceMappingURL=splitLink.d.ts.map | ||
| //#endregion | ||
| export { splitLink }; | ||
| //# sourceMappingURL=splitLink.d-Df2gT0RV.d.mts.map |
| {"version":3,"file":"splitLink.d-Df2gT0RV.d.mts","names":[],"sources":["../src/links/splitLink.ts"],"sourcesContent":[],"mappings":";;;;iBAQgB,0BAA0B,YAAY;kBACpC;EADF;;;EAAmC,IAAG,EAK9C,QAL8C,CAKrC,OALqC,CAAA,GAK1B,QAL0B,CAKjB,OALiB,CAAA,EAAA;EAAS;;;EAK/C,KAAqB,EAI5B,QAJ4B,CAInB,OAJmB,CAAA,GAIR,QAJQ,CAIC,OAJD,CAAA,EAAA;CAAO,CAAA,EAKxC,QALwB,CAKf,OALe,CAAA"} |
| import { TRPCConnectionState } from "./subscriptions.d-Dlr1nWGD.mjs"; | ||
| import { Observable, Observer } from "@trpc/server/observable"; | ||
| import { DefaultErrorShape, InferrableClientTypes, Maybe, TRPCErrorResponse, TRPCResultMessage, TRPCSuccessResponse, inferClientTypes } from "@trpc/server/unstable-core-do-not-import"; | ||
| //#region src/internals/types.d.ts | ||
| /** | ||
| * A subset of the standard fetch function type needed by tRPC internally. | ||
| * @see fetch from lib.dom.d.ts | ||
| * @remarks | ||
| * If you need a property that you know exists but doesn't exist on this | ||
| * interface, go ahead and add it. | ||
| */ | ||
| type FetchEsque = (input: RequestInfo | URL | string, init?: RequestInit | RequestInitEsque) => Promise<ResponseEsque>; | ||
| /** | ||
| * A simpler version of the native fetch function's type for packages with | ||
| * their own fetch types, such as undici and node-fetch. | ||
| */ | ||
| type NativeFetchEsque = (url: URL | string, init?: NodeFetchRequestInitEsque) => Promise<ResponseEsque>; | ||
| interface NodeFetchRequestInitEsque { | ||
| body?: string; | ||
| } | ||
| /** | ||
| * A subset of the standard RequestInit properties needed by tRPC internally. | ||
| * @see RequestInit from lib.dom.d.ts | ||
| * @remarks | ||
| * If you need a property that you know exists but doesn't exist on this | ||
| * interface, go ahead and add it. | ||
| */ | ||
| interface RequestInitEsque { | ||
| /** | ||
| * Sets the request's body. | ||
| */ | ||
| body?: FormData | string | null | Uint8Array<ArrayBuffer> | Blob | File; | ||
| /** | ||
| * Sets the request's associated headers. | ||
| */ | ||
| headers?: [string, string][] | Record<string, string>; | ||
| /** | ||
| * The request's HTTP-style method. | ||
| */ | ||
| method?: string; | ||
| /** | ||
| * Sets the request's signal. | ||
| */ | ||
| signal?: AbortSignal | undefined; | ||
| } | ||
| /** | ||
| * A subset of the standard ReadableStream properties needed by tRPC internally. | ||
| * @see ReadableStream from lib.dom.d.ts | ||
| */ | ||
| type WebReadableStreamEsque = { | ||
| getReader: () => ReadableStreamDefaultReader<Uint8Array>; | ||
| }; | ||
| type NodeJSReadableStreamEsque = { | ||
| on(eventName: string | symbol, listener: (...args: any[]) => void): NodeJSReadableStreamEsque; | ||
| }; | ||
| /** | ||
| * A subset of the standard Response properties needed by tRPC internally. | ||
| * @see Response from lib.dom.d.ts | ||
| */ | ||
| interface ResponseEsque { | ||
| readonly body?: NodeJSReadableStreamEsque | WebReadableStreamEsque | null; | ||
| /** | ||
| * @remarks | ||
| * The built-in Response::json() method returns Promise<any>, but | ||
| * that's not as type-safe as unknown. We use unknown because we're | ||
| * more type-safe. You do want more type safety, right? 😉 | ||
| */ | ||
| json(): Promise<unknown>; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| type NonEmptyArray<TItem> = [TItem, ...TItem[]]; | ||
| type ClientContext = Record<string, unknown>; | ||
| /** | ||
| * @public | ||
| */ | ||
| interface TRPCProcedureOptions { | ||
| /** | ||
| * Client-side context | ||
| */ | ||
| context?: ClientContext; | ||
| signal?: AbortSignal; | ||
| } | ||
| //#endregion | ||
| //#region src/TRPCClientError.d.ts | ||
| type inferErrorShape<TInferrable extends InferrableClientTypes> = inferClientTypes<TInferrable>['errorShape']; | ||
| interface TRPCClientErrorBase<TShape extends DefaultErrorShape> { | ||
| readonly message: string; | ||
| readonly shape: Maybe<TShape>; | ||
| readonly data: Maybe<TShape['data']>; | ||
| } | ||
| type TRPCClientErrorLike<TInferrable extends InferrableClientTypes> = TRPCClientErrorBase<inferErrorShape<TInferrable>>; | ||
| declare function isTRPCClientError<TInferrable extends InferrableClientTypes>(cause: unknown): cause is TRPCClientError<TInferrable>; | ||
| declare class TRPCClientError<TRouterOrProcedure extends InferrableClientTypes> extends Error implements TRPCClientErrorBase<inferErrorShape<TRouterOrProcedure>> { | ||
| readonly cause: Error | undefined; | ||
| readonly shape: Maybe<inferErrorShape<TRouterOrProcedure>>; | ||
| readonly data: Maybe<inferErrorShape<TRouterOrProcedure>['data']>; | ||
| /** | ||
| * Additional meta data about the error | ||
| * In the case of HTTP-errors, we'll have `response` and potentially `responseJSON` here | ||
| */ | ||
| meta: Record<string, unknown> | undefined; | ||
| constructor(message: string, opts?: { | ||
| result?: Maybe<TRPCErrorResponse<inferErrorShape<TRouterOrProcedure>>>; | ||
| cause?: Error; | ||
| meta?: Record<string, unknown>; | ||
| }); | ||
| static from<TRouterOrProcedure extends InferrableClientTypes>(_cause: Error | TRPCErrorResponse<any> | object, opts?: { | ||
| meta?: Record<string, unknown>; | ||
| }): TRPCClientError<TRouterOrProcedure>; | ||
| } | ||
| //#endregion | ||
| //#region src/links/internals/contentTypes.d.ts | ||
| declare function isOctetType(input: unknown): input is Uint8Array<ArrayBuffer> | Blob; | ||
| declare function isFormData(input: unknown): input is FormData; | ||
| declare function isNonJsonSerializable(input: unknown): input is Blob | FormData | Uint8Array<ArrayBuffer>; | ||
| //# sourceMappingURL=contentTypes.d.ts.map | ||
| //#endregion | ||
| //#region src/links/types.d.ts | ||
| /** | ||
| * @internal | ||
| */ | ||
| interface OperationContext extends Record<string, unknown> {} | ||
| /** | ||
| * @internal | ||
| */ | ||
| type Operation<TInput = unknown> = { | ||
| id: number; | ||
| type: 'mutation' | 'query' | 'subscription'; | ||
| input: TInput; | ||
| path: string; | ||
| context: OperationContext; | ||
| signal: Maybe<AbortSignal>; | ||
| }; | ||
| interface HeadersInitEsque { | ||
| [Symbol.iterator](): IterableIterator<[string, string]>; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| type HTTPHeaders = HeadersInitEsque | Record<string, string[] | string | undefined>; | ||
| /** | ||
| * The default `fetch` implementation has an overloaded signature. By convention this library | ||
| * only uses the overload taking a string and options object. | ||
| */ | ||
| type TRPCFetch = (url: string, options?: RequestInit) => Promise<ResponseEsque>; | ||
| interface TRPCClientRuntime {} | ||
| /** | ||
| * @internal | ||
| */ | ||
| interface OperationResultEnvelope<TOutput, TError> { | ||
| result: TRPCResultMessage<TOutput>['result'] | TRPCSuccessResponse<TOutput>['result'] | TRPCConnectionState<TError>; | ||
| context?: OperationContext; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| type OperationResultObservable<TInferrable extends InferrableClientTypes, TOutput> = Observable<OperationResultEnvelope<TOutput, TRPCClientError<TInferrable>>, TRPCClientError<TInferrable>>; | ||
| /** | ||
| * @internal | ||
| */ | ||
| type OperationResultObserver<TInferrable extends InferrableClientTypes, TOutput> = Observer<OperationResultEnvelope<TOutput, TRPCClientError<TInferrable>>, TRPCClientError<TInferrable>>; | ||
| /** | ||
| * @internal | ||
| */ | ||
| type OperationLink<TInferrable extends InferrableClientTypes, TInput = unknown, TOutput = unknown> = (opts: { | ||
| op: Operation<TInput>; | ||
| next: (op: Operation<TInput>) => OperationResultObservable<TInferrable, TOutput>; | ||
| }) => OperationResultObservable<TInferrable, TOutput>; | ||
| /** | ||
| * @public | ||
| */ | ||
| type TRPCLink<TInferrable extends InferrableClientTypes> = (opts: TRPCClientRuntime) => OperationLink<TInferrable>; | ||
| //# sourceMappingURL=types.d.ts.map | ||
| //#endregion | ||
| export { FetchEsque, HTTPHeaders, NativeFetchEsque, NonEmptyArray, Operation, OperationContext, OperationLink, OperationResultEnvelope, OperationResultObservable, OperationResultObserver, TRPCClientError, TRPCClientErrorBase, TRPCClientErrorLike, TRPCClientRuntime, TRPCFetch, TRPCLink, TRPCProcedureOptions, isFormData, isNonJsonSerializable, isOctetType, isTRPCClientError }; | ||
| //# sourceMappingURL=types.d-CAt1zKAY.d.mts.map |
| {"version":3,"file":"types.d-CAt1zKAY.d.mts","names":[],"sources":["../src/internals/types.ts","../src/TRPCClientError.ts","../src/links/internals/contentTypes.ts","../src/links/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AAOA;;AACS,KADG,UAAA,GACH,CAAA,KAAA,EAAA,WAAA,GAAc,GAAd,GAAA,MAAA,EAAA,IAAA,CAAA,EACA,WADA,GACc,gBADd,EAAA,GAEJ,OAFI,CAEI,aAFJ,CAAA;;;;;AAEJ,KAMO,gBAAA,GANP,CAAA,GAAA,EAOE,GAPF,GAAA,MAAA,EAAA,IAAA,CAAA,EAQI,yBARJ,EAAA,GASA,OATA,CASQ,aATR,CAAA;AAAO,UAWK,yBAAA,CAXL;EAMA,IAAA,CAAA,EAAA,MAAA;;;;;;AAGA;AAEZ;AAWA;AAAiC,UAAhB,gBAAA,CAAgB;EAAA;;;EAIa,IAAgB,CAAA,EAArD,QAAqD,GAAA,MAAA,GAAA,IAAA,GAA1B,UAA0B,CAAf,WAAe,CAAA,GAAA,IAAA,GAAO,IAAP;EAAI;;;EAe5C,OAAA,CAAA,EAAA,CAAA,MAAA,EAAA,MAAA,CAAA,EAAA,GAVW,MAUX,CAAA,MAAA,EAAA,MAAA,CAAA;EAOV;;;EAC6C,MAAtC,CAAA,EAAA,MAAA;EAA2B;AAG9C;AAWA;EAA8B,MAAA,CAAA,EAtBnB,WAsBmB,GAAA,SAAA;;;;AAQb;AAMjB;AAAyB,KA7Bb,sBAAA,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FK;;;AAG/B,KEgGP,QFhGO,CAAA,oBEgGsB,qBFhGtB,CAAA,GAAA,CAAA,IAAA,EEiGX,iBFjGW,EAAA,GEkGd,aFlGc,CEkGA,WFlGA,CAAA"} |
| import { TRPCConnectionState } from "./subscriptions.d-Dlr1nWGD.mjs"; | ||
| import { Operation, OperationResultEnvelope, TRPCClientError, TRPCLink } from "./types.d-CAt1zKAY.mjs"; | ||
| import { TransformerOptions } from "./unstable-internals.d-BOmV7EK1.mjs"; | ||
| import * as _trpc_server_observable0 from "@trpc/server/observable"; | ||
| import { BehaviorSubject } from "@trpc/server/observable"; | ||
| import { AnyRouter, CombinedDataTransformer, inferClientTypes } from "@trpc/server/unstable-core-do-not-import"; | ||
| import { AnyTRPCRouter } from "@trpc/server"; | ||
| import { TRPCRequestInfo } from "@trpc/server/http"; | ||
| //#region src/links/internals/urlWithConnectionParams.d.ts | ||
| /** | ||
| * A value that can be wrapped in callback | ||
| */ | ||
| type CallbackOrValue<T> = T | (() => T | Promise<T>); | ||
| interface UrlOptionsWithConnectionParams { | ||
| /** | ||
| * The URL to connect to (can be a function that returns a URL) | ||
| */ | ||
| url: CallbackOrValue<string>; | ||
| /** | ||
| * Connection params that are available in `createContext()` | ||
| * - For `wsLink`/`wsClient`, these are sent as the first message | ||
| * - For `httpSubscriptionLink`, these are serialized as part of the URL under the `connectionParams` query | ||
| */ | ||
| connectionParams?: CallbackOrValue<TRPCRequestInfo['connectionParams']>; | ||
| } | ||
| //# sourceMappingURL=urlWithConnectionParams.d.ts.map | ||
| //#endregion | ||
| //#region src/links/wsLink/wsClient/options.d.ts | ||
| interface WebSocketClientOptions extends UrlOptionsWithConnectionParams { | ||
| /** | ||
| * Ponyfill which WebSocket implementation to use | ||
| */ | ||
| WebSocket?: typeof WebSocket; | ||
| /** | ||
| * The number of milliseconds before a reconnect is attempted. | ||
| * @default {@link exponentialBackoff} | ||
| */ | ||
| retryDelayMs?: (attemptIndex: number) => number; | ||
| /** | ||
| * Triggered when a WebSocket connection is established | ||
| */ | ||
| onOpen?: () => void; | ||
| /** | ||
| * Triggered when a WebSocket connection encounters an error | ||
| */ | ||
| onError?: (evt?: Event) => void; | ||
| /** | ||
| * Triggered when a WebSocket connection is closed | ||
| */ | ||
| onClose?: (cause?: { | ||
| code?: number; | ||
| }) => void; | ||
| /** | ||
| * Lazy mode will close the WebSocket automatically after a period of inactivity (no messages sent or received and no pending requests) | ||
| */ | ||
| lazy?: { | ||
| /** | ||
| * Enable lazy mode | ||
| * @default false | ||
| */ | ||
| enabled: boolean; | ||
| /** | ||
| * Close the WebSocket after this many milliseconds | ||
| * @default 0 | ||
| */ | ||
| closeMs: number; | ||
| }; | ||
| /** | ||
| * Send ping messages to the server and kill the connection if no pong message is returned | ||
| */ | ||
| keepAlive?: { | ||
| /** | ||
| * @default false | ||
| */ | ||
| enabled: boolean; | ||
| /** | ||
| * Send a ping message every this many milliseconds | ||
| * @default 5_000 | ||
| */ | ||
| intervalMs?: number; | ||
| /** | ||
| * Close the WebSocket after this many milliseconds if the server does not respond | ||
| * @default 1_000 | ||
| */ | ||
| pongTimeoutMs?: number; | ||
| }; | ||
| } | ||
| /** | ||
| * Default options for lazy WebSocket connections. | ||
| * Determines whether the connection should be established lazily and defines the delay before closure. | ||
| */ | ||
| //#endregion | ||
| //#region src/links/wsLink/wsClient/wsClient.d.ts | ||
| /** | ||
| * A WebSocket client for managing TRPC operations, supporting lazy initialization, | ||
| * reconnection, keep-alive, and request management. | ||
| */ | ||
| declare class WsClient { | ||
| /** | ||
| * Observable tracking the current connection state, including errors. | ||
| */ | ||
| readonly connectionState: BehaviorSubject<TRPCConnectionState<TRPCClientError<AnyTRPCRouter>>>; | ||
| private allowReconnect; | ||
| private requestManager; | ||
| private readonly activeConnection; | ||
| private readonly reconnectRetryDelay; | ||
| private inactivityTimeout; | ||
| private readonly callbacks; | ||
| private readonly lazyMode; | ||
| constructor(opts: WebSocketClientOptions); | ||
| /** | ||
| * Opens the WebSocket connection. Handles reconnection attempts and updates | ||
| * the connection state accordingly. | ||
| */ | ||
| private open; | ||
| /** | ||
| * Closes the WebSocket connection and stops managing requests. | ||
| * Ensures all outgoing and pending requests are properly finalized. | ||
| */ | ||
| close(): Promise<void>; | ||
| /** | ||
| * Method to request the server. | ||
| * Handles data transformation, batching of requests, and subscription lifecycle. | ||
| * | ||
| * @param op - The operation details including id, type, path, input and signal | ||
| * @param transformer - Data transformer for serializing requests and deserializing responses | ||
| * @param lastEventId - Optional ID of the last received event for subscriptions | ||
| * | ||
| * @returns An observable that emits operation results and handles cleanup | ||
| */ | ||
| request({ | ||
| op: { | ||
| id, | ||
| type, | ||
| path, | ||
| input, | ||
| signal | ||
| }, | ||
| transformer, | ||
| lastEventId | ||
| }: { | ||
| op: Pick<Operation, 'id' | 'type' | 'path' | 'input' | 'signal'>; | ||
| transformer: CombinedDataTransformer; | ||
| lastEventId?: string; | ||
| }): _trpc_server_observable0.Observable<OperationResultEnvelope<unknown, TRPCClientError<AnyTRPCRouter>>, TRPCClientError<AnyTRPCRouter>>; | ||
| get connection(): { | ||
| readonly id: number; | ||
| readonly state: "open"; | ||
| readonly ws: WebSocket; | ||
| } | { | ||
| readonly id: number; | ||
| readonly state: "closed"; | ||
| readonly ws: WebSocket; | ||
| } | { | ||
| readonly id: number; | ||
| readonly state: "connecting"; | ||
| readonly ws: WebSocket; | ||
| } | null; | ||
| /** | ||
| * Manages the reconnection process for the WebSocket using retry logic. | ||
| * Ensures that only one reconnection attempt is active at a time by tracking the current | ||
| * reconnection state in the `reconnecting` promise. | ||
| */ | ||
| private reconnecting; | ||
| private reconnect; | ||
| private setupWebSocketListeners; | ||
| private handleResponseMessage; | ||
| private handleIncomingRequest; | ||
| /** | ||
| * Sends a message or batch of messages directly to the server. | ||
| */ | ||
| private send; | ||
| /** | ||
| * Groups requests for batch sending. | ||
| * | ||
| * @returns A function to abort the batched request. | ||
| */ | ||
| private batchSend; | ||
| } | ||
| //# sourceMappingURL=wsClient.d.ts.map | ||
| //#endregion | ||
| //#region src/links/wsLink/createWsClient.d.ts | ||
| declare function createWSClient(opts: WebSocketClientOptions): WsClient; | ||
| type TRPCWebSocketClient = ReturnType<typeof createWSClient>; | ||
| //#endregion | ||
| //#region src/links/wsLink/wsLink.d.ts | ||
| type WebSocketLinkOptions<TRouter extends AnyRouter> = { | ||
| client: TRPCWebSocketClient; | ||
| } & TransformerOptions<inferClientTypes<TRouter>>; | ||
| declare function wsLink<TRouter extends AnyRouter>(opts: WebSocketLinkOptions<TRouter>): TRPCLink<TRouter>; | ||
| //#endregion | ||
| export { TRPCWebSocketClient, UrlOptionsWithConnectionParams, WebSocketClientOptions, WebSocketLinkOptions, createWSClient, wsLink }; | ||
| //# sourceMappingURL=wsLink.d-Bssh2HIQ.d.mts.map |
| {"version":3,"file":"wsLink.d-Bssh2HIQ.d.mts","names":[],"sources":["../src/links/internals/urlWithConnectionParams.ts","../src/links/wsLink/wsClient/options.ts","../src/links/wsLink/wsClient/wsClient.ts","../src/links/wsLink/createWsClient.ts","../src/links/wsLink/wsLink.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;KAkBY,qBAAqB,WAAW,IAAI,QAAQ;AAA5C,UAEK,8BAAA,CAFU;EAAA;;;EAAkB,GAAW,EAMjD,eANiD,CAAA,MAAA,CAAA;EAAC;AAAF;AAEvD;;;EAIsB,gBAOe,CAAA,EAAhB,eAAgB,CAAA,eAAA,CAAA,kBAAA,CAAA,CAAA;;AAAD;;;UC7BnB,sBAAA,SAA+B;;;;qBAI3B;;;;;EDYT,YAAA,CAAA,EAAA,CAAA,YAAe,EAAA,MAAA,EAAA,GAAA,MAAA;EAAA;;;EAAkB,MAAW,CAAA,EAAA,GAAA,GAAA,IAAA;EAAC;AAAF;AAEvD;EAA+C,OAAA,CAAA,EAAA,CAAA,GAAA,CAAA,ECD5B,KDC4B,EAAA,GAAA,IAAA;EAAA;;;EAWX,OAAA,CAAA,EAAA,CAAA,MAAA,EAAA;;;;AC7BpC;;EAAwC,IAInB,CAA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,KAAA,EAAA,QAAA;IAAA,SAAA,EAAA,WAAA;EAAA,CAAA,GAAA;IAAA,SAAA,EAAA,EAAA,MAAA;IAAA,SAAA,KAAA,EAAA,YAAA;;;;;;;ACxLH;EAA8B,QAAA,YAAA;EAAA,QAAO,SAAA;EAAsB,QAAA,uBAAA;EAAA,QAAA,qBAAA;EAI/C,QAAA,qBAAmB;EAAA;;;EAAa,QAAA,IAAA;;;;ACO5C;;EAAgC,QAAiB,SAAA;;;;;iBDXjC,cAAA,OAAqB,yBAAsB;KAI/C,mBAAA,GAAsB,kBAAkB;;;KCOxC,qCAAqC;UACvC;IACN,mBAAmB,iBAAiB;iBAExB,uBAAuB,iBAC/B,qBAAqB,WAC1B,SAAS"} |
+7
-7
| import { TRPCConnectionState } from "./subscriptions.d-Dlr1nWGD.mjs"; | ||
| import { FetchEsque, HTTPHeaders, NativeFetchEsque, Operation, OperationContext, OperationLink, OperationResultEnvelope, OperationResultObservable, OperationResultObserver, TRPCClientError, TRPCClientErrorBase, TRPCClientErrorLike, TRPCClientRuntime, TRPCFetch, TRPCLink, TRPCProcedureOptions, isFormData, isNonJsonSerializable, isOctetType, isTRPCClientError } from "./types.d-ByL4iq_b.mjs"; | ||
| import { FetchEsque, HTTPHeaders, NativeFetchEsque, Operation, OperationContext, OperationLink, OperationResultEnvelope, OperationResultObservable, OperationResultObserver, TRPCClientError, TRPCClientErrorBase, TRPCClientErrorLike, TRPCClientRuntime, TRPCFetch, TRPCLink, TRPCProcedureOptions, isFormData, isNonJsonSerializable, isOctetType, isTRPCClientError } from "./types.d-CAt1zKAY.mjs"; | ||
| import { TransformerOptions } from "./unstable-internals.d-BOmV7EK1.mjs"; | ||
| import "./httpUtils.d-BordpgU5.mjs"; | ||
| import { HTTPBatchLinkOptions, httpBatchLink } from "./httpBatchLink.d-VqJm9adv.mjs"; | ||
| import { HTTPLinkOptions, httpLink } from "./httpLink.d-Cw8WgV_O.mjs"; | ||
| import { LoggerLinkOptions, loggerLink } from "./loggerLink.d-DNZv9tYh.mjs"; | ||
| import { splitLink } from "./splitLink.d-BQlbH9vp.mjs"; | ||
| import { TRPCWebSocketClient, UrlOptionsWithConnectionParams, WebSocketClientOptions, WebSocketLinkOptions, createWSClient, wsLink } from "./wsLink.d-em3USiMI.mjs"; | ||
| import "./httpUtils.d-akze5l4u.mjs"; | ||
| import { HTTPBatchLinkOptions, httpBatchLink } from "./httpBatchLink.d-B0jS5RCU.mjs"; | ||
| import { HTTPLinkOptions, httpLink } from "./httpLink.d-BEC5B7OH.mjs"; | ||
| import { LoggerLinkOptions, loggerLink } from "./loggerLink.d-B_ylo7O3.mjs"; | ||
| import { splitLink } from "./splitLink.d-Df2gT0RV.mjs"; | ||
| import { TRPCWebSocketClient, UrlOptionsWithConnectionParams, WebSocketClientOptions, WebSocketLinkOptions, createWSClient, wsLink } from "./wsLink.d-Bssh2HIQ.mjs"; | ||
| import { Unsubscribable } from "@trpc/server/observable"; | ||
@@ -11,0 +11,0 @@ import { AnyClientTypes, AnyProcedure, AnyRouter, ErrorHandlerOptions, EventSourceLike, InferrableClientTypes, ProcedureType, RouterRecord, TypeError, inferAsyncIterableYield, inferClientTypes, inferProcedureInput, inferRouterContext, inferTransformedProcedureOutput } from "@trpc/server/unstable-core-do-not-import"; |
+3
-3
| import { __commonJS, __toESM, require_defineProperty, require_objectSpread2 } from "./objectSpread2-BvkFp-_Y.mjs"; | ||
| import { createChain, splitLink } from "./splitLink-B7Cuf2c_.mjs"; | ||
| import { TRPCClientError, isTRPCClientError } from "./TRPCClientError-CjKyS10w.mjs"; | ||
| import { fetchHTTPResponse, getBody, getFetch, getUrl, resolveHTTPLinkOptions } from "./httpUtils-Dv57hbOd.mjs"; | ||
| import { httpLink, isFormData, isNonJsonSerializable, isOctetType } from "./httpLink-DCFpUmZF.mjs"; | ||
| import { abortSignalToPromise, allAbortSignals, dataLoader, httpBatchLink, raceAbortSignals } from "./httpBatchLink-BOe5aCcR.mjs"; | ||
| import { fetchHTTPResponse, getBody, getFetch, getUrl, resolveHTTPLinkOptions } from "./httpUtils-D61f8fkr.mjs"; | ||
| import { httpLink, isFormData, isNonJsonSerializable, isOctetType } from "./httpLink-CBOGz9wP.mjs"; | ||
| import { abortSignalToPromise, allAbortSignals, dataLoader, httpBatchLink, raceAbortSignals } from "./httpBatchLink-B2CqKGTi.mjs"; | ||
| import { getTransformer } from "./unstable-internals-Bg7n9BBj.mjs"; | ||
@@ -8,0 +8,0 @@ import { loggerLink } from "./loggerLink-ineCN1PO.mjs"; |
| import "../subscriptions.d-Dlr1nWGD.mjs"; | ||
| import "../types.d-ByL4iq_b.mjs"; | ||
| import "../types.d-CAt1zKAY.mjs"; | ||
| import "../unstable-internals.d-BOmV7EK1.mjs"; | ||
| import "../httpUtils.d-BordpgU5.mjs"; | ||
| import { httpBatchLink } from "../httpBatchLink.d-VqJm9adv.mjs"; | ||
| import "../httpUtils.d-akze5l4u.mjs"; | ||
| import { httpBatchLink } from "../httpBatchLink.d-B0jS5RCU.mjs"; | ||
| export { httpBatchLink }; |
| import "../objectSpread2-BvkFp-_Y.mjs"; | ||
| import "../TRPCClientError-CjKyS10w.mjs"; | ||
| import "../httpUtils-Dv57hbOd.mjs"; | ||
| import { httpBatchLink } from "../httpBatchLink-BOe5aCcR.mjs"; | ||
| import "../httpUtils-D61f8fkr.mjs"; | ||
| import { httpBatchLink } from "../httpBatchLink-B2CqKGTi.mjs"; | ||
| import "../unstable-internals-Bg7n9BBj.mjs"; | ||
| export { httpBatchLink }; |
| import "../subscriptions.d-Dlr1nWGD.mjs"; | ||
| import "../types.d-ByL4iq_b.mjs"; | ||
| import "../types.d-CAt1zKAY.mjs"; | ||
| import "../unstable-internals.d-BOmV7EK1.mjs"; | ||
| import "../httpUtils.d-BordpgU5.mjs"; | ||
| import { HTTPLinkOptions, httpLink } from "../httpLink.d-Cw8WgV_O.mjs"; | ||
| import "../httpUtils.d-akze5l4u.mjs"; | ||
| import { HTTPLinkOptions, httpLink } from "../httpLink.d-BEC5B7OH.mjs"; | ||
| export { HTTPLinkOptions, httpLink }; |
| import "../objectSpread2-BvkFp-_Y.mjs"; | ||
| import "../TRPCClientError-CjKyS10w.mjs"; | ||
| import "../httpUtils-Dv57hbOd.mjs"; | ||
| import { httpLink } from "../httpLink-DCFpUmZF.mjs"; | ||
| import "../httpUtils-D61f8fkr.mjs"; | ||
| import { httpLink } from "../httpLink-CBOGz9wP.mjs"; | ||
| import "../unstable-internals-Bg7n9BBj.mjs"; | ||
| export { httpLink }; |
| import "../subscriptions.d-Dlr1nWGD.mjs"; | ||
| import "../types.d-ByL4iq_b.mjs"; | ||
| import { LoggerLinkOptions, loggerLink } from "../loggerLink.d-DNZv9tYh.mjs"; | ||
| import "../types.d-CAt1zKAY.mjs"; | ||
| import { LoggerLinkOptions, loggerLink } from "../loggerLink.d-B_ylo7O3.mjs"; | ||
| export { LoggerLinkOptions, loggerLink }; |
| import "../subscriptions.d-Dlr1nWGD.mjs"; | ||
| import "../types.d-ByL4iq_b.mjs"; | ||
| import { splitLink } from "../splitLink.d-BQlbH9vp.mjs"; | ||
| import "../types.d-CAt1zKAY.mjs"; | ||
| import { splitLink } from "../splitLink.d-Df2gT0RV.mjs"; | ||
| export { splitLink }; |
| import "../../subscriptions.d-Dlr1nWGD.mjs"; | ||
| import "../../types.d-ByL4iq_b.mjs"; | ||
| import "../../types.d-CAt1zKAY.mjs"; | ||
| import "../../unstable-internals.d-BOmV7EK1.mjs"; | ||
| import { TRPCWebSocketClient, WebSocketClientOptions, WebSocketLinkOptions, createWSClient, wsLink } from "../../wsLink.d-em3USiMI.mjs"; | ||
| import { TRPCWebSocketClient, WebSocketClientOptions, WebSocketLinkOptions, createWSClient, wsLink } from "../../wsLink.d-Bssh2HIQ.mjs"; | ||
| export { TRPCWebSocketClient, WebSocketClientOptions, WebSocketLinkOptions, createWSClient, wsLink }; |
+4
-4
| { | ||
| "name": "@trpc/client", | ||
| "type": "module", | ||
| "version": "11.8.1-canary.13+e25dd1d02", | ||
| "version": "11.8.1-canary.14+599a99217", | ||
| "description": "The tRPC client library", | ||
@@ -115,7 +115,7 @@ "author": "KATT", | ||
| "peerDependencies": { | ||
| "@trpc/server": "11.8.1-canary.13+e25dd1d02", | ||
| "@trpc/server": "11.8.1-canary.14+599a99217", | ||
| "typescript": ">=5.7.2" | ||
| }, | ||
| "devDependencies": { | ||
| "@trpc/server": "11.8.1-canary.13+e25dd1d02", | ||
| "@trpc/server": "11.8.1-canary.14+599a99217", | ||
| "@types/isomorphic-fetch": "^0.0.39", | ||
@@ -139,3 +139,3 @@ "@types/node": "^22.13.5", | ||
| ], | ||
| "gitHead": "e25dd1d021a5236c7bdbfd2c9895862cb56fb3b4" | ||
| "gitHead": "599a99217946b247f31de040da778b222dd949a5" | ||
| } |
| import { __toESM, require_objectSpread2 } from "./objectSpread2-BvkFp-_Y.mjs"; | ||
| import { TRPCClientError } from "./TRPCClientError-CjKyS10w.mjs"; | ||
| import { getUrl, jsonHttpRequester, resolveHTTPLinkOptions } from "./httpUtils-Dv57hbOd.mjs"; | ||
| import { observable } from "@trpc/server/observable"; | ||
| import { transformResult } from "@trpc/server/unstable-core-do-not-import"; | ||
| //#region src/internals/dataLoader.ts | ||
| /** | ||
| * A function that should never be called unless we messed something up. | ||
| */ | ||
| const throwFatalError = () => { | ||
| throw new Error("Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new"); | ||
| }; | ||
| /** | ||
| * Dataloader that's very inspired by https://github.com/graphql/dataloader | ||
| * Less configuration, no caching, and allows you to cancel requests | ||
| * When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled | ||
| */ | ||
| function dataLoader(batchLoader) { | ||
| let pendingItems = null; | ||
| let dispatchTimer = null; | ||
| const destroyTimerAndPendingItems = () => { | ||
| clearTimeout(dispatchTimer); | ||
| dispatchTimer = null; | ||
| pendingItems = null; | ||
| }; | ||
| /** | ||
| * Iterate through the items and split them into groups based on the `batchLoader`'s validate function | ||
| */ | ||
| function groupItems(items) { | ||
| const groupedItems = [[]]; | ||
| let index = 0; | ||
| while (true) { | ||
| const item = items[index]; | ||
| if (!item) break; | ||
| const lastGroup = groupedItems[groupedItems.length - 1]; | ||
| if (item.aborted) { | ||
| var _item$reject; | ||
| (_item$reject = item.reject) === null || _item$reject === void 0 || _item$reject.call(item, new Error("Aborted")); | ||
| index++; | ||
| continue; | ||
| } | ||
| const isValid = batchLoader.validate(lastGroup.concat(item).map((it) => it.key)); | ||
| if (isValid) { | ||
| lastGroup.push(item); | ||
| index++; | ||
| continue; | ||
| } | ||
| if (lastGroup.length === 0) { | ||
| var _item$reject2; | ||
| (_item$reject2 = item.reject) === null || _item$reject2 === void 0 || _item$reject2.call(item, new Error("Input is too big for a single dispatch")); | ||
| index++; | ||
| continue; | ||
| } | ||
| groupedItems.push([]); | ||
| } | ||
| return groupedItems; | ||
| } | ||
| function dispatch() { | ||
| const groupedItems = groupItems(pendingItems); | ||
| destroyTimerAndPendingItems(); | ||
| for (const items of groupedItems) { | ||
| if (!items.length) continue; | ||
| const batch = { items }; | ||
| for (const item of items) item.batch = batch; | ||
| const promise = batchLoader.fetch(batch.items.map((_item) => _item.key)); | ||
| promise.then(async (result) => { | ||
| await Promise.all(result.map(async (valueOrPromise, index) => { | ||
| const item = batch.items[index]; | ||
| try { | ||
| var _item$resolve; | ||
| const value = await Promise.resolve(valueOrPromise); | ||
| (_item$resolve = item.resolve) === null || _item$resolve === void 0 || _item$resolve.call(item, value); | ||
| } catch (cause) { | ||
| var _item$reject3; | ||
| (_item$reject3 = item.reject) === null || _item$reject3 === void 0 || _item$reject3.call(item, cause); | ||
| } | ||
| item.batch = null; | ||
| item.reject = null; | ||
| item.resolve = null; | ||
| })); | ||
| for (const item of batch.items) { | ||
| var _item$reject4; | ||
| (_item$reject4 = item.reject) === null || _item$reject4 === void 0 || _item$reject4.call(item, new Error("Missing result")); | ||
| item.batch = null; | ||
| } | ||
| }).catch((cause) => { | ||
| for (const item of batch.items) { | ||
| var _item$reject5; | ||
| (_item$reject5 = item.reject) === null || _item$reject5 === void 0 || _item$reject5.call(item, cause); | ||
| item.batch = null; | ||
| } | ||
| }); | ||
| } | ||
| } | ||
| function load(key) { | ||
| var _dispatchTimer; | ||
| const item = { | ||
| aborted: false, | ||
| key, | ||
| batch: null, | ||
| resolve: throwFatalError, | ||
| reject: throwFatalError | ||
| }; | ||
| const promise = new Promise((resolve, reject) => { | ||
| var _pendingItems; | ||
| item.reject = reject; | ||
| item.resolve = resolve; | ||
| (_pendingItems = pendingItems) !== null && _pendingItems !== void 0 || (pendingItems = []); | ||
| pendingItems.push(item); | ||
| }); | ||
| (_dispatchTimer = dispatchTimer) !== null && _dispatchTimer !== void 0 || (dispatchTimer = setTimeout(dispatch)); | ||
| return promise; | ||
| } | ||
| return { load }; | ||
| } | ||
| //#endregion | ||
| //#region src/internals/signals.ts | ||
| /** | ||
| * Like `Promise.all()` but for abort signals | ||
| * - When all signals have been aborted, the merged signal will be aborted | ||
| * - If one signal is `null`, no signal will be aborted | ||
| */ | ||
| function allAbortSignals(...signals) { | ||
| const ac = new AbortController(); | ||
| const count = signals.length; | ||
| let abortedCount = 0; | ||
| const onAbort = () => { | ||
| if (++abortedCount === count) ac.abort(); | ||
| }; | ||
| for (const signal of signals) if (signal === null || signal === void 0 ? void 0 : signal.aborted) onAbort(); | ||
| else signal === null || signal === void 0 || signal.addEventListener("abort", onAbort, { once: true }); | ||
| return ac.signal; | ||
| } | ||
| /** | ||
| * Like `Promise.race` but for abort signals | ||
| * | ||
| * Basically, a ponyfill for | ||
| * [`AbortSignal.any`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static). | ||
| */ | ||
| function raceAbortSignals(...signals) { | ||
| const ac = new AbortController(); | ||
| for (const signal of signals) if (signal === null || signal === void 0 ? void 0 : signal.aborted) ac.abort(); | ||
| else signal === null || signal === void 0 || signal.addEventListener("abort", () => ac.abort(), { once: true }); | ||
| return ac.signal; | ||
| } | ||
| function abortSignalToPromise(signal) { | ||
| return new Promise((_, reject) => { | ||
| if (signal.aborted) { | ||
| reject(signal.reason); | ||
| return; | ||
| } | ||
| signal.addEventListener("abort", () => { | ||
| reject(signal.reason); | ||
| }, { once: true }); | ||
| }); | ||
| } | ||
| //#endregion | ||
| //#region src/links/httpBatchLink.ts | ||
| var import_objectSpread2 = __toESM(require_objectSpread2(), 1); | ||
| /** | ||
| * @see https://trpc.io/docs/client/links/httpBatchLink | ||
| */ | ||
| function httpBatchLink(opts) { | ||
| var _opts$maxURLLength, _opts$maxItems; | ||
| const resolvedOpts = resolveHTTPLinkOptions(opts); | ||
| const maxURLLength = (_opts$maxURLLength = opts.maxURLLength) !== null && _opts$maxURLLength !== void 0 ? _opts$maxURLLength : Infinity; | ||
| const maxItems = (_opts$maxItems = opts.maxItems) !== null && _opts$maxItems !== void 0 ? _opts$maxItems : Infinity; | ||
| return () => { | ||
| const batchLoader = (type) => { | ||
| return { | ||
| validate(batchOps) { | ||
| if (maxURLLength === Infinity && maxItems === Infinity) return true; | ||
| if (batchOps.length > maxItems) return false; | ||
| const path = batchOps.map((op) => op.path).join(","); | ||
| const inputs = batchOps.map((op) => op.input); | ||
| const url = getUrl((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, resolvedOpts), {}, { | ||
| type, | ||
| path, | ||
| inputs, | ||
| signal: null | ||
| })); | ||
| return url.length <= maxURLLength; | ||
| }, | ||
| async fetch(batchOps) { | ||
| const path = batchOps.map((op) => op.path).join(","); | ||
| const inputs = batchOps.map((op) => op.input); | ||
| const signal = allAbortSignals(...batchOps.map((op) => op.signal)); | ||
| const res = await jsonHttpRequester((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, resolvedOpts), {}, { | ||
| path, | ||
| inputs, | ||
| type, | ||
| headers() { | ||
| if (!opts.headers) return {}; | ||
| if (typeof opts.headers === "function") return opts.headers({ opList: batchOps }); | ||
| return opts.headers; | ||
| }, | ||
| signal | ||
| })); | ||
| const resJSON = Array.isArray(res.json) ? res.json : batchOps.map(() => res.json); | ||
| const result = resJSON.map((item) => ({ | ||
| meta: res.meta, | ||
| json: item | ||
| })); | ||
| return result; | ||
| } | ||
| }; | ||
| }; | ||
| const query = dataLoader(batchLoader("query")); | ||
| const mutation = dataLoader(batchLoader("mutation")); | ||
| const loaders = { | ||
| query, | ||
| mutation | ||
| }; | ||
| return ({ op }) => { | ||
| return observable((observer) => { | ||
| /* istanbul ignore if -- @preserve */ | ||
| if (op.type === "subscription") throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`"); | ||
| const loader = loaders[op.type]; | ||
| const promise = loader.load(op); | ||
| let _res = void 0; | ||
| promise.then((res) => { | ||
| _res = res; | ||
| const transformed = transformResult(res.json, resolvedOpts.transformer.output); | ||
| if (!transformed.ok) { | ||
| observer.error(TRPCClientError.from(transformed.error, { meta: res.meta })); | ||
| return; | ||
| } | ||
| observer.next({ | ||
| context: res.meta, | ||
| result: transformed.result | ||
| }); | ||
| observer.complete(); | ||
| }).catch((err) => { | ||
| observer.error(TRPCClientError.from(err, { meta: _res === null || _res === void 0 ? void 0 : _res.meta })); | ||
| }); | ||
| return () => {}; | ||
| }); | ||
| }; | ||
| }; | ||
| } | ||
| //#endregion | ||
| export { abortSignalToPromise, allAbortSignals, dataLoader, httpBatchLink, raceAbortSignals }; | ||
| //# sourceMappingURL=httpBatchLink-BOe5aCcR.mjs.map |
| {"version":3,"file":"httpBatchLink-BOe5aCcR.mjs","names":["batchLoader: BatchLoader<TKey, TValue>","pendingItems: BatchItem<TKey, TValue>[] | null","dispatchTimer: ReturnType<typeof setTimeout> | null","items: BatchItem<TKey, TValue>[]","groupedItems: BatchItem<TKey, TValue>[][]","batch: Batch<TKey, TValue>","key: TKey","item: BatchItem<TKey, TValue>","signal: AbortSignal","opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>","type: ProcedureType"],"sources":["../src/internals/dataLoader.ts","../src/internals/signals.ts","../src/links/httpBatchLink.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\ntype BatchItem<TKey, TValue> = {\n aborted: boolean;\n key: TKey;\n resolve: ((value: TValue) => void) | null;\n reject: ((error: Error) => void) | null;\n batch: Batch<TKey, TValue> | null;\n};\ntype Batch<TKey, TValue> = {\n items: BatchItem<TKey, TValue>[];\n};\nexport type BatchLoader<TKey, TValue> = {\n validate: (keys: TKey[]) => boolean;\n fetch: (keys: TKey[]) => Promise<TValue[] | Promise<TValue>[]>;\n};\n\n/**\n * A function that should never be called unless we messed something up.\n */\nconst throwFatalError = () => {\n throw new Error(\n 'Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new',\n );\n};\n\n/**\n * Dataloader that's very inspired by https://github.com/graphql/dataloader\n * Less configuration, no caching, and allows you to cancel requests\n * When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled\n */\nexport function dataLoader<TKey, TValue>(\n batchLoader: BatchLoader<TKey, TValue>,\n) {\n let pendingItems: BatchItem<TKey, TValue>[] | null = null;\n let dispatchTimer: ReturnType<typeof setTimeout> | null = null;\n\n const destroyTimerAndPendingItems = () => {\n clearTimeout(dispatchTimer as any);\n dispatchTimer = null;\n pendingItems = null;\n };\n\n /**\n * Iterate through the items and split them into groups based on the `batchLoader`'s validate function\n */\n function groupItems(items: BatchItem<TKey, TValue>[]) {\n const groupedItems: BatchItem<TKey, TValue>[][] = [[]];\n let index = 0;\n while (true) {\n const item = items[index];\n if (!item) {\n // we're done\n break;\n }\n const lastGroup = groupedItems[groupedItems.length - 1]!;\n\n if (item.aborted) {\n // Item was aborted before it was dispatched\n item.reject?.(new Error('Aborted'));\n index++;\n continue;\n }\n\n const isValid = batchLoader.validate(\n lastGroup.concat(item).map((it) => it.key),\n );\n\n if (isValid) {\n lastGroup.push(item);\n index++;\n continue;\n }\n\n if (lastGroup.length === 0) {\n item.reject?.(new Error('Input is too big for a single dispatch'));\n index++;\n continue;\n }\n // Create new group, next iteration will try to add the item to that\n groupedItems.push([]);\n }\n return groupedItems;\n }\n\n function dispatch() {\n const groupedItems = groupItems(pendingItems!);\n destroyTimerAndPendingItems();\n\n // Create batches for each group of items\n for (const items of groupedItems) {\n if (!items.length) {\n continue;\n }\n const batch: Batch<TKey, TValue> = {\n items,\n };\n for (const item of items) {\n item.batch = batch;\n }\n const promise = batchLoader.fetch(batch.items.map((_item) => _item.key));\n\n promise\n .then(async (result) => {\n await Promise.all(\n result.map(async (valueOrPromise, index) => {\n const item = batch.items[index]!;\n try {\n const value = await Promise.resolve(valueOrPromise);\n\n item.resolve?.(value);\n } catch (cause) {\n item.reject?.(cause as Error);\n }\n\n item.batch = null;\n item.reject = null;\n item.resolve = null;\n }),\n );\n\n for (const item of batch.items) {\n item.reject?.(new Error('Missing result'));\n item.batch = null;\n }\n })\n .catch((cause) => {\n for (const item of batch.items) {\n item.reject?.(cause);\n item.batch = null;\n }\n });\n }\n }\n function load(key: TKey): Promise<TValue> {\n const item: BatchItem<TKey, TValue> = {\n aborted: false,\n key,\n batch: null,\n resolve: throwFatalError,\n reject: throwFatalError,\n };\n\n const promise = new Promise<TValue>((resolve, reject) => {\n item.reject = reject;\n item.resolve = resolve;\n\n pendingItems ??= [];\n pendingItems.push(item);\n });\n\n dispatchTimer ??= setTimeout(dispatch);\n\n return promise;\n }\n\n return {\n load,\n };\n}\n","import type { 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 { 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 } from '../internals/signals';\nimport type { NonEmptyArray } from '../internals/types';\nimport { TRPCClientError } from '../TRPCClientError';\nimport type { HTTPBatchLinkOptions } from './HTTPBatchLinkOptions';\nimport type { HTTPResult } from './internals/httpUtils';\nimport {\n getUrl,\n jsonHttpRequester,\n resolveHTTPLinkOptions,\n} from './internals/httpUtils';\nimport type { Operation, TRPCLink } from './types';\n\n/**\n * @see https://trpc.io/docs/client/links/httpBatchLink\n */\nexport function httpBatchLink<TRouter extends AnyRouter>(\n opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>,\n): TRPCLink<TRouter> {\n const resolvedOpts = resolveHTTPLinkOptions(opts);\n const maxURLLength = opts.maxURLLength ?? Infinity;\n const maxItems = opts.maxItems ?? Infinity;\n\n return () => {\n const batchLoader = (\n type: ProcedureType,\n ): BatchLoader<Operation, HTTPResult> => {\n return {\n validate(batchOps) {\n if (maxURLLength === Infinity && maxItems === Infinity) {\n // escape hatch for quick calcs\n return true;\n }\n if (batchOps.length > maxItems) {\n return false;\n }\n const path = batchOps.map((op) => op.path).join(',');\n const inputs = batchOps.map((op) => op.input);\n\n const url = getUrl({\n ...resolvedOpts,\n type,\n path,\n inputs,\n signal: null,\n });\n\n return url.length <= maxURLLength;\n },\n async fetch(batchOps) {\n const path = batchOps.map((op) => op.path).join(',');\n const inputs = batchOps.map((op) => op.input);\n const signal = allAbortSignals(...batchOps.map((op) => op.signal));\n\n const res = await jsonHttpRequester({\n ...resolvedOpts,\n path,\n inputs,\n type,\n headers() {\n if (!opts.headers) {\n return {};\n }\n if (typeof opts.headers === 'function') {\n return opts.headers({\n opList: batchOps as NonEmptyArray<Operation>,\n });\n }\n return opts.headers;\n },\n signal,\n });\n const resJSON = Array.isArray(res.json)\n ? res.json\n : batchOps.map(() => res.json);\n const result = resJSON.map((item) => ({\n meta: res.meta,\n json: item,\n }));\n return result;\n },\n };\n };\n\n const query = dataLoader(batchLoader('query'));\n const mutation = dataLoader(batchLoader('mutation'));\n\n const loaders = { query, mutation };\n return ({ op }) => {\n return observable((observer) => {\n /* istanbul ignore if -- @preserve */\n if (op.type === 'subscription') {\n throw new Error(\n 'Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`',\n );\n }\n const loader = loaders[op.type];\n const promise = loader.load(op);\n\n let _res = undefined as HTTPResult | undefined;\n promise\n .then((res) => {\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 observer.error(\n TRPCClientError.from(err, {\n meta: _res?.meta,\n }),\n );\n });\n\n return () => {\n // noop\n };\n });\n };\n };\n}\n"],"mappings":";;;;;;;;;;AAoBA,MAAM,kBAAkB,MAAM;AAC5B,OAAM,IAAI,MACR;AAEH;;;;;;AAOD,SAAgB,WACdA,aACA;CACA,IAAIC,eAAiD;CACrD,IAAIC,gBAAsD;CAE1D,MAAM,8BAA8B,MAAM;AACxC,eAAa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M,QAAQ,WAAW,YAAY,QAAQ,CAAC;EAC9C,MAAM,WAAW,WAAW,YAAY,WAAW,CAAC;EAEpD,MAAM,UAAU;GAAE;GAAO;EAAU;AACnC,SAAO,CAAC,EAAE,IAAI,KAAK;AACjB,UAAO,WAAW,CAAC,aAAa;;AAE9B,QAAI,GAAG,SAAS,eACd,OAAM,IAAI,MACR;IAGJ,MAAM,SAAS,QAAQ,GAAG;IAC1B,MAAM,UAAU,OAAO,KAAK,GAAG;IAE/B,IAAI;AACJ,YACG,KAAK,CAAC,QAAQ;AACb,YAAO;KACP,MAAM,cAAc,gBAClB,IAAI,MACJ,aAAa,YAAY,OAC1B;AAED,UAAK,YAAY,IAAI;AACnB,eAAS,MACP,gBAAgB,KAAK,YAAY,OAAO,EACtC,MAAM,IAAI,KACX,EAAC,CACH;AACD;KACD;AACD,cAAS,KAAK;MACZ,SAAS,IAAI;MACb,QAAQ,YAAY;KACrB,EAAC;AACF,cAAS,UAAU;IACpB,EAAC,CACD,MAAM,CAAC,QAAQ;AACd,cAAS,MACP,gBAAgB,KAAK,KAAK,EACxB,kDAAM,KAAM,KACb,EAAC,CACH;IACF,EAAC;AAEJ,WAAO,MAAM,CAEZ;GACF,EAAC;EACH;CACF;AACF"} |
| import { HTTPHeaders, NonEmptyArray, Operation, TRPCLink } from "./types.d-ByL4iq_b.mjs"; | ||
| import { HTTPLinkBaseOptions } from "./httpUtils.d-BordpgU5.mjs"; | ||
| import { AnyClientTypes } from "@trpc/server/unstable-core-do-not-import"; | ||
| import { AnyRouter as AnyRouter$1 } from "@trpc/server"; | ||
| //#region src/links/HTTPBatchLinkOptions.d.ts | ||
| type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TRoot> & { | ||
| maxURLLength?: number; | ||
| /** | ||
| * Headers to be set on outgoing requests or a callback that of said headers | ||
| * @see http://trpc.io/docs/client/headers | ||
| */ | ||
| headers?: HTTPHeaders | ((opts: { | ||
| opList: NonEmptyArray<Operation>; | ||
| }) => HTTPHeaders | Promise<HTTPHeaders>); | ||
| /** | ||
| * Maximum number of calls in a single batch request | ||
| * @default Infinity | ||
| */ | ||
| maxItems?: number; | ||
| }; | ||
| //# sourceMappingURL=HTTPBatchLinkOptions.d.ts.map | ||
| //#endregion | ||
| //#region src/links/httpBatchLink.d.ts | ||
| /** | ||
| * @see https://trpc.io/docs/client/links/httpBatchLink | ||
| */ | ||
| declare function httpBatchLink<TRouter extends AnyRouter$1>(opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>; | ||
| //# sourceMappingURL=httpBatchLink.d.ts.map | ||
| //#endregion | ||
| export { HTTPBatchLinkOptions, httpBatchLink }; | ||
| //# sourceMappingURL=httpBatchLink.d-VqJm9adv.d.mts.map |
| {"version":3,"file":"httpBatchLink.d-VqJm9adv.d.mts","names":[],"sources":["../src/links/HTTPBatchLinkOptions.ts","../src/links/httpBatchLink.ts"],"sourcesContent":[],"mappings":";;;;;;KAKY,mCAAmC,kBAC7C,oBAAoB;;EADV;;;;EACe,OAAzB,CAAA,EAOM,WAPN,GAAA,CAAA,CAAA,IAAA,EAAA;IAOM,MAAA,EAEU,aAFV,CAEwB,SAFxB,CAAA;EAAW,CAAA,EAEa,GAClB,WADkB,GACJ,OADI,CACI,WADJ,CAAA,CAAA;EAAS;;;;EACN,QAAA,CAAA,EAAA,MAAA;;;;;;;;AAXvB,iBCeI,aDfgB,CAAA,gBCec,WDfd,CAAA,CAAA,IAAA,ECgBxB,oBDhBwB,CCgBH,ODhBG,CAAA,MAAA,CAAA,CAAA,SAAA,CAAA,CAAA,QAAA,CAAA,CAAA,CAAA,ECiB7B,QDjB6B,CCiBpB,ODjBoB,CAAA"} |
| import { __toESM, require_objectSpread2 } from "./objectSpread2-BvkFp-_Y.mjs"; | ||
| import { TRPCClientError } from "./TRPCClientError-CjKyS10w.mjs"; | ||
| import { getUrl, httpRequest, jsonHttpRequester, resolveHTTPLinkOptions } from "./httpUtils-Dv57hbOd.mjs"; | ||
| import { observable } from "@trpc/server/observable"; | ||
| import { transformResult } from "@trpc/server/unstable-core-do-not-import"; | ||
| //#region src/links/internals/contentTypes.ts | ||
| function isOctetType(input) { | ||
| return input instanceof Uint8Array || input instanceof Blob; | ||
| } | ||
| function isFormData(input) { | ||
| return input instanceof FormData; | ||
| } | ||
| function isNonJsonSerializable(input) { | ||
| return isOctetType(input) || isFormData(input); | ||
| } | ||
| //#endregion | ||
| //#region src/links/httpLink.ts | ||
| var import_objectSpread2 = __toESM(require_objectSpread2(), 1); | ||
| const universalRequester = (opts) => { | ||
| if ("input" in opts) { | ||
| const { input } = opts; | ||
| if (isFormData(input)) { | ||
| if (opts.type !== "mutation" && opts.methodOverride !== "POST") throw new Error("FormData is only supported for mutations"); | ||
| return httpRequest((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts), {}, { | ||
| contentTypeHeader: void 0, | ||
| getUrl, | ||
| getBody: () => input | ||
| })); | ||
| } | ||
| if (isOctetType(input)) { | ||
| if (opts.type !== "mutation" && opts.methodOverride !== "POST") throw new Error("Octet type input is only supported for mutations"); | ||
| return httpRequest((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts), {}, { | ||
| contentTypeHeader: "application/octet-stream", | ||
| getUrl, | ||
| getBody: () => input | ||
| })); | ||
| } | ||
| } | ||
| return jsonHttpRequester(opts); | ||
| }; | ||
| /** | ||
| * @see https://trpc.io/docs/client/links/httpLink | ||
| */ | ||
| function httpLink(opts) { | ||
| const resolvedOpts = resolveHTTPLinkOptions(opts); | ||
| return () => { | ||
| return (operationOpts) => { | ||
| const { op } = operationOpts; | ||
| return observable((observer) => { | ||
| const { path, input, type } = op; | ||
| /* istanbul ignore if -- @preserve */ | ||
| if (type === "subscription") throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`"); | ||
| const request = universalRequester((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, resolvedOpts), {}, { | ||
| type, | ||
| path, | ||
| input, | ||
| signal: op.signal, | ||
| headers() { | ||
| if (!opts.headers) return {}; | ||
| if (typeof opts.headers === "function") return opts.headers({ op }); | ||
| return opts.headers; | ||
| } | ||
| })); | ||
| let meta = void 0; | ||
| request.then((res) => { | ||
| meta = res.meta; | ||
| const transformed = transformResult(res.json, resolvedOpts.transformer.output); | ||
| if (!transformed.ok) { | ||
| observer.error(TRPCClientError.from(transformed.error, { meta })); | ||
| return; | ||
| } | ||
| observer.next({ | ||
| context: res.meta, | ||
| result: transformed.result | ||
| }); | ||
| observer.complete(); | ||
| }).catch((cause) => { | ||
| observer.error(TRPCClientError.from(cause, { meta })); | ||
| }); | ||
| return () => {}; | ||
| }); | ||
| }; | ||
| }; | ||
| } | ||
| //#endregion | ||
| export { httpLink, isFormData, isNonJsonSerializable, isOctetType }; | ||
| //# sourceMappingURL=httpLink-DCFpUmZF.mjs.map |
| {"version":3,"file":"httpLink-DCFpUmZF.mjs","names":["input: unknown","universalRequester: Requester","opts: HTTPLinkOptions<TRouter['_def']['_config']['$types']>","meta: HTTPResult['meta'] | undefined"],"sources":["../src/links/internals/contentTypes.ts","../src/links/httpLink.ts"],"sourcesContent":["export function isOctetType(\n input: unknown,\n): input is Uint8Array<ArrayBuffer> | Blob {\n return (\n input instanceof Uint8Array ||\n // File extends from Blob but is only available in nodejs from v20\n input instanceof Blob\n );\n}\n\nexport function isFormData(input: unknown) {\n return input instanceof FormData;\n}\n\nexport function isNonJsonSerializable(input: unknown) {\n return isOctetType(input) || isFormData(input);\n}\n","import { observable } from '@trpc/server/observable';\nimport type {\n AnyClientTypes,\n AnyRouter,\n} from '@trpc/server/unstable-core-do-not-import';\nimport { transformResult } from '@trpc/server/unstable-core-do-not-import';\nimport { TRPCClientError } from '../TRPCClientError';\nimport type {\n HTTPLinkBaseOptions,\n HTTPResult,\n Requester,\n} from './internals/httpUtils';\nimport {\n getUrl,\n httpRequest,\n jsonHttpRequester,\n resolveHTTPLinkOptions,\n} from './internals/httpUtils';\nimport {\n isFormData,\n isOctetType,\n type HTTPHeaders,\n type Operation,\n type TRPCLink,\n} from './types';\n\nexport type HTTPLinkOptions<TRoot extends AnyClientTypes> =\n HTTPLinkBaseOptions<TRoot> & {\n /**\n * Headers to be set on outgoing requests or a callback that of said headers\n * @see http://trpc.io/docs/client/headers\n */\n headers?:\n | HTTPHeaders\n | ((opts: { op: Operation }) => HTTPHeaders | Promise<HTTPHeaders>);\n };\n\nconst universalRequester: Requester = (opts) => {\n if ('input' in opts) {\n const { input } = opts;\n if (isFormData(input)) {\n if (opts.type !== 'mutation' && opts.methodOverride !== 'POST') {\n throw new Error('FormData is only supported for mutations');\n }\n\n return httpRequest({\n ...opts,\n // The browser will set this automatically and include the boundary= in it\n contentTypeHeader: undefined,\n getUrl,\n getBody: () => input,\n });\n }\n\n if (isOctetType(input)) {\n if (opts.type !== 'mutation' && opts.methodOverride !== 'POST') {\n throw new Error('Octet type input is only supported for mutations');\n }\n\n return httpRequest({\n ...opts,\n contentTypeHeader: 'application/octet-stream',\n getUrl,\n getBody: () => input,\n });\n }\n }\n\n return jsonHttpRequester(opts);\n};\n\n/**\n * @see https://trpc.io/docs/client/links/httpLink\n */\nexport function httpLink<TRouter extends AnyRouter = AnyRouter>(\n opts: HTTPLinkOptions<TRouter['_def']['_config']['$types']>,\n): TRPCLink<TRouter> {\n const resolvedOpts = resolveHTTPLinkOptions(opts);\n return () => {\n return (operationOpts) => {\n const { op } = operationOpts;\n return observable((observer) => {\n const { path, input, type } = op;\n /* istanbul ignore if -- @preserve */\n if (type === 'subscription') {\n throw new Error(\n 'Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`',\n );\n }\n\n const request = universalRequester({\n ...resolvedOpts,\n type,\n path,\n input,\n signal: op.signal,\n headers() {\n if (!opts.headers) {\n return {};\n }\n if (typeof opts.headers === 'function') {\n return opts.headers({\n op,\n });\n }\n return opts.headers;\n },\n });\n let meta: HTTPResult['meta'] | undefined = undefined;\n request\n .then((res) => {\n meta = res.meta;\n const transformed = transformResult(\n res.json,\n resolvedOpts.transformer.output,\n );\n\n if (!transformed.ok) {\n observer.error(\n TRPCClientError.from(transformed.error, {\n meta,\n }),\n );\n return;\n }\n observer.next({\n context: res.meta,\n result: transformed.result,\n });\n observer.complete();\n })\n .catch((cause) => {\n observer.error(TRPCClientError.from(cause, { meta }));\n });\n\n return () => {\n // noop\n };\n });\n };\n };\n}\n"],"mappings":";;;;;;;AAAA,SAAgB,YACdA,OACyC;AACzC,QACE,iBAAiB,cAEjB,iBAAiB;AAEpB;AAED,SAAgB,WAAWA,OAAgB;AACzC,QAAO,iBAAiB;AACzB;AAED,SAAgB,sBAAsBA,OAAgB;AACpD,QAAO,YAAY,MAAM,IAAI,WAAW,MAAM;AAC/C;;;;;ACqBD,MAAMC,qBAAgC,CAAC,SAAS;AAC9C,KAAI,WAAW,MAAM;EACnB,MAAM,EAAE,OAAO,GAAG;AAClB,MAAI,WAAW,MAAM,EAAE;AACrB,OAAI,KAAK,SAAS,cAAc,KAAK,mBAAmB,OACtD,OAAM,IAAI,MAAM;AAGlB,UAAO,oFACF;IAEH;IACA;IACA,SAAS,MAAM;MACf;EACH;AAED,MAAI,YAAY,MAAM,EAAE;AACtB,OAAI,KAAK,SAAS,cAAc,KAAK,mBAAmB,OACtD,OAAM,IAAI,MAAM;AAGlB,UAAO,oFACF;IACH,mBAAmB;IACnB;IACA,SAAS,MAAM;MACf;EACH;CACF;AAED,QAAO,kBAAkB,KAAK;AAC/B;;;;AAKD,SAAgB,SACdC,MACmB;CACnB,MAAM,eAAe,uBAAuB,KAAK;AACjD,QAAO,MAAM;AACX,SAAO,CAAC,kBAAkB;GACxB,MAAM,EAAE,IAAI,GAAG;AACf,UAAO,WAAW,CAAC,aAAa;IAC9B,MAAM,EAAE,MAAM,OAAO,MAAM,GAAG;;AAE9B,QAAI,SAAS,eACX,OAAM,IAAI,MACR;IAIJ,MAAM,UAAU,2FACX;KACH;KACA;KACA;KACA,QAAQ,GAAG;KACX,UAAU;AACR,WAAK,KAAK,QACR,QAAO,CAAE;AAEX,iBAAW,KAAK,YAAY,WAC1B,QAAO,KAAK,QAAQ,EAClB,GACD,EAAC;AAEJ,aAAO,KAAK;KACb;OACD;IACF,IAAIC;AACJ,YACG,KAAK,CAAC,QAAQ;AACb,YAAO,IAAI;KACX,MAAM,cAAc,gBAClB,IAAI,MACJ,aAAa,YAAY,OAC1B;AAED,UAAK,YAAY,IAAI;AACnB,eAAS,MACP,gBAAgB,KAAK,YAAY,OAAO,EACtC,KACD,EAAC,CACH;AACD;KACD;AACD,cAAS,KAAK;MACZ,SAAS,IAAI;MACb,QAAQ,YAAY;KACrB,EAAC;AACF,cAAS,UAAU;IACpB,EAAC,CACD,MAAM,CAAC,UAAU;AAChB,cAAS,MAAM,gBAAgB,KAAK,OAAO,EAAE,KAAM,EAAC,CAAC;IACtD,EAAC;AAEJ,WAAO,MAAM,CAEZ;GACF,EAAC;EACH;CACF;AACF"} |
| import { HTTPHeaders, Operation, TRPCLink } from "./types.d-ByL4iq_b.mjs"; | ||
| import { HTTPLinkBaseOptions } from "./httpUtils.d-BordpgU5.mjs"; | ||
| import { AnyClientTypes, AnyRouter } from "@trpc/server/unstable-core-do-not-import"; | ||
| //#region src/links/httpLink.d.ts | ||
| type HTTPLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TRoot> & { | ||
| /** | ||
| * Headers to be set on outgoing requests or a callback that of said headers | ||
| * @see http://trpc.io/docs/client/headers | ||
| */ | ||
| headers?: HTTPHeaders | ((opts: { | ||
| op: Operation; | ||
| }) => HTTPHeaders | Promise<HTTPHeaders>); | ||
| }; | ||
| /** | ||
| * @see https://trpc.io/docs/client/links/httpLink | ||
| */ | ||
| declare function httpLink<TRouter extends AnyRouter = AnyRouter>(opts: HTTPLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>; | ||
| //# sourceMappingURL=httpLink.d.ts.map | ||
| //#endregion | ||
| export { HTTPLinkOptions, httpLink }; | ||
| //# sourceMappingURL=httpLink.d-Cw8WgV_O.d.mts.map |
| {"version":3,"file":"httpLink.d-Cw8WgV_O.d.mts","names":[],"sources":["../src/links/httpLink.ts"],"sourcesContent":[],"mappings":";;;;;KA0BY,8BAA8B,kBACxC,oBAAoB;;AADtB;;;EAAwD,OAClC,CAAA,EAMd,WANc,GAAA,CAAA,CAAA,IAAA,EAAA;IAApB,EAAA,EAOoB,SAPpB;EAAmB,CAAA,EAMb,GAC8B,WAD9B,GAC4C,OAD5C,CACoD,WADpD,CAAA,CAAA;CAAW;;;;AACwC,iBAwC3C,QAxC2C,CAAA,gBAwClB,SAxCkB,GAwCN,SAxCM,CAAA,CAAA,IAAA,EAyCnD,eAzCmD,CAyCnC,OAzCmC,CAAA,MAAA,CAAA,CAAA,SAAA,CAAA,CAAA,QAAA,CAAA,CAAA,CAAA,EA0CxD,QA1CwD,CA0C/C,OA1C+C,CAAA;AAwC3D"} |
| import { __toESM, require_objectSpread2 } from "./objectSpread2-BvkFp-_Y.mjs"; | ||
| import { getTransformer } from "./unstable-internals-Bg7n9BBj.mjs"; | ||
| //#region src/getFetch.ts | ||
| const isFunction = (fn) => typeof fn === "function"; | ||
| function getFetch(customFetchImpl) { | ||
| if (customFetchImpl) return customFetchImpl; | ||
| if (typeof window !== "undefined" && isFunction(window.fetch)) return window.fetch; | ||
| if (typeof globalThis !== "undefined" && isFunction(globalThis.fetch)) return globalThis.fetch; | ||
| throw new Error("No fetch implementation found"); | ||
| } | ||
| //#endregion | ||
| //#region src/links/internals/httpUtils.ts | ||
| var import_objectSpread2 = __toESM(require_objectSpread2(), 1); | ||
| function resolveHTTPLinkOptions(opts) { | ||
| return { | ||
| url: opts.url.toString(), | ||
| fetch: opts.fetch, | ||
| transformer: getTransformer(opts.transformer), | ||
| methodOverride: opts.methodOverride | ||
| }; | ||
| } | ||
| function arrayToDict(array) { | ||
| const dict = {}; | ||
| for (let index = 0; index < array.length; index++) { | ||
| const element = array[index]; | ||
| dict[index] = element; | ||
| } | ||
| return dict; | ||
| } | ||
| const METHOD = { | ||
| query: "GET", | ||
| mutation: "POST", | ||
| subscription: "PATCH" | ||
| }; | ||
| function getInput(opts) { | ||
| return "input" in opts ? opts.transformer.input.serialize(opts.input) : arrayToDict(opts.inputs.map((_input) => opts.transformer.input.serialize(_input))); | ||
| } | ||
| const getUrl = (opts) => { | ||
| const parts = opts.url.split("?"); | ||
| const base = parts[0].replace(/\/$/, ""); | ||
| let url = base + "/" + opts.path; | ||
| const queryParts = []; | ||
| if (parts[1]) queryParts.push(parts[1]); | ||
| if ("inputs" in opts) queryParts.push("batch=1"); | ||
| if (opts.type === "query" || opts.type === "subscription") { | ||
| const input = getInput(opts); | ||
| if (input !== void 0 && opts.methodOverride !== "POST") queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`); | ||
| } | ||
| if (queryParts.length) url += "?" + queryParts.join("&"); | ||
| return url; | ||
| }; | ||
| const getBody = (opts) => { | ||
| if (opts.type === "query" && opts.methodOverride !== "POST") return void 0; | ||
| const input = getInput(opts); | ||
| return input !== void 0 ? JSON.stringify(input) : void 0; | ||
| }; | ||
| const jsonHttpRequester = (opts) => { | ||
| return httpRequest((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts), {}, { | ||
| contentTypeHeader: "application/json", | ||
| getUrl, | ||
| getBody | ||
| })); | ||
| }; | ||
| /** | ||
| * Polyfill for DOMException with AbortError name | ||
| */ | ||
| var AbortError = class extends Error { | ||
| constructor() { | ||
| const name = "AbortError"; | ||
| super(name); | ||
| this.name = name; | ||
| this.message = name; | ||
| } | ||
| }; | ||
| /** | ||
| * Polyfill for `signal.throwIfAborted()` | ||
| * | ||
| * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/throwIfAborted | ||
| */ | ||
| const throwIfAborted = (signal) => { | ||
| var _signal$throwIfAborte; | ||
| if (!(signal === null || signal === void 0 ? void 0 : signal.aborted)) return; | ||
| (_signal$throwIfAborte = signal.throwIfAborted) === null || _signal$throwIfAborte === void 0 || _signal$throwIfAborte.call(signal); | ||
| if (typeof DOMException !== "undefined") throw new DOMException("AbortError", "AbortError"); | ||
| throw new AbortError(); | ||
| }; | ||
| async function fetchHTTPResponse(opts) { | ||
| var _opts$methodOverride; | ||
| throwIfAborted(opts.signal); | ||
| const url = opts.getUrl(opts); | ||
| const body = opts.getBody(opts); | ||
| const method = (_opts$methodOverride = opts.methodOverride) !== null && _opts$methodOverride !== void 0 ? _opts$methodOverride : METHOD[opts.type]; | ||
| const resolvedHeaders = await (async () => { | ||
| const heads = await opts.headers(); | ||
| if (Symbol.iterator in heads) return Object.fromEntries(heads); | ||
| return heads; | ||
| })(); | ||
| const headers = (0, import_objectSpread2.default)((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, opts.contentTypeHeader && method !== "GET" ? { "content-type": opts.contentTypeHeader } : {}), opts.trpcAcceptHeader ? { "trpc-accept": opts.trpcAcceptHeader } : void 0), resolvedHeaders); | ||
| return getFetch(opts.fetch)(url, { | ||
| method, | ||
| signal: opts.signal, | ||
| body, | ||
| headers | ||
| }); | ||
| } | ||
| async function httpRequest(opts) { | ||
| const meta = {}; | ||
| const res = await fetchHTTPResponse(opts); | ||
| meta.response = res; | ||
| const json = await res.json(); | ||
| meta.responseJSON = json; | ||
| return { | ||
| json, | ||
| meta | ||
| }; | ||
| } | ||
| //#endregion | ||
| export { fetchHTTPResponse, getBody, getFetch, getUrl, httpRequest, jsonHttpRequester, resolveHTTPLinkOptions }; | ||
| //# sourceMappingURL=httpUtils-Dv57hbOd.mjs.map |
| {"version":3,"file":"httpUtils-Dv57hbOd.mjs","names":["fn: unknown","customFetchImpl?: FetchEsque | NativeFetchEsque","opts: HTTPLinkBaseOptions<AnyClientTypes>","array: unknown[]","dict: Record<number, unknown>","opts: GetInputOptions","getUrl: GetUrl","queryParts: string[]","getBody: GetBody","jsonHttpRequester: Requester","signal: Maybe<AbortSignal>","opts: HTTPRequestOptions"],"sources":["../src/getFetch.ts","../src/links/internals/httpUtils.ts"],"sourcesContent":["import type { FetchEsque, NativeFetchEsque } from './internals/types';\n\ntype AnyFn = (...args: any[]) => unknown;\n\nconst isFunction = (fn: unknown): fn is AnyFn => typeof fn === 'function';\n\nexport function getFetch(\n customFetchImpl?: FetchEsque | NativeFetchEsque,\n): FetchEsque {\n if (customFetchImpl) {\n return customFetchImpl as FetchEsque;\n }\n\n if (typeof window !== 'undefined' && isFunction(window.fetch)) {\n return window.fetch as FetchEsque;\n }\n\n if (typeof globalThis !== 'undefined' && isFunction(globalThis.fetch)) {\n return globalThis.fetch as FetchEsque;\n }\n\n throw new Error('No fetch implementation found');\n}\n","import type {\n AnyClientTypes,\n CombinedDataTransformer,\n Maybe,\n ProcedureType,\n TRPCAcceptHeader,\n TRPCResponse,\n} from '@trpc/server/unstable-core-do-not-import';\nimport { getFetch } from '../../getFetch';\nimport type {\n FetchEsque,\n RequestInitEsque,\n ResponseEsque,\n} from '../../internals/types';\nimport type { TransformerOptions } from '../../unstable-internals';\nimport { getTransformer } from '../../unstable-internals';\nimport type { HTTPHeaders } from '../types';\n\n/**\n * @internal\n */\nexport type HTTPLinkBaseOptions<\n TRoot extends Pick<AnyClientTypes, 'transformer'>,\n> = {\n url: string | URL;\n /**\n * Add ponyfill for fetch\n */\n fetch?: FetchEsque;\n /**\n * Send all requests `as POST`s requests regardless of the procedure type\n * The HTTP handler must separately allow overriding the method. See:\n * @see https://trpc.io/docs/rpc\n */\n methodOverride?: 'POST';\n} & TransformerOptions<TRoot>;\n\nexport interface ResolvedHTTPLinkOptions {\n url: string;\n fetch?: FetchEsque;\n transformer: CombinedDataTransformer;\n methodOverride?: 'POST';\n}\n\nexport function resolveHTTPLinkOptions(\n opts: HTTPLinkBaseOptions<AnyClientTypes>,\n): ResolvedHTTPLinkOptions {\n return {\n url: opts.url.toString(),\n fetch: opts.fetch,\n transformer: getTransformer(opts.transformer),\n methodOverride: opts.methodOverride,\n };\n}\n\n// https://github.com/trpc/trpc/pull/669\nfunction arrayToDict(array: unknown[]) {\n const dict: Record<number, unknown> = {};\n for (let index = 0; index < array.length; index++) {\n const element = array[index];\n dict[index] = element;\n }\n return dict;\n}\n\nconst METHOD = {\n query: 'GET',\n mutation: 'POST',\n subscription: 'PATCH',\n} as const;\n\nexport interface HTTPResult {\n json: TRPCResponse;\n meta: {\n response: ResponseEsque;\n responseJSON?: unknown;\n };\n}\n\ntype GetInputOptions = {\n transformer: CombinedDataTransformer;\n} & ({ input: unknown } | { inputs: unknown[] });\n\nexport function getInput(opts: GetInputOptions) {\n return 'input' in opts\n ? opts.transformer.input.serialize(opts.input)\n : arrayToDict(\n opts.inputs.map((_input) => opts.transformer.input.serialize(_input)),\n );\n}\n\nexport type HTTPBaseRequestOptions = GetInputOptions &\n ResolvedHTTPLinkOptions & {\n type: ProcedureType;\n path: string;\n signal: Maybe<AbortSignal>;\n };\n\ntype GetUrl = (opts: HTTPBaseRequestOptions) => string;\ntype GetBody = (opts: HTTPBaseRequestOptions) => RequestInitEsque['body'];\n\nexport type ContentOptions = {\n trpcAcceptHeader?: TRPCAcceptHeader;\n contentTypeHeader?: string;\n getUrl: GetUrl;\n getBody: GetBody;\n};\n\nexport const getUrl: GetUrl = (opts) => {\n const parts = opts.url.split('?') as [string, string?];\n const base = parts[0].replace(/\\/$/, ''); // Remove any trailing slashes\n\n let url = base + '/' + opts.path;\n const queryParts: string[] = [];\n\n if (parts[1]) {\n queryParts.push(parts[1]);\n }\n if ('inputs' in opts) {\n queryParts.push('batch=1');\n }\n if (opts.type === 'query' || opts.type === 'subscription') {\n const input = getInput(opts);\n if (input !== undefined && opts.methodOverride !== 'POST') {\n queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`);\n }\n }\n if (queryParts.length) {\n url += '?' + queryParts.join('&');\n }\n return url;\n};\n\nexport const getBody: GetBody = (opts) => {\n if (opts.type === 'query' && opts.methodOverride !== 'POST') {\n return undefined;\n }\n const input = getInput(opts);\n return input !== undefined ? JSON.stringify(input) : undefined;\n};\n\nexport type Requester = (\n opts: HTTPBaseRequestOptions & {\n headers: () => HTTPHeaders | Promise<HTTPHeaders>;\n },\n) => Promise<HTTPResult>;\n\nexport const jsonHttpRequester: Requester = (opts) => {\n return httpRequest({\n ...opts,\n contentTypeHeader: 'application/json',\n getUrl,\n getBody,\n });\n};\n\n/**\n * Polyfill for DOMException with AbortError name\n */\nclass AbortError extends Error {\n constructor() {\n const name = 'AbortError';\n super(name);\n this.name = name;\n this.message = name;\n }\n}\n\nexport type HTTPRequestOptions = ContentOptions &\n HTTPBaseRequestOptions & {\n headers: () => HTTPHeaders | Promise<HTTPHeaders>;\n };\n\n/**\n * Polyfill for `signal.throwIfAborted()`\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/throwIfAborted\n */\nconst throwIfAborted = (signal: Maybe<AbortSignal>) => {\n if (!signal?.aborted) {\n return;\n }\n // If available, use the native implementation\n signal.throwIfAborted?.();\n\n // If we have `DOMException`, use it\n if (typeof DOMException !== 'undefined') {\n throw new DOMException('AbortError', 'AbortError');\n }\n\n // Otherwise, use our own implementation\n throw new AbortError();\n};\n\nexport async function fetchHTTPResponse(opts: HTTPRequestOptions) {\n throwIfAborted(opts.signal);\n\n const url = opts.getUrl(opts);\n const body = opts.getBody(opts);\n const method = opts.methodOverride ?? METHOD[opts.type];\n const resolvedHeaders = await (async () => {\n const heads = await opts.headers();\n if (Symbol.iterator in heads) {\n return Object.fromEntries(heads);\n }\n return heads;\n })();\n const headers = {\n ...(opts.contentTypeHeader && method !== 'GET'\n ? { 'content-type': opts.contentTypeHeader }\n : {}),\n ...(opts.trpcAcceptHeader\n ? { '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,aAAa,CAACA,cAAoC,OAAO;AAE/D,SAAgB,SACdC,iBACY;AACZ,KAAI,gBACF,QAAO;AAGT,YAAW,WAAW,eAAe,WAAW,OAAO,MAAM,CAC3D,QAAO,OAAO;AAGhB,YAAW,eAAe,eAAe,WAAW,WAAW,MAAM,CACnE,QAAO,WAAW;AAGpB,OAAM,IAAI,MAAM;AACjB;;;;;ACsBD,SAAgB,uBACdC,MACyB;AACzB,QAAO;EACL,KAAK,KAAK,IAAI,UAAU;EACxB,OAAO,KAAK;EACZ,aAAa,eAAe,KAAK,YAAY;EAC7C,gBAAgB,KAAK;CACtB;AACF;AAGD,SAAS,YAAYC,OAAkB;CACrC,MAAMC,OAAgC,CAAE;AACxC,MAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS;EACjD,MAAM,UAAU,MAAM;AACtB,OAAK,SAAS;CACf;AACD,QAAO;AACR;AAED,MAAM,SAAS;CACb,OAAO;CACP,UAAU;CACV,cAAc;AACf;AAcD,SAAgB,SAASC,MAAuB;AAC9C,QAAO,WAAW,OACd,KAAK,YAAY,MAAM,UAAU,KAAK,MAAM,GAC5C,YACE,KAAK,OAAO,IAAI,CAAC,WAAW,KAAK,YAAY,MAAM,UAAU,OAAO,CAAC,CACtE;AACN;AAmBD,MAAaC,SAAiB,CAAC,SAAS;CACtC,MAAM,QAAQ,KAAK,IAAI,MAAM,IAAI;CACjC,MAAM,OAAO,MAAM,GAAG,QAAQ,OAAO,GAAG;CAExC,IAAI,MAAM,OAAO,MAAM,KAAK;CAC5B,MAAMC,aAAuB,CAAE;AAE/B,KAAI,MAAM,GACR,YAAW,KAAK,MAAM,GAAG;AAE3B,KAAI,YAAY,KACd,YAAW,KAAK,UAAU;AAE5B,KAAI,KAAK,SAAS,WAAW,KAAK,SAAS,gBAAgB;EACzD,MAAM,QAAQ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MAAM,CAAC,KAAK;EAC/B;EACA,QAAQ,KAAK;EACb;EACA;CACD,EAAC;AACH;AAED,eAAsB,YACpBA,MACqB;CACrB,MAAM,OAAO,CAAE;CAEf,MAAM,MAAM,MAAM,kBAAkB,KAAK;AACzC,MAAK,WAAW;CAEhB,MAAM,OAAO,MAAM,IAAI,MAAM;AAE7B,MAAK,eAAe;AAEpB,QAAO;EACC;EACN;CACD;AACF"} |
| import { FetchEsque } from "./types.d-ByL4iq_b.mjs"; | ||
| import { TransformerOptions } from "./unstable-internals.d-BOmV7EK1.mjs"; | ||
| import { AnyClientTypes, CombinedDataTransformer, Maybe, ProcedureType } from "@trpc/server/unstable-core-do-not-import"; | ||
| //#region src/links/internals/httpUtils.d.ts | ||
| /** | ||
| * @internal | ||
| */ | ||
| type HTTPLinkBaseOptions<TRoot extends Pick<AnyClientTypes, 'transformer'>> = { | ||
| url: string | URL; | ||
| /** | ||
| * Add ponyfill for fetch | ||
| */ | ||
| fetch?: FetchEsque; | ||
| /** | ||
| * Send all requests `as POST`s requests regardless of the procedure type | ||
| * The HTTP handler must separately allow overriding the method. See: | ||
| * @see https://trpc.io/docs/rpc | ||
| */ | ||
| methodOverride?: 'POST'; | ||
| } & TransformerOptions<TRoot>; | ||
| //#endregion | ||
| export { HTTPLinkBaseOptions }; | ||
| //# sourceMappingURL=httpUtils.d-BordpgU5.d.mts.map |
| {"version":3,"file":"httpUtils.d-BordpgU5.d.mts","names":[],"sources":["../src/links/internals/httpUtils.ts"],"sourcesContent":[],"mappings":";;;;;;;AAqBA;;AACqB,KADT,mBACS,CAAA,cAAL,IAAK,CAAA,cAAA,EAAA,aAAA,CAAA,CAAA,GAAA;EAAc,GAAnB,EAAA,MAAA,GAEA,GAFA;EAAI;;;EAaQ,KAAxB,CAAA,EAPM,UAON;EAAkB;;;;;;IAAlB,mBAAmB"} |
| import { Operation, OperationResultEnvelope, TRPCClientError, TRPCLink } from "./types.d-ByL4iq_b.mjs"; | ||
| import { AnyRouter, InferrableClientTypes } from "@trpc/server/unstable-core-do-not-import"; | ||
| //#region src/links/loggerLink.d.ts | ||
| type ConsoleEsque = { | ||
| log: (...args: any[]) => void; | ||
| error: (...args: any[]) => void; | ||
| }; | ||
| type EnableFnOptions<TRouter extends InferrableClientTypes> = { | ||
| direction: 'down'; | ||
| result: OperationResultEnvelope<unknown, TRPCClientError<TRouter>> | TRPCClientError<TRouter>; | ||
| } | (Operation & { | ||
| direction: 'up'; | ||
| }); | ||
| type EnabledFn<TRouter extends AnyRouter> = (opts: EnableFnOptions<TRouter>) => boolean; | ||
| type LoggerLinkFnOptions<TRouter extends AnyRouter> = Operation & ({ | ||
| /** | ||
| * Request result | ||
| */ | ||
| direction: 'down'; | ||
| result: OperationResultEnvelope<unknown, TRPCClientError<TRouter>> | TRPCClientError<TRouter>; | ||
| elapsedMs: number; | ||
| } | { | ||
| /** | ||
| * Request was just initialized | ||
| */ | ||
| direction: 'up'; | ||
| }); | ||
| type LoggerLinkFn<TRouter extends AnyRouter> = (opts: LoggerLinkFnOptions<TRouter>) => void; | ||
| type ColorMode = 'ansi' | 'css' | 'none'; | ||
| interface LoggerLinkOptions<TRouter extends AnyRouter> { | ||
| logger?: LoggerLinkFn<TRouter>; | ||
| enabled?: EnabledFn<TRouter>; | ||
| /** | ||
| * Used in the built-in defaultLogger | ||
| */ | ||
| console?: ConsoleEsque; | ||
| /** | ||
| * Color mode | ||
| * @default typeof window === 'undefined' ? 'ansi' : 'css' | ||
| */ | ||
| colorMode?: ColorMode; | ||
| /** | ||
| * Include context in the log - defaults to false unless `colorMode` is 'css' | ||
| */ | ||
| withContext?: boolean; | ||
| } | ||
| /** | ||
| * @see https://trpc.io/docs/v11/client/links/loggerLink | ||
| */ | ||
| declare function loggerLink<TRouter extends AnyRouter = AnyRouter>(opts?: LoggerLinkOptions<TRouter>): TRPCLink<TRouter>; | ||
| //#endregion | ||
| export { LoggerLinkOptions, loggerLink }; | ||
| //# sourceMappingURL=loggerLink.d-DNZv9tYh.d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SARK,CAQK,OARL,CAAA;EAAA;;;EACkB,OAA3B,CAAA,EAWI,YAXJ;EAAmB;AAAA;AAK3B;;EAAkC,SAAiB,CAAA,EAWrC,SAXqC;EAAS;;;EAE/B,WAAjB,CAAA,EAAA,OAAA;;;AASW;AA8IvB;AAA0B,iBAAV,UAAU,CAAA,gBAAiB,SAAjB,GAA6B,SAA7B,CAAA,CAAA,IAAA,CAAA,EAClB,iBADkB,CACA,OADA,CAAA,CAAA,EAEvB,QAFuB,CAEd,OAFc,CAAA"} |
| import { Operation, TRPCLink } from "./types.d-ByL4iq_b.mjs"; | ||
| import { AnyRouter } from "@trpc/server/unstable-core-do-not-import"; | ||
| //#region src/links/splitLink.d.ts | ||
| declare function splitLink<TRouter extends AnyRouter = AnyRouter>(opts: { | ||
| condition: (op: Operation) => boolean; | ||
| /** | ||
| * The link to execute next if the test function returns `true`. | ||
| */ | ||
| true: TRPCLink<TRouter> | TRPCLink<TRouter>[]; | ||
| /** | ||
| * The link to execute next if the test function returns `false`. | ||
| */ | ||
| false: TRPCLink<TRouter> | TRPCLink<TRouter>[]; | ||
| }): TRPCLink<TRouter>; | ||
| //# sourceMappingURL=splitLink.d.ts.map | ||
| //#endregion | ||
| export { splitLink }; | ||
| //# sourceMappingURL=splitLink.d-BQlbH9vp.d.mts.map |
| {"version":3,"file":"splitLink.d-BQlbH9vp.d.mts","names":[],"sources":["../src/links/splitLink.ts"],"sourcesContent":[],"mappings":";;;;iBAQgB,0BAA0B,YAAY;kBACpC;EADF;;;EAAmC,IAAG,EAK9C,QAL8C,CAKrC,OALqC,CAAA,GAK1B,QAL0B,CAKjB,OALiB,CAAA,EAAA;EAAS;;;EAK/C,KAAqB,EAI5B,QAJ4B,CAInB,OAJmB,CAAA,GAIR,QAJQ,CAIC,OAJD,CAAA,EAAA;CAAO,CAAA,EAKxC,QALwB,CAKf,OALe,CAAA"} |
| import { TRPCConnectionState } from "./subscriptions.d-Dlr1nWGD.mjs"; | ||
| import { Observable, Observer } from "@trpc/server/observable"; | ||
| import { DefaultErrorShape, InferrableClientTypes, Maybe, TRPCErrorResponse, TRPCResultMessage, TRPCSuccessResponse, inferClientTypes } from "@trpc/server/unstable-core-do-not-import"; | ||
| //#region src/internals/types.d.ts | ||
| /** | ||
| * A subset of the standard fetch function type needed by tRPC internally. | ||
| * @see fetch from lib.dom.d.ts | ||
| * @remarks | ||
| * If you need a property that you know exists but doesn't exist on this | ||
| * interface, go ahead and add it. | ||
| */ | ||
| type FetchEsque = (input: RequestInfo | URL | string, init?: RequestInit | RequestInitEsque) => Promise<ResponseEsque>; | ||
| /** | ||
| * A simpler version of the native fetch function's type for packages with | ||
| * their own fetch types, such as undici and node-fetch. | ||
| */ | ||
| type NativeFetchEsque = (url: URL | string, init?: NodeFetchRequestInitEsque) => Promise<ResponseEsque>; | ||
| interface NodeFetchRequestInitEsque { | ||
| body?: string; | ||
| } | ||
| /** | ||
| * A subset of the standard RequestInit properties needed by tRPC internally. | ||
| * @see RequestInit from lib.dom.d.ts | ||
| * @remarks | ||
| * If you need a property that you know exists but doesn't exist on this | ||
| * interface, go ahead and add it. | ||
| */ | ||
| interface RequestInitEsque { | ||
| /** | ||
| * Sets the request's body. | ||
| */ | ||
| body?: FormData | string | null | Uint8Array<ArrayBuffer> | Blob | File; | ||
| /** | ||
| * Sets the request's associated headers. | ||
| */ | ||
| headers?: [string, string][] | Record<string, string>; | ||
| /** | ||
| * The request's HTTP-style method. | ||
| */ | ||
| method?: string; | ||
| /** | ||
| * Sets the request's signal. | ||
| */ | ||
| signal?: AbortSignal | undefined; | ||
| } | ||
| /** | ||
| * A subset of the standard ReadableStream properties needed by tRPC internally. | ||
| * @see ReadableStream from lib.dom.d.ts | ||
| */ | ||
| type WebReadableStreamEsque = { | ||
| getReader: () => ReadableStreamDefaultReader<Uint8Array>; | ||
| }; | ||
| type NodeJSReadableStreamEsque = { | ||
| on(eventName: string | symbol, listener: (...args: any[]) => void): NodeJSReadableStreamEsque; | ||
| }; | ||
| /** | ||
| * A subset of the standard Response properties needed by tRPC internally. | ||
| * @see Response from lib.dom.d.ts | ||
| */ | ||
| interface ResponseEsque { | ||
| readonly body?: NodeJSReadableStreamEsque | WebReadableStreamEsque | null; | ||
| /** | ||
| * @remarks | ||
| * The built-in Response::json() method returns Promise<any>, but | ||
| * that's not as type-safe as unknown. We use unknown because we're | ||
| * more type-safe. You do want more type safety, right? 😉 | ||
| */ | ||
| json(): Promise<unknown>; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| type NonEmptyArray<TItem> = [TItem, ...TItem[]]; | ||
| type ClientContext = Record<string, unknown>; | ||
| /** | ||
| * @public | ||
| */ | ||
| interface TRPCProcedureOptions { | ||
| /** | ||
| * Client-side context | ||
| */ | ||
| context?: ClientContext; | ||
| signal?: AbortSignal; | ||
| } | ||
| //#endregion | ||
| //#region src/TRPCClientError.d.ts | ||
| type inferErrorShape<TInferrable extends InferrableClientTypes> = inferClientTypes<TInferrable>['errorShape']; | ||
| interface TRPCClientErrorBase<TShape extends DefaultErrorShape> { | ||
| readonly message: string; | ||
| readonly shape: Maybe<TShape>; | ||
| readonly data: Maybe<TShape['data']>; | ||
| } | ||
| type TRPCClientErrorLike<TInferrable extends InferrableClientTypes> = TRPCClientErrorBase<inferErrorShape<TInferrable>>; | ||
| declare function isTRPCClientError<TInferrable extends InferrableClientTypes>(cause: unknown): cause is TRPCClientError<TInferrable>; | ||
| declare class TRPCClientError<TRouterOrProcedure extends InferrableClientTypes> extends Error implements TRPCClientErrorBase<inferErrorShape<TRouterOrProcedure>> { | ||
| readonly cause: Error | undefined; | ||
| readonly shape: Maybe<inferErrorShape<TRouterOrProcedure>>; | ||
| readonly data: Maybe<inferErrorShape<TRouterOrProcedure>['data']>; | ||
| /** | ||
| * Additional meta data about the error | ||
| * In the case of HTTP-errors, we'll have `response` and potentially `responseJSON` here | ||
| */ | ||
| meta: Record<string, unknown> | undefined; | ||
| constructor(message: string, opts?: { | ||
| result?: Maybe<TRPCErrorResponse<inferErrorShape<TRouterOrProcedure>>>; | ||
| cause?: Error; | ||
| meta?: Record<string, unknown>; | ||
| }); | ||
| static from<TRouterOrProcedure extends InferrableClientTypes>(_cause: Error | TRPCErrorResponse<any> | object, opts?: { | ||
| meta?: Record<string, unknown>; | ||
| }): TRPCClientError<TRouterOrProcedure>; | ||
| } | ||
| //#endregion | ||
| //#region src/links/internals/contentTypes.d.ts | ||
| declare function isOctetType(input: unknown): input is Uint8Array<ArrayBuffer> | Blob; | ||
| declare function isFormData(input: unknown): input is FormData; | ||
| declare function isNonJsonSerializable(input: unknown): input is FormData | Uint8Array<ArrayBuffer> | Blob; | ||
| //# sourceMappingURL=contentTypes.d.ts.map | ||
| //#endregion | ||
| //#region src/links/types.d.ts | ||
| /** | ||
| * @internal | ||
| */ | ||
| interface OperationContext extends Record<string, unknown> {} | ||
| /** | ||
| * @internal | ||
| */ | ||
| type Operation<TInput = unknown> = { | ||
| id: number; | ||
| type: 'mutation' | 'query' | 'subscription'; | ||
| input: TInput; | ||
| path: string; | ||
| context: OperationContext; | ||
| signal: Maybe<AbortSignal>; | ||
| }; | ||
| interface HeadersInitEsque { | ||
| [Symbol.iterator](): IterableIterator<[string, string]>; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| type HTTPHeaders = HeadersInitEsque | Record<string, string[] | string | undefined>; | ||
| /** | ||
| * The default `fetch` implementation has an overloaded signature. By convention this library | ||
| * only uses the overload taking a string and options object. | ||
| */ | ||
| type TRPCFetch = (url: string, options?: RequestInit) => Promise<ResponseEsque>; | ||
| interface TRPCClientRuntime {} | ||
| /** | ||
| * @internal | ||
| */ | ||
| interface OperationResultEnvelope<TOutput, TError> { | ||
| result: TRPCResultMessage<TOutput>['result'] | TRPCSuccessResponse<TOutput>['result'] | TRPCConnectionState<TError>; | ||
| context?: OperationContext; | ||
| } | ||
| /** | ||
| * @internal | ||
| */ | ||
| type OperationResultObservable<TInferrable extends InferrableClientTypes, TOutput> = Observable<OperationResultEnvelope<TOutput, TRPCClientError<TInferrable>>, TRPCClientError<TInferrable>>; | ||
| /** | ||
| * @internal | ||
| */ | ||
| type OperationResultObserver<TInferrable extends InferrableClientTypes, TOutput> = Observer<OperationResultEnvelope<TOutput, TRPCClientError<TInferrable>>, TRPCClientError<TInferrable>>; | ||
| /** | ||
| * @internal | ||
| */ | ||
| type OperationLink<TInferrable extends InferrableClientTypes, TInput = unknown, TOutput = unknown> = (opts: { | ||
| op: Operation<TInput>; | ||
| next: (op: Operation<TInput>) => OperationResultObservable<TInferrable, TOutput>; | ||
| }) => OperationResultObservable<TInferrable, TOutput>; | ||
| /** | ||
| * @public | ||
| */ | ||
| type TRPCLink<TInferrable extends InferrableClientTypes> = (opts: TRPCClientRuntime) => OperationLink<TInferrable>; | ||
| //# sourceMappingURL=types.d.ts.map | ||
| //#endregion | ||
| export { FetchEsque, HTTPHeaders, NativeFetchEsque, NonEmptyArray, Operation, OperationContext, OperationLink, OperationResultEnvelope, OperationResultObservable, OperationResultObserver, TRPCClientError, TRPCClientErrorBase, TRPCClientErrorLike, TRPCClientRuntime, TRPCFetch, TRPCLink, TRPCProcedureOptions, isFormData, isNonJsonSerializable, isOctetType, isTRPCClientError }; | ||
| //# sourceMappingURL=types.d-ByL4iq_b.d.mts.map |
| {"version":3,"file":"types.d-ByL4iq_b.d.mts","names":[],"sources":["../src/internals/types.ts","../src/TRPCClientError.ts","../src/links/internals/contentTypes.ts","../src/links/types.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;AAOA;;AACS,KADG,UAAA,GACH,CAAA,KAAA,EAAA,WAAA,GAAc,GAAd,GAAA,MAAA,EAAA,IAAA,CAAA,EACA,WADA,GACc,gBADd,EAAA,GAEJ,OAFI,CAEI,aAFJ,CAAA;;;;;AAEJ,KAMO,gBAAA,GANP,CAAA,GAAA,EAOE,GAPF,GAAA,MAAA,EAAA,IAAA,CAAA,EAQI,yBARJ,EAAA,GASA,OATA,CASQ,aATR,CAAA;AAAO,UAWK,yBAAA,CAXL;EAMA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WkC,CGXV,OHWU,EGXD,eHWC,CGXe,WHWf,CAAA,CAAA,EGVlC,eHUkC,CGVlB,WHUkB,CAAA,CAAA;;AAAe;AAAI;AAOtC,KGXL,uBHWyB,CAAA,oBGVf,qBHUe,EAAA,OAAA,CAAA,GGRjC,QHQiC,CGPnC,uBHOmC,CGPX,OHOW,EGPF,eHOE,CGPc,WHOd,CAAA,CAAA,EGNnC,eHMmC,CGNnB,WHMmB,CAAA,CAAA;;;;AAKf,KGLV,aHKU,CAAA,oBGJA,qBHIA,EAAA,SAAA,OAAA,EAAA,UAAA,OAAA,CAAA,GAAA,CAAA,IAAA,EAAA;MGAhB,UAAU;aAER,UAAU,YACX,0BAA0B,aAAa;MACxC,0BAA0B,aAAa;AF9FK;;;AAG/B,KEgGP,QFhGO,CAAA,oBEgGsB,qBFhGtB,CAAA,GAAA,CAAA,IAAA,EEiGX,iBFjGW,EAAA,GEkGd,aFlGc,CEkGA,WFlGA,CAAA"} |
| import { TRPCConnectionState } from "./subscriptions.d-Dlr1nWGD.mjs"; | ||
| import { Operation, OperationResultEnvelope, TRPCClientError, TRPCLink } from "./types.d-ByL4iq_b.mjs"; | ||
| import { TransformerOptions } from "./unstable-internals.d-BOmV7EK1.mjs"; | ||
| import * as _trpc_server_observable0 from "@trpc/server/observable"; | ||
| import { BehaviorSubject } from "@trpc/server/observable"; | ||
| import { AnyRouter, CombinedDataTransformer, inferClientTypes } from "@trpc/server/unstable-core-do-not-import"; | ||
| import { AnyTRPCRouter } from "@trpc/server"; | ||
| import { TRPCRequestInfo } from "@trpc/server/http"; | ||
| //#region src/links/internals/urlWithConnectionParams.d.ts | ||
| /** | ||
| * A value that can be wrapped in callback | ||
| */ | ||
| type CallbackOrValue<T> = T | (() => T | Promise<T>); | ||
| interface UrlOptionsWithConnectionParams { | ||
| /** | ||
| * The URL to connect to (can be a function that returns a URL) | ||
| */ | ||
| url: CallbackOrValue<string>; | ||
| /** | ||
| * Connection params that are available in `createContext()` | ||
| * - For `wsLink`/`wsClient`, these are sent as the first message | ||
| * - For `httpSubscriptionLink`, these are serialized as part of the URL under the `connectionParams` query | ||
| */ | ||
| connectionParams?: CallbackOrValue<TRPCRequestInfo['connectionParams']>; | ||
| } | ||
| //# sourceMappingURL=urlWithConnectionParams.d.ts.map | ||
| //#endregion | ||
| //#region src/links/wsLink/wsClient/options.d.ts | ||
| interface WebSocketClientOptions extends UrlOptionsWithConnectionParams { | ||
| /** | ||
| * Ponyfill which WebSocket implementation to use | ||
| */ | ||
| WebSocket?: typeof WebSocket; | ||
| /** | ||
| * The number of milliseconds before a reconnect is attempted. | ||
| * @default {@link exponentialBackoff} | ||
| */ | ||
| retryDelayMs?: (attemptIndex: number) => number; | ||
| /** | ||
| * Triggered when a WebSocket connection is established | ||
| */ | ||
| onOpen?: () => void; | ||
| /** | ||
| * Triggered when a WebSocket connection encounters an error | ||
| */ | ||
| onError?: (evt?: Event) => void; | ||
| /** | ||
| * Triggered when a WebSocket connection is closed | ||
| */ | ||
| onClose?: (cause?: { | ||
| code?: number; | ||
| }) => void; | ||
| /** | ||
| * Lazy mode will close the WebSocket automatically after a period of inactivity (no messages sent or received and no pending requests) | ||
| */ | ||
| lazy?: { | ||
| /** | ||
| * Enable lazy mode | ||
| * @default false | ||
| */ | ||
| enabled: boolean; | ||
| /** | ||
| * Close the WebSocket after this many milliseconds | ||
| * @default 0 | ||
| */ | ||
| closeMs: number; | ||
| }; | ||
| /** | ||
| * Send ping messages to the server and kill the connection if no pong message is returned | ||
| */ | ||
| keepAlive?: { | ||
| /** | ||
| * @default false | ||
| */ | ||
| enabled: boolean; | ||
| /** | ||
| * Send a ping message every this many milliseconds | ||
| * @default 5_000 | ||
| */ | ||
| intervalMs?: number; | ||
| /** | ||
| * Close the WebSocket after this many milliseconds if the server does not respond | ||
| * @default 1_000 | ||
| */ | ||
| pongTimeoutMs?: number; | ||
| }; | ||
| } | ||
| /** | ||
| * Default options for lazy WebSocket connections. | ||
| * Determines whether the connection should be established lazily and defines the delay before closure. | ||
| */ | ||
| //#endregion | ||
| //#region src/links/wsLink/wsClient/wsClient.d.ts | ||
| /** | ||
| * A WebSocket client for managing TRPC operations, supporting lazy initialization, | ||
| * reconnection, keep-alive, and request management. | ||
| */ | ||
| declare class WsClient { | ||
| /** | ||
| * Observable tracking the current connection state, including errors. | ||
| */ | ||
| readonly connectionState: BehaviorSubject<TRPCConnectionState<TRPCClientError<AnyTRPCRouter>>>; | ||
| private allowReconnect; | ||
| private requestManager; | ||
| private readonly activeConnection; | ||
| private readonly reconnectRetryDelay; | ||
| private inactivityTimeout; | ||
| private readonly callbacks; | ||
| private readonly lazyMode; | ||
| constructor(opts: WebSocketClientOptions); | ||
| /** | ||
| * Opens the WebSocket connection. Handles reconnection attempts and updates | ||
| * the connection state accordingly. | ||
| */ | ||
| private open; | ||
| /** | ||
| * Closes the WebSocket connection and stops managing requests. | ||
| * Ensures all outgoing and pending requests are properly finalized. | ||
| */ | ||
| close(): Promise<void>; | ||
| /** | ||
| * Method to request the server. | ||
| * Handles data transformation, batching of requests, and subscription lifecycle. | ||
| * | ||
| * @param op - The operation details including id, type, path, input and signal | ||
| * @param transformer - Data transformer for serializing requests and deserializing responses | ||
| * @param lastEventId - Optional ID of the last received event for subscriptions | ||
| * | ||
| * @returns An observable that emits operation results and handles cleanup | ||
| */ | ||
| request({ | ||
| op: { | ||
| id, | ||
| type, | ||
| path, | ||
| input, | ||
| signal | ||
| }, | ||
| transformer, | ||
| lastEventId | ||
| }: { | ||
| op: Pick<Operation, 'id' | 'type' | 'path' | 'input' | 'signal'>; | ||
| transformer: CombinedDataTransformer; | ||
| lastEventId?: string; | ||
| }): _trpc_server_observable0.Observable<OperationResultEnvelope<unknown, TRPCClientError<AnyTRPCRouter>>, TRPCClientError<AnyTRPCRouter>>; | ||
| get connection(): { | ||
| readonly id: number; | ||
| readonly state: "open"; | ||
| readonly ws: WebSocket; | ||
| } | { | ||
| readonly id: number; | ||
| readonly state: "closed"; | ||
| readonly ws: WebSocket; | ||
| } | { | ||
| readonly id: number; | ||
| readonly state: "connecting"; | ||
| readonly ws: WebSocket; | ||
| } | null; | ||
| /** | ||
| * Manages the reconnection process for the WebSocket using retry logic. | ||
| * Ensures that only one reconnection attempt is active at a time by tracking the current | ||
| * reconnection state in the `reconnecting` promise. | ||
| */ | ||
| private reconnecting; | ||
| private reconnect; | ||
| private setupWebSocketListeners; | ||
| private handleResponseMessage; | ||
| private handleIncomingRequest; | ||
| /** | ||
| * Sends a message or batch of messages directly to the server. | ||
| */ | ||
| private send; | ||
| /** | ||
| * Groups requests for batch sending. | ||
| * | ||
| * @returns A function to abort the batched request. | ||
| */ | ||
| private batchSend; | ||
| } | ||
| //# sourceMappingURL=wsClient.d.ts.map | ||
| //#endregion | ||
| //#region src/links/wsLink/createWsClient.d.ts | ||
| declare function createWSClient(opts: WebSocketClientOptions): WsClient; | ||
| type TRPCWebSocketClient = ReturnType<typeof createWSClient>; | ||
| //#endregion | ||
| //#region src/links/wsLink/wsLink.d.ts | ||
| type WebSocketLinkOptions<TRouter extends AnyRouter> = { | ||
| client: TRPCWebSocketClient; | ||
| } & TransformerOptions<inferClientTypes<TRouter>>; | ||
| declare function wsLink<TRouter extends AnyRouter>(opts: WebSocketLinkOptions<TRouter>): TRPCLink<TRouter>; | ||
| //#endregion | ||
| export { TRPCWebSocketClient, UrlOptionsWithConnectionParams, WebSocketClientOptions, WebSocketLinkOptions, createWSClient, wsLink }; | ||
| //# sourceMappingURL=wsLink.d-em3USiMI.d.mts.map |
| {"version":3,"file":"wsLink.d-em3USiMI.d.mts","names":[],"sources":["../src/links/internals/urlWithConnectionParams.ts","../src/links/wsLink/wsClient/options.ts","../src/links/wsLink/wsClient/wsClient.ts","../src/links/wsLink/createWsClient.ts","../src/links/wsLink/wsLink.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;KAkBY,qBAAqB,WAAW,IAAI,QAAQ;AAA5C,UAEK,8BAAA,CAFU;EAAA;;;EAAkB,GAAW,EAMjD,eANiD,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AJY,CAIP,SAJO,EAAA,IAAA,GAAA,MAAA,GAAA,MAAA,GAAA,OAAA,GAAA,QAAA,CAAA;IAAM,WAAA,EAKT,uBALS;IAAO,WAAA,CAAA,EAAA,MAAA;EAAM,CAAA,CAAA,EAOpC,wBAAA,CAAA,UANC,CAMD,uBANC,CAAA,OAAA,EAMD,eANC,CAMD,aANC,CAAA,CAAA,EAMD,eANC,CAMD,aANC,CAAA,CAAA;EAAW,IACX,UAAA,CAAA,CAAA,EAAA;IAES,SAAA,EAAA,EAAA,MAAA;IAAL,SAAA,KAAA,EAAA,MAAA;IACS,SAAA,EAAA,EAEd,SAFc;EAAuB,CAAA,GAErC;IAAA,SAAA,EAAA,EAAA,MAAA;IAAA,SAAA,KAAA,EAAA,QAAA;IAAA,SAAA,EAAA,WAAA;EAAA,CAAA,GAAA;IAAA,SAAA,EAAA,EAAA,MAAA;IAAA,SAAA,KAAA,EAAA,YAAA;;;;;;;ACxLH;EAA8B,QAAA,YAAA;EAAA,QAAO,SAAA;EAAsB,QAAA,uBAAA;EAAA,QAAA,qBAAA;EAI/C,QAAA,qBAAmB;EAAA;;;EAAa,QAAA,IAAA;;;;ACO5C;;EAAgC,QAAiB,SAAA;;;;;iBDXjC,cAAA,OAAqB,yBAAsB;KAI/C,mBAAA,GAAsB,kBAAkB;;;KCOxC,qCAAqC;UACvC;IACN,mBAAmB,iBAAiB;iBAExB,uBAAuB,iBAC/B,qBAAqB,WAC1B,SAAS"} |
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
554250
0