@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
258 lines • 10.4 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 { eq } from '../ops';
import { versionStoreFactory } from '../version-store';
describe('Filter data', function () {
test('by property, internal api', 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["COMMENT"] = 1] = "COMMENT";
PropTypes[PropTypes["WEIGHT"] = 2] = "WEIGHT";
})(PropTypes || (PropTypes = {}));
let KeyTypes;
(function (KeyTypes) {
KeyTypes[KeyTypes["TEXT"] = 3] = "TEXT";
KeyTypes[KeyTypes["VALUE"] = 333] = "VALUE";
})(KeyTypes || (KeyTypes = {}));
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(ObjectTypes.TWEET);
const v2 = tx.addVertex(ObjectTypes.TWEET);
const v3 = 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 p1 = await tx.addEdgeProp(e1, KeyTypes.VALUE, 55, PropTypes.WEIGHT);
const p2 = await tx.addEdgeProp(e2, KeyTypes.VALUE, 33, PropTypes.WEIGHT);
await tx.addVertexProp(v2, KeyTypes.TEXT, 'hello world from v2', PropTypes.COMMENT);
await tx.addVertexProp(v3, KeyTypes.TEXT, 'hello world from v3', PropTypes.COMMENT);
const { root } = await tx.commit({});
const request = new RequestBuilder()
.add(PathElemType.VERTEX)
.add(PathElemType.EDGE)
.add(PathElemType.VERTEX)
.propPred(KeyTypes.TEXT, eq('hello world from v3'))
.maxResults(10)
.get();
const vr = [];
try {
for (var _d = true, _e = __asyncValues(navigateVertices(graph, [v1.offset], request)), _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, 1);
assert.equal(vr[0].offset, 50);
});
test('by property, proto-gremlin api, json object property', async () => {
var _a, e_2, _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["COMMENT"] = 1] = "COMMENT";
PropTypes[PropTypes["WEIGHT"] = 2] = "WEIGHT";
})(PropTypes || (PropTypes = {}));
let KeyTypes;
(function (KeyTypes) {
KeyTypes[KeyTypes["TEXT"] = 3] = "TEXT";
KeyTypes[KeyTypes["VALUE"] = 333] = "VALUE";
})(KeyTypes || (KeyTypes = {}));
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(ObjectTypes.TWEET).next();
const v2 = await tx
.addV(ObjectTypes.TWEET)
.property(KeyTypes.VALUE, { hello: 'v2' }, PropTypes.COMMENT)
.next();
const v3 = await tx
.addV(ObjectTypes.TWEET)
.property(KeyTypes.VALUE, { hello: 'v3' }, PropTypes.COMMENT)
.next();
const e1 = await tx.addE(RlshpTypes.COMMENT_TO).from(v1).to(v2).next();
const e2 = await tx.addE(RlshpTypes.COMMENT_TO).from(v1).to(v3).next();
await tx.commit({});
const vr = [];
try {
for (var _d = true, _e = __asyncValues(g
.V([v1.offset])
.out()
.has(ObjectTypes.TWEET, {
keyType: KeyTypes.VALUE,
operation: eq('v3', (v) => v.hello),
})
.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, 1);
assert.equal(vr[0].offset, 50);
});
test('by property, proto-gremlin api, text property', async () => {
var _a, e_3, _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["COMMENT"] = 1] = "COMMENT";
PropTypes[PropTypes["WEIGHT"] = 2] = "WEIGHT";
})(PropTypes || (PropTypes = {}));
let KeyTypes;
(function (KeyTypes) {
KeyTypes[KeyTypes["TEXT"] = 3] = "TEXT";
KeyTypes[KeyTypes["VALUE"] = 333] = "VALUE";
})(KeyTypes || (KeyTypes = {}));
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(ObjectTypes.TWEET).next();
const v2 = await tx
.addV(ObjectTypes.TWEET)
.property(KeyTypes.VALUE, 'hello world from v2', PropTypes.COMMENT)
.next();
const v3 = await tx
.addV(ObjectTypes.TWEET)
.property(KeyTypes.VALUE, 'hello world from v3', PropTypes.COMMENT)
.next();
const e1 = await tx.addE(RlshpTypes.COMMENT_TO).from(v1).to(v2).next();
const e2 = await tx.addE(RlshpTypes.COMMENT_TO).from(v1).to(v3).next();
await tx.commit({});
const vr = [];
try {
for (var _d = true, _e = __asyncValues(g
.V([v1.offset])
.out()
.has(ObjectTypes.TWEET, {
keyType: KeyTypes.VALUE,
operation: eq('hello world from v3'),
})
.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_3_1) { e_3 = { error: e_3_1 }; }
finally {
try {
if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
}
finally { if (e_3) throw e_3.error; }
}
assert.equal(vr.length, 1);
assert.equal(vr[0].offset, 50);
});
});
//# sourceMappingURL=filter.test.js.map