elysia 2.0.0-beta.13 → 2.0.0-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter/bun/index.d.ts +4 -2
- package/dist/adapter/bun/index.js +35 -38
- package/dist/adapter/bun/index.mjs +35 -39
- package/dist/adapter/utils.js +16 -21
- package/dist/adapter/utils.mjs +16 -21
- package/dist/base.d.ts +28 -0
- package/dist/base.js +109 -59
- package/dist/base.mjs +110 -60
- package/dist/compile/aot.js +14 -21
- package/dist/compile/aot.mjs +14 -21
- package/dist/compile/handler/frozen-validator.js +51 -42
- package/dist/compile/handler/frozen-validator.mjs +51 -42
- package/dist/compile/handler/index.js +57 -50
- package/dist/compile/handler/index.mjs +57 -50
- package/dist/compile/handler/jit.js +36 -26
- package/dist/compile/handler/jit.mjs +37 -27
- package/dist/compile/handler/params.js +2 -0
- package/dist/compile/handler/params.mjs +3 -1
- package/dist/compile/handler/utils.d.ts +2 -2
- package/dist/compile/handler/utils.js +115 -111
- package/dist/compile/handler/utils.mjs +115 -113
- package/dist/context.d.ts +3 -1
- package/dist/context.js +2 -0
- package/dist/context.mjs +3 -1
- package/dist/cookie/config.js +6 -7
- package/dist/cookie/config.mjs +6 -7
- package/dist/error.d.ts +6 -3
- package/dist/error.js +26 -28
- package/dist/error.mjs +26 -28
- package/dist/handler/fetch.js +2 -1
- package/dist/handler/fetch.mjs +3 -2
- package/dist/handler/utils.d.ts +3 -1
- package/dist/handler/utils.js +19 -1
- package/dist/handler/utils.mjs +17 -1
- package/dist/index.d.ts +3 -3
- package/dist/package.js +1 -1
- package/dist/package.mjs +1 -1
- package/dist/plugin/aot/core.js +4 -0
- package/dist/plugin/aot/core.mjs +4 -0
- package/dist/sucrose.js +60 -59
- package/dist/sucrose.mjs +60 -59
- package/dist/trace.js +6 -9
- package/dist/trace.mjs +6 -9
- package/dist/type/coerce-plan.js +41 -36
- package/dist/type/coerce-plan.mjs +41 -36
- package/dist/type/coerce.d.ts +1 -1
- package/dist/type/constants.d.ts +1 -1
- package/dist/type/elysia/cookie.js +8 -17
- package/dist/type/elysia/cookie.mjs +8 -17
- package/dist/type/elysia/date.js +6 -7
- package/dist/type/elysia/date.mjs +6 -7
- package/dist/type/elysia/numeric.js +8 -9
- package/dist/type/elysia/numeric.mjs +8 -9
- package/dist/type/elysia/problem.d.ts +20 -0
- package/dist/type/elysia/problem.js +25 -0
- package/dist/type/elysia/problem.mjs +24 -0
- package/dist/type/exports.d.ts +3 -2
- package/dist/type/exports.js +2 -0
- package/dist/type/exports.mjs +2 -1
- package/dist/type/index.js +2 -0
- package/dist/type/index.mjs +2 -0
- package/dist/type/validator/clean-safe.d.ts +1 -2
- package/dist/type/validator/clean-safe.js +0 -2
- package/dist/type/validator/clean-safe.mjs +1 -2
- package/dist/type/validator/custom-error.js +37 -26
- package/dist/type/validator/custom-error.mjs +37 -26
- package/dist/type/validator/default-precompute.js +24 -26
- package/dist/type/validator/default-precompute.mjs +24 -26
- package/dist/type/validator/exact-mirror.js +6 -8
- package/dist/type/validator/exact-mirror.mjs +6 -8
- package/dist/type/validator/index.js +64 -66
- package/dist/type/validator/index.mjs +65 -67
- package/dist/type/validator/validator-cache.d.ts +2 -2
- package/dist/type/validator/validator-cache.js +7 -10
- package/dist/type/validator/validator-cache.mjs +6 -9
- package/dist/types.d.ts +4 -3
- package/dist/universal/file.js +2 -6
- package/dist/universal/file.mjs +2 -6
- package/dist/utils.d.ts +11 -2
- package/dist/utils.js +85 -47
- package/dist/utils.mjs +82 -48
- package/dist/validator/index.js +14 -18
- package/dist/validator/index.mjs +14 -18
- package/dist/ws/context.js +9 -11
- package/dist/ws/context.mjs +9 -11
- package/dist/ws/parser.js +23 -20
- package/dist/ws/parser.mjs +23 -20
- package/dist/ws/route.js +76 -87
- package/dist/ws/route.mjs +76 -87
- package/package.json +5 -2
package/dist/sucrose.js
CHANGED
|
@@ -258,12 +258,6 @@ function findAlias(type, body, seen = /* @__PURE__ */ new Set()) {
|
|
|
258
258
|
return aliases;
|
|
259
259
|
}
|
|
260
260
|
/**
|
|
261
|
-
* Whitespace as JavaScript defines it, which is what `\s` matches: everything
|
|
262
|
-
* `String.prototype.trim` removes, not just the three characters that happen to
|
|
263
|
-
* appear in LF-formatted source.
|
|
264
|
-
*/
|
|
265
|
-
const isWhitespace = (char) => char === 32 || char >= 9 && char <= 13 || char === 160 || char === 5760 || char >= 8192 && char <= 8202 || char === 8232 || char === 8233 || char === 8239 || char === 8287 || char === 12288 || char === 65279;
|
|
266
|
-
/**
|
|
267
261
|
* Words that lex as an identifier but are operators, so a `/` after one opens a
|
|
268
262
|
* regex instead of dividing. Padded so a lookup cannot match a substring.
|
|
269
263
|
*/
|
|
@@ -274,7 +268,11 @@ const operatorKeyword = " typeof void delete in of instanceof new return case do
|
|
|
274
268
|
*/
|
|
275
269
|
function skipRegexLiteral(parameter, start, regexEnd) {
|
|
276
270
|
let previous = start - 1;
|
|
277
|
-
while (previous >= 0
|
|
271
|
+
while (previous >= 0) {
|
|
272
|
+
const char = parameter.charCodeAt(previous);
|
|
273
|
+
if (char === 32 || char >= 9 && char <= 13 || char === 160 || char === 5760 || char >= 8192 && char <= 8202 || char === 8232 || char === 8233 || char === 8239 || char === 8287 || char === 12288 || char === 65279) previous--;
|
|
274
|
+
else break;
|
|
275
|
+
}
|
|
278
276
|
if (previous >= 0) {
|
|
279
277
|
const char = parameter.charCodeAt(previous);
|
|
280
278
|
if (isIdentifierPart(char)) {
|
|
@@ -378,30 +376,13 @@ function markAllAccessed(i) {
|
|
|
378
376
|
}
|
|
379
377
|
const DEFAULT_CACHE_LIMIT = 1024;
|
|
380
378
|
const globalSourceCache = /* @__PURE__ */ new Map();
|
|
381
|
-
function sourceCache() {
|
|
382
|
-
const session = require_compile_aot.getCompilerSession();
|
|
383
|
-
return session?.external ? session.sucroseCache : globalSourceCache;
|
|
384
|
-
}
|
|
385
379
|
let functionCaches = /* @__PURE__ */ new WeakMap();
|
|
386
|
-
function
|
|
387
|
-
if (
|
|
388
|
-
if (caches.size >= DEFAULT_CACHE_LIMIT) require_utils.evictOldestHalf(caches);
|
|
389
|
-
caches.set(key, {
|
|
390
|
-
content,
|
|
391
|
-
inference
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
if (typeof event === "function") functionCaches.set(event, inference);
|
|
395
|
-
}
|
|
396
|
-
function clearCache() {
|
|
380
|
+
function clearSucroseCache(delay) {
|
|
381
|
+
if (delay === null) return;
|
|
397
382
|
globalSourceCache.clear();
|
|
398
383
|
require_compile_aot.getCompilerSession()?.sucroseCache.clear();
|
|
399
384
|
functionCaches = /* @__PURE__ */ new WeakMap();
|
|
400
385
|
}
|
|
401
|
-
function clearSucroseCache(delay) {
|
|
402
|
-
if (delay === null) return;
|
|
403
|
-
clearCache();
|
|
404
|
-
}
|
|
405
386
|
const mergeInference = (a, b) => ({
|
|
406
387
|
body: a.body || b.body,
|
|
407
388
|
cookie: a.cookie || b.cookie,
|
|
@@ -423,9 +404,6 @@ const emptyInference = Object.freeze(defaultSucrose());
|
|
|
423
404
|
function push(target, array) {
|
|
424
405
|
for (let i = 0; i < array.length; i++) target.push(array[i]);
|
|
425
406
|
}
|
|
426
|
-
function pushParse(target, array) {
|
|
427
|
-
for (let i = 0; i < array.length; i++) if (typeof array[i] === "function") target.push(array[i]);
|
|
428
|
-
}
|
|
429
407
|
const prefixKeywords = new Set([
|
|
430
408
|
"await",
|
|
431
409
|
"case",
|
|
@@ -444,32 +422,6 @@ const prefixKeywords = new Set([
|
|
|
444
422
|
]);
|
|
445
423
|
const isIdentifierStart = (char) => char >= 65 && char <= 90 || char >= 97 && char <= 122 || char === 36 || char === 95 || char >= 128;
|
|
446
424
|
const isIdentifierPart = (char) => isIdentifierStart(char) || char >= 48 && char <= 57;
|
|
447
|
-
function decodeIdentifier(value) {
|
|
448
|
-
if (!value.includes("\\u")) return value;
|
|
449
|
-
let decoded = "";
|
|
450
|
-
for (let i = 0; i < value.length; i++) {
|
|
451
|
-
if (value.charCodeAt(i) !== 92 || value.charCodeAt(i + 1) !== 117) {
|
|
452
|
-
decoded += value[i];
|
|
453
|
-
continue;
|
|
454
|
-
}
|
|
455
|
-
i += 2;
|
|
456
|
-
let hex;
|
|
457
|
-
if (value.charCodeAt(i) === 123) {
|
|
458
|
-
const end = value.indexOf("}", i + 1);
|
|
459
|
-
if (end === -1) return;
|
|
460
|
-
hex = value.slice(i + 1, end);
|
|
461
|
-
i = end;
|
|
462
|
-
} else {
|
|
463
|
-
hex = value.slice(i, i + 4);
|
|
464
|
-
if (hex.length !== 4) return;
|
|
465
|
-
i += 3;
|
|
466
|
-
}
|
|
467
|
-
const codePoint = Number.parseInt(hex, 16);
|
|
468
|
-
if (!Number.isFinite(codePoint) || codePoint > 1114111) return;
|
|
469
|
-
decoded += String.fromCodePoint(codePoint);
|
|
470
|
-
}
|
|
471
|
-
return decoded;
|
|
472
|
-
}
|
|
473
425
|
function scanTokens(source) {
|
|
474
426
|
const tokens = [];
|
|
475
427
|
let index = 0;
|
|
@@ -618,7 +570,44 @@ function scanTokens(source) {
|
|
|
618
570
|
}
|
|
619
571
|
break;
|
|
620
572
|
}
|
|
621
|
-
const
|
|
573
|
+
const identifierText = source.slice(start, index);
|
|
574
|
+
let value;
|
|
575
|
+
if (!identifierText.includes("\\u")) value = identifierText;
|
|
576
|
+
else {
|
|
577
|
+
let decoded = "";
|
|
578
|
+
let failed = false;
|
|
579
|
+
for (let i = 0; i < identifierText.length; i++) {
|
|
580
|
+
if (identifierText.charCodeAt(i) !== 92 || identifierText.charCodeAt(i + 1) !== 117) {
|
|
581
|
+
decoded += identifierText[i];
|
|
582
|
+
continue;
|
|
583
|
+
}
|
|
584
|
+
i += 2;
|
|
585
|
+
let hex;
|
|
586
|
+
if (identifierText.charCodeAt(i) === 123) {
|
|
587
|
+
const end = identifierText.indexOf("}", i + 1);
|
|
588
|
+
if (end === -1) {
|
|
589
|
+
failed = true;
|
|
590
|
+
break;
|
|
591
|
+
}
|
|
592
|
+
hex = identifierText.slice(i + 1, end);
|
|
593
|
+
i = end;
|
|
594
|
+
} else {
|
|
595
|
+
hex = identifierText.slice(i, i + 4);
|
|
596
|
+
if (hex.length !== 4) {
|
|
597
|
+
failed = true;
|
|
598
|
+
break;
|
|
599
|
+
}
|
|
600
|
+
i += 3;
|
|
601
|
+
}
|
|
602
|
+
const codePoint = Number.parseInt(hex, 16);
|
|
603
|
+
if (!Number.isFinite(codePoint) || codePoint > 1114111) {
|
|
604
|
+
failed = true;
|
|
605
|
+
break;
|
|
606
|
+
}
|
|
607
|
+
decoded += String.fromCodePoint(codePoint);
|
|
608
|
+
}
|
|
609
|
+
value = failed ? void 0 : decoded;
|
|
610
|
+
}
|
|
622
611
|
if (value === void 0) return false;
|
|
623
612
|
tokens.push({
|
|
624
613
|
k: "i",
|
|
@@ -864,14 +853,19 @@ function sucrose(handler, lifeCycle) {
|
|
|
864
853
|
if (lifeCycle) {
|
|
865
854
|
if (lifeCycle.request?.length) push(events, lifeCycle.request);
|
|
866
855
|
if (lifeCycle.beforeHandle?.length) push(events, lifeCycle.beforeHandle);
|
|
867
|
-
if (lifeCycle.parse?.length)
|
|
856
|
+
if (lifeCycle.parse?.length) {
|
|
857
|
+
const target = events;
|
|
858
|
+
const array = lifeCycle.parse;
|
|
859
|
+
for (let i = 0; i < array.length; i++) if (typeof array[i] === "function") target.push(array[i]);
|
|
860
|
+
}
|
|
868
861
|
if (lifeCycle.error?.length) push(events, lifeCycle.error);
|
|
869
862
|
if (lifeCycle.transform?.length) push(events, lifeCycle.transform);
|
|
870
863
|
if (lifeCycle.afterHandle?.length) push(events, lifeCycle.afterHandle);
|
|
871
864
|
if (lifeCycle.mapResponse?.length) push(events, lifeCycle.mapResponse);
|
|
872
865
|
if (lifeCycle.afterResponse?.length) push(events, lifeCycle.afterResponse);
|
|
873
866
|
}
|
|
874
|
-
const
|
|
867
|
+
const session = require_compile_aot.getCompilerSession();
|
|
868
|
+
const caches = session?.external ? session.sucroseCache : globalSourceCache;
|
|
875
869
|
for (let i = 0; i < events.length; i++) {
|
|
876
870
|
const event = events[i];
|
|
877
871
|
if (!event) continue;
|
|
@@ -894,7 +888,14 @@ function sucrose(handler, lifeCycle) {
|
|
|
894
888
|
if (typeof event === "function") functionCaches.set(event, inferred);
|
|
895
889
|
} else {
|
|
896
890
|
inferred = Object.freeze(inferFunction(content));
|
|
897
|
-
|
|
891
|
+
if (!cached || cached.content !== content) {
|
|
892
|
+
if (caches.size >= DEFAULT_CACHE_LIMIT) require_utils.evictOldestHalf(caches);
|
|
893
|
+
caches.set(key, {
|
|
894
|
+
content,
|
|
895
|
+
inference: inferred
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
if (typeof event === "function") functionCaches.set(event, inferred);
|
|
898
899
|
}
|
|
899
900
|
}
|
|
900
901
|
if (inference) {
|
package/dist/sucrose.mjs
CHANGED
|
@@ -257,12 +257,6 @@ function findAlias(type, body, seen = /* @__PURE__ */ new Set()) {
|
|
|
257
257
|
return aliases;
|
|
258
258
|
}
|
|
259
259
|
/**
|
|
260
|
-
* Whitespace as JavaScript defines it, which is what `\s` matches: everything
|
|
261
|
-
* `String.prototype.trim` removes, not just the three characters that happen to
|
|
262
|
-
* appear in LF-formatted source.
|
|
263
|
-
*/
|
|
264
|
-
const isWhitespace = (char) => char === 32 || char >= 9 && char <= 13 || char === 160 || char === 5760 || char >= 8192 && char <= 8202 || char === 8232 || char === 8233 || char === 8239 || char === 8287 || char === 12288 || char === 65279;
|
|
265
|
-
/**
|
|
266
260
|
* Words that lex as an identifier but are operators, so a `/` after one opens a
|
|
267
261
|
* regex instead of dividing. Padded so a lookup cannot match a substring.
|
|
268
262
|
*/
|
|
@@ -273,7 +267,11 @@ const operatorKeyword = " typeof void delete in of instanceof new return case do
|
|
|
273
267
|
*/
|
|
274
268
|
function skipRegexLiteral(parameter, start, regexEnd) {
|
|
275
269
|
let previous = start - 1;
|
|
276
|
-
while (previous >= 0
|
|
270
|
+
while (previous >= 0) {
|
|
271
|
+
const char = parameter.charCodeAt(previous);
|
|
272
|
+
if (char === 32 || char >= 9 && char <= 13 || char === 160 || char === 5760 || char >= 8192 && char <= 8202 || char === 8232 || char === 8233 || char === 8239 || char === 8287 || char === 12288 || char === 65279) previous--;
|
|
273
|
+
else break;
|
|
274
|
+
}
|
|
277
275
|
if (previous >= 0) {
|
|
278
276
|
const char = parameter.charCodeAt(previous);
|
|
279
277
|
if (isIdentifierPart(char)) {
|
|
@@ -377,30 +375,13 @@ function markAllAccessed(i) {
|
|
|
377
375
|
}
|
|
378
376
|
const DEFAULT_CACHE_LIMIT = 1024;
|
|
379
377
|
const globalSourceCache = /* @__PURE__ */ new Map();
|
|
380
|
-
function sourceCache() {
|
|
381
|
-
const session = getCompilerSession();
|
|
382
|
-
return session?.external ? session.sucroseCache : globalSourceCache;
|
|
383
|
-
}
|
|
384
378
|
let functionCaches = /* @__PURE__ */ new WeakMap();
|
|
385
|
-
function
|
|
386
|
-
if (
|
|
387
|
-
if (caches.size >= DEFAULT_CACHE_LIMIT) evictOldestHalf(caches);
|
|
388
|
-
caches.set(key, {
|
|
389
|
-
content,
|
|
390
|
-
inference
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
if (typeof event === "function") functionCaches.set(event, inference);
|
|
394
|
-
}
|
|
395
|
-
function clearCache() {
|
|
379
|
+
function clearSucroseCache(delay) {
|
|
380
|
+
if (delay === null) return;
|
|
396
381
|
globalSourceCache.clear();
|
|
397
382
|
getCompilerSession()?.sucroseCache.clear();
|
|
398
383
|
functionCaches = /* @__PURE__ */ new WeakMap();
|
|
399
384
|
}
|
|
400
|
-
function clearSucroseCache(delay) {
|
|
401
|
-
if (delay === null) return;
|
|
402
|
-
clearCache();
|
|
403
|
-
}
|
|
404
385
|
const mergeInference = (a, b) => ({
|
|
405
386
|
body: a.body || b.body,
|
|
406
387
|
cookie: a.cookie || b.cookie,
|
|
@@ -422,9 +403,6 @@ const emptyInference = Object.freeze(defaultSucrose());
|
|
|
422
403
|
function push(target, array) {
|
|
423
404
|
for (let i = 0; i < array.length; i++) target.push(array[i]);
|
|
424
405
|
}
|
|
425
|
-
function pushParse(target, array) {
|
|
426
|
-
for (let i = 0; i < array.length; i++) if (typeof array[i] === "function") target.push(array[i]);
|
|
427
|
-
}
|
|
428
406
|
const prefixKeywords = new Set([
|
|
429
407
|
"await",
|
|
430
408
|
"case",
|
|
@@ -443,32 +421,6 @@ const prefixKeywords = new Set([
|
|
|
443
421
|
]);
|
|
444
422
|
const isIdentifierStart = (char) => char >= 65 && char <= 90 || char >= 97 && char <= 122 || char === 36 || char === 95 || char >= 128;
|
|
445
423
|
const isIdentifierPart = (char) => isIdentifierStart(char) || char >= 48 && char <= 57;
|
|
446
|
-
function decodeIdentifier(value) {
|
|
447
|
-
if (!value.includes("\\u")) return value;
|
|
448
|
-
let decoded = "";
|
|
449
|
-
for (let i = 0; i < value.length; i++) {
|
|
450
|
-
if (value.charCodeAt(i) !== 92 || value.charCodeAt(i + 1) !== 117) {
|
|
451
|
-
decoded += value[i];
|
|
452
|
-
continue;
|
|
453
|
-
}
|
|
454
|
-
i += 2;
|
|
455
|
-
let hex;
|
|
456
|
-
if (value.charCodeAt(i) === 123) {
|
|
457
|
-
const end = value.indexOf("}", i + 1);
|
|
458
|
-
if (end === -1) return;
|
|
459
|
-
hex = value.slice(i + 1, end);
|
|
460
|
-
i = end;
|
|
461
|
-
} else {
|
|
462
|
-
hex = value.slice(i, i + 4);
|
|
463
|
-
if (hex.length !== 4) return;
|
|
464
|
-
i += 3;
|
|
465
|
-
}
|
|
466
|
-
const codePoint = Number.parseInt(hex, 16);
|
|
467
|
-
if (!Number.isFinite(codePoint) || codePoint > 1114111) return;
|
|
468
|
-
decoded += String.fromCodePoint(codePoint);
|
|
469
|
-
}
|
|
470
|
-
return decoded;
|
|
471
|
-
}
|
|
472
424
|
function scanTokens(source) {
|
|
473
425
|
const tokens = [];
|
|
474
426
|
let index = 0;
|
|
@@ -617,7 +569,44 @@ function scanTokens(source) {
|
|
|
617
569
|
}
|
|
618
570
|
break;
|
|
619
571
|
}
|
|
620
|
-
const
|
|
572
|
+
const identifierText = source.slice(start, index);
|
|
573
|
+
let value;
|
|
574
|
+
if (!identifierText.includes("\\u")) value = identifierText;
|
|
575
|
+
else {
|
|
576
|
+
let decoded = "";
|
|
577
|
+
let failed = false;
|
|
578
|
+
for (let i = 0; i < identifierText.length; i++) {
|
|
579
|
+
if (identifierText.charCodeAt(i) !== 92 || identifierText.charCodeAt(i + 1) !== 117) {
|
|
580
|
+
decoded += identifierText[i];
|
|
581
|
+
continue;
|
|
582
|
+
}
|
|
583
|
+
i += 2;
|
|
584
|
+
let hex;
|
|
585
|
+
if (identifierText.charCodeAt(i) === 123) {
|
|
586
|
+
const end = identifierText.indexOf("}", i + 1);
|
|
587
|
+
if (end === -1) {
|
|
588
|
+
failed = true;
|
|
589
|
+
break;
|
|
590
|
+
}
|
|
591
|
+
hex = identifierText.slice(i + 1, end);
|
|
592
|
+
i = end;
|
|
593
|
+
} else {
|
|
594
|
+
hex = identifierText.slice(i, i + 4);
|
|
595
|
+
if (hex.length !== 4) {
|
|
596
|
+
failed = true;
|
|
597
|
+
break;
|
|
598
|
+
}
|
|
599
|
+
i += 3;
|
|
600
|
+
}
|
|
601
|
+
const codePoint = Number.parseInt(hex, 16);
|
|
602
|
+
if (!Number.isFinite(codePoint) || codePoint > 1114111) {
|
|
603
|
+
failed = true;
|
|
604
|
+
break;
|
|
605
|
+
}
|
|
606
|
+
decoded += String.fromCodePoint(codePoint);
|
|
607
|
+
}
|
|
608
|
+
value = failed ? void 0 : decoded;
|
|
609
|
+
}
|
|
621
610
|
if (value === void 0) return false;
|
|
622
611
|
tokens.push({
|
|
623
612
|
k: "i",
|
|
@@ -863,14 +852,19 @@ function sucrose(handler, lifeCycle) {
|
|
|
863
852
|
if (lifeCycle) {
|
|
864
853
|
if (lifeCycle.request?.length) push(events, lifeCycle.request);
|
|
865
854
|
if (lifeCycle.beforeHandle?.length) push(events, lifeCycle.beforeHandle);
|
|
866
|
-
if (lifeCycle.parse?.length)
|
|
855
|
+
if (lifeCycle.parse?.length) {
|
|
856
|
+
const target = events;
|
|
857
|
+
const array = lifeCycle.parse;
|
|
858
|
+
for (let i = 0; i < array.length; i++) if (typeof array[i] === "function") target.push(array[i]);
|
|
859
|
+
}
|
|
867
860
|
if (lifeCycle.error?.length) push(events, lifeCycle.error);
|
|
868
861
|
if (lifeCycle.transform?.length) push(events, lifeCycle.transform);
|
|
869
862
|
if (lifeCycle.afterHandle?.length) push(events, lifeCycle.afterHandle);
|
|
870
863
|
if (lifeCycle.mapResponse?.length) push(events, lifeCycle.mapResponse);
|
|
871
864
|
if (lifeCycle.afterResponse?.length) push(events, lifeCycle.afterResponse);
|
|
872
865
|
}
|
|
873
|
-
const
|
|
866
|
+
const session = getCompilerSession();
|
|
867
|
+
const caches = session?.external ? session.sucroseCache : globalSourceCache;
|
|
874
868
|
for (let i = 0; i < events.length; i++) {
|
|
875
869
|
const event = events[i];
|
|
876
870
|
if (!event) continue;
|
|
@@ -893,7 +887,14 @@ function sucrose(handler, lifeCycle) {
|
|
|
893
887
|
if (typeof event === "function") functionCaches.set(event, inferred);
|
|
894
888
|
} else {
|
|
895
889
|
inferred = Object.freeze(inferFunction(content));
|
|
896
|
-
|
|
890
|
+
if (!cached || cached.content !== content) {
|
|
891
|
+
if (caches.size >= DEFAULT_CACHE_LIMIT) evictOldestHalf(caches);
|
|
892
|
+
caches.set(key, {
|
|
893
|
+
content,
|
|
894
|
+
inference: inferred
|
|
895
|
+
});
|
|
896
|
+
}
|
|
897
|
+
if (typeof event === "function") functionCaches.set(event, inferred);
|
|
897
898
|
}
|
|
898
899
|
}
|
|
899
900
|
if (inference) {
|
package/dist/trace.js
CHANGED
|
@@ -188,7 +188,12 @@ var TraceRecorder = class {
|
|
|
188
188
|
return slot.#end();
|
|
189
189
|
},
|
|
190
190
|
get error() {
|
|
191
|
-
return slot
|
|
191
|
+
if (slot.errorPromise) return slot.errorPromise;
|
|
192
|
+
if (slot.ended) return slot.errorPromise = Promise.resolve(slot.endError);
|
|
193
|
+
const { promise, resolve } = withResolvers();
|
|
194
|
+
slot.errorPromise = promise;
|
|
195
|
+
slot.errorResolve = resolve;
|
|
196
|
+
return promise;
|
|
192
197
|
},
|
|
193
198
|
onEvent(callback) {
|
|
194
199
|
if (callback) (slot.callbacksChild ??= []).push(callback);
|
|
@@ -207,14 +212,6 @@ var TraceRecorder = class {
|
|
|
207
212
|
this.endResolve = resolve;
|
|
208
213
|
return promise;
|
|
209
214
|
}
|
|
210
|
-
#error() {
|
|
211
|
-
if (this.errorPromise) return this.errorPromise;
|
|
212
|
-
if (this.ended) return this.errorPromise = Promise.resolve(this.endError);
|
|
213
|
-
const { promise, resolve } = withResolvers();
|
|
214
|
-
this.errorPromise = promise;
|
|
215
|
-
this.errorResolve = resolve;
|
|
216
|
-
return promise;
|
|
217
|
-
}
|
|
218
215
|
begin(process) {
|
|
219
216
|
this.begun = process;
|
|
220
217
|
this.remaining = process.total ?? 0;
|
package/dist/trace.mjs
CHANGED
|
@@ -187,7 +187,12 @@ var TraceRecorder = class {
|
|
|
187
187
|
return slot.#end();
|
|
188
188
|
},
|
|
189
189
|
get error() {
|
|
190
|
-
return slot
|
|
190
|
+
if (slot.errorPromise) return slot.errorPromise;
|
|
191
|
+
if (slot.ended) return slot.errorPromise = Promise.resolve(slot.endError);
|
|
192
|
+
const { promise, resolve } = withResolvers();
|
|
193
|
+
slot.errorPromise = promise;
|
|
194
|
+
slot.errorResolve = resolve;
|
|
195
|
+
return promise;
|
|
191
196
|
},
|
|
192
197
|
onEvent(callback) {
|
|
193
198
|
if (callback) (slot.callbacksChild ??= []).push(callback);
|
|
@@ -206,14 +211,6 @@ var TraceRecorder = class {
|
|
|
206
211
|
this.endResolve = resolve;
|
|
207
212
|
return promise;
|
|
208
213
|
}
|
|
209
|
-
#error() {
|
|
210
|
-
if (this.errorPromise) return this.errorPromise;
|
|
211
|
-
if (this.ended) return this.errorPromise = Promise.resolve(this.endError);
|
|
212
|
-
const { promise, resolve } = withResolvers();
|
|
213
|
-
this.errorPromise = promise;
|
|
214
|
-
this.errorResolve = resolve;
|
|
215
|
-
return promise;
|
|
216
|
-
}
|
|
217
214
|
begin(process) {
|
|
218
215
|
this.begun = process;
|
|
219
216
|
this.remaining = process.total ?? 0;
|
package/dist/type/coerce-plan.js
CHANGED
|
@@ -24,28 +24,55 @@ const isCoerceUnion = (x) => Array.isArray(x.u);
|
|
|
24
24
|
const icPlaceholder = () => {
|
|
25
25
|
throw new Error("[elysia] ObjectString/ArrayString shape placeholder was not reconstructed. missing inner-codec (ic) entry");
|
|
26
26
|
};
|
|
27
|
-
function ObjectStringShape(property, _options) {
|
|
28
|
-
const [{ properties, ...constraints }, meta] = require_type_elysia_utils.getMeta(_options ?? require_utils.nullObject());
|
|
29
|
-
const object = require_type_elysia_object.ObjectType(property, constraints);
|
|
30
|
-
const objectString = require_type_typebox_type.Decode(require_type_typebox_type.Refine(require_type_elysia_string.StringType(), icPlaceholder, () => "must be an object"), icPlaceholder);
|
|
31
|
-
return require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.ObjectString, require_type_elysia_union.Union([object, objectString], meta));
|
|
32
|
-
}
|
|
33
|
-
function ArrayStringShape(property, _options) {
|
|
34
|
-
const [constraints, meta] = require_type_elysia_utils.getMeta(_options ?? require_utils.nullObject());
|
|
35
|
-
const array = require_type_elysia_array.ArrayType(property, constraints);
|
|
36
|
-
const arrayString = require_type_typebox_type.Decode(require_type_typebox_type.Refine(require_type_elysia_string.StringType(), icPlaceholder, () => "must be an array"), icPlaceholder);
|
|
37
|
-
return require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.ArrayString, require_type_elysia_union.Union([array, arrayString], meta));
|
|
38
|
-
}
|
|
39
27
|
const rebuildObjStrShape = (original, site) => {
|
|
40
28
|
const { type, ...rest } = original;
|
|
41
|
-
|
|
29
|
+
let node;
|
|
30
|
+
if (site.os === require_type_constants.ELYSIA_TYPES.ObjectString) {
|
|
31
|
+
const property = rest.properties ?? require_utils.nullObject();
|
|
32
|
+
const [{ properties, ...constraints }, meta] = require_type_elysia_utils.getMeta(rest ?? require_utils.nullObject());
|
|
33
|
+
const object = require_type_elysia_object.ObjectType(property, constraints);
|
|
34
|
+
const objectString = require_type_typebox_type.Decode(require_type_typebox_type.Refine(require_type_elysia_string.StringType(), icPlaceholder, () => "must be an object"), icPlaceholder);
|
|
35
|
+
node = require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.ObjectString, require_type_elysia_union.Union([object, objectString], meta));
|
|
36
|
+
} else {
|
|
37
|
+
const property = rest.items ?? require_utils.nullObject();
|
|
38
|
+
const [constraints, meta] = require_type_elysia_utils.getMeta(rest ?? require_utils.nullObject());
|
|
39
|
+
const array = require_type_elysia_array.ArrayType(property, constraints);
|
|
40
|
+
const arrayString = require_type_typebox_type.Decode(require_type_typebox_type.Refine(require_type_elysia_string.StringType(), icPlaceholder, () => "must be an array"), icPlaceholder);
|
|
41
|
+
node = require_type_elysia_utils.elyType(require_type_constants.ELYSIA_TYPES.ArrayString, require_type_elysia_union.Union([array, arrayString], meta));
|
|
42
|
+
}
|
|
42
43
|
if ("o" in site) return Object.defineProperty(node, "~optional", {
|
|
43
44
|
value: site.o,
|
|
44
45
|
enumerable: false
|
|
45
46
|
});
|
|
46
47
|
return node;
|
|
47
48
|
};
|
|
48
|
-
const buildCoerceNode = (original, node, seen, objStr) =>
|
|
49
|
+
const buildCoerceNode = (original, node, seen, objStr) => {
|
|
50
|
+
if (isCoerceLeaf(node)) {
|
|
51
|
+
const key = node.e + (node.c ? JSON.stringify(node.c) : "");
|
|
52
|
+
let leaf;
|
|
53
|
+
if (seen.has(key)) leaf = COERCE_LEAF_CTOR[node.e](node.c);
|
|
54
|
+
else {
|
|
55
|
+
seen.add(key);
|
|
56
|
+
leaf = require_type_shared.coerceLeafCache.get(key);
|
|
57
|
+
if (leaf === void 0) {
|
|
58
|
+
leaf = COERCE_LEAF_CTOR[node.e](node.c);
|
|
59
|
+
if (require_type_shared.coerceLeafCache.size >= 1024) require_utils.evictOldestHalf(require_type_shared.coerceLeafCache);
|
|
60
|
+
require_type_shared.coerceLeafCache.set(key, leaf);
|
|
61
|
+
} else if (require_type_shared.coerceLeafCache.size >= 1024) {
|
|
62
|
+
require_type_shared.coerceLeafCache.delete(key);
|
|
63
|
+
require_type_shared.coerceLeafCache.set(key, leaf);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if ("o" in node) return Object.defineProperty(Object.create(leaf), "~optional", {
|
|
67
|
+
value: node.o,
|
|
68
|
+
enumerable: false
|
|
69
|
+
});
|
|
70
|
+
return leaf;
|
|
71
|
+
}
|
|
72
|
+
if (isCoerceObjStr(node)) return objStr(original, node);
|
|
73
|
+
if (isCoerceUnion(node)) return rebuildUnion(original, node, seen, objStr);
|
|
74
|
+
return buildCoercedFromPlan(original, node, seen, objStr);
|
|
75
|
+
};
|
|
49
76
|
function cloneSchemaNode(original) {
|
|
50
77
|
const out = Object.create(Object.getPrototypeOf(original));
|
|
51
78
|
for (const k in original) out[k] = original[k];
|
|
@@ -62,28 +89,6 @@ function rebuildUnion(original, site, seen, objStr) {
|
|
|
62
89
|
}
|
|
63
90
|
/** @internal */
|
|
64
91
|
const COERCE_LEAF_CACHE_LIMIT = 1024;
|
|
65
|
-
function coerceLeaf(leaf, seen) {
|
|
66
|
-
const key = leaf.e + (leaf.c ? JSON.stringify(leaf.c) : "");
|
|
67
|
-
let node;
|
|
68
|
-
if (seen.has(key)) node = COERCE_LEAF_CTOR[leaf.e](leaf.c);
|
|
69
|
-
else {
|
|
70
|
-
seen.add(key);
|
|
71
|
-
node = require_type_shared.coerceLeafCache.get(key);
|
|
72
|
-
if (node === void 0) {
|
|
73
|
-
node = COERCE_LEAF_CTOR[leaf.e](leaf.c);
|
|
74
|
-
if (require_type_shared.coerceLeafCache.size >= 1024) require_utils.evictOldestHalf(require_type_shared.coerceLeafCache);
|
|
75
|
-
require_type_shared.coerceLeafCache.set(key, node);
|
|
76
|
-
} else if (require_type_shared.coerceLeafCache.size >= 1024) {
|
|
77
|
-
require_type_shared.coerceLeafCache.delete(key);
|
|
78
|
-
require_type_shared.coerceLeafCache.set(key, node);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
if ("o" in leaf) return Object.defineProperty(Object.create(node), "~optional", {
|
|
82
|
-
value: leaf.o,
|
|
83
|
-
enumerable: false
|
|
84
|
-
});
|
|
85
|
-
return node;
|
|
86
|
-
}
|
|
87
92
|
function buildCoercedFromPlan(original, plan, seen = /* @__PURE__ */ new Set(), objStr = rebuildObjStrShape) {
|
|
88
93
|
if (isCoerceLeaf(plan) || isCoerceObjStr(plan) || isCoerceUnion(plan)) return buildCoerceNode(original, plan, seen, objStr);
|
|
89
94
|
const out = cloneSchemaNode(original);
|
|
@@ -23,28 +23,55 @@ const isCoerceUnion = (x) => Array.isArray(x.u);
|
|
|
23
23
|
const icPlaceholder = () => {
|
|
24
24
|
throw new Error("[elysia] ObjectString/ArrayString shape placeholder was not reconstructed. missing inner-codec (ic) entry");
|
|
25
25
|
};
|
|
26
|
-
function ObjectStringShape(property, _options) {
|
|
27
|
-
const [{ properties, ...constraints }, meta] = getMeta(_options ?? nullObject());
|
|
28
|
-
const object = ObjectType(property, constraints);
|
|
29
|
-
const objectString = Decode(Refine(StringType(), icPlaceholder, () => "must be an object"), icPlaceholder);
|
|
30
|
-
return elyType(ELYSIA_TYPES.ObjectString, Union([object, objectString], meta));
|
|
31
|
-
}
|
|
32
|
-
function ArrayStringShape(property, _options) {
|
|
33
|
-
const [constraints, meta] = getMeta(_options ?? nullObject());
|
|
34
|
-
const array = ArrayType(property, constraints);
|
|
35
|
-
const arrayString = Decode(Refine(StringType(), icPlaceholder, () => "must be an array"), icPlaceholder);
|
|
36
|
-
return elyType(ELYSIA_TYPES.ArrayString, Union([array, arrayString], meta));
|
|
37
|
-
}
|
|
38
26
|
const rebuildObjStrShape = (original, site) => {
|
|
39
27
|
const { type, ...rest } = original;
|
|
40
|
-
|
|
28
|
+
let node;
|
|
29
|
+
if (site.os === ELYSIA_TYPES.ObjectString) {
|
|
30
|
+
const property = rest.properties ?? nullObject();
|
|
31
|
+
const [{ properties, ...constraints }, meta] = getMeta(rest ?? nullObject());
|
|
32
|
+
const object = ObjectType(property, constraints);
|
|
33
|
+
const objectString = Decode(Refine(StringType(), icPlaceholder, () => "must be an object"), icPlaceholder);
|
|
34
|
+
node = elyType(ELYSIA_TYPES.ObjectString, Union([object, objectString], meta));
|
|
35
|
+
} else {
|
|
36
|
+
const property = rest.items ?? nullObject();
|
|
37
|
+
const [constraints, meta] = getMeta(rest ?? nullObject());
|
|
38
|
+
const array = ArrayType(property, constraints);
|
|
39
|
+
const arrayString = Decode(Refine(StringType(), icPlaceholder, () => "must be an array"), icPlaceholder);
|
|
40
|
+
node = elyType(ELYSIA_TYPES.ArrayString, Union([array, arrayString], meta));
|
|
41
|
+
}
|
|
41
42
|
if ("o" in site) return Object.defineProperty(node, "~optional", {
|
|
42
43
|
value: site.o,
|
|
43
44
|
enumerable: false
|
|
44
45
|
});
|
|
45
46
|
return node;
|
|
46
47
|
};
|
|
47
|
-
const buildCoerceNode = (original, node, seen, objStr) =>
|
|
48
|
+
const buildCoerceNode = (original, node, seen, objStr) => {
|
|
49
|
+
if (isCoerceLeaf(node)) {
|
|
50
|
+
const key = node.e + (node.c ? JSON.stringify(node.c) : "");
|
|
51
|
+
let leaf;
|
|
52
|
+
if (seen.has(key)) leaf = COERCE_LEAF_CTOR[node.e](node.c);
|
|
53
|
+
else {
|
|
54
|
+
seen.add(key);
|
|
55
|
+
leaf = coerceLeafCache.get(key);
|
|
56
|
+
if (leaf === void 0) {
|
|
57
|
+
leaf = COERCE_LEAF_CTOR[node.e](node.c);
|
|
58
|
+
if (coerceLeafCache.size >= 1024) evictOldestHalf(coerceLeafCache);
|
|
59
|
+
coerceLeafCache.set(key, leaf);
|
|
60
|
+
} else if (coerceLeafCache.size >= 1024) {
|
|
61
|
+
coerceLeafCache.delete(key);
|
|
62
|
+
coerceLeafCache.set(key, leaf);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if ("o" in node) return Object.defineProperty(Object.create(leaf), "~optional", {
|
|
66
|
+
value: node.o,
|
|
67
|
+
enumerable: false
|
|
68
|
+
});
|
|
69
|
+
return leaf;
|
|
70
|
+
}
|
|
71
|
+
if (isCoerceObjStr(node)) return objStr(original, node);
|
|
72
|
+
if (isCoerceUnion(node)) return rebuildUnion(original, node, seen, objStr);
|
|
73
|
+
return buildCoercedFromPlan(original, node, seen, objStr);
|
|
74
|
+
};
|
|
48
75
|
function cloneSchemaNode(original) {
|
|
49
76
|
const out = Object.create(Object.getPrototypeOf(original));
|
|
50
77
|
for (const k in original) out[k] = original[k];
|
|
@@ -61,28 +88,6 @@ function rebuildUnion(original, site, seen, objStr) {
|
|
|
61
88
|
}
|
|
62
89
|
/** @internal */
|
|
63
90
|
const COERCE_LEAF_CACHE_LIMIT = 1024;
|
|
64
|
-
function coerceLeaf(leaf, seen) {
|
|
65
|
-
const key = leaf.e + (leaf.c ? JSON.stringify(leaf.c) : "");
|
|
66
|
-
let node;
|
|
67
|
-
if (seen.has(key)) node = COERCE_LEAF_CTOR[leaf.e](leaf.c);
|
|
68
|
-
else {
|
|
69
|
-
seen.add(key);
|
|
70
|
-
node = coerceLeafCache.get(key);
|
|
71
|
-
if (node === void 0) {
|
|
72
|
-
node = COERCE_LEAF_CTOR[leaf.e](leaf.c);
|
|
73
|
-
if (coerceLeafCache.size >= 1024) evictOldestHalf(coerceLeafCache);
|
|
74
|
-
coerceLeafCache.set(key, node);
|
|
75
|
-
} else if (coerceLeafCache.size >= 1024) {
|
|
76
|
-
coerceLeafCache.delete(key);
|
|
77
|
-
coerceLeafCache.set(key, node);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if ("o" in leaf) return Object.defineProperty(Object.create(node), "~optional", {
|
|
81
|
-
value: leaf.o,
|
|
82
|
-
enumerable: false
|
|
83
|
-
});
|
|
84
|
-
return node;
|
|
85
|
-
}
|
|
86
91
|
function buildCoercedFromPlan(original, plan, seen = /* @__PURE__ */ new Set(), objStr = rebuildObjStrShape) {
|
|
87
92
|
if (isCoerceLeaf(plan) || isCoerceObjStr(plan) || isCoerceUnion(plan)) return buildCoerceNode(original, plan, seen, objStr);
|
|
88
93
|
const out = cloneSchemaNode(original);
|
package/dist/type/coerce.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ declare const coerceQuery: () => CoerceOption[];
|
|
|
34
34
|
declare const coerceBody: () => CoerceOption[];
|
|
35
35
|
declare const coerceFormData: () => CoerceOption[];
|
|
36
36
|
declare const coerceStringToStructure: () => CoerceOption[];
|
|
37
|
-
declare function applyCoercions(schema: BaseSchema | TSchema, coerces: CoerceOption[] | undefined):
|
|
37
|
+
declare function applyCoercions(schema: BaseSchema | TSchema, coerces: CoerceOption[] | undefined): TSchema | BaseSchema;
|
|
38
38
|
declare function captureCoercePlan(original: any, coerced: any): CoerceNode | null;
|
|
39
39
|
/** Full rebuild: scalar leaves + ObjectString/ArrayString sites (wired path). */
|
|
40
40
|
declare const buildCoercedFromPlan: (original: any, plan: CoerceNode, seen?: Set<string>) => any;
|
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<2 | 1 |
|
|
20
|
+
declare const primitiveElysiaTypes: Set<2 | 1 | 3 | 14 | 13 | 11 | 10 | 6>;
|
|
21
21
|
declare const noEnumerable: {
|
|
22
22
|
readonly enumerable: false;
|
|
23
23
|
};
|
|
@@ -16,27 +16,18 @@ const COOKIE_OPTION_KEYS = [
|
|
|
16
16
|
"sign",
|
|
17
17
|
"legacySignature"
|
|
18
18
|
];
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
let config;
|
|
19
|
+
const isSchema = (value) => !!value && typeof value === "object" && "~kind" in value;
|
|
20
|
+
function Cookie(first, options) {
|
|
21
|
+
const raw = options;
|
|
22
|
+
let configRaw;
|
|
25
23
|
let rest;
|
|
26
|
-
for (const key in
|
|
27
|
-
const value =
|
|
24
|
+
if (raw) for (const key in raw) {
|
|
25
|
+
const value = raw[key];
|
|
28
26
|
if (value === void 0) continue;
|
|
29
|
-
if (COOKIE_OPTION_KEYS.includes(key)) (
|
|
27
|
+
if (COOKIE_OPTION_KEYS.includes(key)) (configRaw ??= {})[key] = value;
|
|
30
28
|
else (rest ??= {})[key] = value;
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
config,
|
|
34
|
-
rest
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
const isSchema = (value) => !!value && typeof value === "object" && "~kind" in value;
|
|
38
|
-
function Cookie(first, options) {
|
|
39
|
-
const { config, rest } = extractConfig(options);
|
|
30
|
+
const config = configRaw;
|
|
40
31
|
if (isSchema(first)) {
|
|
41
32
|
if (!config) return first;
|
|
42
33
|
const target = Object.create(Object.getPrototypeOf(first), Object.getOwnPropertyDescriptors(first));
|