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

chore: add http response headers, clippy #103

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
File renamed without changes.
13 changes: 9 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ jobs:
include:
- name: linux
os: ubuntu-latest
- name: windows
os: windows-latest
# Re-enable once we can build on Windows again
# - name: windows
# os: windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
Expand All @@ -29,12 +30,16 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
python-version: '3.12'

- name: Install Extism CLI
run: |
go install github.com/extism/cli/extism@v1.6.0
extism --version

- name: Update deps (Linux)
run: |
./install-wasi-sdk.sh
go install github.com/extism/cli/extism@latest
cd /tmp
# get just wasm-merge and wasm-opt
curl -L https://github.com/WebAssembly/binaryen/releases/download/version_116/binaryen-version_116-x86_64-linux.tar.gz > binaryen.tar.gz
Expand Down
5 changes: 3 additions & 2 deletions crates/cli/src/ts_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use swc_ecma_parser::{lexer::Lexer, Parser, StringInput, Syntax};

#[derive(Debug, Clone)]
pub struct Param {
#[allow(unused)]
pub name: String,
pub ptype: ValType,
}
Expand Down Expand Up @@ -139,7 +140,7 @@ fn parse_user_interface(i: &TsInterfaceDecl) -> Result<Interface> {

/// Try to parse the imports
fn parse_imports(tsmod: &TsModuleDecl) -> Result<Option<Interface>> {
for block in &tsmod.body {
if let Some(block) = &tsmod.body {
if let Some(block) = block.clone().ts_module_block() {
for inter in block.body {
if let ModuleItem::Stmt(Stmt::Decl(decl)) = inter {
Expand All @@ -166,7 +167,7 @@ fn parse_imports(tsmod: &TsModuleDecl) -> Result<Option<Interface>> {
fn parse_module_decl(tsmod: &TsModuleDecl) -> Result<Interface> {
let mut signatures = Vec::new();

for block in &tsmod.body {
if let Some(block) = &tsmod.body {
if let Some(block) = block.as_ts_module_block() {
for decl in &block.body {
if let ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(e)) = decl {
Expand Down
6 changes: 3 additions & 3 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ license.workspace = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
extism-pdk = "1"
extism-pdk = "1.3"
once_cell = "1.16"
anyhow = { workspace = true }
quickjs-wasm-rs = "3"
chrono = { version = "0.4", default_features = false, features = ["clock"] }
chrono = { version = "0.4", default-features = false, features = ["clock"] }
rquickjs = { version = "0.6.2", features = ["array-buffer"]}

[lib]
crate_type = ["cdylib"]
crate-type = ["cdylib"]
16 changes: 12 additions & 4 deletions crates/core/src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn inject_globals(context: &JSContext) -> anyhow::Result<()> {
this.eval("globalThis.module = {}; globalThis.module.exports = {}")?;
// need a *global* var for polyfills to work
this.eval("var global = globalThis")?;
this.eval(from_utf8(PRELUDE).map_err(|e| rquickjs::Error::Utf8(e))?)?;
this.eval(from_utf8(PRELUDE).map_err(rquickjs::Error::Utf8)?)?;

Ok::<_, rquickjs::Error>(())
})?;
Expand Down Expand Up @@ -535,6 +535,14 @@ fn build_http_object<'js>(this: Ctx<'js>) -> anyhow::Result<Object> {
"status",
Value::new_int(cx.clone(), res.status_code() as i32),
)?;

let headers = rquickjs::Object::new(cx.clone())?;

for (k, v) in res.headers() {
headers.set(k, v)?;
}

resp_obj.set("headers", headers)?;
Ok(resp_obj)
})?;

Expand Down Expand Up @@ -744,7 +752,7 @@ fn get_time<'js>(
let now = Utc::now();
// This format is compatible with JavaScript's Date constructor
let formatted = now.to_rfc3339_opts(SecondsFormat::Millis, true);
Ok(rquickjs::String::from_str(cx.clone(), &formatted)?)
rquickjs::String::from_str(cx.clone(), &formatted)
})
}

Expand Down Expand Up @@ -799,12 +807,12 @@ fn decode_utf8_buffer_to_js_string<'js>(
}

let str = if fatal {
Cow::from(from_utf8(view).map_err(|e| rquickjs::Error::Utf8(e))?)
Cow::from(from_utf8(view).map_err(rquickjs::Error::Utf8)?)
} else {
String::from_utf8_lossy(view)
};

Ok(rquickjs::String::from_str(cx.clone(), &str.to_string())?.into())
Ok(rquickjs::String::from_str(cx.clone(), &str)?.into())
})
}

Expand Down
1 change: 1 addition & 0 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ pub extern "C" fn __arg_f64(arg: f64) {

macro_rules! unwrap_value {
($d:expr, $x:expr) => {
#[allow(clippy::blocks_in_conditions)]
match $x {
Ok(x) => x,
Err(e) => {
Expand Down
Loading