Skip to content

Commit

Permalink
WASM bindings update (#1256)
Browse files Browse the repository at this point in the history
* Set type to module

* Add syncAllConversations

* camelCase GroupMetadata fields

* Add smart contract wallet support

* Run cargo update

* Prepare release

* Add constructor for LogOptions

* Add @sqlite.org/sqlite-wasm dependency

* Add copy script

* Update CHANGELOG
  • Loading branch information
rygine authored Nov 12, 2024
1 parent f37234a commit f4816cb
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 44 deletions.
90 changes: 53 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions bindings_wasm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @xmtp/wasm-bindings

## 0.0.4

- Added smart contract wallet signature support
- Changed package type to `module`
- Upgraded `diesel-wasm-sqlite`
- Added `sqlite3.wasm` to the package
- Added structured logging support

## 0.0.3

- Updated naming conventions for JS exports
Expand Down
7 changes: 5 additions & 2 deletions bindings_wasm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@xmtp/wasm-bindings",
"version": "0.0.3",
"version": "0.0.4",
"type": "module",
"license": "MIT",
"description": "WASM bindings for the libXMTP rust library",
"keywords": [
Expand All @@ -23,8 +24,9 @@
"directory": "bindings_wasm"
},
"scripts": {
"build": "yarn clean && yarn build:web && yarn clean:release",
"build": "yarn clean && yarn build:web && yarn build:copy && yarn clean:release",
"build:web": "cargo xtask build BindingsWasm --out-dir ./dist --plain -- --release",
"build:copy": "node scripts/copyFiles.js",
"clean:release": "rm -f ./dist/package.json",
"clean": "rm -rf ./dist",
"lint": "yarn lint:clippy && yarn lint:fmt",
Expand Down Expand Up @@ -53,6 +55,7 @@
"registry": "https://registry.npmjs.org/"
},
"devDependencies": {
"@sqlite.org/sqlite-wasm": "^3.47.0-build1",
"binaryen": "^120.0.0",
"wasm-pack": "^0.13.1"
},
Expand Down
39 changes: 39 additions & 0 deletions bindings_wasm/scripts/copyFiles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { readdirSync, existsSync, copyFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";

const __dirname = dirname(fileURLToPath(import.meta.url));
const distDir = join(__dirname, "..", "dist");

const files = readdirSync(distDir, { recursive: true });

let targetDir = "";
files.some((file) => {
if (file.endsWith("sqlite3-diesel.js")) {
targetDir = join(distDir, dirname(file));
return true;
}
});

if (!targetDir) {
console.error("Unable to find target directory for `sqlite3.wasm`");
process.exit(1);
}

const nodeModules = join(__dirname, "..", "node_modules");
const sourceFile = join(
nodeModules,
"@sqlite.org",
"sqlite-wasm",
"sqlite-wasm",
"jswasm",
"sqlite3.wasm"
);

if (!existsSync(sourceFile)) {
console.error(`Unable to find "sqlite3.wasm" in "${dirname(sourceFile)}"`);
process.exit(1);
}

console.log(`Copying "sqlite3.wasm" to "${targetDir}"`);
copyFileSync(sourceFile, join(targetDir, "sqlite3.wasm"));
16 changes: 14 additions & 2 deletions bindings_wasm/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static LOGGER_INIT: std::sync::OnceLock<Result<(), filter::LevelParseError>> =

#[wasm_bindgen]
#[derive(Copy, Clone, Debug)]
pub enum Level {
pub enum LogLevel {
Off = "off",
Error = "error",
Warn = "warn",
Expand All @@ -63,7 +63,19 @@ pub struct LogOptions {
/// enable performance metrics for libxmtp in the `performance` tab
pub performance: bool,
/// filter for logs
pub level: Option<Level>,
pub level: Option<LogLevel>,
}

#[wasm_bindgen]
impl LogOptions {
#[wasm_bindgen(constructor)]
pub fn new(structured: bool, performance: bool, level: Option<LogLevel>) -> Self {
Self {
structured,
performance,
level,
}
}
}

fn init_logging(options: LogOptions) -> Result<(), JsError> {
Expand Down
Loading

0 comments on commit f4816cb

Please sign in to comment.