@trpc/server 11.4.0 → 11.4.2-canary.1

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 (73) hide show
  1. package/dist/adapters/aws-lambda/index.cjs +49 -42
  2. package/dist/adapters/aws-lambda/index.mjs +47 -40
  3. package/dist/adapters/aws-lambda/index.mjs.map +1 -1
  4. package/dist/adapters/express.cjs +14 -15
  5. package/dist/adapters/express.mjs +14 -15
  6. package/dist/adapters/express.mjs.map +1 -1
  7. package/dist/adapters/fastify/index.cjs +27 -28
  8. package/dist/adapters/fastify/index.mjs +27 -28
  9. package/dist/adapters/fastify/index.mjs.map +1 -1
  10. package/dist/adapters/fetch/index.cjs +18 -19
  11. package/dist/adapters/fetch/index.mjs +18 -19
  12. package/dist/adapters/fetch/index.mjs.map +1 -1
  13. package/dist/adapters/next-app-dir.cjs +57 -53
  14. package/dist/adapters/next-app-dir.mjs +15 -11
  15. package/dist/adapters/next-app-dir.mjs.map +1 -1
  16. package/dist/adapters/next.cjs +14 -15
  17. package/dist/adapters/next.mjs +14 -15
  18. package/dist/adapters/next.mjs.map +1 -1
  19. package/dist/adapters/node-http/index.cjs +8 -8
  20. package/dist/adapters/node-http/index.mjs +8 -8
  21. package/dist/adapters/standalone.cjs +17 -17
  22. package/dist/adapters/standalone.mjs +16 -16
  23. package/dist/adapters/standalone.mjs.map +1 -1
  24. package/dist/adapters/ws.cjs +10 -10
  25. package/dist/adapters/ws.mjs +10 -10
  26. package/dist/getErrorShape-DKiEF6Zc.cjs +339 -0
  27. package/dist/getErrorShape-Uhlrl4Bk.mjs +263 -0
  28. package/dist/getErrorShape-Uhlrl4Bk.mjs.map +1 -0
  29. package/dist/http.cjs +5 -5
  30. package/dist/http.mjs +5 -5
  31. package/dist/index.cjs +4 -4
  32. package/dist/index.mjs +4 -4
  33. package/dist/{initTRPC-DjEpHmY2.cjs → initTRPC-IT4M4lu3.cjs} +83 -64
  34. package/dist/{initTRPC-COaJMShh.mjs → initTRPC-IT_6ZYJd.mjs} +84 -65
  35. package/dist/initTRPC-IT_6ZYJd.mjs.map +1 -0
  36. package/dist/{node-http-BUQnHuGI.mjs → node-http-Du8akt-R.mjs} +26 -23
  37. package/dist/{node-http-BUQnHuGI.mjs.map → node-http-Du8akt-R.mjs.map} +1 -1
  38. package/dist/{node-http-BPR68yI4.cjs → node-http-kIQEhZUH.cjs} +25 -22
  39. package/dist/observable/index.cjs +2 -2
  40. package/dist/observable/index.mjs +2 -2
  41. package/dist/{observable-BwdrSFZU.cjs → observable-B1Nk6r1H.cjs} +7 -4
  42. package/dist/{observable-C6qq2Ydk.cjs → observable-BVzLuBs6.cjs} +19 -7
  43. package/dist/{observable-CFXA_tyK.mjs → observable-CUiPknO-.mjs} +20 -8
  44. package/dist/{observable-CFXA_tyK.mjs.map → observable-CUiPknO-.mjs.map} +1 -1
  45. package/dist/{observable-B1orLHHI.mjs → observable-UMO3vUa_.mjs} +8 -5
  46. package/dist/{observable-B1orLHHI.mjs.map → observable-UMO3vUa_.mjs.map} +1 -1
  47. package/dist/{parseTRPCMessage-CNyYMSRB.mjs → parseTRPCMessage-ByIHyFRz.mjs} +2 -2
  48. package/dist/{parseTRPCMessage-CNyYMSRB.mjs.map → parseTRPCMessage-ByIHyFRz.mjs.map} +1 -1
  49. package/dist/{parseTRPCMessage-ByQWigsq.cjs → parseTRPCMessage-snNQop7N.cjs} +1 -1
  50. package/dist/{resolveResponse-B2CuaT_1.cjs → resolveResponse-CVGbakBm.cjs} +664 -405
  51. package/dist/{resolveResponse-DPbYgJDD.mjs → resolveResponse-CzlbRpCI.mjs} +660 -389
  52. package/dist/resolveResponse-CzlbRpCI.mjs.map +1 -0
  53. package/dist/rpc.cjs +2 -2
  54. package/dist/rpc.mjs +2 -2
  55. package/dist/shared.cjs +2 -2
  56. package/dist/shared.mjs +2 -2
  57. package/dist/{tracked-Dl9sBZxY.cjs → tracked-HoF8L_mq.cjs} +30 -42
  58. package/dist/{tracked-GEWPoL0C.mjs → tracked-gU3ttYjg.mjs} +31 -43
  59. package/dist/{tracked-GEWPoL0C.mjs.map → tracked-gU3ttYjg.mjs.map} +1 -1
  60. package/dist/unstable-core-do-not-import.cjs +7 -7
  61. package/dist/unstable-core-do-not-import.mjs +7 -7
  62. package/dist/{utils-BHZJcBRv.mjs → utils-DdbbrDku.mjs} +1 -1
  63. package/dist/{utils-BHZJcBRv.mjs.map → utils-DdbbrDku.mjs.map} +1 -1
  64. package/dist/{ws-C2nEUNk_.cjs → ws-BhrWsMpl.cjs} +37 -26
  65. package/dist/{ws-eIVIMTrw.mjs → ws-Bn5rkP_I.mjs} +37 -26
  66. package/dist/{ws-eIVIMTrw.mjs.map → ws-Bn5rkP_I.mjs.map} +1 -1
  67. package/package.json +62 -62
  68. package/dist/getErrorShape-CsikfkAc.cjs +0 -201
  69. package/dist/getErrorShape-DyYil4aT.mjs +0 -149
  70. package/dist/getErrorShape-DyYil4aT.mjs.map +0 -1
  71. package/dist/initTRPC-COaJMShh.mjs.map +0 -1
  72. package/dist/resolveResponse-DPbYgJDD.mjs.map +0 -1
  73. /package/dist/{utils-DVO6HZiR.cjs → utils-BhNVZA-c.cjs} +0 -0
@@ -1,33 +1,7 @@
1
- //#region rolldown:runtime
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __commonJS = (cb, mod) => function() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
13
- key = keys[i];
14
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
- get: ((k) => from[k]).bind(null, key),
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
- });
18
- }
19
- return to;
20
- };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
22
- value: mod,
23
- enumerable: true
24
- }) : target, mod));
25
-
26
- //#endregion
27
- const require_getErrorShape = require('./getErrorShape-CsikfkAc.cjs');
28
- const require_tracked = require('./tracked-Dl9sBZxY.cjs');
29
- const require_utils = require('./utils-DVO6HZiR.cjs');
30
- const require_observable = require('./observable-BwdrSFZU.cjs');
1
+ const require_getErrorShape = require('./getErrorShape-DKiEF6Zc.cjs');
2
+ const require_tracked = require('./tracked-HoF8L_mq.cjs');
3
+ const require_utils = require('./utils-BhNVZA-c.cjs');
4
+ const require_observable = require('./observable-B1Nk6r1H.cjs');
31
5
 
32
6
  //#region src/unstable-core-do-not-import/http/parseConnectionParams.ts
33
7
  function parseConnectionParamsFromUnknown(parsed) {
@@ -61,6 +35,7 @@ function parseConnectionParamsFromString(str) {
61
35
 
62
36
  //#endregion
63
37
  //#region src/unstable-core-do-not-import/http/contentType.ts
38
+ var import_objectSpread2$1 = require_getErrorShape.__toESM(require_getErrorShape.require_objectSpread2(), 1);
64
39
  /**
65
40
  * Memoize a function that takes no arguments
66
41
  * @internal
@@ -71,15 +46,16 @@ function memo(fn) {
71
46
  let value = sym;
72
47
  return {
73
48
  read: async () => {
49
+ var _promise;
74
50
  if (value !== sym) return value;
75
- promise ??= fn().catch((cause) => {
51
+ (_promise = promise) !== null && _promise !== void 0 || (promise = fn().catch((cause) => {
76
52
  if (cause instanceof require_tracked.TRPCError) throw cause;
77
53
  throw new require_tracked.TRPCError({
78
54
  code: "BAD_REQUEST",
79
55
  message: cause instanceof Error ? cause.message : "Invalid input",
80
56
  cause
81
57
  });
82
- });
58
+ }));
83
59
  value = await promise;
84
60
  promise = null;
85
61
  return value;
@@ -91,9 +67,11 @@ function memo(fn) {
91
67
  }
92
68
  const jsonContentTypeHandler = {
93
69
  isMatch(req) {
94
- return !!req.headers.get("content-type")?.startsWith("application/json");
70
+ var _req$headers$get;
71
+ return !!((_req$headers$get = req.headers.get("content-type")) === null || _req$headers$get === void 0 ? void 0 : _req$headers$get.startsWith("application/json"));
95
72
  },
96
73
  async parse(opts) {
74
+ var _types$values$next$va;
97
75
  const { req } = opts;
98
76
  const isBatchCall = opts.searchParams.get("batch") === "1";
99
77
  const paths = isBatchCall ? opts.path.split(",") : [opts.path];
@@ -124,28 +102,33 @@ const jsonContentTypeHandler = {
124
102
  getRawInput: async () => {
125
103
  const inputs = await getInputs.read();
126
104
  let input = inputs[index];
127
- if (procedure?._def.type === "subscription") {
128
- const lastEventId = opts.headers.get("last-event-id") ?? opts.searchParams.get("lastEventId") ?? opts.searchParams.get("Last-Event-Id");
129
- if (lastEventId) if (require_utils.isObject(input)) input = {
130
- ...input,
131
- lastEventId
132
- };
133
- else input ??= { lastEventId };
105
+ if ((procedure === null || procedure === void 0 ? void 0 : procedure._def.type) === "subscription") {
106
+ var _ref, _opts$headers$get;
107
+ const lastEventId = (_ref = (_opts$headers$get = opts.headers.get("last-event-id")) !== null && _opts$headers$get !== void 0 ? _opts$headers$get : opts.searchParams.get("lastEventId")) !== null && _ref !== void 0 ? _ref : opts.searchParams.get("Last-Event-Id");
108
+ if (lastEventId) if (require_utils.isObject(input)) input = (0, import_objectSpread2$1.default)((0, import_objectSpread2$1.default)({}, input), {}, { lastEventId });
109
+ else {
110
+ var _input;
111
+ (_input = input) !== null && _input !== void 0 || (input = { lastEventId });
112
+ }
134
113
  }
135
114
  return input;
136
115
  },
137
116
  result: () => {
138
- return getInputs.result()?.[index];
117
+ var _getInputs$result;
118
+ return (_getInputs$result = getInputs.result()) === null || _getInputs$result === void 0 ? void 0 : _getInputs$result[index];
139
119
  }
140
120
  };
141
121
  }));
142
- const types = new Set(calls.map((call) => call.procedure?._def.type).filter(Boolean));
122
+ const types = new Set(calls.map((call) => {
123
+ var _call$procedure;
124
+ return (_call$procedure = call.procedure) === null || _call$procedure === void 0 ? void 0 : _call$procedure._def.type;
125
+ }).filter(Boolean));
143
126
  /* istanbul ignore if -- @preserve */
144
127
  if (types.size > 1) throw new require_tracked.TRPCError({
145
128
  code: "BAD_REQUEST",
146
129
  message: `Cannot mix procedure types in call: ${Array.from(types).join(", ")}`
147
130
  });
148
- const type = types.values().next().value ?? "unknown";
131
+ const type = (_types$values$next$va = types.values().next().value) !== null && _types$values$next$va !== void 0 ? _types$values$next$va : "unknown";
149
132
  const connectionParamsStr = opts.searchParams.get("connectionParams");
150
133
  const info = {
151
134
  isBatchCall,
@@ -161,7 +144,8 @@ const jsonContentTypeHandler = {
161
144
  };
162
145
  const formDataContentTypeHandler = {
163
146
  isMatch(req) {
164
- return !!req.headers.get("content-type")?.startsWith("multipart/form-data");
147
+ var _req$headers$get2;
148
+ return !!((_req$headers$get2 = req.headers.get("content-type")) === null || _req$headers$get2 === void 0 ? void 0 : _req$headers$get2.startsWith("multipart/form-data"));
165
149
  },
166
150
  async parse(opts) {
167
151
  const { req } = opts;
@@ -192,7 +176,8 @@ const formDataContentTypeHandler = {
192
176
  };
193
177
  const octetStreamContentTypeHandler = {
194
178
  isMatch(req) {
195
- return !!req.headers.get("content-type")?.startsWith("application/octet-stream");
179
+ var _req$headers$get3;
180
+ return !!((_req$headers$get3 = req.headers.get("content-type")) === null || _req$headers$get3 === void 0 ? void 0 : _req$headers$get3.startsWith("application/octet-stream"));
196
181
  },
197
182
  async parse(opts) {
198
183
  const { req } = opts;
@@ -249,6 +234,8 @@ function throwAbortError(message = "AbortError") {
249
234
 
250
235
  //#endregion
251
236
  //#region src/vendor/unpromise/unpromise.ts
237
+ var import_defineProperty = require_getErrorShape.__toESM(require_getErrorShape.require_defineProperty(), 1);
238
+ let _Symbol$toStringTag;
252
239
  /** Memory safe (weakmapped) cache of the ProxyPromise for each Promise,
253
240
  * which is retained for the lifetime of the original Promise.
254
241
  */
@@ -257,6 +244,7 @@ const subscribableCache = /* @__PURE__ */ new WeakMap();
257
244
  * SubscribedPromises (settled promises are not subscribed - they resolve
258
245
  * immediately). */
259
246
  const NOOP = () => {};
247
+ _Symbol$toStringTag = Symbol.toStringTag;
260
248
  /**
261
249
  * Every `Promise<T>` can be shadowed by a single `ProxyPromise<T>`. It is
262
250
  * created once, cached and reused throughout the lifetime of the Promise. Get a
@@ -291,17 +279,11 @@ const NOOP = () => {};
291
279
  *
292
280
  */
293
281
  var Unpromise = class Unpromise {
294
- /** INSTANCE IMPLEMENTATION */
295
- /** The promise shadowed by this Unpromise<T> */
296
- promise;
297
- /** Promises expecting eventual settlement (unless unsubscribed first). This list is deleted
298
- * after the original promise settles - no further notifications will be issued. */
299
- subscribers = [];
300
- /** The Promise's settlement (recorded when it fulfils or rejects). This is consulted when
301
- * calling .subscribe() .then() .catch() .finally() to see if an immediately-resolving Promise
302
- * can be returned, and therefore subscription can be bypassed. */
303
- settlement = null;
304
282
  constructor(arg) {
283
+ (0, import_defineProperty.default)(this, "promise", void 0);
284
+ (0, import_defineProperty.default)(this, "subscribers", []);
285
+ (0, import_defineProperty.default)(this, "settlement", null);
286
+ (0, import_defineProperty.default)(this, _Symbol$toStringTag, "Unpromise");
305
287
  if (typeof arg === "function") this.promise = new Promise(arg);
306
288
  else this.promise = arg;
307
289
  const thenReturn = this.promise.then((value) => {
@@ -311,7 +293,7 @@ var Unpromise = class Unpromise {
311
293
  status: "fulfilled",
312
294
  value
313
295
  };
314
- subscribers?.forEach(({ resolve }) => {
296
+ subscribers === null || subscribers === void 0 || subscribers.forEach(({ resolve }) => {
315
297
  resolve(value);
316
298
  });
317
299
  });
@@ -322,7 +304,7 @@ var Unpromise = class Unpromise {
322
304
  status: "rejected",
323
305
  reason
324
306
  };
325
- subscribers?.forEach(({ reject }) => {
307
+ subscribers === null || subscribers === void 0 || subscribers.forEach(({ reject }) => {
326
308
  reject(reason);
327
309
  });
328
310
  });
@@ -381,8 +363,6 @@ var Unpromise = class Unpromise {
381
363
  const { unsubscribe } = subscribed;
382
364
  return Object.assign(subscribed.finally(onfinally), { unsubscribe });
383
365
  }
384
- /** TOSTRING SUPPORT */
385
- [Symbol.toStringTag] = "Unpromise";
386
366
  /** Unpromise STATIC METHODS */
387
367
  /** Create or Retrieve the proxy Unpromise (a re-used Unpromise for the VM lifetime
388
368
  * of the provided Promise reference) */
@@ -490,8 +470,9 @@ function listWithoutMember(arr, member) {
490
470
 
491
471
  //#endregion
492
472
  //#region src/unstable-core-do-not-import/stream/utils/disposable.ts
493
- Symbol.dispose ??= Symbol();
494
- Symbol.asyncDispose ??= Symbol();
473
+ var _Symbol, _Symbol$dispose, _Symbol2, _Symbol2$asyncDispose;
474
+ (_Symbol$dispose = (_Symbol = Symbol).dispose) !== null && _Symbol$dispose !== void 0 || (_Symbol.dispose = Symbol());
475
+ (_Symbol2$asyncDispose = (_Symbol2 = Symbol).asyncDispose) !== null && _Symbol2$asyncDispose !== void 0 || (_Symbol2.asyncDispose = Symbol());
495
476
  /**
496
477
  * Takes a value and a dispose function and returns a new object that implements the Disposable interface.
497
478
  * The returned object is the original value augmented with a Symbol.dispose method.
@@ -504,7 +485,7 @@ function makeResource(thing, dispose) {
504
485
  const existing = it[Symbol.dispose];
505
486
  it[Symbol.dispose] = () => {
506
487
  dispose();
507
- existing?.();
488
+ existing === null || existing === void 0 || existing();
508
489
  };
509
490
  return it;
510
491
  }
@@ -520,7 +501,7 @@ function makeAsyncResource(thing, dispose) {
520
501
  const existing = it[Symbol.asyncDispose];
521
502
  it[Symbol.asyncDispose] = async () => {
522
503
  await dispose();
523
- await existing?.();
504
+ await (existing === null || existing === void 0 ? void 0 : existing());
524
505
  };
525
506
  return it;
526
507
  }
@@ -543,7 +524,7 @@ function timerResource(ms) {
543
524
 
544
525
  //#endregion
545
526
  //#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js
546
- var require_usingCtx = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js"(exports, module) {
527
+ var require_usingCtx = require_getErrorShape.__commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js"(exports, module) {
547
528
  function _usingCtx() {
548
529
  var r = "function" == typeof SuppressedError ? SuppressedError : function(r$1, e$1) {
549
530
  var n$1 = Error();
@@ -601,65 +582,170 @@ var require_usingCtx = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runti
601
582
  module.exports = _usingCtx, module.exports.__esModule = true, module.exports["default"] = module.exports;
602
583
  } });
603
584
 
585
+ //#endregion
586
+ //#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/OverloadYield.js
587
+ var require_OverloadYield = require_getErrorShape.__commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/OverloadYield.js"(exports, module) {
588
+ function _OverloadYield(e, d) {
589
+ this.v = e, this.k = d;
590
+ }
591
+ module.exports = _OverloadYield, module.exports.__esModule = true, module.exports["default"] = module.exports;
592
+ } });
593
+
594
+ //#endregion
595
+ //#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/awaitAsyncGenerator.js
596
+ var require_awaitAsyncGenerator = require_getErrorShape.__commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/awaitAsyncGenerator.js"(exports, module) {
597
+ var OverloadYield$2 = require_OverloadYield();
598
+ function _awaitAsyncGenerator$5(e) {
599
+ return new OverloadYield$2(e, 0);
600
+ }
601
+ module.exports = _awaitAsyncGenerator$5, module.exports.__esModule = true, module.exports["default"] = module.exports;
602
+ } });
603
+
604
+ //#endregion
605
+ //#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/wrapAsyncGenerator.js
606
+ var require_wrapAsyncGenerator = require_getErrorShape.__commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/wrapAsyncGenerator.js"(exports, module) {
607
+ var OverloadYield$1 = require_OverloadYield();
608
+ function _wrapAsyncGenerator$6(e) {
609
+ return function() {
610
+ return new AsyncGenerator(e.apply(this, arguments));
611
+ };
612
+ }
613
+ function AsyncGenerator(e) {
614
+ var r, t;
615
+ function resume(r$1, t$1) {
616
+ try {
617
+ var n = e[r$1](t$1), o = n.value, u = o instanceof OverloadYield$1;
618
+ Promise.resolve(u ? o.v : o).then(function(t$2) {
619
+ if (u) {
620
+ var i = "return" === r$1 ? "return" : "next";
621
+ if (!o.k || t$2.done) return resume(i, t$2);
622
+ t$2 = e[i](t$2).value;
623
+ }
624
+ settle(n.done ? "return" : "normal", t$2);
625
+ }, function(e$1) {
626
+ resume("throw", e$1);
627
+ });
628
+ } catch (e$1) {
629
+ settle("throw", e$1);
630
+ }
631
+ }
632
+ function settle(e$1, n) {
633
+ switch (e$1) {
634
+ case "return":
635
+ r.resolve({
636
+ value: n,
637
+ done: !0
638
+ });
639
+ break;
640
+ case "throw":
641
+ r.reject(n);
642
+ break;
643
+ default: r.resolve({
644
+ value: n,
645
+ done: !1
646
+ });
647
+ }
648
+ (r = r.next) ? resume(r.key, r.arg) : t = null;
649
+ }
650
+ this._invoke = function(e$1, n) {
651
+ return new Promise(function(o, u) {
652
+ var i = {
653
+ key: e$1,
654
+ arg: n,
655
+ resolve: o,
656
+ reject: u,
657
+ next: null
658
+ };
659
+ t ? t = t.next = i : (r = t = i, resume(e$1, n));
660
+ });
661
+ }, "function" != typeof e["return"] && (this["return"] = void 0);
662
+ }
663
+ AsyncGenerator.prototype["function" == typeof Symbol && Symbol.asyncIterator || "@@asyncIterator"] = function() {
664
+ return this;
665
+ }, AsyncGenerator.prototype.next = function(e) {
666
+ return this._invoke("next", e);
667
+ }, AsyncGenerator.prototype["throw"] = function(e) {
668
+ return this._invoke("throw", e);
669
+ }, AsyncGenerator.prototype["return"] = function(e) {
670
+ return this._invoke("return", e);
671
+ };
672
+ module.exports = _wrapAsyncGenerator$6, module.exports.__esModule = true, module.exports["default"] = module.exports;
673
+ } });
674
+
604
675
  //#endregion
605
676
  //#region src/unstable-core-do-not-import/stream/utils/asyncIterable.ts
606
- var import_usingCtx$4 = __toESM(require_usingCtx(), 1);
677
+ var import_usingCtx$4 = require_getErrorShape.__toESM(require_usingCtx(), 1);
678
+ var import_awaitAsyncGenerator$4 = require_getErrorShape.__toESM(require_awaitAsyncGenerator(), 1);
679
+ var import_wrapAsyncGenerator$5 = require_getErrorShape.__toESM(require_wrapAsyncGenerator(), 1);
607
680
  function iteratorResource(iterable) {
608
681
  const iterator = iterable[Symbol.asyncIterator]();
609
682
  if (iterator[Symbol.asyncDispose]) return iterator;
610
683
  return makeAsyncResource(iterator, async () => {
611
- await iterator.return?.();
684
+ var _iterator$return;
685
+ await ((_iterator$return = iterator.return) === null || _iterator$return === void 0 ? void 0 : _iterator$return.call(iterator));
612
686
  });
613
687
  }
614
688
  /**
615
689
  * Derives a new {@link AsyncGenerator} based on {@link iterable}, that automatically aborts after the specified duration.
616
690
  */
617
- async function* withMaxDuration(iterable, opts) {
618
- try {
619
- var _usingCtx$1 = (0, import_usingCtx$4.default)();
620
- const iterator = _usingCtx$1.a(iteratorResource(iterable));
621
- const timer = _usingCtx$1.u(timerResource(opts.maxDurationMs));
622
- const timerPromise = timer.start();
623
- let result;
624
- while (true) {
625
- result = await Unpromise.race([iterator.next(), timerPromise]);
626
- if (result === disposablePromiseTimerResult) throwAbortError();
627
- if (result.done) return result;
628
- yield result.value;
629
- result = null;
691
+ function withMaxDuration(_x, _x2) {
692
+ return _withMaxDuration.apply(this, arguments);
693
+ }
694
+ function _withMaxDuration() {
695
+ _withMaxDuration = (0, import_wrapAsyncGenerator$5.default)(function* (iterable, opts) {
696
+ try {
697
+ var _usingCtx$1 = (0, import_usingCtx$4.default)();
698
+ const iterator = _usingCtx$1.a(iteratorResource(iterable));
699
+ const timer = _usingCtx$1.u(timerResource(opts.maxDurationMs));
700
+ const timerPromise = timer.start();
701
+ let result;
702
+ while (true) {
703
+ result = yield (0, import_awaitAsyncGenerator$4.default)(Unpromise.race([iterator.next(), timerPromise]));
704
+ if (result === disposablePromiseTimerResult) throwAbortError();
705
+ if (result.done) return result;
706
+ yield result.value;
707
+ result = null;
708
+ }
709
+ } catch (_) {
710
+ _usingCtx$1.e = _;
711
+ } finally {
712
+ yield (0, import_awaitAsyncGenerator$4.default)(_usingCtx$1.d());
630
713
  }
631
- } catch (_) {
632
- _usingCtx$1.e = _;
633
- } finally {
634
- await _usingCtx$1.d();
635
- }
714
+ });
715
+ return _withMaxDuration.apply(this, arguments);
636
716
  }
637
717
  /**
638
718
  * Derives a new {@link AsyncGenerator} based of {@link iterable}, that yields its first
639
719
  * {@link count} values. Then, a grace period of {@link gracePeriodMs} is started in which further
640
720
  * values may still come through. After this period, the generator aborts.
641
721
  */
642
- async function* takeWithGrace(iterable, opts) {
643
- try {
644
- var _usingCtx3 = (0, import_usingCtx$4.default)();
645
- const iterator = _usingCtx3.a(iteratorResource(iterable));
646
- let result;
647
- const timer = _usingCtx3.u(timerResource(opts.gracePeriodMs));
648
- let count = opts.count;
649
- let timerPromise = new Promise(() => {});
650
- while (true) {
651
- result = await Unpromise.race([iterator.next(), timerPromise]);
652
- if (result === disposablePromiseTimerResult) throwAbortError();
653
- if (result.done) return result.value;
654
- yield result.value;
655
- if (--count === 0) timerPromise = timer.start();
656
- result = null;
722
+ function takeWithGrace(_x3, _x4) {
723
+ return _takeWithGrace.apply(this, arguments);
724
+ }
725
+ function _takeWithGrace() {
726
+ _takeWithGrace = (0, import_wrapAsyncGenerator$5.default)(function* (iterable, opts) {
727
+ try {
728
+ var _usingCtx3 = (0, import_usingCtx$4.default)();
729
+ const iterator = _usingCtx3.a(iteratorResource(iterable));
730
+ let result;
731
+ const timer = _usingCtx3.u(timerResource(opts.gracePeriodMs));
732
+ let count = opts.count;
733
+ let timerPromise = new Promise(() => {});
734
+ while (true) {
735
+ result = yield (0, import_awaitAsyncGenerator$4.default)(Unpromise.race([iterator.next(), timerPromise]));
736
+ if (result === disposablePromiseTimerResult) throwAbortError();
737
+ if (result.done) return result.value;
738
+ yield result.value;
739
+ if (--count === 0) timerPromise = timer.start();
740
+ result = null;
741
+ }
742
+ } catch (_) {
743
+ _usingCtx3.e = _;
744
+ } finally {
745
+ yield (0, import_awaitAsyncGenerator$4.default)(_usingCtx3.d());
657
746
  }
658
- } catch (_) {
659
- _usingCtx3.e = _;
660
- } finally {
661
- await _usingCtx3.d();
662
- }
747
+ });
748
+ return _takeWithGrace.apply(this, arguments);
663
749
  }
664
750
 
665
751
  //#endregion
@@ -680,7 +766,9 @@ function createDeferred() {
680
766
 
681
767
  //#endregion
682
768
  //#region src/unstable-core-do-not-import/stream/utils/mergeAsyncIterables.ts
683
- var import_usingCtx$3 = __toESM(require_usingCtx(), 1);
769
+ var import_usingCtx$3 = require_getErrorShape.__toESM(require_usingCtx(), 1);
770
+ var import_awaitAsyncGenerator$3 = require_getErrorShape.__toESM(require_awaitAsyncGenerator(), 1);
771
+ var import_wrapAsyncGenerator$4 = require_getErrorShape.__toESM(require_wrapAsyncGenerator(), 1);
684
772
  function createManagedIterator(iterable, onResult) {
685
773
  const iterator = iterable[Symbol.asyncIterator]();
686
774
  let state = "idle";
@@ -718,8 +806,9 @@ function createManagedIterator(iterable, onResult) {
718
806
  return {
719
807
  pull,
720
808
  destroy: async () => {
809
+ var _iterator$return;
721
810
  cleanup();
722
- await iterator.return?.();
811
+ await ((_iterator$return = iterator.return) === null || _iterator$return === void 0 ? void 0 : _iterator$return.call(iterator));
723
812
  }
724
813
  };
725
814
  }
@@ -779,46 +868,48 @@ function mergeAsyncIterables() {
779
868
  case "done": break;
780
869
  }
781
870
  },
782
- async *[Symbol.asyncIterator]() {
783
- try {
784
- var _usingCtx$1 = (0, import_usingCtx$3.default)();
785
- if (state !== "idle") throw new Error("Cannot iterate twice");
786
- state = "pending";
787
- const _finally = _usingCtx$1.a(makeAsyncResource({}, async () => {
788
- state = "done";
789
- const errors = [];
790
- await Promise.all(Array.from(iterators.values()).map(async (it) => {
791
- try {
792
- await it.destroy();
793
- } catch (cause) {
794
- errors.push(cause);
795
- }
871
+ [Symbol.asyncIterator]() {
872
+ return (0, import_wrapAsyncGenerator$4.default)(function* () {
873
+ try {
874
+ var _usingCtx$1 = (0, import_usingCtx$3.default)();
875
+ if (state !== "idle") throw new Error("Cannot iterate twice");
876
+ state = "pending";
877
+ const _finally = _usingCtx$1.a(makeAsyncResource({}, async () => {
878
+ state = "done";
879
+ const errors = [];
880
+ await Promise.all(Array.from(iterators.values()).map(async (it) => {
881
+ try {
882
+ await it.destroy();
883
+ } catch (cause) {
884
+ errors.push(cause);
885
+ }
886
+ }));
887
+ buffer.length = 0;
888
+ iterators.clear();
889
+ flushSignal.resolve();
890
+ if (errors.length > 0) throw new AggregateError(errors);
796
891
  }));
797
- buffer.length = 0;
798
- iterators.clear();
799
- flushSignal.resolve();
800
- if (errors.length > 0) throw new AggregateError(errors);
801
- }));
802
- while (iterables.length > 0) initIterable(iterables.shift());
803
- while (iterators.size > 0) {
804
- await flushSignal.promise;
805
- while (buffer.length > 0) {
806
- const [iterator, result] = buffer.shift();
807
- switch (result.status) {
808
- case "yield":
809
- yield result.value;
810
- iterator.pull();
811
- break;
812
- case "error": throw result.error;
892
+ while (iterables.length > 0) initIterable(iterables.shift());
893
+ while (iterators.size > 0) {
894
+ yield (0, import_awaitAsyncGenerator$3.default)(flushSignal.promise);
895
+ while (buffer.length > 0) {
896
+ const [iterator, result] = buffer.shift();
897
+ switch (result.status) {
898
+ case "yield":
899
+ yield result.value;
900
+ iterator.pull();
901
+ break;
902
+ case "error": throw result.error;
903
+ }
813
904
  }
905
+ flushSignal = createDeferred();
814
906
  }
815
- flushSignal = createDeferred();
907
+ } catch (_) {
908
+ _usingCtx$1.e = _;
909
+ } finally {
910
+ yield (0, import_awaitAsyncGenerator$3.default)(_usingCtx$1.d());
816
911
  }
817
- } catch (_) {
818
- _usingCtx$1.e = _;
819
- } finally {
820
- await _usingCtx$1.d();
821
- }
912
+ })();
822
913
  }
823
914
  };
824
915
  }
@@ -835,7 +926,8 @@ function readableStreamFrom(iterable) {
835
926
  const iterator = iterable[Symbol.asyncIterator]();
836
927
  return new ReadableStream({
837
928
  async cancel() {
838
- await iterator.return?.();
929
+ var _iterator$return;
930
+ await ((_iterator$return = iterator.return) === null || _iterator$return === void 0 ? void 0 : _iterator$return.call(iterator));
839
931
  },
840
932
  async pull(controller) {
841
933
  const result = await iterator.next();
@@ -850,45 +942,103 @@ function readableStreamFrom(iterable) {
850
942
 
851
943
  //#endregion
852
944
  //#region src/unstable-core-do-not-import/stream/utils/withPing.ts
853
- var import_usingCtx$2 = __toESM(require_usingCtx(), 1);
945
+ var import_usingCtx$2 = require_getErrorShape.__toESM(require_usingCtx(), 1);
946
+ var import_awaitAsyncGenerator$2 = require_getErrorShape.__toESM(require_awaitAsyncGenerator(), 1);
947
+ var import_wrapAsyncGenerator$3 = require_getErrorShape.__toESM(require_wrapAsyncGenerator(), 1);
854
948
  const PING_SYM = Symbol("ping");
855
949
  /**
856
950
  * Derives a new {@link AsyncGenerator} based of {@link iterable}, that yields {@link PING_SYM}
857
951
  * whenever no value has been yielded for {@link pingIntervalMs}.
858
952
  */
859
- async function* withPing(iterable, pingIntervalMs) {
860
- try {
861
- var _usingCtx$1 = (0, import_usingCtx$2.default)();
862
- const iterator = _usingCtx$1.a(iteratorResource(iterable));
863
- let result;
864
- let nextPromise = iterator.next();
865
- while (true) try {
866
- var _usingCtx3 = (0, import_usingCtx$2.default)();
867
- const pingPromise = _usingCtx3.u(timerResource(pingIntervalMs));
868
- result = await Unpromise.race([nextPromise, pingPromise.start()]);
869
- if (result === disposablePromiseTimerResult) {
870
- yield PING_SYM;
871
- continue;
953
+ function withPing(_x, _x2) {
954
+ return _withPing.apply(this, arguments);
955
+ }
956
+ function _withPing() {
957
+ _withPing = (0, import_wrapAsyncGenerator$3.default)(function* (iterable, pingIntervalMs) {
958
+ try {
959
+ var _usingCtx$1 = (0, import_usingCtx$2.default)();
960
+ const iterator = _usingCtx$1.a(iteratorResource(iterable));
961
+ let result;
962
+ let nextPromise = iterator.next();
963
+ while (true) try {
964
+ var _usingCtx3 = (0, import_usingCtx$2.default)();
965
+ const pingPromise = _usingCtx3.u(timerResource(pingIntervalMs));
966
+ result = yield (0, import_awaitAsyncGenerator$2.default)(Unpromise.race([nextPromise, pingPromise.start()]));
967
+ if (result === disposablePromiseTimerResult) {
968
+ yield PING_SYM;
969
+ continue;
970
+ }
971
+ if (result.done) return result.value;
972
+ nextPromise = iterator.next();
973
+ yield result.value;
974
+ result = null;
975
+ } catch (_) {
976
+ _usingCtx3.e = _;
977
+ } finally {
978
+ _usingCtx3.d();
872
979
  }
873
- if (result.done) return result.value;
874
- nextPromise = iterator.next();
875
- yield result.value;
876
- result = null;
877
980
  } catch (_) {
878
- _usingCtx3.e = _;
981
+ _usingCtx$1.e = _;
879
982
  } finally {
880
- _usingCtx3.d();
983
+ yield (0, import_awaitAsyncGenerator$2.default)(_usingCtx$1.d());
881
984
  }
882
- } catch (_) {
883
- _usingCtx$1.e = _;
884
- } finally {
885
- await _usingCtx$1.d();
886
- }
985
+ });
986
+ return _withPing.apply(this, arguments);
887
987
  }
888
988
 
989
+ //#endregion
990
+ //#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/asyncIterator.js
991
+ var require_asyncIterator = require_getErrorShape.__commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/asyncIterator.js"(exports, module) {
992
+ function _asyncIterator$2(r) {
993
+ var n, t, o, e = 2;
994
+ for ("undefined" != typeof Symbol && (t = Symbol.asyncIterator, o = Symbol.iterator); e--;) {
995
+ if (t && null != (n = r[t])) return n.call(r);
996
+ if (o && null != (n = r[o])) return new AsyncFromSyncIterator(n.call(r));
997
+ t = "@@asyncIterator", o = "@@iterator";
998
+ }
999
+ throw new TypeError("Object is not async iterable");
1000
+ }
1001
+ function AsyncFromSyncIterator(r) {
1002
+ function AsyncFromSyncIteratorContinuation(r$1) {
1003
+ if (Object(r$1) !== r$1) return Promise.reject(new TypeError(r$1 + " is not an object."));
1004
+ var n = r$1.done;
1005
+ return Promise.resolve(r$1.value).then(function(r$2) {
1006
+ return {
1007
+ value: r$2,
1008
+ done: n
1009
+ };
1010
+ });
1011
+ }
1012
+ return AsyncFromSyncIterator = function AsyncFromSyncIterator$1(r$1) {
1013
+ this.s = r$1, this.n = r$1.next;
1014
+ }, AsyncFromSyncIterator.prototype = {
1015
+ s: null,
1016
+ n: null,
1017
+ next: function next() {
1018
+ return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
1019
+ },
1020
+ "return": function _return(r$1) {
1021
+ var n = this.s["return"];
1022
+ return void 0 === n ? Promise.resolve({
1023
+ value: r$1,
1024
+ done: !0
1025
+ }) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
1026
+ },
1027
+ "throw": function _throw(r$1) {
1028
+ var n = this.s["return"];
1029
+ return void 0 === n ? Promise.reject(r$1) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
1030
+ }
1031
+ }, new AsyncFromSyncIterator(r);
1032
+ }
1033
+ module.exports = _asyncIterator$2, module.exports.__esModule = true, module.exports["default"] = module.exports;
1034
+ } });
1035
+
889
1036
  //#endregion
890
1037
  //#region src/unstable-core-do-not-import/stream/jsonl.ts
891
- var import_usingCtx$1 = __toESM(require_usingCtx(), 1);
1038
+ var import_awaitAsyncGenerator$1 = require_getErrorShape.__toESM(require_awaitAsyncGenerator(), 1);
1039
+ var import_wrapAsyncGenerator$2 = require_getErrorShape.__toESM(require_wrapAsyncGenerator(), 1);
1040
+ var import_usingCtx$1 = require_getErrorShape.__toESM(require_usingCtx(), 1);
1041
+ var import_asyncIterator$1 = require_getErrorShape.__toESM(require_asyncIterator(), 1);
892
1042
  function isPlainObject(value) {
893
1043
  return Object.prototype.toString.call(value) === "[object Object]";
894
1044
  }
@@ -900,7 +1050,7 @@ const ASYNC_ITERABLE_STATUS_RETURN = 0;
900
1050
  const ASYNC_ITERABLE_STATUS_YIELD = 1;
901
1051
  const ASYNC_ITERABLE_STATUS_ERROR = 2;
902
1052
  function isPromise(value) {
903
- return (require_utils.isObject(value) || require_utils.isFunction(value)) && typeof value?.["then"] === "function" && typeof value?.["catch"] === "function";
1053
+ return (require_utils.isObject(value) || require_utils.isFunction(value)) && typeof (value === null || value === void 0 ? void 0 : value["then"]) === "function" && typeof (value === null || value === void 0 ? void 0 : value["catch"]) === "function";
904
1054
  }
905
1055
  var MaxDepthError = class extends Error {
906
1056
  constructor(path) {
@@ -908,133 +1058,169 @@ var MaxDepthError = class extends Error {
908
1058
  this.path = path;
909
1059
  }
910
1060
  };
911
- async function* createBatchStreamProducer(opts) {
912
- const { data } = opts;
913
- let counter = 0;
914
- const placeholder = 0;
915
- const mergedIterables = mergeAsyncIterables();
916
- function registerAsync(callback) {
917
- const idx = counter++;
918
- const iterable$1 = callback(idx);
919
- mergedIterables.add(iterable$1);
920
- return idx;
921
- }
922
- function encodePromise(promise, path) {
923
- return registerAsync(async function* (idx) {
924
- const error = checkMaxDepth(path);
925
- if (error) {
926
- promise.catch((cause) => {
927
- opts.onError?.({
928
- error: cause,
929
- path
930
- });
931
- });
932
- promise = Promise.reject(error);
933
- }
934
- try {
935
- const next = await promise;
936
- yield [
937
- idx,
938
- PROMISE_STATUS_FULFILLED,
939
- encode(next, path)
940
- ];
941
- } catch (cause) {
942
- opts.onError?.({
943
- error: cause,
944
- path
1061
+ function createBatchStreamProducer(_x3) {
1062
+ return _createBatchStreamProducer.apply(this, arguments);
1063
+ }
1064
+ function _createBatchStreamProducer() {
1065
+ _createBatchStreamProducer = (0, import_wrapAsyncGenerator$2.default)(function* (opts) {
1066
+ const { data } = opts;
1067
+ let counter = 0;
1068
+ const placeholder = 0;
1069
+ const mergedIterables = mergeAsyncIterables();
1070
+ function registerAsync(callback) {
1071
+ const idx = counter++;
1072
+ const iterable$1 = callback(idx);
1073
+ mergedIterables.add(iterable$1);
1074
+ return idx;
1075
+ }
1076
+ function encodePromise(promise, path) {
1077
+ return registerAsync(/* @__PURE__ */ function() {
1078
+ var _ref = (0, import_wrapAsyncGenerator$2.default)(function* (idx) {
1079
+ const error = checkMaxDepth(path);
1080
+ if (error) {
1081
+ promise.catch((cause) => {
1082
+ var _opts$onError;
1083
+ (_opts$onError = opts.onError) === null || _opts$onError === void 0 || _opts$onError.call(opts, {
1084
+ error: cause,
1085
+ path
1086
+ });
1087
+ });
1088
+ promise = Promise.reject(error);
1089
+ }
1090
+ try {
1091
+ const next = yield (0, import_awaitAsyncGenerator$1.default)(promise);
1092
+ yield [
1093
+ idx,
1094
+ PROMISE_STATUS_FULFILLED,
1095
+ encode(next, path)
1096
+ ];
1097
+ } catch (cause) {
1098
+ var _opts$onError2, _opts$formatError;
1099
+ (_opts$onError2 = opts.onError) === null || _opts$onError2 === void 0 || _opts$onError2.call(opts, {
1100
+ error: cause,
1101
+ path
1102
+ });
1103
+ yield [
1104
+ idx,
1105
+ PROMISE_STATUS_REJECTED,
1106
+ (_opts$formatError = opts.formatError) === null || _opts$formatError === void 0 ? void 0 : _opts$formatError.call(opts, {
1107
+ error: cause,
1108
+ path
1109
+ })
1110
+ ];
1111
+ }
945
1112
  });
946
- yield [
947
- idx,
948
- PROMISE_STATUS_REJECTED,
949
- opts.formatError?.({
950
- error: cause,
951
- path
952
- })
953
- ];
954
- }
955
- });
956
- }
957
- function encodeAsyncIterable(iterable$1, path) {
958
- return registerAsync(async function* (idx) {
959
- try {
960
- var _usingCtx$1 = (0, import_usingCtx$1.default)();
961
- const error = checkMaxDepth(path);
962
- if (error) throw error;
963
- const iterator = _usingCtx$1.a(iteratorResource(iterable$1));
964
- try {
965
- while (true) {
966
- const next = await iterator.next();
967
- if (next.done) {
1113
+ return function(_x) {
1114
+ return _ref.apply(this, arguments);
1115
+ };
1116
+ }());
1117
+ }
1118
+ function encodeAsyncIterable(iterable$1, path) {
1119
+ return registerAsync(/* @__PURE__ */ function() {
1120
+ var _ref2 = (0, import_wrapAsyncGenerator$2.default)(function* (idx) {
1121
+ try {
1122
+ var _usingCtx$1 = (0, import_usingCtx$1.default)();
1123
+ const error = checkMaxDepth(path);
1124
+ if (error) throw error;
1125
+ const iterator = _usingCtx$1.a(iteratorResource(iterable$1));
1126
+ try {
1127
+ while (true) {
1128
+ const next = yield (0, import_awaitAsyncGenerator$1.default)(iterator.next());
1129
+ if (next.done) {
1130
+ yield [
1131
+ idx,
1132
+ ASYNC_ITERABLE_STATUS_RETURN,
1133
+ encode(next.value, path)
1134
+ ];
1135
+ break;
1136
+ }
1137
+ yield [
1138
+ idx,
1139
+ ASYNC_ITERABLE_STATUS_YIELD,
1140
+ encode(next.value, path)
1141
+ ];
1142
+ }
1143
+ } catch (cause) {
1144
+ var _opts$onError3, _opts$formatError2;
1145
+ (_opts$onError3 = opts.onError) === null || _opts$onError3 === void 0 || _opts$onError3.call(opts, {
1146
+ error: cause,
1147
+ path
1148
+ });
968
1149
  yield [
969
1150
  idx,
970
- ASYNC_ITERABLE_STATUS_RETURN,
971
- encode(next.value, path)
1151
+ ASYNC_ITERABLE_STATUS_ERROR,
1152
+ (_opts$formatError2 = opts.formatError) === null || _opts$formatError2 === void 0 ? void 0 : _opts$formatError2.call(opts, {
1153
+ error: cause,
1154
+ path
1155
+ })
972
1156
  ];
973
- break;
974
1157
  }
975
- yield [
976
- idx,
977
- ASYNC_ITERABLE_STATUS_YIELD,
978
- encode(next.value, path)
979
- ];
1158
+ } catch (_) {
1159
+ _usingCtx$1.e = _;
1160
+ } finally {
1161
+ yield (0, import_awaitAsyncGenerator$1.default)(_usingCtx$1.d());
980
1162
  }
981
- } catch (cause) {
982
- opts.onError?.({
983
- error: cause,
984
- path
985
- });
986
- yield [
987
- idx,
988
- ASYNC_ITERABLE_STATUS_ERROR,
989
- opts.formatError?.({
990
- error: cause,
991
- path
992
- })
993
- ];
1163
+ });
1164
+ return function(_x2) {
1165
+ return _ref2.apply(this, arguments);
1166
+ };
1167
+ }());
1168
+ }
1169
+ function checkMaxDepth(path) {
1170
+ if (opts.maxDepth && path.length > opts.maxDepth) return new MaxDepthError(path);
1171
+ return null;
1172
+ }
1173
+ function encodeAsync(value, path) {
1174
+ if (isPromise(value)) return [CHUNK_VALUE_TYPE_PROMISE, encodePromise(value, path)];
1175
+ if (require_utils.isAsyncIterable(value)) {
1176
+ if (opts.maxDepth && path.length >= opts.maxDepth) throw new Error("Max depth reached");
1177
+ return [CHUNK_VALUE_TYPE_ASYNC_ITERABLE, encodeAsyncIterable(value, path)];
1178
+ }
1179
+ return null;
1180
+ }
1181
+ function encode(value, path) {
1182
+ if (value === void 0) return [[]];
1183
+ const reg = encodeAsync(value, path);
1184
+ if (reg) return [[placeholder], [null, ...reg]];
1185
+ if (!isPlainObject(value)) return [[value]];
1186
+ const newObj = {};
1187
+ const asyncValues = [];
1188
+ for (const [key, item] of Object.entries(value)) {
1189
+ const transformed = encodeAsync(item, [...path, key]);
1190
+ if (!transformed) {
1191
+ newObj[key] = item;
1192
+ continue;
994
1193
  }
995
- } catch (_) {
996
- _usingCtx$1.e = _;
997
- } finally {
998
- await _usingCtx$1.d();
1194
+ newObj[key] = placeholder;
1195
+ asyncValues.push([key, ...transformed]);
999
1196
  }
1000
- });
1001
- }
1002
- function checkMaxDepth(path) {
1003
- if (opts.maxDepth && path.length > opts.maxDepth) return new MaxDepthError(path);
1004
- return null;
1005
- }
1006
- function encodeAsync(value, path) {
1007
- if (isPromise(value)) return [CHUNK_VALUE_TYPE_PROMISE, encodePromise(value, path)];
1008
- if (require_utils.isAsyncIterable(value)) {
1009
- if (opts.maxDepth && path.length >= opts.maxDepth) throw new Error("Max depth reached");
1010
- return [CHUNK_VALUE_TYPE_ASYNC_ITERABLE, encodeAsyncIterable(value, path)];
1197
+ return [[newObj], ...asyncValues];
1011
1198
  }
1012
- return null;
1013
- }
1014
- function encode(value, path) {
1015
- if (value === void 0) return [[]];
1016
- const reg = encodeAsync(value, path);
1017
- if (reg) return [[placeholder], [null, ...reg]];
1018
- if (!isPlainObject(value)) return [[value]];
1019
- const newObj = {};
1020
- const asyncValues = [];
1021
- for (const [key, item] of Object.entries(value)) {
1022
- const transformed = encodeAsync(item, [...path, key]);
1023
- if (!transformed) {
1024
- newObj[key] = item;
1025
- continue;
1199
+ const newHead = {};
1200
+ for (const [key, item] of Object.entries(data)) newHead[key] = encode(item, [key]);
1201
+ yield newHead;
1202
+ let iterable = mergedIterables;
1203
+ if (opts.pingMs) iterable = withPing(mergedIterables, opts.pingMs);
1204
+ var _iteratorAbruptCompletion = false;
1205
+ var _didIteratorError = false;
1206
+ var _iteratorError;
1207
+ try {
1208
+ for (var _iterator = (0, import_asyncIterator$1.default)(iterable), _step; _iteratorAbruptCompletion = !(_step = yield (0, import_awaitAsyncGenerator$1.default)(_iterator.next())).done; _iteratorAbruptCompletion = false) {
1209
+ const value = _step.value;
1210
+ yield value;
1211
+ }
1212
+ } catch (err) {
1213
+ _didIteratorError = true;
1214
+ _iteratorError = err;
1215
+ } finally {
1216
+ try {
1217
+ if (_iteratorAbruptCompletion && _iterator.return != null) yield (0, import_awaitAsyncGenerator$1.default)(_iterator.return());
1218
+ } finally {
1219
+ if (_didIteratorError) throw _iteratorError;
1026
1220
  }
1027
- newObj[key] = placeholder;
1028
- asyncValues.push([key, ...transformed]);
1029
1221
  }
1030
- return [[newObj], ...asyncValues];
1031
- }
1032
- const newHead = {};
1033
- for (const [key, item] of Object.entries(data)) newHead[key] = encode(item, [key]);
1034
- yield newHead;
1035
- let iterable = mergedIterables;
1036
- if (opts.pingMs) iterable = withPing(mergedIterables, opts.pingMs);
1037
- for await (const value of iterable) yield value;
1222
+ });
1223
+ return _createBatchStreamProducer.apply(this, arguments);
1038
1224
  }
1039
1225
  /**
1040
1226
  * JSON Lines stream producer
@@ -1087,9 +1273,10 @@ function createLineAccumulator(from) {
1087
1273
  return reader.cancel();
1088
1274
  }
1089
1275
  }).pipeThrough(new TextDecoderStream()).pipeThrough(new TransformStream({ transform(chunk, controller) {
1276
+ var _parts$pop;
1090
1277
  lineAggregate += chunk;
1091
1278
  const parts = lineAggregate.split("\n");
1092
- lineAggregate = parts.pop() ?? "";
1279
+ lineAggregate = (_parts$pop = parts.pop()) !== null && _parts$pop !== void 0 ? _parts$pop : "";
1093
1280
  for (const part of parts) controller.enqueue(part);
1094
1281
  } }));
1095
1282
  }
@@ -1204,7 +1391,9 @@ async function jsonlStreamConsumer(opts) {
1204
1391
  const [_chunkId, status, data] = value$1;
1205
1392
  switch (status) {
1206
1393
  case PROMISE_STATUS_FULFILLED: return decode(data);
1207
- case PROMISE_STATUS_REJECTED: throw opts.formatError?.({ error: data }) ?? new AsyncError(data);
1394
+ case PROMISE_STATUS_REJECTED:
1395
+ var _opts$formatError3, _opts$formatError4;
1396
+ throw (_opts$formatError3 = (_opts$formatError4 = opts.formatError) === null || _opts$formatError4 === void 0 ? void 0 : _opts$formatError4.call(opts, { error: data })) !== null && _opts$formatError3 !== void 0 ? _opts$formatError3 : new AsyncError(data);
1208
1397
  }
1209
1398
  } catch (_) {
1210
1399
  _usingCtx3.e = _;
@@ -1212,19 +1401,21 @@ async function jsonlStreamConsumer(opts) {
1212
1401
  _usingCtx3.d();
1213
1402
  }
1214
1403
  });
1215
- case CHUNK_VALUE_TYPE_ASYNC_ITERABLE: return require_utils.run(async function* () {
1404
+ case CHUNK_VALUE_TYPE_ASYNC_ITERABLE: return require_utils.run((0, import_wrapAsyncGenerator$2.default)(function* () {
1216
1405
  try {
1217
1406
  var _usingCtx4 = (0, import_usingCtx$1.default)();
1218
1407
  const reader = _usingCtx4.u(controller.getReaderResource());
1219
1408
  while (true) {
1220
- const { value: value$1 } = await reader.read();
1409
+ const { value: value$1 } = yield (0, import_awaitAsyncGenerator$1.default)(reader.read());
1221
1410
  const [_chunkId, status, data] = value$1;
1222
1411
  switch (status) {
1223
1412
  case ASYNC_ITERABLE_STATUS_YIELD:
1224
1413
  yield decode(data);
1225
1414
  break;
1226
1415
  case ASYNC_ITERABLE_STATUS_RETURN: return decode(data);
1227
- case ASYNC_ITERABLE_STATUS_ERROR: throw opts.formatError?.({ error: data }) ?? new AsyncError(data);
1416
+ case ASYNC_ITERABLE_STATUS_ERROR:
1417
+ var _opts$formatError5, _opts$formatError6;
1418
+ throw (_opts$formatError5 = (_opts$formatError6 = opts.formatError) === null || _opts$formatError6 === void 0 ? void 0 : _opts$formatError6.call(opts, { error: data })) !== null && _opts$formatError5 !== void 0 ? _opts$formatError5 : new AsyncError(data);
1228
1419
  }
1229
1420
  }
1230
1421
  } catch (_) {
@@ -1232,7 +1423,7 @@ async function jsonlStreamConsumer(opts) {
1232
1423
  } finally {
1233
1424
  _usingCtx4.d();
1234
1425
  }
1235
- });
1426
+ }));
1236
1427
  }
1237
1428
  }
1238
1429
  function decode(value) {
@@ -1246,7 +1437,7 @@ async function jsonlStreamConsumer(opts) {
1246
1437
  return data;
1247
1438
  }
1248
1439
  const closeOrAbort = (reason) => {
1249
- headDeferred?.reject(reason);
1440
+ headDeferred === null || headDeferred === void 0 || headDeferred.reject(reason);
1250
1441
  streamManager.cancelAll(reason);
1251
1442
  };
1252
1443
  source.pipeTo(new WritableStream({
@@ -1269,15 +1460,48 @@ async function jsonlStreamConsumer(opts) {
1269
1460
  close: () => closeOrAbort(new Error("Stream closed")),
1270
1461
  abort: closeOrAbort
1271
1462
  }), { signal: opts.abortController.signal }).catch((error) => {
1272
- opts.onError?.({ error });
1463
+ var _opts$onError4;
1464
+ (_opts$onError4 = opts.onError) === null || _opts$onError4 === void 0 || _opts$onError4.call(opts, { error });
1273
1465
  closeOrAbort(error);
1274
1466
  });
1275
1467
  return [await headDeferred.promise, streamManager];
1276
1468
  }
1277
1469
 
1470
+ //#endregion
1471
+ //#region ../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/asyncGeneratorDelegate.js
1472
+ var require_asyncGeneratorDelegate = require_getErrorShape.__commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/asyncGeneratorDelegate.js"(exports, module) {
1473
+ var OverloadYield = require_OverloadYield();
1474
+ function _asyncGeneratorDelegate$1(t) {
1475
+ var e = {}, n = !1;
1476
+ function pump(e$1, r) {
1477
+ return n = !0, r = new Promise(function(n$1) {
1478
+ n$1(t[e$1](r));
1479
+ }), {
1480
+ done: !1,
1481
+ value: new OverloadYield(r, 1)
1482
+ };
1483
+ }
1484
+ return e["undefined" != typeof Symbol && Symbol.iterator || "@@iterator"] = function() {
1485
+ return this;
1486
+ }, e.next = function(t$1) {
1487
+ return n ? (n = !1, t$1) : pump("next", t$1);
1488
+ }, "function" == typeof t["throw"] && (e["throw"] = function(t$1) {
1489
+ if (n) throw n = !1, t$1;
1490
+ return pump("throw", t$1);
1491
+ }), "function" == typeof t["return"] && (e["return"] = function(t$1) {
1492
+ return n ? (n = !1, t$1) : pump("return", t$1);
1493
+ }), e;
1494
+ }
1495
+ module.exports = _asyncGeneratorDelegate$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
1496
+ } });
1497
+
1278
1498
  //#endregion
1279
1499
  //#region src/unstable-core-do-not-import/stream/sse.ts
1280
- var import_usingCtx = __toESM(require_usingCtx(), 1);
1500
+ var import_asyncIterator = require_getErrorShape.__toESM(require_asyncIterator(), 1);
1501
+ var import_awaitAsyncGenerator = require_getErrorShape.__toESM(require_awaitAsyncGenerator(), 1);
1502
+ var import_wrapAsyncGenerator$1 = require_getErrorShape.__toESM(require_wrapAsyncGenerator(), 1);
1503
+ var import_asyncGeneratorDelegate = require_getErrorShape.__toESM(require_asyncGeneratorDelegate(), 1);
1504
+ var import_usingCtx = require_getErrorShape.__toESM(require_usingCtx(), 1);
1281
1505
  const PING_EVENT = "ping";
1282
1506
  const SERIALIZED_ERROR_EVENT = "serialized-error";
1283
1507
  const CONNECTED_EVENT = "connected";
@@ -1287,61 +1511,92 @@ const RETURN_EVENT = "return";
1287
1511
  * @see https://html.spec.whatwg.org/multipage/server-sent-events.html
1288
1512
  */
1289
1513
  function sseStreamProducer(opts) {
1514
+ var _opts$ping$enabled, _opts$ping, _opts$ping$intervalMs, _opts$ping2, _opts$client;
1290
1515
  const { serialize = require_utils.identity } = opts;
1291
1516
  const ping = {
1292
- enabled: opts.ping?.enabled ?? false,
1293
- intervalMs: opts.ping?.intervalMs ?? 1e3
1517
+ enabled: (_opts$ping$enabled = (_opts$ping = opts.ping) === null || _opts$ping === void 0 ? void 0 : _opts$ping.enabled) !== null && _opts$ping$enabled !== void 0 ? _opts$ping$enabled : false,
1518
+ intervalMs: (_opts$ping$intervalMs = (_opts$ping2 = opts.ping) === null || _opts$ping2 === void 0 ? void 0 : _opts$ping2.intervalMs) !== null && _opts$ping$intervalMs !== void 0 ? _opts$ping$intervalMs : 1e3
1294
1519
  };
1295
- const client = opts.client ?? {};
1520
+ const client = (_opts$client = opts.client) !== null && _opts$client !== void 0 ? _opts$client : {};
1296
1521
  if (ping.enabled && client.reconnectAfterInactivityMs && ping.intervalMs > client.reconnectAfterInactivityMs) throw new Error(`Ping interval must be less than client reconnect interval to prevent unnecessary reconnection - ping.intervalMs: ${ping.intervalMs} client.reconnectAfterInactivityMs: ${client.reconnectAfterInactivityMs}`);
1297
- async function* generator() {
1298
- yield {
1299
- event: CONNECTED_EVENT,
1300
- data: JSON.stringify(client)
1301
- };
1302
- let iterable = opts.data;
1303
- if (opts.emitAndEndImmediately) iterable = takeWithGrace(iterable, {
1304
- count: 1,
1305
- gracePeriodMs: 1
1522
+ function generator() {
1523
+ return _generator.apply(this, arguments);
1524
+ }
1525
+ function _generator() {
1526
+ _generator = (0, import_wrapAsyncGenerator$1.default)(function* () {
1527
+ yield {
1528
+ event: CONNECTED_EVENT,
1529
+ data: JSON.stringify(client)
1530
+ };
1531
+ let iterable = opts.data;
1532
+ if (opts.emitAndEndImmediately) iterable = takeWithGrace(iterable, {
1533
+ count: 1,
1534
+ gracePeriodMs: 1
1535
+ });
1536
+ if (opts.maxDurationMs && opts.maxDurationMs > 0 && opts.maxDurationMs !== Infinity) iterable = withMaxDuration(iterable, { maxDurationMs: opts.maxDurationMs });
1537
+ if (ping.enabled && ping.intervalMs !== Infinity && ping.intervalMs > 0) iterable = withPing(iterable, ping.intervalMs);
1538
+ let value;
1539
+ let chunk;
1540
+ var _iteratorAbruptCompletion = false;
1541
+ var _didIteratorError = false;
1542
+ var _iteratorError;
1543
+ try {
1544
+ for (var _iterator = (0, import_asyncIterator.default)(iterable), _step; _iteratorAbruptCompletion = !(_step = yield (0, import_awaitAsyncGenerator.default)(_iterator.next())).done; _iteratorAbruptCompletion = false) {
1545
+ value = _step.value;
1546
+ {
1547
+ if (value === PING_SYM) {
1548
+ yield {
1549
+ event: PING_EVENT,
1550
+ data: ""
1551
+ };
1552
+ continue;
1553
+ }
1554
+ chunk = require_tracked.isTrackedEnvelope(value) ? {
1555
+ id: value[0],
1556
+ data: value[1]
1557
+ } : { data: value };
1558
+ chunk.data = JSON.stringify(serialize(chunk.data));
1559
+ yield chunk;
1560
+ value = null;
1561
+ chunk = null;
1562
+ }
1563
+ }
1564
+ } catch (err) {
1565
+ _didIteratorError = true;
1566
+ _iteratorError = err;
1567
+ } finally {
1568
+ try {
1569
+ if (_iteratorAbruptCompletion && _iterator.return != null) yield (0, import_awaitAsyncGenerator.default)(_iterator.return());
1570
+ } finally {
1571
+ if (_didIteratorError) throw _iteratorError;
1572
+ }
1573
+ }
1306
1574
  });
1307
- if (opts.maxDurationMs && opts.maxDurationMs > 0 && opts.maxDurationMs !== Infinity) iterable = withMaxDuration(iterable, { maxDurationMs: opts.maxDurationMs });
1308
- if (ping.enabled && ping.intervalMs !== Infinity && ping.intervalMs > 0) iterable = withPing(iterable, ping.intervalMs);
1309
- let value;
1310
- let chunk;
1311
- for await (value of iterable) {
1312
- if (value === PING_SYM) {
1575
+ return _generator.apply(this, arguments);
1576
+ }
1577
+ function generatorWithErrorHandling() {
1578
+ return _generatorWithErrorHandling.apply(this, arguments);
1579
+ }
1580
+ function _generatorWithErrorHandling() {
1581
+ _generatorWithErrorHandling = (0, import_wrapAsyncGenerator$1.default)(function* () {
1582
+ try {
1583
+ yield* (0, import_asyncGeneratorDelegate.default)((0, import_asyncIterator.default)(generator()));
1313
1584
  yield {
1314
- event: PING_EVENT,
1585
+ event: RETURN_EVENT,
1315
1586
  data: ""
1316
1587
  };
1317
- continue;
1588
+ } catch (cause) {
1589
+ var _opts$formatError, _opts$formatError2;
1590
+ if (isAbortError(cause)) return;
1591
+ const error = require_tracked.getTRPCErrorFromUnknown(cause);
1592
+ const data = (_opts$formatError = (_opts$formatError2 = opts.formatError) === null || _opts$formatError2 === void 0 ? void 0 : _opts$formatError2.call(opts, { error })) !== null && _opts$formatError !== void 0 ? _opts$formatError : null;
1593
+ yield {
1594
+ event: SERIALIZED_ERROR_EVENT,
1595
+ data: JSON.stringify(serialize(data))
1596
+ };
1318
1597
  }
1319
- chunk = require_tracked.isTrackedEnvelope(value) ? {
1320
- id: value[0],
1321
- data: value[1]
1322
- } : { data: value };
1323
- chunk.data = JSON.stringify(serialize(chunk.data));
1324
- yield chunk;
1325
- value = null;
1326
- chunk = null;
1327
- }
1328
- }
1329
- async function* generatorWithErrorHandling() {
1330
- try {
1331
- yield* generator();
1332
- yield {
1333
- event: RETURN_EVENT,
1334
- data: ""
1335
- };
1336
- } catch (cause) {
1337
- if (isAbortError(cause)) return;
1338
- const error = require_tracked.getTRPCErrorFromUnknown(cause);
1339
- const data = opts.formatError?.({ error }) ?? null;
1340
- yield {
1341
- event: SERIALIZED_ERROR_EVENT,
1342
- data: JSON.stringify(serialize(data))
1343
- };
1344
- }
1598
+ });
1599
+ return _generatorWithErrorHandling.apply(this, arguments);
1345
1600
  }
1346
1601
  const stream = readableStreamFrom(generatorWithErrorHandling());
1347
1602
  return stream.pipeThrough(new TransformStream({ transform(chunk, controller) {
@@ -1434,13 +1689,13 @@ function sseStreamConsumer(opts) {
1434
1689
  try {
1435
1690
  eventSource.close();
1436
1691
  controller.close();
1437
- } catch {}
1692
+ } catch (_unused) {}
1438
1693
  };
1439
1694
  if (signal.aborted) onAbort();
1440
1695
  else signal.addEventListener("abort", onAbort);
1441
1696
  },
1442
1697
  cancel() {
1443
- _es?.close();
1698
+ _es === null || _es === void 0 || _es.close();
1444
1699
  }
1445
1700
  });
1446
1701
  const getStreamResource = () => {
@@ -1461,7 +1716,7 @@ function sseStreamConsumer(opts) {
1461
1716
  }
1462
1717
  }, dispose);
1463
1718
  };
1464
- return require_utils.run(async function* () {
1719
+ return require_utils.run((0, import_wrapAsyncGenerator$1.default)(function* () {
1465
1720
  try {
1466
1721
  var _usingCtx3 = (0, import_usingCtx.default)();
1467
1722
  const stream = _usingCtx3.a(getStreamResource());
@@ -1484,16 +1739,16 @@ function sseStreamConsumer(opts) {
1484
1739
  return res;
1485
1740
  }
1486
1741
  });
1487
- const result = await promise;
1742
+ const result = yield (0, import_awaitAsyncGenerator.default)(promise);
1488
1743
  if (result.done) return result.value;
1489
1744
  yield result.value;
1490
1745
  }
1491
1746
  } catch (_) {
1492
1747
  _usingCtx3.e = _;
1493
1748
  } finally {
1494
- await _usingCtx3.d();
1749
+ yield (0, import_awaitAsyncGenerator.default)(_usingCtx3.d());
1495
1750
  }
1496
- });
1751
+ }));
1497
1752
  }
1498
1753
  const sseHeaders = {
1499
1754
  "Content-Type": "text/event-stream",
@@ -1504,10 +1759,12 @@ const sseHeaders = {
1504
1759
 
1505
1760
  //#endregion
1506
1761
  //#region src/unstable-core-do-not-import/http/resolveResponse.ts
1762
+ var import_wrapAsyncGenerator = require_getErrorShape.__toESM(require_wrapAsyncGenerator(), 1);
1763
+ var import_objectSpread2 = require_getErrorShape.__toESM(require_getErrorShape.require_objectSpread2(), 1);
1507
1764
  function errorToAsyncIterable(err) {
1508
- return require_utils.run(async function* () {
1765
+ return require_utils.run((0, import_wrapAsyncGenerator.default)(function* () {
1509
1766
  throw err;
1510
- });
1767
+ }));
1511
1768
  }
1512
1769
  const TYPE_ACCEPTED_METHOD_MAP = {
1513
1770
  mutation: ["POST"],
@@ -1520,19 +1777,23 @@ const TYPE_ACCEPTED_METHOD_MAP_WITH_METHOD_OVERRIDE = {
1520
1777
  subscription: ["GET", "POST"]
1521
1778
  };
1522
1779
  function initResponse(initOpts) {
1780
+ var _responseMeta, _info$calls$find$proc, _info$calls$find;
1523
1781
  const { ctx, info, responseMeta, untransformedJSON, errors = [], headers } = initOpts;
1524
1782
  let status = untransformedJSON ? require_getErrorShape.getHTTPStatusCode(untransformedJSON) : 200;
1525
1783
  const eagerGeneration = !untransformedJSON;
1526
1784
  const data = eagerGeneration ? [] : Array.isArray(untransformedJSON) ? untransformedJSON : [untransformedJSON];
1527
- const meta = responseMeta?.({
1785
+ const meta = (_responseMeta = responseMeta === null || responseMeta === void 0 ? void 0 : responseMeta({
1528
1786
  ctx,
1529
1787
  info,
1530
- paths: info?.calls.map((call) => call.path),
1788
+ paths: info === null || info === void 0 ? void 0 : info.calls.map((call) => call.path),
1531
1789
  data,
1532
1790
  errors,
1533
1791
  eagerGeneration,
1534
- type: info?.calls.find((call) => call.procedure?._def.type)?.procedure?._def.type ?? "unknown"
1535
- }) ?? {};
1792
+ type: (_info$calls$find$proc = info === null || info === void 0 || (_info$calls$find = info.calls.find((call) => {
1793
+ var _call$procedure;
1794
+ return (_call$procedure = call.procedure) === null || _call$procedure === void 0 ? void 0 : _call$procedure._def.type;
1795
+ })) === null || _info$calls$find === void 0 || (_info$calls$find = _info$calls$find.procedure) === null || _info$calls$find === void 0 ? void 0 : _info$calls$find._def.type) !== null && _info$calls$find$proc !== void 0 ? _info$calls$find$proc : "unknown"
1796
+ })) !== null && _responseMeta !== void 0 ? _responseMeta : {};
1536
1797
  if (meta.headers) {
1537
1798
  if (meta.headers instanceof Headers) for (const [key, value] of meta.headers.entries()) headers.append(key, value);
1538
1799
  else
@@ -1548,7 +1809,7 @@ function initResponse(initOpts) {
1548
1809
  function caughtErrorToData(cause, errorOpts) {
1549
1810
  const { router, req, onError } = errorOpts.opts;
1550
1811
  const error = require_tracked.getTRPCErrorFromUnknown(cause);
1551
- onError?.({
1812
+ onError === null || onError === void 0 || onError({
1552
1813
  error,
1553
1814
  path: errorOpts.path,
1554
1815
  input: errorOpts.input,
@@ -1583,13 +1844,14 @@ function isDataStream(v) {
1583
1844
  return Object.values(v).some(isPromise) || Object.values(v).some(require_utils.isAsyncIterable);
1584
1845
  }
1585
1846
  async function resolveResponse(opts) {
1847
+ var _ref, _opts$allowBatching, _opts$batching, _opts$allowMethodOver, _config$sse$enabled, _config$sse;
1586
1848
  const { router, req } = opts;
1587
1849
  const headers = new Headers([["vary", "trpc-accept"]]);
1588
1850
  const config = router._def._config;
1589
1851
  const url = new URL(req.url);
1590
1852
  if (req.method === "HEAD") return new Response(null, { status: 204 });
1591
- const allowBatching = opts.allowBatching ?? opts.batching?.enabled ?? true;
1592
- const allowMethodOverride = (opts.allowMethodOverride ?? false) && req.method === "POST";
1853
+ const allowBatching = (_ref = (_opts$allowBatching = opts.allowBatching) !== null && _opts$allowBatching !== void 0 ? _opts$allowBatching : (_opts$batching = opts.batching) === null || _opts$batching === void 0 ? void 0 : _opts$batching.enabled) !== null && _ref !== void 0 ? _ref : true;
1854
+ const allowMethodOverride = ((_opts$allowMethodOver = opts.allowMethodOverride) !== null && _opts$allowMethodOver !== void 0 ? _opts$allowMethodOver : false) && req.method === "POST";
1593
1855
  const infoTuple = await require_utils.run(async () => {
1594
1856
  try {
1595
1857
  return [void 0, await getRequestInfo({
@@ -1632,7 +1894,7 @@ async function resolveResponse(opts) {
1632
1894
  * @deprecated
1633
1895
  */
1634
1896
  const isStreamCall = req.headers.get("trpc-accept") === "application/jsonl";
1635
- const experimentalSSE = config.sse?.enabled ?? true;
1897
+ const experimentalSSE = (_config$sse$enabled = (_config$sse = config.sse) === null || _config$sse === void 0 ? void 0 : _config$sse.enabled) !== null && _config$sse$enabled !== void 0 ? _config$sse$enabled : true;
1636
1898
  try {
1637
1899
  const [infoError, info] = infoTuple;
1638
1900
  if (infoError) throw infoError;
@@ -1674,14 +1936,15 @@ async function resolveResponse(opts) {
1674
1936
  });
1675
1937
  return [void 0, { data }];
1676
1938
  } catch (cause) {
1939
+ var _opts$onError, _call$procedure$_def$, _call$procedure2;
1677
1940
  const error = require_tracked.getTRPCErrorFromUnknown(cause);
1678
1941
  const input = call.result();
1679
- opts.onError?.({
1942
+ (_opts$onError = opts.onError) === null || _opts$onError === void 0 || _opts$onError.call(opts, {
1680
1943
  error,
1681
1944
  path: call.path,
1682
1945
  input,
1683
1946
  ctx: ctxManager.valueOrUndefined(),
1684
- type: call.procedure?._def.type ?? "unknown",
1947
+ type: (_call$procedure$_def$ = (_call$procedure2 = call.procedure) === null || _call$procedure2 === void 0 ? void 0 : _call$procedure2._def.type) !== null && _call$procedure$_def$ !== void 0 ? _call$procedure$_def$ : "unknown",
1685
1948
  req: opts.req
1686
1949
  });
1687
1950
  return [error, void 0];
@@ -1695,7 +1958,7 @@ async function resolveResponse(opts) {
1695
1958
  case "mutation":
1696
1959
  case "query": {
1697
1960
  headers.set("content-type", "application/json");
1698
- if (isDataStream(result?.data)) throw new require_tracked.TRPCError({
1961
+ if (isDataStream(result === null || result === void 0 ? void 0 : result.data)) throw new require_tracked.TRPCError({
1699
1962
  code: "UNSUPPORTED_MEDIA_TYPE",
1700
1963
  message: "Cannot use stream-like response in non-streaming request - use httpBatchStreamLink"
1701
1964
  });
@@ -1734,16 +1997,16 @@ async function resolveResponse(opts) {
1734
1997
  const dataAsIterable = require_observable.isObservable(result.data) ? require_observable.observableToAsyncIterable(result.data, opts.req.signal) : result.data;
1735
1998
  return dataAsIterable;
1736
1999
  });
1737
- const stream = sseStreamProducer({
1738
- ...config.sse,
2000
+ const stream = sseStreamProducer((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, config.sse), {}, {
1739
2001
  data: iterable,
1740
2002
  serialize: (v) => config.transformer.output.serialize(v),
1741
2003
  formatError(errorOpts) {
2004
+ var _call$procedure$_def$2, _call$procedure3, _opts$onError2;
1742
2005
  const error$1 = require_tracked.getTRPCErrorFromUnknown(errorOpts.error);
1743
- const input = call?.result();
1744
- const path = call?.path;
1745
- const type = call?.procedure?._def.type ?? "unknown";
1746
- opts.onError?.({
2006
+ const input = call === null || call === void 0 ? void 0 : call.result();
2007
+ const path = call === null || call === void 0 ? void 0 : call.path;
2008
+ const type = (_call$procedure$_def$2 = call === null || call === void 0 || (_call$procedure3 = call.procedure) === null || _call$procedure3 === void 0 ? void 0 : _call$procedure3._def.type) !== null && _call$procedure$_def$2 !== void 0 ? _call$procedure$_def$2 : "unknown";
2009
+ (_opts$onError2 = opts.onError) === null || _opts$onError2 === void 0 || _opts$onError2.call(opts, {
1747
2010
  error: error$1,
1748
2011
  path,
1749
2012
  input,
@@ -1761,7 +2024,7 @@ async function resolveResponse(opts) {
1761
2024
  });
1762
2025
  return shape;
1763
2026
  }
1764
- });
2027
+ }));
1765
2028
  for (const [key, value] of Object.entries(sseHeaders)) headers.set(key, value);
1766
2029
  const headResponse$1 = initResponse({
1767
2030
  ctx: ctxManager.valueOrUndefined(),
@@ -1789,20 +2052,22 @@ async function resolveResponse(opts) {
1789
2052
  headers,
1790
2053
  untransformedJSON: null
1791
2054
  });
1792
- const stream = jsonlStreamProducer({
1793
- ...config.jsonl,
2055
+ const stream = jsonlStreamProducer((0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, config.jsonl), {}, {
1794
2056
  maxDepth: Infinity,
1795
2057
  data: rpcCalls.map(async (res) => {
1796
2058
  const [error, result] = await res;
1797
2059
  const call = info.calls[0];
1798
- if (error) return { error: require_getErrorShape.getErrorShape({
1799
- config,
1800
- ctx: ctxManager.valueOrUndefined(),
1801
- error,
1802
- input: call.result(),
1803
- path: call.path,
1804
- type: call.procedure?._def.type ?? "unknown"
1805
- }) };
2060
+ if (error) {
2061
+ var _procedure$_def$type, _procedure;
2062
+ return { error: require_getErrorShape.getErrorShape({
2063
+ config,
2064
+ ctx: ctxManager.valueOrUndefined(),
2065
+ error,
2066
+ input: call.result(),
2067
+ path: call.path,
2068
+ type: (_procedure$_def$type = (_procedure = call.procedure) === null || _procedure === void 0 ? void 0 : _procedure._def.type) !== null && _procedure$_def$type !== void 0 ? _procedure$_def$type : "unknown"
2069
+ }) };
2070
+ }
1806
2071
  /**
1807
2072
  * Not very pretty, but we need to wrap nested data in promises
1808
2073
  * Our stream producer will only resolve top-level async values or async values that are directly nested in another async value
@@ -1812,21 +2077,23 @@ async function resolveResponse(opts) {
1812
2077
  }),
1813
2078
  serialize: config.transformer.output.serialize,
1814
2079
  onError: (cause) => {
1815
- opts.onError?.({
2080
+ var _opts$onError3, _info$type;
2081
+ (_opts$onError3 = opts.onError) === null || _opts$onError3 === void 0 || _opts$onError3.call(opts, {
1816
2082
  error: require_tracked.getTRPCErrorFromUnknown(cause),
1817
2083
  path: void 0,
1818
2084
  input: void 0,
1819
2085
  ctx: ctxManager.valueOrUndefined(),
1820
2086
  req: opts.req,
1821
- type: info?.type ?? "unknown"
2087
+ type: (_info$type = info === null || info === void 0 ? void 0 : info.type) !== null && _info$type !== void 0 ? _info$type : "unknown"
1822
2088
  });
1823
2089
  },
1824
2090
  formatError(errorOpts) {
1825
- const call = info?.calls[errorOpts.path[0]];
2091
+ var _call$procedure$_def$3, _call$procedure4;
2092
+ const call = info === null || info === void 0 ? void 0 : info.calls[errorOpts.path[0]];
1826
2093
  const error = require_tracked.getTRPCErrorFromUnknown(errorOpts.error);
1827
- const input = call?.result();
1828
- const path = call?.path;
1829
- const type = call?.procedure?._def.type ?? "unknown";
2094
+ const input = call === null || call === void 0 ? void 0 : call.result();
2095
+ const path = call === null || call === void 0 ? void 0 : call.path;
2096
+ const type = (_call$procedure$_def$3 = call === null || call === void 0 || (_call$procedure4 = call.procedure) === null || _call$procedure4 === void 0 ? void 0 : _call$procedure4._def.type) !== null && _call$procedure$_def$3 !== void 0 ? _call$procedure$_def$3 : "unknown";
1830
2097
  const shape = require_getErrorShape.getErrorShape({
1831
2098
  config,
1832
2099
  ctx: ctxManager.valueOrUndefined(),
@@ -1837,7 +2104,7 @@ async function resolveResponse(opts) {
1837
2104
  });
1838
2105
  return shape;
1839
2106
  }
1840
- });
2107
+ }));
1841
2108
  return new Response(stream, {
1842
2109
  headers,
1843
2110
  status: headResponse$1.status
@@ -1861,14 +2128,17 @@ async function resolveResponse(opts) {
1861
2128
  });
1862
2129
  const resultAsRPCResponse = results.map(([error, result], index) => {
1863
2130
  const call = info.calls[index];
1864
- if (error) return { error: require_getErrorShape.getErrorShape({
1865
- config,
1866
- ctx: ctxManager.valueOrUndefined(),
1867
- error,
1868
- input: call.result(),
1869
- path: call.path,
1870
- type: call.procedure?._def.type ?? "unknown"
1871
- }) };
2131
+ if (error) {
2132
+ var _call$procedure$_def$4, _call$procedure5;
2133
+ return { error: require_getErrorShape.getErrorShape({
2134
+ config,
2135
+ ctx: ctxManager.valueOrUndefined(),
2136
+ error,
2137
+ input: call.result(),
2138
+ path: call.path,
2139
+ type: (_call$procedure$_def$4 = (_call$procedure5 = call.procedure) === null || _call$procedure5 === void 0 ? void 0 : _call$procedure5._def.type) !== null && _call$procedure$_def$4 !== void 0 ? _call$procedure$_def$4 : "unknown"
2140
+ }) };
2141
+ }
1872
2142
  return { result: { data: result.data } };
1873
2143
  });
1874
2144
  const errors = results.map(([error]) => error).filter(Boolean);
@@ -1885,12 +2155,13 @@ async function resolveResponse(opts) {
1885
2155
  headers
1886
2156
  });
1887
2157
  } catch (cause) {
2158
+ var _info$type2;
1888
2159
  const [_infoError, info] = infoTuple;
1889
2160
  const ctx = ctxManager.valueOrUndefined();
1890
2161
  const { error, untransformedJSON, body } = caughtErrorToData(cause, {
1891
2162
  opts,
1892
2163
  ctx: ctxManager.valueOrUndefined(),
1893
- type: info?.type ?? "unknown"
2164
+ type: (_info$type2 = info === null || info === void 0 ? void 0 : info.type) !== null && _info$type2 !== void 0 ? _info$type2 : "unknown"
1894
2165
  });
1895
2166
  const headResponse = initResponse({
1896
2167
  ctx,
@@ -1914,18 +2185,6 @@ Object.defineProperty(exports, 'Unpromise', {
1914
2185
  return Unpromise;
1915
2186
  }
1916
2187
  });
1917
- Object.defineProperty(exports, '__commonJS', {
1918
- enumerable: true,
1919
- get: function () {
1920
- return __commonJS;
1921
- }
1922
- });
1923
- Object.defineProperty(exports, '__toESM', {
1924
- enumerable: true,
1925
- get: function () {
1926
- return __toESM;
1927
- }
1928
- });
1929
2188
  Object.defineProperty(exports, 'createDeferred', {
1930
2189
  enumerable: true,
1931
2190
  get: function () {