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

hono

Package Overview
Dependencies
Maintainers
1
Versions
344
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.0.0 to 2.0.1

6

dist/compose.d.ts
import type { ErrorHandler, NotFoundHandler } from './hono';
export declare const compose: <C>(middleware: Function[], onError?: ErrorHandler<{
[x: string]: any;
}> | undefined, onNotFound?: NotFoundHandler<{
[x: string]: any;
}> | undefined) => (context: C, next?: Function | undefined) => Promise<C>;
export declare const compose: <C>(middleware: Function[], onError?: ErrorHandler, onNotFound?: NotFoundHandler) => (context: C, next?: Function) => Promise<C>;

4

dist/compose.js

@@ -7,3 +7,3 @@ "use strict";

const compose = (middleware, onError, onNotFound) => {
return async (context, next) => {
return (context, next) => {
let index = -1;

@@ -26,3 +26,3 @@ return dispatch(0);

return Promise.resolve(handler(context, () => dispatch(i + 1)))
.then(async (res) => {
.then((res) => {
// If handler return Response like `return c.text('foo')`

@@ -29,0 +29,0 @@ if (res && context instanceof context_1.HonoContext) {

@@ -11,4 +11,4 @@ /// <reference types="@cloudflare/workers-types" />

env: E;
event: FetchEvent | undefined;
executionCtx: ExecutionContext | undefined;
event: FetchEvent;
executionCtx: ExecutionContext;
finalized: boolean;

@@ -34,6 +34,5 @@ get res(): Response;

env: E;
event: FetchEvent | undefined;
executionCtx: ExecutionContext | undefined;
finalized: boolean;
_status: StatusCode;
private _executionCtx;
private _pretty;

@@ -45,3 +44,5 @@ private _prettySpace;

private notFoundHandler;
constructor(req: Request, env?: E | undefined, eventOrExecutionCtx?: FetchEvent | ExecutionContext | undefined, notFoundHandler?: NotFoundHandler);
constructor(req: Request, env?: E | undefined, executionCtx?: FetchEvent | ExecutionContext | undefined, notFoundHandler?: NotFoundHandler);
get event(): FetchEvent;
get executionCtx(): ExecutionContext;
get res(): Response;

@@ -48,0 +49,0 @@ set res(_res: Response);

@@ -7,17 +7,28 @@ "use strict";

class HonoContext {
constructor(req, env = undefined, eventOrExecutionCtx = undefined, notFoundHandler = () => new Response()) {
constructor(req, env = undefined, executionCtx = undefined, notFoundHandler = () => new Response()) {
this._status = 200;
this._pretty = false;
this._prettySpace = 2;
this._executionCtx = executionCtx;
this.req = req;
this.env = env ? env : {};
if (eventOrExecutionCtx && 'respondWith' in eventOrExecutionCtx) {
this.event = eventOrExecutionCtx;
this.notFoundHandler = notFoundHandler;
this.finalized = false;
}
get event() {
if (this._executionCtx instanceof FetchEvent) {
return this._executionCtx;
}
else {
this.executionCtx = eventOrExecutionCtx;
throw Error('This context has no FetchEvent');
}
this.notFoundHandler = notFoundHandler;
this.finalized = false;
}
get executionCtx() {
if (this._executionCtx) {
return this._executionCtx;
}
else {
throw Error('This context has no ExecutionContext');
}
}
get res() {

@@ -24,0 +35,0 @@ return (this._res || (this._res = new Response()));

@@ -51,5 +51,5 @@ /// <reference types="@cloudflare/workers-types" />

handleEvent(event: FetchEvent): Promise<Response>;
fetch: (request: Request, env?: E | undefined, executionCtx?: ExecutionContext | undefined) => Promise<Response>;
fetch: (request: Request, env?: E, executionCtx?: ExecutionContext) => Promise<Response>;
request(input: RequestInfo, requestInit?: RequestInit): Promise<Response>;
}
export {};

@@ -32,3 +32,3 @@ "use strict";

};
this.fetch = async (request, env, executionCtx) => {
this.fetch = (request, env, executionCtx) => {
return this.dispatch(request, executionCtx, env);

@@ -121,3 +121,3 @@ };

}
async handleEvent(event) {
handleEvent(event) {
return this.dispatch(event.request, event);

@@ -124,0 +124,0 @@ }

import type { Context } from '../../context';
import type { Next } from '../../hono';
declare type EncodingType = 'gzip' | 'deflate';
interface CompressionOptions {
encoding?: 'gzip' | 'deflate';
encoding?: EncodingType;
}
export declare const compress: (options?: CompressionOptions | undefined) => (ctx: Context, next: Next) => Promise<void>;
export declare const compress: (options?: CompressionOptions) => (ctx: Context, next: Next) => Promise<void>;
export {};

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

};
export declare const cors: (options?: CORSOptions | undefined) => (c: Context, next: Next) => Promise<void>;
export declare const cors: (options?: CORSOptions) => (c: Context, next: Next) => Promise<void>;
export {};
import type { Context } from '../../context';
import type { Next } from '../../hono';
export declare const logger: (fn?: {
(...data: any[]): void;
(...data: any[]): void;
(message?: any, ...optionalParams: any[]): void;
}) => (c: Context, next: Next) => Promise<void>;
declare type PrintFunc = (str: string, ...rest: string[]) => void;
export declare const logger: (fn: PrintFunc) => (c: Context, next: Next) => Promise<void>;
export {};

@@ -5,20 +5,18 @@ "use strict";

const url_1 = require("../../utils/url");
const humanize = (n, opts) => {
const options = opts || {};
const d = options.delimiter || ',';
const s = options.separator || '.';
n = n.toString().split('.');
n[0] = n[0].replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1' + d);
return n.join(s);
var LogPrefix;
(function (LogPrefix) {
LogPrefix["Outgoing"] = "-->";
LogPrefix["Incoming"] = "<--";
LogPrefix["Error"] = "xxx";
})(LogPrefix || (LogPrefix = {}));
const humanize = (times) => {
const [delimiter, separator] = [',', '.'];
const orderTimes = times.map((v) => v.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, '$1' + delimiter));
return orderTimes.join(separator);
};
const time = (start) => {
const delta = Date.now() - start;
return humanize([delta < 10000 ? delta + 'ms' : Math.round(delta / 1000) + 's']);
return humanize([delta < 1000 ? delta + 'ms' : Math.round(delta / 1000) + 's']);
};
const LogPrefix = {
Outgoing: '-->',
Incoming: '<--',
Error: 'xxx',
};
const colorStatus = (status = 0) => {
const colorStatus = (status) => {
const out = {

@@ -33,5 +31,6 @@ 7: `\x1b[35m${status}\x1b[0m`,

};
return out[(status / 100) | 0];
const calculateStatus = (status / 100) | 0;
return out[calculateStatus];
};
function log(fn, prefix, method, path, status, elapsed) {
function log(fn, prefix, method, path, status = 0, elapsed) {
const out = prefix === LogPrefix.Incoming

@@ -42,3 +41,3 @@ ? ` ${prefix} ${method} ${path}`

}
const logger = (fn = console.log) => {
const logger = (fn) => {
return async (c, next) => {

@@ -45,0 +44,0 @@ const { method } = c.req;

export declare const equal: (a: ArrayBuffer, b: ArrayBuffer) => boolean;
export declare const timingSafeEqual: (a: string | object | boolean, b: string | object | boolean, hashFunction?: Function | undefined) => Promise<boolean>;
export declare const timingSafeEqual: (a: string | object | boolean, b: string | object | boolean, hashFunction?: Function) => Promise<boolean>;
export declare const bufferToString: (buffer: ArrayBuffer) => string;

@@ -6,2 +6,2 @@ /// <reference types="@cloudflare/workers-types" />

};
export declare const getContentFromKVAsset: (path: string, options?: KVAssetOptions | undefined) => Promise<ArrayBuffer | null>;
export declare const getContentFromKVAsset: (path: string, options?: KVAssetOptions) => Promise<ArrayBuffer | null>;

@@ -49,3 +49,3 @@ "use strict";

default:
throw new types_2.JwtAlorithmNotImplemented(name);
throw new types_2.JwtAlgorithmNotImplemented(name);
}

@@ -52,0 +52,0 @@ };

@@ -1,4 +0,9 @@

export declare class JwtAlorithmNotImplemented extends Error {
export declare class JwtAlgorithmNotImplemented extends Error {
constructor(token: string);
}
/**
* Export for backward compatibility
* @deprecated Use JwtAlgorithmNotImplemented instead
**/
export declare const JwtAlorithmNotImplemented: typeof JwtAlgorithmNotImplemented;
export declare class JwtTokenInvalid extends Error {

@@ -5,0 +10,0 @@ constructor(token: string);

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.AlgorithmTypes = exports.JwtTokenSignatureMismatched = exports.JwtTokenExpired = exports.JwtTokenNotBefore = exports.JwtTokenInvalid = exports.JwtAlorithmNotImplemented = void 0;
class JwtAlorithmNotImplemented extends Error {
exports.AlgorithmTypes = exports.JwtTokenSignatureMismatched = exports.JwtTokenExpired = exports.JwtTokenNotBefore = exports.JwtTokenInvalid = exports.JwtAlorithmNotImplemented = exports.JwtAlgorithmNotImplemented = void 0;
class JwtAlgorithmNotImplemented extends Error {
constructor(token) {
super(`invalid JWT token: ${token}`);
this.name = 'JwtAlorithmNotImplemented';
this.name = 'JwtAlgorithmNotImplemented';
}
}
exports.JwtAlorithmNotImplemented = JwtAlorithmNotImplemented;
exports.JwtAlgorithmNotImplemented = JwtAlgorithmNotImplemented;
/**
* Export for backward compatibility
* @deprecated Use JwtAlgorithmNotImplemented instead
**/
exports.JwtAlorithmNotImplemented = JwtAlgorithmNotImplemented;
class JwtTokenInvalid extends Error {

@@ -12,0 +17,0 @@ constructor(token) {

{
"name": "hono",
"version": "2.0.0",
"version": "2.0.1",
"description": "Ultrafast web framework for Cloudflare Workers.",

@@ -13,3 +13,3 @@ "main": "dist/index.js",

"test:deno": "deno test --allow-read deno_test",
"test:bun": "bun run ./bun_test/index.test.ts",
"test:bun": "bun wiptest bun_test/index.test.ts",
"lint": "eslint --ext js,ts src .eslintrc.js",

@@ -16,0 +16,0 @@ "lint:fix": "eslint --ext js,ts src .eslintrc.js --fix",

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