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
350
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 3.0.0-rc.5 to 3.0.0-rc.6

dist/adapter/bun/index.js

237

dist/cjs/context.js

@@ -37,2 +37,120 @@ "use strict";

this.notFoundHandler = () => new Response();
this.header = (name, value, options) => {
if (options?.append) {
if (!this._headers) {
this._headers = new Headers(this._preparedHeaders);
}
this._headers.append(name, value);
} else {
if (this._headers) {
this._headers.set(name, value);
} else {
this._preparedHeaders ?? (this._preparedHeaders = {});
this._preparedHeaders[name.toLowerCase()] = value;
}
}
if (this.finalized) {
if (options?.append) {
this.res.headers.append(name, value);
} else {
this.res.headers.set(name, value);
}
}
};
this.status = (status) => {
this._status = status;
};
this.set = (key, value) => {
this._map || (this._map = {});
this._map[key] = value;
};
this.get = (key) => {
return this._map?.[key];
};
this.pretty = (prettyJSON, space = 2) => {
this._pretty = prettyJSON;
this._prettySpace = space;
};
this.newResponse = (data, status, headers) => {
if (!headers && !this._headers && !this._res && !status) {
return new Response(data, {
headers: this._preparedHeaders
});
}
this._preparedHeaders ?? (this._preparedHeaders = {});
if (!this._headers) {
this._headers = new Headers();
for (const [k, v] of Object.entries(this._preparedHeaders)) {
this._headers.set(k, v);
}
}
if (this._res) {
this._res.headers.forEach((v, k) => {
this._headers?.set(k, v);
});
for (const [k, v] of Object.entries(this._preparedHeaders)) {
this._headers.set(k, v);
}
}
headers ?? (headers = {});
for (const [k, v] of Object.entries(headers)) {
if (typeof v === "string") {
this._headers.set(k, v);
} else {
this._headers.delete(k);
for (const v2 of v) {
this._headers.append(k, v2);
}
}
}
return new Response(data, {
status,
headers: this._headers
});
};
this.body = (data, status = this._status, headers) => {
return this.newResponse(data, status, headers);
};
this.text = (text, status, headers) => {
if (!this._preparedHeaders) {
if (!headers && !this._res && !this._headers && !status) {
return new Response(text);
}
this._preparedHeaders = {};
}
if (this._preparedHeaders["content-type"]) {
this._preparedHeaders["content-type"] = "text/plain; charset=UTF8";
}
return this.newResponse(text, status, headers);
};
this.json = (object, status = this._status, headers) => {
const body = this._pretty ? JSON.stringify(object, null, this._prettySpace) : JSON.stringify(object);
this._preparedHeaders ?? (this._preparedHeaders = {});
this._preparedHeaders["content-type"] = "application/json; charset=UTF-8";
return this.newResponse(body, status, headers);
};
this.jsonT = (object, status = this._status, headers) => {
return {
response: this.json(object, status, headers),
data: object,
format: "json"
};
};
this.html = (html, status = this._status, headers) => {
this._preparedHeaders ?? (this._preparedHeaders = {});
this._preparedHeaders["content-type"] = "text/html; charset=UTF-8";
return this.newResponse(html, status, headers);
};
this.redirect = (location, status = 302) => {
this._headers ?? (this._headers = new Headers());
this._headers.set("Location", location);
return this.newResponse(null, status);
};
this.cookie = (name, value, opt) => {
const cookie = (0, import_cookie.serialize)(name, value, opt);
this.header("set-cookie", cookie, { append: true });
};
this.notFound = () => {
return this.notFoundHandler(this);
};
this.rawRequest = req;

@@ -54,2 +172,6 @@ if (options) {

this._req = new import_request.HonoRequest(this.rawRequest, this._paramData, this._queryIndex);
this.rawRequest = null;
delete this.rawRequest;
this._paramData = null;
delete this._paramData;
return this._req;

@@ -79,117 +201,2 @@ }

}
header(name, value, options) {
if (options?.append) {
if (!this._headers) {
this._headers = new Headers(this._preparedHeaders);
}
this._headers.append(name, value);
} else {
if (this._headers) {
this._headers.set(name, value);
} else {
this._preparedHeaders ?? (this._preparedHeaders = {});
this._preparedHeaders[name.toLowerCase()] = value;
}
}
if (this.finalized) {
if (options?.append) {
this.res.headers.append(name, value);
} else {
this.res.headers.set(name, value);
}
}
}
status(status) {
this._status = status;
}
set(key, value) {
this._map || (this._map = {});
this._map[key] = value;
}
get(key) {
return this._map?.[key];
}
pretty(prettyJSON, space = 2) {
this._pretty = prettyJSON;
this._prettySpace = space;
}
newResponse(data, status, headers) {
if (!headers && !this._headers && !this._res) {
return new Response(data, {
status,
headers: this._preparedHeaders
});
}
this._preparedHeaders ?? (this._preparedHeaders = {});
if (!this._headers) {
this._headers ?? (this._headers = new Headers());
for (const [k, v] of Object.entries(this._preparedHeaders)) {
this._headers.set(k, v);
}
}
if (this._res) {
this._res.headers.forEach((v, k) => {
this._headers?.set(k, v);
});
for (const [k, v] of Object.entries(this._preparedHeaders)) {
this._headers.set(k, v);
}
}
headers ?? (headers = {});
for (const [k, v] of Object.entries(headers)) {
if (typeof v === "string") {
this._headers.set(k, v);
} else {
this._headers.delete(k);
for (const v2 of v) {
this._headers.append(k, v2);
}
}
}
return new Response(data, {
status,
headers: this._headers
});
}
body(data, status = this._status, headers) {
return this.newResponse(data, status, headers);
}
text(text, status, headers) {
if (!headers && !status && !this._res && !this._headers && !this._preparedHeaders) {
return new Response(text);
}
this._preparedHeaders ?? (this._preparedHeaders = {});
this._preparedHeaders["content-type"] = "text/plain; charset=UTF8";
return this.newResponse(text, status ?? this._status, headers);
}
json(object, status = this._status, headers) {
const body = this._pretty ? JSON.stringify(object, null, this._prettySpace) : JSON.stringify(object);
this._preparedHeaders ?? (this._preparedHeaders = {});
this._preparedHeaders["content-type"] = "application/json; charset=UTF-8";
return this.newResponse(body, status, headers);
}
jsonT(object, status = this._status, headers) {
return {
response: this.json(object, status, headers),
data: object,
format: "json"
};
}
html(html, status = this._status, headers) {
this._preparedHeaders ?? (this._preparedHeaders = {});
this._preparedHeaders["content-type"] = "text/html; charset=UTF-8";
return this.newResponse(html, status, headers);
}
redirect(location, status = 302) {
this._headers ?? (this._headers = new Headers());
this._headers.set("Location", location);
return this.newResponse(null, status);
}
cookie(name, value, opt) {
const cookie = (0, import_cookie.serialize)(name, value, opt);
this.header("set-cookie", cookie, { append: true });
}
notFound() {
return this.notFoundHandler(this);
}
get runtime() {

@@ -196,0 +203,0 @@ const global = globalThis;

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

this._tempPath = "";
this.path = "/";
this.path = "*";
this.routes = [];

@@ -66,4 +66,4 @@ this.notFoundHandler = (c) => {

};
this.fetch = (request, Environment, executionCtx) => {
return this.dispatch(request, executionCtx, Environment);
this.fetch = (request, Env, executionCtx) => {
return this.dispatch(request, executionCtx, Env);
};

@@ -168,3 +168,3 @@ this.request = async (input, requestInit) => {

});
if (result && result.handlers.length === 1) {
if (result?.handlers.length === 1) {
const handler = result.handlers[0];

@@ -171,0 +171,0 @@ let res;

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

class HonoRequest {
constructor(request, paramData, queryIndex) {
constructor(request, paramData, queryIndex = -1) {
this.raw = request;

@@ -39,3 +39,3 @@ this.paramData = paramData;

const param = this.paramData[key];
return param ? decodeURIComponent(param) : void 0;
return param ? param.indexOf("%") !== -1 ? decodeURIComponent(param) : param : void 0;
} else {

@@ -45,3 +45,3 @@ const decoded = {};

if (value && typeof value === "string") {
decoded[key2] = decodeURIComponent(value);
decoded[key2] = value.indexOf("%") !== -1 ? decodeURIComponent(value) : value;
}

@@ -56,27 +56,7 @@ }

const queryString = (0, import_url.getQueryStringFromURL)(this.url, this.queryIndex);
const searchParams = new URLSearchParams(queryString);
if (!this.queryData) {
this.queryData = {};
for (const key2 of searchParams.keys()) {
this.queryData[key2] = searchParams.get(key2) || "";
}
}
if (key) {
return this.queryData[key];
} else {
return this.queryData;
}
return (0, import_url.getQueryParam)(queryString, key);
}
queries(key) {
const queryString = (0, import_url.getQueryStringFromURL)(this.url, this.queryIndex);
const searchParams = new URLSearchParams(queryString);
if (key) {
return searchParams.getAll(key);
} else {
const result = {};
for (const key2 of searchParams.keys()) {
result[key2] = searchParams.getAll(key2);
}
return result;
}
return (0, import_url.getQueryParams)(queryString, key);
}

@@ -83,0 +63,0 @@ header(name) {

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

aac: "audio/aac",
abw: "application/x-abiword",
arc: "application/x-freearc",
avi: "video/x-msvideo",
azw: "application/vnd.amazon.ebook",
bin: "application/octet-stream",

@@ -46,3 +43,2 @@ bmp: "image/bmp",

bz2: "application/x-bzip2",
csh: "application/x-csh",
css: "text/css",

@@ -72,10 +68,4 @@ csv: "text/csv",

mpeg: "video/mpeg",
mpkg: "application/vnd.apple.installer+xml",
odp: "application/vnd.oasis.opendocument.presentation",
ods: "application/vnd.oasis.opendocument.spreadsheet",
odt: "application/vnd.oasis.opendocument.text",
oga: "audio/ogg",
ogv: "video/ogg",
ogx: "application/ogg",
opus: "audio/opus",
otf: "font/otf",

@@ -88,15 +78,9 @@ png: "image/png",

rar: "application/vnd.rar",
rtf: "application/rtf",
sh: "application/x-sh",
svg: "image/svg+xml",
swf: "application/x-shockwave-flash",
tar: "application/x-tar",
tif: "image/tiff",
tiff: "image/tiff",
ts: "video/mp2t",
ttf: "font/ttf",
txt: "text/plain",
vsd: "application/vnd.visio",
wav: "audio/wav",
weba: "audio/webm",
webm: "video/webm",

@@ -110,3 +94,2 @@ webp: "image/webp",

xml: "application/xml",
xul: "application/vnd.mozilla.xul+xml",
zip: "application/zip",

@@ -113,0 +96,0 @@ "3gp": "video/3gpp",

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

getPattern: () => getPattern,
getQueryParam: () => getQueryParam,
getQueryParams: () => getQueryParams,
getQueryStringFromURL: () => getQueryStringFromURL,

@@ -32,3 +34,3 @@ mergePath: () => mergePath,

const splitPath = (path) => {
const paths = path.split(/\//);
const paths = path.split("/");
if (paths[0] === "") {

@@ -54,3 +56,3 @@ paths.shift();

}
const paths = path.split(/\//);
const paths = path.split("/");
if (paths[0] === "") {

@@ -97,4 +99,3 @@ paths.shift();

const getQueryStringFromURL = (url, queryIndex) => {
queryIndex || (queryIndex = url.indexOf("?"));
const result = queryIndex !== -1 ? url.substring(queryIndex) : "";
const result = queryIndex !== -1 ? url.slice(queryIndex + 1) : "";
return result;

@@ -132,2 +133,54 @@ };

};
const filterQueryString = (queryString) => {
const fragIndex = queryString.indexOf("#");
if (fragIndex !== -1) {
queryString = queryString.slice(0, fragIndex);
}
return queryString;
};
const getQueryParam = (queryString, key) => {
queryString = filterQueryString(queryString);
const results = {};
while (true) {
const andIndex = queryString.indexOf("&");
let strings = "";
if (andIndex === -1) {
strings = queryString;
} else {
strings = queryString.slice(0, andIndex);
}
const eqIndex = strings.indexOf("=");
if (eqIndex !== -1) {
const v = strings.slice(eqIndex + 1);
const k = strings.slice(0, eqIndex);
if (key === k) {
return v.indexOf("%") !== -1 ? decodeURI(v) : v;
} else {
results[k] || (results[k] = v);
}
} else if (strings === key) {
return "";
}
if (andIndex === -1)
break;
queryString = queryString.slice(andIndex + 1, queryString.length);
}
if (key)
return null;
return results;
};
const getQueryParams = (queryString, key) => {
queryString = filterQueryString(queryString);
const results = {};
for (const strings of queryString.split("&")) {
let [k, v] = strings.split("=");
if (v === void 0)
v = "";
results[k] || (results[k] = []);
results[k].push(v.indexOf("%") !== -1 ? decodeURI(v) : v);
}
if (key)
return results[key] ? results[key] : null;
return results;
};
// Annotate the CommonJS export names for ESM import in node:

@@ -138,2 +191,4 @@ 0 && (module.exports = {

getPattern,
getQueryParam,
getQueryParams,
getQueryStringFromURL,

@@ -140,0 +195,0 @@ mergePath,

@@ -23,2 +23,120 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {

this.notFoundHandler = () => new Response();
this.header = (name, value, options) => {
if (options?.append) {
if (!this._headers) {
this._headers = new Headers(this._preparedHeaders);
}
this._headers.append(name, value);
} else {
if (this._headers) {
this._headers.set(name, value);
} else {
this._preparedHeaders ?? (this._preparedHeaders = {});
this._preparedHeaders[name.toLowerCase()] = value;
}
}
if (this.finalized) {
if (options?.append) {
this.res.headers.append(name, value);
} else {
this.res.headers.set(name, value);
}
}
};
this.status = (status) => {
this._status = status;
};
this.set = (key, value) => {
this._map || (this._map = {});
this._map[key] = value;
};
this.get = (key) => {
return this._map?.[key];
};
this.pretty = (prettyJSON, space = 2) => {
this._pretty = prettyJSON;
this._prettySpace = space;
};
this.newResponse = (data, status, headers) => {
if (!headers && !this._headers && !this._res && !status) {
return new Response(data, {
headers: this._preparedHeaders
});
}
this._preparedHeaders ?? (this._preparedHeaders = {});
if (!this._headers) {
this._headers = new Headers();
for (const [k, v] of Object.entries(this._preparedHeaders)) {
this._headers.set(k, v);
}
}
if (this._res) {
this._res.headers.forEach((v, k) => {
this._headers?.set(k, v);
});
for (const [k, v] of Object.entries(this._preparedHeaders)) {
this._headers.set(k, v);
}
}
headers ?? (headers = {});
for (const [k, v] of Object.entries(headers)) {
if (typeof v === "string") {
this._headers.set(k, v);
} else {
this._headers.delete(k);
for (const v2 of v) {
this._headers.append(k, v2);
}
}
}
return new Response(data, {
status,
headers: this._headers
});
};
this.body = (data, status = this._status, headers) => {
return this.newResponse(data, status, headers);
};
this.text = (text, status, headers) => {
if (!this._preparedHeaders) {
if (!headers && !this._res && !this._headers && !status) {
return new Response(text);
}
this._preparedHeaders = {};
}
if (this._preparedHeaders["content-type"]) {
this._preparedHeaders["content-type"] = "text/plain; charset=UTF8";
}
return this.newResponse(text, status, headers);
};
this.json = (object, status = this._status, headers) => {
const body = this._pretty ? JSON.stringify(object, null, this._prettySpace) : JSON.stringify(object);
this._preparedHeaders ?? (this._preparedHeaders = {});
this._preparedHeaders["content-type"] = "application/json; charset=UTF-8";
return this.newResponse(body, status, headers);
};
this.jsonT = (object, status = this._status, headers) => {
return {
response: this.json(object, status, headers),
data: object,
format: "json"
};
};
this.html = (html, status = this._status, headers) => {
this._preparedHeaders ?? (this._preparedHeaders = {});
this._preparedHeaders["content-type"] = "text/html; charset=UTF-8";
return this.newResponse(html, status, headers);
};
this.redirect = (location, status = 302) => {
this._headers ?? (this._headers = new Headers());
this._headers.set("Location", location);
return this.newResponse(null, status);
};
this.cookie = (name, value, opt) => {
const cookie = serialize(name, value, opt);
this.header("set-cookie", cookie, { append: true });
};
this.notFound = () => {
return this.notFoundHandler(this);
};
this.rawRequest = req;

@@ -40,2 +158,6 @@ if (options) {

this._req = new HonoRequest(this.rawRequest, this._paramData, this._queryIndex);
this.rawRequest = null;
delete this.rawRequest;
this._paramData = null;
delete this._paramData;
return this._req;

@@ -65,117 +187,2 @@ }

}
header(name, value, options) {
if (options?.append) {
if (!this._headers) {
this._headers = new Headers(this._preparedHeaders);
}
this._headers.append(name, value);
} else {
if (this._headers) {
this._headers.set(name, value);
} else {
this._preparedHeaders ?? (this._preparedHeaders = {});
this._preparedHeaders[name.toLowerCase()] = value;
}
}
if (this.finalized) {
if (options?.append) {
this.res.headers.append(name, value);
} else {
this.res.headers.set(name, value);
}
}
}
status(status) {
this._status = status;
}
set(key, value) {
this._map || (this._map = {});
this._map[key] = value;
}
get(key) {
return this._map?.[key];
}
pretty(prettyJSON, space = 2) {
this._pretty = prettyJSON;
this._prettySpace = space;
}
newResponse(data, status, headers) {
if (!headers && !this._headers && !this._res) {
return new Response(data, {
status,
headers: this._preparedHeaders
});
}
this._preparedHeaders ?? (this._preparedHeaders = {});
if (!this._headers) {
this._headers ?? (this._headers = new Headers());
for (const [k, v] of Object.entries(this._preparedHeaders)) {
this._headers.set(k, v);
}
}
if (this._res) {
this._res.headers.forEach((v, k) => {
this._headers?.set(k, v);
});
for (const [k, v] of Object.entries(this._preparedHeaders)) {
this._headers.set(k, v);
}
}
headers ?? (headers = {});
for (const [k, v] of Object.entries(headers)) {
if (typeof v === "string") {
this._headers.set(k, v);
} else {
this._headers.delete(k);
for (const v2 of v) {
this._headers.append(k, v2);
}
}
}
return new Response(data, {
status,
headers: this._headers
});
}
body(data, status = this._status, headers) {
return this.newResponse(data, status, headers);
}
text(text, status, headers) {
if (!headers && !status && !this._res && !this._headers && !this._preparedHeaders) {
return new Response(text);
}
this._preparedHeaders ?? (this._preparedHeaders = {});
this._preparedHeaders["content-type"] = "text/plain; charset=UTF8";
return this.newResponse(text, status ?? this._status, headers);
}
json(object, status = this._status, headers) {
const body = this._pretty ? JSON.stringify(object, null, this._prettySpace) : JSON.stringify(object);
this._preparedHeaders ?? (this._preparedHeaders = {});
this._preparedHeaders["content-type"] = "application/json; charset=UTF-8";
return this.newResponse(body, status, headers);
}
jsonT(object, status = this._status, headers) {
return {
response: this.json(object, status, headers),
data: object,
format: "json"
};
}
html(html, status = this._status, headers) {
this._preparedHeaders ?? (this._preparedHeaders = {});
this._preparedHeaders["content-type"] = "text/html; charset=UTF-8";
return this.newResponse(html, status, headers);
}
redirect(location, status = 302) {
this._headers ?? (this._headers = new Headers());
this._headers.set("Location", location);
return this.newResponse(null, status);
}
cookie(name, value, opt) {
const cookie = serialize(name, value, opt);
this.header("set-cookie", cookie, { append: true });
}
notFound() {
return this.notFoundHandler(this);
}
get runtime() {

@@ -182,0 +189,0 @@ const global = globalThis;

@@ -23,3 +23,3 @@ // src/hono.ts

this._tempPath = "";
this.path = "/";
this.path = "*";
this.routes = [];

@@ -44,4 +44,4 @@ this.notFoundHandler = (c) => {

};
this.fetch = (request, Environment, executionCtx) => {
return this.dispatch(request, executionCtx, Environment);
this.fetch = (request, Env, executionCtx) => {
return this.dispatch(request, executionCtx, Env);
};

@@ -146,3 +146,3 @@ this.request = async (input, requestInit) => {

});
if (result && result.handlers.length === 1) {
if (result?.handlers.length === 1) {
const handler = result.handlers[0];

@@ -149,0 +149,0 @@ let res;

// src/request.ts
import { parseBody } from "./utils/body.js";
import { parse } from "./utils/cookie.js";
import { getQueryStringFromURL } from "./utils/url.js";
import { getQueryStringFromURL, getQueryParam, getQueryParams } from "./utils/url.js";
var HonoRequest = class {
constructor(request, paramData, queryIndex) {
constructor(request, paramData, queryIndex = -1) {
this.raw = request;

@@ -16,3 +16,3 @@ this.paramData = paramData;

const param = this.paramData[key];
return param ? decodeURIComponent(param) : void 0;
return param ? param.indexOf("%") !== -1 ? decodeURIComponent(param) : param : void 0;
} else {

@@ -22,3 +22,3 @@ const decoded = {};

if (value && typeof value === "string") {
decoded[key2] = decodeURIComponent(value);
decoded[key2] = value.indexOf("%") !== -1 ? decodeURIComponent(value) : value;
}

@@ -33,27 +33,7 @@ }

const queryString = getQueryStringFromURL(this.url, this.queryIndex);
const searchParams = new URLSearchParams(queryString);
if (!this.queryData) {
this.queryData = {};
for (const key2 of searchParams.keys()) {
this.queryData[key2] = searchParams.get(key2) || "";
}
}
if (key) {
return this.queryData[key];
} else {
return this.queryData;
}
return getQueryParam(queryString, key);
}
queries(key) {
const queryString = getQueryStringFromURL(this.url, this.queryIndex);
const searchParams = new URLSearchParams(queryString);
if (key) {
return searchParams.getAll(key);
} else {
const result = {};
for (const key2 of searchParams.keys()) {
result[key2] = searchParams.getAll(key2);
}
return result;
}
return getQueryParams(queryString, key);
}

@@ -60,0 +40,0 @@ header(name) {

@@ -1,2 +0,2 @@

import type { Environment, NotFoundHandler, ErrorHandler } from './types';
import type { Env, NotFoundHandler, ErrorHandler } from './types';
interface ComposeContext {

@@ -6,3 +6,3 @@ finalized: boolean;

}
export declare const compose: <C extends ComposeContext, E extends Partial<Environment> = Environment>(middleware: Function[], onNotFound?: NotFoundHandler<E, import("./types").Route> | undefined, onError?: ErrorHandler<E> | undefined) => (context: C, next?: Function) => C | Promise<C>;
export declare const compose: <C extends ComposeContext, E extends Env = Env>(middleware: Function[], onNotFound?: NotFoundHandler<E> | undefined, onError?: ErrorHandler<E> | undefined) => (context: C, next?: Function) => C | Promise<C>;
export {};
import { HonoRequest } from './request';
import type { TypeResponse, Route } from './types';
import type { Environment, NotFoundHandler } from './types';
import type { TypeResponse } from './types';
import type { Env, NotFoundHandler } from './types';
import type { CookieOptions } from './utils/cookie';

@@ -15,11 +15,11 @@ import type { StatusCode } from './utils/http-status';

}
declare type GetVariable<K, E extends Partial<Environment>> = K extends keyof E['Variables'] ? E['Variables'][K] : K extends keyof ContextVariableMap ? ContextVariableMap[K] : unknown;
declare type ContextOptions<E extends Partial<Environment>, R extends Route> = {
env?: E['Bindings'];
declare type GetVariable<K, E extends Env> = K extends keyof E['Variables'] ? E['Variables'][K] : K extends keyof ContextVariableMap ? ContextVariableMap[K] : unknown;
declare type ContextOptions<E extends Env> = {
env: E['Bindings'];
executionCtx?: FetchEvent | ExecutionContext | undefined;
notFoundHandler?: NotFoundHandler<E, R>;
notFoundHandler?: NotFoundHandler<E>;
paramData?: Record<string, string>;
queryIndex?: number;
};
export declare class Context<E extends Partial<Environment> = Environment, R extends Route = Route, I = any> {
export declare class Context<E extends Env = any, Path extends string = any, Schema = {}> {
env: E['Bindings'];

@@ -37,8 +37,8 @@ finalized: boolean;

private _res;
private _paramData;
private _paramData?;
private _queryIndex;
private rawRequest;
private rawRequest?;
private notFoundHandler;
constructor(req: Request, options?: ContextOptions<E, R>);
get req(): HonoRequest<R, I>;
constructor(req: Request, options?: ContextOptions<E>);
get req(): HonoRequest<Path, Schema>;
get event(): FetchEvent;

@@ -48,20 +48,20 @@ get executionCtx(): ExecutionContext;

set res(_res: Response);
header(name: string, value: string, options?: {
header: (name: string, value: string, options?: {
append?: boolean;
}): void;
status(status: StatusCode): void;
set<Key extends keyof E['Variables'] | keyof ContextVariableMap>(key: Key, value: GetVariable<Key, E>): void;
get<Key extends keyof E['Variables'] | keyof ContextVariableMap>(key: Key): GetVariable<Key, E>;
pretty(prettyJSON: boolean, space?: number): void;
newResponse(data: Data | null, status: StatusCode, headers?: HeaderRecord): Response;
body(data: Data | null, status?: StatusCode, headers?: HeaderRecord): Response;
text(text: string, status?: StatusCode, headers?: HeaderRecord): Response;
json<T>(object: T, status?: StatusCode, headers?: HeaderRecord): Response;
jsonT<T>(object: T, status?: StatusCode, headers?: HeaderRecord): TypeResponse<T>;
html(html: string, status?: StatusCode, headers?: HeaderRecord): Response;
redirect(location: string, status?: StatusCode): Response;
cookie(name: string, value: string, opt?: CookieOptions): void;
notFound(): Response | Promise<Response>;
}) => void;
status: (status: StatusCode) => void;
set: <Key extends keyof E["Variables"]>(key: Key, value: GetVariable<Key, E>) => void;
get: <Key extends keyof E["Variables"]>(key: Key) => GetVariable<Key, E>;
pretty: (prettyJSON: boolean, space?: number) => void;
newResponse: (data: Data | null, status?: StatusCode, headers?: HeaderRecord) => Response;
body: (data: Data | null, status?: StatusCode, headers?: HeaderRecord) => Response;
text: (text: string, status?: StatusCode, headers?: HeaderRecord) => Response;
json: <T>(object: T, status?: StatusCode, headers?: HeaderRecord) => Response;
jsonT: <T>(object: T, status?: StatusCode, headers?: HeaderRecord) => TypeResponse<T>;
html: (html: string, status?: StatusCode, headers?: HeaderRecord) => Response;
redirect: (location: string, status?: StatusCode) => Response;
cookie: (name: string, value: string, opt?: CookieOptions) => void;
notFound: () => Response | Promise<Response>;
get runtime(): Runtime;
}
export {};
import type { ExecutionContext } from './context';
import type { Router } from './router';
import type { HandlerInterface, ToAppType, Handler, ErrorHandler, NotFoundHandler, Environment, Route } from './types';
import type { HandlerInterface, ToAppType, Handler, ErrorHandler, NotFoundHandler, Env, Route, MiddlewareHandler } from './types';
interface RouterRoute {

@@ -9,13 +9,13 @@ path: string;

}
declare const Hono_base: new <E_1 extends Partial<Environment> = {}, _M extends string = string, P extends string = string, I_1 = {}, O_1 = {}>() => {
all: HandlerInterface<E_1, "all", P, I_1, O_1>;
get: HandlerInterface<E_1, "get", P, I_1, O_1>;
post: HandlerInterface<E_1, "post", P, I_1, O_1>;
put: HandlerInterface<E_1, "put", P, I_1, O_1>;
delete: HandlerInterface<E_1, "delete", P, I_1, O_1>;
head: HandlerInterface<E_1, "head", P, I_1, O_1>;
options: HandlerInterface<E_1, "options", P, I_1, O_1>;
patch: HandlerInterface<E_1, "patch", P, I_1, O_1>;
declare const Hono_base: new <E_1 extends Env = Env, _M extends string = string, P extends string = any>() => {
all: HandlerInterface<E_1, "all", P>;
get: HandlerInterface<E_1, "get", P>;
post: HandlerInterface<E_1, "post", P>;
put: HandlerInterface<E_1, "put", P>;
delete: HandlerInterface<E_1, "delete", P>;
head: HandlerInterface<E_1, "head", P>;
options: HandlerInterface<E_1, "options", P>;
patch: HandlerInterface<E_1, "patch", P>;
};
export declare class Hono<E extends Partial<Environment> = {}, R extends Route = Route, I = {}, O = {}> extends Hono_base<E, R['method'], R['path'], I, O> {
export declare class Hono<E extends Env = Env, R extends Route = Route, I = {}, O = {}> extends Hono_base<E, R['method'], R['path']> {
readonly router: Router<Handler>;

@@ -29,17 +29,14 @@ readonly strict: boolean;

private errorHandler;
route(path: string, app?: Hono<any>): this;
use(...middleware: Handler<E>[]): Hono<E, {
route(path: string, app?: Hono<any, any>): this;
use(...middleware: MiddlewareHandler<E>[]): Hono<E, {
method: 'all';
path: string;
}, I, O>;
use<Path extends string, E2 extends Partial<Environment> = E>(arg1: Path, ...middleware: Handler<E2>[]): Hono<E, {
use<Path extends string>(arg1: Path, ...middleware: MiddlewareHandler<E>[]): Hono<E, {
method: 'all';
path: Path;
}, I, O>;
on<Method extends string, Path extends string>(method: Method, path: Path, ...handlers: Handler<E, {
on<Method extends string, Path extends string>(method: Method, path: Path, ...handlers: Handler<E, Path>[]): Hono<E, {
method: Method;
path: Path;
}>[]): Hono<E, {
method: Method;
path: Path;
}, I, O>;

@@ -55,5 +52,5 @@ build: () => ToAppType<typeof this>;

handleEvent: (event: FetchEvent) => Response | Promise<Response>;
fetch: (request: Request, Environment?: E['Bindings'], executionCtx?: ExecutionContext) => Response | Promise<Response>;
fetch: (request: Request, Env?: E['Bindings'], executionCtx?: ExecutionContext) => Response | Promise<Response>;
request: (input: Request | string, requestInit?: RequestInit) => Promise<Response>;
}
export {};
import type { Context } from '../../context';
import type { Environment, Next, Route, ValidationTypes } from '../../types';
declare type ValidatorHandler<E extends Partial<Environment>, R extends Route = Route, I = unknown> = (c: Context<E, R, I>, next: Next) => Promise<Response | undefined | void> | Response;
import type { Env, ValidationTypes, MiddlewareHandler } from '../../types';
declare type ValidationTypeKeysWithBody = 'form' | 'json';
declare type ValidationTypeByMethod<M> = M extends 'get' | 'head' ? Exclude<keyof ValidationTypes, ValidationTypeKeysWithBody> : keyof ValidationTypes;
export declare const validator: <T, Method extends string, U extends ValidationTypeByMethod<Method>, V extends {
export declare const validator: <T, Path extends string, Method extends string, U extends ValidationTypeByMethod<Method>, V extends {
type: U;
data: T;
}, V2 = {}, E extends Partial<Environment> = Environment>(type: U, validationFunc: (value: ValidationTypes[U], c: Context<E, Route, any>) => Response | Promise<Response> | T) => ValidatorHandler<E, {
method: Method;
path: string;
}, V | V2>;
}, V2 = {}, E extends Env = any>(type: U, validationFunc: (value: ValidationTypes[U], c: Context<E, any, {}>) => Response | Promise<Response> | T) => MiddlewareHandler<E, Path, V | V2>;
export {};

@@ -1,9 +0,8 @@

import type { GetParamKeys, InputToData, Route } from './types';
import type { InputToData, ParamKeys } from './types';
import type { BodyData } from './utils/body';
import type { Cookie } from './utils/cookie';
export declare class HonoRequest<R extends Route = Route, I = any> {
export declare class HonoRequest<Path extends string = '/', Input = {}> {
raw: Request;
private paramData;
private headerData;
private queryData;
private bodyData;

@@ -14,4 +13,4 @@ private jsonData;

constructor(request: Request, paramData?: Record<string, string> | undefined, queryIndex?: number);
param(key: GetParamKeys<R['path']>): string;
param(): Record<GetParamKeys<R['path']>, string>;
param(key: ParamKeys<Path>): string;
param(): Record<ParamKeys<Path>, string>;
query(key: string): string;

@@ -31,3 +30,3 @@ query(): Record<string, string>;

formData(): Promise<FormData>;
valid(data?: unknown): InputToData<I>;
valid(data?: unknown): InputToData<Input>;
get url(): string;

@@ -34,0 +33,0 @@ get method(): string;

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

export declare type Variables = Record<string, unknown>;
export declare type Environment = {
Bindings: Bindings;
Variables: Variables;
export declare type Env = {
Bindings?: Bindings;
Variables?: Variables;
};
declare type Env = Partial<Environment>;
declare type I = {};
declare type O = {};
export declare type Route = {

@@ -17,32 +14,20 @@ path: string;

};
export declare type Handler<E extends Env = Environment, R extends Route = Route, I = {}, O = {}> = (c: Context<E, R, I>, next: Next) => Response | Promise<Response | void | TypeResponse<O>> | TypeResponse<O>;
export interface HandlerInterface<E extends Env = Env, M extends string = string, P extends string = string, _I = {}, _O = {}> {
<Input = I, Output = O>(...handlers: Handler<E, {
export declare type Handler<E extends Env = any, P extends string = any, I = {}, O = {}> = (c: Context<E, P, I>, next: Next) => Response | Promise<Response | void | TypeResponse<O>> | TypeResponse<O>;
export interface HandlerInterface<E extends Env = Env, M extends string = any, P extends string = any> {
<Input = {}, Output = {}>(...handlers: (Handler<E, P, Input, Output> | MiddlewareHandler<E, P, Input>)[]): Hono<E, {
method: M;
path: string;
}, Input, Output>[]): Hono<E, {
method: M;
path: string;
path: P;
}, Input, Output>;
(...handlers: Handler<any, any>[]): Hono;
<Input = I, Output = O, Path extends string = P>(path: Path, ...handlers: Handler<E, {
<Path extends string, Input = {}, Output = {}>(path: Path, ...handlers: (Handler<E, Path, Input, Output> | MiddlewareHandler<E, Path, Input>)[]): Hono<E, {
method: M;
path: Path;
}, Input, Output>[]): Hono<E, {
method: M;
path: Path;
}, Input, Output>;
<Input = I, Output = O, Path extends string = P>(path: Path, ...handlers: Handler<any, any, Input, Output>[]): Hono<E, {
method: M;
path: Path;
}, Input, Output>;
}
export declare type ExtractType<T> = T extends TypeResponse<infer R> ? R : T extends Promise<TypeResponse<infer R>> ? R : never;
declare type ParamKeyName<NameWithPattern> = NameWithPattern extends `${infer Name}{${infer _Pattern}` ? Name : NameWithPattern;
declare type ParamKey<Component> = Component extends `:${infer NameWithPattern}` ? ParamKeyName<NameWithPattern> : never;
declare type ParamKeys<Path> = Path extends `${infer Component}/${infer Rest}` ? ParamKey<Component> | ParamKeys<Rest> : ParamKey<Path>;
export declare type GetParamKeys<Path> = ParamKeys<Path> extends never ? Path : ParamKeys<Path>;
export declare type MiddlewareHandler<E extends Env = Env, R extends Route = Route, S = unknown> = (c: Context<E, R, S>, next: Next) => Promise<Response | undefined | void>;
export declare type NotFoundHandler<E extends Env = Environment, R extends Route = Route> = (c: Context<E, R>) => Response | Promise<Response>;
export declare type ErrorHandler<E extends Env = Environment> = (err: Error, c: Context<E>) => Response;
declare type ParamKey<Component> = Component extends `:${infer NameWithPattern}?` ? ParamKeyName<NameWithPattern> : Component extends `:${infer NameWithPattern}` ? ParamKeyName<NameWithPattern> : never;
export declare type ParamKeys<Path> = Path extends `${infer Component}/${infer Rest}` ? ParamKey<Component> | ParamKeys<Rest> : ParamKey<Path>;
export declare type MiddlewareHandler<E extends Env = any, P extends string = any, I = {}> = (c: Context<E, P, I>, next: Next) => Promise<Response | undefined | void>;
export declare type NotFoundHandler<E extends Env = any> = (c: Context<E>) => Response | Promise<Response>;
export declare type ErrorHandler<E extends Env = any> = (err: Error, c: Context<E>) => Response;
export declare type Next = () => Promise<void>;

@@ -54,7 +39,4 @@ export declare type TypeResponse<T = unknown> = {

};
export interface CustomHandler<E = Env, R = Route, I = any> {
(c: Context<E extends Env ? E : Env, E extends Route ? E : R extends Route ? R : R extends string ? {
path: R;
method: string;
} : never, E extends Env ? R extends Route | string ? I : E extends Env ? E : never : E extends Route | string ? R extends Env ? E : R : E>, next: Next): Response | Promise<Response | undefined | void>;
export interface CustomHandler<E = Env, P = any, I = any> {
(c: Context<E extends Env ? E : Env, E extends string ? E : P extends string ? P : never, E extends Env ? P extends string ? I : E extends Env ? E : never : E extends Route | string ? P extends Env ? E : P : E>, next: Next): Response | Promise<Response | undefined | void>;
}

@@ -61,0 +43,0 @@ export declare type ValidationTypes = {

@@ -6,4 +6,6 @@ export declare type Pattern = readonly [string, string, RegExp | true] | '*';

export declare const getPathFromURL: (url: string, strict?: boolean) => [string, number];
export declare const getQueryStringFromURL: (url: string, queryIndex?: number) => string;
export declare const getQueryStringFromURL: (url: string, queryIndex: number) => string;
export declare const mergePath: (...paths: string[]) => string;
export declare const checkOptionalParameter: (path: string) => string[] | null;
export declare const getQueryParam: (queryString: string, key?: string) => string | null | Record<string, string>;
export declare const getQueryParams: (queryString: string, key?: string) => string[] | null | Record<string, string[]>;

@@ -15,6 +15,3 @@ // src/utils/mime.ts

aac: "audio/aac",
abw: "application/x-abiword",
arc: "application/x-freearc",
avi: "video/x-msvideo",
azw: "application/vnd.amazon.ebook",
bin: "application/octet-stream",

@@ -24,3 +21,2 @@ bmp: "image/bmp",

bz2: "application/x-bzip2",
csh: "application/x-csh",
css: "text/css",

@@ -50,10 +46,4 @@ csv: "text/csv",

mpeg: "video/mpeg",
mpkg: "application/vnd.apple.installer+xml",
odp: "application/vnd.oasis.opendocument.presentation",
ods: "application/vnd.oasis.opendocument.spreadsheet",
odt: "application/vnd.oasis.opendocument.text",
oga: "audio/ogg",
ogv: "video/ogg",
ogx: "application/ogg",
opus: "audio/opus",
otf: "font/otf",

@@ -66,15 +56,9 @@ png: "image/png",

rar: "application/vnd.rar",
rtf: "application/rtf",
sh: "application/x-sh",
svg: "image/svg+xml",
swf: "application/x-shockwave-flash",
tar: "application/x-tar",
tif: "image/tiff",
tiff: "image/tiff",
ts: "video/mp2t",
ttf: "font/ttf",
txt: "text/plain",
vsd: "application/vnd.visio",
wav: "audio/wav",
weba: "audio/webm",
webm: "video/webm",

@@ -88,3 +72,2 @@ webp: "image/webp",

xml: "application/xml",
xul: "application/vnd.mozilla.xul+xml",
zip: "application/zip",

@@ -91,0 +74,0 @@ "3gp": "video/3gpp",

// src/utils/url.ts
var splitPath = (path) => {
const paths = path.split(/\//);
const paths = path.split("/");
if (paths[0] === "") {

@@ -24,3 +24,3 @@ paths.shift();

}
const paths = path.split(/\//);
const paths = path.split("/");
if (paths[0] === "") {

@@ -67,4 +67,3 @@ paths.shift();

var getQueryStringFromURL = (url, queryIndex) => {
queryIndex || (queryIndex = url.indexOf("?"));
const result = queryIndex !== -1 ? url.substring(queryIndex) : "";
const result = queryIndex !== -1 ? url.slice(queryIndex + 1) : "";
return result;

@@ -102,2 +101,54 @@ };

};
var filterQueryString = (queryString) => {
const fragIndex = queryString.indexOf("#");
if (fragIndex !== -1) {
queryString = queryString.slice(0, fragIndex);
}
return queryString;
};
var getQueryParam = (queryString, key) => {
queryString = filterQueryString(queryString);
const results = {};
while (true) {
const andIndex = queryString.indexOf("&");
let strings = "";
if (andIndex === -1) {
strings = queryString;
} else {
strings = queryString.slice(0, andIndex);
}
const eqIndex = strings.indexOf("=");
if (eqIndex !== -1) {
const v = strings.slice(eqIndex + 1);
const k = strings.slice(0, eqIndex);
if (key === k) {
return v.indexOf("%") !== -1 ? decodeURI(v) : v;
} else {
results[k] || (results[k] = v);
}
} else if (strings === key) {
return "";
}
if (andIndex === -1)
break;
queryString = queryString.slice(andIndex + 1, queryString.length);
}
if (key)
return null;
return results;
};
var getQueryParams = (queryString, key) => {
queryString = filterQueryString(queryString);
const results = {};
for (const strings of queryString.split("&")) {
let [k, v] = strings.split("=");
if (v === void 0)
v = "";
results[k] || (results[k] = []);
results[k].push(v.indexOf("%") !== -1 ? decodeURI(v) : v);
}
if (key)
return results[key] ? results[key] : null;
return results;
};
export {

@@ -107,2 +158,4 @@ checkOptionalParameter,

getPattern,
getQueryParam,
getQueryParams,
getQueryStringFromURL,

@@ -109,0 +162,0 @@ mergePath,

{
"name": "hono",
"version": "3.0.0-rc.5",
"version": "3.0.0-rc.6",
"description": "Ultrafast web framework for Cloudflare Workers, Deno, and Bun.",

@@ -105,16 +105,2 @@ "main": "dist/cjs/index.js",

},
"./serve-static": {
"types": "./dist/types/middleware/serve-static/index.d.ts",
"import": "./dist/middleware/serve-static/index.js",
"require": "./dist/cjs/middleware/serve-static/index.js"
},
"./serve-static.bun": {
"types": "./dist/types/middleware/serve-static/bun.d.ts",
"import": "./dist/middleware/serve-static/bun.js",
"require": "./dist/cjs/middleware/serve-static/bun.js"
},
"./serve-static.module": {
"types": "./dist/types/middleware/serve-static/module.d.ts",
"import": "./dist/middleware/serve-static/module.js"
},
"./validator": {

@@ -154,2 +140,22 @@ "types": "./dist/types/middleware/validator/index.d.ts",

"require": "./dist/cjs/utils/*.js"
},
"./cloudflare-workers": {
"types": "./dist/types/adapter/cloudflare-workers/index.d.ts",
"import": "./dist/adapter/cloudflare-workers/index.js",
"require": "./dist/cjs/adapter/cloudflare-workers/index.js"
},
"./cloudflare-pages": {
"types": "./dist/types/adapter/cloudflare-pages/index.d.ts",
"import": "./dist/adapter/cloudflare-pages/index.js",
"require": "./dist/cjs/adapter/cloudflare-pages/index.js"
},
"./bun": {
"types": "./dist/types/adapter/bun/index.d.ts",
"import": "./dist/adapter/bun/index.js",
"require": "./dist/cjs/adapter/bun/index.js"
},
"./nextjs": {
"types": "./dist/types/adapter/nextjs/index.d.ts",
"import": "./dist/adapter/nextjs/index.js",
"require": "./dist/cjs/adapter/nextjs/index.js"
}

@@ -230,2 +236,14 @@ },

"./dist/types/utils/*"
],
"cloudflare-workers": [
"./dist/types/adapter/cloudflare-workers"
],
"cloudflare-pages": [
"./dist/types/adapter/cloudflare-pages"
],
"bun": [
"./dist/types/adapter/bun"
],
"nextjs": [
"./dist/types/adapter/nextjs"
]

@@ -232,0 +250,0 @@ }

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