elysia 1.4.28 → 2.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_virtual/_rolldown/runtime.js +29 -0
- package/dist/_virtual/_rolldown/runtime.mjs +38 -0
- package/dist/adapter/bun/index.d.ts +7 -6
- package/dist/adapter/bun/index.js +219 -380
- package/dist/adapter/bun/index.mjs +217 -382
- package/dist/adapter/constants.d.ts +6 -0
- package/dist/adapter/constants.js +10 -0
- package/dist/adapter/constants.mjs +9 -0
- package/dist/adapter/default-headers.d.ts +4 -0
- package/dist/adapter/default-headers.js +7 -0
- package/dist/adapter/default-headers.mjs +5 -0
- package/dist/adapter/index.d.ts +8 -1
- package/dist/adapter/index.js +7 -14
- package/dist/adapter/index.mjs +5 -0
- package/dist/adapter/origin.d.ts +63 -0
- package/dist/adapter/origin.js +64 -0
- package/dist/adapter/origin.mjs +62 -0
- package/dist/adapter/response-ownership.d.ts +5 -0
- package/dist/adapter/response-ownership.js +13 -0
- package/dist/adapter/response-ownership.mjs +10 -0
- package/dist/adapter/skip-clone.d.ts +4 -0
- package/dist/adapter/skip-clone.js +7 -0
- package/dist/adapter/skip-clone.mjs +5 -0
- package/dist/adapter/types.d.ts +50 -125
- package/dist/adapter/types.js +1 -14
- package/dist/adapter/types.mjs +1 -0
- package/dist/adapter/utils.d.ts +47 -19
- package/dist/adapter/utils.js +561 -311
- package/dist/adapter/utils.mjs +551 -283
- package/dist/adapter/web-standard/handler.d.ts +11 -9
- package/dist/adapter/web-standard/handler.js +146 -415
- package/dist/adapter/web-standard/handler.mjs +144 -400
- package/dist/adapter/web-standard/index.d.ts +5 -2
- package/dist/adapter/web-standard/index.js +68 -161
- package/dist/adapter/web-standard/index.mjs +68 -146
- package/dist/adapter/web-standard/utils.d.ts +4 -0
- package/dist/adapter/web-standard/utils.js +153 -0
- package/dist/adapter/web-standard/utils.mjs +152 -0
- package/dist/base.d.ts +898 -0
- package/dist/base.js +1564 -0
- package/dist/base.mjs +1561 -0
- package/dist/compile/analysis-cache.d.ts +6 -0
- package/dist/compile/analysis-cache.js +12 -0
- package/dist/compile/analysis-cache.mjs +11 -0
- package/dist/compile/aot-capture.d.ts +24 -0
- package/dist/compile/aot-capture.js +376 -0
- package/dist/compile/aot-capture.mjs +365 -0
- package/dist/compile/aot-emit.d.ts +29 -0
- package/dist/compile/aot-emit.js +107 -0
- package/dist/compile/aot-emit.mjs +101 -0
- package/dist/compile/aot-reconstruct.d.ts +30 -0
- package/dist/compile/aot-reconstruct.js +156 -0
- package/dist/compile/aot-reconstruct.mjs +147 -0
- package/dist/compile/aot.d.ts +287 -0
- package/dist/compile/aot.js +220 -0
- package/dist/compile/aot.mjs +200 -0
- package/dist/compile/handler/descriptor.d.ts +77 -0
- package/dist/compile/handler/descriptor.js +199 -0
- package/dist/compile/handler/descriptor.mjs +194 -0
- package/dist/compile/handler/frozen-validator.d.ts +39 -0
- package/dist/compile/handler/frozen-validator.js +319 -0
- package/dist/compile/handler/frozen-validator.mjs +313 -0
- package/dist/compile/handler/index.d.ts +19 -0
- package/dist/compile/handler/index.js +379 -0
- package/dist/compile/handler/index.mjs +371 -0
- package/dist/compile/handler/jit.d.ts +43 -0
- package/dist/compile/handler/jit.js +536 -0
- package/dist/compile/handler/jit.mjs +532 -0
- package/dist/compile/handler/params.d.ts +28 -0
- package/dist/compile/handler/params.js +78 -0
- package/dist/compile/handler/params.mjs +76 -0
- package/dist/compile/handler/reconstruct.d.ts +12 -0
- package/dist/compile/handler/reconstruct.js +50 -0
- package/dist/compile/handler/reconstruct.mjs +49 -0
- package/dist/compile/handler/utils.d.ts +45 -0
- package/dist/compile/handler/utils.js +514 -0
- package/dist/compile/handler/utils.mjs +498 -0
- package/dist/compile/jit-probe.d.ts +15 -0
- package/dist/compile/jit-probe.js +28 -0
- package/dist/compile/jit-probe.mjs +26 -0
- package/dist/compile/lexer.d.ts +7 -0
- package/dist/compile/lexer.js +53 -0
- package/dist/compile/lexer.mjs +48 -0
- package/dist/compile/utils.d.ts +8 -0
- package/dist/compile/utils.js +23 -0
- package/dist/compile/utils.mjs +19 -0
- package/dist/compiled.d.ts +17 -0
- package/dist/compiled.js +20 -0
- package/dist/compiled.mjs +16 -0
- package/dist/constants.d.ts +137 -0
- package/dist/constants.js +96 -0
- package/dist/constants.mjs +88 -0
- package/dist/context.d.ts +86 -129
- package/dist/context.js +110 -13
- package/dist/context.mjs +108 -0
- package/dist/cookie/config.d.ts +31 -0
- package/dist/cookie/config.js +98 -0
- package/dist/cookie/config.mjs +95 -0
- package/dist/cookie/cookie.d.ts +26 -0
- package/dist/cookie/cookie.js +105 -0
- package/dist/cookie/cookie.mjs +104 -0
- package/dist/cookie/crypto.d.ts +20 -0
- package/dist/cookie/crypto.js +168 -0
- package/dist/cookie/crypto.mjs +151 -0
- package/dist/cookie/error.d.ts +17 -0
- package/dist/cookie/error.js +25 -0
- package/dist/cookie/error.mjs +24 -0
- package/dist/cookie/index.d.ts +7 -0
- package/dist/cookie/index.js +13 -0
- package/dist/cookie/index.mjs +7 -0
- package/dist/cookie/lib.d.ts +7 -0
- package/dist/cookie/lib.js +76 -0
- package/dist/cookie/lib.mjs +74 -0
- package/dist/cookie/serialize.d.ts +6 -0
- package/dist/cookie/serialize.js +32 -0
- package/dist/cookie/serialize.mjs +31 -0
- package/dist/cookie/types.d.ts +113 -0
- package/dist/cookie/types.js +1 -0
- package/dist/cookie/types.mjs +1 -0
- package/dist/cookie/utils.d.ts +25 -0
- package/dist/cookie/utils.js +182 -0
- package/dist/cookie/utils.mjs +171 -0
- package/dist/error.d.ts +226 -188
- package/dist/error.js +519 -357
- package/dist/error.mjs +503 -327
- package/dist/generation.d.ts +30 -0
- package/dist/generation.js +23 -0
- package/dist/generation.mjs +17 -0
- package/dist/handler/error.d.ts +7 -0
- package/dist/handler/error.js +105 -0
- package/dist/handler/error.mjs +104 -0
- package/dist/handler/fetch.d.ts +8 -0
- package/dist/handler/fetch.js +371 -0
- package/dist/handler/fetch.mjs +367 -0
- package/dist/handler/index.d.ts +2 -0
- package/dist/handler/index.js +5 -0
- package/dist/handler/index.mjs +3 -0
- package/dist/handler/utils.d.ts +15 -0
- package/dist/handler/utils.js +48 -0
- package/dist/handler/utils.mjs +42 -0
- package/dist/index.d.ts +23 -2198
- package/dist/index.js +62 -1948
- package/dist/index.mjs +20 -1986
- package/dist/memory.d.ts +4 -0
- package/dist/memory.js +17 -0
- package/dist/memory.mjs +16 -0
- package/dist/package.js +11 -0
- package/dist/package.mjs +5 -0
- package/dist/parse-query.d.ts +7 -9
- package/dist/parse-query.js +154 -164
- package/dist/parse-query.mjs +150 -133
- package/dist/plugin/aot/bun.d.ts +26 -0
- package/dist/plugin/aot/bun.js +35 -0
- package/dist/plugin/aot/bun.mjs +34 -0
- package/dist/plugin/aot/core.d.ts +291 -0
- package/dist/plugin/aot/core.js +505 -0
- package/dist/plugin/aot/core.mjs +481 -0
- package/dist/plugin/aot/esbuild.d.ts +28 -0
- package/dist/plugin/aot/esbuild.js +48 -0
- package/dist/plugin/aot/esbuild.mjs +46 -0
- package/dist/plugin/aot/hooks.d.ts +28 -0
- package/dist/plugin/aot/hooks.js +114 -0
- package/dist/plugin/aot/hooks.mjs +112 -0
- package/dist/plugin/aot/rspack-loader.d.ts +23 -0
- package/dist/plugin/aot/rspack-loader.js +44 -0
- package/dist/plugin/aot/rspack-loader.mjs +40 -0
- package/dist/plugin/aot/rspack.d.ts +23 -0
- package/dist/plugin/aot/rspack.js +85 -0
- package/dist/plugin/aot/rspack.mjs +82 -0
- package/dist/plugin/aot/source.d.ts +60 -0
- package/dist/plugin/aot/source.js +422 -0
- package/dist/plugin/aot/source.mjs +418 -0
- package/dist/plugin/aot/treeshake.d.ts +4 -0
- package/dist/plugin/aot/treeshake.js +95 -0
- package/dist/plugin/aot/treeshake.mjs +94 -0
- package/dist/plugin/aot/unplugin.d.ts +50 -0
- package/dist/plugin/aot/unplugin.js +64 -0
- package/dist/plugin/aot/unplugin.mjs +62 -0
- package/dist/plugin/aot/vite.d.ts +30 -0
- package/dist/plugin/aot/vite.js +34 -0
- package/dist/plugin/aot/vite.mjs +33 -0
- package/dist/plugin/aot/worker.d.ts +1 -0
- package/dist/plugin/aot/worker.js +28 -0
- package/dist/plugin/aot/worker.mjs +27 -0
- package/dist/plugin/auto-head.d.ts +6 -0
- package/dist/plugin/auto-head.js +38 -0
- package/dist/plugin/auto-head.mjs +36 -0
- package/dist/plugin/trace.d.ts +10 -0
- package/dist/plugin/trace.js +39 -0
- package/dist/plugin/trace.mjs +36 -0
- package/dist/plugin/websocket.d.ts +6 -0
- package/dist/plugin/websocket.js +61 -0
- package/dist/plugin/websocket.mjs +60 -0
- package/dist/route-table.d.ts +28 -0
- package/dist/route-table.js +64 -0
- package/dist/route-table.mjs +61 -0
- package/dist/schema-snapshot.d.ts +9 -0
- package/dist/schema-snapshot.js +271 -0
- package/dist/schema-snapshot.mjs +269 -0
- package/dist/sucrose.d.ts +28 -63
- package/dist/sucrose.js +814 -306
- package/dist/sucrose.mjs +805 -274
- package/dist/trace.d.ts +145 -130
- package/dist/trace.js +387 -135
- package/dist/trace.mjs +385 -113
- package/dist/type/bridge-live.d.ts +15 -0
- package/dist/type/bridge-live.js +39 -0
- package/dist/type/bridge-live.mjs +17 -0
- package/dist/type/bridge.d.ts +56 -0
- package/dist/type/bridge.js +180 -0
- package/dist/type/bridge.mjs +63 -0
- package/dist/type/coerce-plan.d.ts +38 -0
- package/dist/type/coerce-plan.js +107 -0
- package/dist/type/coerce-plan.mjs +98 -0
- package/dist/type/coerce.d.ts +43 -0
- package/dist/type/coerce.js +351 -0
- package/dist/type/coerce.mjs +339 -0
- package/dist/type/compat.d.ts +8 -0
- package/dist/type/compat.js +46 -0
- package/dist/type/compat.mjs +44 -0
- package/dist/type/constants.d.ts +25 -0
- package/dist/type/constants.js +36 -0
- package/dist/type/constants.mjs +32 -0
- package/dist/type/elysia/accelerate.d.ts +6 -0
- package/dist/type/elysia/accelerate.js +12 -0
- package/dist/type/elysia/accelerate.mjs +10 -0
- package/dist/type/elysia/array-buffer.d.ts +6 -0
- package/dist/type/elysia/array-buffer.js +27 -0
- package/dist/type/elysia/array-buffer.mjs +25 -0
- package/dist/type/elysia/array-string.d.ts +7 -0
- package/dist/type/elysia/array-string.js +28 -0
- package/dist/type/elysia/array-string.mjs +26 -0
- package/dist/type/elysia/array.d.ts +6 -0
- package/dist/type/elysia/array.js +32 -0
- package/dist/type/elysia/array.mjs +31 -0
- package/dist/type/elysia/boolean-string.d.ts +6 -0
- package/dist/type/elysia/boolean-string.js +24 -0
- package/dist/type/elysia/boolean-string.mjs +22 -0
- package/dist/type/elysia/boolean.d.ts +6 -0
- package/dist/type/elysia/boolean.js +20 -0
- package/dist/type/elysia/boolean.mjs +18 -0
- package/dist/type/elysia/cookie.d.ts +15 -0
- package/dist/type/elysia/cookie.js +51 -0
- package/dist/type/elysia/cookie.mjs +50 -0
- package/dist/type/elysia/date.d.ts +7 -0
- package/dist/type/elysia/date.js +98 -0
- package/dist/type/elysia/date.mjs +96 -0
- package/dist/type/elysia/file-type.d.ts +25 -0
- package/dist/type/elysia/file-type.js +81 -0
- package/dist/type/elysia/file-type.mjs +71 -0
- package/dist/type/elysia/file.d.ts +9 -0
- package/dist/type/elysia/file.js +64 -0
- package/dist/type/elysia/file.mjs +48 -0
- package/dist/type/elysia/files.d.ts +8 -0
- package/dist/type/elysia/files.js +45 -0
- package/dist/type/elysia/files.mjs +43 -0
- package/dist/type/elysia/form.d.ts +8 -0
- package/dist/type/elysia/form.js +17 -0
- package/dist/type/elysia/form.mjs +15 -0
- package/dist/type/elysia/integer-string.d.ts +7 -0
- package/dist/type/elysia/integer-string.js +40 -0
- package/dist/type/elysia/integer-string.mjs +38 -0
- package/dist/type/elysia/integer.d.ts +6 -0
- package/dist/type/elysia/integer.js +20 -0
- package/dist/type/elysia/integer.mjs +18 -0
- package/dist/type/elysia/intersect.d.ts +6 -0
- package/dist/type/elysia/intersect.js +20 -0
- package/dist/type/elysia/intersect.mjs +19 -0
- package/dist/type/elysia/maybe-empty.d.ts +7 -0
- package/dist/type/elysia/maybe-empty.js +21 -0
- package/dist/type/elysia/maybe-empty.mjs +19 -0
- package/dist/type/elysia/no-validate.d.ts +6 -0
- package/dist/type/elysia/no-validate.js +9 -0
- package/dist/type/elysia/no-validate.mjs +8 -0
- package/dist/type/elysia/nullable.d.ts +7 -0
- package/dist/type/elysia/nullable.js +15 -0
- package/dist/type/elysia/nullable.mjs +13 -0
- package/dist/type/elysia/number.d.ts +6 -0
- package/dist/type/elysia/number.js +20 -0
- package/dist/type/elysia/number.mjs +18 -0
- package/dist/type/elysia/numeric-enum.d.ts +11 -0
- package/dist/type/elysia/numeric-enum.js +26 -0
- package/dist/type/elysia/numeric-enum.mjs +24 -0
- package/dist/type/elysia/numeric.d.ts +7 -0
- package/dist/type/elysia/numeric.js +62 -0
- package/dist/type/elysia/numeric.mjs +60 -0
- package/dist/type/elysia/object-string.d.ts +7 -0
- package/dist/type/elysia/object-string.js +28 -0
- package/dist/type/elysia/object-string.mjs +26 -0
- package/dist/type/elysia/object.d.ts +6 -0
- package/dist/type/elysia/object.js +47 -0
- package/dist/type/elysia/object.mjs +46 -0
- package/dist/type/elysia/optional.d.ts +6 -0
- package/dist/type/elysia/optional.js +22 -0
- package/dist/type/elysia/optional.mjs +21 -0
- package/dist/type/elysia/string.d.ts +6 -0
- package/dist/type/elysia/string.js +43 -0
- package/dist/type/elysia/string.mjs +41 -0
- package/dist/type/elysia/uint8-array.d.ts +6 -0
- package/dist/type/elysia/uint8-array.js +27 -0
- package/dist/type/elysia/uint8-array.mjs +25 -0
- package/dist/type/elysia/union-enum.d.ts +8 -0
- package/dist/type/elysia/union-enum.js +31 -0
- package/dist/type/elysia/union-enum.mjs +29 -0
- package/dist/type/elysia/union.d.ts +6 -0
- package/dist/type/elysia/union.js +20 -0
- package/dist/type/elysia/union.mjs +19 -0
- package/dist/type/elysia/utils.d.ts +53 -0
- package/dist/type/elysia/utils.js +98 -0
- package/dist/type/elysia/utils.mjs +88 -0
- package/dist/type/exports.d.ts +36 -0
- package/dist/type/exports.js +68 -0
- package/dist/type/exports.mjs +36 -0
- package/dist/type/index.d.ts +13 -0
- package/dist/type/index.js +81 -0
- package/dist/type/index.mjs +68 -0
- package/dist/type/shared.d.ts +27 -0
- package/dist/type/shared.js +171 -0
- package/dist/type/shared.mjs +161 -0
- package/dist/type/types.d.ts +206 -0
- package/dist/type/types.js +1 -0
- package/dist/type/types.mjs +1 -0
- package/dist/type/utils.d.ts +7 -0
- package/dist/type/utils.js +43 -0
- package/dist/type/utils.mjs +41 -0
- package/dist/type/validator/clean-safe.d.ts +8 -0
- package/dist/type/validator/clean-safe.js +82 -0
- package/dist/type/validator/clean-safe.mjs +77 -0
- package/dist/type/validator/custom-error.d.ts +10 -0
- package/dist/type/validator/custom-error.js +191 -0
- package/dist/type/validator/custom-error.mjs +188 -0
- package/dist/type/validator/default-precompute.d.ts +26 -0
- package/dist/type/validator/default-precompute.js +432 -0
- package/dist/type/validator/default-precompute.mjs +421 -0
- package/dist/type/validator/exact-mirror.d.ts +7 -0
- package/dist/type/validator/exact-mirror.js +19 -0
- package/dist/type/validator/exact-mirror.mjs +15 -0
- package/dist/type/validator/frozen-check.d.ts +11 -0
- package/dist/type/validator/frozen-check.js +20 -0
- package/dist/type/validator/frozen-check.mjs +19 -0
- package/dist/type/validator/index.d.ts +32 -0
- package/dist/type/validator/index.js +657 -0
- package/dist/type/validator/index.mjs +651 -0
- package/dist/type/validator/string-codec-aot.d.ts +8 -0
- package/dist/type/validator/string-codec-aot.js +68 -0
- package/dist/type/validator/string-codec-aot.mjs +66 -0
- package/dist/type/validator/validator-cache.d.ts +26 -0
- package/dist/type/validator/validator-cache.js +247 -0
- package/dist/type/validator/validator-cache.mjs +242 -0
- package/dist/types.d.ts +938 -1235
- package/dist/types.js +1 -14
- package/dist/types.mjs +1 -0
- package/dist/universal/constants.d.ts +6 -0
- package/dist/universal/constants.js +19 -0
- package/dist/universal/constants.mjs +15 -0
- package/dist/universal/env.d.ts +5 -1
- package/dist/universal/env.js +12 -26
- package/dist/universal/env.mjs +10 -5
- package/dist/universal/file.d.ts +55 -86
- package/dist/universal/file.js +116 -157
- package/dist/universal/file.mjs +111 -132
- package/dist/universal/index.d.ts +5 -3
- package/dist/universal/index.js +8 -27
- package/dist/universal/index.mjs +4 -5
- package/dist/universal/is-production.d.ts +5 -0
- package/dist/universal/is-production.js +10 -0
- package/dist/universal/is-production.mjs +8 -0
- package/dist/universal/server.d.ts +318 -313
- package/dist/universal/server.js +1 -14
- package/dist/universal/server.mjs +1 -0
- package/dist/utils.d.ts +162 -191
- package/dist/utils.js +732 -693
- package/dist/utils.mjs +683 -631
- package/dist/validator/index.d.ts +63 -0
- package/dist/validator/index.js +299 -0
- package/dist/validator/index.mjs +296 -0
- package/dist/validator/route.d.ts +32 -0
- package/dist/validator/route.js +51 -0
- package/dist/validator/route.mjs +50 -0
- package/dist/ws/context.d.ts +49 -0
- package/dist/ws/context.js +152 -0
- package/dist/ws/context.mjs +150 -0
- package/dist/ws/index.d.ts +5 -77
- package/dist/ws/index.js +11 -180
- package/dist/ws/index.mjs +5 -157
- package/dist/ws/parser.d.ts +5 -0
- package/dist/ws/parser.js +69 -0
- package/dist/ws/parser.mjs +66 -0
- package/dist/ws/route.d.ts +16 -0
- package/dist/ws/route.js +560 -0
- package/dist/ws/route.mjs +554 -0
- package/dist/ws/types.d.ts +154 -57
- package/dist/ws/types.js +1 -14
- package/dist/ws/types.mjs +1 -0
- package/package.json +179 -120
- package/bunfig.toml +0 -2
- package/dist/adapter/bun/compose.d.ts +0 -3
- package/dist/adapter/bun/compose.js +0 -90
- package/dist/adapter/bun/compose.mjs +0 -74
- package/dist/adapter/bun/handler-native.d.ts +0 -3
- package/dist/adapter/bun/handler-native.js +0 -42
- package/dist/adapter/bun/handler-native.mjs +0 -22
- package/dist/adapter/bun/handler.d.ts +0 -7
- package/dist/adapter/bun/handler.js +0 -363
- package/dist/adapter/bun/handler.mjs +0 -346
- package/dist/adapter/cloudflare-worker/index.d.ts +0 -20
- package/dist/adapter/cloudflare-worker/index.js +0 -59
- package/dist/adapter/cloudflare-worker/index.mjs +0 -39
- package/dist/compose.d.ts +0 -30
- package/dist/compose.js +0 -1324
- package/dist/compose.mjs +0 -1336
- package/dist/cookies.d.ts +0 -158
- package/dist/cookies.js +0 -250
- package/dist/cookies.mjs +0 -221
- package/dist/dynamic-handle.d.ts +0 -15
- package/dist/dynamic-handle.js +0 -521
- package/dist/dynamic-handle.mjs +0 -509
- package/dist/formats.d.ts +0 -79
- package/dist/formats.js +0 -153
- package/dist/formats.mjs +0 -132
- package/dist/manifest.d.ts +0 -0
- package/dist/manifest.js +0 -1
- package/dist/manifest.mjs +0 -0
- package/dist/replace-schema.d.ts +0 -60
- package/dist/replace-schema.js +0 -140
- package/dist/replace-schema.mjs +0 -115
- package/dist/schema.d.ts +0 -107
- package/dist/schema.js +0 -833
- package/dist/schema.mjs +0 -814
- package/dist/type-system/format.d.ts +0 -55
- package/dist/type-system/format.js +0 -197
- package/dist/type-system/format.mjs +0 -175
- package/dist/type-system/index.d.ts +0 -45
- package/dist/type-system/index.js +0 -406
- package/dist/type-system/index.mjs +0 -394
- package/dist/type-system/types.d.ts +0 -155
- package/dist/type-system/types.js +0 -14
- package/dist/type-system/types.mjs +0 -0
- package/dist/type-system/utils.d.ts +0 -62
- package/dist/type-system/utils.js +0 -141
- package/dist/type-system/utils.mjs +0 -111
- package/dist/universal/request.d.ts +0 -29
- package/dist/universal/request.js +0 -126
- package/dist/universal/request.mjs +0 -105
- package/dist/universal/types.d.ts +0 -124
- package/dist/universal/types.js +0 -41
- package/dist/universal/types.mjs +0 -19
- package/dist/universal/utils.d.ts +0 -3
- package/dist/universal/utils.js +0 -41
- package/dist/universal/utils.mjs +0 -18
- package/dist/ws/bun.d.ts +0 -419
- package/dist/ws/bun.js +0 -14
- package/dist/ws/bun.mjs +0 -0
- package/knip.json +0 -22
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//#region src/cookie/crypto.d.ts
|
|
2
|
+
declare const hmacProvider: 'bun' | 'node' | 'subtle';
|
|
3
|
+
declare const hasSyncHmac: boolean;
|
|
4
|
+
declare const signCookieBun: (val: string, secret: string) => string;
|
|
5
|
+
declare const signCookieNode: (val: string, secret: string) => string;
|
|
6
|
+
declare const signCookieSyncImpl: (val: string, secret: string) => string;
|
|
7
|
+
declare const keyCache: Map<string, Promise<CryptoKey>>;
|
|
8
|
+
declare function importSecretKey(secret: string): Promise<CryptoKey>;
|
|
9
|
+
declare function signCookieSubtle(val: string, secret: string): Promise<string>;
|
|
10
|
+
declare function signCookie(val: string, secret: string | null): Promise<string>;
|
|
11
|
+
declare function signCookieSync(val: string, secret: string | null): string;
|
|
12
|
+
declare function unsignCookie(input: string, secret: string | null): Promise<string | false>;
|
|
13
|
+
declare function unsignCookieSync(input: string, secret: string | null): string | false;
|
|
14
|
+
declare function unsignWithSecretsSync(name: string, value: unknown, secrets: string | null | (string | null)[] | undefined): string;
|
|
15
|
+
declare function unsignWithSecrets(name: string, value: unknown, secrets: string | null | (string | null)[] | undefined): Promise<string>;
|
|
16
|
+
declare const rawJsonValue: WeakMap<object, string>;
|
|
17
|
+
declare function maybeJsonDecode(value: unknown): any;
|
|
18
|
+
declare function resolvePendingCookie(entry: Record<string, any>, name: string): void;
|
|
19
|
+
//#endregion
|
|
20
|
+
export { hasSyncHmac, hmacProvider, importSecretKey, keyCache, maybeJsonDecode, rawJsonValue, resolvePendingCookie, signCookie, signCookieBun, signCookieNode, signCookieSubtle, signCookieSync, signCookieSyncImpl, unsignCookie, unsignCookieSync, unsignWithSecrets, unsignWithSecretsSync };
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_utils = require('../utils.js');
|
|
3
|
+
const require_cookie_error = require('./error.js');
|
|
4
|
+
|
|
5
|
+
//#region src/cookie/crypto.ts
|
|
6
|
+
const removeTrailingEquals = /=+$/g;
|
|
7
|
+
const algorithm = {
|
|
8
|
+
name: "HMAC",
|
|
9
|
+
hash: "SHA-256"
|
|
10
|
+
};
|
|
11
|
+
const encoder = new TextEncoder();
|
|
12
|
+
let _nodeCrypto;
|
|
13
|
+
let _nodeCryptoResolved = false;
|
|
14
|
+
function nodeCrypto() {
|
|
15
|
+
if (!_nodeCryptoResolved) {
|
|
16
|
+
_nodeCryptoResolved = true;
|
|
17
|
+
try {
|
|
18
|
+
_nodeCrypto = globalThis.process?.getBuiltinModule?.("node:crypto");
|
|
19
|
+
} catch {}
|
|
20
|
+
}
|
|
21
|
+
return _nodeCrypto;
|
|
22
|
+
}
|
|
23
|
+
const HMAC_PROBE_DIGEST = "bzs6y9cVmkYub8fplSKaOuuqMqJlDwhMypFT/jSdCEk=";
|
|
24
|
+
const bunCryptoHasher = (() => {
|
|
25
|
+
const hasher = globalThis.Bun?.CryptoHasher;
|
|
26
|
+
if (typeof hasher !== "function") return void 0;
|
|
27
|
+
try {
|
|
28
|
+
return new hasher("sha256", "elysia").update("probe").digest("base64") === HMAC_PROBE_DIGEST ? hasher : void 0;
|
|
29
|
+
} catch {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
})();
|
|
33
|
+
const hmacProvider = bunCryptoHasher ? "bun" : typeof nodeCrypto()?.createHmac === "function" ? "node" : "subtle";
|
|
34
|
+
const hasSyncHmac = hmacProvider !== "subtle";
|
|
35
|
+
function coerceValue(val) {
|
|
36
|
+
if (typeof val === "object") return JSON.stringify(val);
|
|
37
|
+
if (typeof val !== "string") return val + "";
|
|
38
|
+
return val;
|
|
39
|
+
}
|
|
40
|
+
const signCookieBun = (val, secret) => `${val}.${new bunCryptoHasher("sha256", secret).update(val).digest("base64").replace(removeTrailingEquals, "")}`;
|
|
41
|
+
const signCookieNode = (val, secret) => `${val}.${nodeCrypto().createHmac("sha256", secret).update(val).digest("base64").replace(removeTrailingEquals, "")}`;
|
|
42
|
+
const signCookieSyncImpl = hmacProvider === "bun" ? signCookieBun : signCookieNode;
|
|
43
|
+
const keyCache = /* @__PURE__ */ new Map();
|
|
44
|
+
function importSecretKey(secret) {
|
|
45
|
+
let key = keyCache.get(secret);
|
|
46
|
+
if (key) {
|
|
47
|
+
if (keyCache.size >= 256) {
|
|
48
|
+
keyCache.delete(secret);
|
|
49
|
+
keyCache.set(secret, key);
|
|
50
|
+
}
|
|
51
|
+
return key;
|
|
52
|
+
}
|
|
53
|
+
if (keyCache.size >= 256) require_utils.evictOldestHalf(keyCache);
|
|
54
|
+
key = crypto.subtle.importKey("raw", encoder.encode(secret), algorithm, false, ["sign"]);
|
|
55
|
+
key.catch(() => {
|
|
56
|
+
if (keyCache.get(secret) === key) keyCache.delete(secret);
|
|
57
|
+
});
|
|
58
|
+
keyCache.set(secret, key);
|
|
59
|
+
return key;
|
|
60
|
+
}
|
|
61
|
+
async function signCookieSubtle(val, secret) {
|
|
62
|
+
const hmacBuffer = await crypto.subtle.sign("HMAC", await importSecretKey(secret), encoder.encode(val));
|
|
63
|
+
return `${val}.${btoa(String.fromCharCode(...new Uint8Array(hmacBuffer))).replace(removeTrailingEquals, "")}`;
|
|
64
|
+
}
|
|
65
|
+
async function signCookie(val, secret) {
|
|
66
|
+
val = coerceValue(val);
|
|
67
|
+
if (secret === null || secret === void 0) throw new TypeError("Secret key must be provided");
|
|
68
|
+
if (hasSyncHmac) return signCookieSyncImpl(val, secret);
|
|
69
|
+
return signCookieSubtle(val, secret);
|
|
70
|
+
}
|
|
71
|
+
function signCookieSync(val, secret) {
|
|
72
|
+
val = coerceValue(val);
|
|
73
|
+
if (secret === null || secret === void 0) throw new TypeError("Secret key must be provided");
|
|
74
|
+
if (!hasSyncHmac) throw new Error("signCookieSync called without a sync HMAC available");
|
|
75
|
+
return signCookieSyncImpl(val, secret);
|
|
76
|
+
}
|
|
77
|
+
async function unsignCookie(input, secret) {
|
|
78
|
+
if (typeof input !== "string") throw new TypeError("Signed cookie string must be provided.");
|
|
79
|
+
const dot = input.lastIndexOf(".");
|
|
80
|
+
if (dot === -1) {
|
|
81
|
+
if (secret === null) return input;
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
const tentativeValue = input.slice(0, dot);
|
|
85
|
+
if (secret === null) return false;
|
|
86
|
+
return require_utils.constantTimeEqual(await signCookie(tentativeValue, secret), input) ? tentativeValue : false;
|
|
87
|
+
}
|
|
88
|
+
function unsignCookieSync(input, secret) {
|
|
89
|
+
if (typeof input !== "string") throw new TypeError("Signed cookie string must be provided.");
|
|
90
|
+
const dot = input.lastIndexOf(".");
|
|
91
|
+
if (dot === -1) {
|
|
92
|
+
if (secret === null) return input;
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
const tentativeValue = input.slice(0, dot);
|
|
96
|
+
if (secret === null) return false;
|
|
97
|
+
return require_utils.constantTimeEqual(signCookieSync(tentativeValue, secret), input) ? tentativeValue : false;
|
|
98
|
+
}
|
|
99
|
+
function unsignWithSecretsSync(name, value, secrets) {
|
|
100
|
+
if (typeof value !== "string") throw require_cookie_error.InvalidCookie.signature(name);
|
|
101
|
+
if (typeof secrets === "string") {
|
|
102
|
+
const temp = unsignCookieSync(value, secrets);
|
|
103
|
+
if (temp === false) throw require_cookie_error.InvalidCookie.signature(name);
|
|
104
|
+
return temp;
|
|
105
|
+
}
|
|
106
|
+
if (Array.isArray(secrets)) for (let i = 0; i < secrets.length; i++) {
|
|
107
|
+
const temp = unsignCookieSync(value, secrets[i]);
|
|
108
|
+
if (temp !== false) return temp;
|
|
109
|
+
}
|
|
110
|
+
throw require_cookie_error.InvalidCookie.signature(name);
|
|
111
|
+
}
|
|
112
|
+
async function unsignWithSecrets(name, value, secrets) {
|
|
113
|
+
if (typeof value !== "string") throw require_cookie_error.InvalidCookie.signature(name);
|
|
114
|
+
if (typeof secrets === "string") {
|
|
115
|
+
const temp = await unsignCookie(value, secrets);
|
|
116
|
+
if (temp === false) throw require_cookie_error.InvalidCookie.signature(name);
|
|
117
|
+
return temp;
|
|
118
|
+
}
|
|
119
|
+
if (Array.isArray(secrets)) for (let i = 0; i < secrets.length; i++) {
|
|
120
|
+
const temp = await unsignCookie(value, secrets[i]);
|
|
121
|
+
if (temp !== false) return temp;
|
|
122
|
+
}
|
|
123
|
+
throw require_cookie_error.InvalidCookie.signature(name);
|
|
124
|
+
}
|
|
125
|
+
const rawJsonValue = /* @__PURE__ */ new WeakMap();
|
|
126
|
+
function maybeJsonDecode(value) {
|
|
127
|
+
if (typeof value === "string" && value.length > 1) {
|
|
128
|
+
const starts = value.charCodeAt(0);
|
|
129
|
+
const ends = value.charCodeAt(value.length - 1);
|
|
130
|
+
if (starts === 123 && ends === 125 || starts === 91 && ends === 93) try {
|
|
131
|
+
const parsed = JSON.parse(value);
|
|
132
|
+
if (parsed !== null && typeof parsed === "object") rawJsonValue.set(parsed, value);
|
|
133
|
+
return parsed;
|
|
134
|
+
} catch {}
|
|
135
|
+
}
|
|
136
|
+
return value;
|
|
137
|
+
}
|
|
138
|
+
function resolvePendingCookie(entry, name) {
|
|
139
|
+
const value = entry.value;
|
|
140
|
+
if (typeof value !== "string") throw require_cookie_error.InvalidCookie.signature(name);
|
|
141
|
+
if (!hasSyncHmac) throw new Error(`resolvePendingCookie called without sync HMAC. Unreachable under correct lane gating (cookie: "${name}")`);
|
|
142
|
+
const resolvedValue = maybeJsonDecode(unsignWithSecretsSync(name, value, entry["~unsign"]));
|
|
143
|
+
entry.value = resolvedValue;
|
|
144
|
+
if (resolvedValue !== null && typeof resolvedValue === "object") {
|
|
145
|
+
const raw = rawJsonValue.get(resolvedValue);
|
|
146
|
+
entry["~raw"] = raw !== void 0 ? raw : JSON.stringify(resolvedValue);
|
|
147
|
+
}
|
|
148
|
+
delete entry["~unsign"];
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
//#endregion
|
|
152
|
+
exports.hasSyncHmac = hasSyncHmac;
|
|
153
|
+
exports.hmacProvider = hmacProvider;
|
|
154
|
+
exports.importSecretKey = importSecretKey;
|
|
155
|
+
exports.keyCache = keyCache;
|
|
156
|
+
exports.maybeJsonDecode = maybeJsonDecode;
|
|
157
|
+
exports.rawJsonValue = rawJsonValue;
|
|
158
|
+
exports.resolvePendingCookie = resolvePendingCookie;
|
|
159
|
+
exports.signCookie = signCookie;
|
|
160
|
+
exports.signCookieBun = signCookieBun;
|
|
161
|
+
exports.signCookieNode = signCookieNode;
|
|
162
|
+
exports.signCookieSubtle = signCookieSubtle;
|
|
163
|
+
exports.signCookieSync = signCookieSync;
|
|
164
|
+
exports.signCookieSyncImpl = signCookieSyncImpl;
|
|
165
|
+
exports.unsignCookie = unsignCookie;
|
|
166
|
+
exports.unsignCookieSync = unsignCookieSync;
|
|
167
|
+
exports.unsignWithSecrets = unsignWithSecrets;
|
|
168
|
+
exports.unsignWithSecretsSync = unsignWithSecretsSync;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { constantTimeEqual, evictOldestHalf } from "../utils.mjs";
|
|
2
|
+
import { InvalidCookie } from "./error.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/cookie/crypto.ts
|
|
5
|
+
const removeTrailingEquals = /=+$/g;
|
|
6
|
+
const algorithm = {
|
|
7
|
+
name: "HMAC",
|
|
8
|
+
hash: "SHA-256"
|
|
9
|
+
};
|
|
10
|
+
const encoder = new TextEncoder();
|
|
11
|
+
let _nodeCrypto;
|
|
12
|
+
let _nodeCryptoResolved = false;
|
|
13
|
+
function nodeCrypto() {
|
|
14
|
+
if (!_nodeCryptoResolved) {
|
|
15
|
+
_nodeCryptoResolved = true;
|
|
16
|
+
try {
|
|
17
|
+
_nodeCrypto = globalThis.process?.getBuiltinModule?.("node:crypto");
|
|
18
|
+
} catch {}
|
|
19
|
+
}
|
|
20
|
+
return _nodeCrypto;
|
|
21
|
+
}
|
|
22
|
+
const HMAC_PROBE_DIGEST = "bzs6y9cVmkYub8fplSKaOuuqMqJlDwhMypFT/jSdCEk=";
|
|
23
|
+
const bunCryptoHasher = (() => {
|
|
24
|
+
const hasher = globalThis.Bun?.CryptoHasher;
|
|
25
|
+
if (typeof hasher !== "function") return void 0;
|
|
26
|
+
try {
|
|
27
|
+
return new hasher("sha256", "elysia").update("probe").digest("base64") === HMAC_PROBE_DIGEST ? hasher : void 0;
|
|
28
|
+
} catch {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
})();
|
|
32
|
+
const hmacProvider = bunCryptoHasher ? "bun" : typeof nodeCrypto()?.createHmac === "function" ? "node" : "subtle";
|
|
33
|
+
const hasSyncHmac = hmacProvider !== "subtle";
|
|
34
|
+
function coerceValue(val) {
|
|
35
|
+
if (typeof val === "object") return JSON.stringify(val);
|
|
36
|
+
if (typeof val !== "string") return val + "";
|
|
37
|
+
return val;
|
|
38
|
+
}
|
|
39
|
+
const signCookieBun = (val, secret) => `${val}.${new bunCryptoHasher("sha256", secret).update(val).digest("base64").replace(removeTrailingEquals, "")}`;
|
|
40
|
+
const signCookieNode = (val, secret) => `${val}.${nodeCrypto().createHmac("sha256", secret).update(val).digest("base64").replace(removeTrailingEquals, "")}`;
|
|
41
|
+
const signCookieSyncImpl = hmacProvider === "bun" ? signCookieBun : signCookieNode;
|
|
42
|
+
const keyCache = /* @__PURE__ */ new Map();
|
|
43
|
+
function importSecretKey(secret) {
|
|
44
|
+
let key = keyCache.get(secret);
|
|
45
|
+
if (key) {
|
|
46
|
+
if (keyCache.size >= 256) {
|
|
47
|
+
keyCache.delete(secret);
|
|
48
|
+
keyCache.set(secret, key);
|
|
49
|
+
}
|
|
50
|
+
return key;
|
|
51
|
+
}
|
|
52
|
+
if (keyCache.size >= 256) evictOldestHalf(keyCache);
|
|
53
|
+
key = crypto.subtle.importKey("raw", encoder.encode(secret), algorithm, false, ["sign"]);
|
|
54
|
+
key.catch(() => {
|
|
55
|
+
if (keyCache.get(secret) === key) keyCache.delete(secret);
|
|
56
|
+
});
|
|
57
|
+
keyCache.set(secret, key);
|
|
58
|
+
return key;
|
|
59
|
+
}
|
|
60
|
+
async function signCookieSubtle(val, secret) {
|
|
61
|
+
const hmacBuffer = await crypto.subtle.sign("HMAC", await importSecretKey(secret), encoder.encode(val));
|
|
62
|
+
return `${val}.${btoa(String.fromCharCode(...new Uint8Array(hmacBuffer))).replace(removeTrailingEquals, "")}`;
|
|
63
|
+
}
|
|
64
|
+
async function signCookie(val, secret) {
|
|
65
|
+
val = coerceValue(val);
|
|
66
|
+
if (secret === null || secret === void 0) throw new TypeError("Secret key must be provided");
|
|
67
|
+
if (hasSyncHmac) return signCookieSyncImpl(val, secret);
|
|
68
|
+
return signCookieSubtle(val, secret);
|
|
69
|
+
}
|
|
70
|
+
function signCookieSync(val, secret) {
|
|
71
|
+
val = coerceValue(val);
|
|
72
|
+
if (secret === null || secret === void 0) throw new TypeError("Secret key must be provided");
|
|
73
|
+
if (!hasSyncHmac) throw new Error("signCookieSync called without a sync HMAC available");
|
|
74
|
+
return signCookieSyncImpl(val, secret);
|
|
75
|
+
}
|
|
76
|
+
async function unsignCookie(input, secret) {
|
|
77
|
+
if (typeof input !== "string") throw new TypeError("Signed cookie string must be provided.");
|
|
78
|
+
const dot = input.lastIndexOf(".");
|
|
79
|
+
if (dot === -1) {
|
|
80
|
+
if (secret === null) return input;
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
const tentativeValue = input.slice(0, dot);
|
|
84
|
+
if (secret === null) return false;
|
|
85
|
+
return constantTimeEqual(await signCookie(tentativeValue, secret), input) ? tentativeValue : false;
|
|
86
|
+
}
|
|
87
|
+
function unsignCookieSync(input, secret) {
|
|
88
|
+
if (typeof input !== "string") throw new TypeError("Signed cookie string must be provided.");
|
|
89
|
+
const dot = input.lastIndexOf(".");
|
|
90
|
+
if (dot === -1) {
|
|
91
|
+
if (secret === null) return input;
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
const tentativeValue = input.slice(0, dot);
|
|
95
|
+
if (secret === null) return false;
|
|
96
|
+
return constantTimeEqual(signCookieSync(tentativeValue, secret), input) ? tentativeValue : false;
|
|
97
|
+
}
|
|
98
|
+
function unsignWithSecretsSync(name, value, secrets) {
|
|
99
|
+
if (typeof value !== "string") throw InvalidCookie.signature(name);
|
|
100
|
+
if (typeof secrets === "string") {
|
|
101
|
+
const temp = unsignCookieSync(value, secrets);
|
|
102
|
+
if (temp === false) throw InvalidCookie.signature(name);
|
|
103
|
+
return temp;
|
|
104
|
+
}
|
|
105
|
+
if (Array.isArray(secrets)) for (let i = 0; i < secrets.length; i++) {
|
|
106
|
+
const temp = unsignCookieSync(value, secrets[i]);
|
|
107
|
+
if (temp !== false) return temp;
|
|
108
|
+
}
|
|
109
|
+
throw InvalidCookie.signature(name);
|
|
110
|
+
}
|
|
111
|
+
async function unsignWithSecrets(name, value, secrets) {
|
|
112
|
+
if (typeof value !== "string") throw InvalidCookie.signature(name);
|
|
113
|
+
if (typeof secrets === "string") {
|
|
114
|
+
const temp = await unsignCookie(value, secrets);
|
|
115
|
+
if (temp === false) throw InvalidCookie.signature(name);
|
|
116
|
+
return temp;
|
|
117
|
+
}
|
|
118
|
+
if (Array.isArray(secrets)) for (let i = 0; i < secrets.length; i++) {
|
|
119
|
+
const temp = await unsignCookie(value, secrets[i]);
|
|
120
|
+
if (temp !== false) return temp;
|
|
121
|
+
}
|
|
122
|
+
throw InvalidCookie.signature(name);
|
|
123
|
+
}
|
|
124
|
+
const rawJsonValue = /* @__PURE__ */ new WeakMap();
|
|
125
|
+
function maybeJsonDecode(value) {
|
|
126
|
+
if (typeof value === "string" && value.length > 1) {
|
|
127
|
+
const starts = value.charCodeAt(0);
|
|
128
|
+
const ends = value.charCodeAt(value.length - 1);
|
|
129
|
+
if (starts === 123 && ends === 125 || starts === 91 && ends === 93) try {
|
|
130
|
+
const parsed = JSON.parse(value);
|
|
131
|
+
if (parsed !== null && typeof parsed === "object") rawJsonValue.set(parsed, value);
|
|
132
|
+
return parsed;
|
|
133
|
+
} catch {}
|
|
134
|
+
}
|
|
135
|
+
return value;
|
|
136
|
+
}
|
|
137
|
+
function resolvePendingCookie(entry, name) {
|
|
138
|
+
const value = entry.value;
|
|
139
|
+
if (typeof value !== "string") throw InvalidCookie.signature(name);
|
|
140
|
+
if (!hasSyncHmac) throw new Error(`resolvePendingCookie called without sync HMAC. Unreachable under correct lane gating (cookie: "${name}")`);
|
|
141
|
+
const resolvedValue = maybeJsonDecode(unsignWithSecretsSync(name, value, entry["~unsign"]));
|
|
142
|
+
entry.value = resolvedValue;
|
|
143
|
+
if (resolvedValue !== null && typeof resolvedValue === "object") {
|
|
144
|
+
const raw = rawJsonValue.get(resolvedValue);
|
|
145
|
+
entry["~raw"] = raw !== void 0 ? raw : JSON.stringify(resolvedValue);
|
|
146
|
+
}
|
|
147
|
+
delete entry["~unsign"];
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
//#endregion
|
|
151
|
+
export { hasSyncHmac, hmacProvider, importSecretKey, keyCache, maybeJsonDecode, rawJsonValue, resolvePendingCookie, signCookie, signCookieBun, signCookieNode, signCookieSubtle, signCookieSync, signCookieSyncImpl, unsignCookie, unsignCookieSync, unsignWithSecrets, unsignWithSecretsSync };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ElysiaError } from "../error.js";
|
|
2
|
+
|
|
3
|
+
//#region src/cookie/error.d.ts
|
|
4
|
+
declare class InvalidCookie extends ElysiaError {
|
|
5
|
+
key?: string | undefined;
|
|
6
|
+
response: string;
|
|
7
|
+
status: 400;
|
|
8
|
+
problemType: string;
|
|
9
|
+
problemTitle: string;
|
|
10
|
+
constructor(key?: string | undefined, response?: string, status?: number);
|
|
11
|
+
static signature(key: string): InvalidCookie;
|
|
12
|
+
static secret(key?: string): Omit<InvalidCookie, 'status'> & {
|
|
13
|
+
status: 500;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { InvalidCookie };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_error = require('../error.js');
|
|
3
|
+
|
|
4
|
+
//#region src/cookie/error.ts
|
|
5
|
+
var InvalidCookie = class InvalidCookie extends require_error.ElysiaError {
|
|
6
|
+
constructor(key, response = key ? `"${key}" is an invalid cookie` : "Invalid Cookie", status) {
|
|
7
|
+
super(response);
|
|
8
|
+
this.key = key;
|
|
9
|
+
this.response = response;
|
|
10
|
+
this.status = 400;
|
|
11
|
+
this.problemType = "invalid-cookie";
|
|
12
|
+
this.problemTitle = "Invalid Cookie";
|
|
13
|
+
if (status) this.status = status;
|
|
14
|
+
}
|
|
15
|
+
static signature(key) {
|
|
16
|
+
return new InvalidCookie(key, `"${key}" has invalid cookie signature`);
|
|
17
|
+
}
|
|
18
|
+
static secret(key) {
|
|
19
|
+
if (key) return new InvalidCookie(key, `"${key}" is signed but no secret is provided`, 500);
|
|
20
|
+
return new InvalidCookie(void 0, `Cookie is signed but no secret is provided`, 500);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.InvalidCookie = InvalidCookie;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ElysiaError } from "../error.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/cookie/error.ts
|
|
4
|
+
var InvalidCookie = class InvalidCookie extends ElysiaError {
|
|
5
|
+
constructor(key, response = key ? `"${key}" is an invalid cookie` : "Invalid Cookie", status) {
|
|
6
|
+
super(response);
|
|
7
|
+
this.key = key;
|
|
8
|
+
this.response = response;
|
|
9
|
+
this.status = 400;
|
|
10
|
+
this.problemType = "invalid-cookie";
|
|
11
|
+
this.problemTitle = "Invalid Cookie";
|
|
12
|
+
if (status) this.status = status;
|
|
13
|
+
}
|
|
14
|
+
static signature(key) {
|
|
15
|
+
return new InvalidCookie(key, `"${key}" has invalid cookie signature`);
|
|
16
|
+
}
|
|
17
|
+
static secret(key) {
|
|
18
|
+
if (key) return new InvalidCookie(key, `"${key}" is signed but no secret is provided`, 500);
|
|
19
|
+
return new InvalidCookie(void 0, `Cookie is signed but no secret is provided`, 500);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { InvalidCookie };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BaseCookie, CookieOptions } from "./types.js";
|
|
2
|
+
import { Cookie } from "./cookie.js";
|
|
3
|
+
import { serializeCookie } from "./serialize.js";
|
|
4
|
+
import { signCookie, unsignCookie } from "./crypto.js";
|
|
5
|
+
import { parseCookie } from "./utils.js";
|
|
6
|
+
import { InvalidCookie } from "./error.js";
|
|
7
|
+
export { type BaseCookie, Cookie, type CookieOptions, InvalidCookie, parseCookie, serializeCookie, signCookie, unsignCookie };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_cookie_error = require('./error.js');
|
|
3
|
+
const require_cookie_serialize = require('./serialize.js');
|
|
4
|
+
const require_cookie_crypto = require('./crypto.js');
|
|
5
|
+
const require_cookie_cookie = require('./cookie.js');
|
|
6
|
+
const require_cookie_utils = require('./utils.js');
|
|
7
|
+
|
|
8
|
+
exports.Cookie = require_cookie_cookie.Cookie;
|
|
9
|
+
exports.InvalidCookie = require_cookie_error.InvalidCookie;
|
|
10
|
+
exports.parseCookie = require_cookie_utils.parseCookie;
|
|
11
|
+
exports.serializeCookie = require_cookie_serialize.serializeCookie;
|
|
12
|
+
exports.signCookie = require_cookie_crypto.signCookie;
|
|
13
|
+
exports.unsignCookie = require_cookie_crypto.unsignCookie;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { InvalidCookie } from "./error.mjs";
|
|
2
|
+
import { serializeCookie } from "./serialize.mjs";
|
|
3
|
+
import { signCookie, unsignCookie } from "./crypto.mjs";
|
|
4
|
+
import { Cookie } from "./cookie.mjs";
|
|
5
|
+
import { parseCookie } from "./utils.mjs";
|
|
6
|
+
|
|
7
|
+
export { Cookie, InvalidCookie, parseCookie, serializeCookie, signCookie, unsignCookie };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { CookieOptions } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/cookie/lib.d.ts
|
|
4
|
+
declare function parse(str: string): Record<string, string | undefined>;
|
|
5
|
+
declare function serialize(name: string, value: string | undefined, options: CookieOptions): string;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { parse, serialize };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_utils = require('../utils.js');
|
|
3
|
+
const require_cookie_error = require('./error.js');
|
|
4
|
+
|
|
5
|
+
//#region src/cookie/lib.ts
|
|
6
|
+
function parse(str) {
|
|
7
|
+
const obj = require_utils.nullObject();
|
|
8
|
+
const len = str.length;
|
|
9
|
+
if (len < 2) return obj;
|
|
10
|
+
let i = 0;
|
|
11
|
+
while (i < len) {
|
|
12
|
+
const eq = str.indexOf("=", i);
|
|
13
|
+
if (eq === -1) break;
|
|
14
|
+
let semi = str.indexOf(";", i);
|
|
15
|
+
if (semi === -1) semi = len;
|
|
16
|
+
if (eq > semi) {
|
|
17
|
+
i = str.lastIndexOf(";", eq - 1) + 1;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
let ks = i, ke = eq, c;
|
|
21
|
+
while (ks < ke && ((c = str.charCodeAt(ks)) === 32 || c === 9)) ks++;
|
|
22
|
+
while (ke > ks && ((c = str.charCodeAt(ke - 1)) === 32 || c === 9)) ke--;
|
|
23
|
+
const key = str.slice(ks, ke);
|
|
24
|
+
if (obj[key] === void 0) {
|
|
25
|
+
let vs = eq + 1, ve = semi;
|
|
26
|
+
while (vs < ve && ((c = str.charCodeAt(vs)) === 32 || c === 9)) vs++;
|
|
27
|
+
while (ve > vs && ((c = str.charCodeAt(ve - 1)) === 32 || c === 9)) ve--;
|
|
28
|
+
obj[key] = str.slice(vs, ve);
|
|
29
|
+
}
|
|
30
|
+
i = semi + 1;
|
|
31
|
+
}
|
|
32
|
+
return obj;
|
|
33
|
+
}
|
|
34
|
+
const PRIORITY = "; Priority=";
|
|
35
|
+
const SAMESITE = "; SameSite=";
|
|
36
|
+
const COOKIE_NAME_INVALID = /[\x00-\x1F\x7F()<>@,;:\\"/[\]?={} \t]/;
|
|
37
|
+
const COOKIE_ATTR_INVALID = /[\x00-\x1F\x7F;]/;
|
|
38
|
+
function serialize(name, value = "", options) {
|
|
39
|
+
if (COOKIE_NAME_INVALID.test(name)) throw new require_cookie_error.InvalidCookie(`[Elysia] Invalid cookie name ${JSON.stringify(name)}. Cookie names cannot contain separators, whitespace, or control characters.`);
|
|
40
|
+
if (value) value = encodeURIComponent(value);
|
|
41
|
+
let str = `${name}=${value}`;
|
|
42
|
+
const maxAge = options.maxAge;
|
|
43
|
+
if (maxAge !== void 0) str += "; Max-Age=" + maxAge;
|
|
44
|
+
const domain = options.domain;
|
|
45
|
+
if (domain) {
|
|
46
|
+
if (COOKIE_ATTR_INVALID.test(domain)) throw new require_cookie_error.InvalidCookie(`Invalid cookie Domain ${JSON.stringify(domain)}.`);
|
|
47
|
+
str += "; Domain=" + domain;
|
|
48
|
+
}
|
|
49
|
+
const path = options.path;
|
|
50
|
+
if (path) {
|
|
51
|
+
if (COOKIE_ATTR_INVALID.test(path)) throw new require_cookie_error.InvalidCookie(`Invalid cookie Path ${JSON.stringify(path)}.`);
|
|
52
|
+
str += "; Path=" + path;
|
|
53
|
+
}
|
|
54
|
+
const expires = options.expires;
|
|
55
|
+
if (expires) str += "; Expires=" + expires.toUTCString();
|
|
56
|
+
if (options.httpOnly) str += "; HttpOnly";
|
|
57
|
+
if (options.secure) str += "; Secure";
|
|
58
|
+
if (options.partitioned) str += "; Partitioned";
|
|
59
|
+
const priority = options.priority;
|
|
60
|
+
if (priority) {
|
|
61
|
+
if (priority === "low") str += `${PRIORITY}Low`;
|
|
62
|
+
else if (priority === "medium") str += `${PRIORITY}Medium`;
|
|
63
|
+
else if (priority === "high") str += `${PRIORITY}High`;
|
|
64
|
+
}
|
|
65
|
+
const sameSite = options.sameSite;
|
|
66
|
+
if (sameSite) {
|
|
67
|
+
if (sameSite === true || sameSite === "strict") str += `${SAMESITE}Strict`;
|
|
68
|
+
else if (sameSite === "lax") str += `${SAMESITE}Lax`;
|
|
69
|
+
else if (sameSite === "none") str += `${SAMESITE}None`;
|
|
70
|
+
}
|
|
71
|
+
return str;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
//#endregion
|
|
75
|
+
exports.parse = parse;
|
|
76
|
+
exports.serialize = serialize;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { nullObject } from "../utils.mjs";
|
|
2
|
+
import { InvalidCookie } from "./error.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/cookie/lib.ts
|
|
5
|
+
function parse(str) {
|
|
6
|
+
const obj = nullObject();
|
|
7
|
+
const len = str.length;
|
|
8
|
+
if (len < 2) return obj;
|
|
9
|
+
let i = 0;
|
|
10
|
+
while (i < len) {
|
|
11
|
+
const eq = str.indexOf("=", i);
|
|
12
|
+
if (eq === -1) break;
|
|
13
|
+
let semi = str.indexOf(";", i);
|
|
14
|
+
if (semi === -1) semi = len;
|
|
15
|
+
if (eq > semi) {
|
|
16
|
+
i = str.lastIndexOf(";", eq - 1) + 1;
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
let ks = i, ke = eq, c;
|
|
20
|
+
while (ks < ke && ((c = str.charCodeAt(ks)) === 32 || c === 9)) ks++;
|
|
21
|
+
while (ke > ks && ((c = str.charCodeAt(ke - 1)) === 32 || c === 9)) ke--;
|
|
22
|
+
const key = str.slice(ks, ke);
|
|
23
|
+
if (obj[key] === void 0) {
|
|
24
|
+
let vs = eq + 1, ve = semi;
|
|
25
|
+
while (vs < ve && ((c = str.charCodeAt(vs)) === 32 || c === 9)) vs++;
|
|
26
|
+
while (ve > vs && ((c = str.charCodeAt(ve - 1)) === 32 || c === 9)) ve--;
|
|
27
|
+
obj[key] = str.slice(vs, ve);
|
|
28
|
+
}
|
|
29
|
+
i = semi + 1;
|
|
30
|
+
}
|
|
31
|
+
return obj;
|
|
32
|
+
}
|
|
33
|
+
const PRIORITY = "; Priority=";
|
|
34
|
+
const SAMESITE = "; SameSite=";
|
|
35
|
+
const COOKIE_NAME_INVALID = /[\x00-\x1F\x7F()<>@,;:\\"/[\]?={} \t]/;
|
|
36
|
+
const COOKIE_ATTR_INVALID = /[\x00-\x1F\x7F;]/;
|
|
37
|
+
function serialize(name, value = "", options) {
|
|
38
|
+
if (COOKIE_NAME_INVALID.test(name)) throw new InvalidCookie(`[Elysia] Invalid cookie name ${JSON.stringify(name)}. Cookie names cannot contain separators, whitespace, or control characters.`);
|
|
39
|
+
if (value) value = encodeURIComponent(value);
|
|
40
|
+
let str = `${name}=${value}`;
|
|
41
|
+
const maxAge = options.maxAge;
|
|
42
|
+
if (maxAge !== void 0) str += "; Max-Age=" + maxAge;
|
|
43
|
+
const domain = options.domain;
|
|
44
|
+
if (domain) {
|
|
45
|
+
if (COOKIE_ATTR_INVALID.test(domain)) throw new InvalidCookie(`Invalid cookie Domain ${JSON.stringify(domain)}.`);
|
|
46
|
+
str += "; Domain=" + domain;
|
|
47
|
+
}
|
|
48
|
+
const path = options.path;
|
|
49
|
+
if (path) {
|
|
50
|
+
if (COOKIE_ATTR_INVALID.test(path)) throw new InvalidCookie(`Invalid cookie Path ${JSON.stringify(path)}.`);
|
|
51
|
+
str += "; Path=" + path;
|
|
52
|
+
}
|
|
53
|
+
const expires = options.expires;
|
|
54
|
+
if (expires) str += "; Expires=" + expires.toUTCString();
|
|
55
|
+
if (options.httpOnly) str += "; HttpOnly";
|
|
56
|
+
if (options.secure) str += "; Secure";
|
|
57
|
+
if (options.partitioned) str += "; Partitioned";
|
|
58
|
+
const priority = options.priority;
|
|
59
|
+
if (priority) {
|
|
60
|
+
if (priority === "low") str += `${PRIORITY}Low`;
|
|
61
|
+
else if (priority === "medium") str += `${PRIORITY}Medium`;
|
|
62
|
+
else if (priority === "high") str += `${PRIORITY}High`;
|
|
63
|
+
}
|
|
64
|
+
const sameSite = options.sameSite;
|
|
65
|
+
if (sameSite) {
|
|
66
|
+
if (sameSite === true || sameSite === "strict") str += `${SAMESITE}Strict`;
|
|
67
|
+
else if (sameSite === "lax") str += `${SAMESITE}Lax`;
|
|
68
|
+
else if (sameSite === "none") str += `${SAMESITE}None`;
|
|
69
|
+
}
|
|
70
|
+
return str;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
export { parse, serialize };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_utils = require('../utils.js');
|
|
3
|
+
const require_cookie_lib = require('./lib.js');
|
|
4
|
+
|
|
5
|
+
//#region src/cookie/serialize.ts
|
|
6
|
+
function serializeCookie(cookies) {
|
|
7
|
+
if (!cookies || !require_utils.isNotEmpty(cookies)) return;
|
|
8
|
+
let set;
|
|
9
|
+
let isArray = false;
|
|
10
|
+
for (const key in cookies) {
|
|
11
|
+
if (!key) continue;
|
|
12
|
+
const property = cookies[key];
|
|
13
|
+
if (!property) continue;
|
|
14
|
+
let value = property.value;
|
|
15
|
+
if (value === void 0 || value === null) continue;
|
|
16
|
+
if (typeof value === "object") {
|
|
17
|
+
value = JSON.stringify(value);
|
|
18
|
+
if (property["~raw"] === value) continue;
|
|
19
|
+
}
|
|
20
|
+
const v = require_cookie_lib.serialize(key, value, property);
|
|
21
|
+
if (set) if (isArray) set.push(v);
|
|
22
|
+
else {
|
|
23
|
+
set = [set, v];
|
|
24
|
+
isArray = true;
|
|
25
|
+
}
|
|
26
|
+
else set = v;
|
|
27
|
+
}
|
|
28
|
+
return set;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
exports.serializeCookie = serializeCookie;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isNotEmpty } from "../utils.mjs";
|
|
2
|
+
import { serialize } from "./lib.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/cookie/serialize.ts
|
|
5
|
+
function serializeCookie(cookies) {
|
|
6
|
+
if (!cookies || !isNotEmpty(cookies)) return;
|
|
7
|
+
let set;
|
|
8
|
+
let isArray = false;
|
|
9
|
+
for (const key in cookies) {
|
|
10
|
+
if (!key) continue;
|
|
11
|
+
const property = cookies[key];
|
|
12
|
+
if (!property) continue;
|
|
13
|
+
let value = property.value;
|
|
14
|
+
if (value === void 0 || value === null) continue;
|
|
15
|
+
if (typeof value === "object") {
|
|
16
|
+
value = JSON.stringify(value);
|
|
17
|
+
if (property["~raw"] === value) continue;
|
|
18
|
+
}
|
|
19
|
+
const v = serialize(key, value, property);
|
|
20
|
+
if (set) if (isArray) set.push(v);
|
|
21
|
+
else {
|
|
22
|
+
set = [set, v];
|
|
23
|
+
isArray = true;
|
|
24
|
+
}
|
|
25
|
+
else set = v;
|
|
26
|
+
}
|
|
27
|
+
return set;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//#endregion
|
|
31
|
+
export { serializeCookie };
|