@hestia-earth/data-validation 0.39.2 → 0.40.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.
package/index.mjs ADDED
@@ -0,0 +1,750 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // validation.json
8
+ var validation_exports = {};
9
+ __export(validation_exports, {
10
+ default: () => validation_default,
11
+ validations: () => validations
12
+ });
13
+ var validations = [
14
+ {
15
+ function: "validate_date_lt_today",
16
+ level: "error",
17
+ message: "must be before today"
18
+ },
19
+ {
20
+ function: "validate_node_dates",
21
+ level: "error",
22
+ message: "must be greater than startDate"
23
+ },
24
+ {
25
+ function: "validate_node_dates",
26
+ level: "error",
27
+ message: "must be in the same format as endDate"
28
+ },
29
+ {
30
+ function: "validate_list_dates",
31
+ level: "error",
32
+ message: "must be greater than startDate"
33
+ },
34
+ {
35
+ function: "validate_list_dates_format",
36
+ level: "error",
37
+ message: "must have the same length as endDate"
38
+ },
39
+ {
40
+ function: "validate_list_dates_length",
41
+ level: "error",
42
+ message: "must contain as many items as values"
43
+ },
44
+ {
45
+ function: "validate_list_value_between_min_max",
46
+ level: "error",
47
+ message: "must be between min and max"
48
+ },
49
+ {
50
+ function: "validate_list_min_below_max",
51
+ level: "error",
52
+ message: "must be greater than min"
53
+ },
54
+ {
55
+ function: "validate_list_min_max_lookup",
56
+ level: "error",
57
+ message: "must be above the minimum"
58
+ },
59
+ {
60
+ function: "validate_list_min_max_lookup",
61
+ level: "error",
62
+ message: "must be below the maximum"
63
+ },
64
+ {
65
+ function: "validate_region_list_value_diff_property_lookup",
66
+ level: "warning",
67
+ message: "should be within acceptable range of the lookup value"
68
+ },
69
+ {
70
+ function: "validate_list_term_percent",
71
+ level: "warning",
72
+ message: "may be between 0 and 100"
73
+ },
74
+ {
75
+ function: "validate_list_term_percent",
76
+ level: "error",
77
+ message: "should be between 0 and 100 (percentage)"
78
+ },
79
+ {
80
+ function: "validate_list_percent_requires_value",
81
+ level: "error",
82
+ message: "should have required property 'value'"
83
+ },
84
+ {
85
+ function: "validate_list_valueType",
86
+ level: "error",
87
+ message: "the node value type is incorrect"
88
+ },
89
+ {
90
+ function: "validate_list_has_properties",
91
+ level: "warning",
92
+ message: "should add missing properties"
93
+ },
94
+ {
95
+ function: "validate_is_region",
96
+ level: "error",
97
+ message: "must not be a country"
98
+ },
99
+ {
100
+ function: "validate_region_in_country",
101
+ level: "error",
102
+ message: "must be within the country"
103
+ },
104
+ {
105
+ function: "validate_country",
106
+ level: "error",
107
+ message: "must be a country"
108
+ },
109
+ {
110
+ function: "validate_coordinates",
111
+ level: "error",
112
+ message: "does not contain latitude and longitude"
113
+ },
114
+ {
115
+ function: "validate_area",
116
+ level: "warning",
117
+ message: "should be equal to boundary"
118
+ },
119
+ {
120
+ function: "validate_boundary_area",
121
+ level: "warning",
122
+ message: "boundaryArea should be lower than max size"
123
+ },
124
+ {
125
+ function: "validate_region_size",
126
+ level: "warning",
127
+ message: "should be lower than max size"
128
+ },
129
+ {
130
+ function: "validate_empty_fields",
131
+ level: "warning",
132
+ message: "may not be empty"
133
+ },
134
+ {
135
+ function: "validate_linked_source_privacy",
136
+ level: "error",
137
+ message: "should have the same privacy as the related source"
138
+ },
139
+ {
140
+ function: "validate_private_has_source",
141
+ level: "warning",
142
+ message: "should add a source"
143
+ },
144
+ {
145
+ function: "_validate_list_model",
146
+ level: "error",
147
+ message: "the value provided is not consistent with the model result"
148
+ },
149
+ {
150
+ function: "validate_duplicated_term_units",
151
+ level: "warning",
152
+ message: "should not use identical terms with different units"
153
+ },
154
+ {
155
+ function: "validate_other_model",
156
+ level: "error",
157
+ message: "is required when using other model"
158
+ },
159
+ {
160
+ function: "validate_nested_existing_node",
161
+ level: "warning",
162
+ message: "should not link to an existing node"
163
+ },
164
+ {
165
+ function: "validate_nested_existing_node",
166
+ level: "warning",
167
+ message: "should not link to an existing node"
168
+ },
169
+ {
170
+ function: "validate_lifespan",
171
+ level: "error",
172
+ message: "must equal to endDate - startDate in decimal years"
173
+ },
174
+ {
175
+ function: "validate_method_not_relevant",
176
+ level: "warning",
177
+ message: "should not use not relevant model"
178
+ },
179
+ {
180
+ function: "validate_methodTier_not_relevant",
181
+ level: "warning",
182
+ message: "should not use not relevant methodTier"
183
+ },
184
+ {
185
+ function: "validate_methodTier_background",
186
+ level: "error",
187
+ message: "must not have background methodTier"
188
+ },
189
+ {
190
+ function: "validate_depth",
191
+ level: "warning",
192
+ message: "should set the depth"
193
+ },
194
+ {
195
+ function: "validate_defaultValue",
196
+ level: "warning",
197
+ message: "should specify a value when HESTIA has a default one"
198
+ },
199
+ {
200
+ function: "validate_longFallowDuration",
201
+ level: "error",
202
+ message: "longFallowDuration must be lower than 5 years"
203
+ },
204
+ {
205
+ function: "validate_waterRegime_rice_products",
206
+ level: "error",
207
+ message: "rice products not allowed for this water regime practice"
208
+ },
209
+ {
210
+ function: "validate_croppingDuration_riceGrainInHuskFlooded",
211
+ level: "warning",
212
+ message: "croppingDuration must be between min and max"
213
+ },
214
+ {
215
+ function: "validate_excretaManagement",
216
+ level: "error",
217
+ message: "an excreta input is required when using an excretaManagement practice"
218
+ },
219
+ {
220
+ function: "validate_no_tillage",
221
+ level: "error",
222
+ message: "is not allowed in combination with noTillage"
223
+ },
224
+ {
225
+ function: "validate_tillage_site_type",
226
+ level: "warning",
227
+ message: "should contain a tillage practice"
228
+ },
229
+ {
230
+ function: "validate_tillage_values",
231
+ level: "error",
232
+ message: "cannot use no tillage if depth or number of tillages is not 0"
233
+ },
234
+ {
235
+ function: "validate_tillage_values",
236
+ level: "error",
237
+ message: "cannot use full tillage if depth or number of tillages is 0"
238
+ },
239
+ {
240
+ function: "validate_liveAnimal_system",
241
+ level: "warning",
242
+ message: "should add an animal production system"
243
+ },
244
+ {
245
+ function: "validate_has_pastureGrass",
246
+ level: "warning",
247
+ message: "should add the term pastureGrass"
248
+ },
249
+ {
250
+ function: "validate_pastureGrass_key_termType",
251
+ level: "error",
252
+ message: "pastureGrass key termType must be landCover"
253
+ },
254
+ {
255
+ function: "validate_pastureGrass_key_value",
256
+ level: "error",
257
+ message: "all values must be numbers"
258
+ },
259
+ {
260
+ function: "validate_pastureGrass_key_value",
261
+ level: "error",
262
+ message: "the sum of all pastureGrass values must be 100"
263
+ },
264
+ {
265
+ function: "validate_permanent_crop_productive_phase",
266
+ level: "error",
267
+ message: "must add the term productivePhasePermanentCrops"
268
+ },
269
+ {
270
+ function: "validate_primaryPercent",
271
+ level: "error",
272
+ message: "primaryPercent not allowed on this siteType"
273
+ },
274
+ {
275
+ function: "validate_primaryPercent",
276
+ level: "error",
277
+ message: "primaryPercent not allowed on this practice"
278
+ },
279
+ {
280
+ function: "validate_processing_operation",
281
+ level: "error",
282
+ message: "must have a primary processing operation"
283
+ },
284
+ {
285
+ function: "validate_landCover_match_products",
286
+ level: "error",
287
+ message: "at least one landCover practice must match an equivalent product"
288
+ },
289
+ {
290
+ function: "validate_practices_management",
291
+ level: "error",
292
+ message: "should match the site management node value"
293
+ },
294
+ {
295
+ function: "validate_irrigated_complete_has_inputs",
296
+ level: "error",
297
+ message: "must contain water inputs"
298
+ },
299
+ {
300
+ function: "validate_rainfed_water_inputs",
301
+ level: "error",
302
+ message: "must not set rainfed with water inputs"
303
+ },
304
+ {
305
+ function: "validate_irrigating_operation_rainfed_water_regime",
306
+ level: "warning",
307
+ message: "should use irrigated water regime"
308
+ },
309
+ {
310
+ function: "validate_soilTexture",
311
+ level: "error",
312
+ message: "is outside the allowed range"
313
+ },
314
+ {
315
+ function: "validate_depths",
316
+ level: "error",
317
+ message: "must be greater than or equal to depthUpper"
318
+ },
319
+ {
320
+ function: "validate_required_depths",
321
+ level: "error",
322
+ message: "must set both depthUpper and depthLower"
323
+ },
324
+ {
325
+ function: "validate_required_depths",
326
+ level: "warning",
327
+ message: "should set both depthUpper and depthLower"
328
+ },
329
+ {
330
+ function: "validate_term_unique",
331
+ level: "error",
332
+ message: "must be unique"
333
+ },
334
+ {
335
+ function: "validate_term_unique",
336
+ level: "error",
337
+ message: "must provide value or min and max"
338
+ },
339
+ {
340
+ function: "validate_with_models",
341
+ level: "warning",
342
+ message: "the measurement provided might be in error"
343
+ },
344
+ {
345
+ function: "validate_value_length",
346
+ level: "error",
347
+ message: "must not contain more than 1 value"
348
+ },
349
+ {
350
+ function: "validate_water_measurements",
351
+ level: "error",
352
+ message: "must specify water type for ponds"
353
+ },
354
+ {
355
+ function: "validate_water_salinity",
356
+ level: "error",
357
+ message: "invalid water salinity"
358
+ },
359
+ {
360
+ function: "validate_soil_type_consistency",
361
+ level: "error",
362
+ message: "measurements for the same termType must be consistent"
363
+ },
364
+ {
365
+ function: "validate_characterisedIndicator_model",
366
+ level: "error",
367
+ message: "is not allowed for this characterisedIndicator"
368
+ },
369
+ {
370
+ function: "_below_occupation",
371
+ level: "error",
372
+ message: "must be less than or equal to land occupation"
373
+ },
374
+ {
375
+ function: "validate_inonising_compounds_waste",
376
+ level: "error",
377
+ message: "must be linked to waste input"
378
+ },
379
+ {
380
+ function: "validate_resourceUse_landCover",
381
+ level: "error",
382
+ message: "this field is required"
383
+ },
384
+ {
385
+ function: "validate_resourceUse_landCover",
386
+ level: "error",
387
+ message: "this field is required"
388
+ },
389
+ {
390
+ function: "validate_empty",
391
+ level: "error",
392
+ message: "should not be empty"
393
+ },
394
+ {
395
+ function: "validate_linked_cycle_product",
396
+ level: "error",
397
+ message: "should be included in the cycle products"
398
+ },
399
+ {
400
+ function: "validate_linked_cycle_endDate",
401
+ level: "error",
402
+ message: "must be equal to the Cycle endDate"
403
+ },
404
+ {
405
+ function: "validate_functionalUnit_not_1_ha",
406
+ level: "error",
407
+ message: "must not be equal to 1 ha"
408
+ },
409
+ {
410
+ function: "validate_sum_aboveGroundCropResidue",
411
+ level: "error",
412
+ message: "must be more than or equal to other crop residues"
413
+ },
414
+ {
415
+ function: "validate_crop_residue_complete",
416
+ level: "error",
417
+ message: "must specify the fate of cropResidue"
418
+ },
419
+ {
420
+ function: "validate_crop_residue_incomplete",
421
+ level: "warning",
422
+ message: "should specify the fate of cropResidue"
423
+ },
424
+ {
425
+ function: "validate_cycleDuration",
426
+ level: "error",
427
+ message: "must equal to endDate - startDate in days"
428
+ },
429
+ {
430
+ function: "validate_harvestedArea",
431
+ level: "error",
432
+ message: "must be lower or equal to siteArea"
433
+ },
434
+ {
435
+ function: "validate_maximum_cycleDuration",
436
+ level: "error",
437
+ message: "must be below maximum cycleDuration"
438
+ },
439
+ {
440
+ function: "validate_riceGrainInHuskFlooded_minimum_cycleDuration",
441
+ level: "warning",
442
+ message: "should be more than the cropping duration"
443
+ },
444
+ {
445
+ function: "validate_crop_siteDuration",
446
+ level: "error",
447
+ message: "should be equal to cycleDuration for crop"
448
+ },
449
+ {
450
+ function: "validate_crop_siteDuration",
451
+ level: "error",
452
+ message: "should be greater than cycleDuration for crop"
453
+ },
454
+ {
455
+ function: "validate_animal_siteDuration",
456
+ level: "error",
457
+ message: "should be equal to cycleDuration for animals"
458
+ },
459
+ {
460
+ function: "validate_animal_siteDuration",
461
+ level: "error",
462
+ message: "should be equal to cycleDuration - otherSitesDuration for animals"
463
+ },
464
+ {
465
+ function: "validate_animal_siteDuration",
466
+ level: "error",
467
+ message: "should be less than cycleDuration for animals"
468
+ },
469
+ {
470
+ function: "validate_durations",
471
+ level: "warning",
472
+ message: "should add the fields for a relative cycle"
473
+ },
474
+ {
475
+ function: "validate_possibleCoverCrop",
476
+ level: "error",
477
+ message: "cover crop cycle contains non cover crop product"
478
+ },
479
+ {
480
+ function: "validate_set_treatment",
481
+ level: "warning",
482
+ message: "should specify a treatment when experimentDesign is specified"
483
+ },
484
+ {
485
+ function: "validate_products_animals",
486
+ level: "warning",
487
+ message: "should not specify both liveAnimal and animalProduct"
488
+ },
489
+ {
490
+ function: "validate_stocking_density",
491
+ level: "warning",
492
+ message: "should add the term stockingDensityPermanentPastureAverage"
493
+ },
494
+ {
495
+ function: "validate_linked_impact_assessment",
496
+ level: "error",
497
+ message: "multiple ImpactAssessment are associated with this Product"
498
+ },
499
+ {
500
+ function: "validate_linked_impact_assessment",
501
+ level: "error",
502
+ message: "no ImpactAssessment are associated with this Product"
503
+ },
504
+ {
505
+ function: "validate_animal_product_mapping",
506
+ level: "error",
507
+ message: "is not an allowed animalProduct"
508
+ },
509
+ {
510
+ function: "validate_requires_substrate",
511
+ level: "error",
512
+ message: "must add substrate inputs"
513
+ },
514
+ {
515
+ function: "validate_property_valueType",
516
+ level: "error",
517
+ message: "the property value type is incorrect"
518
+ },
519
+ {
520
+ function: "validate_term_type",
521
+ level: "error",
522
+ message: "can not be used on this termType"
523
+ },
524
+ {
525
+ function: "validate_default_value",
526
+ level: "warning",
527
+ message: "should be within percentage of default value"
528
+ },
529
+ {
530
+ function: "validate_economicValueShare",
531
+ level: "error",
532
+ message: "economicValueShare should sum to 100 or less across all products"
533
+ },
534
+ {
535
+ function: "validate_value_empty",
536
+ level: "warning",
537
+ message: "may not be 0"
538
+ },
539
+ {
540
+ function: "validate_value_0",
541
+ level: "error",
542
+ message: "economicValueShare must be 0 for product value 0"
543
+ },
544
+ {
545
+ function: "validate_value_0",
546
+ level: "error",
547
+ message: "revenue must be 0 for product value 0"
548
+ },
549
+ {
550
+ function: "validate_primary",
551
+ level: "error",
552
+ message: "only 1 primary product allowed"
553
+ },
554
+ {
555
+ function: "validate_product_ha_functional_unit_ha",
556
+ level: "error",
557
+ message: "must be below or equal to 1 for unit in ha"
558
+ },
559
+ {
560
+ function: "_validate_product_yield",
561
+ level: "warning",
562
+ message: "is outside confidence interval"
563
+ },
564
+ {
565
+ function: "validate_excreta_product",
566
+ level: "warning",
567
+ message: "should add an excreta product"
568
+ },
569
+ {
570
+ function: "validate_excreta_product",
571
+ level: "error",
572
+ message: "is not an allowed excreta product"
573
+ },
574
+ {
575
+ function: "validate_has_animals",
576
+ level: "warning",
577
+ message: "should specify the herd composition"
578
+ },
579
+ {
580
+ function: "validate_duplicated_feed_inputs",
581
+ level: "error",
582
+ message: "must not add the feed input to the Cycle as well"
583
+ },
584
+ {
585
+ function: "validate_has_milkYieldPractice",
586
+ level: "warning",
587
+ message: "should specify the a milkYield practice"
588
+ },
589
+ {
590
+ function: "validate_animal_has_recommended_products",
591
+ level: "warning",
592
+ message: "should specify a recommended product"
593
+ },
594
+ {
595
+ function: "validate_must_include_id",
596
+ level: "warning",
597
+ message: "should add missing inputs"
598
+ },
599
+ {
600
+ function: "validate_related_impacts",
601
+ level: "error",
602
+ message: "can not be linked to the same type"
603
+ },
604
+ {
605
+ function: "validate_related_impact_product",
606
+ level: "error",
607
+ message: "can not be linked to a different term"
608
+ },
609
+ {
610
+ function: "_validate_input_value",
611
+ level: "warning",
612
+ message: "is outside confidence interval"
613
+ },
614
+ {
615
+ function: "validate_animalFeed_requires_isAnimalFeed",
616
+ level: "error",
617
+ message: "must specify is it an animal feed"
618
+ },
619
+ {
620
+ function: "validate_saplings",
621
+ level: "error",
622
+ message: "saplings cannot be used as an input here"
623
+ },
624
+ {
625
+ function: "validate_input_is_product",
626
+ level: "error",
627
+ message: "must be a product"
628
+ },
629
+ {
630
+ function: "_validate_all_values",
631
+ level: "warning",
632
+ message: "may not all be set to false"
633
+ },
634
+ {
635
+ function: "_validate_material",
636
+ level: "error",
637
+ message: "must be set to false when specifying fuel use"
638
+ },
639
+ {
640
+ function: "_validate_freshForage",
641
+ level: "error",
642
+ message: "must have inputs representing the forage when set to true"
643
+ },
644
+ {
645
+ function: "_validate_ingredient",
646
+ level: "error",
647
+ message: "must have inputs to represent ingredients"
648
+ },
649
+ {
650
+ function: "_validate_ingredient",
651
+ level: "error",
652
+ message: "ingredients should be complete"
653
+ },
654
+ {
655
+ function: "_validate_animalPopulation",
656
+ level: "error",
657
+ message: "animal population must not be complete"
658
+ },
659
+ {
660
+ function: "_validate_completeness_blank_nodes_key",
661
+ level: "error",
662
+ message: "must not be blank if complete"
663
+ },
664
+ {
665
+ function: "validate_has_termType",
666
+ level: "warning",
667
+ message: "should contain at least one management node"
668
+ },
669
+ {
670
+ function: "validate_fallow_dates",
671
+ level: "error",
672
+ message: "duration must be in specified interval"
673
+ },
674
+ {
675
+ function: "validate_cycles_overlap",
676
+ level: "error",
677
+ message: "management date must be before cycle start date"
678
+ },
679
+ {
680
+ function: "validate_cycle_dates",
681
+ level: "error",
682
+ message: "multiple cycles on the same site cannot overlap"
683
+ },
684
+ {
685
+ function: "validate_cycles_linked_ia",
686
+ level: "error",
687
+ message: "cycles linked together cannot be added to the same site"
688
+ },
689
+ {
690
+ function: "validate_linked_impactAssessment",
691
+ level: "error",
692
+ message: "must be linked to a verified country-level Impact Assessment"
693
+ },
694
+ {
695
+ function: "validate_plantation_practices",
696
+ level: "error",
697
+ message: "must include practices for plantation weighting"
698
+ },
699
+ {
700
+ function: "validate_id",
701
+ level: "error",
702
+ message: "aggregation id must contain a product, region, start, end year, and a timestamp"
703
+ },
704
+ {
705
+ function: "_validate_previous_transformationId",
706
+ level: "error",
707
+ message: "must point to a previous transformation in the list"
708
+ },
709
+ {
710
+ function: "_validate_previous_input",
711
+ level: "error",
712
+ message: "at least one Input must be a Product of the Cycle"
713
+ },
714
+ {
715
+ function: "_validate_previous_input",
716
+ level: "error",
717
+ message: "at least one Input must be a Product of the previous Transformation"
718
+ },
719
+ {
720
+ function: "_validate_previous_product_value",
721
+ level: "error",
722
+ message: "must be equal to previous product multiplied by the share"
723
+ },
724
+ {
725
+ function: "validate_linked_emission",
726
+ level: "warning",
727
+ message: "should be linked to an emission in the Cycle"
728
+ },
729
+ {
730
+ function: "validate_excreta_inputs_products",
731
+ level: "error",
732
+ message: "must be included as an Input"
733
+ }
734
+ ];
735
+ var validation_default = {
736
+ validations
737
+ };
738
+
739
+ // src/validations.ts
740
+ var validations2 = validation_exports;
741
+ var validationsByMessage = validations.reduce(
742
+ (prev, curr) => {
743
+ prev[curr.message] = prev[curr.message] || [];
744
+ prev[curr.message].push(curr);
745
+ return prev;
746
+ },
747
+ {}
748
+ );
749
+
750
+ export { validations2 as validations, validationsByMessage };