@live-change/relations-plugin 0.9.108 → 0.9.110
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/src/changeTriggers.js +24 -11
- package/src/utilsAny.ts +2 -1
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.110",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@live-change/framework": "^0.9.
|
|
25
|
+
"@live-change/framework": "^0.9.110",
|
|
26
26
|
"pluralize": "^8.0.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"typedoc-plugin-markdown": "^4.6.3",
|
|
31
31
|
"typedoc-plugin-rename-defaults": "^0.7.3"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "856dd2e63a9c18efd85943caf04d898847c09805"
|
|
34
34
|
}
|
package/src/changeTriggers.js
CHANGED
|
@@ -2,10 +2,13 @@ import { extractObjectData, extractIdentifiers } from "./dataUtils.js"
|
|
|
2
2
|
import {
|
|
3
3
|
TriggerDefinition
|
|
4
4
|
} from "@live-change/framework"
|
|
5
|
+
import assert from "assert"
|
|
5
6
|
|
|
6
7
|
async function fireChangeTriggers(context, objectType, identifiers, object, oldData, data,
|
|
7
|
-
trigger
|
|
8
|
+
trigger) {
|
|
8
9
|
const { service, modelName, app } = context
|
|
10
|
+
//if(!trigger) trigger = (...args) => app.trigger(...args)
|
|
11
|
+
assert(trigger, "trigger is required")
|
|
9
12
|
const changeType = data ? (oldData ? 'update' : 'create') : 'delete'
|
|
10
13
|
//console.log("FIRE CHANGE TRIGGERS", { context, objectType, identifiers, object, oldData, data })
|
|
11
14
|
//console.trace()
|
|
@@ -31,6 +34,12 @@ async function iterateChildren(context, propertyName, path, cb) {
|
|
|
31
34
|
service, modelRuntime, objectType: myType, writeableProperties, modelName,
|
|
32
35
|
reverseRelationWord, app, otherPropertyNames, sameIdAsParent
|
|
33
36
|
} = context
|
|
37
|
+
assert(modelRuntime, "modelRuntime is required")
|
|
38
|
+
assert(modelRuntime().sortedIndexRangeGet, "sortedIndexRangeGet is required")
|
|
39
|
+
assert(modelRuntime().get, "get is required")
|
|
40
|
+
assert(propertyName, "propertyName is required")
|
|
41
|
+
assert(path, "path is required")
|
|
42
|
+
assert(cb, "cb is required")
|
|
34
43
|
if(sameIdAsParent) {
|
|
35
44
|
const entity = await modelRuntime().get(path)
|
|
36
45
|
if(entity) await cb(entity)
|
|
@@ -47,15 +56,16 @@ async function iterateChildren(context, propertyName, path, cb) {
|
|
|
47
56
|
//console.log("BUCKET", bucket)
|
|
48
57
|
if(bucket.length === 0) break
|
|
49
58
|
gt = bucket[bucket.length - 1].id
|
|
50
|
-
const
|
|
51
|
-
await Promise.all(
|
|
59
|
+
const triggerPromises = bucket.map(entity => cb({ ...entity, id: entity.to }))
|
|
60
|
+
await Promise.all(triggerPromises)
|
|
52
61
|
} while (bucket.length === bucketSize)
|
|
53
62
|
}
|
|
54
63
|
}
|
|
55
64
|
|
|
56
65
|
|
|
57
66
|
async function triggerDeleteOnParentDeleteTriggers(
|
|
58
|
-
context, propertyName, path, objectType, object, emit) {
|
|
67
|
+
context, propertyName, path, objectType, object, emit, trigger) {
|
|
68
|
+
assert(trigger, "trigger is required")
|
|
59
69
|
const {
|
|
60
70
|
service, modelRuntime, objectType: myType, writeableProperties, modelName,
|
|
61
71
|
reverseRelationWord, otherPropertyNames
|
|
@@ -66,7 +76,7 @@ async function triggerDeleteOnParentDeleteTriggers(
|
|
|
66
76
|
found = true
|
|
67
77
|
const identifiers = extractIdentifiers(otherPropertyNames, entity)
|
|
68
78
|
await fireChangeTriggers(context, myType, identifiers, entity.id,
|
|
69
|
-
extractObjectData(writeableProperties, entity, {}), null)
|
|
79
|
+
extractObjectData(writeableProperties, entity, {}), null, trigger)
|
|
70
80
|
})
|
|
71
81
|
if (found) {
|
|
72
82
|
const eventName = modelName + 'DeleteByOwner'
|
|
@@ -80,12 +90,15 @@ async function triggerDeleteOnParentDeleteTriggers(
|
|
|
80
90
|
|
|
81
91
|
function registerParentDeleteTriggers(context, config) {
|
|
82
92
|
const {
|
|
83
|
-
service, parentsTypes, otherPropertyNames,
|
|
93
|
+
service, parentsTypes, otherPropertyNames, isAny
|
|
84
94
|
} = context
|
|
85
|
-
if(parentsTypes) {
|
|
95
|
+
if(parentsTypes && !isAny) {
|
|
86
96
|
for (const index in parentsTypes) {
|
|
97
|
+
assert(otherPropertyNames.length === parentsTypes.length, "otherPropertyNames.length === parentsTypes.length")
|
|
87
98
|
const otherType = parentsTypes[index]
|
|
88
99
|
const propertyName = otherPropertyNames[index]
|
|
100
|
+
assert(propertyName, "propertyName is required")
|
|
101
|
+
assert(otherType, "otherType is required")
|
|
89
102
|
const triggerName = 'delete' + otherType[0].toUpperCase() + otherType.slice(1)
|
|
90
103
|
if (!service.triggers[triggerName]) service.triggers[triggerName] = []
|
|
91
104
|
service.triggers[triggerName].push(new TriggerDefinition({
|
|
@@ -96,9 +109,9 @@ function registerParentDeleteTriggers(context, config) {
|
|
|
96
109
|
}
|
|
97
110
|
},
|
|
98
111
|
timeout: config.parentDeleteTriggerTimeout,
|
|
99
|
-
async execute({object}, {client, service}, emit) {
|
|
112
|
+
async execute({object}, {client, service, trigger}, emit) {
|
|
100
113
|
await triggerDeleteOnParentDeleteTriggers(context, propertyName, [object],
|
|
101
|
-
otherType, object, emit)
|
|
114
|
+
otherType, object, emit, trigger)
|
|
102
115
|
}
|
|
103
116
|
}))
|
|
104
117
|
}
|
|
@@ -116,10 +129,10 @@ function registerParentDeleteTriggers(context, config) {
|
|
|
116
129
|
}
|
|
117
130
|
},
|
|
118
131
|
timeout: config.parentDeleteTriggerTimeout,
|
|
119
|
-
async execute({ objectType, object }, {client, service}, emit) {
|
|
132
|
+
async execute({ objectType, object }, {client, service, trigger}, emit) {
|
|
120
133
|
for(const propertyName of otherPropertyNames) {
|
|
121
134
|
await triggerDeleteOnParentDeleteTriggers(context, propertyName, [objectType, object],
|
|
122
|
-
objectType, object, emit)
|
|
135
|
+
objectType, object, emit, trigger)
|
|
123
136
|
}
|
|
124
137
|
}
|
|
125
138
|
}))
|
package/src/utilsAny.ts
CHANGED
|
@@ -117,6 +117,7 @@ interface AnyRelationContext {
|
|
|
117
117
|
partialReverseRelationWord?: string,
|
|
118
118
|
identifiers?: Record<string, PropertyDefinition<PropertyDefinitionSpecification>>
|
|
119
119
|
sameIdAsParent?: boolean
|
|
120
|
+
isAny: true
|
|
120
121
|
}
|
|
121
122
|
|
|
122
123
|
export function processModelsAnyAnnotation<PreparedConfig extends AnyRelationConfig>
|
|
@@ -190,7 +191,7 @@ export function processModelsAnyAnnotation<PreparedConfig extends AnyRelationCon
|
|
|
190
191
|
annotation,
|
|
191
192
|
service, app, model, originalModelProperties, modelProperties, modelPropertyName, modelRuntime,
|
|
192
193
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others,
|
|
193
|
-
objectType, parentsTypes, otherPossibleTypes
|
|
194
|
+
objectType, parentsTypes, otherPossibleTypes, isAny: true
|
|
194
195
|
}
|
|
195
196
|
|
|
196
197
|
cb(config, context)
|