elysia
Advanced tools
Comparing version 1.0.7 to 1.0.8
@@ -388,3 +388,30 @@ "use strict"; | ||
MaybeEmpty: (schema) => t.Union([t.Null(), t.Undefined(), schema]), | ||
Cookie: (properties, options) => t.Object(properties, options) | ||
Cookie: (properties, { | ||
domain, | ||
expires, | ||
httpOnly, | ||
maxAge, | ||
path, | ||
priority, | ||
sameSite, | ||
secure, | ||
secrets, | ||
sign, | ||
...options | ||
} = {}) => { | ||
const v = t.Object(properties, options); | ||
v.config = { | ||
domain, | ||
expires, | ||
httpOnly, | ||
maxAge, | ||
path, | ||
priority, | ||
sameSite, | ||
secure, | ||
secrets, | ||
sign | ||
}; | ||
return v; | ||
} | ||
}; | ||
@@ -391,0 +418,0 @@ t.BooleanString = ElysiaType.BooleanString; |
@@ -589,3 +589,30 @@ "use strict"; | ||
MaybeEmpty: (schema) => t.Union([t.Null(), t.Undefined(), schema]), | ||
Cookie: (properties, options) => t.Object(properties, options) | ||
Cookie: (properties, { | ||
domain, | ||
expires, | ||
httpOnly, | ||
maxAge, | ||
path, | ||
priority, | ||
sameSite, | ||
secure, | ||
secrets, | ||
sign, | ||
...options | ||
} = {}) => { | ||
const v = t.Object(properties, options); | ||
v.config = { | ||
domain, | ||
expires, | ||
httpOnly, | ||
maxAge, | ||
path, | ||
priority, | ||
sameSite, | ||
secure, | ||
secrets, | ||
sign | ||
}; | ||
return v; | ||
} | ||
}; | ||
@@ -876,3 +903,4 @@ t.BooleanString = ElysiaType.BooleanString; | ||
; | ||
response.cancel(request); | ||
if (!request?.signal.aborted) | ||
response.cancel(request); | ||
} | ||
@@ -973,3 +1001,4 @@ }, | ||
; | ||
response.cancel(request); | ||
if (!request?.signal.aborted) | ||
response.cancel(request); | ||
} | ||
@@ -1081,3 +1110,4 @@ }, | ||
; | ||
response.cancel(request); | ||
if (!request?.signal.aborted) | ||
response.cancel(request); | ||
} | ||
@@ -1182,3 +1212,4 @@ }, | ||
; | ||
response.cancel(request); | ||
if (!request?.signal.aborted) | ||
response.cancel(request); | ||
} | ||
@@ -1274,3 +1305,4 @@ }, | ||
; | ||
response.cancel(request); | ||
if (!request?.signal.aborted) | ||
response.cancel(request); | ||
} | ||
@@ -1461,13 +1493,17 @@ }, | ||
context.headers[key] = value; | ||
const cookieMeta = validator?.cookie?.schema; | ||
const cookieMeta = Object.assign( | ||
{}, | ||
app.config?.cookie, | ||
// @ts-expect-error | ||
validator?.cookie?.config | ||
); | ||
const cookieHeaderValue = request.headers.get("cookie"); | ||
if (cookieHeaderValue) | ||
context.cookie = await parseCookie( | ||
context.set, | ||
cookieHeaderValue, | ||
cookieMeta ? { | ||
secret: cookieMeta.secrets !== void 0 ? typeof cookieMeta.secrets === "string" ? cookieMeta.secrets : cookieMeta.secrets.join(",") : void 0, | ||
sign: cookieMeta.sign === true ? true : cookieMeta.sign !== void 0 ? typeof cookieMeta.sign === "string" ? cookieMeta.sign : cookieMeta.sign.join(",") : void 0 | ||
} : void 0 | ||
); | ||
context.cookie = await parseCookie( | ||
context.set, | ||
cookieHeaderValue, | ||
cookieMeta ? { | ||
secret: cookieMeta.secrets !== void 0 ? typeof cookieMeta.secrets === "string" ? cookieMeta.secrets : cookieMeta.secrets.join(",") : void 0, | ||
sign: cookieMeta.sign === true ? true : cookieMeta.sign !== void 0 ? typeof cookieMeta.sign === "string" ? cookieMeta.sign : cookieMeta.sign.join(",") : void 0 | ||
} : void 0 | ||
); | ||
for (let i = 0; i < hooks.transform.length; i++) { | ||
@@ -1586,5 +1622,6 @@ const hook = hooks.transform[i]; | ||
); | ||
else | ||
else { | ||
const properties = validator?.cookie?.schema?.properties; | ||
for (const name of cookieMeta.sign) { | ||
if (!(name in cookieMeta.properties)) | ||
if (!(name in properties)) | ||
continue; | ||
@@ -1598,2 +1635,3 @@ if (context.set.cookie[name]?.value) { | ||
} | ||
} | ||
} | ||
@@ -1600,0 +1638,0 @@ return mapResponse(response, context.set); |
@@ -307,3 +307,30 @@ "use strict"; | ||
MaybeEmpty: (schema) => t.Union([t.Null(), t.Undefined(), schema]), | ||
Cookie: (properties, options) => t.Object(properties, options) | ||
Cookie: (properties, { | ||
domain, | ||
expires, | ||
httpOnly, | ||
maxAge, | ||
path, | ||
priority, | ||
sameSite, | ||
secure, | ||
secrets, | ||
sign, | ||
...options | ||
} = {}) => { | ||
const v = t.Object(properties, options); | ||
v.config = { | ||
domain, | ||
expires, | ||
httpOnly, | ||
maxAge, | ||
path, | ||
priority, | ||
sameSite, | ||
secure, | ||
secrets, | ||
sign | ||
}; | ||
return v; | ||
} | ||
}; | ||
@@ -310,0 +337,0 @@ t.BooleanString = ElysiaType.BooleanString; |
@@ -492,3 +492,30 @@ "use strict"; | ||
MaybeEmpty: (schema) => t.Union([t.Null(), t.Undefined(), schema]), | ||
Cookie: (properties, options) => t.Object(properties, options) | ||
Cookie: (properties, { | ||
domain, | ||
expires, | ||
httpOnly, | ||
maxAge, | ||
path, | ||
priority, | ||
sameSite, | ||
secure, | ||
secrets, | ||
sign, | ||
...options | ||
} = {}) => { | ||
const v = t.Object(properties, options); | ||
v.config = { | ||
domain, | ||
expires, | ||
httpOnly, | ||
maxAge, | ||
path, | ||
priority, | ||
sameSite, | ||
secure, | ||
secrets, | ||
sign | ||
}; | ||
return v; | ||
} | ||
}; | ||
@@ -734,3 +761,4 @@ t.BooleanString = ElysiaType.BooleanString; | ||
; | ||
response.cancel(request); | ||
if (!request?.signal.aborted) | ||
response.cancel(request); | ||
} | ||
@@ -831,3 +859,4 @@ }, | ||
; | ||
response.cancel(request); | ||
if (!request?.signal.aborted) | ||
response.cancel(request); | ||
} | ||
@@ -939,3 +968,4 @@ }, | ||
; | ||
response.cancel(request); | ||
if (!request?.signal.aborted) | ||
response.cancel(request); | ||
} | ||
@@ -1040,3 +1070,4 @@ }, | ||
; | ||
response.cancel(request); | ||
if (!request?.signal.aborted) | ||
response.cancel(request); | ||
} | ||
@@ -1132,3 +1163,4 @@ }, | ||
; | ||
response.cancel(request); | ||
if (!request?.signal.aborted) | ||
response.cancel(request); | ||
} | ||
@@ -1135,0 +1167,0 @@ }, |
@@ -21,2 +21,17 @@ /// <reference types="node" /> | ||
} | ||
interface CookieValidatorOption<T extends Object = {}> extends ObjectOptions, CookieOptions { | ||
/** | ||
* Secret key for signing cookie | ||
* | ||
* If array is passed, will use Key Rotation. | ||
* | ||
* Key rotation is when an encryption key is retired | ||
* and replaced by generating a new cryptographic key. | ||
*/ | ||
secrets?: string | string[]; | ||
/** | ||
* Specified cookie name to be signed globally | ||
*/ | ||
sign?: Readonly<(keyof T | (string & {}))[]>; | ||
} | ||
} | ||
@@ -36,17 +51,3 @@ declare const Files: (options?: Partial<ElysiaTypeOptions.Files> | undefined) => import("@sinclair/typebox").TUnsafe<File[]>; | ||
readonly MaybeEmpty: <T_2 extends TSchema>(schema: T_2) => TUnion<[T_2, TUndefined]>; | ||
readonly Cookie: <T_3 extends TProperties>(properties: T_3, options?: (ObjectOptions & CookieOptions & { | ||
/** | ||
* Secret key for signing cookie | ||
* | ||
* If array is passed, will use Key Rotation. | ||
* | ||
* Key rotation is when an encryption key is retired | ||
* and replaced by generating a new cryptographic key. | ||
*/ | ||
secrets?: string | string[] | undefined; | ||
/** | ||
* Specified cookie name to be signed globally | ||
*/ | ||
sign?: readonly ((string & {}) | keyof T_3)[] | undefined; | ||
}) | undefined) => TObject<T_3>; | ||
readonly Cookie: <T_3 extends TProperties>(properties: T_3, { domain, expires, httpOnly, maxAge, path, priority, sameSite, secure, secrets, sign, ...options }?: ElysiaTypeOptions.CookieValidatorOption<T_3>) => TObject<T_3>; | ||
}; | ||
@@ -53,0 +54,0 @@ export type TCookie = (typeof ElysiaType)['Cookie']; |
@@ -486,3 +486,30 @@ "use strict"; | ||
MaybeEmpty: (schema) => t.Union([t.Null(), t.Undefined(), schema]), | ||
Cookie: (properties, options) => t.Object(properties, options) | ||
Cookie: (properties, { | ||
domain, | ||
expires, | ||
httpOnly, | ||
maxAge, | ||
path, | ||
priority, | ||
sameSite, | ||
secure, | ||
secrets, | ||
sign, | ||
...options | ||
} = {}) => { | ||
const v = t.Object(properties, options); | ||
v.config = { | ||
domain, | ||
expires, | ||
httpOnly, | ||
maxAge, | ||
path, | ||
priority, | ||
sameSite, | ||
secure, | ||
secrets, | ||
sign | ||
}; | ||
return v; | ||
} | ||
}; | ||
@@ -489,0 +516,0 @@ t.BooleanString = ElysiaType.BooleanString; |
@@ -87,2 +87,11 @@ /// <reference types="bun-types" /> | ||
experimental?: {}; | ||
/** | ||
* 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. | ||
* This allows for sending unknown or disallowed properties in the bodies. These will simply be filtered out instead of failing the request. | ||
* This has no effect when the schemas allow additional properties. | ||
* Since this uses dynamic schema it may have an impact on performance. Use with caution. | ||
* | ||
* @default false | ||
*/ | ||
normalize?: boolean; | ||
}; | ||
@@ -89,0 +98,0 @@ export type MaybeArray<T> = T | T[]; |
@@ -18,11 +18,13 @@ import { TSchema } from '@sinclair/typebox'; | ||
}) => LifeCycleStore; | ||
export declare const getSchemaValidator: (s: TSchema | string | undefined, { models, additionalProperties, dynamic }: { | ||
export declare const getSchemaValidator: (s: TSchema | string | undefined, { models, dynamic, normalize, additionalProperties }: { | ||
models?: Record<string, TSchema> | undefined; | ||
additionalProperties?: boolean | undefined; | ||
dynamic?: boolean | undefined; | ||
normalize?: boolean | undefined; | ||
}) => TypeCheck<TSchema> | undefined; | ||
export declare const getResponseSchemaValidator: (s: InputSchema['response'] | undefined, { models, additionalProperties, dynamic }: { | ||
export declare const getResponseSchemaValidator: (s: InputSchema['response'] | undefined, { models, dynamic, normalize, additionalProperties }: { | ||
models?: Record<string, TSchema> | undefined; | ||
additionalProperties?: boolean | undefined; | ||
dynamic?: boolean | undefined; | ||
normalize?: boolean | undefined; | ||
}) => Record<number, TypeCheck<any>> | undefined; | ||
@@ -29,0 +31,0 @@ export declare const checksum: (s: string) => number; |
@@ -409,3 +409,30 @@ "use strict"; | ||
MaybeEmpty: (schema) => t.Union([t.Null(), t.Undefined(), schema]), | ||
Cookie: (properties, options) => t.Object(properties, options) | ||
Cookie: (properties, { | ||
domain, | ||
expires, | ||
httpOnly, | ||
maxAge, | ||
path, | ||
priority, | ||
sameSite, | ||
secure, | ||
secrets, | ||
sign, | ||
...options | ||
} = {}) => { | ||
const v = t.Object(properties, options); | ||
v.config = { | ||
domain, | ||
expires, | ||
httpOnly, | ||
maxAge, | ||
path, | ||
priority, | ||
sameSite, | ||
secure, | ||
secrets, | ||
sign | ||
}; | ||
return v; | ||
} | ||
}; | ||
@@ -569,4 +596,5 @@ t.BooleanString = ElysiaType.BooleanString; | ||
models = {}, | ||
additionalProperties = false, | ||
dynamic = false | ||
dynamic = false, | ||
normalize = false, | ||
additionalProperties = normalize | ||
}) => { | ||
@@ -580,4 +608,5 @@ if (!s) | ||
schema.additionalProperties = additionalProperties; | ||
if (dynamic) | ||
return { | ||
const cleaner = (value) => import_value4.Value.Clean(schema, value); | ||
if (dynamic) { | ||
const validator = { | ||
schema, | ||
@@ -592,8 +621,25 @@ references: "", | ||
}; | ||
return import_compiler2.TypeCompiler.Compile(schema, Object.values(models)); | ||
if (normalize && schema.additionalProperties === true) | ||
validator.Clean = cleaner; | ||
if (schema.config) { | ||
validator.config = schema.config; | ||
if (validator?.schema?.config) | ||
delete validator.schema.config; | ||
} | ||
return validator; | ||
} | ||
const compiled = import_compiler2.TypeCompiler.Compile(schema, Object.values(models)); | ||
compiled.Clean = cleaner; | ||
if (schema.config) { | ||
compiled.config = schema.config; | ||
if (compiled?.schema?.config) | ||
delete compiled.schema.config; | ||
} | ||
return compiled; | ||
}; | ||
var getResponseSchemaValidator = (s, { | ||
models = {}, | ||
additionalProperties = false, | ||
dynamic = false | ||
dynamic = false, | ||
normalize = false, | ||
additionalProperties = normalize | ||
}) => { | ||
@@ -606,2 +652,3 @@ if (!s) | ||
const compile = (schema, references) => { | ||
const cleaner = (value) => import_value4.Value.Clean(schema, value); | ||
if (dynamic) | ||
@@ -618,3 +665,6 @@ return { | ||
}; | ||
return import_compiler2.TypeCompiler.Compile(schema, references); | ||
const compiledValidator = import_compiler2.TypeCompiler.Compile(schema, references); | ||
if (normalize && schema.additionalProperties === true) | ||
compiledValidator.Clean = cleaner; | ||
return compiledValidator; | ||
}; | ||
@@ -669,9 +719,9 @@ if (import_typebox2.Kind in maybeSchemaOrRecord) { | ||
if (cookieValidator) { | ||
cookieValidator.schema = mergeCookie( | ||
cookieValidator.config = mergeCookie( | ||
// @ts-expect-error private | ||
cookieValidator.schema, | ||
cookieValidator.config, | ||
config | ||
); | ||
} else { | ||
cookieValidator = getSchemaValidator(t.Cookie({}, defaultConfig), { | ||
cookieValidator = getSchemaValidator(t.Cookie({}), { | ||
dynamic, | ||
@@ -681,2 +731,3 @@ models, | ||
}); | ||
cookieValidator.config = defaultConfig; | ||
} | ||
@@ -1020,6 +1071,6 @@ } | ||
await this.promises[0]; | ||
this.promises.shift(); | ||
} catch (error2) { | ||
this.onError(error2); | ||
} | ||
this.promises.shift(); | ||
} | ||
@@ -1026,0 +1077,0 @@ this.root = null; |
@@ -302,3 +302,30 @@ "use strict"; | ||
MaybeEmpty: (schema) => t.Union([t.Null(), t.Undefined(), schema]), | ||
Cookie: (properties, options) => t.Object(properties, options) | ||
Cookie: (properties, { | ||
domain, | ||
expires, | ||
httpOnly, | ||
maxAge, | ||
path, | ||
priority, | ||
sameSite, | ||
secure, | ||
secrets, | ||
sign, | ||
...options | ||
} = {}) => { | ||
const v = t.Object(properties, options); | ||
v.config = { | ||
domain, | ||
expires, | ||
httpOnly, | ||
maxAge, | ||
path, | ||
priority, | ||
sameSite, | ||
secure, | ||
secrets, | ||
sign | ||
}; | ||
return v; | ||
} | ||
}; | ||
@@ -305,0 +332,0 @@ t.BooleanString = ElysiaType.BooleanString; |
@@ -21,2 +21,17 @@ /// <reference types="node" /> | ||
} | ||
interface CookieValidatorOption<T extends Object = {}> extends ObjectOptions, CookieOptions { | ||
/** | ||
* Secret key for signing cookie | ||
* | ||
* If array is passed, will use Key Rotation. | ||
* | ||
* Key rotation is when an encryption key is retired | ||
* and replaced by generating a new cryptographic key. | ||
*/ | ||
secrets?: string | string[]; | ||
/** | ||
* Specified cookie name to be signed globally | ||
*/ | ||
sign?: Readonly<(keyof T | (string & {}))[]>; | ||
} | ||
} | ||
@@ -36,17 +51,3 @@ declare const Files: (options?: Partial<ElysiaTypeOptions.Files> | undefined) => import("@sinclair/typebox").TUnsafe<File[]>; | ||
readonly MaybeEmpty: <T_2 extends TSchema>(schema: T_2) => TUnion<[T_2, TUndefined]>; | ||
readonly Cookie: <T_3 extends TProperties>(properties: T_3, options?: (ObjectOptions & CookieOptions & { | ||
/** | ||
* Secret key for signing cookie | ||
* | ||
* If array is passed, will use Key Rotation. | ||
* | ||
* Key rotation is when an encryption key is retired | ||
* and replaced by generating a new cryptographic key. | ||
*/ | ||
secrets?: string | string[] | undefined; | ||
/** | ||
* Specified cookie name to be signed globally | ||
*/ | ||
sign?: readonly ((string & {}) | keyof T_3)[] | undefined; | ||
}) | undefined) => TObject<T_3>; | ||
readonly Cookie: <T_3 extends TProperties>(properties: T_3, { domain, expires, httpOnly, maxAge, path, priority, sameSite, secure, secrets, sign, ...options }?: ElysiaTypeOptions.CookieValidatorOption<T_3>) => TObject<T_3>; | ||
}; | ||
@@ -53,0 +54,0 @@ export type TCookie = (typeof ElysiaType)['Cookie']; |
@@ -87,2 +87,11 @@ /// <reference types="bun-types" /> | ||
experimental?: {}; | ||
/** | ||
* 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. | ||
* This allows for sending unknown or disallowed properties in the bodies. These will simply be filtered out instead of failing the request. | ||
* This has no effect when the schemas allow additional properties. | ||
* Since this uses dynamic schema it may have an impact on performance. Use with caution. | ||
* | ||
* @default false | ||
*/ | ||
normalize?: boolean; | ||
}; | ||
@@ -89,0 +98,0 @@ export type MaybeArray<T> = T | T[]; |
@@ -18,11 +18,13 @@ import { TSchema } from '@sinclair/typebox'; | ||
}) => LifeCycleStore; | ||
export declare const getSchemaValidator: (s: TSchema | string | undefined, { models, additionalProperties, dynamic }: { | ||
export declare const getSchemaValidator: (s: TSchema | string | undefined, { models, dynamic, normalize, additionalProperties }: { | ||
models?: Record<string, TSchema> | undefined; | ||
additionalProperties?: boolean | undefined; | ||
dynamic?: boolean | undefined; | ||
normalize?: boolean | undefined; | ||
}) => TypeCheck<TSchema> | undefined; | ||
export declare const getResponseSchemaValidator: (s: InputSchema['response'] | undefined, { models, additionalProperties, dynamic }: { | ||
export declare const getResponseSchemaValidator: (s: InputSchema['response'] | undefined, { models, dynamic, normalize, additionalProperties }: { | ||
models?: Record<string, TSchema> | undefined; | ||
additionalProperties?: boolean | undefined; | ||
dynamic?: boolean | undefined; | ||
normalize?: boolean | undefined; | ||
}) => Record<number, TypeCheck<any>> | undefined; | ||
@@ -29,0 +31,0 @@ export declare const checksum: (s: string) => number; |
{ | ||
"name": "elysia", | ||
"description": "Ergonomic Framework for Human", | ||
"version": "1.0.7", | ||
"version": "1.0.8", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "saltyAom", |
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 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
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 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
Sorry, the diff of this file is not supported yet
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
2065549
65
41671