@alevnyacow/nzmt 0.0.31 → 0.0.33

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 +14 -12
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -308,14 +308,16 @@ if (command === 'entity') {
308
308
  }
309
309
 
310
310
  function generateService(lowerCase, upperCase, withCrud) {
311
- const folder = config?.paths?.services ? path.resolve(process.cwd(), config?.paths?.services, entityName) : path.resolve(process.cwd(), entityName);
311
+
312
+ const serviceName = withCrud ? entityName + 's' : entityName
313
+ const folder = config?.paths?.services ? path.resolve(process.cwd(), config?.paths?.services, serviceName) : path.resolve(process.cwd(), serviceName);
312
314
 
313
315
  fs.mkdirSync(folder, { recursive: true })
314
316
 
315
317
  // Metadata
316
318
 
317
319
  if (withCrud) {
318
- fs.writeFileSync(path.resolve(folder, `${entityName}.service.metadata.ts`), [
320
+ fs.writeFileSync(path.resolve(folder, `${serviceName}.service.metadata.ts`), [
319
321
  "import { type Module, Entities } from '@alevnyacow/nzmt'",
320
322
  "import z from 'zod'",
321
323
  `import { ${lowerCase}StoreMetadata } from '${config?.paths?.stores?.replace('./src', '@')}/${entityName}'`,
@@ -325,8 +327,8 @@ function generateService(lowerCase, upperCase, withCrud) {
325
327
  "\tschemas: {",
326
328
  "\t\tgetSpecific: {",
327
329
  `\t\t\tpayload: z.object({`,
328
- `\t\t\tfilter: ${lowerCase}StoreMetadata.searchPayload.specific`,
329
- `\t\t}),`,
330
+ `\t\t\t\tfilter: ${lowerCase}StoreMetadata.searchPayload.specific`,
331
+ `\t\t\t}),`,
330
332
  `\t\t\tresponse: z.object({`,
331
333
  `\t\t\t\titem: ${lowerCase}StoreMetadata.models.details.nullable()`,
332
334
  `\t\t\t})`,
@@ -335,7 +337,7 @@ function generateService(lowerCase, upperCase, withCrud) {
335
337
  `\t\t\tpayload: z.object({`,
336
338
  `\t\t\t\tfilter: ${lowerCase}StoreMetadata.searchPayload.list,`,
337
339
  `\t\t\t\tpagination: Entities.Pagination.schema.optional()`,
338
- `\t\t\t})`,
340
+ `\t\t\t}),`,
339
341
  `\t\t\tresponse: z.object({`,
340
342
  `\t\t\t\titems: z.array(${lowerCase}StoreMetadata.models.list)`,
341
343
  `\t\t\t})`,
@@ -343,14 +345,14 @@ function generateService(lowerCase, upperCase, withCrud) {
343
345
  `\t\tupdateOne: {`,
344
346
  `\t\t\tpayload: z.object({`,
345
347
  `\t\t\t\tfilter: ${lowerCase}StoreMetadata.searchPayload.specific,`,
346
- `\t\t\t\tpayload: userStoreMetadata.actionsPayload.update`,
348
+ `\t\t\t\tpayload: ${lowerCase}StoreMetadata.actionsPayload.update`,
347
349
  `\t\t\t}),`,
348
350
  `\t\t\tresponse: z.object({})`,
349
351
  `\t\t},`,
350
352
  `\t\tcreate: {`,
351
353
  `\t\t\tpayload: z.object({`,
352
354
  `\t\t\t\tpayload: ${lowerCase}StoreMetadata.actionsPayload.create`,
353
- `\t\t\t},`,
355
+ `\t\t\t}),`,
354
356
  `\t\t\tresponse: z.object({`,
355
357
  `\t\t\t\tid: Entities.Identifier.schema`,
356
358
  `\t\t\t}),`,
@@ -367,7 +369,7 @@ function generateService(lowerCase, upperCase, withCrud) {
367
369
  `export type ${upperCase}sServiceDTOs = Module.DTOs<typeof ${lowerCase}sServiceMetadata>"`
368
370
  ].filter(x => typeof x === 'string').join('\n'))
369
371
  } else {
370
- fs.writeFileSync(path.resolve(folder, `${entityName}.service.metadata.ts`), [
372
+ fs.writeFileSync(path.resolve(folder, `${serviceName}.service.metadata.ts`), [
371
373
  "import type { Module } from '@alevnyacow/nzmt'",
372
374
  "",
373
375
  `export const ${lowerCase}ServiceMetadata = {`,
@@ -381,7 +383,7 @@ function generateService(lowerCase, upperCase, withCrud) {
381
383
 
382
384
  // Service body
383
385
 
384
- fs.writeFileSync(path.resolve(folder, `${entityName}.service.ts`), [
386
+ fs.writeFileSync(path.resolve(folder, `${serviceName}.service.ts`), [
385
387
  config?.dependencyInjection?.inversifyjs ? "import { injectable } from 'inversify'" : undefined,
386
388
  `import { ${lowerCase}ServiceMetadata } from './${entityName}.service.metadata'`,
387
389
  "import { Module } from '@alevnyacow/nzmt'",
@@ -395,8 +397,8 @@ function generateService(lowerCase, upperCase, withCrud) {
395
397
  // Barrel
396
398
 
397
399
  fs.writeFileSync(path.resolve(folder, 'index.ts'), [
398
- `export * from ${entityName}.service.metadata`,
399
- `export * from ${entityName}.service`
400
+ `export * from ${serviceName}.service.metadata`,
401
+ `export * from ${serviceName}.service`
400
402
  ].join('\n'))
401
403
  }
402
404
 
@@ -411,5 +413,5 @@ if (command === 'crud') {
411
413
  var [lowerCase, upperCase] = camelizeVariants(entityName)
412
414
  generateEntity(upperCase)
413
415
  generateStores(lowerCase, upperCase)
414
- generateService(entityName + 's', lowerCase, upperCase, true)
416
+ generateService(lowerCase, upperCase, true)
415
417
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alevnyacow/nzmt",
3
- "version": "0.0.31",
3
+ "version": "0.0.33",
4
4
  "description": "Next Zod Modules Toolkit",
5
5
  "type": "module",
6
6
  "exports": {