@azure-net/cli 4.0.0-0 → 4.1.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.
Files changed (45) hide show
  1. package/bin/azure-net.js +73 -34
  2. package/bin/azure-net.ts +81 -34
  3. package/eslint.config.js +15 -0
  4. package/package.json +1 -1
  5. package/src/checks/checkDomain.js +201 -0
  6. package/src/checks/checkDomain.ts +223 -0
  7. package/src/checks/checkFoldersStructure.js +70 -0
  8. package/src/checks/checkFoldersStructure.ts +85 -0
  9. package/src/checks/checkImports.ts +166 -0
  10. package/src/checks/checkInternal.js +37 -0
  11. package/src/checks/checkInternal.ts +44 -0
  12. package/src/checks/checkLayerBoundaries.js +178 -0
  13. package/src/checks/checkLayerBoundaries.ts +216 -0
  14. package/src/checks/checkPresenterNames.js +202 -0
  15. package/src/checks/checkPresenterNames.ts +208 -0
  16. package/src/checks/checkProject.js +42 -0
  17. package/src/checks/checkProject.ts +45 -0
  18. package/src/checks/checkProviderGraph.js +221 -0
  19. package/src/checks/checkProviderGraph.ts +234 -0
  20. package/src/checks/checkProviderNames.js +158 -0
  21. package/src/checks/checkProviderNames.ts +165 -0
  22. package/src/checks/index.js +8 -0
  23. package/src/checks/index.ts +9 -0
  24. package/src/generate/layers/generateRepository.ts +123 -0
  25. package/src/generate/layers/generateRepositoryMethod.ts +102 -0
  26. package/src/generate/layers/generateUseCases.ts +50 -0
  27. package/src/generate/layers/repositoryShared.ts +657 -0
  28. package/src/generate/module/generateModulePreset.js +307 -0
  29. package/src/generate/module/generateModulePreset.ts +337 -0
  30. package/src/generate/module/generateSchemaFromType.js +46 -8
  31. package/src/generate/module/generateSchemaFromType.ts +52 -8
  32. package/src/generate/module/repositoryModuleShared.ts +665 -0
  33. package/src/utils/contextUtils.ts +89 -0
  34. package/src/utils/fileUtils.ts +100 -0
  35. package/src/utils/loadConfig.ts +69 -0
  36. package/src/commands/generate/generateCrudBase.js +0 -188
  37. package/src/commands/generate/generateCrudPresenter.js +0 -225
  38. package/src/commands/generate/generateModule.js +0 -31
  39. package/src/commands/generate/generateModuleBase.js +0 -130
  40. package/src/commands/generate/generateModulePresenter.js +0 -103
  41. package/src/commands/generate/generatePresenter.js +0 -80
  42. package/src/commands/generate/generateRepository.js +0 -70
  43. package/src/commands/generate/generateSchema.js +0 -100
  44. package/src/commands/generate/generateService.js +0 -66
  45. package/src/commands/generate/index.js +0 -9
@@ -186,9 +186,9 @@ const findInterfaceBodyByScan = async (rootDir, interfaceName) => {
186
186
  return null;
187
187
  };
188
188
 
189
- const extractKeys = (body) => {
189
+ const extractRuleKeys = (body) => {
190
190
  const keys = [];
191
- const keyRegex = /^\s*([A-Za-z_$][A-Za-z0-9_$]*)\??\s*:/gm;
191
+ const keyRegex = /^\s*([A-Za-z_$][A-Za-z0-9_$]*)\s*:/gm;
192
192
  let match;
193
193
  while ((match = keyRegex.exec(body)) !== null) {
194
194
  keys.push(match[1]);
@@ -196,14 +196,52 @@ const extractKeys = (body) => {
196
196
  return Array.from(new Set(keys));
197
197
  };
198
198
 
199
- const updateRulesObject = (schemaContent, keys) => {
199
+ const extractInterfaceFields = (body) => {
200
+ const fields = [];
201
+ const fieldRegex = /^\s*(?:readonly\s+)?([A-Za-z_$][A-Za-z0-9_$]*)(\?)?\s*:\s*([^;]+);/gm;
202
+ let match;
203
+ while ((match = fieldRegex.exec(body)) !== null) {
204
+ const name = match[1];
205
+ const optionalMark = match[2];
206
+ const type = String(match[3] ?? '').trim();
207
+ if (!name || !type) continue;
208
+ fields.push({
209
+ name,
210
+ optional: optionalMark === '?',
211
+ type
212
+ });
213
+ }
214
+
215
+ const unique = new Map();
216
+ for (const field of fields) {
217
+ if (!unique.has(field.name)) unique.set(field.name, field);
218
+ }
219
+ return Array.from(unique.values());
220
+ };
221
+
222
+ const buildRulesArray = (field) => {
223
+ const ruleCalls = [];
224
+ if (!field.optional) {
225
+ ruleCalls.push('rules.required()');
226
+ }
227
+
228
+ if (field.type === 'string') {
229
+ ruleCalls.push('rules.string()');
230
+ } else if (field.type === 'number') {
231
+ ruleCalls.push('rules.number()');
232
+ }
233
+
234
+ return `[${ruleCalls.join(', ')}]`;
235
+ };
236
+
237
+ const updateRulesObject = (schemaContent, fields) => {
200
238
  const rulesRegex = /\.rules\(\(rules\)\s*=>\s*\(\{([\s\S]*?)\}\)\)/m;
201
239
  const match = schemaContent.match(rulesRegex);
202
240
  if (!match) return null;
203
241
 
204
242
  const currentBody = match[1] ?? '';
205
- const existingKeys = new Set(extractKeys(currentBody));
206
- const newLines = keys.filter((key) => !existingKeys.has(key)).map((key) => `\t\t${key}: [],`);
243
+ const existingKeys = new Set(extractRuleKeys(currentBody));
244
+ const newLines = fields.filter((field) => !existingKeys.has(field.name)).map((field) => `\t\t${field.name}: ${buildRulesArray(field)},`);
207
245
 
208
246
  if (!newLines.length) return schemaContent;
209
247
 
@@ -297,13 +335,13 @@ export default async function generateSchemaFromType() {
297
335
  return;
298
336
  }
299
337
 
300
- const interfaceKeys = extractKeys(interfaceBody);
301
- if (!interfaceKeys.length) {
338
+ const interfaceFields = extractInterfaceFields(interfaceBody);
339
+ if (!interfaceFields.length) {
302
340
  console.log('ℹ️ Interface has no explicit keys to transfer into rules.');
303
341
  return;
304
342
  }
305
343
 
306
- const updatedSchemaContent = updateRulesObject(schemaContent, interfaceKeys);
344
+ const updatedSchemaContent = updateRulesObject(schemaContent, interfaceFields);
307
345
  if (!updatedSchemaContent) {
308
346
  console.error('❌ Could not locate `.rules((rules) => ({}))` block in schema file.');
309
347
  process.exitCode = 1;
@@ -190,9 +190,15 @@ const findInterfaceBodyByScan = async (rootDir: string, interfaceName: string):
190
190
  return null;
191
191
  };
192
192
 
193
- const extractKeys = (body: string): string[] => {
193
+ type InterfaceField = {
194
+ name: string;
195
+ optional: boolean;
196
+ type: string;
197
+ };
198
+
199
+ const extractRuleKeys = (body: string): string[] => {
194
200
  const keys: string[] = [];
195
- const keyRegex = /^\s*([A-Za-z_$][A-Za-z0-9_$]*)\??\s*:/gm;
201
+ const keyRegex = /^\s*([A-Za-z_$][A-Za-z0-9_$]*)\s*:/gm;
196
202
  let match: RegExpExecArray | null;
197
203
  while ((match = keyRegex.exec(body)) !== null) {
198
204
  const key = match[1];
@@ -201,14 +207,52 @@ const extractKeys = (body: string): string[] => {
201
207
  return Array.from(new Set(keys));
202
208
  };
203
209
 
204
- const updateRulesObject = (schemaContent: string, keys: string[]): string | null => {
210
+ const extractInterfaceFields = (body: string): InterfaceField[] => {
211
+ const fields: InterfaceField[] = [];
212
+ const fieldRegex = /^\s*(?:readonly\s+)?([A-Za-z_$][A-Za-z0-9_$]*)(\?)?\s*:\s*([^;]+);/gm;
213
+ let match: RegExpExecArray | null;
214
+ while ((match = fieldRegex.exec(body)) !== null) {
215
+ const name = match[1];
216
+ const optionalMark = match[2];
217
+ const type = String(match[3] ?? '').trim();
218
+ if (!name || !type) continue;
219
+ fields.push({
220
+ name,
221
+ optional: optionalMark === '?',
222
+ type
223
+ });
224
+ }
225
+
226
+ const unique = new Map<string, InterfaceField>();
227
+ for (const field of fields) {
228
+ if (!unique.has(field.name)) unique.set(field.name, field);
229
+ }
230
+ return Array.from(unique.values());
231
+ };
232
+
233
+ const buildRulesArray = (field: InterfaceField): string => {
234
+ const ruleCalls: string[] = [];
235
+ if (!field.optional) {
236
+ ruleCalls.push('rules.required()');
237
+ }
238
+
239
+ if (field.type === 'string') {
240
+ ruleCalls.push('rules.string()');
241
+ } else if (field.type === 'number') {
242
+ ruleCalls.push('rules.number()');
243
+ }
244
+
245
+ return `[${ruleCalls.join(', ')}]`;
246
+ };
247
+
248
+ const updateRulesObject = (schemaContent: string, fields: InterfaceField[]): string | null => {
205
249
  const rulesRegex = /\.rules\(\(rules\)\s*=>\s*\(\{([\s\S]*?)\}\)\)/m;
206
250
  const match = schemaContent.match(rulesRegex);
207
251
  if (!match) return null;
208
252
 
209
253
  const currentBody = match[1] ?? '';
210
- const existingKeys = new Set(extractKeys(currentBody));
211
- const newLines = keys.filter((key) => !existingKeys.has(key)).map((key) => `\t\t${key}: [],`);
254
+ const existingKeys = new Set(extractRuleKeys(currentBody));
255
+ const newLines = fields.filter((field) => !existingKeys.has(field.name)).map((field) => `\t\t${field.name}: ${buildRulesArray(field)},`);
212
256
 
213
257
  if (!newLines.length) return schemaContent;
214
258
 
@@ -302,13 +346,13 @@ export default async function generateSchemaFromType(): Promise<void> {
302
346
  return;
303
347
  }
304
348
 
305
- const interfaceKeys = extractKeys(interfaceBody);
306
- if (!interfaceKeys.length) {
349
+ const interfaceFields = extractInterfaceFields(interfaceBody);
350
+ if (!interfaceFields.length) {
307
351
  console.log('ℹ️ Interface has no explicit keys to transfer into rules.');
308
352
  return;
309
353
  }
310
354
 
311
- const updatedSchemaContent = updateRulesObject(schemaContent, interfaceKeys);
355
+ const updatedSchemaContent = updateRulesObject(schemaContent, interfaceFields);
312
356
  if (!updatedSchemaContent) {
313
357
  console.error('❌ Could not locate `.rules((rules) => ({}))` block in schema file.');
314
358
  process.exitCode = 1;