Skip to content
Myr

fix(context): use `FetchEvent` instead of `FetchEventLike` (#1532)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Yusuke Wada · committed by GitHub · parent 82f1033 · Browse files · 5 files+25 added−15 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+25 added−15 removed

  • other:+25 added−15 removed

5 files+25 added−15 removed

modified:deno_dist/context.ts+8 added-5 removed
1/// <reference lib="es2022" />2/// <reference lib="webworker" />3// We need these triple slashes to correctly refer to `FetchEvent` in Deno.45import type { HonoRequest } from './request.ts'2import { FetchEventLike } from './types.ts'6import type { Env, NotFoundHandler, Input, TypedResponse } from './types.ts'7import type { CookieOptions } from './utils/cookie.ts'8import { serialize } from './utils/cookie.ts'9import type { StatusCode } from './utils/http-status.ts'
74 unmodified lines
84}8586type ContextOptions<E extends Env> = {87 env: E['Bindings']85 executionCtx?: FetchEventLike | ExecutionContext | undefined88 executionCtx?: FetchEvent | ExecutionContext | undefined89 notFoundHandler?: NotFoundHandler<E>90}9192const TEXT_PLAIN = 'text/plain; charset=UTF-8'
11 unmodified lines
104 finalized: boolean = false105 error: Error | undefined = undefined106107 private _status: StatusCode = 200105 private _exCtx: FetchEventLike | ExecutionContext | undefined // _executionCtx108 private _exCtx: FetchEvent | ExecutionContext | undefined // _executionCtx109 private _h: Headers | undefined = undefined // _headers110 private _pH: Record<string, string> | undefined = undefined // _preparedHeaders111 private _res: Response | undefined112 private _init = true
10 unmodified lines
123 }124 }125 }126124 get event(): FetchEventLike {125 if (this._exCtx instanceof FetchEventLike) {127 get event(): FetchEvent {128 if (this._exCtx instanceof FetchEvent) {129 return this._exCtx130 } else {131 throw Error('This context has no FetchEvent')132 }
343 unmodified lines
modified:src/context.ts+8 added-5 removed
1/// <reference lib="es2022" />2/// <reference lib="webworker" />3// We need these triple slashes to correctly refer to `FetchEvent` in Deno.45import type { HonoRequest } from './request'2import { FetchEventLike } from './types'6import type { Env, NotFoundHandler, Input, TypedResponse } from './types'7import type { CookieOptions } from './utils/cookie'8import { serialize } from './utils/cookie'9import type { StatusCode } from './utils/http-status'
74 unmodified lines
84}8586type ContextOptions<E extends Env> = {87 env: E['Bindings']85 executionCtx?: FetchEventLike | ExecutionContext | undefined88 executionCtx?: FetchEvent | ExecutionContext | undefined89 notFoundHandler?: NotFoundHandler<E>90}9192const TEXT_PLAIN = 'text/plain; charset=UTF-8'
11 unmodified lines
104 finalized: boolean = false105 error: Error | undefined = undefined106107 private _status: StatusCode = 200105 private _exCtx: FetchEventLike | ExecutionContext | undefined // _executionCtx108 private _exCtx: FetchEvent | ExecutionContext | undefined // _executionCtx109 private _h: Headers | undefined = undefined // _headers110 private _pH: Record<string, string> | undefined = undefined // _preparedHeaders111 private _res: Response | undefined112 private _init = true
10 unmodified lines
123 }124 }125 }126124 get event(): FetchEventLike {125 if (this._exCtx instanceof FetchEventLike) {127 get event(): FetchEvent {128 if (this._exCtx instanceof FetchEvent) {129 return this._exCtx130 } else {131 throw Error('This context has no FetchEvent')132 }
343 unmodified lines
modified:package.json+1 added-1 removed
396 unmodified lines
397 "@hono/node-server": "^1.0.2",398 "@types/crypto-js": "^4.1.1",399 "@types/glob": "^8.0.0",400 "@types/jest": "^29.4.0",401 "@types/node": "^17.0.29",401 "@types/node": "^20.8.2",402 "@types/node-fetch": "^2.6.2",403 "@types/supertest": "^2.0.12",404 "@typescript-eslint/eslint-plugin": "^5.59.2",405 "@typescript-eslint/parser": "^5.59.2",
37 unmodified lines
modified:tsconfig.json+4 added
modified:yarn.lock+4 added-4 removed
1708 unmodified lines
1709 version "17.0.13"1710 resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.13.tgz#5ed7ed7c662948335fcad6c412bb42d99ea754e3"1711 integrity sha512-Y86MAxASe25hNzlDbsviXl8jQHb0RDvKt4c40ZJQ1Don0AAL0STLZSs4N+6gLEO55pedy7r2cLwS+ZDxPm/2Bw==17121713"@types/node@^17.0.29":1714 version "17.0.29"1715 resolved "https://registry.yarnpkg.com/@types/node/-/node-17.0.29.tgz#7f2e1159231d4a077bb660edab0fde373e375a3d"1716 integrity sha512-tx5jMmMFwx7wBwq/V7OohKDVb/JwJU5qCVkeLMh1//xycAJ/ESuw9aJ9SEtlCZDYi2pBfe4JkisSoAtbOsBNAA==1713"@types/node@^20.8.2":1714 version "20.8.2"1715 resolved "https://registry.yarnpkg.com/@types/node/-/node-20.8.2.tgz#d76fb80d87d0d8abfe334fc6d292e83e5524efc4"1716 integrity sha512-Vvycsc9FQdwhxE3y3DzeIxuEJbWGDsnrxvMADzTDF/lcdR9/K+AQIeAghTQsHtotg/q0j3WEOYS/jQgSdWue3w==17171718"@types/normalize-package-data@^2.4.0":1719 version "2.4.1"1720 resolved "https://registry.yarnpkg.com/@types/normalize-package-data/-/normalize-package-data-2.4.1.tgz#d3357479a0fdfdd5907fe67e17e0a85c906e1301"
6355 unmodified lines