@graffy/common
Advanced tools
Comparing version 0.14.6-alpha1 to 0.14.6-alpha10
@@ -24,5 +24,13 @@ "use strict"; | ||
}]; | ||
return (0, _sliceInstanceProperty(_graph))((0, _graph.setVersion)((0, _graph.merge)(empty, graph), version), query).known; | ||
var res = (0, _sliceInstanceProperty(_graph))((0, _graph.setVersion)((0, _graph.merge)(empty, graph), version), query, { | ||
addLinked: function addLinked() { | ||
/* | ||
This is quite a hacky way to prevent slice from trying to expand | ||
links. | ||
*/ | ||
} | ||
}).known; | ||
return res; | ||
} | ||
module.exports = exports.default; |
@@ -9,2 +9,3 @@ "use strict"; | ||
exports.link = link; | ||
exports.value = value; | ||
@@ -17,6 +18,6 @@ var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter")); | ||
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map")); | ||
var _sort = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/sort")); | ||
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map")); | ||
var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array")); | ||
@@ -30,2 +31,4 @@ | ||
var _encode = require("../encode"); | ||
function makeGraph(key, value, version) { | ||
@@ -36,8 +39,15 @@ if (typeof value === 'function') { | ||
} else if ((0, _isArray["default"])(value)) { | ||
// console.warn('makeGraph: Unnecessary call with', value); | ||
// This has already been converted to a CRDT graph | ||
var _context; | ||
// Convert the KV-tuple format to a graph | ||
return { | ||
key: key, | ||
version: version, | ||
children: value | ||
children: (0, _sort["default"])(_context = (0, _map["default"])(value).call(value, function (_ref) { | ||
var k = _ref[0], | ||
v = _ref[1]; | ||
return makeGraph((0, _encode.encodeKey)(k), v, version); | ||
})).call(_context, function (a, b) { | ||
return a.key <= b.key ? -1 : 1; | ||
}) | ||
}; | ||
@@ -52,3 +62,3 @@ } else if (value === null) { | ||
} else if (typeof value === 'object' && value) { | ||
var _context, _context2; | ||
var _context2, _context3; | ||
@@ -58,3 +68,3 @@ return { | ||
version: version, | ||
children: (0, _map["default"])(_context = (0, _sort["default"])(_context2 = (0, _keys["default"])(value)).call(_context2)).call(_context, function (k) { | ||
children: (0, _map["default"])(_context2 = (0, _sort["default"])(_context3 = (0, _keys["default"])(value)).call(_context3)).call(_context2, function (k) { | ||
return makeGraph(k, value[k], version); | ||
@@ -92,10 +102,10 @@ }) | ||
return function (outerKey, version) { | ||
var _context3, _context4; | ||
var _context4, _context5; | ||
var nodes = graph(obj, version); | ||
var gaps = (0, _filter["default"])(_context3 = (0, _graph.merge)([{ | ||
var gaps = (0, _filter["default"])(_context4 = (0, _graph.merge)([{ | ||
key: key, | ||
end: end, | ||
version: version | ||
}], (0, _map["default"])(_context4 = (0, _keys["default"])(obj)).call(_context4, function (key) { | ||
}], (0, _map["default"])(_context5 = (0, _keys["default"])(obj)).call(_context5, function (key) { | ||
return { | ||
@@ -106,3 +116,3 @@ key: key, | ||
}; | ||
}))).call(_context3, function (node) { | ||
}))).call(_context4, function (node) { | ||
return (0, _node.isRange)(node); | ||
@@ -128,2 +138,12 @@ }); | ||
}; | ||
} | ||
function value(value) { | ||
return function (key, version) { | ||
return { | ||
key: key, | ||
version: version, | ||
value: value | ||
}; | ||
}; | ||
} |
@@ -6,3 +6,3 @@ "use strict"; | ||
exports.__esModule = true; | ||
exports.finalize = exports.makeQuery = exports.link = exports.page = exports.makeGraph = void 0; | ||
exports.finalize = exports.makeQuery = exports.value = exports.link = exports.page = exports.makeGraph = void 0; | ||
@@ -14,2 +14,3 @@ var _graph = require("./graph"); | ||
exports.link = _graph.link; | ||
exports.value = _graph.value; | ||
@@ -16,0 +17,0 @@ var _query = require("./query"); |
@@ -20,9 +20,15 @@ "use strict"; | ||
var MAX_PAGE_SIZE = 4096; | ||
var _encode = require("../encode"); | ||
var _graph = require("../graph"); | ||
var FALLBACK_PAGE_SIZE = 4096; | ||
function pageToRange(page) { | ||
var node = {}; | ||
node.key = page.after || ''; | ||
node.end = page.before || "\uFFFF"; | ||
node.count = page.first || -page.last || MAX_PAGE_SIZE; | ||
node.key = typeof page.after !== 'undefined' ? (0, _encode.key)(page.after) : ''; | ||
node.end = typeof page.before !== 'undefined' ? (0, _encode.key)(page.before) : "\uFFFF"; | ||
node.count = page.first || -page.last || FALLBACK_PAGE_SIZE; | ||
if (page.excludeAfter) node.key = (0, _graph.keyAfter)(node.key); | ||
if (page.excludeBefore) node.end = (0, _graph.keyBefore)(node.end); | ||
return node; | ||
@@ -39,2 +45,3 @@ } // We freeze constructed queries to guard against bugs that might mutate them. | ||
if ((0, _isArray["default"])(value)) { | ||
if (value.length === 1) value.unshift({}); | ||
return freeze({ | ||
@@ -41,0 +48,0 @@ children: freeze([freeze((0, _extends2["default"])({}, pageToRange(value[0]), {}, makeQuery(value[1], version)))]), |
@@ -9,2 +9,14 @@ "use strict"; | ||
var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind")); | ||
var _getIterator2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator")); | ||
var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array")); | ||
var _getIteratorMethod2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator-method")); | ||
var _from = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/from")); | ||
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice")); | ||
var _defineProperty = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/define-property")); | ||
@@ -14,6 +26,2 @@ | ||
var _getIterator2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator")); | ||
var _isArray4 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array")); | ||
var _symbol = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/symbol")); | ||
@@ -25,2 +33,8 @@ | ||
function _createForOfIteratorHelperLoose(o) { var _context2; var i = 0; if (typeof _symbol["default"] === "undefined" || (0, _getIteratorMethod2["default"])(o) == null) { if ((0, _isArray["default"])(o) || (o = _unsupportedIterableToArray(o))) return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } i = (0, _getIterator2["default"])(o); return (0, _bind["default"])(_context2 = i.next).call(_context2, i); } | ||
function _unsupportedIterableToArray(o, minLen) { var _context; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = (0, _slice["default"])(_context = Object.prototype.toString.call(o)).call(_context, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return (0, _from["default"])(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
var LINK_PLACEHOLDER = (0, _symbol["default"])(); | ||
@@ -31,15 +45,4 @@ | ||
for (var _iterator = path, _isArray = (0, _isArray4["default"])(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator2["default"])(_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 key = _ref; | ||
for (var _iterator = _createForOfIteratorHelperLoose(path), _step; !(_step = _iterator()).done;) { | ||
var key = _step.value; | ||
if (!node) return; | ||
@@ -98,15 +101,4 @@ if (!(key in node)) return undefined; | ||
for (var _iterator2 = graph, _isArray2 = (0, _isArray4["default"])(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator2["default"])(_iterator2);;) { | ||
var _ref2; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i2++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref2 = _i2.value; | ||
} | ||
var node = _ref2; | ||
for (var _iterator2 = _createForOfIteratorHelperLoose(graph), _step2; !(_step2 = _iterator2()).done;) { | ||
var node = _step2.value; | ||
if ((0, _node.isRange)(node)) continue; | ||
@@ -139,15 +131,4 @@ | ||
for (var _iterator3 = graph, _isArray3 = (0, _isArray4["default"])(_iterator3), _i3 = 0, _iterator3 = _isArray3 ? _iterator3 : (0, _getIterator2["default"])(_iterator3);;) { | ||
var _ref3; | ||
if (_isArray3) { | ||
if (_i3 >= _iterator3.length) break; | ||
_ref3 = _iterator3[_i3++]; | ||
} else { | ||
_i3 = _iterator3.next(); | ||
if (_i3.done) break; | ||
_ref3 = _i3.value; | ||
} | ||
var node = _ref3; | ||
for (var _iterator3 = _createForOfIteratorHelperLoose(graph), _step3; !(_step3 = _iterator3()).done;) { | ||
var node = _step3.value; | ||
var key = node.key; | ||
@@ -154,0 +135,0 @@ |
@@ -8,6 +8,16 @@ "use strict"; | ||
var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind")); | ||
var _getIterator2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator")); | ||
var _isArray3 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array")); | ||
var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array")); | ||
var _getIteratorMethod2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator-method")); | ||
var _symbol = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/symbol")); | ||
var _from = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/from")); | ||
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice")); | ||
var _some = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/some")); | ||
@@ -17,7 +27,34 @@ | ||
var _encode = require("../encode"); | ||
var _graph = require("../graph"); | ||
function _createForOfIteratorHelperLoose(o) { var _context2; var i = 0; if (typeof _symbol["default"] === "undefined" || (0, _getIteratorMethod2["default"])(o) == null) { if ((0, _isArray["default"])(o) || (o = _unsupportedIterableToArray(o))) return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } i = (0, _getIterator2["default"])(o); return (0, _bind["default"])(_context2 = i.next).call(_context2, i); } | ||
function _unsupportedIterableToArray(o, minLen) { var _context; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = (0, _slice["default"])(_context = Object.prototype.toString.call(o)).call(_context, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return (0, _from["default"])(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function rangeToPage(key, end, count) { | ||
var page = {}; | ||
page[count > 0 ? 'first' : 'last'] = count; | ||
if (key !== '') page.after = key; | ||
if (end !== "\uFFFF") page.before = end; | ||
if (key !== '') { | ||
var _keyStep = (0, _graph.keyStep)(key), | ||
k = _keyStep.key, | ||
step = _keyStep.step; | ||
page.after = (0, _encode.decodeKey)(k); | ||
if (step === 1) page.excludeAfter = true; | ||
} | ||
if (end !== "\uFFFF") { | ||
var _keyStep2 = (0, _graph.keyStep)(end), | ||
_k = _keyStep2.key, | ||
_step = _keyStep2.step; | ||
page.before = (0, _encode.decodeKey)(_k); | ||
if (_step === -1) page.excludeBefore = true; | ||
} | ||
return page; | ||
@@ -46,15 +83,4 @@ } | ||
for (var _iterator = query, _isArray = (0, _isArray3["default"])(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator2["default"])(_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 node = _ref; | ||
for (var _iterator = _createForOfIteratorHelperLoose(query), _step2; !(_step2 = _iterator()).done;) { | ||
var node = _step2.value; | ||
var child = (0, _node.isBranch)(node) ? decorateChildren(node.children) : true; | ||
@@ -79,15 +105,4 @@ | ||
for (var _iterator2 = query, _isArray2 = (0, _isArray3["default"])(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator2["default"])(_iterator2);;) { | ||
var _ref2; | ||
if (_isArray2) { | ||
if (_i2 >= _iterator2.length) break; | ||
_ref2 = _iterator2[_i2++]; | ||
} else { | ||
_i2 = _iterator2.next(); | ||
if (_i2.done) break; | ||
_ref2 = _i2.value; | ||
} | ||
var node = _ref2; | ||
for (var _iterator2 = _createForOfIteratorHelperLoose(query), _step3; !(_step3 = _iterator2()).done;) { | ||
var node = _step3.value; | ||
var child = (0, _node.isBranch)(node) ? decorateChildren(node.children) : true; | ||
@@ -94,0 +109,0 @@ var key = node.key; |
@@ -6,5 +6,5 @@ "use strict"; | ||
exports.__esModule = true; | ||
exports["default"] = id; | ||
exports["default"] = void 0; | ||
var _generate = _interopRequireDefault(require("nanoid/non-secure/generate")); | ||
var _nonSecure = require("nanoid/non-secure"); | ||
@@ -14,6 +14,5 @@ var _alphabet = _interopRequireDefault(require("./alphabet")); | ||
// The ID is 20 digits for a similar collision probability as UUID v4 | ||
function id() { | ||
return (0, _generate["default"])(_alphabet["default"], 20); | ||
} | ||
var _default = (0, _nonSecure.customAlphabet)(_alphabet["default"], 20); | ||
exports["default"] = _default; | ||
module.exports = exports.default; |
"use strict"; | ||
var _Object$keys = require("@babel/runtime-corejs3/core-js-stable/object/keys"); | ||
var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/for-each"); | ||
var _context; | ||
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault"); | ||
exports.__esModule = true; | ||
var _exportNames = { | ||
encodeUrl: true, | ||
key: true, | ||
encodeKey: true, | ||
decodeUrl: true, | ||
decodeKey: true, | ||
makeId: true | ||
}; | ||
exports.makeId = exports.decodeKey = exports.decodeUrl = exports.encodeKey = exports.key = exports.encodeUrl = void 0; | ||
@@ -21,2 +35,10 @@ | ||
exports.makeId = _id["default"]; | ||
exports.makeId = _id["default"]; | ||
var _serialize = require("./serialize.js"); | ||
_forEachInstanceProperty(_context = _Object$keys(_serialize)).call(_context, function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
exports[key] = _serialize[key]; | ||
}); |
@@ -9,9 +9,17 @@ "use strict"; | ||
var _symbol = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/symbol")); | ||
var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind")); | ||
var _getIterator2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator")); | ||
var _getIteratorMethod2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator-method")); | ||
var _from = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/from")); | ||
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice")); | ||
var _symbol = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/symbol")); | ||
var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/reduce")); | ||
var _isArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array")); | ||
var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array")); | ||
@@ -32,2 +40,8 @@ var _keys = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/keys")); | ||
function _createForOfIteratorHelperLoose(o) { var _context6; var i = 0; if (typeof _symbol["default"] === "undefined" || (0, _getIteratorMethod2["default"])(o) == null) { if ((0, _isArray["default"])(o) || (o = _unsupportedIterableToArray(o))) return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } i = (0, _getIterator2["default"])(o); return (0, _bind["default"])(_context6 = i.next).call(_context6, i); } | ||
function _unsupportedIterableToArray(o, minLen) { var _context5; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = (0, _slice["default"])(_context5 = Object.prototype.toString.call(o)).call(_context5, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return (0, _from["default"])(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
var NULL = 0; | ||
@@ -82,3 +96,3 @@ var FALSE = 1; | ||
if (typeof value === 'string') return [STR, (0, _string.encode)(value), NULL]; | ||
if ((0, _isArray2["default"])(value)) return encodeArray(value); | ||
if ((0, _isArray["default"])(value)) return encodeArray(value); | ||
if (typeof value === 'object') return encodeObject(value); | ||
@@ -96,16 +110,5 @@ return [NULL]; | ||
for (var _iterator = parts, _isArray = (0, _isArray2["default"])(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator2["default"])(_iterator);;) { | ||
var _ref; | ||
for (var _iterator = _createForOfIteratorHelperLoose(parts), _step; !(_step = _iterator()).done;) { | ||
var part = _step.value; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var part = _ref; | ||
if (typeof part === 'number') { | ||
@@ -173,3 +176,3 @@ buffer[i] = part; | ||
if ((0, _isArray2["default"])(current)) { | ||
if ((0, _isArray["default"])(current)) { | ||
current.push(value); | ||
@@ -176,0 +179,0 @@ current[COUNT]--; |
@@ -10,2 +10,16 @@ "use strict"; | ||
var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind")); | ||
var _getIterator2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator")); | ||
var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array")); | ||
var _getIteratorMethod2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator-method")); | ||
var _symbol = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/symbol")); | ||
var _from = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/from")); | ||
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice")); | ||
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map")); | ||
@@ -17,8 +31,10 @@ | ||
var _getIterator2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator")); | ||
var _node = require("../node"); | ||
var _isArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array")); | ||
function _createForOfIteratorHelperLoose(o) { var _context3; var i = 0; if (typeof _symbol["default"] === "undefined" || (0, _getIteratorMethod2["default"])(o) == null) { if ((0, _isArray["default"])(o) || (o = _unsupportedIterableToArray(o))) return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } i = (0, _getIterator2["default"])(o); return (0, _bind["default"])(_context3 = i.next).call(_context3, i); } | ||
var _node = require("../node"); | ||
function _unsupportedIterableToArray(o, minLen) { var _context2; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = (0, _slice["default"])(_context2 = Object.prototype.toString.call(o)).call(_context2, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return (0, _from["default"])(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function add(base, diff) { | ||
@@ -28,15 +44,4 @@ var changed = false; | ||
for (var _iterator = diff, _isArray = (0, _isArray2["default"])(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator2["default"])(_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 node = _ref; | ||
for (var _iterator = _createForOfIteratorHelperLoose(diff), _step; !(_step = _iterator()).done;) { | ||
var node = _step.value; | ||
var cmp = compare(node); | ||
@@ -43,0 +48,0 @@ var nodeIsBranch = (0, _node.isBranch)(node); |
@@ -10,2 +10,16 @@ "use strict"; | ||
var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind")); | ||
var _getIterator2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator")); | ||
var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array")); | ||
var _getIteratorMethod2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator-method")); | ||
var _symbol = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/symbol")); | ||
var _from = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/from")); | ||
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice")); | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends")); | ||
@@ -19,26 +33,17 @@ | ||
var _getIterator2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator")); | ||
var _node = require("../node"); | ||
var _isArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array")); | ||
var _step2 = require("./step"); | ||
var _node = require("../node"); | ||
function _createForOfIteratorHelperLoose(o) { var _context6; var i = 0; if (typeof _symbol["default"] === "undefined" || (0, _getIteratorMethod2["default"])(o) == null) { if ((0, _isArray["default"])(o) || (o = _unsupportedIterableToArray(o))) return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } i = (0, _getIterator2["default"])(o); return (0, _bind["default"])(_context6 = i.next).call(_context6, i); } | ||
var _step = require("./step"); | ||
function _unsupportedIterableToArray(o, minLen) { var _context5; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = (0, _slice["default"])(_context5 = Object.prototype.toString.call(o)).call(_context5, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return (0, _from["default"])(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function merge(current, changes) { | ||
var index = 0; | ||
for (var _iterator = changes, _isArray = (0, _isArray2["default"])(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator2["default"])(_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 change = _ref; | ||
for (var _iterator = _createForOfIteratorHelperLoose(changes), _step; !(_step = _iterator()).done;) { | ||
var change = _step.value; | ||
index = (0, _node.isRange)(change) ? insertRange(current, change, index) : insertNode(current, change, index); | ||
@@ -86,11 +91,11 @@ } | ||
if (node.version < base.version) { | ||
var _ref2 = [base, node]; | ||
node = _ref2[0]; | ||
base = _ref2[1]; | ||
var _ref = [base, node]; | ||
node = _ref[0]; | ||
base = _ref[1]; | ||
} | ||
return (0, _filter["default"])(_context2 = [base.key < node.key && (0, _extends2["default"])({}, base, { | ||
end: (0, _step.keyBefore)(node.key) | ||
end: (0, _step2.keyBefore)(node.key) | ||
}), node, base.end > node.end && (0, _extends2["default"])({}, base, { | ||
key: (0, _step.keyAfter)(node.end) | ||
key: (0, _step2.keyAfter)(node.end) | ||
})]).call(_context2, Boolean); | ||
@@ -126,5 +131,5 @@ } | ||
var insertions = (0, _filter["default"])(_context3 = [range.key < key && (0, _extends2["default"])({}, range, { | ||
end: (0, _step.keyBefore)(key) | ||
end: (0, _step2.keyBefore)(key) | ||
}), newChange, range.end > key && (0, _extends2["default"])({}, range, { | ||
key: (0, _step.keyAfter)(key) | ||
key: (0, _step2.keyAfter)(key) | ||
})]).call(_context3, Boolean); | ||
@@ -131,0 +136,0 @@ |
@@ -8,8 +8,18 @@ "use strict"; | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator")); | ||
var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind")); | ||
var _getIterator2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator")); | ||
var _isArray3 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array")); | ||
var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array")); | ||
var _getIteratorMethod2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator-method")); | ||
var _symbol = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/symbol")); | ||
var _from = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/from")); | ||
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice")); | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator")); | ||
var _some = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/some")); | ||
@@ -33,2 +43,8 @@ | ||
function _createForOfIteratorHelperLoose(o) { var _context4; var i = 0; if (typeof _symbol["default"] === "undefined" || (0, _getIteratorMethod2["default"])(o) == null) { if ((0, _isArray["default"])(o) || (o = _unsupportedIterableToArray(o))) return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } i = (0, _getIterator2["default"])(o); return (0, _bind["default"])(_context4 = i.next).call(_context4, i); } | ||
function _unsupportedIterableToArray(o, minLen) { var _context3; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = (0, _slice["default"])(_context3 = Object.prototype.toString.call(o)).call(_context3, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return (0, _from["default"])(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function mergeStreams() { | ||
@@ -39,5 +55,3 @@ return _mergeStreams.apply(this, arguments); | ||
function _mergeStreams() { | ||
_mergeStreams = (0, _wrapAsyncGenerator2["default"])( | ||
/*#__PURE__*/ | ||
_regenerator["default"].mark(function _callee() { | ||
_mergeStreams = (0, _wrapAsyncGenerator2["default"])( /*#__PURE__*/_regenerator["default"].mark(function _callee() { | ||
var _context; | ||
@@ -50,11 +64,7 @@ | ||
_iterator, | ||
_isArray, | ||
_i, | ||
_ref, | ||
_step, | ||
value, | ||
merged, | ||
_iterator2, | ||
_isArray2, | ||
_i2, | ||
_ref2, | ||
_step2, | ||
_value, | ||
@@ -79,124 +89,58 @@ _args = arguments; | ||
_context2.t1 = _context = _context2.sent; | ||
_context2.t2 = _context; | ||
_context2.t3 = function (iter) { | ||
firstValues = (0, _context2.t0)(_context2.t1).call(_context, function (iter) { | ||
return iter.value; | ||
}; | ||
}); | ||
firstValues = (0, _context2.t0)(_context2.t1).call(_context2.t2, _context2.t3); | ||
if (!(0, _some["default"])(firstValues).call(firstValues, function (value) { | ||
return typeof value === 'undefined'; | ||
})) { | ||
_context2.next = 30; | ||
_context2.next = 19; | ||
break; | ||
} | ||
_context2.next = 11; | ||
_context2.next = 9; | ||
return undefined; | ||
case 11: | ||
_iterator = firstValues, _isArray = (0, _isArray3["default"])(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator2["default"])(_iterator); | ||
case 9: | ||
_iterator = _createForOfIteratorHelperLoose(firstValues); | ||
case 12: | ||
if (!_isArray) { | ||
_context2.next = 18; | ||
case 10: | ||
if ((_step = _iterator()).done) { | ||
_context2.next = 17; | ||
break; | ||
} | ||
if (!(_i >= _iterator.length)) { | ||
_context2.next = 15; | ||
break; | ||
} | ||
value = _step.value; | ||
return _context2.abrupt("break", 28); | ||
case 15: | ||
_ref = _iterator[_i++]; | ||
_context2.next = 22; | ||
break; | ||
case 18: | ||
_i = _iterator.next(); | ||
if (!_i.done) { | ||
_context2.next = 21; | ||
break; | ||
} | ||
return _context2.abrupt("break", 28); | ||
case 21: | ||
_ref = _i.value; | ||
case 22: | ||
value = _ref; | ||
if (!(typeof value !== 'undefined')) { | ||
_context2.next = 26; | ||
_context2.next = 15; | ||
break; | ||
} | ||
_context2.next = 26; | ||
_context2.next = 15; | ||
return value; | ||
case 26: | ||
_context2.next = 12; | ||
case 15: | ||
_context2.next = 10; | ||
break; | ||
case 28: | ||
_context2.next = 48; | ||
case 17: | ||
_context2.next = 23; | ||
break; | ||
case 30: | ||
case 19: | ||
merged = []; | ||
_iterator2 = firstValues, _isArray2 = (0, _isArray3["default"])(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : (0, _getIterator2["default"])(_iterator2); | ||
case 32: | ||
if (!_isArray2) { | ||
_context2.next = 38; | ||
break; | ||
for (_iterator2 = _createForOfIteratorHelperLoose(firstValues); !(_step2 = _iterator2()).done;) { | ||
_value = _step2.value; | ||
(0, _merge["default"])(merged, _value); | ||
} | ||
if (!(_i2 >= _iterator2.length)) { | ||
_context2.next = 35; | ||
break; | ||
} | ||
return _context2.abrupt("break", 46); | ||
case 35: | ||
_ref2 = _iterator2[_i2++]; | ||
_context2.next = 42; | ||
break; | ||
case 38: | ||
_i2 = _iterator2.next(); | ||
if (!_i2.done) { | ||
_context2.next = 41; | ||
break; | ||
} | ||
return _context2.abrupt("break", 46); | ||
case 41: | ||
_ref2 = _i2.value; | ||
case 42: | ||
_value = _ref2; | ||
(0, _merge["default"])(merged, _value); | ||
case 44: | ||
_context2.next = 32; | ||
break; | ||
case 46: | ||
_context2.next = 48; | ||
_context2.next = 23; | ||
return merged; | ||
case 48: | ||
return _context2.delegateYield((0, _asyncGeneratorDelegate2["default"])((0, _asyncIterator2["default"])((0, _mergeAsyncIterators["default"])(streams)), _awaitAsyncGenerator2["default"]), "t4", 49); | ||
case 23: | ||
return _context2.delegateYield((0, _asyncGeneratorDelegate2["default"])((0, _asyncIterator2["default"])((0, _mergeAsyncIterators["default"])(streams)), _awaitAsyncGenerator2["default"]), "t2", 24); | ||
case 49: | ||
case 24: | ||
case "end": | ||
@@ -203,0 +147,0 @@ return _context2.stop(); |
@@ -8,6 +8,22 @@ "use strict"; | ||
var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind")); | ||
var _getIterator2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator")); | ||
var _isArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array")); | ||
var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array")); | ||
var _getIteratorMethod2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator-method")); | ||
var _symbol = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/symbol")); | ||
var _from = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/from")); | ||
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice")); | ||
function _createForOfIteratorHelperLoose(o) { var _context2; var i = 0; if (typeof _symbol["default"] === "undefined" || (0, _getIteratorMethod2["default"])(o) == null) { if ((0, _isArray["default"])(o) || (o = _unsupportedIterableToArray(o))) return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } i = (0, _getIterator2["default"])(o); return (0, _bind["default"])(_context2 = i.next).call(_context2, i); } | ||
function _unsupportedIterableToArray(o, minLen) { var _context; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = (0, _slice["default"])(_context = Object.prototype.toString.call(o)).call(_context, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return (0, _from["default"])(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
// import { isRange } from '../node'; | ||
@@ -17,15 +33,4 @@ // import { keyAfter } from './step'; | ||
// mergeRanges(graph); | ||
for (var _iterator = graph, _isArray = (0, _isArray2["default"])(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator2["default"])(_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 node = _ref; | ||
for (var _iterator = _createForOfIteratorHelperLoose(graph), _step; !(_step = _iterator()).done;) { | ||
var node = _step.value; | ||
node.version = version; | ||
@@ -32,0 +37,0 @@ if (node.children) setVersion(node.children, version); |
@@ -10,2 +10,16 @@ "use strict"; | ||
var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind")); | ||
var _getIterator2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator")); | ||
var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array")); | ||
var _getIteratorMethod2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator-method")); | ||
var _symbol = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/symbol")); | ||
var _from = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/from")); | ||
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice")); | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends")); | ||
@@ -19,10 +33,12 @@ | ||
var _getIterator2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator")); | ||
var _node2 = require("../node"); | ||
var _isArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array")); | ||
var _step2 = require("./step"); | ||
var _node = require("../node"); | ||
function _createForOfIteratorHelperLoose(o) { var _context7; var i = 0; if (typeof _symbol["default"] === "undefined" || (0, _getIteratorMethod2["default"])(o) == null) { if ((0, _isArray["default"])(o) || (o = _unsupportedIterableToArray(o))) return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } i = (0, _getIterator2["default"])(o); return (0, _bind["default"])(_context7 = i.next).call(_context7, i); } | ||
var _step = require("./step"); | ||
function _unsupportedIterableToArray(o, minLen) { var _context6; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = (0, _slice["default"])(_context6 = Object.prototype.toString.call(o)).call(_context6, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return (0, _from["default"])(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function sieve(current, changes, result) { | ||
@@ -35,16 +51,5 @@ if (result === void 0) { | ||
for (var _iterator = changes, _isArray = (0, _isArray2["default"])(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator2["default"])(_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 change = _ref; | ||
index = (0, _node.isRange)(change) ? insertRange(current, change, result, index) : insertNode(current, change, result, index); | ||
for (var _iterator = _createForOfIteratorHelperLoose(changes), _step; !(_step = _iterator()).done;) { | ||
var change = _step.value; | ||
index = (0, _node2.isRange)(change) ? insertRange(current, change, result, index) : insertNode(current, change, result, index); | ||
} | ||
@@ -64,4 +69,4 @@ | ||
end = change.end; | ||
var keyIx = (0, _node.getIndex)(current, key, start); | ||
var endIx = (0, _node.getLastIndex)(current, end, keyIx); | ||
var keyIx = (0, _node2.getIndex)(current, key, start); | ||
var endIx = (0, _node2.getLastIndex)(current, end, keyIx); | ||
@@ -71,6 +76,46 @@ if (keyIx === endIx && !(current[keyIx] && current[keyIx].key <= key && current[keyIx].end >= end)) { | ||
return keyIx; | ||
} // TODO: Extract the parts of result that are relevant. | ||
} | ||
var appliedChange = []; | ||
var currentKey = change.key; | ||
result.push(change); // If current contains nodes that are newer than this range, keep them. | ||
for (var i = keyIx; i < endIx; i++) { | ||
var node = current[i]; // We treat a negative version as a non-existent node | ||
// as this is a hack used by subscribe. | ||
if ((0, _node2.isRange)(node) && node.version >= 0) { | ||
if (node.key > currentKey) { | ||
appliedChange.push({ | ||
key: currentKey, | ||
end: (0, _step2.keyBefore)(node.key), | ||
version: change.version | ||
}); | ||
} | ||
currentKey = (0, _step2.keyAfter)(node.end); | ||
} else { | ||
if (getNewerChange(node, change)) { | ||
appliedChange.push({ | ||
key: currentKey, | ||
end: (0, _step2.keyBefore)(node.key), | ||
version: change.version | ||
}); | ||
currentKey = (0, _step2.keyAfter)(node.key); | ||
} | ||
} | ||
if (currentKey >= change.end) { | ||
break; | ||
} | ||
} | ||
if (currentKey <= change.end) { | ||
appliedChange.push({ | ||
key: currentKey, | ||
end: change.end, | ||
version: change.version | ||
}); | ||
} | ||
if (appliedChange.length) result.push.apply(result, appliedChange); // If current contains nodes that are newer than this range, keep them. | ||
// We do this by merging them back into insertions first. | ||
@@ -80,12 +125,15 @@ | ||
for (var i = keyIx; i < endIx; i++) { | ||
var node = current[i]; | ||
for (var _i = keyIx; _i < endIx; _i++) { | ||
var _node = current[_i]; | ||
if ((0, _node.isRange)(node)) { | ||
insertions.push.apply(insertions, mergeRanges(insertions.pop(), node)); | ||
if ((0, _node2.isRange)(_node)) { | ||
// console.log('Sieve Range-Range', debug(change), debug(node)); | ||
insertions.push.apply(insertions, mergeRanges(insertions.pop(), _node)); | ||
} else { | ||
insertNode(insertions, node, [], insertions.length - 1); | ||
// console.log('Sieve Change-Node', debug(change), debug(node)); | ||
insertNode(insertions, _node, [], insertions.length - 1); | ||
} | ||
} | ||
} // console.log('Sieve:insertions', debug(insertions)); | ||
(_spliceInstanceProper = (0, _splice["default"])(current)).call.apply(_spliceInstanceProper, (0, _concat["default"])(_context = [current, keyIx, endIx - keyIx]).call(_context, insertions)); | ||
@@ -102,5 +150,5 @@ | ||
if (node.version < base.version) { | ||
var _ref2 = [base, node]; | ||
node = _ref2[0]; | ||
base = _ref2[1]; | ||
var _ref = [base, node]; | ||
node = _ref[0]; | ||
base = _ref[1]; | ||
} // Ensure node is newer than base | ||
@@ -110,5 +158,5 @@ | ||
return (0, _filter["default"])(_context2 = [base.key < node.key && (0, _extends2["default"])({}, base, { | ||
end: (0, _step.keyBefore)(node.key) | ||
end: (0, _step2.keyBefore)(node.key) | ||
}), node, base.end > node.end && (0, _extends2["default"])({}, base, { | ||
key: (0, _step.keyAfter)(node.end) | ||
key: (0, _step2.keyAfter)(node.end) | ||
})]).call(_context2, Boolean); | ||
@@ -123,3 +171,3 @@ } | ||
var key = change.key; | ||
var index = (0, _node.getIndex)(current, key, start); | ||
var index = (0, _node2.getIndex)(current, key, start); | ||
var node = current[index]; | ||
@@ -129,3 +177,3 @@ | ||
// This change overlaps with something that exists. | ||
return (0, _node.isRange)(node) ? insertNodeIntoRange(current, index, change, result) : updateNode(current, index, change, result); | ||
return (0, _node2.isRange)(node) ? insertNodeIntoRange(current, index, change, result) : updateNode(current, index, change, result); | ||
} else { | ||
@@ -143,9 +191,10 @@ // This change does not overlap with any existing knowledge. Skip it | ||
var range = current[index]; | ||
var newChange = getNewer(change, range); | ||
var newChange = getNewerChange(change, range); | ||
var newNode = getNewerNode(change, range); | ||
if (!newChange) return; | ||
result.push(newChange); | ||
var insertions = (0, _filter["default"])(_context3 = [range.key < key && (0, _extends2["default"])({}, range, { | ||
end: (0, _step.keyBefore)(key) | ||
}), newChange, range.end > key && (0, _extends2["default"])({}, range, { | ||
key: (0, _step.keyAfter)(key) | ||
end: (0, _step2.keyBefore)(key) | ||
}), newNode, range.end > key && (0, _extends2["default"])({}, range, { | ||
key: (0, _step2.keyAfter)(key) | ||
})]).call(_context3, Boolean); | ||
@@ -161,3 +210,3 @@ | ||
if ((0, _node.isBranch)(change) && (0, _node.isBranch)(node)) { | ||
if ((0, _node2.isBranch)(change) && (0, _node2.isBranch)(node)) { | ||
// Both are branches: Recursively merge children. | ||
@@ -170,7 +219,7 @@ var nextResult = []; | ||
})); | ||
} else if ((0, _node.isBranch)(node)) { | ||
} else if ((0, _node2.isBranch)(node)) { | ||
// Current node is a branch but the change is a leaf; if the branch | ||
// has newer children, ignore the change and keep only those children; | ||
// Otherwise, discard the branch and keep the change. | ||
var newNode = getNewer(node, change); | ||
var newNode = getNewerNode(node, change); | ||
current[index] = newNode || change; | ||
@@ -180,10 +229,10 @@ if (!newNode) result.push(change); // TODO: In the case of partial removal, what should result be? | ||
// Current node is a leaf. Replace with the change if it is newer. | ||
var newChange = getNewer(change, node); | ||
var newChange = getNewerChange(change, node); | ||
if (newChange) { | ||
current[index] = newChange; // console.log(current); | ||
var _newNode = getNewerNode(change, node); | ||
if (change.value !== node.value || change.path !== node.path) { | ||
result.push(newChange); | ||
} | ||
if (_newNode) current[index] = _newNode; // console.log(current); | ||
if (newChange && (change.value !== node.value || !isPathEqual(change.path, node.path))) { | ||
result.push(newChange); | ||
} | ||
@@ -195,8 +244,37 @@ } | ||
function getNewer(node, base) { | ||
if ((0, _node.isBranch)(node)) { | ||
function isPathEqual(first, second) { | ||
if (!first && !second) return true; | ||
if (!first || !second) return false; | ||
if (first.length !== second.length) return false; | ||
for (var i = 0; i < first.length; i++) { | ||
if (first[i] !== second[i]) return false; | ||
} | ||
return true; | ||
} | ||
function getNewerNode(node, base) { | ||
if ((0, _node2.isBranch)(node)) { | ||
var children = [{ | ||
key: '', | ||
end: "\uFFFF", | ||
version: base.version | ||
}]; | ||
sieve(children, node.children); | ||
return children.length === 1 ? null : (0, _extends2["default"])({}, node, { | ||
children: children | ||
}); | ||
} else { | ||
// assertVersion(node, version); | ||
return node.version >= base.version ? node : null; | ||
} | ||
} | ||
function getNewerChange(node, base) { | ||
if ((0, _node2.isBranch)(node)) { | ||
var _context5; | ||
var children = (0, _filter["default"])(_context5 = node.children).call(_context5, function (child) { | ||
return getNewer(child, base); | ||
return getNewerChange(child, base); | ||
}); | ||
@@ -203,0 +281,0 @@ return children.length && (0, _extends2["default"])({}, node, { |
@@ -9,11 +9,21 @@ "use strict"; | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends")); | ||
var _bind = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/bind")); | ||
var _getIterator2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator")); | ||
var _isArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array")); | ||
var _isArray = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/is-array")); | ||
var _getIteratorMethod2 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/get-iterator-method")); | ||
var _symbol = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/symbol")); | ||
var _from = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/from")); | ||
var _slice3 = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice")); | ||
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends")); | ||
var _node2 = require("../node"); | ||
var _step = require("./step"); | ||
var _step2 = require("./step"); | ||
@@ -26,5 +36,9 @@ var _path = require("../path"); | ||
var Result = | ||
/*#__PURE__*/ | ||
function () { | ||
function _createForOfIteratorHelperLoose(o) { var _context2; var i = 0; if (typeof _symbol["default"] === "undefined" || (0, _getIteratorMethod2["default"])(o) == null) { if ((0, _isArray["default"])(o) || (o = _unsupportedIterableToArray(o))) return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } i = (0, _getIterator2["default"])(o); return (0, _bind["default"])(_context2 = i.next).call(_context2, i); } | ||
function _unsupportedIterableToArray(o, minLen) { var _context; if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = (0, _slice3["default"])(_context = Object.prototype.toString.call(o)).call(_context, 8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return (0, _from["default"])(n); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
var Result = /*#__PURE__*/function () { | ||
function Result(root) { | ||
@@ -63,16 +77,5 @@ // When linked queries are added, they are forwarded to the root. | ||
for (var _iterator = currentQuery, _isArray = (0, _isArray2["default"])(_iterator), _i = 0, _iterator = _isArray ? _iterator : (0, _getIterator2["default"])(_iterator);;) { | ||
var _ref; | ||
for (var _iterator = _createForOfIteratorHelperLoose(currentQuery), _step; !(_step = _iterator()).done;) { | ||
var queryNode = _step.value; | ||
if (_isArray) { | ||
if (_i >= _iterator.length) break; | ||
_ref = _iterator[_i++]; | ||
} else { | ||
_i = _iterator.next(); | ||
if (_i.done) break; | ||
_ref = _i.value; | ||
} | ||
var queryNode = _ref; | ||
if ((0, _node2.isRange)(queryNode)) { | ||
@@ -88,3 +91,3 @@ sliceRange(graph, queryNode, result); | ||
currentQuery = result.linked; | ||
currentQuery = root ? undefined : result.linked; | ||
delete result.linked; | ||
@@ -107,15 +110,30 @@ } | ||
// The graph is indicating that this value was deleted. | ||
result.addKnown({ | ||
key: key, | ||
end: key, | ||
version: graph.version | ||
}); | ||
if ((0, _node2.isBranch)(query)) { | ||
var _slice = slice([{ | ||
key: '', | ||
end: "\uFFFF", | ||
version: graph.version | ||
}], query.children), | ||
known = _slice.known; | ||
result.addKnown({ | ||
key: key, | ||
version: graph.version, | ||
children: known | ||
}); | ||
} else { | ||
result.addKnown({ | ||
key: key, | ||
end: key, | ||
version: graph.version | ||
}); | ||
} | ||
} else if ((0, _node2.isBranch)(graph) && (0, _node2.isBranch)(query)) { | ||
// Both sides are branches; recurse into them. | ||
var _slice = slice(graph.children, query.children, root), | ||
known = _slice.known, | ||
unknown = _slice.unknown; | ||
var _slice2 = slice(graph.children, query.children, root), | ||
_known = _slice2.known, | ||
unknown = _slice2.unknown; | ||
if (known) result.addKnown((0, _extends2["default"])({}, graph, { | ||
children: known | ||
if (_known) result.addKnown((0, _extends2["default"])({}, graph, { | ||
children: _known | ||
})); | ||
@@ -162,7 +180,7 @@ if (unknown) result.addUnknown((0, _extends2["default"])({}, query, { | ||
key = (0, _step.keyAfter)(node.end || node.key); | ||
key = (0, _step2.keyAfter)(node.end || node.key); | ||
} | ||
} else { | ||
for (var _i2 = (0, _node2.getLastIndex)(graph, end) - 1; end >= key && count < 0; _i2--) { | ||
var _node = graph[_i2]; | ||
for (var _i = (0, _node2.getLastIndex)(graph, end) - 1; end >= key && count < 0; _i--) { | ||
var _node = graph[_i]; | ||
if (!_node || end > (_node.end || _node.key) || (0, _node2.isOlder)(_node, version)) break; | ||
@@ -179,3 +197,3 @@ | ||
end = (0, _step.keyBefore)(_node.key); | ||
end = (0, _step2.keyBefore)(_node.key); | ||
} | ||
@@ -182,0 +200,0 @@ } |
"use strict"; | ||
exports.__esModule = true; | ||
exports.keyStep = keyStep; | ||
exports.keyBefore = keyBefore; | ||
exports.keyAfter = keyAfter; | ||
function keyStep(key) { | ||
if (key === '') return { | ||
key: key, | ||
step: 1 | ||
}; | ||
if (key === "\uFFFF") return { | ||
key: key, | ||
step: -1 | ||
}; | ||
var l = key.length - 1; | ||
switch (key.charCodeAt(l)) { | ||
case 0: | ||
return { | ||
key: key.substr(0, l), | ||
step: 1 | ||
}; | ||
case 0xffff: | ||
return { | ||
key: key.substr(0, l - 1) + String.fromCharCode(key.charCodeAt(l - 1) + 1), | ||
step: -1 | ||
}; | ||
default: | ||
return { | ||
key: key, | ||
step: 0 | ||
}; | ||
} | ||
} | ||
function keyBefore(key) { | ||
if (key === '') return key; | ||
if (key === '' || key === "\uFFFF") return key; | ||
var l = key.length - 1; | ||
@@ -14,5 +47,5 @@ return key.charCodeAt(l) === 0 ? key.substr(0, l) : key.substr(0, l) + String.fromCharCode(key.charCodeAt(l) - 1) + "\uFFFF"; | ||
function keyAfter(key) { | ||
if (key === "\uFFFF") return key; | ||
if (key === '' || key === "\uFFFF") return key; | ||
var l = key.length - 1; | ||
return key.charCodeAt(l) === 0xffff ? key.substr(0, l - 1) + String.fromCharCode(key.charCodeAt(l - 1) + 1) : key + '\0'; | ||
} |
@@ -5,3 +5,3 @@ { | ||
"author": "aravind (https://github.com/aravindet)", | ||
"version": "0.14.6-alpha1", | ||
"version": "0.14.6-alpha10", | ||
"main": "index.js", | ||
@@ -16,4 +16,4 @@ "source": "src/index.js", | ||
"dependencies": { | ||
"@babel/runtime-corejs3": "^7.8.4", | ||
"nanoid": "^2.1.11", | ||
"@babel/runtime-corejs3": "^7.9.2", | ||
"nanoid": "^3.1.3", | ||
"text-encoder-lite": "^2.0.0", | ||
@@ -20,0 +20,0 @@ "merge-async-iterators": "^0.2.1" |
@@ -5,3 +5,11 @@ import { slice, merge, setVersion } from '../graph'; | ||
const empty = [{ key: '', end: '\uffff', version: 0 }]; | ||
return slice(setVersion(merge(empty, graph), version), query).known; | ||
const res = slice(setVersion(merge(empty, graph), version), query, { | ||
addLinked: () => { | ||
/* | ||
This is quite a hacky way to prevent slice from trying to expand | ||
links. | ||
*/ | ||
}, | ||
}).known; | ||
return res; | ||
} |
import { merge } from '../graph'; | ||
import { makePath } from '../path'; | ||
import { isRange } from '../node'; | ||
import { encodeKey } from '../encode'; | ||
@@ -10,5 +11,10 @@ function makeGraph(key, value, version) { | ||
} else if (Array.isArray(value)) { | ||
// console.warn('makeGraph: Unnecessary call with', value); | ||
// This has already been converted to a CRDT graph | ||
return { key, version, children: value }; | ||
// Convert the KV-tuple format to a graph | ||
return { | ||
key, | ||
version, | ||
children: value | ||
.map(([k, v]) => makeGraph(encodeKey(k), v, version)) | ||
.sort((a, b) => (a.key <= b.key ? -1 : 1)), | ||
}; | ||
} else if (value === null) { | ||
@@ -53,1 +59,5 @@ // This is a single key known to be missing. | ||
} | ||
export function value(value) { | ||
return (key, version) => ({ key, version, value }); | ||
} |
@@ -1,3 +0,3 @@ | ||
export { graph as makeGraph, page, link } from './graph'; | ||
export { graph as makeGraph, page, link, value } from './graph'; | ||
export { query as makeQuery } from './query'; | ||
export { default as finalize } from './finalize'; |
@@ -1,8 +0,13 @@ | ||
const MAX_PAGE_SIZE = 4096; | ||
import { key } from '../encode'; | ||
import { keyBefore, keyAfter } from '../graph'; | ||
const FALLBACK_PAGE_SIZE = 4096; | ||
function pageToRange(page) { | ||
const node = {}; | ||
node.key = page.after || ''; | ||
node.end = page.before || '\uffff'; | ||
node.count = page.first || -page.last || MAX_PAGE_SIZE; | ||
node.key = typeof page.after !== 'undefined' ? key(page.after) : ''; | ||
node.end = typeof page.before !== 'undefined' ? key(page.before) : '\uffff'; | ||
node.count = page.first || -page.last || FALLBACK_PAGE_SIZE; | ||
if (page.excludeAfter) node.key = keyAfter(node.key); | ||
if (page.excludeBefore) node.end = keyBefore(node.end); | ||
return node; | ||
@@ -17,2 +22,3 @@ } | ||
if (Array.isArray(value)) { | ||
if (value.length === 1) value.unshift({}); | ||
return freeze({ | ||
@@ -19,0 +25,0 @@ children: freeze([ |
import { isRange, isBranch } from '../node'; | ||
import { decodeKey } from '../encode'; | ||
import { keyStep } from '../graph'; | ||
@@ -6,4 +8,12 @@ function rangeToPage(key, end, count) { | ||
page[count > 0 ? 'first' : 'last'] = count; | ||
if (key !== '') page.after = key; | ||
if (end !== '\uffff') page.before = end; | ||
if (key !== '') { | ||
const { key: k, step } = keyStep(key); | ||
page.after = decodeKey(k); | ||
if (step === 1) page.excludeAfter = true; | ||
} | ||
if (end !== '\uffff') { | ||
const { key: k, step } = keyStep(end); | ||
page.before = decodeKey(k); | ||
if (step === -1) page.excludeBefore = true; | ||
} | ||
return page; | ||
@@ -10,0 +20,0 @@ } |
@@ -1,7 +0,5 @@ | ||
import generate from 'nanoid/non-secure/generate'; | ||
import { customAlphabet } from 'nanoid/non-secure'; | ||
import alpha from './alphabet'; | ||
// The ID is 20 digits for a similar collision probability as UUID v4 | ||
export default function id() { | ||
return generate(alpha, 20); | ||
} | ||
export default customAlphabet(alpha, 20); |
@@ -8,1 +8,2 @@ export { encode as encodeUrl, decode as decodeUrl } from './url.js'; | ||
export { default as makeId } from './id.js'; | ||
export * from './serialize.js'; |
@@ -27,5 +27,42 @@ import { isBranch, isRange, getIndex, getLastIndex } from '../node'; | ||
// TODO: Extract the parts of result that are relevant. | ||
result.push(change); | ||
const appliedChange = []; | ||
let currentKey = change.key; | ||
for (let i = keyIx; i < endIx; i++) { | ||
const node = current[i]; | ||
// We treat a negative version as a non-existent node | ||
// as this is a hack used by subscribe. | ||
if (isRange(node) && node.version >= 0) { | ||
if (node.key > currentKey) { | ||
appliedChange.push({ | ||
key: currentKey, | ||
end: keyBefore(node.key), | ||
version: change.version, | ||
}); | ||
} | ||
currentKey = keyAfter(node.end); | ||
} else { | ||
if (getNewerChange(node, change)) { | ||
appliedChange.push({ | ||
key: currentKey, | ||
end: keyBefore(node.key), | ||
version: change.version, | ||
}); | ||
currentKey = keyAfter(node.key); | ||
} | ||
} | ||
if (currentKey >= change.end) { | ||
break; | ||
} | ||
} | ||
if (currentKey <= change.end) { | ||
appliedChange.push({ | ||
key: currentKey, | ||
end: change.end, | ||
version: change.version, | ||
}); | ||
} | ||
if (appliedChange.length) result.push(...appliedChange); | ||
// If current contains nodes that are newer than this range, keep them. | ||
@@ -37,4 +74,6 @@ // We do this by merging them back into insertions first. | ||
if (isRange(node)) { | ||
// console.log('Sieve Range-Range', debug(change), debug(node)); | ||
insertions.push(...mergeRanges(insertions.pop(), node)); | ||
} else { | ||
// console.log('Sieve Change-Node', debug(change), debug(node)); | ||
insertNode(insertions, node, [], insertions.length - 1); | ||
@@ -44,2 +83,4 @@ } | ||
// console.log('Sieve:insertions', debug(insertions)); | ||
current.splice(keyIx, endIx - keyIx, ...insertions); | ||
@@ -82,3 +123,4 @@ return keyIx + insertions.length; | ||
const range = current[index]; | ||
const newChange = getNewer(change, range); | ||
const newChange = getNewerChange(change, range); | ||
const newNode = getNewerNode(change, range); | ||
if (!newChange) return; | ||
@@ -89,3 +131,3 @@ result.push(newChange); | ||
range.key < key && { ...range, end: keyBefore(key) }, | ||
newChange, | ||
newNode, | ||
range.end > key && { ...range, key: keyAfter(key) }, | ||
@@ -110,3 +152,3 @@ ].filter(Boolean); | ||
// Otherwise, discard the branch and keep the change. | ||
const newNode = getNewer(node, change); | ||
const newNode = getNewerNode(node, change); | ||
current[index] = newNode || change; | ||
@@ -117,9 +159,11 @@ if (!newNode) result.push(change); | ||
// Current node is a leaf. Replace with the change if it is newer. | ||
const newChange = getNewer(change, node); | ||
if (newChange) { | ||
current[index] = newChange; | ||
// console.log(current); | ||
if (change.value !== node.value || change.path !== node.path) { | ||
result.push(newChange); | ||
} | ||
const newChange = getNewerChange(change, node); | ||
const newNode = getNewerNode(change, node); | ||
if (newNode) current[index] = newNode; | ||
// console.log(current); | ||
if ( | ||
newChange && | ||
(change.value !== node.value || !isPathEqual(change.path, node.path)) | ||
) { | ||
result.push(newChange); | ||
} | ||
@@ -130,5 +174,26 @@ } | ||
function getNewer(node, base) { | ||
function isPathEqual(first, second) { | ||
if (!first && !second) return true; | ||
if (!first || !second) return false; | ||
if (first.length !== second.length) return false; | ||
for (let i = 0; i < first.length; i++) { | ||
if (first[i] !== second[i]) return false; | ||
} | ||
return true; | ||
} | ||
function getNewerNode(node, base) { | ||
if (isBranch(node)) { | ||
const children = node.children.filter(child => getNewer(child, base)); | ||
const children = [{ key: '', end: '\uffff', version: base.version }]; | ||
sieve(children, node.children); | ||
return children.length === 1 ? null : { ...node, children }; | ||
} else { | ||
// assertVersion(node, version); | ||
return node.version >= base.version ? node : null; | ||
} | ||
} | ||
function getNewerChange(node, base) { | ||
if (isBranch(node)) { | ||
const children = node.children.filter(child => getNewerChange(child, base)); | ||
return children.length && { ...node, children }; | ||
@@ -135,0 +200,0 @@ } else { |
@@ -52,3 +52,3 @@ import { | ||
} | ||
currentQuery = result.linked; | ||
currentQuery = root ? undefined : result.linked; | ||
delete result.linked; | ||
@@ -69,3 +69,11 @@ } | ||
// The graph is indicating that this value was deleted. | ||
result.addKnown({ key, end: key, version: graph.version }); | ||
if (isBranch(query)) { | ||
const { known } = slice( | ||
[{ key: '', end: '\uffff', version: graph.version }], | ||
query.children, | ||
); | ||
result.addKnown({ key, version: graph.version, children: known }); | ||
} else { | ||
result.addKnown({ key, end: key, version: graph.version }); | ||
} | ||
} else if (isBranch(graph) && isBranch(query)) { | ||
@@ -72,0 +80,0 @@ // Both sides are branches; recurse into them. |
@@ -0,3 +1,21 @@ | ||
export function keyStep(key) { | ||
if (key === '') return { key, step: 1 }; | ||
if (key === '\uffff') return { key, step: -1 }; | ||
const l = key.length - 1; | ||
switch (key.charCodeAt(l)) { | ||
case 0: | ||
return { key: key.substr(0, l), step: 1 }; | ||
case 0xffff: | ||
return { | ||
key: | ||
key.substr(0, l - 1) + String.fromCharCode(key.charCodeAt(l - 1) + 1), | ||
step: -1, | ||
}; | ||
default: | ||
return { key, step: 0 }; | ||
} | ||
} | ||
export function keyBefore(key) { | ||
if (key === '') return key; | ||
if (key === '' || key === '\uffff') return key; | ||
const l = key.length - 1; | ||
@@ -10,3 +28,3 @@ return key.charCodeAt(l) === 0 | ||
export function keyAfter(key) { | ||
if (key === '\uffff') return key; | ||
if (key === '' || key === '\uffff') return key; | ||
const l = key.length - 1; | ||
@@ -13,0 +31,0 @@ return key.charCodeAt(l) === 0xffff |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
122946
66
3075
+ Addednanoid@3.3.8(transitive)
- Removednanoid@2.1.11(transitive)
Updatednanoid@^3.1.3