hh-contracts 0.0.91 → 0.0.93

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.
@@ -29,4 +29,3 @@ __exportStar(require("./role-types.constant"), exports);
29
29
  __exportStar(require("./route-component-key.constants"), exports);
30
30
  __exportStar(require("./slug.constant"), exports);
31
31
  __exportStar(require("./translatable-field.constant"), exports);
32
- __exportStar(require("./zod-error-mapping.constant"), exports);
@@ -33,8 +33,14 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.makeTranslationsByLang = void 0;
36
+ exports.makeTranslations = void 0;
37
37
  const z = __importStar(require("zod"));
38
38
  const language_keys_schema_1 = require("./language-keys.schema");
39
- const makeTranslationsByLang = (schema) => z.partialRecord(language_keys_schema_1.LanguageKeysSchema, schema);
40
- exports.makeTranslationsByLang = makeTranslationsByLang;
39
+ const makeTranslations = (schema) => z
40
+ .partialRecord(language_keys_schema_1.LanguageKeysSchema, schema)
41
+ .refine(translations => Object.keys(translations).length > 0, {
42
+ params: {
43
+ messageKey: 'zod.translations.must_not_be_empty',
44
+ },
45
+ });
46
+ exports.makeTranslations = makeTranslations;
@@ -52,7 +52,7 @@ exports.PageLangTranslationSchema = z.object({
52
52
  .default({}),
53
53
  blocks: blocks_1.BlocksTranslationSchema.default({}),
54
54
  });
55
- const TranslationsSchema = (0, common_1.makeTranslationsByLang)(exports.PageLangTranslationSchema);
55
+ const TranslationsSchema = (0, common_1.makeTranslations)(exports.PageLangTranslationSchema);
56
56
  exports.PageSchema = z.object({
57
57
  meta: MetaSchema,
58
58
  blocks: z.array(blocks_1.BlockSchema),
@@ -66,7 +66,7 @@ exports.PermissionTranslationsSchema = z.object({
66
66
  description: z.string().optional(),
67
67
  });
68
68
  exports.PermissionWithTranslationsSchema = exports.PermissionPersistedSchema.extend({
69
- translations: (0, common_1.makeTranslationsByLang)(exports.PermissionTranslationsSchema),
69
+ translations: (0, common_1.makeTranslations)(exports.PermissionTranslationsSchema),
70
70
  });
71
71
  exports.PermissionListItemSchema = exports.PermissionPersistedSchema.extend({
72
72
  name: z.string().nullable(),
@@ -53,7 +53,7 @@ exports.RoleTranslationsSchema = z.object({
53
53
  description: z.string().optional(),
54
54
  });
55
55
  exports.RoleWithTranslationsSchema = exports.RoleWithPermissionsSchema.extend({
56
- translations: (0, common_1.makeTranslationsByLang)(exports.RoleTranslationsSchema),
56
+ translations: (0, common_1.makeTranslations)(exports.RoleTranslationsSchema),
57
57
  });
58
58
  exports.RoleListItemSchema = exports.RolePersistedSchema.extend({
59
59
  name: z.string().nullable(),
@@ -13,4 +13,3 @@ export * from './role-types.constant';
13
13
  export * from './route-component-key.constants';
14
14
  export * from './slug.constant';
15
15
  export * from './translatable-field.constant';
16
- export * from './zod-error-mapping.constant';
@@ -1,8 +1,14 @@
1
1
  import * as z from 'zod';
2
2
  import { LanguageKeysSchema } from './language-keys.schema';
3
3
 
4
- export const makeTranslationsByLang = <T extends z.ZodObject>(schema: T) =>
5
- z.partialRecord(LanguageKeysSchema, schema);
6
- export type TranslationsByLang<T extends object> = Partial<
4
+ export const makeTranslations = <T extends z.ZodObject>(schema: T) =>
5
+ z
6
+ .partialRecord(LanguageKeysSchema, schema)
7
+ .refine(translations => Object.keys(translations).length > 0, {
8
+ params: {
9
+ messageKey: 'zod.translations.must_not_be_empty',
10
+ },
11
+ });
12
+ export type TTranslations<T extends object> = Partial<
7
13
  Record<z.infer<typeof LanguageKeysSchema>, T>
8
14
  >;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hh-contracts",
3
- "version": "0.0.91",
3
+ "version": "0.0.93",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {
@@ -1,5 +1,5 @@
1
1
  import * as z from 'zod';
2
- import { AppStatuses, LanguageKeysSchema, makeTranslationsByLang, SlugSchema } from '../../common';
2
+ import { AppStatuses, LanguageKeysSchema, makeTranslations, SlugSchema } from '../../common';
3
3
  import { BlocksTranslationSchema, BlockSchema } from './blocks';
4
4
 
5
5
  const MetaSchema = z.object({
@@ -18,7 +18,7 @@ export const PageLangTranslationSchema = z.object({
18
18
  .default({}),
19
19
  blocks: BlocksTranslationSchema.default({}),
20
20
  });
21
- const TranslationsSchema = makeTranslationsByLang(PageLangTranslationSchema);
21
+ const TranslationsSchema = makeTranslations(PageLangTranslationSchema);
22
22
 
23
23
  export const PageSchema = z.object({
24
24
  meta: MetaSchema,
@@ -1,5 +1,5 @@
1
1
  import * as z from 'zod';
2
- import { AppAbility, TimestampSchema, makeTranslationsByLang } from '../common';
2
+ import { AppAbility, TimestampSchema, makeTranslations } from '../common';
3
3
 
4
4
  export const JsonConditionsSchema = z
5
5
  .string()
@@ -39,7 +39,7 @@ export const PermissionTranslationsSchema = z.object({
39
39
  export type TPermissionTranslations = z.infer<typeof PermissionTranslationsSchema>;
40
40
 
41
41
  export const PermissionWithTranslationsSchema = PermissionPersistedSchema.extend({
42
- translations: makeTranslationsByLang(PermissionTranslationsSchema),
42
+ translations: makeTranslations(PermissionTranslationsSchema),
43
43
  });
44
44
  export type TPermissionWithTranslations = z.infer<typeof PermissionWithTranslationsSchema>;
45
45
 
@@ -1,10 +1,5 @@
1
1
  import * as z from 'zod';
2
- import {
3
- ROLE_TYPE_VALUES,
4
- TimestampSchema,
5
- UuidArraySchema,
6
- makeTranslationsByLang,
7
- } from '../common';
2
+ import { ROLE_TYPE_VALUES, TimestampSchema, UuidArraySchema, makeTranslations } from '../common';
8
3
  import { PermissionListItemSchema } from '../permissions';
9
4
 
10
5
  export const RolePersistedSchema = z
@@ -29,7 +24,7 @@ export const RoleTranslationsSchema = z.object({
29
24
  export type TRoleTranslations = z.infer<typeof RoleTranslationsSchema>;
30
25
 
31
26
  export const RoleWithTranslationsSchema = RoleWithPermissionsSchema.extend({
32
- translations: makeTranslationsByLang(RoleTranslationsSchema),
27
+ translations: makeTranslations(RoleTranslationsSchema),
33
28
  });
34
29
  export type TRoleWithTranslations = z.infer<typeof RoleWithTranslationsSchema>;
35
30
 
@@ -1,46 +0,0 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.ZOD_ERROR_MAPPING = void 0;
37
- const z = __importStar(require("zod"));
38
- exports.ZOD_ERROR_MAPPING = {
39
- [z.ZodIssueCode.invalid_type]: 'errors.validation.invalidType',
40
- [z.ZodIssueCode.custom]: 'errors.validation.custom',
41
- [z.ZodIssueCode.invalid_union]: 'errors.validation.invalidUnion',
42
- [z.ZodIssueCode.unrecognized_keys]: 'errors.validation.unrecognizedKeys',
43
- [z.ZodIssueCode.too_small]: 'errors.validation.tooSmall',
44
- [z.ZodIssueCode.too_big]: 'errors.validation.tooBig',
45
- [z.ZodIssueCode.not_multiple_of]: 'errors.validation.notMultipleOf',
46
- };
@@ -1,13 +0,0 @@
1
- import * as z from 'zod';
2
-
3
- export const ZOD_ERROR_MAPPING = {
4
- [z.ZodIssueCode.invalid_type]: 'errors.validation.invalidType',
5
- [z.ZodIssueCode.custom]: 'errors.validation.custom',
6
- [z.ZodIssueCode.invalid_union]: 'errors.validation.invalidUnion',
7
- [z.ZodIssueCode.unrecognized_keys]: 'errors.validation.unrecognizedKeys',
8
- [z.ZodIssueCode.too_small]: 'errors.validation.tooSmall',
9
- [z.ZodIssueCode.too_big]: 'errors.validation.tooBig',
10
- [z.ZodIssueCode.not_multiple_of]: 'errors.validation.notMultipleOf',
11
- };
12
-
13
- export type TZodErorrKey = (typeof ZOD_ERROR_MAPPING)[keyof typeof ZOD_ERROR_MAPPING];