lieko-express 0.0.6 → 0.0.8

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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # **Lieko-express — A Modern, Minimal, REST API Framework for Node.js**
1
+ # **Lieko-express — A Modern, Minimal, express-like Framework for Node.js**
2
2
 
3
- A lightweight, fast, and modern Node.js REST API framework built on top of the native `http` module. Zero external dependencies for core functionality.
3
+ A lightweight, fast, and modern Node.js framework built on top of the native `http` module. Zero external dependencies for core functionality.
4
4
 
5
5
  ![Performance](https://img.shields.io/badge/Performance-49%25_faster_than_Express-00d26a?style=for-the-badge)
6
6
 
@@ -388,7 +388,7 @@ app.use(async (req, res, next) => {
388
388
  Lieko-Express includes a **fully built-in, high-performance CORS engine**, with:
389
389
 
390
390
  * Global CORS (`app.cors()`)
391
- * Route-level CORS (`app.get("/test", { cors: {...} }, handler)`—coming soon if you want it)
391
+ * Route-level CORS (`app.get("/test", { cors: {...} }, handler)`)
392
392
  * Wildcard origins (`https://*.example.com`)
393
393
  * Multiple allowed origins
394
394
  * Strict mode (reject unknown origins)
@@ -907,8 +907,6 @@ const app = Lieko(); // Ready to handle JSON, form-data, files, etc.
907
907
  | `application/x-www-form-urlencoded` | **1mb** | ~1,048,576 bytes |
908
908
  | `multipart/form-data` (file uploads) | **10mb** | ~10,485,760 bytes |
909
909
 
910
- That’s already **10× more generous** than Express’s default 100kb!
911
-
912
910
  ### Change Limits — Three Super-Simple Ways
913
911
 
914
912
  #### 1. Per content-type (most common)
@@ -35,6 +35,8 @@ declare namespace Lieko {
35
35
 
36
36
  // headers helpers
37
37
  setHeader(name: string, value: string | number): void;
38
+ set(name: string | Record<string, string | number>, value?: string | number): void;
39
+ header(name: string, value: string | number): void;
38
40
  getHeader(name: string): string | number | string[] | undefined;
39
41
  removeHeader(name: string): void;
40
42
  headersSent?: boolean;
@@ -69,20 +71,22 @@ declare namespace Lieko {
69
71
  interface Response extends ResponseBase {
70
72
  // Rich helpers provided by Lieko
71
73
  ok(data?: any, message?: string): void;
74
+ success: (data?: any, message?: string) => void;
72
75
  created(data?: any, message?: string): void;
73
- accepted(data?: any, message?: string): void;
74
76
  noContent(): void;
77
+ accepted(data?: any, message?: string): void;
75
78
 
76
79
  badRequest(message?: string, details?: any): void;
77
80
  unauthorized(message?: string, details?: any): void;
78
81
  forbidden(message?: string, details?: any): void;
79
82
  notFound(message?: string, details?: any): void;
80
83
  error(message?: string, status?: number, details?: any): void;
84
+ fail: (message?: string, status?: number, details?: any) => void;
85
+ serverError(message?: string, details?: any): void;
81
86
 
82
87
  // 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;
88
+ paginated?(items: any[], total: number, message?: string): void;
89
+ html?(html: string, status?: number): void;
86
90
 
87
91
  // short alias
88
92
  statusCode?: number;
@@ -132,35 +136,57 @@ declare namespace Lieko {
132
136
 
133
137
  // -------------- Validation / Schema (loose typing to match runtime) --------------
134
138
  // 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;
139
+ type ValidatorFn = (value: any, field: string, data: any) => { field: string; message: string; type: string } | null;
140
+
141
+ interface Validators {
142
+ required(message?: string): ValidatorFn;
143
+ requiredTrue(message?: string): ValidatorFn;
144
+ optional(): ValidatorFn;
145
+ string(message?: string): ValidatorFn;
146
+ number(message?: string): ValidatorFn;
147
+ boolean(message?: string): ValidatorFn;
148
+ integer(message?: string): ValidatorFn;
149
+ positive(message?: string): ValidatorFn;
150
+ negative(message?: string): ValidatorFn;
151
+ email(message?: string): ValidatorFn;
152
+ min(minValue: number, message?: string): ValidatorFn;
153
+ max(maxValue: number, message?: string): ValidatorFn;
154
+ length(n: number, message?: string): ValidatorFn;
155
+ minLength(minLength: number, message?: string): ValidatorFn;
156
+ maxLength(maxLength: number, message?: string): ValidatorFn;
157
+ pattern(regex: RegExp, message?: string): ValidatorFn;
158
+ oneOf(allowedValues: any[], message?: string): ValidatorFn;
159
+ notOneOf(values: any[], message?: string): ValidatorFn;
160
+ custom(validatorFn: (value: any, data: any) => boolean, message?: string): ValidatorFn;
161
+ equal(expectedValue: any, message?: string): ValidatorFn;
162
+ mustBeTrue(message?: string): ValidatorFn;
163
+ mustBeFalse(message?: string): ValidatorFn;
164
+ date(message?: string): ValidatorFn;
165
+ before(limit: string | Date, message?: string): ValidatorFn;
166
+ after(limit: string | Date, message?: string): ValidatorFn;
167
+ startsWith(prefix: string, message?: string): ValidatorFn;
168
+ endsWith(suffix: string, message?: string): ValidatorFn;
144
169
  }
145
170
 
146
- interface SchemaDefinition {
147
- [field: string]: SchemaField | string; // string shorthand for type
171
+ class Schema {
172
+ constructor(rules: Record<string, ValidatorFn[]>);
173
+ rules: Record<string, ValidatorFn[]>;
174
+ fields: Record<string, ValidatorFn[]>;
175
+ validate(data: Record<string, any>): true | never;
148
176
  }
149
177
 
150
- interface Schema {
151
- definition: SchemaDefinition;
152
- validate(obj: any, options?: { partial?: boolean }): { valid: boolean; errors?: any };
153
- }
178
+ function validate(schema: Schema): Handler;
179
+
180
+ function validatePartial(schema: Schema): Handler;
154
181
 
155
182
  // -------------- 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;
183
+ interface Route {
184
+ method: string;
185
+ path: string;
186
+ handler: Handler;
187
+ middlewares: Handler[];
188
+ pattern: RegExp;
189
+ groupChain: any[];
164
190
  }
165
191
 
166
192
  // -------------- App interface --------------
@@ -168,77 +194,71 @@ declare namespace Lieko {
168
194
  // route methods (typed path param extraction)
169
195
  get<Path extends string, Q = any, B = any>(
170
196
  path: Path,
171
- optionsOrHandler?: RouteOptions | Handler<ExtractRouteParams<Path>, Q, B>,
172
- maybeHandler?: Handler<ExtractRouteParams<Path>, Q, B>
197
+ ...handlers: Handler<ExtractRouteParams<Path>, Q, B>[]
173
198
  ): this;
174
199
 
175
200
  post<Path extends string, Q = any, B = any>(
176
201
  path: Path,
177
- optionsOrHandler?: RouteOptions | Handler<ExtractRouteParams<Path>, Q, B>,
178
- maybeHandler?: Handler<ExtractRouteParams<Path>, Q, B>
202
+ ...handlers: Handler<ExtractRouteParams<Path>, Q, B>[]
179
203
  ): this;
180
204
 
181
205
  put<Path extends string, Q = any, B = any>(
182
206
  path: Path,
183
- optionsOrHandler?: RouteOptions | Handler<ExtractRouteParams<Path>, Q, B>,
184
- maybeHandler?: Handler<ExtractRouteParams<Path>, Q, B>
207
+ ...handlers: Handler<ExtractRouteParams<Path>, Q, B>[]
185
208
  ): this;
186
209
 
187
210
  patch<Path extends string, Q = any, B = any>(
188
211
  path: Path,
189
- optionsOrHandler?: RouteOptions | Handler<ExtractRouteParams<Path>, Q, B>,
190
- maybeHandler?: Handler<ExtractRouteParams<Path>, Q, B>
212
+ ...handlers: Handler<ExtractRouteParams<Path>, Q, B>[]
191
213
  ): this;
192
214
 
193
215
  delete<Path extends string, Q = any, B = any>(
194
216
  path: Path,
195
- optionsOrHandler?: RouteOptions | Handler<ExtractRouteParams<Path>, Q, B>,
196
- maybeHandler?: Handler<ExtractRouteParams<Path>, Q, B>
217
+ ...handlers: Handler<ExtractRouteParams<Path>, Q, B>[]
197
218
  ): this;
198
219
 
199
- options<Path extends string, Q = any, B = any>(
220
+ all<Path extends string, Q = any, B = any>(
200
221
  path: Path,
201
- optionsOrHandler?: RouteOptions | Handler<ExtractRouteParams<Path>, Q, B>,
202
- maybeHandler?: Handler<ExtractRouteParams<Path>, Q, B>
222
+ ...handlers: Handler<ExtractRouteParams<Path>, Q, B>[]
203
223
  ): this;
204
224
 
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
225
  // middleware
215
- use(handler: Handler): this;
216
- use(path: string, handler: Handler): this;
226
+ use(handler: Handler | App): this;
227
+ use(path: string, handler: Handler | App): this;
217
228
 
218
229
  // grouping
219
- group(prefix: string, cb: (router: App) => void): this;
230
+ group(basePath: string, callback: (group: App) => void): this;
220
231
 
221
232
  // CORS
222
- cors(options?: Partial<CorsOptions>): this;
233
+ cors(options?: Partial<CorsOptions>): Handler;
223
234
 
224
- // body parser options at app-level
225
- bodyParser(options: Partial<BodyParserOptions>): this;
235
+ // body parser
236
+ bodyParser: {
237
+ json(options?: JsonBodyOptions): Handler;
238
+ urlencoded(options?: UrlencodedOptions): Handler;
239
+ multipart(options?: MultipartOptions): Handler;
240
+ };
226
241
 
227
- // validation / schema helpers
228
- schema(name: string, definition: SchemaDefinition | Schema): Schema;
229
- validate(schemaOrDef: string | Schema | SchemaDefinition): Handler;
242
+ // static files
243
+ static(root: string, options?: { maxAge?: number; index?: string }): Handler;
230
244
 
231
- // error / notFound handlers
232
- notFound(handler: Handler): this;
233
- error(handler: (err: any, req: Request, res: Response) => any): this;
245
+ // error handler
246
+ error(res: Response, obj: any): void;
247
+
248
+ // settings
249
+ set(key: string, value: any): this;
250
+ get(key: string): any;
251
+
252
+ // debug
253
+ debug(value?: boolean | string): this;
234
254
 
235
255
  // utilities
256
+ listRoutes(): { method: string; path: string | string[]; middlewares: number }[];
236
257
  printRoutes(): void;
237
- close(): Promise<void> | void;
238
258
 
239
259
  // server control
240
- listen(port: number, callback?: () => void): any;
241
- listen(port: number, host: string, callback?: () => void): any;
260
+ listen(port: number, host?: string, callback?: () => void): any;
261
+ listen(...args: any[]): any;
242
262
  }
243
263
 
244
264
  // -------------- Factory / Constructor --------------
@@ -247,6 +267,9 @@ declare namespace Lieko {
247
267
  cors?: Partial<CorsOptions>;
248
268
  bodyParser?: Partial<BodyParserOptions>;
249
269
  trustProxy?: boolean | string | string[];
270
+ debug?: boolean;
271
+ allowTrailingSlash?: boolean;
272
+ strictTrailingSlash?: boolean;
250
273
  // other global options
251
274
  [key: string]: any;
252
275
  }
@@ -255,10 +278,16 @@ declare namespace Lieko {
255
278
  (opts?: ConstructorOptions): App;
256
279
 
257
280
  // expose helpers statically if present in runtime
258
- createApp(opts?: ConstructorOptions): App;
281
+ Router: () => App;
282
+ Schema: typeof Schema;
283
+ schema: (...args: any[]) => Schema;
284
+ validators: Validators;
285
+ validate: typeof validate;
286
+ validatePartial: (schema: Schema) => Handler;
287
+ ValidationError: typeof ValidationError;
288
+ static: (root: string, options?: { maxAge?: number; index?: string }) => Handler;
259
289
  }
260
290
  }
261
291
 
262
- // Export as CommonJS-compatible factory function
263
292
  declare const Lieko: Lieko.LiekoStatic;
264
- export = Lieko;
293
+ export = Lieko;