hh-contracts 0.0.4 → 0.0.6

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.
@@ -4,4 +4,8 @@ exports.IconKeys = void 0;
4
4
  exports.IconKeys = {
5
5
  EyeIcon: 'EyeIcon',
6
6
  EyeSlashIcon: 'EyeSlashIcon',
7
+ ChevronRightIcon: 'ChevronRightIcon',
8
+ LogoIcon: 'LogoIcon',
9
+ HousekeepingIcon: 'HousekeepingIcon',
10
+ Bars3CenterLeftIcon: 'Bars3CenterLeftIcon',
7
11
  };
@@ -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.NavigationItemSchema),
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,5 @@ 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);
22
+ __exportStar(require("./types"), 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,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NavigationItemSchema = 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(),
19
+ createdAt: zod_1.z.date(),
20
+ updatedAt: zod_1.z.date(),
18
21
  });
19
- exports.NavigationItemEntityWithChildrenSchema = NavigationItemEntitySchema.extend({
20
- children: zod_1.z.array(NavigationItemEntitySchema).optional(),
22
+ exports.NavigationItemEntitySchema = exports.NavigationItemEntityBaseSchema.extend({
23
+ children: zod_1.z.lazy(() => zod_1.z.array(exports.NavigationItemEntitySchema).optional()),
21
24
  });
22
- exports.NavigationItemSchema = 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
+ }));
@@ -0,0 +1,18 @@
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);
18
+ __exportStar(require("./optionalized.type"), exports);
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,6 +1,10 @@
1
1
  export const IconKeys = {
2
2
  EyeIcon: 'EyeIcon',
3
3
  EyeSlashIcon: 'EyeSlashIcon',
4
+ ChevronRightIcon: 'ChevronRightIcon',
5
+ LogoIcon: 'LogoIcon',
6
+ HousekeepingIcon: 'HousekeepingIcon',
7
+ Bars3CenterLeftIcon: 'Bars3CenterLeftIcon',
4
8
  } as const;
5
9
 
6
10
  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 { NavigationItemSchema } 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(NavigationItemSchema),
8
+ appMenu: z.array(NavigationItem),
9
9
  });
10
10
 
11
11
  export namespace GetAppMenuQuery {
package/index.ts CHANGED
@@ -2,3 +2,5 @@
2
2
  export * from './dto';
3
3
  export * from './constants';
4
4
  export * from './models';
5
+ export * from './transforms';
6
+ export * from './types';
@@ -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,31 +1,29 @@
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
- export const NavigationItemEntityWithChildrenSchema = NavigationItemEntitySchema.extend({
19
- children: z.array(NavigationItemEntitySchema).optional(),
18
+ createdAt: z.date(),
19
+ updatedAt: z.date(),
20
20
  });
21
21
 
22
- export const NavigationItemSchema = 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 TNavigationItemEntityWithChildren = z.infer<
29
- typeof NavigationItemEntityWithChildrenSchema
30
- >;
31
- export type TNavigationItem = z.infer<typeof NavigationItemSchema>;
22
+ export type TNavigationItemEntityBase = z.infer<typeof NavigationItemEntityBaseSchema>;
23
+ export type TNavigationItemEntity = TNavigationItemEntityBase & {
24
+ children?: TNavigationItemEntity[];
25
+ };
26
+ export const NavigationItemEntitySchema: z.ZodType<TNavigationItemEntity> =
27
+ NavigationItemEntityBaseSchema.extend({
28
+ children: z.lazy(() => z.array(NavigationItemEntitySchema).optional()),
29
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hh-contracts",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1 @@
1
+ export * from './navigation-item.transform';
@@ -0,0 +1,39 @@
1
+ import { z } from 'zod';
2
+ import { NavigationItemEntityBaseSchema, NavigationItemEntitySchema } from '../models';
3
+ import { TDeepOptionalize } from '../types';
4
+
5
+ const NavigationItemBase = NavigationItemEntityBaseSchema.transform(
6
+ ({
7
+ parentId,
8
+ description,
9
+ iconKey,
10
+ link,
11
+ routeComponentKey,
12
+ type,
13
+ disabled,
14
+ order,
15
+ ...rest
16
+ }) => ({
17
+ ...rest,
18
+ description: description || undefined,
19
+ iconKey: iconKey || undefined,
20
+ link: link || undefined,
21
+ routeComponentKey: routeComponentKey || undefined,
22
+ disabled: disabled === null ? undefined : disabled,
23
+ }),
24
+ );
25
+
26
+ type TInput = z.input<typeof NavigationItemEntityBaseSchema> & {
27
+ children?: TInput[];
28
+ };
29
+ type TOutput = z.output<typeof NavigationItemBase> & {
30
+ children?: TOutput[];
31
+ };
32
+
33
+ export const NavigationItem: z.ZodType<TOutput, z.ZodTypeDef, TInput> = z.lazy(() =>
34
+ NavigationItemEntitySchema.transform(({ children, ...rest }) => ({
35
+ ...NavigationItemBase.parse(rest),
36
+ children: children?.length ? children.map(child => NavigationItem.parse(child)) : undefined,
37
+ })),
38
+ );
39
+ export type TNavigationItem = TDeepOptionalize<z.infer<typeof NavigationItem>>;
package/types/index.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './zod.type';
2
+ export * from './optionalized.type';
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Utility type that converts properties of T that include undefined to optional properties.
3
+ *
4
+ * Для каждого ключа K, если undefined расширяет T[K] (то есть T[K] содержит undefined),
5
+ * то в результирующем типе свойство K становится опциональным, а его тип – Exclude<T[K], undefined>.
6
+ */
7
+ export type TOptionalize<T> = {
8
+ [K in keyof T as undefined extends T[K] ? K : never]?: T[K];
9
+ } & {
10
+ [K in keyof T as undefined extends T[K] ? never : K]: T[K];
11
+ };
12
+
13
+ /**
14
+ * Helper type to merge intersections into a single object type.
15
+ */
16
+ export type TMerge<T> = { [K in keyof T]: T[K] };
17
+
18
+ /**
19
+ * Итоговый утилитарный тип, который превращает свойства с undefined в опциональные.
20
+ */
21
+ export type TOptionalized<T> = TMerge<TOptionalize<T>>;
22
+
23
+ /**
24
+ * DeepOptionalize: Рекурсивно применяет Optionalize ко всем вложенным объектам и массивам.
25
+ */
26
+ export type TDeepOptionalize<T> = T extends Date | null
27
+ ? T
28
+ : T extends Array<infer U>
29
+ ? Array<TDeepOptionalize<U>>
30
+ : T extends object
31
+ ? TMerge<
32
+ {
33
+ // Если свойство не допускает undefined, оставляем его обязательным
34
+ [K in keyof T as undefined extends T[K] ? never : K]: TDeepOptionalize<T[K]>;
35
+ } & {
36
+ // Если свойство допускает undefined, делаем его опциональным
37
+ [K in keyof T as undefined extends T[K] ? K : never]?: TDeepOptionalize<T[K]>;
38
+ }
39
+ >
40
+ : T;
@@ -0,0 +1,2 @@
1
+ import { input, ZodType, ZodTypeAny, ZodTypeDef } from 'zod';
2
+ export type TZodType<T> = ZodType<T, ZodTypeDef, input<ZodTypeAny>>;