@nest-extended/cli 0.0.2-beta-14 → 0.0.2-beta-15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +73 -9
- package/package.json +1 -1
- package/src/commands/generate-app.js +145 -30
- package/src/commands/generate-app.js.map +1 -1
- package/src/commands/generate-service.js +204 -15
- package/src/commands/generate-service.js.map +1 -1
- package/src/lib/generate-prisma-auth-services.d.ts +1 -0
- package/src/lib/generate-prisma-auth-services.js +38 -0
- package/src/lib/generate-prisma-auth-services.js.map +1 -0
- package/src/templates/dto-class-validator.template.d.ts +1 -0
- package/src/templates/dto-class-validator.template.js +93 -0
- package/src/templates/dto-class-validator.template.js.map +1 -0
- package/src/templates/dto.template.js +19 -0
- package/src/templates/dto.template.js.map +1 -1
- package/src/templates/prisma-auth.template.d.ts +9 -0
- package/src/templates/prisma-auth.template.js +190 -0
- package/src/templates/prisma-auth.template.js.map +1 -0
- package/src/templates/prisma-controller.template.d.ts +1 -0
- package/src/templates/prisma-controller.template.js +53 -0
- package/src/templates/prisma-controller.template.js.map +1 -0
- package/src/templates/prisma-dto-class-validator.template.d.ts +1 -0
- package/src/templates/prisma-dto-class-validator.template.js +93 -0
- package/src/templates/prisma-dto-class-validator.template.js.map +1 -0
- package/src/templates/prisma-dto.template.d.ts +1 -0
- package/src/templates/prisma-dto.template.js +55 -0
- package/src/templates/prisma-dto.template.js.map +1 -0
- package/src/templates/prisma-model.template.d.ts +7 -0
- package/src/templates/prisma-model.template.js +27 -0
- package/src/templates/prisma-model.template.js.map +1 -0
- package/src/templates/prisma-module.template.d.ts +1 -0
- package/src/templates/prisma-module.template.js +18 -0
- package/src/templates/prisma-module.template.js.map +1 -0
- package/src/templates/prisma-service.template.d.ts +1 -0
- package/src/templates/prisma-service.template.js +15 -0
- package/src/templates/prisma-service.template.js.map +1 -0
- package/src/templates/prisma-setup.template.d.ts +6 -0
- package/src/templates/prisma-setup.template.js +34 -0
- package/src/templates/prisma-setup.template.js.map +1 -0
- package/src/templates/prisma-users.template.d.ts +8 -0
- package/src/templates/prisma-users.template.js +135 -0
- package/src/templates/prisma-users.template.js.map +1 -0
- package/src/templates/schema.template.js +8 -4
- package/src/templates/schema.template.js.map +1 -1
|
@@ -5,6 +5,7 @@ const tslib_1 = require("tslib");
|
|
|
5
5
|
const chalk = require("chalk");
|
|
6
6
|
const path = require("path");
|
|
7
7
|
const fs = require("fs-extra");
|
|
8
|
+
const inquirer = require("inquirer");
|
|
8
9
|
const child_process_1 = require("child_process");
|
|
9
10
|
const create_file_1 = require("../lib/create-file");
|
|
10
11
|
const update_app_module_1 = require("../lib/update-app-module");
|
|
@@ -12,9 +13,142 @@ const module_template_1 = require("../templates/module.template");
|
|
|
12
13
|
const service_template_1 = require("../templates/service.template");
|
|
13
14
|
const controller_template_1 = require("../templates/controller.template");
|
|
14
15
|
const dto_template_1 = require("../templates/dto.template");
|
|
16
|
+
const dto_class_validator_template_1 = require("../templates/dto-class-validator.template");
|
|
15
17
|
const schema_template_1 = require("../templates/schema.template");
|
|
16
18
|
const service_spec_template_1 = require("../templates/service.spec.template");
|
|
17
19
|
const controller_spec_template_1 = require("../templates/controller.spec.template");
|
|
20
|
+
const prisma_service_template_1 = require("../templates/prisma-service.template");
|
|
21
|
+
const prisma_module_template_1 = require("../templates/prisma-module.template");
|
|
22
|
+
const prisma_model_template_1 = require("../templates/prisma-model.template");
|
|
23
|
+
const prisma_controller_template_1 = require("../templates/prisma-controller.template");
|
|
24
|
+
const prisma_dto_template_1 = require("../templates/prisma-dto.template");
|
|
25
|
+
const prisma_dto_class_validator_template_1 = require("../templates/prisma-dto-class-validator.template");
|
|
26
|
+
const prisma_setup_template_1 = require("../templates/prisma-setup.template");
|
|
27
|
+
/**
|
|
28
|
+
* Detect the package manager used in the project.
|
|
29
|
+
*/
|
|
30
|
+
const detectPackageManager = (projectDir) => {
|
|
31
|
+
if (fs.existsSync(path.join(projectDir, 'yarn.lock')))
|
|
32
|
+
return 'yarn';
|
|
33
|
+
if (fs.existsSync(path.join(projectDir, 'pnpm-lock.yaml')))
|
|
34
|
+
return 'pnpm';
|
|
35
|
+
return 'npm';
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Check if a package is installed in node_modules.
|
|
39
|
+
*/
|
|
40
|
+
const isPackageInstalled = (projectDir, packageName) => {
|
|
41
|
+
return fs.existsSync(path.join(projectDir, 'node_modules', packageName));
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Install packages if they are not already installed.
|
|
45
|
+
*/
|
|
46
|
+
const ensurePackagesInstalled = (projectDir, packages) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
const missing = packages.filter(pkg => !isPackageInstalled(projectDir, pkg));
|
|
48
|
+
if (missing.length === 0)
|
|
49
|
+
return;
|
|
50
|
+
const pkgManager = detectPackageManager(projectDir);
|
|
51
|
+
const installArgs = pkgManager === 'npm' ? ['install'] : ['add'];
|
|
52
|
+
console.log(chalk.blue(`Installing missing packages: ${missing.join(', ')}...`));
|
|
53
|
+
yield new Promise((resolve, reject) => {
|
|
54
|
+
const child = (0, child_process_1.spawn)(pkgManager, [...installArgs, ...missing], {
|
|
55
|
+
stdio: 'inherit',
|
|
56
|
+
cwd: projectDir,
|
|
57
|
+
shell: true,
|
|
58
|
+
});
|
|
59
|
+
child.on('close', (code) => {
|
|
60
|
+
if (code === 0)
|
|
61
|
+
resolve();
|
|
62
|
+
else
|
|
63
|
+
reject(new Error(`${pkgManager} install failed with code ${code}`));
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
console.log(chalk.green('Packages installed successfully!'));
|
|
67
|
+
});
|
|
68
|
+
/**
|
|
69
|
+
* Install dev dependencies if not already installed.
|
|
70
|
+
*/
|
|
71
|
+
const ensureDevPackagesInstalled = (projectDir, packages) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
+
const missing = packages.filter(pkg => !isPackageInstalled(projectDir, pkg));
|
|
73
|
+
if (missing.length === 0)
|
|
74
|
+
return;
|
|
75
|
+
const pkgManager = detectPackageManager(projectDir);
|
|
76
|
+
const installArgs = pkgManager === 'npm' ? ['install', '-D'] : ['add', '-D'];
|
|
77
|
+
console.log(chalk.blue(`Installing missing dev packages: ${missing.join(', ')}...`));
|
|
78
|
+
yield new Promise((resolve, reject) => {
|
|
79
|
+
const child = (0, child_process_1.spawn)(pkgManager, [...installArgs, ...missing], {
|
|
80
|
+
stdio: 'inherit',
|
|
81
|
+
cwd: projectDir,
|
|
82
|
+
shell: true,
|
|
83
|
+
});
|
|
84
|
+
child.on('close', (code) => {
|
|
85
|
+
if (code === 0)
|
|
86
|
+
resolve();
|
|
87
|
+
else
|
|
88
|
+
reject(new Error(`${pkgManager} install failed with code ${code}`));
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
console.log(chalk.green('Dev packages installed successfully!'));
|
|
92
|
+
});
|
|
93
|
+
/**
|
|
94
|
+
* Ensure Prisma is initialized and PrismaModule/Service exist.
|
|
95
|
+
*/
|
|
96
|
+
const ensurePrismaSetup = (projectDir, dbType) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
+
const prismaSchemaPath = path.join(projectDir, 'prisma/schema.prisma');
|
|
98
|
+
// Initialize Prisma if schema.prisma doesn't exist
|
|
99
|
+
if (!fs.existsSync(prismaSchemaPath)) {
|
|
100
|
+
let datasourceProvider = 'postgresql';
|
|
101
|
+
if (dbType === 'MySQL')
|
|
102
|
+
datasourceProvider = 'mysql';
|
|
103
|
+
else if (dbType === 'SQLite')
|
|
104
|
+
datasourceProvider = 'sqlite';
|
|
105
|
+
console.log(chalk.blue(`Initializing Prisma with ${datasourceProvider}...`));
|
|
106
|
+
yield new Promise((resolve, reject) => {
|
|
107
|
+
const child = (0, child_process_1.spawn)('npx', ['prisma', 'init', '--datasource-provider', datasourceProvider], {
|
|
108
|
+
stdio: 'inherit',
|
|
109
|
+
cwd: projectDir,
|
|
110
|
+
shell: true,
|
|
111
|
+
});
|
|
112
|
+
child.on('close', (code) => {
|
|
113
|
+
if (code === 0)
|
|
114
|
+
resolve();
|
|
115
|
+
else
|
|
116
|
+
reject(new Error(`prisma init failed with code ${code}`));
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
// Create PrismaService and PrismaModule if they don't exist
|
|
121
|
+
const prismaServicePath = path.join(projectDir, 'src/prisma/prisma.service.ts');
|
|
122
|
+
const prismaModulePath = path.join(projectDir, 'src/prisma/prisma.module.ts');
|
|
123
|
+
if (!fs.existsSync(prismaServicePath)) {
|
|
124
|
+
fs.ensureDirSync(path.join(projectDir, 'src/prisma'));
|
|
125
|
+
fs.writeFileSync(prismaServicePath, (0, prisma_setup_template_1.getPrismaServiceFile)());
|
|
126
|
+
console.log(chalk.green('Created src/prisma/prisma.service.ts'));
|
|
127
|
+
}
|
|
128
|
+
if (!fs.existsSync(prismaModulePath)) {
|
|
129
|
+
fs.writeFileSync(prismaModulePath, (0, prisma_setup_template_1.getPrismaModuleFile)());
|
|
130
|
+
console.log(chalk.green('Created src/prisma/prisma.module.ts'));
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
/**
|
|
134
|
+
* Append a Prisma model to schema.prisma if it doesn't already exist.
|
|
135
|
+
*/
|
|
136
|
+
const appendPrismaModel = (projectDir, Name, isAuthGenerated) => {
|
|
137
|
+
const prismaSchemaPath = path.join(projectDir, 'prisma/schema.prisma');
|
|
138
|
+
if (!fs.existsSync(prismaSchemaPath)) {
|
|
139
|
+
console.warn(chalk.yellow('Warning: prisma/schema.prisma not found. Skipping model creation.'));
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const content = fs.readFileSync(prismaSchemaPath, 'utf8');
|
|
143
|
+
// Check if model already exists
|
|
144
|
+
if (content.includes(`model ${Name} {`)) {
|
|
145
|
+
console.log(chalk.yellow(`Model ${Name} already exists in schema.prisma`));
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const modelBlock = (0, prisma_model_template_1.getPrismaModel)(Name, isAuthGenerated);
|
|
149
|
+
fs.appendFileSync(prismaSchemaPath, '\n' + modelBlock);
|
|
150
|
+
console.log(chalk.green(`Added model ${Name} to prisma/schema.prisma`));
|
|
151
|
+
};
|
|
18
152
|
const generateServiceAction = (rawName) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
|
|
19
153
|
const parts = rawName.split('/');
|
|
20
154
|
const rawBasename = parts.pop() || '';
|
|
@@ -28,23 +162,78 @@ const generateServiceAction = (rawName) => tslib_1.__awaiter(void 0, void 0, voi
|
|
|
28
162
|
const name = Name[0].toLowerCase() + Name.slice(1); // camelCase
|
|
29
163
|
const fullPath = dirPath ? `${dirPath}/${name}` : name;
|
|
30
164
|
const targetDir = `src/services/${fullPath}`;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
165
|
+
// Ask user which database to use
|
|
166
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
167
|
+
// @ts-expect-error
|
|
168
|
+
const { databaseType } = yield inquirer.prompt([
|
|
169
|
+
{
|
|
170
|
+
type: 'list',
|
|
171
|
+
name: 'databaseType',
|
|
172
|
+
message: 'Which database would you like to use?',
|
|
173
|
+
choices: ['Mongoose', 'PostgreSQL', 'MySQL', 'SQLite'],
|
|
174
|
+
default: 'Mongoose',
|
|
175
|
+
},
|
|
176
|
+
]);
|
|
177
|
+
// Ask user which validator to use
|
|
178
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
179
|
+
// @ts-expect-error
|
|
180
|
+
const { validatorType } = yield inquirer.prompt([
|
|
181
|
+
{
|
|
182
|
+
type: 'list',
|
|
183
|
+
name: 'validatorType',
|
|
184
|
+
message: 'Which validation library would you like to use?',
|
|
185
|
+
choices: ['zod', 'class-validator'],
|
|
186
|
+
default: 'zod',
|
|
187
|
+
},
|
|
188
|
+
]);
|
|
189
|
+
const projectDir = process.cwd();
|
|
190
|
+
const isPrisma = databaseType !== 'Mongoose';
|
|
191
|
+
// Ensure required validator packages are installed
|
|
192
|
+
if (validatorType === 'zod') {
|
|
193
|
+
yield ensurePackagesInstalled(projectDir, ['zod']);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
yield ensurePackagesInstalled(projectDir, ['class-validator', 'class-transformer']);
|
|
197
|
+
}
|
|
198
|
+
// Ensure database-specific packages are installed
|
|
199
|
+
if (isPrisma) {
|
|
200
|
+
yield ensurePackagesInstalled(projectDir, ['@prisma/client', '@nest-extended/prisma']);
|
|
201
|
+
yield ensureDevPackagesInstalled(projectDir, ['prisma']);
|
|
202
|
+
yield ensurePrismaSetup(projectDir, databaseType);
|
|
203
|
+
}
|
|
204
|
+
console.log(`Generating service for: ${Name} (${fullPath}) using ${databaseType}`);
|
|
205
|
+
const isAuthGenerated = fs.existsSync(path.join(projectDir, 'src/services/auth'));
|
|
206
|
+
if (isPrisma) {
|
|
207
|
+
// --- Prisma-based generation ---
|
|
208
|
+
// Generate DTO
|
|
209
|
+
const dtoContent = validatorType === 'zod' ? (0, prisma_dto_template_1.getPrismaDto)(Name) : (0, prisma_dto_class_validator_template_1.getPrismaDtoClassValidator)(Name);
|
|
210
|
+
// Append model to schema.prisma
|
|
211
|
+
appendPrismaModel(projectDir, Name, isAuthGenerated);
|
|
212
|
+
// Generate service files
|
|
213
|
+
(0, create_file_1.createFileWithContent)(`${targetDir}/${name}.module.ts`, (0, prisma_module_template_1.getPrismaModule)(Name, name));
|
|
214
|
+
(0, create_file_1.createFileWithContent)(`${targetDir}/${name}.service.ts`, (0, prisma_service_template_1.getPrismaService)(Name, name));
|
|
215
|
+
(0, create_file_1.createFileWithContent)(`${targetDir}/${name}.controller.ts`, (0, prisma_controller_template_1.getPrismaController)(Name, name, rawName));
|
|
216
|
+
(0, create_file_1.createFileWithContent)(`${targetDir}/dto/${name}.dto.ts`, dtoContent);
|
|
217
|
+
(0, create_file_1.createFileWithContent)(`${targetDir}/${name}.service.spec.ts`, (0, service_spec_template_1.getServiceSpec)(Name, name));
|
|
218
|
+
(0, create_file_1.createFileWithContent)(`${targetDir}/${name}.controller.spec.ts`, (0, controller_spec_template_1.getControllerSpec)(Name, name));
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
// --- Mongoose-based generation (existing behavior) ---
|
|
222
|
+
// To compute depth for relative imports to src/schemas
|
|
223
|
+
const depth = dirPath ? dirPath.split('/').map(() => '../').join('') + '../../' : '../../';
|
|
224
|
+
// Generate the DTO based on validator selection
|
|
225
|
+
const dtoContent = validatorType === 'zod' ? (0, dto_template_1.getDto)(Name) : (0, dto_class_validator_template_1.getDtoClassValidator)(Name);
|
|
226
|
+
(0, create_file_1.createFileWithContent)(`src/schemas/${fullPath}.schema.ts`, (0, schema_template_1.getSchema)(Name, 'Users', isAuthGenerated, dirPath));
|
|
227
|
+
(0, create_file_1.createFileWithContent)(`${targetDir}/${name}.module.ts`, (0, module_template_1.getModule)(Name, name, fullPath, depth));
|
|
228
|
+
(0, create_file_1.createFileWithContent)(`${targetDir}/${name}.service.ts`, (0, service_template_1.getService)(Name, name, fullPath));
|
|
229
|
+
(0, create_file_1.createFileWithContent)(`${targetDir}/${name}.controller.ts`, (0, controller_template_1.getController)(Name, name, rawName, depth, fullPath));
|
|
230
|
+
(0, create_file_1.createFileWithContent)(`${targetDir}/dto/${name}.dto.ts`, dtoContent);
|
|
231
|
+
(0, create_file_1.createFileWithContent)(`${targetDir}/${name}.service.spec.ts`, (0, service_spec_template_1.getServiceSpec)(Name, name));
|
|
232
|
+
(0, create_file_1.createFileWithContent)(`${targetDir}/${name}.controller.spec.ts`, (0, controller_spec_template_1.getControllerSpec)(Name, name));
|
|
233
|
+
}
|
|
44
234
|
yield (0, update_app_module_1.updateAppModule)(Name, name, fullPath);
|
|
45
235
|
console.log(chalk.blue('Running lint...'));
|
|
46
|
-
const
|
|
47
|
-
const pkgManager = fs.existsSync(path.join(projectDir, 'yarn.lock')) ? 'yarn' : 'npm';
|
|
236
|
+
const pkgManager = detectPackageManager(projectDir);
|
|
48
237
|
yield new Promise((resolve) => {
|
|
49
238
|
const lintChild = (0, child_process_1.spawn)(pkgManager, ['run', 'lint'], {
|
|
50
239
|
stdio: 'inherit',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-service.js","sourceRoot":"","sources":["../../../../../packages/cli/src/commands/generate-service.ts"],"names":[],"mappings":";;;;AAAA,+BAA+B;AAC/B,6BAA6B;AAC7B,+BAA+B;AAC/B,iDAAsC;AACtC,oDAA2D;AAC3D,gEAA2D;AAC3D,kEAAyD;AACzD,oEAA2D;AAC3D,0EAAiE;AACjE,4DAAmD;AACnD,kEAAyD;AACzD,8EAAoE;AACpE,oFAA0E;
|
|
1
|
+
{"version":3,"file":"generate-service.js","sourceRoot":"","sources":["../../../../../packages/cli/src/commands/generate-service.ts"],"names":[],"mappings":";;;;AAAA,+BAA+B;AAC/B,6BAA6B;AAC7B,+BAA+B;AAC/B,qCAAqC;AACrC,iDAAsC;AACtC,oDAA2D;AAC3D,gEAA2D;AAC3D,kEAAyD;AACzD,oEAA2D;AAC3D,0EAAiE;AACjE,4DAAmD;AACnD,4FAAiF;AACjF,kEAAyD;AACzD,8EAAoE;AACpE,oFAA0E;AAC1E,kFAAwE;AACxE,gFAAsE;AACtE,8EAAoE;AACpE,wFAA8E;AAC9E,0EAAgE;AAChE,0GAA8F;AAC9F,8EAA+F;AAE/F;;GAEG;AACH,MAAM,oBAAoB,GAAG,CAAC,UAAkB,EAAU,EAAE;IACxD,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QAAE,OAAO,MAAM,CAAC;IACrE,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,E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ACjB,GAAG,SAAS,IAAI,IAAI,kBAAkB,EACtC,IAAA,sCAAc,EAAC,IAAI,EAAE,IAAI,CAAC,CAC7B,CAAC;QACF,IAAA,mCAAqB,EACjB,GAAG,SAAS,IAAI,IAAI,qBAAqB,EACzC,IAAA,4CAAiB,EAAC,IAAI,EAAE,IAAI,CAAC,CAChC,CAAC;IACN,CAAC;IAED,MAAM,IAAA,mCAAe,EAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IAE5C,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC3C,MAAM,UAAU,GAAG,oBAAoB,CAAC,UAAU,CAAC,CAAC;IACpD,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QAChC,MAAM,SAAS,GAAG,IAAA,qBAAK,EAAC,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE;YACjD,KAAK,EAAE,SAAS;YAChB,GAAG,EAAE,UAAU;YACf,KAAK,EAAE,IAAI;SACd,CAAC,CAAC;QACH,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACP,CAAC,CAAA,CAAC;AAvHW,QAAA,qBAAqB,yBAuHhC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const generatePrismaAuthServices: (appDir: string) => void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generatePrismaAuthServices = void 0;
|
|
4
|
+
const path = require("path");
|
|
5
|
+
const fs = require("fs-extra");
|
|
6
|
+
const prisma_auth_template_1 = require("../templates/prisma-auth.template");
|
|
7
|
+
const prisma_users_template_1 = require("../templates/prisma-users.template");
|
|
8
|
+
const prisma_dto_template_1 = require("../templates/prisma-dto.template");
|
|
9
|
+
const generatePrismaAuthServices = (appDir) => {
|
|
10
|
+
// 1. Generate Users Service
|
|
11
|
+
const usersDir = path.join(appDir, 'src/services/users');
|
|
12
|
+
fs.ensureDirSync(usersDir);
|
|
13
|
+
fs.writeFileSync(path.join(usersDir, 'users.module.ts'), (0, prisma_users_template_1.getPrismaUsersModule)());
|
|
14
|
+
fs.writeFileSync(path.join(usersDir, 'users.service.ts'), (0, prisma_users_template_1.getPrismaUsersService)());
|
|
15
|
+
fs.writeFileSync(path.join(usersDir, 'users.controller.ts'), (0, prisma_users_template_1.getPrismaUsersController)());
|
|
16
|
+
fs.ensureDirSync(path.join(usersDir, 'dto'));
|
|
17
|
+
fs.writeFileSync(path.join(usersDir, 'dto/users.dto.ts'), (0, prisma_dto_template_1.getPrismaDto)('Users'));
|
|
18
|
+
// 2. Append Users model to schema.prisma
|
|
19
|
+
const prismaSchemaPath = path.join(appDir, 'prisma/schema.prisma');
|
|
20
|
+
if (fs.existsSync(prismaSchemaPath)) {
|
|
21
|
+
const content = fs.readFileSync(prismaSchemaPath, 'utf8');
|
|
22
|
+
if (!content.includes('model Users {')) {
|
|
23
|
+
const usersModel = (0, prisma_users_template_1.getPrismaUsersModel)();
|
|
24
|
+
fs.appendFileSync(prismaSchemaPath, '\n' + usersModel);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// 3. Generate Auth Service
|
|
28
|
+
const authDir = path.join(appDir, 'src/services/auth');
|
|
29
|
+
fs.ensureDirSync(authDir);
|
|
30
|
+
fs.ensureDirSync(path.join(authDir, 'constants'));
|
|
31
|
+
fs.writeFileSync(path.join(authDir, 'auth.module.ts'), (0, prisma_auth_template_1.getPrismaAuthModule)());
|
|
32
|
+
fs.writeFileSync(path.join(authDir, 'auth.service.ts'), (0, prisma_auth_template_1.getPrismaAuthService)());
|
|
33
|
+
fs.writeFileSync(path.join(authDir, 'auth.controller.ts'), (0, prisma_auth_template_1.getPrismaAuthController)());
|
|
34
|
+
fs.writeFileSync(path.join(authDir, 'auth.guard.ts'), (0, prisma_auth_template_1.getPrismaAuthGuard)());
|
|
35
|
+
fs.writeFileSync(path.join(authDir, 'constants/jwt-constants.ts'), (0, prisma_auth_template_1.getPrismaJwtConstants)());
|
|
36
|
+
};
|
|
37
|
+
exports.generatePrismaAuthServices = generatePrismaAuthServices;
|
|
38
|
+
//# sourceMappingURL=generate-prisma-auth-services.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate-prisma-auth-services.js","sourceRoot":"","sources":["../../../../../packages/cli/src/lib/generate-prisma-auth-services.ts"],"names":[],"mappings":";;;AAAA,6BAA6B;AAC7B,+BAA+B;AAC/B,4EAM2C;AAC3C,8EAK4C;AAC5C,0EAAgE;AAEzD,MAAM,0BAA0B,GAAG,CAAC,MAAc,EAAE,EAAE;IACzD,4BAA4B;IAC5B,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;IACzD,EAAE,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAE3B,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,iBAAiB,CAAC,EAAE,IAAA,4CAAoB,GAAE,CAAC,CAAC;IACjF,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,kBAAkB,CAAC,EAAE,IAAA,6CAAqB,GAAE,CAAC,CAAC;IACnF,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,qBAAqB,CAAC,EAAE,IAAA,gDAAwB,GAAE,CAAC,CAAC;IACzF,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;IAC7C,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,kBAAkB,CAAC,EAAE,IAAA,kCAAY,EAAC,OAAO,CAAC,CAAC,CA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O,EAAE,4BAA4B,CAAC,EAAE,IAAA,4CAAqB,GAAE,CAAC,CAAC;AAChG,CAAC,CAAC;AA/BW,QAAA,0BAA0B,8BA+BrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getDtoClassValidator: (Name: string) => string;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDtoClassValidator = void 0;
|
|
4
|
+
const getDtoClassValidator = (Name) => `import { IsString, IsOptional, IsBoolean, IsDate, IsMongoId } from 'class-validator';
|
|
5
|
+
import { Type } from 'class-transformer';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Usage: To enable class-validator validation, add the following to your main.ts:
|
|
9
|
+
*
|
|
10
|
+
* import { ValidationPipe } from '@nestjs/common';
|
|
11
|
+
* app.useGlobalPipes(new ValidationPipe({ transform: true, whitelist: true }));
|
|
12
|
+
*
|
|
13
|
+
* Or apply per-route using @UsePipes(new ValidationPipe({ transform: true }))
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export class Create${Name}Dto {
|
|
17
|
+
@IsString()
|
|
18
|
+
@IsOptional()
|
|
19
|
+
name?: string;
|
|
20
|
+
|
|
21
|
+
@IsMongoId()
|
|
22
|
+
@IsOptional()
|
|
23
|
+
createdBy?: string;
|
|
24
|
+
|
|
25
|
+
@IsDate()
|
|
26
|
+
@IsOptional()
|
|
27
|
+
@Type(() => Date)
|
|
28
|
+
createdAt?: Date;
|
|
29
|
+
|
|
30
|
+
@IsDate()
|
|
31
|
+
@IsOptional()
|
|
32
|
+
@Type(() => Date)
|
|
33
|
+
updatedAt?: Date;
|
|
34
|
+
|
|
35
|
+
@IsBoolean()
|
|
36
|
+
@IsOptional()
|
|
37
|
+
deleted?: boolean;
|
|
38
|
+
|
|
39
|
+
@IsMongoId()
|
|
40
|
+
@IsOptional()
|
|
41
|
+
deletedBy?: string;
|
|
42
|
+
|
|
43
|
+
@IsDate()
|
|
44
|
+
@IsOptional()
|
|
45
|
+
@Type(() => Date)
|
|
46
|
+
deletedAt?: Date;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export class Patch${Name}Dto {
|
|
50
|
+
@IsString()
|
|
51
|
+
@IsOptional()
|
|
52
|
+
name?: string;
|
|
53
|
+
|
|
54
|
+
@IsDate()
|
|
55
|
+
@IsOptional()
|
|
56
|
+
@Type(() => Date)
|
|
57
|
+
updatedAt?: Date;
|
|
58
|
+
|
|
59
|
+
@IsDate()
|
|
60
|
+
@IsOptional()
|
|
61
|
+
@Type(() => Date)
|
|
62
|
+
createdAt?: Date;
|
|
63
|
+
|
|
64
|
+
@IsBoolean()
|
|
65
|
+
@IsOptional()
|
|
66
|
+
deleted?: boolean;
|
|
67
|
+
|
|
68
|
+
@IsMongoId()
|
|
69
|
+
@IsOptional()
|
|
70
|
+
deletedBy?: string;
|
|
71
|
+
|
|
72
|
+
@IsDate()
|
|
73
|
+
@IsOptional()
|
|
74
|
+
@Type(() => Date)
|
|
75
|
+
deletedAt?: Date;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export class Remove${Name}Dto {
|
|
79
|
+
@IsMongoId()
|
|
80
|
+
id: string;
|
|
81
|
+
|
|
82
|
+
@IsMongoId()
|
|
83
|
+
@IsOptional()
|
|
84
|
+
deletedBy?: string;
|
|
85
|
+
|
|
86
|
+
@IsDate()
|
|
87
|
+
@IsOptional()
|
|
88
|
+
@Type(() => Date)
|
|
89
|
+
deletedAt?: Date;
|
|
90
|
+
}
|
|
91
|
+
`;
|
|
92
|
+
exports.getDtoClassValidator = getDtoClassValidator;
|
|
93
|
+
//# sourceMappingURL=dto-class-validator.template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dto-class-validator.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/dto-class-validator.template.ts"],"names":[],"mappings":";;;AACO,MAAM,oBAAoB,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC;;;;;;;;;;;;qBAYzC,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;oBAiCL,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA6BH,IAAI;;;;;;;;;;;;;CAaxB,CAAC;AAvFW,QAAA,oBAAoB,wBAuF/B"}
|
|
@@ -4,6 +4,25 @@ exports.getDto = void 0;
|
|
|
4
4
|
const getDto = (Name) => `import { z } from 'zod';
|
|
5
5
|
import { Types } from 'mongoose';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Usage: To enable Zod validation, create a ZodValidationPipe and apply it globally or per-route.
|
|
9
|
+
*
|
|
10
|
+
* // zod-validation.pipe.ts
|
|
11
|
+
* import { PipeTransform, BadRequestException } from '@nestjs/common';
|
|
12
|
+
* import { ZodSchema } from 'zod';
|
|
13
|
+
* export class ZodValidationPipe implements PipeTransform {
|
|
14
|
+
* constructor(private schema: ZodSchema) {}
|
|
15
|
+
* transform(value: unknown) {
|
|
16
|
+
* const result = this.schema.safeParse(value);
|
|
17
|
+
* if (!result.success) throw new BadRequestException(result.error);
|
|
18
|
+
* return result.data;
|
|
19
|
+
* }
|
|
20
|
+
* }
|
|
21
|
+
*
|
|
22
|
+
* // Then in your controller:
|
|
23
|
+
* @UsePipes(new ZodValidationPipe(Create${Name}Validation))
|
|
24
|
+
*/
|
|
25
|
+
|
|
7
26
|
export const Create${Name}Validation = z.object({
|
|
8
27
|
name: z.string().optional(),
|
|
9
28
|
createdBy: z
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dto.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/dto.template.ts"],"names":[],"mappings":";;;AACO,MAAM,MAAM,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC;;;
|
|
1
|
+
{"version":3,"file":"dto.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/dto.template.ts"],"names":[],"mappings":";;;AACO,MAAM,MAAM,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC;;;;;;;;;;;;;;;;;;;6CAmBH,IAAI;;;qBAG5B,IAAI;;;;;;;;;;;;;;;;;;;;oBAoBL,IAAI;;;;;;;;;;;;;;qBAcH,IAAI;;;;;;;;;;;;;oBAaL,IAAI,8BAA8B,IAAI;mBACvC,IAAI,6BAA6B,IAAI;oBACpC,IAAI,8BAA8B,IAAI;CACzD,CAAC;AAxEW,QAAA,MAAM,UAwEjB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prisma-compatible auth templates.
|
|
3
|
+
* Same functionality as the Mongoose auth templates but using Prisma.
|
|
4
|
+
*/
|
|
5
|
+
export declare const getPrismaAuthController: () => string;
|
|
6
|
+
export declare const getPrismaAuthService: () => string;
|
|
7
|
+
export declare const getPrismaAuthModule: () => string;
|
|
8
|
+
export declare const getPrismaAuthGuard: () => string;
|
|
9
|
+
export declare const getPrismaJwtConstants: () => string;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Prisma-compatible auth templates.
|
|
4
|
+
* Same functionality as the Mongoose auth templates but using Prisma.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getPrismaJwtConstants = exports.getPrismaAuthGuard = exports.getPrismaAuthModule = exports.getPrismaAuthService = exports.getPrismaAuthController = void 0;
|
|
8
|
+
const getPrismaAuthController = () => `import {
|
|
9
|
+
Body,
|
|
10
|
+
Controller,
|
|
11
|
+
Post,
|
|
12
|
+
HttpCode,
|
|
13
|
+
HttpStatus,
|
|
14
|
+
Get,
|
|
15
|
+
Request,
|
|
16
|
+
BadRequestException,
|
|
17
|
+
} from '@nestjs/common';
|
|
18
|
+
import { AuthService } from './auth.service';
|
|
19
|
+
import { Public } from '@nest-extended/decorators';
|
|
20
|
+
import { UsersService } from '../users/users.service';
|
|
21
|
+
|
|
22
|
+
@Controller('authentication')
|
|
23
|
+
export class AuthController {
|
|
24
|
+
constructor(
|
|
25
|
+
private authService: AuthService,
|
|
26
|
+
private usersService: UsersService,
|
|
27
|
+
) {}
|
|
28
|
+
|
|
29
|
+
@Public()
|
|
30
|
+
@HttpCode(HttpStatus.OK)
|
|
31
|
+
@Post('')
|
|
32
|
+
signIn(@Body() signInDto: Record<string, string>) {
|
|
33
|
+
if (signInDto.strategy === 'local') {
|
|
34
|
+
return this.authService.signInLocal(signInDto.email, signInDto.password);
|
|
35
|
+
}
|
|
36
|
+
throw new BadRequestException('Invalid Strategy');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Get('verify')
|
|
40
|
+
getProfile(@Request() req: Record<string, any>) {
|
|
41
|
+
const user = req.user as Record<string, any>;
|
|
42
|
+
return {
|
|
43
|
+
user: this.usersService.sanitizeUser(user),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
exports.getPrismaAuthController = getPrismaAuthController;
|
|
49
|
+
const getPrismaAuthService = () => `import { Injectable, UnauthorizedException } from '@nestjs/common';
|
|
50
|
+
import { JwtService } from '@nestjs/jwt';
|
|
51
|
+
import * as bcrypt from 'bcrypt';
|
|
52
|
+
import { UsersService } from '../users/users.service';
|
|
53
|
+
|
|
54
|
+
@Injectable()
|
|
55
|
+
export class AuthService {
|
|
56
|
+
constructor(
|
|
57
|
+
private usersService: UsersService,
|
|
58
|
+
private jwtService: JwtService,
|
|
59
|
+
) { }
|
|
60
|
+
|
|
61
|
+
async signInLocal(
|
|
62
|
+
email: string,
|
|
63
|
+
pass: string,
|
|
64
|
+
): Promise<Record<string, unknown>> {
|
|
65
|
+
const users = await this.usersService._find(
|
|
66
|
+
{
|
|
67
|
+
email,
|
|
68
|
+
$limit: 1,
|
|
69
|
+
$select: ['id', 'firstName', 'lastName', 'email', 'password', 'createdAt', 'updatedAt'],
|
|
70
|
+
},
|
|
71
|
+
{ pagination: false },
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const user = users[0] as Record<string, any>;
|
|
75
|
+
if (!user) throw new UnauthorizedException();
|
|
76
|
+
|
|
77
|
+
const passwordValid = await bcrypt.compare(pass, user.password);
|
|
78
|
+
if (!passwordValid) {
|
|
79
|
+
throw new UnauthorizedException();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const sanitizedUser = this.usersService.sanitizeUser(user);
|
|
83
|
+
const payload = { sub: { id: user.id }, user };
|
|
84
|
+
return {
|
|
85
|
+
accessToken: await this.jwtService.signAsync(payload),
|
|
86
|
+
user: sanitizedUser,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
`;
|
|
91
|
+
exports.getPrismaAuthService = getPrismaAuthService;
|
|
92
|
+
const getPrismaAuthModule = () => `import { Module } from '@nestjs/common';
|
|
93
|
+
import { AuthService } from './auth.service';
|
|
94
|
+
import { JwtModule } from '@nestjs/jwt';
|
|
95
|
+
import { AuthController } from './auth.controller';
|
|
96
|
+
import { APP_GUARD } from '@nestjs/core';
|
|
97
|
+
import { AuthGuard } from './auth.guard';
|
|
98
|
+
import { UsersModule } from '../users/users.module';
|
|
99
|
+
import { jwtConstants } from './constants/jwt-constants';
|
|
100
|
+
|
|
101
|
+
@Module({
|
|
102
|
+
imports: [
|
|
103
|
+
UsersModule,
|
|
104
|
+
JwtModule.register({
|
|
105
|
+
global: true,
|
|
106
|
+
secret: jwtConstants.secret,
|
|
107
|
+
signOptions: { expiresIn: '365d' },
|
|
108
|
+
}),
|
|
109
|
+
],
|
|
110
|
+
providers: [
|
|
111
|
+
AuthService,
|
|
112
|
+
{
|
|
113
|
+
provide: APP_GUARD,
|
|
114
|
+
useClass: AuthGuard,
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
controllers: [AuthController],
|
|
118
|
+
exports: [AuthService],
|
|
119
|
+
})
|
|
120
|
+
export class AuthModule {}
|
|
121
|
+
`;
|
|
122
|
+
exports.getPrismaAuthModule = getPrismaAuthModule;
|
|
123
|
+
const getPrismaAuthGuard = () => `import {
|
|
124
|
+
CanActivate,
|
|
125
|
+
ExecutionContext,
|
|
126
|
+
Injectable,
|
|
127
|
+
UnauthorizedException,
|
|
128
|
+
} from '@nestjs/common';
|
|
129
|
+
import { Reflector } from '@nestjs/core';
|
|
130
|
+
import { JwtService } from '@nestjs/jwt';
|
|
131
|
+
import { IS_PUBLIC_KEY } from '@nest-extended/decorators';
|
|
132
|
+
import { UsersService } from '../users/users.service';
|
|
133
|
+
import { jwtConstants } from './constants/jwt-constants';
|
|
134
|
+
import { ClsService } from 'nestjs-cls';
|
|
135
|
+
|
|
136
|
+
@Injectable()
|
|
137
|
+
export class AuthGuard implements CanActivate {
|
|
138
|
+
constructor(
|
|
139
|
+
private usersService: UsersService,
|
|
140
|
+
private jwtService: JwtService,
|
|
141
|
+
private reflector: Reflector,
|
|
142
|
+
private cls: ClsService,
|
|
143
|
+
) {}
|
|
144
|
+
|
|
145
|
+
async canActivate(context: ExecutionContext): Promise<boolean> {
|
|
146
|
+
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
|
|
147
|
+
context.getHandler(),
|
|
148
|
+
context.getClass(),
|
|
149
|
+
]);
|
|
150
|
+
if (isPublic) {
|
|
151
|
+
return true;
|
|
152
|
+
}
|
|
153
|
+
const request = context.switchToHttp().getRequest<{ user?: Record<string, unknown>, headers: Record<string, string | undefined> }>();
|
|
154
|
+
const token = this.extractTokenFromHeader(request);
|
|
155
|
+
if (!token) {
|
|
156
|
+
throw new UnauthorizedException();
|
|
157
|
+
}
|
|
158
|
+
try {
|
|
159
|
+
const payload = await this.jwtService.verifyAsync<{ sub: { id: string } }>(token, {
|
|
160
|
+
secret: jwtConstants.secret,
|
|
161
|
+
});
|
|
162
|
+
const user = (await this.usersService._get(
|
|
163
|
+
payload.sub.id,
|
|
164
|
+
)) as unknown as Record<string, unknown>;
|
|
165
|
+
if (user) {
|
|
166
|
+
request.user = user;
|
|
167
|
+
this.cls.set('user', user);
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
} catch {
|
|
171
|
+
throw new UnauthorizedException();
|
|
172
|
+
}
|
|
173
|
+
throw new UnauthorizedException();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
private extractTokenFromHeader(request: { headers: Record<string, string | undefined> }): string | undefined {
|
|
177
|
+
const [type, token] = request.headers.authorization?.split(' ') ?? [];
|
|
178
|
+
return type === 'Bearer' ? token : undefined;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
`;
|
|
182
|
+
exports.getPrismaAuthGuard = getPrismaAuthGuard;
|
|
183
|
+
const getPrismaJwtConstants = () => `import { randomBytes } from 'crypto';
|
|
184
|
+
// NOTE: For a real application, consider using a more secure way to inject the secret (like ConfigService)
|
|
185
|
+
export const jwtConstants = {
|
|
186
|
+
secret: process.env.JWT_SECRET || randomBytes(32).toString('hex'),
|
|
187
|
+
};
|
|
188
|
+
`;
|
|
189
|
+
exports.getPrismaJwtConstants = getPrismaJwtConstants;
|
|
190
|
+
//# sourceMappingURL=prisma-auth.template.js.map
|