@bottlebooks/valid-values 1.1.0 → 1.2.1

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.
Files changed (93) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/core/translate.d.ts +3 -0
  3. package/dist/core/translate.d.ts.map +1 -0
  4. package/dist/core/translate.js +42 -0
  5. package/dist/index.d.ts +1 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +9 -10
  8. package/dist/main.js +23 -17
  9. package/dist/validValues/award.d.ts +6 -2
  10. package/dist/validValues/award.d.ts.map +1 -1
  11. package/dist/validValues/award.js +29 -236
  12. package/dist/validValues/awardMedal.d.ts +1 -1
  13. package/dist/validValues/beerStyle.d.ts +1 -1
  14. package/dist/validValues/certification.d.ts +1 -1
  15. package/dist/validValues/country.d.ts +7 -2
  16. package/dist/validValues/country.d.ts.map +1 -1
  17. package/dist/validValues/country.js +2 -149
  18. package/dist/validValues/designation.d.ts +0 -115
  19. package/dist/validValues/designation.d.ts.map +1 -1
  20. package/dist/validValues/ingredient.d.ts +1 -1
  21. package/dist/validValues/ingredient.d.ts.map +1 -1
  22. package/dist/validValues/ingredient.js +37 -33
  23. package/dist/validValues/packagingCertification.d.ts +1 -1
  24. package/dist/validValues/productType.d.ts +6 -2
  25. package/dist/validValues/productType.d.ts.map +1 -1
  26. package/dist/validValues/productType.js +39 -78
  27. package/dist/validValues/productionMethod.d.ts +1 -1
  28. package/dist/validValues/region.d.ts +14 -17
  29. package/dist/validValues/region.d.ts.map +1 -1
  30. package/dist/validValues/region.js +4804 -5250
  31. package/dist/validValues/responsibleConsumptionLogo.d.ts +1 -1
  32. package/dist/validValues/subregion.d.ts +10 -17
  33. package/dist/validValues/subregion.d.ts.map +1 -1
  34. package/dist/validValues/subregion.js +11115 -13852
  35. package/dist/validValues/types/ProductType.d.ts.map +1 -1
  36. package/dist/validValues/types/ValidValueDefinition.d.ts +1 -1
  37. package/dist/validValues/types/ValidValueDefinition.d.ts.map +1 -1
  38. package/dist/validValues/types/award_p85_100.d.ts +3 -0
  39. package/dist/validValues/types/award_p85_100.d.ts.map +1 -0
  40. package/dist/validValues/types/award_p85_100.js +9 -0
  41. package/dist/validValues/types/productTypesSpirit.d.ts +4 -0
  42. package/dist/validValues/types/productTypesSpirit.d.ts.map +1 -0
  43. package/dist/validValues/types/productTypesSpirit.js +9 -0
  44. package/dist/validValues/types/productTypesWine.d.ts +4 -0
  45. package/dist/validValues/types/productTypesWine.d.ts.map +1 -0
  46. package/dist/validValues/types/productTypesWine.js +9 -0
  47. package/dist/validValues/utils/createValidValues.d.ts +1 -1
  48. package/dist/validValues/utils/createValidValues.d.ts.map +1 -1
  49. package/dist/validValues/utils/createValidValues.js +50 -53
  50. package/dist/validValues/varietyName.d.ts +1 -1
  51. package/dist/validValues/wineColor.d.ts +1 -1
  52. package/dist/validValues/wineType.d.ts +1 -1
  53. package/package.json +2 -2
  54. package/region.ts +0 -0
  55. package/src/core/translate.ts +40 -0
  56. package/src/index.ts +1 -6
  57. package/src/locales/po/bg.po +2110 -2110
  58. package/src/locales/po/de.po +2110 -2110
  59. package/src/locales/po/ee.po +2110 -2110
  60. package/src/locales/po/en.po +2110 -2110
  61. package/src/locales/po/es.po +2110 -2110
  62. package/src/locales/po/fi.po +2110 -2110
  63. package/src/locales/po/fr.po +2110 -2110
  64. package/src/locales/po/hr.po +2110 -2110
  65. package/src/locales/po/hu.po +2110 -2110
  66. package/src/locales/po/it.po +2110 -2110
  67. package/src/locales/po/lt.po +2110 -2110
  68. package/src/locales/po/lv.po +2110 -2110
  69. package/src/locales/po/mt.po +2110 -2110
  70. package/src/locales/po/nl.po +2110 -2110
  71. package/src/locales/po/pl.po +2110 -2110
  72. package/src/locales/po/pt.po +2110 -2110
  73. package/src/locales/po/ro.po +2110 -2110
  74. package/src/locales/po/se.po +2110 -2110
  75. package/src/locales/po/si.po +2110 -2110
  76. package/src/locales/po/sk.po +2110 -2110
  77. package/src/main.ts +39 -29
  78. package/src/validValues/award.ts +242 -709
  79. package/src/validValues/country.ts +7 -148
  80. package/src/validValues/designation.ts +0 -5
  81. package/src/validValues/ingredient.ts +35 -343
  82. package/src/validValues/productType.ts +7 -40
  83. package/src/validValues/region.ts +514 -479
  84. package/src/validValues/subregion.ts +1429 -2775
  85. package/src/validValues/types/ProductType.ts +0 -1
  86. package/src/validValues/types/ValidValueDefinition.ts +1 -1
  87. package/src/validValues/types/award_p85_100.ts +19 -0
  88. package/src/validValues/types/productTypesSpirit.ts +38 -0
  89. package/src/validValues/types/productTypesWine.ts +10 -0
  90. package/src/validValues/utils/createValidValues.ts +52 -50
  91. package/dist/validValues/types/Country.js +0 -5
  92. package/src/validValues/types/Award.ts +0 -39
  93. package/src/validValues/types/Country.ts +0 -39
@@ -1,6 +1,5 @@
1
1
  import type { MessageDescriptor } from '@lingui/core';
2
2
  import { ValidValueDefinition } from './ValidValueDefinition';
3
- import { IngredientTag } from './IngredientTag';
4
3
 
5
4
  export interface ProductType extends ValidValueDefinition {
6
5
  title: MessageDescriptor;
@@ -12,7 +12,7 @@ export interface ValidValueDefinition {
12
12
  *
13
13
  * Define it using `defineMessage()` from @lingui/macro.
14
14
  */
15
- title?: string | MessageDescriptor;
15
+ title: string | MessageDescriptor;
16
16
  /**
17
17
  * Fields that will never be stored in the database,
18
18
  * because they are not relevant to the frontend rendering.
@@ -0,0 +1,19 @@
1
+ const range: Array<string> = [
2
+ 'p_85',
3
+ 'p_86',
4
+ 'p_87',
5
+ 'p_88',
6
+ 'p_89',
7
+ 'p_90',
8
+ 'p_91',
9
+ 'p_92',
10
+ 'p_93',
11
+ 'p_94',
12
+ 'p_95',
13
+ 'p_96',
14
+ 'p_97',
15
+ 'p_98',
16
+ 'p_99',
17
+ 'p_100',
18
+ ];
19
+ export default range;
@@ -0,0 +1,38 @@
1
+ import { ProductType } from './ProductTypeKey';
2
+
3
+ const PRODUCT_TYPE_SPIRITS: Array<ProductType> = [
4
+ 'spirit_absinthe',
5
+ 'spirit_anise',
6
+ 'spirit_aquavit',
7
+ 'spirit_arak',
8
+ 'spirit_armagnac',
9
+ 'spirit_asianspirit',
10
+ 'spirit_bitter',
11
+ 'spirit_cachaca',
12
+ 'spirit_calvados',
13
+ 'spirit_cocktail',
14
+ 'spirit_cognac',
15
+ 'spirit_fruitspirit',
16
+ 'spirit_genever',
17
+ 'spirit_gin',
18
+ 'spirit_grainspirit',
19
+ 'spirit_grapebrandy',
20
+ 'spirit_grappa',
21
+ 'spirit_liqueur',
22
+ 'spirit_marc',
23
+ 'spirit_mezcal',
24
+ 'spirit_miscspririt',
25
+ 'spirit_ouzo',
26
+ 'spirit_pastis',
27
+ 'spirit_pisco',
28
+ 'spirit_raki',
29
+ 'spirit_rum',
30
+ 'spirit_sambuca',
31
+ 'spirit_shochu',
32
+ 'spirit_schnaps',
33
+ 'spirit_tequila',
34
+ 'spirit_vermouth',
35
+ 'spirit_vodka',
36
+ 'spirit_whisky',
37
+ ];
38
+ export default PRODUCT_TYPE_SPIRITS;
@@ -0,0 +1,10 @@
1
+ import { ProductType } from './ProductTypeKey';
2
+
3
+ const PRODUCT_TYPE_WINES: Array<ProductType> = [
4
+ 'wine_stillwine',
5
+ 'wine_fortified',
6
+ 'wine_pearlwine',
7
+ 'wine_sparkling',
8
+ 'wine_aromatized',
9
+ ];
10
+ export default PRODUCT_TYPE_WINES;
@@ -12,63 +12,65 @@ type Locale = keyof typeof allMessages;
12
12
  export default function createValidValues<
13
13
  ValidValue extends ValidValueDefinition = ValidValueDefinition
14
14
  >(values: Record<string, ValidValue>) {
15
- function list() {
16
- // TODO if we provide locale argument here we can avoid getTitle without locale argument which can help in .map functions
17
- // const initialLocale = locale;
18
- return Object.entries(values).map(([id, value]) => {
19
- const { key, title, form, frontend } = value;
20
- if (!title) throw new Error('missing_required:title');
15
+ // TODO if we provide locale argument here we can avoid getTitle without locale argument which can help in .map functions
16
+ // const initialLocale = locale;
17
+ const list = Object.entries(values).map(([id, value]) => {
18
+ const { key, title, form, frontend } = value;
19
+ if (!title) throw new Error('missing_required:title');
21
20
 
22
- function getTitle(locale?: Locale) {
23
- if (typeof title === 'string') {
24
- return title;
25
- } else if (title) {
26
- i18n.activate(locale || 'en');
27
- const translation = i18n._(title) || '';
28
- if (translation === title.id) {
29
- console.log('%c' + `WARNING: translation_missing:${title.id}:${locale}`, 'color: #d0011b;');
30
- i18n.activate('en');
31
- return i18n._(title) || '';
32
- }
33
- return translation;
34
- } else {
35
- return key;
21
+ function getTitle(locale?: Locale) {
22
+ if (typeof title === 'string') {
23
+ return title;
24
+ } else if (title) {
25
+ i18n.activate(locale || 'en');
26
+ const translation = i18n._(title) || '';
27
+ if (translation === title.id) {
28
+ console.log(
29
+ '%c' + `WARNING: translation_missing:${title.id}:${locale}`,
30
+ 'color: #d0011b;'
31
+ );
32
+ i18n.activate('en');
33
+ return i18n._(title) || '';
36
34
  }
35
+ return translation;
36
+ } else {
37
+ return key;
37
38
  }
39
+ }
40
+
41
+ return {
42
+ /** The value identifier. */
43
+ id,
44
+ ...value,
45
+ /** Returns the localized title of a lookup value. */
46
+ getTitle,
47
+ /** Returns the translatet titles for multiple locales. */
48
+ getTitles(locales: Locale[] = allSupportedLocales as Locale[]) {
49
+ const translations = Object.fromEntries(
50
+ locales.map((locale) => {
51
+ return [locale, getTitle(locale)];
52
+ })
53
+ ) as Record<Locale, string>;
54
+ return translations;
55
+ },
56
+ form: value.form
57
+ ? {
58
+ ...value.form,
59
+ /** Returns the localized description of a lookup value. */
60
+ // getDescription(locale: Locale) {
61
+ // if (!value?.form?.description) return undefined;
62
+ // i18n.activate(locale);
63
+ // return i18n._(value.form?.description);
64
+ // },
65
+ }
66
+ : undefined,
67
+ };
68
+ });
38
69
 
39
- return {
40
- /** The value identifier. */
41
- id,
42
- ...value,
43
- /** Returns the localized title of a lookup value. */
44
- getTitle,
45
- /** Returns the translatet titles for multiple locales. */
46
- getTitles(locales: Locale[] = allSupportedLocales as Locale[]) {
47
- const translations = Object.fromEntries(
48
- locales.map((locale) => {
49
- return [locale, getTitle(locale)];
50
- })
51
- ) as Record<Locale, string>;
52
- return translations;
53
- },
54
- form: value.form
55
- ? {
56
- ...value.form,
57
- /** Returns the localized description of a lookup value. */
58
- // getDescription(locale: Locale) {
59
- // if (!value?.form?.description) return undefined;
60
- // i18n.activate(locale);
61
- // return i18n._(value.form?.description);
62
- // },
63
- }
64
- : undefined,
65
- };
66
- });
67
- }
68
70
  return {
69
71
  list,
70
72
  byId: () => {
71
- return Object.fromEntries(list().map((value) => [value.id, value]));
73
+ return Object.fromEntries(list.map((value) => [value.id, value]));
72
74
  },
73
75
  };
74
76
  }
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1,39 +0,0 @@
1
- import type { MessageDescriptor } from '@lingui/core';
2
- interface ValidValueEnabledFor {
3
- field: string;
4
- value: string;
5
- }
6
-
7
- export interface Award {
8
- key: string;
9
- enabledFor?: ValidValueEnabledFor[];
10
- /**
11
- * The translatable title of the valid value.
12
- *
13
- * Define it using `defineMessage()` from @lingui/macro.
14
- */
15
- title?: string | MessageDescriptor;
16
- /**
17
- * Fields that will never be stored in the database,
18
- * because they are not relevant to the frontend rendering.
19
- * They are only used for the form, like grouping values for easier entry.
20
- */
21
- form?: {
22
- /**
23
- * A helpful description shown only when using the form.
24
- */
25
- // description?: MessageDescriptor;
26
- };
27
- medals?: string[];
28
- /**
29
- * Fields that are stored in the database together with each lookup value,
30
- * because they affect the frontend rendering.
31
- * They are also included in the hash values to detect breaking changes.
32
- *
33
- * We should try to avoid them if possible because if false positives:
34
- * Any change in one of those fields would lead to
35
- * eLabels that are marked as incompatible,
36
- * although there might be no user-visible changes.
37
- */
38
- frontend?: {};
39
- }
@@ -1,39 +0,0 @@
1
- import type { MessageDescriptor } from '@lingui/core';
2
- interface ValidValueEnabledFor {
3
- field: string;
4
- value: string;
5
- }
6
-
7
- export interface Country {
8
- key: string;
9
- enabledFor?: ValidValueEnabledFor[];
10
- /**
11
- * The translatable title of the valid value.
12
- *
13
- * Define it using `defineMessage()` from @lingui/macro.
14
- */
15
- title?: string | MessageDescriptor;
16
- /**
17
- * Fields that will never be stored in the database,
18
- * because they are not relevant to the frontend rendering.
19
- * They are only used for the form, like grouping values for easier entry.
20
- */
21
- form?: {
22
- /**
23
- * A helpful description shown only when using the form.
24
- */
25
- // description?: MessageDescriptor;
26
- };
27
- regions?: string[];
28
- /**
29
- * Fields that are stored in the database together with each lookup value,
30
- * because they affect the frontend rendering.
31
- * They are also included in the hash values to detect breaking changes.
32
- *
33
- * We should try to avoid them if possible because if false positives:
34
- * Any change in one of those fields would lead to
35
- * eLabels that are marked as incompatible,
36
- * although there might be no user-visible changes.
37
- */
38
- frontend?: {};
39
- }