@trpc/client 10.0.0-alpha.12 → 10.0.0-alpha.13

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 (77) hide show
  1. package/dist/{httpUtils-1f9e4e3c.js → httpUtils-27640b42.js} +0 -0
  2. package/dist/{httpUtils-c09d7b79.mjs → httpUtils-b92552af.mjs} +0 -0
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +138 -9
  6. package/dist/index.mjs +128 -6
  7. package/dist/links/httpBatchLink.d.ts +1 -1
  8. package/dist/links/httpBatchLink.d.ts.map +1 -1
  9. package/dist/links/httpBatchLink.js +1 -1
  10. package/dist/links/httpBatchLink.mjs +1 -1
  11. package/dist/links/httpLink.d.ts +1 -1
  12. package/dist/links/httpLink.d.ts.map +1 -1
  13. package/dist/links/httpLink.js +1 -1
  14. package/dist/links/httpLink.mjs +1 -1
  15. package/dist/links/index.d.ts +11 -0
  16. package/dist/links/index.d.ts.map +1 -0
  17. package/dist/links/{httpUtils.d.ts → internals/httpUtils.d.ts} +1 -1
  18. package/dist/links/internals/httpUtils.d.ts.map +1 -0
  19. package/dist/links/splitLink.js +3 -25
  20. package/dist/links/splitLink.mjs +2 -28
  21. package/dist/links/wsLink.js +11 -377
  22. package/dist/links/wsLink.mjs +9 -369
  23. package/dist/{createChain-e77be464.js → splitLink-8635d455.js} +25 -0
  24. package/dist/{createChain-480b6341.mjs → splitLink-a736378a.mjs} +25 -1
  25. package/dist/wsLink-a6a0f3a8.mjs +440 -0
  26. package/dist/wsLink-c9323097.js +455 -0
  27. package/package.json +4 -34
  28. package/src/index.ts +1 -1
  29. package/src/links/httpBatchLink.ts +5 -1
  30. package/src/links/httpLink.ts +1 -1
  31. package/src/links/index.ts +10 -0
  32. package/src/links/{httpUtils.ts → internals/httpUtils.ts} +1 -1
  33. package/dist/TRPCClientError-17b117e1.mjs +0 -81
  34. package/dist/TRPCClientError-ec6bd2ca.js +0 -94
  35. package/dist/links/httpUtils.d.ts.map +0 -1
  36. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.d.ts +0 -1
  37. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js +0 -214
  38. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.js +0 -7
  39. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +0 -214
  40. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js +0 -210
  41. package/links/httpBatchLink/index.d.ts +0 -1
  42. package/links/httpBatchLink/index.js +0 -1
  43. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.d.ts +0 -1
  44. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +0 -67
  45. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.js +0 -7
  46. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +0 -67
  47. package/links/httpLink/dist/trpc-client-links-httpLink.esm.js +0 -63
  48. package/links/httpLink/index.d.ts +0 -1
  49. package/links/httpLink/index.js +0 -1
  50. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.d.ts +0 -1
  51. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.dev.js +0 -89
  52. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.js +0 -7
  53. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.prod.js +0 -89
  54. package/links/loggerLink/dist/trpc-client-links-loggerLink.esm.js +0 -85
  55. package/links/loggerLink/index.d.ts +0 -1
  56. package/links/loggerLink/index.js +0 -1
  57. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.d.ts +0 -1
  58. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.dev.js +0 -19
  59. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.js +0 -7
  60. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.prod.js +0 -19
  61. package/links/splitLink/dist/trpc-client-links-splitLink.esm.js +0 -15
  62. package/links/splitLink/index.d.ts +0 -1
  63. package/links/splitLink/index.js +0 -1
  64. package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.d.ts +0 -1
  65. package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.dev.js +0 -67
  66. package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.js +0 -7
  67. package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.prod.js +0 -67
  68. package/links/transformerLink/dist/trpc-client-links-transformerLink.esm.js +0 -63
  69. package/links/transformerLink/index.d.ts +0 -1
  70. package/links/transformerLink/index.js +0 -1
  71. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.d.ts +0 -1
  72. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.dev.js +0 -395
  73. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.js +0 -7
  74. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +0 -395
  75. package/links/wsLink/dist/trpc-client-links-wsLink.esm.js +0 -390
  76. package/links/wsLink/index.d.ts +0 -1
  77. package/links/wsLink/index.js +0 -1
@@ -1,94 +0,0 @@
1
- 'use strict';
2
-
3
- var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
- var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
5
- var _createClass = require('@babel/runtime/helpers/createClass');
6
- var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized');
7
- var _inherits = require('@babel/runtime/helpers/inherits');
8
- var _possibleConstructorReturn = require('@babel/runtime/helpers/possibleConstructorReturn');
9
- var _getPrototypeOf = require('@babel/runtime/helpers/getPrototypeOf');
10
- var _wrapNativeSuper = require('@babel/runtime/helpers/wrapNativeSuper');
11
-
12
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
-
14
- var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
15
- var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
16
- var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
17
- var _assertThisInitialized__default = /*#__PURE__*/_interopDefaultLegacy(_assertThisInitialized);
18
- var _inherits__default = /*#__PURE__*/_interopDefaultLegacy(_inherits);
19
- var _possibleConstructorReturn__default = /*#__PURE__*/_interopDefaultLegacy(_possibleConstructorReturn);
20
- var _getPrototypeOf__default = /*#__PURE__*/_interopDefaultLegacy(_getPrototypeOf);
21
- var _wrapNativeSuper__default = /*#__PURE__*/_interopDefaultLegacy(_wrapNativeSuper);
22
-
23
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
24
-
25
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
26
-
27
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
28
-
29
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
30
-
31
- var TRPCClientError = /*#__PURE__*/function (_Error) {
32
- _inherits__default["default"](TRPCClientError, _Error);
33
-
34
- var _super = /*#__PURE__*/_createSuper(TRPCClientError);
35
-
36
- /**
37
- * @deprecated use `cause`
38
- */
39
- function TRPCClientError(message, opts) {
40
- var _opts$cause, _opts$result, _opts$result2;
41
-
42
- var _this;
43
-
44
- _classCallCheck__default["default"](this, TRPCClientError);
45
-
46
- var cause = (_opts$cause = opts === null || opts === void 0 ? void 0 : opts.cause) !== null && _opts$cause !== void 0 ? _opts$cause : opts === null || opts === void 0 ? void 0 : opts.originalError; // eslint-disable-next-line @typescript-eslint/ban-ts-comment
47
- // @ts-ignore https://github.com/tc39/proposal-error-cause
48
-
49
- _this = _super.call(this, message, {
50
- cause: cause
51
- });
52
- _this.originalError = void 0;
53
- _this.cause = void 0;
54
- _this.shape = void 0;
55
- _this.data = void 0;
56
- _this.meta = void 0;
57
- _this.meta = opts === null || opts === void 0 ? void 0 : opts.meta;
58
- _this.cause = _this.originalError = cause;
59
- _this.shape = opts === null || opts === void 0 ? void 0 : (_opts$result = opts.result) === null || _opts$result === void 0 ? void 0 : _opts$result.error;
60
- _this.data = opts === null || opts === void 0 ? void 0 : (_opts$result2 = opts.result) === null || _opts$result2 === void 0 ? void 0 : _opts$result2.error.data;
61
- _this.name = 'TRPCClientError';
62
- Object.setPrototypeOf(_assertThisInitialized__default["default"](_this), TRPCClientError.prototype);
63
- return _this;
64
- }
65
-
66
- _createClass__default["default"](TRPCClientError, null, [{
67
- key: "from",
68
- value: function from(cause) {
69
- var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
70
-
71
- if (!(cause instanceof Error)) {
72
- var _message;
73
-
74
- return new TRPCClientError((_message = cause.error.message) !== null && _message !== void 0 ? _message : '', _objectSpread(_objectSpread({}, opts), {}, {
75
- cause: null,
76
- result: cause
77
- }));
78
- }
79
-
80
- if (cause.name === 'TRPCClientError') {
81
- return cause;
82
- }
83
-
84
- return new TRPCClientError(cause.message, _objectSpread(_objectSpread({}, opts), {}, {
85
- cause: cause,
86
- result: null
87
- }));
88
- }
89
- }]);
90
-
91
- return TRPCClientError;
92
- }( /*#__PURE__*/_wrapNativeSuper__default["default"](Error));
93
-
94
- exports.TRPCClientError = TRPCClientError;
@@ -1 +0,0 @@
1
- {"version":3,"file":"httpUtils.d.ts","sourceRoot":"","sources":["../../src/links/httpUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AACxD,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;CACb;AAiBD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE;QACJ,QAAQ,EAAE,QAAQ,CAAC;KACpB,CAAC;CACH;AACD,wBAAgB,WAAW,CACzB,KAAK,EAAE;IACL,OAAO,EAAE,WAAW,CAAC;IACrB,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;CACb,GAAG,CAAC;IAAE,MAAM,EAAE,OAAO,EAAE,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC,GAC/C,gBAAgB,CAAC,aAAa,CAAC,CA2DjC"}
@@ -1 +0,0 @@
1
- export * from "../../../dist/declarations/src/links/httpBatchLink";
@@ -1,214 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
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');
14
- require('@babel/runtime/helpers/objectSpread2');
15
-
16
- /**
17
- * Dataloader that's very inspired by https://github.com/graphql/dataloader
18
- * Less configuration, no caching, and allows you to cancel requests
19
- * When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
20
- */
21
- function dataLoader(fetchMany, opts) {
22
- var batch = null;
23
- var dispatchTimer = null;
24
-
25
- var destroyTimerAndBatch = function destroyTimerAndBatch() {
26
- clearTimeout(dispatchTimer);
27
- dispatchTimer = null;
28
- batch = null;
29
- };
30
-
31
- function dispatch() {
32
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
33
- var batchCopy = batch;
34
- destroyTimerAndBatch();
35
-
36
- var _fetchMany = fetchMany(batchCopy.items.map(function (v) {
37
- return v.key;
38
- })),
39
- promise = _fetchMany.promise,
40
- cancel = _fetchMany.cancel;
41
-
42
- batchCopy.cancel = cancel;
43
- promise.then(function (result) {
44
- for (var i = 0; i < result.length; i++) {
45
- var _value = result[i];
46
- batchCopy.items[i].resolve(_value);
47
- }
48
- }).catch(function (cause) {
49
- var _iterator = _createForOfIteratorHelper(batchCopy.items),
50
- _step;
51
-
52
- try {
53
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
54
- var item = _step.value;
55
- item.reject(cause);
56
- }
57
- } catch (err) {
58
- _iterator.e(err);
59
- } finally {
60
- _iterator.f();
61
- }
62
- });
63
- }
64
-
65
- function load(key) {
66
- var batchItem = {
67
- cancelled: false,
68
- key: key
69
- };
70
-
71
- if (!batch) {
72
- batch = {
73
- items: [],
74
- cancel: function cancel() {
75
- destroyTimerAndBatch();
76
- }
77
- };
78
- }
79
-
80
- var thisBatch = batch;
81
- var promise = new Promise(function (resolve, reject) {
82
- var item = batchItem;
83
- item.reject = reject;
84
- item.resolve = resolve;
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
- }
91
- });
92
-
93
- if (!dispatchTimer) {
94
- dispatchTimer = setTimeout(dispatch);
95
- }
96
-
97
- var cancel = function cancel() {
98
- batchItem.cancelled = true;
99
-
100
- if (thisBatch.items.some(function (item) {
101
- return !item.cancelled;
102
- })) {
103
- // there are still things that can be resolved
104
- return;
105
- }
106
-
107
- thisBatch.cancel();
108
- };
109
-
110
- return {
111
- promise: promise,
112
- cancel: cancel
113
- };
114
- }
115
-
116
- return {
117
- load: load
118
- };
119
- }
120
-
121
- function httpBatchLink(opts) {
122
- var url = opts.url,
123
- maxBatchSize = opts.maxBatchSize; // initialized config
124
-
125
- return function (runtime) {
126
- // initialized in app
127
- var fetcher = function fetcher(type) {
128
- return function (keyInputPairs) {
129
- var path = keyInputPairs.map(function (op) {
130
- return op.path;
131
- }).join(',');
132
- var inputs = keyInputPairs.map(function (op) {
133
- return op.input;
134
- });
135
-
136
- var _httpRequest = transformRPCResponse.httpRequest({
137
- url: url,
138
- inputs: inputs,
139
- path: path,
140
- runtime: runtime,
141
- type: type
142
- }),
143
- promise = _httpRequest.promise,
144
- cancel = _httpRequest.cancel;
145
-
146
- return {
147
- promise: promise.then(function (res) {
148
- if (!Array.isArray(res)) {
149
- return keyInputPairs.map(function () {
150
- return res;
151
- });
152
- }
153
-
154
- return res;
155
- }),
156
- cancel: cancel
157
- };
158
- };
159
- };
160
-
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
- });
170
- var loaders = {
171
- query: query,
172
- subscription: subscription,
173
- mutation: mutation
174
- };
175
- return function (_ref) {
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));
209
- });
210
- };
211
- };
212
- }
213
-
214
- exports.httpBatchLink = httpBatchLink;
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- if (process.env.NODE_ENV === "production") {
4
- module.exports = require("./trpc-client-links-httpBatchLink.cjs.prod.js");
5
- } else {
6
- module.exports = require("./trpc-client-links-httpBatchLink.cjs.dev.js");
7
- }
@@ -1,214 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
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');
14
- require('@babel/runtime/helpers/objectSpread2');
15
-
16
- /**
17
- * Dataloader that's very inspired by https://github.com/graphql/dataloader
18
- * Less configuration, no caching, and allows you to cancel requests
19
- * When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
20
- */
21
- function dataLoader(fetchMany, opts) {
22
- var batch = null;
23
- var dispatchTimer = null;
24
-
25
- var destroyTimerAndBatch = function destroyTimerAndBatch() {
26
- clearTimeout(dispatchTimer);
27
- dispatchTimer = null;
28
- batch = null;
29
- };
30
-
31
- function dispatch() {
32
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
33
- var batchCopy = batch;
34
- destroyTimerAndBatch();
35
-
36
- var _fetchMany = fetchMany(batchCopy.items.map(function (v) {
37
- return v.key;
38
- })),
39
- promise = _fetchMany.promise,
40
- cancel = _fetchMany.cancel;
41
-
42
- batchCopy.cancel = cancel;
43
- promise.then(function (result) {
44
- for (var i = 0; i < result.length; i++) {
45
- var _value = result[i];
46
- batchCopy.items[i].resolve(_value);
47
- }
48
- }).catch(function (cause) {
49
- var _iterator = _createForOfIteratorHelper(batchCopy.items),
50
- _step;
51
-
52
- try {
53
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
54
- var item = _step.value;
55
- item.reject(cause);
56
- }
57
- } catch (err) {
58
- _iterator.e(err);
59
- } finally {
60
- _iterator.f();
61
- }
62
- });
63
- }
64
-
65
- function load(key) {
66
- var batchItem = {
67
- cancelled: false,
68
- key: key
69
- };
70
-
71
- if (!batch) {
72
- batch = {
73
- items: [],
74
- cancel: function cancel() {
75
- destroyTimerAndBatch();
76
- }
77
- };
78
- }
79
-
80
- var thisBatch = batch;
81
- var promise = new Promise(function (resolve, reject) {
82
- var item = batchItem;
83
- item.reject = reject;
84
- item.resolve = resolve;
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
- }
91
- });
92
-
93
- if (!dispatchTimer) {
94
- dispatchTimer = setTimeout(dispatch);
95
- }
96
-
97
- var cancel = function cancel() {
98
- batchItem.cancelled = true;
99
-
100
- if (thisBatch.items.some(function (item) {
101
- return !item.cancelled;
102
- })) {
103
- // there are still things that can be resolved
104
- return;
105
- }
106
-
107
- thisBatch.cancel();
108
- };
109
-
110
- return {
111
- promise: promise,
112
- cancel: cancel
113
- };
114
- }
115
-
116
- return {
117
- load: load
118
- };
119
- }
120
-
121
- function httpBatchLink(opts) {
122
- var url = opts.url,
123
- maxBatchSize = opts.maxBatchSize; // initialized config
124
-
125
- return function (runtime) {
126
- // initialized in app
127
- var fetcher = function fetcher(type) {
128
- return function (keyInputPairs) {
129
- var path = keyInputPairs.map(function (op) {
130
- return op.path;
131
- }).join(',');
132
- var inputs = keyInputPairs.map(function (op) {
133
- return op.input;
134
- });
135
-
136
- var _httpRequest = transformRPCResponse.httpRequest({
137
- url: url,
138
- inputs: inputs,
139
- path: path,
140
- runtime: runtime,
141
- type: type
142
- }),
143
- promise = _httpRequest.promise,
144
- cancel = _httpRequest.cancel;
145
-
146
- return {
147
- promise: promise.then(function (res) {
148
- if (!Array.isArray(res)) {
149
- return keyInputPairs.map(function () {
150
- return res;
151
- });
152
- }
153
-
154
- return res;
155
- }),
156
- cancel: cancel
157
- };
158
- };
159
- };
160
-
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
- });
170
- var loaders = {
171
- query: query,
172
- subscription: subscription,
173
- mutation: mutation
174
- };
175
- return function (_ref) {
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));
209
- });
210
- };
211
- };
212
- }
213
-
214
- exports.httpBatchLink = httpBatchLink;