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/types.d.ts
CHANGED
|
@@ -1,1271 +1,974 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
1
|
+
import { CookieOptions } from "./cookie/types.js";
|
|
2
|
+
import { StatusMapBack } from "./constants.js";
|
|
3
|
+
import { ElysiaError, ElysiaStatus } from "./error.js";
|
|
4
|
+
import { TraceHandler } from "./trace.js";
|
|
5
|
+
import { ElysiaFile } from "./universal/file.js";
|
|
6
|
+
import { Serve } from "./universal/server.js";
|
|
7
|
+
import { ChainNode } from "./utils.js";
|
|
8
|
+
import { Context, ErrorContext, LifecycleContext, PreContext } from "./context.js";
|
|
9
|
+
import { AnySchema, StandardSchemaV1Like, TypeBoxSchema } from "./type/types.js";
|
|
10
|
+
import { AnyElysia, Elysia } from "./base.js";
|
|
11
|
+
import { ElysiaAdapter } from "./adapter/index.js";
|
|
12
|
+
import { Static, StaticDecode, StaticEncode, TIntersect, TObject, TSchema } from "typebox";
|
|
13
|
+
import { OpenAPIV3 } from "openapi-types";
|
|
14
|
+
|
|
15
|
+
//#region src/types.d.ts
|
|
16
|
+
interface ElysiaConfig<in out Prefix extends string | undefined, in out Scope extends EventScope, in out Adapter extends ElysiaAdapter = ElysiaAdapter> {
|
|
17
|
+
/**
|
|
18
|
+
* Define event scope for the instance
|
|
19
|
+
*
|
|
20
|
+
* @since 2.0.0
|
|
21
|
+
*/
|
|
22
|
+
as?: Scope;
|
|
23
|
+
/**
|
|
24
|
+
* @default BunAdapter v2
|
|
25
|
+
* @since 2.0.0
|
|
26
|
+
*/
|
|
27
|
+
adapter?: Adapter;
|
|
28
|
+
/**
|
|
29
|
+
* Path prefix of the instance
|
|
30
|
+
*
|
|
31
|
+
* @default '''
|
|
32
|
+
*/
|
|
33
|
+
prefix?: Prefix;
|
|
34
|
+
/**
|
|
35
|
+
* Name of the instance for debugging, and plugin deduplication purpose
|
|
36
|
+
*/
|
|
37
|
+
name?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Seed for generating checksum for plugin deduplication
|
|
40
|
+
*
|
|
41
|
+
* @see https://elysiajs.com/essential/plugin.html#plugin-deduplication
|
|
42
|
+
*/
|
|
43
|
+
seed?: unknown;
|
|
44
|
+
/**
|
|
45
|
+
* Bun serve
|
|
46
|
+
*
|
|
47
|
+
* @see https://bun.sh/docs/api/http
|
|
48
|
+
*/
|
|
49
|
+
serve?: Partial<Serve>;
|
|
50
|
+
/**
|
|
51
|
+
* OpenAPI documentation (use in Swagger)
|
|
52
|
+
*
|
|
53
|
+
* @see https://swagger.io/specification/
|
|
54
|
+
*/
|
|
55
|
+
detail?: DocumentDecoration;
|
|
56
|
+
/**
|
|
57
|
+
* OpenAPI tags
|
|
58
|
+
*
|
|
59
|
+
* current instance' routes with tags
|
|
60
|
+
*
|
|
61
|
+
* @see https://swagger.io/specification/#tag-object
|
|
62
|
+
*/
|
|
63
|
+
tags?: DocumentDecoration['tags'];
|
|
64
|
+
/**
|
|
65
|
+
* Warm up Elysia before starting the server
|
|
66
|
+
*
|
|
67
|
+
* This will perform Ahead of Time compilation and generate code for route handlers
|
|
68
|
+
*
|
|
69
|
+
* If set to false, Elysia will perform Just in Time compilation
|
|
70
|
+
*
|
|
71
|
+
* Only required for root instance (instance which use listen) to effect
|
|
72
|
+
*
|
|
73
|
+
* ! If performing a benchmark, it's recommended to set this to `true`
|
|
74
|
+
*
|
|
75
|
+
* @default false
|
|
76
|
+
*/
|
|
77
|
+
precompile?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Whether should Elysia tolerate suffix '/' or vice-versa
|
|
80
|
+
*
|
|
81
|
+
* @default false
|
|
82
|
+
*/
|
|
83
|
+
strictPath?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Abort processing when request is aborted
|
|
86
|
+
*
|
|
87
|
+
* When enabled, Elysia checks the abort state after each lifecycle stage
|
|
88
|
+
* and returns an empty response instead of running the remaining hooks and
|
|
89
|
+
* handler.
|
|
90
|
+
*
|
|
91
|
+
* @default true
|
|
92
|
+
*/
|
|
93
|
+
abortSignal?: boolean;
|
|
94
|
+
cookie?: CookieOptions & {
|
|
95
|
+
/**
|
|
96
|
+
* Specified cookie name to be signed globally
|
|
97
|
+
*/
|
|
98
|
+
sign?: true | string | string[];
|
|
99
|
+
/**
|
|
100
|
+
* Verify signed cookies lazily on access or eagerly at request entry.
|
|
101
|
+
* @default 'lazy'
|
|
102
|
+
*/
|
|
103
|
+
verify?: 'lazy' | 'eager';
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Retain the metadata required by introspection tooling after sealing.
|
|
107
|
+
* Plugins that provide introspection may enable this for their host.
|
|
108
|
+
*
|
|
109
|
+
* @default false
|
|
110
|
+
*/
|
|
111
|
+
introspect?: boolean;
|
|
112
|
+
/**
|
|
113
|
+
* If enabled, Elysia will attempt to coerce value to defined type on incoming and outgoing bodies.
|
|
114
|
+
*
|
|
115
|
+
* This allows for sending unknown or disallowed properties in the bodies. These will simply be filtered out instead of failing the request.
|
|
116
|
+
* This has no effect when the schemas allow additional properties.
|
|
117
|
+
* Since this uses dynamic schema it may have an impact on performance.
|
|
118
|
+
*
|
|
119
|
+
* options:
|
|
120
|
+
* - true: use 'exactMirror'
|
|
121
|
+
* - false: do not normalize the value
|
|
122
|
+
* - 'exactMirror': use Elysia's custom exact-mirror which precompile a schema
|
|
123
|
+
* - 'typebox': Since this uses dynamic Value.Clean, it have performance impact
|
|
124
|
+
*
|
|
125
|
+
* Note: This option only works when Elysia schema is provided, doesn't work with Standard Schema
|
|
126
|
+
*
|
|
127
|
+
* @default 'exactMirror'
|
|
128
|
+
*/
|
|
129
|
+
normalize?: boolean | 'exactMirror' | 'typebox';
|
|
130
|
+
handler?: {
|
|
131
|
+
/**
|
|
132
|
+
* optimization for standard internet hostname
|
|
133
|
+
* this will assume hostname is always use a standard internet hostname
|
|
134
|
+
* assuming hostname is at minimum of 11 length of string (http://a.bc)
|
|
96
135
|
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* @default false
|
|
100
|
-
*/
|
|
101
|
-
precompile?: boolean | {
|
|
102
|
-
/**
|
|
103
|
-
* Perform dynamic code generation for route handlers before starting the server
|
|
104
|
-
*
|
|
105
|
-
* @default false
|
|
106
|
-
*/
|
|
107
|
-
compose?: boolean;
|
|
108
|
-
/**
|
|
109
|
-
* Perform Ahead of Time compilation for schema before starting the server
|
|
110
|
-
*
|
|
111
|
-
* @default false
|
|
112
|
-
*/
|
|
113
|
-
schema?: boolean;
|
|
114
|
-
};
|
|
115
|
-
/**
|
|
116
|
-
* Enable Ahead of Time compilation
|
|
117
|
-
*
|
|
118
|
-
* Trade significant performance with slightly faster startup time and reduced memory usage
|
|
119
|
-
*/
|
|
120
|
-
aot?: boolean;
|
|
121
|
-
/**
|
|
122
|
-
* Whether should Elysia tolerate suffix '/' or vice-versa
|
|
123
|
-
*
|
|
124
|
-
* @default false
|
|
125
|
-
*/
|
|
126
|
-
strictPath?: boolean;
|
|
127
|
-
/**
|
|
128
|
-
* Override websocket configuration
|
|
129
|
-
*
|
|
130
|
-
* @see https://bun.sh/docs/api/websockets
|
|
131
|
-
*/
|
|
132
|
-
websocket?: Omit<WebSocketHandler<any>, 'open' | 'close' | 'message' | 'drain'>;
|
|
133
|
-
cookie?: CookieOptions & {
|
|
134
|
-
/**
|
|
135
|
-
* Specified cookie name to be signed globally
|
|
136
|
-
*/
|
|
137
|
-
sign?: true | string | string[];
|
|
138
|
-
};
|
|
139
|
-
/**
|
|
140
|
-
* Capture more detail information for each dependencies
|
|
141
|
-
*/
|
|
142
|
-
analytic?: boolean;
|
|
143
|
-
/**
|
|
144
|
-
* If enabled, the schema with `t.Transform` will call `Encode` before sending the response
|
|
145
|
-
*
|
|
146
|
-
* @default true
|
|
147
|
-
* @since 1.3.0
|
|
148
|
-
* @since 1.2.16 (experimental)
|
|
149
|
-
**/
|
|
150
|
-
encodeSchema?: boolean;
|
|
151
|
-
/**
|
|
152
|
-
* Enable experimental features
|
|
153
|
-
*/
|
|
154
|
-
experimental?: {};
|
|
155
|
-
/**
|
|
156
|
-
* If enabled, Elysia will attempt to coerce value to defined type on incoming and outgoing bodies.
|
|
157
|
-
*
|
|
158
|
-
* This allows for sending unknown or disallowed properties in the bodies. These will simply be filtered out instead of failing the request.
|
|
159
|
-
* This has no effect when the schemas allow additional properties.
|
|
160
|
-
* Since this uses dynamic schema it may have an impact on performance.
|
|
161
|
-
*
|
|
162
|
-
* options:
|
|
163
|
-
* - true: use 'exactMirror'
|
|
164
|
-
* - false: do not normalize the value
|
|
165
|
-
* - 'exactMirror': use Elysia's custom exact-mirror which precompile a schema
|
|
166
|
-
* - 'typebox': Since this uses dynamic Value.Clean, it have performance impact
|
|
167
|
-
*
|
|
168
|
-
* Note: This option only works when Elysia schema is provided, doesn't work with Standard Schema
|
|
136
|
+
* setting this to true will skip the first 11 character of the hostname
|
|
169
137
|
*
|
|
170
138
|
* @default true
|
|
171
139
|
*/
|
|
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
|
-
scoped: SchemaValidator | null;
|
|
216
|
-
local: SchemaValidator | null;
|
|
217
|
-
getCandidate(): SchemaValidator;
|
|
218
|
-
}
|
|
219
|
-
export interface StandaloneInputSchema<Name extends string = string> {
|
|
220
|
-
body?: AnySchema | Name | `${Name}[]`;
|
|
221
|
-
headers?: AnySchema | Name | `${Name}[]`;
|
|
222
|
-
query?: AnySchema | Name | `${Name}[]`;
|
|
223
|
-
params?: AnySchema | Name | `${Name}[]`;
|
|
224
|
-
cookie?: AnySchema | Name | `${Name}[]`;
|
|
225
|
-
response?: {
|
|
226
|
-
[status in number]: `${Name}[]` | Name | AnySchema;
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
export interface StandaloneValidator {
|
|
230
|
-
global: InputSchema[] | null;
|
|
231
|
-
scoped: InputSchema[] | null;
|
|
232
|
-
local: InputSchema[] | null;
|
|
233
|
-
}
|
|
234
|
-
export type MaybeArray<T> = T | T[];
|
|
235
|
-
export type MaybeReadonlyArray<T> = T | readonly T[];
|
|
236
|
-
export type MaybePromise<T> = T | Promise<T>;
|
|
237
|
-
export type ObjectValues<T extends object> = T[keyof T];
|
|
238
|
-
type IsPathParameter<Part extends string> = Part extends `:${infer Parameter}` ? Parameter : Part extends `*` ? '*' : never;
|
|
239
|
-
export type GetPathParameter<Path extends string> = Path extends `${infer A}/${infer B}` ? IsPathParameter<A> | GetPathParameter<B> : IsPathParameter<Path>;
|
|
240
|
-
type _ResolvePath<Path extends string> = {
|
|
241
|
-
[Param in GetPathParameter<Path> as Param extends `${string}?` ? never : Param]: string;
|
|
242
|
-
} & {
|
|
243
|
-
[Param in GetPathParameter<Path> as Param extends `${infer OptionalParam}?` ? OptionalParam : never]?: string;
|
|
140
|
+
standardHostname?: boolean;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Enable Bun adapter native static response collection for eligible literal
|
|
144
|
+
* static routes.
|
|
145
|
+
*
|
|
146
|
+
* @default true
|
|
147
|
+
* @since 1.1.11
|
|
148
|
+
*/
|
|
149
|
+
nativeStaticResponse?: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* Array of callback function to transform a string value defined in a schema
|
|
152
|
+
*
|
|
153
|
+
* This option only works when `sanitlize` is `exactMirror`
|
|
154
|
+
*
|
|
155
|
+
* This only works when set on the main instance
|
|
156
|
+
*
|
|
157
|
+
* @default true
|
|
158
|
+
* @since 1.3.0
|
|
159
|
+
*/
|
|
160
|
+
sanitize?: ((value: string) => string) | ((value: string) => string)[];
|
|
161
|
+
/**
|
|
162
|
+
* Allow unsafe validation details in errors thrown by Elysia's schema validator (422 status code)
|
|
163
|
+
*
|
|
164
|
+
* Ideally, this should only be used in development environment or public APIs
|
|
165
|
+
* This may leak sensitive information about the server implementation and should be used with caution in production environments.
|
|
166
|
+
*
|
|
167
|
+
* @default false
|
|
168
|
+
*/
|
|
169
|
+
allowUnsafeValidationDetails?: boolean;
|
|
170
|
+
}
|
|
171
|
+
interface DocumentDecoration extends Partial<OpenAPIV3.OperationObject> {
|
|
172
|
+
/**
|
|
173
|
+
* Pass `true` to hide route from OpenAPI/swagger document
|
|
174
|
+
* */
|
|
175
|
+
hide?: boolean;
|
|
176
|
+
}
|
|
177
|
+
type Prettify<in out T> = { [K in keyof T]: T[K] } & {};
|
|
178
|
+
type SSEPayload<Data = unknown, Event extends string | undefined = string | undefined> = {
|
|
179
|
+
id?: string | number | null;
|
|
180
|
+
event?: Event;
|
|
181
|
+
retry?: number;
|
|
182
|
+
data?: Data;
|
|
244
183
|
};
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
type IsClass<V> = V extends abstract new (...args: any) => any ? true : false;
|
|
255
|
-
export type Reconcile<A extends Object, B extends Object, Override extends boolean = false, Stack extends number[] = []> = Stack['length'] extends 16 ? A : Override extends true ? {
|
|
256
|
-
[key in keyof A as key extends keyof B ? never : key]: A[key];
|
|
257
|
-
} extends infer Collision ? {} extends Collision ? {
|
|
258
|
-
[key in keyof B]: IsBothObject<A[key], B[key]> extends true ? Reconcile<A[key], B[key], Override, [
|
|
259
|
-
0,
|
|
260
|
-
...Stack
|
|
261
|
-
]> : B[key];
|
|
262
|
-
} : Prettify<Collision & {
|
|
263
|
-
[key in keyof B]: B[key];
|
|
264
|
-
}> : never : {
|
|
265
|
-
[key in keyof B as key extends keyof A ? never : key]: B[key];
|
|
266
|
-
} extends infer Collision ? {} extends Collision ? {
|
|
267
|
-
[key in keyof A]: IsBothObject<A[key], B[key]> extends true ? Reconcile<A[key], B[key], Override, [
|
|
268
|
-
0,
|
|
269
|
-
...Stack
|
|
270
|
-
]> : A[key];
|
|
271
|
-
} : Prettify<{
|
|
272
|
-
[key in keyof A]: A[key];
|
|
273
|
-
} & Collision> : never;
|
|
274
|
-
export interface SingletonBase {
|
|
275
|
-
decorator: Record<string, unknown>;
|
|
276
|
-
store: Record<string, unknown>;
|
|
277
|
-
derive: Record<string, unknown>;
|
|
278
|
-
resolve: Record<string, unknown>;
|
|
279
|
-
}
|
|
280
|
-
export interface PossibleResponse {
|
|
281
|
-
[status: number]: unknown;
|
|
282
|
-
}
|
|
283
|
-
export interface EphemeralType {
|
|
284
|
-
derive: SingletonBase['derive'];
|
|
285
|
-
resolve: SingletonBase['resolve'];
|
|
286
|
-
schema: MetadataBase['schema'];
|
|
287
|
-
standaloneSchema: MetadataBase['schema'];
|
|
288
|
-
response: PossibleResponse;
|
|
289
|
-
}
|
|
290
|
-
export interface DefinitionBase {
|
|
291
|
-
typebox: Record<string, AnySchema>;
|
|
292
|
-
error: Record<string, Error>;
|
|
293
|
-
}
|
|
294
|
-
export type RouteBase = Record<string, unknown>;
|
|
295
|
-
export interface MetadataBase {
|
|
296
|
-
schema: RouteSchema;
|
|
297
|
-
standaloneSchema: MetadataBase['schema'];
|
|
298
|
-
macro: BaseMacro;
|
|
299
|
-
macroFn: Macro;
|
|
300
|
-
parser: Record<string, BodyHandler<any, any>>;
|
|
301
|
-
response: PossibleResponse;
|
|
302
|
-
}
|
|
303
|
-
export interface RouteSchema {
|
|
304
|
-
body?: unknown;
|
|
305
|
-
headers?: unknown;
|
|
306
|
-
query?: unknown;
|
|
307
|
-
params?: unknown;
|
|
308
|
-
cookie?: unknown;
|
|
309
|
-
response?: unknown;
|
|
310
|
-
}
|
|
311
|
-
interface OptionalField {
|
|
312
|
-
[OptionalKind]: 'Optional';
|
|
313
|
-
}
|
|
314
|
-
export type UnwrapSchema<Schema extends AnySchema | string | undefined, Definitions extends DefinitionBase['typebox'] = {}> = Schema extends undefined ? unknown : Schema extends TSchema ? Schema extends OptionalField ? Partial<TImport<Definitions & {
|
|
315
|
-
readonly __elysia: Schema;
|
|
316
|
-
}, '__elysia'>['static']> : TImport<Definitions & {
|
|
317
|
-
readonly __elysia: Schema;
|
|
318
|
-
}, '__elysia'>['static'] : Schema extends FastStandardSchemaV1Like ? NonNullable<Schema['~standard']['types']>['output'] : Schema extends string ? Schema extends keyof Definitions ? Definitions[Schema] extends TAnySchema ? TImport<Definitions, Schema>['static'] : NonNullable<Definitions[Schema]['~standard']['types']>['output'] : unknown : unknown;
|
|
319
|
-
export type UnwrapBodySchema<Schema extends AnySchema | string | undefined, Definitions extends DefinitionBase['typebox'] = {}> = undefined extends Schema ? unknown : Schema extends TSchema ? Schema extends OptionalField ? Partial<TImport<Definitions & {
|
|
320
|
-
readonly __elysia: Schema;
|
|
321
|
-
}, '__elysia'>['static']> | null : TImport<Definitions & {
|
|
322
|
-
readonly __elysia: Schema;
|
|
323
|
-
}, '__elysia'>['static'] : Schema extends FastStandardSchemaV1Like ? NonNullable<Schema['~standard']['types']>['output'] : Schema extends string ? Schema extends keyof Definitions ? Definitions[Schema] extends TAnySchema ? TImport<Definitions, Schema>['static'] : NonNullable<Definitions[Schema]['~standard']['types']>['output'] : unknown : unknown;
|
|
324
|
-
export interface UnwrapRoute<in out Schema extends InputSchema<any>, in out Definitions extends DefinitionBase['typebox'] = {}, in out Path extends string = ''> {
|
|
325
|
-
body: UnwrapBodySchema<Schema['body'], Definitions>;
|
|
326
|
-
headers: UnwrapSchema<Schema['headers'], Definitions>;
|
|
327
|
-
query: UnwrapSchema<Schema['query'], Definitions>;
|
|
328
|
-
params: {} extends Schema['params'] ? ResolvePath<Path> : {} extends Schema ? ResolvePath<Path> : UnwrapSchema<Schema['params'], Definitions>;
|
|
329
|
-
cookie: UnwrapSchema<Schema['cookie'], Definitions>;
|
|
330
|
-
response: Schema['response'] extends FastAnySchema | string ? {
|
|
331
|
-
200: UnwrapSchema<Schema['response'], Definitions> extends infer A ? A extends File ? File | ElysiaFile : A : unknown;
|
|
332
|
-
} : Schema['response'] extends {
|
|
333
|
-
[status in number]: FastAnySchema | string;
|
|
334
|
-
} ? {
|
|
335
|
-
[k in keyof Schema['response']]: UnwrapSchema<Schema['response'][k], Definitions> extends infer A ? A extends File ? File | ElysiaFile : A : unknown;
|
|
336
|
-
} : unknown | void;
|
|
337
|
-
}
|
|
338
|
-
export interface UnwrapGroupGuardRoute<in out Schema extends InputSchema<any>, in out Definitions extends DefinitionBase['typebox'] = {}, Path extends string | undefined = undefined> {
|
|
339
|
-
body: UnwrapBodySchema<Schema['body'], Definitions>;
|
|
340
|
-
headers: UnwrapSchema<Schema['headers'], Definitions> extends infer A extends Record<string, any> ? A : undefined;
|
|
341
|
-
query: UnwrapSchema<Schema['query'], Definitions> extends infer A extends Record<string, any> ? A : undefined;
|
|
342
|
-
params: UnwrapSchema<Schema['params'], Definitions> extends infer A extends Record<string, any> ? A : Path extends PathParameterLike ? Record<GetPathParameter<Path>, string> : never;
|
|
343
|
-
cookie: UnwrapSchema<Schema['cookie'], Definitions> extends infer A extends Record<string, any> ? A : undefined;
|
|
344
|
-
response: Schema['response'] extends TSchema | string ? UnwrapSchema<Schema['response'], Definitions> : Schema['response'] extends {
|
|
345
|
-
[k in string]: TSchema | string;
|
|
346
|
-
} ? UnwrapSchema<Schema['response'][keyof Schema['response']], Definitions> : unknown | void;
|
|
347
|
-
}
|
|
348
|
-
export type HookContainer<T extends Function = Function> = {
|
|
349
|
-
checksum?: number;
|
|
350
|
-
scope?: LifeCycleType;
|
|
351
|
-
subType?: 'derive' | 'resolve' | 'mapDerive' | 'mapResolve' | (string & {});
|
|
352
|
-
fn: T;
|
|
353
|
-
isAsync?: boolean;
|
|
354
|
-
hasReturn?: boolean;
|
|
184
|
+
type MaybeArray<T> = T | T[];
|
|
185
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
186
|
+
type IsAny<T> = 0 extends 1 & T ? true : false;
|
|
187
|
+
type IsTuple<T> = T extends readonly any[] ? number extends T['length'] ? false : true : false;
|
|
188
|
+
type Replace<Original, Target, With> = IsAny<Target> extends true ? Original : Original extends Record<string, unknown> ? { [K in keyof Original]: Original[K] extends Target ? With : Original[K] } : Original extends Target ? With : Original;
|
|
189
|
+
type EventScope = 'global' | 'local' | 'plugin';
|
|
190
|
+
type GuardSchemaType = 'override' | 'merge';
|
|
191
|
+
type ElysiaFormData<T extends Record<keyof any, unknown>> = FormData & {
|
|
192
|
+
['~ely-form']: Replace<T, Blob | ElysiaFile, File> extends infer A ? { [key in keyof A]: IsTuple<A[key]> extends true ? A[key][number] extends Blob | ElysiaFile ? File[] : A[key] : A[key] } : T;
|
|
355
193
|
};
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
194
|
+
type ContentType = MaybeArray<'none' | 'text' | 'json' | 'formdata' | 'urlencoded' | 'arrayBuffer' | 'text/plain' | 'application/json' | 'multipart/form-data' | 'application/x-www-form-urlencoded' | 'application/octet-stream'>;
|
|
195
|
+
type HTTPMethod = (string & {}) | 'ACL' | 'BIND' | 'CHECKOUT' | 'CONNECT' | 'COPY' | 'DELETE' | 'GET' | 'HEAD' | 'LINK' | 'LOCK' | 'M-SEARCH' | 'MERGE' | 'MKACTIVITY' | 'MKCALENDAR' | 'MKCOL' | 'MOVE' | 'NOTIFY' | 'OPTIONS' | 'PATCH' | 'POST' | 'PROPFIND' | 'PROPPATCH' | 'PURGE' | 'PUT' | 'REBIND' | 'REPORT' | 'SEARCH' | 'SOURCE' | 'SUBSCRIBE' | 'TRACE' | 'UNBIND' | 'UNLINK' | 'UNLOCK' | 'UNSUBSCRIBE' | 'ALL';
|
|
196
|
+
type UnwrapArray<T> = T extends (infer U)[] ? U : T;
|
|
197
|
+
type AppEvent = 'start' | 'stop' | 'request' | 'parse' | 'transform' | 'beforeHandle' | 'afterHandle' | 'mapResponse' | 'afterResponse' | 'error' | 'trace';
|
|
198
|
+
interface AppHook {
|
|
199
|
+
start: GracefulHandler<any>[];
|
|
200
|
+
stop: GracefulHandler<any>[];
|
|
201
|
+
request: VoidHandler<any, any>[];
|
|
202
|
+
parse: (string | BodyHandler<any, any>)[];
|
|
203
|
+
transform: TransformHandler<any, any>[];
|
|
204
|
+
beforeHandle: OptionalHandler<any, any>[];
|
|
205
|
+
afterHandle: AfterHandler<any, any>[];
|
|
206
|
+
mapResponse: MapResponse<any, any>[];
|
|
207
|
+
afterResponse: AfterResponseHandler<any, any>[];
|
|
208
|
+
error: ErrorHandler<any, any, any>[];
|
|
209
|
+
trace: TraceHandler<any, any>[];
|
|
210
|
+
body: AnySchema;
|
|
211
|
+
headers: AnySchema;
|
|
212
|
+
query: AnySchema;
|
|
213
|
+
params: AnySchema;
|
|
214
|
+
cookie: AnySchema;
|
|
215
|
+
response: AnySchema | Record<number, AnySchema>;
|
|
216
|
+
schemas: RouteSchema[];
|
|
217
|
+
}
|
|
218
|
+
interface InputSchema<Name extends string = string> {
|
|
219
|
+
body?: Name | AnySchema;
|
|
220
|
+
headers?: Name | AnySchema;
|
|
221
|
+
query?: Name | AnySchema;
|
|
222
|
+
params?: Name | AnySchema;
|
|
223
|
+
cookie?: Name | AnySchema;
|
|
224
|
+
response?: Name | AnySchema | Record<number, Name | AnySchema>;
|
|
225
|
+
}
|
|
226
|
+
type InputSchemaKey = keyof InputSchema;
|
|
227
|
+
interface EmptyInputSchema {
|
|
228
|
+
body: unknown;
|
|
229
|
+
headers: unknown;
|
|
230
|
+
query: unknown;
|
|
231
|
+
params: {};
|
|
232
|
+
cookie: unknown;
|
|
233
|
+
response: unknown;
|
|
234
|
+
}
|
|
235
|
+
type LocalHook<Input extends BaseMacro, Schema extends RouteSchemaWithResolvedMacro, Singleton extends SingletonBase, Errors extends ErrorDefinition[], Parser extends keyof any = ''> = {
|
|
236
|
+
detail?: DocumentDecoration;
|
|
237
|
+
/**
|
|
238
|
+
* Short for 'Content-Type'
|
|
239
|
+
*
|
|
240
|
+
* Available:
|
|
241
|
+
* - 'none': do not parse body
|
|
242
|
+
* - 'text' / 'text/plain': parse body as string
|
|
243
|
+
* - 'json' / 'application/json': parse body as json
|
|
244
|
+
* - 'formdata' / 'multipart/form-data': parse body as form-data
|
|
245
|
+
* - 'urlencoded' / 'application/x-www-form-urlencoded: parse body as urlencoded
|
|
246
|
+
* - 'arraybuffer': parse body as readable stream
|
|
247
|
+
*/
|
|
248
|
+
parse?: MaybeArray<BodyHandler<Schema, Singleton & {
|
|
249
|
+
derive: Schema['resolve'];
|
|
250
|
+
}> | ContentType | Parser>;
|
|
251
|
+
/**
|
|
252
|
+
* Transform context's value
|
|
253
|
+
*/
|
|
254
|
+
transform?: MaybeArray<TransformHandler<Schema, Singleton & {
|
|
255
|
+
derive: Schema['resolve'];
|
|
256
|
+
}>>;
|
|
257
|
+
/**
|
|
258
|
+
* Execute before main handler
|
|
259
|
+
*/
|
|
260
|
+
beforeHandle?: MaybeArray<OptionalHandler<Schema, Singleton & {
|
|
261
|
+
derive: Schema['resolve'];
|
|
262
|
+
}>>;
|
|
263
|
+
/**
|
|
264
|
+
* Execute after main handler
|
|
265
|
+
*/
|
|
266
|
+
afterHandle?: MaybeArray<AfterHandler<Schema, Singleton & {
|
|
267
|
+
derive: Schema['resolve'];
|
|
268
|
+
}>>;
|
|
269
|
+
/**
|
|
270
|
+
* Execute after main handler
|
|
271
|
+
*/
|
|
272
|
+
mapResponse?: MaybeArray<MapResponse<Schema, Singleton & {
|
|
273
|
+
derive: Schema['resolve'];
|
|
274
|
+
}>>;
|
|
275
|
+
/**
|
|
276
|
+
* Execute after response is sent
|
|
277
|
+
*/
|
|
278
|
+
afterResponse?: MaybeArray<AfterResponseHandler<Schema, Singleton & {
|
|
279
|
+
derive: Schema['resolve'];
|
|
280
|
+
}>>;
|
|
281
|
+
/**
|
|
282
|
+
* Catch error
|
|
283
|
+
*/
|
|
284
|
+
error?: MaybeArray<ErrorHandler<Errors, Schema, Singleton & {
|
|
285
|
+
derive: Schema['resolve'];
|
|
286
|
+
}>>;
|
|
287
|
+
tags?: DocumentDecoration['tags'];
|
|
288
|
+
} & (Input extends any ? Input : Prettify<Input>);
|
|
289
|
+
type AnyLocalHook = LocalHook<any, any, any, any, any>;
|
|
290
|
+
type GuardLocalHook<Input extends BaseMacro | undefined, Schema extends RouteSchema, Singleton extends SingletonBase, Parser extends keyof any, BeforeHandle extends MaybeArray<OptionalHandler<any, any>>, AfterHandle extends MaybeArray<AfterHandler<any, any>>, ErrorHandle extends MaybeArray<ErrorHandler<any, any, any>>, GuardType extends GuardSchemaType = 'merge'> = (Input extends any ? Input : Prettify<Input>) & {
|
|
291
|
+
/**
|
|
292
|
+
* @default 'override'
|
|
293
|
+
* @since 1.3.0
|
|
294
|
+
*/
|
|
295
|
+
schema?: GuardType;
|
|
296
|
+
detail?: DocumentDecoration;
|
|
297
|
+
/**
|
|
298
|
+
* Short for 'Content-Type'
|
|
299
|
+
*
|
|
300
|
+
* Available:
|
|
301
|
+
* - 'none': do not parse body
|
|
302
|
+
* - 'text' / 'text/plain': parse body as string
|
|
303
|
+
* - 'json' / 'application/json': parse body as json
|
|
304
|
+
* - 'formdata' / 'multipart/form-data': parse body as form-data
|
|
305
|
+
* - 'urlencoded' / 'application/x-www-form-urlencoded: parse body as urlencoded
|
|
306
|
+
* - 'arraybuffer': parse body as readable stream
|
|
307
|
+
*/
|
|
308
|
+
parse?: MaybeArray<BodyHandler<Schema, Singleton> | ContentType | Parser>;
|
|
309
|
+
/**
|
|
310
|
+
* Transform context's value
|
|
311
|
+
*/
|
|
312
|
+
transform?: MaybeArray<TransformHandler<Schema, Singleton>>;
|
|
313
|
+
/**
|
|
314
|
+
* Execute before main handler
|
|
315
|
+
*/
|
|
316
|
+
beforeHandle?: BeforeHandle;
|
|
317
|
+
/**
|
|
318
|
+
* Execute after main handler
|
|
319
|
+
*/
|
|
320
|
+
afterHandle?: AfterHandle;
|
|
321
|
+
/**
|
|
322
|
+
* Execute after main handler
|
|
323
|
+
*/
|
|
324
|
+
mapResponse?: MaybeArray<MapResponse<Schema, Singleton>>;
|
|
325
|
+
/**
|
|
326
|
+
* Execute after response is sent
|
|
327
|
+
*/
|
|
328
|
+
afterResponse?: MaybeArray<AfterResponseHandler<Schema, Singleton>>;
|
|
329
|
+
/**
|
|
330
|
+
* Catch error
|
|
331
|
+
*/
|
|
332
|
+
error?: ErrorHandle;
|
|
333
|
+
tags?: DocumentDecoration['tags'];
|
|
334
|
+
};
|
|
335
|
+
type EventFn<T extends AppEvent> = UnwrapArray<AppHook[T]>;
|
|
336
|
+
interface SingletonBase {
|
|
337
|
+
decorator: Record<string, unknown>;
|
|
338
|
+
store: Record<string, unknown>;
|
|
339
|
+
derive: Record<string, unknown>;
|
|
340
|
+
}
|
|
341
|
+
interface ErrorDefinition {
|
|
342
|
+
error: Error;
|
|
343
|
+
response: PossibleResponse;
|
|
344
|
+
}
|
|
345
|
+
interface EphemeralType {
|
|
346
|
+
derive: SingletonBase['derive'];
|
|
347
|
+
schema: MetadataBase['schema'];
|
|
348
|
+
schemas: MetadataBase['schema'];
|
|
349
|
+
response: PossibleResponse;
|
|
350
|
+
error: ErrorDefinition[];
|
|
351
|
+
}
|
|
352
|
+
interface DefinitionBase {
|
|
353
|
+
typebox: Record<string, AnySchema>;
|
|
354
|
+
error: ErrorDefinition[];
|
|
355
|
+
}
|
|
356
|
+
interface DefaultEphemeral {
|
|
357
|
+
derive: {};
|
|
358
|
+
schema: {};
|
|
359
|
+
schemas: {};
|
|
360
|
+
response: {};
|
|
361
|
+
error: [];
|
|
362
|
+
}
|
|
363
|
+
interface DefaultSingleton {
|
|
364
|
+
decorator: {};
|
|
365
|
+
store: {};
|
|
366
|
+
derive: {};
|
|
367
|
+
}
|
|
368
|
+
interface DefaultMetadata {
|
|
369
|
+
schema: {};
|
|
370
|
+
schemas: {};
|
|
371
|
+
macro: {};
|
|
372
|
+
macroFn: {};
|
|
373
|
+
parser: {};
|
|
374
|
+
response: {};
|
|
375
|
+
}
|
|
376
|
+
type RouteBase = Record<string, unknown>;
|
|
377
|
+
type BaseMacro = Record<string, string | number | boolean | Object | undefined | null>;
|
|
378
|
+
interface PossibleResponse {
|
|
379
|
+
[status: number]: unknown;
|
|
380
|
+
}
|
|
381
|
+
interface MetadataBase {
|
|
382
|
+
schema: RouteSchema;
|
|
383
|
+
schemas: MetadataBase['schema'];
|
|
384
|
+
macro: BaseMacro;
|
|
385
|
+
macroFn: Macro;
|
|
386
|
+
parser: Record<string, BodyHandler<any, any>>;
|
|
387
|
+
response: PossibleResponse;
|
|
388
|
+
}
|
|
389
|
+
interface RouteSchema {
|
|
390
|
+
body?: unknown;
|
|
391
|
+
headers?: unknown;
|
|
392
|
+
query?: unknown;
|
|
393
|
+
params?: unknown;
|
|
394
|
+
cookie?: unknown;
|
|
395
|
+
response?: unknown;
|
|
396
|
+
}
|
|
397
|
+
type OptionalHandler<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = DefaultSingleton, Path extends string | undefined = undefined, ParamsScope extends 'local' | 'plugin' | 'global' = 'local'> = (context: LifecycleContext<Route, Singleton, Path, ParamsScope>) => MaybePromise<{} extends Route['response'] ? unknown : Route['response'][keyof Route['response']] | InlineHandlerResponse<Route['response']> | void>;
|
|
398
|
+
type AfterHandler<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = DefaultSingleton, Path extends string | undefined = undefined, ParamsScope extends 'local' | 'plugin' | 'global' = 'local'> = (context: LifecycleContext<Route, Singleton, Path, ParamsScope> & {
|
|
399
|
+
responseValue: {} extends Route['response'] ? unknown : Route['response'][keyof Route['response']];
|
|
400
|
+
}) => MaybePromise<{} extends Route['response'] ? unknown : Route['response'][keyof Route['response']] | InlineHandlerResponse<Route['response']> | void>;
|
|
401
|
+
type MapResponse<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = DefaultSingleton, Path extends string | undefined = undefined, ParamsScope extends 'local' | 'plugin' | 'global' = 'local'> = (context: LifecycleContext<Route, Singleton, Path, ParamsScope> & {
|
|
402
|
+
responseValue: {} extends Route['response'] ? unknown : Route['response'][keyof Route['response']];
|
|
403
|
+
}) => MaybePromise<Response | void>;
|
|
404
|
+
type VoidHandler<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = DefaultSingleton> = (context: Context<Route, Singleton>) => MaybePromise<void>;
|
|
405
|
+
type TransformHandler<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = DefaultSingleton, Path extends string | undefined = undefined, ParamsScope extends 'local' | 'plugin' | 'global' = 'local'> = (context: LifecycleContext<Route, Singleton, Path, ParamsScope>) => MaybePromise<void>;
|
|
406
|
+
type BodyHandler<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = DefaultSingleton, Path extends string | undefined = undefined, ParamsScope extends 'local' | 'plugin' | 'global' = 'local'> = (context: LifecycleContext<Route, Singleton & {
|
|
407
|
+
decorator: {
|
|
408
|
+
contentType: string;
|
|
409
|
+
};
|
|
410
|
+
}, Path, ParamsScope>) => MaybePromise<any>;
|
|
411
|
+
type PreHandler<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = DefaultSingleton> = (context: PreContext<Singleton>) => MaybePromise<Route['response'] | InlineHandlerResponse<Route['response']> | void>;
|
|
412
|
+
type AfterResponseHandler<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = DefaultSingleton, Path extends string | undefined = undefined, ParamsScope extends 'local' | 'plugin' | 'global' = 'local'> = (context: LifecycleContext<Route, Singleton, Path, ParamsScope> & {
|
|
413
|
+
responseValue: {} extends Route['response'] ? unknown : Route['response'][keyof Route['response']];
|
|
414
|
+
}) => MaybePromise<unknown>;
|
|
415
|
+
type GracefulHandler<in Instance extends AnyElysia> = (data: Instance) => any;
|
|
416
|
+
type ResolveHandler<in out Route extends RouteSchema, in out Singleton extends SingletonBase> = (context: Context<Route, Singleton>) => MaybePromise<Record<string, unknown> | ElysiaError | AnyElysiaStatus | void>;
|
|
417
|
+
interface BunHTMLBundlelike {
|
|
418
|
+
index: string;
|
|
419
|
+
files?: {
|
|
420
|
+
input?: string;
|
|
421
|
+
path: string;
|
|
422
|
+
loader: any;
|
|
423
|
+
isEntry: boolean;
|
|
424
|
+
headers: {
|
|
425
|
+
etag: string;
|
|
426
|
+
'content-type': string;
|
|
427
|
+
[key: string]: string;
|
|
383
428
|
};
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
}
|
|
395
|
-
|
|
396
|
-
|
|
429
|
+
}[];
|
|
430
|
+
}
|
|
431
|
+
type InlineResponse = string | number | boolean | Record<any, unknown> | Response | AnyElysiaStatus | ElysiaFile | Blob | BunHTMLBundlelike | Error;
|
|
432
|
+
type InlineHandlerResponse<Route extends RouteSchema['response']> = { [Status in keyof Route]: ElysiaStatus<Status, Route[Status], Status> }[keyof Route];
|
|
433
|
+
type InlineHandler<Route extends RouteSchema = {}, Singleton extends SingletonBase = DefaultSingleton, MacroContext extends {
|
|
434
|
+
response: PossibleResponse;
|
|
435
|
+
return: PossibleResponse;
|
|
436
|
+
resolve: Record<string, unknown>;
|
|
437
|
+
} = {
|
|
438
|
+
response: {};
|
|
439
|
+
return: {};
|
|
440
|
+
resolve: {};
|
|
441
|
+
}> = InlineHandlerNonMacro<Route & MacroContext, Singleton & {
|
|
442
|
+
derive: MacroContext['resolve'];
|
|
443
|
+
}>;
|
|
444
|
+
type InlineHandlerNonMacro<Route extends RouteSchema = {}, Singleton extends SingletonBase = DefaultSingleton> = MaybePromise<InlineHandlerResponse<Route['response']> | ({} extends Route['response'] ? InlineResponse : Route['response'][keyof Route['response']])> | ((context: Context<Route, Singleton>) => MaybePromise<Response> | MaybePromise<{} extends Route['response'] ? unknown : (Route['response'] extends {
|
|
445
|
+
200: any;
|
|
446
|
+
} ? Route['response'][200] | ElysiaStatus<200, Route['response'][200], 200> | Generator<Route['response'][200]> | AsyncGenerator<Route['response'][200]> : unknown) | Route['response'][keyof Route['response']] | InlineHandlerResponse<Route['response']>>);
|
|
447
|
+
type Handler = (context: Context) => unknown;
|
|
448
|
+
type CompiledHandler = (context: Partial<Context>) => MaybePromise<Response>;
|
|
449
|
+
type InternalRoute = readonly [method: string, path: string, handler: unknown, instance: AnyElysia, hook: AnyLocalHook | undefined, appHook: ChainNode | undefined, inheritedChain?: ChainNode, macroScope?: AnyElysia];
|
|
450
|
+
interface HistoryEntry {
|
|
451
|
+
readonly sequence: number;
|
|
452
|
+
readonly method: string;
|
|
453
|
+
readonly path: string;
|
|
454
|
+
readonly source?: string;
|
|
455
|
+
}
|
|
456
|
+
type ErrorHandler<T extends ErrorDefinition[] = [], in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = DefaultSingleton> = (context: ErrorContext<Route, {
|
|
457
|
+
store: Singleton['store'];
|
|
458
|
+
decorator: Singleton['decorator'];
|
|
459
|
+
derive: {};
|
|
460
|
+
}> & {
|
|
461
|
+
error: T[number]['error'] | Error;
|
|
462
|
+
}) => unknown;
|
|
463
|
+
type MergeSchema<A extends RouteSchema, B extends RouteSchema, Path extends string = '', AParamsPathDerived extends boolean = false> = {} extends A ? Path extends PathParameterLike ? Omit<B, 'params'> & {
|
|
464
|
+
params: ResolvePath<Path>;
|
|
397
465
|
} : B : {} extends B ? Path extends PathParameterLike ? Omit<A, 'params'> & {
|
|
398
|
-
|
|
466
|
+
params: ResolvePath<Path>;
|
|
399
467
|
} : A : {
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
468
|
+
body: undefined extends A['body'] ? B['body'] : A['body'];
|
|
469
|
+
headers: undefined extends A['headers'] ? B['headers'] : A['headers'];
|
|
470
|
+
query: undefined extends A['query'] ? B['query'] : A['query'];
|
|
471
|
+
params: AParamsPathDerived extends true ? IsNever<keyof B['params']> extends true ? A['params'] : B['params'] : IsNever<keyof A['params']> extends true ? IsNever<keyof B['params']> extends true ? ResolvePath<Path> : B['params'] : A['params'];
|
|
472
|
+
cookie: undefined extends A['cookie'] ? B['cookie'] : A['cookie'];
|
|
473
|
+
response: {} extends A['response'] ? {} extends B['response'] ? {} : B['response'] : {} extends B['response'] ? A['response'] : A['response'] & Omit<B['response'], keyof A['response']>;
|
|
406
474
|
};
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
475
|
+
type AnyWSLocalHook = any;
|
|
476
|
+
type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
|
|
477
|
+
type IsNever<T> = [T] extends [never] ? true : false;
|
|
478
|
+
type UnionToIntersect<U> = (U extends unknown ? (arg: U) => 0 : never) extends ((arg: infer I) => 0) ? I : never;
|
|
479
|
+
interface PublicRoute {
|
|
480
|
+
method: HTTPMethod;
|
|
481
|
+
path: string;
|
|
482
|
+
handler: Handler;
|
|
483
|
+
hooks: AnyLocalHook;
|
|
484
|
+
compile(): CompiledHandler;
|
|
485
|
+
websocket?: AnyWSLocalHook;
|
|
486
|
+
}
|
|
487
|
+
type MaybeValueOrVoidFunction<T> = T | ((...a: any) => void | T);
|
|
488
|
+
type MacroProperty<Macro extends BaseMacro = {}, TypedRoute extends RouteSchema = {}, Singleton extends SingletonBase = DefaultSingleton, Errors extends ErrorDefinition[] = []> = Macro & {
|
|
489
|
+
/**
|
|
490
|
+
* Deduplication similar to Elysia.constructor.seed
|
|
491
|
+
*/
|
|
492
|
+
seed?: unknown;
|
|
493
|
+
parse?: MaybeArray<BodyHandler<TypedRoute, Singleton>>;
|
|
494
|
+
transform?: MaybeArray<VoidHandler<TypedRoute, Singleton>>;
|
|
495
|
+
beforeHandle?: MaybeArray<OptionalHandler<TypedRoute, Singleton>>;
|
|
496
|
+
afterHandle?: MaybeArray<AfterHandler<TypedRoute, Singleton>>;
|
|
497
|
+
error?: MaybeArray<ErrorHandler<Errors, TypedRoute, Singleton>>;
|
|
498
|
+
mapResponse?: MaybeArray<MapResponse<TypedRoute, Singleton>>;
|
|
499
|
+
afterResponse?: MaybeArray<AfterResponseHandler<TypedRoute, Singleton>>;
|
|
500
|
+
derive?: MaybeArray<ResolveHandler<TypedRoute, Singleton>>;
|
|
501
|
+
detail?: DocumentDecoration;
|
|
502
|
+
/**
|
|
503
|
+
* Introspect hook option for documentation generation or analysis
|
|
504
|
+
*
|
|
505
|
+
* @param option
|
|
506
|
+
*/
|
|
507
|
+
introspect?(option: Prettify<Macro>): unknown;
|
|
508
|
+
};
|
|
509
|
+
interface Macro<in out Macro extends BaseMacro = {}, in out Input extends BaseMacro = {}, in out TypedRoute extends RouteSchema = {}, in out Singleton extends SingletonBase = DefaultSingleton, Errors extends ErrorDefinition[] = []> {
|
|
510
|
+
[K: keyof any]: MaybeValueOrVoidFunction<Input & MacroProperty<Macro, TypedRoute, Singleton, Errors>>;
|
|
414
511
|
}
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
512
|
+
type JoinPath<A extends string, B extends string> = B extends `/${string}` ? `${A}${B}` : `${A}/${B}`;
|
|
513
|
+
type IsPathParameter<Part extends string> = Part extends `:${infer Parameter}` ? Parameter : Part extends `*` ? '*' : never;
|
|
514
|
+
type GetPathParameter<Path extends string> = Path extends `${infer A}/${infer B}` ? IsPathParameter<A> | GetPathParameter<B> : IsPathParameter<Path>;
|
|
515
|
+
type _ResolvePath<Path extends string> = { [Param in GetPathParameter<Path> as Param extends `${string}?` ? never : Param]: string } & { [Param in GetPathParameter<Path> as Param extends `${infer OptionalParam}?` ? OptionalParam : never]?: string };
|
|
516
|
+
type PathParameterLike = `${string}/${':' | '*'}${string}`;
|
|
517
|
+
type ResolvePath<Path extends string> = Path extends '' ? {} : Path extends PathParameterLike ? _ResolvePath<Path> : {};
|
|
518
|
+
type SetContentType = 'application/octet-stream' | 'application/vnd.ms-fontobject' | 'application/epub+zip' | 'application/gzip' | 'application/json' | 'application/ld+json' | 'application/ogg' | 'application/pdf' | 'application/rtf' | 'application/wasm' | 'application/xhtml+xml' | 'application/xml' | 'application/zip' | 'text/css' | 'text/csv' | 'text/calendar' | 'text/event-stream' | 'text/html' | 'text/javascript' | 'text/plain' | 'text/xml' | 'image/avif' | 'image/bmp' | 'image/gif' | 'image/x-icon' | 'image/jpeg' | 'image/png' | 'image/svg+xml' | 'image/tiff' | 'image/webp' | 'multipart/mixed' | 'multipart/alternative' | 'multipart/form-data' | 'audio/aac' | 'audio/x-midi' | 'audio/mpeg' | 'audio/ogg' | 'audio/opus' | 'audio/webm' | 'video/x-msvideo' | 'video/quicktime' | 'video/x-ms-wmv' | 'video/x-flv' | 'video/av1' | 'video/mp4' | 'video/mpeg' | 'video/ogg' | 'video/mp2t' | 'video/webm' | 'video/3gpp' | 'video/3gpp2' | 'font/otf' | 'font/ttf' | 'font/woff' | 'font/woff2' | 'model/gltf+json' | 'model/gltf-binary';
|
|
519
|
+
type HTTPHeaders = Record<string, string | number | string[]> & {
|
|
520
|
+
'www-authenticate'?: string;
|
|
521
|
+
authorization?: string;
|
|
522
|
+
'proxy-authenticate'?: string;
|
|
523
|
+
'proxy-authorization'?: string;
|
|
524
|
+
age?: string;
|
|
525
|
+
'cache-control'?: string;
|
|
526
|
+
'clear-site-data'?: string;
|
|
527
|
+
expires?: string;
|
|
528
|
+
'no-vary-search'?: string;
|
|
529
|
+
pragma?: string;
|
|
530
|
+
'last-modified'?: string;
|
|
531
|
+
etag?: string;
|
|
532
|
+
'if-match'?: string;
|
|
533
|
+
'if-none-match'?: string;
|
|
534
|
+
'if-modified-since'?: string;
|
|
535
|
+
'if-unmodified-since'?: string;
|
|
536
|
+
vary?: string;
|
|
537
|
+
connection?: string;
|
|
538
|
+
'keep-alive'?: string;
|
|
539
|
+
accept?: string;
|
|
540
|
+
'accept-encoding'?: string;
|
|
541
|
+
'accept-language'?: string;
|
|
542
|
+
expect?: string;
|
|
543
|
+
'max-forwards'?: string;
|
|
544
|
+
cookie?: string;
|
|
545
|
+
'set-cookie'?: string | string[];
|
|
546
|
+
'access-control-allow-origin'?: string;
|
|
547
|
+
'access-control-allow-credentials'?: string;
|
|
548
|
+
'access-control-allow-headers'?: string;
|
|
549
|
+
'access-control-allow-methods'?: string;
|
|
550
|
+
'access-control-expose-headers'?: string;
|
|
551
|
+
'access-control-max-age'?: string;
|
|
552
|
+
'access-control-request-headers'?: string;
|
|
553
|
+
'access-control-request-method'?: string;
|
|
554
|
+
origin?: string;
|
|
555
|
+
'timing-allow-origin'?: string;
|
|
556
|
+
'content-disposition'?: string;
|
|
557
|
+
'content-length'?: string | number;
|
|
558
|
+
'content-type'?: SetContentType | (string & {});
|
|
559
|
+
'content-encoding'?: string;
|
|
560
|
+
'content-language'?: string;
|
|
561
|
+
'content-location'?: string;
|
|
562
|
+
forwarded?: string;
|
|
563
|
+
via?: string;
|
|
564
|
+
location?: string;
|
|
565
|
+
refresh?: string;
|
|
566
|
+
allow?: string;
|
|
567
|
+
server?: 'Elysia' | (string & {});
|
|
568
|
+
'accept-ranges'?: string;
|
|
569
|
+
range?: string;
|
|
570
|
+
'if-range'?: string;
|
|
571
|
+
'content-range'?: string;
|
|
572
|
+
'content-security-policy'?: string;
|
|
573
|
+
'content-security-policy-report-only'?: string;
|
|
574
|
+
'cross-origin-embedder-policy'?: string;
|
|
575
|
+
'cross-origin-opener-policy'?: string;
|
|
576
|
+
'cross-origin-resource-policy'?: string;
|
|
577
|
+
'expect-ct'?: string;
|
|
578
|
+
'permission-policy'?: string;
|
|
579
|
+
'strict-transport-security'?: string;
|
|
580
|
+
'upgrade-insecure-requests'?: string;
|
|
581
|
+
'x-content-type-options'?: string;
|
|
582
|
+
'x-frame-options'?: string;
|
|
583
|
+
'x-xss-protection'?: string;
|
|
584
|
+
'last-event-id'?: string;
|
|
585
|
+
'ping-from'?: string;
|
|
586
|
+
'ping-to'?: string;
|
|
587
|
+
'report-to'?: string;
|
|
588
|
+
te?: string;
|
|
589
|
+
trailer?: string;
|
|
590
|
+
'transfer-encoding'?: string;
|
|
591
|
+
'alt-svg'?: string;
|
|
592
|
+
'alt-used'?: string;
|
|
593
|
+
date?: string;
|
|
594
|
+
dnt?: string;
|
|
595
|
+
'early-data'?: string;
|
|
596
|
+
'large-allocation'?: string;
|
|
597
|
+
link?: string;
|
|
598
|
+
'retry-after'?: string;
|
|
599
|
+
'service-worker-allowed'?: string;
|
|
600
|
+
'source-map'?: string;
|
|
601
|
+
upgrade?: string;
|
|
602
|
+
'x-dns-prefetch-control'?: string;
|
|
603
|
+
'x-forwarded-for'?: string;
|
|
604
|
+
'x-forwarded-host'?: string;
|
|
605
|
+
'x-forwarded-proto'?: string;
|
|
606
|
+
'x-powered-by'?: 'Elysia' | (string & {});
|
|
607
|
+
'x-request-id'?: string;
|
|
608
|
+
'x-requested-with'?: string;
|
|
609
|
+
'x-robots-tag'?: string;
|
|
610
|
+
'x-ua-compatible'?: string;
|
|
611
|
+
};
|
|
612
|
+
type AnyErrorConstructor = {
|
|
613
|
+
prototype: Error;
|
|
614
|
+
};
|
|
615
|
+
type ContextAppendType = 'append' | 'override';
|
|
616
|
+
type OptionalField = {
|
|
617
|
+
'~optional': true;
|
|
618
|
+
};
|
|
619
|
+
type StaticCyclic<T extends TypeBoxSchema, Definitions extends Record<string, AnySchema>> = {} extends Definitions ? StaticDecode<T> : StaticDecode<T, Definitions>;
|
|
620
|
+
type UnwrapSchema<Schema extends AnySchema | string | undefined, Definitions extends DefinitionBase['typebox'] = {}> = Schema extends undefined ? unknown : Schema extends TypeBoxSchema ? Schema extends OptionalField ? Partial<StaticCyclic<Schema, Definitions>> : StaticCyclic<Schema, Definitions> : Schema extends StandardSchemaV1Like ? NonNullable<Schema['~standard']['types']>['output'] : Schema extends string ? Schema extends keyof Definitions ? Definitions[Schema] extends TypeBoxSchema ? StaticCyclic<Definitions[Schema], Definitions> : Definitions[Schema] extends StandardSchemaV1Like ? NonNullable<Definitions[Schema]['~standard']['types']>['output'] : unknown : unknown : unknown;
|
|
621
|
+
type UnwrapBodySchema<Schema extends AnySchema | string | undefined, Definitions extends DefinitionBase['typebox'] = {}> = undefined extends Schema ? unknown : Schema extends TypeBoxSchema ? Schema extends OptionalField ? Partial<StaticCyclic<Schema, Definitions>> | null : StaticCyclic<Schema, Definitions> : Schema extends StandardSchemaV1Like ? NonNullable<Schema['~standard']['types']>['output'] : Schema extends string ? Schema extends keyof Definitions ? Definitions[Schema] extends TypeBoxSchema ? StaticCyclic<Definitions[Schema], Definitions> : Definitions[Schema] extends StandardSchemaV1Like ? NonNullable<Definitions[Schema]['~standard']['types']>['output'] : unknown : unknown : unknown;
|
|
622
|
+
type FormInnerProperties<Schema> = Extract<Schema extends TIntersect<infer Members> ? Members[number] : never, TObject>['properties'];
|
|
623
|
+
type UnwrapResponseSchema<Schema extends AnySchema | string | undefined, Definitions extends DefinitionBase['typebox'] = {}> = Schema extends TypeBoxSchema ? StaticEncode<Schema> extends {
|
|
624
|
+
'~ely-form': any;
|
|
625
|
+
} ? ElysiaFormData<{ [K in keyof FormInnerProperties<Schema>]: Static<FormInnerProperties<Schema>[K] & TSchema> }> : UnwrapSchema<Schema, Definitions> : Schema extends StandardSchemaV1Like ? NonNullable<Schema['~standard']['types']>['input'] : Schema extends string ? Schema extends keyof Definitions ? Definitions[Schema] extends TypeBoxSchema ? StaticCyclic<Definitions[Schema], Definitions> : Definitions[Schema] extends StandardSchemaV1Like ? NonNullable<Definitions[Schema]['~standard']['types']>['input'] : unknown : unknown : unknown;
|
|
626
|
+
interface UnwrapRoute<in out Schema extends InputSchema<any>, in out Definitions extends DefinitionBase['typebox'] = {}, in out Path extends string = ''> {
|
|
627
|
+
body: UnwrapBodySchema<Schema['body'], Definitions>;
|
|
628
|
+
headers: UnwrapSchema<Schema['headers'], Definitions>;
|
|
629
|
+
query: UnwrapSchema<Schema['query'], Definitions>;
|
|
630
|
+
params: {} extends Schema['params'] ? ResolvePath<Path> : {} extends Schema ? ResolvePath<Path> : UnwrapSchema<Schema['params'], Definitions>;
|
|
631
|
+
cookie: UnwrapSchema<Schema['cookie'], Definitions>;
|
|
632
|
+
response: Schema['response'] extends AnySchema | string ? {
|
|
633
|
+
200: UnwrapResponseSchema<Schema['response'], Definitions> extends infer A ? A extends File ? File | ElysiaFile : A : unknown;
|
|
634
|
+
} : Schema['response'] extends { [status in number]: AnySchema | string } ? { [k in keyof Schema['response']]: UnwrapResponseSchema<Schema['response'][k], Definitions> extends infer A ? A extends File ? File | ElysiaFile : A : unknown } : unknown | void;
|
|
635
|
+
}
|
|
636
|
+
type LocalLifecycleProperty = 'detail' | 'parse' | 'transform' | 'beforeHandle' | 'afterHandle' | 'mapResponse' | 'afterResponse' | 'error' | 'tags';
|
|
637
|
+
type MacroToProperty<in out T> = Prettify<{ [K in keyof T]: T[K] extends Function ? T[K] extends ((a: infer Params) => any) ? Params : boolean : boolean }>;
|
|
638
|
+
type NonResolvableMacroKey = LocalLifecycleProperty | keyof InputSchema | 'derive';
|
|
639
|
+
interface RouteSchemaWithResolvedMacro extends RouteSchema {
|
|
640
|
+
response: PossibleResponse;
|
|
641
|
+
return: PossibleResponse;
|
|
642
|
+
resolve: Record<string, unknown>;
|
|
643
|
+
}
|
|
644
|
+
type IntersectIfObject<A, B> = unknown extends A ? B : A extends Record<any, any> ? B extends Record<any, any> ? A & B : A : B extends Record<any, any> ? B : A;
|
|
645
|
+
interface IntersectIfObjectSchema<A extends RouteSchema, B extends RouteSchema> {
|
|
646
|
+
body: IntersectIfObject<A['body'], B['body']>;
|
|
647
|
+
headers: IntersectIfObject<A['headers'], B['headers']>;
|
|
648
|
+
query: IntersectIfObject<A['query'], B['query']>;
|
|
649
|
+
params: IntersectIfObject<A['params'], B['params']>;
|
|
650
|
+
cookie: IntersectIfObject<A['cookie'], B['cookie']>;
|
|
651
|
+
response: {} extends A['response'] ? {} extends B['response'] ? A['response'] : B['response'] : {} extends B['response'] ? A['response'] : { [K in keyof A['response'] | keyof B['response']]: K extends keyof A['response'] ? K extends keyof B['response'] ? IntersectIfObject<A['response'][K], B['response'][K]> : A['response'][K] : K extends keyof B['response'] ? B['response'][K] : never };
|
|
652
|
+
}
|
|
653
|
+
interface MergeScopedSchemas<Global extends RouteSchema, Scoped extends RouteSchema, Local extends RouteSchema> {
|
|
654
|
+
body: Global['body'] & Scoped['body'] & Local['body'];
|
|
655
|
+
headers: Global['headers'] & Scoped['headers'] & Local['headers'];
|
|
656
|
+
query: Global['query'] & Scoped['query'] & Local['query'];
|
|
657
|
+
params: Global['params'] & Scoped['params'] & Local['params'];
|
|
658
|
+
cookie: Global['cookie'] & Scoped['cookie'] & Local['cookie'];
|
|
659
|
+
response: { [K in keyof Global['response'] | keyof Scoped['response'] | keyof Local['response']]: K extends keyof Local['response'] ? Local['response'][K] : K extends keyof Scoped['response'] ? Scoped['response'][K] : K extends keyof Global['response'] ? Global['response'][K] : never };
|
|
660
|
+
}
|
|
661
|
+
type ReturnTypeIfPossible<T, Enabled = true> = false extends Enabled ? {} : T extends ((...a: any) => infer R) ? R : T;
|
|
431
662
|
type FunctionArrayReturnType<T> = any[] extends T ? never : T extends any[] ? _FunctionArrayReturnType<T> : Awaited<ReturnType<T>>;
|
|
432
|
-
type _FunctionArrayReturnType<T, Carry = undefined> = T extends [
|
|
433
|
-
infer Fn,
|
|
434
|
-
...infer Rest
|
|
435
|
-
] ? _FunctionArrayReturnType<Rest, Awaited<ReturnType<Fn>> extends infer A ? IsNever<A> extends true ? Carry : A | Carry : Carry> : Carry;
|
|
663
|
+
type _FunctionArrayReturnType<T, Carry = undefined> = T extends [infer Fn, ...infer Rest] ? _FunctionArrayReturnType<Rest, Awaited<ReturnType<Fn>> extends infer A ? IsNever<A> extends true ? Carry : A | Carry : Carry> : Carry;
|
|
436
664
|
type FunctionArrayReturnTypeNonNullable<T> = any[] extends T ? never : T extends any[] ? _FunctionArrayReturnTypeNonNullable<T> : NonNullable<Awaited<ReturnType<T>>>;
|
|
437
|
-
type _FunctionArrayReturnTypeNonNullable<T, Carry = undefined> = T extends [
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
type
|
|
442
|
-
|
|
443
|
-
return: MergeResponseStatus<A>;
|
|
665
|
+
type _FunctionArrayReturnTypeNonNullable<T, Carry = undefined> = T extends [infer Fn, ...infer Rest] ? _FunctionArrayReturnTypeNonNullable<Rest, NonNullable<Awaited<ReturnType<Fn>>> extends infer A ? IsNever<A> extends true ? Carry : A | Carry : Carry> : Carry;
|
|
666
|
+
type AnyElysiaStatus = ElysiaStatus<any, any, any>;
|
|
667
|
+
type ExcludeElysiaResponse<T> = Exclude<Awaited<T>, AnyElysiaStatus> extends infer A ? IsNever<A & {}> extends true ? {} : undefined extends A ? Partial<A & {}> : A & {} : {};
|
|
668
|
+
type ExtractResolveFromMacro<A> = IsNever<A> extends true ? {} : A extends AnyElysiaStatus ? A : Exclude<A, AnyElysiaStatus> extends infer A ? IsAny<A> extends true ? {} : A : {};
|
|
669
|
+
type ExtractOnlyResponseFromMacro<A> = IsNever<A> extends true ? {} : Extract<A, AnyElysiaStatus> extends infer A ? IsNever<A> extends true ? {} : {
|
|
670
|
+
return: MergeResponseStatus<A>;
|
|
444
671
|
} : {};
|
|
445
|
-
type MergeResponseStatus<A> = {
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
} : never>]: Extract<A, {
|
|
449
|
-
code: status;
|
|
450
|
-
}>['response'] extends infer Value ? IsAny<Value> extends true ? InvertedStatusMap[status] : Value : never;
|
|
451
|
-
};
|
|
452
|
-
type MergeAllStatus<T> = {
|
|
453
|
-
[K in T extends any ? keyof T : never]: T extends Record<K, infer V> ? V : never;
|
|
454
|
-
};
|
|
672
|
+
type MergeResponseStatus<A> = { [status in keyof UnionToIntersect<A extends ElysiaStatus<any, any, infer Status> ? { [A in Status]: 1 } : never>]: Extract<A, {
|
|
673
|
+
code: status;
|
|
674
|
+
}>['response'] extends infer Value ? IsAny<Value> extends true ? StatusMapBack[status] : Value : never };
|
|
455
675
|
type ExtractAllResponseFromMacro<A> = IsNever<A> extends true ? {} : {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
676
|
+
return: MergeResponseStatus<A> & (Exclude<A, AnyElysiaStatus> extends infer A ? IsAny<A> extends true ? {} : IsNever<A> extends true ? {} : NonNullable<void> extends A ? {} : undefined extends A ? {} : {
|
|
677
|
+
200: A;
|
|
678
|
+
} : {});
|
|
459
679
|
};
|
|
460
|
-
type FlattenMacroResponse<T> = T extends object ? '_' extends keyof T ?
|
|
461
|
-
type
|
|
462
|
-
|
|
680
|
+
type FlattenMacroResponse<T> = T extends object ? '_' extends keyof T ? UnionResponseStatus<Omit<T, '_'>, FlattenMacroResponse<MergeStatusUnion<T['_']>>> : T : T;
|
|
681
|
+
type UnionMacroContext<A> = UnionToIntersect<{ [K in Exclude<keyof A, 'return'>]: A[K] }> & {
|
|
682
|
+
return: {
|
|
683
|
+
_: A['return'];
|
|
684
|
+
};
|
|
463
685
|
};
|
|
464
|
-
type
|
|
465
|
-
|
|
466
|
-
}> & {
|
|
467
|
-
return: {
|
|
468
|
-
_: A['return'];
|
|
469
|
-
};
|
|
470
|
-
};
|
|
471
|
-
export type MacroToContext<in out MacroFn extends Macro = {}, in out SelectedMacro extends BaseMacro = {}, in out Definitions extends DefinitionBase['typebox'] = {}, in out R extends 1[] = []> = Prettify<InnerMacroToContext<MacroFn, Pick<SelectedMacro, Extract<keyof MacroFn, keyof SelectedMacro>>, Definitions, R> extends infer A ? {
|
|
472
|
-
[K in Exclude<keyof A, 'return'>]: UnionToIntersect<A[K]>;
|
|
473
|
-
} & Prettify<{
|
|
474
|
-
return: FlattenMacroResponse<A['return']>;
|
|
686
|
+
type MacroToContext<in out MacroFn extends Macro = {}, in out SelectedMacro extends BaseMacro = {}, in out Definitions extends DefinitionBase['typebox'] = {}, in out R extends 1[] = []> = Prettify<InnerMacroToContext<MacroFn, Pick<SelectedMacro, Extract<keyof MacroFn, keyof SelectedMacro>>, Definitions, R> extends infer A ? { [K in Exclude<keyof A, 'return'>]: UnionToIntersect<A[K]> } & Prettify<{
|
|
687
|
+
return: FlattenMacroResponse<A['return']>;
|
|
475
688
|
}> : {}>;
|
|
476
|
-
type InnerMacroToContext<MacroFn extends Macro = {}, SelectedMacro extends BaseMacro = {}, Definitions extends DefinitionBase['typebox'] = {}, R extends 1[] = []> = {} extends SelectedMacro ? {} : R['length'] extends 15 ? {} : UnionMacroContext<{
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
...R,
|
|
481
|
-
1
|
|
482
|
-
]> : {};
|
|
483
|
-
}[keyof SelectedMacro]>;
|
|
689
|
+
type InnerMacroToContext<MacroFn extends Macro = {}, SelectedMacro extends BaseMacro = {}, Definitions extends DefinitionBase['typebox'] = {}, R extends 1[] = []> = {} extends SelectedMacro ? {} : R['length'] extends 15 ? {} : UnionMacroContext<{ [key in keyof SelectedMacro]: ReturnTypeIfPossible<MacroFn[key], SelectedMacro[key]> extends infer Value ? {
|
|
690
|
+
q: UnwrapMacroSchema<Value, Definitions>;
|
|
691
|
+
resolve: ExtractResolveFromMacro<Extract<Exclude<FunctionArrayReturnType<Value['derive']>, AnyElysiaStatus>, Record<any, unknown>>>;
|
|
692
|
+
} & UnwrapMacroSchema<Value, Definitions> & ExtractAllResponseFromMacro<FunctionArrayReturnTypeNonNullable<Value['beforeHandle']>> & ExtractAllResponseFromMacro<FunctionArrayReturnTypeNonNullable<Value['afterHandle']>> & ExtractAllResponseFromMacro<FunctionArrayReturnType<Value['error']>> & ExtractOnlyResponseFromMacro<FunctionArrayReturnTypeNonNullable<Value['derive']>> & InnerMacroToContext<MacroFn, Pick<Value, Extract<keyof MacroFn, keyof Value>>, Definitions, [...R, 1]> : {} }[keyof SelectedMacro]>;
|
|
484
693
|
type UnwrapMacroSchema<T extends Partial<InputSchema<any>>, Definitions extends DefinitionBase['typebox'] = {}> = UnwrapRoute<{
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
694
|
+
body: 'body' extends keyof T ? T['body'] : undefined;
|
|
695
|
+
headers: 'headers' extends keyof T ? T['headers'] : undefined;
|
|
696
|
+
query: 'query' extends keyof T ? T['query'] : undefined;
|
|
697
|
+
params: 'params' extends keyof T ? T['params'] : undefined;
|
|
698
|
+
cookie: 'cookie' extends keyof T ? T['cookie'] : undefined;
|
|
699
|
+
response: 'response' extends keyof T ? T['response'] : undefined;
|
|
491
700
|
}, Definitions>;
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
type InlineResponse = string | number | boolean | Record<any, unknown> | Response | AnyElysiaCustomStatusResponse | ElysiaFile | Record<any, unknown> | BunHTMLBundlelike;
|
|
505
|
-
type LastOf<T> = UnionToIntersect<T extends any ? () => T : never> extends () => infer R ? R : never;
|
|
506
|
-
type Push<T extends any[], V> = [...T, V];
|
|
507
|
-
type TuplifyUnion<T, L = LastOf<T>, N = [T] extends [never] ? true : false> = true extends N ? [] : Push<TuplifyUnion<Exclude<T, L>>, L>;
|
|
508
|
-
export type Tuple<T, A extends T[] = []> = TuplifyUnion<T>['length'] extends A['length'] ? [...A] : Tuple<T, [T, ...A]>;
|
|
509
|
-
export type InlineHandler<Route extends RouteSchema = {}, Singleton extends SingletonBase = {
|
|
510
|
-
decorator: {};
|
|
511
|
-
store: {};
|
|
512
|
-
derive: {};
|
|
513
|
-
resolve: {};
|
|
514
|
-
}, MacroContext extends {
|
|
515
|
-
response: PossibleResponse;
|
|
516
|
-
return: PossibleResponse;
|
|
517
|
-
resolve: Record<string, unknown>;
|
|
518
|
-
} = {
|
|
519
|
-
response: {};
|
|
520
|
-
return: {};
|
|
521
|
-
resolve: {};
|
|
522
|
-
}> = MaybePromise<InlineResponse> | ((context: Context<Route & MacroContext, Singleton & {
|
|
523
|
-
resolve: MacroContext['resolve'];
|
|
524
|
-
}>) => MaybePromise<Response> | MaybePromise<{} extends Route['response'] ? unknown : (Route['response'] extends {
|
|
525
|
-
200: any;
|
|
526
|
-
} ? Route['response'][200] | ElysiaCustomStatusResponse<200, Route['response'][200], 200> | Generator<Route['response'][200]> | AsyncGenerator<Route['response'][200]> : unknown) | Route['response'][keyof Route['response']] | InlineHandlerResponse<Route['response'] & MacroContext['response']>>);
|
|
527
|
-
export type InlineHandlerNonMacro<Route extends RouteSchema = {}, Singleton extends SingletonBase = {
|
|
528
|
-
decorator: {};
|
|
529
|
-
store: {};
|
|
530
|
-
derive: {};
|
|
531
|
-
resolve: {};
|
|
532
|
-
}> = MaybePromise<InlineResponse> | ((context: Context<Route, Singleton>) => MaybePromise<Response> | MaybePromise<{} extends Route['response'] ? unknown : (Route['response'] extends {
|
|
533
|
-
200: any;
|
|
534
|
-
} ? Route['response'][200] | ElysiaCustomStatusResponse<200, Route['response'][200], 200> | Generator<Route['response'][200]> | AsyncGenerator<Route['response'][200]> : unknown) | Route['response'][keyof Route['response']] | InlineHandlerResponse<Route['response']>>);
|
|
535
|
-
export type OptionalHandler<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = {
|
|
536
|
-
decorator: {};
|
|
537
|
-
store: {};
|
|
538
|
-
derive: {};
|
|
539
|
-
resolve: {};
|
|
540
|
-
}, Path extends string | undefined = undefined> = (context: Context<Route, Singleton, Path>) => MaybePromise<{} extends Route['response'] ? unknown : Route['response'][keyof Route['response']] | InlineHandlerResponse<Route['response']> | void>;
|
|
541
|
-
export type AfterHandler<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = {
|
|
542
|
-
decorator: {};
|
|
543
|
-
store: {};
|
|
544
|
-
derive: {};
|
|
545
|
-
resolve: {};
|
|
546
|
-
}, Path extends string | undefined = undefined> = (context: Context<Route, Singleton, Path> & {
|
|
547
|
-
responseValue: {} extends Route['response'] ? unknown : Route['response'][keyof Route['response']];
|
|
548
|
-
/**
|
|
549
|
-
* @deprecated use `context.responseValue` instead
|
|
550
|
-
*/
|
|
551
|
-
response: {} extends Route['response'] ? unknown : Route['response'][keyof Route['response']];
|
|
552
|
-
}) => MaybePromise<{} extends Route['response'] ? unknown : Route['response'][keyof Route['response']] | InlineHandlerResponse<Route['response']> | void>;
|
|
553
|
-
export type MapResponse<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = {
|
|
554
|
-
decorator: {};
|
|
555
|
-
store: {};
|
|
556
|
-
derive: {};
|
|
557
|
-
resolve: {};
|
|
558
|
-
}, Path extends string | undefined = undefined> = (context: Context<Route, Singleton, Path> & {
|
|
559
|
-
responseValue: {} extends Route['response'] ? unknown : Route['response'][keyof Route['response']];
|
|
560
|
-
/**
|
|
561
|
-
* @deprecated use `context.responseValue` instead
|
|
562
|
-
*/
|
|
563
|
-
response: {} extends Route['response'] ? unknown : Route['response'][keyof Route['response']];
|
|
564
|
-
}) => MaybePromise<Response | void>;
|
|
565
|
-
export type VoidHandler<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = {
|
|
566
|
-
decorator: {};
|
|
567
|
-
store: {};
|
|
568
|
-
derive: {};
|
|
569
|
-
resolve: {};
|
|
570
|
-
}> = (context: Context<Route, Singleton>) => MaybePromise<void>;
|
|
571
|
-
export type TransformHandler<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = {
|
|
572
|
-
decorator: {};
|
|
573
|
-
store: {};
|
|
574
|
-
derive: {};
|
|
575
|
-
resolve: {};
|
|
576
|
-
}, Path extends string | undefined = undefined> = (context: Context<Route, Omit<Singleton, 'resolve'> & {
|
|
577
|
-
resolve: {};
|
|
578
|
-
}, Path>) => MaybePromise<void>;
|
|
579
|
-
export type BodyHandler<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = {
|
|
580
|
-
decorator: {};
|
|
581
|
-
store: {};
|
|
582
|
-
derive: {};
|
|
583
|
-
resolve: {};
|
|
584
|
-
}, Path extends string | undefined = undefined> = (context: Context<Route, Singleton & {
|
|
585
|
-
decorator: {
|
|
586
|
-
contentType: string;
|
|
587
|
-
};
|
|
588
|
-
}, Path>,
|
|
701
|
+
type MacroPropertyKey = keyof MacroProperty;
|
|
702
|
+
type AsMacroSchemaField<T> = [T] extends [never] ? undefined : [unknown] extends [T] ? undefined : T extends AnySchema | string ? T : undefined;
|
|
703
|
+
type MacroDefSchema<K, MBody, MHeaders, MQuery, MParams, MCookie> = {
|
|
704
|
+
body: AsMacroSchemaField<K extends keyof MBody ? MBody[K] : undefined>;
|
|
705
|
+
headers: AsMacroSchemaField<K extends keyof MHeaders ? MHeaders[K] : undefined>;
|
|
706
|
+
query: AsMacroSchemaField<K extends keyof MQuery ? MQuery[K] : undefined>;
|
|
707
|
+
params: AsMacroSchemaField<K extends keyof MParams ? MParams[K] : undefined>;
|
|
708
|
+
cookie: AsMacroSchemaField<K extends keyof MCookie ? MCookie[K] : undefined>;
|
|
709
|
+
response: undefined;
|
|
710
|
+
};
|
|
711
|
+
type MacroSchemaChannel<Definitions extends DefinitionBase> = Record<keyof any, AnySchema | (keyof Definitions['typebox'] & string)>;
|
|
712
|
+
type MacroChannel<Channel, Key extends keyof InputSchema, Definitions extends DefinitionBase> = { [K in keyof Channel]: MaybeValueOrVoidFunction<{ [F in Key]?: Channel[K] | (keyof Definitions['typebox'] & string) } & Record<string, unknown>> };
|
|
589
713
|
/**
|
|
590
|
-
*
|
|
714
|
+
* Captures the verbatim `.macro()` definition record into a separate first-pass
|
|
715
|
+
* generic (mirrors {@link MacroChannel}). This lets each definition's enabled
|
|
716
|
+
* sibling flags (`{ auth: true }`) be read back without reusing the contextually
|
|
717
|
+
* typed `NewMacro`, which would form the record -> handler-typing inference
|
|
718
|
+
* cycle documented on {@link ObjectMacroDefs}.
|
|
719
|
+
*/
|
|
720
|
+
type MacroRefChannel<Refs> = { [K in keyof Refs]: MaybeValueOrVoidFunction<{ [M in keyof Refs[K]]?: Refs[K][M] } & Record<string, unknown>> };
|
|
721
|
+
/**
|
|
722
|
+
* `resolve` (derive) context contributed by the sibling macros a definition
|
|
723
|
+
* enables via `{ name: true }`. Extracted through `infer` because
|
|
724
|
+
* {@link MacroToContext} is a mapped type whose `resolve` key cannot be indexed
|
|
725
|
+
* with a plain `['resolve']` on the generic form.
|
|
726
|
+
*/
|
|
727
|
+
type MacroRefResolve<MacroFn, SelectedMacro, Definitions> = MacroToContext<MacroFn, SelectedMacro, Definitions> extends {
|
|
728
|
+
resolve: infer Resolve;
|
|
729
|
+
} ? Resolve : {};
|
|
730
|
+
/**
|
|
731
|
+
* Parameter type of the object-form `.macro({ name: definition })`
|
|
591
732
|
*
|
|
592
|
-
*
|
|
733
|
+
* TypeScript cannot infer one generic from a record while ALSO using it to
|
|
734
|
+
* contextually type that record's own handlers (the inference cycle that
|
|
735
|
+
* historically forced the named `.macro(name, def)` overload).
|
|
593
736
|
*
|
|
594
|
-
*
|
|
595
|
-
*
|
|
596
|
-
*
|
|
597
|
-
*
|
|
598
|
-
* if (contentType === 'application/json')
|
|
599
|
-
* return request.json()
|
|
600
|
-
* })
|
|
601
|
-
* ```
|
|
737
|
+
* Handler member only consumes them so `derive`/ `beforeHandle`
|
|
738
|
+
* see their sibling schema fully typed while their return types
|
|
739
|
+
* still flow into `N` (the verbatim definitions, stored in
|
|
740
|
+
* `Metadata['macroFn']` for the consuming route)
|
|
602
741
|
*/
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
export type GracefulHandler<in Instance extends AnyElysia> = (data: Instance) => any;
|
|
623
|
-
export type ErrorHandler<in out T extends Record<string, Error> = {}, in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = {
|
|
624
|
-
decorator: {};
|
|
625
|
-
store: {};
|
|
626
|
-
derive: {};
|
|
627
|
-
resolve: {};
|
|
628
|
-
}, in out Ephemeral extends EphemeralType = {
|
|
629
|
-
derive: {};
|
|
630
|
-
resolve: {};
|
|
631
|
-
schema: {};
|
|
632
|
-
standaloneSchema: {};
|
|
633
|
-
response: {};
|
|
634
|
-
}, in out Volatile extends EphemeralType = {
|
|
635
|
-
derive: {};
|
|
636
|
-
resolve: {};
|
|
637
|
-
schema: {};
|
|
638
|
-
standaloneSchema: {};
|
|
639
|
-
response: {};
|
|
640
|
-
}> = (context: ErrorContext<Route, {
|
|
641
|
-
store: Singleton['store'];
|
|
642
|
-
decorator: Singleton['decorator'];
|
|
643
|
-
derive: {};
|
|
644
|
-
resolve: {};
|
|
645
|
-
}> & (Prettify<{
|
|
646
|
-
request: Request;
|
|
647
|
-
code: 'UNKNOWN';
|
|
648
|
-
error: Readonly<Error>;
|
|
649
|
-
set: Context['set'];
|
|
650
|
-
} & Partial<Singleton['derive'] & Ephemeral['derive'] & Volatile['derive'] & Singleton['resolve'] & Ephemeral['resolve'] & Volatile['resolve']>> | Prettify<{
|
|
651
|
-
request: Request;
|
|
652
|
-
code: 'VALIDATION';
|
|
653
|
-
error: Readonly<ValidationError>;
|
|
654
|
-
set: Context['set'];
|
|
655
|
-
} & Singleton['derive'] & Ephemeral['derive'] & Volatile['derive'] & NeverKey<Singleton['resolve'] & Ephemeral['resolve'] & Volatile['resolve']>> | Prettify<{
|
|
656
|
-
request: Request;
|
|
657
|
-
code: 'NOT_FOUND';
|
|
658
|
-
error: Readonly<NotFoundError>;
|
|
659
|
-
set: Context['set'];
|
|
660
|
-
} & NeverKey<Singleton['derive'] & Ephemeral['derive'] & Volatile['derive'] & Singleton['resolve'] & Ephemeral['resolve'] & Volatile['resolve']>> | Prettify<{
|
|
661
|
-
request: Request;
|
|
662
|
-
code: 'PARSE';
|
|
663
|
-
error: Readonly<ParseError>;
|
|
664
|
-
set: Context['set'];
|
|
665
|
-
} & NeverKey<Singleton['derive'] & Ephemeral['derive'] & Volatile['derive'] & Singleton['resolve'] & Ephemeral['resolve'] & Volatile['resolve']>> | Prettify<{
|
|
666
|
-
request: Request;
|
|
667
|
-
code: 'INTERNAL_SERVER_ERROR';
|
|
668
|
-
error: Readonly<InternalServerError>;
|
|
669
|
-
set: Context['set'];
|
|
670
|
-
} & Partial<Singleton['derive'] & Ephemeral['derive'] & Volatile['derive'] & Singleton['resolve'] & Ephemeral['resolve'] & Volatile['resolve']>> | Prettify<{
|
|
671
|
-
request: Request;
|
|
672
|
-
code: 'INVALID_COOKIE_SIGNATURE';
|
|
673
|
-
error: Readonly<InvalidCookieSignature>;
|
|
674
|
-
set: Context['set'];
|
|
675
|
-
} & NeverKey<Singleton['derive'] & Ephemeral['derive'] & Volatile['derive'] & Singleton['resolve'] & Ephemeral['resolve'] & Volatile['resolve']>> | Prettify<{
|
|
676
|
-
request: Request;
|
|
677
|
-
code: 'INVALID_FILE_TYPE';
|
|
678
|
-
error: Readonly<InvalidFileType>;
|
|
679
|
-
set: Context['set'];
|
|
680
|
-
} & Singleton['derive'] & Ephemeral['derive'] & Volatile['derive'] & NeverKey<Singleton['resolve'] & Ephemeral['resolve'] & Volatile['resolve']>> | Prettify<{
|
|
681
|
-
request: Request;
|
|
682
|
-
code: number;
|
|
683
|
-
error: Readonly<ElysiaCustomStatusResponse<number>>;
|
|
684
|
-
set: Context['set'];
|
|
685
|
-
} & Partial<Singleton['derive'] & Ephemeral['derive'] & Volatile['derive'] & Singleton['resolve'] & Ephemeral['resolve'] & Volatile['resolve']>> | Prettify<{
|
|
686
|
-
[K in keyof T]: {
|
|
687
|
-
request: Request;
|
|
688
|
-
code: K;
|
|
689
|
-
error: Readonly<T[K]>;
|
|
690
|
-
set: Context['set'];
|
|
691
|
-
};
|
|
692
|
-
}[keyof T] & Partial<Singleton['derive'] & Ephemeral['derive'] & Volatile['derive'] & Singleton['resolve'] & Ephemeral['resolve'] & Volatile['resolve']>>)) => any | Promise<any>;
|
|
693
|
-
export interface DocumentDecoration extends Partial<OpenAPIV3.OperationObject> {
|
|
694
|
-
/**
|
|
695
|
-
* Pass `true` to hide route from OpenAPI/swagger document
|
|
696
|
-
* */
|
|
697
|
-
hide?: boolean;
|
|
698
|
-
}
|
|
699
|
-
export type ResolveHandler<in out Route extends RouteSchema, in out Singleton extends SingletonBase, Derivative extends Record<string, unknown> | AnyElysiaCustomStatusResponse | void = Record<string, unknown> | AnyElysiaCustomStatusResponse | void> = (context: Context<Route, Singleton>) => MaybePromise<Derivative>;
|
|
700
|
-
export type ResolveReturnType<T extends MaybeArray<unknown>> = any[] extends T ? {} : T extends any[] ? _ResolveReturnTypeArray<// @ts-ignore Trust me bro
|
|
701
|
-
T> : Exclude<Awaited<ReturnType<T>>, AnyElysiaCustomStatusResponse> extends infer Value extends Record<any, unknown> ? Value : {};
|
|
702
|
-
type _ResolveReturnTypeArray<T, Carry = {}> = T extends [
|
|
703
|
-
infer Fn,
|
|
704
|
-
...infer Rest
|
|
705
|
-
] ? Exclude<Awaited<ReturnType<Fn>>, AnyElysiaCustomStatusResponse> extends infer Value extends Record<any, unknown> ? _ResolveReturnTypeArray<Rest, Value & Carry> : _ResolveReturnTypeArray<Rest, Carry & {}> : Prettify<Carry>;
|
|
706
|
-
export type AnyLocalHook = LocalHook<any, any, any, any, any>;
|
|
707
|
-
export interface BaseHookLifeCycle<in out Schema extends RouteSchema, in out Singleton extends SingletonBase, in out Errors extends {
|
|
708
|
-
[key in string]: Error;
|
|
709
|
-
}, in out Parser extends keyof any = ''> {
|
|
710
|
-
detail?: DocumentDecoration;
|
|
711
|
-
/**
|
|
712
|
-
* Short for 'Content-Type'
|
|
713
|
-
*
|
|
714
|
-
* Available:
|
|
715
|
-
* - 'none': do not parse body
|
|
716
|
-
* - 'text' / 'text/plain': parse body as string
|
|
717
|
-
* - 'json' / 'application/json': parse body as json
|
|
718
|
-
* - 'formdata' / 'multipart/form-data': parse body as form-data
|
|
719
|
-
* - 'urlencoded' / 'application/x-www-form-urlencoded: parse body as urlencoded
|
|
720
|
-
* - 'arraybuffer': parse body as readable stream
|
|
721
|
-
*/
|
|
722
|
-
parse?: MaybeArray<BodyHandler<Schema, Singleton> | ContentType | Parser>;
|
|
723
|
-
/**
|
|
724
|
-
* Transform context's value
|
|
725
|
-
*/
|
|
726
|
-
transform?: MaybeArray<TransformHandler<Schema, Singleton>>;
|
|
727
|
-
/**
|
|
728
|
-
* Execute before main handler
|
|
729
|
-
*/
|
|
730
|
-
beforeHandle?: MaybeArray<OptionalHandler<Schema, Singleton>>;
|
|
731
|
-
/**
|
|
732
|
-
* Execute after main handler
|
|
733
|
-
*/
|
|
734
|
-
afterHandle?: MaybeArray<AfterHandler<Schema, Singleton>>;
|
|
735
|
-
/**
|
|
736
|
-
* Execute after main handler
|
|
737
|
-
*/
|
|
738
|
-
mapResponse?: MaybeArray<MapResponse<Schema, Singleton>>;
|
|
739
|
-
/**
|
|
740
|
-
* Execute after response is sent
|
|
741
|
-
*/
|
|
742
|
-
afterResponse?: MaybeArray<AfterResponseHandler<Schema, Singleton>>;
|
|
743
|
-
/**
|
|
744
|
-
* Catch error
|
|
745
|
-
*/
|
|
746
|
-
error?: MaybeArray<ErrorHandler<Errors, Schema, Singleton>>;
|
|
747
|
-
tags?: DocumentDecoration['tags'];
|
|
748
|
-
}
|
|
749
|
-
export type CreateDecorator<Singleton extends SingletonBase, Ephemeral extends EphemeralType, Volatile extends EphemeralType> = {} extends Ephemeral ? {} extends Volatile ? Singleton : Singleton & Volatile : {} extends Volatile ? Singleton & Ephemeral : Singleton & Ephemeral & Volatile;
|
|
750
|
-
export type AnyBaseHookLifeCycle = BaseHookLifeCycle<any, any, any, any>;
|
|
751
|
-
export type NonResolvableMacroKey = keyof AnyBaseHookLifeCycle | keyof InputSchema | 'resolve';
|
|
752
|
-
interface RouteSchemaWithResolvedMacro extends RouteSchema {
|
|
753
|
-
response: PossibleResponse;
|
|
754
|
-
return: PossibleResponse;
|
|
755
|
-
resolve: Record<string, unknown>;
|
|
756
|
-
}
|
|
757
|
-
export type LocalHook<Input extends BaseMacro, Schema extends RouteSchemaWithResolvedMacro, Singleton extends SingletonBase, Errors extends {
|
|
758
|
-
[key in string]: Error;
|
|
759
|
-
}, Parser extends keyof any = ''> = {
|
|
760
|
-
detail?: DocumentDecoration;
|
|
761
|
-
/**
|
|
762
|
-
* Short for 'Content-Type'
|
|
763
|
-
*
|
|
764
|
-
* Available:
|
|
765
|
-
* - 'none': do not parse body
|
|
766
|
-
* - 'text' / 'text/plain': parse body as string
|
|
767
|
-
* - 'json' / 'application/json': parse body as json
|
|
768
|
-
* - 'formdata' / 'multipart/form-data': parse body as form-data
|
|
769
|
-
* - 'urlencoded' / 'application/x-www-form-urlencoded: parse body as urlencoded
|
|
770
|
-
* - 'arraybuffer': parse body as readable stream
|
|
771
|
-
*/
|
|
772
|
-
parse?: MaybeArray<BodyHandler<Schema, Singleton & {
|
|
773
|
-
resolve: Schema['resolve'];
|
|
774
|
-
}> | ContentType | Parser>;
|
|
775
|
-
/**
|
|
776
|
-
* Transform context's value
|
|
777
|
-
*/
|
|
778
|
-
transform?: MaybeArray<TransformHandler<Schema, Singleton & {
|
|
779
|
-
resolve: Schema['resolve'];
|
|
780
|
-
}>>;
|
|
781
|
-
/**
|
|
782
|
-
* Execute before main handler
|
|
783
|
-
*/
|
|
784
|
-
beforeHandle?: MaybeArray<OptionalHandler<Schema, Singleton & {
|
|
785
|
-
resolve: Schema['resolve'];
|
|
786
|
-
}>>;
|
|
787
|
-
/**
|
|
788
|
-
* Execute after main handler
|
|
789
|
-
*/
|
|
790
|
-
afterHandle?: MaybeArray<AfterHandler<Schema, Singleton & {
|
|
791
|
-
resolve: Schema['resolve'];
|
|
792
|
-
}>>;
|
|
793
|
-
/**
|
|
794
|
-
* Execute after main handler
|
|
795
|
-
*/
|
|
796
|
-
mapResponse?: MaybeArray<MapResponse<Schema, Singleton & {
|
|
797
|
-
resolve: Schema['resolve'];
|
|
798
|
-
}>>;
|
|
799
|
-
/**
|
|
800
|
-
* Execute after response is sent
|
|
801
|
-
*/
|
|
802
|
-
afterResponse?: MaybeArray<AfterResponseHandler<Schema, Singleton & {
|
|
803
|
-
resolve: Schema['resolve'];
|
|
804
|
-
}>>;
|
|
805
|
-
/**
|
|
806
|
-
* Catch error
|
|
807
|
-
*/
|
|
808
|
-
error?: MaybeArray<ErrorHandler<Errors, Schema, Singleton & {
|
|
809
|
-
resolve: Schema['resolve'];
|
|
810
|
-
}>>;
|
|
811
|
-
tags?: DocumentDecoration['tags'];
|
|
812
|
-
} & (Input extends any ? Input : Prettify<Input>);
|
|
813
|
-
export type GuardLocalHook<Input extends BaseMacro | undefined, Schema extends RouteSchema, Singleton extends SingletonBase, Parser extends keyof any, BeforeHandle extends MaybeArray<OptionalHandler<any, any>>, AfterHandle extends MaybeArray<AfterHandler<any, any>>, ErrorHandle extends MaybeArray<ErrorHandler<any, any, any>>, GuardType extends GuardSchemaType = 'standalone', AsType extends LifeCycleType = 'local'> = (Input extends any ? Input : Prettify<Input>) & {
|
|
814
|
-
/**
|
|
815
|
-
* @default 'override'
|
|
816
|
-
*/
|
|
817
|
-
as?: AsType;
|
|
818
|
-
/**
|
|
819
|
-
* @default 'standalone'
|
|
820
|
-
* @since 1.3.0
|
|
821
|
-
*/
|
|
822
|
-
schema?: GuardType;
|
|
823
|
-
detail?: DocumentDecoration;
|
|
824
|
-
/**
|
|
825
|
-
* Short for 'Content-Type'
|
|
826
|
-
*
|
|
827
|
-
* Available:
|
|
828
|
-
* - 'none': do not parse body
|
|
829
|
-
* - 'text' / 'text/plain': parse body as string
|
|
830
|
-
* - 'json' / 'application/json': parse body as json
|
|
831
|
-
* - 'formdata' / 'multipart/form-data': parse body as form-data
|
|
832
|
-
* - 'urlencoded' / 'application/x-www-form-urlencoded: parse body as urlencoded
|
|
833
|
-
* - 'arraybuffer': parse body as readable stream
|
|
834
|
-
*/
|
|
835
|
-
parse?: MaybeArray<BodyHandler<Schema, Singleton> | ContentType | Parser>;
|
|
836
|
-
/**
|
|
837
|
-
* Transform context's value
|
|
838
|
-
*/
|
|
839
|
-
transform?: MaybeArray<TransformHandler<Schema, Singleton>>;
|
|
840
|
-
/**
|
|
841
|
-
* Execute before main handler
|
|
842
|
-
*/
|
|
843
|
-
beforeHandle?: BeforeHandle;
|
|
844
|
-
/**
|
|
845
|
-
* Execute after main handler
|
|
846
|
-
*/
|
|
847
|
-
afterHandle?: AfterHandle;
|
|
848
|
-
/**
|
|
849
|
-
* Execute after main handler
|
|
850
|
-
*/
|
|
851
|
-
mapResponse?: MaybeArray<MapResponse<Schema, Singleton>>;
|
|
852
|
-
/**
|
|
853
|
-
* Execute after response is sent
|
|
854
|
-
*/
|
|
855
|
-
afterResponse?: MaybeArray<AfterResponseHandler<Schema, Singleton>>;
|
|
856
|
-
/**
|
|
857
|
-
* Catch error
|
|
858
|
-
*/
|
|
859
|
-
error?: ErrorHandle;
|
|
860
|
-
tags?: DocumentDecoration['tags'];
|
|
861
|
-
};
|
|
862
|
-
export type ComposedHandler = (context: Context) => MaybePromise<Response>;
|
|
863
|
-
export interface InternalRoute {
|
|
864
|
-
method: HTTPMethod;
|
|
865
|
-
path: string;
|
|
866
|
-
composed: ComposedHandler | Response | null;
|
|
867
|
-
compile(): ComposedHandler;
|
|
868
|
-
handler: Handler;
|
|
869
|
-
hooks: AnyLocalHook;
|
|
870
|
-
websocket?: AnyWSLocalHook;
|
|
871
|
-
}
|
|
872
|
-
export interface SchemaValidator {
|
|
873
|
-
createBody?(): ElysiaTypeCheck<any>;
|
|
874
|
-
createHeaders?(): ElysiaTypeCheck<any>;
|
|
875
|
-
createQuery?(): ElysiaTypeCheck<any>;
|
|
876
|
-
createParams?(): ElysiaTypeCheck<any>;
|
|
877
|
-
createCookie?(): ElysiaTypeCheck<any>;
|
|
878
|
-
createResponse?(): Record<number, ElysiaTypeCheck<any>>;
|
|
879
|
-
body?: ElysiaTypeCheck<any>;
|
|
880
|
-
headers?: ElysiaTypeCheck<any>;
|
|
881
|
-
query?: ElysiaTypeCheck<any>;
|
|
882
|
-
params?: ElysiaTypeCheck<any>;
|
|
883
|
-
cookie?: ElysiaTypeCheck<any>;
|
|
884
|
-
response?: Record<number, ElysiaTypeCheck<any>>;
|
|
885
|
-
}
|
|
886
|
-
export type AddPrefix<in out Prefix extends string, in out T> = {
|
|
887
|
-
[K in keyof T as Prefix extends string ? `${Prefix}${K & string}` : K]: T[K];
|
|
888
|
-
};
|
|
889
|
-
export type AddPrefixCapitalize<in out Prefix extends string, in out T> = {
|
|
890
|
-
[K in keyof T as `${Prefix}${Capitalize<K & string>}`]: T[K];
|
|
891
|
-
};
|
|
892
|
-
export type AddSuffix<in out Suffix extends string, in out T> = {
|
|
893
|
-
[K in keyof T as `${K & string}${Suffix}`]: T[K];
|
|
894
|
-
};
|
|
895
|
-
export type AddSuffixCapitalize<in out Suffix extends string, in out T> = {
|
|
896
|
-
[K in keyof T as `${K & string}${Capitalize<Suffix>}`]: T[K];
|
|
897
|
-
};
|
|
898
|
-
export interface Checksum {
|
|
899
|
-
name?: string;
|
|
900
|
-
seed?: unknown;
|
|
901
|
-
checksum: number;
|
|
902
|
-
stack?: string;
|
|
903
|
-
routes?: InternalRoute[];
|
|
904
|
-
decorators?: SingletonBase['decorator'];
|
|
905
|
-
store?: SingletonBase['store'];
|
|
906
|
-
error?: DefinitionBase['error'];
|
|
907
|
-
dependencies?: Record<string, Checksum[]>;
|
|
908
|
-
derive?: {
|
|
909
|
-
fn: string;
|
|
910
|
-
stack: string;
|
|
911
|
-
}[];
|
|
912
|
-
resolve?: {
|
|
913
|
-
fn: string;
|
|
914
|
-
stack: string;
|
|
915
|
-
}[];
|
|
916
|
-
}
|
|
917
|
-
export type BaseMacro = Record<string, string | number | boolean | Object | undefined | null>;
|
|
918
|
-
export type MaybeValueOrVoidFunction<T> = T | ((...a: any) => void | T);
|
|
919
|
-
export interface MacroProperty<in out Macro extends BaseMacro = {}, in out TypedRoute extends RouteSchema = {}, in out Singleton extends SingletonBase = {
|
|
920
|
-
decorator: {};
|
|
921
|
-
store: {};
|
|
922
|
-
derive: {};
|
|
923
|
-
resolve: {};
|
|
924
|
-
}, in out Errors extends Record<string, Error> = {}> {
|
|
925
|
-
/**
|
|
926
|
-
* Deduplication similar to Elysia.constructor.seed
|
|
927
|
-
*/
|
|
928
|
-
seed?: unknown;
|
|
929
|
-
parse?: MaybeArray<BodyHandler<TypedRoute, Singleton>>;
|
|
930
|
-
transform?: MaybeArray<VoidHandler<TypedRoute, Singleton>>;
|
|
931
|
-
beforeHandle?: MaybeArray<OptionalHandler<TypedRoute, Singleton>>;
|
|
932
|
-
afterHandle?: MaybeArray<AfterHandler<TypedRoute, Singleton>>;
|
|
933
|
-
error?: MaybeArray<ErrorHandler<Errors, TypedRoute, Singleton>>;
|
|
934
|
-
mapResponse?: MaybeArray<MapResponse<TypedRoute, Singleton>>;
|
|
935
|
-
afterResponse?: MaybeArray<AfterResponseHandler<TypedRoute, Singleton>>;
|
|
936
|
-
resolve?: MaybeArray<ResolveHandler<TypedRoute, Singleton>>;
|
|
937
|
-
detail?: DocumentDecoration;
|
|
938
|
-
/**
|
|
939
|
-
* Introspect hook option for documentation generation or analysis
|
|
940
|
-
*
|
|
941
|
-
* @param option
|
|
942
|
-
*/
|
|
943
|
-
introspect?(option: Prettify<Macro>): unknown;
|
|
944
|
-
}
|
|
945
|
-
export interface Macro<in out Macro extends BaseMacro = {}, in out Input extends BaseMacro = {}, in out TypedRoute extends RouteSchema = {}, in out Singleton extends SingletonBase = {
|
|
946
|
-
decorator: {};
|
|
947
|
-
store: {};
|
|
948
|
-
derive: {};
|
|
949
|
-
resolve: {};
|
|
950
|
-
}, in out Errors extends Record<string, Error> = {}> {
|
|
951
|
-
[K: keyof any]: MaybeValueOrVoidFunction<Input & MacroProperty<Macro, TypedRoute, Singleton, Errors>>;
|
|
952
|
-
}
|
|
953
|
-
export type MaybeFunction<T> = T | ((...args: any[]) => T);
|
|
954
|
-
export type MacroToProperty<in out T extends Macro<any, any, any, any>> = Prettify<{
|
|
955
|
-
[K in keyof T]: T[K] extends Function ? T[K] extends (a: infer Params) => any ? Params : boolean : boolean;
|
|
956
|
-
}>;
|
|
957
|
-
interface MacroOptions {
|
|
958
|
-
insert?: 'before' | 'after';
|
|
959
|
-
stack?: 'global' | 'local';
|
|
960
|
-
}
|
|
961
|
-
export interface MacroManager<in out TypedRoute extends RouteSchema = {}, in out Singleton extends SingletonBase = {
|
|
962
|
-
decorator: {};
|
|
963
|
-
store: {};
|
|
964
|
-
derive: {};
|
|
965
|
-
resolve: {};
|
|
966
|
-
}, in out Errors extends Record<string, Error> = {}> {
|
|
967
|
-
body(schema: InputSchema['body']): unknown;
|
|
968
|
-
headers(schema: InputSchema['headers']): unknown;
|
|
969
|
-
query(schema: InputSchema['query']): unknown;
|
|
970
|
-
params(schema: InputSchema['params']): unknown;
|
|
971
|
-
cookie(schema: InputSchema['cookie']): unknown;
|
|
972
|
-
response(schema: InputSchema['response']): unknown;
|
|
973
|
-
detail(detail: DocumentDecoration): unknown;
|
|
974
|
-
onParse(fn: MaybeArray<BodyHandler<TypedRoute, Singleton>>): unknown;
|
|
975
|
-
onParse(options: MacroOptions, fn: MaybeArray<BodyHandler<TypedRoute, Singleton>>): unknown;
|
|
976
|
-
onTransform(fn: MaybeArray<VoidHandler<TypedRoute, Singleton>>): unknown;
|
|
977
|
-
onTransform(options: MacroOptions, fn: MaybeArray<VoidHandler<TypedRoute, Singleton>>): unknown;
|
|
978
|
-
onBeforeHandle(fn: MaybeArray<OptionalHandler<TypedRoute, Singleton>>): unknown;
|
|
979
|
-
onBeforeHandle(options: MacroOptions, fn: MaybeArray<OptionalHandler<TypedRoute, Singleton>>): unknown;
|
|
980
|
-
onAfterHandle(fn: MaybeArray<AfterHandler<TypedRoute, Singleton>>): unknown;
|
|
981
|
-
onAfterHandle(options: MacroOptions, fn: MaybeArray<AfterHandler<TypedRoute, Singleton>>): unknown;
|
|
982
|
-
onError(fn: MaybeArray<ErrorHandler<Errors, TypedRoute, Singleton>>): unknown;
|
|
983
|
-
onError(options: MacroOptions, fn: MaybeArray<ErrorHandler<Errors, TypedRoute, Singleton>>): unknown;
|
|
984
|
-
mapResponse(fn: MaybeArray<MapResponse<TypedRoute, Singleton>>): unknown;
|
|
985
|
-
mapResponse(options: MacroOptions, fn: MaybeArray<MapResponse<TypedRoute, Singleton>>): unknown;
|
|
986
|
-
onAfterResponse(fn: MaybeArray<AfterResponseHandler<TypedRoute, Singleton>>): unknown;
|
|
987
|
-
onAfterResponse(options: MacroOptions, fn: MaybeArray<AfterResponseHandler<TypedRoute, Singleton>>): unknown;
|
|
988
|
-
events: {
|
|
989
|
-
global: Partial<LifeCycleStore & RouteSchema>;
|
|
990
|
-
local: Partial<LifeCycleStore & RouteSchema>;
|
|
991
|
-
};
|
|
992
|
-
}
|
|
993
|
-
type _CreateEden<Path extends string, Property extends Record<string, unknown> = {}> = Path extends `${infer Start}/${infer Rest}` ? {
|
|
994
|
-
[x in Start]: _CreateEden<Rest, Property>;
|
|
995
|
-
} : Path extends '' ? Property : {
|
|
996
|
-
[x in Path]: Property;
|
|
742
|
+
type ObjectMacroDefs<Body, Headers, Query, Params, Cookie, N, AmbientSchema extends RouteSchema, ScopedSchemas extends RouteSchema, Singleton extends SingletonBase, Definitions extends DefinitionBase, MacroNames extends BaseMacro, MacroFn = {}, Refs = {}> = MacroChannel<Body, 'body', Definitions> & MacroChannel<Headers, 'headers', Definitions> & MacroChannel<Query, 'query', Definitions> & MacroChannel<Params, 'params', Definitions> & MacroChannel<Cookie, 'cookie', Definitions> & MacroRefChannel<Refs> & { [K in keyof N]: MaybeValueOrVoidFunction<MacroProperty<MacroNames & InputSchema<keyof Definitions['typebox'] & string>, IntersectIfObjectSchema<MergeSchema<UnwrapMacroSchema<MacroDefSchema<K, Body, Headers, Query, Params, Cookie>, Definitions['typebox']>, AmbientSchema>, ScopedSchemas>, Singleton & {
|
|
743
|
+
derive: Singleton['derive'] & MacroRefResolve<MacroFn, K extends keyof Refs ? Refs[K] : {}, Definitions['typebox']>;
|
|
744
|
+
}, Definitions['error']>> } & { [K in keyof N]: N[K] extends ((...a: any[]) => any) ? unknown : string extends keyof N[K] ? unknown : { [P in Exclude<keyof N[K], MacroPropertyKey | InputSchemaKey | keyof MacroNames | keyof N>]: `Unknown macro property '${P & string}'` } } & N;
|
|
745
|
+
type CreateEden<Path extends string, Property extends Record<string, unknown> = {}> = Path extends `/${infer Rest}` ? _CreateEden<Rest, Property> : Path extends '' | '/' ? Property : _CreateEden<Path, Property>;
|
|
746
|
+
type _CreateEden<Path extends string, Property extends Record<string, unknown> = {}> = Path extends `${infer Start}/${infer Rest}` ? { [x in Start]: _CreateEden<Rest, Property> } : Path extends '' ? Property : { [x in Path]: Property };
|
|
747
|
+
type CreateEdenResponse<Path extends string, Schema extends RouteSchema, MacroContext extends RouteSchema, Res extends PossibleResponse, Err extends Error = never> = RouteSchema extends MacroContext ? {
|
|
748
|
+
body: Schema['body'];
|
|
749
|
+
params: IsNever<keyof Schema['params']> extends true ? ResolvePath<Path> : Schema['params'];
|
|
750
|
+
query: Schema['query'];
|
|
751
|
+
headers: Schema['headers'];
|
|
752
|
+
response: Prettify<Res>;
|
|
753
|
+
error: Err;
|
|
754
|
+
} : {
|
|
755
|
+
body: Prettify<Schema['body'] & MacroContext['body']>;
|
|
756
|
+
params: IsNever<keyof (Schema['params'] & MacroContext['params'])> extends true ? ResolvePath<Path> : Prettify<Schema['params'] & MacroContext['params']>;
|
|
757
|
+
query: Prettify<Schema['query'] & MacroContext['query']>;
|
|
758
|
+
headers: Prettify<Schema['headers'] & MacroContext['headers']>;
|
|
759
|
+
response: Prettify<Res>;
|
|
760
|
+
error: Err;
|
|
997
761
|
};
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
query: unknown;
|
|
1003
|
-
params: {};
|
|
1004
|
-
cookie: unknown;
|
|
1005
|
-
response: unknown;
|
|
1006
|
-
}
|
|
1007
|
-
export interface UnknownRouteSchema<Params = {
|
|
1008
|
-
[name: string]: string | undefined;
|
|
1009
|
-
}> {
|
|
1010
|
-
body: unknown;
|
|
1011
|
-
headers: {
|
|
1012
|
-
[name: string]: string | undefined;
|
|
1013
|
-
};
|
|
1014
|
-
query: {
|
|
1015
|
-
[name: string]: string | undefined;
|
|
1016
|
-
};
|
|
1017
|
-
params: Params;
|
|
1018
|
-
cookie: {};
|
|
1019
|
-
response: unknown;
|
|
1020
|
-
}
|
|
1021
|
-
type Extract200<T> = T extends AnyElysiaCustomStatusResponse ? Exclude<T, AnyElysiaCustomStatusResponse> | Extract<T, ElysiaCustomStatusResponse<200, any, 200>>['response'] : T;
|
|
1022
|
-
export type IsUnknown<T> = [unknown] extends [T] ? IsAny<T> extends true ? false : true : false;
|
|
1023
|
-
export type ValueToResponseSchema<Value> = ExtractErrorFromHandle<Value> & (Extract200<Value> extends infer R200 ? undefined extends R200 ? {} : IsNever<R200> extends true ? {} : {
|
|
1024
|
-
200: R200;
|
|
762
|
+
type CreateWSEdenResponse<Path extends string, Schema extends RouteSchema, MacroContext extends RouteSchema, Res extends PossibleResponse> = Omit<CreateEdenResponse<Path, Schema, MacroContext, Res>, 'error'>;
|
|
763
|
+
type Extract200<T> = T extends AnyElysiaStatus ? Exclude<T, AnyElysiaStatus> | Extract<T, ElysiaStatus<200, any, 200>>['response'] : T;
|
|
764
|
+
type ValueToResponseSchema<Value, Errors extends ErrorDefinition[] = []> = ExtractErrorFromHandle<Exclude<Value, Error>> & ExtractReturnedError<Value, Errors> & (Extract200<Exclude<Value, Error>> extends infer R200 ? undefined extends R200 ? {} : IsNever<R200> extends true ? {} : {
|
|
765
|
+
200: R200;
|
|
1025
766
|
} : {});
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
type ReconcileStatus<in out A extends Record<number, unknown>, in out B extends Record<number, unknown>> = {
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
767
|
+
type ValueOrFunctionToResponseSchema<T, Errors extends ErrorDefinition[] = []> = T extends ((...a: any) => MaybePromise<infer R>) ? ValueToResponseSchema<R, Errors> : ValueToResponseSchema<T, Errors>;
|
|
768
|
+
type ElysiaHandlerToResponseSchema<in out Handle extends Function> = Prettify<Handle extends ((...a: any) => MaybePromise<infer R>) ? ValueToResponseSchema<Exclude<R, undefined>> : {}>;
|
|
769
|
+
type ElysiaHandlerToResponseSchemas<Handle extends Function[], Carry extends PossibleResponse = {}> = Handle extends [infer Current, ...infer Rest] ? ElysiaHandlerToResponseSchemas<Rest, UnionResponseStatus<ElysiaHandlerToResponseSchema<Current>, Carry>> : Prettify<Carry>;
|
|
770
|
+
type ElysiaHandlerToResponseSchemaAmbiguous<Schemas extends MaybeArray<Function>> = MaybeArray<(...a: any) => any> extends Schemas ? {} : Schemas extends Function ? ElysiaHandlerToResponseSchema<Schemas> : Schemas extends Function[] ? ElysiaHandlerToResponseSchemas<Schemas> : {};
|
|
771
|
+
type ReconcileStatus<in out A extends Record<number, unknown>, in out B extends Record<number, unknown>> = { [K in keyof A | keyof B]: K extends keyof A ? A[K] : B[K] };
|
|
772
|
+
type UnionResponseStatus<A, B> = {} extends A ? B : {} extends B ? A : { [key in keyof A | keyof B]: key extends keyof A ? key extends keyof B ? A[key] | B[key] : A[key] : key extends keyof B ? B[key] : never };
|
|
773
|
+
type HasInputValidator<Schema extends RouteSchema, Path extends string> = EmptyInputSchema extends Pick<Schema, Exclude<InputSchemaKey, 'params' | 'response'>> ? undefined extends Schema['params'] ? false : Schema['params'] extends ResolvePath<Path> ? ResolvePath<Path> extends Schema['params'] ? false : true : true : true;
|
|
774
|
+
type ComposeElysiaResponse<Schema extends RouteSchema, Handle, Possibility extends PossibleResponse, Errors extends ErrorDefinition[] = [], Path extends string = string> = ReconcileStatus<Schema['response'], UnionResponseStatus<ValueOrFunctionToResponseSchema<Handle, Errors>, Possibility & (HasInputValidator<Schema, Path> extends false ? {} : {
|
|
775
|
+
422: {
|
|
776
|
+
type: 'validation';
|
|
777
|
+
title: 'Validation Error';
|
|
778
|
+
status: 422;
|
|
779
|
+
detail?: string;
|
|
780
|
+
on: string;
|
|
781
|
+
found?: unknown;
|
|
782
|
+
property?: string;
|
|
783
|
+
expected?: string;
|
|
784
|
+
};
|
|
1043
785
|
})>>;
|
|
1044
|
-
|
|
1045
|
-
[ErrorResponse in Extract<Handle, AnyElysiaCustomStatusResponse> as ErrorResponse extends AnyElysiaCustomStatusResponse ? ErrorResponse['code'] : never]: Prettify<ErrorResponse['response']>;
|
|
1046
|
-
};
|
|
1047
|
-
export type MergeElysiaInstances<Instances extends AnyElysia[] = [], Prefix extends string = '', Singleton extends SingletonBase = {
|
|
1048
|
-
decorator: {};
|
|
1049
|
-
store: {};
|
|
1050
|
-
derive: {};
|
|
1051
|
-
resolve: {};
|
|
1052
|
-
}, Definitions extends DefinitionBase = {
|
|
1053
|
-
typebox: {};
|
|
1054
|
-
error: {};
|
|
1055
|
-
}, Metadata extends MetadataBase = {
|
|
1056
|
-
schema: {};
|
|
1057
|
-
standaloneSchema: {};
|
|
1058
|
-
macro: {};
|
|
1059
|
-
macroFn: {};
|
|
1060
|
-
parser: {};
|
|
1061
|
-
response: {};
|
|
1062
|
-
}, Ephemeral extends EphemeralType = {
|
|
1063
|
-
derive: {};
|
|
1064
|
-
resolve: {};
|
|
1065
|
-
schema: {};
|
|
1066
|
-
standaloneSchema: {};
|
|
1067
|
-
response: {};
|
|
1068
|
-
}, Volatile extends EphemeralType = {
|
|
1069
|
-
derive: {};
|
|
1070
|
-
resolve: {};
|
|
1071
|
-
schema: {};
|
|
1072
|
-
standaloneSchema: {};
|
|
1073
|
-
response: {};
|
|
1074
|
-
}, Routes extends RouteBase = {}> = Instances extends [
|
|
1075
|
-
infer Current extends AnyElysia,
|
|
1076
|
-
...infer Rest extends AnyElysia[]
|
|
1077
|
-
] ? MergeElysiaInstances<Rest, Prefix, Singleton & Current['~Singleton'], Definitions & Current['~Definitions'], Metadata & Current['~Metadata'], Ephemeral, Volatile & Current['~Ephemeral'], Routes & (Prefix extends `` ? Current['~Routes'] : CreateEden<Prefix, Current['~Routes']>)> : Elysia<Prefix, {
|
|
1078
|
-
decorator: Singleton['decorator'];
|
|
1079
|
-
store: Prettify<Singleton['store']>;
|
|
1080
|
-
derive: Singleton['derive'];
|
|
1081
|
-
resolve: Singleton['resolve'];
|
|
1082
|
-
}, Definitions, Metadata, Routes, Ephemeral, Volatile>;
|
|
1083
|
-
export type LifeCycleType = 'global' | 'local' | 'scoped';
|
|
1084
|
-
export type GuardSchemaType = 'override' | 'standalone';
|
|
1085
|
-
type PartialIf<T, Condition extends boolean> = Condition extends true ? Partial<T> : T;
|
|
1086
|
-
export type ExcludeElysiaResponse<T> = PartialIf<Exclude<Awaited<T>, AnyElysiaCustomStatusResponse> extends infer A ? IsNever<A & {}> extends true ? {} : // Intersect all union and fallback never to {}
|
|
1087
|
-
A & {} : {}, undefined extends Awaited<T> ? true : false>;
|
|
786
|
+
type ExtractErrorFromHandle<in out Handle> = { [ErrorResponse in Extract<Handle, AnyElysiaStatus> as ErrorResponse extends AnyElysiaStatus ? ErrorResponse['code'] : never]: Prettify<ErrorResponse['response']> };
|
|
1088
787
|
/**
|
|
1089
|
-
*
|
|
788
|
+
* Status used when an error handler returns a plain value (or falls through):
|
|
789
|
+
* the error's declared literal `status`, otherwise 500
|
|
1090
790
|
*/
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
}, Path>;
|
|
791
|
+
type ErrorFallbackStatus<E> = E extends {
|
|
792
|
+
status: infer S extends number;
|
|
793
|
+
} ? number extends S ? 500 : S : 500;
|
|
1095
794
|
/**
|
|
1096
|
-
*
|
|
795
|
+
* Body produced when no error handler returns a value:
|
|
796
|
+
* the error's declared `response`, otherwise its message (string)
|
|
1097
797
|
*/
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
safeParse(a: T): {
|
|
1109
|
-
success: true;
|
|
1110
|
-
data: T;
|
|
1111
|
-
error: null;
|
|
1112
|
-
} | {
|
|
1113
|
-
success: true;
|
|
1114
|
-
data: null;
|
|
1115
|
-
error: string;
|
|
1116
|
-
errors: ModelValidatorError[];
|
|
1117
|
-
};
|
|
1118
|
-
}
|
|
1119
|
-
export type UnionToIntersect<U> = (U extends unknown ? (arg: U) => 0 : never) extends (arg: infer I) => 0 ? I : never;
|
|
1120
|
-
export type ContextAppendType = 'append' | 'override';
|
|
1121
|
-
export type HigherOrderFunction<T extends (...arg: unknown[]) => Function = (...arg: unknown[]) => Function> = (fn: T, request: Request) => ReturnType<T>;
|
|
1122
|
-
type SetContentType = 'application/octet-stream' | 'application/vnd.ms-fontobject' | 'application/epub+zip' | 'application/gzip' | 'application/json' | 'application/ld+json' | 'application/ogg' | 'application/pdf' | 'application/rtf' | 'application/wasm' | 'application/xhtml+xml' | 'application/xml' | 'application/zip' | 'text/css' | 'text/csv' | 'text/calendar' | 'text/event-stream' | 'text/html' | 'text/javascript' | 'text/plain' | 'text/xml' | 'image/avif' | 'image/bmp' | 'image/gif' | 'image/x-icon' | 'image/jpeg' | 'image/png' | 'image/svg+xml' | 'image/tiff' | 'image/webp' | 'multipart/mixed' | 'multipart/alternative' | 'multipart/form-data' | 'audio/aac' | 'audio/x-midi' | 'audio/mpeg' | 'audio/ogg' | 'audio/opus' | 'audio/webm' | 'video/x-msvideo' | 'video/quicktime' | 'video/x-ms-wmv' | 'video/x-msvideo' | 'video/x-flv' | 'video/av1' | 'video/mp4' | 'video/mpeg' | 'video/ogg' | 'video/mp2t' | 'video/webm' | 'video/3gpp' | 'video/3gpp2' | 'font/otf' | 'font/ttf' | 'font/woff' | 'font/woff2' | 'model/gltf+json' | 'model/gltf-binary';
|
|
1123
|
-
export type HTTPHeaders = Record<string, string | number> & {
|
|
1124
|
-
'www-authenticate'?: string;
|
|
1125
|
-
authorization?: string;
|
|
1126
|
-
'proxy-authenticate'?: string;
|
|
1127
|
-
'proxy-authorization'?: string;
|
|
1128
|
-
age?: string;
|
|
1129
|
-
'cache-control'?: string;
|
|
1130
|
-
'clear-site-data'?: string;
|
|
1131
|
-
expires?: string;
|
|
1132
|
-
'no-vary-search'?: string;
|
|
1133
|
-
pragma?: string;
|
|
1134
|
-
'last-modified'?: string;
|
|
1135
|
-
etag?: string;
|
|
1136
|
-
'if-match'?: string;
|
|
1137
|
-
'if-none-match'?: string;
|
|
1138
|
-
'if-modified-since'?: string;
|
|
1139
|
-
'if-unmodified-since'?: string;
|
|
1140
|
-
vary?: string;
|
|
1141
|
-
connection?: string;
|
|
1142
|
-
'keep-alive'?: string;
|
|
1143
|
-
accept?: string;
|
|
1144
|
-
'accept-encoding'?: string;
|
|
1145
|
-
'accept-language'?: string;
|
|
1146
|
-
expect?: string;
|
|
1147
|
-
'max-forwards'?: string;
|
|
1148
|
-
cookie?: string;
|
|
1149
|
-
'set-cookie'?: string | string[];
|
|
1150
|
-
'access-control-allow-origin'?: string;
|
|
1151
|
-
'access-control-allow-credentials'?: string;
|
|
1152
|
-
'access-control-allow-headers'?: string;
|
|
1153
|
-
'access-control-allow-methods'?: string;
|
|
1154
|
-
'access-control-expose-headers'?: string;
|
|
1155
|
-
'access-control-max-age'?: string;
|
|
1156
|
-
'access-control-request-headers'?: string;
|
|
1157
|
-
'access-control-request-method'?: string;
|
|
1158
|
-
origin?: string;
|
|
1159
|
-
'timing-allow-origin'?: string;
|
|
1160
|
-
'content-disposition'?: string;
|
|
1161
|
-
'content-length'?: string | number;
|
|
1162
|
-
'content-type'?: SetContentType | (string & {});
|
|
1163
|
-
'content-encoding'?: string;
|
|
1164
|
-
'content-language'?: string;
|
|
1165
|
-
'content-location'?: string;
|
|
1166
|
-
forwarded?: string;
|
|
1167
|
-
via?: string;
|
|
1168
|
-
location?: string;
|
|
1169
|
-
refresh?: string;
|
|
1170
|
-
allow?: string;
|
|
1171
|
-
server?: 'Elysia' | (string & {});
|
|
1172
|
-
'accept-ranges'?: string;
|
|
1173
|
-
range?: string;
|
|
1174
|
-
'if-range'?: string;
|
|
1175
|
-
'content-range'?: string;
|
|
1176
|
-
'content-security-policy'?: string;
|
|
1177
|
-
'content-security-policy-report-only'?: string;
|
|
1178
|
-
'cross-origin-embedder-policy'?: string;
|
|
1179
|
-
'cross-origin-opener-policy'?: string;
|
|
1180
|
-
'cross-origin-resource-policy'?: string;
|
|
1181
|
-
'expect-ct'?: string;
|
|
1182
|
-
'permission-policy'?: string;
|
|
1183
|
-
'strict-transport-security'?: string;
|
|
1184
|
-
'upgrade-insecure-requests'?: string;
|
|
1185
|
-
'x-content-type-options'?: string;
|
|
1186
|
-
'x-frame-options'?: string;
|
|
1187
|
-
'x-xss-protection'?: string;
|
|
1188
|
-
'last-event-id'?: string;
|
|
1189
|
-
'ping-from'?: string;
|
|
1190
|
-
'ping-to'?: string;
|
|
1191
|
-
'report-to'?: string;
|
|
1192
|
-
te?: string;
|
|
1193
|
-
trailer?: string;
|
|
1194
|
-
'transfer-encoding'?: string;
|
|
1195
|
-
'alt-svg'?: string;
|
|
1196
|
-
'alt-used'?: string;
|
|
1197
|
-
date?: string;
|
|
1198
|
-
dnt?: string;
|
|
1199
|
-
'early-data'?: string;
|
|
1200
|
-
'large-allocation'?: string;
|
|
1201
|
-
link?: string;
|
|
1202
|
-
'retry-after'?: string;
|
|
1203
|
-
'service-worker-allowed'?: string;
|
|
1204
|
-
'source-map'?: string;
|
|
1205
|
-
upgrade?: string;
|
|
1206
|
-
'x-dns-prefetch-control'?: string;
|
|
1207
|
-
'x-forwarded-for'?: string;
|
|
1208
|
-
'x-forwarded-host'?: string;
|
|
1209
|
-
'x-forwarded-proto'?: string;
|
|
1210
|
-
'x-powered-by'?: 'Elysia' | (string & {});
|
|
1211
|
-
'x-request-id'?: string;
|
|
1212
|
-
'x-requested-with'?: string;
|
|
1213
|
-
'x-robots-tag'?: string;
|
|
1214
|
-
'x-ua-compatible'?: string;
|
|
1215
|
-
};
|
|
1216
|
-
export type JoinPath<A extends string, B extends string> = B extends `/${string}` ? `${A}${B}` : `${A}/${B}`;
|
|
1217
|
-
export type UnwrapTypeModule<Module extends TModule<any, any>> = Module extends TModule<infer Type extends TProperties, any> ? Type : {};
|
|
1218
|
-
export type MergeTypeModule<A extends TModule<any, any>, B extends TModule<any, any>> = TModule<Prettify<UnwrapTypeModule<A> & UnwrapTypeModule<B>>>;
|
|
1219
|
-
export type SSEPayload<Data extends unknown = unknown, Event extends string | undefined = string | undefined> = {
|
|
1220
|
-
/** id of the event */
|
|
1221
|
-
id?: string | number | null;
|
|
1222
|
-
/** event name */
|
|
1223
|
-
event?: Event;
|
|
1224
|
-
/** retry in millisecond */
|
|
1225
|
-
retry?: number;
|
|
1226
|
-
/** data to send */
|
|
1227
|
-
data?: Data;
|
|
798
|
+
type ErrorFallbackBody<E> = E extends {
|
|
799
|
+
response: infer R;
|
|
800
|
+
} ? unknown extends R ? string : R : string;
|
|
801
|
+
/**
|
|
802
|
+
* `Definitions['error']` / `EphemeralType['error']` entry registered by an
|
|
803
|
+
* `.error(Class, handler)` call
|
|
804
|
+
*/
|
|
805
|
+
type ErrorDefinitionEntry<E extends abstract new (...args: any) => Error, R> = {
|
|
806
|
+
error: InstanceType<E>;
|
|
807
|
+
response: ErrorHandlerResponseSchema<Awaited<R>, InstanceType<E>>;
|
|
1228
808
|
};
|
|
1229
|
-
|
|
1230
|
-
|
|
809
|
+
type ErrorHandlerResponseSchema<R, E> = ExtractErrorFromHandle<Exclude<R, Error>> & (Exclude<R, Extract<Exclude<R, Error>, AnyElysiaStatus> | undefined> | (undefined extends R ? ErrorFallbackBody<E> : never) extends infer Plain ? IsNever<Plain> extends true ? {} : { [S in ErrorFallbackStatus<E>]: Plain } : {});
|
|
810
|
+
type MatchRegisteredError<V, Errors extends ErrorDefinition[]> = Errors extends [infer Head extends ErrorDefinition, ...infer Rest extends ErrorDefinition[]] ? [V] extends [Head['error']] ? Head['response'] : MatchRegisteredError<V, Rest> : never;
|
|
811
|
+
type HasErrorMatch<V, Errors extends ErrorDefinition[]> = Errors extends [infer Head extends ErrorDefinition, ...infer Rest extends ErrorDefinition[]] ? [V] extends [Head['error']] ? true : HasErrorMatch<V, Rest> : false;
|
|
812
|
+
type UnhandledReturnedError<Value, Errors extends ErrorDefinition[]> = 0 extends 1 & Value ? never : Extract<Value, Error> extends infer Es ? Es extends Error ? HasErrorMatch<Es, Errors> extends true ? never : Es : never : never;
|
|
813
|
+
type UnhandledReturnedErrorOf<T, Errors extends ErrorDefinition[]> = T extends ((...a: any) => MaybePromise<infer R>) ? UnhandledReturnedError<R, Errors> : UnhandledReturnedError<T, Errors>;
|
|
814
|
+
type ResolveRouteErrors<Routes, Errors extends ErrorDefinition[]> = Errors extends [] ? Routes : { [K in keyof Routes]: Routes[K] extends {
|
|
815
|
+
params: any;
|
|
816
|
+
query: any;
|
|
817
|
+
headers: any;
|
|
818
|
+
response: any;
|
|
819
|
+
error: any;
|
|
820
|
+
} ? [Routes[K]['error']] extends [never] ? Routes[K] : Omit<Routes[K], 'response' | 'error'> & {
|
|
821
|
+
response: Prettify<UnionResponseStatus<Routes[K]['response'], ExtractReturnedError<Routes[K]['error'], Errors>>>;
|
|
822
|
+
error: UnhandledReturnedError<Routes[K]['error'], Errors>;
|
|
823
|
+
} : Routes[K] extends Record<keyof any, any> ? ResolveRouteErrors<Routes[K], Errors> : Routes[K] };
|
|
824
|
+
type MergeStatusUnion<U> = { [K in U extends unknown ? keyof U : never]: U extends unknown ? K extends keyof U ? U[K] : never : never };
|
|
825
|
+
/**
|
|
826
|
+
* Map `Error` instances in a handler's return type to the response of their
|
|
827
|
+
* matching `.error(Class, handler)`. Returned errors are forwarded to the
|
|
828
|
+
* error pipeline at runtime, so they never appear in the 200 response
|
|
829
|
+
*/
|
|
830
|
+
type ExtractReturnedError<Value, Errors extends ErrorDefinition[]> = 0 extends 1 & Value ? {} : Extract<Value, Error> extends infer Es ? IsNever<Es> extends true ? {} : MergeStatusUnion<Es extends Error ? MatchRegisteredError<Es, Errors> : never> : {};
|
|
831
|
+
type MergeElysiaInstances<Instances extends AnyElysia[] = [], Prefix extends string = '', Scope extends EventScope = 'local', Singleton extends SingletonBase = DefaultSingleton, Definitions extends DefinitionBase = {
|
|
832
|
+
typebox: {};
|
|
833
|
+
error: [];
|
|
834
|
+
}, Metadata extends MetadataBase = DefaultMetadata, Ephemeral extends EphemeralType = DefaultEphemeral, Volatile extends EphemeralType = DefaultEphemeral, Routes extends RouteBase = {}> = Instances extends [infer Current extends AnyElysia, ...infer Rest extends AnyElysia[]] ? MergeElysiaInstances<Rest, Prefix, Scope, Singleton & Current['~Singleton'], {
|
|
835
|
+
typebox: Definitions['typebox'] & Current['~Definitions']['typebox'];
|
|
836
|
+
error: [...Definitions['error'], ...Current['~Definitions']['error']];
|
|
837
|
+
}, Metadata & Current['~Metadata'], Ephemeral, {
|
|
838
|
+
derive: Volatile['derive'] & Current['~Ephemeral']['derive'];
|
|
839
|
+
schema: Volatile['schema'] & Current['~Ephemeral']['schema'];
|
|
840
|
+
schemas: Volatile['schemas'] & Current['~Ephemeral']['schemas'];
|
|
841
|
+
response: Volatile['response'] & Current['~Ephemeral']['response'];
|
|
842
|
+
error: [...Volatile['error'], ...Current['~Ephemeral']['error']];
|
|
843
|
+
}, ResolveRouteErrors<Routes, [...Current['~Definitions']['error'], ...Current['~Ephemeral']['error']]> & (Prefix extends `` ? ResolveRouteErrors<Current['~Routes'], [...Definitions['error'], ...Ephemeral['error'], ...Volatile['error']]> : CreateEden<Prefix, ResolveRouteErrors<Current['~Routes'], [...Definitions['error'], ...Ephemeral['error'], ...Volatile['error']]>>)> : Elysia<Prefix, Scope, {
|
|
844
|
+
decorator: Singleton['decorator'];
|
|
845
|
+
store: Prettify<Singleton['store']>;
|
|
846
|
+
derive: Singleton['derive'];
|
|
847
|
+
}, Definitions, Metadata, Routes, Ephemeral, Volatile>;
|
|
848
|
+
type WrapFn<Callback extends (...params: any) => MaybePromise<Response> = (request: Request, ...rest: any[]) => MaybePromise<Response>> = (fetch: (request: Request, ...rest: any[]) => MaybePromise<Response>) => Callback;
|
|
849
|
+
type AddRoute<BasePath extends string, Scope extends EventScope, Singleton extends SingletonBase, Definitions extends DefinitionBase, Metadata extends MetadataBase, Routes extends RouteBase, Ephemeral extends EphemeralType, Volatile extends EphemeralType, Method extends string, Path extends string, Schema extends RouteSchema, MacroContext extends RouteSchema, Handle> = Elysia<BasePath, Scope, Singleton, Definitions, Metadata, Routes & CreateEden<JoinPath<BasePath, Path>, { [method in Method]: CreateEdenResponse<Path, Schema, MacroContext, ComposeElysiaResponse<Schema & MacroContext & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], Handle, UnionResponseStatus<Metadata['response'], UnionResponseStatus<Ephemeral['response'], UnionResponseStatus<Volatile['response'], MacroContext['return'] & {}>>>, [...Definitions['error'], ...Ephemeral['error'], ...Volatile['error']], Path>, UnhandledReturnedErrorOf<Handle, [...Definitions['error'], ...Ephemeral['error'], ...Volatile['error']]>> }>, Ephemeral, Volatile>;
|
|
850
|
+
type HookContextSchema<Metadata extends MetadataBase, Ephemeral extends EphemeralType, Volatile extends EphemeralType, BasePath extends string> = MergeSchema<Volatile['schema'], MergeSchema<Ephemeral['schema'], Metadata['schema']>, BasePath> & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'];
|
|
851
|
+
type HookContextSingleton<Singleton extends SingletonBase, Ephemeral extends EphemeralType, Volatile extends EphemeralType> = Singleton & {
|
|
852
|
+
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
1231
853
|
};
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
854
|
+
type LocalHookReturn<BasePath extends string, Scope extends EventScope, Singleton extends SingletonBase, Definitions extends DefinitionBase, Metadata extends MetadataBase, Routes extends RouteBase, Ephemeral extends EphemeralType, Volatile extends EphemeralType, ResponseAddition extends PossibleResponse, DeriveAddition extends Record<string, unknown> = {}> = Elysia<BasePath, Scope, Singleton, Definitions, Metadata, Routes, Ephemeral, {
|
|
855
|
+
derive: Volatile['derive'] & DeriveAddition;
|
|
856
|
+
schema: Volatile['schema'];
|
|
857
|
+
schemas: Volatile['schemas'];
|
|
858
|
+
response: UnionResponseStatus<Volatile['response'], ResponseAddition>;
|
|
859
|
+
error: Volatile['error'];
|
|
860
|
+
}>;
|
|
861
|
+
type PluginHookReturn<BasePath extends string, Scope extends EventScope, Singleton extends SingletonBase, Definitions extends DefinitionBase, Metadata extends MetadataBase, Routes extends RouteBase, Ephemeral extends EphemeralType, Volatile extends EphemeralType, ResponseAddition extends PossibleResponse, DeriveAddition extends Record<string, unknown> = {}> = Elysia<BasePath, Scope, Singleton, Definitions, Metadata, Routes, {
|
|
862
|
+
derive: Ephemeral['derive'] & DeriveAddition;
|
|
863
|
+
schema: Ephemeral['schema'];
|
|
864
|
+
schemas: Ephemeral['schemas'];
|
|
865
|
+
response: UnionResponseStatus<Ephemeral['response'], ResponseAddition>;
|
|
866
|
+
error: Ephemeral['error'];
|
|
867
|
+
}, Volatile>;
|
|
868
|
+
type GlobalHookReturn<BasePath extends string, Scope extends EventScope, Singleton extends SingletonBase, Definitions extends DefinitionBase, Metadata extends MetadataBase, Routes extends RouteBase, Ephemeral extends EphemeralType, Volatile extends EphemeralType, ResponseAddition extends PossibleResponse, DeriveAddition extends Record<string, unknown> = never> = Elysia<BasePath, Scope, [DeriveAddition] extends [never] ? Singleton : {
|
|
869
|
+
decorator: Singleton['decorator'];
|
|
870
|
+
store: Singleton['store'];
|
|
871
|
+
derive: Singleton['derive'] & DeriveAddition;
|
|
872
|
+
}, Definitions, {
|
|
873
|
+
schema: Metadata['schema'];
|
|
874
|
+
schemas: Metadata['schemas'];
|
|
875
|
+
macro: Metadata['macro'];
|
|
876
|
+
macroFn: Metadata['macroFn'];
|
|
877
|
+
parser: Metadata['parser'];
|
|
878
|
+
response: UnionResponseStatus<Metadata['response'], ResponseAddition>;
|
|
879
|
+
}, Routes, Ephemeral, Volatile>;
|
|
880
|
+
type ScopedHookReturn<HookScope extends EventScope, BasePath extends string, Scope extends EventScope, Singleton extends SingletonBase, Definitions extends DefinitionBase, Metadata extends MetadataBase, Routes extends RouteBase, Ephemeral extends EphemeralType, Volatile extends EphemeralType, ResponseAddition extends PossibleResponse, DeriveAddition extends Record<string, unknown> = never> = Elysia<BasePath, Scope, [HookScope] extends ['global'] ? [DeriveAddition] extends [never] ? Singleton : {
|
|
881
|
+
decorator: Singleton['decorator'];
|
|
882
|
+
store: Singleton['store'];
|
|
883
|
+
derive: Singleton['derive'] & DeriveAddition;
|
|
884
|
+
} : Singleton, Definitions, [HookScope] extends ['global'] ? {
|
|
885
|
+
schema: Metadata['schema'];
|
|
886
|
+
schemas: Metadata['schemas'];
|
|
887
|
+
macro: Metadata['macro'];
|
|
888
|
+
macroFn: Metadata['macroFn'];
|
|
889
|
+
parser: Metadata['parser'];
|
|
890
|
+
response: UnionResponseStatus<Metadata['response'], ResponseAddition>;
|
|
891
|
+
} : Metadata, Routes, [HookScope] extends ['global'] ? Ephemeral : [HookScope] extends ['plugin' | 'global'] ? {
|
|
892
|
+
derive: Ephemeral['derive'] & ([DeriveAddition] extends [never] ? {} : DeriveAddition);
|
|
893
|
+
schema: Ephemeral['schema'];
|
|
894
|
+
schemas: Ephemeral['schemas'];
|
|
895
|
+
response: UnionResponseStatus<Ephemeral['response'], ResponseAddition>;
|
|
896
|
+
error: Ephemeral['error'];
|
|
897
|
+
} : Ephemeral, [HookScope] extends ['plugin' | 'global'] ? Volatile : {
|
|
898
|
+
derive: Volatile['derive'] & ([DeriveAddition] extends [never] ? {} : DeriveAddition);
|
|
899
|
+
schema: Volatile['schema'];
|
|
900
|
+
schemas: Volatile['schemas'];
|
|
901
|
+
response: UnionResponseStatus<Volatile['response'], ResponseAddition>;
|
|
902
|
+
error: Volatile['error'];
|
|
903
|
+
}>;
|
|
904
|
+
type ScopedMapDeriveReturn<HookScope extends EventScope, BasePath extends string, Scope extends EventScope, Singleton extends SingletonBase, Definitions extends DefinitionBase, Metadata extends MetadataBase, Routes extends RouteBase, Ephemeral extends EphemeralType, Volatile extends EphemeralType, ResponseAddition extends PossibleResponse, Derive extends Record<string, unknown>> = Elysia<BasePath, Scope, [HookScope] extends ['global'] ? {
|
|
905
|
+
decorator: Singleton['decorator'];
|
|
906
|
+
store: Singleton['store'];
|
|
907
|
+
derive: Derive;
|
|
908
|
+
} : [HookScope] extends ['plugin' | 'local'] ? Singleton : {
|
|
909
|
+
decorator: Singleton['decorator'];
|
|
910
|
+
store: Singleton['store'];
|
|
911
|
+
derive: Partial<Singleton['derive']>;
|
|
912
|
+
}, Definitions, [HookScope] extends ['global'] ? {
|
|
913
|
+
schema: Metadata['schema'];
|
|
914
|
+
schemas: Metadata['schemas'];
|
|
915
|
+
macro: Metadata['macro'];
|
|
916
|
+
macroFn: Metadata['macroFn'];
|
|
917
|
+
parser: Metadata['parser'];
|
|
918
|
+
response: UnionResponseStatus<Metadata['response'], ResponseAddition>;
|
|
919
|
+
} : Metadata, Routes, [HookScope] extends ['global'] ? Ephemeral : [HookScope] extends ['plugin'] ? {
|
|
920
|
+
derive: Derive;
|
|
921
|
+
schema: Ephemeral['schema'];
|
|
922
|
+
schemas: Ephemeral['schemas'];
|
|
923
|
+
response: UnionResponseStatus<Ephemeral['response'], ResponseAddition>;
|
|
924
|
+
error: Ephemeral['error'];
|
|
925
|
+
} : [HookScope] extends ['local'] ? Ephemeral : [HookScope] extends ['plugin' | 'global'] ? {
|
|
926
|
+
derive: Partial<Ephemeral['derive']> & Derive;
|
|
927
|
+
schema: Ephemeral['schema'];
|
|
928
|
+
schemas: Ephemeral['schemas'];
|
|
929
|
+
response: UnionResponseStatus<Ephemeral['response'], ResponseAddition>;
|
|
930
|
+
error: Ephemeral['error'];
|
|
931
|
+
} : 'plugin' extends HookScope ? {
|
|
932
|
+
derive: Partial<Ephemeral['derive']> & Partial<Derive>;
|
|
933
|
+
schema: Ephemeral['schema'];
|
|
934
|
+
schemas: Ephemeral['schemas'];
|
|
935
|
+
response: UnionResponseStatus<Ephemeral['response'], ResponseAddition>;
|
|
936
|
+
error: Ephemeral['error'];
|
|
937
|
+
} : Ephemeral, [HookScope] extends ['plugin' | 'global'] ? Volatile : [HookScope] extends ['local'] ? {
|
|
938
|
+
derive: Derive;
|
|
939
|
+
schema: Volatile['schema'];
|
|
940
|
+
schemas: Volatile['schemas'];
|
|
941
|
+
response: UnionResponseStatus<Volatile['response'], ResponseAddition>;
|
|
942
|
+
error: Volatile['error'];
|
|
1238
943
|
} : {
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
944
|
+
derive: Partial<Volatile['derive']> & Derive;
|
|
945
|
+
schema: Volatile['schema'];
|
|
946
|
+
schemas: Volatile['schemas'];
|
|
947
|
+
response: UnionResponseStatus<Volatile['response'], ResponseAddition>;
|
|
948
|
+
error: Volatile['error'];
|
|
949
|
+
}>;
|
|
950
|
+
type AddWSRoute<BasePath extends string, Scope extends EventScope, Singleton extends SingletonBase, Definitions extends DefinitionBase, Metadata extends MetadataBase, Routes extends RouteBase, Ephemeral extends EphemeralType, Volatile extends EphemeralType, Path extends string, Schema extends RouteSchema, MacroContext extends RouteSchema, Response> = Elysia<BasePath, Scope, Singleton, Definitions, Metadata, Routes & CreateEden<JoinPath<BasePath, Path>, {
|
|
951
|
+
subscribe: CreateWSEdenResponse<Path, Schema, MacroContext, ComposeElysiaResponse<Schema & MacroContext & Metadata['schemas'] & Ephemeral['schemas'] & Volatile['schemas'], Response, UnionResponseStatus<Metadata['response'], UnionResponseStatus<Ephemeral['response'], UnionResponseStatus<Volatile['response'], MacroContext['return'] & {}>>>, [...Definitions['error'], ...Ephemeral['error'], ...Volatile['error']], Path>>;
|
|
952
|
+
}>, Ephemeral, Volatile>;
|
|
953
|
+
type GuardHookSingleton<Singleton extends SingletonBase, Ephemeral extends EphemeralType, Volatile extends EphemeralType, MacroContext> = Singleton & {
|
|
954
|
+
derive: Ephemeral['derive'] & Volatile['derive'] & MacroContext['resolve'];
|
|
1244
955
|
};
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
response: {
|
|
1262
|
-
[path: string]: MaybePromise<Response | undefined> | {
|
|
1263
|
-
[method: string]: MaybePromise<Response | undefined>;
|
|
1264
|
-
};
|
|
1265
|
-
};
|
|
1266
|
-
history: InternalRoute[];
|
|
1267
|
-
}
|
|
1268
|
-
export type ModelsToTypes<T extends Record<keyof any, AnySchema>> = {
|
|
1269
|
-
[K in keyof T]: UnwrapSchema<T[K]>;
|
|
956
|
+
interface StaticMapAliases {
|
|
957
|
+
method: string;
|
|
958
|
+
paths: string[];
|
|
959
|
+
}
|
|
960
|
+
type LazyComposeEntry = {
|
|
961
|
+
kind: 'route';
|
|
962
|
+
route: InternalRoute;
|
|
963
|
+
source?: string;
|
|
964
|
+
} | {
|
|
965
|
+
kind: 'use';
|
|
966
|
+
child: AnyElysia;
|
|
967
|
+
preChain: ChainNode | undefined;
|
|
968
|
+
childBaseLen: number;
|
|
969
|
+
childPlan: LazyComposeEntry[] | undefined;
|
|
970
|
+
childPlanLen: number;
|
|
971
|
+
source?: string;
|
|
1270
972
|
};
|
|
1271
|
-
|
|
973
|
+
//#endregion
|
|
974
|
+
export { AddRoute, AddWSRoute, AfterHandler, AfterResponseHandler, AnyErrorConstructor, AnyLocalHook, type AnySchema, AnyWSLocalHook, AppEvent, AppHook, BaseMacro, BodyHandler, BunHTMLBundlelike, CompiledHandler, ComposeElysiaResponse, ContentType, ContextAppendType, CreateEden, CreateEdenResponse, CreateWSEdenResponse, DefaultEphemeral, DefaultMetadata, DefaultSingleton, DefinitionBase, DocumentDecoration, ElysiaConfig, ElysiaFormData, ElysiaHandlerToResponseSchema, ElysiaHandlerToResponseSchemaAmbiguous, ElysiaHandlerToResponseSchemas, EmptyInputSchema, EphemeralType, Equal, ErrorDefinition, ErrorDefinitionEntry, ErrorHandler, ErrorHandlerResponseSchema, EventFn, EventScope, ExcludeElysiaResponse, ExtractErrorFromHandle, ExtractReturnedError, GetPathParameter, GlobalHookReturn, GracefulHandler, GuardHookSingleton, GuardLocalHook, GuardSchemaType, HTTPHeaders, HTTPMethod, Handler, HistoryEntry, HookContextSchema, HookContextSingleton, InlineHandler, InlineHandlerNonMacro, InlineHandlerResponse, InlineResponse, InputSchema, InputSchemaKey, InternalRoute, IntersectIfObject, IntersectIfObjectSchema, IsAny, IsNever, IsTuple, JoinPath, LazyComposeEntry, LocalHook, LocalHookReturn, Macro, MacroProperty, MacroPropertyKey, MacroSchemaChannel, MacroToContext, MacroToProperty, MapResponse, MaybeArray, MaybePromise, MaybeValueOrVoidFunction, MergeElysiaInstances, MergeSchema, MergeScopedSchemas, MetadataBase, NonResolvableMacroKey, ObjectMacroDefs, OptionalHandler, PluginHookReturn, PossibleResponse, PreHandler, Prettify, PublicRoute, Replace, ResolveHandler, ResolvePath, ResolveRouteErrors, RouteBase, RouteSchema, SSEPayload, ScopedHookReturn, ScopedMapDeriveReturn, SingletonBase, type StandardSchemaV1Like, StaticMapAliases, TransformHandler, type TypeBoxSchema, UnhandledReturnedError, UnhandledReturnedErrorOf, UnionResponseStatus, UnionToIntersect, UnwrapArray, UnwrapBodySchema, UnwrapMacroSchema, UnwrapRoute, UnwrapSchema, ValueOrFunctionToResponseSchema, ValueToResponseSchema, VoidHandler, WrapFn };
|