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.mjs
CHANGED
|
@@ -28,20 +28,60 @@ function isCacheableExpected(value, visited = /* @__PURE__ */ new Set()) {
|
|
|
28
28
|
var ElysiaError = class extends Error {
|
|
29
29
|
constructor(message, cause) {
|
|
30
30
|
super(message);
|
|
31
|
-
this.problemType = "about:blank";
|
|
32
31
|
this.name = this.constructor.name;
|
|
33
32
|
if (cause) this.cause = cause;
|
|
34
33
|
}
|
|
35
34
|
toResponse(headers) {
|
|
36
|
-
return problemResponse(
|
|
37
|
-
type: this.problemType,
|
|
38
|
-
title: this.problemTitle,
|
|
39
|
-
status: this.status ?? 500,
|
|
40
|
-
detail: this.response !== void 0 && this.response !== this.problemTitle ? this.response : void 0
|
|
41
|
-
}, headers);
|
|
35
|
+
return problemResponse(elysiaErrorProblem(this), headers);
|
|
42
36
|
}
|
|
43
37
|
};
|
|
44
38
|
/**
|
|
39
|
+
* `type` an error slug resolves to: the slug verbatim, or `<typeBase>/<slug>`
|
|
40
|
+
* once {@link HTTPError.typeBase} is set. Shared by `ElysiaError` and every
|
|
41
|
+
* class {@link HTTPError.id} makes, so both lanes derive `type` identically
|
|
42
|
+
*/
|
|
43
|
+
function problemTypeOf(code) {
|
|
44
|
+
if (code === void 0) return;
|
|
45
|
+
const base = HTTPError.typeBase;
|
|
46
|
+
if (!base) return code;
|
|
47
|
+
return (base.endsWith("/") ? base : base + "/") + code;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Problem members an `ElysiaError` serves. `title` is left to `problemBody`,
|
|
51
|
+
* which derives it from the status — so `response` is only worth serving as
|
|
52
|
+
* `detail` when it says something the title doesn't
|
|
53
|
+
*/
|
|
54
|
+
function elysiaErrorProblem(error) {
|
|
55
|
+
const status = error.status ?? 500;
|
|
56
|
+
return {
|
|
57
|
+
type: error.type ?? "about:blank",
|
|
58
|
+
code: error.code,
|
|
59
|
+
status,
|
|
60
|
+
detail: error.response !== void 0 && error.response !== StatusMapBack[status] ? error.response : void 0
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function defineData(target, key, value, enumerable = true) {
|
|
64
|
+
Object.defineProperty(target, key, {
|
|
65
|
+
value,
|
|
66
|
+
writable: true,
|
|
67
|
+
enumerable,
|
|
68
|
+
configurable: true
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function defineProblemType(prototype) {
|
|
72
|
+
Object.defineProperty(prototype, "type", {
|
|
73
|
+
get() {
|
|
74
|
+
return problemTypeOf(this.code);
|
|
75
|
+
},
|
|
76
|
+
set(value) {
|
|
77
|
+
defineData(this, "type", value);
|
|
78
|
+
},
|
|
79
|
+
enumerable: true,
|
|
80
|
+
configurable: true
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
defineProblemType(ElysiaError.prototype);
|
|
84
|
+
/**
|
|
45
85
|
* Wrap a string into a TypeBox `error` callback that overrides the default
|
|
46
86
|
* validation message. Use as `t.Number({ error: validationDetail('x must be a number') })`.
|
|
47
87
|
*/
|
|
@@ -54,8 +94,7 @@ var InternalServerError = class extends ElysiaError {
|
|
|
54
94
|
super(response, cause);
|
|
55
95
|
this.response = response;
|
|
56
96
|
this.status = 500;
|
|
57
|
-
this.
|
|
58
|
-
this.problemTitle = "Internal Server Error";
|
|
97
|
+
this.code = "internal-server-error";
|
|
59
98
|
}
|
|
60
99
|
};
|
|
61
100
|
var NotFound = class extends ElysiaError {
|
|
@@ -63,8 +102,7 @@ var NotFound = class extends ElysiaError {
|
|
|
63
102
|
super(response);
|
|
64
103
|
this.response = response;
|
|
65
104
|
this.status = 404;
|
|
66
|
-
this.
|
|
67
|
-
this.problemTitle = "Not Found";
|
|
105
|
+
this.code = "not-found";
|
|
68
106
|
}
|
|
69
107
|
};
|
|
70
108
|
var ParseError = class extends ElysiaError {
|
|
@@ -72,15 +110,12 @@ var ParseError = class extends ElysiaError {
|
|
|
72
110
|
super("Bad Request", cause);
|
|
73
111
|
this.status = 400;
|
|
74
112
|
this.response = "Bad Request";
|
|
75
|
-
this.
|
|
76
|
-
this.problemTitle = "Bad Request";
|
|
113
|
+
this.code = "parse";
|
|
77
114
|
}
|
|
78
115
|
toResponse(headers) {
|
|
79
116
|
const cause = this.cause;
|
|
80
117
|
return problemResponse({
|
|
81
|
-
|
|
82
|
-
title: this.problemTitle,
|
|
83
|
-
status: 400,
|
|
118
|
+
...elysiaErrorProblem(this),
|
|
84
119
|
detail: !isProduction() && cause?.message != null ? String(cause.message) : void 0
|
|
85
120
|
}, headers);
|
|
86
121
|
}
|
|
@@ -112,6 +147,7 @@ function walkComposition(schema, parts, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
112
147
|
const walkSubSchema = (schema, instancePath) => !schema || !instancePath ? schema : walkComposition(schema, instancePath.split("/").filter(Boolean));
|
|
113
148
|
const FOUND_ECHO_LIMIT = 8192;
|
|
114
149
|
const FOUND_ECHO_OMITTED = `[value exceeds ${FOUND_ECHO_LIMIT} byte echo limit]`;
|
|
150
|
+
const MAX_ERRORS = 64;
|
|
115
151
|
function jsonStringLengthWithin(value, budget) {
|
|
116
152
|
budget -= 2;
|
|
117
153
|
for (let i = 0; i < value.length && budget >= 0; i++) {
|
|
@@ -173,11 +209,54 @@ function subValueAt(value, path) {
|
|
|
173
209
|
}
|
|
174
210
|
return current;
|
|
175
211
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
212
|
+
const issueLocator = new Set([
|
|
213
|
+
"keyword",
|
|
214
|
+
"schemaPath",
|
|
215
|
+
"instancePath",
|
|
216
|
+
"path"
|
|
217
|
+
]);
|
|
218
|
+
function scopeIssues(errors) {
|
|
219
|
+
let budget = FOUND_ECHO_LIMIT;
|
|
220
|
+
let out;
|
|
221
|
+
for (let i = 0; i < errors.length; i++) {
|
|
222
|
+
const issue = errors[i];
|
|
223
|
+
if (!issue || typeof issue !== "object") {
|
|
224
|
+
out?.push(issue);
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
let scoped;
|
|
228
|
+
for (const key in issue) {
|
|
229
|
+
if (issueLocator.has(key)) continue;
|
|
230
|
+
const member = issue[key];
|
|
231
|
+
const remaining = jsonLengthWithin(member, budget);
|
|
232
|
+
if (remaining >= 0) {
|
|
233
|
+
budget = remaining;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
scoped ??= { ...issue };
|
|
237
|
+
if (member === null || typeof member !== "object" || Array.isArray(member)) {
|
|
238
|
+
scoped[key] = FOUND_ECHO_OMITTED;
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
const narrowed = {};
|
|
242
|
+
for (const name in member) {
|
|
243
|
+
const value = member[name];
|
|
244
|
+
const rest = jsonLengthWithin(value, budget);
|
|
245
|
+
if (rest >= 0) {
|
|
246
|
+
narrowed[name] = value;
|
|
247
|
+
budget = rest;
|
|
248
|
+
} else narrowed[name] = FOUND_ECHO_OMITTED;
|
|
249
|
+
}
|
|
250
|
+
scoped[key] = narrowed;
|
|
251
|
+
}
|
|
252
|
+
if (!scoped) {
|
|
253
|
+
out?.push(issue);
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
out ??= errors.slice(0, i);
|
|
257
|
+
out.push(scoped);
|
|
258
|
+
}
|
|
259
|
+
return out ?? errors;
|
|
181
260
|
}
|
|
182
261
|
var ValidationError = class extends ElysiaError {
|
|
183
262
|
#thunk;
|
|
@@ -188,19 +267,16 @@ var ValidationError = class extends ElysiaError {
|
|
|
188
267
|
this.type = type;
|
|
189
268
|
this.value = value;
|
|
190
269
|
this.status = 422;
|
|
270
|
+
this.code = "validation";
|
|
191
271
|
this.allowUnsafeValidationDetails = false;
|
|
272
|
+
if (type === "response") this.status = 500;
|
|
192
273
|
this.schema = schema;
|
|
193
274
|
this.#thunk = typeof errors === "function" ? errors : () => errors;
|
|
194
275
|
this.#findCustomError = findCustomError;
|
|
195
276
|
Object.defineProperty(this, "errors", {
|
|
196
277
|
get: () => this["~resolve"]().errors,
|
|
197
278
|
set(v) {
|
|
198
|
-
|
|
199
|
-
value: v,
|
|
200
|
-
writable: true,
|
|
201
|
-
enumerable: true,
|
|
202
|
-
configurable: true
|
|
203
|
-
});
|
|
279
|
+
defineData(this, "errors", v);
|
|
204
280
|
},
|
|
205
281
|
enumerable: true,
|
|
206
282
|
configurable: true
|
|
@@ -215,7 +291,6 @@ var ValidationError = class extends ElysiaError {
|
|
|
215
291
|
const findCustomError = this.#findCustomError;
|
|
216
292
|
let resolved;
|
|
217
293
|
let custom;
|
|
218
|
-
let message;
|
|
219
294
|
if (production && !allowUnsafe && findCustomError) {
|
|
220
295
|
const hit = findCustomError(value);
|
|
221
296
|
resolved = hit ? [{ instancePath: hit.instancePath }] : [];
|
|
@@ -224,26 +299,23 @@ var ValidationError = class extends ElysiaError {
|
|
|
224
299
|
on: type,
|
|
225
300
|
found: void 0
|
|
226
301
|
}) : hit.error;
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
302
|
+
} else {
|
|
303
|
+
resolved = this.#thunk() ?? [];
|
|
304
|
+
if (resolved.length > 64) resolved = resolved.slice(0, 64);
|
|
305
|
+
resolved = scopeIssues(resolved);
|
|
306
|
+
const sub = walkSubSchema(this.schema, resolved[0]?.instancePath);
|
|
307
|
+
if (sub?.error !== void 0) custom = typeof sub.error === "function" ? sub.error(production && !allowUnsafe ? {
|
|
308
|
+
type: "validation",
|
|
309
|
+
on: type,
|
|
310
|
+
found: void 0
|
|
311
|
+
} : {
|
|
312
|
+
type: "validation",
|
|
313
|
+
on: type,
|
|
314
|
+
value,
|
|
315
|
+
errors: resolved
|
|
316
|
+
}) : sub.error;
|
|
233
317
|
}
|
|
234
|
-
|
|
235
|
-
const sub = walkSubSchema(this.schema, resolved[0]?.instancePath);
|
|
236
|
-
if (sub?.error !== void 0) custom = typeof sub.error === "function" ? sub.error(production && !allowUnsafe ? {
|
|
237
|
-
type: "validation",
|
|
238
|
-
on: type,
|
|
239
|
-
found: void 0
|
|
240
|
-
} : {
|
|
241
|
-
type: "validation",
|
|
242
|
-
on: type,
|
|
243
|
-
value,
|
|
244
|
-
errors: resolved
|
|
245
|
-
}) : sub.error;
|
|
246
|
-
message = custom !== void 0 ? typeof custom === "string" ? custom : JSON.stringify(custom) : resolved[0]?.message ? resolved[0].message : `Validation error on ${type ?? "unknown"}`;
|
|
318
|
+
const message = custom !== void 0 ? typeof custom === "string" ? custom : JSON.stringify(custom) : resolved[0]?.message ? resolved[0].message : `Validation error on ${type ?? "unknown"}`;
|
|
247
319
|
return this.#state = {
|
|
248
320
|
errors: resolved,
|
|
249
321
|
custom,
|
|
@@ -254,16 +326,21 @@ var ValidationError = class extends ElysiaError {
|
|
|
254
326
|
return this["~resolve"]().custom;
|
|
255
327
|
}
|
|
256
328
|
set customError(v) {
|
|
257
|
-
|
|
258
|
-
value: v,
|
|
259
|
-
writable: true,
|
|
260
|
-
enumerable: true,
|
|
261
|
-
configurable: true
|
|
262
|
-
});
|
|
329
|
+
defineData(this, "customError", v);
|
|
263
330
|
}
|
|
264
331
|
get all() {
|
|
265
332
|
if (!this.errors) return [];
|
|
266
|
-
return this.#collapseCoercionErrors(this.errors.filter(Boolean)).map((e) =>
|
|
333
|
+
return this.#collapseCoercionErrors(this.errors.filter(Boolean)).map((e) => {
|
|
334
|
+
if (!e) return e;
|
|
335
|
+
const issue = {
|
|
336
|
+
path: Array.isArray(e.path) ? e.path.length ? e.path.map(segmentString).join(".") : "root" : typeof e.path === "string" ? e.path.replace(/^\//, "").replace(/\//g, ".") || "root" : "root",
|
|
337
|
+
message: e.message ?? "",
|
|
338
|
+
schemaPath: e.schemaPath,
|
|
339
|
+
params: e.params
|
|
340
|
+
};
|
|
341
|
+
defineData(issue, "value", this.value, false);
|
|
342
|
+
return issue;
|
|
343
|
+
});
|
|
267
344
|
}
|
|
268
345
|
#collapseCoercionErrors(errors) {
|
|
269
346
|
if (!this.schema || !errors.length) return errors;
|
|
@@ -303,52 +380,30 @@ var ValidationError = class extends ElysiaError {
|
|
|
303
380
|
}
|
|
304
381
|
return out ?? errors;
|
|
305
382
|
}
|
|
306
|
-
#normalizeIssue(e) {
|
|
307
|
-
if (!e) return e;
|
|
308
|
-
return {
|
|
309
|
-
path: Array.isArray(e.path) ? e.path.length ? e.path.map(segmentString).join(".") : "root" : typeof e.path === "string" ? e.path.replace(/^\//, "").replace(/\//g, ".") || "root" : "root",
|
|
310
|
-
message: e.message ?? "",
|
|
311
|
-
schemaPath: e.schemaPath,
|
|
312
|
-
params: e.params,
|
|
313
|
-
value: this.value
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
383
|
get #productionDetail() {
|
|
317
384
|
return isProduction() && !this.allowUnsafeValidationDetails;
|
|
318
385
|
}
|
|
319
|
-
get #maskResponseValue() {
|
|
320
|
-
return this.type === "response" && this.#productionDetail;
|
|
321
|
-
}
|
|
322
386
|
detail(message) {
|
|
323
|
-
if (this.#productionDetail) {
|
|
324
|
-
if (this.type === "response") return {
|
|
325
|
-
type: "internal-server-error",
|
|
326
|
-
on: this.type,
|
|
327
|
-
message
|
|
328
|
-
};
|
|
329
|
-
return {
|
|
330
|
-
type: "validation",
|
|
331
|
-
on: this.type,
|
|
332
|
-
message
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
return {
|
|
387
|
+
if (!this.#productionDetail) return {
|
|
336
388
|
type: "validation",
|
|
337
389
|
on: this.type,
|
|
338
390
|
message,
|
|
339
391
|
errors: this.all
|
|
340
392
|
};
|
|
393
|
+
return {
|
|
394
|
+
type: this.type === "response" ? "internal-server-error" : "validation",
|
|
395
|
+
on: this.type,
|
|
396
|
+
message
|
|
397
|
+
};
|
|
341
398
|
}
|
|
342
399
|
get payload() {
|
|
400
|
+
const server = this.type === "response";
|
|
343
401
|
if (this.#productionDetail) {
|
|
344
|
-
if (
|
|
345
|
-
type: "internal-server-error",
|
|
346
|
-
title: "Internal Server Error",
|
|
347
|
-
status: 500
|
|
348
|
-
};
|
|
402
|
+
if (server) return internalServerErrorProblem();
|
|
349
403
|
const first = (this.errors ?? []).find(Boolean);
|
|
350
404
|
return {
|
|
351
405
|
type: "validation",
|
|
406
|
+
code: "validation",
|
|
352
407
|
title: "Validation Error",
|
|
353
408
|
status: 422,
|
|
354
409
|
on: this.type,
|
|
@@ -373,24 +428,35 @@ var ValidationError = class extends ElysiaError {
|
|
|
373
428
|
}
|
|
374
429
|
else expected = created;
|
|
375
430
|
} catch {}
|
|
431
|
+
const value = this.value;
|
|
432
|
+
let found;
|
|
433
|
+
if (jsonLengthWithin(value, FOUND_ECHO_LIMIT) >= 0) found = value;
|
|
434
|
+
else {
|
|
435
|
+
const sub = subValueAt(value, first?.instancePath ?? first?.path);
|
|
436
|
+
if (sub !== void 0 && jsonLengthWithin(sub, FOUND_ECHO_LIMIT) >= 0) found = sub;
|
|
437
|
+
else found = FOUND_ECHO_OMITTED;
|
|
438
|
+
}
|
|
376
439
|
return {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
440
|
+
...server ? internalServerErrorProblem() : {
|
|
441
|
+
type: "validation",
|
|
442
|
+
code: "validation",
|
|
443
|
+
title: "Validation Error",
|
|
444
|
+
status: 422
|
|
445
|
+
},
|
|
380
446
|
detail,
|
|
381
447
|
on: this.type,
|
|
382
448
|
property,
|
|
383
|
-
found
|
|
449
|
+
found,
|
|
384
450
|
expected,
|
|
385
451
|
errors
|
|
386
452
|
};
|
|
387
453
|
}
|
|
388
454
|
toResponse(headers) {
|
|
389
|
-
if (this.#
|
|
455
|
+
if (this.type === "response" && this.#productionDetail) return problemResponse(this.payload, headers);
|
|
390
456
|
if (this.customError !== void 0) {
|
|
391
457
|
const isString = typeof this.customError === "string";
|
|
392
458
|
const response = new Response(isString ? this.customError : JSON.stringify(this.customError), {
|
|
393
|
-
status: this.status ?? 422,
|
|
459
|
+
status: this.type === "response" ? 500 : this.status ?? 422,
|
|
394
460
|
headers: {
|
|
395
461
|
...headers,
|
|
396
462
|
"content-type": isString ? "text/plain" : "application/json"
|
|
@@ -407,12 +473,7 @@ Object.defineProperty(ValidationError.prototype, "message", {
|
|
|
407
473
|
return this["~resolve"]().message;
|
|
408
474
|
},
|
|
409
475
|
set(v) {
|
|
410
|
-
|
|
411
|
-
value: v,
|
|
412
|
-
writable: true,
|
|
413
|
-
enumerable: false,
|
|
414
|
-
configurable: true
|
|
415
|
-
});
|
|
476
|
+
defineData(this, "message", v, false);
|
|
416
477
|
},
|
|
417
478
|
enumerable: false,
|
|
418
479
|
configurable: true
|
|
@@ -428,13 +489,10 @@ const emptyHttpStatus = new Set([
|
|
|
428
489
|
var ElysiaStatus = class {
|
|
429
490
|
constructor(code, res, headers) {
|
|
430
491
|
const response = res ?? (code in StatusMapBack ? StatusMapBack[code] : code);
|
|
431
|
-
this.
|
|
432
|
-
if (!emptyHttpStatus.has(this.
|
|
492
|
+
this.status = StatusMap[code] ?? code;
|
|
493
|
+
if (!emptyHttpStatus.has(this.status)) this.response = response;
|
|
433
494
|
this.headers = headers;
|
|
434
495
|
}
|
|
435
|
-
get status() {
|
|
436
|
-
return this.code;
|
|
437
|
-
}
|
|
438
496
|
};
|
|
439
497
|
Object.defineProperty(ElysiaStatus, "name", { value: "ElysiaStatus" });
|
|
440
498
|
const status = (code, response) => new ElysiaStatus(code, response);
|
|
@@ -461,12 +519,14 @@ function problemResponse(p, headers) {
|
|
|
461
519
|
skipClone.add(response);
|
|
462
520
|
return response;
|
|
463
521
|
}
|
|
522
|
+
const internalServerErrorProblem = () => ({
|
|
523
|
+
type: problemTypeOf("internal-server-error"),
|
|
524
|
+
code: "internal-server-error",
|
|
525
|
+
title: "Internal Server Error",
|
|
526
|
+
status: 500
|
|
527
|
+
});
|
|
464
528
|
function internalServerErrorBody(error) {
|
|
465
|
-
const body =
|
|
466
|
-
type: "internal-server-error",
|
|
467
|
-
title: "Internal Server Error",
|
|
468
|
-
status: 500
|
|
469
|
-
};
|
|
529
|
+
const body = internalServerErrorProblem();
|
|
470
530
|
if (!isProduction()) {
|
|
471
531
|
if (error?.message != null) body.detail = error.message;
|
|
472
532
|
if (error?.name) body.name = error.name;
|
|
@@ -483,11 +543,7 @@ function internalServerErrorBodyString(error) {
|
|
|
483
543
|
delete safe.cause;
|
|
484
544
|
return JSON.stringify(safe);
|
|
485
545
|
} catch {
|
|
486
|
-
return JSON.stringify(
|
|
487
|
-
type: "internal-server-error",
|
|
488
|
-
title: "Internal Server Error",
|
|
489
|
-
status: 500
|
|
490
|
-
});
|
|
546
|
+
return JSON.stringify(internalServerErrorProblem());
|
|
491
547
|
}
|
|
492
548
|
}
|
|
493
549
|
}
|
|
@@ -565,12 +621,17 @@ function problem(statusOrDetail, detail) {
|
|
|
565
621
|
* @since 2.0.0
|
|
566
622
|
*/
|
|
567
623
|
var HTTPError = class HTTPError extends Error {
|
|
568
|
-
static id(
|
|
569
|
-
const Tagged = class extends HTTPError {
|
|
570
|
-
|
|
571
|
-
|
|
624
|
+
static id(code, status) {
|
|
625
|
+
const Tagged = class extends HTTPError {
|
|
626
|
+
constructor(..._args) {
|
|
627
|
+
super(..._args);
|
|
628
|
+
this.code = code;
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
defineProblemType(Tagged.prototype);
|
|
632
|
+
Tagged.prototype.name = code;
|
|
572
633
|
Object.defineProperty(Tagged, "name", {
|
|
573
|
-
value:
|
|
634
|
+
value: code,
|
|
574
635
|
configurable: true
|
|
575
636
|
});
|
|
576
637
|
const resolved = typeof status === "string" ? StatusMap[status] : status;
|
|
@@ -580,4 +641,4 @@ var HTTPError = class HTTPError extends Error {
|
|
|
580
641
|
};
|
|
581
642
|
|
|
582
643
|
//#endregion
|
|
583
|
-
export { ElysiaError, ElysiaStatus, HTTPError, InternalServerError, NotFound, PROBLEM_JSON, ParseError, ValidationError, internalServerErrorBody, internalServerErrorBodyString, internalServerErrorResponse, isProduction, problem, problemBody, problemResponse, status, subValueAt, validationDetail };
|
|
644
|
+
export { ElysiaError, ElysiaStatus, HTTPError, InternalServerError, MAX_ERRORS, NotFound, PROBLEM_JSON, ParseError, ValidationError, elysiaErrorProblem, internalServerErrorBody, internalServerErrorBodyString, internalServerErrorResponse, isProduction, problem, problemBody, problemResponse, problemTypeOf, status, subValueAt, validationDetail };
|
package/dist/generation.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TraceCapability } from "./trace.js";
|
|
2
1
|
import { ChainNode } from "./utils.js";
|
|
2
|
+
import { TraceCapability } from "./trace.js";
|
|
3
3
|
import { ProgramId } from "./compile/aot.js";
|
|
4
4
|
import { WSCapability, WSOptions } from "./ws/types.js";
|
|
5
5
|
import { RouteTable } from "./route-table.js";
|
|
@@ -27,4 +27,4 @@ declare const resolvedWsOf: (root: AnyElysia) => {
|
|
|
27
27
|
} | undefined;
|
|
28
28
|
declare const wsCapabilityRequired = "[Elysia] .ws() requires the WebSocket capability: import { websocket } from 'elysia/websocket' and .use(websocket())";
|
|
29
29
|
//#endregion
|
|
30
|
-
export {
|
|
30
|
+
export { Generation, frozenRootOf, resolvedTraceOf, resolvedWsOf, traceCapabilityRequired, wsCapabilityRequired };
|
package/dist/handler/error.d.ts
CHANGED
|
@@ -1,18 +1,8 @@
|
|
|
1
|
-
import { AppHook } from "../types.js";
|
|
2
1
|
import { Context } from "../context.js";
|
|
2
|
+
import { AppHook } from "../types.js";
|
|
3
3
|
|
|
4
4
|
//#region src/handler/error.d.ts
|
|
5
|
-
|
|
6
|
-
* Adopt the intercepted error's `type` into a problem the hook produced
|
|
7
|
-
* without one.
|
|
8
|
-
*
|
|
9
|
-
* `'about:blank'` is RFC 9457's "unspecified" default, so it's the only value
|
|
10
|
-
* worth replacing — an explicit type the handler set always wins.
|
|
11
|
-
*
|
|
12
|
-
* The result is copied rather than mutated: `.error(Class, value)` wraps a
|
|
13
|
-
* non-function into `() => value`, so the very same `ElysiaStatus` is replayed
|
|
14
|
-
* on every request and an in-place write would leak across requests
|
|
15
|
-
*/
|
|
5
|
+
declare const claimsProblemType: (error: any) => boolean;
|
|
16
6
|
declare function adoptErrorType(result: any, error: any): any;
|
|
17
7
|
/**
|
|
18
8
|
* Response served once every error hook has declined the error.
|
|
@@ -20,7 +10,28 @@ declare function adoptErrorType(result: any, error: any): any;
|
|
|
20
10
|
* Exported for the JIT: a route with error hooks emits its own catch block,
|
|
21
11
|
* which must land on *this* function rather than re-implementing it
|
|
22
12
|
*/
|
|
23
|
-
declare function fallbackResponse(context: Context, error: any, mapResponse: (response: unknown, set: Context['set'], context?: Context) => unknown
|
|
24
|
-
|
|
13
|
+
declare function fallbackResponse(context: Context, error: any, mapResponse: (response: unknown, set: Context['set'], context?: Context) => unknown): unknown;
|
|
14
|
+
/**
|
|
15
|
+
* Numeric form of an annotated status, which may be written as a name.
|
|
16
|
+
* A numeric string keeps coercing so the production mask below can't be
|
|
17
|
+
* slipped past with `'502'`
|
|
18
|
+
*/
|
|
19
|
+
declare const resolveStatus: (status: unknown) => unknown;
|
|
20
|
+
/**
|
|
21
|
+
* Body served by an error that carries a status but no usable body:
|
|
22
|
+
* its declared `response`, otherwise its message
|
|
23
|
+
*/
|
|
24
|
+
declare function statusFallbackBody(error: any, status: unknown): any;
|
|
25
|
+
/**
|
|
26
|
+
* Read one annotation knob.
|
|
27
|
+
*
|
|
28
|
+
* Both knobs are canonically methods, so they're evaluated per serve and may
|
|
29
|
+
* be `async`. Running a stranger's function is side-effect surface (it may
|
|
30
|
+
* consume a stream or do IO), so it takes the same problem claim the shaping
|
|
31
|
+
* does — an unclaimed duck error never invokes one. A *value* annotation stays
|
|
32
|
+
* inert data and keeps duck-participating as it always has
|
|
33
|
+
*/
|
|
34
|
+
declare const readAnnotation: (self: any, key: "value" | "detail", claimsProblem: boolean) => any;
|
|
35
|
+
declare function createErrorHandler(onErrors: AppHook['error'] | undefined, mapResponse: (response: unknown, set: Context['set'], ...any: unknown[]) => unknown, allowUnsafe?: boolean): (context: Context, error: Error, sign?: ((set: Context["set"]) => unknown) | undefined) => unknown;
|
|
25
36
|
//#endregion
|
|
26
|
-
export { adoptErrorType, createErrorHandler, fallbackResponse };
|
|
37
|
+
export { adoptErrorType, claimsProblemType, createErrorHandler, fallbackResponse, readAnnotation, resolveStatus, statusFallbackBody };
|