@trpc/client 10.0.0-alpha.8 → 10.0.0-proxy-alpha.53

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 (180) hide show
  1. package/README.md +58 -1
  2. package/dist/TRPCClientError.d.ts +16 -20
  3. package/dist/TRPCClientError.d.ts.map +1 -1
  4. package/dist/createTRPCClient.d.ts +2 -3
  5. package/dist/createTRPCClient.d.ts.map +1 -1
  6. package/dist/createTRPCClientProxy.d.ts +37 -0
  7. package/dist/createTRPCClientProxy.d.ts.map +1 -0
  8. package/dist/httpUtils-44781613.mjs +76 -0
  9. package/dist/httpUtils-801112a6.js +79 -0
  10. package/dist/index.d.ts +2 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +260 -280
  13. package/dist/index.mjs +253 -271
  14. package/dist/internals/TRPCClient.d.ts +39 -21
  15. package/dist/internals/TRPCClient.d.ts.map +1 -1
  16. package/dist/internals/dataLoader.d.ts +7 -6
  17. package/dist/internals/dataLoader.d.ts.map +1 -1
  18. package/dist/internals/fetchHelpers.d.ts +1 -1
  19. package/dist/internals/fetchHelpers.d.ts.map +1 -1
  20. package/dist/internals/retryDelay.d.ts.map +1 -1
  21. package/dist/links/dedupeLink.d.ts.map +1 -1
  22. package/dist/links/httpBatchLink.d.ts +2 -2
  23. package/dist/links/httpBatchLink.d.ts.map +1 -1
  24. package/dist/links/httpBatchLink.js +189 -172
  25. package/dist/links/httpBatchLink.mjs +189 -172
  26. package/dist/links/httpLink.d.ts +1 -1
  27. package/dist/links/httpLink.d.ts.map +1 -1
  28. package/dist/links/httpLink.js +31 -35
  29. package/dist/links/httpLink.mjs +31 -35
  30. package/dist/links/index.d.ts +9 -0
  31. package/dist/links/index.d.ts.map +1 -0
  32. package/dist/links/internals/createChain.d.ts.map +1 -1
  33. package/dist/links/internals/httpUtils.d.ts +31 -0
  34. package/dist/links/internals/httpUtils.d.ts.map +1 -0
  35. package/dist/links/internals/transformResult.d.ts +28 -0
  36. package/dist/links/internals/transformResult.d.ts.map +1 -0
  37. package/dist/links/loggerLink.d.ts +3 -3
  38. package/dist/links/loggerLink.d.ts.map +1 -1
  39. package/dist/links/loggerLink.js +90 -96
  40. package/dist/links/loggerLink.mjs +90 -91
  41. package/dist/links/retryLink.d.ts.map +1 -1
  42. package/dist/links/splitLink.d.ts +1 -1
  43. package/dist/links/splitLink.d.ts.map +1 -1
  44. package/dist/links/splitLink.js +3 -25
  45. package/dist/links/splitLink.mjs +2 -28
  46. package/dist/links/types.d.ts +13 -12
  47. package/dist/links/types.d.ts.map +1 -1
  48. package/dist/links/wsLink.d.ts +12 -5
  49. package/dist/links/wsLink.d.ts.map +1 -1
  50. package/dist/links/wsLink.js +250 -358
  51. package/dist/links/wsLink.mjs +250 -348
  52. package/dist/splitLink-695ae288.js +48 -0
  53. package/dist/splitLink-ad44a55d.mjs +45 -0
  54. package/dist/transformResult-106791d7.mjs +62 -0
  55. package/dist/transformResult-e15ccdf6.js +65 -0
  56. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.dev.js +15 -13
  57. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.cjs.prod.js +15 -13
  58. package/links/httpBatchLink/dist/trpc-client-links-httpBatchLink.esm.js +12 -10
  59. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.dev.js +4 -4
  60. package/links/httpLink/dist/trpc-client-links-httpLink.cjs.prod.js +4 -4
  61. package/links/httpLink/dist/trpc-client-links-httpLink.esm.js +1 -1
  62. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.dev.js +3 -1
  63. package/links/wsLink/dist/trpc-client-links-wsLink.cjs.prod.js +3 -1
  64. package/links/wsLink/dist/trpc-client-links-wsLink.esm.js +3 -1
  65. package/package.json +23 -34
  66. package/src/TRPCClientError.ts +38 -28
  67. package/src/createTRPCClient.ts +8 -3
  68. package/src/createTRPCClientProxy.ts +113 -0
  69. package/src/index.ts +2 -1
  70. package/src/internals/TRPCClient.ts +118 -77
  71. package/src/internals/dataLoader.ts +116 -53
  72. package/src/internals/fetchHelpers.ts +2 -2
  73. package/src/links/dedupeLink.test.ts +9 -15
  74. package/src/links/dedupeLink.ts +6 -7
  75. package/src/links/httpBatchLink.ts +73 -36
  76. package/src/links/httpLink.ts +18 -6
  77. package/src/links/index.ts +8 -0
  78. package/src/links/internals/createChain.test.ts +23 -38
  79. package/src/links/internals/createChain.ts +8 -3
  80. package/src/links/internals/httpUtils.ts +117 -0
  81. package/src/links/internals/transformResult.ts +40 -0
  82. package/src/links/loggerLink.ts +6 -7
  83. package/src/links/retryLink.ts +2 -3
  84. package/src/links/splitLink.test.ts +3 -3
  85. package/src/links/splitLink.ts +5 -5
  86. package/src/links/types.ts +15 -12
  87. package/src/links/wsLink.ts +57 -23
  88. package/dist/TRPCClientError-17b117e1.mjs +0 -81
  89. package/dist/TRPCClientError-ec6bd2ca.js +0 -94
  90. package/dist/createChain-389cc116.mjs +0 -25
  91. package/dist/createChain-864dbb30.js +0 -27
  92. package/dist/httpUtils-1f9e4e3c.js +0 -97
  93. package/dist/httpUtils-c09d7b79.mjs +0 -91
  94. package/dist/index.ts.js +0 -1
  95. package/dist/internals/transformRPCResponse.d.ts +0 -15
  96. package/dist/internals/transformRPCResponse.d.ts.map +0 -1
  97. package/dist/links/httpBatchLink.ts.js +0 -1
  98. package/dist/links/httpLink.ts.js +0 -1
  99. package/dist/links/httpUtils.d.ts +0 -22
  100. package/dist/links/httpUtils.d.ts.map +0 -1
  101. package/dist/links/internals/transformOperationResult.d.ts +0 -16
  102. package/dist/links/internals/transformOperationResult.d.ts.map +0 -1
  103. package/dist/links/loggerLink.ts.js +0 -1
  104. package/dist/links/splitLink.ts.js +0 -1
  105. package/dist/links/transformerLink.d.ts +0 -4
  106. package/dist/links/transformerLink.d.ts.map +0 -1
  107. package/dist/links/transformerLink.js +0 -75
  108. package/dist/links/transformerLink.mjs +0 -67
  109. package/dist/links/transformerLink.ts.js +0 -1
  110. package/dist/links/wsLink.ts.js +0 -1
  111. package/dist/observable-7e66cb56.mjs +0 -102
  112. package/dist/observable-85669100.js +0 -104
  113. package/dist/rx/index.d.ts +0 -3
  114. package/dist/rx/index.d.ts.map +0 -1
  115. package/dist/rx/index.js +0 -9
  116. package/dist/rx/index.mjs +0 -1
  117. package/dist/rx/index.ts.js +0 -1
  118. package/dist/rx/observable.d.ts +0 -4
  119. package/dist/rx/observable.d.ts.map +0 -1
  120. package/dist/rx/operators/index.d.ts +0 -4
  121. package/dist/rx/operators/index.d.ts.map +0 -1
  122. package/dist/rx/operators/index.js +0 -38
  123. package/dist/rx/operators/index.mjs +0 -32
  124. package/dist/rx/operators/index.ts.js +0 -1
  125. package/dist/rx/operators/map.d.ts +0 -3
  126. package/dist/rx/operators/map.d.ts.map +0 -1
  127. package/dist/rx/operators/share.d.ts +0 -6
  128. package/dist/rx/operators/share.d.ts.map +0 -1
  129. package/dist/rx/operators/tap.d.ts +0 -3
  130. package/dist/rx/operators/tap.d.ts.map +0 -1
  131. package/dist/rx/types.d.ts +0 -29
  132. package/dist/rx/types.d.ts.map +0 -1
  133. package/dist/rx/util/identity.d.ts +0 -2
  134. package/dist/rx/util/identity.d.ts.map +0 -1
  135. package/dist/rx/util/observableToPromise.d.ts +0 -10
  136. package/dist/rx/util/observableToPromise.d.ts.map +0 -1
  137. package/dist/rx/util/pipe.d.ts +0 -4
  138. package/dist/rx/util/pipe.d.ts.map +0 -1
  139. package/dist/share-4d79dc49.js +0 -110
  140. package/dist/share-671b63fa.mjs +0 -108
  141. package/dist/tap-538fa07f.mjs +0 -30
  142. package/dist/tap-799a2d33.js +0 -32
  143. package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.d.ts +0 -1
  144. package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.dev.js +0 -67
  145. package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.js +0 -7
  146. package/links/transformerLink/dist/trpc-client-links-transformerLink.cjs.prod.js +0 -67
  147. package/links/transformerLink/dist/trpc-client-links-transformerLink.esm.js +0 -63
  148. package/links/transformerLink/index.d.ts +0 -1
  149. package/links/transformerLink/index.js +0 -1
  150. package/rx/dist/trpc-client-rx.cjs.d.ts +0 -1
  151. package/rx/dist/trpc-client-rx.cjs.dev.js +0 -9
  152. package/rx/dist/trpc-client-rx.cjs.js +0 -7
  153. package/rx/dist/trpc-client-rx.cjs.prod.js +0 -9
  154. package/rx/dist/trpc-client-rx.esm.js +0 -1
  155. package/rx/index.d.ts +0 -1
  156. package/rx/index.js +0 -1
  157. package/rx/operators/dist/trpc-client-rx-operators.cjs.d.ts +0 -1
  158. package/rx/operators/dist/trpc-client-rx-operators.cjs.dev.js +0 -39
  159. package/rx/operators/dist/trpc-client-rx-operators.cjs.js +0 -7
  160. package/rx/operators/dist/trpc-client-rx-operators.cjs.prod.js +0 -39
  161. package/rx/operators/dist/trpc-client-rx-operators.esm.js +0 -33
  162. package/rx/operators/index.d.ts +0 -1
  163. package/rx/operators/index.js +0 -1
  164. package/src/internals/transformRPCResponse.ts +0 -25
  165. package/src/links/httpUtils.ts +0 -94
  166. package/src/links/internals/transformOperationResult.ts +0 -25
  167. package/src/links/transformerLink.ts +0 -70
  168. package/src/rx/index.ts +0 -2
  169. package/src/rx/observable.test.ts +0 -83
  170. package/src/rx/observable.ts +0 -70
  171. package/src/rx/operators/index.ts +0 -3
  172. package/src/rx/operators/map.test.ts +0 -92
  173. package/src/rx/operators/map.ts +0 -25
  174. package/src/rx/operators/share.test.ts +0 -60
  175. package/src/rx/operators/share.ts +0 -67
  176. package/src/rx/operators/tap.ts +0 -26
  177. package/src/rx/types.ts +0 -69
  178. package/src/rx/util/identity.ts +0 -3
  179. package/src/rx/util/observableToPromise.ts +0 -49
  180. package/src/rx/util/pipe.ts +0 -22
@@ -1,191 +1,208 @@
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; }
10
-
1
+ import { observable } from '@trpc/server/observable';
2
+ import { t as transformResult, T as TRPCClientError } from '../transformResult-106791d7.mjs';
3
+ import { g as getUrl, h as httpRequest } from '../httpUtils-44781613.mjs';
4
+
5
+ /* eslint-disable @typescript-eslint/no-non-null-assertion */ /**
6
+ * A function that should never be called unless we messed something up.
7
+ */ const throwFatalError = ()=>{
8
+ throw new Error('Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new');
9
+ };
11
10
  /**
12
11
  * Dataloader that's very inspired by https://github.com/graphql/dataloader
13
12
  * Less configuration, no caching, and allows you to cancel requests
14
13
  * When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
15
- */
16
- function dataLoader(fetchMany, opts) {
17
- var batch = null;
18
- var dispatchTimer = null;
19
-
20
- var destroyTimerAndBatch = function destroyTimerAndBatch() {
21
- clearTimeout(dispatchTimer);
22
- dispatchTimer = null;
23
- batch = null;
24
- };
25
-
26
- function dispatch() {
27
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
28
- var batchCopy = batch;
29
- destroyTimerAndBatch();
30
-
31
- var _fetchMany = fetchMany(batchCopy.items.map(function (v) {
32
- return v.key;
33
- })),
34
- promise = _fetchMany.promise,
35
- cancel = _fetchMany.cancel;
36
-
37
- batchCopy.cancel = cancel;
38
- promise.then(function (result) {
39
- for (var i = 0; i < result.length; i++) {
40
- var _value = result[i];
41
- batchCopy.items[i].resolve(_value);
42
- }
43
- }).catch(function (cause) {
44
- var _iterator = _createForOfIteratorHelper(batchCopy.items),
45
- _step;
46
-
47
- try {
48
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
49
- var item = _step.value;
50
- item.reject(cause);
51
- }
52
- } catch (err) {
53
- _iterator.e(err);
54
- } finally {
55
- _iterator.f();
56
- }
57
- });
58
- }
59
-
60
- function load(key) {
61
- var batchItem = {
62
- cancelled: false,
63
- key: key
14
+ */ function dataLoader(batchLoader) {
15
+ let pendingItems = null;
16
+ let dispatchTimer = null;
17
+ const destroyTimerAndPendingItems = ()=>{
18
+ clearTimeout(dispatchTimer);
19
+ dispatchTimer = null;
20
+ pendingItems = null;
64
21
  };
65
-
66
- if (!batch) {
67
- batch = {
68
- items: [],
69
- cancel: function cancel() {
70
- destroyTimerAndBatch();
22
+ /**
23
+ * Iterate through the items and split them into groups based on the `batchLoader`'s validate function
24
+ */ function groupItems(items) {
25
+ const groupedItems = [
26
+ []
27
+ ];
28
+ let index = 0;
29
+ while(true){
30
+ const item = items[index];
31
+ if (!item) {
32
+ break;
33
+ }
34
+ const lastGroup = groupedItems[groupedItems.length - 1];
35
+ if (item.aborted) {
36
+ // Item was aborted before it was dispatched
37
+ item.reject(new Error('Aborted'));
38
+ index++;
39
+ continue;
40
+ }
41
+ const isValid = batchLoader.validate(lastGroup.concat(item).map((it)=>it.key));
42
+ if (isValid) {
43
+ lastGroup.push(item);
44
+ index++;
45
+ continue;
46
+ }
47
+ if (lastGroup.length === 0) {
48
+ item.reject(new Error('Input is too big for a single dispatch'));
49
+ index++;
50
+ continue;
51
+ }
52
+ // Create new group, next iteration will try to add the item to that
53
+ groupedItems.push([]);
71
54
  }
72
- };
55
+ return groupedItems;
73
56
  }
74
-
75
- var thisBatch = batch;
76
- var promise = new Promise(function (resolve, reject) {
77
- var item = batchItem;
78
- item.reject = reject;
79
- item.resolve = resolve;
80
- thisBatch.items.push(item);
81
-
82
- if (typeof (opts === null || opts === void 0 ? void 0 : opts.maxBatchSize) !== 'undefined' && thisBatch.items.length >= opts.maxBatchSize) {
83
- dispatch();
84
- return;
85
- }
86
- });
87
-
88
- if (!dispatchTimer) {
89
- dispatchTimer = setTimeout(dispatch);
57
+ function dispatch() {
58
+ const groupedItems = groupItems(pendingItems);
59
+ destroyTimerAndPendingItems();
60
+ // Create batches for each group of items
61
+ for (const items of groupedItems){
62
+ if (!items.length) {
63
+ continue;
64
+ }
65
+ const batch = {
66
+ items,
67
+ cancel: throwFatalError
68
+ };
69
+ for (const item of items){
70
+ item.batch = batch;
71
+ }
72
+ const { promise , cancel } = batchLoader.fetch(batch.items.map((_item)=>_item.key));
73
+ batch.cancel = cancel;
74
+ promise.then((result)=>{
75
+ for(let i = 0; i < result.length; i++){
76
+ const value = result[i];
77
+ const item = batch.items[i];
78
+ item.resolve(value);
79
+ item.batch = null;
80
+ }
81
+ }).catch((cause)=>{
82
+ for (const item of batch.items){
83
+ item.reject(cause);
84
+ item.batch = null;
85
+ }
86
+ });
87
+ }
88
+ }
89
+ function load(key) {
90
+ const item = {
91
+ aborted: false,
92
+ key,
93
+ batch: null,
94
+ resolve: throwFatalError,
95
+ reject: throwFatalError
96
+ };
97
+ const promise = new Promise((resolve, reject)=>{
98
+ item.reject = reject;
99
+ item.resolve = resolve;
100
+ if (!pendingItems) {
101
+ pendingItems = [];
102
+ }
103
+ pendingItems.push(item);
104
+ });
105
+ if (!dispatchTimer) {
106
+ dispatchTimer = setTimeout(dispatch);
107
+ }
108
+ const cancel = ()=>{
109
+ item.aborted = true;
110
+ if (item.batch?.items.every((item)=>item.aborted)) {
111
+ // All items in the batch have been cancelled
112
+ item.batch.cancel();
113
+ item.batch = null;
114
+ }
115
+ };
116
+ return {
117
+ promise,
118
+ cancel
119
+ };
90
120
  }
91
-
92
- var cancel = function cancel() {
93
- batchItem.cancelled = true;
94
-
95
- if (thisBatch.items.some(function (item) {
96
- return !item.cancelled;
97
- })) {
98
- // there are still things that can be resolved
99
- return;
100
- }
101
-
102
- thisBatch.cancel();
103
- };
104
-
105
121
  return {
106
- promise: promise,
107
- cancel: cancel
122
+ load
108
123
  };
109
- }
110
-
111
- return {
112
- load: load
113
- };
114
124
  }
115
125
 
116
126
  function httpBatchLink(opts) {
117
- var url = opts.url; // initialized config
118
-
119
- return function (runtime) {
120
- var fetcher = function fetcher(type) {
121
- return function (keyInputPairs) {
122
- var path = keyInputPairs.map(function (op) {
123
- return op.path;
124
- }).join(',');
125
- var inputs = keyInputPairs.map(function (op) {
126
- return op.input;
127
- });
128
-
129
- var _httpRequest = httpRequest({
130
- url: url,
131
- inputs: inputs,
132
- path: path,
133
- runtime: runtime,
134
- type: type
135
- }),
136
- promise = _httpRequest.promise,
137
- cancel = _httpRequest.cancel;
138
-
139
- return {
140
- 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;
151
- }),
152
- cancel: cancel
127
+ // initialized config
128
+ return (runtime)=>{
129
+ const maxURLLength = opts.maxURLLength || Infinity;
130
+ const batchLoader = (type)=>{
131
+ const validate = (batchOps)=>{
132
+ if (maxURLLength === Infinity) {
133
+ // escape hatch for quick calcs
134
+ return true;
135
+ }
136
+ const path = batchOps.map((op)=>op.path).join(',');
137
+ const inputs = batchOps.map((op)=>op.input);
138
+ const url = getUrl({
139
+ url: opts.url,
140
+ runtime,
141
+ type,
142
+ path,
143
+ inputs
144
+ });
145
+ return url.length <= maxURLLength;
146
+ };
147
+ const fetch = (batchOps)=>{
148
+ const path = batchOps.map((op)=>op.path).join(',');
149
+ const inputs = batchOps.map((op)=>op.input);
150
+ const { promise , cancel } = httpRequest({
151
+ url: opts.url,
152
+ runtime,
153
+ type,
154
+ path,
155
+ inputs
156
+ });
157
+ return {
158
+ promise: promise.then((res)=>{
159
+ const resJSON = Array.isArray(res.json) ? res.json : batchOps.map(()=>res.json);
160
+ const result = resJSON.map((item)=>({
161
+ meta: res.meta,
162
+ json: item
163
+ }));
164
+ return result;
165
+ }),
166
+ cancel
167
+ };
168
+ };
169
+ return {
170
+ validate,
171
+ fetch
172
+ };
153
173
  };
154
- };
155
- };
156
-
157
- var query = dataLoader(fetcher('query'), opts);
158
- var mutation = dataLoader(fetcher('mutation'), opts);
159
- var subscription = dataLoader(fetcher('subscription'), opts);
160
- var loaders = {
161
- query: query,
162
- subscription: subscription,
163
- mutation: mutation
164
- };
165
- 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();
174
+ const query = dataLoader(batchLoader('query'));
175
+ const mutation = dataLoader(batchLoader('mutation'));
176
+ const subscription = dataLoader(batchLoader('subscription'));
177
+ const loaders = {
178
+ query,
179
+ subscription,
180
+ mutation
181
+ };
182
+ return ({ op })=>{
183
+ return observable((observer)=>{
184
+ const loader = loaders[op.type];
185
+ const { promise , cancel } = loader.load(op);
186
+ promise.then((res)=>{
187
+ const transformed = transformResult(res.json, runtime);
188
+ if (!transformed.ok) {
189
+ observer.error(TRPCClientError.from(transformed.error, {
190
+ meta: res.meta
191
+ }));
192
+ return;
193
+ }
194
+ observer.next({
195
+ context: res.meta,
196
+ result: transformed.result
197
+ });
198
+ observer.complete();
199
+ }).catch((err)=>observer.error(TRPCClientError.from(err)));
200
+ return ()=>{
201
+ cancel();
202
+ };
203
+ });
185
204
  };
186
- });
187
205
  };
188
- };
189
206
  }
190
207
 
191
208
  export { httpBatchLink };
@@ -1,5 +1,5 @@
1
1
  import { AnyRouter } from '@trpc/server';
2
+ import { HTTPLinkOptions } from './internals/httpUtils';
2
3
  import { TRPCLink } from './types';
3
- import { HTTPLinkOptions } from './httpUtils';
4
4
  export declare function httpLink<TRouter extends AnyRouter>(opts: HTTPLinkOptions): TRPCLink<TRouter>;
5
5
  //# sourceMappingURL=httpLink.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"httpLink.d.ts","sourceRoot":"","sources":["../../src/links/httpLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,eAAe,EAAe,MAAM,aAAa,CAAC;AAE3D,wBAAgB,QAAQ,CAAC,OAAO,SAAS,SAAS,EAChD,IAAI,EAAE,eAAe,GACpB,QAAQ,CAAC,OAAO,CAAC,CA2BnB"}
1
+ {"version":3,"file":"httpLink.d.ts","sourceRoot":"","sources":["../../../../packages/client/src/links/httpLink.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAE,eAAe,EAAe,MAAM,uBAAuB,CAAC;AAErE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,wBAAgB,QAAQ,CAAC,OAAO,SAAS,SAAS,EAChD,IAAI,EAAE,eAAe,GACpB,QAAQ,CAAC,OAAO,CAAC,CAqCnB"}
@@ -2,43 +2,39 @@
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');
5
+ var observable = require('@trpc/server/observable');
6
+ var transformResult = require('../transformResult-e15ccdf6.js');
7
+ var httpUtils = require('../httpUtils-801112a6.js');
8
8
 
9
9
  function httpLink(opts) {
10
- var url = opts.url;
11
- return function (runtime) {
12
- 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
- };
39
- });
40
- };
41
- };
10
+ const { url } = opts;
11
+ return (runtime)=>({ op })=>observable.observable((observer)=>{
12
+ const { path , input , type } = op;
13
+ const { promise , cancel } = httpUtils.httpRequest({
14
+ url,
15
+ runtime,
16
+ type,
17
+ path,
18
+ input
19
+ });
20
+ promise.then((res)=>{
21
+ const transformed = transformResult.transformResult(res.json, runtime);
22
+ if (!transformed.ok) {
23
+ observer.error(transformResult.TRPCClientError.from(transformed.error, {
24
+ meta: res.meta
25
+ }));
26
+ return;
27
+ }
28
+ observer.next({
29
+ context: res.meta,
30
+ result: transformed.result
31
+ });
32
+ observer.complete();
33
+ }).catch((cause)=>observer.error(transformResult.TRPCClientError.from(cause)));
34
+ return ()=>{
35
+ cancel();
36
+ };
37
+ });
42
38
  }
43
39
 
44
40
  exports.httpLink = httpLink;
@@ -1,40 +1,36 @@
1
- import { o as observable } from '../observable-7e66cb56.mjs';
2
- import { h as httpRequest } from '../httpUtils-c09d7b79.mjs';
3
- import '@babel/runtime/helpers/defineProperty';
1
+ import { observable } from '@trpc/server/observable';
2
+ import { t as transformResult, T as TRPCClientError } from '../transformResult-106791d7.mjs';
3
+ import { h as httpRequest } from '../httpUtils-44781613.mjs';
4
4
 
5
5
  function httpLink(opts) {
6
- var url = opts.url;
7
- return function (runtime) {
8
- return function (_ref) {
9
- var op = _ref.op;
10
- return observable(function (observer) {
11
- var path = op.path,
12
- input = op.input,
13
- type = op.type;
14
-
15
- var _httpRequest = httpRequest({
16
- runtime: runtime,
17
- path: path,
18
- input: input,
19
- type: type,
20
- url: url
21
- }),
22
- promise = _httpRequest.promise,
23
- cancel = _httpRequest.cancel;
24
-
25
- promise.then(function (res) {
26
- observer.next({
27
- context: res.meta,
28
- data: res.json
29
- });
30
- observer.complete();
31
- }).catch(observer.error);
32
- return function () {
33
- cancel();
34
- };
35
- });
36
- };
37
- };
6
+ const { url } = opts;
7
+ return (runtime)=>({ op })=>observable((observer)=>{
8
+ const { path , input , type } = op;
9
+ const { promise , cancel } = httpRequest({
10
+ url,
11
+ runtime,
12
+ type,
13
+ path,
14
+ input
15
+ });
16
+ promise.then((res)=>{
17
+ const transformed = transformResult(res.json, runtime);
18
+ if (!transformed.ok) {
19
+ observer.error(TRPCClientError.from(transformed.error, {
20
+ meta: res.meta
21
+ }));
22
+ return;
23
+ }
24
+ observer.next({
25
+ context: res.meta,
26
+ result: transformed.result
27
+ });
28
+ observer.complete();
29
+ }).catch((cause)=>observer.error(TRPCClientError.from(cause)));
30
+ return ()=>{
31
+ cancel();
32
+ };
33
+ });
38
34
  }
39
35
 
40
36
  export { httpLink };
@@ -0,0 +1,9 @@
1
+ export * from './dedupeLink';
2
+ export * from './httpBatchLink';
3
+ export * from './httpLink';
4
+ export * from './loggerLink';
5
+ export * from './retryLink';
6
+ export * from './splitLink';
7
+ export * from './wsLink';
8
+ export * from './types';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/client/src/links/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createChain.d.ts","sourceRoot":"","sources":["../../../src/links/internals/createChain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAE/E,gBAAgB;AAChB,wBAAgB,WAAW,CACzB,OAAO,SAAS,SAAS,EACzB,MAAM,GAAG,OAAO,EAChB,OAAO,GAAG,OAAO,EACjB,IAAI,EAAE;IACN,KAAK,EAAE,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IACjD,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;CACvB,GAAG,yBAAyB,CAAC,OAAO,EAAE,OAAO,CAAC,CAkB9C"}
1
+ {"version":3,"file":"createChain.d.ts","sourceRoot":"","sources":["../../../../../packages/client/src/links/internals/createChain.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAE/E,gBAAgB;AAChB,wBAAgB,WAAW,CACzB,OAAO,SAAS,SAAS,EACzB,MAAM,GAAG,OAAO,EAChB,OAAO,GAAG,OAAO,EACjB,IAAI,EAAE;IACN,KAAK,EAAE,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IACjD,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;CACvB,GAAG,yBAAyB,CAAC,OAAO,EAAE,OAAO,CAAC,CAuB9C"}
@@ -0,0 +1,31 @@
1
+ import { ProcedureType } from '@trpc/server';
2
+ import { TRPCResponse } from '@trpc/server/rpc';
3
+ import { PromiseAndCancel, TRPCClientRuntime } from '../types';
4
+ export interface HTTPLinkOptions {
5
+ url: string;
6
+ }
7
+ export interface HTTPResult {
8
+ json: TRPCResponse;
9
+ meta: {
10
+ response: Response;
11
+ };
12
+ }
13
+ declare type GetInputOptions = {
14
+ runtime: TRPCClientRuntime;
15
+ } & ({
16
+ inputs: unknown[];
17
+ } | {
18
+ input: unknown;
19
+ });
20
+ export declare type HTTPRequestOptions = HTTPLinkOptions & GetInputOptions & {
21
+ type: ProcedureType;
22
+ path: string;
23
+ };
24
+ export declare function getUrl(opts: HTTPRequestOptions): string;
25
+ declare type GetBodyOptions = {
26
+ type: ProcedureType;
27
+ } & GetInputOptions;
28
+ export declare function getBody(opts: GetBodyOptions): string | undefined;
29
+ export declare function httpRequest(opts: HTTPRequestOptions): PromiseAndCancel<HTTPResult>;
30
+ export {};
31
+ //# sourceMappingURL=httpUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"httpUtils.d.ts","sourceRoot":"","sources":["../../../../../packages/client/src/links/internals/httpUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE/D,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;CACb;AAkBD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE;QACJ,QAAQ,EAAE,QAAQ,CAAC;KACpB,CAAC;CACH;AAED,aAAK,eAAe,GAAG;IACrB,OAAO,EAAE,iBAAiB,CAAC;CAC5B,GAAG,CAAC;IAAE,MAAM,EAAE,OAAO,EAAE,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAUjD,oBAAY,kBAAkB,GAAG,eAAe,GAC9C,eAAe,GAAG;IAChB,IAAI,EAAE,aAAa,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAEJ,wBAAgB,MAAM,CAAC,IAAI,EAAE,kBAAkB,UAgB9C;AAED,aAAK,cAAc,GAAG;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GAAG,eAAe,CAAC;AAEhE,wBAAgB,OAAO,CAAC,IAAI,EAAE,cAAc,sBAM3C;AAED,wBAAgB,WAAW,CACzB,IAAI,EAAE,kBAAkB,GACvB,gBAAgB,CAAC,UAAU,CAAC,CAqC9B"}
@@ -0,0 +1,28 @@
1
+ import { AnyRouter, inferRouterError } from '@trpc/server';
2
+ import { TRPCResponse, TRPCResponseMessage } from '@trpc/server/rpc';
3
+ import { TRPCClientRuntime } from '..';
4
+ /** @internal */
5
+ export declare function transformResult<TRouter extends AnyRouter, TOutput>(response: TRPCResponseMessage<TOutput, inferRouterError<TRouter>> | TRPCResponse<TOutput, inferRouterError<TRouter>>, runtime: TRPCClientRuntime): {
6
+ readonly ok: false;
7
+ readonly error: {
8
+ readonly error: inferRouterError<TRouter>;
9
+ readonly id?: import("@trpc/server/rpc").JSONRPC2.RequestId | undefined;
10
+ readonly jsonrpc?: "2.0" | undefined;
11
+ } | {
12
+ readonly error: inferRouterError<TRouter>;
13
+ readonly id: string | number | null;
14
+ readonly jsonrpc?: "2.0" | undefined;
15
+ };
16
+ readonly result?: undefined;
17
+ } | {
18
+ readonly ok: true;
19
+ readonly result: {
20
+ type: "started";
21
+ } | {
22
+ type: "stopped";
23
+ } | (import("@trpc/server/rpc").TRPCResult<TOutput> & {
24
+ type: "data";
25
+ });
26
+ readonly error?: undefined;
27
+ };
28
+ //# sourceMappingURL=transformResult.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformResult.d.ts","sourceRoot":"","sources":["../../../../../packages/client/src/links/internals/transformResult.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EACL,YAAY,EACZ,mBAAmB,EAEpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAC;AAKvC,gBAAgB;AAChB,wBAAgB,eAAe,CAAC,OAAO,SAAS,SAAS,EAAE,OAAO,EAChE,QAAQ,EACJ,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,GACvD,YAAY,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,EACpD,OAAO,EAAE,iBAAiB;;;;;;;;;;;;;;;;;;;;;;EAuB3B"}