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
|
@@ -18,10 +18,8 @@ async function captureArtifacts(app, options) {
|
|
|
18
18
|
const previousAotBuild = require_universal_env.env.ELYSIA_AOT_BUILD;
|
|
19
19
|
require_universal_env.env.ELYSIA_AOT_BUILD = "1";
|
|
20
20
|
try {
|
|
21
|
-
if (!require_compile_aot.Capture.isCapturing()) throw new Error("[elysia-aot]: ELYSIA_AOT_BUILD=1 must be set to enable AOT capture mode");
|
|
22
21
|
require_compile_aot_capture.beginValidatorCapture();
|
|
23
|
-
|
|
24
|
-
if (modules) await modules;
|
|
22
|
+
await app.modules;
|
|
25
23
|
if (options?.target !== void 0) require_compile_handler_jit.setCaptureHeaderShorthand(options.target === "bun");
|
|
26
24
|
app.compile();
|
|
27
25
|
const captured = require_compile_aot_capture.endValidatorCapture();
|
|
@@ -42,10 +40,14 @@ async function captureArtifacts(app, options) {
|
|
|
42
40
|
}
|
|
43
41
|
const materialiseHandlersForReplay = (captured) => {
|
|
44
42
|
const manifest = {};
|
|
45
|
-
for (const h of captured)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
for (const h of captured) {
|
|
44
|
+
if (!h.code) continue;
|
|
45
|
+
(manifest[h.method] ??= {})[h.path] = {
|
|
46
|
+
a: h.alias ? h.alias.split(",") : [],
|
|
47
|
+
f: new Function(`return ${require_compile_aot_emit.Source.handlerFactory(h.alias, h.code)}`)(),
|
|
48
|
+
k: h.k
|
|
49
|
+
};
|
|
50
|
+
}
|
|
49
51
|
return manifest;
|
|
50
52
|
};
|
|
51
53
|
function replayStubbability(app, handlers) {
|
|
@@ -56,23 +58,28 @@ function replayStubbability(app, handlers) {
|
|
|
56
58
|
require_compile_aot.Compiled.clear();
|
|
57
59
|
const fingerprint = require_compile_aot.createAotFingerprint();
|
|
58
60
|
require_compile_aot.Compiled.register({
|
|
59
|
-
bf: 1,
|
|
60
61
|
fingerprint,
|
|
61
62
|
handlers: materialiseHandlersForReplay(handlers)
|
|
62
63
|
});
|
|
63
64
|
require_compile_aot.Compiled.claim(app["~programId"], fingerprint);
|
|
64
65
|
require_validator_index.Validator.clear();
|
|
65
|
-
const history = app["~routes"]
|
|
66
|
+
const history = app["~routes"];
|
|
66
67
|
require_compile_jit_probe.JITProbe.begin();
|
|
68
|
+
const exact = /* @__PURE__ */ new Map();
|
|
69
|
+
for (const route of history) {
|
|
70
|
+
const method = route[0];
|
|
71
|
+
if (method === "WS") continue;
|
|
72
|
+
let paths = exact.get(method);
|
|
73
|
+
if (!paths) exact.set(method, paths = /* @__PURE__ */ new Set());
|
|
74
|
+
if (paths.has(route[1])) require_compile_jit_probe.JITProbe.record("handler:indexed-duplicate");
|
|
75
|
+
else paths.add(route[1]);
|
|
76
|
+
}
|
|
67
77
|
for (const route of history) try {
|
|
68
78
|
if (route[0] === "WS") continue;
|
|
69
79
|
require_compile_handler_index.compileHandler(route, app);
|
|
70
80
|
} catch {
|
|
71
|
-
require_compile_jit_probe.JITProbe.
|
|
72
|
-
return
|
|
73
|
-
jit: false,
|
|
74
|
-
reasons: ["handler:new-function"]
|
|
75
|
-
};
|
|
81
|
+
require_compile_jit_probe.JITProbe.record("handler:new-function");
|
|
82
|
+
return require_compile_jit_probe.JITProbe.end();
|
|
76
83
|
}
|
|
77
84
|
return require_compile_jit_probe.JITProbe.end();
|
|
78
85
|
} finally {
|
|
@@ -95,45 +102,33 @@ const normalizeCheckIdentifiers = (src) => {
|
|
|
95
102
|
};
|
|
96
103
|
function createEntryEncoder() {
|
|
97
104
|
const branchRef = /* @__PURE__ */ new Map();
|
|
98
|
-
let branchDecls = "";
|
|
99
105
|
const branchTable = (u) => "[" + u.map((branch) => "[" + branch.map((b) => {
|
|
100
106
|
const src = normalizeCheckIdentifiers(require_compile_aot_emit.Source.checkFactory(b.identifier, b.code));
|
|
101
107
|
let ref = branchRef.get(src);
|
|
102
108
|
if (ref === void 0) {
|
|
103
109
|
ref = `_b${branchRef.size}`;
|
|
104
110
|
branchRef.set(src, ref);
|
|
105
|
-
branchDecls += `const ${ref} = ${src}\n`;
|
|
111
|
+
enc.branchDecls += `const ${ref} = ${src}\n`;
|
|
106
112
|
}
|
|
107
113
|
return ref;
|
|
108
114
|
}).join(", ") + "]").join(", ") + "]";
|
|
109
115
|
const unionRef = /* @__PURE__ */ new Map();
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
ref =
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
unionTable,
|
|
124
|
-
setCoercePlan() {
|
|
125
|
-
hasCoercePlan = true;
|
|
126
|
-
},
|
|
127
|
-
get branchDecls() {
|
|
128
|
-
return branchDecls;
|
|
129
|
-
},
|
|
130
|
-
get unionDecls() {
|
|
131
|
-
return unionDecls;
|
|
132
|
-
},
|
|
133
|
-
get hasCoercePlan() {
|
|
134
|
-
return hasCoercePlan;
|
|
116
|
+
const enc = {
|
|
117
|
+
branchDecls: "",
|
|
118
|
+
unionDecls: "",
|
|
119
|
+
hasCoercePlan: false,
|
|
120
|
+
unionTable(u) {
|
|
121
|
+
const str = branchTable(u);
|
|
122
|
+
let ref = unionRef.get(str);
|
|
123
|
+
if (ref === void 0) {
|
|
124
|
+
ref = `_u${unionRef.size}`;
|
|
125
|
+
unionRef.set(str, ref);
|
|
126
|
+
enc.unionDecls += `const ${ref} = ${str}\n`;
|
|
127
|
+
}
|
|
128
|
+
return ref;
|
|
135
129
|
}
|
|
136
130
|
};
|
|
131
|
+
return enc;
|
|
137
132
|
}
|
|
138
133
|
function entryParts(c, enc) {
|
|
139
134
|
const parts = [];
|
|
@@ -193,14 +188,15 @@ function entryParts(c, enc) {
|
|
|
193
188
|
parts.push(`ic: [${ic}]`);
|
|
194
189
|
}
|
|
195
190
|
if (c.coercePlan) {
|
|
196
|
-
enc.
|
|
191
|
+
enc.hasCoercePlan = true;
|
|
197
192
|
parts.push(`cp: ${JSON.stringify(c.coercePlan)}`);
|
|
198
193
|
}
|
|
199
194
|
return parts;
|
|
200
195
|
}
|
|
201
196
|
function emitModule(captured, handlers, fingerprint, options) {
|
|
202
197
|
const enc = createEntryEncoder();
|
|
203
|
-
const treeToSource = (tree
|
|
198
|
+
const treeToSource = (tree) => {
|
|
199
|
+
const slotRef = /* @__PURE__ */ new Map();
|
|
204
200
|
const methods = [];
|
|
205
201
|
for (const method in tree) {
|
|
206
202
|
const paths = [];
|
|
@@ -210,7 +206,7 @@ function emitModule(captured, handlers, fingerprint, options) {
|
|
|
210
206
|
if (ref === void 0) {
|
|
211
207
|
ref = `_s${slotRef.size}`;
|
|
212
208
|
slotRef.set(slotObj, ref);
|
|
213
|
-
|
|
209
|
+
validatorDecls += `const ${ref} = ${slotObj}\n`;
|
|
214
210
|
}
|
|
215
211
|
paths.push(`${JSON.stringify(path)}:${ref}`);
|
|
216
212
|
}
|
|
@@ -342,7 +338,6 @@ function emitModule(captured, handlers, fingerprint, options) {
|
|
|
342
338
|
}
|
|
343
339
|
validatorDecls += `const _groups = [${thunks.join(", ")}]\n`;
|
|
344
340
|
validatorDecls += `const _groupOf = ${JSON.stringify(groupOf)}\n`;
|
|
345
|
-
validatorExport = options?.register ? "" : "export const groups = _groups\nexport const groupOf = _groupOf\n";
|
|
346
341
|
} else {
|
|
347
342
|
const factoryRef = /* @__PURE__ */ new Map();
|
|
348
343
|
const tree = require_utils.nullObject();
|
|
@@ -359,59 +354,64 @@ function emitModule(captured, handlers, fingerprint, options) {
|
|
|
359
354
|
const byPath = tree[c.method] ??= require_utils.nullObject();
|
|
360
355
|
(byPath[c.path] ??= require_utils.nullObject())[c.slot] = ref;
|
|
361
356
|
}
|
|
362
|
-
const
|
|
363
|
-
validatorDecls += d;
|
|
364
|
-
});
|
|
365
|
-
validatorExport = options?.register ? `const validators = ${treeStr}\n` : `export const validators = ${treeStr}\n`;
|
|
357
|
+
validatorExport = `const validators = ${treeToSource(tree)}\n`;
|
|
366
358
|
}
|
|
367
359
|
const aliasRef = /* @__PURE__ */ new Map();
|
|
360
|
+
const factoryRef = /* @__PURE__ */ new Map();
|
|
368
361
|
const handlerRef = /* @__PURE__ */ new Map();
|
|
369
362
|
let handlerDecls = "";
|
|
370
363
|
const handlerTree = require_utils.nullObject();
|
|
371
364
|
for (const h of handlers) {
|
|
365
|
+
const k = h.k === void 0 ? "" : `k: ${JSON.stringify(h.k)}`;
|
|
366
|
+
if (!h.code) {
|
|
367
|
+
(handlerTree[h.method] ??= {})[h.path] = `{ ${k} }`;
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
372
370
|
const src = require_compile_aot_emit.Source.handlerFactory(h.alias, h.code);
|
|
373
|
-
let
|
|
371
|
+
let fref = factoryRef.get(src);
|
|
372
|
+
if (fref === void 0) {
|
|
373
|
+
fref = `_h${factoryRef.size}`;
|
|
374
|
+
factoryRef.set(src, fref);
|
|
375
|
+
handlerDecls += `const ${fref} = ${src}\n`;
|
|
376
|
+
}
|
|
377
|
+
let wref = handlerRef.get(fref + k);
|
|
374
378
|
if (wref === void 0) {
|
|
375
|
-
const n = handlerRef.size;
|
|
376
379
|
let aref = aliasRef.get(h.alias);
|
|
377
380
|
if (aref === void 0) {
|
|
378
381
|
aref = `_a${aliasRef.size}`;
|
|
379
382
|
aliasRef.set(h.alias, aref);
|
|
380
383
|
handlerDecls += `const ${aref} = ${JSON.stringify(h.alias ? h.alias.split(",") : [])}\n`;
|
|
381
384
|
}
|
|
382
|
-
wref = `_w${
|
|
383
|
-
handlerRef.set(
|
|
384
|
-
handlerDecls += `const
|
|
385
|
+
wref = `_w${handlerRef.size}`;
|
|
386
|
+
handlerRef.set(fref + k, wref);
|
|
387
|
+
handlerDecls += `const ${wref} = { a: ${aref}, f: ${fref}, ${k} }\n`;
|
|
385
388
|
}
|
|
386
389
|
(handlerTree[h.method] ??= {})[h.path] = wref;
|
|
387
390
|
}
|
|
388
|
-
let handlerExport =
|
|
391
|
+
let handlerExport = "const handlers = {\n";
|
|
389
392
|
for (const method in handlerTree) {
|
|
390
393
|
handlerExport += `\t${JSON.stringify(method)}: {\n`;
|
|
391
394
|
for (const path in handlerTree[method]) handlerExport += `\t\t${JSON.stringify(path)}: ${handlerTree[method][path]},\n`;
|
|
392
395
|
handlerExport += " },\n";
|
|
393
396
|
}
|
|
394
397
|
handlerExport += "}\n";
|
|
395
|
-
const fingerprintExport = options?.register ? `export const fingerprint = ${JSON.stringify(fingerprint)}\n` : "";
|
|
396
398
|
let body = "// Generated by Elysia build plugin. Do not edit.\n";
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
399
|
+
const moduleCondition = options?.moduleCondition ?? "esm";
|
|
400
|
+
const importNamed = (name, specifier) => moduleCondition === "cjs" ? `const { ${name} } = require(${JSON.stringify(specifier)})\n` : `import { ${name} } from ${JSON.stringify(specifier)}\n`;
|
|
401
|
+
body += importNamed("Compiled", options?.registerFrom ?? "elysia");
|
|
402
|
+
if (enc.hasCoercePlan) body += importNamed("buildCoercedFromPlan", "elysia/coerce-plan");
|
|
403
|
+
if (captured.length) body += importNamed("Reconstruct", options?.reconstructFrom ?? "elysia/reconstruct");
|
|
400
404
|
const generated = enc.branchDecls + enc.unionDecls + validatorDecls + handlerDecls;
|
|
401
405
|
const needs = (symbol) => new RegExp(`\\b${symbol}\\b`).test(generated);
|
|
402
|
-
if (needs("CheckContext")) body += "
|
|
403
|
-
if (needs("Guard")) body += "
|
|
404
|
-
if (needs("Format")) body += "
|
|
405
|
-
if (needs("Hashing")) body += "
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
406
|
+
if (needs("CheckContext")) body += importNamed("CheckContext", "typebox/schema");
|
|
407
|
+
if (needs("Guard")) body += importNamed("Guard", "typebox/guard");
|
|
408
|
+
if (needs("Format")) body += importNamed("Format", "typebox/format");
|
|
409
|
+
if (needs("Hashing")) body += importNamed("Hashing", "typebox/system");
|
|
410
|
+
body += "\n";
|
|
411
|
+
if (captured.length) body += "Compiled.reconstruct = Reconstruct\n";
|
|
412
|
+
body += `export const fingerprint = ${JSON.stringify(fingerprint)}\nCompiled.register((() => {
|
|
413
|
+
` + enc.branchDecls + (enc.branchDecls && "\n") + enc.unionDecls + (enc.unionDecls && "\n") + validatorDecls + handlerDecls + "\n" + validatorExport + "\n" + handlerExport + "\nreturn { fingerprint, " + (lazy ? "lazyGroups: _groups, lazyGroupOf: _groupOf, " : "validators, ") + `handlers${enc.hasCoercePlan ? ", planRebuilder: buildCoercedFromPlan" : ""} }\n})())
|
|
410
414
|
`;
|
|
411
|
-
} else {
|
|
412
|
-
body += "\n" + enc.branchDecls + (enc.branchDecls && "\n") + enc.unionDecls + (enc.unionDecls && "\n") + validatorDecls + handlerDecls + "\n" + validatorExport + "\n" + handlerExport + "\n";
|
|
413
|
-
if (!lazy) body += "\nexport default validators\n";
|
|
414
|
-
}
|
|
415
415
|
return body;
|
|
416
416
|
}
|
|
417
417
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { nullObject } from "../../utils.mjs";
|
|
2
2
|
import { env } from "../../universal/env.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { Compiled, createAotFingerprint } from "../../compile/aot.mjs";
|
|
4
4
|
import { JITProbe } from "../../compile/jit-probe.mjs";
|
|
5
5
|
import { setCaptureHeaderShorthand } from "../../compile/handler/jit.mjs";
|
|
6
6
|
import { Validator } from "../../validator/index.mjs";
|
|
@@ -17,10 +17,8 @@ async function captureArtifacts(app, options) {
|
|
|
17
17
|
const previousAotBuild = env.ELYSIA_AOT_BUILD;
|
|
18
18
|
env.ELYSIA_AOT_BUILD = "1";
|
|
19
19
|
try {
|
|
20
|
-
if (!Capture.isCapturing()) throw new Error("[elysia-aot]: ELYSIA_AOT_BUILD=1 must be set to enable AOT capture mode");
|
|
21
20
|
beginValidatorCapture();
|
|
22
|
-
|
|
23
|
-
if (modules) await modules;
|
|
21
|
+
await app.modules;
|
|
24
22
|
if (options?.target !== void 0) setCaptureHeaderShorthand(options.target === "bun");
|
|
25
23
|
app.compile();
|
|
26
24
|
const captured = endValidatorCapture();
|
|
@@ -41,10 +39,14 @@ async function captureArtifacts(app, options) {
|
|
|
41
39
|
}
|
|
42
40
|
const materialiseHandlersForReplay = (captured) => {
|
|
43
41
|
const manifest = {};
|
|
44
|
-
for (const h of captured)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
for (const h of captured) {
|
|
43
|
+
if (!h.code) continue;
|
|
44
|
+
(manifest[h.method] ??= {})[h.path] = {
|
|
45
|
+
a: h.alias ? h.alias.split(",") : [],
|
|
46
|
+
f: new Function(`return ${Source.handlerFactory(h.alias, h.code)}`)(),
|
|
47
|
+
k: h.k
|
|
48
|
+
};
|
|
49
|
+
}
|
|
48
50
|
return manifest;
|
|
49
51
|
};
|
|
50
52
|
function replayStubbability(app, handlers) {
|
|
@@ -55,23 +57,28 @@ function replayStubbability(app, handlers) {
|
|
|
55
57
|
Compiled.clear();
|
|
56
58
|
const fingerprint = createAotFingerprint();
|
|
57
59
|
Compiled.register({
|
|
58
|
-
bf: 1,
|
|
59
60
|
fingerprint,
|
|
60
61
|
handlers: materialiseHandlersForReplay(handlers)
|
|
61
62
|
});
|
|
62
63
|
Compiled.claim(app["~programId"], fingerprint);
|
|
63
64
|
Validator.clear();
|
|
64
|
-
const history = app["~routes"]
|
|
65
|
+
const history = app["~routes"];
|
|
65
66
|
JITProbe.begin();
|
|
67
|
+
const exact = /* @__PURE__ */ new Map();
|
|
68
|
+
for (const route of history) {
|
|
69
|
+
const method = route[0];
|
|
70
|
+
if (method === "WS") continue;
|
|
71
|
+
let paths = exact.get(method);
|
|
72
|
+
if (!paths) exact.set(method, paths = /* @__PURE__ */ new Set());
|
|
73
|
+
if (paths.has(route[1])) JITProbe.record("handler:indexed-duplicate");
|
|
74
|
+
else paths.add(route[1]);
|
|
75
|
+
}
|
|
66
76
|
for (const route of history) try {
|
|
67
77
|
if (route[0] === "WS") continue;
|
|
68
78
|
compileHandler(route, app);
|
|
69
79
|
} catch {
|
|
70
|
-
JITProbe.
|
|
71
|
-
return
|
|
72
|
-
jit: false,
|
|
73
|
-
reasons: ["handler:new-function"]
|
|
74
|
-
};
|
|
80
|
+
JITProbe.record("handler:new-function");
|
|
81
|
+
return JITProbe.end();
|
|
75
82
|
}
|
|
76
83
|
return JITProbe.end();
|
|
77
84
|
} finally {
|
|
@@ -94,45 +101,33 @@ const normalizeCheckIdentifiers = (src) => {
|
|
|
94
101
|
};
|
|
95
102
|
function createEntryEncoder() {
|
|
96
103
|
const branchRef = /* @__PURE__ */ new Map();
|
|
97
|
-
let branchDecls = "";
|
|
98
104
|
const branchTable = (u) => "[" + u.map((branch) => "[" + branch.map((b) => {
|
|
99
105
|
const src = normalizeCheckIdentifiers(Source.checkFactory(b.identifier, b.code));
|
|
100
106
|
let ref = branchRef.get(src);
|
|
101
107
|
if (ref === void 0) {
|
|
102
108
|
ref = `_b${branchRef.size}`;
|
|
103
109
|
branchRef.set(src, ref);
|
|
104
|
-
branchDecls += `const ${ref} = ${src}\n`;
|
|
110
|
+
enc.branchDecls += `const ${ref} = ${src}\n`;
|
|
105
111
|
}
|
|
106
112
|
return ref;
|
|
107
113
|
}).join(", ") + "]").join(", ") + "]";
|
|
108
114
|
const unionRef = /* @__PURE__ */ new Map();
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
ref =
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
unionTable,
|
|
123
|
-
setCoercePlan() {
|
|
124
|
-
hasCoercePlan = true;
|
|
125
|
-
},
|
|
126
|
-
get branchDecls() {
|
|
127
|
-
return branchDecls;
|
|
128
|
-
},
|
|
129
|
-
get unionDecls() {
|
|
130
|
-
return unionDecls;
|
|
131
|
-
},
|
|
132
|
-
get hasCoercePlan() {
|
|
133
|
-
return hasCoercePlan;
|
|
115
|
+
const enc = {
|
|
116
|
+
branchDecls: "",
|
|
117
|
+
unionDecls: "",
|
|
118
|
+
hasCoercePlan: false,
|
|
119
|
+
unionTable(u) {
|
|
120
|
+
const str = branchTable(u);
|
|
121
|
+
let ref = unionRef.get(str);
|
|
122
|
+
if (ref === void 0) {
|
|
123
|
+
ref = `_u${unionRef.size}`;
|
|
124
|
+
unionRef.set(str, ref);
|
|
125
|
+
enc.unionDecls += `const ${ref} = ${str}\n`;
|
|
126
|
+
}
|
|
127
|
+
return ref;
|
|
134
128
|
}
|
|
135
129
|
};
|
|
130
|
+
return enc;
|
|
136
131
|
}
|
|
137
132
|
function entryParts(c, enc) {
|
|
138
133
|
const parts = [];
|
|
@@ -192,14 +187,15 @@ function entryParts(c, enc) {
|
|
|
192
187
|
parts.push(`ic: [${ic}]`);
|
|
193
188
|
}
|
|
194
189
|
if (c.coercePlan) {
|
|
195
|
-
enc.
|
|
190
|
+
enc.hasCoercePlan = true;
|
|
196
191
|
parts.push(`cp: ${JSON.stringify(c.coercePlan)}`);
|
|
197
192
|
}
|
|
198
193
|
return parts;
|
|
199
194
|
}
|
|
200
195
|
function emitModule(captured, handlers, fingerprint, options) {
|
|
201
196
|
const enc = createEntryEncoder();
|
|
202
|
-
const treeToSource = (tree
|
|
197
|
+
const treeToSource = (tree) => {
|
|
198
|
+
const slotRef = /* @__PURE__ */ new Map();
|
|
203
199
|
const methods = [];
|
|
204
200
|
for (const method in tree) {
|
|
205
201
|
const paths = [];
|
|
@@ -209,7 +205,7 @@ function emitModule(captured, handlers, fingerprint, options) {
|
|
|
209
205
|
if (ref === void 0) {
|
|
210
206
|
ref = `_s${slotRef.size}`;
|
|
211
207
|
slotRef.set(slotObj, ref);
|
|
212
|
-
|
|
208
|
+
validatorDecls += `const ${ref} = ${slotObj}\n`;
|
|
213
209
|
}
|
|
214
210
|
paths.push(`${JSON.stringify(path)}:${ref}`);
|
|
215
211
|
}
|
|
@@ -341,7 +337,6 @@ function emitModule(captured, handlers, fingerprint, options) {
|
|
|
341
337
|
}
|
|
342
338
|
validatorDecls += `const _groups = [${thunks.join(", ")}]\n`;
|
|
343
339
|
validatorDecls += `const _groupOf = ${JSON.stringify(groupOf)}\n`;
|
|
344
|
-
validatorExport = options?.register ? "" : "export const groups = _groups\nexport const groupOf = _groupOf\n";
|
|
345
340
|
} else {
|
|
346
341
|
const factoryRef = /* @__PURE__ */ new Map();
|
|
347
342
|
const tree = nullObject();
|
|
@@ -358,59 +353,64 @@ function emitModule(captured, handlers, fingerprint, options) {
|
|
|
358
353
|
const byPath = tree[c.method] ??= nullObject();
|
|
359
354
|
(byPath[c.path] ??= nullObject())[c.slot] = ref;
|
|
360
355
|
}
|
|
361
|
-
const
|
|
362
|
-
validatorDecls += d;
|
|
363
|
-
});
|
|
364
|
-
validatorExport = options?.register ? `const validators = ${treeStr}\n` : `export const validators = ${treeStr}\n`;
|
|
356
|
+
validatorExport = `const validators = ${treeToSource(tree)}\n`;
|
|
365
357
|
}
|
|
366
358
|
const aliasRef = /* @__PURE__ */ new Map();
|
|
359
|
+
const factoryRef = /* @__PURE__ */ new Map();
|
|
367
360
|
const handlerRef = /* @__PURE__ */ new Map();
|
|
368
361
|
let handlerDecls = "";
|
|
369
362
|
const handlerTree = nullObject();
|
|
370
363
|
for (const h of handlers) {
|
|
364
|
+
const k = h.k === void 0 ? "" : `k: ${JSON.stringify(h.k)}`;
|
|
365
|
+
if (!h.code) {
|
|
366
|
+
(handlerTree[h.method] ??= {})[h.path] = `{ ${k} }`;
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
371
369
|
const src = Source.handlerFactory(h.alias, h.code);
|
|
372
|
-
let
|
|
370
|
+
let fref = factoryRef.get(src);
|
|
371
|
+
if (fref === void 0) {
|
|
372
|
+
fref = `_h${factoryRef.size}`;
|
|
373
|
+
factoryRef.set(src, fref);
|
|
374
|
+
handlerDecls += `const ${fref} = ${src}\n`;
|
|
375
|
+
}
|
|
376
|
+
let wref = handlerRef.get(fref + k);
|
|
373
377
|
if (wref === void 0) {
|
|
374
|
-
const n = handlerRef.size;
|
|
375
378
|
let aref = aliasRef.get(h.alias);
|
|
376
379
|
if (aref === void 0) {
|
|
377
380
|
aref = `_a${aliasRef.size}`;
|
|
378
381
|
aliasRef.set(h.alias, aref);
|
|
379
382
|
handlerDecls += `const ${aref} = ${JSON.stringify(h.alias ? h.alias.split(",") : [])}\n`;
|
|
380
383
|
}
|
|
381
|
-
wref = `_w${
|
|
382
|
-
handlerRef.set(
|
|
383
|
-
handlerDecls += `const
|
|
384
|
+
wref = `_w${handlerRef.size}`;
|
|
385
|
+
handlerRef.set(fref + k, wref);
|
|
386
|
+
handlerDecls += `const ${wref} = { a: ${aref}, f: ${fref}, ${k} }\n`;
|
|
384
387
|
}
|
|
385
388
|
(handlerTree[h.method] ??= {})[h.path] = wref;
|
|
386
389
|
}
|
|
387
|
-
let handlerExport =
|
|
390
|
+
let handlerExport = "const handlers = {\n";
|
|
388
391
|
for (const method in handlerTree) {
|
|
389
392
|
handlerExport += `\t${JSON.stringify(method)}: {\n`;
|
|
390
393
|
for (const path in handlerTree[method]) handlerExport += `\t\t${JSON.stringify(path)}: ${handlerTree[method][path]},\n`;
|
|
391
394
|
handlerExport += " },\n";
|
|
392
395
|
}
|
|
393
396
|
handlerExport += "}\n";
|
|
394
|
-
const fingerprintExport = options?.register ? `export const fingerprint = ${JSON.stringify(fingerprint)}\n` : "";
|
|
395
397
|
let body = "// Generated by Elysia build plugin. Do not edit.\n";
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
398
|
+
const moduleCondition = options?.moduleCondition ?? "esm";
|
|
399
|
+
const importNamed = (name, specifier) => moduleCondition === "cjs" ? `const { ${name} } = require(${JSON.stringify(specifier)})\n` : `import { ${name} } from ${JSON.stringify(specifier)}\n`;
|
|
400
|
+
body += importNamed("Compiled", options?.registerFrom ?? "elysia");
|
|
401
|
+
if (enc.hasCoercePlan) body += importNamed("buildCoercedFromPlan", "elysia/coerce-plan");
|
|
402
|
+
if (captured.length) body += importNamed("Reconstruct", options?.reconstructFrom ?? "elysia/reconstruct");
|
|
399
403
|
const generated = enc.branchDecls + enc.unionDecls + validatorDecls + handlerDecls;
|
|
400
404
|
const needs = (symbol) => new RegExp(`\\b${symbol}\\b`).test(generated);
|
|
401
|
-
if (needs("CheckContext")) body += "
|
|
402
|
-
if (needs("Guard")) body += "
|
|
403
|
-
if (needs("Format")) body += "
|
|
404
|
-
if (needs("Hashing")) body += "
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
405
|
+
if (needs("CheckContext")) body += importNamed("CheckContext", "typebox/schema");
|
|
406
|
+
if (needs("Guard")) body += importNamed("Guard", "typebox/guard");
|
|
407
|
+
if (needs("Format")) body += importNamed("Format", "typebox/format");
|
|
408
|
+
if (needs("Hashing")) body += importNamed("Hashing", "typebox/system");
|
|
409
|
+
body += "\n";
|
|
410
|
+
if (captured.length) body += "Compiled.reconstruct = Reconstruct\n";
|
|
411
|
+
body += `export const fingerprint = ${JSON.stringify(fingerprint)}\nCompiled.register((() => {
|
|
412
|
+
` + enc.branchDecls + (enc.branchDecls && "\n") + enc.unionDecls + (enc.unionDecls && "\n") + validatorDecls + handlerDecls + "\n" + validatorExport + "\n" + handlerExport + "\nreturn { fingerprint, " + (lazy ? "lazyGroups: _groups, lazyGroupOf: _groupOf, " : "validators, ") + `handlers${enc.hasCoercePlan ? ", planRebuilder: buildCoercedFromPlan" : ""} }\n})())
|
|
409
413
|
`;
|
|
410
|
-
} else {
|
|
411
|
-
body += "\n" + enc.branchDecls + (enc.branchDecls && "\n") + enc.unionDecls + (enc.unionDecls && "\n") + validatorDecls + handlerDecls + "\n" + validatorExport + "\n" + handlerExport + "\n";
|
|
412
|
-
if (!lazy) body += "\nexport default validators\n";
|
|
413
|
-
}
|
|
414
414
|
return body;
|
|
415
415
|
}
|
|
416
416
|
|
|
@@ -2,7 +2,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_compile_lexer = require('../../compile/lexer.js');
|
|
3
3
|
|
|
4
4
|
//#region src/plugin/aot/treeshake.ts
|
|
5
|
-
const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
6
5
|
function nonCodeSpans(code) {
|
|
7
6
|
const spans = [];
|
|
8
7
|
const length = code.length;
|
|
@@ -49,7 +48,7 @@ function rewriteTypeImport(code) {
|
|
|
49
48
|
const from = "elysia";
|
|
50
49
|
const typeFrom = "elysia/type";
|
|
51
50
|
if (!code.includes(from)) return code;
|
|
52
|
-
const importRe = new RegExp(`(^|\\n)([ \\t]*)import\\s+(?!type\\b)((?:[A-Za-z_$][\\w$]*\\s*,\\s*)?\\{[^}]*\\})\\s+from\\s*(['"])${
|
|
51
|
+
const importRe = new RegExp(`(^|\\n)([ \\t]*)import\\s+(?!type\\b)((?:[A-Za-z_$][\\w$]*\\s*,\\s*)?\\{[^}]*\\})\\s+from\\s*(['"])${from}\\4(\\s*(?:with|assert)\\s*\\{[^}]*\\})?`, "g");
|
|
53
52
|
const spans = nonCodeSpans(code);
|
|
54
53
|
const edits = [];
|
|
55
54
|
let m;
|
|
@@ -58,9 +57,7 @@ function rewriteTypeImport(code) {
|
|
|
58
57
|
const keyword = m.index + lead.length + indent.length;
|
|
59
58
|
if (spans.some(([start, end]) => keyword >= start && keyword < end)) continue;
|
|
60
59
|
const braceStart = clause.indexOf("{");
|
|
61
|
-
if (braceStart === -1) continue;
|
|
62
60
|
const braceEnd = clause.indexOf("}", braceStart);
|
|
63
|
-
if (braceEnd === -1) continue;
|
|
64
61
|
const before = clause.slice(0, braceStart).trim();
|
|
65
62
|
const memberSource = clause.slice(braceStart + 1, braceEnd);
|
|
66
63
|
if (/['"`]|\/\/|\/\*/.test(memberSource)) continue;
|
|
@@ -73,8 +70,7 @@ function rewriteTypeImport(code) {
|
|
|
73
70
|
else kept.push(member);
|
|
74
71
|
}
|
|
75
72
|
if (!alias) continue;
|
|
76
|
-
const
|
|
77
|
-
const keptClause = head && kept.length ? `${head}, { ${kept.join(", ")} }` : head ? head : kept.length ? `{ ${kept.join(", ")} }` : "";
|
|
73
|
+
const keptClause = [before.replace(/,\s*$/, "").trim(), kept.length ? `{ ${kept.join(", ")} }` : ""].filter(Boolean).join(", ");
|
|
78
74
|
const attr = attributes ?? "";
|
|
79
75
|
const lines = [];
|
|
80
76
|
if (keptClause) lines.push(`import ${keptClause} from '${from}'${attr}`);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { skipString } from "../../compile/lexer.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugin/aot/treeshake.ts
|
|
4
|
-
const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
5
4
|
function nonCodeSpans(code) {
|
|
6
5
|
const spans = [];
|
|
7
6
|
const length = code.length;
|
|
@@ -48,7 +47,7 @@ function rewriteTypeImport(code) {
|
|
|
48
47
|
const from = "elysia";
|
|
49
48
|
const typeFrom = "elysia/type";
|
|
50
49
|
if (!code.includes(from)) return code;
|
|
51
|
-
const importRe = new RegExp(`(^|\\n)([ \\t]*)import\\s+(?!type\\b)((?:[A-Za-z_$][\\w$]*\\s*,\\s*)?\\{[^}]*\\})\\s+from\\s*(['"])${
|
|
50
|
+
const importRe = new RegExp(`(^|\\n)([ \\t]*)import\\s+(?!type\\b)((?:[A-Za-z_$][\\w$]*\\s*,\\s*)?\\{[^}]*\\})\\s+from\\s*(['"])${from}\\4(\\s*(?:with|assert)\\s*\\{[^}]*\\})?`, "g");
|
|
52
51
|
const spans = nonCodeSpans(code);
|
|
53
52
|
const edits = [];
|
|
54
53
|
let m;
|
|
@@ -57,9 +56,7 @@ function rewriteTypeImport(code) {
|
|
|
57
56
|
const keyword = m.index + lead.length + indent.length;
|
|
58
57
|
if (spans.some(([start, end]) => keyword >= start && keyword < end)) continue;
|
|
59
58
|
const braceStart = clause.indexOf("{");
|
|
60
|
-
if (braceStart === -1) continue;
|
|
61
59
|
const braceEnd = clause.indexOf("}", braceStart);
|
|
62
|
-
if (braceEnd === -1) continue;
|
|
63
60
|
const before = clause.slice(0, braceStart).trim();
|
|
64
61
|
const memberSource = clause.slice(braceStart + 1, braceEnd);
|
|
65
62
|
if (/['"`]|\/\/|\/\*/.test(memberSource)) continue;
|
|
@@ -72,8 +69,7 @@ function rewriteTypeImport(code) {
|
|
|
72
69
|
else kept.push(member);
|
|
73
70
|
}
|
|
74
71
|
if (!alias) continue;
|
|
75
|
-
const
|
|
76
|
-
const keptClause = head && kept.length ? `${head}, { ${kept.join(", ")} }` : head ? head : kept.length ? `{ ${kept.join(", ")} }` : "";
|
|
72
|
+
const keptClause = [before.replace(/,\s*$/, "").trim(), kept.length ? `{ ${kept.join(", ")} }` : ""].filter(Boolean).join(", ");
|
|
77
73
|
const attr = attributes ?? "";
|
|
78
74
|
const lines = [];
|
|
79
75
|
if (keptClause) lines.push(`import ${keptClause} from '${from}'${attr}`);
|
|
@@ -16,14 +16,11 @@ interface ElysiaAotUnpluginFactoryResult {
|
|
|
16
16
|
resolveId?: (id: string) => string | undefined;
|
|
17
17
|
load?: (id: string) => string | undefined;
|
|
18
18
|
transformInclude?: (id: string) => boolean;
|
|
19
|
-
transform?: (code: string, id: string) => string | undefined
|
|
20
|
-
/** Vite-specific override (`apply: 'build'` keeps dev on runtime JIT). */
|
|
19
|
+
transform?: (code: string, id: string) => string | undefined;
|
|
21
20
|
vite?: {
|
|
22
21
|
apply?: 'build' | 'serve';
|
|
23
22
|
};
|
|
24
|
-
/** rspack compiler hook: forces the manifest module side-effectful. */
|
|
25
23
|
rspack?: (compiler: unknown) => void;
|
|
26
|
-
/** webpack compiler hook: forces the manifest module side-effectful. */
|
|
27
24
|
webpack?: (compiler: unknown) => void;
|
|
28
25
|
}
|
|
29
26
|
/**
|
|
@@ -2,7 +2,6 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
|
|
|
2
2
|
const require_plugin_aot_hooks = require('./hooks.js');
|
|
3
3
|
|
|
4
4
|
//#region src/plugin/aot/unplugin.ts
|
|
5
|
-
const cleanIdOf = (id) => id.split("?", 1)[0];
|
|
6
5
|
const VIRTUAL_MANIFEST_RESOURCE = /%00elysia%2Fcompiled/;
|
|
7
6
|
const forceManifestSideEffect = (compiler) => {
|
|
8
7
|
compiler.options.module.rules.push({
|
|
@@ -37,18 +36,10 @@ const aotFactory = (options) => {
|
|
|
37
36
|
enforce: "pre",
|
|
38
37
|
buildStart: hooks.buildStart,
|
|
39
38
|
buildEnd: hooks.buildEnd,
|
|
40
|
-
resolveId
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
return hooks.load(id) ?? void 0;
|
|
45
|
-
},
|
|
46
|
-
transformInclude(id) {
|
|
47
|
-
return hooks.isTransformCandidate(cleanIdOf(id));
|
|
48
|
-
},
|
|
49
|
-
transform(code, id) {
|
|
50
|
-
return hooks.transform(code, id);
|
|
51
|
-
},
|
|
39
|
+
resolveId: hooks.resolveId,
|
|
40
|
+
load: hooks.load,
|
|
41
|
+
transformInclude: hooks.isTransformCandidate,
|
|
42
|
+
transform: hooks.transform,
|
|
52
43
|
vite: { apply: "build" },
|
|
53
44
|
rspack(compiler) {
|
|
54
45
|
forceManifestSideEffect(compiler);
|