-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2423 from IDEMSInternational/refactor/app-config
Refactor: app config runtime
- Loading branch information
Showing
27 changed files
with
598 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,6 +71,7 @@ export function extractDynamicFields(data: any): FlowTypes.IDynamicField | undef | |
export function extractDynamicEvaluators( | ||
fullExpression: string | ||
): FlowTypes.TemplateRowDynamicEvaluator[] | null { | ||
const appConfigDefault = getDefaultAppConfig(); | ||
// match fields such as @local.someField | ||
// deeper nesting will be need to be handled after evaluation as part of JSEvaluation | ||
// (e.g. @local.somefield.nestedProperty or even !@[email protected]) | ||
|
@@ -89,7 +90,7 @@ export function extractDynamicEvaluators( | |
type = "raw"; | ||
} | ||
// cross-check to ensure lookup matches one of the pre-defined dynamic field types (e.g. not [email protected]) | ||
if (!getDefaultAppConfig().DYNAMIC_PREFIXES.includes(type)) { | ||
if (!appConfigDefault.DYNAMIC_PREFIXES.includes(type)) { | ||
return undefined; | ||
} | ||
return { fullExpression, matchedExpression, type, fieldName }; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
// Provide access to FlowTypes used in the app | ||
export { FlowTypes, IDeploymentConfig, DEPLOYMENT_CONFIG_EXAMPLE_DEFAULTS } from "data-models"; | ||
export { FlowTypes, IDeploymentConfig } from "data-models"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { | ||
cleanEmptyObject, | ||
isEmptyObjectDeep, | ||
isObjectLiteral, | ||
toEmptyObject, | ||
} from "./object-utils"; | ||
|
||
const MOCK_NESTED_OBJECT = { | ||
obj_1: { | ||
obj_1_1: { | ||
number: 2, | ||
obj_1_1_1: {}, | ||
}, | ||
obj_1_2: { | ||
obj_1_2_1: {}, | ||
}, | ||
}, | ||
string: "hi", | ||
number: 1, | ||
}; | ||
|
||
describe("Object Utils", () => { | ||
it("isObjectLiteral", () => { | ||
expect(isObjectLiteral({})).toEqual(true); | ||
expect(isObjectLiteral({ string: "hello" })).toEqual(true); | ||
expect(isObjectLiteral(undefined)).toEqual(false); | ||
expect(isObjectLiteral([])).toEqual(false); | ||
expect(isObjectLiteral(new Date())).toEqual(false); | ||
}); | ||
|
||
it("isEmptyObjectDeep", () => { | ||
expect(isEmptyObjectDeep({})).toEqual(true); | ||
expect(isEmptyObjectDeep(undefined)).toEqual(false); | ||
expect(isEmptyObjectDeep({ key: { key: { key: {} } } })).toEqual(true); | ||
expect(isEmptyObjectDeep({ key: { key: { key: undefined } } })).toEqual(false); | ||
}); | ||
|
||
it("toEmptyObject", () => { | ||
const res = toEmptyObject(MOCK_NESTED_OBJECT); | ||
expect(res).toEqual({ | ||
obj_1: { obj_1_1: { obj_1_1_1: {} }, obj_1_2: { obj_1_2_1: {} } }, | ||
} as any); | ||
}); | ||
|
||
it("cleanEmptyObject", () => { | ||
const res = cleanEmptyObject(MOCK_NESTED_OBJECT); | ||
expect(res).toEqual({ | ||
obj_1: { | ||
obj_1_1: { | ||
number: 2, | ||
}, | ||
}, | ||
string: "hi", | ||
number: 1, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/** | ||
* Determine whether a value is a literal object type (`{}`) | ||
* Adapted from discussion https://stackoverflow.com/q/1173549 | ||
*/ | ||
export function isObjectLiteral(v: any) { | ||
return v ? v.constructor === {}.constructor : false; | ||
} | ||
|
||
/** Check if an object is either empty or contains only empty child */ | ||
export function isEmptyObjectDeep(v: any) { | ||
return isObjectLiteral(v) && Object.values(v).every((x) => isEmptyObjectDeep(x)); | ||
} | ||
|
||
/** | ||
* Takes a json object and empties all data inside, just leaving nested entry nodes | ||
* This is used to create placeholder objects for deeply nested partial configurations | ||
* @example | ||
* ```ts | ||
* const obj = {parent:{text:'hello',obj:{number:1}}} | ||
* toEmptyObject(obj) | ||
* // output | ||
* {parent:{obj:{}}} | ||
* ``` | ||
***/ | ||
export function toEmptyObject<T extends Record<string, any>>(obj: T) { | ||
const emptied = {} as any; | ||
if (isObjectLiteral(obj)) { | ||
for (const [key, value] of Object.entries(obj)) { | ||
if (isObjectLiteral(value)) { | ||
emptied[key] = toEmptyObject(value); | ||
} | ||
} | ||
} else { | ||
console.error("[toEmptyObject] invalid input: " + obj); | ||
return obj; | ||
} | ||
return emptied as T; | ||
} | ||
|
||
/** | ||
* Takes an input object with deeply nested keys and removes all child entries | ||
* that are either empty `{}` or contain only empty child entries `{nested:{}}` | ||
* @example | ||
* ```ts | ||
* | ||
* ``` | ||
*/ | ||
export function cleanEmptyObject(obj: Record<string, any>) { | ||
const cleaned = {} as any; | ||
if (obj.constructor === {}.constructor) { | ||
for (const [key, value] of Object.entries(obj)) { | ||
if (value.constructor === {}.constructor) { | ||
if (!isEmptyObjectDeep(value)) { | ||
cleaned[key] = cleanEmptyObject(value); | ||
} | ||
} else { | ||
cleaned[key] = value; | ||
} | ||
} | ||
} else { | ||
return cleaned; | ||
} | ||
return cleaned; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.