@trpc/client 11.32.2 → 11.33.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/dist/httpBatchLink-DRitkRBC.mjs.map +1 -1
  2. package/dist/{httpBatchLink-DbD4ZGAM.d.cts → httpBatchLink-DaVHWlLU.d.mts} +6 -4
  3. package/dist/{httpBatchLink-DbD4ZGAM.d.cts.map → httpBatchLink-DaVHWlLU.d.mts.map} +1 -1
  4. package/dist/{httpBatchLink-Dk3_n5pP.d.mts → httpBatchLink-_bkMj4mk.d.cts} +6 -4
  5. package/dist/{httpBatchLink-Dk3_n5pP.d.mts.map → httpBatchLink-_bkMj4mk.d.cts.map} +1 -1
  6. package/dist/httpLink-Cmg_mV7L.mjs.map +1 -1
  7. package/dist/{httpLink-BjZdBzr6.d.mts → httpLink-DN_Ana7a.d.mts} +6 -4
  8. package/dist/httpLink-DN_Ana7a.d.mts.map +1 -0
  9. package/dist/{httpUtils-CxgZ3W-1.d.cts → httpUtils-1z6dzl3V.d.cts} +2 -2
  10. package/dist/{httpUtils-CxgZ3W-1.d.cts.map → httpUtils-1z6dzl3V.d.cts.map} +1 -1
  11. package/dist/{httpUtils-gZ7bAQ6T.d.mts → httpUtils-BAs5frdP.d.mts} +2 -2
  12. package/dist/{httpUtils-gZ7bAQ6T.d.mts.map → httpUtils-BAs5frdP.d.mts.map} +1 -1
  13. package/dist/index.cjs +22 -14
  14. package/dist/index.d.cts +93 -21
  15. package/dist/index.d.cts.map +1 -1
  16. package/dist/index.d.mts +96 -24
  17. package/dist/index.d.mts.map +1 -1
  18. package/dist/index.mjs +22 -15
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/links/httpBatchLink.d.cts +1 -1
  21. package/dist/links/httpBatchLink.d.mts +1 -1
  22. package/dist/links/httpLink.d.cts +5 -3
  23. package/dist/links/httpLink.d.cts.map +1 -1
  24. package/dist/links/httpLink.d.mts +1 -1
  25. package/dist/links/loggerLink.d.cts +4 -2
  26. package/dist/links/loggerLink.d.cts.map +1 -1
  27. package/dist/links/loggerLink.d.mts +1 -1
  28. package/dist/links/loggerLink.mjs.map +1 -1
  29. package/dist/links/splitLink.cjs +1 -1
  30. package/dist/links/splitLink.d.cts +21 -8
  31. package/dist/links/splitLink.d.cts.map +1 -1
  32. package/dist/links/splitLink.d.mts +1 -1
  33. package/dist/links/splitLink.mjs +1 -1
  34. package/dist/links/wsLink/wsLink.d.cts +1 -1
  35. package/dist/links/wsLink/wsLink.d.mts +1 -1
  36. package/dist/{loggerLink-CBPx95zm.d.mts → loggerLink-CiVinJOG.d.mts} +5 -3
  37. package/dist/loggerLink-CiVinJOG.d.mts.map +1 -0
  38. package/dist/{splitLink-BBLj14Dv.cjs → splitLink-BQoYcpdp.cjs} +3 -0
  39. package/dist/splitLink-ClFN_nbg.d.mts +35 -0
  40. package/dist/splitLink-ClFN_nbg.d.mts.map +1 -0
  41. package/dist/{splitLink-PFsRy7Mf.mjs → splitLink-IUbsOwO6.mjs} +4 -1
  42. package/dist/splitLink-IUbsOwO6.mjs.map +1 -0
  43. package/dist/{types-BhHxuBsu.d.cts → types-DMe6B4SV.d.cts} +65 -8
  44. package/dist/types-DMe6B4SV.d.cts.map +1 -0
  45. package/dist/{types-BG-3kpeg.d.mts → types-DW0iJUBU.d.mts} +65 -8
  46. package/dist/types-DW0iJUBU.d.mts.map +1 -0
  47. package/dist/wsLink-C_Zg2yXV.mjs.map +1 -1
  48. package/dist/{wsLink-DU5wj6kH.d.mts → wsLink-DX5fv7-H.d.mts} +5 -3
  49. package/dist/{wsLink-BlAMQb0i.d.cts.map → wsLink-DX5fv7-H.d.mts.map} +1 -1
  50. package/dist/{wsLink-BlAMQb0i.d.cts → wsLink-DuyXOEPt.d.cts} +5 -3
  51. package/dist/{wsLink-DU5wj6kH.d.mts.map → wsLink-DuyXOEPt.d.cts.map} +1 -1
  52. package/package.json +3 -3
  53. package/skills/client-setup/SKILL.md +1 -1
  54. package/skills/links/SKILL.md +58 -1
  55. package/skills/superjson/SKILL.md +1 -1
  56. package/src/createTRPCClient.ts +88 -21
  57. package/src/index.ts +1 -0
  58. package/src/internals/types.ts +8 -5
  59. package/src/links/httpBatchLink.ts +6 -2
  60. package/src/links/httpBatchStreamLink.ts +6 -2
  61. package/src/links/httpLink.ts +6 -1
  62. package/src/links/httpSubscriptionLink.ts +6 -2
  63. package/src/links/localLink.ts +1 -1
  64. package/src/links/loggerLink.ts +11 -2
  65. package/src/links/retryLink.ts +6 -2
  66. package/src/links/splitLink.ts +52 -10
  67. package/src/links/types.ts +109 -3
  68. package/src/links/wsLink/wsLink.ts +1 -1
  69. package/src/routerType.ts +31 -0
  70. package/dist/httpLink-BjZdBzr6.d.mts.map +0 -1
  71. package/dist/loggerLink-CBPx95zm.d.mts.map +0 -1
  72. package/dist/splitLink-BtPz7lCB.d.mts +0 -23
  73. package/dist/splitLink-BtPz7lCB.d.mts.map +0 -1
  74. package/dist/splitLink-PFsRy7Mf.mjs.map +0 -1
  75. package/dist/types-BG-3kpeg.d.mts.map +0 -1
  76. package/dist/types-BhHxuBsu.d.cts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"httpBatchLink-DRitkRBC.mjs","names":[],"sources":["../src/internals/dataLoader.ts","../src/links/httpBatchLink.ts"],"sourcesContent":["/* oxlint-disable typescript/no-non-null-assertion */\n\ntype BatchItem<TKey, TValue> = {\n aborted: boolean;\n key: TKey;\n resolve: ((value: TValue) => void) | null;\n reject: ((error: Error) => void) | null;\n batch: Batch<TKey, TValue> | null;\n};\ntype Batch<TKey, TValue> = {\n items: BatchItem<TKey, TValue>[];\n};\nexport type BatchLoader<TKey, TValue> = {\n validate: (keys: TKey[]) => boolean;\n fetch: (keys: TKey[]) => Promise<TValue[] | Promise<TValue>[]>;\n};\n\n/**\n * A function that should never be called unless we messed something up.\n */\nconst throwFatalError = () => {\n throw new Error(\n 'Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new',\n );\n};\n\n/**\n * Dataloader that's very inspired by https://github.com/graphql/dataloader\n * Less configuration, no caching, and allows you to cancel requests\n * When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled\n */\nexport function dataLoader<TKey, TValue>(\n batchLoader: BatchLoader<TKey, TValue>,\n) {\n let pendingItems: BatchItem<TKey, TValue>[] | null = null;\n let dispatchTimer: ReturnType<typeof setTimeout> | null = null;\n\n const destroyTimerAndPendingItems = () => {\n clearTimeout(dispatchTimer as any);\n dispatchTimer = null;\n pendingItems = null;\n };\n\n /**\n * Iterate through the items and split them into groups based on the `batchLoader`'s validate function\n */\n function groupItems(items: BatchItem<TKey, TValue>[]) {\n const groupedItems: BatchItem<TKey, TValue>[][] = [[]];\n let index = 0;\n while (true) {\n const item = items[index];\n if (!item) {\n // we're done\n break;\n }\n const lastGroup = groupedItems[groupedItems.length - 1]!;\n\n if (item.aborted) {\n // Item was aborted before it was dispatched\n item.reject?.(new Error('Aborted'));\n index++;\n continue;\n }\n\n let isValid: boolean;\n try {\n isValid = batchLoader.validate(\n lastGroup.concat(item).map((it) => it.key),\n );\n } catch (cause) {\n item.reject?.(cause as Error);\n index++;\n continue;\n }\n\n if (isValid) {\n lastGroup.push(item);\n index++;\n continue;\n }\n\n if (lastGroup.length === 0) {\n item.reject?.(new Error('Input is too big for a single dispatch'));\n index++;\n continue;\n }\n // Create new group, next iteration will try to add the item to that\n groupedItems.push([]);\n }\n return groupedItems;\n }\n\n function dispatch() {\n const groupedItems = groupItems(pendingItems!);\n destroyTimerAndPendingItems();\n\n // Create batches for each group of items\n for (const items of groupedItems) {\n if (!items.length) {\n continue;\n }\n const batch: Batch<TKey, TValue> = {\n items,\n };\n for (const item of items) {\n item.batch = batch;\n }\n const promise = batchLoader.fetch(batch.items.map((_item) => _item.key));\n\n promise\n .then(async (result) => {\n await Promise.all(\n result.map(async (valueOrPromise, index) => {\n const item = batch.items[index]!;\n try {\n const value = await Promise.resolve(valueOrPromise);\n\n item.resolve?.(value);\n } catch (cause) {\n item.reject?.(cause as Error);\n }\n\n item.batch = null;\n item.reject = null;\n item.resolve = null;\n }),\n );\n\n for (const item of batch.items) {\n item.reject?.(new Error('Missing result'));\n item.batch = null;\n }\n })\n .catch((cause) => {\n for (const item of batch.items) {\n item.reject?.(cause);\n item.batch = null;\n }\n });\n }\n }\n function load(key: TKey): Promise<TValue> {\n const item: BatchItem<TKey, TValue> = {\n aborted: false,\n key,\n batch: null,\n resolve: throwFatalError,\n reject: throwFatalError,\n };\n\n const promise = new Promise<TValue>((resolve, reject) => {\n item.reject = reject;\n item.resolve = resolve;\n\n pendingItems ??= [];\n pendingItems.push(item);\n });\n\n dispatchTimer ??= setTimeout(dispatch);\n\n return promise;\n }\n\n return {\n load,\n };\n}\n","import type { AnyRouter, ProcedureType } from '@trpc/server';\nimport { observable } from '@trpc/server/observable';\nimport { transformResult } from '@trpc/server/unstable-core-do-not-import';\nimport type { BatchLoader } from '../internals/dataLoader';\nimport { dataLoader } from '../internals/dataLoader';\nimport {\n allAbortSignals,\n raceAbortSignalsWithCleanup,\n} from '../internals/signals';\nimport type { NonEmptyArray } from '../internals/types';\nimport { TRPCClientError } from '../TRPCClientError';\nimport type { HTTPBatchLinkOptions } from './HTTPBatchLinkOptions';\nimport type { HTTPResult } from './internals/httpUtils';\nimport {\n getUrl,\n jsonHttpRequester,\n resolveHTTPLinkOptions,\n} from './internals/httpUtils';\nimport type { Operation, TRPCLink } from './types';\n\n/**\n * A terminating link that batches calls made in the same tick into one HTTP\n * request.\n *\n * @see https://trpc.io/docs/client/links/httpBatchLink\n */\nexport function httpBatchLink<TRouter extends AnyRouter>(\n opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>,\n): TRPCLink<TRouter> {\n const resolvedOpts = resolveHTTPLinkOptions(opts);\n const maxURLLength = opts.maxURLLength ?? Infinity;\n const maxItems = opts.maxItems ?? Infinity;\n\n return () => {\n const batchLoader = (\n type: ProcedureType,\n ): BatchLoader<Operation, HTTPResult> => {\n return {\n validate(batchOps) {\n if (maxURLLength === Infinity && maxItems === Infinity) {\n // escape hatch for quick calcs\n return true;\n }\n if (batchOps.length > maxItems) {\n return false;\n }\n const path = batchOps.map((op) => op.path).join(',');\n const inputs = batchOps.map((op) => op.input);\n\n const url = getUrl({\n ...resolvedOpts,\n type,\n path,\n inputs,\n signal: null,\n });\n\n return url.length <= maxURLLength;\n },\n async fetch(batchOps) {\n const path = batchOps.map((op) => op.path).join(',');\n const inputs = batchOps.map((op) => op.input);\n const signal = allAbortSignals(...batchOps.map((op) => op.signal));\n\n const res = await jsonHttpRequester({\n ...resolvedOpts,\n path,\n inputs,\n type,\n headers() {\n if (!opts.headers) {\n return {};\n }\n if (typeof opts.headers === 'function') {\n return opts.headers({\n opList: batchOps as NonEmptyArray<Operation>,\n });\n }\n return opts.headers;\n },\n signal,\n });\n const resJSON = Array.isArray(res.json)\n ? res.json\n : batchOps.map(() => res.json);\n const result = resJSON.map((item) => ({\n meta: res.meta,\n json: item,\n }));\n return result;\n },\n };\n };\n\n const query = dataLoader(batchLoader('query'));\n const mutation = dataLoader(batchLoader('mutation'));\n\n const loaders = { query, mutation };\n return ({ op }) => {\n return observable((observer) => {\n /* istanbul ignore if -- @preserve */\n if (op.type === 'subscription') {\n throw new Error(\n 'Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`',\n );\n }\n const ac = new AbortController();\n const { signal, cleanup } = raceAbortSignalsWithCleanup(\n op.signal,\n ac.signal,\n );\n const loader = loaders[op.type];\n const promise = loader.load({\n ...op,\n signal,\n });\n\n let isDone = false;\n let _res = undefined as HTTPResult | undefined;\n promise\n .then((res) => {\n isDone = true;\n _res = res;\n const transformed = transformResult(\n res.json,\n resolvedOpts.transformer.output,\n );\n\n if (!transformed.ok) {\n observer.error(\n TRPCClientError.from(transformed.error, {\n meta: res.meta,\n }),\n );\n return;\n }\n observer.next({\n context: res.meta,\n result: transformed.result,\n });\n observer.complete();\n })\n .catch((err) => {\n isDone = true;\n observer.error(\n TRPCClientError.from(err, {\n meta: _res?.meta,\n }),\n );\n });\n\n return () => {\n if (!isDone) {\n ac.abort();\n }\n cleanup();\n };\n });\n };\n };\n}\n"],"mappings":";;;;;;;;;AAoBA,MAAM,wBAAwB;CAC5B,MAAM,IAAI,MACR,yFACF;AACF;;;;;;AAOA,SAAgB,WACd,aACA;CACA,IAAI,eAAiD;CACrD,IAAI,gBAAsD;CAE1D,MAAM,oCAAoC;EACxC,aAAa,aAAoB;EACjC,gBAAgB;EAChB,eAAe;CACjB;;;;CAKA,SAAS,WAAW,OAAkC;EACpD,MAAM,eAA4C,CAAC,CAAC,CAAC;EACrD,IAAI,QAAQ;EACZ,OAAO,MAAM;GACX,MAAM,OAAO,MAAM;GACnB,IAAI,CAAC,MAEH;GAEF,MAAM,YAAY,aAAa,aAAa,SAAS;GAErD,IAAI,KAAK,SAAS;;IAEhB,CAAA,eAAA,KAAK,YAAA,QAAA,iBAAA,KAAA,KAAA,aAAA,KAAA,sBAAS,IAAI,MAAM,SAAS,CAAC;IAClC;IACA;GACF;GAEA,IAAI;GACJ,IAAI;IACF,UAAU,YAAY,SACpB,UAAU,OAAO,IAAI,CAAC,CAAC,KAAK,OAAO,GAAG,GAAG,CAC3C;GACF,SAAS,OAAO;;IACd,CAAA,gBAAA,KAAK,YAAA,QAAA,kBAAA,KAAA,KAAA,cAAA,KAAA,MAAS,KAAc;IAC5B;IACA;GACF;GAEA,IAAI,SAAS;IACX,UAAU,KAAK,IAAI;IACnB;IACA;GACF;GAEA,IAAI,UAAU,WAAW,GAAG;;IAC1B,CAAA,gBAAA,KAAK,YAAA,QAAA,kBAAA,KAAA,KAAA,cAAA,KAAA,sBAAS,IAAI,MAAM,wCAAwC,CAAC;IACjE;IACA;GACF;GAEA,aAAa,KAAK,CAAC,CAAC;EACtB;EACA,OAAO;CACT;CAEA,SAAS,WAAW;EAClB,MAAM,eAAe,WAAW,YAAa;EAC7C,4BAA4B;EAG5B,KAAK,MAAM,SAAS,cAAc;GAChC,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Q,IAAI,IAAI,IAClC,IAAI,OACJ,SAAS,UAAU,IAAI,IAAI,EAAA,CACR,KAAK,UAAU;MACpC,MAAM,IAAI;MACV,MAAM;KACR,EACY;IACd;GACF;EACF;EAKA,MAAM,UAAU;GAAE,OAHJ,WAAW,YAAY,OAAO,CAGtB;GAAG,UAFR,WAAW,YAAY,UAAU,CAElB;EAAE;EAClC,QAAQ,EAAE,SAAS;GACjB,OAAO,YAAY,aAAa;;IAE9B,IAAI,GAAG,SAAS,gBACd,MAAM,IAAI,MACR,sFACF;IAEF,MAAM,KAAK,IAAI,gBAAgB;IAC/B,MAAM,EAAE,QAAQ,YAAY,4BAC1B,GAAG,QACH,GAAG,MACL;IAEA,MAAM,UADS,QAAQ,GAAG,KACJ,CAAC,KAAA,eAAA,eAAA,CAAA,GAClB,EAAA,GAAA,CAAA,GAAA,EACH,OAAA,CACF,CAAC;IAED,IAAI,SAAS;IACb,IAAI,OAAO,KAAA;IACX,QACG,MAAM,QAAQ;KACb,SAAS;KACT,OAAO;KACP,MAAM,cAAc,gBAClB,IAAI,MACJ,aAAa,YAAY,MAC3B;KAEA,IAAI,CAAC,YAAY,IAAI;MACnB,SAAS,MACP,gBAAgB,KAAK,YAAY,OAAO,EACtC,MAAM,IAAI,KACZ,CAAC,CACH;MACA;KACF;KACA,SAAS,KAAK;MACZ,SAAS,IAAI;MACb,QAAQ,YAAY;KACtB,CAAC;KACD,SAAS,SAAS;IACpB,CAAC,CAAC,CACD,OAAO,QAAQ;KACd,SAAS;KACT,SAAS,MACP,gBAAgB,KAAK,KAAK,EACxB,MAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAAM,KAAM,KACd,CAAC,CACH;IACF,CAAC;IAEH,aAAa;KACX,IAAI,CAAC,QACH,GAAG,MAAM;KAEX,QAAQ;IACV;GACF,CAAC;EACH;CACF;AACF"}
1
+ {"version":3,"file":"httpBatchLink-DRitkRBC.mjs","names":[],"sources":["../src/internals/dataLoader.ts","../src/links/httpBatchLink.ts"],"sourcesContent":["/* oxlint-disable typescript/no-non-null-assertion */\n\ntype BatchItem<TKey, TValue> = {\n aborted: boolean;\n key: TKey;\n resolve: ((value: TValue) => void) | null;\n reject: ((error: Error) => void) | null;\n batch: Batch<TKey, TValue> | null;\n};\ntype Batch<TKey, TValue> = {\n items: BatchItem<TKey, TValue>[];\n};\nexport type BatchLoader<TKey, TValue> = {\n validate: (keys: TKey[]) => boolean;\n fetch: (keys: TKey[]) => Promise<TValue[] | Promise<TValue>[]>;\n};\n\n/**\n * A function that should never be called unless we messed something up.\n */\nconst throwFatalError = () => {\n throw new Error(\n 'Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new',\n );\n};\n\n/**\n * Dataloader that's very inspired by https://github.com/graphql/dataloader\n * Less configuration, no caching, and allows you to cancel requests\n * When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled\n */\nexport function dataLoader<TKey, TValue>(\n batchLoader: BatchLoader<TKey, TValue>,\n) {\n let pendingItems: BatchItem<TKey, TValue>[] | null = null;\n let dispatchTimer: ReturnType<typeof setTimeout> | null = null;\n\n const destroyTimerAndPendingItems = () => {\n clearTimeout(dispatchTimer as any);\n dispatchTimer = null;\n pendingItems = null;\n };\n\n /**\n * Iterate through the items and split them into groups based on the `batchLoader`'s validate function\n */\n function groupItems(items: BatchItem<TKey, TValue>[]) {\n const groupedItems: BatchItem<TKey, TValue>[][] = [[]];\n let index = 0;\n while (true) {\n const item = items[index];\n if (!item) {\n // we're done\n break;\n }\n const lastGroup = groupedItems[groupedItems.length - 1]!;\n\n if (item.aborted) {\n // Item was aborted before it was dispatched\n item.reject?.(new Error('Aborted'));\n index++;\n continue;\n }\n\n let isValid: boolean;\n try {\n isValid = batchLoader.validate(\n lastGroup.concat(item).map((it) => it.key),\n );\n } catch (cause) {\n item.reject?.(cause as Error);\n index++;\n continue;\n }\n\n if (isValid) {\n lastGroup.push(item);\n index++;\n continue;\n }\n\n if (lastGroup.length === 0) {\n item.reject?.(new Error('Input is too big for a single dispatch'));\n index++;\n continue;\n }\n // Create new group, next iteration will try to add the item to that\n groupedItems.push([]);\n }\n return groupedItems;\n }\n\n function dispatch() {\n const groupedItems = groupItems(pendingItems!);\n destroyTimerAndPendingItems();\n\n // Create batches for each group of items\n for (const items of groupedItems) {\n if (!items.length) {\n continue;\n }\n const batch: Batch<TKey, TValue> = {\n items,\n };\n for (const item of items) {\n item.batch = batch;\n }\n const promise = batchLoader.fetch(batch.items.map((_item) => _item.key));\n\n promise\n .then(async (result) => {\n await Promise.all(\n result.map(async (valueOrPromise, index) => {\n const item = batch.items[index]!;\n try {\n const value = await Promise.resolve(valueOrPromise);\n\n item.resolve?.(value);\n } catch (cause) {\n item.reject?.(cause as Error);\n }\n\n item.batch = null;\n item.reject = null;\n item.resolve = null;\n }),\n );\n\n for (const item of batch.items) {\n item.reject?.(new Error('Missing result'));\n item.batch = null;\n }\n })\n .catch((cause) => {\n for (const item of batch.items) {\n item.reject?.(cause);\n item.batch = null;\n }\n });\n }\n }\n function load(key: TKey): Promise<TValue> {\n const item: BatchItem<TKey, TValue> = {\n aborted: false,\n key,\n batch: null,\n resolve: throwFatalError,\n reject: throwFatalError,\n };\n\n const promise = new Promise<TValue>((resolve, reject) => {\n item.reject = reject;\n item.resolve = resolve;\n\n pendingItems ??= [];\n pendingItems.push(item);\n });\n\n dispatchTimer ??= setTimeout(dispatch);\n\n return promise;\n }\n\n return {\n load,\n };\n}\n","import type { AnyRouter, ProcedureType } from '@trpc/server';\nimport { observable } from '@trpc/server/observable';\nimport { transformResult } from '@trpc/server/unstable-core-do-not-import';\nimport type { BatchLoader } from '../internals/dataLoader';\nimport { dataLoader } from '../internals/dataLoader';\nimport {\n allAbortSignals,\n raceAbortSignalsWithCleanup,\n} from '../internals/signals';\nimport type { NonEmptyArray } from '../internals/types';\nimport { TRPCClientError } from '../TRPCClientError';\nimport type { HTTPBatchLinkOptions } from './HTTPBatchLinkOptions';\nimport type { HTTPResult } from './internals/httpUtils';\nimport {\n getUrl,\n jsonHttpRequester,\n resolveHTTPLinkOptions,\n} from './internals/httpUtils';\nimport type { AugmentedOperationContext, Operation, TRPCLink } from './types';\n\n/**\n * A terminating link that batches calls made in the same tick into one HTTP\n * request.\n *\n * @see https://trpc.io/docs/client/links/httpBatchLink\n */\nexport function httpBatchLink<TRouter extends AnyRouter>(\n opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>,\n): TRPCLink<\n TRouter,\n // its callbacks may read the fields added to `OperationContext`\n { context: AugmentedOperationContext }\n> {\n const resolvedOpts = resolveHTTPLinkOptions(opts);\n const maxURLLength = opts.maxURLLength ?? Infinity;\n const maxItems = opts.maxItems ?? Infinity;\n\n return () => {\n const batchLoader = (\n type: ProcedureType,\n ): BatchLoader<Operation, HTTPResult> => {\n return {\n validate(batchOps) {\n if (maxURLLength === Infinity && maxItems === Infinity) {\n // escape hatch for quick calcs\n return true;\n }\n if (batchOps.length > maxItems) {\n return false;\n }\n const path = batchOps.map((op) => op.path).join(',');\n const inputs = batchOps.map((op) => op.input);\n\n const url = getUrl({\n ...resolvedOpts,\n type,\n path,\n inputs,\n signal: null,\n });\n\n return url.length <= maxURLLength;\n },\n async fetch(batchOps) {\n const path = batchOps.map((op) => op.path).join(',');\n const inputs = batchOps.map((op) => op.input);\n const signal = allAbortSignals(...batchOps.map((op) => op.signal));\n\n const res = await jsonHttpRequester({\n ...resolvedOpts,\n path,\n inputs,\n type,\n headers() {\n if (!opts.headers) {\n return {};\n }\n if (typeof opts.headers === 'function') {\n return opts.headers({\n opList: batchOps as NonEmptyArray<Operation>,\n });\n }\n return opts.headers;\n },\n signal,\n });\n const resJSON = Array.isArray(res.json)\n ? res.json\n : batchOps.map(() => res.json);\n const result = resJSON.map((item) => ({\n meta: res.meta,\n json: item,\n }));\n return result;\n },\n };\n };\n\n const query = dataLoader(batchLoader('query'));\n const mutation = dataLoader(batchLoader('mutation'));\n\n const loaders = { query, mutation };\n return ({ op }) => {\n return observable((observer) => {\n /* istanbul ignore if -- @preserve */\n if (op.type === 'subscription') {\n throw new Error(\n 'Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`',\n );\n }\n const ac = new AbortController();\n const { signal, cleanup } = raceAbortSignalsWithCleanup(\n op.signal,\n ac.signal,\n );\n const loader = loaders[op.type];\n const promise = loader.load({\n ...op,\n signal,\n });\n\n let isDone = false;\n let _res = undefined as HTTPResult | undefined;\n promise\n .then((res) => {\n isDone = true;\n _res = res;\n const transformed = transformResult(\n res.json,\n resolvedOpts.transformer.output,\n );\n\n if (!transformed.ok) {\n observer.error(\n TRPCClientError.from(transformed.error, {\n meta: res.meta,\n }),\n );\n return;\n }\n observer.next({\n context: res.meta,\n result: transformed.result,\n });\n observer.complete();\n })\n .catch((err) => {\n isDone = true;\n observer.error(\n TRPCClientError.from(err, {\n meta: _res?.meta,\n }),\n );\n });\n\n return () => {\n if (!isDone) {\n ac.abort();\n }\n cleanup();\n };\n });\n };\n };\n}\n"],"mappings":";;;;;;;;;AAoBA,MAAM,wBAAwB;CAC5B,MAAM,IAAI,MACR,yFACF;AACF;;;;;;AAOA,SAAgB,WACd,aACA;CACA,IAAI,eAAiD;CACrD,IAAI,gBAAsD;CAE1D,MAAM,oCAAoC;EACxC,aAAa,aAAoB;EACjC,gBAAgB;EAChB,eAAe;CACjB;;;;CAKA,SAAS,WAAW,OAAkC;EACpD,MAAM,eAA4C,CAAC,CAAC,CAAC;EACrD,IAAI,QAAQ;EACZ,OAAO,MAAM;GACX,MAAM,OAAO,MAAM;GACnB,IAAI,CAAC,MAEH;GAEF,MAAM,YAAY,aAAa,aAAa,SAAS;GAErD,IAAI,KAAK,SAAS;;IAEhB,CAAA,eAAA,KAAK,YAAA,QAAA,iBAAA,KAAA,KAAA,aAAA,KAAA,sBAAS,IAAI,MAAM,SAAS,CAAC;IAClC;IACA;GACF;GAEA,IAAI;GACJ,IAAI;IACF,UAAU,YAAY,SACpB,UAAU,OAAO,IAAI,CAAC,CAAC,KAAK,OAA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BAAgB,KAAK,YAAY,OAAO,EACtC,MAAM,IAAI,KACZ,CAAC,CACH;MACA;KACF;KACA,SAAS,KAAK;MACZ,SAAS,IAAI;MACb,QAAQ,YAAY;KACtB,CAAC;KACD,SAAS,SAAS;IACpB,CAAC,CAAC,CACD,OAAO,QAAQ;KACd,SAAS;KACT,SAAS,MACP,gBAAgB,KAAK,KAAK,EACxB,MAAA,SAAA,QAAA,SAAA,KAAA,IAAA,KAAA,IAAM,KAAM,KACd,CAAC,CACH;IACF,CAAC;IAEH,aAAa;KACX,IAAI,CAAC,QACH,GAAG,MAAM;KAEX,QAAQ;IACV;GACF,CAAC;EACH;CACF;AACF"}
@@ -1,5 +1,5 @@
1
- import { b as NonEmptyArray, n as Operation, t as HTTPHeaders, u as TRPCLink } from "./types-BhHxuBsu.cjs";
2
- import { t as HTTPLinkBaseOptions } from "./httpUtils-CxgZ3W-1.cjs";
1
+ import { S as NonEmptyArray, a as Operation, n as HTTPHeaders, p as TRPCLink, t as AugmentedOperationContext } from "./types-DW0iJUBU.mjs";
2
+ import { t as HTTPLinkBaseOptions } from "./httpUtils-BAs5frdP.mjs";
3
3
  import { AnyClientTypes } from "@trpc/server/unstable-core-do-not-import";
4
4
  import { AnyRouter as AnyRouter$1 } from "@trpc/server";
5
5
  /**
@@ -37,6 +37,8 @@ type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TR
37
37
  *
38
38
  * @see https://trpc.io/docs/client/links/httpBatchLink
39
39
  */
40
- declare function httpBatchLink<TRouter extends AnyRouter$1>(opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
40
+ declare function httpBatchLink<TRouter extends AnyRouter$1>(opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter, {
41
+ context: AugmentedOperationContext;
42
+ }>;
41
43
  export { HTTPBatchLinkOptions as n, httpBatchLink as t };
42
- //# sourceMappingURL=httpBatchLink-DbD4ZGAM.d.cts.map
44
+ //# sourceMappingURL=httpBatchLink-DaVHWlLU.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"httpBatchLink-DbD4ZGAM.d.cts","names":["AnyRouter"],"sources":["../src/links/HTTPBatchLinkOptions.ts","../src/links/httpBatchLink.ts"],"mappings":";;;;;;;;KASY,qBAAqB,cAAc,kBAC7C,oBAAoB;;;;;;;;EAQlB;;;;;;EAMA,UACI,gBACE;IACA,QAAQ,cAAc;QAClB,cAAc,QAAQ;;;;;;;EAQhC;;;;;;;;iBCVY,cAAc,gBAAgBA,aAC5C,MAAM,qBAAqB,wCAC1B,SAAS"}
1
+ {"version":3,"file":"httpBatchLink-DaVHWlLU.d.mts","names":["AnyRouter"],"sources":["../src/links/HTTPBatchLinkOptions.ts","../src/links/httpBatchLink.ts"],"mappings":";;;;;;;;KASY,qBAAqB,cAAc,kBAC7C,oBAAoB;;;;;;;;EAQlB;;;;;;EAMA,UACI,gBACE;IACA,QAAQ,cAAc;QAClB,cAAc,QAAQ;;;;;;;EAQhC;;;;;;;;iBCVY,cAAc,gBAAgBA,aAC5C,MAAM,qBAAqB,wCAC1B,SACD;EAEE,SAAS"}
@@ -1,5 +1,5 @@
1
- import { _ as NonEmptyArray, n as Operation, t as HTTPHeaders, u as TRPCLink } from "./types-BG-3kpeg.mjs";
2
- import { t as HTTPLinkBaseOptions } from "./httpUtils-gZ7bAQ6T.mjs";
1
+ import { T as NonEmptyArray, a as Operation, n as HTTPHeaders, p as TRPCLink, t as AugmentedOperationContext } from "./types-DMe6B4SV.cjs";
2
+ import { t as HTTPLinkBaseOptions } from "./httpUtils-1z6dzl3V.cjs";
3
3
  import { AnyClientTypes } from "@trpc/server/unstable-core-do-not-import";
4
4
  import { AnyRouter as AnyRouter$1 } from "@trpc/server";
5
5
  /**
@@ -37,6 +37,8 @@ type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TR
37
37
  *
38
38
  * @see https://trpc.io/docs/client/links/httpBatchLink
39
39
  */
40
- declare function httpBatchLink<TRouter extends AnyRouter$1>(opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
40
+ declare function httpBatchLink<TRouter extends AnyRouter$1>(opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter, {
41
+ context: AugmentedOperationContext;
42
+ }>;
41
43
  export { HTTPBatchLinkOptions as n, httpBatchLink as t };
42
- //# sourceMappingURL=httpBatchLink-Dk3_n5pP.d.mts.map
44
+ //# sourceMappingURL=httpBatchLink-_bkMj4mk.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"httpBatchLink-Dk3_n5pP.d.mts","names":["AnyRouter"],"sources":["../src/links/HTTPBatchLinkOptions.ts","../src/links/httpBatchLink.ts"],"mappings":";;;;;;;;KASY,qBAAqB,cAAc,kBAC7C,oBAAoB;;;;;;;;EAQlB;;;;;;EAMA,UACI,gBACE;IACA,QAAQ,cAAc;QAClB,cAAc,QAAQ;;;;;;;EAQhC;;;;;;;;iBCVY,cAAc,gBAAgBA,aAC5C,MAAM,qBAAqB,wCAC1B,SAAS"}
1
+ {"version":3,"file":"httpBatchLink-_bkMj4mk.d.cts","names":["AnyRouter"],"sources":["../src/links/HTTPBatchLinkOptions.ts","../src/links/httpBatchLink.ts"],"mappings":";;;;;;;;KASY,qBAAqB,cAAc,kBAC7C,oBAAoB;;;;;;;;EAQlB;;;;;;EAMA,UACI,gBACE;IACA,QAAQ,cAAc;QAClB,cAAc,QAAQ;;;;;;;EAQhC;;;;;;;;iBCVY,cAAc,gBAAgBA,aAC5C,MAAM,qBAAqB,wCAC1B,SACD;EAEE,SAAS"}
@@ -1 +1 @@
1
- {"version":3,"file":"httpLink-Cmg_mV7L.mjs","names":[],"sources":["../src/links/internals/contentTypes.ts","../src/links/httpLink.ts"],"sourcesContent":["/** Whether an input is binary: a `Uint8Array`, `Blob` or `File`. */\nexport function isOctetType(\n input: unknown,\n): input is Uint8Array<ArrayBuffer> | Blob {\n return (\n input instanceof Uint8Array ||\n // File extends from Blob but is only available in nodejs from v20\n input instanceof Blob\n );\n}\n\n/** Whether an input is `FormData`. */\nexport function isFormData(input: unknown) {\n return input instanceof FormData;\n}\n\n/**\n * Whether an input can't be sent as JSON: binary data or `FormData`. Use\n * it in a `splitLink` to send such inputs with `httpLink`.\n * @see https://trpc.io/docs/server/non-json-content-types#client-setup\n */\nexport function isNonJsonSerializable(input: unknown) {\n return isOctetType(input) || isFormData(input);\n}\n","import { observable } from '@trpc/server/observable';\nimport type {\n AnyClientTypes,\n AnyRouter,\n} from '@trpc/server/unstable-core-do-not-import';\nimport { transformResult } from '@trpc/server/unstable-core-do-not-import';\nimport { raceAbortSignalsWithCleanup } from '../internals/signals';\nimport { TRPCClientError } from '../TRPCClientError';\nimport type {\n HTTPLinkBaseOptions,\n HTTPResult,\n Requester,\n} from './internals/httpUtils';\nimport {\n getUrl,\n httpRequest,\n jsonHttpRequester,\n resolveHTTPLinkOptions,\n} from './internals/httpUtils';\nimport {\n isFormData,\n isOctetType,\n type HTTPHeaders,\n type Operation,\n type TRPCLink,\n} from './types';\n\n/**\n * The options of `httpLink`.\n * @see https://trpc.io/docs/client/links/httpLink#httplink-options\n */\nexport type HTTPLinkOptions<TRoot extends AnyClientTypes> =\n HTTPLinkBaseOptions<TRoot> & {\n /**\n * Headers for each request: an object, or a function of the operation\n * that returns them.\n * @see https://trpc.io/docs/client/headers\n */\n headers?:\n | HTTPHeaders\n | ((opts: { op: Operation }) => HTTPHeaders | Promise<HTTPHeaders>);\n };\n\nconst universalRequester: Requester = (opts) => {\n if ('input' in opts) {\n const { input } = opts;\n if (isFormData(input)) {\n if (opts.type !== 'mutation' && opts.methodOverride !== 'POST') {\n throw new Error('FormData is only supported for mutations');\n }\n\n return httpRequest({\n ...opts,\n // The browser will set this automatically and include the boundary= in it\n contentTypeHeader: undefined,\n getUrl,\n getBody: () => input,\n });\n }\n\n if (isOctetType(input)) {\n if (opts.type !== 'mutation' && opts.methodOverride !== 'POST') {\n throw new Error('Octet type input is only supported for mutations');\n }\n\n return httpRequest({\n ...opts,\n contentTypeHeader: 'application/octet-stream',\n getUrl,\n getBody: () => input,\n });\n }\n }\n\n return jsonHttpRequester(opts);\n};\n\n/**\n * A terminating link that sends each call in its own HTTP request. It can\n * send `FormData` and binary inputs.\n * @see https://trpc.io/docs/client/links/httpLink\n */\nexport function httpLink<TRouter extends AnyRouter = AnyRouter>(\n opts: HTTPLinkOptions<TRouter['_def']['_config']['$types']>,\n): TRPCLink<TRouter> {\n const resolvedOpts = resolveHTTPLinkOptions(opts);\n return () => {\n return (operationOpts) => {\n const { op } = operationOpts;\n return observable((observer) => {\n const { path, input, type } = op;\n /* istanbul ignore if -- @preserve */\n if (type === 'subscription') {\n throw new Error(\n 'Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`',\n );\n }\n\n const ac = new AbortController();\n const { signal, cleanup } = raceAbortSignalsWithCleanup(\n op.signal,\n ac.signal,\n );\n let request: Promise<HTTPResult>;\n try {\n request = universalRequester({\n ...resolvedOpts,\n type,\n path,\n input,\n signal,\n headers() {\n if (!opts.headers) {\n return {};\n }\n if (typeof opts.headers === 'function') {\n return opts.headers({\n op,\n });\n }\n return opts.headers;\n },\n });\n } catch (cause) {\n cleanup();\n throw cause;\n }\n let isDone = false;\n let meta: HTTPResult['meta'] | undefined = undefined;\n request\n .then((res) => {\n isDone = true;\n meta = res.meta;\n const transformed = transformResult(\n res.json,\n resolvedOpts.transformer.output,\n );\n\n if (!transformed.ok) {\n observer.error(\n TRPCClientError.from(transformed.error, {\n meta,\n }),\n );\n return;\n }\n observer.next({\n context: res.meta,\n result: transformed.result,\n });\n observer.complete();\n })\n .catch((cause) => {\n isDone = true;\n observer.error(TRPCClientError.from(cause, { meta }));\n });\n\n return () => {\n if (!isDone) {\n ac.abort();\n }\n cleanup();\n };\n });\n };\n };\n}\n"],"mappings":";;;;;;;AACA,SAAgB,YACd,OACyC;CACzC,OACE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V,IAAI,OAAO,KAAK,YAAY,YAC1B,OAAO,KAAK,QAAQ,EAClB,GACF,CAAC;OAEH,OAAO,KAAK;MACd;KACF,CAAA,CAAC;IACH,SAAS,OAAO;KACd,QAAQ;KACR,MAAM;IACR;IACA,IAAI,SAAS;IACb,IAAI,OAAuC,KAAA;IAC3C,QACG,MAAM,QAAQ;KACb,SAAS;KACT,OAAO,IAAI;KACX,MAAM,cAAc,gBAClB,IAAI,MACJ,aAAa,YAAY,MAC3B;KAEA,IAAI,CAAC,YAAY,IAAI;MACnB,SAAS,MACP,gBAAgB,KAAK,YAAY,OAAO,EACtC,KACF,CAAC,CACH;MACA;KACF;KACA,SAAS,KAAK;MACZ,SAAS,IAAI;MACb,QAAQ,YAAY;KACtB,CAAC;KACD,SAAS,SAAS;IACpB,CAAC,CAAC,CACD,OAAO,UAAU;KAChB,SAAS;KACT,SAAS,MAAM,gBAAgB,KAAK,OAAO,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;IAEH,aAAa;KACX,IAAI,CAAC,QACH,GAAG,MAAM;KAEX,QAAQ;IACV;GACF,CAAC;EACH;CACF;AACF"}
1
+ {"version":3,"file":"httpLink-Cmg_mV7L.mjs","names":[],"sources":["../src/links/internals/contentTypes.ts","../src/links/httpLink.ts"],"sourcesContent":["/** Whether an input is binary: a `Uint8Array`, `Blob` or `File`. */\nexport function isOctetType(\n input: unknown,\n): input is Uint8Array<ArrayBuffer> | Blob {\n return (\n input instanceof Uint8Array ||\n // File extends from Blob but is only available in nodejs from v20\n input instanceof Blob\n );\n}\n\n/** Whether an input is `FormData`. */\nexport function isFormData(input: unknown) {\n return input instanceof FormData;\n}\n\n/**\n * Whether an input can't be sent as JSON: binary data or `FormData`. Use\n * it in a `splitLink` to send such inputs with `httpLink`.\n * @see https://trpc.io/docs/server/non-json-content-types#client-setup\n */\nexport function isNonJsonSerializable(input: unknown) {\n return isOctetType(input) || isFormData(input);\n}\n","import { observable } from '@trpc/server/observable';\nimport type {\n AnyClientTypes,\n AnyRouter,\n} from '@trpc/server/unstable-core-do-not-import';\nimport { transformResult } from '@trpc/server/unstable-core-do-not-import';\nimport { raceAbortSignalsWithCleanup } from '../internals/signals';\nimport { TRPCClientError } from '../TRPCClientError';\nimport type {\n HTTPLinkBaseOptions,\n HTTPResult,\n Requester,\n} from './internals/httpUtils';\nimport {\n getUrl,\n httpRequest,\n jsonHttpRequester,\n resolveHTTPLinkOptions,\n} from './internals/httpUtils';\nimport {\n isFormData,\n isOctetType,\n type HTTPHeaders,\n type Operation,\n type AugmentedOperationContext,\n type TRPCLink,\n} from './types';\n\n/**\n * The options of `httpLink`.\n * @see https://trpc.io/docs/client/links/httpLink#httplink-options\n */\nexport type HTTPLinkOptions<TRoot extends AnyClientTypes> =\n HTTPLinkBaseOptions<TRoot> & {\n /**\n * Headers for each request: an object, or a function of the operation\n * that returns them.\n * @see https://trpc.io/docs/client/headers\n */\n headers?:\n | HTTPHeaders\n | ((opts: { op: Operation }) => HTTPHeaders | Promise<HTTPHeaders>);\n };\n\nconst universalRequester: Requester = (opts) => {\n if ('input' in opts) {\n const { input } = opts;\n if (isFormData(input)) {\n if (opts.type !== 'mutation' && opts.methodOverride !== 'POST') {\n throw new Error('FormData is only supported for mutations');\n }\n\n return httpRequest({\n ...opts,\n // The browser will set this automatically and include the boundary= in it\n contentTypeHeader: undefined,\n getUrl,\n getBody: () => input,\n });\n }\n\n if (isOctetType(input)) {\n if (opts.type !== 'mutation' && opts.methodOverride !== 'POST') {\n throw new Error('Octet type input is only supported for mutations');\n }\n\n return httpRequest({\n ...opts,\n contentTypeHeader: 'application/octet-stream',\n getUrl,\n getBody: () => input,\n });\n }\n }\n\n return jsonHttpRequester(opts);\n};\n\n/**\n * A terminating link that sends each call in its own HTTP request. It can\n * send `FormData` and binary inputs.\n * @see https://trpc.io/docs/client/links/httpLink\n */\nexport function httpLink<TRouter extends AnyRouter = AnyRouter>(\n opts: HTTPLinkOptions<TRouter['_def']['_config']['$types']>,\n): TRPCLink<\n TRouter,\n // its callbacks may read the fields added to `OperationContext`\n { context: AugmentedOperationContext }\n> {\n const resolvedOpts = resolveHTTPLinkOptions(opts);\n return () => {\n return (operationOpts) => {\n const { op } = operationOpts;\n return observable((observer) => {\n const { path, input, type } = op;\n /* istanbul ignore if -- @preserve */\n if (type === 'subscription') {\n throw new Error(\n 'Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`',\n );\n }\n\n const ac = new AbortController();\n const { signal, cleanup } = raceAbortSignalsWithCleanup(\n op.signal,\n ac.signal,\n );\n let request: Promise<HTTPResult>;\n try {\n request = universalRequester({\n ...resolvedOpts,\n type,\n path,\n input,\n signal,\n headers() {\n if (!opts.headers) {\n return {};\n }\n if (typeof opts.headers === 'function') {\n return opts.headers({\n op,\n });\n }\n return opts.headers;\n },\n });\n } catch (cause) {\n cleanup();\n throw cause;\n }\n let isDone = false;\n let meta: HTTPResult['meta'] | undefined = undefined;\n request\n .then((res) => {\n isDone = true;\n meta = res.meta;\n const transformed = transformResult(\n res.json,\n resolvedOpts.transformer.output,\n );\n\n if (!transformed.ok) {\n observer.error(\n TRPCClientError.from(transformed.error, {\n meta,\n }),\n );\n return;\n }\n observer.next({\n context: res.meta,\n result: transformed.result,\n });\n observer.complete();\n })\n .catch((cause) => {\n isDone = true;\n observer.error(TRPCClientError.from(cause, { meta }));\n });\n\n return () => {\n if (!isDone) {\n ac.abort();\n }\n cleanup();\n };\n });\n };\n };\n}\n"],"mappings":";;;;;;;AACA,SAAgB,YACd,OACyC;CACzC,OACE,iBAAiB,cAEjB,iBAAiB;AAErB;;AAGA,SAAgB,WAAW,OAAgB;CACzC,OAAO,iBAAiB;AAC1B;;;;;;AAOA,SAAgB,sBAAsB,OAAgB;CACpD,OAAO,YAAY,KAAK,KAAK,WAAW,KAAK;AAC/C;;ACqBA,MAAM,sBAAiC,SAAS;CAC9C,IAAI,WAAW,MAAM;EACnB,MAAM,EAAE,UAAU;EAClB,IAAI,WAAW,KAAK,GAAG;G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,aAAa,YAAY,MAC3B;KAEA,IAAI,CAAC,YAAY,IAAI;MACnB,SAAS,MACP,gBAAgB,KAAK,YAAY,OAAO,EACtC,KACF,CAAC,CACH;MACA;KACF;KACA,SAAS,KAAK;MACZ,SAAS,IAAI;MACb,QAAQ,YAAY;KACtB,CAAC;KACD,SAAS,SAAS;IACpB,CAAC,CAAC,CACD,OAAO,UAAU;KAChB,SAAS;KACT,SAAS,MAAM,gBAAgB,KAAK,OAAO,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;IAEH,aAAa;KACX,IAAI,CAAC,QACH,GAAG,MAAM;KAEX,QAAQ;IACV;GACF,CAAC;EACH;CACF;AACF"}
@@ -1,5 +1,5 @@
1
- import { t as HTTPLinkBaseOptions } from "./httpUtils-gZ7bAQ6T.mjs";
2
- import { n as Operation, t as HTTPHeaders, u as TRPCLink } from "./types-BG-3kpeg.mjs";
1
+ import { t as HTTPLinkBaseOptions } from "./httpUtils-BAs5frdP.mjs";
2
+ import { a as Operation, n as HTTPHeaders, p as TRPCLink, t as AugmentedOperationContext } from "./types-DW0iJUBU.mjs";
3
3
  import { AnyClientTypes, AnyRouter } from "@trpc/server/unstable-core-do-not-import";
4
4
  /**
5
5
  * The options of `httpLink`.
@@ -20,6 +20,8 @@ type HTTPLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TRoot>
20
20
  * send `FormData` and binary inputs.
21
21
  * @see https://trpc.io/docs/client/links/httpLink
22
22
  */
23
- declare function httpLink<TRouter extends AnyRouter = AnyRouter>(opts: HTTPLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
23
+ declare function httpLink<TRouter extends AnyRouter = AnyRouter>(opts: HTTPLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter, {
24
+ context: AugmentedOperationContext;
25
+ }>;
24
26
  export { httpLink as n, HTTPLinkOptions as t };
25
- //# sourceMappingURL=httpLink-BjZdBzr6.d.mts.map
27
+ //# sourceMappingURL=httpLink-DN_Ana7a.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpLink-DN_Ana7a.d.mts","names":[],"sources":["../src/links/httpLink.ts"],"mappings":";;;;;;;KAgCY,gBAAgB,cAAc,kBACxC,oBAAoB;;;;;;EAMlB,UACI,gBACE;IAAQ,IAAI;QAAgB,cAAc,QAAQ;;;;;;;iBA0C5C,SAAS,gBAAgB,YAAY,WACnD,MAAM,gBAAgB,wCACrB,SACD;EAEE,SAAS"}
@@ -1,4 +1,4 @@
1
- import { v as FetchEsque } from "./types-BhHxuBsu.cjs";
1
+ import { C as FetchEsque } from "./types-DMe6B4SV.cjs";
2
2
  import { TransformerOptions } from "./unstable-internals.cjs";
3
3
  import { AnyClientTypes, PathSeparator } from "@trpc/server/unstable-core-do-not-import";
4
4
  /**
@@ -27,4 +27,4 @@ type HTTPLinkBaseOptions<TRoot extends Pick<AnyClientTypes, 'transformer'>> = {
27
27
  pathSeparator?: PathSeparator;
28
28
  } & TransformerOptions<TRoot>;
29
29
  export { HTTPLinkBaseOptions as t };
30
- //# sourceMappingURL=httpUtils-CxgZ3W-1.d.cts.map
30
+ //# sourceMappingURL=httpUtils-1z6dzl3V.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"httpUtils-CxgZ3W-1.d.cts","names":[],"sources":["../src/links/internals/httpUtils.ts"],"mappings":";;;;;;;KA4BY,oBACV,cAAc,KAAK;;EAGnB,cAAc;;;;EAId,QAAQ;;;;;;EAMR;;;;;;;EAOA,gBAAgB;IACd,mBAAmB"}
1
+ {"version":3,"file":"httpUtils-1z6dzl3V.d.cts","names":[],"sources":["../src/links/internals/httpUtils.ts"],"mappings":";;;;;;;KA4BY,oBACV,cAAc,KAAK;;EAGnB,cAAc;;;;EAId,QAAQ;;;;;;EAMR;;;;;;;EAOA,gBAAgB;IACd,mBAAmB"}
@@ -1,4 +1,4 @@
1
- import { h as FetchEsque } from "./types-BG-3kpeg.mjs";
1
+ import { b as FetchEsque } from "./types-DW0iJUBU.mjs";
2
2
  import { n as TransformerOptions } from "./unstable-internals-CnrO49lh.mjs";
3
3
  import { AnyClientTypes, PathSeparator } from "@trpc/server/unstable-core-do-not-import";
4
4
  /**
@@ -27,4 +27,4 @@ type HTTPLinkBaseOptions<TRoot extends Pick<AnyClientTypes, 'transformer'>> = {
27
27
  pathSeparator?: PathSeparator;
28
28
  } & TransformerOptions<TRoot>;
29
29
  export { HTTPLinkBaseOptions as t };
30
- //# sourceMappingURL=httpUtils-gZ7bAQ6T.d.mts.map
30
+ //# sourceMappingURL=httpUtils-BAs5frdP.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"httpUtils-gZ7bAQ6T.d.mts","names":[],"sources":["../src/links/internals/httpUtils.ts"],"mappings":";;;;;;;KA4BY,oBACV,cAAc,KAAK;;EAGnB,cAAc;;;;EAId,QAAQ;;;;;;EAMR;;;;;;;EAOA,gBAAgB;IACd,mBAAmB"}
1
+ {"version":3,"file":"httpUtils-BAs5frdP.d.mts","names":[],"sources":["../src/links/internals/httpUtils.ts"],"mappings":";;;;;;;KA4BY,oBACV,cAAc,KAAK;;EAGnB,cAAc;;;;EAId,QAAQ;;;;;;EAMR;;;;;;;EAOA,gBAAgB;IACd,mBAAmB"}
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_splitLink = require("./splitLink-BBLj14Dv.cjs");
2
+ const require_splitLink = require("./splitLink-BQoYcpdp.cjs");
3
3
  const require_TRPCClientError = require("./TRPCClientError-irOPxS6c.cjs");
4
4
  const require_objectSpread2 = require("./objectSpread2-Xm0br5eL.cjs");
5
5
  const require_httpUtils = require("./httpUtils-coYP4VfN.cjs");
@@ -169,20 +169,8 @@ function createTRPCClientProxy(client) {
169
169
  return proxy[key];
170
170
  });
171
171
  }
172
- /**
173
- * Creates a typed client for a router. Pass the router's type, and the
174
- * links that send its calls.
175
- * @example
176
- * ```ts
177
- * const client = createTRPCClient<AppRouter>({
178
- * links: [httpBatchLink({ url: 'http://localhost:3000/trpc' })],
179
- * });
180
- * const post = await client.post.byId.query({ id: '1' });
181
- * ```
182
- * @see https://trpc.io/docs/client/vanilla/setup#3-initialize-the-trpc-client
183
- */
184
172
  function createTRPCClient(opts) {
185
- return createTRPCClientProxy(new TRPCUntypedClient(opts));
173
+ return createTRPCClientProxy(new TRPCUntypedClient({ links: [...opts.links] }));
186
174
  }
187
175
  /**
188
176
  * The untyped client behind a typed client, which calls procedures by
@@ -192,6 +180,25 @@ function createTRPCClient(opts) {
192
180
  function getUntypedClient(client) {
193
181
  return client[untypedClientSymbol];
194
182
  }
183
+ // src/routerType.ts
184
+ /**
185
+ * Passes a router's type to `createTRPCClient({ router })` as a normal
186
+ * option, instead of a type argument. Nothing about the router exists at
187
+ * runtime, so it's safe to import the router's type only.
188
+ *
189
+ * @example
190
+ * ```ts
191
+ * const client = createTRPCClient({
192
+ * router: routerType<AppRouter>(),
193
+ * links: [httpBatchLink({ url: 'http://localhost:3000/trpc' })],
194
+ * });
195
+ * ```
196
+ * @see https://trpc.io/docs/client/vanilla/setup#3-initialize-the-trpc-client
197
+ * @public
198
+ */
199
+ function routerType() {
200
+ return {};
201
+ }
195
202
  // src/links/httpBatchStreamLink.ts
196
203
  /**
197
204
  * A terminating link that batches calls like `httpBatchLink`, but streams each
@@ -952,6 +959,7 @@ exports.jsonEncoder = require_wsLink.jsonEncoder;
952
959
  exports.localLink = localLink;
953
960
  exports.loggerLink = require_links_loggerLink.loggerLink;
954
961
  exports.retryLink = retryLink;
962
+ exports.routerType = routerType;
955
963
  exports.safe = safe;
956
964
  exports.splitLink = require_splitLink.splitLink;
957
965
  exports.unstable_httpBatchStreamLink = unstable_httpBatchStreamLink;
package/dist/index.d.cts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { t as TRPCConnectionState } from "./subscriptions-CvJnusYO.cjs";
2
- import { _ as isTRPCClientError, a as OperationResultEnvelope, c as TRPCClientRuntime, d as isFormData, f as isNonJsonSerializable, g as TRPCClientErrorLike, h as TRPCClientErrorBase, i as OperationLink, l as TRPCFetch, m as TRPCClientError, n as Operation, o as OperationResultObservable, p as isOctetType, r as OperationContext, s as OperationResultObserver, t as HTTPHeaders, u as TRPCLink, v as FetchEsque, x as TRPCProcedureOptions, y as NativeFetchEsque } from "./types-BhHxuBsu.cjs";
3
- import { n as HTTPBatchLinkOptions, t as httpBatchLink } from "./httpBatchLink-DbD4ZGAM.cjs";
2
+ import { C as FetchEsque, E as TRPCProcedureOptions, S as isTRPCClientError, _ as isNonJsonSerializable, a as Operation, b as TRPCClientErrorBase, c as OperationResultEnvelope, d as TRPCClientRuntime, f as TRPCFetch, g as isFormData, h as inferLinksDeclaredContext, i as NoLinkReadsContext, l as OperationResultObservable, m as inferLinksContext, n as HTTPHeaders, o as OperationContext, p as TRPCLink, r as LinkDecl, s as OperationLink, t as AugmentedOperationContext, u as OperationResultObserver, v as isOctetType, w as NativeFetchEsque, x as TRPCClientErrorLike, y as TRPCClientError } from "./types-DMe6B4SV.cjs";
3
+ import { n as HTTPBatchLinkOptions, t as httpBatchLink } from "./httpBatchLink-_bkMj4mk.cjs";
4
4
  import { HTTPLinkOptions, httpLink } from "./links/httpLink.cjs";
5
5
  import { LoggerLinkOptions, loggerLink } from "./links/loggerLink.cjs";
6
6
  import { splitLink } from "./links/splitLink.cjs";
7
- import { a as WebSocketClientOptions, c as jsonEncoder, i as createWSClient, n as wsLink, o as UrlOptionsWithConnectionParams, r as TRPCWebSocketClient, s as Encoder, t as WebSocketLinkOptions } from "./wsLink-BlAMQb0i.cjs";
7
+ import { a as WebSocketClientOptions, c as jsonEncoder, i as createWSClient, n as wsLink, o as UrlOptionsWithConnectionParams, r as TRPCWebSocketClient, s as Encoder, t as WebSocketLinkOptions } from "./wsLink-DuyXOEPt.cjs";
8
8
  import { TransformerOptions } from "./unstable-internals.cjs";
9
- import { t as HTTPLinkBaseOptions } from "./httpUtils-CxgZ3W-1.cjs";
9
+ import { t as HTTPLinkBaseOptions } from "./httpUtils-1z6dzl3V.cjs";
10
10
  import { AnyClientTypes, AnyProcedure, AnyRouter, ErrorHandlerOptions, EventSourceLike, InferrableClientTypes, ProcedureType, RouterRecord, TypeError, inferAsyncIterableYield, inferClientTypes, inferProcedureErrorShape, inferProcedureInput, inferRouterContext, inferTransformedProcedureOutput } from "@trpc/server/unstable-core-do-not-import";
11
11
  import { Unsubscribable } from "@trpc/server/observable";
12
12
  import { AnyRouter as AnyRouter$1 } from "@trpc/server";
@@ -97,6 +97,31 @@ export declare class TRPCUntypedClient<TInferrable extends InferrableClientTypes
97
97
  * Meant for libraries built on tRPC; apps should use `createTRPCClient`.
98
98
  */
99
99
  export declare function createTRPCUntypedClient<TRouter extends AnyRouter>(opts: CreateTRPCClientOptions<TRouter>): TRPCUntypedClient<TRouter>;
100
+ declare const routerTypeBrand: unique symbol;
101
+ /**
102
+ * A value that carries a router's type and nothing else. Made by
103
+ * {@link routerType}.
104
+ * @public
105
+ */
106
+ export interface RouterType<TRouter extends AnyRouter> {
107
+ readonly [routerTypeBrand]: TRouter;
108
+ }
109
+ /**
110
+ * Passes a router's type to `createTRPCClient({ router })` as a normal
111
+ * option, instead of a type argument. Nothing about the router exists at
112
+ * runtime, so it's safe to import the router's type only.
113
+ *
114
+ * @example
115
+ * ```ts
116
+ * const client = createTRPCClient({
117
+ * router: routerType<AppRouter>(),
118
+ * links: [httpBatchLink({ url: 'http://localhost:3000/trpc' })],
119
+ * });
120
+ * ```
121
+ * @see https://trpc.io/docs/client/vanilla/setup#3-initialize-the-trpc-client
122
+ * @public
123
+ */
124
+ export declare function routerType<TRouter extends AnyRouter>(): RouterType<TRouter>;
100
125
  /**
101
126
  * @internal
102
127
  */
@@ -152,13 +177,16 @@ declare const untypedClientSymbol: unique symbol;
152
177
  /**
153
178
  * A typed client for a router, as `createTRPCClient` returns it. Each
154
179
  * procedure has `.query()`, `.mutate()` or `.subscribe()`.
180
+ *
181
+ * `TContext` is the `context` calls take; `createTRPCClient({ router,
182
+ * links })` infers it from the links.
155
183
  * @see https://trpc.io/docs/client/vanilla/infer-types
156
184
  * @public
157
185
  **/
158
- export type TRPCClient<TRouter extends AnyRouter> = DecoratedProcedureRecord<{
186
+ export type TRPCClient<TRouter extends AnyRouter, TContext extends object = Record<string, unknown>> = DecoratedProcedureRecord<{
159
187
  transformer: TRouter['_def']['_config']['$types']['transformer'];
160
188
  errorShape: TRouter['_def']['_config']['$types']['errorShape'];
161
- }, TRouter['_def']['record']> & {
189
+ }, TRouter['_def']['record'], TContext> & {
162
190
  [untypedClientSymbol]: TRPCUntypedClient<TRouter>;
163
191
  };
164
192
  /**
@@ -176,31 +204,31 @@ type coerceAsyncGeneratorToIterable<T> = T extends AsyncGenerator<infer $T, infe
176
204
  * The `.query()` or `.mutate()` of a procedure on the client.
177
205
  * @internal
178
206
  */
179
- export type Resolver<TDef extends TRPCResolverDef> = (input: TDef['input'], opts?: TRPCProcedureOptions) => TRPCTaggedPromise<coerceAsyncGeneratorToIterable<TDef['output']>, TDef['errorShape']>;
207
+ export type Resolver<TDef extends TRPCResolverDef, TContext extends object = Record<string, unknown>> = (input: TDef['input'], opts?: TRPCProcedureOptions<TContext>) => TRPCTaggedPromise<coerceAsyncGeneratorToIterable<TDef['output']>, TDef['errorShape']>;
180
208
  /**
181
209
  * The `.subscribe()` of a subscription procedure on the client.
182
210
  * @internal
183
211
  */
184
- export type SubscriptionResolver<TDef extends TRPCResolverDef> = {
185
- (input: TDef['input'], opts: TRPCSubscriptionCallbacks<TDef['output'], TRPCClientError<TDef>> & TRPCProcedureOptions): Unsubscribable;
186
- <TOpts extends TRPCProcedureOptions & Partial<TRPCSubscriptionObserver<TDef['output'], TRPCClientError<TDef>>> = TRPCProcedureOptions>(input: TDef['input'], opts?: TRPCSubscriptionWithoutCallbacks<TOpts>): AsyncIterableIterator<inferAsyncIterableYield<TDef['output']>>;
212
+ export type SubscriptionResolver<TDef extends TRPCResolverDef, TContext extends object = Record<string, unknown>> = {
213
+ (input: TDef['input'], opts: TRPCSubscriptionCallbacks<TDef['output'], TRPCClientError<TDef>> & TRPCProcedureOptions<TContext>): Unsubscribable;
214
+ <TOpts extends TRPCProcedureOptions<TContext> & Partial<TRPCSubscriptionObserver<TDef['output'], TRPCClientError<TDef>>> = TRPCProcedureOptions<TContext>>(input: TDef['input'], opts?: TRPCSubscriptionWithoutCallbacks<TOpts>): AsyncIterableIterator<inferAsyncIterableYield<TDef['output']>>;
187
215
  };
188
- type DecorateProcedure<TType extends ProcedureType, TDef extends TRPCResolverDef> = TType extends 'query' ? {
189
- query: Resolver<TDef>;
216
+ type DecorateProcedure<TType extends ProcedureType, TDef extends TRPCResolverDef, TContext extends object> = TType extends 'query' ? {
217
+ query: Resolver<TDef, TContext>;
190
218
  } : TType extends 'mutation' ? {
191
- mutate: Resolver<TDef>;
219
+ mutate: Resolver<TDef, TContext>;
192
220
  } : TType extends 'subscription' ? {
193
- subscribe: SubscriptionResolver<TDef>;
221
+ subscribe: SubscriptionResolver<TDef, TContext>;
194
222
  } : never;
195
223
  /**
196
224
  * @internal
197
225
  */
198
- type DecoratedProcedureRecord<TRoot extends InferrableClientTypes, TRecord extends RouterRecord> = { [TKey in keyof TRecord]: TRecord[TKey] extends (infer $Value) ? $Value extends AnyProcedure ? DecorateProcedure<$Value['_def']['type'], {
226
+ type DecoratedProcedureRecord<TRoot extends InferrableClientTypes, TRecord extends RouterRecord, TContext extends object> = { [TKey in keyof TRecord]: TRecord[TKey] extends (infer $Value) ? $Value extends AnyProcedure ? DecorateProcedure<$Value['_def']['type'], {
199
227
  input: inferProcedureInput<$Value>;
200
228
  output: inferTransformedProcedureOutput<inferClientTypes<TRoot>, $Value>;
201
229
  errorShape: inferProcedureErrorShape<TRoot, $Value>;
202
230
  transformer: inferClientTypes<TRoot>['transformer'];
203
- }> : $Value extends RouterRecord ? DecoratedProcedureRecord<TRoot, $Value> : never : never; };
231
+ }, TContext> : $Value extends RouterRecord ? DecoratedProcedureRecord<TRoot, $Value, TContext> : never : never; };
204
232
  /**
205
233
  * The procedure type of a client method: `query`, `mutate` or `subscribe`.
206
234
  * @internal
@@ -211,6 +239,42 @@ export declare const clientCallTypeToProcedureType: (clientCallType: string) =>
211
239
  * @internal
212
240
  */
213
241
  export declare function createTRPCClientProxy<TRouter extends AnyRouter>(client: TRPCUntypedClient<TRouter>): TRPCClient<TRouter>;
242
+ /**
243
+ * The options of `createTRPCClient` with the router's type passed as
244
+ * `router: routerType<AppRouter>()`.
245
+ * @public
246
+ */
247
+ export type CreateTRPCClientWithRouterOptions<TRouter extends AnyRouter, TLinks extends readonly TRPCLink<TRouter, any>[] = TRPCLink<TRouter>[]> = Omit<CreateTRPCClientOptions<TRouter>, 'links'> & {
248
+ /**
249
+ * The router's type, from `routerType<AppRouter>()`. It's a type only:
250
+ * nothing about the router is sent or bundled.
251
+ */
252
+ router: RouterType<TRouter>;
253
+ /**
254
+ * The links each call goes through, in order. The last one must send
255
+ * the call, such as `httpBatchLink`. What they declare types each call's
256
+ * `context`, and which methods the client has. Pass them inline or
257
+ * `as const`: in an array declared without it, TypeScript can merge the
258
+ * links' types and drop what one declares.
259
+ * @see https://trpc.io/docs/client/links
260
+ */
261
+ links: TLinks;
262
+ };
263
+ /**
264
+ * Creates a typed client for a router. Pass the router's type with
265
+ * `routerType`, and the links that send its calls. What the links declare
266
+ * types each call's `context`.
267
+ * @example
268
+ * ```ts
269
+ * const client = createTRPCClient({
270
+ * router: routerType<AppRouter>(),
271
+ * links: [httpBatchLink({ url: 'http://localhost:3000/trpc' })],
272
+ * });
273
+ * const post = await client.post.byId.query({ id: '1' });
274
+ * ```
275
+ * @see https://trpc.io/docs/client/vanilla/setup#3-initialize-the-trpc-client
276
+ */
277
+ export declare function createTRPCClient<TRouter extends AnyRouter, const TLinks extends readonly TRPCLink<TRouter, any>[] = TRPCLink<TRouter>[]>(opts: CreateTRPCClientWithRouterOptions<TRouter, TLinks>): TRPCClient<TRouter, inferLinksContext<TLinks>>;
214
278
  /**
215
279
  * Creates a typed client for a router. Pass the router's type, and the
216
280
  * links that send its calls.
@@ -256,7 +320,9 @@ export type HTTPBatchStreamLinkOptions<TRoot extends AnyClientTypes> = HTTPBatch
256
320
  *
257
321
  * @see https://trpc.io/docs/client/links/httpBatchStreamLink
258
322
  */
259
- export declare function httpBatchStreamLink<TRouter extends AnyRouter$1>(opts: HTTPBatchStreamLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
323
+ export declare function httpBatchStreamLink<TRouter extends AnyRouter$1>(opts: HTTPBatchStreamLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter, {
324
+ context: AugmentedOperationContext;
325
+ }>;
260
326
  /**
261
327
  * @deprecated Use {@link httpBatchStreamLink} instead.
262
328
  */
@@ -283,7 +349,9 @@ type HTTPSubscriptionLinkOptions<TRoot extends AnyClientTypes, TEventSource exte
283
349
  *
284
350
  * @see https://trpc.io/docs/client/links/httpSubscriptionLink
285
351
  */
286
- export declare function httpSubscriptionLink<TInferrable extends InferrableClientTypes, TEventSource extends EventSourceLike.AnyConstructor>(opts: HTTPSubscriptionLinkOptions<inferClientTypes<TInferrable>, TEventSource>): TRPCLink<TInferrable>;
352
+ export declare function httpSubscriptionLink<TInferrable extends InferrableClientTypes, TEventSource extends EventSourceLike.AnyConstructor>(opts: HTTPSubscriptionLinkOptions<inferClientTypes<TInferrable>, TEventSource>): TRPCLink<TInferrable, {
353
+ context: AugmentedOperationContext;
354
+ }>;
287
355
  /**
288
356
  * @deprecated Use {@link httpSubscriptionLink} instead.
289
357
  */
@@ -318,7 +386,9 @@ interface RetryFnOptions<TInferrable extends InferrableClientTypes> {
318
386
  *
319
387
  * @see https://trpc.io/docs/client/links/retryLink
320
388
  */
321
- export declare function retryLink<TInferrable extends InferrableClientTypes>(opts: RetryLinkOptions<TInferrable>): TRPCLink<TInferrable>;
389
+ export declare function retryLink<TInferrable extends InferrableClientTypes>(opts: RetryLinkOptions<TInferrable>): TRPCLink<TInferrable, {
390
+ context: AugmentedOperationContext;
391
+ }>;
322
392
  /**
323
393
  * Passed to {@link LocalLinkOptions.createContext}.
324
394
  */
@@ -364,7 +434,9 @@ export type LocalLinkOptions<TRouter extends AnyRouter> = {
364
434
  *
365
435
  * @see https://trpc.io/docs/client/links/localLink
366
436
  */
367
- export declare function localLink<TRouter extends AnyRouter>(opts: LocalLinkOptions<TRouter>): TRPCLink<TRouter>;
437
+ export declare function localLink<TRouter extends AnyRouter>(opts: LocalLinkOptions<TRouter>): TRPCLink<TRouter, {
438
+ context: {};
439
+ }>;
368
440
  /**
369
441
  * @deprecated Use {@link localLink} instead.
370
442
  * @function
@@ -375,5 +447,5 @@ export declare const unstable_localLink: typeof localLink;
375
447
  * future major release.
376
448
  */
377
449
  export declare const experimental_localLink: typeof localLink;
378
- export { type CreateTRPCClientOptions, type Encoder, HTTPBatchLinkOptions, HTTPHeaders, HTTPLinkOptions, LoggerLinkOptions, Operation, OperationContext, OperationLink, OperationResultEnvelope, OperationResultObservable, OperationResultObserver, type SafeResult, TRPCClientError, TRPCClientErrorBase, TRPCClientErrorLike, TRPCClientRuntime, TRPCFetch, TRPCLink, type TRPCProcedureOptions, type TRPCTaggedPromise as TRPCPromise, type TRPCRequestOptions, type TRPCWebSocketClient, type WebSocketClientOptions, WebSocketLinkOptions, createTRPCClient as createTRPCProxyClient, createWSClient, httpBatchLink, httpLink, type inferRouterClient as inferRouterProxyClient, isFormData, isNonJsonSerializable, isOctetType, isTRPCClientError, jsonEncoder, loggerLink, splitLink, wsLink };
450
+ export { AugmentedOperationContext, type CreateTRPCClientOptions, type Encoder, HTTPBatchLinkOptions, HTTPHeaders, HTTPLinkOptions, LinkDecl, LoggerLinkOptions, NoLinkReadsContext, Operation, OperationContext, OperationLink, OperationResultEnvelope, OperationResultObservable, OperationResultObserver, type SafeResult, TRPCClientError, TRPCClientErrorBase, TRPCClientErrorLike, TRPCClientRuntime, TRPCFetch, TRPCLink, type TRPCProcedureOptions, type TRPCTaggedPromise as TRPCPromise, type TRPCRequestOptions, type TRPCWebSocketClient, type WebSocketClientOptions, WebSocketLinkOptions, createTRPCClient as createTRPCProxyClient, createWSClient, httpBatchLink, httpLink, inferLinksContext, inferLinksDeclaredContext, type inferRouterClient as inferRouterProxyClient, isFormData, isNonJsonSerializable, isOctetType, isTRPCClientError, jsonEncoder, loggerLink, splitLink, wsLink };
379
451
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":["AnyRouter"],"sources":["../src/internals/TRPCUntypedClient.ts","../src/createTRPCUntypedClient.ts","../src/safe.ts","../src/createTRPCClient.ts","../src/getFetch.ts","../src/links/httpBatchStreamLink.ts","../src/links/httpSubscriptionLink.ts","../src/links/retryLink.ts","../src/links/localLink.ts"],"mappings":";;;;;;;;;;;;;UA6BiB;;;;;EAKf,UAAU;;;;;EAKV,SAAS;;;UAIM,yBAAyB,QAAQ;;EAEhD,YAAY;IAAQ,SAAS;;;EAE7B,SAAS,OAAO,wBAAwB;;EAExC,UAAU,KAAK;;;;;EAKf;;EAEA;;EAEA,0BAA0B,OAAO,oBAAoB;;KAGlD,oBAAoB;;;;;;KAOb,iCAAiC,SAAS,WAEnD,QAAQ,6BAER,cAAc,QAAQ;;;;;KAOb,0BAA0B,QAAQ,UAAU,QACtD,yBAAyB,QAAQ,cAG9B,QAAQ,cAAc,KAAK,yBAAyB,QAAQ,SAAS,SACtE;;;;;KAeQ,wBAAwB,gBAAgB;;;;;;EAMlD,OAAO,SAAS;EAChB,cAAc;;;;;;qBAOH,kBAAkB,oBAAoB;mBAChC;WACD,SAAS;UACjB;EAER,YAAY,MAAM,wBAAwB;UASlC;UAkBM;;EAmBP,MAAM,cAAc,iBAAiB,OAAO,qBAAkB;;EAU9D,SAAS,cAAc,iBAAiB,OAAO,qBAAkB;;;;;;;EAejE,aACL,cACA,gBACA,MAAM,mCAAmC,gBAAgB,cACvD,qBACD;EACI,aACL,cAAc,qBACZ,QAAQ,kCAAkC,gBAAgB,eA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B,UAAU,gBAAgB,WACxC,MAAM,iBAAiB,WACtB,SAAS;;;;;qBAqQC,2BAAkB;;;;;qBAMlB,+BAAsB"}
1
+ {"version":3,"file":"index.d.cts","names":["AnyRouter"],"sources":["../src/internals/TRPCUntypedClient.ts","../src/createTRPCUntypedClient.ts","../src/routerType.ts","../src/safe.ts","../src/createTRPCClient.ts","../src/getFetch.ts","../src/links/httpBatchStreamLink.ts","../src/links/httpSubscriptionLink.ts","../src/links/retryLink.ts","../src/links/localLink.ts"],"mappings":";;;;;;;;;;;;;UA6BiB;;;;;EAKf,UAAU;;;;;EAKV,SAAS;;;UAIM,yBAAyB,QAAQ;;EAEhD,YAAY;IAAQ,SAAS;;;EAE7B,SAAS,OAAO,wBAAwB;;EAExC,UAAU,KAAK;;;;;EAKf;;EAEA;;EAEA,0BAA0B,OAAO,oBAAoB;;KAGlD,oBAAoB;;;;;;KAOb,iCAAiC,SAAS,WAEnD,QAAQ,6BAER,cAAc,QAAQ;;;;;KAOb,0BAA0B,QAAQ,UAAU,QACtD,yBAAyB,QAAQ,cAG9B,QAAQ,cAAc,KAAK,yBAAyB,QAAQ,SAAS,SACtE;;;;;KAeQ,wBAAwB,gBAAgB;;;;;;EAMlD,OAAO,SAAS;EAChB,cAAc;;;;;;qBAOH,kBAAkB,oBAAoB;mBAChC;WACD,SAAS;UACjB;EAER,YAAY,MAAM,wBAAwB;UASlC;UAkBM;;EAmBP,MAAM,cAAc,iBAAiB,OAAO,qBAAkB;;EAU9D,SAAS,cAAc,iBAAiB,OAAO,qBAAkB;;;;;;;EAejE,aACL,cACA,gBACA,MAAM,mCAAmC,gBAAgB,cACvD,qBACD;EACI,aACL,cAAc,qBACZ,QAAQ,kCAAkC,gBAAgB,eAC1D,oBAEF,cACA,gBACA,OAAO,iCAAiC,SACvC;;;;;;wBCnMW,wBAAwB,gBAAgB,WACtD,MAAM,wBAAwB,WAC7B,kBAAkB;cCRP;;;;;;iBAOG,WAAW,gBAAgB;YAChC,kBAAkB;;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