@trpc/client 11.0.0-rc.373 → 11.0.0-rc.374

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 (47) hide show
  1. package/dist/bundle-analysis.json +60 -106
  2. package/dist/index.js +0 -1
  3. package/dist/index.mjs +1 -1
  4. package/dist/internals/dataLoader.d.ts +3 -4
  5. package/dist/internals/dataLoader.d.ts.map +1 -1
  6. package/dist/internals/dataLoader.js +14 -13
  7. package/dist/internals/dataLoader.mjs +14 -13
  8. package/dist/links/httpBatchLink.d.ts +6 -1
  9. package/dist/links/httpBatchLink.d.ts.map +1 -1
  10. package/dist/links/httpBatchLink.js +95 -30
  11. package/dist/links/httpBatchLink.mjs +96 -31
  12. package/dist/links/httpBatchStreamLink.d.ts +9 -6
  13. package/dist/links/httpBatchStreamLink.d.ts.map +1 -1
  14. package/dist/links/httpBatchStreamLink.js +132 -34
  15. package/dist/links/httpBatchStreamLink.mjs +132 -34
  16. package/dist/links/httpLink.d.ts +4 -7
  17. package/dist/links/httpLink.d.ts.map +1 -1
  18. package/dist/links/httpLink.js +72 -46
  19. package/dist/links/httpLink.mjs +74 -47
  20. package/dist/links/internals/httpUtils.d.ts +2 -4
  21. package/dist/links/internals/httpUtils.d.ts.map +1 -1
  22. package/dist/links/internals/httpUtils.js +4 -32
  23. package/dist/links/internals/httpUtils.mjs +4 -32
  24. package/package.json +4 -4
  25. package/src/internals/dataLoader.ts +21 -19
  26. package/src/links/httpBatchLink.ts +132 -46
  27. package/src/links/httpBatchStreamLink.ts +173 -48
  28. package/src/links/httpLink.ts +100 -60
  29. package/src/links/internals/httpUtils.ts +5 -41
  30. package/dist/links/internals/createHTTPBatchLink.d.ts +0 -20
  31. package/dist/links/internals/createHTTPBatchLink.d.ts.map +0 -1
  32. package/dist/links/internals/createHTTPBatchLink.js +0 -85
  33. package/dist/links/internals/createHTTPBatchLink.mjs +0 -83
  34. package/dist/links/internals/getTextDecoder.d.ts +0 -3
  35. package/dist/links/internals/getTextDecoder.d.ts.map +0 -1
  36. package/dist/links/internals/getTextDecoder.js +0 -16
  37. package/dist/links/internals/getTextDecoder.mjs +0 -14
  38. package/dist/links/internals/parseJSONStream.d.ts +0 -39
  39. package/dist/links/internals/parseJSONStream.d.ts.map +0 -1
  40. package/dist/links/internals/parseJSONStream.js +0 -118
  41. package/dist/links/internals/parseJSONStream.mjs +0 -115
  42. package/dist/links/internals/streamingUtils.d.ts +0 -7
  43. package/dist/links/internals/streamingUtils.d.ts.map +0 -1
  44. package/src/links/internals/createHTTPBatchLink.ts +0 -133
  45. package/src/links/internals/getTextDecoder.ts +0 -19
  46. package/src/links/internals/parseJSONStream.ts +0 -166
  47. package/src/links/internals/streamingUtils.ts +0 -6
@@ -1,7 +1,7 @@
1
1
  {
2
- "bundleSize": 46894,
3
- "bundleOrigSize": 66367,
4
- "bundleReduction": 29.34,
2
+ "bundleSize": 46599,
3
+ "bundleOrigSize": 63289,
4
+ "bundleReduction": 26.37,
5
5
  "modules": [
6
6
  {
7
7
  "id": "/src/links/wsLink.ts",
@@ -13,9 +13,21 @@
13
13
  ],
14
14
  "removedExports": [],
15
15
  "dependents": [],
16
- "percent": 25.71,
16
+ "percent": 25.88,
17
17
  "reduction": 11.68
18
18
  },
19
+ {
20
+ "id": "/src/links/httpBatchStreamLink.ts",
21
+ "size": 5776,
22
+ "origSize": 6023,
23
+ "renderedExports": [
24
+ "unstable_httpBatchStreamLink"
25
+ ],
26
+ "removedExports": [],
27
+ "dependents": [],
28
+ "percent": 12.4,
29
+ "reduction": 4.1
30
+ },
19
31
  {
20
32
  "id": "/src/links/loggerLink.ts",
21
33
  "size": 5457,
@@ -25,33 +37,46 @@
25
37
  ],
26
38
  "removedExports": [],
27
39
  "dependents": [],
28
- "percent": 11.64,
40
+ "percent": 11.71,
29
41
  "reduction": 18.48
30
42
  },
31
43
  {
32
44
  "id": "/src/internals/dataLoader.ts",
33
- "size": 4409,
34
- "origSize": 4766,
45
+ "size": 4504,
46
+ "origSize": 4809,
35
47
  "renderedExports": [
36
48
  "dataLoader"
37
49
  ],
38
50
  "removedExports": [],
39
51
  "dependents": [
40
- "/src/links/internals/createHTTPBatchLink.ts"
52
+ "/src/links/httpBatchLink.ts",
53
+ "/src/links/httpBatchStreamLink.ts"
41
54
  ],
42
- "percent": 9.4,
43
- "reduction": 7.49
55
+ "percent": 9.67,
56
+ "reduction": 6.34
57
+ },
58
+ {
59
+ "id": "/src/links/httpBatchLink.ts",
60
+ "size": 3906,
61
+ "origSize": 4074,
62
+ "renderedExports": [
63
+ "httpBatchLink"
64
+ ],
65
+ "removedExports": [],
66
+ "dependents": [],
67
+ "percent": 8.38,
68
+ "reduction": 4.12
44
69
  },
45
70
  {
46
71
  "id": "/src/links/internals/httpUtils.ts",
47
- "size": 4407,
48
- "origSize": 6905,
72
+ "size": 3469,
73
+ "origSize": 5927,
49
74
  "renderedExports": [
50
75
  "resolveHTTPLinkOptions",
76
+ "getInput",
51
77
  "getUrl",
52
78
  "getBody",
53
79
  "jsonHttpRequester",
54
- "universalRequester",
55
80
  "fetchHTTPResponse",
56
81
  "httpRequest"
57
82
  ],
@@ -59,41 +84,22 @@
59
84
  "dependents": [
60
85
  "/src/links/httpBatchLink.ts",
61
86
  "/src/links/httpLink.ts",
62
- "/src/links/internals/createHTTPBatchLink.ts",
63
- "/src/links/internals/parseJSONStream.ts"
64
- ],
65
- "percent": 9.4,
66
- "reduction": 36.18
67
- },
68
- {
69
- "id": "/src/links/internals/parseJSONStream.ts",
70
- "size": 4007,
71
- "origSize": 5037,
72
- "renderedExports": [
73
- "parseJSONStream",
74
- "streamingJsonHttpRequester"
75
- ],
76
- "removedExports": [],
77
- "dependents": [
78
87
  "/src/links/httpBatchStreamLink.ts"
79
88
  ],
80
- "percent": 8.54,
81
- "reduction": 20.45
89
+ "percent": 7.44,
90
+ "reduction": 41.47
82
91
  },
83
92
  {
84
- "id": "/src/links/internals/createHTTPBatchLink.ts",
85
- "size": 2944,
86
- "origSize": 3711,
93
+ "id": "/src/links/httpLink.ts",
94
+ "size": 2939,
95
+ "origSize": 3459,
87
96
  "renderedExports": [
88
- "createHTTPBatchLink"
97
+ "httpLink"
89
98
  ],
90
99
  "removedExports": [],
91
- "dependents": [
92
- "/src/links/httpBatchLink.ts",
93
- "/src/links/httpBatchStreamLink.ts"
94
- ],
95
- "percent": 6.28,
96
- "reduction": 20.67
100
+ "dependents": [],
101
+ "percent": 6.31,
102
+ "reduction": 15.03
97
103
  },
98
104
  {
99
105
  "id": "/src/internals/TRPCUntypedClient.ts",
@@ -107,22 +113,9 @@
107
113
  "/src/createTRPCUntypedClient.ts",
108
114
  "/src/createTRPCClient.ts"
109
115
  ],
110
- "percent": 4.9,
116
+ "percent": 4.93,
111
117
  "reduction": 45.35
112
118
  },
113
- {
114
- "id": "/src/links/httpLink.ts",
115
- "size": 2170,
116
- "origSize": 2755,
117
- "renderedExports": [
118
- "httpLinkFactory",
119
- "httpLink"
120
- ],
121
- "removedExports": [],
122
- "dependents": [],
123
- "percent": 4.63,
124
- "reduction": 21.23
125
- },
126
119
  {
127
120
  "id": "/src/TRPCClientError.ts",
128
121
  "size": 1866,
@@ -133,27 +126,16 @@
133
126
  "removedExports": [],
134
127
  "dependents": [
135
128
  "/src/index.ts",
129
+ "/src/links/httpBatchLink.ts",
136
130
  "/src/links/httpLink.ts",
137
131
  "/src/links/wsLink.ts",
132
+ "/src/links/httpBatchStreamLink.ts",
138
133
  "/src/internals/TRPCUntypedClient.ts",
139
- "/src/links/internals/createHTTPBatchLink.ts",
140
134
  "/src/links/internals/httpUtils.ts"
141
135
  ],
142
- "percent": 3.98,
136
+ "percent": 4,
143
137
  "reduction": 45.71
144
138
  },
145
- {
146
- "id": "/src/links/httpBatchStreamLink.ts",
147
- "size": 1340,
148
- "origSize": 2176,
149
- "renderedExports": [
150
- "unstable_httpBatchStreamLink"
151
- ],
152
- "removedExports": [],
153
- "dependents": [],
154
- "percent": 2.86,
155
- "reduction": 38.42
156
- },
157
139
  {
158
140
  "id": "/src/createTRPCClient.ts",
159
141
  "size": 1206,
@@ -168,21 +150,9 @@
168
150
  "dependents": [
169
151
  "/src/index.ts"
170
152
  ],
171
- "percent": 2.57,
153
+ "percent": 2.59,
172
154
  "reduction": 72.4
173
155
  },
174
- {
175
- "id": "/src/links/httpBatchLink.ts",
176
- "size": 1205,
177
- "origSize": 1527,
178
- "renderedExports": [
179
- "httpBatchLink"
180
- ],
181
- "removedExports": [],
182
- "dependents": [],
183
- "percent": 2.57,
184
- "reduction": 21.09
185
- },
186
156
  {
187
157
  "id": "/src/links/internals/createChain.ts",
188
158
  "size": 690,
@@ -195,7 +165,7 @@
195
165
  "/src/links/splitLink.ts",
196
166
  "/src/internals/TRPCUntypedClient.ts"
197
167
  ],
198
- "percent": 1.47,
168
+ "percent": 1.48,
199
169
  "reduction": 32.75
200
170
  },
201
171
  {
@@ -207,7 +177,7 @@
207
177
  ],
208
178
  "removedExports": [],
209
179
  "dependents": [],
210
- "percent": 1.3,
180
+ "percent": 1.31,
211
181
  "reduction": 44.95
212
182
  },
213
183
  {
@@ -221,7 +191,7 @@
221
191
  "dependents": [
222
192
  "/src/unstable-internals.ts"
223
193
  ],
224
- "percent": 1.2,
194
+ "percent": 1.21,
225
195
  "reduction": 66.75
226
196
  },
227
197
  {
@@ -236,23 +206,9 @@
236
206
  "/src/index.ts",
237
207
  "/src/links/internals/httpUtils.ts"
238
208
  ],
239
- "percent": 0.91,
209
+ "percent": 0.92,
240
210
  "reduction": 33.54
241
211
  },
242
- {
243
- "id": "/src/links/internals/getTextDecoder.ts",
244
- "size": 407,
245
- "origSize": 493,
246
- "renderedExports": [
247
- "getTextDecoder"
248
- ],
249
- "removedExports": [],
250
- "dependents": [
251
- "/src/links/httpBatchStreamLink.ts"
252
- ],
253
- "percent": 0.87,
254
- "reduction": 17.44
255
- },
256
212
  {
257
213
  "id": "/src/internals/getAbortController.ts",
258
214
  "size": 396,
@@ -264,7 +220,7 @@
264
220
  "dependents": [
265
221
  "/src/links/internals/httpUtils.ts"
266
222
  ],
267
- "percent": 0.84,
223
+ "percent": 0.85,
268
224
  "reduction": 30.4
269
225
  },
270
226
  {
@@ -277,10 +233,8 @@
277
233
  "isNonJsonSerializable"
278
234
  ],
279
235
  "removedExports": [],
280
- "dependents": [
281
- "/src/links/internals/httpUtils.ts"
282
- ],
283
- "percent": 0.7,
236
+ "dependents": [],
237
+ "percent": 0.71,
284
238
  "reduction": 15.17
285
239
  },
286
240
  {
@@ -321,5 +275,5 @@
321
275
  "reduction": 100
322
276
  }
323
277
  ],
324
- "moduleCount": 22
278
+ "moduleCount": 19
325
279
  }
package/dist/index.js CHANGED
@@ -29,7 +29,6 @@ exports.isOctetType = contentTypes.isOctetType;
29
29
  exports.httpBatchLink = httpBatchLink.httpBatchLink;
30
30
  exports.unstable_httpBatchStreamLink = httpBatchStreamLink.unstable_httpBatchStreamLink;
31
31
  exports.httpLink = httpLink.httpLink;
32
- exports.httpLinkFactory = httpLink.httpLinkFactory;
33
32
  exports.loggerLink = loggerLink.loggerLink;
34
33
  exports.splitLink = splitLink.splitLink;
35
34
  exports.createWSClient = wsLink.createWSClient;
package/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ export { TRPCClientError } from './TRPCClientError.mjs';
5
5
  export { isFormData, isNonJsonSerializable, isOctetType } from './links/internals/contentTypes.mjs';
6
6
  export { httpBatchLink } from './links/httpBatchLink.mjs';
7
7
  export { unstable_httpBatchStreamLink } from './links/httpBatchStreamLink.mjs';
8
- export { httpLink, httpLinkFactory } from './links/httpLink.mjs';
8
+ export { httpLink } from './links/httpLink.mjs';
9
9
  export { loggerLink } from './links/loggerLink.mjs';
10
10
  export { splitLink } from './links/splitLink.mjs';
11
11
  export { createWSClient, wsLink } from './links/wsLink.mjs';
@@ -1,8 +1,8 @@
1
1
  import type { CancelFn, PromiseAndCancel } from '../links/types';
2
- type BatchLoader<TKey, TValue> = {
2
+ export type BatchLoader<TKey, TValue> = {
3
3
  validate: (keys: TKey[]) => boolean;
4
- fetch: (keys: TKey[], unitResolver: (index: number, value: NonNullable<TValue>) => void) => {
5
- promise: Promise<TValue[]>;
4
+ fetch: (keys: TKey[]) => {
5
+ promise: Promise<TValue[] | Promise<TValue>[]>;
6
6
  cancel: CancelFn;
7
7
  };
8
8
  };
@@ -14,5 +14,4 @@ type BatchLoader<TKey, TValue> = {
14
14
  export declare function dataLoader<TKey, TValue>(batchLoader: BatchLoader<TKey, TValue>): {
15
15
  load: (key: TKey) => PromiseAndCancel<TValue>;
16
16
  };
17
- export {};
18
17
  //# sourceMappingURL=dataLoader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dataLoader.d.ts","sourceRoot":"","sources":["../../src/internals/dataLoader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAajE,KAAK,WAAW,CAAC,IAAI,EAAE,MAAM,IAAI;IAC/B,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC;IACpC,KAAK,EAAE,CACL,IAAI,EAAE,IAAI,EAAE,EACZ,YAAY,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,CAAC,MAAM,CAAC,KAAK,IAAI,KAC9D;QACH,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;QAC3B,MAAM,EAAE,QAAQ,CAAC;KAClB,CAAC;CACH,CAAC;AAWF;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EACrC,WAAW,EAAE,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC;gBAqGnB,IAAI,KAAG,iBAAiB,MAAM,CAAC;EAsCnD"}
1
+ {"version":3,"file":"dataLoader.d.ts","sourceRoot":"","sources":["../../src/internals/dataLoader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAajE,MAAM,MAAM,WAAW,CAAC,IAAI,EAAE,MAAM,IAAI;IACtC,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC;IACpC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK;QACvB,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAC/C,MAAM,EAAE,QAAQ,CAAC;KAClB,CAAC;CACH,CAAC;AAWF;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EACrC,WAAW,EAAE,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC;gBA0GnB,IAAI,KAAG,iBAAiB,MAAM,CAAC;EAsCnD"}
@@ -67,20 +67,21 @@
67
67
  for (const item of items){
68
68
  item.batch = batch;
69
69
  }
70
- const unitResolver = (index, value)=>{
71
- const item = batch.items[index];
72
- item.resolve?.(value);
73
- item.batch = null;
74
- item.reject = null;
75
- item.resolve = null;
76
- };
77
- const { promise , cancel } = batchLoader.fetch(batch.items.map((_item)=>_item.key), unitResolver);
70
+ const { promise , cancel } = batchLoader.fetch(batch.items.map((_item)=>_item.key));
78
71
  batch.cancel = cancel;
79
- promise.then((result)=>{
80
- for(let i = 0; i < result.length; i++){
81
- const value = result[i];
82
- unitResolver(i, value);
83
- }
72
+ promise.then(async (result)=>{
73
+ await Promise.all(result.map(async (valueOrPromise, index)=>{
74
+ const item = batch.items[index];
75
+ try {
76
+ const value = await Promise.resolve(valueOrPromise);
77
+ item.resolve?.(value);
78
+ } catch (cause) {
79
+ item.reject?.(cause);
80
+ }
81
+ item.batch = null;
82
+ item.reject = null;
83
+ item.resolve = null;
84
+ }));
84
85
  for (const item of batch.items){
85
86
  item.reject?.(new Error('Missing result'));
86
87
  item.batch = null;
@@ -65,20 +65,21 @@
65
65
  for (const item of items){
66
66
  item.batch = batch;
67
67
  }
68
- const unitResolver = (index, value)=>{
69
- const item = batch.items[index];
70
- item.resolve?.(value);
71
- item.batch = null;
72
- item.reject = null;
73
- item.resolve = null;
74
- };
75
- const { promise , cancel } = batchLoader.fetch(batch.items.map((_item)=>_item.key), unitResolver);
68
+ const { promise , cancel } = batchLoader.fetch(batch.items.map((_item)=>_item.key));
76
69
  batch.cancel = cancel;
77
- promise.then((result)=>{
78
- for(let i = 0; i < result.length; i++){
79
- const value = result[i];
80
- unitResolver(i, value);
81
- }
70
+ promise.then(async (result)=>{
71
+ await Promise.all(result.map(async (valueOrPromise, index)=>{
72
+ const item = batch.items[index];
73
+ try {
74
+ const value = await Promise.resolve(valueOrPromise);
75
+ item.resolve?.(value);
76
+ } catch (cause) {
77
+ item.reject?.(cause);
78
+ }
79
+ item.batch = null;
80
+ item.reject = null;
81
+ item.resolve = null;
82
+ }));
82
83
  for (const item of batch.items){
83
84
  item.reject?.(new Error('Missing result'));
84
85
  item.batch = null;
@@ -1,3 +1,8 @@
1
+ import type { AnyRouter } from '@trpc/server';
1
2
  import type { HTTPBatchLinkOptions } from './HTTPBatchLinkOptions';
2
- export declare const httpBatchLink: <TRouter extends import("@trpc/server/unstable-core-do-not-import").AnyRouter>(opts: HTTPBatchLinkOptions<import("@trpc/server/unstable-core-do-not-import").inferClientTypes<TRouter>>) => import("./types").TRPCLink<TRouter>;
3
+ import type { TRPCLink } from './types';
4
+ /**
5
+ * @see https://trpc.io/docs/client/links/httpBatchLink
6
+ */
7
+ export declare function httpBatchLink<TRouter extends AnyRouter>(opts: HTTPBatchLinkOptions<TRouter['_def']['_config']['$types']>): TRPCLink<TRouter>;
3
8
  //# sourceMappingURL=httpBatchLink.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"httpBatchLink.d.ts","sourceRoot":"","sources":["../../src/links/httpBatchLink.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAgDnE,eAAO,MAAM,aAAa,iOAAsC,CAAC"}
1
+ {"version":3,"file":"httpBatchLink.d.ts","sourceRoot":"","sources":["../../src/links/httpBatchLink.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAiB,MAAM,cAAc,CAAC;AAO7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAOnE,OAAO,KAAK,EAAa,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnD;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,SAAS,SAAS,EACrD,IAAI,EAAE,oBAAoB,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,GAC/D,QAAQ,CAAC,OAAO,CAAC,CAmHnB"}
@@ -1,41 +1,106 @@
1
1
  'use strict';
2
2
 
3
- var createHTTPBatchLink = require('./internals/createHTTPBatchLink.js');
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 TRPCClientError = require('../TRPCClientError.js');
4
7
  var httpUtils = require('./internals/httpUtils.js');
5
8
 
6
- const batchRequester = (requesterOpts)=>{
7
- return (batchOps)=>{
8
- const path = batchOps.map((op)=>op.path).join(',');
9
- const inputs = batchOps.map((op)=>op.input);
10
- const { promise , cancel } = httpUtils.jsonHttpRequester({
11
- ...requesterOpts,
12
- path,
13
- inputs,
14
- headers () {
15
- if (!requesterOpts.opts.headers) {
16
- return {};
17
- }
18
- if (typeof requesterOpts.opts.headers === 'function') {
19
- return requesterOpts.opts.headers({
20
- opList: batchOps
9
+ /**
10
+ * @see https://trpc.io/docs/client/links/httpBatchLink
11
+ */ function httpBatchLink(opts) {
12
+ const resolvedOpts = httpUtils.resolveHTTPLinkOptions(opts);
13
+ const maxURLLength = opts.maxURLLength ?? Infinity;
14
+ return ()=>{
15
+ const batchLoader = (type)=>{
16
+ return {
17
+ validate (batchOps) {
18
+ if (maxURLLength === Infinity) {
19
+ // escape hatch for quick calcs
20
+ return true;
21
+ }
22
+ const path = batchOps.map((op)=>op.path).join(',');
23
+ const inputs = batchOps.map((op)=>op.input);
24
+ const url = httpUtils.getUrl({
25
+ ...resolvedOpts,
26
+ type,
27
+ path,
28
+ inputs
29
+ });
30
+ return url.length <= maxURLLength;
31
+ },
32
+ fetch (batchOps) {
33
+ const path = batchOps.map((op)=>op.path).join(',');
34
+ const inputs = batchOps.map((op)=>op.input);
35
+ const requester = httpUtils.jsonHttpRequester({
36
+ ...resolvedOpts,
37
+ path,
38
+ inputs,
39
+ type,
40
+ headers () {
41
+ if (!opts.headers) {
42
+ return {};
43
+ }
44
+ if (typeof opts.headers === 'function') {
45
+ return opts.headers({
46
+ opList: batchOps
47
+ });
48
+ }
49
+ return opts.headers;
50
+ }
21
51
  });
52
+ return {
53
+ cancel: requester.cancel,
54
+ promise: requester.promise.then((res)=>{
55
+ const resJSON = Array.isArray(res.json) ? res.json : batchOps.map(()=>res.json);
56
+ const result = resJSON.map((item)=>({
57
+ meta: res.meta,
58
+ json: item
59
+ }));
60
+ return result;
61
+ })
62
+ };
22
63
  }
23
- return requesterOpts.opts.headers;
24
- }
25
- });
26
- return {
27
- promise: promise.then((res)=>{
28
- const resJSON = Array.isArray(res.json) ? res.json : batchOps.map(()=>res.json);
29
- const result = resJSON.map((item)=>({
30
- meta: res.meta,
31
- json: item
64
+ };
65
+ };
66
+ const query = dataLoader.dataLoader(batchLoader('query'));
67
+ const mutation = dataLoader.dataLoader(batchLoader('mutation'));
68
+ const subscription = dataLoader.dataLoader(batchLoader('subscription'));
69
+ const loaders = {
70
+ query,
71
+ subscription,
72
+ mutation
73
+ };
74
+ return ({ op })=>{
75
+ return observable.observable((observer)=>{
76
+ const loader = loaders[op.type];
77
+ const { promise , cancel } = loader.load(op);
78
+ let _res = undefined;
79
+ promise.then((res)=>{
80
+ _res = res;
81
+ const transformed = unstableCoreDoNotImport.transformResult(res.json, resolvedOpts.transformer.output);
82
+ if (!transformed.ok) {
83
+ observer.error(TRPCClientError.TRPCClientError.from(transformed.error, {
84
+ meta: res.meta
85
+ }));
86
+ return;
87
+ }
88
+ observer.next({
89
+ context: res.meta,
90
+ result: transformed.result
91
+ });
92
+ observer.complete();
93
+ }).catch((err)=>{
94
+ observer.error(TRPCClientError.TRPCClientError.from(err, {
95
+ meta: _res?.meta
32
96
  }));
33
- return result;
34
- }),
35
- cancel
97
+ });
98
+ return ()=>{
99
+ cancel();
100
+ };
101
+ });
36
102
  };
37
103
  };
38
- };
39
- const httpBatchLink = createHTTPBatchLink.createHTTPBatchLink(batchRequester);
104
+ }
40
105
 
41
106
  exports.httpBatchLink = httpBatchLink;