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/error.d.ts
CHANGED
|
@@ -6,13 +6,32 @@ import { MaybePromise } from "./types.js";
|
|
|
6
6
|
declare class ElysiaError<Status extends number = number, Response extends string = string> extends Error {
|
|
7
7
|
status?: Status;
|
|
8
8
|
response?: Response;
|
|
9
|
-
/**
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Stable machine-readable token served in the `code` member, the same
|
|
11
|
+
* contract a {@link HTTPError.id} class speaks (set per subclass)
|
|
12
|
+
*/
|
|
13
|
+
readonly code?: string;
|
|
14
|
+
/**
|
|
15
|
+
* RFC 9457 problem type served in the `type` member. Mirrors `code`, or
|
|
16
|
+
* resolves to `<typeBase>/<code>` once {@link HTTPError.typeBase} is set.
|
|
17
|
+
* Defined on the prototype below
|
|
18
|
+
*/
|
|
19
|
+
type?: string;
|
|
13
20
|
constructor(message: string, cause?: Error);
|
|
14
21
|
toResponse(headers?: Record<string, any>): globalThis.Response;
|
|
15
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* `type` an error slug resolves to: the slug verbatim, or `<typeBase>/<slug>`
|
|
25
|
+
* once {@link HTTPError.typeBase} is set. Shared by `ElysiaError` and every
|
|
26
|
+
* class {@link HTTPError.id} makes, so both lanes derive `type` identically
|
|
27
|
+
*/
|
|
28
|
+
declare function problemTypeOf(code: string | undefined): string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Problem members an `ElysiaError` serves. `title` is left to `problemBody`,
|
|
31
|
+
* which derives it from the status — so `response` is only worth serving as
|
|
32
|
+
* `detail` when it says something the title doesn't
|
|
33
|
+
*/
|
|
34
|
+
declare function elysiaErrorProblem(error: ElysiaError): Problem;
|
|
16
35
|
/**
|
|
17
36
|
* Wrap a string into a TypeBox `error` callback that overrides the default
|
|
18
37
|
* validation message. Use as `t.Number({ error: validationDetail('x must be a number') })`.
|
|
@@ -21,31 +40,31 @@ declare const validationDetail: <T>(message: T) => (error: any) => any;
|
|
|
21
40
|
declare class InternalServerError extends ElysiaError {
|
|
22
41
|
response: string;
|
|
23
42
|
status: 500;
|
|
24
|
-
|
|
25
|
-
problemTitle: string;
|
|
43
|
+
readonly code = "internal-server-error";
|
|
26
44
|
constructor(response?: string, cause?: Error);
|
|
27
45
|
}
|
|
28
46
|
declare class NotFound extends ElysiaError {
|
|
29
47
|
response: string;
|
|
30
48
|
status: 404;
|
|
31
|
-
|
|
32
|
-
problemTitle: string;
|
|
49
|
+
readonly code = "not-found";
|
|
33
50
|
constructor(response?: string);
|
|
34
51
|
}
|
|
35
52
|
declare class ParseError extends ElysiaError {
|
|
36
53
|
status: 400;
|
|
37
54
|
response: string;
|
|
38
|
-
|
|
39
|
-
problemTitle: string;
|
|
55
|
+
readonly code = "parse";
|
|
40
56
|
constructor(cause?: Error);
|
|
41
57
|
toResponse(headers?: Record<string, any>): Response;
|
|
42
58
|
}
|
|
59
|
+
declare const MAX_ERRORS = 64;
|
|
43
60
|
declare function subValueAt(value: unknown, path: unknown): any;
|
|
44
61
|
declare class ValidationError extends ElysiaError {
|
|
45
62
|
#private;
|
|
46
63
|
type: string | undefined;
|
|
47
64
|
value: unknown;
|
|
48
|
-
|
|
65
|
+
/** Response validation is a server error; other validation is a client error. */
|
|
66
|
+
status: 422 | 500;
|
|
67
|
+
readonly code = "validation";
|
|
49
68
|
schema?: unknown;
|
|
50
69
|
message: string;
|
|
51
70
|
allowUnsafeValidationDetails: boolean;
|
|
@@ -57,7 +76,7 @@ declare class ValidationError extends ElysiaError {
|
|
|
57
76
|
'~resolve'(): {
|
|
58
77
|
errors: any[];
|
|
59
78
|
custom: unknown;
|
|
60
|
-
message:
|
|
79
|
+
message: any;
|
|
61
80
|
};
|
|
62
81
|
errors: any[];
|
|
63
82
|
get customError(): unknown;
|
|
@@ -67,116 +86,56 @@ declare class ValidationError extends ElysiaError {
|
|
|
67
86
|
type: string;
|
|
68
87
|
on: string | undefined;
|
|
69
88
|
message: unknown;
|
|
70
|
-
errors
|
|
89
|
+
errors: any[];
|
|
71
90
|
} | {
|
|
72
91
|
type: string;
|
|
73
92
|
on: string | undefined;
|
|
74
93
|
message: unknown;
|
|
75
|
-
errors
|
|
94
|
+
errors?: undefined;
|
|
76
95
|
};
|
|
77
96
|
get payload(): {
|
|
78
|
-
type: string;
|
|
97
|
+
type: string | undefined;
|
|
98
|
+
code: string;
|
|
79
99
|
title: string;
|
|
80
100
|
status: number;
|
|
81
|
-
on?: undefined;
|
|
82
|
-
property?: undefined;
|
|
83
|
-
detail?: undefined;
|
|
84
|
-
found?: undefined;
|
|
85
|
-
expected?: undefined;
|
|
86
|
-
errors?: undefined;
|
|
87
101
|
} | {
|
|
88
102
|
type: string;
|
|
103
|
+
code: string;
|
|
89
104
|
title: string;
|
|
90
105
|
status: number;
|
|
91
106
|
on: string | undefined;
|
|
92
107
|
property: string;
|
|
93
|
-
detail?: undefined;
|
|
94
|
-
found?: undefined;
|
|
95
|
-
expected?: undefined;
|
|
96
|
-
errors?: undefined;
|
|
97
108
|
} | {
|
|
98
|
-
type: string;
|
|
99
|
-
title: string;
|
|
100
|
-
status: number;
|
|
101
109
|
detail: any;
|
|
102
110
|
on: string | undefined;
|
|
103
111
|
property: string;
|
|
104
|
-
found:
|
|
112
|
+
found: unknown;
|
|
105
113
|
expected: unknown;
|
|
106
114
|
errors: any[];
|
|
115
|
+
type: string | undefined;
|
|
116
|
+
code: string;
|
|
117
|
+
title: string;
|
|
118
|
+
status: number;
|
|
107
119
|
};
|
|
108
120
|
toResponse(headers?: Record<string, any>): Response;
|
|
109
121
|
}
|
|
110
|
-
|
|
111
|
-
|
|
122
|
+
/** Default body for a status with no response. Named to keep emitted types small. */
|
|
123
|
+
type StatusResponse<Code extends number | keyof StatusMap> = Code extends keyof StatusMapBack ? StatusMapBack[Code] : Code;
|
|
124
|
+
declare class ElysiaStatus<const in out Code extends number | keyof StatusMap, T = StatusResponse<Code>, const in out Status extends NumericStatus<Code> = NumericStatus<Code>> {
|
|
125
|
+
/**
|
|
126
|
+
* Type-only brand, erased at runtime.
|
|
127
|
+
*
|
|
128
|
+
* `status` + `response` is a shape a handler may write by hand, so without
|
|
129
|
+
* a nominal marker a plain `{ status, response }` literal would be
|
|
130
|
+
* absorbed as a status box by response inference
|
|
131
|
+
*/
|
|
132
|
+
readonly ['~status']: true;
|
|
133
|
+
status: Status;
|
|
112
134
|
response: T;
|
|
113
135
|
headers?: Record<string, string>;
|
|
114
136
|
constructor(code: Code, res: T, headers?: Record<string, string>);
|
|
115
|
-
get status(): number;
|
|
116
137
|
}
|
|
117
|
-
declare const status: <const Code extends number | keyof StatusMap, const T =
|
|
118
|
-
readonly Continue: 100;
|
|
119
|
-
readonly 'Switching Protocols': 101;
|
|
120
|
-
readonly Processing: 102;
|
|
121
|
-
readonly 'Early Hints': 103;
|
|
122
|
-
readonly OK: 200;
|
|
123
|
-
readonly Created: 201;
|
|
124
|
-
readonly Accepted: 202;
|
|
125
|
-
readonly 'Non-Authoritative Information': 203;
|
|
126
|
-
readonly 'No Content': 204;
|
|
127
|
-
readonly 'Reset Content': 205;
|
|
128
|
-
readonly 'Partial Content': 206;
|
|
129
|
-
readonly 'Multi-Status': 207;
|
|
130
|
-
readonly 'Already Reported': 208;
|
|
131
|
-
readonly 'Multiple Choices': 300;
|
|
132
|
-
readonly 'Moved Permanently': 301;
|
|
133
|
-
readonly Found: 302;
|
|
134
|
-
readonly 'See Other': 303;
|
|
135
|
-
readonly 'Not Modified': 304;
|
|
136
|
-
readonly 'Temporary Redirect': 307;
|
|
137
|
-
readonly 'Permanent Redirect': 308;
|
|
138
|
-
readonly 'Bad Request': 400;
|
|
139
|
-
readonly Unauthorized: 401;
|
|
140
|
-
readonly 'Payment Required': 402;
|
|
141
|
-
readonly Forbidden: 403;
|
|
142
|
-
readonly 'Not Found': 404;
|
|
143
|
-
readonly 'Method Not Allowed': 405;
|
|
144
|
-
readonly 'Not Acceptable': 406;
|
|
145
|
-
readonly 'Proxy Authentication Required': 407;
|
|
146
|
-
readonly 'Request Timeout': 408;
|
|
147
|
-
readonly Conflict: 409;
|
|
148
|
-
readonly Gone: 410;
|
|
149
|
-
readonly 'Length Required': 411;
|
|
150
|
-
readonly 'Precondition Failed': 412;
|
|
151
|
-
readonly 'Payload Too Large': 413;
|
|
152
|
-
readonly 'URI Too Long': 414;
|
|
153
|
-
readonly 'Unsupported Media Type': 415;
|
|
154
|
-
readonly 'Range Not Satisfiable': 416;
|
|
155
|
-
readonly 'Expectation Failed': 417;
|
|
156
|
-
readonly "I'm a teapot": 418;
|
|
157
|
-
readonly 'Enhance Your Calm': 420;
|
|
158
|
-
readonly 'Misdirected Request': 421;
|
|
159
|
-
readonly 'Unprocessable Content': 422;
|
|
160
|
-
readonly Locked: 423;
|
|
161
|
-
readonly 'Failed Dependency': 424;
|
|
162
|
-
readonly 'Too Early': 425;
|
|
163
|
-
readonly 'Upgrade Required': 426;
|
|
164
|
-
readonly 'Precondition Required': 428;
|
|
165
|
-
readonly 'Too Many Requests': 429;
|
|
166
|
-
readonly 'Request Header Fields Too Large': 431;
|
|
167
|
-
readonly 'Unavailable For Legal Reasons': 451;
|
|
168
|
-
readonly 'Internal Server Error': 500;
|
|
169
|
-
readonly 'Not Implemented': 501;
|
|
170
|
-
readonly 'Bad Gateway': 502;
|
|
171
|
-
readonly 'Service Unavailable': 503;
|
|
172
|
-
readonly 'Gateway Timeout': 504;
|
|
173
|
-
readonly 'HTTP Version Not Supported': 505;
|
|
174
|
-
readonly 'Variant Also Negotiates': 506;
|
|
175
|
-
readonly 'Insufficient Storage': 507;
|
|
176
|
-
readonly 'Loop Detected': 508;
|
|
177
|
-
readonly 'Not Extended': 510;
|
|
178
|
-
readonly 'Network Authentication Required': 511;
|
|
179
|
-
}[Code] : Code>;
|
|
138
|
+
declare const status: <const Code extends number | keyof StatusMap, const T = StatusResponse<Code>>(code: Code, response?: T) => ElysiaStatus<Code, T, NumericStatus<Code>>;
|
|
180
139
|
declare const PROBLEM_JSON = "application/problem+json";
|
|
181
140
|
/**
|
|
182
141
|
* RFC 9457 Problem Details shape.
|
|
@@ -184,16 +143,36 @@ declare const PROBLEM_JSON = "application/problem+json";
|
|
|
184
143
|
* @see https://www.rfc-editor.org/info/rfc9457/
|
|
185
144
|
*/
|
|
186
145
|
type Problem<Code extends number | keyof StatusMap = number | keyof StatusMap, Extension extends Record<string, unknown> = {}> = {
|
|
187
|
-
/** URI (or slug) identifying the problem type. @default 'about:blank' */type?: string;
|
|
146
|
+
/** URI (or slug) identifying the problem type. @default 'about:blank' */type?: string;
|
|
147
|
+
/**
|
|
148
|
+
* Extension member carrying a stable machine-readable token.
|
|
149
|
+
*
|
|
150
|
+
* `type` may be widened to a URI by {@link HTTPError.typeBase}, `code`
|
|
151
|
+
* never is
|
|
152
|
+
*/
|
|
153
|
+
code?: string; /** Short, human-readable summary of the problem type */
|
|
188
154
|
title?: string; /** HTTP status. A number or a `StatusMap` name (e.g. `'Conflict'`) */
|
|
189
155
|
status?: Code; /** Human-readable explanation specific to this occurrence */
|
|
190
156
|
detail?: string; /** URI identifying the specific occurrence of the problem */
|
|
191
157
|
instance?: string;
|
|
192
158
|
} & Extension;
|
|
159
|
+
/** Numeric form of a status name or code. */
|
|
193
160
|
type NumericStatus<Code extends number | keyof StatusMap> = Code extends keyof StatusMap ? StatusMap[Code] : Code;
|
|
194
161
|
type ProblemStatus<P> = P extends {
|
|
195
162
|
status: infer S extends number | keyof StatusMap;
|
|
196
163
|
} ? NumericStatus<S> : 500;
|
|
164
|
+
/** Request validation problem. Diagnostic fields are development-only. */
|
|
165
|
+
type ValidationErrorResponse = {
|
|
166
|
+
type: 'validation';
|
|
167
|
+
code: 'validation';
|
|
168
|
+
title: 'Validation Error';
|
|
169
|
+
status: 422;
|
|
170
|
+
detail?: string;
|
|
171
|
+
on: string;
|
|
172
|
+
found?: unknown;
|
|
173
|
+
property?: string;
|
|
174
|
+
expected?: string;
|
|
175
|
+
};
|
|
197
176
|
type ProblemResponseBody<Status extends number, P> = Omit<{
|
|
198
177
|
type: string;
|
|
199
178
|
title: string;
|
|
@@ -235,12 +214,16 @@ declare function problem<const Code extends number | keyof StatusMap, const P ex
|
|
|
235
214
|
declare function problem<const P extends Problem>(detail: P): ElysiaStatus<ProblemStatus<P>, ProblemResponseBody<ProblemStatus<P>, P>>;
|
|
236
215
|
type CheckExcessProps<T, U> = 0 extends 1 & T ? T : U extends U ? Exclude<keyof T, keyof U> extends never ? T : { [K in keyof U]: U[K] } & { [K in Exclude<keyof T, keyof U>]: never } : never;
|
|
237
216
|
type SelectiveStatus<in out Res> = <const Code extends keyof Res | StatusMapBack[Extract<keyof StatusMapBack, keyof Res>], T extends (Code extends keyof Res ? Res[Code] : Code extends keyof StatusMap ? Res[StatusMap[Code]] : never)>(code: Code, response: CheckExcessProps<T, Code extends keyof Res ? Res[Code] : Code extends keyof StatusMap ? Res[StatusMap[Code]] : never>) => ElysiaStatus<Code, T>;
|
|
217
|
+
type ProblemInput<T> = T extends object ? Omit<T, 'type' | 'title' | 'status'> & { [K in keyof T as K extends 'type' | 'title' ? K : never]?: T[K] } : never;
|
|
218
|
+
type ResponseOf<Res, Code> = Code extends keyof Res ? Res[Code] : Code extends keyof StatusMap ? Res[StatusMap[Code]] : never;
|
|
219
|
+
type SelectiveProblem<in out Res> = <const Code extends keyof Res | StatusMapBack[Extract<keyof StatusMapBack, keyof Res>], T extends ProblemInput<ResponseOf<Res, Code>> = ProblemInput<ResponseOf<Res, Code>>>(code: Code, ...detail: {} extends ProblemInput<ResponseOf<Res, Code>> ? [detail?: CheckExcessProps<T, ProblemInput<ResponseOf<Res, Code>>>] : [detail: CheckExcessProps<T, ProblemInput<ResponseOf<Res, Code>>>]) => ElysiaStatus<NumericStatus<Code>, ResponseOf<Res, Code>>;
|
|
238
220
|
/**
|
|
239
221
|
* Class returned by {@link HTTPError.id}
|
|
240
222
|
*/
|
|
241
223
|
type TaggedHTTPError<Type extends string, Annotation = {}> = {
|
|
242
224
|
new (message?: string, options?: ErrorOptions): HTTPError<Type> & {
|
|
243
225
|
type: Type;
|
|
226
|
+
readonly code: Type;
|
|
244
227
|
} & Annotation;
|
|
245
228
|
prototype: HTTPError<Type>;
|
|
246
229
|
};
|
|
@@ -305,8 +288,34 @@ declare abstract class HTTPError<const in out T extends string = string> extends
|
|
|
305
288
|
/**
|
|
306
289
|
* RFC 9457 problem type served in the `type` member, a URI or a slug.
|
|
307
290
|
* Doubles as the tag that discriminates one error class from another
|
|
291
|
+
*
|
|
292
|
+
* On a {@link HTTPError.id} class this mirrors `code`, or resolves to
|
|
293
|
+
* `<typeBase>/<code>` once {@link HTTPError.typeBase} is set
|
|
308
294
|
*/
|
|
309
295
|
abstract type: T;
|
|
296
|
+
/**
|
|
297
|
+
* Stable machine-readable token served in the `code` member, set by
|
|
298
|
+
* {@link HTTPError.id} to its first argument
|
|
299
|
+
*
|
|
300
|
+
* Unlike `type` it is never widened to a URI, so it stays the value to
|
|
301
|
+
* dispatch on
|
|
302
|
+
*/
|
|
303
|
+
readonly code?: string;
|
|
304
|
+
/**
|
|
305
|
+
* Absolute base for the RFC 9457 `type` URI, applied to every class made
|
|
306
|
+
* by {@link HTTPError.id} and to every built-in `ElysiaError`
|
|
307
|
+
* (`NotFound`, `ParseError`, …) both derive `type` from the same slug
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```ts
|
|
311
|
+
* HTTPError.typeBase = 'https://example.com/errors'
|
|
312
|
+
*
|
|
313
|
+
* class OutOfCredit extends HTTPError.id('OUT_OF_CREDIT', 402) {}
|
|
314
|
+
* // → { type: 'https://example.com/errors/OUT_OF_CREDIT',
|
|
315
|
+
* // code: 'OUT_OF_CREDIT', … }
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
static typeBase?: string;
|
|
310
319
|
/**
|
|
311
320
|
* HTTP status served when the error reaches the error pipeline,
|
|
312
321
|
* as a number or a status name (`'Payment Required'`)
|
|
@@ -328,9 +337,10 @@ declare abstract class HTTPError<const in out T extends string = string> extends
|
|
|
328
337
|
*/
|
|
329
338
|
detail?(): MaybePromise<unknown>;
|
|
330
339
|
/**
|
|
331
|
-
* Create a concrete `HTTPError` subclass carrying `
|
|
340
|
+
* Create a concrete `HTTPError` subclass carrying `code`, mirrored into
|
|
341
|
+
* `type` unless {@link HTTPError.typeBase} is set
|
|
332
342
|
*
|
|
333
|
-
* `
|
|
343
|
+
* `code` carries no status annotation, annotate `status` in the subclass
|
|
334
344
|
* body as a number or a status name
|
|
335
345
|
*
|
|
336
346
|
* @example
|
|
@@ -342,9 +352,9 @@ declare abstract class HTTPError<const in out T extends string = string> extends
|
|
|
342
352
|
* }
|
|
343
353
|
* ```
|
|
344
354
|
*/
|
|
345
|
-
static id<const Type extends string>(
|
|
355
|
+
static id<const Type extends string>(code: Type): TaggedHTTPError<Type>;
|
|
346
356
|
/**
|
|
347
|
-
* Create a concrete `HTTPError` subclass carrying `
|
|
357
|
+
* Create a concrete `HTTPError` subclass carrying `code`, annotated with
|
|
348
358
|
* `status` as a number or a status name
|
|
349
359
|
*
|
|
350
360
|
* Annotate what is served with `detail()` (problem `detail` member) or
|
|
@@ -353,16 +363,16 @@ declare abstract class HTTPError<const in out T extends string = string> extends
|
|
|
353
363
|
* @example
|
|
354
364
|
* ```ts
|
|
355
365
|
* class OutOfCredit extends HTTPError.id('OUT_OF_CREDIT', 402) {}
|
|
356
|
-
* class Denied extends HTTPError.id('
|
|
366
|
+
* class Denied extends HTTPError.id('DENIED', 'Payment Required') {
|
|
357
367
|
* async detail() {
|
|
358
368
|
* return await describeBalance()
|
|
359
369
|
* }
|
|
360
370
|
* }
|
|
361
371
|
* ```
|
|
362
372
|
*/
|
|
363
|
-
static id<const Type extends string, const S extends number | keyof StatusMap>(
|
|
373
|
+
static id<const Type extends string, const S extends number | keyof StatusMap>(code: Type, status: S): TaggedHTTPError<Type, {
|
|
364
374
|
readonly status: S extends keyof StatusMap ? StatusMap[S] : S;
|
|
365
375
|
}>;
|
|
366
376
|
}
|
|
367
377
|
//#endregion
|
|
368
|
-
export { ElysiaError, ElysiaStatus, HTTPError, InternalServerError, NotFound, PROBLEM_JSON, ParseError, Problem, ProblemResponseBody, SelectiveStatus, TaggedHTTPError, ValidationError, internalServerErrorBody, internalServerErrorBodyString, internalServerErrorResponse, isProduction, problem, problemBody, problemResponse, status, subValueAt, validationDetail };
|
|
378
|
+
export { ElysiaError, ElysiaStatus, HTTPError, InternalServerError, MAX_ERRORS, NotFound, NumericStatus, PROBLEM_JSON, ParseError, Problem, ProblemResponseBody, SelectiveProblem, SelectiveStatus, StatusResponse, TaggedHTTPError, ValidationError, ValidationErrorResponse, elysiaErrorProblem, internalServerErrorBody, internalServerErrorBodyString, internalServerErrorResponse, isProduction, problem, problemBody, problemResponse, problemTypeOf, status, subValueAt, validationDetail };
|