elysia 2.0.0-exp.45 → 2.0.0-exp.46
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/utils.js +2 -7
- package/dist/adapter/utils.mjs +2 -7
- package/dist/adapter/web-standard/handler.js +3 -6
- package/dist/adapter/web-standard/handler.mjs +3 -6
- package/dist/base.js +4 -103
- package/dist/base.mjs +4 -103
- package/dist/compile/aot-capture.d.ts +18 -2
- package/dist/compile/aot-capture.js +170 -7
- package/dist/compile/aot-capture.mjs +161 -5
- package/dist/compile/aot-emit.d.ts +29 -0
- package/dist/compile/aot-emit.js +107 -0
- package/dist/compile/aot-emit.mjs +101 -0
- package/dist/compile/aot-reconstruct.d.ts +3 -27
- package/dist/compile/aot-reconstruct.js +4 -97
- package/dist/compile/aot-reconstruct.mjs +5 -92
- package/dist/compile/aot.d.ts +12 -30
- package/dist/compile/aot.js +39 -146
- package/dist/compile/aot.mjs +38 -142
- package/dist/compile/handler/descriptor.d.ts +0 -10
- package/dist/compile/handler/descriptor.js +0 -11
- package/dist/compile/handler/descriptor.mjs +0 -11
- package/dist/compile/handler/frozen-validator.js +15 -6
- package/dist/compile/handler/frozen-validator.mjs +15 -6
- package/dist/compile/handler/index.js +7 -5
- package/dist/compile/handler/index.mjs +7 -5
- package/dist/compile/handler/params.d.ts +2 -1
- package/dist/compile/handler/params.js +1 -0
- package/dist/compile/handler/params.mjs +1 -0
- package/dist/compile/plan/emit.d.ts +2 -5
- package/dist/compile/plan/emit.js +9 -32
- package/dist/compile/plan/emit.mjs +9 -32
- package/dist/compile/plan/plan.d.ts +9 -32
- package/dist/compile/plan/plan.js +9 -43
- package/dist/compile/plan/plan.mjs +9 -43
- package/dist/context.d.ts +10 -44
- package/dist/context.js +1 -10
- package/dist/context.mjs +1 -10
- package/dist/cookie/config.d.ts +2 -1
- package/dist/cookie/config.js +13 -18
- package/dist/cookie/config.mjs +12 -18
- package/dist/cookie/crypto.d.ts +3 -1
- package/dist/cookie/crypto.js +30 -13
- package/dist/cookie/crypto.mjs +28 -13
- package/dist/cookie/lib.d.ts +1 -1
- package/dist/cookie/lib.js +3 -11
- package/dist/cookie/lib.mjs +3 -11
- package/dist/cookie/utils.d.ts +2 -2
- package/dist/cookie/utils.js +11 -65
- package/dist/cookie/utils.mjs +9 -58
- package/dist/error.d.ts +3 -2
- package/dist/error.js +4 -3
- package/dist/error.mjs +4 -4
- package/dist/handler/error.js +2 -3
- package/dist/handler/error.mjs +2 -3
- package/dist/handler/fetch.js +1 -1
- package/dist/handler/fetch.mjs +1 -1
- package/dist/handler/index.d.ts +1 -3
- package/dist/handler/index.js +1 -5
- package/dist/handler/index.mjs +1 -3
- package/dist/handler/utils.d.ts +1 -2
- package/dist/handler/utils.js +0 -1
- package/dist/handler/utils.mjs +1 -1
- package/dist/plugin/aot/bun.js +3 -10
- package/dist/plugin/aot/bun.mjs +3 -10
- package/dist/plugin/aot/core.d.ts +1 -48
- package/dist/plugin/aot/core.js +4 -111
- package/dist/plugin/aot/core.mjs +4 -110
- package/dist/plugin/aot/esbuild.js +5 -36
- package/dist/plugin/aot/esbuild.mjs +6 -37
- package/dist/plugin/aot/hooks.d.ts +15 -1
- package/dist/plugin/aot/hooks.js +40 -1
- package/dist/plugin/aot/hooks.mjs +39 -1
- package/dist/plugin/aot/source.js +25 -20
- package/dist/plugin/aot/source.mjs +12 -7
- package/dist/plugin/aot/treeshake.js +3 -21
- package/dist/plugin/aot/treeshake.mjs +4 -21
- package/dist/sucrose.d.ts +0 -6
- package/dist/sucrose.js +5 -20
- package/dist/sucrose.mjs +5 -20
- package/dist/type/coerce.d.ts +0 -4
- package/dist/type/coerce.js +0 -1
- package/dist/type/coerce.mjs +0 -1
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/elysia/file-type.d.ts +2 -1
- package/dist/type/elysia/file-type.js +3 -0
- package/dist/type/elysia/file-type.mjs +4 -1
- package/dist/type/utils.js +20 -45
- package/dist/type/utils.mjs +20 -45
- package/dist/type/validator/clean-safe.d.ts +1 -1
- package/dist/type/validator/clean-safe.js +9 -8
- package/dist/type/validator/clean-safe.mjs +9 -8
- package/dist/type/validator/custom-error.js +4 -11
- package/dist/type/validator/custom-error.mjs +1 -8
- package/dist/type/validator/default-precompute.d.ts +7 -1
- package/dist/type/validator/default-precompute.js +11 -83
- package/dist/type/validator/default-precompute.mjs +10 -84
- package/dist/type/validator/frozen-check.js +3 -2
- package/dist/type/validator/frozen-check.mjs +2 -1
- package/dist/type/validator/index.d.ts +1 -2
- package/dist/type/validator/index.js +2 -5
- package/dist/type/validator/index.mjs +3 -5
- package/dist/type/validator/string-codec-aot.js +4 -3
- package/dist/type/validator/string-codec-aot.mjs +3 -2
- package/dist/types.d.ts +3 -29
- package/dist/universal/file.d.ts +1 -0
- package/dist/universal/file.js +1 -0
- package/dist/universal/file.mjs +1 -0
- package/dist/utils.d.ts +2 -12
- package/dist/utils.js +0 -1
- package/dist/utils.mjs +1 -1
- package/dist/validator/index.d.ts +0 -4
- package/dist/validator/index.js +20 -62
- package/dist/validator/index.mjs +21 -63
- package/dist/ws/context.d.ts +11 -11
- package/dist/ws/context.js +21 -42
- package/dist/ws/context.mjs +21 -42
- package/dist/ws/route.js +88 -126
- package/dist/ws/route.mjs +89 -127
- package/dist/ws/types.d.ts +2 -4
- package/package.json +1 -4
package/dist/adapter/utils.js
CHANGED
|
@@ -95,10 +95,7 @@ function normalizeHeaders(set) {
|
|
|
95
95
|
function parseSetCookies(headers, setCookie) {
|
|
96
96
|
if (!headers) return headers;
|
|
97
97
|
headers.delete("set-cookie");
|
|
98
|
-
for (let i = 0; i < setCookie.length; i++)
|
|
99
|
-
const index = setCookie[i].indexOf("=");
|
|
100
|
-
headers.append("set-cookie", `${setCookie[i].slice(0, index)}=${setCookie[i].slice(index + 1) || ""}`);
|
|
101
|
-
}
|
|
98
|
+
for (let i = 0; i < setCookie.length; i++) headers.append("set-cookie", setCookie[i]);
|
|
102
99
|
return headers;
|
|
103
100
|
}
|
|
104
101
|
function responseToSetHeaders(response, set) {
|
|
@@ -123,9 +120,7 @@ function responseToSetHeaders(response, set) {
|
|
|
123
120
|
};
|
|
124
121
|
for (const [key, value] of response.headers.entries()) set.headers[key] = value;
|
|
125
122
|
}
|
|
126
|
-
if (set.headers
|
|
127
|
-
if (set.headers.has("content-encoding")) set.headers.delete("content-encoding");
|
|
128
|
-
} else if (set.headers["content-encoding"]) delete set.headers["content-encoding"];
|
|
123
|
+
if (set.headers["content-encoding"]) delete set.headers["content-encoding"];
|
|
129
124
|
return set;
|
|
130
125
|
}
|
|
131
126
|
function enqueueBinaryChunk(controller, chunk) {
|
package/dist/adapter/utils.mjs
CHANGED
|
@@ -94,10 +94,7 @@ function normalizeHeaders(set) {
|
|
|
94
94
|
function parseSetCookies(headers, setCookie) {
|
|
95
95
|
if (!headers) return headers;
|
|
96
96
|
headers.delete("set-cookie");
|
|
97
|
-
for (let i = 0; i < setCookie.length; i++)
|
|
98
|
-
const index = setCookie[i].indexOf("=");
|
|
99
|
-
headers.append("set-cookie", `${setCookie[i].slice(0, index)}=${setCookie[i].slice(index + 1) || ""}`);
|
|
100
|
-
}
|
|
97
|
+
for (let i = 0; i < setCookie.length; i++) headers.append("set-cookie", setCookie[i]);
|
|
101
98
|
return headers;
|
|
102
99
|
}
|
|
103
100
|
function responseToSetHeaders(response, set) {
|
|
@@ -122,9 +119,7 @@ function responseToSetHeaders(response, set) {
|
|
|
122
119
|
};
|
|
123
120
|
for (const [key, value] of response.headers.entries()) set.headers[key] = value;
|
|
124
121
|
}
|
|
125
|
-
if (set.headers
|
|
126
|
-
if (set.headers.has("content-encoding")) set.headers.delete("content-encoding");
|
|
127
|
-
} else if (set.headers["content-encoding"]) delete set.headers["content-encoding"];
|
|
122
|
+
if (set.headers["content-encoding"]) delete set.headers["content-encoding"];
|
|
128
123
|
return set;
|
|
129
124
|
}
|
|
130
125
|
function enqueueBinaryChunk(controller, chunk) {
|
|
@@ -15,10 +15,7 @@ function handleElysiaFile(file, set = { headers: require_utils.nullObject() }, r
|
|
|
15
15
|
const stats = file.stats;
|
|
16
16
|
if (stats) return stats.then((stat) => {
|
|
17
17
|
const size = stat.size;
|
|
18
|
-
if (size !== void 0 && set.status !== 206 && set.status !== 304 && set.status !== 412 && set.status !== 416)
|
|
19
|
-
headers["content-range"] = `bytes 0-${size - 1}/${size}`;
|
|
20
|
-
headers["content-length"] = size;
|
|
21
|
-
}
|
|
18
|
+
if (size !== void 0 && set.status !== 206 && set.status !== 304 && set.status !== 412 && set.status !== 416) headers["content-length"] = size;
|
|
22
19
|
return require_adapter_utils.handleFile(file, set, request, size);
|
|
23
20
|
});
|
|
24
21
|
return require_adapter_utils.handleFile(file.value, set, request);
|
|
@@ -117,7 +114,7 @@ function errorToResponse(error, set) {
|
|
|
117
114
|
headers
|
|
118
115
|
});
|
|
119
116
|
}
|
|
120
|
-
function mapFallback(map
|
|
117
|
+
function mapFallback(map) {
|
|
121
118
|
return (response, set, request) => {
|
|
122
119
|
if (response instanceof Response) return handleResponse(response, set, request);
|
|
123
120
|
if (response instanceof Promise) return response.then((x) => map(x, set, request));
|
|
@@ -138,7 +135,7 @@ function mapFallback(map, mustReturn = true) {
|
|
|
138
135
|
if (Array.isArray(response)) return Response.json(response);
|
|
139
136
|
if (typeof response?.toResponse === "function") return map(response.toResponse(), set, request);
|
|
140
137
|
if (response?.constructor?.name === "Cookie" && response.jar) return new Response(response.value, set);
|
|
141
|
-
|
|
138
|
+
return new Response(response, set);
|
|
142
139
|
};
|
|
143
140
|
}
|
|
144
141
|
const mapResponseFallback = mapFallback(mapResponse);
|
|
@@ -14,10 +14,7 @@ function handleElysiaFile(file, set = { headers: nullObject() }, request) {
|
|
|
14
14
|
const stats = file.stats;
|
|
15
15
|
if (stats) return stats.then((stat) => {
|
|
16
16
|
const size = stat.size;
|
|
17
|
-
if (size !== void 0 && set.status !== 206 && set.status !== 304 && set.status !== 412 && set.status !== 416)
|
|
18
|
-
headers["content-range"] = `bytes 0-${size - 1}/${size}`;
|
|
19
|
-
headers["content-length"] = size;
|
|
20
|
-
}
|
|
17
|
+
if (size !== void 0 && set.status !== 206 && set.status !== 304 && set.status !== 412 && set.status !== 416) headers["content-length"] = size;
|
|
21
18
|
return handleFile(file, set, request, size);
|
|
22
19
|
});
|
|
23
20
|
return handleFile(file.value, set, request);
|
|
@@ -116,7 +113,7 @@ function errorToResponse(error, set) {
|
|
|
116
113
|
headers
|
|
117
114
|
});
|
|
118
115
|
}
|
|
119
|
-
function mapFallback(map
|
|
116
|
+
function mapFallback(map) {
|
|
120
117
|
return (response, set, request) => {
|
|
121
118
|
if (response instanceof Response) return handleResponse(response, set, request);
|
|
122
119
|
if (response instanceof Promise) return response.then((x) => map(x, set, request));
|
|
@@ -137,7 +134,7 @@ function mapFallback(map, mustReturn = true) {
|
|
|
137
134
|
if (Array.isArray(response)) return Response.json(response);
|
|
138
135
|
if (typeof response?.toResponse === "function") return map(response.toResponse(), set, request);
|
|
139
136
|
if (response?.constructor?.name === "Cookie" && response.jar) return new Response(response.value, set);
|
|
140
|
-
|
|
137
|
+
return new Response(response, set);
|
|
141
138
|
};
|
|
142
139
|
}
|
|
143
140
|
const mapResponseFallback = mapFallback(mapResponse);
|
package/dist/base.js
CHANGED
|
@@ -33,11 +33,7 @@ var Elysia = class Elysia {
|
|
|
33
33
|
#declaredRoutes;
|
|
34
34
|
#routeSources;
|
|
35
35
|
#cachedHistory;
|
|
36
|
-
#lazyPlan;
|
|
37
|
-
#lazyPlanBase;
|
|
38
|
-
#flushingLazyPlan;
|
|
39
36
|
get history() {
|
|
40
|
-
if (this.#lazyPlan) this.#flushLazyPlan();
|
|
41
37
|
if (this.#cachedHistory) return this.#cachedHistory;
|
|
42
38
|
if (!this.#declaredRoutes?.length) return emptyHistory;
|
|
43
39
|
const history = new Array(this.#declaredRoutes.length);
|
|
@@ -54,7 +50,6 @@ var Elysia = class Elysia {
|
|
|
54
50
|
return this.#cachedHistory = Object.freeze(history);
|
|
55
51
|
}
|
|
56
52
|
get ["~routes"]() {
|
|
57
|
-
if (this.#lazyPlan) this.#flushLazyPlan();
|
|
58
53
|
if (!this.#declaredRoutes?.length) return [];
|
|
59
54
|
const routes = this.#declaredRoutes;
|
|
60
55
|
if (!this["~ext"]?.macro && !this["~scopeChildren"]) return routes;
|
|
@@ -89,7 +84,6 @@ var Elysia = class Elysia {
|
|
|
89
84
|
if (config?.name) this.#hash = require_utils.fnv1a(config.seed ? `${config.name}_${typeof config.seed === "object" ? JSON.stringify(config.seed, require_utils.serializeMacroSeed) : config.seed}` : config.name);
|
|
90
85
|
}
|
|
91
86
|
get routes() {
|
|
92
|
-
if (this.#lazyPlan) this.#flushLazyPlan();
|
|
93
87
|
if (!this.#declaredRoutes?.length) return [];
|
|
94
88
|
if (this.#cachedRoutes) return this.#cachedRoutes;
|
|
95
89
|
const routes = this["~routes"].map(([method, path, handler, instance, hook, appHook, inheritedChain, macroScope]) => {
|
|
@@ -548,7 +542,6 @@ var Elysia = class Elysia {
|
|
|
548
542
|
this.#macroBaseline = prevBaseline;
|
|
549
543
|
}
|
|
550
544
|
if (result && typeof result.then === "function") {
|
|
551
|
-
if (this.#useLazyCompose) throw new Error("[Elysia] experimental.lazyCompose does not support a functional `use` that returns a Promise (async plugin).");
|
|
552
545
|
const beforeMacro = new Map(Object.entries(this["~ext"]?.macro ?? require_utils.nullObject()));
|
|
553
546
|
return this.#useAsync(result.then((value) => {
|
|
554
547
|
const after = this["~ext"]?.macro;
|
|
@@ -560,20 +553,14 @@ var Elysia = class Elysia {
|
|
|
560
553
|
}
|
|
561
554
|
return this;
|
|
562
555
|
}
|
|
563
|
-
if (typeof app.then === "function")
|
|
564
|
-
if (this.#useLazyCompose) throw new Error("[Elysia] experimental.lazyCompose does not support `.use(Promise)`. Remove the flag for this instance or await the plugin before `.use`.");
|
|
565
|
-
return this.#useAsync(app);
|
|
566
|
-
}
|
|
556
|
+
if (typeof app.then === "function") return this.#useAsync(app);
|
|
567
557
|
if (Array.isArray(app)) {
|
|
568
558
|
for (const plugin of app) this.use(plugin);
|
|
569
559
|
return this;
|
|
570
560
|
}
|
|
571
561
|
if (typeof app === "object" && "default" in app && app.default && !("~config" in app)) return this.use(app.default);
|
|
572
562
|
if (app === this) return this;
|
|
573
|
-
if (app.pending)
|
|
574
|
-
if (this.#useLazyCompose) throw new Error("[Elysia] experimental.lazyCompose does not support a pending (async) plugin. Remove the flag for this instance or await `plugin.modules` before `.use`.");
|
|
575
|
-
return this.#useAsync(app.modules.then(() => app));
|
|
576
|
-
}
|
|
563
|
+
if (app.pending) return this.#useAsync(app.modules.then(() => app));
|
|
577
564
|
this.#use(app);
|
|
578
565
|
return this;
|
|
579
566
|
}
|
|
@@ -612,26 +599,9 @@ var Elysia = class Elysia {
|
|
|
612
599
|
throw new Error(`[Elysia] Macro "${macroName}" can be only define once`);
|
|
613
600
|
}
|
|
614
601
|
if (app["~hasTrace"]) this["~hasTrace"] = true;
|
|
615
|
-
if (app.#declaredRoutes?.length
|
|
602
|
+
if (app.#declaredRoutes?.length) {
|
|
616
603
|
if (app["~hasWS"]) this["~hasWS"] = true;
|
|
617
|
-
|
|
618
|
-
if (!this.#lazyPlan) {
|
|
619
|
-
this.#lazyPlan = [];
|
|
620
|
-
this.#lazyPlanBase = this.#declaredRoutes?.length ?? 0;
|
|
621
|
-
}
|
|
622
|
-
this.#lazyPlan.push({
|
|
623
|
-
kind: "use",
|
|
624
|
-
child: app,
|
|
625
|
-
preChain: this["~hookChain"],
|
|
626
|
-
childBaseLen: app.#lazyPlan ? app.#lazyPlanBase ?? 0 : app.#declaredRoutes?.length ?? 0,
|
|
627
|
-
childPlan: app.#lazyPlan,
|
|
628
|
-
childPlanLen: app.#lazyPlan?.length ?? 0,
|
|
629
|
-
source: name
|
|
630
|
-
});
|
|
631
|
-
} else {
|
|
632
|
-
if (app.#lazyPlan) app.#flushLazyPlan();
|
|
633
|
-
if (app.#declaredRoutes?.length) this.#emitChildRoutes(app, this["~hookChain"], name);
|
|
634
|
-
}
|
|
604
|
+
this.#emitChildRoutes(app, this["~hookChain"], name);
|
|
635
605
|
}
|
|
636
606
|
if (app["~scopeChildren"]) {
|
|
637
607
|
const children = this["~scopeChildren"] ??= [];
|
|
@@ -771,9 +741,6 @@ var Elysia = class Elysia {
|
|
|
771
741
|
};
|
|
772
742
|
}
|
|
773
743
|
}
|
|
774
|
-
get #useLazyCompose() {
|
|
775
|
-
return this["~config"]?.experimental?.lazyCompose === true && !require_compile_aot.Capture.isCapturing() && !require_compile_aot.Capture.isAotBuildEnv();
|
|
776
|
-
}
|
|
777
744
|
#emitChildRoutes(app, preChain, name) {
|
|
778
745
|
const declared = app.#declaredRoutes;
|
|
779
746
|
if (!declared?.length) return;
|
|
@@ -812,58 +779,6 @@ var Elysia = class Elysia {
|
|
|
812
779
|
macroScope
|
|
813
780
|
], source);
|
|
814
781
|
}
|
|
815
|
-
#emitLazyRoute(route, owner, macroScope, accPrefix, over, source) {
|
|
816
|
-
const childChain = route[6];
|
|
817
|
-
let inheritedChain;
|
|
818
|
-
if (childChain === void 0) inheritedChain = over;
|
|
819
|
-
else if (over === void 0) inheritedChain = childChain;
|
|
820
|
-
else inheritedChain = {
|
|
821
|
-
combine: childChain,
|
|
822
|
-
over
|
|
823
|
-
};
|
|
824
|
-
this.#emitRoute(route, owner, macroScope, accPrefix, inheritedChain, source);
|
|
825
|
-
}
|
|
826
|
-
#emitLazyNode(node, usingNode, accPrefix, over, macroScope, baseLen, plan, planLen, source) {
|
|
827
|
-
if (usingNode["~scopeChild"]) macroScope = usingNode;
|
|
828
|
-
const declared = node.#declaredRoutes;
|
|
829
|
-
if (declared) for (let i = 0; i < baseLen && i < declared.length; i++) this.#emitLazyRoute(declared[i], node, macroScope, accPrefix, over, source);
|
|
830
|
-
if (!plan) return;
|
|
831
|
-
const childAccPrefix = node["~Prefix"] ? accPrefix ? require_utils.joinPath(accPrefix, node["~Prefix"]) : node["~Prefix"] : accPrefix;
|
|
832
|
-
for (let i = 0; i < planLen && i < plan.length; i++) {
|
|
833
|
-
const entry = plan[i];
|
|
834
|
-
if (entry.kind === "route") {
|
|
835
|
-
this.#emitLazyRoute(entry.route, node, macroScope, accPrefix, over, entry.source);
|
|
836
|
-
continue;
|
|
837
|
-
}
|
|
838
|
-
const edgeOver = entry.preChain === void 0 ? over : over === void 0 ? entry.preChain : {
|
|
839
|
-
combine: entry.preChain,
|
|
840
|
-
over
|
|
841
|
-
};
|
|
842
|
-
this.#emitLazyNode(entry.child, node, childAccPrefix, edgeOver, macroScope, entry.childBaseLen, entry.childPlan, entry.childPlanLen, entry.source);
|
|
843
|
-
}
|
|
844
|
-
}
|
|
845
|
-
#flushLazyPlan() {
|
|
846
|
-
const plan = this.#lazyPlan;
|
|
847
|
-
if (!plan) return;
|
|
848
|
-
if (this.#flushingLazyPlan) throw new Error("[Elysia] experimental.lazyCompose, cyclic plugin references are unsupported under the flag");
|
|
849
|
-
this.#flushingLazyPlan = true;
|
|
850
|
-
this.#lazyPlan = void 0;
|
|
851
|
-
this.#lazyPlanBase = 0;
|
|
852
|
-
try {
|
|
853
|
-
const childAccPrefix = this["~Prefix"];
|
|
854
|
-
for (let i = 0; i < plan.length; i++) {
|
|
855
|
-
const entry = plan[i];
|
|
856
|
-
if (entry.kind === "route") {
|
|
857
|
-
this.#registerRoute(entry.route, entry.source);
|
|
858
|
-
continue;
|
|
859
|
-
}
|
|
860
|
-
const edgeOver = entry.preChain;
|
|
861
|
-
this.#emitLazyNode(entry.child, this, childAccPrefix, edgeOver, void 0, entry.childBaseLen, entry.childPlan, entry.childPlanLen, entry.source);
|
|
862
|
-
}
|
|
863
|
-
} finally {
|
|
864
|
-
this.#flushingLazyPlan = false;
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
782
|
#compactRouteOwner(app, route) {
|
|
868
783
|
if (route[3] !== app) return route[3];
|
|
869
784
|
if (route[0] === "WS" || route[4] !== void 0 || route[7] !== void 0 || typeof route[2] !== "function" || route[2]["~mount"]) return route[3];
|
|
@@ -950,19 +865,6 @@ var Elysia = class Elysia {
|
|
|
950
865
|
}
|
|
951
866
|
#registerRoute(route, source) {
|
|
952
867
|
this.#assertMutable("route");
|
|
953
|
-
if (this.#lazyPlan) {
|
|
954
|
-
this.#lazyPlan.push({
|
|
955
|
-
kind: "route",
|
|
956
|
-
route,
|
|
957
|
-
source
|
|
958
|
-
});
|
|
959
|
-
this.#cachedHistory = void 0;
|
|
960
|
-
this.#cachedRoutes = void 0;
|
|
961
|
-
this.#compiled = void 0;
|
|
962
|
-
this.#fetchFn = void 0;
|
|
963
|
-
this.#routerBuilt = false;
|
|
964
|
-
return;
|
|
965
|
-
}
|
|
966
868
|
const routes = this.#declaredRoutes ??= [];
|
|
967
869
|
const sequence = routes.length;
|
|
968
870
|
routes.push(route);
|
|
@@ -1258,7 +1160,6 @@ var Elysia = class Elysia {
|
|
|
1258
1160
|
}
|
|
1259
1161
|
#routerBuilt = false;
|
|
1260
1162
|
#buildRouter(seal = false) {
|
|
1261
|
-
if (this.#lazyPlan) this.#flushLazyPlan();
|
|
1262
1163
|
if (this.#routerBuilt) {
|
|
1263
1164
|
if (seal && this["~generation"] === void 0) this.#publishGeneration();
|
|
1264
1165
|
return;
|
package/dist/base.mjs
CHANGED
|
@@ -30,11 +30,7 @@ var Elysia = class Elysia {
|
|
|
30
30
|
#declaredRoutes;
|
|
31
31
|
#routeSources;
|
|
32
32
|
#cachedHistory;
|
|
33
|
-
#lazyPlan;
|
|
34
|
-
#lazyPlanBase;
|
|
35
|
-
#flushingLazyPlan;
|
|
36
33
|
get history() {
|
|
37
|
-
if (this.#lazyPlan) this.#flushLazyPlan();
|
|
38
34
|
if (this.#cachedHistory) return this.#cachedHistory;
|
|
39
35
|
if (!this.#declaredRoutes?.length) return emptyHistory;
|
|
40
36
|
const history = new Array(this.#declaredRoutes.length);
|
|
@@ -51,7 +47,6 @@ var Elysia = class Elysia {
|
|
|
51
47
|
return this.#cachedHistory = Object.freeze(history);
|
|
52
48
|
}
|
|
53
49
|
get ["~routes"]() {
|
|
54
|
-
if (this.#lazyPlan) this.#flushLazyPlan();
|
|
55
50
|
if (!this.#declaredRoutes?.length) return [];
|
|
56
51
|
const routes = this.#declaredRoutes;
|
|
57
52
|
if (!this["~ext"]?.macro && !this["~scopeChildren"]) return routes;
|
|
@@ -86,7 +81,6 @@ var Elysia = class Elysia {
|
|
|
86
81
|
if (config?.name) this.#hash = fnv1a(config.seed ? `${config.name}_${typeof config.seed === "object" ? JSON.stringify(config.seed, serializeMacroSeed) : config.seed}` : config.name);
|
|
87
82
|
}
|
|
88
83
|
get routes() {
|
|
89
|
-
if (this.#lazyPlan) this.#flushLazyPlan();
|
|
90
84
|
if (!this.#declaredRoutes?.length) return [];
|
|
91
85
|
if (this.#cachedRoutes) return this.#cachedRoutes;
|
|
92
86
|
const routes = this["~routes"].map(([method, path, handler, instance, hook, appHook, inheritedChain, macroScope]) => {
|
|
@@ -545,7 +539,6 @@ var Elysia = class Elysia {
|
|
|
545
539
|
this.#macroBaseline = prevBaseline;
|
|
546
540
|
}
|
|
547
541
|
if (result && typeof result.then === "function") {
|
|
548
|
-
if (this.#useLazyCompose) throw new Error("[Elysia] experimental.lazyCompose does not support a functional `use` that returns a Promise (async plugin).");
|
|
549
542
|
const beforeMacro = new Map(Object.entries(this["~ext"]?.macro ?? nullObject()));
|
|
550
543
|
return this.#useAsync(result.then((value) => {
|
|
551
544
|
const after = this["~ext"]?.macro;
|
|
@@ -557,20 +550,14 @@ var Elysia = class Elysia {
|
|
|
557
550
|
}
|
|
558
551
|
return this;
|
|
559
552
|
}
|
|
560
|
-
if (typeof app.then === "function")
|
|
561
|
-
if (this.#useLazyCompose) throw new Error("[Elysia] experimental.lazyCompose does not support `.use(Promise)`. Remove the flag for this instance or await the plugin before `.use`.");
|
|
562
|
-
return this.#useAsync(app);
|
|
563
|
-
}
|
|
553
|
+
if (typeof app.then === "function") return this.#useAsync(app);
|
|
564
554
|
if (Array.isArray(app)) {
|
|
565
555
|
for (const plugin of app) this.use(plugin);
|
|
566
556
|
return this;
|
|
567
557
|
}
|
|
568
558
|
if (typeof app === "object" && "default" in app && app.default && !("~config" in app)) return this.use(app.default);
|
|
569
559
|
if (app === this) return this;
|
|
570
|
-
if (app.pending)
|
|
571
|
-
if (this.#useLazyCompose) throw new Error("[Elysia] experimental.lazyCompose does not support a pending (async) plugin. Remove the flag for this instance or await `plugin.modules` before `.use`.");
|
|
572
|
-
return this.#useAsync(app.modules.then(() => app));
|
|
573
|
-
}
|
|
560
|
+
if (app.pending) return this.#useAsync(app.modules.then(() => app));
|
|
574
561
|
this.#use(app);
|
|
575
562
|
return this;
|
|
576
563
|
}
|
|
@@ -609,26 +596,9 @@ var Elysia = class Elysia {
|
|
|
609
596
|
throw new Error(`[Elysia] Macro "${macroName}" can be only define once`);
|
|
610
597
|
}
|
|
611
598
|
if (app["~hasTrace"]) this["~hasTrace"] = true;
|
|
612
|
-
if (app.#declaredRoutes?.length
|
|
599
|
+
if (app.#declaredRoutes?.length) {
|
|
613
600
|
if (app["~hasWS"]) this["~hasWS"] = true;
|
|
614
|
-
|
|
615
|
-
if (!this.#lazyPlan) {
|
|
616
|
-
this.#lazyPlan = [];
|
|
617
|
-
this.#lazyPlanBase = this.#declaredRoutes?.length ?? 0;
|
|
618
|
-
}
|
|
619
|
-
this.#lazyPlan.push({
|
|
620
|
-
kind: "use",
|
|
621
|
-
child: app,
|
|
622
|
-
preChain: this["~hookChain"],
|
|
623
|
-
childBaseLen: app.#lazyPlan ? app.#lazyPlanBase ?? 0 : app.#declaredRoutes?.length ?? 0,
|
|
624
|
-
childPlan: app.#lazyPlan,
|
|
625
|
-
childPlanLen: app.#lazyPlan?.length ?? 0,
|
|
626
|
-
source: name
|
|
627
|
-
});
|
|
628
|
-
} else {
|
|
629
|
-
if (app.#lazyPlan) app.#flushLazyPlan();
|
|
630
|
-
if (app.#declaredRoutes?.length) this.#emitChildRoutes(app, this["~hookChain"], name);
|
|
631
|
-
}
|
|
601
|
+
this.#emitChildRoutes(app, this["~hookChain"], name);
|
|
632
602
|
}
|
|
633
603
|
if (app["~scopeChildren"]) {
|
|
634
604
|
const children = this["~scopeChildren"] ??= [];
|
|
@@ -768,9 +738,6 @@ var Elysia = class Elysia {
|
|
|
768
738
|
};
|
|
769
739
|
}
|
|
770
740
|
}
|
|
771
|
-
get #useLazyCompose() {
|
|
772
|
-
return this["~config"]?.experimental?.lazyCompose === true && !Capture.isCapturing() && !Capture.isAotBuildEnv();
|
|
773
|
-
}
|
|
774
741
|
#emitChildRoutes(app, preChain, name) {
|
|
775
742
|
const declared = app.#declaredRoutes;
|
|
776
743
|
if (!declared?.length) return;
|
|
@@ -809,58 +776,6 @@ var Elysia = class Elysia {
|
|
|
809
776
|
macroScope
|
|
810
777
|
], source);
|
|
811
778
|
}
|
|
812
|
-
#emitLazyRoute(route, owner, macroScope, accPrefix, over, source) {
|
|
813
|
-
const childChain = route[6];
|
|
814
|
-
let inheritedChain;
|
|
815
|
-
if (childChain === void 0) inheritedChain = over;
|
|
816
|
-
else if (over === void 0) inheritedChain = childChain;
|
|
817
|
-
else inheritedChain = {
|
|
818
|
-
combine: childChain,
|
|
819
|
-
over
|
|
820
|
-
};
|
|
821
|
-
this.#emitRoute(route, owner, macroScope, accPrefix, inheritedChain, source);
|
|
822
|
-
}
|
|
823
|
-
#emitLazyNode(node, usingNode, accPrefix, over, macroScope, baseLen, plan, planLen, source) {
|
|
824
|
-
if (usingNode["~scopeChild"]) macroScope = usingNode;
|
|
825
|
-
const declared = node.#declaredRoutes;
|
|
826
|
-
if (declared) for (let i = 0; i < baseLen && i < declared.length; i++) this.#emitLazyRoute(declared[i], node, macroScope, accPrefix, over, source);
|
|
827
|
-
if (!plan) return;
|
|
828
|
-
const childAccPrefix = node["~Prefix"] ? accPrefix ? joinPath(accPrefix, node["~Prefix"]) : node["~Prefix"] : accPrefix;
|
|
829
|
-
for (let i = 0; i < planLen && i < plan.length; i++) {
|
|
830
|
-
const entry = plan[i];
|
|
831
|
-
if (entry.kind === "route") {
|
|
832
|
-
this.#emitLazyRoute(entry.route, node, macroScope, accPrefix, over, entry.source);
|
|
833
|
-
continue;
|
|
834
|
-
}
|
|
835
|
-
const edgeOver = entry.preChain === void 0 ? over : over === void 0 ? entry.preChain : {
|
|
836
|
-
combine: entry.preChain,
|
|
837
|
-
over
|
|
838
|
-
};
|
|
839
|
-
this.#emitLazyNode(entry.child, node, childAccPrefix, edgeOver, macroScope, entry.childBaseLen, entry.childPlan, entry.childPlanLen, entry.source);
|
|
840
|
-
}
|
|
841
|
-
}
|
|
842
|
-
#flushLazyPlan() {
|
|
843
|
-
const plan = this.#lazyPlan;
|
|
844
|
-
if (!plan) return;
|
|
845
|
-
if (this.#flushingLazyPlan) throw new Error("[Elysia] experimental.lazyCompose, cyclic plugin references are unsupported under the flag");
|
|
846
|
-
this.#flushingLazyPlan = true;
|
|
847
|
-
this.#lazyPlan = void 0;
|
|
848
|
-
this.#lazyPlanBase = 0;
|
|
849
|
-
try {
|
|
850
|
-
const childAccPrefix = this["~Prefix"];
|
|
851
|
-
for (let i = 0; i < plan.length; i++) {
|
|
852
|
-
const entry = plan[i];
|
|
853
|
-
if (entry.kind === "route") {
|
|
854
|
-
this.#registerRoute(entry.route, entry.source);
|
|
855
|
-
continue;
|
|
856
|
-
}
|
|
857
|
-
const edgeOver = entry.preChain;
|
|
858
|
-
this.#emitLazyNode(entry.child, this, childAccPrefix, edgeOver, void 0, entry.childBaseLen, entry.childPlan, entry.childPlanLen, entry.source);
|
|
859
|
-
}
|
|
860
|
-
} finally {
|
|
861
|
-
this.#flushingLazyPlan = false;
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
779
|
#compactRouteOwner(app, route) {
|
|
865
780
|
if (route[3] !== app) return route[3];
|
|
866
781
|
if (route[0] === "WS" || route[4] !== void 0 || route[7] !== void 0 || typeof route[2] !== "function" || route[2]["~mount"]) return route[3];
|
|
@@ -947,19 +862,6 @@ var Elysia = class Elysia {
|
|
|
947
862
|
}
|
|
948
863
|
#registerRoute(route, source) {
|
|
949
864
|
this.#assertMutable("route");
|
|
950
|
-
if (this.#lazyPlan) {
|
|
951
|
-
this.#lazyPlan.push({
|
|
952
|
-
kind: "route",
|
|
953
|
-
route,
|
|
954
|
-
source
|
|
955
|
-
});
|
|
956
|
-
this.#cachedHistory = void 0;
|
|
957
|
-
this.#cachedRoutes = void 0;
|
|
958
|
-
this.#compiled = void 0;
|
|
959
|
-
this.#fetchFn = void 0;
|
|
960
|
-
this.#routerBuilt = false;
|
|
961
|
-
return;
|
|
962
|
-
}
|
|
963
865
|
const routes = this.#declaredRoutes ??= [];
|
|
964
866
|
const sequence = routes.length;
|
|
965
867
|
routes.push(route);
|
|
@@ -1255,7 +1157,6 @@ var Elysia = class Elysia {
|
|
|
1255
1157
|
}
|
|
1256
1158
|
#routerBuilt = false;
|
|
1257
1159
|
#buildRouter(seal = false) {
|
|
1258
|
-
if (this.#lazyPlan) this.#flushLazyPlan();
|
|
1259
1160
|
if (this.#routerBuilt) {
|
|
1260
1161
|
if (seal && this["~generation"] === void 0) this.#publishGeneration();
|
|
1261
1162
|
return;
|
|
@@ -1,8 +1,24 @@
|
|
|
1
|
-
import { CaptureImpl } from "./aot.js";
|
|
1
|
+
import { CaptureImpl, CapturedHandler, CapturedValidator, CompiledSnapshot } from "./aot.js";
|
|
2
2
|
|
|
3
3
|
//#region src/compile/aot-capture.d.ts
|
|
4
4
|
declare function resetCompactErrorWarnings(): void;
|
|
5
|
+
declare function beginValidatorCapture(): void;
|
|
6
|
+
declare function abortCapture(): void;
|
|
7
|
+
declare function endValidatorCapture(): CapturedValidator[];
|
|
8
|
+
declare function endHandlerCapture(): CapturedHandler[];
|
|
9
|
+
/** @internal deterministic session/capture assertions. */
|
|
10
|
+
declare const getCompilerSessionDiagnostics: () => {
|
|
11
|
+
active: boolean;
|
|
12
|
+
appAttached: boolean;
|
|
13
|
+
validators: number;
|
|
14
|
+
handlers: number;
|
|
15
|
+
sucrose: number;
|
|
16
|
+
};
|
|
17
|
+
/** @internal preserve registry around in-process AOT analysis */
|
|
18
|
+
declare const snapshotCompiled: () => CompiledSnapshot;
|
|
19
|
+
/** @internal restore registry after in-process AOT analysis */
|
|
20
|
+
declare function restoreCompiled(snapshot: CompiledSnapshot): void;
|
|
5
21
|
declare const impl: CaptureImpl;
|
|
6
22
|
declare function installCaptureImpl(): void;
|
|
7
23
|
//#endregion
|
|
8
|
-
export { impl as captureImplementation, installCaptureImpl, resetCompactErrorWarnings };
|
|
24
|
+
export { abortCapture, beginValidatorCapture, impl as captureImplementation, endHandlerCapture, endValidatorCapture, getCompilerSessionDiagnostics, installCaptureImpl, resetCompactErrorWarnings, restoreCompiled, snapshotCompiled };
|