@hestia-earth/schema-convert 21.2.0 → 21.3.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.
- package/default-values.d.ts +6 -0
- package/default-values.js +12 -6
- package/package.json +1 -1
package/default-values.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { SchemaType, JSON as HestiaJson, Cycle, Product, Site, Organisation, Term, ImpactAssessment } from '@hestia-earth/schema';
|
|
2
|
+
export declare const siteLocationName: (region?: Term, country?: Term) => string;
|
|
2
3
|
export declare const primaryProduct: (products?: Product[], defaultValue?: Product) => Product;
|
|
4
|
+
export declare const cycleDefaultName: ({ endDate, treatment, description }: Cycle, site?: Site, product?: Product) => string;
|
|
5
|
+
export declare const calculateCycleDuration: ({ cycleDuration, startDate, endDate }: Cycle) => boolean;
|
|
6
|
+
export declare const cycleDefaultDuration: ({ startDate, endDate }: Cycle) => number;
|
|
3
7
|
export declare const extendCycle: (nodes: HestiaJson<SchemaType>[], cycle: Cycle) => Cycle;
|
|
8
|
+
export declare const impactAssessmentDefaultName: ({ product, country, region, endDate }: Partial<ImpactAssessment>) => string;
|
|
4
9
|
export declare const extendImpactAssessment: (_n: HestiaJson<SchemaType>[], impactAssessment: ImpactAssessment) => {
|
|
5
10
|
name: string;
|
|
6
11
|
version?: string;
|
|
@@ -39,5 +44,6 @@ export declare const extendImpactAssessment: (_n: HestiaJson<SchemaType>[], impa
|
|
|
39
44
|
type: SchemaType.ImpactAssessment;
|
|
40
45
|
id?: string;
|
|
41
46
|
};
|
|
47
|
+
export declare const siteDefaultName: ({ siteType, region, country, description }: Site, organisation?: Organisation) => string;
|
|
42
48
|
export declare const extendSite: (nodes: HestiaJson<SchemaType>[], site: Site) => Site;
|
|
43
49
|
export declare const setDefaultValues: (nodes: HestiaJson<any>[]) => (HestiaJson<SchemaType> | Partial<Partial<HestiaJson<SchemaType.Cycle>> | Partial<HestiaJson<SchemaType.ImpactAssessment>> | Partial<HestiaJson<SchemaType.Site>> | Partial<HestiaJson<SchemaType.Actor>> | Partial<HestiaJson<SchemaType.Animal>> | Partial<HestiaJson<SchemaType.Bibliography>> | Partial<HestiaJson<SchemaType.Completeness>> | Partial<HestiaJson<SchemaType.Emission>> | Partial<HestiaJson<SchemaType.Indicator>> | Partial<HestiaJson<SchemaType.Infrastructure>> | Partial<HestiaJson<SchemaType.Input>> | Partial<HestiaJson<SchemaType.Measurement>> | Partial<HestiaJson<SchemaType.Organisation>> | Partial<HestiaJson<SchemaType.Practice>> | Partial<HestiaJson<SchemaType.Product>> | Partial<HestiaJson<SchemaType.Property>> | Partial<HestiaJson<SchemaType.Source>> | Partial<HestiaJson<SchemaType.Term>> | Partial<HestiaJson<SchemaType.Transformation>> | Partial<HestiaJson<SchemaType.Transport>>>)[];
|
package/default-values.js
CHANGED
|
@@ -12,7 +12,7 @@ var __assign = (this && this.__assign) || function () {
|
|
|
12
12
|
};
|
|
13
13
|
var _a;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.setDefaultValues = exports.extendSite = exports.extendImpactAssessment = exports.extendCycle = exports.primaryProduct = void 0;
|
|
15
|
+
exports.setDefaultValues = exports.extendSite = exports.siteDefaultName = exports.extendImpactAssessment = exports.impactAssessmentDefaultName = exports.extendCycle = exports.cycleDefaultDuration = exports.calculateCycleDuration = exports.cycleDefaultName = exports.primaryProduct = exports.siteLocationName = void 0;
|
|
16
16
|
var schema_1 = require("@hestia-earth/schema");
|
|
17
17
|
var utils_1 = require("./utils");
|
|
18
18
|
var findLinkedNode = function (nodes, type, node) {
|
|
@@ -25,6 +25,7 @@ var siteLocationName = function (region, country) { return [
|
|
|
25
25
|
// make sure country doesnt appear in region already, if so don't add it
|
|
26
26
|
(country === null || country === void 0 ? void 0 : country.name) ? ((region === null || region === void 0 ? void 0 : region.name) && region.name.includes(country === null || country === void 0 ? void 0 : country.name) ? undefined : country === null || country === void 0 ? void 0 : country.name) : undefined
|
|
27
27
|
].filter(Boolean).join(', '); };
|
|
28
|
+
exports.siteLocationName = siteLocationName;
|
|
28
29
|
var primaryProduct = function (products, defaultValue) {
|
|
29
30
|
if (defaultValue === void 0) { defaultValue = {}; }
|
|
30
31
|
return (products && products.length ? (products.find(function (product) { return product.primary || product.economicValueShare > 50; }) || products[0]) : null) || defaultValue;
|
|
@@ -33,7 +34,7 @@ exports.primaryProduct = primaryProduct;
|
|
|
33
34
|
var defaultName = function (product, country, region, endDate, treatment, description) {
|
|
34
35
|
return [
|
|
35
36
|
(product === null || product === void 0 ? void 0 : product.name) || 'No Product',
|
|
36
|
-
siteLocationName(region, country),
|
|
37
|
+
(0, exports.siteLocationName)(region, country),
|
|
37
38
|
endDate,
|
|
38
39
|
treatment,
|
|
39
40
|
(0, utils_1.ellipsis)(description, 30)
|
|
@@ -43,40 +44,45 @@ var cycleDefaultName = function (_a, site, product) {
|
|
|
43
44
|
var endDate = _a.endDate, treatment = _a.treatment, description = _a.description;
|
|
44
45
|
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);
|
|
45
46
|
};
|
|
47
|
+
exports.cycleDefaultName = cycleDefaultName;
|
|
46
48
|
var cycleDurationDefault = 365;
|
|
47
49
|
var calculateCycleDuration = function (_a) {
|
|
48
50
|
var cycleDuration = _a.cycleDuration, startDate = _a.startDate, endDate = _a.endDate;
|
|
49
51
|
return (!cycleDuration || cycleDuration === cycleDurationDefault) &&
|
|
50
52
|
startDate && endDate && (new Date(startDate).getTime() < new Date(endDate).getTime());
|
|
51
53
|
};
|
|
54
|
+
exports.calculateCycleDuration = calculateCycleDuration;
|
|
52
55
|
var cycleDefaultDuration = function (_a) {
|
|
53
56
|
var startDate = _a.startDate, endDate = _a.endDate;
|
|
54
57
|
return (0, utils_1.diffInDays)(startDate, endDate);
|
|
55
58
|
};
|
|
59
|
+
exports.cycleDefaultDuration = cycleDefaultDuration;
|
|
56
60
|
var extendCycle = function (nodes, cycle) {
|
|
57
61
|
var product = (0, exports.primaryProduct)(cycle.products);
|
|
58
62
|
var site = findLinkedNode(nodes, schema_1.SchemaType.Site, cycle.site);
|
|
59
|
-
return __assign(__assign(__assign({}, cycle), { name: cycleDefaultName(cycle, site, product) }), (calculateCycleDuration(cycle) ? { cycleDuration: cycleDefaultDuration(cycle) } : {}));
|
|
63
|
+
return __assign(__assign(__assign({}, cycle), { name: (0, exports.cycleDefaultName)(cycle, site, product) }), ((0, exports.calculateCycleDuration)(cycle) ? { cycleDuration: (0, exports.cycleDefaultDuration)(cycle) } : {}));
|
|
60
64
|
};
|
|
61
65
|
exports.extendCycle = extendCycle;
|
|
62
66
|
var impactAssessmentDefaultName = function (_a) {
|
|
63
67
|
var product = _a.product, country = _a.country, region = _a.region, endDate = _a.endDate;
|
|
64
68
|
return defaultName(product === null || product === void 0 ? void 0 : product.term, country, region, endDate);
|
|
65
69
|
};
|
|
66
|
-
|
|
70
|
+
exports.impactAssessmentDefaultName = impactAssessmentDefaultName;
|
|
71
|
+
var extendImpactAssessment = function (_n, impactAssessment) { return (__assign(__assign({}, impactAssessment), { name: impactAssessment.name || (0, exports.impactAssessmentDefaultName)(impactAssessment) })); };
|
|
67
72
|
exports.extendImpactAssessment = extendImpactAssessment;
|
|
68
73
|
var siteDefaultName = function (_a, organisation) {
|
|
69
74
|
var siteType = _a.siteType, region = _a.region, country = _a.country, description = _a.description;
|
|
70
75
|
return [
|
|
71
76
|
siteType ? (0, utils_1.keyToLabel)(siteType) : null,
|
|
72
77
|
organisation === null || organisation === void 0 ? void 0 : organisation.name,
|
|
73
|
-
siteLocationName(region, country),
|
|
78
|
+
(0, exports.siteLocationName)(region, country),
|
|
74
79
|
(0, utils_1.ellipsis)(description, 30)
|
|
75
80
|
].filter(Boolean).join(' - ');
|
|
76
81
|
};
|
|
82
|
+
exports.siteDefaultName = siteDefaultName;
|
|
77
83
|
var extendSite = function (nodes, site) {
|
|
78
84
|
var org = findLinkedNode(nodes, schema_1.SchemaType.Organisation, site.organisation);
|
|
79
|
-
return __assign(__assign({}, site), { name: siteDefaultName(site, org) });
|
|
85
|
+
return __assign(__assign({}, site), { name: (0, exports.siteDefaultName)(site, org) });
|
|
80
86
|
};
|
|
81
87
|
exports.extendSite = extendSite;
|
|
82
88
|
var extendNodeType = (_a = {},
|