@live-change/relations-plugin 0.8.24 → 0.8.26
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 +19 -5
- package/boundToAny.js +18 -5
- package/entity.js +164 -62
- package/itemOf.js +11 -4
- package/itemOfAny.js +11 -5
- package/package.json +3 -3
- package/pluralRelationAnyUtils.js +187 -70
- package/pluralRelationUtils.js +277 -114
- package/propertyOf.js +11 -5
- package/propertyOfAny.js +15 -8
- package/relatedTo.js +11 -4
- package/relatedToAny.js +11 -4
- package/singularRelationAnyUtils.js +208 -81
- package/singularRelationUtils.js +222 -77
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 defineView(config, context) {
|
|
9
|
+
function defineView(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,7 +18,7 @@ function defineView(config, context) {
|
|
|
18
18
|
})
|
|
19
19
|
}
|
|
20
20
|
const viewName = joinedOthersPropertyName + context.reverseRelationWord + pluralize(modelName)
|
|
21
|
-
const accessControl = config.readAccessControl || config.writeAccessControl
|
|
21
|
+
const accessControl = external && (config.readAccessControl || config.writeAccessControl)
|
|
22
22
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
23
23
|
service.views[viewName] = new ViewDefinition({
|
|
24
24
|
name: viewName,
|
|
@@ -32,7 +32,8 @@ function defineView(config, context) {
|
|
|
32
32
|
type: model
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
|
-
|
|
35
|
+
internal: !external,
|
|
36
|
+
access: external && (config.readAccess || config.writeAccess),
|
|
36
37
|
accessControl: config.readAccessControl || config.writeAccessControl,
|
|
37
38
|
daoPath(properties, { client, context }) {
|
|
38
39
|
const idParts = extractIdParts(otherPropertyNames, properties)
|
|
@@ -43,16 +44,40 @@ function defineView(config, context) {
|
|
|
43
44
|
})
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
function
|
|
47
|
+
function getCreateFunction( validators, validationContext, config, context) {
|
|
47
48
|
const {
|
|
48
49
|
service, app, model, modelPropertyName, modelRuntime, objectType,
|
|
49
50
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
50
51
|
} = context
|
|
51
52
|
const eventName = joinedOthersPropertyName + context.reverseRelationWord + modelName + 'Created'
|
|
53
|
+
return async function execute(properties, { client, service }, emit) {
|
|
54
|
+
const id = properties[modelPropertyName] || app.generateUid()
|
|
55
|
+
const entity = await modelRuntime().get(id)
|
|
56
|
+
if(entity) throw 'exists'
|
|
57
|
+
const identifiers = extractIdentifiers(otherPropertyNames, properties)
|
|
58
|
+
const data = extractObjectData(writeableProperties, properties,
|
|
59
|
+
App.computeDefaults(model, properties, { client, service } ))
|
|
60
|
+
await App.validation.validate({ ...identifiers, ...data }, validators,
|
|
61
|
+
validationContext)
|
|
62
|
+
await fireChangeTriggers(context, objectType, identifiers, id, null, data)
|
|
63
|
+
emit({
|
|
64
|
+
type: eventName,
|
|
65
|
+
[modelPropertyName]: id,
|
|
66
|
+
identifiers, data
|
|
67
|
+
})
|
|
68
|
+
return id
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function defineCreateAction(config, context) {
|
|
73
|
+
const {
|
|
74
|
+
service, app, model, modelPropertyName, modelRuntime, objectType,
|
|
75
|
+
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
76
|
+
} = context
|
|
52
77
|
const actionName = 'create' + joinedOthersClassName + context.reverseRelationWord + modelName
|
|
53
78
|
const accessControl = config.createAccessControl || config.writeAccessControl
|
|
54
79
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
55
|
-
|
|
80
|
+
const action = new ActionDefinition({
|
|
56
81
|
name: actionName,
|
|
57
82
|
properties: {
|
|
58
83
|
...(model.properties)
|
|
@@ -62,26 +87,68 @@ function defineCreateAction(config, context) {
|
|
|
62
87
|
skipValidation: true,
|
|
63
88
|
//queuedBy: otherPropertyNames,
|
|
64
89
|
waitForEvents: true,
|
|
65
|
-
|
|
66
|
-
const id = properties[modelPropertyName] || app.generateUid()
|
|
67
|
-
const entity = await modelRuntime().get(id)
|
|
68
|
-
if(entity) throw 'exists'
|
|
69
|
-
const identifiers = extractIdentifiers(otherPropertyNames, properties)
|
|
70
|
-
const data = extractObjectData(writeableProperties, properties,
|
|
71
|
-
App.computeDefaults(model, properties, { client, service } ))
|
|
72
|
-
await App.validation.validate({ ...identifiers, ...data }, validators,
|
|
73
|
-
{ source: action, action, service, app, client })
|
|
74
|
-
await fireChangeTriggers(context, objectType, identifiers, id, null, data)
|
|
75
|
-
emit({
|
|
76
|
-
type: eventName,
|
|
77
|
-
[modelPropertyName]: id,
|
|
78
|
-
identifiers, data
|
|
79
|
-
})
|
|
80
|
-
return id
|
|
81
|
-
}
|
|
90
|
+
execute: () => { throw new Error('not generated yet') }
|
|
82
91
|
})
|
|
83
|
-
const action = service.actions[actionName]
|
|
84
92
|
const validators = App.validation.getValidators(action, service, action)
|
|
93
|
+
const validationContext = { source: action, action }
|
|
94
|
+
action.execute = getCreateFunction( validators, validationContext, config, context)
|
|
95
|
+
service.actions[actionName] = action
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function defineCreateTrigger(config, context) {
|
|
99
|
+
const {
|
|
100
|
+
service, app, model, modelPropertyName, modelRuntime, objectType,
|
|
101
|
+
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
102
|
+
} = context
|
|
103
|
+
const actionName = 'create' + joinedOthersClassName + context.reverseRelationWord + modelName
|
|
104
|
+
const triggerName = `${service.name}_${actionName}`
|
|
105
|
+
const trigger = new TriggerDefinition({
|
|
106
|
+
name: triggerName,
|
|
107
|
+
properties: {
|
|
108
|
+
...(model.properties)
|
|
109
|
+
},
|
|
110
|
+
skipValidation: true,
|
|
111
|
+
//queuedBy: otherPropertyNames,
|
|
112
|
+
waitForEvents: true,
|
|
113
|
+
execute: () => { throw new Error('not generated yet') }
|
|
114
|
+
})
|
|
115
|
+
const validators = App.validation.getValidators(trigger, service, trigger)
|
|
116
|
+
const validationContext = { source: trigger, trigger }
|
|
117
|
+
trigger.execute = getCreateFunction( validators, validationContext, config, context)
|
|
118
|
+
service.triggers[triggerName] = [trigger]
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function getUpdateFunction( validators, validationContext, config, context) {
|
|
122
|
+
const {
|
|
123
|
+
service, app, model, modelPropertyName, modelRuntime, objectType,
|
|
124
|
+
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
125
|
+
} = context
|
|
126
|
+
const eventName = joinedOthersPropertyName + context.reverseRelationWord + modelName + 'Updated'
|
|
127
|
+
return async function execute(properties, { client, service }, emit) {
|
|
128
|
+
const id = properties[modelPropertyName]
|
|
129
|
+
const entity = await modelRuntime().get(id)
|
|
130
|
+
if(!entity) throw 'not_found'
|
|
131
|
+
const entityIdParts = extractIdParts(otherPropertyNames, entity)
|
|
132
|
+
const idParts = extractIdParts(otherPropertyNames, properties)
|
|
133
|
+
if(JSON.stringify(entityIdParts) !== JSON.stringify(idParts)) {
|
|
134
|
+
throw 'not_authorized'
|
|
135
|
+
}
|
|
136
|
+
const identifiers = extractIdentifiers(otherPropertyNames, properties)
|
|
137
|
+
const data = App.utils.mergeDeep({},
|
|
138
|
+
extractObjectData(writeableProperties, properties, entity),
|
|
139
|
+
App.computeUpdates(model, { ...entity, ...properties }, { client, service })
|
|
140
|
+
)
|
|
141
|
+
await App.validation.validate({ ...identifiers, ...data }, validators,
|
|
142
|
+
validationContext)
|
|
143
|
+
await fireChangeTriggers(context, objectType, identifiers, id,
|
|
144
|
+
extractObjectData(writeableProperties, entity, {}), data)
|
|
145
|
+
emit({
|
|
146
|
+
type: eventName,
|
|
147
|
+
[modelPropertyName]: id,
|
|
148
|
+
identifiers,
|
|
149
|
+
data
|
|
150
|
+
})
|
|
151
|
+
}
|
|
85
152
|
}
|
|
86
153
|
|
|
87
154
|
function defineUpdateAction(config, context) {
|
|
@@ -93,7 +160,7 @@ function defineUpdateAction(config, context) {
|
|
|
93
160
|
const actionName = 'update' + joinedOthersClassName + context.reverseRelationWord + modelName
|
|
94
161
|
const accessControl = config.updateAccessControl || config.writeAccessControl
|
|
95
162
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
96
|
-
|
|
163
|
+
const action = new ActionDefinition({
|
|
97
164
|
name: actionName,
|
|
98
165
|
properties: {
|
|
99
166
|
[modelPropertyName]: {
|
|
@@ -103,37 +170,69 @@ function defineUpdateAction(config, context) {
|
|
|
103
170
|
...(model.properties)
|
|
104
171
|
},
|
|
105
172
|
access: config.updateAccess || config.writeAccess,
|
|
106
|
-
accessControl
|
|
173
|
+
accessControl,
|
|
107
174
|
skipValidation: true,
|
|
108
175
|
//queuedBy: otherPropertyNames,
|
|
109
176
|
waitForEvents: true,
|
|
110
|
-
|
|
111
|
-
console.log("UPDATE", actionName, properties)
|
|
112
|
-
const id = properties[modelPropertyName]
|
|
113
|
-
const entity = await modelRuntime().get(id)
|
|
114
|
-
if(!entity) throw 'not_found'
|
|
115
|
-
const entityIdParts = extractIdParts(otherPropertyNames, entity)
|
|
116
|
-
const idParts = extractIdParts(otherPropertyNames, properties)
|
|
117
|
-
if(JSON.stringify(entityIdParts) != JSON.stringify(idParts)) {
|
|
118
|
-
throw 'not_authorized'
|
|
119
|
-
}
|
|
120
|
-
const identifiers = extractIdentifiers(otherPropertyNames, properties)
|
|
121
|
-
const data = extractObjectData(writeableProperties, properties, entity)
|
|
122
|
-
const dataWithIdentifiers = { [modelPropertyName]: id, ...identifiers, ...data }
|
|
123
|
-
await App.validation.validate(dataWithIdentifiers, validators,
|
|
124
|
-
{ source: action, action, service, app, client })
|
|
125
|
-
await fireChangeTriggers(context, objectType, identifiers, id,
|
|
126
|
-
extractObjectData(writeableProperties, entity, {}), data)
|
|
127
|
-
emit({
|
|
128
|
-
type: eventName,
|
|
129
|
-
[modelPropertyName]: id,
|
|
130
|
-
identifiers,
|
|
131
|
-
data
|
|
132
|
-
})
|
|
133
|
-
}
|
|
177
|
+
execute: () => { throw new Error('not generated yet') }
|
|
134
178
|
})
|
|
135
|
-
const action = service.actions[actionName]
|
|
136
179
|
const validators = App.validation.getValidators(action, service, action)
|
|
180
|
+
const validationContext = { source: action, action }
|
|
181
|
+
action.execute = getUpdateFunction( validators, validationContext, config, context)
|
|
182
|
+
service.actions[actionName] = action
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function defineUpdateTrigger(config, context) {
|
|
186
|
+
const {
|
|
187
|
+
service, app, model, modelRuntime, modelPropertyName, objectType,
|
|
188
|
+
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
189
|
+
} = context
|
|
190
|
+
const eventName = joinedOthersPropertyName + context.reverseRelationWord + modelName + 'Updated'
|
|
191
|
+
const actionName = 'update' + joinedOthersClassName + context.reverseRelationWord + modelName
|
|
192
|
+
const triggerName = `${service.name}_${actionName}`
|
|
193
|
+
const trigger = new TriggerDefinition({
|
|
194
|
+
name: triggerName,
|
|
195
|
+
properties: {
|
|
196
|
+
[modelPropertyName]: {
|
|
197
|
+
type: model,
|
|
198
|
+
validation: ['nonEmpty']
|
|
199
|
+
},
|
|
200
|
+
...(model.properties)
|
|
201
|
+
},
|
|
202
|
+
skipValidation: true,
|
|
203
|
+
//queuedBy: otherPropertyNames,
|
|
204
|
+
waitForEvents: true,
|
|
205
|
+
execute: () => { throw new Error('not generated yet') }
|
|
206
|
+
})
|
|
207
|
+
const validators = App.validation.getValidators(trigger, service, trigger)
|
|
208
|
+
const validationContext = { source: trigger, trigger }
|
|
209
|
+
trigger.execute = getUpdateFunction( validators, validationContext, config, context)
|
|
210
|
+
service.triggers[triggerName] = [trigger]
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
function getDeleteFunction( validators, validationContext, config, context) {
|
|
214
|
+
const {
|
|
215
|
+
service, app, model, modelPropertyName, modelRuntime, objectType,
|
|
216
|
+
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
217
|
+
} = context
|
|
218
|
+
const eventName = joinedOthersPropertyName + context.reverseRelationWord + modelName + 'Deleted'
|
|
219
|
+
return async function execute(properties, { client, service }, emit) {
|
|
220
|
+
const id = properties[modelPropertyName]
|
|
221
|
+
const entity = await modelRuntime().get(id)
|
|
222
|
+
if(!entity) throw 'not_found'
|
|
223
|
+
const entityIdParts = extractIdParts(otherPropertyNames, entity)
|
|
224
|
+
const idParts = extractIdParts(otherPropertyNames, properties)
|
|
225
|
+
if(JSON.stringify(entityIdParts) !== JSON.stringify(idParts)) {
|
|
226
|
+
throw 'not_authorized'
|
|
227
|
+
}
|
|
228
|
+
const identifiers = extractIdentifiers(otherPropertyNames, entity)
|
|
229
|
+
await fireChangeTriggers(context, objectType, identifiers, id,
|
|
230
|
+
extractObjectData(writeableProperties, entity, {}), null)
|
|
231
|
+
emit({
|
|
232
|
+
type: eventName,
|
|
233
|
+
[modelPropertyName]: id
|
|
234
|
+
})
|
|
235
|
+
}
|
|
137
236
|
}
|
|
138
237
|
|
|
139
238
|
function defineDeleteAction(config, context) {
|
|
@@ -145,7 +244,7 @@ function defineDeleteAction(config, context) {
|
|
|
145
244
|
const actionName = 'delete' + joinedOthersClassName + context.reverseRelationWord + modelName
|
|
146
245
|
const accessControl = config.deleteAccessControl || config.writeAccessControl
|
|
147
246
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
148
|
-
|
|
247
|
+
const action = new ActionDefinition({
|
|
149
248
|
name: actionName,
|
|
150
249
|
properties: {
|
|
151
250
|
[modelPropertyName]: {
|
|
@@ -160,24 +259,93 @@ function defineDeleteAction(config, context) {
|
|
|
160
259
|
//queuedBy: otherPropertyNames,
|
|
161
260
|
waitForEvents: true,
|
|
162
261
|
timeout: config.deleteTimeout,
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
262
|
+
execute: () => { throw new Error('not generated yet') }
|
|
263
|
+
})
|
|
264
|
+
const validators = App.validation.getValidators(action, service, action)
|
|
265
|
+
const validationContext = { source: action, action }
|
|
266
|
+
action.execute = getDeleteFunction( validators, validationContext, config, context)
|
|
267
|
+
service.actions[actionName] = action
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function defineDeleteTrigger(config, context) {
|
|
271
|
+
const {
|
|
272
|
+
service, app, model, modelPropertyName, modelRuntime, objectType,
|
|
273
|
+
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
274
|
+
} = context
|
|
275
|
+
const eventName = joinedOthersPropertyName + context.reverseRelationWord + modelName + 'Deleted'
|
|
276
|
+
const actionName = 'delete' + joinedOthersClassName + context.reverseRelationWord + modelName
|
|
277
|
+
const triggerName = `${service.name}_${actionName}`
|
|
278
|
+
const trigger = new TriggerDefinition({
|
|
279
|
+
name: triggerName,
|
|
280
|
+
properties: {
|
|
281
|
+
[modelPropertyName]: {
|
|
282
|
+
type: model,
|
|
283
|
+
validation: ['nonEmpty']
|
|
284
|
+
},
|
|
285
|
+
...(model.properties)
|
|
286
|
+
},
|
|
287
|
+
skipValidation: true,
|
|
288
|
+
//queuedBy: otherPropertyNames,
|
|
289
|
+
waitForEvents: true,
|
|
290
|
+
execute: () => { throw new Error('not generated yet') }
|
|
291
|
+
})
|
|
292
|
+
const validators = App.validation.getValidators(trigger, service, trigger)
|
|
293
|
+
const validationContext = { source: trigger, trigger }
|
|
294
|
+
trigger.execute = getDeleteFunction( validators, validationContext, config, context)
|
|
295
|
+
service.triggers[triggerName] = [trigger]
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function getCopyFunction( validators, validationContext, config, context) {
|
|
299
|
+
const {
|
|
300
|
+
service, app, model, modelPropertyName, modelRuntime, objectType,
|
|
301
|
+
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
302
|
+
} = context
|
|
303
|
+
const eventName = joinedOthersPropertyName + context.reverseRelationWord + modelName + 'Copied'
|
|
304
|
+
return async function execute(properties, { client, service }, emit) {
|
|
305
|
+
const id = properties[modelPropertyName]
|
|
306
|
+
const entity = await modelRuntime().get(id)
|
|
307
|
+
if(!entity) throw new Error('not_found')
|
|
308
|
+
const entityIdParts = extractIdParts(otherPropertyNames, entity)
|
|
309
|
+
const idParts = extractIdParts(otherPropertyNames, properties)
|
|
310
|
+
const identifiers = extractIdentifiers(otherPropertyNames, entity)
|
|
311
|
+
if(JSON.stringify(entityIdParts) !== JSON.stringify(idParts)) {
|
|
312
|
+
throw new Error('not_authorized')
|
|
313
|
+
}
|
|
314
|
+
const srcData = extractObjectData(writeableProperties, properties, entity)
|
|
315
|
+
const updatedData = App.utils.mergeDeep(srcData, properties.updates)
|
|
316
|
+
const newId = app.generateUid()
|
|
317
|
+
const dataWithIdentifiers = { [modelPropertyName]: newId, ...identifiers, ...updatedData }
|
|
318
|
+
await App.validation.validate(dataWithIdentifiers, validators,
|
|
319
|
+
validationContext)
|
|
320
|
+
app.trigger({
|
|
321
|
+
type: 'copy'+service.name[0].toUpperCase()+service.name.slice(1)+'_'+modelName,
|
|
322
|
+
objectType,
|
|
323
|
+
object: newId,
|
|
324
|
+
from: id,
|
|
325
|
+
identifiers,
|
|
326
|
+
data: updatedData
|
|
327
|
+
}),
|
|
328
|
+
app.trigger({
|
|
329
|
+
type: 'copyObject',
|
|
330
|
+
objectType,
|
|
331
|
+
object: newId,
|
|
332
|
+
from: id,
|
|
333
|
+
identifiers,
|
|
334
|
+
data: updatedData
|
|
178
335
|
})
|
|
336
|
+
await fireChangeTriggers(context, objectType, identifiers, newId, null, updatedData)
|
|
337
|
+
emit({
|
|
338
|
+
type: eventName,
|
|
339
|
+
[modelPropertyName]: newId,
|
|
340
|
+
['from'+modelPropertyName[0].toUpperCase() + modelPropertyName.slice(1)]: id,
|
|
341
|
+
identifiers,
|
|
342
|
+
data: updatedData
|
|
343
|
+
})
|
|
344
|
+
return {
|
|
345
|
+
newId,
|
|
179
346
|
}
|
|
180
|
-
}
|
|
347
|
+
}
|
|
348
|
+
|
|
181
349
|
}
|
|
182
350
|
|
|
183
351
|
function defineCopyAction(config, context) {
|
|
@@ -190,7 +358,7 @@ function defineCopyAction(config, context) {
|
|
|
190
358
|
const actionName = 'copy' + joinedOthersClassName + context.reverseRelationWord + modelName
|
|
191
359
|
const accessControl = config.copyAccessControl
|
|
192
360
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
193
|
-
|
|
361
|
+
const action = new ActionDefinition({
|
|
194
362
|
name: actionName,
|
|
195
363
|
properties: {
|
|
196
364
|
[modelPropertyName]: {
|
|
@@ -209,53 +377,47 @@ function defineCopyAction(config, context) {
|
|
|
209
377
|
skipValidation: true,
|
|
210
378
|
//queuedBy: otherPropertyNames,
|
|
211
379
|
waitForEvents: true,
|
|
212
|
-
|
|
213
|
-
const id = properties[modelPropertyName]
|
|
214
|
-
const entity = await modelRuntime().get(id)
|
|
215
|
-
if(!entity) throw new Error('not_found')
|
|
216
|
-
const entityIdParts = extractIdParts(otherPropertyNames, entity)
|
|
217
|
-
const idParts = extractIdParts(otherPropertyNames, properties)
|
|
218
|
-
const identifiers = extractIdentifiers(otherPropertyNames, entity)
|
|
219
|
-
if(JSON.stringify(entityIdParts) != JSON.stringify(idParts)) {
|
|
220
|
-
throw new Error('not_authorized')
|
|
221
|
-
}
|
|
222
|
-
const srcData = extractObjectData(writeableProperties, properties, entity)
|
|
223
|
-
const updatedData = App.utils.mergeDeep(srcData, properties.updates)
|
|
224
|
-
const newId = app.generateUid()
|
|
225
|
-
const dataWithIdentifiers = { [modelPropertyName]: newId, ...identifiers, ...updatedData }
|
|
226
|
-
await App.validation.validate(dataWithIdentifiers, validators,
|
|
227
|
-
{ source: action, action, service, app, client })
|
|
228
|
-
app.trigger({
|
|
229
|
-
type: 'copy'+service.name[0].toUpperCase()+service.name.slice(1)+'_'+modelName,
|
|
230
|
-
objectType,
|
|
231
|
-
object: newId,
|
|
232
|
-
from: id,
|
|
233
|
-
identifiers,
|
|
234
|
-
data: updatedData
|
|
235
|
-
}),
|
|
236
|
-
app.trigger({
|
|
237
|
-
type: 'copyObject',
|
|
238
|
-
objectType,
|
|
239
|
-
object: newId,
|
|
240
|
-
from: id,
|
|
241
|
-
identifiers,
|
|
242
|
-
data: updatedData
|
|
243
|
-
})
|
|
244
|
-
await fireChangeTriggers(context, objectType, identifiers, newId, null, updatedData)
|
|
245
|
-
emit({
|
|
246
|
-
type: eventName,
|
|
247
|
-
[modelPropertyName]: newId,
|
|
248
|
-
['from'+modelPropertyName[0].toUpperCase() + modelPropertyName.slice(1)]: id,
|
|
249
|
-
identifiers,
|
|
250
|
-
data: updatedData
|
|
251
|
-
})
|
|
252
|
-
return {
|
|
253
|
-
newId,
|
|
254
|
-
}
|
|
255
|
-
}
|
|
380
|
+
execute: () => { throw new Error('not generated yet') }
|
|
256
381
|
})
|
|
257
|
-
const action = service.actions[actionName]
|
|
258
382
|
const validators = App.validation.getValidators(action, service, action)
|
|
383
|
+
const validationContext = { source: action, action }
|
|
384
|
+
action.execute = getCopyFunction( validators, validationContext, config, context)
|
|
385
|
+
service.actions[actionName] = action
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
function defineCopyTrigger(config, context) {
|
|
389
|
+
const {
|
|
390
|
+
service, app, model, modelRuntime, modelPropertyName, objectType,
|
|
391
|
+
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others,
|
|
392
|
+
identifiers
|
|
393
|
+
} = context
|
|
394
|
+
const eventName = joinedOthersPropertyName + context.reverseRelationWord + modelName + 'Copied'
|
|
395
|
+
const actionName = 'copy' + joinedOthersClassName + context.reverseRelationWord + modelName
|
|
396
|
+
const triggerName = `${service.name}_${actionName}`
|
|
397
|
+
const trigger = new TriggerDefinition({
|
|
398
|
+
name: triggerName,
|
|
399
|
+
properties: {
|
|
400
|
+
[modelPropertyName]: {
|
|
401
|
+
type: model,
|
|
402
|
+
validation: ['nonEmpty']
|
|
403
|
+
},
|
|
404
|
+
...(identifiers),
|
|
405
|
+
updates: {
|
|
406
|
+
type: 'object',
|
|
407
|
+
properties: {
|
|
408
|
+
...(model.properties)
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
},
|
|
412
|
+
skipValidation: true,
|
|
413
|
+
//queuedBy: otherPropertyNames,
|
|
414
|
+
waitForEvents: true,
|
|
415
|
+
execute: () => { throw new Error('not generated yet') }
|
|
416
|
+
})
|
|
417
|
+
const validators = App.validation.getValidators(trigger, service, trigger)
|
|
418
|
+
const validationContext = { source: trigger, trigger }
|
|
419
|
+
trigger.execute = getCopyFunction( validators, validationContext, config, context)
|
|
420
|
+
service.triggers[triggerName] = [trigger]
|
|
259
421
|
}
|
|
260
422
|
|
|
261
423
|
function defineCopyOnParentCopyTrigger(config, context) {
|
|
@@ -297,7 +459,7 @@ function defineCopyOnParentCopyTrigger(config, context) {
|
|
|
297
459
|
}
|
|
298
460
|
for(let i = 0; i < others.length; i++) {
|
|
299
461
|
const other = others[i]
|
|
300
|
-
if(other
|
|
462
|
+
if(other === parentType) {
|
|
301
463
|
newIdentifiers[otherPropertyNames[i]] = parent
|
|
302
464
|
}
|
|
303
465
|
}
|
|
@@ -343,6 +505,7 @@ function defineSortIndex(context, sortFields) {
|
|
|
343
505
|
export {
|
|
344
506
|
defineView,
|
|
345
507
|
defineCreateAction, defineUpdateAction, defineDeleteAction, defineCopyAction,
|
|
508
|
+
defineCreateTrigger, defineUpdateTrigger, defineDeleteTrigger, defineCopyTrigger,
|
|
346
509
|
defineCopyOnParentCopyTrigger,
|
|
347
510
|
defineSortIndex,
|
|
348
511
|
}
|
package/propertyOf.js
CHANGED
|
@@ -7,7 +7,9 @@ import {
|
|
|
7
7
|
import { defineSetEvent, defineUpdatedEvent, defineTransferredEvent, defineResetEvent } from './propertyEvents.js'
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
|
-
defineView,
|
|
10
|
+
defineView,
|
|
11
|
+
defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction,
|
|
12
|
+
defineSetTrigger, defineUpdateTrigger, defineSetOrUpdateTrigger, defineResetTrigger
|
|
11
13
|
} from './singularRelationUtils.js'
|
|
12
14
|
|
|
13
15
|
export default function(service, app) {
|
|
@@ -22,12 +24,11 @@ export default function(service, app) {
|
|
|
22
24
|
addAccessControlParents(context)
|
|
23
25
|
defineIndexes(context.model, context.otherPropertyNames, context.others)
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
27
|
+
defineView({ ...config }, context,
|
|
28
|
+
config.readAccess || config.writeAccess || config.readAccessControl || config.writeAccessControl)
|
|
28
29
|
if(config.views) {
|
|
29
30
|
for(const view of config.views) {
|
|
30
|
-
defineView({ ...config, ...view }, context)
|
|
31
|
+
defineView({ ...config, ...view }, context, !view.internal)
|
|
31
32
|
}
|
|
32
33
|
}
|
|
33
34
|
|
|
@@ -37,6 +38,11 @@ export default function(service, app) {
|
|
|
37
38
|
defineResetEvent(config, context, generateId)
|
|
38
39
|
defineDeleteByOwnerEvents(config, context)
|
|
39
40
|
|
|
41
|
+
defineSetTrigger(config, context)
|
|
42
|
+
defineUpdateTrigger(config, context)
|
|
43
|
+
defineSetOrUpdateTrigger(config, context)
|
|
44
|
+
defineResetTrigger(config, context)
|
|
45
|
+
|
|
40
46
|
if(config.setAccess || config.writeAccess || config.setAccessControl || config.writeAccessControl) {
|
|
41
47
|
defineSetAction(config, context)
|
|
42
48
|
}
|
package/propertyOfAny.js
CHANGED
|
@@ -9,7 +9,9 @@ import {
|
|
|
9
9
|
} from './propertyEvents.js'
|
|
10
10
|
|
|
11
11
|
import {
|
|
12
|
-
defineObjectView, defineRangeViews,
|
|
12
|
+
defineObjectView, defineRangeViews,
|
|
13
|
+
defineSetAction, defineUpdateAction, defineSetOrUpdateAction, defineResetAction,
|
|
14
|
+
defineSetTrigger, defineUpdateTrigger, defineSetOrUpdateTrigger, defineResetTrigger
|
|
13
15
|
} from './singularRelationAnyUtils.js'
|
|
14
16
|
|
|
15
17
|
export default function(service, app) {
|
|
@@ -25,15 +27,15 @@ export default function(service, app) {
|
|
|
25
27
|
addAccessControlAnyParents(context)
|
|
26
28
|
defineAnyIndexes(context.model, context.otherPropertyNames, false)
|
|
27
29
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
defineObjectView(config, context,
|
|
31
|
+
config.singleAccess || config.readAccess || config.singleAccessControl || config.readAccessControl
|
|
32
|
+
)
|
|
33
|
+
defineRangeViews(config, context,
|
|
34
|
+
config.listAccess || config.readAccess || config.listAccessControl || config.readAccessControl
|
|
35
|
+
)
|
|
34
36
|
if(config.views) {
|
|
35
37
|
for(const view of config.views) {
|
|
36
|
-
defineObjectView({ ...config, ...view }, context)
|
|
38
|
+
defineObjectView({ ...config, ...view }, context, !view.internal)
|
|
37
39
|
}
|
|
38
40
|
}
|
|
39
41
|
|
|
@@ -43,6 +45,11 @@ export default function(service, app) {
|
|
|
43
45
|
defineResetEvent(config, context, generateAnyId)
|
|
44
46
|
defineDeleteByOwnerEvents(config, context, generateAnyId)
|
|
45
47
|
|
|
48
|
+
defineSetTrigger(config, context)
|
|
49
|
+
defineUpdateTrigger(config, context)
|
|
50
|
+
defineSetOrUpdateTrigger(config, context)
|
|
51
|
+
defineResetTrigger(config, context)
|
|
52
|
+
|
|
46
53
|
if(config.setAccess || config.writeAccess || config.setAccessControl || config.writeAccessControl) {
|
|
47
54
|
defineSetAction(config, context)
|
|
48
55
|
}
|
package/relatedTo.js
CHANGED
|
@@ -7,7 +7,10 @@ import {
|
|
|
7
7
|
} from './itemEvents.js'
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
|
-
defineView,
|
|
10
|
+
defineView,
|
|
11
|
+
defineCreateAction, defineUpdateAction, defineDeleteAction, defineCopyAction,
|
|
12
|
+
defineCreateTrigger, defineUpdateTrigger, defineDeleteTrigger, defineCopyTrigger,
|
|
13
|
+
defineSortIndex,
|
|
11
14
|
} from './pluralRelationUtils.js'
|
|
12
15
|
|
|
13
16
|
export default function(service, app) {
|
|
@@ -25,9 +28,9 @@ export default function(service, app) {
|
|
|
25
28
|
}
|
|
26
29
|
}
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
defineView(config, context,
|
|
32
|
+
config.readAccess || config.readAccessControl || config.writeAccessControl
|
|
33
|
+
)
|
|
31
34
|
/// TODO: multiple views with limited fields
|
|
32
35
|
|
|
33
36
|
defineCreatedEvent(config, context)
|
|
@@ -35,6 +38,10 @@ export default function(service, app) {
|
|
|
35
38
|
defineTransferredEvent(config, context)
|
|
36
39
|
defineDeletedEvent(config, context)
|
|
37
40
|
|
|
41
|
+
defineCreateTrigger(config, context)
|
|
42
|
+
defineUpdateTrigger(config, context)
|
|
43
|
+
defineDeleteTrigger(config, context)
|
|
44
|
+
|
|
38
45
|
if(config.createAccess || config.writeAccess || config.createAccessControl || config.writeAccessControl) {
|
|
39
46
|
defineCreateAction(config, context)
|
|
40
47
|
}
|
package/relatedToAny.js
CHANGED
|
@@ -7,7 +7,10 @@ import {
|
|
|
7
7
|
} from './itemEvents.js'
|
|
8
8
|
|
|
9
9
|
import {
|
|
10
|
-
defineView,
|
|
10
|
+
defineView,
|
|
11
|
+
defineCreateAction, defineUpdateAction, defineDeleteAction,
|
|
12
|
+
defineCreateTrigger, defineUpdateTrigger, defineDeleteTrigger,
|
|
13
|
+
defineSortIndex
|
|
11
14
|
} from './pluralRelationAnyUtils.js'
|
|
12
15
|
|
|
13
16
|
export default function(service, app) {
|
|
@@ -25,9 +28,9 @@ export default function(service, app) {
|
|
|
25
28
|
}
|
|
26
29
|
}
|
|
27
30
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
defineView(config, context,
|
|
32
|
+
config.readAccess || config.readAccessControl || config.writeAccessControl
|
|
33
|
+
)
|
|
31
34
|
/// TODO: multiple views with limited fields
|
|
32
35
|
|
|
33
36
|
defineCreatedEvent(config, context)
|
|
@@ -35,6 +38,10 @@ export default function(service, app) {
|
|
|
35
38
|
defineTransferredEvent(config, context)
|
|
36
39
|
defineDeletedEvent(config, context)
|
|
37
40
|
|
|
41
|
+
defineCreateTrigger(config, context)
|
|
42
|
+
defineUpdateTrigger(config, context)
|
|
43
|
+
defineDeleteTrigger(config, context)
|
|
44
|
+
|
|
38
45
|
if(config.createAccess || config.writeAccess || config.createAccessControl || config.writeAccessControl) {
|
|
39
46
|
defineCreateAction(config, context)
|
|
40
47
|
}
|