@live-change/framework 0.9.19 → 0.9.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 +13 -9
- package/package.json +4 -4
package/lib/updaters/database.js
CHANGED
|
@@ -83,7 +83,7 @@ async function update(changes, service, app, force) {
|
|
|
83
83
|
// if(Array.isArray(index.property)) throw new Error("multi indexes on multiple properties are not supported!")
|
|
84
84
|
const properties = (Array.isArray(index.property) ? index.property : [index.property])
|
|
85
85
|
.map(propSet => (Array.isArray(propSet) ? propSet : [propSet]).map(p => p.split('.')))
|
|
86
|
-
const func = async function(input, output, { table, properties }) {
|
|
86
|
+
const func = async function(input, output, { table, properties, hash }) {
|
|
87
87
|
const value = (obj, property) => {
|
|
88
88
|
let at = obj
|
|
89
89
|
for(const p of property) at = at && at[p]
|
|
@@ -101,32 +101,36 @@ async function update(changes, service, app, force) {
|
|
|
101
101
|
let pointers = obj && new Set(keys(obj))
|
|
102
102
|
let oldPointers = oldObj && new Set(keys(oldObj))
|
|
103
103
|
for(let pointer of pointers) if(!oldPointers.has(pointer)) {
|
|
104
|
-
output.change({ id: pointer+'_'+obj.id, to: obj.id }, null)
|
|
104
|
+
output.change({ id: pointer+'_'+(hash ? sha1(obj.id, 'base64') : obj.id), to: obj.id }, null)
|
|
105
105
|
}
|
|
106
106
|
for(let pointer of oldPointers) if(!pointers.has(pointer)) {
|
|
107
|
-
output.change(null, { id: pointer+'_'+obj.id, to: obj.id })
|
|
107
|
+
output.change(null, { id: pointer+'_'+(hash ? sha1(obj.id, 'base64') : obj.id), to: obj.id })
|
|
108
108
|
}
|
|
109
109
|
} else if(obj) {
|
|
110
|
-
keys(obj).forEach(k => output.change({
|
|
110
|
+
keys(obj).forEach(k => output.change({
|
|
111
|
+
id: k+'_'+(hash ? sha1(obj.id, 'base64') : obj.id),
|
|
112
|
+
to: obj.id }, null))
|
|
111
113
|
} else if(oldObj) {
|
|
112
|
-
keys(oldObj).forEach(k => output.change(null, {
|
|
114
|
+
keys(oldObj).forEach(k => output.change(null, {
|
|
115
|
+
id: k+'_'+(hash ? sha1(obj.id, 'base64') : obj.id),
|
|
116
|
+
to: oldObj.id }))
|
|
113
117
|
}
|
|
114
118
|
})
|
|
115
119
|
}
|
|
116
120
|
const functionCode = `(${func})`
|
|
117
121
|
;(globalThis.compiledFunctions = globalThis.compiledFunctions || {})[functionCode] = func
|
|
118
122
|
await dao.requestWithSettings(indexRequestSettings, ['database', 'createIndex'], database, indexName,
|
|
119
|
-
functionCode, { properties, table }, index.storage ?? {})
|
|
123
|
+
functionCode, { properties, table, hash: index.hash }, index.storage ?? {})
|
|
120
124
|
} else {
|
|
121
125
|
if(!table) throw new Error("only function indexes are possible without table")
|
|
122
126
|
const properties = (Array.isArray(index.property) ? index.property : [index.property]).map(p => p.split('.'))
|
|
123
|
-
const func = async function(input, output, { table,
|
|
127
|
+
const func = async function(input, output, { table, properties, hash }) {
|
|
124
128
|
const mapper = (obj) => ({
|
|
125
129
|
id: properties.map(path => {
|
|
126
130
|
let at = obj
|
|
127
131
|
for(const p of path) at = at && at[p]
|
|
128
132
|
return at === undefined ? '' : JSON.stringify(at)
|
|
129
|
-
}).join(':')+'_'+obj.id,
|
|
133
|
+
}).join(':')+'_'+(hash ? sha1(obj.id, 'base64') : obj.id),
|
|
130
134
|
to: obj.id
|
|
131
135
|
})
|
|
132
136
|
await input.table(table).onChange((obj, oldObj) =>
|
|
@@ -135,7 +139,7 @@ async function update(changes, service, app, force) {
|
|
|
135
139
|
const functionCode = `(${func})`
|
|
136
140
|
;(globalThis.compiledFunctions = globalThis.compiledFunctions || {})[functionCode] = func
|
|
137
141
|
await dao.requestWithSettings(indexRequestSettings, ['database', 'createIndex'], database, indexName,
|
|
138
|
-
functionCode, { properties, table }, index.storage ?? {})
|
|
142
|
+
functionCode, { properties, table, hash: index.hash }, index.storage ?? {})
|
|
139
143
|
}
|
|
140
144
|
}
|
|
141
145
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/framework",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.21",
|
|
4
4
|
"description": "Live Change Framework - ultimate solution for real time mobile/web apps",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"homepage": "https://github.com/live-change/live-change-stack",
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@live-change/dao": "^0.9.
|
|
26
|
-
"@live-change/uid": "^0.9.
|
|
25
|
+
"@live-change/dao": "^0.9.21",
|
|
26
|
+
"@live-change/uid": "^0.9.21"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "362e325d1c636f9c0f2fb6432e209c5c56f46919"
|
|
29
29
|
}
|