Skip to content

Commit b2f8a39

Browse files
committed
Divided the link crates - into wasm commons
1 parent ab9c288 commit b2f8a39

35 files changed

Lines changed: 264 additions & 147 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,5 @@ link/sdks/typescript/client/.npmrc
133133
cli/kalam.toml
134134
/link/sdks/rust/sdks/typescript/client/.wasm-cargo-home
135135
/link/sdks/rust/sdks/typescript/client/.wasm-target
136+
/link/kalam-link-wasm/sdks/typescript/client/.wasm-cargo-home
137+
/link/kalam-link-wasm/sdks/typescript/client/.wasm-target

Cargo.lock

Lines changed: 67 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ members = [
4747
"backend",
4848
"link/link-common",
4949
"link/sdks/rust",
50+
"link/kalam-link-wasm",
5051
"link/kalam-consumer-wasm",
5152
"link/kalam-link-dart",
5253
"cli",

docker/build/Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ COPY backend/Cargo.toml ./backend/
6565
COPY cli/Cargo.toml ./cli/
6666
COPY link/link-common/Cargo.toml ./link/link-common/
6767
COPY link/sdks/rust/Cargo.toml ./link/sdks/rust/
68+
COPY link/kalam-link-wasm/Cargo.toml ./link/kalam-link-wasm/
6869
COPY link/kalam-consumer-wasm/Cargo.toml ./link/kalam-consumer-wasm/
6970
COPY link/kalam-link-dart/Cargo.toml ./link/kalam-link-dart/
7071
COPY pg/crates/kalam-pg-common/Cargo.toml ./pg/crates/kalam-pg-common/
@@ -162,6 +163,8 @@ RUN mkdir -p link/link-common/src && \
162163
echo "pub fn lib() {}" > link/link-common/src/lib.rs && \
163164
mkdir -p link/sdks/rust/src && \
164165
echo "pub fn lib() {}" > link/sdks/rust/src/lib.rs && \
166+
mkdir -p link/kalam-link-wasm/src && \
167+
echo "pub fn lib() {}" > link/kalam-link-wasm/src/lib.rs && \
165168
mkdir -p link/kalam-consumer-wasm/src && \
166169
echo "pub fn lib() {}" > link/kalam-consumer-wasm/src/lib.rs && \
167170
mkdir -p link/kalam-link-dart/src && \
@@ -197,7 +200,7 @@ RUN SKIP_UI_BUILD=1 cargo build --profile docker --features mimalloc --bin kalam
197200
FROM deps AS builder
198201

199202
# Remove dummy source files
200-
RUN rm -rf backend/src backend/crates cli/src link/link-common/src link/sdks/rust/src link/kalam-consumer-wasm/src link/kalam-link-dart/src pg/crates
203+
RUN rm -rf backend/src backend/crates cli/src link/link-common/src link/sdks/rust/src link/kalam-link-wasm/src link/kalam-consumer-wasm/src link/kalam-link-dart/src pg/crates
201204

202205
# Copy actual source code
203206
COPY backend/src ./backend/src
@@ -208,6 +211,7 @@ COPY cli/src ./cli/src
208211
COPY cli/build.rs ./cli/
209212
COPY link/link-common/src ./link/link-common/src
210213
COPY link/sdks/rust/src ./link/sdks/rust/src
214+
COPY link/kalam-link-wasm/src ./link/kalam-link-wasm/src
211215
COPY link/kalam-consumer-wasm/src ./link/kalam-consumer-wasm/src
212216
COPY link/kalam-link-dart/src ./link/kalam-link-dart/src
213217
COPY pg/crates ./pg/crates

docs/development/rust-method-map.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ Generated from repo-wide Rust function discovery using ripgrep.
6262
- `backend/crates/kalamdb-tables/src/utils`: 201
6363
- `cli/tests/common`: 187
6464
- `link/link-common/src`: 178
65-
- `link/kalam-client/tests`: 164
65+
- `link/kalam-link-wasm/tests`: WASM browser integration tests
66+
- `link/sdks/rust/tests`: native SDK integration tests
6667
- `backend/tests/common/testserver`: 161
6768
- `backend/crates/kalamdb-commons/src/models/schemas`: 160
6869
- `backend/crates/kalamdb-views/src`: 156

docs/sdk/sdk.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ export * from './schema.generated';
4545

4646
This repo contains two related pieces:
4747

48-
- The Rust client crate: `link/kalam-client/` (package name: `kalam-client`)
48+
- The Rust client crate: `link/sdks/rust/` (package name: `kalam-client`, native only)
49+
- The browser WASM entry crate: `link/kalam-link-wasm/` (built by `@kalamdb/client`)
4950
- The npm-publishable TypeScript SDK package: `link/sdks/typescript/client/`
5051

5152
### Prerequisites
@@ -60,7 +61,15 @@ Install wasm-pack:
6061
cargo install wasm-pack
6162
```
6263

63-
### Compile the Rust client (`kalam-client`)
64+
### Compile the browser WASM module (`kalam-link-wasm`)
65+
66+
From the repo root:
67+
68+
```bash
69+
wasm-pack build kalam-link-wasm --target web --out-dir link/sdks/typescript/client/wasm --out-name kalam_client --profile release-dist
70+
```
71+
72+
### Compile the native Rust client (`kalam-client`)
6473

6574
From the repo root:
6675

link/README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Shared Rust transport crates and SDK packages for KalamDB clients.
55
This directory contains:
66

77
- the shared Rust implementation crate `link-common`
8-
- the app-facing Rust/WASM entry crate `kalam-client`
8+
- the published native Rust SDK crate `kalam-client` (`link/sdks/rust`)
9+
- the browser WebAssembly wrapper crate `kalam-link-wasm` (`@kalamdb/client`)
910
- the consumer-only WebAssembly wrapper crate `kalam-consumer-wasm`
1011
- the publishable TypeScript CLI wrapper package in [sdks/typescript/cli](sdks/typescript/cli/README.md) as `@kalamdb/cli`
1112
- the publishable TypeScript app-facing package in [sdks/typescript/client](sdks/typescript/client/README.md) as `@kalamdb/client`
@@ -47,9 +48,11 @@ Older constructor-based examples, manual `connect()` walkthroughs, and raw WASM
4748
```text
4849
link/
4950
|-- link-common/ # shared Rust implementation
50-
|-- kalam-client/ # app-facing Rust/WASM entry crate
51+
|-- kalam-link-wasm/ # wasm-pack entry for @kalamdb/client
5152
|-- kalam-consumer-wasm/ # wasm-bindgen wrapper for @kalamdb/consumer
53+
|-- kalam-link-dart/ # FRB bridge for kalam_link (Flutter)
5254
`-- sdks/
55+
|-- rust/ # kalam-client (native Rust SDK, crates.io)
5356
|-- typescript/
5457
| |-- cli/ # npm package: @kalamdb/cli
5558
| |-- client/ # npm package: @kalamdb/client
@@ -66,7 +69,7 @@ Package-specific build, test, and publish instructions live with each SDK:
6669
- TypeScript / JavaScript CLI wrapper: [sdks/typescript/cli/README.md](sdks/typescript/cli/README.md)
6770
- Dart / Flutter: [sdks/dart/README.md](sdks/dart/README.md)
6871

69-
If you change the shared Rust implementation in `link-common` or the `kalam-client` WASM entry crate, validate the affected SDK package afterward.
72+
If you change the shared Rust implementation in `link-common` or the `kalam-link-wasm` entry crate, validate the affected SDK package afterward.
7073

7174
## License
7275

link/kalam-link-dart/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ anyhow = { workspace = true }
1919
[features]
2020
default = ["native"]
2121
native = ["kalam-client/native-sdk", "kalam-client/file-uploads", "tokio"]
22-
wasm = ["kalam-client/wasm"]
2322

2423
[lib]
2524
crate-type = ["cdylib", "staticlib", "rlib"]

link/kalam-link-wasm/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target/

link/kalam-link-wasm/Cargo.toml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[package]
2+
name = "kalam-link-wasm"
3+
version.workspace = true
4+
edition.workspace = true
5+
rust-version.workspace = true
6+
authors.workspace = true
7+
license.workspace = true
8+
repository.workspace = true
9+
description = "Browser WebAssembly bindings for @kalamdb/client"
10+
keywords = ["kalamdb", "database", "client", "websocket", "wasm"]
11+
categories = ["database", "web-programming::websocket", "wasm"]
12+
readme = "README.md"
13+
14+
[dependencies]
15+
link-common = { workspace = true, default-features = false, features = ["client-core"] }
16+
serde = { workspace = true }
17+
serde_json = { workspace = true }
18+
rmp-serde = { workspace = true }
19+
miniz_oxide = { workspace = true }
20+
log = { workspace = true }
21+
base64 = { workspace = true }
22+
wasm-bindgen = { workspace = true }
23+
wasm-bindgen-futures = { workspace = true }
24+
js-sys = { workspace = true }
25+
web-sys = { workspace = true, features = [
26+
"console",
27+
"WebSocket",
28+
"BinaryType",
29+
"MessageEvent",
30+
"CloseEvent",
31+
"ErrorEvent",
32+
"Event",
33+
"EventTarget",
34+
"Blob",
35+
"FileReader",
36+
"Window",
37+
"Request",
38+
"RequestInit",
39+
"RequestMode",
40+
"Response",
41+
"Headers",
42+
"FormData",
43+
"BlobPropertyBag",
44+
] }
45+
46+
[dev-dependencies]
47+
js-sys = { workspace = true }
48+
wasm-bindgen = { workspace = true }
49+
wasm-bindgen-test = "0.3.50"
50+
51+
[[test]]
52+
name = "wasm_integration"
53+
path = "tests/wasm_integration.rs"
54+
55+
[lib]
56+
crate-type = ["cdylib", "rlib"]
57+
58+
[package.metadata.wasm-pack.profile.release]
59+
wasm-opt = false

0 commit comments

Comments
 (0)