You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by jo...@apache.org on 2018/11/08 10:22:21 UTC
[tinkerpop] branch TINKERPOP-2078 updated: TINKERPOP-2078 Introduce
AnonymousTraversalSource in JS
This is an automated email from the ASF dual-hosted git repository.
jorgebg pushed a commit to branch TINKERPOP-2078
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
The following commit(s) were added to refs/heads/TINKERPOP-2078 by this push:
new 40c7650 TINKERPOP-2078 Introduce AnonymousTraversalSource in JS
40c7650 is described below
commit 40c765081d2572ffa95b39240f9d1585af373980
Author: Jorge Bay Gondra <jo...@gmail.com>
AuthorDate: Thu Nov 8 11:22:14 2018 +0100
TINKERPOP-2078 Introduce AnonymousTraversalSource in JS
---
.../main/javascript/gremlin-javascript/index.js | 4 +-
.../lib/process/anonymous-traversal.js | 64 ++++++++++++++++++++++
.../lib/process/graph-traversal.js | 1 +
.../gremlin-javascript/lib/structure/graph.js | 11 +---
.../test/cucumber/feature-steps.js | 2 +-
.../gremlin-javascript/test/cucumber/world.js | 3 +-
.../test/integration/traversal-test.js | 2 +-
.../gremlin-javascript/test/unit/exports-test.js | 2 +
8 files changed, 74 insertions(+), 15 deletions(-)
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/index.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/index.js
index 3849933..9833cc9 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/index.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/index.js
@@ -36,6 +36,7 @@ const Client = require('./lib/driver/client');
const ResultSet = require('./lib/driver/result-set');
const Authenticator = require('./lib/driver/auth/authenticator');
const PlainTextSaslAuthenticator = require('./lib/driver/auth/plain-text-sasl-authenticator');
+const AnonymousTraversalSource = require('./lib/process/anonymous-traversal');
module.exports = {
driver: {
@@ -73,7 +74,8 @@ module.exports = {
GraphTraversalSource: gt.GraphTraversalSource,
statics: gt.statics,
Translator,
- traversal: gt.traversal
+ traversal: AnonymousTraversalSource.traversal,
+ AnonymousTraversalSource
},
structure: {
io: {
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/anonymous-traversal.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/anonymous-traversal.js
new file mode 100644
index 0000000..ba5532f
--- /dev/null
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/anonymous-traversal.js
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+'use strict';
+
+const graphTraversalModule = require('./graph-traversal');
+const TraversalStrategies = require('./traversal-strategy').TraversalStrategies;
+const GraphTraversalSource = graphTraversalModule.GraphTraversalSource;
+const Graph = require('../structure/graph').Graph;
+
+/**
+ * Provides a unified way to construct a <code>TraversalSource</code> from the perspective of the traversal. In this
+ * syntax the user is creating the source and binding it to a reference which is either an existing <code>Graph</code>
+ * instance or a <code>RemoteConnection</code>.
+ */
+class AnonymousTraversalSource {
+
+ /**
+ * Constructs an {@code AnonymousTraversalSource} which will then be configured to spawn a
+ * {@link GraphTraversalSource}.
+ * @returns {AnonymousTraversalSource}.
+ */
+ static traversal() {
+ return new AnonymousTraversalSource();
+ }
+
+ /**
+ * Creates the specified {@link GraphTraversalSource{ binding a {@link RemoteConnection} as its reference such that
+ * traversals spawned from it will execute over that reference.
+ * @param {GraphTraversalSource} remoteConnection
+ * @return {GraphTraversalSource}
+ */
+ withRemote(remoteConnection) {
+ return this.withGraph(new Graph()).withRemote(remoteConnection);
+ }
+
+ /**
+ * Creates the specified {@link GraphTraversalSource} binding a {@link Graph} as its reference such that traversals
+ * spawned from it will execute over that reference.
+ * @param {Graph} graph
+ * @return {GraphTraversalSource}
+ */
+ withGraph(graph) {
+ return new GraphTraversalSource(graph, new TraversalStrategies());
+ }
+}
+
+module.exports = AnonymousTraversalSource;
\ No newline at end of file
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/graph-traversal.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/graph-traversal.js
index edeb2cb..56b9e69 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/graph-traversal.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/graph-traversal.js
@@ -47,6 +47,7 @@ class GraphTraversalSource {
/**
* @param remoteConnection
* @returns {GraphTraversalSource}
+ * @deprecated As of release 3.3.5, replaced by {@link AnonymousTraversalSource#withRemote(Configuration)}.
*/
withRemote(remoteConnection) {
const traversalStrategy = new TraversalStrategies(this.traversalStrategies);
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/graph.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/graph.js
index 0c45b78..cd74e25 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/graph.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/structure/graph.js
@@ -159,20 +159,11 @@ function areEqual(obj1, obj2) {
return false;
}
-/**
-* Returns an anonymous traversal source.
-* @returns {GraphTraversalSource}
-*/
-function traversal() {
- return new gt.GraphTraversalSource(new Graph(), new TraversalStrategies());
-}
-
module.exports = {
Edge: Edge,
Graph: Graph,
Path: Path,
Property: Property,
Vertex: Vertex,
- VertexProperty: VertexProperty,
- traversal
+ VertexProperty: VertexProperty
};
\ No newline at end of file
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/feature-steps.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/feature-steps.js
index f02a5cb..6374d8b 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/feature-steps.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/feature-steps.js
@@ -30,9 +30,9 @@ const graphModule = require('../../lib/structure/graph');
const graphTraversalModule = require('../../lib/process/graph-traversal');
const traversalModule = require('../../lib/process/traversal');
const utils = require('../../lib/utils');
+const traversal = require('../../lib/process/anonymous-traversal').traversal;
const Path = graphModule.Path;
const __ = graphTraversalModule.statics;
-const traversal = graphModule.traversal;
const t = traversalModule.t;
// Determines whether the feature maps (m[]), are deserialized as objects (true) or maps (false).
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/world.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/world.js
index abed7b9..bde8a53 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/world.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/cucumber/world.js
@@ -24,10 +24,9 @@
const defineSupportCode = require('cucumber').defineSupportCode;
const helper = require('../helper');
-const graphModule = require('../../lib/structure/graph');
+const traversal = require('../../lib/process/anonymous-traversal').traversal;
const graphTraversalModule = require('../../lib/process/graph-traversal');
const __ = graphTraversalModule.statics;
-const traversal = graphModule.traversal;
defineSupportCode(function (methods) {
const cache = {};
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/traversal-test.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/traversal-test.js
index 1ee0b7e..d454552 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/traversal-test.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/traversal-test.js
@@ -25,7 +25,7 @@
const assert = require('assert');
const graphModule = require('../../lib/structure/graph');
const Vertex = graphModule.Vertex;
-const traversal = require('../../lib/structure/graph').traversal;
+const traversal = require('../../lib/process/anonymous-traversal').traversal;
const utils = require('../../lib/utils');
const helper = require('../helper');
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/exports-test.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/exports-test.js
index b12bfed..be46e93 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/exports-test.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/unit/exports-test.js
@@ -51,6 +51,8 @@ describe('API', function () {
assert.strictEqual(typeof glvModule.process.scope, 'object');
assert.strictEqual(typeof glvModule.process.t, 'object');
assert.ok(glvModule.process.statics);
+ validateConstructor(glvModule.process, 'AnonymousTraversalSource');
+ assert.strictEqual(typeof glvModule.process.traversal, 'function');
});
it('should expose fields under structure', function () {
assert.ok(glvModule.structure);