2019-10-07 18:03:41 +13:00
|
|
|
import {
|
2020-02-03 22:24:25 +13:00
|
|
|
hierarchy as hierarchyFunctions,
|
|
|
|
common,
|
|
|
|
getTemplateApi,
|
|
|
|
getAuthApi,
|
2020-04-01 23:38:07 +13:00
|
|
|
} from "../../../../core/src"
|
|
|
|
import { _getNew } from "../../../../core/src/recordApi/getNew"
|
2020-02-26 04:21:23 +13:00
|
|
|
import { find, filter, keyBy, flatten, map } from "lodash/fp"
|
2020-04-01 23:38:07 +13:00
|
|
|
import { generateSchema } from "../../../../core/src/indexing/indexSchemaCreator"
|
2020-03-11 00:25:25 +13:00
|
|
|
import { generate } from "shortid"
|
2019-10-07 18:03:41 +13:00
|
|
|
|
2020-04-01 23:38:07 +13:00
|
|
|
export { canDeleteIndex } from "../../../../core/src/templateApi/canDeleteIndex"
|
2020-04-14 21:25:37 +12:00
|
|
|
export { canDeleteModel } from "../../../../core/src/templateApi/canDeleteModel"
|
2020-04-01 23:38:07 +13:00
|
|
|
export { userWithFullAccess } from "../../../../core/src/index"
|
|
|
|
export { joinKey } from "../../../../core/src/common"
|
|
|
|
export { getExactNodeForKey } from "../../../../core/src/templateApi/hierarchy"
|
2020-02-03 22:24:25 +13:00
|
|
|
export const pipe = common.$
|
2019-07-13 21:35:57 +12:00
|
|
|
|
2020-02-03 22:24:25 +13:00
|
|
|
export const events = common.eventsList
|
2019-07-13 21:35:57 +12:00
|
|
|
|
2020-02-03 22:24:25 +13:00
|
|
|
export const getNode = (hierarchy, nodeId) =>
|
|
|
|
pipe(hierarchy, [
|
|
|
|
hierarchyFunctions.getFlattenedHierarchy,
|
|
|
|
find(n => n.nodeId === nodeId || n.nodeKey() === nodeId),
|
|
|
|
])
|
2019-07-13 21:35:57 +12:00
|
|
|
|
|
|
|
export const constructHierarchy = node => {
|
2020-02-03 22:24:25 +13:00
|
|
|
if (!node) return node
|
|
|
|
return templateApi(node).constructHierarchy(node)
|
2019-07-13 21:35:57 +12:00
|
|
|
}
|
|
|
|
|
2019-07-14 18:46:36 +12:00
|
|
|
export const createNewHierarchy = () => {
|
2020-02-03 22:24:25 +13:00
|
|
|
return templateApi().getNewRootLevel()
|
2019-07-13 21:35:57 +12:00
|
|
|
}
|
|
|
|
|
2020-02-03 22:24:25 +13:00
|
|
|
export const templateApi = hierarchy => getTemplateApi({ hierarchy })
|
|
|
|
export const authApi = (hierarchy, actions) =>
|
|
|
|
getAuthApi({
|
|
|
|
hierarchy,
|
|
|
|
actions: keyBy("name")(actions),
|
2020-04-01 00:16:03 +13:00
|
|
|
publish: () => { },
|
2020-02-03 22:24:25 +13:00
|
|
|
})
|
2019-07-13 21:35:57 +12:00
|
|
|
|
2020-02-03 22:24:25 +13:00
|
|
|
export const allTypes = templateApi({}).allTypes
|
2019-07-13 21:35:57 +12:00
|
|
|
|
|
|
|
export const validate = {
|
2020-02-03 22:24:25 +13:00
|
|
|
all: templateApi({}).validateAll,
|
|
|
|
node: templateApi({}).validateNode,
|
|
|
|
field: templateApi({}).validateField,
|
|
|
|
}
|
2019-07-13 21:35:57 +12:00
|
|
|
|
|
|
|
export const getPotentialReverseReferenceIndexes = (hierarchy, refIndex) => {
|
2020-02-03 22:24:25 +13:00
|
|
|
const res = pipe(hierarchy, [
|
|
|
|
hierarchyFunctions.getFlattenedHierarchy,
|
|
|
|
filter(
|
|
|
|
n =>
|
|
|
|
hierarchyFunctions.isAncestor(refIndex)(n) ||
|
|
|
|
hierarchyFunctions.isAncestor(refIndex)(n.parent())
|
|
|
|
),
|
|
|
|
map(n => n.indexes),
|
|
|
|
flatten,
|
|
|
|
filter(hierarchyFunctions.isReferenceIndex),
|
|
|
|
])
|
|
|
|
|
|
|
|
return res
|
2019-07-13 21:35:57 +12:00
|
|
|
}
|
|
|
|
|
2020-04-14 22:07:21 +12:00
|
|
|
export const getPotentialReferenceIndexes = (hierarchy, model) =>
|
2020-02-03 22:24:25 +13:00
|
|
|
pipe(hierarchy, [
|
|
|
|
hierarchyFunctions.getFlattenedHierarchy,
|
|
|
|
filter(hierarchyFunctions.isAncestorIndex),
|
|
|
|
filter(
|
|
|
|
i =>
|
2020-04-14 22:07:21 +12:00
|
|
|
hierarchyFunctions.isAncestor(model)(i.parent()) ||
|
|
|
|
i.parent().nodeId === model.parent().nodeId ||
|
2020-02-03 22:24:25 +13:00
|
|
|
hierarchyFunctions.isRoot(i.parent())
|
|
|
|
),
|
|
|
|
])
|
|
|
|
|
2020-03-24 23:58:15 +13:00
|
|
|
export const isIndex = hierarchyFunctions.isIndex
|
2020-04-14 22:03:22 +12:00
|
|
|
export const isModel = hierarchyFunctions.isModel
|
2020-04-02 18:55:11 +13:00
|
|
|
export const nodeNameFromNodeKey = hierarchyFunctions.nodeNameFromNodeKey
|
2020-03-24 23:58:15 +13:00
|
|
|
|
2020-02-03 22:24:25 +13:00
|
|
|
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)
|
|
|
|
|
|
|
|
export const getIndexNodes = hierarchy =>
|
|
|
|
pipe(hierarchy, [
|
|
|
|
hierarchyFunctions.getFlattenedHierarchy,
|
|
|
|
filter(hierarchyFunctions.isIndex),
|
|
|
|
])
|
|
|
|
|
|
|
|
export const getRecordNodes = hierarchy =>
|
|
|
|
pipe(hierarchy, [
|
|
|
|
hierarchyFunctions.getFlattenedHierarchy,
|
2020-04-14 22:03:22 +12:00
|
|
|
filter(hierarchyFunctions.isModel),
|
2020-02-03 22:24:25 +13:00
|
|
|
])
|
|
|
|
|
|
|
|
export const getIndexSchema = hierarchy => index =>
|
|
|
|
generateSchema(hierarchy, index)
|
2020-03-11 00:25:25 +13:00
|
|
|
|
|
|
|
export const getNewRecord = _getNew
|
|
|
|
|
|
|
|
export const getNewInstance = (appId, name) => {
|
|
|
|
const id = `2-${generate()}`
|
|
|
|
return {
|
|
|
|
key: `/applications/${appId}/instances/${id}`,
|
|
|
|
active: true,
|
|
|
|
version: { key: "" },
|
|
|
|
isNew: true,
|
|
|
|
type: "instance",
|
2020-03-24 03:15:09 +13:00
|
|
|
datastoreconfig: "",
|
2020-03-11 00:25:25 +13:00
|
|
|
id,
|
|
|
|
name,
|
|
|
|
}
|
|
|
|
}
|