Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(binding/node.js): basic IO #1416

Merged
merged 20 commits into from
Mar 3, 2023
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
58 changes: 58 additions & 0 deletions .github/workflows/bindings_nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright 2022 Datafuse Labs
#
# 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.

name: Binding NodeJS CI
env:
DEBUG: napi:*
APP_NAME: opendal
MACOSX_DEPLOYMENT_TARGET: '10.13'

on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:

jobs:
test:
name: Test bindings on Linux-x64-gnu - node@${{ matrix.node }}
strategy:
fail-fast: false
matrix:
node:
- '18'
runs-on: ubuntu-latest

# Notes: this defaults only apply on run tasks.
defaults:
run:
working-directory: "bindings/nodejs"

steps:
- uses: actions/checkout@v3
- name: Setup node
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node }}
cache: yarn
cache-dependency-path: "bindings/nodejs/yarn.lock"
- name: Install dependencies
run: yarn install
- name: Build
run: yarn build
- name: Test bindings
run: yarn test
17 changes: 17 additions & 0 deletions bindings/nodejs/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2022 Datafuse Labs
#
# 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.

[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-musl-gcc"
rustflags = ["-C", "target-feature=-crt-static"]
196 changes: 193 additions & 3 deletions bindings/nodejs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,197 @@
/target
# Created by https://www.toptal.com/developers/gitignore/api/node
# Edit at https://www.toptal.com/developers/gitignore?templates=node

*.node
### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

Cargo.lock
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Stores VSCode versions used for testing VSCode extensions
.vscode-test

# End of https://www.toptal.com/developers/gitignore/api/node

# Created by https://www.toptal.com/developers/gitignore/api/macos
# Edit at https://www.toptal.com/developers/gitignore?templates=macos

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

# End of https://www.toptal.com/developers/gitignore/api/macos

# Created by https://www.toptal.com/developers/gitignore/api/windows
# Edit at https://www.toptal.com/developers/gitignore?templates=windows

### Windows ###
# Windows thumbnail cache files
Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db

# Dump file
*.stackdump

# Folder config file
[Dd]esktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.toptal.com/developers/gitignore/api/windows

#Added by cargo

/target
Cargo.lock

.pnp.*
.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

*.node
3 changes: 3 additions & 0 deletions bindings/nodejs/.npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ npm
rustfmt.toml
yarn.lock
*.node
.yarn
__test__
renovate.json
873 changes: 873 additions & 0 deletions bindings/nodejs/.yarn/releases/yarn-3.4.1.cjs

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions bindings/nodejs/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2022 Datafuse Labs
#
# 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.

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-3.4.1.cjs
17 changes: 12 additions & 5 deletions bindings/nodejs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,25 @@
# See the License for the specific language governing permissions and
# limitations under the License.


[package]
edition = "2021"
name = "opendal-nodejs"
version = "0.0.1"
name = "opendal"
version = "0.0.0"

[lib]
crate-type = ["cdylib"]

[dependencies]
napi = "2"
napi-derive = "2"
opendal = { version = "0.29", path = "../../" }
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
napi = { version = "2.11.2", default-features = false, features = ["napi4", "async"] }
napi-derive = "2.11.1"
opendal = { version = "0.29", path = "../../"}
chrono = "0.4.23"
futures = "0.3.26"

[build-dependencies]
napi-build = "2"

[profile.release]
lto = true
2 changes: 1 addition & 1 deletion bindings/nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
## Build

```shell
pnpm run build:debug
yarn run build:debug
suyanhanx marked this conversation as resolved.
Show resolved Hide resolved
```
34 changes: 34 additions & 0 deletions bindings/nodejs/__test__/index.spec.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2022 Datafuse Labs
//
// 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.


import test from 'ava'

import { OperatorFactory } from '../index.js'

test('test memory write & read', async (t) => {
let op = OperatorFactory.memory()
suyanhanx marked this conversation as resolved.
Show resolved Hide resolved
let content = "hello world"
let path = 'test'

await op.write(path, Array.from(new TextEncoder().encode(content)))

let meta = await op.meta(path)
t.is(meta.size, content.length)

let res = await op.read(path)
t.is(content, new TextDecoder().decode(Buffer.from(res)))

await op.delete(path)
})
2 changes: 1 addition & 1 deletion bindings/nodejs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
extern crate napi_build;

fn main() {
napi_build::setup();
napi_build::setup();
}
Loading