@alevnyacow/nzmt 0.0.21 → 0.0.22

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 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
@@ -253,9 +257,49 @@ function generateStores(lowerCase, upperCase) {
253
257
 
254
258
  }
255
259
 
260
+
256
261
  if (command === 'store') {
257
262
  var [lowerCase, upperCase] = camelizeVariants(entityName)
258
263
  generateStores(lowerCase, upperCase)
259
264
  process.exit(0);
260
265
  }
261
266
 
267
+ function generateEntity(upperCase) {
268
+ const folder = config?.paths?.entities ? path.resolve(process.cwd(), config?.paths?.entities, entityName) : path.resolve(process.cwd(), entityName);
269
+
270
+ fs.mkdirSync(folder, { recursive: true })
271
+
272
+ const body = [
273
+ "import z from 'zod'",
274
+ "import { Entities } from '@alevnyacow/nzmt'",
275
+ "",
276
+ `export type ${upperCase}Model = z.infer<typeof ${upperCase}.schema>`,
277
+ "",
278
+ `export class ${upperCase} {`,
279
+ "\tstatic schema = z.object({",
280
+ "\t\tid: Entities.Identifier.schema,",
281
+ "\t\t",
282
+ "\t})",
283
+ "\t",
284
+ `\tprivate constructor(private readonly data: ${upperCase}Model) {}`,
285
+ "\t",
286
+ `\tstatic create = (data: ${upperCase}Model) => {`,
287
+ `\t\tconst parsedModel = ${upperCase}.schema.parse(data)`,
288
+ `\t\treturn new ${upperCase}(parsedModel)`,
289
+ "\t}",
290
+ "\t",
291
+ `\tget model(): ${upperCase}Model {`,
292
+ "\t\treturn this.data",
293
+ "\t}",
294
+ "}"
295
+ ].join('\n')
296
+
297
+ fs.writeFileSync(path.resolve(folder, `${entityName}.entity.ts`), body)
298
+ fs.writeFileSync(path.resolve(folder, 'index.ts'), `export * from './${entityName}.entity'`)
299
+ }
300
+
301
+ if (command === 'entity') {
302
+ var [lowerCase, upperCase] = camelizeVariants(entityName)
303
+ generateEntity(upperCase)
304
+ process.exit(0)
305
+ }
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ export * from './identifier.entity';
2
+ export * from './pagination.entity';
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
@@ -1,3 +1,4 @@
1
1
  export * as Module from './zod-module.utils';
2
2
  export * as Controller from './zod-controller.utils';
3
3
  export * as Store from './store';
4
+ export * as Entities from './entities';
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
- export { store_namespaceObject as Store, zod_controller_utils_namespaceObject as Controller, zod_module_utils_namespaceObject as Module };
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 './store.pagination.entity';
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("./store.pagination.entity").PaginationModel;
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,4 +1,4 @@
1
- import type { PaginationModel } from './store.pagination.entity';
1
+ import type { PaginationModel } from '../entities/pagination.entity';
2
2
  export type CRUD<Models extends {
3
3
  list: unknown;
4
4
  detail: unknown;
@@ -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 './store.pagination.entity';
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alevnyacow/nzmt",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "Next Zod Modules Toolkit",
5
5
  "type": "module",
6
6
  "exports": {