hh-contracts 0.0.33 → 0.0.34

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,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LANGUAGE_VALUES = exports.LANGUAGE = void 0;
4
+ exports.LANGUAGE = {
5
+ ru: 'ru',
6
+ en: 'en',
7
+ };
8
+ exports.LANGUAGE_VALUES = Object.values(exports.LANGUAGE);
@@ -15,10 +15,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./app-ability.constant"), exports);
18
+ __exportStar(require("./app-error.constant"), exports);
19
+ __exportStar(require("./app-languge.constant"), exports);
18
20
  __exportStar(require("./default-pagination-config.constant"), exports);
19
21
  __exportStar(require("./http-method.constant"), exports);
20
22
  __exportStar(require("./icon-key.constant"), exports);
21
23
  __exportStar(require("./navigation-item-type.constant"), exports);
22
24
  __exportStar(require("./order-direction.constant"), exports);
23
25
  __exportStar(require("./route-component-key.constants"), exports);
24
- __exportStar(require("./app-error.constant"), exports);
@@ -23,3 +23,4 @@ __exportStar(require("./order.schema"), exports);
23
23
  __exportStar(require("./pagination.schema"), exports);
24
24
  __exportStar(require("./search.schema"), exports);
25
25
  __exportStar(require("./timestamp.schemas"), exports);
26
+ __exportStar(require("./language-values.schema"), exports);
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LanguageValuesSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ const constants_1 = require("../constants");
6
+ exports.LanguageValuesSchema = zod_1.z.enum(constants_1.LANGUAGE_VALUES);
@@ -6,11 +6,11 @@ const common_1 = require("../common");
6
6
  exports.PermissionSchema = zod_1.z
7
7
  .object({
8
8
  id: zod_1.z.number({ invalid_type_error: 'idInvalid' }).positive({ message: 'idMustBePositive' }),
9
- name: zod_1.z
10
- .string({ required_error: 'nameRequired' })
11
- .trim()
12
- .min(1, { message: 'nameRequired' })
13
- .max(50, { message: 'nameTooLong' }),
9
+ name_i18n: zod_1.z
10
+ .record(common_1.LanguageValuesSchema, zod_1.z.string().transform(s => s.trim()))
11
+ .refine(val => Object.values(val).some(str => str.length > 0), {
12
+ message: 'atLeastOneTranslationRequired',
13
+ }),
14
14
  action: zod_1.z.nativeEnum(common_1.AppAbility.ACTION, {
15
15
  invalid_type_error: 'actionInvalid',
16
16
  required_error: 'actionRequired',
@@ -0,0 +1,7 @@
1
+ export const LANGUAGE = {
2
+ ru: 'ru',
3
+ en: 'en',
4
+ } as const;
5
+ export type TLanguage = (typeof LANGUAGE)[keyof typeof LANGUAGE];
6
+
7
+ export const LANGUAGE_VALUES = Object.values(LANGUAGE) as [TLanguage, ...TLanguage[]];
@@ -1,8 +1,9 @@
1
1
  export * from './app-ability.constant';
2
+ export * from './app-error.constant';
3
+ export * from './app-languge.constant';
2
4
  export * from './default-pagination-config.constant';
3
5
  export * from './http-method.constant';
4
6
  export * from './icon-key.constant';
5
7
  export * from './navigation-item-type.constant';
6
8
  export * from './order-direction.constant';
7
9
  export * from './route-component-key.constants';
8
- export * from './app-error.constant';
@@ -7,3 +7,4 @@ export * from './order.schema';
7
7
  export * from './pagination.schema';
8
8
  export * from './search.schema';
9
9
  export * from './timestamp.schemas';
10
+ export * from './language-values.schema';
@@ -0,0 +1,4 @@
1
+ import { z } from 'zod';
2
+ import { LANGUAGE_VALUES } from '../constants';
3
+
4
+ export const LanguageValuesSchema = z.enum(LANGUAGE_VALUES);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hh-contracts",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {
@@ -1,14 +1,17 @@
1
1
  import { z } from 'zod';
2
- import { AppAbility, TimestampSchema } from '../common';
2
+ import { AppAbility, LanguageValuesSchema, TimestampSchema } from '../common';
3
3
 
4
4
  export const PermissionSchema = z
5
5
  .object({
6
6
  id: z.number({ invalid_type_error: 'idInvalid' }).positive({ message: 'idMustBePositive' }),
7
- name: z
8
- .string({ required_error: 'nameRequired' })
9
- .trim()
10
- .min(1, { message: 'nameRequired' })
11
- .max(50, { message: 'nameTooLong' }),
7
+ name_i18n: z
8
+ .record(
9
+ LanguageValuesSchema,
10
+ z.string().transform(s => s.trim()),
11
+ )
12
+ .refine(val => Object.values(val).some(str => str.length > 0), {
13
+ message: 'atLeastOneTranslationRequired',
14
+ }),
12
15
  action: z.nativeEnum(AppAbility.ACTION, {
13
16
  invalid_type_error: 'actionInvalid',
14
17
  required_error: 'actionRequired',