@trpc/client 11.1.3-alpha-tmp-tsdown.23 → 11.1.3-alpha-tmp-tsdown.26

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 (276) hide show
  1. package/dist/{TRPCClientError.js → TRPCClientError-CGgRtttT.cjs} +14 -4
  2. package/dist/{TRPCClientError.mjs → TRPCClientError-COkhCKf3.mjs} +1 -1
  3. package/dist/TRPCClientError-COkhCKf3.mjs.map +1 -0
  4. package/dist/httpBatchLink-CIC9PZ_Z.cjs +267 -0
  5. package/dist/httpBatchLink-DIfnmmcu.mjs +238 -0
  6. package/dist/httpBatchLink-DIfnmmcu.mjs.map +1 -0
  7. package/dist/{links/HTTPBatchLinkOptions.d.mts → httpBatchLink.d-BN2Iw_cK.d.mts} +14 -6
  8. package/dist/httpBatchLink.d-BN2Iw_cK.d.mts.map +1 -0
  9. package/dist/{links/HTTPBatchLinkOptions.d.ts → httpBatchLink.d-CLAuJKNV.d.cts} +14 -6
  10. package/dist/httpBatchLink.d-CLAuJKNV.d.cts.map +1 -0
  11. package/dist/httpLink-9bpwQ15c.mjs +90 -0
  12. package/dist/httpLink-9bpwQ15c.mjs.map +1 -0
  13. package/dist/httpLink-BbVj_TgM.cjs +113 -0
  14. package/dist/{links/httpLink.d.ts → httpLink.d-CTSOARfE.d.mts} +4 -5
  15. package/dist/httpLink.d-CTSOARfE.d.mts.map +1 -0
  16. package/dist/httpLink.d-yMKfOlTU.d.cts +23 -0
  17. package/dist/httpLink.d-yMKfOlTU.d.cts.map +1 -0
  18. package/dist/{links/internals/httpUtils.mjs → httpUtils-3pbQzhUL.mjs} +13 -4
  19. package/dist/httpUtils-3pbQzhUL.mjs.map +1 -0
  20. package/dist/{links/internals/httpUtils.js → httpUtils-Buf6jCgh.cjs} +55 -10
  21. package/dist/{links/internals/httpUtils.d.ts → httpUtils.d-C8wPxU79.d.mts} +6 -7
  22. package/dist/httpUtils.d-C8wPxU79.d.mts.map +1 -0
  23. package/dist/{links/internals/httpUtils.d.mts → httpUtils.d-DNRVGNHs.d.cts} +6 -7
  24. package/dist/httpUtils.d-DNRVGNHs.d.cts.map +1 -0
  25. package/dist/index.cjs +731 -0
  26. package/dist/index.d.cts +197 -0
  27. package/dist/index.d.cts.map +1 -0
  28. package/dist/index.d.mts +197 -21
  29. package/dist/index.d.mts.map +1 -0
  30. package/dist/index.mjs +733 -18
  31. package/dist/index.mjs.map +1 -0
  32. package/dist/links/httpBatchLink.cjs +6 -0
  33. package/dist/links/httpBatchLink.d.cts +6 -0
  34. package/dist/links/httpBatchLink.d.mts +6 -18
  35. package/dist/links/httpBatchLink.mjs +5 -93
  36. package/dist/links/httpLink.cjs +6 -0
  37. package/dist/links/httpLink.d.cts +6 -0
  38. package/dist/links/httpLink.d.mts +6 -24
  39. package/dist/links/httpLink.mjs +5 -78
  40. package/dist/links/loggerLink.cjs +3 -0
  41. package/dist/links/loggerLink.d.cts +4 -0
  42. package/dist/links/loggerLink.d.mts +4 -56
  43. package/dist/links/loggerLink.mjs +2 -124
  44. package/dist/links/splitLink.cjs +3 -0
  45. package/dist/links/splitLink.d.cts +4 -0
  46. package/dist/links/splitLink.d.mts +4 -21
  47. package/dist/links/splitLink.mjs +2 -25
  48. package/dist/links/wsLink/wsLink.cjs +6 -0
  49. package/dist/links/wsLink/wsLink.d.cts +5 -0
  50. package/dist/links/wsLink/wsLink.d.mts +5 -15
  51. package/dist/links/wsLink/wsLink.mjs +4 -32
  52. package/dist/{links/loggerLink.js → loggerLink-CsDfg5Bb.cjs} +8 -3
  53. package/dist/loggerLink-PGBSQFcR.mjs +125 -0
  54. package/dist/loggerLink-PGBSQFcR.mjs.map +1 -0
  55. package/dist/{links/loggerLink.d.ts → loggerLink.d-CZjK1CXm.d.mts} +2 -4
  56. package/dist/loggerLink.d-CZjK1CXm.d.mts.map +1 -0
  57. package/dist/loggerLink.d-DU855urG.d.cts +54 -0
  58. package/dist/loggerLink.d-DU855urG.d.cts.map +1 -0
  59. package/dist/splitLink-BMgxggng.cjs +58 -0
  60. package/dist/{links/internals/createChain.mjs → splitLink-BVblHq4n.mjs} +23 -2
  61. package/dist/splitLink-BVblHq4n.mjs.map +1 -0
  62. package/dist/{links/splitLink.d.ts → splitLink.d-BAqgq0NG.d.mts} +3 -4
  63. package/dist/splitLink.d-BAqgq0NG.d.mts.map +1 -0
  64. package/dist/splitLink.d-GdevSkGW.d.cts +20 -0
  65. package/dist/splitLink.d-GdevSkGW.d.cts.map +1 -0
  66. package/dist/{links/internals/subscriptions.d.mts → subscriptions.d-Ciljg_dH.d.cts} +1 -2
  67. package/dist/subscriptions.d-Ciljg_dH.d.cts.map +1 -0
  68. package/dist/{links/internals/subscriptions.d.ts → subscriptions.d-U92STdZl.d.mts} +1 -2
  69. package/dist/subscriptions.d-U92STdZl.d.mts.map +1 -0
  70. package/dist/types.d-DXbqQLCC.d.mts +182 -0
  71. package/dist/types.d-DXbqQLCC.d.mts.map +1 -0
  72. package/dist/types.d-DqGYG6S_.d.cts +182 -0
  73. package/dist/types.d-DqGYG6S_.d.cts.map +1 -0
  74. package/dist/{internals/transformer.js → unstable-internals-CYBH4jbF.cjs} +6 -1
  75. package/dist/{internals/transformer.mjs → unstable-internals-DU4WecoG.mjs} +1 -1
  76. package/dist/unstable-internals-DU4WecoG.mjs.map +1 -0
  77. package/dist/unstable-internals.cjs +3 -0
  78. package/dist/{internals/transformer.d.ts → unstable-internals.d-DyLd-B0J.d.mts} +4 -5
  79. package/dist/unstable-internals.d-DyLd-B0J.d.mts.map +1 -0
  80. package/dist/{internals/transformer.d.mts → unstable-internals.d-kWsZTlQq.d.cts} +5 -6
  81. package/dist/unstable-internals.d-kWsZTlQq.d.cts.map +1 -0
  82. package/dist/unstable-internals.d.cts +3 -0
  83. package/dist/unstable-internals.d.mts +2 -2
  84. package/dist/unstable-internals.mjs +1 -1
  85. package/dist/wsLink-DbSHOzlB.mjs +698 -0
  86. package/dist/wsLink-DbSHOzlB.mjs.map +1 -0
  87. package/dist/wsLink-DhJ50EC5.cjs +715 -0
  88. package/dist/wsLink.d-BqO7ltN_.d.mts +194 -0
  89. package/dist/wsLink.d-BqO7ltN_.d.mts.map +1 -0
  90. package/dist/wsLink.d-DtZjg09g.d.cts +194 -0
  91. package/dist/wsLink.d-DtZjg09g.d.cts.map +1 -0
  92. package/links/httpBatchLink/package.json +1 -1
  93. package/links/httpLink/package.json +1 -1
  94. package/links/loggerLink/package.json +1 -1
  95. package/links/splitLink/package.json +1 -1
  96. package/links/wsLink/wsLink/package.json +1 -1
  97. package/package.json +23 -24
  98. package/unstable-internals/package.json +1 -1
  99. package/dist/TRPCClientError.d.mts +0 -33
  100. package/dist/TRPCClientError.d.mts.map +0 -1
  101. package/dist/TRPCClientError.d.ts +0 -33
  102. package/dist/TRPCClientError.d.ts.map +0 -1
  103. package/dist/TRPCClientError.mjs.map +0 -1
  104. package/dist/_virtual/rolldown_runtime.mjs +0 -27
  105. package/dist/createTRPCClient.d.mts +0 -73
  106. package/dist/createTRPCClient.d.mts.map +0 -1
  107. package/dist/createTRPCClient.d.ts +0 -73
  108. package/dist/createTRPCClient.d.ts.map +0 -1
  109. package/dist/createTRPCClient.js +0 -48
  110. package/dist/createTRPCClient.mjs +0 -45
  111. package/dist/createTRPCClient.mjs.map +0 -1
  112. package/dist/createTRPCUntypedClient.d.mts +0 -9
  113. package/dist/createTRPCUntypedClient.d.mts.map +0 -1
  114. package/dist/createTRPCUntypedClient.d.ts +0 -9
  115. package/dist/createTRPCUntypedClient.d.ts.map +0 -1
  116. package/dist/createTRPCUntypedClient.js +0 -9
  117. package/dist/createTRPCUntypedClient.mjs +0 -10
  118. package/dist/createTRPCUntypedClient.mjs.map +0 -1
  119. package/dist/getFetch.d.mts +0 -10
  120. package/dist/getFetch.d.mts.map +0 -1
  121. package/dist/getFetch.d.ts +0 -10
  122. package/dist/getFetch.d.ts.map +0 -1
  123. package/dist/getFetch.js +0 -12
  124. package/dist/getFetch.mjs +0 -12
  125. package/dist/getFetch.mjs.map +0 -1
  126. package/dist/index.d.ts +0 -21
  127. package/dist/index.js +0 -42
  128. package/dist/internals/TRPCUntypedClient.d.mts +0 -46
  129. package/dist/internals/TRPCUntypedClient.d.mts.map +0 -1
  130. package/dist/internals/TRPCUntypedClient.d.ts +0 -46
  131. package/dist/internals/TRPCUntypedClient.d.ts.map +0 -1
  132. package/dist/internals/TRPCUntypedClient.js +0 -96
  133. package/dist/internals/TRPCUntypedClient.mjs +0 -96
  134. package/dist/internals/TRPCUntypedClient.mjs.map +0 -1
  135. package/dist/internals/dataLoader.js +0 -106
  136. package/dist/internals/dataLoader.mjs +0 -106
  137. package/dist/internals/dataLoader.mjs.map +0 -1
  138. package/dist/internals/inputWithTrackedEventId.js +0 -13
  139. package/dist/internals/inputWithTrackedEventId.mjs +0 -13
  140. package/dist/internals/inputWithTrackedEventId.mjs.map +0 -1
  141. package/dist/internals/signals.js +0 -46
  142. package/dist/internals/signals.mjs +0 -44
  143. package/dist/internals/signals.mjs.map +0 -1
  144. package/dist/internals/transformer.d.mts.map +0 -1
  145. package/dist/internals/transformer.d.ts.map +0 -1
  146. package/dist/internals/transformer.mjs.map +0 -1
  147. package/dist/internals/types.d.mts +0 -85
  148. package/dist/internals/types.d.mts.map +0 -1
  149. package/dist/internals/types.d.ts +0 -85
  150. package/dist/internals/types.d.ts.map +0 -1
  151. package/dist/links/HTTPBatchLinkOptions.d.mts.map +0 -1
  152. package/dist/links/HTTPBatchLinkOptions.d.ts.map +0 -1
  153. package/dist/links/httpBatchLink.d.mts.map +0 -1
  154. package/dist/links/httpBatchLink.d.ts +0 -18
  155. package/dist/links/httpBatchLink.d.ts.map +0 -1
  156. package/dist/links/httpBatchLink.js +0 -94
  157. package/dist/links/httpBatchLink.mjs.map +0 -1
  158. package/dist/links/httpBatchStreamLink.d.mts +0 -22
  159. package/dist/links/httpBatchStreamLink.d.mts.map +0 -1
  160. package/dist/links/httpBatchStreamLink.d.ts +0 -22
  161. package/dist/links/httpBatchStreamLink.d.ts.map +0 -1
  162. package/dist/links/httpBatchStreamLink.js +0 -126
  163. package/dist/links/httpBatchStreamLink.mjs +0 -125
  164. package/dist/links/httpBatchStreamLink.mjs.map +0 -1
  165. package/dist/links/httpLink.d.mts.map +0 -1
  166. package/dist/links/httpLink.d.ts.map +0 -1
  167. package/dist/links/httpLink.js +0 -79
  168. package/dist/links/httpLink.mjs.map +0 -1
  169. package/dist/links/httpSubscriptionLink.d.mts +0 -30
  170. package/dist/links/httpSubscriptionLink.d.mts.map +0 -1
  171. package/dist/links/httpSubscriptionLink.d.ts +0 -30
  172. package/dist/links/httpSubscriptionLink.d.ts.map +0 -1
  173. package/dist/links/httpSubscriptionLink.js +0 -142
  174. package/dist/links/httpSubscriptionLink.mjs +0 -141
  175. package/dist/links/httpSubscriptionLink.mjs.map +0 -1
  176. package/dist/links/internals/contentTypes.d.mts +0 -10
  177. package/dist/links/internals/contentTypes.d.mts.map +0 -1
  178. package/dist/links/internals/contentTypes.d.ts +0 -10
  179. package/dist/links/internals/contentTypes.d.ts.map +0 -1
  180. package/dist/links/internals/contentTypes.js +0 -16
  181. package/dist/links/internals/contentTypes.mjs +0 -14
  182. package/dist/links/internals/contentTypes.mjs.map +0 -1
  183. package/dist/links/internals/createChain.js +0 -26
  184. package/dist/links/internals/createChain.mjs.map +0 -1
  185. package/dist/links/internals/httpUtils.d.mts.map +0 -1
  186. package/dist/links/internals/httpUtils.d.ts.map +0 -1
  187. package/dist/links/internals/httpUtils.mjs.map +0 -1
  188. package/dist/links/internals/subscriptions.d.mts.map +0 -1
  189. package/dist/links/internals/subscriptions.d.ts.map +0 -1
  190. package/dist/links/internals/urlWithConnectionParams.d.mts +0 -27
  191. package/dist/links/internals/urlWithConnectionParams.d.mts.map +0 -1
  192. package/dist/links/internals/urlWithConnectionParams.d.ts +0 -27
  193. package/dist/links/internals/urlWithConnectionParams.d.ts.map +0 -1
  194. package/dist/links/internals/urlWithConnectionParams.js +0 -12
  195. package/dist/links/internals/urlWithConnectionParams.mjs +0 -12
  196. package/dist/links/internals/urlWithConnectionParams.mjs.map +0 -1
  197. package/dist/links/localLink.d.mts +0 -22
  198. package/dist/links/localLink.d.mts.map +0 -1
  199. package/dist/links/localLink.d.ts +0 -22
  200. package/dist/links/localLink.d.ts.map +0 -1
  201. package/dist/links/localLink.js +0 -192
  202. package/dist/links/localLink.mjs +0 -193
  203. package/dist/links/localLink.mjs.map +0 -1
  204. package/dist/links/loggerLink.d.mts.map +0 -1
  205. package/dist/links/loggerLink.d.ts.map +0 -1
  206. package/dist/links/loggerLink.mjs.map +0 -1
  207. package/dist/links/retryLink.d.mts +0 -35
  208. package/dist/links/retryLink.d.mts.map +0 -1
  209. package/dist/links/retryLink.d.ts +0 -35
  210. package/dist/links/retryLink.d.ts.map +0 -1
  211. package/dist/links/retryLink.js +0 -64
  212. package/dist/links/retryLink.mjs +0 -64
  213. package/dist/links/retryLink.mjs.map +0 -1
  214. package/dist/links/splitLink.d.mts.map +0 -1
  215. package/dist/links/splitLink.d.ts.map +0 -1
  216. package/dist/links/splitLink.js +0 -26
  217. package/dist/links/splitLink.mjs.map +0 -1
  218. package/dist/links/types.d.mts +0 -71
  219. package/dist/links/types.d.mts.map +0 -1
  220. package/dist/links/types.d.ts +0 -71
  221. package/dist/links/types.d.ts.map +0 -1
  222. package/dist/links/wsLink/createWsClient.d.mts +0 -10
  223. package/dist/links/wsLink/createWsClient.d.mts.map +0 -1
  224. package/dist/links/wsLink/createWsClient.d.ts +0 -10
  225. package/dist/links/wsLink/createWsClient.d.ts.map +0 -1
  226. package/dist/links/wsLink/createWsClient.js +0 -9
  227. package/dist/links/wsLink/createWsClient.mjs +0 -10
  228. package/dist/links/wsLink/createWsClient.mjs.map +0 -1
  229. package/dist/links/wsLink/wsClient/options.d.mts +0 -69
  230. package/dist/links/wsLink/wsClient/options.d.mts.map +0 -1
  231. package/dist/links/wsLink/wsClient/options.d.ts +0 -69
  232. package/dist/links/wsLink/wsClient/options.d.ts.map +0 -1
  233. package/dist/links/wsLink/wsClient/options.js +0 -24
  234. package/dist/links/wsLink/wsClient/options.mjs +0 -22
  235. package/dist/links/wsLink/wsClient/options.mjs.map +0 -1
  236. package/dist/links/wsLink/wsClient/requestManager.js +0 -136
  237. package/dist/links/wsLink/wsClient/requestManager.mjs +0 -137
  238. package/dist/links/wsLink/wsClient/requestManager.mjs.map +0 -1
  239. package/dist/links/wsLink/wsClient/utils.js +0 -77
  240. package/dist/links/wsLink/wsClient/utils.mjs +0 -74
  241. package/dist/links/wsLink/wsClient/utils.mjs.map +0 -1
  242. package/dist/links/wsLink/wsClient/wsClient.d.mts +0 -104
  243. package/dist/links/wsLink/wsClient/wsClient.d.mts.map +0 -1
  244. package/dist/links/wsLink/wsClient/wsClient.d.ts +0 -104
  245. package/dist/links/wsLink/wsClient/wsClient.d.ts.map +0 -1
  246. package/dist/links/wsLink/wsClient/wsClient.js +0 -276
  247. package/dist/links/wsLink/wsClient/wsClient.mjs +0 -276
  248. package/dist/links/wsLink/wsClient/wsClient.mjs.map +0 -1
  249. package/dist/links/wsLink/wsClient/wsConnection.js +0 -165
  250. package/dist/links/wsLink/wsClient/wsConnection.mjs +0 -164
  251. package/dist/links/wsLink/wsClient/wsConnection.mjs.map +0 -1
  252. package/dist/links/wsLink/wsLink.d.mts.map +0 -1
  253. package/dist/links/wsLink/wsLink.d.ts +0 -15
  254. package/dist/links/wsLink/wsLink.d.ts.map +0 -1
  255. package/dist/links/wsLink/wsLink.js +0 -34
  256. package/dist/links/wsLink/wsLink.mjs.map +0 -1
  257. package/dist/links.js +0 -11
  258. package/dist/links.mjs +0 -11
  259. package/dist/node_modules/.pnpm/@oxc-project_runtime@0.71.0/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js +0 -68
  260. package/dist/node_modules/.pnpm/@oxc-project_runtime@0.71.0/node_modules/@oxc-project/runtime/src/helpers/usingCtx.mjs +0 -66
  261. package/dist/node_modules/.pnpm/@oxc-project_runtime@0.71.0/node_modules/@oxc-project/runtime/src/helpers/usingCtx.mjs.map +0 -1
  262. package/dist/unstable-internals.d.ts +0 -3
  263. package/dist/unstable-internals.js +0 -3
  264. package/links/httpBatchLink/index.d.ts +0 -1
  265. package/links/httpBatchLink/index.js +0 -1
  266. package/links/httpLink/index.d.ts +0 -1
  267. package/links/httpLink/index.js +0 -1
  268. package/links/loggerLink/index.d.ts +0 -1
  269. package/links/loggerLink/index.js +0 -1
  270. package/links/splitLink/index.d.ts +0 -1
  271. package/links/splitLink/index.js +0 -1
  272. package/links/wsLink/wsLink/index.d.ts +0 -1
  273. package/links/wsLink/wsLink/index.js +0 -1
  274. package/unstable-internals/index.d.ts +0 -1
  275. package/unstable-internals/index.js +0 -1
  276. /package/dist/{_virtual/rolldown_runtime.js → chunk-DWy1uDak.cjs} +0 -0
@@ -1,5 +1,5 @@
1
- const require_rolldown_runtime = require('./_virtual/rolldown_runtime.js');
2
- const __trpc_server_unstable_core_do_not_import = require_rolldown_runtime.__toESM(require("@trpc/server/unstable-core-do-not-import"));
1
+ const require_chunk = require('./chunk-DWy1uDak.cjs');
2
+ const __trpc_server_unstable_core_do_not_import = require_chunk.__toESM(require("@trpc/server/unstable-core-do-not-import"));
3
3
 
4
4
  //#region src/TRPCClientError.ts
5
5
  function isTRPCClientError(cause) {
@@ -53,5 +53,15 @@ var TRPCClientError = class TRPCClientError extends Error {
53
53
  };
54
54
 
55
55
  //#endregion
56
- exports.TRPCClientError = TRPCClientError;
57
- exports.isTRPCClientError = isTRPCClientError;
56
+ Object.defineProperty(exports, 'TRPCClientError', {
57
+ enumerable: true,
58
+ get: function () {
59
+ return TRPCClientError;
60
+ }
61
+ });
62
+ Object.defineProperty(exports, 'isTRPCClientError', {
63
+ enumerable: true,
64
+ get: function () {
65
+ return isTRPCClientError;
66
+ }
67
+ });
@@ -53,4 +53,4 @@ var TRPCClientError = class TRPCClientError extends Error {
53
53
 
54
54
  //#endregion
55
55
  export { TRPCClientError, isTRPCClientError };
56
- //# sourceMappingURL=TRPCClientError.mjs.map
56
+ //# sourceMappingURL=TRPCClientError-COkhCKf3.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TRPCClientError-COkhCKf3.mjs","names":["cause: unknown","obj: unknown","err: unknown","fallback: string","message: string","opts?: {\n result?: Maybe<TRPCErrorResponse<inferErrorShape<TRouterOrProcedure>>>;\n cause?: Error;\n meta?: Record<string, unknown>;\n }","_cause: Error | TRPCErrorResponse<any> | object","opts: { meta?: Record<string, unknown> }"],"sources":["../src/TRPCClientError.ts"],"sourcesContent":["import type {\n inferClientTypes,\n InferrableClientTypes,\n Maybe,\n TRPCErrorResponse,\n} from '@trpc/server/unstable-core-do-not-import';\nimport {\n isObject,\n type DefaultErrorShape,\n} from '@trpc/server/unstable-core-do-not-import';\n\ntype inferErrorShape<TInferrable extends InferrableClientTypes> =\n inferClientTypes<TInferrable>['errorShape'];\nexport interface TRPCClientErrorBase<TShape extends DefaultErrorShape> {\n readonly message: string;\n readonly shape: Maybe<TShape>;\n readonly data: Maybe<TShape['data']>;\n}\nexport type TRPCClientErrorLike<TInferrable extends InferrableClientTypes> =\n TRPCClientErrorBase<inferErrorShape<TInferrable>>;\n\nexport function isTRPCClientError<TInferrable extends InferrableClientTypes>(\n cause: unknown,\n): cause is TRPCClientError<TInferrable> {\n return cause instanceof TRPCClientError;\n}\n\nfunction isTRPCErrorResponse(obj: unknown): obj is TRPCErrorResponse<any> {\n return (\n isObject(obj) &&\n isObject(obj['error']) &&\n typeof obj['error']['code'] === 'number' &&\n typeof obj['error']['message'] === 'string'\n );\n}\n\nfunction getMessageFromUnknownError(err: unknown, fallback: string): string {\n if (typeof err === 'string') {\n return err;\n }\n if (isObject(err) && typeof err['message'] === 'string') {\n return err['message'];\n }\n return fallback;\n}\n\nexport class TRPCClientError<TRouterOrProcedure extends InferrableClientTypes>\n extends Error\n implements TRPCClientErrorBase<inferErrorShape<TRouterOrProcedure>>\n{\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore override doesn't work in all environments due to \"This member cannot have an 'override' modifier because it is not declared in the base class 'Error'\"\n public override readonly cause;\n public readonly shape: Maybe<inferErrorShape<TRouterOrProcedure>>;\n public readonly data: Maybe<inferErrorShape<TRouterOrProcedure>['data']>;\n\n /**\n * Additional meta data about the error\n * In the case of HTTP-errors, we'll have `response` and potentially `responseJSON` here\n */\n public meta;\n\n constructor(\n message: string,\n opts?: {\n result?: Maybe<TRPCErrorResponse<inferErrorShape<TRouterOrProcedure>>>;\n cause?: Error;\n meta?: Record<string, unknown>;\n },\n ) {\n const cause = opts?.cause;\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore https://github.com/tc39/proposal-error-cause\n super(message, { cause });\n\n this.meta = opts?.meta;\n\n this.cause = cause;\n this.shape = opts?.result?.error;\n this.data = opts?.result?.error.data;\n this.name = 'TRPCClientError';\n\n Object.setPrototypeOf(this, TRPCClientError.prototype);\n }\n\n public static from<TRouterOrProcedure extends InferrableClientTypes>(\n _cause: Error | TRPCErrorResponse<any> | object,\n opts: { meta?: Record<string, unknown> } = {},\n ): TRPCClientError<TRouterOrProcedure> {\n const cause = _cause as unknown;\n\n if (isTRPCClientError(cause)) {\n if (opts.meta) {\n // Decorate with meta error data\n cause.meta = {\n ...cause.meta,\n ...opts.meta,\n };\n }\n return cause;\n }\n if (isTRPCErrorResponse(cause)) {\n return new TRPCClientError(cause.error.message, {\n ...opts,\n result: cause,\n });\n }\n return new TRPCClientError(\n getMessageFromUnknownError(cause, 'Unknown error'),\n {\n ...opts,\n cause: cause as any,\n },\n );\n }\n}\n"],"mappings":";;;AAqBA,SAAgB,kBACdA,OACuC;AACvC,QAAO,iBAAiB;AACzB;AAED,SAAS,oBAAoBC,KAA6C;AACxE,QACE,SAAS,IAAI,IACb,SAAS,IAAI,SAAS,WACf,IAAI,SAAS,YAAY,mBACzB,IAAI,SAAS,eAAe;AAEtC;AAED,SAAS,2BAA2BC,KAAcC,UAA0B;AAC1E,YAAW,QAAQ,SACjB,QAAO;AAET,KAAI,SAAS,IAAI,WAAW,IAAI,eAAe,SAC7C,QAAO,IAAI;AAEb,QAAO;AACR;AAED,IAAa,kBAAb,MAAa,wBACH,MAEV;CAGE,AAAyB;CACzB,AAAgB;CAChB,AAAgB;;;;;CAMhB,AAAO;CAEP,YACEC,SACAC,MAKA;EACA,MAAM,QAAQ,MAAM;AAIpB,QAAM,SAAS,EAAE,MAAO,EAAC;AAEzB,OAAK,OAAO,MAAM;AAElB,OAAK,QAAQ;AACb,OAAK,QAAQ,MAAM,QAAQ;AAC3B,OAAK,OAAO,MAAM,QAAQ,MAAM;AAChC,OAAK,OAAO;AAEZ,SAAO,eAAe,MAAM,gBAAgB,UAAU;CACvD;CAED,OAAc,KACZC,QACAC,OAA2C,CAAE,GACR;EACrC,MAAM,QAAQ;AAEd,MAAI,kBAAkB,MAAM,EAAE;AAC5B,OAAI,KAAK,KAEP,OAAM,OAAO;IACX,GAAG,MAAM;IACT,GAAG,KAAK;GACT;AAEH,UAAO;EACR;AACD,MAAI,oBAAoB,MAAM,CAC5B,QAAO,IAAI,gBAAgB,MAAM,MAAM,SAAS;GAC9C,GAAG;GACH,QAAQ;EACT;AAEH,SAAO,IAAI,gBACT,2BAA2B,OAAO,gBAAgB,EAClD;GACE,GAAG;GACI;EACR;CAEJ;AACF"}
@@ -0,0 +1,267 @@
1
+ const require_chunk = require('./chunk-DWy1uDak.cjs');
2
+ const require_TRPCClientError = require('./TRPCClientError-CGgRtttT.cjs');
3
+ const require_httpUtils = require('./httpUtils-Buf6jCgh.cjs');
4
+ const __trpc_server_observable = require_chunk.__toESM(require("@trpc/server/observable"));
5
+ const __trpc_server_unstable_core_do_not_import = require_chunk.__toESM(require("@trpc/server/unstable-core-do-not-import"));
6
+
7
+ //#region src/internals/dataLoader.ts
8
+ /**
9
+ * A function that should never be called unless we messed something up.
10
+ */
11
+ const throwFatalError = () => {
12
+ throw new Error("Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new");
13
+ };
14
+ /**
15
+ * Dataloader that's very inspired by https://github.com/graphql/dataloader
16
+ * Less configuration, no caching, and allows you to cancel requests
17
+ * When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
18
+ */
19
+ function dataLoader(batchLoader) {
20
+ let pendingItems = null;
21
+ let dispatchTimer = null;
22
+ const destroyTimerAndPendingItems = () => {
23
+ clearTimeout(dispatchTimer);
24
+ dispatchTimer = null;
25
+ pendingItems = null;
26
+ };
27
+ /**
28
+ * Iterate through the items and split them into groups based on the `batchLoader`'s validate function
29
+ */
30
+ function groupItems(items) {
31
+ const groupedItems = [[]];
32
+ let index = 0;
33
+ while (true) {
34
+ const item = items[index];
35
+ if (!item) break;
36
+ const lastGroup = groupedItems[groupedItems.length - 1];
37
+ if (item.aborted) {
38
+ item.reject?.(new Error("Aborted"));
39
+ index++;
40
+ continue;
41
+ }
42
+ const isValid = batchLoader.validate(lastGroup.concat(item).map((it) => it.key));
43
+ if (isValid) {
44
+ lastGroup.push(item);
45
+ index++;
46
+ continue;
47
+ }
48
+ if (lastGroup.length === 0) {
49
+ item.reject?.(new Error("Input is too big for a single dispatch"));
50
+ index++;
51
+ continue;
52
+ }
53
+ groupedItems.push([]);
54
+ }
55
+ return groupedItems;
56
+ }
57
+ function dispatch() {
58
+ const groupedItems = groupItems(pendingItems);
59
+ destroyTimerAndPendingItems();
60
+ for (const items of groupedItems) {
61
+ if (!items.length) continue;
62
+ const batch = { items };
63
+ for (const item of items) item.batch = batch;
64
+ const promise = batchLoader.fetch(batch.items.map((_item) => _item.key));
65
+ promise.then(async (result) => {
66
+ await Promise.all(result.map(async (valueOrPromise, index) => {
67
+ const item = batch.items[index];
68
+ try {
69
+ const value = await Promise.resolve(valueOrPromise);
70
+ item.resolve?.(value);
71
+ } catch (cause) {
72
+ item.reject?.(cause);
73
+ }
74
+ item.batch = null;
75
+ item.reject = null;
76
+ item.resolve = null;
77
+ }));
78
+ for (const item of batch.items) {
79
+ item.reject?.(new Error("Missing result"));
80
+ item.batch = null;
81
+ }
82
+ }).catch((cause) => {
83
+ for (const item of batch.items) {
84
+ item.reject?.(cause);
85
+ item.batch = null;
86
+ }
87
+ });
88
+ }
89
+ }
90
+ function load(key) {
91
+ const item = {
92
+ aborted: false,
93
+ key,
94
+ batch: null,
95
+ resolve: throwFatalError,
96
+ reject: throwFatalError
97
+ };
98
+ const promise = new Promise((resolve, reject) => {
99
+ item.reject = reject;
100
+ item.resolve = resolve;
101
+ pendingItems ??= [];
102
+ pendingItems.push(item);
103
+ });
104
+ dispatchTimer ??= setTimeout(dispatch);
105
+ return promise;
106
+ }
107
+ return { load };
108
+ }
109
+
110
+ //#endregion
111
+ //#region src/internals/signals.ts
112
+ /**
113
+ * Like `Promise.all()` but for abort signals
114
+ * - When all signals have been aborted, the merged signal will be aborted
115
+ * - If one signal is `null`, no signal will be aborted
116
+ */
117
+ function allAbortSignals(...signals) {
118
+ const ac = new AbortController();
119
+ const count = signals.length;
120
+ let abortedCount = 0;
121
+ const onAbort = () => {
122
+ if (++abortedCount === count) ac.abort();
123
+ };
124
+ for (const signal of signals) if (signal?.aborted) onAbort();
125
+ else signal?.addEventListener("abort", onAbort, { once: true });
126
+ return ac.signal;
127
+ }
128
+ /**
129
+ * Like `Promise.race` but for abort signals
130
+ *
131
+ * Basically, a ponyfill for
132
+ * [`AbortSignal.any`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static).
133
+ */
134
+ function raceAbortSignals(...signals) {
135
+ const ac = new AbortController();
136
+ for (const signal of signals) if (signal?.aborted) ac.abort();
137
+ else signal?.addEventListener("abort", () => ac.abort(), { once: true });
138
+ return ac.signal;
139
+ }
140
+ function abortSignalToPromise(signal) {
141
+ return new Promise((_, reject) => {
142
+ if (signal.aborted) {
143
+ reject(signal.reason);
144
+ return;
145
+ }
146
+ signal.addEventListener("abort", () => {
147
+ reject(signal.reason);
148
+ }, { once: true });
149
+ });
150
+ }
151
+
152
+ //#endregion
153
+ //#region src/links/httpBatchLink.ts
154
+ /**
155
+ * @see https://trpc.io/docs/client/links/httpBatchLink
156
+ */
157
+ function httpBatchLink(opts) {
158
+ const resolvedOpts = require_httpUtils.resolveHTTPLinkOptions(opts);
159
+ const maxURLLength = opts.maxURLLength ?? Infinity;
160
+ const maxItems = opts.maxItems ?? Infinity;
161
+ return () => {
162
+ const batchLoader = (type) => {
163
+ return {
164
+ validate(batchOps) {
165
+ if (maxURLLength === Infinity && maxItems === Infinity) return true;
166
+ if (batchOps.length > maxItems) return false;
167
+ const path = batchOps.map((op) => op.path).join(",");
168
+ const inputs = batchOps.map((op) => op.input);
169
+ const url = require_httpUtils.getUrl({
170
+ ...resolvedOpts,
171
+ type,
172
+ path,
173
+ inputs,
174
+ signal: null
175
+ });
176
+ return url.length <= maxURLLength;
177
+ },
178
+ async fetch(batchOps) {
179
+ const path = batchOps.map((op) => op.path).join(",");
180
+ const inputs = batchOps.map((op) => op.input);
181
+ const signal = allAbortSignals(...batchOps.map((op) => op.signal));
182
+ const res = await require_httpUtils.jsonHttpRequester({
183
+ ...resolvedOpts,
184
+ path,
185
+ inputs,
186
+ type,
187
+ headers() {
188
+ if (!opts.headers) return {};
189
+ if (typeof opts.headers === "function") return opts.headers({ opList: batchOps });
190
+ return opts.headers;
191
+ },
192
+ signal
193
+ });
194
+ const resJSON = Array.isArray(res.json) ? res.json : batchOps.map(() => res.json);
195
+ const result = resJSON.map((item) => ({
196
+ meta: res.meta,
197
+ json: item
198
+ }));
199
+ return result;
200
+ }
201
+ };
202
+ };
203
+ const query = dataLoader(batchLoader("query"));
204
+ const mutation = dataLoader(batchLoader("mutation"));
205
+ const loaders = {
206
+ query,
207
+ mutation
208
+ };
209
+ return ({ op }) => {
210
+ return (0, __trpc_server_observable.observable)((observer) => {
211
+ /* istanbul ignore if -- @preserve */
212
+ if (op.type === "subscription") throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`");
213
+ const loader = loaders[op.type];
214
+ const promise = loader.load(op);
215
+ let _res = void 0;
216
+ promise.then((res) => {
217
+ _res = res;
218
+ const transformed = (0, __trpc_server_unstable_core_do_not_import.transformResult)(res.json, resolvedOpts.transformer.output);
219
+ if (!transformed.ok) {
220
+ observer.error(require_TRPCClientError.TRPCClientError.from(transformed.error, { meta: res.meta }));
221
+ return;
222
+ }
223
+ observer.next({
224
+ context: res.meta,
225
+ result: transformed.result
226
+ });
227
+ observer.complete();
228
+ }).catch((err) => {
229
+ observer.error(require_TRPCClientError.TRPCClientError.from(err, { meta: _res?.meta }));
230
+ });
231
+ return () => {};
232
+ });
233
+ };
234
+ };
235
+ }
236
+
237
+ //#endregion
238
+ Object.defineProperty(exports, 'abortSignalToPromise', {
239
+ enumerable: true,
240
+ get: function () {
241
+ return abortSignalToPromise;
242
+ }
243
+ });
244
+ Object.defineProperty(exports, 'allAbortSignals', {
245
+ enumerable: true,
246
+ get: function () {
247
+ return allAbortSignals;
248
+ }
249
+ });
250
+ Object.defineProperty(exports, 'dataLoader', {
251
+ enumerable: true,
252
+ get: function () {
253
+ return dataLoader;
254
+ }
255
+ });
256
+ Object.defineProperty(exports, 'httpBatchLink', {
257
+ enumerable: true,
258
+ get: function () {
259
+ return httpBatchLink;
260
+ }
261
+ });
262
+ Object.defineProperty(exports, 'raceAbortSignals', {
263
+ enumerable: true,
264
+ get: function () {
265
+ return raceAbortSignals;
266
+ }
267
+ });
@@ -0,0 +1,238 @@
1
+ import { TRPCClientError } from "./TRPCClientError-COkhCKf3.mjs";
2
+ import { getUrl, jsonHttpRequester, resolveHTTPLinkOptions } from "./httpUtils-3pbQzhUL.mjs";
3
+ import { observable } from "@trpc/server/observable";
4
+ import { transformResult } from "@trpc/server/unstable-core-do-not-import";
5
+
6
+ //#region src/internals/dataLoader.ts
7
+ /**
8
+ * A function that should never be called unless we messed something up.
9
+ */
10
+ const throwFatalError = () => {
11
+ throw new Error("Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new");
12
+ };
13
+ /**
14
+ * Dataloader that's very inspired by https://github.com/graphql/dataloader
15
+ * Less configuration, no caching, and allows you to cancel requests
16
+ * When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
17
+ */
18
+ function dataLoader(batchLoader) {
19
+ let pendingItems = null;
20
+ let dispatchTimer = null;
21
+ const destroyTimerAndPendingItems = () => {
22
+ clearTimeout(dispatchTimer);
23
+ dispatchTimer = null;
24
+ pendingItems = null;
25
+ };
26
+ /**
27
+ * Iterate through the items and split them into groups based on the `batchLoader`'s validate function
28
+ */
29
+ function groupItems(items) {
30
+ const groupedItems = [[]];
31
+ let index = 0;
32
+ while (true) {
33
+ const item = items[index];
34
+ if (!item) break;
35
+ const lastGroup = groupedItems[groupedItems.length - 1];
36
+ if (item.aborted) {
37
+ item.reject?.(new Error("Aborted"));
38
+ index++;
39
+ continue;
40
+ }
41
+ const isValid = batchLoader.validate(lastGroup.concat(item).map((it) => it.key));
42
+ if (isValid) {
43
+ lastGroup.push(item);
44
+ index++;
45
+ continue;
46
+ }
47
+ if (lastGroup.length === 0) {
48
+ item.reject?.(new Error("Input is too big for a single dispatch"));
49
+ index++;
50
+ continue;
51
+ }
52
+ groupedItems.push([]);
53
+ }
54
+ return groupedItems;
55
+ }
56
+ function dispatch() {
57
+ const groupedItems = groupItems(pendingItems);
58
+ destroyTimerAndPendingItems();
59
+ for (const items of groupedItems) {
60
+ if (!items.length) continue;
61
+ const batch = { items };
62
+ for (const item of items) item.batch = batch;
63
+ const promise = batchLoader.fetch(batch.items.map((_item) => _item.key));
64
+ promise.then(async (result) => {
65
+ await Promise.all(result.map(async (valueOrPromise, index) => {
66
+ const item = batch.items[index];
67
+ try {
68
+ const value = await Promise.resolve(valueOrPromise);
69
+ item.resolve?.(value);
70
+ } catch (cause) {
71
+ item.reject?.(cause);
72
+ }
73
+ item.batch = null;
74
+ item.reject = null;
75
+ item.resolve = null;
76
+ }));
77
+ for (const item of batch.items) {
78
+ item.reject?.(new Error("Missing result"));
79
+ item.batch = null;
80
+ }
81
+ }).catch((cause) => {
82
+ for (const item of batch.items) {
83
+ item.reject?.(cause);
84
+ item.batch = null;
85
+ }
86
+ });
87
+ }
88
+ }
89
+ function load(key) {
90
+ const item = {
91
+ aborted: false,
92
+ key,
93
+ batch: null,
94
+ resolve: throwFatalError,
95
+ reject: throwFatalError
96
+ };
97
+ const promise = new Promise((resolve, reject) => {
98
+ item.reject = reject;
99
+ item.resolve = resolve;
100
+ pendingItems ??= [];
101
+ pendingItems.push(item);
102
+ });
103
+ dispatchTimer ??= setTimeout(dispatch);
104
+ return promise;
105
+ }
106
+ return { load };
107
+ }
108
+
109
+ //#endregion
110
+ //#region src/internals/signals.ts
111
+ /**
112
+ * Like `Promise.all()` but for abort signals
113
+ * - When all signals have been aborted, the merged signal will be aborted
114
+ * - If one signal is `null`, no signal will be aborted
115
+ */
116
+ function allAbortSignals(...signals) {
117
+ const ac = new AbortController();
118
+ const count = signals.length;
119
+ let abortedCount = 0;
120
+ const onAbort = () => {
121
+ if (++abortedCount === count) ac.abort();
122
+ };
123
+ for (const signal of signals) if (signal?.aborted) onAbort();
124
+ else signal?.addEventListener("abort", onAbort, { once: true });
125
+ return ac.signal;
126
+ }
127
+ /**
128
+ * Like `Promise.race` but for abort signals
129
+ *
130
+ * Basically, a ponyfill for
131
+ * [`AbortSignal.any`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static).
132
+ */
133
+ function raceAbortSignals(...signals) {
134
+ const ac = new AbortController();
135
+ for (const signal of signals) if (signal?.aborted) ac.abort();
136
+ else signal?.addEventListener("abort", () => ac.abort(), { once: true });
137
+ return ac.signal;
138
+ }
139
+ function abortSignalToPromise(signal) {
140
+ return new Promise((_, reject) => {
141
+ if (signal.aborted) {
142
+ reject(signal.reason);
143
+ return;
144
+ }
145
+ signal.addEventListener("abort", () => {
146
+ reject(signal.reason);
147
+ }, { once: true });
148
+ });
149
+ }
150
+
151
+ //#endregion
152
+ //#region src/links/httpBatchLink.ts
153
+ /**
154
+ * @see https://trpc.io/docs/client/links/httpBatchLink
155
+ */
156
+ function httpBatchLink(opts) {
157
+ const resolvedOpts = resolveHTTPLinkOptions(opts);
158
+ const maxURLLength = opts.maxURLLength ?? Infinity;
159
+ const maxItems = opts.maxItems ?? Infinity;
160
+ return () => {
161
+ const batchLoader = (type) => {
162
+ return {
163
+ validate(batchOps) {
164
+ if (maxURLLength === Infinity && maxItems === Infinity) return true;
165
+ if (batchOps.length > maxItems) return false;
166
+ const path = batchOps.map((op) => op.path).join(",");
167
+ const inputs = batchOps.map((op) => op.input);
168
+ const url = getUrl({
169
+ ...resolvedOpts,
170
+ type,
171
+ path,
172
+ inputs,
173
+ signal: null
174
+ });
175
+ return url.length <= maxURLLength;
176
+ },
177
+ async fetch(batchOps) {
178
+ const path = batchOps.map((op) => op.path).join(",");
179
+ const inputs = batchOps.map((op) => op.input);
180
+ const signal = allAbortSignals(...batchOps.map((op) => op.signal));
181
+ const res = await jsonHttpRequester({
182
+ ...resolvedOpts,
183
+ path,
184
+ inputs,
185
+ type,
186
+ headers() {
187
+ if (!opts.headers) return {};
188
+ if (typeof opts.headers === "function") return opts.headers({ opList: batchOps });
189
+ return opts.headers;
190
+ },
191
+ signal
192
+ });
193
+ const resJSON = Array.isArray(res.json) ? res.json : batchOps.map(() => res.json);
194
+ const result = resJSON.map((item) => ({
195
+ meta: res.meta,
196
+ json: item
197
+ }));
198
+ return result;
199
+ }
200
+ };
201
+ };
202
+ const query = dataLoader(batchLoader("query"));
203
+ const mutation = dataLoader(batchLoader("mutation"));
204
+ const loaders = {
205
+ query,
206
+ mutation
207
+ };
208
+ return ({ op }) => {
209
+ return observable((observer) => {
210
+ /* istanbul ignore if -- @preserve */
211
+ if (op.type === "subscription") throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`");
212
+ const loader = loaders[op.type];
213
+ const promise = loader.load(op);
214
+ let _res = void 0;
215
+ promise.then((res) => {
216
+ _res = res;
217
+ const transformed = transformResult(res.json, resolvedOpts.transformer.output);
218
+ if (!transformed.ok) {
219
+ observer.error(TRPCClientError.from(transformed.error, { meta: res.meta }));
220
+ return;
221
+ }
222
+ observer.next({
223
+ context: res.meta,
224
+ result: transformed.result
225
+ });
226
+ observer.complete();
227
+ }).catch((err) => {
228
+ observer.error(TRPCClientError.from(err, { meta: _res?.meta }));
229
+ });
230
+ return () => {};
231
+ });
232
+ };
233
+ };
234
+ }
235
+
236
+ //#endregion
237
+ export { abortSignalToPromise, allAbortSignals, dataLoader, httpBatchLink, raceAbortSignals };
238
+ //# sourceMappingURL=httpBatchLink-DIfnmmcu.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpBatchLink-DIfnmmcu.mjs","names":["batchLoader: BatchLoader<TKey, TValue>","pendingItems: BatchItem<TKey, TValue>[] | null","dispatchTimer: ReturnType<typeof setTimeout> | null","items: BatchItem<TKey, TValue>[]","groupedItems: BatchItem<TKey, TValue>[][]","batch: Batch<TKey, TValue>","key: TKey","item: BatchItem<TKey, TValue>","signal: AbortSignal","opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>","type: ProcedureType"],"sources":["../src/internals/dataLoader.ts","../src/internals/signals.ts","../src/links/httpBatchLink.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\ntype BatchItem<TKey, TValue> = {\n aborted: boolean;\n key: TKey;\n resolve: ((value: TValue) => void) | null;\n reject: ((error: Error) => void) | null;\n batch: Batch<TKey, TValue> | null;\n};\ntype Batch<TKey, TValue> = {\n items: BatchItem<TKey, TValue>[];\n};\nexport type BatchLoader<TKey, TValue> = {\n validate: (keys: TKey[]) => boolean;\n fetch: (keys: TKey[]) => Promise<TValue[] | Promise<TValue>[]>;\n};\n\n/**\n * A function that should never be called unless we messed something up.\n */\nconst throwFatalError = () => {\n throw new Error(\n 'Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new',\n );\n};\n\n/**\n * Dataloader that's very inspired by https://github.com/graphql/dataloader\n * Less configuration, no caching, and allows you to cancel requests\n * When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled\n */\nexport function dataLoader<TKey, TValue>(\n batchLoader: BatchLoader<TKey, TValue>,\n) {\n let pendingItems: BatchItem<TKey, TValue>[] | null = null;\n let dispatchTimer: ReturnType<typeof setTimeout> | null = null;\n\n const destroyTimerAndPendingItems = () => {\n clearTimeout(dispatchTimer as any);\n dispatchTimer = null;\n pendingItems = null;\n };\n\n /**\n * Iterate through the items and split them into groups based on the `batchLoader`'s validate function\n */\n function groupItems(items: BatchItem<TKey, TValue>[]) {\n const groupedItems: BatchItem<TKey, TValue>[][] = [[]];\n let index = 0;\n while (true) {\n const item = items[index];\n if (!item) {\n // we're done\n break;\n }\n const lastGroup = groupedItems[groupedItems.length - 1]!;\n\n if (item.aborted) {\n // Item was aborted before it was dispatched\n item.reject?.(new Error('Aborted'));\n index++;\n continue;\n }\n\n const isValid = batchLoader.validate(\n lastGroup.concat(item).map((it) => it.key),\n );\n\n if (isValid) {\n lastGroup.push(item);\n index++;\n continue;\n }\n\n if (lastGroup.length === 0) {\n item.reject?.(new Error('Input is too big for a single dispatch'));\n index++;\n continue;\n }\n // Create new group, next iteration will try to add the item to that\n groupedItems.push([]);\n }\n return groupedItems;\n }\n\n function dispatch() {\n const groupedItems = groupItems(pendingItems!);\n destroyTimerAndPendingItems();\n\n // Create batches for each group of items\n for (const items of groupedItems) {\n if (!items.length) {\n continue;\n }\n const batch: Batch<TKey, TValue> = {\n items,\n };\n for (const item of items) {\n item.batch = batch;\n }\n const promise = batchLoader.fetch(batch.items.map((_item) => _item.key));\n\n promise\n .then(async (result) => {\n await Promise.all(\n result.map(async (valueOrPromise, index) => {\n const item = batch.items[index]!;\n try {\n const value = await Promise.resolve(valueOrPromise);\n\n item.resolve?.(value);\n } catch (cause) {\n item.reject?.(cause as Error);\n }\n\n item.batch = null;\n item.reject = null;\n item.resolve = null;\n }),\n );\n\n for (const item of batch.items) {\n item.reject?.(new Error('Missing result'));\n item.batch = null;\n }\n })\n .catch((cause) => {\n for (const item of batch.items) {\n item.reject?.(cause);\n item.batch = null;\n }\n });\n }\n }\n function load(key: TKey): Promise<TValue> {\n const item: BatchItem<TKey, TValue> = {\n aborted: false,\n key,\n batch: null,\n resolve: throwFatalError,\n reject: throwFatalError,\n };\n\n const promise = new Promise<TValue>((resolve, reject) => {\n item.reject = reject;\n item.resolve = resolve;\n\n pendingItems ??= [];\n pendingItems.push(item);\n });\n\n dispatchTimer ??= setTimeout(dispatch);\n\n return promise;\n }\n\n return {\n load,\n };\n}\n","import type { Maybe } from '@trpc/server/unstable-core-do-not-import';\n\n/**\n * Like `Promise.all()` but for abort signals\n * - When all signals have been aborted, the merged signal will be aborted\n * - If one signal is `null`, no signal will be aborted\n */\nexport function allAbortSignals(...signals: Maybe<AbortSignal>[]): AbortSignal {\n const ac = new AbortController();\n\n const count = signals.length;\n\n let abortedCount = 0;\n\n const onAbort = () => {\n if (++abortedCount === count) {\n ac.abort();\n }\n };\n\n for (const signal of signals) {\n if (signal?.aborted) {\n onAbort();\n } else {\n signal?.addEventListener('abort', onAbort, {\n once: true,\n });\n }\n }\n\n return ac.signal;\n}\n\n/**\n * Like `Promise.race` but for abort signals\n *\n * Basically, a ponyfill for\n * [`AbortSignal.any`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static).\n */\nexport function raceAbortSignals(\n ...signals: Maybe<AbortSignal>[]\n): AbortSignal {\n const ac = new AbortController();\n\n for (const signal of signals) {\n if (signal?.aborted) {\n ac.abort();\n } else {\n signal?.addEventListener('abort', () => ac.abort(), { once: true });\n }\n }\n\n return ac.signal;\n}\n\nexport function abortSignalToPromise(signal: AbortSignal): Promise<never> {\n return new Promise((_, reject) => {\n if (signal.aborted) {\n reject(signal.reason);\n return;\n }\n signal.addEventListener(\n 'abort',\n () => {\n reject(signal.reason);\n },\n { once: true },\n );\n });\n}\n","import type { AnyRouter, ProcedureType } from '@trpc/server';\nimport { observable } from '@trpc/server/observable';\nimport { transformResult } from '@trpc/server/unstable-core-do-not-import';\nimport type { BatchLoader } from '../internals/dataLoader';\nimport { dataLoader } from '../internals/dataLoader';\nimport { allAbortSignals } from '../internals/signals';\nimport type { NonEmptyArray } from '../internals/types';\nimport { TRPCClientError } from '../TRPCClientError';\nimport type { HTTPBatchLinkOptions } from './HTTPBatchLinkOptions';\nimport type { HTTPResult } from './internals/httpUtils';\nimport {\n getUrl,\n jsonHttpRequester,\n resolveHTTPLinkOptions,\n} from './internals/httpUtils';\nimport type { Operation, TRPCLink } from './types';\n\n/**\n * @see https://trpc.io/docs/client/links/httpBatchLink\n */\nexport function httpBatchLink<TRouter extends AnyRouter>(\n opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>,\n): TRPCLink<TRouter> {\n const resolvedOpts = resolveHTTPLinkOptions(opts);\n const maxURLLength = opts.maxURLLength ?? Infinity;\n const maxItems = opts.maxItems ?? Infinity;\n\n return () => {\n const batchLoader = (\n type: ProcedureType,\n ): BatchLoader<Operation, HTTPResult> => {\n return {\n validate(batchOps) {\n if (maxURLLength === Infinity && maxItems === Infinity) {\n // escape hatch for quick calcs\n return true;\n }\n if (batchOps.length > maxItems) {\n return false;\n }\n const path = batchOps.map((op) => op.path).join(',');\n const inputs = batchOps.map((op) => op.input);\n\n const url = getUrl({\n ...resolvedOpts,\n type,\n path,\n inputs,\n signal: null,\n });\n\n return url.length <= maxURLLength;\n },\n async fetch(batchOps) {\n const path = batchOps.map((op) => op.path).join(',');\n const inputs = batchOps.map((op) => op.input);\n const signal = allAbortSignals(...batchOps.map((op) => op.signal));\n\n const res = await jsonHttpRequester({\n ...resolvedOpts,\n path,\n inputs,\n type,\n headers() {\n if (!opts.headers) {\n return {};\n }\n if (typeof opts.headers === 'function') {\n return opts.headers({\n opList: batchOps as NonEmptyArray<Operation>,\n });\n }\n return opts.headers;\n },\n signal,\n });\n const resJSON = Array.isArray(res.json)\n ? res.json\n : batchOps.map(() => res.json);\n const result = resJSON.map((item) => ({\n meta: res.meta,\n json: item,\n }));\n return result;\n },\n };\n };\n\n const query = dataLoader(batchLoader('query'));\n const mutation = dataLoader(batchLoader('mutation'));\n\n const loaders = { query, mutation };\n return ({ op }) => {\n return observable((observer) => {\n /* istanbul ignore if -- @preserve */\n if (op.type === 'subscription') {\n throw new Error(\n 'Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`',\n );\n }\n const loader = loaders[op.type];\n const promise = loader.load(op);\n\n let _res = undefined as HTTPResult | undefined;\n promise\n .then((res) => {\n _res = res;\n const transformed = transformResult(\n res.json,\n resolvedOpts.transformer.output,\n );\n\n if (!transformed.ok) {\n observer.error(\n TRPCClientError.from(transformed.error, {\n meta: res.meta,\n }),\n );\n return;\n }\n observer.next({\n context: res.meta,\n result: transformed.result,\n });\n observer.complete();\n })\n .catch((err) => {\n observer.error(\n TRPCClientError.from(err, {\n meta: _res?.meta,\n }),\n );\n });\n\n return () => {\n // noop\n };\n });\n };\n };\n}\n"],"mappings":";;;;;;;;;AAoBA,MAAM,kBAAkB,MAAM;AAC5B,OAAM,IAAI,MACR;AAEH;;;;;;AAOD,SAAgB,WACdA,aACA;CACA,IAAIC,eAAiD;CACrD,IAAIC,gBAAsD;CAE1D,MAAM,8BAA8B,MAAM;AACxC,eAAa,cAAqB;AAClC,kBAAgB;AAChB,iBAAe;CAChB;;;;CAKD,SAAS,WAAWC,OAAkC;EACpD,MAAMC,eAA4C,CAAC,CAAE,CAAC;EACtD,IAAI,QAAQ;AACZ,SAAO,MAAM;GACX,MAAM,OAAO,MAAM;AACnB,QAAK,KAEH;GAEF,MAAM,YAAY,aAAa,aAAa,SAAS;AAErD,OAAI,KAAK,SAAS;AAEhB,SAAK,SAAS,IAAI,MAAM,WAAW;AACnC;AACA;GACD;GAED,MAAM,UAAU,YAAY,SAC1B,UAAU,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,GAAG,IAAI,CAC3C;AAED,OAAI,SAAS;AACX,cAAU,KAAK,KAAK;AACpB;AACA;GACD;AAED,OAAI,UA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C,CACH;AACD;KACD;AACD,cAAS,KAAK;MACZ,SAAS,IAAI;MACb,QAAQ,YAAY;KACrB,EAAC;AACF,cAAS,UAAU;IACpB,EAAC,CACD,MAAM,CAAC,QAAQ;AACd,cAAS,MACP,gBAAgB,KAAK,KAAK,EACxB,MAAM,MAAM,KACb,EAAC,CACH;IACF,EAAC;AAEJ,WAAO,MAAM,CAEZ;GACF,EAAC;EACH;CACF;AACF"}
@@ -1,7 +1,7 @@
1
- import { NonEmptyArray } from "../internals/types.mjs";
2
- import { HTTPHeaders, Operation } from "./types.mjs";
3
- import { HTTPLinkBaseOptions } from "./internals/httpUtils.mjs";
1
+ import { HTTPHeaders, NonEmptyArray, Operation, TRPCLink } from "./types.d-DXbqQLCC.mjs";
2
+ import { HTTPLinkBaseOptions } from "./httpUtils.d-C8wPxU79.mjs";
4
3
  import { AnyClientTypes } from "@trpc/server/unstable-core-do-not-import";
4
+ import { AnyRouter as AnyRouter$1 } from "@trpc/server";
5
5
 
6
6
  //#region src/links/HTTPBatchLinkOptions.d.ts
7
7
  type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TRoot> & {
@@ -19,7 +19,15 @@ type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TR
19
19
  */
20
20
  maxItems?: number;
21
21
  };
22
- //#endregion
23
22
  //# sourceMappingURL=HTTPBatchLinkOptions.d.ts.map
24
- export { HTTPBatchLinkOptions };
25
- //# sourceMappingURL=HTTPBatchLinkOptions.d.mts.map
23
+ //#endregion
24
+ //#region src/links/httpBatchLink.d.ts
25
+ /**
26
+ * @see https://trpc.io/docs/client/links/httpBatchLink
27
+ */
28
+ declare function httpBatchLink<TRouter extends AnyRouter$1>(opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
29
+ //# sourceMappingURL=httpBatchLink.d.ts.map
30
+
31
+ //#endregion
32
+ export { HTTPBatchLinkOptions, httpBatchLink };
33
+ //# sourceMappingURL=httpBatchLink.d-BN2Iw_cK.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpBatchLink.d-BN2Iw_cK.d.mts","names":[],"sources":["../src/links/HTTPBatchLinkOptions.ts","../src/links/httpBatchLink.ts"],"sourcesContent":[],"mappings":";;;;;;KAKY,mCAAmC,kBAC7C,oBAAoB;;EADV;;;;EACe,OAAzB,CAAA,EAOM,WAPN,GAAA,CAAA,CAAA,IAAA,EAAA;IAOM,MAAA,EAEU,aAFV,CAEwB,SAFxB,CAAA;EAAW,CAAA,EAEa,GAClB,WADkB,GACJ,OADI,CACI,WADJ,CAAA,CAAA;EAAS;;;;EACN,QAAA,CAAA,EAAA,MAAA;;;;;;;;AAXvB,iBCeI,aDfgB,CAAA,gBCec,WDfd,CAAA,CAAA,IAAA,ECgBxB,oBDhBwB,CCgBH,ODhBG,CAAA,MAAA,CAAA,CAAA,SAAA,CAAA,CAAA,QAAA,CAAA,CAAA,CAAA,ECiB7B,QDjB6B,CCiBpB,ODjBoB,CAAA"}
@@ -1,7 +1,7 @@
1
- import { NonEmptyArray } from "../internals/types.js";
2
- import { HTTPHeaders, Operation } from "./types.js";
3
- import { HTTPLinkBaseOptions } from "./internals/httpUtils.js";
1
+ import { HTTPHeaders, NonEmptyArray, Operation, TRPCLink } from "./types.d-DqGYG6S_.cjs";
2
+ import { HTTPLinkBaseOptions } from "./httpUtils.d-DNRVGNHs.cjs";
4
3
  import { AnyClientTypes } from "@trpc/server/unstable-core-do-not-import";
4
+ import { AnyRouter as AnyRouter$1 } from "@trpc/server";
5
5
 
6
6
  //#region src/links/HTTPBatchLinkOptions.d.ts
7
7
  type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TRoot> & {
@@ -19,7 +19,15 @@ type HTTPBatchLinkOptions<TRoot extends AnyClientTypes> = HTTPLinkBaseOptions<TR
19
19
  */
20
20
  maxItems?: number;
21
21
  };
22
- //#endregion
23
22
  //# sourceMappingURL=HTTPBatchLinkOptions.d.ts.map
24
- export { HTTPBatchLinkOptions };
25
- //# sourceMappingURL=HTTPBatchLinkOptions.d.ts.map
23
+ //#endregion
24
+ //#region src/links/httpBatchLink.d.ts
25
+ /**
26
+ * @see https://trpc.io/docs/client/links/httpBatchLink
27
+ */
28
+ declare function httpBatchLink<TRouter extends AnyRouter$1>(opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
29
+ //# sourceMappingURL=httpBatchLink.d.ts.map
30
+
31
+ //#endregion
32
+ export { HTTPBatchLinkOptions, httpBatchLink };
33
+ //# sourceMappingURL=httpBatchLink.d-CLAuJKNV.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpBatchLink.d-CLAuJKNV.d.cts","names":[],"sources":["../src/links/HTTPBatchLinkOptions.ts","../src/links/httpBatchLink.ts"],"sourcesContent":[],"mappings":";;;;;;KAKY,mCAAmC,kBAC7C,oBAAoB;;EADV;;;;EACe,OAAzB,CAAA,EAOM,WAPN,GAAA,CAAA,CAAA,IAAA,EAAA;IAOM,MAAA,EAEU,aAFV,CAEwB,SAFxB,CAAA;EAAW,CAAA,EAEa,GAClB,WADkB,GACJ,OADI,CACI,WADJ,CAAA,CAAA;EAAS;;;;EACN,QAAA,CAAA,EAAA,MAAA;;;;;;;;AAXvB,iBCeI,aDfgB,CAAA,gBCec,WDfd,CAAA,CAAA,IAAA,ECgBxB,oBDhBwB,CCgBH,ODhBG,CAAA,MAAA,CAAA,CAAA,SAAA,CAAA,CAAA,QAAA,CAAA,CAAA,CAAA,ECiB7B,QDjB6B,CCiBpB,ODjBoB,CAAA"}