@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
195 lines • 7.85 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 { linkCodecFactory, valueCodecFactory, } from '../codecs';
import { graphStore } from '../graph-store';
import { compute_chunks } from '@dstanesc/wasm-chunking-fastcdc-node';
import { chunkerFactory } from '../chunking';
import { Graph } from '../graph';
import { memoryBlockStoreFactory } from '../block-store';
import { protoGremlinFactory } from '../api/proto-gremlin';
import * as assert from 'assert';
import { navigateVertices, PathElemType, RequestBuilder } from '../navigate';
import { Status } from '../types';
import { versionStoreFactory } from '../version-store';
describe('Minimal, schema-less creation and navigation deterministic root', function () {
test('internal api creation', async () => {
const { chunk } = chunkerFactory(1024, compute_chunks);
const linkCodec = linkCodecFactory();
const valueCodec = valueCodecFactory();
const blockStore = memoryBlockStoreFactory();
const story = await versionStoreFactory({
chunk,
linkCodec,
valueCodec,
blockStore,
});
const store = graphStore({ chunk, linkCodec, valueCodec, blockStore });
const graph = new Graph(story, store);
const tx = graph.tx();
await tx.start();
const v1 = tx.addVertex();
const v2 = tx.addVertex();
const v3 = tx.addVertex();
await tx.addEdge(v1, v2);
await tx.addEdge(v1, v3);
await tx.addVertexProp(v2, 1, { hello: 'v2' });
await tx.addVertexProp(v2, 1, { hello: 'v3' });
const { root } = await tx.commit({});
assert.equal('bafkreib5ma2hntxxmizkpnqjum6b2glrj5p3grfbzotvfq7xrvuraxzria', root.toString());
});
test('proto-gremlin api creation', async () => {
const { chunk } = chunkerFactory(1024, compute_chunks);
const linkCodec = linkCodecFactory();
const valueCodec = valueCodecFactory();
const blockStore = memoryBlockStoreFactory();
const versionStore = await versionStoreFactory({
chunk,
linkCodec,
valueCodec,
blockStore,
});
const g = protoGremlinFactory({
chunk,
linkCodec,
valueCodec,
blockStore,
versionStore,
}).g();
const tx = await g.tx();
const v1 = await tx.addV().next();
const v2 = await tx
.addV()
.property(1, { hello: 'v2' })
.property(1, { hello: 'v3' })
.next();
const v3 = await tx.addV().next();
const e1 = await tx.addE().from(v1).to(v2).next();
const e2 = await tx.addE().from(v1).to(v3).next();
const { root } = await tx.commit({});
assert.equal('bafkreib5ma2hntxxmizkpnqjum6b2glrj5p3grfbzotvfq7xrvuraxzria', root.toString());
});
test('internal api navigate', async () => {
var _a, e_1, _b, _c;
const { chunk } = chunkerFactory(1024, compute_chunks);
const linkCodec = linkCodecFactory();
const valueCodec = valueCodecFactory();
const blockStore = memoryBlockStoreFactory();
const story = await versionStoreFactory({
chunk,
linkCodec,
valueCodec,
blockStore,
});
const store = graphStore({ chunk, linkCodec, valueCodec, blockStore });
const graph = new Graph(story, store);
const tx = graph.tx();
await tx.start();
const v1 = tx.addVertex();
const v2 = tx.addVertex();
const v3 = tx.addVertex();
const e1 = await tx.addEdge(v1, v2);
const e2 = await tx.addEdge(v1, v3);
const p1 = await tx.addVertexProp(v2, 1, { hello: 'v2' });
const p2 = await tx.addVertexProp(v2, 1, { hello: 'v3' });
await tx.commit({});
const path = new RequestBuilder()
.add(PathElemType.VERTEX)
.add(PathElemType.EDGE)
.add(PathElemType.VERTEX)
.maxResults(10)
.get();
const vr = [];
try {
for (var _d = true, _e = __asyncValues(navigateVertices(graph, [v1.offset], path)), _f; _f = await _e.next(), _a = _f.done, !_a;) {
_c = _f.value;
_d = false;
try {
const result = _c;
vr.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.equal(vr.length, 2);
assert.equal(vr[0].offset, 25);
assert.equal(vr[1].offset, 50);
assert.equal(vr[0].status, Status.CREATED);
assert.equal(vr[1].status, Status.CREATED);
assert.equal(p1.status, Status.CREATED);
assert.equal(p2.status, Status.CREATED);
assert.equal(e1.status, Status.CREATED);
assert.equal(e2.status, Status.CREATED);
});
test('proto-gremlin api navigate', async () => {
var _a, e_2, _b, _c;
const { chunk } = chunkerFactory(1024, compute_chunks);
const linkCodec = linkCodecFactory();
const valueCodec = valueCodecFactory();
const blockStore = memoryBlockStoreFactory();
const versionStore = await versionStoreFactory({
chunk,
linkCodec,
valueCodec,
blockStore,
});
const g = protoGremlinFactory({
chunk,
linkCodec,
valueCodec,
blockStore,
versionStore,
}).g();
const tx = await g.tx();
const v1 = await tx.addV().next();
const v2 = await tx
.addV()
.property(1, { hello: 'v2' })
.property(1, { hello: 'v3' })
.next();
const v3 = await tx.addV().next();
const e1 = await tx.addE().from(v1).to(v2).next();
const e2 = await tx.addE().from(v1).to(v3).next();
await tx.commit({});
const vr = [];
try {
for (var _d = true, _e = __asyncValues(g.V([v1.offset]).out().exec()), _f; _f = await _e.next(), _a = _f.done, !_a;) {
_c = _f.value;
_d = false;
try {
const result = _c;
vr.push(result);
}
finally {
_d = true;
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
}
finally { if (e_2) throw e_2.error; }
}
assert.equal(vr.length, 2);
assert.equal(vr[0].offset, 25);
assert.equal(vr[1].offset, 50);
assert.equal(vr[0].status, Status.CREATED);
assert.equal(vr[1].status, Status.CREATED);
});
});
//# sourceMappingURL=schema-less.test.js.map