@nxtedition/agent
Advanced tools
Comparing version 1.0.8 to 1.0.9
55
index.js
const objectHash = require('object-hash') | ||
const { Observable } = require('rxjs') | ||
@@ -11,2 +12,4 @@ function hashObject (obj) { | ||
const providers = new Map() | ||
module.exports = { | ||
@@ -26,3 +29,55 @@ spawn (query, prop) { | ||
) | ||
}, | ||
init () { | ||
const ds = this | ||
return ds.record.provide(`^.+:agent(\\.methods|\\.stats|\\.result)?$`, key => { | ||
const [ , id, prop ] = key.match(/^(.+):agent(?:\.(stats|result|description))?/) | ||
return ds.record | ||
.observe(`${id}:agent.query`) | ||
.first(x => Object.keys(x).length > 0) | ||
.switchMap(({ type, parent, description }) => { | ||
if (!prop) { | ||
return Observable.of({ type, parent }) | ||
} | ||
if (prop === 'description') { | ||
return Observable.of(description) | ||
} | ||
const name = `${hashObject(description)}:agent-${type}` | ||
return Observable | ||
.using( | ||
() => { | ||
let provider = providers.get(name) | ||
if (!provider) { | ||
provider = { | ||
unsubscribe: ds.record.provide(`${name}\\.query`, () => Observable.of({ parent, description })), | ||
refs: 0 | ||
} | ||
providers.set(name, provider) | ||
} | ||
provider.refs += 1 | ||
return { | ||
unsubscribe: () => { | ||
provider.refs -= 1 | ||
if (providers.refs === 0) { | ||
provider.unsubscribe() | ||
providers.delete(key) | ||
} | ||
} | ||
} | ||
}, | ||
() => ds.record.observe(name) | ||
) | ||
.pluck(prop) | ||
.map(x => x || {}) | ||
}) | ||
.catch(err => Observable.of({ error: err.message || err })) | ||
}) | ||
} | ||
} |
{ | ||
"name": "@nxtedition/agent", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "author": "Robert Nagy <robert.nagy@boffins.se>", |
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
4175
71