2019-07-13 21:35:57 +12:00
|
|
|
import {hierarchy as hierarchyFunctions,
|
2019-07-30 20:08:40 +12:00
|
|
|
common, getTemplateApi, getAuthApi } from "../../../core/src";
|
2019-07-13 21:35:57 +12:00
|
|
|
import {find, filter, includes, keyBy, some,
|
|
|
|
flatten, map} from "lodash/fp";
|
|
|
|
|
2019-08-03 01:54:10 +12:00
|
|
|
export const pipe = common.$;
|
2019-07-13 21:35:57 +12:00
|
|
|
|
|
|
|
export const events = common.eventsList;
|
|
|
|
|
|
|
|
export const getNode = (hierarchy, nodeId) =>
|
2019-08-03 01:54:10 +12:00
|
|
|
pipe(hierarchy, [
|
2019-07-13 21:35:57 +12:00
|
|
|
hierarchyFunctions.getFlattenedHierarchy,
|
|
|
|
find(n => n.nodeId === nodeId || n.nodeKey() === nodeId)
|
|
|
|
]);
|
|
|
|
|
|
|
|
export const constructHierarchy = node => {
|
|
|
|
if(!node) return node;
|
2019-07-14 18:46:36 +12:00
|
|
|
return templateApi(node).constructHierarchy(node);
|
2019-07-13 21:35:57 +12:00
|
|
|
}
|
|
|
|
|
2019-07-14 18:46:36 +12:00
|
|
|
export const createNewHierarchy = () => {
|
2019-07-13 21:35:57 +12:00
|
|
|
return templateApi().getNewRootLevel();
|
|
|
|
}
|
|
|
|
|
2019-07-14 18:46:36 +12:00
|
|
|
export const templateApi = hierarchy => getTemplateApi({hierarchy})
|
2019-07-13 21:35:57 +12:00
|
|
|
export const authApi = (hierarchy, actions) => getAuthApi({
|
2019-07-14 18:46:36 +12:00
|
|
|
hierarchy, actions: keyBy("name")(actions), publish:()=>{}})
|
2019-07-13 21:35:57 +12:00
|
|
|
|
|
|
|
export const allTypes = templateApi({}).allTypes;
|
|
|
|
|
|
|
|
export const validate = {
|
|
|
|
all: templateApi({}).validateAll,
|
|
|
|
node: templateApi({}).validateNode,
|
|
|
|
field: templateApi({}).validateField
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getPotentialReverseReferenceIndexes = (hierarchy, refIndex) => {
|
2019-08-03 01:54:10 +12:00
|
|
|
const res = pipe(hierarchy, [
|
2019-07-13 21:35:57 +12:00
|
|
|
hierarchyFunctions.getFlattenedHierarchy,
|
|
|
|
filter(n => hierarchyFunctions.isAncestor(refIndex)(n)
|
|
|
|
|| hierarchyFunctions.isAncestor(refIndex)(n.parent())),
|
|
|
|
map(n => n.indexes),
|
|
|
|
flatten,
|
|
|
|
filter(hierarchyFunctions.isReferenceIndex)
|
|
|
|
]);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getPotentialReferenceIndexes = (hierarchy, record) =>
|
2019-08-03 01:54:10 +12:00
|
|
|
pipe(hierarchy, [
|
2019-07-13 21:35:57 +12:00
|
|
|
hierarchyFunctions.getFlattenedHierarchy,
|
|
|
|
filter(hierarchyFunctions.isAncestorIndex),
|
|
|
|
filter(i => hierarchyFunctions.isAncestor(record)(i.parent())
|
|
|
|
|| i.parent().nodeId === record.parent().nodeId
|
|
|
|
|| hierarchyFunctions.isRoot(i.parent()))
|
|
|
|
]);
|
|
|
|
|
|
|
|
export const getDefaultTypeOptions = type =>
|
|
|
|
!type ? {} : allTypes[type].getDefaultOptions();
|
|
|
|
|
|
|
|
export const getNewAction = () => templateApi({}).createAction();
|
|
|
|
export const getNewTrigger = () => templateApi({}).createTrigger();
|
|
|
|
|
|
|
|
export const validateActions = actions => templateApi({}).validateActions(actions);
|
|
|
|
export const validateTriggers = (triggers, actions) => templateApi({}).validateTriggers(triggers, actions);
|
|
|
|
|
|
|
|
export const generateFullPermissions = (hierarchy, actions) =>
|
|
|
|
authApi(hierarchy,actions).generateFullPermissions();
|
|
|
|
|
|
|
|
export const getNewAccessLevel = () =>
|
|
|
|
authApi().getNewAccessLevel();
|
|
|
|
|
|
|
|
export const validateAccessLevels = (hierarchy, actions, accessLevels) =>
|
|
|
|
authApi(hierarchy, actions).validateAccessLevels(accessLevels);
|