@trpc/client 11.0.0-next.92 → 11.0.0-rc.330

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 (159) hide show
  1. package/README.md +4 -4
  2. package/dist/TRPCClientError.d.ts +8 -7
  3. package/dist/TRPCClientError.d.ts.map +1 -1
  4. package/dist/{TRPCClientError-e224e397.js → TRPCClientError.js} +3 -3
  5. package/dist/{TRPCClientError-0de4d231.mjs → TRPCClientError.mjs} +4 -4
  6. package/dist/bundle-analysis.json +126 -155
  7. package/dist/createTRPCClient.d.ts +27 -19
  8. package/dist/createTRPCClient.d.ts.map +1 -1
  9. package/dist/createTRPCClient.js +50 -0
  10. package/dist/createTRPCClient.mjs +45 -0
  11. package/dist/createTRPCUntypedClient.d.ts +3 -2
  12. package/dist/createTRPCUntypedClient.d.ts.map +1 -1
  13. package/dist/createTRPCUntypedClient.js +10 -0
  14. package/dist/createTRPCUntypedClient.mjs +7 -0
  15. package/dist/getFetch.d.ts +1 -1
  16. package/dist/getFetch.d.ts.map +1 -1
  17. package/dist/getFetch.js +17 -0
  18. package/dist/getFetch.mjs +15 -0
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +32 -370
  21. package/dist/index.mjs +9 -354
  22. package/dist/internals/TRPCUntypedClient.d.ts +5 -30
  23. package/dist/internals/TRPCUntypedClient.d.ts.map +1 -1
  24. package/dist/internals/TRPCUntypedClient.js +85 -0
  25. package/dist/internals/TRPCUntypedClient.mjs +83 -0
  26. package/dist/internals/dataLoader.d.ts +1 -1
  27. package/dist/internals/dataLoader.d.ts.map +1 -1
  28. package/dist/{httpBatchLink-204206a5.mjs → internals/dataLoader.js} +2 -117
  29. package/dist/internals/dataLoader.mjs +131 -0
  30. package/dist/internals/getAbortController.d.ts +2 -2
  31. package/dist/internals/getAbortController.d.ts.map +1 -1
  32. package/dist/internals/getAbortController.js +18 -0
  33. package/dist/internals/getAbortController.mjs +16 -0
  34. package/dist/internals/transformer.d.ts +42 -0
  35. package/dist/internals/transformer.d.ts.map +1 -0
  36. package/dist/internals/transformer.js +30 -0
  37. package/dist/internals/transformer.mjs +28 -0
  38. package/dist/internals/types.d.ts +4 -2
  39. package/dist/internals/types.d.ts.map +1 -1
  40. package/dist/links/HTTPBatchLinkOptions.d.ts +6 -5
  41. package/dist/links/HTTPBatchLinkOptions.d.ts.map +1 -1
  42. package/dist/links/httpBatchLink.d.ts +2 -2
  43. package/dist/links/httpBatchLink.d.ts.map +1 -1
  44. package/dist/links/httpBatchLink.js +37 -9
  45. package/dist/links/httpBatchLink.mjs +39 -5
  46. package/dist/links/httpBatchStreamLink.d.ts +6 -5
  47. package/dist/links/httpBatchStreamLink.d.ts.map +1 -1
  48. package/dist/links/httpBatchStreamLink.js +43 -0
  49. package/dist/links/httpBatchStreamLink.mjs +41 -0
  50. package/dist/links/httpFormDataLink.d.ts +1 -1
  51. package/dist/links/httpFormDataLink.d.ts.map +1 -1
  52. package/dist/links/httpFormDataLink.js +31 -0
  53. package/dist/links/httpFormDataLink.mjs +29 -0
  54. package/dist/links/httpLink.d.ts +8 -8
  55. package/dist/links/httpLink.d.ts.map +1 -1
  56. package/dist/links/httpLink.js +6 -9
  57. package/dist/links/httpLink.mjs +6 -7
  58. package/dist/links/internals/createChain.d.ts +2 -2
  59. package/dist/links/internals/createChain.d.ts.map +1 -1
  60. package/dist/{splitLink-f29e84be.js → links/internals/createChain.js} +0 -22
  61. package/dist/{splitLink-4c75f7be.mjs → links/internals/createChain.mjs} +1 -22
  62. package/dist/links/internals/createHTTPBatchLink.d.ts +6 -6
  63. package/dist/links/internals/createHTTPBatchLink.d.ts.map +1 -1
  64. package/dist/links/internals/createHTTPBatchLink.js +85 -0
  65. package/dist/links/internals/createHTTPBatchLink.mjs +83 -0
  66. package/dist/links/internals/dedupeLink.d.ts +2 -2
  67. package/dist/links/internals/dedupeLink.d.ts.map +1 -1
  68. package/dist/links/internals/getTextDecoder.d.ts +1 -1
  69. package/dist/links/internals/getTextDecoder.d.ts.map +1 -1
  70. package/dist/links/internals/getTextDecoder.js +18 -0
  71. package/dist/links/internals/getTextDecoder.mjs +16 -0
  72. package/dist/links/internals/httpUtils.d.ts +19 -11
  73. package/dist/links/internals/httpUtils.d.ts.map +1 -1
  74. package/dist/{httpUtils-c0e7bf5a.js → links/internals/httpUtils.js} +20 -39
  75. package/dist/{httpUtils-f58ceda1.mjs → links/internals/httpUtils.mjs} +20 -38
  76. package/dist/links/internals/parseJSONStream.d.ts +5 -6
  77. package/dist/links/internals/parseJSONStream.d.ts.map +1 -1
  78. package/dist/links/internals/parseJSONStream.js +118 -0
  79. package/dist/links/internals/parseJSONStream.mjs +115 -0
  80. package/dist/links/internals/retryLink.d.ts +2 -2
  81. package/dist/links/internals/retryLink.d.ts.map +1 -1
  82. package/dist/links/loggerLink.d.ts +4 -4
  83. package/dist/links/loggerLink.d.ts.map +1 -1
  84. package/dist/links/loggerLink.js +6 -4
  85. package/dist/links/loggerLink.mjs +6 -2
  86. package/dist/links/splitLink.d.ts +2 -2
  87. package/dist/links/splitLink.d.ts.map +1 -1
  88. package/dist/links/splitLink.js +23 -6
  89. package/dist/links/splitLink.mjs +25 -2
  90. package/dist/links/types.d.ts +15 -14
  91. package/dist/links/types.d.ts.map +1 -1
  92. package/dist/links/wsLink.d.ts +44 -13
  93. package/dist/links/wsLink.d.ts.map +1 -1
  94. package/dist/links/wsLink.js +64 -24
  95. package/dist/links/wsLink.mjs +64 -22
  96. package/dist/links.d.ts +10 -0
  97. package/dist/links.d.ts.map +1 -0
  98. package/dist/unstable-internals.d.ts +2 -0
  99. package/dist/unstable-internals.d.ts.map +1 -0
  100. package/dist/unstable-internals.js +7 -0
  101. package/dist/unstable-internals.mjs +1 -0
  102. package/package.json +26 -28
  103. package/src/TRPCClientError.ts +24 -13
  104. package/src/createTRPCClient.ts +58 -51
  105. package/src/createTRPCUntypedClient.ts +3 -5
  106. package/src/getFetch.ts +1 -1
  107. package/src/index.ts +2 -0
  108. package/src/internals/TRPCUntypedClient.ts +14 -84
  109. package/src/internals/dataLoader.ts +1 -1
  110. package/src/internals/getAbortController.ts +2 -2
  111. package/src/internals/transformer.ts +76 -0
  112. package/src/internals/types.ts +8 -1
  113. package/src/links/HTTPBatchLinkOptions.ts +17 -15
  114. package/src/links/httpBatchLink.ts +9 -8
  115. package/src/links/httpBatchStreamLink.ts +17 -17
  116. package/src/links/httpFormDataLink.ts +11 -12
  117. package/src/links/httpLink.ts +27 -19
  118. package/src/links/internals/createChain.ts +6 -2
  119. package/src/links/internals/createHTTPBatchLink.ts +24 -16
  120. package/src/links/internals/dedupeLink.ts +4 -3
  121. package/src/links/internals/getTextDecoder.ts +1 -1
  122. package/src/links/internals/httpUtils.ts +42 -21
  123. package/src/links/internals/parseJSONStream.ts +12 -14
  124. package/src/links/internals/retryLink.ts +4 -3
  125. package/src/links/loggerLink.ts +5 -5
  126. package/src/links/splitLink.ts +2 -2
  127. package/src/links/types.ts +27 -22
  128. package/src/links/wsLink.ts +124 -36
  129. package/src/links.ts +14 -0
  130. package/src/unstable-internals.ts +1 -0
  131. package/unstable-internals/index.d.ts +1 -0
  132. package/unstable-internals/index.js +1 -0
  133. package/dist/TRPCClientError-23c8aa93.js +0 -61
  134. package/dist/httpBatchLink-64fceaac.js +0 -251
  135. package/dist/httpBatchLink-92dab48e.js +0 -247
  136. package/dist/httpUtils-35e50476.js +0 -145
  137. package/dist/internals/isObject.d.ts +0 -2
  138. package/dist/internals/isObject.d.ts.map +0 -1
  139. package/dist/internals/retryDelay.d.ts +0 -2
  140. package/dist/internals/retryDelay.d.ts.map +0 -1
  141. package/dist/links/index.d.ts +0 -10
  142. package/dist/links/index.d.ts.map +0 -1
  143. package/dist/shared/index.d.ts +0 -2
  144. package/dist/shared/index.d.ts.map +0 -1
  145. package/dist/shared/index.js +0 -9
  146. package/dist/shared/index.mjs +0 -1
  147. package/dist/shared/transformResult.d.ts +0 -34
  148. package/dist/shared/transformResult.d.ts.map +0 -1
  149. package/dist/splitLink-0df96fdc.js +0 -41
  150. package/dist/transformResult-ace864b8.mjs +0 -58
  151. package/dist/transformResult-c1422cb5.js +0 -60
  152. package/dist/transformResult-dfce8f15.js +0 -61
  153. package/shared/index.d.ts +0 -1
  154. package/shared/index.js +0 -1
  155. package/src/internals/isObject.ts +0 -4
  156. package/src/internals/retryDelay.ts +0 -3
  157. package/src/links/index.ts +0 -14
  158. package/src/shared/index.ts +0 -1
  159. package/src/shared/transformResult.ts +0 -79
@@ -1,247 +0,0 @@
1
- import { observable } from '@trpc/server/observable';
2
- import { t as transformResult } from './transformResult-c1422cb5.js';
3
- import { T as TRPCClientError } from './TRPCClientError-23c8aa93.js';
4
- import { r as resolveHTTPLinkOptions, g as getUrl, j as jsonHttpRequester } from './httpUtils-35e50476.js';
5
-
6
- /**
7
- * A function that should never be called unless we messed something up.
8
- */
9
- const throwFatalError = () => {
10
- throw new Error('Something went wrong. Please submit an issue at https://github.com/trpc/trpc/issues/new');
11
- };
12
- /**
13
- * Dataloader that's very inspired by https://github.com/graphql/dataloader
14
- * Less configuration, no caching, and allows you to cancel requests
15
- * When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
16
- */
17
- function dataLoader(batchLoader) {
18
- let pendingItems = null;
19
- let dispatchTimer = null;
20
- const destroyTimerAndPendingItems = () => {
21
- clearTimeout(dispatchTimer);
22
- dispatchTimer = null;
23
- pendingItems = null;
24
- };
25
- /**
26
- * Iterate through the items and split them into groups based on the `batchLoader`'s validate function
27
- */
28
- function groupItems(items) {
29
- const groupedItems = [[]];
30
- let index = 0;
31
- while (true) {
32
- const item = items[index];
33
- if (!item) {
34
- // we're done
35
- break;
36
- }
37
- const lastGroup = groupedItems[groupedItems.length - 1];
38
- if (item.aborted) {
39
- // Item was aborted before it was dispatched
40
- item.reject?.(new Error('Aborted'));
41
- index++;
42
- continue;
43
- }
44
- const isValid = batchLoader.validate(lastGroup.concat(item).map((it) => it.key));
45
- if (isValid) {
46
- lastGroup.push(item);
47
- index++;
48
- continue;
49
- }
50
- if (lastGroup.length === 0) {
51
- item.reject?.(new Error('Input is too big for a single dispatch'));
52
- index++;
53
- continue;
54
- }
55
- // Create new group, next iteration will try to add the item to that
56
- groupedItems.push([]);
57
- }
58
- return groupedItems;
59
- }
60
- function dispatch() {
61
- const groupedItems = groupItems(pendingItems);
62
- destroyTimerAndPendingItems();
63
- // Create batches for each group of items
64
- for (const items of groupedItems) {
65
- if (!items.length) {
66
- continue;
67
- }
68
- const batch = {
69
- items,
70
- cancel: throwFatalError,
71
- };
72
- for (const item of items) {
73
- item.batch = batch;
74
- }
75
- const unitResolver = (index, value) => {
76
- const item = batch.items[index];
77
- item.resolve?.(value);
78
- item.batch = null;
79
- item.reject = null;
80
- item.resolve = null;
81
- };
82
- const { promise, cancel } = batchLoader.fetch(batch.items.map((_item) => _item.key), unitResolver);
83
- batch.cancel = cancel;
84
- promise
85
- .then((result) => {
86
- for (let i = 0; i < result.length; i++) {
87
- const value = result[i];
88
- unitResolver(i, value);
89
- }
90
- for (const item of batch.items) {
91
- item.reject?.(new Error('Missing result'));
92
- item.batch = null;
93
- }
94
- })
95
- .catch((cause) => {
96
- for (const item of batch.items) {
97
- item.reject?.(cause);
98
- item.batch = null;
99
- }
100
- });
101
- }
102
- }
103
- function load(key) {
104
- const item = {
105
- aborted: false,
106
- key,
107
- batch: null,
108
- resolve: throwFatalError,
109
- reject: throwFatalError,
110
- };
111
- const promise = new Promise((resolve, reject) => {
112
- item.reject = reject;
113
- item.resolve = resolve;
114
- if (!pendingItems) {
115
- pendingItems = [];
116
- }
117
- pendingItems.push(item);
118
- });
119
- if (!dispatchTimer) {
120
- dispatchTimer = setTimeout(dispatch);
121
- }
122
- const cancel = () => {
123
- item.aborted = true;
124
- if (item.batch?.items.every((item) => item.aborted)) {
125
- // All items in the batch have been cancelled
126
- item.batch.cancel();
127
- item.batch = null;
128
- }
129
- };
130
- return { promise, cancel };
131
- }
132
- return {
133
- load,
134
- };
135
- }
136
-
137
- /**
138
- * @internal
139
- */
140
- function createHTTPBatchLink(requester) {
141
- return function httpBatchLink(opts) {
142
- const resolvedOpts = resolveHTTPLinkOptions(opts);
143
- const maxURLLength = opts.maxURLLength ?? Infinity;
144
- // initialized config
145
- return (runtime) => {
146
- const batchLoader = (type) => {
147
- const validate = (batchOps) => {
148
- if (maxURLLength === Infinity) {
149
- // escape hatch for quick calcs
150
- return true;
151
- }
152
- const path = batchOps.map((op) => op.path).join(',');
153
- const inputs = batchOps.map((op) => op.input);
154
- const url = getUrl({
155
- ...resolvedOpts,
156
- runtime,
157
- type,
158
- path,
159
- inputs,
160
- });
161
- return url.length <= maxURLLength;
162
- };
163
- const fetch = requester({
164
- ...resolvedOpts,
165
- runtime,
166
- type,
167
- opts,
168
- });
169
- return { validate, fetch };
170
- };
171
- const query = dataLoader(batchLoader('query'));
172
- const mutation = dataLoader(batchLoader('mutation'));
173
- const subscription = dataLoader(batchLoader('subscription'));
174
- const loaders = { query, subscription, mutation };
175
- return ({ op }) => {
176
- return observable((observer) => {
177
- const loader = loaders[op.type];
178
- const { promise, cancel } = loader.load(op);
179
- let _res = undefined;
180
- promise
181
- .then((res) => {
182
- _res = res;
183
- const transformed = transformResult(res.json, runtime);
184
- if (!transformed.ok) {
185
- observer.error(TRPCClientError.from(transformed.error, {
186
- meta: res.meta,
187
- }));
188
- return;
189
- }
190
- observer.next({
191
- context: res.meta,
192
- result: transformed.result,
193
- });
194
- observer.complete();
195
- })
196
- .catch((err) => {
197
- observer.error(TRPCClientError.from(err, {
198
- meta: _res?.meta,
199
- }));
200
- });
201
- return () => {
202
- cancel();
203
- };
204
- });
205
- };
206
- };
207
- };
208
- }
209
-
210
- const batchRequester = (requesterOpts) => {
211
- return (batchOps) => {
212
- const path = batchOps.map((op) => op.path).join(',');
213
- const inputs = batchOps.map((op) => op.input);
214
- const { promise, cancel } = jsonHttpRequester({
215
- ...requesterOpts,
216
- path,
217
- inputs,
218
- headers() {
219
- if (!requesterOpts.opts.headers) {
220
- return {};
221
- }
222
- if (typeof requesterOpts.opts.headers === 'function') {
223
- return requesterOpts.opts.headers({
224
- opList: batchOps,
225
- });
226
- }
227
- return requesterOpts.opts.headers;
228
- },
229
- });
230
- return {
231
- promise: promise.then((res) => {
232
- const resJSON = Array.isArray(res.json)
233
- ? res.json
234
- : batchOps.map(() => res.json);
235
- const result = resJSON.map((item) => ({
236
- meta: res.meta,
237
- json: item,
238
- }));
239
- return result;
240
- }),
241
- cancel,
242
- };
243
- };
244
- };
245
- const httpBatchLink = createHTTPBatchLink(batchRequester);
246
-
247
- export { createHTTPBatchLink as c, httpBatchLink as h };
@@ -1,145 +0,0 @@
1
- import { T as TRPCClientError } from './TRPCClientError-23c8aa93.js';
2
-
3
- const isFunction = (fn) => typeof fn === 'function';
4
- function getFetch(customFetchImpl) {
5
- if (customFetchImpl) {
6
- return customFetchImpl;
7
- }
8
- if (typeof window !== 'undefined' && isFunction(window.fetch)) {
9
- return window.fetch;
10
- }
11
- if (typeof globalThis !== 'undefined' && isFunction(globalThis.fetch)) {
12
- return globalThis.fetch;
13
- }
14
- throw new Error('No fetch implementation found');
15
- }
16
-
17
- function getAbortController(customAbortControllerImpl) {
18
- if (customAbortControllerImpl) {
19
- return customAbortControllerImpl;
20
- }
21
- // eslint-disable-next-line @typescript-eslint/prefer-optional-chain
22
- if (typeof window !== 'undefined' && window.AbortController) {
23
- return window.AbortController;
24
- }
25
- // eslint-disable-next-line @typescript-eslint/prefer-optional-chain
26
- if (typeof globalThis !== 'undefined' && globalThis.AbortController) {
27
- return globalThis.AbortController;
28
- }
29
- return null;
30
- }
31
-
32
- function resolveHTTPLinkOptions(opts) {
33
- return {
34
- url: opts.url.toString().replace(/\/$/, ''),
35
- fetch: opts.fetch,
36
- AbortController: getAbortController(opts.AbortController),
37
- };
38
- }
39
- // https://github.com/trpc/trpc/pull/669
40
- function arrayToDict(array) {
41
- const dict = {};
42
- for (let index = 0; index < array.length; index++) {
43
- const element = array[index];
44
- dict[index] = element;
45
- }
46
- return dict;
47
- }
48
- const METHOD = {
49
- query: 'GET',
50
- mutation: 'POST',
51
- };
52
- function getInput(opts) {
53
- return 'input' in opts
54
- ? opts.runtime.transformer.serialize(opts.input)
55
- : arrayToDict(opts.inputs.map((_input) => opts.runtime.transformer.serialize(_input)));
56
- }
57
- const getUrl = (opts) => {
58
- let url = opts.url + '/' + opts.path;
59
- const queryParts = [];
60
- if ('inputs' in opts) {
61
- queryParts.push('batch=1');
62
- }
63
- if (opts.type === 'query') {
64
- const input = getInput(opts);
65
- if (input !== undefined) {
66
- queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`);
67
- }
68
- }
69
- if (queryParts.length) {
70
- url += '?' + queryParts.join('&');
71
- }
72
- return url;
73
- };
74
- const getBody = (opts) => {
75
- if (opts.type === 'query') {
76
- return undefined;
77
- }
78
- const input = getInput(opts);
79
- return input !== undefined ? JSON.stringify(input) : undefined;
80
- };
81
- const jsonHttpRequester = (opts) => {
82
- return httpRequest({
83
- ...opts,
84
- contentTypeHeader: 'application/json',
85
- getUrl,
86
- getBody,
87
- });
88
- };
89
- async function fetchHTTPResponse(opts, ac) {
90
- const url = opts.getUrl(opts);
91
- const body = opts.getBody(opts);
92
- const { type } = opts;
93
- const resolvedHeaders = await opts.headers();
94
- /* istanbul ignore if -- @preserve */
95
- if (type === 'subscription') {
96
- throw new Error('Subscriptions should use wsLink');
97
- }
98
- const headers = {
99
- ...(opts.contentTypeHeader
100
- ? { 'content-type': opts.contentTypeHeader }
101
- : {}),
102
- ...(opts.batchModeHeader
103
- ? { 'trpc-batch-mode': opts.batchModeHeader }
104
- : {}),
105
- ...resolvedHeaders,
106
- };
107
- return getFetch(opts.fetch)(url, {
108
- method: METHOD[type],
109
- signal: ac?.signal,
110
- body: body,
111
- headers,
112
- });
113
- }
114
- function httpRequest(opts) {
115
- const ac = opts.AbortController ? new opts.AbortController() : null;
116
- const meta = {};
117
- let done = false;
118
- const promise = new Promise((resolve, reject) => {
119
- fetchHTTPResponse(opts, ac)
120
- .then((_res) => {
121
- meta.response = _res;
122
- done = true;
123
- return _res.json();
124
- })
125
- .then((json) => {
126
- meta.responseJSON = json;
127
- resolve({
128
- json: json,
129
- meta,
130
- });
131
- })
132
- .catch((err) => {
133
- done = true;
134
- reject(TRPCClientError.from(err, { meta }));
135
- });
136
- });
137
- const cancel = () => {
138
- if (!done) {
139
- ac?.abort();
140
- }
141
- };
142
- return { promise, cancel };
143
- }
144
-
145
- export { getBody as a, getFetch as b, fetchHTTPResponse as f, getUrl as g, httpRequest as h, jsonHttpRequester as j, resolveHTTPLinkOptions as r };
@@ -1,2 +0,0 @@
1
- export declare function isObject(value: unknown): value is Record<string, unknown>;
2
- //# sourceMappingURL=isObject.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isObject.d.ts","sourceRoot":"","sources":["../../src/internals/isObject.ts"],"names":[],"mappings":"AAAA,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAGzE"}
@@ -1,2 +0,0 @@
1
- export declare const retryDelay: (attemptIndex: number) => number;
2
- //# sourceMappingURL=retryDelay.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"retryDelay.d.ts","sourceRoot":"","sources":["../../src/internals/retryDelay.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,UAAU,iBAAkB,MAAM,WACqB,CAAC"}
@@ -1,10 +0,0 @@
1
- export * from './types';
2
- export * from './HTTPBatchLinkOptions';
3
- export * from './httpBatchLink';
4
- export * from './httpBatchStreamLink';
5
- export * from './httpLink';
6
- export * from './loggerLink';
7
- export * from './splitLink';
8
- export * from './wsLink';
9
- export * from './httpFormDataLink';
10
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/links/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AAExB,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC;AAChC,cAAc,uBAAuB,CAAC;AACtC,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,oBAAoB,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './transformResult';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/shared/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC"}
@@ -1,9 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var transformResult = require('../transformResult-dfce8f15.js');
6
-
7
-
8
-
9
- exports.transformResult = transformResult.transformResult;
@@ -1 +0,0 @@
1
- export { t as transformResult } from '../transformResult-ace864b8.mjs';
@@ -1,34 +0,0 @@
1
- import type { AnyRouter, inferRouterError } from '@trpc/server';
2
- import type { TRPCResponse, TRPCResponseMessage } from '@trpc/server/rpc';
3
- import type { TRPCClientRuntime } from '../links';
4
- /** @internal */
5
- declare function transformResultInner<TRouter extends AnyRouter, TOutput>(response: TRPCResponse<TOutput, inferRouterError<TRouter>> | TRPCResponseMessage<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
- /**
29
- * Transforms and validates that the result is a valid TRPCResponse
30
- * @internal
31
- */
32
- export declare function transformResult<TRouter extends AnyRouter, TOutput>(response: TRPCResponse<TOutput, inferRouterError<TRouter>> | TRPCResponseMessage<TOutput, inferRouterError<TRouter>>, runtime: TRPCClientRuntime): ReturnType<typeof transformResultInner>;
33
- export {};
34
- //# sourceMappingURL=transformResult.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"transformResult.d.ts","sourceRoot":"","sources":["../../src/shared/transformResult.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,KAAK,EACV,YAAY,EACZ,mBAAmB,EAEpB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAKlD,gBAAgB;AAChB,iBAAS,oBAAoB,CAAC,OAAO,SAAS,SAAS,EAAE,OAAO,EAC9D,QAAQ,EACJ,YAAY,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAChD,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAC3D,OAAO,EAAE,iBAAiB;;;;;;;;;;;;;;;;;;;;;;EAuB3B;AAQD;;;GAGG;AACH,wBAAgB,eAAe,CAAC,OAAO,SAAS,SAAS,EAAE,OAAO,EAChE,QAAQ,EACJ,YAAY,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,GAChD,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAC3D,OAAO,EAAE,iBAAiB,GACzB,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAqBzC"}
@@ -1,41 +0,0 @@
1
- import { observable } from '@trpc/server/observable';
2
-
3
- /** @internal */
4
- function createChain(opts) {
5
- return observable((observer) => {
6
- function execute(index = 0, op = opts.op) {
7
- const next = opts.links[index];
8
- if (!next) {
9
- throw new Error('No more links to execute - did you forget to add an ending link?');
10
- }
11
- const subscription = next({
12
- op,
13
- next(nextOp) {
14
- const nextObserver = execute(index + 1, nextOp);
15
- return nextObserver;
16
- },
17
- });
18
- return subscription;
19
- }
20
- const obs$ = execute();
21
- return obs$.subscribe(observer);
22
- });
23
- }
24
-
25
- function asArray(value) {
26
- return Array.isArray(value) ? value : [value];
27
- }
28
- function splitLink(opts) {
29
- return (runtime) => {
30
- const yes = asArray(opts.true).map((link) => link(runtime));
31
- const no = asArray(opts.false).map((link) => link(runtime));
32
- return (props) => {
33
- return observable((observer) => {
34
- const links = opts.condition(props.op) ? yes : no;
35
- return createChain({ op: props.op, links }).subscribe(observer);
36
- });
37
- };
38
- };
39
- }
40
-
41
- export { createChain as c, splitLink as s };
@@ -1,58 +0,0 @@
1
- function isObject(value) {
2
- // check that value is object
3
- return !!value && !Array.isArray(value) && typeof value === 'object';
4
- }
5
-
6
- // FIXME:
7
- // - the generics here are probably unnecessary
8
- // - the RPC-spec could probably be simplified to combine HTTP + WS
9
- /** @internal */ function transformResultInner(response, runtime) {
10
- if ('error' in response) {
11
- const error = runtime.transformer.deserialize(response.error);
12
- return {
13
- ok: false,
14
- error: {
15
- ...response,
16
- error
17
- }
18
- };
19
- }
20
- const result = {
21
- ...response.result,
22
- ...(!response.result.type || response.result.type === 'data') && {
23
- type: 'data',
24
- data: runtime.transformer.deserialize(response.result.data)
25
- }
26
- };
27
- return {
28
- ok: true,
29
- result
30
- };
31
- }
32
- class TransformResultError extends Error {
33
- constructor(){
34
- super('Unable to transform response from server');
35
- }
36
- }
37
- /**
38
- * Transforms and validates that the result is a valid TRPCResponse
39
- * @internal
40
- */ function transformResult(response, runtime) {
41
- let result;
42
- try {
43
- // Use the data transformers on the JSON-response
44
- result = transformResultInner(response, runtime);
45
- } catch (err) {
46
- throw new TransformResultError();
47
- }
48
- // check that output of the transformers is a valid TRPCResponse
49
- if (!result.ok && (!isObject(result.error.error) || typeof result.error.error.code !== 'number')) {
50
- throw new TransformResultError();
51
- }
52
- if (result.ok && !isObject(result.result)) {
53
- throw new TransformResultError();
54
- }
55
- return result;
56
- }
57
-
58
- export { isObject as i, transformResult as t };
@@ -1,60 +0,0 @@
1
- function isObject(value) {
2
- // check that value is object
3
- return !!value && !Array.isArray(value) && typeof value === 'object';
4
- }
5
-
6
- // FIXME:
7
- // - the generics here are probably unnecessary
8
- // - the RPC-spec could probably be simplified to combine HTTP + WS
9
- /** @internal */
10
- function transformResultInner(response, runtime) {
11
- if ('error' in response) {
12
- const error = runtime.transformer.deserialize(response.error);
13
- return {
14
- ok: false,
15
- error: {
16
- ...response,
17
- error,
18
- },
19
- };
20
- }
21
- const result = {
22
- ...response.result,
23
- ...((!response.result.type || response.result.type === 'data') && {
24
- type: 'data',
25
- data: runtime.transformer.deserialize(response.result.data),
26
- }),
27
- };
28
- return { ok: true, result };
29
- }
30
- class TransformResultError extends Error {
31
- constructor() {
32
- super('Unable to transform response from server');
33
- }
34
- }
35
- /**
36
- * Transforms and validates that the result is a valid TRPCResponse
37
- * @internal
38
- */
39
- function transformResult(response, runtime) {
40
- let result;
41
- try {
42
- // Use the data transformers on the JSON-response
43
- result = transformResultInner(response, runtime);
44
- }
45
- catch (err) {
46
- throw new TransformResultError();
47
- }
48
- // check that output of the transformers is a valid TRPCResponse
49
- if (!result.ok &&
50
- (!isObject(result.error.error) ||
51
- typeof result.error.error.code !== 'number')) {
52
- throw new TransformResultError();
53
- }
54
- if (result.ok && !isObject(result.result)) {
55
- throw new TransformResultError();
56
- }
57
- return result;
58
- }
59
-
60
- export { isObject as i, transformResult as t };