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,119 @@
|
|
|
1
|
+
import { createFile } from "../../utils/helpers.js";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a database-specific validation error handler file
|
|
6
|
+
* @param projectPath - Absolute path to the project root
|
|
7
|
+
* @param answers - User answers from CLI prompts
|
|
8
|
+
* @returns Promise that resolves when the validation error handler file is created
|
|
9
|
+
*/
|
|
10
|
+
export const create_HandleDB_ValidationError = async (projectPath, answers) => {
|
|
11
|
+
try {
|
|
12
|
+
if (answers.database === "MongoDB with Mongoose") {
|
|
13
|
+
const handleMongooseValidationErrorTemplate = `import mongoose from 'mongoose';
|
|
14
|
+
import { TErrorSource, TGenericErrorResponse } from '../interfaces/errors';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Handle Mongoose ValidationError
|
|
18
|
+
* @param err - Mongoose ValidationError instance
|
|
19
|
+
* @returns Formatted error response
|
|
20
|
+
*/
|
|
21
|
+
const handleMongooseValidationError = (
|
|
22
|
+
err: mongoose.Error.ValidationError
|
|
23
|
+
): TGenericErrorResponse => {
|
|
24
|
+
const errorSources: TErrorSource[] = Object.values(err.errors).map(
|
|
25
|
+
(val: mongoose.Error.ValidatorError | mongoose.Error.CastError) => {
|
|
26
|
+
return {
|
|
27
|
+
path: val.path,
|
|
28
|
+
message: val.message
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
statusCode: 400,
|
|
35
|
+
message: 'Validation Error',
|
|
36
|
+
errorSources
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default handleMongooseValidationError;
|
|
41
|
+
`;
|
|
42
|
+
await createFile(path.join(projectPath, "src/app/errors", "handleMongooseValidationError.ts"), handleMongooseValidationErrorTemplate);
|
|
43
|
+
}
|
|
44
|
+
if (answers.database === "PostgreSQL with Prisma") {
|
|
45
|
+
const handlePrismaValidationErrorTemplate = `import {
|
|
46
|
+
PrismaClientValidationError,
|
|
47
|
+
PrismaClientKnownRequestError
|
|
48
|
+
} from '@prisma/client/runtime/library'
|
|
49
|
+
import { TErrorSource, TGenericErrorResponse } from '../interfaces/errors'
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Handle Prisma validation errors
|
|
53
|
+
* @param err - Prisma error instance
|
|
54
|
+
* @returns Formatted error response or null if not a validation error
|
|
55
|
+
*/
|
|
56
|
+
const handlePrismaValidationError = (
|
|
57
|
+
err: PrismaClientValidationError | PrismaClientKnownRequestError
|
|
58
|
+
): TGenericErrorResponse | null => {
|
|
59
|
+
// Handle PrismaClientValidationError (invalid data types, missing required fields, etc.)
|
|
60
|
+
if (err instanceof PrismaClientValidationError) {
|
|
61
|
+
// Extract field information from error message
|
|
62
|
+
const fieldMatches = [...err.message.matchAll(/Argument \`(\w+)\`/g)].map(
|
|
63
|
+
match => match[1]
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
const errorSources: TErrorSource[] =
|
|
67
|
+
fieldMatches.length > 0
|
|
68
|
+
? fieldMatches.map(field => ({
|
|
69
|
+
path: field,
|
|
70
|
+
message: \`Invalid value for field: \${field}\`
|
|
71
|
+
}))
|
|
72
|
+
: [
|
|
73
|
+
{
|
|
74
|
+
path: 'validation',
|
|
75
|
+
message: 'Invalid data provided'
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
statusCode: 400,
|
|
81
|
+
message: 'Validation Error',
|
|
82
|
+
errorSources
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Handle PrismaClientKnownRequestError for missing required fields (P2018)
|
|
87
|
+
if (err instanceof PrismaClientKnownRequestError && err.code === 'P2018') {
|
|
88
|
+
const errorSources: TErrorSource[] = [
|
|
89
|
+
{
|
|
90
|
+
path: 'required_fields',
|
|
91
|
+
message: 'Required fields are missing'
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
statusCode: 400,
|
|
97
|
+
message: 'Validation Error',
|
|
98
|
+
errorSources
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Return null if it's not a validation error we handle
|
|
103
|
+
return null
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export default handlePrismaValidationError
|
|
107
|
+
`;
|
|
108
|
+
await createFile(path.join(projectPath, "src/app/errors", "handlePrismaValidationError.ts"), handlePrismaValidationErrorTemplate);
|
|
109
|
+
}
|
|
110
|
+
// Success message with green checkmark and text
|
|
111
|
+
console.log(chalk.green("✅ Successfully created HandleDB_ValidationError file"));
|
|
112
|
+
}
|
|
113
|
+
catch (err) {
|
|
114
|
+
// Error message with red cross and text
|
|
115
|
+
console.error(chalk.red("❌ Error creating HandleDB_ValidationError file:"), err);
|
|
116
|
+
throw err;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=create_HandleDB_ValidationError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_HandleDB_ValidationError.js","sourceRoot":"","sources":["../../../../src/lib/src/errors/create_HandleDB_ValidationError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,+BAA+B,GAAG,KAAK,EAClD,WAAmB,EACnB,OAAiB,EACF,EAAE;IACjB,IAAI,CAAC;QACH,IAAI,OAAO,CAAC,QAAQ,KAAK,uBAAuB,EAAE,CAAC;YACjD,MAAM,qCAAqC,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BnD,CAAC;YAEI,MAAM,UAAU,CACd,IAAI,CAAC,IAAI,CACP,WAAW,EACX,gBAAgB,EAChB,kCAAkC,CACnC,EACD,qCAAqC,CACtC,CAAC;QACJ,CAAC;QAED,IAAI,OAAO,CAAC,QAAQ,KAAK,wBAAwB,EAAE,CAAC;YAClD,MAAM,mCAAmC,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8DjD,CAAC;YAEI,MAAM,UAAU,CACd,IAAI,CAAC,IAAI,CACP,WAAW,EACX,gBAAgB,EAChB,gCAAgC,CACjC,EACD,mCAAmC,CACpC,CAAC;QACJ,CAAC;QAED,gDAAgD;QAChD,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,KAAK,CAAC,sDAAsD,CAAC,CACpE,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,wCAAwC;QACxC,OAAO,CAAC,KAAK,CACX,KAAK,CAAC,GAAG,CAAC,iDAAiD,CAAC,EAC5D,GAAG,CACJ,CAAC;QACF,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TAnswers } from "../../utils/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a database-specific duplicate error handler file
|
|
4
|
+
* @param projectPath - Absolute path to the project root
|
|
5
|
+
* @param answers - User answers from CLI prompts
|
|
6
|
+
* @returns Promise that resolves when the duplicate error handler file is created
|
|
7
|
+
*/
|
|
8
|
+
export declare const create_HandleDuplicateError: (projectPath: string, answers: TAnswers) => Promise<void>;
|
|
9
|
+
//# sourceMappingURL=create_HandleDuplicateError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_HandleDuplicateError.d.ts","sourceRoot":"","sources":["../../../../src/lib/src/errors/create_HandleDuplicateError.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,GACtC,aAAa,MAAM,EACnB,SAAS,QAAQ,KAChB,OAAO,CAAC,IAAI,CA8Gd,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { createFile } from "../../utils/helpers.js";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a database-specific duplicate error handler file
|
|
6
|
+
* @param projectPath - Absolute path to the project root
|
|
7
|
+
* @param answers - User answers from CLI prompts
|
|
8
|
+
* @returns Promise that resolves when the duplicate error handler file is created
|
|
9
|
+
*/
|
|
10
|
+
export const create_HandleDuplicateError = async (projectPath, answers) => {
|
|
11
|
+
try {
|
|
12
|
+
if (answers.database === "MongoDB with Mongoose") {
|
|
13
|
+
const handleMongooseDuplicateErrorTemplate = `/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
14
|
+
import { TErrorSource, TGenericErrorResponse } from '../interfaces/errors';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Handle Mongoose duplicate key error (11000)
|
|
18
|
+
* @param err - Mongoose error object
|
|
19
|
+
* @returns Formatted error response
|
|
20
|
+
*/
|
|
21
|
+
const handleMongooseDuplicateError = (err: any): TGenericErrorResponse => {
|
|
22
|
+
// Extract field name and value from error message
|
|
23
|
+
const match = err.message.match(/dup key: \\{\\s*([^:]+):\\s*"([^"]+)"\\s*\\}/);
|
|
24
|
+
const fieldName = match?.[1]?.trim() || 'unknown_field';
|
|
25
|
+
const fieldValue = match?.[2]?.trim() || 'unknown_value';
|
|
26
|
+
|
|
27
|
+
const errorSources: TErrorSource[] = [
|
|
28
|
+
{
|
|
29
|
+
path: fieldName,
|
|
30
|
+
message: fieldValue ? \`\${fieldValue} is already exists!\` : 'Duplicate value detected'
|
|
31
|
+
}
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
statusCode: 409,
|
|
36
|
+
message: 'Duplicate entry violation',
|
|
37
|
+
errorSources
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export default handleMongooseDuplicateError;
|
|
42
|
+
`;
|
|
43
|
+
await createFile(path.join(projectPath, "src/app/errors", "handleMongooseDuplicateError.ts"), handleMongooseDuplicateErrorTemplate);
|
|
44
|
+
}
|
|
45
|
+
if (answers.database === "PostgreSQL with Prisma") {
|
|
46
|
+
const handlePrismaDuplicateErrorTemplate = `import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library'
|
|
47
|
+
import { TErrorSource, TGenericErrorResponse } from '../interfaces/errors'
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Handle Prisma unique constraint violation error (P2002)
|
|
51
|
+
* @param err - Prisma known request error
|
|
52
|
+
* @returns Formatted error response or null if not a duplicate error
|
|
53
|
+
*/
|
|
54
|
+
const handlePrismaDuplicateError = (
|
|
55
|
+
err: PrismaClientKnownRequestError
|
|
56
|
+
): TGenericErrorResponse | null => {
|
|
57
|
+
// Handle unique constraint violation (P2002)
|
|
58
|
+
if (err.code === 'P2002') {
|
|
59
|
+
// Extract field name from the target array
|
|
60
|
+
const target = (err.meta?.target as string[]) || []
|
|
61
|
+
const fieldName = target.length > 0 ? target[0] : 'unknown_field'
|
|
62
|
+
|
|
63
|
+
// Extract duplicate value if available
|
|
64
|
+
const keyValue = err.meta?.target
|
|
65
|
+
? \`Duplicate value for field: \${fieldName}\`
|
|
66
|
+
: 'Duplicate entry violation'
|
|
67
|
+
|
|
68
|
+
const errorSources: TErrorSource[] = [
|
|
69
|
+
{
|
|
70
|
+
path: fieldName,
|
|
71
|
+
message: keyValue
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
statusCode: 409,
|
|
77
|
+
message: 'Duplicate entry violation',
|
|
78
|
+
errorSources
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Return null if it's not a duplicate error we handle
|
|
83
|
+
return null
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export default handlePrismaDuplicateError
|
|
87
|
+
`;
|
|
88
|
+
await createFile(path.join(projectPath, "src/app/errors", "handlePrismaDuplicateError.ts"), handlePrismaDuplicateErrorTemplate);
|
|
89
|
+
}
|
|
90
|
+
// Success message with green checkmark and text
|
|
91
|
+
console.log(chalk.green("✅ Successfully created HandleDuplicateError file"));
|
|
92
|
+
}
|
|
93
|
+
catch (err) {
|
|
94
|
+
// Error message with red cross and text
|
|
95
|
+
console.error(chalk.red("❌ Error creating HandleDuplicateError file:"), err);
|
|
96
|
+
throw err;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
//# sourceMappingURL=create_HandleDuplicateError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_HandleDuplicateError.js","sourceRoot":"","sources":["../../../../src/lib/src/errors/create_HandleDuplicateError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,KAAK,EAC9C,WAAmB,EACnB,OAAiB,EACF,EAAE;IACjB,IAAI,CAAC;QACH,IAAI,OAAO,CAAC,QAAQ,KAAK,uBAAuB,EAAE,CAAC;YACjD,MAAM,oCAAoC,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BlD,CAAC;YAEI,MAAM,UAAU,CACd,IAAI,CAAC,IAAI,CACP,WAAW,EACX,gBAAgB,EAChB,iCAAiC,CAClC,EACD,oCAAoC,CACrC,CAAC;QACJ,CAAC;QAED,IAAI,OAAO,CAAC,QAAQ,KAAK,wBAAwB,EAAE,CAAC;YAClD,MAAM,kCAAkC,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyChD,CAAC;YAEI,MAAM,UAAU,CACd,IAAI,CAAC,IAAI,CACP,WAAW,EACX,gBAAgB,EAChB,+BAA+B,CAChC,EACD,kCAAkC,CACnC,CAAC;QACJ,CAAC;QAED,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,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a Zod validation error handler file
|
|
3
|
+
* @param projectPath - Absolute path to the project root
|
|
4
|
+
* @returns Promise that resolves when the Zod validation error handler file is created
|
|
5
|
+
*/
|
|
6
|
+
export declare const create_HandleZodValidationError: (projectPath: string) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=create_HandleZodValidationError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_HandleZodValidationError.d.ts","sourceRoot":"","sources":["../../../../src/lib/src/errors/create_HandleZodValidationError.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,+BAA+B,GAC1C,aAAa,MAAM,KAClB,OAAO,CAAC,IAAI,CAiDd,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createFile } from "../../utils/helpers.js";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a Zod validation error handler file
|
|
6
|
+
* @param projectPath - Absolute path to the project root
|
|
7
|
+
* @returns Promise that resolves when the Zod validation error handler file is created
|
|
8
|
+
*/
|
|
9
|
+
export const create_HandleZodValidationError = async (projectPath) => {
|
|
10
|
+
try {
|
|
11
|
+
const handleZodValidationErrorTemplate = `import { ZodError, ZodIssue } from 'zod';
|
|
12
|
+
import { TErrorSource, TGenericErrorResponse } from '../interfaces/errors';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Handle Zod validation errors
|
|
16
|
+
* @param error - ZodError instance
|
|
17
|
+
* @returns Formatted error response
|
|
18
|
+
*/
|
|
19
|
+
const handleZodValidationError = (error: ZodError): TGenericErrorResponse => {
|
|
20
|
+
const errorSources: TErrorSource[] = error.issues.map((issue: ZodIssue) => {
|
|
21
|
+
// Remove the first element (usually 'body', 'query', or 'params') and join the rest
|
|
22
|
+
const pathSegments = issue.path.slice(1);
|
|
23
|
+
const fullPath = pathSegments.join('.');
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
path: fullPath,
|
|
27
|
+
message: issue.message
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
statusCode: 400,
|
|
33
|
+
message: 'Validation Error',
|
|
34
|
+
errorSources
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default handleZodValidationError;
|
|
39
|
+
`;
|
|
40
|
+
await createFile(path.join(projectPath, "src/app/errors", "handleZodValidationError.ts"), handleZodValidationErrorTemplate);
|
|
41
|
+
// Success message with green checkmark and text
|
|
42
|
+
console.log(chalk.green("✅ Zod validation error handler file created successfully"));
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
// Error message with red cross and text
|
|
46
|
+
console.error(chalk.red("❌ Error creating Zod validation error handler file:"), err);
|
|
47
|
+
throw err;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=create_HandleZodValidationError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_HandleZodValidationError.js","sourceRoot":"","sources":["../../../../src/lib/src/errors/create_HandleZodValidationError.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,+BAA+B,GAAG,KAAK,EAClD,WAAmB,EACJ,EAAE;IACjB,IAAI,CAAC;QACH,MAAM,gCAAgC,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4B5C,CAAC;QAEE,MAAM,UAAU,CACd,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,gBAAgB,EAAE,6BAA6B,CAAC,EACvE,gCAAgC,CACjC,CAAC;QAEF,gDAAgD;QAChD,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,KAAK,CAAC,0DAA0D,CAAC,CACxE,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,wCAAwC;QACxC,OAAO,CAAC,KAAK,CACX,KAAK,CAAC,GAAG,CAAC,qDAAqD,CAAC,EAChE,GAAG,CACJ,CAAC;QACF,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a TypeScript type definition file for email format
|
|
3
|
+
* @param projectPath - Absolute path to the project root
|
|
4
|
+
* @returns Promise that resolves when the email format type file is created
|
|
5
|
+
*/
|
|
6
|
+
export declare const create_EmailFormat_type: (projectPath: string) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=create_EmailFomat_type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_EmailFomat_type.d.ts","sourceRoot":"","sources":["../../../../src/lib/src/interfaces/create_EmailFomat_type.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,GAClC,aAAa,MAAM,KAClB,OAAO,CAAC,IAAI,CA4Bd,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { createFile } from "../../utils/helpers.js";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a TypeScript type definition file for email format
|
|
6
|
+
* @param projectPath - Absolute path to the project root
|
|
7
|
+
* @returns Promise that resolves when the email format type file is created
|
|
8
|
+
*/
|
|
9
|
+
export const create_EmailFormat_type = async (projectPath) => {
|
|
10
|
+
try {
|
|
11
|
+
const emailFormatTypeTemplate = `/**
|
|
12
|
+
* Email format type for nodemailer
|
|
13
|
+
* Defines the structure for email content
|
|
14
|
+
*/
|
|
15
|
+
export type TEmailFormat = {
|
|
16
|
+
/** HTML body content of the email */
|
|
17
|
+
emailBody: string;
|
|
18
|
+
/** Subject line of the email */
|
|
19
|
+
subject: string;
|
|
20
|
+
/** Optional plain text alternative body */
|
|
21
|
+
text?: string;
|
|
22
|
+
};
|
|
23
|
+
`;
|
|
24
|
+
await createFile(path.join(projectPath, "src/app/interfaces", "emailFormat.ts"), emailFormatTypeTemplate);
|
|
25
|
+
// Success message with green checkmark and text
|
|
26
|
+
console.log(chalk.green("✅ EmailFormat type file created successfully"));
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
// Error message with red cross and text
|
|
30
|
+
console.error(chalk.red("❌ Error creating EmailFormat type file:"), err);
|
|
31
|
+
throw err;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=create_EmailFomat_type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_EmailFomat_type.js","sourceRoot":"","sources":["../../../../src/lib/src/interfaces/create_EmailFomat_type.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;GAIG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,EAC1C,WAAmB,EACJ,EAAE;IACjB,IAAI,CAAC;QACH,MAAM,uBAAuB,GAAG;;;;;;;;;;;;CAYnC,CAAC;QAEE,MAAM,UAAU,CACd,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,oBAAoB,EAAE,gBAAgB,CAAC,EAC9D,uBAAuB,CACxB,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 TypeScript type definitions for error structures
|
|
3
|
+
* @param projectPath - Absolute path to the project root
|
|
4
|
+
* @returns Promise that resolves when the errors type file is created
|
|
5
|
+
*/
|
|
6
|
+
export declare const create_Errors_type: (projectPath: string) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=create_Errors_type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_Errors_type.d.ts","sourceRoot":"","sources":["../../../../src/lib/src/interfaces/create_Errors_type.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAC7B,aAAa,MAAM,KAClB,OAAO,CAAC,IAAI,CAqCd,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { createFile } from "../../utils/helpers.js";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
/**
|
|
5
|
+
* Creates TypeScript type definitions for error structures
|
|
6
|
+
* @param projectPath - Absolute path to the project root
|
|
7
|
+
* @returns Promise that resolves when the errors type file is created
|
|
8
|
+
*/
|
|
9
|
+
export const create_Errors_type = async (projectPath) => {
|
|
10
|
+
try {
|
|
11
|
+
const errorsTypeTemplate = `/**
|
|
12
|
+
* Individual error source structure
|
|
13
|
+
*/
|
|
14
|
+
export type TErrorSource = {
|
|
15
|
+
/** Field path or identifier where the error occurred */
|
|
16
|
+
path: string | number;
|
|
17
|
+
/** Error message describing the issue */
|
|
18
|
+
message: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Generic error response structure
|
|
23
|
+
*/
|
|
24
|
+
export type TGenericErrorResponse = {
|
|
25
|
+
/** HTTP status code */
|
|
26
|
+
statusCode: number;
|
|
27
|
+
/** Error message */
|
|
28
|
+
message: string;
|
|
29
|
+
/** Array of error sources with detailed information */
|
|
30
|
+
errorSources: TErrorSource[];
|
|
31
|
+
};
|
|
32
|
+
`;
|
|
33
|
+
await createFile(path.join(projectPath, "src/app/interfaces", "errors.ts"), errorsTypeTemplate);
|
|
34
|
+
// Success message with green checkmark and text
|
|
35
|
+
console.log(chalk.green("✅ Errors type file created successfully"));
|
|
36
|
+
}
|
|
37
|
+
catch (err) {
|
|
38
|
+
// Error message with red cross and text
|
|
39
|
+
console.error(chalk.red("❌ Error creating Errors type file:"), err);
|
|
40
|
+
throw err;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=create_Errors_type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_Errors_type.js","sourceRoot":"","sources":["../../../../src/lib/src/interfaces/create_Errors_type.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;GAIG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACrC,WAAmB,EACJ,EAAE;IACjB,IAAI,CAAC;QACH,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;CAqB9B,CAAC;QAEE,MAAM,UAAU,CACd,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,oBAAoB,EAAE,WAAW,CAAC,EACzD,kBAAkB,CACnB,CAAC;QAEF,gDAAgD;QAChD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC,CAAC;IACtE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,wCAAwC;QACxC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,oCAAoC,CAAC,EAAE,GAAG,CAAC,CAAC;QACpE,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TAnswers } from "../../utils/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a global type declaration file extending Express Request when authentication is enabled
|
|
4
|
+
* @param projectPath - Absolute path to the project root
|
|
5
|
+
* @param answers - User answers from CLI prompts
|
|
6
|
+
* @returns Promise that resolves when the index.d.ts file is created (if auth is enabled)
|
|
7
|
+
*/
|
|
8
|
+
export declare const create_IndexD_type: (projectPath: string, answers: TAnswers) => Promise<void>;
|
|
9
|
+
//# sourceMappingURL=create_Index_d_type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_Index_d_type.d.ts","sourceRoot":"","sources":["../../../../src/lib/src/interfaces/create_Index_d_type.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,GAC7B,aAAa,MAAM,EACnB,SAAS,QAAQ,KAChB,OAAO,CAAC,IAAI,CAsCd,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { createFile } from "../../utils/helpers.js";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a global type declaration file extending Express Request when authentication is enabled
|
|
6
|
+
* @param projectPath - Absolute path to the project root
|
|
7
|
+
* @param answers - User answers from CLI prompts
|
|
8
|
+
* @returns Promise that resolves when the index.d.ts file is created (if auth is enabled)
|
|
9
|
+
*/
|
|
10
|
+
export const create_IndexD_type = async (projectPath, answers) => {
|
|
11
|
+
try {
|
|
12
|
+
// Check if authentication is included
|
|
13
|
+
if (answers.includeAuth) {
|
|
14
|
+
const indexDTypeTemplate = `import { JwtPayload } from 'jsonwebtoken';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Global declaration extending Express Request interface
|
|
18
|
+
* Adds a 'user' property to the Request object when authentication is enabled
|
|
19
|
+
*/
|
|
20
|
+
declare global {
|
|
21
|
+
namespace Express {
|
|
22
|
+
interface Request {
|
|
23
|
+
/** JWT payload containing user information */
|
|
24
|
+
user?: JwtPayload;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Export the extended Request type for convenience
|
|
30
|
+
export type AuthenticatedRequest = Express.Request & {
|
|
31
|
+
user: JwtPayload;
|
|
32
|
+
};
|
|
33
|
+
`;
|
|
34
|
+
await createFile(path.join(projectPath, "src/app/interfaces", "index.d.ts"), indexDTypeTemplate);
|
|
35
|
+
// Success message with green checkmark and text
|
|
36
|
+
console.log(chalk.green("✅ Index.d.ts file created successfully."));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
// Error message with red cross and text
|
|
41
|
+
console.error(chalk.red("❌ Error creating Index.d type file:"), err);
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=create_Index_d_type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_Index_d_type.js","sourceRoot":"","sources":["../../../../src/lib/src/interfaces/create_Index_d_type.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACrC,WAAmB,EACnB,OAAiB,EACF,EAAE;IACjB,IAAI,CAAC;QACH,sCAAsC;QACtC,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;YACxB,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;CAmBhC,CAAC;YAEI,MAAM,UAAU,CACd,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,oBAAoB,EAAE,YAAY,CAAC,EAC1D,kBAAkB,CACnB,CAAC;YAEF,gDAAgD;YAChD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,yCAAyC,CAAC,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,wCAAwC;QACxC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,qCAAqC,CAAC,EAAE,GAAG,CAAC,CAAC;QACrE,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TAnswers } from "../../utils/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a JWT token interface file when authentication is enabled
|
|
4
|
+
* @param projectPath - Absolute path to the project root
|
|
5
|
+
* @param answers - User answers from CLI prompts
|
|
6
|
+
* @returns Promise that resolves when the JWT token interface file is created (if auth is enabled)
|
|
7
|
+
*/
|
|
8
|
+
export declare const create_JWT_Token_type: (projectPath: string, answers: TAnswers) => Promise<void>;
|
|
9
|
+
//# sourceMappingURL=create_JWT_Token_type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_JWT_Token_type.d.ts","sourceRoot":"","sources":["../../../../src/lib/src/interfaces/create_JWT_Token_type.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GAChC,aAAa,MAAM,EACnB,SAAS,QAAQ,KAChB,OAAO,CAAC,IAAI,CA+Bd,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { createFile } from "../../utils/helpers.js";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a JWT token interface file when authentication is enabled
|
|
6
|
+
* @param projectPath - Absolute path to the project root
|
|
7
|
+
* @param answers - User answers from CLI prompts
|
|
8
|
+
* @returns Promise that resolves when the JWT token interface file is created (if auth is enabled)
|
|
9
|
+
*/
|
|
10
|
+
export const create_JWT_Token_type = async (projectPath, answers) => {
|
|
11
|
+
try {
|
|
12
|
+
// Check if authentication is included
|
|
13
|
+
if (answers.includeAuth) {
|
|
14
|
+
const jwtTokenTemplate = `/**
|
|
15
|
+
* JWT Payload Interface
|
|
16
|
+
* Defines the structure of the JWT payload used in authentication
|
|
17
|
+
*/
|
|
18
|
+
export type TJwtPayload = {
|
|
19
|
+
id: string;
|
|
20
|
+
};
|
|
21
|
+
`;
|
|
22
|
+
await createFile(path.join(projectPath, "src/app/interfaces", "jwtToken_interface.ts"), jwtTokenTemplate);
|
|
23
|
+
// Success message with green checkmark and text
|
|
24
|
+
console.log(chalk.green("✅ JWT token interface file created successfully."));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
// Error message with red cross and text
|
|
29
|
+
console.error(chalk.red("❌ Error creating JWT token interface file:"), err);
|
|
30
|
+
throw err;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=create_JWT_Token_type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_JWT_Token_type.js","sourceRoot":"","sources":["../../../../src/lib/src/interfaces/create_JWT_Token_type.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,EACxC,WAAmB,EACnB,OAAiB,EACF,EAAE;IACjB,IAAI,CAAC;QACH,sCAAsC;QACtC,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;YACxB,MAAM,gBAAgB,GAAG;;;;;;;CAO9B,CAAC;YAEI,MAAM,UAAU,CACd,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,oBAAoB,EAAE,uBAAuB,CAAC,EACrE,gBAAgB,CACjB,CAAC;YAEF,gDAAgD;YAChD,OAAO,CAAC,GAAG,CACT,KAAK,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAChE,CAAC;QACJ,CAAC;IACH,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,wCAAwC;QACxC,OAAO,CAAC,KAAK,CACX,KAAK,CAAC,GAAG,CAAC,4CAA4C,CAAC,EACvD,GAAG,CACJ,CAAC;QACF,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a TypeScript type definition file for user roles
|
|
3
|
+
* @param projectPath - Absolute path to the project root
|
|
4
|
+
* @returns Promise that resolves when the user role type file is created
|
|
5
|
+
*/
|
|
6
|
+
export declare const create_UserRole_type: (projectPath: string) => Promise<void>;
|
|
7
|
+
//# sourceMappingURL=create_UserRole_type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_UserRole_type.d.ts","sourceRoot":"","sources":["../../../../src/lib/src/interfaces/create_UserRole_type.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,GAC/B,aAAa,MAAM,KAClB,OAAO,CAAC,IAAI,CA2Bd,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { createFile } from "../../utils/helpers.js";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
/**
|
|
5
|
+
* Creates a TypeScript type definition file for user roles
|
|
6
|
+
* @param projectPath - Absolute path to the project root
|
|
7
|
+
* @returns Promise that resolves when the user role type file is created
|
|
8
|
+
*/
|
|
9
|
+
export const create_UserRole_type = async (projectPath) => {
|
|
10
|
+
try {
|
|
11
|
+
const userRoletypeTemplate = `/**
|
|
12
|
+
* User Role Type Definitions
|
|
13
|
+
* Defines TypeScript types for user roles based on USER_ROLE constants
|
|
14
|
+
*/
|
|
15
|
+
import { USER_ROLE } from '../constants/userRole_constant';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Type representing all possible user roles
|
|
19
|
+
* This type is derived from the keys of the USER_ROLE object
|
|
20
|
+
*/
|
|
21
|
+
export type TUserRole = keyof typeof USER_ROLE;
|
|
22
|
+
`;
|
|
23
|
+
await createFile(path.join(projectPath, "src/app/interfaces", "userRole_type.ts"), userRoletypeTemplate);
|
|
24
|
+
// Success message with green checkmark and text
|
|
25
|
+
console.log(chalk.green("✅ Successfully created userRole_type file"));
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
// Error message with red cross and text
|
|
29
|
+
console.error(chalk.red("❌ Error creating userRole_type file:"), err);
|
|
30
|
+
throw err;
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=create_UserRole_type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_UserRole_type.js","sourceRoot":"","sources":["../../../../src/lib/src/interfaces/create_UserRole_type.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,EACvC,WAAmB,EACJ,EAAE;IACjB,IAAI,CAAC;QACH,MAAM,oBAAoB,GAAG;;;;;;;;;;;CAWhC,CAAC;QAEE,MAAM,UAAU,CACd,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,oBAAoB,EAAE,kBAAkB,CAAC,EAChE,oBAAoB,CACrB,CAAC;QAEF,gDAAgD;QAChD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC,CAAC;IACxE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,wCAAwC;QACxC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,sCAAsC,CAAC,EAAE,GAAG,CAAC,CAAC;QACtE,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TAnswers } from "../../utils/types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates an authentication middleware file when authentication is enabled
|
|
4
|
+
* @param projectPath - Absolute path to the project root
|
|
5
|
+
* @param answers - User answers from CLI prompts
|
|
6
|
+
* @returns Promise that resolves when the auth guard file is created (if auth is enabled)
|
|
7
|
+
*/
|
|
8
|
+
export declare const create_Auth_Guard: (projectPath: string, answers: TAnswers) => Promise<void>;
|
|
9
|
+
//# sourceMappingURL=create_Auth_Gurad.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create_Auth_Gurad.d.ts","sourceRoot":"","sources":["../../../../src/lib/src/middlewares/create_Auth_Gurad.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEhD;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAC5B,aAAa,MAAM,EACnB,SAAS,QAAQ,KAChB,OAAO,CAAC,IAAI,CA4Fd,CAAC"}
|