import { driver, process, structure } from 'gremlin'; const { RemoteConnection, RemoteStrategy, RemoteTraversal, DriverRemoteConnection, Client, ResultSet, auth: { Authenticator, PlainTextSaslAuthenticator }, } = driver; const { Bytecode, EnumValue, P, TextP, Transaction, Traversal, TraversalStrategies, TraversalSideEffects, TraversalStrategy, Traverser, GraphTraversal, GraphTraversalSource, Translator, AnonymousTraversalSource, barrier, cardinality, column, direction, graphSONVersion, gryoVersion, merge, operator, order, pick, pop, scope, t, traversal, statics, } = process; const { Graph, Element, Edge, Vertex, VertexProperty, Path, Property, Long, toLong } = structure; const { GraphSONReader, GraphSONWriter } = structure.io; import Statics = process.Statics; function constructorTests() { const remoteConnection = new RemoteConnection('test'); const remoteStrategy = new RemoteStrategy(remoteConnection); const remoteTraversal = new RemoteTraversal(); const driverRemoteConnection = new DriverRemoteConnection('test'); const client = new Client('test'); const resultSet = new ResultSet([1, 2, 3]); const authenticator = new Authenticator(); const plainTextSaslAuthenticator = new PlainTextSaslAuthenticator('gremlin', 'test'); remoteConnection.open(); remoteConnection.submit(new Bytecode()); remoteConnection.close(); remoteStrategy.apply(remoteTraversal); const eventHandler = (logline: string) => {}; driverRemoteConnection.addListener('log', eventHandler); driverRemoteConnection.open(); driverRemoteConnection.isOpen; driverRemoteConnection.isSessionBound; driverRemoteConnection.submit(new Bytecode()); driverRemoteConnection.createSession(); driverRemoteConnection.commit(); driverRemoteConnection.rollback(); driverRemoteConnection.close(); driverRemoteConnection.removeListener('log', eventHandler); client.addListener('log', eventHandler); client.open(); client.isOpen; client.submit(new Bytecode()); client.stream(new Bytecode()); client.close(); client.removeListener('log', eventHandler); resultSet.toArray(); resultSet.first(); authenticator.evaluateChallenge('test'); plainTextSaslAuthenticator.evaluateChallenge('test'); } function processTests() { const bytecode = new Bytecode(); const enumValue = new EnumValue('Int', 'Test'); const p = new P(operator.addAll, 1); const textP = new TextP('operator', 'test'); const traversalStrategies = new TraversalStrategies(); const traversal = new Traversal(null, traversalStrategies, bytecode); const traversalSideEffects = new TraversalSideEffects(); const traversalStrategy = new TraversalStrategy(); const traverser = new Traverser({}); const graphTraversal = new GraphTraversal(null, traversalStrategies, bytecode); const graphTraversalSource = new GraphTraversalSource(null, traversalStrategies, bytecode); const transaction = new Transaction(graphTraversalSource); const translator = new Translator(graphTraversalSource); const anonymousTraversalSource = new AnonymousTraversalSource(); bytecode.addSource('test'); bytecode.addStep('test'); bytecode.toString(); enumValue.toString(); p.and(); p.or(); p.toString(); P.between(); P.eq(); P.gt(); P.gte(); P.inside(); P.lt(); P.lte(); P.neq(); P.not(); P.outside(); P.test(); P.within(); P.without(); textP.and(); textP.or(); textP.toString(); TextP.containing(); TextP.endingWith(); TextP.notContaining(); TextP.notEndingWith(); TextP.notStartingWith(); TextP.startingWith(); TextP.regex(); TextP.notRegex(); traversal.getBytecode(); traversal.hasNext(); traversal.iterate(); traversal.next(); traversal.toList(); traversal.toString(); traversalStrategies.addStrategy(traversalStrategy); traversalStrategies.removeStrategy(traversalStrategy); traversalStrategies.applyStrategies(traversal); traversalStrategy.apply(traversal); graphTraversal.V(); graphTraversal.addE(); graphTraversal.mergeE(); graphTraversal.addV(); graphTraversal.mergeV(); graphTraversal.inE(); graphTraversal.outE(); graphTraversal.drop(); graphTraversalSource.E(); graphTraversalSource.V(); graphTraversalSource.addE(); graphTraversalSource.addV(); graphTraversalSource.mergeE(); graphTraversalSource.mergeV(); graphTraversalSource.tx(); translator.getTraversalSource(); translator.of(graphTraversalSource); translator.translate(bytecode); translator.convert({}); transaction.begin(); transaction.close(); transaction.commit(); transaction.rollback(); transaction.isOpen; anonymousTraversalSource.withGraph(new Graph()); anonymousTraversalSource.withRemote(new RemoteConnection('test')); } function structureTests() { const element = new Element(1, 'test'); const graphSonReader = new GraphSONReader(); const graphSonWriter = new GraphSONWriter(); const vertexProperty = new VertexProperty(1, 'test', 'test'); const vertex = new Vertex(1, 'test', [vertexProperty]); const edge = new Edge(1, vertex, 'test', vertex); const graph = new Graph(); const path = new Path(['test'], [{}]); const property = new Property('test', 1); const long = new Long('11111111111'); element.equals(new Element(2, 'test')); graphSonReader.read({}); graphSonWriter.adaptObject({}); graphSonWriter.write({}); edge.equals(new Edge(2, vertex, 'test', vertex)); edge.toString(); graph.toString(); graph.traversal(); path.equals(new Path(['test'], [])); path.toString(); property.equals(new Property('test', 1)); property.toString(); vertex.equals(new Vertex(2, 'test')); vertex.toString(); vertexProperty.equals(new VertexProperty(2, 'test', 1)); vertexProperty.toString(); } function functionTests() { const traversal = AnonymousTraversalSource.traversal(); const long = toLong('11111111111'); } function predefinedEnumTests() { barrier.normSack.toString() === 'normSack'; cardinality.list.toString() === 'list'; cardinality.set.toString() === 'set'; cardinality.single.toString() === 'single'; column.keys.toString() === 'keys'; column.values.toString() === 'values'; direction.both.toString() === 'BOTH'; direction.in.toString() === 'IN'; direction.out.toString() === 'OUT'; graphSONVersion['v1_0'].toString() === 'V1_0'; graphSONVersion['v2_0'].toString() === 'V2_0'; graphSONVersion['v3_0'].toString() === 'V3_0'; gryoVersion['v1_0'].toString() === 'V1_0'; gryoVersion['v3_0'].toString() === 'V3_0'; merge.inV.toString() === 'inV'; merge.outV.toString() === 'outV'; merge.onCreate.toString() === 'onCreate'; merge.onMatch.toString() === 'onMatch'; operator.addAll.toString() === 'addAll'; operator.and.toString() === 'and'; operator.assign.toString() === 'assign'; operator.div.toString() === 'div'; operator.max.toString() === 'max'; operator.min.toString() === 'min'; operator.minus.toString() === 'minus'; operator.mult.toString() === 'mult'; operator.or.toString() === 'or'; operator.sum.toString() === 'sum'; operator.sumLong.toString() === 'sumLong'; order.asc.toString() === 'asc'; order.desc.toString() === 'desc'; order.shuffle.toString() === 'shuffle'; pick.any.toString() === 'any'; pick.none.toString() === 'none'; pop.all.toString() === 'all'; pop.first.toString() === 'first'; pop.last.toString() === 'last'; pop.mixed.toString() === 'mixed'; scope.global.toString() === 'global'; scope.local.toString() === 'local'; t.id.toString() === 'id'; t.key.toString() === 'key'; t.label.toString() === 'label'; t.value.toString() === 'value'; } function dslTests() { // DSL definition interface TestDSLStatics extends Statics { aged: (age: number) => TestDSLTraversal; hasNotLabel: (...args: string[]) => TestDSLTraversal; } let __: TestDSLStatics; class TestDSLTraversal extends GraphTraversal { private static _statics: TestDSLStatics; static get statics(): TestDSLStatics { if (!TestDSLTraversal._statics) { // Should construct a proper statics object here that fits the return type // ie. merge the newly defined DSL steps with the base Tinkerpop statics TestDSLTraversal._statics = statics; } return TestDSLTraversal._statics; } aged(age: number): TestDSLTraversal { return this.has('person', 'age', age); } hasNotLabel(...args: string[]): TestDSLTraversal { return this.not(__.hasLabel(...args)); } } class TestDSLTraversalSource extends GraphTraversalSource { person(name: string): TestDSLTraversal { return this.V().has('person', 'name', name); } } // DSL usage __ = TestDSLTraversal.statics; const connection = new DriverRemoteConnection('test'); const g = traversal(TestDSLTraversalSource).withRemote(connection); g.person('test').aged(33); g.person('test').where(__.hasNotLabel('test')).aged(33); g.V().where(__.hasNotLabel('test')); g.V().aged(33); g.tx().begin(); } async function asyncIteratorTest() { const t = new process.Traversal(null, null, new Bytecode()); // tslint:disable-next-line: await-promise Bug in tslint: https://github.com/palantir/tslint/issues/3997 for await (const v of t) { v; } }