@hestia-earth/engine-models 0.65.9 → 0.65.10

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,7 +1,12 @@
1
1
  import { describe, expect, test } from '@jest/globals';
2
2
  import { NodeType } from '@hestia-earth/schema';
3
3
 
4
- import { loadConfig, loadRunConfig, loadTriggerConfig } from './config';
4
+ import {
5
+ loadConfig,
6
+ loadRunConfig,
7
+ loadTriggerConfig,
8
+ getMaxStage
9
+ } from './config';
5
10
 
6
11
  describe('config', () => {
7
12
  describe('loadConfig', () => {
@@ -64,4 +69,20 @@ describe('config', () => {
64
69
  );
65
70
  });
66
71
  });
72
+
73
+ describe('getMaxStage', () => {
74
+ test('existing config', () => {
75
+ expect(getMaxStage(NodeType.Cycle)).toEqual(2);
76
+ expect(getMaxStage(NodeType.Site)).toEqual(2);
77
+ expect(getMaxStage(NodeType.ImpactAssessment)).toEqual(1);
78
+ });
79
+
80
+ test('non-existing config', () => {
81
+ const t = () => getMaxStage('unknown' as any);
82
+
83
+ expect(t).toThrowError(
84
+ 'Invalid type unknown. Allowed types: Cycle, Site, ImpactAssessment'
85
+ );
86
+ });
87
+ });
67
88
  });
package/src/config.ts CHANGED
@@ -1,4 +1,9 @@
1
1
  import { NodeType } from '@hestia-earth/schema';
2
+ import * as runConfig from '../config/run-calculations.json';
3
+ import * as triggerConfig from '../config/trigger-calculations.json';
4
+ import * as Cycle from '../config/Cycle.json';
5
+ import * as ImpactAssessment from '../config/ImpactAssessment.json';
6
+ import * as Site from '../config/Site.json';
2
7
 
3
8
  export interface IOrchestratorModelConfig {
4
9
  key: string;
@@ -29,14 +34,22 @@ const validateType = (nodeType: any) =>
29
34
  );
30
35
  })();
31
36
 
37
+ const typeToConfig: {
38
+ [type in NodeType]?: IOrchestratorConfig;
39
+ } = {
40
+ [NodeType.Cycle]: Cycle as IOrchestratorConfig,
41
+ [NodeType.ImpactAssessment]: ImpactAssessment as IOrchestratorConfig,
42
+ [NodeType.Site]: Site as IOrchestratorConfig
43
+ };
44
+
32
45
  /**
33
46
  * Load orchestrator configuration.
34
47
  *
35
48
  * @param nodeType NodeType associated with configuration.
36
49
  * @returns
37
50
  */
38
- export const loadConfig = (nodeType: allowedType): IOrchestratorConfig =>
39
- validateType(nodeType) && require(`../config/${nodeType}.json`);
51
+ export const loadConfig = (nodeType: allowedType) =>
52
+ validateType(nodeType) && typeToConfig[nodeType];
40
53
 
41
54
  interface ICalculationConfigData {
42
55
  key: 'related' | 'nested';
@@ -67,16 +80,18 @@ const validateStage = (
67
80
 
68
81
  export const loadRunConfig = (nodeType: allowedType, stage: number) =>
69
82
  validateType(nodeType) &&
70
- validateStage(
71
- require('../config/run-calculations.json') as calculationConfig,
72
- nodeType,
73
- stage
74
- );
83
+ validateStage(runConfig as calculationConfig, nodeType, stage);
75
84
 
76
85
  export const loadTriggerConfig = (nodeType: allowedType, stage: number) =>
77
86
  validateType(nodeType) &&
78
- validateStage(
79
- require('../config/trigger-calculations.json') as calculationConfig,
80
- nodeType,
81
- stage
82
- );
87
+ validateStage(triggerConfig as calculationConfig, nodeType, stage);
88
+
89
+ export const getMaxStage = (nodeType: allowedType) =>
90
+ validateType(nodeType)
91
+ ? Math.max.apply(
92
+ Math.max,
93
+ Object.keys((runConfig as calculationConfig)[nodeType]).map((key) =>
94
+ Number(key.replace('stage-', ''))
95
+ )
96
+ )
97
+ : null;
@@ -1,12 +1,11 @@
1
1
  import { describe, expect, test } from '@jest/globals';
2
2
 
3
- import { loadModels } from './models';
3
+ import { models } from './models';
4
4
 
5
5
  describe('models', () => {
6
6
  describe('loadModels', () => {
7
- test('load models', () => {
8
- const { links } = loadModels();
9
- expect(links?.length > 0).toBeTruthy();
7
+ test('has links', () => {
8
+ expect(models.links?.length > 0).toBeTruthy();
10
9
  });
11
10
  });
12
11
  });
package/src/models.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { EmissionMethodTier } from '@hestia-earth/schema';
2
+ import * as data from '../model-links.json';
2
3
 
3
4
  export interface IModel {
4
5
  /**
@@ -33,4 +34,4 @@ export interface IModelLinks {
33
34
  ecoinventV3AndEmberClimateLinks?: IModel[];
34
35
  }
35
36
 
36
- export const loadModels = (): IModelLinks => require('../model-links.json');
37
+ export const models = data as IModelLinks;
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const ENGINE_VERSION = '0.65.9';
1
+ export const ENGINE_VERSION = '0.65.10';