@alevnyacow/nzmt 0.2.3 → 0.2.4
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 +11 -9
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -247,31 +247,33 @@ if (command === 'init') {
|
|
|
247
247
|
process.exit(0)
|
|
248
248
|
}
|
|
249
249
|
|
|
250
|
-
function generateStores(lowerCase, upperCase) {
|
|
250
|
+
function generateStores(lowerCase, upperCase, withEntityPreset) {
|
|
251
251
|
const folder = config?.paths?.stores ? path.resolve(process.cwd(), config?.paths?.stores, entityName) : path.resolve(process.cwd(), entityName);
|
|
252
252
|
|
|
253
253
|
fs.mkdirSync(folder, { recursive: true })
|
|
254
254
|
|
|
255
|
+
const withEntity = withEntityPreset || (options ?? []).includes('with-entity')
|
|
256
|
+
|
|
255
257
|
// Contract
|
|
256
258
|
|
|
257
259
|
fs.writeFileSync(path.resolve(folder, `${entityName}.store.ts`), [
|
|
258
260
|
"import type { Store } from '@alevnyacow/nzmt'",
|
|
259
|
-
|
|
261
|
+
withEntity ? `import { ${upperCase} } from '${config?.paths?.entities.replace('./src', '@')}/${entityName}'` : undefined,
|
|
260
262
|
"",
|
|
261
263
|
`export const ${lowerCase}StoreMetadata = {`,
|
|
262
264
|
"\tmodels: {",
|
|
263
|
-
|
|
264
|
-
|
|
265
|
+
withEntity ? `\t\tlist: ${upperCase}.schema,` : "\t\tlist: z.object({ }),",
|
|
266
|
+
withEntity ? `\t\tdetails: ${upperCase}.schema,` : "\t\tdetails: z.object({ }),",
|
|
265
267
|
"\t},",
|
|
266
268
|
"",
|
|
267
269
|
"\tsearchPayload: {",
|
|
268
|
-
|
|
269
|
-
|
|
270
|
+
withEntity ? `\t\tlist: ${upperCase}.schema.omit({ id: true }),` : "\t\tlist: z.object({ }),",
|
|
271
|
+
withEntity ? `\t\tspecific: ${upperCase}.schema.pick({ id: true }),` : "\t\tspecific: z.object({ }),",
|
|
270
272
|
"\t},",
|
|
271
273
|
"",
|
|
272
274
|
"\tactionsPayload: {",
|
|
273
|
-
|
|
274
|
-
|
|
275
|
+
withEntity ? `\t\tcreate: ${upperCase}.schema.omit({ id: true }),` : "\t\tcreate: z.object({ }),",
|
|
276
|
+
withEntity ? `\t\tupdate: ${upperCase}.schema.omit({ id: true }).partial(),` : "\t\tupdate: z.object({ }),",
|
|
275
277
|
"\t},",
|
|
276
278
|
"",
|
|
277
279
|
`\tname: '${upperCase}Store'`,
|
|
@@ -672,7 +674,7 @@ if (command === 'service') {
|
|
|
672
674
|
if (command === 'crud') {
|
|
673
675
|
var [lowerCase, upperCase] = camelizeVariants(entityName)
|
|
674
676
|
generateEntity(upperCase)
|
|
675
|
-
generateStores(lowerCase, upperCase)
|
|
677
|
+
generateStores(lowerCase, upperCase, true)
|
|
676
678
|
generateService(lowerCase, upperCase, true)
|
|
677
679
|
process.exit(0)
|
|
678
680
|
}
|