Skip to content

Commit fe6190b

Browse files
committed
JS driver v1.4.0-beta01: Checking in transpiled files for bower
1 parent 68cbf8b commit fe6190b

15 files changed

+24652
-3632
lines changed

lib/browser/neo4j-web.js

Lines changed: 1765 additions & 1134 deletions
Large diffs are not rendered by default.

lib/browser/neo4j-web.min.js

Lines changed: 17 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/browser/neo4j-web.test.js

Lines changed: 22232 additions & 2174 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/v1/driver.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,24 @@ var _error = require('./error');
4747

4848
var _connectionProviders = require('./internal/connection-providers');
4949

50+
var _bookmark = require('./internal/bookmark');
51+
52+
var _bookmark2 = _interopRequireDefault(_bookmark);
53+
5054
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
5155

56+
var READ = 'READ',
57+
WRITE = 'WRITE';
58+
/**
59+
* A driver maintains one or more {@link Session}s with a remote
60+
* Neo4j instance. Through the {@link Session}s you can send statements
61+
* and retrieve results from the database.
62+
*
63+
* Drivers are reasonably expensive to create - you should strive to keep one
64+
* driver instance around per Neo4j Instance you connect to.
65+
*
66+
* @access public
67+
*/
5268
/**
5369
* Copyright (c) 2002-2017 "Neo Technology,","
5470
* Network Engine for Objects in Lund AB [http://neotechnology.com]
@@ -68,19 +84,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
6884
* limitations under the License.
6985
*/
7086

71-
var READ = 'READ',
72-
WRITE = 'WRITE';
73-
/**
74-
* A driver maintains one or more {@link Session}s with a remote
75-
* Neo4j instance. Through the {@link Session}s you can send statements
76-
* and retrieve results from the database.
77-
*
78-
* Drivers are reasonably expensive to create - you should strive to keep one
79-
* driver instance around per Neo4j Instance you connect to.
80-
*
81-
* @access public
82-
*/
83-
8487
var Driver = function () {
8588
/**
8689
* You should not be calling this directly, instead use {@link driver}.
@@ -107,7 +110,7 @@ var Driver = function () {
107110
/**
108111
* Reference to the connection provider. Initialized lazily by {@link _getOrCreateConnectionProvider}.
109112
* @type {ConnectionProvider}
110-
* @private
113+
* @protected
111114
*/
112115
this._connectionProvider = null;
113116
}
@@ -167,16 +170,17 @@ var Driver = function () {
167170
* made available for others to use.
168171
*
169172
* @param {string} [mode=WRITE] the access mode of this session, allowed values are {@link READ} and {@link WRITE}.
170-
* @param {string} [bookmark=null] the initial reference to some previous transaction. Value is optional and
171-
* absence indicates that that the bookmark does not exist or is unknown.
173+
* @param {string|string[]} [bookmarkOrBookmarks=null] the initial reference or references to some previous
174+
* transactions. Value is optional and absence indicates that that the bookmarks do not exist or are unknown.
172175
* @return {Session} new session.
173176
*/
174177

175178
}, {
176179
key: 'session',
177-
value: function session(mode, bookmark) {
180+
value: function session(mode, bookmarkOrBookmarks) {
178181
var sessionMode = Driver._validateSessionMode(mode);
179182
var connectionProvider = this._getOrCreateConnectionProvider();
183+
var bookmark = new _bookmark2.default(bookmarkOrBookmarks);
180184
return this._createSession(sessionMode, connectionProvider, bookmark, this._config);
181185
}
182186
}, {

lib/v1/graph-types.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,11 @@ var _createClass2 = require("babel-runtime/helpers/createClass");
2121

2222
var _createClass3 = _interopRequireDefault(_createClass2);
2323

24-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
24+
var _integer = require("./integer");
2525

26-
/**
27-
* Copyright (c) 2002-2017 "Neo Technology,","
28-
* Network Engine for Objects in Lund AB [http://neotechnology.com]
29-
*
30-
* This file is part of Neo4j.
31-
*
32-
* Licensed under the Apache License, Version 2.0 (the "License");
33-
* you may not use this file except in compliance with the License.
34-
* You may obtain a copy of the License at
35-
*
36-
* http://www.apache.org/licenses/LICENSE-2.0
37-
*
38-
* Unless required by applicable law or agreed to in writing, software
39-
* distributed under the License is distributed on an "AS IS" BASIS,
40-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
41-
* See the License for the specific language governing permissions and
42-
* limitations under the License.
43-
*/
26+
var _integer2 = _interopRequireDefault(_integer);
27+
28+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
4429

4530
/**
4631
* Class for Node Type.
@@ -86,7 +71,24 @@ var Node = function () {
8671
/**
8772
* Class for Relationship Type.
8873
*/
89-
74+
/**
75+
* Copyright (c) 2002-2017 "Neo Technology,","
76+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
77+
*
78+
* This file is part of Neo4j.
79+
*
80+
* Licensed under the Apache License, Version 2.0 (the "License");
81+
* you may not use this file except in compliance with the License.
82+
* You may obtain a copy of the License at
83+
*
84+
* http://www.apache.org/licenses/LICENSE-2.0
85+
*
86+
* Unless required by applicable law or agreed to in writing, software
87+
* distributed under the License is distributed on an "AS IS" BASIS,
88+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
89+
* See the License for the specific language governing permissions and
90+
* limitations under the License.
91+
*/
9092

9193
var Relationship = function () {
9294
/**

lib/v1/internal/bookmark.js

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
7+
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
8+
9+
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
10+
11+
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
12+
13+
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
14+
15+
var _createClass2 = require('babel-runtime/helpers/createClass');
16+
17+
var _createClass3 = _interopRequireDefault(_createClass2);
18+
19+
var _util = require('./util');
20+
21+
var util = _interopRequireWildcard(_util);
22+
23+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
24+
25+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
26+
27+
var BOOKMARK_KEY = 'bookmark'; /**
28+
* Copyright (c) 2002-2017 "Neo Technology,","
29+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
30+
*
31+
* This file is part of Neo4j.
32+
*
33+
* Licensed under the Apache License, Version 2.0 (the "License");
34+
* you may not use this file except in compliance with the License.
35+
* You may obtain a copy of the License at
36+
*
37+
* http://www.apache.org/licenses/LICENSE-2.0
38+
*
39+
* Unless required by applicable law or agreed to in writing, software
40+
* distributed under the License is distributed on an "AS IS" BASIS,
41+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42+
* See the License for the specific language governing permissions and
43+
* limitations under the License.
44+
*/
45+
46+
var BOOKMARKS_KEY = 'bookmarks';
47+
var BOOKMARK_PREFIX = 'neo4j:bookmark:v1:tx';
48+
49+
var UNKNOWN_BOOKMARK_VALUE = -1;
50+
51+
var Bookmark = function () {
52+
53+
/**
54+
* @constructor
55+
* @param {string|string[]} values single bookmark as string or multiple bookmarks as a string array.
56+
*/
57+
function Bookmark(values) {
58+
(0, _classCallCheck3.default)(this, Bookmark);
59+
60+
this._values = asStringArray(values);
61+
this._maxValue = maxBookmark(this._values);
62+
}
63+
64+
/**
65+
* Check if the given bookmark is meaningful and can be send to the database.
66+
* @return {boolean} returns <code>true</code> bookmark has a value, <code>false</code> otherwise.
67+
*/
68+
69+
70+
(0, _createClass3.default)(Bookmark, [{
71+
key: 'isEmpty',
72+
value: function isEmpty() {
73+
return this._maxValue === null;
74+
}
75+
76+
/**
77+
* Get maximum value of this bookmark as string.
78+
* @return {string|null} the maximum value or <code>null</code> if it is not defined.
79+
*/
80+
81+
}, {
82+
key: 'maxBookmarkAsString',
83+
value: function maxBookmarkAsString() {
84+
return this._maxValue;
85+
}
86+
87+
/**
88+
* Get this bookmark as an object for begin transaction call.
89+
* @return {object} the value of this bookmark as object.
90+
*/
91+
92+
}, {
93+
key: 'asBeginTransactionParameters',
94+
value: function asBeginTransactionParameters() {
95+
var _ref;
96+
97+
if (this.isEmpty()) {
98+
return {};
99+
}
100+
101+
// Driver sends {bookmark: "max", bookmarks: ["one", "two", "max"]} instead of simple
102+
// {bookmarks: ["one", "two", "max"]} for backwards compatibility reasons. Old servers can only accept single
103+
// bookmark that is why driver has to parse and compare given list of bookmarks. This functionality will
104+
// eventually be removed.
105+
return _ref = {}, (0, _defineProperty3.default)(_ref, BOOKMARK_KEY, this._maxValue), (0, _defineProperty3.default)(_ref, BOOKMARKS_KEY, this._values), _ref;
106+
}
107+
}]);
108+
return Bookmark;
109+
}();
110+
111+
/**
112+
* Converts given value to an array.
113+
* @param {string|string[]} [value=undefined] argument to convert.
114+
* @return {string[]} value converted to an array.
115+
*/
116+
117+
118+
exports.default = Bookmark;
119+
function asStringArray(value) {
120+
if (!value) {
121+
return [];
122+
}
123+
124+
if (util.isString(value)) {
125+
return [value];
126+
}
127+
128+
if (Array.isArray(value)) {
129+
var result = [];
130+
for (var i = 0; i < value.length; i++) {
131+
var element = value[i];
132+
if (!util.isString(element)) {
133+
throw new TypeError('Bookmark should be a string, given: \'' + element + '\'');
134+
}
135+
result.push(element);
136+
}
137+
return result;
138+
}
139+
140+
throw new TypeError('Bookmark should either be a string or a string array, given: \'' + value + '\'');
141+
}
142+
143+
/**
144+
* Find latest bookmark in the given array of bookmarks.
145+
* @param {string[]} bookmarks array of bookmarks.
146+
* @return {string|null} latest bookmark value.
147+
*/
148+
function maxBookmark(bookmarks) {
149+
if (!bookmarks || bookmarks.length === 0) {
150+
return null;
151+
}
152+
153+
var maxBookmark = bookmarks[0];
154+
var maxValue = bookmarkValue(maxBookmark);
155+
156+
for (var i = 1; i < bookmarks.length; i++) {
157+
var bookmark = bookmarks[i];
158+
var value = bookmarkValue(bookmark);
159+
160+
if (value > maxValue) {
161+
maxBookmark = bookmark;
162+
maxValue = value;
163+
}
164+
}
165+
166+
return maxBookmark;
167+
}
168+
169+
/**
170+
* Calculate numeric value for the given bookmark.
171+
* @param {string} bookmark argument to get numeric value for.
172+
* @return {number} value of the bookmark.
173+
*/
174+
function bookmarkValue(bookmark) {
175+
if (bookmark && bookmark.indexOf(BOOKMARK_PREFIX) === 0) {
176+
var result = parseInt(bookmark.substring(BOOKMARK_PREFIX.length));
177+
return result ? result : UNKNOWN_BOOKMARK_VALUE;
178+
}
179+
return UNKNOWN_BOOKMARK_VALUE;
180+
}

lib/v1/internal/ch-dummy.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ var DummyChannel = function () {
7878
value: function toBuffer() {
7979
return new _buf.CombinedBuffer(this.written);
8080
}
81+
}, {
82+
key: "close",
83+
value: function close(cb) {
84+
this.written = [];
85+
if (cb) {
86+
return cb();
87+
}
88+
}
8189
}]);
8290
return DummyChannel;
8391
}();

lib/v1/internal/connection-holder.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,17 @@ var ConnectionHolder = function () {
6969

7070
/**
7171
* Get the current connection promise.
72+
* @param {StreamObserver} streamObserver an observer for this connection.
7273
* @return {Promise<Connection>} promise resolved with the current connection.
7374
*/
7475

7576
}, {
7677
key: 'getConnection',
77-
value: function getConnection() {
78-
return this._connectionPromise;
78+
value: function getConnection(streamObserver) {
79+
return this._connectionPromise.then(function (connection) {
80+
streamObserver.resolveConnection(connection);
81+
return connection.initializationCompleted();
82+
});
7983
}
8084

8185
/**
@@ -178,7 +182,7 @@ var EmptyConnectionHolder = function (_ConnectionHolder) {
178182
}
179183
}, {
180184
key: 'getConnection',
181-
value: function getConnection() {
185+
value: function getConnection(streamObserver) {
182186
return _promise2.default.reject((0, _error.newError)('This connection holder does not serve connections'));
183187
}
184188
}, {

0 commit comments

Comments
 (0)