@live-change/framework
Advanced tools
Comparing version 0.2.11 to 0.2.12
@@ -211,3 +211,11 @@ const ReactiveDao = require("@live-change/dao") | ||
) | ||
await this.dao.request(['database', 'put'], this.databaseName, commandsTable, { ...data }) | ||
//await this.dao.request(['database', 'put'], this.databaseName, commandsTable, { ...data }) | ||
await this.dao.request(['database', 'query', this.databaseName, `(${ | ||
async (input, output, { commandsTable, data }) => { | ||
const value = await input.table(commandsTable).object(data.id).get() | ||
if(!value) { | ||
return await output.table(commandsTable).put(data) | ||
} | ||
} | ||
})`, { commandsTable, data }]) | ||
let observer | ||
@@ -214,0 +222,0 @@ return new Promise((resolve, reject) => { |
@@ -13,3 +13,3 @@ const getAccessMethod = require("./accessMethod.js") | ||
console.error("NOT AUTHORIZED ACTION", module.name, actionName) | ||
throw new Error("notAuthorized") | ||
throw "notAuthorized" | ||
} | ||
@@ -28,4 +28,4 @@ return oldExec.apply(action, args) | ||
if(!(await access(...args))) { | ||
console.error("NOT AUTHORIZED ACTION", module.name, viewName) | ||
throw new Error("notAuthorized") | ||
console.error("NOT AUTHORIZED VIEW", module.name, viewName) | ||
throw "notAuthorized" | ||
} | ||
@@ -37,4 +37,4 @@ return oldObservable.apply(view, args) | ||
if(!(await access(...args))) { | ||
console.error("NOT AUTHORIZED ACTION", module.name, viewName) | ||
throw new Error("notAuthorized") | ||
console.error("NOT AUTHORIZED VIEW", module.name, viewName) | ||
throw "notAuthorized" | ||
} | ||
@@ -41,0 +41,0 @@ return oldGet.apply(view, args) |
@@ -1,60 +0,12 @@ | ||
const ReactiveDao = require("@live-change/dao") | ||
const ReaderModel = require("./ReaderModel.js") | ||
class ForeignModel { | ||
class ForeignModel extends ReaderModel { | ||
constructor(definition, service) { | ||
this.serviceName = definition.serviceName | ||
this.modelName = definition.modelName | ||
super(definition.serviceName, definition.modelName, service) | ||
this.service = service | ||
this.tableName = this.serviceName + "_" + this.modelName | ||
} | ||
path(id) { | ||
return ['database', 'tableObject', this.service.databaseName, this.tableName, id] | ||
} | ||
rangePath(range = {}) { | ||
if(typeof range != 'object') { | ||
const str = range.toString() | ||
return this.rangePath({ gte: str, lte: str+'\xFF\xFF\xFF\xFF' }) | ||
} | ||
if(Array.isArray(range)) this.rangePath(range.join(',')) | ||
return ['database', 'tableRange', this.service.databaseName, this.tableName, range] | ||
} | ||
indexRangePath(index, range = {}) { | ||
if(typeof range != 'object') { | ||
const str = range.toString() | ||
return this.indexRangePath(index,{ gte: str, lte: str+'\xFF\xFF\xFF\xFF' }) | ||
} | ||
if(Array.isArray(range)) this.indexRangePath(index, range.join(',')) | ||
return ['database', 'indexRange', this.service.databaseName, this.tableName+'_'+index, range] | ||
} | ||
observable(id) { | ||
return this.service.dao.observable(this.path(id), ReactiveDao.ObservableValue) | ||
} | ||
async get(id) { | ||
return this.service.dao.get(this.path(id), ReactiveDao.ObservableValue) | ||
} | ||
rangeObservable(range) { | ||
return this.service.dao.observable(this.rangePath(range), ReactiveDao.ObservableList) | ||
} | ||
async rangeGet(range) { | ||
return this.service.dao.get(this.path(range), ReactiveDao.ObservableList) | ||
} | ||
indexRangeObservable(index, range) { | ||
return this.service.dao.observable(this.indexRangePath(index, range), ReactiveDao.ObservableList) | ||
} | ||
async indexRangeGet(index, range) { | ||
return this.service.dao.get(this.indexRangePath(index, range), ReactiveDao.ObservableList) | ||
} | ||
} | ||
module.exports = ForeignModel |
@@ -1,120 +0,12 @@ | ||
const ReactiveDao = require("@live-change/dao") | ||
const ReaderModel = require("./ReaderModel.js") | ||
class Model { | ||
class Model extends ReaderModel { | ||
constructor(definition, service) { | ||
super(service.name, definition.name, service) | ||
this.service = service | ||
this.definition = definition | ||
this.tableName = service.name + "_" + this.definition.name | ||
this.changeListeners = this.definition.onChange || [] | ||
} | ||
path(id) { | ||
return ['database', 'tableObject', this.service.databaseName, this.tableName, id] | ||
} | ||
rangePath(range = {}) { | ||
if(typeof range != 'object') { | ||
const str = range.toString() | ||
return this.rangePath({ gte: str, lte: str+'\xFF\xFF\xFF\xFF' }) | ||
} | ||
if(Array.isArray(range)) this.rangePath(range.join(',')) | ||
return ['database', 'tableRange', this.service.databaseName, this.tableName, range] | ||
} | ||
indexRangePath(index, range = {}) { | ||
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' }) | ||
} | ||
return ['database', 'query', this.service.databaseName, `(${ | ||
async (input, output, { tableName, indexName, range }) => { | ||
const mapper = async (res) => input.table(tableName).object(res.to).get() | ||
await (await input.index(indexName)).range(range).onChange(async (obj, oldObj) => { | ||
output.change(obj && await mapper(obj), oldObj && await mapper(oldObj)) | ||
}) | ||
} | ||
})`, { indexName: this.tableName+'_'+index, tableName: this.tableName, range }] | ||
} | ||
indexObjectPath(index, range = {}) { | ||
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' }) | ||
} | ||
return ['database', 'queryObject', this.service.databaseName, `(${ | ||
async (input, output, { tableName, indexName, range }) => { | ||
const mapper = async (res) => input.table(tableName).object(res.to).get() | ||
await (await input.index(indexName)).range(range).onChange(async (obj, oldObj) => { | ||
output.change(obj && await mapper(obj), oldObj && await mapper(oldObj)) | ||
}) | ||
} | ||
})`, { indexName: this.tableName+'_'+index, tableName: this.tableName, range }] | ||
} | ||
indexRangeDelete(index, range = {}) { | ||
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' }) | ||
} | ||
this.service.dao.request(['database', 'query'], this.service.databaseName, `(${ | ||
async (input, output, { tableName, indexName, range }) => { | ||
await (await input.index(indexName)).range(range).onChange(async (ind, oldInd) => { | ||
output.table(tableName).delete(ind.to) | ||
}) | ||
} | ||
})`, { indexName: this.tableName+'_'+index, tableName: this.tableName, range }) | ||
} | ||
indexRangeUpdate(index, range = {}, update) { | ||
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 operations = Array.isArray(update) ? update : [{ op:'merge', property: null, value: update }] | ||
this.service.dao.request(['database', 'query'], this.service.databaseName, `(${ | ||
async (input, output, { tableName, indexName, range, operations }) => { | ||
await (await input.index(indexName)).range(range).onChange(async (ind, oldInd) => { | ||
output.table(tableName).update(ind.to, operations) | ||
}) | ||
} | ||
})`, { indexName: this.tableName+'_'+index, tableName: this.tableName, range, operations }) | ||
} | ||
observable(id) { | ||
return this.service.dao.observable(this.path(id), ReactiveDao.ObservableValue) | ||
} | ||
async get(id) { | ||
return this.service.dao.get(this.path(id), ReactiveDao.ObservableValue) | ||
} | ||
rangeObservable(range) { | ||
return this.service.dao.observable(this.rangePath(range), ReactiveDao.ObservableList) | ||
} | ||
async rangeGet(range) { | ||
return this.service.dao.get(this.path(range), ReactiveDao.ObservableList) | ||
} | ||
indexRangeObservable(index, range) { | ||
return this.service.dao.observable(this.indexRangePath(index, range), ReactiveDao.ObservableList) | ||
} | ||
async indexRangeGet(index, range) { | ||
return this.service.dao.get(this.indexRangePath(index, range), ReactiveDao.ObservableList) | ||
} | ||
indexObjectObservable(index, range) { | ||
return this.service.dao.observable(this.indexObjectPath(index, range)) | ||
} | ||
async indexObjectGet(index, range) { | ||
return this.service.dao.get(this.indexObjectPath(index, range)) | ||
} | ||
async update(id, data, options) { | ||
@@ -121,0 +13,0 @@ const operations = Array.isArray(data) ? data : [{ op:'merge', property: null, value: data }] |
@@ -149,3 +149,3 @@ const Model = require("./Model.js") | ||
Array.isArray(trigger.queuedBy) ? (c) => JSON.stringify(trigger.queuedBy.map(k=>c.parameters[k])) : | ||
(c) => JSON.stringify(c.parameters[keyFunction]) ) | ||
(c) => JSON.stringify(c.parameters[trigger.queuedBy]) ) | ||
this.triggerQueue.addCommandHandler(triggerName, async (trig) => { | ||
@@ -152,0 +152,0 @@ const emit = this.app.splitEvents |
{ | ||
"name": "@live-change/framework", | ||
"version": "0.2.11", | ||
"version": "0.2.12", | ||
"description": "Live Change Framework - ultimate solution for real time mobile/web apps", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39
104658
2901