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
Provenance
- Commit
850ae92- Tree
c2fbe28- Author
Yusuke Wada <yusuke@kamawada.com>- Committer
GitHub <noreply@github.com>- Parent
46b9b53
5 files changed+15 added−20 removed
modified:deno_dist/context.ts+5 added-6 removed
1 import type { HonoRequest } from './request.ts'2-import type { Env, NotFoundHandler, Input, TypedResponse } from './types.ts'3-import { FetchEvent } from './types.ts'2+import type { Env, FetchEventLike, NotFoundHandler, Input, TypedResponse } from './types.ts'3 import type { CookieOptions } from './utils/cookie.ts'4 import { serialize } from './utils/cookie.ts'5 import type { StatusCode } from './utils/http-status.ts'6 import { StreamingApi } from './utils/stream.ts'73 unmodified lines80 }81 82 type ContextOptions<E extends Env> = {83 env: E['Bindings']85- executionCtx?: FetchEvent | ExecutionContext | undefined84+ executionCtx?: FetchEventLike | ExecutionContext | undefined85 notFoundHandler?: NotFoundHandler<E>86 }87 88 const TEXT_PLAIN = 'text/plain; charset=UTF-8'11 unmodified lines100 finalized: boolean = false101 error: Error | undefined = undefined102 103 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 = true10 unmodified lines119 }120 }121 }122 124- 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 linesmodified:deno_dist/types.ts-2 removed
590 unmodified lines591 abstract respondWith(promise: Response | Promise<Response>): void592 abstract passThroughOnException(): void593 abstract waitUntil(promise: Promise<void>): void594 }595-596-export abstract class FetchEvent extends FetchEventLike {}modified:src/adapter/vercel/handler.ts+5 added-4 removed
1234456678789// @denoify-ignore/* eslint-disable @typescript-eslint/no-explicit-any */import type { Hono } from '../../hono'import type { FetchEvent } from '../../types'import type { FetchEventLike } from '../../types'
export const handle =export const handle = (app: Hono<any, any, any>) => (req: Request, requestContext: FetchEvent) => { return app.fetch(req, {}, requestContext as any)} (app: Hono<any, any, any>) => (req: Request, requestContext: FetchEventLike) => { return app.fetch(req, {}, requestContext as any) }modified:src/context.ts+5 added-6 removed
1 import type { HonoRequest } from './request'2-import type { Env, NotFoundHandler, Input, TypedResponse } from './types'3-import { FetchEvent } from './types'2+import type { Env, FetchEventLike, NotFoundHandler, Input, TypedResponse } from './types'3 import type { CookieOptions } from './utils/cookie'4 import { serialize } from './utils/cookie'5 import type { StatusCode } from './utils/http-status'6 import { StreamingApi } from './utils/stream'73 unmodified lines80 }81 82 type ContextOptions<E extends Env> = {83 env: E['Bindings']85- executionCtx?: FetchEvent | ExecutionContext | undefined84+ executionCtx?: FetchEventLike | ExecutionContext | undefined85 notFoundHandler?: NotFoundHandler<E>86 }87 88 const TEXT_PLAIN = 'text/plain; charset=UTF-8'11 unmodified lines100 finalized: boolean = false101 error: Error | undefined = undefined102 103 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 = true10 unmodified lines119 }120 }121 }122 124- 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 linesmodified:src/types.ts-2 removed
590 unmodified lines591 abstract respondWith(promise: Response | Promise<Response>): void592 abstract passThroughOnException(): void593 abstract waitUntil(promise: Promise<void>): void594 }595-596-export abstract class FetchEvent extends FetchEventLike {}