@live-change/relations-plugin 0.5.19 → 0.5.22
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 +45 -0
- package/boundToAny.js +46 -0
- package/index.js +15 -6
- package/itemOf.js +9 -157
- package/itemOfAny.js +9 -165
- package/package.json +7 -6
- package/pluralRelationAnyUtils.js +163 -0
- package/pluralRelationUtils.js +158 -0
- package/propertyOf.js +7 -132
- package/propertyOfAny.js +7 -139
- package/relatedTo.js +51 -0
- package/relatedToAny.js +51 -0
- package/singularRelationAnyUtils.js +136 -0
- package/singularRelationUtils.js +129 -0
- package/utils.js +31 -19
- package/utilsAny.js +29 -17
package/boundTo.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const {
|
|
2
|
+
defineProperties, defineIndex,
|
|
3
|
+
processModelsAnnotation, generateId
|
|
4
|
+
} = require('./utils.js')
|
|
5
|
+
|
|
6
|
+
const { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent } = require('./propertyEvents.js')
|
|
7
|
+
|
|
8
|
+
const { defineView, defineSetAction, defineUpdateAction, defineResetAction } = require('./singularRelationUtils.js')
|
|
9
|
+
|
|
10
|
+
module.exports = function(service, app) {
|
|
11
|
+
processModelsAnnotation(service, app, 'boundTo', false, (config, context) => {
|
|
12
|
+
|
|
13
|
+
context.relationWord = 'Friend'
|
|
14
|
+
context.reverseRelationWord = 'Bound'
|
|
15
|
+
|
|
16
|
+
defineProperties(context.model, context.others, context.otherPropertyNames)
|
|
17
|
+
defineIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
|
|
18
|
+
|
|
19
|
+
if(config.readAccess) {
|
|
20
|
+
defineView({ ...config, access: config.readAccess }, context)
|
|
21
|
+
}
|
|
22
|
+
if(config.views) {
|
|
23
|
+
for(const view of config.views) {
|
|
24
|
+
defineView({ ...config, ...view }, context)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
defineSetEvent(config, context, generateId)
|
|
29
|
+
defineUpdatedEvent(config, context, generateId)
|
|
30
|
+
defineTransferredEvent(config, context, generateId)
|
|
31
|
+
defineResetEvent(config, context, generateId)
|
|
32
|
+
|
|
33
|
+
if(config.setAccess || config.writeAccess) {
|
|
34
|
+
defineSetAction(config, context)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if(config.updateAccess || config.writeAccess) {
|
|
38
|
+
defineUpdateAction(config, context)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if(config.resetAccess || config.writeAccess) {
|
|
42
|
+
defineResetAction(config, context);
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
}
|
package/boundToAny.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const {
|
|
2
|
+
defineAnyProperties, defineAnyIndex,
|
|
3
|
+
processModelsAnyAnnotation, generateAnyId
|
|
4
|
+
} = require('./utilsAny.js')
|
|
5
|
+
|
|
6
|
+
const { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent } = require('./propertyEvents.js')
|
|
7
|
+
|
|
8
|
+
const { defineView, defineSetAction, defineUpdateAction, defineResetAction } = require('./singularRelationUtils.js')
|
|
9
|
+
|
|
10
|
+
module.exports = function(service, app) {
|
|
11
|
+
processModelsAnyAnnotation(service, app, 'boundToAny', false, (config, context) => {
|
|
12
|
+
|
|
13
|
+
context.relationWord = 'Friend'
|
|
14
|
+
context.reverseRelationWord = 'Bound'
|
|
15
|
+
|
|
16
|
+
defineAnyProperties(context.model, context.otherPropertyNames)
|
|
17
|
+
defineAnyIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
|
|
18
|
+
|
|
19
|
+
if(config.readAccess) {
|
|
20
|
+
defineView({ ...config, access: config.readAccess }, context)
|
|
21
|
+
}
|
|
22
|
+
if(config.views) {
|
|
23
|
+
for(const view of config.views) {
|
|
24
|
+
defineView({ ...config, ...view }, context)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
defineSetEvent(config, context, generateAnyId)
|
|
29
|
+
defineUpdatedEvent(config, context, generateAnyId)
|
|
30
|
+
defineTransferredEvent(config, context, generateAnyId)
|
|
31
|
+
defineResetEvent(config, context, generateAnyId)
|
|
32
|
+
|
|
33
|
+
if(config.setAccess || config.writeAccess) {
|
|
34
|
+
defineSetAction(config, context)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if(config.updateAccess || config.writeAccess) {
|
|
38
|
+
defineUpdateAction(config, context)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if(config.resetAccess || config.writeAccess) {
|
|
42
|
+
defineResetAction(config, context);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
})
|
|
46
|
+
}
|
package/index.js
CHANGED
|
@@ -4,14 +4,23 @@ const itemOf = require('./itemOf.js')
|
|
|
4
4
|
const propertyOfAny = require('./propertyOfAny.js')
|
|
5
5
|
const itemOfAny = require('./itemOfAny.js')
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const relatedTo = require('./relatedTo.js')
|
|
8
|
+
const relatedToAny = require('./relatedToAny.js')
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
const boundTo = require('./boundTo.js')
|
|
11
|
+
const boundToAny = require('./boundToAny.js')
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
const processors = [
|
|
14
|
+
propertyOf, itemOf,
|
|
15
|
+
propertyOfAny, itemOfAny,
|
|
16
|
+
relatedTo, relatedToAny,
|
|
17
|
+
boundTo, boundToAny
|
|
18
|
+
]
|
|
14
19
|
|
|
20
|
+
module.exports = function(app, services) {
|
|
21
|
+
app.defaultProcessors.push(...processors)
|
|
15
22
|
}
|
|
16
23
|
|
|
17
|
-
module.exports.processors = [
|
|
24
|
+
module.exports.processors = [
|
|
25
|
+
...processors
|
|
26
|
+
]
|
package/itemOf.js
CHANGED
|
@@ -1,169 +1,21 @@
|
|
|
1
|
-
const App = require("@live-change/framework")
|
|
2
|
-
const { PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition } = App
|
|
3
|
-
|
|
4
1
|
const {
|
|
5
|
-
|
|
2
|
+
defineProperties, defineIndex,
|
|
6
3
|
processModelsAnnotation
|
|
7
4
|
} = require('./utils.js')
|
|
8
5
|
|
|
9
|
-
function defineView(config, context) {
|
|
10
|
-
const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
|
|
11
|
-
modelName, others, model } = context
|
|
12
|
-
const indexName = 'by'+context.joinedOthersClassName
|
|
13
|
-
const viewProperties = {}
|
|
14
|
-
for (let i = 0; i < others.length; i++) {
|
|
15
|
-
viewProperties[otherPropertyNames[i]] = new PropertyDefinition({
|
|
16
|
-
type: others[i],
|
|
17
|
-
validation: ['nonEmpty']
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
const viewName = joinedOthersPropertyName + 'Owned' + modelName + 's'
|
|
21
|
-
service.views[viewName] = new ViewDefinition({
|
|
22
|
-
name: viewName,
|
|
23
|
-
properties: {
|
|
24
|
-
...viewProperties,
|
|
25
|
-
...App.utils.rangeProperties
|
|
26
|
-
},
|
|
27
|
-
returns: {
|
|
28
|
-
type: Array,
|
|
29
|
-
of: {
|
|
30
|
-
type: model
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
access: config.readAccess,
|
|
34
|
-
daoPath(properties, { client, context }) {
|
|
35
|
-
const idParts = extractIdParts(otherPropertyNames, properties)
|
|
36
|
-
const range = extractRange(properties)
|
|
37
|
-
const path = modelRuntime().sortedIndexRangePath(indexName, idParts, range)
|
|
38
|
-
return path
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
|
|
43
6
|
const {
|
|
44
7
|
defineCreatedEvent, defineUpdatedEvent, defineDeletedEvent, defineTransferredEvent,
|
|
45
8
|
} = require('./itemEvents.js')
|
|
46
|
-
const {defineTransferEvent} = require("./itemEvents");
|
|
47
9
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
52
|
-
} = context
|
|
53
|
-
const eventName = joinedOthersPropertyName + 'Owned' + modelName + 'Created'
|
|
54
|
-
const actionName = 'set' + joinedOthersClassName + 'Owned' + modelName
|
|
55
|
-
service.actions[actionName] = new ActionDefinition({
|
|
56
|
-
name: actionName,
|
|
57
|
-
properties: {
|
|
58
|
-
...(model.properties)
|
|
59
|
-
},
|
|
60
|
-
access: config.createAccess || config.writeAccess,
|
|
61
|
-
skipValidation: true,
|
|
62
|
-
//queuedBy: otherPropertyNames,
|
|
63
|
-
waitForEvents: true,
|
|
64
|
-
async execute(properties, { client, service }, emit) {
|
|
65
|
-
const id = properties[modelPropertyName] || app.generateUid()
|
|
66
|
-
const entity = await modelRuntime().get(id)
|
|
67
|
-
if(entity) throw 'exists'
|
|
68
|
-
const identifiers = extractIdentifiers(otherPropertyNames, properties)
|
|
69
|
-
const data = extractObjectData(writeableProperties, properties, defaults)
|
|
70
|
-
await App.validation.validate(data, validators, { source: action, action, service, app, client })
|
|
71
|
-
emit({
|
|
72
|
-
type: eventName,
|
|
73
|
-
[modelPropertyName]: id,
|
|
74
|
-
identifiers, data
|
|
75
|
-
})
|
|
76
|
-
}
|
|
77
|
-
})
|
|
78
|
-
const action = service.actions[actionName]
|
|
79
|
-
const validators = App.validation.getValidators(action, service, action)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
function defineUpdateAction(config, context) {
|
|
83
|
-
const {
|
|
84
|
-
service, app, model, modelRuntime, modelPropertyName,
|
|
85
|
-
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
86
|
-
} = context
|
|
87
|
-
const eventName = joinedOthersPropertyName + 'Owned' + modelName + 'Updated'
|
|
88
|
-
const actionName = 'update' + joinedOthersClassName + 'Owned' + modelName
|
|
89
|
-
service.actions[actionName] = new ActionDefinition({
|
|
90
|
-
name: actionName,
|
|
91
|
-
properties: {
|
|
92
|
-
...(model.properties)
|
|
93
|
-
},
|
|
94
|
-
access: config.updateAccess || config.writeAccess,
|
|
95
|
-
skipValidation: true,
|
|
96
|
-
//queuedBy: otherPropertyNames,
|
|
97
|
-
waitForEvents: true,
|
|
98
|
-
async execute(properties, {client, service}, emit) {
|
|
99
|
-
const id = properties[modelPropertyName]
|
|
100
|
-
const entity = await modelRuntime().get(id)
|
|
101
|
-
if(!entity) throw 'not_found'
|
|
102
|
-
const entityIdParts = extractIdParts(otherPropertyNames, entity)
|
|
103
|
-
const idParts = extractIdParts(otherPropertyNames, properties)
|
|
104
|
-
if(JSON.stringify(entityIdParts) != JSON.stringify(idParts)) {
|
|
105
|
-
throw 'not_authorized'
|
|
106
|
-
}
|
|
107
|
-
const identifiers = extractIdentifiers(otherPropertyNames, properties)
|
|
108
|
-
const data = extractObjectData(writeableProperties, properties, entity)
|
|
109
|
-
await App.validation.validate(data, validators, { source: action, action, service, app, client })
|
|
110
|
-
emit({
|
|
111
|
-
type: eventName,
|
|
112
|
-
[modelPropertyName]: id,
|
|
113
|
-
identifiers,
|
|
114
|
-
data
|
|
115
|
-
})
|
|
116
|
-
}
|
|
117
|
-
})
|
|
118
|
-
const action = service.actions[actionName]
|
|
119
|
-
const validators = App.validation.getValidators(action, service, action)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function defineDeleteAction(config, context) {
|
|
123
|
-
const {
|
|
124
|
-
service, app, model, modelRuntime, modelPropertyName,
|
|
125
|
-
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
126
|
-
} = context
|
|
127
|
-
const eventName = joinedOthersPropertyName + 'Owned' + modelName + 'Deleted'
|
|
128
|
-
const actionName = 'delete' + joinedOthersClassName + 'Owned' + modelName
|
|
129
|
-
service.actions[actionName] = new ActionDefinition({
|
|
130
|
-
name: actionName,
|
|
131
|
-
properties: {
|
|
132
|
-
...(model.properties)
|
|
133
|
-
},
|
|
134
|
-
access: config.deleteAccess || config.writeAccess,
|
|
135
|
-
skipValidation: true,
|
|
136
|
-
//queuedBy: otherPropertyNames,
|
|
137
|
-
waitForEvents: true,
|
|
138
|
-
async execute(properties, {client, service}, emit) {
|
|
139
|
-
const id = properties[modelPropertyName]
|
|
140
|
-
const entity = await modelRuntime().get(id)
|
|
141
|
-
if(!entity) throw new Error('not_found')
|
|
142
|
-
const entityIdParts = extractIdParts(otherPropertyNames, entity)
|
|
143
|
-
const idParts = extractIdParts(otherPropertyNames, properties)
|
|
144
|
-
if(JSON.stringify(entityIdParts) != JSON.stringify(idParts)) {
|
|
145
|
-
throw new Error('not_authorized')
|
|
146
|
-
}
|
|
147
|
-
emit({
|
|
148
|
-
type: eventName,
|
|
149
|
-
[modelPropertyName]: id
|
|
150
|
-
})
|
|
151
|
-
}
|
|
152
|
-
})
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function defineSortIndex(context, sortFields) {
|
|
156
|
-
if(!Array.isArray(sortFields)) sortFields = [sortFields]
|
|
157
|
-
console.log("DEFINE SORT INDEX", sortFields)
|
|
158
|
-
const sortFieldsUc = sortFields.map(fd=>fd.slice(0, 1).toUpperCase() + fd.slice(1))
|
|
159
|
-
const indexName = 'by' + context.joinedOthersClassName + sortFieldsUc.join('')
|
|
160
|
-
context.model.indexes[indexName] = new IndexDefinition({
|
|
161
|
-
property: [...context.otherPropertyNames, ...sortFields]
|
|
162
|
-
})
|
|
163
|
-
}
|
|
10
|
+
const {
|
|
11
|
+
defineView, defineCreateAction, defineUpdateAction, defineDeleteAction, defineSortIndex
|
|
12
|
+
} = require('./pluralRelationUtils.js')
|
|
164
13
|
|
|
165
14
|
module.exports = function(service, app) {
|
|
166
|
-
processModelsAnnotation(service, app, 'itemOf', (config, context) => {
|
|
15
|
+
processModelsAnnotation(service, app, 'itemOf', false, (config, context) => {
|
|
16
|
+
|
|
17
|
+
context.relationWord = 'Item'
|
|
18
|
+
context.reverseRelationWord = 'Owned'
|
|
167
19
|
|
|
168
20
|
defineProperties(context.model, context.others, context.otherPropertyNames)
|
|
169
21
|
defineIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
|
|
@@ -184,7 +36,7 @@ module.exports = function(service, app) {
|
|
|
184
36
|
defineTransferredEvent(config, context)
|
|
185
37
|
defineDeletedEvent(config, context)
|
|
186
38
|
|
|
187
|
-
if(config.
|
|
39
|
+
if(config.createAccess || config.writeAccess) {
|
|
188
40
|
defineCreateAction(config, context)
|
|
189
41
|
}
|
|
190
42
|
|
package/itemOfAny.js
CHANGED
|
@@ -1,177 +1,21 @@
|
|
|
1
|
-
const App = require("@live-change/framework")
|
|
2
|
-
const { PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition } = App
|
|
3
|
-
|
|
4
|
-
const {
|
|
5
|
-
extractRange, extractObjectData
|
|
6
|
-
} = require('./utils.js')
|
|
7
|
-
|
|
8
1
|
const {
|
|
9
|
-
|
|
2
|
+
defineAnyProperties, defineAnyIndex,
|
|
10
3
|
processModelsAnyAnnotation
|
|
11
4
|
} = require('./utilsAny.js')
|
|
12
5
|
|
|
13
|
-
function defineView(config, context) {
|
|
14
|
-
const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
|
|
15
|
-
modelName, others, model } = context
|
|
16
|
-
const indexName = 'by'+context.joinedOthersClassName
|
|
17
|
-
const viewProperties = {}
|
|
18
|
-
for (let i = 0; i < others.length; i++) {
|
|
19
|
-
viewProperties[otherPropertyNames[i]] = new PropertyDefinition({
|
|
20
|
-
type: 'String',
|
|
21
|
-
validation: ['nonEmpty']
|
|
22
|
-
})
|
|
23
|
-
viewProperties[otherPropertyNames[i] + 'Type'] = new PropertyDefinition({
|
|
24
|
-
type: 'String',
|
|
25
|
-
validation: ['nonEmpty']
|
|
26
|
-
})
|
|
27
|
-
}
|
|
28
|
-
const viewName = joinedOthersPropertyName + 'Owned' + modelName + 's'
|
|
29
|
-
service.views[viewName] = new ViewDefinition({
|
|
30
|
-
name: viewName,
|
|
31
|
-
properties: {
|
|
32
|
-
...viewProperties,
|
|
33
|
-
...App.utils.rangeProperties
|
|
34
|
-
},
|
|
35
|
-
returns: {
|
|
36
|
-
type: Array,
|
|
37
|
-
of: {
|
|
38
|
-
type: model
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
access: config.readAccess,
|
|
42
|
-
daoPath(properties, { client, context }) {
|
|
43
|
-
const typeAndIdParts = extractTypeAndIdParts(otherPropertyNames, properties)
|
|
44
|
-
const range = extractRange(properties)
|
|
45
|
-
const path = modelRuntime().sortedIndexRangePath(indexName, typeAndIdParts, range)
|
|
46
|
-
return path
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
}
|
|
50
|
-
|
|
51
6
|
const {
|
|
52
7
|
defineCreatedEvent, defineUpdatedEvent, defineDeletedEvent, defineTransferredEvent,
|
|
53
8
|
} = require('./itemEvents.js')
|
|
54
|
-
const {defineTransferEvent} = require("./itemEvents");
|
|
55
9
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
60
|
-
} = context
|
|
61
|
-
const eventName = joinedOthersPropertyName + 'Owned' + modelName + 'Created'
|
|
62
|
-
const actionName = 'set' + joinedOthersClassName + 'Owned' + modelName
|
|
63
|
-
service.actions[actionName] = new ActionDefinition({
|
|
64
|
-
name: actionName,
|
|
65
|
-
properties: {
|
|
66
|
-
...(model.properties)
|
|
67
|
-
},
|
|
68
|
-
access: config.createAccess || config.writeAccess,
|
|
69
|
-
skipValidation: true,
|
|
70
|
-
//queuedBy: otherPropertyNames,
|
|
71
|
-
waitForEvents: true,
|
|
72
|
-
async execute(properties, { client, service }, emit) {
|
|
73
|
-
const id = properties[modelPropertyName] || app.generateUid()
|
|
74
|
-
const entity = await modelRuntime().get(id)
|
|
75
|
-
if(entity) throw 'exists'
|
|
76
|
-
const identifiers = extractIdentifiersWithTypes(otherPropertyNames, properties)
|
|
77
|
-
const data = extractObjectData(writeableProperties, properties, defaults)
|
|
78
|
-
await App.validation.validate(data, validators, { source: action, action, service, app, client })
|
|
79
|
-
emit({
|
|
80
|
-
type: eventName,
|
|
81
|
-
[modelPropertyName]: id,
|
|
82
|
-
identifiers, data
|
|
83
|
-
})
|
|
84
|
-
}
|
|
85
|
-
})
|
|
86
|
-
const action = service.actions[actionName]
|
|
87
|
-
const validators = App.validation.getValidators(action, service, action)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function defineUpdateAction(config, context) {
|
|
91
|
-
const {
|
|
92
|
-
service, app, model, modelRuntime, modelPropertyName,
|
|
93
|
-
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
94
|
-
} = context
|
|
95
|
-
const eventName = joinedOthersPropertyName + 'Owned' + modelName + 'Updated'
|
|
96
|
-
const actionName = 'update' + joinedOthersClassName + 'Owned' + modelName
|
|
97
|
-
service.actions[actionName] = new ActionDefinition({
|
|
98
|
-
name: actionName,
|
|
99
|
-
properties: {
|
|
100
|
-
...(model.properties)
|
|
101
|
-
},
|
|
102
|
-
access: config.updateAccess || config.writeAccess,
|
|
103
|
-
skipValidation: true,
|
|
104
|
-
//queuedBy: otherPropertyNames,
|
|
105
|
-
waitForEvents: true,
|
|
106
|
-
async execute(properties, { client, service }, emit) {
|
|
107
|
-
const id = properties[modelPropertyName]
|
|
108
|
-
const entity = await modelRuntime().get(id)
|
|
109
|
-
if(!entity) throw 'not_found'
|
|
110
|
-
const entityTypeAndIdParts = extractTypeAndIdParts(otherPropertyNames, entity)
|
|
111
|
-
const typeAndIdParts = extractTypeAndIdParts(otherPropertyNames, properties)
|
|
112
|
-
if(JSON.stringify(entityTypeAndIdParts) != JSON.stringify(typeAndIdParts)) {
|
|
113
|
-
throw 'not_authorized'
|
|
114
|
-
}
|
|
115
|
-
const identifiers = extractIdentifiersWithTypes(otherPropertyNames, properties)
|
|
116
|
-
const data = extractObjectData(writeableProperties, properties, entity)
|
|
117
|
-
await App.validation.validate(data, validators, { source: action, action, service, app, client })
|
|
118
|
-
emit({
|
|
119
|
-
type: eventName,
|
|
120
|
-
[modelPropertyName]: id,
|
|
121
|
-
identifiers,
|
|
122
|
-
data
|
|
123
|
-
})
|
|
124
|
-
}
|
|
125
|
-
})
|
|
126
|
-
const action = service.actions[actionName]
|
|
127
|
-
const validators = App.validation.getValidators(action, service, action)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function defineDeleteAction(config, context) {
|
|
131
|
-
const {
|
|
132
|
-
service, app, model, modelRuntime, modelPropertyName,
|
|
133
|
-
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
134
|
-
} = context
|
|
135
|
-
const eventName = joinedOthersPropertyName + 'Owned' + modelName + 'Deleted'
|
|
136
|
-
const actionName = 'delete' + joinedOthersClassName + 'Owned' + modelName
|
|
137
|
-
service.actions[actionName] = new ActionDefinition({
|
|
138
|
-
name: actionName,
|
|
139
|
-
properties: {
|
|
140
|
-
...(model.properties)
|
|
141
|
-
},
|
|
142
|
-
access: config.deleteAccess || config.writeAccess,
|
|
143
|
-
skipValidation: true,
|
|
144
|
-
//queuedBy: otherPropertyNames,
|
|
145
|
-
waitForEvents: true,
|
|
146
|
-
async execute(properties, { client, service }, emit) {
|
|
147
|
-
const id = properties[modelPropertyName]
|
|
148
|
-
const entity = await modelRuntime().get(id)
|
|
149
|
-
if(!entity) throw new Error('not_found')
|
|
150
|
-
const entityTypeAndIdParts = extractTypeAndIdParts(otherPropertyNames, entity)
|
|
151
|
-
const typeAndIdParts = extractTypeAndIdParts(otherPropertyNames, properties)
|
|
152
|
-
if(JSON.stringify(entityTypeAndIdParts) != JSON.stringify(typeAndIdParts)) {
|
|
153
|
-
throw new Error('not_authorized')
|
|
154
|
-
}
|
|
155
|
-
emit({
|
|
156
|
-
type: eventName,
|
|
157
|
-
[modelPropertyName]: id
|
|
158
|
-
})
|
|
159
|
-
}
|
|
160
|
-
})
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function defineSortIndex(context, sortFields) {
|
|
164
|
-
if(!Array.isArray(sortFields)) sortFields = [sortFields]
|
|
165
|
-
console.log("DEFINE SORT INDEX", sortFields)
|
|
166
|
-
const sortFieldsUc = sortFields.map(fd => fd.slice(0, 1).toUpperCase() + fd.slice(1))
|
|
167
|
-
const indexName = 'by' + context.joinedOthersClassName + sortFieldsUc.join('')
|
|
168
|
-
context.model.indexes[indexName] = new IndexDefinition({
|
|
169
|
-
property: [...(context.otherPropertyNames.map(prop => [prop + 'Type', prop])), ...sortFields]
|
|
170
|
-
})
|
|
171
|
-
}
|
|
10
|
+
const {
|
|
11
|
+
defineView, defineCreateAction, defineUpdateAction, defineDeleteAction, defineSortIndex
|
|
12
|
+
} = require('./pluralRelationUtils.js')
|
|
172
13
|
|
|
173
14
|
module.exports = function(service, app) {
|
|
174
|
-
processModelsAnyAnnotation(service, app, 'itemOfAny', (config, context) => {
|
|
15
|
+
processModelsAnyAnnotation(service, app, 'itemOfAny',false, (config, context) => {
|
|
16
|
+
|
|
17
|
+
context.relationWord = 'Item'
|
|
18
|
+
context.reverseRelationWord = 'Owned'
|
|
175
19
|
|
|
176
20
|
defineAnyProperties(context.model, context.otherPropertyNames)
|
|
177
21
|
defineAnyIndex(context.model, context.joinedOthersClassName, context.otherPropertyNames)
|
|
@@ -192,7 +36,7 @@ module.exports = function(service, app) {
|
|
|
192
36
|
defineTransferredEvent(config, context)
|
|
193
37
|
defineDeletedEvent(config, context)
|
|
194
38
|
|
|
195
|
-
if(config.
|
|
39
|
+
if(config.createAccess || config.writeAccess) {
|
|
196
40
|
defineCreateAction(config, context)
|
|
197
41
|
}
|
|
198
42
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/relations-plugin",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.22",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,20 +8,21 @@
|
|
|
8
8
|
},
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/live-change/
|
|
11
|
+
"url": "git+https://github.com/live-change/live-change-framework.git"
|
|
12
12
|
},
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"bugs": {
|
|
15
|
-
"url": "https://github.com/live-change/
|
|
15
|
+
"url": "https://github.com/live-change/live-change-framework/issues"
|
|
16
16
|
},
|
|
17
|
-
"homepage": "https://github.com/live-change/
|
|
17
|
+
"homepage": "https://github.com/live-change/live-change-framework",
|
|
18
18
|
"author": {
|
|
19
19
|
"email": "michal@laszczewski.pl",
|
|
20
20
|
"name": "Michał Łaszczewski",
|
|
21
21
|
"url": "https://www.viamage.com/"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@live-change/framework": "^0.5.
|
|
24
|
+
"@live-change/framework": "^0.5.21",
|
|
25
|
+
"pluralize": "8.0.0"
|
|
25
26
|
},
|
|
26
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "1f71e9b116b669699994424c4cf38dd17b5109a8"
|
|
27
28
|
}
|