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,17 +1,13 @@
|
|
|
1
1
|
import { nullObject } from "../../utils.mjs";
|
|
2
2
|
import { ELYSIA_TYPES } from "../../type/constants.mjs";
|
|
3
3
|
import { ValidationError } from "../../error.mjs";
|
|
4
|
-
import { Compiled, reconstruct } from "../aot.mjs";
|
|
4
|
+
import { Compiled, EMPTY_EXTERNALS, reconstruct } from "../aot.mjs";
|
|
5
5
|
import { frozenRootOf } from "../../generation.mjs";
|
|
6
6
|
import { isFullyClosedObject } from "../../type/validator/clean-safe.mjs";
|
|
7
7
|
import { StandardValidator } from "../../validator/index.mjs";
|
|
8
8
|
|
|
9
9
|
//#region src/compile/handler/frozen-validator.ts
|
|
10
10
|
const isBridgeNotInitialized = (error) => error instanceof Error && error.message.startsWith("Typebox module isn't initialized");
|
|
11
|
-
function codecCoercionBridgeFree(f, coerced, raw) {
|
|
12
|
-
return f.k === 1 && !!f.dm && !f.em && !f.ce && f.a !== 1 && !(f.d === 1 && f.ps !== 1) && innerCodecsAligned(f.ic?.length, coerced) && mirrorUnionsAligned(f.u, raw) && mirrorUnionsAligned(f.dm.u, coerced);
|
|
13
|
-
}
|
|
14
|
-
const innerCodecsAligned = (icLength, coerced) => reconstruct().collectStringCodecNodes(coerced).length === (icLength ?? 0);
|
|
15
11
|
function mirrorUnionsAligned(u, schema) {
|
|
16
12
|
if (!u) return true;
|
|
17
13
|
const branches = reconstruct().collectMirrorUnions(schema);
|
|
@@ -21,25 +17,12 @@ function mirrorUnionsAligned(u, schema) {
|
|
|
21
17
|
}
|
|
22
18
|
function isBridgeFreeComplete(f, schema, raw) {
|
|
23
19
|
if (!f.cm) return false;
|
|
24
|
-
if (
|
|
20
|
+
if (f.k === 1 && !!f.dm && !f.em && !f.ce && f.a !== 1 && !(f.d === 1 && f.ps !== 1) && (f.ic?.length ?? 0) === reconstruct().collectStringCodecNodes(schema).length && mirrorUnionsAligned(f.u, raw) && mirrorUnionsAligned(f.dm.u, schema)) return true;
|
|
25
21
|
if (f.e === 1 || f.u || f.dm || f.em || f.k === 1 || f.ce || f.ic || f.a === 1) return false;
|
|
26
22
|
if (f.d === 1 && f.ps !== 1) return false;
|
|
27
23
|
if (isFullyClosedObject(schema)) return false;
|
|
28
24
|
return true;
|
|
29
25
|
}
|
|
30
|
-
const EMPTY_EXTERNALS = Object.freeze([]);
|
|
31
|
-
function jsTypeMatches(value, type) {
|
|
32
|
-
switch (type) {
|
|
33
|
-
case "string": return typeof value === "string";
|
|
34
|
-
case "number": return typeof value === "number";
|
|
35
|
-
case "integer": return typeof value === "number" && Number.isInteger(value);
|
|
36
|
-
case "boolean": return typeof value === "boolean";
|
|
37
|
-
case "null": return value === null;
|
|
38
|
-
case "array": return Array.isArray(value);
|
|
39
|
-
case "object": return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
40
|
-
default: return true;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
26
|
const typeError = (schema, instancePath, schemaPath) => ({
|
|
44
27
|
keyword: "type",
|
|
45
28
|
schemaPath,
|
|
@@ -97,63 +80,28 @@ function walkCompactError(schema, value, instancePath, schemaPath) {
|
|
|
97
80
|
}
|
|
98
81
|
return;
|
|
99
82
|
}
|
|
100
|
-
if (typeof type === "
|
|
101
|
-
}
|
|
102
|
-
function bestEffortCodecError(schema, value) {
|
|
103
|
-
if (schema?.type === "object" && typeof value === "object" && value !== null && !Array.isArray(value) && schema.properties) for (const key in schema.properties) {
|
|
104
|
-
if (!(key in value)) continue;
|
|
105
|
-
if (isCompactDiagnosable(schema.properties[key])) continue;
|
|
106
|
-
return {
|
|
107
|
-
keyword: "type",
|
|
108
|
-
schemaPath: `#/properties/${key}`,
|
|
109
|
-
instancePath: `/${key}`,
|
|
110
|
-
params: {},
|
|
111
|
-
message: `must match ${schema.properties[key]?.["~kind"] ?? "schema"}`
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
return {
|
|
115
|
-
keyword: "type",
|
|
116
|
-
schemaPath: "#",
|
|
117
|
-
instancePath: "",
|
|
118
|
-
params: {},
|
|
119
|
-
message: `must match ${schema?.["~kind"] ?? "schema"}`
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
function isCompactDiagnosable(schema) {
|
|
123
|
-
if (!schema || typeof schema !== "object") return false;
|
|
124
|
-
if (schema.anyOf || schema.oneOf || schema.allOf) return false;
|
|
125
|
-
const type = schema.type;
|
|
126
|
-
if (type === "object") {
|
|
127
|
-
const properties = schema.properties;
|
|
128
|
-
if (properties) {
|
|
129
|
-
for (const key in properties) if (!isCompactDiagnosable(properties[key])) return false;
|
|
130
|
-
}
|
|
131
|
-
return true;
|
|
132
|
-
}
|
|
133
|
-
if (type === "array") return isCompactDiagnosable(schema.items);
|
|
134
|
-
return type === "string" || type === "number" || type === "integer" || type === "boolean" || type === "null";
|
|
83
|
+
if (!(type === "string" || type === "number" || type === "boolean" ? typeof value === type : type === "integer" ? Number.isInteger(value) : type !== "null" || value === null)) return typeError(schema, instancePath, schemaPath);
|
|
135
84
|
}
|
|
136
|
-
function isCompactWalkable(schema) {
|
|
85
|
+
function isCompactWalkable(schema, lookThrough = true) {
|
|
137
86
|
if (!schema || typeof schema !== "object") return false;
|
|
138
87
|
const elyTyp = schema["~elyTyp"];
|
|
139
|
-
if (schema.anyOf && (elyTyp === ELYSIA_TYPES.ObjectString || elyTyp === ELYSIA_TYPES.ArrayString)) return isCompactWalkable(schema.anyOf[0]);
|
|
88
|
+
if (lookThrough && schema.anyOf && (elyTyp === ELYSIA_TYPES.ObjectString || elyTyp === ELYSIA_TYPES.ArrayString)) return isCompactWalkable(schema.anyOf[0]);
|
|
140
89
|
if (schema.anyOf || schema.oneOf || schema.allOf) return false;
|
|
141
90
|
const type = schema.type;
|
|
142
91
|
if (type === "object") {
|
|
143
92
|
const properties = schema.properties;
|
|
144
93
|
if (properties) {
|
|
145
|
-
for (const key in properties) if (!isCompactWalkable(properties[key])) return false;
|
|
94
|
+
for (const key in properties) if (!isCompactWalkable(properties[key], lookThrough)) return false;
|
|
146
95
|
}
|
|
147
96
|
return true;
|
|
148
97
|
}
|
|
149
|
-
if (type === "array") return isCompactWalkable(schema.items);
|
|
98
|
+
if (type === "array") return isCompactWalkable(schema.items, lookThrough);
|
|
150
99
|
return type === "string" || type === "number" || type === "integer" || type === "boolean" || type === "null";
|
|
151
100
|
}
|
|
152
101
|
var FrozenSlotValidator = class {
|
|
153
102
|
#check;
|
|
154
103
|
#clean;
|
|
155
104
|
#decode;
|
|
156
|
-
#hasDefault;
|
|
157
105
|
#defaultFastPath;
|
|
158
106
|
#hasOptional;
|
|
159
107
|
#noValidate;
|
|
@@ -162,13 +110,21 @@ var FrozenSlotValidator = class {
|
|
|
162
110
|
this.hasCodec = false;
|
|
163
111
|
this.schema = schema;
|
|
164
112
|
this.hasCodec = frozen.k === 1;
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
113
|
+
if (frozen.ic) reconstruct().reconstructInnerCodecs(frozen.ic, schema);
|
|
114
|
+
if (frozen.k === 1 && frozen.dm) {
|
|
115
|
+
const both = reconstruct().instantiateFrozenBoth(frozen, schema, raw);
|
|
116
|
+
this.#check = both.check;
|
|
117
|
+
if (normalize !== false) {
|
|
118
|
+
this.#clean = both.clean;
|
|
119
|
+
this.#decode = reconstruct().instantiateFrozenDecodeMirror(frozen.dm, schema);
|
|
120
|
+
}
|
|
121
|
+
} else {
|
|
122
|
+
const both = frozen.cm(EMPTY_EXTERNALS, void 0);
|
|
123
|
+
this.#check = both.check;
|
|
124
|
+
if (normalize !== false) this.#clean = both.clean;
|
|
125
|
+
}
|
|
169
126
|
this.#hasOptional = !!schema?.["~optional"];
|
|
170
127
|
this.#noValidate = schema?.["~elyTyp"] === ELYSIA_TYPES.NoValidate;
|
|
171
|
-
this.#hasDefault = frozen.d === 1;
|
|
172
128
|
if (frozen.ps === 1) this.#defaultFastPath = {
|
|
173
129
|
value: frozen.pd,
|
|
174
130
|
appliesToNull: frozen.pn === 1,
|
|
@@ -176,20 +132,34 @@ var FrozenSlotValidator = class {
|
|
|
176
132
|
merge: frozen.pm
|
|
177
133
|
};
|
|
178
134
|
}
|
|
179
|
-
buildCheckClean(frozen, schema, raw, normalize) {
|
|
180
|
-
const both = frozen.cm(EMPTY_EXTERNALS, void 0);
|
|
181
|
-
return {
|
|
182
|
-
check: both.check,
|
|
183
|
-
clean: normalize === false ? void 0 : both.clean
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
135
|
Check(value) {
|
|
187
136
|
return this.#check(value);
|
|
188
137
|
}
|
|
189
138
|
Errors(value) {
|
|
190
139
|
const hit = walkCompactError(this.schema, value, "", "#");
|
|
191
140
|
if (hit) return [hit];
|
|
192
|
-
|
|
141
|
+
const schema = this.schema;
|
|
142
|
+
let error;
|
|
143
|
+
if (schema?.type === "object" && typeof value === "object" && value !== null && !Array.isArray(value) && schema.properties) for (const key in schema.properties) {
|
|
144
|
+
if (!(key in value)) continue;
|
|
145
|
+
if (isCompactWalkable(schema.properties[key], false)) continue;
|
|
146
|
+
error = {
|
|
147
|
+
keyword: "type",
|
|
148
|
+
schemaPath: `#/properties/${key}`,
|
|
149
|
+
instancePath: `/${key}`,
|
|
150
|
+
params: {},
|
|
151
|
+
message: `must match ${schema.properties[key]?.["~kind"] ?? "schema"}`
|
|
152
|
+
};
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
if (!error) error = {
|
|
156
|
+
keyword: "type",
|
|
157
|
+
schemaPath: "#",
|
|
158
|
+
instancePath: "",
|
|
159
|
+
params: {},
|
|
160
|
+
message: `must match ${schema?.["~kind"] ?? "schema"}`
|
|
161
|
+
};
|
|
162
|
+
return [error];
|
|
193
163
|
}
|
|
194
164
|
#error(value, type) {
|
|
195
165
|
return new ValidationError(type, value, () => this.Errors(value), this.schema);
|
|
@@ -200,16 +170,11 @@ var FrozenSlotValidator = class {
|
|
|
200
170
|
if (value === null || typeof value !== "object") return value;
|
|
201
171
|
return defaults.clone ? defaults.clone() : structuredClone(value);
|
|
202
172
|
}
|
|
203
|
-
#applyDefault(value) {
|
|
204
|
-
return this.#defaultFastPath.merge(value);
|
|
205
|
-
}
|
|
206
173
|
From(value, type) {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (defaults)
|
|
210
|
-
|
|
211
|
-
else if (value !== null && typeof value === "object" && defaults.merge !== void 0) value = this.#applyDefault(value);
|
|
212
|
-
}
|
|
174
|
+
const defaults = this.#defaultFastPath;
|
|
175
|
+
if (defaults) {
|
|
176
|
+
if (value === void 0 || value === null && defaults.appliesToNull) value = this.#cloneSharedDefault();
|
|
177
|
+
else if (value !== null && typeof value === "object" && defaults.merge !== void 0) value = defaults.merge(value);
|
|
213
178
|
}
|
|
214
179
|
if (this.#hasOptional) {
|
|
215
180
|
const schema = this.schema;
|
|
@@ -225,25 +190,6 @@ var FrozenSlotValidator = class {
|
|
|
225
190
|
return this.#clean ? this.#clean(value) : value;
|
|
226
191
|
}
|
|
227
192
|
};
|
|
228
|
-
/**
|
|
229
|
-
* The JIT/frozen slot validator: the reconstruct-free `FrozenSlotValidator`
|
|
230
|
-
* base plus the codec/inner-codec branch re-added via the `buildCheckClean`
|
|
231
|
-
* override
|
|
232
|
-
*/
|
|
233
|
-
var CodecFrozenSlotValidator = class extends FrozenSlotValidator {
|
|
234
|
-
buildCheckClean(frozen, schema, raw, normalize) {
|
|
235
|
-
if (frozen.ic) reconstruct().reconstructInnerCodecs(frozen.ic, schema);
|
|
236
|
-
if (frozen.k === 1 && frozen.dm) {
|
|
237
|
-
const both = reconstruct().instantiateFrozenBoth(frozen, schema, raw);
|
|
238
|
-
return {
|
|
239
|
-
check: both.check,
|
|
240
|
-
clean: normalize === false ? void 0 : both.clean,
|
|
241
|
-
decode: normalize === false ? void 0 : reconstruct().instantiateFrozenDecodeMirror(frozen.dm, schema)
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
return super.buildCheckClean(frozen, schema, raw, normalize);
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
193
|
const REQUEST_SLOTS = [
|
|
248
194
|
"body",
|
|
249
195
|
"headers",
|
|
@@ -289,11 +235,13 @@ function buildFrozenRouteValidator(hook, root, method, path) {
|
|
|
289
235
|
coerced = rebuild(schema, frozen.cp);
|
|
290
236
|
}
|
|
291
237
|
if (!isBridgeFreeComplete(frozen, coerced, schema)) return void 0;
|
|
292
|
-
out[slot] = new
|
|
238
|
+
out[slot] = new FrozenSlotValidator(frozen, coerced, schema, normalize);
|
|
293
239
|
}
|
|
294
240
|
const response = hook?.response;
|
|
295
241
|
if (response) {
|
|
296
|
-
const
|
|
242
|
+
const resolved = resolveModelRef(response, root);
|
|
243
|
+
if (!resolved) return void 0;
|
|
244
|
+
const statuses = isResponseMap(resolved) ? resolved : { 200: resolved };
|
|
297
245
|
const responseOut = {};
|
|
298
246
|
for (const status in statuses) {
|
|
299
247
|
const raw = statuses[status];
|
|
@@ -306,13 +254,13 @@ function buildFrozenRouteValidator(hook, root, method, path) {
|
|
|
306
254
|
}
|
|
307
255
|
const frozen = Compiled.getValidator(method, path, `response:${status}`, root["~programId"]);
|
|
308
256
|
if (!frozen || !isBridgeFreeComplete(frozen, schema, schema)) return void 0;
|
|
309
|
-
responseOut[status] = new
|
|
257
|
+
responseOut[status] = new FrozenSlotValidator(frozen, schema, schema, normalize);
|
|
310
258
|
}
|
|
311
259
|
out.response = responseOut;
|
|
312
260
|
}
|
|
313
261
|
return out;
|
|
314
262
|
}
|
|
315
|
-
const isResponseMap = (schema) => !("~kind" in schema || "~elyAcl" in schema || "~standard" in schema);
|
|
263
|
+
const isResponseMap = (schema) => schema !== null && typeof schema === "object" && !("~kind" in schema || "~elyAcl" in schema || "~standard" in schema);
|
|
316
264
|
const capturedBothMarker = (() => ({}));
|
|
317
265
|
function isCapturedBridgeFree(c, schema, coerced = schema) {
|
|
318
266
|
if (typeof schema === "string") return false;
|
|
@@ -339,4 +287,4 @@ function isCapturedBridgeFree(c, schema, coerced = schema) {
|
|
|
339
287
|
}
|
|
340
288
|
|
|
341
289
|
//#endregion
|
|
342
|
-
export { buildFrozenRouteValidator, isBridgeNotInitialized, isCapturedBridgeFree,
|
|
290
|
+
export { REQUEST_SLOTS, buildFrozenRouteValidator, isBridgeNotInitialized, isCapturedBridgeFree, isCompactWalkable, isResponseMap, isStandardSchema, mergeSchemasAllStandard, resolveModelRef };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ChainNode } from "../../utils.js";
|
|
2
|
-
import { AnyLocalHook, CompiledHandler, InternalRoute } from "../../types.js";
|
|
2
|
+
import { AnyLocalHook, AppHook, CompiledHandler, InternalRoute } from "../../types.js";
|
|
3
3
|
import { AnyElysia } from "../../base.js";
|
|
4
4
|
import { setCaptureHeaderShorthand } from "./jit.js";
|
|
5
5
|
|
|
@@ -11,9 +11,11 @@ declare function resolveWSLocalHook(scope: AnyElysia, hook: Partial<AnyLocalHook
|
|
|
11
11
|
* (JIT or rebuild) compile repopulates them anyway, just uncached
|
|
12
12
|
*/
|
|
13
13
|
declare function clearHandlerAnalysisCaches(root: AnyElysia): void;
|
|
14
|
+
declare function chainResolver(root: AnyElysia): ((node: ChainNode) => Partial<AppHook> | undefined) | undefined;
|
|
14
15
|
declare const localMacroRoot: (instance: AnyElysia, root: AnyElysia) => AnyElysia;
|
|
15
|
-
declare function buildNativeStaticResponse(
|
|
16
|
-
declare function composeRouteHook(instance: AnyElysia, localHook: Partial<AnyLocalHook> | undefined, appHook: ChainNode | undefined, inheritedChain: ChainNode | undefined, root: AnyElysia, macroScope?: AnyElysia): AnyLocalHook | undefined;
|
|
17
|
-
declare function
|
|
16
|
+
declare function buildNativeStaticResponse(route: InternalRoute, root: AnyElysia): Response | undefined;
|
|
17
|
+
declare function composeRouteHook(instance: AnyElysia, localHook: Partial<AnyLocalHook> | undefined, appHook: ChainNode | undefined, inheritedChain: ChainNode | undefined, root: AnyElysia, macroScope?: AnyElysia, allowCompactPrefix?: boolean): AnyLocalHook | undefined;
|
|
18
|
+
declare function routeShape(hook: AnyLocalHook | undefined, handler: unknown, root: AnyElysia): number | undefined;
|
|
19
|
+
declare function compileHandler(route: InternalRoute, root: AnyElysia, liveOnly?: boolean): CompiledHandler;
|
|
18
20
|
//#endregion
|
|
19
|
-
export { buildNativeStaticResponse, clearHandlerAnalysisCaches, compileHandler, composeRouteHook, localMacroRoot, resolveLocalHook, resolveWSLocalHook, setCaptureHeaderShorthand };
|
|
21
|
+
export { buildNativeStaticResponse, chainResolver, clearHandlerAnalysisCaches, compileHandler, composeRouteHook, localMacroRoot, resolveLocalHook, resolveWSLocalHook, routeShape, setCaptureHeaderShorthand };
|