/*! * This Source Code Form is subject to the terms of the Mozilla Public License, * v. 2.0. If a copy of the MPL was not distributed with this file, You can * obtain one at http://mozilla.org/MPL/2.0/. */ import { Schema as S } from "@effect/schema"; import type { Field } from "./Field"; import type { MimeTypePredicate } from "./MimeType"; // --- INTERFACES -------------------------------------------------------------- export interface RequestBodyNone { readonly _tag: "None"; } export interface RequestBodyText> { readonly _tag: "Text"; readonly schema: Schema; } export interface RequestBodyJson { readonly _tag: "Json"; readonly schema: Schema; } export interface RequestBodyUrlEncoded { readonly _tag: "UrlEncoded"; readonly fields: Readonly; } export interface RequestBodyMultipart { readonly _tag: "Multipart"; readonly fields: Readonly; } export interface RequestBodyFile { readonly _tag: "File"; readonly mimeType: MimeTypePredicate; } export namespace RequestBodyText { export type Any = RequestBodyText>; } export namespace RequestBodyJson { export type Any = RequestBodyJson; } export namespace RequestBodyUrlEncoded { export type Any = RequestBodyUrlEncoded<{}>; } export namespace RequestBodyMultipart { export type Any = RequestBodyMultipart<{}>; } export namespace RequestBodyFile { export type Any = RequestBodyFile; } export namespace RequestBody { export type Any = | RequestBodyNone | RequestBodyText.Any | RequestBodyJson.Any | RequestBodyUrlEncoded.Any | RequestBodyMultipart.Any | RequestBodyFile.Any ; } // --- CONSTRUCTORS ------------------------------------------------------------ export const RequestBodyNone: RequestBodyNone = Object.freeze({ _tag: "None", }); export const RequestBodyText = >(schema: Schema): RequestBodyText => Object.freeze>({ _tag: "Text", schema, }); export const RequestBodyJson = (schema: Schema): RequestBodyJson => Object.freeze>({ _tag: "Json", schema, }); export const RequestBodyUrlEncoded = (fields: Fields): RequestBodyUrlEncoded => Object.freeze>({ _tag: "UrlEncoded", fields, }); export const RequestBodyMultipart = (fields: Fields): RequestBodyMultipart => Object.freeze>({ _tag: "Multipart", fields, }); export const RequestBodyFile = (mimeType: MimeTypePredicate): RequestBodyFile => Object.freeze>({ _tag: "File", mimeType, });