@trpc/client 9.20.1 → 10.0.0-alpha.10

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 (154) hide show
  1. package/dist/TRPCClientError-17b117e1.mjs +81 -0
  2. package/dist/TRPCClientError-ec6bd2ca.js +94 -0
  3. package/dist/{declarations/src/TRPCClientError.d.ts → TRPCClientError.d.ts} +29 -33
  4. package/dist/TRPCClientError.d.ts.map +1 -0
  5. package/dist/createChain-3b458753.js +27 -0
  6. package/dist/createChain-b7cb1f5a.mjs +25 -0
  7. package/dist/{declarations/src/createTRPCClient.d.ts → createTRPCClient.d.ts} +5 -6
  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-1f9e4e3c.js +97 -0
  12. package/dist/httpUtils-c09d7b79.mjs +91 -0
  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/index.js +243 -0
  16. package/dist/index.mjs +233 -0
  17. package/dist/index.ts.js +1 -0
  18. package/dist/{declarations/src/internals → internals}/TRPCClient.d.ts +62 -61
  19. package/dist/internals/TRPCClient.d.ts.map +1 -0
  20. package/dist/{declarations/src/internals → internals}/dataLoader.d.ts +16 -16
  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/links/dedupeLink.d.ts +4 -0
  27. package/dist/links/dedupeLink.d.ts.map +1 -0
  28. package/dist/{declarations/src/links → links}/httpBatchLink.d.ts +7 -6
  29. package/dist/links/httpBatchLink.d.ts.map +1 -0
  30. package/dist/links/httpBatchLink.js +195 -0
  31. package/dist/links/httpBatchLink.mjs +191 -0
  32. package/dist/links/httpBatchLink.ts.js +1 -0
  33. package/dist/{declarations/src/links → links}/httpLink.d.ts +4 -3
  34. package/dist/links/httpLink.d.ts.map +1 -0
  35. package/dist/links/httpLink.js +44 -0
  36. package/dist/links/httpLink.mjs +40 -0
  37. package/dist/links/httpLink.ts.js +1 -0
  38. package/dist/links/httpUtils.d.ts +22 -0
  39. package/dist/links/httpUtils.d.ts.map +1 -0
  40. package/dist/links/internals/createChain.d.ts +8 -0
  41. package/dist/links/internals/createChain.d.ts.map +1 -0
  42. package/dist/links/internals/transformOperationResult.d.ts +16 -0
  43. package/dist/links/internals/transformOperationResult.d.ts.map +1 -0
  44. package/dist/{declarations/src/links → links}/loggerLink.d.ts +38 -37
  45. package/dist/links/loggerLink.d.ts.map +1 -0
  46. package/dist/links/loggerLink.js +107 -0
  47. package/dist/links/loggerLink.mjs +98 -0
  48. package/dist/links/loggerLink.ts.js +1 -0
  49. package/dist/links/retryLink.d.ts +6 -0
  50. package/dist/links/retryLink.d.ts.map +1 -0
  51. package/dist/links/splitLink.d.ts +14 -0
  52. package/dist/links/splitLink.d.ts.map +1 -0
  53. package/dist/links/splitLink.js +32 -0
  54. package/dist/links/splitLink.mjs +28 -0
  55. package/dist/links/splitLink.ts.js +1 -0
  56. package/dist/links/transformerLink.d.ts +4 -0
  57. package/dist/links/transformerLink.d.ts.map +1 -0
  58. package/dist/links/transformerLink.js +79 -0
  59. package/dist/links/transformerLink.mjs +71 -0
  60. package/dist/links/transformerLink.ts.js +1 -0
  61. package/dist/links/types.d.ts +39 -0
  62. package/dist/links/types.d.ts.map +1 -0
  63. package/dist/links/wsLink.d.ts +21 -0
  64. package/dist/links/wsLink.d.ts.map +1 -0
  65. package/dist/links/wsLink.js +385 -0
  66. package/dist/links/wsLink.mjs +370 -0
  67. package/dist/links/wsLink.ts.js +1 -0
  68. package/dist/rx.d.ts +11 -0
  69. package/dist/rx.d.ts.map +1 -0
  70. package/dist/rx.js +88 -0
  71. package/dist/rx.mjs +73 -0
  72. package/dist/rx.ts.js +1 -0
  73. package/links/httpBatchLink/index.d.ts +1 -0
  74. package/links/httpBatchLink/index.js +1 -0
  75. package/links/httpLink/index.d.ts +1 -0
  76. package/links/httpLink/index.js +1 -0
  77. package/links/loggerLink/index.d.ts +1 -0
  78. package/links/loggerLink/index.js +1 -0
  79. package/links/splitLink/index.d.ts +1 -0
  80. package/links/splitLink/index.js +1 -0
  81. package/links/transformerLink/index.d.ts +1 -0
  82. package/links/transformerLink/index.js +1 -0
  83. package/links/wsLink/index.d.ts +1 -0
  84. package/links/wsLink/index.js +1 -0
  85. package/package.json +53 -18
  86. package/src/TRPCClientError.ts +17 -21
  87. package/src/createTRPCClient.ts +4 -3
  88. package/src/index.ts +1 -1
  89. package/src/internals/TRPCClient.ts +78 -92
  90. package/src/internals/dataLoader.ts +1 -1
  91. package/src/links/dedupeLink.test.ts +134 -0
  92. package/src/links/dedupeLink.ts +54 -0
  93. package/src/links/httpBatchLink.ts +36 -46
  94. package/src/links/httpLink.ts +26 -37
  95. package/src/{internals/httpRequest.ts → links/httpUtils.ts} +30 -21
  96. package/src/links/internals/createChain.test.ts +132 -0
  97. package/src/links/internals/createChain.ts +31 -0
  98. package/src/links/internals/transformOperationResult.ts +25 -0
  99. package/src/links/loggerLink.ts +39 -22
  100. package/src/links/retryLink.ts +44 -14
  101. package/src/links/splitLink.test.ts +56 -0
  102. package/src/links/splitLink.ts +23 -38
  103. package/src/links/transformerLink.ts +74 -0
  104. package/src/links/types.ts +64 -0
  105. package/src/links/wsLink.ts +57 -77
  106. package/src/rx.ts +50 -0
  107. package/dist/TRPCClientError-09b8a26b.esm.js +0 -77
  108. package/dist/TRPCClientError-bfee2bf5.cjs.dev.js +0 -79
  109. package/dist/TRPCClientError-e9bf96e9.cjs.prod.js +0 -79
  110. package/dist/declarations/src/TRPCClientError.d.ts.map +0 -1
  111. package/dist/declarations/src/createTRPCClient.d.ts.map +0 -1
  112. package/dist/declarations/src/getFetch.d.ts.map +0 -1
  113. package/dist/declarations/src/index.d.ts.map +0 -1
  114. package/dist/declarations/src/internals/TRPCAbortError.d.ts +0 -4
  115. package/dist/declarations/src/internals/TRPCAbortError.d.ts.map +0 -1
  116. package/dist/declarations/src/internals/TRPCClient.d.ts.map +0 -1
  117. package/dist/declarations/src/internals/dataLoader.d.ts.map +0 -1
  118. package/dist/declarations/src/internals/executeChain.d.ts +0 -9
  119. package/dist/declarations/src/internals/executeChain.d.ts.map +0 -1
  120. package/dist/declarations/src/internals/fetchHelpers.d.ts.map +0 -1
  121. package/dist/declarations/src/internals/httpRequest.d.ts +0 -14
  122. package/dist/declarations/src/internals/httpRequest.d.ts.map +0 -1
  123. package/dist/declarations/src/internals/observable.d.ts +0 -18
  124. package/dist/declarations/src/internals/observable.d.ts.map +0 -1
  125. package/dist/declarations/src/internals/retryDelay.d.ts.map +0 -1
  126. package/dist/declarations/src/internals/transformRPCResponse.d.ts +0 -15
  127. package/dist/declarations/src/internals/transformRPCResponse.d.ts.map +0 -1
  128. package/dist/declarations/src/links/core.d.ts +0 -45
  129. package/dist/declarations/src/links/core.d.ts.map +0 -1
  130. package/dist/declarations/src/links/httpBatchLink.d.ts.map +0 -1
  131. package/dist/declarations/src/links/httpLink.d.ts.map +0 -1
  132. package/dist/declarations/src/links/loggerLink.d.ts.map +0 -1
  133. package/dist/declarations/src/links/splitLink.d.ts +0 -24
  134. package/dist/declarations/src/links/splitLink.d.ts.map +0 -1
  135. package/dist/declarations/src/links/wsLink.d.ts +0 -30
  136. package/dist/declarations/src/links/wsLink.d.ts.map +0 -1
  137. package/dist/transformRPCResponse-57e80136.cjs.dev.js +0 -133
  138. package/dist/transformRPCResponse-739c13d0.cjs.prod.js +0 -133
  139. package/dist/transformRPCResponse-f7f8b0e1.esm.js +0 -129
  140. package/dist/trpc-client.cjs.d.ts +0 -1
  141. package/dist/trpc-client.cjs.dev.js +0 -379
  142. package/dist/trpc-client.cjs.js +0 -7
  143. package/dist/trpc-client.cjs.prod.js +0 -379
  144. package/dist/trpc-client.esm.js +0 -374
  145. package/links/httpBatchLink/package.json +0 -4
  146. package/links/httpLink/package.json +0 -4
  147. package/links/loggerLink/package.json +0 -4
  148. package/links/splitLink/package.json +0 -4
  149. package/links/wsLink/package.json +0 -4
  150. package/src/internals/TRPCAbortError.ts +0 -7
  151. package/src/internals/executeChain.ts +0 -67
  152. package/src/internals/observable.ts +0 -89
  153. package/src/internals/transformRPCResponse.ts +0 -25
  154. package/src/links/core.ts +0 -71
@@ -1,379 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
6
- var _createClass = require('@babel/runtime/helpers/createClass');
7
- var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
8
- var _createForOfIteratorHelper = require('@babel/runtime/helpers/createForOfIteratorHelper');
9
- var transformRPCResponse = require('./transformRPCResponse-739c13d0.cjs.prod.js');
10
- var links_httpBatchLink_dist_trpcClientLinksHttpBatchLink = require('../links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js');
11
- var TRPCClientError = require('./TRPCClientError-e9bf96e9.cjs.prod.js');
12
- require('@babel/runtime/helpers/assertThisInitialized');
13
- require('@babel/runtime/helpers/inherits');
14
- require('@babel/runtime/helpers/createSuper');
15
- require('@babel/runtime/helpers/wrapNativeSuper');
16
-
17
- function observable() {
18
- var listeners = [];
19
- var value = null;
20
- return {
21
- subscribe: function subscribe(callbacks) {
22
- var listener = {
23
- callbacks: callbacks,
24
- unsubscribe: function unsubscribe() {
25
- var index = listeners.indexOf(listener);
26
-
27
- if (index !== -1) {
28
- var _listener$callbacks$o, _listener$callbacks;
29
-
30
- listeners.splice(index, 1);
31
- (_listener$callbacks$o = (_listener$callbacks = listener.callbacks).onDone) === null || _listener$callbacks$o === void 0 ? void 0 : _listener$callbacks$o.call(_listener$callbacks);
32
- }
33
- }
34
- };
35
- listeners.push(listener);
36
- return function () {
37
- listener.unsubscribe();
38
- };
39
- },
40
- next: function next(newValue) {
41
- var oldValue = value;
42
- value = newValue;
43
-
44
- if (oldValue !== newValue) {
45
- var _iterator = _createForOfIteratorHelper(listeners),
46
- _step;
47
-
48
- try {
49
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
50
- var _listener$callbacks$o2, _listener$callbacks2;
51
-
52
- var listener = _step.value;
53
- (_listener$callbacks$o2 = (_listener$callbacks2 = listener.callbacks).onNext) === null || _listener$callbacks$o2 === void 0 ? void 0 : _listener$callbacks$o2.call(_listener$callbacks2, newValue);
54
- }
55
- } catch (err) {
56
- _iterator.e(err);
57
- } finally {
58
- _iterator.f();
59
- }
60
- }
61
- },
62
- done: function done() {
63
- while (listeners.length) {
64
- var _listener$callbacks$o3, _listener$callbacks3;
65
-
66
- var listener = listeners.pop();
67
- listener === null || listener === void 0 ? void 0 : (_listener$callbacks$o3 = (_listener$callbacks3 = listener.callbacks).onDone) === null || _listener$callbacks$o3 === void 0 ? void 0 : _listener$callbacks$o3.call(_listener$callbacks3);
68
- listener === null || listener === void 0 ? void 0 : listener.unsubscribe();
69
- }
70
- },
71
- error: function (_error) {
72
- function error(_x) {
73
- return _error.apply(this, arguments);
74
- }
75
-
76
- error.toString = function () {
77
- return _error.toString();
78
- };
79
-
80
- return error;
81
- }(function (error) {
82
- var _iterator2 = _createForOfIteratorHelper(listeners),
83
- _step2;
84
-
85
- try {
86
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
87
- var _listener$callbacks$o4, _listener$callbacks4;
88
-
89
- var listener = _step2.value;
90
- (_listener$callbacks$o4 = (_listener$callbacks4 = listener.callbacks).onError) === null || _listener$callbacks$o4 === void 0 ? void 0 : _listener$callbacks$o4.call(_listener$callbacks4, error);
91
- }
92
- } catch (err) {
93
- _iterator2.e(err);
94
- } finally {
95
- _iterator2.f();
96
- }
97
- })
98
- };
99
- }
100
- function observableSubject(initialValue) {
101
- var $obs = observable();
102
- var value = initialValue;
103
- $obs.next(initialValue);
104
- return _objectSpread(_objectSpread({}, $obs), {}, {
105
- next: function next(v) {
106
- value = v;
107
- $obs.next(v);
108
- },
109
- get: function get() {
110
- return value;
111
- }
112
- });
113
- }
114
-
115
- function executeChain(opts) {
116
- var $result = observableSubject(null);
117
-
118
- var updateResult = function updateResult(result) {
119
- if (result instanceof Error) {
120
- $result.error(result);
121
-
122
- if (result.isDone) {
123
- $result.done();
124
- }
125
- } else {
126
- $result.next(result);
127
- }
128
- };
129
-
130
- function walk(_ref) {
131
- var index = _ref.index,
132
- op = _ref.op,
133
- stack = _ref.stack;
134
- var link = opts.links[index];
135
- var prev = index === 0 ? function (value) {
136
- return updateResult(value);
137
- } : stack[index - 1];
138
- link({
139
- op: op,
140
- prev: prev,
141
- next: function next(op, prevOp) {
142
- var prevStack = stack.slice();
143
- prevStack[index] = prevOp;
144
- walk({
145
- index: index + 1,
146
- op: op,
147
- stack: prevStack
148
- });
149
- },
150
- onDestroy: function onDestroy(callback) {
151
- $result.subscribe({
152
- onDone: function onDone() {
153
- callback();
154
- }
155
- });
156
- }
157
- });
158
- }
159
-
160
- walk({
161
- index: 0,
162
- op: opts.op,
163
- stack: []
164
- });
165
- return $result;
166
- }
167
-
168
- function getWindow() {
169
- if (typeof window !== 'undefined') {
170
- return window;
171
- }
172
-
173
- return global;
174
- }
175
- function getAbortController(ac) {
176
- var win = getWindow();
177
- return ac || win.AbortController || null;
178
- }
179
-
180
- function getFetch(f) {
181
- if (f) {
182
- return f;
183
- }
184
-
185
- var win = getWindow();
186
-
187
- if (win.fetch) {
188
- return typeof win.fetch.bind === 'function' ? win.fetch.bind(win) : win.fetch;
189
- }
190
-
191
- throw new Error('No fetch implementation found');
192
- }
193
-
194
- var idCounter = 0;
195
-
196
- function getRequestId() {
197
- return ++idCounter;
198
- }
199
-
200
- var TRPCClient = /*#__PURE__*/function () {
201
- function TRPCClient(opts) {
202
- var _this = this;
203
-
204
- _classCallCheck(this, TRPCClient);
205
-
206
- this.links = void 0;
207
- this.runtime = void 0;
208
- var transformer = opts.transformer ? 'input' in opts.transformer ? {
209
- serialize: opts.transformer.input.serialize,
210
- deserialize: opts.transformer.output.deserialize
211
- } : opts.transformer : {
212
- serialize: function serialize(data) {
213
- return data;
214
- },
215
- deserialize: function deserialize(data) {
216
- return data;
217
- }
218
- };
219
-
220
- var _fetch = getFetch(opts === null || opts === void 0 ? void 0 : opts.fetch);
221
-
222
- var AC = getAbortController(opts === null || opts === void 0 ? void 0 : opts.AbortController);
223
-
224
- function getHeadersFn() {
225
- if (opts.headers) {
226
- var headers = opts.headers;
227
- return typeof headers === 'function' ? headers : function () {
228
- return headers;
229
- };
230
- }
231
-
232
- return function () {
233
- return {};
234
- };
235
- }
236
-
237
- this.runtime = {
238
- transformer: transformer,
239
- AbortController: AC,
240
- fetch: _fetch,
241
- headers: getHeadersFn()
242
- };
243
-
244
- if ('links' in opts) {
245
- this.links = opts.links.map(function (link) {
246
- return link(_this.runtime);
247
- });
248
- } else {
249
- this.links = [links_httpBatchLink_dist_trpcClientLinksHttpBatchLink.httpBatchLink({
250
- url: opts.url
251
- })(this.runtime)];
252
- }
253
- }
254
-
255
- _createClass(TRPCClient, [{
256
- key: "$request",
257
- value: function $request(_ref) {
258
- var type = _ref.type,
259
- input = _ref.input,
260
- path = _ref.path,
261
- _ref$context = _ref.context,
262
- context = _ref$context === void 0 ? {} : _ref$context;
263
- var $result = executeChain({
264
- links: this.links,
265
- op: {
266
- id: getRequestId(),
267
- type: type,
268
- path: path,
269
- input: input,
270
- context: context
271
- }
272
- });
273
- return $result;
274
- }
275
- }, {
276
- key: "requestAsPromise",
277
- value: function requestAsPromise(opts) {
278
- var $result = this.$request(opts);
279
- var promise = new Promise(function (resolve, reject) {
280
- var res = $result.get();
281
-
282
- if ((res === null || res === void 0 ? void 0 : res.type) === 'data') {
283
- resolve(res.data);
284
- $result.done();
285
- return;
286
- }
287
-
288
- $result.subscribe({
289
- onNext: function onNext(result) {
290
- if ((result === null || result === void 0 ? void 0 : result.type) !== 'data') {
291
- return;
292
- }
293
-
294
- resolve(result.data);
295
- $result.done();
296
- },
297
- onError: function onError(err) {
298
- reject(err);
299
- $result.done();
300
- },
301
- onDone: function onDone() {
302
- reject(TRPCClientError.TRPCClientError.from(new transformRPCResponse.TRPCAbortError()));
303
- }
304
- });
305
- });
306
-
307
- promise.cancel = function () {
308
- $result.done();
309
- };
310
-
311
- return promise;
312
- }
313
- }, {
314
- key: "query",
315
- value: function query(path) {
316
- var _ref2;
317
-
318
- var context = (_ref2 = arguments.length <= 2 ? undefined : arguments[2]) === null || _ref2 === void 0 ? void 0 : _ref2.context;
319
- return this.requestAsPromise({
320
- type: 'query',
321
- path: path,
322
- input: arguments.length <= 1 ? undefined : arguments[1],
323
- context: context
324
- });
325
- }
326
- }, {
327
- key: "mutation",
328
- value: function mutation(path) {
329
- var _ref3;
330
-
331
- var context = (_ref3 = arguments.length <= 2 ? undefined : arguments[2]) === null || _ref3 === void 0 ? void 0 : _ref3.context;
332
- return this.requestAsPromise({
333
- type: 'mutation',
334
- path: path,
335
- input: arguments.length <= 1 ? undefined : arguments[1],
336
- context: context
337
- });
338
- }
339
- }, {
340
- key: "subscription",
341
- value: function subscription(path, input, opts) {
342
- var $res = this.$request({
343
- type: 'subscription',
344
- path: path,
345
- input: input,
346
- context: opts.context
347
- });
348
- $res.subscribe({
349
- onNext: function onNext(output) {
350
- if (output) {
351
- var _opts$onNext;
352
-
353
- (_opts$onNext = opts.onNext) === null || _opts$onNext === void 0 ? void 0 : _opts$onNext.call(opts, output);
354
- }
355
- },
356
- onError: function onError(err) {
357
- var _opts$onError;
358
-
359
- (_opts$onError = opts.onError) === null || _opts$onError === void 0 ? void 0 : _opts$onError.call(opts, err);
360
- },
361
- onDone: opts.onDone
362
- });
363
- return function () {
364
- $res.done();
365
- };
366
- }
367
- }]);
368
-
369
- return TRPCClient;
370
- }();
371
-
372
- /* eslint-disable @typescript-eslint/no-explicit-any */
373
- function createTRPCClient(opts) {
374
- return new TRPCClient(opts);
375
- }
376
-
377
- exports.TRPCClientError = TRPCClientError.TRPCClientError;
378
- exports.createTRPCClient = createTRPCClient;
379
- exports.getFetch = getFetch;