@alevnyacow/nzmt 0.0.21 → 0.0.23
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 +51 -8
- package/dist/entities/identifier.entity.d.ts +11 -0
- package/dist/entities/index.d.ts +2 -0
- package/dist/index.cjs +28 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +25 -1
- package/dist/store/store.ram.utils.d.ts +2 -2
- package/dist/store/store.shared-models.utils.d.ts +1 -1
- package/dist/store/store.zod.utils.d.ts +1 -1
- package/package.json +1 -1
- /package/dist/{store/store.pagination.entity.d.ts → entities/pagination.entity.d.ts} +0 -0
package/bin/cli.js
CHANGED
|
@@ -7,6 +7,10 @@ var args = process.argv.slice(2);
|
|
|
7
7
|
var [command, entityName] = args;
|
|
8
8
|
|
|
9
9
|
function camelizeVariants(str) {
|
|
10
|
+
if (!str.includes('-')) {
|
|
11
|
+
return [str, str.substring(0, 1).toUpperCase() + str.substring(1)]
|
|
12
|
+
}
|
|
13
|
+
|
|
10
14
|
const words = str.split("-");
|
|
11
15
|
|
|
12
16
|
const lowerCamel = words
|
|
@@ -97,28 +101,29 @@ function generateStores(lowerCase, upperCase) {
|
|
|
97
101
|
fs.writeFileSync(path.resolve(folder, `${entityName}.store.ts`), [
|
|
98
102
|
"import z from 'zod'",
|
|
99
103
|
"import { Store } from '@alevnyacow/nzmt'",
|
|
104
|
+
config?.paths?.entities ? `import ${upperCase} from ${config?.paths?.entities.replace('./src', '@')}/${entityName}` : undefined,
|
|
100
105
|
"",
|
|
101
106
|
`export const ${lowerCase}StoreMetadata = {`,
|
|
102
107
|
"\tmodels: {",
|
|
103
|
-
"\t\tlist: z.object({ }),",
|
|
104
|
-
"\t\tdetails: z.object({ }),",
|
|
108
|
+
config?.paths?.entities ? `\t\tlist: ${upperCase}.schema,` : "\t\tlist: z.object({ }),",
|
|
109
|
+
config?.paths?.entities ? `\t\tdetails: ${upperCase}.schema,` : "\t\tdetails: z.object({ }),",
|
|
105
110
|
"\t},",
|
|
106
111
|
"",
|
|
107
112
|
"\tsearchPayload: {",
|
|
108
|
-
"\t\tlist: z.object({ }),",
|
|
109
|
-
"\t\tspecific: z.object({ }),",
|
|
113
|
+
config?.paths?.entities ? `\t\tlist: ${upperCase}.schema.omit({ id: true }),` : "\t\tlist: z.object({ }),",
|
|
114
|
+
config?.paths?.entities ? `\t\tspecific: ${upperCase}.schema.pick({ id: true }),` : "\t\tspecific: z.object({ }),",
|
|
110
115
|
"\t},",
|
|
111
116
|
"",
|
|
112
117
|
"\tactionsPayload: {",
|
|
113
|
-
"\t\tcreate: z.object({ }),",
|
|
114
|
-
"\t\tupdate: z.object({ }),",
|
|
118
|
+
config?.paths?.entities ? `\t\tcreate: ${upperCase}.schema.omit({ id: true }),` : "\t\tcreate: z.object({ }),",
|
|
119
|
+
config?.paths?.entities ? `\t\tupdate: ${upperCase}.schema.omit({ id: true }),` : "\t\tupdate: z.object({ }),",
|
|
115
120
|
"\t},",
|
|
116
121
|
"",
|
|
117
122
|
`\tname: '${upperCase}Store'`,
|
|
118
123
|
"} satisfies Store.Metadata",
|
|
119
124
|
"",
|
|
120
125
|
`export type ${upperCase}Store = Store.Contract<typeof ${lowerCase}StoreMetadata>`
|
|
121
|
-
].join('\n'))
|
|
126
|
+
].filter(x => typeof x === 'string').join('\n'))
|
|
122
127
|
|
|
123
128
|
// RAM
|
|
124
129
|
|
|
@@ -250,7 +255,6 @@ function generateStores(lowerCase, upperCase) {
|
|
|
250
255
|
`export * from './${entityName}.store.prisma.ts'`,
|
|
251
256
|
`export * from './${entityName}.store.ram.ts'`
|
|
252
257
|
].join('\n'))
|
|
253
|
-
|
|
254
258
|
}
|
|
255
259
|
|
|
256
260
|
if (command === 'store') {
|
|
@@ -259,3 +263,42 @@ if (command === 'store') {
|
|
|
259
263
|
process.exit(0);
|
|
260
264
|
}
|
|
261
265
|
|
|
266
|
+
function generateEntity(upperCase) {
|
|
267
|
+
const folder = config?.paths?.entities ? path.resolve(process.cwd(), config?.paths?.entities, entityName) : path.resolve(process.cwd(), entityName);
|
|
268
|
+
|
|
269
|
+
fs.mkdirSync(folder, { recursive: true })
|
|
270
|
+
|
|
271
|
+
const body = [
|
|
272
|
+
"import z from 'zod'",
|
|
273
|
+
"import { Entities } from '@alevnyacow/nzmt'",
|
|
274
|
+
"",
|
|
275
|
+
`export type ${upperCase}Model = z.infer<typeof ${upperCase}.schema>`,
|
|
276
|
+
"",
|
|
277
|
+
`export class ${upperCase} {`,
|
|
278
|
+
"\tstatic schema = z.object({",
|
|
279
|
+
"\t\tid: Entities.Identifier.schema,",
|
|
280
|
+
"\t\t",
|
|
281
|
+
"\t})",
|
|
282
|
+
"\t",
|
|
283
|
+
`\tprivate constructor(private readonly data: ${upperCase}Model) {}`,
|
|
284
|
+
"\t",
|
|
285
|
+
`\tstatic create = (data: ${upperCase}Model) => {`,
|
|
286
|
+
`\t\tconst parsedModel = ${upperCase}.schema.parse(data)`,
|
|
287
|
+
`\t\treturn new ${upperCase}(parsedModel)`,
|
|
288
|
+
"\t}",
|
|
289
|
+
"\t",
|
|
290
|
+
`\tget model(): ${upperCase}Model {`,
|
|
291
|
+
"\t\treturn this.data",
|
|
292
|
+
"\t}",
|
|
293
|
+
"}"
|
|
294
|
+
].join('\n')
|
|
295
|
+
|
|
296
|
+
fs.writeFileSync(path.resolve(folder, `${entityName}.entity.ts`), body)
|
|
297
|
+
fs.writeFileSync(path.resolve(folder, 'index.ts'), `export * from './${entityName}.entity'`)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
if (command === 'entity') {
|
|
301
|
+
var [lowerCase, upperCase] = camelizeVariants(entityName)
|
|
302
|
+
generateEntity(upperCase)
|
|
303
|
+
process.exit(0)
|
|
304
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import z from 'zod';
|
|
2
|
+
export type IdentifierModel = z.infer<typeof Identifier.schema>;
|
|
3
|
+
export declare class Identifier {
|
|
4
|
+
private readonly data;
|
|
5
|
+
static schema: z.ZodString;
|
|
6
|
+
private constructor();
|
|
7
|
+
static create: (data: IdentifierModel) => Identifier;
|
|
8
|
+
static get randomUUID(): Identifier;
|
|
9
|
+
get model(): IdentifierModel;
|
|
10
|
+
get isUUID(): boolean;
|
|
11
|
+
}
|
package/dist/index.cjs
CHANGED
|
@@ -35,7 +35,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
35
35
|
__webpack_require__.d(__webpack_exports__, {
|
|
36
36
|
Controller: ()=>zod_controller_utils_namespaceObject,
|
|
37
37
|
Store: ()=>store_namespaceObject,
|
|
38
|
-
Module: ()=>zod_module_utils_namespaceObject
|
|
38
|
+
Module: ()=>zod_module_utils_namespaceObject,
|
|
39
|
+
Entities: ()=>entities_namespaceObject
|
|
39
40
|
});
|
|
40
41
|
var zod_module_utils_namespaceObject = {};
|
|
41
42
|
__webpack_require__.r(zod_module_utils_namespaceObject);
|
|
@@ -54,6 +55,12 @@ __webpack_require__.d(store_namespaceObject, {
|
|
|
54
55
|
InRAM: ()=>InRAM,
|
|
55
56
|
methods: ()=>store_zod_utils_methods
|
|
56
57
|
});
|
|
58
|
+
var entities_namespaceObject = {};
|
|
59
|
+
__webpack_require__.r(entities_namespaceObject);
|
|
60
|
+
__webpack_require__.d(entities_namespaceObject, {
|
|
61
|
+
Identifier: ()=>Identifier,
|
|
62
|
+
Pagination: ()=>Pagination
|
|
63
|
+
});
|
|
57
64
|
class ErrorFactory {
|
|
58
65
|
static isControllerError = (error)=>{
|
|
59
66
|
if (!error || 'object' != typeof error) return false;
|
|
@@ -505,11 +512,31 @@ const InRAM = (schemas, options)=>{
|
|
|
505
512
|
}
|
|
506
513
|
return RAMStore;
|
|
507
514
|
};
|
|
515
|
+
const external_node_crypto_namespaceObject = require("node:crypto");
|
|
516
|
+
class Identifier {
|
|
517
|
+
data;
|
|
518
|
+
static schema = external_zod_default().string().nonempty();
|
|
519
|
+
constructor(data){
|
|
520
|
+
this.data = data;
|
|
521
|
+
}
|
|
522
|
+
static create = (data)=>new Identifier(Identifier.schema.parse(data));
|
|
523
|
+
static get randomUUID() {
|
|
524
|
+
return Identifier.create((0, external_node_crypto_namespaceObject.randomUUID)());
|
|
525
|
+
}
|
|
526
|
+
get model() {
|
|
527
|
+
return this.data;
|
|
528
|
+
}
|
|
529
|
+
get isUUID() {
|
|
530
|
+
return external_zod_default().uuidv4().safeParse(this.data).success;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
508
533
|
exports.Controller = __webpack_exports__.Controller;
|
|
534
|
+
exports.Entities = __webpack_exports__.Entities;
|
|
509
535
|
exports.Module = __webpack_exports__.Module;
|
|
510
536
|
exports.Store = __webpack_exports__.Store;
|
|
511
537
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
512
538
|
"Controller",
|
|
539
|
+
"Entities",
|
|
513
540
|
"Module",
|
|
514
541
|
"Store"
|
|
515
542
|
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { __webpack_require__ } from "./rslib-runtime.js";
|
|
2
2
|
import { NextResponse } from "next/server";
|
|
3
3
|
import zod from "zod";
|
|
4
|
+
import { randomUUID } from "node:crypto";
|
|
5
|
+
var entities_namespaceObject = {};
|
|
6
|
+
__webpack_require__.r(entities_namespaceObject);
|
|
7
|
+
__webpack_require__.d(entities_namespaceObject, {
|
|
8
|
+
Identifier: ()=>Identifier,
|
|
9
|
+
Pagination: ()=>Pagination
|
|
10
|
+
});
|
|
4
11
|
var store_namespaceObject = {};
|
|
5
12
|
__webpack_require__.r(store_namespaceObject);
|
|
6
13
|
__webpack_require__.d(store_namespaceObject, {
|
|
@@ -466,4 +473,21 @@ const InRAM = (schemas, options)=>{
|
|
|
466
473
|
}
|
|
467
474
|
return RAMStore;
|
|
468
475
|
};
|
|
469
|
-
|
|
476
|
+
class Identifier {
|
|
477
|
+
data;
|
|
478
|
+
static schema = zod.string().nonempty();
|
|
479
|
+
constructor(data){
|
|
480
|
+
this.data = data;
|
|
481
|
+
}
|
|
482
|
+
static create = (data)=>new Identifier(Identifier.schema.parse(data));
|
|
483
|
+
static get randomUUID() {
|
|
484
|
+
return Identifier.create(randomUUID());
|
|
485
|
+
}
|
|
486
|
+
get model() {
|
|
487
|
+
return this.data;
|
|
488
|
+
}
|
|
489
|
+
get isUUID() {
|
|
490
|
+
return zod.uuidv4().safeParse(this.data).success;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
export { entities_namespaceObject as Entities, store_namespaceObject as Store, zod_controller_utils_namespaceObject as Controller, zod_module_utils_namespaceObject as Module };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
|
-
import { Pagination } from '
|
|
2
|
+
import { Pagination } from '../entities/pagination.entity';
|
|
3
3
|
import type { CRUD, Types } from './store.shared-models.utils';
|
|
4
4
|
import { type Contract, type Metadata } from './store.zod.utils';
|
|
5
5
|
export declare const InRAM: <T extends Metadata>(schemas: T, options?: {
|
|
@@ -741,7 +741,7 @@ export declare const InRAM: <T extends Metadata>(schemas: T, options?: {
|
|
|
741
741
|
update: AUpdate;
|
|
742
742
|
};
|
|
743
743
|
} : never : never : never)["SearchPayload"]["list"];
|
|
744
|
-
pagination?: import("
|
|
744
|
+
pagination?: import("../entities").PaginationModel;
|
|
745
745
|
}) => Promise<(Contract<T> extends infer T_2 ? T_2 extends Contract<T> ? T_2 extends {
|
|
746
746
|
list: (data: {
|
|
747
747
|
filter: infer SList;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ZodArray, ZodBoolean, ZodObject, ZodString, ZodType, ZodUnion } from 'zod';
|
|
2
2
|
import z from 'zod';
|
|
3
|
-
import { Pagination } from '
|
|
3
|
+
import { Pagination } from '../entities/pagination.entity';
|
|
4
4
|
import type { CRUD } from './store.shared-models.utils';
|
|
5
5
|
type ZodSchema = ZodType;
|
|
6
6
|
type Models<List, Detail> = {
|
package/package.json
CHANGED
|
File without changes
|