Skip to content

Commit 0d761ec

Browse files
committed
Add wasi build in CI
1 parent 2ab5143 commit 0d761ec

File tree

18 files changed

+264
-230
lines changed

18 files changed

+264
-230
lines changed

.github/workflows/CI.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ jobs:
9494
- host: windows-latest
9595
target: aarch64-pc-windows-msvc
9696
build: yarn build --target aarch64-pc-windows-msvc
97+
- host: ubuntu-latest
98+
target: wasm32-wasip1-threads
99+
build: yarn build --target wasm32-wasip1-threads
97100
name: stable - ${{ matrix.settings.target }} - node@22
98101
runs-on: ${{ matrix.settings.host }}
99102
steps:
@@ -343,6 +346,34 @@ jobs:
343346
344347
fi
345348
yarn test
349+
test-wasi:
350+
name: Test WASI target
351+
needs:
352+
- build
353+
runs-on: ubuntu-latest
354+
steps:
355+
- uses: actions/checkout@v5
356+
- name: Setup node
357+
uses: actions/setup-node@v4
358+
with:
359+
node-version: 22
360+
cache: yarn
361+
- name: Install dependencies
362+
run: |
363+
yarn config set supportedArchitectures.cpu "wasm32"
364+
yarn install
365+
- name: Download artifacts
366+
uses: actions/download-artifact@v5
367+
with:
368+
name: bindings-wasm32-wasip1-threads
369+
path: .
370+
- name: List packages
371+
run: ls -R .
372+
shell: bash
373+
- name: Test bindings
374+
run: yarn test
375+
env:
376+
NAPI_RS_FORCE_WASI: 1
346377
publish:
347378
name: Publish
348379
runs-on: ubuntu-latest
@@ -354,6 +385,7 @@ jobs:
354385
- build-freebsd
355386
- test-macOS-windows-binding
356387
- test-linux-binding
388+
- test-wasi
357389
steps:
358390
- uses: actions/checkout@v5
359391
- name: Setup node

src/client/browser/client.rs

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
use crate::client::browser::HttpQueryResponseV1;
12
use crate::client::http_client::get_http_client;
23
use crate::client::options::{FlightOptions, QueryPayload, WriteOptions};
3-
use crate::serializer::browser::{Serializer};
4+
use crate::query::browser::query_processor::into_stream;
5+
use crate::serializer::browser::Serializer;
6+
use napi::bindgen_prelude::*;
47
use napi::bindgen_prelude::{Buffer, Either, ReadableStream};
5-
use napi::Env;
68
use napi::tokio_stream::wrappers::ReceiverStream;
9+
use napi::Env;
710
use reqwest::Client;
811
use serde::{Deserialize, Serialize};
912
use serde_json::{Map, Value};
10-
use crate::client::browser::HttpQueryResponseV1;
11-
use crate::query::browser::query_processor::into_stream;
12-
use napi::bindgen_prelude::*;
1313

1414
#[napi_derive::napi]
1515
pub struct InfluxDBClient {
@@ -20,7 +20,7 @@ pub struct InfluxDBClient {
2020
}
2121

2222
// replace it with #[napi_derive::napi] in the future
23-
// impl InfluxClientTrait for InfluxDBClient {
23+
// impl InfluxClientTrait for InfluxDBClient {
2424
#[napi_derive::napi]
2525
impl InfluxDBClient {
2626
#[napi(constructor)]
@@ -43,12 +43,7 @@ impl InfluxDBClient {
4343
&mut self,
4444
query_payload: QueryPayload,
4545
env: &Env,
46-
) -> napi::Result<
47-
Either<
48-
ReadableStream<'_, Map<String, Value>>,
49-
ReadableStream<'_, Buffer>,
50-
>,
51-
> {
46+
) -> napi::Result<Either<ReadableStream<'_, Map<String, Value>>, ReadableStream<'_, Buffer>>> {
5247
let stream = self.query_inner(query_payload, env)?;
5348
Ok(Either::A(stream))
5449
}
@@ -60,35 +55,36 @@ impl InfluxDBClient {
6055
) -> Result<ReadableStream<'_, serde_json::Map<String, serde_json::Value>>> {
6156
use napi::bindgen_prelude::block_on;
6257

63-
let stream: ReceiverStream<Result<serde_json::Map<String, serde_json::Value>>> = block_on(async {
64-
let url = format!("{}/query", self.addr);
58+
let stream: ReceiverStream<Result<serde_json::Map<String, serde_json::Value>>> =
59+
block_on(async {
60+
let url = format!("{}/query", self.addr);
6561

66-
let response = self
67-
.http_client
68-
.get(&url)
69-
.query(&[
70-
("db", query_payload.database.clone()),
71-
("q", query_payload.query.clone()),
72-
])
73-
.send()
74-
.await
75-
.map_err(|e| Error::from_reason(format!("HTTP request failed: {}", e)))?;
62+
let response = self
63+
.http_client
64+
.get(&url)
65+
.query(&[
66+
("db", query_payload.database.clone()),
67+
("q", query_payload.query.clone()),
68+
])
69+
.send()
70+
.await
71+
.map_err(|e| Error::from_reason(format!("HTTP request failed: {}", e)))?;
7672

77-
let status = response.status();
78-
if !status.is_success() {
79-
return Err(Error::from_reason(format!(
80-
"InfluxDB returned non-success status: {}",
81-
status
82-
)));
83-
}
73+
let status = response.status();
74+
if !status.is_success() {
75+
return Err(Error::from_reason(format!(
76+
"InfluxDB returned non-success status: {}",
77+
status
78+
)));
79+
}
8480

85-
let data: HttpQueryResponseV1 = response
86-
.json()
87-
.await
88-
.map_err(|e| Error::from_reason(format!("Failed to parse JSON: {}", e)))?;
81+
let data: HttpQueryResponseV1 = response
82+
.json()
83+
.await
84+
.map_err(|e| Error::from_reason(format!("Failed to parse JSON: {}", e)))?;
8985

90-
Ok(into_stream(data))
91-
})?;
86+
Ok(into_stream(data))
87+
})?;
9288

9389
ReadableStream::new(env, stream)
9490
}

src/client/browser/mod.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ pub(crate) mod client;
44

55
#[derive(Deserialize, Serialize)]
66
pub struct Series {
7-
name: String,
8-
pub(crate)columns: Vec<String>,
9-
pub(crate)values: Vec<Vec<serde_json::Value>>,
7+
name: String,
8+
pub(crate) columns: Vec<String>,
9+
pub(crate) values: Vec<Vec<serde_json::Value>>,
1010
}
1111

1212
#[derive(Deserialize, Serialize)]
1313
pub struct QueryDataV1 {
14-
statement_id: u32,
15-
pub(crate) series: Vec<Series>,
14+
statement_id: u32,
15+
pub(crate) series: Vec<Series>,
1616
}
1717

1818
#[derive(Deserialize, Serialize)]
1919
pub(crate) struct HttpQueryResponseV1 {
20-
pub(crate)results: Vec<QueryDataV1>,
21-
}
20+
pub(crate) results: Vec<QueryDataV1>,
21+
}

src/client/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ pub mod browser;
1212
pub mod napi_rs;
1313

1414
pub mod http_client;
15-
pub mod options;
15+
pub mod options;

0 commit comments

Comments
 (0)