Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ functions:
DISTRO_ID: ${distro_id}
BUILD_VARIANT: ${build_variant}

"attach node xunit results":
- command: attach.xunit_results
params:
file: ./libmongocrypt/bindings/node/xunit.xml

"publish snapshot":
- command: shell.exec
params:
Expand Down Expand Up @@ -398,6 +403,7 @@ tasks:
commands:
- func: "fetch source"
- func: "build and test node"
- func: "attach node xunit results"

# Note: keep this disabled unless you want master to force-push
- name: build-and-test-node-force-publish
Expand All @@ -407,6 +413,7 @@ tasks:
commands:
- func: "fetch source"
- func: "build and test node"
- func: "attach node xunit results"

- name: publish-snapshot
depends_on:
Expand Down Expand Up @@ -1068,4 +1075,3 @@ buildvariants:
run_on: macos-1100-arm64
tasks:
- build-and-test-and-upload

30 changes: 0 additions & 30 deletions bindings/node/.eslintrc

This file was deleted.

71 changes: 71 additions & 0 deletions bindings/node/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"root": true,
"extends": [
"eslint:recommended",
"plugin:prettier/recommended"
],
"env": {
"node": true,
"mocha": true,
"es6": true
},
"parserOptions": {
"ecmaVersion": 2019
},
"plugins": [
"prettier"
],
"rules": {
"no-restricted-properties": [
"error",
{
"object": "describe",
"property": "only"
},
{
"object": "it",
"property": "only"
},
{
"object": "context",
"property": "only"
}
],
"prettier/prettier": "error",
"no-console": "error",
"valid-typeof": "error",
"eqeqeq": ["error", "always", {"null": "ignore"}],
"strict": ["error", "global"],
"no-restricted-syntax": [
"error",
{
"selector": "TSEnumDeclaration",
"message": "Do not declare enums"
},
{
"selector": "BinaryExpression[operator=/[=!]==/] Identifier[name='undefined']",
"message": "Do not strictly check undefined"
},
{
"selector": "BinaryExpression[operator=/[=!]==/] Literal[raw='null']",
"message": "Do not strictly check null"
},
{
"selector": "BinaryExpression[operator=/[=!]==?/] Literal[value='undefined']",
"message": "Do not strictly check typeof undefined (NOTE: currently this rule only detects the usage of 'undefined' string literal so this could be a misfire)"
}
]
},
"overrides": [
{
// Settings for javascript test files
"files": [
"test/**/*.js"
],
"rules": {
"no-console": "off",
"no-restricted-syntax": "off"
}
}
]
}
2 changes: 1 addition & 1 deletion bindings/node/.evergreen/find_cmake.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash -x
#!/usr/bin/env bash

# Copied from the mongo-c-driver
find_cmake ()
Expand Down
28 changes: 20 additions & 8 deletions bindings/node/.evergreen/setup_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
set -o xtrace # Write all commands first to stderr
set -o errexit # Exit the script with error if any of the commands fail

NODE_VERSION=14
NODE_BINDINGS_PATH="${PROJECT_DIRECTORY}/bindings/node"
NODE_ARTIFACTS_PATH="${NODE_BINDINGS_PATH}/node-artifacts"
NPM_CACHE_DIR="${NODE_ARTIFACTS_PATH}/npm"
NPM_TMP_DIR="${NODE_ARTIFACTS_PATH}/tmp"
BIN_DIR="$(pwd)/bin"
NVM_WINDOWS_URL="https://github.com/coreybutler/nvm-windows/releases/download/1.1.7/nvm-noinstall.zip"
NVM_URL="https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh"
NVM_WINDOWS_URL="https://github.com/coreybutler/nvm-windows/releases/download/1.1.9/nvm-noinstall.zip"
NVM_URL="https://raw.githubusercontent.com/creationix/nvm/v0.38.0/install.sh"

# create node artifacts path if needed
mkdir -p ${NODE_ARTIFACTS_PATH}
Expand All @@ -37,6 +36,8 @@ mkdir -p ${NVM_DIR}
# install Node.js
echo "Installing Node ${NODE_LTS_NAME}"
if [ "$OS" == "Windows_NT" ]; then
set +o xtrace

export NVM_HOME=`cygpath -w "$NVM_DIR"`
export NVM_SYMLINK=`cygpath -w "$NODE_ARTIFACTS_PATH/bin"`
export PATH=`cygpath $NVM_SYMLINK`:`cygpath $NVM_HOME`:$PATH
Expand All @@ -54,14 +55,26 @@ root: $NVM_HOME
path: $NVM_SYMLINK
EOT

nvm install $NODE_VERSION
nvm use $NODE_VERSION
echo "Running: nvm install lts"
nvm install lts
echo "Running: nvm use lts"
nvm use lts
echo "Running: npm install -g npm@8.3.1"
npm install -g npm@8.3.1 # https://github.com/npm/cli/issues/4341
set -o xtrace
else
set +o xtrace

echo " Downloading nvm"
curl -o- $NVM_URL | bash
[ -s "${NVM_DIR}/nvm.sh" ] && \. "${NVM_DIR}/nvm.sh"

nvm install $NODE_VERSION
nvm use $NODE_VERSION
echo "Running: nvm install --lts --latest-npm"
nvm install --lts --latest-npm
echo "Running: nvm use --lts"
nvm use --lts

set -o xtrace
fi

# setup npm cache in a local directory
Expand All @@ -71,4 +84,3 @@ init-module=${NPM_CACHE_DIR}/.npm-init.js
cache=${NPM_CACHE_DIR}
tmp=${NPM_TMP_DIR}
EOT

1 change: 1 addition & 0 deletions bindings/node/.evergreen/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ echo "Installing package dependencies (includes a static build)"

# Run tests
echo "Running tests"
npm run check:lint
MONGODB_NODE_SKIP_LIVE_TESTS=true npm test

# Run prebuild and deploy
Expand Down
2 changes: 2 additions & 0 deletions bindings/node/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ npm-debug.log
.vscode
deps
*.tgz

xunit.xml
8 changes: 8 additions & 0 deletions bindings/node/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/mocharc.json",
"recursive": true,
"failZero": true,
"reporter": "test/tools/mongodb_reporter.js",
"sort": true,
"color": true
}
7 changes: 7 additions & 0 deletions bindings/node/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"singleQuote": true,
"tabWidth": 2,
"printWidth": 100,
"arrowParens": "avoid",
"trailingComma": "none"
}
1 change: 1 addition & 0 deletions bindings/node/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ The public interface for explicit client side encryption
| client | <code>MongoClient</code> | The client used for encryption |
| options | <code>object</code> | Additional settings |
| options.keyVaultNamespace | <code>string</code> | The namespace of the key vault, used to store encryption keys |
| options.tlsOptions | <code>object</code> | An object that maps KMS provider names to TLS options. |
| [options.keyVaultClient] | <code>MongoClient</code> | A `MongoClient` used to fetch keys from a key vault. Defaults to `client` |
| [options.kmsProviders] | [<code>KMSProviders</code>](#KMSProviders) | options for specific KMS providers to use |

Expand Down
2 changes: 1 addition & 1 deletion bindings/node/lib/autoEncrypter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

module.exports = function(modules) {
module.exports = function (modules) {
const mc = require('bindings')('mongocrypt');
const common = require('./common');
const databaseNamespace = common.databaseNamespace;
Expand Down
115 changes: 115 additions & 0 deletions bindings/node/lib/buffer_pool.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
'use strict';

/** @internal */
const kBuffers = Symbol('buffers');
/** @internal */
const kLength = Symbol('length');

/**
* A pool of Buffers which allow you to read them as if they were one
* @internal
*/
class BufferPool {
// [kBuffers]: Buffer[];
// [kLength]: number;

constructor() {
this[kBuffers] = [];
this[kLength] = 0;
}

get length() {
return this[kLength];
}

/**
* Adds a buffer to the internal buffer pool list
* @param {Buffer} buffer - buffer to append to the pool
* @returns {void}
*/
append(buffer) {
this[kBuffers].push(buffer);
this[kLength] += buffer.length;
}

/**
* Returns the requested number of bytes without consuming them
* @param {number} size - the number of bytes to return from the head of the pool
* @returns {Buffer}
*/
peek(size) {
return this.read(size, false);
}

/**
* Reads the requested number of bytes, optionally consuming them
* @param {number} size - the number of bytes to return from the head of the pool
* @param {boolean} [consume] - whether the bytes returned should be removed, defaults to true
* @returns {Buffer}
*/
read(size, consume = true) {
if (typeof size !== 'number' || size < 0) {
throw new Error('Argument "size" must be a non-negative number');
}

if (size > this[kLength]) {
return Buffer.alloc(0);
}

let result;

// read the whole buffer
if (size === this.length) {
result = Buffer.concat(this[kBuffers]);

if (consume) {
this[kBuffers] = [];
this[kLength] = 0;
}
}

// size is within first buffer, no need to concat
else if (size <= this[kBuffers][0].length) {
result = this[kBuffers][0].slice(0, size);
if (consume) {
this[kBuffers][0] = this[kBuffers][0].slice(size);
this[kLength] -= size;
}
}

// size is beyond first buffer, need to track and copy
else {
result = Buffer.allocUnsafe(size);

let idx;
let offset = 0;
let bytesToCopy = size;
for (idx = 0; idx < this[kBuffers].length; ++idx) {
let bytesCopied;
if (bytesToCopy > this[kBuffers][idx].length) {
bytesCopied = this[kBuffers][idx].copy(result, offset, 0);
offset += bytesCopied;
} else {
bytesCopied = this[kBuffers][idx].copy(result, offset, 0, bytesToCopy);
if (consume) {
this[kBuffers][idx] = this[kBuffers][idx].slice(bytesCopied);
}
offset += bytesCopied;
break;
}

bytesToCopy -= bytesCopied;
}

// compact the internal buffer array
if (consume) {
this[kBuffers] = this[kBuffers].slice(idx);
this[kLength] -= size;
}
}

return result;
}
}

module.exports = { BufferPool };
4 changes: 2 additions & 2 deletions bindings/node/lib/clientEncryption.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

module.exports = function(modules) {
module.exports = function (modules) {
const mc = require('bindings')('mongocrypt');
const common = require('./common');
const databaseNamespace = common.databaseNamespace;
Expand Down Expand Up @@ -172,7 +172,7 @@ module.exports = function(modules) {
callback = options;
options = {};
}
if (typeof options === 'undefined') {
if (options == null) {
options = {};
}

Expand Down
Loading