fix(types): remove `any` and fix types of adapter/deno (#3291)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* fix(types): remove any and fix types of adapter/deno * fix some errors * refactor jsdoc
authored by EdamAmex · committed by GitHub · parent 7a9e387 · Browse files · 3 files·+57 added−28 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+57 added−28 removed
- other:+57 added−28 removed
Provenance
- Commit
caeecf9- Tree
9bfae37- Author
EdamAmex <121654029+EdamAme-x@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
7a9e387
3 files changed+57 added−28 removed
modified:src/adapter/deno/deno.d.ts+54 added-3 removed
1234567891011121314151617181920212223242526272829304 unmodified lines353637381539404142434445464748495022235152535455565758596061626364656667686970717273747576777879declare namespace Deno { interface FileHandleLike { readonly readable: ReadableStream<Uint8Array> }
/** * Open the file using the specified path. * * @param path The path to open the file. * @returns FileHandle object. */ export function open(path: string): Promise<FileHandleLike>
interface StatsLike { isDirectory: boolean }
/** * Get stats with the specified path. * * @param path The path to get stats. * @returns Stats object. */ export function lstatSync(path: string): StatsLike
/** * Creates a new directory with the specified path. * * @param path The path to create a directory. * @param options Options for creating a directory.4 unmodified lines /** * Write a new file, with the specified path and data. * * @param path The path to the file to write. * @param data The data to write to the file. * @param data The data to write into the file. * @returns A promise that resolves when the file is written. */ export function writeFile(path: string, data: Uint8Array): Promise<void>
/** * Errors of Deno */ export const errors: Record<string, Function>
export function upgradeWebSocket( req: Request, // eslint-disable-next-line @typescript-eslint/no-explicit-any options: any options: UpgradeWebSocketOptions ): { response: Response socket: WebSocket }
/** * Options of `upgradeWebSocket` */ export interface UpgradeWebSocketOptions { /** * Sets the `.protocol` property on the client-side web socket to the * value provided here, which should be one of the strings specified in the * `protocols` parameter when requesting the web socket. This is intended * for clients and servers to specify sub-protocols to use to communicate to * each other. */ protocol?: string /** * If the client does not respond to this frame with a * `pong` within the timeout specified, the connection is deemed * unhealthy and is closed. The `close` and `error` events will be emitted. * * The unit is seconds, with a default of 30. * Set to `0` to disable timeouts. */ idleTimeout?: number }}modified:src/adapter/deno/serve-static.ts+2 added-4 removed
123456567891011121316171415161718192021222317 unmodified linesimport type { ServeStaticOptions } from '../../middleware/serve-static'import { serveStatic as baseServeStatic } from '../../middleware/serve-static'import type { Env, MiddlewareHandler } from '../../types'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment// @ts-ignoreconst { open, lstatSync, errors } = Deno
export const serveStatic = <E extends Env = Env>( options: ServeStaticOptions<E>): MiddlewareHandler => { return async function serveStatic(c, next) { const getContent = async (path: string) => { try { const file = await open(path) // eslint-disable-next-line @typescript-eslint/no-explicit-any return file ? (file.readable as any) : null return file.readable } catch (e) { if (!(e instanceof errors.NotFound)) { console.warn(`${e}`) } return null } } const pathResolve = (path: string) => { return path.startsWith('/') ? path : `./${path}`17 unmodified linesmodified:src/adapter/deno/websocket.ts+1 added-21 removed
1234567891011121314151617181920212223244567822 unmodified linesimport type { UpgradeWebSocket, WSReadyState } from '../../helper/websocket'import { WSContext, defineWebSocketHelper } from '../../helper/websocket'
export interface UpgradeWebSocketOptions { /** * Sets the `.protocol` property on the client side web socket to the * value provided here, which should be one of the strings specified in the * `protocols` parameter when requesting the web socket. This is intended * for clients and servers to specify sub-protocols to use to communicate to * each other. */ protocol?: string /** * If the client does not respond to this frame with a * `pong` within the timeout specified, the connection is deemed * unhealthy and is closed. The `close` and `error` event will be emitted. * * The unit is seconds, with a default of 30. * Set to `0` to disable timeouts. */ idleTimeout?: number}
export const upgradeWebSocket: UpgradeWebSocket<WebSocket, UpgradeWebSocketOptions> =export const upgradeWebSocket: UpgradeWebSocket<WebSocket, Deno.UpgradeWebSocketOptions> = defineWebSocketHelper(async (c, events, options) => { if (c.req.header('upgrade') !== 'websocket') { return }22 unmodified lines