@dstanesc/o-o-o-o-o-o-o
Version:
O-O-O-O-O-O-O is a collection of content addressed persistent data structures
167 lines • 8.94 kB
JavaScript
var __asyncValues = (this && this.__asyncValues) || function (o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
};
import { memoryBlockStoreFactory, } from '../block-store';
import { compute_chunks } from '@dstanesc/wasm-chunking-fastcdc-node';
import { chunkerFactory } from '../chunking';
import { linkCodecFactory, valueCodecFactory, } from '../codecs';
import { Graph } from '../graph';
import { graphStore } from '../graph-store';
import * as assert from 'assert';
import { indexStoreFactory } from '../index-store-factory';
import { navigateVertices, PathElemType, RequestBuilder } from '../navigate';
import { eq } from '../ops';
import { versionStoreFactory } from '../version-store';
const { chunk } = chunkerFactory(1024, compute_chunks);
const linkCodec = linkCodecFactory();
const valueCodec = valueCodecFactory();
describe('Indexing', function () {
test('index store api', async () => {
const blockStore = memoryBlockStoreFactory();
const indexStore = indexStoreFactory(blockStore);
const root = await indexStore.indexCreate([{ value: 'aaa', ref: 111 }]);
const result = await indexStore.indexSearch(root, 'aaa');
assert.strictEqual(result.ref, 111);
assert.strictEqual(result.value, 'aaa');
});
test('create index', async () => {
var _a, e_1, _b, _c;
let ObjectTypes;
(function (ObjectTypes) {
ObjectTypes[ObjectTypes["TWEET"] = 1] = "TWEET";
})(ObjectTypes || (ObjectTypes = {}));
let RlshpTypes;
(function (RlshpTypes) {
RlshpTypes[RlshpTypes["COMMENT_TO"] = 1] = "COMMENT_TO";
})(RlshpTypes || (RlshpTypes = {}));
let PropTypes;
(function (PropTypes) {
PropTypes[PropTypes["NAME"] = 2] = "NAME";
PropTypes[PropTypes["COMMENT"] = 3] = "COMMENT";
})(PropTypes || (PropTypes = {}));
let KeyTypes;
(function (KeyTypes) {
KeyTypes[KeyTypes["NAME"] = 33] = "NAME";
KeyTypes[KeyTypes["TEXT"] = 11] = "TEXT";
})(KeyTypes || (KeyTypes = {}));
let IndexTypes;
(function (IndexTypes) {
IndexTypes[IndexTypes["L2_NAME"] = 33] = "L2_NAME";
})(IndexTypes || (IndexTypes = {}));
const blockStore = memoryBlockStoreFactory();
const story = await versionStoreFactory({
chunk,
linkCodec,
valueCodec,
blockStore,
});
const store = graphStore({ chunk, linkCodec, valueCodec, blockStore });
const indexStore = indexStoreFactory(blockStore);
const graph = new Graph(story, store, indexStore);
const tx = graph.tx();
await tx.start();
const v1 = tx.addVertex(ObjectTypes.TWEET);
// second level
const v2 = tx.addVertex(ObjectTypes.TWEET);
const v3 = tx.addVertex(ObjectTypes.TWEET);
const v4 = tx.addVertex(ObjectTypes.TWEET);
const v5 = tx.addVertex(ObjectTypes.TWEET);
const v6 = tx.addVertex(ObjectTypes.TWEET);
const v7 = tx.addVertex(ObjectTypes.TWEET);
const v8 = tx.addVertex(ObjectTypes.TWEET);
const v9 = tx.addVertex(ObjectTypes.TWEET);
const v10 = tx.addVertex(ObjectTypes.TWEET);
const v11 = tx.addVertex(ObjectTypes.TWEET);
const v12 = tx.addVertex(ObjectTypes.TWEET);
const v13 = tx.addVertex(ObjectTypes.TWEET);
const v14 = tx.addVertex(ObjectTypes.TWEET);
const v15 = tx.addVertex(ObjectTypes.TWEET);
const e1 = await tx.addEdge(v1, v2, RlshpTypes.COMMENT_TO);
const e2 = await tx.addEdge(v1, v3, RlshpTypes.COMMENT_TO);
const e3 = await tx.addEdge(v1, v4, RlshpTypes.COMMENT_TO);
const e4 = await tx.addEdge(v1, v5, RlshpTypes.COMMENT_TO);
const e5 = await tx.addEdge(v1, v6, RlshpTypes.COMMENT_TO);
const e6 = await tx.addEdge(v1, v7, RlshpTypes.COMMENT_TO);
const e7 = await tx.addEdge(v1, v8, RlshpTypes.COMMENT_TO);
const e8 = await tx.addEdge(v1, v9, RlshpTypes.COMMENT_TO);
const e9 = await tx.addEdge(v1, v10, RlshpTypes.COMMENT_TO);
const e10 = await tx.addEdge(v1, v11, RlshpTypes.COMMENT_TO);
const e11 = await tx.addEdge(v1, v12, RlshpTypes.COMMENT_TO);
const e12 = await tx.addEdge(v1, v13, RlshpTypes.COMMENT_TO);
const e13 = await tx.addEdge(v1, v14, RlshpTypes.COMMENT_TO);
const e14 = await tx.addEdge(v1, v15, RlshpTypes.COMMENT_TO);
await tx.addVertexProp(v2, KeyTypes.NAME, 'v2', PropTypes.NAME);
await tx.addVertexProp(v3, KeyTypes.NAME, 'v3', PropTypes.NAME);
await tx.addVertexProp(v4, KeyTypes.NAME, 'v4', PropTypes.NAME);
await tx.addVertexProp(v5, KeyTypes.NAME, 'v5', PropTypes.NAME);
await tx.addVertexProp(v6, KeyTypes.NAME, 'v6', PropTypes.NAME);
await tx.addVertexProp(v7, KeyTypes.NAME, 'v7', PropTypes.NAME);
await tx.addVertexProp(v8, KeyTypes.NAME, 'v8', PropTypes.NAME);
await tx.addVertexProp(v9, KeyTypes.NAME, 'v9', PropTypes.NAME);
await tx.addVertexProp(v10, KeyTypes.NAME, 'v10', PropTypes.NAME);
await tx.addVertexProp(v11, KeyTypes.NAME, 'v11', PropTypes.NAME);
await tx.addVertexProp(v12, KeyTypes.NAME, 'v12', PropTypes.NAME);
await tx.addVertexProp(v13, KeyTypes.NAME, 'v13', PropTypes.NAME);
await tx.addVertexProp(v14, KeyTypes.NAME, 'v14', PropTypes.NAME);
await tx.addVertexProp(v15, KeyTypes.NAME, 'v15', PropTypes.NAME);
await tx.addVertexProp(v2, KeyTypes.TEXT, 'Comment v2', PropTypes.COMMENT);
await tx.addVertexProp(v3, KeyTypes.TEXT, 'Comment v3', PropTypes.COMMENT);
await tx.addVertexProp(v4, KeyTypes.TEXT, 'Comment v4', PropTypes.COMMENT);
await tx.addVertexProp(v5, KeyTypes.TEXT, 'Comment v5', PropTypes.COMMENT);
await tx.addVertexProp(v6, KeyTypes.TEXT, 'Comment v6', PropTypes.COMMENT);
await tx.addVertexProp(v7, KeyTypes.TEXT, 'Comment v7', PropTypes.COMMENT);
await tx.addVertexProp(v8, KeyTypes.TEXT, 'Comment v8', PropTypes.COMMENT);
await tx.addVertexProp(v9, KeyTypes.TEXT, 'Comment v9', PropTypes.COMMENT);
await tx.addVertexProp(v10, KeyTypes.TEXT, 'Comment v10', PropTypes.COMMENT);
await tx.addVertexProp(v11, KeyTypes.TEXT, 'Comment v11', PropTypes.COMMENT);
await tx.addVertexProp(v12, KeyTypes.TEXT, 'Comment v12', PropTypes.COMMENT);
await tx.addVertexProp(v13, KeyTypes.TEXT, 'Comment v13', PropTypes.COMMENT);
await tx.addVertexProp(v14, KeyTypes.TEXT, 'Comment v14', PropTypes.COMMENT);
await tx.addVertexProp(v15, KeyTypes.TEXT, 'Comment v15', PropTypes.COMMENT);
const index = await tx.uniqueIndex(v1, KeyTypes.NAME, IndexTypes.L2_NAME);
const { root } = await tx.commit({});
const request = new RequestBuilder()
.add(PathElemType.VERTEX)
.add(PathElemType.EDGE)
.add(PathElemType.VERTEX)
.propPred(KeyTypes.NAME, eq('v10'))
.extract(KeyTypes.TEXT)
.maxResults(10)
.get();
const g = new Graph(story, store, indexStore);
blockStore.resetReads();
const results = [];
try {
for (var _d = true, _e = __asyncValues(navigateVertices(g, [v1.offset], request)), _f; _f = await _e.next(), _a = _f.done, !_a;) {
_c = _f.value;
_d = false;
try {
const result = _c;
results.push(result);
}
finally {
_d = true;
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
}
finally { if (e_1) throw e_1.error; }
}
assert.strictEqual(results.length, 1);
assert.strictEqual(results[0].offset, 704);
assert.strictEqual(results[0].type, PropTypes.COMMENT);
assert.strictEqual(results[0].key, KeyTypes.TEXT);
assert.strictEqual(results[0].value, 'Comment v10');
const blocksLoaded = blockStore.countReads();
assert.strictEqual(blocksLoaded, 10);
});
});
//# sourceMappingURL=indexing.test.js.map