Comparing version 1.2.15 to 1.2.16
@@ -161,3 +161,4 @@ "use strict"; | ||
normalize = false, | ||
validator | ||
validator, | ||
encodeSchema = false | ||
}) => ({ | ||
@@ -179,4 +180,10 @@ composeValidation: (type, value = `c.${type}`) => `c.set.status=422;throw new ValidationError('${type}',validator.${type},${value})`, | ||
code += `if(validator.response['${status}'].Check(${name})===false){c.set.status=422 | ||
throw new ValidationError('response',validator.response['${status}'],${name})}c.set.status = ${status}}break | ||
throw new ValidationError('response',validator.response['${status}'],${name})}c.set.status = ${status}} | ||
`; | ||
if (encodeSchema && // @ts-expect-error hasTransform is appended by getResponseSchemaValidator | ||
(value.hasTransform || typeof value.Decode === "function")) { | ||
code += `${name}=validator.response['${status}'].Encode(${name}) | ||
`; | ||
} | ||
code += "break\n"; | ||
} | ||
@@ -404,3 +411,5 @@ return code + "}"; | ||
const hasQuery = inference.query || !!validator.query; | ||
const hasBody = method !== "$INTERNALWS" && method !== "GET" && method !== "HEAD" && (inference.body || !!validator.body || !!hooks.parse?.length); | ||
const requestNoBody = hooks.parse?.length === 1 && // @ts-expect-error | ||
hooks.parse[0].fn === "none"; | ||
const hasBody = method !== "$INTERNALWS" && method !== "GET" && method !== "HEAD" && (inference.body || !!validator.body || !!hooks.parse?.length) && !requestNoBody; | ||
if (hasBody) fnLiteral += `let isParsing=false | ||
@@ -440,5 +449,7 @@ `; | ||
const normalize = app.config.normalize; | ||
const encodeSchema = app.config.experimental?.encodeSchema; | ||
const { composeValidation, composeResponseValidation } = composeValidationFactory({ | ||
normalize, | ||
validator | ||
validator, | ||
encodeSchema | ||
}); | ||
@@ -445,0 +456,0 @@ if (hasHeaders) fnLiteral += adapter.headers; |
@@ -111,3 +111,3 @@ import type { Server } from 'bun'; | ||
store: Singleton['store']; | ||
response?: undefined extends Route['response'] ? unknown : Route['response'][keyof Route['response']]; | ||
response?: never extends keyof Route['response'] ? unknown : Route['response'][keyof Route['response']]; | ||
} & ({} extends Route['response'] ? { | ||
@@ -114,0 +114,0 @@ error: typeof error; |
@@ -103,2 +103,3 @@ "use strict"; | ||
return true; | ||
return false; | ||
} | ||
@@ -234,9 +235,8 @@ return true; | ||
const date = new Date(value); | ||
if (!date || isNaN(date.getTime())) | ||
throw new import_error.ValidationError("property", schema, date); | ||
if (!import_value.Value.Check(schema, date)) | ||
throw new import_error.ValidationError("property", schema, date); | ||
return date; | ||
}).Encode((value) => { | ||
if (typeof value === "string") return new Date(value); | ||
return value; | ||
}); | ||
}).Encode((value) => value.toISOString()); | ||
}, | ||
@@ -243,0 +243,0 @@ BooleanString: (property) => { |
@@ -116,3 +116,10 @@ import type { Elysia, AnyElysia } from '.'; | ||
*/ | ||
experimental?: {}; | ||
experimental?: { | ||
/** | ||
* If enabled, the schema with `t.Transform` will call `Encode` before sending the response | ||
* | ||
* @since 1.2.16 | ||
**/ | ||
encodeSchema?: boolean; | ||
}; | ||
/** | ||
@@ -333,5 +340,3 @@ * If enabled, the handlers will run a [clean](https://github.com/sinclairzx81/typebox?tab=readme-ov-file#clean) on incoming and outgoing bodies instead of failing directly. | ||
resolve: {}; | ||
}, Path extends string | undefined = undefined> = Handler<Route, Singleton, Path> extends (context: infer Context) => infer Returned ? (context: Prettify<{ | ||
response: Route['response'][keyof Route['response']]; | ||
} & Context>) => Returned | MaybePromise<void> : never; | ||
}, Path extends string | undefined = undefined> = Handler<Route, Singleton, Path> extends (context: infer Context) => infer Returned ? (context: Context) => Returned | MaybePromise<void> : never; | ||
export type MapResponse<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = { | ||
@@ -338,0 +343,0 @@ decorator: {}; |
@@ -5,4 +5,4 @@ import type { BunFile } from 'bun'; | ||
import type { Sucrose } from './sucrose'; | ||
import type { CookieOptions } from './cookies'; | ||
import type { LifeCycleStore, MaybeArray, InputSchema, LifeCycleType, HookContainer, Replace, SchemaValidator, AnyLocalHook } from './types'; | ||
import type { CookieOptions } from './cookies'; | ||
export declare const hasHeaderShorthand: boolean; | ||
@@ -9,0 +9,0 @@ export declare const replaceUrlPath: (url: string, pathname: string) => string; |
@@ -73,3 +73,2 @@ "use strict"; | ||
var import_error = require("./error"); | ||
var import_compose = require("./compose"); | ||
const hasHeaderShorthand = "toJSON" in new Headers(); | ||
@@ -456,3 +455,2 @@ const replaceUrlPath = (url, pathname) => { | ||
schema = modules.Import(key) ?? models[key]; | ||
if (!(0, import_compose.hasRef)(schema)) schema = models[key]; | ||
if (isArray) schema = import_type_system.t.Array(schema); | ||
@@ -459,0 +457,0 @@ } |
@@ -111,3 +111,3 @@ import type { Server } from 'bun'; | ||
store: Singleton['store']; | ||
response?: undefined extends Route['response'] ? unknown : Route['response'][keyof Route['response']]; | ||
response?: never extends keyof Route['response'] ? unknown : Route['response'][keyof Route['response']]; | ||
} & ({} extends Route['response'] ? { | ||
@@ -114,0 +114,0 @@ error: typeof error; |
@@ -116,3 +116,10 @@ import type { Elysia, AnyElysia } from '.'; | ||
*/ | ||
experimental?: {}; | ||
experimental?: { | ||
/** | ||
* If enabled, the schema with `t.Transform` will call `Encode` before sending the response | ||
* | ||
* @since 1.2.16 | ||
**/ | ||
encodeSchema?: boolean; | ||
}; | ||
/** | ||
@@ -333,5 +340,3 @@ * If enabled, the handlers will run a [clean](https://github.com/sinclairzx81/typebox?tab=readme-ov-file#clean) on incoming and outgoing bodies instead of failing directly. | ||
resolve: {}; | ||
}, Path extends string | undefined = undefined> = Handler<Route, Singleton, Path> extends (context: infer Context) => infer Returned ? (context: Prettify<{ | ||
response: Route['response'][keyof Route['response']]; | ||
} & Context>) => Returned | MaybePromise<void> : never; | ||
}, Path extends string | undefined = undefined> = Handler<Route, Singleton, Path> extends (context: infer Context) => infer Returned ? (context: Context) => Returned | MaybePromise<void> : never; | ||
export type MapResponse<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = { | ||
@@ -338,0 +343,0 @@ decorator: {}; |
@@ -5,4 +5,4 @@ import type { BunFile } from 'bun'; | ||
import type { Sucrose } from './sucrose'; | ||
import type { CookieOptions } from './cookies'; | ||
import type { LifeCycleStore, MaybeArray, InputSchema, LifeCycleType, HookContainer, Replace, SchemaValidator, AnyLocalHook } from './types'; | ||
import type { CookieOptions } from './cookies'; | ||
export declare const hasHeaderShorthand: boolean; | ||
@@ -9,0 +9,0 @@ export declare const replaceUrlPath: (url: string, pathname: string) => string; |
{ | ||
"name": "elysia", | ||
"description": "Ergonomic Framework for Human", | ||
"version": "1.2.15", | ||
"version": "1.2.16", | ||
"author": { | ||
@@ -161,3 +161,3 @@ "name": "saltyAom", | ||
"dependencies": { | ||
"@sinclair/typebox": "^0.34.15", | ||
"@sinclair/typebox": "^0.34.27", | ||
"cookie": "^1.0.2", | ||
@@ -164,0 +164,0 @@ "memoirist": "^0.3.0", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1911805
30595
Updated@sinclair/typebox@^0.34.27