@live-change/relations-plugin
Advanced tools
Comparing version 0.9.15 to 0.9.16
@@ -10,4 +10,12 @@ import { | ||
defineView, | ||
defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction, | ||
defineSetTrigger, defineUpdateTrigger, defineSetOrUpdateTrigger, defineResetTrigger | ||
defineSetAction, | ||
defineUpdateAction, | ||
defineSetOrUpdateAction, | ||
defineResetAction, | ||
defineSetTrigger, | ||
defineUpdateTrigger, | ||
defineSetOrUpdateTrigger, | ||
defineResetTrigger, | ||
defineDeleteAction, | ||
defineDeleteTrigger | ||
} from './singularRelationUtils.js' | ||
@@ -42,2 +50,3 @@ | ||
defineResetTrigger(config, context) | ||
defineDeleteTrigger(config, context) | ||
@@ -58,5 +67,6 @@ if(config.setAccess || config.writeAccess || config.setAccessControl || config.writeAccessControl) { | ||
if(config.resetAccess || config.writeAccess || config.resetAccessControl || config.writeAccessControl) { | ||
defineResetAction(config, context); | ||
defineResetAction(config, context) | ||
defineDeleteAction(config, context) | ||
} | ||
}) | ||
} |
@@ -13,2 +13,3 @@ import { | ||
} from './singularRelationUtils.js' | ||
import { defineDeleteAction, defineDeleteTrigger } from './singularRelationAnyUtils.js' | ||
@@ -41,2 +42,3 @@ export default function(service, app) { | ||
defineResetTrigger(config, context) | ||
defineDeleteTrigger(config, context) | ||
@@ -57,3 +59,4 @@ if(config.setAccess || config.writeAccess || config.setAccessControl || config.writeAccessControl) { | ||
if(config.resetAccess || config.writeAccess || config.resetAccessControl || config.writeAccessControl) { | ||
defineResetAction(config, context); | ||
defineResetAction(config, context) | ||
defineDeleteAction(config, context) | ||
} | ||
@@ -60,0 +63,0 @@ |
{ | ||
"name": "@live-change/relations-plugin", | ||
"version": "0.9.15", | ||
"version": "0.9.16", | ||
"description": "", | ||
@@ -25,6 +25,6 @@ "main": "index.js", | ||
"dependencies": { | ||
"@live-change/framework": "^0.9.15", | ||
"@live-change/framework": "^0.9.16", | ||
"pluralize": "^8.0.0" | ||
}, | ||
"gitHead": "7b145114b9ca412b99f4c052d5069dd1729ff388" | ||
"gitHead": "226df9fa7eb682f6d7da5e4541eb320e8309facf" | ||
} |
@@ -6,4 +6,12 @@ import App from "@live-change/framework" | ||
} from "@live-change/framework" | ||
import { extractTypeAndIdParts, extractIdentifiersWithTypes, prepareAccessControl } from "./utilsAny.js" | ||
import { extractObjectData, extractIdentifiers, extractIdParts } from './utils.js' | ||
import { | ||
extractTypeAndIdParts, | ||
extractIdentifiersWithTypes, | ||
prepareAccessControl, | ||
cloneAndPrepareAccessControl | ||
} from './utilsAny.js' | ||
import { | ||
extractObjectData, extractIdentifiers, extractIdParts, | ||
cloneAndPrepareAccessControl as cloneAndPrepareSingleAccessControl | ||
} from './utils.js' | ||
import { fireChangeTriggers } from "./changeTriggers.js" | ||
@@ -28,4 +36,4 @@ | ||
} | ||
const accessControl = external && (config.readAccessControl || config.writeAccessControl) | ||
prepareAccessControl(accessControl, otherPropertyNames) | ||
const sourceAccessControl = external && (config.readAccessControl || config.writeAccessControl) | ||
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames) | ||
const viewName = joinedOthersPropertyName + context.reverseRelationWord + pluralize(modelName) | ||
@@ -60,3 +68,3 @@ model.crud.range = viewName | ||
const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName, | ||
modelName, others, model, modelPropertyName } = context | ||
modelName, others, model, modelPropertyName, objectType } = context | ||
const viewProperties = {} | ||
@@ -67,4 +75,6 @@ viewProperties[modelPropertyName] = new PropertyDefinition({ | ||
}) | ||
const accessControl = external && (config.readAccessControl || config.writeAccessControl) | ||
prepareAccessControl(accessControl, otherPropertyNames) | ||
const sourceAccessControl = external && (config.readAccessControl || config.writeAccessControl) | ||
const accessControl = cloneAndPrepareSingleAccessControl( | ||
sourceAccessControl, [modelPropertyName], [objectType] | ||
) | ||
const viewName = modelName[0].toLowerCase() + modelName.slice(1) | ||
@@ -122,4 +132,4 @@ model.crud.read = viewName | ||
model.crud.create = actionName | ||
const accessControl = config.createAccessControl || config.writeAccessControl | ||
prepareAccessControl(accessControl, otherPropertyNames) | ||
const sourceAccessControl = config.createAccessControl || config.writeAccessControl | ||
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames) | ||
const action = new ActionDefinition({ | ||
@@ -212,4 +222,6 @@ name: actionName, | ||
model.crud.update = actionName | ||
const accessControl = config.updateAccessControl || config.writeAccessControl | ||
prepareAccessControl(accessControl, otherPropertyNames) | ||
const sourceAccessControl = config.updateAccessControl || config.writeAccessControl | ||
const accessControl = cloneAndPrepareSingleAccessControl( | ||
sourceAccessControl, [modelPropertyName], [objectType] | ||
) | ||
const action = new ActionDefinition({ | ||
@@ -298,4 +310,6 @@ name: actionName, | ||
model.crud.delete = actionName | ||
const accessControl = config.deleteAccessControl || config.writeAccessControl | ||
prepareAccessControl(accessControl, otherPropertyNames) | ||
const sourceAccessControl = config.deleteAccessControl || config.writeAccessControl | ||
const accessControl = cloneAndPrepareSingleAccessControl( | ||
sourceAccessControl, [modelPropertyName], [objectType] | ||
) | ||
const action = new ActionDefinition({ | ||
@@ -302,0 +316,0 @@ name: actionName, |
@@ -5,3 +5,9 @@ import App from '@live-change/framework' | ||
} from "@live-change/framework" | ||
import { extractIdParts, extractIdentifiers, extractObjectData, prepareAccessControl } from "./utils.js" | ||
import { | ||
extractIdParts, | ||
extractIdentifiers, | ||
extractObjectData, | ||
prepareAccessControl, | ||
cloneAndPrepareAccessControl | ||
} from './utils.js' | ||
import { fireChangeTriggers } from "./changeTriggers.js" | ||
@@ -23,4 +29,8 @@ import pluralize from 'pluralize' | ||
model.crud.range = viewName | ||
const accessControl = external && (config.readAccessControl || config.writeAccessControl) | ||
prepareAccessControl(accessControl, otherPropertyNames, others) | ||
const sourceAccessControl = external && (config.readAccessControl || config.writeAccessControl) | ||
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames, others) | ||
if(viewName === 'companyOwnedProducts') { | ||
console.error("ACCESS CONTROL", viewName, accessControl, otherPropertyNames, others) | ||
if(accessControl) accessControl.kutas = 1 | ||
} | ||
service.views[viewName] = new ViewDefinition({ | ||
@@ -41,3 +51,3 @@ name: viewName, | ||
access: external && (config.readAccess || config.writeAccess), | ||
accessControl: config.readAccessControl || config.writeAccessControl, | ||
accessControl, | ||
daoPath(properties, { client, context }) { | ||
@@ -53,3 +63,3 @@ const idParts = extractIdParts(otherPropertyNames, properties) | ||
function defineSingleView(config, context, external = true) { | ||
const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName, | ||
const { service, modelRuntime, objectType, joinedOthersPropertyName, joinedOthersClassName, | ||
modelName, others, model, modelPropertyName } = context | ||
@@ -63,4 +73,6 @@ const viewProperties = {} | ||
model.crud.read = viewName | ||
const accessControl = external && (config.readAccessControl || config.writeAccessControl) | ||
prepareAccessControl(accessControl, otherPropertyNames, others) | ||
const sourceAccessControl = external && (config.readAccessControl || config.writeAccessControl) | ||
const accessControl = cloneAndPrepareAccessControl( | ||
sourceAccessControl, [modelPropertyName], [objectType] | ||
) | ||
service.views[viewName] = new ViewDefinition({ | ||
@@ -77,3 +89,3 @@ name: viewName, | ||
access: external && (config.readAccess || config.writeAccess), | ||
accessControl: config.readAccessControl || config.writeAccessControl, | ||
accessControl, | ||
async daoPath(properties, { client, context }) { | ||
@@ -117,4 +129,4 @@ return modelRuntime().path(properties[modelPropertyName]) | ||
model.crud.create = actionName | ||
const accessControl = config.createAccessControl || config.writeAccessControl | ||
prepareAccessControl(accessControl, otherPropertyNames, others) | ||
const sourceAccessControl = config.createAccessControl || config.writeAccessControl | ||
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames, others) | ||
const action = new ActionDefinition({ | ||
@@ -201,4 +213,6 @@ name: actionName, | ||
model.crud.update = actionName | ||
const accessControl = config.updateAccessControl || config.writeAccessControl | ||
prepareAccessControl(accessControl, otherPropertyNames, others) | ||
const sourceAccessControl = config.updateAccessControl || config.writeAccessControl | ||
const accessControl = cloneAndPrepareAccessControl( | ||
sourceAccessControl, [modelPropertyName], [objectType] | ||
) | ||
const action = new ActionDefinition({ | ||
@@ -284,4 +298,7 @@ name: actionName, | ||
const actionName = 'delete' + modelName | ||
const accessControl = config.deleteAccessControl || config.writeAccessControl | ||
prepareAccessControl(accessControl, otherPropertyNames, others) | ||
model.crud.delete = actionName | ||
const sourceAccessControl = config.deleteAccessControl || config.writeAccessControl | ||
const accessControl = cloneAndPrepareAccessControl( | ||
sourceAccessControl, [modelPropertyName], [objectType] | ||
) | ||
const action = new ActionDefinition({ | ||
@@ -399,4 +416,6 @@ name: actionName, | ||
const actionName = 'copy' + modelName | ||
const accessControl = config.copyAccessControl | ||
prepareAccessControl(accessControl, otherPropertyNames, others) | ||
const sourceAccessControl = config.copyAccessControl | ||
const accessControl = cloneAndPrepareAccessControl( | ||
sourceAccessControl, [modelPropertyName], [objectType] | ||
) | ||
const action = new ActionDefinition({ | ||
@@ -403,0 +422,0 @@ name: actionName, |
@@ -11,4 +11,12 @@ import { | ||
defineView, | ||
defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction, | ||
defineSetTrigger, defineUpdateTrigger, defineSetOrUpdateTrigger, defineResetTrigger | ||
defineSetAction, | ||
defineUpdateAction, | ||
defineSetOrUpdateAction, | ||
defineResetAction, | ||
defineSetTrigger, | ||
defineUpdateTrigger, | ||
defineSetOrUpdateTrigger, | ||
defineResetTrigger, | ||
defineDeleteTrigger, | ||
defineDeleteAction | ||
} from './singularRelationUtils.js' | ||
@@ -48,2 +56,3 @@ | ||
defineResetTrigger(config, context) | ||
defineDeleteTrigger(config, context) | ||
@@ -64,3 +73,4 @@ if(config.setAccess || config.writeAccess || config.setAccessControl || config.writeAccessControl) { | ||
if(config.resetAccess || config.writeAccess || config.resetAccessControl || config.writeAccessControl) { | ||
defineResetAction(config, context); | ||
defineResetAction(config, context) | ||
defineDeleteAction(config, context) | ||
} | ||
@@ -67,0 +77,0 @@ |
@@ -12,5 +12,14 @@ import { | ||
import { | ||
defineObjectView, defineRangeViews, | ||
defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction, | ||
defineSetTrigger, defineUpdateTrigger, defineSetOrUpdateTrigger, defineResetTrigger | ||
defineObjectView, | ||
defineRangeViews, | ||
defineSetAction, | ||
defineUpdateAction, | ||
defineSetOrUpdateAction, | ||
defineResetAction, | ||
defineSetTrigger, | ||
defineUpdateTrigger, | ||
defineSetOrUpdateTrigger, | ||
defineResetTrigger, | ||
defineDeleteTrigger, | ||
defineDeleteAction | ||
} from './singularRelationAnyUtils.js' | ||
@@ -55,2 +64,3 @@ | ||
defineResetTrigger(config, context) | ||
defineDeleteTrigger(config, context) | ||
@@ -71,3 +81,4 @@ if(config.setAccess || config.writeAccess || config.setAccessControl || config.writeAccessControl) { | ||
if(config.resetAccess || config.writeAccess || config.resetAccessControl || config.writeAccessControl) { | ||
defineResetAction(config, context); | ||
defineResetAction(config, context) | ||
defineDeleteAction(config, context) | ||
} | ||
@@ -74,0 +85,0 @@ |
@@ -6,5 +6,9 @@ import App from '@live-change/framework' | ||
import { | ||
extractTypeAndIdParts, extractIdentifiersWithTypes, generateAnyId, prepareAccessControl | ||
extractTypeAndIdParts, extractIdentifiersWithTypes, generateAnyId, | ||
prepareAccessControl, cloneAndPrepareAccessControl | ||
} from './utilsAny.js' | ||
import { extractObjectData } from "./utils.js" | ||
import { | ||
extractObjectData, | ||
cloneAndPrepareAccessControl as cloneAndPrepareSingleAccessControl | ||
} from './utils.js' | ||
import { allCombinations } from "./combinations.js" | ||
@@ -44,5 +48,5 @@ import { fireChangeTriggers } from "./changeTriggers.js" | ||
} | ||
const accessControl = external | ||
const sourceAccessControl = external | ||
&& (config.singleAccessControl || config.readAccessControl || config.writeAccessControl) | ||
prepareAccessControl(accessControl, otherPropertyNames) | ||
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames) | ||
const viewName = config.name | ||
@@ -76,4 +80,5 @@ || ((config.prefix ? config.prefix + modelName : modelName[0].toLowerCase() + modelName.slice(1)) + (config.suffix || '')) | ||
const identifierCombinations = allCombinations(otherPropertyNames).slice(0, -1) | ||
const accessControl = external && (config.listAccessControl || config.readAccessControl || config.writeAccessControl) | ||
prepareAccessControl(accessControl, otherPropertyNames) | ||
const sourceAccessControl = external | ||
&& (config.listAccessControl || config.readAccessControl || config.writeAccessControl) | ||
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames) | ||
for(const combination of identifierCombinations) { | ||
@@ -136,4 +141,4 @@ const propsUpperCase = combination.map(prop => prop[0].toUpperCase() + prop.slice(1)) | ||
model.crud.create = actionName | ||
const accessControl = config.setAccessControl || config.writeAccessControl | ||
prepareAccessControl(accessControl, otherPropertyNames) | ||
const sourceAccessControl = config.setAccessControl || config.writeAccessControl | ||
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames) | ||
const action = new ActionDefinition({ | ||
@@ -211,4 +216,4 @@ name: actionName, | ||
model.crud.update = actionName | ||
const accessControl = config.updateAccessControl || config.writeAccessControl | ||
prepareAccessControl(accessControl, otherPropertyNames) | ||
const sourceAccessControl = config.updateAccessControl || config.writeAccessControl | ||
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames) | ||
const action = new ActionDefinition({ | ||
@@ -288,7 +293,6 @@ name: actionName, | ||
} = context | ||
const eventName = modelName + 'Updated' | ||
const actionName = 'setOrUpdate' + modelName | ||
model.crud.createOrUpdate = actionName | ||
const accessControl = config.setOrUpdateAccessControl || config.writeAccessControl | ||
prepareAccessControl(accessControl, otherPropertyNames) | ||
const sourceAccessControl = config.setOrUpdateAccessControl || config.writeAccessControl | ||
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames) | ||
const action = new ActionDefinition({ | ||
@@ -339,3 +343,3 @@ name: actionName, | ||
const { | ||
service, app, model, modelRuntime, objectType, | ||
service, app, model, modelRuntime, objectType, modelPropertyName, | ||
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName | ||
@@ -346,3 +350,3 @@ } = context | ||
const identifiers = extractIdentifiersWithTypes(otherPropertyNames, properties) | ||
const id = generateAnyId(otherPropertyNames, properties) | ||
const id = properties[modelPropertyName] ?? generateAnyId(otherPropertyNames, properties) | ||
const entity = await modelRuntime().get(id) | ||
@@ -365,5 +369,4 @@ if (!entity) throw new Error('not_found') | ||
const actionName = 'reset' + modelName | ||
model.crud.delete = actionName | ||
const accessControl = config.resetAccessControl || config.writeAccessControl | ||
prepareAccessControl(accessControl, otherPropertyNames) | ||
const sourceAccessControl = config.resetAccessControl || config.writeAccessControl | ||
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames) | ||
service.actions[actionName] = new ActionDefinition({ | ||
@@ -400,6 +403,54 @@ name: actionName, | ||
function defineDeleteAction(config, context) { | ||
const { | ||
service, modelRuntime, modelPropertyName, identifiers, objectType, | ||
otherPropertyNames, joinedOthersPropertyName, modelName, joinedOthersClassName, model | ||
} = context | ||
const actionName = 'reset' + modelName | ||
model.crud.delete = actionName | ||
const sourceAccessControl = config.resetAccessControl || config.writeAccessControl | ||
const accessControl = cloneAndPrepareAccessControl( | ||
sourceAccessControl, [modelPropertyName], [objectType] | ||
) | ||
service.actions[actionName] = new ActionDefinition({ | ||
name: actionName, | ||
properties: { | ||
[modelPropertyName]: { | ||
type: model, | ||
validation: ['nonEmpty'] | ||
} | ||
}, | ||
access: config.resetAccess || config.writeAccess, | ||
accessControl, | ||
queuedBy: otherPropertyNames, | ||
waitForEvents: true, | ||
execute: getResetFunction(config, context) | ||
}) | ||
} | ||
function defineDeleteTrigger(config, context) { | ||
const { | ||
service, modelRuntime, modelPropertyName, identifiers, objectType, | ||
otherPropertyNames, joinedOthersPropertyName, modelName, joinedOthersClassName, model | ||
} = context | ||
const actionName = 'reset' + modelName | ||
const triggerName = `${service.name}_${actionName}` | ||
service.triggers[triggerName] = [new TriggerDefinition({ | ||
name: triggerName, | ||
properties: { | ||
[modelPropertyName]: { | ||
type: model, | ||
validation: ['nonEmpty'] | ||
} | ||
}, | ||
queuedBy: otherPropertyNames, | ||
waitForEvents: true, | ||
execute: getResetFunction(config, context) | ||
})] | ||
} | ||
export { | ||
defineObjectView, defineRangeViews, | ||
defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction, | ||
defineSetTrigger, defineUpdateTrigger, defineSetOrUpdateTrigger, defineResetTrigger | ||
defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction, defineDeleteAction, | ||
defineSetTrigger, defineUpdateTrigger, defineSetOrUpdateTrigger, defineResetTrigger, defineDeleteTrigger | ||
} |
@@ -6,4 +6,4 @@ import App from '@live-change/framework' | ||
import { | ||
extractIdentifiers, extractObjectData, generateId, extractIdParts, prepareAccessControl | ||
} from "./utils.js" | ||
extractIdentifiers, extractObjectData, generateId, extractIdParts, prepareAccessControl, cloneAndPrepareAccessControl | ||
} from './utils.js' | ||
import { fireChangeTriggers } from "./changeTriggers.js" | ||
@@ -24,4 +24,4 @@ | ||
model.crud.read = viewName | ||
const accessControl = external && (config.readAccessControl || config.writeAccessControl) | ||
prepareAccessControl(accessControl, otherPropertyNames, others) | ||
const sourceAccessControl = external && (config.readAccessControl || config.writeAccessControl) | ||
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames, others) | ||
service.view({ | ||
@@ -78,4 +78,4 @@ name: viewName, | ||
model.crud.create = actionName | ||
const accessControl = config.setAccessControl || config.writeAccessControl | ||
prepareAccessControl(accessControl, otherPropertyNames, others) | ||
const sourceAccessControl = config.setAccessControl || config.writeAccessControl | ||
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames, others) | ||
const action = new ActionDefinition({ | ||
@@ -154,4 +154,4 @@ name: actionName, | ||
model.crud.update = actionName | ||
const accessControl = config.updateAccessControl || config.writeAccessControl | ||
prepareAccessControl(accessControl, otherPropertyNames, others) | ||
const sourceAccessControl = config.updateAccessControl || config.writeAccessControl | ||
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames, others) | ||
const action = new ActionDefinition({ | ||
@@ -232,4 +232,4 @@ name: actionName, | ||
model.crud.createOrUpdate = actionName | ||
const accessControl = config.updateAccessControl || config.writeAccessControl | ||
prepareAccessControl(accessControl, otherPropertyNames, others) | ||
const sourceAccessControl = config.updateAccessControl || config.writeAccessControl | ||
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames, others) | ||
const action = new ActionDefinition({ | ||
@@ -241,3 +241,3 @@ name: actionName, | ||
access: config.updateAccess || config.writeAccess, | ||
accessControl: config.updateAccessControl || config.writeAccessControl, | ||
accessControl, | ||
skipValidation: true, | ||
@@ -302,3 +302,3 @@ queuedBy: otherPropertyNames, | ||
function defineResetAction(config, context) { | ||
function defineDeleteAction(config, context) { | ||
const { | ||
@@ -309,6 +309,8 @@ service, modelRuntime, modelPropertyName, objectType, identifiers, | ||
} = context | ||
const actionName = 'reset' + modelName | ||
const actionName = 'delete' + modelName | ||
model.crud.delete = actionName | ||
const accessControl = config.resetAccessControl || config.writeAccessControl | ||
prepareAccessControl(accessControl, otherPropertyNames, others) | ||
const sourceAccessControl = config.resetAccessControl || config.writeAccessControl | ||
const accessControl = cloneAndPrepareAccessControl( | ||
sourceAccessControl, [modelPropertyName], [objectType] | ||
) | ||
const action = new ActionDefinition({ | ||
@@ -335,3 +337,3 @@ name: actionName, | ||
function defineResetTrigger(config, context) { | ||
function defineDeleteTrigger(config, context) { | ||
const { | ||
@@ -341,3 +343,3 @@ service, modelRuntime, modelPropertyName, objectType, | ||
} = context | ||
const actionName = 'reset' + modelName | ||
const actionName = 'delete' + modelName | ||
const triggerName = `${service.name}_${actionName}` | ||
@@ -363,6 +365,72 @@ const trigger = new TriggerDefinition({ | ||
function defineResetAction(config, context) { | ||
const { | ||
service, modelRuntime, modelPropertyName, objectType, identifiers, | ||
otherPropertyNames, joinedOthersPropertyName, modelName, | ||
joinedOthersClassName, model, others, writeableProperties | ||
} = context | ||
const actionName = 'reset' + modelName | ||
const properties = {} | ||
for (let i = 0; i < others.length; i++) { | ||
properties[otherPropertyNames[i]] = new PropertyDefinition({ | ||
type: others[i], | ||
validation: ['nonEmpty'] | ||
}) | ||
} | ||
const sourceAccessControl = config.resetAccessControl || config.writeAccessControl | ||
const accessControl = cloneAndPrepareAccessControl( | ||
sourceAccessControl, [modelPropertyName], [objectType] | ||
) | ||
const action = new ActionDefinition({ | ||
name: actionName, | ||
properties, | ||
access: config.resetAccess || config.writeAccess, | ||
accessControl, | ||
queuedBy: otherPropertyNames, | ||
waitForEvents: true, | ||
execute: () => { throw new Error('not generated yet') } | ||
}) | ||
const validators = App.validation.getValidators(action, service, action) | ||
const validationContext = { source: action, action } | ||
action.execute = getResetFunction( validators, validationContext, config, context) | ||
if(service.actions[actionName]) throw new Error('Action ' + actionName + ' already defined') | ||
service.actions[actionName] = action | ||
} | ||
function defineResetTrigger(config, context) { | ||
const { | ||
service, modelRuntime, modelPropertyName, objectType, | ||
otherPropertyNames, joinedOthersPropertyName, modelName, joinedOthersClassName, model, | ||
others, writeableProperties | ||
} = context | ||
const actionName = 'reset' + modelName | ||
const properties = {} | ||
for (let i = 0; i < others.length; i++) { | ||
properties[otherPropertyNames[i]] = new PropertyDefinition({ | ||
type: others[i], | ||
validation: ['nonEmpty'] | ||
}) | ||
} | ||
const triggerName = `${service.name}_${actionName}` | ||
const trigger = new TriggerDefinition({ | ||
name: triggerName, | ||
properties, | ||
queuedBy: otherPropertyNames, | ||
waitForEvents: true, | ||
execute: () => { throw new Error('not generated yet') } | ||
}) | ||
const validators = App.validation.getValidators(trigger, service, trigger) | ||
const validationContext = { source: trigger, trigger } | ||
trigger.execute = getResetFunction( validators, validationContext, config, context) | ||
if(service.triggers[triggerName]) throw new Error('Trigger ' + triggerName + ' already defined') | ||
service.triggers[triggerName] = [trigger] | ||
} | ||
export { | ||
defineView, | ||
defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction, | ||
defineSetTrigger, defineUpdateTrigger, defineSetOrUpdateTrigger, defineResetTrigger | ||
defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction, defineDeleteAction, | ||
defineSetTrigger, defineUpdateTrigger, defineSetOrUpdateTrigger, defineDeleteTrigger, defineResetTrigger | ||
} |
11
utils.js
@@ -159,5 +159,16 @@ import App from "@live-change/framework" | ||
}))) | ||
accessControl.objParams = { names, types } | ||
} | ||
} | ||
export function cloneAndPrepareAccessControl(accessControl, names, types) { | ||
if(!accessControl) return accessControl | ||
if(Array.isArray(accessControl)) { | ||
accessControl = { roles: accessControl} | ||
} | ||
const newAccessControl = { ...accessControl } | ||
prepareAccessControl(newAccessControl, names, types) | ||
return newAccessControl | ||
} | ||
export function defineDeleteByOwnerEvents(config, context, generateId) { | ||
@@ -164,0 +175,0 @@ const { |
@@ -166,2 +166,12 @@ import App from "@live-change/framework" | ||
export function cloneAndPrepareAccessControl(accessControl, names) { | ||
if(!accessControl) return accessControl | ||
if(Array.isArray(accessControl)) { | ||
accessControl = { roles: accessControl} | ||
} | ||
const newAccessControl = { ...accessControl } | ||
prepareAccessControl(newAccessControl, names) | ||
return newAccessControl | ||
} | ||
function defineDeleteByOwnerEvents(config, context) { | ||
@@ -168,0 +178,0 @@ const { |
139007
3527