@alevnyacow/nzmt 0.2.2 → 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 +40 -0
  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: {
@@ -474,6 +475,45 @@ if (command === 'entity') {
474
475
  process.exit(0)
475
476
  }
476
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
+
477
517
  function generateService(lowerCase, upperCase, withCrud) {
478
518
  const folder = config?.paths?.services ? path.resolve(process.cwd(), config?.paths?.services, entityName) : path.resolve(process.cwd(), entityName);
479
519
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alevnyacow/nzmt",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Next Zod Modules Toolkit",
5
5
  "repository": {
6
6
  "type": "git",