express-project-builder 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/dist/bin/index.d.ts +3 -0
- package/dist/bin/index.d.ts.map +1 -0
- package/dist/bin/index.js +177 -0
- package/dist/bin/index.js.map +1 -0
- package/dist/lib/config/createEnvExample.d.ts +3 -0
- package/dist/lib/config/createEnvExample.d.ts.map +1 -0
- package/dist/lib/config/createEnvExample.js +39 -0
- package/dist/lib/config/createEnvExample.js.map +1 -0
- package/dist/lib/config/createEslintConfig.d.ts +2 -0
- package/dist/lib/config/createEslintConfig.d.ts.map +1 -0
- package/dist/lib/config/createEslintConfig.js +48 -0
- package/dist/lib/config/createEslintConfig.js.map +1 -0
- package/dist/lib/config/createGitignore.d.ts +3 -0
- package/dist/lib/config/createGitignore.d.ts.map +1 -0
- package/dist/lib/config/createGitignore.js +51 -0
- package/dist/lib/config/createGitignore.js.map +1 -0
- package/dist/lib/config/createPackageJson.d.ts +3 -0
- package/dist/lib/config/createPackageJson.d.ts.map +1 -0
- package/dist/lib/config/createPackageJson.js +74 -0
- package/dist/lib/config/createPackageJson.js.map +1 -0
- package/dist/lib/config/createPrettierConfig.d.ts +2 -0
- package/dist/lib/config/createPrettierConfig.d.ts.map +1 -0
- package/dist/lib/config/createPrettierConfig.js +30 -0
- package/dist/lib/config/createPrettierConfig.js.map +1 -0
- package/dist/lib/config/createTsConfig.d.ts +2 -0
- package/dist/lib/config/createTsConfig.d.ts.map +1 -0
- package/dist/lib/config/createTsConfig.js +133 -0
- package/dist/lib/config/createTsConfig.js.map +1 -0
- package/dist/lib/prisma/create_Schema.Prisma.d.ts +3 -0
- package/dist/lib/prisma/create_Schema.Prisma.d.ts.map +1 -0
- package/dist/lib/prisma/create_Schema.Prisma.js +36 -0
- package/dist/lib/prisma/create_Schema.Prisma.js.map +1 -0
- package/dist/lib/src/builders/create_QueryBuilder_Helpers.d.ts +3 -0
- package/dist/lib/src/builders/create_QueryBuilder_Helpers.d.ts.map +1 -0
- package/dist/lib/src/builders/create_QueryBuilder_Helpers.js +292 -0
- package/dist/lib/src/builders/create_QueryBuilder_Helpers.js.map +1 -0
- package/dist/lib/src/config/create_Config_Index.d.ts +9 -0
- package/dist/lib/src/config/create_Config_Index.d.ts.map +1 -0
- package/dist/lib/src/config/create_Config_Index.js +92 -0
- package/dist/lib/src/config/create_Config_Index.js.map +1 -0
- package/dist/lib/src/constants/create_UserRole_Constant.d.ts +7 -0
- package/dist/lib/src/constants/create_UserRole_Constant.d.ts.map +1 -0
- package/dist/lib/src/constants/create_UserRole_Constant.js +39 -0
- package/dist/lib/src/constants/create_UserRole_Constant.js.map +1 -0
- package/dist/lib/src/createAppFile.d.ts +2 -0
- package/dist/lib/src/createAppFile.d.ts.map +1 -0
- package/dist/lib/src/createAppFile.js +122 -0
- package/dist/lib/src/createAppFile.js.map +1 -0
- package/dist/lib/src/createServerFile.d.ts +3 -0
- package/dist/lib/src/createServerFile.d.ts.map +1 -0
- package/dist/lib/src/createServerFile.js +75 -0
- package/dist/lib/src/createServerFile.js.map +1 -0
- package/dist/lib/src/createSrcStructure.d.ts +2 -0
- package/dist/lib/src/createSrcStructure.d.ts.map +1 -0
- package/dist/lib/src/createSrcStructure.js +50 -0
- package/dist/lib/src/createSrcStructure.js.map +1 -0
- package/dist/lib/src/errors/create_AppError_Class.d.ts +7 -0
- package/dist/lib/src/errors/create_AppError_Class.d.ts.map +1 -0
- package/dist/lib/src/errors/create_AppError_Class.js +65 -0
- package/dist/lib/src/errors/create_AppError_Class.js.map +1 -0
- package/dist/lib/src/errors/create_HandleCastError.d.ts +9 -0
- package/dist/lib/src/errors/create_HandleCastError.d.ts.map +1 -0
- package/dist/lib/src/errors/create_HandleCastError.js +101 -0
- package/dist/lib/src/errors/create_HandleCastError.js.map +1 -0
- package/dist/lib/src/errors/create_HandleDB_ValidationError.d.ts +9 -0
- package/dist/lib/src/errors/create_HandleDB_ValidationError.d.ts.map +1 -0
- package/dist/lib/src/errors/create_HandleDB_ValidationError.js +119 -0
- package/dist/lib/src/errors/create_HandleDB_ValidationError.js.map +1 -0
- package/dist/lib/src/errors/create_HandleDuplicateError.d.ts +9 -0
- package/dist/lib/src/errors/create_HandleDuplicateError.d.ts.map +1 -0
- package/dist/lib/src/errors/create_HandleDuplicateError.js +99 -0
- package/dist/lib/src/errors/create_HandleDuplicateError.js.map +1 -0
- package/dist/lib/src/errors/create_HandleZodValidationError.d.ts +7 -0
- package/dist/lib/src/errors/create_HandleZodValidationError.d.ts.map +1 -0
- package/dist/lib/src/errors/create_HandleZodValidationError.js +50 -0
- package/dist/lib/src/errors/create_HandleZodValidationError.js.map +1 -0
- package/dist/lib/src/interfaces/create_EmailFomat_type.d.ts +7 -0
- package/dist/lib/src/interfaces/create_EmailFomat_type.d.ts.map +1 -0
- package/dist/lib/src/interfaces/create_EmailFomat_type.js +34 -0
- package/dist/lib/src/interfaces/create_EmailFomat_type.js.map +1 -0
- package/dist/lib/src/interfaces/create_Errors_type.d.ts +7 -0
- package/dist/lib/src/interfaces/create_Errors_type.d.ts.map +1 -0
- package/dist/lib/src/interfaces/create_Errors_type.js +43 -0
- package/dist/lib/src/interfaces/create_Errors_type.js.map +1 -0
- package/dist/lib/src/interfaces/create_Index_d_type.d.ts +9 -0
- package/dist/lib/src/interfaces/create_Index_d_type.d.ts.map +1 -0
- package/dist/lib/src/interfaces/create_Index_d_type.js +45 -0
- package/dist/lib/src/interfaces/create_Index_d_type.js.map +1 -0
- package/dist/lib/src/interfaces/create_JWT_Token_type.d.ts +9 -0
- package/dist/lib/src/interfaces/create_JWT_Token_type.d.ts.map +1 -0
- package/dist/lib/src/interfaces/create_JWT_Token_type.js +33 -0
- package/dist/lib/src/interfaces/create_JWT_Token_type.js.map +1 -0
- package/dist/lib/src/interfaces/create_UserRole_type.d.ts +7 -0
- package/dist/lib/src/interfaces/create_UserRole_type.d.ts.map +1 -0
- package/dist/lib/src/interfaces/create_UserRole_type.js +33 -0
- package/dist/lib/src/interfaces/create_UserRole_type.js.map +1 -0
- package/dist/lib/src/middlewares/create_Auth_Gurad.d.ts +9 -0
- package/dist/lib/src/middlewares/create_Auth_Gurad.d.ts.map +1 -0
- package/dist/lib/src/middlewares/create_Auth_Gurad.js +99 -0
- package/dist/lib/src/middlewares/create_Auth_Gurad.js.map +1 -0
- package/dist/lib/src/middlewares/create_BigIntSerializer_Guard.d.ts +7 -0
- package/dist/lib/src/middlewares/create_BigIntSerializer_Guard.d.ts.map +1 -0
- package/dist/lib/src/middlewares/create_BigIntSerializer_Guard.js +64 -0
- package/dist/lib/src/middlewares/create_BigIntSerializer_Guard.js.map +1 -0
- package/dist/lib/src/middlewares/create_FormDataToSetJSONformatData_Guard.d.ts +7 -0
- package/dist/lib/src/middlewares/create_FormDataToSetJSONformatData_Guard.d.ts.map +1 -0
- package/dist/lib/src/middlewares/create_FormDataToSetJSONformatData_Guard.js +63 -0
- package/dist/lib/src/middlewares/create_FormDataToSetJSONformatData_Guard.js.map +1 -0
- package/dist/lib/src/middlewares/create_Global_ErrorHandler_Guard.d.ts +12 -0
- package/dist/lib/src/middlewares/create_Global_ErrorHandler_Guard.d.ts.map +1 -0
- package/dist/lib/src/middlewares/create_Global_ErrorHandler_Guard.js +375 -0
- package/dist/lib/src/middlewares/create_Global_ErrorHandler_Guard.js.map +1 -0
- package/dist/lib/src/middlewares/create_Handle_File_Upload_Middleware.d.ts +7 -0
- package/dist/lib/src/middlewares/create_Handle_File_Upload_Middleware.d.ts.map +1 -0
- package/dist/lib/src/middlewares/create_Handle_File_Upload_Middleware.js +260 -0
- package/dist/lib/src/middlewares/create_Handle_File_Upload_Middleware.js.map +1 -0
- package/dist/lib/src/middlewares/create_NotFound_Guard.d.ts +7 -0
- package/dist/lib/src/middlewares/create_NotFound_Guard.d.ts.map +1 -0
- package/dist/lib/src/middlewares/create_NotFound_Guard.js +47 -0
- package/dist/lib/src/middlewares/create_NotFound_Guard.js.map +1 -0
- package/dist/lib/src/middlewares/create_RateLimiting_Handler_Guard.d.ts +7 -0
- package/dist/lib/src/middlewares/create_RateLimiting_Handler_Guard.d.ts.map +1 -0
- package/dist/lib/src/middlewares/create_RateLimiting_Handler_Guard.js +270 -0
- package/dist/lib/src/middlewares/create_RateLimiting_Handler_Guard.js.map +1 -0
- package/dist/lib/src/middlewares/create_ValidateRequest_Guard.d.ts +7 -0
- package/dist/lib/src/middlewares/create_ValidateRequest_Guard.d.ts.map +1 -0
- package/dist/lib/src/middlewares/create_ValidateRequest_Guard.js +104 -0
- package/dist/lib/src/middlewares/create_ValidateRequest_Guard.js.map +1 -0
- package/dist/lib/src/modules/create_DemoModules_SrcStructure.d.ts +7 -0
- package/dist/lib/src/modules/create_DemoModules_SrcStructure.d.ts.map +1 -0
- package/dist/lib/src/modules/create_DemoModules_SrcStructure.js +367 -0
- package/dist/lib/src/modules/create_DemoModules_SrcStructure.js.map +1 -0
- package/dist/lib/src/routers/create_Router_Index_Path.d.ts +7 -0
- package/dist/lib/src/routers/create_Router_Index_Path.d.ts.map +1 -0
- package/dist/lib/src/routers/create_Router_Index_Path.js +54 -0
- package/dist/lib/src/routers/create_Router_Index_Path.js.map +1 -0
- package/dist/lib/src/shared/create_Prisma_Shated.d.ts +9 -0
- package/dist/lib/src/shared/create_Prisma_Shated.d.ts.map +1 -0
- package/dist/lib/src/shared/create_Prisma_Shated.js +34 -0
- package/dist/lib/src/shared/create_Prisma_Shated.js.map +1 -0
- package/dist/lib/src/utils/createCatchAsync_Utils.d.ts +7 -0
- package/dist/lib/src/utils/createCatchAsync_Utils.d.ts.map +1 -0
- package/dist/lib/src/utils/createCatchAsync_Utils.js +59 -0
- package/dist/lib/src/utils/createCatchAsync_Utils.js.map +1 -0
- package/dist/lib/src/utils/createLoggerFile.d.ts +7 -0
- package/dist/lib/src/utils/createLoggerFile.d.ts.map +1 -0
- package/dist/lib/src/utils/createLoggerFile.js +35 -0
- package/dist/lib/src/utils/createLoggerFile.js.map +1 -0
- package/dist/lib/src/utils/create_Common_Utils.d.ts +9 -0
- package/dist/lib/src/utils/create_Common_Utils.d.ts.map +1 -0
- package/dist/lib/src/utils/create_Common_Utils.js +262 -0
- package/dist/lib/src/utils/create_Common_Utils.js.map +1 -0
- package/dist/lib/src/utils/create_Date_Time_Validation_Utils.d.ts +7 -0
- package/dist/lib/src/utils/create_Date_Time_Validation_Utils.d.ts.map +1 -0
- package/dist/lib/src/utils/create_Date_Time_Validation_Utils.js +181 -0
- package/dist/lib/src/utils/create_Date_Time_Validation_Utils.js.map +1 -0
- package/dist/lib/src/utils/create_Node_Cache_Utils.d.ts +7 -0
- package/dist/lib/src/utils/create_Node_Cache_Utils.d.ts.map +1 -0
- package/dist/lib/src/utils/create_Node_Cache_Utils.js +149 -0
- package/dist/lib/src/utils/create_Node_Cache_Utils.js.map +1 -0
- package/dist/lib/src/utils/create_Remove_Uploaded_Files_Utils.d.ts +7 -0
- package/dist/lib/src/utils/create_Remove_Uploaded_Files_Utils.d.ts.map +1 -0
- package/dist/lib/src/utils/create_Remove_Uploaded_Files_Utils.js +162 -0
- package/dist/lib/src/utils/create_Remove_Uploaded_Files_Utils.js.map +1 -0
- package/dist/lib/src/utils/create_SendEmail_Utils.d.ts +7 -0
- package/dist/lib/src/utils/create_SendEmail_Utils.d.ts.map +1 -0
- package/dist/lib/src/utils/create_SendEmail_Utils.js +140 -0
- package/dist/lib/src/utils/create_SendEmail_Utils.js.map +1 -0
- package/dist/lib/src/utils/create_sendResponse_Utils.d.ts +7 -0
- package/dist/lib/src/utils/create_sendResponse_Utils.d.ts.map +1 -0
- package/dist/lib/src/utils/create_sendResponse_Utils.js +95 -0
- package/dist/lib/src/utils/create_sendResponse_Utils.js.map +1 -0
- package/dist/lib/utils/helpers.d.ts +5 -0
- package/dist/lib/utils/helpers.d.ts.map +1 -0
- package/dist/lib/utils/helpers.js +31 -0
- package/dist/lib/utils/helpers.js.map +1 -0
- package/dist/lib/utils/types.d.ts +5 -0
- package/dist/lib/utils/types.d.ts.map +1 -0
- package/dist/lib/utils/types.js +2 -0
- package/dist/lib/utils/types.js.map +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { createFile } from "../../utils/helpers.js";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a Node Cache utilities file for in-memory caching
|
|
6
|
+
* @param projectPath - Absolute path to the project root
|
|
7
|
+
* @returns Promise that resolves when the Node Cache utils file is created
|
|
8
|
+
*/
|
|
9
|
+
export const create_Node_Cache_Utils = async (projectPath) => {
|
|
10
|
+
try {
|
|
11
|
+
const node_cache_template = `/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
12
|
+
import NodeCache from 'node-cache';
|
|
13
|
+
|
|
14
|
+
// Initialize cache with default options (stdTTL: 0 = never expire, checkperiod: 600 = 10 minutes)
|
|
15
|
+
export const myCache = new NodeCache({
|
|
16
|
+
stdTTL: 0, // Default time to live in seconds (0 = never expire)
|
|
17
|
+
checkperiod: 600, // Period in seconds to check for expired items
|
|
18
|
+
useClones: false // For better performance with large objects
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Create or update cache entry in RAM
|
|
23
|
+
* @param key - Cache key (string)
|
|
24
|
+
* @param value - Value to cache (any type)
|
|
25
|
+
* @param ttl - Time to live in seconds (optional)
|
|
26
|
+
* @returns boolean indicating success
|
|
27
|
+
*/
|
|
28
|
+
export const create_cache_into_RAM = (
|
|
29
|
+
key: string,
|
|
30
|
+
value: any,
|
|
31
|
+
ttl?: number
|
|
32
|
+
): boolean => {
|
|
33
|
+
try {
|
|
34
|
+
if (ttl && ttl > 0) {
|
|
35
|
+
return myCache.set(key, value, ttl);
|
|
36
|
+
}
|
|
37
|
+
return myCache.set(key, value);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
console.error('Cache creation error:', error);
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Retrieve cached value from RAM
|
|
46
|
+
* @param key - Cache key (string)
|
|
47
|
+
* @returns Cached value or undefined if not found
|
|
48
|
+
*/
|
|
49
|
+
export const get_cache_from_RAM = (key: string): any | undefined => {
|
|
50
|
+
try {
|
|
51
|
+
return myCache.get(key);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error('Cache retrieval error:', error);
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Delete specific cache entry from RAM
|
|
60
|
+
* @param key - Cache key to delete
|
|
61
|
+
* @returns number of deleted entries (0 or 1)
|
|
62
|
+
*/
|
|
63
|
+
export const delete_cache_from_RAM = (key: string): number => {
|
|
64
|
+
try {
|
|
65
|
+
return myCache.del(key);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.error('Cache deletion error:', error);
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Clear all cache entries
|
|
74
|
+
* @returns void
|
|
75
|
+
*/
|
|
76
|
+
export const clear_all_cache = (): void => {
|
|
77
|
+
try {
|
|
78
|
+
myCache.flushAll();
|
|
79
|
+
console.log('All cache entries cleared');
|
|
80
|
+
} catch (error) {
|
|
81
|
+
console.error('Cache clearing error:', error);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get cache statistics
|
|
87
|
+
* @returns Object with cache statistics
|
|
88
|
+
*/
|
|
89
|
+
export const get_cache_stats = () => {
|
|
90
|
+
try {
|
|
91
|
+
return myCache.getStats();
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error('Cache stats error:', error);
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Check if key exists in cache
|
|
100
|
+
* @param key - Cache key to check
|
|
101
|
+
* @returns boolean indicating if key exists
|
|
102
|
+
*/
|
|
103
|
+
export const has_cache_key = (key: string): boolean => {
|
|
104
|
+
try {
|
|
105
|
+
return myCache.has(key);
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error('Cache key check error:', error);
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Get all cache keys
|
|
114
|
+
* @returns Array of all cache keys
|
|
115
|
+
*/
|
|
116
|
+
export const get_all_cache_keys = (): string[] => {
|
|
117
|
+
try {
|
|
118
|
+
return myCache.keys();
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error('Cache keys retrieval error:', error);
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Get TTL for a specific key
|
|
127
|
+
* @param key - Cache key
|
|
128
|
+
* @returns TTL in seconds or 0 if no TTL set
|
|
129
|
+
*/
|
|
130
|
+
export const get_cache_ttl = (key: string): number => {
|
|
131
|
+
try {
|
|
132
|
+
return myCache.getTtl(key) || 0;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
console.error('Cache TTL retrieval error:', error);
|
|
135
|
+
return 0;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
`;
|
|
139
|
+
await createFile(path.join(projectPath, "src/app/utils", "node_cache.ts"), node_cache_template);
|
|
140
|
+
// Success message with green checkmark and text
|
|
141
|
+
console.log(chalk.green("✅ Node Cache Utils file created successfully"));
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
// Error message with red cross and text
|
|
145
|
+
console.error(chalk.red("❌ Error creating Node Cache Utils file:"), err);
|
|
146
|
+
throw err;
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
//# sourceMappingURL=create_Node_Cache_Utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_Node_Cache_Utils.js","sourceRoot":"","sources":["../../../../src/lib/src/utils/create_Node_Cache_Utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,EAC1C,WAAmB,EACJ,EAAE;IACjB,IAAI,CAAC;QACH,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+H/B,CAAC;QAEE,MAAM,UAAU,CACd,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,eAAe,EAAE,eAAe,CAAC,EACxD,mBAAmB,CACpB,CAAC;QAEF,gDAAgD;QAChD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC,CAAC;IAC3E,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,wCAAwC;QACxC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,yCAAyC,CAAC,EAAE,GAAG,CAAC,CAAC;QACzE,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a remove uploaded files utilities file for cleaning up uploaded files
|
|
3
|
+
* @param projectPath - Absolute path to the project root
|
|
4
|
+
* @returns Promise that resolves when the remove uploaded files utils file is created
|
|
5
|
+
*/
|
|
6
|
+
export declare const create_Remove_Uploaded_Files_Utils: (projectPath: string) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=create_Remove_Uploaded_Files_Utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_Remove_Uploaded_Files_Utils.d.ts","sourceRoot":"","sources":["../../../../src/lib/src/utils/create_Remove_Uploaded_Files_Utils.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,kCAAkC,GAC7C,aAAa,MAAM,KAClB,OAAO,CAAC,IAAI,CAiKd,CAAC"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { createFile } from "../../utils/helpers.js";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a remove uploaded files utilities file for cleaning up uploaded files
|
|
6
|
+
* @param projectPath - Absolute path to the project root
|
|
7
|
+
* @returns Promise that resolves when the remove uploaded files utils file is created
|
|
8
|
+
*/
|
|
9
|
+
export const create_Remove_Uploaded_Files_Utils = async (projectPath) => {
|
|
10
|
+
try {
|
|
11
|
+
const removeUploadedFilesTemplate = `/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
12
|
+
import fs from 'fs/promises';
|
|
13
|
+
import { promisify } from 'util';
|
|
14
|
+
import path from 'path';
|
|
15
|
+
|
|
16
|
+
// Promisify the unlink function for callback-based operations
|
|
17
|
+
const unlinkAsync = promisify(fs.unlink);
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Remove a single uploaded file
|
|
21
|
+
* @param filePath - Path to the file to remove
|
|
22
|
+
* @returns Promise that resolves when file is removed or rejects on error
|
|
23
|
+
*/
|
|
24
|
+
export const removeSingleUploadedFile = async (filePath: string): Promise<void> => {
|
|
25
|
+
try {
|
|
26
|
+
// Check if file exists before attempting to remove
|
|
27
|
+
await fs.access(filePath, fs.constants.F_OK);
|
|
28
|
+
await unlinkAsync(filePath);
|
|
29
|
+
} catch (error: any) {
|
|
30
|
+
// If file doesn't exist (ENOENT), that's okay - it might have been removed already
|
|
31
|
+
if (error.code !== 'ENOENT') {
|
|
32
|
+
console.error(\`Failed to remove file: \${filePath}\`, error);
|
|
33
|
+
throw new Error(\`Failed to remove file: \${filePath}\`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Type definition for uploaded files structure from multer
|
|
40
|
+
*/
|
|
41
|
+
type UploadedFiles = {
|
|
42
|
+
[fieldname: string]: Express.Multer.File[];
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Remove multiple uploaded files from all fields
|
|
47
|
+
* @param files - Object containing uploaded files grouped by field name
|
|
48
|
+
* @returns Promise that resolves when all files are removed or rejects on error
|
|
49
|
+
*/
|
|
50
|
+
export const removeUploadedFiles = async (files: UploadedFiles): Promise<void> => {
|
|
51
|
+
if (!files || Object.keys(files).length === 0) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
// Create an array of removal promises for all files
|
|
57
|
+
const removalPromises: Promise<void>[] = [];
|
|
58
|
+
|
|
59
|
+
// Iterate through each field in the files object
|
|
60
|
+
for (const fieldName in files) {
|
|
61
|
+
if (Object.prototype.hasOwnProperty.call(files, fieldName)) {
|
|
62
|
+
const fieldFiles = files[fieldName] || [];
|
|
63
|
+
|
|
64
|
+
// Add removal promise for each file in the field
|
|
65
|
+
for (const file of fieldFiles) {
|
|
66
|
+
removalPromises.push(
|
|
67
|
+
removeSingleUploadedFile(file.path).catch(error => {
|
|
68
|
+
console.error(\`Failed to remove file: \${file.path}\`, error);
|
|
69
|
+
// Don't throw - continue removing other files
|
|
70
|
+
})
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Execute all removal promises concurrently
|
|
77
|
+
await Promise.all(removalPromises);
|
|
78
|
+
} catch (error: any) {
|
|
79
|
+
console.error('Error during batch file removal:', error);
|
|
80
|
+
throw new Error('Failed to remove uploaded files');
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Remove files from specific fields only
|
|
86
|
+
* @param files - Object containing uploaded files grouped by field name
|
|
87
|
+
* @param fieldNames - Array of field names to remove files from
|
|
88
|
+
* @returns Promise that resolves when specified files are removed or rejects on error
|
|
89
|
+
*/
|
|
90
|
+
export const removeFilesFromFields = async (
|
|
91
|
+
files: UploadedFiles,
|
|
92
|
+
fieldNames: string[]
|
|
93
|
+
): Promise<void> => {
|
|
94
|
+
if (!files || fieldNames.length === 0) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
const removalPromises: Promise<void>[] = [];
|
|
100
|
+
|
|
101
|
+
// Only process files from specified fields
|
|
102
|
+
for (const fieldName of fieldNames) {
|
|
103
|
+
const fieldFiles = files[fieldName] || [];
|
|
104
|
+
|
|
105
|
+
for (const file of fieldFiles) {
|
|
106
|
+
removalPromises.push(
|
|
107
|
+
removeSingleUploadedFile(file.path).catch(error => {
|
|
108
|
+
console.error(\`Failed to remove file: \${file.path}\`, error);
|
|
109
|
+
})
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
await Promise.all(removalPromises);
|
|
115
|
+
} catch (error: any) {
|
|
116
|
+
console.error('Error during field-specific file removal:', error);
|
|
117
|
+
throw new Error('Failed to remove files from specified fields');
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Clean up uploaded files directory (removes all files in a directory)
|
|
123
|
+
* @param directoryPath - Path to the directory to clean
|
|
124
|
+
* @returns Promise that resolves when directory is cleaned or rejects on error
|
|
125
|
+
*/
|
|
126
|
+
export const cleanUploadDirectory = async (directoryPath: string): Promise<void> => {
|
|
127
|
+
try {
|
|
128
|
+
// Check if directory exists
|
|
129
|
+
await fs.access(directoryPath, fs.constants.F_OK);
|
|
130
|
+
|
|
131
|
+
// Read all files in the directory
|
|
132
|
+
const files = await fs.readdir(directoryPath);
|
|
133
|
+
|
|
134
|
+
// Remove each file
|
|
135
|
+
const removalPromises = files.map(file => {
|
|
136
|
+
const filePath = path.join(directoryPath, file);
|
|
137
|
+
return removeSingleUploadedFile(filePath).catch(error => {
|
|
138
|
+
console.error(\`Failed to remove file: \${filePath}\`, error);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
await Promise.all(removalPromises);
|
|
143
|
+
} catch (error: any) {
|
|
144
|
+
// If directory doesn't exist, that's okay
|
|
145
|
+
if (error.code !== 'ENOENT') {
|
|
146
|
+
console.error('Error cleaning upload directory:', error);
|
|
147
|
+
throw new Error(\`Failed to clean directory: \${directoryPath}\`);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
`;
|
|
152
|
+
await createFile(path.join(projectPath, "src/app/utils", "removeUploadedFiles.ts"), removeUploadedFilesTemplate);
|
|
153
|
+
// Success message with green checkmark and text
|
|
154
|
+
console.log(chalk.green("✅ Remove Uploaded Files Utils file created successfully"));
|
|
155
|
+
}
|
|
156
|
+
catch (err) {
|
|
157
|
+
// Error message with red cross and text
|
|
158
|
+
console.error(chalk.red("❌ Error creating Remove Uploaded Files Utils file:"), err);
|
|
159
|
+
throw err;
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
//# sourceMappingURL=create_Remove_Uploaded_Files_Utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_Remove_Uploaded_Files_Utils.js","sourceRoot":"","sources":["../../../../src/lib/src/utils/create_Remove_Uploaded_Files_Utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;GAIG;AACH,MAAM,CAAC,MAAM,kCAAkC,GAAG,KAAK,EACrD,WAAmB,EACJ,EAAE;IACjB,IAAI,CAAC;QACH,MAAM,2BAA2B,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4IvC,CAAC;QAEE,MAAM,UAAU,CACd,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,eAAe,EAAE,wBAAwB,CAAC,EACjE,2BAA2B,CAC5B,CAAC;QAEF,gDAAgD;QAChD,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,KAAK,CAAC,yDAAyD,CAAC,CACvE,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,wCAAwC;QACxC,OAAO,CAAC,KAAK,CACX,KAAK,CAAC,GAAG,CAAC,oDAAoD,CAAC,EAC/D,GAAG,CACJ,CAAC;QACF,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a send email utilities file for handling email operations
|
|
3
|
+
* @param projectPath - Absolute path to the project root
|
|
4
|
+
* @returns Promise that resolves when the send email utils file is created
|
|
5
|
+
*/
|
|
6
|
+
export declare const create_SendEmail_Utils: (projectPath: string) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=create_SendEmail_Utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_SendEmail_Utils.d.ts","sourceRoot":"","sources":["../../../../src/lib/src/utils/create_SendEmail_Utils.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GACjC,aAAa,MAAM,KAClB,OAAO,CAAC,IAAI,CAsId,CAAC"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { createFile } from "../../utils/helpers.js";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a send email utilities file for handling email operations
|
|
6
|
+
* @param projectPath - Absolute path to the project root
|
|
7
|
+
* @returns Promise that resolves when the send email utils file is created
|
|
8
|
+
*/
|
|
9
|
+
export const create_SendEmail_Utils = async (projectPath) => {
|
|
10
|
+
try {
|
|
11
|
+
const sendEmailTemplate = `/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
12
|
+
import nodemailer from 'nodemailer'
|
|
13
|
+
import config from '../config'
|
|
14
|
+
import { TEmailFormat } from '../interfaces/emailFormat'
|
|
15
|
+
import AppError from '../errors/AppError'
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Email transporter configuration
|
|
19
|
+
*/
|
|
20
|
+
const createTransporter = () => {
|
|
21
|
+
return nodemailer.createTransport({
|
|
22
|
+
host: config.email_host_provider_name as string,
|
|
23
|
+
port: Number(config.email_host_provider_port),
|
|
24
|
+
secure: config.NODE_ENV === 'production', // Use TLS in production
|
|
25
|
+
auth: {
|
|
26
|
+
user: config.email_sender_email,
|
|
27
|
+
pass: config.email_sender_email_app_pass
|
|
28
|
+
},
|
|
29
|
+
// Additional security options for production
|
|
30
|
+
...(config.NODE_ENV === 'production' && {
|
|
31
|
+
tls: {
|
|
32
|
+
rejectUnauthorized: true // Enforce certificate validation in production
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Send email using configured transporter
|
|
40
|
+
* @param to - Recipient email address
|
|
41
|
+
* @param emailTemplate - Email template containing subject and body
|
|
42
|
+
* @returns Promise that resolves when email is sent
|
|
43
|
+
* @throws AppError if email sending fails
|
|
44
|
+
*/
|
|
45
|
+
const sendEmail = async (to: string, emailTemplate: TEmailFormat): Promise<void> => {
|
|
46
|
+
try {
|
|
47
|
+
// Validate required parameters
|
|
48
|
+
if (!to || !emailTemplate?.subject || !emailTemplate?.emailBody) {
|
|
49
|
+
throw new AppError(400, 'INVALID_INPUT', 'Missing required email parameters');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Create transporter
|
|
53
|
+
const transporter = createTransporter();
|
|
54
|
+
|
|
55
|
+
// Prepare email options
|
|
56
|
+
const mailOptions = {
|
|
57
|
+
from: \`"\${config.email_sender_name || 'Your App'}" <\${config.email_sender_email}>\`,
|
|
58
|
+
to,
|
|
59
|
+
subject: emailTemplate.subject,
|
|
60
|
+
text: emailTemplate.text || '', // Fallback to empty string if text not provided
|
|
61
|
+
html: emailTemplate.emailBody,
|
|
62
|
+
// Optional: Add reply-to address
|
|
63
|
+
...(config.email_reply_to && {
|
|
64
|
+
replyTo: config.email_reply_to
|
|
65
|
+
})
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// Send email
|
|
69
|
+
const info = await transporter.sendMail(mailOptions);
|
|
70
|
+
|
|
71
|
+
// Log successful email sending (optional)
|
|
72
|
+
console.log('Email sent successfully:', {
|
|
73
|
+
messageId: info.messageId,
|
|
74
|
+
to,
|
|
75
|
+
subject: emailTemplate.subject
|
|
76
|
+
});
|
|
77
|
+
} catch (error: any) {
|
|
78
|
+
console.error('Email sending failed:', {
|
|
79
|
+
to,
|
|
80
|
+
subject: emailTemplate?.subject,
|
|
81
|
+
error: error.message,
|
|
82
|
+
stack: error.stack
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Throw a more specific error based on the error type
|
|
86
|
+
if (error.code === 'EAUTH') {
|
|
87
|
+
throw new AppError(500, 'EMAIL_AUTH_ERROR', 'Email authentication failed. Check email credentials.');
|
|
88
|
+
} else if (error.code === 'ECONNECTION') {
|
|
89
|
+
throw new AppError(500, 'EMAIL_CONNECTION_ERROR', 'Failed to connect to email server.');
|
|
90
|
+
} else if (error.code === 'EMESSAGE') {
|
|
91
|
+
throw new AppError(400, 'EMAIL_MESSAGE_ERROR', 'Invalid email message format.');
|
|
92
|
+
} else {
|
|
93
|
+
throw new AppError(500, 'EMAIL_SEND_ERROR', \`Failed to send email: \${error.message}\`);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Test email configuration
|
|
100
|
+
* @returns Promise that resolves when test email is sent
|
|
101
|
+
*/
|
|
102
|
+
export const testEmailConfig = async (): Promise<void> => {
|
|
103
|
+
try {
|
|
104
|
+
const testEmail = config.email_test_recipient || config.email_sender_email;
|
|
105
|
+
|
|
106
|
+
if (!testEmail) {
|
|
107
|
+
throw new AppError(400, 'INVALID_CONFIG', 'No test email recipient configured');
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const testTemplate: TEmailFormat = {
|
|
111
|
+
subject: 'Test Email from Your App',
|
|
112
|
+
text: 'This is a test email to verify your email configuration.',
|
|
113
|
+
emailBody: \`
|
|
114
|
+
<h1>Email Configuration Test</h1>
|
|
115
|
+
<p>If you receive this email, your email configuration is working correctly.</p>
|
|
116
|
+
<p>Time sent: \${new Date().toISOString()}</p>
|
|
117
|
+
\`
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
await sendEmail(testEmail, testTemplate);
|
|
121
|
+
console.log('Email configuration test successful');
|
|
122
|
+
} catch (error) {
|
|
123
|
+
console.error('Email configuration test failed:', error);
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
export default sendEmail;
|
|
129
|
+
`;
|
|
130
|
+
await createFile(path.join(projectPath, "src/app/utils", "sendEmail.ts"), sendEmailTemplate);
|
|
131
|
+
// Success message with green checkmark and text
|
|
132
|
+
console.log(chalk.green("✅ SendEmail utility file created successfully"));
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
// Error message with red cross and text
|
|
136
|
+
console.error(chalk.red("❌ Error creating SendEmail utility file:"), err);
|
|
137
|
+
throw err;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
//# sourceMappingURL=create_SendEmail_Utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_SendEmail_Utils.js","sourceRoot":"","sources":["../../../../src/lib/src/utils/create_SendEmail_Utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EACzC,WAAmB,EACJ,EAAE;IACjB,IAAI,CAAC;QACH,MAAM,iBAAiB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsH7B,CAAC;QAEE,MAAM,UAAU,CACd,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,eAAe,EAAE,cAAc,CAAC,EACvD,iBAAiB,CAClB,CAAC;QAEF,gDAAgD;QAChD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,+CAA+C,CAAC,CAAC,CAAC;IAC5E,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,wCAAwC;QACxC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,0CAA0C,CAAC,EAAE,GAAG,CAAC,CAAC;QAC1E,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a send response utilities file for standardized API responses
|
|
3
|
+
* @param projectPath - Absolute path to the project root
|
|
4
|
+
* @returns Promise that resolves when the send response utils file is created
|
|
5
|
+
*/
|
|
6
|
+
export declare const create_SendResponse_Utils: (projectPath: string) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=create_sendResponse_Utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_sendResponse_Utils.d.ts","sourceRoot":"","sources":["../../../../src/lib/src/utils/create_sendResponse_Utils.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GACpC,aAAa,MAAM,KAClB,OAAO,CAAC,IAAI,CA8Fd,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { createFile } from "../../utils/helpers.js";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a send response utilities file for standardized API responses
|
|
6
|
+
* @param projectPath - Absolute path to the project root
|
|
7
|
+
* @returns Promise that resolves when the send response utils file is created
|
|
8
|
+
*/
|
|
9
|
+
export const create_SendResponse_Utils = async (projectPath) => {
|
|
10
|
+
try {
|
|
11
|
+
const responseTemplate = `import { Response } from 'express';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Metadata type for paginated responses
|
|
15
|
+
*/
|
|
16
|
+
type TMeta = {
|
|
17
|
+
page: number;
|
|
18
|
+
limit: number;
|
|
19
|
+
totalData: number;
|
|
20
|
+
totalPage: number;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Standardized response structure
|
|
25
|
+
*/
|
|
26
|
+
type TSendResponse<T> = {
|
|
27
|
+
status: number;
|
|
28
|
+
success: boolean;
|
|
29
|
+
message?: string;
|
|
30
|
+
meta?: TMeta;
|
|
31
|
+
data: T;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Sends a standardized JSON response
|
|
36
|
+
* @param res - Express Response object
|
|
37
|
+
* @param data - Response data containing status, success, message, meta, and actual data
|
|
38
|
+
* @returns Express Response with JSON payload
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* // Basic success response
|
|
42
|
+
* sendResponse(res, {
|
|
43
|
+
* status: 200,
|
|
44
|
+
* success: true,
|
|
45
|
+
* message: 'User created successfully',
|
|
46
|
+
* data: newUser
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* // Paginated response
|
|
51
|
+
* sendResponse(res, {
|
|
52
|
+
* status: 200,
|
|
53
|
+
* success: true,
|
|
54
|
+
* message: 'Users retrieved',
|
|
55
|
+
* meta: {
|
|
56
|
+
* page: 1,
|
|
57
|
+
* limit: 10,
|
|
58
|
+
* totalData: 100,
|
|
59
|
+
* totalPage: 10
|
|
60
|
+
* },
|
|
61
|
+
* data: users
|
|
62
|
+
* });
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* // Error response
|
|
66
|
+
* sendResponse(res, {
|
|
67
|
+
* status: 404,
|
|
68
|
+
* success: false,
|
|
69
|
+
* message: 'User not found',
|
|
70
|
+
* data: null
|
|
71
|
+
* });
|
|
72
|
+
*/
|
|
73
|
+
const sendResponse = <T>(res: Response, data: TSendResponse<T>) => {
|
|
74
|
+
return res.status(data.status).json({
|
|
75
|
+
status: data.status,
|
|
76
|
+
success: data.success,
|
|
77
|
+
message: data.message,
|
|
78
|
+
meta: data.meta,
|
|
79
|
+
data: data.data
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export default sendResponse;
|
|
84
|
+
`;
|
|
85
|
+
await createFile(path.join(projectPath, "src/app/utils", "sendResponse.ts"), responseTemplate);
|
|
86
|
+
// Success message with green checkmark and text
|
|
87
|
+
console.log(chalk.green("✅ SendResponse utility file created successfully"));
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
// Error message with red cross and text
|
|
91
|
+
console.error(chalk.red("❌ Error creating SendResponse utility file:"), err);
|
|
92
|
+
throw err;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=create_sendResponse_Utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_sendResponse_Utils.js","sourceRoot":"","sources":["../../../../src/lib/src/utils/create_sendResponse_Utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,KAAK,EAC5C,WAAmB,EACJ,EAAE;IACjB,IAAI,CAAC;QACH,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyE5B,CAAC;QAEE,MAAM,UAAU,CACd,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,eAAe,EAAE,iBAAiB,CAAC,EAC1D,gBAAgB,CACjB,CAAC;QAEF,gDAAgD;QAChD,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAChE,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,wCAAwC;QACxC,OAAO,CAAC,KAAK,CACX,KAAK,CAAC,GAAG,CAAC,6CAA6C,CAAC,EACxD,GAAG,CACJ,CAAC;QACF,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const createProjectDirectory: (projectName: string) => Promise<void>;
|
|
2
|
+
export declare const createDirectory: (dirPath: string) => Promise<void>;
|
|
3
|
+
export declare const createFile: (filePath: string, content: string) => Promise<void>;
|
|
4
|
+
export declare const createJsonFile: <T = unknown>(filePath: string, data: T) => Promise<void>;
|
|
5
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/helpers.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,sBAAsB,GACjC,aAAa,MAAM,KAClB,OAAO,CAAC,IAAI,CAEd,CAAC;AAKF,eAAO,MAAM,eAAe,GAAU,SAAS,MAAM,KAAG,OAAO,CAAC,IAAI,CAEnE,CAAC;AAOF,eAAO,MAAM,UAAU,GACrB,UAAU,MAAM,EAChB,SAAS,MAAM,KACd,OAAO,CAAC,IAAI,CAEd,CAAC;AAQF,eAAO,MAAM,cAAc,GAAU,CAAC,GAAG,OAAO,EAC9C,UAAU,MAAM,EAChB,MAAM,CAAC,KACN,OAAO,CAAC,IAAI,CAEd,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
// Creates a project directory with the given name
|
|
3
|
+
// Parameter: projectName (string) - Name of the directory to create
|
|
4
|
+
// Returns: Promise<void> - Resolves when directory is created
|
|
5
|
+
export const createProjectDirectory = async (projectName) => {
|
|
6
|
+
await fs.mkdir(projectName);
|
|
7
|
+
};
|
|
8
|
+
// Creates a directory and any necessary parent directories
|
|
9
|
+
// Parameter: dirPath (string) - Path of the directory to create
|
|
10
|
+
// Returns: Promise<void> - Resolves when directory is created
|
|
11
|
+
export const createDirectory = async (dirPath) => {
|
|
12
|
+
await fs.ensureDir(dirPath);
|
|
13
|
+
};
|
|
14
|
+
// Creates a file with specified content
|
|
15
|
+
// Parameters:
|
|
16
|
+
// filePath (string) - Path where the file should be created
|
|
17
|
+
// content (string) - Content to write to the file
|
|
18
|
+
// Returns: Promise<void> - Resolves when file is created
|
|
19
|
+
export const createFile = async (filePath, content) => {
|
|
20
|
+
await fs.writeFile(filePath, content);
|
|
21
|
+
};
|
|
22
|
+
// Creates a JSON file with formatted data
|
|
23
|
+
// Generic Type: T - Type of data to be serialized (defaults to unknown)
|
|
24
|
+
// Parameters:
|
|
25
|
+
// filePath (string) - Path where the JSON file should be created
|
|
26
|
+
// data (T) - Data object to serialize to JSON
|
|
27
|
+
// Returns: Promise<void> - Resolves when JSON file is created
|
|
28
|
+
export const createJsonFile = async (filePath, data) => {
|
|
29
|
+
await fs.writeJSON(filePath, data, { spaces: 2 });
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../src/lib/utils/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,UAAU,CAAC;AAE1B,kDAAkD;AAClD,oEAAoE;AACpE,8DAA8D;AAC9D,MAAM,CAAC,MAAM,sBAAsB,GAAG,KAAK,EACzC,WAAmB,EACJ,EAAE;IACjB,MAAM,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;AAC9B,CAAC,CAAC;AAEF,2DAA2D;AAC3D,gEAAgE;AAChE,8DAA8D;AAC9D,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,OAAe,EAAiB,EAAE;IACtE,MAAM,EAAE,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AAC9B,CAAC,CAAC;AAEF,wCAAwC;AACxC,cAAc;AACd,8DAA8D;AAC9D,oDAAoD;AACpD,yDAAyD;AACzD,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAC7B,QAAgB,EAChB,OAAe,EACA,EAAE;IACjB,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AACxC,CAAC,CAAC;AAEF,0CAA0C;AAC1C,wEAAwE;AACxE,cAAc;AACd,mEAAmE;AACnE,gDAAgD;AAChD,8DAA8D;AAC9D,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EACjC,QAAgB,EAChB,IAAO,EACQ,EAAE;IACjB,MAAM,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC;AACpD,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/lib/utils/types.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,EAAE,uBAAuB,GAAG,wBAAwB,GAAG,MAAM,CAAC;IACtE,WAAW,EAAE,OAAO,CAAC;CACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/lib/utils/types.ts"],"names":[],"mappings":""}
|