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,24 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CapturedHandler, CapturedValidator, CompiledSnapshot } from "./aot.js";
|
|
2
2
|
|
|
3
3
|
//#region src/compile/aot-capture.d.ts
|
|
4
|
-
declare function resetCompactErrorWarnings(): void;
|
|
5
4
|
declare function beginValidatorCapture(): void;
|
|
6
5
|
declare function abortCapture(): void;
|
|
7
6
|
declare function endValidatorCapture(): CapturedValidator[];
|
|
8
7
|
declare function endHandlerCapture(): CapturedHandler[];
|
|
9
|
-
/** @internal deterministic session/capture assertions. */
|
|
10
|
-
declare const getCompilerSessionDiagnostics: () => {
|
|
11
|
-
active: boolean;
|
|
12
|
-
appAttached: boolean;
|
|
13
|
-
validators: number;
|
|
14
|
-
handlers: number;
|
|
15
|
-
sucrose: number;
|
|
16
|
-
};
|
|
17
8
|
/** @internal preserve registry around in-process AOT analysis */
|
|
18
9
|
declare const snapshotCompiled: () => CompiledSnapshot;
|
|
19
10
|
/** @internal restore registry after in-process AOT analysis */
|
|
20
11
|
declare function restoreCompiled(snapshot: CompiledSnapshot): void;
|
|
21
|
-
declare const impl: CaptureImpl;
|
|
22
|
-
declare function installCaptureImpl(): void;
|
|
23
12
|
//#endregion
|
|
24
|
-
export { abortCapture, beginValidatorCapture,
|
|
13
|
+
export { abortCapture, beginValidatorCapture, endHandlerCapture, endValidatorCapture, restoreCompiled, snapshotCompiled };
|
|
@@ -3,9 +3,9 @@ const require_runtime = require('../_virtual/_rolldown/runtime.js');
|
|
|
3
3
|
const require_utils = require('../utils.js');
|
|
4
4
|
const require_universal_env = require('../universal/env.js');
|
|
5
5
|
const require_compile_aot = require('./aot.js');
|
|
6
|
-
const require_type_elysia_file_type = require('../type/elysia/file-type.js');
|
|
7
6
|
const require_compile_handler_frozen_validator = require('./handler/frozen-validator.js');
|
|
8
7
|
const require_type_coerce = require('../type/coerce.js');
|
|
8
|
+
const require_type_elysia_file_type = require('../type/elysia/file-type.js');
|
|
9
9
|
const require_type_validator_default_precompute = require('../type/validator/default-precompute.js');
|
|
10
10
|
const require_compile_aot_reconstruct = require('./aot-reconstruct.js');
|
|
11
11
|
const require_compile_aot_emit = require('./aot-emit.js');
|
|
@@ -13,8 +13,8 @@ const require_type_validator_frozen_check = require('../type/validator/frozen-ch
|
|
|
13
13
|
const require_type_validator_custom_error = require('../type/validator/custom-error.js');
|
|
14
14
|
const require_type_validator_exact_mirror = require('../type/validator/exact-mirror.js');
|
|
15
15
|
const require_type_validator_string_codec_aot = require('../type/validator/string-codec-aot.js');
|
|
16
|
-
let typebox_value = require("typebox/value");
|
|
17
16
|
let typebox_schema = require("typebox/schema");
|
|
17
|
+
let typebox_value = require("typebox/value");
|
|
18
18
|
|
|
19
19
|
//#region src/compile/aot-capture.ts
|
|
20
20
|
function emptyContainers(node, depth) {
|
|
@@ -124,13 +124,14 @@ function sourceOnlyValidator(schema) {
|
|
|
124
124
|
}
|
|
125
125
|
function maybeCapture(args) {
|
|
126
126
|
const { aot, slot, hasRef, originalSchema, schema, hasCodec, hasDefault, coerces, normalize, buildResult } = args;
|
|
127
|
+
const loc = {
|
|
128
|
+
method: aot.method,
|
|
129
|
+
path: aot.path,
|
|
130
|
+
slot
|
|
131
|
+
};
|
|
127
132
|
if (hasCodec && !hasRef && coerces && normalize !== false && normalize !== "typebox") {
|
|
128
133
|
const plan = require_type_coerce.captureCoercePlan(originalSchema, schema);
|
|
129
|
-
if (plan && externalsShape(require_type_coerce.buildCoercedFromPlan(originalSchema, plan)) === externalsShape(schema)) require_compile_aot.Capture.set({
|
|
130
|
-
method: aot.method,
|
|
131
|
-
path: aot.path,
|
|
132
|
-
slot
|
|
133
|
-
}, { coercePlan: plan });
|
|
134
|
+
if (plan && externalsShape(require_type_coerce.buildCoercedFromPlan(originalSchema, plan)) === externalsShape(schema)) require_compile_aot.Capture.set(loc, { coercePlan: plan });
|
|
134
135
|
}
|
|
135
136
|
const defaultFastPathCapture = {
|
|
136
137
|
precomputeSafe: void 0,
|
|
@@ -151,30 +152,14 @@ function maybeCapture(args) {
|
|
|
151
152
|
defaultFastPathCapture.objectDefaultMerger = defaults.ms ?? (defaults.pod !== void 0 ? require_type_validator_default_precompute.buildObjectDefaultMergeSource(defaults.pod) : void 0);
|
|
152
153
|
}
|
|
153
154
|
}
|
|
154
|
-
require_compile_aot.Capture.set(
|
|
155
|
-
method: aot.method,
|
|
156
|
-
path: aot.path,
|
|
157
|
-
slot
|
|
158
|
-
}, defaultFastPathCapture);
|
|
155
|
+
require_compile_aot.Capture.set(loc, defaultFastPathCapture);
|
|
159
156
|
const customErrors = require_type_validator_custom_error.captureCustomErrors(schema);
|
|
160
|
-
if (customErrors) require_compile_aot.Capture.set({
|
|
161
|
-
method: aot.method,
|
|
162
|
-
path: aot.path,
|
|
163
|
-
slot
|
|
164
|
-
}, { customErrors });
|
|
157
|
+
if (customErrors) require_compile_aot.Capture.set(loc, { customErrors });
|
|
165
158
|
const innerCodecs = require_type_validator_string_codec_aot.captureStringCodecEntries(schema, args.sanitize);
|
|
166
|
-
if (innerCodecs) require_compile_aot.Capture.set({
|
|
167
|
-
method: aot.method,
|
|
168
|
-
path: aot.path,
|
|
169
|
-
slot
|
|
170
|
-
}, { innerCodecs });
|
|
159
|
+
if (innerCodecs) require_compile_aot.Capture.set(loc, { innerCodecs });
|
|
171
160
|
const cf = require_type_validator_frozen_check.buildFrozenCheck(buildResult, schema);
|
|
172
161
|
if (!cf) return;
|
|
173
|
-
require_compile_aot.Capture.set({
|
|
174
|
-
method: aot.method,
|
|
175
|
-
path: aot.path,
|
|
176
|
-
slot
|
|
177
|
-
}, {
|
|
162
|
+
require_compile_aot.Capture.set(loc, {
|
|
178
163
|
...cf,
|
|
179
164
|
async: buildResult.external.variables.some(require_type_elysia_file_type.isAsyncPredicate),
|
|
180
165
|
hasDefault,
|
|
@@ -187,27 +172,24 @@ function captureMirror(schema, aot, slot, sanitize) {
|
|
|
187
172
|
if (!createMirror) return;
|
|
188
173
|
try {
|
|
189
174
|
const emitted = createMirror(schema, {
|
|
190
|
-
Compile:
|
|
175
|
+
Compile: require_type_validator_string_codec_aot.compileWithBuild,
|
|
191
176
|
sanitize,
|
|
192
177
|
emit: true
|
|
193
178
|
});
|
|
194
179
|
if (typeof emitted?.source === "string") {
|
|
195
180
|
const ext = emitted.externals;
|
|
196
|
-
|
|
181
|
+
const loc = {
|
|
197
182
|
method: aot.method,
|
|
198
183
|
path: aot.path,
|
|
199
184
|
slot
|
|
200
|
-
}
|
|
185
|
+
};
|
|
186
|
+
if (!ext) require_compile_aot.Capture.set(loc, { mirror: {
|
|
201
187
|
source: emitted.source,
|
|
202
188
|
hasExternals: false
|
|
203
189
|
} });
|
|
204
190
|
else if (ext.unions && !ext.hof) {
|
|
205
191
|
const u = require_compile_aot_emit.captureMirrorUnions(schema, ext.unions);
|
|
206
|
-
if (u) require_compile_aot.Capture.set({
|
|
207
|
-
method: aot.method,
|
|
208
|
-
path: aot.path,
|
|
209
|
-
slot
|
|
210
|
-
}, { mirror: {
|
|
192
|
+
if (u) require_compile_aot.Capture.set(loc, { mirror: {
|
|
211
193
|
source: emitted.source,
|
|
212
194
|
hasExternals: true,
|
|
213
195
|
u
|
|
@@ -222,7 +204,7 @@ function captureCodecMirror(schema, aot, slot, sanitize, dir) {
|
|
|
222
204
|
const dirOpt = dir === "decode" ? { decode: true } : { encode: true };
|
|
223
205
|
try {
|
|
224
206
|
const emitted = createMirror(schema, {
|
|
225
|
-
Compile:
|
|
207
|
+
Compile: require_type_validator_string_codec_aot.compileWithBuild,
|
|
226
208
|
sanitize,
|
|
227
209
|
...dirOpt,
|
|
228
210
|
emit: true
|
|
@@ -254,9 +236,6 @@ function captureCodecMirror(schema, aot, slot, sanitize, dir) {
|
|
|
254
236
|
}
|
|
255
237
|
const compactErrorWarned = /* @__PURE__ */ new Set();
|
|
256
238
|
const isVerboseAotWarnings = () => !!require_universal_env.env.ELYSIA_AOT_VERBOSE;
|
|
257
|
-
function resetCompactErrorWarnings() {
|
|
258
|
-
compactErrorWarned.clear();
|
|
259
|
-
}
|
|
260
239
|
function warnCompactErrorLoss(aot, slot) {
|
|
261
240
|
const key = `${aot.method}\0${aot.path}\0${slot}`;
|
|
262
241
|
if (compactErrorWarned.has(key)) return;
|
|
@@ -266,22 +245,19 @@ function warnCompactErrorLoss(aot, slot) {
|
|
|
266
245
|
function flushCompactErrorWarnings() {
|
|
267
246
|
const total = compactErrorWarned.size;
|
|
268
247
|
if (total > 0 && !isVerboseAotWarnings()) console.warn(`[elysia-aot]: ${total} sealed validator slot${total === 1 ? "" : "s"} ${total === 1 ? "carries" : "carry"} a coercion/codec schema; 422 error details will be coarse (best-effort). Set ELYSIA_AOT_VERBOSE=1 for per-route detail.`);
|
|
269
|
-
|
|
248
|
+
compactErrorWarned.clear();
|
|
270
249
|
}
|
|
271
250
|
function captureBridgeFree(aot, slot, rawSchema) {
|
|
272
|
-
const
|
|
251
|
+
const loc = {
|
|
273
252
|
method: aot.method,
|
|
274
253
|
path: aot.path,
|
|
275
254
|
slot
|
|
276
|
-
}
|
|
255
|
+
};
|
|
256
|
+
const captured = require_compile_aot.Capture.get(loc);
|
|
277
257
|
if (captured) {
|
|
278
258
|
const coerced = captured.coercePlan && typeof rawSchema !== "string" ? require_type_coerce.buildCoercedFromPlan(rawSchema, captured.coercePlan) : rawSchema;
|
|
279
259
|
const bridgeFree = require_compile_handler_frozen_validator.isCapturedBridgeFree(captured, rawSchema, coerced);
|
|
280
|
-
require_compile_aot.Capture.set({
|
|
281
|
-
method: aot.method,
|
|
282
|
-
path: aot.path,
|
|
283
|
-
slot
|
|
284
|
-
}, { bridgeFree });
|
|
260
|
+
require_compile_aot.Capture.set(loc, { bridgeFree });
|
|
285
261
|
if (bridgeFree && !require_compile_handler_frozen_validator.isCompactWalkable(coerced)) warnCompactErrorLoss(aot, slot);
|
|
286
262
|
}
|
|
287
263
|
}
|
|
@@ -333,44 +309,25 @@ function endHandlerCapture() {
|
|
|
333
309
|
}
|
|
334
310
|
return captured;
|
|
335
311
|
}
|
|
336
|
-
/** @internal deterministic session/capture assertions. */
|
|
337
|
-
const getCompilerSessionDiagnostics = () => {
|
|
338
|
-
const session = require_compile_aot.CompilerState.session;
|
|
339
|
-
return {
|
|
340
|
-
active: session !== void 0,
|
|
341
|
-
appAttached: session?.app !== void 0,
|
|
342
|
-
validators: session?.capture?.size ?? 0,
|
|
343
|
-
handlers: session?.handlerCapture?.size ?? 0,
|
|
344
|
-
sucrose: session?.sucroseCache.size ?? 0
|
|
345
|
-
};
|
|
346
|
-
};
|
|
347
312
|
/** @internal preserve registry around in-process AOT analysis */
|
|
348
313
|
const snapshotCompiled = () => require_compile_aot.CompilerState.registry;
|
|
349
314
|
/** @internal restore registry after in-process AOT analysis */
|
|
350
315
|
function restoreCompiled(snapshot) {
|
|
351
316
|
require_compile_aot.CompilerState.registry = snapshot;
|
|
352
317
|
}
|
|
353
|
-
|
|
318
|
+
require_compile_aot.setCaptureImpl({
|
|
354
319
|
sourceOnlyValidator,
|
|
355
320
|
maybeCapture,
|
|
356
321
|
captureMirror,
|
|
357
322
|
captureCodecMirror,
|
|
358
323
|
captureBridgeFree
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
require_compile_aot.setCaptureImpl(impl);
|
|
362
|
-
require_compile_aot_emit.installReconstructImpl();
|
|
363
|
-
}
|
|
364
|
-
installCaptureImpl();
|
|
324
|
+
});
|
|
325
|
+
require_compile_aot_emit.installReconstructImpl();
|
|
365
326
|
|
|
366
327
|
//#endregion
|
|
367
328
|
exports.abortCapture = abortCapture;
|
|
368
329
|
exports.beginValidatorCapture = beginValidatorCapture;
|
|
369
|
-
exports.captureImplementation = impl;
|
|
370
330
|
exports.endHandlerCapture = endHandlerCapture;
|
|
371
331
|
exports.endValidatorCapture = endValidatorCapture;
|
|
372
|
-
exports.getCompilerSessionDiagnostics = getCompilerSessionDiagnostics;
|
|
373
|
-
exports.installCaptureImpl = installCaptureImpl;
|
|
374
|
-
exports.resetCompactErrorWarnings = resetCompactErrorWarnings;
|
|
375
332
|
exports.restoreCompiled = restoreCompiled;
|
|
376
333
|
exports.snapshotCompiled = snapshotCompiled;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { nullObject } from "../utils.mjs";
|
|
2
2
|
import { env } from "../universal/env.mjs";
|
|
3
3
|
import { Capture, CompilerState, aotActivationError, captureImpl, setCaptureImpl } from "./aot.mjs";
|
|
4
|
-
import { isAsyncPredicate } from "../type/elysia/file-type.mjs";
|
|
5
4
|
import { isCapturedBridgeFree, isCompactWalkable } from "./handler/frozen-validator.mjs";
|
|
6
5
|
import { buildCoercedFromPlan, captureCoercePlan } from "../type/coerce.mjs";
|
|
6
|
+
import { isAsyncPredicate } from "../type/elysia/file-type.mjs";
|
|
7
7
|
import { applyPrecomputed, buildDefaultClonerSource, buildObjectDefaultMergeSource, canonical, createMergerFromSource, setDefaultProbeImpl, verifyPreallocatableDefault } from "../type/validator/default-precompute.mjs";
|
|
8
8
|
import { collectExternals } from "./aot-reconstruct.mjs";
|
|
9
9
|
import { captureMirrorCodecs, captureMirrorUnions, installReconstructImpl } from "./aot-emit.mjs";
|
|
10
10
|
import { buildFrozenCheck } from "../type/validator/frozen-check.mjs";
|
|
11
11
|
import { captureCustomErrors } from "../type/validator/custom-error.mjs";
|
|
12
12
|
import { getExactMirror } from "../type/validator/exact-mirror.mjs";
|
|
13
|
-
import { captureStringCodecEntries } from "../type/validator/string-codec-aot.mjs";
|
|
14
|
-
import { Default } from "typebox/value";
|
|
13
|
+
import { captureStringCodecEntries, compileWithBuild } from "../type/validator/string-codec-aot.mjs";
|
|
15
14
|
import { Build, Compile } from "typebox/schema";
|
|
15
|
+
import { Default } from "typebox/value";
|
|
16
16
|
|
|
17
17
|
//#region src/compile/aot-capture.ts
|
|
18
18
|
function emptyContainers(node, depth) {
|
|
@@ -122,13 +122,14 @@ function sourceOnlyValidator(schema) {
|
|
|
122
122
|
}
|
|
123
123
|
function maybeCapture(args) {
|
|
124
124
|
const { aot, slot, hasRef, originalSchema, schema, hasCodec, hasDefault, coerces, normalize, buildResult } = args;
|
|
125
|
+
const loc = {
|
|
126
|
+
method: aot.method,
|
|
127
|
+
path: aot.path,
|
|
128
|
+
slot
|
|
129
|
+
};
|
|
125
130
|
if (hasCodec && !hasRef && coerces && normalize !== false && normalize !== "typebox") {
|
|
126
131
|
const plan = captureCoercePlan(originalSchema, schema);
|
|
127
|
-
if (plan && externalsShape(buildCoercedFromPlan(originalSchema, plan)) === externalsShape(schema)) Capture.set({
|
|
128
|
-
method: aot.method,
|
|
129
|
-
path: aot.path,
|
|
130
|
-
slot
|
|
131
|
-
}, { coercePlan: plan });
|
|
132
|
+
if (plan && externalsShape(buildCoercedFromPlan(originalSchema, plan)) === externalsShape(schema)) Capture.set(loc, { coercePlan: plan });
|
|
132
133
|
}
|
|
133
134
|
const defaultFastPathCapture = {
|
|
134
135
|
precomputeSafe: void 0,
|
|
@@ -149,30 +150,14 @@ function maybeCapture(args) {
|
|
|
149
150
|
defaultFastPathCapture.objectDefaultMerger = defaults.ms ?? (defaults.pod !== void 0 ? buildObjectDefaultMergeSource(defaults.pod) : void 0);
|
|
150
151
|
}
|
|
151
152
|
}
|
|
152
|
-
Capture.set(
|
|
153
|
-
method: aot.method,
|
|
154
|
-
path: aot.path,
|
|
155
|
-
slot
|
|
156
|
-
}, defaultFastPathCapture);
|
|
153
|
+
Capture.set(loc, defaultFastPathCapture);
|
|
157
154
|
const customErrors = captureCustomErrors(schema);
|
|
158
|
-
if (customErrors) Capture.set({
|
|
159
|
-
method: aot.method,
|
|
160
|
-
path: aot.path,
|
|
161
|
-
slot
|
|
162
|
-
}, { customErrors });
|
|
155
|
+
if (customErrors) Capture.set(loc, { customErrors });
|
|
163
156
|
const innerCodecs = captureStringCodecEntries(schema, args.sanitize);
|
|
164
|
-
if (innerCodecs) Capture.set({
|
|
165
|
-
method: aot.method,
|
|
166
|
-
path: aot.path,
|
|
167
|
-
slot
|
|
168
|
-
}, { innerCodecs });
|
|
157
|
+
if (innerCodecs) Capture.set(loc, { innerCodecs });
|
|
169
158
|
const cf = buildFrozenCheck(buildResult, schema);
|
|
170
159
|
if (!cf) return;
|
|
171
|
-
Capture.set({
|
|
172
|
-
method: aot.method,
|
|
173
|
-
path: aot.path,
|
|
174
|
-
slot
|
|
175
|
-
}, {
|
|
160
|
+
Capture.set(loc, {
|
|
176
161
|
...cf,
|
|
177
162
|
async: buildResult.external.variables.some(isAsyncPredicate),
|
|
178
163
|
hasDefault,
|
|
@@ -185,27 +170,24 @@ function captureMirror(schema, aot, slot, sanitize) {
|
|
|
185
170
|
if (!createMirror) return;
|
|
186
171
|
try {
|
|
187
172
|
const emitted = createMirror(schema, {
|
|
188
|
-
Compile,
|
|
173
|
+
Compile: compileWithBuild,
|
|
189
174
|
sanitize,
|
|
190
175
|
emit: true
|
|
191
176
|
});
|
|
192
177
|
if (typeof emitted?.source === "string") {
|
|
193
178
|
const ext = emitted.externals;
|
|
194
|
-
|
|
179
|
+
const loc = {
|
|
195
180
|
method: aot.method,
|
|
196
181
|
path: aot.path,
|
|
197
182
|
slot
|
|
198
|
-
}
|
|
183
|
+
};
|
|
184
|
+
if (!ext) Capture.set(loc, { mirror: {
|
|
199
185
|
source: emitted.source,
|
|
200
186
|
hasExternals: false
|
|
201
187
|
} });
|
|
202
188
|
else if (ext.unions && !ext.hof) {
|
|
203
189
|
const u = captureMirrorUnions(schema, ext.unions);
|
|
204
|
-
if (u) Capture.set({
|
|
205
|
-
method: aot.method,
|
|
206
|
-
path: aot.path,
|
|
207
|
-
slot
|
|
208
|
-
}, { mirror: {
|
|
190
|
+
if (u) Capture.set(loc, { mirror: {
|
|
209
191
|
source: emitted.source,
|
|
210
192
|
hasExternals: true,
|
|
211
193
|
u
|
|
@@ -220,7 +202,7 @@ function captureCodecMirror(schema, aot, slot, sanitize, dir) {
|
|
|
220
202
|
const dirOpt = dir === "decode" ? { decode: true } : { encode: true };
|
|
221
203
|
try {
|
|
222
204
|
const emitted = createMirror(schema, {
|
|
223
|
-
Compile,
|
|
205
|
+
Compile: compileWithBuild,
|
|
224
206
|
sanitize,
|
|
225
207
|
...dirOpt,
|
|
226
208
|
emit: true
|
|
@@ -252,9 +234,6 @@ function captureCodecMirror(schema, aot, slot, sanitize, dir) {
|
|
|
252
234
|
}
|
|
253
235
|
const compactErrorWarned = /* @__PURE__ */ new Set();
|
|
254
236
|
const isVerboseAotWarnings = () => !!env.ELYSIA_AOT_VERBOSE;
|
|
255
|
-
function resetCompactErrorWarnings() {
|
|
256
|
-
compactErrorWarned.clear();
|
|
257
|
-
}
|
|
258
237
|
function warnCompactErrorLoss(aot, slot) {
|
|
259
238
|
const key = `${aot.method}\0${aot.path}\0${slot}`;
|
|
260
239
|
if (compactErrorWarned.has(key)) return;
|
|
@@ -264,22 +243,19 @@ function warnCompactErrorLoss(aot, slot) {
|
|
|
264
243
|
function flushCompactErrorWarnings() {
|
|
265
244
|
const total = compactErrorWarned.size;
|
|
266
245
|
if (total > 0 && !isVerboseAotWarnings()) console.warn(`[elysia-aot]: ${total} sealed validator slot${total === 1 ? "" : "s"} ${total === 1 ? "carries" : "carry"} a coercion/codec schema; 422 error details will be coarse (best-effort). Set ELYSIA_AOT_VERBOSE=1 for per-route detail.`);
|
|
267
|
-
|
|
246
|
+
compactErrorWarned.clear();
|
|
268
247
|
}
|
|
269
248
|
function captureBridgeFree(aot, slot, rawSchema) {
|
|
270
|
-
const
|
|
249
|
+
const loc = {
|
|
271
250
|
method: aot.method,
|
|
272
251
|
path: aot.path,
|
|
273
252
|
slot
|
|
274
|
-
}
|
|
253
|
+
};
|
|
254
|
+
const captured = Capture.get(loc);
|
|
275
255
|
if (captured) {
|
|
276
256
|
const coerced = captured.coercePlan && typeof rawSchema !== "string" ? buildCoercedFromPlan(rawSchema, captured.coercePlan) : rawSchema;
|
|
277
257
|
const bridgeFree = isCapturedBridgeFree(captured, rawSchema, coerced);
|
|
278
|
-
Capture.set({
|
|
279
|
-
method: aot.method,
|
|
280
|
-
path: aot.path,
|
|
281
|
-
slot
|
|
282
|
-
}, { bridgeFree });
|
|
258
|
+
Capture.set(loc, { bridgeFree });
|
|
283
259
|
if (bridgeFree && !isCompactWalkable(coerced)) warnCompactErrorLoss(aot, slot);
|
|
284
260
|
}
|
|
285
261
|
}
|
|
@@ -331,35 +307,20 @@ function endHandlerCapture() {
|
|
|
331
307
|
}
|
|
332
308
|
return captured;
|
|
333
309
|
}
|
|
334
|
-
/** @internal deterministic session/capture assertions. */
|
|
335
|
-
const getCompilerSessionDiagnostics = () => {
|
|
336
|
-
const session = CompilerState.session;
|
|
337
|
-
return {
|
|
338
|
-
active: session !== void 0,
|
|
339
|
-
appAttached: session?.app !== void 0,
|
|
340
|
-
validators: session?.capture?.size ?? 0,
|
|
341
|
-
handlers: session?.handlerCapture?.size ?? 0,
|
|
342
|
-
sucrose: session?.sucroseCache.size ?? 0
|
|
343
|
-
};
|
|
344
|
-
};
|
|
345
310
|
/** @internal preserve registry around in-process AOT analysis */
|
|
346
311
|
const snapshotCompiled = () => CompilerState.registry;
|
|
347
312
|
/** @internal restore registry after in-process AOT analysis */
|
|
348
313
|
function restoreCompiled(snapshot) {
|
|
349
314
|
CompilerState.registry = snapshot;
|
|
350
315
|
}
|
|
351
|
-
|
|
316
|
+
setCaptureImpl({
|
|
352
317
|
sourceOnlyValidator,
|
|
353
318
|
maybeCapture,
|
|
354
319
|
captureMirror,
|
|
355
320
|
captureCodecMirror,
|
|
356
321
|
captureBridgeFree
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
setCaptureImpl(impl);
|
|
360
|
-
installReconstructImpl();
|
|
361
|
-
}
|
|
362
|
-
installCaptureImpl();
|
|
322
|
+
});
|
|
323
|
+
installReconstructImpl();
|
|
363
324
|
|
|
364
325
|
//#endregion
|
|
365
|
-
export { abortCapture, beginValidatorCapture,
|
|
326
|
+
export { abortCapture, beginValidatorCapture, endHandlerCapture, endValidatorCapture, restoreCompiled, snapshotCompiled };
|
|
@@ -6,6 +6,14 @@ declare function reconstructCheck(build: CheckBuildResult): {
|
|
|
6
6
|
value: string;
|
|
7
7
|
};
|
|
8
8
|
declare function externalsMatch(a: unknown[], b: unknown[]): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Align a TypeBox build's externals with the layout the runtime rebuilds from
|
|
11
|
+
* the schema (`collectExternals`). Returns the build as is when they already
|
|
12
|
+
* match, a copy with a prepended remap when TypeBox >= 1.3.31 passed a lone
|
|
13
|
+
* refinement instead of its `~refine` array, or undefined (don't freeze) when
|
|
14
|
+
* a slot can't be proven equal, e.g. a 1.3.31+ format function
|
|
15
|
+
*/
|
|
16
|
+
declare function alignBuildExternals(build: CheckBuildResult, schema: unknown): CheckBuildResult | undefined;
|
|
9
17
|
declare const Source: {
|
|
10
18
|
readonly checkFactory: (identifier: string, code: string) => string;
|
|
11
19
|
readonly checkCode: (defs: string, value: string) => string;
|
|
@@ -13,12 +21,6 @@ declare const Source: {
|
|
|
13
21
|
readonly mirrorFactory: (source: string, hasExternals: boolean) => string;
|
|
14
22
|
readonly bothFactory: (identifier: string, checkDefs: string, checkValue: string, mirrorSource: string, mirrorHasExternals: boolean) => string;
|
|
15
23
|
};
|
|
16
|
-
/**
|
|
17
|
-
* verify that mirror unions can be reconstructed in build time
|
|
18
|
-
*
|
|
19
|
-
* return undefined if not reconstructable
|
|
20
|
-
* `truthUnions` is `mir.externals.unions` (compiled branches).
|
|
21
|
-
*/
|
|
22
24
|
declare function captureMirrorUnions(schema: unknown, truthUnions: any[][]): {
|
|
23
25
|
identifier: string;
|
|
24
26
|
code: string;
|
|
@@ -26,4 +28,4 @@ declare function captureMirrorUnions(schema: unknown, truthUnions: any[][]): {
|
|
|
26
28
|
declare function captureMirrorCodecs(schema: unknown, truthCodecs: Function[], dir?: 'decode' | 'encode'): boolean;
|
|
27
29
|
declare function installReconstructImpl(): void;
|
|
28
30
|
//#endregion
|
|
29
|
-
export { Source, captureMirrorCodecs, captureMirrorUnions, externalsMatch, installReconstructImpl, reconstructCheck };
|
|
31
|
+
export { Source, alignBuildExternals, captureMirrorCodecs, captureMirrorUnions, externalsMatch, installReconstructImpl, reconstructCheck };
|
package/dist/compile/aot-emit.js
CHANGED
|
@@ -28,7 +28,7 @@ function reconstructCheckCode(build) {
|
|
|
28
28
|
const { defs, value } = reconstructCheck(build);
|
|
29
29
|
return checkCode(defs, value);
|
|
30
30
|
}
|
|
31
|
-
const checkFactorySource = (identifier, code) => `
|
|
31
|
+
const checkFactorySource = (identifier, code) => `(${identifier})=>{${code}}`;
|
|
32
32
|
const handlerFactorySource = (alias, code) => `function(h${alias ? "," + alias : ""}){return ${code}}`;
|
|
33
33
|
function externalsMatch(a, b) {
|
|
34
34
|
if (a.length !== b.length) return false;
|
|
@@ -40,19 +40,46 @@ function externalsMatch(a, b) {
|
|
|
40
40
|
if (x.source !== y.source || x.flags !== y.flags) return false;
|
|
41
41
|
continue;
|
|
42
42
|
}
|
|
43
|
-
if (Array.isArray(x) && Array.isArray(y))
|
|
44
|
-
if (x.length !== y.length) return false;
|
|
45
|
-
let ok = true;
|
|
46
|
-
for (let j = 0; j < x.length; j++) if (x[j] !== y[j]) {
|
|
47
|
-
ok = false;
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
if (ok) continue;
|
|
51
|
-
}
|
|
43
|
+
if (Array.isArray(x) && Array.isArray(y) && x.length === y.length && x.findIndex((v, j) => v !== y[j]) === -1) continue;
|
|
52
44
|
return false;
|
|
53
45
|
}
|
|
54
46
|
return true;
|
|
55
47
|
}
|
|
48
|
+
/**
|
|
49
|
+
* Align a TypeBox build's externals with the layout the runtime rebuilds from
|
|
50
|
+
* the schema (`collectExternals`). Returns the build as is when they already
|
|
51
|
+
* match, a copy with a prepended remap when TypeBox >= 1.3.31 passed a lone
|
|
52
|
+
* refinement instead of its `~refine` array, or undefined (don't freeze) when
|
|
53
|
+
* a slot can't be proven equal, e.g. a 1.3.31+ format function
|
|
54
|
+
*/
|
|
55
|
+
function alignBuildExternals(build, schema) {
|
|
56
|
+
const variables = build.external.variables;
|
|
57
|
+
const canonical = require_compile_aot_reconstruct.collectExternals(schema);
|
|
58
|
+
const id = build.external.identifier;
|
|
59
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(id)) return;
|
|
60
|
+
const slots = [];
|
|
61
|
+
let j = 0;
|
|
62
|
+
let same = variables.length === canonical.length;
|
|
63
|
+
for (let i = 0; i < variables.length; i++) {
|
|
64
|
+
const v = variables[i];
|
|
65
|
+
const c = canonical[j];
|
|
66
|
+
if (j < canonical.length && externalsMatch([c], [v])) slots.push(`${id}[${j++}]`);
|
|
67
|
+
else if (Array.isArray(c) && c.length === 1 && c[0] === v) {
|
|
68
|
+
slots.push(`${id}[${j++}][0]`);
|
|
69
|
+
same = false;
|
|
70
|
+
} else return;
|
|
71
|
+
}
|
|
72
|
+
if (j !== canonical.length) return;
|
|
73
|
+
if (same) return build;
|
|
74
|
+
return {
|
|
75
|
+
...build,
|
|
76
|
+
functions: [`${id}=[${slots.join(",")}]`, ...build.functions],
|
|
77
|
+
external: {
|
|
78
|
+
identifier: id,
|
|
79
|
+
variables: canonical
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
56
83
|
const mirrorFactorySource = (source, hasExternals) => hasExternals ? `function(d){${source}}` : `function(v){${source}}`;
|
|
57
84
|
const bothFactorySource = (identifier, checkDefs, checkValue, mirrorSource, mirrorHasExternals) => `function(${identifier},d){${checkDefs}; return{check:${checkValue},clean:${mirrorHasExternals ? `(function(d){${mirrorSource}})(d)` : `function(v){${mirrorSource}}`}}}`;
|
|
58
85
|
const Source = {
|
|
@@ -62,12 +89,6 @@ const Source = {
|
|
|
62
89
|
mirrorFactory: mirrorFactorySource,
|
|
63
90
|
bothFactory: bothFactorySource
|
|
64
91
|
};
|
|
65
|
-
/**
|
|
66
|
-
* verify that mirror unions can be reconstructed in build time
|
|
67
|
-
*
|
|
68
|
-
* return undefined if not reconstructable
|
|
69
|
-
* `truthUnions` is `mir.externals.unions` (compiled branches).
|
|
70
|
-
*/
|
|
71
92
|
function captureMirrorUnions(schema, truthUnions) {
|
|
72
93
|
const branchSchemas = require_compile_aot_reconstruct.collectMirrorUnions(schema);
|
|
73
94
|
if (branchSchemas.length !== truthUnions.length) return;
|
|
@@ -76,9 +97,10 @@ function captureMirrorUnions(schema, truthUnions) {
|
|
|
76
97
|
if (!branchSchemas[ui] || branchSchemas[ui].length !== truthUnions[ui].length) return;
|
|
77
98
|
const branch = [];
|
|
78
99
|
for (let i = 0; i < truthUnions[ui].length; i++) {
|
|
79
|
-
const
|
|
80
|
-
if (!
|
|
81
|
-
|
|
100
|
+
const raw = truthUnions[ui][i]?.buildResult;
|
|
101
|
+
if (!raw?.functions?.length || !raw.entry) return;
|
|
102
|
+
const build = alignBuildExternals(raw, branchSchemas[ui][i]);
|
|
103
|
+
if (!build) return;
|
|
82
104
|
branch.push({
|
|
83
105
|
identifier: build.external.identifier,
|
|
84
106
|
code: reconstructCheckCode(build)
|
|
@@ -100,6 +122,7 @@ function installReconstructImpl() {
|
|
|
100
122
|
|
|
101
123
|
//#endregion
|
|
102
124
|
exports.Source = Source;
|
|
125
|
+
exports.alignBuildExternals = alignBuildExternals;
|
|
103
126
|
exports.captureMirrorCodecs = captureMirrorCodecs;
|
|
104
127
|
exports.captureMirrorUnions = captureMirrorUnions;
|
|
105
128
|
exports.externalsMatch = externalsMatch;
|
|
@@ -27,7 +27,7 @@ function reconstructCheckCode(build) {
|
|
|
27
27
|
const { defs, value } = reconstructCheck(build);
|
|
28
28
|
return checkCode(defs, value);
|
|
29
29
|
}
|
|
30
|
-
const checkFactorySource = (identifier, code) => `
|
|
30
|
+
const checkFactorySource = (identifier, code) => `(${identifier})=>{${code}}`;
|
|
31
31
|
const handlerFactorySource = (alias, code) => `function(h${alias ? "," + alias : ""}){return ${code}}`;
|
|
32
32
|
function externalsMatch(a, b) {
|
|
33
33
|
if (a.length !== b.length) return false;
|
|
@@ -39,19 +39,46 @@ function externalsMatch(a, b) {
|
|
|
39
39
|
if (x.source !== y.source || x.flags !== y.flags) return false;
|
|
40
40
|
continue;
|
|
41
41
|
}
|
|
42
|
-
if (Array.isArray(x) && Array.isArray(y))
|
|
43
|
-
if (x.length !== y.length) return false;
|
|
44
|
-
let ok = true;
|
|
45
|
-
for (let j = 0; j < x.length; j++) if (x[j] !== y[j]) {
|
|
46
|
-
ok = false;
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
if (ok) continue;
|
|
50
|
-
}
|
|
42
|
+
if (Array.isArray(x) && Array.isArray(y) && x.length === y.length && x.findIndex((v, j) => v !== y[j]) === -1) continue;
|
|
51
43
|
return false;
|
|
52
44
|
}
|
|
53
45
|
return true;
|
|
54
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Align a TypeBox build's externals with the layout the runtime rebuilds from
|
|
49
|
+
* the schema (`collectExternals`). Returns the build as is when they already
|
|
50
|
+
* match, a copy with a prepended remap when TypeBox >= 1.3.31 passed a lone
|
|
51
|
+
* refinement instead of its `~refine` array, or undefined (don't freeze) when
|
|
52
|
+
* a slot can't be proven equal, e.g. a 1.3.31+ format function
|
|
53
|
+
*/
|
|
54
|
+
function alignBuildExternals(build, schema) {
|
|
55
|
+
const variables = build.external.variables;
|
|
56
|
+
const canonical = collectExternals(schema);
|
|
57
|
+
const id = build.external.identifier;
|
|
58
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(id)) return;
|
|
59
|
+
const slots = [];
|
|
60
|
+
let j = 0;
|
|
61
|
+
let same = variables.length === canonical.length;
|
|
62
|
+
for (let i = 0; i < variables.length; i++) {
|
|
63
|
+
const v = variables[i];
|
|
64
|
+
const c = canonical[j];
|
|
65
|
+
if (j < canonical.length && externalsMatch([c], [v])) slots.push(`${id}[${j++}]`);
|
|
66
|
+
else if (Array.isArray(c) && c.length === 1 && c[0] === v) {
|
|
67
|
+
slots.push(`${id}[${j++}][0]`);
|
|
68
|
+
same = false;
|
|
69
|
+
} else return;
|
|
70
|
+
}
|
|
71
|
+
if (j !== canonical.length) return;
|
|
72
|
+
if (same) return build;
|
|
73
|
+
return {
|
|
74
|
+
...build,
|
|
75
|
+
functions: [`${id}=[${slots.join(",")}]`, ...build.functions],
|
|
76
|
+
external: {
|
|
77
|
+
identifier: id,
|
|
78
|
+
variables: canonical
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
55
82
|
const mirrorFactorySource = (source, hasExternals) => hasExternals ? `function(d){${source}}` : `function(v){${source}}`;
|
|
56
83
|
const bothFactorySource = (identifier, checkDefs, checkValue, mirrorSource, mirrorHasExternals) => `function(${identifier},d){${checkDefs}; return{check:${checkValue},clean:${mirrorHasExternals ? `(function(d){${mirrorSource}})(d)` : `function(v){${mirrorSource}}`}}}`;
|
|
57
84
|
const Source = {
|
|
@@ -61,12 +88,6 @@ const Source = {
|
|
|
61
88
|
mirrorFactory: mirrorFactorySource,
|
|
62
89
|
bothFactory: bothFactorySource
|
|
63
90
|
};
|
|
64
|
-
/**
|
|
65
|
-
* verify that mirror unions can be reconstructed in build time
|
|
66
|
-
*
|
|
67
|
-
* return undefined if not reconstructable
|
|
68
|
-
* `truthUnions` is `mir.externals.unions` (compiled branches).
|
|
69
|
-
*/
|
|
70
91
|
function captureMirrorUnions(schema, truthUnions) {
|
|
71
92
|
const branchSchemas = collectMirrorUnions(schema);
|
|
72
93
|
if (branchSchemas.length !== truthUnions.length) return;
|
|
@@ -75,9 +96,10 @@ function captureMirrorUnions(schema, truthUnions) {
|
|
|
75
96
|
if (!branchSchemas[ui] || branchSchemas[ui].length !== truthUnions[ui].length) return;
|
|
76
97
|
const branch = [];
|
|
77
98
|
for (let i = 0; i < truthUnions[ui].length; i++) {
|
|
78
|
-
const
|
|
79
|
-
if (!
|
|
80
|
-
|
|
99
|
+
const raw = truthUnions[ui][i]?.buildResult;
|
|
100
|
+
if (!raw?.functions?.length || !raw.entry) return;
|
|
101
|
+
const build = alignBuildExternals(raw, branchSchemas[ui][i]);
|
|
102
|
+
if (!build) return;
|
|
81
103
|
branch.push({
|
|
82
104
|
identifier: build.external.identifier,
|
|
83
105
|
code: reconstructCheckCode(build)
|
|
@@ -98,4 +120,4 @@ function installReconstructImpl() {
|
|
|
98
120
|
}
|
|
99
121
|
|
|
100
122
|
//#endregion
|
|
101
|
-
export { Source, captureMirrorCodecs, captureMirrorUnions, externalsMatch, installReconstructImpl, reconstructCheck };
|
|
123
|
+
export { Source, alignBuildExternals, captureMirrorCodecs, captureMirrorUnions, externalsMatch, installReconstructImpl, reconstructCheck };
|