Skip to content

Commit d695ac6

Browse files
committed
feat(server): add production-ready Express server and enhance middleware utilities
- Implement Express server framework with enterprise-ready features: - Security middleware (helmet, CORS, rate limiting) - Monitoring and health checks - Graceful shutdown support - Extensibility for future features - Add comprehensive test coverage for server functionality - Update deepObjMerge utility to support: - Circular references - Special objects (Date, RegExp, Set, Map) - TypedArrays and complex cloning scenarios
1 parent 7e181f7 commit d695ac6

25 files changed

Lines changed: 5179 additions & 238 deletions

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,11 +536,11 @@ logger.error({ context: "some context" }, "Error occurred");
536536

537537
## 🧩 Middleware Utilities
538538

539-
- `requestId(options?): Middleware` – Generate and attach a unique request ID to each request.
540-
- `responseTime(options?): Middleware` – Measure and log the response time for each request.
539+
- `requestId(options: { headerName?: string; exposeHeader?: boolean; generator?: () => string }): Middleware` – Generate and attach a unique request ID to each request.
540+
- `responseTime(options?: { addHeader?: boolean; logOnComplete?: boolean }): Middleware` – Measure and log the response time for each request.
541541
- `timeout(timeoutMs?: number): Middleware` – Abort requests that exceed a specified timeout.
542542
- `setupRequestContext(): Middleware` – Set up the request context for each incoming request.
543-
- `errorHandler(options?): Middleware` – Centralized error handling middleware.
543+
- `errorHandler(options: { logErrors?: boolean; includeDetails?: boolean }): Middleware` – Centralized error handling middleware.
544544

545545
**Example:**
546546
```ts
@@ -557,7 +557,8 @@ A set of helpers for working with JavaScript objects, including deep merging, fl
557557
- `isObjEmpty(obj: Record<any, any>): boolean` – Check if an object has no own properties.
558558
- `pick<T, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>` – Create a new object with only the specified keys.
559559
- `omit<T, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>` – Create a new object without the specified keys.
560-
- `deepObjMerge<T>(target: T, source: Partial<T>): T` – Deeply merge two objects.
560+
- `deepObjMerge<T extends object>(target: T, ...sources: any[]): T` – Deeply merge multiple objects into the target.
561+
- `isPlainObject(value: any): value is Record<string, any>` – Check if a value is a plain object.
561562
- `flattenObject<T>(obj: T, prefix?: string): Record<string, any>` – Flatten a nested object into dot notation.
562563
- `getValueByPath<T>(obj: T, path: string): any` – Get a value from an object by dot path.
563564
- `setValueByPath<T>(obj: T, path: string, value: any): T` – Set a value in an object by dot path.
@@ -828,6 +829,7 @@ const url = appendQueryParams('https://example.com', { page: 1, limit: 10 });
828829

829830
A comprehensive suite of validators for checking strings, numbers, objects, arrays, and common formats such as email, UUID, IP, and more. Useful for input validation and API parameter checks.
830831

832+
- `isPort(str: string | number): boolean` – Check if a string or number is a valid port number.
831833
- `isEmail(str: string): boolean` – Check if a string is a valid email address.
832834
- `isUUID(str: string): boolean` – Check if a string is a valid UUID.
833835
- `isURL(str: string): boolean` – Check if a string is a valid URL.

jest.config.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ export default {
2020
],
2121
testMatch: ['**/tests/**/*.test.ts'],
2222
coveragePathIgnorePatterns: ['index.ts'],
23-
testResultsProcessor: 'jest-sonar-reporter'
23+
testResultsProcessor: 'jest-sonar-reporter',
24+
detectOpenHandles: true
2425
}

0 commit comments

Comments
 (0)