@live-change/relations-plugin 0.9.9 → 0.9.11
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/package.json +3 -3
- package/propertyEvents.js +4 -2
- package/singularRelationUtils.js +8 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/relations-plugin",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.11",
|
|
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.9.
|
|
25
|
+
"@live-change/framework": "^0.9.11",
|
|
26
26
|
"pluralize": "^8.0.0"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "a1bd367ae175f0937d999577f1b10bf10e7df0fb"
|
|
29
29
|
}
|
package/propertyEvents.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PropertyDefinition, ViewDefinition, IndexDefinition, ActionDefinition, EventDefinition
|
|
3
3
|
} from '@live-change/framework'
|
|
4
|
+
import { generateId } from './utils.js'
|
|
4
5
|
|
|
5
6
|
function defineSetEvent(config, context, generateId) {
|
|
6
7
|
const {
|
|
@@ -78,7 +79,8 @@ function defineTransferredEvent(config, context, generateId) {
|
|
|
78
79
|
|
|
79
80
|
function defineResetEvent(config, context, generateId) {
|
|
80
81
|
const {
|
|
81
|
-
service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames, reverseRelationWord
|
|
82
|
+
service, modelRuntime, joinedOthersPropertyName, modelName, otherPropertyNames, reverseRelationWord,
|
|
83
|
+
modelPropertyName
|
|
82
84
|
} = context
|
|
83
85
|
const eventName = modelName + 'Reset'
|
|
84
86
|
service.events[eventName] = new EventDefinition({
|
|
@@ -89,7 +91,7 @@ function defineResetEvent(config, context, generateId) {
|
|
|
89
91
|
}
|
|
90
92
|
},
|
|
91
93
|
execute({ identifiers }) {
|
|
92
|
-
const id = generateId(otherPropertyNames, identifiers)
|
|
94
|
+
const id = identifiers[modelPropertyName] ?? generateId(otherPropertyNames, identifiers)
|
|
93
95
|
return modelRuntime().delete(id)
|
|
94
96
|
}
|
|
95
97
|
})
|
package/singularRelationUtils.js
CHANGED
|
@@ -278,22 +278,26 @@ function getResetFunction( validators, validationContext, config, context) {
|
|
|
278
278
|
const eventName = modelName + 'Reset'
|
|
279
279
|
return async function execute(properties, { client, service }, emit) {
|
|
280
280
|
const identifiers = extractIdentifiers(otherPropertyNames, properties)
|
|
281
|
-
const id = generateId(otherPropertyNames, properties)
|
|
281
|
+
const id = properties[modelPropertyName] ?? generateId(otherPropertyNames, properties)
|
|
282
282
|
const entity = await modelRuntime().get(id)
|
|
283
283
|
if (!entity) throw new Error('not_found')
|
|
284
284
|
await fireChangeTriggers(context, objectType, identifiers, id,
|
|
285
285
|
entity ? extractObjectData(writeableProperties, entity, {}) : null, null)
|
|
286
286
|
emit({
|
|
287
287
|
type: eventName,
|
|
288
|
-
identifiers
|
|
288
|
+
identifiers: {
|
|
289
|
+
...identifiers,
|
|
290
|
+
[modelPropertyName]: id
|
|
291
|
+
}
|
|
289
292
|
})
|
|
290
293
|
}
|
|
291
294
|
}
|
|
292
295
|
|
|
293
296
|
function defineResetAction(config, context) {
|
|
294
297
|
const {
|
|
295
|
-
service, modelRuntime, modelPropertyName, objectType,
|
|
296
|
-
otherPropertyNames, joinedOthersPropertyName, modelName,
|
|
298
|
+
service, modelRuntime, modelPropertyName, objectType, identifiers,
|
|
299
|
+
otherPropertyNames, joinedOthersPropertyName, modelName,
|
|
300
|
+
joinedOthersClassName, model, others, writeableProperties
|
|
297
301
|
} = context
|
|
298
302
|
const actionName = 'reset' + modelName
|
|
299
303
|
model.crud.delete = actionName
|