elysia 2.0.0-beta.2 → 2.0.0-beta.21
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.d.ts +18 -2
- package/dist/adapter/bun/index.js +467 -110
- package/dist/adapter/bun/index.mjs +467 -112
- package/dist/adapter/types.d.ts +2 -21
- package/dist/adapter/utils.d.ts +14 -3
- package/dist/adapter/utils.js +146 -87
- package/dist/adapter/utils.mjs +148 -90
- package/dist/adapter/web-standard/handler.d.ts +1 -1
- package/dist/adapter/web-standard/handler.js +47 -36
- package/dist/adapter/web-standard/handler.mjs +48 -37
- package/dist/adapter/web-standard/index.js +2 -30
- package/dist/adapter/web-standard/index.mjs +2 -30
- package/dist/adapter/web-standard/utils.js +5 -18
- package/dist/adapter/web-standard/utils.mjs +5 -18
- package/dist/base.d.ts +99 -67
- package/dist/base.js +678 -510
- package/dist/base.mjs +682 -514
- package/dist/compile/aot-capture.d.ts +2 -13
- package/dist/compile/aot-capture.js +26 -69
- package/dist/compile/aot-capture.mjs +28 -67
- package/dist/compile/aot-emit.d.ts +9 -7
- package/dist/compile/aot-emit.js +42 -19
- package/dist/compile/aot-emit.mjs +42 -20
- package/dist/compile/aot.d.ts +17 -19
- package/dist/compile/aot.js +41 -51
- package/dist/compile/aot.mjs +39 -49
- package/dist/compile/handler/descriptor.d.ts +9 -12
- package/dist/compile/handler/descriptor.js +19 -44
- package/dist/compile/handler/descriptor.mjs +20 -42
- package/dist/compile/handler/frozen-validator.d.ts +5 -10
- package/dist/compile/handler/frozen-validator.js +55 -105
- package/dist/compile/handler/frozen-validator.mjs +53 -105
- package/dist/compile/handler/index.d.ts +7 -5
- package/dist/compile/handler/index.js +270 -111
- package/dist/compile/handler/index.mjs +270 -113
- package/dist/compile/handler/jit.d.ts +19 -17
- package/dist/compile/handler/jit.js +222 -149
- package/dist/compile/handler/jit.mjs +224 -152
- package/dist/compile/handler/params.d.ts +1 -4
- package/dist/compile/handler/params.js +10 -5
- package/dist/compile/handler/params.mjs +14 -8
- package/dist/compile/handler/reconstruct.d.ts +2 -2
- package/dist/compile/handler/reconstruct.js +6 -4
- package/dist/compile/handler/reconstruct.mjs +6 -4
- package/dist/compile/handler/static-clone-resolver.d.ts +6 -0
- package/dist/compile/handler/static-clone-resolver.js +8 -0
- package/dist/compile/handler/static-clone-resolver.mjs +7 -0
- package/dist/compile/handler/utils.d.ts +22 -11
- package/dist/compile/handler/utils.js +159 -253
- package/dist/compile/handler/utils.mjs +155 -252
- package/dist/compile/jit-probe.d.ts +2 -2
- package/dist/compile/jit-probe.js +2 -3
- package/dist/compile/jit-probe.mjs +2 -3
- package/dist/compile/lexer.d.ts +7 -4
- package/dist/compile/lexer.js +268 -6
- package/dist/compile/lexer.mjs +268 -4
- package/dist/compile/utils.js +7 -4
- package/dist/compile/utils.mjs +7 -4
- package/dist/compiled.d.ts +0 -1
- package/dist/compiled.js +0 -1
- package/dist/compiled.mjs +0 -1
- package/dist/context.d.ts +14 -4
- package/dist/context.js +17 -32
- package/dist/context.mjs +19 -34
- package/dist/cookie/config.d.ts +7 -2
- package/dist/cookie/config.js +76 -16
- package/dist/cookie/config.mjs +77 -18
- package/dist/cookie/cookie.d.ts +1 -1
- package/dist/cookie/cookie.js +8 -10
- package/dist/cookie/cookie.mjs +8 -10
- package/dist/cookie/crypto.d.ts +8 -7
- package/dist/cookie/crypto.js +51 -40
- package/dist/cookie/crypto.mjs +51 -41
- package/dist/cookie/error.d.ts +1 -2
- package/dist/cookie/error.js +6 -4
- package/dist/cookie/error.mjs +6 -4
- package/dist/cookie/lib.js +7 -2
- package/dist/cookie/lib.mjs +7 -2
- package/dist/cookie/serialize.js +1 -1
- package/dist/cookie/serialize.mjs +1 -1
- package/dist/cookie/types.d.ts +10 -0
- package/dist/cookie/utils.d.ts +4 -8
- package/dist/cookie/utils.js +86 -52
- package/dist/cookie/utils.mjs +89 -54
- package/dist/error.d.ts +113 -103
- package/dist/error.js +181 -117
- package/dist/error.mjs +179 -118
- package/dist/generation.d.ts +2 -2
- package/dist/handler/error.d.ts +26 -15
- package/dist/handler/error.js +77 -96
- package/dist/handler/error.mjs +74 -97
- package/dist/handler/fetch.js +87 -108
- package/dist/handler/fetch.mjs +89 -110
- package/dist/handler/utils.d.ts +12 -6
- package/dist/handler/utils.js +84 -28
- package/dist/handler/utils.mjs +80 -28
- package/dist/index.d.ts +12 -12
- package/dist/index.js +2 -9
- package/dist/index.mjs +1 -1
- package/dist/memory.js +1 -1
- package/dist/memory.mjs +1 -1
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/bun.d.ts +8 -1
- package/dist/plugin/aot/bun.js +16 -9
- package/dist/plugin/aot/bun.mjs +17 -10
- package/dist/plugin/aot/core.d.ts +52 -60
- package/dist/plugin/aot/core.js +208 -109
- package/dist/plugin/aot/core.mjs +205 -111
- package/dist/plugin/aot/esbuild.js +8 -5
- package/dist/plugin/aot/esbuild.mjs +9 -6
- package/dist/plugin/aot/hooks.d.ts +6 -17
- package/dist/plugin/aot/hooks.js +36 -14
- package/dist/plugin/aot/hooks.mjs +37 -16
- package/dist/plugin/aot/rspack-loader.d.ts +1 -5
- package/dist/plugin/aot/rspack-loader.js +1 -10
- package/dist/plugin/aot/rspack-loader.mjs +1 -10
- package/dist/plugin/aot/rspack.js +2 -5
- package/dist/plugin/aot/rspack.mjs +3 -6
- package/dist/plugin/aot/source.d.ts +6 -42
- package/dist/plugin/aot/source.js +71 -71
- package/dist/plugin/aot/source.mjs +72 -72
- package/dist/plugin/aot/treeshake.js +2 -6
- package/dist/plugin/aot/treeshake.mjs +2 -6
- package/dist/plugin/aot/unplugin.d.ts +1 -4
- package/dist/plugin/aot/unplugin.js +4 -13
- package/dist/plugin/aot/unplugin.mjs +4 -13
- package/dist/plugin/aot/vite.d.ts +2 -6
- package/dist/plugin/aot/worker.js +2 -2
- package/dist/plugin/aot/worker.mjs +2 -2
- package/dist/plugin/auto-head.js +1 -10
- package/dist/plugin/auto-head.mjs +1 -10
- package/dist/plugin/trace.d.ts +2 -1
- package/dist/route-table.d.ts +3 -0
- package/dist/route-table.js +16 -11
- package/dist/route-table.mjs +16 -11
- package/dist/schema-snapshot.d.ts +0 -4
- package/dist/schema-snapshot.js +32 -49
- package/dist/schema-snapshot.mjs +32 -49
- package/dist/sucrose.d.ts +6 -55
- package/dist/sucrose.js +103 -731
- package/dist/sucrose.mjs +102 -724
- package/dist/trace.d.ts +5 -8
- package/dist/trace.js +23 -134
- package/dist/trace.mjs +24 -135
- package/dist/type/bridge-live.d.ts +4 -2
- package/dist/type/bridge-live.js +6 -3
- package/dist/type/bridge-live.mjs +4 -2
- package/dist/type/bridge.d.ts +6 -4
- package/dist/type/bridge.js +17 -9
- package/dist/type/bridge.mjs +5 -3
- package/dist/type/coerce-plan.d.ts +5 -5
- package/dist/type/coerce-plan.js +41 -39
- package/dist/type/coerce-plan.mjs +43 -39
- package/dist/type/coerce.d.ts +3 -7
- package/dist/type/coerce.js +18 -75
- package/dist/type/coerce.mjs +19 -76
- package/dist/type/compat.d.ts +3 -0
- package/dist/type/compat.js +23 -14
- package/dist/type/compat.mjs +20 -10
- package/dist/type/elysia/array-buffer.d.ts +4 -1
- package/dist/type/elysia/array-buffer.js +17 -17
- package/dist/type/elysia/array-buffer.mjs +17 -17
- package/dist/type/elysia/array-string.js +2 -40
- package/dist/type/elysia/array-string.mjs +2 -39
- package/dist/type/elysia/array.js +5 -9
- package/dist/type/elysia/array.mjs +5 -9
- package/dist/type/elysia/boolean-string.js +2 -3
- package/dist/type/elysia/boolean-string.mjs +1 -1
- package/dist/type/elysia/boolean.js +3 -12
- package/dist/type/elysia/boolean.mjs +3 -11
- package/dist/type/elysia/cookie.d.ts +3 -4
- package/dist/type/elysia/cookie.js +5 -15
- package/dist/type/elysia/cookie.mjs +5 -15
- package/dist/type/elysia/date.js +13 -20
- package/dist/type/elysia/date.mjs +10 -16
- package/dist/type/elysia/file-type.d.ts +11 -4
- package/dist/type/elysia/file-type.js +17 -2
- package/dist/type/elysia/file-type.mjs +17 -3
- package/dist/type/elysia/file.d.ts +1 -3
- package/dist/type/elysia/file.js +11 -27
- package/dist/type/elysia/file.mjs +11 -12
- package/dist/type/elysia/files.js +7 -11
- package/dist/type/elysia/files.mjs +7 -10
- package/dist/type/elysia/form.js +2 -3
- package/dist/type/elysia/form.mjs +3 -3
- package/dist/type/elysia/integer-string.d.ts +1 -1
- package/dist/type/elysia/integer-string.js +4 -30
- package/dist/type/elysia/integer-string.mjs +5 -30
- package/dist/type/elysia/integer.js +3 -12
- package/dist/type/elysia/integer.mjs +3 -11
- package/dist/type/elysia/intersect.js +0 -5
- package/dist/type/elysia/intersect.mjs +0 -5
- package/dist/type/elysia/json-string.d.ts +7 -0
- package/dist/type/elysia/json-string.js +47 -0
- package/dist/type/elysia/json-string.mjs +46 -0
- package/dist/type/elysia/keep-config.d.ts +14 -0
- package/dist/type/elysia/keep-config.js +62 -0
- package/dist/type/elysia/keep-config.mjs +53 -0
- package/dist/type/elysia/maybe-empty.js +3 -4
- package/dist/type/elysia/maybe-empty.mjs +1 -1
- package/dist/type/elysia/nullable.js +2 -3
- package/dist/type/elysia/nullable.mjs +1 -1
- package/dist/type/elysia/number.d.ts +2 -1
- package/dist/type/elysia/number.js +19 -11
- package/dist/type/elysia/number.mjs +18 -10
- package/dist/type/elysia/numeric-enum.d.ts +1 -1
- package/dist/type/elysia/numeric-enum.js +4 -5
- package/dist/type/elysia/numeric-enum.mjs +3 -3
- package/dist/type/elysia/numeric.d.ts +4 -2
- package/dist/type/elysia/numeric.js +20 -17
- package/dist/type/elysia/numeric.mjs +19 -16
- package/dist/type/elysia/object-string.js +2 -37
- package/dist/type/elysia/object-string.mjs +2 -36
- package/dist/type/elysia/object.js +5 -9
- package/dist/type/elysia/object.mjs +5 -9
- package/dist/type/elysia/optional.js +8 -8
- package/dist/type/elysia/optional.mjs +7 -7
- package/dist/type/elysia/problem.d.ts +20 -0
- package/dist/type/elysia/problem.js +25 -0
- package/dist/type/elysia/problem.mjs +24 -0
- package/dist/type/elysia/string.js +4 -3
- package/dist/type/elysia/string.mjs +4 -2
- package/dist/type/elysia/uint8-array.d.ts +1 -1
- package/dist/type/elysia/uint8-array.js +5 -20
- package/dist/type/elysia/uint8-array.mjs +5 -19
- package/dist/type/elysia/union-enum.js +7 -8
- package/dist/type/elysia/union-enum.mjs +6 -6
- package/dist/type/elysia/union.js +0 -5
- package/dist/type/elysia/union.mjs +0 -5
- package/dist/type/elysia/utils.d.ts +2 -4
- package/dist/type/elysia/utils.js +10 -21
- package/dist/type/elysia/utils.mjs +7 -15
- package/dist/type/exports.d.ts +4 -2
- package/dist/type/exports.js +23 -2
- package/dist/type/exports.mjs +11 -2
- package/dist/type/index.d.ts +10 -2
- package/dist/type/index.js +62 -15
- package/dist/type/index.mjs +65 -11
- package/dist/type/shared.d.ts +3 -9
- package/dist/type/shared.js +44 -97
- package/dist/type/shared.mjs +43 -97
- package/dist/type/sync-require.d.ts +11 -0
- package/dist/type/sync-require.js +14 -0
- package/dist/type/sync-require.mjs +12 -0
- package/dist/type/typebox-system-lite.d.ts +2 -0
- package/dist/type/typebox-system-lite.js +34 -0
- package/dist/type/typebox-system-lite.mjs +3 -0
- package/dist/type/typebox-system-require.d.ts +7 -0
- package/dist/type/typebox-system-require.js +24 -0
- package/dist/type/typebox-system-require.mjs +23 -0
- package/dist/type/typebox-type-live.d.ts +11 -0
- package/dist/type/typebox-type-live.js +45 -0
- package/dist/type/typebox-type-live.mjs +20 -0
- package/dist/type/typebox-type.d.ts +34 -0
- package/dist/type/typebox-type.js +199 -0
- package/dist/type/typebox-type.mjs +86 -0
- package/dist/type/typebox-value-live.d.ts +11 -0
- package/dist/type/typebox-value-live.js +31 -0
- package/dist/type/typebox-value-live.mjs +13 -0
- package/dist/type/typebox-value-ops.d.ts +4 -0
- package/dist/type/typebox-value-ops.js +90 -0
- package/dist/type/typebox-value-ops.mjs +5 -0
- package/dist/type/typebox-value-require.d.ts +8 -0
- package/dist/type/typebox-value-require.js +28 -0
- package/dist/type/typebox-value-require.mjs +25 -0
- package/dist/type/typebox-value.d.ts +35 -0
- package/dist/type/typebox-value.js +161 -0
- package/dist/type/typebox-value.mjs +74 -0
- package/dist/type/utils.js +1 -10
- package/dist/type/utils.mjs +1 -10
- package/dist/type/validator/clean-safe.d.ts +2 -4
- package/dist/type/validator/clean-safe.js +15 -11
- package/dist/type/validator/clean-safe.mjs +16 -10
- package/dist/type/validator/custom-error.js +12 -16
- package/dist/type/validator/custom-error.mjs +11 -14
- package/dist/type/validator/default-precompute.d.ts +9 -1
- package/dist/type/validator/default-precompute.js +40 -77
- package/dist/type/validator/default-precompute.mjs +37 -74
- 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/exact-mirror-require.d.ts +4 -0
- package/dist/type/validator/exact-mirror-require.js +11 -0
- package/dist/type/validator/exact-mirror-require.mjs +9 -0
- package/dist/type/validator/exact-mirror.js +8 -8
- package/dist/type/validator/exact-mirror.mjs +9 -8
- package/dist/type/validator/frozen-check.js +5 -6
- package/dist/type/validator/frozen-check.mjs +6 -7
- package/dist/type/validator/index.d.ts +1 -0
- package/dist/type/validator/index.js +169 -166
- package/dist/type/validator/index.mjs +162 -158
- package/dist/type/validator/string-codec-aot.d.ts +2 -1
- package/dist/type/validator/string-codec-aot.js +8 -2
- package/dist/type/validator/string-codec-aot.mjs +7 -2
- package/dist/type/validator/validator-cache.d.ts +5 -4
- package/dist/type/validator/validator-cache.js +41 -24
- package/dist/type/validator/validator-cache.mjs +40 -22
- package/dist/types.d.ts +263 -95
- package/dist/universal/constants.d.ts +2 -1
- package/dist/universal/constants.js +3 -1
- package/dist/universal/constants.mjs +2 -1
- package/dist/universal/env.js +2 -3
- package/dist/universal/env.mjs +2 -3
- package/dist/universal/file.d.ts +6 -4
- package/dist/universal/file.js +11 -16
- package/dist/universal/file.mjs +12 -16
- package/dist/universal/index.d.ts +2 -2
- package/dist/universal/is-production.d.ts +1 -2
- package/dist/universal/is-production.js +1 -3
- package/dist/universal/is-production.mjs +2 -3
- package/dist/universal/server.d.ts +0 -272
- package/dist/utils.d.ts +43 -7
- package/dist/utils.js +181 -126
- package/dist/utils.mjs +168 -126
- package/dist/validator/index.d.ts +1 -1
- package/dist/validator/index.js +17 -30
- package/dist/validator/index.mjs +18 -31
- package/dist/validator/route.js +2 -1
- package/dist/validator/route.mjs +2 -1
- package/dist/ws/context.d.ts +8 -1
- package/dist/ws/context.js +68 -44
- package/dist/ws/context.mjs +67 -44
- package/dist/ws/parser.js +10 -20
- package/dist/ws/parser.mjs +10 -20
- package/dist/ws/route.d.ts +2 -2
- package/dist/ws/route.js +249 -141
- package/dist/ws/route.mjs +254 -146
- package/dist/ws/types.d.ts +2 -2
- package/package.json +23 -49
- package/dist/compile/analysis-cache.d.ts +0 -6
- package/dist/compile/analysis-cache.js +0 -12
- package/dist/compile/analysis-cache.mjs +0 -11
- package/dist/cookie/index.d.ts +0 -7
- package/dist/cookie/index.js +0 -13
- package/dist/cookie/index.mjs +0 -7
- package/dist/handler/index.d.ts +0 -2
- package/dist/handler/index.js +0 -5
- package/dist/handler/index.mjs +0 -3
package/dist/plugin/aot/core.js
CHANGED
|
@@ -20,8 +20,31 @@ function findPackageRoot(from = process.cwd()) {
|
|
|
20
20
|
return dir;
|
|
21
21
|
}
|
|
22
22
|
const resolveEntry = (entry) => (0, node_path.resolve)(findPackageRoot(), entry);
|
|
23
|
+
/** @internal Resolve the package condition used to evaluate an AOT entry. */
|
|
24
|
+
const resolveEntryModuleKind = (entry) => {
|
|
25
|
+
const entryPath = resolveEntry(entry);
|
|
26
|
+
switch ((0, node_path.extname)(entryPath)) {
|
|
27
|
+
case ".cjs":
|
|
28
|
+
case ".cts": return "cjs";
|
|
29
|
+
case ".mjs":
|
|
30
|
+
case ".mts":
|
|
31
|
+
case ".ts":
|
|
32
|
+
case ".tsx": return "esm";
|
|
33
|
+
case ".js":
|
|
34
|
+
case ".jsx": {
|
|
35
|
+
const packagePath = (0, node_path.join)(findPackageRoot((0, node_path.dirname)(entryPath)), "package.json");
|
|
36
|
+
if (!(0, node_fs.existsSync)(packagePath)) return "cjs";
|
|
37
|
+
const pkg = JSON.parse((0, node_fs.readFileSync)(packagePath, "utf8"));
|
|
38
|
+
if (pkg.type === "module") return "esm";
|
|
39
|
+
if (pkg.type === void 0 || pkg.type === "commonjs") return "cjs";
|
|
40
|
+
throw new Error(`[elysia-aot] package.json has unsupported "type" ${JSON.stringify(pkg.type)} for JavaScript entry ${JSON.stringify(entryPath)}.`);
|
|
41
|
+
}
|
|
42
|
+
default: throw new Error(`[elysia-aot] entry ${JSON.stringify(entryPath)} has an ambiguous module condition. Use a .cjs/.cts CommonJS entry or a .mjs/.mts/.ts/.tsx ESM entry; .js/.jsx follows the nearest package.json "type".`);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
23
45
|
const NO_STUB = {
|
|
24
46
|
jit: false,
|
|
47
|
+
staticClone: false,
|
|
25
48
|
ws: false,
|
|
26
49
|
reconstruct: false,
|
|
27
50
|
cookie: false,
|
|
@@ -29,6 +52,8 @@ const NO_STUB = {
|
|
|
29
52
|
sucrose: false,
|
|
30
53
|
compat: false,
|
|
31
54
|
bridge: false,
|
|
55
|
+
typeboxValue: false,
|
|
56
|
+
exactMirror: false,
|
|
32
57
|
adapter: false,
|
|
33
58
|
isProduction: false
|
|
34
59
|
};
|
|
@@ -49,20 +74,23 @@ const NO_STUB = {
|
|
|
49
74
|
* is not active, so the bridge must stay wired the ordinary way. No compat
|
|
50
75
|
* stub, no reroute.
|
|
51
76
|
*/
|
|
52
|
-
function planFromReport(strip, report, hasWS, mayTrace, aliases, allBridgeFree, zeroCapture, adapterStub = false, productionStub = true) {
|
|
77
|
+
function planFromReport(strip, report, hasWS, mayTrace, aliases, allBridgeFree, zeroCapture, adapterStub = false, productionStub = true, wsCookie = false, exactMirror = false) {
|
|
53
78
|
const jit = report.jit;
|
|
54
79
|
if (strip === true && !jit) throw new Error(`[elysia-aot] strip: true requires every route to be covered by the AOT handler manifest, but handler JIT is still reachable (${report.reasons.join(", ") || "unknown"}). Use strip: 'auto' to skip stubbing when the app is not fully precompiled.`);
|
|
55
80
|
const mode = !jit ? "off" : allBridgeFree ? "sealed" : hasWS && zeroCapture ? "off" : "wired";
|
|
56
81
|
return {
|
|
57
82
|
plan: {
|
|
58
83
|
jit,
|
|
84
|
+
staticClone: jit && !aliases.has("scl"),
|
|
59
85
|
ws: !hasWS,
|
|
60
86
|
reconstruct: jit && !aliases.has("va") && !aliases.has("cc") && !aliases.has("tr"),
|
|
61
|
-
cookie: jit && !aliases.has("cc"),
|
|
87
|
+
cookie: jit && !aliases.has("cc") && !wsCookie,
|
|
62
88
|
trace: !aliases.has("tr") && (jit || !mayTrace),
|
|
63
89
|
sucrose: jit,
|
|
64
90
|
compat: mode !== "off",
|
|
65
91
|
bridge: mode === "wired",
|
|
92
|
+
typeboxValue: mode !== "sealed",
|
|
93
|
+
exactMirror: exactMirror && mode !== "sealed",
|
|
66
94
|
adapter: adapterStub,
|
|
67
95
|
isProduction: productionStub
|
|
68
96
|
},
|
|
@@ -73,71 +101,48 @@ function adapterConstantsSource(target) {
|
|
|
73
101
|
if (target === "bun") return "import { BunAdapter } from './bun/index'\nexport const defaultAdapter = BunAdapter\n";
|
|
74
102
|
return "import { WebStandardAdapter } from './web-standard/index'\nexport const defaultAdapter = WebStandardAdapter\n";
|
|
75
103
|
}
|
|
76
|
-
/** Filter matching elysia's own `adapter/constants` module (src + dist). */
|
|
77
104
|
const ADAPTER_CONSTANTS_FILTER = /[\\/]elysia[\\/](dist|src)[\\/]adapter[\\/]constants\.(m?js|ts)$/;
|
|
78
105
|
const ADAPTER_BUN_FILTER = /[\\/]elysia[\\/](dist|src)[\\/]adapter[\\/]bun[\\/]index\.(m?js|ts)$/;
|
|
79
106
|
const IS_PRODUCTION_FILTER = /[\\/]elysia[\\/](dist|src)[\\/]universal[\\/]is-production\.(m?js|ts)$/;
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
* monorepos, linked installs). Used by esbuild as a broad pre-filter
|
|
85
|
-
*
|
|
86
|
-
* The caller must further check that the path is under the resolved elysia package root
|
|
87
|
-
* to avoid matching user code in a directory that happens to be named "elysia"
|
|
88
|
-
*
|
|
89
|
-
* @internal
|
|
90
|
-
*/
|
|
107
|
+
const TYPEBOX_TYPE_FILTER = /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]typebox-type\.(m?js|ts)$/;
|
|
108
|
+
const TYPEBOX_SYSTEM_LITE_FILTER = /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]typebox-system-lite\.(m?js|ts)$/;
|
|
109
|
+
const TYPEBOX_REQUIRE_FILTER = /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]typebox-value-require\.(m?js|ts)$/;
|
|
110
|
+
const EXACT_MIRROR_REQUIRE_FILTER = /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]validator[\\/]exact-mirror-require\.(m?js|ts)$/;
|
|
91
111
|
const ELYSIA_MODULE_FILTER = /[\\/]elysia[\\/](dist|src)[\\/].+\.(m?js|ts)x?$/;
|
|
92
|
-
|
|
93
|
-
* Build a predicate that returns `true` only for modules that are under the
|
|
94
|
-
* resolved elysia package root (i.e. actually elysia's own files).
|
|
95
|
-
*
|
|
96
|
-
* Anchoring to the real package root prevents user projects rooted in a
|
|
97
|
-
* directory named `elysia` (like this repo itself) from having their code
|
|
98
|
-
* rewritten.
|
|
99
|
-
*
|
|
100
|
-
* Pass the result to both the esbuild `filter` (convert to RegExp via
|
|
101
|
-
* `makeElysiaModuleFilterRegex`) and the Vite transform (`isElysiaModule`).
|
|
102
|
-
*/
|
|
103
|
-
function resolveElysiaRoot(from = process.cwd()) {
|
|
112
|
+
function resolveElysiaRoot(from) {
|
|
104
113
|
try {
|
|
105
114
|
return (0, node_path.dirname)((0, node_module.createRequire)((0, node_path.join)(from, "package.json")).resolve("elysia/package.json"));
|
|
106
115
|
} catch {
|
|
107
116
|
return from;
|
|
108
117
|
}
|
|
109
118
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
119
|
+
function resolveExactMirror(from) {
|
|
120
|
+
try {
|
|
121
|
+
(0, node_module.createRequire)((0, node_path.join)(resolveElysiaRoot(from), "package.json")).resolve("exact-mirror");
|
|
122
|
+
return true;
|
|
123
|
+
} catch {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
114
127
|
function makeIsElysiaModule(elysiaRoot) {
|
|
115
128
|
const root = elysiaRoot.replace(/\\/g, "/");
|
|
116
129
|
return (path) => {
|
|
117
130
|
return path.replace(/\\/g, "/").startsWith(root + "/") && ELYSIA_MODULE_FILTER.test(path);
|
|
118
131
|
};
|
|
119
132
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
* so the `onLoad` pre-filter is as tight as possible. esbuild uses this as an
|
|
123
|
-
* initial path filter before calling the callback, so we still double-check
|
|
124
|
-
* with `makeIsElysiaModule` inside the callback.
|
|
125
|
-
*/
|
|
126
|
-
function makeElysiaModuleFilterRegex(elysiaRoot) {
|
|
127
|
-
const escaped = elysiaRoot.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
128
|
-
return new RegExp("^" + escaped + "[\\\\/](dist|src)[\\\\/].+\\.(m?js|ts)x?$");
|
|
129
|
-
}
|
|
130
|
-
function rewriteIsProductionCalls(code) {
|
|
131
|
-
return code.replace(/(?<![.?])\bisProduction\(\)/g, "true");
|
|
132
|
-
}
|
|
133
|
-
const bunAdapterStubSource = "const e=(t)=>{throw new Error(`[elysia-aot] Bun adapter was stripped for target 'web-standard' .listen() is unavailable; use the exported fetch handler or rebuild with a different target.`)}\nexport const BunAdapter={name:'bun',runtime:'bun',isWebStandard:true,parse:{},response:{},listen:e}\nexport function collectStaticRoutes(){}\n";
|
|
133
|
+
const rewriteIsProductionCalls = (code) => code.replace(/(?<![.?])\bisProduction\(\)/g, "true");
|
|
134
|
+
const bunAdapterStubSource = "const e=(t)=>{throw new Error(`[elysia-aot] Bun adapter was stripped for target 'web-standard' .listen() is unavailable; use the exported fetch handler or rebuild with a different target.`)}\nexport const BunAdapter={parse:{},response:{},listen:e}\nexport function collectStaticRoutes(){}\n";
|
|
134
135
|
const STUB_SOURCES = {
|
|
136
|
+
staticClone: [{
|
|
137
|
+
filter: /[\\/]elysia[\\/](dist|src)[\\/]compile[\\/]handler[\\/]static-clone-resolver\.(m?js|ts)$/,
|
|
138
|
+
source: `export const staticCloneResolver = undefined\n`
|
|
139
|
+
}],
|
|
135
140
|
jit: [{
|
|
136
141
|
filter: /[\\/]elysia[\\/](dist|src)[\\/]compile[\\/]handler[\\/]jit\.(m?js|ts)$/,
|
|
137
142
|
source: "const e=()=>{throw new Error(\"[elysia-aot] handler compiler JIT was stripped (strip mode) but a route needed runtime compilation. Rebuild with strip:false.\")}\nexport function compileHandlerJit(){return e()}\nexport function createInlineHandler(){return e()}\nexport function setCaptureHeaderShorthand(){}\n"
|
|
138
143
|
}, {
|
|
139
144
|
filter: /[\\/]elysia[\\/](dist|src)[\\/]compile[\\/]handler[\\/]descriptor\.(m?js|ts)$/,
|
|
140
|
-
source: "const e=()=>{throw new Error(\"[elysia-aot] handler compiler JIT was stripped (strip mode) but a route needed runtime compilation. Rebuild with strip:false.\")}\nexport function describeRoute(){return e()}\nexport const routeDescriptors=new WeakMap()\
|
|
145
|
+
source: "const e=()=>{throw new Error(\"[elysia-aot] handler compiler JIT was stripped (strip mode) but a route needed runtime compilation. Rebuild with strip:false.\")}\nexport function describeRoute(){return e()}\nexport const routeDescriptors=new WeakMap()\n"
|
|
141
146
|
}],
|
|
142
147
|
ws: [{
|
|
143
148
|
filter: /[\\/]elysia[\\/](dist|src)[\\/]ws[\\/]route\.(m?js|ts)$/,
|
|
@@ -147,13 +152,20 @@ const STUB_SOURCES = {
|
|
|
147
152
|
filter: /[\\/]elysia[\\/](dist|src)[\\/]compile[\\/]handler[\\/]reconstruct\.(m?js|ts)$/,
|
|
148
153
|
source: "const e=()=>{throw new Error(\"[elysia-aot] handler reconstruction was stripped (strip mode) but a route needed it. Rebuild with strip:false.\")}\nexport class Reconstrct {\n static validator(){return e()}\n static cookie(){return e()}\n static trace(){return e()}\n}\n"
|
|
149
154
|
}],
|
|
150
|
-
cookie: [
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
155
|
+
cookie: [
|
|
156
|
+
{
|
|
157
|
+
filter: /[\\/]elysia[\\/](dist|src)[\\/]cookie[\\/]crypto\.(m?js|ts)$/,
|
|
158
|
+
source: `export function resolvePendingCookie(){throw new Error("[elysia-aot] cookie support was stripped (strip mode) but a signed cookie was read. Rebuild with strip:false.")}\n`
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
filter: /[\\/]elysia[\\/](dist|src)[\\/]cookie[\\/]utils\.(m?js|ts)$/,
|
|
162
|
+
source: "const e=()=>{throw new Error(\"[elysia-aot] cookie support was stripped (strip mode) but a route used cookies. Rebuild with strip:false.\")}\nexport const hasSyncHmac=false\nexport function parseCookieRaw(){return e()}\nexport function parseCookieRawSync(){return e()}\nexport function parseCookieRawSigned(){return e()}\nexport function parseCookieRawLazy(){return e()}\nexport function parseCookieRawDeferred(){return e()}\nexport function buildCookieJar(){return e()}\nexport function signCookieValues(){return e()}\n"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
filter: /[\\/]elysia[\\/](dist|src)[\\/]cookie[\\/]config\.(m?js|ts)$/,
|
|
166
|
+
source: "const e=()=>{throw new Error(\"[elysia-aot] cookie support was stripped (strip mode) but a route used cookies. Rebuild with strip:false.\")}\nexport function compileCookieConfig(){return e()}\n"
|
|
167
|
+
}
|
|
168
|
+
],
|
|
157
169
|
trace: [{
|
|
158
170
|
filter: /[\\/]elysia[\\/](dist|src)[\\/]trace\.(m?js|ts)$/,
|
|
159
171
|
source: "const e=()=>{throw new Error(\"[elysia-aot] trace support was stripped (strip mode) but a route used trace. Rebuild with strip:false.\")}\nexport function createTracer(){return e()}\nexport function unionTracePhases(){return new Set()}\n"
|
|
@@ -161,9 +173,6 @@ const STUB_SOURCES = {
|
|
|
161
173
|
sucrose: [{
|
|
162
174
|
filter: /[\\/]elysia[\\/](dist|src)[\\/]memory\.(m?js|ts)$/,
|
|
163
175
|
source: "import { clearContextCache } from './context'\nimport { Validator } from './validator'\nexport function flushMemory() {\n clearContextCache()\n Validator.clear()\n}\n"
|
|
164
|
-
}, {
|
|
165
|
-
filter: /[\\/]elysia[\\/](dist|src)[\\/]compile[\\/]analysis-cache\.(m?js|ts)$/,
|
|
166
|
-
source: "import { clearHandlerAnalysisCaches } from './handler/index'\nimport { clearFlattenChainMemo } from '../utils'\nexport function clearAuthoringAnalysisCaches(root) {\n clearHandlerAnalysisCaches(root)\n clearFlattenChainMemo(root)\n}\n"
|
|
167
176
|
}],
|
|
168
177
|
compat: [{
|
|
169
178
|
filter: /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]compat\.(m?js|ts)$/,
|
|
@@ -172,11 +181,23 @@ const STUB_SOURCES = {
|
|
|
172
181
|
bridge: [{
|
|
173
182
|
filter: /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]bridge\.(m?js|ts)$/,
|
|
174
183
|
source: `export * from './bridge-live'\n`
|
|
184
|
+
}],
|
|
185
|
+
typeboxValue: [{
|
|
186
|
+
filter: /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]typebox-value\.(m?js|ts)$/,
|
|
187
|
+
source: `export * from './typebox-value-live'\n`
|
|
188
|
+
}],
|
|
189
|
+
exactMirror: [{
|
|
190
|
+
filter: /[\\/]elysia[\\/](dist|src)[\\/]type[\\/]validator[\\/]exact-mirror\.(m?js|ts)$/,
|
|
191
|
+
source: `export * from './exact-mirror-live'\n`
|
|
175
192
|
}]
|
|
176
193
|
};
|
|
177
194
|
const alignStubExtensions = (stubSource, targetPath) => {
|
|
178
195
|
const ext = targetPath.slice(targetPath.lastIndexOf("."));
|
|
179
196
|
if (ext !== ".mjs" && ext !== ".js" && ext !== ".cjs") return stubSource;
|
|
197
|
+
if (ext !== ".mjs") {
|
|
198
|
+
const reexport = /^export \* from '(\.[^']+)'\n$/.exec(stubSource);
|
|
199
|
+
if (reexport) return `let m;const t=()=>m??=require('${reexport[1]}${ext}'),d=(o,k)=>Reflect.getOwnPropertyDescriptor(o,k)\nmodule.exports=new Proxy({},{get:(_,k)=>t()[k],has:(_,k)=>k in t(),ownKeys:()=>Reflect.ownKeys(t()),getOwnPropertyDescriptor:(o,k)=>{let x=d(o,k);if(x)return x;x=d(t(),k);if(x)x.configurable=true;return x},preventExtensions:o=>{for(const k of Reflect.ownKeys(t()))Object.defineProperty(o,k,d(t(),k));return Reflect.preventExtensions(o)}})\n`;
|
|
200
|
+
}
|
|
180
201
|
return stubSource.replace(/(from ')(\.[^']+)(')/g, (_m, open, spec, close) => open + (spec === "./validator" ? spec + "/index" : spec) + ext + close);
|
|
181
202
|
};
|
|
182
203
|
const OVERRIDE_MAP = {
|
|
@@ -204,6 +225,10 @@ const OVERRIDE_MAP = {
|
|
|
204
225
|
leaf: "boolean-string",
|
|
205
226
|
export: "BooleanString"
|
|
206
227
|
},
|
|
228
|
+
Composite: {
|
|
229
|
+
leaf: "keep-config",
|
|
230
|
+
export: "CompositeType"
|
|
231
|
+
},
|
|
207
232
|
Cookie: {
|
|
208
233
|
leaf: "cookie",
|
|
209
234
|
export: "Cookie"
|
|
@@ -212,6 +237,10 @@ const OVERRIDE_MAP = {
|
|
|
212
237
|
leaf: "date",
|
|
213
238
|
export: "DateType"
|
|
214
239
|
},
|
|
240
|
+
Evaluate: {
|
|
241
|
+
leaf: "keep-config",
|
|
242
|
+
export: "EvaluateType"
|
|
243
|
+
},
|
|
215
244
|
File: {
|
|
216
245
|
leaf: "file",
|
|
217
246
|
export: "File"
|
|
@@ -232,10 +261,18 @@ const OVERRIDE_MAP = {
|
|
|
232
261
|
leaf: "integer-string",
|
|
233
262
|
export: "IntegerString"
|
|
234
263
|
},
|
|
264
|
+
Interface: {
|
|
265
|
+
leaf: "keep-config",
|
|
266
|
+
export: "InterfaceType"
|
|
267
|
+
},
|
|
235
268
|
Intersect: {
|
|
236
269
|
leaf: "intersect",
|
|
237
270
|
export: "Intersect"
|
|
238
271
|
},
|
|
272
|
+
Mapped: {
|
|
273
|
+
leaf: "keep-config",
|
|
274
|
+
export: "MappedType"
|
|
275
|
+
},
|
|
239
276
|
MaybeEmpty: {
|
|
240
277
|
leaf: "maybe-empty",
|
|
241
278
|
export: "MaybeEmpty"
|
|
@@ -268,10 +305,34 @@ const OVERRIDE_MAP = {
|
|
|
268
305
|
leaf: "object-string",
|
|
269
306
|
export: "ObjectString"
|
|
270
307
|
},
|
|
308
|
+
Omit: {
|
|
309
|
+
leaf: "keep-config",
|
|
310
|
+
export: "OmitType"
|
|
311
|
+
},
|
|
271
312
|
Optional: {
|
|
272
313
|
leaf: "optional",
|
|
273
314
|
export: "Optional"
|
|
274
315
|
},
|
|
316
|
+
Partial: {
|
|
317
|
+
leaf: "keep-config",
|
|
318
|
+
export: "PartialType"
|
|
319
|
+
},
|
|
320
|
+
Pick: {
|
|
321
|
+
leaf: "keep-config",
|
|
322
|
+
export: "PickType"
|
|
323
|
+
},
|
|
324
|
+
Problem: {
|
|
325
|
+
leaf: "problem",
|
|
326
|
+
export: "Problem"
|
|
327
|
+
},
|
|
328
|
+
ReadonlyObject: {
|
|
329
|
+
leaf: "keep-config",
|
|
330
|
+
export: "ReadonlyObjectType"
|
|
331
|
+
},
|
|
332
|
+
Required: {
|
|
333
|
+
leaf: "keep-config",
|
|
334
|
+
export: "RequiredType"
|
|
335
|
+
},
|
|
275
336
|
String: {
|
|
276
337
|
leaf: "string",
|
|
277
338
|
export: "StringType"
|
|
@@ -290,17 +351,20 @@ const OVERRIDE_MAP = {
|
|
|
290
351
|
}
|
|
291
352
|
};
|
|
292
353
|
const requireFromHere = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href);
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
354
|
+
const moduleMeta = {};
|
|
355
|
+
const loadedModuleCondition = require("url").pathToFileURL(__filename).href.endsWith(".js") ? "cjs" : "esm";
|
|
356
|
+
const resolveSpecifier = (specifier, moduleCondition) => {
|
|
357
|
+
if (moduleCondition === "cjs") return requireFromHere.resolve(specifier);
|
|
358
|
+
if (moduleMeta.resolve) {
|
|
359
|
+
const url = moduleMeta.resolve(specifier);
|
|
360
|
+
return url.startsWith("file://") ? (0, node_url.fileURLToPath)(url) : url;
|
|
298
361
|
}
|
|
362
|
+
if (moduleCondition === "esm") throw new Error("[elysia-aot] CommonJS-loaded build plugin cannot resolve the ESM package condition. Load the build plugin through import for an ESM entry.");
|
|
299
363
|
return requireFromHere.resolve(specifier);
|
|
300
364
|
};
|
|
301
|
-
async function generateVirtualType(
|
|
302
|
-
const typePath = resolveSpecifier(
|
|
303
|
-
const typeboxPath = resolveSpecifier("typebox/type");
|
|
365
|
+
async function generateVirtualType(moduleCondition) {
|
|
366
|
+
const typePath = resolveSpecifier("elysia/type", moduleCondition);
|
|
367
|
+
const typeboxPath = resolveSpecifier("typebox/type", moduleCondition);
|
|
304
368
|
const ext = typePath.slice(typePath.lastIndexOf("."));
|
|
305
369
|
const leafDir = (0, node_path.join)((0, node_path.dirname)(typePath), "elysia");
|
|
306
370
|
const typebox = await import((0, node_url.pathToFileURL)(typeboxPath).href);
|
|
@@ -316,13 +380,6 @@ async function generateVirtualType(typeSpecifier = "elysia/type") {
|
|
|
316
380
|
return source;
|
|
317
381
|
}
|
|
318
382
|
const _importedEntries = /* @__PURE__ */ new Set();
|
|
319
|
-
let activeGenerationWorkers = 0;
|
|
320
|
-
let lastGenerationWorkerExit;
|
|
321
|
-
/** @internal Test diagnostic for deterministic worker cleanup. */
|
|
322
|
-
const getAotWorkerDiagnostics = () => ({
|
|
323
|
-
activeWorkers: activeGenerationWorkers,
|
|
324
|
-
lastExit: lastGenerationWorkerExit
|
|
325
|
-
});
|
|
326
383
|
/**
|
|
327
384
|
* Extension mirroring the running module's own build output, so a sibling
|
|
328
385
|
* source file can be resolved from `import.meta.url` in `.mjs`/`.js`/`.ts`
|
|
@@ -336,16 +393,15 @@ const workerUrl = () => {
|
|
|
336
393
|
return new URL("./worker" + siblingModuleExt(moduleUrl), moduleUrl);
|
|
337
394
|
};
|
|
338
395
|
/** @internal Re-evaluate an entry in a disposable worker for watch rebuilds. */
|
|
339
|
-
async function generateCompiledArtifactsIsolated(file, options) {
|
|
396
|
+
async function generateCompiledArtifactsIsolated(file, options, moduleCondition = resolveEntryModuleKind(file)) {
|
|
340
397
|
const entry = resolveEntry(file);
|
|
341
398
|
console.warn("[elysia-aot] re-evaluating \"" + entry + "\" in an isolated worker for rebuild. Top-level side effects run only inside the worker.");
|
|
342
399
|
const worker = new node_worker_threads.Worker(workerUrl(), { workerData: {
|
|
343
400
|
file: entry,
|
|
344
|
-
options
|
|
401
|
+
options,
|
|
402
|
+
moduleCondition
|
|
345
403
|
} });
|
|
346
|
-
activeGenerationWorkers++;
|
|
347
404
|
const exit = new Promise((resolve) => worker.once("exit", resolve));
|
|
348
|
-
lastGenerationWorkerExit = exit;
|
|
349
405
|
try {
|
|
350
406
|
return await new Promise((resolve, reject) => {
|
|
351
407
|
let received = false;
|
|
@@ -367,19 +423,34 @@ async function generateCompiledArtifactsIsolated(file, options) {
|
|
|
367
423
|
await worker.terminate();
|
|
368
424
|
} finally {
|
|
369
425
|
await exit;
|
|
370
|
-
activeGenerationWorkers--;
|
|
371
426
|
}
|
|
372
427
|
}
|
|
373
428
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
const
|
|
379
|
-
if (
|
|
380
|
-
|
|
429
|
+
const validatorSlotKey = ({ method, path, slot }) => `${method}\0${path}\0${slot}`;
|
|
430
|
+
/** @internal Exact logical-slot gate used by AOT mode selection. */
|
|
431
|
+
function validatorSlotSetsMatch(expected, captured) {
|
|
432
|
+
const expectedKeys = new Set(expected.map(validatorSlotKey));
|
|
433
|
+
const capturedKeys = new Set(captured.map(validatorSlotKey));
|
|
434
|
+
if (expectedKeys.size !== capturedKeys.size) return false;
|
|
435
|
+
for (const key of expectedKeys) if (!capturedKeys.has(key)) return false;
|
|
436
|
+
return true;
|
|
381
437
|
}
|
|
382
|
-
|
|
438
|
+
/**
|
|
439
|
+
* The manifest is one flat `method -> path` table with no per-app namespace,
|
|
440
|
+
* bound to whichever app builds a router first, so a mounted sub-app (a second
|
|
441
|
+
* Elysia building on its own schedule) is not representable
|
|
442
|
+
*
|
|
443
|
+
* refuse at build time rather than ship a coin flip
|
|
444
|
+
*/
|
|
445
|
+
const assertNoMount = (app, entry) => {
|
|
446
|
+
const routes = app["~routes"];
|
|
447
|
+
const mounted = [];
|
|
448
|
+
for (const route of routes) if (route[2]?.["~mount"] && !mounted.includes(route[1])) mounted.push(route[1]);
|
|
449
|
+
if (!mounted.length) return;
|
|
450
|
+
throw new Error(`[elysia-aot] "${entry}" mounts a sub-app (${mounted.join(", ")}). AOT cannot compile a mounted sub-app. Compose with .use() instead of .mount(), or disable AOT plugin`);
|
|
451
|
+
};
|
|
452
|
+
async function generateCompiledArtifacts(file, options, moduleCondition = resolveEntryModuleKind(file)) {
|
|
453
|
+
if (moduleCondition !== loadedModuleCondition) throw new Error(`[elysia-aot] entry uses the ${moduleCondition === "cjs" ? "CommonJS \"require\"" : "ESM \"import\""} package condition, but the AOT build plugin was loaded through ${loadedModuleCondition === "cjs" ? "CommonJS \"require\"" : "ESM \"import\""}; entry: ${JSON.stringify(resolveEntry(file))}. Load the plugin through ${moduleCondition === "cjs" ? "require()" : "import"} so capture and generated registration share one Elysia module instance.`);
|
|
383
454
|
const previousAotBuild = process.env.ELYSIA_AOT_BUILD;
|
|
384
455
|
process.env.ELYSIA_AOT_BUILD = "1";
|
|
385
456
|
const previousAotVerbose = process.env.ELYSIA_AOT_VERBOSE;
|
|
@@ -388,14 +459,15 @@ async function generateCompiledArtifacts(file, options) {
|
|
|
388
459
|
try {
|
|
389
460
|
const entry = resolveEntry(file);
|
|
390
461
|
const entryReal = realPath(entry);
|
|
391
|
-
if (_importedEntries.has(entryReal)) return generateCompiledArtifactsIsolated(file, options);
|
|
462
|
+
if (_importedEntries.has(entryReal)) return generateCompiledArtifactsIsolated(file, options, moduleCondition);
|
|
392
463
|
_importedEntries.add(entryReal);
|
|
393
464
|
const mod = await import(entry);
|
|
394
465
|
const app = mod.app ?? mod.default;
|
|
395
466
|
if (!app || typeof app.compile !== "function") throw new Error(`[elysia-aot] "${entry}" must export an Elysia app`);
|
|
396
467
|
const typedApp = app;
|
|
468
|
+
assertNoMount(typedApp, entry);
|
|
397
469
|
const sourceOptions = {
|
|
398
|
-
|
|
470
|
+
moduleCondition,
|
|
399
471
|
registerFrom: options?.registerFrom,
|
|
400
472
|
reconstructFrom: options?.reconstructFrom,
|
|
401
473
|
lazy: options?.lazy,
|
|
@@ -404,10 +476,13 @@ async function generateCompiledArtifacts(file, options) {
|
|
|
404
476
|
const strip = options?.strip ?? "auto";
|
|
405
477
|
const adapterStub = options?.target === "bun" ? "bun" : options?.target === "node" || options?.target === "workerd" ? "web-standard" : false;
|
|
406
478
|
const productionStub = options?.production !== false;
|
|
479
|
+
const exactMirror = resolveExactMirror(entry);
|
|
407
480
|
if (strip === false) return {
|
|
408
481
|
source: await require_plugin_aot_source.compileToSource(typedApp, sourceOptions),
|
|
409
482
|
stub: {
|
|
410
483
|
...NO_STUB,
|
|
484
|
+
typeboxValue: true,
|
|
485
|
+
exactMirror,
|
|
411
486
|
adapter: adapterStub,
|
|
412
487
|
isProduction: productionStub
|
|
413
488
|
},
|
|
@@ -417,32 +492,51 @@ async function generateCompiledArtifacts(file, options) {
|
|
|
417
492
|
const report = require_plugin_aot_source.replayStubbability(typedApp, artifacts.handlers);
|
|
418
493
|
const aliases = /* @__PURE__ */ new Set();
|
|
419
494
|
for (const handler of artifacts.handlers) if (handler.alias) for (const name of handler.alias.split(",")) aliases.add(name);
|
|
420
|
-
const
|
|
421
|
-
const
|
|
495
|
+
const history = typedApp["~routes"];
|
|
496
|
+
const hasWS = !!typedApp["~hasWS"] || history.some((route) => route[0] === "WS");
|
|
422
497
|
const mayTrace = !!typedApp["~hasTrace"] || history.some((route) => (route?.[4])?.trace?.length || route?.[2]?.["~mount"]);
|
|
423
|
-
|
|
498
|
+
const expectedSlots = [];
|
|
499
|
+
const declaredTypeBoxSlots = /* @__PURE__ */ new Set();
|
|
424
500
|
let routesForbidSeal = false;
|
|
501
|
+
let wsCookie = false;
|
|
425
502
|
for (const route of history) {
|
|
503
|
+
const method = route[0];
|
|
504
|
+
const path = route[1];
|
|
505
|
+
const expectTypeBoxSlot = (slot) => {
|
|
506
|
+
const identity = {
|
|
507
|
+
method,
|
|
508
|
+
path,
|
|
509
|
+
slot
|
|
510
|
+
};
|
|
511
|
+
const key = validatorSlotKey(identity);
|
|
512
|
+
if (declaredTypeBoxSlots.has(key)) routesForbidSeal = true;
|
|
513
|
+
else {
|
|
514
|
+
declaredTypeBoxSlots.add(key);
|
|
515
|
+
expectedSlots.push(identity);
|
|
516
|
+
}
|
|
517
|
+
};
|
|
426
518
|
const [, , , instance, hook, appHook, inheritedChain, macroScope] = route;
|
|
427
519
|
const hooks = require_compile_handler_index.composeRouteHook(instance, hook, appHook, inheritedChain, typedApp, macroScope);
|
|
520
|
+
if (method === "WS" && (hook?.cookie !== void 0 || hooks?.cookie !== void 0)) wsCookie = true;
|
|
428
521
|
if (!hooks) continue;
|
|
429
522
|
let routeHasTypeBoxDirectSlot = false;
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
]) {
|
|
437
|
-
const value = hooks[slot];
|
|
438
|
-
if (value === void 0) continue;
|
|
439
|
-
if (require_compile_handler_frozen_validator.isStandardSchema(value)) continue;
|
|
523
|
+
const classify = (schema, slot) => {
|
|
524
|
+
if (schema === void 0) {
|
|
525
|
+
routesForbidSeal = true;
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
if (require_compile_handler_frozen_validator.isStandardSchema(schema)) return;
|
|
440
529
|
routeHasTypeBoxDirectSlot = true;
|
|
441
|
-
|
|
530
|
+
expectTypeBoxSlot(slot);
|
|
531
|
+
};
|
|
532
|
+
for (const slot of require_compile_handler_frozen_validator.REQUEST_SLOTS) {
|
|
533
|
+
const value = hooks[slot];
|
|
534
|
+
if (value !== void 0) classify(require_compile_handler_frozen_validator.resolveModelRef(value, typedApp), slot);
|
|
442
535
|
}
|
|
443
|
-
if (hooks.response !== void 0
|
|
444
|
-
|
|
445
|
-
|
|
536
|
+
if (hooks.response !== void 0) {
|
|
537
|
+
const response = require_compile_handler_frozen_validator.resolveModelRef(hooks.response, typedApp);
|
|
538
|
+
if (require_compile_handler_frozen_validator.isResponseMap(response)) for (const status in response) classify(require_compile_handler_frozen_validator.resolveModelRef(response[status], typedApp), `response:${status}`);
|
|
539
|
+
else classify(response, "response:200");
|
|
446
540
|
}
|
|
447
541
|
const mergeSchemas = hooks.schemas;
|
|
448
542
|
if (Array.isArray(mergeSchemas) && mergeSchemas.length > 0) {
|
|
@@ -450,13 +544,13 @@ async function generateCompiledArtifacts(file, options) {
|
|
|
450
544
|
}
|
|
451
545
|
}
|
|
452
546
|
if (typedApp["~config"]?.normalize === "typebox") routesForbidSeal = true;
|
|
453
|
-
const
|
|
454
|
-
const { plan: stub, mode } = planFromReport(strip, report, hasWS, mayTrace, aliases, (artifacts.handlers.
|
|
547
|
+
const validatorSlotsMatch = validatorSlotSetsMatch(expectedSlots, artifacts.validators);
|
|
548
|
+
const { plan: stub, mode } = planFromReport(strip, report, hasWS, mayTrace, aliases, (artifacts.handlers.some((h) => h.code) || artifacts.validators.length > 0) && !routesForbidSeal && validatorSlotsMatch && artifacts.validators.every((v) => v.bridgeFree === true), !artifacts.handlers.some((h) => h.code) && artifacts.validators.length === 0, adapterStub, productionStub, wsCookie, exactMirror);
|
|
455
549
|
if (options?.target === "workerd") {
|
|
456
550
|
if (!report.jit) throw new Error(`[elysia-aot] target 'workerd' but handler JIT is still reachable (${report.reasons.join(", ") || "unknown"}). Every route must be captured into the AOT manifest.`);
|
|
457
|
-
if (
|
|
551
|
+
if (!validatorSlotsMatch) console.warn("[elysia-aot] target 'workerd': captured validator slots do not exactly match declared slots; unfrozen slots compile at runtime and will fail on workerd.");
|
|
458
552
|
}
|
|
459
|
-
const virtualType = mode === "off" ? void 0 : await generateVirtualType(
|
|
553
|
+
const virtualType = mode === "off" ? void 0 : await generateVirtualType(moduleCondition);
|
|
460
554
|
return {
|
|
461
555
|
source: artifacts.source,
|
|
462
556
|
stub,
|
|
@@ -483,23 +577,28 @@ const realPath = (path) => {
|
|
|
483
577
|
exports.ADAPTER_BUN_FILTER = ADAPTER_BUN_FILTER;
|
|
484
578
|
exports.ADAPTER_CONSTANTS_FILTER = ADAPTER_CONSTANTS_FILTER;
|
|
485
579
|
exports.ELYSIA_MODULE_FILTER = ELYSIA_MODULE_FILTER;
|
|
580
|
+
exports.EXACT_MIRROR_REQUIRE_FILTER = EXACT_MIRROR_REQUIRE_FILTER;
|
|
486
581
|
exports.IS_PRODUCTION_FILTER = IS_PRODUCTION_FILTER;
|
|
487
582
|
exports.NO_STUB = NO_STUB;
|
|
488
583
|
exports.OVERRIDE_MAP = OVERRIDE_MAP;
|
|
489
584
|
exports.SOURCE_REGEX = SOURCE_REGEX;
|
|
490
585
|
exports.STUB_SOURCES = STUB_SOURCES;
|
|
586
|
+
exports.TYPEBOX_REQUIRE_FILTER = TYPEBOX_REQUIRE_FILTER;
|
|
587
|
+
exports.TYPEBOX_SYSTEM_LITE_FILTER = TYPEBOX_SYSTEM_LITE_FILTER;
|
|
588
|
+
exports.TYPEBOX_TYPE_FILTER = TYPEBOX_TYPE_FILTER;
|
|
491
589
|
exports.adapterConstantsSource = adapterConstantsSource;
|
|
492
590
|
exports.alignStubExtensions = alignStubExtensions;
|
|
493
591
|
exports.bunAdapterStubSource = bunAdapterStubSource;
|
|
494
592
|
exports.generateCompiledArtifacts = generateCompiledArtifacts;
|
|
495
593
|
exports.generateCompiledArtifactsIsolated = generateCompiledArtifactsIsolated;
|
|
496
594
|
exports.generateVirtualType = generateVirtualType;
|
|
497
|
-
exports.getAotWorkerDiagnostics = getAotWorkerDiagnostics;
|
|
498
|
-
exports.makeElysiaModuleFilterRegex = makeElysiaModuleFilterRegex;
|
|
499
595
|
exports.makeIsElysiaModule = makeIsElysiaModule;
|
|
500
596
|
exports.planFromReport = planFromReport;
|
|
501
597
|
exports.realPath = realPath;
|
|
502
598
|
exports.resolveElysiaRoot = resolveElysiaRoot;
|
|
503
599
|
exports.resolveEntry = resolveEntry;
|
|
600
|
+
exports.resolveEntryModuleKind = resolveEntryModuleKind;
|
|
601
|
+
exports.resolveExactMirror = resolveExactMirror;
|
|
504
602
|
exports.rewriteIsProductionCalls = rewriteIsProductionCalls;
|
|
505
|
-
exports.siblingModuleExt = siblingModuleExt;
|
|
603
|
+
exports.siblingModuleExt = siblingModuleExt;
|
|
604
|
+
exports.validatorSlotSetsMatch = validatorSlotSetsMatch;
|