feat: init nodejs bindgen

This commit is contained in:
leeeon233 2023-02-07 10:24:25 +08:00 committed by Leonzhao
parent 1002c9cca5
commit 5b6f864479
44 changed files with 2027 additions and 0 deletions

View file

@ -8,6 +8,7 @@
"heapless",
"Leeeon",
"LOGSTORE",
"napi",
"nextest",
"Peritext",
"RUSTFLAGS",

101
Cargo.lock generated
View file

@ -23,6 +23,15 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aho-corasick"
version = "0.7.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
dependencies = [
"memchr",
]
[[package]]
name = "aliasable"
version = "0.1.3"
@ -280,6 +289,15 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "convert_case"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "cpufeatures"
version = "0.2.5"
@ -697,6 +715,16 @@ version = "0.2.139"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79"
[[package]]
name = "libloading"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f"
dependencies = [
"cfg-if",
"winapi",
]
[[package]]
name = "lock_api"
version = "0.4.9"
@ -780,6 +808,16 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "loro-nodejs"
version = "0.0.0"
dependencies = [
"loro-internal",
"napi",
"napi-build",
"napi-derive",
]
[[package]]
name = "loro-wasm"
version = "0.1.0"
@ -836,6 +874,61 @@ dependencies = [
"sys-info",
]
[[package]]
name = "napi"
version = "2.10.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b34c348aab5ea879c3642a5cb149870a376ef7aedf98c96fb1f9aa8a82f3c6c0"
dependencies = [
"bitflags",
"ctor",
"napi-sys",
"once_cell",
"thread_local",
]
[[package]]
name = "napi-build"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "882a73d9ef23e8dc2ebbffb6a6ae2ef467c0f18ac10711e4cc59c5485d41df0e"
[[package]]
name = "napi-derive"
version = "2.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f73dd4ddd118bd87756c72fead4c727dc4ee6ba3af3cd98d8490eb09b5a8573"
dependencies = [
"convert_case",
"napi-derive-backend",
"proc-macro2 1.0.49",
"quote 1.0.23",
"syn 1.0.107",
]
[[package]]
name = "napi-derive-backend"
version = "1.0.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57e4e6bb1ee73ec3938a8dfd2ce81955954b8e48c3a40c839918a9735feb0d61"
dependencies = [
"convert_case",
"once_cell",
"proc-macro2 1.0.49",
"quote 1.0.23",
"regex",
"syn 1.0.107",
]
[[package]]
name = "napi-sys"
version = "2.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "166b5ef52a3ab5575047a9fe8d4a030cdd0f63c96f071cd6907674453b07bae3"
dependencies = [
"libloading",
]
[[package]]
name = "new_debug_unreachable"
version = "1.0.4"
@ -1334,6 +1427,8 @@ version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
@ -1822,6 +1917,12 @@ version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc"
[[package]]
name = "unicode-segmentation"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36"
[[package]]
name = "unicode-width"
version = "0.1.10"

View file

@ -0,0 +1,3 @@
[target.aarch64-unknown-linux-musl]
linker = "aarch64-linux-musl-gcc"
rustflags = ["-C", "target-feature=-crt-static"]

197
crates/loro-nodejs/.gitignore vendored Normal file
View file

@ -0,0 +1,197 @@
# Created by https://www.toptal.com/developers/gitignore/api/node
# Edit at https://www.toptal.com/developers/gitignore?templates=node
### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
# 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

View file

@ -0,0 +1,13 @@
target
Cargo.lock
.cargo
.github
npm
.eslintrc
.prettierignore
rustfmt.toml
yarn.lock
*.node
.yarn
__test__
renovate.json

View file

@ -0,0 +1 @@
nodeLinker: node-modules

View file

@ -0,0 +1,19 @@
[package]
edition = "2021"
name = "loro-nodejs"
version = "0.0.0"
[lib]
crate-type = ["cdylib"]
[dependencies]
loro-internal = { path = "../loro-internal" }
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
napi = { version = "2.10.14", default-features = false, features = ["napi4"] }
napi-derive = "2.10.1"
[build-dependencies]
napi-build = "2.0.1"
[profile.release]
lto = true

View file

@ -0,0 +1,11 @@
# loro-nodejs
A nodejs bindgen for Loro by using `napi`.
```bash
# build
yarn build
# test
yarn test
```

View file

@ -0,0 +1,10 @@
import test from 'ava'
import { Loro } from '../index.js'
test('loro text', (t) => {
const loro = new Loro();
const text = loro.getText("text");
text.insert(loro, 0, "abc");
t.is(text.value(), "abc");
})

View file

@ -0,0 +1,5 @@
extern crate napi_build;
fn main() {
napi_build::setup();
}

13
crates/loro-nodejs/index.d.ts vendored Normal file
View file

@ -0,0 +1,13 @@
/* tslint:disable */
/* eslint-disable */
/* auto-generated by NAPI-RS */
export class Loro {
constructor()
getText(id: string): LoroText
}
export class LoroText {
insert(loro: Loro, pos: number, text: string): void
value(): string
}

252
crates/loro-nodejs/index.js Normal file
View file

@ -0,0 +1,252 @@
const { existsSync, readFileSync } = require('fs')
const { join } = require('path')
const { platform, arch } = process
let nativeBinding = null
let localFileExisted = false
let loadError = null
function isMusl() {
// For Node 10
if (!process.report || typeof process.report.getReport !== 'function') {
try {
const lddPath = require('child_process').execSync('which ldd').toString().trim();
return readFileSync(lddPath, 'utf8').includes('musl')
} catch (e) {
return true
}
} else {
const { glibcVersionRuntime } = process.report.getReport().header
return !glibcVersionRuntime
}
}
switch (platform) {
case 'android':
switch (arch) {
case 'arm64':
localFileExisted = existsSync(join(__dirname, 'loro-nodejs.android-arm64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./loro-nodejs.android-arm64.node')
} else {
nativeBinding = require('loro-nodejs-android-arm64')
}
} catch (e) {
loadError = e
}
break
case 'arm':
localFileExisted = existsSync(join(__dirname, 'loro-nodejs.android-arm-eabi.node'))
try {
if (localFileExisted) {
nativeBinding = require('./loro-nodejs.android-arm-eabi.node')
} else {
nativeBinding = require('loro-nodejs-android-arm-eabi')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Android ${arch}`)
}
break
case 'win32':
switch (arch) {
case 'x64':
localFileExisted = existsSync(
join(__dirname, 'loro-nodejs.win32-x64-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./loro-nodejs.win32-x64-msvc.node')
} else {
nativeBinding = require('loro-nodejs-win32-x64-msvc')
}
} catch (e) {
loadError = e
}
break
case 'ia32':
localFileExisted = existsSync(
join(__dirname, 'loro-nodejs.win32-ia32-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./loro-nodejs.win32-ia32-msvc.node')
} else {
nativeBinding = require('loro-nodejs-win32-ia32-msvc')
}
} catch (e) {
loadError = e
}
break
case 'arm64':
localFileExisted = existsSync(
join(__dirname, 'loro-nodejs.win32-arm64-msvc.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./loro-nodejs.win32-arm64-msvc.node')
} else {
nativeBinding = require('loro-nodejs-win32-arm64-msvc')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Windows: ${arch}`)
}
break
case 'darwin':
localFileExisted = existsSync(join(__dirname, 'loro-nodejs.darwin-universal.node'))
try {
if (localFileExisted) {
nativeBinding = require('./loro-nodejs.darwin-universal.node')
} else {
nativeBinding = require('loro-nodejs-darwin-universal')
}
break
} catch {}
switch (arch) {
case 'x64':
localFileExisted = existsSync(join(__dirname, 'loro-nodejs.darwin-x64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./loro-nodejs.darwin-x64.node')
} else {
nativeBinding = require('loro-nodejs-darwin-x64')
}
} catch (e) {
loadError = e
}
break
case 'arm64':
localFileExisted = existsSync(
join(__dirname, 'loro-nodejs.darwin-arm64.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./loro-nodejs.darwin-arm64.node')
} else {
nativeBinding = require('loro-nodejs-darwin-arm64')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on macOS: ${arch}`)
}
break
case 'freebsd':
if (arch !== 'x64') {
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
}
localFileExisted = existsSync(join(__dirname, 'loro-nodejs.freebsd-x64.node'))
try {
if (localFileExisted) {
nativeBinding = require('./loro-nodejs.freebsd-x64.node')
} else {
nativeBinding = require('loro-nodejs-freebsd-x64')
}
} catch (e) {
loadError = e
}
break
case 'linux':
switch (arch) {
case 'x64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'loro-nodejs.linux-x64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./loro-nodejs.linux-x64-musl.node')
} else {
nativeBinding = require('loro-nodejs-linux-x64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'loro-nodejs.linux-x64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./loro-nodejs.linux-x64-gnu.node')
} else {
nativeBinding = require('loro-nodejs-linux-x64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 'arm64':
if (isMusl()) {
localFileExisted = existsSync(
join(__dirname, 'loro-nodejs.linux-arm64-musl.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./loro-nodejs.linux-arm64-musl.node')
} else {
nativeBinding = require('loro-nodejs-linux-arm64-musl')
}
} catch (e) {
loadError = e
}
} else {
localFileExisted = existsSync(
join(__dirname, 'loro-nodejs.linux-arm64-gnu.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./loro-nodejs.linux-arm64-gnu.node')
} else {
nativeBinding = require('loro-nodejs-linux-arm64-gnu')
}
} catch (e) {
loadError = e
}
}
break
case 'arm':
localFileExisted = existsSync(
join(__dirname, 'loro-nodejs.linux-arm-gnueabihf.node')
)
try {
if (localFileExisted) {
nativeBinding = require('./loro-nodejs.linux-arm-gnueabihf.node')
} else {
nativeBinding = require('loro-nodejs-linux-arm-gnueabihf')
}
} catch (e) {
loadError = e
}
break
default:
throw new Error(`Unsupported architecture on Linux: ${arch}`)
}
break
default:
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
}
if (!nativeBinding) {
if (loadError) {
throw loadError
}
throw new Error(`Failed to load native binding`)
}
const { Loro, LoroText } = nativeBinding
module.exports.Loro = Loro
module.exports.LoroText = LoroText

View file

@ -0,0 +1,3 @@
# `loro-nodejs-android-arm-eabi`
This is the **armv7-linux-androideabi** binary for `loro-nodejs`

View file

@ -0,0 +1,18 @@
{
"name": "loro-nodejs-android-arm-eabi",
"version": "0.0.0",
"os": [
"android"
],
"cpu": [
"arm"
],
"main": "loro-nodejs.android-arm-eabi.node",
"files": [
"loro-nodejs.android-arm-eabi.node"
],
"license": "MIT",
"engines": {
"node": ">= 10"
}
}

View file

@ -0,0 +1,3 @@
# `loro-nodejs-android-arm64`
This is the **aarch64-linux-android** binary for `loro-nodejs`

View file

@ -0,0 +1,18 @@
{
"name": "loro-nodejs-android-arm64",
"version": "0.0.0",
"os": [
"android"
],
"cpu": [
"arm64"
],
"main": "loro-nodejs.android-arm64.node",
"files": [
"loro-nodejs.android-arm64.node"
],
"license": "MIT",
"engines": {
"node": ">= 10"
}
}

View file

@ -0,0 +1,3 @@
# `loro-nodejs-darwin-arm64`
This is the **aarch64-apple-darwin** binary for `loro-nodejs`

View file

@ -0,0 +1,18 @@
{
"name": "loro-nodejs-darwin-arm64",
"version": "0.0.0",
"os": [
"darwin"
],
"cpu": [
"arm64"
],
"main": "loro-nodejs.darwin-arm64.node",
"files": [
"loro-nodejs.darwin-arm64.node"
],
"license": "MIT",
"engines": {
"node": ">= 10"
}
}

View file

@ -0,0 +1,3 @@
# `loro-nodejs-darwin-universal`
This is the **universal-apple-darwin** binary for `loro-nodejs`

View file

@ -0,0 +1,15 @@
{
"name": "loro-nodejs-darwin-universal",
"version": "0.0.0",
"os": [
"darwin"
],
"main": "loro-nodejs.darwin-universal.node",
"files": [
"loro-nodejs.darwin-universal.node"
],
"license": "MIT",
"engines": {
"node": ">= 10"
}
}

View file

@ -0,0 +1,3 @@
# `loro-nodejs-darwin-x64`
This is the **x86_64-apple-darwin** binary for `loro-nodejs`

View file

@ -0,0 +1,18 @@
{
"name": "loro-nodejs-darwin-x64",
"version": "0.0.0",
"os": [
"darwin"
],
"cpu": [
"x64"
],
"main": "loro-nodejs.darwin-x64.node",
"files": [
"loro-nodejs.darwin-x64.node"
],
"license": "MIT",
"engines": {
"node": ">= 10"
}
}

View file

@ -0,0 +1,3 @@
# `loro-nodejs-freebsd-x64`
This is the **x86_64-unknown-freebsd** binary for `loro-nodejs`

View file

@ -0,0 +1,18 @@
{
"name": "loro-nodejs-freebsd-x64",
"version": "0.0.0",
"os": [
"freebsd"
],
"cpu": [
"x64"
],
"main": "loro-nodejs.freebsd-x64.node",
"files": [
"loro-nodejs.freebsd-x64.node"
],
"license": "MIT",
"engines": {
"node": ">= 10"
}
}

View file

@ -0,0 +1,3 @@
# `loro-nodejs-linux-arm-gnueabihf`
This is the **armv7-unknown-linux-gnueabihf** binary for `loro-nodejs`

View file

@ -0,0 +1,18 @@
{
"name": "loro-nodejs-linux-arm-gnueabihf",
"version": "0.0.0",
"os": [
"linux"
],
"cpu": [
"arm"
],
"main": "loro-nodejs.linux-arm-gnueabihf.node",
"files": [
"loro-nodejs.linux-arm-gnueabihf.node"
],
"license": "MIT",
"engines": {
"node": ">= 10"
}
}

View file

@ -0,0 +1,3 @@
# `loro-nodejs-linux-arm64-gnu`
This is the **aarch64-unknown-linux-gnu** binary for `loro-nodejs`

View file

@ -0,0 +1,21 @@
{
"name": "loro-nodejs-linux-arm64-gnu",
"version": "0.0.0",
"os": [
"linux"
],
"cpu": [
"arm64"
],
"main": "loro-nodejs.linux-arm64-gnu.node",
"files": [
"loro-nodejs.linux-arm64-gnu.node"
],
"license": "MIT",
"engines": {
"node": ">= 10"
},
"libc": [
"glibc"
]
}

View file

@ -0,0 +1,3 @@
# `loro-nodejs-linux-arm64-musl`
This is the **aarch64-unknown-linux-musl** binary for `loro-nodejs`

View file

@ -0,0 +1,21 @@
{
"name": "loro-nodejs-linux-arm64-musl",
"version": "0.0.0",
"os": [
"linux"
],
"cpu": [
"arm64"
],
"main": "loro-nodejs.linux-arm64-musl.node",
"files": [
"loro-nodejs.linux-arm64-musl.node"
],
"license": "MIT",
"engines": {
"node": ">= 10"
},
"libc": [
"musl"
]
}

View file

@ -0,0 +1,3 @@
# `loro-nodejs-linux-x64-gnu`
This is the **x86_64-unknown-linux-gnu** binary for `loro-nodejs`

View file

@ -0,0 +1,21 @@
{
"name": "loro-nodejs-linux-x64-gnu",
"version": "0.0.0",
"os": [
"linux"
],
"cpu": [
"x64"
],
"main": "loro-nodejs.linux-x64-gnu.node",
"files": [
"loro-nodejs.linux-x64-gnu.node"
],
"license": "MIT",
"engines": {
"node": ">= 10"
},
"libc": [
"glibc"
]
}

View file

@ -0,0 +1,3 @@
# `loro-nodejs-linux-x64-musl`
This is the **x86_64-unknown-linux-musl** binary for `loro-nodejs`

View file

@ -0,0 +1,21 @@
{
"name": "loro-nodejs-linux-x64-musl",
"version": "0.0.0",
"os": [
"linux"
],
"cpu": [
"x64"
],
"main": "loro-nodejs.linux-x64-musl.node",
"files": [
"loro-nodejs.linux-x64-musl.node"
],
"license": "MIT",
"engines": {
"node": ">= 10"
},
"libc": [
"musl"
]
}

View file

@ -0,0 +1,3 @@
# `loro-nodejs-win32-arm64-msvc`
This is the **aarch64-pc-windows-msvc** binary for `loro-nodejs`

View file

@ -0,0 +1,18 @@
{
"name": "loro-nodejs-win32-arm64-msvc",
"version": "0.0.0",
"os": [
"win32"
],
"cpu": [
"arm64"
],
"main": "loro-nodejs.win32-arm64-msvc.node",
"files": [
"loro-nodejs.win32-arm64-msvc.node"
],
"license": "MIT",
"engines": {
"node": ">= 10"
}
}

View file

@ -0,0 +1,3 @@
# `loro-nodejs-win32-ia32-msvc`
This is the **i686-pc-windows-msvc** binary for `loro-nodejs`

View file

@ -0,0 +1,18 @@
{
"name": "loro-nodejs-win32-ia32-msvc",
"version": "0.0.0",
"os": [
"win32"
],
"cpu": [
"ia32"
],
"main": "loro-nodejs.win32-ia32-msvc.node",
"files": [
"loro-nodejs.win32-ia32-msvc.node"
],
"license": "MIT",
"engines": {
"node": ">= 10"
}
}

View file

@ -0,0 +1,3 @@
# `loro-nodejs-win32-x64-msvc`
This is the **x86_64-pc-windows-msvc** binary for `loro-nodejs`

View file

@ -0,0 +1,18 @@
{
"name": "loro-nodejs-win32-x64-msvc",
"version": "0.0.0",
"os": [
"win32"
],
"cpu": [
"x64"
],
"main": "loro-nodejs.win32-x64-msvc.node",
"files": [
"loro-nodejs.win32-x64-msvc.node"
],
"license": "MIT",
"engines": {
"node": ">= 10"
}
}

View file

@ -0,0 +1,44 @@
{
"name": "loro-nodejs",
"version": "0.0.0",
"main": "index.js",
"types": "index.d.ts",
"napi": {
"name": "loro-nodejs",
"triples": {
"additional": [
"aarch64-apple-darwin",
"aarch64-linux-android",
"aarch64-unknown-linux-gnu",
"aarch64-unknown-linux-musl",
"aarch64-pc-windows-msvc",
"armv7-unknown-linux-gnueabihf",
"x86_64-unknown-linux-musl",
"x86_64-unknown-freebsd",
"i686-pc-windows-msvc",
"armv7-linux-androideabi",
"universal-apple-darwin"
]
}
},
"license": "MIT",
"devDependencies": {
"@napi-rs/cli": "^2.14.6",
"ava": "^5.1.1"
},
"ava": {
"timeout": "3m"
},
"engines": {
"node": ">= 10"
},
"scripts": {
"artifacts": "napi artifacts",
"build": "napi build --platform --release",
"build:debug": "napi build --platform",
"prepublishOnly": "napi prepublish -t npm",
"test": "ava",
"universal": "napi universal",
"version": "napi version"
}
}

View file

@ -0,0 +1,2 @@
tab_spaces = 2
edition = "2021"

View file

@ -0,0 +1,39 @@
#![deny(clippy::all)]
use loro_internal::{LoroCore, Text};
#[macro_use]
extern crate napi_derive;
#[napi]
#[derive(Default)]
pub struct Loro(LoroCore);
#[napi]
impl Loro {
#[napi(constructor)]
pub fn new() -> Self {
Self(LoroCore::default())
}
#[napi]
pub fn get_text(&mut self, id: String) -> LoroText {
LoroText(self.0.get_text(id))
}
}
#[napi]
pub struct LoroText(Text);
#[napi]
impl LoroText {
#[napi]
pub fn insert(&mut self, loro: &Loro, pos: u32, text: String) {
self.0.insert(&loro.0, pos as usize, &text).unwrap()
}
#[napi]
pub fn value(&self) -> String {
self.0.get_value().as_string().unwrap().to_string()
}
}

1013
crates/loro-nodejs/yarn.lock Normal file

File diff suppressed because it is too large Load diff