@live-change/framework
Advanced tools
Comparing version 0.5.8 to 0.5.9
11
index.js
const App = require('./lib/App.js') | ||
App.app = () => { | ||
module.exports = App | ||
module.exports.app = () => { | ||
if(!global.liveChangeFrameworkApp) { | ||
@@ -9,6 +12,6 @@ global.liveChangeFrameworkApp = new App() | ||
App.utils = require('./lib/utils.js') | ||
App.validation = require('./lib/utils/validation.js') | ||
module.exports.utils = require('./lib/utils.js') | ||
module.exports.validation = require('./lib/utils/validation.js') | ||
module.exports.rangeProperties = module.exports.utils.rangeProperties | ||
module.exports = App | ||
@@ -15,0 +18,0 @@ module.exports.ActionDefinition = require('./lib/definition/ActionDefinition.js') |
@@ -12,4 +12,5 @@ const { uidGenerator, randomString } = require('@live-change/uid') | ||
const Dao = require("./runtime/Dao.js") | ||
const SessionDao = require("./runtime/SessionDao.js") | ||
const LiveDao = require("./runtime/LiveDao.js") | ||
const ApiServer = require("./runtime/ApiServer.js") | ||
const SessionApiServer = require("./runtime/SessionApiServer.js") | ||
@@ -77,6 +78,9 @@ const reverseRelationProcessor = require("./processors/reverseRelation.js") | ||
this.uidGenerator = uidGenerator(this.instanceId) | ||
this.activeTimeouts = new Set() | ||
} | ||
createServiceDefinition( definition ) { | ||
const config = this.config && this.config.services && this.config.services[definition.name] | ||
const config = this.config && this.config.services && this.config.services.find | ||
&& this.config.services.find(c => c.name == definition.name) | ||
return new ServiceDefinition({ ...definition, config }) | ||
@@ -155,6 +159,8 @@ } | ||
} | ||
async createSessionApiServer( config ) { | ||
return new SessionApiServer({ ...config, app: this }) | ||
return new ApiServer({ ...config, app: this }, SessionDao) | ||
} | ||
async createLiveApiServer( config ) { | ||
return new ApiServer({ ...config, app: this }, LiveDao) | ||
} | ||
@@ -259,5 +265,7 @@ generateUid() { | ||
if(requestTimeout) { | ||
setTimeout(() => { | ||
const timeout = setTimeout(() => { | ||
this.activeTimeouts.delete(timeout) | ||
reject('timeout') | ||
}, requestTimeout) | ||
this.activeTimeouts.add(timeout) | ||
} | ||
@@ -386,2 +394,5 @@ }).finally(() => { | ||
async close() { | ||
for(const timeout of this.activeTimeouts) { | ||
clearTimeout(timeout) | ||
} | ||
this.dao.dispose() | ||
@@ -394,2 +405,1 @@ } | ||
module.exports = App | ||
module.exports.rangeProperties = utils.rangeProperties |
@@ -45,3 +45,3 @@ const { prepareParameters, processReturn, preFilterParameters } = require("./params.js") | ||
if(parameters._commandId) command.id = parameters._commandId | ||
console.log("CALL COMMAND", JSON.stringify(command, null, " ")) | ||
//console.log("CALL COMMAND", JSON.stringify(command, null, " ")) | ||
return this.service.app.command(command, this.definition.requestTimeout) | ||
@@ -48,0 +48,0 @@ } |
@@ -1,2 +0,2 @@ | ||
const ReactiveDao = require("@live-change/dao") | ||
const LcDao = require("@live-change/dao") | ||
const Dao = require("./Dao.js") | ||
@@ -8,6 +8,8 @@ const cookie = require('cookie') | ||
class ApiServer { | ||
constructor(config) { | ||
constructor(config, DaoConstructor = Dao) { | ||
this.config = config | ||
this.reactiveServer = new ReactiveDao.ReactiveServer( | ||
(credentials, connection) => { | ||
this.DaoConstructor = DaoConstructor | ||
this.reactiveServer = new LcDao.ReactiveServer( | ||
(credentials, connection) => { | ||
const ip = getIp(connection) | ||
@@ -28,12 +30,24 @@ if(this.config.fastAuth) { | ||
async daoFactory(credentialsp, ip) { | ||
async daoFactory(credentialsp, ip) { | ||
let credentials = { ...credentialsp, ip, roles: [] } | ||
if(this.config.authentication) { | ||
let auth = Array.isArray(this.config.authentication) | ||
? this.config.authentication : [this.config.authentication] | ||
for(let authenticator of auth) { | ||
if(authenticator) await authenticator(credentials, this.config) | ||
if(this.config.authenticators) { | ||
const auth = Array.isArray(this.config.authenticators) | ||
? this.config.authenticators : [this.config.authenticators] | ||
for(const authenticator of auth) { | ||
if(authenticator && authenticator.prepareCredentials) | ||
await authenticator.prepareCredentials(credentials, this.config) | ||
} | ||
} | ||
return new Dao(this.config, { ...credentials }) | ||
for(const service of this.config.services) { | ||
console.log("SERIVCE AUTH", service.name, service.authenticators) | ||
if(service.authenticators) { | ||
for(const authenticator of service.authenticators) { | ||
if(authenticator && authenticator.prepareCredentials) | ||
await authenticator.prepareCredentials(credentials, this.config) | ||
} | ||
} | ||
} | ||
const dao = new this.DaoConstructor(this.config, { ...credentials }) | ||
await dao.start() | ||
return dao | ||
} | ||
@@ -40,0 +54,0 @@ |
@@ -51,3 +51,3 @@ const ReactiveDao = require('@live-change/dao') | ||
async handleCommand(command) { | ||
console.log("COMMNAD HANDLE!", command) | ||
//console.log("COMMNAD HANDLE!", command) | ||
if(command.state != 'new') return | ||
@@ -54,0 +54,0 @@ if(this.commandsStarted.has(command.id)) return |
@@ -31,3 +31,3 @@ function getValidator(validation, context) { | ||
async function validate(props, validators, context) { | ||
console.log("VALIDATE PROPS", props, "WITH", validators) | ||
//console.log("VALIDATE PROPS", props, "WITH", validators) | ||
let propPromises = {} | ||
@@ -34,0 +34,0 @@ for(let propName in validators) { |
{ | ||
"name": "@live-change/framework", | ||
"version": "0.5.8", | ||
"version": "0.5.9", | ||
"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
160919
4367