@hestia-earth/engine-models 0.87.1 → 0.87.3

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,11 +1,126 @@
1
- import { allowedType, IOrchestratorModelConfig } from './config';
1
+ import { allowedType, IOrchestratorConfig, IOrchestratorModelConfig } from './config';
2
+ /**
3
+ * JSON Schema (draft-07) describing an orchestrator configuration file.
4
+ * Note: it uses no external `$ref` and no `format` keyword, so it compiles with any ajv version.
5
+ */
6
+ export declare const configSchema: {
7
+ $schema: string;
8
+ type: string;
9
+ definitions: {
10
+ runArgs: {
11
+ type: string;
12
+ properties: {
13
+ skipEmptyValue: {
14
+ type: string;
15
+ };
16
+ skipAggregated: {
17
+ type: string;
18
+ };
19
+ termId: {
20
+ type: string;
21
+ };
22
+ runNonAddedTerm: {
23
+ type: string;
24
+ };
25
+ runNonMeasured: {
26
+ type: string;
27
+ };
28
+ };
29
+ };
30
+ mergeArgs: {
31
+ type: string;
32
+ properties: {
33
+ sameMethodModel: {
34
+ type: string;
35
+ };
36
+ skipSameTerm: {
37
+ type: string;
38
+ };
39
+ replaceThreshold: {
40
+ type: string;
41
+ minItems: number;
42
+ maxItems: number;
43
+ items: {
44
+ type: string;
45
+ }[];
46
+ };
47
+ replaceLowerTier: {
48
+ type: string;
49
+ };
50
+ matchDatesFormat: {
51
+ type: string;
52
+ };
53
+ };
54
+ };
55
+ model: {
56
+ type: string;
57
+ properties: {
58
+ key: {
59
+ type: string;
60
+ };
61
+ model: {
62
+ type: string;
63
+ };
64
+ value: {
65
+ type: string;
66
+ };
67
+ runStrategy: {
68
+ type: string;
69
+ enum: string[];
70
+ };
71
+ runArgs: {
72
+ $ref: string;
73
+ };
74
+ mergeStrategy: {
75
+ type: string;
76
+ enum: string[];
77
+ };
78
+ mergeArgs: {
79
+ $ref: string;
80
+ };
81
+ stage: {
82
+ type: string;
83
+ minimum: number;
84
+ maximum: number;
85
+ };
86
+ };
87
+ required: string[];
88
+ };
89
+ "model-list": {
90
+ anyOf: ({
91
+ $ref: string;
92
+ type?: undefined;
93
+ items?: undefined;
94
+ } | {
95
+ type: string;
96
+ items: {
97
+ $ref: string;
98
+ };
99
+ $ref?: undefined;
100
+ })[];
101
+ };
102
+ };
103
+ properties: {
104
+ models: {
105
+ type: string;
106
+ items: {
107
+ $ref: string;
108
+ };
109
+ };
110
+ };
111
+ required: string[];
112
+ };
113
+ /**
114
+ * Either a node type, in which case the bundled configuration is used, or a configuration to validate.
115
+ */
116
+ export type configOrNodeType = allowedType | IOrchestratorConfig;
2
117
  /**
3
118
  * Use inter-dependencies to detect models that are in the wrong order.
4
119
  *
5
- * @param nodeType Cycle, Site, or ImpactAssessment
120
+ * @param config Cycle, Site, or ImpactAssessment to use the bundled configuration, or a configuration itself.
6
121
  * @returns List of models that have dependencies that could not be found prior to running.
7
122
  */
8
- export declare const validateConfigOrder: (nodeType: allowedType) => {
123
+ export declare const validateConfigOrder: (config: configOrNodeType) => {
9
124
  model: IOrchestratorModelConfig;
10
125
  existing: string[];
11
126
  missing: string[];
@@ -14,6 +129,6 @@ export declare const validateConfigOrder: (nodeType: allowedType) => {
14
129
  * Detect multiple models running in parallel when they should not.
15
130
  * Note: we use the `mergeArgs` to handle special cases when multiple identical models CAN run in parallel
16
131
  *
17
- * @param nodeType Cycle, Site, or ImpactAssessment
132
+ * @param config Cycle, Site, or ImpactAssessment to use the bundled configuration, or a configuration itself.
18
133
  */
19
- export declare const validateConfigDuplicates: (nodeType: allowedType) => IOrchestratorModelConfig[];
134
+ export declare const validateConfigDuplicates: (config: configOrNodeType) => IOrchestratorModelConfig[];
@@ -36,9 +36,18 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
36
36
  return to.concat(ar || Array.prototype.slice.call(from));
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.validateConfigDuplicates = exports.validateConfigOrder = void 0;
39
+ exports.validateConfigDuplicates = exports.validateConfigOrder = exports.configSchema = void 0;
40
40
  var config_1 = require("./config");
41
41
  var utils_1 = require("./utils");
42
+ var schema = require("../config/config-schema.json");
43
+ /**
44
+ * JSON Schema (draft-07) describing an orchestrator configuration file.
45
+ * Note: it uses no external `$ref` and no `format` keyword, so it compiles with any ajv version.
46
+ */
47
+ exports.configSchema = schema;
48
+ var resolveConfig = function (config) {
49
+ return typeof config === 'string' ? (0, config_1.loadConfig)(config) : config;
50
+ };
42
51
  // models not included in the links
43
52
  var skipModels = ['emissions.deleted', 'transformations'];
44
53
  var isHestiaResidueCyclicModel = function (_a) {
@@ -85,13 +94,12 @@ var matchDependencies = function (models) { return function (model) {
85
94
  /**
86
95
  * Use inter-dependencies to detect models that are in the wrong order.
87
96
  *
88
- * @param nodeType Cycle, Site, or ImpactAssessment
97
+ * @param config Cycle, Site, or ImpactAssessment to use the bundled configuration, or a configuration itself.
89
98
  * @returns List of models that have dependencies that could not be found prior to running.
90
99
  */
91
- var validateConfigOrder = function (nodeType) {
92
- var config = (0, config_1.loadConfig)(nodeType);
100
+ var validateConfigOrder = function (config) {
93
101
  // flatten all models to process one by one, starting with the last one
94
- var models = config.models.flat();
102
+ var models = resolveConfig(config).models.flat();
95
103
  var results = models.filter(includeModel).map(matchDependencies(models));
96
104
  return results.filter(function (r) { return r.missing.length > 0; });
97
105
  };
@@ -109,12 +117,13 @@ var findDuplicatedConfigs = function (models) {
109
117
  * Detect multiple models running in parallel when they should not.
110
118
  * Note: we use the `mergeArgs` to handle special cases when multiple identical models CAN run in parallel
111
119
  *
112
- * @param nodeType Cycle, Site, or ImpactAssessment
120
+ * @param config Cycle, Site, or ImpactAssessment to use the bundled configuration, or a configuration itself.
113
121
  */
114
- var validateConfigDuplicates = function (nodeType) {
115
- var config = (0, config_1.loadConfig)(nodeType);
116
- var duplicates = config.models
117
- .map(function (value) { return (Array.isArray(value) ? findDuplicatedConfigs(value) : []); })
122
+ var validateConfigDuplicates = function (config) {
123
+ var duplicates = resolveConfig(config)
124
+ .models.map(function (value) {
125
+ return Array.isArray(value) ? findDuplicatedConfigs(value) : [];
126
+ })
118
127
  .flat(2);
119
128
  return duplicates;
120
129
  };
package/cjs/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const ENGINE_VERSION = "0.87.1";
1
+ export declare const ENGINE_VERSION = "0.87.3";
package/cjs/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ENGINE_VERSION = void 0;
4
- exports.ENGINE_VERSION = '0.87.1';
4
+ exports.ENGINE_VERSION = '0.87.3';
@@ -0,0 +1,108 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema",
3
+ "type": "object",
4
+ "definitions": {
5
+ "runArgs": {
6
+ "type": "object",
7
+ "properties": {
8
+ "skipEmptyValue": {
9
+ "type": "boolean"
10
+ },
11
+ "skipAggregated": {
12
+ "type": "boolean"
13
+ },
14
+ "termId": {
15
+ "type": "string"
16
+ },
17
+ "runNonAddedTerm": {
18
+ "type": "boolean"
19
+ },
20
+ "runNonMeasured": {
21
+ "type": "boolean"
22
+ }
23
+ }
24
+ },
25
+ "mergeArgs": {
26
+ "type": "object",
27
+ "properties": {
28
+ "sameMethodModel": {
29
+ "type": "boolean"
30
+ },
31
+ "skipSameTerm": {
32
+ "type": "boolean"
33
+ },
34
+ "replaceThreshold": {
35
+ "type": "array",
36
+ "minItems": 2,
37
+ "maxItems": 2,
38
+ "items": [
39
+ {
40
+ "type": "string"
41
+ },
42
+ {
43
+ "type": "number"
44
+ }
45
+ ]
46
+ },
47
+ "replaceLowerTier": {
48
+ "type": "boolean"
49
+ },
50
+ "matchDatesFormat": {
51
+ "type": "string"
52
+ }
53
+ }
54
+ },
55
+ "model": {
56
+ "type": "object",
57
+ "properties": {
58
+ "key": {
59
+ "type": "string"
60
+ },
61
+ "model": {
62
+ "type": "string"
63
+ },
64
+ "value": {
65
+ "type": "string"
66
+ },
67
+ "runStrategy": {
68
+ "type": "string",
69
+ "enum": ["add_blank_node_if_missing", "add_key_if_missing", "always"]
70
+ },
71
+ "runArgs": {
72
+ "$ref": "#/definitions/runArgs"
73
+ },
74
+ "mergeStrategy": {
75
+ "type": "string",
76
+ "enum": ["default", "list", "node", "append"]
77
+ },
78
+ "mergeArgs": {
79
+ "$ref": "#/definitions/mergeArgs"
80
+ },
81
+ "stage": {
82
+ "type": "integer",
83
+ "minimum": 1,
84
+ "maximum": 2
85
+ }
86
+ },
87
+ "required": ["key", "model", "runStrategy", "mergeStrategy"]
88
+ },
89
+ "model-list": {
90
+ "anyOf": [
91
+ { "$ref": "#/definitions/model" },
92
+ {
93
+ "type": "array",
94
+ "items": { "$ref": "#/definitions/model" }
95
+ }
96
+ ]
97
+ }
98
+ },
99
+ "properties": {
100
+ "models": {
101
+ "type": "array",
102
+ "items": {
103
+ "$ref": "#/definitions/model-list"
104
+ }
105
+ }
106
+ },
107
+ "required": ["models"]
108
+ }
@@ -1,11 +1,126 @@
1
- import { allowedType, IOrchestratorModelConfig } from './config';
1
+ import { allowedType, IOrchestratorConfig, IOrchestratorModelConfig } from './config';
2
+ /**
3
+ * JSON Schema (draft-07) describing an orchestrator configuration file.
4
+ * Note: it uses no external `$ref` and no `format` keyword, so it compiles with any ajv version.
5
+ */
6
+ export declare const configSchema: {
7
+ $schema: string;
8
+ type: string;
9
+ definitions: {
10
+ runArgs: {
11
+ type: string;
12
+ properties: {
13
+ skipEmptyValue: {
14
+ type: string;
15
+ };
16
+ skipAggregated: {
17
+ type: string;
18
+ };
19
+ termId: {
20
+ type: string;
21
+ };
22
+ runNonAddedTerm: {
23
+ type: string;
24
+ };
25
+ runNonMeasured: {
26
+ type: string;
27
+ };
28
+ };
29
+ };
30
+ mergeArgs: {
31
+ type: string;
32
+ properties: {
33
+ sameMethodModel: {
34
+ type: string;
35
+ };
36
+ skipSameTerm: {
37
+ type: string;
38
+ };
39
+ replaceThreshold: {
40
+ type: string;
41
+ minItems: number;
42
+ maxItems: number;
43
+ items: {
44
+ type: string;
45
+ }[];
46
+ };
47
+ replaceLowerTier: {
48
+ type: string;
49
+ };
50
+ matchDatesFormat: {
51
+ type: string;
52
+ };
53
+ };
54
+ };
55
+ model: {
56
+ type: string;
57
+ properties: {
58
+ key: {
59
+ type: string;
60
+ };
61
+ model: {
62
+ type: string;
63
+ };
64
+ value: {
65
+ type: string;
66
+ };
67
+ runStrategy: {
68
+ type: string;
69
+ enum: string[];
70
+ };
71
+ runArgs: {
72
+ $ref: string;
73
+ };
74
+ mergeStrategy: {
75
+ type: string;
76
+ enum: string[];
77
+ };
78
+ mergeArgs: {
79
+ $ref: string;
80
+ };
81
+ stage: {
82
+ type: string;
83
+ minimum: number;
84
+ maximum: number;
85
+ };
86
+ };
87
+ required: string[];
88
+ };
89
+ "model-list": {
90
+ anyOf: ({
91
+ $ref: string;
92
+ type?: undefined;
93
+ items?: undefined;
94
+ } | {
95
+ type: string;
96
+ items: {
97
+ $ref: string;
98
+ };
99
+ $ref?: undefined;
100
+ })[];
101
+ };
102
+ };
103
+ properties: {
104
+ models: {
105
+ type: string;
106
+ items: {
107
+ $ref: string;
108
+ };
109
+ };
110
+ };
111
+ required: string[];
112
+ };
113
+ /**
114
+ * Either a node type, in which case the bundled configuration is used, or a configuration to validate.
115
+ */
116
+ export type configOrNodeType = allowedType | IOrchestratorConfig;
2
117
  /**
3
118
  * Use inter-dependencies to detect models that are in the wrong order.
4
119
  *
5
- * @param nodeType Cycle, Site, or ImpactAssessment
120
+ * @param config Cycle, Site, or ImpactAssessment to use the bundled configuration, or a configuration itself.
6
121
  * @returns List of models that have dependencies that could not be found prior to running.
7
122
  */
8
- export declare const validateConfigOrder: (nodeType: allowedType) => {
123
+ export declare const validateConfigOrder: (config: configOrNodeType) => {
9
124
  model: IOrchestratorModelConfig;
10
125
  existing: string[];
11
126
  missing: string[];
@@ -14,6 +129,6 @@ export declare const validateConfigOrder: (nodeType: allowedType) => {
14
129
  * Detect multiple models running in parallel when they should not.
15
130
  * Note: we use the `mergeArgs` to handle special cases when multiple identical models CAN run in parallel
16
131
  *
17
- * @param nodeType Cycle, Site, or ImpactAssessment
132
+ * @param config Cycle, Site, or ImpactAssessment to use the bundled configuration, or a configuration itself.
18
133
  */
19
- export declare const validateConfigDuplicates: (nodeType: allowedType) => IOrchestratorModelConfig[];
134
+ export declare const validateConfigDuplicates: (config: configOrNodeType) => IOrchestratorModelConfig[];
@@ -1,5 +1,12 @@
1
1
  import { loadConfig } from './config';
2
2
  import { findMatchingModelFromConfig } from './utils';
3
+ import * as schema from '../config/config-schema.json';
4
+ /**
5
+ * JSON Schema (draft-07) describing an orchestrator configuration file.
6
+ * Note: it uses no external `$ref` and no `format` keyword, so it compiles with any ajv version.
7
+ */
8
+ export const configSchema = schema;
9
+ const resolveConfig = (config) => typeof config === 'string' ? loadConfig(config) : config;
3
10
  // models not included in the links
4
11
  const skipModels = ['emissions.deleted', 'transformations'];
5
12
  const isHestiaResidueCyclicModel = ({ model, value }) => model === 'hestia' && (value === null || value === void 0 ? void 0 : value.startsWith('residue'));
@@ -34,13 +41,12 @@ const matchDependencies = (models) => (model) => {
34
41
  /**
35
42
  * Use inter-dependencies to detect models that are in the wrong order.
36
43
  *
37
- * @param nodeType Cycle, Site, or ImpactAssessment
44
+ * @param config Cycle, Site, or ImpactAssessment to use the bundled configuration, or a configuration itself.
38
45
  * @returns List of models that have dependencies that could not be found prior to running.
39
46
  */
40
- export const validateConfigOrder = (nodeType) => {
41
- const config = loadConfig(nodeType);
47
+ export const validateConfigOrder = (config) => {
42
48
  // flatten all models to process one by one, starting with the last one
43
- const models = config.models.flat();
49
+ const models = resolveConfig(config).models.flat();
44
50
  const results = models.filter(includeModel).map(matchDependencies(models));
45
51
  return results.filter((r) => r.missing.length > 0);
46
52
  };
@@ -54,12 +60,11 @@ const findDuplicatedConfigs = (models) => {
54
60
  * Detect multiple models running in parallel when they should not.
55
61
  * Note: we use the `mergeArgs` to handle special cases when multiple identical models CAN run in parallel
56
62
  *
57
- * @param nodeType Cycle, Site, or ImpactAssessment
63
+ * @param config Cycle, Site, or ImpactAssessment to use the bundled configuration, or a configuration itself.
58
64
  */
59
- export const validateConfigDuplicates = (nodeType) => {
60
- const config = loadConfig(nodeType);
61
- const duplicates = config.models
62
- .map((value) => (Array.isArray(value) ? findDuplicatedConfigs(value) : []))
65
+ export const validateConfigDuplicates = (config) => {
66
+ const duplicates = resolveConfig(config)
67
+ .models.map((value) => Array.isArray(value) ? findDuplicatedConfigs(value) : [])
63
68
  .flat(2);
64
69
  return duplicates;
65
70
  };
package/esm/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const ENGINE_VERSION = "0.87.1";
1
+ export declare const ENGINE_VERSION = "0.87.3";
package/esm/version.js CHANGED
@@ -1 +1 @@
1
- export const ENGINE_VERSION = '0.87.1';
1
+ export const ENGINE_VERSION = '0.87.3';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hestia-earth/engine-models",
3
- "version": "0.87.1",
3
+ "version": "0.87.3",
4
4
  "description": "HESTIA Engine Models",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -38,7 +38,7 @@
38
38
  "test": "jest --coverage",
39
39
  "test:jsonld": "hestia-validate-jsonld tests/fixtures",
40
40
  "test:terms": "node scripts/validate-terms-models.js && hestia-validate-terms tests/fixtures",
41
- "validate:config": "ajv validate -s scripts/config-schema.json -d config/Cycle.json -d config/ImpactAssessment.json -d config/Site.json",
41
+ "validate:config": "ajv validate -s config/config-schema.json -d config/Cycle.json -d config/ImpactAssessment.json -d config/Site.json",
42
42
  "validate:models": "node scripts/validate-models-schema.js",
43
43
  "validate:docs": "node scripts/validate-documentation.js",
44
44
  "validate:formula-coverage": "node scripts/formula-coverage.js",