EdgeAIG's picture
download
raw
14.3 kB
/**
* Attaches HTTP API metadata to Effect Schema values.
*
* This module is the schema-side bridge for HttpApi endpoint builders,
* generated clients, and OpenAPI support. It does not define routes or perform
* IO. Instead, the helpers annotate schemas so the surrounding HTTP API tooling
* can choose response status codes, content types, body codecs, multipart
* handling, and no-body response behavior.
*
* @since 4.0.0
*/
import { type LazyArg } from "../../Function.ts";
import * as Schema from "../../Schema.ts";
import * as SchemaAST from "../../SchemaAST.ts";
import * as Stream from "../../Stream.ts";
import type * as Sse from "../encoding/Sse.ts";
import type * as Multipart_ from "../http/Multipart.ts";
declare module "../../Schema.ts" {
namespace Annotations {
interface Augment {
readonly httpApiStatus?: number | undefined;
}
}
}
/**
* HTTP API body encoding metadata used by payloads and responses.
*
* @category models
* @since 4.0.0
*/
export type Encoding = PayloadEncoding | ResponseEncoding;
/**
* HTTP API request payload encoding metadata.
*
* @category models
* @since 4.0.0
*/
export type PayloadEncoding = {
readonly _tag: "Multipart";
readonly mode: "buffered" | "stream";
readonly contentType: string;
readonly limits?: Multipart_.withLimits.Options | undefined;
} | {
readonly _tag: "Json" | "FormUrlEncoded" | "Uint8Array" | "Text";
readonly contentType: string;
};
/**
* HTTP API response body encoding metadata.
*
* @category models
* @since 4.0.0
*/
export type ResponseEncoding = {
readonly _tag: "Json" | "FormUrlEncoded" | "Uint8Array" | "Text";
readonly contentType: string;
};
declare const statusCodeByLiteral: {
readonly Continue: 100;
readonly SwitchingProtocols: 101;
readonly Processing: 102;
readonly EarlyHints: 103;
readonly OK: 200;
readonly Ok: 200;
readonly Created: 201;
readonly Accepted: 202;
readonly NonAuthoritativeInformation: 203;
readonly NoContent: 204;
readonly ResetContent: 205;
readonly PartialContent: 206;
readonly MultiStatus: 207;
readonly AlreadyReported: 208;
readonly ImUsed: 226;
readonly MultipleChoices: 300;
readonly MovedPermanently: 301;
readonly Found: 302;
readonly SeeOther: 303;
readonly NotModified: 304;
readonly TemporaryRedirect: 307;
readonly PermanentRedirect: 308;
readonly BadRequest: 400;
readonly Unauthorized: 401;
readonly PaymentRequired: 402;
readonly Forbidden: 403;
readonly NotFound: 404;
readonly MethodNotAllowed: 405;
readonly NotAcceptable: 406;
readonly ProxyAuthenticationRequired: 407;
readonly RequestTimeout: 408;
readonly Conflict: 409;
readonly Gone: 410;
readonly LengthRequired: 411;
readonly PreconditionFailed: 412;
readonly PayloadTooLarge: 413;
readonly UriTooLong: 414;
readonly UnsupportedMediaType: 415;
readonly RangeNotSatisfiable: 416;
readonly ExpectationFailed: 417;
readonly ImATeapot: 418;
readonly MisdirectedRequest: 421;
readonly UnprocessableEntity: 422;
readonly Locked: 423;
readonly FailedDependency: 424;
readonly TooEarly: 425;
readonly UpgradeRequired: 426;
readonly PreconditionRequired: 428;
readonly TooManyRequests: 429;
readonly RequestHeaderFieldsTooLarge: 431;
readonly UnavailableForLegalReasons: 451;
readonly InternalServerError: 500;
readonly NotImplemented: 501;
readonly BadGateway: 502;
readonly ServiceUnavailable: 503;
readonly GatewayTimeout: 504;
readonly HttpVersionNotSupported: 505;
readonly VariantAlsoNegotiates: 506;
readonly InsufficientStorage: 507;
readonly LoopDetected: 508;
readonly NotExtended: 510;
readonly NetworkAuthenticationRequired: 511;
};
declare const StreamSchemaTypeId = "~effect/httpapi/HttpApiSchema/Stream";
/**
* Common HTTP status code literals accepted by {@link status}.
*
* @category status
* @since 4.0.0
*/
export type StatusLiteral = keyof typeof statusCodeByLiteral;
/**
* Sets the HTTP status code of a schema.
*
* **Details**
*
* This is equivalent to calling `.annotate({ httpApiStatus: code })` on the
* schema. You can pass either a numeric status code (for example, `201`) or a
* common literal name (for example, `"Created"`).
*
* @category status
* @since 4.0.0
*/
export declare function status(code: number): {
<S extends Schema.Top>(self: S): S["Rebuild"];
};
export declare function status(code: StatusLiteral): {
<S extends Schema.Top>(self: S): S["Rebuild"];
};
/**
* Creates a void schema with the given HTTP status code.
* This is used to represent empty responses with a specific status code.
*
* @see {@link NoContent} for the predefined 204 no content schema.
*
* @category Empty
* @since 4.0.0
*/
export declare const Empty: (code: number) => Schema.Void;
/**
* Type of the `NoContent` schema, a void schema annotated with HTTP status code 204.
*
* @category models
* @since 4.0.0
*/
export interface NoContent extends Schema.Void {
}
/**
* Schema for empty HTTP responses with status code 204.
*
* @category Empty
* @since 4.0.0
*/
export declare const NoContent: NoContent;
/**
* Type of the `Created` schema, a void schema annotated with HTTP status code 201.
*
* @category models
* @since 4.0.0
*/
export interface Created extends Schema.Void {
}
/**
* Schema for empty HTTP responses with status code 201.
*
* @category Empty
* @since 4.0.0
*/
export declare const Created: Created;
/**
* Type of the `Accepted` schema, a void schema annotated with HTTP status code 202.
*
* @category models
* @since 4.0.0
*/
export interface Accepted extends Schema.Void {
}
/**
* Schema for empty HTTP responses with status code 202.
*
* @category Empty
* @since 4.0.0
*/
export declare const Accepted: Accepted;
/**
* Schema type returned by `asNoContent`, encoding as `void` while decoding to the original schema type.
*
* @category schemas
* @since 4.0.0
*/
export interface asNoContent<S extends Schema.Top> extends Schema.decodeTo<Schema.toType<S>, Schema.Void> {
}
/**
* Marks a schema as a no-content response while preserving a decoded client value.
*
* **Details**
*
* The server encodes the response as `void`; generated clients call `decode` to
* produce the schema's decoded value when the response has no body.
*
* @see {@link NoContent} for a void schema with the status code 204.
* @see {@link Empty} for creating a void schema with a specific status code.
*
* @category encoding
* @since 4.0.0
*/
export declare function asNoContent<S extends Schema.Top>(options: {
readonly decode: LazyArg<S["Type"]>;
}): (self: S) => asNoContent<S>;
/**
* Mode describing whether an SSE stream emits full events or raw data values.
*
* @category models
* @since 4.0.0
*/
export type StreamSseMode = "events" | "data";
/**
* Schema for a Server-Sent Events success response.
*
* **Details**
*
* `events` describes successful application events emitted by the stream, and
* `error` describes typed stream failures that will be encoded by later
* endpoint/server/client integrations using the reserved failure event. If
* `error` is omitted, it defaults to `Schema.Never`. When `StreamSse` is
* constructed from `data`, handlers and clients expose raw data values while
* the server and client still use an SSE event schema internally.
*
* @category models
* @since 4.0.0
*/
export interface StreamSse<Events extends Sse.EventCodec, Error extends Schema.Top, Value = Events["Type"]> extends Schema.Bottom<Stream.Stream<Value, Error["Type"], never>, Stream.Stream<Value, Error["Type"], never>, Events["DecodingServices"] | Error["DecodingServices"], Events["EncodingServices"] | Error["EncodingServices"], SchemaAST.Declaration, StreamSse<Events, Error, Value>> {
readonly "Rebuild": StreamSse<Events, Error, Value>;
readonly [StreamSchemaTypeId]: typeof StreamSchemaTypeId;
readonly _tag: "StreamSse";
readonly mode: "sse";
readonly sseMode: StreamSseMode;
readonly contentType: string;
readonly events: Events;
readonly error: Error;
readonly "~Value"?: Value | undefined;
}
/**
* Event schema produced when {@link StreamSse} is constructed from a JSON data schema.
*
* @category models
* @since 4.0.0
*/
export interface SseEventFromData<Data extends Schema.Top> extends Schema.Codec<{
readonly id: string | undefined;
readonly event: string;
readonly data: Data["Type"];
}, {
readonly id?: string | undefined;
readonly event?: string | undefined;
readonly data: string;
}, Data["DecodingServices"], Data["EncodingServices"]> {
}
/**
* Schema for a streaming `Uint8Array` success response.
*
* **Details**
*
* This declaration stores the response content type for later endpoint,
* server, client, and OpenAPI integrations. It is intentionally separate from
* the buffered `asUint8Array` response encoding.
*
* @category models
* @since 4.0.0
*/
export interface StreamUint8Array extends Schema.Bottom<Stream.Stream<Uint8Array, unknown, never>, Stream.Stream<Uint8Array, unknown, never>, never, never, SchemaAST.Declaration, StreamUint8Array> {
readonly "Rebuild": StreamUint8Array;
readonly [StreamSchemaTypeId]: typeof StreamSchemaTypeId;
readonly _tag: "StreamUint8Array";
readonly mode: "uint8array";
readonly contentType: string;
}
/**
* Schema for a streaming HTTP API success response.
*
* @category models
* @since 4.0.0
*/
export type StreamSchema = StreamSse<Sse.EventCodec, Schema.Top, unknown> | StreamUint8Array;
/**
* Creates a Server-Sent Events streaming success response schema.
*
* @category constructors
* @since 4.0.0
*/
export declare const StreamSse: {
/**
* Creates a Server-Sent Events streaming success response schema.
*
* @category constructors
* @since 4.0.0
*/
<Events extends Sse.EventCodec, Error extends Schema.Top = Schema.Never>(options: {
readonly contentType?: string | undefined;
readonly events: Events;
readonly error?: Error | undefined;
}): StreamSse<Events, Error, Events["Type"]>;
/**
* Creates a Server-Sent Events streaming success response schema.
*
* @category constructors
* @since 4.0.0
*/
<Data extends Schema.Top, Error extends Schema.Top = Schema.Never>(options: {
readonly contentType?: string | undefined;
readonly data: Data;
readonly error?: Error | undefined;
}): StreamSse<SseEventFromData<Data>, Error, Data["Type"]>;
};
/**
* Creates a streaming `Uint8Array` success response schema.
*
* @category constructors
* @since 4.0.0
*/
export declare const StreamUint8Array: (options?: {
readonly contentType?: string | undefined;
}) => StreamUint8Array;
/**
* Runtime brand key used to mark schemas as buffered multipart payloads.
*
* @category type IDs
* @since 4.0.0
*/
export declare const MultipartTypeId = "~effect/httpapi/HttpApiSchema/Multipart";
/**
* Type-level brand identifier used by `asMultipart`.
*
* @category type IDs
* @since 4.0.0
*/
export type MultipartTypeId = typeof MultipartTypeId;
/**
* Schema type returned by `asMultipart` for buffered multipart payloads.
*
* @category schemas
* @since 4.0.0
*/
export interface asMultipart<S extends Schema.Top> extends Schema.brand<S["Rebuild"], MultipartTypeId> {
}
/**
* Marks a schema as a multipart payload.
*
* @see {@link asMultipartStream} for a multipart stream payload.
*
* @category encoding
* @since 4.0.0
*/
export declare function asMultipart(options?: Multipart_.withLimits.Options): <S extends Schema.Top>(self: S) => asMultipart<S>;
/**
* Runtime brand key used to mark schemas as streaming multipart payloads.
*
* @category type IDs
* @since 4.0.0
*/
export declare const MultipartStreamTypeId = "~effect/httpapi/HttpApiSchema/MultipartStream";
/**
* Type-level brand identifier used by `asMultipartStream`.
*
* @category type IDs
* @since 4.0.0
*/
export type MultipartStreamTypeId = typeof MultipartStreamTypeId;
/**
* Schema type returned by `asMultipartStream` for streaming multipart payloads.
*
* @category schemas
* @since 4.0.0
*/
export interface asMultipartStream<S extends Schema.Top> extends Schema.brand<S["Rebuild"], MultipartStreamTypeId> {
}
/**
* Marks a schema as a multipart stream payload.
*
* @see {@link asMultipart} for a buffered multipart payload.
*
* @category encoding
* @since 4.0.0
*/
export declare function asMultipartStream(options?: Multipart_.withLimits.Options): <S extends Schema.Top>(self: S) => asMultipartStream<S>;
/**
* Marks a schema as a JSON payload / response.
*
* @category encoding
* @since 4.0.0
*/
export declare function asJson(options?: {
readonly contentType?: string;
}): <S extends Schema.Top>(self: S) => S["Rebuild"];
/**
* Marks a schema as an `application/x-www-form-urlencoded` payload or response.
*
* **Details**
*
* The schema's encoded side must be a record of strings.
*
* @category encoding
* @since 4.0.0
*/
export declare function asFormUrlEncoded(options?: {
readonly contentType?: string;
}): <S extends Schema.Top>(self: S) => S["Rebuild"];
/**
* Marks a schema as a text payload / response.
*
* **Details**
*
* The schema encoded side must be a string.
*
* @category encoding
* @since 4.0.0
*/
export declare function asText(options?: {
readonly contentType?: string;
}): <S extends Schema.Top & {
readonly Encoded: string;
}>(self: S) => S["Rebuild"];
/**
* Marks a schema as a binary payload / response.
*
* **Details**
*
* The schema encoded side must be a `Uint8Array`.
*
* @category encoding
* @since 4.0.0
*/
export declare function asUint8Array(options?: {
readonly contentType?: string;
}): <S extends Schema.Top & {
readonly Encoded: Uint8Array;
}>(self: S) => S["Rebuild"];
/**
* Returns `true` when a schema AST represents a no-content response.
*
* **Details**
*
* The check succeeds for direct `void` schemas and schemas whose encoded or
* transformation target is `void`.
*
* @category predicates
* @since 4.0.0
*/
export declare const isNoContent: (ast: SchemaAST.AST) => boolean;
export {};
//# sourceMappingURL=HttpApiSchema.d.ts.map

Xet Storage Details

Size:
14.3 kB
·
Xet hash:
5cfb052c7450214c64850c67f6e17f2ac834b1238c765cdccf07c345454f3a72

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.