hh-contracts 0.0.3 → 0.0.5

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.
@@ -0,0 +1 @@
1
+ export * from './zod.type';
@@ -0,0 +1,2 @@
1
+ import { input, ZodType, ZodTypeAny, ZodTypeDef } from 'zod';
2
+ export type TZodType<T> = ZodType<T, ZodTypeDef, input<ZodTypeAny>>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./zod.type"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -4,4 +4,5 @@ exports.IconKeys = void 0;
4
4
  exports.IconKeys = {
5
5
  EyeIcon: 'EyeIcon',
6
6
  EyeSlashIcon: 'EyeSlashIcon',
7
+ ChevronRightIcon: 'ChevronRightIcon',
7
8
  };
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NavigationItemTypes = void 0;
4
4
  exports.NavigationItemTypes = {
5
- section: 'section',
6
5
  group: 'group',
7
6
  link: 'link',
8
7
  };
@@ -2,12 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GetAppMenuQuery = void 0;
4
4
  const zod_1 = require("zod");
5
- const models_1 = require("../../models");
5
+ const transforms_1 = require("../../transforms");
6
6
  const GetAppMenuQueryRequestSchema = zod_1.z.object({
7
7
  userUuid: zod_1.z.string().uuid(),
8
8
  });
9
9
  const GetAppMenuQueryResponseSchema = zod_1.z.object({
10
- appMenu: zod_1.z.array(models_1.NavigationBaseSchema),
10
+ appMenu: zod_1.z.array(transforms_1.NavigationItem),
11
11
  });
12
12
  var GetAppMenuQuery;
13
13
  (function (GetAppMenuQuery) {
package/build/index.js CHANGED
@@ -18,3 +18,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  __exportStar(require("./dto"), exports);
19
19
  __exportStar(require("./constants"), exports);
20
20
  __exportStar(require("./models"), exports);
21
+ __exportStar(require("./transforms"), exports);
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IconKeySchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const constants_1 = require("../constants");
6
+ exports.IconKeySchema = zod_1.z.nativeEnum(constants_1.IconKeys);
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InfoSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const icon_key_schema_1 = require("./icon-key.schema");
6
+ exports.InfoSchema = zod_1.z.object({
7
+ iconKey: icon_key_schema_1.IconKeySchema.optional(),
8
+ title: zod_1.z.string().min(1),
9
+ description: zod_1.z.string().min(1),
10
+ });
@@ -1,25 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NavigationBaseSchema = exports.NavigationItemEntityWithChildrenSchema = void 0;
3
+ exports.NavigationItemEntitySchema = exports.NavigationItemEntityBaseSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const constants_1 = require("../constants");
6
6
  const constants_2 = require("../constants");
7
- const NavigationItemEntitySchema = zod_1.z.object({
7
+ const icon_key_schema_1 = require("./icon-key.schema");
8
+ exports.NavigationItemEntityBaseSchema = zod_1.z.object({
8
9
  id: zod_1.z.number().int().positive(),
9
10
  parentId: zod_1.z.nullable(zod_1.z.number().int().positive()),
10
11
  label: zod_1.z.string().min(1),
11
12
  description: zod_1.z.nullable(zod_1.z.string().min(1)),
12
- iconKey: zod_1.z.nullable(zod_1.z.nativeEnum(constants_1.IconKeys)),
13
+ iconKey: zod_1.z.nullable(icon_key_schema_1.IconKeySchema),
13
14
  link: zod_1.z.nullable(zod_1.z.string().min(1)),
14
15
  routeComponentKey: zod_1.z.nullable(zod_1.z.nativeEnum(constants_1.RouteComponentKeys)),
15
16
  type: zod_1.z.nativeEnum(constants_2.NavigationItemTypes),
16
- disabled: zod_1.z.boolean().default(false),
17
+ disabled: zod_1.z.boolean(),
17
18
  order: zod_1.z.number().int().positive(),
18
19
  });
19
- exports.NavigationItemEntityWithChildrenSchema = NavigationItemEntitySchema.extend({
20
- children: zod_1.z.array(NavigationItemEntitySchema).optional(),
20
+ exports.NavigationItemEntitySchema = exports.NavigationItemEntityBaseSchema.extend({
21
+ children: zod_1.z.lazy(() => zod_1.z.array(exports.NavigationItemEntitySchema).optional()),
21
22
  });
22
- exports.NavigationBaseSchema = exports.NavigationItemEntityWithChildrenSchema.omit({
23
- parentId: true,
24
- order: true,
25
- }).partial({ description: true, link: true, iconKey: true, routeComponentKey: true });
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./navigation-item.transform"), exports);
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.NavigationItem = void 0;
15
+ const zod_1 = require("zod");
16
+ const models_1 = require("../models");
17
+ const NavigationItemBase = models_1.NavigationItemEntityBaseSchema.transform((_a) => {
18
+ var { parentId, description, iconKey, link, routeComponentKey, type, disabled, order } = _a, rest = __rest(_a, ["parentId", "description", "iconKey", "link", "routeComponentKey", "type", "disabled", "order"]);
19
+ return (Object.assign(Object.assign({}, rest), { description: description || undefined, iconKey: iconKey || undefined, link: link || undefined, routeComponentKey: routeComponentKey || undefined, disabled: disabled === null ? undefined : disabled }));
20
+ });
21
+ exports.NavigationItem = zod_1.z.lazy(() => models_1.NavigationItemEntitySchema.transform((_a) => {
22
+ var { children } = _a, rest = __rest(_a, ["children"]);
23
+ return (Object.assign(Object.assign({}, NavigationItemBase.parse(rest)), { children: (children === null || children === void 0 ? void 0 : children.length) ? children.map(child => exports.NavigationItem.parse(child)) : undefined }));
24
+ }));
@@ -1,6 +1,7 @@
1
1
  export const IconKeys = {
2
2
  EyeIcon: 'EyeIcon',
3
3
  EyeSlashIcon: 'EyeSlashIcon',
4
+ ChevronRightIcon: 'ChevronRightIcon',
4
5
  } as const;
5
6
 
6
7
  export type TIconKey = (typeof IconKeys)[keyof typeof IconKeys];
@@ -1,5 +1,4 @@
1
1
  export const NavigationItemTypes = {
2
- section: 'section',
3
2
  group: 'group',
4
3
  link: 'link',
5
4
  } as const;
@@ -1,11 +1,11 @@
1
1
  import { z } from 'zod';
2
- import { NavigationBaseSchema } from '../../models';
2
+ import { NavigationItem } from '../../transforms';
3
3
 
4
4
  const GetAppMenuQueryRequestSchema = z.object({
5
5
  userUuid: z.string().uuid(),
6
6
  });
7
7
  const GetAppMenuQueryResponseSchema = z.object({
8
- appMenu: z.array(NavigationBaseSchema),
8
+ appMenu: z.array(NavigationItem),
9
9
  });
10
10
 
11
11
  export namespace GetAppMenuQuery {
package/index.ts CHANGED
@@ -2,3 +2,4 @@
2
2
  export * from './dto';
3
3
  export * from './constants';
4
4
  export * from './models';
5
+ export * from './transforms';
@@ -0,0 +1,4 @@
1
+ import { z } from 'zod';
2
+ import { IconKeys } from '../constants';
3
+
4
+ export const IconKeySchema = z.nativeEnum(IconKeys);
@@ -0,0 +1,8 @@
1
+ import { z } from 'zod';
2
+ import { IconKeySchema } from './icon-key.schema';
3
+
4
+ export const InfoSchema = z.object({
5
+ iconKey: IconKeySchema.optional(),
6
+ title: z.string().min(1),
7
+ description: z.string().min(1),
8
+ });
@@ -1,29 +1,26 @@
1
1
  import { z } from 'zod';
2
- import { IconKeys, RouteComponentKeys } from '../constants';
2
+ import { RouteComponentKeys } from '../constants';
3
3
  import { NavigationItemTypes } from '../constants';
4
+ import { IconKeySchema } from './icon-key.schema';
4
5
 
5
- const NavigationItemEntitySchema = z.object({
6
+ export const NavigationItemEntityBaseSchema = z.object({
6
7
  id: z.number().int().positive(),
7
8
  parentId: z.nullable(z.number().int().positive()),
8
9
  label: z.string().min(1),
9
10
  description: z.nullable(z.string().min(1)),
10
- iconKey: z.nullable(z.nativeEnum(IconKeys)),
11
+ iconKey: z.nullable(IconKeySchema),
11
12
  link: z.nullable(z.string().min(1)),
12
13
  routeComponentKey: z.nullable(z.nativeEnum(RouteComponentKeys)),
13
14
  type: z.nativeEnum(NavigationItemTypes),
14
- disabled: z.boolean().default(false),
15
+ disabled: z.boolean(),
15
16
  order: z.number().int().positive(),
16
17
  });
17
18
 
18
- export const NavigationItemEntityWithChildrenSchema = NavigationItemEntitySchema.extend({
19
- children: z.array(NavigationItemEntitySchema).optional(),
20
- });
21
-
22
- export const NavigationBaseSchema = NavigationItemEntityWithChildrenSchema.omit({
23
- parentId: true,
24
- order: true,
25
- }).partial({ description: true, link: true, iconKey: true, routeComponentKey: true });
26
-
27
- export type TNavigationItemEntity = z.infer<typeof NavigationItemEntitySchema>;
28
- export type TNavigationItemWithChildren = z.infer<typeof NavigationItemEntityWithChildrenSchema>;
29
- export type TNavigationBase = z.infer<typeof NavigationBaseSchema>;
19
+ export type TNavigationItemEntityBase = z.infer<typeof NavigationItemEntityBaseSchema>;
20
+ export type TNavigationItemEntity = TNavigationItemEntityBase & {
21
+ children?: TNavigationItemEntity[];
22
+ };
23
+ export const NavigationItemEntitySchema: z.ZodType<TNavigationItemEntity> =
24
+ NavigationItemEntityBaseSchema.extend({
25
+ children: z.lazy(() => z.array(NavigationItemEntitySchema).optional()),
26
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hh-contracts",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1 @@
1
+ export * from './navigation-item.transform';
@@ -0,0 +1,38 @@
1
+ import { z } from 'zod';
2
+ import { NavigationItemEntityBaseSchema, NavigationItemEntitySchema } from '../models';
3
+
4
+ const NavigationItemBase = NavigationItemEntityBaseSchema.transform(
5
+ ({
6
+ parentId,
7
+ description,
8
+ iconKey,
9
+ link,
10
+ routeComponentKey,
11
+ type,
12
+ disabled,
13
+ order,
14
+ ...rest
15
+ }) => ({
16
+ ...rest,
17
+ description: description || undefined,
18
+ iconKey: iconKey || undefined,
19
+ link: link || undefined,
20
+ routeComponentKey: routeComponentKey || undefined,
21
+ disabled: disabled === null ? undefined : disabled,
22
+ }),
23
+ );
24
+
25
+ type TInput = z.input<typeof NavigationItemEntityBaseSchema> & {
26
+ children?: TInput[];
27
+ };
28
+ type TOutput = z.output<typeof NavigationItemBase> & {
29
+ children?: TOutput[];
30
+ };
31
+ export type TNavigationItem = z.ZodType<TOutput, z.ZodTypeDef, TInput>;
32
+
33
+ export const NavigationItem: TNavigationItem = z.lazy(() =>
34
+ NavigationItemEntitySchema.transform(({ children, ...rest }) => ({
35
+ ...NavigationItemBase.parse(rest),
36
+ children: children?.length ? children.map(child => NavigationItem.parse(child)) : undefined,
37
+ })),
38
+ );