Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

elysia

Package Overview
Dependencies
Maintainers
0
Versions
477
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

elysia - npm Package Compare versions

Comparing version 1.2.6 to 1.2.7

6

dist/adapter/types.d.ts

@@ -98,2 +98,8 @@ import type { Serve, ListenCallback } from '../universal/server';

validationError: string;
/**
* Handle thrown error which is instance of Error
*
* Despite its name of `unknownError`, it also handle named error like `NOT_FOUND`, `VALIDATION_ERROR`
* It's named `unknownError` because it also catch unknown error
*/
unknownError: string;

@@ -100,0 +106,0 @@ };

2

dist/adapter/web-standard/handler.d.ts

@@ -6,3 +6,3 @@ import type { Context } from '../../context';

export declare const handleSet: (set: Context["set"]) => void;
export declare const mergeResponseWithSetHeaders: (response: Response, set: Context["set"]) => void;
export declare const mergeResponseWithSetHeaders: (response: Response, set: Context["set"]) => Response;
export declare const mapResponse: (response: unknown, set: Context["set"], request?: Request) => Response;

@@ -9,0 +9,0 @@ export declare const mapEarlyResponse: (response: unknown, set: Context["set"], request?: Request) => Response | undefined;

@@ -105,2 +105,4 @@ "use strict";

// @ts-expect-error private property
modules: app.definitions.typebox,
// @ts-expect-error private property
models: app.definitions.type,

@@ -111,2 +113,4 @@ normalize: app.config.normalize

// @ts-expect-error private property
modules: app.definitions.typebox,
// @ts-expect-error private property
models: app.definitions.type,

@@ -113,0 +117,0 @@ normalize: app.config.normalize

@@ -199,2 +199,7 @@ "use strict";

const mergeResponseWithSetHeaders = (response, set2) => {
if (response.status !== set2.status && set2.status !== 200 && (response.status <= 300 || response.status > 400))
response = new Response(response.body, {
headers: response.headers,
status: set2.status
});
let isCookieSet = false;

@@ -213,4 +218,3 @@ if (set2.headers instanceof Headers)

response.headers.append(key, set2.headers[key]);
if (response.status !== set2.status)
set2.status = response.status;
return response;
};

@@ -259,3 +263,6 @@ const mapResponse = (response, set2, request) => {

case "Response":
mergeResponseWithSetHeaders(response, set2);
response = mergeResponseWithSetHeaders(
response,
set2
);
if (response.headers.get("transfer-encoding") === "chunked")

@@ -290,3 +297,6 @@ return handleStream(

if (response instanceof Response) {
mergeResponseWithSetHeaders(response, set2);
response = mergeResponseWithSetHeaders(
response,
set2
);
if (response.headers.get(

@@ -384,3 +394,6 @@ "transfer-encoding"

case "Response":
mergeResponseWithSetHeaders(response, set2);
response = mergeResponseWithSetHeaders(
response,
set2
);
if (response.headers.get("transfer-encoding") === "chunked")

@@ -415,3 +428,6 @@ return handleStream(

if (response instanceof Response) {
mergeResponseWithSetHeaders(response, set2);
response = mergeResponseWithSetHeaders(
response,
set2
);
if (response.headers.get(

@@ -418,0 +434,0 @@ "transfer-encoding"

@@ -8,3 +8,3 @@ import type { AnyElysia } from '.';

export declare const hasType: (type: string, schema: TAnySchema) => any;
export declare const hasProperty: (expectedProperty: string, schema: TAnySchema) => boolean | undefined;
export declare const hasProperty: (expectedProperty: string, _schema: TAnySchema | TypeCheck<any>) => any;
export declare const hasTransform: (schema: TAnySchema) => any;

@@ -11,0 +11,0 @@ export declare const isAsyncName: (v: Function | HookContainer) => boolean;

@@ -60,2 +60,4 @@ "use strict";

const schema = validator?.schema;
if (schema?.[TypeBoxSymbol.kind] === "Import")
return validator.References().some(isOptional);
return !!schema && TypeBoxSymbol.optional in schema;

@@ -70,5 +72,9 @@ };

"application/json",
// eslint-disable-next-line sonarjs/no-duplicate-string
"text/plain",
// eslint-disable-next-line sonarjs/no-duplicate-string
"application/x-www-form-urlencoded",
// eslint-disable-next-line sonarjs/no-duplicate-string
"application/octet-stream",
// eslint-disable-next-line sonarjs/no-duplicate-string
"multipart/form-data"

@@ -79,2 +85,5 @@ ];

const schema = _schema?.schema ?? _schema;
if (schema[TypeBoxSymbol.kind] === "Import" && _schema.References()) {
return _schema.References().some(hasAdditionalProperties);
}
if (schema.anyOf) return schema.anyOf.some(hasAdditionalProperties);

@@ -207,4 +216,7 @@ if (schema.someOf) return schema.someOf.some(hasAdditionalProperties);

};
const hasProperty = (expectedProperty, schema) => {
if (!schema) return;
const hasProperty = (expectedProperty, _schema) => {
if (!_schema) return;
const schema = _schema.schema ?? _schema;
if (schema[TypeBoxSymbol.kind] === "Import")
return _schema.References().some((schema2) => hasProperty(expectedProperty, schema2));
if (schema.type === "object") {

@@ -328,2 +340,4 @@ const properties = schema.properties;

const cookieValidator = hasCookie ? (0, import_utils.getCookieValidator)({
// @ts-expect-error private property
modules: app.definitions.typebox,
validator: validator.cookie,

@@ -359,2 +373,10 @@ defaultConfig: app.config.cookie,

if (hasHeaders) fnLiteral += adapter.headers;
if (hasTrace) fnLiteral += "const id=c[ELYSIA_REQUEST_ID]\n";
const report = createReport({
trace: hooks.trace,
addFn: (word) => {
fnLiteral += word;
}
});
fnLiteral += "try{";
if (hasCookie) {

@@ -494,10 +516,2 @@ const get = (name, defaultValue) => {

}
if (hasTrace) fnLiteral += "const id=c[ELYSIA_REQUEST_ID]\n";
const report = createReport({
trace: hooks.trace,
addFn: (word) => {
fnLiteral += word;
}
});
fnLiteral += "try{";
const isAsyncHandler = typeof handler === "function" && isAsync(handler);

@@ -695,3 +709,3 @@ const saveResponse = hasTrace || hooks.afterResponse.length > 0 ? "c.response= " : "";

fnLiteral += "c.headers=validator.headers.Clean(c.headers);\n";
if (hasProperty("default", validator.headers.schema))
if (hasProperty("default", validator.headers))
for (const [key, value] of Object.entries(

@@ -718,3 +732,3 @@ import_value.Value.Default(

if (validator.params) {
if (hasProperty("default", validator.params.schema))
if (hasProperty("default", validator.params))
for (const [key, value] of Object.entries(

@@ -740,3 +754,3 @@ import_value.Value.Default(

fnLiteral += "c.query=validator.query.Clean(c.query)\n";
if (hasProperty("default", validator.query.schema))
if (hasProperty("default", validator.query))
for (const [key, value] of Object.entries(

@@ -769,3 +783,3 @@ import_value.Value.Default(

`;
if (hasProperty("default", validator.body.schema)) {
if (hasProperty("default", validator.body)) {
const value = import_value.Value.Default(

@@ -796,3 +810,3 @@ // @ts-expect-error private property

}
if ((0, import_utils.isNotEmpty)(
if (cookieValidator && (0, import_utils.isNotEmpty)(
// @ts-ignore

@@ -805,3 +819,3 @@ cookieValidator?.schema?.properties ?? // @ts-ignore

`;
if (hasProperty("default", cookieValidator.schema))
if (hasProperty("default", cookieValidator))
for (const [key, value] of Object.entries(

@@ -1398,8 +1412,8 @@ import_value.Value.Default(

});
fnLiteral += `const set = context.set
fnLiteral += `const set=context.set
let _r
if(!context.code)context.code=error.code??error[ERROR_CODE]
if(!(context.error instanceof Error))context.error = error
if(error instanceof ElysiaCustomStatusResponse){error.status = error.code
error.message = error.response}`;
if(!(context.error instanceof Error))context.error=error
if(error instanceof ElysiaCustomStatusResponse){set.status=error.status=error.code
error.message=error.response}`;
if (adapter.declare) fnLiteral += adapter.declare;

@@ -1416,3 +1430,3 @@ const saveResponse = hasTrace || hooks.afterResponse.length > 0 || hooks.afterResponse.length > 0 ? "context.response = " : "";

if(_r instanceof ElysiaCustomStatusResponse){error.status=error.code
error.message = error.response}if(set.status === 200) set.status = error.status
error.message = error.response}if(set.status===200||!set.status)set.status=error.status
`;

@@ -1440,4 +1454,5 @@ const mapResponseReporter2 = report("mapResponse", {

fnLiteral += `if(error.constructor.name==="ValidationError"||error.constructor.name==="TransformDecodeError"){if(error.error)error=error.error
set.status = error.status??422
` + adapter.validationError + `}else{if(error.code&&typeof error.status==="number"){` + adapter.unknownError + "}";
set.status=error.status??422
` + adapter.validationError + `}`;
fnLiteral += `if(error instanceof Error){` + adapter.unknownError + `}`;
const mapResponseReporter = report("mapResponse", {

@@ -1447,3 +1462,5 @@ total: hooks.mapResponse.length,

});
fnLiteral += "\nif(!context.response)context.response=error.message??error\n";
if (hooks.mapResponse.length) {
fnLiteral += "let mr\n";
for (let i = 0; i < hooks.mapResponse.length; i++) {

@@ -1454,5 +1471,4 @@ const mapResponse = hooks.mapResponse[i];

);
fnLiteral += `context.response=error
error=${isAsyncName(mapResponse) ? "await " : ""}onMapResponse[${i}](context)
`;
fnLiteral += `if(mr===undefined){mr=${isAsyncName(mapResponse) ? "await " : ""}onMapResponse[${i}](context)
if(mr!==undefined)error=context.response=mr}`;
endUnit();

@@ -1463,3 +1479,3 @@ }

fnLiteral += `
return mapResponse(${saveResponse}error,set${adapter.mapResponseContext})}}`;
return mapResponse(${saveResponse}error,set${adapter.mapResponseContext})}`;
return Function(

@@ -1466,0 +1482,0 @@ "inject",

@@ -31,3 +31,6 @@ "use strict";

const injectDefaultValues = (typeChecker, obj) => {
for (const [key, keySchema] of Object.entries(typeChecker.schema.properties)) {
for (const [key, keySchema] of Object.entries(
// @ts-expect-error private
typeChecker.schema.properties
)) {
obj[key] ??= keySchema.default;

@@ -238,3 +241,4 @@ }

const result = mapEarlyResponse(response2, context.set);
if (result) return context.response = result;
if (result)
return context.response = result;
}

@@ -325,7 +329,5 @@ if (response2 instanceof Promise)

}
return context.response = mapResponse(response, context.set);
return mapResponse(context.response = response, context.set);
} catch (error) {
const reportedError = error instanceof import_value.TransformDecodeError && error.error ? error.error : error;
if (reportedError.status)
set.status = reportedError.status;
return app.handleError(context, reportedError);

@@ -332,0 +334,0 @@ } finally {

@@ -265,2 +265,3 @@ "use strict";

const validator = (0, import_utils2.getSchemaValidator)(model, {
modules: this.definitions.typebox,
dynamic: true,

@@ -350,5 +351,6 @@ additionalProperties: true,

const models = {};
for (const [name, schema] of Object.entries(this.definitions.type))
for (const name of Object.keys(this.definitions.type))
models[name] = (0, import_utils2.getSchemaValidator)(
schema
// @ts-expect-error
this.definitions.typebox.Import(name)
);

@@ -397,2 +399,3 @@ models.modules = this.definitions.typebox;

const cookieValidator = () => cloned.cookie ? (0, import_utils2.getCookieValidator)({
modules,
validator: cloned.cookie,

@@ -405,4 +408,6 @@ defaultConfig: this.config.cookie,

const normalize = this.config.normalize;
const modules = this.definitions.typebox;
const validator = this.config.precompile === true || typeof this.config.precompile === "object" && this.config.precompile.schema === true ? {
body: (0, import_utils2.getSchemaValidator)(cloned.body, {
modules,
dynamic,

@@ -414,2 +419,3 @@ models,

headers: (0, import_utils2.getSchemaValidator)(cloned.headers, {
modules,
dynamic,

@@ -422,2 +428,3 @@ models,

params: (0, import_utils2.getSchemaValidator)(cloned.params, {
modules,
dynamic,

@@ -429,2 +436,3 @@ models,

query: (0, import_utils2.getSchemaValidator)(cloned.query, {
modules,
dynamic,

@@ -438,2 +446,3 @@ models,

response: (0, import_utils2.getResponseSchemaValidator)(cloned.response, {
modules,
dynamic,

@@ -449,2 +458,3 @@ models,

{
modules,
dynamic,

@@ -462,2 +472,3 @@ models,

{
modules,
dynamic,

@@ -476,2 +487,3 @@ models,

{
modules,
dynamic,

@@ -489,2 +501,3 @@ models,

{
modules,
dynamic,

@@ -506,2 +519,3 @@ models,

{
modules,
dynamic,

@@ -1857,15 +1871,28 @@ models,

model(name, model) {
const coerce = (schema) => (0, import_utils.replaceSchemaType)(schema, [
{
from: import_type_system.t.Number(),
to: (options) => import_type_system.t.Numeric(options),
untilObjectFound: true
},
{
from: import_type_system.t.Boolean(),
to: (options) => import_type_system.t.BooleanString(options),
untilObjectFound: true
}
]);
switch (typeof name) {
case "object":
const parsedSchemas = {};
Object.entries(name).forEach(([key, value]) => {
if (!(key in this.definitions.type))
this.definitions.type[key] = value;
parsedSchemas[key] = this.definitions.type[key] = coerce(value);
});
this.definitions.typebox = import_type_system.t.Module({
...this.definitions.typebox["$defs"],
...name
...parsedSchemas
});
return this;
case "function":
const result = name(this.definitions.type);
const result = coerce(name(this.definitions.type));
this.definitions.type = result;

@@ -1872,0 +1899,0 @@ this.definitions.typebox = import_type_system.t.Module(result);

@@ -336,9 +336,7 @@ import type { Elysia, AnyElysia } from '.';

resolve: {};
}, Path extends string | undefined = undefined> = Handler<Omit<Route, 'response'> & {
response: {} extends Route['response'] ? unknown : Route['response'];
}, Singleton & {
}, Path extends string | undefined = undefined> = (context: Context<Omit<Route, 'response'> & {}, Singleton & {
derive: {
response: Route['response'];
response: {} extends Route['response'] ? unknown : Route['response'];
};
}, Path>;
}, Path>) => MaybePromise<Response | void>;
export type VoidHandler<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = {

@@ -447,2 +445,7 @@ decorator: {};

} & NeverKey<Singleton['derive'] & Ephemeral['derive'] & Volatile['derive']> & NeverKey<Singleton['derive'] & Ephemeral['resolve'] & Volatile['resolve']>> | Prettify<{
request: Request;
code: number;
error: Readonly<ElysiaCustomStatusResponse<number>>;
set: Context['set'];
} & Partial<Singleton['derive'] & Ephemeral['derive'] & Volatile['derive']> & Partial<Singleton['derive'] & Ephemeral['resolve'] & Volatile['resolve']>> | Prettify<{
[K in keyof T]: {

@@ -449,0 +452,0 @@ request: Request;

import type { BunFile } from 'bun';
import { type TSchema } from '@sinclair/typebox';
import { TModule, type TSchema } from '@sinclair/typebox';
import { TypeCheck } from '@sinclair/typebox/compiler';

@@ -33,4 +33,5 @@ import type { Sucrose } from './sucrose';

export declare const replaceSchemaType: (schema: TSchema, options: MaybeArray<ReplaceSchemaTypeOptions>, root?: boolean) => TSchema;
export declare const getSchemaValidator: <T extends TSchema | string | undefined>(s: T, { models, dynamic, normalize, additionalProperties, coerce, additionalCoerce }?: {
export declare const getSchemaValidator: <T extends TSchema | string | undefined>(s: T, { models, dynamic, modules, normalize, additionalProperties, coerce, additionalCoerce }?: {
models?: Record<string, TSchema>;
modules: TModule<any, any>;
additionalProperties?: boolean;

@@ -42,3 +43,4 @@ dynamic?: boolean;

}) => T extends TSchema ? TypeCheck<TSchema> : undefined;
export declare const getResponseSchemaValidator: (s: InputSchema["response"] | undefined, { models, dynamic, normalize, additionalProperties }: {
export declare const getResponseSchemaValidator: (s: InputSchema["response"] | undefined, { models, modules, dynamic, normalize, additionalProperties }: {
modules: TModule<any, any>;
models?: Record<string, TSchema>;

@@ -52,4 +54,5 @@ additionalProperties?: boolean;

export declare const coercePrimitiveRoot: () => ReplaceSchemaTypeOptions[];
export declare const getCookieValidator: ({ validator, defaultConfig, config, dynamic, models }: {
export declare const getCookieValidator: ({ validator, modules, defaultConfig, config, dynamic, models }: {
validator: TSchema | string | undefined;
modules: TModule<any, any>;
defaultConfig: CookieOptions | undefined;

@@ -56,0 +59,0 @@ config: CookieOptions;

@@ -427,2 +427,3 @@ "use strict";

dynamic = false,
modules,
normalize = false,

@@ -432,6 +433,11 @@ additionalProperties = false,

additionalCoerce = []
} = {}) => {
} = {
modules: import_type_system.t.Module({})
}) => {
if (!s) return void 0;
if (typeof s === "string" && !(s in models)) return void 0;
let schema = typeof s === "string" ? models[s] : s;
let schema = typeof s === "string" ? (
// @ts-expect-error
modules.Import(s) ?? models[s]
) : s;
if (coerce || additionalCoerce) {

@@ -441,2 +447,7 @@ if (coerce)

{
from: import_type_system.t.Ref(""),
// @ts-expect-error
to: (options) => modules.Import(options["$ref"])
},
{
from: import_type_system.t.Number(),

@@ -455,2 +466,7 @@ to: (options) => import_type_system.t.Numeric(options),

schema = replaceSchemaType(schema, [
{
from: import_type_system.t.Ref(""),
// @ts-expect-error
to: (options) => modules.Import(options["$ref"])
},
...Array.isArray(additionalCoerce) ? additionalCoerce : [additionalCoerce]

@@ -536,2 +552,3 @@ ]);

models = {},
modules,
dynamic = false,

@@ -543,3 +560,6 @@ normalize = false,

if (typeof s === "string" && !(s in models)) return;
const maybeSchemaOrRecord = typeof s === "string" ? models[s] : s;
const maybeSchemaOrRecord = typeof s === "string" ? (
// @ts-ignore
modules.Import(s) ?? models[s]
) : s;
const compile = (schema, references) => {

@@ -633,2 +653,3 @@ if (dynamic)

validator,
modules,
defaultConfig = {},

@@ -640,2 +661,3 @@ config,

let cookieValidator = getSchemaValidator(validator, {
modules,
dynamic,

@@ -656,2 +678,3 @@ models,

cookieValidator = getSchemaValidator(import_type_system.t.Cookie({}), {
modules,
dynamic,

@@ -658,0 +681,0 @@ models,

@@ -8,3 +8,3 @@ import type { AnyElysia } from '.';

export declare const hasType: (type: string, schema: TAnySchema) => any;
export declare const hasProperty: (expectedProperty: string, schema: TAnySchema) => boolean | undefined;
export declare const hasProperty: (expectedProperty: string, _schema: TAnySchema | TypeCheck<any>) => any;
export declare const hasTransform: (schema: TAnySchema) => any;

@@ -11,0 +11,0 @@ export declare const isAsyncName: (v: Function | HookContainer) => boolean;

@@ -336,9 +336,7 @@ import type { Elysia, AnyElysia } from '.';

resolve: {};
}, Path extends string | undefined = undefined> = Handler<Omit<Route, 'response'> & {
response: {} extends Route['response'] ? unknown : Route['response'];
}, Singleton & {
}, Path extends string | undefined = undefined> = (context: Context<Omit<Route, 'response'> & {}, Singleton & {
derive: {
response: Route['response'];
response: {} extends Route['response'] ? unknown : Route['response'];
};
}, Path>;
}, Path>) => MaybePromise<Response | void>;
export type VoidHandler<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = {

@@ -447,2 +445,7 @@ decorator: {};

} & NeverKey<Singleton['derive'] & Ephemeral['derive'] & Volatile['derive']> & NeverKey<Singleton['derive'] & Ephemeral['resolve'] & Volatile['resolve']>> | Prettify<{
request: Request;
code: number;
error: Readonly<ElysiaCustomStatusResponse<number>>;
set: Context['set'];
} & Partial<Singleton['derive'] & Ephemeral['derive'] & Volatile['derive']> & Partial<Singleton['derive'] & Ephemeral['resolve'] & Volatile['resolve']>> | Prettify<{
[K in keyof T]: {

@@ -449,0 +452,0 @@ request: Request;

import type { BunFile } from 'bun';
import { type TSchema } from '@sinclair/typebox';
import { TModule, type TSchema } from '@sinclair/typebox';
import { TypeCheck } from '@sinclair/typebox/compiler';

@@ -33,4 +33,5 @@ import type { Sucrose } from './sucrose';

export declare const replaceSchemaType: (schema: TSchema, options: MaybeArray<ReplaceSchemaTypeOptions>, root?: boolean) => TSchema;
export declare const getSchemaValidator: <T extends TSchema | string | undefined>(s: T, { models, dynamic, normalize, additionalProperties, coerce, additionalCoerce }?: {
export declare const getSchemaValidator: <T extends TSchema | string | undefined>(s: T, { models, dynamic, modules, normalize, additionalProperties, coerce, additionalCoerce }?: {
models?: Record<string, TSchema>;
modules: TModule<any, any>;
additionalProperties?: boolean;

@@ -42,3 +43,4 @@ dynamic?: boolean;

}) => T extends TSchema ? TypeCheck<TSchema> : undefined;
export declare const getResponseSchemaValidator: (s: InputSchema["response"] | undefined, { models, dynamic, normalize, additionalProperties }: {
export declare const getResponseSchemaValidator: (s: InputSchema["response"] | undefined, { models, modules, dynamic, normalize, additionalProperties }: {
modules: TModule<any, any>;
models?: Record<string, TSchema>;

@@ -52,4 +54,5 @@ additionalProperties?: boolean;

export declare const coercePrimitiveRoot: () => ReplaceSchemaTypeOptions[];
export declare const getCookieValidator: ({ validator, defaultConfig, config, dynamic, models }: {
export declare const getCookieValidator: ({ validator, modules, defaultConfig, config, dynamic, models }: {
validator: TSchema | string | undefined;
modules: TModule<any, any>;
defaultConfig: CookieOptions | undefined;

@@ -56,0 +59,0 @@ config: CookieOptions;

{
"name": "elysia",
"description": "Ergonomic Framework for Human",
"version": "1.2.6",
"version": "1.2.7",
"author": {

@@ -6,0 +6,0 @@ "name": "saltyAom",

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 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 too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc