@live-change/framework 0.8.34 → 0.8.35

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.
@@ -62,18 +62,24 @@ async function update(changes, service, app, force) {
62
62
  if(!table) throw new Error("only function indexes are possible without table")
63
63
  if(index.multi) {
64
64
  if(Array.isArray(index.property)) throw new Error("multi indexes on multiple properties are not supported!")
65
- const func = async function(input, output, { table, property }) {
66
- const values = (obj) => {
65
+ const properties = (Array.isArray(index.property) ? index.property : [index.property]).map(p => p.split('.'))
66
+ const func = async function(input, output, { table, properties }) {
67
+ const value = (obj, property) => {
67
68
  let at = obj
68
69
  for(const p of property) at = at && at[p]
69
70
  if(at === undefined) return []
70
71
  if(Array.isArray(at)) return at.map(v => JSON.stringify(v))
71
72
  return [at]
72
73
  }
74
+ const keys = (obj, id) => {
75
+ const values = value(obj, properties[id])
76
+ if(id === properties.length - 1) return values
77
+ return values.flatMap(v => keys(obj, id + 1).map(k => v + ':' + k))
78
+ }
73
79
  await input.table(table).onChange((obj, oldObj) => {
74
80
  if(obj && oldObj) {
75
- let pointers = obj && new Set(values(obj))
76
- let oldPointers = oldObj && new Set(values(oldObj))
81
+ let pointers = obj && new Set(keys(obj))
82
+ let oldPointers = oldObj && new Set(keys(oldObj))
77
83
  for(let pointer of pointers) {
78
84
  if(!!oldPointers.has(pointer)) output.change({ id: pointer+'_'+obj.id, to: obj.id }, null)
79
85
  }
@@ -81,16 +87,16 @@ async function update(changes, service, app, force) {
81
87
  if(!!pointers.has(pointer)) output.change(null, { id: pointer+'_'+obj.id, to: obj.id })
82
88
  }
83
89
  } else if(obj) {
84
- values(obj).forEach(v => output.change({ id: v+'_'+obj.id, to: obj.id }, null))
90
+ keys(obj).forEach(k => output.change({ id: k+'_'+obj.id, to: obj.id }, null))
85
91
  } else if(oldObj) {
86
- values(oldObj).forEach(v => output.change(null, { id: v+'_'+oldObj.id, to: oldObj.id }))
92
+ keys(oldObj).forEach(k => output.change(null, { id: k+'_'+oldObj.id, to: oldObj.id }))
87
93
  }
88
94
  })
89
95
  }
90
96
  const functionCode = `(${func})`
91
97
  ;(globalThis.compiledFunctions = globalThis.compiledFunctions || {})[functionCode] = func
92
98
  await dao.requestWithSettings(indexRequestSettings, ['database', 'createIndex'], database, indexName,
93
- functionCode, { property: index.property.split('.'), table }, index.storage ?? {})
99
+ functionCode, { properties, table }, index.storage ?? {})
94
100
  } else {
95
101
  if(!table) throw new Error("only function indexes are possible without table")
96
102
  const properties = (Array.isArray(index.property) ? index.property : [index.property]).map(p => p.split('.'))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/framework",
3
- "version": "0.8.34",
3
+ "version": "0.8.35",
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.8.34",
26
- "@live-change/uid": "^0.8.34"
25
+ "@live-change/dao": "^0.8.35",
26
+ "@live-change/uid": "^0.8.35"
27
27
  },
28
- "gitHead": "40e61928bf43b35352c76fc135f36a2d8bd76c4a"
28
+ "gitHead": "90fbb746dc7270895daf17b437ca48c0b0a01c01"
29
29
  }