@live-change/framework
Advanced tools
Comparing version 0.4.28 to 0.4.29
@@ -175,3 +175,22 @@ const utils = require("../utils.js") | ||
name: genName("Range"), | ||
properties: {}, | ||
properties: { | ||
gt: { | ||
type: String, | ||
}, | ||
lt: { | ||
type: String, | ||
}, | ||
gte: { | ||
type: String, | ||
}, | ||
lte: { | ||
type: String, | ||
}, | ||
limit: { | ||
type: Number | ||
}, | ||
reverse: { | ||
type: Boolean | ||
} | ||
}, | ||
returns: { | ||
@@ -178,0 +197,0 @@ type: Array, |
const ReactiveDao = require("@live-change/dao") | ||
const utils = require('../utils.js') | ||
@@ -25,7 +26,10 @@ class ReaderModel { | ||
indexRangePath(index, range = {}) { | ||
indexRangePath(index, range = {}, pathRange = null) { | ||
if(typeof range != 'object' || Array.isArray(range)) { | ||
const values = Array.isArray(range) ? range : [range] | ||
const str = values.map(value => value === undefined ? '' : JSON.stringify(value)).join(':')+'_' | ||
return this.indexRangePath(index,{ gte: str, lte: str+'\xFF\xFF\xFF\xFF' }) | ||
const prefix = values.map(value => value === undefined ? '' : JSON.stringify(value)).join(':') | ||
if(pathRange) { | ||
return this.indexRangePath(index, utils.prefixRange(pathRange, prefix, prefix)) | ||
} | ||
return this.indexRangePath(index,{ gte: prefix+'_', lte: prefix+'_\xFF\xFF\xFF\xFF' }) | ||
} | ||
@@ -78,7 +82,10 @@ return ['database', 'query', this.service.databaseName, `(${ | ||
sortedIndexRangePath(index, range = {}) { | ||
sortedIndexRangePath(index, range = {}, pathRange = null) { | ||
if(typeof range != 'object' || Array.isArray(range)) { | ||
const values = Array.isArray(range) ? range : [range] | ||
const str = values.map(value => value === undefined ? '' : JSON.stringify(value)).join(':')+'_' | ||
return this.sortedIndexRangePath(index,{ gte: str, lte: str+'\xFF\xFF\xFF\xFF' }) | ||
const prefix = values.map(value => value === undefined ? '' : JSON.stringify(value)).join(':') | ||
if(pathRange) { | ||
return this.sortedIndexRangePath(index, utils.prefixRange(pathRange, prefix, prefix)) | ||
} | ||
return this.sortedIndexRangePath(index,{ gte: str+'_', lte: str+'_\xFF\xFF\xFF\xFF' }) | ||
} | ||
@@ -137,7 +144,10 @@ return ['database', 'query', this.service.databaseName, `(${ | ||
indexObjectPath(index, range = {}) { | ||
indexObjectPath(index, range = {}, pathRange = null) { | ||
if(typeof range != 'object' || Array.isArray(range)) { | ||
const values = Array.isArray(range) ? range : [range] | ||
const str = values.map(value => value === undefined ? '' : JSON.stringify(value)).join(':')+'_' | ||
return this.indexObjectPath(index,{ gte: str, lte: str+'\xFF\xFF\xFF\xFF' }) | ||
const prefix = values.map(value => value === undefined ? '' : JSON.stringify(value)).join(':') | ||
if(pathRange) { | ||
return this.indexObjectPath(index, utils.prefixRange(pathRange, prefix, prefix)) | ||
} | ||
return this.indexObjectPath(index,{ gte: prefix+'_', lte: prefix+'_\xFF\xFF\xFF\xFF' }) | ||
} | ||
@@ -168,7 +178,10 @@ return ['database', 'queryObject', this.service.databaseName, `(${ | ||
indexRangeDelete(index, range = {}) { | ||
indexRangeDelete(index, range = {}, pathRange = null) { | ||
if(typeof range != 'object' || Array.isArray(range)) { | ||
const values = Array.isArray(range) ? range : [range] | ||
const str = values.map(value => value === undefined ? '' : JSON.stringify(value)).join(':')+'_' | ||
return this.indexRangeDelete(index,{ gte: str, lte: str+'\xFF\xFF\xFF\xFF' }) | ||
const prefix = values.map(value => value === undefined ? '' : JSON.stringify(value)).join(':') | ||
if(pathRange) { | ||
return this.indexRangeDelete(index, utils.prefixRange(pathRange, prefix, prefix)) | ||
} | ||
return this.indexRangeDelete(index,{ gte: prefix+'_', lte: prefix+'_\xFF\xFF\xFF\xFF' }) | ||
} | ||
@@ -184,7 +197,10 @@ this.service.dao.request(['database', 'query'], this.service.databaseName, `(${ | ||
indexRangeUpdate(index, range = {}, update) { | ||
indexRangeUpdate(index, update, range = {}, pathRange = null) { | ||
if(typeof range != 'object' || Array.isArray(range)) { | ||
const values = Array.isArray(range) ? range : [range] | ||
const str = values.map(value => value === undefined ? '' : JSON.stringify(value)).join(':')+'_' | ||
return this.indexRangeDelete(index,{ gte: str, lte: str+'\xFF\xFF\xFF\xFF' }, update) | ||
const prefix = values.map(value => value === undefined ? '' : JSON.stringify(value)).join(':') | ||
if(pathRange) { | ||
return this.indexRangeUpdate(index, update, utils.prefixRange(pathRange, prefix, prefix)) | ||
} | ||
return this.indexRangeUpdate(index, update,{ gte: prefix+'_', lte: prefix+'_\xFF\xFF\xFF\xFF' }) | ||
} | ||
@@ -191,0 +207,0 @@ const operations = Array.isArray(update) ? update : [{ op:'merge', property: null, value: update }] |
@@ -353,2 +353,3 @@ const Model = require("./Model.js") | ||
if(this.commited) { | ||
if(events.length == 0) return | ||
this.service.dao.request(['database', 'putLog'], this.service.databaseName, | ||
@@ -362,2 +363,3 @@ this.service.name+'_events', { type: 'bucket', events, ...this.flags }) | ||
this.commited = true | ||
if(this.emittedEvents.length == 0) return [] | ||
let allEvents = [] | ||
@@ -370,3 +372,3 @@ for(const [service, events] of this.emittedEvents.keys()) { | ||
await Promise.all(promises) | ||
return events | ||
return allEvents | ||
} | ||
@@ -402,2 +404,3 @@ } | ||
if(this.commited) { | ||
if(events.length == 0) return | ||
this.service.dao.request(['database', 'putLog'], this.service.databaseName, | ||
@@ -410,2 +413,3 @@ 'events', { type: 'bucket', events, ...this.flags }) | ||
this.commited = true | ||
if(this.emittedEvents.length == 0) return [] | ||
await this.service.dao.request(['database', 'putLog'], this.service.databaseName, | ||
@@ -412,0 +416,0 @@ 'events', { type: 'bucket', events: this.emittedEvents, ...this.flags }) |
@@ -220,5 +220,29 @@ const fs = require("fs") | ||
function prefixRange({ gt, lt, gte, lte, limit, reverse }, prefix, from = "") { | ||
function getPrefix(id) { | ||
if(id.length > from.length) { | ||
if(id.slice(0, from.length) != from) throw new Error("id does not match prefix") | ||
id = id.slice(from.length) | ||
} | ||
if(id === '') return `${prefix}:` | ||
if(id === '\xFF\xFF\xFF\xFF') return `${prefix}:\xFF\xFF\xFF\xFF` | ||
return `${prefix}:"${id}"_` | ||
} | ||
return { | ||
gt: (typeof gt == 'string') ? getPrefix(gt)+"\xFF\xFF\xFF\xFF" : undefined, | ||
lt: (typeof lt == 'string') ? getPrefix(lt) : undefined, | ||
gte: (typeof gte == 'string') ? getPrefix(gte) : (typeof gt == 'string' ? undefined : `${prefix}`), | ||
lte: (typeof lte == 'string') | ||
? getPrefix(lte)+"\xFF\xFF\xFF\xFF" | ||
: (typeof lt == 'string' ? undefined : `${prefix}:\xFF\xFF\xFF\xFF`), | ||
limit, | ||
reverse | ||
} | ||
} | ||
module.exports = { | ||
typeName, toJSON, setDifference, mapDifference, crudChanges, loadJson, saveJson, exists, | ||
getProperty, setProperty, getField, setField, isObject, mergeDeep, generateDefault | ||
getProperty, setProperty, getField, setField, isObject, mergeDeep, generateDefault, | ||
prefixRange | ||
} |
@@ -86,2 +86,6 @@ | ||
} | ||
push(object) { | ||
if(this.disposed) return | ||
this.handleEvent(object) | ||
} | ||
@@ -88,0 +92,0 @@ } |
{ | ||
"name": "@live-change/framework", | ||
"version": "0.4.28", | ||
"version": "0.4.29", | ||
"description": "Live Change Framework - ultimate solution for real time mobile/web apps", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
162460
4468