elysia 2.0.0-beta.5 → 2.0.0-beta.7

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 (50) hide show
  1. package/dist/base.d.ts +26 -9
  2. package/dist/base.js +207 -202
  3. package/dist/base.mjs +207 -202
  4. package/dist/compile/aot-capture.js +1 -1
  5. package/dist/compile/aot-capture.mjs +1 -1
  6. package/dist/compile/aot.d.ts +5 -5
  7. package/dist/compile/handler/index.js +6 -1
  8. package/dist/compile/handler/index.mjs +6 -1
  9. package/dist/compile/handler/jit.js +3 -1
  10. package/dist/compile/handler/jit.mjs +4 -2
  11. package/dist/compile/handler/params.js +1 -0
  12. package/dist/compile/handler/params.mjs +2 -1
  13. package/dist/compile/handler/utils.d.ts +2 -1
  14. package/dist/compile/handler/utils.js +8 -0
  15. package/dist/compile/handler/utils.mjs +8 -1
  16. package/dist/error.d.ts +2 -1
  17. package/dist/error.js +62 -3
  18. package/dist/error.mjs +62 -4
  19. package/dist/package.js +1 -1
  20. package/dist/package.mjs +1 -1
  21. package/dist/plugin/aot/core.d.ts +15 -36
  22. package/dist/plugin/aot/core.js +21 -39
  23. package/dist/plugin/aot/core.mjs +22 -41
  24. package/dist/type/bridge-live.d.ts +1 -1
  25. package/dist/type/bridge-live.js +1 -1
  26. package/dist/type/bridge-live.mjs +1 -1
  27. package/dist/type/bridge.d.ts +3 -3
  28. package/dist/type/coerce-plan.d.ts +1 -1
  29. package/dist/type/coerce-plan.js +1 -0
  30. package/dist/type/coerce-plan.mjs +1 -0
  31. package/dist/type/coerce.d.ts +2 -2
  32. package/dist/type/coerce.js +1 -1
  33. package/dist/type/coerce.mjs +2 -2
  34. package/dist/type/constants.d.ts +1 -1
  35. package/dist/type/typebox-value-live.d.ts +2 -2
  36. package/dist/type/typebox-value-live.js +2 -2
  37. package/dist/type/typebox-value-live.mjs +2 -2
  38. package/dist/type/typebox-value.d.ts +6 -6
  39. package/dist/type/validator/default-precompute.d.ts +9 -1
  40. package/dist/type/validator/default-precompute.js +14 -2
  41. package/dist/type/validator/default-precompute.mjs +14 -3
  42. package/dist/type/validator/exact-mirror-live.d.ts +8 -0
  43. package/dist/type/validator/exact-mirror-live.js +22 -0
  44. package/dist/type/validator/exact-mirror-live.mjs +17 -0
  45. package/dist/type/validator/index.d.ts +1 -1
  46. package/dist/type/validator/index.js +12 -1
  47. package/dist/type/validator/index.mjs +13 -2
  48. package/dist/type/validator/validator-cache.d.ts +1 -1
  49. package/dist/types.d.ts +11 -7
  50. package/package.json +1 -1
package/dist/base.js CHANGED
@@ -61,25 +61,13 @@ const expandPaths = (path, needsEncode, registerLoose, explicit) => {
61
61
  return paths;
62
62
  };
63
63
  var Elysia = class Elysia {
64
- #hasPlugin;
65
- #hasGlobal;
66
- #ready;
67
- #pending = 0;
68
- #error;
69
- #hash;
70
- #childrenHash;
71
- #scopeParent;
72
- #pluginMacros;
73
- #macroBaseline;
74
- #declaredRoutes;
75
- #routeSources;
76
64
  get history() {
77
- if (this.#declaredRoutes === void 0 && this["~routeTable"]?.length) this.#materializeDeclaredRoutes();
78
- if (!this.#declaredRoutes?.length) return emptyHistory;
79
- const history = new Array(this.#declaredRoutes.length);
80
- for (let sequence = 0; sequence < this.#declaredRoutes.length; sequence++) {
81
- const route = this.#declaredRoutes[sequence];
82
- const source = this.#routeSources?.[sequence];
65
+ if (this.declaredRoutes === void 0 && this["~routeTable"]?.length) this.#materializeDeclaredRoutes();
66
+ if (!this.declaredRoutes?.length) return emptyHistory;
67
+ const history = new Array(this.declaredRoutes.length);
68
+ for (let sequence = 0; sequence < this.declaredRoutes.length; sequence++) {
69
+ const route = this.declaredRoutes[sequence];
70
+ const source = this.routeSources?.[sequence];
83
71
  history[sequence] = Object.freeze({
84
72
  sequence,
85
73
  method: route[0],
@@ -90,9 +78,9 @@ var Elysia = class Elysia {
90
78
  return Object.freeze(history);
91
79
  }
92
80
  get ["~routes"]() {
93
- if (this.#declaredRoutes === void 0 && this["~routeTable"]?.length) this.#materializeDeclaredRoutes();
94
- if (!this.#declaredRoutes?.length) return [];
95
- const routes = this.#declaredRoutes;
81
+ if (this.declaredRoutes === void 0 && this["~routeTable"]?.length) this.#materializeDeclaredRoutes();
82
+ if (!this.declaredRoutes?.length) return [];
83
+ const routes = this.declaredRoutes;
96
84
  if (!this["~ext"]?.macro && !this["~scopeChildren"]) return routes;
97
85
  return routes.map((r) => {
98
86
  const localHook = r[4];
@@ -115,16 +103,12 @@ var Elysia = class Elysia {
115
103
  this.#registerRoute(route);
116
104
  return this;
117
105
  }
118
- #compiled;
119
- #jitColdRemaining;
120
- #jitTable;
121
- #jitRoute;
122
- #jitStatic;
123
- #jitAliases;
124
106
  get ["~programId"]() {
125
107
  return this;
126
108
  }
127
109
  constructor(config) {
110
+ this._pending = 0;
111
+ this.routerBuilt = false;
128
112
  /**
129
113
  * ! Don't tune
130
114
  *
@@ -170,13 +154,13 @@ var Elysia = class Elysia {
170
154
  if (config) {
171
155
  const { prefix, name, seed, adapter } = config;
172
156
  this["~Prefix"] = prefix ? prefix.charCodeAt(0) === 47 ? prefix : `/${prefix}` : void 0;
173
- if (name) this.#hash = require_utils.fnv1a(seed ? `${name}_${typeof seed === "object" ? JSON.stringify(seed, require_utils.serializeMacroSeed) : seed}` : name);
157
+ if (name) this.hash = require_utils.fnv1a(seed ? `${name}_${typeof seed === "object" ? JSON.stringify(seed, require_utils.serializeMacroSeed) : seed}` : name);
174
158
  if (adapter?.setup) this.#useFn(adapter.setup);
175
159
  } else this["~Prefix"] = void 0;
176
160
  }
177
161
  get routes() {
178
- if (this.#declaredRoutes === void 0 && this["~routeTable"]?.length) this.#materializeDeclaredRoutes();
179
- if (!this.#declaredRoutes?.length) return [];
162
+ if (this.declaredRoutes === void 0 && this["~routeTable"]?.length) this.#materializeDeclaredRoutes();
163
+ if (!this.declaredRoutes?.length) return [];
180
164
  return this["~routes"].map(([method, path, handler, instance, hook, appHook, inheritedChain, macroScope]) => {
181
165
  const merged = require_compile_handler_index.composeRouteHook(instance, hook, appHook, inheritedChain, this, macroScope);
182
166
  if (merged?.schemas?.length) for (const entry of merged.schemas) {
@@ -204,7 +188,7 @@ var Elysia = class Elysia {
204
188
  }
205
189
  #setField(field, as, name, value) {
206
190
  if (this["~generation"] !== void 0) this.#assertMutable(field === "store" ? "state" : "decorate");
207
- const ext = this.#ext;
191
+ const ext = this.ext;
208
192
  const fresh = !ext[field];
209
193
  const target = ext[field] ??= require_utils.nullObject();
210
194
  switch (typeof value) {
@@ -248,7 +232,7 @@ var Elysia = class Elysia {
248
232
  }
249
233
  headers(headers) {
250
234
  this.#assertMutable("headers");
251
- const ext = this.#ext;
235
+ const ext = this.ext;
252
236
  if (ext.headers) Object.assign(ext.headers, headers);
253
237
  else ext.headers = Object.assign(require_utils.nullObject(), headers);
254
238
  return this;
@@ -266,11 +250,11 @@ var Elysia = class Elysia {
266
250
  scope,
267
251
  owner: this
268
252
  };
269
- if (scope === "plugin") this.#hasPlugin = true;
270
- else if (scope === "global") this.#hasGlobal = true;
271
- if (this.#hash !== void 0) {
253
+ if (scope === "plugin") this.hasPlugin = true;
254
+ else if (scope === "global") this.hasGlobal = true;
255
+ if (this.hash !== void 0) {
272
256
  const tag = (f) => {
273
- if (typeof f === "function" && !require_utils.fnOrigin.has(f)) require_utils.fnOrigin.set(f, this.#hash);
257
+ if (typeof f === "function" && !require_utils.fnOrigin.has(f)) require_utils.fnOrigin.set(f, this.hash);
274
258
  };
275
259
  if (Array.isArray(fn)) for (const f of fn) tag(f);
276
260
  else tag(fn);
@@ -292,7 +276,7 @@ var Elysia = class Elysia {
292
276
  }
293
277
  parser(name, fn) {
294
278
  this.#assertMutable("parser");
295
- const ext = this.#ext;
279
+ const ext = this.ext;
296
280
  const parsers = ext.parser ??= require_utils.nullObject();
297
281
  parsers[name] = fn;
298
282
  return this;
@@ -313,7 +297,7 @@ var Elysia = class Elysia {
313
297
  */
314
298
  setup(handler) {
315
299
  this.#assertMutable("setup");
316
- const arr = this.#ext.setup ??= [];
300
+ const arr = this.ext.setup ??= [];
317
301
  if (Array.isArray(handler)) arr.push(...handler);
318
302
  else arr.push(handler);
319
303
  return this;
@@ -360,20 +344,20 @@ var Elysia = class Elysia {
360
344
  switch (arguments.length) {
361
345
  case 1:
362
346
  if (scopeOrFnOrError && typeof scopeOrFnOrError === "object") {
363
- for (const [code, ErrorClass] of Object.entries(scopeOrFnOrError)) if (typeof ErrorClass === "function") (this.#ext.error ??= /* @__PURE__ */ new Map()).set(ErrorClass, code);
347
+ for (const [code, ErrorClass] of Object.entries(scopeOrFnOrError)) if (typeof ErrorClass === "function") (this.ext.error ??= /* @__PURE__ */ new Map()).set(ErrorClass, code);
364
348
  return this;
365
349
  }
366
350
  return this.#onBranch("error", scopeOrFnOrError);
367
351
  case 2:
368
352
  if (typeof scopeOrFnOrError === "function" && (scopeOrFnOrError === Error || scopeOrFnOrError.prototype instanceof Error)) {
369
353
  const run = typeof fnOrError === "function" ? fnOrError : () => fnOrError;
370
- (this.#ext.error ??= /* @__PURE__ */ new Map()).set(scopeOrFnOrError, scopeOrFnOrError.name);
354
+ (this.ext.error ??= /* @__PURE__ */ new Map()).set(scopeOrFnOrError, scopeOrFnOrError.name);
371
355
  return this.#onBranch("error", require_utils.createErrorEventHandler(run, scopeOrFnOrError));
372
356
  }
373
357
  return this.#onBranch("error", scopeOrFnOrError, fnOrError);
374
358
  case 3: {
375
359
  const run = typeof fn === "function" ? fn : () => fn;
376
- (this.#ext.error ??= /* @__PURE__ */ new Map()).set(fnOrError, fnOrError.name);
360
+ (this.ext.error ??= /* @__PURE__ */ new Map()).set(fnOrError, fnOrError.name);
377
361
  return this.#onBranch("error", scopeOrFnOrError, require_utils.createErrorEventHandler(run, fnOrError));
378
362
  }
379
363
  }
@@ -403,8 +387,8 @@ var Elysia = class Elysia {
403
387
  const fns = Array.isArray(v) ? v : [v];
404
388
  for (const fn of fns) {
405
389
  if (typeof fn !== "function") continue;
406
- if (scope === "plugin") this.#hasPlugin = true;
407
- else this.#hasGlobal = true;
390
+ if (scope === "plugin") this.hasPlugin = true;
391
+ else this.hasGlobal = true;
408
392
  }
409
393
  }
410
394
  }
@@ -412,6 +396,8 @@ var Elysia = class Elysia {
412
396
  }
413
397
  }
414
398
  guard() {
399
+ const maybeHook = typeof arguments[0] === "string" ? arguments[1] : arguments[0];
400
+ if (maybeHook && typeof maybeHook === "object" && "as" in maybeHook && maybeHook.as !== void 0) throw new Error(`[elysia] guard({ as: '${maybeHook.as}' }) was removed in 2.0. Pass the scope as the first argument instead: guard('${maybeHook.as === "scoped" ? "plugin" : maybeHook.as}', { ... }). To combine a guard schema with a route's own schema for the same slot, add schema: 'merge'.`);
415
401
  if (arguments.length === 1) return this.#guard("local", arguments[0]);
416
402
  if (arguments.length === 2) {
417
403
  if (typeof arguments[1] === "function") return this.group("", arguments[0], arguments[1]);
@@ -424,7 +410,7 @@ var Elysia = class Elysia {
424
410
  require_utils.hookToGuard(hook);
425
411
  const trackFn = (fn) => {
426
412
  if (typeof fn !== "function") return;
427
- if (this.#hash !== void 0 && !require_utils.fnOrigin.has(fn)) require_utils.fnOrigin.set(fn, this.#hash);
413
+ if (this.hash !== void 0 && !require_utils.fnOrigin.has(fn)) require_utils.fnOrigin.set(fn, this.hash);
428
414
  };
429
415
  for (const key in hook) {
430
416
  if (!require_utils.eventProperties.has(key)) continue;
@@ -453,7 +439,7 @@ var Elysia = class Elysia {
453
439
  prefix
454
440
  } : void 0);
455
441
  child["~scopeChild"] = true;
456
- child.#scopeParent = this;
442
+ child.scopeParent = this;
457
443
  (this["~scopeChildren"] ??= []).push(child);
458
444
  const src = this["~ext"];
459
445
  if (src) {
@@ -476,7 +462,7 @@ var Elysia = class Elysia {
476
462
  this.#use(child);
477
463
  return this;
478
464
  }
479
- get #ext() {
465
+ get ext() {
480
466
  return this["~ext"] ??= require_utils.nullObject();
481
467
  }
482
468
  ["~resolvedCapability"](kind) {
@@ -495,9 +481,9 @@ var Elysia = class Elysia {
495
481
  return provider;
496
482
  }
497
483
  #ensureMacroTable() {
498
- const ext = this.#ext;
484
+ const ext = this.ext;
499
485
  if (ext.macro) return ext.macro;
500
- const parent = this["~scopeChild"] ? this.#scopeParent : void 0;
486
+ const parent = this["~scopeChild"] ? this.scopeParent : void 0;
501
487
  ext.macro = parent ? Object.create(parent.#ensureMacroTable()) : require_utils.nullObject();
502
488
  return ext.macro;
503
489
  }
@@ -536,10 +522,10 @@ var Elysia = class Elysia {
536
522
  this.#assertMutable("macro");
537
523
  if (typeof macro === "function") throw new Error("use `.macro({ name: fn })` instead of `.macro(fn)`");
538
524
  const m = this.#ensureMacroTable();
539
- const baseline = this.#macroBaseline;
525
+ const baseline = this.macroBaseline;
540
526
  for (const key in macro) {
541
527
  if (typeof macro[key] === "object") macro[key] = require_utils.hookToGuard(macro[key]);
542
- if (this.#hash !== void 0 && !require_utils.macroOrigin.has(macro[key])) require_utils.macroOrigin.set(macro[key], this.#hash);
528
+ if (this.hash !== void 0 && !require_utils.macroOrigin.has(macro[key])) require_utils.macroOrigin.set(macro[key], this.hash);
543
529
  if (baseline?.has(key) && key in m && m[key] !== macro[key]) throw new Error(`[Elysia] Macro "${key}" can be only define once`);
544
530
  }
545
531
  Object.assign(m, macro);
@@ -577,9 +563,7 @@ var Elysia = class Elysia {
577
563
  }
578
564
  for (const k in hook) {
579
565
  const v = hook[k];
580
- if (k === "seed") continue;
581
- if (k === "meta") continue;
582
- if (k === "$type") continue;
566
+ if (k === "seed" || k === "meta" || k === "$type") continue;
583
567
  if (k === "introspect") {
584
568
  v?.(input);
585
569
  delete input[key];
@@ -654,21 +638,37 @@ var Elysia = class Elysia {
654
638
  return this;
655
639
  }
656
640
  #useFn(app) {
657
- const prevBaseline = this.#macroBaseline;
641
+ const prevBaseline = this.macroBaseline;
658
642
  const baseline = /* @__PURE__ */ new Set();
659
643
  const existingMacro = this["~ext"]?.macro;
660
644
  if (existingMacro) for (const k in existingMacro) baseline.add(k);
661
- this.#macroBaseline = baseline;
645
+ this.macroBaseline = baseline;
646
+ let wantSnapshot = false;
647
+ let settled = false;
648
+ let beforeMacro;
649
+ queueMicrotask(() => {
650
+ if (wantSnapshot && !settled) {
651
+ beforeMacro = new Map(Object.entries(this["~ext"]?.macro ?? require_utils.nullObject()));
652
+ (this.macroSnapshots ??= /* @__PURE__ */ new Set()).add(beforeMacro);
653
+ }
654
+ });
662
655
  const result = app(this);
663
- this.#macroBaseline = prevBaseline;
656
+ this.macroBaseline = prevBaseline;
664
657
  if (result && typeof result.then === "function") {
665
- const beforeMacro = new Map(Object.entries(this["~ext"]?.macro ?? require_utils.nullObject()));
666
- return this.#useAsync(result.then((value) => {
658
+ wantSnapshot = true;
659
+ return this.#useAsync(Promise.resolve(result).then((value) => {
660
+ settled = true;
661
+ if (!beforeMacro) return value;
662
+ this.macroSnapshots?.delete(beforeMacro);
667
663
  const after = this["~ext"]?.macro;
668
664
  if (after) {
669
665
  for (const [k, def] of Object.entries(after)) if (beforeMacro.get(k) !== def) throw new Error(`Macro ${k} can only run in sync plugin`);
670
666
  }
671
667
  return value;
668
+ }, (err) => {
669
+ settled = true;
670
+ if (beforeMacro) this.macroSnapshots?.delete(beforeMacro);
671
+ throw err;
672
672
  }));
673
673
  }
674
674
  return this;
@@ -679,17 +679,17 @@ var Elysia = class Elysia {
679
679
  if (app["~introspect"] || config?.introspect) this["~introspect"] = true;
680
680
  const name = config?.name;
681
681
  if (name) {
682
- const hash = app.#hash;
683
- if (this.#childrenHash?.has(hash)) return;
684
- this.#childrenHash ??= /* @__PURE__ */ new Set();
685
- this.#childrenHash.add(hash);
682
+ const hash = app.hash;
683
+ if (this.childrenHash?.has(hash)) return;
684
+ this.childrenHash ??= /* @__PURE__ */ new Set();
685
+ this.childrenHash.add(hash);
686
686
  (addedByThisCall ??= /* @__PURE__ */ new Set()).add(hash);
687
687
  }
688
- if (app.#childrenHash) addedByThisCall = this.#absorbChildrenHash(app, addedByThisCall);
688
+ if (app.childrenHash) addedByThisCall = this.#absorbChildrenHash(app, addedByThisCall);
689
689
  if (app["~ext"]) this.#assertMacroUnique(app, addedByThisCall);
690
690
  if (app["~hasTrace"]) this["~hasTrace"] = true;
691
- if (app.#declaredRoutes === void 0 && app["~routeTable"]?.length) app.#materializeDeclaredRoutes();
692
- if (app.#declaredRoutes?.length) {
691
+ if (app.declaredRoutes === void 0 && app["~routeTable"]?.length) app.#materializeDeclaredRoutes();
692
+ if (app.declaredRoutes?.length) {
693
693
  if (app["~hasWS"]) this["~hasWS"] = true;
694
694
  this.#emitChildRoutes(app, this["~hookChain"], name);
695
695
  }
@@ -699,17 +699,17 @@ var Elysia = class Elysia {
699
699
  }
700
700
  const hookChain = app["~hookChain"];
701
701
  if (app["~ext"]) this.#absorbExt(app);
702
- if (app.#hasPlugin || app.#hasGlobal || hookChain) this.#propagateHooks(app, hookChain, addedByThisCall);
702
+ if (app.hasPlugin || app.hasGlobal || hookChain) this.#propagateHooks(app, hookChain, addedByThisCall);
703
703
  }
704
704
  #absorbChildrenHash(app, addedByThisCall) {
705
- const incoming = app.#childrenHash;
706
- if (this.#childrenHash) for (const h of incoming) {
707
- if (this.#childrenHash.has(h)) continue;
708
- this.#childrenHash.add(h);
705
+ const incoming = app.childrenHash;
706
+ if (this.childrenHash) for (const h of incoming) {
707
+ if (this.childrenHash.has(h)) continue;
708
+ this.childrenHash.add(h);
709
709
  (addedByThisCall ??= /* @__PURE__ */ new Set()).add(h);
710
710
  }
711
711
  else {
712
- this.#childrenHash = new Set(incoming);
712
+ this.childrenHash = new Set(incoming);
713
713
  addedByThisCall = new Set(incoming);
714
714
  }
715
715
  return addedByThisCall;
@@ -728,7 +728,7 @@ var Elysia = class Elysia {
728
728
  if (existing === incoming) continue;
729
729
  const origin = require_utils.macroOrigin.get(existing);
730
730
  if (origin !== void 0 && origin === require_utils.macroOrigin.get(incoming)) continue;
731
- if (addedByThisCall) for (const h of addedByThisCall) this.#childrenHash.delete(h);
731
+ if (addedByThisCall) for (const h of addedByThisCall) this.childrenHash.delete(h);
732
732
  throw new Error(`[Elysia] Macro "${macroName}" can be only define once`);
733
733
  }
734
734
  }
@@ -754,21 +754,21 @@ var Elysia = class Elysia {
754
754
  if (parser) if (ext.parser) Object.assign(ext.parser, parser);
755
755
  else ext.parser = Object.assign(require_utils.nullObject(), parser);
756
756
  if (macro) if (app["~scopeChild"]) {
757
- const pluginMacros = app.#pluginMacros;
757
+ const pluginMacros = app.pluginMacros;
758
758
  let changed = false;
759
759
  if (pluginMacros?.size) {
760
760
  const target = this.#ensureMacroTable();
761
761
  for (const [name, def] of pluginMacros) if (!(name in target)) {
762
762
  target[name] = def;
763
763
  changed = true;
764
- if (this["~scopeChild"]) (this.#pluginMacros ??= /* @__PURE__ */ new Map()).set(name, def);
764
+ if (this["~scopeChild"]) (this.pluginMacros ??= /* @__PURE__ */ new Map()).set(name, def);
765
765
  }
766
766
  }
767
767
  if (changed) require_utils.invalidateMacroEpoch();
768
768
  } else {
769
769
  Object.assign(this.#ensureMacroTable(), macro);
770
770
  if (this["~scopeChild"]) {
771
- const pluginMacros = this.#pluginMacros ??= /* @__PURE__ */ new Map();
771
+ const pluginMacros = this.pluginMacros ??= /* @__PURE__ */ new Map();
772
772
  for (const name in macro) pluginMacros.set(name, macro[name]);
773
773
  }
774
774
  require_utils.invalidateMacroEpoch();
@@ -829,7 +829,7 @@ var Elysia = class Elysia {
829
829
  let globalEvents;
830
830
  let pluginMayRef = false;
831
831
  let globalMayRef = false;
832
- if (app.#hasGlobal) this.#hasGlobal = true;
832
+ if (app.hasGlobal) this.hasGlobal = true;
833
833
  const nodes = useNodesBuffer;
834
834
  nodes.length = 0;
835
835
  let current = hookChain;
@@ -859,7 +859,7 @@ var Elysia = class Elysia {
859
859
  else pluginMayRef = true;
860
860
  for (const s of schemas) {
861
861
  (target.schemas ??= []).push(s);
862
- if (isGlobal) this.#hasGlobal = true;
862
+ if (isGlobal) this.hasGlobal = true;
863
863
  }
864
864
  continue;
865
865
  }
@@ -870,13 +870,13 @@ var Elysia = class Elysia {
870
870
  const count = many ? raw.length : 1;
871
871
  for (let f = 0; f < count; f++) {
872
872
  const fn = many ? raw[f] : raw;
873
- const childrenHash = this.#childrenHash;
873
+ const childrenHash = this.childrenHash;
874
874
  if (childrenHash !== void 0) {
875
875
  const origin = require_utils.fnOrigin.get(fn);
876
876
  if (origin !== void 0 && childrenHash.has(origin) && !addedByThisCall?.has(origin)) continue;
877
877
  }
878
878
  require_utils.pushField(isGlobal ? globalEvents ??= require_utils.nullObject() : pluginEvents ??= require_utils.nullObject(), key, fn);
879
- if (isGlobal) this.#hasGlobal = true;
879
+ if (isGlobal) this.hasGlobal = true;
880
880
  }
881
881
  continue;
882
882
  }
@@ -919,7 +919,7 @@ var Elysia = class Elysia {
919
919
  }
920
920
  }
921
921
  #emitChildRoutes(app, preChain, name) {
922
- const declared = app.#declaredRoutes;
922
+ const declared = app.declaredRoutes;
923
923
  if (!declared?.length) return;
924
924
  const limit = declared.length;
925
925
  let lastChildChain;
@@ -957,55 +957,69 @@ var Elysia = class Elysia {
957
957
  ], source);
958
958
  }
959
959
  get modules() {
960
- const ready = this.#ready;
960
+ const ready = this.ready;
961
961
  if (!ready) {
962
- if (this.#error !== void 0) return Promise.reject(this.#error.error);
962
+ if (this._error !== void 0) return Promise.reject(this._error.error);
963
963
  return Promise.resolve();
964
964
  }
965
965
  return ready.then(() => {
966
- if (this.#error !== void 0) throw this.#error.error;
967
- if (this.#ready && this.#ready !== ready) return this.modules;
966
+ if (this._error !== void 0) throw this._error.error;
967
+ if (this.ready && this.ready !== ready) return this.modules;
968
968
  });
969
969
  }
970
970
  get pending() {
971
- return this.#pending > 0;
971
+ return this._pending > 0;
972
972
  }
973
973
  #useAsync(promise) {
974
- if (!this.#ready) this.#error = void 0;
975
- this.#pending++;
976
- const next = (this.#ready ?? Promise.resolve()).then(() => promise).then((value) => {
974
+ if (!this.ready) this._error = void 0;
975
+ this._pending++;
976
+ const next = (this.ready ?? Promise.resolve()).then(() => promise).then((value) => {
977
977
  const plugin = value && typeof value === "object" && "default" in value && value.default ? value.default : value;
978
+ const snapshots = this.macroSnapshots;
979
+ let before;
980
+ if (snapshots?.size) {
981
+ const macro = this["~ext"]?.macro;
982
+ before = macro ? new Map(Object.entries(macro)) : /* @__PURE__ */ new Map();
983
+ }
978
984
  if (plugin) try {
979
985
  this.use(plugin);
980
986
  } catch (err) {
981
- this.#error ??= { error: err };
987
+ this._error ??= { error: err };
982
988
  console.error(err);
983
989
  }
990
+ if (before) {
991
+ const after = this["~ext"]?.macro;
992
+ if (after) {
993
+ for (const [k, def] of Object.entries(after)) if (before.get(k) !== def) {
994
+ for (const snap of snapshots) if (snap.has(k) === before.has(k) && snap.get(k) === before.get(k)) snap.set(k, def);
995
+ }
996
+ }
997
+ }
984
998
  }).finally(() => {
985
- this.#pending--;
999
+ this._pending--;
986
1000
  }).then(() => {}, (err) => {
987
- this.#error ??= { error: err };
1001
+ this._error ??= { error: err };
988
1002
  console.error(err);
989
1003
  }).finally(() => this.#tryDrain(next));
990
- this.#ready = next;
1004
+ this.ready = next;
991
1005
  return this;
992
1006
  }
993
1007
  #tryDrain(sentinel) {
994
- if (this.#pending > 0) return;
995
- if (this.#ready !== sentinel) return;
996
- const previousCompiled = this.#compiled;
997
- const previousJitColdRemaining = this.#jitColdRemaining;
998
- this.#ready = void 0;
999
- this.#compiled = void 0;
1000
- this.#fetchFn = void 0;
1001
- this.#routerBuilt = false;
1008
+ if (this._pending > 0) return;
1009
+ if (this.ready !== sentinel) return;
1010
+ const previousCompiled = this.compiled;
1011
+ const previousJitColdRemaining = this.jitColdRemaining;
1012
+ this.ready = void 0;
1013
+ this.compiled = void 0;
1014
+ this.fetchFn = void 0;
1015
+ this.routerBuilt = false;
1002
1016
  require_context.clearContextCache(this);
1003
1017
  try {
1004
1018
  this.#buildRouter(false);
1005
1019
  } catch (error) {
1006
- this.#compiled = previousCompiled;
1007
- this.#jitColdRemaining = previousJitColdRemaining;
1008
- this.#error ??= { error };
1020
+ this.compiled = previousCompiled;
1021
+ this.jitColdRemaining = previousJitColdRemaining;
1022
+ this._error ??= { error };
1009
1023
  }
1010
1024
  }
1011
1025
  #add(method, path, hookOrFn, fn, hasHook = fn !== void 0) {
@@ -1015,7 +1029,7 @@ var Elysia = class Elysia {
1015
1029
  const hook = hasHook ? require_schema_snapshot.snapshotHookSchemas(hookOrFn) : void 0;
1016
1030
  const appHook = this["~hookChain"];
1017
1031
  if (this["~generation"] !== void 0) this.#assertMutable("route");
1018
- (this.#declaredRoutes ?? this.#materializeDeclaredRoutes()).push(appHook ? [
1032
+ (this.declaredRoutes ?? this.#materializeDeclaredRoutes()).push(appHook ? [
1019
1033
  method,
1020
1034
  path,
1021
1035
  handler,
@@ -1034,15 +1048,15 @@ var Elysia = class Elysia {
1034
1048
  handler,
1035
1049
  this
1036
1050
  ]);
1037
- if (this.#routerBuilt || this.#compiled !== void 0) {
1038
- this.#compiled = void 0;
1039
- this.#jitColdRemaining = void 0;
1040
- this.#jitTable = void 0;
1041
- this.#jitRoute = void 0;
1042
- this.#jitStatic = void 0;
1043
- this.#jitAliases = void 0;
1044
- this.#fetchFn = void 0;
1045
- this.#routerBuilt = false;
1051
+ if (this.routerBuilt || this.compiled !== void 0) {
1052
+ this.compiled = void 0;
1053
+ this.jitColdRemaining = void 0;
1054
+ this.jitTable = void 0;
1055
+ this.jitRoute = void 0;
1056
+ this.jitStatic = void 0;
1057
+ this.jitAliases = void 0;
1058
+ this.fetchFn = void 0;
1059
+ this.routerBuilt = false;
1046
1060
  }
1047
1061
  return this;
1048
1062
  }
@@ -1051,33 +1065,33 @@ var Elysia = class Elysia {
1051
1065
  throw new Error(`[Elysia] .${api}() called after the app was sealed`);
1052
1066
  }
1053
1067
  #materializeDeclaredRoutes() {
1054
- if (this.#declaredRoutes !== void 0) return this.#declaredRoutes;
1068
+ if (this.declaredRoutes !== void 0) return this.declaredRoutes;
1055
1069
  const table = this["~routeTable"];
1056
- if (!table) return this.#declaredRoutes = [];
1070
+ if (!table) return this.declaredRoutes = [];
1057
1071
  const routes = new Array(table.length);
1058
1072
  for (let i = 0; i < table.length; i++) routes[i] = require_route_table.routeRow(table, i);
1059
- return this.#declaredRoutes = routes;
1073
+ return this.declaredRoutes = routes;
1060
1074
  }
1061
1075
  #registerRoute(route, source) {
1062
1076
  if (this["~generation"] !== void 0) this.#assertMutable("route");
1063
- const routes = this.#declaredRoutes ?? this.#materializeDeclaredRoutes();
1077
+ const routes = this.declaredRoutes ?? this.#materializeDeclaredRoutes();
1064
1078
  const sequence = routes.length;
1065
1079
  routes.push(route);
1066
- if (source) (this.#routeSources ??= [])[sequence] = source;
1067
- if (this.#routerBuilt || this.#compiled !== void 0) {
1068
- this.#compiled = void 0;
1069
- this.#jitColdRemaining = void 0;
1070
- this.#jitTable = void 0;
1071
- this.#jitRoute = void 0;
1072
- this.#jitStatic = void 0;
1073
- this.#jitAliases = void 0;
1074
- this.#fetchFn = void 0;
1075
- this.#routerBuilt = false;
1080
+ if (source) (this.routeSources ??= [])[sequence] = source;
1081
+ if (this.routerBuilt || this.compiled !== void 0) {
1082
+ this.compiled = void 0;
1083
+ this.jitColdRemaining = void 0;
1084
+ this.jitTable = void 0;
1085
+ this.jitRoute = void 0;
1086
+ this.jitStatic = void 0;
1087
+ this.jitAliases = void 0;
1088
+ this.fetchFn = void 0;
1089
+ this.routerBuilt = false;
1076
1090
  }
1077
1091
  }
1078
1092
  model(name, model) {
1079
1093
  this.#assertMutable("model");
1080
- const models = this.#ext.models ??= require_utils.nullObject();
1094
+ const models = this.ext.models ??= require_utils.nullObject();
1081
1095
  switch (typeof name) {
1082
1096
  case "object":
1083
1097
  const entries = Object.entries(name);
@@ -1103,7 +1117,7 @@ var Elysia = class Elysia {
1103
1117
  next[key] = value;
1104
1118
  }
1105
1119
  }
1106
- this.#ext.models = next;
1120
+ this.ext.models = next;
1107
1121
  return this;
1108
1122
  }
1109
1123
  case "string":
@@ -1213,21 +1227,21 @@ var Elysia = class Elysia {
1213
1227
  compile() {
1214
1228
  this["~config"] ??= require_utils.nullObject();
1215
1229
  this["~config"].precompile = true;
1216
- this.#routerBuilt = false;
1217
- this.#compiled = void 0;
1218
- this.#jitColdRemaining = void 0;
1219
- this.#jitTable = void 0;
1220
- this.#jitRoute = void 0;
1221
- this.#jitStatic = void 0;
1222
- this.#jitAliases = void 0;
1223
- this.#fetchFn = void 0;
1230
+ this.routerBuilt = false;
1231
+ this.compiled = void 0;
1232
+ this.jitColdRemaining = void 0;
1233
+ this.jitTable = void 0;
1234
+ this.jitRoute = void 0;
1235
+ this.jitStatic = void 0;
1236
+ this.jitAliases = void 0;
1237
+ this.fetchFn = void 0;
1224
1238
  this.fetch;
1225
1239
  return this;
1226
1240
  }
1227
1241
  handler(index, immediate, route, precomputedStatic, aliases, table) {
1228
- if (this.#compiled?.[index]) return this.#compiled[index];
1229
- const indexedTable = table ?? (this.#routerBuilt ? this["~routeTable"] : void 0);
1230
- const compiled = this.#compiled ??= new Array(indexedTable?.length ?? this["~routes"].length);
1242
+ if (this.compiled?.[index]) return this.compiled[index];
1243
+ const indexedTable = table ?? (this.routerBuilt ? this["~routeTable"] : void 0);
1244
+ const compiled = this.compiled ??= new Array(indexedTable?.length ?? this["~routes"].length);
1231
1245
  if (immediate ?? this["~config"]?.precompile) {
1232
1246
  const row = route ?? (indexedTable ? require_route_table.routeRow(indexedTable, index) : this["~routes"][index]);
1233
1247
  const exactDuplicate = ((indexedTable?.flags[index] ?? 0) & require_route_table.RouteFlag.ExactDuplicate) !== 0;
@@ -1244,10 +1258,10 @@ var Elysia = class Elysia {
1244
1258
  return this.#jitHandler(index, route ?? (indexedTable ? void 0 : this["~routes"][index]), precomputedStatic, aliases, indexedTable);
1245
1259
  }
1246
1260
  #jitHandler(index, route, precomputedStatic, aliases, table) {
1247
- if (table !== void 0) this.#jitTable = table;
1248
- if (route !== void 0) (this.#jitRoute ??= [])[index] = route;
1249
- if (precomputedStatic !== void 0) (this.#jitStatic ??= [])[index] = precomputedStatic;
1250
- if (aliases !== void 0) (this.#jitAliases ??= [])[index] = aliases;
1261
+ if (table !== void 0) this.jitTable = table;
1262
+ if (route !== void 0) (this.jitRoute ??= [])[index] = route;
1263
+ if (precomputedStatic !== void 0) (this.jitStatic ??= [])[index] = precomputedStatic;
1264
+ if (aliases !== void 0) (this.jitAliases ??= [])[index] = aliases;
1251
1265
  return (context) => this.#jitDispatch(index, context);
1252
1266
  }
1253
1267
  #staticAliases(table, index) {
@@ -1275,42 +1289,42 @@ var Elysia = class Elysia {
1275
1289
  }
1276
1290
  #releaseJit() {
1277
1291
  require_compile_aot.Compiled.release(this["~programId"]);
1278
- this.#jitColdRemaining = void 0;
1279
- this.#jitRoute = void 0;
1280
- this.#jitStatic = void 0;
1281
- this.#jitAliases = void 0;
1282
- this.#jitTable = void 0;
1292
+ this.jitColdRemaining = void 0;
1293
+ this.jitRoute = void 0;
1294
+ this.jitStatic = void 0;
1295
+ this.jitAliases = void 0;
1296
+ this.jitTable = void 0;
1283
1297
  }
1284
1298
  #satisfyJit(table, index) {
1285
1299
  if ((table.flags[index] & require_route_table.RouteFlag.ExactDuplicate) !== 0) return false;
1286
- if (this.#jitColdRemaining === void 0) {
1300
+ if (this.jitColdRemaining === void 0) {
1287
1301
  if (this["~generation"] === void 0 && this["~config"]?.precompile !== true && require_universal_is_production.isProduction() && !require_compile_aot.Capture.isAotBuildEnv()) table.flags[index] |= require_route_table.RouteFlag.JITSatisfied;
1288
1302
  return false;
1289
1303
  }
1290
1304
  if ((table.flags[index] & require_route_table.RouteFlag.JITCold) === 0) return false;
1291
1305
  table.flags[index] &= ~require_route_table.RouteFlag.JITCold;
1292
- if (--this.#jitColdRemaining > 0) return false;
1306
+ if (--this.jitColdRemaining > 0) return false;
1293
1307
  this.#releaseJit();
1294
1308
  return true;
1295
1309
  }
1296
1310
  #jitDispatch(index, context) {
1297
- if (this.#compiled[index]) return this.#compiled[index](context);
1298
- const route = this.#jitRoute?.[index];
1299
- const table = this.#jitTable ?? this["~routeTable"];
1311
+ if (this.compiled[index]) return this.compiled[index](context);
1312
+ const route = this.jitRoute?.[index];
1313
+ const table = this.jitTable ?? this["~routeTable"];
1300
1314
  const materialized = route ?? require_route_table.routeRow(table, index);
1301
1315
  const exactDuplicate = ((table?.flags[index] ?? 0) & require_route_table.RouteFlag.ExactDuplicate) !== 0;
1302
1316
  let handler;
1303
1317
  try {
1304
- handler = require_compile_handler_index.compileHandler(materialized, this, this.#jitStatic?.[index], exactDuplicate && require_compile_aot.Compiled.hasProgram(this["~programId"]));
1318
+ handler = require_compile_handler_index.compileHandler(materialized, this, this.jitStatic?.[index], exactDuplicate && require_compile_aot.Compiled.hasProgram(this["~programId"]));
1305
1319
  } catch (error) {
1306
1320
  const routeError = new Error(`[Elysia] Failed to compile route ${materialized[0]} ${materialized[1]}: ${error?.message ?? error}`, { cause: error });
1307
1321
  const finalize = this["~finalizeError"];
1308
1322
  if (finalize) return finalize(context, routeError);
1309
1323
  throw routeError;
1310
1324
  }
1311
- this.#compiled[index] = handler;
1325
+ this.compiled[index] = handler;
1312
1326
  if (!exactDuplicate) {
1313
- const aliases = this.#jitAliases?.[index] ?? (table ? this.#staticAliases(table, index) : void 0);
1327
+ const aliases = this.jitAliases?.[index] ?? (table ? this.#staticAliases(table, index) : void 0);
1314
1328
  if (aliases) {
1315
1329
  this.#initMap();
1316
1330
  const map = this["~map"][aliases.method] ??= require_utils.nullObject();
@@ -1318,9 +1332,9 @@ var Elysia = class Elysia {
1318
1332
  } else this.#saveHandler(materialized[0], materialized[1], handler);
1319
1333
  }
1320
1334
  if (!(table ? this.#satisfyJit(table, index) : false)) {
1321
- if (this.#jitRoute) this.#jitRoute[index] = void 0;
1322
- if (this.#jitStatic) this.#jitStatic[index] = void 0;
1323
- if (this.#jitAliases) this.#jitAliases[index] = void 0;
1335
+ if (this.jitRoute) this.jitRoute[index] = void 0;
1336
+ if (this.jitStatic) this.jitStatic[index] = void 0;
1337
+ if (this.jitAliases) this.jitAliases[index] = void 0;
1324
1338
  }
1325
1339
  return handler(context);
1326
1340
  }
@@ -1387,30 +1401,29 @@ var Elysia = class Elysia {
1387
1401
  const schemas = hook?.schemas;
1388
1402
  if (Array.isArray(schemas)) for (let s = 0; s < schemas.length; s++) checkSlots(schemas[s]);
1389
1403
  }
1390
- #routerBuilt = false;
1391
1404
  #buildRouter(seal = false) {
1392
- if (this.#routerBuilt) {
1405
+ if (this.routerBuilt) {
1393
1406
  if (seal && this["~generation"] === void 0) this.#publishGeneration();
1394
1407
  return;
1395
1408
  }
1396
1409
  const compilerSession = require_compile_aot.beginCompilerSession(this);
1397
1410
  const previousMap = this["~map"];
1398
1411
  const previousRouter = this["~router"];
1399
- const previousCompiled = this.#compiled;
1400
- const previousJitTable = this.#jitTable;
1401
- const previousJitRoute = this.#jitRoute;
1402
- const previousJitStatic = this.#jitStatic;
1403
- const previousJitAliases = this.#jitAliases;
1412
+ const previousCompiled = this.compiled;
1413
+ const previousJitTable = this.jitTable;
1414
+ const previousJitRoute = this.jitRoute;
1415
+ const previousJitStatic = this.jitStatic;
1416
+ const previousJitAliases = this.jitAliases;
1404
1417
  const previousHasDynamicWS = this["~hasDynamicWS"];
1405
1418
  const previousGeneration = this["~generation"];
1406
1419
  this["~map"] = void 0;
1407
1420
  this["~router"] = void 0;
1408
- this.#compiled = previousCompiled?.slice();
1409
- this.#jitColdRemaining = void 0;
1410
- this.#jitTable = void 0;
1411
- this.#jitRoute = void 0;
1412
- this.#jitStatic = void 0;
1413
- this.#jitAliases = void 0;
1421
+ this.compiled = previousCompiled?.slice();
1422
+ this.jitColdRemaining = void 0;
1423
+ this.jitTable = void 0;
1424
+ this.jitRoute = void 0;
1425
+ this.jitStatic = void 0;
1426
+ this.jitAliases = void 0;
1414
1427
  this["~hasDynamicWS"] = void 0;
1415
1428
  this["~generation"] = void 0;
1416
1429
  let buildSucceeded = false;
@@ -1426,18 +1439,18 @@ var Elysia = class Elysia {
1426
1439
  Object.assign(previousRouter, nextRouter);
1427
1440
  this["~router"] = previousRouter;
1428
1441
  }
1429
- this.#routerBuilt = true;
1442
+ this.routerBuilt = true;
1430
1443
  if (seal) this.#publishGeneration();
1431
1444
  buildSucceeded = true;
1432
1445
  } catch (error) {
1433
1446
  this["~map"] = previousMap;
1434
1447
  this["~router"] = previousRouter;
1435
- this.#compiled = previousCompiled;
1436
- this.#jitColdRemaining = void 0;
1437
- this.#jitTable = previousJitTable;
1438
- this.#jitRoute = previousJitRoute;
1439
- this.#jitStatic = previousJitStatic;
1440
- this.#jitAliases = previousJitAliases;
1448
+ this.compiled = previousCompiled;
1449
+ this.jitColdRemaining = void 0;
1450
+ this.jitTable = previousJitTable;
1451
+ this.jitRoute = previousJitRoute;
1452
+ this.jitStatic = previousJitStatic;
1453
+ this.jitAliases = previousJitAliases;
1441
1454
  this["~hasDynamicWS"] = previousHasDynamicWS;
1442
1455
  this["~generation"] = previousGeneration;
1443
1456
  throw error;
@@ -1462,7 +1475,7 @@ var Elysia = class Elysia {
1462
1475
  else {
1463
1476
  const table = this["~routeTable"];
1464
1477
  const routeCount = table.length;
1465
- const compiled = this.#compiled;
1478
+ const compiled = this.compiled;
1466
1479
  let cold = 0;
1467
1480
  for (let i = 0; i < routeCount; i++) {
1468
1481
  const satisfied = (table.flags[i] & require_route_table.RouteFlag.JITSatisfied) !== 0;
@@ -1473,10 +1486,10 @@ var Elysia = class Elysia {
1473
1486
  cold++;
1474
1487
  }
1475
1488
  if (cold === 0) this.#releaseJit();
1476
- else this.#jitColdRemaining = cold;
1489
+ else this.jitColdRemaining = cold;
1477
1490
  }
1478
1491
  require_compile_analysis_cache.clearAuthoringAnalysisCaches(this);
1479
- if (!this["~ext"]?.macro && !this["~scopeChildren"]) this.#declaredRoutes = void 0;
1492
+ if (!this["~ext"]?.macro && !this["~scopeChildren"]) this.declaredRoutes = void 0;
1480
1493
  }
1481
1494
  const ext = this["~ext"];
1482
1495
  if (ext?.hoc) extCallbackIndexes.delete(ext.hoc);
@@ -1484,8 +1497,8 @@ var Elysia = class Elysia {
1484
1497
  if (ext?.cleanup) extCallbackIndexes.delete(ext.cleanup);
1485
1498
  }
1486
1499
  ["~newGeneration"]() {
1487
- this.#fetchFn = void 0;
1488
- this.#routerBuilt = false;
1500
+ this.fetchFn = void 0;
1501
+ this.routerBuilt = false;
1489
1502
  this["~generation"] = void 0;
1490
1503
  this.#buildRouter(true);
1491
1504
  return this;
@@ -1584,15 +1597,13 @@ var Elysia = class Elysia {
1584
1597
  }
1585
1598
  this["~wsConfig"] = wsConfig;
1586
1599
  }
1587
- #fetchFn;
1588
1600
  get fetch() {
1589
- if (this.#fetchFn) return this.#fetchFn;
1590
- this.#buildRouter(!this.#pending);
1591
- return this.#fetchFn ??= require_handler_fetch.applyHoc(this, require_handler_fetch.createFetchHandler(this));
1601
+ if (this.fetchFn) return this.fetchFn;
1602
+ this.#buildRouter(!this._pending);
1603
+ return this.fetchFn ??= require_handler_fetch.applyHoc(this, require_handler_fetch.createFetchHandler(this));
1592
1604
  }
1593
- #handle;
1594
1605
  get handle() {
1595
- return this.#handle ??= async (requestOrUrl, options) => this.fetch(typeof requestOrUrl === "string" ? new Request(requestOrUrl.charCodeAt(0) === 47 ? `http://e.ly${requestOrUrl}` : requestOrUrl, options) : requestOrUrl);
1606
+ return this._handle ??= async (requestOrUrl, options) => this.fetch(typeof requestOrUrl === "string" ? new Request(requestOrUrl.charCodeAt(0) === 47 ? `http://e.ly${requestOrUrl}` : requestOrUrl, options) : requestOrUrl);
1596
1607
  }
1597
1608
  listen(options, callback) {
1598
1609
  const listen = (this["~config"]?.adapter ?? (require_universal_constants.isBun ? require_adapter_bun_index.BunAdapter : void 0))?.listen;
@@ -1617,8 +1628,8 @@ var Elysia = class Elysia {
1617
1628
  */
1618
1629
  wrap(callback) {
1619
1630
  this.#assertMutable("wrap");
1620
- if (this.#fetchFn && !this.#pending) console.warn("[Elysia] .wrap() was called after the fetch handler was built");
1621
- const ext = this.#ext;
1631
+ if (this.fetchFn && !this._pending) console.warn("[Elysia] .wrap() was called after the fetch handler was built");
1632
+ const ext = this.ext;
1622
1633
  (ext.hoc ??= []).push(callback);
1623
1634
  return this;
1624
1635
  }
@@ -1638,22 +1649,16 @@ var Elysia = class Elysia {
1638
1649
  cleanup(handler) {
1639
1650
  if (this["~ext"]?.cleanupEpoch?.(handler)) return this;
1640
1651
  this.#assertMutable("cleanup");
1641
- const arr = this.#ext.cleanup ??= [];
1652
+ const arr = this.ext.cleanup ??= [];
1642
1653
  if (Array.isArray(handler)) arr.push(...handler);
1643
1654
  else arr.push(handler);
1644
1655
  return this;
1645
1656
  }
1646
1657
  /**
1647
- * Stop the underlying server (if any), then run every `cleanup` handler.
1648
- * Omitted and `false` are the same graceful stop: new requests are gated,
1649
- * tracked WebSockets are settled and active HTTP is drained, then cleanup
1650
- * runs and the epoch is released. `true` force-closes the transport
1651
- * instead of draining it, and escalates a graceful stop already in flight.
1658
+ * Stop the underlying server (if any), then run every `cleanup` handler
1652
1659
  *
1653
1660
  * Awaiting `stop()` from inside a `setup`, `cleanup` or WebSocket lifecycle
1654
- * callback is only supported while that callback is still synchronous; the
1655
- * teardown is waiting on the callback, so after an `await` it can only be
1656
- * issued as `void app.stop()`.
1661
+ * callback is only supported while that callback is still synchronous
1657
1662
  *
1658
1663
  * @param closeActiveConnections Pass `true` to terminate active
1659
1664
  * transports. Omit (or pass `false`) to drain safely.