@live-change/relations-plugin 0.8.148 → 0.9.0
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 +1 -1
- package/package.json +3 -3
- package/pluralRelationAnyUtils.js +21 -31
- package/pluralRelationUtils.js +17 -29
- package/propertyEvents.js +4 -4
- package/singularRelationAnyUtils.js +23 -16
- package/singularRelationUtils.js +24 -15
package/itemEvents.js
CHANGED
|
@@ -6,7 +6,7 @@ function defineCreatedEvent(config, context) {
|
|
|
6
6
|
const {
|
|
7
7
|
service, modelRuntime, joinedOthersPropertyName, modelName, modelPropertyName, reverseRelationWord
|
|
8
8
|
} = context
|
|
9
|
-
const eventName =
|
|
9
|
+
const eventName = modelName + 'Created'
|
|
10
10
|
service.events[eventName] = new EventDefinition({
|
|
11
11
|
name: eventName,
|
|
12
12
|
properties: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/relations-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
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.
|
|
25
|
+
"@live-change/framework": "^0.9.0",
|
|
26
26
|
"pluralize": "^8.0.0"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "b82513f5b400afcc4b8cc3ae1f9dfe4ac3a2a6eb"
|
|
29
29
|
}
|
|
@@ -28,7 +28,7 @@ function defineRangeView(config, context, external = true) {
|
|
|
28
28
|
prepareAccessControl(accessControl, otherPropertyNames)
|
|
29
29
|
const viewName = joinedOthersPropertyName + context.reverseRelationWord + pluralize(modelName)
|
|
30
30
|
model.crud.range = viewName
|
|
31
|
-
service.
|
|
31
|
+
service.view({
|
|
32
32
|
name: viewName,
|
|
33
33
|
properties: {
|
|
34
34
|
...viewProperties,
|
|
@@ -41,6 +41,7 @@ function defineRangeView(config, context, external = true) {
|
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
internal: !external,
|
|
44
|
+
global: config.globalView,
|
|
44
45
|
access: external && (config.readAccess || config.writeAccess),
|
|
45
46
|
accessControl,
|
|
46
47
|
daoPath(properties, { client, context }) {
|
|
@@ -55,27 +56,16 @@ function defineRangeView(config, context, external = true) {
|
|
|
55
56
|
function defineSingleView(config, context, external = true) {
|
|
56
57
|
const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
|
|
57
58
|
modelName, others, model, modelPropertyName } = context
|
|
58
|
-
const indexName = 'by'+context.joinedOthersClassName
|
|
59
59
|
const viewProperties = {}
|
|
60
|
-
for (let i = 0; i < others.length; i++) {
|
|
61
|
-
viewProperties[otherPropertyNames[i]] = new PropertyDefinition({
|
|
62
|
-
type: 'String',
|
|
63
|
-
validation: ['nonEmpty']
|
|
64
|
-
})
|
|
65
|
-
viewProperties[otherPropertyNames[i] + 'Type'] = new PropertyDefinition({
|
|
66
|
-
type: 'String',
|
|
67
|
-
validation: ['nonEmpty']
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
60
|
viewProperties[modelPropertyName] = new PropertyDefinition({
|
|
71
61
|
type: model,
|
|
72
62
|
validation: ['nonEmpty']
|
|
73
63
|
})
|
|
74
64
|
const accessControl = external && (config.readAccessControl || config.writeAccessControl)
|
|
75
65
|
prepareAccessControl(accessControl, otherPropertyNames)
|
|
76
|
-
const viewName =
|
|
66
|
+
const viewName = modelName[0].toLowerCase() + modelName.slice(1)
|
|
77
67
|
model.crud.read = viewName
|
|
78
|
-
service.
|
|
68
|
+
service.view({
|
|
79
69
|
name: viewName,
|
|
80
70
|
properties: {
|
|
81
71
|
...viewProperties
|
|
@@ -84,17 +74,11 @@ function defineSingleView(config, context, external = true) {
|
|
|
84
74
|
type: model
|
|
85
75
|
},
|
|
86
76
|
internal: !external,
|
|
77
|
+
global: config.globalView,
|
|
87
78
|
access: external && (config.readAccess || config.writeAccess),
|
|
88
79
|
accessControl,
|
|
89
80
|
async daoPath(properties, { client, context }) {
|
|
90
|
-
|
|
91
|
-
const prefix = App.encodeIdentifier(idParts)
|
|
92
|
-
const range = {
|
|
93
|
-
gte: prefix+'_'+properties[modelPropertyName],
|
|
94
|
-
lte: prefix+'_'+properties[modelPropertyName]
|
|
95
|
-
}
|
|
96
|
-
const path = modelRuntime().indexObjectPath(indexName, idParts, range)
|
|
97
|
-
return path
|
|
81
|
+
return modelRuntime().path(properties[modelPropertyName])
|
|
98
82
|
}
|
|
99
83
|
})
|
|
100
84
|
}
|
|
@@ -104,7 +88,7 @@ function getCreateFunction( validators, validationContext, config, context) {
|
|
|
104
88
|
service, app, model, modelPropertyName, modelRuntime, objectType,
|
|
105
89
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
106
90
|
} = context
|
|
107
|
-
const eventName =
|
|
91
|
+
const eventName = modelName + 'Created'
|
|
108
92
|
return async function execute(properties, { client, service }, emit) {
|
|
109
93
|
const id = properties[modelPropertyName] || app.generateUid()
|
|
110
94
|
const entity = await modelRuntime().get(id)
|
|
@@ -129,7 +113,7 @@ function defineCreateAction(config, context) {
|
|
|
129
113
|
service, app, model, modelPropertyName, modelRuntime, objectType,
|
|
130
114
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
131
115
|
} = context
|
|
132
|
-
const actionName = 'create' +
|
|
116
|
+
const actionName = 'create' + modelName
|
|
133
117
|
model.crud.create = actionName
|
|
134
118
|
const accessControl = config.createAccessControl || config.writeAccessControl
|
|
135
119
|
prepareAccessControl(accessControl, otherPropertyNames)
|
|
@@ -148,6 +132,7 @@ function defineCreateAction(config, context) {
|
|
|
148
132
|
const validators = App.validation.getValidators(action, service, action)
|
|
149
133
|
const validationContext = { source: action, action }
|
|
150
134
|
action.execute = getCreateFunction( validators, validationContext, config, context)
|
|
135
|
+
if(service.actions[actionName]) throw new Error('Action ' + actionName + ' already defined')
|
|
151
136
|
service.actions[actionName] = action
|
|
152
137
|
}
|
|
153
138
|
|
|
@@ -156,7 +141,7 @@ function defineCreateTrigger(config, context) {
|
|
|
156
141
|
service, app, model, modelPropertyName, modelRuntime, objectType,
|
|
157
142
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
158
143
|
} = context
|
|
159
|
-
const actionName = 'create' +
|
|
144
|
+
const actionName = 'create' + modelName
|
|
160
145
|
const triggerName = `${service.name}_${actionName}`
|
|
161
146
|
const trigger = new TriggerDefinition({
|
|
162
147
|
name: triggerName,
|
|
@@ -172,6 +157,7 @@ function defineCreateTrigger(config, context) {
|
|
|
172
157
|
const validators = App.validation.getValidators(trigger, service, trigger)
|
|
173
158
|
const validationContext = { source: trigger, trigger }
|
|
174
159
|
trigger.execute = getCreateFunction( validators, validationContext, config, context)
|
|
160
|
+
if(service.triggers[triggerName]) throw new Error('Trigger ' + triggerName + ' already defined')
|
|
175
161
|
service.triggers[triggerName] = [trigger]
|
|
176
162
|
}
|
|
177
163
|
|
|
@@ -180,7 +166,7 @@ function getUpdateFunction( validators, validationContext, config, context) {
|
|
|
180
166
|
service, app, model, modelPropertyName, modelRuntime, objectType,
|
|
181
167
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
182
168
|
} = context
|
|
183
|
-
const eventName =
|
|
169
|
+
const eventName = modelName + 'Updated'
|
|
184
170
|
return async function execute(properties, { client, service }, emit) {
|
|
185
171
|
const id = properties[modelPropertyName]
|
|
186
172
|
if(!id) throw new Error('no_id')
|
|
@@ -216,7 +202,7 @@ function defineUpdateAction(config, context) {
|
|
|
216
202
|
service, app, model, modelRuntime, modelPropertyName, objectType,
|
|
217
203
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
218
204
|
} = context
|
|
219
|
-
const actionName = 'update' +
|
|
205
|
+
const actionName = 'update' + modelName
|
|
220
206
|
model.crud.update = actionName
|
|
221
207
|
const accessControl = config.updateAccessControl || config.writeAccessControl
|
|
222
208
|
prepareAccessControl(accessControl, otherPropertyNames)
|
|
@@ -239,6 +225,7 @@ function defineUpdateAction(config, context) {
|
|
|
239
225
|
const validators = App.validation.getValidators(action, service, action)
|
|
240
226
|
const validationContext = { source: action, action }
|
|
241
227
|
action.execute = getUpdateFunction( validators, validationContext, config, context)
|
|
228
|
+
if(service.actions[actionName]) throw new Error('Action ' + actionName + ' already defined')
|
|
242
229
|
service.actions[actionName] = action
|
|
243
230
|
}
|
|
244
231
|
|
|
@@ -247,7 +234,7 @@ function defineUpdateTrigger(config, context) {
|
|
|
247
234
|
service, app, model, modelRuntime, modelPropertyName, objectType,
|
|
248
235
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
249
236
|
} = context
|
|
250
|
-
const actionName = 'update' +
|
|
237
|
+
const actionName = 'update' + modelName
|
|
251
238
|
const triggerName = `${service.name}_${actionName}`
|
|
252
239
|
const trigger = new TriggerDefinition({
|
|
253
240
|
name: triggerName,
|
|
@@ -267,6 +254,7 @@ function defineUpdateTrigger(config, context) {
|
|
|
267
254
|
const validators = App.validation.getValidators(trigger, service, trigger)
|
|
268
255
|
const validationContext = { source: trigger, trigger }
|
|
269
256
|
trigger.execute = getUpdateFunction( validators, validationContext, config, context)
|
|
257
|
+
if(service.triggers[triggerName]) throw new Error('Trigger ' + triggerName + ' already defined')
|
|
270
258
|
service.triggers[triggerName] = [trigger]
|
|
271
259
|
}
|
|
272
260
|
|
|
@@ -275,7 +263,7 @@ function getDeleteFunction(config, context) {
|
|
|
275
263
|
service, app, model, modelPropertyName, modelRuntime, objectType,
|
|
276
264
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
277
265
|
} = context
|
|
278
|
-
const eventName =
|
|
266
|
+
const eventName = modelName + 'Deleted'
|
|
279
267
|
return async function execute(properties, { client, service }, emit) {
|
|
280
268
|
const id = properties[modelPropertyName]
|
|
281
269
|
const entity = await modelRuntime().get(id)
|
|
@@ -299,7 +287,7 @@ function defineDeleteAction(config, context) {
|
|
|
299
287
|
service, app, model, modelRuntime, modelPropertyName, identifiers, objectType,
|
|
300
288
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
301
289
|
} = context
|
|
302
|
-
const actionName = 'delete' +
|
|
290
|
+
const actionName = 'delete' + modelName
|
|
303
291
|
model.crud.delete = actionName
|
|
304
292
|
const accessControl = config.deleteAccessControl || config.writeAccessControl
|
|
305
293
|
prepareAccessControl(accessControl, otherPropertyNames)
|
|
@@ -320,6 +308,7 @@ function defineDeleteAction(config, context) {
|
|
|
320
308
|
execute: () => { throw new Error('not generated yet') }
|
|
321
309
|
})
|
|
322
310
|
action.execute = getDeleteFunction(config, context)
|
|
311
|
+
if(service.actions[actionName]) throw new Error('Action ' + actionName + ' already defined')
|
|
323
312
|
service.actions[actionName] = action
|
|
324
313
|
}
|
|
325
314
|
|
|
@@ -328,7 +317,7 @@ function defineDeleteTrigger(config, context) {
|
|
|
328
317
|
service, app, model, modelRuntime, modelPropertyName, identifiers, objectType,
|
|
329
318
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
330
319
|
} = context
|
|
331
|
-
const actionName = 'delete' +
|
|
320
|
+
const actionName = 'delete' + modelName
|
|
332
321
|
const triggerName = `${service.name}_${actionName}`
|
|
333
322
|
const trigger = new TriggerDefinition({
|
|
334
323
|
name: triggerName,
|
|
@@ -346,6 +335,7 @@ function defineDeleteTrigger(config, context) {
|
|
|
346
335
|
execute: () => { throw new Error('not generated yet') }
|
|
347
336
|
})
|
|
348
337
|
trigger.execute = getDeleteFunction(config, context)
|
|
338
|
+
if(service.triggers[triggerName]) throw new Error('Trigger ' + triggerName + ' already defined')
|
|
349
339
|
service.triggers[triggerName] = [trigger]
|
|
350
340
|
}
|
|
351
341
|
|
package/pluralRelationUtils.js
CHANGED
|
@@ -34,6 +34,7 @@ function defineRangeView(config, context, external = true) {
|
|
|
34
34
|
}
|
|
35
35
|
},
|
|
36
36
|
internal: !external,
|
|
37
|
+
global: config.globalView,
|
|
37
38
|
access: external && (config.readAccess || config.writeAccess),
|
|
38
39
|
accessControl: config.readAccessControl || config.writeAccessControl,
|
|
39
40
|
daoPath(properties, { client, context }) {
|
|
@@ -48,19 +49,12 @@ function defineRangeView(config, context, external = true) {
|
|
|
48
49
|
function defineSingleView(config, context, external = true) {
|
|
49
50
|
const { service, modelRuntime, otherPropertyNames, joinedOthersPropertyName, joinedOthersClassName,
|
|
50
51
|
modelName, others, model, modelPropertyName } = context
|
|
51
|
-
const indexName = 'by'+context.joinedOthersClassName
|
|
52
52
|
const viewProperties = {}
|
|
53
|
-
for (let i = 0; i < others.length; i++) {
|
|
54
|
-
viewProperties[otherPropertyNames[i][0].toLowerCase() + otherPropertyNames[i].slice(1) ] = new PropertyDefinition({
|
|
55
|
-
type: others[i],
|
|
56
|
-
validation: ['nonEmpty']
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
53
|
viewProperties[modelPropertyName] = new PropertyDefinition({
|
|
60
54
|
type: model,
|
|
61
55
|
validation: ['nonEmpty']
|
|
62
56
|
})
|
|
63
|
-
const viewName =
|
|
57
|
+
const viewName = modelName[0].toLowerCase() + modelName.slice(1)
|
|
64
58
|
model.crud.read = viewName
|
|
65
59
|
const accessControl = external && (config.readAccessControl || config.writeAccessControl)
|
|
66
60
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
@@ -73,17 +67,11 @@ function defineSingleView(config, context, external = true) {
|
|
|
73
67
|
type: model
|
|
74
68
|
},
|
|
75
69
|
internal: !external,
|
|
70
|
+
global: config.globalView,
|
|
76
71
|
access: external && (config.readAccess || config.writeAccess),
|
|
77
72
|
accessControl: config.readAccessControl || config.writeAccessControl,
|
|
78
|
-
daoPath(properties, { client, context }) {
|
|
79
|
-
|
|
80
|
-
const prefix = App.encodeIdentifier(idParts)
|
|
81
|
-
const range = {
|
|
82
|
-
gte: prefix+'_'+properties[modelPropertyName],
|
|
83
|
-
lte: prefix+'_'+properties[modelPropertyName]
|
|
84
|
-
}
|
|
85
|
-
const path = modelRuntime().indexObjectPath(indexName, idParts, range)
|
|
86
|
-
return path
|
|
73
|
+
async daoPath(properties, { client, context }) {
|
|
74
|
+
return modelRuntime().path(properties[modelPropertyName])
|
|
87
75
|
}
|
|
88
76
|
})
|
|
89
77
|
}
|
|
@@ -93,7 +81,7 @@ function getCreateFunction( validators, validationContext, config, context) {
|
|
|
93
81
|
service, app, model, modelPropertyName, modelRuntime, objectType,
|
|
94
82
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
95
83
|
} = context
|
|
96
|
-
const eventName =
|
|
84
|
+
const eventName = modelName + 'Created'
|
|
97
85
|
return async function execute(properties, { client, service }, emit) {
|
|
98
86
|
const id = properties[modelPropertyName] || app.generateUid()
|
|
99
87
|
const entity = await modelRuntime().get(id)
|
|
@@ -118,7 +106,7 @@ function defineCreateAction(config, context) {
|
|
|
118
106
|
service, app, model, modelPropertyName, modelRuntime, objectType,
|
|
119
107
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
120
108
|
} = context
|
|
121
|
-
const actionName = 'create' +
|
|
109
|
+
const actionName = 'create' + modelName
|
|
122
110
|
model.crud.create = actionName
|
|
123
111
|
const accessControl = config.createAccessControl || config.writeAccessControl
|
|
124
112
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
@@ -145,7 +133,7 @@ function defineCreateTrigger(config, context) {
|
|
|
145
133
|
service, app, model, modelPropertyName, modelRuntime, objectType,
|
|
146
134
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
147
135
|
} = context
|
|
148
|
-
const actionName = 'create' +
|
|
136
|
+
const actionName = 'create' + modelName
|
|
149
137
|
const triggerName = `${service.name}_${actionName}`
|
|
150
138
|
const trigger = new TriggerDefinition({
|
|
151
139
|
name: triggerName,
|
|
@@ -201,7 +189,7 @@ function defineUpdateAction(config, context) {
|
|
|
201
189
|
service, app, model, modelRuntime, modelPropertyName, objectType,
|
|
202
190
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
203
191
|
} = context
|
|
204
|
-
const actionName = 'update' +
|
|
192
|
+
const actionName = 'update' + modelName
|
|
205
193
|
model.crud.update = actionName
|
|
206
194
|
const accessControl = config.updateAccessControl || config.writeAccessControl
|
|
207
195
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
@@ -232,7 +220,7 @@ function defineUpdateTrigger(config, context) {
|
|
|
232
220
|
service, app, model, modelRuntime, modelPropertyName, objectType,
|
|
233
221
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
234
222
|
} = context
|
|
235
|
-
const actionName = 'update' +
|
|
223
|
+
const actionName = 'update' + modelName
|
|
236
224
|
const triggerName = `${service.name}_${actionName}`
|
|
237
225
|
const trigger = new TriggerDefinition({
|
|
238
226
|
name: triggerName,
|
|
@@ -259,7 +247,7 @@ function getDeleteFunction( validators, validationContext, config, context) {
|
|
|
259
247
|
service, app, model, modelPropertyName, modelRuntime, objectType,
|
|
260
248
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
261
249
|
} = context
|
|
262
|
-
const eventName =
|
|
250
|
+
const eventName = modelName + 'Deleted'
|
|
263
251
|
return async function execute(properties, { client, service }, emit) {
|
|
264
252
|
const id = properties[modelPropertyName]
|
|
265
253
|
const entity = await modelRuntime().get(id)
|
|
@@ -285,7 +273,7 @@ function defineDeleteAction(config, context) {
|
|
|
285
273
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
286
274
|
} = context
|
|
287
275
|
const eventName = joinedOthersPropertyName + context.reverseRelationWord + modelName + 'Deleted'
|
|
288
|
-
const actionName = 'delete' +
|
|
276
|
+
const actionName = 'delete' + modelName
|
|
289
277
|
const accessControl = config.deleteAccessControl || config.writeAccessControl
|
|
290
278
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
291
279
|
const action = new ActionDefinition({
|
|
@@ -316,8 +304,8 @@ function defineDeleteTrigger(config, context) {
|
|
|
316
304
|
service, app, model, modelPropertyName, modelRuntime, objectType,
|
|
317
305
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
318
306
|
} = context
|
|
319
|
-
const eventName =
|
|
320
|
-
const actionName = 'delete' +
|
|
307
|
+
const eventName = modelName + 'Deleted'
|
|
308
|
+
const actionName = 'delete' + modelName
|
|
321
309
|
const triggerName = `${service.name}_${actionName}`
|
|
322
310
|
const trigger = new TriggerDefinition({
|
|
323
311
|
name: triggerName,
|
|
@@ -400,8 +388,8 @@ function defineCopyAction(config, context) {
|
|
|
400
388
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others,
|
|
401
389
|
identifiers
|
|
402
390
|
} = context
|
|
403
|
-
const eventName =
|
|
404
|
-
const actionName = 'copy' +
|
|
391
|
+
const eventName = modelName + 'Copied'
|
|
392
|
+
const actionName = 'copy' + modelName
|
|
405
393
|
const accessControl = config.copyAccessControl
|
|
406
394
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
407
395
|
const action = new ActionDefinition({
|
|
@@ -471,7 +459,7 @@ function defineCopyOnParentCopyTrigger(config, context) {
|
|
|
471
459
|
service, app, model, modelRuntime, modelPropertyName, objectType,
|
|
472
460
|
otherPropertyNames, others, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName,
|
|
473
461
|
} = context
|
|
474
|
-
const eventName =
|
|
462
|
+
const eventName = modelName + 'Copied'
|
|
475
463
|
const triggerName = 'copyOnParentCopy_' + service.name + '_' + modelName
|
|
476
464
|
if(!service.triggers[triggerName]) service.triggers[triggerName] = []
|
|
477
465
|
service.triggers[triggerName].push(new TriggerDefinition({
|
package/propertyEvents.js
CHANGED
|
@@ -6,7 +6,7 @@ function defineSetEvent(config, context, generateId) {
|
|
|
6
6
|
const {
|
|
7
7
|
service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames, reverseRelationWord
|
|
8
8
|
} = context
|
|
9
|
-
const eventName =
|
|
9
|
+
const eventName = modelName + 'Set'
|
|
10
10
|
service.events[eventName] = new EventDefinition({
|
|
11
11
|
name: eventName,
|
|
12
12
|
properties: {
|
|
@@ -28,7 +28,7 @@ function defineUpdatedEvent(config, context, generateId) {
|
|
|
28
28
|
const {
|
|
29
29
|
service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames, reverseRelationWord
|
|
30
30
|
} = context
|
|
31
|
-
const eventName =
|
|
31
|
+
const eventName = modelName + 'Updated'
|
|
32
32
|
service.events[eventName] = new EventDefinition({
|
|
33
33
|
name: eventName,
|
|
34
34
|
properties: {
|
|
@@ -50,7 +50,7 @@ function defineTransferredEvent(config, context, generateId) {
|
|
|
50
50
|
const {
|
|
51
51
|
service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames, reverseRelationWord
|
|
52
52
|
} = context
|
|
53
|
-
const eventName =
|
|
53
|
+
const eventName = modelName + 'Transferred'
|
|
54
54
|
service.events[eventName] = new EventDefinition({
|
|
55
55
|
name: eventName,
|
|
56
56
|
properties: {
|
|
@@ -80,7 +80,7 @@ function defineResetEvent(config, context, generateId) {
|
|
|
80
80
|
const {
|
|
81
81
|
service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames, reverseRelationWord
|
|
82
82
|
} = context
|
|
83
|
-
const eventName =
|
|
83
|
+
const eventName = modelName + 'Reset'
|
|
84
84
|
service.events[eventName] = new EventDefinition({
|
|
85
85
|
name: eventName,
|
|
86
86
|
properties: {
|
|
@@ -43,10 +43,10 @@ function defineObjectView(config, context, external = true) {
|
|
|
43
43
|
const accessControl = external
|
|
44
44
|
&& (config.singleAccessControl || config.readAccessControl || config.writeAccessControl)
|
|
45
45
|
prepareAccessControl(accessControl, otherPropertyNames)
|
|
46
|
-
const viewName = config.name
|
|
47
|
-
|
|
46
|
+
const viewName = config.name
|
|
47
|
+
|| ((config.prefix ? config.prefix + modelName : modelName[0].toLowerCase() + modelName.slice(1)) + (config.suffix || ''))
|
|
48
48
|
model.crud.read = viewName
|
|
49
|
-
service.
|
|
49
|
+
service.view({
|
|
50
50
|
name: viewName,
|
|
51
51
|
properties: {
|
|
52
52
|
...viewProperties
|
|
@@ -56,6 +56,7 @@ function defineObjectView(config, context, external = true) {
|
|
|
56
56
|
},
|
|
57
57
|
internal: !external,
|
|
58
58
|
access: external && (config.singleAccess || config.readAccess),
|
|
59
|
+
global: config.globalView,
|
|
59
60
|
accessControl,
|
|
60
61
|
daoPath(properties, { client, context }) {
|
|
61
62
|
const typeAndIdParts = extractTypeAndIdParts(otherPropertyNames, properties)
|
|
@@ -79,7 +80,7 @@ function defineRangeViews(config, context, external = true) {
|
|
|
79
80
|
propsUpperCase.slice(1).join('And') + context.partialReverseRelationWord + pluralize(modelName)
|
|
80
81
|
console.log("DEFINE RANGE VIEW", viewName, combination)
|
|
81
82
|
const identifiers = createIdentifiersProperties(combination)
|
|
82
|
-
service.
|
|
83
|
+
service.view({
|
|
83
84
|
name: viewName,
|
|
84
85
|
properties: {
|
|
85
86
|
...identifiers,
|
|
@@ -104,7 +105,7 @@ function getSetFunction( validators, validationContext, config, context) {
|
|
|
104
105
|
service, app, model, objectType, modelRuntime,
|
|
105
106
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
106
107
|
} = context
|
|
107
|
-
const eventName =
|
|
108
|
+
const eventName = modelName + 'Set'
|
|
108
109
|
return async function execute(properties, { client, service }, emit) {
|
|
109
110
|
const identifiers = extractIdentifiersWithTypes(otherPropertyNames, properties)
|
|
110
111
|
const id = generateAnyId(otherPropertyNames, properties)
|
|
@@ -127,7 +128,7 @@ function defineSetAction(config, context) {
|
|
|
127
128
|
service, app, model, objectType,
|
|
128
129
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
129
130
|
} = context
|
|
130
|
-
const actionName = 'set' +
|
|
131
|
+
const actionName = 'set' + modelName
|
|
131
132
|
model.crud.create = actionName
|
|
132
133
|
const accessControl = config.setAccessControl || config.writeAccessControl
|
|
133
134
|
prepareAccessControl(accessControl, otherPropertyNames)
|
|
@@ -144,6 +145,7 @@ function defineSetAction(config, context) {
|
|
|
144
145
|
const validators = App.validation.getValidators(action, service, action)
|
|
145
146
|
const validationContext = { source: action, action }
|
|
146
147
|
action.execute = getSetFunction( validators, validationContext, config, context)
|
|
148
|
+
if(service.actions[actionName]) throw new Error('Action ' + actionName + ' already defined')
|
|
147
149
|
service.actions[actionName] = action
|
|
148
150
|
}
|
|
149
151
|
|
|
@@ -152,7 +154,7 @@ function defineSetTrigger(config, context) {
|
|
|
152
154
|
service, app, model, objectType,
|
|
153
155
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
154
156
|
} = context
|
|
155
|
-
const actionName = 'set' +
|
|
157
|
+
const actionName = 'set' + modelName
|
|
156
158
|
const triggerName = `${service.name}_${actionName}`
|
|
157
159
|
const trigger = new TriggerDefinition({
|
|
158
160
|
name: triggerName,
|
|
@@ -165,6 +167,7 @@ function defineSetTrigger(config, context) {
|
|
|
165
167
|
const validators = App.validation.getValidators(trigger, service, trigger)
|
|
166
168
|
const validationContext = { source: trigger, trigger }
|
|
167
169
|
trigger.execute = getSetFunction( validators, validationContext, config, context)
|
|
170
|
+
if(service.triggers[triggerName]) throw new Error('Trigger ' + triggerName + ' already defined')
|
|
168
171
|
service.triggers[triggerName] = [trigger]
|
|
169
172
|
}
|
|
170
173
|
|
|
@@ -173,7 +176,7 @@ function getUpdateFunction( validators, validationContext, config, context) {
|
|
|
173
176
|
service, app, model, modelRuntime, objectType,
|
|
174
177
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
175
178
|
} = context
|
|
176
|
-
const eventName =
|
|
179
|
+
const eventName = modelName + 'Updated'
|
|
177
180
|
return async function execute(properties, {client, service}, emit) {
|
|
178
181
|
const identifiers = extractIdentifiersWithTypes(otherPropertyNames, properties)
|
|
179
182
|
const id = generateAnyId(otherPropertyNames, properties)
|
|
@@ -199,7 +202,7 @@ function defineUpdateAction(config, context) {
|
|
|
199
202
|
service, app, model, modelRuntime, objectType,
|
|
200
203
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
201
204
|
} = context
|
|
202
|
-
const actionName = 'update' +
|
|
205
|
+
const actionName = 'update' + modelName
|
|
203
206
|
model.crud.update = actionName
|
|
204
207
|
const accessControl = config.updateAccessControl || config.writeAccessControl
|
|
205
208
|
prepareAccessControl(accessControl, otherPropertyNames)
|
|
@@ -218,6 +221,7 @@ function defineUpdateAction(config, context) {
|
|
|
218
221
|
const validators = App.validation.getValidators(action, service, action)
|
|
219
222
|
const validationContext = { source: action, action }
|
|
220
223
|
action.execute = getUpdateFunction( validators, validationContext, config, context)
|
|
224
|
+
if(service.actions[actionName]) throw new Error('Action ' + actionName + ' already defined')
|
|
221
225
|
service.actions[actionName] = action
|
|
222
226
|
}
|
|
223
227
|
|
|
@@ -226,7 +230,7 @@ function defineUpdateTrigger(config, context) {
|
|
|
226
230
|
service, app, model, modelRuntime, objectType,
|
|
227
231
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
228
232
|
} = context
|
|
229
|
-
const actionName = 'update' +
|
|
233
|
+
const actionName = 'update' + modelName
|
|
230
234
|
const triggerName = `${service.name}_${actionName}`
|
|
231
235
|
const trigger = new TriggerDefinition({
|
|
232
236
|
name: triggerName,
|
|
@@ -241,6 +245,7 @@ function defineUpdateTrigger(config, context) {
|
|
|
241
245
|
const validators = App.validation.getValidators(trigger, service, trigger)
|
|
242
246
|
const validationContext = { source: trigger, trigger }
|
|
243
247
|
trigger.execute = getUpdateFunction( validators, validationContext, config, context)
|
|
248
|
+
if(service.triggers[triggerName]) throw new Error('Trigger ' + triggerName + ' already defined')
|
|
244
249
|
service.triggers[triggerName] = [trigger]
|
|
245
250
|
}
|
|
246
251
|
|
|
@@ -249,7 +254,7 @@ function getSetOrUpdateFunction( validators, validationContext, config, context)
|
|
|
249
254
|
service, app, model, modelRuntime, objectType,
|
|
250
255
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
251
256
|
} = context
|
|
252
|
-
const eventName =
|
|
257
|
+
const eventName = modelName + 'Updated'
|
|
253
258
|
return async function execute(properties, { client, service }, emit) {
|
|
254
259
|
const identifiers = extractIdentifiersWithTypes(otherPropertyNames, properties)
|
|
255
260
|
const id = generateAnyId(otherPropertyNames, properties)
|
|
@@ -275,8 +280,8 @@ function defineSetOrUpdateAction(config, context) {
|
|
|
275
280
|
service, app, model, modelRuntime, objectType,
|
|
276
281
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
277
282
|
} = context
|
|
278
|
-
const eventName =
|
|
279
|
-
const actionName = 'setOrUpdate' +
|
|
283
|
+
const eventName = modelName + 'Updated'
|
|
284
|
+
const actionName = 'setOrUpdate' + modelName
|
|
280
285
|
model.crud.createOrUpdate = actionName
|
|
281
286
|
const accessControl = config.setOrUpdateAccessControl || config.writeAccessControl
|
|
282
287
|
prepareAccessControl(accessControl, otherPropertyNames)
|
|
@@ -295,6 +300,7 @@ function defineSetOrUpdateAction(config, context) {
|
|
|
295
300
|
const validators = App.validation.getValidators(action, service, action)
|
|
296
301
|
const validationContext = { source: action, action }
|
|
297
302
|
action.execute = getSetOrUpdateFunction( validators, validationContext, config, context)
|
|
303
|
+
if(service.actions[actionName]) throw new Error('Action ' + actionName + ' already defined')
|
|
298
304
|
service.actions[actionName] = action
|
|
299
305
|
}
|
|
300
306
|
|
|
@@ -303,7 +309,7 @@ function defineSetOrUpdateTrigger(config, context) {
|
|
|
303
309
|
service, app, model, modelRuntime, objectType,
|
|
304
310
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName
|
|
305
311
|
} = context
|
|
306
|
-
const actionName = 'setOrUpdate' +
|
|
312
|
+
const actionName = 'setOrUpdate' + modelName
|
|
307
313
|
const triggerName = `${service.name}_${actionName}`
|
|
308
314
|
const trigger = new TriggerDefinition({
|
|
309
315
|
name: triggerName,
|
|
@@ -318,6 +324,7 @@ function defineSetOrUpdateTrigger(config, context) {
|
|
|
318
324
|
const validators = App.validation.getValidators(trigger, service, trigger)
|
|
319
325
|
const validationContext = { source: trigger, trigger }
|
|
320
326
|
trigger.execute = getSetOrUpdateFunction( validators, validationContext, config, context)
|
|
327
|
+
if(service.triggers[triggerName]) throw new Error('Trigger ' + triggerName + ' already defined')
|
|
321
328
|
service.triggers[triggerName] = [trigger]
|
|
322
329
|
}
|
|
323
330
|
|
|
@@ -346,7 +353,7 @@ function defineResetAction(config, context) {
|
|
|
346
353
|
service, modelRuntime, modelPropertyName, identifiers, objectType,
|
|
347
354
|
otherPropertyNames, joinedOthersPropertyName, modelName, joinedOthersClassName, model
|
|
348
355
|
} = context
|
|
349
|
-
const actionName = 'reset' +
|
|
356
|
+
const actionName = 'reset' + modelName
|
|
350
357
|
model.crud.delete = actionName
|
|
351
358
|
const accessControl = config.resetAccessControl || config.writeAccessControl
|
|
352
359
|
prepareAccessControl(accessControl, otherPropertyNames)
|
|
@@ -368,7 +375,7 @@ function defineResetTrigger(config, context) {
|
|
|
368
375
|
service, modelRuntime, modelPropertyName, identifiers, objectType,
|
|
369
376
|
otherPropertyNames, joinedOthersPropertyName, modelName, joinedOthersClassName, model
|
|
370
377
|
} = context
|
|
371
|
-
const actionName = 'reset' +
|
|
378
|
+
const actionName = 'reset' + modelName
|
|
372
379
|
const triggerName = `${service.name}_${actionName}`
|
|
373
380
|
service.triggers[triggerName] = [new TriggerDefinition({
|
|
374
381
|
name: triggerName,
|
package/singularRelationUtils.js
CHANGED
|
@@ -17,12 +17,12 @@ function defineView(config, context, external = true) {
|
|
|
17
17
|
validation: ['nonEmpty']
|
|
18
18
|
})
|
|
19
19
|
}
|
|
20
|
-
const viewName = config.name
|
|
21
|
-
|
|
20
|
+
const viewName = config.name
|
|
21
|
+
|| ((config.prefix ? config.prefix + modelName : modelName[0].toLowerCase() + modelName.slice(1)) + (config.suffix || ''))
|
|
22
22
|
model.crud.read = viewName
|
|
23
23
|
const accessControl = external && (config.readAccessControl || config.writeAccessControl)
|
|
24
24
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
25
|
-
service.
|
|
25
|
+
service.view({
|
|
26
26
|
name: viewName,
|
|
27
27
|
properties: {
|
|
28
28
|
...viewProperties
|
|
@@ -31,6 +31,7 @@ function defineView(config, context, external = true) {
|
|
|
31
31
|
type: model,
|
|
32
32
|
},
|
|
33
33
|
internal: !external,
|
|
34
|
+
global: config.globalView,
|
|
34
35
|
access: external && (config.readAccess || config.writeAccess),
|
|
35
36
|
accessControl,
|
|
36
37
|
daoPath(properties, { client, context }) {
|
|
@@ -47,7 +48,7 @@ function getSetFunction( validators, validationContext, config, context) {
|
|
|
47
48
|
service, app, model, objectType,
|
|
48
49
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
49
50
|
} = context
|
|
50
|
-
const eventName =
|
|
51
|
+
const eventName = modelName + 'Set'
|
|
51
52
|
async function execute(properties, { client, service }, emit) {
|
|
52
53
|
const idParts = extractIdParts(otherPropertyNames, properties)
|
|
53
54
|
const id = idParts.length > 1 ? idParts.map(p => JSON.stringify(p)).join(':') : idParts[0]
|
|
@@ -70,7 +71,7 @@ function defineSetAction(config, context) {
|
|
|
70
71
|
service, app, model, objectType,
|
|
71
72
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
72
73
|
} = context
|
|
73
|
-
const actionName = 'set' +
|
|
74
|
+
const actionName = 'set' + modelName
|
|
74
75
|
model.crud.create = actionName
|
|
75
76
|
const accessControl = config.setAccessControl || config.writeAccessControl
|
|
76
77
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
@@ -87,6 +88,7 @@ function defineSetAction(config, context) {
|
|
|
87
88
|
const validators = App.validation.getValidators(action, service, action)
|
|
88
89
|
const validationContext = { source: action, action }
|
|
89
90
|
action.execute = getSetFunction( validators, validationContext, config, context)
|
|
91
|
+
if(service.actions[actionName]) throw new Error('Action ' + actionName + ' already defined')
|
|
90
92
|
service.actions[actionName] = action
|
|
91
93
|
}
|
|
92
94
|
|
|
@@ -95,7 +97,7 @@ function defineSetTrigger(config, context) {
|
|
|
95
97
|
service, app, model, objectType,
|
|
96
98
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
97
99
|
} = context
|
|
98
|
-
const actionName = 'set' +
|
|
100
|
+
const actionName = 'set' + modelName
|
|
99
101
|
const triggerName = `${service.name}_${actionName}`
|
|
100
102
|
const trigger = new TriggerDefinition({
|
|
101
103
|
name: triggerName,
|
|
@@ -108,6 +110,7 @@ function defineSetTrigger(config, context) {
|
|
|
108
110
|
const validators = App.validation.getValidators(trigger, service, trigger)
|
|
109
111
|
const validationContext = { source: trigger, trigger }
|
|
110
112
|
trigger.execute = getSetFunction( validators, validationContext, config, context)
|
|
113
|
+
if(service.triggers[triggerName]) throw new Error('Trigger ' + triggerName + ' already defined')
|
|
111
114
|
service.triggers[triggerName] = [trigger]
|
|
112
115
|
}
|
|
113
116
|
|
|
@@ -116,7 +119,7 @@ function getUpdateFunction( validators, validationContext, config, context) {
|
|
|
116
119
|
service, app, model, modelRuntime, objectType,
|
|
117
120
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
118
121
|
} = context
|
|
119
|
-
const eventName =
|
|
122
|
+
const eventName = modelName + 'Updated'
|
|
120
123
|
return async function execute(properties, { client, service }, emit) {
|
|
121
124
|
const identifiers = extractIdentifiers(otherPropertyNames, properties)
|
|
122
125
|
const id = generateId(otherPropertyNames, properties)
|
|
@@ -143,7 +146,7 @@ function defineUpdateAction(config, context) {
|
|
|
143
146
|
service, app, model, modelRuntime, objectType,
|
|
144
147
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
145
148
|
} = context
|
|
146
|
-
const actionName = 'update' +
|
|
149
|
+
const actionName = 'update' + modelName
|
|
147
150
|
model.crud.update = actionName
|
|
148
151
|
const accessControl = config.updateAccessControl || config.writeAccessControl
|
|
149
152
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
@@ -162,6 +165,7 @@ function defineUpdateAction(config, context) {
|
|
|
162
165
|
const validators = App.validation.getValidators(action, service, action)
|
|
163
166
|
const validationContext = { source: action, action }
|
|
164
167
|
action.execute = getUpdateFunction( validators, validationContext, config, context)
|
|
168
|
+
if(service.actions[actionName]) throw new Error('Action ' + actionName + ' already defined')
|
|
165
169
|
service.actions[actionName] = action
|
|
166
170
|
}
|
|
167
171
|
|
|
@@ -170,7 +174,7 @@ function defineUpdateTrigger(config, context) {
|
|
|
170
174
|
service, app, model, modelRuntime, objectType,
|
|
171
175
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
172
176
|
} = context
|
|
173
|
-
const actionName = 'update' +
|
|
177
|
+
const actionName = 'update' + modelName
|
|
174
178
|
const triggerName = `${service.name}_${actionName}`
|
|
175
179
|
const trigger = new TriggerDefinition({
|
|
176
180
|
name: triggerName,
|
|
@@ -185,6 +189,7 @@ function defineUpdateTrigger(config, context) {
|
|
|
185
189
|
const validators = App.validation.getValidators(trigger, service, trigger)
|
|
186
190
|
const validationContext = { source: trigger, trigger }
|
|
187
191
|
trigger.execute = getUpdateFunction( validators, validationContext, config, context)
|
|
192
|
+
if(service.triggers[triggerName]) throw new Error('Trigger ' + triggerName + ' already defined')
|
|
188
193
|
service.triggers[triggerName] = [trigger]
|
|
189
194
|
}
|
|
190
195
|
|
|
@@ -193,7 +198,7 @@ function getSetOrUpdateFunction( validators, validationContext, config, context)
|
|
|
193
198
|
service, app, model, modelRuntime, objectType,
|
|
194
199
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
195
200
|
} = context
|
|
196
|
-
const eventName =
|
|
201
|
+
const eventName = modelName + 'Updated'
|
|
197
202
|
return async function execute(properties, { client, service }, emit) {
|
|
198
203
|
const identifiers = extractIdentifiers(otherPropertyNames, properties)
|
|
199
204
|
const id = generateId(otherPropertyNames, properties)
|
|
@@ -218,7 +223,7 @@ function defineSetOrUpdateAction(config, context) {
|
|
|
218
223
|
service, app, model, modelRuntime, objectType,
|
|
219
224
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
220
225
|
} = context
|
|
221
|
-
const actionName = 'setOrUpdate' +
|
|
226
|
+
const actionName = 'setOrUpdate' + modelName
|
|
222
227
|
model.crud.createOrUpdate = actionName
|
|
223
228
|
const accessControl = config.updateAccessControl || config.writeAccessControl
|
|
224
229
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
@@ -237,6 +242,7 @@ function defineSetOrUpdateAction(config, context) {
|
|
|
237
242
|
const validators = App.validation.getValidators(action, service, action)
|
|
238
243
|
const validationContext = { source: action, action }
|
|
239
244
|
action.execute = getSetOrUpdateFunction( validators, validationContext, config, context)
|
|
245
|
+
if(service.actions[actionName]) throw new Error('Action ' + actionName + ' already defined')
|
|
240
246
|
service.actions[actionName] = action
|
|
241
247
|
}
|
|
242
248
|
|
|
@@ -245,7 +251,7 @@ function defineSetOrUpdateTrigger(config, context) {
|
|
|
245
251
|
service, app, model, modelRuntime, objectType,
|
|
246
252
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
247
253
|
} = context
|
|
248
|
-
const actionName = 'setOrUpdate' +
|
|
254
|
+
const actionName = 'setOrUpdate' + modelName
|
|
249
255
|
const triggerName = `${service.name}_${actionName}`
|
|
250
256
|
const trigger = new TriggerDefinition({
|
|
251
257
|
name: triggerName,
|
|
@@ -260,6 +266,7 @@ function defineSetOrUpdateTrigger(config, context) {
|
|
|
260
266
|
const validators = App.validation.getValidators(trigger, service, trigger)
|
|
261
267
|
const validationContext = { source: trigger, trigger }
|
|
262
268
|
trigger.execute = getSetOrUpdateFunction( validators, validationContext, config, context)
|
|
269
|
+
if(service.triggers[triggerName]) throw new Error('Trigger ' + triggerName + ' already defined')
|
|
263
270
|
service.triggers[triggerName] = [trigger]
|
|
264
271
|
}
|
|
265
272
|
|
|
@@ -268,7 +275,7 @@ function getResetFunction( validators, validationContext, config, context) {
|
|
|
268
275
|
service, modelRuntime, modelPropertyName, objectType,
|
|
269
276
|
otherPropertyNames, joinedOthersPropertyName, modelName, joinedOthersClassName, model, others, writeableProperties
|
|
270
277
|
} = context
|
|
271
|
-
const eventName =
|
|
278
|
+
const eventName = modelName + 'Reset'
|
|
272
279
|
return async function execute(properties, { client, service }, emit) {
|
|
273
280
|
const identifiers = extractIdentifiers(otherPropertyNames, properties)
|
|
274
281
|
const id = generateId(otherPropertyNames, properties)
|
|
@@ -288,7 +295,7 @@ function defineResetAction(config, context) {
|
|
|
288
295
|
service, modelRuntime, modelPropertyName, objectType,
|
|
289
296
|
otherPropertyNames, joinedOthersPropertyName, modelName, joinedOthersClassName, model, others, writeableProperties
|
|
290
297
|
} = context
|
|
291
|
-
const actionName = 'reset' +
|
|
298
|
+
const actionName = 'reset' + modelName
|
|
292
299
|
model.crud.delete = actionName
|
|
293
300
|
const accessControl = config.resetAccessControl || config.writeAccessControl
|
|
294
301
|
prepareAccessControl(accessControl, otherPropertyNames, others)
|
|
@@ -309,6 +316,7 @@ function defineResetAction(config, context) {
|
|
|
309
316
|
const validators = App.validation.getValidators(action, service, action)
|
|
310
317
|
const validationContext = { source: action, action }
|
|
311
318
|
action.execute = getResetFunction( validators, validationContext, config, context)
|
|
319
|
+
if(service.actions[actionName]) throw new Error('Action ' + actionName + ' already defined')
|
|
312
320
|
service.actions[actionName] = action
|
|
313
321
|
}
|
|
314
322
|
|
|
@@ -317,7 +325,7 @@ function defineResetTrigger(config, context) {
|
|
|
317
325
|
service, modelRuntime, modelPropertyName, objectType,
|
|
318
326
|
otherPropertyNames, joinedOthersPropertyName, modelName, joinedOthersClassName, model, others, writeableProperties
|
|
319
327
|
} = context
|
|
320
|
-
const actionName = 'reset' +
|
|
328
|
+
const actionName = 'reset' + modelName
|
|
321
329
|
const triggerName = `${service.name}_${actionName}`
|
|
322
330
|
const trigger = new TriggerDefinition({
|
|
323
331
|
name: triggerName,
|
|
@@ -334,6 +342,7 @@ function defineResetTrigger(config, context) {
|
|
|
334
342
|
const validators = App.validation.getValidators(trigger, service, trigger)
|
|
335
343
|
const validationContext = { source: trigger, trigger }
|
|
336
344
|
trigger.execute = getResetFunction( validators, validationContext, config, context)
|
|
345
|
+
if(service.triggers[triggerName]) throw new Error('Trigger ' + triggerName + ' already defined')
|
|
337
346
|
service.triggers[triggerName] = [trigger]
|
|
338
347
|
}
|
|
339
348
|
|