elysia 2.0.0-beta.2 → 2.0.0-beta.20
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 +11 -13
- package/dist/compile/aot.js +34 -46
- package/dist/compile/aot.mjs +35 -45
- package/dist/compile/handler/descriptor.d.ts +9 -12
- package/dist/compile/handler/descriptor.js +17 -41
- package/dist/compile/handler/descriptor.mjs +18 -39
- 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 +6 -5
- package/dist/compile/handler/index.js +148 -109
- package/dist/compile/handler/index.mjs +149 -111
- package/dist/compile/handler/jit.d.ts +17 -17
- package/dist/compile/handler/jit.js +220 -148
- package/dist/compile/handler/jit.mjs +222 -151
- 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 +4 -3
- package/dist/compile/handler/reconstruct.mjs +4 -3
- 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 +1 -0
- package/dist/cookie/config.js +9 -9
- package/dist/cookie/config.mjs +9 -9
- 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 +47 -60
- package/dist/plugin/aot/core.js +172 -109
- package/dist/plugin/aot/core.mjs +169 -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 +47 -62
- package/dist/plugin/aot/source.mjs +48 -63
- 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 +29 -47
- package/dist/schema-snapshot.mjs +29 -47
- 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 +2 -6
- 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/constants.d.ts +1 -1
- 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/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 +3 -2
- package/dist/type/exports.js +13 -2
- package/dist/type/exports.mjs +10 -2
- package/dist/type/index.d.ts +10 -2
- package/dist/type/index.js +52 -15
- package/dist/type/index.mjs +55 -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 +37 -0
- package/dist/type/typebox-type-live.mjs +20 -0
- package/dist/type/typebox-type.d.ts +26 -0
- package/dist/type/typebox-type.js +135 -0
- package/dist/type/typebox-type.mjs +70 -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 +261 -94
- 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 +41 -7
- package/dist/utils.js +158 -126
- package/dist/utils.mjs +147 -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 +219 -139
- package/dist/ws/route.mjs +223 -143
- 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/schema-snapshot.js
CHANGED
|
@@ -52,8 +52,7 @@ function isImmutableNode(value) {
|
|
|
52
52
|
immutableNodes.set(value, immutable);
|
|
53
53
|
return immutable;
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
function deepCloneSchema(value, seen, canShare = true) {
|
|
55
|
+
function deepCloneSchema(value, freeze, seen, canShare = true) {
|
|
57
56
|
if (value === null || typeof value !== "object") return value;
|
|
58
57
|
const cached = seen?.get(value);
|
|
59
58
|
if (cached) return cached;
|
|
@@ -61,8 +60,8 @@ function deepCloneSchema(value, seen, canShare = true) {
|
|
|
61
60
|
const out = [];
|
|
62
61
|
seen ??= /* @__PURE__ */ new Map();
|
|
63
62
|
seen.set(value, out);
|
|
64
|
-
for (let i = 0; i < value.length; i++) out[i] = deepCloneSchema(value[i], seen);
|
|
65
|
-
return
|
|
63
|
+
for (let i = 0; i < value.length; i++) out[i] = deepCloneSchema(value[i], freeze, seen);
|
|
64
|
+
return freeze ? Object.freeze(out) : out;
|
|
66
65
|
}
|
|
67
66
|
if (canShare && isImmutableNode(value)) return value;
|
|
68
67
|
const proto = Object.getPrototypeOf(value);
|
|
@@ -84,7 +83,7 @@ function deepCloneSchema(value, seen, canShare = true) {
|
|
|
84
83
|
});
|
|
85
84
|
continue;
|
|
86
85
|
}
|
|
87
|
-
const cloned = deepCloneSchema(property, seen);
|
|
86
|
+
const cloned = deepCloneSchema(property, freeze, seen);
|
|
88
87
|
if (key === "__proto__") Object.defineProperty(out, key, {
|
|
89
88
|
value: cloned,
|
|
90
89
|
enumerable: true,
|
|
@@ -97,7 +96,7 @@ function deepCloneSchema(value, seen, canShare = true) {
|
|
|
97
96
|
for (let i = 0; i < symbols.length; i++) {
|
|
98
97
|
const key = symbols[i];
|
|
99
98
|
const property = value[key];
|
|
100
|
-
if (isEnumerable.call(value, key)) out[key] = deepCloneSchema(property, seen);
|
|
99
|
+
if (isEnumerable.call(value, key)) out[key] = deepCloneSchema(property, freeze, seen);
|
|
101
100
|
else Object.defineProperty(out, key, {
|
|
102
101
|
value: property,
|
|
103
102
|
enumerable: false,
|
|
@@ -105,7 +104,7 @@ function deepCloneSchema(value, seen, canShare = true) {
|
|
|
105
104
|
configurable: true
|
|
106
105
|
});
|
|
107
106
|
}
|
|
108
|
-
return
|
|
107
|
+
return freeze ? Object.freeze(out) : out;
|
|
109
108
|
}
|
|
110
109
|
const refIds = /* @__PURE__ */ new WeakMap();
|
|
111
110
|
let nextRefId = 0;
|
|
@@ -114,9 +113,8 @@ function refKey(value) {
|
|
|
114
113
|
if (id === void 0) refIds.set(value, id = ++nextRefId);
|
|
115
114
|
return "r" + id + ";";
|
|
116
115
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
function fingerprint(value, seen, canShare = true) {
|
|
116
|
+
const byRefKey = (value, state) => value !== null && (typeof value === "object" || typeof value === "function") ? refKey(value) : fingerprint(value, void 0, state);
|
|
117
|
+
function fingerprint(value, seen, state, canShare = true) {
|
|
120
118
|
if (value === null) return "z;";
|
|
121
119
|
const type = typeof value;
|
|
122
120
|
if (type !== "object") switch (type) {
|
|
@@ -127,7 +125,7 @@ function fingerprint(value, seen, canShare = true) {
|
|
|
127
125
|
case "undefined": return "u;";
|
|
128
126
|
case "bigint": return "g" + value + ";";
|
|
129
127
|
default:
|
|
130
|
-
|
|
128
|
+
state.bail = true;
|
|
131
129
|
return "y;";
|
|
132
130
|
}
|
|
133
131
|
const backReference = seen?.get(value);
|
|
@@ -136,7 +134,7 @@ function fingerprint(value, seen, canShare = true) {
|
|
|
136
134
|
seen ??= /* @__PURE__ */ new Map();
|
|
137
135
|
seen.set(value, seen.size);
|
|
138
136
|
let out = "[";
|
|
139
|
-
for (let i = 0; i < value.length; i++) out += fingerprint(value[i], seen);
|
|
137
|
+
for (let i = 0; i < value.length; i++) out += fingerprint(value[i], seen, state);
|
|
140
138
|
return out + "];";
|
|
141
139
|
}
|
|
142
140
|
if (canShare && isImmutableNode(value)) return refKey(value);
|
|
@@ -151,15 +149,18 @@ function fingerprint(value, seen, canShare = true) {
|
|
|
151
149
|
const key = keys[i];
|
|
152
150
|
const property = value[key];
|
|
153
151
|
out += "k" + key.length + ":" + key;
|
|
154
|
-
out += !allEnumerable && !isEnumerable.call(value, key) ? "!" + byRefKey(property) : "=" + fingerprint(property, seen);
|
|
152
|
+
out += !allEnumerable && !isEnumerable.call(value, key) ? "!" + byRefKey(property, state) : "=" + fingerprint(property, seen, state);
|
|
155
153
|
}
|
|
156
|
-
if (Object.getOwnPropertySymbols(value).length)
|
|
154
|
+
if (Object.getOwnPropertySymbols(value).length) state.bail = true;
|
|
157
155
|
return out + "};";
|
|
158
156
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
157
|
+
function cloneOrWarn(object, freeze) {
|
|
158
|
+
try {
|
|
159
|
+
return deepCloneSchema(object, freeze, void 0, false);
|
|
160
|
+
} catch (error) {
|
|
161
|
+
console.warn("[Elysia] schema snapshot failed; schema kept by reference:", error);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
163
164
|
function snapshotSchema(schema) {
|
|
164
165
|
if (schema === null || typeof schema !== "object") return schema;
|
|
165
166
|
const object = schema;
|
|
@@ -167,13 +168,8 @@ function snapshotSchema(schema) {
|
|
|
167
168
|
if (produced.has(object) && !Object.isFrozen(object)) return schema;
|
|
168
169
|
const existing = modelSnapshots.get(object);
|
|
169
170
|
if (existing) return existing;
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
cloned = deepCloneSchema(object, void 0, false);
|
|
173
|
-
} catch (error) {
|
|
174
|
-
console.warn("[Elysia] schema snapshot failed; schema kept by reference:", error);
|
|
175
|
-
return schema;
|
|
176
|
-
}
|
|
171
|
+
const cloned = cloneOrWarn(object, false);
|
|
172
|
+
if (cloned === void 0) return schema;
|
|
177
173
|
modelSnapshots.set(object, cloned);
|
|
178
174
|
produced.add(cloned);
|
|
179
175
|
return cloned;
|
|
@@ -193,11 +189,11 @@ function internSchema(schema, intern) {
|
|
|
193
189
|
if (existing) return existing;
|
|
194
190
|
let key;
|
|
195
191
|
if (intern) {
|
|
196
|
-
|
|
192
|
+
const state = { bail: false };
|
|
197
193
|
try {
|
|
198
|
-
key = fingerprint(object, void 0, false);
|
|
194
|
+
key = fingerprint(object, void 0, state, false);
|
|
199
195
|
} catch {}
|
|
200
|
-
if (
|
|
196
|
+
if (state.bail) key = void 0;
|
|
201
197
|
}
|
|
202
198
|
if (key !== void 0) {
|
|
203
199
|
const shared = interned.get(key);
|
|
@@ -210,16 +206,8 @@ function internSchema(schema, intern) {
|
|
|
210
206
|
return shared;
|
|
211
207
|
}
|
|
212
208
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
try {
|
|
216
|
-
cloned = deepCloneSchema(object, void 0, false);
|
|
217
|
-
} catch (error) {
|
|
218
|
-
console.warn("[Elysia] schema snapshot failed; schema kept by reference:", error);
|
|
219
|
-
return schema;
|
|
220
|
-
} finally {
|
|
221
|
-
freezeClones = false;
|
|
222
|
-
}
|
|
209
|
+
const cloned = cloneOrWarn(object, true);
|
|
210
|
+
if (cloned === void 0) return schema;
|
|
223
211
|
hookSnapshots.set(object, cloned);
|
|
224
212
|
produced.add(cloned);
|
|
225
213
|
if (key !== void 0) {
|
|
@@ -242,18 +230,12 @@ function isStatusMap(response) {
|
|
|
242
230
|
for (const key in response) if (!Number.isInteger(Number(key))) return false;
|
|
243
231
|
return true;
|
|
244
232
|
}
|
|
233
|
+
const hasSlot = (target) => schemaSlots.some((slot) => target[slot] != null) || target.response != null;
|
|
245
234
|
function snapshotHookSchemas(hook) {
|
|
246
235
|
if (!hook) return hook;
|
|
247
|
-
|
|
248
|
-
if (schemaSlots.some((slot) => hook[slot] != null) || hook.response != null) needsCopy = true;
|
|
236
|
+
const needsCopy = hasSlot(hook);
|
|
249
237
|
const schemas = hook.schemas;
|
|
250
|
-
if (!needsCopy && Array.isArray(schemas))
|
|
251
|
-
for (const entry of schemas) if (entry && (schemaSlots.some((slot) => entry[slot] != null) || entry.response != null)) {
|
|
252
|
-
needsCopy = true;
|
|
253
|
-
break;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
if (!needsCopy) return hook;
|
|
238
|
+
if (!needsCopy && !(Array.isArray(schemas) && schemas.some((e) => e && hasSlot(e)))) return hook;
|
|
257
239
|
const intern = !require_universal_env.env.ELYSIA_AOT_BUILD;
|
|
258
240
|
const copy = Object.assign(Object.create(Object.getPrototypeOf(hook)), hook);
|
|
259
241
|
snapshotSlots(copy, intern);
|
package/dist/schema-snapshot.mjs
CHANGED
|
@@ -51,8 +51,7 @@ function isImmutableNode(value) {
|
|
|
51
51
|
immutableNodes.set(value, immutable);
|
|
52
52
|
return immutable;
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
function deepCloneSchema(value, seen, canShare = true) {
|
|
54
|
+
function deepCloneSchema(value, freeze, seen, canShare = true) {
|
|
56
55
|
if (value === null || typeof value !== "object") return value;
|
|
57
56
|
const cached = seen?.get(value);
|
|
58
57
|
if (cached) return cached;
|
|
@@ -60,8 +59,8 @@ function deepCloneSchema(value, seen, canShare = true) {
|
|
|
60
59
|
const out = [];
|
|
61
60
|
seen ??= /* @__PURE__ */ new Map();
|
|
62
61
|
seen.set(value, out);
|
|
63
|
-
for (let i = 0; i < value.length; i++) out[i] = deepCloneSchema(value[i], seen);
|
|
64
|
-
return
|
|
62
|
+
for (let i = 0; i < value.length; i++) out[i] = deepCloneSchema(value[i], freeze, seen);
|
|
63
|
+
return freeze ? Object.freeze(out) : out;
|
|
65
64
|
}
|
|
66
65
|
if (canShare && isImmutableNode(value)) return value;
|
|
67
66
|
const proto = Object.getPrototypeOf(value);
|
|
@@ -83,7 +82,7 @@ function deepCloneSchema(value, seen, canShare = true) {
|
|
|
83
82
|
});
|
|
84
83
|
continue;
|
|
85
84
|
}
|
|
86
|
-
const cloned = deepCloneSchema(property, seen);
|
|
85
|
+
const cloned = deepCloneSchema(property, freeze, seen);
|
|
87
86
|
if (key === "__proto__") Object.defineProperty(out, key, {
|
|
88
87
|
value: cloned,
|
|
89
88
|
enumerable: true,
|
|
@@ -96,7 +95,7 @@ function deepCloneSchema(value, seen, canShare = true) {
|
|
|
96
95
|
for (let i = 0; i < symbols.length; i++) {
|
|
97
96
|
const key = symbols[i];
|
|
98
97
|
const property = value[key];
|
|
99
|
-
if (isEnumerable.call(value, key)) out[key] = deepCloneSchema(property, seen);
|
|
98
|
+
if (isEnumerable.call(value, key)) out[key] = deepCloneSchema(property, freeze, seen);
|
|
100
99
|
else Object.defineProperty(out, key, {
|
|
101
100
|
value: property,
|
|
102
101
|
enumerable: false,
|
|
@@ -104,7 +103,7 @@ function deepCloneSchema(value, seen, canShare = true) {
|
|
|
104
103
|
configurable: true
|
|
105
104
|
});
|
|
106
105
|
}
|
|
107
|
-
return
|
|
106
|
+
return freeze ? Object.freeze(out) : out;
|
|
108
107
|
}
|
|
109
108
|
const refIds = /* @__PURE__ */ new WeakMap();
|
|
110
109
|
let nextRefId = 0;
|
|
@@ -113,9 +112,8 @@ function refKey(value) {
|
|
|
113
112
|
if (id === void 0) refIds.set(value, id = ++nextRefId);
|
|
114
113
|
return "r" + id + ";";
|
|
115
114
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
function fingerprint(value, seen, canShare = true) {
|
|
115
|
+
const byRefKey = (value, state) => value !== null && (typeof value === "object" || typeof value === "function") ? refKey(value) : fingerprint(value, void 0, state);
|
|
116
|
+
function fingerprint(value, seen, state, canShare = true) {
|
|
119
117
|
if (value === null) return "z;";
|
|
120
118
|
const type = typeof value;
|
|
121
119
|
if (type !== "object") switch (type) {
|
|
@@ -126,7 +124,7 @@ function fingerprint(value, seen, canShare = true) {
|
|
|
126
124
|
case "undefined": return "u;";
|
|
127
125
|
case "bigint": return "g" + value + ";";
|
|
128
126
|
default:
|
|
129
|
-
|
|
127
|
+
state.bail = true;
|
|
130
128
|
return "y;";
|
|
131
129
|
}
|
|
132
130
|
const backReference = seen?.get(value);
|
|
@@ -135,7 +133,7 @@ function fingerprint(value, seen, canShare = true) {
|
|
|
135
133
|
seen ??= /* @__PURE__ */ new Map();
|
|
136
134
|
seen.set(value, seen.size);
|
|
137
135
|
let out = "[";
|
|
138
|
-
for (let i = 0; i < value.length; i++) out += fingerprint(value[i], seen);
|
|
136
|
+
for (let i = 0; i < value.length; i++) out += fingerprint(value[i], seen, state);
|
|
139
137
|
return out + "];";
|
|
140
138
|
}
|
|
141
139
|
if (canShare && isImmutableNode(value)) return refKey(value);
|
|
@@ -150,15 +148,18 @@ function fingerprint(value, seen, canShare = true) {
|
|
|
150
148
|
const key = keys[i];
|
|
151
149
|
const property = value[key];
|
|
152
150
|
out += "k" + key.length + ":" + key;
|
|
153
|
-
out += !allEnumerable && !isEnumerable.call(value, key) ? "!" + byRefKey(property) : "=" + fingerprint(property, seen);
|
|
151
|
+
out += !allEnumerable && !isEnumerable.call(value, key) ? "!" + byRefKey(property, state) : "=" + fingerprint(property, seen, state);
|
|
154
152
|
}
|
|
155
|
-
if (Object.getOwnPropertySymbols(value).length)
|
|
153
|
+
if (Object.getOwnPropertySymbols(value).length) state.bail = true;
|
|
156
154
|
return out + "};";
|
|
157
155
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
156
|
+
function cloneOrWarn(object, freeze) {
|
|
157
|
+
try {
|
|
158
|
+
return deepCloneSchema(object, freeze, void 0, false);
|
|
159
|
+
} catch (error) {
|
|
160
|
+
console.warn("[Elysia] schema snapshot failed; schema kept by reference:", error);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
162
163
|
function snapshotSchema(schema) {
|
|
163
164
|
if (schema === null || typeof schema !== "object") return schema;
|
|
164
165
|
const object = schema;
|
|
@@ -166,13 +167,8 @@ function snapshotSchema(schema) {
|
|
|
166
167
|
if (produced.has(object) && !Object.isFrozen(object)) return schema;
|
|
167
168
|
const existing = modelSnapshots.get(object);
|
|
168
169
|
if (existing) return existing;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
cloned = deepCloneSchema(object, void 0, false);
|
|
172
|
-
} catch (error) {
|
|
173
|
-
console.warn("[Elysia] schema snapshot failed; schema kept by reference:", error);
|
|
174
|
-
return schema;
|
|
175
|
-
}
|
|
170
|
+
const cloned = cloneOrWarn(object, false);
|
|
171
|
+
if (cloned === void 0) return schema;
|
|
176
172
|
modelSnapshots.set(object, cloned);
|
|
177
173
|
produced.add(cloned);
|
|
178
174
|
return cloned;
|
|
@@ -192,11 +188,11 @@ function internSchema(schema, intern) {
|
|
|
192
188
|
if (existing) return existing;
|
|
193
189
|
let key;
|
|
194
190
|
if (intern) {
|
|
195
|
-
|
|
191
|
+
const state = { bail: false };
|
|
196
192
|
try {
|
|
197
|
-
key = fingerprint(object, void 0, false);
|
|
193
|
+
key = fingerprint(object, void 0, state, false);
|
|
198
194
|
} catch {}
|
|
199
|
-
if (
|
|
195
|
+
if (state.bail) key = void 0;
|
|
200
196
|
}
|
|
201
197
|
if (key !== void 0) {
|
|
202
198
|
const shared = interned.get(key);
|
|
@@ -209,16 +205,8 @@ function internSchema(schema, intern) {
|
|
|
209
205
|
return shared;
|
|
210
206
|
}
|
|
211
207
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
try {
|
|
215
|
-
cloned = deepCloneSchema(object, void 0, false);
|
|
216
|
-
} catch (error) {
|
|
217
|
-
console.warn("[Elysia] schema snapshot failed; schema kept by reference:", error);
|
|
218
|
-
return schema;
|
|
219
|
-
} finally {
|
|
220
|
-
freezeClones = false;
|
|
221
|
-
}
|
|
208
|
+
const cloned = cloneOrWarn(object, true);
|
|
209
|
+
if (cloned === void 0) return schema;
|
|
222
210
|
hookSnapshots.set(object, cloned);
|
|
223
211
|
produced.add(cloned);
|
|
224
212
|
if (key !== void 0) {
|
|
@@ -241,18 +229,12 @@ function isStatusMap(response) {
|
|
|
241
229
|
for (const key in response) if (!Number.isInteger(Number(key))) return false;
|
|
242
230
|
return true;
|
|
243
231
|
}
|
|
232
|
+
const hasSlot = (target) => schemaSlots.some((slot) => target[slot] != null) || target.response != null;
|
|
244
233
|
function snapshotHookSchemas(hook) {
|
|
245
234
|
if (!hook) return hook;
|
|
246
|
-
|
|
247
|
-
if (schemaSlots.some((slot) => hook[slot] != null) || hook.response != null) needsCopy = true;
|
|
235
|
+
const needsCopy = hasSlot(hook);
|
|
248
236
|
const schemas = hook.schemas;
|
|
249
|
-
if (!needsCopy && Array.isArray(schemas))
|
|
250
|
-
for (const entry of schemas) if (entry && (schemaSlots.some((slot) => entry[slot] != null) || entry.response != null)) {
|
|
251
|
-
needsCopy = true;
|
|
252
|
-
break;
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
if (!needsCopy) return hook;
|
|
237
|
+
if (!needsCopy && !(Array.isArray(schemas) && schemas.some((e) => e && hasSlot(e)))) return hook;
|
|
256
238
|
const intern = !env.ELYSIA_AOT_BUILD;
|
|
257
239
|
const copy = Object.assign(Object.create(Object.getPrototypeOf(hook)), hook);
|
|
258
240
|
snapshotSlots(copy, intern);
|
package/dist/sucrose.d.ts
CHANGED
|
@@ -13,62 +13,13 @@ declare namespace Sucrose {
|
|
|
13
13
|
}
|
|
14
14
|
type LifeCycle = Partial<Partial<AppHook>>;
|
|
15
15
|
}
|
|
16
|
+
declare function clearSucroseCache(): void;
|
|
17
|
+
declare const mergeInference: (a: Sucrose.Inference, b: Sucrose.Inference) => Sucrose.Inference;
|
|
16
18
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```typescript
|
|
21
|
-
* separateFunction('async ({ hello }) => { return hello }') // => ['({ hello })', '{ return hello }']
|
|
22
|
-
* ```
|
|
23
|
-
*/
|
|
24
|
-
declare function separateFunction(code: string): [string, string];
|
|
25
|
-
/**
|
|
26
|
-
* Get range between bracket pair
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```typescript
|
|
30
|
-
* bracketPairRange('hello: { world: { a } }, elysia') // [6, 20]
|
|
31
|
-
* ```
|
|
32
|
-
*/
|
|
33
|
-
declare function bracketPairRange(parameter: string): [number, number];
|
|
34
|
-
/**
|
|
35
|
-
* Similar to `bracketPairRange` but in reverse order
|
|
36
|
-
* Get range between bracket pair from end to beginning
|
|
37
|
-
*
|
|
38
|
-
* @example
|
|
39
|
-
* ```typescript
|
|
40
|
-
* bracketPairRange('hello: { world: { a } }, elysia') // [6, 20]
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
declare function bracketPairRangeReverse(parameter: string): [number, number];
|
|
44
|
-
declare function removeColonAlias(parameter: string): string;
|
|
45
|
-
/**
|
|
46
|
-
* Retrieve only root parameters of a function
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```typescript
|
|
50
|
-
* retrieveRootParameters('({ hello: { world: { a } }, elysia })') // => {
|
|
51
|
-
* parameters: ['hello', 'elysia'],
|
|
52
|
-
* hasParenthesis: true
|
|
53
|
-
* }
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
declare function retrieveRootparameters(parameter: string): {
|
|
57
|
-
hasParenthesis: boolean;
|
|
58
|
-
parameters: Record<string, true>;
|
|
59
|
-
};
|
|
60
|
-
/**
|
|
61
|
-
* Find alias of variable from function body
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```typescript
|
|
65
|
-
* findAlias('body', '{ const a = body, b = body }') // => ['a', 'b']
|
|
66
|
-
* ```
|
|
19
|
+
* @internal Which `channelOf`-mapped members of a function's first parameter
|
|
20
|
+
* the function may read, or `null` when any member may be read
|
|
67
21
|
*/
|
|
68
|
-
declare function
|
|
69
|
-
declare function removeDefaultParameter(parameter: string): string;
|
|
70
|
-
declare function clearSucroseCache(delay?: number | null): void;
|
|
71
|
-
declare const mergeInference: (a: Sucrose.Inference, b: Sucrose.Inference) => Sucrose.Inference;
|
|
22
|
+
declare function inferFunction<K extends string>(source: string, channelOf: (value: string) => K | undefined, strict?: boolean): Set<K> | null;
|
|
72
23
|
declare function sucrose(handler: Handler | undefined, lifeCycle: Sucrose.LifeCycle | undefined): Sucrose.Inference;
|
|
73
24
|
//#endregion
|
|
74
|
-
export { Sucrose,
|
|
25
|
+
export { Sucrose, clearSucroseCache, inferFunction, mergeInference, sucrose };
|