@trpc/server 11.0.0-rc.373 → 11.0.0-rc.377

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 (36) hide show
  1. package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts +7 -1
  2. package/dist/adapters/next-app-dir/nextAppDirCaller.d.ts.map +1 -1
  3. package/dist/adapters/next-app-dir/nextAppDirCaller.js +6 -3
  4. package/dist/adapters/next-app-dir/nextAppDirCaller.mjs +6 -3
  5. package/dist/bundle-analysis.json +118 -99
  6. package/dist/unstable-core-do-not-import/clientish/serialize.d.ts +1 -1
  7. package/dist/unstable-core-do-not-import/clientish/serialize.d.ts.map +1 -1
  8. package/dist/unstable-core-do-not-import/http/resolveResponse.d.ts.map +1 -1
  9. package/dist/unstable-core-do-not-import/http/resolveResponse.js +79 -52
  10. package/dist/unstable-core-do-not-import/http/resolveResponse.mjs +78 -51
  11. package/dist/unstable-core-do-not-import/initTRPC.d.ts.map +1 -1
  12. package/dist/unstable-core-do-not-import/initTRPC.js +2 -1
  13. package/dist/unstable-core-do-not-import/initTRPC.mjs +2 -1
  14. package/dist/unstable-core-do-not-import/rootConfig.d.ts +6 -0
  15. package/dist/unstable-core-do-not-import/rootConfig.d.ts.map +1 -1
  16. package/dist/unstable-core-do-not-import/stream/stream.d.ts +94 -0
  17. package/dist/unstable-core-do-not-import/stream/stream.d.ts.map +1 -0
  18. package/dist/unstable-core-do-not-import/stream/stream.js +466 -0
  19. package/dist/unstable-core-do-not-import/stream/stream.mjs +462 -0
  20. package/dist/unstable-core-do-not-import/utils.d.ts +2 -1
  21. package/dist/unstable-core-do-not-import/utils.d.ts.map +1 -1
  22. package/dist/unstable-core-do-not-import/utils.js +4 -0
  23. package/dist/unstable-core-do-not-import/utils.mjs +4 -1
  24. package/dist/unstable-core-do-not-import.d.ts +1 -0
  25. package/dist/unstable-core-do-not-import.d.ts.map +1 -1
  26. package/dist/unstable-core-do-not-import.js +5 -0
  27. package/dist/unstable-core-do-not-import.mjs +2 -1
  28. package/package.json +2 -2
  29. package/src/adapters/next-app-dir/nextAppDirCaller.ts +10 -4
  30. package/src/unstable-core-do-not-import/clientish/serialize.ts +1 -0
  31. package/src/unstable-core-do-not-import/http/resolveResponse.ts +83 -52
  32. package/src/unstable-core-do-not-import/initTRPC.ts +1 -0
  33. package/src/unstable-core-do-not-import/rootConfig.ts +7 -0
  34. package/src/unstable-core-do-not-import/stream/stream.ts +580 -0
  35. package/src/unstable-core-do-not-import/utils.ts +7 -1
  36. package/src/unstable-core-do-not-import.ts +1 -0
@@ -3,8 +3,9 @@
3
3
  var getErrorShape = require('../error/getErrorShape.js');
4
4
  var TRPCError = require('../error/TRPCError.js');
5
5
  var router = require('../router.js');
6
+ var stream = require('../stream/stream.js');
6
7
  var transformer = require('../transformer.js');
7
- var batchStreamFormatter = require('./batchStreamFormatter.js');
8
+ var utils = require('../utils.js');
8
9
  var contentType = require('./contentType.js');
9
10
  var getHTTPStatusCode = require('./getHTTPStatusCode.js');
10
11
 
@@ -13,14 +14,8 @@ const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
13
14
  POST: 'mutation'
14
15
  };
15
16
  function initResponse(initOpts) {
16
- const { ctx , info , type , responseMeta , untransformedJSON , errors =[] , } = initOpts;
17
+ const { ctx , info , type , responseMeta , untransformedJSON , errors =[] , headers , } = initOpts;
17
18
  let status = untransformedJSON ? getHTTPStatusCode.getHTTPStatusCode(untransformedJSON) : 200;
18
- const headers = new Headers([
19
- [
20
- 'Content-Type',
21
- 'application/json'
22
- ]
23
- ]);
24
19
  const eagerGeneration = !untransformedJSON;
25
20
  const data = eagerGeneration ? [] : Array.isArray(untransformedJSON) ? untransformedJSON : [
26
21
  untransformedJSON
@@ -57,8 +52,7 @@ function initResponse(initOpts) {
57
52
  status = meta.status;
58
53
  }
59
54
  return {
60
- status,
61
- headers
55
+ status
62
56
  };
63
57
  }
64
58
  function caughtErrorToData(cause, errorOpts) {
@@ -92,6 +86,12 @@ function caughtErrorToData(cause, errorOpts) {
92
86
  }
93
87
  async function resolveResponse(opts) {
94
88
  const { router: router$1 , req } = opts;
89
+ const headers = new Headers([
90
+ [
91
+ 'vary',
92
+ 'trpc-accept'
93
+ ]
94
+ ]);
95
95
  const url = new URL(req.url);
96
96
  if (req.method === 'HEAD') {
97
97
  // can be used for lambda warmup
@@ -104,7 +104,8 @@ async function resolveResponse(opts) {
104
104
  const type = HTTP_METHOD_PROCEDURE_TYPE_MAP[req.method] ?? 'unknown';
105
105
  let ctx = undefined;
106
106
  let info = undefined;
107
- const isStreamCall = req.headers.get('trpc-batch-mode') === 'stream';
107
+ const isStreamCall = req.headers.get('trpc-accept') === 'application/jsonl';
108
+ const experimentalIterablesAndDeferreds = router$1._def._config.experimental?.iterablesAndDeferreds ?? false;
108
109
  try {
109
110
  info = contentType.getRequestInfo({
110
111
  req,
@@ -142,6 +143,20 @@ async function resolveResponse(opts) {
142
143
  type,
143
144
  allowMethodOverride
144
145
  });
146
+ if ((!isStreamCall || !experimentalIterablesAndDeferreds) && utils.isObject(data) && (Symbol.asyncIterator in data || Object.values(data).some(stream.isPromise))) {
147
+ if (!isStreamCall) {
148
+ throw new TRPCError.TRPCError({
149
+ code: 'UNSUPPORTED_MEDIA_TYPE',
150
+ message: 'Cannot return async iterable or nested promises in non-streaming response'
151
+ });
152
+ }
153
+ if (!experimentalIterablesAndDeferreds) {
154
+ throw new TRPCError.TRPCError({
155
+ code: 'INTERNAL_SERVER_ERROR',
156
+ message: 'Missing experimental flag "iterablesAndDeferreds"'
157
+ });
158
+ }
159
+ }
145
160
  return {
146
161
  result: {
147
162
  data
@@ -172,6 +187,7 @@ async function resolveResponse(opts) {
172
187
  }
173
188
  });
174
189
  if (!isStreamCall) {
190
+ headers.set('content-type', 'application/json');
175
191
  /**
176
192
  * Non-streaming response:
177
193
  * - await all responses in parallel, blocking on the slowest one
@@ -187,7 +203,8 @@ async function resolveResponse(opts) {
187
203
  type,
188
204
  responseMeta: opts.responseMeta,
189
205
  untransformedJSON,
190
- errors: errors1
206
+ errors: errors1,
207
+ headers
191
208
  });
192
209
  // return body stuff
193
210
  const result = info.isBatchCall ? untransformedJSON : untransformedJSON[0];
@@ -195,9 +212,11 @@ async function resolveResponse(opts) {
195
212
  const body = JSON.stringify(transformedJSON);
196
213
  return new Response(body, {
197
214
  status: headResponse.status,
198
- headers: headResponse.headers
215
+ headers
199
216
  });
200
217
  }
218
+ headers.set('content-type', 'application/json');
219
+ headers.set('transfer-encoding', 'chunked');
201
220
  /**
202
221
  * Streaming response:
203
222
  * - block on none, call `onChunk` as soon as each response is ready
@@ -208,46 +227,53 @@ async function resolveResponse(opts) {
208
227
  info,
209
228
  type,
210
229
  responseMeta: opts.responseMeta,
211
- errors: []
230
+ errors: [],
231
+ headers
212
232
  });
213
- const encoder = new TextEncoderStream();
214
- const stream = encoder.readable;
215
- const controller = encoder.writable.getWriter();
216
- async function exec() {
217
- const indexedPromises = new Map(promises.map((promise, index)=>[
218
- index,
219
- promise.then((r)=>[
220
- index,
221
- r
222
- ])
223
- ]));
224
- const formatter = batchStreamFormatter.getBatchStreamFormatter();
225
- while(indexedPromises.size > 0){
226
- const [index, untransformedJSON] = await Promise.race(indexedPromises.values());
227
- indexedPromises.delete(index);
228
- try {
229
- const transformedJSON = transformer.transformTRPCResponse(router$1._def._config, untransformedJSON);
230
- const body = JSON.stringify(transformedJSON);
231
- await controller.write(formatter(index, body));
232
- } catch (cause) {
233
- const call = info.calls[index];
234
- const input = call.result();
235
- const { body: body1 } = caughtErrorToData(cause, {
236
- opts,
237
- ctx,
238
- type,
239
- path: call.path,
240
- input
241
- });
242
- await controller.write(formatter(index, body1));
233
+ const stream$1 = stream.jsonlStreamProducer({
234
+ /**
235
+ * Example structure for `maxDepth: 4`:
236
+ * {
237
+ * // 1
238
+ * 0: {
239
+ * // 2
240
+ * result: {
241
+ * // 3
242
+ * data: // 4
243
+ * }
244
+ * }
245
+ * }
246
+ */ maxDepth: experimentalIterablesAndDeferreds ? 4 : 3,
247
+ data: promises.map(async (it)=>{
248
+ const response = await it;
249
+ if ('result' in response) {
250
+ /**
251
+ * Not very pretty, but we need to wrap nested data in promises
252
+ * Our stream producer will only resolve top-level async values or async values that are directly nested in another async value
253
+ */ return {
254
+ ...response,
255
+ result: Promise.resolve({
256
+ ...response.result,
257
+ data: Promise.resolve(response.result.data)
258
+ })
259
+ };
243
260
  }
261
+ return response;
262
+ }),
263
+ serialize: opts.router._def._config.transformer.output.serialize,
264
+ onError: (cause)=>{
265
+ opts.onError?.({
266
+ error: TRPCError.getTRPCErrorFromUnknown(cause),
267
+ path: undefined,
268
+ input: undefined,
269
+ ctx,
270
+ type,
271
+ req: opts.req
272
+ });
244
273
  }
245
- await controller.write(formatter.end());
246
- await controller.close();
247
- }
248
- exec().catch((err)=>controller.abort(err));
249
- return new Response(stream, {
250
- headers: headResponse1.headers,
274
+ });
275
+ return new Response(stream$1, {
276
+ headers,
251
277
  status: headResponse1.status
252
278
  });
253
279
  } catch (cause) {
@@ -271,11 +297,12 @@ async function resolveResponse(opts) {
271
297
  untransformedJSON: untransformedJSON1,
272
298
  errors: [
273
299
  error
274
- ]
300
+ ],
301
+ headers
275
302
  });
276
303
  return new Response(body1, {
277
304
  status: headResponse2.status,
278
- headers: headResponse2.headers
305
+ headers
279
306
  });
280
307
  }
281
308
  }
@@ -1,8 +1,9 @@
1
1
  import { getErrorShape } from '../error/getErrorShape.mjs';
2
2
  import { TRPCError, getTRPCErrorFromUnknown } from '../error/TRPCError.mjs';
3
3
  import { callProcedure } from '../router.mjs';
4
+ import { isPromise, jsonlStreamProducer } from '../stream/stream.mjs';
4
5
  import { transformTRPCResponse } from '../transformer.mjs';
5
- import { getBatchStreamFormatter } from './batchStreamFormatter.mjs';
6
+ import { isObject } from '../utils.mjs';
6
7
  import { getRequestInfo } from './contentType.mjs';
7
8
  import { getHTTPStatusCode } from './getHTTPStatusCode.mjs';
8
9
 
@@ -11,14 +12,8 @@ const HTTP_METHOD_PROCEDURE_TYPE_MAP = {
11
12
  POST: 'mutation'
12
13
  };
13
14
  function initResponse(initOpts) {
14
- const { ctx , info , type , responseMeta , untransformedJSON , errors =[] , } = initOpts;
15
+ const { ctx , info , type , responseMeta , untransformedJSON , errors =[] , headers , } = initOpts;
15
16
  let status = untransformedJSON ? getHTTPStatusCode(untransformedJSON) : 200;
16
- const headers = new Headers([
17
- [
18
- 'Content-Type',
19
- 'application/json'
20
- ]
21
- ]);
22
17
  const eagerGeneration = !untransformedJSON;
23
18
  const data = eagerGeneration ? [] : Array.isArray(untransformedJSON) ? untransformedJSON : [
24
19
  untransformedJSON
@@ -55,8 +50,7 @@ function initResponse(initOpts) {
55
50
  status = meta.status;
56
51
  }
57
52
  return {
58
- status,
59
- headers
53
+ status
60
54
  };
61
55
  }
62
56
  function caughtErrorToData(cause, errorOpts) {
@@ -90,6 +84,12 @@ function caughtErrorToData(cause, errorOpts) {
90
84
  }
91
85
  async function resolveResponse(opts) {
92
86
  const { router , req } = opts;
87
+ const headers = new Headers([
88
+ [
89
+ 'vary',
90
+ 'trpc-accept'
91
+ ]
92
+ ]);
93
93
  const url = new URL(req.url);
94
94
  if (req.method === 'HEAD') {
95
95
  // can be used for lambda warmup
@@ -102,7 +102,8 @@ async function resolveResponse(opts) {
102
102
  const type = HTTP_METHOD_PROCEDURE_TYPE_MAP[req.method] ?? 'unknown';
103
103
  let ctx = undefined;
104
104
  let info = undefined;
105
- const isStreamCall = req.headers.get('trpc-batch-mode') === 'stream';
105
+ const isStreamCall = req.headers.get('trpc-accept') === 'application/jsonl';
106
+ const experimentalIterablesAndDeferreds = router._def._config.experimental?.iterablesAndDeferreds ?? false;
106
107
  try {
107
108
  info = getRequestInfo({
108
109
  req,
@@ -140,6 +141,20 @@ async function resolveResponse(opts) {
140
141
  type,
141
142
  allowMethodOverride
142
143
  });
144
+ if ((!isStreamCall || !experimentalIterablesAndDeferreds) && isObject(data) && (Symbol.asyncIterator in data || Object.values(data).some(isPromise))) {
145
+ if (!isStreamCall) {
146
+ throw new TRPCError({
147
+ code: 'UNSUPPORTED_MEDIA_TYPE',
148
+ message: 'Cannot return async iterable or nested promises in non-streaming response'
149
+ });
150
+ }
151
+ if (!experimentalIterablesAndDeferreds) {
152
+ throw new TRPCError({
153
+ code: 'INTERNAL_SERVER_ERROR',
154
+ message: 'Missing experimental flag "iterablesAndDeferreds"'
155
+ });
156
+ }
157
+ }
143
158
  return {
144
159
  result: {
145
160
  data
@@ -170,6 +185,7 @@ async function resolveResponse(opts) {
170
185
  }
171
186
  });
172
187
  if (!isStreamCall) {
188
+ headers.set('content-type', 'application/json');
173
189
  /**
174
190
  * Non-streaming response:
175
191
  * - await all responses in parallel, blocking on the slowest one
@@ -185,7 +201,8 @@ async function resolveResponse(opts) {
185
201
  type,
186
202
  responseMeta: opts.responseMeta,
187
203
  untransformedJSON,
188
- errors: errors1
204
+ errors: errors1,
205
+ headers
189
206
  });
190
207
  // return body stuff
191
208
  const result = info.isBatchCall ? untransformedJSON : untransformedJSON[0];
@@ -193,9 +210,11 @@ async function resolveResponse(opts) {
193
210
  const body = JSON.stringify(transformedJSON);
194
211
  return new Response(body, {
195
212
  status: headResponse.status,
196
- headers: headResponse.headers
213
+ headers
197
214
  });
198
215
  }
216
+ headers.set('content-type', 'application/json');
217
+ headers.set('transfer-encoding', 'chunked');
199
218
  /**
200
219
  * Streaming response:
201
220
  * - block on none, call `onChunk` as soon as each response is ready
@@ -206,46 +225,53 @@ async function resolveResponse(opts) {
206
225
  info,
207
226
  type,
208
227
  responseMeta: opts.responseMeta,
209
- errors: []
228
+ errors: [],
229
+ headers
210
230
  });
211
- const encoder = new TextEncoderStream();
212
- const stream = encoder.readable;
213
- const controller = encoder.writable.getWriter();
214
- async function exec() {
215
- const indexedPromises = new Map(promises.map((promise, index)=>[
216
- index,
217
- promise.then((r)=>[
218
- index,
219
- r
220
- ])
221
- ]));
222
- const formatter = getBatchStreamFormatter();
223
- while(indexedPromises.size > 0){
224
- const [index, untransformedJSON] = await Promise.race(indexedPromises.values());
225
- indexedPromises.delete(index);
226
- try {
227
- const transformedJSON = transformTRPCResponse(router._def._config, untransformedJSON);
228
- const body = JSON.stringify(transformedJSON);
229
- await controller.write(formatter(index, body));
230
- } catch (cause) {
231
- const call = info.calls[index];
232
- const input = call.result();
233
- const { body: body1 } = caughtErrorToData(cause, {
234
- opts,
235
- ctx,
236
- type,
237
- path: call.path,
238
- input
239
- });
240
- await controller.write(formatter(index, body1));
231
+ const stream = jsonlStreamProducer({
232
+ /**
233
+ * Example structure for `maxDepth: 4`:
234
+ * {
235
+ * // 1
236
+ * 0: {
237
+ * // 2
238
+ * result: {
239
+ * // 3
240
+ * data: // 4
241
+ * }
242
+ * }
243
+ * }
244
+ */ maxDepth: experimentalIterablesAndDeferreds ? 4 : 3,
245
+ data: promises.map(async (it)=>{
246
+ const response = await it;
247
+ if ('result' in response) {
248
+ /**
249
+ * Not very pretty, but we need to wrap nested data in promises
250
+ * Our stream producer will only resolve top-level async values or async values that are directly nested in another async value
251
+ */ return {
252
+ ...response,
253
+ result: Promise.resolve({
254
+ ...response.result,
255
+ data: Promise.resolve(response.result.data)
256
+ })
257
+ };
241
258
  }
259
+ return response;
260
+ }),
261
+ serialize: opts.router._def._config.transformer.output.serialize,
262
+ onError: (cause)=>{
263
+ opts.onError?.({
264
+ error: getTRPCErrorFromUnknown(cause),
265
+ path: undefined,
266
+ input: undefined,
267
+ ctx,
268
+ type,
269
+ req: opts.req
270
+ });
242
271
  }
243
- await controller.write(formatter.end());
244
- await controller.close();
245
- }
246
- exec().catch((err)=>controller.abort(err));
272
+ });
247
273
  return new Response(stream, {
248
- headers: headResponse1.headers,
274
+ headers,
249
275
  status: headResponse1.status
250
276
  });
251
277
  } catch (cause) {
@@ -269,11 +295,12 @@ async function resolveResponse(opts) {
269
295
  untransformedJSON: untransformedJSON1,
270
296
  errors: [
271
297
  error
272
- ]
298
+ ],
299
+ headers
273
300
  });
274
301
  return new Response(body1, {
275
302
  status: headResponse2.status,
276
- headers: headResponse2.headers
303
+ headers
277
304
  });
278
305
  }
279
306
  }
@@ -1 +1 @@
1
- {"version":3,"file":"initTRPC.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/initTRPC.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAI3B,OAAO,EAAmB,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAGL,YAAY,EACb,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAE5D,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAErD,KAAK,wBAAwB,CAAC,KAAK,IAAI,KAAK,SAAS,cAAc,CACjE,GAAG,EACH,MAAM,MAAM,CACb,GACG,MAAM,GACN,iBAAiB,CAAC;AACtB,UAAU,oBAAoB,CAAC,QAAQ,SAAS,MAAM,EAAE,KAAK,SAAS,MAAM,CAC1E,SAAQ,OAAO,CACb,IAAI,CACF,UAAU,CAAC;IACT,GAAG,EAAE,QAAQ,CAAC;IACd,IAAI,EAAE,KAAK,CAAC;IACZ,UAAU,EAAE,GAAG,CAAC;IAChB,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC,EACF,QAAQ,GAAG,aAAa,CACzB,CACF;IACD;;;OAGG;IACH,WAAW,CAAC,EAAE,sBAAsB,CAAC;CACtC;AAED,KAAK,eAAe,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAEpE,cAAM,WAAW,CAAC,QAAQ,SAAS,MAAM,EAAE,KAAK,SAAS,MAAM;IAC7D;;;OAGG;IACH,OAAO,CAAC,WAAW,SAAS,MAAM,GAAG,eAAe;IAOpD;;;OAGG;IACH,IAAI,CAAC,QAAQ,SAAS,MAAM;IAI5B;;;OAGG;I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;kBACP,KAAK;wBACC,SAAS,SAAS,QAAQ,CAAC,gBAAgB,CAAC,GACpD,iBAAiB,GACjB,yBAAyB,QAAQ,CAAC,gBAAgB,CAAC,CAAC;yBAC3C,SAAS,SAAS,QAAQ,CAAC,aAAa,CAAC,GAAG,KAAK,GAAG,IAAI;;;CAiE1E;AAED;;;GAGG;AACH,eAAO,MAAM,QAAQ,6BAAoB,CAAC;AAC1C,YAAY,EAAE,WAAW,EAAE,CAAC"}
@@ -34,7 +34,8 @@ class TRPCBuilder {
34
34
  /**
35
35
  * These are just types, they can't be used at runtime
36
36
  * @internal
37
- */ $types: null
37
+ */ $types: null,
38
+ experimental: opts?.experimental ?? {}
38
39
  };
39
40
  {
40
41
  // Server check
@@ -32,7 +32,8 @@ class TRPCBuilder {
32
32
  /**
33
33
  * These are just types, they can't be used at runtime
34
34
  * @internal
35
- */ $types: null
35
+ */ $types: null,
36
+ experimental: opts?.experimental ?? {}
36
37
  };
37
38
  {
38
39
  // Server check
@@ -53,6 +53,12 @@ export interface RootConfig<TTypes extends RootTypes> {
53
53
  */
54
54
  isDev: boolean;
55
55
  defaultMeta?: TTypes['meta'] extends object ? TTypes['meta'] : never;
56
+ experimental?: {
57
+ /**
58
+ * Enable support for returning async iterables and returning deferred promises when using `httpBatchStreamLink`
59
+ */
60
+ iterablesAndDeferreds?: boolean;
61
+ };
56
62
  }
57
63
  /**
58
64
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"rootConfig.d.ts","sourceRoot":"","sources":["../../src/unstable-core-do-not-import/rootConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAC9E,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE3E;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,iBAAiB,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EAAE,GAAG,CAAC;IAChB,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC,CAAC;AAEH,KAAK,SAAS,CAAC,UAAU,SAAS,OAAO,EAAE,KAAK,IAAI,UAAU,SAAS,IAAI,GACvE,OAAO,CAAC,KAAK,CAAC,GACd,KAAK,CAAC;AAEV;;;GAGG;AACH,MAAM,MAAM,qBAAqB,CAC/B,QAAQ,EACR,SAAS,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,IACvC,SAAS,CACX,MAAM,SAAS,QAAQ,GAAG,IAAI,GAAG,KAAK,EACtC;IACE;;QAEI;IACJ,aAAa,EAAE,SAAS,CAAC;CAC1B,CACF,CAAC"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * A subset of the standard ReadableStream properties needed by tRPC internally.
3
+ * @see ReadableStream from lib.dom.d.ts
4
+ */
5
+ export type WebReadableStreamEsque = {
6
+ getReader: () => ReadableStreamDefaultReader<Uint8Array>;
7
+ };
8
+ export type NodeJSReadableStreamEsque = {
9
+ on(eventName: string | symbol, listener: (...args: any[]) => void): NodeJSReadableStreamEsque;
10
+ };
11
+ declare const CHUNK_VALUE_TYPE_PROMISE = 0;
12
+ type CHUNK_VALUE_TYPE_PROMISE = typeof CHUNK_VALUE_TYPE_PROMISE;
13
+ declare const CHUNK_VALUE_TYPE_ASYNC_ITERABLE = 1;
14
+ type CHUNK_VALUE_TYPE_ASYNC_ITERABLE = typeof CHUNK_VALUE_TYPE_ASYNC_ITERABLE;
15
+ declare const PROMISE_STATUS_FULFILLED = 0;
16
+ type PROMISE_STATUS_FULFILLED = typeof PROMISE_STATUS_FULFILLED;
17
+ declare const PROMISE_STATUS_REJECTED = 1;
18
+ type PROMISE_STATUS_REJECTED = typeof PROMISE_STATUS_REJECTED;
19
+ declare const ASYNC_ITERABLE_STATUS_DONE = 0;
20
+ type ASYNC_ITERABLE_STATUS_DONE = typeof ASYNC_ITERABLE_STATUS_DONE;
21
+ declare const ASYNC_ITERABLE_STATUS_VALUE = 1;
22
+ type ASYNC_ITERABLE_STATUS_VALUE = typeof ASYNC_ITERABLE_STATUS_VALUE;
23
+ declare const ASYNC_ITERABLE_STATUS_ERROR = 2;
24
+ type ASYNC_ITERABLE_STATUS_ERROR = typeof ASYNC_ITERABLE_STATUS_ERROR;
25
+ type ChunkDefinitionKey = null | number | string;
26
+ type ChunkIndex = number & {
27
+ __chunkIndex: true;
28
+ };
29
+ type ChunkValueType = CHUNK_VALUE_TYPE_PROMISE | CHUNK_VALUE_TYPE_ASYNC_ITERABLE;
30
+ type ChunkDefinition = [
31
+ key: ChunkDefinitionKey,
32
+ type: ChunkValueType,
33
+ chunkId: ChunkIndex
34
+ ];
35
+ type HydratedValue = [
36
+ [
37
+ unknown
38
+ ],
39
+ ...ChunkDefinition[]
40
+ ];
41
+ type PromiseChunk = [
42
+ chunkIndex: ChunkIndex,
43
+ status: PROMISE_STATUS_FULFILLED,
44
+ value: HydratedValue
45
+ ] | [
46
+ chunkIndex: ChunkIndex,
47
+ status: PROMISE_STATUS_REJECTED
48
+ ];
49
+ type IterableChunk = [chunkIndex: ChunkIndex, status: ASYNC_ITERABLE_STATUS_DONE] | [
50
+ chunkIndex: ChunkIndex,
51
+ status: ASYNC_ITERABLE_STATUS_VALUE,
52
+ value: HydratedValue
53
+ ] | [
54
+ chunkIndex: ChunkIndex,
55
+ status: ASYNC_ITERABLE_STATUS_ERROR
56
+ ];
57
+ type ChunkData = PromiseChunk | IterableChunk;
58
+ export declare function isPromise(value: unknown): value is Promise<unknown>;
59
+ type Serialize = (value: any) => any;
60
+ type Deserialize = (value: any) => any;
61
+ export type ProducerOnError = (opts: {
62
+ error: unknown;
63
+ path: (string | number)[];
64
+ }) => void;
65
+ export interface ProducerOptions {
66
+ serialize?: Serialize;
67
+ data: Record<number, unknown>;
68
+ onError?: ProducerOnError;
69
+ maxDepth?: number;
70
+ }
71
+ /**
72
+ * JSON Lines stream producer
73
+ * @see https://jsonlines.org/
74
+ */
75
+ export declare function jsonlStreamProducer(opts: ProducerOptions): ReadableStream<Uint8Array>;
76
+ declare class StreamInterruptedError extends Error {
77
+ constructor(cause?: unknown);
78
+ }
79
+ export type ConsumerOnError = (opts: {
80
+ error: unknown;
81
+ }) => void;
82
+ /**
83
+ * JSON Lines stream consumer
84
+ * @see https://jsonlines.org/
85
+ */
86
+ export declare function jsonlStreamConsumer<THead>(opts: {
87
+ from: NodeJSReadableStreamEsque | WebReadableStreamEsque;
88
+ deserialize?: Deserialize;
89
+ onError?: ConsumerOnError;
90
+ }): Promise<readonly [Awaited<THead>, {
91
+ readonly controllers: Map<ChunkIndex, ReadableStreamDefaultController<ChunkData | StreamInterruptedError>>;
92
+ }]>;
93
+ export {};
94
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../src/unstable-core-do-not-import/stream/stream.ts"],"names":[],"mappings":"AAiBA;;;GAGG;AACH,MAAM,MAAM,sBAAsB,GAAG;IACnC,SAAS,EAAE,MAAM,2BAA2B,CAAC,UAAU,CAAC,CAAC;CAC1D,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,EAAE,CACA,SAAS,EAAE,MAAM,GAAG,MAAM,EAC1B,QAAQ,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,GACjC,yBAAyB,CAAC;CAC9B,CAAC;AAGF,QAAA,MAAM,wBAAwB,IAAI,CAAC;AACnC,KAAK,wBAAwB,GAAG,OAAO,wBAAwB,CAAC;AAChE,QAAA,MAAM,+BAA+B,IAAI,CAAC;AAC1C,KAAK,+BAA+B,GAAG,OAAO,+BAA+B,CAAC;AAE9E,QAAA,MAAM,wBAAwB,IAAI,CAAC;AACnC,KAAK,wBAAwB,GAAG,OAAO,wBAAwB,CAAC;AAChE,QAAA,MAAM,uBAAuB,IAAI,CAAC;AAClC,KAAK,uBAAuB,GAAG,OAAO,uBAAuB,CAAC;AAE9D,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