2023-10-10 12:32:17 +00:00
|
|
|
import type { ConfigTree, DataTree } from "entities/DataTree/dataTreeTypes";
|
2023-04-03 10:41:15 +00:00
|
|
|
import { isEmpty } from "lodash";
|
|
|
|
|
import type { EvalContext } from "workers/Evaluation/evaluate";
|
2023-07-08 14:07:26 +00:00
|
|
|
import { getEvaluationContext } from "./utils/getEvaluationContext";
|
2023-04-03 10:41:15 +00:00
|
|
|
|
|
|
|
|
class GlobalData {
|
|
|
|
|
globalDataWithFunctions: EvalContext = {};
|
|
|
|
|
globalDataWithoutFunctions: EvalContext = {};
|
|
|
|
|
unevalTree: DataTree = {};
|
2023-07-08 14:07:26 +00:00
|
|
|
configTree: ConfigTree = {};
|
2023-04-03 10:41:15 +00:00
|
|
|
cloudHosting = false;
|
|
|
|
|
|
2023-07-08 14:07:26 +00:00
|
|
|
initialize(
|
|
|
|
|
unevalTree: DataTree,
|
|
|
|
|
configTree: ConfigTree,
|
|
|
|
|
cloudHosting: boolean,
|
|
|
|
|
) {
|
2023-04-03 10:41:15 +00:00
|
|
|
this.globalDataWithFunctions = {};
|
|
|
|
|
this.globalDataWithoutFunctions = {};
|
|
|
|
|
this.unevalTree = unevalTree;
|
2023-07-08 14:07:26 +00:00
|
|
|
this.configTree = configTree;
|
2023-04-03 10:41:15 +00:00
|
|
|
this.cloudHosting = cloudHosting;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getGlobalData(withFunctions: boolean) {
|
|
|
|
|
// Our goal is to create global data (with or without functions) only once during a linting cycle
|
|
|
|
|
if (withFunctions) {
|
|
|
|
|
if (isEmpty(this.globalDataWithFunctions)) {
|
|
|
|
|
this.globalDataWithFunctions = getEvaluationContext(
|
|
|
|
|
this.unevalTree,
|
2023-07-08 14:07:26 +00:00
|
|
|
this.configTree,
|
2023-04-03 10:41:15 +00:00
|
|
|
this.cloudHosting,
|
|
|
|
|
{
|
|
|
|
|
withFunctions: true,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return this.globalDataWithFunctions;
|
|
|
|
|
} else {
|
|
|
|
|
if (isEmpty(this.globalDataWithoutFunctions)) {
|
|
|
|
|
this.globalDataWithoutFunctions = getEvaluationContext(
|
|
|
|
|
this.unevalTree,
|
2023-07-08 14:07:26 +00:00
|
|
|
this.configTree,
|
2023-04-03 10:41:15 +00:00
|
|
|
this.cloudHosting,
|
|
|
|
|
{
|
|
|
|
|
withFunctions: false,
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return this.globalDataWithoutFunctions;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const globalData = new GlobalData();
|