@alevnyacow/nzmt 0.9.6 → 0.10.1
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.
- package/README.md +3 -3
- package/bin/cli.js +25 -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>-<
|
|
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
|
|
45
|
-
npx nzmt service product
|
|
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}
|
|
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
|
|
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,19 @@ 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
|
-
|
|
781
|
+
proxiedStore ? [
|
|
782
|
+
`\tschemas: {`,
|
|
783
|
+
`\t\tgetList: ${proxiedStore.substring(0, 1).toLowerCase() + proxiedStore.substring(1)}Schemas.list,`,
|
|
784
|
+
`\t\tgetDetails: ${proxiedStore.substring(0, 1).toLowerCase() + proxiedStore.substring(1)}Schemas.details,`,
|
|
785
|
+
`\t\tcreate: ${proxiedStore.substring(0, 1).toLowerCase() + proxiedStore.substring(1)}Schemas.create,`,
|
|
786
|
+
`\t\tupdate: ${proxiedStore.substring(0, 1).toLowerCase() + proxiedStore.substring(1)}Schemas.updateOne,`,
|
|
787
|
+
`\t\tdelete: ${proxiedStore.substring(0, 1).toLowerCase() + proxiedStore.substring(1)}Schemas.deleteOne,`,
|
|
788
|
+
`\t}`,
|
|
789
|
+
].join('\n') : "\tschemas: {}",
|
|
773
790
|
"} satisfies Module.Metadata",
|
|
774
791
|
"",
|
|
775
792
|
`export type ${upperCase}ServiceDTOs = Module.DTOs<typeof ${lowerCase}ServiceMetadata>`
|
|
@@ -793,6 +810,11 @@ function generateService(lowerCase, upperCase) {
|
|
|
793
810
|
...injections.map(x => `\t\t@inject('${x}' satisfies DITokens) private readonly ${x.charAt(0).toLowerCase() + x.slice(1)}: ${x},`),
|
|
794
811
|
`\t) {}`,
|
|
795
812
|
``,
|
|
813
|
+
proxiedStore ? `\tgetList = this.methods('getList', this.${proxiedStore.charAt(0).toLowerCase() + proxiedStore.slice(1)}.list)` : undefined,
|
|
814
|
+
proxiedStore ? `\tgetDetails = this.methods('getDetails', this.${proxiedStore.charAt(0).toLowerCase() + proxiedStore.slice(1)}.details)` : undefined,
|
|
815
|
+
proxiedStore ? `\tcreate = this.methods('create', this.${proxiedStore.charAt(0).toLowerCase() + proxiedStore.slice(1)}.create)` : undefined,
|
|
816
|
+
proxiedStore ? `\tupdate = this.methods('update', this.${proxiedStore.charAt(0).toLowerCase() + proxiedStore.slice(1)}.updateOne)` : undefined,
|
|
817
|
+
proxiedStore ? `\tdelete = this.methods('delete', this.${proxiedStore.charAt(0).toLowerCase() + proxiedStore.slice(1)}.deleteOne)` : undefined,
|
|
796
818
|
"}"
|
|
797
819
|
].filter(x => typeof x === 'string').join('\n'))
|
|
798
820
|
|