hh-contracts 0.0.49 → 0.0.50

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.
@@ -17,7 +17,16 @@ exports.TranslationItemSchema = exports.TranslationPersistedSchema.omit({
17
17
  entityName: true,
18
18
  field: true,
19
19
  });
20
- exports.TranslationsArraySchema = zod_1.z.array(exports.TranslationItemSchema);
20
+ exports.TranslationsArraySchema = zod_1.z
21
+ .array(exports.TranslationItemSchema)
22
+ .min(1, { message: 'translationAtLeastOneMustBeExists' })
23
+ .refine(items => {
24
+ const langs = items.map(item => item.lang);
25
+ const uniqueLangs = new Set(langs);
26
+ return langs.length === uniqueLangs.size;
27
+ }, {
28
+ message: 'duplicateLanguagesNotAllowed',
29
+ });
21
30
  exports.TranslationsSchema = zod_1.z.object({
22
31
  name: exports.TranslationsArraySchema,
23
32
  description: exports.TranslationsArraySchema,
@@ -34,7 +34,9 @@ exports.PermissionPersistedSchema = zod_1.z
34
34
  })
35
35
  .merge(common_1.TimestampSchema);
36
36
  exports.PermissionWithTranslationsSchema = exports.PermissionPersistedSchema.extend({
37
- translations: common_1.TranslationsSchema.pick({ name: true, description: true }),
37
+ translations: common_1.TranslationsSchema.pick({ name: true, description: true }).partial({
38
+ description: true,
39
+ }),
38
40
  });
39
41
  exports.PermissionListItemSchema = exports.PermissionPersistedSchema.extend({
40
42
  name: zod_1.z.string().nullable(),
@@ -19,7 +19,19 @@ export const TranslationItemSchema = TranslationPersistedSchema.omit({
19
19
  });
20
20
  export type TTranslationItem = z.infer<typeof TranslationItemSchema>;
21
21
 
22
- export const TranslationsArraySchema = z.array(TranslationItemSchema);
22
+ export const TranslationsArraySchema = z
23
+ .array(TranslationItemSchema)
24
+ .min(1, { message: 'translationAtLeastOneMustBeExists' })
25
+ .refine(
26
+ items => {
27
+ const langs = items.map(item => item.lang);
28
+ const uniqueLangs = new Set(langs);
29
+ return langs.length === uniqueLangs.size;
30
+ },
31
+ {
32
+ message: 'duplicateLanguagesNotAllowed',
33
+ },
34
+ );
23
35
  export type TTranslationsArray = z.infer<typeof TranslationsArraySchema>;
24
36
 
25
37
  export const TranslationsSchema = z.object({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hh-contracts",
3
- "version": "0.0.49",
3
+ "version": "0.0.50",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "scripts": {
@@ -38,7 +38,9 @@ export const PermissionPersistedSchema = z
38
38
  export type TPermissionPersisted = z.infer<typeof PermissionPersistedSchema>;
39
39
 
40
40
  export const PermissionWithTranslationsSchema = PermissionPersistedSchema.extend({
41
- translations: TranslationsSchema.pick({ name: true, description: true }),
41
+ translations: TranslationsSchema.pick({ name: true, description: true }).partial({
42
+ description: true,
43
+ }),
42
44
  });
43
45
  export type TPermissionWithTranslations = z.infer<typeof PermissionWithTranslationsSchema>;
44
46