@live-change/relations-plugin 0.8.110 → 0.8.111
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/entity.js +7 -2
- package/itemOf.js +5 -2
- package/itemOfAny.js +6 -2
- package/package.json +3 -3
- package/pluralRelationAnyUtils.js +55 -3
- package/pluralRelationUtils.js +48 -4
- package/propertyOf.js +2 -0
- package/propertyOfAny.js +2 -0
- package/relatedTo.js +5 -2
- package/relatedToAny.js +5 -2
- package/singularRelationAnyUtils.js +5 -0
- package/singularRelationUtils.js +5 -1
- package/utils.js +14 -7
- package/utilsAny.js +3 -0
package/entity.js
CHANGED
|
@@ -21,6 +21,7 @@ function entityAccessControl({service, modelName, modelPropertyName}, accessCont
|
|
|
21
21
|
function defineView(config, context, external) {
|
|
22
22
|
const { service, modelRuntime, modelPropertyName, modelName, model } = context
|
|
23
23
|
const viewName = (config.prefix || '' ) + (config.prefix ? modelName : modelPropertyName) + (config.suffix || '')
|
|
24
|
+
if(external) model.crud.read = viewName
|
|
24
25
|
service.views[viewName] = new ViewDefinition({
|
|
25
26
|
name: viewName,
|
|
26
27
|
properties: {
|
|
@@ -140,6 +141,7 @@ function defineCreateAction(config, context) {
|
|
|
140
141
|
modelName, writeableProperties
|
|
141
142
|
} = context
|
|
142
143
|
const actionName = 'create' + modelName
|
|
144
|
+
model.crud.create = actionName
|
|
143
145
|
const action = new ActionDefinition({
|
|
144
146
|
name: actionName,
|
|
145
147
|
properties: { ...model.properties },
|
|
@@ -209,7 +211,7 @@ function defineUpdateAction(config, context) {
|
|
|
209
211
|
modelName, writeableProperties
|
|
210
212
|
} = context
|
|
211
213
|
const actionName = 'update' + modelName
|
|
212
|
-
|
|
214
|
+
model.crud.update = actionName
|
|
213
215
|
const action = new ActionDefinition({
|
|
214
216
|
name: actionName,
|
|
215
217
|
properties: {
|
|
@@ -282,7 +284,7 @@ function defineDeleteAction(config, context) {
|
|
|
282
284
|
modelName, writeableProperties
|
|
283
285
|
} = context
|
|
284
286
|
const actionName = 'delete' + modelName
|
|
285
|
-
|
|
287
|
+
model.crud.delete = actionName
|
|
286
288
|
service.actions[actionName] = new ActionDefinition({
|
|
287
289
|
name: actionName,
|
|
288
290
|
properties: {
|
|
@@ -336,6 +338,9 @@ export default function(service, app) {
|
|
|
336
338
|
const modelProperties = Object.keys(model.properties)
|
|
337
339
|
const modelPropertyName = modelName.slice(0, 1).toLowerCase() + modelName.slice(1)
|
|
338
340
|
|
|
341
|
+
model.identifiers = [{ [modelPropertyName]: 'id' }]
|
|
342
|
+
model.crud = {}
|
|
343
|
+
|
|
339
344
|
function modelRuntime() {
|
|
340
345
|
return service._runtime.models[modelName]
|
|
341
346
|
}
|
package/itemOf.js
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from './itemEvents.js'
|
|
11
11
|
|
|
12
12
|
import {
|
|
13
|
-
|
|
13
|
+
defineSingleView, defineRangeView,
|
|
14
14
|
defineCreateAction, defineUpdateAction, defineDeleteAction,
|
|
15
15
|
defineCreateTrigger, defineUpdateTrigger, defineDeleteTrigger, defineCopyTrigger,
|
|
16
16
|
defineSortIndex,
|
|
@@ -24,6 +24,7 @@ export default function(service, app) {
|
|
|
24
24
|
context.reverseRelationWord = 'Owned'
|
|
25
25
|
|
|
26
26
|
context.identifiers = defineProperties(context.model, context.others, context.otherPropertyNames)
|
|
27
|
+
context.model.identifiers = [...Object.keys(context.identifiers), { [context.modelPropertyName]: 'id' }]
|
|
27
28
|
|
|
28
29
|
addAccessControlParents(context)
|
|
29
30
|
defineIndexes(context.model, context.otherPropertyNames.map(p => p[0].toLowerCase() + p.slice(1)), context.others)
|
|
@@ -34,7 +35,9 @@ export default function(service, app) {
|
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
defineSingleView(config, context,
|
|
39
|
+
config.readAccess || config.readAccessControl || config.writeAccessControl)
|
|
40
|
+
defineRangeView(config, context,
|
|
38
41
|
config.readAccess || config.readAccessControl || config.writeAccessControl)
|
|
39
42
|
/// TODO: multiple views with limited fields
|
|
40
43
|
|
package/itemOfAny.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from './itemEvents.js'
|
|
10
10
|
|
|
11
11
|
import {
|
|
12
|
-
|
|
12
|
+
defineSingleView, defineRangeView,
|
|
13
13
|
defineCreateAction, defineUpdateAction, defineDeleteAction,
|
|
14
14
|
defineCreateTrigger, defineUpdateTrigger, defineDeleteTrigger,
|
|
15
15
|
defineSortIndex
|
|
@@ -22,6 +22,8 @@ export default function(service, app) {
|
|
|
22
22
|
context.reverseRelationWord = 'Owned'
|
|
23
23
|
|
|
24
24
|
context.identifiers = defineAnyProperties(context.model, context.otherPropertyNames)
|
|
25
|
+
context.model.identifiers = [...Object.keys(context.identifiers), { [context.modelPropertyName]: 'id' }]
|
|
26
|
+
|
|
25
27
|
addAccessControlAnyParents(context)
|
|
26
28
|
defineAnyIndexes(context.model, context.otherPropertyNames)
|
|
27
29
|
|
|
@@ -31,7 +33,9 @@ export default function(service, app) {
|
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
defineSingleView(config, context,
|
|
37
|
+
config.readAccess || config.writeAccess || config.readAccessControl || config.writeAccessControl)
|
|
38
|
+
defineRangeView(config, context,
|
|
35
39
|
config.readAccess || config.writeAccess || config.readAccessControl || config.writeAccessControl)
|
|
36
40
|
/// TODO: multiple views with all properties combinations
|
|
37
41
|
/// TODO: multiple views with limited fields
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/relations-plugin",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.111",
|
|
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.8.
|
|
25
|
+
"@live-change/framework": "^0.8.111",
|
|
26
26
|
"pluralize": "^8.0.0"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "9b96afb2fc61ab3d2a5d143924e2c56d411280b4"
|
|
29
29
|
}
|
|
@@ -4,12 +4,12 @@ import {
|
|
|
4
4
|
PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, TriggerDefinition
|
|
5
5
|
} from "@live-change/framework"
|
|
6
6
|
import { extractTypeAndIdParts, extractIdentifiersWithTypes, prepareAccessControl } from "./utilsAny.js"
|
|
7
|
-
import { extractObjectData, extractIdentifiers} from
|
|
7
|
+
import { extractObjectData, extractIdentifiers, extractIdParts } from './utils.js'
|
|
8
8
|
import { fireChangeTriggers } from "./changeTriggers.js"
|
|
9
9
|
|
|
10
10
|
import pluralize from 'pluralize'
|
|
11
11
|
|
|
12
|
-
function
|
|
12
|
+
function defineRangeView(config, context, external = true) {
|
|
13
13
|
const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
|
|
14
14
|
modelName, others, model } = context
|
|
15
15
|
const indexName = 'by'+context.joinedOthersClassName
|
|
@@ -27,6 +27,7 @@ function defineView(config, context, external = true) {
|
|
|
27
27
|
const accessControl = external && (config.readAccessControl || config.writeAccessControl)
|
|
28
28
|
prepareAccessControl(accessControl, otherPropertyNames)
|
|
29
29
|
const viewName = joinedOthersPropertyName + context.reverseRelationWord + pluralize(modelName)
|
|
30
|
+
model.crud.range = viewName
|
|
30
31
|
service.views[viewName] = new ViewDefinition({
|
|
31
32
|
name: viewName,
|
|
32
33
|
properties: {
|
|
@@ -51,6 +52,54 @@ function defineView(config, context, external = true) {
|
|
|
51
52
|
})
|
|
52
53
|
}
|
|
53
54
|
|
|
55
|
+
function defineSingleView(config, context, external = true) {
|
|
56
|
+
const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
|
|
57
|
+
modelName, others, model, modelPropertyName } = context
|
|
58
|
+
const indexName = 'by'+context.joinedOthersClassName
|
|
59
|
+
const viewProperties = {}
|
|
60
|
+
for (let i = 0; i < others.length; i++) {
|
|
61
|
+
viewProperties[otherPropertyNames[i]] = new PropertyDefinition({
|
|
62
|
+
type: 'String',
|
|
63
|
+
validation: ['nonEmpty']
|
|
64
|
+
})
|
|
65
|
+
viewProperties[otherPropertyNames[i] + 'Type'] = new PropertyDefinition({
|
|
66
|
+
type: 'String',
|
|
67
|
+
validation: ['nonEmpty']
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
viewProperties[modelPropertyName] = new PropertyDefinition({
|
|
71
|
+
type: model,
|
|
72
|
+
validation: ['nonEmpty']
|
|
73
|
+
})
|
|
74
|
+
const accessControl = external && (config.readAccessControl || config.writeAccessControl)
|
|
75
|
+
prepareAccessControl(accessControl, otherPropertyNames)
|
|
76
|
+
const viewName = joinedOthersPropertyName + context.reverseRelationWord + modelName
|
|
77
|
+
model.crud.read = viewName
|
|
78
|
+
service.views[viewName] = new ViewDefinition({
|
|
79
|
+
name: viewName,
|
|
80
|
+
properties: {
|
|
81
|
+
...viewProperties,
|
|
82
|
+
...App.utils.rangeProperties
|
|
83
|
+
},
|
|
84
|
+
returns: {
|
|
85
|
+
type: model
|
|
86
|
+
},
|
|
87
|
+
internal: !external,
|
|
88
|
+
access: external && (config.readAccess || config.writeAccess),
|
|
89
|
+
accessControl,
|
|
90
|
+
daoPath(properties, { client, context }) {
|
|
91
|
+
const idParts = extractIdParts(otherPropertyNames, properties)
|
|
92
|
+
const prefix = App.encodeIdentifier(idParts)
|
|
93
|
+
const range = {
|
|
94
|
+
gte: prefix+'_'+properties[modelPropertyName],
|
|
95
|
+
lte: prefix+'_'+properties[modelPropertyName]
|
|
96
|
+
}
|
|
97
|
+
const path = modelRuntime().indexObjectPath(indexName, idParts, range)
|
|
98
|
+
return path
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
|
|
54
103
|
function getCreateFunction( validators, validationContext, config, context) {
|
|
55
104
|
const {
|
|
56
105
|
service, app, model, modelPropertyName, modelRuntime, objectType,
|
|
@@ -82,6 +131,7 @@ function defineCreateAction(config, context) {
|
|
|
82
131
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
83
132
|
} = context
|
|
84
133
|
const actionName = 'create' + joinedOthersClassName + context.reverseRelationWord + modelName
|
|
134
|
+
model.crud.create = actionName
|
|
85
135
|
const accessControl = config.createAccessControl || config.writeAccessControl
|
|
86
136
|
prepareAccessControl(accessControl, otherPropertyNames)
|
|
87
137
|
const action = new ActionDefinition({
|
|
@@ -168,6 +218,7 @@ function defineUpdateAction(config, context) {
|
|
|
168
218
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
169
219
|
} = context
|
|
170
220
|
const actionName = 'update' + joinedOthersClassName + context.reverseRelationWord + modelName
|
|
221
|
+
model.crud.update = actionName
|
|
171
222
|
const accessControl = config.updateAccessControl || config.writeAccessControl
|
|
172
223
|
prepareAccessControl(accessControl, otherPropertyNames)
|
|
173
224
|
const action = new ActionDefinition({
|
|
@@ -250,6 +301,7 @@ function defineDeleteAction(config, context) {
|
|
|
250
301
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
251
302
|
} = context
|
|
252
303
|
const actionName = 'delete' + joinedOthersClassName + context.reverseRelationWord + modelName
|
|
304
|
+
model.crud.delete = actionName
|
|
253
305
|
const accessControl = config.deleteAccessControl || config.writeAccessControl
|
|
254
306
|
prepareAccessControl(accessControl, otherPropertyNames)
|
|
255
307
|
const action = new ActionDefinition({
|
|
@@ -310,7 +362,7 @@ function defineSortIndex(context, sortFields) {
|
|
|
310
362
|
}
|
|
311
363
|
|
|
312
364
|
export {
|
|
313
|
-
|
|
365
|
+
defineSingleView, defineRangeView,
|
|
314
366
|
defineCreateAction, defineUpdateAction, defineDeleteAction,
|
|
315
367
|
defineCreateTrigger, defineUpdateTrigger, defineDeleteTrigger,
|
|
316
368
|
defineSortIndex
|
package/pluralRelationUtils.js
CHANGED
|
@@ -6,7 +6,7 @@ import { extractIdParts, extractIdentifiers, extractObjectData, prepareAccessCon
|
|
|
6
6
|
import { fireChangeTriggers } from "./changeTriggers.js"
|
|
7
7
|
import pluralize from 'pluralize'
|
|
8
8
|
|
|
9
|
-
function
|
|
9
|
+
function defineRangeView(config, context, external = true) {
|
|
10
10
|
const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
|
|
11
11
|
modelName, others, model } = context
|
|
12
12
|
const indexName = 'by'+context.joinedOthersClassName
|
|
@@ -18,6 +18,7 @@ function defineView(config, context, external = true) {
|
|
|
18
18
|
})
|
|
19
19
|
}
|
|
20
20
|
const viewName = joinedOthersPropertyName + context.reverseRelationWord + pluralize(modelName)
|
|
21
|
+
model.crud.range = viewName
|
|
21
22
|
const accessControl = external && (config.readAccessControl || config.writeAccessControl)
|
|
22
23
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
23
24
|
service.views[viewName] = new ViewDefinition({
|
|
@@ -44,6 +45,49 @@ function defineView(config, context, external = true) {
|
|
|
44
45
|
})
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
function defineSingleView(config, context, external = true) {
|
|
49
|
+
const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
|
|
50
|
+
modelName, others, model, modelPropertyName } = context
|
|
51
|
+
const indexName = 'by'+context.joinedOthersClassName
|
|
52
|
+
const viewProperties = {}
|
|
53
|
+
for (let i = 0; i < others.length; i++) {
|
|
54
|
+
viewProperties[otherPropertyNames[i][0].toLowerCase() + otherPropertyNames[i].slice(1) ] = new PropertyDefinition({
|
|
55
|
+
type: others[i],
|
|
56
|
+
validation: ['nonEmpty']
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
viewProperties[modelPropertyName] = new PropertyDefinition({
|
|
60
|
+
type: model,
|
|
61
|
+
validation: ['nonEmpty']
|
|
62
|
+
})
|
|
63
|
+
const viewName = joinedOthersPropertyName + context.reverseRelationWord + modelName
|
|
64
|
+
model.crud.read = viewName
|
|
65
|
+
const accessControl = external && (config.readAccessControl || config.writeAccessControl)
|
|
66
|
+
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
67
|
+
service.views[viewName] = new ViewDefinition({
|
|
68
|
+
name: viewName,
|
|
69
|
+
properties: {
|
|
70
|
+
...viewProperties,
|
|
71
|
+
},
|
|
72
|
+
returns: {
|
|
73
|
+
type: model
|
|
74
|
+
},
|
|
75
|
+
internal: !external,
|
|
76
|
+
access: external && (config.readAccess || config.writeAccess),
|
|
77
|
+
accessControl: config.readAccessControl || config.writeAccessControl,
|
|
78
|
+
daoPath(properties, { client, context }) {
|
|
79
|
+
const idParts = extractIdParts(otherPropertyNames, properties)
|
|
80
|
+
const prefix = App.encodeIdentifier(idParts)
|
|
81
|
+
const range = {
|
|
82
|
+
gte: prefix+'_'+properties[modelPropertyName],
|
|
83
|
+
lte: prefix+'_'+properties[modelPropertyName]
|
|
84
|
+
}
|
|
85
|
+
const path = modelRuntime().indexObjectPath(indexName, idParts, range)
|
|
86
|
+
return path
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
47
91
|
function getCreateFunction( validators, validationContext, config, context) {
|
|
48
92
|
const {
|
|
49
93
|
service, app, model, modelPropertyName, modelRuntime, objectType,
|
|
@@ -75,6 +119,7 @@ function defineCreateAction(config, context) {
|
|
|
75
119
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
76
120
|
} = context
|
|
77
121
|
const actionName = 'create' + joinedOthersClassName + context.reverseRelationWord + modelName
|
|
122
|
+
model.crud.create = actionName
|
|
78
123
|
const accessControl = config.createAccessControl || config.writeAccessControl
|
|
79
124
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
80
125
|
const action = new ActionDefinition({
|
|
@@ -156,8 +201,8 @@ function defineUpdateAction(config, context) {
|
|
|
156
201
|
service, app, model, modelRuntime, modelPropertyName, objectType,
|
|
157
202
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
158
203
|
} = context
|
|
159
|
-
const eventName = joinedOthersPropertyName + context.reverseRelationWord + modelName + 'Updated'
|
|
160
204
|
const actionName = 'update' + joinedOthersClassName + context.reverseRelationWord + modelName
|
|
205
|
+
model.crud.update = actionName
|
|
161
206
|
const accessControl = config.updateAccessControl || config.writeAccessControl
|
|
162
207
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
163
208
|
const action = new ActionDefinition({
|
|
@@ -187,7 +232,6 @@ function defineUpdateTrigger(config, context) {
|
|
|
187
232
|
service, app, model, modelRuntime, modelPropertyName, objectType,
|
|
188
233
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
189
234
|
} = context
|
|
190
|
-
const eventName = joinedOthersPropertyName + context.reverseRelationWord + modelName + 'Updated'
|
|
191
235
|
const actionName = 'update' + joinedOthersClassName + context.reverseRelationWord + modelName
|
|
192
236
|
const triggerName = `${service.name}_${actionName}`
|
|
193
237
|
const trigger = new TriggerDefinition({
|
|
@@ -507,7 +551,7 @@ function defineSortIndex(context, sortFields) {
|
|
|
507
551
|
}
|
|
508
552
|
|
|
509
553
|
export {
|
|
510
|
-
|
|
554
|
+
defineRangeView, defineSingleView,
|
|
511
555
|
defineCreateAction, defineUpdateAction, defineDeleteAction, defineCopyAction,
|
|
512
556
|
defineCreateTrigger, defineUpdateTrigger, defineDeleteTrigger, defineCopyTrigger,
|
|
513
557
|
defineCopyOnParentCopyTrigger,
|
package/propertyOf.js
CHANGED
|
@@ -21,6 +21,8 @@ export default function(service, app) {
|
|
|
21
21
|
context.sameIdAsParent = true
|
|
22
22
|
|
|
23
23
|
context.identifiers = defineProperties(context.model, context.others, context.otherPropertyNames)
|
|
24
|
+
context.model.identifiers = Object.keys(context.identifiers)
|
|
25
|
+
|
|
24
26
|
addAccessControlParents(context)
|
|
25
27
|
defineIndexes(context.model, context.otherPropertyNames, context.others)
|
|
26
28
|
|
package/propertyOfAny.js
CHANGED
|
@@ -24,6 +24,8 @@ export default function(service, app) {
|
|
|
24
24
|
context.sameIdAsParent = true
|
|
25
25
|
|
|
26
26
|
context.identifiers = defineAnyProperties(context.model, context.otherPropertyNames)
|
|
27
|
+
context.model.identifiers = Object.keys(context.identifiers)
|
|
28
|
+
|
|
27
29
|
addAccessControlAnyParents(context)
|
|
28
30
|
defineAnyIndexes(context.model, context.otherPropertyNames, false)
|
|
29
31
|
|
package/relatedTo.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from './itemEvents.js'
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
|
-
|
|
10
|
+
defineSingleView, defineRangeView,
|
|
11
11
|
defineCreateAction, defineUpdateAction, defineDeleteAction, defineCopyAction,
|
|
12
12
|
defineCreateTrigger, defineUpdateTrigger, defineDeleteTrigger, defineCopyTrigger,
|
|
13
13
|
defineSortIndex,
|
|
@@ -28,7 +28,10 @@ export default function(service, app) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
defineSingleView(config, context,
|
|
32
|
+
config.readAccess || config.readAccessControl || config.writeAccessControl
|
|
33
|
+
)
|
|
34
|
+
defineRangeView(config, context,
|
|
32
35
|
config.readAccess || config.readAccessControl || config.writeAccessControl
|
|
33
36
|
)
|
|
34
37
|
/// TODO: multiple views with limited fields
|
package/relatedToAny.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from './itemEvents.js'
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
|
-
|
|
10
|
+
defineSingleView, defineRangeView,
|
|
11
11
|
defineCreateAction, defineUpdateAction, defineDeleteAction,
|
|
12
12
|
defineCreateTrigger, defineUpdateTrigger, defineDeleteTrigger,
|
|
13
13
|
defineSortIndex
|
|
@@ -28,7 +28,10 @@ export default function(service, app) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
defineSingleView(config, context,
|
|
32
|
+
config.readAccess || config.readAccessControl || config.writeAccessControl
|
|
33
|
+
)
|
|
34
|
+
defineRangeView(config, context,
|
|
32
35
|
config.readAccess || config.readAccessControl || config.writeAccessControl
|
|
33
36
|
)
|
|
34
37
|
/// TODO: multiple views with limited fields
|
|
@@ -45,6 +45,7 @@ function defineObjectView(config, context, external = true) {
|
|
|
45
45
|
prepareAccessControl(accessControl, otherPropertyNames)
|
|
46
46
|
const viewName = config.name || ((config.prefix ? (config.prefix + joinedOthersClassName) : joinedOthersPropertyName) +
|
|
47
47
|
context.reverseRelationWord + modelName + (config.suffix || ''))
|
|
48
|
+
model.crud.read = viewName
|
|
48
49
|
service.views[viewName] = new ViewDefinition({
|
|
49
50
|
name: viewName,
|
|
50
51
|
properties: {
|
|
@@ -127,6 +128,7 @@ function defineSetAction(config, context) {
|
|
|
127
128
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
128
129
|
} = context
|
|
129
130
|
const actionName = 'set' + joinedOthersClassName + context.reverseRelationWord + modelName
|
|
131
|
+
model.crud.create = actionName
|
|
130
132
|
const accessControl = config.setAccessControl || config.writeAccessControl
|
|
131
133
|
prepareAccessControl(accessControl, otherPropertyNames)
|
|
132
134
|
const action = new ActionDefinition({
|
|
@@ -198,6 +200,7 @@ function defineUpdateAction(config, context) {
|
|
|
198
200
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
199
201
|
} = context
|
|
200
202
|
const actionName = 'update' + joinedOthersClassName + context.reverseRelationWord + modelName
|
|
203
|
+
model.crud.update = actionName
|
|
201
204
|
const accessControl = config.updateAccessControl || config.writeAccessControl
|
|
202
205
|
prepareAccessControl(accessControl, otherPropertyNames)
|
|
203
206
|
const action = new ActionDefinition({
|
|
@@ -274,6 +277,7 @@ function defineSetOrUpdateAction(config, context) {
|
|
|
274
277
|
} = context
|
|
275
278
|
const eventName = joinedOthersPropertyName + context.reverseRelationWord + modelName + 'Updated'
|
|
276
279
|
const actionName = 'setOrUpdate' + joinedOthersClassName + context.reverseRelationWord + modelName
|
|
280
|
+
model.crud.createOrUpdate = actionName
|
|
277
281
|
const accessControl = config.setOrUpdateAccessControl || config.writeAccessControl
|
|
278
282
|
prepareAccessControl(accessControl, otherPropertyNames)
|
|
279
283
|
const action = new ActionDefinition({
|
|
@@ -343,6 +347,7 @@ function defineResetAction(config, context) {
|
|
|
343
347
|
otherPropertyNames, joinedOthersPropertyName, modelName, joinedOthersClassName, model
|
|
344
348
|
} = context
|
|
345
349
|
const actionName = 'reset' + joinedOthersClassName + context.reverseRelationWord + modelName
|
|
350
|
+
model.crud.delete = actionName
|
|
346
351
|
const accessControl = config.resetAccessControl || config.writeAccessControl
|
|
347
352
|
prepareAccessControl(accessControl, otherPropertyNames)
|
|
348
353
|
service.actions[actionName] = new ActionDefinition({
|
package/singularRelationUtils.js
CHANGED
|
@@ -19,6 +19,7 @@ function defineView(config, context, external = true) {
|
|
|
19
19
|
}
|
|
20
20
|
const viewName = config.name || ((config.prefix ? (config.prefix + joinedOthersClassName) : joinedOthersPropertyName) +
|
|
21
21
|
'Owned' + modelName + (config.suffix || ''))
|
|
22
|
+
model.crud.read = viewName
|
|
22
23
|
const accessControl = external && (config.readAccessControl || config.writeAccessControl)
|
|
23
24
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
24
25
|
service.views[viewName] = new ViewDefinition({
|
|
@@ -70,6 +71,7 @@ function defineSetAction(config, context) {
|
|
|
70
71
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
71
72
|
} = context
|
|
72
73
|
const actionName = 'set' + joinedOthersClassName + 'Owned' + modelName
|
|
74
|
+
model.crud.create = actionName
|
|
73
75
|
const accessControl = config.setAccessControl || config.writeAccessControl
|
|
74
76
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
75
77
|
const action = new ActionDefinition({
|
|
@@ -142,6 +144,7 @@ function defineUpdateAction(config, context) {
|
|
|
142
144
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
143
145
|
} = context
|
|
144
146
|
const actionName = 'update' + joinedOthersClassName + 'Owned' + modelName
|
|
147
|
+
model.crud.update = actionName
|
|
145
148
|
const accessControl = config.updateAccessControl || config.writeAccessControl
|
|
146
149
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
147
150
|
const action = new ActionDefinition({
|
|
@@ -215,8 +218,8 @@ function defineSetOrUpdateAction(config, context) {
|
|
|
215
218
|
service, app, model, modelRuntime, objectType,
|
|
216
219
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
217
220
|
} = context
|
|
218
|
-
const eventName = joinedOthersPropertyName + 'Owned' + modelName + 'Updated'
|
|
219
221
|
const actionName = 'setOrUpdate' + joinedOthersClassName + 'Owned' + modelName
|
|
222
|
+
model.crud.createOrUpdate = actionName
|
|
220
223
|
const accessControl = config.updateAccessControl || config.writeAccessControl
|
|
221
224
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
222
225
|
const action = new ActionDefinition({
|
|
@@ -286,6 +289,7 @@ function defineResetAction(config, context) {
|
|
|
286
289
|
otherPropertyNames, joinedOthersPropertyName, modelName, joinedOthersClassName, model, others, writeableProperties
|
|
287
290
|
} = context
|
|
288
291
|
const actionName = 'reset' + joinedOthersClassName + 'Owned' + modelName
|
|
292
|
+
model.crud.delete = actionName
|
|
289
293
|
const accessControl = config.resetAccessControl || config.writeAccessControl
|
|
290
294
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
291
295
|
const action = new ActionDefinition({
|
package/utils.js
CHANGED
|
@@ -76,6 +76,9 @@ export function processModelsAnnotation(service, app, annotation, multiple, cb)
|
|
|
76
76
|
const modelProperties = Object.keys(model.properties)
|
|
77
77
|
const modelPropertyName = modelName.slice(0, 1).toLowerCase() + modelName.slice(1)
|
|
78
78
|
|
|
79
|
+
if(!model.editableProperties) model.editableProperties = modelProperties
|
|
80
|
+
model.crud = {}
|
|
81
|
+
|
|
79
82
|
function modelRuntime() {
|
|
80
83
|
return service._runtime.models[modelName]
|
|
81
84
|
}
|
|
@@ -96,7 +99,7 @@ export function processModelsAnnotation(service, app, annotation, multiple, cb)
|
|
|
96
99
|
config = { what: config }
|
|
97
100
|
}
|
|
98
101
|
|
|
99
|
-
console.log("MODEL " + modelName + " IS " + annotation + " " + config.what)
|
|
102
|
+
console.log("MODEL " + modelName + " IS " + annotation + " " + config.what ?? '')
|
|
100
103
|
|
|
101
104
|
const what = (Array.isArray(config.what) ? config.what : [config.what])
|
|
102
105
|
const others = what.map(other => other.getTypeName ? other.getTypeName() : (other.name ? other.name : other))
|
|
@@ -127,17 +130,21 @@ export function addAccessControlParents(context) {
|
|
|
127
130
|
context.model.accessControlParents = async (what) => {
|
|
128
131
|
const id = what.object
|
|
129
132
|
const data = await modelRuntime().get(id)
|
|
130
|
-
return context.otherPropertyNames.map(otherPropertyName => {
|
|
131
|
-
const
|
|
133
|
+
return context.otherPropertyNames.map((otherPropertyName, i) => {
|
|
134
|
+
const other = context.others[i]
|
|
135
|
+
const objectType = other
|
|
132
136
|
const object = data[otherPropertyName]
|
|
133
137
|
return { objectType, object }
|
|
134
138
|
}).filter(parent => parent.object && parent.objectType)
|
|
135
139
|
}
|
|
136
140
|
context.model.accessControlParentsSource = context.otherPropertyNames.map(
|
|
137
|
-
otherPropertyName =>
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
+
(otherPropertyName, i) => {
|
|
142
|
+
const other = context.others[i]
|
|
143
|
+
return ({
|
|
144
|
+
property: otherPropertyName,
|
|
145
|
+
type: other
|
|
146
|
+
})
|
|
147
|
+
}
|
|
141
148
|
)
|
|
142
149
|
}
|
|
143
150
|
|
package/utilsAny.js
CHANGED
|
@@ -88,6 +88,9 @@ function processModelsAnyAnnotation(service, app, annotation, multiple, cb) {
|
|
|
88
88
|
const modelProperties = Object.keys(model.properties)
|
|
89
89
|
const modelPropertyName = modelName.slice(0, 1).toLowerCase() + modelName.slice(1)
|
|
90
90
|
|
|
91
|
+
if(!model.editableProperties) model.editableProperties = modelProperties
|
|
92
|
+
model.crud = {}
|
|
93
|
+
|
|
91
94
|
function modelRuntime() {
|
|
92
95
|
return service._runtime.models[modelName]
|
|
93
96
|
}
|