@hestia-earth/schema-convert 30.7.2 → 31.0.0

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.
@@ -1,17 +1,22 @@
1
1
  import { SchemaType, JSON as HestiaJson, Cycle, Product, Site, Organisation, Term, ImpactAssessment } from '@hestia-earth/schema';
2
2
  export declare const siteLocationName: (region?: Term, country?: Term) => string;
3
3
  export declare const primaryProduct: (products?: Product[], defaultValue?: Product) => Product;
4
- export declare const cycleDefaultName: ({ endDate, treatment, description }: Cycle, site?: Site, product?: Product) => string;
4
+ export declare const cycleDefaultName: ({ endDate, treatment, description, products }: Cycle, site?: Site) => string;
5
5
  export declare const defaultSiteArea: (cycle: Cycle) => Partial<Partial<Cycle>>;
6
6
  export declare const extendCycle: (nodes: HestiaJson<SchemaType>[], cycle: Cycle) => Cycle;
7
7
  export declare const impactAssessmentDefaultName: ({ product, country, region, endDate }: Partial<ImpactAssessment>) => string;
8
8
  export declare const extendImpactAssessment: (nodes: HestiaJson<SchemaType>[], impactAssessment: ImpactAssessment) => {
9
+ cycle?: Partial<{
10
+ id: string;
11
+ type: SchemaType;
12
+ name: string;
13
+ description: string;
14
+ }>;
9
15
  name: string;
10
16
  source: import("@hestia-earth/schema").Source;
11
17
  product: Product;
12
18
  version?: string;
13
19
  versionDetails?: string;
14
- cycle?: Cycle;
15
20
  functionalUnitQuantity?: number;
16
21
  allocationMethod?: import("@hestia-earth/schema").ImpactAssessmentAllocationMethod;
17
22
  endDate?: string;
package/default-values.js CHANGED
@@ -48,9 +48,10 @@ var defaultName = function (product, country, region, endDate, treatment, descri
48
48
  .filter(Boolean)
49
49
  .join(' - ');
50
50
  };
51
- var cycleDefaultName = function (_a, site, product) {
52
- var endDate = _a.endDate, treatment = _a.treatment, description = _a.description;
53
- return defaultName(product === null || product === void 0 ? void 0 : product.term, site === null || site === void 0 ? void 0 : site.country, site === null || site === void 0 ? void 0 : site.region, endDate, treatment, description);
51
+ var cycleDefaultName = function (_a, site) {
52
+ var _b;
53
+ var endDate = _a.endDate, treatment = _a.treatment, description = _a.description, products = _a.products;
54
+ return defaultName((_b = (0, exports.primaryProduct)(products)) === null || _b === void 0 ? void 0 : _b.term, site === null || site === void 0 ? void 0 : site.country, site === null || site === void 0 ? void 0 : site.region, endDate, treatment, description);
54
55
  };
55
56
  exports.cycleDefaultName = cycleDefaultName;
56
57
  var defaultSiteArea = function (cycle) {
@@ -59,11 +60,7 @@ var defaultSiteArea = function (cycle) {
59
60
  });
60
61
  };
61
62
  exports.defaultSiteArea = defaultSiteArea;
62
- var extendCycle = function (nodes, cycle) {
63
- var product = (0, exports.primaryProduct)(cycle.products);
64
- var site = findLinkedNode(nodes, schema_1.SchemaType.Site, cycle.site);
65
- return __assign(__assign(__assign({}, cycle), { name: (0, exports.cycleDefaultName)(cycle, site, product) }), (0, exports.defaultSiteArea)(cycle));
66
- };
63
+ var extendCycle = function (nodes, cycle) { return (__assign(__assign(__assign({}, cycle), { name: (0, exports.cycleDefaultName)(cycle, findLinkedNode(nodes, schema_1.SchemaType.Site, cycle.site)) }), (0, exports.defaultSiteArea)(cycle))); };
67
64
  exports.extendCycle = extendCycle;
68
65
  var impactAssessmentDefaultName = function (_a) {
69
66
  var product = _a.product, country = _a.country, region = _a.region, endDate = _a.endDate;
@@ -75,7 +72,17 @@ var extendImpactAssessment = function (nodes, impactAssessment) {
75
72
  var cycle = findLinkedNode(nodes, schema_1.SchemaType.Cycle, impactAssessment.cycle);
76
73
  // replace the product if there is a single match in the Cycle products
77
74
  var products = (_a = cycle === null || cycle === void 0 ? void 0 : cycle.products) === null || _a === void 0 ? void 0 : _a.filter(function (v) { var _a, _b, _c; return ((_a = v.term) === null || _a === void 0 ? void 0 : _a['@id']) === ((_c = (_b = impactAssessment === null || impactAssessment === void 0 ? void 0 : impactAssessment.product) === null || _b === void 0 ? void 0 : _b.term) === null || _c === void 0 ? void 0 : _c['@id']); });
78
- return __assign(__assign({}, impactAssessment), { name: impactAssessment.name || (0, exports.impactAssessmentDefaultName)(impactAssessment), source: impactAssessment.source || (cycle === null || cycle === void 0 ? void 0 : cycle.defaultSource), product: (products === null || products === void 0 ? void 0 : products.length) === 1 ? products[0] : impactAssessment.product });
75
+ var product = (products === null || products === void 0 ? void 0 : products.length) === 1 ? products[0] : impactAssessment.product;
76
+ return __assign(__assign(__assign({}, impactAssessment), { name: impactAssessment.name || (0, exports.impactAssessmentDefaultName)(impactAssessment), source: impactAssessment.source || (cycle === null || cycle === void 0 ? void 0 : cycle.defaultSource), product: product }), (cycle
77
+ ? {
78
+ cycle: (0, utils_1.reduceUndefinedValues)({
79
+ id: cycle.id,
80
+ type: schema_1.SchemaType.Cycle,
81
+ name: cycle.name || (0, exports.cycleDefaultName)(cycle, findLinkedNode(nodes, schema_1.SchemaType.Site, cycle.site)),
82
+ description: cycle.description
83
+ })
84
+ }
85
+ : {}));
79
86
  };
80
87
  exports.extendImpactAssessment = extendImpactAssessment;
81
88
  var siteDefaultName = function (_a, organisation) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/schema-convert",
3
- "version": "30.7.2",
3
+ "version": "31.0.0",
4
4
  "description": "HESTIA Schema Converters",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",