@live-change/relations-plugin 0.5.24 → 0.5.27
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/itemEvents.js +8 -8
- package/package.json +3 -3
- package/pluralRelationAnyUtils.js +8 -4
- package/pluralRelationUtils.js +6 -4
- package/propertyEvents.js +12 -10
- package/propertyOf.js +7 -1
- package/propertyOfAny.js +5 -1
- package/singularRelationAnyUtils.js +40 -5
- package/singularRelationUtils.js +41 -6
- package/utils.js +3 -3
package/itemEvents.js
CHANGED
|
@@ -3,9 +3,9 @@ const { PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, E
|
|
|
3
3
|
|
|
4
4
|
function defineCreatedEvent(config, context) {
|
|
5
5
|
const {
|
|
6
|
-
service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName
|
|
6
|
+
service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName, reverseRelationWord
|
|
7
7
|
} = context
|
|
8
|
-
const eventName = joinedOthersPropertyName +
|
|
8
|
+
const eventName = joinedOthersPropertyName + reverseRelationWord + modelName + 'Created'
|
|
9
9
|
service.events[eventName] = new EventDefinition({
|
|
10
10
|
name: eventName,
|
|
11
11
|
execute(properties) {
|
|
@@ -17,9 +17,9 @@ function defineCreatedEvent(config, context) {
|
|
|
17
17
|
|
|
18
18
|
function defineUpdatedEvent(config, context) {
|
|
19
19
|
const {
|
|
20
|
-
service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName
|
|
20
|
+
service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName, reverseRelationWord
|
|
21
21
|
} = context
|
|
22
|
-
const eventName = joinedOthersPropertyName +
|
|
22
|
+
const eventName = joinedOthersPropertyName + reverseRelationWord + modelName + 'Updated'
|
|
23
23
|
service.events[eventName] = new EventDefinition({
|
|
24
24
|
name: eventName,
|
|
25
25
|
execute(properties) {
|
|
@@ -31,9 +31,9 @@ function defineUpdatedEvent(config, context) {
|
|
|
31
31
|
|
|
32
32
|
function defineTransferredEvent(config, context) {
|
|
33
33
|
const {
|
|
34
|
-
service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName
|
|
34
|
+
service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName, reverseRelationWord
|
|
35
35
|
} = context
|
|
36
|
-
const eventName = joinedOthersPropertyName +
|
|
36
|
+
const eventName = joinedOthersPropertyName + reverseRelationWord + modelName + 'Transferred'
|
|
37
37
|
service.events[eventName] = new EventDefinition({
|
|
38
38
|
name: eventName,
|
|
39
39
|
execute(properties) {
|
|
@@ -45,9 +45,9 @@ function defineTransferredEvent(config, context) {
|
|
|
45
45
|
|
|
46
46
|
function defineDeletedEvent(config, context) {
|
|
47
47
|
const {
|
|
48
|
-
service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName
|
|
48
|
+
service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName, reverseRelationWord
|
|
49
49
|
} = context
|
|
50
|
-
const eventName = joinedOthersPropertyName +
|
|
50
|
+
const eventName = joinedOthersPropertyName + reverseRelationWord + modelName + 'Deleted'
|
|
51
51
|
service.events[eventName] = new EventDefinition({
|
|
52
52
|
name: eventName,
|
|
53
53
|
execute(properties) {
|
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.27",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"url": "https://www.viamage.com/"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@live-change/framework": "^0.5.
|
|
24
|
+
"@live-change/framework": "^0.5.27",
|
|
25
25
|
"pluralize": "8.0.0"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "8cdab8d362794c923e765193d2e786fb29587877"
|
|
28
28
|
}
|
|
@@ -65,7 +65,8 @@ function defineCreateAction(config, context) {
|
|
|
65
65
|
if(entity) throw 'exists'
|
|
66
66
|
const identifiers = extractIdentifiersWithTypes(otherPropertyNames, properties)
|
|
67
67
|
const data = extractObjectData(writeableProperties, properties, defaults)
|
|
68
|
-
await App.validation.validate(
|
|
68
|
+
await App.validation.validate({ ...identifiers, ...data }, validators,
|
|
69
|
+
{ source: action, action, service, app, client })
|
|
69
70
|
emit({
|
|
70
71
|
type: eventName,
|
|
71
72
|
[modelPropertyName]: id,
|
|
@@ -95,6 +96,7 @@ function defineUpdateAction(config, context) {
|
|
|
95
96
|
waitForEvents: true,
|
|
96
97
|
async execute(properties, { client, service }, emit) {
|
|
97
98
|
const id = properties[modelPropertyName]
|
|
99
|
+
if(!id) throw 'no_id'
|
|
98
100
|
const entity = await modelRuntime().get(id)
|
|
99
101
|
if(!entity) throw 'not_found'
|
|
100
102
|
const entityTypeAndIdParts = extractTypeAndIdParts(otherPropertyNames, entity)
|
|
@@ -104,7 +106,8 @@ function defineUpdateAction(config, context) {
|
|
|
104
106
|
}
|
|
105
107
|
const identifiers = extractIdentifiersWithTypes(otherPropertyNames, properties)
|
|
106
108
|
const data = extractObjectData(writeableProperties, properties, entity)
|
|
107
|
-
await App.validation.validate(
|
|
109
|
+
await App.validation.validate({ ...identifiers, ...data }, validators,
|
|
110
|
+
{ source: action, action, service, app, client })
|
|
108
111
|
emit({
|
|
109
112
|
type: eventName,
|
|
110
113
|
[modelPropertyName]: id,
|
|
@@ -152,11 +155,12 @@ function defineDeleteAction(config, context) {
|
|
|
152
155
|
|
|
153
156
|
function defineSortIndex(context, sortFields) {
|
|
154
157
|
if(!Array.isArray(sortFields)) sortFields = [sortFields]
|
|
155
|
-
console.log("DEFINE SORT INDEX", sortFields)
|
|
156
158
|
const sortFieldsUc = sortFields.map(fd => fd.slice(0, 1).toUpperCase() + fd.slice(1))
|
|
157
159
|
const indexName = 'by' + context.joinedOthersClassName + sortFieldsUc.join('')
|
|
160
|
+
const property = [...(context.otherPropertyNames.map(prop => [prop + 'Type', prop]).flat()), ...sortFields]
|
|
161
|
+
console.log("DEFINE SORT INDEX", sortFields, "NAME", indexName, "PROP", property)
|
|
158
162
|
context.model.indexes[indexName] = new IndexDefinition({
|
|
159
|
-
property
|
|
163
|
+
property
|
|
160
164
|
})
|
|
161
165
|
}
|
|
162
166
|
|
package/pluralRelationUtils.js
CHANGED
|
@@ -60,7 +60,8 @@ function defineCreateAction(config, context) {
|
|
|
60
60
|
if(entity) throw 'exists'
|
|
61
61
|
const identifiers = extractIdentifiers(otherPropertyNames, properties)
|
|
62
62
|
const data = extractObjectData(writeableProperties, properties, defaults)
|
|
63
|
-
await App.validation.validate(
|
|
63
|
+
await App.validation.validate({ ...identifiers, ...data }, validators,
|
|
64
|
+
{ source: action, action, service, app, client })
|
|
64
65
|
emit({
|
|
65
66
|
type: eventName,
|
|
66
67
|
[modelPropertyName]: id,
|
|
@@ -88,7 +89,7 @@ function defineUpdateAction(config, context) {
|
|
|
88
89
|
skipValidation: true,
|
|
89
90
|
//queuedBy: otherPropertyNames,
|
|
90
91
|
waitForEvents: true,
|
|
91
|
-
async execute(properties, {client, service}, emit) {
|
|
92
|
+
async execute(properties, { client, service }, emit) {
|
|
92
93
|
const id = properties[modelPropertyName]
|
|
93
94
|
const entity = await modelRuntime().get(id)
|
|
94
95
|
if(!entity) throw 'not_found'
|
|
@@ -99,7 +100,8 @@ function defineUpdateAction(config, context) {
|
|
|
99
100
|
}
|
|
100
101
|
const identifiers = extractIdentifiers(otherPropertyNames, properties)
|
|
101
102
|
const data = extractObjectData(writeableProperties, properties, entity)
|
|
102
|
-
await App.validation.validate(
|
|
103
|
+
await App.validation.validate({ ...identifiers, ...data }, validators,
|
|
104
|
+
{ source: action, action, service, app, client })
|
|
103
105
|
emit({
|
|
104
106
|
type: eventName,
|
|
105
107
|
[modelPropertyName]: id,
|
|
@@ -128,7 +130,7 @@ function defineDeleteAction(config, context) {
|
|
|
128
130
|
skipValidation: true,
|
|
129
131
|
//queuedBy: otherPropertyNames,
|
|
130
132
|
waitForEvents: true,
|
|
131
|
-
async execute(properties, {client, service}, emit) {
|
|
133
|
+
async execute(properties, { client, service }, emit) {
|
|
132
134
|
const id = properties[modelPropertyName]
|
|
133
135
|
const entity = await modelRuntime().get(id)
|
|
134
136
|
if(!entity) throw new Error('not_found')
|
package/propertyEvents.js
CHANGED
|
@@ -3,9 +3,9 @@ const { PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, E
|
|
|
3
3
|
|
|
4
4
|
function defineSetEvent(config, context, generateId) {
|
|
5
5
|
const {
|
|
6
|
-
service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames
|
|
6
|
+
service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames, reverseRelationWord
|
|
7
7
|
} = context
|
|
8
|
-
const eventName = joinedOthersPropertyName +
|
|
8
|
+
const eventName = joinedOthersPropertyName + reverseRelationWord + modelName + 'Set'
|
|
9
9
|
service.events[eventName] = new EventDefinition({
|
|
10
10
|
name: eventName,
|
|
11
11
|
execute(properties) {
|
|
@@ -17,23 +17,23 @@ function defineSetEvent(config, context, generateId) {
|
|
|
17
17
|
|
|
18
18
|
function defineUpdatedEvent(config, context, generateId) {
|
|
19
19
|
const {
|
|
20
|
-
service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames
|
|
20
|
+
service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames, reverseRelationWord
|
|
21
21
|
} = context
|
|
22
|
-
const eventName = joinedOthersPropertyName +
|
|
22
|
+
const eventName = joinedOthersPropertyName + reverseRelationWord + modelName + 'Updated'
|
|
23
23
|
service.events[eventName] = new EventDefinition({
|
|
24
24
|
name: eventName,
|
|
25
25
|
execute(properties) {
|
|
26
26
|
const id = generateId(otherPropertyNames, properties.identifiers)
|
|
27
|
-
return modelRuntime().update(id, { ...properties.data,
|
|
27
|
+
return modelRuntime().update(id, { ...properties.data, ...properties.identifiers })
|
|
28
28
|
}
|
|
29
29
|
})
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
function defineTransferredEvent(config, context, generateId) {
|
|
33
33
|
const {
|
|
34
|
-
service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames
|
|
34
|
+
service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames, reverseRelationWord
|
|
35
35
|
} = context
|
|
36
|
-
const eventName = joinedOthersPropertyName +
|
|
36
|
+
const eventName = joinedOthersPropertyName + reverseRelationWord + modelName + 'Transferred'
|
|
37
37
|
service.events[eventName] = new EventDefinition({
|
|
38
38
|
name: eventName,
|
|
39
39
|
async execute(properties) {
|
|
@@ -53,9 +53,9 @@ function defineTransferredEvent(config, context, generateId) {
|
|
|
53
53
|
|
|
54
54
|
function defineResetEvent(config, context, generateId) {
|
|
55
55
|
const {
|
|
56
|
-
service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames
|
|
56
|
+
service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames, reverseRelationWord
|
|
57
57
|
} = context
|
|
58
|
-
const eventName = joinedOthersPropertyName +
|
|
58
|
+
const eventName = joinedOthersPropertyName + reverseRelationWord + modelName + 'Reset'
|
|
59
59
|
service.events[eventName] = new EventDefinition({
|
|
60
60
|
name: eventName,
|
|
61
61
|
execute({ identifiers }) {
|
|
@@ -65,4 +65,6 @@ function defineResetEvent(config, context, generateId) {
|
|
|
65
65
|
})
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
module.exports = {
|
|
68
|
+
module.exports = {
|
|
69
|
+
defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent
|
|
70
|
+
}
|
package/propertyOf.js
CHANGED
|
@@ -5,7 +5,9 @@ const {
|
|
|
5
5
|
|
|
6
6
|
const { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent } = require('./propertyEvents.js')
|
|
7
7
|
|
|
8
|
-
const {
|
|
8
|
+
const {
|
|
9
|
+
defineView, defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction
|
|
10
|
+
} = require('./singularRelationUtils.js')
|
|
9
11
|
|
|
10
12
|
module.exports = function(service, app) {
|
|
11
13
|
processModelsAnnotation(service, app, 'propertyOf', false, (config, context) => {
|
|
@@ -38,6 +40,10 @@ module.exports = function(service, app) {
|
|
|
38
40
|
defineUpdateAction(config, context)
|
|
39
41
|
}
|
|
40
42
|
|
|
43
|
+
if((config.setAccess && config.updateAccess) || config.writeAccess) {
|
|
44
|
+
defineSetOrUpdateAction(config, context)
|
|
45
|
+
}
|
|
46
|
+
|
|
41
47
|
if(config.resetAccess || config.writeAccess) {
|
|
42
48
|
defineResetAction(config, context);
|
|
43
49
|
}
|
package/propertyOfAny.js
CHANGED
|
@@ -8,7 +8,7 @@ const {
|
|
|
8
8
|
} = require('./propertyEvents.js')
|
|
9
9
|
|
|
10
10
|
const {
|
|
11
|
-
defineView, defineSetAction, defineUpdateAction, defineResetAction
|
|
11
|
+
defineView, defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction
|
|
12
12
|
} = require('./singularRelationAnyUtils.js')
|
|
13
13
|
|
|
14
14
|
module.exports = function(service, app) {
|
|
@@ -42,6 +42,10 @@ module.exports = function(service, app) {
|
|
|
42
42
|
defineUpdateAction(config, context)
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
if((config.setAccess && config.updateAccess) || config.writeAccess) {
|
|
46
|
+
defineSetOrUpdateAction(config, context)
|
|
47
|
+
}
|
|
48
|
+
|
|
45
49
|
if(config.resetAccess || config.writeAccess) {
|
|
46
50
|
defineResetAction(config, context);
|
|
47
51
|
}
|
|
@@ -40,7 +40,7 @@ function defineView(config, context) {
|
|
|
40
40
|
|
|
41
41
|
function defineSetAction(config, context) {
|
|
42
42
|
const {
|
|
43
|
-
service, app, model,
|
|
43
|
+
service, app, model, defaults,
|
|
44
44
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
45
45
|
} = context
|
|
46
46
|
|
|
@@ -55,10 +55,11 @@ function defineSetAction(config, context) {
|
|
|
55
55
|
skipValidation: true,
|
|
56
56
|
queuedBy: otherPropertyNames,
|
|
57
57
|
waitForEvents: true,
|
|
58
|
-
async execute(properties, {client, service}, emit) {
|
|
58
|
+
async execute(properties, { client, service }, emit) {
|
|
59
59
|
const identifiers = extractIdentifiersWithTypes(otherPropertyNames, properties)
|
|
60
60
|
const data = extractObjectData(writeableProperties, properties, defaults)
|
|
61
|
-
await App.validation.validate(
|
|
61
|
+
await App.validation.validate({ ...identifiers, ...data }, validators,
|
|
62
|
+
{ source: action, action, service, app, client })
|
|
62
63
|
emit({
|
|
63
64
|
type: eventName,
|
|
64
65
|
identifiers, data
|
|
@@ -91,7 +92,41 @@ function defineUpdateAction(config, context) {
|
|
|
91
92
|
const entity = await modelRuntime().get(id)
|
|
92
93
|
if (!entity) throw new Error('not_found')
|
|
93
94
|
const data = extractObjectData(writeableProperties, properties, entity)
|
|
94
|
-
await App.validation.validate(
|
|
95
|
+
await App.validation.validate({ ...identifiers, ...data }, validators,
|
|
96
|
+
{ source: action, action, service, app, client })
|
|
97
|
+
emit({
|
|
98
|
+
type: eventName,
|
|
99
|
+
identifiers, data
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
const action = service.actions[actionName]
|
|
104
|
+
const validators = App.validation.getValidators(action, service, action)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function defineSetOrUpdateAction(config, context) {
|
|
108
|
+
const {
|
|
109
|
+
service, app, model, modelRuntime, defaults,
|
|
110
|
+
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
111
|
+
} = context
|
|
112
|
+
const eventName = joinedOthersPropertyName + context.reverseRelationWord + modelName + 'Updated'
|
|
113
|
+
const actionName = 'setOrUpdate' + joinedOthersClassName + context.reverseRelationWord + modelName
|
|
114
|
+
service.actions[actionName] = new ActionDefinition({
|
|
115
|
+
name: actionName,
|
|
116
|
+
properties: {
|
|
117
|
+
...(model.properties)
|
|
118
|
+
},
|
|
119
|
+
access: config.updateAccess || config.writeAccess,
|
|
120
|
+
skipValidation: true,
|
|
121
|
+
queuedBy: otherPropertyNames,
|
|
122
|
+
waitForEvents: true,
|
|
123
|
+
async execute(properties, { client, service }, emit) {
|
|
124
|
+
const identifiers = extractIdentifiersWithTypes(otherPropertyNames, properties)
|
|
125
|
+
const id = generateAnyId(otherPropertyNames, properties)
|
|
126
|
+
const entity = await modelRuntime().get(id)
|
|
127
|
+
const data = extractObjectData(writeableProperties, properties, { ...defaults, ...entity } )
|
|
128
|
+
await App.validation.validate({ ...identifiers, ...data }, validators,
|
|
129
|
+
{ source: action, action, service, app, client })
|
|
95
130
|
emit({
|
|
96
131
|
type: eventName,
|
|
97
132
|
identifiers, data
|
|
@@ -133,4 +168,4 @@ function defineResetAction(config, context) {
|
|
|
133
168
|
})
|
|
134
169
|
}
|
|
135
170
|
|
|
136
|
-
module.exports = { defineView, defineSetAction, defineUpdateAction, defineResetAction }
|
|
171
|
+
module.exports = { defineView, defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction }
|
package/singularRelationUtils.js
CHANGED
|
@@ -48,10 +48,11 @@ function defineSetAction(config, context) {
|
|
|
48
48
|
skipValidation: true,
|
|
49
49
|
queuedBy: otherPropertyNames,
|
|
50
50
|
waitForEvents: true,
|
|
51
|
-
async execute(properties, {client, service}, emit) {
|
|
51
|
+
async execute(properties, { client, service }, emit) {
|
|
52
52
|
const identifiers = extractIdentifiers(otherPropertyNames, properties)
|
|
53
53
|
const data = extractObjectData(writeableProperties, properties, defaults)
|
|
54
|
-
await App.validation.validate(
|
|
54
|
+
await App.validation.validate({ ...identifiers, ...data }, validators,
|
|
55
|
+
{ source: action, action, service, app, client })
|
|
55
56
|
emit({
|
|
56
57
|
type: eventName,
|
|
57
58
|
identifiers, data
|
|
@@ -78,13 +79,47 @@ function defineUpdateAction(config, context) {
|
|
|
78
79
|
skipValidation: true,
|
|
79
80
|
queuedBy: otherPropertyNames,
|
|
80
81
|
waitForEvents: true,
|
|
81
|
-
async execute(properties, {client, service}, emit) {
|
|
82
|
+
async execute(properties, { client, service }, emit) {
|
|
82
83
|
const identifiers = extractIdentifiers(otherPropertyNames, properties)
|
|
83
84
|
const id = generateId(otherPropertyNames, properties)
|
|
84
85
|
const entity = await modelRuntime().get(id)
|
|
85
86
|
if (!entity) throw new Error('not_found')
|
|
86
87
|
const data = extractObjectData(writeableProperties, properties, entity)
|
|
87
|
-
await App.validation.validate(
|
|
88
|
+
await App.validation.validate({ ...identifiers, ...data }, validators,
|
|
89
|
+
{ source: action, action, service, app, client })
|
|
90
|
+
emit({
|
|
91
|
+
type: eventName,
|
|
92
|
+
identifiers, data
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
const action = service.actions[actionName]
|
|
97
|
+
const validators = App.validation.getValidators(action, service, action)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function defineSetOrUpdateAction(config, context) {
|
|
101
|
+
const {
|
|
102
|
+
service, app, model, defaults, modelRuntime,
|
|
103
|
+
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
104
|
+
} = context
|
|
105
|
+
const eventName = joinedOthersPropertyName + 'Owned' + modelName + 'Updated'
|
|
106
|
+
const actionName = 'update' + joinedOthersClassName + 'Owned' + modelName
|
|
107
|
+
service.actions[actionName] = new ActionDefinition({
|
|
108
|
+
name: actionName,
|
|
109
|
+
properties: {
|
|
110
|
+
...(model.properties)
|
|
111
|
+
},
|
|
112
|
+
access: config.updateAccess || config.writeAccess,
|
|
113
|
+
skipValidation: true,
|
|
114
|
+
queuedBy: otherPropertyNames,
|
|
115
|
+
waitForEvents: true,
|
|
116
|
+
async execute(properties, { client, service }, emit) {
|
|
117
|
+
const identifiers = extractIdentifiers(otherPropertyNames, properties)
|
|
118
|
+
const id = generateId(otherPropertyNames, properties)
|
|
119
|
+
const entity = await modelRuntime().get(id)
|
|
120
|
+
const data = extractObjectData(writeableProperties, properties, { ...defaults, ...entity })
|
|
121
|
+
await App.validation.validate({ ...identifiers, ...data }, validators,
|
|
122
|
+
{ source: action, action, service, app, client })
|
|
88
123
|
emit({
|
|
89
124
|
type: eventName,
|
|
90
125
|
identifiers, data
|
|
@@ -113,7 +148,7 @@ function defineResetAction(config, context) {
|
|
|
113
148
|
access: config.resetAccess || config.writeAccess,
|
|
114
149
|
queuedBy: otherPropertyNames,
|
|
115
150
|
waitForEvents: true,
|
|
116
|
-
async execute(properties, {client, service}, emit) {
|
|
151
|
+
async execute(properties, { client, service }, emit) {
|
|
117
152
|
const identifiers = extractIdentifiers(otherPropertyNames, properties)
|
|
118
153
|
const id = generateId(otherPropertyNames, properties)
|
|
119
154
|
const entity = await modelRuntime().get(id)
|
|
@@ -126,4 +161,4 @@ function defineResetAction(config, context) {
|
|
|
126
161
|
})
|
|
127
162
|
}
|
|
128
163
|
|
|
129
|
-
module.exports = { defineView, defineSetAction, defineUpdateAction, defineResetAction }
|
|
164
|
+
module.exports = { defineView, defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction }
|
package/utils.js
CHANGED
|
@@ -35,13 +35,13 @@ function generateId(otherPropertyNames, properties) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
function extractObjectData(writeableProperties, properties, defaults) {
|
|
38
|
-
let
|
|
38
|
+
let objectData = {}
|
|
39
39
|
for (const propertyName of writeableProperties) {
|
|
40
40
|
if (properties.hasOwnProperty(propertyName)) {
|
|
41
|
-
|
|
41
|
+
objectData[propertyName] = properties[propertyName]
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
return App.utils.mergeDeep({}, defaults,
|
|
44
|
+
return App.utils.mergeDeep({}, defaults, JSON.parse(JSON.stringify(objectData)))
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
function defineProperties(model, types, names) {
|