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
package/dist/index.js
CHANGED
|
@@ -1,1950 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
ValidationError: () => import_error2.ValidationError,
|
|
44
|
-
checksum: () => import_utils4.checksum,
|
|
45
|
-
cloneInference: () => import_utils4.cloneInference,
|
|
46
|
-
deduplicateChecksum: () => import_utils4.deduplicateChecksum,
|
|
47
|
-
default: () => Elysia,
|
|
48
|
-
env: () => import_env2.env,
|
|
49
|
-
file: () => import_file.file,
|
|
50
|
-
fileType: () => import_utils3.fileType,
|
|
51
|
-
form: () => import_utils4.form,
|
|
52
|
-
getResponseSchemaValidator: () => import_schema2.getResponseSchemaValidator,
|
|
53
|
-
getSchemaValidator: () => import_schema2.getSchemaValidator,
|
|
54
|
-
mapValueError: () => import_error2.mapValueError,
|
|
55
|
-
mergeHook: () => import_utils4.mergeHook,
|
|
56
|
-
mergeObjectArray: () => import_utils4.mergeObjectArray,
|
|
57
|
-
redirect: () => import_utils4.redirect,
|
|
58
|
-
replaceSchemaType: () => import_replace_schema2.replaceSchemaTypeFromManyOptions,
|
|
59
|
-
replaceUrlPath: () => import_utils4.replaceUrlPath,
|
|
60
|
-
serializeCookie: () => import_cookies.serializeCookie,
|
|
61
|
-
sse: () => import_utils4.sse,
|
|
62
|
-
status: () => import_error2.status,
|
|
63
|
-
t: () => import_type_system2.t,
|
|
64
|
-
validationDetail: () => import_utils3.validationDetail
|
|
65
|
-
});
|
|
66
|
-
module.exports = __toCommonJS(index_exports);
|
|
67
|
-
var import_memoirist = require("memoirist"), import_typebox = require("@sinclair/typebox"), import_fast_decode_uri_component = __toESM(require("fast-decode-uri-component")), import_type_system = require('./type-system/index.js'), import_sucrose = require('./sucrose.js'), import_bun = require('./adapter/bun/index.js'), import_web_standard = require('./adapter/web-standard/index.js'), import_env = require('./universal/env.js'), import_utils = require('./utils.js'), import_schema = require('./schema.js'), import_compose = require('./compose.js'), import_trace = require('./trace.js'), import_utils2 = require('./utils.js'), import_dynamic_handle = require('./dynamic-handle.js'), import_error = require('./error.js'), import_replace_schema = require('./replace-schema.js'), import_type_system2 = require('./type-system/index.js'), import_utils3 = require('./type-system/utils.js'), import_cookies = require('./cookies.js'), import_trace2 = require('./trace.js'), import_schema2 = require('./schema.js'), import_replace_schema2 = require('./replace-schema.js'), import_utils4 = require('./utils.js'), import_error2 = require('./error.js'), import_env2 = require('./universal/env.js'), import_file = require('./universal/file.js'), import_system = require("@sinclair/typebox/system"), _a;
|
|
68
|
-
_a = Symbol.dispose;
|
|
69
|
-
const _Elysia = class _Elysia {
|
|
70
|
-
constructor(config = {}) {
|
|
71
|
-
this.server = null;
|
|
72
|
-
this.dependencies = {};
|
|
73
|
-
this["~Prefix"] = "";
|
|
74
|
-
this["~Singleton"] = null;
|
|
75
|
-
this["~Definitions"] = null;
|
|
76
|
-
this["~Metadata"] = null;
|
|
77
|
-
this["~Ephemeral"] = null;
|
|
78
|
-
this["~Volatile"] = null;
|
|
79
|
-
this["~Routes"] = null;
|
|
80
|
-
this.singleton = {
|
|
81
|
-
decorator: {},
|
|
82
|
-
store: {},
|
|
83
|
-
derive: {},
|
|
84
|
-
resolve: {}
|
|
85
|
-
};
|
|
86
|
-
this.definitions = {
|
|
87
|
-
typebox: import_type_system.t.Module({}),
|
|
88
|
-
type: {},
|
|
89
|
-
error: {}
|
|
90
|
-
};
|
|
91
|
-
this.extender = {
|
|
92
|
-
macro: {},
|
|
93
|
-
higherOrderFunctions: []
|
|
94
|
-
};
|
|
95
|
-
this.validator = {
|
|
96
|
-
global: null,
|
|
97
|
-
scoped: null,
|
|
98
|
-
local: null,
|
|
99
|
-
getCandidate() {
|
|
100
|
-
return !this.global && !this.scoped && !this.local ? {
|
|
101
|
-
body: void 0,
|
|
102
|
-
headers: void 0,
|
|
103
|
-
params: void 0,
|
|
104
|
-
query: void 0,
|
|
105
|
-
cookie: void 0,
|
|
106
|
-
response: void 0
|
|
107
|
-
} : (0, import_utils.mergeSchemaValidator)(
|
|
108
|
-
(0, import_utils.mergeSchemaValidator)(this.global, this.scoped),
|
|
109
|
-
this.local
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
this.standaloneValidator = {
|
|
114
|
-
global: null,
|
|
115
|
-
scoped: null,
|
|
116
|
-
local: null
|
|
117
|
-
};
|
|
118
|
-
this.event = {};
|
|
119
|
-
this.router = {
|
|
120
|
-
"~http": void 0,
|
|
121
|
-
get http() {
|
|
122
|
-
return this["~http"] || (this["~http"] = new import_memoirist.Memoirist({
|
|
123
|
-
lazy: !0,
|
|
124
|
-
onParam: import_fast_decode_uri_component.default
|
|
125
|
-
})), this["~http"];
|
|
126
|
-
},
|
|
127
|
-
"~dynamic": void 0,
|
|
128
|
-
// Use in non-AOT mode
|
|
129
|
-
get dynamic() {
|
|
130
|
-
return this["~dynamic"] || (this["~dynamic"] = new import_memoirist.Memoirist({
|
|
131
|
-
onParam: import_fast_decode_uri_component.default
|
|
132
|
-
})), this["~dynamic"];
|
|
133
|
-
},
|
|
134
|
-
// Static Router
|
|
135
|
-
static: {},
|
|
136
|
-
// Native Static Response
|
|
137
|
-
response: {},
|
|
138
|
-
history: []
|
|
139
|
-
};
|
|
140
|
-
this.routeTree = {};
|
|
141
|
-
this.inference = {
|
|
142
|
-
body: !1,
|
|
143
|
-
cookie: !1,
|
|
144
|
-
headers: !1,
|
|
145
|
-
query: !1,
|
|
146
|
-
set: !1,
|
|
147
|
-
server: !1,
|
|
148
|
-
path: !1,
|
|
149
|
-
route: !1,
|
|
150
|
-
url: !1
|
|
151
|
-
};
|
|
152
|
-
this["~parser"] = {};
|
|
153
|
-
this.handle = async (request) => this.fetch(request);
|
|
154
|
-
this.handleError = async (context, error) => (this.handleError = this.config.aot ? (0, import_compose.composeErrorHandler)(this) : (0, import_dynamic_handle.createDynamicErrorHandler)(this))(context, error);
|
|
155
|
-
/**
|
|
156
|
-
* ### listen
|
|
157
|
-
* Assign current instance to port and start serving
|
|
158
|
-
*
|
|
159
|
-
* ---
|
|
160
|
-
* @example
|
|
161
|
-
* ```typescript
|
|
162
|
-
* new Elysia()
|
|
163
|
-
* .get("/", () => 'hi')
|
|
164
|
-
* .listen(3000)
|
|
165
|
-
* ```
|
|
166
|
-
*/
|
|
167
|
-
this.listen = (options, callback) => (this["~adapter"].listen(this)(options, callback), this);
|
|
168
|
-
/**
|
|
169
|
-
* ### stop
|
|
170
|
-
* Stop server from serving
|
|
171
|
-
*
|
|
172
|
-
* ---
|
|
173
|
-
* @example
|
|
174
|
-
* ```typescript
|
|
175
|
-
* const app = new Elysia()
|
|
176
|
-
* .get("/", () => 'hi')
|
|
177
|
-
* .listen(3000)
|
|
178
|
-
*
|
|
179
|
-
* // Sometime later
|
|
180
|
-
* app.stop()
|
|
181
|
-
* ```
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* ```typescript
|
|
185
|
-
* const app = new Elysia()
|
|
186
|
-
* .get("/", () => 'hi')
|
|
187
|
-
* .listen(3000)
|
|
188
|
-
*
|
|
189
|
-
* app.stop(true) // Abruptly any requests inflight
|
|
190
|
-
* ```
|
|
191
|
-
*/
|
|
192
|
-
this.stop = async (closeActiveConnections) => (await this["~adapter"].stop?.(this, closeActiveConnections), this);
|
|
193
|
-
this[_a] = () => {
|
|
194
|
-
this.server && this.stop();
|
|
195
|
-
};
|
|
196
|
-
config.tags && (config.detail ? config.detail.tags = config.tags : config.detail = {
|
|
197
|
-
tags: config.tags
|
|
198
|
-
}), this.config = {
|
|
199
|
-
aot: import_env.env.ELYSIA_AOT !== "false",
|
|
200
|
-
nativeStaticResponse: !0,
|
|
201
|
-
encodeSchema: !0,
|
|
202
|
-
normalize: !0,
|
|
203
|
-
...config,
|
|
204
|
-
prefix: config.prefix ? config.prefix.charCodeAt(0) === 47 ? config.prefix : `/${config.prefix}` : void 0,
|
|
205
|
-
cookie: {
|
|
206
|
-
path: "/",
|
|
207
|
-
...config?.cookie
|
|
208
|
-
},
|
|
209
|
-
experimental: config?.experimental ?? {},
|
|
210
|
-
seed: config?.seed === void 0 ? "" : config?.seed
|
|
211
|
-
}, this["~adapter"] = config.adapter ?? (typeof Bun < "u" ? import_bun.BunAdapter : import_web_standard.WebStandardAdapter), config?.analytic && (config?.name || config?.seed !== void 0) && (this.telemetry = {
|
|
212
|
-
stack: new Error().stack
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
get store() {
|
|
216
|
-
return this.singleton.store;
|
|
217
|
-
}
|
|
218
|
-
get decorator() {
|
|
219
|
-
return this.singleton.decorator;
|
|
220
|
-
}
|
|
221
|
-
get routes() {
|
|
222
|
-
return this.router.history;
|
|
223
|
-
}
|
|
224
|
-
getGlobalRoutes() {
|
|
225
|
-
return this.router.history;
|
|
226
|
-
}
|
|
227
|
-
getGlobalDefinitions() {
|
|
228
|
-
return this.definitions;
|
|
229
|
-
}
|
|
230
|
-
getServer() {
|
|
231
|
-
return this.server;
|
|
232
|
-
}
|
|
233
|
-
getParent() {
|
|
234
|
-
return null;
|
|
235
|
-
}
|
|
236
|
-
get promisedModules() {
|
|
237
|
-
return this._promisedModules || (this._promisedModules = new import_utils.PromiseGroup(console.error, () => {
|
|
238
|
-
})), this._promisedModules;
|
|
239
|
-
}
|
|
240
|
-
env(model, _env = import_env.env) {
|
|
241
|
-
if ((0, import_schema.getSchemaValidator)(model, {
|
|
242
|
-
modules: this.definitions.typebox,
|
|
243
|
-
dynamic: !0,
|
|
244
|
-
additionalProperties: !0,
|
|
245
|
-
coerce: !0,
|
|
246
|
-
sanitize: () => this.config.sanitize
|
|
247
|
-
}).Check(_env) === !1) {
|
|
248
|
-
const error = new import_error.ValidationError("env", model, _env);
|
|
249
|
-
throw new Error(error.all.map((x) => x.summary).join(`
|
|
250
|
-
`));
|
|
251
|
-
}
|
|
252
|
-
return this;
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* @private DO_NOT_USE_OR_YOU_WILL_BE_FIRED
|
|
256
|
-
* @version 1.1.0
|
|
257
|
-
*
|
|
258
|
-
* ! Do not use unless you know exactly what you are doing
|
|
259
|
-
* ? Add Higher order function to Elysia.fetch
|
|
260
|
-
*/
|
|
261
|
-
wrap(fn) {
|
|
262
|
-
return this.extender.higherOrderFunctions.push({
|
|
263
|
-
checksum: (0, import_utils2.checksum)(
|
|
264
|
-
JSON.stringify({
|
|
265
|
-
name: this.config.name,
|
|
266
|
-
seed: this.config.seed,
|
|
267
|
-
content: fn.toString()
|
|
268
|
-
})
|
|
269
|
-
),
|
|
270
|
-
fn
|
|
271
|
-
}), this;
|
|
272
|
-
}
|
|
273
|
-
get models() {
|
|
274
|
-
const models = {};
|
|
275
|
-
for (const name of Object.keys(this.definitions.type))
|
|
276
|
-
models[name] = (0, import_schema.getSchemaValidator)(
|
|
277
|
-
this.definitions.typebox.Import(name),
|
|
278
|
-
{
|
|
279
|
-
models: this.definitions.type
|
|
280
|
-
}
|
|
281
|
-
);
|
|
282
|
-
return models.modules = this.definitions.typebox, models;
|
|
283
|
-
}
|
|
284
|
-
add(method, path, handle, localHook, options) {
|
|
285
|
-
const skipPrefix = options?.skipPrefix ?? !1, allowMeta = options?.allowMeta ?? !1;
|
|
286
|
-
localHook ??= {}, this.applyMacro(localHook);
|
|
287
|
-
let standaloneValidators = [];
|
|
288
|
-
if (localHook.standaloneValidator && (standaloneValidators = standaloneValidators.concat(
|
|
289
|
-
localHook.standaloneValidator
|
|
290
|
-
)), this.standaloneValidator.local && (standaloneValidators = standaloneValidators.concat(
|
|
291
|
-
this.standaloneValidator.local
|
|
292
|
-
)), this.standaloneValidator.scoped && (standaloneValidators = standaloneValidators.concat(
|
|
293
|
-
this.standaloneValidator.scoped
|
|
294
|
-
)), this.standaloneValidator.global && (standaloneValidators = standaloneValidators.concat(
|
|
295
|
-
this.standaloneValidator.global
|
|
296
|
-
)), path !== "" && path.charCodeAt(0) !== 47 && (path = "/" + path), this.config.prefix && !skipPrefix && (path = this.config.prefix + path), localHook?.type)
|
|
297
|
-
switch (localHook.type) {
|
|
298
|
-
case "text":
|
|
299
|
-
localHook.type = "text/plain";
|
|
300
|
-
break;
|
|
301
|
-
case "json":
|
|
302
|
-
localHook.type = "application/json";
|
|
303
|
-
break;
|
|
304
|
-
case "formdata":
|
|
305
|
-
localHook.type = "multipart/form-data";
|
|
306
|
-
break;
|
|
307
|
-
case "urlencoded":
|
|
308
|
-
localHook.type = "application/x-www-form-urlencoded";
|
|
309
|
-
break;
|
|
310
|
-
case "arrayBuffer":
|
|
311
|
-
localHook.type = "application/octet-stream";
|
|
312
|
-
break;
|
|
313
|
-
default:
|
|
314
|
-
break;
|
|
315
|
-
}
|
|
316
|
-
const instanceValidator = this.validator.getCandidate(), cloned = {
|
|
317
|
-
body: localHook?.body ?? instanceValidator?.body,
|
|
318
|
-
headers: localHook?.headers ?? instanceValidator?.headers,
|
|
319
|
-
params: localHook?.params ?? instanceValidator?.params,
|
|
320
|
-
query: localHook?.query ?? instanceValidator?.query,
|
|
321
|
-
cookie: localHook?.cookie ?? instanceValidator?.cookie,
|
|
322
|
-
response: localHook?.response ?? instanceValidator?.response
|
|
323
|
-
}, shouldPrecompile = this.config.precompile === !0 || typeof this.config.precompile == "object" && this.config.precompile.compose === !0, createValidator = () => {
|
|
324
|
-
const models = this.definitions.type, dynamic = !this.config.aot, normalize = this.config.normalize, modules = this.definitions.typebox, sanitize = () => this.config.sanitize, cookieValidator = () => {
|
|
325
|
-
if (cloned.cookie || standaloneValidators.find((x) => x.cookie))
|
|
326
|
-
return (0, import_schema.getCookieValidator)({
|
|
327
|
-
modules,
|
|
328
|
-
validator: cloned.cookie,
|
|
329
|
-
defaultConfig: this.config.cookie,
|
|
330
|
-
normalize,
|
|
331
|
-
config: cloned.cookie?.config ?? {},
|
|
332
|
-
dynamic,
|
|
333
|
-
models,
|
|
334
|
-
validators: standaloneValidators.map((x) => x.cookie),
|
|
335
|
-
sanitize
|
|
336
|
-
});
|
|
337
|
-
};
|
|
338
|
-
return shouldPrecompile ? {
|
|
339
|
-
body: (0, import_schema.getSchemaValidator)(cloned.body, {
|
|
340
|
-
modules,
|
|
341
|
-
dynamic,
|
|
342
|
-
models,
|
|
343
|
-
normalize,
|
|
344
|
-
additionalCoerce: (() => {
|
|
345
|
-
const resolved = (0, import_schema.resolveSchema)(
|
|
346
|
-
cloned.body,
|
|
347
|
-
models,
|
|
348
|
-
modules
|
|
349
|
-
);
|
|
350
|
-
return resolved && import_typebox.Kind in resolved && ((0, import_schema.hasType)("File", resolved) || (0, import_schema.hasType)("Files", resolved)) ? (0, import_replace_schema.coerceFormData)() : (0, import_replace_schema.coercePrimitiveRoot)();
|
|
351
|
-
})(),
|
|
352
|
-
validators: standaloneValidators.map((x) => x.body),
|
|
353
|
-
sanitize
|
|
354
|
-
}),
|
|
355
|
-
headers: (0, import_schema.getSchemaValidator)(cloned.headers, {
|
|
356
|
-
modules,
|
|
357
|
-
dynamic,
|
|
358
|
-
models,
|
|
359
|
-
additionalProperties: !0,
|
|
360
|
-
coerce: !0,
|
|
361
|
-
additionalCoerce: (0, import_replace_schema.stringToStructureCoercions)(),
|
|
362
|
-
validators: standaloneValidators.map(
|
|
363
|
-
(x) => x.headers
|
|
364
|
-
),
|
|
365
|
-
sanitize
|
|
366
|
-
}),
|
|
367
|
-
params: (0, import_schema.getSchemaValidator)(cloned.params, {
|
|
368
|
-
modules,
|
|
369
|
-
dynamic,
|
|
370
|
-
models,
|
|
371
|
-
coerce: !0,
|
|
372
|
-
additionalCoerce: (0, import_replace_schema.stringToStructureCoercions)(),
|
|
373
|
-
validators: standaloneValidators.map(
|
|
374
|
-
(x) => x.params
|
|
375
|
-
),
|
|
376
|
-
sanitize
|
|
377
|
-
}),
|
|
378
|
-
query: (0, import_schema.getSchemaValidator)(cloned.query, {
|
|
379
|
-
modules,
|
|
380
|
-
dynamic,
|
|
381
|
-
models,
|
|
382
|
-
normalize,
|
|
383
|
-
coerce: !0,
|
|
384
|
-
additionalCoerce: (0, import_replace_schema.queryCoercions)(),
|
|
385
|
-
validators: standaloneValidators.map(
|
|
386
|
-
(x) => x.query
|
|
387
|
-
),
|
|
388
|
-
sanitize
|
|
389
|
-
}),
|
|
390
|
-
cookie: cookieValidator(),
|
|
391
|
-
response: (0, import_schema.getResponseSchemaValidator)(cloned.response, {
|
|
392
|
-
modules,
|
|
393
|
-
dynamic,
|
|
394
|
-
models,
|
|
395
|
-
normalize,
|
|
396
|
-
validators: standaloneValidators.map(
|
|
397
|
-
(x) => x.response
|
|
398
|
-
),
|
|
399
|
-
sanitize
|
|
400
|
-
})
|
|
401
|
-
} : {
|
|
402
|
-
createBody() {
|
|
403
|
-
return this.body ? this.body : this.body = (0, import_schema.getSchemaValidator)(
|
|
404
|
-
cloned.body,
|
|
405
|
-
{
|
|
406
|
-
modules,
|
|
407
|
-
dynamic,
|
|
408
|
-
models,
|
|
409
|
-
normalize,
|
|
410
|
-
additionalCoerce: (() => {
|
|
411
|
-
const resolved = (0, import_schema.resolveSchema)(
|
|
412
|
-
cloned.body,
|
|
413
|
-
models,
|
|
414
|
-
modules
|
|
415
|
-
);
|
|
416
|
-
return resolved && import_typebox.Kind in resolved && ((0, import_schema.hasType)("File", resolved) || (0, import_schema.hasType)("Files", resolved)) ? (0, import_replace_schema.coerceFormData)() : (0, import_replace_schema.coercePrimitiveRoot)();
|
|
417
|
-
})(),
|
|
418
|
-
validators: standaloneValidators.map(
|
|
419
|
-
(x) => x.body
|
|
420
|
-
),
|
|
421
|
-
sanitize
|
|
422
|
-
}
|
|
423
|
-
);
|
|
424
|
-
},
|
|
425
|
-
createHeaders() {
|
|
426
|
-
return this.headers ? this.headers : this.headers = (0, import_schema.getSchemaValidator)(
|
|
427
|
-
cloned.headers,
|
|
428
|
-
{
|
|
429
|
-
modules,
|
|
430
|
-
dynamic,
|
|
431
|
-
models,
|
|
432
|
-
normalize,
|
|
433
|
-
additionalProperties: !normalize,
|
|
434
|
-
coerce: !0,
|
|
435
|
-
additionalCoerce: (0, import_replace_schema.stringToStructureCoercions)(),
|
|
436
|
-
validators: standaloneValidators.map(
|
|
437
|
-
(x) => x.headers
|
|
438
|
-
),
|
|
439
|
-
sanitize
|
|
440
|
-
}
|
|
441
|
-
);
|
|
442
|
-
},
|
|
443
|
-
createParams() {
|
|
444
|
-
return this.params ? this.params : this.params = (0, import_schema.getSchemaValidator)(
|
|
445
|
-
cloned.params,
|
|
446
|
-
{
|
|
447
|
-
modules,
|
|
448
|
-
dynamic,
|
|
449
|
-
models,
|
|
450
|
-
normalize,
|
|
451
|
-
coerce: !0,
|
|
452
|
-
additionalCoerce: (0, import_replace_schema.stringToStructureCoercions)(),
|
|
453
|
-
validators: standaloneValidators.map(
|
|
454
|
-
(x) => x.params
|
|
455
|
-
),
|
|
456
|
-
sanitize
|
|
457
|
-
}
|
|
458
|
-
);
|
|
459
|
-
},
|
|
460
|
-
createQuery() {
|
|
461
|
-
return this.query ? this.query : this.query = (0, import_schema.getSchemaValidator)(
|
|
462
|
-
cloned.query,
|
|
463
|
-
{
|
|
464
|
-
modules,
|
|
465
|
-
dynamic,
|
|
466
|
-
models,
|
|
467
|
-
normalize,
|
|
468
|
-
coerce: !0,
|
|
469
|
-
additionalCoerce: (0, import_replace_schema.queryCoercions)(),
|
|
470
|
-
validators: standaloneValidators.map(
|
|
471
|
-
(x) => x.query
|
|
472
|
-
),
|
|
473
|
-
sanitize
|
|
474
|
-
}
|
|
475
|
-
);
|
|
476
|
-
},
|
|
477
|
-
createCookie() {
|
|
478
|
-
return this.cookie ? this.cookie : this.cookie = cookieValidator();
|
|
479
|
-
},
|
|
480
|
-
createResponse() {
|
|
481
|
-
return this.response ? this.response : this.response = (0, import_schema.getResponseSchemaValidator)(
|
|
482
|
-
cloned.response,
|
|
483
|
-
{
|
|
484
|
-
modules,
|
|
485
|
-
dynamic,
|
|
486
|
-
models,
|
|
487
|
-
normalize,
|
|
488
|
-
validators: standaloneValidators.map(
|
|
489
|
-
(x) => x.response
|
|
490
|
-
),
|
|
491
|
-
sanitize
|
|
492
|
-
}
|
|
493
|
-
);
|
|
494
|
-
}
|
|
495
|
-
};
|
|
496
|
-
};
|
|
497
|
-
(instanceValidator.body || instanceValidator.cookie || instanceValidator.headers || instanceValidator.params || instanceValidator.query || instanceValidator.response) && (localHook = (0, import_utils2.mergeHook)(localHook, instanceValidator)), localHook.tags && (localHook.detail ? localHook.detail.tags = localHook.tags : localHook.detail = {
|
|
498
|
-
tags: localHook.tags
|
|
499
|
-
}), (0, import_utils.isNotEmpty)(this.config.detail) && (localHook.detail = (0, import_utils.mergeDeep)(
|
|
500
|
-
Object.assign({}, this.config.detail),
|
|
501
|
-
localHook.detail
|
|
502
|
-
));
|
|
503
|
-
const hooks = (0, import_utils.isNotEmpty)(this.event) ? (0, import_utils2.mergeHook)(this.event, (0, import_utils.localHookToLifeCycleStore)(localHook)) : { ...(0, import_utils.lifeCycleToArray)((0, import_utils.localHookToLifeCycleStore)(localHook)) };
|
|
504
|
-
if (standaloneValidators.length && Object.assign(hooks, {
|
|
505
|
-
standaloneValidator: standaloneValidators
|
|
506
|
-
}), this.config.aot === !1) {
|
|
507
|
-
const validator = createValidator();
|
|
508
|
-
this.router.dynamic.add(method, path, {
|
|
509
|
-
validator,
|
|
510
|
-
hooks,
|
|
511
|
-
content: localHook?.type,
|
|
512
|
-
handle,
|
|
513
|
-
route: path
|
|
514
|
-
});
|
|
515
|
-
const encoded = (0, import_utils.encodePath)(path, { dynamic: !0 });
|
|
516
|
-
if (path !== encoded && this.router.dynamic.add(method, encoded, {
|
|
517
|
-
validator,
|
|
518
|
-
hooks,
|
|
519
|
-
content: localHook?.type,
|
|
520
|
-
handle,
|
|
521
|
-
route: path
|
|
522
|
-
}), !this.config.strictPath) {
|
|
523
|
-
const loosePath = (0, import_utils.getLoosePath)(path);
|
|
524
|
-
this.router.dynamic.add(method, loosePath, {
|
|
525
|
-
validator,
|
|
526
|
-
hooks,
|
|
527
|
-
content: localHook?.type,
|
|
528
|
-
handle,
|
|
529
|
-
route: path
|
|
530
|
-
});
|
|
531
|
-
const encoded2 = (0, import_utils.encodePath)(loosePath);
|
|
532
|
-
loosePath !== encoded2 && this.router.dynamic.add(method, loosePath, {
|
|
533
|
-
validator,
|
|
534
|
-
hooks,
|
|
535
|
-
content: localHook?.type,
|
|
536
|
-
handle,
|
|
537
|
-
route: path
|
|
538
|
-
});
|
|
539
|
-
}
|
|
540
|
-
this.router.history.push({
|
|
541
|
-
method,
|
|
542
|
-
path,
|
|
543
|
-
composed: null,
|
|
544
|
-
handler: handle,
|
|
545
|
-
compile: void 0,
|
|
546
|
-
hooks
|
|
547
|
-
});
|
|
548
|
-
return;
|
|
549
|
-
}
|
|
550
|
-
const adapter = this["~adapter"].handler, nativeStaticHandler = typeof handle != "function" ? () => {
|
|
551
|
-
const context = {
|
|
552
|
-
redirect: import_utils.redirect,
|
|
553
|
-
request: this["~adapter"].isWebStandard ? new Request(`http://ely.sia${path}`, {
|
|
554
|
-
method
|
|
555
|
-
}) : void 0,
|
|
556
|
-
server: null,
|
|
557
|
-
set: {
|
|
558
|
-
headers: Object.assign({}, this.setHeaders)
|
|
559
|
-
},
|
|
560
|
-
status: import_error.status,
|
|
561
|
-
store: this.store
|
|
562
|
-
};
|
|
563
|
-
try {
|
|
564
|
-
this.event.request?.map((x) => {
|
|
565
|
-
if (typeof x.fn == "function")
|
|
566
|
-
return x.fn(context);
|
|
567
|
-
if (typeof x == "function") return x(context);
|
|
568
|
-
});
|
|
569
|
-
} catch (error) {
|
|
570
|
-
let res;
|
|
571
|
-
context.error = error, this.event.error?.some((x) => {
|
|
572
|
-
if (typeof x.fn == "function")
|
|
573
|
-
return res = x.fn(context);
|
|
574
|
-
if (typeof x == "function")
|
|
575
|
-
return res = x(context);
|
|
576
|
-
}), res !== void 0 && (handle = res);
|
|
577
|
-
}
|
|
578
|
-
const fn = adapter.createNativeStaticHandler?.(
|
|
579
|
-
handle,
|
|
580
|
-
hooks,
|
|
581
|
-
context.set
|
|
582
|
-
);
|
|
583
|
-
return fn instanceof Promise ? fn.then((fn2) => {
|
|
584
|
-
if (fn2) return fn2;
|
|
585
|
-
}) : fn?.();
|
|
586
|
-
} : void 0, useNativeStaticResponse = this.config.nativeStaticResponse === !0, addResponsePath = (path2) => {
|
|
587
|
-
!useNativeStaticResponse || !nativeStaticHandler || (import_utils.supportPerMethodInlineHandler ? this.router.response[path2] ? this.router.response[path2][method] = nativeStaticHandler() : this.router.response[path2] = {
|
|
588
|
-
[method]: nativeStaticHandler()
|
|
589
|
-
} : this.router.response[path2] = nativeStaticHandler());
|
|
590
|
-
};
|
|
591
|
-
addResponsePath(path);
|
|
592
|
-
let _compiled;
|
|
593
|
-
const compile = () => {
|
|
594
|
-
if (_compiled) return _compiled;
|
|
595
|
-
const compiled = (0, import_compose.composeHandler)({
|
|
596
|
-
app: this,
|
|
597
|
-
path,
|
|
598
|
-
method,
|
|
599
|
-
hooks,
|
|
600
|
-
validator: createValidator(),
|
|
601
|
-
handler: typeof handle != "function" && typeof adapter.createStaticHandler != "function" ? () => handle : handle,
|
|
602
|
-
allowMeta,
|
|
603
|
-
inference: this.inference
|
|
604
|
-
});
|
|
605
|
-
return this.router.history[index] && (_compiled = this.router.history[index].composed = compiled), compiled;
|
|
606
|
-
};
|
|
607
|
-
let oldIndex;
|
|
608
|
-
if (`${method}_${path}` in this.routeTree)
|
|
609
|
-
for (let i = 0; i < this.router.history.length; i++) {
|
|
610
|
-
const route2 = this.router.history[i];
|
|
611
|
-
if (route2.path === path && route2.method === method) {
|
|
612
|
-
oldIndex = i;
|
|
613
|
-
break;
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
else this.routeTree[`${method}_${path}`] = this.router.history.length;
|
|
617
|
-
const index = oldIndex ?? this.router.history.length, route = this.router.history, mainHandler = shouldPrecompile ? compile() : (ctx) => _compiled ? _compiled(ctx) : (route[index].composed = compile())(ctx);
|
|
618
|
-
oldIndex !== void 0 ? this.router.history[oldIndex] = Object.assign(
|
|
619
|
-
{
|
|
620
|
-
method,
|
|
621
|
-
path,
|
|
622
|
-
composed: mainHandler,
|
|
623
|
-
compile,
|
|
624
|
-
handler: handle,
|
|
625
|
-
hooks
|
|
626
|
-
},
|
|
627
|
-
standaloneValidators.length ? {
|
|
628
|
-
standaloneValidators
|
|
629
|
-
} : void 0,
|
|
630
|
-
localHook.webSocket ? { websocket: localHook.websocket } : void 0
|
|
631
|
-
) : this.router.history.push(
|
|
632
|
-
Object.assign(
|
|
633
|
-
{
|
|
634
|
-
method,
|
|
635
|
-
path,
|
|
636
|
-
composed: mainHandler,
|
|
637
|
-
compile,
|
|
638
|
-
handler: handle,
|
|
639
|
-
hooks
|
|
640
|
-
},
|
|
641
|
-
localHook.webSocket ? { websocket: localHook.websocket } : void 0
|
|
642
|
-
)
|
|
643
|
-
);
|
|
644
|
-
const handler = {
|
|
645
|
-
handler: shouldPrecompile ? route[index].composed : void 0,
|
|
646
|
-
compile() {
|
|
647
|
-
return this.handler = compile();
|
|
648
|
-
}
|
|
649
|
-
}, staticRouter = this.router.static, isStaticPath = path.indexOf(":") === -1 && path.indexOf("*") === -1;
|
|
650
|
-
if (method === "WS") {
|
|
651
|
-
if (isStaticPath) {
|
|
652
|
-
path in staticRouter ? staticRouter[path][method] = index : staticRouter[path] = {
|
|
653
|
-
[method]: index
|
|
654
|
-
};
|
|
655
|
-
return;
|
|
656
|
-
}
|
|
657
|
-
this.router.http.add("WS", path, handler), this.config.strictPath || this.router.http.add("WS", (0, import_utils.getLoosePath)(path), handler);
|
|
658
|
-
const encoded = (0, import_utils.encodePath)(path, { dynamic: !0 });
|
|
659
|
-
path !== encoded && this.router.http.add("WS", encoded, handler);
|
|
660
|
-
return;
|
|
661
|
-
}
|
|
662
|
-
if (isStaticPath)
|
|
663
|
-
path in staticRouter ? staticRouter[path][method] = index : staticRouter[path] = {
|
|
664
|
-
[method]: index
|
|
665
|
-
}, this.config.strictPath || addResponsePath((0, import_utils.getLoosePath)(path));
|
|
666
|
-
else {
|
|
667
|
-
if (this.router.http.add(method, path, handler), !this.config.strictPath) {
|
|
668
|
-
const loosePath = (0, import_utils.getLoosePath)(path);
|
|
669
|
-
addResponsePath(loosePath), this.router.http.add(method, loosePath, handler);
|
|
670
|
-
}
|
|
671
|
-
const encoded = (0, import_utils.encodePath)(path, { dynamic: !0 });
|
|
672
|
-
path !== encoded && (this.router.http.add(method, encoded, handler), addResponsePath(encoded));
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
headers(header) {
|
|
676
|
-
return header ? (this.setHeaders || (this.setHeaders = {}), this.setHeaders = (0, import_utils.mergeDeep)(this.setHeaders, header), this) : this;
|
|
677
|
-
}
|
|
678
|
-
/**
|
|
679
|
-
* ### start | Life cycle event
|
|
680
|
-
* Called after server is ready for serving
|
|
681
|
-
*
|
|
682
|
-
* ---
|
|
683
|
-
* @example
|
|
684
|
-
* ```typescript
|
|
685
|
-
* new Elysia()
|
|
686
|
-
* .onStart(({ server }) => {
|
|
687
|
-
* console.log("Running at ${server?.url}:${server?.port}")
|
|
688
|
-
* })
|
|
689
|
-
* .listen(3000)
|
|
690
|
-
* ```
|
|
691
|
-
*/
|
|
692
|
-
onStart(handler) {
|
|
693
|
-
return this.on("start", handler), this;
|
|
694
|
-
}
|
|
695
|
-
onRequest(handler) {
|
|
696
|
-
return this.on("request", handler), this;
|
|
697
|
-
}
|
|
698
|
-
onParse(options, handler) {
|
|
699
|
-
return handler ? this.on(
|
|
700
|
-
options,
|
|
701
|
-
"parse",
|
|
702
|
-
handler
|
|
703
|
-
) : typeof options == "string" ? this.on("parse", this["~parser"][options]) : this.on("parse", options);
|
|
704
|
-
}
|
|
705
|
-
/**
|
|
706
|
-
* ### parse | Life cycle event
|
|
707
|
-
* Callback function to handle body parsing
|
|
708
|
-
*
|
|
709
|
-
* If truthy value is returned, will be assigned to `context.body`
|
|
710
|
-
* Otherwise will skip the callback and look for the next one.
|
|
711
|
-
*
|
|
712
|
-
* Equivalent to Express's body parser
|
|
713
|
-
*
|
|
714
|
-
* ---
|
|
715
|
-
* @example
|
|
716
|
-
* ```typescript
|
|
717
|
-
* new Elysia()
|
|
718
|
-
* .onParse((request, contentType) => {
|
|
719
|
-
* if(contentType === "application/json")
|
|
720
|
-
* return request.json()
|
|
721
|
-
* })
|
|
722
|
-
* ```
|
|
723
|
-
*/
|
|
724
|
-
parser(name, parser) {
|
|
725
|
-
return this["~parser"][name] = parser, this;
|
|
726
|
-
}
|
|
727
|
-
onTransform(options, handler) {
|
|
728
|
-
return handler ? this.on(
|
|
729
|
-
options,
|
|
730
|
-
"transform",
|
|
731
|
-
handler
|
|
732
|
-
) : this.on("transform", options);
|
|
733
|
-
}
|
|
734
|
-
resolve(optionsOrResolve, resolve) {
|
|
735
|
-
resolve || (resolve = optionsOrResolve, optionsOrResolve = { as: "local" });
|
|
736
|
-
const hook = {
|
|
737
|
-
subType: "resolve",
|
|
738
|
-
fn: resolve
|
|
739
|
-
};
|
|
740
|
-
return this.onBeforeHandle(optionsOrResolve, hook);
|
|
741
|
-
}
|
|
742
|
-
mapResolve(optionsOrResolve, mapper) {
|
|
743
|
-
mapper || (mapper = optionsOrResolve, optionsOrResolve = { as: "local" });
|
|
744
|
-
const hook = {
|
|
745
|
-
subType: "mapResolve",
|
|
746
|
-
fn: mapper
|
|
747
|
-
};
|
|
748
|
-
return this.onBeforeHandle(optionsOrResolve, hook);
|
|
749
|
-
}
|
|
750
|
-
onBeforeHandle(options, handler) {
|
|
751
|
-
return handler ? this.on(
|
|
752
|
-
options,
|
|
753
|
-
"beforeHandle",
|
|
754
|
-
handler
|
|
755
|
-
) : this.on("beforeHandle", options);
|
|
756
|
-
}
|
|
757
|
-
onAfterHandle(options, handler) {
|
|
758
|
-
return handler ? this.on(
|
|
759
|
-
options,
|
|
760
|
-
"afterHandle",
|
|
761
|
-
handler
|
|
762
|
-
) : this.on("afterHandle", options);
|
|
763
|
-
}
|
|
764
|
-
mapResponse(options, handler) {
|
|
765
|
-
return handler ? this.on(
|
|
766
|
-
options,
|
|
767
|
-
"mapResponse",
|
|
768
|
-
handler
|
|
769
|
-
) : this.on("mapResponse", options);
|
|
770
|
-
}
|
|
771
|
-
onAfterResponse(options, handler) {
|
|
772
|
-
return handler ? this.on(
|
|
773
|
-
options,
|
|
774
|
-
"afterResponse",
|
|
775
|
-
handler
|
|
776
|
-
) : this.on("afterResponse", options);
|
|
777
|
-
}
|
|
778
|
-
/**
|
|
779
|
-
* ### After Handle | Life cycle event
|
|
780
|
-
* Intercept request **after** main handler is called.
|
|
781
|
-
*
|
|
782
|
-
* If truthy value is returned, will be assigned as `Response`
|
|
783
|
-
*
|
|
784
|
-
* ---
|
|
785
|
-
* @example
|
|
786
|
-
* ```typescript
|
|
787
|
-
* new Elysia()
|
|
788
|
-
* .onAfterHandle((context, response) => {
|
|
789
|
-
* if(typeof response === "object")
|
|
790
|
-
* return JSON.stringify(response)
|
|
791
|
-
* })
|
|
792
|
-
* ```
|
|
793
|
-
*/
|
|
794
|
-
trace(options, handler) {
|
|
795
|
-
handler || (handler = options, options = { as: "local" }), Array.isArray(handler) || (handler = [handler]);
|
|
796
|
-
for (const fn of handler)
|
|
797
|
-
this.on(
|
|
798
|
-
options,
|
|
799
|
-
"trace",
|
|
800
|
-
(0, import_trace.createTracer)(fn)
|
|
801
|
-
);
|
|
802
|
-
return this;
|
|
803
|
-
}
|
|
804
|
-
error(name, error) {
|
|
805
|
-
switch (typeof name) {
|
|
806
|
-
case "string":
|
|
807
|
-
return error.prototype[import_error.ERROR_CODE] = name, this.definitions.error[name] = error, this;
|
|
808
|
-
case "function":
|
|
809
|
-
return this.definitions.error = name(this.definitions.error), this;
|
|
810
|
-
}
|
|
811
|
-
for (const [code, error2] of Object.entries(name))
|
|
812
|
-
error2.prototype[import_error.ERROR_CODE] = code, this.definitions.error[code] = error2;
|
|
813
|
-
return this;
|
|
814
|
-
}
|
|
815
|
-
/**
|
|
816
|
-
* ### Error | Life cycle event
|
|
817
|
-
* Called when error is thrown during processing request
|
|
818
|
-
*
|
|
819
|
-
* ---
|
|
820
|
-
* @example
|
|
821
|
-
* ```typescript
|
|
822
|
-
* new Elysia()
|
|
823
|
-
* .onError(({ code }) => {
|
|
824
|
-
* if(code === "NOT_FOUND")
|
|
825
|
-
* return "Path not found :("
|
|
826
|
-
* })
|
|
827
|
-
* ```
|
|
828
|
-
*/
|
|
829
|
-
onError(options, handler) {
|
|
830
|
-
return handler ? this.on(
|
|
831
|
-
options,
|
|
832
|
-
"error",
|
|
833
|
-
handler
|
|
834
|
-
) : this.on("error", options);
|
|
835
|
-
}
|
|
836
|
-
/**
|
|
837
|
-
* ### stop | Life cycle event
|
|
838
|
-
* Called after server stop serving request
|
|
839
|
-
*
|
|
840
|
-
* ---
|
|
841
|
-
* @example
|
|
842
|
-
* ```typescript
|
|
843
|
-
* new Elysia()
|
|
844
|
-
* .onStop((app) => {
|
|
845
|
-
* cleanup()
|
|
846
|
-
* })
|
|
847
|
-
* ```
|
|
848
|
-
*/
|
|
849
|
-
onStop(handler) {
|
|
850
|
-
return this.on("stop", handler), this;
|
|
851
|
-
}
|
|
852
|
-
on(optionsOrType, typeOrHandlers, handlers) {
|
|
853
|
-
let type;
|
|
854
|
-
switch (typeof optionsOrType) {
|
|
855
|
-
case "string":
|
|
856
|
-
type = optionsOrType, handlers = typeOrHandlers;
|
|
857
|
-
break;
|
|
858
|
-
case "object":
|
|
859
|
-
type = typeOrHandlers, !Array.isArray(typeOrHandlers) && typeof typeOrHandlers == "object" && (handlers = typeOrHandlers);
|
|
860
|
-
break;
|
|
861
|
-
}
|
|
862
|
-
Array.isArray(handlers) ? handlers = (0, import_utils.fnToContainer)(handlers) : typeof handlers == "function" ? handlers = [
|
|
863
|
-
{
|
|
864
|
-
fn: handlers
|
|
865
|
-
}
|
|
866
|
-
] : handlers = [handlers];
|
|
867
|
-
const handles = handlers;
|
|
868
|
-
for (const handle of handles)
|
|
869
|
-
handle.scope = typeof optionsOrType == "string" ? "local" : optionsOrType?.as ?? "local", (type === "resolve" || type === "derive") && (handle.subType = type);
|
|
870
|
-
type !== "trace" && (this.inference = (0, import_sucrose.sucrose)(
|
|
871
|
-
{
|
|
872
|
-
[type]: handles.map((x) => x.fn)
|
|
873
|
-
},
|
|
874
|
-
this.inference,
|
|
875
|
-
this.config.sucrose
|
|
876
|
-
));
|
|
877
|
-
for (const handle of handles) {
|
|
878
|
-
const fn = (0, import_utils2.asHookType)(handle, "global", { skipIfHasType: !0 });
|
|
879
|
-
switch ((this.config.name || this.config.seed) && (fn.checksum = (0, import_utils2.checksum)(
|
|
880
|
-
this.config.name + JSON.stringify(this.config.seed)
|
|
881
|
-
)), type) {
|
|
882
|
-
case "start":
|
|
883
|
-
this.event.start ??= [], this.event.start.push(fn);
|
|
884
|
-
break;
|
|
885
|
-
case "request":
|
|
886
|
-
this.event.request ??= [], this.event.request.push(fn);
|
|
887
|
-
break;
|
|
888
|
-
case "parse":
|
|
889
|
-
this.event.parse ??= [], this.event.parse.push(fn);
|
|
890
|
-
break;
|
|
891
|
-
case "transform":
|
|
892
|
-
this.event.transform ??= [], this.event.transform.push(fn);
|
|
893
|
-
break;
|
|
894
|
-
// @ts-expect-error
|
|
895
|
-
case "derive":
|
|
896
|
-
this.event.transform ??= [], this.event.transform.push(
|
|
897
|
-
(0, import_utils.fnToContainer)(fn, "derive")
|
|
898
|
-
);
|
|
899
|
-
break;
|
|
900
|
-
case "beforeHandle":
|
|
901
|
-
this.event.beforeHandle ??= [], this.event.beforeHandle.push(fn);
|
|
902
|
-
break;
|
|
903
|
-
// @ts-expect-error
|
|
904
|
-
// eslint-disable-next-line sonarjs/no-duplicated-branches
|
|
905
|
-
case "resolve":
|
|
906
|
-
this.event.beforeHandle ??= [], this.event.beforeHandle.push(
|
|
907
|
-
(0, import_utils.fnToContainer)(fn, "resolve")
|
|
908
|
-
);
|
|
909
|
-
break;
|
|
910
|
-
case "afterHandle":
|
|
911
|
-
this.event.afterHandle ??= [], this.event.afterHandle.push(fn);
|
|
912
|
-
break;
|
|
913
|
-
case "mapResponse":
|
|
914
|
-
this.event.mapResponse ??= [], this.event.mapResponse.push(fn);
|
|
915
|
-
break;
|
|
916
|
-
case "afterResponse":
|
|
917
|
-
this.event.afterResponse ??= [], this.event.afterResponse.push(fn);
|
|
918
|
-
break;
|
|
919
|
-
case "trace":
|
|
920
|
-
this.event.trace ??= [], this.event.trace.push(fn);
|
|
921
|
-
break;
|
|
922
|
-
case "error":
|
|
923
|
-
this.event.error ??= [], this.event.error.push(fn);
|
|
924
|
-
break;
|
|
925
|
-
case "stop":
|
|
926
|
-
this.event.stop ??= [], this.event.stop.push(fn);
|
|
927
|
-
break;
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
return this;
|
|
931
|
-
}
|
|
932
|
-
as(type) {
|
|
933
|
-
return (0, import_utils.promoteEvent)(this.event.parse, type), (0, import_utils.promoteEvent)(this.event.transform, type), (0, import_utils.promoteEvent)(this.event.beforeHandle, type), (0, import_utils.promoteEvent)(this.event.afterHandle, type), (0, import_utils.promoteEvent)(this.event.mapResponse, type), (0, import_utils.promoteEvent)(this.event.afterResponse, type), (0, import_utils.promoteEvent)(this.event.trace, type), (0, import_utils.promoteEvent)(this.event.error, type), type === "scoped" ? (this.validator.scoped = (0, import_utils.mergeSchemaValidator)(
|
|
934
|
-
this.validator.scoped,
|
|
935
|
-
this.validator.local
|
|
936
|
-
), this.validator.local = null, this.standaloneValidator.local !== null && (this.standaloneValidator.scoped ||= [], this.standaloneValidator.scoped.push(
|
|
937
|
-
...this.standaloneValidator.local
|
|
938
|
-
), this.standaloneValidator.local = null)) : type === "global" && (this.validator.global = (0, import_utils.mergeSchemaValidator)(
|
|
939
|
-
this.validator.global,
|
|
940
|
-
(0, import_utils.mergeSchemaValidator)(
|
|
941
|
-
this.validator.scoped,
|
|
942
|
-
this.validator.local
|
|
943
|
-
)
|
|
944
|
-
), this.validator.scoped = null, this.validator.local = null, this.standaloneValidator.local !== null && (this.standaloneValidator.scoped ||= [], this.standaloneValidator.scoped.push(
|
|
945
|
-
...this.standaloneValidator.local
|
|
946
|
-
), this.standaloneValidator.local = null), this.standaloneValidator.scoped !== null && (this.standaloneValidator.global ||= [], this.standaloneValidator.global.push(
|
|
947
|
-
...this.standaloneValidator.scoped
|
|
948
|
-
), this.standaloneValidator.scoped = null)), this;
|
|
949
|
-
}
|
|
950
|
-
/**
|
|
951
|
-
* ### group
|
|
952
|
-
* Encapsulate and group path with prefix
|
|
953
|
-
*
|
|
954
|
-
* ---
|
|
955
|
-
* @example
|
|
956
|
-
* ```typescript
|
|
957
|
-
* new Elysia()
|
|
958
|
-
* .group('/v1', app => app
|
|
959
|
-
* .get('/', () => 'Hi')
|
|
960
|
-
* .get('/name', () => 'Elysia')
|
|
961
|
-
* })
|
|
962
|
-
* ```
|
|
963
|
-
*/
|
|
964
|
-
group(prefix, schemaOrRun, run) {
|
|
965
|
-
const instance = new _Elysia({
|
|
966
|
-
...this.config,
|
|
967
|
-
prefix: ""
|
|
968
|
-
});
|
|
969
|
-
instance.singleton = { ...this.singleton }, instance.definitions = { ...this.definitions }, instance.getServer = () => this.getServer(), instance.inference = (0, import_utils.cloneInference)(this.inference), instance.extender = { ...this.extender }, instance["~parser"] = this["~parser"], instance.standaloneValidator = {
|
|
970
|
-
local: [...this.standaloneValidator.local ?? []],
|
|
971
|
-
scoped: [...this.standaloneValidator.scoped ?? []],
|
|
972
|
-
global: [...this.standaloneValidator.global ?? []]
|
|
973
|
-
};
|
|
974
|
-
const isSchema = typeof schemaOrRun == "object", sandbox = (isSchema ? run : schemaOrRun)(instance);
|
|
975
|
-
return this.singleton = (0, import_utils.mergeDeep)(this.singleton, instance.singleton), this.definitions = (0, import_utils.mergeDeep)(this.definitions, instance.definitions), sandbox.event.request?.length && (this.event.request = [
|
|
976
|
-
...this.event.request || [],
|
|
977
|
-
...sandbox.event.request || []
|
|
978
|
-
]), sandbox.event.mapResponse?.length && (this.event.mapResponse = [
|
|
979
|
-
...this.event.mapResponse || [],
|
|
980
|
-
...sandbox.event.mapResponse || []
|
|
981
|
-
]), this.model(sandbox.definitions.type), Object.values(instance.router.history).forEach(
|
|
982
|
-
({ method, path, handler, hooks }) => {
|
|
983
|
-
if (path = (isSchema ? "" : this.config.prefix ?? "") + prefix + path, isSchema) {
|
|
984
|
-
const {
|
|
985
|
-
body,
|
|
986
|
-
headers,
|
|
987
|
-
query,
|
|
988
|
-
params,
|
|
989
|
-
cookie,
|
|
990
|
-
response,
|
|
991
|
-
...hook
|
|
992
|
-
} = schemaOrRun, localHook = hooks;
|
|
993
|
-
this.applyMacro(hook);
|
|
994
|
-
const hasStandaloneSchema = body || headers || query || params || cookie || response;
|
|
995
|
-
this.add(
|
|
996
|
-
method,
|
|
997
|
-
path,
|
|
998
|
-
handler,
|
|
999
|
-
(0, import_utils2.mergeHook)(hook, {
|
|
1000
|
-
...localHook || {},
|
|
1001
|
-
error: localHook.error ? Array.isArray(localHook.error) ? [
|
|
1002
|
-
...localHook.error ?? [],
|
|
1003
|
-
...sandbox.event.error ?? []
|
|
1004
|
-
] : [
|
|
1005
|
-
localHook.error,
|
|
1006
|
-
...sandbox.event.error ?? []
|
|
1007
|
-
] : sandbox.event.error,
|
|
1008
|
-
// Merge macro's standaloneValidator with local and group schema
|
|
1009
|
-
standaloneValidator: hook.standaloneValidator || localHook.standaloneValidator || hasStandaloneSchema ? [
|
|
1010
|
-
...hook.standaloneValidator ?? [],
|
|
1011
|
-
...localHook.standaloneValidator ?? [],
|
|
1012
|
-
...hasStandaloneSchema ? [
|
|
1013
|
-
{
|
|
1014
|
-
body,
|
|
1015
|
-
headers,
|
|
1016
|
-
query,
|
|
1017
|
-
params,
|
|
1018
|
-
cookie,
|
|
1019
|
-
response
|
|
1020
|
-
}
|
|
1021
|
-
] : []
|
|
1022
|
-
] : void 0
|
|
1023
|
-
}),
|
|
1024
|
-
void 0
|
|
1025
|
-
);
|
|
1026
|
-
} else
|
|
1027
|
-
this.add(
|
|
1028
|
-
method,
|
|
1029
|
-
path,
|
|
1030
|
-
handler,
|
|
1031
|
-
(0, import_utils2.mergeHook)(hooks, {
|
|
1032
|
-
error: sandbox.event.error
|
|
1033
|
-
}),
|
|
1034
|
-
{
|
|
1035
|
-
skipPrefix: !0
|
|
1036
|
-
}
|
|
1037
|
-
);
|
|
1038
|
-
}
|
|
1039
|
-
), this;
|
|
1040
|
-
}
|
|
1041
|
-
/**
|
|
1042
|
-
* ### guard
|
|
1043
|
-
* Encapsulate and pass hook into all child handler
|
|
1044
|
-
*
|
|
1045
|
-
* ---
|
|
1046
|
-
* @example
|
|
1047
|
-
* ```typescript
|
|
1048
|
-
* import { t } from 'elysia'
|
|
1049
|
-
*
|
|
1050
|
-
* new Elysia()
|
|
1051
|
-
* .guard({
|
|
1052
|
-
* body: t.Object({
|
|
1053
|
-
* username: t.String(),
|
|
1054
|
-
* password: t.String()
|
|
1055
|
-
* })
|
|
1056
|
-
* }, app => app
|
|
1057
|
-
* .get("/", () => 'Hi')
|
|
1058
|
-
* .get("/name", () => 'Elysia')
|
|
1059
|
-
* })
|
|
1060
|
-
* ```
|
|
1061
|
-
*/
|
|
1062
|
-
guard(hook, run) {
|
|
1063
|
-
if (!run) {
|
|
1064
|
-
if (typeof hook == "object") {
|
|
1065
|
-
this.applyMacro(hook), hook.detail && (this.config.detail ? this.config.detail = (0, import_utils.mergeDeep)(
|
|
1066
|
-
Object.assign({}, this.config.detail),
|
|
1067
|
-
hook.detail
|
|
1068
|
-
) : this.config.detail = hook.detail), hook.tags && (this.config.detail ? this.config.detail.tags = hook.tags : this.config.detail = {
|
|
1069
|
-
tags: hook.tags
|
|
1070
|
-
});
|
|
1071
|
-
const type = hook.as ?? "local";
|
|
1072
|
-
if (hook.schema === "standalone") {
|
|
1073
|
-
this.standaloneValidator[type] || (this.standaloneValidator[type] = []);
|
|
1074
|
-
const response = hook?.response ? typeof hook.response == "string" || import_typebox.Kind in hook.response || "~standard" in hook.response ? {
|
|
1075
|
-
200: hook.response
|
|
1076
|
-
} : hook?.response : void 0;
|
|
1077
|
-
this.standaloneValidator[type].push({
|
|
1078
|
-
body: hook.body,
|
|
1079
|
-
headers: hook.headers,
|
|
1080
|
-
params: hook.params,
|
|
1081
|
-
query: hook.query,
|
|
1082
|
-
response,
|
|
1083
|
-
cookie: hook.cookie
|
|
1084
|
-
});
|
|
1085
|
-
} else
|
|
1086
|
-
this.validator[type] = {
|
|
1087
|
-
body: hook.body ?? this.validator[type]?.body,
|
|
1088
|
-
headers: hook.headers ?? this.validator[type]?.headers,
|
|
1089
|
-
params: hook.params ?? this.validator[type]?.params,
|
|
1090
|
-
query: hook.query ?? this.validator[type]?.query,
|
|
1091
|
-
response: hook.response ?? this.validator[type]?.response,
|
|
1092
|
-
cookie: hook.cookie ?? this.validator[type]?.cookie
|
|
1093
|
-
};
|
|
1094
|
-
return hook.parse && this.on({ as: type }, "parse", hook.parse), hook.transform && this.on({ as: type }, "transform", hook.transform), hook.derive && this.on({ as: type }, "derive", hook.derive), hook.beforeHandle && this.on({ as: type }, "beforeHandle", hook.beforeHandle), hook.resolve && this.on({ as: type }, "resolve", hook.resolve), hook.afterHandle && this.on({ as: type }, "afterHandle", hook.afterHandle), hook.mapResponse && this.on({ as: type }, "mapResponse", hook.mapResponse), hook.afterResponse && this.on({ as: type }, "afterResponse", hook.afterResponse), hook.error && this.on({ as: type }, "error", hook.error), this;
|
|
1095
|
-
}
|
|
1096
|
-
return this.guard({}, hook);
|
|
1097
|
-
}
|
|
1098
|
-
const instance = new _Elysia({
|
|
1099
|
-
...this.config,
|
|
1100
|
-
prefix: ""
|
|
1101
|
-
});
|
|
1102
|
-
instance.singleton = { ...this.singleton }, instance.definitions = { ...this.definitions }, instance.inference = (0, import_utils.cloneInference)(this.inference), instance.extender = { ...this.extender }, instance.getServer = () => this.getServer();
|
|
1103
|
-
const sandbox = run(instance);
|
|
1104
|
-
if (this.singleton = (0, import_utils.mergeDeep)(this.singleton, instance.singleton), this.definitions = (0, import_utils.mergeDeep)(this.definitions, instance.definitions), sandbox.getServer = () => this.server, sandbox.event.request?.length && (this.event.request = [
|
|
1105
|
-
...this.event.request || [],
|
|
1106
|
-
...sandbox.event.request || []
|
|
1107
|
-
]), sandbox.event.mapResponse?.length && (this.event.mapResponse = [
|
|
1108
|
-
...this.event.mapResponse || [],
|
|
1109
|
-
...sandbox.event.mapResponse || []
|
|
1110
|
-
]), this.model(sandbox.definitions.type), Object.values(instance.router.history).forEach(
|
|
1111
|
-
({ method, path, handler, hooks: localHook }) => {
|
|
1112
|
-
const {
|
|
1113
|
-
body,
|
|
1114
|
-
headers,
|
|
1115
|
-
query,
|
|
1116
|
-
params,
|
|
1117
|
-
cookie,
|
|
1118
|
-
response,
|
|
1119
|
-
...guardHook
|
|
1120
|
-
} = hook, hasStandaloneSchema = body || headers || query || params || cookie || response;
|
|
1121
|
-
this.add(
|
|
1122
|
-
method,
|
|
1123
|
-
path,
|
|
1124
|
-
handler,
|
|
1125
|
-
(0, import_utils2.mergeHook)(guardHook, {
|
|
1126
|
-
...localHook || {},
|
|
1127
|
-
error: localHook.error ? Array.isArray(localHook.error) ? [
|
|
1128
|
-
...localHook.error ?? [],
|
|
1129
|
-
...sandbox.event.error ?? []
|
|
1130
|
-
] : [
|
|
1131
|
-
localHook.error,
|
|
1132
|
-
...sandbox.event.error ?? []
|
|
1133
|
-
] : sandbox.event.error,
|
|
1134
|
-
standaloneValidator: hasStandaloneSchema ? [
|
|
1135
|
-
...localHook.standaloneValidator ?? [],
|
|
1136
|
-
{
|
|
1137
|
-
body,
|
|
1138
|
-
headers,
|
|
1139
|
-
query,
|
|
1140
|
-
params,
|
|
1141
|
-
cookie,
|
|
1142
|
-
response
|
|
1143
|
-
}
|
|
1144
|
-
] : localHook.standaloneValidator
|
|
1145
|
-
})
|
|
1146
|
-
);
|
|
1147
|
-
}
|
|
1148
|
-
), instance.promisedModules.size > 0) {
|
|
1149
|
-
let processedUntil = instance.router.history.length;
|
|
1150
|
-
for (const promise of instance.promisedModules.promises)
|
|
1151
|
-
this.promisedModules.add(
|
|
1152
|
-
promise.then(() => {
|
|
1153
|
-
const {
|
|
1154
|
-
body,
|
|
1155
|
-
headers,
|
|
1156
|
-
query,
|
|
1157
|
-
params,
|
|
1158
|
-
cookie,
|
|
1159
|
-
response,
|
|
1160
|
-
...guardHook
|
|
1161
|
-
} = hook, hasStandaloneSchema = body || headers || query || params || cookie || response, startIndex = processedUntil;
|
|
1162
|
-
processedUntil = instance.router.history.length;
|
|
1163
|
-
for (let i = startIndex; i < instance.router.history.length; i++) {
|
|
1164
|
-
const {
|
|
1165
|
-
method,
|
|
1166
|
-
path,
|
|
1167
|
-
handler,
|
|
1168
|
-
hooks: localHook
|
|
1169
|
-
} = instance.router.history[i];
|
|
1170
|
-
this.add(
|
|
1171
|
-
method,
|
|
1172
|
-
path,
|
|
1173
|
-
handler,
|
|
1174
|
-
(0, import_utils2.mergeHook)(guardHook, {
|
|
1175
|
-
...localHook || {},
|
|
1176
|
-
error: localHook.error ? Array.isArray(localHook.error) ? [
|
|
1177
|
-
...localHook.error ?? [],
|
|
1178
|
-
...sandbox.event.error ?? []
|
|
1179
|
-
] : [
|
|
1180
|
-
localHook.error,
|
|
1181
|
-
...sandbox.event.error ?? []
|
|
1182
|
-
] : sandbox.event.error,
|
|
1183
|
-
standaloneValidator: hasStandaloneSchema ? [
|
|
1184
|
-
...localHook.standaloneValidator ?? [],
|
|
1185
|
-
{
|
|
1186
|
-
body,
|
|
1187
|
-
headers,
|
|
1188
|
-
query,
|
|
1189
|
-
params,
|
|
1190
|
-
cookie,
|
|
1191
|
-
response
|
|
1192
|
-
}
|
|
1193
|
-
] : localHook.standaloneValidator
|
|
1194
|
-
})
|
|
1195
|
-
);
|
|
1196
|
-
}
|
|
1197
|
-
})
|
|
1198
|
-
);
|
|
1199
|
-
}
|
|
1200
|
-
return this;
|
|
1201
|
-
}
|
|
1202
|
-
/**
|
|
1203
|
-
* ### use
|
|
1204
|
-
* Merge separate logic of Elysia with current
|
|
1205
|
-
*
|
|
1206
|
-
* ---
|
|
1207
|
-
* @example
|
|
1208
|
-
* ```typescript
|
|
1209
|
-
* const plugin = (app: Elysia) => app
|
|
1210
|
-
* .get('/plugin', () => 'hi')
|
|
1211
|
-
*
|
|
1212
|
-
* new Elysia()
|
|
1213
|
-
* .use(plugin)
|
|
1214
|
-
* ```
|
|
1215
|
-
*/
|
|
1216
|
-
use(plugin) {
|
|
1217
|
-
if (!plugin) return this;
|
|
1218
|
-
if (Array.isArray(plugin)) {
|
|
1219
|
-
let app = this;
|
|
1220
|
-
for (const p of plugin) app = app.use(p);
|
|
1221
|
-
return app;
|
|
1222
|
-
}
|
|
1223
|
-
return plugin instanceof Promise ? (this.promisedModules.add(
|
|
1224
|
-
plugin.then((plugin2) => {
|
|
1225
|
-
if (typeof plugin2 == "function") return plugin2(this);
|
|
1226
|
-
if (plugin2 instanceof _Elysia)
|
|
1227
|
-
return this._use(plugin2).compile();
|
|
1228
|
-
if (plugin2.constructor?.name === "Elysia")
|
|
1229
|
-
return this._use(
|
|
1230
|
-
plugin2
|
|
1231
|
-
).compile();
|
|
1232
|
-
if (typeof plugin2.default == "function")
|
|
1233
|
-
return plugin2.default(this);
|
|
1234
|
-
if (plugin2.default instanceof _Elysia)
|
|
1235
|
-
return this._use(plugin2.default);
|
|
1236
|
-
if (plugin2.constructor?.name === "Elysia")
|
|
1237
|
-
return this._use(plugin2.default);
|
|
1238
|
-
if (plugin2.constructor?.name === "_Elysia")
|
|
1239
|
-
return this._use(plugin2.default);
|
|
1240
|
-
try {
|
|
1241
|
-
return this._use(plugin2.default);
|
|
1242
|
-
} catch (error) {
|
|
1243
|
-
throw console.error(
|
|
1244
|
-
'Invalid plugin type. Expected Elysia instance, function, or module with "default" as Elysia instance or function that returns Elysia instance.'
|
|
1245
|
-
), error;
|
|
1246
|
-
}
|
|
1247
|
-
}).then((v) => (v && typeof v.compile == "function" && v.compile(), v))
|
|
1248
|
-
), this) : this._use(plugin);
|
|
1249
|
-
}
|
|
1250
|
-
propagatePromiseModules(plugin) {
|
|
1251
|
-
if (plugin.promisedModules.size <= 0) return this;
|
|
1252
|
-
for (const promise of plugin.promisedModules.promises)
|
|
1253
|
-
this.promisedModules.add(
|
|
1254
|
-
promise.then((v) => {
|
|
1255
|
-
if (!v) return;
|
|
1256
|
-
const t3 = this._use(v);
|
|
1257
|
-
return t3 instanceof Promise ? t3.then((v2) => {
|
|
1258
|
-
v2 ? v2.compile() : v.compile();
|
|
1259
|
-
}) : v.compile();
|
|
1260
|
-
})
|
|
1261
|
-
);
|
|
1262
|
-
return this;
|
|
1263
|
-
}
|
|
1264
|
-
_use(plugin) {
|
|
1265
|
-
if (typeof plugin == "function") {
|
|
1266
|
-
const instance = plugin(this);
|
|
1267
|
-
return instance instanceof Promise ? (this.promisedModules.add(
|
|
1268
|
-
instance.then((plugin2) => {
|
|
1269
|
-
if (plugin2 instanceof _Elysia) {
|
|
1270
|
-
plugin2.getServer = () => this.getServer(), plugin2.getGlobalRoutes = () => this.getGlobalRoutes(), plugin2.getGlobalDefinitions = () => this.getGlobalDefinitions(), plugin2.model(this.definitions.type), plugin2.error(this.definitions.error);
|
|
1271
|
-
for (const {
|
|
1272
|
-
method,
|
|
1273
|
-
path,
|
|
1274
|
-
handler,
|
|
1275
|
-
hooks
|
|
1276
|
-
} of Object.values(plugin2.router.history))
|
|
1277
|
-
this.add(
|
|
1278
|
-
method,
|
|
1279
|
-
path,
|
|
1280
|
-
handler,
|
|
1281
|
-
hooks,
|
|
1282
|
-
void 0
|
|
1283
|
-
);
|
|
1284
|
-
return plugin2 === this ? void 0 : (this.propagatePromiseModules(plugin2), plugin2);
|
|
1285
|
-
}
|
|
1286
|
-
return typeof plugin2 == "function" ? plugin2(
|
|
1287
|
-
this
|
|
1288
|
-
) : typeof plugin2.default == "function" ? plugin2.default(
|
|
1289
|
-
this
|
|
1290
|
-
) : this._use(plugin2);
|
|
1291
|
-
}).then((v) => (v && typeof v.compile == "function" && v.compile(), v))
|
|
1292
|
-
), this) : instance;
|
|
1293
|
-
}
|
|
1294
|
-
this.propagatePromiseModules(plugin);
|
|
1295
|
-
const name = plugin.config.name, seed = plugin.config.seed;
|
|
1296
|
-
if (plugin.getParent = () => this, plugin.getServer = () => this.getServer(), plugin.getGlobalRoutes = () => this.getGlobalRoutes(), plugin.getGlobalDefinitions = () => this.getGlobalDefinitions(), plugin.standaloneValidator?.scoped && (this.standaloneValidator.local ? this.standaloneValidator.local = this.standaloneValidator.local.concat(
|
|
1297
|
-
plugin.standaloneValidator.scoped
|
|
1298
|
-
) : this.standaloneValidator.local = plugin.standaloneValidator.scoped), plugin.standaloneValidator?.global && (this.standaloneValidator.global ? this.standaloneValidator.global = this.standaloneValidator.global.concat(
|
|
1299
|
-
plugin.standaloneValidator.global
|
|
1300
|
-
) : this.standaloneValidator.global = plugin.standaloneValidator.global), (0, import_utils.isNotEmpty)(plugin["~parser"]) && (this["~parser"] = {
|
|
1301
|
-
...plugin["~parser"],
|
|
1302
|
-
...this["~parser"]
|
|
1303
|
-
}), plugin.setHeaders && this.headers(plugin.setHeaders), name) {
|
|
1304
|
-
name in this.dependencies || (this.dependencies[name] = []);
|
|
1305
|
-
const current = seed !== void 0 ? (0, import_utils2.checksum)(name + JSON.stringify(seed)) : 0;
|
|
1306
|
-
this.dependencies[name].some(
|
|
1307
|
-
({ checksum: checksum3 }) => current === checksum3
|
|
1308
|
-
) || (this.extender.macro = {
|
|
1309
|
-
...this.extender.macro,
|
|
1310
|
-
...plugin.extender.macro
|
|
1311
|
-
}, this.extender.higherOrderFunctions = this.extender.higherOrderFunctions.concat(
|
|
1312
|
-
plugin.extender.higherOrderFunctions
|
|
1313
|
-
));
|
|
1314
|
-
} else
|
|
1315
|
-
(0, import_utils.isNotEmpty)(plugin.extender.macro) && (this.extender.macro = {
|
|
1316
|
-
...this.extender.macro,
|
|
1317
|
-
...plugin.extender.macro
|
|
1318
|
-
}), plugin.extender.higherOrderFunctions.length && (this.extender.higherOrderFunctions = this.extender.higherOrderFunctions.concat(
|
|
1319
|
-
plugin.extender.higherOrderFunctions
|
|
1320
|
-
));
|
|
1321
|
-
if (plugin.extender.higherOrderFunctions.length) {
|
|
1322
|
-
(0, import_utils.deduplicateChecksum)(this.extender.higherOrderFunctions);
|
|
1323
|
-
const hofHashes = [];
|
|
1324
|
-
for (let i = 0; i < this.extender.higherOrderFunctions.length; i++) {
|
|
1325
|
-
const hof = this.extender.higherOrderFunctions[i];
|
|
1326
|
-
hof.checksum && (hofHashes.includes(hof.checksum) && (this.extender.higherOrderFunctions.splice(i, 1), i--), hofHashes.push(hof.checksum));
|
|
1327
|
-
}
|
|
1328
|
-
hofHashes.length = 0;
|
|
1329
|
-
}
|
|
1330
|
-
this.inference = (0, import_sucrose.mergeInference)(this.inference, plugin.inference), (0, import_utils.isNotEmpty)(plugin.singleton.decorator) && this.decorate(plugin.singleton.decorator), (0, import_utils.isNotEmpty)(plugin.singleton.store) && this.state(plugin.singleton.store), (0, import_utils.isNotEmpty)(plugin.definitions.type) && this.model(plugin.definitions.type), (0, import_utils.isNotEmpty)(plugin.definitions.error) && this.error(plugin.definitions.error), (0, import_utils.isNotEmpty)(plugin.extender.macro) && (this.extender.macro = {
|
|
1331
|
-
...this.extender.macro,
|
|
1332
|
-
...plugin.extender.macro
|
|
1333
|
-
});
|
|
1334
|
-
for (const { method, path, handler, hooks } of Object.values(
|
|
1335
|
-
plugin.router.history
|
|
1336
|
-
))
|
|
1337
|
-
this.add(method, path, handler, hooks);
|
|
1338
|
-
if (name) {
|
|
1339
|
-
name in this.dependencies || (this.dependencies[name] = []);
|
|
1340
|
-
const current = seed !== void 0 ? (0, import_utils2.checksum)(name + JSON.stringify(seed)) : 0;
|
|
1341
|
-
if (this.dependencies[name].some(
|
|
1342
|
-
({ checksum: checksum3 }) => current === checksum3
|
|
1343
|
-
))
|
|
1344
|
-
return this;
|
|
1345
|
-
this.dependencies[name].push(
|
|
1346
|
-
this.config?.analytic ? {
|
|
1347
|
-
name: plugin.config.name,
|
|
1348
|
-
seed: plugin.config.seed,
|
|
1349
|
-
checksum: current,
|
|
1350
|
-
dependencies: plugin.dependencies,
|
|
1351
|
-
stack: plugin.telemetry?.stack,
|
|
1352
|
-
routes: plugin.router.history,
|
|
1353
|
-
decorators: plugin.singleton,
|
|
1354
|
-
store: plugin.singleton.store,
|
|
1355
|
-
error: plugin.definitions.error,
|
|
1356
|
-
derive: plugin.event.transform?.filter((x) => x?.subType === "derive").map((x) => ({
|
|
1357
|
-
fn: x.toString(),
|
|
1358
|
-
stack: new Error().stack ?? ""
|
|
1359
|
-
})),
|
|
1360
|
-
resolve: plugin.event.transform?.filter((x) => x?.subType === "resolve").map((x) => ({
|
|
1361
|
-
fn: x.toString(),
|
|
1362
|
-
stack: new Error().stack ?? ""
|
|
1363
|
-
}))
|
|
1364
|
-
} : {
|
|
1365
|
-
name: plugin.config.name,
|
|
1366
|
-
seed: plugin.config.seed,
|
|
1367
|
-
checksum: current,
|
|
1368
|
-
dependencies: plugin.dependencies
|
|
1369
|
-
}
|
|
1370
|
-
), (0, import_utils.isNotEmpty)(plugin.event) && (this.event = (0, import_utils2.mergeLifeCycle)(
|
|
1371
|
-
this.event,
|
|
1372
|
-
(0, import_utils2.filterGlobalHook)(plugin.event),
|
|
1373
|
-
current
|
|
1374
|
-
));
|
|
1375
|
-
} else
|
|
1376
|
-
(0, import_utils.isNotEmpty)(plugin.event) && (this.event = (0, import_utils2.mergeLifeCycle)(
|
|
1377
|
-
this.event,
|
|
1378
|
-
(0, import_utils2.filterGlobalHook)(plugin.event)
|
|
1379
|
-
));
|
|
1380
|
-
return plugin.validator.global && (this.validator.global = (0, import_utils2.mergeHook)(this.validator.global, {
|
|
1381
|
-
...plugin.validator.global
|
|
1382
|
-
})), plugin.validator.scoped && (this.validator.local = (0, import_utils2.mergeHook)(this.validator.local, {
|
|
1383
|
-
...plugin.validator.scoped
|
|
1384
|
-
})), this;
|
|
1385
|
-
}
|
|
1386
|
-
macro(macroOrName, macro) {
|
|
1387
|
-
if (typeof macroOrName == "string" && !macro)
|
|
1388
|
-
throw new Error("Macro function is required");
|
|
1389
|
-
return typeof macroOrName == "string" ? this.extender.macro[macroOrName] = macro : this.extender.macro = {
|
|
1390
|
-
...this.extender.macro,
|
|
1391
|
-
...macroOrName
|
|
1392
|
-
}, this;
|
|
1393
|
-
}
|
|
1394
|
-
applyMacro(localHook, appliable = localHook, {
|
|
1395
|
-
iteration = 0,
|
|
1396
|
-
applied = {}
|
|
1397
|
-
} = {}) {
|
|
1398
|
-
if (iteration >= 16) return;
|
|
1399
|
-
const macro = this.extender.macro;
|
|
1400
|
-
for (let [key, value] of Object.entries(appliable)) {
|
|
1401
|
-
if (!(key in macro)) continue;
|
|
1402
|
-
const macroHook = typeof macro[key] == "function" ? macro[key](value) : macro[key];
|
|
1403
|
-
if (!macroHook || typeof macro[key] == "object" && value === !1)
|
|
1404
|
-
return;
|
|
1405
|
-
const seed = (0, import_utils2.checksum)(key + JSON.stringify(macroHook.seed ?? value));
|
|
1406
|
-
if (!(seed in applied)) {
|
|
1407
|
-
applied[seed] = !0;
|
|
1408
|
-
for (let [k, value2] of Object.entries(macroHook))
|
|
1409
|
-
if (k !== "seed") {
|
|
1410
|
-
if (k in import_utils.emptySchema) {
|
|
1411
|
-
(0, import_utils.insertStandaloneValidator)(
|
|
1412
|
-
localHook,
|
|
1413
|
-
k,
|
|
1414
|
-
value2
|
|
1415
|
-
), delete localHook[key];
|
|
1416
|
-
continue;
|
|
1417
|
-
}
|
|
1418
|
-
if (k === "introspect") {
|
|
1419
|
-
value2?.(localHook), delete localHook[key];
|
|
1420
|
-
continue;
|
|
1421
|
-
}
|
|
1422
|
-
if (k === "detail") {
|
|
1423
|
-
localHook.detail || (localHook.detail = {}), localHook.detail = (0, import_utils.mergeDeep)(localHook.detail, value2, {
|
|
1424
|
-
mergeArray: !0
|
|
1425
|
-
}), delete localHook[key];
|
|
1426
|
-
continue;
|
|
1427
|
-
}
|
|
1428
|
-
if (k in macro) {
|
|
1429
|
-
this.applyMacro(
|
|
1430
|
-
localHook,
|
|
1431
|
-
{ [k]: value2 },
|
|
1432
|
-
{ applied, iteration: iteration + 1 }
|
|
1433
|
-
), delete localHook[key];
|
|
1434
|
-
continue;
|
|
1435
|
-
}
|
|
1436
|
-
switch ((k === "derive" || k === "resolve") && typeof value2 == "function" && (value2 = {
|
|
1437
|
-
fn: value2,
|
|
1438
|
-
subType: k
|
|
1439
|
-
}), typeof localHook[k]) {
|
|
1440
|
-
case "function":
|
|
1441
|
-
localHook[k] = [localHook[k], value2];
|
|
1442
|
-
break;
|
|
1443
|
-
case "object":
|
|
1444
|
-
Array.isArray(localHook[k]) ? localHook[k].push(value2) : localHook[k] = [localHook[k], value2];
|
|
1445
|
-
break;
|
|
1446
|
-
case "undefined":
|
|
1447
|
-
localHook[k] = value2;
|
|
1448
|
-
break;
|
|
1449
|
-
}
|
|
1450
|
-
delete localHook[key];
|
|
1451
|
-
}
|
|
1452
|
-
}
|
|
1453
|
-
}
|
|
1454
|
-
}
|
|
1455
|
-
mount(path, handleOrConfig, config) {
|
|
1456
|
-
if (path instanceof _Elysia || typeof path == "function" || path.length === 0 || path === "/") {
|
|
1457
|
-
const run = typeof path == "function" ? path : path instanceof _Elysia ? path.compile().fetch : handleOrConfig instanceof _Elysia ? handleOrConfig.compile().fetch : typeof handleOrConfig == "function" ? handleOrConfig : (() => {
|
|
1458
|
-
throw new Error("Invalid handler");
|
|
1459
|
-
})(), handler2 = ({ request, path: path2 }) => run(new Request((0, import_utils2.replaceUrlPath)(request.url, path2), request));
|
|
1460
|
-
return this.route("ALL", "/*", handler2, {
|
|
1461
|
-
parse: "none",
|
|
1462
|
-
...config,
|
|
1463
|
-
detail: {
|
|
1464
|
-
...config?.detail,
|
|
1465
|
-
hide: !0
|
|
1466
|
-
},
|
|
1467
|
-
config: {
|
|
1468
|
-
mount: run
|
|
1469
|
-
}
|
|
1470
|
-
}), this;
|
|
1471
|
-
}
|
|
1472
|
-
const handle = handleOrConfig instanceof _Elysia ? handleOrConfig.compile().fetch : typeof handleOrConfig == "function" ? handleOrConfig : (() => {
|
|
1473
|
-
throw new Error("Invalid handler");
|
|
1474
|
-
})(), length = (typeof path == "string" && this.config.prefix ? this.config.prefix + path : path).length - (path.endsWith("*") ? 1 : 0), handler = ({ request, path: path2 }) => handle(
|
|
1475
|
-
new Request(
|
|
1476
|
-
(0, import_utils2.replaceUrlPath)(request.url, path2.slice(length) || "/"),
|
|
1477
|
-
request
|
|
1478
|
-
)
|
|
1479
|
-
);
|
|
1480
|
-
return this.route("ALL", path, handler, {
|
|
1481
|
-
parse: "none",
|
|
1482
|
-
...config,
|
|
1483
|
-
detail: {
|
|
1484
|
-
...config?.detail,
|
|
1485
|
-
hide: !0
|
|
1486
|
-
},
|
|
1487
|
-
config: {
|
|
1488
|
-
mount: handle
|
|
1489
|
-
}
|
|
1490
|
-
}), this.route(
|
|
1491
|
-
"ALL",
|
|
1492
|
-
path + (path.endsWith("/") ? "*" : "/*"),
|
|
1493
|
-
handler,
|
|
1494
|
-
{
|
|
1495
|
-
parse: "none",
|
|
1496
|
-
...config,
|
|
1497
|
-
detail: {
|
|
1498
|
-
...config?.detail,
|
|
1499
|
-
hide: !0
|
|
1500
|
-
},
|
|
1501
|
-
config: {
|
|
1502
|
-
mount: handle
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
), this;
|
|
1506
|
-
}
|
|
1507
|
-
/**
|
|
1508
|
-
* ### get
|
|
1509
|
-
* Register handler for path with method [GET]
|
|
1510
|
-
*
|
|
1511
|
-
* ---
|
|
1512
|
-
* @example
|
|
1513
|
-
* ```typescript
|
|
1514
|
-
* import { Elysia, t } from 'elysia'
|
|
1515
|
-
*
|
|
1516
|
-
* new Elysia()
|
|
1517
|
-
* .get('/', () => 'hi')
|
|
1518
|
-
* .get('/with-hook', () => 'hi', {
|
|
1519
|
-
* response: t.String()
|
|
1520
|
-
* })
|
|
1521
|
-
* ```
|
|
1522
|
-
*/
|
|
1523
|
-
get(path, handler, hook) {
|
|
1524
|
-
return this.add("GET", path, handler, hook), this;
|
|
1525
|
-
}
|
|
1526
|
-
/**
|
|
1527
|
-
* ### post
|
|
1528
|
-
* Register handler for path with method [POST]
|
|
1529
|
-
*
|
|
1530
|
-
* ---
|
|
1531
|
-
* @example
|
|
1532
|
-
* ```typescript
|
|
1533
|
-
* import { Elysia, t } from 'elysia'
|
|
1534
|
-
*
|
|
1535
|
-
* new Elysia()
|
|
1536
|
-
* .post('/', () => 'hi')
|
|
1537
|
-
* .post('/with-hook', () => 'hi', {
|
|
1538
|
-
* response: t.String()
|
|
1539
|
-
* })
|
|
1540
|
-
* ```
|
|
1541
|
-
*/
|
|
1542
|
-
post(path, handler, hook) {
|
|
1543
|
-
return this.add("POST", path, handler, hook), this;
|
|
1544
|
-
}
|
|
1545
|
-
/**
|
|
1546
|
-
* ### put
|
|
1547
|
-
* Register handler for path with method [PUT]
|
|
1548
|
-
*
|
|
1549
|
-
* ---
|
|
1550
|
-
* @example
|
|
1551
|
-
* ```typescript
|
|
1552
|
-
* import { Elysia, t } from 'elysia'
|
|
1553
|
-
*
|
|
1554
|
-
* new Elysia()
|
|
1555
|
-
* .put('/', () => 'hi')
|
|
1556
|
-
* .put('/with-hook', () => 'hi', {
|
|
1557
|
-
* response: t.String()
|
|
1558
|
-
* })
|
|
1559
|
-
* ```
|
|
1560
|
-
*/
|
|
1561
|
-
put(path, handler, hook) {
|
|
1562
|
-
return this.add("PUT", path, handler, hook), this;
|
|
1563
|
-
}
|
|
1564
|
-
/**
|
|
1565
|
-
* ### patch
|
|
1566
|
-
* Register handler for path with method [PATCH]
|
|
1567
|
-
*
|
|
1568
|
-
* ---
|
|
1569
|
-
* @example
|
|
1570
|
-
* ```typescript
|
|
1571
|
-
* import { Elysia, t } from 'elysia'
|
|
1572
|
-
*
|
|
1573
|
-
* new Elysia()
|
|
1574
|
-
* .patch('/', () => 'hi')
|
|
1575
|
-
* .patch('/with-hook', () => 'hi', {
|
|
1576
|
-
* response: t.String()
|
|
1577
|
-
* })
|
|
1578
|
-
* ```
|
|
1579
|
-
*/
|
|
1580
|
-
patch(path, handler, hook) {
|
|
1581
|
-
return this.add("PATCH", path, handler, hook), this;
|
|
1582
|
-
}
|
|
1583
|
-
/**
|
|
1584
|
-
* ### delete
|
|
1585
|
-
* Register handler for path with method [DELETE]
|
|
1586
|
-
*
|
|
1587
|
-
* ---
|
|
1588
|
-
* @example
|
|
1589
|
-
* ```typescript
|
|
1590
|
-
* import { Elysia, t } from 'elysia'
|
|
1591
|
-
*
|
|
1592
|
-
* new Elysia()
|
|
1593
|
-
* .delete('/', () => 'hi')
|
|
1594
|
-
* .delete('/with-hook', () => 'hi', {
|
|
1595
|
-
* response: t.String()
|
|
1596
|
-
* })
|
|
1597
|
-
* ```
|
|
1598
|
-
*/
|
|
1599
|
-
delete(path, handler, hook) {
|
|
1600
|
-
return this.add("DELETE", path, handler, hook), this;
|
|
1601
|
-
}
|
|
1602
|
-
/**
|
|
1603
|
-
* ### options
|
|
1604
|
-
* Register handler for path with method [POST]
|
|
1605
|
-
*
|
|
1606
|
-
* ---
|
|
1607
|
-
* @example
|
|
1608
|
-
* ```typescript
|
|
1609
|
-
* import { Elysia, t } from 'elysia'
|
|
1610
|
-
*
|
|
1611
|
-
* new Elysia()
|
|
1612
|
-
* .options('/', () => 'hi')
|
|
1613
|
-
* .options('/with-hook', () => 'hi', {
|
|
1614
|
-
* response: t.String()
|
|
1615
|
-
* })
|
|
1616
|
-
* ```
|
|
1617
|
-
*/
|
|
1618
|
-
options(path, handler, hook) {
|
|
1619
|
-
return this.add("OPTIONS", path, handler, hook), this;
|
|
1620
|
-
}
|
|
1621
|
-
/**
|
|
1622
|
-
* ### all
|
|
1623
|
-
* Register handler for path with method [ALL]
|
|
1624
|
-
*
|
|
1625
|
-
* ---
|
|
1626
|
-
* @example
|
|
1627
|
-
* ```typescript
|
|
1628
|
-
* import { Elysia, t } from 'elysia'
|
|
1629
|
-
*
|
|
1630
|
-
* new Elysia()
|
|
1631
|
-
* .all('/', () => 'hi')
|
|
1632
|
-
* .all('/with-hook', () => 'hi', {
|
|
1633
|
-
* response: t.String()
|
|
1634
|
-
* })
|
|
1635
|
-
* ```
|
|
1636
|
-
*/
|
|
1637
|
-
all(path, handler, hook) {
|
|
1638
|
-
return this.add("ALL", path, handler, hook), this;
|
|
1639
|
-
}
|
|
1640
|
-
/**
|
|
1641
|
-
* ### head
|
|
1642
|
-
* Register handler for path with method [HEAD]
|
|
1643
|
-
*
|
|
1644
|
-
* ---
|
|
1645
|
-
* @example
|
|
1646
|
-
* ```typescript
|
|
1647
|
-
* import { Elysia, t } from 'elysia'
|
|
1648
|
-
*
|
|
1649
|
-
* new Elysia()
|
|
1650
|
-
* .head('/', () => 'hi')
|
|
1651
|
-
* .head('/with-hook', () => 'hi', {
|
|
1652
|
-
* response: t.String()
|
|
1653
|
-
* })
|
|
1654
|
-
* ```
|
|
1655
|
-
*/
|
|
1656
|
-
head(path, handler, hook) {
|
|
1657
|
-
return this.add("HEAD", path, handler, hook), this;
|
|
1658
|
-
}
|
|
1659
|
-
/**
|
|
1660
|
-
* ### connect
|
|
1661
|
-
* Register handler for path with method [CONNECT]
|
|
1662
|
-
*
|
|
1663
|
-
* ---
|
|
1664
|
-
* @example
|
|
1665
|
-
* ```typescript
|
|
1666
|
-
* import { Elysia, t } from 'elysia'
|
|
1667
|
-
*
|
|
1668
|
-
* new Elysia()
|
|
1669
|
-
* .connect('/', () => 'hi')
|
|
1670
|
-
* .connect('/with-hook', () => 'hi', {
|
|
1671
|
-
* response: t.String()
|
|
1672
|
-
* })
|
|
1673
|
-
* ```
|
|
1674
|
-
*/
|
|
1675
|
-
connect(path, handler, hook) {
|
|
1676
|
-
return this.add("CONNECT", path, handler, hook), this;
|
|
1677
|
-
}
|
|
1678
|
-
/**
|
|
1679
|
-
* ### route
|
|
1680
|
-
* Register handler for path with method [ROUTE]
|
|
1681
|
-
*
|
|
1682
|
-
* ---
|
|
1683
|
-
* @example
|
|
1684
|
-
* ```typescript
|
|
1685
|
-
* import { Elysia, t } from 'elysia'
|
|
1686
|
-
*
|
|
1687
|
-
* new Elysia()
|
|
1688
|
-
* .route('/', () => 'hi')
|
|
1689
|
-
* .route('/with-hook', () => 'hi', {
|
|
1690
|
-
* response: t.String()
|
|
1691
|
-
* })
|
|
1692
|
-
* ```
|
|
1693
|
-
*/
|
|
1694
|
-
route(method, path, handler, hook) {
|
|
1695
|
-
return this.add(method.toUpperCase(), path, handler, hook, hook?.config), this;
|
|
1696
|
-
}
|
|
1697
|
-
/**
|
|
1698
|
-
* ### ws
|
|
1699
|
-
* Register handler for path with method [ws]
|
|
1700
|
-
*
|
|
1701
|
-
* ---
|
|
1702
|
-
* @example
|
|
1703
|
-
* ```typescript
|
|
1704
|
-
* import { Elysia, t } from 'elysia'
|
|
1705
|
-
*
|
|
1706
|
-
* new Elysia()
|
|
1707
|
-
* .ws('/', {
|
|
1708
|
-
* message(ws, message) {
|
|
1709
|
-
* ws.send(message)
|
|
1710
|
-
* }
|
|
1711
|
-
* })
|
|
1712
|
-
* ```
|
|
1713
|
-
*/
|
|
1714
|
-
ws(path, options) {
|
|
1715
|
-
return this["~adapter"].ws ? this["~adapter"].ws(this, path, options) : console.warn("Current adapter doesn't support WebSocket"), this;
|
|
1716
|
-
}
|
|
1717
|
-
/**
|
|
1718
|
-
* ### state
|
|
1719
|
-
* Assign global mutatable state accessible for all handler
|
|
1720
|
-
*
|
|
1721
|
-
* ---
|
|
1722
|
-
* @example
|
|
1723
|
-
* ```typescript
|
|
1724
|
-
* new Elysia()
|
|
1725
|
-
* .state('counter', 0)
|
|
1726
|
-
* .get('/', (({ counter }) => ++counter)
|
|
1727
|
-
* ```
|
|
1728
|
-
*/
|
|
1729
|
-
state(options, name, value) {
|
|
1730
|
-
name === void 0 ? (value = options, options = { as: "append" }, name = "") : value === void 0 && (typeof options == "string" ? (value = name, name = options, options = { as: "append" }) : typeof options == "object" && (value = name, name = ""));
|
|
1731
|
-
const { as } = options;
|
|
1732
|
-
if (typeof name != "string") return this;
|
|
1733
|
-
switch (typeof value) {
|
|
1734
|
-
case "object":
|
|
1735
|
-
return !value || !(0, import_utils.isNotEmpty)(value) ? this : name ? (name in this.singleton.store ? this.singleton.store[name] = (0, import_utils.mergeDeep)(
|
|
1736
|
-
this.singleton.store[name],
|
|
1737
|
-
value,
|
|
1738
|
-
{
|
|
1739
|
-
override: as === "override"
|
|
1740
|
-
}
|
|
1741
|
-
) : this.singleton.store[name] = value, this) : value === null ? this : (this.singleton.store = (0, import_utils.mergeDeep)(this.singleton.store, value, {
|
|
1742
|
-
override: as === "override"
|
|
1743
|
-
}), this);
|
|
1744
|
-
case "function":
|
|
1745
|
-
return name ? (as === "override" || !(name in this.singleton.store)) && (this.singleton.store[name] = value) : this.singleton.store = value(this.singleton.store), this;
|
|
1746
|
-
default:
|
|
1747
|
-
return (as === "override" || !(name in this.singleton.store)) && (this.singleton.store[name] = value), this;
|
|
1748
|
-
}
|
|
1749
|
-
}
|
|
1750
|
-
/**
|
|
1751
|
-
* ### decorate
|
|
1752
|
-
* Define custom method to `Context` accessible for all handler
|
|
1753
|
-
*
|
|
1754
|
-
* ---
|
|
1755
|
-
* @example
|
|
1756
|
-
* ```typescript
|
|
1757
|
-
* new Elysia()
|
|
1758
|
-
* .decorate('getDate', () => Date.now())
|
|
1759
|
-
* .get('/', (({ getDate }) => getDate())
|
|
1760
|
-
* ```
|
|
1761
|
-
*/
|
|
1762
|
-
decorate(options, name, value) {
|
|
1763
|
-
name === void 0 ? (value = options, options = { as: "append" }, name = "") : value === void 0 && (typeof options == "string" ? (value = name, name = options, options = { as: "append" }) : typeof options == "object" && (value = name, name = ""));
|
|
1764
|
-
const { as } = options;
|
|
1765
|
-
if (typeof name != "string") return this;
|
|
1766
|
-
switch (typeof value) {
|
|
1767
|
-
case "object":
|
|
1768
|
-
return name ? (name in this.singleton.decorator ? this.singleton.decorator[name] = (0, import_utils.mergeDeep)(
|
|
1769
|
-
this.singleton.decorator[name],
|
|
1770
|
-
value,
|
|
1771
|
-
{
|
|
1772
|
-
override: as === "override"
|
|
1773
|
-
}
|
|
1774
|
-
) : this.singleton.decorator[name] = value, this) : value === null ? this : (this.singleton.decorator = (0, import_utils.mergeDeep)(
|
|
1775
|
-
this.singleton.decorator,
|
|
1776
|
-
value,
|
|
1777
|
-
{
|
|
1778
|
-
override: as === "override"
|
|
1779
|
-
}
|
|
1780
|
-
), this);
|
|
1781
|
-
case "function":
|
|
1782
|
-
return name ? (as === "override" || !(name in this.singleton.decorator)) && (this.singleton.decorator[name] = value) : this.singleton.decorator = value(this.singleton.decorator), this;
|
|
1783
|
-
default:
|
|
1784
|
-
return (as === "override" || !(name in this.singleton.decorator)) && (this.singleton.decorator[name] = value), this;
|
|
1785
|
-
}
|
|
1786
|
-
}
|
|
1787
|
-
derive(optionsOrTransform, transform) {
|
|
1788
|
-
transform || (transform = optionsOrTransform, optionsOrTransform = { as: "local" });
|
|
1789
|
-
const hook = {
|
|
1790
|
-
subType: "derive",
|
|
1791
|
-
fn: transform
|
|
1792
|
-
};
|
|
1793
|
-
return this.onTransform(optionsOrTransform, hook);
|
|
1794
|
-
}
|
|
1795
|
-
model(name, model) {
|
|
1796
|
-
const onlyTypebox = (a) => {
|
|
1797
|
-
const res = {};
|
|
1798
|
-
for (const key in a) "~standard" in a[key] || (res[key] = a[key]);
|
|
1799
|
-
return res;
|
|
1800
|
-
};
|
|
1801
|
-
switch (typeof name) {
|
|
1802
|
-
case "object":
|
|
1803
|
-
const parsedTypebox = {}, kvs = Object.entries(name);
|
|
1804
|
-
if (!kvs.length) return this;
|
|
1805
|
-
for (const [key, value] of kvs)
|
|
1806
|
-
key in this.definitions.type || ("~standard" in value ? this.definitions.type[key] = value : (parsedTypebox[key] = this.definitions.type[key] = value, parsedTypebox[key].$id ??= `#/components/schemas/${key}`));
|
|
1807
|
-
return this.definitions.typebox = import_type_system.t.Module({
|
|
1808
|
-
...this.definitions.typebox.$defs,
|
|
1809
|
-
...parsedTypebox
|
|
1810
|
-
}), this;
|
|
1811
|
-
case "function":
|
|
1812
|
-
const result = name(this.definitions.type);
|
|
1813
|
-
return this.definitions.type = result, this.definitions.typebox = import_type_system.t.Module(onlyTypebox(result)), this;
|
|
1814
|
-
case "string":
|
|
1815
|
-
if (!model) break;
|
|
1816
|
-
if (this.definitions.type[name] = model, "~standard" in model) return this;
|
|
1817
|
-
const newModel = {
|
|
1818
|
-
...model,
|
|
1819
|
-
id: model.$id ?? `#/components/schemas/${name}`
|
|
1820
|
-
};
|
|
1821
|
-
return this.definitions.typebox = import_type_system.t.Module({
|
|
1822
|
-
...this.definitions.typebox.$defs,
|
|
1823
|
-
...newModel
|
|
1824
|
-
}), this;
|
|
1825
|
-
}
|
|
1826
|
-
return model ? (this.definitions.type[name] = model, "~standard" in model ? this : (this.definitions.typebox = import_type_system.t.Module({
|
|
1827
|
-
...this.definitions.typebox.$defs,
|
|
1828
|
-
[name]: model
|
|
1829
|
-
}), this)) : this;
|
|
1830
|
-
}
|
|
1831
|
-
Ref(key) {
|
|
1832
|
-
return import_type_system.t.Ref(key);
|
|
1833
|
-
}
|
|
1834
|
-
mapDerive(optionsOrDerive, mapper) {
|
|
1835
|
-
mapper || (mapper = optionsOrDerive, optionsOrDerive = { as: "local" });
|
|
1836
|
-
const hook = {
|
|
1837
|
-
subType: "mapDerive",
|
|
1838
|
-
fn: mapper
|
|
1839
|
-
};
|
|
1840
|
-
return this.onTransform(optionsOrDerive, hook);
|
|
1841
|
-
}
|
|
1842
|
-
affix(base, type, word) {
|
|
1843
|
-
if (word === "") return this;
|
|
1844
|
-
const delimieter = ["_", "-", " "], capitalize = (word2) => word2[0].toUpperCase() + word2.slice(1), joinKey = base === "prefix" ? (prefix, word2) => delimieter.includes(prefix.at(-1) ?? "") ? prefix + word2 : prefix + capitalize(word2) : delimieter.includes(word.at(-1) ?? "") ? (suffix, word2) => word2 + suffix : (suffix, word2) => word2 + capitalize(suffix), remap = (type2) => {
|
|
1845
|
-
const store = {};
|
|
1846
|
-
switch (type2) {
|
|
1847
|
-
case "decorator":
|
|
1848
|
-
for (const key in this.singleton.decorator)
|
|
1849
|
-
store[joinKey(word, key)] = this.singleton.decorator[key];
|
|
1850
|
-
this.singleton.decorator = store;
|
|
1851
|
-
break;
|
|
1852
|
-
case "state":
|
|
1853
|
-
for (const key in this.singleton.store)
|
|
1854
|
-
store[joinKey(word, key)] = this.singleton.store[key];
|
|
1855
|
-
this.singleton.store = store;
|
|
1856
|
-
break;
|
|
1857
|
-
case "model":
|
|
1858
|
-
for (const key in this.definitions.type)
|
|
1859
|
-
store[joinKey(word, key)] = this.definitions.type[key];
|
|
1860
|
-
this.definitions.type = store;
|
|
1861
|
-
break;
|
|
1862
|
-
case "error":
|
|
1863
|
-
for (const key in this.definitions.error)
|
|
1864
|
-
store[joinKey(word, key)] = this.definitions.error[key];
|
|
1865
|
-
this.definitions.error = store;
|
|
1866
|
-
break;
|
|
1867
|
-
}
|
|
1868
|
-
}, types = Array.isArray(type) ? type : [type];
|
|
1869
|
-
for (const type2 of types.some((x) => x === "all") ? ["decorator", "state", "model", "error"] : types)
|
|
1870
|
-
remap(type2);
|
|
1871
|
-
return this;
|
|
1872
|
-
}
|
|
1873
|
-
prefix(type, word) {
|
|
1874
|
-
return this.affix("prefix", type, word);
|
|
1875
|
-
}
|
|
1876
|
-
suffix(type, word) {
|
|
1877
|
-
return this.affix("suffix", type, word);
|
|
1878
|
-
}
|
|
1879
|
-
compile() {
|
|
1880
|
-
return this["~adapter"].beforeCompile?.(this), this["~adapter"].isWebStandard ? (this._handle = this.config.aot ? (0, import_compose.composeGeneralHandler)(this) : (0, import_dynamic_handle.createDynamicHandler)(this), Object.defineProperty(this, "fetch", {
|
|
1881
|
-
value: this._handle,
|
|
1882
|
-
configurable: !0,
|
|
1883
|
-
writable: !0
|
|
1884
|
-
}), typeof this.server?.reload == "function" && this.server.reload({
|
|
1885
|
-
...this.server || {},
|
|
1886
|
-
fetch: this.fetch
|
|
1887
|
-
}), this) : (typeof this.server?.reload == "function" && this.server.reload(this.server || {}), this._handle = (0, import_compose.composeGeneralHandler)(this), this);
|
|
1888
|
-
}
|
|
1889
|
-
/**
|
|
1890
|
-
* Use handle can be either sync or async to save performance.
|
|
1891
|
-
*
|
|
1892
|
-
* Beside benchmark purpose, please use 'handle' instead.
|
|
1893
|
-
*/
|
|
1894
|
-
get fetch() {
|
|
1895
|
-
const fetch = this.config.aot ? (0, import_compose.composeGeneralHandler)(this) : (0, import_dynamic_handle.createDynamicHandler)(this);
|
|
1896
|
-
return Object.defineProperty(this, "fetch", {
|
|
1897
|
-
value: fetch,
|
|
1898
|
-
configurable: !0,
|
|
1899
|
-
writable: !0
|
|
1900
|
-
}), fetch;
|
|
1901
|
-
}
|
|
1902
|
-
/**
|
|
1903
|
-
* Wait until all lazy loaded modules all load is fully
|
|
1904
|
-
*/
|
|
1905
|
-
get modules() {
|
|
1906
|
-
return this.promisedModules;
|
|
1
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.js');
|
|
3
|
+
const require_constants = require('./constants.js');
|
|
4
|
+
const require_universal_file = require('./universal/file.js');
|
|
5
|
+
const require_utils = require('./utils.js');
|
|
6
|
+
const require_universal_env = require('./universal/env.js');
|
|
7
|
+
const require_error = require('./error.js');
|
|
8
|
+
const require_cookie_error = require('./cookie/error.js');
|
|
9
|
+
const require_adapter_response_ownership = require('./adapter/response-ownership.js');
|
|
10
|
+
const require_compile_aot = require('./compile/aot.js');
|
|
11
|
+
const require_type_elysia_file_type = require('./type/elysia/file-type.js');
|
|
12
|
+
const require_validator_index = require('./validator/index.js');
|
|
13
|
+
const require_context = require('./context.js');
|
|
14
|
+
const require_base = require('./base.js');
|
|
15
|
+
const require_type_validator_index = require('./type/validator/index.js');
|
|
16
|
+
const require_type_compat = require('./type/compat.js');
|
|
17
|
+
const require_type_index = require('./type/index.js');
|
|
18
|
+
let typebox_system = require("typebox/system");
|
|
19
|
+
|
|
20
|
+
//#region src/index.ts
|
|
21
|
+
var src_default = require_base.Elysia;
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.Compiled = require_compile_aot.Compiled;
|
|
25
|
+
exports.Elysia = require_base.Elysia;
|
|
26
|
+
exports.ElysiaError = require_error.ElysiaError;
|
|
27
|
+
exports.ElysiaFile = require_universal_file.ElysiaFile;
|
|
28
|
+
exports.ElysiaStatus = require_error.ElysiaStatus;
|
|
29
|
+
exports.InternalServerError = require_error.InternalServerError;
|
|
30
|
+
exports.InvalidCookie = require_cookie_error.InvalidCookie;
|
|
31
|
+
exports.Manifest = require_compile_aot.Capture;
|
|
32
|
+
exports.MultiValidator = require_validator_index.MultiValidator;
|
|
33
|
+
exports.NotFound = require_error.NotFound;
|
|
34
|
+
exports.ParseError = require_error.ParseError;
|
|
35
|
+
exports.StandardValidator = require_validator_index.StandardValidator;
|
|
36
|
+
exports.StatusMap = require_constants.StatusMap;
|
|
37
|
+
exports.StatusMapBack = require_constants.StatusMapBack;
|
|
38
|
+
exports.TypeBoxValidator = require_type_validator_index.TypeBoxValidator;
|
|
39
|
+
Object.defineProperty(exports, 'TypeSystem', {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
get: function () {
|
|
42
|
+
return typebox_system.System;
|
|
1907
43
|
}
|
|
1908
|
-
};
|
|
1909
|
-
let Elysia = _Elysia;
|
|
1910
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
1911
|
-
0 && (module.exports = {
|
|
1912
|
-
Cookie,
|
|
1913
|
-
ELYSIA_FORM_DATA,
|
|
1914
|
-
ELYSIA_REQUEST_ID,
|
|
1915
|
-
ELYSIA_TRACE,
|
|
1916
|
-
ERROR_CODE,
|
|
1917
|
-
Elysia,
|
|
1918
|
-
ElysiaCustomStatusResponse,
|
|
1919
|
-
ElysiaFile,
|
|
1920
|
-
ElysiaStatus,
|
|
1921
|
-
InternalServerError,
|
|
1922
|
-
InvalidCookieSignature,
|
|
1923
|
-
InvalidFileType,
|
|
1924
|
-
InvertedStatusMap,
|
|
1925
|
-
NotFoundError,
|
|
1926
|
-
ParseError,
|
|
1927
|
-
StatusMap,
|
|
1928
|
-
TypeSystemPolicy,
|
|
1929
|
-
ValidationError,
|
|
1930
|
-
checksum,
|
|
1931
|
-
cloneInference,
|
|
1932
|
-
deduplicateChecksum,
|
|
1933
|
-
env,
|
|
1934
|
-
file,
|
|
1935
|
-
fileType,
|
|
1936
|
-
form,
|
|
1937
|
-
getResponseSchemaValidator,
|
|
1938
|
-
getSchemaValidator,
|
|
1939
|
-
mapValueError,
|
|
1940
|
-
mergeHook,
|
|
1941
|
-
mergeObjectArray,
|
|
1942
|
-
redirect,
|
|
1943
|
-
replaceSchemaType,
|
|
1944
|
-
replaceUrlPath,
|
|
1945
|
-
serializeCookie,
|
|
1946
|
-
sse,
|
|
1947
|
-
status,
|
|
1948
|
-
t,
|
|
1949
|
-
validationDetail
|
|
1950
44
|
});
|
|
45
|
+
exports.ValidationError = require_error.ValidationError;
|
|
46
|
+
exports.Validator = require_validator_index.Validator;
|
|
47
|
+
exports.borrow = require_adapter_response_ownership.borrow;
|
|
48
|
+
exports.bytes = require_utils.bytes;
|
|
49
|
+
exports.createBaseContext = require_context.createBaseContext;
|
|
50
|
+
exports.createContext = require_context.createContext;
|
|
51
|
+
exports.default = src_default;
|
|
52
|
+
exports.env = require_universal_env.env;
|
|
53
|
+
exports.file = require_universal_file.file;
|
|
54
|
+
exports.fileType = require_type_elysia_file_type.fileType;
|
|
55
|
+
exports.form = require_utils.form;
|
|
56
|
+
exports.prefix = require_utils.prefix;
|
|
57
|
+
exports.problem = require_error.problem;
|
|
58
|
+
exports.redirect = require_utils.redirect;
|
|
59
|
+
exports.setFileTypeDetector = require_type_elysia_file_type.setFileTypeDetector;
|
|
60
|
+
exports.setupTypebox = require_type_compat.setupTypebox;
|
|
61
|
+
exports.sse = require_utils.sse;
|
|
62
|
+
exports.status = require_error.status;
|
|
63
|
+
exports.t = require_type_index.t;
|
|
64
|
+
exports.validationDetail = require_error.validationDetail;
|