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/adapter/utils.js
CHANGED
|
@@ -1,320 +1,570 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
-
return to;
|
|
14
|
-
};
|
|
15
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
16
|
-
var utils_exports = {};
|
|
17
|
-
__export(utils_exports, {
|
|
18
|
-
createResponseHandler: () => createResponseHandler,
|
|
19
|
-
createStreamHandler: () => createStreamHandler,
|
|
20
|
-
handleFile: () => handleFile,
|
|
21
|
-
handleSet: () => handleSet,
|
|
22
|
-
mergeHeaders: () => mergeHeaders,
|
|
23
|
-
mergeStatus: () => mergeStatus,
|
|
24
|
-
parseSetCookies: () => parseSetCookies,
|
|
25
|
-
responseToSetHeaders: () => responseToSetHeaders,
|
|
26
|
-
streamResponse: () => streamResponse,
|
|
27
|
-
tee: () => tee
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(utils_exports);
|
|
30
|
-
var import_cookies = require('../cookies.js'), import_utils = require('../utils.js'), import_utils2 = require('../universal/utils.js');
|
|
31
|
-
const handleFile = (response, set, request) => {
|
|
32
|
-
if (!import_utils2.isBun && response instanceof Promise)
|
|
33
|
-
return response.then((res) => handleFile(res, set, request));
|
|
34
|
-
const size = response.size, rangeHeader = request?.headers.get("range");
|
|
35
|
-
if (rangeHeader) {
|
|
36
|
-
const match = /bytes=(\d*)-(\d*)/.exec(rangeHeader);
|
|
37
|
-
if (match) {
|
|
38
|
-
if (!match[1] && !match[2])
|
|
39
|
-
return new Response(null, {
|
|
40
|
-
status: 416,
|
|
41
|
-
headers: mergeHeaders(
|
|
42
|
-
new Headers({ "content-range": `bytes */${size}` }),
|
|
43
|
-
set?.headers ?? {}
|
|
44
|
-
)
|
|
45
|
-
});
|
|
46
|
-
let start, end;
|
|
47
|
-
if (!match[1] && match[2]) {
|
|
48
|
-
const suffix = parseInt(match[2]);
|
|
49
|
-
start = Math.max(0, size - suffix), end = size - 1;
|
|
50
|
-
} else
|
|
51
|
-
start = match[1] ? parseInt(match[1]) : 0, end = match[2] ? Math.min(parseInt(match[2]), size - 1) : size - 1;
|
|
52
|
-
if (start >= size || start > end)
|
|
53
|
-
return new Response(null, {
|
|
54
|
-
status: 416,
|
|
55
|
-
headers: mergeHeaders(
|
|
56
|
-
new Headers({ "content-range": `bytes */${size}` }),
|
|
57
|
-
set?.headers ?? {}
|
|
58
|
-
)
|
|
59
|
-
});
|
|
60
|
-
const contentLength = end - start + 1, rangeHeaders = new Headers({
|
|
61
|
-
"accept-ranges": "bytes",
|
|
62
|
-
"content-range": `bytes ${start}-${end}/${size}`,
|
|
63
|
-
"content-length": String(contentLength)
|
|
64
|
-
});
|
|
65
|
-
return new Response(
|
|
66
|
-
response.slice(start, end + 1, response.type),
|
|
67
|
-
{
|
|
68
|
-
status: 206,
|
|
69
|
-
headers: mergeHeaders(rangeHeaders, set?.headers ?? {})
|
|
70
|
-
}
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
const immutable = set && (set.status === 206 || set.status === 304 || set.status === 412 || set.status === 416), defaultHeader = immutable ? {} : {
|
|
75
|
-
"accept-ranges": "bytes",
|
|
76
|
-
"content-range": size ? `bytes 0-${size - 1}/${size}` : void 0
|
|
77
|
-
};
|
|
78
|
-
if (!set && !size) return new Response(response);
|
|
79
|
-
if (!set)
|
|
80
|
-
return new Response(response, {
|
|
81
|
-
headers: defaultHeader
|
|
82
|
-
});
|
|
83
|
-
if (set.headers instanceof Headers) {
|
|
84
|
-
for (const key of Object.keys(defaultHeader))
|
|
85
|
-
key in set.headers && set.headers.append(key, defaultHeader[key]);
|
|
86
|
-
return immutable && (set.headers.delete("content-length"), set.headers.delete("accept-ranges")), new Response(response, set);
|
|
87
|
-
}
|
|
88
|
-
return (0, import_utils.isNotEmpty)(set.headers) ? new Response(response, {
|
|
89
|
-
status: set.status,
|
|
90
|
-
headers: Object.assign(defaultHeader, set.headers)
|
|
91
|
-
}) : new Response(response, {
|
|
92
|
-
status: set.status,
|
|
93
|
-
headers: defaultHeader
|
|
94
|
-
});
|
|
95
|
-
}, parseSetCookies = (headers, setCookie) => {
|
|
96
|
-
if (!headers) return headers;
|
|
97
|
-
headers.delete("set-cookie");
|
|
98
|
-
for (let i = 0; i < setCookie.length; i++) {
|
|
99
|
-
const index = setCookie[i].indexOf("=");
|
|
100
|
-
headers.append(
|
|
101
|
-
"set-cookie",
|
|
102
|
-
`${setCookie[i].slice(0, index)}=${setCookie[i].slice(index + 1) || ""}`
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
return headers;
|
|
106
|
-
}, responseToSetHeaders = (response, set) => {
|
|
107
|
-
if (set?.headers) {
|
|
108
|
-
if (response)
|
|
109
|
-
if (import_utils.hasHeaderShorthand)
|
|
110
|
-
Object.assign(set.headers, response.headers.toJSON());
|
|
111
|
-
else
|
|
112
|
-
for (const [key, value] of response.headers.entries())
|
|
113
|
-
key in set.headers && (set.headers[key] = value);
|
|
114
|
-
return set.status === 200 && (set.status = response.status), set.headers["content-encoding"] && delete set.headers["content-encoding"], set;
|
|
115
|
-
}
|
|
116
|
-
if (!response)
|
|
117
|
-
return {
|
|
118
|
-
headers: {},
|
|
119
|
-
status: set?.status ?? 200
|
|
120
|
-
};
|
|
121
|
-
if (import_utils.hasHeaderShorthand)
|
|
122
|
-
return set = {
|
|
123
|
-
headers: response.headers.toJSON(),
|
|
124
|
-
status: set?.status ?? 200
|
|
125
|
-
}, set.headers["content-encoding"] && delete set.headers["content-encoding"], set;
|
|
126
|
-
set = {
|
|
127
|
-
headers: {},
|
|
128
|
-
status: set?.status ?? 200
|
|
129
|
-
};
|
|
130
|
-
for (const [key, value] of response.headers.entries())
|
|
131
|
-
key !== "content-encoding" && key in set.headers && (set.headers[key] = value);
|
|
132
|
-
return set;
|
|
133
|
-
}, enqueueBinaryChunk = (controller, chunk) => chunk instanceof Blob ? chunk.arrayBuffer().then((buffer) => (controller.enqueue(new Uint8Array(buffer)), !0)) : chunk instanceof Uint8Array ? (controller.enqueue(chunk), !0) : chunk instanceof ArrayBuffer ? (controller.enqueue(new Uint8Array(chunk)), !0) : ArrayBuffer.isView(chunk) ? (controller.enqueue(
|
|
134
|
-
new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength)
|
|
135
|
-
), !0) : !1, createStreamHandler = ({ mapResponse, mapCompactResponse }) => async (generator, set, request, skipFormat) => {
|
|
136
|
-
let init = generator.next?.();
|
|
137
|
-
if (set && handleSet(set), init instanceof Promise && (init = await init), init?.value instanceof ReadableStream)
|
|
138
|
-
generator = init.value;
|
|
139
|
-
else if (init && (typeof init?.done > "u" || init?.done))
|
|
140
|
-
return set ? mapResponse(init.value, set, request) : mapCompactResponse(init.value, request);
|
|
141
|
-
const isSSE = !skipFormat && // @ts-ignore First SSE result is wrapped with sse()
|
|
142
|
-
(init?.value?.sse ?? // @ts-ignore ReadableStream is wrapped with sse()
|
|
143
|
-
generator?.sse ?? // User explicitly set content-type to SSE
|
|
144
|
-
set?.headers["content-type"]?.startsWith("text/event-stream")), format = isSSE ? (data) => `data: ${data}
|
|
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_utils = require('../utils.js');
|
|
5
|
+
const require_adapter_skip_clone = require('./skip-clone.js');
|
|
6
|
+
const require_cookie_serialize = require('../cookie/serialize.js');
|
|
7
|
+
const require_adapter_response_ownership = require('./response-ownership.js');
|
|
8
|
+
const require_adapter_default_headers = require('./default-headers.js');
|
|
145
9
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
10
|
+
//#region src/adapter/utils.ts
|
|
11
|
+
const setCookie = "set-cookie";
|
|
12
|
+
function materializeSetHeaders(set) {
|
|
13
|
+
const headers = set.headers;
|
|
14
|
+
if (headers["\0"] !== headers) return headers;
|
|
15
|
+
return set.headers = Object.assign(require_utils.nullObject(), headers);
|
|
16
|
+
}
|
|
17
|
+
const sseFormat = (data) => `data: ${data}\n\n`;
|
|
18
|
+
const identityFormat = (data) => data;
|
|
19
|
+
const textEncoder = new TextEncoder();
|
|
20
|
+
const encodeChunk = (s) => textEncoder.encode(s);
|
|
21
|
+
function normalizeContentType(contentType) {
|
|
22
|
+
if (contentType === "application/json") return contentType;
|
|
23
|
+
const end = contentType.indexOf(";");
|
|
24
|
+
return (end === -1 ? contentType : contentType.slice(0, end)).trim().toLowerCase();
|
|
25
|
+
}
|
|
26
|
+
function handleFile(response, set, request, size = response.size) {
|
|
27
|
+
if (!require_universal_constants.isBun && response instanceof Promise) return response.then((res) => handleFile(res, set, request, size));
|
|
28
|
+
const rangeHeader = request?.headers.get("range");
|
|
29
|
+
if (rangeHeader) {
|
|
30
|
+
const match = /bytes=(\d*)-(\d*)/.exec(rangeHeader);
|
|
31
|
+
if (match) {
|
|
32
|
+
if (!match[1] && !match[2]) return new Response(null, {
|
|
33
|
+
status: 416,
|
|
34
|
+
headers: mergeHeaders(new Headers({ "content-range": `bytes */${size}` }), set?.headers ?? require_utils.nullObject())
|
|
35
|
+
});
|
|
36
|
+
let start;
|
|
37
|
+
let end;
|
|
38
|
+
if (!match[1] && match[2]) {
|
|
39
|
+
const suffix = parseInt(match[2]);
|
|
40
|
+
start = Math.max(0, size - suffix);
|
|
41
|
+
end = size - 1;
|
|
42
|
+
} else {
|
|
43
|
+
start = match[1] ? parseInt(match[1]) : 0;
|
|
44
|
+
end = match[2] ? Math.min(parseInt(match[2]), size - 1) : size - 1;
|
|
45
|
+
}
|
|
46
|
+
if (start >= size || start > end) return new Response(null, {
|
|
47
|
+
status: 416,
|
|
48
|
+
headers: mergeHeaders(new Headers({ "content-range": `bytes */${size}` }), set?.headers ?? require_utils.nullObject())
|
|
49
|
+
});
|
|
50
|
+
const contentLength = end - start + 1;
|
|
51
|
+
const rangeHeaders = new Headers({
|
|
52
|
+
"accept-ranges": "bytes",
|
|
53
|
+
"content-range": `bytes ${start}-${end}/${size}`,
|
|
54
|
+
"content-length": String(contentLength)
|
|
55
|
+
});
|
|
56
|
+
return new Response(response.slice(start, end + 1, response.type), {
|
|
57
|
+
status: 206,
|
|
58
|
+
headers: mergeHeaders(rangeHeaders, set?.headers ?? require_utils.nullObject())
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const body = "value" in response ? response.value : response;
|
|
63
|
+
const immutable = set && (set.status === 206 || set.status === 304 || set.status === 412 || set.status === 416);
|
|
64
|
+
const defaultHeader = immutable ? require_utils.nullObject() : {
|
|
65
|
+
"accept-ranges": "bytes",
|
|
66
|
+
"content-range": size ? `bytes 0-${size - 1}/${size}` : void 0
|
|
67
|
+
};
|
|
68
|
+
if (!set && !size) return new Response(body);
|
|
69
|
+
if (!set) return new Response(body, { headers: defaultHeader });
|
|
70
|
+
if (set.headers instanceof Headers) {
|
|
71
|
+
for (const key of Object.keys(defaultHeader)) if (!set.headers.has(key)) set.headers.append(key, defaultHeader[key]);
|
|
72
|
+
if (immutable) {
|
|
73
|
+
set.headers.delete("content-length");
|
|
74
|
+
set.headers.delete("accept-ranges");
|
|
75
|
+
}
|
|
76
|
+
return new Response(body, set);
|
|
77
|
+
}
|
|
78
|
+
if (require_utils.isNotEmpty(set.headers)) return new Response(body, {
|
|
79
|
+
status: set.status,
|
|
80
|
+
headers: Object.assign(defaultHeader, set.headers)
|
|
81
|
+
});
|
|
82
|
+
return new Response(body, {
|
|
83
|
+
status: set.status,
|
|
84
|
+
headers: defaultHeader
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
function normalizeHeaders(set) {
|
|
88
|
+
const headers = set.headers;
|
|
89
|
+
if (!(headers instanceof Headers)) return;
|
|
90
|
+
const flat = Object.create(null);
|
|
91
|
+
for (const [key, value] of headers) if (key !== setCookie) flat[key] = value;
|
|
92
|
+
const cookies = headers.getSetCookie();
|
|
93
|
+
if (cookies.length) flat[setCookie] = cookies;
|
|
94
|
+
set.headers = flat;
|
|
95
|
+
}
|
|
96
|
+
function parseSetCookies(headers, setCookie) {
|
|
97
|
+
if (!headers) return headers;
|
|
98
|
+
headers.delete("set-cookie");
|
|
99
|
+
for (let i = 0; i < setCookie.length; i++) headers.append("set-cookie", setCookie[i]);
|
|
100
|
+
return headers;
|
|
101
|
+
}
|
|
102
|
+
function responseToSetHeaders(response, set) {
|
|
103
|
+
if (set && set.headers instanceof Headers) normalizeHeaders(set);
|
|
104
|
+
if (set) materializeSetHeaders(set);
|
|
105
|
+
if (set?.headers) {
|
|
106
|
+
if (response) if (require_universal_constants.hasHeaderShorthand) Object.assign(set.headers, response.headers.toJSON());
|
|
107
|
+
else for (const [key, value] of response.headers.entries()) set.headers[key] = value;
|
|
108
|
+
if (set.status === void 0 || set.status === 200) set.status = response.status;
|
|
109
|
+
} else if (!response) return {
|
|
110
|
+
headers: require_utils.nullObject(),
|
|
111
|
+
status: set?.status ?? 200
|
|
112
|
+
};
|
|
113
|
+
else if (require_universal_constants.hasHeaderShorthand) set = {
|
|
114
|
+
headers: response.headers.toJSON(),
|
|
115
|
+
status: set?.status ?? 200
|
|
116
|
+
};
|
|
117
|
+
else {
|
|
118
|
+
set = {
|
|
119
|
+
headers: require_utils.nullObject(),
|
|
120
|
+
status: set?.status ?? 200
|
|
121
|
+
};
|
|
122
|
+
for (const [key, value] of response.headers.entries()) set.headers[key] = value;
|
|
123
|
+
}
|
|
124
|
+
if (set.headers["content-encoding"]) delete set.headers["content-encoding"];
|
|
125
|
+
return set;
|
|
126
|
+
}
|
|
127
|
+
function enqueueBinaryChunk(controller, chunk) {
|
|
128
|
+
if (chunk instanceof Blob) return chunk.arrayBuffer().then((buffer) => {
|
|
129
|
+
controller.enqueue(new Uint8Array(buffer));
|
|
130
|
+
return true;
|
|
131
|
+
});
|
|
132
|
+
if (chunk instanceof Uint8Array) {
|
|
133
|
+
controller.enqueue(chunk);
|
|
134
|
+
return true;
|
|
135
|
+
}
|
|
136
|
+
if (chunk instanceof ArrayBuffer) {
|
|
137
|
+
controller.enqueue(new Uint8Array(chunk));
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
if (ArrayBuffer.isView(chunk)) {
|
|
141
|
+
controller.enqueue(new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength));
|
|
142
|
+
return true;
|
|
143
|
+
}
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
function createStreamHandler({ mapResponse, mapCompactResponse }) {
|
|
147
|
+
return async (generator, set, request, skipFormat, owned = false) => {
|
|
148
|
+
if (require_utils.isByteStream(generator)) {
|
|
149
|
+
if (generator.locked) throw new TypeError("Cannot transfer a locked or consumed byte stream");
|
|
150
|
+
if (set) {
|
|
151
|
+
handleSet(set);
|
|
152
|
+
const headers = materializeSetHeaders(set);
|
|
153
|
+
if (headers instanceof Headers) {
|
|
154
|
+
if (!headers.has("content-type")) headers.set("content-type", "application/octet-stream");
|
|
155
|
+
} else if (!headers["content-type"]) headers["content-type"] = "application/octet-stream";
|
|
156
|
+
return new Response(generator, set);
|
|
157
|
+
}
|
|
158
|
+
return new Response(generator, { headers: { "content-type": "application/octet-stream" } });
|
|
159
|
+
}
|
|
160
|
+
const typedSSE = !skipFormat && "sse" in generator && generator.sse === true;
|
|
161
|
+
let init = typedSSE ? void 0 : generator.next?.();
|
|
162
|
+
if (set) handleSet(set);
|
|
163
|
+
if (init instanceof Promise) init = await init;
|
|
164
|
+
if (init?.value instanceof ReadableStream) generator = init.value;
|
|
165
|
+
else if (init && (typeof init?.done === "undefined" || init?.done)) {
|
|
166
|
+
if (set) return mapResponse(init.value, set, request, owned);
|
|
167
|
+
return mapCompactResponse(init.value, request, owned);
|
|
168
|
+
}
|
|
169
|
+
const isSSE = typedSSE || !skipFormat && (init?.value?.sse ?? generator?.sse ?? (set?.headers instanceof Headers ? set.headers.get("content-type")?.startsWith("text/event-stream") : set?.headers["content-type"]?.startsWith("text/event-stream")));
|
|
170
|
+
const format = isSSE ? sseFormat : identityFormat;
|
|
171
|
+
const contentType = isSSE ? "text/event-stream" : init?.value && typeof init?.value === "object" ? ArrayBuffer.isView(init.value) ? "application/octet-stream" : "application/json" : "text/plain";
|
|
172
|
+
if (set) materializeSetHeaders(set);
|
|
173
|
+
const headers = set?.headers;
|
|
174
|
+
if (headers instanceof Headers) {
|
|
175
|
+
if (!typedSSE && !headers.has("transfer-encoding")) headers.set("transfer-encoding", "chunked");
|
|
176
|
+
if (!headers.has("content-type")) headers.set("content-type", contentType);
|
|
177
|
+
if (!headers.has("cache-control")) headers.set("cache-control", "no-cache");
|
|
178
|
+
} else if (headers) {
|
|
179
|
+
if (!typedSSE && !headers["transfer-encoding"]) headers["transfer-encoding"] = "chunked";
|
|
180
|
+
if (!headers["content-type"]) headers["content-type"] = contentType;
|
|
181
|
+
if (!headers["cache-control"]) headers["cache-control"] = "no-cache";
|
|
182
|
+
} else if (typedSSE) set = {
|
|
183
|
+
status: 200,
|
|
184
|
+
headers: {
|
|
185
|
+
"content-type": contentType,
|
|
186
|
+
"cache-control": "no-cache"
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
else set = {
|
|
190
|
+
status: 200,
|
|
191
|
+
headers: {
|
|
192
|
+
"content-type": contentType,
|
|
193
|
+
"transfer-encoding": "chunked",
|
|
194
|
+
"cache-control": "no-cache",
|
|
195
|
+
connection: "keep-alive"
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
const iterator = typeof generator.next === "function" ? generator : generator[Symbol.asyncIterator]();
|
|
199
|
+
let end = false;
|
|
200
|
+
const signal = request?.signal;
|
|
201
|
+
let onAbort;
|
|
202
|
+
const cleanupAbort = () => {
|
|
203
|
+
if (signal && onAbort) {
|
|
204
|
+
signal.removeEventListener("abort", onAbort);
|
|
205
|
+
onAbort = void 0;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
const safeReturn = () => {
|
|
209
|
+
try {
|
|
210
|
+
const r = iterator.return?.();
|
|
211
|
+
if (r && typeof r.then === "function") r.catch(() => {});
|
|
212
|
+
} catch {}
|
|
213
|
+
};
|
|
214
|
+
const closeSafely = (controller) => {
|
|
215
|
+
try {
|
|
216
|
+
controller.close();
|
|
217
|
+
} catch {}
|
|
218
|
+
cleanupAbort();
|
|
219
|
+
};
|
|
220
|
+
const enqueueValue = async (controller, value) => {
|
|
221
|
+
if (value.toSSE) {
|
|
222
|
+
controller.enqueue(encodeChunk(value.toSSE()));
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
const p = enqueueBinaryChunk(controller, value);
|
|
226
|
+
if (p !== false) return void await p;
|
|
227
|
+
if (typeof value === "object") try {
|
|
228
|
+
controller.enqueue(encodeChunk(format(JSON.stringify(value))));
|
|
229
|
+
} catch {
|
|
230
|
+
controller.enqueue(encodeChunk(format(value.toString())));
|
|
231
|
+
}
|
|
232
|
+
else controller.enqueue(encodeChunk(format(value.toString())));
|
|
233
|
+
};
|
|
234
|
+
return new Response(new ReadableStream({
|
|
235
|
+
async start(controller) {
|
|
236
|
+
if (signal) {
|
|
237
|
+
onAbort = () => {
|
|
238
|
+
cleanupAbort();
|
|
239
|
+
end = true;
|
|
240
|
+
safeReturn();
|
|
241
|
+
try {
|
|
242
|
+
controller.close();
|
|
243
|
+
} catch {}
|
|
244
|
+
};
|
|
245
|
+
if (signal.aborted) onAbort();
|
|
246
|
+
else signal.addEventListener("abort", onAbort, { once: true });
|
|
247
|
+
}
|
|
248
|
+
if (!init || init.value instanceof ReadableStream || init.value === void 0 || init.value === null) return;
|
|
249
|
+
await enqueueValue(controller, init.value);
|
|
250
|
+
},
|
|
251
|
+
async pull(controller) {
|
|
252
|
+
if (end) {
|
|
253
|
+
closeSafely(controller);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
try {
|
|
257
|
+
const { value: chunk, done } = await iterator.next();
|
|
258
|
+
if (done || end) {
|
|
259
|
+
closeSafely(controller);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (chunk === void 0 || chunk === null) return;
|
|
263
|
+
await enqueueValue(controller, chunk);
|
|
264
|
+
} catch (error) {
|
|
265
|
+
cleanupAbort();
|
|
266
|
+
controller.error(error);
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
cancel() {
|
|
270
|
+
end = true;
|
|
271
|
+
cleanupAbort();
|
|
272
|
+
safeReturn();
|
|
273
|
+
}
|
|
274
|
+
}, typedSSE ? { highWaterMark: 0 } : void 0), set);
|
|
275
|
+
};
|
|
276
|
+
}
|
|
230
277
|
async function* streamResponse(response) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
278
|
+
const body = response.body;
|
|
279
|
+
if (body) yield* body;
|
|
280
|
+
}
|
|
281
|
+
function handleSet(set) {
|
|
282
|
+
if (typeof set.status === "string") set.status = require_constants.StatusMap[set.status];
|
|
283
|
+
if (set.headers instanceof Headers) normalizeHeaders(set);
|
|
284
|
+
const proto = Object.getPrototypeOf(set.headers);
|
|
285
|
+
if (proto !== null && proto !== Object.prototype) {
|
|
286
|
+
const flat = Object.create(null);
|
|
287
|
+
for (const key in set.headers) flat[key] = set.headers[key];
|
|
288
|
+
set.headers = flat;
|
|
289
|
+
}
|
|
290
|
+
if (set.cookie && require_utils.isNotEmpty(set.cookie)) {
|
|
291
|
+
materializeSetHeaders(set);
|
|
292
|
+
const cookie = require_cookie_serialize.serializeCookie(set.cookie);
|
|
293
|
+
if (cookie) {
|
|
294
|
+
const existing = set.headers[setCookie];
|
|
295
|
+
if (Array.isArray(existing)) set.headers[setCookie] = existing.concat(cookie);
|
|
296
|
+
else set.headers[setCookie] = cookie;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
if (set.headers[setCookie] && Array.isArray(set.headers[setCookie])) set.headers = parseSetCookies(new Headers(set.headers), set.headers[setCookie]);
|
|
300
|
+
}
|
|
301
|
+
function applySetHeaders(target, setHeaders, present) {
|
|
302
|
+
if (setHeaders instanceof Headers) {
|
|
303
|
+
const incoming = setHeaders.getSetCookie();
|
|
304
|
+
if (incoming.length) {
|
|
305
|
+
const cookies = target.getSetCookie();
|
|
306
|
+
for (const cookie of incoming) if (!cookies.includes(cookie)) {
|
|
307
|
+
target.append(setCookie, cookie);
|
|
308
|
+
cookies.push(cookie);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
for (const key of setHeaders.keys()) if (key !== setCookie && !present.has(key)) target.set(key, setHeaders.get(key) ?? "");
|
|
312
|
+
} else {
|
|
313
|
+
let cookies;
|
|
314
|
+
for (const key in setHeaders) if (key === setCookie) {
|
|
315
|
+
const cookie = setHeaders[key];
|
|
316
|
+
cookies ??= target.getSetCookie();
|
|
317
|
+
if (!cookies.includes(cookie)) {
|
|
318
|
+
target.append(key, cookie);
|
|
319
|
+
cookies.push(cookie);
|
|
320
|
+
}
|
|
321
|
+
} else if (!present.has(key)) target.set(key, setHeaders[key]);
|
|
322
|
+
}
|
|
243
323
|
}
|
|
244
|
-
const handleSet = (set) => {
|
|
245
|
-
if (typeof set.status == "string" && (set.status = import_utils.StatusMap[set.status]), set.cookie && (0, import_utils.isNotEmpty)(set.cookie)) {
|
|
246
|
-
const cookie = (0, import_cookies.serializeCookie)(set.cookie);
|
|
247
|
-
cookie && (set.headers["set-cookie"] = cookie);
|
|
248
|
-
}
|
|
249
|
-
set.headers["set-cookie"] && Array.isArray(set.headers["set-cookie"]) && (set.headers = parseSetCookies(
|
|
250
|
-
new Headers(set.headers),
|
|
251
|
-
set.headers["set-cookie"]
|
|
252
|
-
));
|
|
253
|
-
};
|
|
254
324
|
function mergeHeaders(responseHeaders, setHeaders) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
if (key === "set-cookie") {
|
|
259
|
-
if (headers.has("set-cookie")) continue;
|
|
260
|
-
for (const cookie of setHeaders.getSetCookie())
|
|
261
|
-
headers.append("set-cookie", cookie);
|
|
262
|
-
} else responseHeaders.has(key) || headers.set(key, setHeaders?.get(key) ?? "");
|
|
263
|
-
else
|
|
264
|
-
for (const key in setHeaders)
|
|
265
|
-
key === "set-cookie" ? headers.append(key, setHeaders[key]) : responseHeaders.has(key) || headers.set(key, setHeaders[key]);
|
|
266
|
-
return headers;
|
|
325
|
+
const headers = new Headers(responseHeaders);
|
|
326
|
+
applySetHeaders(headers, setHeaders, responseHeaders);
|
|
327
|
+
return headers;
|
|
267
328
|
}
|
|
268
329
|
function mergeStatus(responseStatus, setStatus) {
|
|
269
|
-
|
|
330
|
+
if (typeof setStatus === "string") setStatus = require_constants.StatusMap[setStatus];
|
|
331
|
+
if (responseStatus === 200) return setStatus;
|
|
332
|
+
return responseStatus;
|
|
270
333
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
334
|
+
function cancelPropagatingBody(clonedBody, orphanedBranch, preserveOrphan = false) {
|
|
335
|
+
const reader = clonedBody.getReader();
|
|
336
|
+
return new ReadableStream({
|
|
337
|
+
async pull(controller) {
|
|
338
|
+
const { done, value } = await reader.read();
|
|
339
|
+
if (done) controller.close();
|
|
340
|
+
else controller.enqueue(value);
|
|
341
|
+
},
|
|
342
|
+
cancel(reason) {
|
|
343
|
+
if (preserveOrphan) {
|
|
344
|
+
reader.cancel(reason).catch(() => {});
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
orphanedBranch.cancel(reason);
|
|
348
|
+
return reader.cancel(reason);
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
const warnedStreamBorrows = /* @__PURE__ */ new WeakSet();
|
|
353
|
+
function createResponseHandler(handler) {
|
|
354
|
+
const handleStream = createStreamHandler(handler);
|
|
355
|
+
return (response, set, request, owned = false) => {
|
|
356
|
+
if (require_adapter_skip_clone.skipClone.has(response) && !response.bodyUsed) {
|
|
357
|
+
require_adapter_skip_clone.skipClone.delete(response);
|
|
358
|
+
owned = true;
|
|
359
|
+
}
|
|
360
|
+
const explicitlyBorrowed = require_adapter_response_ownership.isBorrowedResponse(response);
|
|
361
|
+
const borrowed = !owned || explicitlyBorrowed;
|
|
362
|
+
const mustClone = owned && explicitlyBorrowed;
|
|
363
|
+
if (!borrowed && response.bodyUsed) throw new TypeError("Cannot reuse a consumed Response across requests");
|
|
364
|
+
if (set) {
|
|
365
|
+
const status = mergeStatus(response.status, set.status);
|
|
366
|
+
const statusUnchanged = status === void 0 || status === response.status;
|
|
367
|
+
if (!mustClone && statusUnchanged && !set.cookie && !require_utils.isNotEmpty(set.headers)) return response;
|
|
368
|
+
} else if (!mustClone) return response;
|
|
369
|
+
if (!borrowed && response.body?.locked) throw new TypeError("Cannot patch a Response whose body is locked");
|
|
370
|
+
let body = response.body;
|
|
371
|
+
if (borrowed) {
|
|
372
|
+
const bodyBefore = body;
|
|
373
|
+
const cloned = response.clone();
|
|
374
|
+
if (explicitlyBorrowed && bodyBefore && response.body !== bodyBefore && !warnedStreamBorrows.has(response)) {
|
|
375
|
+
warnedStreamBorrows.add(response);
|
|
376
|
+
console.warn("[elysia] borrow() was called on a stream-backed Response");
|
|
377
|
+
}
|
|
378
|
+
body = cloned.body && response.body ? cancelPropagatingBody(cloned.body, response.body, explicitlyBorrowed) : cloned.body;
|
|
379
|
+
}
|
|
380
|
+
const newResponse = new Response(body, set ? {
|
|
381
|
+
headers: mergeHeaders(response.headers, set.headers),
|
|
382
|
+
status: mergeStatus(response.status, set.status),
|
|
383
|
+
statusText: response.statusText
|
|
384
|
+
} : {
|
|
385
|
+
headers: response.headers,
|
|
386
|
+
status: response.status,
|
|
387
|
+
statusText: response.statusText
|
|
388
|
+
});
|
|
389
|
+
if (borrowed && !newResponse.headers.has("content-length") && newResponse.headers.get("transfer-encoding") === "chunked") return handleStream(streamResponse(newResponse), responseToSetHeaders(newResponse, set), request, true);
|
|
390
|
+
return newResponse;
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
function teeChunkCost(chunk) {
|
|
394
|
+
if (typeof chunk === "string") return chunk.length;
|
|
395
|
+
if (typeof chunk !== "object" || chunk === null) return 64;
|
|
396
|
+
const byteLength = chunk.byteLength;
|
|
397
|
+
if (typeof byteLength === "number") return byteLength;
|
|
398
|
+
const size = chunk.size;
|
|
399
|
+
if (typeof size === "number") return size;
|
|
400
|
+
return 64;
|
|
401
|
+
}
|
|
402
|
+
const doneResult = {
|
|
403
|
+
done: true,
|
|
404
|
+
value: void 0
|
|
286
405
|
};
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
406
|
+
/**
|
|
407
|
+
* Split async source into `branches` independent iterators
|
|
408
|
+
*
|
|
409
|
+
* A producer drains the source ahead of consumers
|
|
410
|
+
*
|
|
411
|
+
* To prevent long/infinite stream, the unconsumed window is capped:
|
|
412
|
+
* Consumed-by-every-branch entries are trimmed off the front
|
|
413
|
+
* Producer backpressures whenever the window hits `cap` ENTRIES or
|
|
414
|
+
* `capBytes` bytes, whichever comes first
|
|
415
|
+
*
|
|
416
|
+
* Streams below both caps buffer eagerly
|
|
417
|
+
* Only streams exceeding one gate on the slowest consumer
|
|
418
|
+
*
|
|
419
|
+
* Branch 0 is the value consumer (response/client)
|
|
420
|
+
* When `return()` (client abort / early exit), source is stopped
|
|
421
|
+
* so the observer branches can still reach completion instead of spinning
|
|
422
|
+
* an infinite source
|
|
423
|
+
*/
|
|
424
|
+
function tee(source, branches = 2, cap = 64, capBytes = 1 << 22) {
|
|
425
|
+
const iterator = source[Symbol.asyncIterator]?.() ?? source[Symbol.iterator]();
|
|
426
|
+
const buffer = [];
|
|
427
|
+
const sizes = [];
|
|
428
|
+
let base = 0;
|
|
429
|
+
let windowBytes = 0;
|
|
430
|
+
let done = false;
|
|
431
|
+
let stopped = false;
|
|
432
|
+
let failed = false;
|
|
433
|
+
let sourceError;
|
|
434
|
+
let drainResume = null;
|
|
435
|
+
const cursors = new Array(branches).fill(0);
|
|
436
|
+
let active = branches;
|
|
437
|
+
const pending = new Array(branches).fill(null);
|
|
438
|
+
const resumeProducer = () => {
|
|
439
|
+
if (drainResume) {
|
|
440
|
+
const resume = drainResume;
|
|
441
|
+
drainResume = null;
|
|
442
|
+
resume();
|
|
443
|
+
}
|
|
444
|
+
};
|
|
445
|
+
const trim = () => {
|
|
446
|
+
if (active > 0) {
|
|
447
|
+
let min = Infinity;
|
|
448
|
+
for (const c of cursors) if (c < min) min = c;
|
|
449
|
+
const consumed = min - base;
|
|
450
|
+
if (min !== Infinity && consumed > 0) {
|
|
451
|
+
for (let i = 0; i < consumed; i++) windowBytes -= sizes[i];
|
|
452
|
+
buffer.splice(0, consumed);
|
|
453
|
+
sizes.splice(0, consumed);
|
|
454
|
+
base = min;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (buffer.length < cap && windowBytes < capBytes) resumeProducer();
|
|
458
|
+
};
|
|
459
|
+
const closeBranch = (me) => {
|
|
460
|
+
if (cursors[me] === Infinity) return;
|
|
461
|
+
cursors[me] = Infinity;
|
|
462
|
+
active--;
|
|
463
|
+
if (me === 0 && !stopped) {
|
|
464
|
+
stopped = true;
|
|
465
|
+
done = true;
|
|
466
|
+
resumeProducer();
|
|
467
|
+
try {
|
|
468
|
+
const r = iterator.return?.();
|
|
469
|
+
if (r && typeof r.then === "function") r.catch(() => {});
|
|
470
|
+
} catch {}
|
|
471
|
+
wakeAll();
|
|
472
|
+
}
|
|
473
|
+
if (active === 0) {
|
|
474
|
+
buffer.length = 0;
|
|
475
|
+
sizes.length = 0;
|
|
476
|
+
windowBytes = 0;
|
|
477
|
+
} else trim();
|
|
478
|
+
};
|
|
479
|
+
const serve = (me, p) => {
|
|
480
|
+
const i = cursors[me];
|
|
481
|
+
if (i === Infinity) return p.resolve(doneResult);
|
|
482
|
+
if (i < base + buffer.length) {
|
|
483
|
+
const value = buffer[i - base];
|
|
484
|
+
cursors[me] = i + 1;
|
|
485
|
+
trim();
|
|
486
|
+
return p.resolve({
|
|
487
|
+
done: false,
|
|
488
|
+
value
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
if (failed) return p.reject(sourceError);
|
|
492
|
+
if (done) {
|
|
493
|
+
closeBranch(me);
|
|
494
|
+
return p.resolve(doneResult);
|
|
495
|
+
}
|
|
496
|
+
pending[me] = p;
|
|
497
|
+
};
|
|
498
|
+
const wakeAll = () => {
|
|
499
|
+
for (let b = 0; b < branches; b++) {
|
|
500
|
+
const p = pending[b];
|
|
501
|
+
if (!p) continue;
|
|
502
|
+
pending[b] = null;
|
|
503
|
+
serve(b, p);
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
(async () => {
|
|
507
|
+
try {
|
|
508
|
+
while (!stopped) {
|
|
509
|
+
const result = await iterator.next();
|
|
510
|
+
if (result.done || stopped) break;
|
|
511
|
+
buffer.push(result.value);
|
|
512
|
+
sizes.push(teeChunkCost(result.value));
|
|
513
|
+
windowBytes += sizes[sizes.length - 1];
|
|
514
|
+
wakeAll();
|
|
515
|
+
if ((buffer.length >= cap || windowBytes >= capBytes) && active > 0 && !stopped) await new Promise((resolve) => {
|
|
516
|
+
drainResume = resolve;
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
} catch (error) {
|
|
520
|
+
failed = true;
|
|
521
|
+
sourceError = error;
|
|
522
|
+
} finally {
|
|
523
|
+
done = true;
|
|
524
|
+
wakeAll();
|
|
525
|
+
}
|
|
526
|
+
})();
|
|
527
|
+
const makeBranch = (me) => ({
|
|
528
|
+
[Symbol.asyncIterator]() {
|
|
529
|
+
return this;
|
|
530
|
+
},
|
|
531
|
+
next: () => new Promise((resolve, reject) => serve(me, {
|
|
532
|
+
resolve,
|
|
533
|
+
reject
|
|
534
|
+
})),
|
|
535
|
+
return: (value) => {
|
|
536
|
+
const p = pending[me];
|
|
537
|
+
if (p) {
|
|
538
|
+
pending[me] = null;
|
|
539
|
+
p.resolve(doneResult);
|
|
540
|
+
}
|
|
541
|
+
closeBranch(me);
|
|
542
|
+
return Promise.resolve({
|
|
543
|
+
done: true,
|
|
544
|
+
value
|
|
545
|
+
});
|
|
546
|
+
},
|
|
547
|
+
throw: (error) => {
|
|
548
|
+
const p = pending[me];
|
|
549
|
+
if (p) {
|
|
550
|
+
pending[me] = null;
|
|
551
|
+
p.resolve(doneResult);
|
|
552
|
+
}
|
|
553
|
+
closeBranch(me);
|
|
554
|
+
return Promise.reject(error);
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
return Array.from({ length: branches }, (_, b) => makeBranch(b));
|
|
307
558
|
}
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
});
|
|
559
|
+
|
|
560
|
+
//#endregion
|
|
561
|
+
exports.createResponseHandler = createResponseHandler;
|
|
562
|
+
exports.createStreamHandler = createStreamHandler;
|
|
563
|
+
exports.handleFile = handleFile;
|
|
564
|
+
exports.handleSet = handleSet;
|
|
565
|
+
exports.materializeSetHeaders = materializeSetHeaders;
|
|
566
|
+
exports.normalizeContentType = normalizeContentType;
|
|
567
|
+
exports.parseSetCookies = parseSetCookies;
|
|
568
|
+
exports.responseToSetHeaders = responseToSetHeaders;
|
|
569
|
+
exports.streamResponse = streamResponse;
|
|
570
|
+
exports.tee = tee;
|