New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

hono

Package Overview
Dependencies
Maintainers
1
Versions
349
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hono - npm Package Compare versions

Comparing version 2.5.10 to 2.6.0

11

dist/cjs/middleware/validator/middleware.js

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

const handler = async (c, next) => {
var _a;
const resultSet = {

@@ -79,3 +80,7 @@ hasError: false,

} else {
c.req.valid(keys, value);
let tmp = data;
for (let i = 0; i < keys.length - 1; i++) {
tmp = tmp[_a = keys[i]] || (tmp[_a] = {});
}
tmp[keys[keys.length - 1]] = value;
}

@@ -85,5 +90,3 @@ }

if (!resultSet.hasError) {
Object.keys(data).map((key) => {
c.req.valid(key, data[key]);
});
c.req.valid(data);
}

@@ -90,0 +93,0 @@ if (options && options.done) {

@@ -116,16 +116,8 @@ "use strict";

};
Request.prototype.valid = function(keys, value) {
var _a;
Request.prototype.valid = function(data) {
if (!this.data) {
this.data = {};
}
if (keys !== void 0) {
if (typeof keys === "string") {
keys = [keys];
}
let data = this.data;
for (let i = 0; i < keys.length - 1; i++) {
data = data[_a = keys[i]] || (data[_a] = {});
}
data[keys[keys.length - 1]] = value;
if (data) {
this.data = data;
}

@@ -132,0 +124,0 @@ return this.data;

@@ -9,3 +9,3 @@ import type { ExecutionContext } from './types';

export declare type Data = string | ArrayBuffer | ReadableStream;
export declare class Context<P extends string = string, E extends Partial<Environment> = Environment, S extends Partial<Schema> = Schema> {
export declare class Context<P extends string = string, E extends Partial<Environment> = Environment, S = any> {
req: Request<unknown, P, S extends Schema ? SchemaToProp<S> : S>;

@@ -12,0 +12,0 @@ env: E['Bindings'];

import type { Router } from './router';
import type { ExecutionContext } from './types';
import type { Handler, Environment, ParamKeys, ErrorHandler, NotFoundHandler } from './types';
import type { Schema } from './validator/schema';
interface HandlerInterface<P extends string, E extends Partial<Environment>, S extends Partial<Schema>, U = Hono<E, P, S>> {
<Path extends string, Data extends Schema>(...handlers: Handler<ParamKeys<Path> extends never ? string : ParamKeys<Path>, E, Data>[]): U;
(...handlers: Handler<string, E, S>[]): U;
<Path extends string, Data extends Partial<Schema> = Schema>(path: Path, ...handlers: Handler<ParamKeys<Path> extends never ? string : ParamKeys<Path>, E, Data>[]): U;
<Path extends string, Data extends Schema>(path: Path, ...handlers: Handler<string, E, Data>[]): U;
(path: string, ...handlers: Handler<string, E, S>[]): U;
interface HandlerInterface<P extends string, E extends Partial<Environment> = Environment, S = unknown, U = Hono<E, P, S>> {
<Path extends string, Data = S>(...handlers: Handler<ParamKeys<Path> extends never ? string : ParamKeys<Path>, E, Data>[]): Hono<E, Path, Data & S>;
(...handlers: Handler<P, E, S>[]): U;
<Path extends string, Data = S>(path: Path, ...handlers: Handler<ParamKeys<Path> extends never ? string : ParamKeys<Path>, E, Data>[]): Hono<E, Path, Data & S>;
<Path extends string, Data = S>(path: Path, ...handlers: Handler<string, E, Data>[]): Hono<E, string, Data & S>;
(path: string, ...handlers: Handler<P, E, S>[]): U;
}
interface Route<P extends string = string, E extends Partial<Environment> = Environment, S extends Partial<Schema> = Schema> {
interface Route<P extends string = string, E extends Partial<Environment> = Environment, S = unknown> {
path: string;

@@ -17,3 +16,3 @@ method: string;

}
declare const Hono_base: new <E_1 extends Partial<Environment> = Environment, P_1 extends string = string, S_1 extends Partial<Schema> = Schema, U = Hono<E_1, P_1, S_1>>() => {
declare const Hono_base: new <E_1 extends Partial<Environment> = Environment, P_1 extends string = string, S_1 = unknown, U = Hono<E_1, P_1, S_1>>() => {
get: HandlerInterface<P_1, E_1, S_1, U>;

@@ -28,3 +27,3 @@ all: HandlerInterface<P_1, E_1, S_1, U>;

};
export declare class Hono<E extends Partial<Environment> = Environment, P extends string = '/', S extends Partial<Schema> = Schema> extends Hono_base<E, P, S, Hono<E, P, S>> {
export declare class Hono<E extends Partial<Environment> = Environment, P extends string = '/', S = unknown> extends Hono_base<E, P, S, Hono<E, P, S>> {
readonly router: Router<Handler<P, E, S>>;

@@ -39,4 +38,4 @@ readonly strict: boolean;

route(path: string, app?: Hono<any>): this;
use<Path extends string = string, Data extends Partial<Schema> = Schema>(...middleware: Handler<Path, E, Data>[]): Hono<E, P, S>;
use<Path extends string = string, Data extends Partial<Schema> = Schema>(arg1: string, ...middleware: Handler<Path, E, Data>[]): Hono<E, P, S>;
use<Path extends string = string, Data = unknown>(...middleware: Handler<Path, E, Data>[]): Hono<E, P, S>;
use<Path extends string = string, Data = unknown>(arg1: string, ...middleware: Handler<Path, E, Data>[]): Hono<E, P, S>;
on(method: string, path: string, ...handlers: Handler<P, E, S>[]): this;

@@ -43,0 +42,0 @@ onError(handler: ErrorHandler<E>): this;

import type { ServeStaticOptions } from './serve-static';
declare const module: (options?: ServeStaticOptions) => import("../..").MiddlewareHandler<string, import("../../types").Environment, import("../../validator/schema").Schema>;
declare const module: (options?: ServeStaticOptions) => import("../..").MiddlewareHandler<string, import("../../types").Environment, unknown>;
export { module as serveStatic };
import type { Context } from '../../context';
import type { Environment, MiddlewareHandler } from '../../types';
import type { Schema } from '../../validator/schema';
import type { ValidateResult } from '../../validator/validator';

@@ -12,6 +11,6 @@ import { Validator } from '../../validator/validator';

declare type Done<P extends string, E extends Partial<Environment> = Environment> = (resultSet: ResultSet, c: Context<P, E>) => Response | void;
declare type ValidationFunction<P extends string, E extends Partial<Environment> = Environment, S extends Schema = Schema> = (v: Validator, c: Context<P, E>) => S;
export declare const validatorMiddleware: <P extends string, E extends Partial<Environment> = Environment, S extends Schema = Schema>(validationFunction: ValidationFunction<P, E, S>, options?: {
declare type ValidationFunction<P extends string, E extends Partial<Environment> = Environment, S = unknown> = (v: Validator, c: Context<P, E>) => S;
export declare const validatorMiddleware: <P extends string, E extends Partial<Environment> = Environment, S = unknown>(validationFunction: ValidationFunction<P, E, S>, options?: {
done?: Done<P, E> | undefined;
} | undefined) => MiddlewareHandler<string, E, S>;
export {};

@@ -8,2 +8,3 @@ // src/middleware/validator/middleware.ts

const handler = async (c, next) => {
var _a;
const resultSet = {

@@ -57,3 +58,7 @@ hasError: false,

} else {
c.req.valid(keys, value);
let tmp = data;
for (let i = 0; i < keys.length - 1; i++) {
tmp = tmp[_a = keys[i]] || (tmp[_a] = {});
}
tmp[keys[keys.length - 1]] = value;
}

@@ -63,5 +68,3 @@ }

if (!resultSet.hasError) {
Object.keys(data).map((key) => {
c.req.valid(key, data[key]);
});
c.req.valid(data);
}

@@ -68,0 +71,0 @@ if (options && options.done) {

import type { BodyData } from './utils/body';
import type { Cookie } from './utils/cookie';
declare type ValidatedData = Record<string, unknown>;
declare global {
interface Request<CfHostMetadata = unknown, ParamKeyType extends string = string, Data extends ValidatedData = ValidatedData> {
interface Request<CfHostMetadata = unknown, ParamKeyType extends string = string, Data = any> {
paramData?: Record<ParamKeyType, string>;

@@ -26,3 +25,3 @@ param: {

cookie: {
(name: string): string;
(name: string): string | undefined;
(): Cookie;

@@ -36,3 +35,3 @@ };

valid: {
(key: string | string[], value: unknown): Data;
(data: Data): Data;
(): Data;

@@ -43,2 +42,1 @@ };

export declare function extendRequestPrototype(): void;
export {};

@@ -94,16 +94,8 @@ // src/request.ts

};
Request.prototype.valid = function(keys, value) {
var _a;
Request.prototype.valid = function(data) {
if (!this.data) {
this.data = {};
}
if (keys !== void 0) {
if (typeof keys === "string") {
keys = [keys];
}
let data = this.data;
for (let i = 0; i < keys.length - 1; i++) {
data = data[_a = keys[i]] || (data[_a] = {});
}
data[keys[keys.length - 1]] = value;
if (data) {
this.data = data;
}

@@ -110,0 +102,0 @@ return this.data;

import type { Context } from './context';
import type { Schema } from './validator/schema';
export interface ContextVariableMap {

@@ -11,4 +10,4 @@ }

};
export declare type Handler<P extends string = string, E extends Partial<Environment> = Environment, S extends Partial<Schema> = Schema> = (c: Context<P, E, S>, next: Next) => Response | Promise<Response | undefined | void>;
export declare type MiddlewareHandler<P extends string = string, E extends Partial<Environment> = Environment, S extends Partial<Schema> = Schema> = (c: Context<P, E, S>, next: Next) => Promise<Response | undefined | void>;
export declare type Handler<P extends string = string, E extends Partial<Environment> = Environment, S = unknown> = (c: Context<P, E, S>, next: Next) => Response | Promise<Response | undefined | void>;
export declare type MiddlewareHandler<P extends string = string, E extends Partial<Environment> = Environment, S = unknown> = (c: Context<P, E, S>, next: Next) => Promise<Response | undefined | void>;
export declare type NotFoundHandler<E extends Partial<Environment> = Environment> = (c: Context<string, E>) => Response | Promise<Response>;

@@ -20,4 +19,4 @@ export declare type ErrorHandler<E extends Partial<Environment> = Environment> = (err: Error, c: Context<string, E>) => Response;

export declare type ParamKeys<Path> = Path extends `${infer Component}/${infer Rest}` ? ParamKey<Component> | ParamKeys<Rest> : ParamKey<Path>;
export interface CustomHandler<P extends string | Partial<Environment> | Schema = string, E = Partial<Environment> | Partial<Schema>, S = Partial<Schema>> {
(c: Context<P extends string ? P : P extends Partial<Environment> ? string : P extends Partial<Schema> ? string : never, P extends Partial<Environment> ? P : P extends Partial<Schema> ? Partial<Environment> : E extends Partial<Environment> ? E extends Partial<Schema> ? Environment : E : E extends Partial<Schema> ? Partial<Environment> : Environment, S extends Schema ? S : P extends Schema ? P : E extends Schema ? E : any>, next: Next): Response | Promise<Response | undefined | void>;
export interface CustomHandler<P = string, E = Partial<Environment>, S = any> {
(c: Context<P extends string ? P : string, P extends Partial<Environment> ? P : E extends Partial<Environment> ? E : never, P extends string ? E extends Partial<Environment> ? S : P extends Partial<Environment> ? E : never : P extends Partial<Environment> ? E extends Partial<Environment> ? S : E : P>, next: Next): Response | Promise<Response | undefined | void>;
}

@@ -24,0 +23,0 @@ export interface ExecutionContext {

@@ -76,5 +76,3 @@ import type { JSONObject, JSONPrimitive, JSONArray } from './../utils/json';

get(value: string): this;
validate: <R extends Request<unknown, string, {
[x: string]: unknown;
}>>(req: R) => Promise<ValidateResult[]>;
validate: <R extends Request<unknown, string, any>>(req: R) => Promise<ValidateResult[]>;
protected getTypeRuleName(): string;

@@ -81,0 +79,0 @@ private sanitizeValue;

{
"name": "hono",
"version": "2.5.10",
"version": "2.6.0",
"description": "Ultrafast web framework for Cloudflare Workers, Deno, and Bun.",

@@ -5,0 +5,0 @@ "main": "dist/cjs/index.js",

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