@alevnyacow/nzmt 0.21.3 → 0.22.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 (3) hide show
  1. package/README.md +21 -0
  2. package/bin/cli.js +12 -16
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -124,6 +124,27 @@ export default async function Page() {
124
124
  }
125
125
  ```
126
126
 
127
+ # Scaffolder commands glossary
128
+
129
+ ## Complex scaffolding
130
+
131
+ | Command | Description |
132
+ |---------|-------------|
133
+ | `npx nzmt crud-api <name>` | CRUD via Server Actions and React Query hooks. |
134
+ | `npx nzmt crud-service <name>` | CRUD via Server Actions (no Controllers, API Routes and React Query hooks). |
135
+ | `npx nzmt se <name>` | Generate **e**ntity + **s**tore (contracts linked). |
136
+ | `npx nzmt rq` | Generate API **r**outes and React **q**eries for all of your controllers. This command will also remove endpoints which don't exist anymore with according React query hooks |
137
+
138
+ ## Single module scaffolding
139
+
140
+ | Command | Description |Options|
141
+ |---------|-------------|-------|
142
+ | `npx nzmt e <name>` | Generate **e**ntity. ||
143
+ | `npx nzmt vo <name>` | Generate **v**alue **o**bject. ||
144
+ | `npx nzmt cs <name>` | Generate **c**ustom **s**tore (all schemas are `z.object({})`). ||
145
+ | `npx nzmt s <name>` | Generate **s**ervice. |`i:UserStore,Logger` will automatically inject `UserStore` and `Logger`. E.g. `npx nzmt s shop i:UserStore,ProductStore` will create `ShopService` with already injected `UserStore` and `ProductStore`|
146
+ | `npx nzmt c <name>` | Generate **c**ontroller. |`i:UserService` will automatically inject `UserService`. `Logger` and `Guared` are injected by default regardless of `i:` option|
147
+
127
148
  # FAQ
128
149
 
129
150
  ## What does DDD-inspired mean?
package/bin/cli.js CHANGED
@@ -403,21 +403,21 @@ function initPrisma() {
403
403
  )
404
404
  }
405
405
 
406
- function initEndpointGuards() {
406
+ function initGuards() {
407
407
  const config = loadConfig()
408
- const endpointGuardsFolder = path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.infrastructure}`, 'endpoint-guards')
408
+ const endpointGuardsFolder = path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.infrastructure}`, 'guards')
409
409
  fs.mkdirSync(endpointGuardsFolder, { recursive: true })
410
410
 
411
- fs.writeFileSync(path.resolve(endpointGuardsFolder, 'endpoint-guards.ts'), [
411
+ fs.writeFileSync(path.resolve(endpointGuardsFolder, 'guards.ts'), [
412
412
  `import type { Controller } from '@alevnyacow/nzmt'`,
413
413
  '',
414
- `export class EndpointGuards {`,
414
+ `export class Guards {`,
415
415
  `\tdummyGuard: Controller.Guard = async () => { return undefined }`,
416
416
  `}`
417
417
  ].join('\n'))
418
418
 
419
419
  fs.writeFileSync(path.resolve(endpointGuardsFolder, 'index.ts'), [
420
- `export * from './endpoint-guards'`
420
+ `export * from './guards'`
421
421
  ].join('\n'))
422
422
 
423
423
  // Update DI
@@ -427,13 +427,13 @@ function initEndpointGuards() {
427
427
  insertBeforeLineInFile(
428
428
  diEntriesPath,
429
429
  'type DIEntries =',
430
- `import { EndpointGuards } from '@${config?.paths?.infrastructure}/endpoint-guards'`
430
+ `import { Guards } from '@${config?.paths?.infrastructure}/guards'`
431
431
  )
432
432
 
433
433
  insertAfterLineInFile(
434
434
  diEntriesPath,
435
435
  '// Infrastructure',
436
- `\tEndpointGuards,`,
436
+ `\tGuards,`,
437
437
  )
438
438
 
439
439
  }
@@ -490,7 +490,7 @@ if (command.toLowerCase() === 'init' || command === 'i') {
490
490
  initSharedErrors()
491
491
  initPrisma()
492
492
  initLogger()
493
- initEndpointGuards()
493
+ initGuards()
494
494
 
495
495
  process.exit(0)
496
496
  }
@@ -686,7 +686,7 @@ function generateStores(lowerCase, upperCase, withEntityPreset) {
686
686
 
687
687
  }
688
688
 
689
- if (command.toLowerCase() === 'store' || command === 's') {
689
+ if (command.toLowerCase() === 'store' || command === 'cs') {
690
690
  var [lowerCase, upperCase] = camelizeVariants(entityName)
691
691
  generateStores(lowerCase, upperCase)
692
692
  process.exit(0);
@@ -954,7 +954,7 @@ function generateService(lowerCase, upperCase, store) {
954
954
  )
955
955
  }
956
956
 
957
- if (command.toLowerCase() === 'service' || command === 'S') {
957
+ if (command.toLowerCase() === 'service' || command === 's') {
958
958
  var [lowerCase, upperCase] = camelizeVariants(entityName)
959
959
  generateService(lowerCase, upperCase, false)
960
960
  process.exit(0)
@@ -971,12 +971,8 @@ function generateController(upperCase, lowerCase, crudService) {
971
971
  if (crudService && !injections.includes(crudService)) {
972
972
  injections = injections.concat(crudService)
973
973
  }
974
- if (!injections.includes('Logger')) {
975
- injections = injections.concat('Logger')
976
- }
977
- if (!injections.includes('EndpointGuards')) {
978
- injections = injections.concat('EndpointGuards')
979
- }
974
+
975
+ injections = ['Logger', 'Guards', ...injections.filter(x => x !== 'Logger' && x !== 'Guards')]
980
976
 
981
977
  const crudServiceLowercase = crudService ? crudService.substring(0, 1).toLowerCase() + crudService.substring(1) : undefined
982
978
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alevnyacow/nzmt",
3
- "version": "0.21.3",
3
+ "version": "0.22.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": {