@alevnyacow/nzmt 0.10.1 → 0.11.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/bin/cli.js CHANGED
@@ -388,7 +388,7 @@ function generateStores(lowerCase, upperCase, withEntityPreset) {
388
388
 
389
389
  fs.mkdirSync(folder, { recursive: true })
390
390
 
391
- const withEntity = withEntityPreset || !(options ?? []).includes('dont-import-entity')
391
+ const withEntity = withEntityPreset || (options ?? []).includes('import-entity')
392
392
 
393
393
  // Contract
394
394
 
@@ -743,10 +743,10 @@ function toKebabFromPascal(str) {
743
743
  .toLowerCase()
744
744
  }
745
745
 
746
- function generateService(lowerCase, upperCase) {
746
+ function generateService(lowerCase, upperCase, store) {
747
747
  const folder = config?.paths?.services ? path.resolve(process.cwd(), `${config.coreFolder}${config?.paths?.services}`, entityName) : path.resolve(process.cwd(), entityName);
748
748
 
749
- const proxiedStore = options.find(x => x.startsWith('p:'))?.split(':')?.at(-1)
749
+ const proxiedStore = store || options.find(x => x.startsWith('p:'))?.split(':')?.at(-1)
750
750
  if (proxiedStore && !proxiedStore.endsWith('Store')) {
751
751
  throw 'Only stores can be proxied in services!'
752
752
  }
@@ -933,4 +933,18 @@ if (command.toLowerCase() === 'controller' || command === 'c') {
933
933
  var [lowerCase, upperCase] = camelizeVariants(entityName)
934
934
  generateController(upperCase, lowerCase)
935
935
  process.exit(0)
936
- }
936
+ }
937
+
938
+ if (command.toLowerCase() === 'stored-entity' || command === 'se') {
939
+ var [lowerCase, upperCase] = camelizeVariants(entityName)
940
+ generateEntity(upperCase)
941
+ generateStores(lowerCase, upperCase, true)
942
+ process.exit(0)
943
+ }
944
+
945
+ if (command.toLowerCase() === 'crud-service') {
946
+ var [lowerCase, upperCase] = camelizeVariants(entityName)
947
+ generateEntity(upperCase)
948
+ generateStores(lowerCase, upperCase, true)
949
+ generateService(lowerCase, upperCase, upperCase + 'Store')
950
+ }
@@ -1,5 +1,5 @@
1
1
  import { type NextRequest, NextResponse } from 'next/server';
2
- import z, { ZodType, type ZodObject } from 'zod';
2
+ import z, { type ZodType, type ZodObject, type ZodUnion } from 'zod';
3
3
  import { type ControllerErrorModel, type ErrorBaseCreatingPayload } from './errors.utils';
4
4
  export declare enum DefaultErrorCodes {
5
5
  REQUEST_PARSING = "ZOD-CONTROLLER___REQUEST-PARSING",
@@ -7,8 +7,8 @@ export declare enum DefaultErrorCodes {
7
7
  }
8
8
  type SuccessResponse<ResponseZodSchema> = ResponseZodSchema extends undefined ? {} : z.infer<ResponseZodSchema>;
9
9
  type ZodAPISchemas = {
10
- body?: ZodObject;
11
- query?: ZodObject;
10
+ body?: ZodObject | ZodUnion<[ZodObject<any>, ...ZodObject<any>[]]>;
11
+ query?: ZodObject | ZodUnion<[ZodObject<any>, ...ZodObject<any>[]]>;
12
12
  response?: ZodType;
13
13
  };
14
14
  type ErrorResponse = {
@@ -26,7 +26,7 @@ export type OnErrorHandler = (request: {
26
26
  req: NextRequest;
27
27
  }) => Promise<void>;
28
28
  type EndpointLogic<T extends ZodAPISchemas> = {
29
- handler: (payload: (T['query'] extends ZodObject ? z.infer<T['query']> : {}) & (T['body'] extends ZodObject ? z.infer<T['body']> : {}), request: {
29
+ handler: (payload: (T['query'] extends ZodType ? z.infer<T['query']> : {}) & (T['body'] extends ZodType ? z.infer<T['body']> : {}), request: {
30
30
  request: NextRequest;
31
31
  flags: Record<string, boolean>;
32
32
  endpointError: EndpointErrorGenerator;
@@ -34,9 +34,9 @@ type EndpointLogic<T extends ZodAPISchemas> = {
34
34
  guards?: Guard[];
35
35
  eventHandlers?: {
36
36
  onSuccess?: Array<(data: {
37
- requestPayload: (T['query'] extends ZodObject ? z.infer<T['query']> : {}) & (T['body'] extends ZodObject ? z.infer<T['body']> : {});
37
+ requestPayload: (T['query'] extends ZodType ? z.infer<T['query']> : {}) & (T['body'] extends ZodType ? z.infer<T['body']> : {});
38
38
  request: NextRequest;
39
- result: T['response'] extends ZodObject ? z.infer<T['response']> : undefined;
39
+ result: T['response'] extends ZodType ? z.infer<T['response']> : undefined;
40
40
  flags: Record<string, boolean>;
41
41
  }) => Promise<void>>;
42
42
  onError?: Array<OnErrorHandler>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alevnyacow/nzmt",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "Next Zod Modules Toolkit",
5
5
  "repository": {
6
6
  "type": "git",