@live-change/relations-plugin 0.9.16 → 0.9.18
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 +15 -5
- package/package.json +3 -3
- package/propertyOf.js +13 -3
- package/propertyOfAny.js +6 -1
- package/singularRelationAnyUtils.js +4 -14
- package/singularRelationUtils.js +113 -32
- package/utils.js +19 -2
- package/utilsAny.js +19 -6
package/boundTo.js
CHANGED
|
@@ -6,7 +6,8 @@ import {
|
|
|
6
6
|
import { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent } from './propertyEvents.js'
|
|
7
7
|
|
|
8
8
|
import {
|
|
9
|
-
|
|
9
|
+
defineObjectView,
|
|
10
|
+
defineRangeViews,
|
|
10
11
|
defineSetAction,
|
|
11
12
|
defineUpdateAction,
|
|
12
13
|
defineSetOrUpdateAction,
|
|
@@ -24,16 +25,25 @@ export default function(service, app) {
|
|
|
24
25
|
|
|
25
26
|
context.relationWord = 'Friend'
|
|
26
27
|
context.reverseRelationWord = 'Bound'
|
|
28
|
+
context.partialReverseRelationWord = 'Bound'
|
|
27
29
|
|
|
28
30
|
defineProperties(context.model, context.others, context.otherPropertyNames)
|
|
29
31
|
defineIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
defineObjectView({ ...config, access: config.readAccess }, context,
|
|
32
34
|
config.readAccess || config.readAccessControl || config.writeAccessControl
|
|
33
35
|
)
|
|
36
|
+
defineRangeViews(config, context,
|
|
37
|
+
config.listAccess || config.readAccess || config.listAccessControl
|
|
38
|
+
)
|
|
39
|
+
|
|
34
40
|
if(config.views) {
|
|
35
41
|
for(const view of config.views) {
|
|
36
|
-
|
|
42
|
+
if(view.type !== 'range') {
|
|
43
|
+
defineObjectView({ ...config, ...view }, context, !view.internal)
|
|
44
|
+
} else {
|
|
45
|
+
defineRangeViews({ ...config, ...view }, context, !view.internal)
|
|
46
|
+
}
|
|
37
47
|
}
|
|
38
48
|
}
|
|
39
49
|
|
package/boundToAny.js
CHANGED
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
import { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent } from './propertyEvents.js'
|
|
7
7
|
|
|
8
8
|
import {
|
|
9
|
-
|
|
9
|
+
defineObjectView, defineRangeViews,
|
|
10
10
|
defineSetAction, defineUpdateAction, defineResetAction, defineSetOrUpdateAction,
|
|
11
11
|
defineSetTrigger, defineUpdateTrigger, defineSetOrUpdateTrigger, defineResetTrigger
|
|
12
|
-
} from './
|
|
12
|
+
} from './singularRelationAnyUtils.js'
|
|
13
13
|
import { defineDeleteAction, defineDeleteTrigger } from './singularRelationAnyUtils.js'
|
|
14
14
|
|
|
15
15
|
export default function(service, app) {
|
|
@@ -17,15 +17,25 @@ export default function(service, app) {
|
|
|
17
17
|
|
|
18
18
|
context.relationWord = 'Friend'
|
|
19
19
|
context.reverseRelationWord = 'Bound'
|
|
20
|
+
context.partialReverseRelationWord = 'Bound'
|
|
20
21
|
|
|
21
22
|
defineAnyProperties(context.model, context.otherPropertyNames)
|
|
22
23
|
defineAnyIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
config.readAccess || config.
|
|
25
|
+
defineObjectView(config, context,
|
|
26
|
+
config.singleAccess || config.readAccess || config.singleAccessControl || config.readAccessControl
|
|
27
|
+
)
|
|
28
|
+
defineRangeViews(config, context,
|
|
29
|
+
config.listAccess || config.readAccess || config.listAccessControl || config.readAccessControl
|
|
30
|
+
)
|
|
31
|
+
|
|
26
32
|
if(config.views) {
|
|
27
33
|
for(const view of config.views) {
|
|
28
|
-
|
|
34
|
+
if(view.type !== 'range') {
|
|
35
|
+
defineObjectView({ ...config, ...view }, context, !view.internal)
|
|
36
|
+
} else {
|
|
37
|
+
defineRangeViews({ ...config, ...view }, context, !view.internal)
|
|
38
|
+
}
|
|
29
39
|
}
|
|
30
40
|
}
|
|
31
41
|
|
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.18",
|
|
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.18",
|
|
26
26
|
"pluralize": "^8.0.0"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "d7fd7ad0a0ea331caea9dc8385439b9c637525ed"
|
|
29
29
|
}
|
package/propertyOf.js
CHANGED
|
@@ -7,7 +7,8 @@ import {
|
|
|
7
7
|
import { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent } from './propertyEvents.js'
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
|
-
|
|
10
|
+
defineObjectView,
|
|
11
|
+
defineRangeViews,
|
|
11
12
|
defineSetAction,
|
|
12
13
|
defineUpdateAction,
|
|
13
14
|
defineSetOrUpdateAction,
|
|
@@ -25,6 +26,7 @@ export default function(service, app) {
|
|
|
25
26
|
|
|
26
27
|
context.relationWord = 'Property'
|
|
27
28
|
context.reverseRelationWord = 'Owned'
|
|
29
|
+
context.partialReverseRelationWord = 'Owned'
|
|
28
30
|
|
|
29
31
|
context.sameIdAsParent = true
|
|
30
32
|
|
|
@@ -34,11 +36,19 @@ export default function(service, app) {
|
|
|
34
36
|
addAccessControlParents(context)
|
|
35
37
|
defineIndexes(context.model, context.otherPropertyNames, context.others)
|
|
36
38
|
|
|
37
|
-
|
|
39
|
+
defineObjectView({ ...config }, context,
|
|
38
40
|
config.readAccess || config.writeAccess || config.readAccessControl || config.writeAccessControl)
|
|
41
|
+
defineRangeViews(config, context,
|
|
42
|
+
config.listAccess || config.readAccess || config.listAccessControl
|
|
43
|
+
)
|
|
44
|
+
|
|
39
45
|
if(config.views) {
|
|
40
46
|
for(const view of config.views) {
|
|
41
|
-
|
|
47
|
+
if(view.type !== 'range') {
|
|
48
|
+
defineObjectView({ ...config, ...view }, context, !view.internal)
|
|
49
|
+
} else {
|
|
50
|
+
defineRangeViews({ ...config, ...view }, context, !view.internal)
|
|
51
|
+
}
|
|
42
52
|
}
|
|
43
53
|
}
|
|
44
54
|
|
package/propertyOfAny.js
CHANGED
|
@@ -44,9 +44,14 @@ export default function(service, app) {
|
|
|
44
44
|
defineRangeViews(config, context,
|
|
45
45
|
config.listAccess || config.readAccess || config.listAccessControl || config.readAccessControl
|
|
46
46
|
)
|
|
47
|
+
|
|
47
48
|
if(config.views) {
|
|
48
49
|
for(const view of config.views) {
|
|
49
|
-
|
|
50
|
+
if(view.type !== 'range') {
|
|
51
|
+
defineObjectView({ ...config, ...view }, context, !view.internal)
|
|
52
|
+
} else {
|
|
53
|
+
defineRangeViews({ ...config, ...view }, context, !view.internal)
|
|
54
|
+
}
|
|
50
55
|
}
|
|
51
56
|
}
|
|
52
57
|
|
|
@@ -15,14 +15,14 @@ import { fireChangeTriggers } from "./changeTriggers.js"
|
|
|
15
15
|
|
|
16
16
|
import pluralize from 'pluralize'
|
|
17
17
|
|
|
18
|
-
function createIdentifiersProperties(keys) {
|
|
18
|
+
export function createIdentifiersProperties(keys) {
|
|
19
19
|
const identifiers = {}
|
|
20
20
|
if(keys) for(const key of keys) {
|
|
21
|
-
identifiers[key] = {
|
|
21
|
+
identifiers[key + 'Type'] = {
|
|
22
22
|
type: String,
|
|
23
23
|
validation: ['nonEmpty']
|
|
24
24
|
}
|
|
25
|
-
identifiers[key
|
|
25
|
+
identifiers[key] = {
|
|
26
26
|
type: String,
|
|
27
27
|
validation: ['nonEmpty']
|
|
28
28
|
}
|
|
@@ -33,17 +33,7 @@ function createIdentifiersProperties(keys) {
|
|
|
33
33
|
function defineObjectView(config, context, external = true) {
|
|
34
34
|
const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
|
|
35
35
|
modelName, others, model } = context
|
|
36
|
-
const viewProperties =
|
|
37
|
-
for (let i = 0; i < others.length; i++) {
|
|
38
|
-
viewProperties[otherPropertyNames[i]] = new PropertyDefinition({
|
|
39
|
-
type: 'String',
|
|
40
|
-
validation: ['nonEmpty']
|
|
41
|
-
})
|
|
42
|
-
viewProperties[otherPropertyNames[i] + 'Type'] = new PropertyDefinition({
|
|
43
|
-
type: 'String',
|
|
44
|
-
validation: ['nonEmpty']
|
|
45
|
-
})
|
|
46
|
-
}
|
|
36
|
+
const viewProperties = createIdentifiersProperties(otherPropertyNames)
|
|
47
37
|
const sourceAccessControl = external
|
|
48
38
|
&& (config.singleAccessControl || config.readAccessControl || config.writeAccessControl)
|
|
49
39
|
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, otherPropertyNames)
|
package/singularRelationUtils.js
CHANGED
|
@@ -3,20 +3,35 @@ import {
|
|
|
3
3
|
PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, TriggerDefinition
|
|
4
4
|
} from "@live-change/framework"
|
|
5
5
|
import {
|
|
6
|
-
extractIdentifiers,
|
|
6
|
+
extractIdentifiers,
|
|
7
|
+
extractObjectData,
|
|
8
|
+
generateId,
|
|
9
|
+
extractIdParts,
|
|
10
|
+
prepareAccessControl,
|
|
11
|
+
cloneAndPrepareAccessControl,
|
|
12
|
+
defineIndex
|
|
7
13
|
} from './utils.js'
|
|
8
14
|
import { fireChangeTriggers } from "./changeTriggers.js"
|
|
15
|
+
import { extractTypeAndIdParts } from './utilsAny.js'
|
|
16
|
+
import { allCombinations } from './combinations.js'
|
|
17
|
+
import pluralize from 'pluralize'
|
|
9
18
|
|
|
10
|
-
function
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
type: others[i],
|
|
19
|
+
export function createIdentifiersProperties(keys, types) {
|
|
20
|
+
const identifiers = {}
|
|
21
|
+
if(keys) for(let i = 0; i < keys.length; i++) {
|
|
22
|
+
const key = keys[i]
|
|
23
|
+
identifiers[key] = {
|
|
24
|
+
type: types?.[i] || String,
|
|
17
25
|
validation: ['nonEmpty']
|
|
18
|
-
}
|
|
26
|
+
}
|
|
19
27
|
}
|
|
28
|
+
return identifiers
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function defineObjectView(config, context, external = true) {
|
|
32
|
+
const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
|
|
33
|
+
modelName, others, model } = context
|
|
34
|
+
const viewProperties = createIdentifiersProperties(otherPropertyNames, others)
|
|
20
35
|
const viewName = config.name
|
|
21
36
|
|| ((config.prefix ? config.prefix + modelName : modelName[0].toLowerCase() + modelName.slice(1)) + (config.suffix || ''))
|
|
22
37
|
model.crud.read = viewName
|
|
@@ -43,7 +58,81 @@ function defineView(config, context, external = true) {
|
|
|
43
58
|
})
|
|
44
59
|
}
|
|
45
60
|
|
|
46
|
-
function
|
|
61
|
+
export function defineRangeViews(config, context, external = true) {
|
|
62
|
+
const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
|
|
63
|
+
modelName, others, model } = context
|
|
64
|
+
const identifierCombinations = allCombinations(Object.keys(otherPropertyNames)).slice(0, -1)
|
|
65
|
+
const sourceAccessControl = external
|
|
66
|
+
&& (config.listAccessControl || config.readAccessControl || config.writeAccessControl)
|
|
67
|
+
for(const combination of identifierCombinations) {
|
|
68
|
+
const combinationKeys = combination.map(prop => otherPropertyNames[prop])
|
|
69
|
+
const combinationTypes = combination.map(prop => others[prop])
|
|
70
|
+
const propsUpperCase = combinationKeys.map(prop => prop[0].toUpperCase() + prop.slice(1))
|
|
71
|
+
const indexName = 'by' + combinationKeys.map(prop => prop[0].toUpperCase() + prop.slice(1)).join('And')
|
|
72
|
+
const viewName = combinationKeys[0][0].toLowerCase() + combinationKeys[0].slice(1) +
|
|
73
|
+
propsUpperCase.slice(1).join('And') + context.partialReverseRelationWord + pluralize(modelName)
|
|
74
|
+
model.crud['rangeBy_'+combinationTypes.join('And')] = viewName
|
|
75
|
+
//console.log("DEFINE RANGE VIEW", viewName, combination)
|
|
76
|
+
const identifiers = createIdentifiersProperties(combinationKeys, combinationTypes)
|
|
77
|
+
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, combinationKeys, combinationTypes)
|
|
78
|
+
service.view({
|
|
79
|
+
name: viewName,
|
|
80
|
+
properties: {
|
|
81
|
+
...identifiers,
|
|
82
|
+
...App.rangeProperties,
|
|
83
|
+
},
|
|
84
|
+
internal: !external,
|
|
85
|
+
access: external && (config.listAccess || config.readAccess),
|
|
86
|
+
accessControl,
|
|
87
|
+
daoPath(params, { client, context }) {
|
|
88
|
+
const owner = []
|
|
89
|
+
for (const key of combination) owner.push(params[ownerPropertyNames[key]])
|
|
90
|
+
return modelRuntime().sortedIndexRangePath(indexName, owner, App.extractRange(params) )
|
|
91
|
+
}
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
const propsByType = {}
|
|
95
|
+
for(let i = 0; i < otherPropertyNames.length; i++) {
|
|
96
|
+
const prop = otherPropertyNames[i]
|
|
97
|
+
const type = others[i]
|
|
98
|
+
if(!propsByType[type]) propsByType[type] = []
|
|
99
|
+
propsByType[type].push(prop)
|
|
100
|
+
}
|
|
101
|
+
const multiPropsTypes = Object.keys(propsByType).filter(type => propsByType[type].length > 1)
|
|
102
|
+
const typeCombinations = allCombinations(multiPropsTypes)
|
|
103
|
+
for(const typeCombination of typeCombinations) {
|
|
104
|
+
const typeNames = typeCombination.map(t => {
|
|
105
|
+
const type = t.split('_')[1]
|
|
106
|
+
return type[0].toUpperCase() + type.slice(1)
|
|
107
|
+
})
|
|
108
|
+
const parametersNames = typeCombination
|
|
109
|
+
.map(t => t.split('_').pop())
|
|
110
|
+
.map(t => t[0].toLowerCase() + t.slice(1))
|
|
111
|
+
const accessControl = cloneAndPrepareAccessControl(sourceAccessControl, parametersNames, typeCombination)
|
|
112
|
+
const indexName = 'by'+typeNames.join('And')
|
|
113
|
+
const viewName = typeNames.join('And') + context.partialReverseRelationWord + pluralize(modelName)
|
|
114
|
+
model.crud['rangeBy_'+typeCombination.join('And')] = viewName
|
|
115
|
+
//console.log("DEFINE TYPE RANGE VIEW", viewName, typeCombination)
|
|
116
|
+
const identifiers = createIdentifiersProperties(parametersNames, typeCombination)
|
|
117
|
+
service.view({
|
|
118
|
+
name: viewName,
|
|
119
|
+
properties: {
|
|
120
|
+
...identifiers,
|
|
121
|
+
...App.rangeProperties,
|
|
122
|
+
},
|
|
123
|
+
internal: !external,
|
|
124
|
+
access: external && (config.listAccess || config.readAccess),
|
|
125
|
+
accessControl,
|
|
126
|
+
daoPath(params, { client, context }) {
|
|
127
|
+
const owner = []
|
|
128
|
+
for (const key of parametersNames) owner.push(params[key])
|
|
129
|
+
return modelRuntime().sortedIndexRangePath(indexName, owner, App.extractRange(params) )
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function getSetFunction( validators, validationContext, config, context) {
|
|
47
136
|
const {
|
|
48
137
|
service, app, model, objectType,
|
|
49
138
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
@@ -66,7 +155,7 @@ function getSetFunction( validators, validationContext, config, context) {
|
|
|
66
155
|
return execute
|
|
67
156
|
}
|
|
68
157
|
|
|
69
|
-
function defineSetAction(config, context) {
|
|
158
|
+
export function defineSetAction(config, context) {
|
|
70
159
|
const {
|
|
71
160
|
service, app, model, objectType,
|
|
72
161
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
@@ -92,7 +181,7 @@ function defineSetAction(config, context) {
|
|
|
92
181
|
service.actions[actionName] = action
|
|
93
182
|
}
|
|
94
183
|
|
|
95
|
-
function defineSetTrigger(config, context) {
|
|
184
|
+
export function defineSetTrigger(config, context) {
|
|
96
185
|
const {
|
|
97
186
|
service, app, model, objectType,
|
|
98
187
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
@@ -114,7 +203,7 @@ function defineSetTrigger(config, context) {
|
|
|
114
203
|
service.triggers[triggerName] = [trigger]
|
|
115
204
|
}
|
|
116
205
|
|
|
117
|
-
function getUpdateFunction( validators, validationContext, config, context) {
|
|
206
|
+
export function getUpdateFunction( validators, validationContext, config, context) {
|
|
118
207
|
const {
|
|
119
208
|
service, app, model, modelRuntime, objectType,
|
|
120
209
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
@@ -141,7 +230,7 @@ function getUpdateFunction( validators, validationContext, config, context) {
|
|
|
141
230
|
}
|
|
142
231
|
}
|
|
143
232
|
|
|
144
|
-
function defineUpdateAction(config, context) {
|
|
233
|
+
export function defineUpdateAction(config, context) {
|
|
145
234
|
const {
|
|
146
235
|
service, app, model, modelRuntime, objectType,
|
|
147
236
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
@@ -169,7 +258,7 @@ function defineUpdateAction(config, context) {
|
|
|
169
258
|
service.actions[actionName] = action
|
|
170
259
|
}
|
|
171
260
|
|
|
172
|
-
function defineUpdateTrigger(config, context) {
|
|
261
|
+
export function defineUpdateTrigger(config, context) {
|
|
173
262
|
const {
|
|
174
263
|
service, app, model, modelRuntime, objectType,
|
|
175
264
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
@@ -193,7 +282,7 @@ function defineUpdateTrigger(config, context) {
|
|
|
193
282
|
service.triggers[triggerName] = [trigger]
|
|
194
283
|
}
|
|
195
284
|
|
|
196
|
-
function getSetOrUpdateFunction( validators, validationContext, config, context) {
|
|
285
|
+
export function getSetOrUpdateFunction( validators, validationContext, config, context) {
|
|
197
286
|
const {
|
|
198
287
|
service, app, model, modelRuntime, objectType,
|
|
199
288
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
@@ -218,7 +307,7 @@ function getSetOrUpdateFunction( validators, validationContext, config, context)
|
|
|
218
307
|
}
|
|
219
308
|
}
|
|
220
309
|
|
|
221
|
-
function defineSetOrUpdateAction(config, context) {
|
|
310
|
+
export function defineSetOrUpdateAction(config, context) {
|
|
222
311
|
const {
|
|
223
312
|
service, app, model, modelRuntime, objectType,
|
|
224
313
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
@@ -246,7 +335,7 @@ function defineSetOrUpdateAction(config, context) {
|
|
|
246
335
|
service.actions[actionName] = action
|
|
247
336
|
}
|
|
248
337
|
|
|
249
|
-
function defineSetOrUpdateTrigger(config, context) {
|
|
338
|
+
export function defineSetOrUpdateTrigger(config, context) {
|
|
250
339
|
const {
|
|
251
340
|
service, app, model, modelRuntime, objectType,
|
|
252
341
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
@@ -270,7 +359,7 @@ function defineSetOrUpdateTrigger(config, context) {
|
|
|
270
359
|
service.triggers[triggerName] = [trigger]
|
|
271
360
|
}
|
|
272
361
|
|
|
273
|
-
function getResetFunction( validators, validationContext, config, context) {
|
|
362
|
+
export function getResetFunction( validators, validationContext, config, context) {
|
|
274
363
|
const {
|
|
275
364
|
service, modelRuntime, modelPropertyName, objectType,
|
|
276
365
|
otherPropertyNames, joinedOthersPropertyName, modelName, joinedOthersClassName, model, others, writeableProperties
|
|
@@ -293,14 +382,13 @@ function getResetFunction( validators, validationContext, config, context) {
|
|
|
293
382
|
}
|
|
294
383
|
}
|
|
295
384
|
|
|
296
|
-
function defineDeleteAction(config, context) {
|
|
385
|
+
export function defineDeleteAction(config, context) {
|
|
297
386
|
const {
|
|
298
387
|
service, modelRuntime, modelPropertyName, objectType, identifiers,
|
|
299
388
|
otherPropertyNames, joinedOthersPropertyName, modelName,
|
|
300
389
|
joinedOthersClassName, model, others, writeableProperties
|
|
301
390
|
} = context
|
|
302
391
|
const actionName = 'delete' + modelName
|
|
303
|
-
model.crud.delete = actionName
|
|
304
392
|
const sourceAccessControl = config.resetAccessControl || config.writeAccessControl
|
|
305
393
|
const accessControl = cloneAndPrepareAccessControl(
|
|
306
394
|
sourceAccessControl, [modelPropertyName], [objectType]
|
|
@@ -326,7 +414,7 @@ function defineDeleteAction(config, context) {
|
|
|
326
414
|
service.actions[actionName] = action
|
|
327
415
|
}
|
|
328
416
|
|
|
329
|
-
function defineDeleteTrigger(config, context) {
|
|
417
|
+
export function defineDeleteTrigger(config, context) {
|
|
330
418
|
const {
|
|
331
419
|
service, modelRuntime, modelPropertyName, objectType,
|
|
332
420
|
otherPropertyNames, joinedOthersPropertyName, modelName, joinedOthersClassName, model, others, writeableProperties
|
|
@@ -353,13 +441,14 @@ function defineDeleteTrigger(config, context) {
|
|
|
353
441
|
}
|
|
354
442
|
|
|
355
443
|
|
|
356
|
-
function defineResetAction(config, context) {
|
|
444
|
+
export function defineResetAction(config, context) {
|
|
357
445
|
const {
|
|
358
446
|
service, modelRuntime, modelPropertyName, objectType, identifiers,
|
|
359
447
|
otherPropertyNames, joinedOthersPropertyName, modelName,
|
|
360
448
|
joinedOthersClassName, model, others, writeableProperties
|
|
361
449
|
} = context
|
|
362
450
|
const actionName = 'reset' + modelName
|
|
451
|
+
model.crud.delete = actionName
|
|
363
452
|
const properties = {}
|
|
364
453
|
for (let i = 0; i < others.length; i++) {
|
|
365
454
|
properties[otherPropertyNames[i]] = new PropertyDefinition({
|
|
@@ -387,7 +476,7 @@ function defineResetAction(config, context) {
|
|
|
387
476
|
service.actions[actionName] = action
|
|
388
477
|
}
|
|
389
478
|
|
|
390
|
-
function defineResetTrigger(config, context) {
|
|
479
|
+
export function defineResetTrigger(config, context) {
|
|
391
480
|
const {
|
|
392
481
|
service, modelRuntime, modelPropertyName, objectType,
|
|
393
482
|
otherPropertyNames, joinedOthersPropertyName, modelName, joinedOthersClassName, model,
|
|
@@ -415,11 +504,3 @@ function defineResetTrigger(config, context) {
|
|
|
415
504
|
if(service.triggers[triggerName]) throw new Error('Trigger ' + triggerName + ' already defined')
|
|
416
505
|
service.triggers[triggerName] = [trigger]
|
|
417
506
|
}
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
export {
|
|
422
|
-
defineView,
|
|
423
|
-
defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction, defineDeleteAction,
|
|
424
|
-
defineSetTrigger, defineUpdateTrigger, defineSetOrUpdateTrigger, defineDeleteTrigger, defineResetTrigger
|
|
425
|
-
}
|
package/utils.js
CHANGED
|
@@ -41,10 +41,11 @@ export function defineProperties(model, types, names) {
|
|
|
41
41
|
return identifiers
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
export function defineIndex(model, what, props) {
|
|
44
|
+
export function defineIndex(model, what, props, multi = undefined) {
|
|
45
45
|
console.log("DEFINE INDEX", model.name, what, props)
|
|
46
46
|
model.indexes['by' + what] = new IndexDefinition({
|
|
47
|
-
property: props
|
|
47
|
+
property: props,
|
|
48
|
+
multi
|
|
48
49
|
})
|
|
49
50
|
}
|
|
50
51
|
export function defineIndexes(model, props, types) {
|
|
@@ -58,6 +59,22 @@ export function defineIndexes(model, props, types) {
|
|
|
58
59
|
const indexProps = propCombination.map(id => props[id])
|
|
59
60
|
defineIndex(model, upperCaseProps.join('And'), indexProps)
|
|
60
61
|
}
|
|
62
|
+
const propsByType = {}
|
|
63
|
+
for(const prop in props) {
|
|
64
|
+
const type = types[prop]
|
|
65
|
+
if(!propsByType[type]) propsByType[type] = []
|
|
66
|
+
propsByType[type].push(prop)
|
|
67
|
+
}
|
|
68
|
+
const multiPropsTypes = Object.keys(propsByType).filter(type => propsByType[type].length > 1)
|
|
69
|
+
const typeCombinations = allCombinations(multiPropsTypes)
|
|
70
|
+
for(const typeCombination of typeCombinations) {
|
|
71
|
+
const typeNames = typeCombination.map(t => {
|
|
72
|
+
const type = t.split('_')[1]
|
|
73
|
+
return type[0].toUpperCase() + type.slice(1)
|
|
74
|
+
})
|
|
75
|
+
const typeProps = typeCombination.map(type => propsByType[type])
|
|
76
|
+
defineIndex(model, typeNames.join('And'), typeProps, true)
|
|
77
|
+
}
|
|
61
78
|
}
|
|
62
79
|
|
|
63
80
|
export function processModelsAnnotation(service, app, annotation, multiple, cb) {
|
package/utilsAny.js
CHANGED
|
@@ -41,11 +41,11 @@ function generateAnyId(otherPropertyNames, properties) {
|
|
|
41
41
|
function defineAnyProperties(model, names) {
|
|
42
42
|
const identifiers = {}
|
|
43
43
|
for (let i = 0; i < names.length; i++) {
|
|
44
|
-
identifiers[names[i]] = new PropertyDefinition({
|
|
44
|
+
identifiers[names[i]+'Type'] = new PropertyDefinition({
|
|
45
45
|
type: String,
|
|
46
46
|
validation: ['nonEmpty']
|
|
47
47
|
})
|
|
48
|
-
identifiers[names[i]
|
|
48
|
+
identifiers[names[i]] = new PropertyDefinition({
|
|
49
49
|
type: String,
|
|
50
50
|
validation: ['nonEmpty']
|
|
51
51
|
})
|
|
@@ -111,8 +111,18 @@ function processModelsAnyAnnotation(service, app, annotation, multiple, cb) {
|
|
|
111
111
|
|
|
112
112
|
console.log("MODEL " + modelName + " IS " + annotation + " " + config.what)
|
|
113
113
|
|
|
114
|
-
const
|
|
115
|
-
|
|
114
|
+
const to = (Array.isArray(config.to) ? config.to : [config.to ?? 'owner'])
|
|
115
|
+
|
|
116
|
+
const otherPropertyNames = to.map(other => other.name ? other.name : other)
|
|
117
|
+
|
|
118
|
+
const otherPossibleTypes = to.map(other => {
|
|
119
|
+
const name = other.name ? other.name : other
|
|
120
|
+
const typesConfig = config[name + 'Types'] || []
|
|
121
|
+
const otherTypes = other.types || []
|
|
122
|
+
return Array.from(new Set(
|
|
123
|
+
typesConfig.concat(otherTypes).map(t => t.getTypeName ? t.getTypeName() : t)
|
|
124
|
+
))
|
|
125
|
+
})
|
|
116
126
|
|
|
117
127
|
const writeableProperties = modelProperties || config.writeableProperties
|
|
118
128
|
const others = otherPropertyNames.map(other => other.slice(0, 1).toUpperCase() + other.slice(1))
|
|
@@ -121,12 +131,15 @@ function processModelsAnyAnnotation(service, app, annotation, multiple, cb) {
|
|
|
121
131
|
const joinedOthersClassName = others.join('And')
|
|
122
132
|
const objectType = service.name + '_' + modelName
|
|
123
133
|
|
|
124
|
-
const
|
|
134
|
+
const parentsTypes = Array.from(new Set(
|
|
135
|
+
(config.parentsTypes || [])
|
|
136
|
+
.concat(otherPossibleTypes.filter(x => !!x).flat()
|
|
137
|
+
)))
|
|
125
138
|
|
|
126
139
|
const context = {
|
|
127
140
|
service, app, model, originalModelProperties, modelProperties, modelPropertyName, modelRuntime,
|
|
128
141
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others,
|
|
129
|
-
objectType, parentsTypes
|
|
142
|
+
objectType, parentsTypes, otherPossibleTypes
|
|
130
143
|
}
|
|
131
144
|
|
|
132
145
|
cb(config, context)
|