@trpc/client 10.0.0-alpha.15 → 10.0.0-alpha.18

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 (155) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1081 -18
  4. package/dist/index.mjs +1064 -13
  5. package/dist/internals/TRPCClient.d.ts +3 -3
  6. package/dist/internals/TRPCClient.d.ts.map +1 -1
  7. package/dist/links/httpBatchLink.d.ts +1 -1
  8. package/dist/links/httpBatchLink.d.ts.map +1 -1
  9. package/dist/links/httpLink.d.ts +1 -1
  10. package/dist/links/httpLink.d.ts.map +1 -1
  11. package/dist/links/index.d.ts +11 -0
  12. package/dist/links/index.d.ts.map +1 -0
  13. package/dist/links/{httpUtils.d.ts → internals/httpUtils.d.ts} +1 -1
  14. package/dist/links/internals/httpUtils.d.ts.map +1 -0
  15. package/dist/links/transformerLink.d.ts.map +1 -1
  16. package/dist/links/types.d.ts +1 -1
  17. package/dist/links/types.d.ts.map +1 -1
  18. package/dist/links/wsLink.d.ts +1 -1
  19. package/dist/links/wsLink.d.ts.map +1 -1
  20. package/dist/observable/index.d.ts +4 -0
  21. package/dist/observable/index.d.ts.map +1 -0
  22. package/dist/{rx/operators → observable}/index.js +3 -3
  23. package/dist/{rx/operators → observable}/index.mjs +1 -2
  24. package/dist/{rx → observable}/index.ts.js +0 -0
  25. package/dist/{rx/util → observable/internals}/identity.d.ts +0 -0
  26. package/dist/observable/internals/identity.d.ts.map +1 -0
  27. package/dist/{rx/util → observable/internals}/observableToPromise.d.ts +0 -0
  28. package/dist/observable/internals/observableToPromise.d.ts.map +1 -0
  29. package/dist/{rx/util → observable/internals}/pipe.d.ts +0 -0
  30. package/dist/observable/internals/pipe.d.ts.map +1 -0
  31. package/dist/{rx → observable}/observable.d.ts +0 -0
  32. package/dist/observable/observable.d.ts.map +1 -0
  33. package/dist/{rx → observable}/operators/index.d.ts +0 -0
  34. package/dist/observable/operators/index.d.ts.map +1 -0
  35. package/dist/{rx → observable}/operators/map.d.ts +0 -0
  36. package/dist/observable/operators/map.d.ts.map +1 -0
  37. package/dist/{rx → observable}/operators/share.d.ts +0 -0
  38. package/dist/observable/operators/share.d.ts.map +1 -0
  39. package/dist/{rx → observable}/operators/tap.d.ts +0 -0
  40. package/dist/observable/operators/tap.d.ts.map +1 -0
  41. package/dist/{rx → observable}/types.d.ts +0 -0
  42. package/dist/observable/types.d.ts.map +1 -0
  43. package/dist/{share-671b63fa.mjs → tap-4bc60fb0.mjs} +131 -1
  44. package/dist/{share-4d79dc49.js → tap-fcd41ae6.js} +132 -0
  45. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.d.ts +1 -11
  46. package/{dist/links/httpBatchLink.js → links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js} +63 -44
  47. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.js +6 -15
  48. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +214 -0
  49. package/{dist/links/httpBatchLink.mjs → links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js} +62 -43
  50. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.d.ts +1 -11
  51. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +67 -0
  52. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.js +6 -15
  53. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +67 -0
  54. package/links/httpLink/dist/trpc-client-links-httpLink.esm.js +63 -0
  55. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.d.ts +1 -11
  56. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.dev.js +89 -0
  57. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.js +6 -15
  58. package/links/loggerLink/dist/trpc-client-links-loggerLink.cjs.prod.js +89 -0
  59. package/links/loggerLink/dist/trpc-client-links-loggerLink.esm.js +85 -0
  60. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.d.ts +1 -11
  61. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.dev.js +19 -0
  62. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.js +6 -15
  63. package/links/splitLink/dist/trpc-client-links-splitLink.cjs.prod.js +19 -0
  64. package/links/splitLink/dist/trpc-client-links-splitLink.esm.js +15 -0
  65. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.d.ts +1 -11
  66. package/{dist/links/wsLink.js → links/wsLink/dist/trpc-client-links-wsLink.cjs.dev.js} +92 -82
  67. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.js +6 -15
  68. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +395 -0
  69. package/{dist/links/wsLink.mjs → links/wsLink/dist/trpc-client-links-wsLink.esm.js} +87 -67
  70. package/package.json +8 -43
  71. package/src/index.ts +1 -1
  72. package/src/internals/TRPCClient.ts +8 -11
  73. package/src/links/dedupeLink.test.ts +1 -1
  74. package/src/links/dedupeLink.ts +5 -5
  75. package/src/links/httpBatchLink.ts +6 -2
  76. package/src/links/httpLink.ts +2 -2
  77. package/src/links/index.ts +10 -0
  78. package/src/links/internals/createChain.test.ts +5 -5
  79. package/src/links/internals/createChain.ts +3 -3
  80. package/src/links/{httpUtils.ts → internals/httpUtils.ts} +1 -1
  81. package/src/links/loggerLink.ts +2 -2
  82. package/src/links/retryLink.ts +2 -2
  83. package/src/links/splitLink.test.ts +3 -3
  84. package/src/links/splitLink.ts +1 -1
  85. package/src/links/transformerLink.ts +9 -5
  86. package/src/links/types.ts +1 -1
  87. package/src/links/wsLink.ts +1 -2
  88. package/src/{rx → observable}/index.ts +1 -0
  89. package/src/{rx/util → observable/internals}/identity.ts +0 -0
  90. package/src/{rx/util → observable/internals}/observableToPromise.ts +0 -0
  91. package/src/{rx/util → observable/internals}/pipe.ts +0 -0
  92. package/src/{rx → observable}/observable.test.ts +21 -1
  93. package/src/{rx → observable}/observable.ts +1 -1
  94. package/src/{rx → observable}/operators/index.ts +0 -0
  95. package/src/{rx → observable}/operators/map.test.ts +0 -0
  96. package/src/{rx → observable}/operators/map.ts +0 -0
  97. package/src/{rx → observable}/operators/share.test.ts +0 -0
  98. package/src/{rx → observable}/operators/share.ts +0 -0
  99. package/src/{rx → observable}/operators/tap.ts +0 -0
  100. package/src/{rx → observable}/types.ts +0 -0
  101. package/dist/TRPCClientError-17b117e1.mjs +0 -81
  102. package/dist/TRPCClientError-ec6bd2ca.js +0 -94
  103. package/dist/createChain-389cc116.mjs +0 -25
  104. package/dist/createChain-864dbb30.js +0 -27
  105. package/dist/httpUtils-1f9e4e3c.js +0 -97
  106. package/dist/httpUtils-c09d7b79.mjs +0 -91
  107. package/dist/links/httpBatchLink.ts.js +0 -1
  108. package/dist/links/httpLink.js +0 -44
  109. package/dist/links/httpLink.mjs +0 -40
  110. package/dist/links/httpLink.ts.js +0 -1
  111. package/dist/links/httpUtils.d.ts.map +0 -1
  112. package/dist/links/loggerLink.js +0 -108
  113. package/dist/links/loggerLink.mjs +0 -99
  114. package/dist/links/loggerLink.ts.js +0 -1
  115. package/dist/links/splitLink.js +0 -32
  116. package/dist/links/splitLink.mjs +0 -28
  117. package/dist/links/splitLink.ts.js +0 -1
  118. package/dist/links/transformerLink.js +0 -75
  119. package/dist/links/transformerLink.mjs +0 -67
  120. package/dist/links/transformerLink.ts.js +0 -1
  121. package/dist/links/wsLink.ts.js +0 -1
  122. package/dist/observable-7e66cb56.mjs +0 -102
  123. package/dist/observable-85669100.js +0 -104
  124. package/dist/rx/index.d.ts +0 -3
  125. package/dist/rx/index.d.ts.map +0 -1
  126. package/dist/rx/index.js +0 -9
  127. package/dist/rx/index.mjs +0 -1
  128. package/dist/rx/observable.d.ts.map +0 -1
  129. package/dist/rx/operators/index.d.ts.map +0 -1
  130. package/dist/rx/operators/index.ts.js +0 -1
  131. package/dist/rx/operators/map.d.ts.map +0 -1
  132. package/dist/rx/operators/share.d.ts.map +0 -1
  133. package/dist/rx/operators/tap.d.ts.map +0 -1
  134. package/dist/rx/types.d.ts.map +0 -1
  135. package/dist/rx/util/identity.d.ts.map +0 -1
  136. package/dist/rx/util/observableToPromise.d.ts.map +0 -1
  137. package/dist/rx/util/pipe.d.ts.map +0 -1
  138. package/dist/tap-538fa07f.mjs +0 -30
  139. package/dist/tap-799a2d33.js +0 -32
  140. package/links/httpBatchLink/index.d.ts +0 -1
  141. package/links/httpBatchLink/index.js +0 -1
  142. package/links/httpLink/index.d.ts +0 -1
  143. package/links/httpLink/index.js +0 -1
  144. package/links/loggerLink/index.d.ts +0 -1
  145. package/links/loggerLink/index.js +0 -1
  146. package/links/splitLink/index.d.ts +0 -1
  147. package/links/splitLink/index.js +0 -1
  148. package/links/transformerLink/index.d.ts +0 -1
  149. package/links/transformerLink/index.js +0 -1
  150. package/links/wsLink/index.d.ts +0 -1
  151. package/links/wsLink/index.js +0 -1
  152. package/rx/index.d.ts +0 -1
  153. package/rx/index.js +0 -1
  154. package/rx/operators/index.d.ts +0 -1
  155. package/rx/operators/index.js +0 -1
@@ -2,15 +2,16 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var observable = require('../observable-85669100.js');
6
- var httpUtils = require('../httpUtils-1f9e4e3c.js');
7
- require('@babel/runtime/helpers/defineProperty');
8
-
9
- 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; } } }; }
10
-
11
- 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); }
12
-
13
- 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; }
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');
14
15
 
15
16
  /**
16
17
  * Dataloader that's very inspired by https://github.com/graphql/dataloader
@@ -118,9 +119,11 @@ function dataLoader(fetchMany, opts) {
118
119
  }
119
120
 
120
121
  function httpBatchLink(opts) {
121
- var url = opts.url; // initialized config
122
+ var url = opts.url,
123
+ maxBatchSize = opts.maxBatchSize; // initialized config
122
124
 
123
125
  return function (runtime) {
126
+ // initialized in app
124
127
  var fetcher = function fetcher(type) {
125
128
  return function (keyInputPairs) {
126
129
  var path = keyInputPairs.map(function (op) {
@@ -130,7 +133,7 @@ function httpBatchLink(opts) {
130
133
  return op.input;
131
134
  });
132
135
 
133
- var _httpRequest = httpUtils.httpRequest({
136
+ var _httpRequest = transformRPCResponse.httpRequest({
134
137
  url: url,
135
138
  inputs: inputs,
136
139
  path: path,
@@ -142,51 +145,67 @@ function httpBatchLink(opts) {
142
145
 
143
146
  return {
144
147
  promise: promise.then(function (res) {
145
- var resJSON = Array.isArray(res.json) ? res.json : keyInputPairs.map(function () {
146
- return res.json;
147
- });
148
- var result = resJSON.map(function (item) {
149
- return {
150
- meta: res.meta,
151
- json: item
152
- };
153
- });
154
- return result;
148
+ if (!Array.isArray(res)) {
149
+ return keyInputPairs.map(function () {
150
+ return res;
151
+ });
152
+ }
153
+
154
+ return res;
155
155
  }),
156
156
  cancel: cancel
157
157
  };
158
158
  };
159
159
  };
160
160
 
161
- var query = dataLoader(fetcher('query'), opts);
162
- var mutation = dataLoader(fetcher('mutation'), opts);
163
- var subscription = dataLoader(fetcher('subscription'), opts);
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
+ });
164
170
  var loaders = {
165
171
  query: query,
166
172
  subscription: subscription,
167
173
  mutation: mutation
168
174
  };
169
175
  return function (_ref) {
170
- var op = _ref.op;
171
- return observable.observable(function (observer) {
172
- var loader = loaders[op.type];
173
-
174
- var _loader$load = loader.load(op),
175
- promise = _loader$load.promise,
176
- cancel = _loader$load.cancel;
177
-
178
- promise.then(function (res) {
179
- observer.next({
180
- context: res.meta,
181
- data: res.json
182
- });
183
- observer.complete();
184
- }).catch(function (err) {
185
- return observer.error(err);
186
- });
187
- return function () {
188
- cancel();
189
- };
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));
190
209
  });
191
210
  };
192
211
  };
@@ -1,16 +1,7 @@
1
- "use strict";
2
- // this file might look strange and you might be wondering what it's for
3
- // it's lets you import your source files by importing this entrypoint
4
- // as you would import it if it was built with preconstruct build
5
- // this file is slightly different to some others though
6
- // it has a require hook which compiles your code with Babel
7
- // this means that you don't have to set up @babel/register or anything like that
8
- // but you can still require this module and it'll be compiled
1
+ 'use strict';
9
2
 
10
- // this bit of code imports the require hook and registers it
11
- let unregister = require("../../../../../node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../../../..", "../../..");
12
-
13
- // this re-exports the source file
14
- module.exports = require("../../../src/links/httpBatchLink.ts");
15
-
16
- unregister();
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
+ }
@@ -0,0 +1,214 @@
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;
@@ -1,12 +1,13 @@
1
- import { o as observable } from '../observable-7e66cb56.mjs';
2
- import { h as httpRequest } from '../httpUtils-c09d7b79.mjs';
3
- import '@babel/runtime/helpers/defineProperty';
4
-
5
- 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; } } }; }
6
-
7
- 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); }
8
-
9
- 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; }
1
+ import _createForOfIteratorHelper from '@babel/runtime/helpers/esm/createForOfIteratorHelper';
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';
10
+ import '@babel/runtime/helpers/objectSpread2';
10
11
 
11
12
  /**
12
13
  * Dataloader that's very inspired by https://github.com/graphql/dataloader
@@ -114,9 +115,11 @@ function dataLoader(fetchMany, opts) {
114
115
  }
115
116
 
116
117
  function httpBatchLink(opts) {
117
- var url = opts.url; // initialized config
118
+ var url = opts.url,
119
+ maxBatchSize = opts.maxBatchSize; // initialized config
118
120
 
119
121
  return function (runtime) {
122
+ // initialized in app
120
123
  var fetcher = function fetcher(type) {
121
124
  return function (keyInputPairs) {
122
125
  var path = keyInputPairs.map(function (op) {
@@ -138,51 +141,67 @@ function httpBatchLink(opts) {
138
141
 
139
142
  return {
140
143
  promise: promise.then(function (res) {
141
- var resJSON = Array.isArray(res.json) ? res.json : keyInputPairs.map(function () {
142
- return res.json;
143
- });
144
- var result = resJSON.map(function (item) {
145
- return {
146
- meta: res.meta,
147
- json: item
148
- };
149
- });
150
- return result;
144
+ if (!Array.isArray(res)) {
145
+ return keyInputPairs.map(function () {
146
+ return res;
147
+ });
148
+ }
149
+
150
+ return res;
151
151
  }),
152
152
  cancel: cancel
153
153
  };
154
154
  };
155
155
  };
156
156
 
157
- var query = dataLoader(fetcher('query'), opts);
158
- var mutation = dataLoader(fetcher('mutation'), opts);
159
- var subscription = dataLoader(fetcher('subscription'), opts);
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
+ });
160
166
  var loaders = {
161
167
  query: query,
162
168
  subscription: subscription,
163
169
  mutation: mutation
164
170
  };
165
171
  return function (_ref) {
166
- var op = _ref.op;
167
- return observable(function (observer) {
168
- var loader = loaders[op.type];
169
-
170
- var _loader$load = loader.load(op),
171
- promise = _loader$load.promise,
172
- cancel = _loader$load.cancel;
173
-
174
- promise.then(function (res) {
175
- observer.next({
176
- context: res.meta,
177
- data: res.json
178
- });
179
- observer.complete();
180
- }).catch(function (err) {
181
- return observer.error(err);
182
- });
183
- return function () {
184
- cancel();
185
- };
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));
186
205
  });
187
206
  };
188
207
  };
@@ -1,11 +1 @@
1
- // are you seeing an error that a default export doesn't exist but your source file has a default export?
2
- // you should run `yarn` or `yarn preconstruct dev` if preconstruct dev isn't in your postinstall hook
3
-
4
- // curious why you need to?
5
- // this file exists so that you can import from the entrypoint normally
6
- // except that it points to your source file and you don't need to run build constantly
7
- // which means we need to re-export all of the modules from your source file
8
- // and since export * doesn't include default exports, we need to read your source file
9
- // to check for a default export and re-export it if it exists
10
- // it's not ideal, but it works pretty well ¯\_(ツ)_/¯
11
- export * from "../../../src/links/httpLink";
1
+ export * from "../../../dist/declarations/src/links/httpLink";
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var TRPCClientError = require('../../../dist/TRPCClientError-bfee2bf5.cjs.dev.js');
6
+ var transformRPCResponse = require('../../../dist/transformRPCResponse-57e80136.cjs.dev.js');
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');
14
+
15
+ function httpLink(opts) {
16
+ var url = opts.url; // initialized config
17
+
18
+ return function (runtime) {
19
+ // initialized in app
20
+ return function (_ref) {
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));
62
+ });
63
+ };
64
+ };
65
+ }
66
+
67
+ exports.httpLink = httpLink;
@@ -1,16 +1,7 @@
1
- "use strict";
2
- // this file might look strange and you might be wondering what it's for
3
- // it's lets you import your source files by importing this entrypoint
4
- // as you would import it if it was built with preconstruct build
5
- // this file is slightly different to some others though
6
- // it has a require hook which compiles your code with Babel
7
- // this means that you don't have to set up @babel/register or anything like that
8
- // but you can still require this module and it'll be compiled
1
+ 'use strict';
9
2
 
10
- // this bit of code imports the require hook and registers it
11
- let unregister = require("../../../../../node_modules/@preconstruct/hook").___internalHook(typeof __dirname === 'undefined' ? undefined : __dirname, "../../../../..", "../../..");
12
-
13
- // this re-exports the source file
14
- module.exports = require("../../../src/links/httpLink.ts");
15
-
16
- unregister();
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./trpc-client-links-httpLink.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./trpc-client-links-httpLink.cjs.dev.js");
7
+ }