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.js
CHANGED
|
@@ -29,20 +29,60 @@ function isCacheableExpected(value, visited = /* @__PURE__ */ new Set()) {
|
|
|
29
29
|
var ElysiaError = class extends Error {
|
|
30
30
|
constructor(message, cause) {
|
|
31
31
|
super(message);
|
|
32
|
-
this.problemType = "about:blank";
|
|
33
32
|
this.name = this.constructor.name;
|
|
34
33
|
if (cause) this.cause = cause;
|
|
35
34
|
}
|
|
36
35
|
toResponse(headers) {
|
|
37
|
-
return problemResponse(
|
|
38
|
-
type: this.problemType,
|
|
39
|
-
title: this.problemTitle,
|
|
40
|
-
status: this.status ?? 500,
|
|
41
|
-
detail: this.response !== void 0 && this.response !== this.problemTitle ? this.response : void 0
|
|
42
|
-
}, headers);
|
|
36
|
+
return problemResponse(elysiaErrorProblem(this), headers);
|
|
43
37
|
}
|
|
44
38
|
};
|
|
45
39
|
/**
|
|
40
|
+
* `type` an error slug resolves to: the slug verbatim, or `<typeBase>/<slug>`
|
|
41
|
+
* once {@link HTTPError.typeBase} is set. Shared by `ElysiaError` and every
|
|
42
|
+
* class {@link HTTPError.id} makes, so both lanes derive `type` identically
|
|
43
|
+
*/
|
|
44
|
+
function problemTypeOf(code) {
|
|
45
|
+
if (code === void 0) return;
|
|
46
|
+
const base = HTTPError.typeBase;
|
|
47
|
+
if (!base) return code;
|
|
48
|
+
return (base.endsWith("/") ? base : base + "/") + code;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Problem members an `ElysiaError` serves. `title` is left to `problemBody`,
|
|
52
|
+
* which derives it from the status — so `response` is only worth serving as
|
|
53
|
+
* `detail` when it says something the title doesn't
|
|
54
|
+
*/
|
|
55
|
+
function elysiaErrorProblem(error) {
|
|
56
|
+
const status = error.status ?? 500;
|
|
57
|
+
return {
|
|
58
|
+
type: error.type ?? "about:blank",
|
|
59
|
+
code: error.code,
|
|
60
|
+
status,
|
|
61
|
+
detail: error.response !== void 0 && error.response !== require_constants.StatusMapBack[status] ? error.response : void 0
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function defineData(target, key, value, enumerable = true) {
|
|
65
|
+
Object.defineProperty(target, key, {
|
|
66
|
+
value,
|
|
67
|
+
writable: true,
|
|
68
|
+
enumerable,
|
|
69
|
+
configurable: true
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
function defineProblemType(prototype) {
|
|
73
|
+
Object.defineProperty(prototype, "type", {
|
|
74
|
+
get() {
|
|
75
|
+
return problemTypeOf(this.code);
|
|
76
|
+
},
|
|
77
|
+
set(value) {
|
|
78
|
+
defineData(this, "type", value);
|
|
79
|
+
},
|
|
80
|
+
enumerable: true,
|
|
81
|
+
configurable: true
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
defineProblemType(ElysiaError.prototype);
|
|
85
|
+
/**
|
|
46
86
|
* Wrap a string into a TypeBox `error` callback that overrides the default
|
|
47
87
|
* validation message. Use as `t.Number({ error: validationDetail('x must be a number') })`.
|
|
48
88
|
*/
|
|
@@ -55,8 +95,7 @@ var InternalServerError = class extends ElysiaError {
|
|
|
55
95
|
super(response, cause);
|
|
56
96
|
this.response = response;
|
|
57
97
|
this.status = 500;
|
|
58
|
-
this.
|
|
59
|
-
this.problemTitle = "Internal Server Error";
|
|
98
|
+
this.code = "internal-server-error";
|
|
60
99
|
}
|
|
61
100
|
};
|
|
62
101
|
var NotFound = class extends ElysiaError {
|
|
@@ -64,8 +103,7 @@ var NotFound = class extends ElysiaError {
|
|
|
64
103
|
super(response);
|
|
65
104
|
this.response = response;
|
|
66
105
|
this.status = 404;
|
|
67
|
-
this.
|
|
68
|
-
this.problemTitle = "Not Found";
|
|
106
|
+
this.code = "not-found";
|
|
69
107
|
}
|
|
70
108
|
};
|
|
71
109
|
var ParseError = class extends ElysiaError {
|
|
@@ -73,15 +111,12 @@ var ParseError = class extends ElysiaError {
|
|
|
73
111
|
super("Bad Request", cause);
|
|
74
112
|
this.status = 400;
|
|
75
113
|
this.response = "Bad Request";
|
|
76
|
-
this.
|
|
77
|
-
this.problemTitle = "Bad Request";
|
|
114
|
+
this.code = "parse";
|
|
78
115
|
}
|
|
79
116
|
toResponse(headers) {
|
|
80
117
|
const cause = this.cause;
|
|
81
118
|
return problemResponse({
|
|
82
|
-
|
|
83
|
-
title: this.problemTitle,
|
|
84
|
-
status: 400,
|
|
119
|
+
...elysiaErrorProblem(this),
|
|
85
120
|
detail: !require_universal_is_production.isProduction() && cause?.message != null ? String(cause.message) : void 0
|
|
86
121
|
}, headers);
|
|
87
122
|
}
|
|
@@ -113,6 +148,7 @@ function walkComposition(schema, parts, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
113
148
|
const walkSubSchema = (schema, instancePath) => !schema || !instancePath ? schema : walkComposition(schema, instancePath.split("/").filter(Boolean));
|
|
114
149
|
const FOUND_ECHO_LIMIT = 8192;
|
|
115
150
|
const FOUND_ECHO_OMITTED = `[value exceeds ${FOUND_ECHO_LIMIT} byte echo limit]`;
|
|
151
|
+
const MAX_ERRORS = 64;
|
|
116
152
|
function jsonStringLengthWithin(value, budget) {
|
|
117
153
|
budget -= 2;
|
|
118
154
|
for (let i = 0; i < value.length && budget >= 0; i++) {
|
|
@@ -174,11 +210,54 @@ function subValueAt(value, path) {
|
|
|
174
210
|
}
|
|
175
211
|
return current;
|
|
176
212
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
213
|
+
const issueLocator = new Set([
|
|
214
|
+
"keyword",
|
|
215
|
+
"schemaPath",
|
|
216
|
+
"instancePath",
|
|
217
|
+
"path"
|
|
218
|
+
]);
|
|
219
|
+
function scopeIssues(errors) {
|
|
220
|
+
let budget = FOUND_ECHO_LIMIT;
|
|
221
|
+
let out;
|
|
222
|
+
for (let i = 0; i < errors.length; i++) {
|
|
223
|
+
const issue = errors[i];
|
|
224
|
+
if (!issue || typeof issue !== "object") {
|
|
225
|
+
out?.push(issue);
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
let scoped;
|
|
229
|
+
for (const key in issue) {
|
|
230
|
+
if (issueLocator.has(key)) continue;
|
|
231
|
+
const member = issue[key];
|
|
232
|
+
const remaining = jsonLengthWithin(member, budget);
|
|
233
|
+
if (remaining >= 0) {
|
|
234
|
+
budget = remaining;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
scoped ??= { ...issue };
|
|
238
|
+
if (member === null || typeof member !== "object" || Array.isArray(member)) {
|
|
239
|
+
scoped[key] = FOUND_ECHO_OMITTED;
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
const narrowed = {};
|
|
243
|
+
for (const name in member) {
|
|
244
|
+
const value = member[name];
|
|
245
|
+
const rest = jsonLengthWithin(value, budget);
|
|
246
|
+
if (rest >= 0) {
|
|
247
|
+
narrowed[name] = value;
|
|
248
|
+
budget = rest;
|
|
249
|
+
} else narrowed[name] = FOUND_ECHO_OMITTED;
|
|
250
|
+
}
|
|
251
|
+
scoped[key] = narrowed;
|
|
252
|
+
}
|
|
253
|
+
if (!scoped) {
|
|
254
|
+
out?.push(issue);
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
out ??= errors.slice(0, i);
|
|
258
|
+
out.push(scoped);
|
|
259
|
+
}
|
|
260
|
+
return out ?? errors;
|
|
182
261
|
}
|
|
183
262
|
var ValidationError = class extends ElysiaError {
|
|
184
263
|
#thunk;
|
|
@@ -189,19 +268,16 @@ var ValidationError = class extends ElysiaError {
|
|
|
189
268
|
this.type = type;
|
|
190
269
|
this.value = value;
|
|
191
270
|
this.status = 422;
|
|
271
|
+
this.code = "validation";
|
|
192
272
|
this.allowUnsafeValidationDetails = false;
|
|
273
|
+
if (type === "response") this.status = 500;
|
|
193
274
|
this.schema = schema;
|
|
194
275
|
this.#thunk = typeof errors === "function" ? errors : () => errors;
|
|
195
276
|
this.#findCustomError = findCustomError;
|
|
196
277
|
Object.defineProperty(this, "errors", {
|
|
197
278
|
get: () => this["~resolve"]().errors,
|
|
198
279
|
set(v) {
|
|
199
|
-
|
|
200
|
-
value: v,
|
|
201
|
-
writable: true,
|
|
202
|
-
enumerable: true,
|
|
203
|
-
configurable: true
|
|
204
|
-
});
|
|
280
|
+
defineData(this, "errors", v);
|
|
205
281
|
},
|
|
206
282
|
enumerable: true,
|
|
207
283
|
configurable: true
|
|
@@ -216,7 +292,6 @@ var ValidationError = class extends ElysiaError {
|
|
|
216
292
|
const findCustomError = this.#findCustomError;
|
|
217
293
|
let resolved;
|
|
218
294
|
let custom;
|
|
219
|
-
let message;
|
|
220
295
|
if (production && !allowUnsafe && findCustomError) {
|
|
221
296
|
const hit = findCustomError(value);
|
|
222
297
|
resolved = hit ? [{ instancePath: hit.instancePath }] : [];
|
|
@@ -225,26 +300,23 @@ var ValidationError = class extends ElysiaError {
|
|
|
225
300
|
on: type,
|
|
226
301
|
found: void 0
|
|
227
302
|
}) : hit.error;
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
303
|
+
} else {
|
|
304
|
+
resolved = this.#thunk() ?? [];
|
|
305
|
+
if (resolved.length > 64) resolved = resolved.slice(0, 64);
|
|
306
|
+
resolved = scopeIssues(resolved);
|
|
307
|
+
const sub = walkSubSchema(this.schema, resolved[0]?.instancePath);
|
|
308
|
+
if (sub?.error !== void 0) custom = typeof sub.error === "function" ? sub.error(production && !allowUnsafe ? {
|
|
309
|
+
type: "validation",
|
|
310
|
+
on: type,
|
|
311
|
+
found: void 0
|
|
312
|
+
} : {
|
|
313
|
+
type: "validation",
|
|
314
|
+
on: type,
|
|
315
|
+
value,
|
|
316
|
+
errors: resolved
|
|
317
|
+
}) : sub.error;
|
|
234
318
|
}
|
|
235
|
-
|
|
236
|
-
const sub = walkSubSchema(this.schema, resolved[0]?.instancePath);
|
|
237
|
-
if (sub?.error !== void 0) custom = typeof sub.error === "function" ? sub.error(production && !allowUnsafe ? {
|
|
238
|
-
type: "validation",
|
|
239
|
-
on: type,
|
|
240
|
-
found: void 0
|
|
241
|
-
} : {
|
|
242
|
-
type: "validation",
|
|
243
|
-
on: type,
|
|
244
|
-
value,
|
|
245
|
-
errors: resolved
|
|
246
|
-
}) : sub.error;
|
|
247
|
-
message = custom !== void 0 ? typeof custom === "string" ? custom : JSON.stringify(custom) : resolved[0]?.message ? resolved[0].message : `Validation error on ${type ?? "unknown"}`;
|
|
319
|
+
const message = custom !== void 0 ? typeof custom === "string" ? custom : JSON.stringify(custom) : resolved[0]?.message ? resolved[0].message : `Validation error on ${type ?? "unknown"}`;
|
|
248
320
|
return this.#state = {
|
|
249
321
|
errors: resolved,
|
|
250
322
|
custom,
|
|
@@ -255,16 +327,21 @@ var ValidationError = class extends ElysiaError {
|
|
|
255
327
|
return this["~resolve"]().custom;
|
|
256
328
|
}
|
|
257
329
|
set customError(v) {
|
|
258
|
-
|
|
259
|
-
value: v,
|
|
260
|
-
writable: true,
|
|
261
|
-
enumerable: true,
|
|
262
|
-
configurable: true
|
|
263
|
-
});
|
|
330
|
+
defineData(this, "customError", v);
|
|
264
331
|
}
|
|
265
332
|
get all() {
|
|
266
333
|
if (!this.errors) return [];
|
|
267
|
-
return this.#collapseCoercionErrors(this.errors.filter(Boolean)).map((e) =>
|
|
334
|
+
return this.#collapseCoercionErrors(this.errors.filter(Boolean)).map((e) => {
|
|
335
|
+
if (!e) return e;
|
|
336
|
+
const issue = {
|
|
337
|
+
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",
|
|
338
|
+
message: e.message ?? "",
|
|
339
|
+
schemaPath: e.schemaPath,
|
|
340
|
+
params: e.params
|
|
341
|
+
};
|
|
342
|
+
defineData(issue, "value", this.value, false);
|
|
343
|
+
return issue;
|
|
344
|
+
});
|
|
268
345
|
}
|
|
269
346
|
#collapseCoercionErrors(errors) {
|
|
270
347
|
if (!this.schema || !errors.length) return errors;
|
|
@@ -304,52 +381,30 @@ var ValidationError = class extends ElysiaError {
|
|
|
304
381
|
}
|
|
305
382
|
return out ?? errors;
|
|
306
383
|
}
|
|
307
|
-
#normalizeIssue(e) {
|
|
308
|
-
if (!e) return e;
|
|
309
|
-
return {
|
|
310
|
-
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",
|
|
311
|
-
message: e.message ?? "",
|
|
312
|
-
schemaPath: e.schemaPath,
|
|
313
|
-
params: e.params,
|
|
314
|
-
value: this.value
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
384
|
get #productionDetail() {
|
|
318
385
|
return require_universal_is_production.isProduction() && !this.allowUnsafeValidationDetails;
|
|
319
386
|
}
|
|
320
|
-
get #maskResponseValue() {
|
|
321
|
-
return this.type === "response" && this.#productionDetail;
|
|
322
|
-
}
|
|
323
387
|
detail(message) {
|
|
324
|
-
if (this.#productionDetail) {
|
|
325
|
-
if (this.type === "response") return {
|
|
326
|
-
type: "internal-server-error",
|
|
327
|
-
on: this.type,
|
|
328
|
-
message
|
|
329
|
-
};
|
|
330
|
-
return {
|
|
331
|
-
type: "validation",
|
|
332
|
-
on: this.type,
|
|
333
|
-
message
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
return {
|
|
388
|
+
if (!this.#productionDetail) return {
|
|
337
389
|
type: "validation",
|
|
338
390
|
on: this.type,
|
|
339
391
|
message,
|
|
340
392
|
errors: this.all
|
|
341
393
|
};
|
|
394
|
+
return {
|
|
395
|
+
type: this.type === "response" ? "internal-server-error" : "validation",
|
|
396
|
+
on: this.type,
|
|
397
|
+
message
|
|
398
|
+
};
|
|
342
399
|
}
|
|
343
400
|
get payload() {
|
|
401
|
+
const server = this.type === "response";
|
|
344
402
|
if (this.#productionDetail) {
|
|
345
|
-
if (
|
|
346
|
-
type: "internal-server-error",
|
|
347
|
-
title: "Internal Server Error",
|
|
348
|
-
status: 500
|
|
349
|
-
};
|
|
403
|
+
if (server) return internalServerErrorProblem();
|
|
350
404
|
const first = (this.errors ?? []).find(Boolean);
|
|
351
405
|
return {
|
|
352
406
|
type: "validation",
|
|
407
|
+
code: "validation",
|
|
353
408
|
title: "Validation Error",
|
|
354
409
|
status: 422,
|
|
355
410
|
on: this.type,
|
|
@@ -374,24 +429,35 @@ var ValidationError = class extends ElysiaError {
|
|
|
374
429
|
}
|
|
375
430
|
else expected = created;
|
|
376
431
|
} catch {}
|
|
432
|
+
const value = this.value;
|
|
433
|
+
let found;
|
|
434
|
+
if (jsonLengthWithin(value, FOUND_ECHO_LIMIT) >= 0) found = value;
|
|
435
|
+
else {
|
|
436
|
+
const sub = subValueAt(value, first?.instancePath ?? first?.path);
|
|
437
|
+
if (sub !== void 0 && jsonLengthWithin(sub, FOUND_ECHO_LIMIT) >= 0) found = sub;
|
|
438
|
+
else found = FOUND_ECHO_OMITTED;
|
|
439
|
+
}
|
|
377
440
|
return {
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
441
|
+
...server ? internalServerErrorProblem() : {
|
|
442
|
+
type: "validation",
|
|
443
|
+
code: "validation",
|
|
444
|
+
title: "Validation Error",
|
|
445
|
+
status: 422
|
|
446
|
+
},
|
|
381
447
|
detail,
|
|
382
448
|
on: this.type,
|
|
383
449
|
property,
|
|
384
|
-
found
|
|
450
|
+
found,
|
|
385
451
|
expected,
|
|
386
452
|
errors
|
|
387
453
|
};
|
|
388
454
|
}
|
|
389
455
|
toResponse(headers) {
|
|
390
|
-
if (this.#
|
|
456
|
+
if (this.type === "response" && this.#productionDetail) return problemResponse(this.payload, headers);
|
|
391
457
|
if (this.customError !== void 0) {
|
|
392
458
|
const isString = typeof this.customError === "string";
|
|
393
459
|
const response = new Response(isString ? this.customError : JSON.stringify(this.customError), {
|
|
394
|
-
status: this.status ?? 422,
|
|
460
|
+
status: this.type === "response" ? 500 : this.status ?? 422,
|
|
395
461
|
headers: {
|
|
396
462
|
...headers,
|
|
397
463
|
"content-type": isString ? "text/plain" : "application/json"
|
|
@@ -408,12 +474,7 @@ Object.defineProperty(ValidationError.prototype, "message", {
|
|
|
408
474
|
return this["~resolve"]().message;
|
|
409
475
|
},
|
|
410
476
|
set(v) {
|
|
411
|
-
|
|
412
|
-
value: v,
|
|
413
|
-
writable: true,
|
|
414
|
-
enumerable: false,
|
|
415
|
-
configurable: true
|
|
416
|
-
});
|
|
477
|
+
defineData(this, "message", v, false);
|
|
417
478
|
},
|
|
418
479
|
enumerable: false,
|
|
419
480
|
configurable: true
|
|
@@ -429,13 +490,10 @@ const emptyHttpStatus = new Set([
|
|
|
429
490
|
var ElysiaStatus = class {
|
|
430
491
|
constructor(code, res, headers) {
|
|
431
492
|
const response = res ?? (code in require_constants.StatusMapBack ? require_constants.StatusMapBack[code] : code);
|
|
432
|
-
this.
|
|
433
|
-
if (!emptyHttpStatus.has(this.
|
|
493
|
+
this.status = require_constants.StatusMap[code] ?? code;
|
|
494
|
+
if (!emptyHttpStatus.has(this.status)) this.response = response;
|
|
434
495
|
this.headers = headers;
|
|
435
496
|
}
|
|
436
|
-
get status() {
|
|
437
|
-
return this.code;
|
|
438
|
-
}
|
|
439
497
|
};
|
|
440
498
|
Object.defineProperty(ElysiaStatus, "name", { value: "ElysiaStatus" });
|
|
441
499
|
const status = (code, response) => new ElysiaStatus(code, response);
|
|
@@ -462,12 +520,14 @@ function problemResponse(p, headers) {
|
|
|
462
520
|
require_adapter_skip_clone.skipClone.add(response);
|
|
463
521
|
return response;
|
|
464
522
|
}
|
|
523
|
+
const internalServerErrorProblem = () => ({
|
|
524
|
+
type: problemTypeOf("internal-server-error"),
|
|
525
|
+
code: "internal-server-error",
|
|
526
|
+
title: "Internal Server Error",
|
|
527
|
+
status: 500
|
|
528
|
+
});
|
|
465
529
|
function internalServerErrorBody(error) {
|
|
466
|
-
const body =
|
|
467
|
-
type: "internal-server-error",
|
|
468
|
-
title: "Internal Server Error",
|
|
469
|
-
status: 500
|
|
470
|
-
};
|
|
530
|
+
const body = internalServerErrorProblem();
|
|
471
531
|
if (!require_universal_is_production.isProduction()) {
|
|
472
532
|
if (error?.message != null) body.detail = error.message;
|
|
473
533
|
if (error?.name) body.name = error.name;
|
|
@@ -484,11 +544,7 @@ function internalServerErrorBodyString(error) {
|
|
|
484
544
|
delete safe.cause;
|
|
485
545
|
return JSON.stringify(safe);
|
|
486
546
|
} catch {
|
|
487
|
-
return JSON.stringify(
|
|
488
|
-
type: "internal-server-error",
|
|
489
|
-
title: "Internal Server Error",
|
|
490
|
-
status: 500
|
|
491
|
-
});
|
|
547
|
+
return JSON.stringify(internalServerErrorProblem());
|
|
492
548
|
}
|
|
493
549
|
}
|
|
494
550
|
}
|
|
@@ -566,12 +622,17 @@ function problem(statusOrDetail, detail) {
|
|
|
566
622
|
* @since 2.0.0
|
|
567
623
|
*/
|
|
568
624
|
var HTTPError = class HTTPError extends Error {
|
|
569
|
-
static id(
|
|
570
|
-
const Tagged = class extends HTTPError {
|
|
571
|
-
|
|
572
|
-
|
|
625
|
+
static id(code, status) {
|
|
626
|
+
const Tagged = class extends HTTPError {
|
|
627
|
+
constructor(..._args) {
|
|
628
|
+
super(..._args);
|
|
629
|
+
this.code = code;
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
defineProblemType(Tagged.prototype);
|
|
633
|
+
Tagged.prototype.name = code;
|
|
573
634
|
Object.defineProperty(Tagged, "name", {
|
|
574
|
-
value:
|
|
635
|
+
value: code,
|
|
575
636
|
configurable: true
|
|
576
637
|
});
|
|
577
638
|
const resolved = typeof status === "string" ? require_constants.StatusMap[status] : status;
|
|
@@ -585,10 +646,12 @@ exports.ElysiaError = ElysiaError;
|
|
|
585
646
|
exports.ElysiaStatus = ElysiaStatus;
|
|
586
647
|
exports.HTTPError = HTTPError;
|
|
587
648
|
exports.InternalServerError = InternalServerError;
|
|
649
|
+
exports.MAX_ERRORS = MAX_ERRORS;
|
|
588
650
|
exports.NotFound = NotFound;
|
|
589
651
|
exports.PROBLEM_JSON = PROBLEM_JSON;
|
|
590
652
|
exports.ParseError = ParseError;
|
|
591
653
|
exports.ValidationError = ValidationError;
|
|
654
|
+
exports.elysiaErrorProblem = elysiaErrorProblem;
|
|
592
655
|
exports.internalServerErrorBody = internalServerErrorBody;
|
|
593
656
|
exports.internalServerErrorBodyString = internalServerErrorBodyString;
|
|
594
657
|
exports.internalServerErrorResponse = internalServerErrorResponse;
|
|
@@ -596,6 +659,7 @@ exports.isProduction = require_universal_is_production.isProduction;
|
|
|
596
659
|
exports.problem = problem;
|
|
597
660
|
exports.problemBody = problemBody;
|
|
598
661
|
exports.problemResponse = problemResponse;
|
|
662
|
+
exports.problemTypeOf = problemTypeOf;
|
|
599
663
|
exports.status = status;
|
|
600
664
|
exports.subValueAt = subValueAt;
|
|
601
665
|
exports.validationDetail = validationDetail;
|