@trpc/client 11.1.3-alpha-tmp-issues-6785.34 → 11.1.3-alpha-tmp-tsdown.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/TRPCClientError.d.mts +32 -0
- package/dist/TRPCClientError.d.mts.map +1 -0
- package/dist/TRPCClientError.d.ts +28 -25
- package/dist/TRPCClientError.d.ts.map +1 -1
- package/dist/TRPCClientError.js +48 -72
- package/dist/TRPCClientError.mjs +48 -71
- package/dist/TRPCClientError.mjs.map +1 -0
- package/dist/_virtual/rolldown_runtime.js +39 -0
- package/dist/_virtual/rolldown_runtime.mjs +27 -0
- package/dist/createTRPCClient.d.mts +69 -0
- package/dist/createTRPCClient.d.mts.map +1 -0
- package/dist/createTRPCClient.d.ts +34 -34
- package/dist/createTRPCClient.d.ts.map +1 -1
- package/dist/createTRPCClient.js +34 -34
- package/dist/createTRPCClient.mjs +33 -31
- package/dist/createTRPCClient.mjs.map +1 -0
- package/dist/createTRPCUntypedClient.d.mts +8 -0
- package/dist/createTRPCUntypedClient.d.mts.map +1 -0
- package/dist/createTRPCUntypedClient.d.ts +7 -6
- package/dist/createTRPCUntypedClient.d.ts.map +1 -1
- package/dist/createTRPCUntypedClient.js +5 -6
- package/dist/createTRPCUntypedClient.mjs +6 -3
- package/dist/createTRPCUntypedClient.mjs.map +1 -0
- package/dist/getFetch.d.mts +9 -0
- package/dist/getFetch.d.mts.map +1 -0
- package/dist/getFetch.d.ts +8 -2
- package/dist/getFetch.d.ts.map +1 -1
- package/dist/getFetch.js +8 -13
- package/dist/getFetch.mjs +8 -11
- package/dist/getFetch.mjs.map +1 -0
- package/dist/index.d.mts +21 -0
- package/dist/index.d.ts +21 -16
- package/dist/index.js +42 -42
- package/dist/index.mjs +19 -15
- package/dist/internals/TRPCUntypedClient.d.mts +45 -0
- package/dist/internals/TRPCUntypedClient.d.mts.map +1 -0
- package/dist/internals/TRPCUntypedClient.d.ts +39 -33
- package/dist/internals/TRPCUntypedClient.d.ts.map +1 -1
- package/dist/internals/TRPCUntypedClient.js +94 -113
- package/dist/internals/TRPCUntypedClient.mjs +93 -110
- package/dist/internals/TRPCUntypedClient.mjs.map +1 -0
- package/dist/internals/dataLoader.js +101 -112
- package/dist/internals/dataLoader.mjs +101 -110
- package/dist/internals/dataLoader.mjs.map +1 -0
- package/dist/internals/inputWithTrackedEventId.js +9 -12
- package/dist/internals/inputWithTrackedEventId.mjs +9 -10
- package/dist/internals/inputWithTrackedEventId.mjs.map +1 -0
- package/dist/internals/signals.js +39 -40
- package/dist/internals/signals.mjs +39 -39
- package/dist/internals/signals.mjs.map +1 -0
- package/dist/internals/transformer.d.mts +46 -0
- package/dist/internals/transformer.d.mts.map +1 -0
- package/dist/internals/transformer.d.ts +26 -22
- package/dist/internals/transformer.d.ts.map +1 -1
- package/dist/internals/transformer.js +25 -26
- package/dist/internals/transformer.mjs +25 -24
- package/dist/internals/transformer.mjs.map +1 -0
- package/dist/internals/types.d.mts +84 -0
- package/dist/internals/types.d.mts.map +1 -0
- package/dist/internals/types.d.ts +44 -42
- package/dist/internals/types.d.ts.map +1 -1
- package/dist/links/HTTPBatchLinkOptions.d.mts +25 -0
- package/dist/links/HTTPBatchLinkOptions.d.mts.map +1 -0
- package/dist/links/HTTPBatchLinkOptions.d.ts +23 -18
- package/dist/links/HTTPBatchLinkOptions.d.ts.map +1 -1
- package/dist/links/httpBatchLink.d.mts +15 -0
- package/dist/links/httpBatchLink.d.mts.map +1 -0
- package/dist/links/httpBatchLink.d.ts +11 -4
- package/dist/links/httpBatchLink.d.ts.map +1 -1
- package/dist/links/httpBatchLink.js +90 -106
- package/dist/links/httpBatchLink.mjs +89 -103
- package/dist/links/httpBatchLink.mjs.map +1 -0
- package/dist/links/httpBatchStreamLink.d.mts +19 -0
- package/dist/links/httpBatchStreamLink.d.mts.map +1 -0
- package/dist/links/httpBatchStreamLink.d.ts +12 -5
- package/dist/links/httpBatchStreamLink.d.ts.map +1 -1
- package/dist/links/httpBatchStreamLink.js +120 -144
- package/dist/links/httpBatchStreamLink.mjs +119 -141
- package/dist/links/httpBatchStreamLink.mjs.map +1 -0
- package/dist/links/httpLink.d.mts +23 -0
- package/dist/links/httpLink.d.mts.map +1 -0
- package/dist/links/httpLink.d.ts +18 -12
- package/dist/links/httpLink.d.ts.map +1 -1
- package/dist/links/httpLink.js +74 -90
- package/dist/links/httpLink.mjs +73 -87
- package/dist/links/httpLink.mjs.map +1 -0
- package/dist/links/httpSubscriptionLink.d.mts +29 -0
- package/dist/links/httpSubscriptionLink.d.mts.map +1 -0
- package/dist/links/httpSubscriptionLink.d.ts +20 -17
- package/dist/links/httpSubscriptionLink.d.ts.map +1 -1
- package/dist/links/httpSubscriptionLink.js +134 -179
- package/dist/links/httpSubscriptionLink.mjs +133 -176
- package/dist/links/httpSubscriptionLink.mjs.map +1 -0
- package/dist/links/internals/contentTypes.d.mts +9 -0
- package/dist/links/internals/contentTypes.d.mts.map +1 -0
- package/dist/links/internals/contentTypes.d.ts +8 -3
- package/dist/links/internals/contentTypes.d.ts.map +1 -1
- package/dist/links/internals/contentTypes.js +6 -6
- package/dist/links/internals/contentTypes.mjs +6 -4
- package/dist/links/internals/contentTypes.mjs.map +1 -0
- package/dist/links/internals/createChain.js +23 -23
- package/dist/links/internals/createChain.mjs +22 -20
- package/dist/links/internals/createChain.mjs.map +1 -0
- package/dist/links/internals/httpUtils.d.mts +25 -0
- package/dist/links/internals/httpUtils.d.mts.map +1 -0
- package/dist/links/internals/httpUtils.d.ts +20 -63
- package/dist/links/internals/httpUtils.d.ts.map +1 -1
- package/dist/links/internals/httpUtils.js +93 -116
- package/dist/links/internals/httpUtils.mjs +94 -113
- package/dist/links/internals/httpUtils.mjs.map +1 -0
- package/dist/links/internals/subscriptions.d.mts +19 -0
- package/dist/links/internals/subscriptions.d.mts.map +1 -0
- package/dist/links/internals/subscriptions.d.ts +10 -8
- package/dist/links/internals/subscriptions.d.ts.map +1 -1
- package/dist/links/internals/urlWithConnectionParams.d.mts +24 -0
- package/dist/links/internals/urlWithConnectionParams.d.mts.map +1 -0
- package/dist/links/internals/urlWithConnectionParams.d.ts +19 -18
- package/dist/links/internals/urlWithConnectionParams.d.ts.map +1 -1
- package/dist/links/internals/urlWithConnectionParams.js +8 -6
- package/dist/links/internals/urlWithConnectionParams.mjs +8 -4
- package/dist/links/internals/urlWithConnectionParams.mjs.map +1 -0
- package/dist/links/localLink.d.mts +21 -0
- package/dist/links/localLink.d.mts.map +1 -0
- package/dist/links/localLink.d.ts +21 -0
- package/dist/links/localLink.d.ts.map +1 -0
- package/dist/links/localLink.js +192 -0
- package/dist/links/localLink.mjs +193 -0
- package/dist/links/localLink.mjs.map +1 -0
- package/dist/links/loggerLink.d.mts +55 -0
- package/dist/links/loggerLink.d.mts.map +1 -0
- package/dist/links/loggerLink.d.ts +39 -36
- package/dist/links/loggerLink.d.ts.map +1 -1
- package/dist/links/loggerLink.js +113 -166
- package/dist/links/loggerLink.mjs +112 -163
- package/dist/links/loggerLink.mjs.map +1 -0
- package/dist/links/retryLink.d.mts +36 -0
- package/dist/links/retryLink.d.mts.map +1 -0
- package/dist/links/retryLink.d.ts +28 -25
- package/dist/links/retryLink.d.ts.map +1 -1
- package/dist/links/retryLink.js +60 -68
- package/dist/links/retryLink.mjs +59 -65
- package/dist/links/retryLink.mjs.map +1 -0
- package/dist/links/splitLink.d.mts +20 -0
- package/dist/links/splitLink.d.mts.map +1 -0
- package/dist/links/splitLink.d.ts +18 -12
- package/dist/links/splitLink.d.ts.map +1 -1
- package/dist/links/splitLink.js +20 -21
- package/dist/links/splitLink.mjs +19 -18
- package/dist/links/splitLink.mjs.map +1 -0
- package/dist/links/types.d.mts +68 -0
- package/dist/links/types.d.mts.map +1 -0
- package/dist/links/types.d.ts +34 -29
- package/dist/links/types.d.ts.map +1 -1
- package/dist/links/wsLink/createWsClient.d.mts +9 -0
- package/dist/links/wsLink/createWsClient.d.mts.map +1 -0
- package/dist/links/wsLink/createWsClient.d.ts +8 -5
- package/dist/links/wsLink/createWsClient.d.ts.map +1 -1
- package/dist/links/wsLink/createWsClient.js +5 -5
- package/dist/links/wsLink/createWsClient.mjs +5 -2
- package/dist/links/wsLink/createWsClient.mjs.map +1 -0
- package/dist/links/wsLink/wsClient/options.d.mts +69 -0
- package/dist/links/wsLink/wsClient/options.d.mts.map +1 -0
- package/dist/links/wsLink/wsClient/options.d.ts +53 -63
- package/dist/links/wsLink/wsClient/options.d.ts.map +1 -1
- package/dist/links/wsLink/wsClient/options.js +14 -12
- package/dist/links/wsLink/wsClient/options.mjs +14 -10
- package/dist/links/wsLink/wsClient/options.mjs.map +1 -0
- package/dist/links/wsLink/wsClient/requestManager.js +133 -140
- package/dist/links/wsLink/wsClient/requestManager.mjs +133 -137
- package/dist/links/wsLink/wsClient/requestManager.mjs.map +1 -0
- package/dist/links/wsLink/wsClient/utils.js +64 -81
- package/dist/links/wsLink/wsClient/utils.mjs +64 -78
- package/dist/links/wsLink/wsClient/utils.mjs.map +1 -0
- package/dist/links/wsLink/wsClient/wsClient.d.mts +101 -0
- package/dist/links/wsLink/wsClient/wsClient.d.mts.map +1 -0
- package/dist/links/wsLink/wsClient/wsClient.d.ts +95 -78
- package/dist/links/wsLink/wsClient/wsClient.d.ts.map +1 -1
- package/dist/links/wsLink/wsClient/wsClient.js +273 -322
- package/dist/links/wsLink/wsClient/wsClient.mjs +272 -319
- package/dist/links/wsLink/wsClient/wsClient.mjs.map +1 -0
- package/dist/links/wsLink/wsClient/wsConnection.js +155 -178
- package/dist/links/wsLink/wsClient/wsConnection.mjs +154 -175
- package/dist/links/wsLink/wsClient/wsConnection.mjs.map +1 -0
- package/dist/links/wsLink/wsLink.d.mts +14 -0
- package/dist/links/wsLink/wsLink.d.mts.map +1 -0
- package/dist/links/wsLink/wsLink.d.ts +12 -9
- package/dist/links/wsLink/wsLink.d.ts.map +1 -1
- package/dist/links/wsLink/wsLink.js +30 -31
- package/dist/links/wsLink/wsLink.mjs +29 -28
- package/dist/links/wsLink/wsLink.mjs.map +1 -0
- package/dist/links.js +11 -0
- package/dist/links.mjs +11 -0
- package/dist/node_modules/.pnpm/@oxc-project_runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js +68 -0
- package/dist/node_modules/.pnpm/@oxc-project_runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/usingCtx.mjs +66 -0
- package/dist/node_modules/.pnpm/@oxc-project_runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/usingCtx.mjs.map +1 -0
- package/dist/unstable-internals.d.mts +3 -0
- package/dist/unstable-internals.d.ts +3 -3
- package/dist/unstable-internals.js +2 -6
- package/dist/unstable-internals.mjs +3 -1
- package/links/httpBatchLink/package.json +1 -0
- package/links/httpLink/package.json +1 -0
- package/links/loggerLink/package.json +1 -0
- package/links/splitLink/package.json +1 -0
- package/links/wsLink/wsLink/package.json +1 -0
- package/package.json +63 -30
- package/src/TRPCClientError.ts +4 -9
- package/src/internals/signals.ts +16 -0
- package/src/links/httpSubscriptionLink.ts +3 -18
- package/src/links/localLink.ts +277 -0
- package/src/links.ts +1 -0
- package/unstable-internals/package.json +1 -0
- package/dist/bundle-analysis.json +0 -433
- package/dist/index.d.ts.map +0 -1
- package/dist/internals/dataLoader.d.ts +0 -13
- package/dist/internals/dataLoader.d.ts.map +0 -1
- package/dist/internals/inputWithTrackedEventId.d.ts +0 -2
- package/dist/internals/inputWithTrackedEventId.d.ts.map +0 -1
- package/dist/internals/signals.d.ts +0 -15
- package/dist/internals/signals.d.ts.map +0 -1
- package/dist/links/internals/createChain.d.ts +0 -8
- package/dist/links/internals/createChain.d.ts.map +0 -1
- package/dist/links/internals/dedupeLink.d.ts +0 -7
- package/dist/links/internals/dedupeLink.d.ts.map +0 -1
- package/dist/links/wsLink/wsClient/requestManager.d.ts +0 -106
- package/dist/links/wsLink/wsClient/requestManager.d.ts.map +0 -1
- package/dist/links/wsLink/wsClient/utils.d.ts +0 -38
- package/dist/links/wsLink/wsClient/utils.d.ts.map +0 -1
- package/dist/links/wsLink/wsClient/wsConnection.d.ts +0 -79
- package/dist/links/wsLink/wsClient/wsConnection.d.ts.map +0 -1
- package/dist/links.d.ts +0 -11
- package/dist/links.d.ts.map +0 -1
- package/dist/unstable-internals.d.ts.map +0 -1
- package/links/httpBatchLink/index.d.ts +0 -1
- package/links/httpBatchLink/index.js +0 -1
- package/links/httpLink/index.d.ts +0 -1
- package/links/httpLink/index.js +0 -1
- package/links/loggerLink/index.d.ts +0 -1
- package/links/loggerLink/index.js +0 -1
- package/links/splitLink/index.d.ts +0 -1
- package/links/splitLink/index.js +0 -1
- package/links/wsLink/wsLink/index.d.ts +0 -1
- package/links/wsLink/wsLink/index.js +0 -1
- package/unstable-internals/index.d.ts +0 -1
- package/unstable-internals/index.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpSubscriptionLink.mjs","names":["opts: UrlOptionsWithConnectionParams","opts: HTTPSubscriptionLinkOptions<\n inferClientTypes<TInferrable>,\n TEventSource\n >","lastEventId: string | undefined","result: TRPCResult<unknown>"],"sources":["../../src/links/httpSubscriptionLink.ts"],"sourcesContent":["import { behaviorSubject, observable } from '@trpc/server/observable';\nimport type { TRPCErrorShape, TRPCResult } from '@trpc/server/rpc';\nimport type {\n AnyClientTypes,\n EventSourceLike,\n inferClientTypes,\n InferrableClientTypes,\n} from '@trpc/server/unstable-core-do-not-import';\nimport {\n retryableRpcCodes,\n run,\n sseStreamConsumer,\n} from '@trpc/server/unstable-core-do-not-import';\nimport { inputWithTrackedEventId } from '../internals/inputWithTrackedEventId';\nimport { raceAbortSignals } from '../internals/signals';\nimport { TRPCClientError } from '../TRPCClientError';\nimport type { TRPCConnectionState } from '../unstable-internals';\nimport { getTransformer, type TransformerOptions } from '../unstable-internals';\nimport { getUrl } from './internals/httpUtils';\nimport {\n resultOf,\n type UrlOptionsWithConnectionParams,\n} from './internals/urlWithConnectionParams';\nimport type { Operation, TRPCLink } from './types';\n\nasync function urlWithConnectionParams(\n opts: UrlOptionsWithConnectionParams,\n): Promise<string> {\n let url = await resultOf(opts.url);\n if (opts.connectionParams) {\n const params = await resultOf(opts.connectionParams);\n\n const prefix = url.includes('?') ? '&' : '?';\n url +=\n prefix + 'connectionParams=' + encodeURIComponent(JSON.stringify(params));\n }\n\n return url;\n}\n\ntype HTTPSubscriptionLinkOptions<\n TRoot extends AnyClientTypes,\n TEventSource extends EventSourceLike.AnyConstructor = typeof EventSource,\n> = {\n /**\n * EventSource ponyfill\n */\n EventSource?: TEventSource;\n /**\n * EventSource options or a callback that returns them\n */\n eventSourceOptions?:\n | EventSourceLike.InitDictOf<TEventSource>\n | ((opts: {\n op: Operation;\n }) =>\n | EventSourceLike.InitDictOf<TEventSource>\n | Promise<EventSourceLike.InitDictOf<TEventSource>>);\n} & TransformerOptions<TRoot> &\n UrlOptionsWithConnectionParams;\n\n/**\n * @see https://trpc.io/docs/client/links/httpSubscriptionLink\n */\nexport function httpSubscriptionLink<\n TInferrable extends InferrableClientTypes,\n TEventSource extends EventSourceLike.AnyConstructor,\n>(\n opts: HTTPSubscriptionLinkOptions<\n inferClientTypes<TInferrable>,\n TEventSource\n >,\n): TRPCLink<TInferrable> {\n const transformer = getTransformer(opts.transformer);\n\n return () => {\n return ({ op }) => {\n return observable((observer) => {\n const { type, path, input } = op;\n\n /* istanbul ignore if -- @preserve */\n if (type !== 'subscription') {\n throw new Error('httpSubscriptionLink only supports subscriptions');\n }\n\n let lastEventId: string | undefined = undefined;\n const ac = new AbortController();\n const signal = raceAbortSignals(op.signal, ac.signal);\n const eventSourceStream = sseStreamConsumer<{\n EventSource: TEventSource;\n data: Partial<{\n id?: string;\n data: unknown;\n }>;\n error: TRPCErrorShape;\n }>({\n url: async () =>\n getUrl({\n transformer,\n url: await urlWithConnectionParams(opts),\n input: inputWithTrackedEventId(input, lastEventId),\n path,\n type,\n signal: null,\n }),\n init: () => resultOf(opts.eventSourceOptions, { op }),\n signal,\n deserialize: transformer.output.deserialize,\n EventSource:\n opts.EventSource ??\n (globalThis.EventSource as never as TEventSource),\n });\n\n const connectionState = behaviorSubject<\n TRPCConnectionState<TRPCClientError<any>>\n >({\n type: 'state',\n state: 'connecting',\n error: null,\n });\n\n const connectionSub = connectionState.subscribe({\n next(state) {\n observer.next({\n result: state,\n });\n },\n });\n run(async () => {\n for await (const chunk of eventSourceStream) {\n switch (chunk.type) {\n case 'ping':\n // do nothing\n break;\n case 'data':\n const chunkData = chunk.data;\n\n let result: TRPCResult<unknown>;\n if (chunkData.id) {\n // if the `tracked()`-helper is used, we always have an `id` field\n lastEventId = chunkData.id;\n result = {\n id: chunkData.id,\n data: chunkData,\n };\n } else {\n result = {\n data: chunkData.data,\n };\n }\n\n observer.next({\n result,\n context: {\n eventSource: chunk.eventSource,\n },\n });\n break;\n case 'connected': {\n observer.next({\n result: {\n type: 'started',\n },\n context: {\n eventSource: chunk.eventSource,\n },\n });\n connectionState.next({\n type: 'state',\n state: 'pending',\n error: null,\n });\n break;\n }\n case 'serialized-error': {\n const error = TRPCClientError.from({ error: chunk.error });\n\n if (retryableRpcCodes.includes(chunk.error.code)) {\n //\n connectionState.next({\n type: 'state',\n state: 'connecting',\n error,\n });\n break;\n }\n //\n // non-retryable error, cancel the subscription\n throw error;\n }\n case 'connecting': {\n const lastState = connectionState.get();\n\n const error = chunk.event && TRPCClientError.from(chunk.event);\n if (!error && lastState.state === 'connecting') {\n break;\n }\n\n connectionState.next({\n type: 'state',\n state: 'connecting',\n error,\n });\n break;\n }\n case 'timeout': {\n connectionState.next({\n type: 'state',\n state: 'connecting',\n error: new TRPCClientError(\n `Timeout of ${chunk.ms}ms reached while waiting for a response`,\n ),\n });\n }\n }\n }\n observer.next({\n result: {\n type: 'stopped',\n },\n });\n connectionState.next({\n type: 'state',\n state: 'idle',\n error: null,\n });\n observer.complete();\n }).catch((error) => {\n observer.error(TRPCClientError.from(error));\n });\n\n return () => {\n observer.complete();\n ac.abort();\n connectionSub.unsubscribe();\n };\n });\n };\n };\n}\n\n/**\n * @deprecated use {@link httpSubscriptionLink} instead\n */\nexport const unstable_httpSubscriptionLink = httpSubscriptionLink;\n"],"mappings":"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"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
//#region src/links/internals/contentTypes.d.ts
|
|
2
|
+
declare function isOctetType(input: unknown): input is Blob | Uint8Array<ArrayBufferLike>;
|
|
3
|
+
declare function isFormData(input: unknown): input is FormData;
|
|
4
|
+
declare function isNonJsonSerializable(input: unknown): input is Blob | FormData | Uint8Array<ArrayBufferLike>;
|
|
5
|
+
//# sourceMappingURL=contentTypes.d.ts.map
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { isFormData, isNonJsonSerializable, isOctetType };
|
|
9
|
+
//# sourceMappingURL=contentTypes.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contentTypes.d.mts","names":[],"sources":["../../../src/links/internals/contentTypes.ts"],"sourcesContent":[],"mappings":";iBAAgB,WAAA,2BAA0B,OAAA,WAAA;AAA1B,iBAQA,UAAA,CARW,KAAA,EAAA,OAAA,CAAA,EAAA,KAAA,IAQc,QARd;AAAA,iBAYX,qBAAA,CAZW,KAAA,EAAA,OAAA,CAAA,EAAA,KAAA,IAYyB,IAZzB,GAYyB,QAZzB,GAYyB,UAZzB,CAYyB,eAZzB,CAAA"}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
//#region src/links/internals/contentTypes.d.ts
|
|
2
|
+
declare function isOctetType(input: unknown): input is Blob | Uint8Array<ArrayBufferLike>;
|
|
3
|
+
declare function isFormData(input: unknown): input is FormData;
|
|
4
|
+
declare function isNonJsonSerializable(input: unknown): input is Blob | FormData | Uint8Array<ArrayBufferLike>;
|
|
5
|
+
//# sourceMappingURL=contentTypes.d.ts.map
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { isFormData, isNonJsonSerializable, isOctetType };
|
|
4
9
|
//# sourceMappingURL=contentTypes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contentTypes.d.ts","
|
|
1
|
+
{"version":3,"file":"contentTypes.d.ts","names":[],"sources":["../../../src/links/internals/contentTypes.ts"],"sourcesContent":[],"mappings":";iBAAgB,WAAA,2BAA0B,OAAA,WAAA;AAA1B,iBAQA,UAAA,CARW,KAAA,EAAA,OAAA,CAAA,EAAA,KAAA,IAQc,QARd;AAAA,iBAYX,qBAAA,CAZW,KAAA,EAAA,OAAA,CAAA,EAAA,KAAA,IAYyB,IAZzB,GAYyB,QAZzB,GAYyB,UAZzB,CAYyB,eAZzB,CAAA"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
'use strict';
|
|
2
1
|
|
|
2
|
+
//#region src/links/internals/contentTypes.ts
|
|
3
3
|
function isOctetType(input) {
|
|
4
|
-
|
|
5
|
-
input instanceof Blob;
|
|
4
|
+
return input instanceof Uint8Array || input instanceof Blob;
|
|
6
5
|
}
|
|
7
6
|
function isFormData(input) {
|
|
8
|
-
|
|
7
|
+
return input instanceof FormData;
|
|
9
8
|
}
|
|
10
9
|
function isNonJsonSerializable(input) {
|
|
11
|
-
|
|
10
|
+
return isOctetType(input) || isFormData(input);
|
|
12
11
|
}
|
|
13
12
|
|
|
13
|
+
//#endregion
|
|
14
14
|
exports.isFormData = isFormData;
|
|
15
15
|
exports.isNonJsonSerializable = isNonJsonSerializable;
|
|
16
|
-
exports.isOctetType = isOctetType;
|
|
16
|
+
exports.isOctetType = isOctetType;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
//#region src/links/internals/contentTypes.ts
|
|
1
2
|
function isOctetType(input) {
|
|
2
|
-
|
|
3
|
-
input instanceof Blob;
|
|
3
|
+
return input instanceof Uint8Array || input instanceof Blob;
|
|
4
4
|
}
|
|
5
5
|
function isFormData(input) {
|
|
6
|
-
|
|
6
|
+
return input instanceof FormData;
|
|
7
7
|
}
|
|
8
8
|
function isNonJsonSerializable(input) {
|
|
9
|
-
|
|
9
|
+
return isOctetType(input) || isFormData(input);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
+
//#endregion
|
|
12
13
|
export { isFormData, isNonJsonSerializable, isOctetType };
|
|
14
|
+
//# sourceMappingURL=contentTypes.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contentTypes.mjs","names":["input: unknown"],"sources":["../../../src/links/internals/contentTypes.ts"],"sourcesContent":["export function isOctetType(input: unknown) {\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"],"mappings":";AAAA,SAAgB,YAAYA,OAAgB;AAC1C,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"}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.js');
|
|
2
|
+
const __trpc_server_observable = require_rolldown_runtime.__toESM(require("@trpc/server/observable"));
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return obs$.subscribe(observer);
|
|
23
|
-
});
|
|
4
|
+
//#region src/links/internals/createChain.ts
|
|
5
|
+
/** @internal */
|
|
6
|
+
function createChain(opts) {
|
|
7
|
+
return (0, __trpc_server_observable.observable)((observer) => {
|
|
8
|
+
function execute(index = 0, op = opts.op) {
|
|
9
|
+
const next = opts.links[index];
|
|
10
|
+
if (!next) throw new Error("No more links to execute - did you forget to add an ending link?");
|
|
11
|
+
const subscription = next({
|
|
12
|
+
op,
|
|
13
|
+
next(nextOp) {
|
|
14
|
+
const nextObserver = execute(index + 1, nextOp);
|
|
15
|
+
return nextObserver;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return subscription;
|
|
19
|
+
}
|
|
20
|
+
const obs$ = execute();
|
|
21
|
+
return obs$.subscribe(observer);
|
|
22
|
+
});
|
|
24
23
|
}
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.createChain = createChain;
|
|
@@ -1,24 +1,26 @@
|
|
|
1
|
-
import { observable } from
|
|
1
|
+
import { observable } from "@trpc/server/observable";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
3
|
+
//#region src/links/internals/createChain.ts
|
|
4
|
+
/** @internal */
|
|
5
|
+
function createChain(opts) {
|
|
6
|
+
return observable((observer) => {
|
|
7
|
+
function execute(index = 0, op = opts.op) {
|
|
8
|
+
const next = opts.links[index];
|
|
9
|
+
if (!next) throw new Error("No more links to execute - did you forget to add an ending link?");
|
|
10
|
+
const subscription = next({
|
|
11
|
+
op,
|
|
12
|
+
next(nextOp) {
|
|
13
|
+
const nextObserver = execute(index + 1, nextOp);
|
|
14
|
+
return nextObserver;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return subscription;
|
|
18
|
+
}
|
|
19
|
+
const obs$ = execute();
|
|
20
|
+
return obs$.subscribe(observer);
|
|
21
|
+
});
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
//#endregion
|
|
24
25
|
export { createChain };
|
|
26
|
+
//# sourceMappingURL=createChain.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createChain.mjs","names":["opts: {\n links: OperationLink<TRouter, TInput, TOutput>[];\n op: Operation<TInput>;\n}"],"sources":["../../../src/links/internals/createChain.ts"],"sourcesContent":["import { observable } from '@trpc/server/observable';\nimport type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';\nimport type {\n Operation,\n OperationLink,\n OperationResultObservable,\n} from '../types';\n\n/** @internal */\nexport function createChain<\n TRouter extends AnyRouter,\n TInput = unknown,\n TOutput = unknown,\n>(opts: {\n links: OperationLink<TRouter, TInput, TOutput>[];\n op: Operation<TInput>;\n}): OperationResultObservable<TRouter, TOutput> {\n return observable((observer) => {\n function execute(index = 0, op = opts.op) {\n const next = opts.links[index];\n if (!next) {\n throw new Error(\n 'No more links to execute - did you forget to add an ending link?',\n );\n }\n const subscription = next({\n op,\n next(nextOp) {\n const nextObserver = execute(index + 1, nextOp);\n\n return nextObserver;\n },\n });\n return subscription;\n }\n\n const obs$ = execute();\n return obs$.subscribe(observer);\n });\n}\n"],"mappings":";;;;AASA,SAAgB,YAIdA,MAG8C;AAC9C,QAAO,WAAW,CAAC,aAAa;EAC9B,SAAS,QAAQ,QAAQ,GAAG,KAAK,KAAK,IAAI;GACxC,MAAM,OAAO,KAAK,MAAM;AACxB,QAAK,KACH,OAAM,IAAI,MACR;GAGJ,MAAM,eAAe,KAAK;IACxB;IACA,KAAK,QAAQ;KACX,MAAM,eAAe,QAAQ,QAAQ,GAAG,OAAO;AAE/C,YAAO;IACR;GACF,EAAC;AACF,UAAO;EACR;EAED,MAAM,OAAO,SAAS;AACtB,SAAO,KAAK,UAAU,SAAS;CAChC,EAAC;AACH"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FetchEsque } from "../../internals/types.mjs";
|
|
2
|
+
import { TransformerOptions } from "../../internals/transformer.mjs";
|
|
3
|
+
import { AnyClientTypes, CombinedDataTransformer, Maybe, ProcedureType } from "@trpc/server/unstable-core-do-not-import";
|
|
4
|
+
|
|
5
|
+
//#region src/links/internals/httpUtils.d.ts
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
type HTTPLinkBaseOptions<TRoot extends Pick<AnyClientTypes, 'transformer'>> = {
|
|
11
|
+
url: string | URL;
|
|
12
|
+
/**
|
|
13
|
+
* Add ponyfill for fetch
|
|
14
|
+
*/
|
|
15
|
+
fetch?: FetchEsque;
|
|
16
|
+
/**
|
|
17
|
+
* Send all requests `as POST`s requests regardless of the procedure type
|
|
18
|
+
* The HTTP handler must separately allow overriding the method. See:
|
|
19
|
+
* @see https://trpc.io/docs/rpc
|
|
20
|
+
*/
|
|
21
|
+
methodOverride?: 'POST';
|
|
22
|
+
} & TransformerOptions<TRoot>;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { HTTPLinkBaseOptions };
|
|
25
|
+
//# sourceMappingURL=httpUtils.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpUtils.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"}
|
|
@@ -1,68 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import { FetchEsque } from "../../internals/types.js";
|
|
2
|
+
import { TransformerOptions } from "../../internals/transformer.js";
|
|
3
|
+
import { AnyClientTypes, CombinedDataTransformer, Maybe, ProcedureType } from "@trpc/server/unstable-core-do-not-import";
|
|
4
|
+
|
|
5
|
+
//#region src/links/internals/httpUtils.d.ts
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* @internal
|
|
7
9
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
10
|
+
type HTTPLinkBaseOptions<TRoot extends Pick<AnyClientTypes, 'transformer'>> = {
|
|
11
|
+
url: string | URL;
|
|
12
|
+
/**
|
|
13
|
+
* Add ponyfill for fetch
|
|
14
|
+
*/
|
|
15
|
+
fetch?: FetchEsque;
|
|
16
|
+
/**
|
|
17
|
+
* Send all requests `as POST`s requests regardless of the procedure type
|
|
18
|
+
* The HTTP handler must separately allow overriding the method. See:
|
|
19
|
+
* @see https://trpc.io/docs/rpc
|
|
20
|
+
*/
|
|
21
|
+
methodOverride?: 'POST';
|
|
20
22
|
} & TransformerOptions<TRoot>;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
fetch?: FetchEsque;
|
|
24
|
-
transformer: CombinedDataTransformer;
|
|
25
|
-
methodOverride?: 'POST';
|
|
26
|
-
}
|
|
27
|
-
export declare function resolveHTTPLinkOptions(opts: HTTPLinkBaseOptions<AnyClientTypes>): ResolvedHTTPLinkOptions;
|
|
28
|
-
export interface HTTPResult {
|
|
29
|
-
json: TRPCResponse;
|
|
30
|
-
meta: {
|
|
31
|
-
response: ResponseEsque;
|
|
32
|
-
responseJSON?: unknown;
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
type GetInputOptions = {
|
|
36
|
-
transformer: CombinedDataTransformer;
|
|
37
|
-
} & ({
|
|
38
|
-
input: unknown;
|
|
39
|
-
} | {
|
|
40
|
-
inputs: unknown[];
|
|
41
|
-
});
|
|
42
|
-
export declare function getInput(opts: GetInputOptions): any;
|
|
43
|
-
export type HTTPBaseRequestOptions = GetInputOptions & ResolvedHTTPLinkOptions & {
|
|
44
|
-
type: ProcedureType;
|
|
45
|
-
path: string;
|
|
46
|
-
signal: Maybe<AbortSignal>;
|
|
47
|
-
};
|
|
48
|
-
type GetUrl = (opts: HTTPBaseRequestOptions) => string;
|
|
49
|
-
type GetBody = (opts: HTTPBaseRequestOptions) => RequestInitEsque['body'];
|
|
50
|
-
export type ContentOptions = {
|
|
51
|
-
trpcAcceptHeader?: TRPCAcceptHeader;
|
|
52
|
-
contentTypeHeader?: string;
|
|
53
|
-
getUrl: GetUrl;
|
|
54
|
-
getBody: GetBody;
|
|
55
|
-
};
|
|
56
|
-
export declare const getUrl: GetUrl;
|
|
57
|
-
export declare const getBody: GetBody;
|
|
58
|
-
export type Requester = (opts: HTTPBaseRequestOptions & {
|
|
59
|
-
headers: () => HTTPHeaders | Promise<HTTPHeaders>;
|
|
60
|
-
}) => Promise<HTTPResult>;
|
|
61
|
-
export declare const jsonHttpRequester: Requester;
|
|
62
|
-
export type HTTPRequestOptions = ContentOptions & HTTPBaseRequestOptions & {
|
|
63
|
-
headers: () => HTTPHeaders | Promise<HTTPHeaders>;
|
|
64
|
-
};
|
|
65
|
-
export declare function fetchHTTPResponse(opts: HTTPRequestOptions): Promise<ResponseEsque>;
|
|
66
|
-
export declare function httpRequest(opts: HTTPRequestOptions): Promise<HTTPResult>;
|
|
67
|
-
export {};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { HTTPLinkBaseOptions };
|
|
68
25
|
//# sourceMappingURL=httpUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpUtils.d.ts","
|
|
1
|
+
{"version":3,"file":"httpUtils.d.ts","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"}
|
|
@@ -1,141 +1,118 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var getFetch = require('../../getFetch.js');
|
|
4
|
-
var transformer = require('../../internals/transformer.js');
|
|
1
|
+
const require_getFetch = require('../../getFetch.js');
|
|
2
|
+
const require_transformer = require('../../internals/transformer.js');
|
|
5
3
|
|
|
4
|
+
//#region src/links/internals/httpUtils.ts
|
|
6
5
|
function resolveHTTPLinkOptions(opts) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
return {
|
|
7
|
+
url: opts.url.toString(),
|
|
8
|
+
fetch: opts.fetch,
|
|
9
|
+
transformer: require_transformer.getTransformer(opts.transformer),
|
|
10
|
+
methodOverride: opts.methodOverride
|
|
11
|
+
};
|
|
13
12
|
}
|
|
14
|
-
// https://github.com/trpc/trpc/pull/669
|
|
15
13
|
function arrayToDict(array) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
const dict = {};
|
|
15
|
+
for (let index = 0; index < array.length; index++) {
|
|
16
|
+
const element = array[index];
|
|
17
|
+
dict[index] = element;
|
|
18
|
+
}
|
|
19
|
+
return dict;
|
|
22
20
|
}
|
|
23
21
|
const METHOD = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
query: "GET",
|
|
23
|
+
mutation: "POST",
|
|
24
|
+
subscription: "PATCH"
|
|
27
25
|
};
|
|
28
26
|
function getInput(opts) {
|
|
29
|
-
|
|
27
|
+
return "input" in opts ? opts.transformer.input.serialize(opts.input) : arrayToDict(opts.inputs.map((_input) => opts.transformer.input.serialize(_input)));
|
|
30
28
|
}
|
|
31
|
-
const getUrl = (opts)=>{
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (input !== undefined && opts.methodOverride !== 'POST') {
|
|
45
|
-
queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
if (queryParts.length) {
|
|
49
|
-
url += '?' + queryParts.join('&');
|
|
50
|
-
}
|
|
51
|
-
return url;
|
|
29
|
+
const getUrl = (opts) => {
|
|
30
|
+
const parts = opts.url.split("?");
|
|
31
|
+
const base = parts[0].replace(/\/$/, "");
|
|
32
|
+
let url = base + "/" + opts.path;
|
|
33
|
+
const queryParts = [];
|
|
34
|
+
if (parts[1]) queryParts.push(parts[1]);
|
|
35
|
+
if ("inputs" in opts) queryParts.push("batch=1");
|
|
36
|
+
if (opts.type === "query" || opts.type === "subscription") {
|
|
37
|
+
const input = getInput(opts);
|
|
38
|
+
if (input !== void 0 && opts.methodOverride !== "POST") queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`);
|
|
39
|
+
}
|
|
40
|
+
if (queryParts.length) url += "?" + queryParts.join("&");
|
|
41
|
+
return url;
|
|
52
42
|
};
|
|
53
|
-
const getBody = (opts)=>{
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const input = getInput(opts);
|
|
58
|
-
return input !== undefined ? JSON.stringify(input) : undefined;
|
|
43
|
+
const getBody = (opts) => {
|
|
44
|
+
if (opts.type === "query" && opts.methodOverride !== "POST") return void 0;
|
|
45
|
+
const input = getInput(opts);
|
|
46
|
+
return input !== void 0 ? JSON.stringify(input) : void 0;
|
|
59
47
|
};
|
|
60
|
-
const jsonHttpRequester = (opts)=>{
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
48
|
+
const jsonHttpRequester = (opts) => {
|
|
49
|
+
return httpRequest({
|
|
50
|
+
...opts,
|
|
51
|
+
contentTypeHeader: "application/json",
|
|
52
|
+
getUrl,
|
|
53
|
+
getBody
|
|
54
|
+
});
|
|
67
55
|
};
|
|
68
56
|
/**
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
57
|
+
* Polyfill for DOMException with AbortError name
|
|
58
|
+
*/
|
|
59
|
+
var AbortError = class extends Error {
|
|
60
|
+
constructor() {
|
|
61
|
+
const name = "AbortError";
|
|
62
|
+
super(name);
|
|
63
|
+
this.name = name;
|
|
64
|
+
this.message = name;
|
|
65
|
+
}
|
|
66
|
+
};
|
|
78
67
|
/**
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
// If we have `DOMException`, use it
|
|
89
|
-
if (typeof DOMException !== 'undefined') {
|
|
90
|
-
throw new DOMException('AbortError', 'AbortError');
|
|
91
|
-
}
|
|
92
|
-
// Otherwise, use our own implementation
|
|
93
|
-
throw new AbortError();
|
|
68
|
+
* Polyfill for `signal.throwIfAborted()`
|
|
69
|
+
*
|
|
70
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/throwIfAborted
|
|
71
|
+
*/
|
|
72
|
+
const throwIfAborted = (signal) => {
|
|
73
|
+
if (!signal?.aborted) return;
|
|
74
|
+
signal.throwIfAborted?.();
|
|
75
|
+
if (typeof DOMException !== "undefined") throw new DOMException("AbortError", "AbortError");
|
|
76
|
+
throw new AbortError();
|
|
94
77
|
};
|
|
95
78
|
async function fetchHTTPResponse(opts) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return getFetch.getFetch(opts.fetch)(url, {
|
|
117
|
-
method: opts.methodOverride ?? METHOD[type],
|
|
118
|
-
signal: opts.signal,
|
|
119
|
-
body,
|
|
120
|
-
headers
|
|
121
|
-
});
|
|
79
|
+
throwIfAborted(opts.signal);
|
|
80
|
+
const url = opts.getUrl(opts);
|
|
81
|
+
const body = opts.getBody(opts);
|
|
82
|
+
const { type } = opts;
|
|
83
|
+
const resolvedHeaders = await (async () => {
|
|
84
|
+
const heads = await opts.headers();
|
|
85
|
+
if (Symbol.iterator in heads) return Object.fromEntries(heads);
|
|
86
|
+
return heads;
|
|
87
|
+
})();
|
|
88
|
+
const headers = {
|
|
89
|
+
...opts.contentTypeHeader ? { "content-type": opts.contentTypeHeader } : {},
|
|
90
|
+
...opts.trpcAcceptHeader ? { "trpc-accept": opts.trpcAcceptHeader } : void 0,
|
|
91
|
+
...resolvedHeaders
|
|
92
|
+
};
|
|
93
|
+
return require_getFetch.getFetch(opts.fetch)(url, {
|
|
94
|
+
method: opts.methodOverride ?? METHOD[type],
|
|
95
|
+
signal: opts.signal,
|
|
96
|
+
body,
|
|
97
|
+
headers
|
|
98
|
+
});
|
|
122
99
|
}
|
|
123
100
|
async function httpRequest(opts) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
101
|
+
const meta = {};
|
|
102
|
+
const res = await fetchHTTPResponse(opts);
|
|
103
|
+
meta.response = res;
|
|
104
|
+
const json = await res.json();
|
|
105
|
+
meta.responseJSON = json;
|
|
106
|
+
return {
|
|
107
|
+
json,
|
|
108
|
+
meta
|
|
109
|
+
};
|
|
133
110
|
}
|
|
134
111
|
|
|
112
|
+
//#endregion
|
|
135
113
|
exports.fetchHTTPResponse = fetchHTTPResponse;
|
|
136
114
|
exports.getBody = getBody;
|
|
137
|
-
exports.getInput = getInput;
|
|
138
115
|
exports.getUrl = getUrl;
|
|
139
116
|
exports.httpRequest = httpRequest;
|
|
140
117
|
exports.jsonHttpRequester = jsonHttpRequester;
|
|
141
|
-
exports.resolveHTTPLinkOptions = resolveHTTPLinkOptions;
|
|
118
|
+
exports.resolveHTTPLinkOptions = resolveHTTPLinkOptions;
|