@trpc/client 11.0.0-next-beta.205 → 11.0.0-next-beta.208
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.
- package/dist/{TRPCClientError-3414c3d5.mjs → TRPCClientError.mjs} +1 -1
- package/dist/bundle-analysis.json +61 -61
- package/dist/createTRPCClient.js +50 -0
- package/dist/createTRPCClient.mjs +45 -0
- package/dist/createTRPCUntypedClient.js +10 -0
- package/dist/createTRPCUntypedClient.mjs +7 -0
- package/dist/getFetch.js +17 -0
- package/dist/getFetch.mjs +15 -0
- package/dist/index.js +32 -368
- package/dist/index.mjs +9 -352
- package/dist/internals/TRPCUntypedClient.js +113 -0
- package/dist/internals/TRPCUntypedClient.mjs +111 -0
- package/dist/{httpBatchLink-0ee76b31.mjs → internals/dataLoader.js} +2 -117
- package/dist/{httpBatchLink-6c1c898e.js → internals/dataLoader.mjs} +1 -121
- package/dist/internals/getAbortController.js +18 -0
- package/dist/internals/getAbortController.mjs +16 -0
- package/dist/links/httpBatchLink.js +37 -9
- package/dist/links/httpBatchLink.mjs +39 -5
- package/dist/links/httpBatchStreamLink.js +43 -0
- package/dist/links/httpBatchStreamLink.mjs +41 -0
- package/dist/links/httpFormDataLink.js +31 -0
- package/dist/links/httpFormDataLink.mjs +29 -0
- package/dist/links/httpLink.js +2 -4
- package/dist/links/httpLink.mjs +2 -2
- package/dist/{splitLink-18238436.js → links/internals/createChain.js} +0 -22
- package/dist/{splitLink-13989f7f.mjs → links/internals/createChain.mjs} +1 -22
- package/dist/links/internals/createHTTPBatchLink.js +86 -0
- package/dist/links/internals/createHTTPBatchLink.mjs +84 -0
- package/dist/links/internals/getTextDecoder.js +18 -0
- package/dist/links/internals/getTextDecoder.mjs +16 -0
- package/dist/{httpUtils-60af4c3d.js → links/internals/httpUtils.js} +5 -33
- package/dist/{httpUtils-82ae6a64.mjs → links/internals/httpUtils.mjs} +4 -31
- package/dist/links/internals/parseJSONStream.js +118 -0
- package/dist/links/internals/parseJSONStream.mjs +115 -0
- package/dist/links/loggerLink.js +4 -2
- package/dist/links/loggerLink.mjs +4 -0
- package/dist/links/splitLink.js +23 -6
- package/dist/links/splitLink.mjs +25 -2
- package/dist/links/wsLink.js +1 -3
- package/dist/links/wsLink.mjs +1 -1
- package/package.json +4 -4
- package/dist/TRPCClientError-27d80214.js +0 -61
- package/dist/httpBatchLink-bc1c3273.js +0 -247
- package/dist/httpUtils-49fa3edc.js +0 -151
- package/dist/splitLink-bd4bf809.js +0 -41
- /package/dist/{TRPCClientError-67aefe1c.js → TRPCClientError.js} +0 -0
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { observable } from '@trpc/core/observable';
|
|
3
|
-
import { T as TRPCClientError } from './TRPCClientError-3414c3d5.mjs';
|
|
4
|
-
import { r as resolveHTTPLinkOptions, g as getUrl, j as jsonHttpRequester } from './httpUtils-82ae6a64.mjs';
|
|
1
|
+
'use strict';
|
|
5
2
|
|
|
6
3
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */ /**
|
|
7
4
|
* A function that should never be called unless we messed something up.
|
|
@@ -133,116 +130,4 @@ import { r as resolveHTTPLinkOptions, g as getUrl, j as jsonHttpRequester } from
|
|
|
133
130
|
};
|
|
134
131
|
}
|
|
135
132
|
|
|
136
|
-
|
|
137
|
-
* @internal
|
|
138
|
-
*/ function createHTTPBatchLink(requester) {
|
|
139
|
-
return function httpBatchLink(opts) {
|
|
140
|
-
const resolvedOpts = resolveHTTPLinkOptions(opts);
|
|
141
|
-
const maxURLLength = opts.maxURLLength ?? Infinity;
|
|
142
|
-
// initialized config
|
|
143
|
-
return (runtime)=>{
|
|
144
|
-
const batchLoader = (type)=>{
|
|
145
|
-
const validate = (batchOps)=>{
|
|
146
|
-
if (maxURLLength === Infinity) {
|
|
147
|
-
// escape hatch for quick calcs
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
const path = batchOps.map((op)=>op.path).join(',');
|
|
151
|
-
const inputs = batchOps.map((op)=>op.input);
|
|
152
|
-
const url = getUrl({
|
|
153
|
-
...resolvedOpts,
|
|
154
|
-
runtime,
|
|
155
|
-
type,
|
|
156
|
-
path,
|
|
157
|
-
inputs
|
|
158
|
-
});
|
|
159
|
-
return url.length <= maxURLLength;
|
|
160
|
-
};
|
|
161
|
-
const fetch = requester({
|
|
162
|
-
...resolvedOpts,
|
|
163
|
-
runtime,
|
|
164
|
-
type,
|
|
165
|
-
opts
|
|
166
|
-
});
|
|
167
|
-
return {
|
|
168
|
-
validate,
|
|
169
|
-
fetch
|
|
170
|
-
};
|
|
171
|
-
};
|
|
172
|
-
const query = dataLoader(batchLoader('query'));
|
|
173
|
-
const mutation = dataLoader(batchLoader('mutation'));
|
|
174
|
-
const subscription = dataLoader(batchLoader('subscription'));
|
|
175
|
-
const loaders = {
|
|
176
|
-
query,
|
|
177
|
-
subscription,
|
|
178
|
-
mutation
|
|
179
|
-
};
|
|
180
|
-
return ({ op })=>{
|
|
181
|
-
return observable((observer)=>{
|
|
182
|
-
const loader = loaders[op.type];
|
|
183
|
-
const { promise , cancel } = loader.load(op);
|
|
184
|
-
let _res = undefined;
|
|
185
|
-
promise.then((res)=>{
|
|
186
|
-
_res = res;
|
|
187
|
-
const transformed = transformResult(res.json, runtime.transformer);
|
|
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)=>{
|
|
200
|
-
observer.error(TRPCClientError.from(err, {
|
|
201
|
-
meta: _res?.meta
|
|
202
|
-
}));
|
|
203
|
-
});
|
|
204
|
-
return ()=>{
|
|
205
|
-
cancel();
|
|
206
|
-
};
|
|
207
|
-
});
|
|
208
|
-
};
|
|
209
|
-
};
|
|
210
|
-
};
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
const batchRequester = (requesterOpts)=>{
|
|
214
|
-
return (batchOps)=>{
|
|
215
|
-
const path = batchOps.map((op)=>op.path).join(',');
|
|
216
|
-
const inputs = batchOps.map((op)=>op.input);
|
|
217
|
-
const { promise , cancel } = jsonHttpRequester({
|
|
218
|
-
...requesterOpts,
|
|
219
|
-
path,
|
|
220
|
-
inputs,
|
|
221
|
-
headers () {
|
|
222
|
-
if (!requesterOpts.opts.headers) {
|
|
223
|
-
return {};
|
|
224
|
-
}
|
|
225
|
-
if (typeof requesterOpts.opts.headers === 'function') {
|
|
226
|
-
return requesterOpts.opts.headers({
|
|
227
|
-
opList: batchOps
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
return requesterOpts.opts.headers;
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
return {
|
|
234
|
-
promise: promise.then((res)=>{
|
|
235
|
-
const resJSON = Array.isArray(res.json) ? res.json : batchOps.map(()=>res.json);
|
|
236
|
-
const result = resJSON.map((item)=>({
|
|
237
|
-
meta: res.meta,
|
|
238
|
-
json: item
|
|
239
|
-
}));
|
|
240
|
-
return result;
|
|
241
|
-
}),
|
|
242
|
-
cancel
|
|
243
|
-
};
|
|
244
|
-
};
|
|
245
|
-
};
|
|
246
|
-
const httpBatchLink = createHTTPBatchLink(batchRequester);
|
|
247
|
-
|
|
248
|
-
export { createHTTPBatchLink as c, httpBatchLink as h };
|
|
133
|
+
exports.dataLoader = dataLoader;
|
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var core = require('@trpc/core');
|
|
4
|
-
var observable = require('@trpc/core/observable');
|
|
5
|
-
var TRPCClientError = require('./TRPCClientError-67aefe1c.js');
|
|
6
|
-
var httpUtils = require('./httpUtils-60af4c3d.js');
|
|
7
|
-
|
|
8
1
|
/* eslint-disable @typescript-eslint/no-non-null-assertion */ /**
|
|
9
2
|
* A function that should never be called unless we messed something up.
|
|
10
3
|
*/ const throwFatalError = ()=>{
|
|
@@ -135,117 +128,4 @@ var httpUtils = require('./httpUtils-60af4c3d.js');
|
|
|
135
128
|
};
|
|
136
129
|
}
|
|
137
130
|
|
|
138
|
-
|
|
139
|
-
* @internal
|
|
140
|
-
*/ function createHTTPBatchLink(requester) {
|
|
141
|
-
return function httpBatchLink(opts) {
|
|
142
|
-
const resolvedOpts = httpUtils.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 = httpUtils.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 {
|
|
170
|
-
validate,
|
|
171
|
-
fetch
|
|
172
|
-
};
|
|
173
|
-
};
|
|
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.observable((observer)=>{
|
|
184
|
-
const loader = loaders[op.type];
|
|
185
|
-
const { promise , cancel } = loader.load(op);
|
|
186
|
-
let _res = undefined;
|
|
187
|
-
promise.then((res)=>{
|
|
188
|
-
_res = res;
|
|
189
|
-
const transformed = core.transformResult(res.json, runtime.transformer);
|
|
190
|
-
if (!transformed.ok) {
|
|
191
|
-
observer.error(TRPCClientError.TRPCClientError.from(transformed.error, {
|
|
192
|
-
meta: res.meta
|
|
193
|
-
}));
|
|
194
|
-
return;
|
|
195
|
-
}
|
|
196
|
-
observer.next({
|
|
197
|
-
context: res.meta,
|
|
198
|
-
result: transformed.result
|
|
199
|
-
});
|
|
200
|
-
observer.complete();
|
|
201
|
-
}).catch((err)=>{
|
|
202
|
-
observer.error(TRPCClientError.TRPCClientError.from(err, {
|
|
203
|
-
meta: _res?.meta
|
|
204
|
-
}));
|
|
205
|
-
});
|
|
206
|
-
return ()=>{
|
|
207
|
-
cancel();
|
|
208
|
-
};
|
|
209
|
-
});
|
|
210
|
-
};
|
|
211
|
-
};
|
|
212
|
-
};
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
const batchRequester = (requesterOpts)=>{
|
|
216
|
-
return (batchOps)=>{
|
|
217
|
-
const path = batchOps.map((op)=>op.path).join(',');
|
|
218
|
-
const inputs = batchOps.map((op)=>op.input);
|
|
219
|
-
const { promise , cancel } = httpUtils.jsonHttpRequester({
|
|
220
|
-
...requesterOpts,
|
|
221
|
-
path,
|
|
222
|
-
inputs,
|
|
223
|
-
headers () {
|
|
224
|
-
if (!requesterOpts.opts.headers) {
|
|
225
|
-
return {};
|
|
226
|
-
}
|
|
227
|
-
if (typeof requesterOpts.opts.headers === 'function') {
|
|
228
|
-
return requesterOpts.opts.headers({
|
|
229
|
-
opList: batchOps
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
return requesterOpts.opts.headers;
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
return {
|
|
236
|
-
promise: promise.then((res)=>{
|
|
237
|
-
const resJSON = Array.isArray(res.json) ? res.json : batchOps.map(()=>res.json);
|
|
238
|
-
const result = resJSON.map((item)=>({
|
|
239
|
-
meta: res.meta,
|
|
240
|
-
json: item
|
|
241
|
-
}));
|
|
242
|
-
return result;
|
|
243
|
-
}),
|
|
244
|
-
cancel
|
|
245
|
-
};
|
|
246
|
-
};
|
|
247
|
-
};
|
|
248
|
-
const httpBatchLink = createHTTPBatchLink(batchRequester);
|
|
249
|
-
|
|
250
|
-
exports.createHTTPBatchLink = createHTTPBatchLink;
|
|
251
|
-
exports.httpBatchLink = httpBatchLink;
|
|
131
|
+
export { dataLoader };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function getAbortController(customAbortControllerImpl) {
|
|
4
|
+
if (customAbortControllerImpl) {
|
|
5
|
+
return customAbortControllerImpl;
|
|
6
|
+
}
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
|
8
|
+
if (typeof window !== 'undefined' && window.AbortController) {
|
|
9
|
+
return window.AbortController;
|
|
10
|
+
}
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
|
12
|
+
if (typeof globalThis !== 'undefined' && globalThis.AbortController) {
|
|
13
|
+
return globalThis.AbortController;
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
exports.getAbortController = getAbortController;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
function getAbortController(customAbortControllerImpl) {
|
|
2
|
+
if (customAbortControllerImpl) {
|
|
3
|
+
return customAbortControllerImpl;
|
|
4
|
+
}
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
|
6
|
+
if (typeof window !== 'undefined' && window.AbortController) {
|
|
7
|
+
return window.AbortController;
|
|
8
|
+
}
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
|
10
|
+
if (typeof globalThis !== 'undefined' && globalThis.AbortController) {
|
|
11
|
+
return globalThis.AbortController;
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { getAbortController };
|
|
@@ -1,13 +1,41 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
var createHTTPBatchLink = require('./internals/createHTTPBatchLink.js');
|
|
4
|
+
var httpUtils = require('./internals/httpUtils.js');
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
const batchRequester = (requesterOpts)=>{
|
|
7
|
+
return (batchOps)=>{
|
|
8
|
+
const path = batchOps.map((op)=>op.path).join(',');
|
|
9
|
+
const inputs = batchOps.map((op)=>op.input);
|
|
10
|
+
const { promise , cancel } = httpUtils.jsonHttpRequester({
|
|
11
|
+
...requesterOpts,
|
|
12
|
+
path,
|
|
13
|
+
inputs,
|
|
14
|
+
headers () {
|
|
15
|
+
if (!requesterOpts.opts.headers) {
|
|
16
|
+
return {};
|
|
17
|
+
}
|
|
18
|
+
if (typeof requesterOpts.opts.headers === 'function') {
|
|
19
|
+
return requesterOpts.opts.headers({
|
|
20
|
+
opList: batchOps
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return requesterOpts.opts.headers;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return {
|
|
27
|
+
promise: promise.then((res)=>{
|
|
28
|
+
const resJSON = Array.isArray(res.json) ? res.json : batchOps.map(()=>res.json);
|
|
29
|
+
const result = resJSON.map((item)=>({
|
|
30
|
+
meta: res.meta,
|
|
31
|
+
json: item
|
|
32
|
+
}));
|
|
33
|
+
return result;
|
|
34
|
+
}),
|
|
35
|
+
cancel
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
const httpBatchLink = createHTTPBatchLink.createHTTPBatchLink(batchRequester);
|
|
10
40
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
exports.httpBatchLink = links_httpBatchLink.httpBatchLink;
|
|
41
|
+
exports.httpBatchLink = httpBatchLink;
|
|
@@ -1,5 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
import '
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { createHTTPBatchLink } from './internals/createHTTPBatchLink.mjs';
|
|
2
|
+
import { jsonHttpRequester } from './internals/httpUtils.mjs';
|
|
3
|
+
|
|
4
|
+
const batchRequester = (requesterOpts)=>{
|
|
5
|
+
return (batchOps)=>{
|
|
6
|
+
const path = batchOps.map((op)=>op.path).join(',');
|
|
7
|
+
const inputs = batchOps.map((op)=>op.input);
|
|
8
|
+
const { promise , cancel } = jsonHttpRequester({
|
|
9
|
+
...requesterOpts,
|
|
10
|
+
path,
|
|
11
|
+
inputs,
|
|
12
|
+
headers () {
|
|
13
|
+
if (!requesterOpts.opts.headers) {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
if (typeof requesterOpts.opts.headers === 'function') {
|
|
17
|
+
return requesterOpts.opts.headers({
|
|
18
|
+
opList: batchOps
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return requesterOpts.opts.headers;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return {
|
|
25
|
+
promise: promise.then((res)=>{
|
|
26
|
+
const resJSON = Array.isArray(res.json) ? res.json : batchOps.map(()=>res.json);
|
|
27
|
+
const result = resJSON.map((item)=>({
|
|
28
|
+
meta: res.meta,
|
|
29
|
+
json: item
|
|
30
|
+
}));
|
|
31
|
+
return result;
|
|
32
|
+
}),
|
|
33
|
+
cancel
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
const httpBatchLink = createHTTPBatchLink(batchRequester);
|
|
38
|
+
|
|
39
|
+
export { httpBatchLink };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var createHTTPBatchLink = require('./internals/createHTTPBatchLink.js');
|
|
4
|
+
var getTextDecoder = require('./internals/getTextDecoder.js');
|
|
5
|
+
var parseJSONStream = require('./internals/parseJSONStream.js');
|
|
6
|
+
|
|
7
|
+
const streamRequester = (requesterOpts)=>{
|
|
8
|
+
const textDecoder = getTextDecoder.getTextDecoder(requesterOpts.opts.textDecoder);
|
|
9
|
+
return (batchOps, unitResolver)=>{
|
|
10
|
+
const path = batchOps.map((op)=>op.path).join(',');
|
|
11
|
+
const inputs = batchOps.map((op)=>op.input);
|
|
12
|
+
const { cancel , promise } = parseJSONStream.streamingJsonHttpRequester({
|
|
13
|
+
...requesterOpts,
|
|
14
|
+
textDecoder,
|
|
15
|
+
path,
|
|
16
|
+
inputs,
|
|
17
|
+
headers () {
|
|
18
|
+
if (!requesterOpts.opts.headers) {
|
|
19
|
+
return {};
|
|
20
|
+
}
|
|
21
|
+
if (typeof requesterOpts.opts.headers === 'function') {
|
|
22
|
+
return requesterOpts.opts.headers({
|
|
23
|
+
opList: batchOps
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return requesterOpts.opts.headers;
|
|
27
|
+
}
|
|
28
|
+
}, (index, res)=>{
|
|
29
|
+
unitResolver(index, res);
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
/**
|
|
33
|
+
* return an empty array because the batchLoader expects an array of results
|
|
34
|
+
* but we've already called the `unitResolver` for each of them, there's
|
|
35
|
+
* nothing left to do here.
|
|
36
|
+
*/ promise: promise.then(()=>[]),
|
|
37
|
+
cancel
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
const unstable_httpBatchStreamLink = createHTTPBatchLink.createHTTPBatchLink(streamRequester);
|
|
42
|
+
|
|
43
|
+
exports.unstable_httpBatchStreamLink = unstable_httpBatchStreamLink;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createHTTPBatchLink } from './internals/createHTTPBatchLink.mjs';
|
|
2
|
+
import { getTextDecoder } from './internals/getTextDecoder.mjs';
|
|
3
|
+
import { streamingJsonHttpRequester } from './internals/parseJSONStream.mjs';
|
|
4
|
+
|
|
5
|
+
const streamRequester = (requesterOpts)=>{
|
|
6
|
+
const textDecoder = getTextDecoder(requesterOpts.opts.textDecoder);
|
|
7
|
+
return (batchOps, unitResolver)=>{
|
|
8
|
+
const path = batchOps.map((op)=>op.path).join(',');
|
|
9
|
+
const inputs = batchOps.map((op)=>op.input);
|
|
10
|
+
const { cancel , promise } = streamingJsonHttpRequester({
|
|
11
|
+
...requesterOpts,
|
|
12
|
+
textDecoder,
|
|
13
|
+
path,
|
|
14
|
+
inputs,
|
|
15
|
+
headers () {
|
|
16
|
+
if (!requesterOpts.opts.headers) {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
if (typeof requesterOpts.opts.headers === 'function') {
|
|
20
|
+
return requesterOpts.opts.headers({
|
|
21
|
+
opList: batchOps
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
return requesterOpts.opts.headers;
|
|
25
|
+
}
|
|
26
|
+
}, (index, res)=>{
|
|
27
|
+
unitResolver(index, res);
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
/**
|
|
31
|
+
* return an empty array because the batchLoader expects an array of results
|
|
32
|
+
* but we've already called the `unitResolver` for each of them, there's
|
|
33
|
+
* nothing left to do here.
|
|
34
|
+
*/ promise: promise.then(()=>[]),
|
|
35
|
+
cancel
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
const unstable_httpBatchStreamLink = createHTTPBatchLink(streamRequester);
|
|
40
|
+
|
|
41
|
+
export { unstable_httpBatchStreamLink };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var httpLink = require('./httpLink.js');
|
|
4
|
+
var httpUtils = require('./internals/httpUtils.js');
|
|
5
|
+
|
|
6
|
+
const formDataRequester = (opts)=>{
|
|
7
|
+
if (opts.type !== 'mutation') {
|
|
8
|
+
// TODO(?) handle formdata queries
|
|
9
|
+
throw new Error('We only handle mutations with formdata');
|
|
10
|
+
}
|
|
11
|
+
return httpUtils.httpRequest({
|
|
12
|
+
...opts,
|
|
13
|
+
getUrl () {
|
|
14
|
+
return `${opts.url}/${opts.path}`;
|
|
15
|
+
},
|
|
16
|
+
getBody (opts) {
|
|
17
|
+
if (!('input' in opts)) {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
if (!(opts.input instanceof FormData)) {
|
|
21
|
+
throw new Error('Input is not FormData');
|
|
22
|
+
}
|
|
23
|
+
return opts.input;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
const experimental_formDataLink = httpLink.httpLinkFactory({
|
|
28
|
+
requester: formDataRequester
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
exports.experimental_formDataLink = experimental_formDataLink;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { httpLinkFactory } from './httpLink.mjs';
|
|
2
|
+
import { httpRequest } from './internals/httpUtils.mjs';
|
|
3
|
+
|
|
4
|
+
const formDataRequester = (opts)=>{
|
|
5
|
+
if (opts.type !== 'mutation') {
|
|
6
|
+
// TODO(?) handle formdata queries
|
|
7
|
+
throw new Error('We only handle mutations with formdata');
|
|
8
|
+
}
|
|
9
|
+
return httpRequest({
|
|
10
|
+
...opts,
|
|
11
|
+
getUrl () {
|
|
12
|
+
return `${opts.url}/${opts.path}`;
|
|
13
|
+
},
|
|
14
|
+
getBody (opts) {
|
|
15
|
+
if (!('input' in opts)) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
if (!(opts.input instanceof FormData)) {
|
|
19
|
+
throw new Error('Input is not FormData');
|
|
20
|
+
}
|
|
21
|
+
return opts.input;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
const experimental_formDataLink = httpLinkFactory({
|
|
26
|
+
requester: formDataRequester
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export { experimental_formDataLink };
|
package/dist/links/httpLink.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var core = require('@trpc/core');
|
|
6
4
|
var observable = require('@trpc/core/observable');
|
|
7
|
-
var TRPCClientError = require('../TRPCClientError
|
|
8
|
-
var httpUtils = require('
|
|
5
|
+
var TRPCClientError = require('../TRPCClientError.js');
|
|
6
|
+
var httpUtils = require('./internals/httpUtils.js');
|
|
9
7
|
|
|
10
8
|
function httpLinkFactory(factoryOpts) {
|
|
11
9
|
return (opts)=>{
|
package/dist/links/httpLink.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { transformResult } from '@trpc/core';
|
|
2
2
|
import { observable } from '@trpc/core/observable';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { TRPCClientError } from '../TRPCClientError.mjs';
|
|
4
|
+
import { resolveHTTPLinkOptions, jsonHttpRequester } from './internals/httpUtils.mjs';
|
|
5
5
|
|
|
6
6
|
function httpLinkFactory(factoryOpts) {
|
|
7
7
|
return (opts)=>{
|
|
@@ -23,26 +23,4 @@ var observable = require('@trpc/core/observable');
|
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
function asArray(value) {
|
|
27
|
-
return Array.isArray(value) ? value : [
|
|
28
|
-
value
|
|
29
|
-
];
|
|
30
|
-
}
|
|
31
|
-
function splitLink(opts) {
|
|
32
|
-
return (runtime)=>{
|
|
33
|
-
const yes = asArray(opts.true).map((link)=>link(runtime));
|
|
34
|
-
const no = asArray(opts.false).map((link)=>link(runtime));
|
|
35
|
-
return (props)=>{
|
|
36
|
-
return observable.observable((observer)=>{
|
|
37
|
-
const links = opts.condition(props.op) ? yes : no;
|
|
38
|
-
return createChain({
|
|
39
|
-
op: props.op,
|
|
40
|
-
links
|
|
41
|
-
}).subscribe(observer);
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
|
|
47
26
|
exports.createChain = createChain;
|
|
48
|
-
exports.splitLink = splitLink;
|
|
@@ -21,25 +21,4 @@ import { observable } from '@trpc/core/observable';
|
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
return Array.isArray(value) ? value : [
|
|
26
|
-
value
|
|
27
|
-
];
|
|
28
|
-
}
|
|
29
|
-
function splitLink(opts) {
|
|
30
|
-
return (runtime)=>{
|
|
31
|
-
const yes = asArray(opts.true).map((link)=>link(runtime));
|
|
32
|
-
const no = asArray(opts.false).map((link)=>link(runtime));
|
|
33
|
-
return (props)=>{
|
|
34
|
-
return observable((observer)=>{
|
|
35
|
-
const links = opts.condition(props.op) ? yes : no;
|
|
36
|
-
return createChain({
|
|
37
|
-
op: props.op,
|
|
38
|
-
links
|
|
39
|
-
}).subscribe(observer);
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export { createChain as c, splitLink as s };
|
|
24
|
+
export { createChain };
|