@live-change/framework 0.7.19 → 0.7.21
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/lib/updaters/database.js +46 -41
- package/package.json +8 -8
package/lib/updaters/database.js
CHANGED
|
@@ -53,56 +53,61 @@ async function update(changes, service, app, force) {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
if(index.function) {
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
const functionCode = `(${index.function})`
|
|
57
|
+
;(globalThis.compiledFunctions = globalThis.compiledFunctions || {})[functionCode] = index.function
|
|
58
|
+
await dao.request(['database', 'createIndex'], database, indexName, functionCode, { ...(index.parameters || {}) }, index.storage ?? {})
|
|
58
59
|
} else {
|
|
59
60
|
if(!table) throw new Error("only function indexes are possible without table")
|
|
60
61
|
if(index.multi) {
|
|
61
62
|
if(Array.isArray(index.property)) throw new Error("multi indexes on multiple properties are not supported!")
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
63
|
+
const func = async function(input, output, { table, property }) {
|
|
64
|
+
const values = (obj) => {
|
|
65
|
+
let at = obj
|
|
66
|
+
for(const p of property) at = at && at[p]
|
|
67
|
+
if(at === undefined) return []
|
|
68
|
+
if(Array.isArray(at)) return at.map(v => JSON.stringify(v))
|
|
69
|
+
return [at]
|
|
70
|
+
}
|
|
71
|
+
await input.table(table).onChange((obj, oldObj) => {
|
|
72
|
+
if(obj && oldObj) {
|
|
73
|
+
let pointers = obj && new Set(values(obj))
|
|
74
|
+
let oldPointers = oldObj && new Set(values(oldObj))
|
|
75
|
+
for(let pointer of pointers) {
|
|
76
|
+
if(!!oldPointers.has(pointer)) output.change({ id: pointer+'_'+obj.id, to: obj.id }, null)
|
|
70
77
|
}
|
|
71
|
-
|
|
72
|
-
if(obj
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
for(let pointer of oldPointers) {
|
|
79
|
-
if(!!pointers.has(pointer)) output.change(null, { id: pointer+'_'+obj.id, to: obj.id })
|
|
80
|
-
}
|
|
81
|
-
} else if(obj) {
|
|
82
|
-
values(obj).forEach(v => output.change({ id: v+'_'+obj.id, to: obj.id }, null))
|
|
83
|
-
} else if(oldObj) {
|
|
84
|
-
values(oldObj).forEach(v => output.change(null, { id: v+'_'+oldObj.id, to: oldObj.id }))
|
|
85
|
-
}
|
|
86
|
-
})
|
|
78
|
+
for(let pointer of oldPointers) {
|
|
79
|
+
if(!!pointers.has(pointer)) output.change(null, { id: pointer+'_'+obj.id, to: obj.id })
|
|
80
|
+
}
|
|
81
|
+
} else if(obj) {
|
|
82
|
+
values(obj).forEach(v => output.change({ id: v+'_'+obj.id, to: obj.id }, null))
|
|
83
|
+
} else if(oldObj) {
|
|
84
|
+
values(oldObj).forEach(v => output.change(null, { id: v+'_'+oldObj.id, to: oldObj.id }))
|
|
87
85
|
}
|
|
88
|
-
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
const functionCode = `(${func})`
|
|
89
|
+
;(globalThis.compiledFunctions = globalThis.compiledFunctions || {})[functionCode] = func
|
|
90
|
+
await dao.requestWithSettings(indexRequestSettings, ['database', 'createIndex'], database, indexName,
|
|
91
|
+
functionCode, { property: index.property.split('.'), table }, index.storage ?? {})
|
|
89
92
|
} else {
|
|
90
93
|
if(!table) throw new Error("only function indexes are possible without table")
|
|
91
94
|
const properties = (Array.isArray(index.property) ? index.property : [index.property]).map(p => p.split('.'))
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
95
|
+
const func = async function(input, output, { table, properties }) {
|
|
96
|
+
const mapper = (obj) => ({
|
|
97
|
+
id: properties.map(path => {
|
|
98
|
+
let at = obj
|
|
99
|
+
for(const p of path) at = at && at[p]
|
|
100
|
+
return at === undefined ? '' : JSON.stringify(at)
|
|
101
|
+
}).join(':')+'_'+obj.id,
|
|
102
|
+
to: obj.id
|
|
103
|
+
})
|
|
104
|
+
await input.table(table).onChange((obj, oldObj) =>
|
|
105
|
+
output.change(obj && mapper(obj), oldObj && mapper(oldObj)) )
|
|
106
|
+
}
|
|
107
|
+
const functionCode = `(${func})`
|
|
108
|
+
;(globalThis.compiledFunctions = globalThis.compiledFunctions || {})[functionCode] = func
|
|
109
|
+
await dao.requestWithSettings(indexRequestSettings, ['database', 'createIndex'], database, indexName,
|
|
110
|
+
functionCode, { properties, table }, index.storage ?? {})
|
|
106
111
|
}
|
|
107
112
|
}
|
|
108
113
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/framework",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.21",
|
|
4
4
|
"description": "Live Change Framework - ultimate solution for real time mobile/web apps",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
},
|
|
22
22
|
"homepage": "https://github.com/live-change/live-change-framework",
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@live-change/dao": "0.5.
|
|
25
|
-
"@live-change/dao-websocket": "0.5.
|
|
26
|
-
"@live-change/db": "0.6.
|
|
27
|
-
"@live-change/db-store-level": "0.6.
|
|
28
|
-
"@live-change/db-store-lmdb": "0.6.
|
|
24
|
+
"@live-change/dao": "0.5.17",
|
|
25
|
+
"@live-change/dao-websocket": "0.5.17",
|
|
26
|
+
"@live-change/db": "0.6.5",
|
|
27
|
+
"@live-change/db-store-level": "0.6.5",
|
|
28
|
+
"@live-change/db-store-lmdb": "0.6.5",
|
|
29
29
|
"@live-change/sockjs": "0.4.1",
|
|
30
|
-
"@live-change/uid": "0.7.
|
|
30
|
+
"@live-change/uid": "^0.7.21",
|
|
31
31
|
"cookie": "^0.4.1",
|
|
32
32
|
"express": "^4.18.1",
|
|
33
33
|
"os-service": "^2.2.0",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"tape": "^5.3.2",
|
|
36
36
|
"websocket": "^1.0.34"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "34a57ec8676ad6a671154b8359e82fa97052ded3"
|
|
39
39
|
}
|