elysia 2.0.0-beta.6 → 2.0.0-beta.7
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 -0
- package/dist/base.js +32 -2
- package/dist/base.mjs +32 -2
- package/dist/compile/aot-capture.js +1 -1
- package/dist/compile/aot-capture.mjs +1 -1
- package/dist/compile/handler/index.js +2 -1
- package/dist/compile/handler/index.mjs +2 -1
- package/dist/compile/handler/jit.js +3 -1
- package/dist/compile/handler/jit.mjs +4 -2
- package/dist/compile/handler/params.js +1 -0
- package/dist/compile/handler/params.mjs +2 -1
- package/dist/compile/handler/utils.d.ts +2 -1
- package/dist/compile/handler/utils.js +8 -0
- package/dist/compile/handler/utils.mjs +8 -1
- package/dist/error.d.ts +2 -1
- package/dist/error.js +62 -3
- package/dist/error.mjs +62 -4
- 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-live.js +1 -1
- package/dist/type/bridge-live.mjs +1 -1
- package/dist/type/bridge.d.ts +3 -3
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/typebox-value-live.d.ts +2 -2
- package/dist/type/typebox-value-live.js +2 -2
- package/dist/type/typebox-value-live.mjs +2 -2
- package/dist/type/typebox-value.d.ts +6 -6
- package/dist/type/validator/default-precompute.d.ts +9 -1
- package/dist/type/validator/default-precompute.js +14 -2
- package/dist/type/validator/default-precompute.mjs +14 -3
- package/dist/type/validator/index.d.ts +1 -1
- package/dist/type/validator/index.js +2 -0
- package/dist/type/validator/index.mjs +3 -1
- package/dist/type/validator/validator-cache.d.ts +1 -1
- package/package.json +1 -1
package/dist/base.d.ts
CHANGED
|
@@ -38,6 +38,7 @@ declare class Elysia<const in out BasePath extends string = '', const in out Sco
|
|
|
38
38
|
private scopeParent?;
|
|
39
39
|
private pluginMacros?;
|
|
40
40
|
private macroBaseline?;
|
|
41
|
+
private macroSnapshots?;
|
|
41
42
|
'~ext'?: {
|
|
42
43
|
decorator?: Singleton['decorator'];
|
|
43
44
|
store?: Singleton['store'];
|
package/dist/base.js
CHANGED
|
@@ -643,16 +643,32 @@ var Elysia = class Elysia {
|
|
|
643
643
|
const existingMacro = this["~ext"]?.macro;
|
|
644
644
|
if (existingMacro) for (const k in existingMacro) baseline.add(k);
|
|
645
645
|
this.macroBaseline = baseline;
|
|
646
|
+
let wantSnapshot = false;
|
|
647
|
+
let settled = false;
|
|
648
|
+
let beforeMacro;
|
|
649
|
+
queueMicrotask(() => {
|
|
650
|
+
if (wantSnapshot && !settled) {
|
|
651
|
+
beforeMacro = new Map(Object.entries(this["~ext"]?.macro ?? require_utils.nullObject()));
|
|
652
|
+
(this.macroSnapshots ??= /* @__PURE__ */ new Set()).add(beforeMacro);
|
|
653
|
+
}
|
|
654
|
+
});
|
|
646
655
|
const result = app(this);
|
|
647
656
|
this.macroBaseline = prevBaseline;
|
|
648
657
|
if (result && typeof result.then === "function") {
|
|
649
|
-
|
|
650
|
-
return this.#useAsync(result.then((value) => {
|
|
658
|
+
wantSnapshot = true;
|
|
659
|
+
return this.#useAsync(Promise.resolve(result).then((value) => {
|
|
660
|
+
settled = true;
|
|
661
|
+
if (!beforeMacro) return value;
|
|
662
|
+
this.macroSnapshots?.delete(beforeMacro);
|
|
651
663
|
const after = this["~ext"]?.macro;
|
|
652
664
|
if (after) {
|
|
653
665
|
for (const [k, def] of Object.entries(after)) if (beforeMacro.get(k) !== def) throw new Error(`Macro ${k} can only run in sync plugin`);
|
|
654
666
|
}
|
|
655
667
|
return value;
|
|
668
|
+
}, (err) => {
|
|
669
|
+
settled = true;
|
|
670
|
+
if (beforeMacro) this.macroSnapshots?.delete(beforeMacro);
|
|
671
|
+
throw err;
|
|
656
672
|
}));
|
|
657
673
|
}
|
|
658
674
|
return this;
|
|
@@ -959,12 +975,26 @@ var Elysia = class Elysia {
|
|
|
959
975
|
this._pending++;
|
|
960
976
|
const next = (this.ready ?? Promise.resolve()).then(() => promise).then((value) => {
|
|
961
977
|
const plugin = value && typeof value === "object" && "default" in value && value.default ? value.default : value;
|
|
978
|
+
const snapshots = this.macroSnapshots;
|
|
979
|
+
let before;
|
|
980
|
+
if (snapshots?.size) {
|
|
981
|
+
const macro = this["~ext"]?.macro;
|
|
982
|
+
before = macro ? new Map(Object.entries(macro)) : /* @__PURE__ */ new Map();
|
|
983
|
+
}
|
|
962
984
|
if (plugin) try {
|
|
963
985
|
this.use(plugin);
|
|
964
986
|
} catch (err) {
|
|
965
987
|
this._error ??= { error: err };
|
|
966
988
|
console.error(err);
|
|
967
989
|
}
|
|
990
|
+
if (before) {
|
|
991
|
+
const after = this["~ext"]?.macro;
|
|
992
|
+
if (after) {
|
|
993
|
+
for (const [k, def] of Object.entries(after)) if (before.get(k) !== def) {
|
|
994
|
+
for (const snap of snapshots) if (snap.has(k) === before.has(k) && snap.get(k) === before.get(k)) snap.set(k, def);
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
}
|
|
968
998
|
}).finally(() => {
|
|
969
999
|
this._pending--;
|
|
970
1000
|
}).then(() => {}, (err) => {
|
package/dist/base.mjs
CHANGED
|
@@ -640,16 +640,32 @@ var Elysia = class Elysia {
|
|
|
640
640
|
const existingMacro = this["~ext"]?.macro;
|
|
641
641
|
if (existingMacro) for (const k in existingMacro) baseline.add(k);
|
|
642
642
|
this.macroBaseline = baseline;
|
|
643
|
+
let wantSnapshot = false;
|
|
644
|
+
let settled = false;
|
|
645
|
+
let beforeMacro;
|
|
646
|
+
queueMicrotask(() => {
|
|
647
|
+
if (wantSnapshot && !settled) {
|
|
648
|
+
beforeMacro = new Map(Object.entries(this["~ext"]?.macro ?? nullObject()));
|
|
649
|
+
(this.macroSnapshots ??= /* @__PURE__ */ new Set()).add(beforeMacro);
|
|
650
|
+
}
|
|
651
|
+
});
|
|
643
652
|
const result = app(this);
|
|
644
653
|
this.macroBaseline = prevBaseline;
|
|
645
654
|
if (result && typeof result.then === "function") {
|
|
646
|
-
|
|
647
|
-
return this.#useAsync(result.then((value) => {
|
|
655
|
+
wantSnapshot = true;
|
|
656
|
+
return this.#useAsync(Promise.resolve(result).then((value) => {
|
|
657
|
+
settled = true;
|
|
658
|
+
if (!beforeMacro) return value;
|
|
659
|
+
this.macroSnapshots?.delete(beforeMacro);
|
|
648
660
|
const after = this["~ext"]?.macro;
|
|
649
661
|
if (after) {
|
|
650
662
|
for (const [k, def] of Object.entries(after)) if (beforeMacro.get(k) !== def) throw new Error(`Macro ${k} can only run in sync plugin`);
|
|
651
663
|
}
|
|
652
664
|
return value;
|
|
665
|
+
}, (err) => {
|
|
666
|
+
settled = true;
|
|
667
|
+
if (beforeMacro) this.macroSnapshots?.delete(beforeMacro);
|
|
668
|
+
throw err;
|
|
653
669
|
}));
|
|
654
670
|
}
|
|
655
671
|
return this;
|
|
@@ -956,12 +972,26 @@ var Elysia = class Elysia {
|
|
|
956
972
|
this._pending++;
|
|
957
973
|
const next = (this.ready ?? Promise.resolve()).then(() => promise).then((value) => {
|
|
958
974
|
const plugin = value && typeof value === "object" && "default" in value && value.default ? value.default : value;
|
|
975
|
+
const snapshots = this.macroSnapshots;
|
|
976
|
+
let before;
|
|
977
|
+
if (snapshots?.size) {
|
|
978
|
+
const macro = this["~ext"]?.macro;
|
|
979
|
+
before = macro ? new Map(Object.entries(macro)) : /* @__PURE__ */ new Map();
|
|
980
|
+
}
|
|
959
981
|
if (plugin) try {
|
|
960
982
|
this.use(plugin);
|
|
961
983
|
} catch (err) {
|
|
962
984
|
this._error ??= { error: err };
|
|
963
985
|
console.error(err);
|
|
964
986
|
}
|
|
987
|
+
if (before) {
|
|
988
|
+
const after = this["~ext"]?.macro;
|
|
989
|
+
if (after) {
|
|
990
|
+
for (const [k, def] of Object.entries(after)) if (before.get(k) !== def) {
|
|
991
|
+
for (const snap of snapshots) if (snap.has(k) === before.has(k) && snap.get(k) === before.get(k)) snap.set(k, def);
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
}
|
|
965
995
|
}).finally(() => {
|
|
966
996
|
this._pending--;
|
|
967
997
|
}).then(() => {}, (err) => {
|
|
@@ -13,8 +13,8 @@ const require_type_validator_frozen_check = require('../type/validator/frozen-ch
|
|
|
13
13
|
const require_type_validator_custom_error = require('../type/validator/custom-error.js');
|
|
14
14
|
const require_type_validator_exact_mirror = require('../type/validator/exact-mirror.js');
|
|
15
15
|
const require_type_validator_string_codec_aot = require('../type/validator/string-codec-aot.js');
|
|
16
|
-
let typebox_value = require("typebox/value");
|
|
17
16
|
let typebox_schema = require("typebox/schema");
|
|
17
|
+
let typebox_value = require("typebox/value");
|
|
18
18
|
|
|
19
19
|
//#region src/compile/aot-capture.ts
|
|
20
20
|
function emptyContainers(node, depth) {
|
|
@@ -11,8 +11,8 @@ import { buildFrozenCheck } from "../type/validator/frozen-check.mjs";
|
|
|
11
11
|
import { captureCustomErrors } from "../type/validator/custom-error.mjs";
|
|
12
12
|
import { getExactMirror } from "../type/validator/exact-mirror.mjs";
|
|
13
13
|
import { captureStringCodecEntries } from "../type/validator/string-codec-aot.mjs";
|
|
14
|
-
import { Default } from "typebox/value";
|
|
15
14
|
import { Build, Compile } from "typebox/schema";
|
|
15
|
+
import { Default } from "typebox/value";
|
|
16
16
|
|
|
17
17
|
//#region src/compile/aot-capture.ts
|
|
18
18
|
function emptyContainers(node, depth) {
|
|
@@ -313,9 +313,10 @@ function compileHandler(route, root, precomputedStatic, liveOnly = false) {
|
|
|
313
313
|
throw error;
|
|
314
314
|
};
|
|
315
315
|
}
|
|
316
|
+
const declaresResponse = !!hook && (hook.response != null || !!hook.schemas?.some((schema) => schema?.response));
|
|
316
317
|
const isHandleFunction = typeof handler === "function";
|
|
317
318
|
if (precomputedStatic) handler = precomputedStatic;
|
|
318
|
-
else if (!isHandleFunction && !(handler instanceof Promise) && !(!require_universal_constants.isBun && handler instanceof require_universal_file.ElysiaFile)) {
|
|
319
|
+
else if (!isHandleFunction && !(handler instanceof Promise) && !(!require_universal_constants.isBun && handler instanceof require_universal_file.ElysiaFile) && !declaresResponse) {
|
|
319
320
|
const rootHeaders = frozenRoot["~ext"]?.headers;
|
|
320
321
|
const set = { headers: rootHeaders ? Object.assign(require_utils.nullObject(), rootHeaders) : require_utils.nullObject() };
|
|
321
322
|
const mapped = adapter.response.map(handler, set);
|
|
@@ -312,9 +312,10 @@ function compileHandler(route, root, precomputedStatic, liveOnly = false) {
|
|
|
312
312
|
throw error;
|
|
313
313
|
};
|
|
314
314
|
}
|
|
315
|
+
const declaresResponse = !!hook && (hook.response != null || !!hook.schemas?.some((schema) => schema?.response));
|
|
315
316
|
const isHandleFunction = typeof handler === "function";
|
|
316
317
|
if (precomputedStatic) handler = precomputedStatic;
|
|
317
|
-
else if (!isHandleFunction && !(handler instanceof Promise) && !(!isBun && handler instanceof ElysiaFile)) {
|
|
318
|
+
else if (!isHandleFunction && !(handler instanceof Promise) && !(!isBun && handler instanceof ElysiaFile) && !declaresResponse) {
|
|
318
319
|
const rootHeaders = frozenRoot["~ext"]?.headers;
|
|
319
320
|
const set = { headers: rootHeaders ? Object.assign(nullObject(), rootHeaders) : nullObject() };
|
|
320
321
|
const mapped = adapter.response.map(handler, set);
|
|
@@ -220,7 +220,9 @@ function compileHandlerJit({ method, path, handler, root, errorRoot, hook, adapt
|
|
|
220
220
|
};
|
|
221
221
|
} };
|
|
222
222
|
};
|
|
223
|
-
const
|
|
223
|
+
const needsStaticClone = !isHandleFunction && !isStaticResponse && !isPromiseHandler && (hasAfterHandle || hasMapResponse) && typeof handler === "object" && handler !== null;
|
|
224
|
+
if (needsStaticClone) link(require_compile_handler_utils.cloneStaticValue, "scl");
|
|
225
|
+
const callHandler = isHandleFunction ? callHandlerSyncOnAsync ? `_r=h(c)\nif(_r instanceof Promise)_r=await _r\n` : `_r=${isAsync ? "await " : ""}h(c)\n` : isStaticResponse ? `_r=cr(h)\n` : isPromiseHandler ? `_r=h.then(cr)\n` : needsStaticClone ? `_r=scl(h)\n` : `_r=h\n`;
|
|
224
226
|
let code = `${isAsync ? "async " : ""}function route(c){\n`;
|
|
225
227
|
if (abortOn) {
|
|
226
228
|
link(require_handler_utils.emptyResponse, "emp");
|
|
@@ -12,7 +12,7 @@ import { buildCookieJar, parseCookieRaw, parseCookieRawDeferred, parseCookieRawL
|
|
|
12
12
|
import { isAsyncFunction } from "../utils.mjs";
|
|
13
13
|
import { emptyResponse, finalizeRouteError, forwardError } from "../../handler/utils.mjs";
|
|
14
14
|
import { fallbackResponse } from "../../handler/error.mjs";
|
|
15
|
-
import { armEntryAbort, cloneResponse, getQueryParseChannels, hasRequestBody, mapAfterHandle, mapAfterResponse, mapBeforeHandle, mapError, mapMapResponse, mapTransform, runBeforeHandlePrefix, runBeforeHandlePrefixAsync } from "./utils.mjs";
|
|
15
|
+
import { armEntryAbort, cloneResponse, cloneStaticValue, getQueryParseChannels, hasRequestBody, mapAfterHandle, mapAfterResponse, mapBeforeHandle, mapError, mapMapResponse, mapTransform, runBeforeHandlePrefix, runBeforeHandlePrefixAsync } from "./utils.mjs";
|
|
16
16
|
import { JITProbe } from "../jit-probe.mjs";
|
|
17
17
|
|
|
18
18
|
//#region src/compile/handler/jit.ts
|
|
@@ -219,7 +219,9 @@ function compileHandlerJit({ method, path, handler, root, errorRoot, hook, adapt
|
|
|
219
219
|
};
|
|
220
220
|
} };
|
|
221
221
|
};
|
|
222
|
-
const
|
|
222
|
+
const needsStaticClone = !isHandleFunction && !isStaticResponse && !isPromiseHandler && (hasAfterHandle || hasMapResponse) && typeof handler === "object" && handler !== null;
|
|
223
|
+
if (needsStaticClone) link(cloneStaticValue, "scl");
|
|
224
|
+
const callHandler = isHandleFunction ? callHandlerSyncOnAsync ? `_r=h(c)\nif(_r instanceof Promise)_r=await _r\n` : `_r=${isAsync ? "await " : ""}h(c)\n` : isStaticResponse ? `_r=cr(h)\n` : isPromiseHandler ? `_r=h.then(cr)\n` : needsStaticClone ? `_r=scl(h)\n` : `_r=h\n`;
|
|
223
225
|
let code = `${isAsync ? "async " : ""}function route(c){\n`;
|
|
224
226
|
if (abortOn) {
|
|
225
227
|
link(emptyResponse, "emp");
|
|
@@ -35,6 +35,7 @@ const handlerParams = () => _handlerParams ??= {
|
|
|
35
35
|
tee: () => require_adapter_utils.tee,
|
|
36
36
|
msh: () => require_adapter_utils.materializeSetHeaders,
|
|
37
37
|
cr: () => require_compile_handler_utils.cloneResponse,
|
|
38
|
+
scl: () => require_compile_handler_utils.cloneStaticValue,
|
|
38
39
|
pcr: () => require_cookie_utils.parseCookieRaw,
|
|
39
40
|
pcrs: () => require_cookie_utils.parseCookieRawSync,
|
|
40
41
|
pcrsg: () => require_cookie_utils.parseCookieRawSigned,
|
|
@@ -5,7 +5,7 @@ import { parseQueryFromURL } from "../../parse-query.mjs";
|
|
|
5
5
|
import { buildCookieJar, parseCookieRaw, parseCookieRawDeferred, parseCookieRawLazy, parseCookieRawSigned, parseCookieRawSync, signCookieValues } from "../../cookie/utils.mjs";
|
|
6
6
|
import { emptyResponse, finalizeRouteError, forwardError } from "../../handler/utils.mjs";
|
|
7
7
|
import { adoptErrorType, fallbackResponse } from "../../handler/error.mjs";
|
|
8
|
-
import { armEntryAbort, cloneResponse, getQueryParseChannels, hasRequestBody, replaceDeriveContext, runBeforeHandlePrefix } from "./utils.mjs";
|
|
8
|
+
import { armEntryAbort, cloneResponse, cloneStaticValue, getQueryParseChannels, hasRequestBody, replaceDeriveContext, runBeforeHandlePrefix } from "./utils.mjs";
|
|
9
9
|
|
|
10
10
|
//#region src/compile/handler/params.ts
|
|
11
11
|
let _handlerParams;
|
|
@@ -34,6 +34,7 @@ const handlerParams = () => _handlerParams ??= {
|
|
|
34
34
|
tee: () => tee,
|
|
35
35
|
msh: () => materializeSetHeaders,
|
|
36
36
|
cr: () => cloneResponse,
|
|
37
|
+
scl: () => cloneStaticValue,
|
|
37
38
|
pcr: () => parseCookieRaw,
|
|
38
39
|
pcrs: () => parseCookieRawSync,
|
|
39
40
|
pcrsg: () => parseCookieRawSigned,
|
|
@@ -12,6 +12,7 @@ interface TraceReporter {
|
|
|
12
12
|
};
|
|
13
13
|
}
|
|
14
14
|
declare function cloneResponse(r: unknown): unknown;
|
|
15
|
+
declare function cloneStaticValue(value: unknown): unknown;
|
|
15
16
|
declare function hasRequestBody(request: Request): boolean;
|
|
16
17
|
/**
|
|
17
18
|
* Route-entry abort probe. Mirrors `createFetchHandler`'s `armEager`, but is
|
|
@@ -42,4 +43,4 @@ interface QueryWalkState {
|
|
|
42
43
|
}
|
|
43
44
|
declare function getQueryParseChannels(querySchema: any): QueryWalkState | undefined;
|
|
44
45
|
//#endregion
|
|
45
|
-
export { Link, TraceReporter, armEntryAbort, cloneResponse, deriveModes, emptyResponse, extractDeriveKeys, getQueryParseChannels, hasRequestBody, mapAfterHandle, mapAfterResponse, mapBeforeHandle, mapError, mapMapResponse, mapTransform, replaceDeriveContext, runBeforeHandlePrefix, runBeforeHandlePrefixAsync };
|
|
46
|
+
export { Link, TraceReporter, armEntryAbort, cloneResponse, cloneStaticValue, deriveModes, emptyResponse, extractDeriveKeys, getQueryParseChannels, hasRequestBody, mapAfterHandle, mapAfterResponse, mapBeforeHandle, mapError, mapMapResponse, mapTransform, replaceDeriveContext, runBeforeHandlePrefix, runBeforeHandlePrefixAsync };
|
|
@@ -23,6 +23,13 @@ function cloneResponse(r) {
|
|
|
23
23
|
}
|
|
24
24
|
return r;
|
|
25
25
|
}
|
|
26
|
+
function cloneStaticValue(value) {
|
|
27
|
+
try {
|
|
28
|
+
return structuredClone(value);
|
|
29
|
+
} catch {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
26
33
|
function hasRequestBody(request) {
|
|
27
34
|
const length = request.headers.get("content-length");
|
|
28
35
|
if (length !== null) return length !== "0";
|
|
@@ -501,6 +508,7 @@ const awaitGuard = (fn, isAsync, target) => isAsync && !require_compile_utils.is
|
|
|
501
508
|
//#endregion
|
|
502
509
|
exports.armEntryAbort = armEntryAbort;
|
|
503
510
|
exports.cloneResponse = cloneResponse;
|
|
511
|
+
exports.cloneStaticValue = cloneStaticValue;
|
|
504
512
|
exports.deriveModes = deriveModes;
|
|
505
513
|
exports.emptyResponse = require_handler_utils.emptyResponse;
|
|
506
514
|
exports.extractDeriveKeys = extractDeriveKeys;
|
|
@@ -22,6 +22,13 @@ function cloneResponse(r) {
|
|
|
22
22
|
}
|
|
23
23
|
return r;
|
|
24
24
|
}
|
|
25
|
+
function cloneStaticValue(value) {
|
|
26
|
+
try {
|
|
27
|
+
return structuredClone(value);
|
|
28
|
+
} catch {
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
25
32
|
function hasRequestBody(request) {
|
|
26
33
|
const length = request.headers.get("content-length");
|
|
27
34
|
if (length !== null) return length !== "0";
|
|
@@ -498,4 +505,4 @@ const Await = (fn) => isAsyncFunction(fn) ? "await " : "";
|
|
|
498
505
|
const awaitGuard = (fn, isAsync, target) => isAsync && !isAsyncFunction(fn) ? `if(${target} instanceof Promise)${target}=await ${target}\n` : "";
|
|
499
506
|
|
|
500
507
|
//#endregion
|
|
501
|
-
export { armEntryAbort, cloneResponse, deriveModes, emptyResponse, extractDeriveKeys, getQueryParseChannels, hasRequestBody, mapAfterHandle, mapAfterResponse, mapBeforeHandle, mapError, mapMapResponse, mapTransform, replaceDeriveContext, runBeforeHandlePrefix, runBeforeHandlePrefixAsync };
|
|
508
|
+
export { armEntryAbort, cloneResponse, cloneStaticValue, deriveModes, emptyResponse, extractDeriveKeys, getQueryParseChannels, hasRequestBody, mapAfterHandle, mapAfterResponse, mapBeforeHandle, mapError, mapMapResponse, mapTransform, replaceDeriveContext, runBeforeHandlePrefix, runBeforeHandlePrefixAsync };
|
package/dist/error.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ declare class ParseError extends ElysiaError {
|
|
|
40
40
|
constructor(cause?: Error);
|
|
41
41
|
toResponse(headers?: Record<string, any>): Response;
|
|
42
42
|
}
|
|
43
|
+
declare const MAX_ERRORS = 64;
|
|
43
44
|
declare function subValueAt(value: unknown, path: unknown): any;
|
|
44
45
|
declare class ValidationError extends ElysiaError {
|
|
45
46
|
#private;
|
|
@@ -365,4 +366,4 @@ declare abstract class HTTPError<const in out T extends string = string> extends
|
|
|
365
366
|
}>;
|
|
366
367
|
}
|
|
367
368
|
//#endregion
|
|
368
|
-
export { ElysiaError, ElysiaStatus, HTTPError, InternalServerError, NotFound, PROBLEM_JSON, ParseError, Problem, ProblemResponseBody, SelectiveStatus, TaggedHTTPError, ValidationError, internalServerErrorBody, internalServerErrorBodyString, internalServerErrorResponse, isProduction, problem, problemBody, problemResponse, status, subValueAt, validationDetail };
|
|
369
|
+
export { ElysiaError, ElysiaStatus, HTTPError, InternalServerError, MAX_ERRORS, NotFound, PROBLEM_JSON, ParseError, Problem, ProblemResponseBody, SelectiveStatus, TaggedHTTPError, ValidationError, internalServerErrorBody, internalServerErrorBodyString, internalServerErrorResponse, isProduction, problem, problemBody, problemResponse, status, subValueAt, validationDetail };
|
package/dist/error.js
CHANGED
|
@@ -113,6 +113,7 @@ function walkComposition(schema, parts, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
113
113
|
const walkSubSchema = (schema, instancePath) => !schema || !instancePath ? schema : walkComposition(schema, instancePath.split("/").filter(Boolean));
|
|
114
114
|
const FOUND_ECHO_LIMIT = 8192;
|
|
115
115
|
const FOUND_ECHO_OMITTED = `[value exceeds ${FOUND_ECHO_LIMIT} byte echo limit]`;
|
|
116
|
+
const MAX_ERRORS = 64;
|
|
116
117
|
function jsonStringLengthWithin(value, budget) {
|
|
117
118
|
budget -= 2;
|
|
118
119
|
for (let i = 0; i < value.length && budget >= 0; i++) {
|
|
@@ -180,6 +181,55 @@ function scopeFound(value, first) {
|
|
|
180
181
|
if (sub !== void 0 && jsonLengthWithin(sub, FOUND_ECHO_LIMIT) >= 0) return sub;
|
|
181
182
|
return FOUND_ECHO_OMITTED;
|
|
182
183
|
}
|
|
184
|
+
const issueLocator = new Set([
|
|
185
|
+
"keyword",
|
|
186
|
+
"schemaPath",
|
|
187
|
+
"instancePath",
|
|
188
|
+
"path"
|
|
189
|
+
]);
|
|
190
|
+
function scopeIssues(errors) {
|
|
191
|
+
let budget = FOUND_ECHO_LIMIT;
|
|
192
|
+
let out;
|
|
193
|
+
for (let i = 0; i < errors.length; i++) {
|
|
194
|
+
const issue = errors[i];
|
|
195
|
+
if (!issue || typeof issue !== "object") {
|
|
196
|
+
out?.push(issue);
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
let scoped;
|
|
200
|
+
for (const key in issue) {
|
|
201
|
+
if (issueLocator.has(key)) continue;
|
|
202
|
+
const member = issue[key];
|
|
203
|
+
const remaining = jsonLengthWithin(member, budget);
|
|
204
|
+
if (remaining >= 0) {
|
|
205
|
+
budget = remaining;
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
208
|
+
scoped ??= { ...issue };
|
|
209
|
+
if (member === null || typeof member !== "object" || Array.isArray(member)) {
|
|
210
|
+
scoped[key] = FOUND_ECHO_OMITTED;
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
const narrowed = {};
|
|
214
|
+
for (const name in member) {
|
|
215
|
+
const value = member[name];
|
|
216
|
+
const rest = jsonLengthWithin(value, budget);
|
|
217
|
+
if (rest >= 0) {
|
|
218
|
+
narrowed[name] = value;
|
|
219
|
+
budget = rest;
|
|
220
|
+
} else narrowed[name] = FOUND_ECHO_OMITTED;
|
|
221
|
+
}
|
|
222
|
+
scoped[key] = narrowed;
|
|
223
|
+
}
|
|
224
|
+
if (!scoped) {
|
|
225
|
+
out?.push(issue);
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
out ??= errors.slice(0, i);
|
|
229
|
+
out.push(scoped);
|
|
230
|
+
}
|
|
231
|
+
return out ?? errors;
|
|
232
|
+
}
|
|
183
233
|
var ValidationError = class extends ElysiaError {
|
|
184
234
|
#thunk;
|
|
185
235
|
#findCustomError;
|
|
@@ -233,6 +283,8 @@ var ValidationError = class extends ElysiaError {
|
|
|
233
283
|
};
|
|
234
284
|
}
|
|
235
285
|
resolved = this.#thunk() ?? [];
|
|
286
|
+
if (resolved.length > 64) resolved = resolved.slice(0, 64);
|
|
287
|
+
resolved = scopeIssues(resolved);
|
|
236
288
|
const sub = walkSubSchema(this.schema, resolved[0]?.instancePath);
|
|
237
289
|
if (sub?.error !== void 0) custom = typeof sub.error === "function" ? sub.error(production && !allowUnsafe ? {
|
|
238
290
|
type: "validation",
|
|
@@ -306,13 +358,19 @@ var ValidationError = class extends ElysiaError {
|
|
|
306
358
|
}
|
|
307
359
|
#normalizeIssue(e) {
|
|
308
360
|
if (!e) return e;
|
|
309
|
-
|
|
361
|
+
const issue = {
|
|
310
362
|
path: Array.isArray(e.path) ? e.path.length ? e.path.map(segmentString).join(".") : "root" : typeof e.path === "string" ? e.path.replace(/^\//, "").replace(/\//g, ".") || "root" : "root",
|
|
311
363
|
message: e.message ?? "",
|
|
312
364
|
schemaPath: e.schemaPath,
|
|
313
|
-
params: e.params
|
|
314
|
-
value: this.value
|
|
365
|
+
params: e.params
|
|
315
366
|
};
|
|
367
|
+
Object.defineProperty(issue, "value", {
|
|
368
|
+
value: this.value,
|
|
369
|
+
writable: true,
|
|
370
|
+
enumerable: false,
|
|
371
|
+
configurable: true
|
|
372
|
+
});
|
|
373
|
+
return issue;
|
|
316
374
|
}
|
|
317
375
|
get #productionDetail() {
|
|
318
376
|
return require_universal_is_production.isProduction() && !this.allowUnsafeValidationDetails;
|
|
@@ -585,6 +643,7 @@ exports.ElysiaError = ElysiaError;
|
|
|
585
643
|
exports.ElysiaStatus = ElysiaStatus;
|
|
586
644
|
exports.HTTPError = HTTPError;
|
|
587
645
|
exports.InternalServerError = InternalServerError;
|
|
646
|
+
exports.MAX_ERRORS = MAX_ERRORS;
|
|
588
647
|
exports.NotFound = NotFound;
|
|
589
648
|
exports.PROBLEM_JSON = PROBLEM_JSON;
|
|
590
649
|
exports.ParseError = ParseError;
|
package/dist/error.mjs
CHANGED
|
@@ -112,6 +112,7 @@ function walkComposition(schema, parts, seen = /* @__PURE__ */ new WeakSet()) {
|
|
|
112
112
|
const walkSubSchema = (schema, instancePath) => !schema || !instancePath ? schema : walkComposition(schema, instancePath.split("/").filter(Boolean));
|
|
113
113
|
const FOUND_ECHO_LIMIT = 8192;
|
|
114
114
|
const FOUND_ECHO_OMITTED = `[value exceeds ${FOUND_ECHO_LIMIT} byte echo limit]`;
|
|
115
|
+
const MAX_ERRORS = 64;
|
|
115
116
|
function jsonStringLengthWithin(value, budget) {
|
|
116
117
|
budget -= 2;
|
|
117
118
|
for (let i = 0; i < value.length && budget >= 0; i++) {
|
|
@@ -179,6 +180,55 @@ function scopeFound(value, first) {
|
|
|
179
180
|
if (sub !== void 0 && jsonLengthWithin(sub, FOUND_ECHO_LIMIT) >= 0) return sub;
|
|
180
181
|
return FOUND_ECHO_OMITTED;
|
|
181
182
|
}
|
|
183
|
+
const issueLocator = new Set([
|
|
184
|
+
"keyword",
|
|
185
|
+
"schemaPath",
|
|
186
|
+
"instancePath",
|
|
187
|
+
"path"
|
|
188
|
+
]);
|
|
189
|
+
function scopeIssues(errors) {
|
|
190
|
+
let budget = FOUND_ECHO_LIMIT;
|
|
191
|
+
let out;
|
|
192
|
+
for (let i = 0; i < errors.length; i++) {
|
|
193
|
+
const issue = errors[i];
|
|
194
|
+
if (!issue || typeof issue !== "object") {
|
|
195
|
+
out?.push(issue);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
let scoped;
|
|
199
|
+
for (const key in issue) {
|
|
200
|
+
if (issueLocator.has(key)) continue;
|
|
201
|
+
const member = issue[key];
|
|
202
|
+
const remaining = jsonLengthWithin(member, budget);
|
|
203
|
+
if (remaining >= 0) {
|
|
204
|
+
budget = remaining;
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
scoped ??= { ...issue };
|
|
208
|
+
if (member === null || typeof member !== "object" || Array.isArray(member)) {
|
|
209
|
+
scoped[key] = FOUND_ECHO_OMITTED;
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
const narrowed = {};
|
|
213
|
+
for (const name in member) {
|
|
214
|
+
const value = member[name];
|
|
215
|
+
const rest = jsonLengthWithin(value, budget);
|
|
216
|
+
if (rest >= 0) {
|
|
217
|
+
narrowed[name] = value;
|
|
218
|
+
budget = rest;
|
|
219
|
+
} else narrowed[name] = FOUND_ECHO_OMITTED;
|
|
220
|
+
}
|
|
221
|
+
scoped[key] = narrowed;
|
|
222
|
+
}
|
|
223
|
+
if (!scoped) {
|
|
224
|
+
out?.push(issue);
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
out ??= errors.slice(0, i);
|
|
228
|
+
out.push(scoped);
|
|
229
|
+
}
|
|
230
|
+
return out ?? errors;
|
|
231
|
+
}
|
|
182
232
|
var ValidationError = class extends ElysiaError {
|
|
183
233
|
#thunk;
|
|
184
234
|
#findCustomError;
|
|
@@ -232,6 +282,8 @@ var ValidationError = class extends ElysiaError {
|
|
|
232
282
|
};
|
|
233
283
|
}
|
|
234
284
|
resolved = this.#thunk() ?? [];
|
|
285
|
+
if (resolved.length > 64) resolved = resolved.slice(0, 64);
|
|
286
|
+
resolved = scopeIssues(resolved);
|
|
235
287
|
const sub = walkSubSchema(this.schema, resolved[0]?.instancePath);
|
|
236
288
|
if (sub?.error !== void 0) custom = typeof sub.error === "function" ? sub.error(production && !allowUnsafe ? {
|
|
237
289
|
type: "validation",
|
|
@@ -305,13 +357,19 @@ var ValidationError = class extends ElysiaError {
|
|
|
305
357
|
}
|
|
306
358
|
#normalizeIssue(e) {
|
|
307
359
|
if (!e) return e;
|
|
308
|
-
|
|
360
|
+
const issue = {
|
|
309
361
|
path: Array.isArray(e.path) ? e.path.length ? e.path.map(segmentString).join(".") : "root" : typeof e.path === "string" ? e.path.replace(/^\//, "").replace(/\//g, ".") || "root" : "root",
|
|
310
362
|
message: e.message ?? "",
|
|
311
363
|
schemaPath: e.schemaPath,
|
|
312
|
-
params: e.params
|
|
313
|
-
value: this.value
|
|
364
|
+
params: e.params
|
|
314
365
|
};
|
|
366
|
+
Object.defineProperty(issue, "value", {
|
|
367
|
+
value: this.value,
|
|
368
|
+
writable: true,
|
|
369
|
+
enumerable: false,
|
|
370
|
+
configurable: true
|
|
371
|
+
});
|
|
372
|
+
return issue;
|
|
315
373
|
}
|
|
316
374
|
get #productionDetail() {
|
|
317
375
|
return isProduction() && !this.allowUnsafeValidationDetails;
|
|
@@ -580,4 +638,4 @@ var HTTPError = class HTTPError extends Error {
|
|
|
580
638
|
};
|
|
581
639
|
|
|
582
640
|
//#endregion
|
|
583
|
-
export { ElysiaError, ElysiaStatus, HTTPError, InternalServerError, NotFound, PROBLEM_JSON, ParseError, ValidationError, internalServerErrorBody, internalServerErrorBodyString, internalServerErrorResponse, isProduction, problem, problemBody, problemResponse, status, subValueAt, validationDetail };
|
|
641
|
+
export { ElysiaError, ElysiaStatus, HTTPError, InternalServerError, MAX_ERRORS, NotFound, PROBLEM_JSON, ParseError, ValidationError, internalServerErrorBody, internalServerErrorBodyString, internalServerErrorResponse, isProduction, problem, problemBody, problemResponse, status, subValueAt, validationDetail };
|
package/dist/package.js
CHANGED
package/dist/package.mjs
CHANGED
|
@@ -4,9 +4,9 @@ import { useTypebox as useTypebox$1 } from "./bridge.js";
|
|
|
4
4
|
import { TypeBoxValidatorCache, mayHaveFileType } from "./validator/validator-cache.js";
|
|
5
5
|
import { TypeBoxValidator } from "./validator/index.js";
|
|
6
6
|
import { applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, coerceStringToStructure } from "./coerce.js";
|
|
7
|
+
import { Check, Clone, Create, Decode, Default, HasCodec } from "typebox/value";
|
|
7
8
|
import { Compile } from "typebox/compile";
|
|
8
9
|
import { Ref } from "typebox/type";
|
|
9
|
-
import { Check, Clone, Create, Decode, Default, HasCodec } from "typebox/value";
|
|
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-live.js
CHANGED
|
@@ -5,9 +5,9 @@ const require_type_coerce = require('./coerce.js');
|
|
|
5
5
|
const require_type_validator_validator_cache = require('./validator/validator-cache.js');
|
|
6
6
|
const require_type_validator_index = require('./validator/index.js');
|
|
7
7
|
const require_type_elysia_intersect = require('./elysia/intersect.js');
|
|
8
|
+
let typebox_value = require("typebox/value");
|
|
8
9
|
let typebox_compile = require("typebox/compile");
|
|
9
10
|
let typebox_type = require("typebox/type");
|
|
10
|
-
let typebox_value = require("typebox/value");
|
|
11
11
|
let typebox_system = require("typebox/system");
|
|
12
12
|
|
|
13
13
|
//#region src/type/bridge-live.ts
|
|
@@ -3,9 +3,9 @@ import { applyCoercions, coerceBody, coerceFormData, coerceQuery, coerceRoot, co
|
|
|
3
3
|
import { TypeBoxValidatorCache, mayHaveFileType } from "./validator/validator-cache.mjs";
|
|
4
4
|
import { TypeBoxValidator } from "./validator/index.mjs";
|
|
5
5
|
import { Intersect } from "./elysia/intersect.mjs";
|
|
6
|
+
import { Check, Clone, Create, Decode, Default, HasCodec } from "typebox/value";
|
|
6
7
|
import { Compile } from "typebox/compile";
|
|
7
8
|
import { Ref } from "typebox/type";
|
|
8
|
-
import { Check, Clone, Create, Decode, Default, HasCodec } from "typebox/value";
|
|
9
9
|
import { Settings } from "typebox/system";
|
|
10
10
|
|
|
11
11
|
//#region src/type/bridge-live.ts
|
package/dist/type/bridge.d.ts
CHANGED
|
@@ -3,15 +3,15 @@ import { hasTypes as hasTypes$1 } from "./utils.js";
|
|
|
3
3
|
import { TypeBoxValidatorCache as TypeBoxValidatorCache$1, mayHaveFileType as mayHaveFileType$1 } from "./validator/validator-cache.js";
|
|
4
4
|
import { TypeBoxValidator as TypeBoxValidator$1 } from "./validator/index.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
|
+
import { Check as Check$1, Clone as Clone$1, Create as Create$1, Decode as Decode$1, Default as Default$1, HasCodec as HasCodec$1 } from "typebox/value";
|
|
6
7
|
import { Compile as Compile$1 } from "typebox/compile";
|
|
7
8
|
import { Ref as Ref$1, TAny, TSchema } from "typebox/type";
|
|
8
|
-
import { Check as Check$1, Clone as Clone$1, Create as Create$1, Decode as Decode$2, 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$1;
|
|
15
15
|
applyCoercions: typeof applyCoercions$1;
|
|
16
16
|
TypeBoxValidator: TypeBoxValidator$1;
|
|
17
17
|
TypeBoxValidatorCache: TypeBoxValidatorCache$1;
|
|
@@ -31,7 +31,7 @@ interface TypeboxModule {
|
|
|
31
31
|
}
|
|
32
32
|
declare let Compile: typeof Compile$1;
|
|
33
33
|
declare let Create: typeof Create$1;
|
|
34
|
-
declare let Decode: typeof Decode$
|
|
34
|
+
declare let Decode: typeof Decode$1;
|
|
35
35
|
declare let applyCoercions: typeof applyCoercions$1;
|
|
36
36
|
declare let TypeBoxValidator: TypeBoxValidator$1;
|
|
37
37
|
type TypeBoxValidator<T extends TSchema = TAny> = TypeBoxValidator$1<T>;
|
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 | 3 | 10 |
|
|
20
|
+
declare const primitiveElysiaTypes: Set<1 | 2 | 6 | 3 | 10 | 14 | 13 | 11>;
|
|
21
21
|
declare const noEnumerable: {
|
|
22
22
|
readonly enumerable: false;
|
|
23
23
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { TypeboxNamespaces } from "./typebox-value.js";
|
|
2
|
-
import { Compile } from "typebox/compile";
|
|
3
|
-
import { Check, Clean, Clone, Create, Decode, DecodeUnsafe, Default, Encode, EncodeUnsafe, Errors, HasCodec } from "typebox/value";
|
|
4
2
|
import { Build, Compile as SchemaCompile } from "typebox/schema";
|
|
3
|
+
import { Check, Clean, Clone, Create, Decode, DecodeUnsafe, Default, Encode, EncodeUnsafe, Errors, HasCodec } from "typebox/value";
|
|
4
|
+
import { Compile } from "typebox/compile";
|
|
5
5
|
|
|
6
6
|
//#region src/type/typebox-value-live.d.ts
|
|
7
7
|
declare function injectTypebox(_typebox?: TypeboxNamespaces): void;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_runtime = require('../_virtual/_rolldown/runtime.js');
|
|
3
|
-
let
|
|
3
|
+
let typebox_schema = require("typebox/schema");
|
|
4
4
|
let typebox_value = require("typebox/value");
|
|
5
|
+
let typebox_compile = require("typebox/compile");
|
|
5
6
|
let typebox_system = require("typebox/system");
|
|
6
|
-
let typebox_schema = require("typebox/schema");
|
|
7
7
|
|
|
8
8
|
//#region src/type/typebox-value-live.ts
|
|
9
9
|
typebox_system.Settings.Set({ unionPrioritySort: false });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Compile } from "typebox/
|
|
1
|
+
import { Build, Compile as SchemaCompile } from "typebox/schema";
|
|
2
2
|
import { Check, Clean, Clone, Create, Decode, DecodeUnsafe, Default, Encode, EncodeUnsafe, Errors, HasCodec } from "typebox/value";
|
|
3
|
+
import { Compile } from "typebox/compile";
|
|
3
4
|
import { Settings } from "typebox/system";
|
|
4
|
-
import { Build, Compile as SchemaCompile } from "typebox/schema";
|
|
5
5
|
|
|
6
6
|
//#region src/type/typebox-value-live.ts
|
|
7
7
|
Settings.Set({ unionPrioritySort: false });
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as _$
|
|
2
|
-
import { Compile as Compile$1 } from "typebox/
|
|
1
|
+
import * as _$typebox_schema0 from "typebox/schema";
|
|
2
|
+
import { Build as Build$1, Compile as Compile$1 } from "typebox/schema";
|
|
3
3
|
import * as _$typebox_value0 from "typebox/value";
|
|
4
4
|
import { Check as Check$1, Clean as Clean$1, Clone as Clone$1, Create as Create$1, Decode as Decode$1, DecodeUnsafe as DecodeUnsafe$1, Default as Default$1, Encode as Encode$1, EncodeUnsafe as EncodeUnsafe$1, Errors as Errors$1, HasCodec as HasCodec$1 } from "typebox/value";
|
|
5
|
-
import * as _$
|
|
6
|
-
import {
|
|
5
|
+
import * as _$typebox_compile0 from "typebox/compile";
|
|
6
|
+
import { Compile as Compile$2 } from "typebox/compile";
|
|
7
7
|
|
|
8
8
|
//#region src/type/typebox-value.d.ts
|
|
9
9
|
interface TypeboxNamespaces {
|
|
@@ -22,9 +22,9 @@ declare let Encode: typeof Encode$1;
|
|
|
22
22
|
declare let EncodeUnsafe: typeof EncodeUnsafe$1;
|
|
23
23
|
declare let Errors: typeof Errors$1;
|
|
24
24
|
declare let HasCodec: typeof HasCodec$1;
|
|
25
|
-
declare let SchemaCompile: typeof Compile$
|
|
25
|
+
declare let SchemaCompile: typeof Compile$1;
|
|
26
26
|
declare let Build: typeof Build$1;
|
|
27
|
-
declare let Compile: typeof Compile$
|
|
27
|
+
declare let Compile: typeof Compile$2;
|
|
28
28
|
declare function injectTypebox(typebox: TypeboxNamespaces): void;
|
|
29
29
|
//#endregion
|
|
30
30
|
export { Build, Check, Clean, Clone, Compile, Create, Decode, DecodeUnsafe, Default, Encode, EncodeUnsafe, Errors, HasCodec, SchemaCompile, TypeboxNamespaces, injectTypebox };
|
|
@@ -7,6 +7,14 @@ declare function applyPrecomputed(defaults: Record<string, unknown>, value: Reco
|
|
|
7
7
|
declare function isEmittable(v: unknown, seen: Set<unknown>, top?: boolean): boolean;
|
|
8
8
|
declare function buildDefaultClonerSource(value: unknown): string | undefined;
|
|
9
9
|
declare function buildObjectDefaultMergeSource(defaults: Record<string, unknown>): string | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* How many emitted default-precompute sources have failed to compile.
|
|
12
|
+
*
|
|
13
|
+
* Build-time only. A non-zero count means codegen emitted source that
|
|
14
|
+
* `Function()` rejected, so those routes silently fell back to the interpreted
|
|
15
|
+
* default path — always a bug in this module, never a user error.
|
|
16
|
+
*/
|
|
17
|
+
declare const precomputeCompileFailures: () => number;
|
|
10
18
|
declare function createDefaultCloner(value: unknown): DefaultCloner | undefined;
|
|
11
19
|
declare function createObjectDefaultMerger(defaults: Record<string, unknown>): ObjectDefaultMerger | undefined;
|
|
12
20
|
declare function createMergerFromSource(source: string): ((value: any) => any) | undefined;
|
|
@@ -23,4 +31,4 @@ declare function verifyPreallocatableDefault(schema: TSchema, validate?: boolean
|
|
|
23
31
|
ms: string | undefined;
|
|
24
32
|
} | undefined;
|
|
25
33
|
//#endregion
|
|
26
|
-
export { DefaultProbeImpl, applyPrecomputed, buildDefaultClonerSource, buildObjectDefaultMergeSource, canonical, createDefaultCloner, createMergerFromSource, createObjectDefaultMerger, isEmittable, setDefaultProbeImpl, verifyPreallocatableDefault };
|
|
34
|
+
export { DefaultProbeImpl, applyPrecomputed, buildDefaultClonerSource, buildObjectDefaultMergeSource, canonical, createDefaultCloner, createMergerFromSource, createObjectDefaultMerger, isEmittable, precomputeCompileFailures, setDefaultProbeImpl, verifyPreallocatableDefault };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_constants = require('../../constants.js');
|
|
3
3
|
const require_utils = require('../../utils.js');
|
|
4
|
+
const require_universal_is_production = require('../../universal/is-production.js');
|
|
4
5
|
const require_type_typebox_value = require('../typebox-value.js');
|
|
5
6
|
|
|
6
7
|
//#region src/type/validator/default-precompute.ts
|
|
@@ -257,11 +258,21 @@ function buildObjectDefaultMergeSource(defaults) {
|
|
|
257
258
|
if (!root) return;
|
|
258
259
|
return `(function(){${helpers.join(";")};return ${root}})()`;
|
|
259
260
|
}
|
|
261
|
+
let compileFailures = 0;
|
|
262
|
+
/**
|
|
263
|
+
* How many emitted default-precompute sources have failed to compile.
|
|
264
|
+
*
|
|
265
|
+
* Build-time only. A non-zero count means codegen emitted source that
|
|
266
|
+
* `Function()` rejected, so those routes silently fell back to the interpreted
|
|
267
|
+
* default path — always a bug in this module, never a user error.
|
|
268
|
+
*/
|
|
269
|
+
const precomputeCompileFailures = () => compileFailures;
|
|
260
270
|
function fromSource(source) {
|
|
261
271
|
try {
|
|
262
272
|
return Function(`return ${source}`)();
|
|
263
|
-
} catch {
|
|
264
|
-
|
|
273
|
+
} catch (error) {
|
|
274
|
+
compileFailures++;
|
|
275
|
+
console.warn("[Elysia] default precompute emitted source that does not compile; falling back to the interpreted default path. This is a bug, please report it:", error, ...require_universal_is_production.isProduction() ? [] : ["\nsource: " + (source.length > 512 ? source.slice(0, 512) + "…" : source)]);
|
|
265
276
|
}
|
|
266
277
|
}
|
|
267
278
|
function createDefaultCloner(value) {
|
|
@@ -427,5 +438,6 @@ exports.createDefaultCloner = createDefaultCloner;
|
|
|
427
438
|
exports.createMergerFromSource = createMergerFromSource;
|
|
428
439
|
exports.createObjectDefaultMerger = createObjectDefaultMerger;
|
|
429
440
|
exports.isEmittable = isEmittable;
|
|
441
|
+
exports.precomputeCompileFailures = precomputeCompileFailures;
|
|
430
442
|
exports.setDefaultProbeImpl = setDefaultProbeImpl;
|
|
431
443
|
exports.verifyPreallocatableDefault = verifyPreallocatableDefault;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { dangerousKeys } from "../../constants.mjs";
|
|
2
2
|
import { nullObject } from "../../utils.mjs";
|
|
3
|
+
import { isProduction } from "../../universal/is-production.mjs";
|
|
3
4
|
import { Default } from "../typebox-value.mjs";
|
|
4
5
|
|
|
5
6
|
//#region src/type/validator/default-precompute.ts
|
|
@@ -256,11 +257,21 @@ function buildObjectDefaultMergeSource(defaults) {
|
|
|
256
257
|
if (!root) return;
|
|
257
258
|
return `(function(){${helpers.join(";")};return ${root}})()`;
|
|
258
259
|
}
|
|
260
|
+
let compileFailures = 0;
|
|
261
|
+
/**
|
|
262
|
+
* How many emitted default-precompute sources have failed to compile.
|
|
263
|
+
*
|
|
264
|
+
* Build-time only. A non-zero count means codegen emitted source that
|
|
265
|
+
* `Function()` rejected, so those routes silently fell back to the interpreted
|
|
266
|
+
* default path — always a bug in this module, never a user error.
|
|
267
|
+
*/
|
|
268
|
+
const precomputeCompileFailures = () => compileFailures;
|
|
259
269
|
function fromSource(source) {
|
|
260
270
|
try {
|
|
261
271
|
return Function(`return ${source}`)();
|
|
262
|
-
} catch {
|
|
263
|
-
|
|
272
|
+
} catch (error) {
|
|
273
|
+
compileFailures++;
|
|
274
|
+
console.warn("[Elysia] default precompute emitted source that does not compile; falling back to the interpreted default path. This is a bug, please report it:", error, ...isProduction() ? [] : ["\nsource: " + (source.length > 512 ? source.slice(0, 512) + "…" : source)]);
|
|
264
275
|
}
|
|
265
276
|
}
|
|
266
277
|
function createDefaultCloner(value) {
|
|
@@ -418,4 +429,4 @@ function verifyPreallocatableDefault(schema, validate = true) {
|
|
|
418
429
|
}
|
|
419
430
|
|
|
420
431
|
//#endregion
|
|
421
|
-
export { applyPrecomputed, buildDefaultClonerSource, buildObjectDefaultMergeSource, canonical, createDefaultCloner, createMergerFromSource, createObjectDefaultMerger, isEmittable, setDefaultProbeImpl, verifyPreallocatableDefault };
|
|
432
|
+
export { applyPrecomputed, buildDefaultClonerSource, buildObjectDefaultMergeSource, canonical, createDefaultCloner, createMergerFromSource, createObjectDefaultMerger, isEmittable, precomputeCompileFailures, setDefaultProbeImpl, verifyPreallocatableDefault };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { MaybePromise } from "../../types.js";
|
|
2
2
|
import { Validator as Validator$1, ValidatorOptions } from "../../validator/index.js";
|
|
3
3
|
import { TypeBoxValidatorCache, mayHaveFileType } from "./validator-cache.js";
|
|
4
|
-
import { Static, StaticDecode, StaticEncode, TAny, TSchema } from "typebox/type";
|
|
5
4
|
import { Validator } from "typebox/schema";
|
|
5
|
+
import { Static, StaticDecode, StaticEncode, TAny, TSchema } from "typebox/type";
|
|
6
6
|
import { TLocalizedValidationError } from "typebox/error";
|
|
7
7
|
|
|
8
8
|
//#region src/type/validator/index.d.ts
|
|
@@ -315,6 +315,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
315
315
|
if (defaults) {
|
|
316
316
|
this.precomputeSafe = true;
|
|
317
317
|
const objectTemplate = defaults.pod !== void 0 ? Object.freeze(defaults.pod) : void 0;
|
|
318
|
+
const failures = require_type_validator_default_precompute.precomputeCompileFailures();
|
|
318
319
|
this.#defaultFastPath = {
|
|
319
320
|
value: defaults.pd,
|
|
320
321
|
appliesToNull: defaults.pn,
|
|
@@ -322,6 +323,7 @@ var TypeBoxValidator = class extends require_validator_index.Validator {
|
|
|
322
323
|
clone: defaults.pd !== void 0 ? require_type_validator_default_precompute.createDefaultCloner(defaults.pd) : void 0,
|
|
323
324
|
merge: defaults.ms ? require_type_validator_default_precompute.createMergerFromSource(defaults.ms) : objectTemplate !== void 0 ? require_type_validator_default_precompute.createObjectDefaultMerger(objectTemplate) : void 0
|
|
324
325
|
};
|
|
326
|
+
if (require_type_validator_default_precompute.precomputeCompileFailures() !== failures) this.precomputeSafe = false;
|
|
325
327
|
} else {
|
|
326
328
|
this.precomputeSafe = false;
|
|
327
329
|
this.#defaultFastPath = void 0;
|
|
@@ -10,7 +10,7 @@ import { Validator } from "../../validator/index.mjs";
|
|
|
10
10
|
import { Evaluate, Intersect, Module } from "../typebox-type.mjs";
|
|
11
11
|
import { Check, Clean, Decode, DecodeUnsafe, Default, Encode, EncodeUnsafe, Errors, HasCodec, SchemaCompile } from "../typebox-value.mjs";
|
|
12
12
|
import { applyCoercions, buildCoercedFromPlan } from "../coerce.mjs";
|
|
13
|
-
import { applyPrecomputed, createDefaultCloner, createMergerFromSource, createObjectDefaultMerger, verifyPreallocatableDefault } from "./default-precompute.mjs";
|
|
13
|
+
import { applyPrecomputed, createDefaultCloner, createMergerFromSource, createObjectDefaultMerger, precomputeCompileFailures, verifyPreallocatableDefault } from "./default-precompute.mjs";
|
|
14
14
|
import { buildFindCustomError } from "./custom-error.mjs";
|
|
15
15
|
import { exactMirrorRequired, getExactMirror } from "./exact-mirror.mjs";
|
|
16
16
|
import { TypeBoxValidatorCache, mayHaveFileType } from "./validator-cache.mjs";
|
|
@@ -314,6 +314,7 @@ var TypeBoxValidator = class extends Validator {
|
|
|
314
314
|
if (defaults) {
|
|
315
315
|
this.precomputeSafe = true;
|
|
316
316
|
const objectTemplate = defaults.pod !== void 0 ? Object.freeze(defaults.pod) : void 0;
|
|
317
|
+
const failures = precomputeCompileFailures();
|
|
317
318
|
this.#defaultFastPath = {
|
|
318
319
|
value: defaults.pd,
|
|
319
320
|
appliesToNull: defaults.pn,
|
|
@@ -321,6 +322,7 @@ var TypeBoxValidator = class extends Validator {
|
|
|
321
322
|
clone: defaults.pd !== void 0 ? createDefaultCloner(defaults.pd) : void 0,
|
|
322
323
|
merge: defaults.ms ? createMergerFromSource(defaults.ms) : objectTemplate !== void 0 ? createObjectDefaultMerger(objectTemplate) : void 0
|
|
323
324
|
};
|
|
325
|
+
if (precomputeCompileFailures() !== failures) this.precomputeSafe = false;
|
|
324
326
|
} else {
|
|
325
327
|
this.precomputeSafe = false;
|
|
326
328
|
this.#defaultFastPath = void 0;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CoerceOption } from "../coerce.js";
|
|
2
|
-
import { TSchema } from "typebox/type";
|
|
3
2
|
import * as _$typebox_schema0 from "typebox/schema";
|
|
4
3
|
import { Validator } from "typebox/schema";
|
|
4
|
+
import { TSchema } from "typebox/type";
|
|
5
5
|
|
|
6
6
|
//#region src/type/validator/validator-cache.d.ts
|
|
7
7
|
interface SchemaMeta {
|