hh-contracts 0.0.40 → 0.0.41

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.
@@ -1,14 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TranslationsSchema = exports.TranslationsArraySchema = exports.TranslationItemSchema = void 0;
3
+ exports.TranslationsSchema = exports.TranslationsArraySchema = exports.TranslationItemSchema = exports.PersistedTranslationSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const language_keys_schema_1 = require("./language-keys.schema");
6
6
  const translatable_field_constant_1 = require("../constants/translatable-field.constant");
7
- exports.TranslationItemSchema = zod_1.z.object({
7
+ const constants_1 = require("../constants");
8
+ exports.PersistedTranslationSchema = zod_1.z.object({
9
+ entityName: zod_1.z.enum(constants_1.ENTITY_VALUES),
10
+ entityId: zod_1.z.string(),
8
11
  lang: language_keys_schema_1.LanguageKeysSchema,
9
12
  field: zod_1.z.enum(translatable_field_constant_1.TRANSLATABLE_FIELD_VALUES),
10
13
  text: zod_1.z.string().min(1, { message: 'translationRequired' }),
11
14
  });
15
+ exports.TranslationItemSchema = exports.PersistedTranslationSchema.transform(({ entityId, entityName, ...translationData }) => ({
16
+ ...translationData,
17
+ }));
12
18
  exports.TranslationsArraySchema = zod_1.z.array(exports.TranslationItemSchema);
13
19
  exports.TranslationsSchema = zod_1.z.object({
14
20
  translations: exports.TranslationsArraySchema,
@@ -1,12 +1,22 @@
1
1
  import { z } from 'zod';
2
2
  import { LanguageKeysSchema } from './language-keys.schema';
3
3
  import { TRANSLATABLE_FIELD_VALUES } from '../constants/translatable-field.constant';
4
+ import { ENTITY_VALUES } from '../constants';
4
5
 
5
- export const TranslationItemSchema = z.object({
6
+ export const PersistedTranslationSchema = z.object({
7
+ entityName: z.enum(ENTITY_VALUES),
8
+ entityId: z.string(),
6
9
  lang: LanguageKeysSchema,
7
10
  field: z.enum(TRANSLATABLE_FIELD_VALUES),
8
11
  text: z.string().min(1, { message: 'translationRequired' }),
9
12
  });
13
+ export type TPersistedTranslation = z.infer<typeof PersistedTranslationSchema>;
14
+
15
+ export const TranslationItemSchema = PersistedTranslationSchema.transform(
16
+ ({ entityId, entityName, ...translationData }) => ({
17
+ ...translationData,
18
+ }),
19
+ );
10
20
  export type TTranslationItem = z.infer<typeof TranslationItemSchema>;
11
21
 
12
22
  export const TranslationsArraySchema = z.array(TranslationItemSchema);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hh-contracts",
3
- "version": "0.0.40",
3
+ "version": "0.0.41",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {