@live-change/relations-plugin 0.9.15 → 0.9.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/boundTo.js +13 -3
- package/boundToAny.js +4 -1
- package/package.json +3 -3
- package/pluralRelationAnyUtils.js +27 -13
- package/pluralRelationUtils.js +35 -16
- package/propertyOf.js +13 -3
- package/propertyOfAny.js +15 -4
- package/singularRelationAnyUtils.js +71 -20
- package/singularRelationUtils.js +87 -19
- package/utils.js +11 -0
- package/utilsAny.js +10 -0
package/boundTo.js
CHANGED
|
@@ -7,8 +7,16 @@ import { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineReset
|
|
|
7
7
|
|
|
8
8
|
import {
|
|
9
9
|
defineView,
|
|
10
|
-
defineSetAction,
|
|
11
|
-
|
|
10
|
+
defineSetAction,
|
|
11
|
+
defineUpdateAction,
|
|
12
|
+
defineSetOrUpdateAction,
|
|
13
|
+
defineResetAction,
|
|
14
|
+
defineSetTrigger,
|
|
15
|
+
defineUpdateTrigger,
|
|
16
|
+
defineSetOrUpdateTrigger,
|
|
17
|
+
defineResetTrigger,
|
|
18
|
+
defineDeleteAction,
|
|
19
|
+
defineDeleteTrigger
|
|
12
20
|
} from './singularRelationUtils.js'
|
|
13
21
|
|
|
14
22
|
export default function(service, app) {
|
|
@@ -38,6 +46,7 @@ export default function(service, app) {
|
|
|
38
46
|
defineUpdateTrigger(config, context)
|
|
39
47
|
defineSetOrUpdateTrigger(config, context)
|
|
40
48
|
defineResetTrigger(config, context)
|
|
49
|
+
defineDeleteTrigger(config, context)
|
|
41
50
|
|
|
42
51
|
if(config.setAccess || config.writeAccess || config.setAccessControl || config.writeAccessControl) {
|
|
43
52
|
defineSetAction(config, context)
|
|
@@ -53,7 +62,8 @@ export default function(service, app) {
|
|
|
53
62
|
}
|
|
54
63
|
|
|
55
64
|
if(config.resetAccess || config.writeAccess || config.resetAccessControl || config.writeAccessControl) {
|
|
56
|
-
defineResetAction(config, context)
|
|
65
|
+
defineResetAction(config, context)
|
|
66
|
+
defineDeleteAction(config, context)
|
|
57
67
|
}
|
|
58
68
|
})
|
|
59
69
|
}
|
package/boundToAny.js
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
defineSetAction, defineUpdateAction, defineResetAction, defineSetOrUpdateAction,
|
|
11
11
|
defineSetTrigger, defineUpdateTrigger, defineSetOrUpdateTrigger, defineResetTrigger
|
|
12
12
|
} from './singularRelationUtils.js'
|
|
13
|
+
import { defineDeleteAction, defineDeleteTrigger } from './singularRelationAnyUtils.js'
|
|
13
14
|
|
|
14
15
|
export default function(service, app) {
|
|
15
16
|
processModelsAnyAnnotation(service, app, 'boundToAny', false, (config, context) => {
|
|
@@ -37,6 +38,7 @@ export default function(service, app) {
|
|
|
37
38
|
defineUpdateTrigger(config, context)
|
|
38
39
|
defineSetOrUpdateTrigger(config, context)
|
|
39
40
|
defineResetTrigger(config, context)
|
|
41
|
+
defineDeleteTrigger(config, context)
|
|
40
42
|
|
|
41
43
|
if(config.setAccess || config.writeAccess || config.setAccessControl || config.writeAccessControl) {
|
|
42
44
|
defineSetAction(config, context)
|
|
@@ -52,7 +54,8 @@ export default function(service, app) {
|
|
|
52
54
|
}
|
|
53
55
|
|
|
54
56
|
if(config.resetAccess || config.writeAccess || config.resetAccessControl || config.writeAccessControl) {
|
|
55
|
-
defineResetAction(config, context)
|
|
57
|
+
defineResetAction(config, context)
|
|
58
|
+
defineDeleteAction(config, context)
|
|
56
59
|
}
|
|
57
60
|
|
|
58
61
|
})
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/relations-plugin",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.16",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@live-change/framework": "^0.9.
|
|
25
|
+
"@live-change/framework": "^0.9.16",
|
|
26
26
|
"pluralize": "^8.0.0"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "226df9fa7eb682f6d7da5e4541eb320e8309facf"
|
|
29
29
|
}
|
|
@@ -3,8 +3,16 @@ const { extractRange } = App
|
|
|
3
3
|
import {
|
|
4
4
|
PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, TriggerDefinition
|
|
5
5
|
} from "@live-change/framework"
|
|
6
|
-
import {
|
|
7
|
-
|
|
6
|
+
import {
|
|
7
|
+
extractTypeAndIdParts,
|
|
8
|
+
extractIdentifiersWithTypes,
|
|
9
|
+
prepareAccessControl,
|
|
10
|
+
cloneAndPrepareAccessControl
|
|
11
|
+
} from './utilsAny.js'
|
|
12
|
+
import {
|
|
13
|
+
extractObjectData, extractIdentifiers, extractIdParts,
|
|
14
|
+
cloneAndPrepareAccessControl as cloneAndPrepareSingleAccessControl
|
|
15
|
+
} from './utils.js'
|
|
8
16
|
import { fireChangeTriggers } from "./changeTriggers.js"
|
|
9
17
|
|
|
10
18
|
import pluralize from 'pluralize'
|
|
@@ -24,8 +32,8 @@ function defineRangeView(config, context, external = true) {
|
|
|
24
32
|
validation: ['nonEmpty']
|
|
25
33
|
})
|
|
26
34
|
}
|
|
27
|
-
const
|
|
28
|
-
|
|
35
|
+
const sourceAccessControl = external && (config.readAccessControl || config.writeAccessControl)
|
|
36
|
+
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames)
|
|
29
37
|
const viewName = joinedOthersPropertyName + context.reverseRelationWord + pluralize(modelName)
|
|
30
38
|
model.crud.range = viewName
|
|
31
39
|
service.view({
|
|
@@ -55,14 +63,16 @@ function defineRangeView(config, context, external = true) {
|
|
|
55
63
|
|
|
56
64
|
function defineSingleView(config, context, external = true) {
|
|
57
65
|
const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
|
|
58
|
-
modelName, others, model, modelPropertyName } = context
|
|
66
|
+
modelName, others, model, modelPropertyName, objectType } = context
|
|
59
67
|
const viewProperties = {}
|
|
60
68
|
viewProperties[modelPropertyName] = new PropertyDefinition({
|
|
61
69
|
type: model,
|
|
62
70
|
validation: ['nonEmpty']
|
|
63
71
|
})
|
|
64
|
-
const
|
|
65
|
-
|
|
72
|
+
const sourceAccessControl = external && (config.readAccessControl || config.writeAccessControl)
|
|
73
|
+
const accessControl = cloneAndPrepareSingleAccessControl(
|
|
74
|
+
sourceAccessControl, [modelPropertyName], [objectType]
|
|
75
|
+
)
|
|
66
76
|
const viewName = modelName[0].toLowerCase() + modelName.slice(1)
|
|
67
77
|
model.crud.read = viewName
|
|
68
78
|
service.view({
|
|
@@ -115,8 +125,8 @@ function defineCreateAction(config, context) {
|
|
|
115
125
|
} = context
|
|
116
126
|
const actionName = 'create' + modelName
|
|
117
127
|
model.crud.create = actionName
|
|
118
|
-
const
|
|
119
|
-
|
|
128
|
+
const sourceAccessControl = config.createAccessControl || config.writeAccessControl
|
|
129
|
+
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames)
|
|
120
130
|
const action = new ActionDefinition({
|
|
121
131
|
name: actionName,
|
|
122
132
|
properties: {
|
|
@@ -204,8 +214,10 @@ function defineUpdateAction(config, context) {
|
|
|
204
214
|
} = context
|
|
205
215
|
const actionName = 'update' + modelName
|
|
206
216
|
model.crud.update = actionName
|
|
207
|
-
const
|
|
208
|
-
|
|
217
|
+
const sourceAccessControl = config.updateAccessControl || config.writeAccessControl
|
|
218
|
+
const accessControl = cloneAndPrepareSingleAccessControl(
|
|
219
|
+
sourceAccessControl, [modelPropertyName], [objectType]
|
|
220
|
+
)
|
|
209
221
|
const action = new ActionDefinition({
|
|
210
222
|
name: actionName,
|
|
211
223
|
properties: {
|
|
@@ -289,8 +301,10 @@ function defineDeleteAction(config, context) {
|
|
|
289
301
|
} = context
|
|
290
302
|
const actionName = 'delete' + modelName
|
|
291
303
|
model.crud.delete = actionName
|
|
292
|
-
const
|
|
293
|
-
|
|
304
|
+
const sourceAccessControl = config.deleteAccessControl || config.writeAccessControl
|
|
305
|
+
const accessControl = cloneAndPrepareSingleAccessControl(
|
|
306
|
+
sourceAccessControl, [modelPropertyName], [objectType]
|
|
307
|
+
)
|
|
294
308
|
const action = new ActionDefinition({
|
|
295
309
|
name: actionName,
|
|
296
310
|
properties: {
|
package/pluralRelationUtils.js
CHANGED
|
@@ -2,7 +2,13 @@ import App from '@live-change/framework'
|
|
|
2
2
|
import {
|
|
3
3
|
PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, TriggerDefinition
|
|
4
4
|
} from "@live-change/framework"
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
extractIdParts,
|
|
7
|
+
extractIdentifiers,
|
|
8
|
+
extractObjectData,
|
|
9
|
+
prepareAccessControl,
|
|
10
|
+
cloneAndPrepareAccessControl
|
|
11
|
+
} from './utils.js'
|
|
6
12
|
import { fireChangeTriggers } from "./changeTriggers.js"
|
|
7
13
|
import pluralize from 'pluralize'
|
|
8
14
|
|
|
@@ -19,8 +25,12 @@ function defineRangeView(config, context, external = true) {
|
|
|
19
25
|
}
|
|
20
26
|
const viewName = joinedOthersPropertyName + context.reverseRelationWord + pluralize(modelName)
|
|
21
27
|
model.crud.range = viewName
|
|
22
|
-
const
|
|
23
|
-
|
|
28
|
+
const sourceAccessControl = external && (config.readAccessControl || config.writeAccessControl)
|
|
29
|
+
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames, others)
|
|
30
|
+
if(viewName === 'companyOwnedProducts') {
|
|
31
|
+
console.error("ACCESS CONTROL", viewName, accessControl, otherPropertyNames, others)
|
|
32
|
+
if(accessControl) accessControl.kutas = 1
|
|
33
|
+
}
|
|
24
34
|
service.views[viewName] = new ViewDefinition({
|
|
25
35
|
name: viewName,
|
|
26
36
|
properties: {
|
|
@@ -36,7 +46,7 @@ function defineRangeView(config, context, external = true) {
|
|
|
36
46
|
internal: !external,
|
|
37
47
|
global: config.globalView,
|
|
38
48
|
access: external && (config.readAccess || config.writeAccess),
|
|
39
|
-
accessControl
|
|
49
|
+
accessControl,
|
|
40
50
|
daoPath(properties, { client, context }) {
|
|
41
51
|
const idParts = extractIdParts(otherPropertyNames, properties)
|
|
42
52
|
const range = App.extractRange(properties)
|
|
@@ -47,7 +57,7 @@ function defineRangeView(config, context, external = true) {
|
|
|
47
57
|
}
|
|
48
58
|
|
|
49
59
|
function defineSingleView(config, context, external = true) {
|
|
50
|
-
const { service, modelRuntime,
|
|
60
|
+
const { service, modelRuntime, objectType, joinedOthersPropertyName, joinedOthersClassName,
|
|
51
61
|
modelName, others, model, modelPropertyName } = context
|
|
52
62
|
const viewProperties = {}
|
|
53
63
|
viewProperties[modelPropertyName] = new PropertyDefinition({
|
|
@@ -56,8 +66,10 @@ function defineSingleView(config, context, external = true) {
|
|
|
56
66
|
})
|
|
57
67
|
const viewName = modelName[0].toLowerCase() + modelName.slice(1)
|
|
58
68
|
model.crud.read = viewName
|
|
59
|
-
const
|
|
60
|
-
|
|
69
|
+
const sourceAccessControl = external && (config.readAccessControl || config.writeAccessControl)
|
|
70
|
+
const accessControl = cloneAndPrepareAccessControl(
|
|
71
|
+
sourceAccessControl, [modelPropertyName], [objectType]
|
|
72
|
+
)
|
|
61
73
|
service.views[viewName] = new ViewDefinition({
|
|
62
74
|
name: viewName,
|
|
63
75
|
properties: {
|
|
@@ -69,7 +81,7 @@ function defineSingleView(config, context, external = true) {
|
|
|
69
81
|
internal: !external,
|
|
70
82
|
global: config.globalView,
|
|
71
83
|
access: external && (config.readAccess || config.writeAccess),
|
|
72
|
-
accessControl
|
|
84
|
+
accessControl,
|
|
73
85
|
async daoPath(properties, { client, context }) {
|
|
74
86
|
return modelRuntime().path(properties[modelPropertyName])
|
|
75
87
|
}
|
|
@@ -108,8 +120,8 @@ function defineCreateAction(config, context) {
|
|
|
108
120
|
} = context
|
|
109
121
|
const actionName = 'create' + modelName
|
|
110
122
|
model.crud.create = actionName
|
|
111
|
-
const
|
|
112
|
-
|
|
123
|
+
const sourceAccessControl = config.createAccessControl || config.writeAccessControl
|
|
124
|
+
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames, others)
|
|
113
125
|
const action = new ActionDefinition({
|
|
114
126
|
name: actionName,
|
|
115
127
|
properties: {
|
|
@@ -191,8 +203,10 @@ function defineUpdateAction(config, context) {
|
|
|
191
203
|
} = context
|
|
192
204
|
const actionName = 'update' + modelName
|
|
193
205
|
model.crud.update = actionName
|
|
194
|
-
const
|
|
195
|
-
|
|
206
|
+
const sourceAccessControl = config.updateAccessControl || config.writeAccessControl
|
|
207
|
+
const accessControl = cloneAndPrepareAccessControl(
|
|
208
|
+
sourceAccessControl, [modelPropertyName], [objectType]
|
|
209
|
+
)
|
|
196
210
|
const action = new ActionDefinition({
|
|
197
211
|
name: actionName,
|
|
198
212
|
properties: {
|
|
@@ -273,8 +287,11 @@ function defineDeleteAction(config, context) {
|
|
|
273
287
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
274
288
|
} = context
|
|
275
289
|
const actionName = 'delete' + modelName
|
|
276
|
-
|
|
277
|
-
|
|
290
|
+
model.crud.delete = actionName
|
|
291
|
+
const sourceAccessControl = config.deleteAccessControl || config.writeAccessControl
|
|
292
|
+
const accessControl = cloneAndPrepareAccessControl(
|
|
293
|
+
sourceAccessControl, [modelPropertyName], [objectType]
|
|
294
|
+
)
|
|
278
295
|
const action = new ActionDefinition({
|
|
279
296
|
name: actionName,
|
|
280
297
|
properties: {
|
|
@@ -387,8 +404,10 @@ function defineCopyAction(config, context) {
|
|
|
387
404
|
identifiers
|
|
388
405
|
} = context
|
|
389
406
|
const actionName = 'copy' + modelName
|
|
390
|
-
const
|
|
391
|
-
|
|
407
|
+
const sourceAccessControl = config.copyAccessControl
|
|
408
|
+
const accessControl = cloneAndPrepareAccessControl(
|
|
409
|
+
sourceAccessControl, [modelPropertyName], [objectType]
|
|
410
|
+
)
|
|
392
411
|
const action = new ActionDefinition({
|
|
393
412
|
name: actionName,
|
|
394
413
|
properties: {
|
package/propertyOf.js
CHANGED
|
@@ -8,8 +8,16 @@ import { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineReset
|
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
10
|
defineView,
|
|
11
|
-
defineSetAction,
|
|
12
|
-
|
|
11
|
+
defineSetAction,
|
|
12
|
+
defineUpdateAction,
|
|
13
|
+
defineSetOrUpdateAction,
|
|
14
|
+
defineResetAction,
|
|
15
|
+
defineSetTrigger,
|
|
16
|
+
defineUpdateTrigger,
|
|
17
|
+
defineSetOrUpdateTrigger,
|
|
18
|
+
defineResetTrigger,
|
|
19
|
+
defineDeleteTrigger,
|
|
20
|
+
defineDeleteAction
|
|
13
21
|
} from './singularRelationUtils.js'
|
|
14
22
|
|
|
15
23
|
export default function(service, app) {
|
|
@@ -44,6 +52,7 @@ export default function(service, app) {
|
|
|
44
52
|
defineUpdateTrigger(config, context)
|
|
45
53
|
defineSetOrUpdateTrigger(config, context)
|
|
46
54
|
defineResetTrigger(config, context)
|
|
55
|
+
defineDeleteTrigger(config, context)
|
|
47
56
|
|
|
48
57
|
if(config.setAccess || config.writeAccess || config.setAccessControl || config.writeAccessControl) {
|
|
49
58
|
defineSetAction(config, context)
|
|
@@ -59,7 +68,8 @@ export default function(service, app) {
|
|
|
59
68
|
}
|
|
60
69
|
|
|
61
70
|
if(config.resetAccess || config.writeAccess || config.resetAccessControl || config.writeAccessControl) {
|
|
62
|
-
defineResetAction(config, context)
|
|
71
|
+
defineResetAction(config, context)
|
|
72
|
+
defineDeleteAction(config, context)
|
|
63
73
|
}
|
|
64
74
|
|
|
65
75
|
if(!config.customDeleteTrigger) defineParentDeleteTriggers(config, context)
|
package/propertyOfAny.js
CHANGED
|
@@ -9,9 +9,18 @@ import {
|
|
|
9
9
|
} from './propertyEvents.js'
|
|
10
10
|
|
|
11
11
|
import {
|
|
12
|
-
defineObjectView,
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
defineObjectView,
|
|
13
|
+
defineRangeViews,
|
|
14
|
+
defineSetAction,
|
|
15
|
+
defineUpdateAction,
|
|
16
|
+
defineSetOrUpdateAction,
|
|
17
|
+
defineResetAction,
|
|
18
|
+
defineSetTrigger,
|
|
19
|
+
defineUpdateTrigger,
|
|
20
|
+
defineSetOrUpdateTrigger,
|
|
21
|
+
defineResetTrigger,
|
|
22
|
+
defineDeleteTrigger,
|
|
23
|
+
defineDeleteAction
|
|
15
24
|
} from './singularRelationAnyUtils.js'
|
|
16
25
|
|
|
17
26
|
export default function(service, app) {
|
|
@@ -51,6 +60,7 @@ export default function(service, app) {
|
|
|
51
60
|
defineUpdateTrigger(config, context)
|
|
52
61
|
defineSetOrUpdateTrigger(config, context)
|
|
53
62
|
defineResetTrigger(config, context)
|
|
63
|
+
defineDeleteTrigger(config, context)
|
|
54
64
|
|
|
55
65
|
if(config.setAccess || config.writeAccess || config.setAccessControl || config.writeAccessControl) {
|
|
56
66
|
defineSetAction(config, context)
|
|
@@ -66,7 +76,8 @@ export default function(service, app) {
|
|
|
66
76
|
}
|
|
67
77
|
|
|
68
78
|
if(config.resetAccess || config.writeAccess || config.resetAccessControl || config.writeAccessControl) {
|
|
69
|
-
defineResetAction(config, context)
|
|
79
|
+
defineResetAction(config, context)
|
|
80
|
+
defineDeleteAction(config, context)
|
|
70
81
|
}
|
|
71
82
|
|
|
72
83
|
if(!config.customDeleteTrigger) defineParentDeleteTrigger(config, context)
|
|
@@ -3,9 +3,13 @@ import {
|
|
|
3
3
|
PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, TriggerDefinition
|
|
4
4
|
} from '@live-change/framework'
|
|
5
5
|
import {
|
|
6
|
-
extractTypeAndIdParts, extractIdentifiersWithTypes, generateAnyId,
|
|
6
|
+
extractTypeAndIdParts, extractIdentifiersWithTypes, generateAnyId,
|
|
7
|
+
prepareAccessControl, cloneAndPrepareAccessControl
|
|
7
8
|
} from './utilsAny.js'
|
|
8
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
extractObjectData,
|
|
11
|
+
cloneAndPrepareAccessControl as cloneAndPrepareSingleAccessControl
|
|
12
|
+
} from './utils.js'
|
|
9
13
|
import { allCombinations } from "./combinations.js"
|
|
10
14
|
import { fireChangeTriggers } from "./changeTriggers.js"
|
|
11
15
|
|
|
@@ -40,9 +44,9 @@ function defineObjectView(config, context, external = true) {
|
|
|
40
44
|
validation: ['nonEmpty']
|
|
41
45
|
})
|
|
42
46
|
}
|
|
43
|
-
const
|
|
47
|
+
const sourceAccessControl = external
|
|
44
48
|
&& (config.singleAccessControl || config.readAccessControl || config.writeAccessControl)
|
|
45
|
-
|
|
49
|
+
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames)
|
|
46
50
|
const viewName = config.name
|
|
47
51
|
|| ((config.prefix ? config.prefix + modelName : modelName[0].toLowerCase() + modelName.slice(1)) + (config.suffix || ''))
|
|
48
52
|
model.crud.read = viewName
|
|
@@ -71,8 +75,9 @@ function defineRangeViews(config, context, external = true) {
|
|
|
71
75
|
const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
|
|
72
76
|
modelName, others, model } = context
|
|
73
77
|
const identifierCombinations = allCombinations(otherPropertyNames).slice(0, -1)
|
|
74
|
-
const
|
|
75
|
-
|
|
78
|
+
const sourceAccessControl = external
|
|
79
|
+
&& (config.listAccessControl || config.readAccessControl || config.writeAccessControl)
|
|
80
|
+
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames)
|
|
76
81
|
for(const combination of identifierCombinations) {
|
|
77
82
|
const propsUpperCase = combination.map(prop => prop[0].toUpperCase() + prop.slice(1))
|
|
78
83
|
const indexName = 'by' + combination.map(prop => prop[0].toUpperCase() + prop.slice(1))
|
|
@@ -130,8 +135,8 @@ function defineSetAction(config, context) {
|
|
|
130
135
|
} = context
|
|
131
136
|
const actionName = 'set' + modelName
|
|
132
137
|
model.crud.create = actionName
|
|
133
|
-
const
|
|
134
|
-
|
|
138
|
+
const sourceAccessControl = config.setAccessControl || config.writeAccessControl
|
|
139
|
+
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames)
|
|
135
140
|
const action = new ActionDefinition({
|
|
136
141
|
name: actionName,
|
|
137
142
|
properties: { ...(model.properties) },
|
|
@@ -204,8 +209,8 @@ function defineUpdateAction(config, context) {
|
|
|
204
209
|
} = context
|
|
205
210
|
const actionName = 'update' + modelName
|
|
206
211
|
model.crud.update = actionName
|
|
207
|
-
const
|
|
208
|
-
|
|
212
|
+
const sourceAccessControl = config.updateAccessControl || config.writeAccessControl
|
|
213
|
+
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames)
|
|
209
214
|
const action = new ActionDefinition({
|
|
210
215
|
name: actionName,
|
|
211
216
|
properties: {
|
|
@@ -280,11 +285,10 @@ function defineSetOrUpdateAction(config, context) {
|
|
|
280
285
|
service, app, model, modelRuntime, objectType,
|
|
281
286
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
282
287
|
} = context
|
|
283
|
-
const eventName = modelName + 'Updated'
|
|
284
288
|
const actionName = 'setOrUpdate' + modelName
|
|
285
289
|
model.crud.createOrUpdate = actionName
|
|
286
|
-
const
|
|
287
|
-
|
|
290
|
+
const sourceAccessControl = config.setOrUpdateAccessControl || config.writeAccessControl
|
|
291
|
+
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames)
|
|
288
292
|
const action = new ActionDefinition({
|
|
289
293
|
name: actionName,
|
|
290
294
|
properties: {
|
|
@@ -330,13 +334,13 @@ function defineSetOrUpdateTrigger(config, context) {
|
|
|
330
334
|
|
|
331
335
|
function getResetFunction(config, context) {
|
|
332
336
|
const {
|
|
333
|
-
service, app, model, modelRuntime, objectType,
|
|
337
|
+
service, app, model, modelRuntime, objectType, modelPropertyName,
|
|
334
338
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
335
339
|
} = context
|
|
336
340
|
const eventName = joinedOthersPropertyName + context.reverseRelationWord + modelName + 'Reset'
|
|
337
341
|
return async function execute(properties, {client, service}, emit) {
|
|
338
342
|
const identifiers = extractIdentifiersWithTypes(otherPropertyNames, properties)
|
|
339
|
-
const id = generateAnyId(otherPropertyNames, properties)
|
|
343
|
+
const id = properties[modelPropertyName] ?? generateAnyId(otherPropertyNames, properties)
|
|
340
344
|
const entity = await modelRuntime().get(id)
|
|
341
345
|
if (!entity) throw new Error('not_found')
|
|
342
346
|
await fireChangeTriggers(context, objectType, identifiers, id,
|
|
@@ -354,9 +358,8 @@ function defineResetAction(config, context) {
|
|
|
354
358
|
otherPropertyNames, joinedOthersPropertyName, modelName, joinedOthersClassName, model
|
|
355
359
|
} = context
|
|
356
360
|
const actionName = 'reset' + modelName
|
|
357
|
-
|
|
358
|
-
const accessControl =
|
|
359
|
-
prepareAccessControl(accessControl, otherPropertyNames)
|
|
361
|
+
const sourceAccessControl = config.resetAccessControl || config.writeAccessControl
|
|
362
|
+
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames)
|
|
360
363
|
service.actions[actionName] = new ActionDefinition({
|
|
361
364
|
name: actionName,
|
|
362
365
|
properties: {
|
|
@@ -388,8 +391,56 @@ function defineResetTrigger(config, context) {
|
|
|
388
391
|
})]
|
|
389
392
|
}
|
|
390
393
|
|
|
394
|
+
function defineDeleteAction(config, context) {
|
|
395
|
+
const {
|
|
396
|
+
service, modelRuntime, modelPropertyName, identifiers, objectType,
|
|
397
|
+
otherPropertyNames, joinedOthersPropertyName, modelName, joinedOthersClassName, model
|
|
398
|
+
} = context
|
|
399
|
+
const actionName = 'reset' + modelName
|
|
400
|
+
model.crud.delete = actionName
|
|
401
|
+
const sourceAccessControl = config.resetAccessControl || config.writeAccessControl
|
|
402
|
+
const accessControl = cloneAndPrepareAccessControl(
|
|
403
|
+
sourceAccessControl, [modelPropertyName], [objectType]
|
|
404
|
+
)
|
|
405
|
+
service.actions[actionName] = new ActionDefinition({
|
|
406
|
+
name: actionName,
|
|
407
|
+
properties: {
|
|
408
|
+
[modelPropertyName]: {
|
|
409
|
+
type: model,
|
|
410
|
+
validation: ['nonEmpty']
|
|
411
|
+
}
|
|
412
|
+
},
|
|
413
|
+
access: config.resetAccess || config.writeAccess,
|
|
414
|
+
accessControl,
|
|
415
|
+
queuedBy: otherPropertyNames,
|
|
416
|
+
waitForEvents: true,
|
|
417
|
+
execute: getResetFunction(config, context)
|
|
418
|
+
})
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
function defineDeleteTrigger(config, context) {
|
|
422
|
+
const {
|
|
423
|
+
service, modelRuntime, modelPropertyName, identifiers, objectType,
|
|
424
|
+
otherPropertyNames, joinedOthersPropertyName, modelName, joinedOthersClassName, model
|
|
425
|
+
} = context
|
|
426
|
+
const actionName = 'reset' + modelName
|
|
427
|
+
const triggerName = `${service.name}_${actionName}`
|
|
428
|
+
service.triggers[triggerName] = [new TriggerDefinition({
|
|
429
|
+
name: triggerName,
|
|
430
|
+
properties: {
|
|
431
|
+
[modelPropertyName]: {
|
|
432
|
+
type: model,
|
|
433
|
+
validation: ['nonEmpty']
|
|
434
|
+
}
|
|
435
|
+
},
|
|
436
|
+
queuedBy: otherPropertyNames,
|
|
437
|
+
waitForEvents: true,
|
|
438
|
+
execute: getResetFunction(config, context)
|
|
439
|
+
})]
|
|
440
|
+
}
|
|
441
|
+
|
|
391
442
|
export {
|
|
392
443
|
defineObjectView, defineRangeViews,
|
|
393
|
-
defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction,
|
|
394
|
-
defineSetTrigger, defineUpdateTrigger, defineSetOrUpdateTrigger, defineResetTrigger
|
|
444
|
+
defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction, defineDeleteAction,
|
|
445
|
+
defineSetTrigger, defineUpdateTrigger, defineSetOrUpdateTrigger, defineResetTrigger, defineDeleteTrigger
|
|
395
446
|
}
|
package/singularRelationUtils.js
CHANGED
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, TriggerDefinition
|
|
4
4
|
} from "@live-change/framework"
|
|
5
5
|
import {
|
|
6
|
-
extractIdentifiers, extractObjectData, generateId, extractIdParts, prepareAccessControl
|
|
7
|
-
} from
|
|
6
|
+
extractIdentifiers, extractObjectData, generateId, extractIdParts, prepareAccessControl, cloneAndPrepareAccessControl
|
|
7
|
+
} from './utils.js'
|
|
8
8
|
import { fireChangeTriggers } from "./changeTriggers.js"
|
|
9
9
|
|
|
10
10
|
function defineView(config, context, external = true) {
|
|
@@ -20,8 +20,8 @@ function defineView(config, context, external = true) {
|
|
|
20
20
|
const viewName = config.name
|
|
21
21
|
|| ((config.prefix ? config.prefix + modelName : modelName[0].toLowerCase() + modelName.slice(1)) + (config.suffix || ''))
|
|
22
22
|
model.crud.read = viewName
|
|
23
|
-
const
|
|
24
|
-
|
|
23
|
+
const sourceAccessControl = external && (config.readAccessControl || config.writeAccessControl)
|
|
24
|
+
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames, others)
|
|
25
25
|
service.view({
|
|
26
26
|
name: viewName,
|
|
27
27
|
properties: {
|
|
@@ -73,8 +73,8 @@ function defineSetAction(config, context) {
|
|
|
73
73
|
} = context
|
|
74
74
|
const actionName = 'set' + modelName
|
|
75
75
|
model.crud.create = actionName
|
|
76
|
-
const
|
|
77
|
-
|
|
76
|
+
const sourceAccessControl = config.setAccessControl || config.writeAccessControl
|
|
77
|
+
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames, others)
|
|
78
78
|
const action = new ActionDefinition({
|
|
79
79
|
name: actionName,
|
|
80
80
|
properties: { ...(model.properties) },
|
|
@@ -148,8 +148,8 @@ function defineUpdateAction(config, context) {
|
|
|
148
148
|
} = context
|
|
149
149
|
const actionName = 'update' + modelName
|
|
150
150
|
model.crud.update = actionName
|
|
151
|
-
const
|
|
152
|
-
|
|
151
|
+
const sourceAccessControl = config.updateAccessControl || config.writeAccessControl
|
|
152
|
+
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames, others)
|
|
153
153
|
const action = new ActionDefinition({
|
|
154
154
|
name: actionName,
|
|
155
155
|
properties: {
|
|
@@ -225,15 +225,15 @@ function defineSetOrUpdateAction(config, context) {
|
|
|
225
225
|
} = context
|
|
226
226
|
const actionName = 'setOrUpdate' + modelName
|
|
227
227
|
model.crud.createOrUpdate = actionName
|
|
228
|
-
const
|
|
229
|
-
|
|
228
|
+
const sourceAccessControl = config.updateAccessControl || config.writeAccessControl
|
|
229
|
+
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames, others)
|
|
230
230
|
const action = new ActionDefinition({
|
|
231
231
|
name: actionName,
|
|
232
232
|
properties: {
|
|
233
233
|
...(model.properties)
|
|
234
234
|
},
|
|
235
235
|
access: config.updateAccess || config.writeAccess,
|
|
236
|
-
accessControl
|
|
236
|
+
accessControl,
|
|
237
237
|
skipValidation: true,
|
|
238
238
|
queuedBy: otherPropertyNames,
|
|
239
239
|
waitForEvents: true,
|
|
@@ -293,16 +293,18 @@ function getResetFunction( validators, validationContext, config, context) {
|
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
295
|
|
|
296
|
-
function
|
|
296
|
+
function defineDeleteAction(config, context) {
|
|
297
297
|
const {
|
|
298
298
|
service, modelRuntime, modelPropertyName, objectType, identifiers,
|
|
299
299
|
otherPropertyNames, joinedOthersPropertyName, modelName,
|
|
300
300
|
joinedOthersClassName, model, others, writeableProperties
|
|
301
301
|
} = context
|
|
302
|
-
const actionName = '
|
|
302
|
+
const actionName = 'delete' + modelName
|
|
303
303
|
model.crud.delete = actionName
|
|
304
|
-
const
|
|
305
|
-
|
|
304
|
+
const sourceAccessControl = config.resetAccessControl || config.writeAccessControl
|
|
305
|
+
const accessControl = cloneAndPrepareAccessControl(
|
|
306
|
+
sourceAccessControl, [modelPropertyName], [objectType]
|
|
307
|
+
)
|
|
306
308
|
const action = new ActionDefinition({
|
|
307
309
|
name: actionName,
|
|
308
310
|
properties: {
|
|
@@ -324,12 +326,12 @@ function defineResetAction(config, context) {
|
|
|
324
326
|
service.actions[actionName] = action
|
|
325
327
|
}
|
|
326
328
|
|
|
327
|
-
function
|
|
329
|
+
function defineDeleteTrigger(config, context) {
|
|
328
330
|
const {
|
|
329
331
|
service, modelRuntime, modelPropertyName, objectType,
|
|
330
332
|
otherPropertyNames, joinedOthersPropertyName, modelName, joinedOthersClassName, model, others, writeableProperties
|
|
331
333
|
} = context
|
|
332
|
-
const actionName = '
|
|
334
|
+
const actionName = 'delete' + modelName
|
|
333
335
|
const triggerName = `${service.name}_${actionName}`
|
|
334
336
|
const trigger = new TriggerDefinition({
|
|
335
337
|
name: triggerName,
|
|
@@ -350,8 +352,74 @@ function defineResetTrigger(config, context) {
|
|
|
350
352
|
service.triggers[triggerName] = [trigger]
|
|
351
353
|
}
|
|
352
354
|
|
|
355
|
+
|
|
356
|
+
function defineResetAction(config, context) {
|
|
357
|
+
const {
|
|
358
|
+
service, modelRuntime, modelPropertyName, objectType, identifiers,
|
|
359
|
+
otherPropertyNames, joinedOthersPropertyName, modelName,
|
|
360
|
+
joinedOthersClassName, model, others, writeableProperties
|
|
361
|
+
} = context
|
|
362
|
+
const actionName = 'reset' + modelName
|
|
363
|
+
const properties = {}
|
|
364
|
+
for (let i = 0; i < others.length; i++) {
|
|
365
|
+
properties[otherPropertyNames[i]] = new PropertyDefinition({
|
|
366
|
+
type: others[i],
|
|
367
|
+
validation: ['nonEmpty']
|
|
368
|
+
})
|
|
369
|
+
}
|
|
370
|
+
const sourceAccessControl = config.resetAccessControl || config.writeAccessControl
|
|
371
|
+
const accessControl = cloneAndPrepareAccessControl(
|
|
372
|
+
sourceAccessControl, [modelPropertyName], [objectType]
|
|
373
|
+
)
|
|
374
|
+
const action = new ActionDefinition({
|
|
375
|
+
name: actionName,
|
|
376
|
+
properties,
|
|
377
|
+
access: config.resetAccess || config.writeAccess,
|
|
378
|
+
accessControl,
|
|
379
|
+
queuedBy: otherPropertyNames,
|
|
380
|
+
waitForEvents: true,
|
|
381
|
+
execute: () => { throw new Error('not generated yet') }
|
|
382
|
+
})
|
|
383
|
+
const validators = App.validation.getValidators(action, service, action)
|
|
384
|
+
const validationContext = { source: action, action }
|
|
385
|
+
action.execute = getResetFunction( validators, validationContext, config, context)
|
|
386
|
+
if(service.actions[actionName]) throw new Error('Action ' + actionName + ' already defined')
|
|
387
|
+
service.actions[actionName] = action
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function defineResetTrigger(config, context) {
|
|
391
|
+
const {
|
|
392
|
+
service, modelRuntime, modelPropertyName, objectType,
|
|
393
|
+
otherPropertyNames, joinedOthersPropertyName, modelName, joinedOthersClassName, model,
|
|
394
|
+
others, writeableProperties
|
|
395
|
+
} = context
|
|
396
|
+
const actionName = 'reset' + modelName
|
|
397
|
+
const properties = {}
|
|
398
|
+
for (let i = 0; i < others.length; i++) {
|
|
399
|
+
properties[otherPropertyNames[i]] = new PropertyDefinition({
|
|
400
|
+
type: others[i],
|
|
401
|
+
validation: ['nonEmpty']
|
|
402
|
+
})
|
|
403
|
+
}
|
|
404
|
+
const triggerName = `${service.name}_${actionName}`
|
|
405
|
+
const trigger = new TriggerDefinition({
|
|
406
|
+
name: triggerName,
|
|
407
|
+
properties,
|
|
408
|
+
queuedBy: otherPropertyNames,
|
|
409
|
+
waitForEvents: true,
|
|
410
|
+
execute: () => { throw new Error('not generated yet') }
|
|
411
|
+
})
|
|
412
|
+
const validators = App.validation.getValidators(trigger, service, trigger)
|
|
413
|
+
const validationContext = { source: trigger, trigger }
|
|
414
|
+
trigger.execute = getResetFunction( validators, validationContext, config, context)
|
|
415
|
+
if(service.triggers[triggerName]) throw new Error('Trigger ' + triggerName + ' already defined')
|
|
416
|
+
service.triggers[triggerName] = [trigger]
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
|
|
353
421
|
export {
|
|
354
422
|
defineView,
|
|
355
|
-
defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction,
|
|
356
|
-
defineSetTrigger, defineUpdateTrigger, defineSetOrUpdateTrigger, defineResetTrigger
|
|
423
|
+
defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction, defineDeleteAction,
|
|
424
|
+
defineSetTrigger, defineUpdateTrigger, defineSetOrUpdateTrigger, defineDeleteTrigger, defineResetTrigger
|
|
357
425
|
}
|
package/utils.js
CHANGED
|
@@ -156,9 +156,20 @@ export function prepareAccessControl(accessControl, names, types) {
|
|
|
156
156
|
objectType: types[index],
|
|
157
157
|
object: params[name]
|
|
158
158
|
})))
|
|
159
|
+
accessControl.objParams = { names, types }
|
|
159
160
|
}
|
|
160
161
|
}
|
|
161
162
|
|
|
163
|
+
export function cloneAndPrepareAccessControl(accessControl, names, types) {
|
|
164
|
+
if(!accessControl) return accessControl
|
|
165
|
+
if(Array.isArray(accessControl)) {
|
|
166
|
+
accessControl = { roles: accessControl}
|
|
167
|
+
}
|
|
168
|
+
const newAccessControl = { ...accessControl }
|
|
169
|
+
prepareAccessControl(newAccessControl, names, types)
|
|
170
|
+
return newAccessControl
|
|
171
|
+
}
|
|
172
|
+
|
|
162
173
|
export function defineDeleteByOwnerEvents(config, context, generateId) {
|
|
163
174
|
const {
|
|
164
175
|
service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName, otherPropertyNames, reverseRelationWord
|
package/utilsAny.js
CHANGED
|
@@ -163,6 +163,16 @@ function prepareAccessControl(accessControl, names) {
|
|
|
163
163
|
}
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
+
export function cloneAndPrepareAccessControl(accessControl, names) {
|
|
167
|
+
if(!accessControl) return accessControl
|
|
168
|
+
if(Array.isArray(accessControl)) {
|
|
169
|
+
accessControl = { roles: accessControl}
|
|
170
|
+
}
|
|
171
|
+
const newAccessControl = { ...accessControl }
|
|
172
|
+
prepareAccessControl(newAccessControl, names)
|
|
173
|
+
return newAccessControl
|
|
174
|
+
}
|
|
175
|
+
|
|
166
176
|
function defineDeleteByOwnerEvents(config, context) {
|
|
167
177
|
const {
|
|
168
178
|
service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName, otherPropertyNames, reverseRelationWord
|