Comparing version 1.5.2 to 1.6.0-0
/// <reference types="@cloudflare/workers-types" /> | ||
import type { NotFoundHandler } from './hono'; | ||
import type { HonoRequest } from './request'; | ||
import type { StatusCode } from './utils/http-status'; | ||
@@ -9,3 +8,3 @@ declare type Headers = Record<string, string>; | ||
export declare class Context<RequestParamKeyType extends string = string, E = Env> { | ||
req: HonoRequest<RequestParamKeyType>; | ||
req: Request<RequestParamKeyType>; | ||
env: E; | ||
@@ -22,4 +21,3 @@ event: FetchEvent | undefined; | ||
private notFoundHandler; | ||
render: (content: string, params?: object, options?: object) => Response | Promise<Response>; | ||
constructor(req: HonoRequest | Request, env?: E | undefined, eventOrExecutionCtx?: FetchEvent | ExecutionContext | undefined, notFoundHandler?: NotFoundHandler); | ||
constructor(req: Request, env?: E | undefined, eventOrExecutionCtx?: FetchEvent | ExecutionContext | undefined, notFoundHandler?: NotFoundHandler); | ||
get res(): Response; | ||
@@ -35,3 +33,3 @@ set res(_res: Response); | ||
text(text: string, status?: StatusCode, headers?: Headers): Response; | ||
json(object: object, status?: StatusCode, headers?: Headers): Response; | ||
json<T>(object: T, status?: StatusCode, headers?: Headers): Response; | ||
html(html: string, status?: StatusCode, headers?: Headers): Response; | ||
@@ -38,0 +36,0 @@ redirect(location: string, status?: StatusCode): Response; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Context = void 0; | ||
const request_1 = require("./request"); | ||
const url_1 = require("./utils/url"); | ||
@@ -11,15 +10,10 @@ class Context { | ||
this._prettySpace = 2; | ||
if (req instanceof Request) { | ||
this.req = (0, request_1.extendHonoRequest)(req); | ||
this.req = req; | ||
this.env = env ? env : {}; | ||
if (eventOrExecutionCtx && 'respondWith' in eventOrExecutionCtx) { | ||
this.event = eventOrExecutionCtx; | ||
} | ||
else { | ||
this.req = req; | ||
this.executionCtx = eventOrExecutionCtx; | ||
} | ||
if (env) { | ||
this.env = env; | ||
} | ||
this.executionCtx = eventOrExecutionCtx; | ||
if (eventOrExecutionCtx && 'respondWith' in eventOrExecutionCtx) { | ||
this.event = eventOrExecutionCtx; | ||
} | ||
this.notFoundHandler = notFoundHandler; | ||
@@ -26,0 +20,0 @@ this.finalized = false; |
@@ -53,4 +53,3 @@ /// <reference types="@cloudflare/workers-types" /> | ||
request(input: RequestInfo, requestInit?: RequestInit): Promise<Response>; | ||
fire(): void; | ||
} | ||
export {}; |
@@ -32,2 +32,3 @@ "use strict"; | ||
}; | ||
(0, request_1.extendRequestPrototype)(); | ||
const allMethods = [...methods, router_1.METHOD_NAME_ALL_LOWERCASE]; | ||
@@ -94,4 +95,3 @@ allMethods.map((method) => { | ||
} | ||
async dispatch(request, executionCtx, env) { | ||
request = (0, request_1.extendHonoRequest)(request); | ||
async dispatch(request, eventOrExecutionCtx, env) { | ||
const path = (0, url_1.getPathFromURL)(request.url, this.strict); | ||
@@ -102,3 +102,3 @@ const method = request.method; | ||
const handlers = result ? result.handlers : [this.notFoundHandler]; | ||
const c = new context_1.Context(request, env, executionCtx, this.notFoundHandler); | ||
const c = new context_1.Context(request, env, eventOrExecutionCtx, this.notFoundHandler); | ||
const composed = (0, compose_1.compose)(handlers, this.errorHandler, this.notFoundHandler); | ||
@@ -130,8 +130,3 @@ let context; | ||
} | ||
fire() { | ||
addEventListener('fetch', (event) => { | ||
event.respondWith(this.handleEvent(event)); | ||
}); | ||
} | ||
} | ||
exports.Hono = Hono; |
/// <reference path="request.d.ts" /> | ||
export { Hono } from './hono'; | ||
import { Hono } from './hono'; | ||
export type { Handler, Next } from './hono'; | ||
export { Context } from './context'; | ||
export type { Env } from './context'; | ||
declare module './hono' { | ||
interface Hono { | ||
fire(): void; | ||
} | ||
} | ||
export { Hono }; |
@@ -5,6 +5,11 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Context = exports.Hono = void 0; | ||
var hono_1 = require("./hono"); | ||
exports.Hono = exports.Context = void 0; | ||
const hono_1 = require("./hono"); | ||
Object.defineProperty(exports, "Hono", { enumerable: true, get: function () { return hono_1.Hono; } }); | ||
var context_1 = require("./context"); | ||
Object.defineProperty(exports, "Context", { enumerable: true, get: function () { return context_1.Context; } }); | ||
hono_1.Hono.prototype.fire = function () { | ||
addEventListener('fetch', (event) => { | ||
void event.respondWith(this.handleEvent(event)); | ||
}); | ||
}; |
import type { Context } from '../../context'; | ||
import type { Next } from '../../hono'; | ||
declare module '../../request' { | ||
interface HonoRequest { | ||
declare global { | ||
interface Request { | ||
parsedBody: any; | ||
@@ -6,0 +6,0 @@ } |
import type { Context } from '../../context'; | ||
import type { Next } from '../../hono'; | ||
declare module '../../request' { | ||
interface HonoRequest { | ||
declare global { | ||
interface Request { | ||
cookie: { | ||
@@ -6,0 +6,0 @@ (name: string): string; |
/// <reference types="@cloudflare/workers-types" /> | ||
import type { Context } from '../../context'; | ||
import type { Next } from '../../hono'; | ||
declare module '../../context' { | ||
interface Context { | ||
render: (content: string, params?: object, options?: object) => Response | Promise<Response>; | ||
} | ||
} | ||
export declare type MustacheOptions = { | ||
@@ -5,0 +10,0 @@ root: string; |
@@ -1,20 +0,22 @@ | ||
export declare class HonoRequest<ParamKeyType extends string = string> extends Request { | ||
param: { | ||
(key: ParamKeyType): string; | ||
(): Record<ParamKeyType, string>; | ||
}; | ||
paramData?: Record<ParamKeyType, string>; | ||
query: { | ||
(key: string): string; | ||
(): Record<string, string>; | ||
}; | ||
queries: { | ||
(key: string): string[]; | ||
(): Record<string, string[]>; | ||
}; | ||
header: { | ||
(name: string): string; | ||
(): Record<string, string>; | ||
}; | ||
declare global { | ||
interface Request<ParamKeyType extends string = string> { | ||
param: { | ||
(key: ParamKeyType): string; | ||
(): Record<ParamKeyType, string>; | ||
}; | ||
paramData?: Record<ParamKeyType, string>; | ||
query: { | ||
(key: string): string; | ||
(): Record<string, string>; | ||
}; | ||
queries: { | ||
(key: string): string[]; | ||
(): Record<string, string[]>; | ||
}; | ||
header: { | ||
(name: string): string; | ||
(): Record<string, string>; | ||
}; | ||
} | ||
} | ||
export declare function extendHonoRequest(request: HonoRequest): HonoRequest; | ||
export declare function extendRequestPrototype(): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.extendHonoRequest = exports.HonoRequest = void 0; | ||
class HonoRequest extends Request { | ||
} | ||
exports.HonoRequest = HonoRequest; | ||
function extendHonoRequest(request) { | ||
request.param = function (key) { | ||
exports.extendRequestPrototype = void 0; | ||
function extendRequestPrototype() { | ||
if (!!Request.prototype.param) { | ||
// already extended | ||
return; | ||
} | ||
Request.prototype.param = function (key) { | ||
if (this.paramData) { | ||
@@ -19,3 +20,3 @@ if (key) { | ||
}; | ||
request.header = function (name) { | ||
Request.prototype.header = function (name) { | ||
if (name) { | ||
@@ -32,3 +33,3 @@ return this.headers.get(name); | ||
}; | ||
request.query = function (key) { | ||
Request.prototype.query = function (key) { | ||
const url = new URL(this.url); | ||
@@ -46,3 +47,3 @@ if (key) { | ||
}; | ||
request.queries = function (key) { | ||
Request.prototype.queries = function (key) { | ||
const url = new URL(this.url); | ||
@@ -60,4 +61,3 @@ if (key) { | ||
}; | ||
return request; | ||
} | ||
exports.extendHonoRequest = extendHonoRequest; | ||
exports.extendRequestPrototype = extendRequestPrototype; |
@@ -25,2 +25,3 @@ "use strict"; | ||
this.methods = []; | ||
this.name = ''; | ||
if (method && handler) { | ||
@@ -27,0 +28,0 @@ const m = {}; |
{ | ||
"name": "hono", | ||
"version": "1.5.2", | ||
"version": "1.6.0-0", | ||
"description": "Ultrafast web framework for Cloudflare Workers.", | ||
@@ -14,5 +14,7 @@ "main": "dist/index.js", | ||
"lint:fix": "eslint --ext js,ts src .eslintrc.js --fix", | ||
"denoify": "rimraf deno_dist && denoify", | ||
"build": "rimraf dist && tsc --project tsconfig.build.esm.json && tsc --project tsconfig.build.json", | ||
"watch": "tsc --project tsconfig.build.json -w", | ||
"prepublishOnly": "yarn build" | ||
"prerelease": "yarn denoify && yarn build", | ||
"release": "np" | ||
}, | ||
@@ -116,2 +118,5 @@ "exports": { | ||
}, | ||
"publishConfig": { | ||
"registry": "https://registry.npmjs.org" | ||
}, | ||
"homepage": "https://github.com/honojs/hono", | ||
@@ -139,2 +144,3 @@ "keywords": [ | ||
"crypto-js": "^4.1.1", | ||
"denoify": "^0.11.1", | ||
"eslint": "^8.14.0", | ||
@@ -153,2 +159,3 @@ "eslint-config-prettier": "^8.5.0", | ||
"mustache": "^4.2.0", | ||
"np": "^7.6.2", | ||
"prettier": "^2.6.2", | ||
@@ -163,2 +170,2 @@ "prettier-plugin-md-nocjsp": "^1.2.0", | ||
} | ||
} | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
133413
3005
28
1