@casual-simulation/aux-common
Version:
Common library for AUX projects
115 lines • 3.83 kB
TypeScript
import { z } from 'zod';
/**
* Defines an interface for a generic HTTP request.
*/
export interface GenericHttpRequest {
/**
* The path that the HTTP request is for.
* Does not include the query string parameters.
*/
path: string;
/**
* The query string parameters.
*/
query: GenericQueryStringParameters;
/**
* The path parameters.
* i.e. These are parameters that are calculated from the path of the
*/
pathParams: GenericPathParameters;
/**
* The method that the HTTP request uses.
*
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
*/
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'OPTIONS';
/**
* The headers for the request.
*/
headers: GenericHttpHeaders;
/**
* The body of the HTTP request.
*/
body: string | null;
/**
* The IP address that the request is from.
* Null if the IP address is not available.
*/
ipAddress: string | null;
}
/**
* Defines an interface for a generic HTTP response.
*/
export interface GenericHttpResponse {
/**
* The status code for the response.
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
*
*/
statusCode: number;
/**
* The list of headers to include in the response.
*/
headers?: GenericHttpHeaders;
/**
* The body of the response.
*
* If given a string, then the body will be set to that string.
* If given an AsyncIterable, then each chunk will be written to the stream as a separate chunk.
*/
body?: string | null | AsyncIterable<string>;
}
export interface GenericHttpHeaders {
[]: string;
}
export interface GenericQueryStringParameters {
[]: string;
}
export interface GenericPathParameters {
[]: string;
}
/**
* Defines an interface for a generic Websocket request.
*/
export interface GenericWebsocketRequest {
type: 'connect' | 'disconnect' | 'message';
/**
* The ID of the connection that the server has associated with this request.
*/
connectionId: string;
/**
* The body of the websocket request.
*/
body?: string | Uint8Array | null;
/**
* The IP address of the request.
*/
ipAddress: string;
/**
* The value of the HTTP Origin header when the connection was established.
*/
origin: string;
}
export declare const genericHttpRequestSchema: z.ZodObject<{
path: z.ZodString;
pathParams: z.ZodObject<{}, "strip", z.ZodString, z.objectOutputType<{}, z.ZodString, "strip">, z.objectInputType<{}, z.ZodString, "strip">>;
method: z.ZodUnion<[z.ZodLiteral<"GET">, z.ZodLiteral<"POST">, z.ZodLiteral<"PUT">, z.ZodLiteral<"DELETE">, z.ZodLiteral<"HEAD">, z.ZodLiteral<"OPTIONS">]>;
query: z.ZodObject<{}, "strip", z.ZodString, z.objectOutputType<{}, z.ZodString, "strip">, z.objectInputType<{}, z.ZodString, "strip">>;
headers: z.ZodObject<{}, "strip", z.ZodString, z.objectOutputType<{}, z.ZodString, "strip">, z.objectInputType<{}, z.ZodString, "strip">>;
body: z.ZodUnion<[z.ZodString, z.ZodNull]>;
}, "strip", z.ZodTypeAny, {
path?: string;
pathParams?: z.objectOutputType<{}, z.ZodString, "strip">;
method?: "GET" | "POST" | "PUT" | "DELETE" | "HEAD" | "OPTIONS";
query?: z.objectOutputType<{}, z.ZodString, "strip">;
headers?: z.objectOutputType<{}, z.ZodString, "strip">;
body?: string;
}, {
path?: string;
pathParams?: z.objectInputType<{}, z.ZodString, "strip">;
method?: "GET" | "POST" | "PUT" | "DELETE" | "HEAD" | "OPTIONS";
query?: z.objectInputType<{}, z.ZodString, "strip">;
headers?: z.objectInputType<{}, z.ZodString, "strip">;
body?: string;
}>;
//# sourceMappingURL=GenericHttpInterface.d.ts.map