@hestia-earth/data-validation 0.41.7 → 0.41.9

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.
@@ -202,6 +202,11 @@ var validations = [
202
202
  level: "error",
203
203
  message: "longFallowDuration must be lower than 5 years"
204
204
  },
205
+ {
206
+ function: "validate_plantationLifespan",
207
+ level: "error",
208
+ message: "must be greater than or equal to plantationProductiveLifespan"
209
+ },
205
210
  {
206
211
  function: "validate_waterRegime_rice_products",
207
212
  level: "error",
@@ -427,6 +432,11 @@ var validations = [
427
432
  level: "warning",
428
433
  message: "should specify the fate of cropResidue"
429
434
  },
435
+ {
436
+ function: "validate_cycleDuration",
437
+ level: "error",
438
+ message: "must be one year prior to endDate"
439
+ },
430
440
  {
431
441
  function: "validate_cycleDuration",
432
442
  level: "error",
@@ -627,6 +637,11 @@ var validations = [
627
637
  level: "error",
628
638
  message: "must specify is it an animal feed"
629
639
  },
640
+ {
641
+ function: "validate_isAnimalFeed_animal_cycle",
642
+ level: "error",
643
+ message: "isAnimalFeed not allowed on a non-animal cycle"
644
+ },
630
645
  {
631
646
  function: "validate_saplings",
632
647
  level: "error",
@@ -637,6 +652,11 @@ var validations = [
637
652
  level: "error",
638
653
  message: "seed cannot be used as an input here"
639
654
  },
655
+ {
656
+ function: "validate_saplings_depreciated",
657
+ level: "error",
658
+ message: "saplingsDepreciatedAmountPerCycle cannot be used as an input here"
659
+ },
640
660
  {
641
661
  function: "validate_material_depreciated",
642
662
  level: "error",
@@ -647,6 +667,11 @@ var validations = [
647
667
  level: "error",
648
668
  message: "must be a product"
649
669
  },
670
+ {
671
+ function: "validate_input_unspecified_term",
672
+ level: "warning",
673
+ message: "should use a specific term"
674
+ },
650
675
  {
651
676
  function: "_validate_all_values",
652
677
  level: "warning",
@@ -682,6 +707,11 @@ var validations = [
682
707
  level: "error",
683
708
  message: "must not be blank if complete"
684
709
  },
710
+ {
711
+ function: "validate_completeness_transport",
712
+ level: "error",
713
+ message: "must have a value or a distance if complete"
714
+ },
685
715
  {
686
716
  function: "validate_has_termType",
687
717
  level: "warning",
@@ -751,6 +781,11 @@ var validations = [
751
781
  function: "validate_excreta_inputs_products",
752
782
  level: "error",
753
783
  message: "must be included as an Input"
784
+ },
785
+ {
786
+ function: "validate_transformation_inputs_value",
787
+ level: "error",
788
+ message: "must be specified for multiple Inputs with the same term"
754
789
  }
755
790
  ];
756
791
 
@@ -1130,6 +1165,20 @@ var guidePageId = (nodeType2, errorMessage) => {
1130
1165
  var mapErrorMessage = "does not contain latitude and longitude";
1131
1166
  var allowedDataPathsLabels = Object.values(schema.SchemaType);
1132
1167
  var isInfrastructureInputTermType = (dataPath = "") => /infrastructure\[\d+\]\.inputs\[\d+\]\.term\.termType$/.test(dataPath);
1168
+ var termTypeRestrictingFields = {
1169
+ [schema.SchemaType.Practice]: {
1170
+ variety: [schema.TermTermType.landCover],
1171
+ ownershipStatus: [schema.TermTermType.operation]
1172
+ }
1173
+ };
1174
+ var isNodeTermTypeRule = (schemaPath = "") => /^#\/allOf\/\d+\/then\/properties\/term\/properties\/termType\/enum$/.test(schemaPath);
1175
+ var sameValues = (values = [], others = []) => values.length === others.length && values.every((value) => others.includes(value));
1176
+ var termTypeRestrictingField = (nodeType2, schemaPath, allowedValues) => {
1177
+ var _a;
1178
+ return isNodeTermTypeRule(schemaPath) ? (_a = Object.entries(termTypeRestrictingFields[nodeType2] || {}).find(
1179
+ ([, termTypes]) => sameValues(termTypes, allowedValues)
1180
+ )) == null ? void 0 : _a[0] : void 0;
1181
+ };
1133
1182
  var idPatternError = (chars) => `You can only use the following characters for this field: ${chars.join(", ")}`;
1134
1183
  var noTillage = { id: "noTillage", name: "No tillage" };
1135
1184
  var pastureGrass = { id: "pastureGrass", name: "Pasture grass" };
@@ -1342,9 +1391,11 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1342
1391
  ${errorCount === 1 ? "Please check the measurement, its depth intervals, and the dates of the measurement or update the soil texture if needed." : "Please check your measurements, their depth intervals, and the dates of the measurements or update the soil textures if needed."}`;
1343
1392
  },
1344
1393
  "should be equal to one of the allowed values": ({ params, dataPath, schemaPath }, count, errors) => {
1345
- var _a;
1394
+ var _a, _b;
1346
1395
  const paths = parseDataPath(dataPath);
1347
- const values = paths.length >= 2 ? pluralize(paths[paths.length - 1].path, ((_a = params == null ? void 0 : params.allowedValues) == null ? void 0 : _a.length) || 0) : "values";
1396
+ const nodeLabel = (_a = paths[paths.length - 3]) == null ? void 0 : _a.label;
1397
+ const restrictingField = dataPath.endsWith("term.termType") ? termTypeRestrictingField(nodeLabel, schemaPath, params == null ? void 0 : params.allowedValues) : null;
1398
+ const values = paths.length >= 2 ? pluralize(paths[paths.length - 1].path, ((_b = params == null ? void 0 : params.allowedValues) == null ? void 0 : _b.length) || 0) : "values";
1348
1399
  const schemaPathMatch = schemaPath == null ? void 0 : schemaPath.split("/").slice(0, 3).join("/");
1349
1400
  const ifError = schemaPathMatch ? errors.find(
1350
1401
  (error) => {
@@ -1359,7 +1410,11 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1359
1410
  return [
1360
1411
  isInfrastructureInputTermType(dataPath) ? `Only terms in the ${listAsCodeWithAnd(params == null ? void 0 : params.allowedValues)} glossaries can be added as inputs to Site
1361
1412
  infrastructure. Other inputs, e.g., ${code("fuel")}, should be specified on the Cycle.
1362
- You can use the ${schemaLink("Input#operation", "operation")} field on inputs to specify what the input is for.` : dataPath.endsWith("term.termType") ? [
1413
+ You can use the ${schemaLink("Input#operation", "operation")} field on inputs to specify what the input is for.` : restrictingField ? `The ${schemaLink(`${nodeLabel}#${restrictingField}`, restrictingField)} field can only be added to ${pluralize(
1414
+ nodeLabel,
1415
+ 0
1416
+ )} using a term from the following glossaries: ${listAsCode(params == null ? void 0 : params.allowedValues)}.
1417
+ Please either remove ${code(restrictingField)} from this ${nodeLabel}, or change the Term to one from the glossaries listed above.` : dataPath.endsWith("term.termType") ? [
1363
1418
  `For ${pluralize(
1364
1419
  paths[paths.length - 3].label,
1365
1420
  0
@@ -1391,6 +1446,10 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1391
1446
  "longFallowDuration must be lower than 5 years": () => `Your long fallow duration is greater than five years.
1392
1447
  Fallow is defined by FAOSTAT as land left uncultivated for between 1 and 5 years,
1393
1448
  and this definition is used for HESTIA also.`,
1449
+ "must be greater than or equal to plantationProductiveLifespan": ({ params }) => `The ${termLink({ id: "plantationLifespan", name: "Plantation lifespan" })} (${code(params == null ? void 0 : params.current)} days)
1450
+ is shorter than the ${termLink({ id: "plantationProductiveLifespan", name: "Plantation productive lifespan" })}
1451
+ (${code(params == null ? void 0 : params.min)} days).
1452
+ The productive lifespan is part of the plantation lifespan, so it cannot be longer. Please check both values.`,
1394
1453
  "should be more than the cropping duration": ({ params }) => `The ${schemaLink(
1395
1454
  "Cycle#cycleDuration",
1396
1455
  "cycleDuration"
@@ -1432,6 +1491,13 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1432
1491
  },
1433
1492
  "must be equal to previous product multiplied by the share": () => `Products from a transformation which are an Input in to the next transformation must follow the following rule:
1434
1493
  ${code("previous.product.value * current.transformedShare / 100 == current.input.value")}`,
1494
+ "must be specified for multiple Inputs with the same term": ({ params }) => {
1495
+ var _a, _b;
1496
+ return `There are multiple Inputs of ${code(((_a = params == null ? void 0 : params.term) == null ? void 0 : _a.name) || ((_b = params == null ? void 0 : params.term) == null ? void 0 : _b["@id"]))} in this Transformation
1497
+ which only differ by fields other than ${code("variety")} or ${code("fate")}, so the ${code("transformedShare")}
1498
+ cannot tell how the Product ${code("value")} should be split between them.
1499
+ Please specify the ${code("value")} of each of these Inputs.`;
1500
+ },
1435
1501
  "at least one Input must be a Product of the Cycle": () => `A Transformation converts a Product from a Cycle into another Product.
1436
1502
  Therefore, at least one Input into the Transformation must be a Product of the Cycle.`,
1437
1503
  "must have only one entry with the same term.termType = excretaManagement": () => `There can only be one Practice of type excretaManagement in a Cycle.
@@ -1479,6 +1545,15 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1479
1545
  (_d = params == null ? void 0 : params.term) == null ? void 0 : _d.termType
1480
1546
  )} which reflects the specific ${glossaryTypeLink((_e = params == null ? void 0 : params.product) == null ? void 0 : _e.termType)}.`;
1481
1547
  },
1548
+ "should use a specific term": ({ params }) => {
1549
+ var _a, _b, _c;
1550
+ return `You have used ${termLink({
1551
+ id: (_a = params == null ? void 0 : params.term) == null ? void 0 : _a["@id"],
1552
+ name: (_b = params == null ? void 0 : params.term) == null ? void 0 : _b.name
1553
+ })}, which does not say what was used.
1554
+ If you know it, choose the specific ${glossaryTypeLink((_c = params == null ? void 0 : params.term) == null ? void 0 : _c.termType)} term instead:
1555
+ background emissions, characterisation factors and completeness all depend on it.`;
1556
+ },
1482
1557
  "should not use several terms describing the same product": ({ params }) => {
1483
1558
  var _a, _b, _c, _d;
1484
1559
  const isFertiliser = ((_a = params == null ? void 0 : params.term) == null ? void 0 : _a.termType) === schema.TermTermType.organicFertiliser;
@@ -1694,6 +1769,12 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1694
1769
  "must specify is it an animal feed": () => `This Cycle is an animal production Cycle and this Input could be an animal feed or could be for another use.
1695
1770
  Please specify the ${schemaLink("Input#isAnimalFeed", "isAnimalFeed")} field on this Input.
1696
1771
  Knowing the fate is essential to distinguish Inputs between those which are fed to animals and those which are used for other purposes.`,
1772
+ "isAnimalFeed not allowed on a non-animal cycle": ({ params }) => `This Cycle does not produce animals: it has no ${schemaLink("Cycle#animals", "animals")} and no ${glossaryTypeLink(
1773
+ schema.TermTermType.liveAnimal
1774
+ )}, ${glossaryTypeLink(schema.TermTermType.animalProduct)} or ${glossaryTypeLink(
1775
+ schema.TermTermType.liveAquaticSpecies
1776
+ )} Product, so ${(params == null ? void 0 : params.term) ? code(params.term.name || params.term["@id"]) : "this Input"} cannot be fed to animals.
1777
+ Please remove the ${schemaLink("Input#isAnimalFeed", "isAnimalFeed")} field${(params == null ? void 0 : params.current) === void 0 ? "" : ` (currently ${code(`${params.current}`)})`} from this Input.`,
1697
1778
  "should specify a treatment when experimentDesign is specified": () => `You have specified that this Source uses an experimental design, but have not specified the treatment for this Cycle.
1698
1779
  Adding the treatment provides important meta-data and will enable greater re-use of these data.
1699
1780
  Add the ${schemaLink("Cycle#treatment", "treatment")} field to the Cycle.
@@ -1837,7 +1918,7 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1837
1918
  ${((_a = params == null ? void 0 : params.term) == null ? void 0 : _a.termType) === schema.TermTermType.measurement ? `This Measurement has additional restrictions and needs either a ${code("value")} or both a ${code("min")} and ${code("max")} specified.
1838
1919
  Please consider adding both the ${code("min")} and the ${code("max")}, or delete the Measurement.` : ""}`;
1839
1920
  },
1840
- "must specify water type for ponds": ({ params }) => `For Sites with ${schemaLink("Site#siteType", "siteType")} = ${code("pond")}, you must specify the ${externalNodeLink(
1921
+ "must specify water type for ponds": ({ params }) => `You must specify the ${externalNodeLink(
1841
1922
  {
1842
1923
  "@type": schema.NodeType.Term,
1843
1924
  "@id": "waterSalinity",
@@ -1854,7 +1935,7 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1854
1935
  name: "Brackish water"
1855
1936
  }
1856
1937
  )}).
1857
- This will allow us to calculate methane emissions from constructed waterbodies.
1938
+ This will allow us to calculate methane emissions from the waterbody.
1858
1939
  ${(params == null ? void 0 : params.products) ? `Note: our gap-filling model can only work when the lookup ${code("defaultSalinity")} is set for all products,
1859
1940
  but we are currently missing a value for: ${joinValues(params.products)}.` : ""}`,
1860
1941
  "invalid water salinity": ({ params }) => `The water type ${params == null ? void 0 : params.current} is not consistent with the Water salinity you specified.
@@ -1967,6 +2048,19 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1967
2048
  `Completeness#${params.expected}`,
1968
2049
  params.expected
1969
2050
  )}, none of the data in the completeness area can have missing or blank values.`,
2051
+ "must have a value or a distance if complete": ({ params }) => {
2052
+ var _a, _b;
2053
+ return `If completeness is set to true for ${schemaLink(
2054
+ `Completeness#${params.expected}`,
2055
+ params.expected
2056
+ )}, every Transport must have a ${schemaLink("Transport#value", "value")} (in tkm) or a ${schemaLink(
2057
+ "Transport#distance",
2058
+ "distance"
2059
+ )} (in km). This ${termLink({
2060
+ id: (_a = params.term) == null ? void 0 : _a["@id"],
2061
+ name: (_b = params.term) == null ? void 0 : _b.name
2062
+ })} has neither.`;
2063
+ },
1970
2064
  "primary product cannot be an input": ({ params }) => params.siteType === schema.SiteSiteType["agri-food processor"] ? `For a processing cycle, the primary Product must not also be an Input into the cycle.
1971
2065
  This ensures we reflect the full process rather than just single sub-processes.
1972
2066
  Use Transformations if needed to represent additional processing steps rather than new Cycles.` : "The primary Product must not also be an Input into the cycle.",
@@ -2002,19 +2096,24 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
2002
2096
  "Saplings"
2003
2097
  )} used divided by the number of possible Cycles in the plantation's lifespan.
2004
2098
  See the ${guideLink("guide-file-upload-special-cases", "special upload case")} for more details.`,
2005
- "seed cannot be used as an input here": ({ params }) => `A plantation crop is established from saplings rather than sown, so a plantation Cycle records ${externalNodeLink(
2099
+ "seed cannot be used as an input here": ({ params }) => `The Cycle only represents plantation crops, which are established from saplings rather than sown, so ${externalNodeLink(
2006
2100
  {
2007
2101
  "@type": schema.NodeType.Term,
2008
2102
  "@id": String(params.expected),
2009
2103
  name: "Saplings, depreciated amount per Cycle"
2010
2104
  }
2011
- )} and not ${code(params.current)}.
2012
- Remove the ${code(
2013
- params.current
2014
- )} Input, or, if it was sown as a cover crop under the plantation, add the ${termLink({
2015
- id: "coverCrop",
2016
- name: "Cover crop"
2017
- })} Practice to the Cycle.`,
2105
+ )} should be used instead of ${code(params.current)}.
2106
+ If this is a case of intercropping, add the relevant ${code(schema.TermTermType.landCover)} Practices to the Cycle, or, if it was sown as a cover crop under the plantation, add the ${termLink(
2107
+ {
2108
+ id: "coverCrop",
2109
+ name: "Cover crop"
2110
+ }
2111
+ )} Practice.`,
2112
+ "saplingsDepreciatedAmountPerCycle cannot be used as an input here": ({ params }) => `The Cycle only represents non-plantation crops, so ${termLink({
2113
+ id: String(params.expected),
2114
+ name: "Seed"
2115
+ })} should be used instead of ${code(params.current)}.
2116
+ If this is a case of intercropping, add the relevant ${code(schema.TermTermType.landCover)} Practices to the Cycle.`,
2018
2117
  "must use the depreciated term": ({ params }) => {
2019
2118
  var _a, _b;
2020
2119
  return `${code(
@@ -2073,6 +2172,10 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
2073
2172
  "must be in the same format as endDate": () => `The date format does not match the format of ${code("endDate")}. You must use the same date format for both fields.`,
2074
2173
  "must be at least equal to the minimum value": ({ params: { min } }) => `Must be at least equal to ${min}`,
2075
2174
  "must equal to endDate - startDate in days": ({ params: { expected } }) => `Must be equal to ${code("endDate")} - ${code("startDate")} in days (inclusive of the ${code("startDate")} and ${code("endDate")} days) (~${expected})`,
2175
+ "must be one year prior to endDate": ({ params: { current, expected } }) => `With a ${schemaLink("Cycle#startDateDefinition", "startDateDefinition")} of ${code("one year prior")}, the ${code(
2176
+ "startDate"
2177
+ )} must be the day after the ${code("endDate")} one year earlier, so that the Cycle covers exactly one year.
2178
+ Your ${code("startDate")} is ${code(current)}; it should be ${code(expected)}.`,
2076
2179
  "must equal to endDate - startDate in decimal years": ({ params: { expected } }) => `Must be equal to ${code("endDate")} - ${code("startDate")} in years (~${expected})`,
2077
2180
  "must be more than or equal to other crop residues": ({ params: { expected } }) => `Must be more than or equal to sum(${expected.join(" + ")})`,
2078
2181
  "should add missing inputs": ({ params: { expected } }) => `Should add missing inputs: ${listAsCode(expected)}`,
@@ -200,6 +200,11 @@ var validations = [
200
200
  level: "error",
201
201
  message: "longFallowDuration must be lower than 5 years"
202
202
  },
203
+ {
204
+ function: "validate_plantationLifespan",
205
+ level: "error",
206
+ message: "must be greater than or equal to plantationProductiveLifespan"
207
+ },
203
208
  {
204
209
  function: "validate_waterRegime_rice_products",
205
210
  level: "error",
@@ -425,6 +430,11 @@ var validations = [
425
430
  level: "warning",
426
431
  message: "should specify the fate of cropResidue"
427
432
  },
433
+ {
434
+ function: "validate_cycleDuration",
435
+ level: "error",
436
+ message: "must be one year prior to endDate"
437
+ },
428
438
  {
429
439
  function: "validate_cycleDuration",
430
440
  level: "error",
@@ -625,6 +635,11 @@ var validations = [
625
635
  level: "error",
626
636
  message: "must specify is it an animal feed"
627
637
  },
638
+ {
639
+ function: "validate_isAnimalFeed_animal_cycle",
640
+ level: "error",
641
+ message: "isAnimalFeed not allowed on a non-animal cycle"
642
+ },
628
643
  {
629
644
  function: "validate_saplings",
630
645
  level: "error",
@@ -635,6 +650,11 @@ var validations = [
635
650
  level: "error",
636
651
  message: "seed cannot be used as an input here"
637
652
  },
653
+ {
654
+ function: "validate_saplings_depreciated",
655
+ level: "error",
656
+ message: "saplingsDepreciatedAmountPerCycle cannot be used as an input here"
657
+ },
638
658
  {
639
659
  function: "validate_material_depreciated",
640
660
  level: "error",
@@ -645,6 +665,11 @@ var validations = [
645
665
  level: "error",
646
666
  message: "must be a product"
647
667
  },
668
+ {
669
+ function: "validate_input_unspecified_term",
670
+ level: "warning",
671
+ message: "should use a specific term"
672
+ },
648
673
  {
649
674
  function: "_validate_all_values",
650
675
  level: "warning",
@@ -680,6 +705,11 @@ var validations = [
680
705
  level: "error",
681
706
  message: "must not be blank if complete"
682
707
  },
708
+ {
709
+ function: "validate_completeness_transport",
710
+ level: "error",
711
+ message: "must have a value or a distance if complete"
712
+ },
683
713
  {
684
714
  function: "validate_has_termType",
685
715
  level: "warning",
@@ -749,6 +779,11 @@ var validations = [
749
779
  function: "validate_excreta_inputs_products",
750
780
  level: "error",
751
781
  message: "must be included as an Input"
782
+ },
783
+ {
784
+ function: "validate_transformation_inputs_value",
785
+ level: "error",
786
+ message: "must be specified for multiple Inputs with the same term"
752
787
  }
753
788
  ];
754
789
 
@@ -1128,6 +1163,20 @@ var guidePageId = (nodeType2, errorMessage) => {
1128
1163
  var mapErrorMessage = "does not contain latitude and longitude";
1129
1164
  var allowedDataPathsLabels = Object.values(SchemaType);
1130
1165
  var isInfrastructureInputTermType = (dataPath = "") => /infrastructure\[\d+\]\.inputs\[\d+\]\.term\.termType$/.test(dataPath);
1166
+ var termTypeRestrictingFields = {
1167
+ [SchemaType.Practice]: {
1168
+ variety: [TermTermType.landCover],
1169
+ ownershipStatus: [TermTermType.operation]
1170
+ }
1171
+ };
1172
+ var isNodeTermTypeRule = (schemaPath = "") => /^#\/allOf\/\d+\/then\/properties\/term\/properties\/termType\/enum$/.test(schemaPath);
1173
+ var sameValues = (values = [], others = []) => values.length === others.length && values.every((value) => others.includes(value));
1174
+ var termTypeRestrictingField = (nodeType2, schemaPath, allowedValues) => {
1175
+ var _a;
1176
+ return isNodeTermTypeRule(schemaPath) ? (_a = Object.entries(termTypeRestrictingFields[nodeType2] || {}).find(
1177
+ ([, termTypes]) => sameValues(termTypes, allowedValues)
1178
+ )) == null ? void 0 : _a[0] : void 0;
1179
+ };
1131
1180
  var idPatternError = (chars) => `You can only use the following characters for this field: ${chars.join(", ")}`;
1132
1181
  var noTillage = { id: "noTillage", name: "No tillage" };
1133
1182
  var pastureGrass = { id: "pastureGrass", name: "Pasture grass" };
@@ -1340,9 +1389,11 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1340
1389
  ${errorCount === 1 ? "Please check the measurement, its depth intervals, and the dates of the measurement or update the soil texture if needed." : "Please check your measurements, their depth intervals, and the dates of the measurements or update the soil textures if needed."}`;
1341
1390
  },
1342
1391
  "should be equal to one of the allowed values": ({ params, dataPath, schemaPath }, count, errors) => {
1343
- var _a;
1392
+ var _a, _b;
1344
1393
  const paths = parseDataPath(dataPath);
1345
- const values = paths.length >= 2 ? pluralize(paths[paths.length - 1].path, ((_a = params == null ? void 0 : params.allowedValues) == null ? void 0 : _a.length) || 0) : "values";
1394
+ const nodeLabel = (_a = paths[paths.length - 3]) == null ? void 0 : _a.label;
1395
+ const restrictingField = dataPath.endsWith("term.termType") ? termTypeRestrictingField(nodeLabel, schemaPath, params == null ? void 0 : params.allowedValues) : null;
1396
+ const values = paths.length >= 2 ? pluralize(paths[paths.length - 1].path, ((_b = params == null ? void 0 : params.allowedValues) == null ? void 0 : _b.length) || 0) : "values";
1346
1397
  const schemaPathMatch = schemaPath == null ? void 0 : schemaPath.split("/").slice(0, 3).join("/");
1347
1398
  const ifError = schemaPathMatch ? errors.find(
1348
1399
  (error) => {
@@ -1357,7 +1408,11 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1357
1408
  return [
1358
1409
  isInfrastructureInputTermType(dataPath) ? `Only terms in the ${listAsCodeWithAnd(params == null ? void 0 : params.allowedValues)} glossaries can be added as inputs to Site
1359
1410
  infrastructure. Other inputs, e.g., ${code("fuel")}, should be specified on the Cycle.
1360
- You can use the ${schemaLink("Input#operation", "operation")} field on inputs to specify what the input is for.` : dataPath.endsWith("term.termType") ? [
1411
+ You can use the ${schemaLink("Input#operation", "operation")} field on inputs to specify what the input is for.` : restrictingField ? `The ${schemaLink(`${nodeLabel}#${restrictingField}`, restrictingField)} field can only be added to ${pluralize(
1412
+ nodeLabel,
1413
+ 0
1414
+ )} using a term from the following glossaries: ${listAsCode(params == null ? void 0 : params.allowedValues)}.
1415
+ Please either remove ${code(restrictingField)} from this ${nodeLabel}, or change the Term to one from the glossaries listed above.` : dataPath.endsWith("term.termType") ? [
1361
1416
  `For ${pluralize(
1362
1417
  paths[paths.length - 3].label,
1363
1418
  0
@@ -1389,6 +1444,10 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1389
1444
  "longFallowDuration must be lower than 5 years": () => `Your long fallow duration is greater than five years.
1390
1445
  Fallow is defined by FAOSTAT as land left uncultivated for between 1 and 5 years,
1391
1446
  and this definition is used for HESTIA also.`,
1447
+ "must be greater than or equal to plantationProductiveLifespan": ({ params }) => `The ${termLink({ id: "plantationLifespan", name: "Plantation lifespan" })} (${code(params == null ? void 0 : params.current)} days)
1448
+ is shorter than the ${termLink({ id: "plantationProductiveLifespan", name: "Plantation productive lifespan" })}
1449
+ (${code(params == null ? void 0 : params.min)} days).
1450
+ The productive lifespan is part of the plantation lifespan, so it cannot be longer. Please check both values.`,
1392
1451
  "should be more than the cropping duration": ({ params }) => `The ${schemaLink(
1393
1452
  "Cycle#cycleDuration",
1394
1453
  "cycleDuration"
@@ -1430,6 +1489,13 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1430
1489
  },
1431
1490
  "must be equal to previous product multiplied by the share": () => `Products from a transformation which are an Input in to the next transformation must follow the following rule:
1432
1491
  ${code("previous.product.value * current.transformedShare / 100 == current.input.value")}`,
1492
+ "must be specified for multiple Inputs with the same term": ({ params }) => {
1493
+ var _a, _b;
1494
+ return `There are multiple Inputs of ${code(((_a = params == null ? void 0 : params.term) == null ? void 0 : _a.name) || ((_b = params == null ? void 0 : params.term) == null ? void 0 : _b["@id"]))} in this Transformation
1495
+ which only differ by fields other than ${code("variety")} or ${code("fate")}, so the ${code("transformedShare")}
1496
+ cannot tell how the Product ${code("value")} should be split between them.
1497
+ Please specify the ${code("value")} of each of these Inputs.`;
1498
+ },
1433
1499
  "at least one Input must be a Product of the Cycle": () => `A Transformation converts a Product from a Cycle into another Product.
1434
1500
  Therefore, at least one Input into the Transformation must be a Product of the Cycle.`,
1435
1501
  "must have only one entry with the same term.termType = excretaManagement": () => `There can only be one Practice of type excretaManagement in a Cycle.
@@ -1477,6 +1543,15 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1477
1543
  (_d = params == null ? void 0 : params.term) == null ? void 0 : _d.termType
1478
1544
  )} which reflects the specific ${glossaryTypeLink((_e = params == null ? void 0 : params.product) == null ? void 0 : _e.termType)}.`;
1479
1545
  },
1546
+ "should use a specific term": ({ params }) => {
1547
+ var _a, _b, _c;
1548
+ return `You have used ${termLink({
1549
+ id: (_a = params == null ? void 0 : params.term) == null ? void 0 : _a["@id"],
1550
+ name: (_b = params == null ? void 0 : params.term) == null ? void 0 : _b.name
1551
+ })}, which does not say what was used.
1552
+ If you know it, choose the specific ${glossaryTypeLink((_c = params == null ? void 0 : params.term) == null ? void 0 : _c.termType)} term instead:
1553
+ background emissions, characterisation factors and completeness all depend on it.`;
1554
+ },
1480
1555
  "should not use several terms describing the same product": ({ params }) => {
1481
1556
  var _a, _b, _c, _d;
1482
1557
  const isFertiliser = ((_a = params == null ? void 0 : params.term) == null ? void 0 : _a.termType) === TermTermType.organicFertiliser;
@@ -1692,6 +1767,12 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1692
1767
  "must specify is it an animal feed": () => `This Cycle is an animal production Cycle and this Input could be an animal feed or could be for another use.
1693
1768
  Please specify the ${schemaLink("Input#isAnimalFeed", "isAnimalFeed")} field on this Input.
1694
1769
  Knowing the fate is essential to distinguish Inputs between those which are fed to animals and those which are used for other purposes.`,
1770
+ "isAnimalFeed not allowed on a non-animal cycle": ({ params }) => `This Cycle does not produce animals: it has no ${schemaLink("Cycle#animals", "animals")} and no ${glossaryTypeLink(
1771
+ TermTermType.liveAnimal
1772
+ )}, ${glossaryTypeLink(TermTermType.animalProduct)} or ${glossaryTypeLink(
1773
+ TermTermType.liveAquaticSpecies
1774
+ )} Product, so ${(params == null ? void 0 : params.term) ? code(params.term.name || params.term["@id"]) : "this Input"} cannot be fed to animals.
1775
+ Please remove the ${schemaLink("Input#isAnimalFeed", "isAnimalFeed")} field${(params == null ? void 0 : params.current) === void 0 ? "" : ` (currently ${code(`${params.current}`)})`} from this Input.`,
1695
1776
  "should specify a treatment when experimentDesign is specified": () => `You have specified that this Source uses an experimental design, but have not specified the treatment for this Cycle.
1696
1777
  Adding the treatment provides important meta-data and will enable greater re-use of these data.
1697
1778
  Add the ${schemaLink("Cycle#treatment", "treatment")} field to the Cycle.
@@ -1835,7 +1916,7 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1835
1916
  ${((_a = params == null ? void 0 : params.term) == null ? void 0 : _a.termType) === TermTermType.measurement ? `This Measurement has additional restrictions and needs either a ${code("value")} or both a ${code("min")} and ${code("max")} specified.
1836
1917
  Please consider adding both the ${code("min")} and the ${code("max")}, or delete the Measurement.` : ""}`;
1837
1918
  },
1838
- "must specify water type for ponds": ({ params }) => `For Sites with ${schemaLink("Site#siteType", "siteType")} = ${code("pond")}, you must specify the ${externalNodeLink(
1919
+ "must specify water type for ponds": ({ params }) => `You must specify the ${externalNodeLink(
1839
1920
  {
1840
1921
  "@type": NodeType.Term,
1841
1922
  "@id": "waterSalinity",
@@ -1852,7 +1933,7 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1852
1933
  name: "Brackish water"
1853
1934
  }
1854
1935
  )}).
1855
- This will allow us to calculate methane emissions from constructed waterbodies.
1936
+ This will allow us to calculate methane emissions from the waterbody.
1856
1937
  ${(params == null ? void 0 : params.products) ? `Note: our gap-filling model can only work when the lookup ${code("defaultSalinity")} is set for all products,
1857
1938
  but we are currently missing a value for: ${joinValues(params.products)}.` : ""}`,
1858
1939
  "invalid water salinity": ({ params }) => `The water type ${params == null ? void 0 : params.current} is not consistent with the Water salinity you specified.
@@ -1965,6 +2046,19 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
1965
2046
  `Completeness#${params.expected}`,
1966
2047
  params.expected
1967
2048
  )}, none of the data in the completeness area can have missing or blank values.`,
2049
+ "must have a value or a distance if complete": ({ params }) => {
2050
+ var _a, _b;
2051
+ return `If completeness is set to true for ${schemaLink(
2052
+ `Completeness#${params.expected}`,
2053
+ params.expected
2054
+ )}, every Transport must have a ${schemaLink("Transport#value", "value")} (in tkm) or a ${schemaLink(
2055
+ "Transport#distance",
2056
+ "distance"
2057
+ )} (in km). This ${termLink({
2058
+ id: (_a = params.term) == null ? void 0 : _a["@id"],
2059
+ name: (_b = params.term) == null ? void 0 : _b.name
2060
+ })} has neither.`;
2061
+ },
1968
2062
  "primary product cannot be an input": ({ params }) => params.siteType === SiteSiteType["agri-food processor"] ? `For a processing cycle, the primary Product must not also be an Input into the cycle.
1969
2063
  This ensures we reflect the full process rather than just single sub-processes.
1970
2064
  Use Transformations if needed to represent additional processing steps rather than new Cycles.` : "The primary Product must not also be an Input into the cycle.",
@@ -2000,19 +2094,24 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
2000
2094
  "Saplings"
2001
2095
  )} used divided by the number of possible Cycles in the plantation's lifespan.
2002
2096
  See the ${guideLink("guide-file-upload-special-cases", "special upload case")} for more details.`,
2003
- "seed cannot be used as an input here": ({ params }) => `A plantation crop is established from saplings rather than sown, so a plantation Cycle records ${externalNodeLink(
2097
+ "seed cannot be used as an input here": ({ params }) => `The Cycle only represents plantation crops, which are established from saplings rather than sown, so ${externalNodeLink(
2004
2098
  {
2005
2099
  "@type": NodeType.Term,
2006
2100
  "@id": String(params.expected),
2007
2101
  name: "Saplings, depreciated amount per Cycle"
2008
2102
  }
2009
- )} and not ${code(params.current)}.
2010
- Remove the ${code(
2011
- params.current
2012
- )} Input, or, if it was sown as a cover crop under the plantation, add the ${termLink({
2013
- id: "coverCrop",
2014
- name: "Cover crop"
2015
- })} Practice to the Cycle.`,
2103
+ )} should be used instead of ${code(params.current)}.
2104
+ If this is a case of intercropping, add the relevant ${code(TermTermType.landCover)} Practices to the Cycle, or, if it was sown as a cover crop under the plantation, add the ${termLink(
2105
+ {
2106
+ id: "coverCrop",
2107
+ name: "Cover crop"
2108
+ }
2109
+ )} Practice.`,
2110
+ "saplingsDepreciatedAmountPerCycle cannot be used as an input here": ({ params }) => `The Cycle only represents non-plantation crops, so ${termLink({
2111
+ id: String(params.expected),
2112
+ name: "Seed"
2113
+ })} should be used instead of ${code(params.current)}.
2114
+ If this is a case of intercropping, add the relevant ${code(TermTermType.landCover)} Practices to the Cycle.`,
2016
2115
  "must use the depreciated term": ({ params }) => {
2017
2116
  var _a, _b;
2018
2117
  return `${code(
@@ -2071,6 +2170,10 @@ var createErrorFormatter = ({ renderer: r, urls }) => {
2071
2170
  "must be in the same format as endDate": () => `The date format does not match the format of ${code("endDate")}. You must use the same date format for both fields.`,
2072
2171
  "must be at least equal to the minimum value": ({ params: { min } }) => `Must be at least equal to ${min}`,
2073
2172
  "must equal to endDate - startDate in days": ({ params: { expected } }) => `Must be equal to ${code("endDate")} - ${code("startDate")} in days (inclusive of the ${code("startDate")} and ${code("endDate")} days) (~${expected})`,
2173
+ "must be one year prior to endDate": ({ params: { current, expected } }) => `With a ${schemaLink("Cycle#startDateDefinition", "startDateDefinition")} of ${code("one year prior")}, the ${code(
2174
+ "startDate"
2175
+ )} must be the day after the ${code("endDate")} one year earlier, so that the Cycle covers exactly one year.
2176
+ Your ${code("startDate")} is ${code(current)}; it should be ${code(expected)}.`,
2074
2177
  "must equal to endDate - startDate in decimal years": ({ params: { expected } }) => `Must be equal to ${code("endDate")} - ${code("startDate")} in years (~${expected})`,
2075
2178
  "must be more than or equal to other crop residues": ({ params: { expected } }) => `Must be more than or equal to sum(${expected.join(" + ")})`,
2076
2179
  "should add missing inputs": ({ params: { expected } }) => `Should add missing inputs: ${listAsCode(expected)}`,
package/index.js CHANGED
@@ -208,6 +208,11 @@ var validations = [
208
208
  level: "error",
209
209
  message: "longFallowDuration must be lower than 5 years"
210
210
  },
211
+ {
212
+ function: "validate_plantationLifespan",
213
+ level: "error",
214
+ message: "must be greater than or equal to plantationProductiveLifespan"
215
+ },
211
216
  {
212
217
  function: "validate_waterRegime_rice_products",
213
218
  level: "error",
@@ -433,6 +438,11 @@ var validations = [
433
438
  level: "warning",
434
439
  message: "should specify the fate of cropResidue"
435
440
  },
441
+ {
442
+ function: "validate_cycleDuration",
443
+ level: "error",
444
+ message: "must be one year prior to endDate"
445
+ },
436
446
  {
437
447
  function: "validate_cycleDuration",
438
448
  level: "error",
@@ -633,6 +643,11 @@ var validations = [
633
643
  level: "error",
634
644
  message: "must specify is it an animal feed"
635
645
  },
646
+ {
647
+ function: "validate_isAnimalFeed_animal_cycle",
648
+ level: "error",
649
+ message: "isAnimalFeed not allowed on a non-animal cycle"
650
+ },
636
651
  {
637
652
  function: "validate_saplings",
638
653
  level: "error",
@@ -643,6 +658,11 @@ var validations = [
643
658
  level: "error",
644
659
  message: "seed cannot be used as an input here"
645
660
  },
661
+ {
662
+ function: "validate_saplings_depreciated",
663
+ level: "error",
664
+ message: "saplingsDepreciatedAmountPerCycle cannot be used as an input here"
665
+ },
646
666
  {
647
667
  function: "validate_material_depreciated",
648
668
  level: "error",
@@ -653,6 +673,11 @@ var validations = [
653
673
  level: "error",
654
674
  message: "must be a product"
655
675
  },
676
+ {
677
+ function: "validate_input_unspecified_term",
678
+ level: "warning",
679
+ message: "should use a specific term"
680
+ },
656
681
  {
657
682
  function: "_validate_all_values",
658
683
  level: "warning",
@@ -688,6 +713,11 @@ var validations = [
688
713
  level: "error",
689
714
  message: "must not be blank if complete"
690
715
  },
716
+ {
717
+ function: "validate_completeness_transport",
718
+ level: "error",
719
+ message: "must have a value or a distance if complete"
720
+ },
691
721
  {
692
722
  function: "validate_has_termType",
693
723
  level: "warning",
@@ -757,6 +787,11 @@ var validations = [
757
787
  function: "validate_excreta_inputs_products",
758
788
  level: "error",
759
789
  message: "must be included as an Input"
790
+ },
791
+ {
792
+ function: "validate_transformation_inputs_value",
793
+ level: "error",
794
+ message: "must be specified for multiple Inputs with the same term"
760
795
  }
761
796
  ];
762
797
  var validation_default = {
package/index.mjs CHANGED
@@ -206,6 +206,11 @@ var validations = [
206
206
  level: "error",
207
207
  message: "longFallowDuration must be lower than 5 years"
208
208
  },
209
+ {
210
+ function: "validate_plantationLifespan",
211
+ level: "error",
212
+ message: "must be greater than or equal to plantationProductiveLifespan"
213
+ },
209
214
  {
210
215
  function: "validate_waterRegime_rice_products",
211
216
  level: "error",
@@ -431,6 +436,11 @@ var validations = [
431
436
  level: "warning",
432
437
  message: "should specify the fate of cropResidue"
433
438
  },
439
+ {
440
+ function: "validate_cycleDuration",
441
+ level: "error",
442
+ message: "must be one year prior to endDate"
443
+ },
434
444
  {
435
445
  function: "validate_cycleDuration",
436
446
  level: "error",
@@ -631,6 +641,11 @@ var validations = [
631
641
  level: "error",
632
642
  message: "must specify is it an animal feed"
633
643
  },
644
+ {
645
+ function: "validate_isAnimalFeed_animal_cycle",
646
+ level: "error",
647
+ message: "isAnimalFeed not allowed on a non-animal cycle"
648
+ },
634
649
  {
635
650
  function: "validate_saplings",
636
651
  level: "error",
@@ -641,6 +656,11 @@ var validations = [
641
656
  level: "error",
642
657
  message: "seed cannot be used as an input here"
643
658
  },
659
+ {
660
+ function: "validate_saplings_depreciated",
661
+ level: "error",
662
+ message: "saplingsDepreciatedAmountPerCycle cannot be used as an input here"
663
+ },
644
664
  {
645
665
  function: "validate_material_depreciated",
646
666
  level: "error",
@@ -651,6 +671,11 @@ var validations = [
651
671
  level: "error",
652
672
  message: "must be a product"
653
673
  },
674
+ {
675
+ function: "validate_input_unspecified_term",
676
+ level: "warning",
677
+ message: "should use a specific term"
678
+ },
654
679
  {
655
680
  function: "_validate_all_values",
656
681
  level: "warning",
@@ -686,6 +711,11 @@ var validations = [
686
711
  level: "error",
687
712
  message: "must not be blank if complete"
688
713
  },
714
+ {
715
+ function: "validate_completeness_transport",
716
+ level: "error",
717
+ message: "must have a value or a distance if complete"
718
+ },
689
719
  {
690
720
  function: "validate_has_termType",
691
721
  level: "warning",
@@ -755,6 +785,11 @@ var validations = [
755
785
  function: "validate_excreta_inputs_products",
756
786
  level: "error",
757
787
  message: "must be included as an Input"
788
+ },
789
+ {
790
+ function: "validate_transformation_inputs_value",
791
+ level: "error",
792
+ message: "must be specified for multiple Inputs with the same term"
758
793
  }
759
794
  ];
760
795
  var validation_default = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/data-validation",
3
- "version": "0.41.7",
3
+ "version": "0.41.9",
4
4
  "description": "HESTIA Data Validation library",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
package/validation.json CHANGED
@@ -195,6 +195,11 @@
195
195
  "level": "error",
196
196
  "message": "longFallowDuration must be lower than 5 years"
197
197
  },
198
+ {
199
+ "function": "validate_plantationLifespan",
200
+ "level": "error",
201
+ "message": "must be greater than or equal to plantationProductiveLifespan"
202
+ },
198
203
  {
199
204
  "function": "validate_waterRegime_rice_products",
200
205
  "level": "error",
@@ -420,6 +425,11 @@
420
425
  "level": "warning",
421
426
  "message": "should specify the fate of cropResidue"
422
427
  },
428
+ {
429
+ "function": "validate_cycleDuration",
430
+ "level": "error",
431
+ "message": "must be one year prior to endDate"
432
+ },
423
433
  {
424
434
  "function": "validate_cycleDuration",
425
435
  "level": "error",
@@ -620,6 +630,11 @@
620
630
  "level": "error",
621
631
  "message": "must specify is it an animal feed"
622
632
  },
633
+ {
634
+ "function": "validate_isAnimalFeed_animal_cycle",
635
+ "level": "error",
636
+ "message": "isAnimalFeed not allowed on a non-animal cycle"
637
+ },
623
638
  {
624
639
  "function": "validate_saplings",
625
640
  "level": "error",
@@ -630,6 +645,11 @@
630
645
  "level": "error",
631
646
  "message": "seed cannot be used as an input here"
632
647
  },
648
+ {
649
+ "function": "validate_saplings_depreciated",
650
+ "level": "error",
651
+ "message": "saplingsDepreciatedAmountPerCycle cannot be used as an input here"
652
+ },
633
653
  {
634
654
  "function": "validate_material_depreciated",
635
655
  "level": "error",
@@ -640,6 +660,11 @@
640
660
  "level": "error",
641
661
  "message": "must be a product"
642
662
  },
663
+ {
664
+ "function": "validate_input_unspecified_term",
665
+ "level": "warning",
666
+ "message": "should use a specific term"
667
+ },
643
668
  {
644
669
  "function": "_validate_all_values",
645
670
  "level": "warning",
@@ -675,6 +700,11 @@
675
700
  "level": "error",
676
701
  "message": "must not be blank if complete"
677
702
  },
703
+ {
704
+ "function": "validate_completeness_transport",
705
+ "level": "error",
706
+ "message": "must have a value or a distance if complete"
707
+ },
678
708
  {
679
709
  "function": "validate_has_termType",
680
710
  "level": "warning",
@@ -744,6 +774,11 @@
744
774
  "function": "validate_excreta_inputs_products",
745
775
  "level": "error",
746
776
  "message": "must be included as an Input"
777
+ },
778
+ {
779
+ "function": "validate_transformation_inputs_value",
780
+ "level": "error",
781
+ "message": "must be specified for multiple Inputs with the same term"
747
782
  }
748
783
  ]
749
784
  }