express-resforge 1.0.0
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/CHANGELOG.md +27 -0
- package/LICENSE +21 -0
- package/README.md +309 -0
- package/dist/constants/defaultMessages.d.ts +5 -0
- package/dist/constants/defaultMessages.js +29 -0
- package/dist/constants/httpStatus.d.ts +28 -0
- package/dist/constants/httpStatus.js +33 -0
- package/dist/constants/responseCodes.d.ts +22 -0
- package/dist/constants/responseCodes.js +25 -0
- package/dist/core/context.d.ts +36 -0
- package/dist/core/context.js +45 -0
- package/dist/core/formatter.d.ts +7 -0
- package/dist/core/formatter.js +17 -0
- package/dist/core/pluginManager.d.ts +27 -0
- package/dist/core/pluginManager.js +37 -0
- package/dist/core/responseBuilder.d.ts +32 -0
- package/dist/core/responseBuilder.js +107 -0
- package/dist/core/responseFactory.d.ts +12 -0
- package/dist/core/responseFactory.js +52 -0
- package/dist/formatter/axiosFormatter.d.ts +8 -0
- package/dist/formatter/axiosFormatter.js +12 -0
- package/dist/formatter/firebaseFormatter.d.ts +6 -0
- package/dist/formatter/firebaseFormatter.js +19 -0
- package/dist/formatter/joiFormatter.d.ts +8 -0
- package/dist/formatter/joiFormatter.js +26 -0
- package/dist/formatter/mongooseFormatter.d.ts +2 -0
- package/dist/formatter/mongooseFormatter.js +20 -0
- package/dist/formatter/prismaFormatter.d.ts +15 -0
- package/dist/formatter/prismaFormatter.js +49 -0
- package/dist/formatter/zodFormatter.d.ts +9 -0
- package/dist/formatter/zodFormatter.js +27 -0
- package/dist/helpers/cache.d.ts +2 -0
- package/dist/helpers/cache.js +6 -0
- package/dist/helpers/cookies.d.ts +2 -0
- package/dist/helpers/cookies.js +6 -0
- package/dist/helpers/download.d.ts +2 -0
- package/dist/helpers/download.js +6 -0
- package/dist/helpers/errors.d.ts +10 -0
- package/dist/helpers/errors.js +21 -0
- package/dist/helpers/headers.d.ts +2 -0
- package/dist/helpers/headers.js +7 -0
- package/dist/helpers/health.d.ts +2 -0
- package/dist/helpers/health.js +10 -0
- package/dist/helpers/meta.d.ts +2 -0
- package/dist/helpers/meta.js +11 -0
- package/dist/helpers/pagination.d.ts +9 -0
- package/dist/helpers/pagination.js +14 -0
- package/dist/helpers/redirect.d.ts +2 -0
- package/dist/helpers/redirect.js +6 -0
- package/dist/helpers/success.d.ts +3 -0
- package/dist/helpers/success.js +7 -0
- package/dist/helpers/validation.d.ts +2 -0
- package/dist/helpers/validation.js +6 -0
- package/dist/index.d.ts +90 -0
- package/dist/index.js +74 -0
- package/dist/middleware/errorHandler.d.ts +9 -0
- package/dist/middleware/errorHandler.js +90 -0
- package/dist/middleware/requestId.d.ts +16 -0
- package/dist/middleware/requestId.js +18 -0
- package/dist/middleware/requestTimer.d.ts +6 -0
- package/dist/middleware/requestTimer.js +26 -0
- package/dist/middleware/responseMiddleware.d.ts +7 -0
- package/dist/middleware/responseMiddleware.js +93 -0
- package/dist/plugins/pluginAPI.d.ts +7 -0
- package/dist/plugins/pluginAPI.js +12 -0
- package/dist/types/config.d.ts +52 -0
- package/dist/types/config.js +22 -0
- package/dist/types/index.d.ts +3 -0
- package/dist/types/index.js +19 -0
- package/dist/types/plugin.d.ts +11 -0
- package/dist/types/plugin.js +2 -0
- package/dist/types/responses.d.ts +72 -0
- package/dist/types/responses.js +6 -0
- package/dist/utils/cleanObject.d.ts +11 -0
- package/dist/utils/cleanObject.js +26 -0
- package/dist/utils/deepMerge.d.ts +12 -0
- package/dist/utils/deepMerge.js +43 -0
- package/dist/utils/helpers.d.ts +4 -0
- package/dist/utils/helpers.js +15 -0
- package/dist/utils/time.d.ts +4 -0
- package/dist/utils/time.js +11 -0
- package/dist/utils/uuid.d.ts +9 -0
- package/dist/utils/uuid.js +24 -0
- package/dist/version.d.ts +4 -0
- package/dist/version.js +7 -0
- package/package.json +68 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview High-speed runtime object optimization utility.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Removes all keys containing undefined values from an object mutating it in-place
|
|
6
|
+
* to achieve zero new object allocation penalties.
|
|
7
|
+
* @template T Structural object layout constraint.
|
|
8
|
+
* @param {T} obj Target input object to cleanse.
|
|
9
|
+
* @returns {T} Cleaned reference to the exact same input object.
|
|
10
|
+
*/
|
|
11
|
+
export declare function cleanObject<T extends Record<string, any>>(obj: T): T;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview High-speed runtime object optimization utility.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.cleanObject = cleanObject;
|
|
7
|
+
/**
|
|
8
|
+
* Removes all keys containing undefined values from an object mutating it in-place
|
|
9
|
+
* to achieve zero new object allocation penalties.
|
|
10
|
+
* @template T Structural object layout constraint.
|
|
11
|
+
* @param {T} obj Target input object to cleanse.
|
|
12
|
+
* @returns {T} Cleaned reference to the exact same input object.
|
|
13
|
+
*/
|
|
14
|
+
function cleanObject(obj) {
|
|
15
|
+
if (!obj || typeof obj !== 'object')
|
|
16
|
+
return obj;
|
|
17
|
+
const keys = Object.keys(obj);
|
|
18
|
+
const length = keys.length;
|
|
19
|
+
for (let i = 0; i < length; i++) {
|
|
20
|
+
const key = keys[i];
|
|
21
|
+
if (obj[key] === undefined) {
|
|
22
|
+
delete obj[key];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return obj;
|
|
26
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview High-performance object merge utility focusing on pure operational speed.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Performs deep structural merging of a source object into a target destination.
|
|
6
|
+
* Optimized against prototype pollution exploits.
|
|
7
|
+
* @template T Target structural shape constraint.
|
|
8
|
+
* @param {T} target Base target dictionary to append records onto.
|
|
9
|
+
* @param {Record<string, any>} source Incoming properties to map over target.
|
|
10
|
+
* @returns {T} Fully combined object layout.
|
|
11
|
+
*/
|
|
12
|
+
export declare function deepMerge<T extends Record<string, any>>(target: T, source: Record<string, any>): T;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview High-performance object merge utility focusing on pure operational speed.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.deepMerge = deepMerge;
|
|
7
|
+
/**
|
|
8
|
+
* Validates if an input target represents a simple plain object structure.
|
|
9
|
+
*/
|
|
10
|
+
function isPlainObject(item) {
|
|
11
|
+
return !!item && typeof item === 'object' && !Array.isArray(item) && Object.prototype.toString.call(item) === '[object Object]';
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Performs deep structural merging of a source object into a target destination.
|
|
15
|
+
* Optimized against prototype pollution exploits.
|
|
16
|
+
* @template T Target structural shape constraint.
|
|
17
|
+
* @param {T} target Base target dictionary to append records onto.
|
|
18
|
+
* @param {Record<string, any>} source Incoming properties to map over target.
|
|
19
|
+
* @returns {T} Fully combined object layout.
|
|
20
|
+
*/
|
|
21
|
+
function deepMerge(target, source) {
|
|
22
|
+
if (!source)
|
|
23
|
+
return target;
|
|
24
|
+
const keys = Object.keys(source);
|
|
25
|
+
const length = keys.length;
|
|
26
|
+
for (let i = 0; i < length; i++) {
|
|
27
|
+
const key = keys[i];
|
|
28
|
+
// Mitigate potential Prototype Pollution attack vectors completely
|
|
29
|
+
if (key === '__proto__' || key === 'constructor') {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const sourceValue = source[key];
|
|
33
|
+
const targetValue = target[key];
|
|
34
|
+
if (isPlainObject(sourceValue) && isPlainObject(targetValue)) {
|
|
35
|
+
deepMerge(targetValue, sourceValue);
|
|
36
|
+
}
|
|
37
|
+
else if (sourceValue !== undefined) {
|
|
38
|
+
// Direct fast value assignment bypasses costly clone steps
|
|
39
|
+
target[key] = sourceValue;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return target;
|
|
43
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseToInteger = parseToInteger;
|
|
4
|
+
/**
|
|
5
|
+
* Safely parses input items to numeric limits with resilient default fallbacks.
|
|
6
|
+
*/
|
|
7
|
+
function parseToInteger(value, fallback) {
|
|
8
|
+
if (typeof value === 'number')
|
|
9
|
+
return Math.floor(value);
|
|
10
|
+
if (typeof value === 'string') {
|
|
11
|
+
const parsed = parseInt(value, 10);
|
|
12
|
+
return isNaN(parsed) ? fallback : parsed;
|
|
13
|
+
}
|
|
14
|
+
return fallback;
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateDeltaMs = calculateDeltaMs;
|
|
4
|
+
/**
|
|
5
|
+
* Resolves process high-resolution tuples to unified float millisecond intervals.
|
|
6
|
+
*/
|
|
7
|
+
function calculateDeltaMs(startTime) {
|
|
8
|
+
const diff = process.hrtime(startTime);
|
|
9
|
+
const ms = (diff[0] * 1000) + (diff[1] / 1000000);
|
|
10
|
+
return Math.round(ms * 100) / 100;
|
|
11
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview High-performance, zero-dependency UUIDv4 identifier generator.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Generates an RFC4122 compliant UUID version 4 string using hardware-backed crypto.
|
|
6
|
+
* Optimized for zero external dependency runtime footprint.
|
|
7
|
+
* @returns {string} Compliant 36-character UUIDv4 string.
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateUuid(): string;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateUuid = generateUuid;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
/**
|
|
6
|
+
* @fileoverview High-performance, zero-dependency UUIDv4 identifier generator.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Generates an RFC4122 compliant UUID version 4 string using hardware-backed crypto.
|
|
10
|
+
* Optimized for zero external dependency runtime footprint.
|
|
11
|
+
* @returns {string} Compliant 36-character UUIDv4 string.
|
|
12
|
+
*/
|
|
13
|
+
function generateUuid() {
|
|
14
|
+
// Use Node.js native webcrypto optimization if available (Node 18+)
|
|
15
|
+
if (typeof node_crypto_1.webcrypto?.randomUUID === 'function') {
|
|
16
|
+
return node_crypto_1.webcrypto.randomUUID();
|
|
17
|
+
}
|
|
18
|
+
// Fast performance-fallback for isolated edge configurations
|
|
19
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (char) => {
|
|
20
|
+
const random = (Math.random() * 16) | 0;
|
|
21
|
+
const value = char === 'x' ? random : (random & 0x3) | 0x8;
|
|
22
|
+
return value.toString(16);
|
|
23
|
+
});
|
|
24
|
+
}
|
package/dist/version.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "express-resforge",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Enterprise-grade API response and error orchestration toolkit for Express.",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"homepage": "https://github.com/vaibhavdhake123/express-resforge#readme",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/vaibhavdhake123/express-resforge.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/vaibhavdhake123/express-resforge/issues"
|
|
14
|
+
},
|
|
15
|
+
"author": "Vaibhav Dhake",
|
|
16
|
+
"license": "MIT",
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md",
|
|
20
|
+
"CHANGELOG.md"
|
|
21
|
+
],
|
|
22
|
+
"directories": {
|
|
23
|
+
"doc": "docs",
|
|
24
|
+
"test": "tests"
|
|
25
|
+
},
|
|
26
|
+
"scripts": {
|
|
27
|
+
"build": "npx tsc",
|
|
28
|
+
"prepublishOnly": "npm run build && npm run test",
|
|
29
|
+
"test": "jest",
|
|
30
|
+
"test:watch": "jest --watch",
|
|
31
|
+
"test:coverage": "jest --coverage"
|
|
32
|
+
},
|
|
33
|
+
"keywords": [
|
|
34
|
+
"express",
|
|
35
|
+
"api",
|
|
36
|
+
"response",
|
|
37
|
+
"formatter",
|
|
38
|
+
"error-handler",
|
|
39
|
+
"middleware",
|
|
40
|
+
"zod",
|
|
41
|
+
"prisma",
|
|
42
|
+
"mongoose",
|
|
43
|
+
"joi",
|
|
44
|
+
"standardization",
|
|
45
|
+
"payload",
|
|
46
|
+
"json"
|
|
47
|
+
],
|
|
48
|
+
"engines": {
|
|
49
|
+
"node": ">=18.0.0"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"express": "^5.2.1"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@jest/globals": "^30.4.1",
|
|
56
|
+
"@swc/core": "^1.15.43",
|
|
57
|
+
"@swc/jest": "^0.2.39",
|
|
58
|
+
"@types/express": "^5.0.6",
|
|
59
|
+
"@types/jest": "^30.0.0",
|
|
60
|
+
"@types/node": "^26.1.1",
|
|
61
|
+
"@types/supertest": "^7.2.0",
|
|
62
|
+
"jest": "^30.4.2",
|
|
63
|
+
"supertest": "^7.2.2",
|
|
64
|
+
"ts-jest": "^29.4.11",
|
|
65
|
+
"ts-node": "^10.9.2",
|
|
66
|
+
"typescript": "^5.8.3"
|
|
67
|
+
}
|
|
68
|
+
}
|