Download .opencode/node_modules/effect/src/unstable/http/HttpServerRespondable.ts from Chenloong999/opencode-data: direct link, hf CLI and curl.
- Browser
- Download file 2 kB
-
https://huggingface.co/datasets/Chenloong999/opencode-data/resolve/84c8581d284a6a73a22921151ea3d89e2bcfe44e/.opencode/node_modules/effect/src/unstable/http/HttpServerRespondable.ts
- Command line
-
hf download hf://datasets/Chenloong999/opencode-data@84c8581d284a6a73a22921151ea3d89e2bcfe44e/.opencode/node_modules/effect/src/unstable/http/HttpServerRespondable.ts
-
curl -L -o HttpServerRespondable.ts https://huggingface.co/datasets/Chenloong999/opencode-data/resolve/84c8581d284a6a73a22921151ea3d89e2bcfe44e/.opencode/node_modules/effect/src/unstable/http/HttpServerRespondable.ts
2 kB
| /** | |
| * @since 4.0.0 | |
| */ | |
| import * as Cause from "../../Cause.ts" | |
| import * as Effect from "../../Effect.ts" | |
| import { hasProperty } from "../../Predicate.ts" | |
| import * as Schema from "../../Schema.ts" | |
| import type { HttpServerResponse } from "./HttpServerResponse.ts" | |
| import * as Response from "./HttpServerResponse.ts" | |
| /** | |
| * @since 4.0.0 | |
| * @category Type IDs | |
| */ | |
| export const symbol = "~effect/http/HttpServerRespondable" | |
| /** | |
| * @since 4.0.0 | |
| * @category models | |
| */ | |
| export interface Respondable { | |
| [symbol](): Effect.Effect<HttpServerResponse, unknown> | |
| } | |
| /** | |
| * @since 4.0.0 | |
| * @category guards | |
| */ | |
| export const isRespondable = (u: unknown): u is Respondable => hasProperty(u, symbol) | |
| const badRequest = Response.empty({ status: 400 }) | |
| const notFound = Response.empty({ status: 404 }) | |
| /** | |
| * @since 4.0.0 | |
| * @category accessors | |
| */ | |
| export const toResponse = (self: Respondable): Effect.Effect<HttpServerResponse> => { | |
| if (Response.isHttpServerResponse(self)) { | |
| return Effect.succeed(self) | |
| } | |
| return Effect.orDie(self[symbol]()) | |
| } | |
| /** | |
| * @since 4.0.0 | |
| * @category accessors | |
| */ | |
| export const toResponseOrElse = (u: unknown, orElse: HttpServerResponse): Effect.Effect<HttpServerResponse> => { | |
| if (Response.isHttpServerResponse(u)) { | |
| return Effect.succeed(u) | |
| } else if (isRespondable(u)) { | |
| return Effect.catchCause(u[symbol](), () => Effect.succeed(orElse)) | |
| // add support for some commmon types | |
| } else if (Schema.isSchemaError(u)) { | |
| return Effect.succeed(badRequest) | |
| } else if (Cause.isNoSuchElementError(u)) { | |
| return Effect.succeed(notFound) | |
| } | |
| return Effect.succeed(orElse) | |
| } | |
| /** | |
| * @since 4.0.0 | |
| * @category accessors | |
| */ | |
| export const toResponseOrElseDefect = (u: unknown, orElse: HttpServerResponse): Effect.Effect<HttpServerResponse> => { | |
| if (Response.isHttpServerResponse(u)) { | |
| return Effect.succeed(u) | |
| } else if (isRespondable(u)) { | |
| return Effect.catchCause(u[symbol](), () => Effect.succeed(orElse)) | |
| } | |
| return Effect.succeed(orElse) | |
| } | |