elysia 2.0.0-exp.43 → 2.0.0-exp.45
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/base.d.ts +1 -1
- package/dist/base.js +22 -21
- package/dist/base.mjs +22 -21
- package/dist/compile/aot.js +5 -1
- package/dist/compile/aot.mjs +5 -1
- package/dist/compile/handler/index.js +7 -5
- package/dist/compile/handler/index.mjs +7 -5
- package/dist/compile/handler/jit.js +18 -33
- package/dist/compile/handler/jit.mjs +18 -33
- package/dist/compile/lexer.d.ts +1 -1
- package/dist/handler/fetch.js +26 -17
- package/dist/handler/fetch.mjs +26 -17
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/type/bridge-live.d.ts +1 -1
- package/dist/type/bridge.d.ts +6 -6
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/validator/index.d.ts +1 -1
- package/dist/type/validator/index.js +71 -17
- package/dist/type/validator/index.mjs +71 -17
- package/dist/types.d.ts +1 -1
- package/dist/utils.d.ts +0 -1
- package/dist/validator/index.js +10 -6
- package/dist/validator/index.mjs +10 -6
- package/package.json +1 -1
package/dist/base.d.ts
CHANGED
|
@@ -849,7 +849,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
849
849
|
* on the config and triggers a fresh build of the fetch handler).
|
|
850
850
|
*/
|
|
851
851
|
compile(): this;
|
|
852
|
-
handler(index: number, immediate?: boolean | undefined, route?: InternalRoute, precomputedStatic?: Response, aliases?: StaticMapAliases): CompiledHandler;
|
|
852
|
+
handler(index: number, immediate?: boolean | undefined, route?: InternalRoute, precomputedStatic?: Response, aliases?: StaticMapAliases, table?: RouteTable): CompiledHandler;
|
|
853
853
|
['~newGeneration'](): this;
|
|
854
854
|
get fetch(): (request: Request, ...rest: any[]) => MaybePromise<Response>;
|
|
855
855
|
get handle(): (url: string | Request, options?: RequestInit) => Promise<Response>;
|
package/dist/base.js
CHANGED
|
@@ -1119,30 +1119,32 @@ var Elysia = class Elysia {
|
|
|
1119
1119
|
this.fetch;
|
|
1120
1120
|
return this;
|
|
1121
1121
|
}
|
|
1122
|
-
handler(index, immediate = this["~config"]?.precompile, route
|
|
1122
|
+
handler(index, immediate = this["~config"]?.precompile, route, precomputedStatic, aliases, table) {
|
|
1123
1123
|
if (this.#compiled?.[index]) return this.#compiled[index];
|
|
1124
1124
|
const compiled = this.#compiled ??= new Array(this["~routes"].length);
|
|
1125
1125
|
if (immediate) {
|
|
1126
|
+
const row = route ?? this["~routes"][index];
|
|
1126
1127
|
let handler;
|
|
1127
1128
|
try {
|
|
1128
|
-
handler = require_compile_handler_index.compileHandler(
|
|
1129
|
+
handler = require_compile_handler_index.compileHandler(row, this, precomputedStatic);
|
|
1129
1130
|
} catch (error) {
|
|
1130
|
-
throw new Error(`[Elysia] Failed to compile route ${
|
|
1131
|
+
throw new Error(`[Elysia] Failed to compile route ${row[0]} ${row[1]}: ${error?.message ?? error}`, { cause: error });
|
|
1131
1132
|
}
|
|
1132
1133
|
compiled[index] = handler;
|
|
1133
|
-
this.#saveHandler(
|
|
1134
|
+
this.#saveHandler(row[0], row[1], handler);
|
|
1134
1135
|
return handler;
|
|
1135
1136
|
}
|
|
1136
|
-
return this.#jitHandler(index, route, precomputedStatic, aliases);
|
|
1137
|
+
return this.#jitHandler(index, route ?? (table ? void 0 : this["~routes"][index]), precomputedStatic, aliases, table);
|
|
1137
1138
|
}
|
|
1138
|
-
#jitHandler(index, route, precomputedStatic, aliases) {
|
|
1139
|
+
#jitHandler(index, route, precomputedStatic, aliases, table) {
|
|
1139
1140
|
return (context) => {
|
|
1140
1141
|
if (this.#compiled[index]) return this.#compiled[index](context);
|
|
1142
|
+
const materialized = route ?? require_route_table.routeRow(table, index);
|
|
1141
1143
|
let handler;
|
|
1142
1144
|
try {
|
|
1143
|
-
handler = require_compile_handler_index.compileHandler(
|
|
1145
|
+
handler = require_compile_handler_index.compileHandler(materialized, this, precomputedStatic);
|
|
1144
1146
|
} catch (error) {
|
|
1145
|
-
const routeError = new Error(`[Elysia] Failed to compile route ${
|
|
1147
|
+
const routeError = new Error(`[Elysia] Failed to compile route ${materialized[0]} ${materialized[1]}: ${error?.message ?? error}`, { cause: error });
|
|
1146
1148
|
const finalize = this["~finalizeError"];
|
|
1147
1149
|
if (finalize) return finalize(context, routeError);
|
|
1148
1150
|
throw routeError;
|
|
@@ -1152,7 +1154,7 @@ var Elysia = class Elysia {
|
|
|
1152
1154
|
this.#initMap();
|
|
1153
1155
|
const map = this["~map"][aliases.method] ??= require_utils.nullObject();
|
|
1154
1156
|
for (let p = 0; p < aliases.paths.length; p++) map[aliases.paths[p]] = handler;
|
|
1155
|
-
} else this.#saveHandler(
|
|
1157
|
+
} else this.#saveHandler(materialized[0], materialized[1], handler);
|
|
1156
1158
|
return handler(context);
|
|
1157
1159
|
};
|
|
1158
1160
|
}
|
|
@@ -1221,11 +1223,13 @@ var Elysia = class Elysia {
|
|
|
1221
1223
|
}
|
|
1222
1224
|
return memo.get(start);
|
|
1223
1225
|
}
|
|
1224
|
-
#routeMayHaveModelRef(
|
|
1226
|
+
#routeMayHaveModelRef(table, i) {
|
|
1225
1227
|
if (this["~ext"]?.macro || this["~scopeChildren"]) return true;
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1228
|
+
const macroScope = table.macroScope.get(i);
|
|
1229
|
+
const owner = table.owner[i];
|
|
1230
|
+
if (require_compile_handler_index.localMacroRoot(macroScope ?? owner ?? this, this)["~ext"]?.macro) return true;
|
|
1231
|
+
if (Elysia.#hookHasString(table.localHook[i])) return true;
|
|
1232
|
+
return this.#chainHasModelRef(table.appHook[i]) || this.#chainHasModelRef(table.inheritedChain[i]) || this.#chainHasModelRef(this["~hookChain"]);
|
|
1229
1233
|
}
|
|
1230
1234
|
#assertRouteModelRefs(route, method) {
|
|
1231
1235
|
const models = this["~ext"]?.models;
|
|
@@ -1335,10 +1339,7 @@ var Elysia = class Elysia {
|
|
|
1335
1339
|
const path = table.path;
|
|
1336
1340
|
const flags = table.flags;
|
|
1337
1341
|
const length = table.length;
|
|
1338
|
-
for (let i = 0; i < length; i++)
|
|
1339
|
-
const row = require_route_table.routeRow(table, i);
|
|
1340
|
-
if (this.#routeMayHaveModelRef(row)) this.#assertRouteModelRefs(row, method[i]);
|
|
1341
|
-
}
|
|
1342
|
+
for (let i = 0; i < length; i++) if (this.#routeMayHaveModelRef(table, i)) this.#assertRouteModelRefs(require_route_table.routeRow(table, i), method[i]);
|
|
1342
1343
|
if (length) require_compile_aot.Compiled.claim(this["~programId"], this["~aotFingerprint"] = require_compile_aot.createAotFingerprint());
|
|
1343
1344
|
const isLoose = this["~config"]?.strictPath !== true;
|
|
1344
1345
|
let hasLooseCandidate = false;
|
|
@@ -1401,7 +1402,7 @@ var Elysia = class Elysia {
|
|
|
1401
1402
|
const explicitMain = registerLoose ? explicitPaths?.get(routeMethod) : void 0;
|
|
1402
1403
|
if (!isDynamic && !needsEncode && !registerLoose) {
|
|
1403
1404
|
const map = methods[routeMethod] ??= require_utils.nullObject();
|
|
1404
|
-
map[routePath] = this.handler(i, precompile,
|
|
1405
|
+
map[routePath] = this.handler(i, precompile, void 0, void 0, void 0, table);
|
|
1405
1406
|
continue;
|
|
1406
1407
|
}
|
|
1407
1408
|
const variants = [routePath];
|
|
@@ -1420,14 +1421,14 @@ var Elysia = class Elysia {
|
|
|
1420
1421
|
}
|
|
1421
1422
|
if (isDynamic) {
|
|
1422
1423
|
const router = this["~router"] ??= new memoirist.default({ loosePath: isLoose });
|
|
1423
|
-
const handler = this.handler(i, precompile,
|
|
1424
|
+
const handler = this.handler(i, precompile, void 0, void 0, void 0, table);
|
|
1424
1425
|
for (let p = 0; p < paths.length; p++) router.add(routeMethod, paths[p], handler);
|
|
1425
1426
|
} else {
|
|
1426
1427
|
const map = methods[routeMethod] ??= require_utils.nullObject();
|
|
1427
|
-
const handler = this.handler(i, precompile,
|
|
1428
|
+
const handler = this.handler(i, precompile, void 0, void 0, {
|
|
1428
1429
|
method: routeMethod,
|
|
1429
1430
|
paths
|
|
1430
|
-
});
|
|
1431
|
+
}, table);
|
|
1431
1432
|
for (let p = 0; p < paths.length; p++) map[paths[p]] = handler;
|
|
1432
1433
|
}
|
|
1433
1434
|
}
|
package/dist/base.mjs
CHANGED
|
@@ -1116,30 +1116,32 @@ var Elysia = class Elysia {
|
|
|
1116
1116
|
this.fetch;
|
|
1117
1117
|
return this;
|
|
1118
1118
|
}
|
|
1119
|
-
handler(index, immediate = this["~config"]?.precompile, route
|
|
1119
|
+
handler(index, immediate = this["~config"]?.precompile, route, precomputedStatic, aliases, table) {
|
|
1120
1120
|
if (this.#compiled?.[index]) return this.#compiled[index];
|
|
1121
1121
|
const compiled = this.#compiled ??= new Array(this["~routes"].length);
|
|
1122
1122
|
if (immediate) {
|
|
1123
|
+
const row = route ?? this["~routes"][index];
|
|
1123
1124
|
let handler;
|
|
1124
1125
|
try {
|
|
1125
|
-
handler = compileHandler(
|
|
1126
|
+
handler = compileHandler(row, this, precomputedStatic);
|
|
1126
1127
|
} catch (error) {
|
|
1127
|
-
throw new Error(`[Elysia] Failed to compile route ${
|
|
1128
|
+
throw new Error(`[Elysia] Failed to compile route ${row[0]} ${row[1]}: ${error?.message ?? error}`, { cause: error });
|
|
1128
1129
|
}
|
|
1129
1130
|
compiled[index] = handler;
|
|
1130
|
-
this.#saveHandler(
|
|
1131
|
+
this.#saveHandler(row[0], row[1], handler);
|
|
1131
1132
|
return handler;
|
|
1132
1133
|
}
|
|
1133
|
-
return this.#jitHandler(index, route, precomputedStatic, aliases);
|
|
1134
|
+
return this.#jitHandler(index, route ?? (table ? void 0 : this["~routes"][index]), precomputedStatic, aliases, table);
|
|
1134
1135
|
}
|
|
1135
|
-
#jitHandler(index, route, precomputedStatic, aliases) {
|
|
1136
|
+
#jitHandler(index, route, precomputedStatic, aliases, table) {
|
|
1136
1137
|
return (context) => {
|
|
1137
1138
|
if (this.#compiled[index]) return this.#compiled[index](context);
|
|
1139
|
+
const materialized = route ?? routeRow(table, index);
|
|
1138
1140
|
let handler;
|
|
1139
1141
|
try {
|
|
1140
|
-
handler = compileHandler(
|
|
1142
|
+
handler = compileHandler(materialized, this, precomputedStatic);
|
|
1141
1143
|
} catch (error) {
|
|
1142
|
-
const routeError = new Error(`[Elysia] Failed to compile route ${
|
|
1144
|
+
const routeError = new Error(`[Elysia] Failed to compile route ${materialized[0]} ${materialized[1]}: ${error?.message ?? error}`, { cause: error });
|
|
1143
1145
|
const finalize = this["~finalizeError"];
|
|
1144
1146
|
if (finalize) return finalize(context, routeError);
|
|
1145
1147
|
throw routeError;
|
|
@@ -1149,7 +1151,7 @@ var Elysia = class Elysia {
|
|
|
1149
1151
|
this.#initMap();
|
|
1150
1152
|
const map = this["~map"][aliases.method] ??= nullObject();
|
|
1151
1153
|
for (let p = 0; p < aliases.paths.length; p++) map[aliases.paths[p]] = handler;
|
|
1152
|
-
} else this.#saveHandler(
|
|
1154
|
+
} else this.#saveHandler(materialized[0], materialized[1], handler);
|
|
1153
1155
|
return handler(context);
|
|
1154
1156
|
};
|
|
1155
1157
|
}
|
|
@@ -1218,11 +1220,13 @@ var Elysia = class Elysia {
|
|
|
1218
1220
|
}
|
|
1219
1221
|
return memo.get(start);
|
|
1220
1222
|
}
|
|
1221
|
-
#routeMayHaveModelRef(
|
|
1223
|
+
#routeMayHaveModelRef(table, i) {
|
|
1222
1224
|
if (this["~ext"]?.macro || this["~scopeChildren"]) return true;
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1225
|
+
const macroScope = table.macroScope.get(i);
|
|
1226
|
+
const owner = table.owner[i];
|
|
1227
|
+
if (localMacroRoot(macroScope ?? owner ?? this, this)["~ext"]?.macro) return true;
|
|
1228
|
+
if (Elysia.#hookHasString(table.localHook[i])) return true;
|
|
1229
|
+
return this.#chainHasModelRef(table.appHook[i]) || this.#chainHasModelRef(table.inheritedChain[i]) || this.#chainHasModelRef(this["~hookChain"]);
|
|
1226
1230
|
}
|
|
1227
1231
|
#assertRouteModelRefs(route, method) {
|
|
1228
1232
|
const models = this["~ext"]?.models;
|
|
@@ -1332,10 +1336,7 @@ var Elysia = class Elysia {
|
|
|
1332
1336
|
const path = table.path;
|
|
1333
1337
|
const flags = table.flags;
|
|
1334
1338
|
const length = table.length;
|
|
1335
|
-
for (let i = 0; i < length; i++)
|
|
1336
|
-
const row = routeRow(table, i);
|
|
1337
|
-
if (this.#routeMayHaveModelRef(row)) this.#assertRouteModelRefs(row, method[i]);
|
|
1338
|
-
}
|
|
1339
|
+
for (let i = 0; i < length; i++) if (this.#routeMayHaveModelRef(table, i)) this.#assertRouteModelRefs(routeRow(table, i), method[i]);
|
|
1339
1340
|
if (length) Compiled.claim(this["~programId"], this["~aotFingerprint"] = createAotFingerprint());
|
|
1340
1341
|
const isLoose = this["~config"]?.strictPath !== true;
|
|
1341
1342
|
let hasLooseCandidate = false;
|
|
@@ -1398,7 +1399,7 @@ var Elysia = class Elysia {
|
|
|
1398
1399
|
const explicitMain = registerLoose ? explicitPaths?.get(routeMethod) : void 0;
|
|
1399
1400
|
if (!isDynamic && !needsEncode && !registerLoose) {
|
|
1400
1401
|
const map = methods[routeMethod] ??= nullObject();
|
|
1401
|
-
map[routePath] = this.handler(i, precompile,
|
|
1402
|
+
map[routePath] = this.handler(i, precompile, void 0, void 0, void 0, table);
|
|
1402
1403
|
continue;
|
|
1403
1404
|
}
|
|
1404
1405
|
const variants = [routePath];
|
|
@@ -1417,14 +1418,14 @@ var Elysia = class Elysia {
|
|
|
1417
1418
|
}
|
|
1418
1419
|
if (isDynamic) {
|
|
1419
1420
|
const router = this["~router"] ??= new Memoirist({ loosePath: isLoose });
|
|
1420
|
-
const handler = this.handler(i, precompile,
|
|
1421
|
+
const handler = this.handler(i, precompile, void 0, void 0, void 0, table);
|
|
1421
1422
|
for (let p = 0; p < paths.length; p++) router.add(routeMethod, paths[p], handler);
|
|
1422
1423
|
} else {
|
|
1423
1424
|
const map = methods[routeMethod] ??= nullObject();
|
|
1424
|
-
const handler = this.handler(i, precompile,
|
|
1425
|
+
const handler = this.handler(i, precompile, void 0, void 0, {
|
|
1425
1426
|
method: routeMethod,
|
|
1426
1427
|
paths
|
|
1427
|
-
});
|
|
1428
|
+
}, table);
|
|
1428
1429
|
for (let p = 0; p < paths.length; p++) map[paths[p]] = handler;
|
|
1429
1430
|
}
|
|
1430
1431
|
}
|
package/dist/compile/aot.js
CHANGED
|
@@ -219,7 +219,11 @@ function captureEntry({ method, path, slot }) {
|
|
|
219
219
|
const aotActivationError = /* @__PURE__ */ new Error("Elysia AOT capture module is not activated.");
|
|
220
220
|
function beginValidatorCapture() {
|
|
221
221
|
if (captureImpl === void 0) throw aotActivationError;
|
|
222
|
-
if (activeSession?.capture !== void 0)
|
|
222
|
+
if (activeSession?.capture !== void 0) {
|
|
223
|
+
if (activeSession.explicitCapture) throw new Error("[elysia-aot]: A capture session is already active.");
|
|
224
|
+
activeSession.explicitCapture = true;
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
223
227
|
if (activeSession && !activeSession.external) throw new Error("[elysia-aot]: A compiler session is already active.");
|
|
224
228
|
const session = activeSession ?? (activeSession = newCompilerSession());
|
|
225
229
|
session.external = true;
|
package/dist/compile/aot.mjs
CHANGED
|
@@ -218,7 +218,11 @@ function captureEntry({ method, path, slot }) {
|
|
|
218
218
|
const aotActivationError = /* @__PURE__ */ new Error("Elysia AOT capture module is not activated.");
|
|
219
219
|
function beginValidatorCapture() {
|
|
220
220
|
if (captureImpl === void 0) throw aotActivationError;
|
|
221
|
-
if (activeSession?.capture !== void 0)
|
|
221
|
+
if (activeSession?.capture !== void 0) {
|
|
222
|
+
if (activeSession.explicitCapture) throw new Error("[elysia-aot]: A capture session is already active.");
|
|
223
|
+
activeSession.explicitCapture = true;
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
222
226
|
if (activeSession && !activeSession.external) throw new Error("[elysia-aot]: A compiler session is already active.");
|
|
223
227
|
const session = activeSession ?? (activeSession = newCompilerSession());
|
|
224
228
|
session.external = true;
|
|
@@ -344,12 +344,14 @@ function compileHandler([_method, path, handler, instance, localHook, appHook, i
|
|
|
344
344
|
isStaticResponse,
|
|
345
345
|
isPromiseHandler
|
|
346
346
|
});
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
347
|
+
if (root["~introspect"] === true || root["~config"]?.introspect === true) {
|
|
348
|
+
let descriptors = require_compile_handler_descriptor.routeDescriptors.get(root);
|
|
349
|
+
if (!descriptors) {
|
|
350
|
+
descriptors = /* @__PURE__ */ new Map();
|
|
351
|
+
require_compile_handler_descriptor.routeDescriptors.set(root, descriptors);
|
|
352
|
+
}
|
|
353
|
+
descriptors.set(`${method} ${path}`, state.descriptor);
|
|
351
354
|
}
|
|
352
|
-
descriptors.set(`${method} ${path}`, state.descriptor);
|
|
353
355
|
const resumeEmit = frozenRoot["~config"]?.experimental?.resumeEmit;
|
|
354
356
|
if (resumeEmit) {
|
|
355
357
|
if (typeof resumeEmit.planRoute !== "function" || typeof resumeEmit.emitResume !== "function") throw new TypeError("[elysia] experimental.resumeEmit must be imported from \"elysia/experimental/resume\".");
|
|
@@ -343,12 +343,14 @@ function compileHandler([_method, path, handler, instance, localHook, appHook, i
|
|
|
343
343
|
isStaticResponse,
|
|
344
344
|
isPromiseHandler
|
|
345
345
|
});
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
346
|
+
if (root["~introspect"] === true || root["~config"]?.introspect === true) {
|
|
347
|
+
let descriptors = routeDescriptors.get(root);
|
|
348
|
+
if (!descriptors) {
|
|
349
|
+
descriptors = /* @__PURE__ */ new Map();
|
|
350
|
+
routeDescriptors.set(root, descriptors);
|
|
351
|
+
}
|
|
352
|
+
descriptors.set(`${method} ${path}`, state.descriptor);
|
|
350
353
|
}
|
|
351
|
-
descriptors.set(`${method} ${path}`, state.descriptor);
|
|
352
354
|
const resumeEmit = frozenRoot["~config"]?.experimental?.resumeEmit;
|
|
353
355
|
if (resumeEmit) {
|
|
354
356
|
if (typeof resumeEmit.planRoute !== "function" || typeof resumeEmit.emitResume !== "function") throw new TypeError("[elysia] experimental.resumeEmit must be imported from \"elysia/experimental/resume\".");
|
|
@@ -137,39 +137,24 @@ function schemaMediaKind(schema) {
|
|
|
137
137
|
return result;
|
|
138
138
|
}
|
|
139
139
|
const fromArgs = (type, isAsync) => `'${type}'${isAsync ? ",true" : ""}`;
|
|
140
|
-
const createInlineHandler = (map, h
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const response = map(r, c.request);
|
|
146
|
-
return typeof response?.then === "function" ? Promise.resolve(response).catch((error) => require_handler_utils.finalizeRouteError(root, c, error)) : response;
|
|
147
|
-
} catch (error) {
|
|
148
|
-
return require_handler_utils.finalizeRouteError(root, c, error);
|
|
149
|
-
}
|
|
140
|
+
const createInlineHandler = (map, h) => ((c) => {
|
|
141
|
+
const r = h(c);
|
|
142
|
+
if (r instanceof Error) throw r;
|
|
143
|
+
if (r instanceof Promise) return r.then((v) => map(require_handler_utils.forwardError(v), c.request));
|
|
144
|
+
return map(r, c.request);
|
|
150
145
|
});
|
|
151
|
-
const createInlineHandlerWithSet = (map, h
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const response = map(r, c.set, c.request);
|
|
157
|
-
return typeof response?.then === "function" ? Promise.resolve(response).catch((error) => require_handler_utils.finalizeRouteError(root, c, error)) : response;
|
|
158
|
-
} catch (error) {
|
|
159
|
-
return require_handler_utils.finalizeRouteError(root, c, error);
|
|
160
|
-
}
|
|
146
|
+
const createInlineHandlerWithSet = (map, h) => ((c) => {
|
|
147
|
+
const r = h(c);
|
|
148
|
+
if (r instanceof Error) throw r;
|
|
149
|
+
if (r instanceof Promise) return r.then((v) => map(require_handler_utils.forwardError(v), c.set, c.request));
|
|
150
|
+
return map(r, c.set, c.request);
|
|
161
151
|
});
|
|
162
|
-
const createInlineHandlerWithDefaultHeaders = (map, h
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const response = map(r, c.set, c.request);
|
|
169
|
-
return typeof response?.then === "function" ? Promise.resolve(response).catch((error) => require_handler_utils.finalizeRouteError(root, c, error)) : response;
|
|
170
|
-
} catch (error) {
|
|
171
|
-
return require_handler_utils.finalizeRouteError(root, c, error);
|
|
172
|
-
}
|
|
152
|
+
const createInlineHandlerWithDefaultHeaders = (map, h) => ((c) => {
|
|
153
|
+
require_adapter_utils.materializeSetHeaders(c.set);
|
|
154
|
+
const r = h(c);
|
|
155
|
+
if (r instanceof Error) throw r;
|
|
156
|
+
if (r instanceof Promise) return r.then((v) => map(require_handler_utils.forwardError(v), c.set, c.request));
|
|
157
|
+
return map(r, c.set, c.request);
|
|
173
158
|
});
|
|
174
159
|
function compileHandlerJit({ method, path, handler, root, errorRoot, hook, adapter, isHandleFunction, isStaticResponse, isPromiseHandler, state }) {
|
|
175
160
|
const { vali, inference, cookieConfig, beforeHandlePrefix, traceHandlers, tracePhases, hasAnyPhase, traceHandleOn, descriptor: { async: isAsync, responseMode, hasBody, bodyValiIsAsync, headersValiIsAsync, paramsValiIsAsync, queryValiIsAsync, cookieValiIsAsync: cookieValidIsAsync, responseValiAsync, hasCookieSign, syncCookieSign, asyncCookieSign, lazyCookieVerify, hasErrorHook, hasAfterResponse, hasBeforeHandle, hasAfterHandle, hasMapResponse, hasResponseValidator, hasTrace, traceCount, hasLifecycleHook, callHandlerSyncOnAsync, syncErrorHook, syncAfterResponse } } = state;
|
|
@@ -516,8 +501,8 @@ if(typeof _er?.then==='function')return Promise.resolve(_er).then(${asyncCookieS
|
|
|
516
501
|
const inlineAlias = alias.startsWith("rt,fre,") ? alias.slice(7) : alias;
|
|
517
502
|
const isGeneratorHandler = isHandleFunction && handler.constructor.name.endsWith("GeneratorFunction");
|
|
518
503
|
if (!hasTrace && isHandleFunction && !isGeneratorHandler && !inlineUnsafe) {
|
|
519
|
-
if (inlineAlias === "rc" || !isAsync && !syncErrorHook && inlineAlias === "rc,fe") return createInlineHandler(res.compact ?? res.map, handler
|
|
520
|
-
else if (inlineAlias === "rm" || inlineAlias === "msh,rm" || !isAsync && !syncErrorHook && (inlineAlias === "rm,fe" || inlineAlias === "msh,rm,fe")) return responseMode === "set-with-default-headers" && inference.set ? createInlineHandlerWithDefaultHeaders(responseMap, handler
|
|
504
|
+
if (inlineAlias === "rc" || !isAsync && !syncErrorHook && inlineAlias === "rc,fe") return createInlineHandler(res.compact ?? res.map, handler);
|
|
505
|
+
else if (inlineAlias === "rm" || inlineAlias === "msh,rm" || !isAsync && !syncErrorHook && (inlineAlias === "rm,fe" || inlineAlias === "msh,rm,fe")) return responseMode === "set-with-default-headers" && inference.set ? createInlineHandlerWithDefaultHeaders(responseMap, handler) : createInlineHandlerWithSet(responseMap, handler);
|
|
521
506
|
}
|
|
522
507
|
require_compile_jit_probe.JITProbe.record("handler:new-function");
|
|
523
508
|
return new Function("h", alias, `return ${code}`)(handler, ...paramValues);
|
|
@@ -136,39 +136,24 @@ function schemaMediaKind(schema) {
|
|
|
136
136
|
return result;
|
|
137
137
|
}
|
|
138
138
|
const fromArgs = (type, isAsync) => `'${type}'${isAsync ? ",true" : ""}`;
|
|
139
|
-
const createInlineHandler = (map, h
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const response = map(r, c.request);
|
|
145
|
-
return typeof response?.then === "function" ? Promise.resolve(response).catch((error) => finalizeRouteError(root, c, error)) : response;
|
|
146
|
-
} catch (error) {
|
|
147
|
-
return finalizeRouteError(root, c, error);
|
|
148
|
-
}
|
|
139
|
+
const createInlineHandler = (map, h) => ((c) => {
|
|
140
|
+
const r = h(c);
|
|
141
|
+
if (r instanceof Error) throw r;
|
|
142
|
+
if (r instanceof Promise) return r.then((v) => map(forwardError(v), c.request));
|
|
143
|
+
return map(r, c.request);
|
|
149
144
|
});
|
|
150
|
-
const createInlineHandlerWithSet = (map, h
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const response = map(r, c.set, c.request);
|
|
156
|
-
return typeof response?.then === "function" ? Promise.resolve(response).catch((error) => finalizeRouteError(root, c, error)) : response;
|
|
157
|
-
} catch (error) {
|
|
158
|
-
return finalizeRouteError(root, c, error);
|
|
159
|
-
}
|
|
145
|
+
const createInlineHandlerWithSet = (map, h) => ((c) => {
|
|
146
|
+
const r = h(c);
|
|
147
|
+
if (r instanceof Error) throw r;
|
|
148
|
+
if (r instanceof Promise) return r.then((v) => map(forwardError(v), c.set, c.request));
|
|
149
|
+
return map(r, c.set, c.request);
|
|
160
150
|
});
|
|
161
|
-
const createInlineHandlerWithDefaultHeaders = (map, h
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const response = map(r, c.set, c.request);
|
|
168
|
-
return typeof response?.then === "function" ? Promise.resolve(response).catch((error) => finalizeRouteError(root, c, error)) : response;
|
|
169
|
-
} catch (error) {
|
|
170
|
-
return finalizeRouteError(root, c, error);
|
|
171
|
-
}
|
|
151
|
+
const createInlineHandlerWithDefaultHeaders = (map, h) => ((c) => {
|
|
152
|
+
materializeSetHeaders(c.set);
|
|
153
|
+
const r = h(c);
|
|
154
|
+
if (r instanceof Error) throw r;
|
|
155
|
+
if (r instanceof Promise) return r.then((v) => map(forwardError(v), c.set, c.request));
|
|
156
|
+
return map(r, c.set, c.request);
|
|
172
157
|
});
|
|
173
158
|
function compileHandlerJit({ method, path, handler, root, errorRoot, hook, adapter, isHandleFunction, isStaticResponse, isPromiseHandler, state }) {
|
|
174
159
|
const { vali, inference, cookieConfig, beforeHandlePrefix, traceHandlers, tracePhases, hasAnyPhase, traceHandleOn, descriptor: { async: isAsync, responseMode, hasBody, bodyValiIsAsync, headersValiIsAsync, paramsValiIsAsync, queryValiIsAsync, cookieValiIsAsync: cookieValidIsAsync, responseValiAsync, hasCookieSign, syncCookieSign, asyncCookieSign, lazyCookieVerify, hasErrorHook, hasAfterResponse, hasBeforeHandle, hasAfterHandle, hasMapResponse, hasResponseValidator, hasTrace, traceCount, hasLifecycleHook, callHandlerSyncOnAsync, syncErrorHook, syncAfterResponse } } = state;
|
|
@@ -515,8 +500,8 @@ if(typeof _er?.then==='function')return Promise.resolve(_er).then(${asyncCookieS
|
|
|
515
500
|
const inlineAlias = alias.startsWith("rt,fre,") ? alias.slice(7) : alias;
|
|
516
501
|
const isGeneratorHandler = isHandleFunction && handler.constructor.name.endsWith("GeneratorFunction");
|
|
517
502
|
if (!hasTrace && isHandleFunction && !isGeneratorHandler && !inlineUnsafe) {
|
|
518
|
-
if (inlineAlias === "rc" || !isAsync && !syncErrorHook && inlineAlias === "rc,fe") return createInlineHandler(res.compact ?? res.map, handler
|
|
519
|
-
else if (inlineAlias === "rm" || inlineAlias === "msh,rm" || !isAsync && !syncErrorHook && (inlineAlias === "rm,fe" || inlineAlias === "msh,rm,fe")) return responseMode === "set-with-default-headers" && inference.set ? createInlineHandlerWithDefaultHeaders(responseMap, handler
|
|
503
|
+
if (inlineAlias === "rc" || !isAsync && !syncErrorHook && inlineAlias === "rc,fe") return createInlineHandler(res.compact ?? res.map, handler);
|
|
504
|
+
else if (inlineAlias === "rm" || inlineAlias === "msh,rm" || !isAsync && !syncErrorHook && (inlineAlias === "rm,fe" || inlineAlias === "msh,rm,fe")) return responseMode === "set-with-default-headers" && inference.set ? createInlineHandlerWithDefaultHeaders(responseMap, handler) : createInlineHandlerWithSet(responseMap, handler);
|
|
520
505
|
}
|
|
521
506
|
JITProbe.record("handler:new-function");
|
|
522
507
|
return new Function("h", alias, `return ${code}`)(handler, ...paramValues);
|
package/dist/compile/lexer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//#region src/compile/lexer.d.ts
|
|
2
|
-
declare const isSpace: (ch: string) => ch is "
|
|
2
|
+
declare const isSpace: (ch: string) => ch is " " | "\n" | "\t" | "\r";
|
|
3
3
|
declare const isIdentChar: (ch: string) => boolean;
|
|
4
4
|
declare const isIdentCharCode: (code: number) => boolean;
|
|
5
5
|
declare function skipString(src: string, start: number): number;
|
package/dist/handler/fetch.js
CHANGED
|
@@ -56,6 +56,11 @@ function finalizeError(context, handleError, afterResponse, error) {
|
|
|
56
56
|
return resp;
|
|
57
57
|
}
|
|
58
58
|
const catchError = (context, handleError, afterResponse) => (error) => finalizeError(context, handleError, afterResponse, error);
|
|
59
|
+
function dispatchResult(result, context, handleError, afterResponse) {
|
|
60
|
+
if (result instanceof Promise) return result.catch(catchError(context, handleError, afterResponse));
|
|
61
|
+
if (typeof result?.then === "function") return Promise.resolve(result).catch(catchError(context, handleError, afterResponse));
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
59
64
|
function findRoute(context, request, map, router, hasError, handleError, afterResponse, strictPath, hasWS, hasDynamicWS) {
|
|
60
65
|
const path = context.path;
|
|
61
66
|
if (hasWS && request.method === "GET") {
|
|
@@ -85,11 +90,11 @@ function findRoute(context, request, map, router, hasError, handleError, afterRe
|
|
|
85
90
|
handler = anyMap?.[path] ?? anyMap?.[loose];
|
|
86
91
|
}
|
|
87
92
|
} else handler = map["*"]?.[path];
|
|
88
|
-
if (handler) return handler(context);
|
|
93
|
+
if (handler) return dispatchResult(handler(context), context, handleError, afterResponse);
|
|
89
94
|
const found = router?.find(method, path) ?? router?.find("*", path);
|
|
90
95
|
if (found) {
|
|
91
96
|
context.params = decodeParams(found.params);
|
|
92
|
-
return found.store(context);
|
|
97
|
+
return dispatchResult(found.store(context), context, handleError, afterResponse);
|
|
93
98
|
}
|
|
94
99
|
if (hasError) throw new require_error.NotFound();
|
|
95
100
|
afterResponse?.(context, 404);
|
|
@@ -296,22 +301,26 @@ function createFetchHandler(app) {
|
|
|
296
301
|
}
|
|
297
302
|
}
|
|
298
303
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
304
|
+
try {
|
|
305
|
+
const methodMap = map[method];
|
|
306
|
+
let handler = methodMap?.[path];
|
|
307
|
+
if (handler) return dispatchResult(handler(context), context, handleError, afterResponse);
|
|
308
|
+
if (!strictPath && path.length > 1 && path.charCodeAt(path.length - 1) === 47) {
|
|
309
|
+
const loose = path.slice(0, -1);
|
|
310
|
+
handler = methodMap?.[loose];
|
|
311
|
+
if (!handler) {
|
|
312
|
+
const anyMap = map["*"];
|
|
313
|
+
handler = anyMap?.[path] ?? anyMap?.[loose];
|
|
314
|
+
}
|
|
315
|
+
} else handler = map["*"]?.[path];
|
|
316
|
+
if (handler) return dispatchResult(handler(context), context, handleError, afterResponse);
|
|
317
|
+
const result = router?.find(method, path) ?? router?.find("*", path);
|
|
318
|
+
if (result) {
|
|
319
|
+
context.params = decodeParams(result.params);
|
|
320
|
+
return dispatchResult(result.store(context), context, handleError, afterResponse);
|
|
308
321
|
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
const result = router?.find(method, path) ?? router?.find("*", path);
|
|
312
|
-
if (result) {
|
|
313
|
-
context.params = decodeParams(result.params);
|
|
314
|
-
return result.store(context);
|
|
322
|
+
} catch (error) {
|
|
323
|
+
return finalizeError(context, handleError, afterResponse, error);
|
|
315
324
|
}
|
|
316
325
|
if (hasError) return finalizeError(context, handleError, afterResponse, new require_error.NotFound());
|
|
317
326
|
afterResponse?.(context, 404);
|
package/dist/handler/fetch.mjs
CHANGED
|
@@ -54,6 +54,11 @@ function finalizeError(context, handleError, afterResponse, error) {
|
|
|
54
54
|
return resp;
|
|
55
55
|
}
|
|
56
56
|
const catchError = (context, handleError, afterResponse) => (error) => finalizeError(context, handleError, afterResponse, error);
|
|
57
|
+
function dispatchResult(result, context, handleError, afterResponse) {
|
|
58
|
+
if (result instanceof Promise) return result.catch(catchError(context, handleError, afterResponse));
|
|
59
|
+
if (typeof result?.then === "function") return Promise.resolve(result).catch(catchError(context, handleError, afterResponse));
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
57
62
|
function findRoute(context, request, map, router, hasError, handleError, afterResponse, strictPath, hasWS, hasDynamicWS) {
|
|
58
63
|
const path = context.path;
|
|
59
64
|
if (hasWS && request.method === "GET") {
|
|
@@ -83,11 +88,11 @@ function findRoute(context, request, map, router, hasError, handleError, afterRe
|
|
|
83
88
|
handler = anyMap?.[path] ?? anyMap?.[loose];
|
|
84
89
|
}
|
|
85
90
|
} else handler = map["*"]?.[path];
|
|
86
|
-
if (handler) return handler(context);
|
|
91
|
+
if (handler) return dispatchResult(handler(context), context, handleError, afterResponse);
|
|
87
92
|
const found = router?.find(method, path) ?? router?.find("*", path);
|
|
88
93
|
if (found) {
|
|
89
94
|
context.params = decodeParams(found.params);
|
|
90
|
-
return found.store(context);
|
|
95
|
+
return dispatchResult(found.store(context), context, handleError, afterResponse);
|
|
91
96
|
}
|
|
92
97
|
if (hasError) throw new NotFound();
|
|
93
98
|
afterResponse?.(context, 404);
|
|
@@ -294,22 +299,26 @@ function createFetchHandler(app) {
|
|
|
294
299
|
}
|
|
295
300
|
}
|
|
296
301
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
302
|
+
try {
|
|
303
|
+
const methodMap = map[method];
|
|
304
|
+
let handler = methodMap?.[path];
|
|
305
|
+
if (handler) return dispatchResult(handler(context), context, handleError, afterResponse);
|
|
306
|
+
if (!strictPath && path.length > 1 && path.charCodeAt(path.length - 1) === 47) {
|
|
307
|
+
const loose = path.slice(0, -1);
|
|
308
|
+
handler = methodMap?.[loose];
|
|
309
|
+
if (!handler) {
|
|
310
|
+
const anyMap = map["*"];
|
|
311
|
+
handler = anyMap?.[path] ?? anyMap?.[loose];
|
|
312
|
+
}
|
|
313
|
+
} else handler = map["*"]?.[path];
|
|
314
|
+
if (handler) return dispatchResult(handler(context), context, handleError, afterResponse);
|
|
315
|
+
const result = router?.find(method, path) ?? router?.find("*", path);
|
|
316
|
+
if (result) {
|
|
317
|
+
context.params = decodeParams(result.params);
|
|
318
|
+
return dispatchResult(result.store(context), context, handleError, afterResponse);
|
|
306
319
|
}
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
const result = router?.find(method, path) ?? router?.find("*", path);
|
|
310
|
-
if (result) {
|
|
311
|
-
context.params = decodeParams(result.params);
|
|
312
|
-
return result.store(context);
|
|
320
|
+
} catch (error) {
|
|
321
|
+
return finalizeError(context, handleError, afterResponse, error);
|
|
313
322
|
}
|
|
314
323
|
if (hasError) return finalizeError(context, handleError, afterResponse, new NotFound());
|
|
315
324
|
afterResponse?.(context, 404);
|
package/dist/package.js
CHANGED
package/dist/package.mjs
CHANGED
|
@@ -5,8 +5,8 @@ import { hasTypes } from "./utils.js";
|
|
|
5
5
|
import { useTypebox as useTypebox$1 } from "./bridge.js";
|
|
6
6
|
import { applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, coerceStringToStructure } from "./coerce.js";
|
|
7
7
|
import { Ref } from "typebox/type";
|
|
8
|
-
import { Compile } from "typebox/compile";
|
|
9
8
|
import { Clone, Create, Decode, Default, HasCodec } from "typebox/value";
|
|
9
|
+
import { Compile } from "typebox/compile";
|
|
10
10
|
|
|
11
11
|
//#region src/type/bridge-live.d.ts
|
|
12
12
|
declare function useTypebox(_mod?: Parameters<typeof useTypebox$1>[0]): void;
|
package/dist/type/bridge.d.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { TypeBoxValidatorCache as TypeBoxValidatorCache$1 } from "./validator/validator-cache.js";
|
|
2
2
|
import { TypeBoxValidator as TypeBoxValidator$1 } from "./validator/index.js";
|
|
3
|
-
import { Intersect as Intersect$
|
|
3
|
+
import { Intersect as Intersect$2 } from "./elysia/intersect.js";
|
|
4
4
|
import { hasTypes as hasTypes$1 } from "./utils.js";
|
|
5
5
|
import { applyCoercions as applyCoercions$1, coerceBody as coerceBody$1, coerceFormData as coerceFormData$1, coerceQuery as coerceQuery$1, coerceRoot as coerceRoot$1, coerceStringToStructure as coerceStringToStructure$1 } from "./coerce.js";
|
|
6
6
|
import { Ref as Ref$1, TAny, TSchema } from "typebox/type";
|
|
7
|
+
import { Clone as Clone$1, Create as Create$1, Decode as Decode$2, Default as Default$1, HasCodec as HasCodec$1 } from "typebox/value";
|
|
7
8
|
import { Compile as Compile$1 } from "typebox/compile";
|
|
8
|
-
import { Clone as Clone$1, Create as Create$1, Decode as Decode$1, Default as Default$1, HasCodec as HasCodec$1 } from "typebox/value";
|
|
9
9
|
|
|
10
10
|
//#region src/type/bridge.d.ts
|
|
11
11
|
interface TypeboxModule {
|
|
12
12
|
Compile: typeof Compile$1;
|
|
13
13
|
Create: typeof Create$1;
|
|
14
|
-
Decode: typeof Decode$
|
|
14
|
+
Decode: typeof Decode$2;
|
|
15
15
|
applyCoercions: typeof applyCoercions$1;
|
|
16
16
|
TypeBoxValidator: TypeBoxValidator$1;
|
|
17
17
|
TypeBoxValidatorCache: TypeBoxValidatorCache$1;
|
|
@@ -22,14 +22,14 @@ interface TypeboxModule {
|
|
|
22
22
|
coerceBody: typeof coerceBody$1;
|
|
23
23
|
hasTypes: typeof hasTypes$1;
|
|
24
24
|
HasCodec: typeof HasCodec$1;
|
|
25
|
-
Intersect: typeof Intersect$
|
|
25
|
+
Intersect: typeof Intersect$2;
|
|
26
26
|
Default: typeof Default$1;
|
|
27
27
|
Ref: typeof Ref$1;
|
|
28
28
|
Clone: typeof Clone$1;
|
|
29
29
|
}
|
|
30
30
|
declare let Compile: typeof Compile$1;
|
|
31
31
|
declare let Create: typeof Create$1;
|
|
32
|
-
declare let Decode: typeof Decode$
|
|
32
|
+
declare let Decode: typeof Decode$2;
|
|
33
33
|
declare let applyCoercions: typeof applyCoercions$1;
|
|
34
34
|
declare let TypeBoxValidator: TypeBoxValidator$1;
|
|
35
35
|
type TypeBoxValidator<T extends TSchema = TAny> = TypeBoxValidator$1<T>;
|
|
@@ -42,7 +42,7 @@ declare let coerceStringToStructure: typeof coerceStringToStructure$1;
|
|
|
42
42
|
declare let coerceBody: typeof coerceBody$1;
|
|
43
43
|
declare let hasTypes: typeof hasTypes$1;
|
|
44
44
|
declare let HasCodec: typeof HasCodec$1;
|
|
45
|
-
declare let Intersect: typeof Intersect$
|
|
45
|
+
declare let Intersect: typeof Intersect$2;
|
|
46
46
|
declare let Default: typeof Default$1;
|
|
47
47
|
declare let Ref: typeof Ref$1;
|
|
48
48
|
declare let Clone: typeof Clone$1;
|
package/dist/type/constants.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ declare const ELYSIA_TYPES: {
|
|
|
17
17
|
readonly NoValidate: 15;
|
|
18
18
|
};
|
|
19
19
|
type ELYSIA_TYPES = typeof ELYSIA_TYPES;
|
|
20
|
-
declare const primitiveElysiaTypes: Set<1 | 2 | 6 |
|
|
20
|
+
declare const primitiveElysiaTypes: Set<1 | 2 | 6 | 3 | 10 | 11 | 13 | 14>;
|
|
21
21
|
declare const noEnumerable: {
|
|
22
22
|
readonly enumerable: false;
|
|
23
23
|
};
|
|
@@ -2,8 +2,8 @@ import { TypeBoxValidatorCache } from "./validator-cache.js";
|
|
|
2
2
|
import { Validator as Validator$1, ValidatorOptions } from "../../validator/index.js";
|
|
3
3
|
import { MaybePromise } from "../../types.js";
|
|
4
4
|
import { Static, StaticDecode, StaticEncode, TAny, TSchema } from "typebox/type";
|
|
5
|
-
import { TLocalizedValidationError } from "typebox/error";
|
|
6
5
|
import { Validator } from "typebox/schema";
|
|
6
|
+
import { TLocalizedValidationError } from "typebox/error";
|
|
7
7
|
|
|
8
8
|
//#region src/type/validator/index.d.ts
|
|
9
9
|
declare function shallowMergeObjects(members: any[]): TSchema | null;
|
|
@@ -23,6 +23,24 @@ exact_mirror = require_runtime.__toESM(exact_mirror);
|
|
|
23
23
|
const moduleCache = /* @__PURE__ */ new WeakMap();
|
|
24
24
|
let activeRefineValidation;
|
|
25
25
|
const refinementGroups = /* @__PURE__ */ new WeakMap();
|
|
26
|
+
const freshRefineValidation = (groups) => {
|
|
27
|
+
const slots = /* @__PURE__ */ new Map();
|
|
28
|
+
for (const group of groups) slots.set(group, {
|
|
29
|
+
epoch: 0,
|
|
30
|
+
replayEpoch: 0,
|
|
31
|
+
occurrences: 0,
|
|
32
|
+
recorded: 0,
|
|
33
|
+
verdicts: []
|
|
34
|
+
});
|
|
35
|
+
return {
|
|
36
|
+
slots,
|
|
37
|
+
epoch: 0,
|
|
38
|
+
replayEpoch: 0,
|
|
39
|
+
replay: false,
|
|
40
|
+
active: false,
|
|
41
|
+
checking: false
|
|
42
|
+
};
|
|
43
|
+
};
|
|
26
44
|
function collectRefinements(schema, out = /* @__PURE__ */ new Set(), seen = /* @__PURE__ */ new WeakSet()) {
|
|
27
45
|
if (!schema || typeof schema !== "object" || seen.has(schema)) return out;
|
|
28
46
|
seen.add(schema);
|
|
@@ -41,18 +59,31 @@ function collectRefinements(schema, out = /* @__PURE__ */ new Set(), seen = /* @
|
|
|
41
59
|
const refinement = members[index];
|
|
42
60
|
refinement.check = function(value) {
|
|
43
61
|
const validation = activeRefineValidation;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (
|
|
47
|
-
validation.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
62
|
+
const slot = validation?.slots.get(group);
|
|
63
|
+
if (slot === void 0) return group.checks[index].call(this, value);
|
|
64
|
+
if (!validation.replay) {
|
|
65
|
+
if (slot.epoch !== validation.epoch) {
|
|
66
|
+
slot.epoch = validation.epoch;
|
|
67
|
+
slot.occurrences = 0;
|
|
68
|
+
slot.recorded = 0;
|
|
69
|
+
}
|
|
70
|
+
if (index === 0) {
|
|
71
|
+
const occurrence = slot.occurrences++;
|
|
72
|
+
slot.recorded = slot.occurrences;
|
|
73
|
+
let results = slot.verdicts[occurrence];
|
|
74
|
+
if (results === void 0) slot.verdicts[occurrence] = results = [];
|
|
75
|
+
const checks = group.checks;
|
|
76
|
+
for (let i = 0; i < checks.length; i++) results[i] = Boolean(checks[i].call(this, value));
|
|
53
77
|
}
|
|
78
|
+
return slot.verdicts[slot.occurrences - 1][index];
|
|
54
79
|
}
|
|
55
|
-
|
|
80
|
+
if (slot.replayEpoch !== validation.replayEpoch) {
|
|
81
|
+
slot.replayEpoch = validation.replayEpoch;
|
|
82
|
+
slot.occurrences = 0;
|
|
83
|
+
}
|
|
84
|
+
if (index === 0) slot.occurrences++;
|
|
85
|
+
if (slot.occurrences > slot.recorded) return true;
|
|
86
|
+
return slot.verdicts[slot.occurrences - 1][index];
|
|
56
87
|
};
|
|
57
88
|
}
|
|
58
89
|
}
|
|
@@ -169,6 +200,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
169
200
|
#decodeMirror;
|
|
170
201
|
#encodeMirror;
|
|
171
202
|
#refinements;
|
|
203
|
+
#refineScratch;
|
|
172
204
|
#findCustomError;
|
|
173
205
|
#defaultFastPath;
|
|
174
206
|
#noValidate;
|
|
@@ -290,21 +322,22 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
290
322
|
}
|
|
291
323
|
#validate(value) {
|
|
292
324
|
if (!this.#refinements) return this.Check(value) ? void 0 : [];
|
|
325
|
+
const pool = this.#refineScratch ??= freshRefineValidation(this.#refinements);
|
|
326
|
+
const usingPool = !pool.active;
|
|
327
|
+
const validation = usingPool ? pool : freshRefineValidation(this.#refinements);
|
|
293
328
|
const previous = activeRefineValidation;
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
replay: false,
|
|
298
|
-
occurrences: /* @__PURE__ */ new Map()
|
|
299
|
-
};
|
|
329
|
+
if (usingPool) pool.active = true;
|
|
330
|
+
validation.epoch++;
|
|
331
|
+
validation.replay = false;
|
|
300
332
|
activeRefineValidation = validation;
|
|
301
333
|
try {
|
|
302
334
|
if (this.Check(value)) return;
|
|
303
335
|
validation.replay = true;
|
|
304
|
-
validation.
|
|
336
|
+
validation.replayEpoch++;
|
|
305
337
|
return this.Errors(value);
|
|
306
338
|
} finally {
|
|
307
339
|
activeRefineValidation = previous;
|
|
340
|
+
if (usingPool) pool.active = false;
|
|
308
341
|
}
|
|
309
342
|
}
|
|
310
343
|
#setupMirror(schema, options, frozen) {
|
|
@@ -367,6 +400,27 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
367
400
|
} catch {}
|
|
368
401
|
}
|
|
369
402
|
Check(value) {
|
|
403
|
+
const pool = this.#refineScratch;
|
|
404
|
+
if (pool?.active && this.#refinements) {
|
|
405
|
+
if (pool.checking) {
|
|
406
|
+
const previous = activeRefineValidation;
|
|
407
|
+
activeRefineValidation = void 0;
|
|
408
|
+
try {
|
|
409
|
+
return this.#rawCheck(value);
|
|
410
|
+
} finally {
|
|
411
|
+
activeRefineValidation = previous;
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
pool.checking = true;
|
|
415
|
+
try {
|
|
416
|
+
return this.#rawCheck(value);
|
|
417
|
+
} finally {
|
|
418
|
+
pool.checking = false;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
return this.#rawCheck(value);
|
|
422
|
+
}
|
|
423
|
+
#rawCheck(value) {
|
|
370
424
|
if (this.reconstructedCheck) return this.reconstructedCheck(value);
|
|
371
425
|
return this.tb.Check(value);
|
|
372
426
|
}
|
|
@@ -20,6 +20,24 @@ import createMirror from "exact-mirror";
|
|
|
20
20
|
const moduleCache = /* @__PURE__ */ new WeakMap();
|
|
21
21
|
let activeRefineValidation;
|
|
22
22
|
const refinementGroups = /* @__PURE__ */ new WeakMap();
|
|
23
|
+
const freshRefineValidation = (groups) => {
|
|
24
|
+
const slots = /* @__PURE__ */ new Map();
|
|
25
|
+
for (const group of groups) slots.set(group, {
|
|
26
|
+
epoch: 0,
|
|
27
|
+
replayEpoch: 0,
|
|
28
|
+
occurrences: 0,
|
|
29
|
+
recorded: 0,
|
|
30
|
+
verdicts: []
|
|
31
|
+
});
|
|
32
|
+
return {
|
|
33
|
+
slots,
|
|
34
|
+
epoch: 0,
|
|
35
|
+
replayEpoch: 0,
|
|
36
|
+
replay: false,
|
|
37
|
+
active: false,
|
|
38
|
+
checking: false
|
|
39
|
+
};
|
|
40
|
+
};
|
|
23
41
|
function collectRefinements(schema, out = /* @__PURE__ */ new Set(), seen = /* @__PURE__ */ new WeakSet()) {
|
|
24
42
|
if (!schema || typeof schema !== "object" || seen.has(schema)) return out;
|
|
25
43
|
seen.add(schema);
|
|
@@ -38,18 +56,31 @@ function collectRefinements(schema, out = /* @__PURE__ */ new Set(), seen = /* @
|
|
|
38
56
|
const refinement = members[index];
|
|
39
57
|
refinement.check = function(value) {
|
|
40
58
|
const validation = activeRefineValidation;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (
|
|
44
|
-
validation.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
59
|
+
const slot = validation?.slots.get(group);
|
|
60
|
+
if (slot === void 0) return group.checks[index].call(this, value);
|
|
61
|
+
if (!validation.replay) {
|
|
62
|
+
if (slot.epoch !== validation.epoch) {
|
|
63
|
+
slot.epoch = validation.epoch;
|
|
64
|
+
slot.occurrences = 0;
|
|
65
|
+
slot.recorded = 0;
|
|
66
|
+
}
|
|
67
|
+
if (index === 0) {
|
|
68
|
+
const occurrence = slot.occurrences++;
|
|
69
|
+
slot.recorded = slot.occurrences;
|
|
70
|
+
let results = slot.verdicts[occurrence];
|
|
71
|
+
if (results === void 0) slot.verdicts[occurrence] = results = [];
|
|
72
|
+
const checks = group.checks;
|
|
73
|
+
for (let i = 0; i < checks.length; i++) results[i] = Boolean(checks[i].call(this, value));
|
|
50
74
|
}
|
|
75
|
+
return slot.verdicts[slot.occurrences - 1][index];
|
|
51
76
|
}
|
|
52
|
-
|
|
77
|
+
if (slot.replayEpoch !== validation.replayEpoch) {
|
|
78
|
+
slot.replayEpoch = validation.replayEpoch;
|
|
79
|
+
slot.occurrences = 0;
|
|
80
|
+
}
|
|
81
|
+
if (index === 0) slot.occurrences++;
|
|
82
|
+
if (slot.occurrences > slot.recorded) return true;
|
|
83
|
+
return slot.verdicts[slot.occurrences - 1][index];
|
|
53
84
|
};
|
|
54
85
|
}
|
|
55
86
|
}
|
|
@@ -166,6 +197,7 @@ var TypeBoxValidator = class extends Validator$1 {
|
|
|
166
197
|
#decodeMirror;
|
|
167
198
|
#encodeMirror;
|
|
168
199
|
#refinements;
|
|
200
|
+
#refineScratch;
|
|
169
201
|
#findCustomError;
|
|
170
202
|
#defaultFastPath;
|
|
171
203
|
#noValidate;
|
|
@@ -287,21 +319,22 @@ var TypeBoxValidator = class extends Validator$1 {
|
|
|
287
319
|
}
|
|
288
320
|
#validate(value) {
|
|
289
321
|
if (!this.#refinements) return this.Check(value) ? void 0 : [];
|
|
322
|
+
const pool = this.#refineScratch ??= freshRefineValidation(this.#refinements);
|
|
323
|
+
const usingPool = !pool.active;
|
|
324
|
+
const validation = usingPool ? pool : freshRefineValidation(this.#refinements);
|
|
290
325
|
const previous = activeRefineValidation;
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
replay: false,
|
|
295
|
-
occurrences: /* @__PURE__ */ new Map()
|
|
296
|
-
};
|
|
326
|
+
if (usingPool) pool.active = true;
|
|
327
|
+
validation.epoch++;
|
|
328
|
+
validation.replay = false;
|
|
297
329
|
activeRefineValidation = validation;
|
|
298
330
|
try {
|
|
299
331
|
if (this.Check(value)) return;
|
|
300
332
|
validation.replay = true;
|
|
301
|
-
validation.
|
|
333
|
+
validation.replayEpoch++;
|
|
302
334
|
return this.Errors(value);
|
|
303
335
|
} finally {
|
|
304
336
|
activeRefineValidation = previous;
|
|
337
|
+
if (usingPool) pool.active = false;
|
|
305
338
|
}
|
|
306
339
|
}
|
|
307
340
|
#setupMirror(schema, options, frozen) {
|
|
@@ -364,6 +397,27 @@ var TypeBoxValidator = class extends Validator$1 {
|
|
|
364
397
|
} catch {}
|
|
365
398
|
}
|
|
366
399
|
Check(value) {
|
|
400
|
+
const pool = this.#refineScratch;
|
|
401
|
+
if (pool?.active && this.#refinements) {
|
|
402
|
+
if (pool.checking) {
|
|
403
|
+
const previous = activeRefineValidation;
|
|
404
|
+
activeRefineValidation = void 0;
|
|
405
|
+
try {
|
|
406
|
+
return this.#rawCheck(value);
|
|
407
|
+
} finally {
|
|
408
|
+
activeRefineValidation = previous;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
pool.checking = true;
|
|
412
|
+
try {
|
|
413
|
+
return this.#rawCheck(value);
|
|
414
|
+
} finally {
|
|
415
|
+
pool.checking = false;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
return this.#rawCheck(value);
|
|
419
|
+
}
|
|
420
|
+
#rawCheck(value) {
|
|
367
421
|
if (this.reconstructedCheck) return this.reconstructedCheck(value);
|
|
368
422
|
return this.tb.Check(value);
|
|
369
423
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ import { Context, ErrorContext, LifecycleContext, PreContext } from "./context.j
|
|
|
11
11
|
import { AnySchema, StandardSchemaV1Like, TypeBoxSchema } from "./type/types.js";
|
|
12
12
|
import { AnyElysia, Elysia } from "./base.js";
|
|
13
13
|
import { ElysiaAdapter } from "./adapter/index.js";
|
|
14
|
-
import { Static, StaticDecode, StaticEncode, TIntersect, TObject, TSchema } from "typebox";
|
|
15
14
|
import { Instruction } from "exact-mirror";
|
|
15
|
+
import { Static, StaticDecode, StaticEncode, TIntersect, TObject, TSchema } from "typebox";
|
|
16
16
|
import { OpenAPIV3 } from "openapi-types";
|
|
17
17
|
|
|
18
18
|
//#region src/types.d.ts
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { AnyLocalHook, AppHook, ElysiaFormData, EventFn, EventScope, GuardSchemaType, InputSchema, Macro, MaybeArray, Prettify, SSEPayload } from "./types.js";
|
|
2
2
|
import { Context } from "./context.js";
|
|
3
3
|
import { AnySchema, StandardSchemaV1Like } from "./type/types.js";
|
|
4
|
-
|
|
5
4
|
//#region src/utils.d.ts
|
|
6
5
|
declare const nullObject: () => any;
|
|
7
6
|
type DeriveEntry = Function | readonly [Function, 'mapDerive'];
|
package/dist/validator/index.js
CHANGED
|
@@ -55,19 +55,23 @@ var Validator = class Validator {
|
|
|
55
55
|
const skipCache = options?.normalize === false || !!options?.sanitize;
|
|
56
56
|
const aot = options?.aot;
|
|
57
57
|
const slot = options?.slot;
|
|
58
|
-
const normalizeKey = options?.normalize === "typebox" ? "typebox" : "";
|
|
59
|
-
const
|
|
60
|
-
const
|
|
58
|
+
const normalizeKey = (options?.normalize === "typebox" ? "typebox" : "") + (slot?.startsWith("response") ? "\0r" : "");
|
|
59
|
+
const appHasFrozen = !!aot && !!slot && require_compile_aot.Compiled.hasValidator(aot.method, aot.path, slot, options?.app?.["~programId"]);
|
|
60
|
+
const appSpecific = appHasFrozen || require_compile_aot.Capture.isCapturing();
|
|
61
|
+
const app = options?.app;
|
|
62
|
+
const bypassCache = !!aot && !!slot && require_compile_aot.Capture.isCapturing() || appHasFrozen && options?.normalize !== "typebox" || appSpecific && !app;
|
|
63
|
+
let cache = appSpecific ? app ? tbCaches.get(app) : void 0 : tbCache;
|
|
61
64
|
if (!isIntersectable && !skipCache && !bypassCache && cache) {
|
|
62
65
|
const cached = cache.get(schema, options?.coerces, normalizeKey, options?.models);
|
|
63
66
|
if (cached) return cached;
|
|
64
|
-
} else if (!cache) {
|
|
67
|
+
} else if (!cache && !bypassCache) {
|
|
65
68
|
const created = new require_type_bridge.TypeBoxValidatorCache();
|
|
66
|
-
|
|
69
|
+
cache = created;
|
|
70
|
+
if (appSpecific && app) tbCaches.set(app, created);
|
|
67
71
|
else tbCache = created;
|
|
68
72
|
}
|
|
69
73
|
const validator = new require_type_bridge.TypeBoxValidator(schema, options, typeof name === "string" ? name : void 0, isIntersectable);
|
|
70
|
-
if (!isIntersectable && !skipCache && !bypassCache)
|
|
74
|
+
if (!isIntersectable && !skipCache && !bypassCache) cache.set(schema, options?.coerces, validator, normalizeKey, options?.models);
|
|
71
75
|
return validator;
|
|
72
76
|
}
|
|
73
77
|
if ("~standard" in schema) return new StandardValidator(schema);
|
package/dist/validator/index.mjs
CHANGED
|
@@ -54,19 +54,23 @@ var Validator = class Validator {
|
|
|
54
54
|
const skipCache = options?.normalize === false || !!options?.sanitize;
|
|
55
55
|
const aot = options?.aot;
|
|
56
56
|
const slot = options?.slot;
|
|
57
|
-
const normalizeKey = options?.normalize === "typebox" ? "typebox" : "";
|
|
58
|
-
const
|
|
59
|
-
const
|
|
57
|
+
const normalizeKey = (options?.normalize === "typebox" ? "typebox" : "") + (slot?.startsWith("response") ? "\0r" : "");
|
|
58
|
+
const appHasFrozen = !!aot && !!slot && Compiled.hasValidator(aot.method, aot.path, slot, options?.app?.["~programId"]);
|
|
59
|
+
const appSpecific = appHasFrozen || Capture.isCapturing();
|
|
60
|
+
const app = options?.app;
|
|
61
|
+
const bypassCache = !!aot && !!slot && Capture.isCapturing() || appHasFrozen && options?.normalize !== "typebox" || appSpecific && !app;
|
|
62
|
+
let cache = appSpecific ? app ? tbCaches.get(app) : void 0 : tbCache;
|
|
60
63
|
if (!isIntersectable && !skipCache && !bypassCache && cache) {
|
|
61
64
|
const cached = cache.get(schema, options?.coerces, normalizeKey, options?.models);
|
|
62
65
|
if (cached) return cached;
|
|
63
|
-
} else if (!cache) {
|
|
66
|
+
} else if (!cache && !bypassCache) {
|
|
64
67
|
const created = new TypeBoxValidatorCache();
|
|
65
|
-
|
|
68
|
+
cache = created;
|
|
69
|
+
if (appSpecific && app) tbCaches.set(app, created);
|
|
66
70
|
else tbCache = created;
|
|
67
71
|
}
|
|
68
72
|
const validator = new TypeBoxValidator(schema, options, typeof name === "string" ? name : void 0, isIntersectable);
|
|
69
|
-
if (!isIntersectable && !skipCache && !bypassCache)
|
|
73
|
+
if (!isIntersectable && !skipCache && !bypassCache) cache.set(schema, options?.coerces, validator, normalizeKey, options?.models);
|
|
70
74
|
return validator;
|
|
71
75
|
}
|
|
72
76
|
if ("~standard" in schema) return new StandardValidator(schema);
|