@trpc/client 10.0.0-alpha.2 → 10.0.0-alpha.3

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 (179) hide show
  1. package/dist/{TRPCClientError-e1da1ef0.esm.js → TRPCClientError-17b117e1.mjs} +16 -7
  2. package/dist/TRPCClientError-ec6bd2ca.js +94 -0
  3. package/dist/{declarations/src/TRPCClientError.d.ts → TRPCClientError.d.ts} +29 -29
  4. package/dist/TRPCClientError.d.ts.map +1 -0
  5. package/dist/{createChain-e45e6cf2.esm.js → createChain-389cc116.mjs} +1 -1
  6. package/dist/{createChain-93a38e1c.cjs.dev.js → createChain-864dbb30.js} +1 -1
  7. package/dist/{declarations/src/createTRPCClient.d.ts → createTRPCClient.d.ts} +5 -5
  8. package/dist/createTRPCClient.d.ts.map +1 -0
  9. package/dist/{declarations/src/getFetch.d.ts → getFetch.d.ts} +1 -1
  10. package/dist/getFetch.d.ts.map +1 -0
  11. package/dist/{httpUtils-a1426e14.cjs.dev.js → httpUtils-1f9e4e3c.js} +9 -1
  12. package/dist/{httpUtils-e45c9056.esm.js → httpUtils-c09d7b79.mjs} +5 -1
  13. package/dist/{declarations/src/index.d.ts → index.d.ts} +4 -4
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/{trpc-client.cjs.prod.js → index.js} +30 -16
  16. package/dist/{trpc-client.esm.js → index.mjs} +19 -15
  17. package/dist/index.ts.js +1 -0
  18. package/dist/{declarations/src/internals → internals}/TRPCClient.d.ts +64 -64
  19. package/dist/internals/TRPCClient.d.ts.map +1 -0
  20. package/dist/{declarations/src/internals → internals}/dataLoader.d.ts +14 -14
  21. package/dist/internals/dataLoader.d.ts.map +1 -0
  22. package/dist/{declarations/src/internals → internals}/fetchHelpers.d.ts +2 -2
  23. package/dist/internals/fetchHelpers.d.ts.map +1 -0
  24. package/dist/{declarations/src/internals → internals}/retryDelay.d.ts +1 -1
  25. package/dist/internals/retryDelay.d.ts.map +1 -0
  26. package/dist/internals/transformRPCResponse.d.ts +15 -0
  27. package/dist/internals/transformRPCResponse.d.ts.map +1 -0
  28. package/dist/links/dedupeLink.d.ts +4 -0
  29. package/dist/links/dedupeLink.d.ts.map +1 -0
  30. package/dist/{declarations/src/links → links}/httpBatchLink.d.ts +4 -4
  31. package/dist/links/httpBatchLink.d.ts.map +1 -0
  32. package/dist/links/httpBatchLink.js +189 -0
  33. package/dist/links/httpBatchLink.mjs +185 -0
  34. package/dist/links/httpBatchLink.ts.js +1 -0
  35. package/dist/{declarations/src/links → links}/httpLink.d.ts +4 -4
  36. package/dist/links/httpLink.d.ts.map +1 -0
  37. package/dist/links/httpLink.js +44 -0
  38. package/dist/links/httpLink.mjs +40 -0
  39. package/dist/links/httpLink.ts.js +1 -0
  40. package/dist/{declarations/src/links → links}/httpUtils.d.ts +21 -21
  41. package/dist/links/httpUtils.d.ts.map +1 -0
  42. package/dist/{declarations/src/links → links}/internals/createChain.d.ts +7 -7
  43. package/dist/links/internals/createChain.d.ts.map +1 -0
  44. package/dist/{declarations/src/links → links}/internals/transformOperationResult.d.ts +15 -15
  45. package/dist/links/internals/transformOperationResult.d.ts.map +1 -0
  46. package/dist/{declarations/src/links → links}/loggerLink.d.ts +38 -38
  47. package/dist/links/loggerLink.d.ts.map +1 -0
  48. package/dist/links/loggerLink.js +108 -0
  49. package/dist/links/loggerLink.mjs +99 -0
  50. package/dist/links/loggerLink.ts.js +1 -0
  51. package/dist/links/retryLink.d.ts +6 -0
  52. package/dist/links/retryLink.d.ts.map +1 -0
  53. package/dist/{declarations/src/links → links}/splitLink.d.ts +13 -13
  54. package/dist/links/splitLink.d.ts.map +1 -0
  55. package/dist/links/splitLink.js +32 -0
  56. package/dist/links/splitLink.mjs +28 -0
  57. package/dist/links/splitLink.ts.js +1 -0
  58. package/dist/{declarations/src/links → links}/transformerLink.d.ts +3 -3
  59. package/dist/links/transformerLink.d.ts.map +1 -0
  60. package/dist/links/transformerLink.js +75 -0
  61. package/dist/links/transformerLink.mjs +67 -0
  62. package/dist/links/transformerLink.ts.js +1 -0
  63. package/dist/{declarations/src/links → links}/types.d.ts +39 -39
  64. package/dist/links/types.d.ts.map +1 -0
  65. package/dist/{declarations/src/links → links}/wsLink.d.ts +19 -19
  66. package/dist/links/wsLink.d.ts.map +1 -0
  67. package/dist/links/wsLink.js +384 -0
  68. package/dist/links/wsLink.mjs +370 -0
  69. package/dist/links/wsLink.ts.js +1 -0
  70. package/dist/{observable-01534ea8.esm.js → observable-7e66cb56.mjs} +0 -0
  71. package/dist/{observable-9aad8c3e.cjs.dev.js → observable-85669100.js} +0 -0
  72. package/dist/{declarations/src/rx → rx}/index.d.ts +2 -2
  73. package/dist/rx/index.d.ts.map +1 -0
  74. package/dist/rx/index.js +9 -0
  75. package/dist/rx/index.mjs +1 -0
  76. package/dist/rx/index.ts.js +1 -0
  77. package/dist/{declarations/src/rx → rx}/observable.d.ts +3 -3
  78. package/dist/rx/observable.d.ts.map +1 -0
  79. package/dist/{declarations/src/rx → rx}/operators/index.d.ts +3 -3
  80. package/dist/rx/operators/index.d.ts.map +1 -0
  81. package/dist/rx/operators/index.js +38 -0
  82. package/dist/rx/operators/index.mjs +32 -0
  83. package/dist/rx/operators/index.ts.js +1 -0
  84. package/dist/{declarations/src/rx → rx}/operators/map.d.ts +2 -2
  85. package/dist/rx/operators/map.d.ts.map +1 -0
  86. package/dist/{declarations/src/rx → rx}/operators/share.d.ts +5 -5
  87. package/dist/rx/operators/share.d.ts.map +1 -0
  88. package/dist/{declarations/src/rx → rx}/operators/tap.d.ts +2 -2
  89. package/dist/rx/operators/tap.d.ts.map +1 -0
  90. package/dist/{declarations/src/rx → rx}/types.d.ts +28 -28
  91. package/dist/rx/types.d.ts.map +1 -0
  92. package/dist/{declarations/src/rx → rx}/util/identity.d.ts +1 -1
  93. package/dist/rx/util/identity.d.ts.map +1 -0
  94. package/dist/{declarations/src/rx → rx}/util/observableToPromise.d.ts +9 -9
  95. package/dist/rx/util/observableToPromise.d.ts.map +1 -0
  96. package/dist/{declarations/src/rx → rx}/util/pipe.d.ts +3 -3
  97. package/dist/rx/util/pipe.d.ts.map +1 -0
  98. package/dist/{share-f2ac9332.cjs.dev.js → share-4d79dc49.js} +5 -1
  99. package/dist/{share-ca585761.esm.js → share-671b63fa.mjs} +5 -1
  100. package/dist/{tap-606957cb.esm.js → tap-538fa07f.mjs} +0 -0
  101. package/dist/{tap-2d565250.cjs.dev.js → tap-799a2d33.js} +0 -0
  102. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js +68 -38
  103. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +68 -38
  104. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js +67 -37
  105. package/links/httpBatchLink/index.d.ts +1 -0
  106. package/links/httpBatchLink/index.js +1 -0
  107. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +52 -29
  108. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +52 -29
  109. package/links/httpLink/dist/trpc-client-links-httpLink.esm.js +52 -29
  110. package/links/httpLink/index.d.ts +1 -0
  111. package/links/httpLink/index.js +1 -0
  112. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.dev.js +19 -31
  113. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.prod.js +19 -31
  114. package/links/loggerLink/dist/trpc-client-links-loggerLink.esm.js +19 -31
  115. package/links/loggerLink/index.d.ts +1 -0
  116. package/links/loggerLink/index.js +1 -0
  117. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.dev.js +7 -20
  118. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.prod.js +7 -20
  119. package/links/splitLink/dist/trpc-client-links-splitLink.esm.js +7 -20
  120. package/links/splitLink/index.d.ts +1 -0
  121. package/links/splitLink/index.js +1 -0
  122. package/links/transformerLink/index.d.ts +1 -0
  123. package/links/transformerLink/index.js +1 -0
  124. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.dev.js +84 -60
  125. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +84 -60
  126. package/links/wsLink/dist/trpc-client-links-wsLink.esm.js +84 -60
  127. package/links/wsLink/index.d.ts +1 -0
  128. package/links/wsLink/index.js +1 -0
  129. package/package.json +56 -20
  130. package/rx/index.d.ts +1 -0
  131. package/rx/index.js +1 -0
  132. package/rx/operators/index.d.ts +1 -0
  133. package/rx/operators/index.js +1 -0
  134. package/dist/TRPCClientError-a5312a5f.cjs.dev.js +0 -74
  135. package/dist/TRPCClientError-ea7d89b2.cjs.prod.js +0 -74
  136. package/dist/createChain-e45e052a.cjs.prod.js +0 -27
  137. package/dist/declarations/src/TRPCClientError.d.ts.map +0 -1
  138. package/dist/declarations/src/createTRPCClient.d.ts.map +0 -1
  139. package/dist/declarations/src/getFetch.d.ts.map +0 -1
  140. package/dist/declarations/src/index.d.ts.map +0 -1
  141. package/dist/declarations/src/internals/TRPCClient.d.ts.map +0 -1
  142. package/dist/declarations/src/internals/dataLoader.d.ts.map +0 -1
  143. package/dist/declarations/src/internals/fetchHelpers.d.ts.map +0 -1
  144. package/dist/declarations/src/internals/retryDelay.d.ts.map +0 -1
  145. package/dist/declarations/src/links/httpBatchLink.d.ts.map +0 -1
  146. package/dist/declarations/src/links/httpLink.d.ts.map +0 -1
  147. package/dist/declarations/src/links/httpUtils.d.ts.map +0 -1
  148. package/dist/declarations/src/links/internals/createChain.d.ts.map +0 -1
  149. package/dist/declarations/src/links/internals/transformOperationResult.d.ts.map +0 -1
  150. package/dist/declarations/src/links/loggerLink.d.ts.map +0 -1
  151. package/dist/declarations/src/links/splitLink.d.ts.map +0 -1
  152. package/dist/declarations/src/links/transformerLink.d.ts.map +0 -1
  153. package/dist/declarations/src/links/types.d.ts.map +0 -1
  154. package/dist/declarations/src/links/wsLink.d.ts.map +0 -1
  155. package/dist/declarations/src/rx/index.d.ts.map +0 -1
  156. package/dist/declarations/src/rx/observable.d.ts.map +0 -1
  157. package/dist/declarations/src/rx/operators/index.d.ts.map +0 -1
  158. package/dist/declarations/src/rx/operators/map.d.ts.map +0 -1
  159. package/dist/declarations/src/rx/operators/share.d.ts.map +0 -1
  160. package/dist/declarations/src/rx/operators/tap.d.ts.map +0 -1
  161. package/dist/declarations/src/rx/types.d.ts.map +0 -1
  162. package/dist/declarations/src/rx/util/identity.d.ts.map +0 -1
  163. package/dist/declarations/src/rx/util/observableToPromise.d.ts.map +0 -1
  164. package/dist/declarations/src/rx/util/pipe.d.ts.map +0 -1
  165. package/dist/httpUtils-299a66f6.cjs.prod.js +0 -89
  166. package/dist/observable-ccb54234.cjs.prod.js +0 -104
  167. package/dist/share-5a8c2543.cjs.prod.js +0 -106
  168. package/dist/tap-d907998d.cjs.prod.js +0 -32
  169. package/dist/trpc-client.cjs.d.ts +0 -1
  170. package/dist/trpc-client.cjs.dev.js +0 -300
  171. package/dist/trpc-client.cjs.js +0 -7
  172. package/links/httpBatchLink/package.json +0 -4
  173. package/links/httpLink/package.json +0 -4
  174. package/links/loggerLink/package.json +0 -4
  175. package/links/splitLink/package.json +0 -4
  176. package/links/transformerLink/package.json +0 -4
  177. package/links/wsLink/package.json +0 -4
  178. package/rx/operators/package.json +0 -4
  179. package/rx/package.json +0 -4
@@ -1,6 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
3
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
4
+
5
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
+
7
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
4
8
 
5
9
  /* eslint-disable @typescript-eslint/no-empty-interface */
6
10
  function share( // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -1,4 +1,8 @@
1
- import _createForOfIteratorHelper from '@babel/runtime/helpers/esm/createForOfIteratorHelper';
1
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
+
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+
5
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
2
6
 
3
7
  /* eslint-disable @typescript-eslint/no-empty-interface */
4
8
  function share( // eslint-disable-next-line @typescript-eslint/no-unused-vars
File without changes
@@ -3,8 +3,14 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
6
- var observable = require('../../../dist/observable-9aad8c3e.cjs.dev.js');
7
- var httpUtils = require('../../../dist/httpUtils-a1426e14.cjs.dev.js');
6
+ var transformRPCResponse = require('../../../dist/transformRPCResponse-57e80136.cjs.dev.js');
7
+ var TRPCClientError = require('../../../dist/TRPCClientError-bfee2bf5.cjs.dev.js');
8
+ require('@babel/runtime/helpers/createClass');
9
+ require('@babel/runtime/helpers/classCallCheck');
10
+ require('@babel/runtime/helpers/assertThisInitialized');
11
+ require('@babel/runtime/helpers/inherits');
12
+ require('@babel/runtime/helpers/createSuper');
13
+ require('@babel/runtime/helpers/wrapNativeSuper');
8
14
  require('@babel/runtime/helpers/objectSpread2');
9
15
 
10
16
  /**
@@ -12,7 +18,7 @@ require('@babel/runtime/helpers/objectSpread2');
12
18
  * Less configuration, no caching, and allows you to cancel requests
13
19
  * When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
14
20
  */
15
- function dataLoader(fetchMany) {
21
+ function dataLoader(fetchMany, opts) {
16
22
  var batch = null;
17
23
  var dispatchTimer = null;
18
24
 
@@ -77,6 +83,11 @@ function dataLoader(fetchMany) {
77
83
  item.reject = reject;
78
84
  item.resolve = resolve;
79
85
  thisBatch.items.push(item);
86
+
87
+ if (typeof (opts === null || opts === void 0 ? void 0 : opts.maxBatchSize) !== 'undefined' && thisBatch.items.length >= opts.maxBatchSize) {
88
+ dispatch();
89
+ return;
90
+ }
80
91
  });
81
92
 
82
93
  if (!dispatchTimer) {
@@ -108,8 +119,11 @@ function dataLoader(fetchMany) {
108
119
  }
109
120
 
110
121
  function httpBatchLink(opts) {
111
- var url = opts.url;
122
+ var url = opts.url,
123
+ maxBatchSize = opts.maxBatchSize; // initialized config
124
+
112
125
  return function (runtime) {
126
+ // initialized in app
113
127
  var fetcher = function fetcher(type) {
114
128
  return function (keyInputPairs) {
115
129
  var path = keyInputPairs.map(function (op) {
@@ -119,7 +133,7 @@ function httpBatchLink(opts) {
119
133
  return op.input;
120
134
  });
121
135
 
122
- var _httpRequest = httpUtils.httpRequest({
136
+ var _httpRequest = transformRPCResponse.httpRequest({
123
137
  url: url,
124
138
  inputs: inputs,
125
139
  path: path,
@@ -131,51 +145,67 @@ function httpBatchLink(opts) {
131
145
 
132
146
  return {
133
147
  promise: promise.then(function (res) {
134
- var resJSON = Array.isArray(res.json) ? res.json : keyInputPairs.map(function () {
135
- return res.json;
136
- });
137
- var result = resJSON.map(function (item) {
138
- return {
139
- meta: res.meta,
140
- json: item
141
- };
142
- });
143
- return result;
148
+ if (!Array.isArray(res)) {
149
+ return keyInputPairs.map(function () {
150
+ return res;
151
+ });
152
+ }
153
+
154
+ return res;
144
155
  }),
145
156
  cancel: cancel
146
157
  };
147
158
  };
148
159
  };
149
160
 
150
- var query = dataLoader(fetcher('query'));
151
- var mutation = dataLoader(fetcher('mutation'));
152
- var subscription = dataLoader(fetcher('subscription'));
161
+ var query = dataLoader(fetcher('query'), {
162
+ maxBatchSize: maxBatchSize
163
+ });
164
+ var mutation = dataLoader(fetcher('mutation'), {
165
+ maxBatchSize: maxBatchSize
166
+ });
167
+ var subscription = dataLoader(fetcher('subscription'), {
168
+ maxBatchSize: maxBatchSize
169
+ });
153
170
  var loaders = {
154
171
  query: query,
155
172
  subscription: subscription,
156
173
  mutation: mutation
157
174
  };
158
175
  return function (_ref) {
159
- var op = _ref.op;
160
- return observable.observable(function (observer) {
161
- var loader = loaders[op.type];
162
-
163
- var _loader$load = loader.load(op),
164
- promise = _loader$load.promise,
165
- cancel = _loader$load.cancel;
166
-
167
- promise.then(function (res) {
168
- observer.next({
169
- context: res.meta,
170
- data: res.json
171
- });
172
- observer.complete();
173
- }).catch(function (err) {
174
- return observer.error(err);
175
- });
176
- return function () {
177
- cancel();
178
- };
176
+ var op = _ref.op,
177
+ prev = _ref.prev,
178
+ onDestroy = _ref.onDestroy;
179
+ var loader = loaders[op.type];
180
+
181
+ var _loader$load = loader.load(op),
182
+ promise = _loader$load.promise,
183
+ cancel = _loader$load.cancel;
184
+
185
+ var isDone = false;
186
+
187
+ var prevOnce = function prevOnce(result) {
188
+ if (isDone) {
189
+ return;
190
+ }
191
+
192
+ isDone = true;
193
+ prev(result);
194
+ };
195
+
196
+ onDestroy(function () {
197
+ prevOnce(TRPCClientError.TRPCClientError.from(new transformRPCResponse.TRPCAbortError(), {
198
+ isDone: true
199
+ }));
200
+ cancel();
201
+ });
202
+ promise.then(function (envelope) {
203
+ prevOnce(transformRPCResponse.transformRPCResponse({
204
+ envelope: envelope,
205
+ runtime: runtime
206
+ }));
207
+ }).catch(function (cause) {
208
+ prevOnce(TRPCClientError.TRPCClientError.from(cause));
179
209
  });
180
210
  };
181
211
  };
@@ -3,8 +3,14 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
6
- var observable = require('../../../dist/observable-ccb54234.cjs.prod.js');
7
- var httpUtils = require('../../../dist/httpUtils-299a66f6.cjs.prod.js');
6
+ var transformRPCResponse = require('../../../dist/transformRPCResponse-739c13d0.cjs.prod.js');
7
+ var TRPCClientError = require('../../../dist/TRPCClientError-e9bf96e9.cjs.prod.js');
8
+ require('@babel/runtime/helpers/createClass');
9
+ require('@babel/runtime/helpers/classCallCheck');
10
+ require('@babel/runtime/helpers/assertThisInitialized');
11
+ require('@babel/runtime/helpers/inherits');
12
+ require('@babel/runtime/helpers/createSuper');
13
+ require('@babel/runtime/helpers/wrapNativeSuper');
8
14
  require('@babel/runtime/helpers/objectSpread2');
9
15
 
10
16
  /**
@@ -12,7 +18,7 @@ require('@babel/runtime/helpers/objectSpread2');
12
18
  * Less configuration, no caching, and allows you to cancel requests
13
19
  * When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
14
20
  */
15
- function dataLoader(fetchMany) {
21
+ function dataLoader(fetchMany, opts) {
16
22
  var batch = null;
17
23
  var dispatchTimer = null;
18
24
 
@@ -77,6 +83,11 @@ function dataLoader(fetchMany) {
77
83
  item.reject = reject;
78
84
  item.resolve = resolve;
79
85
  thisBatch.items.push(item);
86
+
87
+ if (typeof (opts === null || opts === void 0 ? void 0 : opts.maxBatchSize) !== 'undefined' && thisBatch.items.length >= opts.maxBatchSize) {
88
+ dispatch();
89
+ return;
90
+ }
80
91
  });
81
92
 
82
93
  if (!dispatchTimer) {
@@ -108,8 +119,11 @@ function dataLoader(fetchMany) {
108
119
  }
109
120
 
110
121
  function httpBatchLink(opts) {
111
- var url = opts.url;
122
+ var url = opts.url,
123
+ maxBatchSize = opts.maxBatchSize; // initialized config
124
+
112
125
  return function (runtime) {
126
+ // initialized in app
113
127
  var fetcher = function fetcher(type) {
114
128
  return function (keyInputPairs) {
115
129
  var path = keyInputPairs.map(function (op) {
@@ -119,7 +133,7 @@ function httpBatchLink(opts) {
119
133
  return op.input;
120
134
  });
121
135
 
122
- var _httpRequest = httpUtils.httpRequest({
136
+ var _httpRequest = transformRPCResponse.httpRequest({
123
137
  url: url,
124
138
  inputs: inputs,
125
139
  path: path,
@@ -131,51 +145,67 @@ function httpBatchLink(opts) {
131
145
 
132
146
  return {
133
147
  promise: promise.then(function (res) {
134
- var resJSON = Array.isArray(res.json) ? res.json : keyInputPairs.map(function () {
135
- return res.json;
136
- });
137
- var result = resJSON.map(function (item) {
138
- return {
139
- meta: res.meta,
140
- json: item
141
- };
142
- });
143
- return result;
148
+ if (!Array.isArray(res)) {
149
+ return keyInputPairs.map(function () {
150
+ return res;
151
+ });
152
+ }
153
+
154
+ return res;
144
155
  }),
145
156
  cancel: cancel
146
157
  };
147
158
  };
148
159
  };
149
160
 
150
- var query = dataLoader(fetcher('query'));
151
- var mutation = dataLoader(fetcher('mutation'));
152
- var subscription = dataLoader(fetcher('subscription'));
161
+ var query = dataLoader(fetcher('query'), {
162
+ maxBatchSize: maxBatchSize
163
+ });
164
+ var mutation = dataLoader(fetcher('mutation'), {
165
+ maxBatchSize: maxBatchSize
166
+ });
167
+ var subscription = dataLoader(fetcher('subscription'), {
168
+ maxBatchSize: maxBatchSize
169
+ });
153
170
  var loaders = {
154
171
  query: query,
155
172
  subscription: subscription,
156
173
  mutation: mutation
157
174
  };
158
175
  return function (_ref) {
159
- var op = _ref.op;
160
- return observable.observable(function (observer) {
161
- var loader = loaders[op.type];
162
-
163
- var _loader$load = loader.load(op),
164
- promise = _loader$load.promise,
165
- cancel = _loader$load.cancel;
166
-
167
- promise.then(function (res) {
168
- observer.next({
169
- context: res.meta,
170
- data: res.json
171
- });
172
- observer.complete();
173
- }).catch(function (err) {
174
- return observer.error(err);
175
- });
176
- return function () {
177
- cancel();
178
- };
176
+ var op = _ref.op,
177
+ prev = _ref.prev,
178
+ onDestroy = _ref.onDestroy;
179
+ var loader = loaders[op.type];
180
+
181
+ var _loader$load = loader.load(op),
182
+ promise = _loader$load.promise,
183
+ cancel = _loader$load.cancel;
184
+
185
+ var isDone = false;
186
+
187
+ var prevOnce = function prevOnce(result) {
188
+ if (isDone) {
189
+ return;
190
+ }
191
+
192
+ isDone = true;
193
+ prev(result);
194
+ };
195
+
196
+ onDestroy(function () {
197
+ prevOnce(TRPCClientError.TRPCClientError.from(new transformRPCResponse.TRPCAbortError(), {
198
+ isDone: true
199
+ }));
200
+ cancel();
201
+ });
202
+ promise.then(function (envelope) {
203
+ prevOnce(transformRPCResponse.transformRPCResponse({
204
+ envelope: envelope,
205
+ runtime: runtime
206
+ }));
207
+ }).catch(function (cause) {
208
+ prevOnce(TRPCClientError.TRPCClientError.from(cause));
179
209
  });
180
210
  };
181
211
  };
@@ -1,6 +1,12 @@
1
1
  import _createForOfIteratorHelper from '@babel/runtime/helpers/esm/createForOfIteratorHelper';
2
- import { o as observable } from '../../../dist/observable-01534ea8.esm.js';
3
- import { h as httpRequest } from '../../../dist/httpUtils-e45c9056.esm.js';
2
+ import { T as TRPCAbortError, t as transformRPCResponse, h as httpRequest } from '../../../dist/transformRPCResponse-f7f8b0e1.esm.js';
3
+ import { T as TRPCClientError } from '../../../dist/TRPCClientError-09b8a26b.esm.js';
4
+ import '@babel/runtime/helpers/createClass';
5
+ import '@babel/runtime/helpers/classCallCheck';
6
+ import '@babel/runtime/helpers/assertThisInitialized';
7
+ import '@babel/runtime/helpers/inherits';
8
+ import '@babel/runtime/helpers/createSuper';
9
+ import '@babel/runtime/helpers/wrapNativeSuper';
4
10
  import '@babel/runtime/helpers/objectSpread2';
5
11
 
6
12
  /**
@@ -8,7 +14,7 @@ import '@babel/runtime/helpers/objectSpread2';
8
14
  * Less configuration, no caching, and allows you to cancel requests
9
15
  * When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
10
16
  */
11
- function dataLoader(fetchMany) {
17
+ function dataLoader(fetchMany, opts) {
12
18
  var batch = null;
13
19
  var dispatchTimer = null;
14
20
 
@@ -73,6 +79,11 @@ function dataLoader(fetchMany) {
73
79
  item.reject = reject;
74
80
  item.resolve = resolve;
75
81
  thisBatch.items.push(item);
82
+
83
+ if (typeof (opts === null || opts === void 0 ? void 0 : opts.maxBatchSize) !== 'undefined' && thisBatch.items.length >= opts.maxBatchSize) {
84
+ dispatch();
85
+ return;
86
+ }
76
87
  });
77
88
 
78
89
  if (!dispatchTimer) {
@@ -104,8 +115,11 @@ function dataLoader(fetchMany) {
104
115
  }
105
116
 
106
117
  function httpBatchLink(opts) {
107
- var url = opts.url;
118
+ var url = opts.url,
119
+ maxBatchSize = opts.maxBatchSize; // initialized config
120
+
108
121
  return function (runtime) {
122
+ // initialized in app
109
123
  var fetcher = function fetcher(type) {
110
124
  return function (keyInputPairs) {
111
125
  var path = keyInputPairs.map(function (op) {
@@ -127,51 +141,67 @@ function httpBatchLink(opts) {
127
141
 
128
142
  return {
129
143
  promise: promise.then(function (res) {
130
- var resJSON = Array.isArray(res.json) ? res.json : keyInputPairs.map(function () {
131
- return res.json;
132
- });
133
- var result = resJSON.map(function (item) {
134
- return {
135
- meta: res.meta,
136
- json: item
137
- };
138
- });
139
- return result;
144
+ if (!Array.isArray(res)) {
145
+ return keyInputPairs.map(function () {
146
+ return res;
147
+ });
148
+ }
149
+
150
+ return res;
140
151
  }),
141
152
  cancel: cancel
142
153
  };
143
154
  };
144
155
  };
145
156
 
146
- var query = dataLoader(fetcher('query'));
147
- var mutation = dataLoader(fetcher('mutation'));
148
- var subscription = dataLoader(fetcher('subscription'));
157
+ var query = dataLoader(fetcher('query'), {
158
+ maxBatchSize: maxBatchSize
159
+ });
160
+ var mutation = dataLoader(fetcher('mutation'), {
161
+ maxBatchSize: maxBatchSize
162
+ });
163
+ var subscription = dataLoader(fetcher('subscription'), {
164
+ maxBatchSize: maxBatchSize
165
+ });
149
166
  var loaders = {
150
167
  query: query,
151
168
  subscription: subscription,
152
169
  mutation: mutation
153
170
  };
154
171
  return function (_ref) {
155
- var op = _ref.op;
156
- return observable(function (observer) {
157
- var loader = loaders[op.type];
158
-
159
- var _loader$load = loader.load(op),
160
- promise = _loader$load.promise,
161
- cancel = _loader$load.cancel;
162
-
163
- promise.then(function (res) {
164
- observer.next({
165
- context: res.meta,
166
- data: res.json
167
- });
168
- observer.complete();
169
- }).catch(function (err) {
170
- return observer.error(err);
171
- });
172
- return function () {
173
- cancel();
174
- };
172
+ var op = _ref.op,
173
+ prev = _ref.prev,
174
+ onDestroy = _ref.onDestroy;
175
+ var loader = loaders[op.type];
176
+
177
+ var _loader$load = loader.load(op),
178
+ promise = _loader$load.promise,
179
+ cancel = _loader$load.cancel;
180
+
181
+ var isDone = false;
182
+
183
+ var prevOnce = function prevOnce(result) {
184
+ if (isDone) {
185
+ return;
186
+ }
187
+
188
+ isDone = true;
189
+ prev(result);
190
+ };
191
+
192
+ onDestroy(function () {
193
+ prevOnce(TRPCClientError.from(new TRPCAbortError(), {
194
+ isDone: true
195
+ }));
196
+ cancel();
197
+ });
198
+ promise.then(function (envelope) {
199
+ prevOnce(transformRPCResponse({
200
+ envelope: envelope,
201
+ runtime: runtime
202
+ }));
203
+ }).catch(function (cause) {
204
+ prevOnce(TRPCClientError.from(cause));
175
205
  });
176
206
  };
177
207
  };
@@ -0,0 +1 @@
1
+ export * from '../../dist/links/httpBatchLink';
@@ -0,0 +1 @@
1
+ module.exports = require('../../dist/links/httpBatchLink');
@@ -2,40 +2,63 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var observable = require('../../../dist/observable-9aad8c3e.cjs.dev.js');
6
- var httpUtils = require('../../../dist/httpUtils-a1426e14.cjs.dev.js');
5
+ var TRPCClientError = require('../../../dist/TRPCClientError-bfee2bf5.cjs.dev.js');
6
+ var transformRPCResponse = require('../../../dist/transformRPCResponse-57e80136.cjs.dev.js');
7
7
  require('@babel/runtime/helpers/objectSpread2');
8
+ require('@babel/runtime/helpers/classCallCheck');
9
+ require('@babel/runtime/helpers/createClass');
10
+ require('@babel/runtime/helpers/assertThisInitialized');
11
+ require('@babel/runtime/helpers/inherits');
12
+ require('@babel/runtime/helpers/createSuper');
13
+ require('@babel/runtime/helpers/wrapNativeSuper');
8
14
 
9
15
  function httpLink(opts) {
10
- var url = opts.url;
16
+ var url = opts.url; // initialized config
17
+
11
18
  return function (runtime) {
19
+ // initialized in app
12
20
  return function (_ref) {
13
- var op = _ref.op;
14
- return observable.observable(function (observer) {
15
- var path = op.path,
16
- input = op.input,
17
- type = op.type;
18
-
19
- var _httpRequest = httpUtils.httpRequest({
20
- runtime: runtime,
21
- path: path,
22
- input: input,
23
- type: type,
24
- url: url
25
- }),
26
- promise = _httpRequest.promise,
27
- cancel = _httpRequest.cancel;
28
-
29
- promise.then(function (res) {
30
- observer.next({
31
- context: res.meta,
32
- data: res.json
33
- });
34
- observer.complete();
35
- }).catch(observer.error);
36
- return function () {
37
- cancel();
38
- };
21
+ var op = _ref.op,
22
+ prev = _ref.prev,
23
+ onDestroy = _ref.onDestroy;
24
+ var path = op.path,
25
+ input = op.input,
26
+ type = op.type;
27
+
28
+ var _httpRequest = transformRPCResponse.httpRequest({
29
+ runtime: runtime,
30
+ type: type,
31
+ input: input,
32
+ url: url,
33
+ path: path
34
+ }),
35
+ promise = _httpRequest.promise,
36
+ cancel = _httpRequest.cancel;
37
+
38
+ var isDone = false;
39
+
40
+ var prevOnce = function prevOnce(result) {
41
+ if (isDone) {
42
+ return;
43
+ }
44
+
45
+ isDone = true;
46
+ prev(result);
47
+ };
48
+
49
+ onDestroy(function () {
50
+ prevOnce(TRPCClientError.TRPCClientError.from(new transformRPCResponse.TRPCAbortError(), {
51
+ isDone: true
52
+ }));
53
+ cancel();
54
+ });
55
+ promise.then(function (envelope) {
56
+ prevOnce(transformRPCResponse.transformRPCResponse({
57
+ envelope: envelope,
58
+ runtime: runtime
59
+ }));
60
+ }).catch(function (cause) {
61
+ prevOnce(TRPCClientError.TRPCClientError.from(cause));
39
62
  });
40
63
  };
41
64
  };