Socket
Socket
Sign inDemoInstall

elysia

Package Overview
Dependencies
7
Maintainers
1
Versions
334
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.14 to 1.0.15

5

dist/cjs/context.d.ts
/// <reference types="node" />
import type { StatusMap, InvertedStatusMap } from './utils';
import type { StatusMap, InvertedStatusMap, redirect as Redirect } from './utils';
import type { Cookie, ElysiaCookie } from './cookies';

@@ -26,2 +26,3 @@ import { error, type ELYSIA_RESPONSE } from './error';

}>>;
redirect: Redirect;
set: {

@@ -55,2 +56,3 @@ headers: Record<string, string> & SetCookie;

}>>;
redirect: Redirect;
set: {

@@ -91,2 +93,3 @@ headers: Record<string, string> & SetCookie;

request: Request;
redirect: Redirect;
set: {

@@ -93,0 +96,0 @@ headers: {

38

dist/cjs/cookies.js

@@ -297,20 +297,22 @@ "use strict";

var _validateDateTime = fullFormats["date-time"];
import_system.TypeSystem.Format("date", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDate(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
import_system.TypeSystem.Format("date-time", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDateTime(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
if (!import_typebox2.FormatRegistry.Has("date"))
import_system.TypeSystem.Format("date", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDate(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
if (!import_typebox2.FormatRegistry.Has("date-time"))
import_system.TypeSystem.Format("date-time", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDateTime(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
Object.entries(fullFormats).forEach((formatEntry) => {

@@ -317,0 +319,0 @@ const [formatName, formatValue] = formatEntry;

@@ -498,20 +498,22 @@ "use strict";

var _validateDateTime = fullFormats["date-time"];
import_system.TypeSystem.Format("date", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDate(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
import_system.TypeSystem.Format("date-time", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDateTime(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
if (!import_typebox2.FormatRegistry.Has("date"))
import_system.TypeSystem.Format("date", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDate(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
if (!import_typebox2.FormatRegistry.Has("date-time"))
import_system.TypeSystem.Format("date-time", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDateTime(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
Object.entries(fullFormats).forEach((formatEntry) => {

@@ -1568,2 +1570,3 @@ const [formatName, formatValue] = formatEntry;

contentType = contentType.slice(0, index);
context.contentType = contentType;
for (let i = 0; i < hooks.parse.length; i++) {

@@ -1579,2 +1582,3 @@ const hook = hooks.parse[i].fn;

}
delete context.contentType;
if (body === void 0) {

@@ -1581,0 +1585,0 @@ switch (contentType) {

@@ -216,20 +216,22 @@ "use strict";

var _validateDateTime = fullFormats["date-time"];
import_system.TypeSystem.Format("date", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDate(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
import_system.TypeSystem.Format("date-time", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDateTime(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
if (!import_typebox2.FormatRegistry.Has("date"))
import_system.TypeSystem.Format("date", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDate(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
if (!import_typebox2.FormatRegistry.Has("date-time"))
import_system.TypeSystem.Format("date-time", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDateTime(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
Object.entries(fullFormats).forEach((formatEntry) => {

@@ -236,0 +238,0 @@ const [formatName, formatValue] = formatEntry;

@@ -401,20 +401,22 @@ "use strict";

var _validateDateTime = fullFormats["date-time"];
import_system.TypeSystem.Format("date", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDate(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
import_system.TypeSystem.Format("date-time", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDateTime(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
if (!import_typebox2.FormatRegistry.Has("date"))
import_system.TypeSystem.Format("date", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDate(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
if (!import_typebox2.FormatRegistry.Has("date-time"))
import_system.TypeSystem.Format("date-time", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDateTime(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
Object.entries(fullFormats).forEach((formatEntry) => {

@@ -421,0 +423,0 @@ const [formatName, formatValue] = formatEntry;

@@ -36,3 +36,5 @@ import type { Handler, LifeCycleStore, TraceHandler } from './types';

*/
export declare const separateFunction: (code: string) => [string, string];
export declare const separateFunction: (code: string) => [string, string, {
isArrowReturn: boolean;
}];
/**

@@ -39,0 +41,0 @@ * Get range between bracket pair

@@ -46,6 +46,14 @@ "use strict";

if (index !== -1)
return [code.slice(1, index), code.slice(index + 5)];
return [
code.slice(1, index),
code.slice(index + 5),
{ isArrowReturn: false }
];
index = code.indexOf(") => ");
if (index !== -1)
return [code.slice(1, index), code.slice(index + 5)];
return [
code.slice(1, index),
code.slice(index + 5),
{ isArrowReturn: true }
];
}

@@ -55,3 +63,9 @@ if (code.startsWith("function")) {

const end = code.indexOf(")");
return [code.slice(index + 1, end), code.slice(end + 2)];
return [
code.slice(index + 1, end),
code.slice(end + 2),
{
isArrowReturn: false
}
];
}

@@ -62,5 +76,12 @@ const start = code.indexOf("(");

const end = parameter.lastIndexOf(")") + 1;
return [parameter.slice(start, end), "{" + body];
return [
parameter.slice(start, end),
"{" + body,
{
isArrowReturn: false
}
];
}
return code.split("\n", 2);
const x = code.split("\n", 2);
return [x[0], x[1], { isArrowReturn: false }];
};

@@ -164,8 +185,2 @@ var bracketPairRange = (parameter) => {

};
var findEndQueryBracketIndex = (type, content, index) => {
const bracketEndIndex = content.indexOf(type + "]", index);
const singleQuoteIndex = content.indexOf(type + "'", index);
const doubleQuoteIndex = content.indexOf(type + '"', index);
return [bracketEndIndex, singleQuoteIndex, doubleQuoteIndex].filter((i) => i > 0).sort((a, b) => a - b)[0] || -1;
};
var findAlias = (type, body, depth = 0) => {

@@ -208,7 +223,2 @@ if (depth > 5)

};
var accessor = (parent, prop) => [
parent + "." + prop,
parent + '["' + prop + '"]',
parent + "['" + prop + "']"
];
var extractMainParameter = (parameter) => {

@@ -259,23 +269,13 @@ if (!parameter)

inference.query = true;
if (code.includes("return " + alias) || accessor("return " + alias, "query").some(
(key) => code.includes(key)
)) {
if (code.includes("return " + alias) || code.includes("return " + alias + ".query")) {
inference.query = true;
inference.unknownQueries = true;
inference.queries = [];
}
if (inference.query && !inference.unknownQueries)
if (!inference.unknownQueries && inference.query) {
let keyword = alias + ".";
if (code.includes(keyword + "query"))
keyword = alias + ".query";
while (true) {
let keyword = alias + ".";
if (code.includes(keyword + "query"))
keyword = alias + ".query";
let isBracket = false;
let start = code.indexOf(keyword);
if (start === -1) {
isBracket = true;
start = code.indexOf(alias + '["');
}
if (start === -1) {
isBracket = true;
start = code.indexOf(alias + "['");
}
if (start === -1 && code.indexOf(alias + "[") !== -1) {

@@ -287,7 +287,7 @@ inference.queries = [];

if (start !== -1) {
let end = isBracket ? findEndQueryBracketIndex(
let end = findEndIndex(
"",
code,
start + keyword.length + 1
) : findEndIndex("", code, start + keyword.length + 1);
);
if (end === -1)

@@ -311,4 +311,2 @@ end = void 0;

query = query.slice(0, -1);
if (isBracket)
query = query.replaceAll(/("|')/g, "");
if (query && !inference.queries.includes(query)) {

@@ -321,2 +319,3 @@ inference.queries.push(query);

}
}
if (!inference.headers && access("headers", alias))

@@ -463,5 +462,12 @@ inference.headers = true;

const event = "fn" in e ? e.fn : e;
const [parameter, body] = separateFunction(event.toString());
const [parameter, body, { isArrowReturn }] = separateFunction(
event.toString()
);
const rootParameters = findParameterReference(parameter, inference);
const mainParameter = extractMainParameter(rootParameters);
if (isArrowReturn && (body === "query" || rootParameters && body.startsWith(rootParameters + ".query"))) {
inference.query = true;
inference.unknownQueries = true;
inference.queries = [];
}
if (mainParameter) {

@@ -473,9 +479,6 @@ const aliases = findAlias(mainParameter, body);

const context = rootParameters || mainParameter;
if (context && ["", "return "].some(
(type) => accessor(type + context, "query").some(
(key) => body.includes(key)
)
)) {
if (context && body.includes("return " + context + ".query")) {
inference.query = true;
inference.unknownQueries = true;
inference.queries = [];
}

@@ -482,0 +485,0 @@ if (inference.query) {

@@ -393,20 +393,22 @@ "use strict";

var _validateDateTime = fullFormats["date-time"];
import_system.TypeSystem.Format("date", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDate(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
import_system.TypeSystem.Format("date-time", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDateTime(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
if (!import_typebox3.FormatRegistry.Has("date"))
import_system.TypeSystem.Format("date", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDate(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
if (!import_typebox3.FormatRegistry.Has("date-time"))
import_system.TypeSystem.Format("date-time", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDateTime(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
Object.entries(fullFormats).forEach((formatEntry) => {

@@ -413,0 +415,0 @@ const [formatName, formatValue] = formatEntry;

@@ -337,3 +337,20 @@ /// <reference types="bun-types" />

resolve: {};
}, Path extends string = ''> = (context: Context<Route, Singleton, Path>, contentType: string) => MaybePromise<any>;
}, Path extends string = ''> = (context: Prettify<{
contentType: string;
} & Context<Route, Singleton, Path>>,
/**
* @deprecated
*
* use `context.contentType` instead
*
* @example
* ```ts
* new Elysia()
* .onParse(({ contentType, request }) => {
* if (contentType === 'application/json')
* return request.json()
* })
* ```
*/
contentType: string) => MaybePromise<any>;
export type PreHandler<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = {

@@ -606,7 +623,7 @@ decorator: {};

resolve: T['_ephemeral']['resolve'] & T['_volatile']['resolve'];
}, T['_types']['Prefix']>;
}, Path>;
export type InferHandler<T extends Elysia<any, any, any, any, any, any, any, any>, Path extends string = T['_types']['Prefix'], Schema extends RouteSchema = T['_types']['Metadata']['schema']> = InlineHandler<MergeSchema<Schema, T['_types']['Metadata']['schema']>, T['_types']['Singleton'] & {
derive: T['_ephemeral']['derive'] & T['_volatile']['derive'];
resolve: T['_ephemeral']['resolve'] & T['_volatile']['resolve'];
}, T['_types']['Prefix']>;
}, Path>;
export {};

@@ -208,1 +208,8 @@ import { TSchema } from '@sinclair/typebox';

};
/**
*
* @param url URL to redirect to
* @param HTTP status code to send,
*/
export declare const redirect: (url: string, status?: number) => import("undici-types").Response;
export type redirect = typeof redirect;

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

primitiveHooks: () => primitiveHooks,
redirect: () => redirect,
replaceUrlPath: () => replaceUrlPath,

@@ -322,20 +323,22 @@ signCookie: () => signCookie,

var _validateDateTime = fullFormats["date-time"];
import_system.TypeSystem.Format("date", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDate(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
import_system.TypeSystem.Format("date-time", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDateTime(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
if (!import_typebox2.FormatRegistry.Has("date"))
import_system.TypeSystem.Format("date", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDate(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
if (!import_typebox2.FormatRegistry.Has("date-time"))
import_system.TypeSystem.Format("date-time", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDateTime(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
Object.entries(fullFormats).forEach((formatEntry) => {

@@ -1278,2 +1281,8 @@ const [formatName, formatValue] = formatEntry;

});
var redirect = (url, status = 301) => new Response(null, {
status,
headers: {
Location: url
}
});
// Annotate the CommonJS export names for ESM import in node:

@@ -1303,2 +1312,3 @@ 0 && (module.exports = {

primitiveHooks,
redirect,
replaceUrlPath,

@@ -1305,0 +1315,0 @@ signCookie,

@@ -211,20 +211,22 @@ "use strict";

var _validateDateTime = fullFormats["date-time"];
import_system.TypeSystem.Format("date", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDate(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
import_system.TypeSystem.Format("date-time", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDateTime(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
if (!import_typebox2.FormatRegistry.Has("date"))
import_system.TypeSystem.Format("date", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDate(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
if (!import_typebox2.FormatRegistry.Has("date-time"))
import_system.TypeSystem.Format("date-time", (value) => {
const temp = value.replace(/"/g, "");
if (isISO8601.test(temp) || isFormalDate.test(temp) || isShortenDate.test(temp) || _validateDateTime(temp)) {
const date2 = new Date(temp);
if (!Number.isNaN(date2.getTime()))
return true;
}
return false;
});
Object.entries(fullFormats).forEach((formatEntry) => {

@@ -231,0 +233,0 @@ const [formatName, formatValue] = formatEntry;

/// <reference types="node" />
import type { StatusMap, InvertedStatusMap } from './utils';
import type { StatusMap, InvertedStatusMap, redirect as Redirect } from './utils';
import type { Cookie, ElysiaCookie } from './cookies';

@@ -26,2 +26,3 @@ import { error, type ELYSIA_RESPONSE } from './error';

}>>;
redirect: Redirect;
set: {

@@ -55,2 +56,3 @@ headers: Record<string, string> & SetCookie;

}>>;
redirect: Redirect;
set: {

@@ -91,2 +93,3 @@ headers: Record<string, string> & SetCookie;

request: Request;
redirect: Redirect;
set: {

@@ -93,0 +96,0 @@ headers: {

@@ -36,3 +36,5 @@ import type { Handler, LifeCycleStore, TraceHandler } from './types';

*/
export declare const separateFunction: (code: string) => [string, string];
export declare const separateFunction: (code: string) => [string, string, {
isArrowReturn: boolean;
}];
/**

@@ -39,0 +41,0 @@ * Get range between bracket pair

@@ -337,3 +337,20 @@ /// <reference types="bun-types" />

resolve: {};
}, Path extends string = ''> = (context: Context<Route, Singleton, Path>, contentType: string) => MaybePromise<any>;
}, Path extends string = ''> = (context: Prettify<{
contentType: string;
} & Context<Route, Singleton, Path>>,
/**
* @deprecated
*
* use `context.contentType` instead
*
* @example
* ```ts
* new Elysia()
* .onParse(({ contentType, request }) => {
* if (contentType === 'application/json')
* return request.json()
* })
* ```
*/
contentType: string) => MaybePromise<any>;
export type PreHandler<in out Route extends RouteSchema = {}, in out Singleton extends SingletonBase = {

@@ -606,7 +623,7 @@ decorator: {};

resolve: T['_ephemeral']['resolve'] & T['_volatile']['resolve'];
}, T['_types']['Prefix']>;
}, Path>;
export type InferHandler<T extends Elysia<any, any, any, any, any, any, any, any>, Path extends string = T['_types']['Prefix'], Schema extends RouteSchema = T['_types']['Metadata']['schema']> = InlineHandler<MergeSchema<Schema, T['_types']['Metadata']['schema']>, T['_types']['Singleton'] & {
derive: T['_ephemeral']['derive'] & T['_volatile']['derive'];
resolve: T['_ephemeral']['resolve'] & T['_volatile']['resolve'];
}, T['_types']['Prefix']>;
}, Path>;
export {};

@@ -208,1 +208,8 @@ import { TSchema } from '@sinclair/typebox';

};
/**
*
* @param url URL to redirect to
* @param HTTP status code to send,
*/
export declare const redirect: (url: string, status?: number) => import("undici-types").Response;
export type redirect = typeof redirect;
{
"name": "elysia",
"description": "Ergonomic Framework for Human",
"version": "1.0.14",
"version": "1.0.15",
"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

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc