elysia 1.4.28 → 2.0.0-beta.0
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/_virtual/_rolldown/runtime.js +29 -0
- package/dist/_virtual/_rolldown/runtime.mjs +38 -0
- package/dist/adapter/bun/index.d.ts +7 -6
- package/dist/adapter/bun/index.js +219 -380
- package/dist/adapter/bun/index.mjs +217 -382
- package/dist/adapter/constants.d.ts +6 -0
- package/dist/adapter/constants.js +10 -0
- package/dist/adapter/constants.mjs +9 -0
- package/dist/adapter/default-headers.d.ts +4 -0
- package/dist/adapter/default-headers.js +7 -0
- package/dist/adapter/default-headers.mjs +5 -0
- package/dist/adapter/index.d.ts +8 -1
- package/dist/adapter/index.js +7 -14
- package/dist/adapter/index.mjs +5 -0
- package/dist/adapter/origin.d.ts +63 -0
- package/dist/adapter/origin.js +64 -0
- package/dist/adapter/origin.mjs +62 -0
- package/dist/adapter/response-ownership.d.ts +5 -0
- package/dist/adapter/response-ownership.js +13 -0
- package/dist/adapter/response-ownership.mjs +10 -0
- package/dist/adapter/skip-clone.d.ts +4 -0
- package/dist/adapter/skip-clone.js +7 -0
- package/dist/adapter/skip-clone.mjs +5 -0
- package/dist/adapter/types.d.ts +50 -125
- package/dist/adapter/types.js +1 -14
- package/dist/adapter/types.mjs +1 -0
- package/dist/adapter/utils.d.ts +47 -19
- package/dist/adapter/utils.js +561 -311
- package/dist/adapter/utils.mjs +551 -283
- package/dist/adapter/web-standard/handler.d.ts +11 -9
- package/dist/adapter/web-standard/handler.js +146 -415
- package/dist/adapter/web-standard/handler.mjs +144 -400
- package/dist/adapter/web-standard/index.d.ts +5 -2
- package/dist/adapter/web-standard/index.js +68 -161
- package/dist/adapter/web-standard/index.mjs +68 -146
- package/dist/adapter/web-standard/utils.d.ts +4 -0
- package/dist/adapter/web-standard/utils.js +153 -0
- package/dist/adapter/web-standard/utils.mjs +152 -0
- package/dist/base.d.ts +898 -0
- package/dist/base.js +1564 -0
- package/dist/base.mjs +1561 -0
- package/dist/compile/analysis-cache.d.ts +6 -0
- package/dist/compile/analysis-cache.js +12 -0
- package/dist/compile/analysis-cache.mjs +11 -0
- package/dist/compile/aot-capture.d.ts +24 -0
- package/dist/compile/aot-capture.js +376 -0
- package/dist/compile/aot-capture.mjs +365 -0
- package/dist/compile/aot-emit.d.ts +29 -0
- package/dist/compile/aot-emit.js +107 -0
- package/dist/compile/aot-emit.mjs +101 -0
- package/dist/compile/aot-reconstruct.d.ts +30 -0
- package/dist/compile/aot-reconstruct.js +156 -0
- package/dist/compile/aot-reconstruct.mjs +147 -0
- package/dist/compile/aot.d.ts +287 -0
- package/dist/compile/aot.js +220 -0
- package/dist/compile/aot.mjs +200 -0
- package/dist/compile/handler/descriptor.d.ts +77 -0
- package/dist/compile/handler/descriptor.js +199 -0
- package/dist/compile/handler/descriptor.mjs +194 -0
- package/dist/compile/handler/frozen-validator.d.ts +39 -0
- package/dist/compile/handler/frozen-validator.js +319 -0
- package/dist/compile/handler/frozen-validator.mjs +313 -0
- package/dist/compile/handler/index.d.ts +19 -0
- package/dist/compile/handler/index.js +379 -0
- package/dist/compile/handler/index.mjs +371 -0
- package/dist/compile/handler/jit.d.ts +43 -0
- package/dist/compile/handler/jit.js +536 -0
- package/dist/compile/handler/jit.mjs +532 -0
- package/dist/compile/handler/params.d.ts +28 -0
- package/dist/compile/handler/params.js +78 -0
- package/dist/compile/handler/params.mjs +76 -0
- package/dist/compile/handler/reconstruct.d.ts +12 -0
- package/dist/compile/handler/reconstruct.js +50 -0
- package/dist/compile/handler/reconstruct.mjs +49 -0
- package/dist/compile/handler/utils.d.ts +45 -0
- package/dist/compile/handler/utils.js +514 -0
- package/dist/compile/handler/utils.mjs +498 -0
- package/dist/compile/jit-probe.d.ts +15 -0
- package/dist/compile/jit-probe.js +28 -0
- package/dist/compile/jit-probe.mjs +26 -0
- package/dist/compile/lexer.d.ts +7 -0
- package/dist/compile/lexer.js +53 -0
- package/dist/compile/lexer.mjs +48 -0
- package/dist/compile/utils.d.ts +8 -0
- package/dist/compile/utils.js +23 -0
- package/dist/compile/utils.mjs +19 -0
- package/dist/compiled.d.ts +17 -0
- package/dist/compiled.js +20 -0
- package/dist/compiled.mjs +16 -0
- package/dist/constants.d.ts +137 -0
- package/dist/constants.js +96 -0
- package/dist/constants.mjs +88 -0
- package/dist/context.d.ts +86 -129
- package/dist/context.js +110 -13
- package/dist/context.mjs +108 -0
- package/dist/cookie/config.d.ts +31 -0
- package/dist/cookie/config.js +98 -0
- package/dist/cookie/config.mjs +95 -0
- package/dist/cookie/cookie.d.ts +26 -0
- package/dist/cookie/cookie.js +105 -0
- package/dist/cookie/cookie.mjs +104 -0
- package/dist/cookie/crypto.d.ts +20 -0
- package/dist/cookie/crypto.js +168 -0
- package/dist/cookie/crypto.mjs +151 -0
- package/dist/cookie/error.d.ts +17 -0
- package/dist/cookie/error.js +25 -0
- package/dist/cookie/error.mjs +24 -0
- package/dist/cookie/index.d.ts +7 -0
- package/dist/cookie/index.js +13 -0
- package/dist/cookie/index.mjs +7 -0
- package/dist/cookie/lib.d.ts +7 -0
- package/dist/cookie/lib.js +76 -0
- package/dist/cookie/lib.mjs +74 -0
- package/dist/cookie/serialize.d.ts +6 -0
- package/dist/cookie/serialize.js +32 -0
- package/dist/cookie/serialize.mjs +31 -0
- package/dist/cookie/types.d.ts +113 -0
- package/dist/cookie/types.js +1 -0
- package/dist/cookie/types.mjs +1 -0
- package/dist/cookie/utils.d.ts +25 -0
- package/dist/cookie/utils.js +182 -0
- package/dist/cookie/utils.mjs +171 -0
- package/dist/error.d.ts +226 -188
- package/dist/error.js +519 -357
- package/dist/error.mjs +503 -327
- package/dist/generation.d.ts +30 -0
- package/dist/generation.js +23 -0
- package/dist/generation.mjs +17 -0
- package/dist/handler/error.d.ts +7 -0
- package/dist/handler/error.js +105 -0
- package/dist/handler/error.mjs +104 -0
- package/dist/handler/fetch.d.ts +8 -0
- package/dist/handler/fetch.js +371 -0
- package/dist/handler/fetch.mjs +367 -0
- package/dist/handler/index.d.ts +2 -0
- package/dist/handler/index.js +5 -0
- package/dist/handler/index.mjs +3 -0
- package/dist/handler/utils.d.ts +15 -0
- package/dist/handler/utils.js +48 -0
- package/dist/handler/utils.mjs +42 -0
- package/dist/index.d.ts +23 -2198
- package/dist/index.js +62 -1948
- package/dist/index.mjs +20 -1986
- package/dist/memory.d.ts +4 -0
- package/dist/memory.js +17 -0
- package/dist/memory.mjs +16 -0
- package/dist/package.js +11 -0
- package/dist/package.mjs +5 -0
- package/dist/parse-query.d.ts +7 -9
- package/dist/parse-query.js +154 -164
- package/dist/parse-query.mjs +150 -133
- package/dist/plugin/aot/bun.d.ts +26 -0
- package/dist/plugin/aot/bun.js +35 -0
- package/dist/plugin/aot/bun.mjs +34 -0
- package/dist/plugin/aot/core.d.ts +291 -0
- package/dist/plugin/aot/core.js +505 -0
- package/dist/plugin/aot/core.mjs +481 -0
- package/dist/plugin/aot/esbuild.d.ts +28 -0
- package/dist/plugin/aot/esbuild.js +48 -0
- package/dist/plugin/aot/esbuild.mjs +46 -0
- package/dist/plugin/aot/hooks.d.ts +28 -0
- package/dist/plugin/aot/hooks.js +114 -0
- package/dist/plugin/aot/hooks.mjs +112 -0
- package/dist/plugin/aot/rspack-loader.d.ts +23 -0
- package/dist/plugin/aot/rspack-loader.js +44 -0
- package/dist/plugin/aot/rspack-loader.mjs +40 -0
- package/dist/plugin/aot/rspack.d.ts +23 -0
- package/dist/plugin/aot/rspack.js +85 -0
- package/dist/plugin/aot/rspack.mjs +82 -0
- package/dist/plugin/aot/source.d.ts +60 -0
- package/dist/plugin/aot/source.js +422 -0
- package/dist/plugin/aot/source.mjs +418 -0
- package/dist/plugin/aot/treeshake.d.ts +4 -0
- package/dist/plugin/aot/treeshake.js +95 -0
- package/dist/plugin/aot/treeshake.mjs +94 -0
- package/dist/plugin/aot/unplugin.d.ts +50 -0
- package/dist/plugin/aot/unplugin.js +64 -0
- package/dist/plugin/aot/unplugin.mjs +62 -0
- package/dist/plugin/aot/vite.d.ts +30 -0
- package/dist/plugin/aot/vite.js +34 -0
- package/dist/plugin/aot/vite.mjs +33 -0
- package/dist/plugin/aot/worker.d.ts +1 -0
- package/dist/plugin/aot/worker.js +28 -0
- package/dist/plugin/aot/worker.mjs +27 -0
- package/dist/plugin/auto-head.d.ts +6 -0
- package/dist/plugin/auto-head.js +38 -0
- package/dist/plugin/auto-head.mjs +36 -0
- package/dist/plugin/trace.d.ts +10 -0
- package/dist/plugin/trace.js +39 -0
- package/dist/plugin/trace.mjs +36 -0
- package/dist/plugin/websocket.d.ts +6 -0
- package/dist/plugin/websocket.js +61 -0
- package/dist/plugin/websocket.mjs +60 -0
- package/dist/route-table.d.ts +28 -0
- package/dist/route-table.js +64 -0
- package/dist/route-table.mjs +61 -0
- package/dist/schema-snapshot.d.ts +9 -0
- package/dist/schema-snapshot.js +271 -0
- package/dist/schema-snapshot.mjs +269 -0
- package/dist/sucrose.d.ts +28 -63
- package/dist/sucrose.js +814 -306
- package/dist/sucrose.mjs +805 -274
- package/dist/trace.d.ts +145 -130
- package/dist/trace.js +387 -135
- package/dist/trace.mjs +385 -113
- package/dist/type/bridge-live.d.ts +15 -0
- package/dist/type/bridge-live.js +39 -0
- package/dist/type/bridge-live.mjs +17 -0
- package/dist/type/bridge.d.ts +56 -0
- package/dist/type/bridge.js +180 -0
- package/dist/type/bridge.mjs +63 -0
- package/dist/type/coerce-plan.d.ts +38 -0
- package/dist/type/coerce-plan.js +107 -0
- package/dist/type/coerce-plan.mjs +98 -0
- package/dist/type/coerce.d.ts +43 -0
- package/dist/type/coerce.js +351 -0
- package/dist/type/coerce.mjs +339 -0
- package/dist/type/compat.d.ts +8 -0
- package/dist/type/compat.js +46 -0
- package/dist/type/compat.mjs +44 -0
- package/dist/type/constants.d.ts +25 -0
- package/dist/type/constants.js +36 -0
- package/dist/type/constants.mjs +32 -0
- package/dist/type/elysia/accelerate.d.ts +6 -0
- package/dist/type/elysia/accelerate.js +12 -0
- package/dist/type/elysia/accelerate.mjs +10 -0
- package/dist/type/elysia/array-buffer.d.ts +6 -0
- package/dist/type/elysia/array-buffer.js +27 -0
- package/dist/type/elysia/array-buffer.mjs +25 -0
- package/dist/type/elysia/array-string.d.ts +7 -0
- package/dist/type/elysia/array-string.js +28 -0
- package/dist/type/elysia/array-string.mjs +26 -0
- package/dist/type/elysia/array.d.ts +6 -0
- package/dist/type/elysia/array.js +32 -0
- package/dist/type/elysia/array.mjs +31 -0
- package/dist/type/elysia/boolean-string.d.ts +6 -0
- package/dist/type/elysia/boolean-string.js +24 -0
- package/dist/type/elysia/boolean-string.mjs +22 -0
- package/dist/type/elysia/boolean.d.ts +6 -0
- package/dist/type/elysia/boolean.js +20 -0
- package/dist/type/elysia/boolean.mjs +18 -0
- package/dist/type/elysia/cookie.d.ts +15 -0
- package/dist/type/elysia/cookie.js +51 -0
- package/dist/type/elysia/cookie.mjs +50 -0
- package/dist/type/elysia/date.d.ts +7 -0
- package/dist/type/elysia/date.js +98 -0
- package/dist/type/elysia/date.mjs +96 -0
- package/dist/type/elysia/file-type.d.ts +25 -0
- package/dist/type/elysia/file-type.js +81 -0
- package/dist/type/elysia/file-type.mjs +71 -0
- package/dist/type/elysia/file.d.ts +9 -0
- package/dist/type/elysia/file.js +64 -0
- package/dist/type/elysia/file.mjs +48 -0
- package/dist/type/elysia/files.d.ts +8 -0
- package/dist/type/elysia/files.js +45 -0
- package/dist/type/elysia/files.mjs +43 -0
- package/dist/type/elysia/form.d.ts +8 -0
- package/dist/type/elysia/form.js +17 -0
- package/dist/type/elysia/form.mjs +15 -0
- package/dist/type/elysia/integer-string.d.ts +7 -0
- package/dist/type/elysia/integer-string.js +40 -0
- package/dist/type/elysia/integer-string.mjs +38 -0
- package/dist/type/elysia/integer.d.ts +6 -0
- package/dist/type/elysia/integer.js +20 -0
- package/dist/type/elysia/integer.mjs +18 -0
- package/dist/type/elysia/intersect.d.ts +6 -0
- package/dist/type/elysia/intersect.js +20 -0
- package/dist/type/elysia/intersect.mjs +19 -0
- package/dist/type/elysia/maybe-empty.d.ts +7 -0
- package/dist/type/elysia/maybe-empty.js +21 -0
- package/dist/type/elysia/maybe-empty.mjs +19 -0
- package/dist/type/elysia/no-validate.d.ts +6 -0
- package/dist/type/elysia/no-validate.js +9 -0
- package/dist/type/elysia/no-validate.mjs +8 -0
- package/dist/type/elysia/nullable.d.ts +7 -0
- package/dist/type/elysia/nullable.js +15 -0
- package/dist/type/elysia/nullable.mjs +13 -0
- package/dist/type/elysia/number.d.ts +6 -0
- package/dist/type/elysia/number.js +20 -0
- package/dist/type/elysia/number.mjs +18 -0
- package/dist/type/elysia/numeric-enum.d.ts +11 -0
- package/dist/type/elysia/numeric-enum.js +26 -0
- package/dist/type/elysia/numeric-enum.mjs +24 -0
- package/dist/type/elysia/numeric.d.ts +7 -0
- package/dist/type/elysia/numeric.js +62 -0
- package/dist/type/elysia/numeric.mjs +60 -0
- package/dist/type/elysia/object-string.d.ts +7 -0
- package/dist/type/elysia/object-string.js +28 -0
- package/dist/type/elysia/object-string.mjs +26 -0
- package/dist/type/elysia/object.d.ts +6 -0
- package/dist/type/elysia/object.js +47 -0
- package/dist/type/elysia/object.mjs +46 -0
- package/dist/type/elysia/optional.d.ts +6 -0
- package/dist/type/elysia/optional.js +22 -0
- package/dist/type/elysia/optional.mjs +21 -0
- package/dist/type/elysia/string.d.ts +6 -0
- package/dist/type/elysia/string.js +43 -0
- package/dist/type/elysia/string.mjs +41 -0
- package/dist/type/elysia/uint8-array.d.ts +6 -0
- package/dist/type/elysia/uint8-array.js +27 -0
- package/dist/type/elysia/uint8-array.mjs +25 -0
- package/dist/type/elysia/union-enum.d.ts +8 -0
- package/dist/type/elysia/union-enum.js +31 -0
- package/dist/type/elysia/union-enum.mjs +29 -0
- package/dist/type/elysia/union.d.ts +6 -0
- package/dist/type/elysia/union.js +20 -0
- package/dist/type/elysia/union.mjs +19 -0
- package/dist/type/elysia/utils.d.ts +53 -0
- package/dist/type/elysia/utils.js +98 -0
- package/dist/type/elysia/utils.mjs +88 -0
- package/dist/type/exports.d.ts +36 -0
- package/dist/type/exports.js +68 -0
- package/dist/type/exports.mjs +36 -0
- package/dist/type/index.d.ts +13 -0
- package/dist/type/index.js +81 -0
- package/dist/type/index.mjs +68 -0
- package/dist/type/shared.d.ts +27 -0
- package/dist/type/shared.js +171 -0
- package/dist/type/shared.mjs +161 -0
- package/dist/type/types.d.ts +206 -0
- package/dist/type/types.js +1 -0
- package/dist/type/types.mjs +1 -0
- package/dist/type/utils.d.ts +7 -0
- package/dist/type/utils.js +43 -0
- package/dist/type/utils.mjs +41 -0
- package/dist/type/validator/clean-safe.d.ts +8 -0
- package/dist/type/validator/clean-safe.js +82 -0
- package/dist/type/validator/clean-safe.mjs +77 -0
- package/dist/type/validator/custom-error.d.ts +10 -0
- package/dist/type/validator/custom-error.js +191 -0
- package/dist/type/validator/custom-error.mjs +188 -0
- package/dist/type/validator/default-precompute.d.ts +26 -0
- package/dist/type/validator/default-precompute.js +432 -0
- package/dist/type/validator/default-precompute.mjs +421 -0
- package/dist/type/validator/exact-mirror.d.ts +7 -0
- package/dist/type/validator/exact-mirror.js +19 -0
- package/dist/type/validator/exact-mirror.mjs +15 -0
- package/dist/type/validator/frozen-check.d.ts +11 -0
- package/dist/type/validator/frozen-check.js +20 -0
- package/dist/type/validator/frozen-check.mjs +19 -0
- package/dist/type/validator/index.d.ts +32 -0
- package/dist/type/validator/index.js +657 -0
- package/dist/type/validator/index.mjs +651 -0
- package/dist/type/validator/string-codec-aot.d.ts +8 -0
- package/dist/type/validator/string-codec-aot.js +68 -0
- package/dist/type/validator/string-codec-aot.mjs +66 -0
- package/dist/type/validator/validator-cache.d.ts +26 -0
- package/dist/type/validator/validator-cache.js +247 -0
- package/dist/type/validator/validator-cache.mjs +242 -0
- package/dist/types.d.ts +938 -1235
- package/dist/types.js +1 -14
- package/dist/types.mjs +1 -0
- package/dist/universal/constants.d.ts +6 -0
- package/dist/universal/constants.js +19 -0
- package/dist/universal/constants.mjs +15 -0
- package/dist/universal/env.d.ts +5 -1
- package/dist/universal/env.js +12 -26
- package/dist/universal/env.mjs +10 -5
- package/dist/universal/file.d.ts +55 -86
- package/dist/universal/file.js +116 -157
- package/dist/universal/file.mjs +111 -132
- package/dist/universal/index.d.ts +5 -3
- package/dist/universal/index.js +8 -27
- package/dist/universal/index.mjs +4 -5
- package/dist/universal/is-production.d.ts +5 -0
- package/dist/universal/is-production.js +10 -0
- package/dist/universal/is-production.mjs +8 -0
- package/dist/universal/server.d.ts +318 -313
- package/dist/universal/server.js +1 -14
- package/dist/universal/server.mjs +1 -0
- package/dist/utils.d.ts +162 -191
- package/dist/utils.js +732 -693
- package/dist/utils.mjs +683 -631
- package/dist/validator/index.d.ts +63 -0
- package/dist/validator/index.js +299 -0
- package/dist/validator/index.mjs +296 -0
- package/dist/validator/route.d.ts +32 -0
- package/dist/validator/route.js +51 -0
- package/dist/validator/route.mjs +50 -0
- package/dist/ws/context.d.ts +49 -0
- package/dist/ws/context.js +152 -0
- package/dist/ws/context.mjs +150 -0
- package/dist/ws/index.d.ts +5 -77
- package/dist/ws/index.js +11 -180
- package/dist/ws/index.mjs +5 -157
- package/dist/ws/parser.d.ts +5 -0
- package/dist/ws/parser.js +69 -0
- package/dist/ws/parser.mjs +66 -0
- package/dist/ws/route.d.ts +16 -0
- package/dist/ws/route.js +560 -0
- package/dist/ws/route.mjs +554 -0
- package/dist/ws/types.d.ts +154 -57
- package/dist/ws/types.js +1 -14
- package/dist/ws/types.mjs +1 -0
- package/package.json +179 -120
- package/bunfig.toml +0 -2
- package/dist/adapter/bun/compose.d.ts +0 -3
- package/dist/adapter/bun/compose.js +0 -90
- package/dist/adapter/bun/compose.mjs +0 -74
- package/dist/adapter/bun/handler-native.d.ts +0 -3
- package/dist/adapter/bun/handler-native.js +0 -42
- package/dist/adapter/bun/handler-native.mjs +0 -22
- package/dist/adapter/bun/handler.d.ts +0 -7
- package/dist/adapter/bun/handler.js +0 -363
- package/dist/adapter/bun/handler.mjs +0 -346
- package/dist/adapter/cloudflare-worker/index.d.ts +0 -20
- package/dist/adapter/cloudflare-worker/index.js +0 -59
- package/dist/adapter/cloudflare-worker/index.mjs +0 -39
- package/dist/compose.d.ts +0 -30
- package/dist/compose.js +0 -1324
- package/dist/compose.mjs +0 -1336
- package/dist/cookies.d.ts +0 -158
- package/dist/cookies.js +0 -250
- package/dist/cookies.mjs +0 -221
- package/dist/dynamic-handle.d.ts +0 -15
- package/dist/dynamic-handle.js +0 -521
- package/dist/dynamic-handle.mjs +0 -509
- package/dist/formats.d.ts +0 -79
- package/dist/formats.js +0 -153
- package/dist/formats.mjs +0 -132
- package/dist/manifest.d.ts +0 -0
- package/dist/manifest.js +0 -1
- package/dist/manifest.mjs +0 -0
- package/dist/replace-schema.d.ts +0 -60
- package/dist/replace-schema.js +0 -140
- package/dist/replace-schema.mjs +0 -115
- package/dist/schema.d.ts +0 -107
- package/dist/schema.js +0 -833
- package/dist/schema.mjs +0 -814
- package/dist/type-system/format.d.ts +0 -55
- package/dist/type-system/format.js +0 -197
- package/dist/type-system/format.mjs +0 -175
- package/dist/type-system/index.d.ts +0 -45
- package/dist/type-system/index.js +0 -406
- package/dist/type-system/index.mjs +0 -394
- package/dist/type-system/types.d.ts +0 -155
- package/dist/type-system/types.js +0 -14
- package/dist/type-system/types.mjs +0 -0
- package/dist/type-system/utils.d.ts +0 -62
- package/dist/type-system/utils.js +0 -141
- package/dist/type-system/utils.mjs +0 -111
- package/dist/universal/request.d.ts +0 -29
- package/dist/universal/request.js +0 -126
- package/dist/universal/request.mjs +0 -105
- package/dist/universal/types.d.ts +0 -124
- package/dist/universal/types.js +0 -41
- package/dist/universal/types.mjs +0 -19
- package/dist/universal/utils.d.ts +0 -3
- package/dist/universal/utils.js +0 -41
- package/dist/universal/utils.mjs +0 -18
- package/dist/ws/bun.d.ts +0 -419
- package/dist/ws/bun.js +0 -14
- package/dist/ws/bun.mjs +0 -0
- package/knip.json +0 -22
|
@@ -0,0 +1,418 @@
|
|
|
1
|
+
import { nullObject } from "../../utils.mjs";
|
|
2
|
+
import { env } from "../../universal/env.mjs";
|
|
3
|
+
import { Capture, Compiled, createAotFingerprint } from "../../compile/aot.mjs";
|
|
4
|
+
import { JITProbe } from "../../compile/jit-probe.mjs";
|
|
5
|
+
import { setCaptureHeaderShorthand } from "../../compile/handler/jit.mjs";
|
|
6
|
+
import { Validator } from "../../validator/index.mjs";
|
|
7
|
+
import { compileHandler } from "../../compile/handler/index.mjs";
|
|
8
|
+
import { Source } from "../../compile/aot-emit.mjs";
|
|
9
|
+
import { abortCapture, beginValidatorCapture, endHandlerCapture, endValidatorCapture, restoreCompiled, snapshotCompiled } from "../../compile/aot-capture.mjs";
|
|
10
|
+
|
|
11
|
+
//#region src/plugin/aot/source.ts
|
|
12
|
+
const autoGroupSize = (routes) => routes < 64 ? 1 : routes < 256 ? 2 : routes < 2048 ? 4 : routes < 8192 ? 16 : 64;
|
|
13
|
+
async function compileToSource(app, options) {
|
|
14
|
+
return (await captureArtifacts(app, options)).source;
|
|
15
|
+
}
|
|
16
|
+
async function captureArtifacts(app, options) {
|
|
17
|
+
const previousAotBuild = env.ELYSIA_AOT_BUILD;
|
|
18
|
+
env.ELYSIA_AOT_BUILD = "1";
|
|
19
|
+
try {
|
|
20
|
+
if (!Capture.isCapturing()) throw new Error("[elysia-aot]: ELYSIA_AOT_BUILD=1 must be set to enable AOT capture mode");
|
|
21
|
+
beginValidatorCapture();
|
|
22
|
+
const modules = app.modules;
|
|
23
|
+
if (modules) await modules;
|
|
24
|
+
if (options?.target !== void 0) setCaptureHeaderShorthand(options.target === "bun");
|
|
25
|
+
app.compile();
|
|
26
|
+
const captured = endValidatorCapture();
|
|
27
|
+
const handlers = endHandlerCapture();
|
|
28
|
+
const fingerprint = app["~aotFingerprint"] ?? createAotFingerprint();
|
|
29
|
+
return {
|
|
30
|
+
source: emitModule(captured, handlers, fingerprint, options),
|
|
31
|
+
validators: captured,
|
|
32
|
+
handlers,
|
|
33
|
+
fingerprint
|
|
34
|
+
};
|
|
35
|
+
} finally {
|
|
36
|
+
setCaptureHeaderShorthand(void 0);
|
|
37
|
+
abortCapture();
|
|
38
|
+
if (previousAotBuild === void 0) delete env.ELYSIA_AOT_BUILD;
|
|
39
|
+
else env.ELYSIA_AOT_BUILD = previousAotBuild;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const materialiseHandlersForReplay = (captured) => {
|
|
43
|
+
const manifest = {};
|
|
44
|
+
for (const h of captured) (manifest[h.method] ??= {})[h.path] = {
|
|
45
|
+
a: h.alias ? h.alias.split(",") : [],
|
|
46
|
+
f: new Function(`return ${Source.handlerFactory(h.alias, h.code)}`)()
|
|
47
|
+
};
|
|
48
|
+
return manifest;
|
|
49
|
+
};
|
|
50
|
+
function replayStubbability(app, handlers) {
|
|
51
|
+
const previousCompiled = snapshotCompiled();
|
|
52
|
+
const previousAotBuild = env.ELYSIA_AOT_BUILD;
|
|
53
|
+
if (previousAotBuild !== void 0) delete env.ELYSIA_AOT_BUILD;
|
|
54
|
+
try {
|
|
55
|
+
Compiled.clear();
|
|
56
|
+
const fingerprint = createAotFingerprint();
|
|
57
|
+
Compiled.register({
|
|
58
|
+
bf: 1,
|
|
59
|
+
fingerprint,
|
|
60
|
+
handlers: materialiseHandlersForReplay(handlers)
|
|
61
|
+
});
|
|
62
|
+
Compiled.claim(app["~programId"], fingerprint);
|
|
63
|
+
Validator.clear();
|
|
64
|
+
const history = app["~routes"] ?? [];
|
|
65
|
+
JITProbe.begin();
|
|
66
|
+
for (const route of history) try {
|
|
67
|
+
if (route[0] === "WS") continue;
|
|
68
|
+
compileHandler(route, app);
|
|
69
|
+
} catch {
|
|
70
|
+
JITProbe.end();
|
|
71
|
+
return {
|
|
72
|
+
jit: false,
|
|
73
|
+
reasons: ["handler:new-function"]
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return JITProbe.end();
|
|
77
|
+
} finally {
|
|
78
|
+
restoreCompiled(previousCompiled);
|
|
79
|
+
Validator.clear();
|
|
80
|
+
if (previousAotBuild !== void 0) env.ELYSIA_AOT_BUILD = previousAotBuild;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const checkIdRegex = /\bcheck_[0-9a-f]+\b/g;
|
|
84
|
+
const normalizeCheckIdentifiers = (src) => {
|
|
85
|
+
const seen = /* @__PURE__ */ new Map();
|
|
86
|
+
return src.replace(checkIdRegex, (id) => {
|
|
87
|
+
let name = seen.get(id);
|
|
88
|
+
if (name === void 0) {
|
|
89
|
+
name = `_k${seen.size}`;
|
|
90
|
+
seen.set(id, name);
|
|
91
|
+
}
|
|
92
|
+
return name;
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
function createEntryEncoder() {
|
|
96
|
+
const branchRef = /* @__PURE__ */ new Map();
|
|
97
|
+
let branchDecls = "";
|
|
98
|
+
const branchTable = (u) => "[" + u.map((branch) => "[" + branch.map((b) => {
|
|
99
|
+
const src = normalizeCheckIdentifiers(Source.checkFactory(b.identifier, b.code));
|
|
100
|
+
let ref = branchRef.get(src);
|
|
101
|
+
if (ref === void 0) {
|
|
102
|
+
ref = `_b${branchRef.size}`;
|
|
103
|
+
branchRef.set(src, ref);
|
|
104
|
+
branchDecls += `const ${ref} = ${src}\n`;
|
|
105
|
+
}
|
|
106
|
+
return ref;
|
|
107
|
+
}).join(", ") + "]").join(", ") + "]";
|
|
108
|
+
const unionRef = /* @__PURE__ */ new Map();
|
|
109
|
+
let unionDecls = "";
|
|
110
|
+
let hasCoercePlan = false;
|
|
111
|
+
const unionTable = (u) => {
|
|
112
|
+
const str = branchTable(u);
|
|
113
|
+
let ref = unionRef.get(str);
|
|
114
|
+
if (ref === void 0) {
|
|
115
|
+
ref = `_u${unionRef.size}`;
|
|
116
|
+
unionRef.set(str, ref);
|
|
117
|
+
unionDecls += `const ${ref} = ${str}\n`;
|
|
118
|
+
}
|
|
119
|
+
return ref;
|
|
120
|
+
};
|
|
121
|
+
return {
|
|
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;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function entryParts(c, enc) {
|
|
138
|
+
const parts = [];
|
|
139
|
+
const flags = [];
|
|
140
|
+
if (c.checkValue) {
|
|
141
|
+
if (c.external) flags.push("e:1");
|
|
142
|
+
if (c.async) flags.push("a:1");
|
|
143
|
+
if (c.hasDefault) flags.push("d:1");
|
|
144
|
+
if (c.hasCodec) flags.push("k:1");
|
|
145
|
+
if (c.hasRef) flags.push("r:1");
|
|
146
|
+
}
|
|
147
|
+
if (c.checkValue && c.mirror) {
|
|
148
|
+
const m = c.mirror;
|
|
149
|
+
parts.push(`cm: ${Source.bothFactory(c.identifier, c.checkDefs, c.checkValue, m.source, m.hasExternals)}`, ...flags);
|
|
150
|
+
if (m.u) parts.push(`u: ${enc.unionTable(m.u)}`);
|
|
151
|
+
} else if (c.checkValue) parts.push(`c: ${Source.checkFactory(c.identifier, Source.checkCode(c.checkDefs, c.checkValue))}`, ...flags);
|
|
152
|
+
else if (c.mirror) {
|
|
153
|
+
const m = c.mirror;
|
|
154
|
+
let ms = `s: ${Source.mirrorFactory(m.source, m.hasExternals)}`;
|
|
155
|
+
if (m.u) ms += `, u: ${enc.unionTable(m.u)}`;
|
|
156
|
+
parts.push(`m: { ${ms} }`);
|
|
157
|
+
}
|
|
158
|
+
if (c.decodeMirror) {
|
|
159
|
+
const dm = c.decodeMirror;
|
|
160
|
+
let dms = `s: ${Source.mirrorFactory(dm.source, true)}`;
|
|
161
|
+
if (dm.u) dms += `, u: ${enc.unionTable(dm.u)}`;
|
|
162
|
+
parts.push(`dm: { ${dms} }`);
|
|
163
|
+
}
|
|
164
|
+
if (c.encodeMirror) {
|
|
165
|
+
const em = c.encodeMirror;
|
|
166
|
+
let ems = `s: ${Source.mirrorFactory(em.source, true)}`;
|
|
167
|
+
if (em.u) ems += `, u: ${enc.unionTable(em.u)}`;
|
|
168
|
+
parts.push(`em: { ${ems} }`);
|
|
169
|
+
}
|
|
170
|
+
if (c.precomputeSafe) {
|
|
171
|
+
parts.push("ps: 1");
|
|
172
|
+
if (c.precomputedDefault !== void 0) parts.push(`pd: ${JSON.stringify(c.precomputedDefault)}`);
|
|
173
|
+
if (c.precomputeNull) parts.push("pn: 1");
|
|
174
|
+
if (c.precomputedObjectDefault !== void 0) parts.push(`pod: ${JSON.stringify(c.precomputedObjectDefault)}`);
|
|
175
|
+
if (c.defaultCloner) parts.push(`dc: ${c.defaultCloner}`);
|
|
176
|
+
if (c.objectDefaultMerger) parts.push(`pm: ${c.objectDefaultMerger}`);
|
|
177
|
+
}
|
|
178
|
+
if (c.customErrors?.length) {
|
|
179
|
+
const ce = c.customErrors.map((e) => `{ p: ${JSON.stringify(e.path)}, c: ${Source.checkFactory(e.identifier, Source.checkCode(e.checkDefs, e.checkValue))}${e.external ? ", e: 1" : ""} }`).join(", ");
|
|
180
|
+
parts.push(`ce: [${ce}]`);
|
|
181
|
+
}
|
|
182
|
+
if (c.innerCodecs?.length) {
|
|
183
|
+
const ic = c.innerCodecs.map((e) => {
|
|
184
|
+
let s = `o: ${e.open}, c: ${Source.checkFactory(e.identifier, Source.checkCode(e.checkDefs, e.checkValue))}`;
|
|
185
|
+
if (e.external) s += ", e: 1";
|
|
186
|
+
let ds = `s: ${Source.mirrorFactory(e.decode.source, e.decode.hasExternals)}`;
|
|
187
|
+
if (e.decode.u) ds += `, u: ${enc.unionTable(e.decode.u)}`;
|
|
188
|
+
if (e.decode.hasExternals) ds += ", x: 1";
|
|
189
|
+
s += `, d: { ${ds} }`;
|
|
190
|
+
return `{ ${s} }`;
|
|
191
|
+
}).join(", ");
|
|
192
|
+
parts.push(`ic: [${ic}]`);
|
|
193
|
+
}
|
|
194
|
+
if (c.coercePlan) {
|
|
195
|
+
enc.setCoercePlan();
|
|
196
|
+
parts.push(`cp: ${JSON.stringify(c.coercePlan)}`);
|
|
197
|
+
}
|
|
198
|
+
return parts;
|
|
199
|
+
}
|
|
200
|
+
function emitModule(captured, handlers, fingerprint, options) {
|
|
201
|
+
const enc = createEntryEncoder();
|
|
202
|
+
const treeToSource = (tree, slotRef, sink) => {
|
|
203
|
+
const methods = [];
|
|
204
|
+
for (const method in tree) {
|
|
205
|
+
const paths = [];
|
|
206
|
+
for (const path in tree[method]) {
|
|
207
|
+
const slotObj = "{" + Object.entries(tree[method][path]).map(([slot, ref]) => `${JSON.stringify(slot)}:${ref}`).join(",") + "}";
|
|
208
|
+
let ref = slotRef.get(slotObj);
|
|
209
|
+
if (ref === void 0) {
|
|
210
|
+
ref = `_s${slotRef.size}`;
|
|
211
|
+
slotRef.set(slotObj, ref);
|
|
212
|
+
sink(`const ${ref} = ${slotObj}\n`);
|
|
213
|
+
}
|
|
214
|
+
paths.push(`${JSON.stringify(path)}:${ref}`);
|
|
215
|
+
}
|
|
216
|
+
methods.push(`${JSON.stringify(method)}:{${paths.join(",")}}`);
|
|
217
|
+
}
|
|
218
|
+
return `{${methods.join(",")}}`;
|
|
219
|
+
};
|
|
220
|
+
let validatorDecls = "";
|
|
221
|
+
let validatorExport = "";
|
|
222
|
+
const order = [];
|
|
223
|
+
const byRoute = /* @__PURE__ */ new Map();
|
|
224
|
+
for (const c of captured) {
|
|
225
|
+
const key = `${c.method}\0${c.path}`;
|
|
226
|
+
let arr = byRoute.get(key);
|
|
227
|
+
if (!arr) {
|
|
228
|
+
byRoute.set(key, arr = []);
|
|
229
|
+
order.push(key);
|
|
230
|
+
}
|
|
231
|
+
arr.push(c);
|
|
232
|
+
}
|
|
233
|
+
const autoSize = autoGroupSize(order.length);
|
|
234
|
+
const lazy = options?.lazy ?? Math.ceil(order.length / autoSize) > 128;
|
|
235
|
+
if (lazy) {
|
|
236
|
+
const groupSize = typeof lazy === "number" ? lazy : autoSize;
|
|
237
|
+
const groupCount = Math.ceil(order.length / groupSize);
|
|
238
|
+
const groupOf = nullObject();
|
|
239
|
+
const groupOfRoute = /* @__PURE__ */ new Map();
|
|
240
|
+
for (let i = 0; i < order.length; i++) {
|
|
241
|
+
const key = order[i];
|
|
242
|
+
const g = Math.floor(i / groupSize);
|
|
243
|
+
groupOfRoute.set(key, g);
|
|
244
|
+
const sep = key.indexOf("\0");
|
|
245
|
+
(groupOf[key.slice(0, sep)] ??= nullObject())[key.slice(sep + 1)] = g;
|
|
246
|
+
}
|
|
247
|
+
const entries = /* @__PURE__ */ new Map();
|
|
248
|
+
const routeSlots = /* @__PURE__ */ new Map();
|
|
249
|
+
for (const [key, cs] of byRoute) {
|
|
250
|
+
const g = groupOfRoute.get(key);
|
|
251
|
+
const slots = [];
|
|
252
|
+
for (const c of cs) {
|
|
253
|
+
const parts = entryParts(c, enc);
|
|
254
|
+
if (!parts.length) continue;
|
|
255
|
+
const entrySrc = normalizeCheckIdentifiers(`{ ${parts.join(", ")} }`);
|
|
256
|
+
let e = entries.get(entrySrc);
|
|
257
|
+
if (!e) {
|
|
258
|
+
e = {
|
|
259
|
+
ref: `_c${entries.size}`,
|
|
260
|
+
groups: /* @__PURE__ */ new Set()
|
|
261
|
+
};
|
|
262
|
+
entries.set(entrySrc, e);
|
|
263
|
+
}
|
|
264
|
+
e.groups.add(g);
|
|
265
|
+
slots.push([c.slot, entrySrc]);
|
|
266
|
+
}
|
|
267
|
+
routeSlots.set(key, slots);
|
|
268
|
+
}
|
|
269
|
+
for (const [src, e] of entries) if (e.groups.size > 1) validatorDecls += `const ${e.ref} = ${src}\n`;
|
|
270
|
+
let slotCounter = 0;
|
|
271
|
+
const groupRouteKeys = [];
|
|
272
|
+
const keySlotSrc = /* @__PURE__ */ new Map();
|
|
273
|
+
const slotStat = /* @__PURE__ */ new Map();
|
|
274
|
+
for (let g = 0; g < groupCount; g++) {
|
|
275
|
+
const keys = [];
|
|
276
|
+
const end = Math.min((g + 1) * groupSize, order.length);
|
|
277
|
+
for (let i = g * groupSize; i < end; i++) {
|
|
278
|
+
const key = order[i];
|
|
279
|
+
const slots = routeSlots.get(key);
|
|
280
|
+
if (!slots.length) continue;
|
|
281
|
+
keys.push(key);
|
|
282
|
+
let safe = true;
|
|
283
|
+
const slotSrc = "{" + slots.map(([slot, entrySrc]) => {
|
|
284
|
+
const e = entries.get(entrySrc);
|
|
285
|
+
if (e.groups.size === 1) safe = false;
|
|
286
|
+
return `${JSON.stringify(slot)}:${e.ref}`;
|
|
287
|
+
}).join(",") + "}";
|
|
288
|
+
keySlotSrc.set(key, slotSrc);
|
|
289
|
+
let stat = slotStat.get(slotSrc);
|
|
290
|
+
if (!stat) {
|
|
291
|
+
stat = {
|
|
292
|
+
groups: /* @__PURE__ */ new Set(),
|
|
293
|
+
safe
|
|
294
|
+
};
|
|
295
|
+
slotStat.set(slotSrc, stat);
|
|
296
|
+
}
|
|
297
|
+
stat.groups.add(g);
|
|
298
|
+
if (!safe) stat.safe = false;
|
|
299
|
+
}
|
|
300
|
+
groupRouteKeys.push(keys);
|
|
301
|
+
}
|
|
302
|
+
const hoistedSlotRef = /* @__PURE__ */ new Map();
|
|
303
|
+
for (const [src, stat] of slotStat) if (stat.groups.size > 1 && stat.safe) {
|
|
304
|
+
const ref = `_s${slotCounter++}`;
|
|
305
|
+
hoistedSlotRef.set(src, ref);
|
|
306
|
+
validatorDecls += `const ${ref} = ${src}\n`;
|
|
307
|
+
}
|
|
308
|
+
const thunks = [];
|
|
309
|
+
for (let g = 0; g < groupCount; g++) {
|
|
310
|
+
let localDecls = "";
|
|
311
|
+
const emitted = /* @__PURE__ */ new Set();
|
|
312
|
+
const localSlotRef = /* @__PURE__ */ new Map();
|
|
313
|
+
const byMethod = /* @__PURE__ */ new Map();
|
|
314
|
+
for (const key of groupRouteKeys[g]) {
|
|
315
|
+
const sep = key.indexOf("\0");
|
|
316
|
+
const method = key.slice(0, sep);
|
|
317
|
+
const path = key.slice(sep + 1);
|
|
318
|
+
for (const [, entrySrc] of routeSlots.get(key)) {
|
|
319
|
+
const e = entries.get(entrySrc);
|
|
320
|
+
if (e.groups.size === 1 && !emitted.has(entrySrc)) {
|
|
321
|
+
emitted.add(entrySrc);
|
|
322
|
+
localDecls += `const ${e.ref} = ${entrySrc}\n`;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
const slotSrc = keySlotSrc.get(key);
|
|
326
|
+
let ref = hoistedSlotRef.get(slotSrc);
|
|
327
|
+
if (ref === void 0) {
|
|
328
|
+
ref = localSlotRef.get(slotSrc);
|
|
329
|
+
if (ref === void 0) {
|
|
330
|
+
ref = `_s${slotCounter++}`;
|
|
331
|
+
localSlotRef.set(slotSrc, ref);
|
|
332
|
+
localDecls += `const ${ref} = ${slotSrc}\n`;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
let paths = byMethod.get(method);
|
|
336
|
+
if (!paths) byMethod.set(method, paths = []);
|
|
337
|
+
paths.push(`${JSON.stringify(path)}:${ref}`);
|
|
338
|
+
}
|
|
339
|
+
const sliceStr = "{" + [...byMethod.entries()].map(([method, paths]) => `${JSON.stringify(method)}:{${paths.join(",")}}`).join(",") + "}";
|
|
340
|
+
thunks.push(`() => {\n${localDecls}return ${sliceStr}\n}`);
|
|
341
|
+
}
|
|
342
|
+
validatorDecls += `const _groups = [${thunks.join(", ")}]\n`;
|
|
343
|
+
validatorDecls += `const _groupOf = ${JSON.stringify(groupOf)}\n`;
|
|
344
|
+
validatorExport = options?.register ? "" : "export const groups = _groups\nexport const groupOf = _groupOf\n";
|
|
345
|
+
} else {
|
|
346
|
+
const factoryRef = /* @__PURE__ */ new Map();
|
|
347
|
+
const tree = nullObject();
|
|
348
|
+
for (const c of captured) {
|
|
349
|
+
const parts = entryParts(c, enc);
|
|
350
|
+
if (!parts.length) continue;
|
|
351
|
+
const entrySrc = normalizeCheckIdentifiers(`{ ${parts.join(", ")} }`);
|
|
352
|
+
let ref = factoryRef.get(entrySrc);
|
|
353
|
+
if (ref === void 0) {
|
|
354
|
+
ref = `_c${factoryRef.size}`;
|
|
355
|
+
factoryRef.set(entrySrc, ref);
|
|
356
|
+
validatorDecls += `const ${ref} = ${entrySrc}\n`;
|
|
357
|
+
}
|
|
358
|
+
const byPath = tree[c.method] ??= nullObject();
|
|
359
|
+
(byPath[c.path] ??= nullObject())[c.slot] = ref;
|
|
360
|
+
}
|
|
361
|
+
const treeStr = treeToSource(tree, /* @__PURE__ */ new Map(), (d) => {
|
|
362
|
+
validatorDecls += d;
|
|
363
|
+
});
|
|
364
|
+
validatorExport = options?.register ? `const validators = ${treeStr}\n` : `export const validators = ${treeStr}\n`;
|
|
365
|
+
}
|
|
366
|
+
const aliasRef = /* @__PURE__ */ new Map();
|
|
367
|
+
const handlerRef = /* @__PURE__ */ new Map();
|
|
368
|
+
let handlerDecls = "";
|
|
369
|
+
const handlerTree = nullObject();
|
|
370
|
+
for (const h of handlers) {
|
|
371
|
+
const src = Source.handlerFactory(h.alias, h.code);
|
|
372
|
+
let wref = handlerRef.get(src);
|
|
373
|
+
if (wref === void 0) {
|
|
374
|
+
const n = handlerRef.size;
|
|
375
|
+
let aref = aliasRef.get(h.alias);
|
|
376
|
+
if (aref === void 0) {
|
|
377
|
+
aref = `_a${aliasRef.size}`;
|
|
378
|
+
aliasRef.set(h.alias, aref);
|
|
379
|
+
handlerDecls += `const ${aref} = ${JSON.stringify(h.alias ? h.alias.split(",") : [])}\n`;
|
|
380
|
+
}
|
|
381
|
+
wref = `_w${n}`;
|
|
382
|
+
handlerRef.set(src, wref);
|
|
383
|
+
handlerDecls += `const _h${n} = ${src}\nconst ${wref} = { a: ${aref}, f: _h${n} }\n`;
|
|
384
|
+
}
|
|
385
|
+
(handlerTree[h.method] ??= {})[h.path] = wref;
|
|
386
|
+
}
|
|
387
|
+
let handlerExport = options?.register ? "const handlers = {\n" : "export const handlers = {\n";
|
|
388
|
+
for (const method in handlerTree) {
|
|
389
|
+
handlerExport += `\t${JSON.stringify(method)}: {\n`;
|
|
390
|
+
for (const path in handlerTree[method]) handlerExport += `\t\t${JSON.stringify(path)}: ${handlerTree[method][path]},\n`;
|
|
391
|
+
handlerExport += " },\n";
|
|
392
|
+
}
|
|
393
|
+
handlerExport += "}\n";
|
|
394
|
+
const fingerprintExport = options?.register ? `export const fingerprint = ${JSON.stringify(fingerprint)}\n` : "";
|
|
395
|
+
let body = "// Generated by Elysia build plugin. Do not edit.\n";
|
|
396
|
+
if (options?.register) body += `import { Compiled } from ${JSON.stringify(options.registerFrom ?? "elysia")}\n`;
|
|
397
|
+
if (options?.register && enc.hasCoercePlan) body += `import { buildCoercedFromPlan } from ${JSON.stringify("elysia/coerce-plan")}\n`;
|
|
398
|
+
if (options?.register && captured.length) body += `import { Reconstruct } from ${JSON.stringify(options.reconstructFrom ?? "elysia/reconstruct")}\n`;
|
|
399
|
+
const generated = enc.branchDecls + enc.unionDecls + validatorDecls + handlerDecls;
|
|
400
|
+
const needs = (symbol) => new RegExp(`\\b${symbol}\\b`).test(generated);
|
|
401
|
+
if (needs("CheckContext")) body += "import { CheckContext } from 'typebox/schema'\n";
|
|
402
|
+
if (needs("Guard")) body += "import { Guard } from 'typebox/guard'\n";
|
|
403
|
+
if (needs("Format")) body += "import { Format } from 'typebox/format'\n";
|
|
404
|
+
if (needs("Hashing")) body += "import { Hashing } from 'typebox/system'\n";
|
|
405
|
+
if (options?.register) {
|
|
406
|
+
body += "\n";
|
|
407
|
+
if (captured.length) body += "Compiled.reconstruct = Reconstruct\n";
|
|
408
|
+
body += fingerprintExport + "Compiled.register((() => {\n" + enc.branchDecls + (enc.branchDecls && "\n") + enc.unionDecls + (enc.unionDecls && "\n") + validatorDecls + handlerDecls + "\n" + validatorExport + "\n" + handlerExport + "\nreturn { bf: 1, fingerprint, " + (lazy ? "lazyGroups: _groups, lazyGroupOf: _groupOf, " : "validators, ") + `handlers${enc.hasCoercePlan ? ", planRebuilder: buildCoercedFromPlan" : ""} }\n})())
|
|
409
|
+
`;
|
|
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
|
+
return body;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
//#endregion
|
|
418
|
+
export { autoGroupSize, captureArtifacts, compileToSource, replayStubbability };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_compile_lexer = require('../../compile/lexer.js');
|
|
3
|
+
|
|
4
|
+
//#region src/plugin/aot/treeshake.ts
|
|
5
|
+
const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
6
|
+
function nonCodeSpans(code) {
|
|
7
|
+
const spans = [];
|
|
8
|
+
const length = code.length;
|
|
9
|
+
let i = 0;
|
|
10
|
+
while (i < length) {
|
|
11
|
+
const c = code.charCodeAt(i);
|
|
12
|
+
if (c === 47 && code.charCodeAt(i + 1) === 47) {
|
|
13
|
+
const start = i;
|
|
14
|
+
const newline = code.indexOf("\n", i + 2);
|
|
15
|
+
i = newline === -1 ? length : newline;
|
|
16
|
+
spans.push([start, i]);
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
if (c === 47 && code.charCodeAt(i + 1) === 42) {
|
|
20
|
+
const start = i;
|
|
21
|
+
const end = code.indexOf("*/", i + 2);
|
|
22
|
+
i = end === -1 ? length : end + 2;
|
|
23
|
+
spans.push([start, i]);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (c === 34 || c === 39) {
|
|
27
|
+
const start = i++;
|
|
28
|
+
while (i < length) {
|
|
29
|
+
const d = code.charCodeAt(i);
|
|
30
|
+
if (d === 92) i += 2;
|
|
31
|
+
else if (d === c || d === 10) break;
|
|
32
|
+
else i++;
|
|
33
|
+
}
|
|
34
|
+
i++;
|
|
35
|
+
spans.push([start, i]);
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (c === 96) {
|
|
39
|
+
const start = i;
|
|
40
|
+
i = require_compile_lexer.skipString(code, i);
|
|
41
|
+
spans.push([start, i]);
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
i++;
|
|
45
|
+
}
|
|
46
|
+
return spans;
|
|
47
|
+
}
|
|
48
|
+
function rewriteTypeImport(code) {
|
|
49
|
+
const from = "elysia";
|
|
50
|
+
const typeFrom = "elysia/type";
|
|
51
|
+
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*(['"])${escape(from)}\\4(\\s*(?:with|assert)\\s*\\{[^}]*\\})?`, "g");
|
|
53
|
+
const spans = nonCodeSpans(code);
|
|
54
|
+
const edits = [];
|
|
55
|
+
let m;
|
|
56
|
+
while (m = importRe.exec(code)) {
|
|
57
|
+
const [full, lead, indent, clause, , attributes] = m;
|
|
58
|
+
const keyword = m.index + lead.length + indent.length;
|
|
59
|
+
if (spans.some(([start, end]) => keyword >= start && keyword < end)) continue;
|
|
60
|
+
const braceStart = clause.indexOf("{");
|
|
61
|
+
if (braceStart === -1) continue;
|
|
62
|
+
const braceEnd = clause.indexOf("}", braceStart);
|
|
63
|
+
if (braceEnd === -1) continue;
|
|
64
|
+
const before = clause.slice(0, braceStart).trim();
|
|
65
|
+
const memberSource = clause.slice(braceStart + 1, braceEnd);
|
|
66
|
+
if (/['"`]|\/\/|\/\*/.test(memberSource)) continue;
|
|
67
|
+
const members = memberSource.split(",").map((x) => x.trim()).filter(Boolean);
|
|
68
|
+
let alias;
|
|
69
|
+
const kept = [];
|
|
70
|
+
for (const member of members) {
|
|
71
|
+
const t = member.match(/^t(?:\s+as\s+([A-Za-z_$][\w$]*))?$/);
|
|
72
|
+
if (t && !alias) alias = t[1] ?? "t";
|
|
73
|
+
else kept.push(member);
|
|
74
|
+
}
|
|
75
|
+
if (!alias) continue;
|
|
76
|
+
const head = before.replace(/,\s*$/, "").trim();
|
|
77
|
+
const keptClause = head && kept.length ? `${head}, { ${kept.join(", ")} }` : head ? head : kept.length ? `{ ${kept.join(", ")} }` : "";
|
|
78
|
+
const attr = attributes ?? "";
|
|
79
|
+
const lines = [];
|
|
80
|
+
if (keptClause) lines.push(`import ${keptClause} from '${from}'${attr}`);
|
|
81
|
+
lines.push(`import * as ${alias} from '${typeFrom}'${attr}`);
|
|
82
|
+
edits.push({
|
|
83
|
+
start: m.index,
|
|
84
|
+
end: m.index + full.length,
|
|
85
|
+
text: lead + indent + lines.join("\n" + indent)
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
if (!edits.length) return code;
|
|
89
|
+
let out = code;
|
|
90
|
+
for (const e of edits.sort((a, b) => b.start - a.start)) out = out.slice(0, e.start) + e.text + out.slice(e.end);
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
//#endregion
|
|
95
|
+
exports.rewriteTypeImport = rewriteTypeImport;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { skipString } from "../../compile/lexer.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/plugin/aot/treeshake.ts
|
|
4
|
+
const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
5
|
+
function nonCodeSpans(code) {
|
|
6
|
+
const spans = [];
|
|
7
|
+
const length = code.length;
|
|
8
|
+
let i = 0;
|
|
9
|
+
while (i < length) {
|
|
10
|
+
const c = code.charCodeAt(i);
|
|
11
|
+
if (c === 47 && code.charCodeAt(i + 1) === 47) {
|
|
12
|
+
const start = i;
|
|
13
|
+
const newline = code.indexOf("\n", i + 2);
|
|
14
|
+
i = newline === -1 ? length : newline;
|
|
15
|
+
spans.push([start, i]);
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (c === 47 && code.charCodeAt(i + 1) === 42) {
|
|
19
|
+
const start = i;
|
|
20
|
+
const end = code.indexOf("*/", i + 2);
|
|
21
|
+
i = end === -1 ? length : end + 2;
|
|
22
|
+
spans.push([start, i]);
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (c === 34 || c === 39) {
|
|
26
|
+
const start = i++;
|
|
27
|
+
while (i < length) {
|
|
28
|
+
const d = code.charCodeAt(i);
|
|
29
|
+
if (d === 92) i += 2;
|
|
30
|
+
else if (d === c || d === 10) break;
|
|
31
|
+
else i++;
|
|
32
|
+
}
|
|
33
|
+
i++;
|
|
34
|
+
spans.push([start, i]);
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (c === 96) {
|
|
38
|
+
const start = i;
|
|
39
|
+
i = skipString(code, i);
|
|
40
|
+
spans.push([start, i]);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
i++;
|
|
44
|
+
}
|
|
45
|
+
return spans;
|
|
46
|
+
}
|
|
47
|
+
function rewriteTypeImport(code) {
|
|
48
|
+
const from = "elysia";
|
|
49
|
+
const typeFrom = "elysia/type";
|
|
50
|
+
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*(['"])${escape(from)}\\4(\\s*(?:with|assert)\\s*\\{[^}]*\\})?`, "g");
|
|
52
|
+
const spans = nonCodeSpans(code);
|
|
53
|
+
const edits = [];
|
|
54
|
+
let m;
|
|
55
|
+
while (m = importRe.exec(code)) {
|
|
56
|
+
const [full, lead, indent, clause, , attributes] = m;
|
|
57
|
+
const keyword = m.index + lead.length + indent.length;
|
|
58
|
+
if (spans.some(([start, end]) => keyword >= start && keyword < end)) continue;
|
|
59
|
+
const braceStart = clause.indexOf("{");
|
|
60
|
+
if (braceStart === -1) continue;
|
|
61
|
+
const braceEnd = clause.indexOf("}", braceStart);
|
|
62
|
+
if (braceEnd === -1) continue;
|
|
63
|
+
const before = clause.slice(0, braceStart).trim();
|
|
64
|
+
const memberSource = clause.slice(braceStart + 1, braceEnd);
|
|
65
|
+
if (/['"`]|\/\/|\/\*/.test(memberSource)) continue;
|
|
66
|
+
const members = memberSource.split(",").map((x) => x.trim()).filter(Boolean);
|
|
67
|
+
let alias;
|
|
68
|
+
const kept = [];
|
|
69
|
+
for (const member of members) {
|
|
70
|
+
const t = member.match(/^t(?:\s+as\s+([A-Za-z_$][\w$]*))?$/);
|
|
71
|
+
if (t && !alias) alias = t[1] ?? "t";
|
|
72
|
+
else kept.push(member);
|
|
73
|
+
}
|
|
74
|
+
if (!alias) continue;
|
|
75
|
+
const head = before.replace(/,\s*$/, "").trim();
|
|
76
|
+
const keptClause = head && kept.length ? `${head}, { ${kept.join(", ")} }` : head ? head : kept.length ? `{ ${kept.join(", ")} }` : "";
|
|
77
|
+
const attr = attributes ?? "";
|
|
78
|
+
const lines = [];
|
|
79
|
+
if (keptClause) lines.push(`import ${keptClause} from '${from}'${attr}`);
|
|
80
|
+
lines.push(`import * as ${alias} from '${typeFrom}'${attr}`);
|
|
81
|
+
edits.push({
|
|
82
|
+
start: m.index,
|
|
83
|
+
end: m.index + full.length,
|
|
84
|
+
text: lead + indent + lines.join("\n" + indent)
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (!edits.length) return code;
|
|
88
|
+
let out = code;
|
|
89
|
+
for (const e of edits.sort((a, b) => b.start - a.start)) out = out.slice(0, e.start) + e.text + out.slice(e.end);
|
|
90
|
+
return out;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
//#endregion
|
|
94
|
+
export { rewriteTypeImport };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ElysiaAotOptions } from "./core.js";
|
|
2
|
+
|
|
3
|
+
//#region src/plugin/aot/unplugin.d.ts
|
|
4
|
+
interface ElysiaAotUnpluginOptions extends ElysiaAotOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Build entrypoint. Resolved by the nearest `package.json`. Must be the
|
|
7
|
+
* module that exports the Elysia app the plugin compiles.
|
|
8
|
+
*/
|
|
9
|
+
entry: string;
|
|
10
|
+
}
|
|
11
|
+
interface ElysiaAotUnpluginFactoryResult {
|
|
12
|
+
name: string;
|
|
13
|
+
enforce?: 'pre' | 'post';
|
|
14
|
+
buildStart?: () => Promise<void>;
|
|
15
|
+
buildEnd?: () => void;
|
|
16
|
+
resolveId?: (id: string) => string | undefined;
|
|
17
|
+
load?: (id: string) => string | undefined;
|
|
18
|
+
transformInclude?: (id: string) => boolean;
|
|
19
|
+
transform?: (code: string, id: string) => string | undefined | Promise<string | undefined>;
|
|
20
|
+
/** Vite-specific override (`apply: 'build'` keeps dev on runtime JIT). */
|
|
21
|
+
vite?: {
|
|
22
|
+
apply?: 'build' | 'serve';
|
|
23
|
+
};
|
|
24
|
+
/** rspack compiler hook: forces the manifest module side-effectful. */
|
|
25
|
+
rspack?: (compiler: unknown) => void;
|
|
26
|
+
/** webpack compiler hook: forces the manifest module side-effectful. */
|
|
27
|
+
webpack?: (compiler: unknown) => void;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Elysia AOT build plugin factory (universal)
|
|
31
|
+
*
|
|
32
|
+
* Run Elysia JIT compilation in build time instead of runtime
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { createUnplugin } from 'unplugin'
|
|
36
|
+
* import { aotFactory } from 'elysia/plugin/aot/unplugin'
|
|
37
|
+
*
|
|
38
|
+
* const aot = createUnplugin(aotFactory)
|
|
39
|
+
*
|
|
40
|
+
* // webpack.config.js → aot.webpack({ entry: 'src/index.ts' })
|
|
41
|
+
* // rollup.config.js → aot.rollup({ entry: 'src/index.ts' })
|
|
42
|
+
* // farm.config.ts → aot.farm({ entry: 'src/index.ts' })
|
|
43
|
+
* ```
|
|
44
|
+
*
|
|
45
|
+
* For rspack, prefer the native `elysia/plugin/aot/rspack` plugin
|
|
46
|
+
* (no `unplugin` needed); for Vite prefer `elysia/plugin/aot/vite`
|
|
47
|
+
*/
|
|
48
|
+
declare const aotFactory: (options: ElysiaAotUnpluginOptions) => ElysiaAotUnpluginFactoryResult;
|
|
49
|
+
//#endregion
|
|
50
|
+
export { ElysiaAotUnpluginFactoryResult, ElysiaAotUnpluginOptions, aotFactory, aotFactory as default };
|