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
|
@@ -2,19 +2,19 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_constants = require('../../constants.js');
|
|
3
3
|
|
|
4
4
|
//#region src/type/validator/clean-safe.ts
|
|
5
|
-
function schemaSome(schema, test, seen = /* @__PURE__ */ new WeakSet(), prune) {
|
|
5
|
+
function schemaSome(schema, test, seen = /* @__PURE__ */ new WeakSet(), prune, conditional = false) {
|
|
6
6
|
if (!schema || typeof schema !== "object" || seen.has(schema)) return false;
|
|
7
7
|
seen.add(schema);
|
|
8
8
|
if (test(schema)) return true;
|
|
9
9
|
if (prune && prune(schema)) return false;
|
|
10
10
|
const props = schema.properties;
|
|
11
11
|
if (props) {
|
|
12
|
-
for (const k in props) if (Object.hasOwn(props, k) && schemaSome(props[k], test, seen, prune)) return true;
|
|
12
|
+
for (const k in props) if ((conditional || Object.hasOwn(props, k)) && schemaSome(props[k], test, seen, prune, conditional)) return true;
|
|
13
13
|
}
|
|
14
14
|
const items = schema.items;
|
|
15
15
|
if (Array.isArray(items)) {
|
|
16
|
-
for (const it of items) if (schemaSome(it, test, seen, prune)) return true;
|
|
17
|
-
} else if (items && schemaSome(items, test, seen, prune)) return true;
|
|
16
|
+
for (const it of items) if (schemaSome(it, test, seen, prune, conditional)) return true;
|
|
17
|
+
} else if (items && schemaSome(items, test, seen, prune, conditional)) return true;
|
|
18
18
|
for (const k of [
|
|
19
19
|
"anyOf",
|
|
20
20
|
"allOf",
|
|
@@ -22,14 +22,21 @@ function schemaSome(schema, test, seen = /* @__PURE__ */ new WeakSet(), prune) {
|
|
|
22
22
|
]) {
|
|
23
23
|
const arr = schema[k];
|
|
24
24
|
if (Array.isArray(arr)) {
|
|
25
|
-
for (const x of arr) if (schemaSome(x, test, seen, prune)) return true;
|
|
25
|
+
for (const x of arr) if (schemaSome(x, test, seen, prune, conditional)) return true;
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
if (schema.additionalProperties && typeof schema.additionalProperties === "object" && schemaSome(schema.additionalProperties, test, seen, prune)) return true;
|
|
29
|
-
if (schema.not && schemaSome(schema.not, test, seen, prune)) return true;
|
|
28
|
+
if (schema.additionalProperties && typeof schema.additionalProperties === "object" && schemaSome(schema.additionalProperties, test, seen, prune, conditional)) return true;
|
|
29
|
+
if (schema.not && schemaSome(schema.not, test, seen, prune, conditional)) return true;
|
|
30
|
+
if (conditional) {
|
|
31
|
+
for (const k of [
|
|
32
|
+
"if",
|
|
33
|
+
"then",
|
|
34
|
+
"else"
|
|
35
|
+
]) if (schema[k] && schemaSome(schema[k], test, seen, prune, true)) return true;
|
|
36
|
+
}
|
|
30
37
|
const pp = schema.patternProperties;
|
|
31
38
|
if (pp) {
|
|
32
|
-
for (const k in pp) if (schemaSome(pp[k], test, seen, prune)) return true;
|
|
39
|
+
for (const k in pp) if (schemaSome(pp[k], test, seen, prune, conditional)) return true;
|
|
33
40
|
}
|
|
34
41
|
return false;
|
|
35
42
|
}
|
|
@@ -39,7 +46,6 @@ const schemaHasDangerousProperties = (schema) => schemaSome(schema, (node) => {
|
|
|
39
46
|
for (const key of require_constants.dangerousKeys) if (Object.hasOwn(properties, key)) return true;
|
|
40
47
|
return false;
|
|
41
48
|
});
|
|
42
|
-
const schemaContainsRef = (node, seen = /* @__PURE__ */ new WeakSet()) => schemaSome(node, (n) => !!n.$ref, seen);
|
|
43
49
|
function isCleanSafeNode(node, visiting, clean) {
|
|
44
50
|
if (!node || typeof node !== "object") return true;
|
|
45
51
|
if (clean.has(node)) return true;
|
|
@@ -75,8 +81,6 @@ function isFullyClosedObject(schema) {
|
|
|
75
81
|
}
|
|
76
82
|
|
|
77
83
|
//#endregion
|
|
78
|
-
exports.isCleanSafeNode = isCleanSafeNode;
|
|
79
84
|
exports.isFullyClosedObject = isFullyClosedObject;
|
|
80
|
-
exports.schemaContainsRef = schemaContainsRef;
|
|
81
85
|
exports.schemaHasDangerousProperties = schemaHasDangerousProperties;
|
|
82
86
|
exports.schemaSome = schemaSome;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { dangerousKeys } from "../../constants.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/type/validator/clean-safe.ts
|
|
4
|
-
function schemaSome(schema, test, seen = /* @__PURE__ */ new WeakSet(), prune) {
|
|
4
|
+
function schemaSome(schema, test, seen = /* @__PURE__ */ new WeakSet(), prune, conditional = false) {
|
|
5
5
|
if (!schema || typeof schema !== "object" || seen.has(schema)) return false;
|
|
6
6
|
seen.add(schema);
|
|
7
7
|
if (test(schema)) return true;
|
|
8
8
|
if (prune && prune(schema)) return false;
|
|
9
9
|
const props = schema.properties;
|
|
10
10
|
if (props) {
|
|
11
|
-
for (const k in props) if (Object.hasOwn(props, k) && schemaSome(props[k], test, seen, prune)) return true;
|
|
11
|
+
for (const k in props) if ((conditional || Object.hasOwn(props, k)) && schemaSome(props[k], test, seen, prune, conditional)) return true;
|
|
12
12
|
}
|
|
13
13
|
const items = schema.items;
|
|
14
14
|
if (Array.isArray(items)) {
|
|
15
|
-
for (const it of items) if (schemaSome(it, test, seen, prune)) return true;
|
|
16
|
-
} else if (items && schemaSome(items, test, seen, prune)) return true;
|
|
15
|
+
for (const it of items) if (schemaSome(it, test, seen, prune, conditional)) return true;
|
|
16
|
+
} else if (items && schemaSome(items, test, seen, prune, conditional)) return true;
|
|
17
17
|
for (const k of [
|
|
18
18
|
"anyOf",
|
|
19
19
|
"allOf",
|
|
@@ -21,14 +21,21 @@ function schemaSome(schema, test, seen = /* @__PURE__ */ new WeakSet(), prune) {
|
|
|
21
21
|
]) {
|
|
22
22
|
const arr = schema[k];
|
|
23
23
|
if (Array.isArray(arr)) {
|
|
24
|
-
for (const x of arr) if (schemaSome(x, test, seen, prune)) return true;
|
|
24
|
+
for (const x of arr) if (schemaSome(x, test, seen, prune, conditional)) return true;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
if (schema.additionalProperties && typeof schema.additionalProperties === "object" && schemaSome(schema.additionalProperties, test, seen, prune)) return true;
|
|
28
|
-
if (schema.not && schemaSome(schema.not, test, seen, prune)) return true;
|
|
27
|
+
if (schema.additionalProperties && typeof schema.additionalProperties === "object" && schemaSome(schema.additionalProperties, test, seen, prune, conditional)) return true;
|
|
28
|
+
if (schema.not && schemaSome(schema.not, test, seen, prune, conditional)) return true;
|
|
29
|
+
if (conditional) {
|
|
30
|
+
for (const k of [
|
|
31
|
+
"if",
|
|
32
|
+
"then",
|
|
33
|
+
"else"
|
|
34
|
+
]) if (schema[k] && schemaSome(schema[k], test, seen, prune, true)) return true;
|
|
35
|
+
}
|
|
29
36
|
const pp = schema.patternProperties;
|
|
30
37
|
if (pp) {
|
|
31
|
-
for (const k in pp) if (schemaSome(pp[k], test, seen, prune)) return true;
|
|
38
|
+
for (const k in pp) if (schemaSome(pp[k], test, seen, prune, conditional)) return true;
|
|
32
39
|
}
|
|
33
40
|
return false;
|
|
34
41
|
}
|
|
@@ -38,7 +45,6 @@ const schemaHasDangerousProperties = (schema) => schemaSome(schema, (node) => {
|
|
|
38
45
|
for (const key of dangerousKeys) if (Object.hasOwn(properties, key)) return true;
|
|
39
46
|
return false;
|
|
40
47
|
});
|
|
41
|
-
const schemaContainsRef = (node, seen = /* @__PURE__ */ new WeakSet()) => schemaSome(node, (n) => !!n.$ref, seen);
|
|
42
48
|
function isCleanSafeNode(node, visiting, clean) {
|
|
43
49
|
if (!node || typeof node !== "object") return true;
|
|
44
50
|
if (clean.has(node)) return true;
|
|
@@ -74,4 +80,4 @@ function isFullyClosedObject(schema) {
|
|
|
74
80
|
}
|
|
75
81
|
|
|
76
82
|
//#endregion
|
|
77
|
-
export {
|
|
83
|
+
export { isFullyClosedObject, schemaHasDangerousProperties, schemaSome };
|
|
@@ -1,10 +1,9 @@
|
|
|
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_error = require('../../error.js');
|
|
5
4
|
const require_compile_aot = require('../../compile/aot.js');
|
|
5
|
+
const require_type_typebox_value = require('../typebox-value.js');
|
|
6
6
|
const require_type_validator_frozen_check = require('./frozen-check.js');
|
|
7
|
-
let typebox_schema = require("typebox/schema");
|
|
8
7
|
|
|
9
8
|
//#region src/type/validator/custom-error.ts
|
|
10
9
|
function encodePointer(segments) {
|
|
@@ -50,18 +49,17 @@ const literalOf = (propSchema) => {
|
|
|
50
49
|
if ("const" in propSchema) return { value: propSchema.const };
|
|
51
50
|
if (Array.isArray(propSchema.enum) && propSchema.enum.length === 1) return { value: propSchema.enum[0] };
|
|
52
51
|
};
|
|
53
|
-
|
|
52
|
+
const findDiscriminators = (branches) => {
|
|
54
53
|
let candidates;
|
|
55
54
|
for (const branch of branches) {
|
|
56
|
-
if (!branch
|
|
55
|
+
if (!branch?.properties) return null;
|
|
57
56
|
const keys = /* @__PURE__ */ new Set();
|
|
58
57
|
for (const k in branch.properties) if (literalOf(branch.properties[k])) keys.add(k);
|
|
59
|
-
if (!keys.size) return;
|
|
60
58
|
if (!candidates) candidates = keys;
|
|
61
59
|
else for (const c of [...candidates]) if (!keys.has(c)) candidates.delete(c);
|
|
62
|
-
if (!candidates.size) return;
|
|
60
|
+
if (!candidates.size) return null;
|
|
63
61
|
}
|
|
64
|
-
if (!candidates
|
|
62
|
+
if (!candidates) return null;
|
|
65
63
|
const perBranch = branches.map(require_utils.nullObject);
|
|
66
64
|
let hasDisambiguating = false;
|
|
67
65
|
for (const key of candidates) {
|
|
@@ -73,8 +71,8 @@ function computeDiscriminators(branches) {
|
|
|
73
71
|
}
|
|
74
72
|
if (new Set(seenValues).size === branches.length) hasDisambiguating = true;
|
|
75
73
|
}
|
|
76
|
-
return hasDisambiguating ? perBranch :
|
|
77
|
-
}
|
|
74
|
+
return hasDisambiguating ? perBranch : null;
|
|
75
|
+
};
|
|
78
76
|
function buildFindCustomError(schema, frozen) {
|
|
79
77
|
const nodes = collectCustomErrorNodes(schema, [], [], /* @__PURE__ */ new WeakSet());
|
|
80
78
|
if (!nodes.length) return;
|
|
@@ -85,7 +83,7 @@ function buildFindCustomError(schema, frozen) {
|
|
|
85
83
|
const cached = unionCheckCache.get(node);
|
|
86
84
|
if (cached) return cached;
|
|
87
85
|
try {
|
|
88
|
-
const uc =
|
|
86
|
+
const uc = require_type_typebox_value.SchemaCompile(node);
|
|
89
87
|
const fn = (v) => uc.Check(v);
|
|
90
88
|
unionCheckCache.set(node, fn);
|
|
91
89
|
return fn;
|
|
@@ -94,10 +92,8 @@ function buildFindCustomError(schema, frozen) {
|
|
|
94
92
|
}
|
|
95
93
|
};
|
|
96
94
|
const discriminatorsOf = (node, branches) => {
|
|
97
|
-
if (discriminatorCache.has(node))
|
|
98
|
-
|
|
99
|
-
discriminatorCache.set(node, d);
|
|
100
|
-
return d ?? void 0;
|
|
95
|
+
if (!discriminatorCache.has(node)) discriminatorCache.set(node, findDiscriminators(branches));
|
|
96
|
+
return discriminatorCache.get(node) ?? void 0;
|
|
101
97
|
};
|
|
102
98
|
const checks = [];
|
|
103
99
|
for (const { path, node, each, segments, union } of nodes) {
|
|
@@ -107,7 +103,7 @@ function buildFindCustomError(schema, frozen) {
|
|
|
107
103
|
check = fe.c(fe.e ? require_compile_aot.reconstruct().collectExternals(node) : require_compile_aot.EMPTY_EXTERNALS);
|
|
108
104
|
} catch {}
|
|
109
105
|
else try {
|
|
110
|
-
const c =
|
|
106
|
+
const c = require_type_typebox_value.SchemaCompile(node);
|
|
111
107
|
check = (v) => c.Check(v);
|
|
112
108
|
} catch {}
|
|
113
109
|
if (!check) continue;
|
|
@@ -176,7 +172,7 @@ function captureCustomErrors(schema) {
|
|
|
176
172
|
for (const { path, node, union, each } of ceNodes) {
|
|
177
173
|
if (union || each) continue;
|
|
178
174
|
try {
|
|
179
|
-
const cf = require_type_validator_frozen_check.buildFrozenCheck(
|
|
175
|
+
const cf = require_type_validator_frozen_check.buildFrozenCheck(require_type_typebox_value.Build(node), node);
|
|
180
176
|
if (cf) entries.push({
|
|
181
177
|
path,
|
|
182
178
|
...cf
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { nullObject } from "../../utils.mjs";
|
|
2
2
|
import { subValueAt } from "../../error.mjs";
|
|
3
3
|
import { EMPTY_EXTERNALS, reconstruct } from "../../compile/aot.mjs";
|
|
4
|
+
import { Build, SchemaCompile } from "../typebox-value.mjs";
|
|
4
5
|
import { buildFrozenCheck } from "./frozen-check.mjs";
|
|
5
|
-
import { Build, Compile } from "typebox/schema";
|
|
6
6
|
|
|
7
7
|
//#region src/type/validator/custom-error.ts
|
|
8
8
|
function encodePointer(segments) {
|
|
@@ -48,18 +48,17 @@ const literalOf = (propSchema) => {
|
|
|
48
48
|
if ("const" in propSchema) return { value: propSchema.const };
|
|
49
49
|
if (Array.isArray(propSchema.enum) && propSchema.enum.length === 1) return { value: propSchema.enum[0] };
|
|
50
50
|
};
|
|
51
|
-
|
|
51
|
+
const findDiscriminators = (branches) => {
|
|
52
52
|
let candidates;
|
|
53
53
|
for (const branch of branches) {
|
|
54
|
-
if (!branch
|
|
54
|
+
if (!branch?.properties) return null;
|
|
55
55
|
const keys = /* @__PURE__ */ new Set();
|
|
56
56
|
for (const k in branch.properties) if (literalOf(branch.properties[k])) keys.add(k);
|
|
57
|
-
if (!keys.size) return;
|
|
58
57
|
if (!candidates) candidates = keys;
|
|
59
58
|
else for (const c of [...candidates]) if (!keys.has(c)) candidates.delete(c);
|
|
60
|
-
if (!candidates.size) return;
|
|
59
|
+
if (!candidates.size) return null;
|
|
61
60
|
}
|
|
62
|
-
if (!candidates
|
|
61
|
+
if (!candidates) return null;
|
|
63
62
|
const perBranch = branches.map(nullObject);
|
|
64
63
|
let hasDisambiguating = false;
|
|
65
64
|
for (const key of candidates) {
|
|
@@ -71,8 +70,8 @@ function computeDiscriminators(branches) {
|
|
|
71
70
|
}
|
|
72
71
|
if (new Set(seenValues).size === branches.length) hasDisambiguating = true;
|
|
73
72
|
}
|
|
74
|
-
return hasDisambiguating ? perBranch :
|
|
75
|
-
}
|
|
73
|
+
return hasDisambiguating ? perBranch : null;
|
|
74
|
+
};
|
|
76
75
|
function buildFindCustomError(schema, frozen) {
|
|
77
76
|
const nodes = collectCustomErrorNodes(schema, [], [], /* @__PURE__ */ new WeakSet());
|
|
78
77
|
if (!nodes.length) return;
|
|
@@ -83,7 +82,7 @@ function buildFindCustomError(schema, frozen) {
|
|
|
83
82
|
const cached = unionCheckCache.get(node);
|
|
84
83
|
if (cached) return cached;
|
|
85
84
|
try {
|
|
86
|
-
const uc =
|
|
85
|
+
const uc = SchemaCompile(node);
|
|
87
86
|
const fn = (v) => uc.Check(v);
|
|
88
87
|
unionCheckCache.set(node, fn);
|
|
89
88
|
return fn;
|
|
@@ -92,10 +91,8 @@ function buildFindCustomError(schema, frozen) {
|
|
|
92
91
|
}
|
|
93
92
|
};
|
|
94
93
|
const discriminatorsOf = (node, branches) => {
|
|
95
|
-
if (discriminatorCache.has(node))
|
|
96
|
-
|
|
97
|
-
discriminatorCache.set(node, d);
|
|
98
|
-
return d ?? void 0;
|
|
94
|
+
if (!discriminatorCache.has(node)) discriminatorCache.set(node, findDiscriminators(branches));
|
|
95
|
+
return discriminatorCache.get(node) ?? void 0;
|
|
99
96
|
};
|
|
100
97
|
const checks = [];
|
|
101
98
|
for (const { path, node, each, segments, union } of nodes) {
|
|
@@ -105,7 +102,7 @@ function buildFindCustomError(schema, frozen) {
|
|
|
105
102
|
check = fe.c(fe.e ? reconstruct().collectExternals(node) : EMPTY_EXTERNALS);
|
|
106
103
|
} catch {}
|
|
107
104
|
else try {
|
|
108
|
-
const c =
|
|
105
|
+
const c = SchemaCompile(node);
|
|
109
106
|
check = (v) => c.Check(v);
|
|
110
107
|
} catch {}
|
|
111
108
|
if (!check) continue;
|
|
@@ -7,6 +7,14 @@ declare function applyPrecomputed(defaults: Record<string, unknown>, value: Reco
|
|
|
7
7
|
declare function isEmittable(v: unknown, seen: Set<unknown>, top?: boolean): boolean;
|
|
8
8
|
declare function buildDefaultClonerSource(value: unknown): string | undefined;
|
|
9
9
|
declare function buildObjectDefaultMergeSource(defaults: Record<string, unknown>): string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* How many emitted default-precompute sources have failed to compile.
|
|
12
|
+
*
|
|
13
|
+
* Build-time only. A non-zero count means codegen emitted source that
|
|
14
|
+
* `Function()` rejected, so those routes silently fell back to the interpreted
|
|
15
|
+
* default path — always a bug in this module, never a user error.
|
|
16
|
+
*/
|
|
17
|
+
declare const precomputeCompileFailures: () => number;
|
|
10
18
|
declare function createDefaultCloner(value: unknown): DefaultCloner | undefined;
|
|
11
19
|
declare function createObjectDefaultMerger(defaults: Record<string, unknown>): ObjectDefaultMerger | undefined;
|
|
12
20
|
declare function createMergerFromSource(source: string): ((value: any) => any) | undefined;
|
|
@@ -23,4 +31,4 @@ declare function verifyPreallocatableDefault(schema: TSchema, validate?: boolean
|
|
|
23
31
|
ms: string | undefined;
|
|
24
32
|
} | undefined;
|
|
25
33
|
//#endregion
|
|
26
|
-
export { DefaultProbeImpl, applyPrecomputed, buildDefaultClonerSource, buildObjectDefaultMergeSource, canonical, createDefaultCloner, createMergerFromSource, createObjectDefaultMerger, isEmittable, setDefaultProbeImpl, verifyPreallocatableDefault };
|
|
34
|
+
export { DefaultProbeImpl, applyPrecomputed, buildDefaultClonerSource, buildObjectDefaultMergeSource, canonical, createDefaultCloner, createMergerFromSource, createObjectDefaultMerger, isEmittable, precomputeCompileFailures, setDefaultProbeImpl, verifyPreallocatableDefault };
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
3
2
|
const require_constants = require('../../constants.js');
|
|
4
3
|
const require_utils = require('../../utils.js');
|
|
5
|
-
|
|
4
|
+
const require_universal_is_production = require('../../universal/is-production.js');
|
|
5
|
+
const require_type_validator_clean_safe = require('./clean-safe.js');
|
|
6
|
+
const require_type_typebox_value = require('../typebox-value.js');
|
|
6
7
|
|
|
7
8
|
//#region src/type/validator/default-precompute.ts
|
|
8
9
|
function isPrecomputeSafe(schema, depth = 0) {
|
|
@@ -66,64 +67,16 @@ function applyPrecomputed(defaults, value) {
|
|
|
66
67
|
}
|
|
67
68
|
return out;
|
|
68
69
|
}
|
|
69
|
-
const subtreeHasDefault = (
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
for (const k in n.properties) if (f(n.properties[k])) return true;
|
|
74
|
-
}
|
|
75
|
-
const items = n.items;
|
|
76
|
-
if (Array.isArray(items)) {
|
|
77
|
-
for (const it of items) if (f(it)) return true;
|
|
78
|
-
} else if (items && f(items)) return true;
|
|
79
|
-
for (const key of [
|
|
80
|
-
"anyOf",
|
|
81
|
-
"allOf",
|
|
82
|
-
"oneOf"
|
|
83
|
-
]) {
|
|
84
|
-
const arr = n[key];
|
|
85
|
-
if (Array.isArray(arr)) {
|
|
86
|
-
for (const s of arr) if (f(s)) return true;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (typeof n.additionalProperties === "object" && f(n.additionalProperties)) return true;
|
|
90
|
-
if (n.patternProperties) {
|
|
91
|
-
for (const k in n.patternProperties) if (f(n.patternProperties[k])) return true;
|
|
92
|
-
}
|
|
93
|
-
for (const key of [
|
|
94
|
-
"not",
|
|
95
|
-
"if",
|
|
96
|
-
"then",
|
|
97
|
-
"else"
|
|
98
|
-
]) if (n[key] && f(n[key])) return true;
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
const hasDefaultBelow = (node) => childSchemaSome(node, subtreeHasDefault);
|
|
102
|
-
function hasUnemittableDefaultValue(node) {
|
|
103
|
-
if (!node || typeof node !== "object") return false;
|
|
104
|
-
if ("default" in node && !isEmittable(node.default, /* @__PURE__ */ new Set(), true)) return true;
|
|
105
|
-
return childSchemaSome(node, hasUnemittableDefaultValue);
|
|
106
|
-
}
|
|
107
|
-
function containsRefLike(node, seen = /* @__PURE__ */ new WeakSet()) {
|
|
108
|
-
if (!node || typeof node !== "object" || seen.has(node)) return false;
|
|
109
|
-
seen.add(node);
|
|
110
|
-
if (node.$ref !== void 0 || node["~kind"] === "Ref" || node["~kind"] === "This" || node["~kind"] === "Cyclic") return true;
|
|
111
|
-
return childSchemaSome(node, (child) => containsRefLike(child, seen));
|
|
112
|
-
}
|
|
113
|
-
function hasDivergentDefaultBelow(node) {
|
|
114
|
-
const ownKey = "default" in node ? canonical(node.default) : void 0;
|
|
115
|
-
let bad = false;
|
|
116
|
-
const visit = (n) => {
|
|
117
|
-
if (!n || typeof n !== "object") return false;
|
|
118
|
-
if ("default" in n && (ownKey === void 0 || canonical(n.default) !== ownKey)) return bad = true;
|
|
119
|
-
return childSchemaSome(n, visit);
|
|
120
|
-
};
|
|
121
|
-
childSchemaSome(node, visit);
|
|
122
|
-
return bad;
|
|
123
|
-
}
|
|
70
|
+
const subtreeHasDefault = (node) => require_type_validator_clean_safe.schemaSome(node, (n) => "default" in n, void 0, void 0, true);
|
|
71
|
+
const hasDefaultBelow = (node) => require_type_validator_clean_safe.schemaSome(node, (n) => n !== node && "default" in n, void 0, void 0, true);
|
|
72
|
+
const hasUnemittableDefaultValue = (node) => require_type_validator_clean_safe.schemaSome(node, (n) => "default" in n && !isEmittable(n.default, /* @__PURE__ */ new Set(), true), void 0, void 0, true);
|
|
73
|
+
const containsRefLike = (node) => require_type_validator_clean_safe.schemaSome(node, (n) => n.$ref !== void 0 || n["~kind"] === "Ref" || n["~kind"] === "This" || n["~kind"] === "Cyclic", void 0, void 0, true);
|
|
124
74
|
function structuralPreallocatable(schema, depth = 0) {
|
|
125
75
|
if (!schema || typeof schema !== "object") return true;
|
|
126
|
-
if (!((schema["~kind"] === "Object" || schema.type === "object") && !schema["~codec"] && !schema["~refine"] && !Array.isArray(schema.anyOf) && !Array.isArray(schema.allOf) && !Array.isArray(schema.oneOf) && schema.$ref === void 0 && schema.if === void 0 && schema.not === void 0))
|
|
76
|
+
if (!((schema["~kind"] === "Object" || schema.type === "object") && !schema["~codec"] && !schema["~refine"] && !Array.isArray(schema.anyOf) && !Array.isArray(schema.allOf) && !Array.isArray(schema.oneOf) && schema.$ref === void 0 && schema.if === void 0 && schema.not === void 0)) {
|
|
77
|
+
const ownKey = "default" in schema ? canonical(schema.default) : void 0;
|
|
78
|
+
return !require_type_validator_clean_safe.schemaSome(schema, (n) => n !== schema && "default" in n && (ownKey === void 0 || canonical(n.default) !== ownKey), void 0, void 0, true);
|
|
79
|
+
}
|
|
127
80
|
if (depth > 0 && schema.default === void 0 && hasDefaultBelow(schema)) return false;
|
|
128
81
|
if (typeof schema.additionalProperties === "object" && subtreeHasDefault(schema.additionalProperties)) return false;
|
|
129
82
|
if (schema.patternProperties) {
|
|
@@ -258,11 +211,21 @@ function buildObjectDefaultMergeSource(defaults) {
|
|
|
258
211
|
if (!root) return;
|
|
259
212
|
return `(function(){${helpers.join(";")};return ${root}})()`;
|
|
260
213
|
}
|
|
214
|
+
let compileFailures = 0;
|
|
215
|
+
/**
|
|
216
|
+
* How many emitted default-precompute sources have failed to compile.
|
|
217
|
+
*
|
|
218
|
+
* Build-time only. A non-zero count means codegen emitted source that
|
|
219
|
+
* `Function()` rejected, so those routes silently fell back to the interpreted
|
|
220
|
+
* default path — always a bug in this module, never a user error.
|
|
221
|
+
*/
|
|
222
|
+
const precomputeCompileFailures = () => compileFailures;
|
|
261
223
|
function fromSource(source) {
|
|
262
224
|
try {
|
|
263
225
|
return Function(`return ${source}`)();
|
|
264
|
-
} catch {
|
|
265
|
-
|
|
226
|
+
} catch (error) {
|
|
227
|
+
compileFailures++;
|
|
228
|
+
console.warn("[Elysia] default precompute emitted source that does not compile; falling back to the interpreted default path. This is a bug, please report it:", error, ...require_universal_is_production.isProduction() ? [] : ["\nsource: " + (source.length > 512 ? source.slice(0, 512) + "…" : source)]);
|
|
266
229
|
}
|
|
267
230
|
}
|
|
268
231
|
function createDefaultCloner(value) {
|
|
@@ -286,20 +249,20 @@ function mergeCategory(node) {
|
|
|
286
249
|
if ((kind === "Array" || node.type === "array") && node.items) return !Array.isArray(node.items) && subtreeHasDefault(node.items) ? "array" : "identity";
|
|
287
250
|
return "identity";
|
|
288
251
|
}
|
|
289
|
-
function presentExpr(child, isObject, varName) {
|
|
290
|
-
if (child === "") return varName;
|
|
291
|
-
return isObject ? `(${varName}!==null&&typeof ${varName}==='object'&&!Array.isArray(${varName})?${child}(${varName}):${varName})` : `(Array.isArray(${varName})?${child}(${varName}):${varName})`;
|
|
292
|
-
}
|
|
293
252
|
function mergeExpression(schema, varName, helpers, memo) {
|
|
294
|
-
const full =
|
|
253
|
+
const full = require_type_typebox_value.Default(schema, void 0);
|
|
295
254
|
const child = emitMerger(schema, helpers, memo);
|
|
296
255
|
if (child === void 0) return;
|
|
297
256
|
const absent = full === void 0 ? void 0 : cloneExpression(full);
|
|
298
257
|
if (full !== void 0 && absent === void 0) return;
|
|
299
258
|
const isObject = mergeCategory(schema) === "object";
|
|
259
|
+
let present;
|
|
260
|
+
if (child === "") present = varName;
|
|
261
|
+
else if (isObject) present = `(${varName}!==null&&typeof ${varName}==='object'&&!Array.isArray(${varName})?${child}(${varName}):${varName})`;
|
|
262
|
+
else present = `(Array.isArray(${varName})?${child}(${varName}):${varName})`;
|
|
300
263
|
return {
|
|
301
264
|
absent,
|
|
302
|
-
present
|
|
265
|
+
present,
|
|
303
266
|
child,
|
|
304
267
|
isObject
|
|
305
268
|
};
|
|
@@ -365,14 +328,6 @@ function emitMerger(node, helpers, memo = /* @__PURE__ */ new WeakMap()) {
|
|
|
365
328
|
helpers[+name.slice(2)] = `function ${name}(v){if(!Array.isArray(v))return v;const o=new Array(v.length);let e;for(let i=0;i<v.length;i++){e=v[i];o[i]=${assign}}return o}`;
|
|
366
329
|
return name;
|
|
367
330
|
}
|
|
368
|
-
function buildMergeSource(schema) {
|
|
369
|
-
const category = mergeCategory(schema);
|
|
370
|
-
if (category !== "object" && category !== "array") return;
|
|
371
|
-
const helpers = [];
|
|
372
|
-
const root = emitMerger(schema, helpers, /* @__PURE__ */ new WeakMap());
|
|
373
|
-
if (!root) return;
|
|
374
|
-
return `(function(){${helpers.join(";")};return ${root}})()`;
|
|
375
|
-
}
|
|
376
331
|
let probeImpl;
|
|
377
332
|
function setDefaultProbeImpl(impl) {
|
|
378
333
|
probeImpl = impl;
|
|
@@ -393,8 +348,8 @@ function verifyPreallocatableDefault(schema, validate = true) {
|
|
|
393
348
|
let pd;
|
|
394
349
|
let podRaw;
|
|
395
350
|
try {
|
|
396
|
-
pd =
|
|
397
|
-
podRaw =
|
|
351
|
+
pd = require_type_typebox_value.Default(schema, void 0);
|
|
352
|
+
podRaw = require_type_typebox_value.Default(schema, require_utils.nullObject());
|
|
398
353
|
} catch {
|
|
399
354
|
return;
|
|
400
355
|
}
|
|
@@ -404,7 +359,14 @@ function verifyPreallocatableDefault(schema, validate = true) {
|
|
|
404
359
|
if (containsRefLike(schema)) return;
|
|
405
360
|
if (!isEmittable(pd, /* @__PURE__ */ new Set(), true) || pod !== void 0 && !isEmittable(pod, /* @__PURE__ */ new Set(), true)) return;
|
|
406
361
|
const nullDefault = isPrecomputeSafe(schema);
|
|
407
|
-
let ms
|
|
362
|
+
let ms;
|
|
363
|
+
const category = mergeCategory(schema);
|
|
364
|
+
if (category !== "object" && category !== "array") ms = void 0;
|
|
365
|
+
else {
|
|
366
|
+
const helpers = [];
|
|
367
|
+
const root = emitMerger(schema, helpers, /* @__PURE__ */ new WeakMap());
|
|
368
|
+
ms = root ? `(function(){${helpers.join(";")};return ${root}})()` : void 0;
|
|
369
|
+
}
|
|
408
370
|
if (ms !== void 0 && validate && !probe().validateMergeSource(schema, ms)) ms = void 0;
|
|
409
371
|
if (!nullDefault && ms === void 0) {
|
|
410
372
|
if (!rootIsObject) return;
|
|
@@ -428,5 +390,6 @@ exports.createDefaultCloner = createDefaultCloner;
|
|
|
428
390
|
exports.createMergerFromSource = createMergerFromSource;
|
|
429
391
|
exports.createObjectDefaultMerger = createObjectDefaultMerger;
|
|
430
392
|
exports.isEmittable = isEmittable;
|
|
393
|
+
exports.precomputeCompileFailures = precomputeCompileFailures;
|
|
431
394
|
exports.setDefaultProbeImpl = setDefaultProbeImpl;
|
|
432
395
|
exports.verifyPreallocatableDefault = verifyPreallocatableDefault;
|