elysia 2.0.0-beta.4 → 2.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/bun/index.js +52 -59
- package/dist/adapter/bun/index.mjs +53 -60
- package/dist/adapter/utils.js +0 -6
- package/dist/adapter/utils.mjs +0 -6
- package/dist/base.d.ts +25 -9
- package/dist/base.js +175 -198
- package/dist/base.mjs +175 -198
- package/dist/compile/aot-capture.js +1 -1
- package/dist/compile/aot-capture.mjs +1 -1
- package/dist/compile/aot.d.ts +5 -5
- package/dist/compile/handler/index.js +4 -0
- package/dist/compile/handler/index.mjs +4 -0
- package/dist/index.d.ts +2 -2
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/core.d.ts +16 -37
- package/dist/plugin/aot/core.js +21 -39
- package/dist/plugin/aot/core.mjs +22 -41
- package/dist/sucrose.js +6 -0
- package/dist/sucrose.mjs +6 -0
- package/dist/type/bridge-live.d.ts +1 -1
- package/dist/type/bridge-live.js +1 -1
- package/dist/type/bridge-live.mjs +1 -1
- package/dist/type/bridge.d.ts +1 -1
- package/dist/type/coerce-plan.d.ts +1 -1
- package/dist/type/coerce-plan.js +1 -0
- package/dist/type/coerce-plan.mjs +1 -0
- package/dist/type/coerce.d.ts +2 -2
- package/dist/type/coerce.js +1 -1
- package/dist/type/coerce.mjs +2 -2
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/typebox-value-live.d.ts +2 -2
- package/dist/type/typebox-value-live.js +2 -2
- package/dist/type/typebox-value-live.mjs +2 -2
- package/dist/type/typebox-value.d.ts +6 -6
- package/dist/type/validator/exact-mirror-live.d.ts +8 -0
- package/dist/type/validator/exact-mirror-live.js +22 -0
- package/dist/type/validator/exact-mirror-live.mjs +17 -0
- package/dist/type/validator/index.d.ts +1 -1
- package/dist/type/validator/index.js +10 -1
- package/dist/type/validator/index.mjs +10 -1
- package/dist/type/validator/validator-cache.d.ts +1 -1
- package/dist/types.d.ts +46 -8
- package/dist/ws/route.js +36 -9
- package/dist/ws/route.mjs +37 -10
- 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
|
|
78
|
-
if (!this
|
|
79
|
-
const history = new Array(this
|
|
80
|
-
for (let sequence = 0; sequence < this
|
|
81
|
-
const route = this
|
|
82
|
-
const source = this
|
|
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
|
|
94
|
-
if (!this
|
|
95
|
-
const routes = this
|
|
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
|
|
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
|
|
179
|
-
if (!this
|
|
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
|
|
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
|
|
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
|
|
270
|
-
else if (scope === "global") this
|
|
271
|
-
if (this
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
407
|
-
else this
|
|
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
|
|
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
|
|
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
|
|
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
|
|
484
|
+
const ext = this.ext;
|
|
499
485
|
if (ext.macro) return ext.macro;
|
|
500
|
-
const parent = this["~scopeChild"] ? this
|
|
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
|
|
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
|
|
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,7 +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;
|
|
566
|
+
if (k === "seed" || k === "meta" || k === "$type") continue;
|
|
581
567
|
if (k === "introspect") {
|
|
582
568
|
v?.(input);
|
|
583
569
|
delete input[key];
|
|
@@ -652,13 +638,13 @@ var Elysia = class Elysia {
|
|
|
652
638
|
return this;
|
|
653
639
|
}
|
|
654
640
|
#useFn(app) {
|
|
655
|
-
const prevBaseline = this
|
|
641
|
+
const prevBaseline = this.macroBaseline;
|
|
656
642
|
const baseline = /* @__PURE__ */ new Set();
|
|
657
643
|
const existingMacro = this["~ext"]?.macro;
|
|
658
644
|
if (existingMacro) for (const k in existingMacro) baseline.add(k);
|
|
659
|
-
this
|
|
645
|
+
this.macroBaseline = baseline;
|
|
660
646
|
const result = app(this);
|
|
661
|
-
this
|
|
647
|
+
this.macroBaseline = prevBaseline;
|
|
662
648
|
if (result && typeof result.then === "function") {
|
|
663
649
|
const beforeMacro = new Map(Object.entries(this["~ext"]?.macro ?? require_utils.nullObject()));
|
|
664
650
|
return this.#useAsync(result.then((value) => {
|
|
@@ -677,17 +663,17 @@ var Elysia = class Elysia {
|
|
|
677
663
|
if (app["~introspect"] || config?.introspect) this["~introspect"] = true;
|
|
678
664
|
const name = config?.name;
|
|
679
665
|
if (name) {
|
|
680
|
-
const hash = app
|
|
681
|
-
if (this
|
|
682
|
-
this
|
|
683
|
-
this
|
|
666
|
+
const hash = app.hash;
|
|
667
|
+
if (this.childrenHash?.has(hash)) return;
|
|
668
|
+
this.childrenHash ??= /* @__PURE__ */ new Set();
|
|
669
|
+
this.childrenHash.add(hash);
|
|
684
670
|
(addedByThisCall ??= /* @__PURE__ */ new Set()).add(hash);
|
|
685
671
|
}
|
|
686
|
-
if (app
|
|
672
|
+
if (app.childrenHash) addedByThisCall = this.#absorbChildrenHash(app, addedByThisCall);
|
|
687
673
|
if (app["~ext"]) this.#assertMacroUnique(app, addedByThisCall);
|
|
688
674
|
if (app["~hasTrace"]) this["~hasTrace"] = true;
|
|
689
|
-
if (app
|
|
690
|
-
if (app
|
|
675
|
+
if (app.declaredRoutes === void 0 && app["~routeTable"]?.length) app.#materializeDeclaredRoutes();
|
|
676
|
+
if (app.declaredRoutes?.length) {
|
|
691
677
|
if (app["~hasWS"]) this["~hasWS"] = true;
|
|
692
678
|
this.#emitChildRoutes(app, this["~hookChain"], name);
|
|
693
679
|
}
|
|
@@ -697,17 +683,17 @@ var Elysia = class Elysia {
|
|
|
697
683
|
}
|
|
698
684
|
const hookChain = app["~hookChain"];
|
|
699
685
|
if (app["~ext"]) this.#absorbExt(app);
|
|
700
|
-
if (app
|
|
686
|
+
if (app.hasPlugin || app.hasGlobal || hookChain) this.#propagateHooks(app, hookChain, addedByThisCall);
|
|
701
687
|
}
|
|
702
688
|
#absorbChildrenHash(app, addedByThisCall) {
|
|
703
|
-
const incoming = app
|
|
704
|
-
if (this
|
|
705
|
-
if (this
|
|
706
|
-
this
|
|
689
|
+
const incoming = app.childrenHash;
|
|
690
|
+
if (this.childrenHash) for (const h of incoming) {
|
|
691
|
+
if (this.childrenHash.has(h)) continue;
|
|
692
|
+
this.childrenHash.add(h);
|
|
707
693
|
(addedByThisCall ??= /* @__PURE__ */ new Set()).add(h);
|
|
708
694
|
}
|
|
709
695
|
else {
|
|
710
|
-
this
|
|
696
|
+
this.childrenHash = new Set(incoming);
|
|
711
697
|
addedByThisCall = new Set(incoming);
|
|
712
698
|
}
|
|
713
699
|
return addedByThisCall;
|
|
@@ -726,7 +712,7 @@ var Elysia = class Elysia {
|
|
|
726
712
|
if (existing === incoming) continue;
|
|
727
713
|
const origin = require_utils.macroOrigin.get(existing);
|
|
728
714
|
if (origin !== void 0 && origin === require_utils.macroOrigin.get(incoming)) continue;
|
|
729
|
-
if (addedByThisCall) for (const h of addedByThisCall) this
|
|
715
|
+
if (addedByThisCall) for (const h of addedByThisCall) this.childrenHash.delete(h);
|
|
730
716
|
throw new Error(`[Elysia] Macro "${macroName}" can be only define once`);
|
|
731
717
|
}
|
|
732
718
|
}
|
|
@@ -752,21 +738,21 @@ var Elysia = class Elysia {
|
|
|
752
738
|
if (parser) if (ext.parser) Object.assign(ext.parser, parser);
|
|
753
739
|
else ext.parser = Object.assign(require_utils.nullObject(), parser);
|
|
754
740
|
if (macro) if (app["~scopeChild"]) {
|
|
755
|
-
const pluginMacros = app
|
|
741
|
+
const pluginMacros = app.pluginMacros;
|
|
756
742
|
let changed = false;
|
|
757
743
|
if (pluginMacros?.size) {
|
|
758
744
|
const target = this.#ensureMacroTable();
|
|
759
745
|
for (const [name, def] of pluginMacros) if (!(name in target)) {
|
|
760
746
|
target[name] = def;
|
|
761
747
|
changed = true;
|
|
762
|
-
if (this["~scopeChild"]) (this
|
|
748
|
+
if (this["~scopeChild"]) (this.pluginMacros ??= /* @__PURE__ */ new Map()).set(name, def);
|
|
763
749
|
}
|
|
764
750
|
}
|
|
765
751
|
if (changed) require_utils.invalidateMacroEpoch();
|
|
766
752
|
} else {
|
|
767
753
|
Object.assign(this.#ensureMacroTable(), macro);
|
|
768
754
|
if (this["~scopeChild"]) {
|
|
769
|
-
const pluginMacros = this
|
|
755
|
+
const pluginMacros = this.pluginMacros ??= /* @__PURE__ */ new Map();
|
|
770
756
|
for (const name in macro) pluginMacros.set(name, macro[name]);
|
|
771
757
|
}
|
|
772
758
|
require_utils.invalidateMacroEpoch();
|
|
@@ -827,7 +813,7 @@ var Elysia = class Elysia {
|
|
|
827
813
|
let globalEvents;
|
|
828
814
|
let pluginMayRef = false;
|
|
829
815
|
let globalMayRef = false;
|
|
830
|
-
if (app
|
|
816
|
+
if (app.hasGlobal) this.hasGlobal = true;
|
|
831
817
|
const nodes = useNodesBuffer;
|
|
832
818
|
nodes.length = 0;
|
|
833
819
|
let current = hookChain;
|
|
@@ -857,7 +843,7 @@ var Elysia = class Elysia {
|
|
|
857
843
|
else pluginMayRef = true;
|
|
858
844
|
for (const s of schemas) {
|
|
859
845
|
(target.schemas ??= []).push(s);
|
|
860
|
-
if (isGlobal) this
|
|
846
|
+
if (isGlobal) this.hasGlobal = true;
|
|
861
847
|
}
|
|
862
848
|
continue;
|
|
863
849
|
}
|
|
@@ -868,13 +854,13 @@ var Elysia = class Elysia {
|
|
|
868
854
|
const count = many ? raw.length : 1;
|
|
869
855
|
for (let f = 0; f < count; f++) {
|
|
870
856
|
const fn = many ? raw[f] : raw;
|
|
871
|
-
const childrenHash = this
|
|
857
|
+
const childrenHash = this.childrenHash;
|
|
872
858
|
if (childrenHash !== void 0) {
|
|
873
859
|
const origin = require_utils.fnOrigin.get(fn);
|
|
874
860
|
if (origin !== void 0 && childrenHash.has(origin) && !addedByThisCall?.has(origin)) continue;
|
|
875
861
|
}
|
|
876
862
|
require_utils.pushField(isGlobal ? globalEvents ??= require_utils.nullObject() : pluginEvents ??= require_utils.nullObject(), key, fn);
|
|
877
|
-
if (isGlobal) this
|
|
863
|
+
if (isGlobal) this.hasGlobal = true;
|
|
878
864
|
}
|
|
879
865
|
continue;
|
|
880
866
|
}
|
|
@@ -917,7 +903,7 @@ var Elysia = class Elysia {
|
|
|
917
903
|
}
|
|
918
904
|
}
|
|
919
905
|
#emitChildRoutes(app, preChain, name) {
|
|
920
|
-
const declared = app
|
|
906
|
+
const declared = app.declaredRoutes;
|
|
921
907
|
if (!declared?.length) return;
|
|
922
908
|
const limit = declared.length;
|
|
923
909
|
let lastChildChain;
|
|
@@ -955,55 +941,55 @@ var Elysia = class Elysia {
|
|
|
955
941
|
], source);
|
|
956
942
|
}
|
|
957
943
|
get modules() {
|
|
958
|
-
const ready = this
|
|
944
|
+
const ready = this.ready;
|
|
959
945
|
if (!ready) {
|
|
960
|
-
if (this
|
|
946
|
+
if (this._error !== void 0) return Promise.reject(this._error.error);
|
|
961
947
|
return Promise.resolve();
|
|
962
948
|
}
|
|
963
949
|
return ready.then(() => {
|
|
964
|
-
if (this
|
|
965
|
-
if (this
|
|
950
|
+
if (this._error !== void 0) throw this._error.error;
|
|
951
|
+
if (this.ready && this.ready !== ready) return this.modules;
|
|
966
952
|
});
|
|
967
953
|
}
|
|
968
954
|
get pending() {
|
|
969
|
-
return this
|
|
955
|
+
return this._pending > 0;
|
|
970
956
|
}
|
|
971
957
|
#useAsync(promise) {
|
|
972
|
-
if (!this
|
|
973
|
-
this
|
|
974
|
-
const next = (this
|
|
958
|
+
if (!this.ready) this._error = void 0;
|
|
959
|
+
this._pending++;
|
|
960
|
+
const next = (this.ready ?? Promise.resolve()).then(() => promise).then((value) => {
|
|
975
961
|
const plugin = value && typeof value === "object" && "default" in value && value.default ? value.default : value;
|
|
976
962
|
if (plugin) try {
|
|
977
963
|
this.use(plugin);
|
|
978
964
|
} catch (err) {
|
|
979
|
-
this
|
|
965
|
+
this._error ??= { error: err };
|
|
980
966
|
console.error(err);
|
|
981
967
|
}
|
|
982
968
|
}).finally(() => {
|
|
983
|
-
this
|
|
969
|
+
this._pending--;
|
|
984
970
|
}).then(() => {}, (err) => {
|
|
985
|
-
this
|
|
971
|
+
this._error ??= { error: err };
|
|
986
972
|
console.error(err);
|
|
987
973
|
}).finally(() => this.#tryDrain(next));
|
|
988
|
-
this
|
|
974
|
+
this.ready = next;
|
|
989
975
|
return this;
|
|
990
976
|
}
|
|
991
977
|
#tryDrain(sentinel) {
|
|
992
|
-
if (this
|
|
993
|
-
if (this
|
|
994
|
-
const previousCompiled = this
|
|
995
|
-
const previousJitColdRemaining = this
|
|
996
|
-
this
|
|
997
|
-
this
|
|
998
|
-
this
|
|
999
|
-
this
|
|
978
|
+
if (this._pending > 0) return;
|
|
979
|
+
if (this.ready !== sentinel) return;
|
|
980
|
+
const previousCompiled = this.compiled;
|
|
981
|
+
const previousJitColdRemaining = this.jitColdRemaining;
|
|
982
|
+
this.ready = void 0;
|
|
983
|
+
this.compiled = void 0;
|
|
984
|
+
this.fetchFn = void 0;
|
|
985
|
+
this.routerBuilt = false;
|
|
1000
986
|
require_context.clearContextCache(this);
|
|
1001
987
|
try {
|
|
1002
988
|
this.#buildRouter(false);
|
|
1003
989
|
} catch (error) {
|
|
1004
|
-
this
|
|
1005
|
-
this
|
|
1006
|
-
this
|
|
990
|
+
this.compiled = previousCompiled;
|
|
991
|
+
this.jitColdRemaining = previousJitColdRemaining;
|
|
992
|
+
this._error ??= { error };
|
|
1007
993
|
}
|
|
1008
994
|
}
|
|
1009
995
|
#add(method, path, hookOrFn, fn, hasHook = fn !== void 0) {
|
|
@@ -1013,7 +999,7 @@ var Elysia = class Elysia {
|
|
|
1013
999
|
const hook = hasHook ? require_schema_snapshot.snapshotHookSchemas(hookOrFn) : void 0;
|
|
1014
1000
|
const appHook = this["~hookChain"];
|
|
1015
1001
|
if (this["~generation"] !== void 0) this.#assertMutable("route");
|
|
1016
|
-
(this
|
|
1002
|
+
(this.declaredRoutes ?? this.#materializeDeclaredRoutes()).push(appHook ? [
|
|
1017
1003
|
method,
|
|
1018
1004
|
path,
|
|
1019
1005
|
handler,
|
|
@@ -1032,15 +1018,15 @@ var Elysia = class Elysia {
|
|
|
1032
1018
|
handler,
|
|
1033
1019
|
this
|
|
1034
1020
|
]);
|
|
1035
|
-
if (this
|
|
1036
|
-
this
|
|
1037
|
-
this
|
|
1038
|
-
this
|
|
1039
|
-
this
|
|
1040
|
-
this
|
|
1041
|
-
this
|
|
1042
|
-
this
|
|
1043
|
-
this
|
|
1021
|
+
if (this.routerBuilt || this.compiled !== void 0) {
|
|
1022
|
+
this.compiled = void 0;
|
|
1023
|
+
this.jitColdRemaining = void 0;
|
|
1024
|
+
this.jitTable = void 0;
|
|
1025
|
+
this.jitRoute = void 0;
|
|
1026
|
+
this.jitStatic = void 0;
|
|
1027
|
+
this.jitAliases = void 0;
|
|
1028
|
+
this.fetchFn = void 0;
|
|
1029
|
+
this.routerBuilt = false;
|
|
1044
1030
|
}
|
|
1045
1031
|
return this;
|
|
1046
1032
|
}
|
|
@@ -1049,33 +1035,33 @@ var Elysia = class Elysia {
|
|
|
1049
1035
|
throw new Error(`[Elysia] .${api}() called after the app was sealed`);
|
|
1050
1036
|
}
|
|
1051
1037
|
#materializeDeclaredRoutes() {
|
|
1052
|
-
if (this
|
|
1038
|
+
if (this.declaredRoutes !== void 0) return this.declaredRoutes;
|
|
1053
1039
|
const table = this["~routeTable"];
|
|
1054
|
-
if (!table) return this
|
|
1040
|
+
if (!table) return this.declaredRoutes = [];
|
|
1055
1041
|
const routes = new Array(table.length);
|
|
1056
1042
|
for (let i = 0; i < table.length; i++) routes[i] = require_route_table.routeRow(table, i);
|
|
1057
|
-
return this
|
|
1043
|
+
return this.declaredRoutes = routes;
|
|
1058
1044
|
}
|
|
1059
1045
|
#registerRoute(route, source) {
|
|
1060
1046
|
if (this["~generation"] !== void 0) this.#assertMutable("route");
|
|
1061
|
-
const routes = this
|
|
1047
|
+
const routes = this.declaredRoutes ?? this.#materializeDeclaredRoutes();
|
|
1062
1048
|
const sequence = routes.length;
|
|
1063
1049
|
routes.push(route);
|
|
1064
|
-
if (source) (this
|
|
1065
|
-
if (this
|
|
1066
|
-
this
|
|
1067
|
-
this
|
|
1068
|
-
this
|
|
1069
|
-
this
|
|
1070
|
-
this
|
|
1071
|
-
this
|
|
1072
|
-
this
|
|
1073
|
-
this
|
|
1050
|
+
if (source) (this.routeSources ??= [])[sequence] = source;
|
|
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;
|
|
1074
1060
|
}
|
|
1075
1061
|
}
|
|
1076
1062
|
model(name, model) {
|
|
1077
1063
|
this.#assertMutable("model");
|
|
1078
|
-
const models = this
|
|
1064
|
+
const models = this.ext.models ??= require_utils.nullObject();
|
|
1079
1065
|
switch (typeof name) {
|
|
1080
1066
|
case "object":
|
|
1081
1067
|
const entries = Object.entries(name);
|
|
@@ -1101,7 +1087,7 @@ var Elysia = class Elysia {
|
|
|
1101
1087
|
next[key] = value;
|
|
1102
1088
|
}
|
|
1103
1089
|
}
|
|
1104
|
-
this
|
|
1090
|
+
this.ext.models = next;
|
|
1105
1091
|
return this;
|
|
1106
1092
|
}
|
|
1107
1093
|
case "string":
|
|
@@ -1211,21 +1197,21 @@ var Elysia = class Elysia {
|
|
|
1211
1197
|
compile() {
|
|
1212
1198
|
this["~config"] ??= require_utils.nullObject();
|
|
1213
1199
|
this["~config"].precompile = true;
|
|
1214
|
-
this
|
|
1215
|
-
this
|
|
1216
|
-
this
|
|
1217
|
-
this
|
|
1218
|
-
this
|
|
1219
|
-
this
|
|
1220
|
-
this
|
|
1221
|
-
this
|
|
1200
|
+
this.routerBuilt = false;
|
|
1201
|
+
this.compiled = void 0;
|
|
1202
|
+
this.jitColdRemaining = void 0;
|
|
1203
|
+
this.jitTable = void 0;
|
|
1204
|
+
this.jitRoute = void 0;
|
|
1205
|
+
this.jitStatic = void 0;
|
|
1206
|
+
this.jitAliases = void 0;
|
|
1207
|
+
this.fetchFn = void 0;
|
|
1222
1208
|
this.fetch;
|
|
1223
1209
|
return this;
|
|
1224
1210
|
}
|
|
1225
1211
|
handler(index, immediate, route, precomputedStatic, aliases, table) {
|
|
1226
|
-
if (this
|
|
1227
|
-
const indexedTable = table ?? (this
|
|
1228
|
-
const compiled = this
|
|
1212
|
+
if (this.compiled?.[index]) return this.compiled[index];
|
|
1213
|
+
const indexedTable = table ?? (this.routerBuilt ? this["~routeTable"] : void 0);
|
|
1214
|
+
const compiled = this.compiled ??= new Array(indexedTable?.length ?? this["~routes"].length);
|
|
1229
1215
|
if (immediate ?? this["~config"]?.precompile) {
|
|
1230
1216
|
const row = route ?? (indexedTable ? require_route_table.routeRow(indexedTable, index) : this["~routes"][index]);
|
|
1231
1217
|
const exactDuplicate = ((indexedTable?.flags[index] ?? 0) & require_route_table.RouteFlag.ExactDuplicate) !== 0;
|
|
@@ -1242,10 +1228,10 @@ var Elysia = class Elysia {
|
|
|
1242
1228
|
return this.#jitHandler(index, route ?? (indexedTable ? void 0 : this["~routes"][index]), precomputedStatic, aliases, indexedTable);
|
|
1243
1229
|
}
|
|
1244
1230
|
#jitHandler(index, route, precomputedStatic, aliases, table) {
|
|
1245
|
-
if (table !== void 0) this
|
|
1246
|
-
if (route !== void 0) (this
|
|
1247
|
-
if (precomputedStatic !== void 0) (this
|
|
1248
|
-
if (aliases !== void 0) (this
|
|
1231
|
+
if (table !== void 0) this.jitTable = table;
|
|
1232
|
+
if (route !== void 0) (this.jitRoute ??= [])[index] = route;
|
|
1233
|
+
if (precomputedStatic !== void 0) (this.jitStatic ??= [])[index] = precomputedStatic;
|
|
1234
|
+
if (aliases !== void 0) (this.jitAliases ??= [])[index] = aliases;
|
|
1249
1235
|
return (context) => this.#jitDispatch(index, context);
|
|
1250
1236
|
}
|
|
1251
1237
|
#staticAliases(table, index) {
|
|
@@ -1273,42 +1259,42 @@ var Elysia = class Elysia {
|
|
|
1273
1259
|
}
|
|
1274
1260
|
#releaseJit() {
|
|
1275
1261
|
require_compile_aot.Compiled.release(this["~programId"]);
|
|
1276
|
-
this
|
|
1277
|
-
this
|
|
1278
|
-
this
|
|
1279
|
-
this
|
|
1280
|
-
this
|
|
1262
|
+
this.jitColdRemaining = void 0;
|
|
1263
|
+
this.jitRoute = void 0;
|
|
1264
|
+
this.jitStatic = void 0;
|
|
1265
|
+
this.jitAliases = void 0;
|
|
1266
|
+
this.jitTable = void 0;
|
|
1281
1267
|
}
|
|
1282
1268
|
#satisfyJit(table, index) {
|
|
1283
1269
|
if ((table.flags[index] & require_route_table.RouteFlag.ExactDuplicate) !== 0) return false;
|
|
1284
|
-
if (this
|
|
1270
|
+
if (this.jitColdRemaining === void 0) {
|
|
1285
1271
|
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;
|
|
1286
1272
|
return false;
|
|
1287
1273
|
}
|
|
1288
1274
|
if ((table.flags[index] & require_route_table.RouteFlag.JITCold) === 0) return false;
|
|
1289
1275
|
table.flags[index] &= ~require_route_table.RouteFlag.JITCold;
|
|
1290
|
-
if (--this
|
|
1276
|
+
if (--this.jitColdRemaining > 0) return false;
|
|
1291
1277
|
this.#releaseJit();
|
|
1292
1278
|
return true;
|
|
1293
1279
|
}
|
|
1294
1280
|
#jitDispatch(index, context) {
|
|
1295
|
-
if (this
|
|
1296
|
-
const route = this
|
|
1297
|
-
const table = this
|
|
1281
|
+
if (this.compiled[index]) return this.compiled[index](context);
|
|
1282
|
+
const route = this.jitRoute?.[index];
|
|
1283
|
+
const table = this.jitTable ?? this["~routeTable"];
|
|
1298
1284
|
const materialized = route ?? require_route_table.routeRow(table, index);
|
|
1299
1285
|
const exactDuplicate = ((table?.flags[index] ?? 0) & require_route_table.RouteFlag.ExactDuplicate) !== 0;
|
|
1300
1286
|
let handler;
|
|
1301
1287
|
try {
|
|
1302
|
-
handler = require_compile_handler_index.compileHandler(materialized, this, this
|
|
1288
|
+
handler = require_compile_handler_index.compileHandler(materialized, this, this.jitStatic?.[index], exactDuplicate && require_compile_aot.Compiled.hasProgram(this["~programId"]));
|
|
1303
1289
|
} catch (error) {
|
|
1304
1290
|
const routeError = new Error(`[Elysia] Failed to compile route ${materialized[0]} ${materialized[1]}: ${error?.message ?? error}`, { cause: error });
|
|
1305
1291
|
const finalize = this["~finalizeError"];
|
|
1306
1292
|
if (finalize) return finalize(context, routeError);
|
|
1307
1293
|
throw routeError;
|
|
1308
1294
|
}
|
|
1309
|
-
this
|
|
1295
|
+
this.compiled[index] = handler;
|
|
1310
1296
|
if (!exactDuplicate) {
|
|
1311
|
-
const aliases = this
|
|
1297
|
+
const aliases = this.jitAliases?.[index] ?? (table ? this.#staticAliases(table, index) : void 0);
|
|
1312
1298
|
if (aliases) {
|
|
1313
1299
|
this.#initMap();
|
|
1314
1300
|
const map = this["~map"][aliases.method] ??= require_utils.nullObject();
|
|
@@ -1316,9 +1302,9 @@ var Elysia = class Elysia {
|
|
|
1316
1302
|
} else this.#saveHandler(materialized[0], materialized[1], handler);
|
|
1317
1303
|
}
|
|
1318
1304
|
if (!(table ? this.#satisfyJit(table, index) : false)) {
|
|
1319
|
-
if (this
|
|
1320
|
-
if (this
|
|
1321
|
-
if (this
|
|
1305
|
+
if (this.jitRoute) this.jitRoute[index] = void 0;
|
|
1306
|
+
if (this.jitStatic) this.jitStatic[index] = void 0;
|
|
1307
|
+
if (this.jitAliases) this.jitAliases[index] = void 0;
|
|
1322
1308
|
}
|
|
1323
1309
|
return handler(context);
|
|
1324
1310
|
}
|
|
@@ -1385,30 +1371,29 @@ var Elysia = class Elysia {
|
|
|
1385
1371
|
const schemas = hook?.schemas;
|
|
1386
1372
|
if (Array.isArray(schemas)) for (let s = 0; s < schemas.length; s++) checkSlots(schemas[s]);
|
|
1387
1373
|
}
|
|
1388
|
-
#routerBuilt = false;
|
|
1389
1374
|
#buildRouter(seal = false) {
|
|
1390
|
-
if (this
|
|
1375
|
+
if (this.routerBuilt) {
|
|
1391
1376
|
if (seal && this["~generation"] === void 0) this.#publishGeneration();
|
|
1392
1377
|
return;
|
|
1393
1378
|
}
|
|
1394
1379
|
const compilerSession = require_compile_aot.beginCompilerSession(this);
|
|
1395
1380
|
const previousMap = this["~map"];
|
|
1396
1381
|
const previousRouter = this["~router"];
|
|
1397
|
-
const previousCompiled = this
|
|
1398
|
-
const previousJitTable = this
|
|
1399
|
-
const previousJitRoute = this
|
|
1400
|
-
const previousJitStatic = this
|
|
1401
|
-
const previousJitAliases = this
|
|
1382
|
+
const previousCompiled = this.compiled;
|
|
1383
|
+
const previousJitTable = this.jitTable;
|
|
1384
|
+
const previousJitRoute = this.jitRoute;
|
|
1385
|
+
const previousJitStatic = this.jitStatic;
|
|
1386
|
+
const previousJitAliases = this.jitAliases;
|
|
1402
1387
|
const previousHasDynamicWS = this["~hasDynamicWS"];
|
|
1403
1388
|
const previousGeneration = this["~generation"];
|
|
1404
1389
|
this["~map"] = void 0;
|
|
1405
1390
|
this["~router"] = void 0;
|
|
1406
|
-
this
|
|
1407
|
-
this
|
|
1408
|
-
this
|
|
1409
|
-
this
|
|
1410
|
-
this
|
|
1411
|
-
this
|
|
1391
|
+
this.compiled = previousCompiled?.slice();
|
|
1392
|
+
this.jitColdRemaining = void 0;
|
|
1393
|
+
this.jitTable = void 0;
|
|
1394
|
+
this.jitRoute = void 0;
|
|
1395
|
+
this.jitStatic = void 0;
|
|
1396
|
+
this.jitAliases = void 0;
|
|
1412
1397
|
this["~hasDynamicWS"] = void 0;
|
|
1413
1398
|
this["~generation"] = void 0;
|
|
1414
1399
|
let buildSucceeded = false;
|
|
@@ -1424,18 +1409,18 @@ var Elysia = class Elysia {
|
|
|
1424
1409
|
Object.assign(previousRouter, nextRouter);
|
|
1425
1410
|
this["~router"] = previousRouter;
|
|
1426
1411
|
}
|
|
1427
|
-
this
|
|
1412
|
+
this.routerBuilt = true;
|
|
1428
1413
|
if (seal) this.#publishGeneration();
|
|
1429
1414
|
buildSucceeded = true;
|
|
1430
1415
|
} catch (error) {
|
|
1431
1416
|
this["~map"] = previousMap;
|
|
1432
1417
|
this["~router"] = previousRouter;
|
|
1433
|
-
this
|
|
1434
|
-
this
|
|
1435
|
-
this
|
|
1436
|
-
this
|
|
1437
|
-
this
|
|
1438
|
-
this
|
|
1418
|
+
this.compiled = previousCompiled;
|
|
1419
|
+
this.jitColdRemaining = void 0;
|
|
1420
|
+
this.jitTable = previousJitTable;
|
|
1421
|
+
this.jitRoute = previousJitRoute;
|
|
1422
|
+
this.jitStatic = previousJitStatic;
|
|
1423
|
+
this.jitAliases = previousJitAliases;
|
|
1439
1424
|
this["~hasDynamicWS"] = previousHasDynamicWS;
|
|
1440
1425
|
this["~generation"] = previousGeneration;
|
|
1441
1426
|
throw error;
|
|
@@ -1460,7 +1445,7 @@ var Elysia = class Elysia {
|
|
|
1460
1445
|
else {
|
|
1461
1446
|
const table = this["~routeTable"];
|
|
1462
1447
|
const routeCount = table.length;
|
|
1463
|
-
const compiled = this
|
|
1448
|
+
const compiled = this.compiled;
|
|
1464
1449
|
let cold = 0;
|
|
1465
1450
|
for (let i = 0; i < routeCount; i++) {
|
|
1466
1451
|
const satisfied = (table.flags[i] & require_route_table.RouteFlag.JITSatisfied) !== 0;
|
|
@@ -1471,10 +1456,10 @@ var Elysia = class Elysia {
|
|
|
1471
1456
|
cold++;
|
|
1472
1457
|
}
|
|
1473
1458
|
if (cold === 0) this.#releaseJit();
|
|
1474
|
-
else this
|
|
1459
|
+
else this.jitColdRemaining = cold;
|
|
1475
1460
|
}
|
|
1476
1461
|
require_compile_analysis_cache.clearAuthoringAnalysisCaches(this);
|
|
1477
|
-
if (!this["~ext"]?.macro && !this["~scopeChildren"]) this
|
|
1462
|
+
if (!this["~ext"]?.macro && !this["~scopeChildren"]) this.declaredRoutes = void 0;
|
|
1478
1463
|
}
|
|
1479
1464
|
const ext = this["~ext"];
|
|
1480
1465
|
if (ext?.hoc) extCallbackIndexes.delete(ext.hoc);
|
|
@@ -1482,8 +1467,8 @@ var Elysia = class Elysia {
|
|
|
1482
1467
|
if (ext?.cleanup) extCallbackIndexes.delete(ext.cleanup);
|
|
1483
1468
|
}
|
|
1484
1469
|
["~newGeneration"]() {
|
|
1485
|
-
this
|
|
1486
|
-
this
|
|
1470
|
+
this.fetchFn = void 0;
|
|
1471
|
+
this.routerBuilt = false;
|
|
1487
1472
|
this["~generation"] = void 0;
|
|
1488
1473
|
this.#buildRouter(true);
|
|
1489
1474
|
return this;
|
|
@@ -1582,15 +1567,13 @@ var Elysia = class Elysia {
|
|
|
1582
1567
|
}
|
|
1583
1568
|
this["~wsConfig"] = wsConfig;
|
|
1584
1569
|
}
|
|
1585
|
-
#fetchFn;
|
|
1586
1570
|
get fetch() {
|
|
1587
|
-
if (this
|
|
1588
|
-
this.#buildRouter(!this
|
|
1589
|
-
return this
|
|
1571
|
+
if (this.fetchFn) return this.fetchFn;
|
|
1572
|
+
this.#buildRouter(!this._pending);
|
|
1573
|
+
return this.fetchFn ??= require_handler_fetch.applyHoc(this, require_handler_fetch.createFetchHandler(this));
|
|
1590
1574
|
}
|
|
1591
|
-
#handle;
|
|
1592
1575
|
get handle() {
|
|
1593
|
-
return this
|
|
1576
|
+
return this._handle ??= async (requestOrUrl, options) => this.fetch(typeof requestOrUrl === "string" ? new Request(requestOrUrl.charCodeAt(0) === 47 ? `http://e.ly${requestOrUrl}` : requestOrUrl, options) : requestOrUrl);
|
|
1594
1577
|
}
|
|
1595
1578
|
listen(options, callback) {
|
|
1596
1579
|
const listen = (this["~config"]?.adapter ?? (require_universal_constants.isBun ? require_adapter_bun_index.BunAdapter : void 0))?.listen;
|
|
@@ -1615,8 +1598,8 @@ var Elysia = class Elysia {
|
|
|
1615
1598
|
*/
|
|
1616
1599
|
wrap(callback) {
|
|
1617
1600
|
this.#assertMutable("wrap");
|
|
1618
|
-
if (this
|
|
1619
|
-
const ext = this
|
|
1601
|
+
if (this.fetchFn && !this._pending) console.warn("[Elysia] .wrap() was called after the fetch handler was built");
|
|
1602
|
+
const ext = this.ext;
|
|
1620
1603
|
(ext.hoc ??= []).push(callback);
|
|
1621
1604
|
return this;
|
|
1622
1605
|
}
|
|
@@ -1636,22 +1619,16 @@ var Elysia = class Elysia {
|
|
|
1636
1619
|
cleanup(handler) {
|
|
1637
1620
|
if (this["~ext"]?.cleanupEpoch?.(handler)) return this;
|
|
1638
1621
|
this.#assertMutable("cleanup");
|
|
1639
|
-
const arr = this
|
|
1622
|
+
const arr = this.ext.cleanup ??= [];
|
|
1640
1623
|
if (Array.isArray(handler)) arr.push(...handler);
|
|
1641
1624
|
else arr.push(handler);
|
|
1642
1625
|
return this;
|
|
1643
1626
|
}
|
|
1644
1627
|
/**
|
|
1645
|
-
* Stop the underlying server (if any), then run every `cleanup` handler
|
|
1646
|
-
* Omitted and `false` are the same graceful stop: new requests are gated,
|
|
1647
|
-
* tracked WebSockets are settled and active HTTP is drained, then cleanup
|
|
1648
|
-
* runs and the epoch is released. `true` force-closes the transport
|
|
1649
|
-
* instead of draining it, and escalates a graceful stop already in flight.
|
|
1628
|
+
* Stop the underlying server (if any), then run every `cleanup` handler
|
|
1650
1629
|
*
|
|
1651
1630
|
* Awaiting `stop()` from inside a `setup`, `cleanup` or WebSocket lifecycle
|
|
1652
|
-
* callback is only supported while that callback is still synchronous
|
|
1653
|
-
* teardown is waiting on the callback, so after an `await` it can only be
|
|
1654
|
-
* issued as `void app.stop()`.
|
|
1631
|
+
* callback is only supported while that callback is still synchronous
|
|
1655
1632
|
*
|
|
1656
1633
|
* @param closeActiveConnections Pass `true` to terminate active
|
|
1657
1634
|
* transports. Omit (or pass `false`) to drain safely.
|