+5
-0
@@ -5,2 +5,7 @@ # Changelog | ||
| ## 0.4.0 (2026-06-13) | ||
| - changed: Convert the build tooling from Yarn to npm. | ||
| - security: Upgrade dependencies per Socket security recommendations. | ||
| ## 0.3.12 (2023-12-11) | ||
@@ -7,0 +12,0 @@ |
+223
-316
@@ -8,17 +8,9 @@ 'use strict'; | ||
| function _extends() { | ||
| _extends = Object.assign || function (target) { | ||
| for (var i = 1; i < arguments.length; i++) { | ||
| var source = arguments[i]; | ||
| for (var key in source) { | ||
| if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
| target[key] = source[key]; | ||
| } | ||
| } | ||
| return _extends = Object.assign ? Object.assign.bind() : function (n) { | ||
| for (var e = 1; e < arguments.length; e++) { | ||
| var t = arguments[e]; | ||
| for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); | ||
| } | ||
| return target; | ||
| }; | ||
| return _extends.apply(this, arguments); | ||
| return n; | ||
| }, _extends.apply(null, arguments); | ||
| } | ||
@@ -33,2 +25,3 @@ | ||
| var MAGIC_KEY = '_yaob'; | ||
| /** | ||
@@ -38,8 +31,24 @@ * Magic data used to mark classes as bridgeable. | ||
| /** | ||
| * Magic data shared by all object instances. | ||
| */ | ||
| /** | ||
| * Magic data found on user-facing object instances. | ||
| */ | ||
| /** | ||
| * Magic data found on proxy objects. | ||
| */ | ||
| /** | ||
| * Magic data found on shared props. | ||
| */ | ||
| var nextLocalId = 1; | ||
| var sharedData = {}; | ||
| /** | ||
| * Adds or updates an object's magic data. | ||
| */ | ||
| function addMagic(o, magic) { | ||
@@ -54,10 +63,8 @@ if (Object.prototype.hasOwnProperty.call(o, MAGIC_KEY)) { | ||
| } | ||
| /** | ||
| * Makes a class bridgeable, including anything derived from it. | ||
| */ | ||
| function bridgifyClass(Class) { | ||
| var o = Class.prototype; | ||
| if (!Object.prototype.hasOwnProperty.call(o, MAGIC_KEY)) { | ||
@@ -67,9 +74,8 @@ var magic = {}; | ||
| } | ||
| return Class; | ||
| } | ||
| /** | ||
| * Makes an object instance bridgeable. | ||
| */ | ||
| function bridgifyObject(o) { | ||
@@ -85,9 +91,8 @@ if (!Object.prototype.hasOwnProperty.call(o, MAGIC_KEY) || o[MAGIC_KEY].localId == null) { | ||
| } | ||
| return o; | ||
| } | ||
| /** | ||
| * Gets the magic data from an object instance. | ||
| */ | ||
| function getInstanceMagic(o) { | ||
@@ -99,6 +104,6 @@ // We only want to look at bridgeable objects: | ||
| } | ||
| /** | ||
| * Creates a new `ProxyMagic` object. | ||
| */ | ||
| function makeProxyMagic(remoteId) { | ||
@@ -117,17 +122,14 @@ return { | ||
| } | ||
| /** | ||
| * Adds items to the global shared data table. | ||
| */ | ||
| function shareData(table, namespace) { | ||
| if (namespace == null) namespace = '';else namespace += '.'; | ||
| for (var _i2 = 0, _Object$getOwnPropert2 = Object.getOwnPropertyNames(table); _i2 < _Object$getOwnPropert2.length; _i2++) { | ||
| var n = _Object$getOwnPropert2[_i2]; | ||
| var shareId = namespace + n; | ||
| if (sharedData[shareId] != null) { | ||
| throw new Error("A shared value named " + shareId + " already exists"); | ||
| } | ||
| sharedData[shareId] = table[n]; | ||
@@ -145,2 +147,26 @@ addMagic(table[n], { | ||
| /** | ||
| * The bridge tries to send values as-is, but that isn't always possible. | ||
| * If this data structure is non-null, the strings indicate what changes | ||
| * need to take place to the value. This data structure is recursive, | ||
| * so it matches the "shape" of the value. | ||
| */ | ||
| // Set | ||
| /** | ||
| * A pure JSON value type. | ||
| */ | ||
| /** | ||
| * A value for sending over the wire. | ||
| * If the `value` needs to be modified on the client side, | ||
| * those modifications are in the `map` structure. | ||
| * If this value was thrown, `throw` will be true. | ||
| */ | ||
| /** | ||
| * The bridge turns errors into these objects. | ||
| */ | ||
| // Object properties | ||
@@ -165,6 +191,6 @@ | ||
| } | ||
| /** | ||
| * Prepares a thrown value for sending over the wire. | ||
| */ | ||
| function packThrow(table, data) { | ||
@@ -179,6 +205,6 @@ var map = mapData(table, data); | ||
| } | ||
| /** | ||
| * Restores a value that has been sent over the wire. | ||
| */ | ||
| function unpackData(table, data, path, supress) { | ||
@@ -188,5 +214,4 @@ if (supress === void 0) { | ||
| } | ||
| var map = data.map, | ||
| raw = data.raw; | ||
| raw = data.raw; | ||
| var out = map != null ? unpackItem(table, map, raw, path, supress) : raw; | ||
@@ -196,2 +221,3 @@ if (data["throw"]) throw out; | ||
| } | ||
| /** | ||
@@ -201,3 +227,2 @@ * Searches through a value, looking for data we can't send directly. | ||
| */ | ||
| function mapData(table, data) { | ||
@@ -209,3 +234,2 @@ switch (typeof data) { | ||
| return ''; | ||
| case 'object': | ||
@@ -220,17 +244,13 @@ { | ||
| if (data instanceof Set) return 'S'; | ||
| if (data[MAGIC_KEY] != null) { | ||
| return data[MAGIC_KEY].shareId != null ? 's' : 'o'; | ||
| } // Arrays: | ||
| } | ||
| // Arrays: | ||
| if (Array.isArray(data)) { | ||
| var _out = ''; | ||
| for (var i = 0; i < data.length; ++i) { | ||
| var map = mapData(table, data[i]); | ||
| if (map !== '' && _out === '') { | ||
| _out = []; | ||
| for (var j = 0; j < i; ++j) { | ||
@@ -240,15 +260,11 @@ _out[j] = ''; | ||
| } | ||
| if (_out !== '') _out[i] = map; | ||
| } | ||
| return _out; | ||
| } // Data objects: | ||
| } | ||
| // Data objects: | ||
| var out = ''; | ||
| for (var n in data) { | ||
| var _map = mapData(table, data[n]); | ||
| if (_map !== '') { | ||
@@ -259,13 +275,9 @@ if (out === '') out = {}; | ||
| } | ||
| return out; | ||
| } | ||
| case 'undefined': | ||
| return 'u'; | ||
| case 'function': | ||
| // $FlowFixMe - MAGIC_KEY isn't a known property here | ||
| return data[MAGIC_KEY] != null && data[MAGIC_KEY].shareId != null ? 's' : '?'; | ||
| default: | ||
@@ -275,12 +287,10 @@ return '?'; | ||
| } | ||
| /** | ||
| * Breaks down an error object into a JSON representation. | ||
| */ | ||
| function packError(table, o) { | ||
| // Grab the properties off the object: | ||
| var message = o.message, | ||
| stack = o.stack; | ||
| stack = o.stack; | ||
| var props = _extends({ | ||
@@ -290,6 +300,6 @@ message: message, | ||
| }, o); | ||
| var base = null; | ||
| if (o instanceof EvalError) base = 'EvalError';else if (o instanceof RangeError) base = 'RangeError';else if (o instanceof ReferenceError) base = 'ReferenceError';else if (o instanceof SyntaxError) base = 'SyntaxError';else if (o instanceof TypeError) base = 'TypeError';else if (o instanceof URIError) base = 'URIError'; // Build the JSON value: | ||
| if (o instanceof EvalError) base = 'EvalError';else if (o instanceof RangeError) base = 'RangeError';else if (o instanceof ReferenceError) base = 'ReferenceError';else if (o instanceof SyntaxError) base = 'SyntaxError';else if (o instanceof TypeError) base = 'TypeError';else if (o instanceof URIError) base = 'URIError'; | ||
| // Build the JSON value: | ||
| return _extends({ | ||
@@ -299,7 +309,6 @@ base: base | ||
| } | ||
| /** | ||
| * Copies a value, removing any API objects identified in the types. | ||
| */ | ||
| function packItem(table, map, data) { | ||
@@ -309,35 +318,24 @@ switch (map) { | ||
| return data; | ||
| case '?': | ||
| return typeof data; | ||
| case 'd': | ||
| return data.toISOString(); | ||
| case 'e': | ||
| return packError(table, data); | ||
| case 'o': | ||
| return table.getPackedId(data); | ||
| case 's': | ||
| return data[MAGIC_KEY].shareId; | ||
| case 'u': | ||
| return null; | ||
| case 'ab': | ||
| return rfc4648.base64.stringify(new Uint8Array(data)); | ||
| case 'u8': | ||
| return rfc4648.base64.stringify(data); | ||
| case 'M': | ||
| // $FlowFixMe - Flow is incorrect. This is fine. | ||
| return packData(table, Array.from(data.entries())); | ||
| case 'S': | ||
| // $FlowFixMe - Flow is incorrect. This is fine. | ||
| return packData(table, Array.from(data.values())); | ||
| default: | ||
@@ -348,17 +346,13 @@ { | ||
| var _out2 = []; | ||
| for (var i = 0; i < map.length; ++i) { | ||
| _out2[i] = packItem(table, map[i], data[i]); | ||
| } | ||
| return _out2; | ||
| } // Objects: | ||
| } | ||
| // Objects: | ||
| var out = {}; | ||
| for (var n in data) { | ||
| out[n] = n in map ? packItem(table, map[n], data[n]) : data[n]; | ||
| } | ||
| return out; | ||
@@ -368,7 +362,6 @@ } | ||
| } | ||
| /** | ||
| * Restores an error object from its JSON representation. | ||
| */ | ||
| function unpackError(table, value, path) { | ||
@@ -382,20 +375,19 @@ var bases = { | ||
| URIError: URIError | ||
| }; // Make the object: | ||
| }; | ||
| // Make the object: | ||
| var Base = value.base != null ? bases[value.base] || Error : Error; | ||
| var out = new Base(); // Restore the properties: | ||
| var out = new Base(); | ||
| // Restore the properties: | ||
| var props = unpackData(table, value, path, true); | ||
| for (var n in props) { | ||
| out[n] = props[n]; | ||
| } | ||
| return out; | ||
| } | ||
| /** | ||
| * Restores a value that has been sent over the wire. | ||
| */ | ||
| function unpackItem(table, map, raw, path, supress) { | ||
@@ -405,3 +397,2 @@ switch (map) { | ||
| return raw; | ||
| case '?': | ||
@@ -412,6 +403,4 @@ { | ||
| } | ||
| case 'd': | ||
| return new Date(raw); | ||
| case 'e': | ||
@@ -421,5 +410,3 @@ if (typeof raw !== 'object' || raw === null) { | ||
| } | ||
| return unpackError(table, raw, path); | ||
| case 'o': | ||
@@ -430,13 +417,9 @@ { | ||
| } | ||
| if (typeof raw !== 'number') { | ||
| throw new TypeError("Expecting a packedId at " + path); | ||
| } | ||
| var _o = table.getObject(-raw); | ||
| if (_o == null) throw new RangeError("Invalid packedId " + raw + " at " + path); | ||
| return _o; | ||
| } | ||
| case 's': | ||
@@ -447,3 +430,2 @@ { | ||
| } | ||
| var s = sharedData[raw]; | ||
@@ -453,6 +435,4 @@ if (s == null) throw new RangeError("Invalid shareId '" + raw + "' at " + path); | ||
| } | ||
| case 'u': | ||
| return undefined; | ||
| case 'ab': | ||
@@ -462,5 +442,3 @@ if (typeof raw !== 'string') { | ||
| } | ||
| return rfc4648.base64.parse(raw).buffer; | ||
| case 'u8': | ||
@@ -470,5 +448,3 @@ if (typeof raw !== 'string') { | ||
| } | ||
| return rfc4648.base64.parse(raw); | ||
| case 'M': | ||
@@ -479,6 +455,4 @@ { | ||
| } | ||
| return new Map(unpackData(table, raw, path)); | ||
| } | ||
| case 'S': | ||
@@ -489,6 +463,4 @@ { | ||
| } | ||
| return new Set(unpackData(table, raw, path)); | ||
| } | ||
| default: | ||
@@ -499,8 +471,7 @@ { | ||
| } | ||
| if (typeof raw !== 'object' || raw === null) { | ||
| throw new TypeError("Expecting an array or object at " + path); | ||
| } // Arrays: | ||
| } | ||
| // Arrays: | ||
| if (Array.isArray(map)) { | ||
@@ -510,5 +481,3 @@ if (!Array.isArray(raw)) { | ||
| } | ||
| var _out3 = []; | ||
| for (var i = 0; i < map.length; ++i) { | ||
@@ -518,9 +487,7 @@ if (supress === true && map[i] === '?') continue; | ||
| } | ||
| return _out3; | ||
| } // Objects: | ||
| } | ||
| // Objects: | ||
| var out = {}; | ||
| for (var n in raw) { | ||
@@ -530,3 +497,2 @@ if (supress === true && map[n] === '?') continue; | ||
| } | ||
| return out; | ||
@@ -541,2 +507,3 @@ } | ||
| */ | ||
| /** | ||
@@ -546,13 +513,16 @@ * Undoes the effect of `on`. | ||
| /** | ||
| * Signature of the `on` method. | ||
| */ | ||
| // No user-supplied value will ever be identical to this. | ||
| var dirtyValue$1 = {}; | ||
| /** | ||
| * Subscribes to an event on a bridgeable object. | ||
| */ | ||
| function addListener(o, name, f) { | ||
| var _getInstanceMagic = getInstanceMagic(o), | ||
| closed = _getInstanceMagic.closed, | ||
| listeners = _getInstanceMagic.listeners; | ||
| closed = _getInstanceMagic.closed, | ||
| listeners = _getInstanceMagic.listeners; | ||
| if (closed) return function () {}; | ||
@@ -566,12 +536,12 @@ if (listeners[name] == null) listeners[name] = [f];else listeners[name].push(f); | ||
| } | ||
| /** | ||
| * Subscribes to property changes on a bridgeable object. | ||
| */ | ||
| function addWatcher(o, name, f) { | ||
| var _getInstanceMagic2 = getInstanceMagic(o), | ||
| closed = _getInstanceMagic2.closed, | ||
| watchers = _getInstanceMagic2.watchers; // Don't catch access errors, since we want the user to see them: | ||
| closed = _getInstanceMagic2.closed, | ||
| watchers = _getInstanceMagic2.watchers; | ||
| // Don't catch access errors, since we want the user to see them: | ||
| var data = o[name]; | ||
@@ -589,2 +559,3 @@ if (closed) return function () {}; | ||
| } | ||
| /** | ||
@@ -595,8 +566,7 @@ * Destroys a proxy. | ||
| */ | ||
| function close(o) { | ||
| var magic = getInstanceMagic(o); // Call local callbacks: | ||
| var magic = getInstanceMagic(o); | ||
| // Call local callbacks: | ||
| var listeners = magic.listeners.close; | ||
| if (listeners != null) { | ||
@@ -608,5 +578,3 @@ for (var _i2 = 0; _i2 < listeners.length; _i2++) { | ||
| } | ||
| magic.closed = true; | ||
| for (var _i4 = 0, _magic$bridges2 = magic.bridges; _i4 < _magic$bridges2.length; _i4++) { | ||
@@ -616,3 +584,2 @@ var bridge = _magic$bridges2[_i4]; | ||
| } | ||
| magic.bridges = []; | ||
@@ -622,10 +589,11 @@ magic.listeners = {}; | ||
| } | ||
| /** | ||
| * Emits an event on a bridgeable object. | ||
| */ | ||
| function emit(o, name, payload) { | ||
| var magic = getInstanceMagic(o); | ||
| if (magic.closed) throw new Error('Cannot emit event on closed object'); // Schedule outgoing event messages: | ||
| if (magic.closed) throw new Error('Cannot emit event on closed object'); | ||
| // Schedule outgoing event messages: | ||
| for (var _i6 = 0, _magic$bridges4 = magic.bridges; _i6 < _magic$bridges4.length; _i6++) { | ||
@@ -635,6 +603,3 @@ var bridge = _magic$bridges4[_i6]; | ||
| } // Call local callbacks: | ||
| var listeners = magic.listeners[name]; | ||
| if (listeners != null) { | ||
@@ -647,32 +612,26 @@ for (var _i8 = 0; _i8 < listeners.length; _i8++) { | ||
| } | ||
| /** | ||
| * Marks an object as having changes. The proxy server will send an update. | ||
| */ | ||
| function update(o, name) { | ||
| var magic = getInstanceMagic(o); | ||
| if (magic.closed) throw new Error('Cannot update closed object'); | ||
| for (var _i10 = 0, _magic$bridges6 = magic.bridges; _i10 < _magic$bridges6.length; _i10++) { | ||
| var bridge = _magic$bridges6[_i10]; | ||
| for (var _i0 = 0, _magic$bridges6 = magic.bridges; _i0 < _magic$bridges6.length; _i0++) { | ||
| var bridge = _magic$bridges6[_i0]; | ||
| bridge.markDirty(magic.localId, name); | ||
| } // Blow away the cache if we have a name: | ||
| if (name != null && magic.watchers[name] != null) { | ||
| magic.watchers[name].data = dirtyValue$1; | ||
| } // Call watcher callbacks: | ||
| } | ||
| // Call watcher callbacks: | ||
| for (var n in magic.watchers) { | ||
| var cache = magic.watchers[n]; | ||
| try { | ||
| var data = o[n]; | ||
| if (data !== cache.data) { | ||
| cache.data = data; | ||
| for (var _i12 = 0, _cache$fs2 = cache.fs; _i12 < _cache$fs2.length; _i12++) { | ||
| var _f3 = _cache$fs2[_i12]; | ||
| for (var _i10 = 0, _cache$fs2 = cache.fs; _i10 < _cache$fs2.length; _i10++) { | ||
| var _f3 = _cache$fs2[_i10]; | ||
| callCallback(o, _f3, cache.data, true); | ||
@@ -684,10 +643,11 @@ } | ||
| } | ||
| /** | ||
| * Calls a user-supplied callback function with error checking. | ||
| */ | ||
| function callCallback(o, f, payload, emitError) { | ||
| try { | ||
| var out = f(payload); // If the function returns a promise, emit an error if it rejects: | ||
| var out = f(payload); | ||
| // If the function returns a promise, emit an error if it rejects: | ||
| if (emitError && out != null && typeof out.then === 'function') { | ||
@@ -710,2 +670,3 @@ out.then(undefined, function (e) { | ||
| var dirtyValue = {}; | ||
| /** | ||
@@ -715,3 +676,2 @@ * Examines a bridgeable object and prepares it for sending of the wire. | ||
| */ | ||
| function packObject(state, o) { | ||
@@ -721,7 +681,5 @@ // Iterate the prototype chain, looking for property names: | ||
| var end = Object.prototype; | ||
| for (var p = o; p !== end && p != null; p = Object.getPrototypeOf(p)) { | ||
| for (var _i2 = 0, _Object$getOwnPropert2 = Object.getOwnPropertyNames(p); _i2 < _Object$getOwnPropert2.length; _i2++) { | ||
| var _name = _Object$getOwnPropert2[_i2]; | ||
| if (_name !== MAGIC_KEY && !/^_/.test(_name) && _name !== 'constructor') { | ||
@@ -731,14 +689,12 @@ allNames[_name] = true; | ||
| } | ||
| } // Iterate over the object's properties and add their names to | ||
| } | ||
| // Iterate over the object's properties and add their names to | ||
| // the method list or the value cache. | ||
| var cache = {}; | ||
| var methods = []; | ||
| var props = {}; | ||
| for (var n in allNames) { | ||
| try { | ||
| var data = o[n]; | ||
| if (typeof data === 'function' && (data[MAGIC_KEY] == null || data[MAGIC_KEY].shareId == null)) { | ||
@@ -755,6 +711,4 @@ methods.push(n); | ||
| } | ||
| var _getInstanceMagic = getInstanceMagic(o), | ||
| localId = _getInstanceMagic.localId; | ||
| localId = _getInstanceMagic.localId; | ||
| var create = { | ||
@@ -770,2 +724,3 @@ localId: localId, | ||
| } | ||
| /** | ||
@@ -775,11 +730,8 @@ * Checks an object for changes. | ||
| */ | ||
| function diffObject(state, o, cache) { | ||
| var dirty = false; | ||
| var props = {}; | ||
| for (var n in cache) { | ||
| try { | ||
| var value = o[n]; | ||
| if (value !== cache[n]) { | ||
@@ -795,3 +747,2 @@ dirty = true; | ||
| } | ||
| return { | ||
@@ -802,2 +753,3 @@ dirty: dirty, | ||
| } | ||
| /** | ||
@@ -808,11 +760,12 @@ * Creates an object proxy. | ||
| */ | ||
| function makeProxy(state, create) { | ||
| var props = {}; // Make the magic property descriptor: | ||
| var props = {}; | ||
| // Make the magic property descriptor: | ||
| var magic = makeProxyMagic(create.localId); | ||
| props[MAGIC_KEY] = { | ||
| value: magic | ||
| }; // Add the getters: | ||
| }; | ||
| // Add the getters: | ||
| for (var n in create.props) { | ||
@@ -823,5 +776,5 @@ props[n] = { | ||
| }; | ||
| } // Add the methods: | ||
| } | ||
| // Add the methods: | ||
| for (var _i4 = 0, _create$methods2 = create.methods; _i4 < _create$methods2.length; _i4++) { | ||
@@ -833,13 +786,10 @@ var _n = _create$methods2[_i4]; | ||
| } // Make the object: | ||
| return Object.create(Object.prototype, props); | ||
| } | ||
| /** | ||
| * Unpacks a proxy's properties into the magic storage area. | ||
| */ | ||
| function updateObjectProps(state, o, props) { | ||
| var magic = o[MAGIC_KEY]; | ||
| for (var n in props) { | ||
@@ -855,3 +805,2 @@ try { | ||
| } | ||
| function makeProxyGetter(magic, name) { | ||
@@ -863,3 +812,2 @@ return function get() { | ||
| } | ||
| function makeProxyMethod(state, magic, name) { | ||
@@ -870,7 +818,5 @@ return function method() { | ||
| } | ||
| for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
| args[_key] = arguments[_key]; | ||
| } | ||
| return state.emitCall(magic.remoteId, name, args); | ||
@@ -882,30 +828,41 @@ }; | ||
| // Options: | ||
| // Objects: | ||
| // Outgoing method calls: | ||
| // Pending message: | ||
| // Update scheduling: | ||
| function BridgeState(opts) { | ||
| var _opts$hideProperties = opts.hideProperties, | ||
| hideProperties = _opts$hideProperties === void 0 ? [] : _opts$hideProperties, | ||
| sendMessage = opts.sendMessage, | ||
| _opts$throttleMs = opts.throttleMs, | ||
| throttleMs = _opts$throttleMs === void 0 ? 0 : _opts$throttleMs; // Options: | ||
| hideProperties = _opts$hideProperties === void 0 ? [] : _opts$hideProperties, | ||
| sendMessage = opts.sendMessage, | ||
| _opts$throttleMs = opts.throttleMs, | ||
| throttleMs = _opts$throttleMs === void 0 ? 0 : _opts$throttleMs; | ||
| // Options: | ||
| this.hideProperties = hideProperties; | ||
| this.sendMessage = sendMessage; | ||
| this.throttleMs = throttleMs; // Objects: | ||
| this.throttleMs = throttleMs; | ||
| // Objects: | ||
| this.proxies = {}; | ||
| this.objects = {}; | ||
| this.caches = {}; // Outgoing method calls: | ||
| this.caches = {}; | ||
| // Outgoing method calls: | ||
| this.nextCallId = 0; | ||
| this.pendingCalls = {}; // Pending message: | ||
| this.pendingCalls = {}; | ||
| // Pending message: | ||
| this.dirty = {}; | ||
| this.message = {}; // Update scheduling: | ||
| this.message = {}; | ||
| // Update scheduling: | ||
| this.lastUpdate = 0; | ||
| this.sendPending = false; | ||
| } | ||
| /** | ||
@@ -916,6 +873,3 @@ * Close the bridge, so it will no longer send messages. | ||
| */ | ||
| var _proto = BridgeState.prototype; | ||
| _proto.close = function close$1(error) { | ||
@@ -926,17 +880,15 @@ for (var _callId in this.pendingCalls) { | ||
| } | ||
| for (var _objectId in this.proxies) { | ||
| close(this.proxies[Number(_objectId)]); | ||
| } | ||
| this.closed = true; | ||
| } | ||
| /** | ||
| * Grabs an object by its proxy id. | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.getObject = function getObject(packedId) { | ||
| return packedId < 0 ? this.proxies[-packedId] : this.objects[packedId]; | ||
| } | ||
| /** | ||
@@ -946,21 +898,15 @@ * Returns an object's id relative to this bridge. | ||
| * and negative for proxy objects reflecting things on the other side. | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.getPackedId = function getPackedId(o) { | ||
| var magic = getInstanceMagic(o); | ||
| if (magic.closed) return null; | ||
| if (magic.remoteId != null && this.proxies[magic.remoteId] != null) { | ||
| return -magic.remoteId; | ||
| } | ||
| if (this.objects[magic.localId] == null) { | ||
| // Add unknown objects to the bridge: | ||
| this.objects[magic.localId] = o; | ||
| var _packObject = packObject(this, o), | ||
| cache = _packObject.cache, | ||
| create = _packObject.create; | ||
| cache = _packObject.cache, | ||
| create = _packObject.create; | ||
| this.caches[magic.localId] = cache; | ||
@@ -970,10 +916,8 @@ magic.bridges.push(this); | ||
| } | ||
| return magic.localId; | ||
| } | ||
| /** | ||
| * Marks an object as needing changes. | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.markDirty = function markDirty(localId, name) { | ||
@@ -988,7 +932,6 @@ var cache = this.caches[localId]; | ||
| } | ||
| /** | ||
| * Marks an object as being deleted. | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.emitClose = function emitClose(localId) { | ||
@@ -1001,21 +944,18 @@ delete this.objects[localId]; | ||
| } | ||
| /** | ||
| * Attaches an object to this bridge, sending a creation message. | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.emitCreate = function emitCreate(create, o) { | ||
| if (this.message.created == null) this.message.created = []; | ||
| this.message.created.push(create); // this.wakeup() not needed, since this is part of data packing. | ||
| this.message.created.push(create); | ||
| // this.wakeup() not needed, since this is part of data packing. | ||
| } | ||
| /** | ||
| * Enqueues a proxy call message. | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.emitCall = function emitCall(remoteId, name, args) { | ||
| var _this = this; | ||
| var callId = this.nextCallId++; | ||
| var message = _extends({ | ||
@@ -1026,3 +966,2 @@ callId: callId, | ||
| }, packData(this, args)); | ||
| if (this.message.calls == null) this.message.calls = []; | ||
@@ -1039,7 +978,6 @@ this.message.calls.push(message); | ||
| } | ||
| /** | ||
| * Enqueues an event message. | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.emitEvent = function emitEvent(localId, name, payload) { | ||
@@ -1050,3 +988,2 @@ var message = _extends({ | ||
| }, packData(this, payload)); | ||
| if (this.message.events == null) this.message.events = []; | ||
@@ -1056,7 +993,6 @@ this.message.events.push(message); | ||
| } | ||
| /** | ||
| * Enqueues a function return message. | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.emitReturn = function emitReturn(callId, fail, value) { | ||
@@ -1066,3 +1002,2 @@ var message = _extends({ | ||
| }, fail ? packThrow(this, value) : packData(this, value)); | ||
| if (this.message.returns == null) this.message.returns = []; | ||
@@ -1072,14 +1007,13 @@ this.message.returns.push(message); | ||
| } | ||
| /** | ||
| * Handles an incoming message, | ||
| * updating state and triggering side-effects as needed. | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.handleMessage = function handleMessage(message) { | ||
| var _this2 = this; | ||
| // ---------------------------------------- | ||
| // Phase 1: Get our proxies up to date. | ||
| // ---------------------------------------- | ||
| // Handle newly-created objects: | ||
@@ -1092,4 +1026,2 @@ if (message.created) { | ||
| } // Pass 2: Fill in the values: | ||
| for (var _i4 = 0, _message$created4 = message.created; _i4 < _message$created4.length; _i4++) { | ||
@@ -1099,5 +1031,5 @@ var _create = _message$created4[_i4]; | ||
| } | ||
| } // Handle updated objects: | ||
| } | ||
| // Handle updated objects: | ||
| if (message.changed) { | ||
@@ -1108,13 +1040,9 @@ // Pass 1: Update all the proxies: | ||
| var _localId = change.localId, | ||
| props = change.props; | ||
| props = change.props; | ||
| var o = this.proxies[_localId]; | ||
| if (o == null) { | ||
| throw new RangeError("Invalid localId " + _localId); | ||
| } | ||
| updateObjectProps(this, o, props); | ||
| } // Pass 2: Fire the callbacks: | ||
| for (var _i8 = 0, _message$changed4 = message.changed; _i8 < _message$changed4.length; _i8++) { | ||
@@ -1124,18 +1052,16 @@ var _change = _message$changed4[_i8]; | ||
| } | ||
| } // ---------------------------------------- | ||
| } | ||
| // ---------------------------------------- | ||
| // Phase 2: Handle events & method calls | ||
| // ---------------------------------------- | ||
| // Handle events: | ||
| if (message.events) { | ||
| for (var _i10 = 0, _message$events2 = message.events; _i10 < _message$events2.length; _i10++) { | ||
| var event = _message$events2[_i10]; | ||
| for (var _i0 = 0, _message$events2 = message.events; _i0 < _message$events2.length; _i0++) { | ||
| var event = _message$events2[_i0]; | ||
| var _localId2 = event.localId, | ||
| name = event.name; | ||
| name = event.name; | ||
| var _o = _localId2 === 0 ? this : this.proxies[_localId2]; | ||
| if (_o == null) continue; | ||
| try { | ||
@@ -1147,23 +1073,19 @@ emit(_o, name, unpackData(this, event, name)); | ||
| } | ||
| } // Handle method calls: | ||
| } | ||
| // Handle method calls: | ||
| if (message.calls) { | ||
| var _loop = function _loop(_i12, _message$calls2) { | ||
| var call = _message$calls2[_i12]; | ||
| var _loop = function _loop(_i10, _message$calls2) { | ||
| var call = _message$calls2[_i10]; | ||
| var callId = call.callId, | ||
| remoteId = call.remoteId, | ||
| name = call.name; | ||
| remoteId = call.remoteId, | ||
| name = call.name; | ||
| try { | ||
| var _o2 = _this2.objects[remoteId]; | ||
| if (_o2 == null) { | ||
| throw new TypeError("Cannot call method '" + name + "' of closed proxy (remote)"); | ||
| } | ||
| if (typeof _o2[name] !== 'function') { | ||
| throw new TypeError("'" + name + "' is not a function"); | ||
| } | ||
| var args = unpackData(_this2, call, name + ".arguments"); | ||
@@ -1179,19 +1101,16 @@ Promise.resolve(_o2[name].apply(_o2, args)).then(function (value) { | ||
| }; | ||
| for (var _i12 = 0, _message$calls2 = message.calls; _i12 < _message$calls2.length; _i12++) { | ||
| _loop(_i12, _message$calls2); | ||
| for (var _i10 = 0, _message$calls2 = message.calls; _i10 < _message$calls2.length; _i10++) { | ||
| _loop(_i10, _message$calls2); | ||
| } | ||
| } // Handle method returns: | ||
| } | ||
| // Handle method returns: | ||
| if (message.returns) { | ||
| for (var _i14 = 0, _message$returns2 = message.returns; _i14 < _message$returns2.length; _i14++) { | ||
| var ret = _message$returns2[_i14]; | ||
| for (var _i12 = 0, _message$returns2 = message.returns; _i12 < _message$returns2.length; _i12++) { | ||
| var ret = _message$returns2[_i12]; | ||
| var _callId2 = ret.callId; | ||
| var pendingCall = this.pendingCalls[_callId2]; | ||
| if (pendingCall == null) { | ||
| throw new RangeError("Invalid callId " + _callId2); | ||
| } | ||
| try { | ||
@@ -1205,14 +1124,14 @@ pendingCall.resolve(unpackData(this, ret, pendingCall.name + ".return")); | ||
| } | ||
| } // ---------------------------------------- | ||
| } | ||
| // ---------------------------------------- | ||
| // Phase 3: Clean up closed objects | ||
| // ---------------------------------------- | ||
| if (message.closed) { | ||
| for (var _i16 = 0, _message$closed2 = message.closed; _i16 < _message$closed2.length; _i16++) { | ||
| var _localId3 = _message$closed2[_i16]; | ||
| for (var _i14 = 0, _message$closed2 = message.closed; _i14 < _message$closed2.length; _i14++) { | ||
| var _localId3 = _message$closed2[_i14]; | ||
| var _o3 = this.proxies[_localId3]; | ||
| if (_o3 == null) return; | ||
| delete this.proxies[_localId3]; | ||
| close(_o3); | ||
@@ -1222,21 +1141,18 @@ } | ||
| } | ||
| /** | ||
| * Sends the current message. | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.sendNow = function sendNow() { | ||
| if (this.closed) return; // Build change messages: | ||
| if (this.closed) return; | ||
| // Build change messages: | ||
| for (var id in this.dirty) { | ||
| var _localId4 = Number(id); | ||
| var _this$dirty$_localId = this.dirty[_localId4], | ||
| object = _this$dirty$_localId.object, | ||
| cache = _this$dirty$_localId.cache; | ||
| object = _this$dirty$_localId.object, | ||
| cache = _this$dirty$_localId.cache; | ||
| var _diffObject = diffObject(this, object, cache), | ||
| dirty = _diffObject.dirty, | ||
| props = _diffObject.props; | ||
| dirty = _diffObject.dirty, | ||
| props = _diffObject.props; | ||
| if (dirty) { | ||
@@ -1251,7 +1167,5 @@ var _message = { | ||
| } | ||
| var message = this.message; | ||
| this.dirty = {}; | ||
| this.message = {}; | ||
| if (message.calls != null || message.changed != null || message.closed != null || message.created != null || message.events != null || message.returns != null) { | ||
@@ -1261,26 +1175,21 @@ this.sendMessage(message); | ||
| } | ||
| /** | ||
| * Something has changed, so prepare to send the pending message: | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.wakeup = function wakeup() { | ||
| var _this3 = this; | ||
| if (this.sendPending) return; | ||
| this.sendPending = true; | ||
| var task = function task() { | ||
| _this3.sendPending = false; | ||
| _this3.lastUpdate = Date.now(); | ||
| _this3.sendNow(); | ||
| }; | ||
| _this3.sendNow(); | ||
| }; // We really do want `setTimeout` here, even if the delay is 0, | ||
| // We really do want `setTimeout` here, even if the delay is 0, | ||
| // since promises and other micro tasks should fire first. | ||
| var delay = this.lastUpdate + this.throttleMs - Date.now(); | ||
| setTimeout(task, delay < 0 ? 0 : delay); | ||
| }; | ||
| return BridgeState; | ||
@@ -1291,2 +1200,14 @@ }(); | ||
| /** | ||
| * The bridge sends messages using this function. | ||
| */ | ||
| /** | ||
| * Options used to create a new bridge. | ||
| */ | ||
| /** | ||
| * Options used to create a new local bridge. | ||
| */ | ||
| /** | ||
| * An object bridge. | ||
@@ -1297,3 +1218,2 @@ */ | ||
| var _this = this; | ||
| this._state = new BridgeState(opts); | ||
@@ -1304,23 +1224,18 @@ this._rootPromise = new Promise(function (resolve) { | ||
| } | ||
| var _proto = Bridge.prototype; | ||
| _proto.handleMessage = function handleMessage(message) { | ||
| this._state.handleMessage(message); | ||
| }; | ||
| _proto.getRoot = function getRoot() { | ||
| return this._rootPromise; | ||
| }; | ||
| _proto.sendRoot = function sendRoot(root) { | ||
| this._state.emitEvent(0, 'root', root); | ||
| }; | ||
| _proto.close = function close(error) { | ||
| this._state.close(error); | ||
| }; | ||
| return Bridge; | ||
| }(); | ||
| /** | ||
@@ -1331,3 +1246,2 @@ * Bridges a single object locally. This is great for unit tests, | ||
| */ | ||
| function makeLocalBridge(o, opts) { | ||
@@ -1337,12 +1251,10 @@ if (opts === void 0) { | ||
| } | ||
| function nopClone(m) { | ||
| return m; | ||
| } | ||
| var _opts = opts, | ||
| _opts$cloneMessage = _opts.cloneMessage, | ||
| cloneMessage = _opts$cloneMessage === void 0 ? nopClone : _opts$cloneMessage, | ||
| hideProperties = _opts.hideProperties, | ||
| throttleMs = _opts.throttleMs; | ||
| _opts$cloneMessage = _opts.cloneMessage, | ||
| cloneMessage = _opts$cloneMessage === void 0 ? nopClone : _opts$cloneMessage, | ||
| hideProperties = _opts.hideProperties, | ||
| throttleMs = _opts.throttleMs; | ||
| var serverState = new BridgeState({ | ||
@@ -1371,6 +1283,6 @@ sendMessage: function sendMessage(message) { | ||
| */ | ||
| var onMethod = function on(name, f) { | ||
| return addListener(this, name, f); | ||
| }; | ||
| /** | ||
@@ -1380,3 +1292,2 @@ * The `watch` function, | ||
| */ | ||
| var watchMethod = function watch(name, f) { | ||
@@ -1389,26 +1300,22 @@ return addWatcher(this, name, f); | ||
| }); | ||
| /** | ||
| * The base class for all bridgeable API's. Provides callback capability. | ||
| */ | ||
| var Bridgeable = /*#__PURE__*/function () { | ||
| function Bridgeable() {} | ||
| var _proto = Bridgeable.prototype; | ||
| _proto._close = function _close() { | ||
| close(this); | ||
| }; | ||
| _proto._emit = function _emit(name, payload) { | ||
| return emit(this, name, payload); | ||
| }; | ||
| _proto._update = function _update(name) { | ||
| update(this, name); | ||
| }; | ||
| return Bridgeable; | ||
| }(); // Put the shared methods onto the prototype: | ||
| }(); | ||
| // Put the shared methods onto the prototype: | ||
| var hack = Bridgeable.prototype; | ||
@@ -1415,0 +1322,0 @@ hack.on = onMethod; |
+223
-316
| import { base64 } from 'rfc4648'; | ||
| function _extends() { | ||
| _extends = Object.assign || function (target) { | ||
| for (var i = 1; i < arguments.length; i++) { | ||
| var source = arguments[i]; | ||
| for (var key in source) { | ||
| if (Object.prototype.hasOwnProperty.call(source, key)) { | ||
| target[key] = source[key]; | ||
| } | ||
| } | ||
| return _extends = Object.assign ? Object.assign.bind() : function (n) { | ||
| for (var e = 1; e < arguments.length; e++) { | ||
| var t = arguments[e]; | ||
| for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); | ||
| } | ||
| return target; | ||
| }; | ||
| return _extends.apply(this, arguments); | ||
| return n; | ||
| }, _extends.apply(null, arguments); | ||
| } | ||
@@ -28,2 +20,3 @@ | ||
| var MAGIC_KEY = '_yaob'; | ||
| /** | ||
@@ -33,8 +26,24 @@ * Magic data used to mark classes as bridgeable. | ||
| /** | ||
| * Magic data shared by all object instances. | ||
| */ | ||
| /** | ||
| * Magic data found on user-facing object instances. | ||
| */ | ||
| /** | ||
| * Magic data found on proxy objects. | ||
| */ | ||
| /** | ||
| * Magic data found on shared props. | ||
| */ | ||
| var nextLocalId = 1; | ||
| var sharedData = {}; | ||
| /** | ||
| * Adds or updates an object's magic data. | ||
| */ | ||
| function addMagic(o, magic) { | ||
@@ -49,10 +58,8 @@ if (Object.prototype.hasOwnProperty.call(o, MAGIC_KEY)) { | ||
| } | ||
| /** | ||
| * Makes a class bridgeable, including anything derived from it. | ||
| */ | ||
| function bridgifyClass(Class) { | ||
| var o = Class.prototype; | ||
| if (!Object.prototype.hasOwnProperty.call(o, MAGIC_KEY)) { | ||
@@ -62,9 +69,8 @@ var magic = {}; | ||
| } | ||
| return Class; | ||
| } | ||
| /** | ||
| * Makes an object instance bridgeable. | ||
| */ | ||
| function bridgifyObject(o) { | ||
@@ -80,9 +86,8 @@ if (!Object.prototype.hasOwnProperty.call(o, MAGIC_KEY) || o[MAGIC_KEY].localId == null) { | ||
| } | ||
| return o; | ||
| } | ||
| /** | ||
| * Gets the magic data from an object instance. | ||
| */ | ||
| function getInstanceMagic(o) { | ||
@@ -94,6 +99,6 @@ // We only want to look at bridgeable objects: | ||
| } | ||
| /** | ||
| * Creates a new `ProxyMagic` object. | ||
| */ | ||
| function makeProxyMagic(remoteId) { | ||
@@ -112,17 +117,14 @@ return { | ||
| } | ||
| /** | ||
| * Adds items to the global shared data table. | ||
| */ | ||
| function shareData(table, namespace) { | ||
| if (namespace == null) namespace = '';else namespace += '.'; | ||
| for (var _i2 = 0, _Object$getOwnPropert2 = Object.getOwnPropertyNames(table); _i2 < _Object$getOwnPropert2.length; _i2++) { | ||
| var n = _Object$getOwnPropert2[_i2]; | ||
| var shareId = namespace + n; | ||
| if (sharedData[shareId] != null) { | ||
| throw new Error("A shared value named " + shareId + " already exists"); | ||
| } | ||
| sharedData[shareId] = table[n]; | ||
@@ -140,2 +142,26 @@ addMagic(table[n], { | ||
| /** | ||
| * The bridge tries to send values as-is, but that isn't always possible. | ||
| * If this data structure is non-null, the strings indicate what changes | ||
| * need to take place to the value. This data structure is recursive, | ||
| * so it matches the "shape" of the value. | ||
| */ | ||
| // Set | ||
| /** | ||
| * A pure JSON value type. | ||
| */ | ||
| /** | ||
| * A value for sending over the wire. | ||
| * If the `value` needs to be modified on the client side, | ||
| * those modifications are in the `map` structure. | ||
| * If this value was thrown, `throw` will be true. | ||
| */ | ||
| /** | ||
| * The bridge turns errors into these objects. | ||
| */ | ||
| // Object properties | ||
@@ -160,6 +186,6 @@ | ||
| } | ||
| /** | ||
| * Prepares a thrown value for sending over the wire. | ||
| */ | ||
| function packThrow(table, data) { | ||
@@ -174,6 +200,6 @@ var map = mapData(table, data); | ||
| } | ||
| /** | ||
| * Restores a value that has been sent over the wire. | ||
| */ | ||
| function unpackData(table, data, path, supress) { | ||
@@ -183,5 +209,4 @@ if (supress === void 0) { | ||
| } | ||
| var map = data.map, | ||
| raw = data.raw; | ||
| raw = data.raw; | ||
| var out = map != null ? unpackItem(table, map, raw, path, supress) : raw; | ||
@@ -191,2 +216,3 @@ if (data["throw"]) throw out; | ||
| } | ||
| /** | ||
@@ -196,3 +222,2 @@ * Searches through a value, looking for data we can't send directly. | ||
| */ | ||
| function mapData(table, data) { | ||
@@ -204,3 +229,2 @@ switch (typeof data) { | ||
| return ''; | ||
| case 'object': | ||
@@ -215,17 +239,13 @@ { | ||
| if (data instanceof Set) return 'S'; | ||
| if (data[MAGIC_KEY] != null) { | ||
| return data[MAGIC_KEY].shareId != null ? 's' : 'o'; | ||
| } // Arrays: | ||
| } | ||
| // Arrays: | ||
| if (Array.isArray(data)) { | ||
| var _out = ''; | ||
| for (var i = 0; i < data.length; ++i) { | ||
| var map = mapData(table, data[i]); | ||
| if (map !== '' && _out === '') { | ||
| _out = []; | ||
| for (var j = 0; j < i; ++j) { | ||
@@ -235,15 +255,11 @@ _out[j] = ''; | ||
| } | ||
| if (_out !== '') _out[i] = map; | ||
| } | ||
| return _out; | ||
| } // Data objects: | ||
| } | ||
| // Data objects: | ||
| var out = ''; | ||
| for (var n in data) { | ||
| var _map = mapData(table, data[n]); | ||
| if (_map !== '') { | ||
@@ -254,13 +270,9 @@ if (out === '') out = {}; | ||
| } | ||
| return out; | ||
| } | ||
| case 'undefined': | ||
| return 'u'; | ||
| case 'function': | ||
| // $FlowFixMe - MAGIC_KEY isn't a known property here | ||
| return data[MAGIC_KEY] != null && data[MAGIC_KEY].shareId != null ? 's' : '?'; | ||
| default: | ||
@@ -270,12 +282,10 @@ return '?'; | ||
| } | ||
| /** | ||
| * Breaks down an error object into a JSON representation. | ||
| */ | ||
| function packError(table, o) { | ||
| // Grab the properties off the object: | ||
| var message = o.message, | ||
| stack = o.stack; | ||
| stack = o.stack; | ||
| var props = _extends({ | ||
@@ -285,6 +295,6 @@ message: message, | ||
| }, o); | ||
| var base = null; | ||
| if (o instanceof EvalError) base = 'EvalError';else if (o instanceof RangeError) base = 'RangeError';else if (o instanceof ReferenceError) base = 'ReferenceError';else if (o instanceof SyntaxError) base = 'SyntaxError';else if (o instanceof TypeError) base = 'TypeError';else if (o instanceof URIError) base = 'URIError'; // Build the JSON value: | ||
| if (o instanceof EvalError) base = 'EvalError';else if (o instanceof RangeError) base = 'RangeError';else if (o instanceof ReferenceError) base = 'ReferenceError';else if (o instanceof SyntaxError) base = 'SyntaxError';else if (o instanceof TypeError) base = 'TypeError';else if (o instanceof URIError) base = 'URIError'; | ||
| // Build the JSON value: | ||
| return _extends({ | ||
@@ -294,7 +304,6 @@ base: base | ||
| } | ||
| /** | ||
| * Copies a value, removing any API objects identified in the types. | ||
| */ | ||
| function packItem(table, map, data) { | ||
@@ -304,35 +313,24 @@ switch (map) { | ||
| return data; | ||
| case '?': | ||
| return typeof data; | ||
| case 'd': | ||
| return data.toISOString(); | ||
| case 'e': | ||
| return packError(table, data); | ||
| case 'o': | ||
| return table.getPackedId(data); | ||
| case 's': | ||
| return data[MAGIC_KEY].shareId; | ||
| case 'u': | ||
| return null; | ||
| case 'ab': | ||
| return base64.stringify(new Uint8Array(data)); | ||
| case 'u8': | ||
| return base64.stringify(data); | ||
| case 'M': | ||
| // $FlowFixMe - Flow is incorrect. This is fine. | ||
| return packData(table, Array.from(data.entries())); | ||
| case 'S': | ||
| // $FlowFixMe - Flow is incorrect. This is fine. | ||
| return packData(table, Array.from(data.values())); | ||
| default: | ||
@@ -343,17 +341,13 @@ { | ||
| var _out2 = []; | ||
| for (var i = 0; i < map.length; ++i) { | ||
| _out2[i] = packItem(table, map[i], data[i]); | ||
| } | ||
| return _out2; | ||
| } // Objects: | ||
| } | ||
| // Objects: | ||
| var out = {}; | ||
| for (var n in data) { | ||
| out[n] = n in map ? packItem(table, map[n], data[n]) : data[n]; | ||
| } | ||
| return out; | ||
@@ -363,7 +357,6 @@ } | ||
| } | ||
| /** | ||
| * Restores an error object from its JSON representation. | ||
| */ | ||
| function unpackError(table, value, path) { | ||
@@ -377,20 +370,19 @@ var bases = { | ||
| URIError: URIError | ||
| }; // Make the object: | ||
| }; | ||
| // Make the object: | ||
| var Base = value.base != null ? bases[value.base] || Error : Error; | ||
| var out = new Base(); // Restore the properties: | ||
| var out = new Base(); | ||
| // Restore the properties: | ||
| var props = unpackData(table, value, path, true); | ||
| for (var n in props) { | ||
| out[n] = props[n]; | ||
| } | ||
| return out; | ||
| } | ||
| /** | ||
| * Restores a value that has been sent over the wire. | ||
| */ | ||
| function unpackItem(table, map, raw, path, supress) { | ||
@@ -400,3 +392,2 @@ switch (map) { | ||
| return raw; | ||
| case '?': | ||
@@ -407,6 +398,4 @@ { | ||
| } | ||
| case 'd': | ||
| return new Date(raw); | ||
| case 'e': | ||
@@ -416,5 +405,3 @@ if (typeof raw !== 'object' || raw === null) { | ||
| } | ||
| return unpackError(table, raw, path); | ||
| case 'o': | ||
@@ -425,13 +412,9 @@ { | ||
| } | ||
| if (typeof raw !== 'number') { | ||
| throw new TypeError("Expecting a packedId at " + path); | ||
| } | ||
| var _o = table.getObject(-raw); | ||
| if (_o == null) throw new RangeError("Invalid packedId " + raw + " at " + path); | ||
| return _o; | ||
| } | ||
| case 's': | ||
@@ -442,3 +425,2 @@ { | ||
| } | ||
| var s = sharedData[raw]; | ||
@@ -448,6 +430,4 @@ if (s == null) throw new RangeError("Invalid shareId '" + raw + "' at " + path); | ||
| } | ||
| case 'u': | ||
| return undefined; | ||
| case 'ab': | ||
@@ -457,5 +437,3 @@ if (typeof raw !== 'string') { | ||
| } | ||
| return base64.parse(raw).buffer; | ||
| case 'u8': | ||
@@ -465,5 +443,3 @@ if (typeof raw !== 'string') { | ||
| } | ||
| return base64.parse(raw); | ||
| case 'M': | ||
@@ -474,6 +450,4 @@ { | ||
| } | ||
| return new Map(unpackData(table, raw, path)); | ||
| } | ||
| case 'S': | ||
@@ -484,6 +458,4 @@ { | ||
| } | ||
| return new Set(unpackData(table, raw, path)); | ||
| } | ||
| default: | ||
@@ -494,8 +466,7 @@ { | ||
| } | ||
| if (typeof raw !== 'object' || raw === null) { | ||
| throw new TypeError("Expecting an array or object at " + path); | ||
| } // Arrays: | ||
| } | ||
| // Arrays: | ||
| if (Array.isArray(map)) { | ||
@@ -505,5 +476,3 @@ if (!Array.isArray(raw)) { | ||
| } | ||
| var _out3 = []; | ||
| for (var i = 0; i < map.length; ++i) { | ||
@@ -513,9 +482,7 @@ if (supress === true && map[i] === '?') continue; | ||
| } | ||
| return _out3; | ||
| } // Objects: | ||
| } | ||
| // Objects: | ||
| var out = {}; | ||
| for (var n in raw) { | ||
@@ -525,3 +492,2 @@ if (supress === true && map[n] === '?') continue; | ||
| } | ||
| return out; | ||
@@ -536,2 +502,3 @@ } | ||
| */ | ||
| /** | ||
@@ -541,13 +508,16 @@ * Undoes the effect of `on`. | ||
| /** | ||
| * Signature of the `on` method. | ||
| */ | ||
| // No user-supplied value will ever be identical to this. | ||
| var dirtyValue$1 = {}; | ||
| /** | ||
| * Subscribes to an event on a bridgeable object. | ||
| */ | ||
| function addListener(o, name, f) { | ||
| var _getInstanceMagic = getInstanceMagic(o), | ||
| closed = _getInstanceMagic.closed, | ||
| listeners = _getInstanceMagic.listeners; | ||
| closed = _getInstanceMagic.closed, | ||
| listeners = _getInstanceMagic.listeners; | ||
| if (closed) return function () {}; | ||
@@ -561,12 +531,12 @@ if (listeners[name] == null) listeners[name] = [f];else listeners[name].push(f); | ||
| } | ||
| /** | ||
| * Subscribes to property changes on a bridgeable object. | ||
| */ | ||
| function addWatcher(o, name, f) { | ||
| var _getInstanceMagic2 = getInstanceMagic(o), | ||
| closed = _getInstanceMagic2.closed, | ||
| watchers = _getInstanceMagic2.watchers; // Don't catch access errors, since we want the user to see them: | ||
| closed = _getInstanceMagic2.closed, | ||
| watchers = _getInstanceMagic2.watchers; | ||
| // Don't catch access errors, since we want the user to see them: | ||
| var data = o[name]; | ||
@@ -584,2 +554,3 @@ if (closed) return function () {}; | ||
| } | ||
| /** | ||
@@ -590,8 +561,7 @@ * Destroys a proxy. | ||
| */ | ||
| function close(o) { | ||
| var magic = getInstanceMagic(o); // Call local callbacks: | ||
| var magic = getInstanceMagic(o); | ||
| // Call local callbacks: | ||
| var listeners = magic.listeners.close; | ||
| if (listeners != null) { | ||
@@ -603,5 +573,3 @@ for (var _i2 = 0; _i2 < listeners.length; _i2++) { | ||
| } | ||
| magic.closed = true; | ||
| for (var _i4 = 0, _magic$bridges2 = magic.bridges; _i4 < _magic$bridges2.length; _i4++) { | ||
@@ -611,3 +579,2 @@ var bridge = _magic$bridges2[_i4]; | ||
| } | ||
| magic.bridges = []; | ||
@@ -617,10 +584,11 @@ magic.listeners = {}; | ||
| } | ||
| /** | ||
| * Emits an event on a bridgeable object. | ||
| */ | ||
| function emit(o, name, payload) { | ||
| var magic = getInstanceMagic(o); | ||
| if (magic.closed) throw new Error('Cannot emit event on closed object'); // Schedule outgoing event messages: | ||
| if (magic.closed) throw new Error('Cannot emit event on closed object'); | ||
| // Schedule outgoing event messages: | ||
| for (var _i6 = 0, _magic$bridges4 = magic.bridges; _i6 < _magic$bridges4.length; _i6++) { | ||
@@ -630,6 +598,3 @@ var bridge = _magic$bridges4[_i6]; | ||
| } // Call local callbacks: | ||
| var listeners = magic.listeners[name]; | ||
| if (listeners != null) { | ||
@@ -642,32 +607,26 @@ for (var _i8 = 0; _i8 < listeners.length; _i8++) { | ||
| } | ||
| /** | ||
| * Marks an object as having changes. The proxy server will send an update. | ||
| */ | ||
| function update(o, name) { | ||
| var magic = getInstanceMagic(o); | ||
| if (magic.closed) throw new Error('Cannot update closed object'); | ||
| for (var _i10 = 0, _magic$bridges6 = magic.bridges; _i10 < _magic$bridges6.length; _i10++) { | ||
| var bridge = _magic$bridges6[_i10]; | ||
| for (var _i0 = 0, _magic$bridges6 = magic.bridges; _i0 < _magic$bridges6.length; _i0++) { | ||
| var bridge = _magic$bridges6[_i0]; | ||
| bridge.markDirty(magic.localId, name); | ||
| } // Blow away the cache if we have a name: | ||
| if (name != null && magic.watchers[name] != null) { | ||
| magic.watchers[name].data = dirtyValue$1; | ||
| } // Call watcher callbacks: | ||
| } | ||
| // Call watcher callbacks: | ||
| for (var n in magic.watchers) { | ||
| var cache = magic.watchers[n]; | ||
| try { | ||
| var data = o[n]; | ||
| if (data !== cache.data) { | ||
| cache.data = data; | ||
| for (var _i12 = 0, _cache$fs2 = cache.fs; _i12 < _cache$fs2.length; _i12++) { | ||
| var _f3 = _cache$fs2[_i12]; | ||
| for (var _i10 = 0, _cache$fs2 = cache.fs; _i10 < _cache$fs2.length; _i10++) { | ||
| var _f3 = _cache$fs2[_i10]; | ||
| callCallback(o, _f3, cache.data, true); | ||
@@ -679,10 +638,11 @@ } | ||
| } | ||
| /** | ||
| * Calls a user-supplied callback function with error checking. | ||
| */ | ||
| function callCallback(o, f, payload, emitError) { | ||
| try { | ||
| var out = f(payload); // If the function returns a promise, emit an error if it rejects: | ||
| var out = f(payload); | ||
| // If the function returns a promise, emit an error if it rejects: | ||
| if (emitError && out != null && typeof out.then === 'function') { | ||
@@ -705,2 +665,3 @@ out.then(undefined, function (e) { | ||
| var dirtyValue = {}; | ||
| /** | ||
@@ -710,3 +671,2 @@ * Examines a bridgeable object and prepares it for sending of the wire. | ||
| */ | ||
| function packObject(state, o) { | ||
@@ -716,7 +676,5 @@ // Iterate the prototype chain, looking for property names: | ||
| var end = Object.prototype; | ||
| for (var p = o; p !== end && p != null; p = Object.getPrototypeOf(p)) { | ||
| for (var _i2 = 0, _Object$getOwnPropert2 = Object.getOwnPropertyNames(p); _i2 < _Object$getOwnPropert2.length; _i2++) { | ||
| var _name = _Object$getOwnPropert2[_i2]; | ||
| if (_name !== MAGIC_KEY && !/^_/.test(_name) && _name !== 'constructor') { | ||
@@ -726,14 +684,12 @@ allNames[_name] = true; | ||
| } | ||
| } // Iterate over the object's properties and add their names to | ||
| } | ||
| // Iterate over the object's properties and add their names to | ||
| // the method list or the value cache. | ||
| var cache = {}; | ||
| var methods = []; | ||
| var props = {}; | ||
| for (var n in allNames) { | ||
| try { | ||
| var data = o[n]; | ||
| if (typeof data === 'function' && (data[MAGIC_KEY] == null || data[MAGIC_KEY].shareId == null)) { | ||
@@ -750,6 +706,4 @@ methods.push(n); | ||
| } | ||
| var _getInstanceMagic = getInstanceMagic(o), | ||
| localId = _getInstanceMagic.localId; | ||
| localId = _getInstanceMagic.localId; | ||
| var create = { | ||
@@ -765,2 +719,3 @@ localId: localId, | ||
| } | ||
| /** | ||
@@ -770,11 +725,8 @@ * Checks an object for changes. | ||
| */ | ||
| function diffObject(state, o, cache) { | ||
| var dirty = false; | ||
| var props = {}; | ||
| for (var n in cache) { | ||
| try { | ||
| var value = o[n]; | ||
| if (value !== cache[n]) { | ||
@@ -790,3 +742,2 @@ dirty = true; | ||
| } | ||
| return { | ||
@@ -797,2 +748,3 @@ dirty: dirty, | ||
| } | ||
| /** | ||
@@ -803,11 +755,12 @@ * Creates an object proxy. | ||
| */ | ||
| function makeProxy(state, create) { | ||
| var props = {}; // Make the magic property descriptor: | ||
| var props = {}; | ||
| // Make the magic property descriptor: | ||
| var magic = makeProxyMagic(create.localId); | ||
| props[MAGIC_KEY] = { | ||
| value: magic | ||
| }; // Add the getters: | ||
| }; | ||
| // Add the getters: | ||
| for (var n in create.props) { | ||
@@ -818,5 +771,5 @@ props[n] = { | ||
| }; | ||
| } // Add the methods: | ||
| } | ||
| // Add the methods: | ||
| for (var _i4 = 0, _create$methods2 = create.methods; _i4 < _create$methods2.length; _i4++) { | ||
@@ -828,13 +781,10 @@ var _n = _create$methods2[_i4]; | ||
| } // Make the object: | ||
| return Object.create(Object.prototype, props); | ||
| } | ||
| /** | ||
| * Unpacks a proxy's properties into the magic storage area. | ||
| */ | ||
| function updateObjectProps(state, o, props) { | ||
| var magic = o[MAGIC_KEY]; | ||
| for (var n in props) { | ||
@@ -850,3 +800,2 @@ try { | ||
| } | ||
| function makeProxyGetter(magic, name) { | ||
@@ -858,3 +807,2 @@ return function get() { | ||
| } | ||
| function makeProxyMethod(state, magic, name) { | ||
@@ -865,7 +813,5 @@ return function method() { | ||
| } | ||
| for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
| args[_key] = arguments[_key]; | ||
| } | ||
| return state.emitCall(magic.remoteId, name, args); | ||
@@ -877,30 +823,41 @@ }; | ||
| // Options: | ||
| // Objects: | ||
| // Outgoing method calls: | ||
| // Pending message: | ||
| // Update scheduling: | ||
| function BridgeState(opts) { | ||
| var _opts$hideProperties = opts.hideProperties, | ||
| hideProperties = _opts$hideProperties === void 0 ? [] : _opts$hideProperties, | ||
| sendMessage = opts.sendMessage, | ||
| _opts$throttleMs = opts.throttleMs, | ||
| throttleMs = _opts$throttleMs === void 0 ? 0 : _opts$throttleMs; // Options: | ||
| hideProperties = _opts$hideProperties === void 0 ? [] : _opts$hideProperties, | ||
| sendMessage = opts.sendMessage, | ||
| _opts$throttleMs = opts.throttleMs, | ||
| throttleMs = _opts$throttleMs === void 0 ? 0 : _opts$throttleMs; | ||
| // Options: | ||
| this.hideProperties = hideProperties; | ||
| this.sendMessage = sendMessage; | ||
| this.throttleMs = throttleMs; // Objects: | ||
| this.throttleMs = throttleMs; | ||
| // Objects: | ||
| this.proxies = {}; | ||
| this.objects = {}; | ||
| this.caches = {}; // Outgoing method calls: | ||
| this.caches = {}; | ||
| // Outgoing method calls: | ||
| this.nextCallId = 0; | ||
| this.pendingCalls = {}; // Pending message: | ||
| this.pendingCalls = {}; | ||
| // Pending message: | ||
| this.dirty = {}; | ||
| this.message = {}; // Update scheduling: | ||
| this.message = {}; | ||
| // Update scheduling: | ||
| this.lastUpdate = 0; | ||
| this.sendPending = false; | ||
| } | ||
| /** | ||
@@ -911,6 +868,3 @@ * Close the bridge, so it will no longer send messages. | ||
| */ | ||
| var _proto = BridgeState.prototype; | ||
| _proto.close = function close$1(error) { | ||
@@ -921,17 +875,15 @@ for (var _callId in this.pendingCalls) { | ||
| } | ||
| for (var _objectId in this.proxies) { | ||
| close(this.proxies[Number(_objectId)]); | ||
| } | ||
| this.closed = true; | ||
| } | ||
| /** | ||
| * Grabs an object by its proxy id. | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.getObject = function getObject(packedId) { | ||
| return packedId < 0 ? this.proxies[-packedId] : this.objects[packedId]; | ||
| } | ||
| /** | ||
@@ -941,21 +893,15 @@ * Returns an object's id relative to this bridge. | ||
| * and negative for proxy objects reflecting things on the other side. | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.getPackedId = function getPackedId(o) { | ||
| var magic = getInstanceMagic(o); | ||
| if (magic.closed) return null; | ||
| if (magic.remoteId != null && this.proxies[magic.remoteId] != null) { | ||
| return -magic.remoteId; | ||
| } | ||
| if (this.objects[magic.localId] == null) { | ||
| // Add unknown objects to the bridge: | ||
| this.objects[magic.localId] = o; | ||
| var _packObject = packObject(this, o), | ||
| cache = _packObject.cache, | ||
| create = _packObject.create; | ||
| cache = _packObject.cache, | ||
| create = _packObject.create; | ||
| this.caches[magic.localId] = cache; | ||
@@ -965,10 +911,8 @@ magic.bridges.push(this); | ||
| } | ||
| return magic.localId; | ||
| } | ||
| /** | ||
| * Marks an object as needing changes. | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.markDirty = function markDirty(localId, name) { | ||
@@ -983,7 +927,6 @@ var cache = this.caches[localId]; | ||
| } | ||
| /** | ||
| * Marks an object as being deleted. | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.emitClose = function emitClose(localId) { | ||
@@ -996,21 +939,18 @@ delete this.objects[localId]; | ||
| } | ||
| /** | ||
| * Attaches an object to this bridge, sending a creation message. | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.emitCreate = function emitCreate(create, o) { | ||
| if (this.message.created == null) this.message.created = []; | ||
| this.message.created.push(create); // this.wakeup() not needed, since this is part of data packing. | ||
| this.message.created.push(create); | ||
| // this.wakeup() not needed, since this is part of data packing. | ||
| } | ||
| /** | ||
| * Enqueues a proxy call message. | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.emitCall = function emitCall(remoteId, name, args) { | ||
| var _this = this; | ||
| var callId = this.nextCallId++; | ||
| var message = _extends({ | ||
@@ -1021,3 +961,2 @@ callId: callId, | ||
| }, packData(this, args)); | ||
| if (this.message.calls == null) this.message.calls = []; | ||
@@ -1034,7 +973,6 @@ this.message.calls.push(message); | ||
| } | ||
| /** | ||
| * Enqueues an event message. | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.emitEvent = function emitEvent(localId, name, payload) { | ||
@@ -1045,3 +983,2 @@ var message = _extends({ | ||
| }, packData(this, payload)); | ||
| if (this.message.events == null) this.message.events = []; | ||
@@ -1051,7 +988,6 @@ this.message.events.push(message); | ||
| } | ||
| /** | ||
| * Enqueues a function return message. | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.emitReturn = function emitReturn(callId, fail, value) { | ||
@@ -1061,3 +997,2 @@ var message = _extends({ | ||
| }, fail ? packThrow(this, value) : packData(this, value)); | ||
| if (this.message.returns == null) this.message.returns = []; | ||
@@ -1067,14 +1002,13 @@ this.message.returns.push(message); | ||
| } | ||
| /** | ||
| * Handles an incoming message, | ||
| * updating state and triggering side-effects as needed. | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.handleMessage = function handleMessage(message) { | ||
| var _this2 = this; | ||
| // ---------------------------------------- | ||
| // Phase 1: Get our proxies up to date. | ||
| // ---------------------------------------- | ||
| // Handle newly-created objects: | ||
@@ -1087,4 +1021,2 @@ if (message.created) { | ||
| } // Pass 2: Fill in the values: | ||
| for (var _i4 = 0, _message$created4 = message.created; _i4 < _message$created4.length; _i4++) { | ||
@@ -1094,5 +1026,5 @@ var _create = _message$created4[_i4]; | ||
| } | ||
| } // Handle updated objects: | ||
| } | ||
| // Handle updated objects: | ||
| if (message.changed) { | ||
@@ -1103,13 +1035,9 @@ // Pass 1: Update all the proxies: | ||
| var _localId = change.localId, | ||
| props = change.props; | ||
| props = change.props; | ||
| var o = this.proxies[_localId]; | ||
| if (o == null) { | ||
| throw new RangeError("Invalid localId " + _localId); | ||
| } | ||
| updateObjectProps(this, o, props); | ||
| } // Pass 2: Fire the callbacks: | ||
| for (var _i8 = 0, _message$changed4 = message.changed; _i8 < _message$changed4.length; _i8++) { | ||
@@ -1119,18 +1047,16 @@ var _change = _message$changed4[_i8]; | ||
| } | ||
| } // ---------------------------------------- | ||
| } | ||
| // ---------------------------------------- | ||
| // Phase 2: Handle events & method calls | ||
| // ---------------------------------------- | ||
| // Handle events: | ||
| if (message.events) { | ||
| for (var _i10 = 0, _message$events2 = message.events; _i10 < _message$events2.length; _i10++) { | ||
| var event = _message$events2[_i10]; | ||
| for (var _i0 = 0, _message$events2 = message.events; _i0 < _message$events2.length; _i0++) { | ||
| var event = _message$events2[_i0]; | ||
| var _localId2 = event.localId, | ||
| name = event.name; | ||
| name = event.name; | ||
| var _o = _localId2 === 0 ? this : this.proxies[_localId2]; | ||
| if (_o == null) continue; | ||
| try { | ||
@@ -1142,23 +1068,19 @@ emit(_o, name, unpackData(this, event, name)); | ||
| } | ||
| } // Handle method calls: | ||
| } | ||
| // Handle method calls: | ||
| if (message.calls) { | ||
| var _loop = function _loop(_i12, _message$calls2) { | ||
| var call = _message$calls2[_i12]; | ||
| var _loop = function _loop(_i10, _message$calls2) { | ||
| var call = _message$calls2[_i10]; | ||
| var callId = call.callId, | ||
| remoteId = call.remoteId, | ||
| name = call.name; | ||
| remoteId = call.remoteId, | ||
| name = call.name; | ||
| try { | ||
| var _o2 = _this2.objects[remoteId]; | ||
| if (_o2 == null) { | ||
| throw new TypeError("Cannot call method '" + name + "' of closed proxy (remote)"); | ||
| } | ||
| if (typeof _o2[name] !== 'function') { | ||
| throw new TypeError("'" + name + "' is not a function"); | ||
| } | ||
| var args = unpackData(_this2, call, name + ".arguments"); | ||
@@ -1174,19 +1096,16 @@ Promise.resolve(_o2[name].apply(_o2, args)).then(function (value) { | ||
| }; | ||
| for (var _i12 = 0, _message$calls2 = message.calls; _i12 < _message$calls2.length; _i12++) { | ||
| _loop(_i12, _message$calls2); | ||
| for (var _i10 = 0, _message$calls2 = message.calls; _i10 < _message$calls2.length; _i10++) { | ||
| _loop(_i10, _message$calls2); | ||
| } | ||
| } // Handle method returns: | ||
| } | ||
| // Handle method returns: | ||
| if (message.returns) { | ||
| for (var _i14 = 0, _message$returns2 = message.returns; _i14 < _message$returns2.length; _i14++) { | ||
| var ret = _message$returns2[_i14]; | ||
| for (var _i12 = 0, _message$returns2 = message.returns; _i12 < _message$returns2.length; _i12++) { | ||
| var ret = _message$returns2[_i12]; | ||
| var _callId2 = ret.callId; | ||
| var pendingCall = this.pendingCalls[_callId2]; | ||
| if (pendingCall == null) { | ||
| throw new RangeError("Invalid callId " + _callId2); | ||
| } | ||
| try { | ||
@@ -1200,14 +1119,14 @@ pendingCall.resolve(unpackData(this, ret, pendingCall.name + ".return")); | ||
| } | ||
| } // ---------------------------------------- | ||
| } | ||
| // ---------------------------------------- | ||
| // Phase 3: Clean up closed objects | ||
| // ---------------------------------------- | ||
| if (message.closed) { | ||
| for (var _i16 = 0, _message$closed2 = message.closed; _i16 < _message$closed2.length; _i16++) { | ||
| var _localId3 = _message$closed2[_i16]; | ||
| for (var _i14 = 0, _message$closed2 = message.closed; _i14 < _message$closed2.length; _i14++) { | ||
| var _localId3 = _message$closed2[_i14]; | ||
| var _o3 = this.proxies[_localId3]; | ||
| if (_o3 == null) return; | ||
| delete this.proxies[_localId3]; | ||
| close(_o3); | ||
@@ -1217,21 +1136,18 @@ } | ||
| } | ||
| /** | ||
| * Sends the current message. | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.sendNow = function sendNow() { | ||
| if (this.closed) return; // Build change messages: | ||
| if (this.closed) return; | ||
| // Build change messages: | ||
| for (var id in this.dirty) { | ||
| var _localId4 = Number(id); | ||
| var _this$dirty$_localId = this.dirty[_localId4], | ||
| object = _this$dirty$_localId.object, | ||
| cache = _this$dirty$_localId.cache; | ||
| object = _this$dirty$_localId.object, | ||
| cache = _this$dirty$_localId.cache; | ||
| var _diffObject = diffObject(this, object, cache), | ||
| dirty = _diffObject.dirty, | ||
| props = _diffObject.props; | ||
| dirty = _diffObject.dirty, | ||
| props = _diffObject.props; | ||
| if (dirty) { | ||
@@ -1246,7 +1162,5 @@ var _message = { | ||
| } | ||
| var message = this.message; | ||
| this.dirty = {}; | ||
| this.message = {}; | ||
| if (message.calls != null || message.changed != null || message.closed != null || message.created != null || message.events != null || message.returns != null) { | ||
@@ -1256,26 +1170,21 @@ this.sendMessage(message); | ||
| } | ||
| /** | ||
| * Something has changed, so prepare to send the pending message: | ||
| */ | ||
| ; | ||
| */; | ||
| _proto.wakeup = function wakeup() { | ||
| var _this3 = this; | ||
| if (this.sendPending) return; | ||
| this.sendPending = true; | ||
| var task = function task() { | ||
| _this3.sendPending = false; | ||
| _this3.lastUpdate = Date.now(); | ||
| _this3.sendNow(); | ||
| }; | ||
| _this3.sendNow(); | ||
| }; // We really do want `setTimeout` here, even if the delay is 0, | ||
| // We really do want `setTimeout` here, even if the delay is 0, | ||
| // since promises and other micro tasks should fire first. | ||
| var delay = this.lastUpdate + this.throttleMs - Date.now(); | ||
| setTimeout(task, delay < 0 ? 0 : delay); | ||
| }; | ||
| return BridgeState; | ||
@@ -1286,2 +1195,14 @@ }(); | ||
| /** | ||
| * The bridge sends messages using this function. | ||
| */ | ||
| /** | ||
| * Options used to create a new bridge. | ||
| */ | ||
| /** | ||
| * Options used to create a new local bridge. | ||
| */ | ||
| /** | ||
| * An object bridge. | ||
@@ -1292,3 +1213,2 @@ */ | ||
| var _this = this; | ||
| this._state = new BridgeState(opts); | ||
@@ -1299,23 +1219,18 @@ this._rootPromise = new Promise(function (resolve) { | ||
| } | ||
| var _proto = Bridge.prototype; | ||
| _proto.handleMessage = function handleMessage(message) { | ||
| this._state.handleMessage(message); | ||
| }; | ||
| _proto.getRoot = function getRoot() { | ||
| return this._rootPromise; | ||
| }; | ||
| _proto.sendRoot = function sendRoot(root) { | ||
| this._state.emitEvent(0, 'root', root); | ||
| }; | ||
| _proto.close = function close(error) { | ||
| this._state.close(error); | ||
| }; | ||
| return Bridge; | ||
| }(); | ||
| /** | ||
@@ -1326,3 +1241,2 @@ * Bridges a single object locally. This is great for unit tests, | ||
| */ | ||
| function makeLocalBridge(o, opts) { | ||
@@ -1332,12 +1246,10 @@ if (opts === void 0) { | ||
| } | ||
| function nopClone(m) { | ||
| return m; | ||
| } | ||
| var _opts = opts, | ||
| _opts$cloneMessage = _opts.cloneMessage, | ||
| cloneMessage = _opts$cloneMessage === void 0 ? nopClone : _opts$cloneMessage, | ||
| hideProperties = _opts.hideProperties, | ||
| throttleMs = _opts.throttleMs; | ||
| _opts$cloneMessage = _opts.cloneMessage, | ||
| cloneMessage = _opts$cloneMessage === void 0 ? nopClone : _opts$cloneMessage, | ||
| hideProperties = _opts.hideProperties, | ||
| throttleMs = _opts.throttleMs; | ||
| var serverState = new BridgeState({ | ||
@@ -1366,6 +1278,6 @@ sendMessage: function sendMessage(message) { | ||
| */ | ||
| var onMethod = function on(name, f) { | ||
| return addListener(this, name, f); | ||
| }; | ||
| /** | ||
@@ -1375,3 +1287,2 @@ * The `watch` function, | ||
| */ | ||
| var watchMethod = function watch(name, f) { | ||
@@ -1384,26 +1295,22 @@ return addWatcher(this, name, f); | ||
| }); | ||
| /** | ||
| * The base class for all bridgeable API's. Provides callback capability. | ||
| */ | ||
| var Bridgeable = /*#__PURE__*/function () { | ||
| function Bridgeable() {} | ||
| var _proto = Bridgeable.prototype; | ||
| _proto._close = function _close() { | ||
| close(this); | ||
| }; | ||
| _proto._emit = function _emit(name, payload) { | ||
| return emit(this, name, payload); | ||
| }; | ||
| _proto._update = function _update(name) { | ||
| update(this, name); | ||
| }; | ||
| return Bridgeable; | ||
| }(); // Put the shared methods onto the prototype: | ||
| }(); | ||
| // Put the shared methods onto the prototype: | ||
| var hack = Bridgeable.prototype; | ||
@@ -1410,0 +1317,0 @@ hack.on = onMethod; |
+7
-4
| { | ||
| "name": "yaob", | ||
| "version": "0.3.12", | ||
| "version": "0.4.0", | ||
| "description": "Bridges an object-oriented API across a messaging layer", | ||
@@ -64,11 +64,14 @@ "repository": { | ||
| "lint-staged": "^10.5.3", | ||
| "mocha": "^8.4.0", | ||
| "mocha": "^10.6.0", | ||
| "prettier": "^2.2.0", | ||
| "rimraf": "^3.0.2", | ||
| "rollup": "^2.48.0", | ||
| "rollup-plugin-filesize": "^9.1.1", | ||
| "rollup": "^2.80.0", | ||
| "rollup-plugin-filesize": "^10.0.0", | ||
| "rollup-plugin-flow-entry": "^0.3.5", | ||
| "source-map-support": "^0.5.19", | ||
| "typescript": "^4.1.2" | ||
| }, | ||
| "overrides": { | ||
| "get-func-name": "2.0.2" | ||
| } | ||
| } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Unstable ownership
Supply chain riskA new collaborator has begun publishing package versions. Package stability and security risk may be elevated.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
281613
6.71%3625
3.31%1
Infinity%1
Infinity%