@alevnyacow/nzmt 0.9.6 → 0.10.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 +3 -3
  2. package/bin/cli.js +17 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -32,7 +32,7 @@ npx nzmt init prismaClientPath:@/app/generated/prisma/client
32
32
 
33
33
  4. Scaffold your first entity. Example for a `Product` with `title` and `price`:
34
34
  ```bash
35
- # Field syntax: f:<name>-<type>[.<zod-validators>]
35
+ # Field syntax: f:<name>-<zod-rules>
36
36
  npx nzmt entity product f:title-string,price-int.positive
37
37
  ```
38
38
  This will generate the entity, its Zod schema and related types.
@@ -41,8 +41,8 @@ This will generate the entity, its Zod schema and related types.
41
41
  ```bash
42
42
  # product store (with Prisma implementation, RAM implementation and DI)
43
43
  npx nzmt store product
44
- # product service with injected product store (with DI)
45
- npx nzmt service product i:ProductStore
44
+ # product service proxying all product store methods (with DI)
45
+ npx nzmt service product p:ProductStore
46
46
  # shop controller with injected product service and logger (with DI)
47
47
  npx nzmt controller shop i:Logger,ProductService
48
48
  ```
package/bin/cli.js CHANGED
@@ -415,7 +415,7 @@ function generateStores(lowerCase, upperCase, withEntityPreset) {
415
415
  `\tname: '${upperCase}Store'`,
416
416
  "} satisfies Store.Metadata",
417
417
  "",
418
- `export const { schemas: ${lowerCase}StoreSchemas } = Store.toModuleMetadata(${lowerCase}Metadata)`,
418
+ `export const { schemas: ${lowerCase}StoreSchemas } = Store.toModuleMetadata(${lowerCase}StoreMetadata)`,
419
419
  "",
420
420
  `export type ${upperCase}Store = Store.Contract<typeof ${lowerCase}StoreMetadata>`
421
421
  ].filter(x => typeof x === 'string').join('\n'))
@@ -746,7 +746,15 @@ function toKebabFromPascal(str) {
746
746
  function generateService(lowerCase, upperCase) {
747
747
  const folder = config?.paths?.services ? path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.services}`, entityName) : path.resolve(process.cwd(), entityName);
748
748
 
749
- const injections = options.filter(x => x.startsWith('i:')).flatMap(x => x.split(':')[1]).join(',').split(',').filter(x => !!x.length)
749
+ const proxiedStore = options.find(x => x.startsWith('p:'))?.split(':')?.at(-1)
750
+ if (proxiedStore && !proxiedStore.endsWith('Store')) {
751
+ throw 'Only stores can be proxied in services!'
752
+ }
753
+
754
+ let injections = options.filter(x => x.startsWith('i:')).flatMap(x => x.split(':')[1]).join(',').split(',').filter(x => !!x.length)
755
+ if (proxiedStore && !injections.includes(proxiedStore)) {
756
+ injections = injections.concat(proxiedStore)
757
+ }
750
758
 
751
759
  const importInjections = injections.map((i) => {
752
760
  if (i.endsWith('Service') || i.endsWith('Controller')) {
@@ -766,10 +774,11 @@ function generateService(lowerCase, upperCase) {
766
774
 
767
775
  fs.writeFileSync(path.resolve(folder, `${entityName}.service.metadata.ts`), [
768
776
  "import type { Module } from '@alevnyacow/nzmt'",
777
+ proxiedStore ? `import { ${proxiedStore.substring(0, 1).toLowerCase() + proxiedStore.substring(1)}Schemas } from '@${config?.paths?.stores}/${toKebabFromPascal(proxiedStore).slice(0, -'-store'.length)}'` : undefined,
769
778
  "",
770
779
  `export const ${lowerCase}ServiceMetadata = {`,
771
780
  `\tname: '${upperCase}Service',`,
772
- "\tschemas: {}",
781
+ proxiedStore ? `\tschemas: { ...${proxiedStore.substring(0, 1).toLowerCase() + proxiedStore.substring(1)}Schemas }` : "\tschemas: {}",
773
782
  "} satisfies Module.Metadata",
774
783
  "",
775
784
  `export type ${upperCase}ServiceDTOs = Module.DTOs<typeof ${lowerCase}ServiceMetadata>`
@@ -793,6 +802,11 @@ function generateService(lowerCase, upperCase) {
793
802
  ...injections.map(x => `\t\t@inject('${x}' satisfies DITokens) private readonly ${x.charAt(0).toLowerCase() + x.slice(1)}: ${x},`),
794
803
  `\t) {}`,
795
804
  ``,
805
+ proxiedStore ? `\tgetList = this.methods('list', this.${proxiedStore.charAt(0).toLowerCase() + proxiedStore.slice(1)}.list)` : undefined,
806
+ proxiedStore ? `\tgetDetails = this.methods('details', this.${proxiedStore.charAt(0).toLowerCase() + proxiedStore.slice(1)}.details)` : undefined,
807
+ proxiedStore ? `\tcreate = this.methods('create', this.${proxiedStore.charAt(0).toLowerCase() + proxiedStore.slice(1)}.create)` : undefined,
808
+ proxiedStore ? `\tupdate = this.methods('updateOne', this.${proxiedStore.charAt(0).toLowerCase() + proxiedStore.slice(1)}.updateOne)` : undefined,
809
+ proxiedStore ? `\tdelete = this.methods('deleteOne', this.${proxiedStore.charAt(0).toLowerCase() + proxiedStore.slice(1)}.deleteOne)` : undefined,
796
810
  "}"
797
811
  ].filter(x => typeof x === 'string').join('\n'))
798
812
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alevnyacow/nzmt",
3
- "version": "0.9.6",
3
+ "version": "0.10.0",
4
4
  "description": "Next Zod Modules Toolkit",
5
5
  "repository": {
6
6
  "type": "git",