UNPKG

2.12 kBTypeScriptView Raw
1declare module 'huncwot' {
2 import { ReadStream } from 'fs';
3
4 interface Request {
5 params: {
6 [name: string]: any
7 },
8 files: {
9 [name: string]: {
10 name: string
11 length: number
12 data: any
13 encoding: string
14 mimetype: string
15 }
16 }
17 }
18
19 type Response = string | { body: string } | Buffer | ReadStream;
20 type Handler = (request: Request) => Response | Promise<Response>;
21
22 interface Resource {
23 feature: string
24 alias?: string
25 children?: Resource[]
26 };
27
28 interface Routes {
29 DELETE?: {
30 [name: string]: Handler
31 },
32 GET?: {
33 [name: string]: Handler
34 },
35 HEAD?: {
36 [name: string]: Handler
37 },
38 OPTIONS?: {
39 [name: string]: Handler
40 }
41 PATCH?: {
42 [name: string]: Handler
43 },
44 POST?: {
45 [name: string]: Handler
46 },
47 PUT?: {
48 [name: string]: Handler
49 },
50 Resources?: Resource[]
51 }
52
53 interface Payload {
54 [key: string]: any
55 }
56 type Task = (input: Payload) => Promise<void>;
57 type Queue = any;
58
59 export { Handler, Routes, Request, Response, Payload, Task }
60}
61
62declare module 'huncwot/response' {
63 import { Response } from 'huncwot';
64
65 interface Mapping {
66 [key: string]: any;
67 }
68
69 function OK(body?: any, headers?: any): Response;
70 function Created(body?: any, headers?: any): Response;
71 function NotFound(headers?: any): Response;
72 function HTMLString(body?: any): Response;
73 function HTMLStream(body?: any): Response;
74 function Page(location: string, mapping: Mapping): Response;
75
76 export { OK, Created, NotFound, HTMLString, HTMLStream, Page };
77}
78
79declare module 'huncwot/background' {
80 import { Task, Payload, Queue } from 'huncwot';
81
82 interface ScheduleInput {
83 task: Task
84 payload?: Payload
85 queue?: Queue
86 runAt?: string
87 maxAttempts?: number
88 }
89
90 function schedule(_: ScheduleInput): Promise<void>;
91}
92
93declare module 'huncwot/db' {
94 interface SQLStatement {
95 text: string
96 values: (string | number)[]
97 }
98
99 function execute(statement: SQLStatement);
100 // FIXME ugly hack
101 function from(table: string);
102}