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,7 +1,6 @@
|
|
|
1
1
|
import { createAotPluginHooks } from "./hooks.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/plugin/aot/unplugin.ts
|
|
4
|
-
const cleanIdOf = (id) => id.split("?", 1)[0];
|
|
5
4
|
const VIRTUAL_MANIFEST_RESOURCE = /%00elysia%2Fcompiled/;
|
|
6
5
|
const forceManifestSideEffect = (compiler) => {
|
|
7
6
|
compiler.options.module.rules.push({
|
|
@@ -36,18 +35,10 @@ const aotFactory = (options) => {
|
|
|
36
35
|
enforce: "pre",
|
|
37
36
|
buildStart: hooks.buildStart,
|
|
38
37
|
buildEnd: hooks.buildEnd,
|
|
39
|
-
resolveId
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
return hooks.load(id) ?? void 0;
|
|
44
|
-
},
|
|
45
|
-
transformInclude(id) {
|
|
46
|
-
return hooks.isTransformCandidate(cleanIdOf(id));
|
|
47
|
-
},
|
|
48
|
-
transform(code, id) {
|
|
49
|
-
return hooks.transform(code, id);
|
|
50
|
-
},
|
|
38
|
+
resolveId: hooks.resolveId,
|
|
39
|
+
load: hooks.load,
|
|
40
|
+
transformInclude: hooks.isTransformCandidate,
|
|
41
|
+
transform: hooks.transform,
|
|
51
42
|
vite: { apply: "build" },
|
|
52
43
|
rspack(compiler) {
|
|
53
44
|
forceManifestSideEffect(compiler);
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import { ElysiaAotOptions } from "./core.js";
|
|
2
|
+
import { AotPluginHooks } from "./hooks.js";
|
|
2
3
|
|
|
3
4
|
//#region src/plugin/aot/vite.d.ts
|
|
4
|
-
interface ElysiaAotVitePlugin {
|
|
5
|
+
interface ElysiaAotVitePlugin extends Omit<AotPluginHooks, 'isTransformCandidate'> {
|
|
5
6
|
name: string;
|
|
6
7
|
enforce?: 'pre';
|
|
7
8
|
apply?: 'build';
|
|
8
|
-
buildStart(): Promise<void>;
|
|
9
|
-
buildEnd(): void;
|
|
10
|
-
resolveId(id: string): string | undefined;
|
|
11
|
-
load(id: string): string | undefined;
|
|
12
|
-
transform(code: string, id: string): string | undefined | Promise<string | undefined>;
|
|
13
9
|
}
|
|
14
10
|
/**
|
|
15
11
|
* Elysia AOT build plugin
|
|
@@ -6,8 +6,8 @@ let node_worker_threads = require("node:worker_threads");
|
|
|
6
6
|
//#region src/plugin/aot/worker.ts
|
|
7
7
|
const port = node_worker_threads.parentPort;
|
|
8
8
|
if (!port) throw new Error("[elysia-aot] worker requires a parent port");
|
|
9
|
-
const { file, options } = node_worker_threads.workerData;
|
|
10
|
-
require_plugin_aot_core.generateCompiledArtifacts(file, options).then((artifacts) => port.postMessage({
|
|
9
|
+
const { file, options, moduleCondition } = node_worker_threads.workerData;
|
|
10
|
+
require_plugin_aot_core.generateCompiledArtifacts(file, options, moduleCondition).then((artifacts) => port.postMessage({
|
|
11
11
|
ok: true,
|
|
12
12
|
artifacts
|
|
13
13
|
}), (error) => {
|
|
@@ -4,8 +4,8 @@ import { parentPort, workerData } from "node:worker_threads";
|
|
|
4
4
|
//#region src/plugin/aot/worker.ts
|
|
5
5
|
const port = parentPort;
|
|
6
6
|
if (!port) throw new Error("[elysia-aot] worker requires a parent port");
|
|
7
|
-
const { file, options } = workerData;
|
|
8
|
-
generateCompiledArtifacts(file, options).then((artifacts) => port.postMessage({
|
|
7
|
+
const { file, options, moduleCondition } = workerData;
|
|
8
|
+
generateCompiledArtifacts(file, options, moduleCondition).then((artifacts) => port.postMessage({
|
|
9
9
|
ok: true,
|
|
10
10
|
artifacts
|
|
11
11
|
}), (error) => {
|
package/dist/plugin/auto-head.js
CHANGED
|
@@ -21,16 +21,7 @@ const autoHead = () => async (app) => {
|
|
|
21
21
|
for (let i = 0; i < routes.length; i++) if (routes[i][0] === "HEAD") explicitHead.add(routes[i][1]);
|
|
22
22
|
for (let i = 0; i < routes.length; i++) {
|
|
23
23
|
const route = routes[i];
|
|
24
|
-
if (route[0] === "GET" && !explicitHead.has(route[1])) app["~addRoute"](
|
|
25
|
-
"HEAD",
|
|
26
|
-
route[1],
|
|
27
|
-
route[2],
|
|
28
|
-
route[3],
|
|
29
|
-
route[4],
|
|
30
|
-
route[5],
|
|
31
|
-
route[6],
|
|
32
|
-
route[7]
|
|
33
|
-
]);
|
|
24
|
+
if (route[0] === "GET" && !explicitHead.has(route[1])) app["~addRoute"](route.with(0, "HEAD"));
|
|
34
25
|
}
|
|
35
26
|
};
|
|
36
27
|
|
|
@@ -19,16 +19,7 @@ const autoHead = () => async (app) => {
|
|
|
19
19
|
for (let i = 0; i < routes.length; i++) if (routes[i][0] === "HEAD") explicitHead.add(routes[i][1]);
|
|
20
20
|
for (let i = 0; i < routes.length; i++) {
|
|
21
21
|
const route = routes[i];
|
|
22
|
-
if (route[0] === "GET" && !explicitHead.has(route[1])) app["~addRoute"](
|
|
23
|
-
"HEAD",
|
|
24
|
-
route[1],
|
|
25
|
-
route[2],
|
|
26
|
-
route[3],
|
|
27
|
-
route[4],
|
|
28
|
-
route[5],
|
|
29
|
-
route[6],
|
|
30
|
-
route[7]
|
|
31
|
-
]);
|
|
22
|
+
if (route[0] === "GET" && !explicitHead.has(route[1])) app["~addRoute"](route.with(0, "HEAD"));
|
|
32
23
|
}
|
|
33
24
|
};
|
|
34
25
|
|
package/dist/plugin/trace.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TraceEvent } from "../constants.js";
|
|
2
|
+
import { TraceCapability, TraceEndDetail, TraceHandler, TraceListener, TraceProcess, TraceStream, createTracer, unionTracePhases } from "../trace.js";
|
|
2
3
|
import { DefaultEphemeral, DefaultMetadata, DefaultSingleton } from "../types.js";
|
|
3
4
|
import { Elysia } from "../base.js";
|
|
4
5
|
//#region src/plugin/trace.d.ts
|
package/dist/route-table.d.ts
CHANGED
package/dist/route-table.js
CHANGED
|
@@ -5,7 +5,10 @@ const require_constants = require('./constants.js');
|
|
|
5
5
|
const RouteFlag = {
|
|
6
6
|
WS: 1,
|
|
7
7
|
Dynamic: 2,
|
|
8
|
-
Encode: 4
|
|
8
|
+
Encode: 4,
|
|
9
|
+
ExactDuplicate: 8,
|
|
10
|
+
JITCold: 16,
|
|
11
|
+
JITSatisfied: 32
|
|
9
12
|
};
|
|
10
13
|
function buildRouteTable(declaredRoutes) {
|
|
11
14
|
const length = declaredRoutes.length;
|
|
@@ -47,16 +50,18 @@ function buildRouteTable(declaredRoutes) {
|
|
|
47
50
|
macroScope
|
|
48
51
|
};
|
|
49
52
|
}
|
|
50
|
-
const routeRow = (table, id) =>
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
const routeRow = (table, id) => {
|
|
54
|
+
return [
|
|
55
|
+
table.method[id],
|
|
56
|
+
table.path[id],
|
|
57
|
+
table.handler[id],
|
|
58
|
+
table.owner[id],
|
|
59
|
+
table.localHook[id],
|
|
60
|
+
table.appHook[id],
|
|
61
|
+
table.inheritedChain[id],
|
|
62
|
+
table.macroScope?.get(id)
|
|
63
|
+
];
|
|
64
|
+
};
|
|
60
65
|
|
|
61
66
|
//#endregion
|
|
62
67
|
exports.RouteFlag = RouteFlag;
|
package/dist/route-table.mjs
CHANGED
|
@@ -4,7 +4,10 @@ import { needEncodeRegex } from "./constants.mjs";
|
|
|
4
4
|
const RouteFlag = {
|
|
5
5
|
WS: 1,
|
|
6
6
|
Dynamic: 2,
|
|
7
|
-
Encode: 4
|
|
7
|
+
Encode: 4,
|
|
8
|
+
ExactDuplicate: 8,
|
|
9
|
+
JITCold: 16,
|
|
10
|
+
JITSatisfied: 32
|
|
8
11
|
};
|
|
9
12
|
function buildRouteTable(declaredRoutes) {
|
|
10
13
|
const length = declaredRoutes.length;
|
|
@@ -46,16 +49,18 @@ function buildRouteTable(declaredRoutes) {
|
|
|
46
49
|
macroScope
|
|
47
50
|
};
|
|
48
51
|
}
|
|
49
|
-
const routeRow = (table, id) =>
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
const routeRow = (table, id) => {
|
|
53
|
+
return [
|
|
54
|
+
table.method[id],
|
|
55
|
+
table.path[id],
|
|
56
|
+
table.handler[id],
|
|
57
|
+
table.owner[id],
|
|
58
|
+
table.localHook[id],
|
|
59
|
+
table.appHook[id],
|
|
60
|
+
table.inheritedChain[id],
|
|
61
|
+
table.macroScope?.get(id)
|
|
62
|
+
];
|
|
63
|
+
};
|
|
59
64
|
|
|
60
65
|
//#endregion
|
|
61
66
|
export { RouteFlag, buildRouteTable, routeRow };
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
//#region src/schema-snapshot.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* The `.model()` snapshot: a private, MUTABLE clone. `base.ts` stamps `$id` onto
|
|
4
|
-
* the node this returns, so it is never frozen and never interned.
|
|
5
|
-
*/
|
|
6
2
|
declare function snapshotSchema<T>(schema: T): T;
|
|
7
3
|
declare function snapshotHookSchemas<T extends Record<string, any> | undefined>(hook: T): T;
|
|
8
4
|
//#endregion
|
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);
|
|
@@ -77,14 +76,14 @@ function deepCloneSchema(value, seen, canShare = true) {
|
|
|
77
76
|
const property = value[key];
|
|
78
77
|
if (!allEnumerable && !isEnumerable.call(value, key)) {
|
|
79
78
|
Object.defineProperty(out, key, {
|
|
80
|
-
value: property,
|
|
79
|
+
value: key === "~cookieFrom" ? deepCloneSchema(property, freeze, seen) : property,
|
|
81
80
|
enumerable: false,
|
|
82
81
|
writable: true,
|
|
83
82
|
configurable: 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,20 +113,19 @@ 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) {
|
|
123
121
|
case "string": return "s" + value.length + ":" + value;
|
|
124
|
-
case "number": return "n" + value + ";";
|
|
122
|
+
case "number": return "n" + (Object.is(value, -0) ? "-0" : value) + ";";
|
|
125
123
|
case "boolean": return value ? "T;" : "F;";
|
|
126
124
|
case "function": return refKey(value);
|
|
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,19 @@ 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
|
-
|
|
152
|
+
const hidden = !allEnumerable && !isEnumerable.call(value, key);
|
|
153
|
+
out += hidden && key !== "~cookieFrom" ? "!" + byRefKey(property, state) : (hidden ? "~" : "=") + fingerprint(property, seen, state);
|
|
155
154
|
}
|
|
156
|
-
if (Object.getOwnPropertySymbols(value).length)
|
|
155
|
+
if (Object.getOwnPropertySymbols(value).length) state.bail = true;
|
|
157
156
|
return out + "};";
|
|
158
157
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
158
|
+
function cloneOrWarn(object, freeze) {
|
|
159
|
+
try {
|
|
160
|
+
return deepCloneSchema(object, freeze, void 0, false);
|
|
161
|
+
} catch (error) {
|
|
162
|
+
console.warn("[Elysia] schema snapshot failed; schema kept by reference:", error);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
163
165
|
function snapshotSchema(schema) {
|
|
164
166
|
if (schema === null || typeof schema !== "object") return schema;
|
|
165
167
|
const object = schema;
|
|
@@ -167,13 +169,8 @@ function snapshotSchema(schema) {
|
|
|
167
169
|
if (produced.has(object) && !Object.isFrozen(object)) return schema;
|
|
168
170
|
const existing = modelSnapshots.get(object);
|
|
169
171
|
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
|
-
}
|
|
172
|
+
const cloned = cloneOrWarn(object, false);
|
|
173
|
+
if (cloned === void 0) return schema;
|
|
177
174
|
modelSnapshots.set(object, cloned);
|
|
178
175
|
produced.add(cloned);
|
|
179
176
|
return cloned;
|
|
@@ -193,11 +190,11 @@ function internSchema(schema, intern) {
|
|
|
193
190
|
if (existing) return existing;
|
|
194
191
|
let key;
|
|
195
192
|
if (intern) {
|
|
196
|
-
|
|
193
|
+
const state = { bail: false };
|
|
197
194
|
try {
|
|
198
|
-
key = fingerprint(object, void 0, false);
|
|
195
|
+
key = fingerprint(object, void 0, state, false);
|
|
199
196
|
} catch {}
|
|
200
|
-
if (
|
|
197
|
+
if (state.bail) key = void 0;
|
|
201
198
|
}
|
|
202
199
|
if (key !== void 0) {
|
|
203
200
|
const shared = interned.get(key);
|
|
@@ -210,16 +207,8 @@ function internSchema(schema, intern) {
|
|
|
210
207
|
return shared;
|
|
211
208
|
}
|
|
212
209
|
}
|
|
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
|
-
}
|
|
210
|
+
const cloned = cloneOrWarn(object, true);
|
|
211
|
+
if (cloned === void 0) return schema;
|
|
223
212
|
hookSnapshots.set(object, cloned);
|
|
224
213
|
produced.add(cloned);
|
|
225
214
|
if (key !== void 0) {
|
|
@@ -242,18 +231,12 @@ function isStatusMap(response) {
|
|
|
242
231
|
for (const key in response) if (!Number.isInteger(Number(key))) return false;
|
|
243
232
|
return true;
|
|
244
233
|
}
|
|
234
|
+
const hasSlot = (target) => schemaSlots.some((slot) => target[slot] != null) || target.response != null;
|
|
245
235
|
function snapshotHookSchemas(hook) {
|
|
246
236
|
if (!hook) return hook;
|
|
247
|
-
|
|
248
|
-
if (schemaSlots.some((slot) => hook[slot] != null) || hook.response != null) needsCopy = true;
|
|
237
|
+
const needsCopy = hasSlot(hook);
|
|
249
238
|
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;
|
|
239
|
+
if (!needsCopy && !(Array.isArray(schemas) && schemas.some((e) => e && hasSlot(e)))) return hook;
|
|
257
240
|
const intern = !require_universal_env.env.ELYSIA_AOT_BUILD;
|
|
258
241
|
const copy = Object.assign(Object.create(Object.getPrototypeOf(hook)), hook);
|
|
259
242
|
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);
|
|
@@ -76,14 +75,14 @@ function deepCloneSchema(value, seen, canShare = true) {
|
|
|
76
75
|
const property = value[key];
|
|
77
76
|
if (!allEnumerable && !isEnumerable.call(value, key)) {
|
|
78
77
|
Object.defineProperty(out, key, {
|
|
79
|
-
value: property,
|
|
78
|
+
value: key === "~cookieFrom" ? deepCloneSchema(property, freeze, seen) : property,
|
|
80
79
|
enumerable: false,
|
|
81
80
|
writable: true,
|
|
82
81
|
configurable: 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,20 +112,19 @@ 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) {
|
|
122
120
|
case "string": return "s" + value.length + ":" + value;
|
|
123
|
-
case "number": return "n" + value + ";";
|
|
121
|
+
case "number": return "n" + (Object.is(value, -0) ? "-0" : value) + ";";
|
|
124
122
|
case "boolean": return value ? "T;" : "F;";
|
|
125
123
|
case "function": return refKey(value);
|
|
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,19 @@ 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
|
-
|
|
151
|
+
const hidden = !allEnumerable && !isEnumerable.call(value, key);
|
|
152
|
+
out += hidden && key !== "~cookieFrom" ? "!" + byRefKey(property, state) : (hidden ? "~" : "=") + fingerprint(property, seen, state);
|
|
154
153
|
}
|
|
155
|
-
if (Object.getOwnPropertySymbols(value).length)
|
|
154
|
+
if (Object.getOwnPropertySymbols(value).length) state.bail = true;
|
|
156
155
|
return out + "};";
|
|
157
156
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
+
}
|
|
162
164
|
function snapshotSchema(schema) {
|
|
163
165
|
if (schema === null || typeof schema !== "object") return schema;
|
|
164
166
|
const object = schema;
|
|
@@ -166,13 +168,8 @@ function snapshotSchema(schema) {
|
|
|
166
168
|
if (produced.has(object) && !Object.isFrozen(object)) return schema;
|
|
167
169
|
const existing = modelSnapshots.get(object);
|
|
168
170
|
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
|
-
}
|
|
171
|
+
const cloned = cloneOrWarn(object, false);
|
|
172
|
+
if (cloned === void 0) return schema;
|
|
176
173
|
modelSnapshots.set(object, cloned);
|
|
177
174
|
produced.add(cloned);
|
|
178
175
|
return cloned;
|
|
@@ -192,11 +189,11 @@ function internSchema(schema, intern) {
|
|
|
192
189
|
if (existing) return existing;
|
|
193
190
|
let key;
|
|
194
191
|
if (intern) {
|
|
195
|
-
|
|
192
|
+
const state = { bail: false };
|
|
196
193
|
try {
|
|
197
|
-
key = fingerprint(object, void 0, false);
|
|
194
|
+
key = fingerprint(object, void 0, state, false);
|
|
198
195
|
} catch {}
|
|
199
|
-
if (
|
|
196
|
+
if (state.bail) key = void 0;
|
|
200
197
|
}
|
|
201
198
|
if (key !== void 0) {
|
|
202
199
|
const shared = interned.get(key);
|
|
@@ -209,16 +206,8 @@ function internSchema(schema, intern) {
|
|
|
209
206
|
return shared;
|
|
210
207
|
}
|
|
211
208
|
}
|
|
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
|
-
}
|
|
209
|
+
const cloned = cloneOrWarn(object, true);
|
|
210
|
+
if (cloned === void 0) return schema;
|
|
222
211
|
hookSnapshots.set(object, cloned);
|
|
223
212
|
produced.add(cloned);
|
|
224
213
|
if (key !== void 0) {
|
|
@@ -241,18 +230,12 @@ function isStatusMap(response) {
|
|
|
241
230
|
for (const key in response) if (!Number.isInteger(Number(key))) return false;
|
|
242
231
|
return true;
|
|
243
232
|
}
|
|
233
|
+
const hasSlot = (target) => schemaSlots.some((slot) => target[slot] != null) || target.response != null;
|
|
244
234
|
function snapshotHookSchemas(hook) {
|
|
245
235
|
if (!hook) return hook;
|
|
246
|
-
|
|
247
|
-
if (schemaSlots.some((slot) => hook[slot] != null) || hook.response != null) needsCopy = true;
|
|
236
|
+
const needsCopy = hasSlot(hook);
|
|
248
237
|
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;
|
|
238
|
+
if (!needsCopy && !(Array.isArray(schemas) && schemas.some((e) => e && hasSlot(e)))) return hook;
|
|
256
239
|
const intern = !env.ELYSIA_AOT_BUILD;
|
|
257
240
|
const copy = Object.assign(Object.create(Object.getPrototypeOf(hook)), hook);
|
|
258
241
|
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 };
|