-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Anna Henningsen <[email protected]>
- Loading branch information
Showing
27 changed files
with
6,558 additions
and
4,898 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 () | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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} | ||
|
@@ -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 | ||
|
@@ -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 [email protected]" | ||
npm install -g [email protected] # 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 | ||
|
@@ -71,4 +84,3 @@ init-module=${NPM_CACHE_DIR}/.npm-init.js | |
cache=${NPM_CACHE_DIR} | ||
tmp=${NPM_TMP_DIR} | ||
EOT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,3 +18,5 @@ npm-debug.log | |
.vscode | ||
deps | ||
*.tgz | ||
|
||
xunit.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"printWidth": 100, | ||
"arrowParens": "avoid", | ||
"trailingComma": "none" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.