@hestia-earth/engine-models 0.65.6 → 0.65.8
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/config/Cycle.json +2193 -0
- package/config/ImpactAssessment.json +2041 -0
- package/config/Site.json +471 -0
- package/config/run-calculations.json +42 -0
- package/config/trigger-calculations.json +43 -0
- package/dist/config.d.ts +29 -0
- package/dist/config.js +38 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/model-links.json +6 -0
- package/package.json +6 -2
- package/search-results.json +4524 -27
- package/src/config.spec.ts +67 -0
- package/src/config.ts +82 -0
- package/src/index.ts +1 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { describe, expect, test } from '@jest/globals';
|
|
2
|
+
import { NodeType } from '@hestia-earth/schema';
|
|
3
|
+
|
|
4
|
+
import { loadConfig, loadRunConfig, loadTriggerConfig } from './config';
|
|
5
|
+
|
|
6
|
+
describe('config', () => {
|
|
7
|
+
describe('loadConfig', () => {
|
|
8
|
+
test('load existing config', () => {
|
|
9
|
+
const config = loadConfig(NodeType.Cycle);
|
|
10
|
+
expect(config.models?.length > 0).toBeTruthy();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('load non-existing config', () => {
|
|
14
|
+
const t = () => loadConfig('unknown' as any);
|
|
15
|
+
|
|
16
|
+
expect(t).toThrowError(
|
|
17
|
+
'Invalid type unknown. Allowed types: Cycle, Site, ImpactAssessment'
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('loadRunConfig', () => {
|
|
23
|
+
test('load existing config', () => {
|
|
24
|
+
const config = loadRunConfig(NodeType.ImpactAssessment, 1);
|
|
25
|
+
expect(config.length > 0).toBeTruthy();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
test('load non-existing config', () => {
|
|
29
|
+
const t = () => loadRunConfig('unknown' as any, 1);
|
|
30
|
+
|
|
31
|
+
expect(t).toThrowError(
|
|
32
|
+
'Invalid type unknown. Allowed types: Cycle, Site, ImpactAssessment'
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('load non-existing stage', () => {
|
|
37
|
+
const t = () => loadRunConfig(NodeType.ImpactAssessment, 2);
|
|
38
|
+
|
|
39
|
+
expect(t).toThrowError(
|
|
40
|
+
'Invalid stage configuration for ImpactAssessment: 2'
|
|
41
|
+
);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('loadTriggerConfig', () => {
|
|
46
|
+
test('load existing config', () => {
|
|
47
|
+
const config = loadTriggerConfig(NodeType.ImpactAssessment, 1);
|
|
48
|
+
expect(config.length > 0).toBeTruthy();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('load non-existing config', () => {
|
|
52
|
+
const t = () => loadTriggerConfig('unknown' as any, 1);
|
|
53
|
+
|
|
54
|
+
expect(t).toThrowError(
|
|
55
|
+
'Invalid type unknown. Allowed types: Cycle, Site, ImpactAssessment'
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('load non-existing stage', () => {
|
|
60
|
+
const t = () => loadTriggerConfig(NodeType.ImpactAssessment, 2);
|
|
61
|
+
|
|
62
|
+
expect(t).toThrowError(
|
|
63
|
+
'Invalid stage configuration for ImpactAssessment: 2'
|
|
64
|
+
);
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
package/src/config.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { NodeType } from '@hestia-earth/schema';
|
|
2
|
+
|
|
3
|
+
export interface IOrchestratorModelConfig {
|
|
4
|
+
key: string;
|
|
5
|
+
model: string;
|
|
6
|
+
value: string;
|
|
7
|
+
runStrategy: 'always' | 'add_key_if_missing' | 'add_blank_node_if_missing';
|
|
8
|
+
runArgs?: Record<string, any>;
|
|
9
|
+
mergeStrategy: 'default' | 'append' | 'list' | 'node';
|
|
10
|
+
mergeArgs?: Record<string, any>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface IOrchestratorConfig {
|
|
14
|
+
models: (IOrchestratorModelConfig | IOrchestratorModelConfig[])[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const allowedTypes = [NodeType.Cycle, NodeType.Site, NodeType.ImpactAssessment];
|
|
18
|
+
|
|
19
|
+
export type allowedType =
|
|
20
|
+
| NodeType.Cycle
|
|
21
|
+
| NodeType.Site
|
|
22
|
+
| NodeType.ImpactAssessment;
|
|
23
|
+
|
|
24
|
+
const validateType = (nodeType: any) =>
|
|
25
|
+
allowedTypes.includes(nodeType) ||
|
|
26
|
+
(() => {
|
|
27
|
+
throw new Error(
|
|
28
|
+
`Invalid type ${nodeType}. Allowed types: ${allowedTypes.join(', ')}`
|
|
29
|
+
);
|
|
30
|
+
})();
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Load orchestrator configuration.
|
|
34
|
+
*
|
|
35
|
+
* @param nodeType NodeType associated with configuration.
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
export const loadConfig = (nodeType: allowedType): IOrchestratorConfig =>
|
|
39
|
+
validateType(nodeType) && require(`../config/${nodeType}.json`);
|
|
40
|
+
|
|
41
|
+
interface ICalculationConfigData {
|
|
42
|
+
key: 'related' | 'nested';
|
|
43
|
+
type: allowedType;
|
|
44
|
+
stage: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type calculationConfigStage = {
|
|
48
|
+
[stage: string]: ICalculationConfigData[];
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type calculationConfig = {
|
|
52
|
+
[type in allowedType]?: calculationConfigStage;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const validateStage = (
|
|
56
|
+
config: calculationConfig,
|
|
57
|
+
nodeType: allowedType,
|
|
58
|
+
stage: number
|
|
59
|
+
) =>
|
|
60
|
+
`stage-${stage}` in config[nodeType]
|
|
61
|
+
? config[nodeType][`stage-${stage}`]
|
|
62
|
+
: (() => {
|
|
63
|
+
throw new Error(
|
|
64
|
+
`Invalid stage configuration for ${nodeType}: ${stage}`
|
|
65
|
+
);
|
|
66
|
+
})();
|
|
67
|
+
|
|
68
|
+
export const loadRunConfig = (nodeType: allowedType, stage: number) =>
|
|
69
|
+
validateType(nodeType) &&
|
|
70
|
+
validateStage(
|
|
71
|
+
require('../config/run-calculations.json') as calculationConfig,
|
|
72
|
+
nodeType,
|
|
73
|
+
stage
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
export const loadTriggerConfig = (nodeType: allowedType, stage: number) =>
|
|
77
|
+
validateType(nodeType) &&
|
|
78
|
+
validateStage(
|
|
79
|
+
require('../config/trigger-calculations.json') as calculationConfig,
|
|
80
|
+
nodeType,
|
|
81
|
+
stage
|
|
82
|
+
);
|
package/src/index.ts
CHANGED
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const ENGINE_VERSION = '0.65.
|
|
1
|
+
export const ENGINE_VERSION = '0.65.8';
|