elysia 2.0.0-exp.49 → 2.0.0-exp.50
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/web-standard/handler.js +23 -27
- package/dist/adapter/web-standard/handler.mjs +23 -27
- package/dist/base.js +1 -2
- package/dist/base.mjs +1 -2
- package/dist/compile/aot-capture.js +6 -11
- package/dist/compile/aot-capture.mjs +6 -11
- package/dist/compile/handler/frozen-validator.d.ts +7 -0
- package/dist/compile/handler/frozen-validator.js +36 -13
- package/dist/compile/handler/frozen-validator.mjs +37 -14
- package/dist/compile/handler/jit.js +2 -3
- package/dist/compile/handler/jit.mjs +3 -4
- package/dist/compile/handler/params.js +0 -1
- package/dist/compile/handler/params.mjs +1 -2
- package/dist/compile/handler/reconstruct.js +2 -1
- package/dist/compile/handler/reconstruct.mjs +2 -1
- package/dist/cookie/utils.d.ts +1 -2
- package/dist/cookie/utils.js +1 -10
- package/dist/cookie/utils.mjs +2 -10
- package/dist/generation.d.ts +2 -5
- package/dist/generation.js +0 -6
- package/dist/generation.mjs +1 -6
- package/dist/handler/fetch.js +4 -4
- package/dist/handler/fetch.mjs +4 -4
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/core.d.ts +19 -5
- package/dist/plugin/aot/core.js +13 -6
- package/dist/plugin/aot/core.mjs +13 -6
- package/dist/plugin/aot/source.js +141 -77
- package/dist/plugin/aot/source.mjs +141 -77
- package/dist/type/bridge-live.d.ts +2 -2
- package/dist/type/bridge-live.js +3 -2
- package/dist/type/bridge-live.mjs +3 -3
- package/dist/type/bridge.d.ts +4 -2
- package/dist/type/bridge.js +8 -0
- package/dist/type/bridge.mjs +3 -1
- package/dist/type/coerce-plan.d.ts +1 -4
- package/dist/type/coerce-plan.js +11 -17
- package/dist/type/coerce-plan.mjs +2 -8
- package/dist/type/coerce.d.ts +2 -2
- package/dist/type/coerce.js +14 -136
- package/dist/type/coerce.mjs +3 -125
- package/dist/type/compat.js +4 -3
- package/dist/type/compat.mjs +4 -3
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/elysia/array-string.js +4 -4
- package/dist/type/elysia/array-string.mjs +2 -2
- package/dist/type/elysia/boolean-string.js +1 -1
- package/dist/type/elysia/boolean-string.mjs +1 -1
- package/dist/type/elysia/date.js +1 -1
- package/dist/type/elysia/date.mjs +1 -1
- package/dist/type/elysia/file.js +1 -1
- package/dist/type/elysia/file.mjs +1 -1
- package/dist/type/elysia/files.js +1 -1
- package/dist/type/elysia/files.mjs +1 -1
- package/dist/type/elysia/integer-string.js +1 -1
- package/dist/type/elysia/integer-string.mjs +1 -1
- package/dist/type/elysia/maybe-empty.js +1 -1
- package/dist/type/elysia/maybe-empty.mjs +1 -1
- package/dist/type/elysia/nullable.js +1 -1
- package/dist/type/elysia/nullable.mjs +1 -1
- package/dist/type/elysia/numeric-enum.js +1 -1
- package/dist/type/elysia/numeric-enum.mjs +1 -1
- package/dist/type/elysia/numeric.js +1 -1
- package/dist/type/elysia/numeric.mjs +1 -1
- package/dist/type/elysia/object-string.js +4 -4
- package/dist/type/elysia/object-string.mjs +2 -2
- package/dist/type/elysia/string.js +2 -2
- package/dist/type/elysia/string.mjs +1 -1
- package/dist/type/elysia/utils.d.ts +2 -7
- package/dist/type/elysia/utils.js +4 -16
- package/dist/type/elysia/utils.mjs +2 -12
- package/dist/type/index.js +1 -1
- package/dist/type/index.mjs +1 -1
- package/dist/type/shared.d.ts +18 -0
- package/dist/type/shared.js +153 -0
- package/dist/type/shared.mjs +145 -0
- package/dist/type/validator/index.d.ts +2 -1
- package/dist/type/validator/index.js +64 -18
- package/dist/type/validator/index.mjs +65 -20
- package/dist/type/validator/validator-cache.js +1 -1
- package/dist/type/validator/validator-cache.mjs +1 -1
- package/dist/types.d.ts +0 -4
- package/dist/utils.d.ts +1 -1
- package/dist/utils.js +2 -2
- package/dist/utils.mjs +2 -2
- package/dist/validator/index.d.ts +1 -0
- package/dist/validator/index.js +5 -7
- package/dist/validator/index.mjs +2 -4
- package/dist/ws/route.js +2 -1
- package/dist/ws/route.mjs +2 -1
- package/package.json +3 -4
|
@@ -48,7 +48,7 @@ function mapResponseWithSet(response, set, request, owned) {
|
|
|
48
48
|
case "Promise": return response.then((x) => mapResponseWithSet(x, set, request, owned));
|
|
49
49
|
case "Function": return mapResponseWithSet(response(), set, request, owned);
|
|
50
50
|
case "FormData": return new Response(response, set);
|
|
51
|
-
default: return
|
|
51
|
+
default: return mapFallback(response, set, request, owned);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
function mapResponse(response, set, request, owned) {
|
|
@@ -87,7 +87,7 @@ function mapCompactResponse(response, request, owned) {
|
|
|
87
87
|
case "Promise": return response.then((x) => mapCompactResponse(x, request, owned));
|
|
88
88
|
case "Function": return mapCompactResponse(response(), request, owned);
|
|
89
89
|
case "FormData": return new Response(response);
|
|
90
|
-
default: return
|
|
90
|
+
default: return mapFallback(response, void 0, request, owned);
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
function errorToResponse(error, set, request, owned = false) {
|
|
@@ -110,32 +110,28 @@ function errorToResponse(error, set, request, owned = false) {
|
|
|
110
110
|
headers
|
|
111
111
|
});
|
|
112
112
|
}
|
|
113
|
-
function mapFallback(
|
|
114
|
-
return (response, set, request, owned
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return new Response(response, set);
|
|
135
|
-
};
|
|
113
|
+
function mapFallback(response, set, request, owned = false) {
|
|
114
|
+
if (response instanceof Response) return handleResponse(response, set, request, owned);
|
|
115
|
+
if (response instanceof Promise) return response.then((x) => set ? mapResponse(x, set, request, owned) : mapCompactResponse(x, request, owned));
|
|
116
|
+
if (response instanceof Error) return errorToResponse(response, set, request, owned);
|
|
117
|
+
if (response instanceof require_error.ElysiaStatus) if (set) {
|
|
118
|
+
set.status = response.code;
|
|
119
|
+
if (response.headers) set.headers = {
|
|
120
|
+
...set.headers,
|
|
121
|
+
...response.headers
|
|
122
|
+
};
|
|
123
|
+
return mapResponse(response.response, set, request, owned);
|
|
124
|
+
} else return mapResponse(response.response, {
|
|
125
|
+
status: response.code,
|
|
126
|
+
headers: response.headers ? { ...response.headers } : {}
|
|
127
|
+
}, request, owned);
|
|
128
|
+
if (typeof response?.next === "function" || response instanceof ReadableStream) return handleStream(response, set, request, void 0, owned);
|
|
129
|
+
if (typeof response?.then === "function") return response.then((x) => set ? mapResponse(x, set, request, owned) : mapCompactResponse(x, request, owned));
|
|
130
|
+
if (Array.isArray(response)) return Response.json(response);
|
|
131
|
+
if (typeof response?.toResponse === "function") return set ? mapResponse(response.toResponse(), set, request, owned) : mapCompactResponse(response.toResponse(), request, owned);
|
|
132
|
+
if (response?.constructor?.name === "Cookie" && response.jar) return new Response(response.value, set);
|
|
133
|
+
return new Response(response, set);
|
|
136
134
|
}
|
|
137
|
-
const mapResponseFallback = mapFallback(mapResponse);
|
|
138
|
-
const mapCompactResponseFallback = mapFallback((response, _, request, owned) => mapCompactResponse(response, request, owned));
|
|
139
135
|
const handleResponse = require_adapter_utils.createResponseHandler({
|
|
140
136
|
mapResponse,
|
|
141
137
|
mapCompactResponse
|
|
@@ -47,7 +47,7 @@ function mapResponseWithSet(response, set, request, owned) {
|
|
|
47
47
|
case "Promise": return response.then((x) => mapResponseWithSet(x, set, request, owned));
|
|
48
48
|
case "Function": return mapResponseWithSet(response(), set, request, owned);
|
|
49
49
|
case "FormData": return new Response(response, set);
|
|
50
|
-
default: return
|
|
50
|
+
default: return mapFallback(response, set, request, owned);
|
|
51
51
|
}
|
|
52
52
|
}
|
|
53
53
|
function mapResponse(response, set, request, owned) {
|
|
@@ -86,7 +86,7 @@ function mapCompactResponse(response, request, owned) {
|
|
|
86
86
|
case "Promise": return response.then((x) => mapCompactResponse(x, request, owned));
|
|
87
87
|
case "Function": return mapCompactResponse(response(), request, owned);
|
|
88
88
|
case "FormData": return new Response(response);
|
|
89
|
-
default: return
|
|
89
|
+
default: return mapFallback(response, void 0, request, owned);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
92
|
function errorToResponse(error, set, request, owned = false) {
|
|
@@ -109,32 +109,28 @@ function errorToResponse(error, set, request, owned = false) {
|
|
|
109
109
|
headers
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
|
-
function mapFallback(
|
|
113
|
-
return (response, set, request, owned
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return new Response(response, set);
|
|
134
|
-
};
|
|
112
|
+
function mapFallback(response, set, request, owned = false) {
|
|
113
|
+
if (response instanceof Response) return handleResponse(response, set, request, owned);
|
|
114
|
+
if (response instanceof Promise) return response.then((x) => set ? mapResponse(x, set, request, owned) : mapCompactResponse(x, request, owned));
|
|
115
|
+
if (response instanceof Error) return errorToResponse(response, set, request, owned);
|
|
116
|
+
if (response instanceof ElysiaStatus) if (set) {
|
|
117
|
+
set.status = response.code;
|
|
118
|
+
if (response.headers) set.headers = {
|
|
119
|
+
...set.headers,
|
|
120
|
+
...response.headers
|
|
121
|
+
};
|
|
122
|
+
return mapResponse(response.response, set, request, owned);
|
|
123
|
+
} else return mapResponse(response.response, {
|
|
124
|
+
status: response.code,
|
|
125
|
+
headers: response.headers ? { ...response.headers } : {}
|
|
126
|
+
}, request, owned);
|
|
127
|
+
if (typeof response?.next === "function" || response instanceof ReadableStream) return handleStream(response, set, request, void 0, owned);
|
|
128
|
+
if (typeof response?.then === "function") return response.then((x) => set ? mapResponse(x, set, request, owned) : mapCompactResponse(x, request, owned));
|
|
129
|
+
if (Array.isArray(response)) return Response.json(response);
|
|
130
|
+
if (typeof response?.toResponse === "function") return set ? mapResponse(response.toResponse(), set, request, owned) : mapCompactResponse(response.toResponse(), request, owned);
|
|
131
|
+
if (response?.constructor?.name === "Cookie" && response.jar) return new Response(response.value, set);
|
|
132
|
+
return new Response(response, set);
|
|
135
133
|
}
|
|
136
|
-
const mapResponseFallback = mapFallback(mapResponse);
|
|
137
|
-
const mapCompactResponseFallback = mapFallback((response, _, request, owned) => mapCompactResponse(response, request, owned));
|
|
138
134
|
const handleResponse = createResponseHandler({
|
|
139
135
|
mapResponse,
|
|
140
136
|
mapCompactResponse
|
package/dist/base.js
CHANGED
|
@@ -1331,10 +1331,9 @@ var Elysia = class Elysia {
|
|
|
1331
1331
|
}
|
|
1332
1332
|
}
|
|
1333
1333
|
#publishGeneration() {
|
|
1334
|
+
this["~aotFingerprint"] ??= require_compile_aot.createAotFingerprint();
|
|
1334
1335
|
this["~generation"] = {
|
|
1335
|
-
abi: this["~aotFingerprint"] ??= require_compile_aot.createAotFingerprint(),
|
|
1336
1336
|
routeTable: this["~routeTable"],
|
|
1337
|
-
introspect: this["~config"]?.introspect === true || this["~introspect"] === true,
|
|
1338
1337
|
"~config": this["~config"],
|
|
1339
1338
|
"~ext": this["~ext"],
|
|
1340
1339
|
"~hookChain": this["~hookChain"],
|
package/dist/base.mjs
CHANGED
|
@@ -1328,10 +1328,9 @@ var Elysia = class Elysia {
|
|
|
1328
1328
|
}
|
|
1329
1329
|
}
|
|
1330
1330
|
#publishGeneration() {
|
|
1331
|
+
this["~aotFingerprint"] ??= createAotFingerprint();
|
|
1331
1332
|
this["~generation"] = {
|
|
1332
|
-
abi: this["~aotFingerprint"] ??= createAotFingerprint(),
|
|
1333
1333
|
routeTable: this["~routeTable"],
|
|
1334
|
-
introspect: this["~config"]?.introspect === true || this["~introspect"] === true,
|
|
1335
1334
|
"~config": this["~config"],
|
|
1336
1335
|
"~ext": this["~ext"],
|
|
1337
1336
|
"~hookChain": this["~hookChain"],
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.js');
|
|
3
3
|
const require_utils = require('../utils.js');
|
|
4
|
+
const require_universal_env = require('../universal/env.js');
|
|
4
5
|
const require_compile_aot = require('./aot.js');
|
|
5
|
-
const require_type_coerce = require('../type/coerce.js');
|
|
6
6
|
const require_type_elysia_file_type = require('../type/elysia/file-type.js');
|
|
7
7
|
const require_compile_handler_frozen_validator = require('./handler/frozen-validator.js');
|
|
8
|
+
const require_type_coerce = require('../type/coerce.js');
|
|
8
9
|
const require_type_validator_default_precompute = require('../type/validator/default-precompute.js');
|
|
9
10
|
const require_compile_aot_reconstruct = require('./aot-reconstruct.js');
|
|
10
11
|
const require_compile_aot_emit = require('./aot-emit.js');
|
|
@@ -249,25 +250,19 @@ function captureCodecMirror(schema, aot, slot, sanitize, dir) {
|
|
|
249
250
|
} catch {}
|
|
250
251
|
}
|
|
251
252
|
const compactErrorWarned = /* @__PURE__ */ new Set();
|
|
252
|
-
const
|
|
253
|
-
let compactErrorSuppressed = 0;
|
|
253
|
+
const isVerboseAotWarnings = () => !!require_universal_env.env.ELYSIA_AOT_VERBOSE;
|
|
254
254
|
function resetCompactErrorWarnings() {
|
|
255
255
|
compactErrorWarned.clear();
|
|
256
|
-
compactErrorSuppressed = 0;
|
|
257
256
|
}
|
|
258
257
|
function warnCompactErrorLoss(aot, slot) {
|
|
259
258
|
const key = `${aot.method}\0${aot.path}\0${slot}`;
|
|
260
259
|
if (compactErrorWarned.has(key)) return;
|
|
261
|
-
if (compactErrorWarned.size >= 1024) {
|
|
262
|
-
const oldest = compactErrorWarned.keys().next().value;
|
|
263
|
-
if (oldest !== void 0) compactErrorWarned.delete(oldest);
|
|
264
|
-
}
|
|
265
260
|
compactErrorWarned.add(key);
|
|
266
|
-
if (
|
|
267
|
-
else compactErrorSuppressed++;
|
|
261
|
+
if (isVerboseAotWarnings()) console.warn(`[elysia-aot]: sealed validator for ${aot.method} ${aot.path} (${slot}) carries a coercion/codec schema; its 422 error detail will name the offending field coarsely (best-effort) instead.`);
|
|
268
262
|
}
|
|
269
263
|
function flushCompactErrorWarnings() {
|
|
270
|
-
|
|
264
|
+
const total = compactErrorWarned.size;
|
|
265
|
+
if (total > 0 && !isVerboseAotWarnings()) console.warn(`[elysia-aot]: ${total} sealed validator slot${total === 1 ? "" : "s"} ${total === 1 ? "carries" : "carry"} a coercion/codec schema; 422 error details will be coarse (best-effort). Set ELYSIA_AOT_VERBOSE=1 for per-route detail.`);
|
|
271
266
|
resetCompactErrorWarnings();
|
|
272
267
|
}
|
|
273
268
|
function captureBridgeFree(aot, slot, rawSchema) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { nullObject } from "../utils.mjs";
|
|
2
|
+
import { env } from "../universal/env.mjs";
|
|
2
3
|
import { Capture, CompilerState, aotActivationError, captureImpl, setCaptureImpl } from "./aot.mjs";
|
|
3
|
-
import { buildCoercedFromPlan, captureCoercePlan } from "../type/coerce.mjs";
|
|
4
4
|
import { isAsyncPredicate } from "../type/elysia/file-type.mjs";
|
|
5
5
|
import { isCapturedBridgeFree, isCompactDiagnosable } from "./handler/frozen-validator.mjs";
|
|
6
|
+
import { buildCoercedFromPlan, captureCoercePlan } from "../type/coerce.mjs";
|
|
6
7
|
import { applyPrecomputed, buildDefaultClonerSource, buildObjectDefaultMergeSource, canonical, createMergerFromSource, setDefaultProbeImpl, verifyPreallocatableDefault } from "../type/validator/default-precompute.mjs";
|
|
7
8
|
import { collectExternals } from "./aot-reconstruct.mjs";
|
|
8
9
|
import { captureMirrorCodecs, captureMirrorUnions, installReconstructImpl } from "./aot-emit.mjs";
|
|
@@ -246,25 +247,19 @@ function captureCodecMirror(schema, aot, slot, sanitize, dir) {
|
|
|
246
247
|
} catch {}
|
|
247
248
|
}
|
|
248
249
|
const compactErrorWarned = /* @__PURE__ */ new Set();
|
|
249
|
-
const
|
|
250
|
-
let compactErrorSuppressed = 0;
|
|
250
|
+
const isVerboseAotWarnings = () => !!env.ELYSIA_AOT_VERBOSE;
|
|
251
251
|
function resetCompactErrorWarnings() {
|
|
252
252
|
compactErrorWarned.clear();
|
|
253
|
-
compactErrorSuppressed = 0;
|
|
254
253
|
}
|
|
255
254
|
function warnCompactErrorLoss(aot, slot) {
|
|
256
255
|
const key = `${aot.method}\0${aot.path}\0${slot}`;
|
|
257
256
|
if (compactErrorWarned.has(key)) return;
|
|
258
|
-
if (compactErrorWarned.size >= 1024) {
|
|
259
|
-
const oldest = compactErrorWarned.keys().next().value;
|
|
260
|
-
if (oldest !== void 0) compactErrorWarned.delete(oldest);
|
|
261
|
-
}
|
|
262
257
|
compactErrorWarned.add(key);
|
|
263
|
-
if (
|
|
264
|
-
else compactErrorSuppressed++;
|
|
258
|
+
if (isVerboseAotWarnings()) console.warn(`[elysia-aot]: sealed validator for ${aot.method} ${aot.path} (${slot}) carries a coercion/codec schema; its 422 error detail will name the offending field coarsely (best-effort) instead.`);
|
|
265
259
|
}
|
|
266
260
|
function flushCompactErrorWarnings() {
|
|
267
|
-
|
|
261
|
+
const total = compactErrorWarned.size;
|
|
262
|
+
if (total > 0 && !isVerboseAotWarnings()) console.warn(`[elysia-aot]: ${total} sealed validator slot${total === 1 ? "" : "s"} ${total === 1 ? "carries" : "carry"} a coercion/codec schema; 422 error details will be coarse (best-effort). Set ELYSIA_AOT_VERBOSE=1 for per-route detail.`);
|
|
268
263
|
resetCompactErrorWarnings();
|
|
269
264
|
}
|
|
270
265
|
function captureBridgeFree(aot, slot, rawSchema) {
|
|
@@ -4,6 +4,12 @@ import { AnyElysia } from "../../base.js";
|
|
|
4
4
|
|
|
5
5
|
//#region src/compile/handler/frozen-validator.d.ts
|
|
6
6
|
declare const isBridgeNotInitialized: (error: unknown) => boolean;
|
|
7
|
+
/** `{ check, clean?, decode? }` — the slot's compiled predicate + cleaner. */
|
|
8
|
+
interface SlotCheckClean {
|
|
9
|
+
check: (value: unknown) => boolean;
|
|
10
|
+
clean?: (value: unknown) => unknown;
|
|
11
|
+
decode?: (value: unknown) => unknown;
|
|
12
|
+
}
|
|
7
13
|
declare function isCompactDiagnosable(schema: any): boolean;
|
|
8
14
|
declare class FrozenSlotValidator {
|
|
9
15
|
#private;
|
|
@@ -11,6 +17,7 @@ declare class FrozenSlotValidator {
|
|
|
11
17
|
hasCodec: boolean;
|
|
12
18
|
schema: unknown;
|
|
13
19
|
constructor(frozen: FrozenValidator, schema: unknown, raw: unknown, normalize: boolean | 'exactMirror' | 'typebox' | undefined);
|
|
20
|
+
protected buildCheckClean(frozen: FrozenValidator, schema: unknown, raw: unknown, normalize: boolean | 'exactMirror' | 'typebox' | undefined): SlotCheckClean;
|
|
14
21
|
Check(value: unknown): boolean;
|
|
15
22
|
Errors(value: unknown): unknown[];
|
|
16
23
|
From(value: unknown, type?: string): unknown;
|
|
@@ -28,6 +28,7 @@ function isBridgeFreeComplete(f, schema, raw) {
|
|
|
28
28
|
if (require_type_validator_clean_safe.isFullyClosedObject(schema)) return false;
|
|
29
29
|
return true;
|
|
30
30
|
}
|
|
31
|
+
const EMPTY_EXTERNALS = Object.freeze([]);
|
|
31
32
|
function jsTypeMatches(value, type) {
|
|
32
33
|
switch (type) {
|
|
33
34
|
case "string": return typeof value === "string";
|
|
@@ -132,18 +133,11 @@ var FrozenSlotValidator = class {
|
|
|
132
133
|
this.isAsync = false;
|
|
133
134
|
this.hasCodec = false;
|
|
134
135
|
this.schema = schema;
|
|
135
|
-
if (frozen.ic) require_compile_aot.reconstruct().reconstructInnerCodecs(frozen.ic, schema);
|
|
136
136
|
this.hasCodec = frozen.k === 1;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
this.#decode = normalize === false ? void 0 : require_compile_aot.reconstruct().instantiateFrozenDecodeMirror(frozen.dm, schema);
|
|
142
|
-
} else {
|
|
143
|
-
const both = frozen.cm(require_compile_aot.EMPTY_EXTERNALS, void 0);
|
|
144
|
-
this.#check = both.check;
|
|
145
|
-
this.#clean = normalize === false ? void 0 : both.clean;
|
|
146
|
-
}
|
|
137
|
+
const built = this.buildCheckClean(frozen, schema, raw, normalize);
|
|
138
|
+
this.#check = built.check;
|
|
139
|
+
this.#clean = built.clean;
|
|
140
|
+
this.#decode = built.decode;
|
|
147
141
|
this.#hasOptional = !!schema?.["~optional"];
|
|
148
142
|
this.#noValidate = schema?.["~elyTyp"] === require_type_constants.ELYSIA_TYPES.NoValidate;
|
|
149
143
|
this.#hasDefault = frozen.d === 1;
|
|
@@ -154,6 +148,13 @@ var FrozenSlotValidator = class {
|
|
|
154
148
|
merge: frozen.pm
|
|
155
149
|
};
|
|
156
150
|
}
|
|
151
|
+
buildCheckClean(frozen, schema, raw, normalize) {
|
|
152
|
+
const both = frozen.cm(EMPTY_EXTERNALS, void 0);
|
|
153
|
+
return {
|
|
154
|
+
check: both.check,
|
|
155
|
+
clean: normalize === false ? void 0 : both.clean
|
|
156
|
+
};
|
|
157
|
+
}
|
|
157
158
|
Check(value) {
|
|
158
159
|
return this.#check(value);
|
|
159
160
|
}
|
|
@@ -196,6 +197,28 @@ var FrozenSlotValidator = class {
|
|
|
196
197
|
return this.#clean ? this.#clean(value) : value;
|
|
197
198
|
}
|
|
198
199
|
};
|
|
200
|
+
/**
|
|
201
|
+
* The JIT/frozen slot validator: the reconstruct-free `FrozenSlotValidator`
|
|
202
|
+
* base plus the codec/inner-codec branch re-added via the `buildCheckClean`
|
|
203
|
+
* override.
|
|
204
|
+
* The only reorder — `this.hasCodec` is set by the base ctor before this runs,
|
|
205
|
+
* where the original set it after the `frozen.ic` side-effect — is unobservable
|
|
206
|
+
* (`reconstructInnerCodecs` neither reads nor sets `hasCodec`).
|
|
207
|
+
*/
|
|
208
|
+
var CodecFrozenSlotValidator = class extends FrozenSlotValidator {
|
|
209
|
+
buildCheckClean(frozen, schema, raw, normalize) {
|
|
210
|
+
if (frozen.ic) require_compile_aot.reconstruct().reconstructInnerCodecs(frozen.ic, schema);
|
|
211
|
+
if (frozen.k === 1 && frozen.dm) {
|
|
212
|
+
const both = require_compile_aot.reconstruct().instantiateFrozenBoth(frozen, schema, raw);
|
|
213
|
+
return {
|
|
214
|
+
check: both.check,
|
|
215
|
+
clean: normalize === false ? void 0 : both.clean,
|
|
216
|
+
decode: normalize === false ? void 0 : require_compile_aot.reconstruct().instantiateFrozenDecodeMirror(frozen.dm, schema)
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
return super.buildCheckClean(frozen, schema, raw, normalize);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
199
222
|
const REQUEST_SLOTS = [
|
|
200
223
|
"body",
|
|
201
224
|
"headers",
|
|
@@ -241,7 +264,7 @@ function buildFrozenRouteValidator(hook, root, method, path) {
|
|
|
241
264
|
coerced = rebuild(schema, frozen.cp);
|
|
242
265
|
}
|
|
243
266
|
if (!isBridgeFreeComplete(frozen, coerced, schema)) return void 0;
|
|
244
|
-
out[slot] = new
|
|
267
|
+
out[slot] = new CodecFrozenSlotValidator(frozen, coerced, schema, normalize);
|
|
245
268
|
}
|
|
246
269
|
const response = hook?.response;
|
|
247
270
|
if (response) {
|
|
@@ -258,7 +281,7 @@ function buildFrozenRouteValidator(hook, root, method, path) {
|
|
|
258
281
|
}
|
|
259
282
|
const frozen = require_compile_aot.Compiled.getValidator(method, path, `response:${status}`, root["~programId"]);
|
|
260
283
|
if (!frozen || !isBridgeFreeComplete(frozen, schema, schema)) return void 0;
|
|
261
|
-
responseOut[status] = new
|
|
284
|
+
responseOut[status] = new CodecFrozenSlotValidator(frozen, schema, schema, normalize);
|
|
262
285
|
}
|
|
263
286
|
out.response = responseOut;
|
|
264
287
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { nullObject } from "../../utils.mjs";
|
|
2
2
|
import { ELYSIA_TYPES } from "../../type/constants.mjs";
|
|
3
3
|
import { ValidationError } from "../../error.mjs";
|
|
4
|
-
import { Compiled,
|
|
4
|
+
import { Compiled, reconstruct } from "../aot.mjs";
|
|
5
5
|
import { frozenRootOf } from "../../generation.mjs";
|
|
6
6
|
import { isFullyClosedObject } from "../../type/validator/clean-safe.mjs";
|
|
7
7
|
import { StandardValidator } from "../../validator/index.mjs";
|
|
@@ -27,6 +27,7 @@ function isBridgeFreeComplete(f, schema, raw) {
|
|
|
27
27
|
if (isFullyClosedObject(schema)) return false;
|
|
28
28
|
return true;
|
|
29
29
|
}
|
|
30
|
+
const EMPTY_EXTERNALS = Object.freeze([]);
|
|
30
31
|
function jsTypeMatches(value, type) {
|
|
31
32
|
switch (type) {
|
|
32
33
|
case "string": return typeof value === "string";
|
|
@@ -131,18 +132,11 @@ var FrozenSlotValidator = class {
|
|
|
131
132
|
this.isAsync = false;
|
|
132
133
|
this.hasCodec = false;
|
|
133
134
|
this.schema = schema;
|
|
134
|
-
if (frozen.ic) reconstruct().reconstructInnerCodecs(frozen.ic, schema);
|
|
135
135
|
this.hasCodec = frozen.k === 1;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
this.#decode = normalize === false ? void 0 : reconstruct().instantiateFrozenDecodeMirror(frozen.dm, schema);
|
|
141
|
-
} else {
|
|
142
|
-
const both = frozen.cm(EMPTY_EXTERNALS, void 0);
|
|
143
|
-
this.#check = both.check;
|
|
144
|
-
this.#clean = normalize === false ? void 0 : both.clean;
|
|
145
|
-
}
|
|
136
|
+
const built = this.buildCheckClean(frozen, schema, raw, normalize);
|
|
137
|
+
this.#check = built.check;
|
|
138
|
+
this.#clean = built.clean;
|
|
139
|
+
this.#decode = built.decode;
|
|
146
140
|
this.#hasOptional = !!schema?.["~optional"];
|
|
147
141
|
this.#noValidate = schema?.["~elyTyp"] === ELYSIA_TYPES.NoValidate;
|
|
148
142
|
this.#hasDefault = frozen.d === 1;
|
|
@@ -153,6 +147,13 @@ var FrozenSlotValidator = class {
|
|
|
153
147
|
merge: frozen.pm
|
|
154
148
|
};
|
|
155
149
|
}
|
|
150
|
+
buildCheckClean(frozen, schema, raw, normalize) {
|
|
151
|
+
const both = frozen.cm(EMPTY_EXTERNALS, void 0);
|
|
152
|
+
return {
|
|
153
|
+
check: both.check,
|
|
154
|
+
clean: normalize === false ? void 0 : both.clean
|
|
155
|
+
};
|
|
156
|
+
}
|
|
156
157
|
Check(value) {
|
|
157
158
|
return this.#check(value);
|
|
158
159
|
}
|
|
@@ -195,6 +196,28 @@ var FrozenSlotValidator = class {
|
|
|
195
196
|
return this.#clean ? this.#clean(value) : value;
|
|
196
197
|
}
|
|
197
198
|
};
|
|
199
|
+
/**
|
|
200
|
+
* The JIT/frozen slot validator: the reconstruct-free `FrozenSlotValidator`
|
|
201
|
+
* base plus the codec/inner-codec branch re-added via the `buildCheckClean`
|
|
202
|
+
* override.
|
|
203
|
+
* The only reorder — `this.hasCodec` is set by the base ctor before this runs,
|
|
204
|
+
* where the original set it after the `frozen.ic` side-effect — is unobservable
|
|
205
|
+
* (`reconstructInnerCodecs` neither reads nor sets `hasCodec`).
|
|
206
|
+
*/
|
|
207
|
+
var CodecFrozenSlotValidator = class extends FrozenSlotValidator {
|
|
208
|
+
buildCheckClean(frozen, schema, raw, normalize) {
|
|
209
|
+
if (frozen.ic) reconstruct().reconstructInnerCodecs(frozen.ic, schema);
|
|
210
|
+
if (frozen.k === 1 && frozen.dm) {
|
|
211
|
+
const both = reconstruct().instantiateFrozenBoth(frozen, schema, raw);
|
|
212
|
+
return {
|
|
213
|
+
check: both.check,
|
|
214
|
+
clean: normalize === false ? void 0 : both.clean,
|
|
215
|
+
decode: normalize === false ? void 0 : reconstruct().instantiateFrozenDecodeMirror(frozen.dm, schema)
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
return super.buildCheckClean(frozen, schema, raw, normalize);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
198
221
|
const REQUEST_SLOTS = [
|
|
199
222
|
"body",
|
|
200
223
|
"headers",
|
|
@@ -240,7 +263,7 @@ function buildFrozenRouteValidator(hook, root, method, path) {
|
|
|
240
263
|
coerced = rebuild(schema, frozen.cp);
|
|
241
264
|
}
|
|
242
265
|
if (!isBridgeFreeComplete(frozen, coerced, schema)) return void 0;
|
|
243
|
-
out[slot] = new
|
|
266
|
+
out[slot] = new CodecFrozenSlotValidator(frozen, coerced, schema, normalize);
|
|
244
267
|
}
|
|
245
268
|
const response = hook?.response;
|
|
246
269
|
if (response) {
|
|
@@ -257,7 +280,7 @@ function buildFrozenRouteValidator(hook, root, method, path) {
|
|
|
257
280
|
}
|
|
258
281
|
const frozen = Compiled.getValidator(method, path, `response:${status}`, root["~programId"]);
|
|
259
282
|
if (!frozen || !isBridgeFreeComplete(frozen, schema, schema)) return void 0;
|
|
260
|
-
responseOut[status] = new
|
|
283
|
+
responseOut[status] = new CodecFrozenSlotValidator(frozen, schema, schema, normalize);
|
|
261
284
|
}
|
|
262
285
|
out.response = responseOut;
|
|
263
286
|
}
|
|
@@ -354,9 +354,8 @@ function compileHandlerJit({ method, path, handler, root, errorRoot, hook, adapt
|
|
|
354
354
|
const dedupSchedule = !!scheduleAfterResponse && (hasErrorHook || hasTrace) && !syncAfterResponse && !syncErrorHook;
|
|
355
355
|
const scheduleDecl = dedupSchedule ? `function _sc(){\n${scheduleAfterResponse}}\n` : "";
|
|
356
356
|
const schedule = dedupSchedule ? `_sc()\n` : scheduleAfterResponse;
|
|
357
|
-
const signPrefix = syncCookieSign ? `
|
|
358
|
-
if (syncCookieSign) link(require_cookie_utils.
|
|
359
|
-
else if (asyncCookieSign) link(require_cookie_utils.signCookieValues, "scv");
|
|
357
|
+
const signPrefix = syncCookieSign ? `scv(c.set.cookie,cc)\n` : asyncCookieSign ? `_sg=scv(c.set.cookie,cc)\nif(_sg)await _sg\n` : "";
|
|
358
|
+
if (syncCookieSign || asyncCookieSign) link(require_cookie_utils.signCookieValues, "scv");
|
|
360
359
|
let factoryHelpers = "";
|
|
361
360
|
if (hasBeforeHandle || hasAfterHandle || hasMapResponse || hasAfterResponse || hasResponseValidator || hasCookieSign || hasTrace) {
|
|
362
361
|
code += `let _r,tmp\n`;
|
|
@@ -8,7 +8,7 @@ import { materializeSetHeaders, normalizeContentType, tee } from "../../adapter/
|
|
|
8
8
|
import { parseQueryFromURL } from "../../parse-query.mjs";
|
|
9
9
|
import { Capture } from "../aot.mjs";
|
|
10
10
|
import { resolvedTraceOf, traceCapabilityRequired } from "../../generation.mjs";
|
|
11
|
-
import { buildCookieJar, parseCookieRaw, parseCookieRawDeferred, parseCookieRawLazy, parseCookieRawSigned, parseCookieRawSync, signCookieValues
|
|
11
|
+
import { buildCookieJar, parseCookieRaw, parseCookieRawDeferred, parseCookieRawLazy, parseCookieRawSigned, parseCookieRawSync, signCookieValues } from "../../cookie/utils.mjs";
|
|
12
12
|
import { isAsyncFunction } from "../utils.mjs";
|
|
13
13
|
import { emptyResponse, finalizeRouteError, forwardError } from "../../handler/utils.mjs";
|
|
14
14
|
import { cloneResponse, getQueryParseChannels, hasRequestBody, mapAfterHandle, mapAfterResponse, mapBeforeHandle, mapError, mapMapResponse, mapTransform, runBeforeHandlePrefix, runBeforeHandlePrefixAsync } from "./utils.mjs";
|
|
@@ -353,9 +353,8 @@ function compileHandlerJit({ method, path, handler, root, errorRoot, hook, adapt
|
|
|
353
353
|
const dedupSchedule = !!scheduleAfterResponse && (hasErrorHook || hasTrace) && !syncAfterResponse && !syncErrorHook;
|
|
354
354
|
const scheduleDecl = dedupSchedule ? `function _sc(){\n${scheduleAfterResponse}}\n` : "";
|
|
355
355
|
const schedule = dedupSchedule ? `_sc()\n` : scheduleAfterResponse;
|
|
356
|
-
const signPrefix = syncCookieSign ? `
|
|
357
|
-
if (syncCookieSign) link(
|
|
358
|
-
else if (asyncCookieSign) link(signCookieValues, "scv");
|
|
356
|
+
const signPrefix = syncCookieSign ? `scv(c.set.cookie,cc)\n` : asyncCookieSign ? `_sg=scv(c.set.cookie,cc)\nif(_sg)await _sg\n` : "";
|
|
357
|
+
if (syncCookieSign || asyncCookieSign) link(signCookieValues, "scv");
|
|
359
358
|
let factoryHelpers = "";
|
|
360
359
|
if (hasBeforeHandle || hasAfterHandle || hasMapResponse || hasAfterResponse || hasResponseValidator || hasCookieSign || hasTrace) {
|
|
361
360
|
code += `let _r,tmp\n`;
|
|
@@ -42,7 +42,6 @@ const HANDLER_PARAMS = {
|
|
|
42
42
|
pcrd: () => require_cookie_utils.parseCookieRawDeferred,
|
|
43
43
|
bcj: () => require_cookie_utils.buildCookieJar,
|
|
44
44
|
scv: () => require_cookie_utils.signCookieValues,
|
|
45
|
-
scvs: () => require_cookie_utils.signCookieValuesSync,
|
|
46
45
|
va: (c) => c.vali,
|
|
47
46
|
fe: () => require_handler_utils.forwardError,
|
|
48
47
|
fre: () => require_handler_utils.finalizeRouteError,
|
|
@@ -3,7 +3,7 @@ import { isProduction } from "../../universal/is-production.mjs";
|
|
|
3
3
|
import { ElysiaStatus, ParseError, ValidationError, internalServerErrorResponse } from "../../error.mjs";
|
|
4
4
|
import { materializeSetHeaders, normalizeContentType, tee } from "../../adapter/utils.mjs";
|
|
5
5
|
import { parseQueryFromURL } from "../../parse-query.mjs";
|
|
6
|
-
import { buildCookieJar, parseCookieRaw, parseCookieRawDeferred, parseCookieRawLazy, parseCookieRawSigned, parseCookieRawSync, signCookieValues
|
|
6
|
+
import { buildCookieJar, parseCookieRaw, parseCookieRawDeferred, parseCookieRawLazy, parseCookieRawSigned, parseCookieRawSync, signCookieValues } from "../../cookie/utils.mjs";
|
|
7
7
|
import { emptyResponse, finalizeRouteError, forwardError } from "../../handler/utils.mjs";
|
|
8
8
|
import { cloneResponse, getQueryParseChannels, hasRequestBody, replaceDeriveContext, runBeforeHandlePrefix } from "./utils.mjs";
|
|
9
9
|
|
|
@@ -41,7 +41,6 @@ const HANDLER_PARAMS = {
|
|
|
41
41
|
pcrd: () => parseCookieRawDeferred,
|
|
42
42
|
bcj: () => buildCookieJar,
|
|
43
43
|
scv: () => signCookieValues,
|
|
44
|
-
scvs: () => signCookieValuesSync,
|
|
45
44
|
va: (c) => c.vali,
|
|
46
45
|
fe: () => forwardError,
|
|
47
46
|
fre: () => finalizeRouteError,
|
package/dist/cookie/utils.d.ts
CHANGED
|
@@ -21,6 +21,5 @@ declare function parseCookieRaw(cookieString: string | null | undefined, config:
|
|
|
21
21
|
declare function parseCookieRawSigned(cookieString: string | null | undefined, config: CompiledCookieConfig): Record<string, unknown>;
|
|
22
22
|
declare function buildCookieJar(set: Context['set'], raw: Record<string, unknown>, config: CompiledCookieConfig, lazySign?: 1, deferDecode?: 1): Record<string, Cookie<unknown>>;
|
|
23
23
|
declare function signCookieValues(cookies: Context['set']['cookie'] | undefined, config: CompiledCookieConfig): Promise<void> | undefined;
|
|
24
|
-
declare function signCookieValuesSync(cookies: Context['set']['cookie'] | undefined, config: CompiledCookieConfig): void;
|
|
25
24
|
//#endregion
|
|
26
|
-
export { buildCookieJar, hasSyncHmac, parseCookie, parseCookieRaw, parseCookieRawDeferred, parseCookieRawLazy, parseCookieRawSigned, parseCookieRawSync, signCookieValues
|
|
25
|
+
export { buildCookieJar, hasSyncHmac, parseCookie, parseCookieRaw, parseCookieRawDeferred, parseCookieRawLazy, parseCookieRawSigned, parseCookieRawSync, signCookieValues };
|
package/dist/cookie/utils.js
CHANGED
|
@@ -162,14 +162,6 @@ function signCookieValues(cookies, config) {
|
|
|
162
162
|
}
|
|
163
163
|
return signPending(pending);
|
|
164
164
|
}
|
|
165
|
-
function signCookieValuesSync(cookies, config) {
|
|
166
|
-
const pending = collectSignPending(cookies, config);
|
|
167
|
-
if (!pending) return;
|
|
168
|
-
for (let i = 0; i < pending.length; i++) {
|
|
169
|
-
const [property, value, secret] = pending[i];
|
|
170
|
-
property.value = require_cookie_crypto.signCookieSync(value, secret);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
165
|
async function signPending(pending) {
|
|
174
166
|
for (let i = 0; i < pending.length; i++) {
|
|
175
167
|
const [property, value, secret] = pending[i];
|
|
@@ -186,5 +178,4 @@ exports.parseCookieRawDeferred = parseCookieRawDeferred;
|
|
|
186
178
|
exports.parseCookieRawLazy = parseCookieRawLazy;
|
|
187
179
|
exports.parseCookieRawSigned = parseCookieRawSigned;
|
|
188
180
|
exports.parseCookieRawSync = parseCookieRawSync;
|
|
189
|
-
exports.signCookieValues = signCookieValues;
|
|
190
|
-
exports.signCookieValuesSync = signCookieValuesSync;
|
|
181
|
+
exports.signCookieValues = signCookieValues;
|
package/dist/cookie/utils.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { dangerousKeys } from "../constants.mjs";
|
|
2
2
|
import { nullObject } from "../utils.mjs";
|
|
3
3
|
import { parse } from "./lib.mjs";
|
|
4
|
-
import { hasSyncHmac, maybeJsonDecode, rawJsonValue, resolvePendingCookie, signCookie,
|
|
4
|
+
import { hasSyncHmac, maybeJsonDecode, rawJsonValue, resolvePendingCookie, signCookie, signCookieSyncImpl, unsignWithSecrets, unsignWithSecretsSync } from "./crypto.mjs";
|
|
5
5
|
import { Cookie } from "./cookie.mjs";
|
|
6
6
|
import { compileCookieConfig, isCookieSigned, resolveSignSecrets } from "./config.mjs";
|
|
7
7
|
import { decodeComponent } from "deuri";
|
|
@@ -160,14 +160,6 @@ function signCookieValues(cookies, config) {
|
|
|
160
160
|
}
|
|
161
161
|
return signPending(pending);
|
|
162
162
|
}
|
|
163
|
-
function signCookieValuesSync(cookies, config) {
|
|
164
|
-
const pending = collectSignPending(cookies, config);
|
|
165
|
-
if (!pending) return;
|
|
166
|
-
for (let i = 0; i < pending.length; i++) {
|
|
167
|
-
const [property, value, secret] = pending[i];
|
|
168
|
-
property.value = signCookieSync(value, secret);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
163
|
async function signPending(pending) {
|
|
172
164
|
for (let i = 0; i < pending.length; i++) {
|
|
173
165
|
const [property, value, secret] = pending[i];
|
|
@@ -176,4 +168,4 @@ async function signPending(pending) {
|
|
|
176
168
|
}
|
|
177
169
|
|
|
178
170
|
//#endregion
|
|
179
|
-
export { buildCookieJar, hasSyncHmac, parseCookie, parseCookieRaw, parseCookieRawDeferred, parseCookieRawLazy, parseCookieRawSigned, parseCookieRawSync, signCookieValues
|
|
171
|
+
export { buildCookieJar, hasSyncHmac, parseCookie, parseCookieRaw, parseCookieRawDeferred, parseCookieRawLazy, parseCookieRawSigned, parseCookieRawSync, signCookieValues };
|