hh-contracts 0.0.79 → 0.0.80

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.
@@ -15,3 +15,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./translation.models"), exports);
18
+ __exportStar(require("./resolve-translation-value-type.helper"), exports);
19
+ __exportStar(require("./translation-value-types.constant"), exports);
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveTranslationValueType = resolveTranslationValueType;
4
+ const translation_value_type_policy_1 = require("./translation-value-type-policy");
5
+ function resolveTranslationValueType(entityName, dotPath, explicit, registry = translation_value_type_policy_1.defaultPolicy) {
6
+ if (explicit)
7
+ return explicit;
8
+ const byEntity = registry.byEntity?.[entityName];
9
+ return byEntity?.[dotPath] ?? registry.default?.[dotPath] ?? 'text';
10
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultPolicy = void 0;
4
+ exports.defaultPolicy = {
5
+ default: {
6
+ name: 'text',
7
+ description: 'html',
8
+ 'seo.title': 'text',
9
+ 'seo.description': 'text',
10
+ },
11
+ byEntity: {
12
+ roles: {
13
+ description: 'text',
14
+ },
15
+ },
16
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TranslationValueTypesValues = exports.TRANSLATION_VALUE_TYPES = void 0;
4
+ exports.TRANSLATION_VALUE_TYPES = {
5
+ text: 'text',
6
+ html: 'html',
7
+ };
8
+ exports.TranslationValueTypesValues = Object.values(exports.TRANSLATION_VALUE_TYPES);
@@ -33,18 +33,15 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.TranslationItemSchema = exports.TranslationPersistedSchema = void 0;
36
+ exports.TranslationPersistedSchema = void 0;
37
37
  const z = __importStar(require("zod"));
38
38
  const common_1 = require("../common");
39
+ const translation_value_types_constant_1 = require("./translation-value-types.constant");
39
40
  exports.TranslationPersistedSchema = z.object({
40
41
  entityName: z.enum(common_1.ENTITY_VALUES),
41
42
  entityId: z.string(),
42
43
  lang: common_1.LanguageKeysSchema,
43
- field: z.string().min(1).max(255),
44
- text: z.string().min(1),
45
- });
46
- exports.TranslationItemSchema = exports.TranslationPersistedSchema.omit({
47
- entityId: true,
48
- entityName: true,
49
- field: true,
44
+ path: z.string(),
45
+ valueType: z.enum(translation_value_types_constant_1.TranslationValueTypesValues),
46
+ value: z.string().min(1),
50
47
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hh-contracts",
3
- "version": "0.0.79",
3
+ "version": "0.0.80",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {
@@ -1 +1,3 @@
1
1
  export * from './translation.models';
2
+ export * from './resolve-translation-value-type.helper';
3
+ export * from './translation-value-types.constant';
@@ -0,0 +1,14 @@
1
+ import { TEntity } from '../common';
2
+ import { ContentPolicyRegistry, defaultPolicy } from './translation-value-type-policy';
3
+ import { TTranslationValueType } from './translation-value-types.constant';
4
+
5
+ export function resolveTranslationValueType<E extends TEntity>(
6
+ entityName: E,
7
+ dotPath: string,
8
+ explicit?: TTranslationValueType | null,
9
+ registry: ContentPolicyRegistry<E> = defaultPolicy,
10
+ ): TTranslationValueType {
11
+ if (explicit) return explicit;
12
+ const byEntity = registry.byEntity?.[entityName];
13
+ return byEntity?.[dotPath] ?? registry.default?.[dotPath] ?? 'text';
14
+ }
@@ -0,0 +1,22 @@
1
+ import { TEntity } from '../common';
2
+ import type { TTranslationValueType } from './translation-value-types.constant';
3
+
4
+ export type ContentPolicy = Record<string, TTranslationValueType>;
5
+ export type ContentPolicyRegistry<E extends TEntity> = {
6
+ default?: ContentPolicy;
7
+ byEntity?: Partial<Record<E, ContentPolicy>>;
8
+ };
9
+
10
+ export const defaultPolicy: ContentPolicyRegistry<TEntity> = {
11
+ default: {
12
+ name: 'text',
13
+ description: 'html',
14
+ 'seo.title': 'text',
15
+ 'seo.description': 'text',
16
+ },
17
+ byEntity: {
18
+ roles: {
19
+ description: 'text',
20
+ },
21
+ },
22
+ };
@@ -0,0 +1,10 @@
1
+ export const TRANSLATION_VALUE_TYPES = {
2
+ text: 'text',
3
+ html: 'html',
4
+ } as const;
5
+ export type TTranslationValueType =
6
+ (typeof TRANSLATION_VALUE_TYPES)[keyof typeof TRANSLATION_VALUE_TYPES];
7
+ export const TranslationValueTypesValues = Object.values(TRANSLATION_VALUE_TYPES) as [
8
+ TTranslationValueType,
9
+ ...TTranslationValueType[],
10
+ ];
@@ -1,18 +1,13 @@
1
1
  import * as z from 'zod';
2
2
  import { ENTITY_VALUES, LanguageKeysSchema } from '../common';
3
+ import { TranslationValueTypesValues } from './translation-value-types.constant';
3
4
 
4
5
  export const TranslationPersistedSchema = z.object({
5
6
  entityName: z.enum(ENTITY_VALUES),
6
7
  entityId: z.string(),
7
8
  lang: LanguageKeysSchema,
8
- field: z.string().min(1).max(255),
9
- text: z.string().min(1),
9
+ path: z.string(),
10
+ valueType: z.enum(TranslationValueTypesValues),
11
+ value: z.string().min(1),
10
12
  });
11
13
  export type TTranslationPersisted = z.infer<typeof TranslationPersistedSchema>;
12
-
13
- export const TranslationItemSchema = TranslationPersistedSchema.omit({
14
- entityId: true,
15
- entityName: true,
16
- field: true,
17
- });
18
- export type TTranslationItem = z.infer<typeof TranslationItemSchema>;