elysia 2.0.0-beta.2 → 2.0.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/bun/index.d.ts +18 -2
- package/dist/adapter/bun/index.js +467 -110
- package/dist/adapter/bun/index.mjs +467 -112
- package/dist/adapter/types.d.ts +2 -21
- package/dist/adapter/utils.d.ts +14 -3
- package/dist/adapter/utils.js +146 -87
- package/dist/adapter/utils.mjs +148 -90
- package/dist/adapter/web-standard/handler.d.ts +1 -1
- package/dist/adapter/web-standard/handler.js +47 -36
- package/dist/adapter/web-standard/handler.mjs +48 -37
- package/dist/adapter/web-standard/index.js +2 -30
- package/dist/adapter/web-standard/index.mjs +2 -30
- package/dist/adapter/web-standard/utils.js +5 -18
- package/dist/adapter/web-standard/utils.mjs +5 -18
- package/dist/base.d.ts +99 -67
- package/dist/base.js +678 -510
- package/dist/base.mjs +682 -514
- package/dist/compile/aot-capture.d.ts +2 -13
- package/dist/compile/aot-capture.js +26 -69
- package/dist/compile/aot-capture.mjs +28 -67
- package/dist/compile/aot-emit.d.ts +9 -7
- package/dist/compile/aot-emit.js +42 -19
- package/dist/compile/aot-emit.mjs +42 -20
- package/dist/compile/aot.d.ts +17 -19
- package/dist/compile/aot.js +41 -51
- package/dist/compile/aot.mjs +39 -49
- package/dist/compile/handler/descriptor.d.ts +9 -12
- package/dist/compile/handler/descriptor.js +19 -44
- package/dist/compile/handler/descriptor.mjs +20 -42
- package/dist/compile/handler/frozen-validator.d.ts +5 -10
- package/dist/compile/handler/frozen-validator.js +55 -105
- package/dist/compile/handler/frozen-validator.mjs +53 -105
- package/dist/compile/handler/index.d.ts +7 -5
- package/dist/compile/handler/index.js +270 -111
- package/dist/compile/handler/index.mjs +270 -113
- package/dist/compile/handler/jit.d.ts +19 -17
- package/dist/compile/handler/jit.js +222 -149
- package/dist/compile/handler/jit.mjs +224 -152
- package/dist/compile/handler/params.d.ts +1 -4
- package/dist/compile/handler/params.js +10 -5
- package/dist/compile/handler/params.mjs +14 -8
- package/dist/compile/handler/reconstruct.d.ts +2 -2
- package/dist/compile/handler/reconstruct.js +6 -4
- package/dist/compile/handler/reconstruct.mjs +6 -4
- package/dist/compile/handler/static-clone-resolver.d.ts +6 -0
- package/dist/compile/handler/static-clone-resolver.js +8 -0
- package/dist/compile/handler/static-clone-resolver.mjs +7 -0
- package/dist/compile/handler/utils.d.ts +22 -11
- package/dist/compile/handler/utils.js +159 -253
- package/dist/compile/handler/utils.mjs +155 -252
- package/dist/compile/jit-probe.d.ts +2 -2
- package/dist/compile/jit-probe.js +2 -3
- package/dist/compile/jit-probe.mjs +2 -3
- package/dist/compile/lexer.d.ts +7 -4
- package/dist/compile/lexer.js +268 -6
- package/dist/compile/lexer.mjs +268 -4
- package/dist/compile/utils.js +7 -4
- package/dist/compile/utils.mjs +7 -4
- package/dist/compiled.d.ts +0 -1
- package/dist/compiled.js +0 -1
- package/dist/compiled.mjs +0 -1
- package/dist/context.d.ts +14 -4
- package/dist/context.js +17 -32
- package/dist/context.mjs +19 -34
- package/dist/cookie/config.d.ts +7 -2
- package/dist/cookie/config.js +76 -16
- package/dist/cookie/config.mjs +77 -18
- package/dist/cookie/cookie.d.ts +1 -1
- package/dist/cookie/cookie.js +8 -10
- package/dist/cookie/cookie.mjs +8 -10
- package/dist/cookie/crypto.d.ts +8 -7
- package/dist/cookie/crypto.js +51 -40
- package/dist/cookie/crypto.mjs +51 -41
- package/dist/cookie/error.d.ts +1 -2
- package/dist/cookie/error.js +6 -4
- package/dist/cookie/error.mjs +6 -4
- package/dist/cookie/lib.js +7 -2
- package/dist/cookie/lib.mjs +7 -2
- package/dist/cookie/serialize.js +1 -1
- package/dist/cookie/serialize.mjs +1 -1
- package/dist/cookie/types.d.ts +10 -0
- package/dist/cookie/utils.d.ts +4 -8
- package/dist/cookie/utils.js +86 -52
- package/dist/cookie/utils.mjs +89 -54
- package/dist/error.d.ts +113 -103
- package/dist/error.js +181 -117
- package/dist/error.mjs +179 -118
- package/dist/generation.d.ts +2 -2
- package/dist/handler/error.d.ts +26 -15
- package/dist/handler/error.js +77 -96
- package/dist/handler/error.mjs +74 -97
- package/dist/handler/fetch.js +87 -108
- package/dist/handler/fetch.mjs +89 -110
- package/dist/handler/utils.d.ts +12 -6
- package/dist/handler/utils.js +84 -28
- package/dist/handler/utils.mjs +80 -28
- package/dist/index.d.ts +12 -12
- package/dist/index.js +2 -9
- package/dist/index.mjs +1 -1
- package/dist/memory.js +1 -1
- package/dist/memory.mjs +1 -1
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/bun.d.ts +8 -1
- package/dist/plugin/aot/bun.js +16 -9
- package/dist/plugin/aot/bun.mjs +17 -10
- package/dist/plugin/aot/core.d.ts +52 -60
- package/dist/plugin/aot/core.js +208 -109
- package/dist/plugin/aot/core.mjs +205 -111
- package/dist/plugin/aot/esbuild.js +8 -5
- package/dist/plugin/aot/esbuild.mjs +9 -6
- package/dist/plugin/aot/hooks.d.ts +6 -17
- package/dist/plugin/aot/hooks.js +36 -14
- package/dist/plugin/aot/hooks.mjs +37 -16
- package/dist/plugin/aot/rspack-loader.d.ts +1 -5
- package/dist/plugin/aot/rspack-loader.js +1 -10
- package/dist/plugin/aot/rspack-loader.mjs +1 -10
- package/dist/plugin/aot/rspack.js +2 -5
- package/dist/plugin/aot/rspack.mjs +3 -6
- package/dist/plugin/aot/source.d.ts +6 -42
- package/dist/plugin/aot/source.js +71 -71
- package/dist/plugin/aot/source.mjs +72 -72
- package/dist/plugin/aot/treeshake.js +2 -6
- package/dist/plugin/aot/treeshake.mjs +2 -6
- package/dist/plugin/aot/unplugin.d.ts +1 -4
- package/dist/plugin/aot/unplugin.js +4 -13
- package/dist/plugin/aot/unplugin.mjs +4 -13
- package/dist/plugin/aot/vite.d.ts +2 -6
- package/dist/plugin/aot/worker.js +2 -2
- package/dist/plugin/aot/worker.mjs +2 -2
- package/dist/plugin/auto-head.js +1 -10
- package/dist/plugin/auto-head.mjs +1 -10
- package/dist/plugin/trace.d.ts +2 -1
- package/dist/route-table.d.ts +3 -0
- package/dist/route-table.js +16 -11
- package/dist/route-table.mjs +16 -11
- package/dist/schema-snapshot.d.ts +0 -4
- package/dist/schema-snapshot.js +32 -49
- package/dist/schema-snapshot.mjs +32 -49
- package/dist/sucrose.d.ts +6 -55
- package/dist/sucrose.js +103 -731
- package/dist/sucrose.mjs +102 -724
- package/dist/trace.d.ts +5 -8
- package/dist/trace.js +23 -134
- package/dist/trace.mjs +24 -135
- package/dist/type/bridge-live.d.ts +4 -2
- package/dist/type/bridge-live.js +6 -3
- package/dist/type/bridge-live.mjs +4 -2
- package/dist/type/bridge.d.ts +6 -4
- package/dist/type/bridge.js +17 -9
- package/dist/type/bridge.mjs +5 -3
- package/dist/type/coerce-plan.d.ts +5 -5
- package/dist/type/coerce-plan.js +41 -39
- package/dist/type/coerce-plan.mjs +43 -39
- package/dist/type/coerce.d.ts +3 -7
- package/dist/type/coerce.js +18 -75
- package/dist/type/coerce.mjs +19 -76
- package/dist/type/compat.d.ts +3 -0
- package/dist/type/compat.js +23 -14
- package/dist/type/compat.mjs +20 -10
- package/dist/type/elysia/array-buffer.d.ts +4 -1
- package/dist/type/elysia/array-buffer.js +17 -17
- package/dist/type/elysia/array-buffer.mjs +17 -17
- package/dist/type/elysia/array-string.js +2 -40
- package/dist/type/elysia/array-string.mjs +2 -39
- package/dist/type/elysia/array.js +5 -9
- package/dist/type/elysia/array.mjs +5 -9
- package/dist/type/elysia/boolean-string.js +2 -3
- package/dist/type/elysia/boolean-string.mjs +1 -1
- package/dist/type/elysia/boolean.js +3 -12
- package/dist/type/elysia/boolean.mjs +3 -11
- package/dist/type/elysia/cookie.d.ts +3 -4
- package/dist/type/elysia/cookie.js +5 -15
- package/dist/type/elysia/cookie.mjs +5 -15
- package/dist/type/elysia/date.js +13 -20
- package/dist/type/elysia/date.mjs +10 -16
- package/dist/type/elysia/file-type.d.ts +11 -4
- package/dist/type/elysia/file-type.js +17 -2
- package/dist/type/elysia/file-type.mjs +17 -3
- package/dist/type/elysia/file.d.ts +1 -3
- package/dist/type/elysia/file.js +11 -27
- package/dist/type/elysia/file.mjs +11 -12
- package/dist/type/elysia/files.js +7 -11
- package/dist/type/elysia/files.mjs +7 -10
- package/dist/type/elysia/form.js +2 -3
- package/dist/type/elysia/form.mjs +3 -3
- package/dist/type/elysia/integer-string.d.ts +1 -1
- package/dist/type/elysia/integer-string.js +4 -30
- package/dist/type/elysia/integer-string.mjs +5 -30
- package/dist/type/elysia/integer.js +3 -12
- package/dist/type/elysia/integer.mjs +3 -11
- package/dist/type/elysia/intersect.js +0 -5
- package/dist/type/elysia/intersect.mjs +0 -5
- package/dist/type/elysia/json-string.d.ts +7 -0
- package/dist/type/elysia/json-string.js +47 -0
- package/dist/type/elysia/json-string.mjs +46 -0
- package/dist/type/elysia/keep-config.d.ts +14 -0
- package/dist/type/elysia/keep-config.js +62 -0
- package/dist/type/elysia/keep-config.mjs +53 -0
- package/dist/type/elysia/maybe-empty.js +3 -4
- package/dist/type/elysia/maybe-empty.mjs +1 -1
- package/dist/type/elysia/nullable.js +2 -3
- package/dist/type/elysia/nullable.mjs +1 -1
- package/dist/type/elysia/number.d.ts +2 -1
- package/dist/type/elysia/number.js +19 -11
- package/dist/type/elysia/number.mjs +18 -10
- package/dist/type/elysia/numeric-enum.d.ts +1 -1
- package/dist/type/elysia/numeric-enum.js +4 -5
- package/dist/type/elysia/numeric-enum.mjs +3 -3
- package/dist/type/elysia/numeric.d.ts +4 -2
- package/dist/type/elysia/numeric.js +20 -17
- package/dist/type/elysia/numeric.mjs +19 -16
- package/dist/type/elysia/object-string.js +2 -37
- package/dist/type/elysia/object-string.mjs +2 -36
- package/dist/type/elysia/object.js +5 -9
- package/dist/type/elysia/object.mjs +5 -9
- package/dist/type/elysia/optional.js +8 -8
- package/dist/type/elysia/optional.mjs +7 -7
- package/dist/type/elysia/problem.d.ts +20 -0
- package/dist/type/elysia/problem.js +25 -0
- package/dist/type/elysia/problem.mjs +24 -0
- package/dist/type/elysia/string.js +4 -3
- package/dist/type/elysia/string.mjs +4 -2
- package/dist/type/elysia/uint8-array.d.ts +1 -1
- package/dist/type/elysia/uint8-array.js +5 -20
- package/dist/type/elysia/uint8-array.mjs +5 -19
- package/dist/type/elysia/union-enum.js +7 -8
- package/dist/type/elysia/union-enum.mjs +6 -6
- package/dist/type/elysia/union.js +0 -5
- package/dist/type/elysia/union.mjs +0 -5
- package/dist/type/elysia/utils.d.ts +2 -4
- package/dist/type/elysia/utils.js +10 -21
- package/dist/type/elysia/utils.mjs +7 -15
- package/dist/type/exports.d.ts +4 -2
- package/dist/type/exports.js +23 -2
- package/dist/type/exports.mjs +11 -2
- package/dist/type/index.d.ts +10 -2
- package/dist/type/index.js +62 -15
- package/dist/type/index.mjs +65 -11
- package/dist/type/shared.d.ts +3 -9
- package/dist/type/shared.js +44 -97
- package/dist/type/shared.mjs +43 -97
- package/dist/type/sync-require.d.ts +11 -0
- package/dist/type/sync-require.js +14 -0
- package/dist/type/sync-require.mjs +12 -0
- package/dist/type/typebox-system-lite.d.ts +2 -0
- package/dist/type/typebox-system-lite.js +34 -0
- package/dist/type/typebox-system-lite.mjs +3 -0
- package/dist/type/typebox-system-require.d.ts +7 -0
- package/dist/type/typebox-system-require.js +24 -0
- package/dist/type/typebox-system-require.mjs +23 -0
- package/dist/type/typebox-type-live.d.ts +11 -0
- package/dist/type/typebox-type-live.js +45 -0
- package/dist/type/typebox-type-live.mjs +20 -0
- package/dist/type/typebox-type.d.ts +34 -0
- package/dist/type/typebox-type.js +199 -0
- package/dist/type/typebox-type.mjs +86 -0
- package/dist/type/typebox-value-live.d.ts +11 -0
- package/dist/type/typebox-value-live.js +31 -0
- package/dist/type/typebox-value-live.mjs +13 -0
- package/dist/type/typebox-value-ops.d.ts +4 -0
- package/dist/type/typebox-value-ops.js +90 -0
- package/dist/type/typebox-value-ops.mjs +5 -0
- package/dist/type/typebox-value-require.d.ts +8 -0
- package/dist/type/typebox-value-require.js +28 -0
- package/dist/type/typebox-value-require.mjs +25 -0
- package/dist/type/typebox-value.d.ts +35 -0
- package/dist/type/typebox-value.js +161 -0
- package/dist/type/typebox-value.mjs +74 -0
- package/dist/type/utils.js +1 -10
- package/dist/type/utils.mjs +1 -10
- package/dist/type/validator/clean-safe.d.ts +2 -4
- package/dist/type/validator/clean-safe.js +15 -11
- package/dist/type/validator/clean-safe.mjs +16 -10
- package/dist/type/validator/custom-error.js +12 -16
- package/dist/type/validator/custom-error.mjs +11 -14
- package/dist/type/validator/default-precompute.d.ts +9 -1
- package/dist/type/validator/default-precompute.js +40 -77
- package/dist/type/validator/default-precompute.mjs +37 -74
- package/dist/type/validator/exact-mirror-live.d.ts +8 -0
- package/dist/type/validator/exact-mirror-live.js +22 -0
- package/dist/type/validator/exact-mirror-live.mjs +17 -0
- package/dist/type/validator/exact-mirror-require.d.ts +4 -0
- package/dist/type/validator/exact-mirror-require.js +11 -0
- package/dist/type/validator/exact-mirror-require.mjs +9 -0
- package/dist/type/validator/exact-mirror.js +8 -8
- package/dist/type/validator/exact-mirror.mjs +9 -8
- package/dist/type/validator/frozen-check.js +5 -6
- package/dist/type/validator/frozen-check.mjs +6 -7
- package/dist/type/validator/index.d.ts +1 -0
- package/dist/type/validator/index.js +169 -166
- package/dist/type/validator/index.mjs +162 -158
- package/dist/type/validator/string-codec-aot.d.ts +2 -1
- package/dist/type/validator/string-codec-aot.js +8 -2
- package/dist/type/validator/string-codec-aot.mjs +7 -2
- package/dist/type/validator/validator-cache.d.ts +5 -4
- package/dist/type/validator/validator-cache.js +41 -24
- package/dist/type/validator/validator-cache.mjs +40 -22
- package/dist/types.d.ts +263 -95
- package/dist/universal/constants.d.ts +2 -1
- package/dist/universal/constants.js +3 -1
- package/dist/universal/constants.mjs +2 -1
- package/dist/universal/env.js +2 -3
- package/dist/universal/env.mjs +2 -3
- package/dist/universal/file.d.ts +6 -4
- package/dist/universal/file.js +11 -16
- package/dist/universal/file.mjs +12 -16
- package/dist/universal/index.d.ts +2 -2
- package/dist/universal/is-production.d.ts +1 -2
- package/dist/universal/is-production.js +1 -3
- package/dist/universal/is-production.mjs +2 -3
- package/dist/universal/server.d.ts +0 -272
- package/dist/utils.d.ts +43 -7
- package/dist/utils.js +181 -126
- package/dist/utils.mjs +168 -126
- package/dist/validator/index.d.ts +1 -1
- package/dist/validator/index.js +17 -30
- package/dist/validator/index.mjs +18 -31
- package/dist/validator/route.js +2 -1
- package/dist/validator/route.mjs +2 -1
- package/dist/ws/context.d.ts +8 -1
- package/dist/ws/context.js +68 -44
- package/dist/ws/context.mjs +67 -44
- package/dist/ws/parser.js +10 -20
- package/dist/ws/parser.mjs +10 -20
- package/dist/ws/route.d.ts +2 -2
- package/dist/ws/route.js +249 -141
- package/dist/ws/route.mjs +254 -146
- package/dist/ws/types.d.ts +2 -2
- package/package.json +23 -49
- package/dist/compile/analysis-cache.d.ts +0 -6
- package/dist/compile/analysis-cache.js +0 -12
- package/dist/compile/analysis-cache.mjs +0 -11
- package/dist/cookie/index.d.ts +0 -7
- package/dist/cookie/index.js +0 -13
- package/dist/cookie/index.mjs +0 -7
- package/dist/handler/index.d.ts +0 -2
- package/dist/handler/index.js +0 -5
- package/dist/handler/index.mjs +0 -3
package/dist/type/bridge.mjs
CHANGED
|
@@ -31,10 +31,11 @@ let hasTypes = stub("hasTypes");
|
|
|
31
31
|
let mayHaveFileType = stub("mayHaveFileType");
|
|
32
32
|
let HasCodec = stub("HasCodec");
|
|
33
33
|
let Intersect = stub("Intersect");
|
|
34
|
-
let Default = stub("Default");
|
|
35
34
|
let Ref = stub("Ref");
|
|
36
35
|
let Clone = stub("Clone");
|
|
37
36
|
let Check = stub("Check");
|
|
37
|
+
let warmTypebox = stub("warmTypebox");
|
|
38
|
+
let preloadTypebox = () => void 0;
|
|
38
39
|
const isBridgeLive = () => live !== void 0;
|
|
39
40
|
function useTypebox(mod) {
|
|
40
41
|
live = mod;
|
|
@@ -53,11 +54,12 @@ function useTypebox(mod) {
|
|
|
53
54
|
mayHaveFileType = mod.mayHaveFileType;
|
|
54
55
|
HasCodec = mod.HasCodec;
|
|
55
56
|
Intersect = mod.Intersect;
|
|
56
|
-
Default = mod.Default;
|
|
57
57
|
Ref = mod.Ref;
|
|
58
58
|
Clone = mod.Clone;
|
|
59
59
|
Check = mod.Check;
|
|
60
|
+
warmTypebox = mod.warmTypebox;
|
|
61
|
+
preloadTypebox = mod.preloadTypebox;
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
//#endregion
|
|
63
|
-
export { Check, Clone, Compile, Create, Decode,
|
|
65
|
+
export { Check, Clone, Compile, Create, Decode, HasCodec, Intersect, Ref, TypeBoxValidator, TypeBoxValidatorCache, applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, coerceStringToStructure, hasTypes, isBridgeLive, mayHaveFileType, preloadTypebox, useTypebox, warmTypebox };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { BooleanString } from "./elysia/boolean-string.js";
|
|
2
|
-
import { IntegerString } from "./elysia/integer-string.js";
|
|
3
2
|
import { Numeric } from "./elysia/numeric.js";
|
|
4
|
-
import { clearCoerceLeafCache
|
|
3
|
+
import { clearCoerceLeafCache } from "./shared.js";
|
|
4
|
+
import * as _$typebox from "typebox";
|
|
5
5
|
|
|
6
6
|
//#region src/type/coerce-plan.d.ts
|
|
7
7
|
declare const COERCE_LEAF_CTOR: {
|
|
8
8
|
readonly 1: typeof Numeric;
|
|
9
|
-
readonly 2:
|
|
9
|
+
readonly 2: (property?: _$typebox.TNumberOptions) => Readonly<_$typebox.TUnion<[_$typebox.TInteger, _$typebox.TCodec<_$typebox.TRefine<_$typebox.TString>, number>]>>;
|
|
10
10
|
readonly 3: typeof BooleanString;
|
|
11
11
|
};
|
|
12
12
|
interface CoerceLeaf {
|
|
@@ -33,6 +33,6 @@ declare const isCoerceUnion: (x: CoerceNode) => x is CoerceUnion;
|
|
|
33
33
|
type RebuildObjStr = (original: any, site: CoerceObjStr) => any;
|
|
34
34
|
/** @internal */
|
|
35
35
|
declare const COERCE_LEAF_CACHE_LIMIT = 1024;
|
|
36
|
-
declare function buildCoercedFromPlan(original: any, plan:
|
|
36
|
+
declare function buildCoercedFromPlan(original: any, plan: CoerceNode, seen?: Set<string>, objStr?: RebuildObjStr): any;
|
|
37
37
|
//#endregion
|
|
38
|
-
export { COERCE_LEAF_CACHE_LIMIT, COERCE_LEAF_CTOR, CoerceLeaf, CoerceNode, CoerceObjStr, CoercePlan, CoerceUnion, RebuildObjStr, buildCoercedFromPlan, clearCoerceLeafCache,
|
|
38
|
+
export { COERCE_LEAF_CACHE_LIMIT, COERCE_LEAF_CTOR, CoerceLeaf, CoerceNode, CoerceObjStr, CoercePlan, CoerceUnion, RebuildObjStr, buildCoercedFromPlan, clearCoerceLeafCache, isCoerceLeaf, isCoerceObjStr, isCoerceUnion };
|
package/dist/type/coerce-plan.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.js');
|
|
3
2
|
const require_utils = require('../utils.js');
|
|
4
3
|
const require_type_constants = require('./constants.js');
|
|
5
4
|
const require_type_shared = require('./shared.js');
|
|
5
|
+
const require_type_typebox_type = require('./typebox-type.js');
|
|
6
6
|
const require_type_elysia_array = require('./elysia/array.js');
|
|
7
7
|
const require_type_elysia_string = require('./elysia/string.js');
|
|
8
8
|
const require_type_elysia_union = require('./elysia/union.js');
|
|
@@ -11,7 +11,6 @@ const require_type_elysia_object = require('./elysia/object.js');
|
|
|
11
11
|
const require_type_elysia_numeric = require('./elysia/numeric.js');
|
|
12
12
|
const require_type_elysia_boolean_string = require('./elysia/boolean-string.js');
|
|
13
13
|
const require_type_elysia_integer_string = require('./elysia/integer-string.js');
|
|
14
|
-
let typebox_type = require("typebox/type");
|
|
15
14
|
|
|
16
15
|
//#region src/type/coerce-plan.ts
|
|
17
16
|
const COERCE_LEAF_CTOR = {
|
|
@@ -25,28 +24,53 @@ const isCoerceUnion = (x) => Array.isArray(x.u);
|
|
|
25
24
|
const icPlaceholder = () => {
|
|
26
25
|
throw new Error("[elysia] ObjectString/ArrayString shape placeholder was not reconstructed. missing inner-codec (ic) entry");
|
|
27
26
|
};
|
|
28
|
-
function ObjectStringShape(property, _options) {
|
|
29
|
-
const [{ properties, ...constraints }, meta] = require_type_elysia_utils.getMeta(_options ?? require_utils.nullObject());
|
|
30
|
-
const object = require_type_elysia_object.ObjectType(property, constraints);
|
|
31
|
-
const objectString = (0, typebox_type.Decode)((0, typebox_type.Refine)(require_type_elysia_string.StringType(), icPlaceholder, () => "must be an object"), icPlaceholder);
|
|
32
|
-
return require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.ObjectString, require_type_elysia_union.Union([object, objectString], meta));
|
|
33
|
-
}
|
|
34
|
-
function ArrayStringShape(property, _options) {
|
|
35
|
-
const [constraints, meta] = require_type_elysia_utils.getMeta(_options ?? require_utils.nullObject());
|
|
36
|
-
const array = require_type_elysia_array.ArrayType(property, constraints);
|
|
37
|
-
const arrayString = (0, typebox_type.Decode)((0, typebox_type.Refine)(require_type_elysia_string.StringType(), icPlaceholder, () => "must be an array"), icPlaceholder);
|
|
38
|
-
return require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.ArrayString, require_type_elysia_union.Union([array, arrayString], meta));
|
|
39
|
-
}
|
|
40
27
|
const rebuildObjStrShape = (original, site) => {
|
|
41
28
|
const { type, ...rest } = original;
|
|
42
|
-
const
|
|
29
|
+
const isObject = site.os === require_type_constants.ELYSIA_TYPES.ObjectString;
|
|
30
|
+
let inner, meta;
|
|
31
|
+
if (isObject) {
|
|
32
|
+
const [{ properties, ...constraints }, m] = require_type_elysia_utils.getMeta(rest);
|
|
33
|
+
inner = require_type_elysia_object.ObjectType(rest.properties ?? require_utils.nullObject(), constraints);
|
|
34
|
+
meta = m;
|
|
35
|
+
} else {
|
|
36
|
+
const [constraints, m] = require_type_elysia_utils.getMeta(rest);
|
|
37
|
+
inner = require_type_elysia_array.ArrayType(rest.items ?? require_utils.nullObject(), constraints);
|
|
38
|
+
meta = m;
|
|
39
|
+
}
|
|
40
|
+
const node = require_type_elysia_utils.elyType(isObject ? require_type_constants.ELYSIA_TYPES.ObjectString : require_type_constants.ELYSIA_TYPES.ArrayString, require_type_elysia_union.Union([inner, require_type_typebox_type.Decode(require_type_typebox_type.Refine(require_type_elysia_string.StringType(), icPlaceholder, () => isObject ? "must be an object" : "must be an array"), icPlaceholder)], meta));
|
|
43
41
|
if ("o" in site) return Object.defineProperty(node, "~optional", {
|
|
44
42
|
value: site.o,
|
|
45
43
|
enumerable: false
|
|
46
44
|
});
|
|
47
45
|
return node;
|
|
48
46
|
};
|
|
49
|
-
const buildCoerceNode = (original, node, seen, objStr) =>
|
|
47
|
+
const buildCoerceNode = (original, node, seen, objStr) => {
|
|
48
|
+
if (isCoerceLeaf(node)) {
|
|
49
|
+
const key = node.e + (node.c ? JSON.stringify(node.c) : "");
|
|
50
|
+
let leaf;
|
|
51
|
+
if (seen.has(key)) leaf = COERCE_LEAF_CTOR[node.e](node.c);
|
|
52
|
+
else {
|
|
53
|
+
seen.add(key);
|
|
54
|
+
leaf = require_type_shared.coerceLeafCache.get(key);
|
|
55
|
+
if (leaf === void 0) {
|
|
56
|
+
leaf = COERCE_LEAF_CTOR[node.e](node.c);
|
|
57
|
+
if (require_type_shared.coerceLeafCache.size >= 1024) require_utils.evictOldestHalf(require_type_shared.coerceLeafCache);
|
|
58
|
+
require_type_shared.coerceLeafCache.set(key, leaf);
|
|
59
|
+
} else if (require_type_shared.coerceLeafCache.size >= 1024) {
|
|
60
|
+
require_type_shared.coerceLeafCache.delete(key);
|
|
61
|
+
require_type_shared.coerceLeafCache.set(key, leaf);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if ("o" in node) return Object.defineProperty(Object.create(leaf), "~optional", {
|
|
65
|
+
value: node.o,
|
|
66
|
+
enumerable: false
|
|
67
|
+
});
|
|
68
|
+
return leaf;
|
|
69
|
+
}
|
|
70
|
+
if (isCoerceObjStr(node)) return objStr(original, node);
|
|
71
|
+
if (isCoerceUnion(node)) return rebuildUnion(original, node, seen, objStr);
|
|
72
|
+
return buildCoercedFromPlan(original, node, seen, objStr);
|
|
73
|
+
};
|
|
50
74
|
function cloneSchemaNode(original) {
|
|
51
75
|
const out = Object.create(Object.getPrototypeOf(original));
|
|
52
76
|
for (const k in original) out[k] = original[k];
|
|
@@ -63,29 +87,8 @@ function rebuildUnion(original, site, seen, objStr) {
|
|
|
63
87
|
}
|
|
64
88
|
/** @internal */
|
|
65
89
|
const COERCE_LEAF_CACHE_LIMIT = 1024;
|
|
66
|
-
function coerceLeaf(leaf, seen) {
|
|
67
|
-
const key = leaf.e + (leaf.c ? JSON.stringify(leaf.c) : "");
|
|
68
|
-
let node;
|
|
69
|
-
if (seen.has(key)) node = COERCE_LEAF_CTOR[leaf.e](leaf.c);
|
|
70
|
-
else {
|
|
71
|
-
seen.add(key);
|
|
72
|
-
node = require_type_shared.coerceLeafCache.get(key);
|
|
73
|
-
if (node === void 0) {
|
|
74
|
-
node = COERCE_LEAF_CTOR[leaf.e](leaf.c);
|
|
75
|
-
if (require_type_shared.coerceLeafCache.size >= 1024) require_utils.evictOldestHalf(require_type_shared.coerceLeafCache);
|
|
76
|
-
require_type_shared.coerceLeafCache.set(key, node);
|
|
77
|
-
} else if (require_type_shared.coerceLeafCache.size >= 1024) {
|
|
78
|
-
require_type_shared.coerceLeafCache.delete(key);
|
|
79
|
-
require_type_shared.coerceLeafCache.set(key, node);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
if ("o" in leaf) return Object.defineProperty(Object.create(node), "~optional", {
|
|
83
|
-
value: leaf.o,
|
|
84
|
-
enumerable: false
|
|
85
|
-
});
|
|
86
|
-
return node;
|
|
87
|
-
}
|
|
88
90
|
function buildCoercedFromPlan(original, plan, seen = /* @__PURE__ */ new Set(), objStr = rebuildObjStrShape) {
|
|
91
|
+
if (isCoerceLeaf(plan) || isCoerceObjStr(plan) || isCoerceUnion(plan)) return buildCoerceNode(original, plan, seen, objStr);
|
|
89
92
|
const out = cloneSchemaNode(original);
|
|
90
93
|
if (plan.p) {
|
|
91
94
|
const props = { ...original.properties };
|
|
@@ -101,7 +104,6 @@ exports.COERCE_LEAF_CACHE_LIMIT = COERCE_LEAF_CACHE_LIMIT;
|
|
|
101
104
|
exports.COERCE_LEAF_CTOR = COERCE_LEAF_CTOR;
|
|
102
105
|
exports.buildCoercedFromPlan = buildCoercedFromPlan;
|
|
103
106
|
exports.clearCoerceLeafCache = require_type_shared.clearCoerceLeafCache;
|
|
104
|
-
exports.coerceLeafCacheSize = require_type_shared.coerceLeafCacheSize;
|
|
105
107
|
exports.isCoerceLeaf = isCoerceLeaf;
|
|
106
108
|
exports.isCoerceObjStr = isCoerceObjStr;
|
|
107
109
|
exports.isCoerceUnion = isCoerceUnion;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { evictOldestHalf, nullObject } from "../utils.mjs";
|
|
2
2
|
import { ELYSIA_TYPES } from "./constants.mjs";
|
|
3
|
-
import { clearCoerceLeafCache, coerceLeafCache
|
|
3
|
+
import { clearCoerceLeafCache, coerceLeafCache } from "./shared.mjs";
|
|
4
|
+
import { Decode, Refine } from "./typebox-type.mjs";
|
|
4
5
|
import { ArrayType } from "./elysia/array.mjs";
|
|
5
6
|
import { StringType } from "./elysia/string.mjs";
|
|
6
7
|
import { Union } from "./elysia/union.mjs";
|
|
@@ -9,7 +10,6 @@ import { ObjectType } from "./elysia/object.mjs";
|
|
|
9
10
|
import { Numeric } from "./elysia/numeric.mjs";
|
|
10
11
|
import { BooleanString } from "./elysia/boolean-string.mjs";
|
|
11
12
|
import { IntegerString } from "./elysia/integer-string.mjs";
|
|
12
|
-
import { Decode, Refine } from "typebox/type";
|
|
13
13
|
|
|
14
14
|
//#region src/type/coerce-plan.ts
|
|
15
15
|
const COERCE_LEAF_CTOR = {
|
|
@@ -23,28 +23,53 @@ const isCoerceUnion = (x) => Array.isArray(x.u);
|
|
|
23
23
|
const icPlaceholder = () => {
|
|
24
24
|
throw new Error("[elysia] ObjectString/ArrayString shape placeholder was not reconstructed. missing inner-codec (ic) entry");
|
|
25
25
|
};
|
|
26
|
-
function ObjectStringShape(property, _options) {
|
|
27
|
-
const [{ properties, ...constraints }, meta] = getMeta(_options ?? nullObject());
|
|
28
|
-
const object = ObjectType(property, constraints);
|
|
29
|
-
const objectString = Decode(Refine(StringType(), icPlaceholder, () => "must be an object"), icPlaceholder);
|
|
30
|
-
return elyType(ELYSIA_TYPES.ObjectString, Union([object, objectString], meta));
|
|
31
|
-
}
|
|
32
|
-
function ArrayStringShape(property, _options) {
|
|
33
|
-
const [constraints, meta] = getMeta(_options ?? nullObject());
|
|
34
|
-
const array = ArrayType(property, constraints);
|
|
35
|
-
const arrayString = Decode(Refine(StringType(), icPlaceholder, () => "must be an array"), icPlaceholder);
|
|
36
|
-
return elyType(ELYSIA_TYPES.ArrayString, Union([array, arrayString], meta));
|
|
37
|
-
}
|
|
38
26
|
const rebuildObjStrShape = (original, site) => {
|
|
39
27
|
const { type, ...rest } = original;
|
|
40
|
-
const
|
|
28
|
+
const isObject = site.os === ELYSIA_TYPES.ObjectString;
|
|
29
|
+
let inner, meta;
|
|
30
|
+
if (isObject) {
|
|
31
|
+
const [{ properties, ...constraints }, m] = getMeta(rest);
|
|
32
|
+
inner = ObjectType(rest.properties ?? nullObject(), constraints);
|
|
33
|
+
meta = m;
|
|
34
|
+
} else {
|
|
35
|
+
const [constraints, m] = getMeta(rest);
|
|
36
|
+
inner = ArrayType(rest.items ?? nullObject(), constraints);
|
|
37
|
+
meta = m;
|
|
38
|
+
}
|
|
39
|
+
const node = elyType(isObject ? ELYSIA_TYPES.ObjectString : ELYSIA_TYPES.ArrayString, Union([inner, Decode(Refine(StringType(), icPlaceholder, () => isObject ? "must be an object" : "must be an array"), icPlaceholder)], meta));
|
|
41
40
|
if ("o" in site) return Object.defineProperty(node, "~optional", {
|
|
42
41
|
value: site.o,
|
|
43
42
|
enumerable: false
|
|
44
43
|
});
|
|
45
44
|
return node;
|
|
46
45
|
};
|
|
47
|
-
const buildCoerceNode = (original, node, seen, objStr) =>
|
|
46
|
+
const buildCoerceNode = (original, node, seen, objStr) => {
|
|
47
|
+
if (isCoerceLeaf(node)) {
|
|
48
|
+
const key = node.e + (node.c ? JSON.stringify(node.c) : "");
|
|
49
|
+
let leaf;
|
|
50
|
+
if (seen.has(key)) leaf = COERCE_LEAF_CTOR[node.e](node.c);
|
|
51
|
+
else {
|
|
52
|
+
seen.add(key);
|
|
53
|
+
leaf = coerceLeafCache.get(key);
|
|
54
|
+
if (leaf === void 0) {
|
|
55
|
+
leaf = COERCE_LEAF_CTOR[node.e](node.c);
|
|
56
|
+
if (coerceLeafCache.size >= 1024) evictOldestHalf(coerceLeafCache);
|
|
57
|
+
coerceLeafCache.set(key, leaf);
|
|
58
|
+
} else if (coerceLeafCache.size >= 1024) {
|
|
59
|
+
coerceLeafCache.delete(key);
|
|
60
|
+
coerceLeafCache.set(key, leaf);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if ("o" in node) return Object.defineProperty(Object.create(leaf), "~optional", {
|
|
64
|
+
value: node.o,
|
|
65
|
+
enumerable: false
|
|
66
|
+
});
|
|
67
|
+
return leaf;
|
|
68
|
+
}
|
|
69
|
+
if (isCoerceObjStr(node)) return objStr(original, node);
|
|
70
|
+
if (isCoerceUnion(node)) return rebuildUnion(original, node, seen, objStr);
|
|
71
|
+
return buildCoercedFromPlan(original, node, seen, objStr);
|
|
72
|
+
};
|
|
48
73
|
function cloneSchemaNode(original) {
|
|
49
74
|
const out = Object.create(Object.getPrototypeOf(original));
|
|
50
75
|
for (const k in original) out[k] = original[k];
|
|
@@ -61,29 +86,8 @@ function rebuildUnion(original, site, seen, objStr) {
|
|
|
61
86
|
}
|
|
62
87
|
/** @internal */
|
|
63
88
|
const COERCE_LEAF_CACHE_LIMIT = 1024;
|
|
64
|
-
function coerceLeaf(leaf, seen) {
|
|
65
|
-
const key = leaf.e + (leaf.c ? JSON.stringify(leaf.c) : "");
|
|
66
|
-
let node;
|
|
67
|
-
if (seen.has(key)) node = COERCE_LEAF_CTOR[leaf.e](leaf.c);
|
|
68
|
-
else {
|
|
69
|
-
seen.add(key);
|
|
70
|
-
node = coerceLeafCache.get(key);
|
|
71
|
-
if (node === void 0) {
|
|
72
|
-
node = COERCE_LEAF_CTOR[leaf.e](leaf.c);
|
|
73
|
-
if (coerceLeafCache.size >= 1024) evictOldestHalf(coerceLeafCache);
|
|
74
|
-
coerceLeafCache.set(key, node);
|
|
75
|
-
} else if (coerceLeafCache.size >= 1024) {
|
|
76
|
-
coerceLeafCache.delete(key);
|
|
77
|
-
coerceLeafCache.set(key, node);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if ("o" in leaf) return Object.defineProperty(Object.create(node), "~optional", {
|
|
81
|
-
value: leaf.o,
|
|
82
|
-
enumerable: false
|
|
83
|
-
});
|
|
84
|
-
return node;
|
|
85
|
-
}
|
|
86
89
|
function buildCoercedFromPlan(original, plan, seen = /* @__PURE__ */ new Set(), objStr = rebuildObjStrShape) {
|
|
90
|
+
if (isCoerceLeaf(plan) || isCoerceObjStr(plan) || isCoerceUnion(plan)) return buildCoerceNode(original, plan, seen, objStr);
|
|
87
91
|
const out = cloneSchemaNode(original);
|
|
88
92
|
if (plan.p) {
|
|
89
93
|
const props = { ...original.properties };
|
|
@@ -95,4 +99,4 @@ function buildCoercedFromPlan(original, plan, seen = /* @__PURE__ */ new Set(),
|
|
|
95
99
|
}
|
|
96
100
|
|
|
97
101
|
//#endregion
|
|
98
|
-
export { COERCE_LEAF_CACHE_LIMIT, COERCE_LEAF_CTOR, buildCoercedFromPlan, clearCoerceLeafCache,
|
|
102
|
+
export { COERCE_LEAF_CACHE_LIMIT, COERCE_LEAF_CTOR, buildCoercedFromPlan, clearCoerceLeafCache, isCoerceLeaf, isCoerceObjStr, isCoerceUnion };
|
package/dist/type/coerce.d.ts
CHANGED
|
@@ -13,10 +13,6 @@ interface CoerceOptions {
|
|
|
13
13
|
* - `undefined`: Replace all schemas regardless of level
|
|
14
14
|
*/
|
|
15
15
|
root?: boolean | undefined;
|
|
16
|
-
/**
|
|
17
|
-
* Replace only the first specified type found
|
|
18
|
-
**/
|
|
19
|
-
onlyFirst?: 'object' | 'array' | (string & {});
|
|
20
16
|
/**
|
|
21
17
|
* Only root object
|
|
22
18
|
*/
|
|
@@ -34,10 +30,10 @@ declare const coerceQuery: () => CoerceOption[];
|
|
|
34
30
|
declare const coerceBody: () => CoerceOption[];
|
|
35
31
|
declare const coerceFormData: () => CoerceOption[];
|
|
36
32
|
declare const coerceStringToStructure: () => CoerceOption[];
|
|
37
|
-
declare function applyCoercions(schema: BaseSchema | TSchema, coerces: CoerceOption[] | undefined):
|
|
38
|
-
declare function captureCoercePlan(original: any, coerced: any):
|
|
33
|
+
declare function applyCoercions(schema: BaseSchema | TSchema, coerces: CoerceOption[] | undefined): TSchema | BaseSchema;
|
|
34
|
+
declare function captureCoercePlan(original: any, coerced: any): CoerceNode | null;
|
|
39
35
|
/** Full rebuild: scalar leaves + ObjectString/ArrayString sites (wired path). */
|
|
40
|
-
declare const buildCoercedFromPlan: (original: any, plan:
|
|
36
|
+
declare const buildCoercedFromPlan: (original: any, plan: CoerceNode, seen?: Set<string>) => any;
|
|
41
37
|
declare function deferCoercions(): void;
|
|
42
38
|
//#endregion
|
|
43
39
|
export { type CoerceLeaf, type CoerceNode, type CoerceObjStr, CoerceOption, type CoercePlan, applyCoercions, buildCoercedFromPlan, captureCoercePlan, clearCoerceLeafCache, coerce, coerceBody, coerceFormData, coerceQuery, coerceRoot, coerceStringToStructure, deferCoercions, nonAdditionalProperties };
|
package/dist/type/coerce.js
CHANGED
|
@@ -18,9 +18,8 @@ function coerce(schema, fromTo, options) {
|
|
|
18
18
|
for (const [from, to] of fromTo) if (!transformMap.has(from)) transformMap.set(from, to);
|
|
19
19
|
const rootOption = options?.root;
|
|
20
20
|
const memo = /* @__PURE__ */ new WeakMap();
|
|
21
|
-
let stopped = false;
|
|
22
21
|
function walk(node, isRoot, isRootProperty = false) {
|
|
23
|
-
if (!node ||
|
|
22
|
+
if (!node || typeof node !== "object" || node["~elyTyp"] && require_type_constants.primitiveElysiaTypes.has(node["~elyTyp"])) return node;
|
|
24
23
|
const memoed = memo.get(node);
|
|
25
24
|
if (memoed !== void 0) return memoed ?? node;
|
|
26
25
|
if (options?.rootPropertiesOnly && !isRoot && !isRootProperty) return node;
|
|
@@ -34,74 +33,18 @@ function coerce(schema, fromTo, options) {
|
|
|
34
33
|
const { type, ...rest } = node;
|
|
35
34
|
let result = to(rest);
|
|
36
35
|
if (result !== null) {
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
enumerable: false
|
|
45
|
-
});
|
|
36
|
+
if ("~optional" in node) {
|
|
37
|
+
if (Object.isFrozen(result)) result = Object.create(result);
|
|
38
|
+
Object.defineProperty(result, "~optional", {
|
|
39
|
+
value: node["~optional"],
|
|
40
|
+
enumerable: false
|
|
41
|
+
});
|
|
42
|
+
}
|
|
46
43
|
memo.set(node, result);
|
|
47
44
|
return result;
|
|
48
45
|
}
|
|
49
46
|
}
|
|
50
47
|
}
|
|
51
|
-
if (stopped) return node;
|
|
52
|
-
if (options?.rootPropertiesOnly && isRootProperty) {
|
|
53
|
-
let out = node;
|
|
54
|
-
for (const key of [
|
|
55
|
-
"anyOf",
|
|
56
|
-
"oneOf",
|
|
57
|
-
"allOf"
|
|
58
|
-
]) {
|
|
59
|
-
const arr = node[key];
|
|
60
|
-
if (!Array.isArray(arr)) continue;
|
|
61
|
-
let newArr;
|
|
62
|
-
for (let i = 0, len = arr.length; i < len; i++) {
|
|
63
|
-
const item = arr[i];
|
|
64
|
-
const r = walk(item, false, true);
|
|
65
|
-
if (stopped && !newArr) {
|
|
66
|
-
memo.set(node, node);
|
|
67
|
-
return node;
|
|
68
|
-
}
|
|
69
|
-
if (r !== item) {
|
|
70
|
-
newArr ??= arr.slice();
|
|
71
|
-
newArr[i] = r;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
if (newArr) {
|
|
75
|
-
out = require_type_shared.cloneNode(node, out);
|
|
76
|
-
out[key] = newArr;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
if (node.items) {
|
|
80
|
-
const items = node.items;
|
|
81
|
-
if (Array.isArray(items)) {
|
|
82
|
-
let newItems;
|
|
83
|
-
for (let i = 0, len = items.length; i < len; i++) {
|
|
84
|
-
const r = walk(items[i], false, true);
|
|
85
|
-
if (r !== items[i]) {
|
|
86
|
-
newItems ??= items.slice();
|
|
87
|
-
newItems[i] = r;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
if (newItems) {
|
|
91
|
-
out = require_type_shared.cloneNode(node, out);
|
|
92
|
-
out.items = newItems;
|
|
93
|
-
}
|
|
94
|
-
} else {
|
|
95
|
-
const r = walk(items, false, true);
|
|
96
|
-
if (r !== items) {
|
|
97
|
-
out = require_type_shared.cloneNode(node, out);
|
|
98
|
-
out.items = r;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
memo.set(node, out);
|
|
103
|
-
return out;
|
|
104
|
-
}
|
|
105
48
|
let out = node;
|
|
106
49
|
for (const key of [
|
|
107
50
|
"anyOf",
|
|
@@ -113,8 +56,7 @@ function coerce(schema, fromTo, options) {
|
|
|
113
56
|
let newArr;
|
|
114
57
|
for (let i = 0, len = arr.length; i < len; i++) {
|
|
115
58
|
const item = arr[i];
|
|
116
|
-
const r = walk(item, false);
|
|
117
|
-
if (stopped && !newArr) return node;
|
|
59
|
+
const r = walk(item, false, isRootProperty);
|
|
118
60
|
if (r !== item) {
|
|
119
61
|
newArr ??= arr.slice();
|
|
120
62
|
newArr[i] = r;
|
|
@@ -125,7 +67,7 @@ function coerce(schema, fromTo, options) {
|
|
|
125
67
|
out[key] = newArr;
|
|
126
68
|
}
|
|
127
69
|
}
|
|
128
|
-
if (node.not) {
|
|
70
|
+
if (node.not && !isRootProperty) {
|
|
129
71
|
const r = walk(node.not, false);
|
|
130
72
|
if (r !== node.not) {
|
|
131
73
|
out = require_type_shared.cloneNode(node, out);
|
|
@@ -138,7 +80,7 @@ function coerce(schema, fromTo, options) {
|
|
|
138
80
|
let newItems;
|
|
139
81
|
for (let i = 0, len = items.length; i < len; i++) {
|
|
140
82
|
const item = items[i];
|
|
141
|
-
const r = walk(item, false);
|
|
83
|
+
const r = walk(item, false, isRootProperty);
|
|
142
84
|
if (r !== item) {
|
|
143
85
|
newItems ??= items.slice();
|
|
144
86
|
newItems[i] = r;
|
|
@@ -149,13 +91,17 @@ function coerce(schema, fromTo, options) {
|
|
|
149
91
|
out.items = newItems;
|
|
150
92
|
}
|
|
151
93
|
} else {
|
|
152
|
-
const r = walk(items, false);
|
|
94
|
+
const r = walk(items, false, isRootProperty);
|
|
153
95
|
if (r !== items) {
|
|
154
96
|
out = require_type_shared.cloneNode(node, out);
|
|
155
97
|
out.items = r;
|
|
156
98
|
}
|
|
157
99
|
}
|
|
158
100
|
}
|
|
101
|
+
if (isRootProperty) {
|
|
102
|
+
memo.set(node, out);
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
159
105
|
if (node.properties) {
|
|
160
106
|
let newProps;
|
|
161
107
|
const props = node.properties;
|
|
@@ -231,10 +177,7 @@ const coerceFormData = () => _coerceFormData ??= [
|
|
|
231
177
|
[[["Integer", require_type_elysia_integer_string.IntegerString]]],
|
|
232
178
|
...coerceRoot(),
|
|
233
179
|
[[["Object", toObjectString]], { rootPropertiesOnly: true }],
|
|
234
|
-
[[["Array", toArrayString]], {
|
|
235
|
-
root: false,
|
|
236
|
-
onlyFirst: "array"
|
|
237
|
-
}]
|
|
180
|
+
[[["Array", toArrayString]], { root: false }]
|
|
238
181
|
];
|
|
239
182
|
let _coerceStringToStructure;
|
|
240
183
|
const coerceStringToStructure = () => _coerceStringToStructure ??= [[[["Object", toObjectString], ["Array", toArrayString]], { rootPropertiesOnly: true }], ...coerceRoot()];
|
|
@@ -308,7 +251,7 @@ function captureCoercePlan(original, coerced) {
|
|
|
308
251
|
return plan.p || plan.i ? plan : null;
|
|
309
252
|
};
|
|
310
253
|
const plan = walk(original, coerced);
|
|
311
|
-
if (!bakeable || !any || !plan
|
|
254
|
+
if (!bakeable || !any || !plan) return null;
|
|
312
255
|
if (!jsonSafe(plan)) return null;
|
|
313
256
|
return plan;
|
|
314
257
|
}
|
package/dist/type/coerce.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import { ObjectString } from "./elysia/object-string.mjs";
|
|
|
6
6
|
import { Numeric } from "./elysia/numeric.mjs";
|
|
7
7
|
import { BooleanString } from "./elysia/boolean-string.mjs";
|
|
8
8
|
import { IntegerString } from "./elysia/integer-string.mjs";
|
|
9
|
-
import { COERCE_LEAF_CTOR, buildCoercedFromPlan as buildCoercedFromPlan$1
|
|
9
|
+
import { COERCE_LEAF_CTOR, buildCoercedFromPlan as buildCoercedFromPlan$1 } from "./coerce-plan.mjs";
|
|
10
10
|
|
|
11
11
|
//#region src/type/coerce.ts
|
|
12
12
|
/**
|
|
@@ -17,9 +17,8 @@ function coerce(schema, fromTo, options) {
|
|
|
17
17
|
for (const [from, to] of fromTo) if (!transformMap.has(from)) transformMap.set(from, to);
|
|
18
18
|
const rootOption = options?.root;
|
|
19
19
|
const memo = /* @__PURE__ */ new WeakMap();
|
|
20
|
-
let stopped = false;
|
|
21
20
|
function walk(node, isRoot, isRootProperty = false) {
|
|
22
|
-
if (!node ||
|
|
21
|
+
if (!node || typeof node !== "object" || node["~elyTyp"] && primitiveElysiaTypes.has(node["~elyTyp"])) return node;
|
|
23
22
|
const memoed = memo.get(node);
|
|
24
23
|
if (memoed !== void 0) return memoed ?? node;
|
|
25
24
|
if (options?.rootPropertiesOnly && !isRoot && !isRootProperty) return node;
|
|
@@ -33,74 +32,18 @@ function coerce(schema, fromTo, options) {
|
|
|
33
32
|
const { type, ...rest } = node;
|
|
34
33
|
let result = to(rest);
|
|
35
34
|
if (result !== null) {
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
enumerable: false
|
|
44
|
-
});
|
|
35
|
+
if ("~optional" in node) {
|
|
36
|
+
if (Object.isFrozen(result)) result = Object.create(result);
|
|
37
|
+
Object.defineProperty(result, "~optional", {
|
|
38
|
+
value: node["~optional"],
|
|
39
|
+
enumerable: false
|
|
40
|
+
});
|
|
41
|
+
}
|
|
45
42
|
memo.set(node, result);
|
|
46
43
|
return result;
|
|
47
44
|
}
|
|
48
45
|
}
|
|
49
46
|
}
|
|
50
|
-
if (stopped) return node;
|
|
51
|
-
if (options?.rootPropertiesOnly && isRootProperty) {
|
|
52
|
-
let out = node;
|
|
53
|
-
for (const key of [
|
|
54
|
-
"anyOf",
|
|
55
|
-
"oneOf",
|
|
56
|
-
"allOf"
|
|
57
|
-
]) {
|
|
58
|
-
const arr = node[key];
|
|
59
|
-
if (!Array.isArray(arr)) continue;
|
|
60
|
-
let newArr;
|
|
61
|
-
for (let i = 0, len = arr.length; i < len; i++) {
|
|
62
|
-
const item = arr[i];
|
|
63
|
-
const r = walk(item, false, true);
|
|
64
|
-
if (stopped && !newArr) {
|
|
65
|
-
memo.set(node, node);
|
|
66
|
-
return node;
|
|
67
|
-
}
|
|
68
|
-
if (r !== item) {
|
|
69
|
-
newArr ??= arr.slice();
|
|
70
|
-
newArr[i] = r;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (newArr) {
|
|
74
|
-
out = cloneNode(node, out);
|
|
75
|
-
out[key] = newArr;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (node.items) {
|
|
79
|
-
const items = node.items;
|
|
80
|
-
if (Array.isArray(items)) {
|
|
81
|
-
let newItems;
|
|
82
|
-
for (let i = 0, len = items.length; i < len; i++) {
|
|
83
|
-
const r = walk(items[i], false, true);
|
|
84
|
-
if (r !== items[i]) {
|
|
85
|
-
newItems ??= items.slice();
|
|
86
|
-
newItems[i] = r;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (newItems) {
|
|
90
|
-
out = cloneNode(node, out);
|
|
91
|
-
out.items = newItems;
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
const r = walk(items, false, true);
|
|
95
|
-
if (r !== items) {
|
|
96
|
-
out = cloneNode(node, out);
|
|
97
|
-
out.items = r;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
memo.set(node, out);
|
|
102
|
-
return out;
|
|
103
|
-
}
|
|
104
47
|
let out = node;
|
|
105
48
|
for (const key of [
|
|
106
49
|
"anyOf",
|
|
@@ -112,8 +55,7 @@ function coerce(schema, fromTo, options) {
|
|
|
112
55
|
let newArr;
|
|
113
56
|
for (let i = 0, len = arr.length; i < len; i++) {
|
|
114
57
|
const item = arr[i];
|
|
115
|
-
const r = walk(item, false);
|
|
116
|
-
if (stopped && !newArr) return node;
|
|
58
|
+
const r = walk(item, false, isRootProperty);
|
|
117
59
|
if (r !== item) {
|
|
118
60
|
newArr ??= arr.slice();
|
|
119
61
|
newArr[i] = r;
|
|
@@ -124,7 +66,7 @@ function coerce(schema, fromTo, options) {
|
|
|
124
66
|
out[key] = newArr;
|
|
125
67
|
}
|
|
126
68
|
}
|
|
127
|
-
if (node.not) {
|
|
69
|
+
if (node.not && !isRootProperty) {
|
|
128
70
|
const r = walk(node.not, false);
|
|
129
71
|
if (r !== node.not) {
|
|
130
72
|
out = cloneNode(node, out);
|
|
@@ -137,7 +79,7 @@ function coerce(schema, fromTo, options) {
|
|
|
137
79
|
let newItems;
|
|
138
80
|
for (let i = 0, len = items.length; i < len; i++) {
|
|
139
81
|
const item = items[i];
|
|
140
|
-
const r = walk(item, false);
|
|
82
|
+
const r = walk(item, false, isRootProperty);
|
|
141
83
|
if (r !== item) {
|
|
142
84
|
newItems ??= items.slice();
|
|
143
85
|
newItems[i] = r;
|
|
@@ -148,13 +90,17 @@ function coerce(schema, fromTo, options) {
|
|
|
148
90
|
out.items = newItems;
|
|
149
91
|
}
|
|
150
92
|
} else {
|
|
151
|
-
const r = walk(items, false);
|
|
93
|
+
const r = walk(items, false, isRootProperty);
|
|
152
94
|
if (r !== items) {
|
|
153
95
|
out = cloneNode(node, out);
|
|
154
96
|
out.items = r;
|
|
155
97
|
}
|
|
156
98
|
}
|
|
157
99
|
}
|
|
100
|
+
if (isRootProperty) {
|
|
101
|
+
memo.set(node, out);
|
|
102
|
+
return out;
|
|
103
|
+
}
|
|
158
104
|
if (node.properties) {
|
|
159
105
|
let newProps;
|
|
160
106
|
const props = node.properties;
|
|
@@ -230,10 +176,7 @@ const coerceFormData = () => _coerceFormData ??= [
|
|
|
230
176
|
[[["Integer", IntegerString]]],
|
|
231
177
|
...coerceRoot(),
|
|
232
178
|
[[["Object", toObjectString]], { rootPropertiesOnly: true }],
|
|
233
|
-
[[["Array", toArrayString]], {
|
|
234
|
-
root: false,
|
|
235
|
-
onlyFirst: "array"
|
|
236
|
-
}]
|
|
179
|
+
[[["Array", toArrayString]], { root: false }]
|
|
237
180
|
];
|
|
238
181
|
let _coerceStringToStructure;
|
|
239
182
|
const coerceStringToStructure = () => _coerceStringToStructure ??= [[[["Object", toObjectString], ["Array", toArrayString]], { rootPropertiesOnly: true }], ...coerceRoot()];
|
|
@@ -307,7 +250,7 @@ function captureCoercePlan(original, coerced) {
|
|
|
307
250
|
return plan.p || plan.i ? plan : null;
|
|
308
251
|
};
|
|
309
252
|
const plan = walk(original, coerced);
|
|
310
|
-
if (!bakeable || !any || !plan
|
|
253
|
+
if (!bakeable || !any || !plan) return null;
|
|
311
254
|
if (!jsonSafe(plan)) return null;
|
|
312
255
|
return plan;
|
|
313
256
|
}
|
package/dist/type/compat.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import { TypeboxTypeNamespaces } from "./typebox-type.js";
|
|
2
|
+
import { TypeboxNamespaces } from "./typebox-value.js";
|
|
1
3
|
import { CreateMirror } from "./validator/exact-mirror.js";
|
|
2
4
|
|
|
3
5
|
//#region src/type/compat.d.ts
|
|
4
6
|
declare function setupTypebox(options?: {
|
|
5
7
|
exactMirror?: CreateMirror;
|
|
8
|
+
typebox?: Partial<TypeboxNamespaces & TypeboxTypeNamespaces>;
|
|
6
9
|
}): void;
|
|
7
10
|
//#endregion
|
|
8
11
|
export { setupTypebox };
|