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/utils.js
CHANGED
|
@@ -1,697 +1,736 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_universal_constants = require('./universal/constants.js');
|
|
3
|
+
const require_constants = require('./constants.js');
|
|
4
|
+
const require_universal_file = require('./universal/file.js');
|
|
5
|
+
|
|
6
|
+
//#region src/utils.ts
|
|
7
|
+
const nullObject = () => Object.create(null);
|
|
8
|
+
const mapDeriveEntry = (fn) => [fn, "mapDerive"];
|
|
9
|
+
const deriveEntryFn = (entry) => Array.isArray(entry) ? entry[0] : entry;
|
|
10
|
+
const isMapDeriveEntry = (entry) => Array.isArray(entry) && entry[1] === "mapDerive";
|
|
11
|
+
function isEmpty(obj) {
|
|
12
|
+
for (const _ in obj) return false;
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
const isNotEmpty = (obj) => obj && !isEmpty(obj);
|
|
16
|
+
const FNV_OFFSET_BASIS = 2166136261;
|
|
17
|
+
const FNV_PRIME = 16777619;
|
|
18
|
+
/**
|
|
19
|
+
* @internal Generational cache eviction at cap, drop the oldest half.
|
|
20
|
+
*
|
|
21
|
+
* `map.delete(oldest)` per insert leaks ~1KB/eviction on JSC in ~1/3 of
|
|
22
|
+
* processes (churned bucket cells permanently grow the heap and are never
|
|
23
|
+
* reclaimed); clear + reinsert of the newest half measures clean and
|
|
24
|
+
* amortizes to O(1) per insertion.
|
|
25
|
+
*/
|
|
26
|
+
function evictOldestHalf(cache) {
|
|
27
|
+
const keep = [...cache].slice(cache.size >> 1);
|
|
28
|
+
cache.clear();
|
|
29
|
+
for (const entry of keep) cache.set(entry[0], entry[1]);
|
|
30
|
+
}
|
|
31
|
+
function fnv1a(str) {
|
|
32
|
+
let hash = FNV_OFFSET_BASIS;
|
|
33
|
+
const len = str.length;
|
|
34
|
+
for (let i = 0; i < len; i++) {
|
|
35
|
+
hash ^= str.charCodeAt(i);
|
|
36
|
+
hash = Math.imul(hash, FNV_PRIME);
|
|
37
|
+
}
|
|
38
|
+
return hash >>> 0;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Maps each lifecycle/derive function to the hash of the named plugin it was
|
|
42
|
+
* first registered on. Used by `.use()` to dedup absorbed hooks: if a fn's
|
|
43
|
+
* origin is already in `parent.#apps`, the parent has already absorbed that
|
|
44
|
+
* named plugin via another path and should skip re-adding the fn.
|
|
45
|
+
*
|
|
46
|
+
* Anonymous plugins (no name) don't tag their fns - there's no hash to dedup
|
|
47
|
+
* by, so their fns always propagate.
|
|
48
|
+
*/
|
|
49
|
+
const fnOrigin = /* @__PURE__ */ new WeakMap();
|
|
50
|
+
const macroOrigin = /* @__PURE__ */ new WeakMap();
|
|
51
|
+
const isLocalScope = (s) => s === "local" || s === void 0;
|
|
52
|
+
const COMPACT_CHUNK_SIZE = 32;
|
|
53
|
+
const emptyCompactBeforeHandlePrefix = {
|
|
54
|
+
length: 0,
|
|
55
|
+
added: []
|
|
14
56
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
deduplicateChecksum: () => deduplicateChecksum,
|
|
27
|
-
deepClone: () => deepClone,
|
|
28
|
-
emptySchema: () => emptySchema,
|
|
29
|
-
encodePath: () => encodePath,
|
|
30
|
-
filterGlobalHook: () => filterGlobalHook,
|
|
31
|
-
fnToContainer: () => fnToContainer,
|
|
32
|
-
form: () => form,
|
|
33
|
-
getLoosePath: () => getLoosePath,
|
|
34
|
-
getResponseLength: () => getResponseLength,
|
|
35
|
-
hasHeaderShorthand: () => hasHeaderShorthand,
|
|
36
|
-
hasSetImmediate: () => hasSetImmediate,
|
|
37
|
-
injectChecksum: () => injectChecksum,
|
|
38
|
-
insertStandaloneValidator: () => insertStandaloneValidator,
|
|
39
|
-
isClass: () => isClass,
|
|
40
|
-
isNotEmpty: () => isNotEmpty,
|
|
41
|
-
isNumericString: () => isNumericString,
|
|
42
|
-
lifeCycleToArray: () => lifeCycleToArray,
|
|
43
|
-
lifeCycleToFn: () => lifeCycleToFn,
|
|
44
|
-
localHookToLifeCycleStore: () => localHookToLifeCycleStore,
|
|
45
|
-
mergeCookie: () => mergeCookie,
|
|
46
|
-
mergeDeep: () => mergeDeep,
|
|
47
|
-
mergeHook: () => mergeHook,
|
|
48
|
-
mergeLifeCycle: () => mergeLifeCycle,
|
|
49
|
-
mergeObjectArray: () => mergeObjectArray,
|
|
50
|
-
mergeResponse: () => mergeResponse,
|
|
51
|
-
mergeSchemaValidator: () => mergeSchemaValidator,
|
|
52
|
-
primitiveHooks: () => primitiveHooks,
|
|
53
|
-
promoteEvent: () => promoteEvent,
|
|
54
|
-
randomId: () => randomId,
|
|
55
|
-
redirect: () => redirect,
|
|
56
|
-
replaceUrlPath: () => replaceUrlPath,
|
|
57
|
-
signCookie: () => signCookie,
|
|
58
|
-
sse: () => sse,
|
|
59
|
-
supportPerMethodInlineHandler: () => supportPerMethodInlineHandler,
|
|
60
|
-
unsignCookie: () => unsignCookie
|
|
61
|
-
});
|
|
62
|
-
module.exports = __toCommonJS(utils_exports);
|
|
63
|
-
var import_file = require('./universal/file.js'), import_utils = require('./universal/utils.js');
|
|
64
|
-
const replaceUrlPath = (url, pathname) => {
|
|
65
|
-
const pathStartIndex = url.indexOf("/", 11), queryIndex = url.indexOf("?", pathStartIndex);
|
|
66
|
-
return queryIndex === -1 ? `${url.slice(0, pathStartIndex)}${pathname.charCodeAt(0) === 47 ? "" : "/"}${pathname}` : `${url.slice(0, pathStartIndex)}${pathname.charCodeAt(0) === 47 ? "" : "/"}${pathname}${url.slice(queryIndex)}`;
|
|
67
|
-
}, isClass = (v) => typeof v == "function" && /^\s*class\s+/.test(v.toString()) || // Handle Object.create(null)
|
|
68
|
-
v.toString && // Handle import * as Sentry from '@sentry/bun'
|
|
69
|
-
// This also handle [object Date], [object Array]
|
|
70
|
-
// and FFI value like [object Prisma]
|
|
71
|
-
v.toString().startsWith("[object ") && v.toString() !== "[object Object]" || // If object prototype is not pure, then probably a class-like object
|
|
72
|
-
isNotEmpty(Object.getPrototypeOf(v)), isObject = (item) => item && typeof item == "object" && !Array.isArray(item), mergeDeep = (target, source, options) => {
|
|
73
|
-
const skipKeys = options?.skipKeys, override = options?.override ?? !0, mergeArray = options?.mergeArray ?? !1, seen = options?.seen ?? /* @__PURE__ */ new WeakSet();
|
|
74
|
-
if (!isObject(target) || !isObject(source) || seen.has(source)) return target;
|
|
75
|
-
seen.add(source);
|
|
76
|
-
for (const [key, value] of Object.entries(source))
|
|
77
|
-
if (!(skipKeys?.includes(key) || ["__proto__", "constructor", "prototype"].includes(key))) {
|
|
78
|
-
if (mergeArray && Array.isArray(value)) {
|
|
79
|
-
target[key] = Array.isArray(
|
|
80
|
-
target[key]
|
|
81
|
-
) ? [...target[key], ...value] : target[key] = value;
|
|
82
|
-
continue;
|
|
83
|
-
}
|
|
84
|
-
if (!isObject(value) || !(key in target) || isClass(value)) {
|
|
85
|
-
if ((override || !(key in target)) && !Object.isFrozen(target))
|
|
86
|
-
try {
|
|
87
|
-
target[key] = value;
|
|
88
|
-
} catch {
|
|
89
|
-
}
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
if (!Object.isFrozen(target[key]))
|
|
93
|
-
try {
|
|
94
|
-
target[key] = mergeDeep(
|
|
95
|
-
target[key],
|
|
96
|
-
value,
|
|
97
|
-
{ skipKeys, override, mergeArray, seen }
|
|
98
|
-
);
|
|
99
|
-
} catch {
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
return seen.delete(source), target;
|
|
103
|
-
}, mergeCookie = (a, b) => {
|
|
104
|
-
const v = mergeDeep(Object.assign({}, a), b, {
|
|
105
|
-
skipKeys: ["properties"],
|
|
106
|
-
mergeArray: !1
|
|
107
|
-
});
|
|
108
|
-
return v.properties && delete v.properties, v;
|
|
109
|
-
}, mergeObjectArray = (a, b) => {
|
|
110
|
-
if (!b) return a;
|
|
111
|
-
const array = [], checksums = [];
|
|
112
|
-
if (a) {
|
|
113
|
-
Array.isArray(a) || (a = [a]);
|
|
114
|
-
for (const item of a)
|
|
115
|
-
array.push(item), item.checksum && checksums.push(item.checksum);
|
|
116
|
-
}
|
|
117
|
-
if (b) {
|
|
118
|
-
Array.isArray(b) || (b = [b]);
|
|
119
|
-
for (const item of b)
|
|
120
|
-
checksums.includes(item.checksum) || array.push(item);
|
|
121
|
-
}
|
|
122
|
-
return array;
|
|
123
|
-
}, primitiveHooks = [
|
|
124
|
-
"start",
|
|
125
|
-
"request",
|
|
126
|
-
"parse",
|
|
127
|
-
"transform",
|
|
128
|
-
"resolve",
|
|
129
|
-
"beforeHandle",
|
|
130
|
-
"afterHandle",
|
|
131
|
-
"mapResponse",
|
|
132
|
-
"afterResponse",
|
|
133
|
-
"trace",
|
|
134
|
-
"error",
|
|
135
|
-
"stop",
|
|
136
|
-
"body",
|
|
137
|
-
"headers",
|
|
138
|
-
"params",
|
|
139
|
-
"query",
|
|
140
|
-
"response",
|
|
141
|
-
"type",
|
|
142
|
-
"detail"
|
|
143
|
-
], primitiveHookMap = primitiveHooks.reduce(
|
|
144
|
-
(acc, x) => (acc[x] = !0, acc),
|
|
145
|
-
{}
|
|
146
|
-
), isRecordNumber = (x) => typeof x == "object" && Object.keys(x).every((x2) => !isNaN(+x2)), mergeResponse = (a, b) => isRecordNumber(a) && isRecordNumber(b) ? Object.assign({}, a, b) : a && !isRecordNumber(a) && isRecordNumber(b) ? Object.assign({ 200: a }, b) : b ?? a, mergeSchemaValidator = (a, b) => !a && !b ? {
|
|
147
|
-
body: void 0,
|
|
148
|
-
headers: void 0,
|
|
149
|
-
params: void 0,
|
|
150
|
-
query: void 0,
|
|
151
|
-
cookie: void 0,
|
|
152
|
-
response: void 0
|
|
153
|
-
} : {
|
|
154
|
-
body: b?.body ?? a?.body,
|
|
155
|
-
headers: b?.headers ?? a?.headers,
|
|
156
|
-
params: b?.params ?? a?.params,
|
|
157
|
-
query: b?.query ?? a?.query,
|
|
158
|
-
cookie: b?.cookie ?? a?.cookie,
|
|
159
|
-
// @ts-ignore ? This order is correct - SaltyAom
|
|
160
|
-
response: mergeResponse(
|
|
161
|
-
// @ts-ignore
|
|
162
|
-
a?.response,
|
|
163
|
-
// @ts-ignore
|
|
164
|
-
b?.response
|
|
165
|
-
)
|
|
166
|
-
}, mergeHook = (a, b) => {
|
|
167
|
-
if (!b) return a ?? {};
|
|
168
|
-
if (!a) return b ?? {};
|
|
169
|
-
if (!Object.values(b).find((x) => x != null))
|
|
170
|
-
return { ...a };
|
|
171
|
-
const hook = {
|
|
172
|
-
...a,
|
|
173
|
-
...b,
|
|
174
|
-
// Merge local hook first
|
|
175
|
-
// @ts-ignore
|
|
176
|
-
body: b.body ?? a.body,
|
|
177
|
-
// @ts-ignore
|
|
178
|
-
headers: b.headers ?? a.headers,
|
|
179
|
-
// @ts-ignore
|
|
180
|
-
params: b.params ?? a.params,
|
|
181
|
-
// @ts-ignore
|
|
182
|
-
query: b.query ?? a.query,
|
|
183
|
-
// @ts-ignore
|
|
184
|
-
cookie: b.cookie ?? a.cookie,
|
|
185
|
-
// ? This order is correct - SaltyAom
|
|
186
|
-
response: mergeResponse(
|
|
187
|
-
// @ts-ignore
|
|
188
|
-
a.response,
|
|
189
|
-
// @ts-ignore
|
|
190
|
-
b.response
|
|
191
|
-
),
|
|
192
|
-
type: a.type || b.type,
|
|
193
|
-
detail: mergeDeep(
|
|
194
|
-
// @ts-ignore
|
|
195
|
-
b.detail ?? {},
|
|
196
|
-
// @ts-ignore
|
|
197
|
-
a.detail ?? {}
|
|
198
|
-
),
|
|
199
|
-
parse: mergeObjectArray(a.parse, b.parse),
|
|
200
|
-
transform: mergeObjectArray(a.transform, b.transform),
|
|
201
|
-
beforeHandle: mergeObjectArray(
|
|
202
|
-
mergeObjectArray(
|
|
203
|
-
// @ts-ignore
|
|
204
|
-
fnToContainer(a.resolve, "resolve"),
|
|
205
|
-
a.beforeHandle
|
|
206
|
-
),
|
|
207
|
-
mergeObjectArray(
|
|
208
|
-
fnToContainer(b.resolve, "resolve"),
|
|
209
|
-
b.beforeHandle
|
|
210
|
-
)
|
|
211
|
-
),
|
|
212
|
-
afterHandle: mergeObjectArray(a.afterHandle, b.afterHandle),
|
|
213
|
-
mapResponse: mergeObjectArray(a.mapResponse, b.mapResponse),
|
|
214
|
-
afterResponse: mergeObjectArray(
|
|
215
|
-
a.afterResponse,
|
|
216
|
-
b.afterResponse
|
|
217
|
-
),
|
|
218
|
-
trace: mergeObjectArray(a.trace, b.trace),
|
|
219
|
-
error: mergeObjectArray(a.error, b.error),
|
|
220
|
-
// @ts-ignore
|
|
221
|
-
standaloneSchema: (
|
|
222
|
-
// @ts-ignore
|
|
223
|
-
a.standaloneSchema || b.standaloneSchema ? (
|
|
224
|
-
// @ts-ignore
|
|
225
|
-
a.standaloneSchema && !b.standaloneSchema ? (
|
|
226
|
-
// @ts-ignore
|
|
227
|
-
a.standaloneSchema
|
|
228
|
-
) : (
|
|
229
|
-
// @ts-ignore
|
|
230
|
-
b.standaloneSchema && !a.standaloneSchema ? b.standaloneSchema : [
|
|
231
|
-
// @ts-ignore
|
|
232
|
-
...a.standaloneSchema ?? [],
|
|
233
|
-
...b.standaloneSchema ?? []
|
|
234
|
-
]
|
|
235
|
-
)
|
|
236
|
-
) : void 0
|
|
237
|
-
)
|
|
238
|
-
};
|
|
239
|
-
return hook.resolve && delete hook.resolve, hook;
|
|
240
|
-
}, lifeCycleToArray = (a) => {
|
|
241
|
-
a.parse && !Array.isArray(a.parse) && (a.parse = [a.parse]), a.transform && !Array.isArray(a.transform) && (a.transform = [a.transform]), a.afterHandle && !Array.isArray(a.afterHandle) && (a.afterHandle = [a.afterHandle]), a.mapResponse && !Array.isArray(a.mapResponse) && (a.mapResponse = [a.mapResponse]), a.afterResponse && !Array.isArray(a.afterResponse) && (a.afterResponse = [a.afterResponse]), a.trace && !Array.isArray(a.trace) && (a.trace = [a.trace]), a.error && !Array.isArray(a.error) && (a.error = [a.error]);
|
|
242
|
-
let beforeHandle = [];
|
|
243
|
-
return a.resolve && (beforeHandle = fnToContainer(
|
|
244
|
-
// @ts-expect-error
|
|
245
|
-
Array.isArray(a.resolve) ? a.resolve : [a.resolve],
|
|
246
|
-
"resolve"
|
|
247
|
-
), delete a.resolve), a.beforeHandle && (beforeHandle.length ? beforeHandle = beforeHandle.concat(
|
|
248
|
-
Array.isArray(a.beforeHandle) ? a.beforeHandle : [a.beforeHandle]
|
|
249
|
-
) : beforeHandle = Array.isArray(a.beforeHandle) ? a.beforeHandle : [a.beforeHandle]), beforeHandle.length && (a.beforeHandle = beforeHandle), a;
|
|
250
|
-
}, hasHeaderShorthand = import_utils.isBun ? "toJSON" in new Headers() : !1, hasSetImmediate = typeof setImmediate == "function", checksum = (s) => {
|
|
251
|
-
let h = 9;
|
|
252
|
-
for (let i = 0; i < s.length; ) h = Math.imul(h ^ s.charCodeAt(i++), 9 ** 9);
|
|
253
|
-
return h = h ^ h >>> 9;
|
|
254
|
-
}, injectChecksum = (checksum2, x) => {
|
|
255
|
-
if (!x) return;
|
|
256
|
-
if (!Array.isArray(x)) {
|
|
257
|
-
const fn = x;
|
|
258
|
-
return checksum2 && !fn.checksum && (fn.checksum = checksum2), fn.scope === "scoped" && (fn.scope = "local"), fn;
|
|
259
|
-
}
|
|
260
|
-
const fns = [...x];
|
|
261
|
-
for (const fn of fns)
|
|
262
|
-
checksum2 && !fn.checksum && (fn.checksum = checksum2), fn.scope === "scoped" && (fn.scope = "local");
|
|
263
|
-
return fns;
|
|
264
|
-
}, mergeLifeCycle = (a, b, checksum2) => ({
|
|
265
|
-
start: mergeObjectArray(
|
|
266
|
-
a.start,
|
|
267
|
-
injectChecksum(checksum2, b?.start)
|
|
268
|
-
),
|
|
269
|
-
request: mergeObjectArray(
|
|
270
|
-
a.request,
|
|
271
|
-
injectChecksum(checksum2, b?.request)
|
|
272
|
-
),
|
|
273
|
-
parse: mergeObjectArray(
|
|
274
|
-
a.parse,
|
|
275
|
-
injectChecksum(checksum2, b?.parse)
|
|
276
|
-
),
|
|
277
|
-
transform: mergeObjectArray(
|
|
278
|
-
a.transform,
|
|
279
|
-
injectChecksum(checksum2, b?.transform)
|
|
280
|
-
),
|
|
281
|
-
beforeHandle: mergeObjectArray(
|
|
282
|
-
mergeObjectArray(
|
|
283
|
-
// @ts-ignore
|
|
284
|
-
fnToContainer(a.resolve, "resolve"),
|
|
285
|
-
a.beforeHandle
|
|
286
|
-
),
|
|
287
|
-
injectChecksum(
|
|
288
|
-
checksum2,
|
|
289
|
-
mergeObjectArray(
|
|
290
|
-
fnToContainer(b?.resolve, "resolve"),
|
|
291
|
-
b?.beforeHandle
|
|
292
|
-
)
|
|
293
|
-
)
|
|
294
|
-
),
|
|
295
|
-
afterHandle: mergeObjectArray(
|
|
296
|
-
a.afterHandle,
|
|
297
|
-
injectChecksum(checksum2, b?.afterHandle)
|
|
298
|
-
),
|
|
299
|
-
mapResponse: mergeObjectArray(
|
|
300
|
-
a.mapResponse,
|
|
301
|
-
injectChecksum(checksum2, b?.mapResponse)
|
|
302
|
-
),
|
|
303
|
-
afterResponse: mergeObjectArray(
|
|
304
|
-
a.afterResponse,
|
|
305
|
-
injectChecksum(checksum2, b?.afterResponse)
|
|
306
|
-
),
|
|
307
|
-
// Already merged on Elysia._use, also logic is more complicated, can't directly merge
|
|
308
|
-
trace: mergeObjectArray(
|
|
309
|
-
a.trace,
|
|
310
|
-
injectChecksum(checksum2, b?.trace)
|
|
311
|
-
),
|
|
312
|
-
error: mergeObjectArray(
|
|
313
|
-
a.error,
|
|
314
|
-
injectChecksum(checksum2, b?.error)
|
|
315
|
-
),
|
|
316
|
-
stop: mergeObjectArray(
|
|
317
|
-
a.stop,
|
|
318
|
-
injectChecksum(checksum2, b?.stop)
|
|
319
|
-
)
|
|
320
|
-
}), asHookType = (fn, inject, { skipIfHasType = !1 }) => {
|
|
321
|
-
if (!fn) return fn;
|
|
322
|
-
if (!Array.isArray(fn))
|
|
323
|
-
return skipIfHasType ? fn.scope ??= inject : fn.scope = inject, fn;
|
|
324
|
-
for (const x of fn)
|
|
325
|
-
skipIfHasType ? x.scope ??= inject : x.scope = inject;
|
|
326
|
-
return fn;
|
|
327
|
-
}, filterGlobal = (fn) => {
|
|
328
|
-
if (!fn) return fn;
|
|
329
|
-
if (!Array.isArray(fn))
|
|
330
|
-
switch (fn.scope) {
|
|
331
|
-
case "global":
|
|
332
|
-
case "scoped":
|
|
333
|
-
return { ...fn };
|
|
334
|
-
default:
|
|
335
|
-
return { fn };
|
|
336
|
-
}
|
|
337
|
-
const array = [];
|
|
338
|
-
for (const x of fn)
|
|
339
|
-
switch (x.scope) {
|
|
340
|
-
case "global":
|
|
341
|
-
case "scoped":
|
|
342
|
-
array.push({
|
|
343
|
-
...x
|
|
344
|
-
});
|
|
345
|
-
break;
|
|
346
|
-
}
|
|
347
|
-
return array;
|
|
348
|
-
}, filterGlobalHook = (hook) => ({
|
|
349
|
-
// rest is validator
|
|
350
|
-
...hook,
|
|
351
|
-
type: hook?.type,
|
|
352
|
-
detail: hook?.detail,
|
|
353
|
-
parse: filterGlobal(hook?.parse),
|
|
354
|
-
transform: filterGlobal(hook?.transform),
|
|
355
|
-
beforeHandle: filterGlobal(hook?.beforeHandle),
|
|
356
|
-
afterHandle: filterGlobal(hook?.afterHandle),
|
|
357
|
-
mapResponse: filterGlobal(hook?.mapResponse),
|
|
358
|
-
afterResponse: filterGlobal(hook?.afterResponse),
|
|
359
|
-
error: filterGlobal(hook?.error),
|
|
360
|
-
trace: filterGlobal(hook?.trace)
|
|
361
|
-
}), StatusMap = {
|
|
362
|
-
Continue: 100,
|
|
363
|
-
"Switching Protocols": 101,
|
|
364
|
-
Processing: 102,
|
|
365
|
-
"Early Hints": 103,
|
|
366
|
-
OK: 200,
|
|
367
|
-
Created: 201,
|
|
368
|
-
Accepted: 202,
|
|
369
|
-
"Non-Authoritative Information": 203,
|
|
370
|
-
"No Content": 204,
|
|
371
|
-
"Reset Content": 205,
|
|
372
|
-
"Partial Content": 206,
|
|
373
|
-
"Multi-Status": 207,
|
|
374
|
-
"Already Reported": 208,
|
|
375
|
-
"Multiple Choices": 300,
|
|
376
|
-
"Moved Permanently": 301,
|
|
377
|
-
Found: 302,
|
|
378
|
-
"See Other": 303,
|
|
379
|
-
"Not Modified": 304,
|
|
380
|
-
"Temporary Redirect": 307,
|
|
381
|
-
"Permanent Redirect": 308,
|
|
382
|
-
"Bad Request": 400,
|
|
383
|
-
Unauthorized: 401,
|
|
384
|
-
"Payment Required": 402,
|
|
385
|
-
Forbidden: 403,
|
|
386
|
-
"Not Found": 404,
|
|
387
|
-
"Method Not Allowed": 405,
|
|
388
|
-
"Not Acceptable": 406,
|
|
389
|
-
"Proxy Authentication Required": 407,
|
|
390
|
-
"Request Timeout": 408,
|
|
391
|
-
Conflict: 409,
|
|
392
|
-
Gone: 410,
|
|
393
|
-
"Length Required": 411,
|
|
394
|
-
"Precondition Failed": 412,
|
|
395
|
-
"Payload Too Large": 413,
|
|
396
|
-
"URI Too Long": 414,
|
|
397
|
-
"Unsupported Media Type": 415,
|
|
398
|
-
"Range Not Satisfiable": 416,
|
|
399
|
-
"Expectation Failed": 417,
|
|
400
|
-
"I'm a teapot": 418,
|
|
401
|
-
"Enhance Your Calm": 420,
|
|
402
|
-
"Misdirected Request": 421,
|
|
403
|
-
"Unprocessable Content": 422,
|
|
404
|
-
Locked: 423,
|
|
405
|
-
"Failed Dependency": 424,
|
|
406
|
-
"Too Early": 425,
|
|
407
|
-
"Upgrade Required": 426,
|
|
408
|
-
"Precondition Required": 428,
|
|
409
|
-
"Too Many Requests": 429,
|
|
410
|
-
"Request Header Fields Too Large": 431,
|
|
411
|
-
"Unavailable For Legal Reasons": 451,
|
|
412
|
-
"Internal Server Error": 500,
|
|
413
|
-
"Not Implemented": 501,
|
|
414
|
-
"Bad Gateway": 502,
|
|
415
|
-
"Service Unavailable": 503,
|
|
416
|
-
"Gateway Timeout": 504,
|
|
417
|
-
"HTTP Version Not Supported": 505,
|
|
418
|
-
"Variant Also Negotiates": 506,
|
|
419
|
-
"Insufficient Storage": 507,
|
|
420
|
-
"Loop Detected": 508,
|
|
421
|
-
"Not Extended": 510,
|
|
422
|
-
"Network Authentication Required": 511
|
|
423
|
-
}, InvertedStatusMap = Object.fromEntries(
|
|
424
|
-
Object.entries(StatusMap).map(([k, v]) => [v, k])
|
|
425
|
-
);
|
|
426
|
-
function removeTrailingEquals(digest) {
|
|
427
|
-
let trimmedDigest = digest;
|
|
428
|
-
for (; trimmedDigest.endsWith("="); )
|
|
429
|
-
trimmedDigest = trimmedDigest.slice(0, -1);
|
|
430
|
-
return trimmedDigest;
|
|
431
|
-
}
|
|
432
|
-
const encoder = new TextEncoder(), signCookie = async (val, secret) => {
|
|
433
|
-
if (typeof val == "object" ? val = JSON.stringify(val) : typeof val != "string" && (val = val + ""), secret == null)
|
|
434
|
-
throw new TypeError("Secret key must be provided");
|
|
435
|
-
const secretKey = await crypto.subtle.importKey(
|
|
436
|
-
"raw",
|
|
437
|
-
encoder.encode(secret),
|
|
438
|
-
{ name: "HMAC", hash: "SHA-256" },
|
|
439
|
-
!1,
|
|
440
|
-
["sign"]
|
|
441
|
-
), hmacBuffer = await crypto.subtle.sign(
|
|
442
|
-
"HMAC",
|
|
443
|
-
secretKey,
|
|
444
|
-
encoder.encode(val)
|
|
445
|
-
);
|
|
446
|
-
return val + "." + removeTrailingEquals(Buffer.from(hmacBuffer).toString("base64"));
|
|
447
|
-
}, constantTimeEqual = typeof crypto?.timingSafeEqual == "function" ? (a, b) => {
|
|
448
|
-
const ab = Buffer.from(a, "utf8"), bb = Buffer.from(b, "utf8");
|
|
449
|
-
return ab.length !== bb.length ? !1 : crypto.timingSafeEqual(ab, bb);
|
|
450
|
-
} : (a, b) => a === b, unsignCookie = async (input, secret) => {
|
|
451
|
-
if (typeof input != "string")
|
|
452
|
-
throw new TypeError("Signed cookie string must be provided.");
|
|
453
|
-
const dot = input.lastIndexOf(".");
|
|
454
|
-
if (dot === -1)
|
|
455
|
-
return secret === null ? input : !1;
|
|
456
|
-
const tentativeValue = input.slice(0, dot), expectedInput = await signCookie(tentativeValue, secret);
|
|
457
|
-
return constantTimeEqual(expectedInput, input) ? tentativeValue : !1;
|
|
458
|
-
}, insertStandaloneValidator = (hook, name, value) => {
|
|
459
|
-
if (!hook.standaloneValidator?.length || !Array.isArray(hook.standaloneValidator)) {
|
|
460
|
-
hook.standaloneValidator = [
|
|
461
|
-
{
|
|
462
|
-
[name]: value
|
|
463
|
-
}
|
|
464
|
-
];
|
|
465
|
-
return;
|
|
466
|
-
}
|
|
467
|
-
const last = hook.standaloneValidator[hook.standaloneValidator.length - 1];
|
|
468
|
-
name in last ? hook.standaloneValidator.push({
|
|
469
|
-
[name]: value
|
|
470
|
-
}) : last[name] = value;
|
|
471
|
-
}, parseNumericString = (message) => {
|
|
472
|
-
if (typeof message == "number") return message;
|
|
473
|
-
if (message.length < 16) {
|
|
474
|
-
if (message.trim().length === 0) return null;
|
|
475
|
-
const length = Number(message);
|
|
476
|
-
return Number.isNaN(length) ? null : length;
|
|
477
|
-
}
|
|
478
|
-
if (message.length === 16) {
|
|
479
|
-
if (message.trim().length === 0) return null;
|
|
480
|
-
const number = Number(message);
|
|
481
|
-
return Number.isNaN(number) || number.toString() !== message ? null : number;
|
|
482
|
-
}
|
|
483
|
-
return null;
|
|
484
|
-
}, isNumericString = (message) => parseNumericString(message) !== null;
|
|
485
|
-
class PromiseGroup {
|
|
486
|
-
constructor(onError = console.error, onFinally = () => {
|
|
487
|
-
}) {
|
|
488
|
-
this.onError = onError;
|
|
489
|
-
this.onFinally = onFinally;
|
|
490
|
-
this.root = null;
|
|
491
|
-
this.promises = [];
|
|
492
|
-
}
|
|
493
|
-
/**
|
|
494
|
-
* The number of promises still being awaited.
|
|
495
|
-
*/
|
|
496
|
-
get size() {
|
|
497
|
-
return this.promises.length;
|
|
498
|
-
}
|
|
499
|
-
/**
|
|
500
|
-
* Add a promise to the group.
|
|
501
|
-
* @returns The promise that was added.
|
|
502
|
-
*/
|
|
503
|
-
add(promise) {
|
|
504
|
-
return this.promises.push(promise), this.root ||= this.drain(), this.promises.length === 1 && this.then(this.onFinally), promise;
|
|
505
|
-
}
|
|
506
|
-
async drain() {
|
|
507
|
-
for (; this.promises.length > 0; ) {
|
|
508
|
-
try {
|
|
509
|
-
await this.promises[0];
|
|
510
|
-
} catch (error) {
|
|
511
|
-
this.onError(error);
|
|
512
|
-
}
|
|
513
|
-
this.promises.shift();
|
|
514
|
-
}
|
|
515
|
-
this.root = null;
|
|
516
|
-
}
|
|
517
|
-
// Allow the group to be awaited.
|
|
518
|
-
then(onfulfilled, onrejected) {
|
|
519
|
-
return (this.root ?? Promise.resolve()).then(onfulfilled, onrejected);
|
|
520
|
-
}
|
|
521
|
-
}
|
|
522
|
-
const fnToContainer = (fn, subType) => {
|
|
523
|
-
if (!fn) return fn;
|
|
524
|
-
if (!Array.isArray(fn)) {
|
|
525
|
-
if (typeof fn == "function" || typeof fn == "string")
|
|
526
|
-
return subType ? { fn, subType } : { fn };
|
|
527
|
-
if ("fn" in fn) return fn;
|
|
528
|
-
}
|
|
529
|
-
const fns = [];
|
|
530
|
-
for (const x of fn)
|
|
531
|
-
typeof x == "function" || typeof x == "string" ? fns.push(subType ? { fn: x, subType } : { fn: x }) : "fn" in x && fns.push(x);
|
|
532
|
-
return fns;
|
|
533
|
-
}, localHookToLifeCycleStore = (a) => (a.start && (a.start = fnToContainer(a.start)), a.request && (a.request = fnToContainer(a.request)), a.parse && (a.parse = fnToContainer(a.parse)), a.transform && (a.transform = fnToContainer(a.transform)), a.beforeHandle && (a.beforeHandle = fnToContainer(a.beforeHandle)), a.afterHandle && (a.afterHandle = fnToContainer(a.afterHandle)), a.mapResponse && (a.mapResponse = fnToContainer(a.mapResponse)), a.afterResponse && (a.afterResponse = fnToContainer(a.afterResponse)), a.trace && (a.trace = fnToContainer(a.trace)), a.error && (a.error = fnToContainer(a.error)), a.stop && (a.stop = fnToContainer(a.stop)), a), lifeCycleToFn = (a) => {
|
|
534
|
-
const lifecycle = /* @__PURE__ */ Object.create(null);
|
|
535
|
-
return a.start?.map && (lifecycle.start = a.start.map((x) => x.fn)), a.request?.map && (lifecycle.request = a.request.map((x) => x.fn)), a.parse?.map && (lifecycle.parse = a.parse.map((x) => x.fn)), a.transform?.map && (lifecycle.transform = a.transform.map((x) => x.fn)), a.beforeHandle?.map && (lifecycle.beforeHandle = a.beforeHandle.map((x) => x.fn)), a.afterHandle?.map && (lifecycle.afterHandle = a.afterHandle.map((x) => x.fn)), a.mapResponse?.map && (lifecycle.mapResponse = a.mapResponse.map((x) => x.fn)), a.afterResponse?.map && (lifecycle.afterResponse = a.afterResponse.map((x) => x.fn)), a.error?.map && (lifecycle.error = a.error.map((x) => x.fn)), a.stop?.map && (lifecycle.stop = a.stop.map((x) => x.fn)), a.trace?.map ? lifecycle.trace = a.trace.map((x) => x.fn) : lifecycle.trace = [], lifecycle;
|
|
536
|
-
}, cloneInference = (inference) => ({
|
|
537
|
-
body: inference.body,
|
|
538
|
-
cookie: inference.cookie,
|
|
539
|
-
headers: inference.headers,
|
|
540
|
-
query: inference.query,
|
|
541
|
-
set: inference.set,
|
|
542
|
-
server: inference.server,
|
|
543
|
-
path: inference.path,
|
|
544
|
-
route: inference.route,
|
|
545
|
-
url: inference.url
|
|
546
|
-
}), redirect = (url, status = 302) => Response.redirect(url, status), ELYSIA_FORM_DATA = Symbol("ElysiaFormData"), ELYSIA_REQUEST_ID = Symbol("ElysiaRequestId"), form = (items) => {
|
|
547
|
-
const formData = new FormData();
|
|
548
|
-
if (formData[ELYSIA_FORM_DATA] = {}, items)
|
|
549
|
-
for (const [key, value] of Object.entries(items)) {
|
|
550
|
-
if (Array.isArray(value)) {
|
|
551
|
-
formData[ELYSIA_FORM_DATA][key] = [];
|
|
552
|
-
for (const v of value)
|
|
553
|
-
value instanceof File ? formData.append(key, value, value.name) : value instanceof import_file.ElysiaFile ? formData.append(key, value.value, value.value?.name) : formData.append(key, value), formData[ELYSIA_FORM_DATA][key].push(value);
|
|
554
|
-
continue;
|
|
555
|
-
}
|
|
556
|
-
value instanceof File ? formData.append(key, value, value.name) : value instanceof import_file.ElysiaFile ? formData.append(key, value.value, value.value?.name) : formData.append(key, value), formData[ELYSIA_FORM_DATA][key] = value;
|
|
557
|
-
}
|
|
558
|
-
return formData;
|
|
559
|
-
}, randomId = typeof crypto > "u" || (0, import_utils.isCloudflareWorker)() ? () => {
|
|
560
|
-
let result = "";
|
|
561
|
-
const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
562
|
-
for (let i = 0; i < 16; i++)
|
|
563
|
-
result += characters.charAt(
|
|
564
|
-
// 62 is characters.length
|
|
565
|
-
Math.floor(Math.random() * 62)
|
|
566
|
-
);
|
|
567
|
-
return result;
|
|
568
|
-
} : () => {
|
|
569
|
-
const uuid = crypto.randomUUID();
|
|
570
|
-
return uuid.slice(0, 8) + uuid.slice(24, 32);
|
|
571
|
-
}, deduplicateChecksum = (array) => {
|
|
572
|
-
if (!array.length) return [];
|
|
573
|
-
const hashes = [];
|
|
574
|
-
for (let i = 0; i < array.length; i++) {
|
|
575
|
-
const item = array[i];
|
|
576
|
-
item.checksum && (hashes.includes(item.checksum) && (array.splice(i, 1), i--), hashes.push(item.checksum));
|
|
577
|
-
}
|
|
578
|
-
return array;
|
|
579
|
-
}, promoteEvent = (events, as = "scoped") => {
|
|
580
|
-
if (events) {
|
|
581
|
-
if (as === "scoped") {
|
|
582
|
-
for (const event of events)
|
|
583
|
-
"scope" in event && event.scope === "local" && (event.scope = "scoped");
|
|
584
|
-
return;
|
|
585
|
-
}
|
|
586
|
-
for (const event of events) "scope" in event && (event.scope = "global");
|
|
587
|
-
}
|
|
588
|
-
}, getLoosePath = (path) => path.charCodeAt(path.length - 1) === 47 ? path.slice(0, path.length - 1) : path + "/", isNotEmpty = (obj) => {
|
|
589
|
-
if (!obj) return !1;
|
|
590
|
-
for (const _ in obj) return !0;
|
|
591
|
-
return !1;
|
|
592
|
-
}, encodePath = (path, { dynamic = !1 } = {}) => {
|
|
593
|
-
let encoded = encodeURIComponent(path).replace(/%2F/g, "/");
|
|
594
|
-
return dynamic && (encoded = encoded.replace(/%3A/g, ":").replace(/%3F/g, "?")), encoded;
|
|
595
|
-
}, supportPerMethodInlineHandler = !!(typeof Bun > "u" || Bun.semver?.satisfies?.(Bun.version, ">=1.2.14")), sse = (_payload) => {
|
|
596
|
-
if (_payload instanceof ReadableStream)
|
|
597
|
-
return _payload.sse = !0, _payload;
|
|
598
|
-
const payload = typeof _payload == "string" ? { data: _payload } : _payload;
|
|
599
|
-
return payload.sse = !0, payload.toSSE = () => {
|
|
600
|
-
let payloadString = "";
|
|
601
|
-
return payload.id !== void 0 && payload.id !== null && (payloadString += `id: ${payload.id}
|
|
602
|
-
`), payload.event && (payloadString += `event: ${payload.event}
|
|
603
|
-
`), payload.retry !== void 0 && (payloadString += `retry: ${payload.retry}
|
|
604
|
-
`), payload.data === null ? payloadString += `data: null
|
|
605
|
-
` : typeof payload.data == "string" ? payloadString += `data: ${payload.data}
|
|
606
|
-
` : typeof payload.data == "object" && (payloadString += `data: ${JSON.stringify(payload.data)}
|
|
607
|
-
`), payloadString && (payloadString += `
|
|
608
|
-
`), payloadString;
|
|
609
|
-
}, payload;
|
|
57
|
+
const compactBeforeHandleMemos = /* @__PURE__ */ new WeakMap();
|
|
58
|
+
const compactBeforeHandleFunctions = /* @__PURE__ */ new WeakSet();
|
|
59
|
+
const compactBeforeHandleValues = (hook) => {
|
|
60
|
+
if (!hook) return [];
|
|
61
|
+
for (const key in hook) if (key !== "beforeHandle") return false;
|
|
62
|
+
const value = hook.beforeHandle;
|
|
63
|
+
if (value === void 0) return [];
|
|
64
|
+
if (typeof value === "function") return [value];
|
|
65
|
+
if (!Array.isArray(value)) return false;
|
|
66
|
+
for (let i = 0; i < value.length; i++) if (typeof value[i] !== "function") return false;
|
|
67
|
+
return value.slice();
|
|
610
68
|
};
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
69
|
+
const isCompactBeforeHandleOnly = (hook) => compactBeforeHandleValues(hook) !== false;
|
|
70
|
+
function compactBeforeHandleConflicts(hook) {
|
|
71
|
+
const values = compactBeforeHandleValues(hook);
|
|
72
|
+
if (values === false) return true;
|
|
73
|
+
for (let i = 0; i < values.length; i++) if (compactBeforeHandleFunctions.has(values[i])) return true;
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
function appendCompactBeforeHandle(previous, added) {
|
|
77
|
+
if (!added.length) return previous;
|
|
78
|
+
let tail = previous.tail;
|
|
79
|
+
let length = previous.length;
|
|
80
|
+
for (let i = 0; i < added.length; i++) {
|
|
81
|
+
const fn = added[i];
|
|
82
|
+
compactBeforeHandleFunctions.add(fn);
|
|
83
|
+
if (tail && tail.values.length < COMPACT_CHUNK_SIZE) tail = {
|
|
84
|
+
parent: tail.parent,
|
|
85
|
+
values: [...tail.values, fn]
|
|
86
|
+
};
|
|
87
|
+
else tail = {
|
|
88
|
+
parent: tail,
|
|
89
|
+
values: [fn]
|
|
90
|
+
};
|
|
91
|
+
length++;
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
tail,
|
|
95
|
+
length,
|
|
96
|
+
previous: previous.length ? previous : void 0,
|
|
97
|
+
added
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
function compactBeforeHandlePrefix(start) {
|
|
101
|
+
if (!start) return;
|
|
102
|
+
const pending = [];
|
|
103
|
+
let node = start;
|
|
104
|
+
let prefix = emptyCompactBeforeHandlePrefix;
|
|
105
|
+
while (node) {
|
|
106
|
+
const cached = compactBeforeHandleMemos.get(node);
|
|
107
|
+
if (cached !== void 0) {
|
|
108
|
+
if (cached === false) {
|
|
109
|
+
for (let i = 0; i < pending.length; i++) compactBeforeHandleMemos.set(pending[i].node, false);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
prefix = cached;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
if ("combine" in node) {
|
|
116
|
+
compactBeforeHandleMemos.set(node, false);
|
|
117
|
+
for (let i = 0; i < pending.length; i++) compactBeforeHandleMemos.set(pending[i].node, false);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const values = compactBeforeHandleValues(node.added);
|
|
121
|
+
if (values === false) {
|
|
122
|
+
compactBeforeHandleMemos.set(node, false);
|
|
123
|
+
for (let i = 0; i < pending.length; i++) compactBeforeHandleMemos.set(pending[i].node, false);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
pending.push({
|
|
127
|
+
node,
|
|
128
|
+
values
|
|
129
|
+
});
|
|
130
|
+
node = node.parent;
|
|
131
|
+
}
|
|
132
|
+
for (let i = pending.length - 1; i >= 0; i--) {
|
|
133
|
+
const item = pending[i];
|
|
134
|
+
prefix = appendCompactBeforeHandle(prefix, item.values);
|
|
135
|
+
compactBeforeHandleMemos.set(item.node, prefix);
|
|
136
|
+
}
|
|
137
|
+
return prefix.length ? prefix : void 0;
|
|
138
|
+
}
|
|
139
|
+
const flattenNodeStack = [];
|
|
140
|
+
const flattenPhaseStack = [];
|
|
141
|
+
/**
|
|
142
|
+
* Walk the chain tail-first into a fresh `Partial<AppHook>`
|
|
143
|
+
*
|
|
144
|
+
* Explicit-stack walk (no recursion) so it works uniformly for linear
|
|
145
|
+
* chains and combine nodes without risking stack overflow on deep chains
|
|
146
|
+
*/
|
|
147
|
+
function flattenChain(start, keep, stopAt, resolveAdded) {
|
|
148
|
+
if (!start || start === stopAt) return;
|
|
149
|
+
const result = nullObject();
|
|
150
|
+
const nodes = flattenNodeStack;
|
|
151
|
+
const phases = flattenPhaseStack;
|
|
152
|
+
nodes.length = 0;
|
|
153
|
+
phases.length = 0;
|
|
154
|
+
nodes.push(start);
|
|
155
|
+
phases.push(0);
|
|
156
|
+
while (nodes.length) {
|
|
157
|
+
const node = nodes.pop();
|
|
158
|
+
if (phases.pop() === 1) {
|
|
159
|
+
const added = resolveAdded ? resolveAdded(node) : node.added;
|
|
160
|
+
if (added) appendInto(result, added, keep, node.scope);
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (stopAt && node === stopAt) continue;
|
|
164
|
+
if ("combine" in node) {
|
|
165
|
+
nodes.push(node.combine);
|
|
166
|
+
phases.push(0);
|
|
167
|
+
if (node.over) {
|
|
168
|
+
nodes.push(node.over);
|
|
169
|
+
phases.push(0);
|
|
170
|
+
}
|
|
171
|
+
} else {
|
|
172
|
+
nodes.push(node);
|
|
173
|
+
phases.push(1);
|
|
174
|
+
if (node.parent && node.parent !== stopAt) {
|
|
175
|
+
nodes.push(node.parent);
|
|
176
|
+
phases.push(0);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (isNotEmpty(result)) return result;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* whenever any macro table mutates (`.macro()` / `#use` merge)
|
|
184
|
+
* every macro-resolution memo flattens, localHook/chainNode memos
|
|
185
|
+
* validates against the current epoch
|
|
186
|
+
*
|
|
187
|
+
* @see `compile/handler`
|
|
188
|
+
*/
|
|
189
|
+
let macroTableEpoch = 0;
|
|
190
|
+
const macroEpoch = () => macroTableEpoch;
|
|
191
|
+
const invalidateMacroEpoch = () => {
|
|
192
|
+
macroTableEpoch++;
|
|
629
193
|
};
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
194
|
+
const flattenChainMemos = /* @__PURE__ */ new WeakMap();
|
|
195
|
+
/** Drop this root's flattened-chain memo. Recomputable on next compile. */
|
|
196
|
+
function clearFlattenChainMemo(root) {
|
|
197
|
+
flattenChainMemos.delete(root);
|
|
198
|
+
}
|
|
199
|
+
const emptyFlatten = Object.freeze(nullObject());
|
|
200
|
+
function flattenChainCached(root, start, resolveAdded) {
|
|
201
|
+
let bucket = flattenChainMemos.get(root);
|
|
202
|
+
if (!bucket || bucket.e !== macroTableEpoch) {
|
|
203
|
+
bucket = {
|
|
204
|
+
e: macroTableEpoch,
|
|
205
|
+
per: /* @__PURE__ */ new WeakMap()
|
|
206
|
+
};
|
|
207
|
+
flattenChainMemos.set(root, bucket);
|
|
208
|
+
}
|
|
209
|
+
const perRoot = bucket.per;
|
|
210
|
+
let cached = perRoot.get(start);
|
|
211
|
+
if (cached === void 0) {
|
|
212
|
+
cached = flattenChain(start, void 0, void 0, resolveAdded) ?? emptyFlatten;
|
|
213
|
+
perRoot.set(start, cached);
|
|
214
|
+
}
|
|
215
|
+
if (cached === emptyFlatten) return;
|
|
216
|
+
return cached;
|
|
217
|
+
}
|
|
218
|
+
function flattenChainMemo(root, start, resolveAdded) {
|
|
219
|
+
if (!start) return;
|
|
220
|
+
const cached = flattenChainCached(root, start, resolveAdded);
|
|
221
|
+
if (cached === void 0) return;
|
|
222
|
+
return cloneHook(cached);
|
|
223
|
+
}
|
|
224
|
+
function flattenChainMemoReadonly(root, start, resolveAdded) {
|
|
225
|
+
if (!start) return;
|
|
226
|
+
return flattenChainCached(root, start, resolveAdded);
|
|
227
|
+
}
|
|
228
|
+
function appendInto(target, src, keep, nodeScope) {
|
|
229
|
+
if (keep && !keep(nodeScope)) return;
|
|
230
|
+
for (const key in src) {
|
|
231
|
+
const v = src[key];
|
|
232
|
+
if (v === void 0 || v === null) continue;
|
|
233
|
+
if (eventProperties.has(key) || key === "schemas" || key === "~deriveEntries") {
|
|
234
|
+
const existing = target[key];
|
|
235
|
+
if (Array.isArray(v)) if (existing) {
|
|
236
|
+
const arr = existing;
|
|
237
|
+
for (let i = 0; i < v.length; i++) arr.push(v[i]);
|
|
238
|
+
} else target[key] = v.slice();
|
|
239
|
+
else if (existing) existing.push(v);
|
|
240
|
+
else target[key] = [v];
|
|
241
|
+
} else target[key] = v;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
const notLatin = /[^\x00-\xFF]/;
|
|
245
|
+
/**
|
|
246
|
+
*
|
|
247
|
+
* @param url URL to redirect to
|
|
248
|
+
* @param HTTP status code to send,
|
|
249
|
+
*/
|
|
250
|
+
const redirect = (url, status = 302) => new Response(null, {
|
|
251
|
+
status,
|
|
252
|
+
headers: { location: notLatin.test(url) ? encodeURI(url) : url }
|
|
253
|
+
});
|
|
254
|
+
function appendFormField(formData, key, value) {
|
|
255
|
+
if (value === void 0 || value === null) return;
|
|
256
|
+
if (value instanceof Blob) formData.append(key, value);
|
|
257
|
+
else if (value instanceof require_universal_file.ElysiaFile) formData.append(key, value.value);
|
|
258
|
+
else if (typeof value === "object") formData.append(key, JSON.stringify(value));
|
|
259
|
+
else formData.append(key, "" + value);
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Build `FormData` from a `form()` object, skipping the internal `~ely-form`
|
|
263
|
+
* marker that flags the object as a form.
|
|
264
|
+
*/
|
|
265
|
+
function formToFormData(value) {
|
|
266
|
+
const formData = new FormData();
|
|
267
|
+
for (const key in value) {
|
|
268
|
+
if (key === "~ely-form") continue;
|
|
269
|
+
const field = value[key];
|
|
270
|
+
if (Array.isArray(field)) for (const item of field) appendFormField(formData, key, item);
|
|
271
|
+
else appendFormField(formData, key, field);
|
|
272
|
+
}
|
|
273
|
+
return formData;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Return a `multipart/form-data` response.
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```ts
|
|
280
|
+
* import { Elysia, form, file } from 'elysia'
|
|
281
|
+
*
|
|
282
|
+
* new Elysia().get('/', () =>
|
|
283
|
+
* form({
|
|
284
|
+
* name: 'Tea Party',
|
|
285
|
+
* images: [file('1.webp'), file('2.webp')]
|
|
286
|
+
* })
|
|
287
|
+
* )
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
const form = (value) => ({
|
|
291
|
+
...value,
|
|
292
|
+
"~ely-form": 1
|
|
697
293
|
});
|
|
294
|
+
const getLoosePath = (path) => path.charCodeAt(path.length - 1) === 47 ? path.slice(0, -1) : path + "/";
|
|
295
|
+
const byteStreams = /* @__PURE__ */ new WeakSet();
|
|
296
|
+
/**
|
|
297
|
+
* Certify a byte stream for direct Response body pass-through.
|
|
298
|
+
*
|
|
299
|
+
* The returned Response owns this exact stream. Cancel it through the response
|
|
300
|
+
* body reader; preserving identity means Elysia does not install a second
|
|
301
|
+
* request-signal reader after the body is locked.
|
|
302
|
+
*/
|
|
303
|
+
function bytes(stream) {
|
|
304
|
+
byteStreams.add(stream);
|
|
305
|
+
return stream;
|
|
306
|
+
}
|
|
307
|
+
const isByteStream = (value) => typeof value === "object" && value !== null && byteStreams.has(value);
|
|
308
|
+
const sseLineBreak = /\r\n|\r|\n/g;
|
|
309
|
+
const sseField = (name, value) => `${name}: ${(value + "").replace(sseLineBreak, "")}\n`;
|
|
310
|
+
const sseData = (value) => {
|
|
311
|
+
if (value.indexOf("\n") === -1 && value.indexOf("\r") === -1) return "data: " + value + "\n";
|
|
312
|
+
return value.split(sseLineBreak).map((line) => `data: ${line}\n`).join("");
|
|
313
|
+
};
|
|
314
|
+
const sse = (_payload) => {
|
|
315
|
+
if (_payload instanceof ReadableStream) {
|
|
316
|
+
_payload.sse = true;
|
|
317
|
+
return _payload;
|
|
318
|
+
}
|
|
319
|
+
const payload = typeof _payload === "string" ? { data: _payload } : _payload;
|
|
320
|
+
payload.sse = true;
|
|
321
|
+
payload.toSSE = () => {
|
|
322
|
+
let s = "";
|
|
323
|
+
if (payload.id !== void 0 && payload.id !== null) s += sseField("id", payload.id);
|
|
324
|
+
if (payload.event) s += sseField("event", payload.event);
|
|
325
|
+
if (typeof payload.retry === "number" && Number.isFinite(payload.retry) && payload.retry >= 0) s += `retry: ${Math.trunc(payload.retry)}\n`;
|
|
326
|
+
if (payload.data === null) s += "data: null\n";
|
|
327
|
+
else if (typeof payload.data === "string") s += sseData(payload.data);
|
|
328
|
+
else if (typeof payload.data === "object") s += `data: ${JSON.stringify(payload.data)}\n`;
|
|
329
|
+
if (s) s += "\n";
|
|
330
|
+
return s;
|
|
331
|
+
};
|
|
332
|
+
return payload;
|
|
333
|
+
};
|
|
334
|
+
const _enc = new TextEncoder();
|
|
335
|
+
let _constantTimeEqual;
|
|
336
|
+
const _resolveConstantTimeEqual = () => {
|
|
337
|
+
let native;
|
|
338
|
+
try {
|
|
339
|
+
const _crypto = globalThis.process?.getBuiltinModule?.("node:crypto");
|
|
340
|
+
if (typeof _crypto?.timingSafeEqual === "function") native = _crypto.timingSafeEqual;
|
|
341
|
+
} catch {}
|
|
342
|
+
if (!native && typeof crypto?.timingSafeEqual === "function") native = (a, b) => crypto.timingSafeEqual(a, b);
|
|
343
|
+
if (!native) return (a, b) => {
|
|
344
|
+
if (a.length !== b.length) return false;
|
|
345
|
+
let mismatch = 0;
|
|
346
|
+
for (let i = 0; i < a.length; i++) mismatch |= a.charCodeAt(i) ^ b.charCodeAt(i);
|
|
347
|
+
return mismatch === 0;
|
|
348
|
+
};
|
|
349
|
+
const compare = native;
|
|
350
|
+
return (a, b) => {
|
|
351
|
+
const ab = _enc.encode(a);
|
|
352
|
+
const bb = _enc.encode(b);
|
|
353
|
+
return ab.length !== bb.length ? false : compare(ab, bb);
|
|
354
|
+
};
|
|
355
|
+
};
|
|
356
|
+
const constantTimeEqual = (a, b) => (_constantTimeEqual ??= _resolveConstantTimeEqual())(a, b);
|
|
357
|
+
const isRecordNumber = (x) => {
|
|
358
|
+
if (typeof x !== "object") return false;
|
|
359
|
+
const keys = Object.keys(x);
|
|
360
|
+
return keys.length > 0 && keys.every((k) => !isNaN(+k));
|
|
361
|
+
};
|
|
362
|
+
function mergeResponse(a, b) {
|
|
363
|
+
const aRecord = isRecordNumber(a);
|
|
364
|
+
const bRecord = isRecordNumber(b);
|
|
365
|
+
if (aRecord && bRecord) return Object.assign({}, a, b);
|
|
366
|
+
if (aRecord && b) return Object.assign({}, a, { 200: b });
|
|
367
|
+
if (a && bRecord) return Object.assign({ 200: a }, b);
|
|
368
|
+
return b ?? a;
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* a is mutable, b is immutable
|
|
372
|
+
*
|
|
373
|
+
* If both are arrays, mutates a by pushing/appending b
|
|
374
|
+
*/
|
|
375
|
+
function mergeArray(a, b, reverse = false) {
|
|
376
|
+
if (!a) return b;
|
|
377
|
+
if (!b) return a;
|
|
378
|
+
const aIsArray = Array.isArray(a);
|
|
379
|
+
const bIsArray = Array.isArray(b);
|
|
380
|
+
if (reverse) {
|
|
381
|
+
if (aIsArray && bIsArray) {
|
|
382
|
+
if (b.length === 1) {
|
|
383
|
+
a.unshift(b[0]);
|
|
384
|
+
return a;
|
|
385
|
+
}
|
|
386
|
+
return b.concat(a);
|
|
387
|
+
}
|
|
388
|
+
if (aIsArray) {
|
|
389
|
+
a.unshift(b);
|
|
390
|
+
return a;
|
|
391
|
+
}
|
|
392
|
+
if (bIsArray) {
|
|
393
|
+
const out = new Array(b.length + 1);
|
|
394
|
+
for (let i = 0; i < b.length; i++) out[i] = b[i];
|
|
395
|
+
out[b.length] = a;
|
|
396
|
+
return out;
|
|
397
|
+
}
|
|
398
|
+
return [b, a];
|
|
399
|
+
}
|
|
400
|
+
if (aIsArray && bIsArray) {
|
|
401
|
+
for (let i = 0; i < b.length; i++) a.push(b[i]);
|
|
402
|
+
return a;
|
|
403
|
+
}
|
|
404
|
+
if (aIsArray) {
|
|
405
|
+
a.push(b);
|
|
406
|
+
return a;
|
|
407
|
+
}
|
|
408
|
+
if (bIsArray) {
|
|
409
|
+
const out = new Array(b.length + 1);
|
|
410
|
+
out[0] = a;
|
|
411
|
+
for (let i = 0; i < b.length; i++) out[i + 1] = b[i];
|
|
412
|
+
return out;
|
|
413
|
+
}
|
|
414
|
+
return [a, b];
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Like {@link mergeArray} but drops entries from `a` that already appear in
|
|
418
|
+
* `b` by reference. Always allocates fresh arrays - never mutates inputs.
|
|
419
|
+
*
|
|
420
|
+
* Used at the compile-time merge of a route's snapshotted `appHook` with the
|
|
421
|
+
* root's current `rootHook`: the same fn can sit on both sides because
|
|
422
|
+
* `.use()` propagates global/plugin-scoped hooks into the parent, while the
|
|
423
|
+
* route's `appHook` was captured on the child and still holds the original.
|
|
424
|
+
* The fn must run once, in `b`'s position.
|
|
425
|
+
*/
|
|
426
|
+
function dedupedMergeArray(a, b, reverse = false) {
|
|
427
|
+
if (!a) return Array.isArray(b) ? b.slice() : b;
|
|
428
|
+
if (!b) return Array.isArray(a) ? a.slice() : a;
|
|
429
|
+
const aArr = Array.isArray(a) ? a : [a];
|
|
430
|
+
const bArr = Array.isArray(b) ? b : [b];
|
|
431
|
+
const seen = new Set(bArr);
|
|
432
|
+
const filtered = [];
|
|
433
|
+
for (let i = 0; i < aArr.length; i++) if (!seen.has(aArr[i])) filtered.push(aArr[i]);
|
|
434
|
+
return reverse ? bArr.concat(filtered) : filtered.concat(bArr);
|
|
435
|
+
}
|
|
436
|
+
const schemaProperties = new Set([
|
|
437
|
+
"body",
|
|
438
|
+
"headers",
|
|
439
|
+
"params",
|
|
440
|
+
"query",
|
|
441
|
+
"cookie",
|
|
442
|
+
"response"
|
|
443
|
+
]);
|
|
444
|
+
const eventProperties = new Set([
|
|
445
|
+
"start",
|
|
446
|
+
"stop",
|
|
447
|
+
"trace",
|
|
448
|
+
"request",
|
|
449
|
+
"parse",
|
|
450
|
+
"transform",
|
|
451
|
+
"beforeHandle",
|
|
452
|
+
"afterHandle",
|
|
453
|
+
"mapResponse",
|
|
454
|
+
"afterResponse",
|
|
455
|
+
"error"
|
|
456
|
+
]);
|
|
457
|
+
function hookToGuard(a) {
|
|
458
|
+
if (a.schema !== "merge") return a;
|
|
459
|
+
if (a.body || a.headers || a.params || a.query || a.cookie || a.response) {
|
|
460
|
+
a.schemas ??= [];
|
|
461
|
+
const schema = Object.create(null);
|
|
462
|
+
if (a.body) {
|
|
463
|
+
schema.body = a.body;
|
|
464
|
+
a.body = void 0;
|
|
465
|
+
}
|
|
466
|
+
if (a.headers) {
|
|
467
|
+
schema.headers = a.headers;
|
|
468
|
+
a.headers = void 0;
|
|
469
|
+
}
|
|
470
|
+
if (a.params) {
|
|
471
|
+
schema.params = a.params;
|
|
472
|
+
a.params = void 0;
|
|
473
|
+
}
|
|
474
|
+
if (a.query) {
|
|
475
|
+
schema.query = a.query;
|
|
476
|
+
a.query = void 0;
|
|
477
|
+
}
|
|
478
|
+
if (a.cookie) {
|
|
479
|
+
schema.cookie = a.cookie;
|
|
480
|
+
a.cookie = void 0;
|
|
481
|
+
}
|
|
482
|
+
if (a.response) {
|
|
483
|
+
schema.response = a.response;
|
|
484
|
+
a.response = void 0;
|
|
485
|
+
}
|
|
486
|
+
a.schemas.push(schema);
|
|
487
|
+
}
|
|
488
|
+
return a;
|
|
489
|
+
}
|
|
490
|
+
function coalesceSchemas(existing, incoming) {
|
|
491
|
+
for (const entry of incoming) {
|
|
492
|
+
if (!entry || typeof entry !== "object") continue;
|
|
493
|
+
let merged = false;
|
|
494
|
+
for (let i = 0; i < existing.length; i++) {
|
|
495
|
+
const e = existing[i];
|
|
496
|
+
let canMerge = true;
|
|
497
|
+
for (const k in entry) if (k in e && e[k] !== entry[k]) {
|
|
498
|
+
canMerge = false;
|
|
499
|
+
break;
|
|
500
|
+
}
|
|
501
|
+
if (canMerge) {
|
|
502
|
+
existing[i] = Object.assign(nullObject(), e, entry);
|
|
503
|
+
merged = true;
|
|
504
|
+
break;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
if (!merged) existing.push(entry);
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
function mergeHook(a, b, reverse = false, dedup = false) {
|
|
511
|
+
if (!b) return a;
|
|
512
|
+
if (!a) return b;
|
|
513
|
+
const merge = dedup ? dedupedMergeArray : mergeArray;
|
|
514
|
+
if (!a.body && b.body) a.body = b.body;
|
|
515
|
+
if (!a.headers && b.headers) a.headers = b.headers;
|
|
516
|
+
if (!a.params && b.params) a.params = b.params;
|
|
517
|
+
if (!a.query && b.query) a.query = b.query;
|
|
518
|
+
if (!a.cookie && b.cookie) a.cookie = b.cookie;
|
|
519
|
+
if (!a.response && b.response) a.response = b.response;
|
|
520
|
+
else if (a.response && b.response) a.response = mergeResponse(b.response, a.response);
|
|
521
|
+
if (a.parse || b.parse) a.parse = merge(a.parse, b.parse, reverse);
|
|
522
|
+
if (a.transform || b.transform) a.transform = merge(a.transform, b.transform, reverse);
|
|
523
|
+
if (a.derive || b.derive) a.derive = merge(a.derive, b.derive, reverse);
|
|
524
|
+
if (a.beforeHandle || b.beforeHandle) a.beforeHandle = merge(a.beforeHandle, b.beforeHandle, reverse);
|
|
525
|
+
if (a.afterHandle || b.afterHandle) a.afterHandle = merge(a.afterHandle, b.afterHandle, reverse);
|
|
526
|
+
if (a.mapResponse || b.mapResponse) a.mapResponse = merge(a.mapResponse, b.mapResponse, reverse);
|
|
527
|
+
if (a.afterResponse || b.afterResponse) a.afterResponse = merge(a.afterResponse, b.afterResponse, reverse);
|
|
528
|
+
if (a.error || b.error) a.error = merge(a.error, b.error, reverse);
|
|
529
|
+
if (a.trace || b.trace) a.trace = merge(a.trace, b.trace, reverse);
|
|
530
|
+
if (a.schemas || b.schemas) a.schemas = mergeArray(a.schemas, b.schemas, reverse);
|
|
531
|
+
const aDerive = a["~deriveEntries"];
|
|
532
|
+
const bDerive = b["~deriveEntries"];
|
|
533
|
+
if (aDerive || bDerive) a["~deriveEntries"] = mergeArray(aDerive, bDerive, reverse);
|
|
534
|
+
return a;
|
|
535
|
+
}
|
|
536
|
+
const createErrorEventHandler = (fn, error) => (context) => {
|
|
537
|
+
if (context.error instanceof error) return fn(context);
|
|
538
|
+
};
|
|
539
|
+
const isObject = (item) => item && typeof item === "object" && !Array.isArray(item);
|
|
540
|
+
const isClassRegex = /^\s*class\s+/;
|
|
541
|
+
const isClass = (v) => typeof v === "function" && isClassRegex.test(v.toString()) || v.toString && v.toString().startsWith("[object ") && v.toString() !== "[object Object]" || isNotEmpty(Object.getPrototypeOf(v));
|
|
542
|
+
function mergeDeep(target, source, skipKeys, override = true, mergeArray = false, seen, cloneAdopt) {
|
|
543
|
+
if (!isObject(target) || !isObject(source)) return target;
|
|
544
|
+
if (seen?.has(source)) return target;
|
|
545
|
+
const keys = Object.keys(source);
|
|
546
|
+
const targetFrozen = Object.isFrozen(target);
|
|
547
|
+
for (let i = 0; i < keys.length; i++) {
|
|
548
|
+
const key = keys[i];
|
|
549
|
+
const value = source[key];
|
|
550
|
+
if (skipKeys?.includes(key) || require_constants.dangerousKeys.has(key)) continue;
|
|
551
|
+
if (mergeArray && Array.isArray(value)) {
|
|
552
|
+
const existing = target[key];
|
|
553
|
+
target[key] = Array.isArray(existing) ? existing.concat(value) : value;
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
556
|
+
const valueIsObject = isObject(value);
|
|
557
|
+
if (!valueIsObject || !(key in target) || isClass(value)) {
|
|
558
|
+
if ((override || !(key in target)) && !targetFrozen) try {
|
|
559
|
+
target[key] = valueIsObject && cloneAdopt !== void 0 && isPlainObject(value) ? clonePlainDecorators(value, cloneAdopt.map ??= /* @__PURE__ */ new WeakMap()) : value;
|
|
560
|
+
} catch {}
|
|
561
|
+
continue;
|
|
562
|
+
}
|
|
563
|
+
if (!Object.isFrozen(target[key])) {
|
|
564
|
+
seen ??= /* @__PURE__ */ new WeakSet();
|
|
565
|
+
seen.add(source);
|
|
566
|
+
try {
|
|
567
|
+
target[key] = mergeDeep(target[key], value, skipKeys, override, mergeArray, seen, cloneAdopt);
|
|
568
|
+
} catch {}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
seen?.delete(source);
|
|
572
|
+
return target;
|
|
573
|
+
}
|
|
574
|
+
const isBlob = (value) => value instanceof Blob || value instanceof require_universal_file.ElysiaFile;
|
|
575
|
+
function cloneHook(src) {
|
|
576
|
+
const out = nullObject();
|
|
577
|
+
for (const key in src) {
|
|
578
|
+
const value = src[key];
|
|
579
|
+
out[key] = Array.isArray(value) ? value.slice() : value;
|
|
580
|
+
}
|
|
581
|
+
return out;
|
|
582
|
+
}
|
|
583
|
+
function clonePlainDeep(value, seen) {
|
|
584
|
+
if (Array.isArray(value)) {
|
|
585
|
+
seen ??= /* @__PURE__ */ new WeakMap();
|
|
586
|
+
const hit = seen.get(value);
|
|
587
|
+
if (hit) return hit;
|
|
588
|
+
const out = [];
|
|
589
|
+
seen.set(value, out);
|
|
590
|
+
for (let i = 0; i < value.length; i++) out[i] = clonePlainDeep(value[i], seen);
|
|
591
|
+
return out;
|
|
592
|
+
}
|
|
593
|
+
if (isPlainObject(value)) {
|
|
594
|
+
seen ??= /* @__PURE__ */ new WeakMap();
|
|
595
|
+
const hit = seen.get(value);
|
|
596
|
+
if (hit) return hit;
|
|
597
|
+
const out = nullObject();
|
|
598
|
+
seen.set(value, out);
|
|
599
|
+
for (const key in value) out[key] = clonePlainDeep(value[key], seen);
|
|
600
|
+
return out;
|
|
601
|
+
}
|
|
602
|
+
return value;
|
|
603
|
+
}
|
|
604
|
+
function guardNonPlainLeaves(target, source) {
|
|
605
|
+
for (const key in source) {
|
|
606
|
+
if (!Object.hasOwn(source, key)) continue;
|
|
607
|
+
const sv = source[key];
|
|
608
|
+
if (!isObject(sv) || isClass(sv)) continue;
|
|
609
|
+
const tv = target[key];
|
|
610
|
+
if (tv === void 0 || !isObject(tv)) continue;
|
|
611
|
+
if (isPlainObject(tv)) {
|
|
612
|
+
guardNonPlainLeaves(tv, sv);
|
|
613
|
+
continue;
|
|
614
|
+
}
|
|
615
|
+
target[key] = clonePlainDeep(sv);
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
function joinPath(base, path) {
|
|
619
|
+
if (!path) return base;
|
|
620
|
+
const baseEndsWithSlash = base.charCodeAt(base.length - 1) === 47;
|
|
621
|
+
const pathStartsWithSlash = path.charCodeAt(0) === 47;
|
|
622
|
+
if (baseEndsWithSlash && pathStartsWithSlash) return base + path.slice(1);
|
|
623
|
+
if (!baseEndsWithSlash && !pathStartsWithSlash) return base + "/" + path;
|
|
624
|
+
return base + path;
|
|
625
|
+
}
|
|
626
|
+
function pushField(target, key, item, defaultArray = false) {
|
|
627
|
+
const v = target[key];
|
|
628
|
+
if (v) if (Array.isArray(v)) target[key].push(item);
|
|
629
|
+
else target[key] = [v, item];
|
|
630
|
+
else target[key] = defaultArray ? [item] : item;
|
|
631
|
+
}
|
|
632
|
+
const requestId = require_universal_constants.isBun ? Bun.randomUUIDv7 : crypto.randomUUIDv7?.bind(crypto) ?? crypto.randomUUID?.bind(crypto);
|
|
633
|
+
function replaceUrlPath(url, path) {
|
|
634
|
+
const i = url.indexOf("/", 11);
|
|
635
|
+
const qs = url.indexOf("?", i);
|
|
636
|
+
return `${url.slice(0, i)}${path.charCodeAt(0) === 47 ? "" : "/"}${path}${qs === -1 ? "" : url.slice(qs)}`;
|
|
637
|
+
}
|
|
638
|
+
function isPlainObject(v) {
|
|
639
|
+
if (!v || typeof v !== "object" || Array.isArray(v)) return false;
|
|
640
|
+
const proto = Object.getPrototypeOf(v);
|
|
641
|
+
return proto === Object.prototype || proto === null;
|
|
642
|
+
}
|
|
643
|
+
function clonePlainDecorators(source, seen) {
|
|
644
|
+
if (seen !== void 0) {
|
|
645
|
+
const existing = seen.get(source);
|
|
646
|
+
if (existing) return existing;
|
|
647
|
+
}
|
|
648
|
+
const out = nullObject();
|
|
649
|
+
if (seen !== void 0) seen.set(source, out);
|
|
650
|
+
for (const key in source) {
|
|
651
|
+
const value = source[key];
|
|
652
|
+
if (isPlainObject(value)) {
|
|
653
|
+
if (seen === void 0) (seen = /* @__PURE__ */ new WeakMap()).set(source, out);
|
|
654
|
+
out[key] = clonePlainDecorators(value, seen);
|
|
655
|
+
} else out[key] = value;
|
|
656
|
+
}
|
|
657
|
+
return out;
|
|
658
|
+
}
|
|
659
|
+
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
660
|
+
function prefix(prefix, models) {
|
|
661
|
+
const prefixed = nullObject();
|
|
662
|
+
for (const key in models) prefixed[`${prefix}.${key}`] = models[key];
|
|
663
|
+
return prefixed;
|
|
664
|
+
}
|
|
665
|
+
prefix.capitalize = function prefixModelsCapitalize(prefix, models) {
|
|
666
|
+
const prefixed = nullObject();
|
|
667
|
+
for (const key in models) prefixed[`${prefix}.${capitalize(key)}`] = models[key];
|
|
668
|
+
return prefixed;
|
|
669
|
+
};
|
|
670
|
+
const macroSeedRefIds = /* @__PURE__ */ new WeakMap();
|
|
671
|
+
let macroSeedRefCounter = 0;
|
|
672
|
+
function macroSeedRefId(ref) {
|
|
673
|
+
let id = macroSeedRefIds.get(ref);
|
|
674
|
+
if (id === void 0) macroSeedRefIds.set(ref, id = ++macroSeedRefCounter);
|
|
675
|
+
return id;
|
|
676
|
+
}
|
|
677
|
+
function serializeMacroSeed(_key, value) {
|
|
678
|
+
switch (typeof value) {
|
|
679
|
+
case "function": return "\0fn:" + macroSeedRefId(value);
|
|
680
|
+
case "bigint": return "\0bigint:" + value.toString();
|
|
681
|
+
case "symbol": return "\0sym:" + String(value);
|
|
682
|
+
case "undefined": return "\0undefined";
|
|
683
|
+
default: return value;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
//#endregion
|
|
688
|
+
exports.bytes = bytes;
|
|
689
|
+
exports.clearFlattenChainMemo = clearFlattenChainMemo;
|
|
690
|
+
exports.cloneHook = cloneHook;
|
|
691
|
+
exports.clonePlainDecorators = clonePlainDecorators;
|
|
692
|
+
exports.clonePlainDeep = clonePlainDeep;
|
|
693
|
+
exports.coalesceSchemas = coalesceSchemas;
|
|
694
|
+
exports.compactBeforeHandleConflicts = compactBeforeHandleConflicts;
|
|
695
|
+
exports.compactBeforeHandlePrefix = compactBeforeHandlePrefix;
|
|
696
|
+
exports.constantTimeEqual = constantTimeEqual;
|
|
697
|
+
exports.createErrorEventHandler = createErrorEventHandler;
|
|
698
|
+
exports.deriveEntryFn = deriveEntryFn;
|
|
699
|
+
exports.eventProperties = eventProperties;
|
|
700
|
+
exports.evictOldestHalf = evictOldestHalf;
|
|
701
|
+
exports.flattenChain = flattenChain;
|
|
702
|
+
exports.flattenChainMemo = flattenChainMemo;
|
|
703
|
+
exports.flattenChainMemoReadonly = flattenChainMemoReadonly;
|
|
704
|
+
exports.fnOrigin = fnOrigin;
|
|
705
|
+
exports.fnv1a = fnv1a;
|
|
706
|
+
exports.form = form;
|
|
707
|
+
exports.formToFormData = formToFormData;
|
|
708
|
+
exports.getLoosePath = getLoosePath;
|
|
709
|
+
exports.guardNonPlainLeaves = guardNonPlainLeaves;
|
|
710
|
+
exports.hookToGuard = hookToGuard;
|
|
711
|
+
exports.invalidateMacroEpoch = invalidateMacroEpoch;
|
|
712
|
+
exports.isBlob = isBlob;
|
|
713
|
+
exports.isByteStream = isByteStream;
|
|
714
|
+
exports.isCompactBeforeHandleOnly = isCompactBeforeHandleOnly;
|
|
715
|
+
exports.isEmpty = isEmpty;
|
|
716
|
+
exports.isLocalScope = isLocalScope;
|
|
717
|
+
exports.isMapDeriveEntry = isMapDeriveEntry;
|
|
718
|
+
exports.isNotEmpty = isNotEmpty;
|
|
719
|
+
exports.isRecordNumber = isRecordNumber;
|
|
720
|
+
exports.joinPath = joinPath;
|
|
721
|
+
exports.macroEpoch = macroEpoch;
|
|
722
|
+
exports.macroOrigin = macroOrigin;
|
|
723
|
+
exports.mapDeriveEntry = mapDeriveEntry;
|
|
724
|
+
exports.mergeArray = mergeArray;
|
|
725
|
+
exports.mergeDeep = mergeDeep;
|
|
726
|
+
exports.mergeHook = mergeHook;
|
|
727
|
+
exports.mergeResponse = mergeResponse;
|
|
728
|
+
exports.nullObject = nullObject;
|
|
729
|
+
exports.prefix = prefix;
|
|
730
|
+
exports.pushField = pushField;
|
|
731
|
+
exports.redirect = redirect;
|
|
732
|
+
exports.replaceUrlPath = replaceUrlPath;
|
|
733
|
+
exports.requestId = requestId;
|
|
734
|
+
exports.schemaProperties = schemaProperties;
|
|
735
|
+
exports.serializeMacroSeed = serializeMacroSeed;
|
|
736
|
+
exports.sse = sse;
|