Compare commits

..

6 Commits

Author SHA1 Message Date
Julien Fontanet
6274969635 0.7.1 2015-12-18 11:23:29 +01:00
Julien Fontanet
069c430346 Fix opaque ref detection. 2015-12-18 11:23:24 +01:00
Julien Fontanet
cbcc4dd21d 0.7.0 2015-12-17 16:33:55 +01:00
Julien Fontanet
b4cdf4d277 Minor optimizations. 2015-12-16 14:19:30 +01:00
Julien Fontanet
716d7bfcf6 Optimize opaque refs detection. 2015-12-16 14:15:37 +01:00
Julien Fontanet
b45a169a2f Read only mode can be altered after initial construction. 2015-12-16 13:58:33 +01:00
2 changed files with 26 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "xen-api",
"version": "0.6.9",
"version": "0.7.1",
"license": "ISC",
"description": "Connector to the Xen API",
"keywords": [

View File

@@ -140,11 +140,16 @@ const {
create: createObject,
defineProperties,
defineProperty,
freeze: freezeObject
freeze: freezeObject,
prototype: { toString }
} = Object
const noop = () => {}
const isString = (tag =>
value => toString.call(value) === tag
)(toString.call(''))
// -------------------------------------------------------------------
let getNotConnectedPromise = function () {
@@ -160,7 +165,12 @@ let getNotConnectedPromise = function () {
// -------------------------------------------------------------------
const OPAQUE_REF_RE = /^OpaqueRef:/
const OPAQUE_REF_PREFIX = 'OpaqueRef:'
const isOpaqueRef = value => isString(value) && startsWith(value, OPAQUE_REF_PREFIX)
// -------------------------------------------------------------------
const getKey = o => o.$id
// -------------------------------------------------------------------
@@ -186,19 +196,27 @@ export class Xapi extends EventEmitter {
this._pool = null
this._objectsByRefs = createObject(null)
this._objectsByRefs['OpaqueRef:NULL'] = null
this._objects = new Collection()
this._objects.getKey = (object) => object.$id
const objects = this._objects = new Collection()
objects.getKey = getKey
this._fromToken = ''
this.on('connected', this._watchEvents)
this.on('disconnected', () => {
this._fromToken = ''
this._objects.clear()
objects.clear()
})
this._readOnly = Boolean(opts.readOnly)
}
get readOnly () {
return this._readOnly
}
set readOnly (ro) {
this._readOnly = Boolean(ro)
}
get sessionId () {
if (this.status !== 'connected') {
throw new Error('sessionId is only available when connected')
@@ -465,7 +483,7 @@ export class Xapi extends EventEmitter {
// Minor memory optimization, use the same empty array for
// everyone.
object[key] = EMPTY_ARRAY
} else if (OPAQUE_REF_RE.test(value)) {
} else if (isOpaqueRef(value)) {
// This is an array of refs.
defineProperty(object, '$' + key, {
get: () => freezeObject(map(value, (ref) => objectsByRefs[ref]))
@@ -477,7 +495,7 @@ export class Xapi extends EventEmitter {
forEach(value, resolveObject)
freezeObject(value)
} else if (OPAQUE_REF_RE.test(value)) {
} else if (isOpaqueRef(value)) {
defineProperty(object, '$' + key, {
get: () => objectsByRefs[value]
})