@graffy/common
Advanced tools
Comparing version 0.13.10 to 0.13.11
@@ -10,2 +10,4 @@ "use strict"; | ||
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter")); | ||
var _now = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/date/now")); | ||
@@ -25,2 +27,4 @@ | ||
var _node = require("../node"); | ||
function makeGraph(key, value, version) { | ||
@@ -82,10 +86,23 @@ if (typeof value === 'function') { | ||
return function (outerKey, version) { | ||
var _context3, _context4; | ||
var nodes = graph(obj, version); | ||
var gaps = (0, _filter["default"])(_context3 = (0, _graph.merge)([{ | ||
key: key, | ||
end: end, | ||
version: version | ||
}], (0, _map["default"])(_context4 = (0, _keys["default"])(obj)).call(_context4, function (key) { | ||
return { | ||
key: key, | ||
value: 1, | ||
version: version | ||
}; | ||
}))).call(_context3, function (node) { | ||
return (0, _node.isRange)(node); | ||
}); | ||
var children = (0, _graph.merge)(nodes, gaps); | ||
return { | ||
key: outerKey, | ||
version: version, | ||
children: (0, _graph.merge)([{ | ||
key: key, | ||
end: end, | ||
version: version | ||
}], graph(obj, version)) | ||
children: children | ||
}; | ||
@@ -92,0 +109,0 @@ }; |
@@ -6,3 +6,3 @@ "use strict"; | ||
exports.__esModule = true; | ||
exports.makeFinalGraph = exports.makeQuery = exports.link = exports.page = exports.makeGraph = void 0; | ||
exports.finalize = exports.makeQuery = exports.link = exports.page = exports.makeGraph = void 0; | ||
@@ -19,4 +19,4 @@ var _graph = require("./graph"); | ||
var _final = _interopRequireDefault(require("./final")); | ||
var _finalize = _interopRequireDefault(require("./finalize")); | ||
exports.makeFinalGraph = _final["default"]; | ||
exports.finalize = _finalize["default"]; |
@@ -148,4 +148,8 @@ "use strict"; | ||
var key = node.key; | ||
if ((0, _node.isRange)(node)) continue; | ||
if ((0, _node.isRange)(node)) { | ||
result[key] = null; | ||
continue; | ||
} | ||
if ((0, _node.isLink)(node)) { | ||
@@ -152,0 +156,0 @@ links.push([result, key, node.path]); |
@@ -120,3 +120,3 @@ "use strict"; | ||
var range = current[index]; | ||
var newChange = getNewer(change, range.version); | ||
var newChange = getNewer(change, range); | ||
if (!newChange) return; | ||
@@ -144,7 +144,7 @@ var insertions = (0, _filter["default"])(_context3 = [range.key < key && (0, _extends2["default"])({}, range, { | ||
// Otherwise, discard the branch and keep the change. | ||
var newNode = getNewer(node, change.version); | ||
var newNode = getNewer(node, change); | ||
current[index] = newNode || change; | ||
} else { | ||
// Current node is a leaf. Replace with the change if it is newer. | ||
var newChange = getNewer(change, node.version); | ||
var newChange = getNewer(change, node); | ||
if (newChange) current[index] = newChange; | ||
@@ -156,10 +156,13 @@ } | ||
function getNewer(node, version) { | ||
function getNewer(node, base) { | ||
var version = base.version; | ||
if ((0, _node.isBranch)(node)) { | ||
var _context5; | ||
var children = (0, _filter["default"])(_context5 = node.children).call(_context5, function (child) { | ||
return getNewer(child, version); | ||
}); | ||
return children.length && (0, _extends2["default"])({}, node, { | ||
var children = [{ | ||
key: '', | ||
end: "\uFFFF", | ||
version: version | ||
}]; | ||
merge(children, node.children); | ||
return children.length === 1 ? null : (0, _extends2["default"])({}, node, { | ||
children: children | ||
@@ -166,0 +169,0 @@ }); |
@@ -32,2 +32,4 @@ "use strict"; | ||
} | ||
return graph; | ||
} // function mergeRanges(graph) { | ||
@@ -34,0 +36,0 @@ // for (let i = 0; i < graph.length; i++) { |
@@ -101,3 +101,7 @@ "use strict"; | ||
// The graph is indicating that this value was deleted. | ||
result.addKnown(graph); | ||
result.addKnown({ | ||
key: key, | ||
end: key, | ||
version: graph.version | ||
}); | ||
} else if ((0, _node2.isBranch)(graph) && (0, _node2.isBranch)(query)) { | ||
@@ -104,0 +108,0 @@ // Both sides are branches; recurse into them. |
@@ -5,3 +5,3 @@ { | ||
"author": "aravind (https://github.com/aravindet)", | ||
"version": "0.13.10", | ||
"version": "0.13.11", | ||
"main": "index.js", | ||
@@ -8,0 +8,0 @@ "source": "src/index.js", |
@@ -16,4 +16,2 @@ "use strict"; | ||
var _now = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/date/now")); | ||
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice")); | ||
@@ -45,3 +43,3 @@ | ||
if (version === void 0) { | ||
version = (0, _now["default"])(); | ||
version = 0; | ||
} | ||
@@ -48,0 +46,0 @@ |
import { merge } from '../graph'; | ||
import { makePath } from '../path'; | ||
import { isRange } from '../node'; | ||
@@ -33,7 +34,12 @@ function makeGraph(key, value, version) { | ||
export function page(obj, key = '', end = '\uffff') { | ||
return (outerKey, version) => ({ | ||
key: outerKey, | ||
version, | ||
children: merge([{ key, end, version }], graph(obj, version)), | ||
}); | ||
return (outerKey, version) => { | ||
const nodes = graph(obj, version); | ||
const gaps = merge( | ||
[{ key, end, version }], | ||
Object.keys(obj).map(key => ({ key, value: 1, version })), | ||
).filter(node => isRange(node)); | ||
const children = merge(nodes, gaps); | ||
return { key: outerKey, version, children }; | ||
}; | ||
} | ||
@@ -40,0 +46,0 @@ |
export { graph as makeGraph, page, link } from './graph'; | ||
export { query as makeQuery } from './query'; | ||
export { default as makeFinalGraph } from './final'; | ||
export { default as finalize } from './finalize'; |
@@ -71,3 +71,6 @@ import { isRange, isBranch, isLink } from '../node'; | ||
const key = node.key; | ||
if (isRange(node)) continue; | ||
if (isRange(node)) { | ||
result[key] = null; | ||
continue; | ||
} | ||
if (isLink(node)) { | ||
@@ -74,0 +77,0 @@ links.push([result, key, node.path]); |
@@ -66,3 +66,3 @@ import { isBranch, isRange, getIndex, getLastIndex } from '../node'; | ||
const range = current[index]; | ||
const newChange = getNewer(change, range.version); | ||
const newChange = getNewer(change, range); | ||
if (!newChange) return; | ||
@@ -89,7 +89,7 @@ | ||
// Otherwise, discard the branch and keep the change. | ||
const newNode = getNewer(node, change.version); | ||
const newNode = getNewer(node, change); | ||
current[index] = newNode || change; | ||
} else { | ||
// Current node is a leaf. Replace with the change if it is newer. | ||
const newChange = getNewer(change, node.version); | ||
const newChange = getNewer(change, node); | ||
if (newChange) current[index] = newChange; | ||
@@ -100,6 +100,8 @@ } | ||
function getNewer(node, version) { | ||
function getNewer(node, base) { | ||
const { version } = base; | ||
if (isBranch(node)) { | ||
const children = node.children.filter(child => getNewer(child, version)); | ||
return children.length && { ...node, children }; | ||
const children = [{ key: '', end: '\uffff', version }]; | ||
merge(children, node.children); | ||
return children.length === 1 ? null : { ...node, children }; | ||
} else { | ||
@@ -106,0 +108,0 @@ // assertVersion(node, version); |
@@ -10,2 +10,3 @@ // import { isRange } from '../node'; | ||
} | ||
return graph; | ||
} | ||
@@ -12,0 +13,0 @@ |
@@ -67,3 +67,3 @@ import { | ||
// The graph is indicating that this value was deleted. | ||
result.addKnown(graph); | ||
result.addKnown({ key, end: key, version: graph.version }); | ||
} else if (isBranch(graph) && isBranch(query)) { | ||
@@ -70,0 +70,0 @@ // Both sides are branches; recurse into them. |
@@ -16,3 +16,3 @@ import { getIndex, isRange, isBranch } from '../node'; | ||
export function wrap(graph, path, version = Date.now()) { | ||
export function wrap(graph, path, version = 0) { | ||
if (!Array.isArray(graph) || !graph.length) return; | ||
@@ -19,0 +19,0 @@ if (!Array.isArray(path)) throw Error('wrap.path_not_array ' + path); |
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
100303
2795