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

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 (234) hide show
  1. package/dist/TRPCClientError.d.mts +33 -0
  2. package/dist/TRPCClientError.d.mts.map +1 -0
  3. package/dist/TRPCClientError.d.ts +29 -25
  4. package/dist/TRPCClientError.d.ts.map +1 -1
  5. package/dist/TRPCClientError.js +48 -72
  6. package/dist/TRPCClientError.mjs +48 -71
  7. package/dist/TRPCClientError.mjs.map +1 -0
  8. package/dist/_virtual/rolldown_runtime.js +39 -0
  9. package/dist/_virtual/rolldown_runtime.mjs +27 -0
  10. package/dist/createTRPCClient.d.mts +73 -0
  11. package/dist/createTRPCClient.d.mts.map +1 -0
  12. package/dist/createTRPCClient.d.ts +38 -34
  13. package/dist/createTRPCClient.d.ts.map +1 -1
  14. package/dist/createTRPCClient.js +34 -34
  15. package/dist/createTRPCClient.mjs +33 -31
  16. package/dist/createTRPCClient.mjs.map +1 -0
  17. package/dist/createTRPCUntypedClient.d.mts +9 -0
  18. package/dist/createTRPCUntypedClient.d.mts.map +1 -0
  19. package/dist/createTRPCUntypedClient.d.ts +8 -6
  20. package/dist/createTRPCUntypedClient.d.ts.map +1 -1
  21. package/dist/createTRPCUntypedClient.js +5 -6
  22. package/dist/createTRPCUntypedClient.mjs +6 -3
  23. package/dist/createTRPCUntypedClient.mjs.map +1 -0
  24. package/dist/getFetch.d.mts +10 -0
  25. package/dist/getFetch.d.mts.map +1 -0
  26. package/dist/getFetch.d.ts +9 -2
  27. package/dist/getFetch.d.ts.map +1 -1
  28. package/dist/getFetch.js +8 -13
  29. package/dist/getFetch.mjs +8 -11
  30. package/dist/getFetch.mjs.map +1 -0
  31. package/dist/index.d.mts +21 -0
  32. package/dist/index.d.ts +21 -16
  33. package/dist/index.js +41 -42
  34. package/dist/index.mjs +18 -15
  35. package/dist/internals/TRPCUntypedClient.d.mts +46 -0
  36. package/dist/internals/TRPCUntypedClient.d.mts.map +1 -0
  37. package/dist/internals/TRPCUntypedClient.d.ts +40 -33
  38. package/dist/internals/TRPCUntypedClient.d.ts.map +1 -1
  39. package/dist/internals/TRPCUntypedClient.js +94 -113
  40. package/dist/internals/TRPCUntypedClient.mjs +93 -110
  41. package/dist/internals/TRPCUntypedClient.mjs.map +1 -0
  42. package/dist/internals/dataLoader.js +101 -116
  43. package/dist/internals/dataLoader.mjs +101 -114
  44. package/dist/internals/dataLoader.mjs.map +1 -0
  45. package/dist/internals/inputWithTrackedEventId.js +9 -12
  46. package/dist/internals/inputWithTrackedEventId.mjs +9 -10
  47. package/dist/internals/inputWithTrackedEventId.mjs.map +1 -0
  48. package/dist/internals/signals.js +39 -40
  49. package/dist/internals/signals.mjs +39 -39
  50. package/dist/internals/signals.mjs.map +1 -0
  51. package/dist/internals/transformer.d.mts +47 -0
  52. package/dist/internals/transformer.d.mts.map +1 -0
  53. package/dist/internals/transformer.d.ts +28 -23
  54. package/dist/internals/transformer.d.ts.map +1 -1
  55. package/dist/internals/transformer.js +25 -26
  56. package/dist/internals/transformer.mjs +25 -24
  57. package/dist/internals/transformer.mjs.map +1 -0
  58. package/dist/internals/types.d.mts +85 -0
  59. package/dist/internals/types.d.mts.map +1 -0
  60. package/dist/internals/types.d.ts +45 -42
  61. package/dist/internals/types.d.ts.map +1 -1
  62. package/dist/links/HTTPBatchLinkOptions.d.mts +25 -0
  63. package/dist/links/HTTPBatchLinkOptions.d.mts.map +1 -0
  64. package/dist/links/HTTPBatchLinkOptions.d.ts +23 -18
  65. package/dist/links/HTTPBatchLinkOptions.d.ts.map +1 -1
  66. package/dist/links/httpBatchLink.d.mts +18 -0
  67. package/dist/links/httpBatchLink.d.mts.map +1 -0
  68. package/dist/links/httpBatchLink.d.ts +14 -4
  69. package/dist/links/httpBatchLink.d.ts.map +1 -1
  70. package/dist/links/httpBatchLink.js +90 -106
  71. package/dist/links/httpBatchLink.mjs +89 -103
  72. package/dist/links/httpBatchLink.mjs.map +1 -0
  73. package/dist/links/httpBatchStreamLink.d.mts +22 -0
  74. package/dist/links/httpBatchStreamLink.d.mts.map +1 -0
  75. package/dist/links/httpBatchStreamLink.d.ts +15 -5
  76. package/dist/links/httpBatchStreamLink.d.ts.map +1 -1
  77. package/dist/links/httpBatchStreamLink.js +120 -144
  78. package/dist/links/httpBatchStreamLink.mjs +119 -141
  79. package/dist/links/httpBatchStreamLink.mjs.map +1 -0
  80. package/dist/links/httpLink.d.mts +24 -0
  81. package/dist/links/httpLink.d.mts.map +1 -0
  82. package/dist/links/httpLink.d.ts +19 -12
  83. package/dist/links/httpLink.d.ts.map +1 -1
  84. package/dist/links/httpLink.js +74 -90
  85. package/dist/links/httpLink.mjs +73 -87
  86. package/dist/links/httpLink.mjs.map +1 -0
  87. package/dist/links/httpSubscriptionLink.d.mts +30 -0
  88. package/dist/links/httpSubscriptionLink.d.mts.map +1 -0
  89. package/dist/links/httpSubscriptionLink.d.ts +21 -17
  90. package/dist/links/httpSubscriptionLink.d.ts.map +1 -1
  91. package/dist/links/httpSubscriptionLink.js +134 -179
  92. package/dist/links/httpSubscriptionLink.mjs +133 -176
  93. package/dist/links/httpSubscriptionLink.mjs.map +1 -0
  94. package/dist/links/internals/contentTypes.d.mts +10 -0
  95. package/dist/links/internals/contentTypes.d.mts.map +1 -0
  96. package/dist/links/internals/contentTypes.d.ts +9 -3
  97. package/dist/links/internals/contentTypes.d.ts.map +1 -1
  98. package/dist/links/internals/contentTypes.js +6 -6
  99. package/dist/links/internals/contentTypes.mjs +6 -4
  100. package/dist/links/internals/contentTypes.mjs.map +1 -0
  101. package/dist/links/internals/createChain.js +23 -23
  102. package/dist/links/internals/createChain.mjs +22 -20
  103. package/dist/links/internals/createChain.mjs.map +1 -0
  104. package/dist/links/internals/httpUtils.d.mts +26 -0
  105. package/dist/links/internals/httpUtils.d.mts.map +1 -0
  106. package/dist/links/internals/httpUtils.d.ts +22 -64
  107. package/dist/links/internals/httpUtils.d.ts.map +1 -1
  108. package/dist/links/internals/httpUtils.js +93 -116
  109. package/dist/links/internals/httpUtils.mjs +94 -113
  110. package/dist/links/internals/httpUtils.mjs.map +1 -0
  111. package/dist/links/internals/subscriptions.d.mts +20 -0
  112. package/dist/links/internals/subscriptions.d.mts.map +1 -0
  113. package/dist/links/internals/subscriptions.d.ts +11 -8
  114. package/dist/links/internals/subscriptions.d.ts.map +1 -1
  115. package/dist/links/internals/urlWithConnectionParams.d.mts +27 -0
  116. package/dist/links/internals/urlWithConnectionParams.d.mts.map +1 -0
  117. package/dist/links/internals/urlWithConnectionParams.d.ts +22 -18
  118. package/dist/links/internals/urlWithConnectionParams.d.ts.map +1 -1
  119. package/dist/links/internals/urlWithConnectionParams.js +8 -6
  120. package/dist/links/internals/urlWithConnectionParams.mjs +8 -4
  121. package/dist/links/internals/urlWithConnectionParams.mjs.map +1 -0
  122. package/dist/links/localLink.d.mts +22 -0
  123. package/dist/links/localLink.d.mts.map +1 -0
  124. package/dist/links/localLink.d.ts +22 -0
  125. package/dist/links/localLink.d.ts.map +1 -0
  126. package/dist/links/localLink.js +192 -0
  127. package/dist/links/localLink.mjs +193 -0
  128. package/dist/links/localLink.mjs.map +1 -0
  129. package/dist/links/loggerLink.d.mts +56 -0
  130. package/dist/links/loggerLink.d.mts.map +1 -0
  131. package/dist/links/loggerLink.d.ts +40 -36
  132. package/dist/links/loggerLink.d.ts.map +1 -1
  133. package/dist/links/loggerLink.js +113 -166
  134. package/dist/links/loggerLink.mjs +112 -163
  135. package/dist/links/loggerLink.mjs.map +1 -0
  136. package/dist/links/retryLink.d.mts +35 -0
  137. package/dist/links/retryLink.d.mts.map +1 -0
  138. package/dist/links/retryLink.d.ts +27 -25
  139. package/dist/links/retryLink.d.ts.map +1 -1
  140. package/dist/links/retryLink.js +60 -68
  141. package/dist/links/retryLink.mjs +59 -65
  142. package/dist/links/retryLink.mjs.map +1 -0
  143. package/dist/links/splitLink.d.mts +21 -0
  144. package/dist/links/splitLink.d.mts.map +1 -0
  145. package/dist/links/splitLink.d.ts +19 -12
  146. package/dist/links/splitLink.d.ts.map +1 -1
  147. package/dist/links/splitLink.js +20 -21
  148. package/dist/links/splitLink.mjs +19 -18
  149. package/dist/links/splitLink.mjs.map +1 -0
  150. package/dist/links/types.d.mts +71 -0
  151. package/dist/links/types.d.mts.map +1 -0
  152. package/dist/links/types.d.ts +37 -29
  153. package/dist/links/types.d.ts.map +1 -1
  154. package/dist/links/wsLink/createWsClient.d.mts +10 -0
  155. package/dist/links/wsLink/createWsClient.d.mts.map +1 -0
  156. package/dist/links/wsLink/createWsClient.d.ts +9 -5
  157. package/dist/links/wsLink/createWsClient.d.ts.map +1 -1
  158. package/dist/links/wsLink/createWsClient.js +5 -5
  159. package/dist/links/wsLink/createWsClient.mjs +5 -2
  160. package/dist/links/wsLink/createWsClient.mjs.map +1 -0
  161. package/dist/links/wsLink/wsClient/options.d.mts +69 -0
  162. package/dist/links/wsLink/wsClient/options.d.mts.map +1 -0
  163. package/dist/links/wsLink/wsClient/options.d.ts +54 -64
  164. package/dist/links/wsLink/wsClient/options.d.ts.map +1 -1
  165. package/dist/links/wsLink/wsClient/options.js +14 -12
  166. package/dist/links/wsLink/wsClient/options.mjs +14 -10
  167. package/dist/links/wsLink/wsClient/options.mjs.map +1 -0
  168. package/dist/links/wsLink/wsClient/requestManager.js +133 -135
  169. package/dist/links/wsLink/wsClient/requestManager.mjs +133 -132
  170. package/dist/links/wsLink/wsClient/requestManager.mjs.map +1 -0
  171. package/dist/links/wsLink/wsClient/utils.js +64 -81
  172. package/dist/links/wsLink/wsClient/utils.mjs +64 -78
  173. package/dist/links/wsLink/wsClient/utils.mjs.map +1 -0
  174. package/dist/links/wsLink/wsClient/wsClient.d.mts +104 -0
  175. package/dist/links/wsLink/wsClient/wsClient.d.mts.map +1 -0
  176. package/dist/links/wsLink/wsClient/wsClient.d.ts +99 -79
  177. package/dist/links/wsLink/wsClient/wsClient.d.ts.map +1 -1
  178. package/dist/links/wsLink/wsClient/wsClient.js +273 -322
  179. package/dist/links/wsLink/wsClient/wsClient.mjs +272 -319
  180. package/dist/links/wsLink/wsClient/wsClient.mjs.map +1 -0
  181. package/dist/links/wsLink/wsClient/wsConnection.js +155 -178
  182. package/dist/links/wsLink/wsClient/wsConnection.mjs +154 -175
  183. package/dist/links/wsLink/wsClient/wsConnection.mjs.map +1 -0
  184. package/dist/links/wsLink/wsLink.d.mts +15 -0
  185. package/dist/links/wsLink/wsLink.d.mts.map +1 -0
  186. package/dist/links/wsLink/wsLink.d.ts +13 -9
  187. package/dist/links/wsLink/wsLink.d.ts.map +1 -1
  188. package/dist/links/wsLink/wsLink.js +30 -31
  189. package/dist/links/wsLink/wsLink.mjs +29 -28
  190. package/dist/links/wsLink/wsLink.mjs.map +1 -0
  191. package/dist/links.js +11 -0
  192. package/dist/links.mjs +11 -0
  193. package/dist/node_modules/.pnpm/@oxc-project_runtime@0.71.0/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js +68 -0
  194. package/dist/node_modules/.pnpm/@oxc-project_runtime@0.71.0/node_modules/@oxc-project/runtime/src/helpers/usingCtx.mjs +66 -0
  195. package/dist/node_modules/.pnpm/@oxc-project_runtime@0.71.0/node_modules/@oxc-project/runtime/src/helpers/usingCtx.mjs.map +1 -0
  196. package/dist/unstable-internals.d.mts +3 -0
  197. package/dist/unstable-internals.d.ts +3 -3
  198. package/dist/unstable-internals.js +2 -6
  199. package/dist/unstable-internals.mjs +3 -1
  200. package/links/httpBatchLink/package.json +1 -0
  201. package/links/httpLink/package.json +1 -0
  202. package/links/loggerLink/package.json +1 -0
  203. package/links/splitLink/package.json +1 -0
  204. package/links/wsLink/wsLink/package.json +1 -0
  205. package/package.json +64 -29
  206. package/src/TRPCClientError.ts +4 -9
  207. package/src/internals/dataLoader.ts +2 -6
  208. package/src/internals/signals.ts +16 -0
  209. package/src/links/httpSubscriptionLink.ts +3 -18
  210. package/src/links/localLink.ts +277 -0
  211. package/src/links/wsLink/wsClient/requestManager.ts +9 -0
  212. package/src/links/wsLink/wsClient/wsClient.ts +1 -1
  213. package/src/links.ts +1 -0
  214. package/unstable-internals/package.json +1 -0
  215. package/dist/index.d.ts.map +0 -1
  216. package/dist/internals/dataLoader.d.ts +0 -13
  217. package/dist/internals/dataLoader.d.ts.map +0 -1
  218. package/dist/internals/inputWithTrackedEventId.d.ts +0 -2
  219. package/dist/internals/inputWithTrackedEventId.d.ts.map +0 -1
  220. package/dist/internals/signals.d.ts +0 -15
  221. package/dist/internals/signals.d.ts.map +0 -1
  222. package/dist/links/internals/createChain.d.ts +0 -8
  223. package/dist/links/internals/createChain.d.ts.map +0 -1
  224. package/dist/links/internals/dedupeLink.d.ts +0 -7
  225. package/dist/links/internals/dedupeLink.d.ts.map +0 -1
  226. package/dist/links/wsLink/wsClient/requestManager.d.ts +0 -102
  227. package/dist/links/wsLink/wsClient/requestManager.d.ts.map +0 -1
  228. package/dist/links/wsLink/wsClient/utils.d.ts +0 -38
  229. package/dist/links/wsLink/wsClient/utils.d.ts.map +0 -1
  230. package/dist/links/wsLink/wsClient/wsConnection.d.ts +0 -79
  231. package/dist/links/wsLink/wsClient/wsConnection.d.ts.map +0 -1
  232. package/dist/links.d.ts +0 -11
  233. package/dist/links.d.ts.map +0 -1
  234. package/dist/unstable-internals.d.ts.map +0 -1
@@ -1,110 +1,94 @@
1
- 'use strict';
2
-
3
- var observable = require('@trpc/server/observable');
4
- var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import');
5
- var dataLoader = require('../internals/dataLoader.js');
6
- var signals = require('../internals/signals.js');
7
- var TRPCClientError = require('../TRPCClientError.js');
8
- var httpUtils = require('./internals/httpUtils.js');
1
+ const require_rolldown_runtime = require('../_virtual/rolldown_runtime.js');
2
+ const require__Users_julius_dev_trpc_packages_client_src_TRPCClientError = require('../TRPCClientError.js');
3
+ const require__Users_julius_dev_trpc_packages_client_src_internals_dataLoader = require('../internals/dataLoader.js');
4
+ const require__Users_julius_dev_trpc_packages_client_src_internals_signals = require('../internals/signals.js');
5
+ const require__Users_julius_dev_trpc_packages_client_src_links_internals_httpUtils = require('./internals/httpUtils.js');
6
+ const __trpc_server_observable = require_rolldown_runtime.__toESM(require("@trpc/server/observable"));
7
+ const __trpc_server_unstable_core_do_not_import = require_rolldown_runtime.__toESM(require("@trpc/server/unstable-core-do-not-import"));
9
8
 
9
+ //#region src/links/httpBatchLink.ts
10
10
  /**
11
- * @see https://trpc.io/docs/client/links/httpBatchLink
12
- */ function httpBatchLink(opts) {
13
- const resolvedOpts = httpUtils.resolveHTTPLinkOptions(opts);
14
- const maxURLLength = opts.maxURLLength ?? Infinity;
15
- const maxItems = opts.maxItems ?? Infinity;
16
- return ()=>{
17
- const batchLoader = (type)=>{
18
- return {
19
- validate (batchOps) {
20
- if (maxURLLength === Infinity && maxItems === Infinity) {
21
- // escape hatch for quick calcs
22
- return true;
23
- }
24
- if (batchOps.length > maxItems) {
25
- return false;
26
- }
27
- const path = batchOps.map((op)=>op.path).join(',');
28
- const inputs = batchOps.map((op)=>op.input);
29
- const url = httpUtils.getUrl({
30
- ...resolvedOpts,
31
- type,
32
- path,
33
- inputs,
34
- signal: null
35
- });
36
- return url.length <= maxURLLength;
37
- },
38
- async fetch (batchOps) {
39
- const path = batchOps.map((op)=>op.path).join(',');
40
- const inputs = batchOps.map((op)=>op.input);
41
- const signal = signals.allAbortSignals(...batchOps.map((op)=>op.signal));
42
- const res = await httpUtils.jsonHttpRequester({
43
- ...resolvedOpts,
44
- path,
45
- inputs,
46
- type,
47
- headers () {
48
- if (!opts.headers) {
49
- return {};
50
- }
51
- if (typeof opts.headers === 'function') {
52
- return opts.headers({
53
- opList: batchOps
54
- });
55
- }
56
- return opts.headers;
57
- },
58
- signal
59
- });
60
- const resJSON = Array.isArray(res.json) ? res.json : batchOps.map(()=>res.json);
61
- const result = resJSON.map((item)=>({
62
- meta: res.meta,
63
- json: item
64
- }));
65
- return result;
66
- }
67
- };
68
- };
69
- const query = dataLoader.dataLoader(batchLoader('query'));
70
- const mutation = dataLoader.dataLoader(batchLoader('mutation'));
71
- const loaders = {
72
- query,
73
- mutation
74
- };
75
- return ({ op })=>{
76
- return observable.observable((observer)=>{
77
- /* istanbul ignore if -- @preserve */ if (op.type === 'subscription') {
78
- throw new Error('Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`');
79
- }
80
- const loader = loaders[op.type];
81
- const promise = loader.load(op);
82
- let _res = undefined;
83
- promise.then((res)=>{
84
- _res = res;
85
- const transformed = unstableCoreDoNotImport.transformResult(res.json, resolvedOpts.transformer.output);
86
- if (!transformed.ok) {
87
- observer.error(TRPCClientError.TRPCClientError.from(transformed.error, {
88
- meta: res.meta
89
- }));
90
- return;
91
- }
92
- observer.next({
93
- context: res.meta,
94
- result: transformed.result
95
- });
96
- observer.complete();
97
- }).catch((err)=>{
98
- observer.error(TRPCClientError.TRPCClientError.from(err, {
99
- meta: _res?.meta
100
- }));
101
- });
102
- return ()=>{
103
- // noop
104
- };
105
- });
106
- };
107
- };
11
+ * @see https://trpc.io/docs/client/links/httpBatchLink
12
+ */
13
+ function httpBatchLink(opts) {
14
+ const resolvedOpts = require__Users_julius_dev_trpc_packages_client_src_links_internals_httpUtils.resolveHTTPLinkOptions(opts);
15
+ const maxURLLength = opts.maxURLLength ?? Infinity;
16
+ const maxItems = opts.maxItems ?? Infinity;
17
+ return () => {
18
+ const batchLoader = (type) => {
19
+ return {
20
+ validate(batchOps) {
21
+ if (maxURLLength === Infinity && maxItems === Infinity) return true;
22
+ if (batchOps.length > maxItems) return false;
23
+ const path = batchOps.map((op) => op.path).join(",");
24
+ const inputs = batchOps.map((op) => op.input);
25
+ const url = require__Users_julius_dev_trpc_packages_client_src_links_internals_httpUtils.getUrl({
26
+ ...resolvedOpts,
27
+ type,
28
+ path,
29
+ inputs,
30
+ signal: null
31
+ });
32
+ return url.length <= maxURLLength;
33
+ },
34
+ async fetch(batchOps) {
35
+ const path = batchOps.map((op) => op.path).join(",");
36
+ const inputs = batchOps.map((op) => op.input);
37
+ const signal = require__Users_julius_dev_trpc_packages_client_src_internals_signals.allAbortSignals(...batchOps.map((op) => op.signal));
38
+ const res = await require__Users_julius_dev_trpc_packages_client_src_links_internals_httpUtils.jsonHttpRequester({
39
+ ...resolvedOpts,
40
+ path,
41
+ inputs,
42
+ type,
43
+ headers() {
44
+ if (!opts.headers) return {};
45
+ if (typeof opts.headers === "function") return opts.headers({ opList: batchOps });
46
+ return opts.headers;
47
+ },
48
+ signal
49
+ });
50
+ const resJSON = Array.isArray(res.json) ? res.json : batchOps.map(() => res.json);
51
+ const result = resJSON.map((item) => ({
52
+ meta: res.meta,
53
+ json: item
54
+ }));
55
+ return result;
56
+ }
57
+ };
58
+ };
59
+ const query = require__Users_julius_dev_trpc_packages_client_src_internals_dataLoader.dataLoader(batchLoader("query"));
60
+ const mutation = require__Users_julius_dev_trpc_packages_client_src_internals_dataLoader.dataLoader(batchLoader("mutation"));
61
+ const loaders = {
62
+ query,
63
+ mutation
64
+ };
65
+ return ({ op }) => {
66
+ return (0, __trpc_server_observable.observable)((observer) => {
67
+ /* istanbul ignore if -- @preserve */
68
+ if (op.type === "subscription") throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`");
69
+ const loader = loaders[op.type];
70
+ const promise = loader.load(op);
71
+ let _res = void 0;
72
+ promise.then((res) => {
73
+ _res = res;
74
+ const transformed = (0, __trpc_server_unstable_core_do_not_import.transformResult)(res.json, resolvedOpts.transformer.output);
75
+ if (!transformed.ok) {
76
+ observer.error(require__Users_julius_dev_trpc_packages_client_src_TRPCClientError.TRPCClientError.from(transformed.error, { meta: res.meta }));
77
+ return;
78
+ }
79
+ observer.next({
80
+ context: res.meta,
81
+ result: transformed.result
82
+ });
83
+ observer.complete();
84
+ }).catch((err) => {
85
+ observer.error(require__Users_julius_dev_trpc_packages_client_src_TRPCClientError.TRPCClientError.from(err, { meta: _res?.meta }));
86
+ });
87
+ return () => {};
88
+ });
89
+ };
90
+ };
108
91
  }
109
92
 
110
- exports.httpBatchLink = httpBatchLink;
93
+ //#endregion
94
+ exports.httpBatchLink = httpBatchLink;
@@ -1,108 +1,94 @@
1
- import { observable } from '@trpc/server/observable';
2
- import { transformResult } from '@trpc/server/unstable-core-do-not-import';
3
- import { dataLoader } from '../internals/dataLoader.mjs';
4
- import { allAbortSignals } from '../internals/signals.mjs';
5
- import { TRPCClientError } from '../TRPCClientError.mjs';
6
- import { resolveHTTPLinkOptions, jsonHttpRequester, getUrl } from './internals/httpUtils.mjs';
1
+ import { TRPCClientError } from "../TRPCClientError.mjs";
2
+ import { dataLoader } from "../internals/dataLoader.mjs";
3
+ import { allAbortSignals } from "../internals/signals.mjs";
4
+ import { getUrl, jsonHttpRequester, resolveHTTPLinkOptions } from "./internals/httpUtils.mjs";
5
+ import { observable } from "@trpc/server/observable";
6
+ import { transformResult } from "@trpc/server/unstable-core-do-not-import";
7
7
 
8
+ //#region src/links/httpBatchLink.ts
8
9
  /**
9
- * @see https://trpc.io/docs/client/links/httpBatchLink
10
- */ function httpBatchLink(opts) {
11
- const resolvedOpts = resolveHTTPLinkOptions(opts);
12
- const maxURLLength = opts.maxURLLength ?? Infinity;
13
- const maxItems = opts.maxItems ?? Infinity;
14
- return ()=>{
15
- const batchLoader = (type)=>{
16
- return {
17
- validate (batchOps) {
18
- if (maxURLLength === Infinity && maxItems === Infinity) {
19
- // escape hatch for quick calcs
20
- return true;
21
- }
22
- if (batchOps.length > maxItems) {
23
- return false;
24
- }
25
- const path = batchOps.map((op)=>op.path).join(',');
26
- const inputs = batchOps.map((op)=>op.input);
27
- const url = getUrl({
28
- ...resolvedOpts,
29
- type,
30
- path,
31
- inputs,
32
- signal: null
33
- });
34
- return url.length <= maxURLLength;
35
- },
36
- async fetch (batchOps) {
37
- const path = batchOps.map((op)=>op.path).join(',');
38
- const inputs = batchOps.map((op)=>op.input);
39
- const signal = allAbortSignals(...batchOps.map((op)=>op.signal));
40
- const res = await jsonHttpRequester({
41
- ...resolvedOpts,
42
- path,
43
- inputs,
44
- type,
45
- headers () {
46
- if (!opts.headers) {
47
- return {};
48
- }
49
- if (typeof opts.headers === 'function') {
50
- return opts.headers({
51
- opList: batchOps
52
- });
53
- }
54
- return opts.headers;
55
- },
56
- signal
57
- });
58
- const resJSON = Array.isArray(res.json) ? res.json : batchOps.map(()=>res.json);
59
- const result = resJSON.map((item)=>({
60
- meta: res.meta,
61
- json: item
62
- }));
63
- return result;
64
- }
65
- };
66
- };
67
- const query = dataLoader(batchLoader('query'));
68
- const mutation = dataLoader(batchLoader('mutation'));
69
- const loaders = {
70
- query,
71
- mutation
72
- };
73
- return ({ op })=>{
74
- return observable((observer)=>{
75
- /* istanbul ignore if -- @preserve */ if (op.type === 'subscription') {
76
- throw new Error('Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`');
77
- }
78
- const loader = loaders[op.type];
79
- const promise = loader.load(op);
80
- let _res = undefined;
81
- promise.then((res)=>{
82
- _res = res;
83
- const transformed = transformResult(res.json, resolvedOpts.transformer.output);
84
- if (!transformed.ok) {
85
- observer.error(TRPCClientError.from(transformed.error, {
86
- meta: res.meta
87
- }));
88
- return;
89
- }
90
- observer.next({
91
- context: res.meta,
92
- result: transformed.result
93
- });
94
- observer.complete();
95
- }).catch((err)=>{
96
- observer.error(TRPCClientError.from(err, {
97
- meta: _res?.meta
98
- }));
99
- });
100
- return ()=>{
101
- // noop
102
- };
103
- });
104
- };
105
- };
10
+ * @see https://trpc.io/docs/client/links/httpBatchLink
11
+ */
12
+ function httpBatchLink(opts) {
13
+ const resolvedOpts = resolveHTTPLinkOptions(opts);
14
+ const maxURLLength = opts.maxURLLength ?? Infinity;
15
+ const maxItems = opts.maxItems ?? Infinity;
16
+ return () => {
17
+ const batchLoader = (type) => {
18
+ return {
19
+ validate(batchOps) {
20
+ if (maxURLLength === Infinity && maxItems === Infinity) return true;
21
+ if (batchOps.length > maxItems) return false;
22
+ const path = batchOps.map((op) => op.path).join(",");
23
+ const inputs = batchOps.map((op) => op.input);
24
+ const url = getUrl({
25
+ ...resolvedOpts,
26
+ type,
27
+ path,
28
+ inputs,
29
+ signal: null
30
+ });
31
+ return url.length <= maxURLLength;
32
+ },
33
+ async fetch(batchOps) {
34
+ const path = batchOps.map((op) => op.path).join(",");
35
+ const inputs = batchOps.map((op) => op.input);
36
+ const signal = allAbortSignals(...batchOps.map((op) => op.signal));
37
+ const res = await jsonHttpRequester({
38
+ ...resolvedOpts,
39
+ path,
40
+ inputs,
41
+ type,
42
+ headers() {
43
+ if (!opts.headers) return {};
44
+ if (typeof opts.headers === "function") return opts.headers({ opList: batchOps });
45
+ return opts.headers;
46
+ },
47
+ signal
48
+ });
49
+ const resJSON = Array.isArray(res.json) ? res.json : batchOps.map(() => res.json);
50
+ const result = resJSON.map((item) => ({
51
+ meta: res.meta,
52
+ json: item
53
+ }));
54
+ return result;
55
+ }
56
+ };
57
+ };
58
+ const query = dataLoader(batchLoader("query"));
59
+ const mutation = dataLoader(batchLoader("mutation"));
60
+ const loaders = {
61
+ query,
62
+ mutation
63
+ };
64
+ return ({ op }) => {
65
+ return observable((observer) => {
66
+ /* istanbul ignore if -- @preserve */
67
+ if (op.type === "subscription") throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`");
68
+ const loader = loaders[op.type];
69
+ const promise = loader.load(op);
70
+ let _res = void 0;
71
+ promise.then((res) => {
72
+ _res = res;
73
+ const transformed = transformResult(res.json, resolvedOpts.transformer.output);
74
+ if (!transformed.ok) {
75
+ observer.error(TRPCClientError.from(transformed.error, { meta: res.meta }));
76
+ return;
77
+ }
78
+ observer.next({
79
+ context: res.meta,
80
+ result: transformed.result
81
+ });
82
+ observer.complete();
83
+ }).catch((err) => {
84
+ observer.error(TRPCClientError.from(err, { meta: _res?.meta }));
85
+ });
86
+ return () => {};
87
+ });
88
+ };
89
+ };
106
90
  }
107
91
 
92
+ //#endregion
108
93
  export { httpBatchLink };
94
+ //# sourceMappingURL=httpBatchLink.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpBatchLink.mjs","names":["opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>","type: ProcedureType"],"sources":["../../src/links/httpBatchLink.ts"],"sourcesContent":["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,SAAgB,cACdA,MACmB;CACnB,MAAM,eAAe,uBAAuB,KAAK;CACjD,MAAM,eAAe,KAAK,gBAAgB;CAC1C,MAAM,WAAW,KAAK,YAAY;AAElC,QAAO,MAAM;EACX,MAAM,cAAc,CAClBC,SACuC;AACvC,UAAO;IACL,SAAS,UAAU;AACjB,SAAI,iBAAiB,YAAY,aAAa,SAE5C,QAAO;AAET,SAAI,SAAS,SAAS,SACpB,QAAO;KAET,MAAM,OAAO,SAAS,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,IAAI;KACpD,MAAM,SAAS,SAAS,IAAI,CAAC,OAAO,GAAG,MAAM;KAE7C,MAAM,MAAM,OAAO;MACjB,GAAG;MACH;MACA;MACA;MACA,QAAQ;KACT,EAAC;AAEF,YAAO,IAAI,UAAU;IACtB;IACD,MAAM,MAAM,UAAU;KACpB,MAAM,OAAO,SAAS,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC,KAAK,IAAI;KACpD,MAAM,SAAS,SAAS,IAAI,CAAC,OAAO,GAAG,MAAM;KAC7C,MAAM,SAAS,gBAAgB,GAAG,SAAS,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;KAElE,MAAM,MAAM,MAAM,kBAAkB;MAClC,GAAG;MACH;MACA;MACA;MACA,UAAU;AACR,YAAK,KAAK,QACR,QAAO,CAAE;AAEX,kBAAW,KAAK,YAAY,WAC1B,QAAO,KAAK,QAAQ,EAClB,QAAQ,SACT,EAAC;AAEJ,cAAO,KAAK;MACb;MACD;KACD,EAAC;KACF,MAAM,UAAU,MAAM,QAAQ,IAAI,KAAK,GACnC,IAAI,OACJ,SAAS,IAAI,MAAM,IAAI,KAAK;KAChC,MAAM,SAAS,QAAQ,IAAI,CAAC,UAAU;MACpC,MAAM,IAAI;MACV,MAAM;KACP,GAAE;AACH,YAAO;IACR;GACF;EACF;EAED,MAAM,QAAQ,WAAW,YAAY,QAAQ,CAAC;EAC9C,MAAM,WAAW,WAAW,YAAY,WAAW,CAAC;EAEpD,MAAM,UAAU;GAAE;GAAO;EAAU;AACnC,SAAO,CAAC,EAAE,IAAI,KAAK;AACjB,UAAO,WAAW,CAAC,aAAa;;AAE9B,QAAI,GAAG,SAAS,eACd,OAAM,IAAI,MACR;IAGJ,MAAM,SAAS,QAAQ,GAAG;IAC1B,MAAM,UAAU,OAAO,KAAK,GAAG;IAE/B,IAAI;AACJ,YACG,KAAK,CAAC,QAAQ;AACb,YAAO;KACP,MAAM,cAAc,gBAClB,IAAI,MACJ,aAAa,YAAY,OAC1B;AAED,UAAK,YAAY,IAAI;AACnB,eAAS,MACP,gBAAgB,KAAK,YAAY,OAAO,EACtC,MAAM,IAAI,KACX,EAAC,CACH;AACD;KACD;AACD,cAAS,KAAK;MACZ,SAAS,IAAI;MACb,QAAQ,YAAY;KACrB,EAAC;AACF,cAAS,UAAU;IACpB,EAAC,CACD,MAAM,CAAC,QAAQ;AACd,cAAS,MACP,gBAAgB,KAAK,KAAK,EACxB,MAAM,MAAM,KACb,EAAC,CACH;IACF,EAAC;AAEJ,WAAO,MAAM,CAEZ;GACF,EAAC;EACH;CACF;AACF"}
@@ -0,0 +1,22 @@
1
+ import { TRPCLink } from "./types.mjs";
2
+ import { HTTPBatchLinkOptions } from "./HTTPBatchLinkOptions.mjs";
3
+ import { AnyRouter } from "@trpc/server";
4
+
5
+ //#region src/links/httpBatchStreamLink.d.ts
6
+ /**
7
+ * @see https://trpc.io/docs/client/links/httpBatchStreamLink
8
+ */
9
+ /**
10
+ * @see https://trpc.io/docs/client/links/httpBatchStreamLink
11
+ */
12
+ declare function httpBatchStreamLink<TRouter extends AnyRouter>(opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
13
+ /**
14
+ * @deprecated use {@link httpBatchStreamLink} instead
15
+ */
16
+ declare const unstable_httpBatchStreamLink: typeof httpBatchStreamLink;
17
+
18
+ //#endregion
19
+ //# sourceMappingURL=httpBatchStreamLink.d.ts.map
20
+
21
+ export { httpBatchStreamLink as httpBatchStreamLink$1, unstable_httpBatchStreamLink as unstable_httpBatchStreamLink$1 };
22
+ //# sourceMappingURL=httpBatchStreamLink.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpBatchStreamLink.d.mts","names":[],"sources":["../../src/links/httpBatchStreamLink.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;iBAsBgB,oCAAoC,iBAC5C,qBAAqB,wCAC1B,SAAS;;AAFZ;;AAAoD,cAuKvC,4BAvKuC,EAAA,OAuKX,mBAvKW"}
@@ -1,12 +1,22 @@
1
- import type { AnyRouter } from '@trpc/server';
2
- import type { HTTPBatchLinkOptions } from './HTTPBatchLinkOptions';
3
- import type { TRPCLink } from './types';
1
+ import { TRPCLink } from "./types.js";
2
+ import { HTTPBatchLinkOptions } from "./HTTPBatchLinkOptions.js";
3
+ import { AnyRouter } from "@trpc/server";
4
+
5
+ //#region src/links/httpBatchStreamLink.d.ts
6
+ /**
7
+ * @see https://trpc.io/docs/client/links/httpBatchStreamLink
8
+ */
4
9
  /**
5
10
  * @see https://trpc.io/docs/client/links/httpBatchStreamLink
6
11
  */
7
- export declare function httpBatchStreamLink<TRouter extends AnyRouter>(opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
12
+ declare function httpBatchStreamLink<TRouter extends AnyRouter>(opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
8
13
  /**
9
14
  * @deprecated use {@link httpBatchStreamLink} instead
10
15
  */
11
- export declare const unstable_httpBatchStreamLink: typeof httpBatchStreamLink;
16
+ declare const unstable_httpBatchStreamLink: typeof httpBatchStreamLink;
17
+
18
+ //#endregion
19
+ //# sourceMappingURL=httpBatchStreamLink.d.ts.map
20
+
21
+ export { httpBatchStreamLink, unstable_httpBatchStreamLink };
12
22
  //# sourceMappingURL=httpBatchStreamLink.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"httpBatchStreamLink.d.ts","sourceRoot":"","sources":["../../src/links/httpBatchStreamLink.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAiB,MAAM,cAAc,CAAC;AAS7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAQnE,OAAO,KAAK,EAAa,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnD;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,SAAS,SAAS,EAC3D,IAAI,EAAE,oBAAoB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,GAC/D,QAAQ,CAAC,OAAO,CAAC,CAgKnB;AAED;;GAEG;AACH,eAAO,MAAM,4BAA4B,4BAAsB,CAAC"}
1
+ {"version":3,"file":"httpBatchStreamLink.d.ts","names":[],"sources":["../../src/links/httpBatchStreamLink.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;iBAsBgB,oCAAoC,iBAC5C,qBAAqB,wCAC1B,SAAS;;AAFZ;;AAAoD,cAuKvC,4BAvKuC,EAAA,OAuKX,mBAvKW"}