elysia 1.4.29 → 1.4.31
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/SECURITY.md +27 -0
- package/dist/adapter/bun/compose.js +9 -4
- package/dist/adapter/bun/compose.mjs +9 -4
- package/dist/adapter/bun/handler-native.js +22 -7
- package/dist/adapter/bun/handler-native.mjs +22 -7
- package/dist/adapter/bun/index.js +22 -13
- package/dist/adapter/bun/index.mjs +22 -13
- package/dist/adapter/utils.js +63 -18
- package/dist/adapter/utils.mjs +63 -18
- package/dist/adapter/web-standard/index.js +3 -55
- package/dist/adapter/web-standard/index.mjs +3 -55
- package/dist/compose.js +50 -90
- package/dist/compose.mjs +54 -90
- package/dist/dynamic-handle.js +135 -145
- package/dist/dynamic-handle.mjs +147 -146
- package/dist/error.d.ts +11 -19
- package/dist/error.js +296 -47
- package/dist/error.mjs +289 -47
- package/dist/form-data.d.ts +3 -0
- package/dist/form-data.js +124 -0
- package/dist/form-data.mjs +103 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +38 -35
- package/dist/index.mjs +40 -38
- package/dist/replace-schema.js +8 -3
- package/dist/replace-schema.mjs +8 -3
- package/dist/schema.d.ts +8 -3
- package/dist/schema.js +368 -7
- package/dist/schema.mjs +366 -7
- package/dist/types.d.ts +12 -1
- package/dist/utils.d.ts +2 -0
- package/dist/utils.js +62 -14
- package/dist/utils.mjs +60 -14
- package/dist/ws/index.d.ts +1 -1
- package/dist/ws/index.js +111 -55
- package/dist/ws/index.mjs +111 -55
- package/package.json +4 -4
package/dist/compose.js
CHANGED
|
@@ -31,7 +31,7 @@ __export(compose_exports, {
|
|
|
31
31
|
isAsync: () => isAsync
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(compose_exports);
|
|
34
|
-
var import_index = require('./index.js'), import_value = require("@sinclair/typebox/value"), import_typebox = require("@sinclair/typebox"), import_fast_decode_uri_component = __toESM(require("fast-decode-uri-component")), import_parse_query = require('./parse-query.js'), import_utils = require('./utils.js'), import_utils2 = require('./universal/utils.js'), import_error = require('./error.js'), import_error2 = require('./error.js'), import_trace = require('./trace.js'), import_schema = require('./schema.js'), import_sucrose = require('./sucrose.js'), import_cookies = require('./cookies.js'), import_utils3 = require('./type-system/utils.js'), import_utils4 = require('./adapter/utils.js'), import_replace_schema = require('./replace-schema.js');
|
|
34
|
+
var import_index = require('./index.js'), import_value = require("@sinclair/typebox/value"), import_typebox = require("@sinclair/typebox"), import_fast_decode_uri_component = __toESM(require("fast-decode-uri-component")), import_parse_query = require('./parse-query.js'), import_form_data = require('./form-data.js'), import_utils = require('./utils.js'), import_utils2 = require('./universal/utils.js'), import_error = require('./error.js'), import_error2 = require('./error.js'), import_trace = require('./trace.js'), import_schema = require('./schema.js'), import_sucrose = require('./sucrose.js'), import_cookies = require('./cookies.js'), import_utils3 = require('./type-system/utils.js'), import_utils4 = require('./adapter/utils.js'), import_replace_schema = require('./replace-schema.js');
|
|
35
35
|
const allocateIf = (value, condition) => condition ? value : "", defaultParsers = [
|
|
36
36
|
"json",
|
|
37
37
|
"text",
|
|
@@ -131,7 +131,7 @@ ${name}=${name}.response}if(${name} instanceof Response === false && typeof ${na
|
|
|
131
131
|
if (code += `
|
|
132
132
|
case ${status2}:
|
|
133
133
|
`, value.provider === "standard") {
|
|
134
|
-
code += `let vare${status2}=validator.response[${status2}].
|
|
134
|
+
code += `let vare${status2}=validator.response[${status2}].Validate(${name})
|
|
135
135
|
if(vare${status2} instanceof Promise)vare${status2}=await vare${status2}
|
|
136
136
|
if(vare${status2}.issues)throw new ValidationError('response',validator.response[${status2}],${name},${allowUnsafeValidationDetails},vare${status2}.issues)
|
|
137
137
|
${name}=vare${status2}.value
|
|
@@ -242,7 +242,7 @@ return function(){return a}`
|
|
|
242
242
|
inference.server && (fnLiteral += `Object.defineProperty(c,'server',{get:function(){return getServer()}})
|
|
243
243
|
`), validator.createBody?.(), validator.createQuery?.(), validator.createHeaders?.(), validator.createParams?.(), validator.createCookie?.(), validator.createResponse?.();
|
|
244
244
|
const hasValidation = !!validator.body || !!validator.headers || !!validator.params || !!validator.query || !!validator.cookie || !!validator.response, hasQuery = inference.query || !!validator.query, requestNoBody = hooks.parse?.length === 1 && // @ts-expect-error
|
|
245
|
-
hooks.parse[0].fn === "none", hasBody = method !== "" && method !== "GET" && method !== "HEAD" && (inference.body || !!validator.body || !!hooks.parse?.length) && !requestNoBody, defaultHeaders = app.setHeaders, hasDefaultHeaders = defaultHeaders && !!Object.keys(defaultHeaders).length, hasHeaders = inference.headers || !!validator.headers || adapter.preferWebstandardHeaders !== !0 && inference.body, hasCookie = inference.cookie || !!validator.cookie,
|
|
245
|
+
hooks.parse[0].fn === "none", hasBody = method !== "" && method !== "GET" && method !== "HEAD" && (inference.body || !!validator.body || !!hooks.parse?.length) && !requestNoBody, defaultHeaders = app.setHeaders, hasDefaultHeaders = defaultHeaders && !!Object.keys(defaultHeaders).length, hasHeaders = inference.headers || !!validator.headers || adapter.preferWebstandardHeaders !== !0 && inference.body, hasCookie = inference.cookie || !!validator.cookie, defaultCookie = hooks.config?.cookie ? (0, import_utils.mergeCookie)(app.config.cookie ?? {}, hooks.config.cookie) : app.config.cookie, cookieMeta = validator.cookie?.config ? (0, import_utils.mergeCookie)(validator?.cookie?.config, defaultCookie) : defaultCookie;
|
|
246
246
|
let _encodeCookie = "";
|
|
247
247
|
const encodeCookie = () => {
|
|
248
248
|
if (_encodeCookie) return _encodeCookie;
|
|
@@ -314,7 +314,7 @@ c.cookie=await parseCookie(c.set,c.request.headers.get('cookie'),${options})
|
|
|
314
314
|
hasArrayProperty ? "," + JSON.stringify(arrayProperties) : hasObjectProperty ? ",undefined" : ""}${//
|
|
315
315
|
hasObjectProperty ? "," + JSON.stringify(objectProperties) : ""})}`;
|
|
316
316
|
}
|
|
317
|
-
const isAsyncHandler = typeof handler == "function" && isAsync(handler), saveResponse = hasTrace || hooks.afterResponse?.length ? "c.response=c.responseValue= " : "", responseKeys = Object.keys(validator.response ?? {}), hasMultipleResponses = responseKeys.length > 1, hasSingle200 = responseKeys.length === 0 || responseKeys.length === 1 && responseKeys[0] === "200", maybeAsync = hasCookie || hasBody || isAsyncHandler || !!hooks.parse?.length || !!hooks.afterHandle?.some(isAsync) || !!hooks.beforeHandle?.some(
|
|
317
|
+
const isAsyncHandler = typeof handler == "function" && isAsync(handler), saveResponse = hasTrace || hooks.afterResponse?.length ? "c.response=c.responseValue= " : "", responseKeys = Object.keys(validator.response ?? {}), hasMultipleResponses = responseKeys.length > 1, hasSingle200 = responseKeys.length === 0 || responseKeys.length === 1 && responseKeys[0] === "200", isAsyncBeforeHandle = (hook) => isAsync(hook) || hook.fn.toString().includes("[native code]"), maybeAsync = hasCookie || hasBody || isAsyncHandler || !!hooks.parse?.length || !!hooks.afterHandle?.some(isAsync) || !!hooks.beforeHandle?.some(isAsyncBeforeHandle) || !!hooks.transform?.some(isAsync) || !!hooks.mapResponse?.some(isAsync) || validator.body?.provider === "standard" || validator.headers?.provider === "standard" || validator.query?.provider === "standard" || validator.params?.provider === "standard" || validator.cookie?.provider === "standard" || Object.values(validator.response ?? {}).find(
|
|
318
318
|
(x) => x.provider === "standard"
|
|
319
319
|
), maybeStream = (typeof handler == "function" ? isGenerator(handler) : !1) || !!hooks.beforeHandle?.some(isGenerator) || !!hooks.afterHandle?.some(isGenerator) || !!hooks.transform?.some(isGenerator), hasSet = inference.cookie || inference.set || hasHeaders || hasTrace || hasMultipleResponses || !hasSingle200 || isHandleFn && hasDefaultHeaders || maybeStream;
|
|
320
320
|
let _afterResponse;
|
|
@@ -351,7 +351,7 @@ ${prefix}e.afterResponse[${i}](c)
|
|
|
351
351
|
`;
|
|
352
352
|
return after ? `const _res=${response}` + after + "return _res" : `return ${response}`;
|
|
353
353
|
}, mapResponseContext = adapter.mapResponseContext ? `,${adapter.mapResponseContext}` : "";
|
|
354
|
-
(hasTrace || inference.route) && (fnLiteral += `c.route
|
|
354
|
+
(hasTrace || inference.route) && (fnLiteral += `c.route=${JSON.stringify(path)}
|
|
355
355
|
`), (hasTrace || hooks.afterResponse?.length) && (fnLiteral += `let afterHandlerStreamListener
|
|
356
356
|
`);
|
|
357
357
|
const parseReporter = report("parse", {
|
|
@@ -523,7 +523,7 @@ transformed.url=c.url
|
|
|
523
523
|
transformed.redirect=c.redirect
|
|
524
524
|
transformed.set=c.set
|
|
525
525
|
transformed.error=c.error
|
|
526
|
-
c=transformed}` : fnLiteral += "if(transformed instanceof ElysiaCustomStatusResponse){" + mapResponse("transformed") + `}else
|
|
526
|
+
c=transformed}` : fnLiteral += "if(transformed instanceof ElysiaCustomStatusResponse){" + mapResponse("transformed") + `}else safeAssign(c,transformed)
|
|
527
527
|
`, endUnit();
|
|
528
528
|
}
|
|
529
529
|
}
|
|
@@ -532,24 +532,15 @@ c=transformed}` : fnLiteral += "if(transformed instanceof ElysiaCustomStatusResp
|
|
|
532
532
|
const fileUnions = [];
|
|
533
533
|
if (validator) {
|
|
534
534
|
if (validator.headers) {
|
|
535
|
-
|
|
536
|
-
for (const [key, value] of Object.entries(
|
|
537
|
-
import_value.Value.Default(
|
|
538
|
-
// @ts-ignore
|
|
539
|
-
validator.headers.schema,
|
|
540
|
-
{}
|
|
541
|
-
)
|
|
542
|
-
)) {
|
|
543
|
-
const parsed = typeof value == "object" ? JSON.stringify(value) : typeof value == "string" ? `'${value}'` : value;
|
|
544
|
-
parsed !== void 0 && (fnLiteral += `c.headers['${key}']??=${parsed}
|
|
545
|
-
`);
|
|
546
|
-
}
|
|
547
|
-
fnLiteral += composeCleaner({
|
|
535
|
+
const cleanHeaders = composeCleaner({
|
|
548
536
|
name: "c.headers",
|
|
549
537
|
schema: validator.headers,
|
|
550
538
|
type: "headers",
|
|
551
539
|
normalize
|
|
552
|
-
})
|
|
540
|
+
});
|
|
541
|
+
cleanHeaders && validator.headers.hasDefault && (fnLiteral += `c.headers=cloneSchemaInput(c.headers)
|
|
542
|
+
`), fnLiteral += cleanHeaders, validator.headers.hasDefault && (fnLiteral += `c.headers=applySchemaDefaults(validator.headers,c.headers,true)
|
|
543
|
+
`), validator.headers.isOptional && (fnLiteral += "if(isNotEmpty(c.headers)){"), validator.headers?.provider === "standard" ? fnLiteral += `let vah=validator.headers.Validate(c.headers)
|
|
553
544
|
if(vah instanceof Promise)vah=await vah
|
|
554
545
|
if(vah.issues){` + validation.validate("headers", void 0, "vah.issues") + `}else{c.headers=vah.value}
|
|
555
546
|
` : validator.headers?.schema?.noValidate !== !0 && (fnLiteral += "if(validator.headers.Check(c.headers) === false){" + validation.validate("headers") + "}"), validator.headers.hasTransform && (fnLiteral += coerceTransformDecodeError(
|
|
@@ -559,48 +550,25 @@ if(vah.issues){` + validation.validate("headers", void 0, "vah.issues") + `}else
|
|
|
559
550
|
allowUnsafeValidationDetails
|
|
560
551
|
)), validator.headers.isOptional && (fnLiteral += "}");
|
|
561
552
|
}
|
|
562
|
-
if (validator.params)
|
|
563
|
-
|
|
564
|
-
for (const [key, value] of Object.entries(
|
|
565
|
-
import_value.Value.Default(
|
|
566
|
-
// @ts-ignore
|
|
567
|
-
validator.params.schema,
|
|
568
|
-
{}
|
|
569
|
-
)
|
|
570
|
-
)) {
|
|
571
|
-
const parsed = typeof value == "object" ? JSON.stringify(value) : typeof value == "string" ? `'${value}'` : value;
|
|
572
|
-
parsed !== void 0 && (fnLiteral += `c.params['${key}']??=${parsed}
|
|
573
|
-
`);
|
|
574
|
-
}
|
|
575
|
-
validator.params.provider === "standard" ? fnLiteral += `let vap=validator.params.Check(c.params)
|
|
553
|
+
if (validator.params && (validator.params.hasDefault && (fnLiteral += `c.params=applySchemaDefaults(validator.params,c.params,true)
|
|
554
|
+
`), validator.params.provider === "standard" ? fnLiteral += `let vap=validator.params.Validate(c.params)
|
|
576
555
|
if(vap instanceof Promise)vap=await vap
|
|
577
556
|
if(vap.issues){` + validation.validate("params", void 0, "vap.issues") + `}else{c.params=vap.value}
|
|
578
557
|
` : validator.params?.schema?.noValidate !== !0 && (fnLiteral += "if(validator.params.Check(c.params)===false){" + validation.validate("params") + "}"), validator.params.hasTransform && (fnLiteral += coerceTransformDecodeError(
|
|
579
|
-
|
|
558
|
+
`c.params=validator.params.Decode(c.params)
|
|
580
559
|
`,
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
if (validator.query) {
|
|
586
|
-
if (import_typebox.Kind in validator.query?.schema && validator.query.hasDefault)
|
|
587
|
-
for (const [key, value] of Object.entries(
|
|
588
|
-
import_value.Value.Default(
|
|
589
|
-
// @ts-ignore
|
|
590
|
-
validator.query.schema,
|
|
591
|
-
{}
|
|
592
|
-
)
|
|
593
|
-
)) {
|
|
594
|
-
const parsed = typeof value == "object" ? JSON.stringify(value) : typeof value == "string" ? `'${value}'` : value;
|
|
595
|
-
parsed !== void 0 && (fnLiteral += `if(c.query['${key}']===undefined)c.query['${key}']=${parsed}
|
|
596
|
-
`);
|
|
597
|
-
}
|
|
598
|
-
fnLiteral += composeCleaner({
|
|
560
|
+
"params",
|
|
561
|
+
allowUnsafeValidationDetails
|
|
562
|
+
))), validator.query) {
|
|
563
|
+
const cleanQuery = composeCleaner({
|
|
599
564
|
name: "c.query",
|
|
600
565
|
schema: validator.query,
|
|
601
566
|
type: "query",
|
|
602
567
|
normalize
|
|
603
|
-
})
|
|
568
|
+
});
|
|
569
|
+
cleanQuery && validator.query.hasDefault && (fnLiteral += `c.query=cloneSchemaInput(c.query)
|
|
570
|
+
`), fnLiteral += cleanQuery, import_typebox.Kind in validator.query?.schema && validator.query.hasDefault && (fnLiteral += `c.query=applySchemaDefaults(validator.query,c.query)
|
|
571
|
+
`), validator.query.isOptional && (fnLiteral += "if(isNotEmpty(c.query)){"), validator.query.provider === "standard" ? fnLiteral += `let vaq=validator.query.Validate(c.query)
|
|
604
572
|
if(vaq instanceof Promise)vaq=await vaq
|
|
605
573
|
if(vaq.issues){` + validation.validate("query", void 0, "vaq.issues") + `}else{c.query=vaq.value}
|
|
606
574
|
` : validator.query?.schema?.noValidate !== !0 && (fnLiteral += "if(validator.query.Check(c.query)===false){" + validation.validate("query") + "}"), validator.query.hasTransform && (fnLiteral += coerceTransformDecodeError(
|
|
@@ -616,32 +584,23 @@ if(vaq.issues){` + validation.validate("query", void 0, "vaq.issues") + `}else{c
|
|
|
616
584
|
)), validator.query.isOptional && (fnLiteral += "}");
|
|
617
585
|
}
|
|
618
586
|
if (hasBody && validator.body) {
|
|
619
|
-
(validator.body.hasTransform || validator.body.isOptional) && (fnLiteral += `
|
|
587
|
+
(validator.body.hasTransform || validator.body.isOptional) && (fnLiteral += `let isNotEmptyObject
|
|
620
588
|
`);
|
|
621
589
|
const hasUnion = (0, import_schema.isUnion)(validator.body.schema);
|
|
622
590
|
let hasNonUnionFileWithDefault = !1;
|
|
623
591
|
if (validator.body.hasDefault) {
|
|
624
|
-
let value = import_value.Value.Default(
|
|
625
|
-
validator.body.schema,
|
|
626
|
-
validator.body.schema.type === "object" || (0, import_schema.unwrapImportSchema)(validator.body.schema)[import_typebox.Kind] === "Object" ? {} : void 0
|
|
627
|
-
);
|
|
628
592
|
const schema = (0, import_schema.unwrapImportSchema)(validator.body.schema);
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
for (const [k, v] of Object.entries(value))
|
|
632
|
-
(v === "File" || v === "Files") && delete value[k];
|
|
633
|
-
(0, import_utils.isNotEmpty)(value) || (value = void 0);
|
|
634
|
-
}
|
|
635
|
-
const parsed = typeof value == "object" ? JSON.stringify(value) : typeof value == "string" ? `'${value}'` : value;
|
|
636
|
-
value != null && (Array.isArray(value) ? fnLiteral += `if(!c.body)c.body=${parsed}
|
|
637
|
-
` : typeof value == "object" ? fnLiteral += `c.body=Object.assign(${parsed},c.body)
|
|
638
|
-
` : fnLiteral += `c.body=${parsed}
|
|
639
|
-
`), fnLiteral += composeCleaner({
|
|
593
|
+
!hasUnion && ((0, import_schema.hasType)("File", schema) || (0, import_schema.hasType)("Files", schema)) && (hasNonUnionFileWithDefault = !0);
|
|
594
|
+
const cleanBody = composeCleaner({
|
|
640
595
|
name: "c.body",
|
|
641
596
|
schema: validator.body,
|
|
642
597
|
type: "body",
|
|
643
598
|
normalize
|
|
644
|
-
})
|
|
599
|
+
});
|
|
600
|
+
cleanBody && (fnLiteral += `c.body=cloneSchemaInput(c.body)
|
|
601
|
+
`), fnLiteral += cleanBody, fnLiteral += `c.body=applySchemaDefaults(validator.body,c.body)
|
|
602
|
+
`, (validator.body.hasTransform || validator.body.isOptional) && (fnLiteral += `isNotEmptyObject=c.body&&(typeof c.body==="object"&&(isNotEmpty(c.body)||c.body instanceof ArrayBuffer))
|
|
603
|
+
`), validator.body.provider === "standard" ? fnLiteral += `let vab=validator.body.Validate(c.body)
|
|
645
604
|
if(vab instanceof Promise)vab=await vab
|
|
646
605
|
if(vab.issues){` + validation.validate("body", void 0, "vab.issues") + `}else{c.body=vab.value}
|
|
647
606
|
` : validator.body?.schema?.noValidate !== !0 && (validator.body.isOptional ? fnLiteral += "if(isNotEmptyObject&&validator.body.Check(c.body)===false){" + validation.validate("body") + "}" : fnLiteral += "if(validator.body.Check(c.body)===false){" + validation.validate("body") + "}");
|
|
@@ -651,7 +610,8 @@ if(vab.issues){` + validation.validate("body", void 0, "vab.issues") + `}else{c.
|
|
|
651
610
|
schema: validator.body,
|
|
652
611
|
type: "body",
|
|
653
612
|
normalize
|
|
654
|
-
}), validator.body.
|
|
613
|
+
}), (validator.body.hasTransform || validator.body.isOptional) && (fnLiteral += `isNotEmptyObject=c.body&&(typeof c.body==="object"&&(isNotEmpty(c.body)||c.body instanceof ArrayBuffer))
|
|
614
|
+
`), validator.body.provider === "standard" ? fnLiteral += `let vab=validator.body.Validate(c.body)
|
|
655
615
|
if(vab instanceof Promise)vab=await vab
|
|
656
616
|
if(vab.issues){` + validation.validate("body", void 0, "vab.issues") + `}else{c.body=vab.value}
|
|
657
617
|
` : validator.body?.schema?.noValidate !== !0 && (validator.body.isOptional ? fnLiteral += "if(isNotEmptyObject&&validator.body.Check(c.body)===false){" + validation.validate("body") + "}" : fnLiteral += "if(validator.body.Check(c.body)===false){" + validation.validate("body") + "}");
|
|
@@ -687,7 +647,7 @@ if(vab.issues){` + validation.validate("body", void 0, "vab.issues") + `}else{c.
|
|
|
687
647
|
let validateFile = "", validatorLength = 0;
|
|
688
648
|
for (let i2 = 0; i2 < iterator2.length; i2++) {
|
|
689
649
|
const [k, v] = iterator2[i2];
|
|
690
|
-
!v.extension || v[import_typebox.Kind] !== "File" && v[import_typebox.Kind] !== "Files" || (validatorLength && (validateFile += ","), validateFile += `fileType(c.body
|
|
650
|
+
!v.extension || v[import_typebox.Kind] !== "File" && v[import_typebox.Kind] !== "Files" || (validatorLength && (validateFile += ","), validateFile += `fileType(c.body[${JSON.stringify(k)}],${JSON.stringify(v.extension)},${JSON.stringify("body." + k)})`, validatorLength++);
|
|
691
651
|
}
|
|
692
652
|
validateFile && (validatorLength === 1 ? validator2 += `await ${validateFile}
|
|
693
653
|
` : validatorLength > 1 && (validator2 += `await Promise.all([${validateFile}])
|
|
@@ -709,7 +669,7 @@ if(vab.issues){` + validation.validate("body", void 0, "vab.issues") + `}else{c.
|
|
|
709
669
|
let i = 0;
|
|
710
670
|
if (bodyProperties)
|
|
711
671
|
for (const [k, v] of Object.entries(bodyProperties))
|
|
712
|
-
!v.extension || v[import_typebox.Kind] !== "File" && v[import_typebox.Kind] !== "Files" || (i && (validateFile += ","), validateFile += `fileType(c.body
|
|
672
|
+
!v.extension || v[import_typebox.Kind] !== "File" && v[import_typebox.Kind] !== "Files" || (i && (validateFile += ","), validateFile += `fileType(c.body[${JSON.stringify(k)}],${JSON.stringify(v.extension)},${JSON.stringify("body." + k)})`, i++);
|
|
713
673
|
i && (fnLiteral += `
|
|
714
674
|
`), i === 1 ? fnLiteral += `await ${validateFile}
|
|
715
675
|
` : i > 1 && (fnLiteral += `await Promise.all([${validateFile}])
|
|
@@ -718,10 +678,10 @@ if(vab.issues){` + validation.validate("body", void 0, "vab.issues") + `}else{c.
|
|
|
718
678
|
}
|
|
719
679
|
validator.cookie && (validator.cookie.config = (0, import_utils.mergeCookie)(
|
|
720
680
|
validator.cookie.config,
|
|
721
|
-
|
|
681
|
+
defaultCookie ?? {}
|
|
722
682
|
), fnLiteral += `let cookieValue={}
|
|
723
683
|
for(const [key,value] of Object.entries(c.cookie))cookieValue[key]=value.value
|
|
724
|
-
`, validator.cookie.isOptional && (fnLiteral += "if(isNotEmpty(c.cookie)){"), validator.cookie.provider === "standard" ? (fnLiteral += `let vac=validator.cookie.
|
|
684
|
+
`, validator.cookie.isOptional && (fnLiteral += "if(isNotEmpty(c.cookie)){"), validator.cookie.provider === "standard" ? (fnLiteral += `let vac=validator.cookie.Validate(cookieValue)
|
|
725
685
|
if(vac instanceof Promise)vac=await vac
|
|
726
686
|
if(vac.issues){` + validation.validate("cookie", void 0, "vac.issues") + `}else{cookieValue=vac.value}
|
|
727
687
|
`, fnLiteral += `for(const k of Object.keys(cookieValue))c.cookie[k].value=cookieValue[k]
|
|
@@ -738,11 +698,11 @@ if(vac.issues){` + validation.validate("cookie", void 0, "vac.issues") + `}else{
|
|
|
738
698
|
let hasResolve = !1;
|
|
739
699
|
if (hooks.beforeHandle?.length)
|
|
740
700
|
for (let i = 0; i < hooks.beforeHandle.length; i++) {
|
|
741
|
-
const beforeHandle = hooks.beforeHandle[i], endUnit = reporter.resolveChild(beforeHandle.fn.name)
|
|
701
|
+
const beforeHandle = hooks.beforeHandle[i], asyncBeforeHandle = isAsyncBeforeHandle(beforeHandle), endUnit = reporter.resolveChild(beforeHandle.fn.name);
|
|
742
702
|
if (beforeHandle.subType === "resolve" || beforeHandle.subType === "mapResolve")
|
|
743
703
|
hasResolve || (hasResolve = !0, fnLiteral += `
|
|
744
704
|
let resolved
|
|
745
|
-
`), fnLiteral +=
|
|
705
|
+
`), fnLiteral += asyncBeforeHandle ? `resolved=await e.beforeHandle[${i}](c);
|
|
746
706
|
` : `resolved=e.beforeHandle[${i}](c);
|
|
747
707
|
`, beforeHandle.subType === "mapResolve" ? fnLiteral += "if(resolved instanceof ElysiaCustomStatusResponse){" + mapResponse("resolved") + `}else{resolved.request=c.request
|
|
748
708
|
resolved.store=c.store
|
|
@@ -752,14 +712,10 @@ resolved.url=c.url
|
|
|
752
712
|
resolved.redirect=c.redirect
|
|
753
713
|
resolved.set=c.set
|
|
754
714
|
resolved.error=c.error
|
|
755
|
-
c=resolved}` : fnLiteral += "if(resolved instanceof ElysiaCustomStatusResponse){" + mapResponse("resolved") + `}else
|
|
756
|
-
`, endUnit();
|
|
757
|
-
else if (!returning)
|
|
758
|
-
fnLiteral += isAsync(beforeHandle) ? `await e.beforeHandle[${i}](c)
|
|
759
|
-
` : `e.beforeHandle[${i}](c)
|
|
715
|
+
c=resolved}` : fnLiteral += "if(resolved instanceof ElysiaCustomStatusResponse){" + mapResponse("resolved") + `}else safeAssign(c,resolved)
|
|
760
716
|
`, endUnit();
|
|
761
717
|
else {
|
|
762
|
-
if (fnLiteral +=
|
|
718
|
+
if (fnLiteral += asyncBeforeHandle ? `be=await e.beforeHandle[${i}](c)
|
|
763
719
|
` : `be=e.beforeHandle[${i}](c)
|
|
764
720
|
`, endUnit("be"), fnLiteral += "if(be!==undefined){", reporter.resolve(), hooks.afterHandle?.length || hasTrace) {
|
|
765
721
|
report("handle", {
|
|
@@ -770,11 +726,11 @@ c=resolved}` : fnLiteral += "if(resolved instanceof ElysiaCustomStatusResponse){
|
|
|
770
726
|
});
|
|
771
727
|
if (hooks.afterHandle?.length)
|
|
772
728
|
for (let i2 = 0; i2 < hooks.afterHandle.length; i2++) {
|
|
773
|
-
const hook = hooks.afterHandle[i2],
|
|
729
|
+
const hook = hooks.afterHandle[i2], returning = hasReturn(hook), endUnit2 = reporter2.resolveChild(
|
|
774
730
|
hook.fn.name
|
|
775
731
|
);
|
|
776
732
|
fnLiteral += `c.response=c.responseValue=be
|
|
777
|
-
`,
|
|
733
|
+
`, returning ? (fnLiteral += isAsync(hook.fn) ? `af=await e.afterHandle[${i2}](c)
|
|
778
734
|
` : `af=e.afterHandle[${i2}](c)
|
|
779
735
|
`, fnLiteral += `if(af!==undefined) c.response=c.responseValue=be=af
|
|
780
736
|
`) : fnLiteral += isAsync(hook.fn) ? `await e.afterHandle[${i2}](c, be)
|
|
@@ -962,7 +918,7 @@ if(mep!==undefined)er=mep
|
|
|
962
918
|
}
|
|
963
919
|
errorReporter.resolve(), fnLiteral += "return handleError(c,error,true)", !maybeAsync && hooks.error?.length && (fnLiteral += "})()"), fnLiteral += "}";
|
|
964
920
|
const adapterVariables = adapter.inject ? Object.keys(adapter.inject).join(",") + "," : "";
|
|
965
|
-
let init = "const {handler,handleError,hooks:e, " + allocateIf("validator,", hasValidation) + "mapResponse,mapCompactResponse,mapEarlyResponse,isNotEmpty,utils:{" + allocateIf("parseQuery,", hasBody) + allocateIf("parseQueryFromURL,", hasQuery) + "},error:{" + allocateIf("ValidationError,", hasValidation) + allocateIf("ParseError", hasBody) + "},fileType,schema,definitions,tee,ERROR_CODE," + allocateIf("parseCookie,", hasCookie) + allocateIf("signCookie,", hasCookie) + allocateIf("decodeURIComponent,", hasQuery) + "ElysiaCustomStatusResponse," + allocateIf("ELYSIA_TRACE,", hasTrace) + allocateIf("ELYSIA_REQUEST_ID,", hasTrace) + allocateIf("parser,", hooks.parse?.length) + allocateIf("getServer,", inference.server) + allocateIf("fileUnions,", fileUnions.length) + adapterVariables + allocateIf("TypeBoxError", hasValidation) + `}=hooks
|
|
921
|
+
let init = "const {handler,handleError,hooks:e, " + allocateIf("validator,", hasValidation) + "mapResponse,mapCompactResponse,mapEarlyResponse,isNotEmpty,safeAssign,applySchemaDefaults,cloneSchemaInput,utils:{" + allocateIf("parseQuery,", hasBody) + allocateIf("parseQueryFromURL,", hasQuery) + allocateIf("parseFormData,", hasBody) + "},error:{" + allocateIf("ValidationError,", hasValidation) + allocateIf("ParseError", hasBody) + "},fileType,schema,definitions,tee,ERROR_CODE," + allocateIf("parseCookie,", hasCookie) + allocateIf("signCookie,", hasCookie) + allocateIf("decodeURIComponent,", hasQuery) + "ElysiaCustomStatusResponse," + allocateIf("ELYSIA_TRACE,", hasTrace) + allocateIf("ELYSIA_REQUEST_ID,", hasTrace) + allocateIf("parser,", hooks.parse?.length) + allocateIf("getServer,", inference.server) + allocateIf("fileUnions,", fileUnions.length) + adapterVariables + allocateIf("TypeBoxError", hasValidation) + `}=hooks
|
|
966
922
|
const trace=e.trace
|
|
967
923
|
return ${maybeAsync ? "async " : ""}function handle(c){`;
|
|
968
924
|
hooks.beforeHandle?.length && (init += `let be
|
|
@@ -986,8 +942,12 @@ c.defs=definitions
|
|
|
986
942
|
mapCompactResponse: adapterHandler.mapCompactResponse,
|
|
987
943
|
mapEarlyResponse: adapterHandler.mapEarlyResponse,
|
|
988
944
|
isNotEmpty: import_utils.isNotEmpty,
|
|
945
|
+
safeAssign: import_utils.safeAssign,
|
|
946
|
+
applySchemaDefaults: import_schema.applySchemaDefaults,
|
|
947
|
+
cloneSchemaInput: import_schema.cloneSchemaInput,
|
|
989
948
|
utils: {
|
|
990
949
|
parseQuery: hasBody ? import_parse_query.parseQuery : void 0,
|
|
950
|
+
parseFormData: hasBody ? import_form_data.parseFormData : void 0,
|
|
991
951
|
parseQueryFromURL: hasQuery ? validator.query?.provider === "standard" ? import_parse_query.parseQueryStandardSchema : import_parse_query.parseQueryFromURL : void 0
|
|
992
952
|
},
|
|
993
953
|
error: {
|
|
@@ -1127,9 +1087,9 @@ return route.store.compile()(c)
|
|
|
1127
1087
|
`;
|
|
1128
1088
|
let switchMap = "";
|
|
1129
1089
|
for (const [path, methods] of Object.entries(router.static)) {
|
|
1130
|
-
switchMap += `case
|
|
1090
|
+
switchMap += `case${JSON.stringify(path)}:`, app.config.strictPath !== !0 && (switchMap += `case${JSON.stringify((0, import_utils.getLoosePath)(path))}:`);
|
|
1131
1091
|
const encoded = (0, import_utils.encodePath)(path);
|
|
1132
|
-
path !== encoded && (switchMap += `case
|
|
1092
|
+
path !== encoded && (switchMap += `case${JSON.stringify(encoded)}:`), switchMap += "switch(r.method){", ("GET" in methods || "WS" in methods) && (switchMap += "case 'GET':", "WS" in methods && (switchMap += `if(r.headers.get('upgrade')==='websocket')return ht[${methods.WS}].composed(c)
|
|
1133
1093
|
`, "GET" in methods || ("ALL" in methods ? switchMap += `return ht[${methods.ALL}].composed(c)
|
|
1134
1094
|
` : switchMap += `break map
|
|
1135
1095
|
`)), "GET" in methods && (switchMap += `return ht[${methods.GET}].composed(c)
|
|
@@ -1138,7 +1098,7 @@ return new Response(null,{status:_ht.status,statusText:_ht.statusText,headers:_h
|
|
|
1138
1098
|
}))
|
|
1139
1099
|
`);
|
|
1140
1100
|
for (const [method, index] of Object.entries(methods))
|
|
1141
|
-
method === "ALL" || method === "GET" || method === "WS" || (switchMap += `case
|
|
1101
|
+
method === "ALL" || method === "GET" || method === "WS" || (switchMap += `case ${JSON.stringify(method)}:return ht[${index}].composed(c)
|
|
1142
1102
|
`);
|
|
1143
1103
|
"ALL" in methods ? switchMap += `default:return ht[${methods.ALL}].composed(c)
|
|
1144
1104
|
` : switchMap += `default:break map
|