@live-change/relations-plugin 0.9.46 → 0.9.48
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/singularRelationUtils.js +1 -1
- package/utilsAny.js +24 -13
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.48",
|
|
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.48",
|
|
26
26
|
"pluralize": "^8.0.0"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "87d012a548f6170fb78b565a111644eddc571a32"
|
|
29
29
|
}
|
package/singularRelationUtils.js
CHANGED
|
@@ -138,7 +138,7 @@ export function getSetFunction( validators, validationContext, config, context)
|
|
|
138
138
|
otherPropertyNames, joinedOthersPropertyName, modelName, writeableProperties, joinedOthersClassName, others
|
|
139
139
|
} = context
|
|
140
140
|
const eventName = modelName + 'Set'
|
|
141
|
-
async function execute(properties, { client, service }, emit) {
|
|
141
|
+
async function execute(properties, { client, service, trigger }, emit) {
|
|
142
142
|
const idParts = extractIdParts(otherPropertyNames, properties)
|
|
143
143
|
const id = idParts.length > 1 ? idParts.map(p => JSON.stringify(p)).join(':') : idParts[0]
|
|
144
144
|
const identifiers = extractIdentifiers(otherPropertyNames, properties)
|
package/utilsAny.js
CHANGED
|
@@ -242,14 +242,19 @@ export function defineAnyTypeIndexes(config, context, useId = false) {
|
|
|
242
242
|
function: async function(input, output, { tableName }) {
|
|
243
243
|
const table = await input.table(tableName)
|
|
244
244
|
await table.onChange(async (obj, oldObj) => {
|
|
245
|
-
const id = obj?.id ?? oldObj?.id
|
|
245
|
+
const id = obj?.id ?? oldObj?.id
|
|
246
246
|
const typeJson = id.slice(0, id.indexOf(':'))
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
247
|
+
try {
|
|
248
|
+
const type = JSON.parse(typeJson)
|
|
249
|
+
const count = await table.count({ gte: typeJson+':', lte: type+'_\xFF\xFF\xFF\xFF', limit: 1 })
|
|
250
|
+
if(count > 0) {
|
|
251
|
+
await output.put({ id: type })
|
|
252
|
+
} else {
|
|
253
|
+
await output.delete({ id: type })
|
|
254
|
+
}
|
|
255
|
+
} catch(e) {
|
|
256
|
+
output.debug('typeJson', typeJson, 'id', id)
|
|
257
|
+
console.error("Error parsing typeJson", typeJson, e)
|
|
253
258
|
}
|
|
254
259
|
})
|
|
255
260
|
},
|
|
@@ -269,12 +274,18 @@ export function defineAnyTypeIndexes(config, context, useId = false) {
|
|
|
269
274
|
const index = await input.index(indexName)
|
|
270
275
|
await index.onChange(async (obj, oldObj) => {
|
|
271
276
|
const id = obj?.id ?? oldObj?.id
|
|
272
|
-
const
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
await
|
|
276
|
-
|
|
277
|
-
|
|
277
|
+
const typeJson = id.slice(0, id.indexOf(':'))
|
|
278
|
+
try {
|
|
279
|
+
const type = JSON.parse(typeJson)
|
|
280
|
+
const count = await index.count({ gte: type+':', lte: typeJson+'_\xFF\xFF\xFF\xFF', limit: 1 })
|
|
281
|
+
if(count > 0) {
|
|
282
|
+
await output.put({ id: type })
|
|
283
|
+
} else {
|
|
284
|
+
await output.delete({ id: type })
|
|
285
|
+
}
|
|
286
|
+
} catch(e) {
|
|
287
|
+
output.debug('typeJson', typeJson, 'id', id)
|
|
288
|
+
console.error("Error parsing typeJson", typeJson, e)
|
|
278
289
|
}
|
|
279
290
|
})
|
|
280
291
|
},
|