@carbonbox/domain 0.27.0 → 0.28.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 (53) hide show
  1. package/build/carbonbox/emission-calculation-formulas/domain/entity/EmissionCalculationFormula.js +1 -1
  2. package/build/carbonbox/emission-calculation-formulas/domain/value-objects/EmissionCalculationFormulaApplicableGreenhouseGases.js +30 -215
  3. package/build/carbonbox/emission-calculation-formulas/emission-factors/domain/value-objects/EmissionFactorGreenhouseGasValues.js +16 -11
  4. package/build/carbonbox/emission-calculation-formulas/global-warming-potentials/domain/value-objects/GlobalWarmingPotentialGreenhouseGasPotentials.js +18 -13
  5. package/build/carbonbox/emission-calculation-results/emission-aggregations/domain/value-objects/EmissionAggregationGhgBreakdown.js +52 -109
  6. package/build/carbonbox/emission-calculation-results/ghg-emission-results/domain/entity/GHGEmissionResult.js +9 -4
  7. package/build/carbonbox/emission-calculation-results/ghg-emission-results/domain/value-objects/GHGEmissionResultGreenhouseGas.js +44 -160
  8. package/build/carbonbox/shared/domain/enums/GreenhouseGasCategory.js +15 -0
  9. package/build/carbonbox/shared/domain/value-objects/GreenhouseGasSpecies.js +50 -0
  10. package/build/main/index.js +15 -13
  11. package/build/types/carbonbox/carbon-footprint-configurations/corporate-configurations/domain/repository/ICorporateCarbonFootprintConfigurationRepository.d.ts +2 -0
  12. package/build/types/carbonbox/carbon-footprint-configurations/corporate-configurations/domain/repository/ICorporateCarbonFootprintConfigurationRepository.d.ts.map +1 -1
  13. package/build/types/carbonbox/emission-calculation-formulas/domain/types/EmissionCalculationFormulaPrimitives.d.ts +1 -2
  14. package/build/types/carbonbox/emission-calculation-formulas/domain/types/EmissionCalculationFormulaPrimitives.d.ts.map +1 -1
  15. package/build/types/carbonbox/emission-calculation-formulas/domain/types/EmissionCalculationFormulaProps.d.ts +1 -2
  16. package/build/types/carbonbox/emission-calculation-formulas/domain/types/EmissionCalculationFormulaProps.d.ts.map +1 -1
  17. package/build/types/carbonbox/emission-calculation-formulas/domain/value-objects/EmissionCalculationFormulaApplicableGreenhouseGases.d.ts +11 -105
  18. package/build/types/carbonbox/emission-calculation-formulas/domain/value-objects/EmissionCalculationFormulaApplicableGreenhouseGases.d.ts.map +1 -1
  19. package/build/types/carbonbox/emission-calculation-formulas/emission-factors/domain/types/GHGFactorValue.d.ts +3 -2
  20. package/build/types/carbonbox/emission-calculation-formulas/emission-factors/domain/types/GHGFactorValue.d.ts.map +1 -1
  21. package/build/types/carbonbox/emission-calculation-formulas/emission-factors/domain/types/GHGFactorValuePrimitives.d.ts +3 -2
  22. package/build/types/carbonbox/emission-calculation-formulas/emission-factors/domain/types/GHGFactorValuePrimitives.d.ts.map +1 -1
  23. package/build/types/carbonbox/emission-calculation-formulas/emission-factors/domain/value-objects/EmissionFactorGreenhouseGasValues.d.ts +1 -1
  24. package/build/types/carbonbox/emission-calculation-formulas/emission-factors/domain/value-objects/EmissionFactorGreenhouseGasValues.d.ts.map +1 -1
  25. package/build/types/carbonbox/emission-calculation-formulas/global-warming-potentials/domain/types/GHGPotentialValue.d.ts +3 -2
  26. package/build/types/carbonbox/emission-calculation-formulas/global-warming-potentials/domain/types/GHGPotentialValue.d.ts.map +1 -1
  27. package/build/types/carbonbox/emission-calculation-formulas/global-warming-potentials/domain/types/GHGPotentialValuePrimitives.d.ts +3 -2
  28. package/build/types/carbonbox/emission-calculation-formulas/global-warming-potentials/domain/types/GHGPotentialValuePrimitives.d.ts.map +1 -1
  29. package/build/types/carbonbox/emission-calculation-formulas/global-warming-potentials/domain/value-objects/GlobalWarmingPotentialGreenhouseGasPotentials.d.ts +2 -2
  30. package/build/types/carbonbox/emission-calculation-formulas/global-warming-potentials/domain/value-objects/GlobalWarmingPotentialGreenhouseGasPotentials.d.ts.map +1 -1
  31. package/build/types/carbonbox/emission-calculation-results/emission-aggregations/domain/types/GHGBreakdown.d.ts +3 -2
  32. package/build/types/carbonbox/emission-calculation-results/emission-aggregations/domain/types/GHGBreakdown.d.ts.map +1 -1
  33. package/build/types/carbonbox/emission-calculation-results/emission-aggregations/domain/types/GHGBreakdownPrimitives.d.ts +3 -2
  34. package/build/types/carbonbox/emission-calculation-results/emission-aggregations/domain/types/GHGBreakdownPrimitives.d.ts.map +1 -1
  35. package/build/types/carbonbox/emission-calculation-results/emission-aggregations/domain/value-objects/EmissionAggregationGhgBreakdown.d.ts +9 -80
  36. package/build/types/carbonbox/emission-calculation-results/emission-aggregations/domain/value-objects/EmissionAggregationGhgBreakdown.d.ts.map +1 -1
  37. package/build/types/carbonbox/emission-calculation-results/ghg-emission-results/domain/entity/GHGEmissionResult.d.ts.map +1 -1
  38. package/build/types/carbonbox/emission-calculation-results/ghg-emission-results/domain/types/GHGEmissionResultPrimitives.d.ts +3 -2
  39. package/build/types/carbonbox/emission-calculation-results/ghg-emission-results/domain/types/GHGEmissionResultPrimitives.d.ts.map +1 -1
  40. package/build/types/carbonbox/emission-calculation-results/ghg-emission-results/domain/types/GHGEmissionResultProps.d.ts +3 -2
  41. package/build/types/carbonbox/emission-calculation-results/ghg-emission-results/domain/types/GHGEmissionResultProps.d.ts.map +1 -1
  42. package/build/types/carbonbox/emission-calculation-results/ghg-emission-results/domain/value-objects/GHGEmissionResultGreenhouseGas.d.ts +22 -89
  43. package/build/types/carbonbox/emission-calculation-results/ghg-emission-results/domain/value-objects/GHGEmissionResultGreenhouseGas.d.ts.map +1 -1
  44. package/build/types/carbonbox/shared/domain/enums/GreenhouseGasCategory.d.ts +12 -0
  45. package/build/types/carbonbox/shared/domain/enums/GreenhouseGasCategory.d.ts.map +1 -0
  46. package/build/types/carbonbox/shared/domain/value-objects/GreenhouseGasSpecies.d.ts +24 -0
  47. package/build/types/carbonbox/shared/domain/value-objects/GreenhouseGasSpecies.d.ts.map +1 -0
  48. package/build/types/main/index.d.ts +3 -1
  49. package/build/types/main/index.d.ts.map +1 -1
  50. package/package.json +1 -1
  51. package/build/carbonbox/shared/domain/enums/GreenhouseGas.js +0 -14
  52. package/build/types/carbonbox/shared/domain/enums/GreenhouseGas.d.ts +0 -11
  53. package/build/types/carbonbox/shared/domain/enums/GreenhouseGas.d.ts.map +0 -1
@@ -134,7 +134,7 @@ class EmissionCalculationFormula extends AggregateRoot_1.AggregateRoot {
134
134
  expression: __classPrivateFieldGet(this, _EmissionCalculationFormula_expression, "f").toPrimitives(),
135
135
  resultUnit: __classPrivateFieldGet(this, _EmissionCalculationFormula_resultUnit, "f").toEnum(),
136
136
  status: __classPrivateFieldGet(this, _EmissionCalculationFormula_status, "f").toEnum(),
137
- applicableGreenhouseGases: __classPrivateFieldGet(this, _EmissionCalculationFormula_applicableGreenhouseGases, "f").toEnums(),
137
+ applicableGreenhouseGases: __classPrivateFieldGet(this, _EmissionCalculationFormula_applicableGreenhouseGases, "f").toPrimitives(),
138
138
  emissionSource: __classPrivateFieldGet(this, _EmissionCalculationFormula_emissionSource, "f").toEnum(),
139
139
  variables: __classPrivateFieldGet(this, _EmissionCalculationFormula_variables, "f").toPrimitives(),
140
140
  activityVariableSymbol: __classPrivateFieldGet(this, _EmissionCalculationFormula_activityVariableSymbol, "f").toPrimitives(),
@@ -1,248 +1,63 @@
1
1
  "use strict";
2
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
- };
7
- var _a, _EmissionCalculationFormulaApplicableGreenhouseGases_guardAgainstInvalidGreenhouseGasTypes, _EmissionCalculationFormulaApplicableGreenhouseGases_guardAgainstDuplicateGreenhouseGases;
8
2
  Object.defineProperty(exports, "__esModule", { value: true });
9
3
  exports.EmissionCalculationFormulaApplicableGreenhouseGases = void 0;
10
4
  const StringList_1 = require("../../../shared/domain/value-objects/StringList");
11
- const GreenhouseGas_1 = require("../../../shared/domain/enums/GreenhouseGas");
12
- const InvalidGreenhouseGasTypeError_1 = require("../exceptions/InvalidGreenhouseGasTypeError");
5
+ const GreenhouseGasSpecies_1 = require("../../../shared/domain/value-objects/GreenhouseGasSpecies");
13
6
  const DuplicateGreenhouseGasError_1 = require("../exceptions/DuplicateGreenhouseGasError");
7
+ /**
8
+ * Especies de gas a las que aplica una fórmula (códigos normalizados: `CO2`, `CH4-FOSSIL`, `R-410A`…).
9
+ * La categoría de cada especie NO se guarda aquí: se resuelve desde el dato de referencia
10
+ * (EmissionFactor / GlobalWarmingPotential), que es la fuente de verdad de la taxonomía.
11
+ * Vacío = la fórmula aplica a toda submission del emissionSource (semántica CAL-007 preservada).
12
+ */
14
13
  class EmissionCalculationFormulaApplicableGreenhouseGases extends StringList_1.StringList {
15
14
  constructor(value, skipDomainValidation) {
16
- super(value, skipDomainValidation, _a.PROPERTY_NAME, { allowEmpty: false });
15
+ super(value, skipDomainValidation, EmissionCalculationFormulaApplicableGreenhouseGases.PROPERTY_NAME, { allowEmpty: false });
17
16
  if (skipDomainValidation === false) {
18
- // Validaciones específicas de greenhouse gases después de las validaciones base de StringList
19
- _a.guardAgainstInvalidGreenhouseGases(value);
17
+ EmissionCalculationFormulaApplicableGreenhouseGases.guardAgainstDuplicateSpecies(value);
20
18
  }
21
19
  }
22
- /**
23
- * Factory method para crear una instancia.
24
- */
25
20
  static create(value) {
26
- StringList_1.StringList.guardAgainstInvalidStringList(value, _a.PROPERTY_NAME);
27
- return new _a(value, false);
21
+ StringList_1.StringList.guardAgainstInvalidStringList(value, EmissionCalculationFormulaApplicableGreenhouseGases.PROPERTY_NAME);
22
+ // Normaliza + valida cada especie por el VO compartido (trim + colapsar espacios + UPPERCASE).
23
+ const normalized = value.map((species) => GreenhouseGasSpecies_1.GreenhouseGasSpecies.create(species).toPrimitives());
24
+ return new EmissionCalculationFormulaApplicableGreenhouseGases(normalized, false);
28
25
  }
29
26
  static fromPrimitives(primitives) {
30
- const value = primitives.map((primitive) => primitive);
31
- return new _a(value, true);
32
- }
33
- /**
34
- * Validaciones específicas para greenhouse gas types.
35
- */
36
- static guardAgainstInvalidGreenhouseGases(value) {
37
- __classPrivateFieldGet(this, _a, "m", _EmissionCalculationFormulaApplicableGreenhouseGases_guardAgainstInvalidGreenhouseGasTypes).call(this, value);
38
- __classPrivateFieldGet(this, _a, "m", _EmissionCalculationFormulaApplicableGreenhouseGases_guardAgainstDuplicateGreenhouseGases).call(this, value);
27
+ return new EmissionCalculationFormulaApplicableGreenhouseGases([...primitives], true);
28
+ }
29
+ static guardAgainstDuplicateSpecies(value) {
30
+ const counts = new Map();
31
+ value.forEach((species) => counts.set(species, (counts.get(species) || 0) + 1));
32
+ const duplicates = [...counts.entries()].filter(([, count]) => count > 1).map(([species]) => species);
33
+ if (duplicates.length > 0) {
34
+ throw DuplicateGreenhouseGasError_1.DuplicateGreenhouseGasError.create(EmissionCalculationFormulaApplicableGreenhouseGases.PROPERTY_NAME, duplicates);
35
+ }
39
36
  }
40
- /**
41
- * Convierte a representación primitiva.
42
- */
43
37
  toPrimitives() {
44
38
  return [...this.value];
45
39
  }
46
- /**
47
- * Obtiene los greenhouse gas types como array de enums.
48
- */
49
- toEnums() {
50
- return this.value;
51
- }
52
- /**
53
- * Obtiene los greenhouse gas types como array de strings.
54
- */
55
- toGreenhouseGasTypeStrings() {
56
- return [...this.value];
57
- }
58
- /**
59
- * Verifica si contiene un greenhouse gas type específico.
60
- */
61
- contains(gasType) {
62
- return this.value.includes(gasType);
63
- }
64
- /**
65
- * Obtiene los greenhouse gases como array inmutable.
66
- */
67
- get greenhouseGases() {
40
+ get speciesCodes() {
68
41
  return Object.freeze([...this.value]);
69
42
  }
70
- /**
71
- * Número de greenhouse gases.
72
- */
43
+ contains(species) {
44
+ return this.value.includes(GreenhouseGasSpecies_1.GreenhouseGasSpecies.normalize(species));
45
+ }
73
46
  get length() {
74
47
  return this.value.length;
75
48
  }
76
- /**
77
- * Verifica si la colección está vacía.
78
- */
79
49
  isEmpty() {
80
50
  return this.value.length === 0;
81
51
  }
82
- /**
83
- * Verifica si la colección tiene valores.
84
- */
85
52
  hasValues() {
86
53
  return !this.isEmpty();
87
54
  }
88
- /**
89
- * Verifica si incluye todos los greenhouse gas types especificados.
90
- */
91
- includesAllOf(gasTypes) {
92
- return gasTypes.every((gasType) => this.contains(gasType));
93
- }
94
- /**
95
- * Verifica si incluye alguno de los greenhouse gas types especificados.
96
- */
97
- includesAnyOf(gasTypes) {
98
- return gasTypes.some((gasType) => this.contains(gasType));
99
- }
100
- /**
101
- * Obtiene los greenhouse gas types comunes con otra colección.
102
- */
103
- getCommonGases(other) {
104
- return this.value.filter((gas) => other.contains(gas));
105
- }
106
- /**
107
- * Obtiene los greenhouse gas types únicos de esta colección comparado con otra.
108
- */
109
- getUniqueGases(other) {
110
- return this.value.filter((gas) => !other.contains(gas));
111
- }
112
- /**
113
- * Verifica si contiene CO2.
114
- */
115
- hasCO2() {
116
- return this.contains(GreenhouseGas_1.GreenhouseGas.CO2);
117
- }
118
- /**
119
- * Verifica si contiene CH4 (metano).
120
- */
121
- hasMethane() {
122
- return this.contains(GreenhouseGas_1.GreenhouseGas.CH4);
55
+ includesAllOf(species) {
56
+ return species.every((current) => this.contains(current));
123
57
  }
124
- /**
125
- * Verifica si contiene N2O (óxido nitroso).
126
- */
127
- hasNitrousOxide() {
128
- return this.contains(GreenhouseGas_1.GreenhouseGas.N2O);
129
- }
130
- /**
131
- * Verifica si contiene gases fluorados (HFCs, PFCs, SF6, NF3).
132
- */
133
- hasFluorinatedGases() {
134
- const fluorinatedGases = [
135
- GreenhouseGas_1.GreenhouseGas.HFC134a,
136
- GreenhouseGas_1.GreenhouseGas.SF6,
137
- GreenhouseGas_1.GreenhouseGas.NF3,
138
- ];
139
- return fluorinatedGases.some((gas) => this.contains(gas));
140
- }
141
- /**
142
- * Verifica si contiene solo los tres gases principales del Protocolo de Kyoto.
143
- */
144
- hasOnlyKyotoMainGases() {
145
- const kyotoMainGases = [GreenhouseGas_1.GreenhouseGas.CO2, GreenhouseGas_1.GreenhouseGas.CH4, GreenhouseGas_1.GreenhouseGas.N2O];
146
- return this.value.length === 3 && this.includesAllOf(kyotoMainGases);
147
- }
148
- /**
149
- * Verifica si incluye todos los gases del Protocolo de Kyoto.
150
- */
151
- includesAllKyotoGases() {
152
- const allKyotoGases = Object.values(GreenhouseGas_1.GreenhouseGas);
153
- return this.includesAllOf(allKyotoGases);
154
- }
155
- /**
156
- * Obtiene los gases por categoría de potencial de calentamiento.
157
- */
158
- getGasesByWarmingPotentialCategory() {
159
- const lowPotential = [];
160
- const mediumPotential = [];
161
- const highPotential = [];
162
- this.value.forEach((gas) => {
163
- const gasType = gas;
164
- switch (gasType) {
165
- case GreenhouseGas_1.GreenhouseGas.CO2:
166
- lowPotential.push(gasType);
167
- break;
168
- case GreenhouseGas_1.GreenhouseGas.CH4:
169
- case GreenhouseGas_1.GreenhouseGas.N2O:
170
- mediumPotential.push(gasType);
171
- break;
172
- default:
173
- highPotential.push(gasType);
174
- break;
175
- }
176
- });
177
- return {
178
- lowPotential,
179
- mediumPotential,
180
- highPotential,
181
- };
182
- }
183
- /**
184
- * Obtiene la complejidad de la colección basada en el número y tipo de gases.
185
- */
186
- getComplexity() {
187
- const gasCount = this.length;
188
- const hasFluorinatedGases = this.hasFluorinatedGases();
189
- if (gasCount === 1)
190
- return 'simple';
191
- if (gasCount <= 3 && !hasFluorinatedGases)
192
- return 'simple';
193
- if (gasCount <= 5)
194
- return 'medium';
195
- return 'complex';
196
- }
197
- /**
198
- * Obtiene estadísticas de la colección.
199
- */
200
- getStatistics() {
201
- return {
202
- totalGases: this.length,
203
- hasCO2: this.hasCO2(),
204
- hasMethane: this.hasMethane(),
205
- hasNitrousOxide: this.hasNitrousOxide(),
206
- hasFluorinatedGases: this.hasFluorinatedGases(),
207
- includesAllKyotoGases: this.includesAllKyotoGases(),
208
- complexity: this.getComplexity(),
209
- };
210
- }
211
- /**
212
- * Representación como string de los greenhouse gas types.
213
- */
214
- toString() {
215
- return this.value.join(', ');
58
+ includesAnyOf(species) {
59
+ return species.some((current) => this.contains(current));
216
60
  }
217
61
  }
218
62
  exports.EmissionCalculationFormulaApplicableGreenhouseGases = EmissionCalculationFormulaApplicableGreenhouseGases;
219
- _a = EmissionCalculationFormulaApplicableGreenhouseGases, _EmissionCalculationFormulaApplicableGreenhouseGases_guardAgainstInvalidGreenhouseGasTypes = function _EmissionCalculationFormulaApplicableGreenhouseGases_guardAgainstInvalidGreenhouseGasTypes(value) {
220
- const validGasTypes = Object.values(GreenhouseGas_1.GreenhouseGas);
221
- const invalidGases = [];
222
- value.forEach((gas, index) => {
223
- if (!validGasTypes.includes(gas)) {
224
- invalidGases.push(`[${index}]: ${gas}`);
225
- }
226
- });
227
- if (invalidGases.length > 0) {
228
- throw InvalidGreenhouseGasTypeError_1.InvalidGreenhouseGasTypeError.create(_a.PROPERTY_NAME, validGasTypes, invalidGases.join(', '));
229
- }
230
- }, _EmissionCalculationFormulaApplicableGreenhouseGases_guardAgainstDuplicateGreenhouseGases = function _EmissionCalculationFormulaApplicableGreenhouseGases_guardAgainstDuplicateGreenhouseGases(value) {
231
- const gasTypeCount = new Map();
232
- const duplicates = [];
233
- // Contar ocurrencias
234
- value.forEach((gas) => {
235
- const count = gasTypeCount.get(gas) || 0;
236
- gasTypeCount.set(gas, count + 1);
237
- });
238
- // Encontrar duplicados
239
- gasTypeCount.forEach((count, gas) => {
240
- if (count > 1) {
241
- duplicates.push(gas);
242
- }
243
- });
244
- if (duplicates.length > 0) {
245
- throw DuplicateGreenhouseGasError_1.DuplicateGreenhouseGasError.create(_a.PROPERTY_NAME, duplicates);
246
- }
247
- };
248
63
  EmissionCalculationFormulaApplicableGreenhouseGases.PROPERTY_NAME = 'applicableGreenhouseGases';
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EmissionFactorGreenhouseGasValues = void 0;
4
4
  const ValueObject_1 = require("../../../../shared/domain/value-objects/ValueObject");
5
- const GreenhouseGas_1 = require("../../../../shared/domain/enums/GreenhouseGas");
5
+ const GreenhouseGasCategory_1 = require("../../../../shared/domain/enums/GreenhouseGasCategory");
6
+ const GreenhouseGasSpecies_1 = require("../../../../shared/domain/value-objects/GreenhouseGasSpecies");
6
7
  const CountryCode_1 = require("../../../../shared/domain/enums/CountryCode");
7
8
  const String_1 = require("../../../../shared/domain/value-objects/String");
8
9
  const Numeric_1 = require("../../../../shared/domain/value-objects/Numeric");
@@ -19,7 +20,8 @@ class EmissionFactorGreenhouseGasValues extends ValueObject_1.ValueObject {
19
20
  }
20
21
  static fromPrimitives(primitives) {
21
22
  const value = primitives.map((primitive) => ({
22
- greenhouseGas: primitive.greenhouseGas,
23
+ greenhouseGasCategory: primitive.greenhouseGasCategory,
24
+ greenhouseGasSpecies: primitive.greenhouseGasSpecies,
23
25
  countryValues: primitive.countryValues.map((countryValue) => countryValue),
24
26
  dataSource: primitive.dataSource,
25
27
  unit: primitive.unit,
@@ -45,14 +47,16 @@ class EmissionFactorGreenhouseGasValues extends ValueObject_1.ValueObject {
45
47
  if (!value || typeof value !== 'object') {
46
48
  throw InvalidPropertyValueError_1.InvalidPropertyValueError.create(propertyName, 'object', typeof value);
47
49
  }
48
- EmissionFactorGreenhouseGasValues.guardAgainstInvalidGreenhouseGas(value.greenhouseGas, `${propertyName}.greenhouseGas`);
50
+ EmissionFactorGreenhouseGasValues.guardAgainstInvalidCategory(value.greenhouseGasCategory, `${propertyName}.greenhouseGasCategory`);
51
+ // Normaliza + valida el código de especie (lanza si el formato es inválido).
52
+ GreenhouseGasSpecies_1.GreenhouseGasSpecies.create(value.greenhouseGasSpecies);
49
53
  EmissionFactorGreenhouseGasValues.guardAgainstInvalidCountryValues(value.countryValues, `${propertyName}.countryValues`);
50
54
  EmissionFactorGreenhouseGasValues.guardAgainstInvalidUnit(value.unit, `${propertyName}.unit`);
51
55
  EmissionFactorGreenhouseGasValues.guardAgainstInvalidDataSource(value.dataSource, `${propertyName}.dataSource`);
52
56
  }
53
- static guardAgainstInvalidGreenhouseGas(greenhouseGas, propertyName) {
54
- if (!Object.values(GreenhouseGas_1.GreenhouseGas).includes(greenhouseGas)) {
55
- throw InvalidPropertyValueError_1.InvalidPropertyValueError.create(propertyName, `valid GreenhouseGas enum value (${Object.values(GreenhouseGas_1.GreenhouseGas).join(', ')})`, `"${greenhouseGas}"`);
57
+ static guardAgainstInvalidCategory(category, propertyName) {
58
+ if (!Object.values(GreenhouseGasCategory_1.GreenhouseGasCategory).includes(category)) {
59
+ throw InvalidPropertyValueError_1.InvalidPropertyValueError.create(propertyName, `valid GreenhouseGasCategory enum value (${Object.values(GreenhouseGasCategory_1.GreenhouseGasCategory).join(', ')})`, `"${category}"`);
56
60
  }
57
61
  }
58
62
  static guardAgainstInvalidCountryValues(countryValues, propertyName) {
@@ -133,10 +137,10 @@ class EmissionFactorGreenhouseGasValues extends ValueObject_1.ValueObject {
133
137
  String_1.String.guardAgainstEmptyValue(dataSource, propertyName);
134
138
  }
135
139
  static guardAgainstDuplicateGreenhouseGases(values, propertyName) {
136
- const greenhouseGases = values.map((value) => value.greenhouseGas);
137
- const uniqueGreenhouseGases = new Set(greenhouseGases);
138
- if (greenhouseGases.length !== uniqueGreenhouseGases.size) {
139
- throw InvalidPropertyValueError_1.InvalidPropertyValueError.create(propertyName, 'unique greenhouse gases', 'duplicate greenhouse gas entries found');
140
+ const species = values.map((value) => GreenhouseGasSpecies_1.GreenhouseGasSpecies.normalize(value.greenhouseGasSpecies));
141
+ const uniqueSpecies = new Set(species);
142
+ if (species.length !== uniqueSpecies.size) {
143
+ throw InvalidPropertyValueError_1.InvalidPropertyValueError.create(propertyName, 'unique greenhouse gas species', 'duplicate greenhouse gas species entries found');
140
144
  }
141
145
  }
142
146
  static guardAgainstDuplicateCountries(countryValues, propertyName) {
@@ -148,7 +152,8 @@ class EmissionFactorGreenhouseGasValues extends ValueObject_1.ValueObject {
148
152
  }
149
153
  static toPrimitivesArray(value) {
150
154
  return value.map((ghgFactorValue) => ({
151
- greenhouseGas: ghgFactorValue.greenhouseGas,
155
+ greenhouseGasCategory: ghgFactorValue.greenhouseGasCategory,
156
+ greenhouseGasSpecies: GreenhouseGasSpecies_1.GreenhouseGasSpecies.normalize(ghgFactorValue.greenhouseGasSpecies),
152
157
  countryValues: ghgFactorValue.countryValues.map((countryValue) => ({
153
158
  country: countryValue.country,
154
159
  factorValue: countryValue.factorValue,
@@ -2,7 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GlobalWarmingPotentialGreenhouseGasPotentials = void 0;
4
4
  const ValueObject_1 = require("../../../../shared/domain/value-objects/ValueObject");
5
- const GreenhouseGas_1 = require("../../../../shared/domain/enums/GreenhouseGas");
5
+ const GreenhouseGasCategory_1 = require("../../../../shared/domain/enums/GreenhouseGasCategory");
6
+ const GreenhouseGasSpecies_1 = require("../../../../shared/domain/value-objects/GreenhouseGasSpecies");
6
7
  const Numeric_1 = require("../../../../shared/domain/value-objects/Numeric");
7
8
  const InvalidPropertyValueError_1 = require("../../../../shared/domain/exceptions/InvalidPropertyValueError");
8
9
  class GlobalWarmingPotentialGreenhouseGasPotentials extends ValueObject_1.ValueObject {
@@ -17,7 +18,8 @@ class GlobalWarmingPotentialGreenhouseGasPotentials extends ValueObject_1.ValueO
17
18
  }
18
19
  static fromPrimitives(primitives) {
19
20
  const value = primitives.map(((primitive) => ({
20
- greenhouseGas: primitive.greenhouseGas,
21
+ greenhouseGasCategory: primitive.greenhouseGasCategory,
22
+ greenhouseGasSpecies: primitive.greenhouseGasSpecies,
21
23
  potentialValue: primitive.potentialValue,
22
24
  })));
23
25
  return new GlobalWarmingPotentialGreenhouseGasPotentials(value, true);
@@ -35,18 +37,20 @@ class GlobalWarmingPotentialGreenhouseGasPotentials extends ValueObject_1.ValueO
35
37
  value.forEach((ghgPotentialValue, index) => {
36
38
  GlobalWarmingPotentialGreenhouseGasPotentials.guardAgainstInvalidGHGPotentialValue(ghgPotentialValue, `${propertyName}[${index}]`);
37
39
  });
38
- GlobalWarmingPotentialGreenhouseGasPotentials.guardAgainstDuplicateGreenhouseGases(value, propertyName);
40
+ GlobalWarmingPotentialGreenhouseGasPotentials.guardAgainstDuplicateSpecies(value, propertyName);
39
41
  }
40
42
  static guardAgainstInvalidGHGPotentialValue(value, propertyName) {
41
43
  if (!value || typeof value !== 'object') {
42
44
  throw InvalidPropertyValueError_1.InvalidPropertyValueError.create(propertyName, 'object', typeof value);
43
45
  }
44
- GlobalWarmingPotentialGreenhouseGasPotentials.guardAgainstInvalidGreenhouseGas(value.greenhouseGas, `${propertyName}.greenhouseGas`);
46
+ GlobalWarmingPotentialGreenhouseGasPotentials.guardAgainstInvalidCategory(value.greenhouseGasCategory, `${propertyName}.greenhouseGasCategory`);
47
+ // Normaliza + valida el código de especie (lanza si el formato es inválido).
48
+ GreenhouseGasSpecies_1.GreenhouseGasSpecies.create(value.greenhouseGasSpecies);
45
49
  GlobalWarmingPotentialGreenhouseGasPotentials.guardAgainstInvalidPotentialValue(value.potentialValue, `${propertyName}.potentialValue`);
46
50
  }
47
- static guardAgainstInvalidGreenhouseGas(greenhouseGas, propertyName) {
48
- if (!Object.values(GreenhouseGas_1.GreenhouseGas).includes(greenhouseGas)) {
49
- throw InvalidPropertyValueError_1.InvalidPropertyValueError.create(propertyName, `valid GreenhouseGas enum value (${Object.values(GreenhouseGas_1.GreenhouseGas).join(', ')})`, `"${greenhouseGas}"`);
51
+ static guardAgainstInvalidCategory(category, propertyName) {
52
+ if (!Object.values(GreenhouseGasCategory_1.GreenhouseGasCategory).includes(category)) {
53
+ throw InvalidPropertyValueError_1.InvalidPropertyValueError.create(propertyName, `valid GreenhouseGasCategory enum value (${Object.values(GreenhouseGasCategory_1.GreenhouseGasCategory).join(', ')})`, `"${category}"`);
50
54
  }
51
55
  }
52
56
  static guardAgainstInvalidPotentialValue(potentialValue, propertyName) {
@@ -58,16 +62,17 @@ class GlobalWarmingPotentialGreenhouseGasPotentials extends ValueObject_1.ValueO
58
62
  throw InvalidPropertyValueError_1.InvalidPropertyValueError.create(propertyName, 'non-negative number', `${potentialValue}`);
59
63
  }
60
64
  }
61
- static guardAgainstDuplicateGreenhouseGases(values, propertyName) {
62
- const greenhouseGases = values.map((value) => value.greenhouseGas);
63
- const uniqueGreenhouseGases = new Set(greenhouseGases);
64
- if (greenhouseGases.length !== uniqueGreenhouseGases.size) {
65
- throw InvalidPropertyValueError_1.InvalidPropertyValueError.create(propertyName, 'unique greenhouse gases', 'duplicate greenhouse gas entries found');
65
+ static guardAgainstDuplicateSpecies(values, propertyName) {
66
+ const species = values.map((value) => GreenhouseGasSpecies_1.GreenhouseGasSpecies.normalize(value.greenhouseGasSpecies));
67
+ const uniqueSpecies = new Set(species);
68
+ if (species.length !== uniqueSpecies.size) {
69
+ throw InvalidPropertyValueError_1.InvalidPropertyValueError.create(propertyName, 'unique greenhouse gas species', 'duplicate greenhouse gas species entries found');
66
70
  }
67
71
  }
68
72
  static toPrimitivesArray(value) {
69
73
  return value.map((ghgPotentialValue) => ({
70
- greenhouseGas: ghgPotentialValue.greenhouseGas,
74
+ greenhouseGasCategory: ghgPotentialValue.greenhouseGasCategory,
75
+ greenhouseGasSpecies: GreenhouseGasSpecies_1.GreenhouseGasSpecies.normalize(ghgPotentialValue.greenhouseGasSpecies),
71
76
  potentialValue: ghgPotentialValue.potentialValue,
72
77
  }));
73
78
  }