@trpc/client 11.0.0-alpha-tmp-export-from-main.213 → 11.0.0-alpha-tmp-export-from-main.217
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/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 -367
- package/dist/index.mjs +9 -351
- package/dist/internals/TRPCUntypedClient.js +113 -0
- package/dist/internals/TRPCUntypedClient.mjs +111 -0
- package/dist/{httpBatchLink-c5101526.mjs → internals/dataLoader.js} +2 -116
- package/dist/{httpBatchLink-63113d09.js → internals/dataLoader.mjs} +1 -120
- package/dist/internals/getAbortController.js +18 -0
- package/dist/internals/getAbortController.mjs +16 -0
- package/dist/links/httpBatchLink.js +37 -8
- package/dist/links/httpBatchLink.mjs +39 -4
- 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-f52aa788.js → links/internals/createChain.js} +0 -22
- package/dist/{splitLink-47716d78.mjs → links/internals/createChain.mjs} +1 -22
- package/dist/links/internals/createHTTPBatchLink.js +85 -0
- package/dist/links/internals/createHTTPBatchLink.mjs +83 -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-1de0fe31.js +0 -246
- package/dist/httpUtils-49fa3edc.js +0 -151
- package/dist/splitLink-7dca81ef.js +0 -41
- /package/dist/{TRPCClientError-67aefe1c.js → TRPCClientError.js} +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@trpc/core');
|
|
4
|
+
var TRPCUntypedClient = require('./internals/TRPCUntypedClient.js');
|
|
5
|
+
|
|
6
|
+
const clientCallTypeMap = {
|
|
7
|
+
query: 'query',
|
|
8
|
+
mutate: 'mutation',
|
|
9
|
+
subscribe: 'subscription'
|
|
10
|
+
};
|
|
11
|
+
/** @internal */ const clientCallTypeToProcedureType = (clientCallType)=>{
|
|
12
|
+
return clientCallTypeMap[clientCallType];
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*/ function createTRPCClientProxy(client) {
|
|
17
|
+
return core.createFlatProxy((key)=>{
|
|
18
|
+
if (client.hasOwnProperty(key)) {
|
|
19
|
+
return client[key];
|
|
20
|
+
}
|
|
21
|
+
if (key === '__untypedClient') {
|
|
22
|
+
return client;
|
|
23
|
+
}
|
|
24
|
+
return core.createRecursiveProxy(({ path , args })=>{
|
|
25
|
+
const pathCopy = [
|
|
26
|
+
key,
|
|
27
|
+
...path
|
|
28
|
+
];
|
|
29
|
+
const procedureType = clientCallTypeToProcedureType(pathCopy.pop());
|
|
30
|
+
const fullPath = pathCopy.join('.');
|
|
31
|
+
return client[procedureType](fullPath, ...args);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function createTRPCClient(opts) {
|
|
36
|
+
const client = new TRPCUntypedClient.TRPCUntypedClient(opts);
|
|
37
|
+
const proxy = createTRPCClientProxy(client);
|
|
38
|
+
return proxy;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Get an untyped client from a proxy client
|
|
42
|
+
* @internal
|
|
43
|
+
*/ function getUntypedClient(client) {
|
|
44
|
+
return client.__untypedClient;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
exports.clientCallTypeToProcedureType = clientCallTypeToProcedureType;
|
|
48
|
+
exports.createTRPCClient = createTRPCClient;
|
|
49
|
+
exports.createTRPCClientProxy = createTRPCClientProxy;
|
|
50
|
+
exports.getUntypedClient = getUntypedClient;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createFlatProxy, createRecursiveProxy } from '@trpc/core';
|
|
2
|
+
import { TRPCUntypedClient } from './internals/TRPCUntypedClient.mjs';
|
|
3
|
+
|
|
4
|
+
const clientCallTypeMap = {
|
|
5
|
+
query: 'query',
|
|
6
|
+
mutate: 'mutation',
|
|
7
|
+
subscribe: 'subscription'
|
|
8
|
+
};
|
|
9
|
+
/** @internal */ const clientCallTypeToProcedureType = (clientCallType)=>{
|
|
10
|
+
return clientCallTypeMap[clientCallType];
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/ function createTRPCClientProxy(client) {
|
|
15
|
+
return createFlatProxy((key)=>{
|
|
16
|
+
if (client.hasOwnProperty(key)) {
|
|
17
|
+
return client[key];
|
|
18
|
+
}
|
|
19
|
+
if (key === '__untypedClient') {
|
|
20
|
+
return client;
|
|
21
|
+
}
|
|
22
|
+
return createRecursiveProxy(({ path , args })=>{
|
|
23
|
+
const pathCopy = [
|
|
24
|
+
key,
|
|
25
|
+
...path
|
|
26
|
+
];
|
|
27
|
+
const procedureType = clientCallTypeToProcedureType(pathCopy.pop());
|
|
28
|
+
const fullPath = pathCopy.join('.');
|
|
29
|
+
return client[procedureType](fullPath, ...args);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
function createTRPCClient(opts) {
|
|
34
|
+
const client = new TRPCUntypedClient(opts);
|
|
35
|
+
const proxy = createTRPCClientProxy(client);
|
|
36
|
+
return proxy;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get an untyped client from a proxy client
|
|
40
|
+
* @internal
|
|
41
|
+
*/ function getUntypedClient(client) {
|
|
42
|
+
return client.__untypedClient;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { clientCallTypeToProcedureType, createTRPCClient, createTRPCClientProxy, getUntypedClient };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var TRPCUntypedClient = require('./internals/TRPCUntypedClient.js');
|
|
4
|
+
|
|
5
|
+
function createTRPCUntypedClient(opts) {
|
|
6
|
+
return new TRPCUntypedClient.TRPCUntypedClient(opts);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
exports.TRPCUntypedClient = TRPCUntypedClient.TRPCUntypedClient;
|
|
10
|
+
exports.createTRPCUntypedClient = createTRPCUntypedClient;
|
package/dist/getFetch.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use strict';
|
|
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
|
+
exports.getFetch = getFetch;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const isFunction = (fn)=>typeof fn === 'function';
|
|
2
|
+
function getFetch(customFetchImpl) {
|
|
3
|
+
if (customFetchImpl) {
|
|
4
|
+
return customFetchImpl;
|
|
5
|
+
}
|
|
6
|
+
if (typeof window !== 'undefined' && isFunction(window.fetch)) {
|
|
7
|
+
return window.fetch;
|
|
8
|
+
}
|
|
9
|
+
if (typeof globalThis !== 'undefined' && isFunction(globalThis.fetch)) {
|
|
10
|
+
return globalThis.fetch;
|
|
11
|
+
}
|
|
12
|
+
throw new Error('No fetch implementation found');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { getFetch };
|
package/dist/index.js
CHANGED
|
@@ -1,370 +1,35 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
26
|
-
return chain$.pipe(core.share());
|
|
27
|
-
}
|
|
28
|
-
requestAsPromise(opts) {
|
|
29
|
-
const req$ = this.$request(opts);
|
|
30
|
-
const { promise , abort } = core.observableToPromise(req$);
|
|
31
|
-
const abortablePromise = new Promise((resolve, reject)=>{
|
|
32
|
-
opts.signal?.addEventListener('abort', abort);
|
|
33
|
-
promise.then((envelope)=>{
|
|
34
|
-
resolve(envelope.result.data);
|
|
35
|
-
}).catch((err)=>{
|
|
36
|
-
reject(TRPCClientError.TRPCClientError.from(err));
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
return abortablePromise;
|
|
40
|
-
}
|
|
41
|
-
query(path, input, opts) {
|
|
42
|
-
return this.requestAsPromise({
|
|
43
|
-
type: 'query',
|
|
44
|
-
path,
|
|
45
|
-
input,
|
|
46
|
-
context: opts?.context,
|
|
47
|
-
signal: opts?.signal
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
mutation(path, input, opts) {
|
|
51
|
-
return this.requestAsPromise({
|
|
52
|
-
type: 'mutation',
|
|
53
|
-
path,
|
|
54
|
-
input,
|
|
55
|
-
context: opts?.context,
|
|
56
|
-
signal: opts?.signal
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
subscription(path, input, opts) {
|
|
60
|
-
const observable$ = this.$request({
|
|
61
|
-
type: 'subscription',
|
|
62
|
-
path,
|
|
63
|
-
input,
|
|
64
|
-
context: opts?.context
|
|
65
|
-
});
|
|
66
|
-
return observable$.subscribe({
|
|
67
|
-
next (envelope) {
|
|
68
|
-
if (envelope.result.type === 'started') {
|
|
69
|
-
opts.onStarted?.();
|
|
70
|
-
} else if (envelope.result.type === 'stopped') {
|
|
71
|
-
opts.onStopped?.();
|
|
72
|
-
} else {
|
|
73
|
-
opts.onData?.(envelope.result.data);
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
error (err) {
|
|
77
|
-
opts.onError?.(err);
|
|
78
|
-
},
|
|
79
|
-
complete () {
|
|
80
|
-
opts.onComplete?.();
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
constructor(opts){
|
|
85
|
-
this.requestId = 0;
|
|
86
|
-
const combinedTransformer = (()=>{
|
|
87
|
-
const transformer = opts.transformer;
|
|
88
|
-
if (!transformer) {
|
|
89
|
-
return {
|
|
90
|
-
input: {
|
|
91
|
-
serialize: (data)=>data,
|
|
92
|
-
deserialize: (data)=>data
|
|
93
|
-
},
|
|
94
|
-
output: {
|
|
95
|
-
serialize: (data)=>data,
|
|
96
|
-
deserialize: (data)=>data
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
if ('input' in transformer) {
|
|
101
|
-
return opts.transformer;
|
|
102
|
-
}
|
|
103
|
-
return {
|
|
104
|
-
input: transformer,
|
|
105
|
-
output: transformer
|
|
106
|
-
};
|
|
107
|
-
})();
|
|
108
|
-
this.runtime = {
|
|
109
|
-
transformer: {
|
|
110
|
-
serialize: (data)=>combinedTransformer.input.serialize(data),
|
|
111
|
-
deserialize: (data)=>combinedTransformer.output.deserialize(data)
|
|
112
|
-
},
|
|
113
|
-
combinedTransformer
|
|
114
|
-
};
|
|
115
|
-
// Initialize the links
|
|
116
|
-
this.links = opts.links.map((link)=>link(this.runtime));
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function createTRPCUntypedClient(opts) {
|
|
121
|
-
return new TRPCUntypedClient(opts);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const clientCallTypeMap = {
|
|
125
|
-
query: 'query',
|
|
126
|
-
mutate: 'mutation',
|
|
127
|
-
subscribe: 'subscription'
|
|
128
|
-
};
|
|
129
|
-
/** @internal */ const clientCallTypeToProcedureType = (clientCallType)=>{
|
|
130
|
-
return clientCallTypeMap[clientCallType];
|
|
131
|
-
};
|
|
132
|
-
/**
|
|
133
|
-
* @internal
|
|
134
|
-
*/ function createTRPCClientProxy(client) {
|
|
135
|
-
return core.createFlatProxy((key)=>{
|
|
136
|
-
if (client.hasOwnProperty(key)) {
|
|
137
|
-
return client[key];
|
|
138
|
-
}
|
|
139
|
-
if (key === '__untypedClient') {
|
|
140
|
-
return client;
|
|
141
|
-
}
|
|
142
|
-
return core.createRecursiveProxy(({ path , args })=>{
|
|
143
|
-
const pathCopy = [
|
|
144
|
-
key,
|
|
145
|
-
...path
|
|
146
|
-
];
|
|
147
|
-
const procedureType = clientCallTypeToProcedureType(pathCopy.pop());
|
|
148
|
-
const fullPath = pathCopy.join('.');
|
|
149
|
-
return client[procedureType](fullPath, ...args);
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
function createTRPCClient(opts) {
|
|
154
|
-
const client = new TRPCUntypedClient(opts);
|
|
155
|
-
const proxy = createTRPCClientProxy(client);
|
|
156
|
-
return proxy;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Get an untyped client from a proxy client
|
|
160
|
-
* @internal
|
|
161
|
-
*/ function getUntypedClient(client) {
|
|
162
|
-
return client.__untypedClient;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function getTextDecoder(customTextDecoder) {
|
|
166
|
-
if (customTextDecoder) {
|
|
167
|
-
return customTextDecoder;
|
|
168
|
-
}
|
|
169
|
-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
|
170
|
-
if (typeof window !== 'undefined' && window.TextDecoder) {
|
|
171
|
-
return new window.TextDecoder();
|
|
172
|
-
}
|
|
173
|
-
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
|
174
|
-
if (typeof globalThis !== 'undefined' && globalThis.TextDecoder) {
|
|
175
|
-
return new globalThis.TextDecoder();
|
|
176
|
-
}
|
|
177
|
-
throw new Error('No TextDecoder implementation found');
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// Stream parsing adapted from https://www.loginradius.com/blog/engineering/guest-post/http-streaming-with-nodejs-and-fetch-api/
|
|
181
|
-
/**
|
|
182
|
-
* @internal
|
|
183
|
-
* @description Take a stream of bytes and call `onLine` with
|
|
184
|
-
* a JSON object for each line in the stream. Expected stream
|
|
185
|
-
* format is:
|
|
186
|
-
* ```json
|
|
187
|
-
* {"1": {...}
|
|
188
|
-
* ,"0": {...}
|
|
189
|
-
* }
|
|
190
|
-
* ```
|
|
191
|
-
*/ async function parseJSONStream(opts) {
|
|
192
|
-
const parse = opts.parse ?? JSON.parse;
|
|
193
|
-
const onLine = (line)=>{
|
|
194
|
-
if (opts.signal?.aborted) return;
|
|
195
|
-
if (!line || line === '}') {
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* At this point, `line` can be one of two things:
|
|
200
|
-
* - The first line of the stream `{"2":{...}`
|
|
201
|
-
* - A line in the middle of the stream `,"2":{...}`
|
|
202
|
-
*/ const indexOfColon = line.indexOf(':');
|
|
203
|
-
const indexAsStr = line.substring(2, indexOfColon - 1);
|
|
204
|
-
const text = line.substring(indexOfColon + 1);
|
|
205
|
-
opts.onSingle(Number(indexAsStr), parse(text));
|
|
206
|
-
};
|
|
207
|
-
await readLines(opts.readableStream, onLine, opts.textDecoder);
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Handle transforming a stream of bytes into lines of text.
|
|
211
|
-
* To avoid using AsyncIterators / AsyncGenerators,
|
|
212
|
-
* we use a callback for each line.
|
|
213
|
-
*
|
|
214
|
-
* @param readableStream can be a NodeJS stream or a WebAPI stream
|
|
215
|
-
* @param onLine will be called for every line ('\n' delimited) in the stream
|
|
216
|
-
*/ async function readLines(readableStream, onLine, textDecoder) {
|
|
217
|
-
let partOfLine = '';
|
|
218
|
-
const onChunk = (chunk)=>{
|
|
219
|
-
const chunkText = textDecoder.decode(chunk);
|
|
220
|
-
const chunkLines = chunkText.split('\n');
|
|
221
|
-
if (chunkLines.length === 1) {
|
|
222
|
-
partOfLine += chunkLines[0];
|
|
223
|
-
} else if (chunkLines.length > 1) {
|
|
224
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- length checked on line above
|
|
225
|
-
onLine(partOfLine + chunkLines[0]);
|
|
226
|
-
for(let i = 1; i < chunkLines.length - 1; i++){
|
|
227
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- length checked on line above
|
|
228
|
-
onLine(chunkLines[i]);
|
|
229
|
-
}
|
|
230
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion -- length doesn't change, so is necessarily > 1
|
|
231
|
-
partOfLine = chunkLines[chunkLines.length - 1];
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
// we handle 2 different types of streams, this if where we figure out which one we have
|
|
235
|
-
if ('getReader' in readableStream) {
|
|
236
|
-
await readStandardChunks(readableStream, onChunk);
|
|
237
|
-
} else {
|
|
238
|
-
await readNodeChunks(readableStream, onChunk);
|
|
239
|
-
}
|
|
240
|
-
onLine(partOfLine);
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Handle NodeJS stream
|
|
244
|
-
*/ function readNodeChunks(stream, onChunk) {
|
|
245
|
-
return new Promise((resolve)=>{
|
|
246
|
-
stream.on('data', onChunk);
|
|
247
|
-
stream.on('end', resolve);
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Handle WebAPI stream
|
|
252
|
-
*/ async function readStandardChunks(stream, onChunk) {
|
|
253
|
-
const reader = stream.getReader();
|
|
254
|
-
let readResult = await reader.read();
|
|
255
|
-
while(!readResult.done){
|
|
256
|
-
onChunk(readResult.value);
|
|
257
|
-
readResult = await reader.read();
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
const streamingJsonHttpRequester = (opts, onSingle)=>{
|
|
261
|
-
const ac = opts.AbortController ? new opts.AbortController() : null;
|
|
262
|
-
const responsePromise = httpUtils.fetchHTTPResponse({
|
|
263
|
-
...opts,
|
|
264
|
-
contentTypeHeader: 'application/json',
|
|
265
|
-
batchModeHeader: 'stream',
|
|
266
|
-
getUrl: httpUtils.getUrl,
|
|
267
|
-
getBody: httpUtils.getBody
|
|
268
|
-
}, ac);
|
|
269
|
-
const cancel = ()=>ac?.abort();
|
|
270
|
-
const promise = responsePromise.then(async (res)=>{
|
|
271
|
-
if (!res.body) throw new Error('Received response without body');
|
|
272
|
-
const meta = {
|
|
273
|
-
response: res
|
|
274
|
-
};
|
|
275
|
-
return parseJSONStream({
|
|
276
|
-
readableStream: res.body,
|
|
277
|
-
onSingle,
|
|
278
|
-
parse: (string)=>({
|
|
279
|
-
json: JSON.parse(string),
|
|
280
|
-
meta
|
|
281
|
-
}),
|
|
282
|
-
signal: ac?.signal,
|
|
283
|
-
textDecoder: opts.textDecoder
|
|
284
|
-
});
|
|
285
|
-
});
|
|
286
|
-
return {
|
|
287
|
-
cancel,
|
|
288
|
-
promise
|
|
289
|
-
};
|
|
290
|
-
};
|
|
291
|
-
|
|
292
|
-
const streamRequester = (requesterOpts)=>{
|
|
293
|
-
const textDecoder = getTextDecoder(requesterOpts.opts.textDecoder);
|
|
294
|
-
return (batchOps, unitResolver)=>{
|
|
295
|
-
const path = batchOps.map((op)=>op.path).join(',');
|
|
296
|
-
const inputs = batchOps.map((op)=>op.input);
|
|
297
|
-
const { cancel , promise } = streamingJsonHttpRequester({
|
|
298
|
-
...requesterOpts,
|
|
299
|
-
textDecoder,
|
|
300
|
-
path,
|
|
301
|
-
inputs,
|
|
302
|
-
headers () {
|
|
303
|
-
if (!requesterOpts.opts.headers) {
|
|
304
|
-
return {};
|
|
305
|
-
}
|
|
306
|
-
if (typeof requesterOpts.opts.headers === 'function') {
|
|
307
|
-
return requesterOpts.opts.headers({
|
|
308
|
-
opList: batchOps
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
return requesterOpts.opts.headers;
|
|
312
|
-
}
|
|
313
|
-
}, (index, res)=>{
|
|
314
|
-
unitResolver(index, res);
|
|
315
|
-
});
|
|
316
|
-
return {
|
|
317
|
-
/**
|
|
318
|
-
* return an empty array because the batchLoader expects an array of results
|
|
319
|
-
* but we've already called the `unitResolver` for each of them, there's
|
|
320
|
-
* nothing left to do here.
|
|
321
|
-
*/ promise: promise.then(()=>[]),
|
|
322
|
-
cancel
|
|
323
|
-
};
|
|
324
|
-
};
|
|
325
|
-
};
|
|
326
|
-
const unstable_httpBatchStreamLink = links_httpBatchLink.createHTTPBatchLink(streamRequester);
|
|
327
|
-
|
|
328
|
-
const formDataRequester = (opts)=>{
|
|
329
|
-
if (opts.type !== 'mutation') {
|
|
330
|
-
// TODO(?) handle formdata queries
|
|
331
|
-
throw new Error('We only handle mutations with formdata');
|
|
332
|
-
}
|
|
333
|
-
return httpUtils.httpRequest({
|
|
334
|
-
...opts,
|
|
335
|
-
getUrl () {
|
|
336
|
-
return `${opts.url}/${opts.path}`;
|
|
337
|
-
},
|
|
338
|
-
getBody (opts) {
|
|
339
|
-
if (!('input' in opts)) {
|
|
340
|
-
return undefined;
|
|
341
|
-
}
|
|
342
|
-
if (!(opts.input instanceof FormData)) {
|
|
343
|
-
throw new Error('Input is not FormData');
|
|
344
|
-
}
|
|
345
|
-
return opts.input;
|
|
346
|
-
}
|
|
347
|
-
});
|
|
348
|
-
};
|
|
349
|
-
const experimental_formDataLink = links_httpLink.httpLinkFactory({
|
|
350
|
-
requester: formDataRequester
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
exports.splitLink = links_splitLink.splitLink;
|
|
3
|
+
var createTRPCUntypedClient = require('./createTRPCUntypedClient.js');
|
|
4
|
+
var createTRPCClient = require('./createTRPCClient.js');
|
|
5
|
+
var getFetch = require('./getFetch.js');
|
|
6
|
+
var TRPCClientError = require('./TRPCClientError.js');
|
|
7
|
+
var httpBatchLink = require('./links/httpBatchLink.js');
|
|
8
|
+
var httpBatchStreamLink = require('./links/httpBatchStreamLink.js');
|
|
9
|
+
var httpLink = require('./links/httpLink.js');
|
|
10
|
+
var loggerLink = require('./links/loggerLink.js');
|
|
11
|
+
var splitLink = require('./links/splitLink.js');
|
|
12
|
+
var wsLink = require('./links/wsLink.js');
|
|
13
|
+
var httpFormDataLink = require('./links/httpFormDataLink.js');
|
|
14
|
+
var TRPCUntypedClient = require('./internals/TRPCUntypedClient.js');
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
exports.createTRPCUntypedClient = createTRPCUntypedClient.createTRPCUntypedClient;
|
|
19
|
+
exports.clientCallTypeToProcedureType = createTRPCClient.clientCallTypeToProcedureType;
|
|
20
|
+
exports.createTRPCClient = createTRPCClient.createTRPCClient;
|
|
21
|
+
exports.createTRPCClientProxy = createTRPCClient.createTRPCClientProxy;
|
|
22
|
+
exports.createTRPCProxyClient = createTRPCClient.createTRPCClient;
|
|
23
|
+
exports.getUntypedClient = createTRPCClient.getUntypedClient;
|
|
24
|
+
exports.getFetch = getFetch.getFetch;
|
|
354
25
|
exports.TRPCClientError = TRPCClientError.TRPCClientError;
|
|
355
|
-
exports.
|
|
356
|
-
exports.
|
|
357
|
-
exports.httpLink =
|
|
358
|
-
exports.httpLinkFactory =
|
|
359
|
-
exports.loggerLink =
|
|
360
|
-
exports.
|
|
361
|
-
exports.
|
|
362
|
-
exports.
|
|
363
|
-
exports.
|
|
364
|
-
exports.
|
|
365
|
-
exports.createTRPCClientProxy = createTRPCClientProxy;
|
|
366
|
-
exports.createTRPCProxyClient = createTRPCClient;
|
|
367
|
-
exports.createTRPCUntypedClient = createTRPCUntypedClient;
|
|
368
|
-
exports.experimental_formDataLink = experimental_formDataLink;
|
|
369
|
-
exports.getUntypedClient = getUntypedClient;
|
|
370
|
-
exports.unstable_httpBatchStreamLink = unstable_httpBatchStreamLink;
|
|
26
|
+
exports.httpBatchLink = httpBatchLink.httpBatchLink;
|
|
27
|
+
exports.unstable_httpBatchStreamLink = httpBatchStreamLink.unstable_httpBatchStreamLink;
|
|
28
|
+
exports.httpLink = httpLink.httpLink;
|
|
29
|
+
exports.httpLinkFactory = httpLink.httpLinkFactory;
|
|
30
|
+
exports.loggerLink = loggerLink.loggerLink;
|
|
31
|
+
exports.splitLink = splitLink.splitLink;
|
|
32
|
+
exports.createWSClient = wsLink.createWSClient;
|
|
33
|
+
exports.wsLink = wsLink.wsLink;
|
|
34
|
+
exports.experimental_formDataLink = httpFormDataLink.experimental_formDataLink;
|
|
35
|
+
exports.TRPCUntypedClient = TRPCUntypedClient.TRPCUntypedClient;
|