@alevnyacow/nzmt 0.0.19 → 0.0.21

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
@@ -6,6 +6,22 @@ var args = process.argv.slice(2);
6
6
 
7
7
  var [command, entityName] = args;
8
8
 
9
+ function camelizeVariants(str) {
10
+ const words = str.split("-");
11
+
12
+ const lowerCamel = words
13
+ .map((word, index) =>
14
+ index === 0 ? word.toLowerCase() : word[0].toUpperCase() + word.slice(1).toLowerCase()
15
+ )
16
+ .join("");
17
+
18
+ const upperCamel = words
19
+ .map(word => word[0].toUpperCase() + word.slice(1).toLowerCase())
20
+ .join("");
21
+
22
+ return [lowerCamel, upperCamel];
23
+ }
24
+
9
25
  function findProjectRoot(startDir = process.cwd()) {
10
26
  let dir = startDir;
11
27
  while (dir !== path.parse(dir).root) {
@@ -40,7 +56,7 @@ function loadConfig() {
40
56
 
41
57
  const config = loadConfig();
42
58
 
43
- if (command === 'init-config') {
59
+ function createDefaultConfig() {
44
60
  if (!config) {
45
61
  const projectRoot = findProjectRoot()
46
62
  if (!projectRoot) {
@@ -56,34 +72,22 @@ if (command === 'init-config') {
56
72
  stores: './src/backend/stores',
57
73
  services: './src/backend/services',
58
74
  providers: './src/backend/providers',
59
- controllers: './src/backend/controllers'
75
+ controllers: './src/backend/controllers',
76
+ entities: './src/shared/entities',
77
+ queries: './src/client/shared/queries'
60
78
  },
61
79
  dependencyInjection: 'inversifyjs'
62
80
  }, null, '\t'))
63
81
  }
64
82
 
65
- process.exit(0);
66
83
  }
67
84
 
68
- function camelizeVariants(str) {
69
- const words = str.split("-");
70
-
71
- const lowerCamel = words
72
- .map((word, index) =>
73
- index === 0 ? word.toLowerCase() : word[0].toUpperCase() + word.slice(1).toLowerCase()
74
- )
75
- .join("");
76
-
77
- const upperCamel = words
78
- .map(word => word[0].toUpperCase() + word.slice(1).toLowerCase())
79
- .join("");
80
-
81
- return [lowerCamel, upperCamel];
85
+ if (command === 'init-config') {
86
+ createDefaultConfig()
87
+ process.exit(0)
82
88
  }
83
89
 
84
- var [lowerCase, upperCase] = camelizeVariants(entityName)
85
-
86
- if (command === 'store') {
90
+ function generateStores(lowerCase, upperCase) {
87
91
  const folder = config?.paths?.stores ? path.resolve(process.cwd(), config?.paths?.stores, entityName) : path.resolve(process.cwd(), entityName);
88
92
 
89
93
  fs.mkdirSync(folder, { recursive: true })
@@ -246,5 +250,12 @@ if (command === 'store') {
246
250
  `export * from './${entityName}.store.prisma.ts'`,
247
251
  `export * from './${entityName}.store.ram.ts'`
248
252
  ].join('\n'))
253
+
254
+ }
255
+
256
+ if (command === 'store') {
257
+ var [lowerCase, upperCase] = camelizeVariants(entityName)
258
+ generateStores(lowerCase, upperCase)
259
+ process.exit(0);
249
260
  }
250
261
 
package/dist/index.cjs CHANGED
@@ -35,7 +35,12 @@ __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
- zodModuleMethodFactory: ()=>zodModuleMethodFactory
38
+ Module: ()=>zod_module_utils_namespaceObject
39
+ });
40
+ var zod_module_utils_namespaceObject = {};
41
+ __webpack_require__.r(zod_module_utils_namespaceObject);
42
+ __webpack_require__.d(zod_module_utils_namespaceObject, {
43
+ methods: ()=>methods
39
44
  });
40
45
  var zod_controller_utils_namespaceObject = {};
41
46
  __webpack_require__.r(zod_controller_utils_namespaceObject);
@@ -47,7 +52,7 @@ var store_namespaceObject = {};
47
52
  __webpack_require__.r(store_namespaceObject);
48
53
  __webpack_require__.d(store_namespaceObject, {
49
54
  InRAM: ()=>InRAM,
50
- methods: ()=>methods
55
+ methods: ()=>store_zod_utils_methods
51
56
  });
52
57
  class ErrorFactory {
53
58
  static isControllerError = (error)=>{
@@ -142,7 +147,7 @@ class ErrorFactory {
142
147
  });
143
148
  };
144
149
  }
145
- const zodModuleMethodFactory = (metadata, sharedConfig = {})=>(methodName, handler, config = {})=>{
150
+ const methods = (metadata, sharedConfig = {})=>(methodName, handler, config = {})=>{
146
151
  const { name, schemas } = metadata;
147
152
  return async (payload)=>{
148
153
  try {
@@ -414,14 +419,14 @@ const mapStoreSchemasToModuleMetadata = (schemas, name)=>({
414
419
  }
415
420
  }
416
421
  });
417
- const methods = (schemas)=>{
422
+ const store_zod_utils_methods = (schemas)=>{
418
423
  const data = mapStoreSchemasToModuleMetadata(schemas, schemas.name);
419
- return zodModuleMethodFactory(data);
424
+ return methods(data);
420
425
  };
421
426
  const InRAM = (schemas, options)=>{
422
427
  class RAMStore {
423
428
  ___data = [];
424
- method = methods(schemas);
429
+ method = store_zod_utils_methods(schemas);
425
430
  ___listSearchLogic = (entity, pattern)=>{
426
431
  const patternKeys = Object.entries(pattern).filter(([_, value])=>!!value).map((x)=>x[0]);
427
432
  const entityAsObject = entity;
@@ -501,12 +506,12 @@ const InRAM = (schemas, options)=>{
501
506
  return RAMStore;
502
507
  };
503
508
  exports.Controller = __webpack_exports__.Controller;
509
+ exports.Module = __webpack_exports__.Module;
504
510
  exports.Store = __webpack_exports__.Store;
505
- exports.zodModuleMethodFactory = __webpack_exports__.zodModuleMethodFactory;
506
511
  for(var __rspack_i in __webpack_exports__)if (-1 === [
507
512
  "Controller",
508
- "Store",
509
- "zodModuleMethodFactory"
513
+ "Module",
514
+ "Store"
510
515
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
511
516
  Object.defineProperty(exports, '__esModule', {
512
517
  value: true
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { zodModuleMethodFactory } from './zod-module.utils';
1
+ export * as Module from './zod-module.utils';
2
2
  export * as Controller from './zod-controller.utils';
3
3
  export * as Store from './store';
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ var store_namespaceObject = {};
5
5
  __webpack_require__.r(store_namespaceObject);
6
6
  __webpack_require__.d(store_namespaceObject, {
7
7
  InRAM: ()=>InRAM,
8
- methods: ()=>methods
8
+ methods: ()=>store_zod_utils_methods
9
9
  });
10
10
  var zod_controller_utils_namespaceObject = {};
11
11
  __webpack_require__.r(zod_controller_utils_namespaceObject);
@@ -13,6 +13,11 @@ __webpack_require__.d(zod_controller_utils_namespaceObject, {
13
13
  DefaultErrorCodes: ()=>zod_controller_utils_DefaultErrorCodes,
14
14
  endpoints: ()=>endpoints
15
15
  });
16
+ var zod_module_utils_namespaceObject = {};
17
+ __webpack_require__.r(zod_module_utils_namespaceObject);
18
+ __webpack_require__.d(zod_module_utils_namespaceObject, {
19
+ methods: ()=>methods
20
+ });
16
21
  class ErrorFactory {
17
22
  static isControllerError = (error)=>{
18
23
  if (!error || 'object' != typeof error) return false;
@@ -106,7 +111,7 @@ class ErrorFactory {
106
111
  });
107
112
  };
108
113
  }
109
- const zodModuleMethodFactory = (metadata, sharedConfig = {})=>(methodName, handler, config = {})=>{
114
+ const methods = (metadata, sharedConfig = {})=>(methodName, handler, config = {})=>{
110
115
  const { name, schemas } = metadata;
111
116
  return async (payload)=>{
112
117
  try {
@@ -375,14 +380,14 @@ const mapStoreSchemasToModuleMetadata = (schemas, name)=>({
375
380
  }
376
381
  }
377
382
  });
378
- const methods = (schemas)=>{
383
+ const store_zod_utils_methods = (schemas)=>{
379
384
  const data = mapStoreSchemasToModuleMetadata(schemas, schemas.name);
380
- return zodModuleMethodFactory(data);
385
+ return methods(data);
381
386
  };
382
387
  const InRAM = (schemas, options)=>{
383
388
  class RAMStore {
384
389
  ___data = [];
385
- method = methods(schemas);
390
+ method = store_zod_utils_methods(schemas);
386
391
  ___listSearchLogic = (entity, pattern)=>{
387
392
  const patternKeys = Object.entries(pattern).filter(([_, value])=>!!value).map((x)=>x[0]);
388
393
  const entityAsObject = entity;
@@ -461,4 +466,4 @@ const InRAM = (schemas, options)=>{
461
466
  }
462
467
  return RAMStore;
463
468
  };
464
- export { store_namespaceObject as Store, zodModuleMethodFactory, zod_controller_utils_namespaceObject as Controller };
469
+ export { store_namespaceObject as Store, zod_controller_utils_namespaceObject as Controller, zod_module_utils_namespaceObject as Module };
@@ -364,7 +364,7 @@ export declare const InRAM: <T extends Metadata>(schemas: T, options?: {
364
364
  success: z.ZodBoolean;
365
365
  }, z.core.$strip>;
366
366
  };
367
- })[Method]["response"]>>, config?: import("../zod-module.utils").ZodModuleConfig) => (payload: z.core.output<(Record<Exclude<keyof (T["customOperations"] extends Record<string, {
367
+ })[Method]["response"]>>, config?: import("../zod-module.utils").Config) => (payload: z.core.output<(Record<Exclude<keyof (T["customOperations"] extends Record<string, {
368
368
  payload: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
369
369
  response: z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>;
370
370
  }> ? { [operation in keyof T["customOperations"]]: {
@@ -261,7 +261,7 @@ export declare const methods: <T extends Metadata>(schemas: T) => <Method extend
261
261
  success: ZodBoolean;
262
262
  }, z.core.$strip>;
263
263
  };
264
- })[Method]["response"]>>, config?: import("../zod-module.utils").ZodModuleConfig) => (payload: z.core.output<(Record<Exclude<keyof (T["customOperations"] extends Record<string, {
264
+ })[Method]["response"]>>, config?: import("../zod-module.utils").Config) => (payload: z.core.output<(Record<Exclude<keyof (T["customOperations"] extends Record<string, {
265
265
  payload: ZodSchema;
266
266
  response: ZodSchema;
267
267
  }> ? { [operation in keyof T["customOperations"]]: {
@@ -12,8 +12,8 @@ type ZodAPISchemas = {
12
12
  response?: ZodObject;
13
13
  };
14
14
  type ErrorResponse = {
15
- message: string;
16
- code?: string;
15
+ code: string;
16
+ message?: string;
17
17
  details?: any;
18
18
  };
19
19
  type EndpointErrorGenerator = (payload: string | ErrorBaseCreatingPayload, errorStatus?: number, cause?: unknown) => ControllerErrorModel;
@@ -17,13 +17,13 @@ export type DTOs<T extends Metadata> = {
17
17
  export type Methods<T extends Metadata> = {
18
18
  [K in keyof T['schemas']]: (payload: z.infer<T['schemas'][K]['payload']>) => Promise<z.infer<T['schemas'][K]['response']>>;
19
19
  };
20
- export type ZodModuleConfig = {
20
+ export type Config = {
21
21
  onError?: (e: ModuleErrorModel) => Promise<void>;
22
22
  };
23
- export declare const zodModuleMethodFactory: <T extends Schemas>(metadata: {
23
+ export declare const methods: <T extends Schemas>(metadata: {
24
24
  schemas: T;
25
25
  name: string;
26
- }, sharedConfig?: ZodModuleConfig) => <Method extends keyof T>(methodName: Method, handler: (payload: z.infer<T[Method]["payload"]>, config: {
26
+ }, sharedConfig?: Config) => <Method extends keyof T>(methodName: Method, handler: (payload: z.infer<T[Method]["payload"]>, config: {
27
27
  methodError: (payload: string | ErrorBaseCreatingPayload, cause?: unknown) => ModuleErrorModel;
28
- }) => Promise<z.infer<T[Method]["response"]>>, config?: ZodModuleConfig) => (payload: z.infer<T[Method]["payload"]>) => Promise<z.infer<T[Method]["response"]>>;
28
+ }) => Promise<z.infer<T[Method]["response"]>>, config?: Config) => (payload: z.infer<T[Method]["payload"]>) => Promise<z.infer<T[Method]["response"]>>;
29
29
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alevnyacow/nzmt",
3
- "version": "0.0.19",
3
+ "version": "0.0.21",
4
4
  "description": "Next Zod Modules Toolkit",
5
5
  "type": "module",
6
6
  "exports": {