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/utils.js
CHANGED
|
@@ -49,6 +49,12 @@ function fnv1a(str) {
|
|
|
49
49
|
const fnOrigin = /* @__PURE__ */ new WeakMap();
|
|
50
50
|
const macroOrigin = /* @__PURE__ */ new WeakMap();
|
|
51
51
|
const isLocalScope = (s) => s === "local" || s === void 0;
|
|
52
|
+
/**
|
|
53
|
+
* The absorbing instance's chain as it stood at `.use()`: the `over` of a
|
|
54
|
+
* combine node, or the node itself. A combine node is never on an instance's
|
|
55
|
+
* own chain, so it can't serve as a `stopAt` directly
|
|
56
|
+
*/
|
|
57
|
+
const rootSnapshot = (node) => node && "combine" in node ? node.over : node;
|
|
52
58
|
const COMPACT_CHUNK_SIZE = 32;
|
|
53
59
|
const emptyCompactBeforeHandlePrefix = {
|
|
54
60
|
length: 0,
|
|
@@ -73,30 +79,6 @@ function compactBeforeHandleConflicts(hook) {
|
|
|
73
79
|
for (let i = 0; i < values.length; i++) if (compactBeforeHandleFunctions.has(values[i])) return true;
|
|
74
80
|
return false;
|
|
75
81
|
}
|
|
76
|
-
function appendCompactBeforeHandle(previous, added) {
|
|
77
|
-
if (!added.length) return previous;
|
|
78
|
-
let tail = previous.tail;
|
|
79
|
-
let length = previous.length;
|
|
80
|
-
for (let i = 0; i < added.length; i++) {
|
|
81
|
-
const fn = added[i];
|
|
82
|
-
compactBeforeHandleFunctions.add(fn);
|
|
83
|
-
if (tail && tail.values.length < COMPACT_CHUNK_SIZE) tail = {
|
|
84
|
-
parent: tail.parent,
|
|
85
|
-
values: [...tail.values, fn]
|
|
86
|
-
};
|
|
87
|
-
else tail = {
|
|
88
|
-
parent: tail,
|
|
89
|
-
values: [fn]
|
|
90
|
-
};
|
|
91
|
-
length++;
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
tail,
|
|
95
|
-
length,
|
|
96
|
-
previous: previous.length ? previous : void 0,
|
|
97
|
-
added
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
82
|
function compactBeforeHandlePrefix(start) {
|
|
101
83
|
if (!start) return;
|
|
102
84
|
const pending = [];
|
|
@@ -104,34 +86,51 @@ function compactBeforeHandlePrefix(start) {
|
|
|
104
86
|
let prefix = emptyCompactBeforeHandlePrefix;
|
|
105
87
|
while (node) {
|
|
106
88
|
const cached = compactBeforeHandleMemos.get(node);
|
|
107
|
-
if (cached
|
|
108
|
-
if (cached === false) {
|
|
109
|
-
for (let i = 0; i < pending.length; i++) compactBeforeHandleMemos.set(pending[i].node, false);
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
89
|
+
if (cached) {
|
|
112
90
|
prefix = cached;
|
|
113
91
|
break;
|
|
114
92
|
}
|
|
115
|
-
if ("combine" in node) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
93
|
+
if (cached === void 0 && !("combine" in node)) {
|
|
94
|
+
const values = compactBeforeHandleValues(node.added);
|
|
95
|
+
if (values !== false) {
|
|
96
|
+
pending.push({
|
|
97
|
+
node,
|
|
98
|
+
values
|
|
99
|
+
});
|
|
100
|
+
node = node.parent;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
125
103
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
});
|
|
130
|
-
node = node.parent;
|
|
104
|
+
compactBeforeHandleMemos.set(node, false);
|
|
105
|
+
for (let i = 0; i < pending.length; i++) compactBeforeHandleMemos.set(pending[i].node, false);
|
|
106
|
+
return;
|
|
131
107
|
}
|
|
132
108
|
for (let i = pending.length - 1; i >= 0; i--) {
|
|
133
109
|
const item = pending[i];
|
|
134
|
-
|
|
110
|
+
const added = item.values;
|
|
111
|
+
if (added.length) {
|
|
112
|
+
let tail = prefix.tail;
|
|
113
|
+
let length = prefix.length;
|
|
114
|
+
for (let j = 0; j < added.length; j++) {
|
|
115
|
+
const fn = added[j];
|
|
116
|
+
compactBeforeHandleFunctions.add(fn);
|
|
117
|
+
if (tail && tail.values.length < COMPACT_CHUNK_SIZE) tail = {
|
|
118
|
+
parent: tail.parent,
|
|
119
|
+
values: [...tail.values, fn]
|
|
120
|
+
};
|
|
121
|
+
else tail = {
|
|
122
|
+
parent: tail,
|
|
123
|
+
values: [fn]
|
|
124
|
+
};
|
|
125
|
+
length++;
|
|
126
|
+
}
|
|
127
|
+
prefix = {
|
|
128
|
+
tail,
|
|
129
|
+
length,
|
|
130
|
+
previous: prefix.length ? prefix : void 0,
|
|
131
|
+
added
|
|
132
|
+
};
|
|
133
|
+
}
|
|
135
134
|
compactBeforeHandleMemos.set(item.node, prefix);
|
|
136
135
|
}
|
|
137
136
|
return prefix.length ? prefix : void 0;
|
|
@@ -157,13 +156,30 @@ function flattenChain(start, keep, stopAt, resolveAdded) {
|
|
|
157
156
|
const node = nodes.pop();
|
|
158
157
|
if (phases.pop() === 1) {
|
|
159
158
|
const added = resolveAdded ? resolveAdded(node) : node.added;
|
|
160
|
-
if (added)
|
|
159
|
+
if (added) {
|
|
160
|
+
const nodeScope = node.scope;
|
|
161
|
+
if (!(keep && !keep(nodeScope))) for (const key in added) {
|
|
162
|
+
const v = added[key];
|
|
163
|
+
if (v === void 0 || v === null) continue;
|
|
164
|
+
if (eventProperties.has(key) || key === "schemas" || key === "~deriveEntries") {
|
|
165
|
+
const existing = result[key];
|
|
166
|
+
if (Array.isArray(v)) if (existing) {
|
|
167
|
+
const arr = existing;
|
|
168
|
+
for (let i = 0; i < v.length; i++) arr.push(v[i]);
|
|
169
|
+
} else result[key] = v.slice();
|
|
170
|
+
else if (existing) existing.push(v);
|
|
171
|
+
else result[key] = [v];
|
|
172
|
+
} else result[key] = v;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
161
175
|
continue;
|
|
162
176
|
}
|
|
163
177
|
if (stopAt && node === stopAt) continue;
|
|
164
178
|
if ("combine" in node) {
|
|
165
|
-
|
|
166
|
-
|
|
179
|
+
if (node.combine) {
|
|
180
|
+
nodes.push(node.combine);
|
|
181
|
+
phases.push(0);
|
|
182
|
+
}
|
|
167
183
|
if (node.over) {
|
|
168
184
|
nodes.push(node.over);
|
|
169
185
|
phases.push(0);
|
|
@@ -197,7 +213,8 @@ function clearFlattenChainMemo(root) {
|
|
|
197
213
|
flattenChainMemos.delete(root);
|
|
198
214
|
}
|
|
199
215
|
const emptyFlatten = Object.freeze(nullObject());
|
|
200
|
-
function
|
|
216
|
+
function flattenChainMemoReadonly(root, start, resolveAdded) {
|
|
217
|
+
if (!start) return;
|
|
201
218
|
let bucket = flattenChainMemos.get(root);
|
|
202
219
|
if (!bucket || bucket.e !== macroTableEpoch) {
|
|
203
220
|
bucket = {
|
|
@@ -216,30 +233,8 @@ function flattenChainCached(root, start, resolveAdded) {
|
|
|
216
233
|
return cached;
|
|
217
234
|
}
|
|
218
235
|
function flattenChainMemo(root, start, resolveAdded) {
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (cached === void 0) return;
|
|
222
|
-
return cloneHook(cached);
|
|
223
|
-
}
|
|
224
|
-
function flattenChainMemoReadonly(root, start, resolveAdded) {
|
|
225
|
-
if (!start) return;
|
|
226
|
-
return flattenChainCached(root, start, resolveAdded);
|
|
227
|
-
}
|
|
228
|
-
function appendInto(target, src, keep, nodeScope) {
|
|
229
|
-
if (keep && !keep(nodeScope)) return;
|
|
230
|
-
for (const key in src) {
|
|
231
|
-
const v = src[key];
|
|
232
|
-
if (v === void 0 || v === null) continue;
|
|
233
|
-
if (eventProperties.has(key) || key === "schemas" || key === "~deriveEntries") {
|
|
234
|
-
const existing = target[key];
|
|
235
|
-
if (Array.isArray(v)) if (existing) {
|
|
236
|
-
const arr = existing;
|
|
237
|
-
for (let i = 0; i < v.length; i++) arr.push(v[i]);
|
|
238
|
-
} else target[key] = v.slice();
|
|
239
|
-
else if (existing) existing.push(v);
|
|
240
|
-
else target[key] = [v];
|
|
241
|
-
} else target[key] = v;
|
|
242
|
-
}
|
|
236
|
+
const cached = flattenChainMemoReadonly(root, start, resolveAdded);
|
|
237
|
+
if (cached) return cloneHook(cached);
|
|
243
238
|
}
|
|
244
239
|
const notLatin = /[^\x00-\xFF]/;
|
|
245
240
|
/**
|
|
@@ -287,6 +282,7 @@ function formToFormData(value) {
|
|
|
287
282
|
* ```
|
|
288
283
|
*/
|
|
289
284
|
const form = (value) => Object.setPrototypeOf({ ...value }, ELYSIA_FORM_PROTOTYPE);
|
|
285
|
+
const assignOwn = (target, source) => source != null && Object.hasOwn(source, "__proto__") ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : Object.assign(target, source);
|
|
290
286
|
const getLoosePath = (path) => path.charCodeAt(path.length - 1) === 47 ? path.slice(0, -1) : path + "/";
|
|
291
287
|
const byteStreams = /* @__PURE__ */ new WeakSet();
|
|
292
288
|
/**
|
|
@@ -322,6 +318,7 @@ const sse = (_payload) => {
|
|
|
322
318
|
if (payload.data === null) s += "data: null\n";
|
|
323
319
|
else if (typeof payload.data === "string") s += sseData(payload.data);
|
|
324
320
|
else if (typeof payload.data === "object") s += `data: ${JSON.stringify(payload.data)}\n`;
|
|
321
|
+
else if (payload.data !== void 0) s += sseData(String(payload.data));
|
|
325
322
|
if (s) s += "\n";
|
|
326
323
|
return s;
|
|
327
324
|
};
|
|
@@ -331,11 +328,11 @@ const _enc = new TextEncoder();
|
|
|
331
328
|
let _constantTimeEqual;
|
|
332
329
|
const _resolveConstantTimeEqual = () => {
|
|
333
330
|
let native;
|
|
334
|
-
|
|
331
|
+
if (require_universal_constants.isBun && typeof crypto?.timingSafeEqual === "function") native = (a, b) => crypto.timingSafeEqual(a, b);
|
|
332
|
+
else try {
|
|
335
333
|
const _crypto = globalThis.process?.getBuiltinModule?.("node:crypto");
|
|
336
334
|
if (typeof _crypto?.timingSafeEqual === "function") native = _crypto.timingSafeEqual;
|
|
337
335
|
} catch {}
|
|
338
|
-
if (!native && typeof crypto?.timingSafeEqual === "function") native = (a, b) => crypto.timingSafeEqual(a, b);
|
|
339
336
|
if (!native) return (a, b) => {
|
|
340
337
|
if (a.length !== b.length) return false;
|
|
341
338
|
let mismatch = 0;
|
|
@@ -429,14 +426,26 @@ function dedupedMergeArray(a, b, reverse = false) {
|
|
|
429
426
|
for (let i = 0; i < aArr.length; i++) if (!seen.has(aArr[i])) filtered.push(aArr[i]);
|
|
430
427
|
return reverse ? bArr.concat(filtered) : filtered.concat(bArr);
|
|
431
428
|
}
|
|
432
|
-
const
|
|
429
|
+
const hookSchemaKeys = [
|
|
433
430
|
"body",
|
|
434
431
|
"headers",
|
|
435
432
|
"params",
|
|
436
433
|
"query",
|
|
437
434
|
"cookie",
|
|
438
435
|
"response"
|
|
439
|
-
]
|
|
436
|
+
];
|
|
437
|
+
const schemaProperties = new Set(hookSchemaKeys);
|
|
438
|
+
const hookEventKeys = [
|
|
439
|
+
"parse",
|
|
440
|
+
"transform",
|
|
441
|
+
"derive",
|
|
442
|
+
"beforeHandle",
|
|
443
|
+
"afterHandle",
|
|
444
|
+
"mapResponse",
|
|
445
|
+
"afterResponse",
|
|
446
|
+
"error",
|
|
447
|
+
"trace"
|
|
448
|
+
];
|
|
440
449
|
const eventProperties = new Set([
|
|
441
450
|
"start",
|
|
442
451
|
"stop",
|
|
@@ -451,33 +460,16 @@ const eventProperties = new Set([
|
|
|
451
460
|
"error"
|
|
452
461
|
]);
|
|
453
462
|
function hookToGuard(a) {
|
|
454
|
-
if (a.schema !== "merge")
|
|
463
|
+
if (a.schema !== "merge") {
|
|
464
|
+
if (a.schema !== void 0 && a.schema !== "override") throw new Error(`[Elysia] Invalid guard schema ${JSON.stringify(a.schema)}, expected 'merge' or 'override' (1.x 'standalone' is 'merge')`);
|
|
465
|
+
return a;
|
|
466
|
+
}
|
|
455
467
|
if (a.body || a.headers || a.params || a.query || a.cookie || a.response) {
|
|
456
468
|
a.schemas ??= [];
|
|
457
469
|
const schema = Object.create(null);
|
|
458
|
-
if (a
|
|
459
|
-
schema
|
|
460
|
-
a
|
|
461
|
-
}
|
|
462
|
-
if (a.headers) {
|
|
463
|
-
schema.headers = a.headers;
|
|
464
|
-
a.headers = void 0;
|
|
465
|
-
}
|
|
466
|
-
if (a.params) {
|
|
467
|
-
schema.params = a.params;
|
|
468
|
-
a.params = void 0;
|
|
469
|
-
}
|
|
470
|
-
if (a.query) {
|
|
471
|
-
schema.query = a.query;
|
|
472
|
-
a.query = void 0;
|
|
473
|
-
}
|
|
474
|
-
if (a.cookie) {
|
|
475
|
-
schema.cookie = a.cookie;
|
|
476
|
-
a.cookie = void 0;
|
|
477
|
-
}
|
|
478
|
-
if (a.response) {
|
|
479
|
-
schema.response = a.response;
|
|
480
|
-
a.response = void 0;
|
|
470
|
+
for (const key of hookSchemaKeys) if (a[key]) {
|
|
471
|
+
schema[key] = a[key];
|
|
472
|
+
a[key] = void 0;
|
|
481
473
|
}
|
|
482
474
|
a.schemas.push(schema);
|
|
483
475
|
}
|
|
@@ -507,30 +499,22 @@ function mergeHook(a, b, reverse = false, dedup = false) {
|
|
|
507
499
|
if (!b) return a;
|
|
508
500
|
if (!a) return b;
|
|
509
501
|
const merge = dedup ? dedupedMergeArray : mergeArray;
|
|
510
|
-
if (!a
|
|
511
|
-
if (
|
|
512
|
-
if (
|
|
513
|
-
if (!a.query && b.query) a.query = b.query;
|
|
514
|
-
if (!a.cookie && b.cookie) a.cookie = b.cookie;
|
|
515
|
-
if (!a.response && b.response) a.response = b.response;
|
|
516
|
-
else if (a.response && b.response) a.response = mergeResponse(b.response, a.response);
|
|
517
|
-
if (a.parse || b.parse) a.parse = merge(a.parse, b.parse, reverse);
|
|
518
|
-
if (a.transform || b.transform) a.transform = merge(a.transform, b.transform, reverse);
|
|
519
|
-
if (a.derive || b.derive) a.derive = merge(a.derive, b.derive, reverse);
|
|
520
|
-
if (a.beforeHandle || b.beforeHandle) a.beforeHandle = merge(a.beforeHandle, b.beforeHandle, reverse);
|
|
521
|
-
if (a.afterHandle || b.afterHandle) a.afterHandle = merge(a.afterHandle, b.afterHandle, reverse);
|
|
522
|
-
if (a.mapResponse || b.mapResponse) a.mapResponse = merge(a.mapResponse, b.mapResponse, reverse);
|
|
523
|
-
if (a.afterResponse || b.afterResponse) a.afterResponse = merge(a.afterResponse, b.afterResponse, reverse);
|
|
524
|
-
if (a.error || b.error) a.error = merge(a.error, b.error, reverse);
|
|
525
|
-
if (a.trace || b.trace) a.trace = merge(a.trace, b.trace, reverse);
|
|
502
|
+
for (const key of hookSchemaKeys) if (!a[key] && b[key]) a[key] = b[key];
|
|
503
|
+
else if (key === "response" && a.response && b.response) a.response = mergeResponse(b.response, a.response);
|
|
504
|
+
for (const key of hookEventKeys) if (a[key] || b[key]) a[key] = merge(a[key], b[key], reverse);
|
|
526
505
|
if (a.schemas || b.schemas) a.schemas = mergeArray(a.schemas, b.schemas, reverse);
|
|
527
506
|
const aDerive = a["~deriveEntries"];
|
|
528
507
|
const bDerive = b["~deriveEntries"];
|
|
529
508
|
if (aDerive || bDerive) a["~deriveEntries"] = mergeArray(aDerive, bDerive, reverse);
|
|
530
509
|
return a;
|
|
531
510
|
}
|
|
532
|
-
const createErrorEventHandler = (fn, error) =>
|
|
533
|
-
|
|
511
|
+
const createErrorEventHandler = (fn, error) => {
|
|
512
|
+
const handler = (context) => {
|
|
513
|
+
if (context.error instanceof error) return fn(context);
|
|
514
|
+
};
|
|
515
|
+
const p = error?.prototype;
|
|
516
|
+
if (typeof p === "object" && p !== null && p !== Error.prototype && !(p instanceof Error)) handler["~errorClass"] = error;
|
|
517
|
+
return handler;
|
|
534
518
|
};
|
|
535
519
|
const isObject = (item) => item && typeof item === "object" && !Array.isArray(item);
|
|
536
520
|
const isClassRegex = /^\s*class\s+/;
|
|
@@ -619,15 +603,21 @@ function joinPath(base, path) {
|
|
|
619
603
|
if (!baseEndsWithSlash && !pathStartsWithSlash) return base + "/" + path;
|
|
620
604
|
return base + path;
|
|
621
605
|
}
|
|
622
|
-
function pushField(target, key, item
|
|
606
|
+
function pushField(target, key, item) {
|
|
623
607
|
const v = target[key];
|
|
624
608
|
if (v) if (Array.isArray(v)) target[key].push(item);
|
|
625
609
|
else target[key] = [v, item];
|
|
626
|
-
else target[key] =
|
|
610
|
+
else target[key] = item;
|
|
627
611
|
}
|
|
628
|
-
const requestId = require_universal_constants.isBun ? Bun.randomUUIDv7 : crypto.
|
|
612
|
+
const requestId = require_universal_constants.isBun ? Bun.randomUUIDv7 : crypto.randomUUID.bind(crypto);
|
|
613
|
+
/**
|
|
614
|
+
* Offset of the first byte after `://`, so the authority is never scanned as
|
|
615
|
+
* path. A fixed offset would let the client-supplied `Host` decide how many
|
|
616
|
+
* leading path bytes are dropped
|
|
617
|
+
*/
|
|
618
|
+
const authorityEnd = (url) => url.charCodeAt(4) === 58 ? 7 : url.charCodeAt(5) === 58 ? 8 : url.indexOf("://") + 3;
|
|
629
619
|
function replaceUrlPath(url, path) {
|
|
630
|
-
const i = url.indexOf("/",
|
|
620
|
+
const i = url.indexOf("/", authorityEnd(url));
|
|
631
621
|
const qs = url.indexOf("?", i);
|
|
632
622
|
return `${url.slice(0, i)}${path.charCodeAt(0) === 47 ? "" : "/"}${path}${qs === -1 ? "" : url.slice(qs)}`;
|
|
633
623
|
}
|
|
@@ -652,7 +642,6 @@ function clonePlainDecorators(source, seen) {
|
|
|
652
642
|
}
|
|
653
643
|
return out;
|
|
654
644
|
}
|
|
655
|
-
const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
|
|
656
645
|
function prefix(prefix, models) {
|
|
657
646
|
const prefixed = nullObject();
|
|
658
647
|
for (const key in models) prefixed[`${prefix}.${key}`] = models[key];
|
|
@@ -660,7 +649,7 @@ function prefix(prefix, models) {
|
|
|
660
649
|
}
|
|
661
650
|
prefix.capitalize = function prefixModelsCapitalize(prefix, models) {
|
|
662
651
|
const prefixed = nullObject();
|
|
663
|
-
for (const key in models) prefixed[`${prefix}.${
|
|
652
|
+
for (const key in models) prefixed[`${prefix}.${key.charAt(0).toUpperCase() + key.slice(1)}`] = models[key];
|
|
664
653
|
return prefixed;
|
|
665
654
|
};
|
|
666
655
|
const macroSeedRefIds = /* @__PURE__ */ new WeakMap();
|
|
@@ -679,9 +668,43 @@ function serializeMacroSeed(_key, value) {
|
|
|
679
668
|
default: return value;
|
|
680
669
|
}
|
|
681
670
|
}
|
|
671
|
+
const throwLifecycleErrors = (errors) => {
|
|
672
|
+
if (errors.length === 1) throw errors[0];
|
|
673
|
+
if (errors.length) throw new AggregateError(errors, "Multiple lifecycle failures");
|
|
674
|
+
};
|
|
675
|
+
const isDisposable = (value) => {
|
|
676
|
+
if (value == null) return false;
|
|
677
|
+
const kind = typeof value;
|
|
678
|
+
if (kind !== "object" && kind !== "function") return false;
|
|
679
|
+
try {
|
|
680
|
+
return typeof value[Symbol.asyncDispose] === "function" || typeof value[Symbol.dispose] === "function";
|
|
681
|
+
} catch {
|
|
682
|
+
return false;
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
const singletons = /* @__PURE__ */ new WeakSet();
|
|
686
|
+
const isSingleton = (value) => singletons.has(value);
|
|
687
|
+
const markSingletons = (value, depth = 4, seen = /* @__PURE__ */ new Set()) => {
|
|
688
|
+
if (value == null) return;
|
|
689
|
+
const kind = typeof value;
|
|
690
|
+
if (kind !== "object" && kind !== "function") return;
|
|
691
|
+
const object = value;
|
|
692
|
+
if (seen.has(object)) return;
|
|
693
|
+
seen.add(object);
|
|
694
|
+
singletons.add(object);
|
|
695
|
+
if (depth <= 0) return;
|
|
696
|
+
for (const key of Object.keys(object)) {
|
|
697
|
+
const descriptor = Object.getOwnPropertyDescriptor(object, key);
|
|
698
|
+
if (descriptor && "value" in descriptor) markSingletons(descriptor.value, depth - 1, seen);
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
const isSocketQuiet = (socket) => socket.readyState === 3 && !socket.data.inflight && !socket.data.opening && !socket.data.settling;
|
|
702
|
+
const isHTMLBundle = (value) => Object.prototype.toString.call(value) === "[object HTMLBundle]" || typeof value?.index === "string" && Array.isArray(value.files);
|
|
682
703
|
|
|
683
704
|
//#endregion
|
|
684
705
|
exports.ELYSIA_FORM_PROTOTYPE = ELYSIA_FORM_PROTOTYPE;
|
|
706
|
+
exports.assignOwn = assignOwn;
|
|
707
|
+
exports.authorityEnd = authorityEnd;
|
|
685
708
|
exports.bytes = bytes;
|
|
686
709
|
exports.clearFlattenChainMemo = clearFlattenChainMemo;
|
|
687
710
|
exports.cloneHook = cloneHook;
|
|
@@ -709,16 +732,22 @@ exports.invalidateMacroEpoch = invalidateMacroEpoch;
|
|
|
709
732
|
exports.isBlob = isBlob;
|
|
710
733
|
exports.isByteStream = isByteStream;
|
|
711
734
|
exports.isCompactBeforeHandleOnly = isCompactBeforeHandleOnly;
|
|
735
|
+
exports.isDisposable = isDisposable;
|
|
712
736
|
exports.isElysiaForm = isElysiaForm;
|
|
713
737
|
exports.isEmpty = isEmpty;
|
|
738
|
+
exports.isHTMLBundle = isHTMLBundle;
|
|
714
739
|
exports.isLocalScope = isLocalScope;
|
|
715
740
|
exports.isMapDeriveEntry = isMapDeriveEntry;
|
|
716
741
|
exports.isNotEmpty = isNotEmpty;
|
|
742
|
+
exports.isPlainObject = isPlainObject;
|
|
717
743
|
exports.isRecordNumber = isRecordNumber;
|
|
744
|
+
exports.isSingleton = isSingleton;
|
|
745
|
+
exports.isSocketQuiet = isSocketQuiet;
|
|
718
746
|
exports.joinPath = joinPath;
|
|
719
747
|
exports.macroEpoch = macroEpoch;
|
|
720
748
|
exports.macroOrigin = macroOrigin;
|
|
721
749
|
exports.mapDeriveEntry = mapDeriveEntry;
|
|
750
|
+
exports.markSingletons = markSingletons;
|
|
722
751
|
exports.mergeArray = mergeArray;
|
|
723
752
|
exports.mergeDeep = mergeDeep;
|
|
724
753
|
exports.mergeHook = mergeHook;
|
|
@@ -729,6 +758,9 @@ exports.pushField = pushField;
|
|
|
729
758
|
exports.redirect = redirect;
|
|
730
759
|
exports.replaceUrlPath = replaceUrlPath;
|
|
731
760
|
exports.requestId = requestId;
|
|
761
|
+
exports.rootSnapshot = rootSnapshot;
|
|
732
762
|
exports.schemaProperties = schemaProperties;
|
|
733
763
|
exports.serializeMacroSeed = serializeMacroSeed;
|
|
734
|
-
exports.sse = sse;
|
|
764
|
+
exports.sse = sse;
|
|
765
|
+
exports.sseData = sseData;
|
|
766
|
+
exports.throwLifecycleErrors = throwLifecycleErrors;
|