diff --git a/.gitignore b/.gitignore
index 8ef40b8f3c..7227f5f440 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,8 +6,6 @@ bindings/flow/bin/
bindings/java/foundationdb-client*.jar
bindings/java/foundationdb-tests*.jar
bindings/java/fdb-java-*-sources.jar
-bindings/nodejs/build/
-bindings/nodejs/modules/
packaging/msi/FDBInstaller.msi
# Generated source, build, and packaging files
@@ -24,7 +22,6 @@ bindings/java/src*/main/com/apple/foundationdb/StreamingMode.java
bindings/java/src*/main/com/apple/foundationdb/MutationType.java
bindings/java/src*/main/com/apple/foundationdb/ConflictRangeType.java
bindings/java/src*/main/com/apple/foundationdb/FDBException.java
-bindings/nodejs/package.json
bindings/python/fdb/fdb*options.py
bindings/python/dist/
bindings/python/setup.py
@@ -52,12 +49,8 @@ bindings/go/godoc
bindings/java/.classstamp*
bindings/java/classes*/
bindings/java/javadoc*/
-bindings/nodejs/fdb_node.stamp
-bindings/nodejs/node_modules/
# Testing and logging
-bindings/nodejs/fdb_node*.log
-bindings/nodejs/npm-debug.log
packaging/msi/*.log
packaging/msi/obj
simfdb
diff --git a/Makefile b/Makefile
index a2311cc52d..55bc077bf9 100644
--- a/Makefile
+++ b/Makefile
@@ -93,7 +93,7 @@ VPATH += $(addprefix :,$(filter-out lib,$(patsubst -L%,%,$(filter -L%,$(LDFLAGS)
CS_PROJECTS := flow/actorcompiler flow/coveragetool fdbclient/vexillographer
CPP_PROJECTS := flow fdbrpc fdbclient fdbbackup fdbserver fdbcli bindings/c bindings/java fdbmonitor bindings/flow/tester bindings/flow
-OTHER_PROJECTS := bindings/python bindings/ruby bindings/nodejs bindings/go
+OTHER_PROJECTS := bindings/python bindings/ruby bindings/go
CS_MK_GENERATED := $(CS_PROJECTS:=/generated.mk)
CPP_MK_GENERATED := $(CPP_PROJECTS:=/generated.mk)
@@ -127,7 +127,7 @@ else
endif
@echo "#define FDB_VT_PACKAGE_NAME \"$(PACKAGE_NAME)\"" >> $@
-bindings: fdb_c fdb_python fdb_ruby fdb_java fdb_node fdb_flow fdb_flow_tester fdb_go fdb_go_tester
+bindings: fdb_c fdb_python fdb_ruby fdb_java fdb_flow fdb_flow_tester fdb_go fdb_go_tester
Makefiles: $(MK_GENERATED)
diff --git a/README.md b/README.md
index 68edc85987..6c1009ec42 100755
--- a/README.md
+++ b/README.md
@@ -1,3 +1,21 @@
# FoundationDB
FoundationDB is a distributed database designed to handle large volumes of structured data across clusters of commodity servers. It organizes data as an ordered key-value store and employs ACID transactions for all operations. It is especially well-suited for read/write workloads but also has excellent performance for write-intensive workloads. Users interact with the database using API language binding.
+
+# Building Locally
+
+## macOS
+
+1. Check out this repo on your Mac.
+1. Install the Xcode command-line tools.
+1. Download version 1.52 of [Boost](https://sourceforge.net/projects/boost/files/boost/1.52.0/).
+1. Set the BOOSTDIR environment variable to the location containing this boost installation.
+1. Install [Mono](http://www.mono-project.com/download/stable/).
+1. Install a [JDK](http://www.oracle.com/technetwork/java/javase/downloads/index.html). FoundationDB currently builds with Java 8.
+1. Navigate to the directory where you checked out the foundationdb repo.
+1. Run `make`.
+
+This will build the fdbserver binary and the python bindings. If you
+want to build our other bindings, you will need to install a runtime for the
+language whose binding you want to build. Each binding has an `.mk` file
+which provides specific targets for that binding.
\ No newline at end of file
diff --git a/bindings/bindingtester/known_testers.py b/bindings/bindingtester/known_testers.py
index 683d79eba9..b7aca6808a 100644
--- a/bindings/bindingtester/known_testers.py
+++ b/bindings/bindingtester/known_testers.py
@@ -58,8 +58,6 @@ _java_cmd = 'java -ea -cp %s:%s com.apple.foundationdb.test.' % (
testers = {
'python': Tester('python', 'python ' + _absolute_path('python/tests/tester.py'), 2040, 23, MAX_API_VERSION, types=ALL_TYPES),
'python3': Tester('python3', 'python3 ' + _absolute_path('python/tests/tester.py'), 2040, 23, MAX_API_VERSION, types=ALL_TYPES),
- 'node': Tester('node', _absolute_path('nodejs/tests/tester.js'), 53, 500, MAX_API_VERSION),
- 'streamline': Tester('streamline', _absolute_path('nodejs/tests/streamline_tester._js'), 53, 500, MAX_API_VERSION),
'ruby': Tester('ruby', _absolute_path('ruby/tests/tester.rb'), 64, 23, MAX_API_VERSION),
'java': Tester('java', _java_cmd + 'StackTester', 2040, 510, MAX_API_VERSION, types=ALL_TYPES),
'java_async': Tester('java', _java_cmd + 'AsyncStackTester', 2040, 510, MAX_API_VERSION, types=ALL_TYPES),
diff --git a/bindings/bindingtester/run_binding_tester.sh b/bindings/bindingtester/run_binding_tester.sh
index 42af9d593f..b8d94e12e3 100644
--- a/bindings/bindingtester/run_binding_tester.sh
+++ b/bindings/bindingtester/run_binding_tester.sh
@@ -25,7 +25,7 @@ BREAKONERROR="${BREAKONERROR:-0}"
RUNSCRIPTS="${RUNSCRIPTS:-1}"
RUNTESTS="${RUNTESTS:-1}"
RANDOMTEST="${RANDOMTEST:-0}"
-BINDINGTESTS="${BINDINGTESTS:-python python3 java java_async ruby node go flow}"
+BINDINGTESTS="${BINDINGTESTS:-python python3 java java_async ruby go flow}"
LOGLEVEL="${LOGLEVEL:-INFO}"
_BINDINGTESTS=(${BINDINGTESTS})
DISABLEDTESTS=()
diff --git a/bindings/bindingtester/run_tester_loop.sh b/bindings/bindingtester/run_tester_loop.sh
index d1eff08b43..d78915a489 100755
--- a/bindings/bindingtester/run_tester_loop.sh
+++ b/bindings/bindingtester/run_tester_loop.sh
@@ -24,7 +24,6 @@ function run_scripted() {
scripted ruby
scripted java
scripted java_async
- scripted node
scripted go
scripted flow
}
@@ -40,8 +39,6 @@ while `true`; do
run ruby
run java
run java_async
- run node
- #run streamline
run go
run flow
done
diff --git a/bindings/c/local.mk b/bindings/c/local.mk
index 7bab3d9919..44f0c31b42 100644
--- a/bindings/c/local.mk
+++ b/bindings/c/local.mk
@@ -102,5 +102,3 @@ fdb_c_tests: packages/fdb-c-tests-$(VERSION)-$(PLATFORM).tar.gz
fdb_c_tests_clean:
@rm -f packages/fdb-c-tests-$(VERSION)-$(PLATFORM).tar.gz
-
-packages: fdb_c_tests
diff --git a/bindings/java/fdb-java-style.xml b/bindings/java/fdb-java-style.xml
index 62d6232eed..b47b094118 100644
--- a/bindings/java/fdb-java-style.xml
+++ b/bindings/java/fdb-java-style.xml
@@ -30,11 +30,6 @@
-
-
-
- -PRERELEASE
-
-
-
-
-
-
-
-
- Debug
- x64
-
-
- Release
- x64
-
-
-
- {9463CB25-DCA0-9D45-C46E-0A8E68EE7FAE}
- Win32Proj
-
-
-
- v140_xp
-
-
-
- $(SystemDrive)\temp\msvcfdb\$(Platform)$(Configuration)\$(MSBuildProjectName)\
-
-
-
-
-
- del "$(SolutionDir)bin\$(Configuration)\fdb-node*.tar.gz"
-
-
-
-
-c:\python27\python -c "print open(\"package.json.in\").read().replace(\"VERSION\",\"$(Version)$(PreReleaseDecoration)\")" > package.json
-copy ..\..\LICENSE
-c:\python27\python "$(SolutionDir)build/tarball.py" -r nodejs "$(SolutionDir)bin\$(Configuration)\fdb-node-$(Version)$(PreReleaseDecoration)-windows-$(Platform).tar.gz" lib modules package.json README.md LICENSE
-del LICENSE
-
-
-
-
-
-
-
- false
-
-
- false
-
-
-
-
-
-
\ No newline at end of file
diff --git a/bindings/nodejs/fdb_node_0_10.vcxproj b/bindings/nodejs/fdb_node_0_10.vcxproj
deleted file mode 100644
index f47ce8ef11..0000000000
--- a/bindings/nodejs/fdb_node_0_10.vcxproj
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
- {E22D4EF8-E75D-4281-93F9-A9F73936DE54}
-
-
- v140_xp
-
-
- 0.10.0
- 0.10
-
-
-
\ No newline at end of file
diff --git a/bindings/nodejs/fdb_node_0_8.vcxproj b/bindings/nodejs/fdb_node_0_8.vcxproj
deleted file mode 100644
index e783b03ed1..0000000000
--- a/bindings/nodejs/fdb_node_0_8.vcxproj
+++ /dev/null
@@ -1,14 +0,0 @@
-
-
-
- {E936E200-689E-49FD-8463-32FE763F1860}
-
-
- v140_xp
-
-
- 0.8.22
- 0.8
-
-
-
\ No newline at end of file
diff --git a/bindings/nodejs/include.mk b/bindings/nodejs/include.mk
deleted file mode 100644
index da829d990a..0000000000
--- a/bindings/nodejs/include.mk
+++ /dev/null
@@ -1,99 +0,0 @@
-#
-# include.mk
-#
-# This source file is part of the FoundationDB open source project
-#
-# Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
-#
-# Licensed 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.
-#
-
-# -*- mode: makefile-gmake; -*-
-
-TARGETS += fdb_node fdb_node_npm
-CLEAN_TARGETS += fdb_node_clean fdb_node_npm_clean
-
-NODE_VERSIONS := 0.8.22 0.10.0
-
-NODE_DIST_URL ?= https://nodejs.org/dist
-NODE_REGISTRY_URL ?= https://registry.npmjs.org/
-
-ifeq ($(RELEASE),true)
- NPMVER = $(VERSION)
-else
- NPMVER = $(VERSION)-PRERELEASE
-endif
-
-packages: fdb_node_npm
-
-packages_clean: fdb_node_npm_clean
-
-fdb_node: fdb_c bindings/nodejs/fdb_node.stamp
-
-bindings/nodejs/fdb_node.stamp: bindings/nodejs/src/FdbOptions.g.cpp bindings/nodejs/src/*.cpp bindings/nodejs/src/*.h bindings/nodejs/binding.gyp lib/libfdb_c.$(DLEXT) bindings/nodejs/package.json
- @echo "Building $@"
- @rm -f $@
- @cd bindings/nodejs && \
- mkdir -p modules && \
- rm -rf modules/* && \
- for ver in $(NODE_VERSIONS); do \
- MMVER=`echo $$ver | sed -e 's,\., ,g' | awk '{print $$1 "." $$2}'` && \
- mkdir modules/$$MMVER && \
- node-gyp configure --dist-url=$(NODE_DIST_URL) --target=$$ver && \
- node-gyp -v build && \
- cp build/Release/fdblib.node modules/$${MMVER} ; \
- done
- @touch $@
-
-bindings/nodejs/src/FdbOptions.g.cpp: bin/vexillographer.exe fdbclient/vexillographer/fdb.options
- @echo "Building $@"
- @$(MONO) bin/vexillographer.exe fdbclient/vexillographer/fdb.options nodejs $@
-
-fdb_node_clean:
- @echo "Cleaning fdb_node"
- @rm -f bindings/nodejs/src/FdbOptions.g.cpp
- @rm -rf bindings/nodejs/modules
- @(cd bindings/nodejs && node-gyp clean)
- @rm -f bindings/nodejs/fdb_node.stamp
-
-bindings/nodejs/package.json: bindings/nodejs/package.json.in $(ALL_MAKEFILES) versions.target
- @m4 -DVERSION=$(NPMVER) $< > $@
- @echo "Updating Node dependencies"
- @cd bindings/nodejs && \
- npm config set registry "$(NODE_REGISTRY_URL)" && \
- npm update
-
-fdb_node_npm: fdb_node versions.target bindings/nodejs/README.md bindings/nodejs/lib/*.js bindings/nodejs/src/* bindings/nodejs/binding.gyp LICENSE
- @echo "Packaging NPM"
- @mkdir -p packages
- @rm -f packages/fdb-node-*
- @rm -rf packages/nodejs.tmp
- @mkdir -p packages/nodejs.tmp/nodejs
- @cp LICENSE packages/nodejs.tmp/nodejs/LICENSE
- @tar -C bindings -czf packages/fdb-node-$(NPMVER)-$(PLATFORM)-$(ARCH).tar.gz nodejs/lib nodejs/modules nodejs/package.json nodejs/README.md -C ../packages/nodejs.tmp nodejs/LICENSE
- @rm -rf packages/nodejs.tmp
-ifeq ($(PLATFORM),linux)
- @echo "Packaging NPM (unbuilt)"
- @rm -rf packages/nodejs.tmp
- @mkdir -p packages/nodejs.tmp/npmsrc/nodejs
- @cat bindings/nodejs/package.json | grep -v private | grep -v engineStrict | awk '/"semver"/ {print " \"bindings\": \"*\""; next} {print}' > packages/nodejs.tmp/npmsrc/nodejs/package.json
- @cp -r bindings/nodejs/lib bindings/nodejs/src bindings/nodejs/README.md LICENSE packages/nodejs.tmp/npmsrc/nodejs
- @cp bindings/nodejs/binding.gyp.npmsrc packages/nodejs.tmp/npmsrc/nodejs/binding.gyp
- @cp bindings/nodejs/fdbModule.js.npmsrc packages/nodejs.tmp/npmsrc/nodejs/lib/fdbModule.js
- @tar -C packages/nodejs.tmp/npmsrc -czf packages/fdb-node-$(NPMVER).tar.gz nodejs
- @rm -rf packages/nodejs.tmp
-endif
-
-fdb_node_npm_clean:
- @echo "Cleaning NPM"
- @rm -f packages/fdb-node-* bindings/nodejs/package.json
diff --git a/bindings/nodejs/lib/apiVersion.js b/bindings/nodejs/lib/apiVersion.js
deleted file mode 100644
index 9bcde04422..0000000000
--- a/bindings/nodejs/lib/apiVersion.js
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * apiVersion.js
- *
- * This source file is part of the FoundationDB open source project
- *
- * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
- *
- * Licensed 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";
-
-var apiVersion;
-module.exports = { value: apiVersion };
-
diff --git a/bindings/nodejs/lib/bufferConversion.js b/bindings/nodejs/lib/bufferConversion.js
deleted file mode 100644
index 97923ca82d..0000000000
--- a/bindings/nodejs/lib/bufferConversion.js
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * bufferConversion.js
- *
- * This source file is part of the FoundationDB open source project
- *
- * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
- *
- * Licensed 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";
-
-var toBuffer = function(obj) {
- if(Buffer.isBuffer(obj))
- return obj;
-
- if(obj instanceof ArrayBuffer)
- obj = new Uint8Array(obj);
-
- if(obj instanceof Uint8Array) {
- var buf = new Buffer(obj.length);
- for(var i = 0; i < obj.length; ++i)
- buf[i] = obj[i];
-
- return buf;
- }
-
- if(typeof obj === 'string')
- return new Buffer(obj, 'utf8');
-
- throw new TypeError('toBuffer function expects a string, buffer, ArrayBuffer, or Uint8Array');
-};
-
-toBuffer.fromByteLiteral = function(str) {
- if(typeof str === 'string') {
- var buf = new Buffer(str.length);
- for(var i = 0; i < str.length; ++i) {
- if(str[i] > 255)
- throw new RangeError('fromByteLiteral string argument cannot have codepoints larger than 1 byte');
- buf[i] = str.charCodeAt(i);
- }
- return buf;
- }
- else
- throw new TypeError('fromByteLiteral function expects a string');
-};
-
-toBuffer.toByteLiteral = function(buf) {
- if(Buffer.isBuffer(buf))
- return String.fromCharCode.apply(null, buf);
- else
- throw new TypeError('toByteLiteral function expects a buffer');
-};
-
-toBuffer.printable = function(buf) {
- buf = toBuffer(buf);
- var out = '';
- for(var i = 0; i < buf.length; ++i) {
- if(buf[i] >= 32 && buf[i] < 127 && buf[i] !== 92)
- out += String.fromCharCode(buf[i]);
- else if(buf[i] === 92)
- out += '\\\\';
- else {
- var str = buf[i].toString(16);
- out += '\\x';
- if(str.length == 1)
- out += '0';
- out += str;
- }
- }
-
- return out;
-};
-
-module.exports = toBuffer;
diff --git a/bindings/nodejs/lib/cluster.js b/bindings/nodejs/lib/cluster.js
deleted file mode 100644
index f00f51fa80..0000000000
--- a/bindings/nodejs/lib/cluster.js
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * cluster.js
- *
- * This source file is part of the FoundationDB open source project
- *
- * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
- *
- * Licensed 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";
-
-var future = require('./future');
-var Database = require('./database');
-
-var Cluster = function(_cluster) {
- this._cluster = _cluster;
- this.options = _cluster.options;
-
-};
-
-Cluster.prototype.openDatabase = function() {
- return new Database(this._cluster.openDatabase());
-};
-
-module.exports = Cluster;
-
diff --git a/bindings/nodejs/lib/database.js b/bindings/nodejs/lib/database.js
deleted file mode 100644
index 0ddd21f907..0000000000
--- a/bindings/nodejs/lib/database.js
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * database.js
- *
- * This source file is part of the FoundationDB open source project
- *
- * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
- *
- * Licensed 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";
-
-var Transaction = require('./transaction');
-var future = require('./future');
-var fdb = require('./fdbModule');
-var fdbUtil = require('./fdbUtil');
-
-var onError = function(tr, err, func, cb) {
- tr.onError(err, function(retryErr, retryRes) {
- if(retryErr)
- cb(retryErr, retryRes);
- else
- retryLoop(tr, func, cb);
- });
-};
-
-var retryLoop = function(tr, func, cb) {
- func(tr, function(err, res) {
- if(err) {
- onError(tr, err, func, cb);
- }
- else {
- tr.commit(function(commitErr, commitRes) {
- if(commitErr)
- onError(tr, commitErr, func, cb);
- else
- cb(commitErr, res);
- });
- }
- });
-};
-
-var atomic = function(db, op) {
- return function(key, value, cb) {
- return db.doTransaction(function(tr, innerCb) {
- fdb.atomic[op].call(tr.tr, fdbUtil.keyToBuffer(key), fdbUtil.valueToBuffer(value));
- innerCb();
- }, cb);
- };
-};
-
-var Database = function(_db) {
- this._db = _db;
- this.options = _db.options;
-
- for(var op in fdb.atomic)
- this[op] = atomic(this, op);
-};
-
-Database.prototype.createTransaction = function() {
- return new Transaction(this, this._db.createTransaction());
-};
-
-Database.prototype.doTransaction = function(func, cb) {
- var tr = this.createTransaction();
-
- return future.create(function(futureCb) {
- retryLoop(tr, func, futureCb);
- }, cb);
-};
-
-Database.prototype.get = function(key, cb) {
- return this.doTransaction(function(tr, innerCb) {
- tr.get(key, innerCb);
- }, cb);
-};
-
-Database.prototype.getKey = function(keySelector, cb) {
- return this.doTransaction(function(tr, innerCb) {
- tr.getKey(keySelector, innerCb);
- }, cb);
-};
-
-Database.prototype.getRange = function(start, end, options, cb) {
- return this.doTransaction(function(tr, innerCb) {
- tr.getRange(start, end, options).toArray(innerCb);
- }, cb);
-};
-
-Database.prototype.getRangeStartsWith = function(prefix, options, cb) {
- return this.doTransaction(function(tr, innerCb) {
- try {
- tr.getRangeStartsWith(prefix, options).toArray(innerCb);
- }
- catch(e) {
- innerCb(e);
- }
- }, cb);
-};
-
-Database.prototype.getAndWatch = function(key, cb) {
- return this.doTransaction(function(tr, innerCb) {
- tr.get(key, function(err, val) {
- if(err)
- innerCb(err);
- else
- innerCb(undefined, { value: val, watch: tr.watch(key) });
- });
- }, cb);
-};
-
-Database.prototype.setAndWatch = function(key, value, cb) {
- return this.doTransaction(function(tr, innerCb) {
- tr.set(key, value);
- var watchObj = tr.watch(key);
- innerCb(undefined, { watch: watchObj });
- }, cb);
-};
-
-Database.prototype.clearAndWatch = function(key, cb) {
- return this.doTransaction(function(tr, innerCb) {
- tr.clear(key);
- var watchObj = tr.watch(key);
- innerCb(undefined, { watch: watchObj });
- }, cb);
-};
-
-Database.prototype.set = function(key, value, cb) {
- return this.doTransaction(function(tr, innerCb) {
- tr.set(key, value);
- innerCb();
- }, cb);
-};
-
-Database.prototype.clear = function(key, cb) {
- return this.doTransaction(function(tr, innerCb) {
- tr.clear(key);
- innerCb();
- }, cb);
-};
-
-Database.prototype.clearRange = function(start, end, cb) {
- return this.doTransaction(function(tr, innerCb) {
- tr.clearRange(start, end);
- innerCb();
- }, cb);
-};
-
-Database.prototype.clearRangeStartsWith = function(prefix, cb) {
- return this.doTransaction(function(tr, innerCb) {
- try {
- tr.clearRangeStartsWith(prefix);
- innerCb();
- }
- catch(e) {
- innerCb(e);
- }
- }, cb);
-};
-
-module.exports = Database;
diff --git a/bindings/nodejs/lib/directory.js b/bindings/nodejs/lib/directory.js
deleted file mode 100644
index 81b4e76559..0000000000
--- a/bindings/nodejs/lib/directory.js
+++ /dev/null
@@ -1,850 +0,0 @@
-/*
- * directory.js
- *
- * This source file is part of the FoundationDB open source project
- *
- * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
- *
- * Licensed 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";
-
-var util = require('util');
-
-var buffer = require('./bufferConversion');
-var future = require('./future');
-var transactional = require('./retryDecorator');
-var tuple = require('./tuple');
-var Subspace = require('./subspace');
-var fdbUtil = require('./fdbUtil');
-
-/*************
- * Utilities *
- *************/
-
-function whileLoop(func, cb) {
- return future.create(function(futureCb) {
- fdbUtil.whileLoop(function(f) {
- func()(f);
- }, futureCb);
- }, cb);
-}
-
-function startsWith(str, prefix) {
- return str.length >= prefix.length && fdbUtil.buffersEqual(str.slice(0, prefix.length), prefix);
-}
-
-function valueOrDefault(value, defaultValue) {
- if(typeof value === 'undefined')
- return defaultValue;
-
- return value;
-}
-
-function pathsEqual(path1, path2) {
- if(path1.length !== path2.length)
- return false;
-
- for(var i = 0; i < path1.length; ++i)
- if(path1[i] !== path2[i])
- return false;
-
- return true;
-}
-
-function tuplifyPath(path) {
- if(!(path instanceof Array))
- path = [path];
-
- return path;
-}
-
-function checkLayer(layer, required) {
- if(layer && layer.length > 0 && !fdbUtil.buffersEqual(layer, required))
- throw new Error('The directory was created with an incompatible layer.');
-}
-
-/***************************
- * HighContentionAllocator *
- ***************************/
-
-var HighContentionAllocator = function(subspace) {
- this.counters = subspace.subspace([0]);
- this.recent = subspace.subspace([1]);
-};
-
-HighContentionAllocator.prototype.allocate = transactional(function(tr) {
- var self = this;
- var windowStart = 0;
- return whileLoop(function() {
- return tr.snapshot.getRange(self.counters.range().begin, self.counters.range().end, { limit: 1, reverse: true })
- .toArray()
- .then(function(arr) {
- if(arr.length > 0) {
- windowStart = self.counters.unpack(arr[0].key)[0];
- }
- })
- .then(function() {
- return self.chooseWindow(tr, windowStart);
- })
- .then(function(window) {
- return self.choosePrefix(tr, window);
- })
- .then(function(prefix) {
- if(prefix !== null) {
- prefix = tuple.pack([prefix]); // exit the loop
- return prefix;
- }
- });
- })
-});
-
-HighContentionAllocator.prototype.chooseWindow = function(tr, windowStart) {
- var self = this;
-
- var increment = new Buffer(8);
- increment.fill(0);
- increment.writeUInt32LE(1, 0);
-
- var window = { start: windowStart, size: 0 };
-
- return whileLoop(function() {
- // Cannot yield to event loop in this block {
- if(window.start > windowStart) {
- tr.clearRange(self.counters, self.counters.get(window.start));
- tr.options.setNextWriteNoWriteConflictRange();
- tr.clearRange(self.recent, self.recent.get(window.start));
- }
-
- tr.add(self.counters.pack([window.start]), increment);
- return tr.snapshot.get(self.counters.get(window.start))
- // }
- .then(function(newCountBuffer) {
- var newCount = (newCountBuffer === null) ? 0 : newCountBuffer.readUInt32LE(0);
- window.size = windowSize(window.start);
- if(newCount * 2 < window.size) {
- return window; // exit the loop
- }
-
- window.start += window.size;
- });
- });
-};
-
-HighContentionAllocator.prototype.choosePrefix = function(tr, window) {
- var self = this;
-
- return whileLoop(function() {
- var candidate = Math.floor(Math.random() * window.size) + window.start;
- var allocationKey = self.recent.pack([candidate]);
-
- // Cannot yield to event loop in this block {
- var counterRange = tr.snapshot.getRange(self.counters.range().begin, self.counters.range().end, { limit: 1, reverse: true }).toArray();
- var allocation = tr.get(allocationKey);
- tr.options.setNextWriteNoWriteConflictRange();
- tr.set(allocationKey, buffer(''));
- // }
-
- return future.all([counterRange, allocation])
- .then(function(vals) {
- var currentWindowStart = vals[0].length > 0 ? self.counters.unpack(vals[0][0].key)[0] : 0;
- if(currentWindowStart > window.start) {
- return null; // exit the loop and force find() to retry
- }
- if(vals[1] === null) {
- tr.addWriteConflictKey(allocationKey);
- return candidate; // exit the loop
- }
- });
- });
-};
-
-function windowSize(start) {
- if(start < 255)
- return 64;
- if(start < 65535)
- return 1024;
-
- return 8192;
-}
-
-/******************
- * DirectoryLayer *
-******************/
-
-var VERSION = [1, 0, 0];
-var SUBDIRS = 0;
-
-var DirectoryLayer = function(options) {
- options = valueOrDefault(options, {});
-
- this._nodeSubspace = valueOrDefault(options.nodeSubspace, new Subspace([], buffer.fromByteLiteral('\xfe')));
-
- // If specified, new automatically allocated prefixes will all fall within the contentSubspace
- this._contentSubspace = valueOrDefault(options.contentSubspace, new Subspace());
- this._allowManualPrefixes = valueOrDefault(options.allowManualPrefixes, false);
-
- this._rootNode = this._nodeSubspace.subspace([this._nodeSubspace.key()]);
- this._allocator = new HighContentionAllocator(this._rootNode.subspace([buffer('hca')]));
-
- this._path = [];
-};
-
-var createOrOpen = transactional(function(tr, self, path, options, allowCreate, allowOpen, cb) {
- options = valueOrDefault(options, {});
- var layer = valueOrDefault(options.layer, buffer(''));
- var prefix = options.prefix;
-
- allowCreate = valueOrDefault(allowCreate, true);
- allowOpen = valueOrDefault(allowOpen, true);
-
- return checkVersion(self, tr, false)
- .then(function() {
- if(typeof prefix !== 'undefined') {
- if(allowCreate && allowOpen)
- throw new Error('Cannot specify a prefix when calling create_or_open.');
- else if(!self._allowManualPrefixes) {
- if(self._path.length === 0)
- throw new Error('Cannot specify a prefix unless manual prefixes are enabled.');
- else
- throw new Error('Cannot specify a prefix in a partition.');
- }
- }
-
- path = toUnicodePath(path);
- if(path.length === 0)
- throw new Error('The root directory cannot be opened.');
-
- return find(self, tr, path).then(loadMetadata(tr));
- })
- .then(function(existingNode) {
- if(existingNode.exists()) {
- if(existingNode.isInPartition(false)) {
- var subpath = existingNode.getPartitionSubpath();
- var directoryLayer = existingNode.getContents(self)._directoryLayer;
- return createOrOpen(tr,
- existingNode.getContents(self)._directoryLayer,
- subpath,
- options,
- allowCreate,
- allowOpen);
- }
-
- return openDirectory(tr, self, path, layer, existingNode, allowOpen);
- }
- else
- return createDirectory(tr, self, path, layer, prefix, allowCreate);
- })(cb);
-});
-
-var openDirectory = function(tr, self, path, layer, existingNode, allowOpen) {
- if(!allowOpen)
- throw new Error('The directory already exists.');
-
- checkLayer(layer, existingNode.layer);
-
- return existingNode.getContents(self);
-};
-
-var createDirectory = function(tr, self, path, layer, prefix, allowCreate) {
- if(!allowCreate)
- throw new Error('The directory does not exist.');
-
- var prefixIsAllocated = typeof(prefix) === 'undefined';
- return checkVersion(self, tr, true)
- .then(function() {
- return getPrefix(self, tr, prefix);
- })
- .then(function(prefix) {
- return isPrefixFree(self, prefixIsAllocated ? tr.snapshot : tr, prefix)
- .then(function(isFree) {
- if(!isFree) {
- if(prefixIsAllocated)
- throw new Error('The directory layer has manually allocated prefixes that conflict with the automatic prefix allocator.');
- else
- throw new Error('The given prefix is already in use.');
- }
-
- return getParentNode(self, tr, path);
- })
- .then(function(parentNode) {
- if(!parentNode)
- throw new Error('The parent directory doesn\'t exist.');
-
- var node = nodeWithPrefix(self, prefix);
- tr.set(parentNode.subspace([SUBDIRS]).pack([path[path.length-1]]), prefix);
- tr.set(node.pack([buffer('layer')]), layer);
-
- return contentsOfNode(self, node, path, layer);
- });
- });
-};
-
-DirectoryLayer.prototype.getLayer = function() {
- return new Buffer(0);
-};
-
-DirectoryLayer.prototype.getPath = function() {
- return this._path.slice(0);
-};
-
-DirectoryLayer.prototype.createOrOpen = function(databaseOrTransaction, path, options, cb) {
- return createOrOpen(databaseOrTransaction, this, path, options, true, true, cb);
-};
-
-DirectoryLayer.prototype.open = function(databaseOrTransaction, path, options, cb) {
- return createOrOpen(databaseOrTransaction, this, path, options, false, true, cb);
-};
-
-DirectoryLayer.prototype.create = function(databaseOrTransaction, path, options, cb) {
- return createOrOpen(databaseOrTransaction, this, path, options, true, false, cb);
-};
-
-DirectoryLayer.prototype.moveTo = function(databaseOrTransaction, newAbsolutePath, cb) {
- return future.reject(new Error('The root directory cannot be moved.'))(cb);
-};
-
-DirectoryLayer.prototype.move = transactional(function(tr, oldPath, newPath, cb) {
- var self = this;
- var oldNode, newNode;
-
- return checkVersion(self, tr, true)
- .then(function() {
- oldPath = toUnicodePath(oldPath);
- newPath = toUnicodePath(newPath);
-
- if(pathsEqual(oldPath, newPath.slice(0, oldPath.length)))
- throw new Error('The destination directory cannot be a subdirectory of the source directory.');
-
- var oldNodeFuture = find(self, tr, oldPath).then(loadMetadata(tr));
- var newNodeFuture = find(self, tr, newPath).then(loadMetadata(tr));
- return future.all([oldNodeFuture, newNodeFuture]);
- })
- .then(function(nodes) {
- oldNode = nodes[0];
- newNode = nodes[1];
-
- if(!oldNode.exists())
- throw new Error('The source directory does not exist.');
-
- if(oldNode.isInPartition(false) || newNode.isInPartition(false)) {
- if(!oldNode.isInPartition(false) || !newNode.isInPartition(false) || !pathsEqual(oldNode.path, newNode.path))
- throw new Error('Cannot move between partitions.');
-
- return newNode.getContents(self).move(tr, oldNode.getPartitionSubpath(), newNode.getPartitionSubpath());
- }
-
- if(newNode.exists())
- throw new Error('The destination directory already exists. Remove it first.');
-
- return find(self, tr, newPath.slice(0, newPath.length-1))
- .then(function(parentNode) {
- if(!parentNode.exists())
- throw new Error('The parent of the destination directory does not exist. Create it first.');
-
- tr.set(parentNode.subspace.subspace([SUBDIRS]).pack([newPath[newPath.length-1]]),
- self._nodeSubspace.unpack(oldNode.subspace.key())[0]);
-
- return removeFromParent(self, tr, oldPath);
- })
- .then(function() {
- return contentsOfNode(self, oldNode.subspace, newPath, oldNode.layer);
- });
- })(cb);
-});
-
-DirectoryLayer.prototype.remove = transactional(function(tr, path, cb) {
- return removeInternal(this, tr, path, true)(cb);
-});
-
-DirectoryLayer.prototype.removeIfExists = transactional(function(tr, path, cb) {
- return removeInternal(this, tr, path, false)(cb);
-});
-
-function removeInternal(self, tr, path, failOnNonexistent) {
- return checkVersion(self, tr, true)
- .then(function() {
- path = valueOrDefault(path, []);
- if(path.length === 0)
- return future.reject(new Error('The root directory cannot be removed.'));
-
- path = toUnicodePath(path);
- return find(self, tr, path).then(loadMetadata(tr));
- })
- .then(function(node) {
- if(!node.exists()) {
- if(failOnNonexistent)
- throw new Error('The directory doesn\'t exist');
- else
- return false;
- }
-
- if(node.isInPartition(false)) {
- return removeInternal(node.getContents(self)._directoryLayer,
- tr,
- node.getPartitionSubpath(),
- failOnNonexistent);
- }
-
- return removeRecursive(self, tr, node.subspace)
- .then(function() {
- return removeFromParent(self, tr, path);
- }).
- then(function() {
- return true;
- });
- });
-}
-
-DirectoryLayer.prototype.list = transactional(function(tr, path, cb) {
- var self = this;
- return checkVersion(self, tr, false)
- .then(function() {
- path = valueOrDefault(path, []);
- path = toUnicodePath(path);
-
- return find(self, tr, path).then(loadMetadata(tr));
- })
- .then(function(node) {
- if(!node.exists())
- throw new Error('The given directory does not exist');
-
- if(node.isInPartition(true))
- return node.getContents(self).list(tr, node.getPartitionSubpath());
-
- var subdir = node.subspace.subspace([SUBDIRS]);
-
- return tr.getRange(subdir.range().begin, subdir.range().end).toArray()
- .then(function(arr) {
- return arr.map(function(kv) { return subdir.unpack(kv.key)[0].toString('utf8'); });
- });
- })(cb);
-});
-
-DirectoryLayer.prototype.exists = transactional(function(tr, path, cb) {
- var self = this;
- return checkVersion(self, tr, false)
- .then(function() {
- path = valueOrDefault(path, []);
- path = toUnicodePath(path);
- return find(self, tr, path).then(loadMetadata(tr));
- })
- .then(function(node) {
- if(!node.exists())
- return false;
-
- if(node.isInPartition(false))
- return node.getContents(self).exists(tr, node.getPartitionSubpath());
-
- return true;
- })(cb);
-});
-
-// Private functions:
-
-function checkVersion(self, tr, writeAccess) {
- return tr.get(self._rootNode.pack([buffer('version')]))
- .then(function(versionBuf) {
- if(!versionBuf) {
- if(writeAccess)
- initializeDirectory(self, tr);
-
- return;
- }
-
- var version = [];
- for(var i = 0; i < 3; ++i)
- version.push(versionBuf.readInt32LE(4*i));
-
- var dirVersion = util.format('%d.%d.%d', version[0], version[1], version[2]);
- var layerVersion = util.format('%d.%d.%d', VERSION[0], VERSION[1], VERSION[2]);
-
- if(version[0] > VERSION[0]) {
- throw new Error(util.format('Cannot load directory with version %s using directory layer %s',
- dirVersion,
- layerVersion));
- }
-
- if(version[1] > VERSION[1]) {
- throw new Error(util.format('Directory with version %s is read-only when opened using directory layer %s',
- dirVersion,
- layerVersion));
- }
- });
-}
-
-function initializeDirectory(self, tr) {
- var versionBuf = new Buffer(12);
- for(var i = 0; i < 3; ++i)
- versionBuf.writeUInt32LE(VERSION[i], i*4);
-
- tr.set(self._rootNode.pack([buffer('version')]), versionBuf);
-}
-
-function nodeWithPrefix(self, prefix) {
- if(prefix === null)
- return null;
-
- return self._nodeSubspace.subspace([prefix]);
-}
-
-function find(self, tr, path) {
- var pathIndex = 0;
- var node = new Node(self._rootNode, [], path);
-
- return whileLoop(function() {
- if(pathIndex === path.length)
- return future.resolve(node);
-
- return tr.get(node.subspace.subspace([SUBDIRS]).pack([path[pathIndex++]]))
- .then(function(val) {
- node = new Node(nodeWithPrefix(self, val), path.slice(0, pathIndex), path);
- if(!node.exists())
- return node;
- return node.loadMetadata(tr)
- .then(function() {
- if(fdbUtil.buffersEqual(node.layer, buffer('partition')))
- return node;
- });
- });
- });
-}
-
-function contentsOfNode(self, node, path, layer) {
- var prefix = self._nodeSubspace.unpack(node.key())[0];
-
- if(fdbUtil.buffersEqual(layer, buffer('partition')))
- return new DirectoryPartition(self._path.concat(path), prefix, self);
- else
- return new DirectorySubspace(self._path.concat(path), prefix, self, layer);
-}
-
-function getPrefix(self, tr, prefix) {
- if(typeof prefix === 'undefined') {
- return self._allocator.allocate(tr)
- .then(function(prefix) {
- var allocated = Buffer.concat([self._contentSubspace.key(), prefix], self._contentSubspace.key().length + prefix.length);
- return tr.getRangeStartsWith(allocated, { limit: 1 })
- .toArray()
- .then(function(arr) {
- if(arr.length > 0)
- throw new Error('The database has keys stored at the prefix chosen by the automatic prefix allocator: ' + prefix);
-
- return allocated;
- });
- });
- }
- else
- return future.resolve(buffer(prefix));
-}
-
-function getNodeContainingKey(self, tr, key) {
- if(self._nodeSubspace.contains(key))
- return future.resolve(self._rootNode);
-
- return tr.getRange(self._nodeSubspace.range([]).begin,
- self._nodeSubspace.subspace([key]).range().begin,
- { limit: 1, reverse: true })
- .toArray()
- .then(function(arr) {
- if(arr.length > 0) {
- var prevPrefix = self._nodeSubspace.unpack(arr[0].key)[0];
- if(startsWith(key, prevPrefix))
- return nodeWithPrefix(self, prevPrefix);
- }
-
- return null;
- });
-}
-
-function isPrefixFree(self, tr, prefix) {
- if(!prefix || prefix.length === 0)
- return future.resolve(false);
-
- return getNodeContainingKey(self, tr, prefix)
- .then(function(node) {
- if(node)
- return false;
-
- return tr.getRange(self._nodeSubspace.pack([prefix]),
- self._nodeSubspace.pack([fdbUtil.strinc(prefix)]),
- { limit: 1 })
- .toArray()
- .then(function(arr) {
- return arr.length === 0;
- });
- });
-}
-
-function getParentNode(self, tr, path) {
- if(path.length > 1) {
- return self.createOrOpen(tr, path.slice(0, path.length-1))
- .then(function(dir) {
- return nodeWithPrefix(self, dir.key());
- });
- }
- else
- return future.resolve(self._rootNode);
-}
-
-function removeFromParent(self, tr, path) {
- return find(self, tr, path.slice(0, path.length-1))
- .then(function(parentNode) {
- tr.clear(parentNode.subspace.subspace([SUBDIRS]).pack([path[path.length-1]]));
- });
-}
-
-function removeRecursive(self, tr, node) {
- var subdir = node.subspace([SUBDIRS]);
- return tr.getRange(subdir.range().begin, subdir.range().end)
- .forEach(function(kv, loopCb) {
- removeRecursive(self, tr, nodeWithPrefix(self, kv.value))(loopCb);
- })
- .then(function() {
- tr.clearRangeStartsWith(self._nodeSubspace.unpack(node.key())[0]);
- tr.clearRange(node.range().begin, node.range().end);
- });
-}
-
-function toUnicodePath(path) {
- if(Buffer.isBuffer(path) || path instanceof ArrayBuffer || path instanceof Uint8Array)
- path = buffer(path).toString('utf8');
-
- if(typeof path === 'string')
- return [path];
-
- if(path instanceof Array) {
- for(var i = 0; i < path.length; ++i) {
- if(Buffer.isBuffer(path[i]) || path[i] instanceof ArrayBuffer || path[i] instanceof Uint8Array)
- path[i] = buffer(path[i]).toString('utf8');
- if(typeof path[i] !== 'string')
- throw new TypeError('Invalid path: must be a string, Buffer, ArrayBuffer, Uint8Array, or an array of such items');
- }
-
- return path;
- }
-
- throw new TypeError('Invalid path: must be a string, Buffer, ArrayBuffer, Uint8Array, or an array of such items');
-}
-
-/*********************
- * DirectorySubspace *
- *********************/
-
-var DirectorySubspace = function(path, prefix, directoryLayer, layer) {
- Subspace.call(this, undefined, prefix);
- this._path = path;
- this._directoryLayer = directoryLayer;
- this._layer = layer;
-};
-
-DirectorySubspace.prototype = new Subspace();
-DirectorySubspace.constructor = DirectorySubspace;
-
-DirectorySubspace.prototype.getLayer = function() {
- return this._layer;
-};
-
-DirectorySubspace.prototype.getPath = function() {
- return this._path.slice(0);
-};
-
-DirectorySubspace.prototype.createOrOpen = function(databaseOrTransaction, nameOrPath, options, cb) {
- var path = tuplifyPath(nameOrPath);
- return this._directoryLayer.createOrOpen(databaseOrTransaction, partitionSubpath(this, path), options, cb);
-};
-
-DirectorySubspace.prototype.open = function(databaseOrTransaction, nameOrPath, options, cb) {
- var path = tuplifyPath(nameOrPath);
- return this._directoryLayer.open(databaseOrTransaction, partitionSubpath(this, path), options, cb);
-};
-
-DirectorySubspace.prototype.create = function(databaseOrTransaction, nameOrPath, options, cb) {
- var path = tuplifyPath(nameOrPath);
- return this._directoryLayer.create(databaseOrTransaction, partitionSubpath(this, path), options, cb);
-};
-
-DirectorySubspace.prototype.list = function(databaseOrTransaction, nameOrPath, cb) {
- var path = tuplifyPath(valueOrDefault(nameOrPath, []));
- return this._directoryLayer.list(databaseOrTransaction, partitionSubpath(this, path), cb);
-};
-
-DirectorySubspace.prototype.move = function(databaseOrTransaction, oldNameOrPath, newNameOrPath, cb) {
- var oldPath = tuplifyPath(oldNameOrPath);
- var newPath = tuplifyPath(newNameOrPath);
- return this._directoryLayer.move(databaseOrTransaction,
- partitionSubpath(this, oldPath),
- partitionSubpath(this, newPath),
- cb);
-};
-
-DirectorySubspace.prototype.moveTo = function(databaseOrTransaction, newAbsoluteNameOrPath, cb) {
- var directoryLayer;
- var newAbsolutePath;
- try {
- directoryLayer = getLayerForPath(this, []);
- newAbsolutePath = toUnicodePath(newAbsoluteNameOrPath);
- var partitionPath = newAbsolutePath.slice(0, directoryLayer._path.length);
- if(!pathsEqual(partitionPath, directoryLayer._path))
- throw new Error('Cannot move between partitions.');
- }
- catch(err) {
- return future.reject(err)(cb);
- }
-
- return directoryLayer.move(databaseOrTransaction,
- this._path.slice(directoryLayer._path.length),
- newAbsolutePath.slice(directoryLayer._path.length),
- cb);
-};
-
-DirectorySubspace.prototype.remove = function(databaseOrTransaction, nameOrPath, cb) {
- var path = tuplifyPath(valueOrDefault(nameOrPath, []));
- var directoryLayer = getLayerForPath(this, path);
- return directoryLayer.remove(databaseOrTransaction, partitionSubpath(this, path, directoryLayer), cb);
-};
-
-DirectorySubspace.prototype.removeIfExists = function(databaseOrTransaction, nameOrPath, cb) {
- var path = tuplifyPath(valueOrDefault(nameOrPath, []));
- var directoryLayer = getLayerForPath(this, path);
- return directoryLayer.removeIfExists(databaseOrTransaction, partitionSubpath(this, path, directoryLayer), cb);
-};
-
-DirectorySubspace.prototype.exists = function(databaseOrTransaction, nameOrPath, cb) {
- var path = tuplifyPath(valueOrDefault(nameOrPath, []));
- var directoryLayer = getLayerForPath(this, path);
- return directoryLayer.exists(databaseOrTransaction, partitionSubpath(this, path, directoryLayer), cb);
-};
-
-var partitionSubpath = function(directorySubspace, path, directoryLayer) {
- directoryLayer = valueOrDefault(directoryLayer, directorySubspace._directoryLayer);
- return directorySubspace._path.slice(directoryLayer._path.length).concat(path);
-};
-
-/**********************
- * DirectoryPartition *
- **********************/
-
-var DirectoryPartition = function(path, prefix, parentDirectoryLayer) {
- var directoryLayer = new DirectoryLayer({
- nodeSubspace: new Subspace(undefined, Buffer.concat([prefix, buffer.fromByteLiteral('\xfe')], prefix.length+1)),
- contentSubspace: new Subspace(undefined, prefix)
- });
-
- directoryLayer._path = path;
- DirectorySubspace.call(this, path, prefix, directoryLayer, buffer('partition'));
- this._parentDirectoryLayer = parentDirectoryLayer;
-};
-
-DirectoryPartition.prototype = new DirectorySubspace();
-DirectoryPartition.constructor = DirectoryPartition;
-
-DirectoryPartition.prototype.key = function() {
- throw new Error('Cannot get key for the root of a directory partition.');
-};
-
-DirectoryPartition.prototype.pack = function(arr) {
- throw new Error('Cannot pack keys using the root of a directory partition.');
-};
-
-DirectoryPartition.prototype.unpack = function(arr) {
- throw new Error('Cannot unpack keys using the root of a directory partition.');
-};
-
-DirectoryPartition.prototype.range = function(arr) {
- throw new Error('Cannot get range for the root of a directory partition.');
-};
-
-DirectoryPartition.prototype.contains = function(key) {
- throw new Error('Cannot check whether a key belongs to the root of a directory partition.');
-};
-
-DirectoryPartition.prototype.get = function(name) {
- throw new Error('Cannot open subspace in the root of a directory partition.');
-};
-
-DirectoryPartition.prototype.subspace = function(arr) {
- throw new Error('Cannot open subspace in the root of a directory partition.');
-};
-
-DirectoryPartition.prototype.asFoundationDBKey = function() {
- throw new Error('Cannot use the root of a directory partition as a key.');
-};
-
-var getLayerForPath = function(directorySubspace, path) {
- if(directorySubspace instanceof DirectoryPartition && path.length === 0)
- return directorySubspace._parentDirectoryLayer;
- else
- return directorySubspace._directoryLayer;
-};
-
-/********
- * Node *
- ********/
-
-var Node = function(subspace, path, targetPath) {
- this.subspace = subspace;
- this.path = path;
- this.targetPath = targetPath;
-};
-
-Node.prototype.exists = function() {
- return typeof(this.subspace) !== 'undefined' && this.subspace !== null;
-};
-
-Node.prototype.loadMetadata = function(tr) {
- var self = this;
- if(!self.exists()) {
- self.loadedMetadata = true;
- return future.resolve(self);
- }
-
- return tr.get(self.subspace.pack([buffer('layer')]))
- .then(function(layer) {
- self.loadedMetadata = true;
- self.layer = layer;
- return self;
- });
-};
-
-Node.prototype.ensureMetadataLoaded = function() {
- if(!this.loadedMetadata)
- throw new Error('Metadata for node has not been loaded');
-};
-
-Node.prototype.isInPartition = function(includeEmptySubpath) {
- this.ensureMetadataLoaded();
- return this.exists() &&
- fdbUtil.buffersEqual(this.layer, buffer('partition')) &&
- (includeEmptySubpath || this.targetPath.length > this.path.length);
-};
-
-Node.prototype.getPartitionSubpath = function() {
- this.ensureMetadataLoaded();
- return this.targetPath.slice(this.path.length);
-};
-
-Node.prototype.getContents = function(directoryLayer) {
- this.ensureMetadataLoaded();
- return contentsOfNode(directoryLayer, this.subspace, this.path, this.layer);
-};
-
-var loadMetadata = function(tr) {
- return function(node) {
- return node.loadMetadata(tr);
- };
-};
-
-module.exports = { directory: new DirectoryLayer(), DirectoryLayer: DirectoryLayer };
diff --git a/bindings/nodejs/lib/error.js b/bindings/nodejs/lib/error.js
deleted file mode 100644
index feb16957b3..0000000000
--- a/bindings/nodejs/lib/error.js
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * error.js
- *
- * This source file is part of the FoundationDB open source project
- *
- * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
- *
- * Licensed 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";
-
-function FDBError(description, code) {
- Error.captureStackTrace(this, this.constructor);
- this.message = description;
- this.code = code;
-}
-
-FDBError.prototype = new Error();
-FDBError.constructor = FDBError;
-FDBError.prototype.name = "FDBError"; // affects error messages, also needed for compatibility with older bindings
-
-module.exports = FDBError;
diff --git a/bindings/nodejs/lib/fdb.js b/bindings/nodejs/lib/fdb.js
deleted file mode 100644
index 056a3bad41..0000000000
--- a/bindings/nodejs/lib/fdb.js
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * fdb.js
- *
- * This source file is part of the FoundationDB open source project
- *
- * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
- *
- * Licensed 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";
-
-var KeySelector = require('./keySelector');
-var Cluster = require('./cluster');
-var future = require('./future');
-var Transactional = require('./retryDecorator');
-var tuple = require('./tuple');
-var buffer = require('./bufferConversion');
-var fdb = require('./fdbModule');
-var FDBError = require('./error');
-var locality = require('./locality');
-var directory = require('./directory');
-var Subspace = require('./subspace');
-var selectedApiVersion = require('./apiVersion');
-
-var fdbModule = {};
-
-module.exports = {
- FDBError: FDBError,
- apiVersion: function(version) {
- if(selectedApiVersion.value && version !== selectedApiVersion.value)
- throw new Error('Cannot select multiple different FDB API versions');
- if(version < 500)
- throw new RangeError('FDB API versions before 500 are not supported');
- if(version > 510)
- throw new RangeError('Latest known FDB API version is 510');
-
- if(!selectedApiVersion.value) {
- fdb.apiVersion(version);
-
- fdbModule.FDBError = this.FDBError;
- fdbModule.KeySelector = KeySelector;
- fdbModule.future = future;
- fdbModule.transactional = Transactional;
- fdbModule.tuple = tuple;
- fdbModule.buffer = buffer;
- fdbModule.locality = locality;
- fdbModule.directory = directory.directory;
- fdbModule.DirectoryLayer = directory.DirectoryLayer;
- fdbModule.Subspace = Subspace;
-
- fdbModule.options = fdb.options;
- fdbModule.streamingMode = fdb.streamingMode;
-
- var dbCache = {};
-
- var doInit = function() {
- fdb.startNetwork();
-
- process.on('exit', function() {
- //Clearing out the caches makes memory debugging a little easier
- dbCache = null;
-
- fdb.stopNetwork();
- });
-
- //Subsequent calls do nothing
- doInit = function() { };
- };
-
- fdbModule.init = function() {
- doInit();
- };
-
- fdbModule.createCluster = function(clusterFile, cb) {
- if(!clusterFile)
- clusterFile = '';
-
- return new Cluster(fdb.createCluster(clusterFile));
- };
-
- fdbModule.open = function(clusterFile, cb) {
- if(clusterFile)
- fdb.options.setClusterFile(clusterFile);
-
- this.init();
-
- var database = dbCache[clusterFile];
- if(!database) {
- var cluster = fdbModule.createCluster(clusterFile);
- database = cluster.openDatabase();
- dbCache[clusterFile] = database;
- }
-
- return database;
- };
- }
-
- selectedApiVersion.value = version;
- return fdbModule;
- }
-};
-
-fdb.FDBError = module.exports.FDBError;
diff --git a/bindings/nodejs/lib/fdbModule.js b/bindings/nodejs/lib/fdbModule.js
deleted file mode 100644
index 047279d184..0000000000
--- a/bindings/nodejs/lib/fdbModule.js
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * fdbModule.js
- *
- * This source file is part of the FoundationDB open source project
- *
- * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
- *
- * Licensed 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";
-
-var semver = require('semver');
-
-if(semver.satisfies(process.version, '0.10.x'))
- var fdb = require('../modules/0.10/fdblib');
-else if(semver.satisfies(process.version, '0.8.x'))
- var fdb = require('../modules/0.8/fdblib');
-else
- throw new Error('FoundationDB binary NPM does not support Node.js ' + process.version + '; only v0.8.x and v0.10.x are supported');
-
-module.exports = fdb;
diff --git a/bindings/nodejs/lib/fdbUtil.js b/bindings/nodejs/lib/fdbUtil.js
deleted file mode 100644
index ed3b80777b..0000000000
--- a/bindings/nodejs/lib/fdbUtil.js
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * fdbUtil.js
- *
- * This source file is part of the FoundationDB open source project
- *
- * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
- *
- * Licensed 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";
-
-var buffer = require('./bufferConversion');
-var future = require('./future');
-
-var strinc = function(str) {
- var buf = buffer(str);
-
- var lastNonFFByte;
- for(lastNonFFByte = buf.length-1; lastNonFFByte >= 0; --lastNonFFByte)
- if(buf[lastNonFFByte] != 0xFF)
- break;
-
- if(lastNonFFByte < 0)
- throw new Error('invalid argument \'' + str + '\': prefix must have at least one byte not equal to 0xFF');
-
- var copy = new Buffer(lastNonFFByte + 1);
- str.copy(copy, 0, 0, copy.length);
- ++copy[lastNonFFByte];
-
- return copy;
-};
-
-var whileLoop = function(func, cb) {
- return future.create(function(futureCb) {
- var calledCallback = true;
- function outer(err, res) {
- if(err || typeof(res) !== 'undefined') {
- futureCb(err, res);
- }
- else if(!calledCallback) {
- calledCallback = true;
- }
- else {
- while(calledCallback) {
- calledCallback = false;
- func(outer);
- }
-
- calledCallback = true;
- }
- }
-
- outer();
- }, cb);
-};
-
-var keyToBuffer = function(key) {
- if(typeof(key.asFoundationDBKey) == 'function')
- return buffer(key.asFoundationDBKey());
-
- return buffer(key);
-};
-
-var valueToBuffer = function(val) {
- if(typeof(val.asFoundationDBValue) == 'function')
- return buffer(val.asFoundationDBValue());
-
- return buffer(val);
-};
-
-var buffersEqual = function(buf1, buf2) {
- if(!buf1 || !buf2)
- return buf1 === buf2;
-
- if(buf1.length !== buf2.length)
- return false;
-
- for(var i = 0; i < buf1.length; ++i)
- if(buf1[i] !== buf2[i])
- return false;
-
- return true;
-};
-
-module.exports = {
- strinc: strinc,
- whileLoop: whileLoop,
- keyToBuffer: keyToBuffer,
- valueToBuffer: valueToBuffer,
- buffersEqual: buffersEqual
-};
-
diff --git a/bindings/nodejs/lib/future.js b/bindings/nodejs/lib/future.js
deleted file mode 100644
index e21293b42b..0000000000
--- a/bindings/nodejs/lib/future.js
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * future.js
- *
- * This source file is part of the FoundationDB open source project
- *
- * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
- *
- * Licensed 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";
-var semver = require('semver');
-
-function isFunction(f) {
- return typeof(f) == 'function';
-}
-
-function isObject(o) {
- return o === Object(o);
-}
-
-var resolvePromise = function(promise, value) {
- var called = false;
- try {
- if(promise === value)
- promise._state.reject(new TypeError('promise.then cannot be fulfilled with itself as the argument.'));
-
- if(isObject(value)) {
- var then = value.then;
- if(isFunction(then)) {
- then.call(value, function(res) {
- if(!called) {
- called = true;
- resolvePromise(promise, res, promise);
- }
- }, function(err) {
- if(!called) {
- called = true;
- promise._state.reject(err);
- }
- });
- }
- else
- promise._state.fulfill(value);
- }
- else
- promise._state.fulfill(value);
- }
- catch(error) {
- if(!called)
- promise._state.reject(error);
- }
-};
-
-var FuturePrototype = {
- cancel: function() {
- //cancel is not implemented for most futures
- },
-
- then: function(onFulfilled, onRejected) {
- var self = this;
- var future = create();
- this._state.addCallback(function(err, res) {
- var setImmediateFunc;
- if(semver.satisfies(process.version, '>=0.10.0')) {
- setImmediateFunc = setImmediate;
- }
- else {
- setImmediateFunc = process.nextTick;
- }
- setImmediateFunc(function() {
- try {
- if(self._state.rejected) {
- if(isFunction(onRejected))
- res = onRejected(err);
- else {
- future._state.reject(err);
- return;
- }
- }
- else if(isFunction(onFulfilled))
- res = onFulfilled(res);
-
- resolvePromise(future, res);
- }
- catch(error) {
- future._state.reject(error);
- }
- });
- });
-
- return future;
- },
-
- "catch": function(onRejected) {
- this.then(undefined, onRejected);
- }
-};
-
-FuturePrototype.__proto__ = Function.__proto__;
-
-var FutureState = function() {
- this.callbacks = [];
- this.fulfilled = false;
- this.rejected = false;
-};
-
-FutureState.prototype.triggerCallbacks = function() {
- for(var i = 0; i < this.callbacks.length; ++i)
- this.callbacks[i](this.error, this.value);
-
- this.callbacks = [];
-};
-
-FutureState.prototype.addCallback = function(cb) {
- if(!this.rejected && !this.fulfilled)
- this.callbacks.push(cb);
- else
- cb(this.error, this.value);
-};
-
-FutureState.prototype.fulfill = function(value) {
- if(!this.fulfilled && !this.rejected) {
- this.fulfilled = true;
- this.value = value;
- this.triggerCallbacks();
- }
-};
-
-FutureState.prototype.reject = function(reason) {
- if(!this.fulfilled && !this.rejected) {
- this.rejected = true;
- this.error = reason;
- this.triggerCallbacks();
- }
-};
-
-var getFutureCallback = function(futureState) {
- return function(err, val) {
- if(err)
- futureState.reject(err);
- else
- futureState.fulfill(val);
- };
-};
-
-var create = function(func, cb) {
- if(cb)
- func(cb);
- else {
- // This object is used to break a reference cycle with C++ objects
- var futureState = new FutureState();
-
- var future = function(callback) {
- if(typeof callback === 'undefined')
- return future;
-
- future.then(function(val) { callback(undefined, val); }, callback);
- };
-
- future._state = futureState;
- future.__proto__ = FuturePrototype;
-
- if(func)
- func.call(future, getFutureCallback(futureState));
-
- return future;
- }
-};
-
-var resolve = function(value) {
- var f = create();
- f._state.fulfill(value);
- return f;
-};
-
-var reject = function(reason) {
- var f = create();
- f._state.reject(reason);
- return f;
-};
-
-var all = function(futures) {
- var future = create(function(futureCb) {
- var count = futures.length;
-
- if(count === 0)
- futureCb(undefined, []);
-
- var successCallback = function() {
- if(--count === 0)
- futureCb(undefined, futures.map(function(f) { return f._state.value; }));
- };
-
- for(var i = 0; i < futures.length; ++i) {
- if(futures[i] && isFunction(futures[i].then))
- futures[i].then(successCallback, futureCb);
- else
- successCallback();
- }
- });
-
- return future;
-};
-
-var race = function(futures) {
- var future = create(function(futureCb) {
- var successCallback = function(val) {
- futureCb(undefined, val);
- };
-
- for(var i = 0; i < futures.length; ++i) {
- if(futures[i] && isFunction(futures[i].then))
- futures[i].then(successCallback, futureCb);
- else {
- futureCb(undefined, futures[i]);
- break;
- }
- }
- });
-
- return future;
-};
-
-module.exports = {
- FuturePrototype: FuturePrototype,
- create: create,
- resolve: resolve,
- reject: reject,
- all: all,
- race: race
-};
-
diff --git a/bindings/nodejs/lib/keySelector.js b/bindings/nodejs/lib/keySelector.js
deleted file mode 100644
index a0960d375a..0000000000
--- a/bindings/nodejs/lib/keySelector.js
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * keySelector.js
- *
- * This source file is part of the FoundationDB open source project
- *
- * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
- *
- * Licensed 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";
-
-var fdbUtil = require('./fdbUtil');
-
-var KeySelector = function(key, orEqual, offset) {
- this.key = fdbUtil.keyToBuffer(key);
- this.orEqual = orEqual;
- this.offset = offset;
-};
-
-KeySelector.prototype.next = function() {
- return this.add(1);
-};
-
-KeySelector.prototype.prev = function() {
- return this.add(-1);
-};
-
-KeySelector.prototype.add = function(addOffset) {
- return new KeySelector(this.key, this.orEqual, this.offset + addOffset);
-};
-
-KeySelector.isKeySelector = function(sel) {
- return sel instanceof KeySelector;
-};
-
-KeySelector.lastLessThan = function(key) {
- return new KeySelector(key, false, 0);
-};
-
-KeySelector.lastLessOrEqual = function(key) {
- return new KeySelector(key, true, 0);
-};
-
-KeySelector.firstGreaterThan = function(key) {
- return new KeySelector(key, true, 1);
-};
-
-KeySelector.firstGreaterOrEqual = function(key) {
- return new KeySelector(key, false, 1);
-};
-
-module.exports = KeySelector;
-
diff --git a/bindings/nodejs/lib/lazyIterator.js b/bindings/nodejs/lib/lazyIterator.js
deleted file mode 100644
index b746493d0b..0000000000
--- a/bindings/nodejs/lib/lazyIterator.js
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * lazyIterator.js
- *
- * This source file is part of the FoundationDB open source project
- *
- * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
- *
- * Licensed 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";
-
-var fdbUtil = require('./fdbUtil');
-var future = require('./future');
-
-function fetch(state, cb) {
- if(cb)
- state.fetchCallbacks.push(cb);
- if(!state.fetching) {
- state.fetching = true;
- state.fetcher.fetch(function(err, res) {
- var cbs = state.fetchCallbacks;
- state.fetching = false;
- state.fetchCallbacks = [];
- state.results = res;
- state.index = -1;
- state.finished = !res || res.length === 0;
-
- for(var i = 0; i < cbs.length; ++i)
- cbs[i](err);
- });
- }
-}
-
-function iterState(fetcher) {
- return {
- index: -1,
- results: undefined,
-
- fetching: false,
- fetchCallbacks: [],
- fetcher: fetcher
- };
-}
-
-var LazyIterator = function(Fetcher) {
- this.Fetcher = Fetcher;
- this.stateForNext = undefined;
-
- this.startState = iterState(new Fetcher());
-
- var startState = this.startState;
- fetch(this.startState);
-};
-
-function copyState(state, wantAll) {
- var newState = iterState();
- newState.index = state.index;
- newState.results = state.results;
- newState.fetching = state.fetching;
-
- if(state.fetching) {
- state.fetchCallbacks.push(function(err) {
- var cbs = newState.fetchCallbacks;
- newState.index = state.index;
- newState.results = state.results;
- newState.fetching = false;
- newState.fetchCallbacks = [];
- newState.finished = state.finished;
- newState.fetcher = state.fetcher.clone(wantAll);
- for(var i = 0; i < cbs.length; ++i)
- cbs[i](err);
- });
- }
- else {
- newState.fetcher = state.fetcher.clone(wantAll);
- }
-
- return newState;
-}
-
-function nextImpl(state, cb) {
- if(state.finished)
- cb();
- else if(state.results && (state.index + 1) < state.results.length)
- cb(null, state.results[++state.index]);
- else {
- fetch(state, function(err) {
- if(err)
- cb(err);
- else if(state.finished)
- cb();
- else
- nextImpl(state, cb);
- });
- }
-}
-
-LazyIterator.prototype.next = function(cb) {
- var itr = this;
- return future.create(function(futureCb) {
- if(!itr.stateForNext)
- itr.stateForNext = copyState(itr.startState);
-
- nextImpl(itr.stateForNext, futureCb);
- }, cb);
-};
-
-LazyIterator.prototype.forEach = function(func, cb) {
- var itr = this;
- return future.create(function(futureCb) {
- var state = copyState(itr.startState);
-
- fdbUtil.whileLoop(function(loopCb) {
- nextImpl(state, function(err, res) {
- if(err || !res)
- loopCb(err, null);
- else
- func(res, loopCb);
- });
- }, futureCb);
-
- }, cb);
-};
-
-function forEachBatchImpl(state, func, cb) {
- function loopBody(loopCb) {
- function processBatch(err) {
- if(err || state.finished)
- loopCb(err, null);
- else {
- state.index = state.results.length;
- func(state.results, loopCb);
- }
- }
-
- if(!state.results || state.index === state.results.length)
- fetch(state, processBatch);
- else
- processBatch();
- }
-
- fdbUtil.whileLoop(loopBody, cb);
-}
-
-LazyIterator.prototype.forEachBatch = function(func, cb) {
- var itr = this;
- return future.create(function(futureCb) {
- forEachBatchImpl(copyState(itr.startState), func, futureCb);
- }, cb);
-};
-
-LazyIterator.prototype.toArray = function(cb) {
- var itr = this;
- return future.create(function(futureCb) {
- var state = copyState(itr.startState, true);
- var result = [];
-
- forEachBatchImpl(state, function(arr, itrCb) {
- result = result.concat(arr);
- itrCb();
- }, function(err, res) {
- if(err)
- futureCb(err);
- else
- futureCb(null, result);
- });
- }, cb);
-};
-
-module.exports = LazyIterator;
diff --git a/bindings/nodejs/lib/locality.js b/bindings/nodejs/lib/locality.js
deleted file mode 100644
index e7ca31d700..0000000000
--- a/bindings/nodejs/lib/locality.js
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * locality.js
- *
- * This source file is part of the FoundationDB open source project
- *
- * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
- *
- * Licensed 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";
-
-var buffer = require('./bufferConversion');
-var transactional = require('./retryDecorator');
-var Database = require('./database');
-var LazyIterator = require('./lazyIterator');
-var fdb = require('./fdbModule');
-var fdbUtil = require('./fdbUtil');
-
-var KEY_SERVERS_PREFIX = buffer.fromByteLiteral('\xff/keyServers/');
-var PAST_VERSION_ERROR_CODE = 1007;
-
-function getBoundaryKeysImpl(tr, begin, end, callback) {
- function BoundaryFetcher(wantAll) {
- this.tr = tr;
- this.begin = begin;
- this.end = end;
- this.lastBegin = undefined;
-
- var fetcher = this;
-
- if(wantAll)
- this.streamingMode = fdb.streamingMode.wantAll;
- else
- this.streamingMode = fdb.streamingMode.iterator;
-
- function iteratorCb(err, res) {
- if(err) {
- if(err.code === PAST_VERSION_ERROR_CODE && fetcher.begin !== fetcher.lastBegin) {
- fetcher.tr = fetcher.tr.db.createTransaction();
- readKeys();
- }
- else {
- fetcher.tr.onError(err, function(e) {
- if(e)
- fetcher.fetchCb(e);
- else
- readKeys();
- });
- }
- }
- else
- fetcher.fetchCb();
- }
-
- function readKeys() {
- fetcher.lastBegin = fetcher.begin;
- fetcher.tr.options.setReadSystemKeys();
- fetcher.tr.options.setLockAware();
- fetcher.tr.snapshot.getRange(fetcher.begin, fetcher.end, {streamingMode: fetcher.streamingMode}).forEachBatch(function(kvs, innerCb) {
- fetcher.forEachCb = innerCb;
- var keys = kvs.map(function(kv) { return kv.key.slice(13); });
- var last = kvs[kvs.length-1].key;
- fetcher.begin = Buffer.concat([last, buffer.fromByteLiteral('\x00')], last.length + 1);
- fetcher.fetchCb(undefined, keys);
- }, iteratorCb);
-
- fetcher.streamingMode = fdb.streamingMode.wantAll;
- }
-
- this.fetch = function(cb) {
- this.fetchCb = cb;
- if(this.read)
- this.forEachCb();
- else {
- this.read = true;
- readKeys();
- }
- };
-
- this.clone = function(wantAll) {
- var clone = new BoundaryFetcher(wantAll);
-
- clone.tr = this.tr.db.createTransaction();
- clone.begin = this.begin;
- clone.end = this.end;
- clone.lastBegin = this.lastBegin;
-
- return clone;
- };
- }
-
- callback(null, new LazyIterator(BoundaryFetcher));
-}
-
-function getBoundaryKeys(databaseOrTransaction, begin, end, callback) {
- begin = fdbUtil.keyToBuffer(begin);
- end = fdbUtil.keyToBuffer(end);
-
- begin = Buffer.concat([KEY_SERVERS_PREFIX, begin], KEY_SERVERS_PREFIX.length + begin.length);
- end = Buffer.concat([KEY_SERVERS_PREFIX, end], KEY_SERVERS_PREFIX.length + end.length);
-
- if(databaseOrTransaction instanceof Database) {
- getBoundaryKeysImpl(databaseOrTransaction.createTransaction(), begin, end, callback);
- }
- else {
- var tr = databaseOrTransaction.db.createTransaction();
- databaseOrTransaction.getReadVersion(function(err, ver) {
- tr.setReadVersion(ver);
- getBoundaryKeysImpl(tr, begin, end, callback);
- });
- }
-}
-
-var getAddressesForKey = transactional(function (tr, key, cb) {
- key = fdbUtil.keyToBuffer(key);
- tr.tr.getAddressesForKey(key, cb);
-});
-
-module.exports = {getBoundaryKeys: getBoundaryKeys, getAddressesForKey: getAddressesForKey};
diff --git a/bindings/nodejs/lib/rangeIterator.js b/bindings/nodejs/lib/rangeIterator.js
deleted file mode 100644
index 15e8723ef9..0000000000
--- a/bindings/nodejs/lib/rangeIterator.js
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * rangeIterator.js
- *
- * This source file is part of the FoundationDB open source project
- *
- * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
- *
- * Licensed 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";
-
-var KeySelector = require('./keySelector');
-var Future = require('./future');
-var fdb = require('./fdbModule');
-var LazyIterator = require('./lazyIterator');
-
-function getStreamingMode(requestedMode, limit, wantAll) {
- if(wantAll && requestedMode === fdb.streamingMode.iterator) {
- if(limit)
- return fdb.streamingMode.exact;
- else
- return fdb.streamingMode.wantAll;
- }
-
- return requestedMode;
-}
-
-module.exports = function(tr, start, end, options, snapshot) {
- if(!options)
- options = {};
-
- if(!options.limit)
- options.limit = 0;
- if(!options.reverse)
- options.reverse = false;
- if(!options.streamingMode && options.streamingMode !== 0)
- options.streamingMode = fdb.streamingMode.iterator;
-
- var RangeFetcher = function(wantAll) {
- this.finished = false;
- this.limit = options.limit;
- this.iterStart = start;
- this.iterEnd = end;
- this.iterationCount = 1;
- this.streamingMode = getStreamingMode(options.streamingMode, this.limit, wantAll);
- };
-
- RangeFetcher.prototype.clone = function(wantAll) {
- var clone = new RangeFetcher(wantAll);
-
- clone.finished = this.finished;
- clone.limit = this.limit;
- clone.iterStart = this.iterStart;
- clone.iterEnd = this.iterEnd;
- clone.iterationCount = this.iterationCount;
-
- return clone;
- };
-
- RangeFetcher.prototype.fetch = function(cb) {
- var fetcher = this;
- if(fetcher.finished) {
- cb();
- }
- else {
- tr.getRange(fetcher.iterStart.key, fetcher.iterStart.orEqual, fetcher.iterStart.offset, fetcher.iterEnd.key, fetcher.iterEnd.orEqual, fetcher.iterEnd.offset, fetcher.limit, fetcher.streamingMode, fetcher.iterationCount++, snapshot, options.reverse, function(err, res)
- {
- if(!err) {
- var results = res.array;
- if(results.length > 0) {
- if(!options.reverse)
- fetcher.iterStart = KeySelector.firstGreaterThan(results[results.length-1].key);
- else
- fetcher.iterEnd = KeySelector.firstGreaterOrEqual(results[results.length-1].key);
- }
-
- if(fetcher.limit !== 0) {
- fetcher.limit -= results.length;
- if(fetcher.limit <= 0)
- fetcher.finished = true;
- }
- if(!res.more)
- fetcher.finished = true;
- cb(undefined, results);
- }
- else {
- cb(err);
- }
- });
- }
- };
-
- return new LazyIterator(RangeFetcher);
-};
diff --git a/bindings/nodejs/lib/retryDecorator.js b/bindings/nodejs/lib/retryDecorator.js
deleted file mode 100644
index ffbb8f8ce5..0000000000
--- a/bindings/nodejs/lib/retryDecorator.js
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * retryDecorator.js
- *
- * This source file is part of the FoundationDB open source project
- *
- * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
- *
- * Licensed 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";
-
-var Database = require('./database');
-var Transaction = require('./transaction');
-
-module.exports = function(func) {
- return function(db) {
- var self = this;
-
- if(db instanceof Database) {
- var cb = arguments[func.length - 1];
-
- if(typeof cb !== "undefined" && !(cb instanceof Function))
- throw new TypeError("fdb.transactional function must declare a callback function as last argument");
- else {
- var args = Array.prototype.slice.call(arguments);
- return db.doTransaction(function(tr, innerCb) {
- args[0] = tr;
- args[func.length - 1] = innerCb;
- func.apply(self, args);
- })(cb);
- }
- }
- else if(db instanceof Transaction || db instanceof Transaction.SnapshotTransaction)
- return func.apply(self, arguments);
- else
- throw new TypeError("fdb.transactional function must pass a Database, Transaction, or SnapshotTransaction as first argument");
- };
-};
diff --git a/bindings/nodejs/lib/subspace.js b/bindings/nodejs/lib/subspace.js
deleted file mode 100644
index e6b05942ad..0000000000
--- a/bindings/nodejs/lib/subspace.js
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * subspace.js
- *
- * This source file is part of the FoundationDB open source project
- *
- * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
- *
- * Licensed 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";
-
-var buffer = require('./bufferConversion');
-var fdbUtil = require('./fdbUtil');
-var tuple = require('./tuple');
-
-var Subspace = function(prefixArray, rawPrefix) {
- if(typeof rawPrefix === 'undefined')
- rawPrefix = new Buffer(0);
- if(typeof prefixArray === 'undefined')
- prefixArray = [];
-
- rawPrefix = fdbUtil.keyToBuffer(rawPrefix);
- var packed = tuple.pack(prefixArray);
-
- this.rawPrefix = Buffer.concat([rawPrefix, packed], rawPrefix.length + packed.length);
-};
-
-Subspace.prototype.key = function() {
- return this.rawPrefix;
-};
-
-Subspace.prototype.pack = function(arr) {
- var packed = tuple.pack(arr);
- return Buffer.concat([this.rawPrefix, packed], this.rawPrefix.length + packed.length) ;
-};
-
-Subspace.prototype.unpack = function(key) {
- key = fdbUtil.keyToBuffer(key);
- if(!this.contains(key))
- throw new Error('Cannot unpack key that is not in subspace.');
-
- return tuple.unpack(key.slice(this.rawPrefix.length));
-};
-
-Subspace.prototype.range = function(arr) {
- if(typeof arr === 'undefined')
- arr = [];
-
- var range = tuple.range(arr);
- return {
- begin: Buffer.concat([this.rawPrefix, range.begin], this.rawPrefix.length + range.begin.length),
- end: Buffer.concat([this.rawPrefix, range.end], this.rawPrefix.length + range.end.length)
- };
-};
-
-Subspace.prototype.contains = function(key) {
- key = fdbUtil.keyToBuffer(key);
- return key.length >= this.rawPrefix.length && fdbUtil.buffersEqual(key.slice(0, this.rawPrefix.length), this.rawPrefix);
-};
-
-Subspace.prototype.get = function(item) {
- return this.subspace([item]);
-};
-
-Subspace.prototype.subspace = function(arr) {
- return new Subspace(arr, this.rawPrefix);
-};
-
-Subspace.prototype.asFoundationDBKey = function() {
- return this.key();
-};
-
-module.exports = Subspace;
diff --git a/bindings/nodejs/lib/transaction.js b/bindings/nodejs/lib/transaction.js
deleted file mode 100644
index ecd4ef83e8..0000000000
--- a/bindings/nodejs/lib/transaction.js
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * transaction.js
- *
- * This source file is part of the FoundationDB open source project
- *
- * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
- *
- * Licensed 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";
-
-var future = require('./future');
-var KeySelector = require('./keySelector');
-var rangeIterator = require('./rangeIterator');
-var buffer = require('./bufferConversion');
-var FDBError = require('./error');
-var fdb = require('./fdbModule');
-var fdbUtil = require('./fdbUtil');
-
-function addReadOperations(object, snapshot) {
- object.prototype.get = function(key, cb) {
- var tr = this.tr;
- key = fdbUtil.keyToBuffer(key);
-
- return future.create(function(futureCb) {
- tr.get(key, snapshot, futureCb);
- }, cb);
- };
-
- object.prototype.getKey = function(keySelector, cb) {
- var tr = this.tr;
- return future.create(function(futureCb) {
- tr.getKey(keySelector.key, keySelector.orEqual, keySelector.offset, snapshot, futureCb);
- }, cb);
- };
-
- object.prototype.getRange = function(start, end, options) {
- if(!KeySelector.isKeySelector(start))
- start = KeySelector.firstGreaterOrEqual(start);
- if(!KeySelector.isKeySelector(end))
- end = KeySelector.firstGreaterOrEqual(end);
-
- return rangeIterator(this.tr, start, end, options, snapshot);
- };
-
- object.prototype.getRangeStartsWith = function(prefix, options) {
- prefix = fdbUtil.keyToBuffer(prefix);
- return this.getRange(prefix, fdbUtil.strinc(prefix), options, snapshot);
- };
-
- object.prototype.getReadVersion = function(cb) {
- var tr = this.tr;
- return future.create(function(futureCb) {
- tr.getReadVersion(futureCb, snapshot);
- }, cb);
- };
-}
-
-var atomic = function(tr, op) {
- return function(key, value) { fdb.atomic[op].call(tr, fdbUtil.keyToBuffer(key), fdbUtil.valueToBuffer(value)); };
-};
-
-var Transaction = function(db, tr) {
- this.db = db;
- this.tr = tr;
-
- this.options = tr.options;
- this.snapshot = new Transaction.SnapshotTransaction(tr);
-
- for(var op in fdb.atomic)
- this[op] = atomic(tr, op);
-};
-
-Transaction.SnapshotTransaction = function(tr) {
- this.tr = tr;
-};
-
-addReadOperations(Transaction, false);
-addReadOperations(Transaction.SnapshotTransaction, true);
-
-Transaction.prototype.doTransaction = function(func, cb) {
- var self = this;
- return future.create(function(futureCb) {
- func(self, futureCb);
- }, cb);
-};
-
-Transaction.prototype.set = function(key, value) {
- key = fdbUtil.keyToBuffer(key);
- value = fdbUtil.valueToBuffer(value);
-
- this.tr.set(key, value);
-};
-
-Transaction.prototype.clear = function(key) {
- key = fdbUtil.keyToBuffer(key);
-
- this.tr.clear(key);
-};
-
-Transaction.prototype.clearRange = function(start, end) {
- start = fdbUtil.keyToBuffer(start);
- end = fdbUtil.keyToBuffer(end);
-
- this.tr.clearRange(start, end);
-};
-
-Transaction.prototype.clearRangeStartsWith = function(prefix) {
- prefix = fdbUtil.keyToBuffer(prefix);
- this.clearRange(prefix, fdbUtil.strinc(prefix));
-};
-
-Transaction.prototype.watch = function(key) {
- key = fdbUtil.keyToBuffer(key);
-
- var self = this;
- var watchFuture = future.create(function(futureCb) {
- // 'this' is the future that is being created.
- // We set its cancel method to cancel the watch.
- this._watch = self.tr.watch(key, futureCb);
- this.cancel = function() { this._watch.cancel(); };
- });
-
- return watchFuture;
-};
-
-Transaction.prototype.addReadConflictRange = function(start, end) {
- start = fdbUtil.keyToBuffer(start);
- end = fdbUtil.keyToBuffer(end);
- this.tr.addReadConflictRange(start, end);
-};
-
-Transaction.prototype.addReadConflictKey = function(key) {
- key = fdbUtil.keyToBuffer(key);
- this.tr.addReadConflictRange(key, Buffer.concat([key, buffer.fromByteLiteral('\x00')], key.length + 1));
-};
-
-Transaction.prototype.addWriteConflictRange = function(start, end) {
- start = fdbUtil.keyToBuffer(start);
- end = fdbUtil.keyToBuffer(end);
-
- this.tr.addWriteConflictRange(start, end);
-};
-
-Transaction.prototype.addWriteConflictKey = function(key) {
- key = fdbUtil.keyToBuffer(key);
- this.tr.addWriteConflictRange(key, Buffer.concat([key, buffer.fromByteLiteral('\x00')], key.length + 1));
-};
-
-Transaction.prototype.commit = function(cb) {
- var tr = this.tr;
- return future.create(function(futureCb) {
- tr.commit(futureCb);
- }, cb);
-};
-
-Transaction.prototype.onError = function(fdbError, cb) {
- var tr = this.tr;
- return future.create(function(futureCb) {
- if(fdbError instanceof FDBError)
- tr.onError(fdbError.code, futureCb);
- else
- futureCb(fdbError, null);
- }, cb);
-};
-
-Transaction.prototype.reset = function() {
- this.tr.reset();
-};
-
-Transaction.prototype.setReadVersion = function(version) {
- this.tr.setReadVersion(version);
-};
-
-Transaction.prototype.getCommittedVersion = function() {
- return this.tr.getCommittedVersion();
-};
-
-Transaction.prototype.getVersionstamp = function(cb) {
- var tr = this.tr;
- return future.create(function(futureCb) {
- tr.getVersionstamp(futureCb);
- }, cb);
-};
-
-Transaction.prototype.cancel = function() {
- this.tr.cancel();
-};
-
-module.exports = Transaction;
-
diff --git a/bindings/nodejs/lib/tuple.js b/bindings/nodejs/lib/tuple.js
deleted file mode 100644
index d7b1d25a76..0000000000
--- a/bindings/nodejs/lib/tuple.js
+++ /dev/null
@@ -1,481 +0,0 @@
-/*
- * tuple.js
- *
- * This source file is part of the FoundationDB open source project
- *
- * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
- *
- * Licensed 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";
-
-var assert = require('assert');
-var buffer = require('./bufferConversion');
-var fdbUtil = require('./fdbUtil');
-var fdb = require('./fdbModule');
-var FDBError = require('./error');
-
-var sizeLimits = new Array(8);
-
-function setupSizeLimits() {
- sizeLimits[0] = 1;
- for(var i = 1; i < sizeLimits.length; i++) {
- sizeLimits[i] = sizeLimits[i-1] * 256;
- sizeLimits[i-1] -= 1;
- }
- sizeLimits[7] -= 1;
-}
-
-setupSizeLimits();
-
-var maxInt = Math.pow(2, 53) - 1;
-var minInt = -Math.pow(2, 53);
-
-var nullByte = new Buffer('00', 'hex');
-
-var BYTES_CODE = 0x01;
-var STRING_CODE = 0x02;
-var NESTED_CODE = 0x05;
-var INT_ZERO_CODE = 0x14;
-var POS_INT_END = 0x1d;
-var NEG_INT_END = 0x0b;
-var FLOAT_CODE = 0x20;
-var DOUBLE_CODE = 0x21;
-var FALSE_CODE = 0x26;
-var TRUE_CODE = 0x27;
-var UUID_CODE = 0x30;
-
-function validateData(data, length) {
- if(!(data instanceof Buffer) && !(data instanceof Array)) {
- throw new TypeError('Data for FDB tuple type not array or buffer.');
- } else if(data.length != length) {
- throw new RangeError('Data for FDB tuple type has length ' + data.length + ' instead of expected length ' + length);
- }
-}
-
-// If encoding and sign bit is 1 (negative), flip all of the bits. Otherwise, just flip sign.
-// If decoding and sign bit is 0 (negative), flip all of the bits. Otherwise, just flip sign.
-function adjustFloat(data, start, encode) {
- if((encode && (data[start] & 0x80) === 0x80) || (!encode && (data[start] & 0x80) === 0x00)) {
- for(var i = start; i < data.length; i++) {
- data[i] = data[i] ^ 0xff;
- }
- } else {
- data[start] = data[start] ^ 0x80;
- }
-}
-
-function Float(value) {
- this.value = value;
- this.toBytes = function () {
- if (this.rawData !== undefined) {
- return this.rawData;
- } else {
- var buf = new Buffer(4);
- buf.writeFloatBE(fdb.toFloat(this.value), 0);
- return buf;
- }
- };
-}
-
-Float.fromBytes = function (buf) {
- validateData(buf, 4);
- var f = new Float(buf.readFloatBE(0));
- if(isNaN(f.value)) {
- f.rawData = buf;
- }
- return f;
-}
-
-function Double(value) {
- this.value = value;
- this.toBytes = function () {
- if (this.rawData !== undefined) {
- return this.rawData;
- } else {
- var buf = new Buffer(8);
- buf.writeDoubleBE(this.value, 0);
- return buf;
- }
- };
-}
-
-Double.fromBytes = function (buf) {
- validateData(buf, 8);
- var d = new Double(buf.readDoubleBE(0));
- if(isNaN(d.value)) {
- d.rawData = buf;
- }
- return d;
-}
-
-function UUID(data) {
- if (data.length != 16) {
- // There's a special code for this, so we check it first and throw the error if appropriate.
- throw new FDBError("invalid_uuid_size", 2268);
- }
- validateData(data, 16);
- this.data = new Buffer(data);
-}
-
-function findNullBytes(buf, pos, searchForTerminators) {
- var nullBytes = [];
-
- var found;
- for(pos; pos < buf.length; ++pos) {
- if(searchForTerminators && found && buf[pos] !== 255) {
- break;
- }
-
- found = false;
- if(buf[pos] === 0) {
- found = true;
- nullBytes.push(pos);
- }
- }
-
- if(!found && searchForTerminators) {
- nullBytes.push(buf.length);
- }
-
- return nullBytes;
-}
-
-function encode(item, buf, pos) {
- var encodedString;
- if(typeof item === 'undefined')
- throw new TypeError('Packed element cannot be undefined');
-
- else if(item === null)
- return nullByte;
-
- //byte string or unicode
- else if(Buffer.isBuffer(item) || item instanceof ArrayBuffer || item instanceof Uint8Array || typeof item === 'string') {
- var unicode = typeof item === 'string';
-
- if(unicode) {
- item = new Buffer(item, 'utf8');
- }
- else {
- item = buffer(item);
- }
-
- var nullBytes = findNullBytes(item, 0);
-
- encodedString = new Buffer(2 + item.length + nullBytes.length);
- encodedString[0] = unicode ? STRING_CODE : BYTES_CODE;
-
- var srcPos = 0;
- var targetPos = 1;
- for(var i = 0; i < nullBytes.length; ++i) {
- item.copy(encodedString, targetPos, srcPos, nullBytes[i]+1);
- targetPos += nullBytes[i]+1 - srcPos;
- srcPos = nullBytes[i]+1;
- encodedString[targetPos++] = 255;
- }
-
- item.copy(encodedString, targetPos, srcPos);
- encodedString[encodedString.length-1] = 0;
-
- return encodedString;
- }
-
- //64-bit integer
- else if((typeof item === 'number' || item instanceof Number) && item % 1 === 0) {
- var negative = item < 0;
- var posItem = Math.abs(item);
-
- var length = 0;
- for(; length < sizeLimits.length; ++length) {
- if(posItem <= sizeLimits[length])
- break;
- }
-
- if(item > maxInt || item < minInt)
- throw new RangeError('Cannot pack signed integer larger than 54 bits');
-
- var prefix = negative ? INT_ZERO_CODE - length : INT_ZERO_CODE + length;
-
- var outBuf = new Buffer(length+1);
- outBuf[0] = prefix;
- for(var byteIdx = length-1; byteIdx >= 0; --byteIdx) {
- var b = posItem & 0xff;
- if(negative)
- outBuf[byteIdx+1] = ~b;
- else {
- outBuf[byteIdx+1] = b;
- }
-
- posItem = (posItem - b) / 0x100;
- }
-
- return outBuf;
- }
-
- // Floats
- else if(item instanceof Float) {
- var outBuf = new Buffer(5);
- outBuf[0] = FLOAT_CODE;
- if (isNaN(item.value) && item.rawData !== undefined) {
- item.rawData.copy(outBuf, 1, 0, 4);
- } else {
- outBuf.writeFloatBE(fdb.toFloat(item.value), 1);
- }
- adjustFloat(outBuf, 1, true);
- return outBuf;
- }
-
- // Doubles
- else if(item instanceof Double) {
- var outBuf = new Buffer(9);
- outBuf[0] = DOUBLE_CODE;
- if (isNaN(item.value) && item.rawData !== undefined) {
- item.rawData.copy(outBuf, 1, 0, 8);
- } else {
- outBuf.writeDoubleBE(item.value, 1);
- }
- adjustFloat(outBuf, 1, true);
- return outBuf;
- }
-
- // UUIDs
- else if(item instanceof UUID) {
- var outBuf = new Buffer(17);
- outBuf[0] = UUID_CODE;
- item.data.copy(outBuf, 1);
- return outBuf;
- }
-
- // booleans
- else if(item instanceof Boolean || typeof item === 'boolean') {
- var outBuf = new Buffer(1);
- var boolItem;
- if(item instanceof Boolean) {
- boolItem = item.valueOf();
- } else {
- boolItem = item;
- }
- if(boolItem) {
- outBuf[0] = TRUE_CODE;
- } else {
- outBuf[0] = FALSE_CODE;
- }
- return outBuf;
- }
-
- // nested tuples
- else if(item instanceof Array) {
- var totalLength = 2;
- var outArr = [new Buffer('05', 'hex')];
- for(var i = 0; i < item.length; ++i) {
- if(item[i] === null) {
- outArr.push(new Buffer('00ff', 'hex'));
- totalLength += 2;
- } else {
- outArr.push(encode(item[i]));
- totalLength += outArr[i+1].length;
- }
- }
- outArr.push(new Buffer('00', 'hex'))
- return Buffer.concat(outArr, totalLength);
- }
-
- else
- throw new TypeError('Packed element must either be a string, a buffer, an integer, or null');
-}
-
-function pack(arr) {
- if(!(arr instanceof Array))
- throw new TypeError('fdb.tuple.pack must be called with a single array argument');
-
- var totalLength = 0;
-
- var outArr = [];
- for(var i = 0; i < arr.length; ++i) {
- outArr.push(encode(arr[i]));
- totalLength += outArr[i].length;
- }
-
- return Buffer.concat(outArr, totalLength);
-}
-
-function decodeNumber(buf, offset, bytes) {
- var negative = bytes < 0;
- bytes = Math.abs(bytes);
-
- var num = 0;
- var mult = 1;
- var odd;
- for(var i = bytes-1; i >= 0; --i) {
- var b = buf[offset+i];
- if(negative)
- b = -(~b & 0xff);
-
- if(i == bytes-1)
- odd = b & 0x01;
-
- num += b * mult;
- mult *= 0x100;
- }
-
- if(num > maxInt || num < minInt || (num === minInt && odd))
- throw new RangeError('Cannot unpack signed integers larger than 54 bits');
-
- return num;
-}
-
-function decode(buf, pos, nested) {
- if(typeof nested === 'undefined') nested = false;
-
- var code = buf[pos];
- var value;
-
- if(code === 0) {
- value = null;
- if(nested) {
- pos += 2;
- } else {
- pos++;
- }
- }
- else if(code === BYTES_CODE || code === STRING_CODE) {
- var nullBytes = findNullBytes(buf, pos+1, true);
-
- var start = pos+1;
- var end = nullBytes[nullBytes.length-1];
-
- if(code === STRING_CODE && nullBytes.length === 1) {
- value = buf.toString('utf8', start, end);
- }
- else {
- value = new Buffer(end-start-(nullBytes.length-1));
- var valuePos = 0;
-
- for(var i=0; i < nullBytes.length && start < end; ++i) {
- buf.copy(value, valuePos, start, nullBytes[i]);
- valuePos += nullBytes[i] - start;
- start = nullBytes[i] + 2;
- if(start <= end) {
- value[valuePos++] = 0;
- }
- }
-
- if(code === STRING_CODE)
- value = value.toString('utf8');
- }
-
- pos = end + 1;
- }
- else if(Math.abs(code-INT_ZERO_CODE) <= 7) {
- if(code === INT_ZERO_CODE)
- value = 0;
- else
- value = decodeNumber(buf, pos+1, code-INT_ZERO_CODE);
-
- pos += Math.abs(INT_ZERO_CODE-code) + 1;
- }
- else if(Math.abs(code-INT_ZERO_CODE) <= 8)
- throw new RangeError('Cannot unpack signed integers larger than 54 bits');
- else if(code === FLOAT_CODE) {
- var valBuf = new Buffer(4);
- buf.copy(valBuf, 0, pos+1, pos+5);
- adjustFloat(valBuf, 0, false);
- value = Float.fromBytes(valBuf);
- pos += 5;
- }
- else if(code === DOUBLE_CODE) {
- var valBuf = new Buffer(8);
- buf.copy(valBuf, 0, pos+1, pos+9);
- adjustFloat(valBuf, 0, false);
- value = Double.fromBytes(valBuf);
- pos += 9;
- }
- else if(code === UUID_CODE) {
- var valBuf = new Buffer(16);
- buf.copy(valBuf, 0, pos+1, pos+17);
- value = new UUID(valBuf);
- pos += 17;
- }
- else if(code === FALSE_CODE) {
- pos++;
- value = false;
- }
- else if(code === TRUE_CODE) {
- pos++;
- value = true;
- }
- else if(code === NESTED_CODE) {
- pos++;
- value = []
- while (buf[pos] != 0 || pos+1 < buf.length && buf[pos+1] === 0xff) {
- var nestedVal = decode(buf, pos, true)
- pos = nestedVal.pos
- value.push(nestedVal.value)
- }
- pos++;
- }
- else
- throw new TypeError('Unknown data type in DB: ' + buf + ' at ' + pos);
-
- return { pos: pos, value: value };
-}
-
-function unpack(key) {
- var res = { pos: 0 };
- var arr = [];
-
- key = fdbUtil.keyToBuffer(key);
-
- while(res.pos < key.length) {
- res = decode(key, res.pos);
- arr.push(res.value);
- }
-
- return arr;
-}
-
-function range(arr) {
- var packed = pack(arr);
- return { begin: Buffer.concat([packed, nullByte]), end: Buffer.concat([packed, new Buffer('ff', 'hex')]) };
-}
-
-function compare(arr1, arr2) {
- // NOTE: There is built-in comparison function included in 0.11.13 that we might want to switch to.
- var buf1 = pack(arr1);
- var buf2 = pack(arr2);
- var pos = 0;
-
- while(pos < buf1.length && pos < buf2.length) {
- if(buf1[pos] != buf2[pos]) {
- if(buf1[pos] < buf2[pos]) {
- return -1;
- } else {
- return 1;
- }
- }
- pos += 1;
- }
-
- // The two arrays begin with a common prefix.
- if(buf1.length < buf2.length) {
- return -1;
- } else if(buf1.length == buf2.length) {
- return 0;
- } else {
- return 1;
- }
-}
-
-module.exports = {pack: pack, unpack: unpack, range: range, compare: compare, Float: Float, Double: Double, UUID: UUID};
diff --git a/bindings/nodejs/package.json.in b/bindings/nodejs/package.json.in
deleted file mode 100644
index c30539a3c2..0000000000
--- a/bindings/nodejs/package.json.in
+++ /dev/null
@@ -1,26 +0,0 @@
-{
- "name": "@apple/fdb",
- "publishConfig": {
- "registry": "https://registry.npmjs.org"
- },
- "version": "VERSION",
- "author": "FoundationDB (https://www.foundationdb.org)",
- "description": "Node.js bindings for the FoundationDB database",
- "keywords": [ "FoundationDB", "database", "NoSQL", "ACID" ],
- "homepage": "http://17.199.145.104",
- "license": "Apache v2",
- "main": "./lib/fdb.js",
- "cpu": [ "x64" ],
- "dependencies": {
- "semver": "~ 4.1"
- },
- "devDependencies": {
- "jshint": ">= 2.5.6",
- "promises-aplus-tests": ">= 2.1.0"
- },
- "engineStrict": true,
- "private": true,
- "engines": {
- "node" : "0.8.x || 0.10.x"
- }
-}
diff --git a/bindings/nodejs/src/Cluster.cpp b/bindings/nodejs/src/Cluster.cpp
deleted file mode 100644
index 53c248beb0..0000000000
--- a/bindings/nodejs/src/Cluster.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * Cluster.cpp
- *
- * This source file is part of the FoundationDB open source project
- *
- * Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
- *
- * Licensed 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.
- */
-
-
-#include
-#include
-#include
-#include
-#include
-
-#include "Cluster.h"
-#include "Database.h"
-#include "FdbOptions.h"
-#include "NodeCallback.h"
-
-using namespace v8;
-using namespace std;
-
-Cluster::Cluster() { }
-Cluster::~Cluster() {
- fdb_cluster_destroy(cluster);
-}
-
-Persistent Cluster::constructor;
-
-Handle Cluster::OpenDatabase(const Arguments &args) {
- HandleScope scope;
-
- Cluster *clusterPtr = ObjectWrap::Unwrap(args.Holder());
-
- const char *dbName = "DB";
- FDBFuture *f = fdb_cluster_create_database(clusterPtr->cluster, (uint8_t*)dbName, (int)strlen(dbName));
-
- fdb_error_t errorCode = fdb_future_block_until_ready(f);
-
- FDBDatabase *database;
- if(errorCode == 0)
- errorCode = fdb_future_get_database(f, &database);
-
- if(errorCode != 0)
- return ThrowException(FdbError::NewInstance(errorCode, fdb_get_error(errorCode)));
-
- Handle jsValue = Database::NewInstance(database);
- return scope.Close(jsValue);
-}
-
-void Cluster::Init() {
- HandleScope scope;
-
- Local tpl = FunctionTemplate::New(New);
- tpl->InstanceTemplate()->SetInternalFieldCount(1);
- tpl->SetClassName(String::NewSymbol("Cluster"));
-
- tpl->PrototypeTemplate()->Set(String::NewSymbol("openDatabase"), FunctionTemplate::New(OpenDatabase)->GetFunction());
-
- constructor = Persistent::New(tpl->GetFunction());
-}
-
-Handle Cluster::New(const Arguments &args) {
- HandleScope scope;
-
- Cluster *c = new Cluster();
- c->Wrap(args.Holder());
-
- return scope.Close(args.Holder());
-}
-
-Handle Cluster::NewInstance(FDBCluster *ptr) {
- HandleScope scope;
-
- Local