@graffy/core
Advanced tools
Comparing version 0.6.0 to 0.7.0
1857
bundle.js
@@ -1,1855 +0,2 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var mergeWith = _interopDefault(require('lodash/mergeWith')); | ||
var sortedIndex = _interopDefault(require('lodash/sortedIndex')); | ||
var sortedLastIndex = _interopDefault(require('lodash/sortedLastIndex')); | ||
var isEmpty = _interopDefault(require('lodash/isEmpty')); | ||
var isEqual = _interopDefault(require('lodash/isEqual')); | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var runtime = createCommonjsModule(function (module) { | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
!(function(global) { | ||
var Op = Object.prototype; | ||
var hasOwn = Op.hasOwnProperty; | ||
var undefined$1; // More compressible than void 0. | ||
var $Symbol = typeof Symbol === "function" ? Symbol : {}; | ||
var iteratorSymbol = $Symbol.iterator || "@@iterator"; | ||
var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator"; | ||
var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; | ||
var runtime = global.regeneratorRuntime; | ||
if (runtime) { | ||
{ | ||
// If regeneratorRuntime is defined globally and we're in a module, | ||
// make the exports object identical to regeneratorRuntime. | ||
module.exports = runtime; | ||
} | ||
// Don't bother evaluating the rest of this file if the runtime was | ||
// already defined globally. | ||
return; | ||
} | ||
// Define the runtime globally (as expected by generated code) as either | ||
// module.exports (if we're in a module) or a new, empty object. | ||
runtime = global.regeneratorRuntime = module.exports; | ||
function wrap(innerFn, outerFn, self, tryLocsList) { | ||
// If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator. | ||
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator; | ||
var generator = Object.create(protoGenerator.prototype); | ||
var context = new Context(tryLocsList || []); | ||
// The ._invoke method unifies the implementations of the .next, | ||
// .throw, and .return methods. | ||
generator._invoke = makeInvokeMethod(innerFn, self, context); | ||
return generator; | ||
} | ||
runtime.wrap = wrap; | ||
// Try/catch helper to minimize deoptimizations. Returns a completion | ||
// record like context.tryEntries[i].completion. This interface could | ||
// have been (and was previously) designed to take a closure to be | ||
// invoked without arguments, but in all the cases we care about we | ||
// already have an existing method we want to call, so there's no need | ||
// to create a new function object. We can even get away with assuming | ||
// the method takes exactly one argument, since that happens to be true | ||
// in every case, so we don't have to touch the arguments object. The | ||
// only additional allocation required is the completion record, which | ||
// has a stable shape and so hopefully should be cheap to allocate. | ||
function tryCatch(fn, obj, arg) { | ||
try { | ||
return { type: "normal", arg: fn.call(obj, arg) }; | ||
} catch (err) { | ||
return { type: "throw", arg: err }; | ||
} | ||
} | ||
var GenStateSuspendedStart = "suspendedStart"; | ||
var GenStateSuspendedYield = "suspendedYield"; | ||
var GenStateExecuting = "executing"; | ||
var GenStateCompleted = "completed"; | ||
// Returning this object from the innerFn has the same effect as | ||
// breaking out of the dispatch switch statement. | ||
var ContinueSentinel = {}; | ||
// Dummy constructor functions that we use as the .constructor and | ||
// .constructor.prototype properties for functions that return Generator | ||
// objects. For full spec compliance, you may wish to configure your | ||
// minifier not to mangle the names of these two functions. | ||
function Generator() {} | ||
function GeneratorFunction() {} | ||
function GeneratorFunctionPrototype() {} | ||
// This is a polyfill for %IteratorPrototype% for environments that | ||
// don't natively support it. | ||
var IteratorPrototype = {}; | ||
IteratorPrototype[iteratorSymbol] = function () { | ||
return this; | ||
}; | ||
var getProto = Object.getPrototypeOf; | ||
var NativeIteratorPrototype = getProto && getProto(getProto(values([]))); | ||
if (NativeIteratorPrototype && | ||
NativeIteratorPrototype !== Op && | ||
hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) { | ||
// This environment has a native %IteratorPrototype%; use it instead | ||
// of the polyfill. | ||
IteratorPrototype = NativeIteratorPrototype; | ||
} | ||
var Gp = GeneratorFunctionPrototype.prototype = | ||
Generator.prototype = Object.create(IteratorPrototype); | ||
GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype; | ||
GeneratorFunctionPrototype.constructor = GeneratorFunction; | ||
GeneratorFunctionPrototype[toStringTagSymbol] = | ||
GeneratorFunction.displayName = "GeneratorFunction"; | ||
// Helper for defining the .next, .throw, and .return methods of the | ||
// Iterator interface in terms of a single ._invoke method. | ||
function defineIteratorMethods(prototype) { | ||
["next", "throw", "return"].forEach(function(method) { | ||
prototype[method] = function(arg) { | ||
return this._invoke(method, arg); | ||
}; | ||
}); | ||
} | ||
runtime.isGeneratorFunction = function(genFun) { | ||
var ctor = typeof genFun === "function" && genFun.constructor; | ||
return ctor | ||
? ctor === GeneratorFunction || | ||
// For the native GeneratorFunction constructor, the best we can | ||
// do is to check its .name property. | ||
(ctor.displayName || ctor.name) === "GeneratorFunction" | ||
: false; | ||
}; | ||
runtime.mark = function(genFun) { | ||
if (Object.setPrototypeOf) { | ||
Object.setPrototypeOf(genFun, GeneratorFunctionPrototype); | ||
} else { | ||
genFun.__proto__ = GeneratorFunctionPrototype; | ||
if (!(toStringTagSymbol in genFun)) { | ||
genFun[toStringTagSymbol] = "GeneratorFunction"; | ||
} | ||
} | ||
genFun.prototype = Object.create(Gp); | ||
return genFun; | ||
}; | ||
// Within the body of any async function, `await x` is transformed to | ||
// `yield regeneratorRuntime.awrap(x)`, so that the runtime can test | ||
// `hasOwn.call(value, "__await")` to determine if the yielded value is | ||
// meant to be awaited. | ||
runtime.awrap = function(arg) { | ||
return { __await: arg }; | ||
}; | ||
function AsyncIterator(generator) { | ||
function invoke(method, arg, resolve, reject) { | ||
var record = tryCatch(generator[method], generator, arg); | ||
if (record.type === "throw") { | ||
reject(record.arg); | ||
} else { | ||
var result = record.arg; | ||
var value = result.value; | ||
if (value && | ||
typeof value === "object" && | ||
hasOwn.call(value, "__await")) { | ||
return Promise.resolve(value.__await).then(function(value) { | ||
invoke("next", value, resolve, reject); | ||
}, function(err) { | ||
invoke("throw", err, resolve, reject); | ||
}); | ||
} | ||
return Promise.resolve(value).then(function(unwrapped) { | ||
// When a yielded Promise is resolved, its final value becomes | ||
// the .value of the Promise<{value,done}> result for the | ||
// current iteration. | ||
result.value = unwrapped; | ||
resolve(result); | ||
}, function(error) { | ||
// If a rejected Promise was yielded, throw the rejection back | ||
// into the async generator function so it can be handled there. | ||
return invoke("throw", error, resolve, reject); | ||
}); | ||
} | ||
} | ||
var previousPromise; | ||
function enqueue(method, arg) { | ||
function callInvokeWithMethodAndArg() { | ||
return new Promise(function(resolve, reject) { | ||
invoke(method, arg, resolve, reject); | ||
}); | ||
} | ||
return previousPromise = | ||
// If enqueue has been called before, then we want to wait until | ||
// all previous Promises have been resolved before calling invoke, | ||
// so that results are always delivered in the correct order. If | ||
// enqueue has not been called before, then it is important to | ||
// call invoke immediately, without waiting on a callback to fire, | ||
// so that the async generator function has the opportunity to do | ||
// any necessary setup in a predictable way. This predictability | ||
// is why the Promise constructor synchronously invokes its | ||
// executor callback, and why async functions synchronously | ||
// execute code before the first await. Since we implement simple | ||
// async functions in terms of async generators, it is especially | ||
// important to get this right, even though it requires care. | ||
previousPromise ? previousPromise.then( | ||
callInvokeWithMethodAndArg, | ||
// Avoid propagating failures to Promises returned by later | ||
// invocations of the iterator. | ||
callInvokeWithMethodAndArg | ||
) : callInvokeWithMethodAndArg(); | ||
} | ||
// Define the unified helper method that is used to implement .next, | ||
// .throw, and .return (see defineIteratorMethods). | ||
this._invoke = enqueue; | ||
} | ||
defineIteratorMethods(AsyncIterator.prototype); | ||
AsyncIterator.prototype[asyncIteratorSymbol] = function () { | ||
return this; | ||
}; | ||
runtime.AsyncIterator = AsyncIterator; | ||
// Note that simple async functions are implemented on top of | ||
// AsyncIterator objects; they just return a Promise for the value of | ||
// the final result produced by the iterator. | ||
runtime.async = function(innerFn, outerFn, self, tryLocsList) { | ||
var iter = new AsyncIterator( | ||
wrap(innerFn, outerFn, self, tryLocsList) | ||
); | ||
return runtime.isGeneratorFunction(outerFn) | ||
? iter // If outerFn is a generator, return the full iterator. | ||
: iter.next().then(function(result) { | ||
return result.done ? result.value : iter.next(); | ||
}); | ||
}; | ||
function makeInvokeMethod(innerFn, self, context) { | ||
var state = GenStateSuspendedStart; | ||
return function invoke(method, arg) { | ||
if (state === GenStateExecuting) { | ||
throw new Error("Generator is already running"); | ||
} | ||
if (state === GenStateCompleted) { | ||
if (method === "throw") { | ||
throw arg; | ||
} | ||
// Be forgiving, per 25.3.3.3.3 of the spec: | ||
// https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume | ||
return doneResult(); | ||
} | ||
context.method = method; | ||
context.arg = arg; | ||
while (true) { | ||
var delegate = context.delegate; | ||
if (delegate) { | ||
var delegateResult = maybeInvokeDelegate(delegate, context); | ||
if (delegateResult) { | ||
if (delegateResult === ContinueSentinel) continue; | ||
return delegateResult; | ||
} | ||
} | ||
if (context.method === "next") { | ||
// Setting context._sent for legacy support of Babel's | ||
// function.sent implementation. | ||
context.sent = context._sent = context.arg; | ||
} else if (context.method === "throw") { | ||
if (state === GenStateSuspendedStart) { | ||
state = GenStateCompleted; | ||
throw context.arg; | ||
} | ||
context.dispatchException(context.arg); | ||
} else if (context.method === "return") { | ||
context.abrupt("return", context.arg); | ||
} | ||
state = GenStateExecuting; | ||
var record = tryCatch(innerFn, self, context); | ||
if (record.type === "normal") { | ||
// If an exception is thrown from innerFn, we leave state === | ||
// GenStateExecuting and loop back for another invocation. | ||
state = context.done | ||
? GenStateCompleted | ||
: GenStateSuspendedYield; | ||
if (record.arg === ContinueSentinel) { | ||
continue; | ||
} | ||
return { | ||
value: record.arg, | ||
done: context.done | ||
}; | ||
} else if (record.type === "throw") { | ||
state = GenStateCompleted; | ||
// Dispatch the exception by looping back around to the | ||
// context.dispatchException(context.arg) call above. | ||
context.method = "throw"; | ||
context.arg = record.arg; | ||
} | ||
} | ||
}; | ||
} | ||
// Call delegate.iterator[context.method](context.arg) and handle the | ||
// result, either by returning a { value, done } result from the | ||
// delegate iterator, or by modifying context.method and context.arg, | ||
// setting context.delegate to null, and returning the ContinueSentinel. | ||
function maybeInvokeDelegate(delegate, context) { | ||
var method = delegate.iterator[context.method]; | ||
if (method === undefined$1) { | ||
// A .throw or .return when the delegate iterator has no .throw | ||
// method always terminates the yield* loop. | ||
context.delegate = null; | ||
if (context.method === "throw") { | ||
if (delegate.iterator.return) { | ||
// If the delegate iterator has a return method, give it a | ||
// chance to clean up. | ||
context.method = "return"; | ||
context.arg = undefined$1; | ||
maybeInvokeDelegate(delegate, context); | ||
if (context.method === "throw") { | ||
// If maybeInvokeDelegate(context) changed context.method from | ||
// "return" to "throw", let that override the TypeError below. | ||
return ContinueSentinel; | ||
} | ||
} | ||
context.method = "throw"; | ||
context.arg = new TypeError( | ||
"The iterator does not provide a 'throw' method"); | ||
} | ||
return ContinueSentinel; | ||
} | ||
var record = tryCatch(method, delegate.iterator, context.arg); | ||
if (record.type === "throw") { | ||
context.method = "throw"; | ||
context.arg = record.arg; | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} | ||
var info = record.arg; | ||
if (! info) { | ||
context.method = "throw"; | ||
context.arg = new TypeError("iterator result is not an object"); | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} | ||
if (info.done) { | ||
// Assign the result of the finished delegate to the temporary | ||
// variable specified by delegate.resultName (see delegateYield). | ||
context[delegate.resultName] = info.value; | ||
// Resume execution at the desired location (see delegateYield). | ||
context.next = delegate.nextLoc; | ||
// If context.method was "throw" but the delegate handled the | ||
// exception, let the outer generator proceed normally. If | ||
// context.method was "next", forget context.arg since it has been | ||
// "consumed" by the delegate iterator. If context.method was | ||
// "return", allow the original .return call to continue in the | ||
// outer generator. | ||
if (context.method !== "return") { | ||
context.method = "next"; | ||
context.arg = undefined$1; | ||
} | ||
} else { | ||
// Re-yield the result returned by the delegate method. | ||
return info; | ||
} | ||
// The delegate iterator is finished, so forget it and continue with | ||
// the outer generator. | ||
context.delegate = null; | ||
return ContinueSentinel; | ||
} | ||
// Define Generator.prototype.{next,throw,return} in terms of the | ||
// unified ._invoke helper method. | ||
defineIteratorMethods(Gp); | ||
Gp[toStringTagSymbol] = "Generator"; | ||
// A Generator should always return itself as the iterator object when the | ||
// @@iterator function is called on it. Some browsers' implementations of the | ||
// iterator prototype chain incorrectly implement this, causing the Generator | ||
// object to not be returned from this call. This ensures that doesn't happen. | ||
// See https://github.com/facebook/regenerator/issues/274 for more details. | ||
Gp[iteratorSymbol] = function() { | ||
return this; | ||
}; | ||
Gp.toString = function() { | ||
return "[object Generator]"; | ||
}; | ||
function pushTryEntry(locs) { | ||
var entry = { tryLoc: locs[0] }; | ||
if (1 in locs) { | ||
entry.catchLoc = locs[1]; | ||
} | ||
if (2 in locs) { | ||
entry.finallyLoc = locs[2]; | ||
entry.afterLoc = locs[3]; | ||
} | ||
this.tryEntries.push(entry); | ||
} | ||
function resetTryEntry(entry) { | ||
var record = entry.completion || {}; | ||
record.type = "normal"; | ||
delete record.arg; | ||
entry.completion = record; | ||
} | ||
function Context(tryLocsList) { | ||
// The root entry object (effectively a try statement without a catch | ||
// or a finally block) gives us a place to store values thrown from | ||
// locations where there is no enclosing try statement. | ||
this.tryEntries = [{ tryLoc: "root" }]; | ||
tryLocsList.forEach(pushTryEntry, this); | ||
this.reset(true); | ||
} | ||
runtime.keys = function(object) { | ||
var keys = []; | ||
for (var key in object) { | ||
keys.push(key); | ||
} | ||
keys.reverse(); | ||
// Rather than returning an object with a next method, we keep | ||
// things simple and return the next function itself. | ||
return function next() { | ||
while (keys.length) { | ||
var key = keys.pop(); | ||
if (key in object) { | ||
next.value = key; | ||
next.done = false; | ||
return next; | ||
} | ||
} | ||
// To avoid creating an additional object, we just hang the .value | ||
// and .done properties off the next function object itself. This | ||
// also ensures that the minifier will not anonymize the function. | ||
next.done = true; | ||
return next; | ||
}; | ||
}; | ||
function values(iterable) { | ||
if (iterable) { | ||
var iteratorMethod = iterable[iteratorSymbol]; | ||
if (iteratorMethod) { | ||
return iteratorMethod.call(iterable); | ||
} | ||
if (typeof iterable.next === "function") { | ||
return iterable; | ||
} | ||
if (!isNaN(iterable.length)) { | ||
var i = -1, next = function next() { | ||
while (++i < iterable.length) { | ||
if (hasOwn.call(iterable, i)) { | ||
next.value = iterable[i]; | ||
next.done = false; | ||
return next; | ||
} | ||
} | ||
next.value = undefined$1; | ||
next.done = true; | ||
return next; | ||
}; | ||
return next.next = next; | ||
} | ||
} | ||
// Return an iterator with no values. | ||
return { next: doneResult }; | ||
} | ||
runtime.values = values; | ||
function doneResult() { | ||
return { value: undefined$1, done: true }; | ||
} | ||
Context.prototype = { | ||
constructor: Context, | ||
reset: function(skipTempReset) { | ||
this.prev = 0; | ||
this.next = 0; | ||
// Resetting context._sent for legacy support of Babel's | ||
// function.sent implementation. | ||
this.sent = this._sent = undefined$1; | ||
this.done = false; | ||
this.delegate = null; | ||
this.method = "next"; | ||
this.arg = undefined$1; | ||
this.tryEntries.forEach(resetTryEntry); | ||
if (!skipTempReset) { | ||
for (var name in this) { | ||
// Not sure about the optimal order of these conditions: | ||
if (name.charAt(0) === "t" && | ||
hasOwn.call(this, name) && | ||
!isNaN(+name.slice(1))) { | ||
this[name] = undefined$1; | ||
} | ||
} | ||
} | ||
}, | ||
stop: function() { | ||
this.done = true; | ||
var rootEntry = this.tryEntries[0]; | ||
var rootRecord = rootEntry.completion; | ||
if (rootRecord.type === "throw") { | ||
throw rootRecord.arg; | ||
} | ||
return this.rval; | ||
}, | ||
dispatchException: function(exception) { | ||
if (this.done) { | ||
throw exception; | ||
} | ||
var context = this; | ||
function handle(loc, caught) { | ||
record.type = "throw"; | ||
record.arg = exception; | ||
context.next = loc; | ||
if (caught) { | ||
// If the dispatched exception was caught by a catch block, | ||
// then let that catch block handle the exception normally. | ||
context.method = "next"; | ||
context.arg = undefined$1; | ||
} | ||
return !! caught; | ||
} | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
var record = entry.completion; | ||
if (entry.tryLoc === "root") { | ||
// Exception thrown outside of any try block that could handle | ||
// it, so set the completion value of the entire function to | ||
// throw the exception. | ||
return handle("end"); | ||
} | ||
if (entry.tryLoc <= this.prev) { | ||
var hasCatch = hasOwn.call(entry, "catchLoc"); | ||
var hasFinally = hasOwn.call(entry, "finallyLoc"); | ||
if (hasCatch && hasFinally) { | ||
if (this.prev < entry.catchLoc) { | ||
return handle(entry.catchLoc, true); | ||
} else if (this.prev < entry.finallyLoc) { | ||
return handle(entry.finallyLoc); | ||
} | ||
} else if (hasCatch) { | ||
if (this.prev < entry.catchLoc) { | ||
return handle(entry.catchLoc, true); | ||
} | ||
} else if (hasFinally) { | ||
if (this.prev < entry.finallyLoc) { | ||
return handle(entry.finallyLoc); | ||
} | ||
} else { | ||
throw new Error("try statement without catch or finally"); | ||
} | ||
} | ||
} | ||
}, | ||
abrupt: function(type, arg) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc <= this.prev && | ||
hasOwn.call(entry, "finallyLoc") && | ||
this.prev < entry.finallyLoc) { | ||
var finallyEntry = entry; | ||
break; | ||
} | ||
} | ||
if (finallyEntry && | ||
(type === "break" || | ||
type === "continue") && | ||
finallyEntry.tryLoc <= arg && | ||
arg <= finallyEntry.finallyLoc) { | ||
// Ignore the finally entry if control is not jumping to a | ||
// location outside the try/catch block. | ||
finallyEntry = null; | ||
} | ||
var record = finallyEntry ? finallyEntry.completion : {}; | ||
record.type = type; | ||
record.arg = arg; | ||
if (finallyEntry) { | ||
this.method = "next"; | ||
this.next = finallyEntry.finallyLoc; | ||
return ContinueSentinel; | ||
} | ||
return this.complete(record); | ||
}, | ||
complete: function(record, afterLoc) { | ||
if (record.type === "throw") { | ||
throw record.arg; | ||
} | ||
if (record.type === "break" || | ||
record.type === "continue") { | ||
this.next = record.arg; | ||
} else if (record.type === "return") { | ||
this.rval = this.arg = record.arg; | ||
this.method = "return"; | ||
this.next = "end"; | ||
} else if (record.type === "normal" && afterLoc) { | ||
this.next = afterLoc; | ||
} | ||
return ContinueSentinel; | ||
}, | ||
finish: function(finallyLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.finallyLoc === finallyLoc) { | ||
this.complete(entry.completion, entry.afterLoc); | ||
resetTryEntry(entry); | ||
return ContinueSentinel; | ||
} | ||
} | ||
}, | ||
"catch": function(tryLoc) { | ||
for (var i = this.tryEntries.length - 1; i >= 0; --i) { | ||
var entry = this.tryEntries[i]; | ||
if (entry.tryLoc === tryLoc) { | ||
var record = entry.completion; | ||
if (record.type === "throw") { | ||
var thrown = record.arg; | ||
resetTryEntry(entry); | ||
} | ||
return thrown; | ||
} | ||
} | ||
// The context.catch method must only be called with a location | ||
// argument that corresponds to a known catch block. | ||
throw new Error("illegal catch attempt"); | ||
}, | ||
delegateYield: function(iterable, resultName, nextLoc) { | ||
this.delegate = { | ||
iterator: values(iterable), | ||
resultName: resultName, | ||
nextLoc: nextLoc | ||
}; | ||
if (this.method === "next") { | ||
// Deliberately forget the last sent value so that we don't | ||
// accidentally pass it on to the delegate. | ||
this.arg = undefined$1; | ||
} | ||
return ContinueSentinel; | ||
} | ||
}; | ||
})( | ||
// In sloppy mode, unbound `this` refers to the global object, fallback to | ||
// Function constructor if we're in global strict mode. That is sadly a form | ||
// of indirect eval which violates Content Security Policy. | ||
(function() { | ||
return this || (typeof self === "object" && self); | ||
})() || Function("return this")() | ||
); | ||
}); | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
// This method of obtaining a reference to the global object needs to be | ||
// kept identical to the way it is obtained in runtime.js | ||
var g = (function() { | ||
return this || (typeof self === "object" && self); | ||
})() || Function("return this")(); | ||
// Use `getOwnPropertyNames` because not all browsers support calling | ||
// `hasOwnProperty` on the global `self` object in a worker. See #183. | ||
var hadRuntime = g.regeneratorRuntime && | ||
Object.getOwnPropertyNames(g).indexOf("regeneratorRuntime") >= 0; | ||
// Save the old regeneratorRuntime in case it needs to be restored later. | ||
var oldRuntime = hadRuntime && g.regeneratorRuntime; | ||
// Force reevalutation of runtime.js. | ||
g.regeneratorRuntime = undefined; | ||
var runtimeModule = runtime; | ||
if (hadRuntime) { | ||
// Restore the original runtime. | ||
g.regeneratorRuntime = oldRuntime; | ||
} else { | ||
// Remove the global property added by runtime.js. | ||
try { | ||
delete g.regeneratorRuntime; | ||
} catch(e) { | ||
g.regeneratorRuntime = undefined; | ||
} | ||
} | ||
var regenerator = runtimeModule; | ||
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 target; | ||
}; | ||
return _extends.apply(this, arguments); | ||
} | ||
function _objectWithoutPropertiesLoose(source, excluded) { | ||
if (source == null) return {}; | ||
var target = {}; | ||
var sourceKeys = Object.keys(source); | ||
var key, i; | ||
for (i = 0; i < sourceKeys.length; i++) { | ||
key = sourceKeys[i]; | ||
if (excluded.indexOf(key) >= 0) continue; | ||
target[key] = source[key]; | ||
} | ||
return target; | ||
} | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
args = arguments; | ||
return new Promise(function (resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
_next(undefined); | ||
}); | ||
}; | ||
} | ||
// This is based on koa-compose. | ||
function compose() { | ||
var middleware = []; | ||
function exec(context, next) { | ||
// last called middleware # | ||
var index = -1; | ||
function dispatch(i) { | ||
if (i <= index) return Promise.reject(new Error('next() called multiple times')); | ||
index = i; | ||
var fn = middleware[i]; | ||
if (i === middleware.length) fn = next; | ||
if (!fn) return Promise.resolve(); | ||
try { | ||
return fn(context, dispatch.bind(null, i + 1)); | ||
} catch (err) { | ||
return Promise.reject(err); | ||
} | ||
} | ||
return dispatch(0); | ||
} | ||
exec.push = middleware.push.bind(middleware); | ||
return exec; | ||
} | ||
var LINK_KEY = '🔗'; | ||
var PAGE_KEY = '__page__'; | ||
var MIN_KEY = ''; | ||
var MAX_KEY = "\uFFFF"; | ||
function getToken() { | ||
var token = {}; | ||
var listeners = []; | ||
var signaled = false; | ||
function onSignal(fn) { | ||
if (signaled) return fn(); | ||
listeners.push(fn); | ||
} | ||
function signal() { | ||
signaled = true; | ||
listeners.forEach(function (fn) { | ||
try { | ||
fn(); | ||
} catch (e) { | ||
/* Do nothing */ | ||
} | ||
}); | ||
listeners = null; | ||
} | ||
Object.defineProperty(token, 'signaled', { | ||
get: function get() { | ||
return signaled; | ||
}, | ||
enumerable: true | ||
}); | ||
Object.defineProperty(token, 'onSignal', { | ||
value: onSignal, | ||
enumerable: true | ||
}); | ||
return [token, signal]; | ||
} | ||
/* | ||
makeOperation: Return an interval operation for the given logic flags. | ||
An interval operation is a function that accepts two interval sets and | ||
returns an interval set. | ||
An interval set is a sorted array with an even number of elements, where | ||
each pair of elements form a closed interval. | ||
e.g. The interval set [1, 2, 3, 4] represents two closed intervals, [1, 2] | ||
and [3, 4]. | ||
The logic flags may each be zero or 1, and they are: | ||
- lForR: Only keep values from the left interval set that are strictly | ||
outside (0) or inside (1) the right interval set | ||
- rForL: Only keep values from the right interval set that are strictly | ||
outside (0) or inside (1) the left interval set | ||
*/ | ||
function makeOperation(lForR, rForL) { | ||
function push(interval, bound) { | ||
var l = interval.length; | ||
if (bound === interval[l - 1] && (!(l % 2) || (lForR + rForL) % 2)) { | ||
interval.splice(-1); | ||
} else { | ||
interval.push(bound); | ||
} | ||
} | ||
return function (left, right) { | ||
var i = 0; | ||
var result = []; | ||
for (var j = 0; j < right.length; j++) { | ||
for (; i < left.length && left[i] <= right[j]; i++) { | ||
if (j % 2 === lForR) push(result, left[i]); | ||
} | ||
if (i % 2 === rForL) push(result, right[j]); | ||
} | ||
if (!lForR) for (; i < left.length; i++) { | ||
push(result, left[i]); | ||
} | ||
return result; | ||
}; | ||
} | ||
var union = makeOperation(0, 0); | ||
var inter = makeOperation(1, 1); | ||
var diff = makeOperation(0, 1); | ||
function atomicArrays(objValue, srcValue, key) { | ||
if (Array.isArray(objValue) || Array.isArray(srcValue)) { | ||
if (key === LINK_KEY) return srcValue; | ||
if (key === PAGE_KEY) return union(objValue || [], srcValue); | ||
throw Error('merge.unexpected_array'); | ||
} | ||
} | ||
function merge() { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
return mergeWith.apply(void 0, args.concat([atomicArrays])); | ||
} | ||
var PATH_SEPARATOR = '/'; | ||
function makePath(path) { | ||
if (Array.isArray(path)) return path; | ||
if (typeof path !== 'string') throw Error('resolve.path'); | ||
if (!path.length || path === PATH_SEPARATOR) return []; | ||
if (path[0] !== PATH_SEPARATOR) throw Error('resolve.path'); | ||
return path.split(PATH_SEPARATOR).slice(1); | ||
} | ||
function getNode(tree, path) { | ||
for (var _iterator = path, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var name = _ref; | ||
if (!tree || !(name in tree)) return; | ||
tree = tree[name]; | ||
} | ||
return tree; | ||
} | ||
function makeNode(tree, path) { | ||
for (var _iterator2 = path, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { | ||
var _ref2; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i2++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref2 = _i2.value; | ||
} | ||
var name = _ref2; | ||
if (typeof tree[name] !== 'object' || !tree[name]) tree[name] = {}; | ||
tree = tree[name]; | ||
} | ||
return tree; | ||
} | ||
function wrap(query, path) { | ||
// return path.concat(query); | ||
for (var i = path.length - 1; i >= 0; i--) { | ||
var _query; | ||
query = (_query = {}, _query[path[i]] = query, _query); | ||
} | ||
return query; | ||
} | ||
var RANGE_PATTERN = /^([^*]*)(\*+)([^*]*)(\**)([^*]*)$/; | ||
function isRange(key) { | ||
return !!key.match(RANGE_PATTERN); | ||
} | ||
function decRange(key) { | ||
var _ref, _ref2; | ||
var match = key.match(RANGE_PATTERN); | ||
if (!match) throw Error('range.decRange.bad_pattern'); // eslint-disable-next-line no-unused-vars | ||
var _ = match[0], | ||
a = match[1], | ||
l = match[2], | ||
b = match[3], | ||
r = match[4], | ||
c = match[5]; | ||
if (l && r && l === r) throw Error('range.decRange.bad_asterisks'); | ||
var int = function int(s) { | ||
return parseInt(s, 10); | ||
}; | ||
if (r !== '') return _ref = { | ||
after: a !== '' ? a : MIN_KEY, | ||
before: c !== '' ? c : MAX_KEY | ||
}, _ref[l === '**' ? 'last' : 'first'] = int(b), _ref; | ||
if (l === '*') return { | ||
after: a !== '' ? a : MIN_KEY, | ||
before: b !== '' ? b : MAX_KEY | ||
}; | ||
return _ref2 = { | ||
after: MIN_KEY, | ||
before: MAX_KEY | ||
}, _ref2[b !== '' ? 'last' : 'first'] = int(b || a), _ref2; | ||
} | ||
function encRange(_ref3) { | ||
var before = _ref3.before, | ||
after = _ref3.after, | ||
first = _ref3.first, | ||
last = _ref3.last; | ||
if (first && last) throw Error('range.encRange.first_last'); | ||
if (after === MIN_KEY) after = ''; | ||
if (before === MAX_KEY) before = ''; | ||
return [after, first && after ? '*' : '', last ? '**' : '', first || last || '*', first ? '**' : '', last && before ? '*' : '', before].join(''); | ||
} | ||
var getKeys = function getKeys(tree) { | ||
return Object.keys(tree).filter(function (k) { | ||
return k !== PAGE_KEY && k !== LINK_KEY && tree[k] !== null; | ||
}).sort(); | ||
}; | ||
function getPage(tree) { | ||
var _ref4 = tree[PAGE_KEY] || [MIN_KEY, MAX_KEY], | ||
start = _ref4[0], | ||
end = _ref4[1]; | ||
var hasNext = end !== MAX_KEY; | ||
var hasPrev = start !== MIN_KEY; | ||
return { | ||
start: start, | ||
end: end, | ||
hasNext: hasNext, | ||
hasPrev: hasPrev | ||
}; | ||
} | ||
/* | ||
This function compares a data object with a range and returns: | ||
- keys, the list of keys known to be in the result | ||
- known, the page bounds of knowledge in the result | ||
- unknown, the range of keys that are not known | ||
*/ | ||
function splitRange(tree, key) { | ||
var _decRange = decRange(key), | ||
first = _decRange.first, | ||
last = _decRange.last, | ||
before = _decRange.before, | ||
after = _decRange.after; | ||
var treePage = tree[PAGE_KEY] || [MIN_KEY, MAX_KEY]; | ||
var rangePage = inter(treePage, [after, before]); | ||
if (first && after !== rangePage[0] || last && before !== rangePage[rangePage.length - 1]) { | ||
return { | ||
keys: [], | ||
known: [], | ||
unknown: key | ||
}; | ||
} | ||
var minKey = last ? rangePage[rangePage.length - 2] : after; | ||
var maxKey = first ? rangePage[1] : before; | ||
var keys = getKeys(tree); | ||
var minIx = sortedIndex(keys, minKey); | ||
var maxIx = sortedLastIndex(keys, maxKey); | ||
var unknown; | ||
if (first) { | ||
if (maxIx - minIx >= first) { | ||
maxIx = minIx + first; | ||
maxKey = keys[maxIx - 1]; | ||
} else { | ||
var remaining = maxKey !== before && { | ||
first: first - (maxIx - minIx) + 1, | ||
after: maxKey | ||
}; // if (last) remaining.last = last; | ||
if (remaining) unknown = encRange(remaining); | ||
} | ||
} else if (last) { | ||
if (maxIx - minIx >= last) { | ||
minIx = maxIx - last; | ||
minKey = keys[minIx]; | ||
} else { | ||
var _remaining = minKey !== after && { | ||
last: last - (maxIx - minIx) + 1, | ||
before: minKey | ||
}; | ||
if (_remaining) unknown = encRange(_remaining); | ||
} | ||
} else { | ||
unknown = diff([after, before], treePage).map(function (val, i, diffs) { | ||
return i % 2 ? null : encRange({ | ||
after: val, | ||
before: diffs[i + 1] | ||
}); | ||
}).filter(Boolean).join(','); | ||
} // if (key === 'c*3**') console.trace('Overflow'); | ||
// console.log('Range overflow', key, keys.slice(minIx, maxIx), unknown); | ||
return { | ||
keys: keys.slice(minIx, maxIx), | ||
known: inter(treePage, [minKey, maxKey]), | ||
unknown: unknown | ||
}; | ||
} | ||
/* | ||
Given a tree, a query and a visitor callback, the walk function invokes | ||
the visitor for: | ||
- each node in the tree that matches the query, with node and path arguments. | ||
- each non-existent path in the tree that would have matched the query | ||
- each range key in the query, with the result bounds as the first argument. | ||
*/ | ||
function walk(root, rootQuery, visit) { | ||
function step(node, query, path) { | ||
if (typeof node !== 'object' || typeof query !== 'object' || !node || !query) { | ||
visit(node, query, path); | ||
return; | ||
} | ||
var link = node[LINK_KEY]; | ||
if (link) { | ||
visit(node, query, path); | ||
step(getNode(root, link), query, link); | ||
return; | ||
} | ||
var _loop = function _loop(key) { | ||
var _visit; | ||
var subQuery = query[key]; | ||
if (!isRange(key)) { | ||
step(node[key], subQuery, path.concat(key)); | ||
return "continue"; | ||
} | ||
var _splitRange = splitRange(node, key), | ||
keys = _splitRange.keys, | ||
known = _splitRange.known, | ||
unknown = _splitRange.unknown; | ||
keys.forEach(function (k) { | ||
return step(node[k], subQuery, path.concat(k)); | ||
}); | ||
if (unknown) step(undefined, subQuery, path.concat(unknown)); | ||
if (known) visit((_visit = {}, _visit[PAGE_KEY] = known, _visit), subQuery, path); | ||
}; | ||
for (var key in query) { | ||
var _ret = _loop(key); | ||
if (_ret === "continue") continue; | ||
} | ||
} | ||
step(root, rootQuery, []); | ||
} | ||
function set(object, path, value) { | ||
var key = path[path.length - 1]; | ||
var node = makeNode(object, path.slice(0, -1)); | ||
if (typeof value !== 'object' || !value) { | ||
node[key] = value; | ||
return; | ||
} | ||
if (typeof node[key] !== 'object' || !node[key]) node[key] = {}; | ||
merge(node[key], value); | ||
} | ||
/* | ||
Sprout (new branches) | ||
Given a cached tree and a query, return a new query representing parts of the | ||
input query that are not present in the tree. | ||
*/ | ||
function sprout(root, rootQuery) { | ||
var nextQuery = {}; | ||
walk(root, rootQuery, function (node, query, path) { | ||
if (typeof node === 'undefined') set(nextQuery, path, query); | ||
}); | ||
return isEmpty(nextQuery) ? undefined : nextQuery; | ||
} | ||
/* | ||
Prune (unnecessary branches) | ||
*/ | ||
function prune(root, rootQuery) { | ||
var pruned = {}; | ||
walk(root, rootQuery, function (node, query, path) { | ||
if (typeof node === 'undefined') return; | ||
if (typeof node !== 'object' || !node || node[LINK_KEY] || node[PAGE_KEY]) { | ||
set(pruned, path, node); | ||
} | ||
}); | ||
return isEmpty(pruned) ? undefined : pruned; | ||
} | ||
/* | ||
strike: Copies parts of the query that cross links, repeating them at their | ||
canonical positions. | ||
The returned value is used to compute intersections with change objects. | ||
*/ | ||
function strike(root, rootQuery) { | ||
var normalized = {}; | ||
walk(root, rootQuery, function (node, query, path) { | ||
if (node && node[PAGE_KEY]) { | ||
var _set; | ||
var _node$PAGE_KEY = node[PAGE_KEY], | ||
after = _node$PAGE_KEY[0], | ||
before = _node$PAGE_KEY[1]; | ||
set(normalized, path, (_set = {}, _set[encRange({ | ||
after: after, | ||
before: before | ||
})] = query, _set)); | ||
return; | ||
} | ||
set(normalized, path, query); | ||
}); | ||
return isEmpty(normalized) ? undefined : normalized; | ||
} | ||
function cap(root, rootQuery) { | ||
var capped = {}; | ||
walk(root, rootQuery, function (node, query, path) { | ||
set(capped, path, typeof node === 'undefined' ? null : node); | ||
}); | ||
return isEmpty(capped) ? undefined : capped; | ||
} // Convert a raw response into a denormalized and easy-to-consume graph. | ||
function graft(root, rootQuery) { | ||
var graph = {}; | ||
var links = []; | ||
walk(root, rootQuery, function (node, query, path) { | ||
if (typeof node === 'undefined' || node === null) { | ||
set(graph, path, null); | ||
return; | ||
} | ||
if (node[LINK_KEY]) { | ||
links.push([path, node[LINK_KEY]]); | ||
} else { | ||
set(graph, path, node); | ||
} | ||
}); | ||
for (var _i = 0; _i < links.length; _i++) { | ||
var _links$_i = links[_i], | ||
from = _links$_i[0], | ||
to = _links$_i[1]; | ||
set(graph, from, getNode(graph, to)); | ||
} | ||
var prunedGraph = {}; | ||
walk(graph, rootQuery, function (node, query, path) { | ||
if (typeof node !== 'object' || node === null) { | ||
set(prunedGraph, path, node); | ||
return; | ||
} | ||
if (node[PAGE_KEY]) { | ||
var target = makeNode(prunedGraph, path); | ||
Object.defineProperty(target, PAGE_KEY, { | ||
value: node[PAGE_KEY] | ||
}); | ||
} | ||
}); | ||
return isEmpty(prunedGraph) ? undefined : prunedGraph; | ||
} | ||
var MAX_RECURSION = 10; | ||
function resolve(_x, _x2, _x3, _x4) { | ||
return _resolve.apply(this, arguments); | ||
} // Squashes layers into one (future) result tree. | ||
function _resolve() { | ||
_resolve = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regenerator.mark(function _callee(initQuery, rootFuncs, type, token) { | ||
var layers, result, rootQuery, build, budget, nextQuery; | ||
return regenerator.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
build = function _ref(query, funcs) { | ||
if (funcs[type]) { | ||
layers.push(Promise.resolve(funcs[type]({ | ||
query: rootQuery, | ||
token: token | ||
})).then(function (tree) { | ||
return prune(tree, rootQuery); | ||
})); | ||
} | ||
if (typeof query !== 'object' || !query) return; | ||
for (var key in query) { | ||
if (key in funcs) { | ||
build(query[key], funcs[key]); | ||
} | ||
} | ||
return layers; | ||
}; | ||
result = {}; | ||
rootQuery = initQuery; // Invokes resolver functions and collects the returned trees into layers. | ||
budget = MAX_RECURSION; | ||
case 4: | ||
if (!rootQuery) { | ||
_context.next = 21; | ||
break; | ||
} | ||
if (!(--budget < 0)) { | ||
_context.next = 7; | ||
break; | ||
} | ||
throw new Error('resolve.max_recursion'); | ||
case 7: | ||
layers = []; | ||
build(rootQuery, rootFuncs); | ||
_context.t0 = merge; | ||
_context.t1 = result; | ||
_context.next = 13; | ||
return squash(layers); | ||
case 13: | ||
_context.t2 = _context.sent; | ||
(0, _context.t0)(_context.t1, _context.t2); | ||
nextQuery = sprout(result, rootQuery); | ||
if (!isEqual(nextQuery, rootQuery)) { | ||
_context.next = 18; | ||
break; | ||
} | ||
return _context.abrupt("break", 21); | ||
case 18: | ||
rootQuery = nextQuery; | ||
_context.next = 4; | ||
break; | ||
case 21: | ||
return _context.abrupt("return", cap(result, initQuery)); | ||
case 22: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return _resolve.apply(this, arguments); | ||
} | ||
function squash(layers) { | ||
if (!layers.length) return Promise.resolve(); | ||
return Promise.all(layers).then(function (ls) { | ||
return merge.apply(void 0, [{}].concat(ls)); | ||
}); | ||
} | ||
function makeStream(fn) { | ||
var _ref; | ||
var payloads = []; | ||
var requests = []; | ||
var done = false; | ||
var push = function push(payload) { | ||
if (done) return; | ||
payload = { | ||
value: payload, | ||
done: false | ||
}; | ||
if (!requests.length) return payloads.push(payload); | ||
requests.shift()(payload); | ||
}; | ||
var close = fn(push); | ||
return _ref = { | ||
next: function next() { | ||
if (done) return Promise.resolve({ | ||
value: void 0, | ||
done: true | ||
}); | ||
if (payloads.length) return Promise.resolve(payloads.shift()); | ||
return new Promise(function (resolve) { | ||
return requests.push(resolve); | ||
}); | ||
}, | ||
return: function _return(val) { | ||
done = true; | ||
close(val); | ||
} | ||
}, _ref[Symbol.iterator] = function () { | ||
return this; | ||
}, _ref; | ||
} | ||
var Subscription = | ||
/*#__PURE__*/ | ||
function () { | ||
function Subscription(query, options) { | ||
var _this = this; | ||
this.query = query; | ||
this.options = options; | ||
this.stream = makeStream(function (push) { | ||
_this.push = push; | ||
return options.onClose; | ||
}); | ||
this.earlyChange = {}; | ||
this.init(); | ||
} | ||
var _proto = Subscription.prototype; | ||
_proto.init = | ||
/*#__PURE__*/ | ||
function () { | ||
var _init = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regenerator.mark(function _callee() { | ||
var options, query, data; | ||
return regenerator.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
// We need this line to be a separate function because the | ||
// constructor can't be async. We're okay even if pub is | ||
// called before this happens. | ||
options = this.options, query = this.query; | ||
_context.next = 3; | ||
return options.resolve(query); | ||
case 3: | ||
data = _context.sent; | ||
merge(data, this.earlyChange); // TODO: Properly resolve, prune etc. after early changes are merged. | ||
delete this.earlyChange; | ||
this.data = data = prune(data, query) || {}; | ||
this.push(options.values ? graft(data, query) || {} : data); | ||
case 8: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee, this); | ||
})); | ||
function init() { | ||
return _init.apply(this, arguments); | ||
} | ||
return init; | ||
}(); | ||
_proto.pub = | ||
/*#__PURE__*/ | ||
function () { | ||
var _pub = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regenerator.mark(function _callee2(change) { | ||
var query, options, data, nextQuery, linked; | ||
return regenerator.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
if (!this.earlyChange) { | ||
_context2.next = 3; | ||
break; | ||
} | ||
merge(this.earlyChanges, change); | ||
return _context2.abrupt("return"); | ||
case 3: | ||
query = this.query, options = this.options, data = this.data; // Returns early if the change does not have any overlap with the query. | ||
// DO NOT prune the change to only those changes that overlap; when the | ||
// overlapping portion includes a deletion in a range, the change set | ||
// may contain additional items to make up. | ||
if (prune(change, strike(data, query))) { | ||
_context2.next = 6; | ||
break; | ||
} | ||
return _context2.abrupt("return"); | ||
case 6: | ||
merge(data, change); | ||
nextQuery = sprout(data, query); | ||
if (!nextQuery) { | ||
_context2.next = 14; | ||
break; | ||
} | ||
_context2.next = 11; | ||
return options.resolve(nextQuery); | ||
case 11: | ||
linked = _context2.sent; | ||
merge(data, linked); | ||
if (!options.values) merge(change, linked); | ||
case 14: | ||
this.data = prune(data, query); | ||
this.push(options.values ? graft(this.data, query) || {} : change); | ||
case 16: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, this); | ||
})); | ||
function pub(_x) { | ||
return _pub.apply(this, arguments); | ||
} | ||
return pub; | ||
}(); | ||
return Subscription; | ||
}(); | ||
var GET = Symbol(); | ||
var PUT = Symbol(); | ||
function ensurePath(basePath, path) { | ||
if (!basePath) basePath = []; | ||
for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
args[_key - 2] = arguments[_key]; | ||
} | ||
if (Array.isArray(path)) { | ||
return [basePath.concat(path)].concat(args); | ||
} else if (typeof path === 'string') { | ||
return [basePath.concat(makePath(path))].concat(args); | ||
} else { | ||
return [basePath, path].concat(args); | ||
} | ||
} | ||
function shiftFn(fn, path) { | ||
return ( | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref2 = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regenerator.mark(function _callee(_ref, next) { | ||
var query, props; | ||
return regenerator.wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
query = _ref.query, props = _objectWithoutPropertiesLoose(_ref, ["query"]); | ||
_context.t0 = wrap; | ||
_context.next = 4; | ||
return fn(_extends({ | ||
query: getNode(query, path) | ||
}, props), next); | ||
case 4: | ||
_context.t1 = _context.sent; | ||
_context.t2 = path; | ||
return _context.abrupt("return", (0, _context.t0)(_context.t1, _context.t2)); | ||
case 7: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return function (_x, _x2) { | ||
return _ref2.apply(this, arguments); | ||
}; | ||
}() | ||
); | ||
} | ||
var Graffy = | ||
/*#__PURE__*/ | ||
function () { | ||
function Graffy(path, root) { | ||
if (root) { | ||
this.root = root; | ||
this.path = path; | ||
this.funcs = this.root.funcs; | ||
this.subs = this.root.subs; | ||
} else { | ||
this.funcs = {}; // Registered provider functions, in a tree | ||
this.subs = {}; // Map of tokens to querys for ongoing subscriptions | ||
this.subId = 0; | ||
} | ||
this.onGet = this.register.bind(this, GET); | ||
this.onPut = this.register.bind(this, PUT); | ||
} | ||
var _proto = Graffy.prototype; | ||
_proto.register = function register(type, path, fn) { | ||
var _ensurePath = ensurePath(this.path, path, fn); | ||
path = _ensurePath[0]; | ||
fn = _ensurePath[1]; | ||
if (this.path) fn = shiftFn(fn, this.path); | ||
var node = makeNode(this.funcs, path); | ||
node[type] = node[type] || compose(); | ||
node[type].push(fn); | ||
}; | ||
_proto.use = function use(path, provider) { | ||
var _ensurePath2 = ensurePath(this.path, path, provider); | ||
path = _ensurePath2[0]; | ||
provider = _ensurePath2[1]; | ||
provider(new Graffy(this.path ? this.path.concat(path) : path, this.root || this)); | ||
}; | ||
_proto.get = | ||
/*#__PURE__*/ | ||
function () { | ||
var _get = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regenerator.mark(function _callee2(path, query) { | ||
var _ensurePath3, result; | ||
return regenerator.wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
_ensurePath3 = ensurePath(this.path, path, query); | ||
path = _ensurePath3[0]; | ||
query = _ensurePath3[1]; | ||
query = wrap(query, path); | ||
_context2.next = 6; | ||
return resolve(query, this.funcs, GET); | ||
case 6: | ||
result = _context2.sent; | ||
return _context2.abrupt("return", getNode(graft(result, query), path)); | ||
case 8: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
} | ||
}, _callee2, this); | ||
})); | ||
function get(_x3, _x4) { | ||
return _get.apply(this, arguments); | ||
} | ||
return get; | ||
}(); | ||
_proto.getRaw = | ||
/*#__PURE__*/ | ||
function () { | ||
var _getRaw = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regenerator.mark(function _callee3(query) { | ||
var result; | ||
return regenerator.wrap(function _callee3$(_context3) { | ||
while (1) { | ||
switch (_context3.prev = _context3.next) { | ||
case 0: | ||
if (this.path) query = wrap(query, this.path); | ||
_context3.next = 3; | ||
return resolve(query, this.funcs, GET); | ||
case 3: | ||
result = _context3.sent; | ||
return _context3.abrupt("return", prune(result, query)); | ||
case 5: | ||
case "end": | ||
return _context3.stop(); | ||
} | ||
} | ||
}, _callee3, this); | ||
})); | ||
function getRaw(_x5) { | ||
return _getRaw.apply(this, arguments); | ||
} | ||
return getRaw; | ||
}(); | ||
_proto.put = | ||
/*#__PURE__*/ | ||
function () { | ||
var _put = _asyncToGenerator( | ||
/*#__PURE__*/ | ||
regenerator.mark(function _callee4() { | ||
return regenerator.wrap(function _callee4$(_context4) { | ||
while (1) { | ||
switch (_context4.prev = _context4.next) { | ||
case 0: | ||
throw Error('core.put.unimplemented'); | ||
case 1: | ||
case "end": | ||
return _context4.stop(); | ||
} | ||
} | ||
}, _callee4); | ||
})); | ||
function put() { | ||
return _put.apply(this, arguments); | ||
} | ||
return put; | ||
}() // TODO: Support passing a cache object to sub to share a cache. | ||
; | ||
_proto.sub = function sub(query, options) { | ||
var _this = this; | ||
var _getToken = getToken(), | ||
token = _getToken[0], | ||
signal = _getToken[1]; | ||
var id = this.subId++; | ||
var sub = new Subscription(query, { | ||
values: options && options.values, | ||
resolve: function resolve$1(query, tree) { | ||
return resolve(query, _this.funcs, GET, token, tree); | ||
}, | ||
onClose: function onClose() { | ||
signal(); | ||
delete _this.subs[id]; | ||
} | ||
}); | ||
this.subs[id] = sub; | ||
return sub.stream; | ||
}; | ||
_proto.pub = function pub(change) { | ||
for (var id in this.subs) { | ||
this.subs[id].pub(this.path ? wrap(change, this.path) : change); | ||
} | ||
}; | ||
return Graffy; | ||
}(); | ||
exports.Graffy = Graffy; | ||
exports.encRange = encRange; | ||
exports.decRange = decRange; | ||
exports.getPage = getPage; | ||
'use strict';Object.defineProperty(exports,"__esModule",{value:!0});function _interopDefault(a){return a&&"object"==typeof a&&"default"in a?a["default"]:a}var mergeWith=_interopDefault(require("lodash/mergeWith")),sortedIndex=_interopDefault(require("lodash/sortedIndex")),sortedLastIndex=_interopDefault(require("lodash/sortedLastIndex")),isEmpty=_interopDefault(require("lodash/isEmpty")),isEqual=_interopDefault(require("lodash/isEqual"));function createCommonjsModule(a,b){return b={exports:{}},a(b,b.exports),b.exports}var runtime=createCommonjsModule(function(a){!function(b){function c(a,b,c,d){var f=b&&b.prototype instanceof e?b:e,g=Object.create(f.prototype),h=new n(d||[]);return g._invoke=j(a,c,h),g}function d(a,b,c){try{return{type:"normal",arg:a.call(b,c)}}catch(a){return{type:"throw",arg:a}}}function e(){}function f(){}function g(){}function h(a){["next","throw","return"].forEach(function(b){a[b]=function(a){return this._invoke(b,a)}})}function i(a){function b(c,e,f,g){var h=d(a[c],a,e);if("throw"===h.type)g(h.arg);else{var i=h.arg,j=i.value;return j&&"object"==typeof j&&s.call(j,"__await")?Promise.resolve(j.__await).then(function(a){b("next",a,f,g)},function(a){b("throw",a,f,g)}):Promise.resolve(j).then(function(a){i.value=a,f(i)},function(a){return b("throw",a,f,g)})}}function c(a,c){function d(){return new Promise(function(d,e){b(a,c,d,e)})}return e=e?e.then(d,d):d()}var e;this._invoke=c}function j(a,b,c){var e="suspendedStart";return function(f,g){if(e==="executing")throw new Error("Generator is already running");if("completed"===e){if("throw"===f)throw g;return p()}for(c.method=f,c.arg=g;;){var h=c.delegate;if(h){var i=k(h,c);if(i){if(i===y)continue;return i}}if("next"===c.method)c.sent=c._sent=c.arg;else if("throw"===c.method){if("suspendedStart"===e)throw e="completed",c.arg;c.dispatchException(c.arg)}else"return"===c.method&&c.abrupt("return",c.arg);e="executing";var j=d(a,b,c);if("normal"===j.type){if(e=c.done?"completed":"suspendedYield",j.arg===y)continue;return{value:j.arg,done:c.done}}"throw"===j.type&&(e="completed",c.method="throw",c.arg=j.arg)}}}function k(a,b){var c=a.iterator[b.method];if(c===q){if(b.delegate=null,"throw"===b.method){if(a.iterator.return&&(b.method="return",b.arg=q,k(a,b),"throw"===b.method))return y;b.method="throw",b.arg=new TypeError("The iterator does not provide a 'throw' method")}return y}var e=d(c,a.iterator,b.arg);if("throw"===e.type)return b.method="throw",b.arg=e.arg,b.delegate=null,y;var f=e.arg;if(!f)return b.method="throw",b.arg=new TypeError("iterator result is not an object"),b.delegate=null,y;if(f.done)b[a.resultName]=f.value,b.next=a.nextLoc,"return"!==b.method&&(b.method="next",b.arg=q);else return f;return b.delegate=null,y}function l(a){var b={tryLoc:a[0]};1 in a&&(b.catchLoc=a[1]),2 in a&&(b.finallyLoc=a[2],b.afterLoc=a[3]),this.tryEntries.push(b)}function m(a){var b=a.completion||{};b.type="normal",delete b.arg,a.completion=b}function n(a){this.tryEntries=[{tryLoc:"root"}],a.forEach(l,this),this.reset(!0)}function o(a){if(a){var b=a[u];if(b)return b.call(a);if("function"==typeof a.next)return a;if(!isNaN(a.length)){var c=-1,d=function b(){for(;++c<a.length;)if(s.call(a,c))return b.value=a[c],b.done=!1,b;return b.value=q,b.done=!0,b};return d.next=d}}return{next:p}}function p(){return{value:q,done:!0}}var q,r=Object.prototype,s=r.hasOwnProperty,t="function"==typeof Symbol?Symbol:{},u=t.iterator||"@@iterator",v=t.asyncIterator||"@@asyncIterator",w=t.toStringTag||"@@toStringTag",x=b.regeneratorRuntime;if(x)return void(a.exports=x);x=b.regeneratorRuntime=a.exports,x.wrap=c;var y={},z={};z[u]=function(){return this};var A=Object.getPrototypeOf,B=A&&A(A(o([])));B&&B!==r&&s.call(B,u)&&(z=B);var C=g.prototype=e.prototype=Object.create(z);f.prototype=C.constructor=g,g.constructor=f,g[w]=f.displayName="GeneratorFunction",x.isGeneratorFunction=function(a){var b="function"==typeof a&&a.constructor;return!!b&&(b===f||"GeneratorFunction"===(b.displayName||b.name))},x.mark=function(a){return Object.setPrototypeOf?Object.setPrototypeOf(a,g):(a.__proto__=g,!(w in a)&&(a[w]="GeneratorFunction")),a.prototype=Object.create(C),a},x.awrap=function(a){return{__await:a}},h(i.prototype),i.prototype[v]=function(){return this},x.AsyncIterator=i,x.async=function(a,b,d,e){var f=new i(c(a,b,d,e));return x.isGeneratorFunction(b)?f:f.next().then(function(a){return a.done?a.value:f.next()})},h(C),C[w]="Generator",C[u]=function(){return this},C.toString=function(){return"[object Generator]"},x.keys=function(a){var b=[];for(var c in a)b.push(c);return b.reverse(),function c(){for(;b.length;){var d=b.pop();if(d in a)return c.value=d,c.done=!1,c}return c.done=!0,c}},x.values=o,n.prototype={constructor:n,reset:function c(a){if(this.prev=0,this.next=0,this.sent=this._sent=q,this.done=!1,this.delegate=null,this.method="next",this.arg=q,this.tryEntries.forEach(m),!a)for(var b in this)"t"===b.charAt(0)&&s.call(this,b)&&!isNaN(+b.slice(1))&&(this[b]=q)},stop:function c(){this.done=!0;var a=this.tryEntries[0],b=a.completion;if("throw"===b.type)throw b.arg;return this.rval},dispatchException:function j(a){function b(b,d){return f.type="throw",f.arg=a,c.next=b,d&&(c.method="next",c.arg=q),!!d}if(this.done)throw a;for(var c=this,d=this.tryEntries.length-1;0<=d;--d){var e=this.tryEntries[d],f=e.completion;if("root"===e.tryLoc)return b("end");if(e.tryLoc<=this.prev){var g=s.call(e,"catchLoc"),h=s.call(e,"finallyLoc");if(g&&h){if(this.prev<e.catchLoc)return b(e.catchLoc,!0);if(this.prev<e.finallyLoc)return b(e.finallyLoc)}else if(g){if(this.prev<e.catchLoc)return b(e.catchLoc,!0);}else if(!h)throw new Error("try statement without catch or finally");else if(this.prev<e.finallyLoc)return b(e.finallyLoc)}}},abrupt:function g(a,b){for(var c,d=this.tryEntries.length-1;0<=d;--d)if(c=this.tryEntries[d],c.tryLoc<=this.prev&&s.call(c,"finallyLoc")&&this.prev<c.finallyLoc){var e=c;break}e&&("break"===a||"continue"===a)&&e.tryLoc<=b&&b<=e.finallyLoc&&(e=null);var f=e?e.completion:{};return f.type=a,f.arg=b,e?(this.method="next",this.next=e.finallyLoc,y):this.complete(f)},complete:function c(a,b){if("throw"===a.type)throw a.arg;return"break"===a.type||"continue"===a.type?this.next=a.arg:"return"===a.type?(this.rval=this.arg=a.arg,this.method="return",this.next="end"):"normal"===a.type&&b&&(this.next=b),y},finish:function d(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.finallyLoc===a)return this.complete(b.completion,b.afterLoc),m(b),y},catch:function f(a){for(var b,c=this.tryEntries.length-1;0<=c;--c)if(b=this.tryEntries[c],b.tryLoc===a){var d=b.completion;if("throw"===d.type){var e=d.arg;m(b)}return e}throw new Error("illegal catch attempt")},delegateYield:function d(a,b,c){return this.delegate={iterator:o(a),resultName:b,nextLoc:c},"next"===this.method&&(this.arg=q),y}}}(function(){return this||"object"==typeof self&&self}()||Function("return this")())}),g=function(){return this||"object"==typeof self&&self}()||Function("return this")(),hadRuntime=g.regeneratorRuntime&&0<=Object.getOwnPropertyNames(g).indexOf("regeneratorRuntime"),oldRuntime=hadRuntime&&g.regeneratorRuntime;g.regeneratorRuntime=void 0;var runtimeModule=runtime;if(hadRuntime)g.regeneratorRuntime=oldRuntime;else try{delete g.regeneratorRuntime}catch(a){g.regeneratorRuntime=void 0}var regenerator=runtimeModule;function _extends(){return _extends=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a},_extends.apply(this,arguments)}function _objectWithoutPropertiesLoose(a,b){if(null==a)return{};var c,d,e={},f=Object.keys(a);for(d=0;d<f.length;d++)c=f[d],0<=b.indexOf(c)||(e[c]=a[c]);return e}function asyncGeneratorStep(a,b,c,d,e,f,g){try{var h=a[f](g),i=h.value}catch(a){return void c(a)}h.done?b(i):Promise.resolve(i).then(d,e)}function _asyncToGenerator(a){return function(){var b=this,c=arguments;return new Promise(function(d,e){function f(a){asyncGeneratorStep(h,d,e,f,g,"next",a)}function g(a){asyncGeneratorStep(h,d,e,f,g,"throw",a)}var h=a.apply(b,c);f(void 0)})}}function compose(){function a(a,c){function d(f){if(f<=e)return Promise.reject(new Error("next() called multiple times"));e=f;var g=b[f];if(f===b.length&&(g=c),!g)return Promise.resolve();try{return g(a,d.bind(null,f+1))}catch(a){return Promise.reject(a)}}var e=-1;return d(0)}var b=[];return a.push=b.push.bind(b),a}var PATH_SEPARATOR="/";function makePath(a){if(Array.isArray(a))return a;if("string"!=typeof a)throw Error("resolve.path");if(!a.length||a===PATH_SEPARATOR)return[];if(a[0]!==PATH_SEPARATOR)throw Error("resolve.path");return a.split(PATH_SEPARATOR).slice(1)}function getNode(a,b){for(var c=b,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;if(!a||!(g in a))return;a=a[g]}return a}function makeNode(a,b){for(var c=b,d=Array.isArray(c),e=0,c=d?c:c[Symbol.iterator]();;){var f;if(d){if(e>=c.length)break;f=c[e++]}else{if(e=c.next(),e.done)break;f=e.value}var g=f;"object"==typeof a[g]&&a[g]||(a[g]={}),a=a[g]}return a}function wrap(a,b){for(var c=b.length-1;0<=c;c--){var d;a=(d={},d[b[c]]=a,d)}return a}var LINK_KEY="\uD83D\uDD17",PAGE_KEY="__page__",MIN_KEY="",MAX_KEY="\uFFFF";function getPage(a){var b=a[PAGE_KEY]||[MIN_KEY,MAX_KEY],c=b[0],d=b[1];return{start:c,end:d,hasNext:d!==MAX_KEY,hasPrev:c!==MIN_KEY}}function getLink(a){return a[LINK_KEY]}function makeLink(a){var b;return b={},b[LINK_KEY]=makePath(a),b}function makePage(a,b,c){return a[PAGE_KEY]=[b,c],a}function getToken(){function a(a){return e?a():void d.push(a)}function b(){e=!0,d.forEach(function(a){try{a()}catch(a){}}),d=null}var c={},d=[],e=!1;return Object.defineProperty(c,"signaled",{get:function(){return e},enumerable:!0}),Object.defineProperty(c,"onSignal",{value:a,enumerable:!0}),[c,b]}function makeOperation(a,b){function c(c,d){var e=c.length;d===c[e-1]&&(!(e%2)||(a+b)%2)?c.splice(-1):c.push(d)}return function(d,e){for(var f=0,g=[],h=0;h<e.length;h++){for(;f<d.length&&d[f]<=e[h];f++)h%2===a&&c(g,d[f]);f%2===b&&c(g,e[h])}if(!a)for(;f<d.length;f++)c(g,d[f]);return g}}var union=makeOperation(0,0),inter=makeOperation(1,1),diff=makeOperation(0,1);function atomicArrays(a,b,c){if(Array.isArray(a)||Array.isArray(b)){if(c===LINK_KEY)return b;if(c===PAGE_KEY)return union(a||[],b);throw Error("merge.unexpected_array")}}function merge(){for(var a=arguments.length,b=Array(a),c=0;c<a;c++)b[c]=arguments[c];return mergeWith.apply(void 0,b.concat([atomicArrays]))}var RANGE_PATTERN=/^([^*]*)(\*+)([^*]*)(\**)([^*]*)$/;function isRange(a){return!!a.match(RANGE_PATTERN)}function decRange(d){var e,f,g=d.match(RANGE_PATTERN);if(!g)throw Error("range.decRange.bad_pattern");var h=g[0],i=g[1],a=g[2],j=g[3],b=g[4],k=g[5];if(a&&b&&a===b)throw Error("range.decRange.bad_asterisks");var c=function(a){return parseInt(a,10)};return""===b?"*"===a?{after:""===i?MIN_KEY:i,before:""===j?MAX_KEY:j}:(f={after:MIN_KEY,before:MAX_KEY},f[""===j?"first":"last"]=c(j||i),f):(e={after:""===i?MIN_KEY:i,before:""===k?MAX_KEY:k},e["**"===a?"last":"first"]=c(j),e)}function encRange(a){var b=a.before,c=a.after,d=a.first,e=a.last;if(d&&e)throw Error("range.encRange.first_last");return c===MIN_KEY&&(c=""),b===MAX_KEY&&(b=""),[c,d&&c?"*":"",e?"**":"",d||e||"*",d?"**":"",e&&b?"*":"",b].join("")}var getKeys=function(a){return Object.keys(a).filter(function(b){return b!==PAGE_KEY&&b!==LINK_KEY&&null!==a[b]}).sort()};function splitRange(a,b){var c=decRange(b),d=c.first,e=c.last,f=c.before,g=c.after,h=a[PAGE_KEY]||[MIN_KEY,MAX_KEY],i=inter(h,[g,f]);if(d&&g!==i[0]||e&&f!==i[i.length-1])return{keys:[],known:[],unknown:b};var j,k=e?i[i.length-2]:g,l=d?i[1]:f,m=getKeys(a),n=sortedIndex(m,k),o=sortedLastIndex(m,l);if(d){if(o-n>=d)o=n+d,l=m[o-1];else{var p=l!==f&&{first:d-(o-n)+1,after:l};p&&(j=encRange(p))}}else if(!e)j=diff([g,f],h).map(function(a,b,c){return b%2?null:encRange({after:a,before:c[b+1]})}).filter(Boolean).join(",");else if(o-n>=e)n=o-e,k=m[n];else{var q=k!==g&&{last:e-(o-n)+1,before:k};q&&(j=encRange(q))}return{keys:m.slice(n,o),known:inter(h,[k,l]),unknown:j}}function walk(a,b,c){function d(b,e,f){if("object"!=typeof b||"object"!=typeof e||!b||!e)return void c(b,e,f);var g=b[LINK_KEY];if(g)return c(b,e,f),void d(getNode(a,g),e,g);var h=function(a){var g,h=e[a];if(!isRange(a))return d(b[a],h,f.concat(a)),"continue";var i=splitRange(b,a),j=i.keys,k=i.known,l=i.unknown;j.forEach(function(a){return d(b[a],h,f.concat(a))}),l&&d(void 0,h,f.concat(l)),k&&c((g={},g[PAGE_KEY]=k,g),h,f)};for(var i in e){var j=h(i)}}d(a,b,[])}function set(a,b,c){var d=b[b.length-1],e=makeNode(a,b.slice(0,-1));return"object"==typeof c&&c?void(("object"!=typeof e[d]||!e[d])&&(e[d]={}),merge(e[d],c)):void(e[d]=c)}function sprout(a,b){var c={};return walk(a,b,function(a,b,d){"undefined"==typeof a&&set(c,d,b)}),isEmpty(c)?void 0:c}function prune(a,b){var c={};return walk(a,b,function(a,b,d){"undefined"==typeof a||("object"!=typeof a||!a||a[LINK_KEY]||a[PAGE_KEY])&&set(c,d,a)}),isEmpty(c)?void 0:c}function strike(a,b){var c={};return walk(a,b,function(a,b,d){if(a&&a[PAGE_KEY]){var e,f=a[PAGE_KEY],g=f[0],h=f[1];return void set(c,d,(e={},e[encRange({after:g,before:h})]=b,e))}set(c,d,b)}),isEmpty(c)?void 0:c}function cap(a,b){var c={};return walk(a,b,function(a,b,d){set(c,d,"undefined"==typeof a?null:a)}),isEmpty(c)?void 0:c}function graft(a,b){var c={},d=[];walk(a,b,function(a,b,e){return"undefined"==typeof a||null===a?void set(c,e,null):void(a[LINK_KEY]?d.push([e,a[LINK_KEY]]):set(c,e,a))});for(var e=0;e<d.length;e++){var f=d[e],g=f[0],h=f[1];set(c,g,getNode(c,h))}var i={};return walk(c,b,function(a,b,c){if("object"!=typeof a||null===a)return void set(i,c,a);if(a[PAGE_KEY]){var d=makeNode(i,c);Object.defineProperty(d,PAGE_KEY,{value:a[PAGE_KEY]})}}),isEmpty(i)?void 0:i}var MAX_RECURSION=10;function resolve(){return _resolve.apply(this,arguments)}function _resolve(){return _resolve=_asyncToGenerator(regenerator.mark(function a(b,c,d,e){var f,g,h,i,j,k;return regenerator.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:i=function(a,b){if(b[d]&&f.push(Promise.resolve(b[d]({query:h,token:e})).then(function(a){return prune(a,h)})),"object"==typeof a&&a){for(var c in a)c in b&&i(a[c],b[c]);return f}},g={},h=b,j=MAX_RECURSION;case 4:if(!h){a.next=21;break}if(!(0>--j)){a.next=7;break}throw new Error("resolve.max_recursion");case 7:return f=[],i(h,c),a.t0=merge,a.t1=g,a.next=13,squash(f);case 13:if(a.t2=a.sent,(0,a.t0)(a.t1,a.t2),k=sprout(g,h),!isEqual(k,h)){a.next=18;break}return a.abrupt("break",21);case 18:h=k,a.next=4;break;case 21:return a.abrupt("return",cap(g,b));case 22:case"end":return a.stop();}},a)})),_resolve.apply(this,arguments)}function squash(a){return a.length?Promise.all(a).then(function(a){return merge.apply(void 0,[{}].concat(a))}):Promise.resolve()}function makeStream(a){var b,c=[],d=[],e=!1,f=function(a){if(!e)return a={value:a,done:!1},d.length?void d.shift()(a):c.push(a)},g=a(f);return b={next:function(){return e?Promise.resolve({value:void 0,done:!0}):c.length?Promise.resolve(c.shift()):new Promise(function(a){return d.push(a)})},return:function(a){e=!0,g(a)}},b[Symbol.iterator]=function(){return this},b}var Subscription=function(){function a(a,b){var c=this;this.query=a,this.options=b,this.stream=makeStream(function(a){return c.push=a,b.onClose}),this.earlyChange={},this.init()}var b=a.prototype;return b.init=function(){var a=_asyncToGenerator(regenerator.mark(function a(){var b,c,d;return regenerator.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return b=this.options,c=this.query,a.next=3,b.resolve(c);case 3:d=a.sent,merge(d,this.earlyChange),delete this.earlyChange,this.data=d=prune(d,c)||{},this.push(b.values?graft(d,c)||{}:d);case 8:case"end":return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}(),b.pub=function(){var a=_asyncToGenerator(regenerator.mark(function a(b){var c,d,e,f,g;return regenerator.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(!this.earlyChange){a.next=3;break}return merge(this.earlyChanges,b),a.abrupt("return");case 3:if(c=this.query,d=this.options,e=this.data,prune(b,strike(e,c))){a.next=6;break}return a.abrupt("return");case 6:if(merge(e,b),f=sprout(e,c),!f){a.next=14;break}return a.next=11,d.resolve(f);case 11:g=a.sent,merge(e,g),d.values||merge(b,g);case 14:this.data=prune(e,c),this.push(d.values?graft(this.data,c)||{}:b);case 16:case"end":return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}(),a}(),GET=Symbol(),PUT=Symbol();function ensurePath(a,b){a||(a=[]);for(var c=arguments.length,d=Array(2<c?c-2:0),e=2;e<c;e++)d[e-2]=arguments[e];return Array.isArray(b)?[a.concat(b)].concat(d):"string"==typeof b?[a.concat(makePath(b))].concat(d):[a,b].concat(d)}function shiftFn(a,b){return function(){var c=_asyncToGenerator(regenerator.mark(function c(d,e){var f,g;return regenerator.wrap(function(c){for(;;)switch(c.prev=c.next){case 0:return f=d.query,g=_objectWithoutPropertiesLoose(d,["query"]),c.t0=wrap,c.next=4,a(_extends({query:getNode(f,b)},g),e);case 4:return c.t1=c.sent,c.t2=b,c.abrupt("return",(0,c.t0)(c.t1,c.t2));case 7:case"end":return c.stop();}},c)}));return function(){return c.apply(this,arguments)}}()}var Graffy=function(){function a(a,b){b?(this.root=b,this.path=a,this.funcs=this.root.funcs,this.subs=this.root.subs):(this.funcs={},this.subs={},this.subId=0),this.onGet=this.register.bind(this,GET),this.onPut=this.register.bind(this,PUT)}var b=a.prototype;return b.register=function(a,b,c){var d=ensurePath(this.path,b,c);b=d[0],c=d[1],this.path&&(c=shiftFn(c,this.path));var e=makeNode(this.funcs,b);e[a]=e[a]||compose(),e[a].push(c)},b.use=function(b,c){var d=ensurePath(this.path,b,c);b=d[0],c=d[1],c(new a(this.path?this.path.concat(b):b,this.root||this))},b.get=function(){var a=_asyncToGenerator(regenerator.mark(function a(b,c){var d,e;return regenerator.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return d=ensurePath(this.path,b,c),b=d[0],c=d[1],c=wrap(c,b),a.next=6,resolve(c,this.funcs,GET);case 6:return e=a.sent,a.abrupt("return",getNode(graft(e,c),b));case 8:case"end":return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}(),b.getRaw=function(){var a=_asyncToGenerator(regenerator.mark(function a(b){var c;return regenerator.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return this.path&&(b=wrap(b,this.path)),a.next=3,resolve(b,this.funcs,GET);case 3:return c=a.sent,a.abrupt("return",prune(c,b));case 5:case"end":return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}(),b.put=function(){var a=_asyncToGenerator(regenerator.mark(function a(){return regenerator.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:throw Error("core.put.unimplemented");case 1:case"end":return a.stop();}},a)}));return function(){return a.apply(this,arguments)}}(),b.sub=function a(b,c){var d=this,e=getToken(),f=e[0],g=e[1],h=this.subId++,a=new Subscription(b,{values:c&&c.values,resolve:function(a,b){return resolve(a,d.funcs,GET,f,b)},onClose:function(){g(),delete d.subs[h]}});return this.subs[h]=a,a.stream},b.pub=function(a){for(var b in this.subs)this.subs[b].pub(this.path?wrap(a,this.path):a)},a}();"undefined"!=typeof module&&(Graffy.encRange=encRange,Graffy.decRange=decRange,Graffy.getPage=getPage,Graffy.makePage=makePage,Graffy.getLink=getLink,Graffy.makeLink=makeLink,module.exports=Graffy),exports.default=Graffy,exports.encRange=encRange,exports.decRange=decRange,exports.getPage=getPage,exports.makePage=makePage,exports.getLink=getLink,exports.makeLink=makeLink; | ||
//# sourceMappingURL=bundle.js.map |
{ | ||
"name": "@graffy/core", | ||
"version": "0.6.0", | ||
"version": "0.7.0", | ||
"author": "aravind (github.com/aravindet)", | ||
@@ -5,0 +5,0 @@ "description": "Live queries on graphs", |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
39547
151
3
5