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
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
3
2
|
const require_utils = require('../../utils.js');
|
|
4
3
|
const require_type_constants = require('../constants.js');
|
|
5
4
|
const require_error = require('../../error.js');
|
|
6
5
|
const require_compile_aot = require('../../compile/aot.js');
|
|
7
6
|
const require_type_shared = require('../shared.js');
|
|
8
|
-
const require_type_elysia_file_type = require('../elysia/file-type.js');
|
|
9
7
|
const require_type_validator_clean_safe = require('./clean-safe.js');
|
|
10
8
|
const require_type_utils = require('../utils.js');
|
|
11
9
|
const require_validator_index = require('../../validator/index.js');
|
|
10
|
+
const require_type_typebox_type = require('../typebox-type.js');
|
|
11
|
+
const require_type_typebox_value = require('../typebox-value.js');
|
|
12
12
|
const require_type_coerce = require('../coerce.js');
|
|
13
|
+
const require_type_elysia_file_type = require('../elysia/file-type.js');
|
|
13
14
|
const require_type_validator_default_precompute = require('./default-precompute.js');
|
|
14
15
|
const require_type_validator_custom_error = require('./custom-error.js');
|
|
15
16
|
const require_type_validator_exact_mirror = require('./exact-mirror.js');
|
|
16
17
|
const require_type_validator_validator_cache = require('./validator-cache.js');
|
|
17
|
-
let typebox_type = require("typebox/type");
|
|
18
|
-
let typebox_value = require("typebox/value");
|
|
19
|
-
let typebox_schema = require("typebox/schema");
|
|
20
18
|
|
|
21
19
|
//#region src/type/validator/index.ts
|
|
22
20
|
const moduleCache = /* @__PURE__ */ new WeakMap();
|
|
@@ -40,6 +38,19 @@ const freshRefineValidation = (groups) => {
|
|
|
40
38
|
checking: false
|
|
41
39
|
};
|
|
42
40
|
};
|
|
41
|
+
const UNAWAITED_REFINE = "[Elysia] t.Refine check must be synchronous";
|
|
42
|
+
const guardedChecks = /* @__PURE__ */ new WeakSet();
|
|
43
|
+
function guardRefinement(refinement) {
|
|
44
|
+
const check = refinement.check;
|
|
45
|
+
if (guardedChecks.has(check) || check["~elyAsyncRefine"] === true || require_type_shared.isPureRefinement(refinement)) return;
|
|
46
|
+
const guarded = function(value) {
|
|
47
|
+
const result = check.call(this, value);
|
|
48
|
+
if (typeof result?.then === "function") throw new Error(UNAWAITED_REFINE);
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
guardedChecks.add(guarded);
|
|
52
|
+
refinement.check = guarded;
|
|
53
|
+
}
|
|
43
54
|
function collectRefinements(schema, out = /* @__PURE__ */ new Set(), seen = /* @__PURE__ */ new WeakSet()) {
|
|
44
55
|
if (!schema || typeof schema !== "object" || seen.has(schema)) return out;
|
|
45
56
|
seen.add(schema);
|
|
@@ -48,7 +59,8 @@ function collectRefinements(schema, out = /* @__PURE__ */ new Set(), seen = /* @
|
|
|
48
59
|
let group = refinementGroups.get(refinements);
|
|
49
60
|
if (!group) {
|
|
50
61
|
const members = refinements.filter((refinement) => refinement && typeof refinement === "object" && typeof refinement.check === "function");
|
|
51
|
-
|
|
62
|
+
for (const refinement of members) guardRefinement(refinement);
|
|
63
|
+
if (members.length && !require_type_elysia_file_type.isAsyncPredicate(members)) {
|
|
52
64
|
group = {
|
|
53
65
|
checks: members.map((refinement) => refinement.check),
|
|
54
66
|
pure: members.every(require_type_shared.isPureRefinement)
|
|
@@ -84,6 +96,7 @@ function collectRefinements(schema, out = /* @__PURE__ */ new Set(), seen = /* @
|
|
|
84
96
|
if (slot.occurrences > slot.recorded) return true;
|
|
85
97
|
return slot.verdicts[slot.occurrences - 1][index];
|
|
86
98
|
};
|
|
99
|
+
guardedChecks.add(refinement.check);
|
|
87
100
|
}
|
|
88
101
|
}
|
|
89
102
|
}
|
|
@@ -120,20 +133,6 @@ function collectRefinements(schema, out = /* @__PURE__ */ new Set(), seen = /* @
|
|
|
120
133
|
]) if (Array.isArray(schema[key])) for (const child of schema[key]) collectRefinements(child, out, seen);
|
|
121
134
|
return out;
|
|
122
135
|
}
|
|
123
|
-
const materializeModels = (models) => {
|
|
124
|
-
const out = {};
|
|
125
|
-
for (const name in models) {
|
|
126
|
-
const schema = models[name];
|
|
127
|
-
const value = {};
|
|
128
|
-
let source = schema;
|
|
129
|
-
while (source && source !== Object.prototype) {
|
|
130
|
-
for (const key of Object.getOwnPropertyNames(source)) if (key !== "$id" && !Object.hasOwn(value, key)) Object.defineProperty(value, key, Object.getOwnPropertyDescriptor(source, key));
|
|
131
|
-
source = Object.getPrototypeOf(source);
|
|
132
|
-
}
|
|
133
|
-
out[name] = value;
|
|
134
|
-
}
|
|
135
|
-
return out;
|
|
136
|
-
};
|
|
137
136
|
function divergesFromEvaluate(node, seen) {
|
|
138
137
|
if (!node || typeof node !== "object" || seen.has(node)) return false;
|
|
139
138
|
seen.add(node);
|
|
@@ -183,7 +182,6 @@ function schemaMayHaveAsyncRefine(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
183
182
|
}
|
|
184
183
|
return false;
|
|
185
184
|
}
|
|
186
|
-
const schemaHasCustomError = (schema) => require_type_validator_clean_safe.schemaSome(schema, (node) => node.error !== void 0);
|
|
187
185
|
async function enforceFileTypeChecks(pending, type, value, schema) {
|
|
188
186
|
const results = await Promise.all(pending.map((x) => x.check));
|
|
189
187
|
for (let i = 0; i < results.length; i++) if (results[i] !== true) throw new require_error.ValidationError(type, value, [{
|
|
@@ -206,7 +204,24 @@ function findInstancePath(value, target, path = "") {
|
|
|
206
204
|
if (found !== void 0) return found;
|
|
207
205
|
}
|
|
208
206
|
}
|
|
207
|
+
function warnMirrorFailure(schema, error) {
|
|
208
|
+
console.warn("Failed to create exactMirror. Please report the following to https://github.com/elysiajs/elysia/issues");
|
|
209
|
+
let report;
|
|
210
|
+
try {
|
|
211
|
+
report = JSON.stringify(schema, (key, value) => key === "secrets" ? "[redacted]" : value);
|
|
212
|
+
} catch {
|
|
213
|
+
report = "[unserializable schema]";
|
|
214
|
+
}
|
|
215
|
+
console.warn(report);
|
|
216
|
+
console.warn(error);
|
|
217
|
+
}
|
|
218
|
+
let warnedMissingMirror = false;
|
|
209
219
|
var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
220
|
+
static member(schema, compiled) {
|
|
221
|
+
const isAsync = (compiled.buildResult ?? require_type_typebox_value.Build(schema)).external.variables.some(require_type_elysia_file_type.isAsyncPredicate);
|
|
222
|
+
collectRefinements(schema);
|
|
223
|
+
return isAsync;
|
|
224
|
+
}
|
|
210
225
|
#decodeMirror;
|
|
211
226
|
#encodeMirror;
|
|
212
227
|
#refinements;
|
|
@@ -229,41 +244,66 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
229
244
|
this.#hits = 0;
|
|
230
245
|
if (isIntersectable) {
|
|
231
246
|
const members = [schema, ...options.schemas];
|
|
232
|
-
schema = shallowMergeObjects(members) ??
|
|
247
|
+
schema = shallowMergeObjects(members) ?? require_type_typebox_type.Evaluate(require_type_typebox_type.Intersect(members));
|
|
233
248
|
}
|
|
234
249
|
const originalElyTyp = schema?.["~elyTyp"];
|
|
235
250
|
const rawSchema = schema;
|
|
236
251
|
const frozen = options?.aot && options.slot ? require_compile_aot.Compiled.getValidator(options.aot.method, options.aot.path, options.slot, options.app?.["~programId"]) : void 0;
|
|
237
252
|
let schemaHasRef = false;
|
|
238
253
|
if (name && options?.models) {
|
|
239
|
-
|
|
254
|
+
let modelModule = moduleCache.get(options.models);
|
|
255
|
+
if (modelModule === void 0) {
|
|
256
|
+
const models = options.models;
|
|
257
|
+
const out = {};
|
|
258
|
+
for (const modelName in models) {
|
|
259
|
+
const modelSchema = models[modelName];
|
|
260
|
+
const value = {};
|
|
261
|
+
let source = modelSchema;
|
|
262
|
+
while (source && source !== Object.prototype) {
|
|
263
|
+
for (const key of Object.getOwnPropertyNames(source)) if (key !== "$id" && !Object.hasOwn(value, key)) Object.defineProperty(value, key, Object.getOwnPropertyDescriptor(source, key));
|
|
264
|
+
source = Object.getPrototypeOf(source);
|
|
265
|
+
}
|
|
266
|
+
out[modelName] = value;
|
|
267
|
+
}
|
|
268
|
+
moduleCache.set(options.models, modelModule = require_type_typebox_type.Module(out));
|
|
269
|
+
}
|
|
270
|
+
schema = modelModule[name];
|
|
240
271
|
if (isIntersectable) {
|
|
241
272
|
const members = [schema, ...options.schemas];
|
|
242
|
-
schema = shallowMergeObjects(members) ??
|
|
273
|
+
schema = shallowMergeObjects(members) ?? require_type_typebox_type.Evaluate(require_type_typebox_type.Intersect(members));
|
|
243
274
|
}
|
|
244
275
|
} else if (options?.models && typeof name !== "string") {
|
|
245
|
-
schemaHasRef = frozen ? frozen.r === 1 : require_type_validator_clean_safe.
|
|
276
|
+
schemaHasRef = frozen ? frozen.r === 1 : require_type_validator_clean_safe.schemaSome(schema, (n) => !!n.$ref);
|
|
246
277
|
if (schemaHasRef) {
|
|
247
278
|
const id = `inline@${++inlineRefId}`;
|
|
248
|
-
schema =
|
|
279
|
+
schema = require_type_typebox_type.Module({
|
|
249
280
|
...options.models,
|
|
250
281
|
[id]: schema
|
|
251
282
|
})[id];
|
|
252
283
|
}
|
|
253
284
|
}
|
|
254
|
-
|
|
285
|
+
let isFrozen;
|
|
286
|
+
if (!options?.aot || !options.slot || options.normalize === "typebox") isFrozen = false;
|
|
287
|
+
else if (!frozen?.c && !frozen?.cm) isFrozen = false;
|
|
288
|
+
else {
|
|
289
|
+
this.isAsync = frozen.a === 1;
|
|
290
|
+
this.hasDefault = frozen.d === 1;
|
|
291
|
+
this.hasCodec = frozen.k === 1;
|
|
292
|
+
isFrozen = true;
|
|
293
|
+
}
|
|
255
294
|
this.schema = isFrozen && frozen.cp ? require_type_coerce.buildCoercedFromPlan(schema, frozen.cp) : isFrozen && !this.hasCodec ? schema : require_type_coerce.applyCoercions(schema, options?.coerces);
|
|
256
295
|
if (options?.normalize === false && options.slot !== "headers" && options.slot !== "cookie") this.schema = require_type_shared.nonAdditionalProperties(this.schema);
|
|
257
296
|
if (!isFrozen) {
|
|
258
297
|
const capturing = require_compile_aot.Capture.isCapturing();
|
|
259
|
-
this.hasCodec =
|
|
298
|
+
this.hasCodec = require_type_typebox_value.HasCodec(this.schema);
|
|
260
299
|
this.hasDefault = require_type_utils.hasProperty("default", this.schema);
|
|
261
|
-
if (!capturing && !options?.eager && !schemaMayHaveAsyncRefine(this.schema) && !
|
|
300
|
+
if (!capturing && !options?.eager && !schemaMayHaveAsyncRefine(this.schema) && !require_type_validator_clean_safe.schemaSome(this.schema, (node) => node.error !== void 0)) {
|
|
262
301
|
this.#deferred = true;
|
|
263
302
|
this.isAsync = false;
|
|
264
303
|
} else {
|
|
265
|
-
this.tb = capturing && require_compile_aot.captureImpl ? require_compile_aot.captureImpl.sourceOnlyValidator(this.schema) :
|
|
266
|
-
|
|
304
|
+
this.tb = capturing && require_compile_aot.captureImpl ? require_compile_aot.captureImpl.sourceOnlyValidator(this.schema) : require_type_typebox_value.SchemaCompile(this.schema);
|
|
305
|
+
const build = this.tb.buildResult ?? require_type_typebox_value.Build(this.schema);
|
|
306
|
+
this.isAsync = build.external.variables.some(require_type_elysia_file_type.isAsyncPredicate);
|
|
267
307
|
if (capturing && require_compile_aot.captureImpl && options?.aot && options.slot) require_compile_aot.captureImpl.maybeCapture({
|
|
268
308
|
aot: options.aot,
|
|
269
309
|
slot: options.slot,
|
|
@@ -275,15 +315,13 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
275
315
|
coerces: options.coerces,
|
|
276
316
|
normalize: options.normalize,
|
|
277
317
|
sanitize: options.sanitize,
|
|
278
|
-
buildResult:
|
|
318
|
+
buildResult: build
|
|
279
319
|
});
|
|
280
|
-
else if (!capturing)
|
|
320
|
+
else if (!capturing) require_type_shared.dropCompiledSource(this.tb);
|
|
281
321
|
}
|
|
282
322
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
if (refinements.size) this.#refinements = refinements;
|
|
286
|
-
}
|
|
323
|
+
const refinements = collectRefinements(this.schema);
|
|
324
|
+
if (!this.isAsync && refinements.size) this.#refinements = refinements;
|
|
287
325
|
if (frozen?.ps === 1) {
|
|
288
326
|
const objectTemplate = frozen.pod !== void 0 ? Object.freeze(frozen.pod) : void 0;
|
|
289
327
|
this.precomputeSafe = true;
|
|
@@ -299,6 +337,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
299
337
|
if (defaults) {
|
|
300
338
|
this.precomputeSafe = true;
|
|
301
339
|
const objectTemplate = defaults.pod !== void 0 ? Object.freeze(defaults.pod) : void 0;
|
|
340
|
+
const failures = require_type_validator_default_precompute.precomputeCompileFailures();
|
|
302
341
|
this.#defaultFastPath = {
|
|
303
342
|
value: defaults.pd,
|
|
304
343
|
appliesToNull: defaults.pn,
|
|
@@ -306,6 +345,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
306
345
|
clone: defaults.pd !== void 0 ? require_type_validator_default_precompute.createDefaultCloner(defaults.pd) : void 0,
|
|
307
346
|
merge: defaults.ms ? require_type_validator_default_precompute.createMergerFromSource(defaults.ms) : objectTemplate !== void 0 ? require_type_validator_default_precompute.createObjectDefaultMerger(objectTemplate) : void 0
|
|
308
347
|
};
|
|
348
|
+
if (require_type_validator_default_precompute.precomputeCompileFailures() !== failures) this.precomputeSafe = false;
|
|
309
349
|
} else {
|
|
310
350
|
this.precomputeSafe = false;
|
|
311
351
|
this.#defaultFastPath = void 0;
|
|
@@ -318,30 +358,60 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
318
358
|
if (isFrozen && frozen.cm) {
|
|
319
359
|
const both = require_compile_aot.reconstruct().instantiateFrozenBoth(frozen, this.schema, schema);
|
|
320
360
|
this.reconstructedCheck = both.check;
|
|
321
|
-
this.Clean = options?.normalize === false ? void 0 : require_type_validator_clean_safe.schemaHasDangerousProperties(this.schema) ? (value) =>
|
|
361
|
+
this.Clean = options?.normalize === false ? void 0 : require_type_validator_clean_safe.schemaHasDangerousProperties(this.schema) ? (value) => require_type_typebox_value.Clean(this.schema, value) : both.clean;
|
|
322
362
|
} else {
|
|
323
363
|
if (isFrozen) this.reconstructedCheck = frozen.c(frozen.e ? require_compile_aot.reconstruct().collectExternals(this.schema) : require_compile_aot.EMPTY_EXTERNALS);
|
|
324
|
-
if (!require_type_validator_exact_mirror.getExactMirror() && !frozen?.m && !require_type_validator_clean_safe.schemaHasDangerousProperties(this.schema) && options?.normalize !== false && options?.normalize !== "typebox"
|
|
364
|
+
if (!require_type_validator_exact_mirror.getExactMirror() && !frozen?.m && !require_type_validator_clean_safe.schemaHasDangerousProperties(this.schema) && options?.normalize !== false && options?.normalize !== "typebox") {
|
|
365
|
+
if (options?.normalize === "exactMirror" || options?.sanitize) throw require_type_validator_exact_mirror.exactMirrorRequired();
|
|
366
|
+
if (options?.normalize === true && !warnedMissingMirror) {
|
|
367
|
+
warnedMissingMirror = true;
|
|
368
|
+
console.warn("exact-mirror is unavailable, normalization degraded to TypeBox. Install exact-mirror, or bundle it statically with the AOT build plugin ('elysia/plugin/aot') to restore the fast path. Use normalize: 'typebox' to silence this.");
|
|
369
|
+
}
|
|
370
|
+
}
|
|
325
371
|
try {
|
|
326
|
-
|
|
372
|
+
if (options?.normalize === false) this.Clean = void 0;
|
|
373
|
+
else if (options?.normalize === "typebox") this.Clean = (value) => require_type_typebox_value.Clean(this.schema, value);
|
|
374
|
+
else if (require_type_validator_clean_safe.schemaHasDangerousProperties(this.schema)) this.Clean = (value) => require_type_typebox_value.Clean(this.schema, value);
|
|
375
|
+
else {
|
|
376
|
+
const aot = options?.aot;
|
|
377
|
+
const slot = options?.slot;
|
|
378
|
+
if (aot && slot && frozen?.m) {
|
|
379
|
+
const m = frozen.m;
|
|
380
|
+
let clean;
|
|
381
|
+
this.Clean = (value) => {
|
|
382
|
+
if (clean === void 0) try {
|
|
383
|
+
clean = require_compile_aot.reconstruct().instantiateFrozenMirror(m, schema);
|
|
384
|
+
} catch (error) {
|
|
385
|
+
warnMirrorFailure(schema, error);
|
|
386
|
+
clean = (v) => v;
|
|
387
|
+
}
|
|
388
|
+
return clean(value);
|
|
389
|
+
};
|
|
390
|
+
} else {
|
|
391
|
+
if (aot && slot && require_compile_aot.Capture.isCapturing() && require_compile_aot.captureImpl) require_compile_aot.captureImpl.captureMirror(schema, aot, slot, options?.sanitize);
|
|
392
|
+
const createMirror = require_type_validator_exact_mirror.getExactMirror();
|
|
393
|
+
this.Clean = !createMirror ? (value) => require_type_typebox_value.Clean(this.schema, value) : createMirror(schema, {
|
|
394
|
+
Compile: require_type_typebox_value.SchemaCompile,
|
|
395
|
+
sanitize: options?.sanitize
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}
|
|
327
399
|
} catch (error) {
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
console.warn(error);
|
|
331
|
-
if (options?.normalize !== false) this.Clean = (value) => (0, typebox_value.Clean)(this.schema, value);
|
|
400
|
+
warnMirrorFailure(schema, error);
|
|
401
|
+
if (options?.normalize !== false) this.Clean = (value) => require_type_typebox_value.Clean(this.schema, value);
|
|
332
402
|
}
|
|
333
403
|
}
|
|
334
404
|
this.#cleanRedundant = !!this.Clean && !options?.sanitize && options?.normalize !== "typebox" && require_type_validator_clean_safe.isFullyClosedObject(this.schema);
|
|
335
|
-
if (this.hasCodec && !this.#isForm && !this.#noValidate &&
|
|
336
|
-
|
|
405
|
+
if (this.hasCodec && !this.#isForm && !this.#noValidate && options?.normalize !== false && options?.normalize !== "typebox") if (options?.slot?.startsWith("r")) this.#encodeMirror = this.#setupCodecMirror(this.schema, options, frozen, "encode");
|
|
406
|
+
else this.#decodeMirror = this.#setupCodecMirror(this.schema, options, frozen, "decode");
|
|
337
407
|
if (!this.#noValidate) this.#findCustomError = require_type_validator_custom_error.buildFindCustomError(this.schema, frozen);
|
|
338
408
|
if (options?.aot && options.slot && require_compile_aot.Capture.isCapturing() && require_compile_aot.captureImpl) require_compile_aot.captureImpl.captureBridgeFree(options.aot, options.slot, rawSchema);
|
|
339
409
|
}
|
|
340
410
|
#error(value, type, errors) {
|
|
341
411
|
return new require_error.ValidationError(type, value, errors ?? (() => this.Errors(value)), this.schema, this.#findCustomError);
|
|
342
412
|
}
|
|
343
|
-
#validate(value) {
|
|
344
|
-
if (!this.#refinements) return this.Check(value) ? void 0 : [];
|
|
413
|
+
#validate(value, countHit = true) {
|
|
414
|
+
if (!this.#refinements) return (countHit ? this.Check(value) : this.#check(value, false)) ? void 0 : [];
|
|
345
415
|
const pool = this.#refineScratch ??= freshRefineValidation(this.#refinements);
|
|
346
416
|
const usingPool = !pool.active;
|
|
347
417
|
const validation = usingPool ? pool : freshRefineValidation(this.#refinements);
|
|
@@ -351,7 +421,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
351
421
|
validation.replay = false;
|
|
352
422
|
activeRefineValidation = validation;
|
|
353
423
|
try {
|
|
354
|
-
if (this.Check(value)) return;
|
|
424
|
+
if (countHit ? this.Check(value) : this.#check(value, false)) return;
|
|
355
425
|
validation.replay = true;
|
|
356
426
|
validation.replayEpoch++;
|
|
357
427
|
return this.Errors(value);
|
|
@@ -360,33 +430,6 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
360
430
|
if (usingPool) pool.active = false;
|
|
361
431
|
}
|
|
362
432
|
}
|
|
363
|
-
#setupMirror(schema, options, frozen) {
|
|
364
|
-
if (require_type_validator_clean_safe.schemaHasDangerousProperties(this.schema)) return (value) => (0, typebox_value.Clean)(this.schema, value);
|
|
365
|
-
const aot = options?.aot;
|
|
366
|
-
const slot = options?.slot;
|
|
367
|
-
if (aot && slot && frozen?.m) {
|
|
368
|
-
const m = frozen.m;
|
|
369
|
-
let clean;
|
|
370
|
-
return (value) => {
|
|
371
|
-
if (clean === void 0) try {
|
|
372
|
-
clean = require_compile_aot.reconstruct().instantiateFrozenMirror(m, schema);
|
|
373
|
-
} catch (error) {
|
|
374
|
-
console.warn("Failed to create exactMirror. Please report the following code to https://github.com/elysiajs/elysia/issues");
|
|
375
|
-
console.warn(schema);
|
|
376
|
-
console.warn(error);
|
|
377
|
-
clean = (v) => v;
|
|
378
|
-
}
|
|
379
|
-
return clean(value);
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
if (aot && slot && require_compile_aot.Capture.isCapturing() && require_compile_aot.captureImpl) require_compile_aot.captureImpl.captureMirror(schema, aot, slot, options?.sanitize);
|
|
383
|
-
const createMirror = require_type_validator_exact_mirror.getExactMirror();
|
|
384
|
-
if (!createMirror) return (value) => (0, typebox_value.Clean)(this.schema, value);
|
|
385
|
-
return createMirror(schema, {
|
|
386
|
-
Compile: typebox_schema.Compile,
|
|
387
|
-
sanitize: options?.sanitize
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
433
|
#setupCodecMirror(schema, options, frozen, dir) {
|
|
391
434
|
if (require_type_validator_clean_safe.schemaHasDangerousProperties(this.schema)) return;
|
|
392
435
|
const aot = options?.aot;
|
|
@@ -400,10 +443,10 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
400
443
|
run = require_compile_aot.reconstruct().instantiateFrozenDecodeMirror(m, schema, dir);
|
|
401
444
|
} catch {
|
|
402
445
|
run = dir === "decode" ? (v) => {
|
|
403
|
-
const decoded =
|
|
446
|
+
const decoded = require_type_typebox_value.DecodeUnsafe(require_utils.nullObject(), schema, v);
|
|
404
447
|
return this.Clean ? this.Clean(decoded) : decoded;
|
|
405
448
|
} : (v) => {
|
|
406
|
-
const out =
|
|
449
|
+
const out = require_type_typebox_value.Encode(schema, v);
|
|
407
450
|
return this.Clean ? this.Clean(out) : out;
|
|
408
451
|
};
|
|
409
452
|
}
|
|
@@ -417,14 +460,17 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
417
460
|
if (!createMirror) return;
|
|
418
461
|
try {
|
|
419
462
|
return createMirror(schema, {
|
|
420
|
-
Compile:
|
|
463
|
+
Compile: require_type_typebox_value.SchemaCompile,
|
|
421
464
|
sanitize: options?.sanitize,
|
|
422
465
|
...dirOpt
|
|
423
466
|
});
|
|
424
467
|
} catch {}
|
|
425
468
|
}
|
|
426
469
|
Check(value) {
|
|
427
|
-
this.#
|
|
470
|
+
return this.#check(value, true);
|
|
471
|
+
}
|
|
472
|
+
#check(value, countHit) {
|
|
473
|
+
if (countHit) this.#tick();
|
|
428
474
|
const pool = this.#refineScratch;
|
|
429
475
|
if (pool?.active && this.#refinements) {
|
|
430
476
|
if (pool.checking) {
|
|
@@ -447,7 +493,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
447
493
|
}
|
|
448
494
|
#rawCheck(value) {
|
|
449
495
|
if (this.reconstructedCheck) return this.reconstructedCheck(value);
|
|
450
|
-
if (this.#deferred) return
|
|
496
|
+
if (this.#deferred) return require_type_typebox_value.Check(this.schema, value);
|
|
451
497
|
return this.tb.Check(value);
|
|
452
498
|
}
|
|
453
499
|
#tick() {
|
|
@@ -457,64 +503,48 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
457
503
|
* Promote a deferred validator to the compiled `Check` fast path
|
|
458
504
|
*/
|
|
459
505
|
#materialize() {
|
|
460
|
-
const tb =
|
|
506
|
+
const tb = require_type_typebox_value.SchemaCompile(this.schema);
|
|
461
507
|
this.tb = tb;
|
|
462
|
-
|
|
508
|
+
require_type_shared.dropCompiledSource(tb);
|
|
463
509
|
this.#deferred = false;
|
|
464
510
|
}
|
|
465
|
-
#reconstruct(options, frozen) {
|
|
466
|
-
if (!options?.aot || !options.slot || options.normalize === "typebox") return false;
|
|
467
|
-
if (!frozen?.c && !frozen?.cm) return false;
|
|
468
|
-
this.isAsync = frozen.a === 1;
|
|
469
|
-
this.hasDefault = frozen.d === 1;
|
|
470
|
-
this.hasCodec = frozen.k === 1;
|
|
471
|
-
return true;
|
|
472
|
-
}
|
|
473
|
-
#dropCompiledSource() {
|
|
474
|
-
const tb = this.tb;
|
|
475
|
-
if (!tb) return;
|
|
476
|
-
if (tb.evaluateResult) tb.evaluateResult.code = void 0;
|
|
477
|
-
if (tb.buildResult) tb.buildResult.functions = void 0;
|
|
478
|
-
}
|
|
479
511
|
Errors(value) {
|
|
480
|
-
return
|
|
512
|
+
return require_type_typebox_value.Errors(this.schema, value);
|
|
481
513
|
}
|
|
482
514
|
Decode(value) {
|
|
483
|
-
return
|
|
515
|
+
return require_type_typebox_value.Decode(this.schema, value);
|
|
484
516
|
}
|
|
485
517
|
Encode(value) {
|
|
486
|
-
return this.hasCodec ?
|
|
518
|
+
return this.hasCodec ? require_type_typebox_value.Encode(this.schema, value) : value;
|
|
487
519
|
}
|
|
488
520
|
EncodeFrom(value, type) {
|
|
489
521
|
this.#tick();
|
|
490
|
-
if (this.#isForm) {
|
|
491
|
-
const errors = this.#noValidate ? void 0 : this.#validate(value);
|
|
492
|
-
if (errors) throw this.#error(value, type, errors.length ? errors : void 0);
|
|
493
|
-
return value;
|
|
494
|
-
}
|
|
495
|
-
if (!this.hasCodec) {
|
|
496
|
-
const errors = this.#noValidate ? void 0 : this.#validate(value);
|
|
522
|
+
if (this.#isForm || !this.hasCodec) {
|
|
523
|
+
const errors = this.#noValidate ? void 0 : this.#validate(value, false);
|
|
497
524
|
if (errors) throw this.#error(value, type, errors.length ? errors : void 0);
|
|
498
|
-
if (this.Clean) value = this.Clean(value);
|
|
525
|
+
if (this.Clean && !this.#isForm) value = this.Clean(value);
|
|
499
526
|
return value;
|
|
500
527
|
}
|
|
501
528
|
try {
|
|
502
529
|
if (this.#encodeMirror) {
|
|
503
530
|
const out = this.#encodeMirror(value);
|
|
504
|
-
const errors = this.#noValidate ? void 0 : this.#validate(out);
|
|
531
|
+
const errors = this.#noValidate ? void 0 : this.#validate(out, false);
|
|
505
532
|
if (errors) throw new require_error.ValidationError(type, out, errors.length ? errors : () => this.Errors(out), this.schema);
|
|
506
533
|
return out;
|
|
507
534
|
}
|
|
508
|
-
const out = this.#noValidate ?
|
|
535
|
+
const out = this.#noValidate ? require_type_typebox_value.EncodeUnsafe(require_utils.nullObject(), this.schema, value) : require_type_typebox_value.Encode(this.schema, value);
|
|
509
536
|
return this.Clean ? this.Clean(out) : out;
|
|
510
537
|
} catch (e) {
|
|
511
538
|
if (this.#noValidate) return this.Clean ? this.Clean(value) : value;
|
|
512
|
-
|
|
513
|
-
if (e?.error) throw e.error;
|
|
514
|
-
if (e?.status) throw e;
|
|
515
|
-
throw new require_error.ValidationError(type, value, () => this.Errors(value), this.schema);
|
|
539
|
+
this.#rethrow(e, value, type);
|
|
516
540
|
}
|
|
517
541
|
}
|
|
542
|
+
#rethrow(e, value, type) {
|
|
543
|
+
if (e instanceof require_error.ValidationError) throw e;
|
|
544
|
+
if (e?.error) throw e.error;
|
|
545
|
+
if (e?.status) throw e;
|
|
546
|
+
throw new require_error.ValidationError(type, value, () => this.Errors(value), this.schema);
|
|
547
|
+
}
|
|
518
548
|
#markForm(value) {
|
|
519
549
|
if (this.#isForm && value !== null && typeof value === "object") {
|
|
520
550
|
const previous = Object.getPrototypeOf(value);
|
|
@@ -541,6 +571,15 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
541
571
|
if (Array.isArray(value)) return value;
|
|
542
572
|
return require_type_validator_default_precompute.applyPrecomputed(defaults.objectTemplate, value);
|
|
543
573
|
}
|
|
574
|
+
#applyDefault(value) {
|
|
575
|
+
const defaults = this.#defaultFastPath;
|
|
576
|
+
if (defaults) {
|
|
577
|
+
if (value === void 0 || value === null && defaults.appliesToNull) return this.#cloneSharedDefault();
|
|
578
|
+
if (value !== null && typeof value === "object" && (defaults.merge !== void 0 || defaults.objectTemplate !== void 0)) return this.#applyPrecomputedObjectDefault(value);
|
|
579
|
+
return value;
|
|
580
|
+
}
|
|
581
|
+
return require_type_typebox_value.Default(this.schema, value);
|
|
582
|
+
}
|
|
544
583
|
optionalBypass(value) {
|
|
545
584
|
const schema = this.schema;
|
|
546
585
|
if (!schema?.["~optional"]) return;
|
|
@@ -554,13 +593,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
554
593
|
};
|
|
555
594
|
}
|
|
556
595
|
async FromAsync(value, type) {
|
|
557
|
-
if (this.hasDefault)
|
|
558
|
-
const defaults = this.#defaultFastPath;
|
|
559
|
-
if (defaults) {
|
|
560
|
-
if (value === void 0 || value === null && defaults.appliesToNull) value = this.#cloneSharedDefault();
|
|
561
|
-
else if (value !== null && typeof value === "object" && (defaults.merge !== void 0 || defaults.objectTemplate !== void 0)) value = this.#applyPrecomputedObjectDefault(value);
|
|
562
|
-
} else value = (0, typebox_value.Default)(this.schema, value);
|
|
563
|
-
}
|
|
596
|
+
if (this.hasDefault) value = this.#applyDefault(value);
|
|
564
597
|
if (this.#hasOptional) {
|
|
565
598
|
const bypass = this.optionalBypass(value);
|
|
566
599
|
if (bypass) return bypass.value;
|
|
@@ -568,29 +601,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
568
601
|
const markedValue = value;
|
|
569
602
|
const marked = this.#isForm ? this.#markForm(value) : void 0;
|
|
570
603
|
try {
|
|
571
|
-
if (this
|
|
572
|
-
if (!this.#noValidate) {
|
|
573
|
-
require_type_elysia_file_type.collectFileTypeChecks();
|
|
574
|
-
let errors;
|
|
575
|
-
let pendingFile;
|
|
576
|
-
try {
|
|
577
|
-
errors = this.#validate(value);
|
|
578
|
-
} finally {
|
|
579
|
-
pendingFile = require_type_elysia_file_type.takeFileTypeChecks();
|
|
580
|
-
}
|
|
581
|
-
if (errors) throw this.#error(value, type, errors.length ? errors : void 0);
|
|
582
|
-
if (pendingFile) await enforceFileTypeChecks(pendingFile, type, value, this.schema);
|
|
583
|
-
}
|
|
584
|
-
if (this.#decodeMirror) value = this.#decodeMirror(value);
|
|
585
|
-
else try {
|
|
586
|
-
value = (0, typebox_value.DecodeUnsafe)(require_utils.nullObject(), this.schema, value);
|
|
587
|
-
} catch (e) {
|
|
588
|
-
if (e instanceof require_error.ValidationError) throw e;
|
|
589
|
-
if (e?.error) throw e.error;
|
|
590
|
-
if (e?.status) throw e;
|
|
591
|
-
throw new require_error.ValidationError(type, value, () => this.Errors(value), this.schema);
|
|
592
|
-
}
|
|
593
|
-
} else if (!this.#noValidate) {
|
|
604
|
+
if (!this.#noValidate) {
|
|
594
605
|
require_type_elysia_file_type.collectFileTypeChecks();
|
|
595
606
|
let errors;
|
|
596
607
|
let pendingFile;
|
|
@@ -602,6 +613,12 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
602
613
|
if (errors) throw this.#error(value, type, errors.length ? errors : void 0);
|
|
603
614
|
if (pendingFile) await enforceFileTypeChecks(pendingFile, type, value, this.schema);
|
|
604
615
|
}
|
|
616
|
+
if (this.hasCodec) if (this.#decodeMirror) value = this.#decodeMirror(value);
|
|
617
|
+
else try {
|
|
618
|
+
value = require_type_typebox_value.DecodeUnsafe(require_utils.nullObject(), this.schema, value);
|
|
619
|
+
} catch (e) {
|
|
620
|
+
this.#rethrow(e, value, type);
|
|
621
|
+
}
|
|
605
622
|
if (this.Clean && !this.#decodeMirror && !this.#cleanRedundant) value = this.Clean(value);
|
|
606
623
|
return value;
|
|
607
624
|
} finally {
|
|
@@ -609,13 +626,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
609
626
|
}
|
|
610
627
|
}
|
|
611
628
|
FromSync(value, type) {
|
|
612
|
-
if (this.hasDefault)
|
|
613
|
-
const defaults = this.#defaultFastPath;
|
|
614
|
-
if (defaults) {
|
|
615
|
-
if (value === void 0 || value === null && defaults.appliesToNull) value = this.#cloneSharedDefault();
|
|
616
|
-
else if (value !== null && typeof value === "object" && (defaults.merge !== void 0 || defaults.objectTemplate !== void 0)) value = this.#applyPrecomputedObjectDefault(value);
|
|
617
|
-
} else value = (0, typebox_value.Default)(this.schema, value);
|
|
618
|
-
}
|
|
629
|
+
if (this.hasDefault) value = this.#applyDefault(value);
|
|
619
630
|
if (this.#hasOptional) {
|
|
620
631
|
const bypass = this.optionalBypass(value);
|
|
621
632
|
if (bypass) return bypass.value;
|
|
@@ -623,21 +634,13 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
623
634
|
const markedValue = value;
|
|
624
635
|
const marked = this.#isForm ? this.#markForm(value) : void 0;
|
|
625
636
|
try {
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
if (e instanceof require_error.ValidationError) throw e;
|
|
634
|
-
if (e?.error) throw e.error;
|
|
635
|
-
if (e?.status) throw e;
|
|
636
|
-
throw new require_error.ValidationError(type, value, () => this.Errors(value), this.schema);
|
|
637
|
-
}
|
|
638
|
-
} else {
|
|
639
|
-
const errors = this.#noValidate ? void 0 : this.#validate(value);
|
|
640
|
-
if (errors) throw this.#error(value, type, errors.length ? errors : void 0);
|
|
637
|
+
const errors = this.#noValidate ? void 0 : this.#validate(value);
|
|
638
|
+
if (errors) throw this.#error(value, type, errors.length ? errors : void 0);
|
|
639
|
+
if (this.hasCodec) if (this.#decodeMirror) value = this.#decodeMirror(value);
|
|
640
|
+
else try {
|
|
641
|
+
value = require_type_typebox_value.DecodeUnsafe(require_utils.nullObject(), this.schema, value);
|
|
642
|
+
} catch (e) {
|
|
643
|
+
this.#rethrow(e, value, type);
|
|
641
644
|
}
|
|
642
645
|
if (this.Clean && !this.#decodeMirror && !this.#cleanRedundant) value = this.Clean(value);
|
|
643
646
|
return value;
|