@alevnyacow/nzmt 0.17.3 → 0.18.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.
- package/bin/cli.js +22 -4
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -110,6 +110,7 @@ function createDefaultConfig() {
|
|
|
110
110
|
infrastructure: '/server/infrastructure',
|
|
111
111
|
entities: '/shared/entities',
|
|
112
112
|
valueObjects: '/shared/value-objects',
|
|
113
|
+
sharedErrors: './shared/errors',
|
|
113
114
|
queries: '/client/shared/queries',
|
|
114
115
|
clientUtils: '/client/shared/utils'
|
|
115
116
|
},
|
|
@@ -129,6 +130,7 @@ function createDefaultConfig() {
|
|
|
129
130
|
infrastructure: '/server/infrastructure',
|
|
130
131
|
entities: '/shared/entities',
|
|
131
132
|
valueObjects: '/shared/value-objects',
|
|
133
|
+
sharedErrors: './shared/errors',
|
|
132
134
|
queries: '/client/shared/queries',
|
|
133
135
|
clientUtils: '/client/shared/utils'
|
|
134
136
|
}
|
|
@@ -136,6 +138,20 @@ function createDefaultConfig() {
|
|
|
136
138
|
}
|
|
137
139
|
}
|
|
138
140
|
|
|
141
|
+
function initSharedErrors() {
|
|
142
|
+
const config = loadConfig()
|
|
143
|
+
const folder = path.resolve(process.cwd(), `${config.coreFolder}${config.paths.sharedErrors}`)
|
|
144
|
+
fs.mkdirSync(folder, { recursive: true })
|
|
145
|
+
|
|
146
|
+
fs.writeFileSync(path.resolve(folder, 'shared-error-codes.ts'), [
|
|
147
|
+
"export enum CommonErrorCodes {",
|
|
148
|
+
"\tNO_DATA_WAS_FOUND = 'COMMON___NO_DATA_WAS_FOUND'",
|
|
149
|
+
"}"
|
|
150
|
+
].join('\n'))
|
|
151
|
+
|
|
152
|
+
fs.writeFileSync(path.resolve(folder, 'index.ts'), "export * from './shared-error-codes'")
|
|
153
|
+
}
|
|
154
|
+
|
|
139
155
|
function initVO() {
|
|
140
156
|
const config = loadConfig()
|
|
141
157
|
const voFolder = path.resolve(process.cwd(), `${config.coreFolder}${config.paths.valueObjects}`)
|
|
@@ -436,6 +452,7 @@ if (command.toLowerCase() === 'init' || command === 'i') {
|
|
|
436
452
|
initDI()
|
|
437
453
|
initClientUtils()
|
|
438
454
|
initVO()
|
|
455
|
+
initSharedErrors()
|
|
439
456
|
initPrisma()
|
|
440
457
|
initLogger()
|
|
441
458
|
|
|
@@ -983,9 +1000,10 @@ function generateController(upperCase, lowerCase, crudService) {
|
|
|
983
1000
|
// Body
|
|
984
1001
|
|
|
985
1002
|
fs.writeFileSync(path.resolve(folder, `${entityName}.controller.ts`), [
|
|
986
|
-
`import { Controller } from '@alevnyacow/nzmt'`,
|
|
987
1003
|
`import { injectable, inject } from 'inversify'`,
|
|
1004
|
+
`import { Controller } from '@alevnyacow/nzmt'`,
|
|
988
1005
|
`import { DITokens } from '@${config?.paths?.di}'`,
|
|
1006
|
+
crudService ? `import { CommonErrorCodes } from '@${config?.paths?.sharedErrors}'` : undefined,
|
|
989
1007
|
`import { ${lowerCase}ControllerMetadata } from './${entityName}.controller.metadata'`,
|
|
990
1008
|
...importInjections,
|
|
991
1009
|
``,
|
|
@@ -1008,7 +1026,7 @@ function generateController(upperCase, lowerCase, crudService) {
|
|
|
1008
1026
|
``,
|
|
1009
1027
|
`\tdetails_GET = this.endpoints('details_GET', async (payload, { endpointError }) => {`,
|
|
1010
1028
|
`\t\tconst details = await this.${crudServiceLowercase}.getDetails(payload)`,
|
|
1011
|
-
`\t\tif (!details) { throw endpointError(
|
|
1029
|
+
`\t\tif (!details) { throw endpointError(CommonErrorCodes.NO_DATA_WAS_FOUND, 404) }`,
|
|
1012
1030
|
`\t\treturn details`,
|
|
1013
1031
|
`\t})`,
|
|
1014
1032
|
``,
|
|
@@ -1115,7 +1133,7 @@ function generateQueries(lowerCase, upperCase) {
|
|
|
1115
1133
|
return acc
|
|
1116
1134
|
}, {})
|
|
1117
1135
|
|
|
1118
|
-
const controllerQueriesPath = path.resolve(projectRoot, `${config.coreFolder}${config.paths.queries}`, `${entityName}`, '
|
|
1136
|
+
const controllerQueriesPath = path.resolve(projectRoot, `${config.coreFolder}${config.paths.queries}`, `${entityName}`, 'endpoints')
|
|
1119
1137
|
let scaffoldedMethods = []
|
|
1120
1138
|
|
|
1121
1139
|
fs.mkdirSync(controllerQueriesPath, { recursive: true })
|
|
@@ -1214,7 +1232,7 @@ function generateQueries(lowerCase, upperCase) {
|
|
|
1214
1232
|
fs.writeFileSync(path.resolve(controllerQueriesPath, 'index.ts'), scaffoldedMethods.map(x => `export * from './${x}'`).join('\n'))
|
|
1215
1233
|
|
|
1216
1234
|
const indexPath = path.resolve(projectRoot, `${config.coreFolder}${config.paths.queries}`, `${entityName}`)
|
|
1217
|
-
fs.writeFileSync(path.resolve(indexPath, 'index.ts'), `export * as ${upperCase}Queries from './
|
|
1235
|
+
fs.writeFileSync(path.resolve(indexPath, 'index.ts'), `export * as ${upperCase}Queries from './endpoints'`)
|
|
1218
1236
|
|
|
1219
1237
|
}
|
|
1220
1238
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alevnyacow/nzmt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "Next Zod Modules Toolkit",
|
|
5
5
|
"keywords": ["next", "full-stack", "server", "backend", "cli", "scaffolder", "zod", "rest", "contract programming", "react-query", "ddd", "domain-driven"],
|
|
6
6
|
"repository": {
|