@furystack/rest-service
Version:
Repository implementation for FuryStack
53 lines • 1.6 kB
TypeScript
import type { Injector } from '@furystack/inject';
import type { IncomingMessage, ServerResponse } from 'http';
export interface ActionResult<T> {
statusCode: number;
headers: {
[K: string]: string;
};
chunk: T;
}
export declare const JsonResult: <T extends object>(chunk: T, statusCode?: number, headers?: {
[K: string]: string;
}) => ActionResult<T>;
export declare const PlainTextResult: (text: string, statusCode?: number, headers?: {
[K: string]: string;
}) => ActionResult<string>;
export declare const XmlResult: (text: string, statusCode?: number, headers?: {
[K: string]: string;
}) => ActionResult<string>;
export declare const EmptyResult: (statusCode?: number, headers?: {
[K: string]: string;
}) => ActionResult<undefined>;
export declare const BypassResult: () => ActionResult<"BypassResult">;
export type RequestActionOptions<T extends {
result: unknown;
}> = {
request: IncomingMessage;
response: ServerResponse;
injector: Injector;
} & (T extends {
result: unknown;
body: infer U;
} ? {
getBody: () => Promise<U>;
} : unknown) & (T extends {
result: unknown;
url: infer U;
} ? {
getUrlParams: () => U;
} : unknown) & (T extends {
result: unknown;
query: infer U;
} ? {
getQuery: () => U;
} : unknown) & (T extends {
result: unknown;
headers: infer U;
} ? {
headers: U;
} : unknown);
export type RequestAction<T extends {
result: unknown;
}> = (options: RequestActionOptions<T>) => Promise<ActionResult<T['result']>>;
//# sourceMappingURL=request-action-implementation.d.ts.map