elysia 2.0.0-beta.2 → 2.0.0-beta.21
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/adapter/bun/index.d.ts +18 -2
- package/dist/adapter/bun/index.js +467 -110
- package/dist/adapter/bun/index.mjs +467 -112
- package/dist/adapter/types.d.ts +2 -21
- package/dist/adapter/utils.d.ts +14 -3
- package/dist/adapter/utils.js +146 -87
- package/dist/adapter/utils.mjs +148 -90
- package/dist/adapter/web-standard/handler.d.ts +1 -1
- package/dist/adapter/web-standard/handler.js +47 -36
- package/dist/adapter/web-standard/handler.mjs +48 -37
- package/dist/adapter/web-standard/index.js +2 -30
- package/dist/adapter/web-standard/index.mjs +2 -30
- package/dist/adapter/web-standard/utils.js +5 -18
- package/dist/adapter/web-standard/utils.mjs +5 -18
- package/dist/base.d.ts +99 -67
- package/dist/base.js +678 -510
- package/dist/base.mjs +682 -514
- package/dist/compile/aot-capture.d.ts +2 -13
- package/dist/compile/aot-capture.js +26 -69
- package/dist/compile/aot-capture.mjs +28 -67
- package/dist/compile/aot-emit.d.ts +9 -7
- package/dist/compile/aot-emit.js +42 -19
- package/dist/compile/aot-emit.mjs +42 -20
- package/dist/compile/aot.d.ts +17 -19
- package/dist/compile/aot.js +41 -51
- package/dist/compile/aot.mjs +39 -49
- package/dist/compile/handler/descriptor.d.ts +9 -12
- package/dist/compile/handler/descriptor.js +19 -44
- package/dist/compile/handler/descriptor.mjs +20 -42
- package/dist/compile/handler/frozen-validator.d.ts +5 -10
- package/dist/compile/handler/frozen-validator.js +55 -105
- package/dist/compile/handler/frozen-validator.mjs +53 -105
- package/dist/compile/handler/index.d.ts +7 -5
- package/dist/compile/handler/index.js +270 -111
- package/dist/compile/handler/index.mjs +270 -113
- package/dist/compile/handler/jit.d.ts +19 -17
- package/dist/compile/handler/jit.js +222 -149
- package/dist/compile/handler/jit.mjs +224 -152
- package/dist/compile/handler/params.d.ts +1 -4
- package/dist/compile/handler/params.js +10 -5
- package/dist/compile/handler/params.mjs +14 -8
- package/dist/compile/handler/reconstruct.d.ts +2 -2
- package/dist/compile/handler/reconstruct.js +6 -4
- package/dist/compile/handler/reconstruct.mjs +6 -4
- package/dist/compile/handler/static-clone-resolver.d.ts +6 -0
- package/dist/compile/handler/static-clone-resolver.js +8 -0
- package/dist/compile/handler/static-clone-resolver.mjs +7 -0
- package/dist/compile/handler/utils.d.ts +22 -11
- package/dist/compile/handler/utils.js +159 -253
- package/dist/compile/handler/utils.mjs +155 -252
- package/dist/compile/jit-probe.d.ts +2 -2
- package/dist/compile/jit-probe.js +2 -3
- package/dist/compile/jit-probe.mjs +2 -3
- package/dist/compile/lexer.d.ts +7 -4
- package/dist/compile/lexer.js +268 -6
- package/dist/compile/lexer.mjs +268 -4
- package/dist/compile/utils.js +7 -4
- package/dist/compile/utils.mjs +7 -4
- package/dist/compiled.d.ts +0 -1
- package/dist/compiled.js +0 -1
- package/dist/compiled.mjs +0 -1
- package/dist/context.d.ts +14 -4
- package/dist/context.js +17 -32
- package/dist/context.mjs +19 -34
- package/dist/cookie/config.d.ts +7 -2
- package/dist/cookie/config.js +76 -16
- package/dist/cookie/config.mjs +77 -18
- package/dist/cookie/cookie.d.ts +1 -1
- package/dist/cookie/cookie.js +8 -10
- package/dist/cookie/cookie.mjs +8 -10
- package/dist/cookie/crypto.d.ts +8 -7
- package/dist/cookie/crypto.js +51 -40
- package/dist/cookie/crypto.mjs +51 -41
- package/dist/cookie/error.d.ts +1 -2
- package/dist/cookie/error.js +6 -4
- package/dist/cookie/error.mjs +6 -4
- package/dist/cookie/lib.js +7 -2
- package/dist/cookie/lib.mjs +7 -2
- package/dist/cookie/serialize.js +1 -1
- package/dist/cookie/serialize.mjs +1 -1
- package/dist/cookie/types.d.ts +10 -0
- package/dist/cookie/utils.d.ts +4 -8
- package/dist/cookie/utils.js +86 -52
- package/dist/cookie/utils.mjs +89 -54
- package/dist/error.d.ts +113 -103
- package/dist/error.js +181 -117
- package/dist/error.mjs +179 -118
- package/dist/generation.d.ts +2 -2
- package/dist/handler/error.d.ts +26 -15
- package/dist/handler/error.js +77 -96
- package/dist/handler/error.mjs +74 -97
- package/dist/handler/fetch.js +87 -108
- package/dist/handler/fetch.mjs +89 -110
- package/dist/handler/utils.d.ts +12 -6
- package/dist/handler/utils.js +84 -28
- package/dist/handler/utils.mjs +80 -28
- package/dist/index.d.ts +12 -12
- package/dist/index.js +2 -9
- package/dist/index.mjs +1 -1
- package/dist/memory.js +1 -1
- package/dist/memory.mjs +1 -1
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/bun.d.ts +8 -1
- package/dist/plugin/aot/bun.js +16 -9
- package/dist/plugin/aot/bun.mjs +17 -10
- package/dist/plugin/aot/core.d.ts +52 -60
- package/dist/plugin/aot/core.js +208 -109
- package/dist/plugin/aot/core.mjs +205 -111
- package/dist/plugin/aot/esbuild.js +8 -5
- package/dist/plugin/aot/esbuild.mjs +9 -6
- package/dist/plugin/aot/hooks.d.ts +6 -17
- package/dist/plugin/aot/hooks.js +36 -14
- package/dist/plugin/aot/hooks.mjs +37 -16
- package/dist/plugin/aot/rspack-loader.d.ts +1 -5
- package/dist/plugin/aot/rspack-loader.js +1 -10
- package/dist/plugin/aot/rspack-loader.mjs +1 -10
- package/dist/plugin/aot/rspack.js +2 -5
- package/dist/plugin/aot/rspack.mjs +3 -6
- package/dist/plugin/aot/source.d.ts +6 -42
- package/dist/plugin/aot/source.js +71 -71
- package/dist/plugin/aot/source.mjs +72 -72
- package/dist/plugin/aot/treeshake.js +2 -6
- package/dist/plugin/aot/treeshake.mjs +2 -6
- package/dist/plugin/aot/unplugin.d.ts +1 -4
- package/dist/plugin/aot/unplugin.js +4 -13
- package/dist/plugin/aot/unplugin.mjs +4 -13
- package/dist/plugin/aot/vite.d.ts +2 -6
- package/dist/plugin/aot/worker.js +2 -2
- package/dist/plugin/aot/worker.mjs +2 -2
- package/dist/plugin/auto-head.js +1 -10
- package/dist/plugin/auto-head.mjs +1 -10
- package/dist/plugin/trace.d.ts +2 -1
- package/dist/route-table.d.ts +3 -0
- package/dist/route-table.js +16 -11
- package/dist/route-table.mjs +16 -11
- package/dist/schema-snapshot.d.ts +0 -4
- package/dist/schema-snapshot.js +32 -49
- package/dist/schema-snapshot.mjs +32 -49
- package/dist/sucrose.d.ts +6 -55
- package/dist/sucrose.js +103 -731
- package/dist/sucrose.mjs +102 -724
- package/dist/trace.d.ts +5 -8
- package/dist/trace.js +23 -134
- package/dist/trace.mjs +24 -135
- package/dist/type/bridge-live.d.ts +4 -2
- package/dist/type/bridge-live.js +6 -3
- package/dist/type/bridge-live.mjs +4 -2
- package/dist/type/bridge.d.ts +6 -4
- package/dist/type/bridge.js +17 -9
- package/dist/type/bridge.mjs +5 -3
- package/dist/type/coerce-plan.d.ts +5 -5
- package/dist/type/coerce-plan.js +41 -39
- package/dist/type/coerce-plan.mjs +43 -39
- package/dist/type/coerce.d.ts +3 -7
- package/dist/type/coerce.js +18 -75
- package/dist/type/coerce.mjs +19 -76
- package/dist/type/compat.d.ts +3 -0
- package/dist/type/compat.js +23 -14
- package/dist/type/compat.mjs +20 -10
- package/dist/type/elysia/array-buffer.d.ts +4 -1
- package/dist/type/elysia/array-buffer.js +17 -17
- package/dist/type/elysia/array-buffer.mjs +17 -17
- package/dist/type/elysia/array-string.js +2 -40
- package/dist/type/elysia/array-string.mjs +2 -39
- package/dist/type/elysia/array.js +5 -9
- package/dist/type/elysia/array.mjs +5 -9
- package/dist/type/elysia/boolean-string.js +2 -3
- package/dist/type/elysia/boolean-string.mjs +1 -1
- package/dist/type/elysia/boolean.js +3 -12
- package/dist/type/elysia/boolean.mjs +3 -11
- package/dist/type/elysia/cookie.d.ts +3 -4
- package/dist/type/elysia/cookie.js +5 -15
- package/dist/type/elysia/cookie.mjs +5 -15
- package/dist/type/elysia/date.js +13 -20
- package/dist/type/elysia/date.mjs +10 -16
- package/dist/type/elysia/file-type.d.ts +11 -4
- package/dist/type/elysia/file-type.js +17 -2
- package/dist/type/elysia/file-type.mjs +17 -3
- package/dist/type/elysia/file.d.ts +1 -3
- package/dist/type/elysia/file.js +11 -27
- package/dist/type/elysia/file.mjs +11 -12
- package/dist/type/elysia/files.js +7 -11
- package/dist/type/elysia/files.mjs +7 -10
- package/dist/type/elysia/form.js +2 -3
- package/dist/type/elysia/form.mjs +3 -3
- package/dist/type/elysia/integer-string.d.ts +1 -1
- package/dist/type/elysia/integer-string.js +4 -30
- package/dist/type/elysia/integer-string.mjs +5 -30
- package/dist/type/elysia/integer.js +3 -12
- package/dist/type/elysia/integer.mjs +3 -11
- package/dist/type/elysia/intersect.js +0 -5
- package/dist/type/elysia/intersect.mjs +0 -5
- package/dist/type/elysia/json-string.d.ts +7 -0
- package/dist/type/elysia/json-string.js +47 -0
- package/dist/type/elysia/json-string.mjs +46 -0
- package/dist/type/elysia/keep-config.d.ts +14 -0
- package/dist/type/elysia/keep-config.js +62 -0
- package/dist/type/elysia/keep-config.mjs +53 -0
- package/dist/type/elysia/maybe-empty.js +3 -4
- package/dist/type/elysia/maybe-empty.mjs +1 -1
- package/dist/type/elysia/nullable.js +2 -3
- package/dist/type/elysia/nullable.mjs +1 -1
- package/dist/type/elysia/number.d.ts +2 -1
- package/dist/type/elysia/number.js +19 -11
- package/dist/type/elysia/number.mjs +18 -10
- package/dist/type/elysia/numeric-enum.d.ts +1 -1
- package/dist/type/elysia/numeric-enum.js +4 -5
- package/dist/type/elysia/numeric-enum.mjs +3 -3
- package/dist/type/elysia/numeric.d.ts +4 -2
- package/dist/type/elysia/numeric.js +20 -17
- package/dist/type/elysia/numeric.mjs +19 -16
- package/dist/type/elysia/object-string.js +2 -37
- package/dist/type/elysia/object-string.mjs +2 -36
- package/dist/type/elysia/object.js +5 -9
- package/dist/type/elysia/object.mjs +5 -9
- package/dist/type/elysia/optional.js +8 -8
- package/dist/type/elysia/optional.mjs +7 -7
- package/dist/type/elysia/problem.d.ts +20 -0
- package/dist/type/elysia/problem.js +25 -0
- package/dist/type/elysia/problem.mjs +24 -0
- package/dist/type/elysia/string.js +4 -3
- package/dist/type/elysia/string.mjs +4 -2
- package/dist/type/elysia/uint8-array.d.ts +1 -1
- package/dist/type/elysia/uint8-array.js +5 -20
- package/dist/type/elysia/uint8-array.mjs +5 -19
- package/dist/type/elysia/union-enum.js +7 -8
- package/dist/type/elysia/union-enum.mjs +6 -6
- package/dist/type/elysia/union.js +0 -5
- package/dist/type/elysia/union.mjs +0 -5
- package/dist/type/elysia/utils.d.ts +2 -4
- package/dist/type/elysia/utils.js +10 -21
- package/dist/type/elysia/utils.mjs +7 -15
- package/dist/type/exports.d.ts +4 -2
- package/dist/type/exports.js +23 -2
- package/dist/type/exports.mjs +11 -2
- package/dist/type/index.d.ts +10 -2
- package/dist/type/index.js +62 -15
- package/dist/type/index.mjs +65 -11
- package/dist/type/shared.d.ts +3 -9
- package/dist/type/shared.js +44 -97
- package/dist/type/shared.mjs +43 -97
- package/dist/type/sync-require.d.ts +11 -0
- package/dist/type/sync-require.js +14 -0
- package/dist/type/sync-require.mjs +12 -0
- package/dist/type/typebox-system-lite.d.ts +2 -0
- package/dist/type/typebox-system-lite.js +34 -0
- package/dist/type/typebox-system-lite.mjs +3 -0
- package/dist/type/typebox-system-require.d.ts +7 -0
- package/dist/type/typebox-system-require.js +24 -0
- package/dist/type/typebox-system-require.mjs +23 -0
- package/dist/type/typebox-type-live.d.ts +11 -0
- package/dist/type/typebox-type-live.js +45 -0
- package/dist/type/typebox-type-live.mjs +20 -0
- package/dist/type/typebox-type.d.ts +34 -0
- package/dist/type/typebox-type.js +199 -0
- package/dist/type/typebox-type.mjs +86 -0
- package/dist/type/typebox-value-live.d.ts +11 -0
- package/dist/type/typebox-value-live.js +31 -0
- package/dist/type/typebox-value-live.mjs +13 -0
- package/dist/type/typebox-value-ops.d.ts +4 -0
- package/dist/type/typebox-value-ops.js +90 -0
- package/dist/type/typebox-value-ops.mjs +5 -0
- package/dist/type/typebox-value-require.d.ts +8 -0
- package/dist/type/typebox-value-require.js +28 -0
- package/dist/type/typebox-value-require.mjs +25 -0
- package/dist/type/typebox-value.d.ts +35 -0
- package/dist/type/typebox-value.js +161 -0
- package/dist/type/typebox-value.mjs +74 -0
- package/dist/type/utils.js +1 -10
- package/dist/type/utils.mjs +1 -10
- package/dist/type/validator/clean-safe.d.ts +2 -4
- package/dist/type/validator/clean-safe.js +15 -11
- package/dist/type/validator/clean-safe.mjs +16 -10
- package/dist/type/validator/custom-error.js +12 -16
- package/dist/type/validator/custom-error.mjs +11 -14
- package/dist/type/validator/default-precompute.d.ts +9 -1
- package/dist/type/validator/default-precompute.js +40 -77
- package/dist/type/validator/default-precompute.mjs +37 -74
- package/dist/type/validator/exact-mirror-live.d.ts +8 -0
- package/dist/type/validator/exact-mirror-live.js +22 -0
- package/dist/type/validator/exact-mirror-live.mjs +17 -0
- package/dist/type/validator/exact-mirror-require.d.ts +4 -0
- package/dist/type/validator/exact-mirror-require.js +11 -0
- package/dist/type/validator/exact-mirror-require.mjs +9 -0
- package/dist/type/validator/exact-mirror.js +8 -8
- package/dist/type/validator/exact-mirror.mjs +9 -8
- package/dist/type/validator/frozen-check.js +5 -6
- package/dist/type/validator/frozen-check.mjs +6 -7
- package/dist/type/validator/index.d.ts +1 -0
- package/dist/type/validator/index.js +169 -166
- package/dist/type/validator/index.mjs +162 -158
- package/dist/type/validator/string-codec-aot.d.ts +2 -1
- package/dist/type/validator/string-codec-aot.js +8 -2
- package/dist/type/validator/string-codec-aot.mjs +7 -2
- package/dist/type/validator/validator-cache.d.ts +5 -4
- package/dist/type/validator/validator-cache.js +41 -24
- package/dist/type/validator/validator-cache.mjs +40 -22
- package/dist/types.d.ts +263 -95
- package/dist/universal/constants.d.ts +2 -1
- package/dist/universal/constants.js +3 -1
- package/dist/universal/constants.mjs +2 -1
- package/dist/universal/env.js +2 -3
- package/dist/universal/env.mjs +2 -3
- package/dist/universal/file.d.ts +6 -4
- package/dist/universal/file.js +11 -16
- package/dist/universal/file.mjs +12 -16
- package/dist/universal/index.d.ts +2 -2
- package/dist/universal/is-production.d.ts +1 -2
- package/dist/universal/is-production.js +1 -3
- package/dist/universal/is-production.mjs +2 -3
- package/dist/universal/server.d.ts +0 -272
- package/dist/utils.d.ts +43 -7
- package/dist/utils.js +181 -126
- package/dist/utils.mjs +168 -126
- package/dist/validator/index.d.ts +1 -1
- package/dist/validator/index.js +17 -30
- package/dist/validator/index.mjs +18 -31
- package/dist/validator/route.js +2 -1
- package/dist/validator/route.mjs +2 -1
- package/dist/ws/context.d.ts +8 -1
- package/dist/ws/context.js +68 -44
- package/dist/ws/context.mjs +67 -44
- package/dist/ws/parser.js +10 -20
- package/dist/ws/parser.mjs +10 -20
- package/dist/ws/route.d.ts +2 -2
- package/dist/ws/route.js +249 -141
- package/dist/ws/route.mjs +254 -146
- package/dist/ws/types.d.ts +2 -2
- package/package.json +23 -49
- package/dist/compile/analysis-cache.d.ts +0 -6
- package/dist/compile/analysis-cache.js +0 -12
- package/dist/compile/analysis-cache.mjs +0 -11
- package/dist/cookie/index.d.ts +0 -7
- package/dist/cookie/index.js +0 -13
- package/dist/cookie/index.mjs +0 -7
- package/dist/handler/index.d.ts +0 -2
- package/dist/handler/index.js +0 -5
- package/dist/handler/index.mjs +0 -3
package/dist/types.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { CookieOptions } from "./cookie/types.js";
|
|
2
|
-
import {
|
|
3
|
-
import { ElysiaFile } from "./universal/file.js";
|
|
2
|
+
import { AnySchema, StandardSchemaV1Like, TypeBoxSchema } from "./type/types.js";
|
|
4
3
|
import { StatusMap, StatusMapBack } from "./constants.js";
|
|
5
|
-
import {
|
|
4
|
+
import { ElysiaError, ElysiaStatus, ProblemResponseBody, ValidationErrorResponse } from "./error.js";
|
|
6
5
|
import { ChainNode } from "./utils.js";
|
|
7
|
-
import {
|
|
6
|
+
import { Serve } from "./universal/server.js";
|
|
8
7
|
import { Context, ErrorContext, LifecycleContext, PreContext } from "./context.js";
|
|
9
|
-
import {
|
|
8
|
+
import { TraceHandler } from "./trace.js";
|
|
9
|
+
import { ElysiaFile } from "./universal/file.js";
|
|
10
10
|
import { AnyElysia, Elysia } from "./base.js";
|
|
11
11
|
import { ElysiaAdapter } from "./adapter/index.js";
|
|
12
|
-
import { Static, StaticDecode, StaticEncode, TIntersect, TObject, TSchema } from "typebox";
|
|
12
|
+
import { Static, StaticDecode, StaticEncode, TIntersect, TObject, TRef, TSchema } from "typebox";
|
|
13
13
|
import { OpenAPIV3 } from "openapi-types";
|
|
14
14
|
|
|
15
15
|
//#region src/types.d.ts
|
|
@@ -70,7 +70,8 @@ interface ElysiaConfig<in out Prefix extends string | undefined, in out Scope ex
|
|
|
70
70
|
*
|
|
71
71
|
* Only required for root instance (instance which use listen) to effect
|
|
72
72
|
*
|
|
73
|
-
*
|
|
73
|
+
* TypeBox loads during build when needed, regardless of this setting.
|
|
74
|
+
* Enable this only to compile route handlers and validators before listen().
|
|
74
75
|
*
|
|
75
76
|
* @default false
|
|
76
77
|
*/
|
|
@@ -127,18 +128,6 @@ interface ElysiaConfig<in out Prefix extends string | undefined, in out Scope ex
|
|
|
127
128
|
* @default 'exactMirror'
|
|
128
129
|
*/
|
|
129
130
|
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)
|
|
135
|
-
*
|
|
136
|
-
* setting this to true will skip the first 11 character of the hostname
|
|
137
|
-
*
|
|
138
|
-
* @default true
|
|
139
|
-
*/
|
|
140
|
-
standardHostname?: boolean;
|
|
141
|
-
};
|
|
142
131
|
/**
|
|
143
132
|
* Enable Bun adapter native static response collection for eligible literal
|
|
144
133
|
* static routes.
|
|
@@ -192,7 +181,7 @@ type ElysiaFormData<T extends Record<keyof any, unknown>> = FormData & {
|
|
|
192
181
|
['~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;
|
|
193
182
|
};
|
|
194
183
|
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';
|
|
184
|
+
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' | 'QUERY' | 'REBIND' | 'REPORT' | 'SEARCH' | 'SOURCE' | 'SUBSCRIBE' | 'TRACE' | 'UNBIND' | 'UNLINK' | 'UNLOCK' | 'UNSUBSCRIBE' | 'ALL';
|
|
196
185
|
type UnwrapArray<T> = T extends (infer U)[] ? U : T;
|
|
197
186
|
type AppEvent = 'start' | 'stop' | 'request' | 'parse' | 'transform' | 'beforeHandle' | 'afterHandle' | 'mapResponse' | 'afterResponse' | 'error' | 'trace';
|
|
198
187
|
interface AppHook {
|
|
@@ -293,6 +282,11 @@ type GuardLocalHook<Input extends BaseMacro | undefined, Schema extends RouteSch
|
|
|
293
282
|
* @since 1.3.0
|
|
294
283
|
*/
|
|
295
284
|
schema?: GuardType;
|
|
285
|
+
/**
|
|
286
|
+
* Removed in 2.0 — pass the scope as guard's first argument instead:
|
|
287
|
+
* `.guard('plugin', { ... })` (1.x `as: 'scoped'` maps to `'plugin'`)
|
|
288
|
+
*/
|
|
289
|
+
as?: never;
|
|
296
290
|
detail?: DocumentDecoration;
|
|
297
291
|
/**
|
|
298
292
|
* Short for 'Content-Type'
|
|
@@ -393,7 +387,13 @@ interface RouteSchema {
|
|
|
393
387
|
params?: unknown;
|
|
394
388
|
cookie?: unknown;
|
|
395
389
|
response?: unknown;
|
|
390
|
+
'~input'?: {
|
|
391
|
+
body?: unknown;
|
|
392
|
+
headers?: unknown;
|
|
393
|
+
query?: unknown;
|
|
394
|
+
};
|
|
396
395
|
}
|
|
396
|
+
type RouteInput<S extends RouteSchema> = '~input' extends keyof S ? NonNullable<S['~input']> : S;
|
|
397
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
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
399
|
responseValue: {} extends Route['response'] ? unknown : Route['response'][keyof Route['response']];
|
|
@@ -429,7 +429,7 @@ interface BunHTMLBundlelike {
|
|
|
429
429
|
}[];
|
|
430
430
|
}
|
|
431
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];
|
|
432
|
+
type InlineHandlerResponse<Route extends RouteSchema['response']> = { [Status in keyof Route]: ElysiaStatus<Status, Route[Status], Status> | (Status extends keyof StatusMapBack ? ElysiaStatus<StatusMapBack[Status], Route[Status]> : never) }[keyof Route];
|
|
433
433
|
type InlineHandler<Route extends RouteSchema = {}, Singleton extends SingletonBase = DefaultSingleton, MacroContext extends {
|
|
434
434
|
response: PossibleResponse;
|
|
435
435
|
return: PossibleResponse;
|
|
@@ -441,7 +441,7 @@ type InlineHandler<Route extends RouteSchema = {}, Singleton extends SingletonBa
|
|
|
441
441
|
}> = InlineHandlerNonMacro<Route & MacroContext, Singleton & {
|
|
442
442
|
derive: MacroContext['resolve'];
|
|
443
443
|
}>;
|
|
444
|
-
type InlineHandlerNonMacro<Route extends RouteSchema = {}, Singleton extends SingletonBase = DefaultSingleton> =
|
|
444
|
+
type InlineHandlerNonMacro<Route extends RouteSchema = {}, Singleton extends SingletonBase = DefaultSingleton> = (Route['response'] extends infer ResponseSchema ? {} extends ResponseSchema ? MaybePromise<InlineResponse> : MaybePromise<ResponseSchema[keyof ResponseSchema] | InlineHandlerResponse<ResponseSchema>> : never) | ((context: Context<Route, Singleton>) => MaybePromise<Response> | MaybePromise<{} extends Route['response'] ? unknown : (Route['response'] extends {
|
|
445
445
|
200: any;
|
|
446
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
447
|
type Handler = (context: Context) => unknown;
|
|
@@ -458,7 +458,7 @@ type ErrorHandler<T extends ErrorDefinition[] = [], in out Route extends RouteSc
|
|
|
458
458
|
decorator: Singleton['decorator'];
|
|
459
459
|
derive: {};
|
|
460
460
|
}> & {
|
|
461
|
-
error: T[number]['error'] |
|
|
461
|
+
error: T[number]['error'] | unknown;
|
|
462
462
|
}) => unknown;
|
|
463
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
464
|
params: ResolvePath<Path>;
|
|
@@ -471,6 +471,7 @@ type MergeSchema<A extends RouteSchema, B extends RouteSchema, Path extends stri
|
|
|
471
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
472
|
cookie: undefined extends A['cookie'] ? B['cookie'] : A['cookie'];
|
|
473
473
|
response: {} extends A['response'] ? {} extends B['response'] ? {} : B['response'] : {} extends B['response'] ? A['response'] : A['response'] & Omit<B['response'], keyof A['response']>;
|
|
474
|
+
'~input'?: { [K in 'body' | 'headers' | 'query']: undefined extends A[K] ? RouteInput<B>[K] : RouteInput<A>[K] };
|
|
474
475
|
};
|
|
475
476
|
type AnyWSLocalHook = any;
|
|
476
477
|
type Equal<X, Y> = (<T>() => T extends X ? 1 : 2) extends (<T>() => T extends Y ? 1 : 2) ? true : false;
|
|
@@ -499,6 +500,19 @@ type MacroProperty<Macro extends BaseMacro = {}, TypedRoute extends RouteSchema
|
|
|
499
500
|
afterResponse?: MaybeArray<AfterResponseHandler<TypedRoute, Singleton>>;
|
|
500
501
|
derive?: MaybeArray<ResolveHandler<TypedRoute, Singleton>>;
|
|
501
502
|
detail?: DocumentDecoration;
|
|
503
|
+
/**
|
|
504
|
+
* Type-level route metadata surfaced on the route's Eden type
|
|
505
|
+
* (`CreateEdenResponse['meta']`). Reserved key like `seed`/`detail`/
|
|
506
|
+
* `introspect` — stripped at runtime, never lands on route hooks
|
|
507
|
+
*/
|
|
508
|
+
meta?: unknown;
|
|
509
|
+
/**
|
|
510
|
+
* Phantom {@link MacroTypeLambda} computing per call site context from
|
|
511
|
+
* the route's literal hook value. Reserved key like `seed`/`meta`/
|
|
512
|
+
* `introspect` — carry it on the declared return type only; a runtime
|
|
513
|
+
* value is tolerated and stripped
|
|
514
|
+
*/
|
|
515
|
+
$type?: MacroTypeLambda;
|
|
502
516
|
/**
|
|
503
517
|
* Introspect hook option for documentation generation or analysis
|
|
504
518
|
*
|
|
@@ -616,24 +630,75 @@ type ContextAppendType = 'append' | 'override';
|
|
|
616
630
|
type OptionalField = {
|
|
617
631
|
'~optional': true;
|
|
618
632
|
};
|
|
619
|
-
type
|
|
620
|
-
type
|
|
621
|
-
type
|
|
633
|
+
type IsOptionalRoot<Schema, Definitions, Seen extends string = never> = Schema extends OptionalField ? true : Schema extends TRef<infer Ref> ? Ref extends Seen ? false : Ref extends keyof Definitions ? IsOptionalRoot<Definitions[Ref], Definitions, Seen | Ref> : false : false;
|
|
634
|
+
type SchemaSide = 'input' | 'output';
|
|
635
|
+
type StaticCyclic<T extends TypeBoxSchema, Definitions extends Record<string, AnySchema>, Side extends SchemaSide = 'output'> = Side extends 'input' ? {} extends Definitions ? StaticEncode<T> : StaticEncode<T, Definitions> : {} extends Definitions ? StaticDecode<T> : StaticDecode<T, Definitions>;
|
|
636
|
+
type UnwrapSchema<Schema extends AnySchema | string | undefined, Definitions extends DefinitionBase['typebox'] = {}, Side extends SchemaSide = 'output'> = Schema extends undefined ? unknown : Schema extends TypeBoxSchema ? true extends IsOptionalRoot<Schema, Definitions> ? Partial<StaticCyclic<Schema, Definitions, Side>> : StaticCyclic<Schema, Definitions, Side> : Schema extends StandardSchemaV1Like ? NonNullable<Schema['~standard']['types']>[Side] : Schema extends string ? Schema extends keyof Definitions ? Definitions[Schema] extends TypeBoxSchema ? true extends IsOptionalRoot<Definitions[Schema], Definitions> ? Partial<StaticCyclic<Definitions[Schema], Definitions, Side>> : StaticCyclic<Definitions[Schema], Definitions, Side> : Definitions[Schema] extends StandardSchemaV1Like ? NonNullable<Definitions[Schema]['~standard']['types']>[Side] : unknown : unknown : unknown;
|
|
637
|
+
type UnwrapBodySchema<Schema extends AnySchema | string | undefined, Definitions extends DefinitionBase['typebox'] = {}, Side extends SchemaSide = 'output'> = undefined extends Schema ? unknown : Schema extends TypeBoxSchema ? true extends IsOptionalRoot<Schema, Definitions> ? Partial<StaticCyclic<Schema, Definitions, Side>> | null | undefined : StaticCyclic<Schema, Definitions, Side> : Schema extends StandardSchemaV1Like ? NonNullable<Schema['~standard']['types']>[Side] : Schema extends string ? Schema extends keyof Definitions ? Definitions[Schema] extends TypeBoxSchema ? true extends IsOptionalRoot<Definitions[Schema], Definitions> ? Partial<StaticCyclic<Definitions[Schema], Definitions, Side>> | null | undefined : StaticCyclic<Definitions[Schema], Definitions, Side> : Definitions[Schema] extends StandardSchemaV1Like ? NonNullable<Definitions[Schema]['~standard']['types']>[Side] : unknown : unknown : unknown;
|
|
638
|
+
type CodecFreeKind = 'Any' | 'BigInt' | 'Boolean' | 'Enum' | 'Integer' | 'Literal' | 'Never' | 'Null' | 'Number' | 'String' | 'Symbol' | 'TemplateLiteral' | 'Undefined' | 'Unknown' | 'Void';
|
|
639
|
+
interface CodecFreeBase {
|
|
640
|
+
'~codec'?: never;
|
|
641
|
+
}
|
|
642
|
+
interface CodecFreeLeaf extends CodecFreeBase {
|
|
643
|
+
'~kind': CodecFreeKind;
|
|
644
|
+
}
|
|
645
|
+
interface CodecFreeObject extends CodecFreeBase {
|
|
646
|
+
'~kind': 'Object';
|
|
647
|
+
properties: {
|
|
648
|
+
[key: PropertyKey]: CodecFreeSchema;
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
interface CodecFreeRecord extends CodecFreeBase {
|
|
652
|
+
'~kind': 'Record';
|
|
653
|
+
patternProperties: {
|
|
654
|
+
[key: PropertyKey]: CodecFreeSchema;
|
|
655
|
+
};
|
|
656
|
+
}
|
|
657
|
+
interface CodecFreeArray extends CodecFreeBase {
|
|
658
|
+
'~kind': 'Array';
|
|
659
|
+
items: CodecFreeSchema;
|
|
660
|
+
}
|
|
661
|
+
interface CodecFreeTuple extends CodecFreeBase {
|
|
662
|
+
'~kind': 'Tuple';
|
|
663
|
+
items: CodecFreeSchema[];
|
|
664
|
+
}
|
|
665
|
+
interface CodecFreeUnion extends CodecFreeBase {
|
|
666
|
+
'~kind': 'Union';
|
|
667
|
+
anyOf: CodecFreeSchema[];
|
|
668
|
+
}
|
|
669
|
+
interface CodecFreeIntersect extends CodecFreeBase {
|
|
670
|
+
'~kind': 'Intersect';
|
|
671
|
+
allOf: CodecFreeSchema[];
|
|
672
|
+
}
|
|
673
|
+
type CodecFreeSchema = CodecFreeLeaf | CodecFreeObject | CodecFreeRecord | CodecFreeArray | CodecFreeTuple | CodecFreeUnion | CodecFreeIntersect;
|
|
674
|
+
type InputSide<Schema, Definitions> = [Schema] extends [CodecFreeSchema] ? 'output' : [Schema] extends [keyof Definitions] ? [Definitions[Schema & keyof Definitions]] extends [CodecFreeSchema] ? 'output' : 'input' : 'input';
|
|
675
|
+
type UnwrapInputSchema<Schema extends AnySchema | string | undefined, Definitions extends DefinitionBase['typebox'] = {}> = {
|
|
676
|
+
output: UnwrapSchema<Schema, Definitions>;
|
|
677
|
+
input: UnwrapSchema<Schema, Definitions, 'input'>;
|
|
678
|
+
}[InputSide<Schema, Definitions>];
|
|
679
|
+
type UnwrapInputBodySchema<Schema extends AnySchema | string | undefined, Definitions extends DefinitionBase['typebox'] = {}> = {
|
|
680
|
+
output: UnwrapBodySchema<Schema, Definitions>;
|
|
681
|
+
input: UnwrapBodySchema<Schema, Definitions, 'input'>;
|
|
682
|
+
}[InputSide<Schema, Definitions>];
|
|
622
683
|
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 ElysiaFormData<any> ? ElysiaFormData<{ [K in keyof FormInnerProperties<Schema>]: Static<FormInnerProperties<Schema>[K] & TSchema> }> :
|
|
684
|
+
type UnwrapResponseSchema<Schema extends AnySchema | string | undefined, Definitions extends DefinitionBase['typebox'] = {}> = Schema extends TypeBoxSchema ? StaticEncode<Schema> extends ElysiaFormData<any> ? ElysiaFormData<{ [K in keyof FormInnerProperties<Schema>]: Static<FormInnerProperties<Schema>[K] & TSchema> }> : Schema extends OptionalField ? Partial<StaticCyclic<Schema, Definitions>> : StaticCyclic<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;
|
|
624
685
|
interface UnwrapRoute<in out Schema extends InputSchema<any>, in out Definitions extends DefinitionBase['typebox'] = {}, in out Path extends string = ''> {
|
|
625
686
|
body: UnwrapBodySchema<Schema['body'], Definitions>;
|
|
626
687
|
headers: UnwrapSchema<Schema['headers'], Definitions>;
|
|
627
688
|
query: UnwrapSchema<Schema['query'], Definitions>;
|
|
628
689
|
params: {} extends Schema['params'] ? ResolvePath<Path> : {} extends Schema ? ResolvePath<Path> : UnwrapSchema<Schema['params'], Definitions>;
|
|
629
690
|
cookie: UnwrapSchema<Schema['cookie'], Definitions>;
|
|
691
|
+
'~input': {
|
|
692
|
+
body: UnwrapInputBodySchema<Schema['body'], Definitions>;
|
|
693
|
+
headers: UnwrapInputSchema<Schema['headers'], Definitions>;
|
|
694
|
+
query: UnwrapInputSchema<Schema['query'], Definitions>;
|
|
695
|
+
};
|
|
630
696
|
response: Schema['response'] extends AnySchema | string ? {
|
|
631
697
|
200: UnwrapResponseSchema<Schema['response'], Definitions> extends infer A ? A extends File ? File | ElysiaFile : A : unknown;
|
|
632
698
|
} : 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;
|
|
633
699
|
}
|
|
634
|
-
type
|
|
700
|
+
type UnwrapModels<T extends Record<string, unknown>, Iteration extends number[] = []> = Iteration['length'] extends 8 ? T : { [K in keyof T]: T[K] extends AnySchema ? UnwrapSchema<T[K]> : T[K] extends Record<string, unknown> ? UnwrapModels<T[K], [...Iteration, 0]> : T[K] };
|
|
635
701
|
type MacroToProperty<in out T> = Prettify<{ [K in keyof T]: T[K] extends Function ? T[K] extends ((a: infer Params) => any) ? Params : boolean : boolean }>;
|
|
636
|
-
type NonResolvableMacroKey = LocalLifecycleProperty | keyof InputSchema | 'derive';
|
|
637
702
|
interface RouteSchemaWithResolvedMacro extends RouteSchema {
|
|
638
703
|
response: PossibleResponse;
|
|
639
704
|
return: PossibleResponse;
|
|
@@ -646,6 +711,11 @@ interface IntersectIfObjectSchema<A extends RouteSchema, B extends RouteSchema>
|
|
|
646
711
|
query: IntersectIfObject<A['query'], B['query']>;
|
|
647
712
|
params: IntersectIfObject<A['params'], B['params']>;
|
|
648
713
|
cookie: IntersectIfObject<A['cookie'], B['cookie']>;
|
|
714
|
+
'~input'?: {
|
|
715
|
+
body: IntersectIfObject<RouteInput<A>['body'], RouteInput<B>['body']>;
|
|
716
|
+
headers: IntersectIfObject<RouteInput<A>['headers'], RouteInput<B>['headers']>;
|
|
717
|
+
query: IntersectIfObject<RouteInput<A>['query'], RouteInput<B>['query']>;
|
|
718
|
+
};
|
|
649
719
|
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 };
|
|
650
720
|
}
|
|
651
721
|
interface MergeScopedSchemas<Global extends RouteSchema, Scoped extends RouteSchema, Local extends RouteSchema> {
|
|
@@ -654,12 +724,13 @@ interface MergeScopedSchemas<Global extends RouteSchema, Scoped extends RouteSch
|
|
|
654
724
|
query: Global['query'] & Scoped['query'] & Local['query'];
|
|
655
725
|
params: Global['params'] & Scoped['params'] & Local['params'];
|
|
656
726
|
cookie: Global['cookie'] & Scoped['cookie'] & Local['cookie'];
|
|
727
|
+
'~input'?: { [K in 'body' | 'headers' | 'query']: RouteInput<Global>[K] & RouteInput<Scoped>[K] & RouteInput<Local>[K] };
|
|
657
728
|
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 };
|
|
658
729
|
}
|
|
659
730
|
type ReturnTypeIfPossible<T, Enabled = true> = false extends Enabled ? {} : T extends ((...a: any) => infer R) ? R : T;
|
|
660
|
-
type FunctionArrayReturnType<T> = any[] extends T ? never : T extends any[] ? _FunctionArrayReturnType<T> : Awaited<ReturnType<T
|
|
731
|
+
type FunctionArrayReturnType<T> = any[] extends T ? never : T extends any[] ? _FunctionArrayReturnType<T> : Awaited<ReturnType<NonNullable<T>>>;
|
|
661
732
|
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;
|
|
662
|
-
type FunctionArrayReturnTypeNonNullable<T> = any[] extends T ? never : T extends any[] ? _FunctionArrayReturnTypeNonNullable<T> : NonNullable<Awaited<ReturnType<T
|
|
733
|
+
type FunctionArrayReturnTypeNonNullable<T> = any[] extends T ? never : T extends any[] ? _FunctionArrayReturnTypeNonNullable<T> : NonNullable<Awaited<ReturnType<NonNullable<T>>>>;
|
|
663
734
|
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;
|
|
664
735
|
type AnyElysiaStatus = ElysiaStatus<any, any, any>;
|
|
665
736
|
type ExcludeElysiaResponse<T> = Exclude<Awaited<T>, AnyElysiaStatus> extends infer A ? IsNever<A & {}> extends true ? {} : undefined extends A ? Partial<A & {}> : A & {} : {};
|
|
@@ -667,8 +738,8 @@ type ExtractResolveFromMacro<A> = IsNever<A> extends true ? {} : A extends AnyEl
|
|
|
667
738
|
type ExtractOnlyResponseFromMacro<A> = IsNever<A> extends true ? {} : Extract<A, AnyElysiaStatus> extends infer A ? IsNever<A> extends true ? {} : {
|
|
668
739
|
return: MergeResponseStatus<A>;
|
|
669
740
|
} : {};
|
|
670
|
-
type MergeResponseStatus<A> = { [status in keyof UnionToIntersect<A extends ElysiaStatus<any, any, infer Status> ? { [A in Status]: 1 } : never>]: Extract<A, {
|
|
671
|
-
|
|
741
|
+
type MergeResponseStatus<A> = { [status in keyof UnionToIntersect<A extends ElysiaStatus<any, any, infer Status> ? { [A in Status]: 1 } : never>]: Extract<A, AnyElysiaStatus & {
|
|
742
|
+
status: status;
|
|
672
743
|
}>['response'] extends infer Value ? IsAny<Value> extends true ? StatusMapBack[status] : Value : never };
|
|
673
744
|
type ExtractAllResponseFromMacro<A> = IsNever<A> extends true ? {} : {
|
|
674
745
|
return: MergeResponseStatus<A> & (Exclude<A, AnyElysiaStatus> extends infer A ? IsAny<A> extends true ? {} : IsNever<A> extends true ? {} : NonNullable<void> extends A ? {} : undefined extends A ? {} : {
|
|
@@ -676,6 +747,22 @@ type ExtractAllResponseFromMacro<A> = IsNever<A> extends true ? {} : {
|
|
|
676
747
|
} : {});
|
|
677
748
|
};
|
|
678
749
|
type FlattenMacroResponse<T> = T extends object ? '_' extends keyof T ? UnionResponseStatus<Omit<T, '_'>, FlattenMacroResponse<MergeStatusUnion<T['_']>>> : T : T;
|
|
750
|
+
/**
|
|
751
|
+
* Type-level lambda applied to a macro's per call site hook value. Extend
|
|
752
|
+
* this interface, compute `output` from `this['input']`, and carry it on
|
|
753
|
+
* the macro's declared return type as a phantom `$type` member — the
|
|
754
|
+
* computed `output` joins the route's context
|
|
755
|
+
*/
|
|
756
|
+
interface MacroTypeLambda {
|
|
757
|
+
input: unknown;
|
|
758
|
+
}
|
|
759
|
+
type MacroLambdaContext<Value, HookValue> = NonNullable<Value> extends {
|
|
760
|
+
$type?: infer Lambda extends MacroTypeLambda;
|
|
761
|
+
} ? Lambda & {
|
|
762
|
+
input: HookValue;
|
|
763
|
+
} extends {
|
|
764
|
+
output: infer Output;
|
|
765
|
+
} ? Output : {} : {};
|
|
679
766
|
type UnionMacroContext<A> = UnionToIntersect<{ [K in Exclude<keyof A, 'return'>]: A[K] }> & {
|
|
680
767
|
return: {
|
|
681
768
|
_: A['return'];
|
|
@@ -684,10 +771,10 @@ type UnionMacroContext<A> = UnionToIntersect<{ [K in Exclude<keyof A, 'return'>]
|
|
|
684
771
|
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<{
|
|
685
772
|
return: FlattenMacroResponse<A['return']>;
|
|
686
773
|
}> : {}>;
|
|
687
|
-
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 ? {
|
|
688
|
-
|
|
689
|
-
resolve: ExtractResolveFromMacro<Extract<Exclude<FunctionArrayReturnType<
|
|
690
|
-
} & UnwrapMacroSchema<
|
|
774
|
+
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 ? NonNullable<Value> extends infer Def ? {
|
|
775
|
+
meta: 'meta' extends keyof Def ? Def['meta'] : never;
|
|
776
|
+
resolve: ExtractResolveFromMacro<Extract<Exclude<FunctionArrayReturnType<Def['derive']>, AnyElysiaStatus>, Record<any, unknown>>> & MacroLambdaContext<Value, SelectedMacro[key]>;
|
|
777
|
+
} & UnwrapMacroSchema<Def, Definitions> & ExtractAllResponseFromMacro<FunctionArrayReturnTypeNonNullable<Def['beforeHandle']>> & ExtractAllResponseFromMacro<FunctionArrayReturnTypeNonNullable<Def['afterHandle']>> & ExtractAllResponseFromMacro<FunctionArrayReturnType<Def['error']>> & ExtractOnlyResponseFromMacro<FunctionArrayReturnTypeNonNullable<Def['derive']>> & InnerMacroToContext<MacroFn, Pick<Def, Extract<keyof MacroFn, keyof Def>>, Definitions, [...R, 1]> : {} : {} }[keyof SelectedMacro]>;
|
|
691
778
|
type UnwrapMacroSchema<T extends Partial<InputSchema<any>>, Definitions extends DefinitionBase['typebox'] = {}> = UnwrapRoute<{
|
|
692
779
|
body: 'body' extends keyof T ? T['body'] : undefined;
|
|
693
780
|
headers: 'headers' extends keyof T ? T['headers'] : undefined;
|
|
@@ -698,19 +785,27 @@ type UnwrapMacroSchema<T extends Partial<InputSchema<any>>, Definitions extends
|
|
|
698
785
|
}, Definitions>;
|
|
699
786
|
type MacroPropertyKey = keyof MacroProperty;
|
|
700
787
|
type AsMacroSchemaField<T> = [T] extends [never] ? undefined : [unknown] extends [T] ? undefined : T extends AnySchema | string ? T : undefined;
|
|
701
|
-
type
|
|
702
|
-
body: AsMacroSchemaField<
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
788
|
+
type RefDefSchema<D> = {
|
|
789
|
+
body: AsMacroSchemaField<D extends {
|
|
790
|
+
body: infer X;
|
|
791
|
+
} ? X : undefined>;
|
|
792
|
+
headers: AsMacroSchemaField<D extends {
|
|
793
|
+
headers: infer X;
|
|
794
|
+
} ? X : undefined>;
|
|
795
|
+
query: AsMacroSchemaField<D extends {
|
|
796
|
+
query: infer X;
|
|
797
|
+
} ? X : undefined>;
|
|
798
|
+
params: AsMacroSchemaField<D extends {
|
|
799
|
+
params: infer X;
|
|
800
|
+
} ? X : undefined>;
|
|
801
|
+
cookie: AsMacroSchemaField<D extends {
|
|
802
|
+
cookie: infer X;
|
|
803
|
+
} ? X : undefined>;
|
|
707
804
|
response: undefined;
|
|
708
805
|
};
|
|
709
|
-
type MacroSchemaChannel<Definitions extends DefinitionBase> = Record<keyof any, AnySchema | (keyof Definitions['typebox'] & string)>;
|
|
710
|
-
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>> };
|
|
711
806
|
/**
|
|
712
807
|
* Captures the verbatim `.macro()` definition record into a separate first-pass
|
|
713
|
-
* generic
|
|
808
|
+
* generic. This lets each definition's enabled
|
|
714
809
|
* sibling flags (`{ auth: true }`) be read back without reusing the contextually
|
|
715
810
|
* typed `NewMacro`, which would form the record -> handler-typing inference
|
|
716
811
|
* cycle documented on {@link ObjectMacroDefs}.
|
|
@@ -737,20 +832,25 @@ type MacroRefResolve<MacroFn, SelectedMacro, Definitions> = MacroToContext<Macro
|
|
|
737
832
|
* still flow into `N` (the verbatim definitions, stored in
|
|
738
833
|
* `Metadata['macroFn']` for the consuming route)
|
|
739
834
|
*/
|
|
740
|
-
type ObjectMacroDefs<
|
|
835
|
+
type ObjectMacroDefs<N, AmbientSchema extends RouteSchema, ScopedSchemas extends RouteSchema, Singleton extends SingletonBase, Definitions extends DefinitionBase, MacroNames extends BaseMacro, MacroFn = {}, Refs = {}> = MacroRefChannel<Refs> & { [K in keyof N]: MaybeValueOrVoidFunction<MacroProperty<MacroNames & InputSchema<keyof Definitions['typebox'] & string>, IntersectIfObjectSchema<MergeSchema<UnwrapMacroSchema<RefDefSchema<K extends keyof Refs ? Refs[K] : {}>, Definitions['typebox']>, AmbientSchema>, ScopedSchemas>, Singleton & {
|
|
741
836
|
derive: Singleton['derive'] & MacroRefResolve<MacroFn, K extends keyof Refs ? Refs[K] : {}, Definitions['typebox']>;
|
|
742
|
-
}, 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
|
|
837
|
+
}, 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 MacroFn | keyof N>]: `Unknown macro property '${P & string}'` } } & N;
|
|
743
838
|
type CreateEden<Path extends string, Property extends Record<string, unknown> = {}> = Path extends `/${infer Rest}` ? _CreateEden<Rest, Property> : Path extends '' | '/' ? Property : _CreateEden<Path, Property>;
|
|
839
|
+
type CreateRouteEden<BasePath extends string, Path extends string, Property extends Record<string, unknown>> = string extends Path ? {} : CreateEden<JoinPath<BasePath, Path>, Property>;
|
|
744
840
|
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 };
|
|
745
841
|
/**
|
|
746
842
|
* Value an annotation knob resolves to, `never` when it annotates nothing.
|
|
747
843
|
*
|
|
748
844
|
* Both knobs are canonically methods, so what they *return* is the
|
|
749
845
|
* annotation. A value or getter reads as the value itself. An `unknown`
|
|
750
|
-
* declaration
|
|
751
|
-
*
|
|
846
|
+
* declaration resolves to `unknown` — the runtime serves whatever a knob
|
|
847
|
+
* returns and can't see its declared type — and `undefined` is excluded, it
|
|
848
|
+
* falls through to the next tier rather than being served.
|
|
849
|
+
*
|
|
850
|
+
* The base declares both knobs optional, so a subclass that doesn't override
|
|
851
|
+
* them never reaches here
|
|
752
852
|
*/
|
|
753
|
-
type ResolveAnnotation<V> = (V extends ((...args: any) => infer Returned) ? Returned : V) extends infer Value ? Exclude<Awaited<Value>, undefined> extends infer Resolved ? IsNever<Resolved> extends true ? never :
|
|
853
|
+
type ResolveAnnotation<V> = (V extends ((...args: any) => infer Returned) ? Returned : V) extends infer Value ? Exclude<Awaited<Value>, undefined> extends infer Resolved ? IsNever<Resolved> extends true ? never : Resolved : never : never;
|
|
754
854
|
/** Whether a knob may resolve `undefined` and fall through to the next tier */
|
|
755
855
|
type AnnotationFallsThrough<V> = undefined extends Awaited<V extends ((...args: any) => infer Returned) ? Returned : V> ? true : false;
|
|
756
856
|
/**
|
|
@@ -774,6 +874,16 @@ type OwnedError<E> = E extends {
|
|
|
774
874
|
type ErrorProblemType<E> = OwnedError<E> extends true ? E extends {
|
|
775
875
|
type: infer T extends string;
|
|
776
876
|
} ? T : 'about:blank' : 'about:blank';
|
|
877
|
+
/**
|
|
878
|
+
* `code` extension member an error contributes a class made by
|
|
879
|
+
* `HTTPError.id`, or a built-in `ElysiaError`. `type` may be widened to a URI
|
|
880
|
+
* by `HTTPError.typeBase`, `code` never is
|
|
881
|
+
*/
|
|
882
|
+
type ErrorProblemCode<E> = E extends {
|
|
883
|
+
code: infer C extends string;
|
|
884
|
+
} ? string extends C ? {} : {
|
|
885
|
+
code: C;
|
|
886
|
+
} : {};
|
|
777
887
|
/**
|
|
778
888
|
* Problem document served for a `detail` annotation. `detail` is carried
|
|
779
889
|
* verbatim, objects included — it is never spread into the envelope
|
|
@@ -781,7 +891,7 @@ type ErrorProblemType<E> = OwnedError<E> extends true ? E extends {
|
|
|
781
891
|
type ProblemOf<E, Detail> = ProblemResponseBody<ErrorFallbackStatus<E>, {
|
|
782
892
|
type: ErrorProblemType<E>;
|
|
783
893
|
detail: Detail;
|
|
784
|
-
}
|
|
894
|
+
} & ErrorProblemCode<E>>;
|
|
785
895
|
/**
|
|
786
896
|
* Tier 3 — nothing annotated. An error that claimed a problem serves its
|
|
787
897
|
* message as `detail`, anything else keeps the legacy raw lane
|
|
@@ -826,23 +936,34 @@ type UnhandledErrorResponse<E> = [E] extends [never] ? {} : MergeStatusUnion<E e
|
|
|
826
936
|
500: E;
|
|
827
937
|
} : SelfDescribedResponse<E> : never>;
|
|
828
938
|
type CreateEdenResponse<Path extends string, Schema extends RouteSchema, MacroContext extends RouteSchema, Res extends PossibleResponse, Err extends Error = never> = RouteSchema extends MacroContext ? {
|
|
829
|
-
body: Schema['body'];
|
|
939
|
+
body: RouteInput<Schema>['body'];
|
|
830
940
|
params: IsNever<keyof Schema['params']> extends true ? ResolvePath<Path> : Schema['params'];
|
|
831
|
-
query: Schema['query'];
|
|
832
|
-
headers: Schema['headers'];
|
|
941
|
+
query: RouteInput<Schema>['query'];
|
|
942
|
+
headers: RouteInput<Schema>['headers'];
|
|
833
943
|
response: Prettify<UnionResponseStatus<Res, UnhandledErrorResponse<Err>>>;
|
|
834
944
|
error: Err;
|
|
835
945
|
} : {
|
|
836
|
-
body: Prettify<Schema['body'] & MacroContext['body']>;
|
|
946
|
+
body: Prettify<RouteInput<Schema>['body'] & RouteInput<MacroContext>['body']>;
|
|
837
947
|
params: IsNever<keyof (Schema['params'] & MacroContext['params'])> extends true ? ResolvePath<Path> : Prettify<Schema['params'] & MacroContext['params']>;
|
|
838
|
-
query: Prettify<Schema['query'] & MacroContext['query']>;
|
|
839
|
-
headers: Prettify<Schema['headers'] & MacroContext['headers']>;
|
|
948
|
+
query: Prettify<RouteInput<Schema>['query'] & RouteInput<MacroContext>['query']>;
|
|
949
|
+
headers: Prettify<RouteInput<Schema>['headers'] & RouteInput<MacroContext>['headers']>;
|
|
840
950
|
response: Prettify<UnionResponseStatus<Res, UnhandledErrorResponse<Err>>>;
|
|
841
951
|
error: Err;
|
|
842
|
-
}
|
|
952
|
+
} & (MacroContext extends {
|
|
953
|
+
meta: infer Meta;
|
|
954
|
+
} ? IsNever<Meta> extends true ? {} : unknown extends Meta ? {} : {
|
|
955
|
+
meta: Meta;
|
|
956
|
+
} : {});
|
|
843
957
|
type CreateWSEdenResponse<Path extends string, Schema extends RouteSchema, MacroContext extends RouteSchema, Res extends PossibleResponse> = Omit<CreateEdenResponse<Path, Schema, MacroContext, Res>, 'error'>;
|
|
844
958
|
type Extract200<T> = T extends AnyElysiaStatus ? Exclude<T, AnyElysiaStatus> | Extract<T, ElysiaStatus<200, any, 200>>['response'] : T;
|
|
845
|
-
|
|
959
|
+
/**
|
|
960
|
+
* A returned value types as an error only if it declares `stack`, as `Error`
|
|
961
|
+
* and zod's `ZodError` do. `{ name, message }` data is structurally an `Error`
|
|
962
|
+
* too, but the runtime serves it as a 200
|
|
963
|
+
*/
|
|
964
|
+
type ErrorOf<T> = T extends Error ? 'stack' extends keyof T ? T : never : never;
|
|
965
|
+
type NonErrorOf<T> = T extends Error ? ('stack' extends keyof T ? never : T) : T;
|
|
966
|
+
type ValueToResponseSchema<Value, Errors extends ErrorDefinition[] = []> = ExtractErrorFromHandle<NonErrorOf<Value>> & ExtractReturnedError<Value, Errors> & (Extract200<NonErrorOf<Value>> extends infer R200 ? undefined extends R200 ? {} : IsNever<R200> extends true ? {} : {
|
|
846
967
|
200: R200;
|
|
847
968
|
} : {});
|
|
848
969
|
type ValueOrFunctionToResponseSchema<T, Errors extends ErrorDefinition[] = []> = T extends ((...a: any) => MaybePromise<infer R>) ? ValueToResponseSchema<R, Errors> : ValueToResponseSchema<T, Errors>;
|
|
@@ -851,20 +972,12 @@ type ElysiaHandlerToResponseSchemas<Handle extends Function[], Carry extends Pos
|
|
|
851
972
|
type ElysiaHandlerToResponseSchemaAmbiguous<Schemas extends MaybeArray<Function>> = MaybeArray<(...a: any) => any> extends Schemas ? {} : Schemas extends Function ? ElysiaHandlerToResponseSchema<Schemas> : Schemas extends Function[] ? ElysiaHandlerToResponseSchemas<Schemas> : {};
|
|
852
973
|
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] };
|
|
853
974
|
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 };
|
|
975
|
+
type ParentResponse<M extends MetadataBase, E extends EphemeralType, V extends EphemeralType> = UnionResponseStatus<M['response'], UnionResponseStatus<E['response'], V['response']>>;
|
|
854
976
|
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;
|
|
855
977
|
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 ? {} : {
|
|
856
|
-
422:
|
|
857
|
-
type: 'validation';
|
|
858
|
-
title: 'Validation Error';
|
|
859
|
-
status: 422;
|
|
860
|
-
detail?: string;
|
|
861
|
-
on: string;
|
|
862
|
-
found?: unknown;
|
|
863
|
-
property?: string;
|
|
864
|
-
expected?: string;
|
|
865
|
-
};
|
|
978
|
+
422: ValidationErrorResponse;
|
|
866
979
|
})>>;
|
|
867
|
-
type ExtractErrorFromHandle<in out Handle> = { [ErrorResponse in Extract<Handle, AnyElysiaStatus> as ErrorResponse extends AnyElysiaStatus ? ErrorResponse['
|
|
980
|
+
type ExtractErrorFromHandle<in out Handle> = { [ErrorResponse in Extract<Handle, AnyElysiaStatus> as ErrorResponse extends AnyElysiaStatus ? ErrorResponse['status'] : never]: Prettify<ErrorResponse['response']> };
|
|
868
981
|
/**
|
|
869
982
|
* Status used when an error handler returns a plain value (or falls through):
|
|
870
983
|
* the error's declared literal `status`, otherwise 500
|
|
@@ -887,8 +1000,44 @@ type ErrorDefinitionEntry<E extends abstract new (...args: any) => Error, R> = {
|
|
|
887
1000
|
type ErrorHandlerResponseSchema<R, E> = ExtractErrorFromHandle<Exclude<R, Error>> & (Exclude<R, Extract<Exclude<R, Error>, AnyElysiaStatus> | undefined> | (undefined extends R ? ErrorFallbackBody<E> : never) extends infer Served ? ServedAtStatus<Served, ErrorFallbackStatus<E>> : {});
|
|
888
1001
|
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;
|
|
889
1002
|
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;
|
|
890
|
-
type UnhandledReturnedError<Value, Errors extends ErrorDefinition[]> = 0 extends 1 & Value ? never :
|
|
1003
|
+
type UnhandledReturnedError<Value, Errors extends ErrorDefinition[]> = 0 extends 1 & Value ? never : ErrorOf<Value> extends infer Es ? Es extends Error ? HasErrorMatch<Es, Errors> extends true ? never : Es : never : never;
|
|
891
1004
|
type UnhandledReturnedErrorOf<T, Errors extends ErrorDefinition[]> = T extends ((...a: any) => MaybePromise<infer R>) ? UnhandledReturnedError<R, Errors> : UnhandledReturnedError<T, Errors>;
|
|
1005
|
+
/**
|
|
1006
|
+
* Returned errors a `.error(Class, handler)` already consumed, each paired
|
|
1007
|
+
* with the response that handler contributed. Carried on the route under
|
|
1008
|
+
* `~handled` so a parent handler registered before `.use()`, which runs first
|
|
1009
|
+
* at runtime, can take the error over
|
|
1010
|
+
*/
|
|
1011
|
+
type HandledReturnedError<Value, Errors extends ErrorDefinition[]> = Errors extends [] ? never : 0 extends 1 & Value ? never : ErrorOf<Value> extends infer Es ? Es extends Error ? HasErrorMatch<Es, Errors> extends true ? {
|
|
1012
|
+
error: Es;
|
|
1013
|
+
response: MatchRegisteredError<Es, Errors>;
|
|
1014
|
+
} : never : never : never;
|
|
1015
|
+
type HandledReturnedErrorOf<T, Errors extends ErrorDefinition[]> = Errors extends [] ? never : T extends ((...a: any) => MaybePromise<infer R>) ? HandledReturnedError<R, Errors> : HandledReturnedError<T, Errors>;
|
|
1016
|
+
type WithHandledErrors<Route, Handle, Errors extends ErrorDefinition[]> = Errors extends [] ? Route : Route & HandledErrorKey<HandledReturnedErrorOf<Handle, Errors>>;
|
|
1017
|
+
type HandledErrorKey<Handled> = [Handled] extends [never] ? {} : {
|
|
1018
|
+
'~handled': Handled;
|
|
1019
|
+
};
|
|
1020
|
+
type RouteHandled<Route> = Route extends {
|
|
1021
|
+
'~handled': infer H;
|
|
1022
|
+
} ? H : never;
|
|
1023
|
+
/**
|
|
1024
|
+
* Strip what the handlers in `Taken` contributed from a route's response.
|
|
1025
|
+
* Same caveat as `WithoutUnhandledErrorResponse`: a value the handler itself
|
|
1026
|
+
* also returns at that status is indistinguishable and goes too
|
|
1027
|
+
*/
|
|
1028
|
+
type WithoutHandledResponse<Response, Contributed> = { [K in keyof Response as K extends keyof Contributed ? IsNever<Exclude<Response[K], Contributed[K]>> extends true ? never : K : K]: K extends keyof Contributed ? Exclude<Response[K], Contributed[K]> : Response[K] };
|
|
1029
|
+
type TakenOverError<H, Errors extends ErrorDefinition[]> = H extends {
|
|
1030
|
+
error: infer V;
|
|
1031
|
+
} ? HasErrorMatch<V, Errors> extends true ? H : never : never;
|
|
1032
|
+
type HandledResponseOf<H> = H extends {
|
|
1033
|
+
response: infer R;
|
|
1034
|
+
} ? R : never;
|
|
1035
|
+
type RehandledError<Won, Errors extends ErrorDefinition[]> = Won extends {
|
|
1036
|
+
error: infer V;
|
|
1037
|
+
} ? {
|
|
1038
|
+
error: V;
|
|
1039
|
+
response: MatchRegisteredError<V, Errors>;
|
|
1040
|
+
} : never;
|
|
892
1041
|
/**
|
|
893
1042
|
* Strip what `UnhandledErrorResponse` contributed for `Err` from a route's
|
|
894
1043
|
* response, so a now-handled error doesn't leave a stale status behind.
|
|
@@ -896,24 +1045,56 @@ type UnhandledReturnedErrorOf<T, Errors extends ErrorDefinition[]> = T extends (
|
|
|
896
1045
|
* A response that merely shares the same status survives, unless it's
|
|
897
1046
|
* indistinguishable from the error's own body
|
|
898
1047
|
*/
|
|
899
|
-
type WithoutUnhandledErrorResponse<Response, Err> =
|
|
1048
|
+
type WithoutUnhandledErrorResponse<Response, Err> = WithoutHandledResponse<Response, UnhandledErrorResponse<Err>>;
|
|
1049
|
+
type ResolveRouteLeafErrors<Route extends {
|
|
1050
|
+
response: any;
|
|
1051
|
+
error: any;
|
|
1052
|
+
}, Errors extends ErrorDefinition[]> = [Route['error']] extends [never] ? Route : Omit<Route, 'response' | 'error' | '~handled'> & {
|
|
1053
|
+
response: Prettify<UnionResponseStatus<WithoutUnhandledErrorResponse<Route['response'], Route['error']>, UnionResponseStatus<ExtractReturnedError<Route['error'], Errors>, UnhandledErrorResponse<UnhandledReturnedError<Route['error'], Errors>>>>>;
|
|
1054
|
+
error: UnhandledReturnedError<Route['error'], Errors>;
|
|
1055
|
+
} & HandledErrorKey<RouteHandled<Route> | HandledReturnedError<Route['error'], Errors>>;
|
|
900
1056
|
type ResolveRouteErrors<Routes, Errors extends ErrorDefinition[]> = Errors extends [] ? Routes : { [K in keyof Routes]: Routes[K] extends {
|
|
901
1057
|
params: any;
|
|
902
1058
|
query: any;
|
|
903
1059
|
headers: any;
|
|
904
1060
|
response: any;
|
|
905
1061
|
error: any;
|
|
906
|
-
} ?
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
1062
|
+
} ? ResolveRouteLeafErrors<Routes[K], Errors> : Routes[K] extends Record<keyof any, any> ? ResolveRouteErrors<Routes[K], Errors> : Routes[K] };
|
|
1063
|
+
/**
|
|
1064
|
+
* Take a parent's handlers registered before `.use()` in front of the
|
|
1065
|
+
* plugin's own: at runtime they run first, so an error the plugin already
|
|
1066
|
+
* handled goes to the parent's matching handler instead
|
|
1067
|
+
*/
|
|
1068
|
+
type PrependRouteLeafErrors<Route extends {
|
|
1069
|
+
response: any;
|
|
1070
|
+
error: any;
|
|
1071
|
+
}, Errors extends ErrorDefinition[]> = TakenOverError<RouteHandled<Route>, Errors> extends infer Won ? [Won] extends [never] ? ResolveRouteLeafErrors<Route, Errors> : ResolveRouteLeafErrors<Omit<Route, 'response' | '~handled'> & {
|
|
1072
|
+
response: Prettify<UnionResponseStatus<WithoutHandledResponse<Route['response'], MergeStatusUnion<HandledResponseOf<Won>>>, UnionResponseStatus<MergeStatusUnion<HandledResponseOf<Exclude<RouteHandled<Route>, Won>>>, MergeStatusUnion<HandledResponseOf<RehandledError<Won, Errors>>>>>>;
|
|
1073
|
+
'~handled': Exclude<RouteHandled<Route>, Won> | RehandledError<Won, Errors>;
|
|
1074
|
+
}, Errors> : never;
|
|
1075
|
+
/**
|
|
1076
|
+
* A parent's hooks registered before `.use()` run on the plugin's routes too,
|
|
1077
|
+
* so what they can respond with joins each route's response, the same as on
|
|
1078
|
+
* a route the parent declares itself
|
|
1079
|
+
*/
|
|
1080
|
+
type WithParentResponse<Route, Response> = {} extends Response ? Route : { [K in keyof Route]: K extends 'response' ? UnionParentResponse<Route[K], Response> : Route[K] };
|
|
1081
|
+
type UnionParentResponse<Own, Response> = { [S in keyof Own | keyof Response]: Own[S & keyof Own] | Response[S & keyof Response] };
|
|
1082
|
+
type ResolveUsedRouteErrors<Routes, Errors extends ErrorDefinition[], Response = {}> = Errors extends [] ? {} extends Response ? Routes : UsedRoutes<Routes, Errors, Response> : UsedRoutes<Routes, Errors, Response>;
|
|
1083
|
+
type UsedRoutes<Routes, Errors extends ErrorDefinition[], Response> = string extends keyof Routes ? Routes : PrependUsedRoutes<Routes, Errors, Response>;
|
|
1084
|
+
/**
|
|
1085
|
+
* Found by its keys alone: matching a route structurally would resolve its
|
|
1086
|
+
* `params`, `query`, `headers` and `error` too, which reading its `response`
|
|
1087
|
+
* never does
|
|
1088
|
+
*/
|
|
1089
|
+
type RouteKey = 'params' | 'query' | 'headers' | 'response';
|
|
1090
|
+
type PrependUsedRoutes<Routes, Errors extends ErrorDefinition[], Response> = { [K in keyof Routes]: RouteKey extends keyof Routes[K] ? WithParentResponse<Errors extends [] ? Routes[K] : 'error' extends keyof Routes[K] ? PrependRouteLeafErrors<Routes[K], Errors> : Routes[K], Response> : PrependUsedRoutes<Routes[K], Errors, Response> };
|
|
910
1091
|
type MergeStatusUnion<U> = { [K in U extends unknown ? keyof U : never]: U extends unknown ? K extends keyof U ? U[K] : never : never };
|
|
911
1092
|
/**
|
|
912
1093
|
* Map `Error` instances in a handler's return type to the response of their
|
|
913
1094
|
* matching `.error(Class, handler)`. Returned errors are forwarded to the
|
|
914
1095
|
* error pipeline at runtime, so they never appear in the 200 response
|
|
915
1096
|
*/
|
|
916
|
-
type ExtractReturnedError<Value, Errors extends ErrorDefinition[]> = 0 extends 1 & Value ? {} :
|
|
1097
|
+
type ExtractReturnedError<Value, Errors extends ErrorDefinition[]> = 0 extends 1 & Value ? {} : ErrorOf<Value> extends infer Es ? IsNever<Es> extends true ? {} : MergeStatusUnion<Es extends Error ? MatchRegisteredError<Es, Errors> : never> : {};
|
|
917
1098
|
type MergeElysiaInstances<Instances extends AnyElysia[] = [], Prefix extends string = '', Scope extends EventScope = 'local', Singleton extends SingletonBase = DefaultSingleton, Definitions extends DefinitionBase = {
|
|
918
1099
|
typebox: {};
|
|
919
1100
|
error: [];
|
|
@@ -926,13 +1107,13 @@ type MergeElysiaInstances<Instances extends AnyElysia[] = [], Prefix extends str
|
|
|
926
1107
|
schemas: Volatile['schemas'] & Current['~Ephemeral']['schemas'];
|
|
927
1108
|
response: Volatile['response'] & Current['~Ephemeral']['response'];
|
|
928
1109
|
error: [...Volatile['error'], ...Current['~Ephemeral']['error']];
|
|
929
|
-
}, ResolveRouteErrors<Routes, [...Current['~Definitions']['error'], ...Current['~Ephemeral']['error']]> & (Prefix extends `` ?
|
|
1110
|
+
}, ResolveRouteErrors<Routes, [...Current['~Definitions']['error'], ...Current['~Ephemeral']['error']]> & (Prefix extends `` ? ResolveUsedRouteErrors<Current['~Routes'], [...Definitions['error'], ...Ephemeral['error'], ...Volatile['error']], ParentResponse<Metadata, Ephemeral, Volatile>> : CreateEden<Prefix, ResolveUsedRouteErrors<Current['~Routes'], [...Definitions['error'], ...Ephemeral['error'], ...Volatile['error']], ParentResponse<Metadata, Ephemeral, Volatile>>>)> : Elysia<Prefix, Scope, {
|
|
930
1111
|
decorator: Singleton['decorator'];
|
|
931
1112
|
store: Prettify<Singleton['store']>;
|
|
932
1113
|
derive: Singleton['derive'];
|
|
933
1114
|
}, Definitions, Metadata, Routes, Ephemeral, Volatile>;
|
|
934
1115
|
type WrapFn<Callback extends (...params: any) => MaybePromise<Response> = (request: Request, ...rest: any[]) => MaybePromise<Response>> = (fetch: (request: Request, ...rest: any[]) => MaybePromise<Response>) => Callback;
|
|
935
|
-
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 &
|
|
1116
|
+
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 & CreateRouteEden<BasePath, Path, { [method in Method]: WithHandledErrors<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']]>>, Handle, [...Definitions['error'], ...Ephemeral['error'], ...Volatile['error']]> }>, Ephemeral, Volatile>;
|
|
936
1117
|
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'];
|
|
937
1118
|
type HookContextSingleton<Singleton extends SingletonBase, Ephemeral extends EphemeralType, Volatile extends EphemeralType> = Singleton & {
|
|
938
1119
|
derive: Ephemeral['derive'] & Volatile['derive'];
|
|
@@ -1033,7 +1214,7 @@ type ScopedMapDeriveReturn<HookScope extends EventScope, BasePath extends string
|
|
|
1033
1214
|
response: UnionResponseStatus<Volatile['response'], ResponseAddition>;
|
|
1034
1215
|
error: Volatile['error'];
|
|
1035
1216
|
}>;
|
|
1036
|
-
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 &
|
|
1217
|
+
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 & CreateRouteEden<BasePath, Path, {
|
|
1037
1218
|
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>>;
|
|
1038
1219
|
}>, Ephemeral, Volatile>;
|
|
1039
1220
|
type GuardHookSingleton<Singleton extends SingletonBase, Ephemeral extends EphemeralType, Volatile extends EphemeralType, MacroContext> = Singleton & {
|
|
@@ -1043,18 +1224,5 @@ interface StaticMapAliases {
|
|
|
1043
1224
|
method: string;
|
|
1044
1225
|
paths: string[];
|
|
1045
1226
|
}
|
|
1046
|
-
type LazyComposeEntry = {
|
|
1047
|
-
kind: 'route';
|
|
1048
|
-
route: InternalRoute;
|
|
1049
|
-
source?: string;
|
|
1050
|
-
} | {
|
|
1051
|
-
kind: 'use';
|
|
1052
|
-
child: AnyElysia;
|
|
1053
|
-
preChain: ChainNode | undefined;
|
|
1054
|
-
childBaseLen: number;
|
|
1055
|
-
childPlan: LazyComposeEntry[] | undefined;
|
|
1056
|
-
childPlanLen: number;
|
|
1057
|
-
source?: string;
|
|
1058
|
-
};
|
|
1059
1227
|
//#endregion
|
|
1060
|
-
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,
|
|
1228
|
+
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, HandledErrorKey, HandledReturnedErrorOf, Handler, HistoryEntry, HookContextSchema, HookContextSingleton, InlineHandler, InlineHandlerNonMacro, InlineHandlerResponse, InlineResponse, InputSchema, InputSchemaKey, InternalRoute, IntersectIfObject, IntersectIfObjectSchema, IsAny, IsNever, IsTuple, JoinPath, LocalHook, LocalHookReturn, Macro, MacroProperty, MacroPropertyKey, MacroToContext, MacroToProperty, MacroTypeLambda, MapResponse, MaybeArray, MaybePromise, MaybeValueOrVoidFunction, MergeElysiaInstances, MergeSchema, MergeScopedSchemas, MetadataBase, ObjectMacroDefs, OptionalHandler, ParentResponse, PluginHookReturn, PossibleResponse, PreHandler, Prettify, PublicRoute, Replace, ResolveHandler, ResolvePath, ResolveRouteErrors, ResolveUsedRouteErrors, RouteBase, RouteInput, RouteSchema, SSEPayload, ScopedHookReturn, ScopedMapDeriveReturn, SingletonBase, type StandardSchemaV1Like, StaticMapAliases, TransformHandler, type TypeBoxSchema, UnhandledReturnedError, UnhandledReturnedErrorOf, UnionResponseStatus, UnionToIntersect, UnwrapArray, UnwrapBodySchema, UnwrapMacroSchema, UnwrapModels, UnwrapRoute, UnwrapSchema, ValueOrFunctionToResponseSchema, ValueToResponseSchema, VoidHandler, WithHandledErrors, WrapFn };
|