elysia 2.0.0-beta.13 → 2.0.0-beta.15
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 +4 -2
- package/dist/adapter/bun/index.js +35 -38
- package/dist/adapter/bun/index.mjs +35 -39
- package/dist/adapter/utils.js +16 -21
- package/dist/adapter/utils.mjs +16 -21
- package/dist/base.d.ts +28 -0
- package/dist/base.js +109 -59
- package/dist/base.mjs +110 -60
- package/dist/compile/aot.js +14 -21
- package/dist/compile/aot.mjs +14 -21
- package/dist/compile/handler/frozen-validator.js +51 -42
- package/dist/compile/handler/frozen-validator.mjs +51 -42
- package/dist/compile/handler/index.js +57 -50
- package/dist/compile/handler/index.mjs +57 -50
- package/dist/compile/handler/jit.js +36 -26
- package/dist/compile/handler/jit.mjs +37 -27
- package/dist/compile/handler/params.js +2 -0
- package/dist/compile/handler/params.mjs +3 -1
- package/dist/compile/handler/utils.d.ts +2 -2
- package/dist/compile/handler/utils.js +115 -111
- package/dist/compile/handler/utils.mjs +115 -113
- package/dist/context.d.ts +3 -1
- package/dist/context.js +2 -0
- package/dist/context.mjs +3 -1
- package/dist/cookie/config.js +6 -7
- package/dist/cookie/config.mjs +6 -7
- package/dist/error.d.ts +6 -3
- package/dist/error.js +26 -28
- package/dist/error.mjs +26 -28
- package/dist/handler/fetch.js +2 -1
- package/dist/handler/fetch.mjs +3 -2
- package/dist/handler/utils.d.ts +3 -1
- package/dist/handler/utils.js +19 -1
- package/dist/handler/utils.mjs +17 -1
- package/dist/index.d.ts +3 -3
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/core.js +4 -0
- package/dist/plugin/aot/core.mjs +4 -0
- package/dist/sucrose.js +60 -59
- package/dist/sucrose.mjs +60 -59
- package/dist/trace.js +6 -9
- package/dist/trace.mjs +6 -9
- package/dist/type/coerce-plan.js +41 -36
- package/dist/type/coerce-plan.mjs +41 -36
- package/dist/type/coerce.d.ts +1 -1
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/elysia/cookie.js +8 -17
- package/dist/type/elysia/cookie.mjs +8 -17
- package/dist/type/elysia/date.js +6 -7
- package/dist/type/elysia/date.mjs +6 -7
- package/dist/type/elysia/numeric.js +8 -9
- package/dist/type/elysia/numeric.mjs +8 -9
- 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/exports.d.ts +3 -2
- package/dist/type/exports.js +2 -0
- package/dist/type/exports.mjs +2 -1
- package/dist/type/index.js +2 -0
- package/dist/type/index.mjs +2 -0
- package/dist/type/validator/clean-safe.d.ts +1 -2
- package/dist/type/validator/clean-safe.js +0 -2
- package/dist/type/validator/clean-safe.mjs +1 -2
- package/dist/type/validator/custom-error.js +37 -26
- package/dist/type/validator/custom-error.mjs +37 -26
- package/dist/type/validator/default-precompute.js +24 -26
- package/dist/type/validator/default-precompute.mjs +24 -26
- package/dist/type/validator/exact-mirror.js +6 -8
- package/dist/type/validator/exact-mirror.mjs +6 -8
- package/dist/type/validator/index.js +64 -66
- package/dist/type/validator/index.mjs +65 -67
- package/dist/type/validator/validator-cache.d.ts +2 -2
- package/dist/type/validator/validator-cache.js +7 -10
- package/dist/type/validator/validator-cache.mjs +6 -9
- package/dist/types.d.ts +4 -3
- package/dist/universal/file.js +2 -6
- package/dist/universal/file.mjs +2 -6
- package/dist/utils.d.ts +11 -2
- package/dist/utils.js +85 -47
- package/dist/utils.mjs +82 -48
- package/dist/validator/index.js +14 -18
- package/dist/validator/index.mjs +14 -18
- package/dist/ws/context.js +9 -11
- package/dist/ws/context.mjs +9 -11
- package/dist/ws/parser.js +23 -20
- package/dist/ws/parser.mjs +23 -20
- package/dist/ws/route.js +76 -87
- package/dist/ws/route.mjs +76 -87
- package/package.json +5 -2
|
@@ -9,10 +9,6 @@ const require_validator_index = require('../../validator/index.js');
|
|
|
9
9
|
|
|
10
10
|
//#region src/compile/handler/frozen-validator.ts
|
|
11
11
|
const isBridgeNotInitialized = (error) => error instanceof Error && error.message.startsWith("Typebox module isn't initialized");
|
|
12
|
-
function codecCoercionBridgeFree(f, coerced, raw) {
|
|
13
|
-
return f.k === 1 && !!f.dm && !f.em && !f.ce && f.a !== 1 && !(f.d === 1 && f.ps !== 1) && innerCodecsAligned(f.ic?.length, coerced) && mirrorUnionsAligned(f.u, raw) && mirrorUnionsAligned(f.dm.u, coerced);
|
|
14
|
-
}
|
|
15
|
-
const innerCodecsAligned = (icLength, coerced) => require_compile_aot.reconstruct().collectStringCodecNodes(coerced).length === (icLength ?? 0);
|
|
16
12
|
function mirrorUnionsAligned(u, schema) {
|
|
17
13
|
if (!u) return true;
|
|
18
14
|
const branches = require_compile_aot.reconstruct().collectMirrorUnions(schema);
|
|
@@ -22,25 +18,13 @@ function mirrorUnionsAligned(u, schema) {
|
|
|
22
18
|
}
|
|
23
19
|
function isBridgeFreeComplete(f, schema, raw) {
|
|
24
20
|
if (!f.cm) return false;
|
|
25
|
-
if (
|
|
21
|
+
if (f.k === 1 && !!f.dm && !f.em && !f.ce && f.a !== 1 && !(f.d === 1 && f.ps !== 1) && (f.ic?.length ?? 0) === require_compile_aot.reconstruct().collectStringCodecNodes(schema).length && mirrorUnionsAligned(f.u, raw) && mirrorUnionsAligned(f.dm.u, schema)) return true;
|
|
26
22
|
if (f.e === 1 || f.u || f.dm || f.em || f.k === 1 || f.ce || f.ic || f.a === 1) return false;
|
|
27
23
|
if (f.d === 1 && f.ps !== 1) return false;
|
|
28
24
|
if (require_type_validator_clean_safe.isFullyClosedObject(schema)) return false;
|
|
29
25
|
return true;
|
|
30
26
|
}
|
|
31
27
|
const EMPTY_EXTERNALS = Object.freeze([]);
|
|
32
|
-
function jsTypeMatches(value, type) {
|
|
33
|
-
switch (type) {
|
|
34
|
-
case "string": return typeof value === "string";
|
|
35
|
-
case "number": return typeof value === "number";
|
|
36
|
-
case "integer": return typeof value === "number" && Number.isInteger(value);
|
|
37
|
-
case "boolean": return typeof value === "boolean";
|
|
38
|
-
case "null": return value === null;
|
|
39
|
-
case "array": return Array.isArray(value);
|
|
40
|
-
case "object": return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
41
|
-
default: return true;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
28
|
const typeError = (schema, instancePath, schemaPath) => ({
|
|
45
29
|
keyword: "type",
|
|
46
30
|
schemaPath,
|
|
@@ -98,27 +82,34 @@ function walkCompactError(schema, value, instancePath, schemaPath) {
|
|
|
98
82
|
}
|
|
99
83
|
return;
|
|
100
84
|
}
|
|
101
|
-
if (typeof type === "string"
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
85
|
+
if (typeof type === "string") {
|
|
86
|
+
let matches;
|
|
87
|
+
switch (type) {
|
|
88
|
+
case "string":
|
|
89
|
+
matches = typeof value === "string";
|
|
90
|
+
break;
|
|
91
|
+
case "number":
|
|
92
|
+
matches = typeof value === "number";
|
|
93
|
+
break;
|
|
94
|
+
case "integer":
|
|
95
|
+
matches = typeof value === "number" && Number.isInteger(value);
|
|
96
|
+
break;
|
|
97
|
+
case "boolean":
|
|
98
|
+
matches = typeof value === "boolean";
|
|
99
|
+
break;
|
|
100
|
+
case "null":
|
|
101
|
+
matches = value === null;
|
|
102
|
+
break;
|
|
103
|
+
case "array":
|
|
104
|
+
matches = Array.isArray(value);
|
|
105
|
+
break;
|
|
106
|
+
case "object":
|
|
107
|
+
matches = typeof value === "object" && value !== null && !Array.isArray(value);
|
|
108
|
+
break;
|
|
109
|
+
default: matches = true;
|
|
110
|
+
}
|
|
111
|
+
if (!matches) return typeError(schema, instancePath, schemaPath);
|
|
114
112
|
}
|
|
115
|
-
return {
|
|
116
|
-
keyword: "type",
|
|
117
|
-
schemaPath: "#",
|
|
118
|
-
instancePath: "",
|
|
119
|
-
params: {},
|
|
120
|
-
message: `must match ${schema?.["~kind"] ?? "schema"}`
|
|
121
|
-
};
|
|
122
113
|
}
|
|
123
114
|
function isCompactDiagnosable(schema) {
|
|
124
115
|
if (!schema || typeof schema !== "object") return false;
|
|
@@ -190,7 +181,28 @@ var FrozenSlotValidator = class {
|
|
|
190
181
|
Errors(value) {
|
|
191
182
|
const hit = walkCompactError(this.schema, value, "", "#");
|
|
192
183
|
if (hit) return [hit];
|
|
193
|
-
|
|
184
|
+
const schema = this.schema;
|
|
185
|
+
let error;
|
|
186
|
+
if (schema?.type === "object" && typeof value === "object" && value !== null && !Array.isArray(value) && schema.properties) for (const key in schema.properties) {
|
|
187
|
+
if (!(key in value)) continue;
|
|
188
|
+
if (isCompactDiagnosable(schema.properties[key])) continue;
|
|
189
|
+
error = {
|
|
190
|
+
keyword: "type",
|
|
191
|
+
schemaPath: `#/properties/${key}`,
|
|
192
|
+
instancePath: `/${key}`,
|
|
193
|
+
params: {},
|
|
194
|
+
message: `must match ${schema.properties[key]?.["~kind"] ?? "schema"}`
|
|
195
|
+
};
|
|
196
|
+
break;
|
|
197
|
+
}
|
|
198
|
+
if (!error) error = {
|
|
199
|
+
keyword: "type",
|
|
200
|
+
schemaPath: "#",
|
|
201
|
+
instancePath: "",
|
|
202
|
+
params: {},
|
|
203
|
+
message: `must match ${schema?.["~kind"] ?? "schema"}`
|
|
204
|
+
};
|
|
205
|
+
return [error];
|
|
194
206
|
}
|
|
195
207
|
#error(value, type) {
|
|
196
208
|
return new require_error.ValidationError(type, value, () => this.Errors(value), this.schema);
|
|
@@ -201,15 +213,12 @@ var FrozenSlotValidator = class {
|
|
|
201
213
|
if (value === null || typeof value !== "object") return value;
|
|
202
214
|
return defaults.clone ? defaults.clone() : structuredClone(value);
|
|
203
215
|
}
|
|
204
|
-
#applyDefault(value) {
|
|
205
|
-
return this.#defaultFastPath.merge(value);
|
|
206
|
-
}
|
|
207
216
|
From(value, type) {
|
|
208
217
|
if (this.#hasDefault) {
|
|
209
218
|
const defaults = this.#defaultFastPath;
|
|
210
219
|
if (defaults) {
|
|
211
220
|
if (value === void 0 || value === null && defaults.appliesToNull) value = this.#cloneSharedDefault();
|
|
212
|
-
else if (value !== null && typeof value === "object" && defaults.merge !== void 0) value = this.#
|
|
221
|
+
else if (value !== null && typeof value === "object" && defaults.merge !== void 0) value = this.#defaultFastPath.merge(value);
|
|
213
222
|
}
|
|
214
223
|
}
|
|
215
224
|
if (this.#hasOptional) {
|
|
@@ -8,10 +8,6 @@ import { StandardValidator } from "../../validator/index.mjs";
|
|
|
8
8
|
|
|
9
9
|
//#region src/compile/handler/frozen-validator.ts
|
|
10
10
|
const isBridgeNotInitialized = (error) => error instanceof Error && error.message.startsWith("Typebox module isn't initialized");
|
|
11
|
-
function codecCoercionBridgeFree(f, coerced, raw) {
|
|
12
|
-
return f.k === 1 && !!f.dm && !f.em && !f.ce && f.a !== 1 && !(f.d === 1 && f.ps !== 1) && innerCodecsAligned(f.ic?.length, coerced) && mirrorUnionsAligned(f.u, raw) && mirrorUnionsAligned(f.dm.u, coerced);
|
|
13
|
-
}
|
|
14
|
-
const innerCodecsAligned = (icLength, coerced) => reconstruct().collectStringCodecNodes(coerced).length === (icLength ?? 0);
|
|
15
11
|
function mirrorUnionsAligned(u, schema) {
|
|
16
12
|
if (!u) return true;
|
|
17
13
|
const branches = reconstruct().collectMirrorUnions(schema);
|
|
@@ -21,25 +17,13 @@ function mirrorUnionsAligned(u, schema) {
|
|
|
21
17
|
}
|
|
22
18
|
function isBridgeFreeComplete(f, schema, raw) {
|
|
23
19
|
if (!f.cm) return false;
|
|
24
|
-
if (
|
|
20
|
+
if (f.k === 1 && !!f.dm && !f.em && !f.ce && f.a !== 1 && !(f.d === 1 && f.ps !== 1) && (f.ic?.length ?? 0) === reconstruct().collectStringCodecNodes(schema).length && mirrorUnionsAligned(f.u, raw) && mirrorUnionsAligned(f.dm.u, schema)) return true;
|
|
25
21
|
if (f.e === 1 || f.u || f.dm || f.em || f.k === 1 || f.ce || f.ic || f.a === 1) return false;
|
|
26
22
|
if (f.d === 1 && f.ps !== 1) return false;
|
|
27
23
|
if (isFullyClosedObject(schema)) return false;
|
|
28
24
|
return true;
|
|
29
25
|
}
|
|
30
26
|
const EMPTY_EXTERNALS = Object.freeze([]);
|
|
31
|
-
function jsTypeMatches(value, type) {
|
|
32
|
-
switch (type) {
|
|
33
|
-
case "string": return typeof value === "string";
|
|
34
|
-
case "number": return typeof value === "number";
|
|
35
|
-
case "integer": return typeof value === "number" && Number.isInteger(value);
|
|
36
|
-
case "boolean": return typeof value === "boolean";
|
|
37
|
-
case "null": return value === null;
|
|
38
|
-
case "array": return Array.isArray(value);
|
|
39
|
-
case "object": return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
40
|
-
default: return true;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
27
|
const typeError = (schema, instancePath, schemaPath) => ({
|
|
44
28
|
keyword: "type",
|
|
45
29
|
schemaPath,
|
|
@@ -97,27 +81,34 @@ function walkCompactError(schema, value, instancePath, schemaPath) {
|
|
|
97
81
|
}
|
|
98
82
|
return;
|
|
99
83
|
}
|
|
100
|
-
if (typeof type === "string"
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
84
|
+
if (typeof type === "string") {
|
|
85
|
+
let matches;
|
|
86
|
+
switch (type) {
|
|
87
|
+
case "string":
|
|
88
|
+
matches = typeof value === "string";
|
|
89
|
+
break;
|
|
90
|
+
case "number":
|
|
91
|
+
matches = typeof value === "number";
|
|
92
|
+
break;
|
|
93
|
+
case "integer":
|
|
94
|
+
matches = typeof value === "number" && Number.isInteger(value);
|
|
95
|
+
break;
|
|
96
|
+
case "boolean":
|
|
97
|
+
matches = typeof value === "boolean";
|
|
98
|
+
break;
|
|
99
|
+
case "null":
|
|
100
|
+
matches = value === null;
|
|
101
|
+
break;
|
|
102
|
+
case "array":
|
|
103
|
+
matches = Array.isArray(value);
|
|
104
|
+
break;
|
|
105
|
+
case "object":
|
|
106
|
+
matches = typeof value === "object" && value !== null && !Array.isArray(value);
|
|
107
|
+
break;
|
|
108
|
+
default: matches = true;
|
|
109
|
+
}
|
|
110
|
+
if (!matches) return typeError(schema, instancePath, schemaPath);
|
|
113
111
|
}
|
|
114
|
-
return {
|
|
115
|
-
keyword: "type",
|
|
116
|
-
schemaPath: "#",
|
|
117
|
-
instancePath: "",
|
|
118
|
-
params: {},
|
|
119
|
-
message: `must match ${schema?.["~kind"] ?? "schema"}`
|
|
120
|
-
};
|
|
121
112
|
}
|
|
122
113
|
function isCompactDiagnosable(schema) {
|
|
123
114
|
if (!schema || typeof schema !== "object") return false;
|
|
@@ -189,7 +180,28 @@ var FrozenSlotValidator = class {
|
|
|
189
180
|
Errors(value) {
|
|
190
181
|
const hit = walkCompactError(this.schema, value, "", "#");
|
|
191
182
|
if (hit) return [hit];
|
|
192
|
-
|
|
183
|
+
const schema = this.schema;
|
|
184
|
+
let error;
|
|
185
|
+
if (schema?.type === "object" && typeof value === "object" && value !== null && !Array.isArray(value) && schema.properties) for (const key in schema.properties) {
|
|
186
|
+
if (!(key in value)) continue;
|
|
187
|
+
if (isCompactDiagnosable(schema.properties[key])) continue;
|
|
188
|
+
error = {
|
|
189
|
+
keyword: "type",
|
|
190
|
+
schemaPath: `#/properties/${key}`,
|
|
191
|
+
instancePath: `/${key}`,
|
|
192
|
+
params: {},
|
|
193
|
+
message: `must match ${schema.properties[key]?.["~kind"] ?? "schema"}`
|
|
194
|
+
};
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
if (!error) error = {
|
|
198
|
+
keyword: "type",
|
|
199
|
+
schemaPath: "#",
|
|
200
|
+
instancePath: "",
|
|
201
|
+
params: {},
|
|
202
|
+
message: `must match ${schema?.["~kind"] ?? "schema"}`
|
|
203
|
+
};
|
|
204
|
+
return [error];
|
|
193
205
|
}
|
|
194
206
|
#error(value, type) {
|
|
195
207
|
return new ValidationError(type, value, () => this.Errors(value), this.schema);
|
|
@@ -200,15 +212,12 @@ var FrozenSlotValidator = class {
|
|
|
200
212
|
if (value === null || typeof value !== "object") return value;
|
|
201
213
|
return defaults.clone ? defaults.clone() : structuredClone(value);
|
|
202
214
|
}
|
|
203
|
-
#applyDefault(value) {
|
|
204
|
-
return this.#defaultFastPath.merge(value);
|
|
205
|
-
}
|
|
206
215
|
From(value, type) {
|
|
207
216
|
if (this.#hasDefault) {
|
|
208
217
|
const defaults = this.#defaultFastPath;
|
|
209
218
|
if (defaults) {
|
|
210
219
|
if (value === void 0 || value === null && defaults.appliesToNull) value = this.#cloneSharedDefault();
|
|
211
|
-
else if (value !== null && typeof value === "object" && defaults.merge !== void 0) value = this.#
|
|
220
|
+
else if (value !== null && typeof value === "object" && defaults.merge !== void 0) value = this.#defaultFastPath.merge(value);
|
|
212
221
|
}
|
|
213
222
|
}
|
|
214
223
|
if (this.#hasOptional) {
|
|
@@ -12,14 +12,6 @@ const require_compile_handler_reconstruct = require('./reconstruct.js');
|
|
|
12
12
|
const require_adapter_constants = require('../../adapter/constants.js');
|
|
13
13
|
|
|
14
14
|
//#region src/compile/handler/index.ts
|
|
15
|
-
function resolveMountHandler(meta, path) {
|
|
16
|
-
const { handle, suffixLen } = meta;
|
|
17
|
-
const rawRoot = suffixLen ? path.slice(0, path.length - suffixLen) : path;
|
|
18
|
-
const encRoot = encodeURI(rawRoot);
|
|
19
|
-
const rawLen = rawRoot.length;
|
|
20
|
-
const encLen = encRoot.length;
|
|
21
|
-
return (c) => handle(new Request(require_utils.replaceUrlPath(c.request.url, c.path.slice(c.path.startsWith(encRoot) ? encLen : rawLen) || "/"), c.request));
|
|
22
|
-
}
|
|
23
15
|
function applyHook(localHook, appHook, rootHook, appHookFresh = false) {
|
|
24
16
|
let hook;
|
|
25
17
|
if (localHook && appHook) hook = require_utils.mergeHook(require_utils.cloneHook(localHook), appHook, true);
|
|
@@ -79,21 +71,6 @@ function dropHooksByOrigin(hook, skip) {
|
|
|
79
71
|
}
|
|
80
72
|
return out;
|
|
81
73
|
}
|
|
82
|
-
function reconstructNeedsHookState(names) {
|
|
83
|
-
for (let i = 0; i < names.length; i++) switch (names[i]) {
|
|
84
|
-
case "ho":
|
|
85
|
-
case "tf":
|
|
86
|
-
case "bf":
|
|
87
|
-
case "af":
|
|
88
|
-
case "mr":
|
|
89
|
-
case "er":
|
|
90
|
-
case "ar":
|
|
91
|
-
case "va":
|
|
92
|
-
case "cc":
|
|
93
|
-
case "tr": return true;
|
|
94
|
-
}
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
74
|
function promoteDerive(hook) {
|
|
98
75
|
const derive = hook.derive;
|
|
99
76
|
if (derive === void 0) return;
|
|
@@ -204,14 +181,6 @@ function chainResolver(root) {
|
|
|
204
181
|
return frozenRoot["~ext"]?.macro || frozenRoot["~scopeChildren"] ? (node) => resolveChainNode(root, node) : void 0;
|
|
205
182
|
}
|
|
206
183
|
const localMacroRoot = (instance, root) => instance !== root && instance["~scopeChild"] === true && require_generation.frozenRootOf(instance)["~ext"]?.macro ? instance : root;
|
|
207
|
-
function composeRootHook(root, inheritedChain) {
|
|
208
|
-
const resolve = chainResolver(root);
|
|
209
|
-
const locals = require_utils.flattenChain(require_generation.frozenRootOf(root)["~hookChain"], require_utils.isLocalScope, inheritedChain, resolve);
|
|
210
|
-
const inherited = locals ? require_utils.flattenChainMemo(root, inheritedChain, resolve) : require_utils.flattenChainMemoReadonly(root, inheritedChain, resolve);
|
|
211
|
-
if (!inherited) return locals;
|
|
212
|
-
if (!locals) return inherited;
|
|
213
|
-
return require_utils.mergeHook(inherited, locals);
|
|
214
|
-
}
|
|
215
184
|
function staticPrimitiveType(response, value) {
|
|
216
185
|
if ((typeof value === "string" || typeof value === "number" || typeof value === "boolean") && !response.headers.has("content-type")) response.headers.set("content-type", "text/plain;charset=utf-8");
|
|
217
186
|
return response;
|
|
@@ -221,7 +190,18 @@ function buildNativeStaticResponse(route, root) {
|
|
|
221
190
|
if (typeof handler === "function" || handler instanceof Error || handler instanceof Promise) return;
|
|
222
191
|
const frozenRoot = require_generation.frozenRootOf(root);
|
|
223
192
|
const adapter = frozenRoot["~config"]?.adapter ?? require_adapter_constants.defaultAdapter;
|
|
224
|
-
const
|
|
193
|
+
const ownedHook = resolveLocalHook(localMacroRoot(macroScope ?? instance, root), localHook, root);
|
|
194
|
+
const flatAppHook = require_utils.flattenChainMemo(root, appHook, chainResolver(root));
|
|
195
|
+
let rootHook;
|
|
196
|
+
if (instance !== root) {
|
|
197
|
+
const resolve = chainResolver(root);
|
|
198
|
+
const locals = require_utils.flattenChain(require_generation.frozenRootOf(root)["~hookChain"], require_utils.isLocalScope, inheritedChain, resolve);
|
|
199
|
+
const inherited = locals ? require_utils.flattenChainMemo(root, inheritedChain, resolve) : require_utils.flattenChainMemoReadonly(root, inheritedChain, resolve);
|
|
200
|
+
if (!inherited) rootHook = locals;
|
|
201
|
+
else if (!locals) rootHook = inherited;
|
|
202
|
+
else rootHook = require_utils.mergeHook(inherited, locals);
|
|
203
|
+
} else rootHook = void 0;
|
|
204
|
+
const hook = applyHook(ownedHook, flatAppHook, rootHook, true);
|
|
225
205
|
if (hook && !require_compile_handler_descriptor.isEmptyPipelineHook(hook)) return;
|
|
226
206
|
const rootHeaders = frozenRoot["~ext"]?.headers;
|
|
227
207
|
if (handler instanceof Response && !rootHeaders) return handler;
|
|
@@ -278,28 +258,48 @@ function composeRouteHook(instance, localHook, appHook, inheritedChain, root, ma
|
|
|
278
258
|
}
|
|
279
259
|
const isBareArrow = /^(?:async\s*)?\(\s*\)\s*=>/;
|
|
280
260
|
const isSucroseOpaque = /arguments|eval|\[native code\]/;
|
|
281
|
-
function isContextFreeHandler(handler) {
|
|
282
|
-
if (Object.hasOwn(handler, "toString")) return false;
|
|
283
|
-
const source = Function.prototype.toString.call(handler);
|
|
284
|
-
return isBareArrow.test(source) && !isSucroseOpaque.test(source);
|
|
285
|
-
}
|
|
286
261
|
function compileHandler(route, root, precomputedStatic, liveOnly = false) {
|
|
287
262
|
let [_method, path, handler, instance, localHook, appHook, inheritedChain, macroScope] = route;
|
|
288
263
|
const frozenRoot = require_generation.frozenRootOf(root);
|
|
289
264
|
const adapter = frozenRoot["~config"]?.adapter ?? require_adapter_constants.defaultAdapter;
|
|
290
265
|
const method = _method;
|
|
291
266
|
const mountMeta = typeof handler === "function" ? handler["~mount"] : void 0;
|
|
292
|
-
if (mountMeta)
|
|
267
|
+
if (mountMeta) {
|
|
268
|
+
const { handle, suffixLen } = mountMeta;
|
|
269
|
+
const rawRoot = suffixLen ? path.slice(0, path.length - suffixLen) : path;
|
|
270
|
+
const encRoot = encodeURI(rawRoot);
|
|
271
|
+
const rawLen = rawRoot.length;
|
|
272
|
+
const encLen = encRoot.length;
|
|
273
|
+
handler = (c) => handle(new Request(require_utils.replaceUrlPath(c.request.url, c.path.slice(c.path.startsWith(encRoot) ? encLen : rawLen) || "/"), c.request));
|
|
274
|
+
}
|
|
293
275
|
const reconstructed = liveOnly ? void 0 : require_compile_aot.Compiled.getHandler(frozenRoot["~programId"], method, path);
|
|
294
|
-
if (reconstructed && !precomputedStatic && typeof handler === "function" && !frozenRoot["~ext"]?.macro && !require_generation.frozenRootOf(localMacroRoot(macroScope ?? instance, root))["~ext"]?.macro
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
276
|
+
if (reconstructed && !precomputedStatic && typeof handler === "function" && !frozenRoot["~ext"]?.macro && !require_generation.frozenRootOf(localMacroRoot(macroScope ?? instance, root))["~ext"]?.macro) {
|
|
277
|
+
let needsHookState = false;
|
|
278
|
+
const names = reconstructed.a;
|
|
279
|
+
hookState: for (let i = 0; i < names.length; i++) switch (names[i]) {
|
|
280
|
+
case "ho":
|
|
281
|
+
case "tf":
|
|
282
|
+
case "bf":
|
|
283
|
+
case "af":
|
|
284
|
+
case "mr":
|
|
285
|
+
case "er":
|
|
286
|
+
case "ar":
|
|
287
|
+
case "va":
|
|
288
|
+
case "cc":
|
|
289
|
+
case "tr":
|
|
290
|
+
needsHookState = true;
|
|
291
|
+
break hookState;
|
|
292
|
+
}
|
|
293
|
+
if (!needsHookState) return reconstructed.f(handler, ...require_compile_handler_params.resolveHandlerParams(reconstructed.a, {
|
|
294
|
+
root,
|
|
295
|
+
parse: adapter.parse,
|
|
296
|
+
res: adapter.response,
|
|
297
|
+
hook: require_utils.nullObject(),
|
|
298
|
+
vali: void 0,
|
|
299
|
+
cookieConfig: void 0,
|
|
300
|
+
tracers: void 0
|
|
301
|
+
}));
|
|
302
|
+
}
|
|
303
303
|
const hook = composeRouteHook(instance, localHook, appHook, inheritedChain, root, macroScope, !reconstructed);
|
|
304
304
|
if (hook) {
|
|
305
305
|
promoteDerive(hook);
|
|
@@ -345,9 +345,16 @@ function compileHandler(route, root, precomputedStatic, liveOnly = false) {
|
|
|
345
345
|
cookieConfig: reconstructed.a.includes("cc") ? require_compile_handler_reconstruct.Reconstrct.cookie(hook, root) : void 0,
|
|
346
346
|
tracers: reconstructed.a.includes("tr") ? require_compile_handler_reconstruct.Reconstrct.trace(hook, root) : void 0
|
|
347
347
|
}));
|
|
348
|
-
if (hook === void 0 && isHandleFunction && !precomputedStatic && !mountMeta && (method === "GET" || method === "HEAD") && !root["~hasTrace"] && root["~introspect"] !== true && root["~config"]?.introspect !== true && !require_utils.isNotEmpty(frozenRoot["~ext"]?.headers) && !require_compile_aot.Capture.isAotBuildEnv() && !require_compile_aot.Capture.isCapturing()
|
|
349
|
-
|
|
350
|
-
if (
|
|
348
|
+
if (hook === void 0 && isHandleFunction && !precomputedStatic && !mountMeta && (method === "GET" || method === "HEAD") && !root["~hasTrace"] && root["~introspect"] !== true && root["~config"]?.introspect !== true && !require_utils.isNotEmpty(frozenRoot["~ext"]?.headers) && !require_compile_aot.Capture.isAotBuildEnv() && !require_compile_aot.Capture.isCapturing()) {
|
|
349
|
+
let isContextFree = false;
|
|
350
|
+
if (!Object.hasOwn(handler, "toString")) {
|
|
351
|
+
const source = Function.prototype.toString.call(handler);
|
|
352
|
+
isContextFree = isBareArrow.test(source) && !isSucroseOpaque.test(source);
|
|
353
|
+
}
|
|
354
|
+
if (isContextFree) {
|
|
355
|
+
const compact = adapter.response.compact;
|
|
356
|
+
if (compact) return require_compile_handler_jit.createInlineHandler(compact, handler);
|
|
357
|
+
}
|
|
351
358
|
}
|
|
352
359
|
const state = require_compile_handler_descriptor.describeRoute({
|
|
353
360
|
method,
|
|
@@ -11,14 +11,6 @@ import { Reconstrct } from "./reconstruct.mjs";
|
|
|
11
11
|
import { defaultAdapter } from "../../adapter/constants.mjs";
|
|
12
12
|
|
|
13
13
|
//#region src/compile/handler/index.ts
|
|
14
|
-
function resolveMountHandler(meta, path) {
|
|
15
|
-
const { handle, suffixLen } = meta;
|
|
16
|
-
const rawRoot = suffixLen ? path.slice(0, path.length - suffixLen) : path;
|
|
17
|
-
const encRoot = encodeURI(rawRoot);
|
|
18
|
-
const rawLen = rawRoot.length;
|
|
19
|
-
const encLen = encRoot.length;
|
|
20
|
-
return (c) => handle(new Request(replaceUrlPath(c.request.url, c.path.slice(c.path.startsWith(encRoot) ? encLen : rawLen) || "/"), c.request));
|
|
21
|
-
}
|
|
22
14
|
function applyHook(localHook, appHook, rootHook, appHookFresh = false) {
|
|
23
15
|
let hook;
|
|
24
16
|
if (localHook && appHook) hook = mergeHook(cloneHook(localHook), appHook, true);
|
|
@@ -78,21 +70,6 @@ function dropHooksByOrigin(hook, skip) {
|
|
|
78
70
|
}
|
|
79
71
|
return out;
|
|
80
72
|
}
|
|
81
|
-
function reconstructNeedsHookState(names) {
|
|
82
|
-
for (let i = 0; i < names.length; i++) switch (names[i]) {
|
|
83
|
-
case "ho":
|
|
84
|
-
case "tf":
|
|
85
|
-
case "bf":
|
|
86
|
-
case "af":
|
|
87
|
-
case "mr":
|
|
88
|
-
case "er":
|
|
89
|
-
case "ar":
|
|
90
|
-
case "va":
|
|
91
|
-
case "cc":
|
|
92
|
-
case "tr": return true;
|
|
93
|
-
}
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
73
|
function promoteDerive(hook) {
|
|
97
74
|
const derive = hook.derive;
|
|
98
75
|
if (derive === void 0) return;
|
|
@@ -203,14 +180,6 @@ function chainResolver(root) {
|
|
|
203
180
|
return frozenRoot["~ext"]?.macro || frozenRoot["~scopeChildren"] ? (node) => resolveChainNode(root, node) : void 0;
|
|
204
181
|
}
|
|
205
182
|
const localMacroRoot = (instance, root) => instance !== root && instance["~scopeChild"] === true && frozenRootOf(instance)["~ext"]?.macro ? instance : root;
|
|
206
|
-
function composeRootHook(root, inheritedChain) {
|
|
207
|
-
const resolve = chainResolver(root);
|
|
208
|
-
const locals = flattenChain(frozenRootOf(root)["~hookChain"], isLocalScope, inheritedChain, resolve);
|
|
209
|
-
const inherited = locals ? flattenChainMemo(root, inheritedChain, resolve) : flattenChainMemoReadonly(root, inheritedChain, resolve);
|
|
210
|
-
if (!inherited) return locals;
|
|
211
|
-
if (!locals) return inherited;
|
|
212
|
-
return mergeHook(inherited, locals);
|
|
213
|
-
}
|
|
214
183
|
function staticPrimitiveType(response, value) {
|
|
215
184
|
if ((typeof value === "string" || typeof value === "number" || typeof value === "boolean") && !response.headers.has("content-type")) response.headers.set("content-type", "text/plain;charset=utf-8");
|
|
216
185
|
return response;
|
|
@@ -220,7 +189,18 @@ function buildNativeStaticResponse(route, root) {
|
|
|
220
189
|
if (typeof handler === "function" || handler instanceof Error || handler instanceof Promise) return;
|
|
221
190
|
const frozenRoot = frozenRootOf(root);
|
|
222
191
|
const adapter = frozenRoot["~config"]?.adapter ?? defaultAdapter;
|
|
223
|
-
const
|
|
192
|
+
const ownedHook = resolveLocalHook(localMacroRoot(macroScope ?? instance, root), localHook, root);
|
|
193
|
+
const flatAppHook = flattenChainMemo(root, appHook, chainResolver(root));
|
|
194
|
+
let rootHook;
|
|
195
|
+
if (instance !== root) {
|
|
196
|
+
const resolve = chainResolver(root);
|
|
197
|
+
const locals = flattenChain(frozenRootOf(root)["~hookChain"], isLocalScope, inheritedChain, resolve);
|
|
198
|
+
const inherited = locals ? flattenChainMemo(root, inheritedChain, resolve) : flattenChainMemoReadonly(root, inheritedChain, resolve);
|
|
199
|
+
if (!inherited) rootHook = locals;
|
|
200
|
+
else if (!locals) rootHook = inherited;
|
|
201
|
+
else rootHook = mergeHook(inherited, locals);
|
|
202
|
+
} else rootHook = void 0;
|
|
203
|
+
const hook = applyHook(ownedHook, flatAppHook, rootHook, true);
|
|
224
204
|
if (hook && !isEmptyPipelineHook(hook)) return;
|
|
225
205
|
const rootHeaders = frozenRoot["~ext"]?.headers;
|
|
226
206
|
if (handler instanceof Response && !rootHeaders) return handler;
|
|
@@ -277,28 +257,48 @@ function composeRouteHook(instance, localHook, appHook, inheritedChain, root, ma
|
|
|
277
257
|
}
|
|
278
258
|
const isBareArrow = /^(?:async\s*)?\(\s*\)\s*=>/;
|
|
279
259
|
const isSucroseOpaque = /arguments|eval|\[native code\]/;
|
|
280
|
-
function isContextFreeHandler(handler) {
|
|
281
|
-
if (Object.hasOwn(handler, "toString")) return false;
|
|
282
|
-
const source = Function.prototype.toString.call(handler);
|
|
283
|
-
return isBareArrow.test(source) && !isSucroseOpaque.test(source);
|
|
284
|
-
}
|
|
285
260
|
function compileHandler(route, root, precomputedStatic, liveOnly = false) {
|
|
286
261
|
let [_method, path, handler, instance, localHook, appHook, inheritedChain, macroScope] = route;
|
|
287
262
|
const frozenRoot = frozenRootOf(root);
|
|
288
263
|
const adapter = frozenRoot["~config"]?.adapter ?? defaultAdapter;
|
|
289
264
|
const method = _method;
|
|
290
265
|
const mountMeta = typeof handler === "function" ? handler["~mount"] : void 0;
|
|
291
|
-
if (mountMeta)
|
|
266
|
+
if (mountMeta) {
|
|
267
|
+
const { handle, suffixLen } = mountMeta;
|
|
268
|
+
const rawRoot = suffixLen ? path.slice(0, path.length - suffixLen) : path;
|
|
269
|
+
const encRoot = encodeURI(rawRoot);
|
|
270
|
+
const rawLen = rawRoot.length;
|
|
271
|
+
const encLen = encRoot.length;
|
|
272
|
+
handler = (c) => handle(new Request(replaceUrlPath(c.request.url, c.path.slice(c.path.startsWith(encRoot) ? encLen : rawLen) || "/"), c.request));
|
|
273
|
+
}
|
|
292
274
|
const reconstructed = liveOnly ? void 0 : Compiled.getHandler(frozenRoot["~programId"], method, path);
|
|
293
|
-
if (reconstructed && !precomputedStatic && typeof handler === "function" && !frozenRoot["~ext"]?.macro && !frozenRootOf(localMacroRoot(macroScope ?? instance, root))["~ext"]?.macro
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
275
|
+
if (reconstructed && !precomputedStatic && typeof handler === "function" && !frozenRoot["~ext"]?.macro && !frozenRootOf(localMacroRoot(macroScope ?? instance, root))["~ext"]?.macro) {
|
|
276
|
+
let needsHookState = false;
|
|
277
|
+
const names = reconstructed.a;
|
|
278
|
+
hookState: for (let i = 0; i < names.length; i++) switch (names[i]) {
|
|
279
|
+
case "ho":
|
|
280
|
+
case "tf":
|
|
281
|
+
case "bf":
|
|
282
|
+
case "af":
|
|
283
|
+
case "mr":
|
|
284
|
+
case "er":
|
|
285
|
+
case "ar":
|
|
286
|
+
case "va":
|
|
287
|
+
case "cc":
|
|
288
|
+
case "tr":
|
|
289
|
+
needsHookState = true;
|
|
290
|
+
break hookState;
|
|
291
|
+
}
|
|
292
|
+
if (!needsHookState) return reconstructed.f(handler, ...resolveHandlerParams(reconstructed.a, {
|
|
293
|
+
root,
|
|
294
|
+
parse: adapter.parse,
|
|
295
|
+
res: adapter.response,
|
|
296
|
+
hook: nullObject(),
|
|
297
|
+
vali: void 0,
|
|
298
|
+
cookieConfig: void 0,
|
|
299
|
+
tracers: void 0
|
|
300
|
+
}));
|
|
301
|
+
}
|
|
302
302
|
const hook = composeRouteHook(instance, localHook, appHook, inheritedChain, root, macroScope, !reconstructed);
|
|
303
303
|
if (hook) {
|
|
304
304
|
promoteDerive(hook);
|
|
@@ -344,9 +344,16 @@ function compileHandler(route, root, precomputedStatic, liveOnly = false) {
|
|
|
344
344
|
cookieConfig: reconstructed.a.includes("cc") ? Reconstrct.cookie(hook, root) : void 0,
|
|
345
345
|
tracers: reconstructed.a.includes("tr") ? Reconstrct.trace(hook, root) : void 0
|
|
346
346
|
}));
|
|
347
|
-
if (hook === void 0 && isHandleFunction && !precomputedStatic && !mountMeta && (method === "GET" || method === "HEAD") && !root["~hasTrace"] && root["~introspect"] !== true && root["~config"]?.introspect !== true && !isNotEmpty(frozenRoot["~ext"]?.headers) && !Capture.isAotBuildEnv() && !Capture.isCapturing()
|
|
348
|
-
|
|
349
|
-
if (
|
|
347
|
+
if (hook === void 0 && isHandleFunction && !precomputedStatic && !mountMeta && (method === "GET" || method === "HEAD") && !root["~hasTrace"] && root["~introspect"] !== true && root["~config"]?.introspect !== true && !isNotEmpty(frozenRoot["~ext"]?.headers) && !Capture.isAotBuildEnv() && !Capture.isCapturing()) {
|
|
348
|
+
let isContextFree = false;
|
|
349
|
+
if (!Object.hasOwn(handler, "toString")) {
|
|
350
|
+
const source = Function.prototype.toString.call(handler);
|
|
351
|
+
isContextFree = isBareArrow.test(source) && !isSucroseOpaque.test(source);
|
|
352
|
+
}
|
|
353
|
+
if (isContextFree) {
|
|
354
|
+
const compact = adapter.response.compact;
|
|
355
|
+
if (compact) return createInlineHandler(compact, handler);
|
|
356
|
+
}
|
|
350
357
|
}
|
|
351
358
|
const state = describeRoute({
|
|
352
359
|
method,
|