Skip to content

Commit 9b1bb72

Browse files
new files
1 parent 3266053 commit 9b1bb72

File tree

9 files changed

+582
-0
lines changed

9 files changed

+582
-0
lines changed

.clang-format

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
BasedOnStyle: Google
2+
AllowShortFunctionsOnASingleLine: Empty
3+
AllowShortIfStatementsOnASingleLine: false
4+
AllowShortLoopsOnASingleLine: false
5+
BinPackArguments: false
6+
BinPackParameters: false
7+
ColumnLimit: 100
8+
Cpp11BracedListStyle: true
9+
DerivePointerAlignment: false
10+
IndentWidth: 4
11+
MaxEmptyLinesToKeep: 1
12+
NamespaceIndentation: None
13+
SpaceBeforeAssignmentOperators: true
14+
Standard: Cpp11
15+
UseTab: Never

.eslintrc.json

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"root": true,
3+
"extends": [
4+
"eslint:recommended",
5+
"plugin:prettier/recommended",
6+
"plugin:@typescript-eslint/eslint-recommended",
7+
"plugin:@typescript-eslint/recommended"
8+
],
9+
"ignorePatterns": "lib/**/*",
10+
"env": {
11+
"node": true,
12+
"mocha": true,
13+
"es6": true
14+
},
15+
"parserOptions": {
16+
"ecmaVersion": 2019
17+
},
18+
"plugins": [
19+
"@typescript-eslint",
20+
"prettier"
21+
],
22+
"rules": {
23+
"no-restricted-properties": [
24+
"error",
25+
{
26+
"object": "describe",
27+
"property": "only"
28+
},
29+
{
30+
"object": "it",
31+
"property": "only"
32+
},
33+
{
34+
"object": "context",
35+
"property": "only"
36+
}
37+
],
38+
"prettier/prettier": "error",
39+
"no-console": "error",
40+
"valid-typeof": "error",
41+
"eqeqeq": [
42+
"error",
43+
"always",
44+
{
45+
"null": "ignore"
46+
}
47+
],
48+
"strict": [
49+
"error",
50+
"global"
51+
],
52+
"no-restricted-syntax": [
53+
"error",
54+
{
55+
"selector": "TSEnumDeclaration",
56+
"message": "Do not declare enums"
57+
},
58+
{
59+
"selector": "BinaryExpression[operator=/[=!]==/] Identifier[name='undefined']",
60+
"message": "Do not strictly check undefined"
61+
},
62+
{
63+
"selector": "BinaryExpression[operator=/[=!]==/] Literal[raw='null']",
64+
"message": "Do not strictly check null"
65+
},
66+
{
67+
"selector": "BinaryExpression[operator=/[=!]==?/] Literal[value='undefined']",
68+
"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)"
69+
}
70+
],
71+
"@typescript-eslint/no-require-imports": "off"
72+
},
73+
"overrides": [
74+
{
75+
"files": [
76+
"test/**/*ts"
77+
],
78+
"rules": {
79+
// chat `expect(..)` style chaining is considered
80+
// an unused expression
81+
"@typescript-eslint/no-unused-expressions": "off"
82+
}
83+
}
84+
]
85+
}

.github/workflows/test.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
on:
2+
push:
3+
branches: [main]
4+
pull_request:
5+
branches: [main]
6+
workflow_dispatch: {}
7+
8+
name: Test
9+
10+
jobs:
11+
host_tests:
12+
strategy:
13+
matrix:
14+
os: [macos-latest, windows-2019]
15+
node: [16.x, 18.x, 20.x, 22.x]
16+
runs-on: ${{ matrix.os }}
17+
steps:
18+
- uses: actions/checkout@v4
19+
20+
- uses: actions/setup-node@v4
21+
with:
22+
node-version: ${{ matrix.node }}
23+
cache: 'npm'
24+
registry-url: 'https://registry.npmjs.org'
25+
26+
- name: Build with Node.js ${{ matrix.node }} on ${{ matrix.os }}
27+
run: npm install && npm run compile
28+
shell: bash
29+
30+
- name: Test ${{ matrix.os }}
31+
shell: bash
32+
run: npm test
33+
34+
# container_tests:
35+
# runs-on: ubuntu-latest
36+
# strategy:
37+
# matrix:
38+
# linux_arch: [s390x, arm64, amd64]
39+
# node: [16.x, 18.x, 20.x, 22.x]
40+
# steps:
41+
# - uses: actions/checkout@v4
42+
43+
# - uses: actions/setup-node@v4
44+
# with:
45+
# node-version: ${{ matrix.node }}
46+
47+
# - name: Get Full Node.js Version
48+
# id: get_nodejs_version
49+
# shell: bash
50+
# run: |
51+
# echo "version=$(node --print 'process.version.slice(1)')" >> "$GITHUB_OUTPUT"
52+
# echo "ubuntu_version=$(node --print '(+process.version.slice(1).split(`.`).at(0)) > 16 ? `noble` : `bionic`')" >> "$GITHUB_OUTPUT"
53+
54+
# - name: Set up QEMU
55+
# uses: docker/setup-qemu-action@v3
56+
57+
# - name: Set up Docker Buildx
58+
# uses: docker/setup-buildx-action@v3
59+
60+
# - name: Run Buildx
61+
# run: |
62+
# docker buildx create --name builder --bootstrap --use
63+
# docker buildx build \
64+
# --platform linux/${{ matrix.linux_arch }} \
65+
# --build-arg="NODE_ARCH=${{ matrix.linux_arch == 'amd64' && 'x64' || matrix.linux_arch }}" \
66+
# --build-arg="NODE_VERSION=${{ steps.get_nodejs_version.outputs.version }}" \
67+
# --build-arg="UBUNTU_VERSION=${{ steps.get_nodejs_version.outputs.ubuntu_version }}" \
68+
# --build-arg="RUN_TEST=true" \
69+
# --output type=local,dest=./prebuilds,platform-split=false \
70+
# -f ./.github/docker/Dockerfile.glibc \
71+
# .

.mocharc.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/mocharc.json",
3+
"require": [
4+
"source-map-support/register",
5+
"test/tools/chai-addons.js"
6+
],
7+
"extension": [
8+
"ts"
9+
],
10+
"recursive": true,
11+
"failZero": true,
12+
"reporter": "test/tools/mongodb_reporter.js",
13+
"color": true
14+
}

.prettierrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"singleQuote": true,
3+
"tabWidth": 2,
4+
"printWidth": 100,
5+
"arrowParens": "avoid",
6+
"trailingComma": "none"
7+
}

binding.gyp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
'targets': [{
3+
'target_name': 'zstd',
4+
'type': 'loadable_module',
5+
'defines': ['ZSTD_STATIC_LINKING_ONLY'],
6+
'include_dirs': [
7+
"<!(node -p \"require('node-addon-api').include_dir\")"
8+
],
9+
'variables': {
10+
'ARCH': '<(host_arch)',
11+
'libmongocrypt_link_type%': 'static',
12+
'mongocrypt_avoid_openssl_crypto%': 'false',
13+
'built_with_electron%': 0
14+
},
15+
'sources': [
16+
'src/addon.cpp'
17+
],
18+
'xcode_settings': {
19+
'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
20+
'CLANG_CXX_LIBRARY': 'libc++',
21+
'MACOSX_DEPLOYMENT_TARGET': '10.12',
22+
'GCC_SYMBOLS_PRIVATE_EXTERN': 'YES', # -fvisibility=hidden
23+
},
24+
'cflags!': [ '-fno-exceptions' ],
25+
'cflags_cc!': [ '-fno-exceptions' ],
26+
'cflags_cc': [ '-std=c++17' ],
27+
'msvs_settings': {
28+
'VCCLCompilerTool': { 'ExceptionHandling': 1 },
29+
}
30+
}]
31+
}

src/addon.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <napi.h>
2+
3+
using namespace Napi;
4+
5+
Napi::String Compress(const Napi::CallbackInfo& info) {
6+
auto string = Napi::String::New(info.Env(), "compress()");
7+
return string;
8+
}
9+
Napi::String Decompress(const Napi::CallbackInfo& info) {
10+
auto string = Napi::String::New(info.Env(), "decompress()");
11+
return string;
12+
}
13+
14+
Napi::Object Init(Napi::Env env, Napi::Object exports) {
15+
exports.Set(Napi::String::New(env, "compress"), Napi::Function::New(env, Compress));
16+
exports.Set(Napi::String::New(env, "decompress"), Napi::Function::New(env, Decompress));
17+
return exports;
18+
}
19+
20+
NODE_API_MODULE(hello, Init)

test/tools/chai-addons.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/* eslint-disable @typescript-eslint/no-var-requires */
2+
/* eslint-disable strict */
3+
4+
'use strict';
5+
// configure chai
6+
const chai = require('chai');
7+
chai.use(require('sinon-chai'));
8+
chai.use(require('chai-subset'));
9+
10+
chai.config.truncateThreshold = 0;

0 commit comments

Comments
 (0)