@alevnyacow/nzmt 0.19.0 → 0.20.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 (2) hide show
  1. package/bin/cli.js +39 -2
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -403,6 +403,40 @@ function initPrisma() {
403
403
  )
404
404
  }
405
405
 
406
+ function initAPIGuards() {
407
+ const config = loadConfig()
408
+ const endpointGuardsFolder = path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.infrastructure}`, 'endpoint-guards')
409
+ fs.mkdirSync(endpointGuardsFolder, { recursive: true })
410
+
411
+ fs.writeFileSync(path.resolve(endpointGuardsFolder, 'endpoint-guards.ts'), [
412
+ `import { Controller } from '@alevnyacow/nzmt'`,
413
+ `export class EndpointGuards {`,
414
+ `\tdummyGuard: Controller.Guard = async () => { return undefined }`,
415
+ `}`
416
+ ].join('\n'))
417
+
418
+ fs.writeFileSync(path.resolve(endpointGuardsFolder, 'index.ts'), [
419
+ `export * from './endpoint-guards'`
420
+ ].join('\n'))
421
+
422
+ // Update DI
423
+
424
+ const diEntriesPath = path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.di}`, 'entries.di.ts')
425
+
426
+ insertBeforeLineInFile(
427
+ diEntriesPath,
428
+ 'type DIEntries =',
429
+ `import { EndpointGuards } from '@${config?.paths?.infrastructure}/endpoint-guards'`
430
+ )
431
+
432
+ insertAfterLineInFile(
433
+ diEntriesPath,
434
+ '// Infrastructure',
435
+ `\tEndpointGuards,`,
436
+ )
437
+
438
+ }
439
+
406
440
  function initLogger() {
407
441
  const config = loadConfig()
408
442
  const loggerFolder = path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.infrastructure}`, 'logger')
@@ -938,6 +972,9 @@ function generateController(upperCase, lowerCase, crudService) {
938
972
  if (!injections.includes('Logger')) {
939
973
  injections = injections.concat('Logger')
940
974
  }
975
+ if (!injections.includes('EndpointGuards')) {
976
+ injections = injections.concat('EndpointGuards')
977
+ }
941
978
 
942
979
  const crudServiceLowercase = crudService ? crudService.substring(0, 1).toLowerCase() + crudService.substring(1) : undefined
943
980
 
@@ -1019,8 +1056,8 @@ function generateController(upperCase, lowerCase, crudService) {
1019
1056
  ...injections.map(x => `\t\t@inject('${x}' satisfies DITokens) private readonly ${x.charAt(0).toLowerCase() + x.slice(1)}: ${x},`),
1020
1057
  `\t) {}`,
1021
1058
  ``,
1022
- `\tprivate readonly endpoints = Controller.endpoints(',
1023
- '\t\t${lowerCase}ControllerMetadata,`,
1059
+ `\tprivate readonly endpoints = Controller.endpoints(`,
1060
+ `\t\t${lowerCase}ControllerMetadata,`,
1024
1061
  '\t\t{ onErrorHandlers: [this.logger.error] }',
1025
1062
  '\t)',
1026
1063
  ``,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alevnyacow/nzmt",
3
- "version": "0.19.0",
3
+ "version": "0.20.0",
4
4
  "description": "Next Zod Modules Toolkit",
5
5
  "keywords": ["next", "full-stack", "server", "backend", "cli", "scaffolder", "zod", "rest", "contract programming", "react-query", "ddd", "domain-driven"],
6
6
  "repository": {