@live-change/relations-plugin 0.8.31 → 0.8.33
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/changeTriggers.js +8 -3
- package/itemOf.js +1 -1
- package/package.json +3 -3
- package/pluralRelationAnyUtils.js +4 -3
- package/pluralRelationUtils.js +4 -0
- package/saveAuthor.js +39 -1
- package/utils.js +0 -15
package/changeTriggers.js
CHANGED
|
@@ -8,7 +8,8 @@ async function fireChangeTriggers(context, objectType, identifiers, object, oldD
|
|
|
8
8
|
const changeType = data ? (oldData ? 'update' : 'create') : 'delete'
|
|
9
9
|
await Promise.all([
|
|
10
10
|
app.trigger({
|
|
11
|
-
type: changeType+service.name[0].toUpperCase()+service.name.slice(1)+'_'+modelName,
|
|
11
|
+
type: changeType + service.name[0].toUpperCase() + service.name.slice(1) + '_' + modelName,
|
|
12
|
+
}, {
|
|
12
13
|
objectType,
|
|
13
14
|
object,
|
|
14
15
|
identifiers,
|
|
@@ -16,7 +17,8 @@ async function fireChangeTriggers(context, objectType, identifiers, object, oldD
|
|
|
16
17
|
oldData
|
|
17
18
|
}),
|
|
18
19
|
app.trigger({
|
|
19
|
-
type: changeType+'Object',
|
|
20
|
+
type: changeType + 'Object',
|
|
21
|
+
}, {
|
|
20
22
|
objectType,
|
|
21
23
|
object,
|
|
22
24
|
identifiers,
|
|
@@ -146,7 +148,8 @@ async function copyObject(context, objectType, object, parentType, parent, ident
|
|
|
146
148
|
|
|
147
149
|
const newId = app.generateUid()
|
|
148
150
|
app.trigger({
|
|
149
|
-
type: 'copy'+service.name[0].toUpperCase()+service.name.slice(1)+'_'+modelName,
|
|
151
|
+
type: 'copy' + service.name[0].toUpperCase() + service.name.slice(1) + '_' + modelName,
|
|
152
|
+
}, {
|
|
150
153
|
objectType,
|
|
151
154
|
object: newId,
|
|
152
155
|
from: object,
|
|
@@ -155,6 +158,7 @@ async function copyObject(context, objectType, object, parentType, parent, ident
|
|
|
155
158
|
})
|
|
156
159
|
app.trigger({
|
|
157
160
|
type: 'copyObject',
|
|
161
|
+
}, {
|
|
158
162
|
objectType,
|
|
159
163
|
object: newId,
|
|
160
164
|
from: object,
|
|
@@ -187,6 +191,7 @@ async function triggerCopyOnParentCopyTriggers(
|
|
|
187
191
|
//console.log("COPY TRIGGER", myType, fromId, objectType, object, from, identifiers, data)
|
|
188
192
|
const copyTriggerResults = await app.trigger({
|
|
189
193
|
type: 'copyOnParentCopy'+service.name[0].toUpperCase()+service.name.slice(1)+'_'+modelName,
|
|
194
|
+
}, {
|
|
190
195
|
objectType: myType,
|
|
191
196
|
object: fromId,
|
|
192
197
|
parentType: objectType,
|
package/itemOf.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
defineProperties, defineIndexes,
|
|
3
3
|
processModelsAnnotation, addAccessControlParents,
|
|
4
|
-
defineDeleteByOwnerEvents, defineParentDeleteTriggers, defineParentCopyTriggers
|
|
4
|
+
defineDeleteByOwnerEvents, defineParentDeleteTriggers, defineParentCopyTriggers
|
|
5
5
|
} from './utils.js'
|
|
6
6
|
|
|
7
7
|
import {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/relations-plugin",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.33",
|
|
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.8.
|
|
25
|
+
"@live-change/framework": "^0.8.33",
|
|
26
26
|
"pluralize": "^8.0.0"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "98ff6f9c09e5fc1f408010df6cc8038eff571276"
|
|
29
29
|
}
|
|
@@ -134,11 +134,13 @@ function getUpdateFunction( validators, validationContext, config, context) {
|
|
|
134
134
|
const eventName = joinedOthersPropertyName + context.reverseRelationWord + modelName + 'Updated'
|
|
135
135
|
return async function execute(properties, { client, service }, emit) {
|
|
136
136
|
const id = properties[modelPropertyName]
|
|
137
|
-
if(!id) throw 'no_id'
|
|
137
|
+
if(!id) throw new Error('no_id')
|
|
138
138
|
const entity = await modelRuntime().get(id)
|
|
139
139
|
if(!entity) throw 'not_found'
|
|
140
140
|
const entityTypeAndIdParts = extractTypeAndIdParts(otherPropertyNames, entity)
|
|
141
141
|
const typeAndIdParts = extractTypeAndIdParts(otherPropertyNames, properties)
|
|
142
|
+
console.log("UPDATE MATCH", entityTypeAndIdParts, '===', typeAndIdParts,
|
|
143
|
+
'=>', JSON.stringify(entityTypeAndIdParts) === JSON.stringify(typeAndIdParts))
|
|
142
144
|
if(JSON.stringify(entityTypeAndIdParts) !== JSON.stringify(typeAndIdParts)) {
|
|
143
145
|
throw 'not_authorized'
|
|
144
146
|
}
|
|
@@ -147,7 +149,7 @@ function getUpdateFunction( validators, validationContext, config, context) {
|
|
|
147
149
|
extractObjectData(writeableProperties, properties, entity),
|
|
148
150
|
App.computeUpdates(model, { ...entity, ...properties }, { client, service })
|
|
149
151
|
)
|
|
150
|
-
await App.validation.validate({ ...identifiers, ...data }, validators,
|
|
152
|
+
await App.validation.validate({ ...identifiers, ...data, [modelPropertyName]: id }, validators,
|
|
151
153
|
validationContext)
|
|
152
154
|
await fireChangeTriggers(context, objectType, identifiers, id,
|
|
153
155
|
extractObjectData(writeableProperties, entity, {}), data)
|
|
@@ -158,7 +160,6 @@ function getUpdateFunction( validators, validationContext, config, context) {
|
|
|
158
160
|
data
|
|
159
161
|
})
|
|
160
162
|
}
|
|
161
|
-
|
|
162
163
|
}
|
|
163
164
|
|
|
164
165
|
function defineUpdateAction(config, context) {
|
package/pluralRelationUtils.js
CHANGED
|
@@ -319,6 +319,7 @@ function getCopyFunction( validators, validationContext, config, context) {
|
|
|
319
319
|
validationContext)
|
|
320
320
|
app.trigger({
|
|
321
321
|
type: 'copy'+service.name[0].toUpperCase()+service.name.slice(1)+'_'+modelName,
|
|
322
|
+
}, {
|
|
322
323
|
objectType,
|
|
323
324
|
object: newId,
|
|
324
325
|
from: id,
|
|
@@ -327,6 +328,7 @@ function getCopyFunction( validators, validationContext, config, context) {
|
|
|
327
328
|
}),
|
|
328
329
|
app.trigger({
|
|
329
330
|
type: 'copyObject',
|
|
331
|
+
}, {
|
|
330
332
|
objectType,
|
|
331
333
|
object: newId,
|
|
332
334
|
from: id,
|
|
@@ -466,6 +468,7 @@ function defineCopyOnParentCopyTrigger(config, context) {
|
|
|
466
468
|
const newId = app.generateUid()
|
|
467
469
|
app.trigger({
|
|
468
470
|
type: 'copy'+service.name[0].toUpperCase()+service.name.slice(1)+'_'+modelName,
|
|
471
|
+
}, {
|
|
469
472
|
objectType,
|
|
470
473
|
object: newId,
|
|
471
474
|
from: object,
|
|
@@ -474,6 +477,7 @@ function defineCopyOnParentCopyTrigger(config, context) {
|
|
|
474
477
|
})
|
|
475
478
|
app.trigger({
|
|
476
479
|
type: 'copyObject',
|
|
480
|
+
}, {
|
|
477
481
|
objectType,
|
|
478
482
|
object: newId,
|
|
479
483
|
from: object,
|
package/saveAuthor.js
CHANGED
|
@@ -1,4 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
PropertyDefinition
|
|
3
|
+
} from "@live-change/framework"
|
|
4
|
+
|
|
5
|
+
export function defineAuthorProperties() {
|
|
6
|
+
return {
|
|
7
|
+
authorType: new PropertyDefinition({
|
|
8
|
+
type: String,
|
|
9
|
+
validation: ['nonEmpty'],
|
|
10
|
+
default: (_props, context) => context.client.user ? 'user_User' : 'session_Session'
|
|
11
|
+
}),
|
|
12
|
+
author: new PropertyDefinition({
|
|
13
|
+
type: String,
|
|
14
|
+
validation: ['nonEmpty'],
|
|
15
|
+
default: (_props, context) => context.client.user ? context.client.user : context.client.session
|
|
16
|
+
})
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function defineUpdaterProperties() {
|
|
21
|
+
return {
|
|
22
|
+
updaterType: new PropertyDefinition({
|
|
23
|
+
type: String,
|
|
24
|
+
validation: ['nonEmpty'],
|
|
25
|
+
default: (_props, context) => context.client.user ? 'user_User' : 'session_Session'
|
|
26
|
+
}),
|
|
27
|
+
updater: new PropertyDefinition({
|
|
28
|
+
type: String,
|
|
29
|
+
validation: ['nonEmpty'],
|
|
30
|
+
default: (_props, context) => context.client.user ? context.client.user : context.client.session
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
}
|
|
2
34
|
|
|
3
35
|
export default function(service, app) {
|
|
4
36
|
for(let modelName in service.models) {
|
|
@@ -9,5 +41,11 @@ export default function(service, app) {
|
|
|
9
41
|
...defineAuthorProperties()
|
|
10
42
|
}
|
|
11
43
|
}
|
|
44
|
+
if(model.saveUpdater) {
|
|
45
|
+
model.properties = {
|
|
46
|
+
...model.properties,
|
|
47
|
+
...defineUpdaterProperties()
|
|
48
|
+
}
|
|
49
|
+
}
|
|
12
50
|
}
|
|
13
51
|
}
|
package/utils.js
CHANGED
|
@@ -41,21 +41,6 @@ export function defineProperties(model, types, names) {
|
|
|
41
41
|
return identifiers
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
export function defineAuthorProperties() {
|
|
45
|
-
return {
|
|
46
|
-
authorType: new PropertyDefinition({
|
|
47
|
-
type: String,
|
|
48
|
-
validation: ['nonEmpty'],
|
|
49
|
-
default: (_props, context) => context.client.user ? 'user_User' : 'session_Session'
|
|
50
|
-
}),
|
|
51
|
-
author: new PropertyDefinition({
|
|
52
|
-
type: String,
|
|
53
|
-
validation: ['nonEmpty'],
|
|
54
|
-
default: (_props, context) => context.client.user ? context.client.user : context.client.session
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
44
|
export function defineIndex(model, what, props) {
|
|
60
45
|
console.log("DEFINE INDEX", model.name, what, props)
|
|
61
46
|
model.indexes['by' + what] = new IndexDefinition({
|