@alevnyacow/nzmt 0.2.1 → 0.2.3

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 +57 -1
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -99,6 +99,7 @@ function createDefaultConfig() {
99
99
  providers: './src/server/providers',
100
100
  controllers: './src/server/controllers',
101
101
  entities: './src/shared/entities',
102
+ valueObjects: './src/shared/value-objects',
102
103
  queries: './src/client/shared/queries'
103
104
  },
104
105
  store: {
@@ -111,7 +112,6 @@ function createDefaultConfig() {
111
112
  }
112
113
  }, null, '\t'))
113
114
  }
114
-
115
115
  }
116
116
 
117
117
  function initDI() {
@@ -410,6 +410,23 @@ function generateStores(lowerCase, upperCase) {
410
410
  `export * from './${entityName}.store.prisma.ts'`,
411
411
  `export * from './${entityName}.store.ram.ts'`
412
412
  ].join('\n'))
413
+
414
+ // update DI
415
+
416
+ const diEntriesPath = path.resolve(process.cwd(), config?.paths?.di, 'entries.di.ts')
417
+
418
+ insertBeforeLineInFile(
419
+ diEntriesPath,
420
+ 'type DIEntries =',
421
+ `import { ${upperCase}PrismaStore, ${upperCase}RAMStore } from '${config?.paths?.stores.replace('./src', '@')}/${entityName}'\n`
422
+ )
423
+
424
+ insertAfterLineInFile(
425
+ diEntriesPath,
426
+ '// Stores',
427
+ `\t${upperCase}Store: { test: [${upperCase}RAMStore, (x) => x.inSingletonScope()], prod: ${upperCase}PrismaStore, dev: ${upperCase}PrismaStore },`,
428
+ )
429
+
413
430
  }
414
431
 
415
432
  if (command === 'store') {
@@ -458,6 +475,45 @@ if (command === 'entity') {
458
475
  process.exit(0)
459
476
  }
460
477
 
478
+ function generateValueObject(upperCase) {
479
+ const folder = config?.paths?.valueObjects ? path.resolve(process.cwd(), config?.paths?.valueObjects, entityName) : path.resolve(process.cwd(), entityName);
480
+
481
+ fs.mkdirSync(folder, { recursive: true })
482
+
483
+ const body = [
484
+ "import z from 'zod'",
485
+ "",
486
+ `export type ${upperCase}Model = z.infer<typeof ${upperCase}.schema>`,
487
+ "",
488
+ `export class ${upperCase} {`,
489
+ "\tstatic schema = z.object({",
490
+ "\t\t",
491
+ "\t})",
492
+ "\t",
493
+ `\tprivate constructor(private readonly data: ${upperCase}Model) {}`,
494
+ "\t",
495
+ `\tstatic create = (data: ${upperCase}Model) => {`,
496
+ `\t\tconst parsedModel = ${upperCase}.schema.parse(data)`,
497
+ `\t\treturn new ${upperCase}(parsedModel)`,
498
+ "\t}",
499
+ "\t",
500
+ `\tget model(): ${upperCase}Model {`,
501
+ "\t\treturn this.data",
502
+ "\t}",
503
+ "}"
504
+ ].join('\n')
505
+
506
+ fs.writeFileSync(path.resolve(folder, `${entityName}.value-object.ts`), body)
507
+ fs.writeFileSync(path.resolve(folder, 'index.ts'), `export * from './${entityName}.value-object'`)
508
+ }
509
+
510
+ if (command === 'value-object') {
511
+ var [lowerCase, upperCase] = camelizeVariants(entityName)
512
+ generateValueObject(upperCase)
513
+ process.exit(0)
514
+ }
515
+
516
+
461
517
  function generateService(lowerCase, upperCase, withCrud) {
462
518
  const folder = config?.paths?.services ? path.resolve(process.cwd(), config?.paths?.services, entityName) : path.resolve(process.cwd(), entityName);
463
519
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alevnyacow/nzmt",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Next Zod Modules Toolkit",
5
5
  "repository": {
6
6
  "type": "git",