@alevnyacow/nzmt 0.23.0 → 0.25.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/README.md +3 -0
- package/bin/cli.js +52 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -142,6 +142,7 @@ export default async function Page() {
|
|
|
142
142
|
| `npx nzmt e <name>` | **e**ntity ||
|
|
143
143
|
| `npx nzmt vo <name>` | **v**alue **o**bject ||
|
|
144
144
|
| `npx nzmt cs <name>` | **c**ustom **s**tore (all schemas are `z.object({})`) ||
|
|
145
|
+
| `npx nzmt p <name>` | **p**rovider | `pt:Console` will generate Console provider. Default value is `pt:API` |
|
|
145
146
|
| `npx nzmt s <name>` | **s**ervice |`i:UserStore,Logger` will automatically inject `UserStore` and `Logger`. E.g. `npx nzmt s shop i:UserStore,ProductStore` will create `ShopService` with already injected `UserStore` and `ProductStore`|
|
|
146
147
|
| `npx nzmt c <name>` | **c**ontroller |`i:UserService` will automatically inject `UserService`. `Logger` and `Guards` are injected by default regardless of `i:` option|
|
|
147
148
|
|
|
@@ -161,6 +162,8 @@ They:
|
|
|
161
162
|
- can be reused across layers (no separate DTOs needed)
|
|
162
163
|
- automatically infer types (no manual TypeScript work)
|
|
163
164
|
|
|
165
|
+
Service method description example:
|
|
166
|
+
|
|
164
167
|
```ts
|
|
165
168
|
orderDetails: {
|
|
166
169
|
payload: Order.schema.pick({ name: true, createdDate: true }),
|
package/bin/cli.js
CHANGED
|
@@ -403,6 +403,48 @@ function initPrisma() {
|
|
|
403
403
|
)
|
|
404
404
|
}
|
|
405
405
|
|
|
406
|
+
function generateInfrastructure(upperCase, lowerCase) {
|
|
407
|
+
const config = loadConfig()
|
|
408
|
+
const folder = path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.infrastructure}`, entityName)
|
|
409
|
+
fs.mkdirSync(folder, { recursive: true })
|
|
410
|
+
|
|
411
|
+
fs.writeFileSync(path.resolve(folder, `${entityName}.ts`), [
|
|
412
|
+
`export class ${upperCase} {`,
|
|
413
|
+
`\t`,
|
|
414
|
+
`}`
|
|
415
|
+
])
|
|
416
|
+
|
|
417
|
+
fs.writeFileSync(path.resolve(folder, `${entityName}.mock.ts`), [
|
|
418
|
+
`import { ${upperCase} } from './${entityName}'`,
|
|
419
|
+
'',
|
|
420
|
+
`export class Mock${upperCase} implements ${upperCase} {`,
|
|
421
|
+
`\t`,
|
|
422
|
+
`}`
|
|
423
|
+
])
|
|
424
|
+
|
|
425
|
+
fs.writeFileSync(path.resolve(folder, `index.ts`), [
|
|
426
|
+
`export * from './${entityName}'`,
|
|
427
|
+
`export * from './${entityName}.mock'`
|
|
428
|
+
])
|
|
429
|
+
|
|
430
|
+
// Update DI
|
|
431
|
+
|
|
432
|
+
const diEntriesPath = path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.di}`, 'entries.di.ts')
|
|
433
|
+
|
|
434
|
+
insertBeforeLineInFile(
|
|
435
|
+
diEntriesPath,
|
|
436
|
+
'type DIEntries =',
|
|
437
|
+
`import { ${upperCase} } from '@${config?.paths?.infrastructure}/${entityName}'`
|
|
438
|
+
)
|
|
439
|
+
|
|
440
|
+
insertAfterLineInFile(
|
|
441
|
+
diEntriesPath,
|
|
442
|
+
'// Infrastructure',
|
|
443
|
+
`\t${upperCase}: { test: Mock${upperCase}, dev: ${upperCase}, prod: ${upperCase} },`,
|
|
444
|
+
)
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
|
|
406
448
|
function initGuards() {
|
|
407
449
|
const config = loadConfig()
|
|
408
450
|
const endpointGuardsFolder = path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.infrastructure}`, 'guards')
|
|
@@ -435,7 +477,6 @@ function initGuards() {
|
|
|
435
477
|
'// Infrastructure',
|
|
436
478
|
`\tGuards,`,
|
|
437
479
|
)
|
|
438
|
-
|
|
439
480
|
}
|
|
440
481
|
|
|
441
482
|
function initLogger() {
|
|
@@ -482,7 +523,7 @@ function initLogger() {
|
|
|
482
523
|
)
|
|
483
524
|
}
|
|
484
525
|
|
|
485
|
-
if (command.toLowerCase() === 'init'
|
|
526
|
+
if (command.toLowerCase() === 'init') {
|
|
486
527
|
createDefaultConfig()
|
|
487
528
|
initDI()
|
|
488
529
|
initClientUtils()
|
|
@@ -832,7 +873,7 @@ function generateProvider(lowerCase, upperCase) {
|
|
|
832
873
|
insertBeforeLineInFile(
|
|
833
874
|
diEntriesPath,
|
|
834
875
|
'type DIEntries =',
|
|
835
|
-
`import { ${upperCase}MockProvider, ${upperCase}${providerType}Provider } from '@${config?.paths?.providers}/${entityName}
|
|
876
|
+
`import { ${upperCase}MockProvider, ${upperCase}${providerType}Provider } from '@${config?.paths?.providers}/${entityName}'`
|
|
836
877
|
)
|
|
837
878
|
|
|
838
879
|
insertAfterLineInFile(
|
|
@@ -1283,10 +1324,10 @@ function generateQueries(lowerCase, upperCase, entity) {
|
|
|
1283
1324
|
|
|
1284
1325
|
const indexPath = path.resolve(projectRoot, `${config.coreFolder}${config.paths.queries}`, `${requiredEntity}`)
|
|
1285
1326
|
fs.writeFileSync(path.resolve(indexPath, 'index.ts'), `export * as ${upperCase}Queries from './endpoints'`)
|
|
1286
|
-
|
|
1287
1327
|
}
|
|
1288
1328
|
|
|
1289
1329
|
|
|
1330
|
+
|
|
1290
1331
|
if (command === 'api-routes') {
|
|
1291
1332
|
var [lowerCase, upperCase] = camelizeVariants(entityName)
|
|
1292
1333
|
|
|
@@ -1316,6 +1357,13 @@ if (command.toLowerCase() === 'controller' || command === 'c') {
|
|
|
1316
1357
|
process.exit(0)
|
|
1317
1358
|
}
|
|
1318
1359
|
|
|
1360
|
+
if (command.toLowerCase() === 'infrastructure' || command === 'i') {
|
|
1361
|
+
var [lowerCase, upperCase] = camelizeVariants(entityName)
|
|
1362
|
+
generateInfrastructure(upperCase, lowerCase)
|
|
1363
|
+
process.exit(0)
|
|
1364
|
+
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1319
1367
|
if (command.toLowerCase() === 'stored-entity' || command === 'se') {
|
|
1320
1368
|
var [lowerCase, upperCase] = camelizeVariants(entityName)
|
|
1321
1369
|
generateEntity(upperCase)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alevnyacow/nzmt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.0",
|
|
4
4
|
"description": "Next Zod Modules Toolkit",
|
|
5
5
|
"keywords": ["next", "full-stack", "server", "backend", "cli", "scaffolding", "zod", "rest", "contract programming", "contract-first", "react-query", "ddd", "domain-driven"],
|
|
6
6
|
"repository": {
|