UNPKG

@jmnuf/ao

Version:

A simple typescript based full-stack api endpoint creator that is meant to somewhat follow web standards in its implementation.

133 lines (132 loc) 7.84 kB
export declare const StatusMap: { readonly 100: "Continue"; readonly 101: "Switching Protocols"; readonly 102: "Processing"; readonly 103: "Early Hints"; readonly 200: "OK"; readonly 201: "Created"; readonly 202: "Accepted"; readonly 203: "Non-Authoritative Information"; readonly 204: "No Content"; readonly 205: "Reset Content"; readonly 206: "Partial Content"; readonly 207: "Multi-Status"; readonly 208: "Already Reported"; readonly 300: "Multiple Choices"; readonly 301: "Moved Permanently"; readonly 302: "Found"; readonly 303: "See Other"; readonly 304: "Not Modified"; readonly 307: "Temporary Redirect"; readonly 308: "Permanent Redirect"; readonly 400: "Bad Request"; readonly 401: "Unauthorized"; readonly 402: "Payment Required"; readonly 403: "Forbidden"; readonly 404: "Not Found"; readonly 405: "Method Not Allowed"; readonly 406: "Not Acceptable"; readonly 407: "Proxy Authentication Required"; readonly 408: "Request Timeout"; readonly 409: "Conflict"; readonly 410: "Gone"; readonly 411: "Length Required"; readonly 412: "Precondition Failed"; readonly 413: "Payload Too Large"; readonly 414: "URI Too Long"; readonly 415: "Unsupported Media Type"; readonly 416: "Range Not Satisfiable"; readonly 417: "Expectation Failed"; readonly 418: "I'm a teapot"; readonly 421: "Misdirected Request"; readonly 422: "Unprocessable Content"; readonly 423: "Locked"; readonly 424: "Failed Dependency"; readonly 425: "Too Early"; readonly 426: "Upgrade Required"; readonly 428: "Precondition Required"; readonly 429: "Too Many Requests"; readonly 431: "Request Header Fields Too Large"; readonly 451: "Unavailable For Legal Reasons"; readonly 500: "Internal Server Error"; readonly 501: "Not Implemented"; readonly 502: "Bad Gateway"; readonly 503: "Service Unavailable"; readonly 504: "Gateway Timeout"; readonly 505: "HTTP Version Not Supported"; readonly 506: "Variant Also Negotiates"; readonly 507: "Insufficient Storage"; readonly 508: "Loop Detected"; readonly 510: "Not Extended"; readonly 511: "Network Authentication Required"; }; export type Prettify<T> = { [K in keyof T]: T[K]; } & unknown; export type And<A extends boolean, B extends boolean> = A extends true ? B extends true ? true : false : false; export type If<Cond extends boolean, OnTrue, OnFalse> = Cond extends true ? OnTrue : OnFalse; export type SplitString<Str extends string, Delimiter extends string, IgnoreEmpty extends boolean = false> = string extends Str ? string[] : Str extends "" ? [] : Str extends `${infer T}${Delimiter}${infer U}` ? If<IgnoreEmpty, If<And<IgnoreEmpty, T extends "" ? true : false>, [...SplitString<U, Delimiter, IgnoreEmpty>], [T, ...SplitString<U, Delimiter, IgnoreEmpty>]>, [T, ...SplitString<U, Delimiter, IgnoreEmpty>]> : [Str]; export type JoinString<Pieces extends any[], Joiner extends string = "", Joined extends string = ""> = Pieces extends [] ? Joined : Pieces extends [infer Head, ...infer Tail] ? Head extends string ? JoinString<Tail, Joiner, Joined extends "" ? `${Head}` : `${Joined}${Joiner}${Head}`> : JoinString<Tail, Joiner, Joined> : never; export type UnionToIntersection<U> = (U extends any ? (x: U) => void : never) extends ((x: infer I) => void) ? I : never; export type UnionToParm<U> = U extends any ? (k: U) => void : never; export type UnionToSect<U> = UnionToParm<U> extends ((k: infer I) => void) ? I : never; export type ExtractParm<F> = F extends { (a: infer A): void; } ? A : never; export type UnionSpliceOne<Union> = Exclude<Union, UnionExtractOne<Union>>; export type UnionExtractOne<Union> = ExtractParm<UnionToSect<UnionToParm<Union>>>; export type UnionToTuple<Union> = UnionToTupleRec<Union, []>; export type UnionToTupleRec<Union, Rslt extends any[]> = UnionSpliceOne<Union> extends never ? [UnionExtractOne<Union>, ...Rslt] : UnionToTupleRec<UnionSpliceOne<Union>, [UnionExtractOne<Union>, ...Rslt]>; export type JoinTuple<Tuple extends string[], Delim extends string> = Tuple extends [] ? "" : Tuple extends [infer Head extends string, ...infer Tail extends string[]] ? JoinTupleRec<Head, Delim, Tail> : never; export type JoinTupleRec<Acc extends string, Delim extends string, Tuple extends string[]> = Tuple extends [] ? Acc : Tuple extends [infer Head extends string, ...infer Tail extends string[]] ? JoinTupleRec<`${Acc}${Delim}${Head}`, Delim, Tail> : Acc; export type TuplePush<Tuple extends any[], Value> = [...Tuple, Value]; export type TupleRemove<Tuple extends any[], Value> = UnionToTuple<Exclude<Tuple[number], Value>>; export type SimplifyBooleanLiteral<Bool extends boolean> = Bool extends true ? boolean : Bool extends false ? boolean : boolean; export type TupleToArraysUnion<Tuple extends any[], SimplifyBoolean extends boolean = false> = Tuple extends [] ? never : Tuple extends [infer Head, ...infer Tail extends any[]] ? TupleToArraysUnionRec<Array<SimplifyBoolean extends true ? Head extends boolean ? SimplifyBooleanLiteral<Head> : Head : Head>, Tail, SimplifyBoolean> : never; export type TupleToArraysUnionRec<Acc, Tuple extends any[], SimplifyBoolean extends boolean> = Tuple extends [] ? Acc : Tuple extends [infer Head, ...infer Tail] ? TupleToArraysUnionRec<Acc | Array<SimplifyBoolean extends true ? Head extends boolean ? SimplifyBooleanLiteral<Head> : Head : Head>, Tail, SimplifyBoolean> : Acc; export type ObjectValues<T extends Record<any, any>> = UnionToIntersection<T[keyof T]>; export type FindPathParams<Path extends string> = FindPathParamsRec<SplitString<Path, "/", true>, {}>; type FindPathParamsRec<Parts extends string[], FoundParams extends { [param: string | never]: string | string[]; }> = Parts extends [] ? FoundParams : Parts extends [infer Head extends string, ...infer Tail extends string[]] ? Head extends `:${infer Param extends string}` ? Param extends keyof FoundParams ? (FoundParams[Param] extends string ? Omit<FoundParams, Param> & { [P in Param]: [string, string]; } : FoundParams[Param] extends string[] ? Omit<FoundParams, Param> & { [P in Param]: TuplePush<FoundParams[Param], string>; } : FoundParams & { [P in Param]: string; }) : FoundParams & { [P in Param]: string; } : FindPathParamsRec<Tail, FoundParams> : never; export type PrimitiveResponse = string | number | boolean; export type ArrayResponse = Prettify<Array<PrimitiveResponse> | TupleToArraysUnion<UnionToTuple<PrimitiveResponse>, true>>; export type ObjectResponse = { [K in string | number]: PrimitiveResponse | ArrayResponse | ObjectResponse; }; export type SimpleResponse = PrimitiveResponse | ArrayResponse | ObjectResponse; export type GeneratorResponse = Generator<SimpleResponse> | AsyncGenerator<SimpleResponse>; export type ResponseValueType = PrimitiveResponse | ArrayResponse | ObjectResponse | GeneratorResponse; export type ResponseData<T extends ResponseValueType> = { ok: true; status: number; data: T extends Generator<infer U> ? AsyncGenerator<U> : T; response: Response; } | { ok: false; status?: number; response?: Response; error: Error; }; export declare const HttpMethods: readonly ["GET", "POST", "PUT", "DELETE"]; export type HTTPMethod = (typeof HttpMethods)[number]; export type Cookie = { value: string | undefined; secure: boolean; expireDate: Date | undefined; maxAge: number | undefined; sameSite: "Strict" | "Lax" | "None" | undefined; remove(): void; }; export declare function isGeneratorObject(obj: any): obj is Generator<any>; export declare function isAsyncGeneratorObject(obj: any): obj is AsyncGenerator<any>; export declare const GeneratorHTTPHeaderName = "X-AncientOnes-Streaming"; export {};