lieko-express 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lieko-express.d.ts +264 -0
  2. package/package.json +2 -1
@@ -0,0 +1,264 @@
1
+ declare namespace Lieko {
2
+ type PlainObject = Record<string, any>;
3
+
4
+ // Extract params from a path string like "/user/:id/books/:bookId"
5
+ type ExtractRouteParams<Path extends string> =
6
+ Path extends `${string}:${infer Param}/${infer Rest}`
7
+ ? { [k in Param | keyof ExtractRouteParams<Rest>]: string }
8
+ : Path extends `${string}:${infer Param}`
9
+ ? { [k in Param]: string }
10
+ : Record<string, never>;
11
+
12
+ // -------------- Request / Response types --------------
13
+ // Minimal subset of http.IncomingMessage / http.ServerResponse for typings
14
+ interface RequestBase {
15
+ method: string;
16
+ url: string;
17
+ headers: Record<string, string | undefined>;
18
+ // populated by the framework:
19
+ query: Record<string, any>;
20
+ params: Record<string, any>;
21
+ body: any;
22
+ files: Record<string, any>;
23
+ ip?: string;
24
+ _bodySize?: number;
25
+ _startTime?: bigint;
26
+ // raw Node objects (optional)
27
+ raw?: any;
28
+ }
29
+
30
+ interface ResponseBase {
31
+ status(code: number): this;
32
+ json(data: any): void;
33
+ send(data: any): void;
34
+ text(data: string): void;
35
+
36
+ // headers helpers
37
+ setHeader(name: string, value: string | number): void;
38
+ getHeader(name: string): string | number | string[] | undefined;
39
+ removeHeader(name: string): void;
40
+ headersSent?: boolean;
41
+
42
+ // redirect helpers
43
+ redirect(url: string): void;
44
+ redirect(status: number, url: string): void;
45
+
46
+ // streaming (optional)
47
+ write?(chunk: any): void;
48
+ end?(chunk?: any): void;
49
+ }
50
+
51
+ // Extended Lieko Request and Response with framework helpers
52
+ interface Request<
53
+ Params extends Record<string, any> = Record<string, any>,
54
+ Query extends Record<string, any> = Record<string, any>,
55
+ Body = any
56
+ > extends RequestBase {
57
+ params: Params;
58
+ query: Query;
59
+ body: Body;
60
+ files: Record<string, {
61
+ filename: string;
62
+ tempFilePath?: string;
63
+ data?: Buffer;
64
+ contentType?: string;
65
+ size?: number;
66
+ }>;
67
+ }
68
+
69
+ interface Response extends ResponseBase {
70
+ // Rich helpers provided by Lieko
71
+ ok(data?: any, message?: string): void;
72
+ created(data?: any, message?: string): void;
73
+ accepted(data?: any, message?: string): void;
74
+ noContent(): void;
75
+
76
+ badRequest(message?: string, details?: any): void;
77
+ unauthorized(message?: string, details?: any): void;
78
+ forbidden(message?: string, details?: any): void;
79
+ notFound(message?: string, details?: any): void;
80
+ error(message?: string, status?: number, details?: any): void;
81
+
82
+ // convenience helpers sometimes provided
83
+ paginated?(items: any[], meta: any): void;
84
+ file?(pathOrBuffer: string | Buffer, filename?: string): void;
85
+ download?(path: string, filename?: string): void;
86
+
87
+ // short alias
88
+ statusCode?: number;
89
+ }
90
+
91
+ // -------------- Handler / Middleware --------------
92
+ type Handler<
93
+ Params extends Record<string, any> = Record<string, any>,
94
+ Query extends Record<string, any> = Record<string, any>,
95
+ Body = any
96
+ > = (req: Request<Params, Query, Body>, res: Response, next?: (err?: any) => void) => any | Promise<any>;
97
+
98
+ // -------------- CORS / BodyParser options --------------
99
+ interface CorsOptions {
100
+ enabled?: boolean;
101
+ origin?: "*" | string | string[]; // supports wildcard like https://*.example.com
102
+ methods?: string[]; // allowed methods
103
+ headers?: string[]; // allowed headers
104
+ exposedHeaders?: string[];
105
+ credentials?: boolean;
106
+ maxAge?: number;
107
+ debug?: boolean;
108
+ strictOrigin?: boolean; // 403 if origin not allowed
109
+ allowPrivateNetwork?: boolean; // Access-Control-Allow-Private-Network
110
+ }
111
+
112
+ interface JsonBodyOptions {
113
+ limit?: string; // e.g. "10mb"
114
+ strict?: boolean;
115
+ }
116
+
117
+ interface UrlencodedOptions {
118
+ limit?: string;
119
+ extended?: boolean;
120
+ }
121
+
122
+ interface MultipartOptions {
123
+ limit?: string;
124
+ tempDir?: string;
125
+ }
126
+
127
+ interface BodyParserOptions {
128
+ json?: JsonBodyOptions;
129
+ urlencoded?: UrlencodedOptions;
130
+ multipart?: MultipartOptions;
131
+ }
132
+
133
+ // -------------- Validation / Schema (loose typing to match runtime) --------------
134
+ // The framework has a validation system — keep it flexible (user can extend)
135
+ type ValidatorFn = (value: any) => boolean | string | Promise<boolean | string>;
136
+
137
+ interface SchemaField {
138
+ type?: string | string[]; // "string", "number", etc.
139
+ required?: boolean;
140
+ validators?: ValidatorFn[];
141
+ default?: any;
142
+ // additional user metadata allowed
143
+ [key: string]: any;
144
+ }
145
+
146
+ interface SchemaDefinition {
147
+ [field: string]: SchemaField | string; // string shorthand for type
148
+ }
149
+
150
+ interface Schema {
151
+ definition: SchemaDefinition;
152
+ validate(obj: any, options?: { partial?: boolean }): { valid: boolean; errors?: any };
153
+ }
154
+
155
+ // -------------- Routes / Options --------------
156
+ interface RouteOptions {
157
+ cors?: Partial<CorsOptions>;
158
+ bodyParserOptions?: Partial<BodyParserOptions>;
159
+ middlewares?: Handler[];
160
+ // validation
161
+ schema?: Schema | SchemaDefinition;
162
+ // other custom per-route options
163
+ [key: string]: any;
164
+ }
165
+
166
+ // -------------- App interface --------------
167
+ interface App {
168
+ // route methods (typed path param extraction)
169
+ get<Path extends string, Q = any, B = any>(
170
+ path: Path,
171
+ optionsOrHandler?: RouteOptions | Handler<ExtractRouteParams<Path>, Q, B>,
172
+ maybeHandler?: Handler<ExtractRouteParams<Path>, Q, B>
173
+ ): this;
174
+
175
+ post<Path extends string, Q = any, B = any>(
176
+ path: Path,
177
+ optionsOrHandler?: RouteOptions | Handler<ExtractRouteParams<Path>, Q, B>,
178
+ maybeHandler?: Handler<ExtractRouteParams<Path>, Q, B>
179
+ ): this;
180
+
181
+ put<Path extends string, Q = any, B = any>(
182
+ path: Path,
183
+ optionsOrHandler?: RouteOptions | Handler<ExtractRouteParams<Path>, Q, B>,
184
+ maybeHandler?: Handler<ExtractRouteParams<Path>, Q, B>
185
+ ): this;
186
+
187
+ patch<Path extends string, Q = any, B = any>(
188
+ path: Path,
189
+ optionsOrHandler?: RouteOptions | Handler<ExtractRouteParams<Path>, Q, B>,
190
+ maybeHandler?: Handler<ExtractRouteParams<Path>, Q, B>
191
+ ): this;
192
+
193
+ delete<Path extends string, Q = any, B = any>(
194
+ path: Path,
195
+ optionsOrHandler?: RouteOptions | Handler<ExtractRouteParams<Path>, Q, B>,
196
+ maybeHandler?: Handler<ExtractRouteParams<Path>, Q, B>
197
+ ): this;
198
+
199
+ options<Path extends string, Q = any, B = any>(
200
+ path: Path,
201
+ optionsOrHandler?: RouteOptions | Handler<ExtractRouteParams<Path>, Q, B>,
202
+ maybeHandler?: Handler<ExtractRouteParams<Path>, Q, B>
203
+ ): this;
204
+
205
+ head<Path extends string, Q = any, B = any>(
206
+ path: Path,
207
+ optionsOrHandler?: RouteOptions | Handler<ExtractRouteParams<Path>, Q, B>,
208
+ maybeHandler?: Handler<ExtractRouteParams<Path>, Q, B>
209
+ ): this;
210
+
211
+ // manual route API
212
+ route(method: string, path: string, options: RouteOptions, handler: Handler): this;
213
+
214
+ // middleware
215
+ use(handler: Handler): this;
216
+ use(path: string, handler: Handler): this;
217
+
218
+ // grouping
219
+ group(prefix: string, cb: (router: App) => void): this;
220
+
221
+ // CORS
222
+ cors(options?: Partial<CorsOptions>): this;
223
+
224
+ // body parser options at app-level
225
+ bodyParser(options: Partial<BodyParserOptions>): this;
226
+
227
+ // validation / schema helpers
228
+ schema(name: string, definition: SchemaDefinition | Schema): Schema;
229
+ validate(schemaOrDef: string | Schema | SchemaDefinition): Handler;
230
+
231
+ // error / notFound handlers
232
+ notFound(handler: Handler): this;
233
+ error(handler: (err: any, req: Request, res: Response) => any): this;
234
+
235
+ // utilities
236
+ printRoutes(): void;
237
+ close(): Promise<void> | void;
238
+
239
+ // server control
240
+ listen(port: number, callback?: () => void): any;
241
+ listen(port: number, host: string, callback?: () => void): any;
242
+ }
243
+
244
+ // -------------- Factory / Constructor --------------
245
+ interface ConstructorOptions {
246
+ // initial options
247
+ cors?: Partial<CorsOptions>;
248
+ bodyParser?: Partial<BodyParserOptions>;
249
+ trustProxy?: boolean | string | string[];
250
+ // other global options
251
+ [key: string]: any;
252
+ }
253
+
254
+ interface LiekoStatic {
255
+ (opts?: ConstructorOptions): App;
256
+
257
+ // expose helpers statically if present in runtime
258
+ createApp(opts?: ConstructorOptions): App;
259
+ }
260
+ }
261
+
262
+ // Export as CommonJS-compatible factory function
263
+ declare const Lieko: Lieko.LiekoStatic;
264
+ export = Lieko;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lieko-express",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/eiwSrvt/lieko-express"
@@ -17,6 +17,7 @@
17
17
  "type": "commonjs",
18
18
  "files": [
19
19
  "lieko-express.js",
20
+ "lieko-express.d.ts",
20
21
  "README.md"
21
22
  ]
22
23
  }