Skip to content
Myr

fix(context): change `FetchEvent` detection way (#1595)

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

* fix(context): change `FetchEvent` detection way * denoify

authored by Yusuke Wada · committed by GitHub · parent 46b9b53 · Browse files · 5 files+15 added−20 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+15 added−20 removed

  • other:+15 added−20 removed

5 files+15 added−20 removed

modified:deno_dist/context.ts+5 added-6 removed
1import type { HonoRequest } from './request.ts'2import type { Env, NotFoundHandler, Input, TypedResponse } from './types.ts'3import { FetchEvent } from './types.ts'2import type { Env, FetchEventLike, NotFoundHandler, Input, TypedResponse } from './types.ts'3import type { CookieOptions } from './utils/cookie.ts'4import { serialize } from './utils/cookie.ts'5import type { StatusCode } from './utils/http-status.ts'6import { StreamingApi } from './utils/stream.ts'
73 unmodified lines
80}8182type ContextOptions<E extends Env> = {83 env: E['Bindings']85 executionCtx?: FetchEvent | ExecutionContext | undefined84 executionCtx?: FetchEventLike | ExecutionContext | undefined85 notFoundHandler?: NotFoundHandler<E>86}8788const TEXT_PLAIN = 'text/plain; charset=UTF-8'
11 unmodified lines
100 finalized: boolean = false101 error: Error | undefined = undefined102103 private _status: StatusCode = 200105 private _exCtx: FetchEvent | ExecutionContext | undefined // _executionCtx104 private _exCtx: FetchEventLike | ExecutionContext | undefined // _executionCtx105 private _h: Headers | undefined = undefined // _headers106 private _pH: Record<string, string> | undefined = undefined // _preparedHeaders107 private _res: Response | undefined108 private _init = true
10 unmodified lines
119 }120 }121 }122124 get event(): FetchEvent {125 if (this._exCtx instanceof FetchEvent) {123 get event(): FetchEventLike {124 if (this._exCtx && 'respondWith' in this._exCtx) {125 return this._exCtx126 } else {127 throw Error('This context has no FetchEvent')128 }
343 unmodified lines
modified:deno_dist/types.ts-2 removed
590 unmodified lines
591 abstract respondWith(promise: Response | Promise<Response>): void592 abstract passThroughOnException(): void593 abstract waitUntil(promise: Promise<void>): void594}595596export abstract class FetchEvent extends FetchEventLike {}
modified:src/adapter/vercel/handler.ts+5 added-4 removed
modified:src/context.ts+5 added-6 removed
1import type { HonoRequest } from './request'2import type { Env, NotFoundHandler, Input, TypedResponse } from './types'3import { FetchEvent } from './types'2import type { Env, FetchEventLike, NotFoundHandler, Input, TypedResponse } from './types'3import type { CookieOptions } from './utils/cookie'4import { serialize } from './utils/cookie'5import type { StatusCode } from './utils/http-status'6import { StreamingApi } from './utils/stream'
73 unmodified lines
80}8182type ContextOptions<E extends Env> = {83 env: E['Bindings']85 executionCtx?: FetchEvent | ExecutionContext | undefined84 executionCtx?: FetchEventLike | ExecutionContext | undefined85 notFoundHandler?: NotFoundHandler<E>86}8788const TEXT_PLAIN = 'text/plain; charset=UTF-8'
11 unmodified lines
100 finalized: boolean = false101 error: Error | undefined = undefined102103 private _status: StatusCode = 200105 private _exCtx: FetchEvent | ExecutionContext | undefined // _executionCtx104 private _exCtx: FetchEventLike | ExecutionContext | undefined // _executionCtx105 private _h: Headers | undefined = undefined // _headers106 private _pH: Record<string, string> | undefined = undefined // _preparedHeaders107 private _res: Response | undefined108 private _init = true
10 unmodified lines
119 }120 }121 }122124 get event(): FetchEvent {125 if (this._exCtx instanceof FetchEvent) {123 get event(): FetchEventLike {124 if (this._exCtx && 'respondWith' in this._exCtx) {125 return this._exCtx126 } else {127 throw Error('This context has no FetchEvent')128 }
343 unmodified lines
modified:src/types.ts-2 removed
590 unmodified lines
591 abstract respondWith(promise: Response | Promise<Response>): void592 abstract passThroughOnException(): void593 abstract waitUntil(promise: Promise<void>): void594}595596export abstract class FetchEvent extends FetchEventLike {}