Skip to content
Merged
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
35 changes: 25 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
deno-version: v2.x
- name: Build
run: deno task debug
run: deno task debug-no-opt
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
Expand All @@ -24,25 +24,22 @@ jobs:
./src/datex-web/datex_web.internal.js
./src/datex-web/datex_web.wasm
retention-days: 5

test:
runs-on: ubuntu-latest
name: Test
lint:
name: Lint
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: "true"
- uses: denoland/setup-deno@v2
with:
deno-version: v2.x
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build
path: ./src/datex-web

- uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- name: Check formatting
run: deno fmt --check

Expand All @@ -52,6 +49,24 @@ jobs:
- name: Type Checking
run: deno check -I ./src ./test

test:
runs-on: ubuntu-latest
name: Test
needs: build
steps:
- uses: actions/checkout@v4
with:
submodules: "true"
- name: Download build artifacts
uses: actions/download-artifact@v4
with:
name: build
path: ./src/datex-web

- uses: denoland/setup-deno@v2
with:
deno-version: v2.x

- name: Run Tests
run: deno task test-no-build

Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"RUSTFLAGS": "--cfg=web_sys_unstable_apis"
},
"rust-analyzer.cargo.target": "wasm32-unknown-unknown",
"rust-analyzer.cargo.features": ["debug"]
"rust-analyzer.cargo.features": []
}
10 changes: 5 additions & 5 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion datex-browser-demo/package-lock.json

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

15 changes: 12 additions & 3 deletions datex-browser-demo/src/demo/demo-runtime.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Ref, Runtime } from "datex";
import { Endpoint, Range, Ref, Repl, Runtime } from "datex";

export const runtime = await Runtime.create(
{
interfaces: [
{
type: "websocket-client",
config: {
url: "ws://localhost:8043",
url: "wss://example.unyt.land",
},
},
],
Expand All @@ -15,7 +15,7 @@ export const runtime = await Runtime.create(
},
},
{
log_level: "warn",
log_level: "info",
},
);

Expand All @@ -25,3 +25,12 @@ runtime.comHub.printMetadata();
globalThis.Datex = runtime;
// @ts-ignore global variable for debugging
globalThis.Ref = Ref;

// @ts-ignore global variable for debugging
globalThis.Range = Range;

// @ts-ignore global variable for debugging
globalThis.Endpoint = Endpoint;

// @ts-ignore global variable for debugging
globalThis.Repl = Repl;
8 changes: 4 additions & 4 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@unyt/datex",
"version": "0.0.13",
"version": "0.0.14",
"license": "MIT",
"exports": {
".": "./src/mod.ts",
Expand All @@ -16,9 +16,9 @@
]
},
"tasks": {
"debug": "deno run -A scripts/build-wasm.ts --profile debug --features debug",
"debug": "deno run -A scripts/build-wasm.ts --profile debug",
"release": "deno run -A scripts/build-wasm.ts --profile release",
"debug-unsecure": "deno run -A scripts/build-wasm.ts --profile debug --features debug,allow_unsigned_blocks",
"debug-unsecure": "deno run -A scripts/build-wasm.ts --profile debug --features allow_unsigned_blocks",

"debug-no-opt": "deno task debug --no-opt",
"test": "deno task debug-no-opt && deno test -A",
Expand All @@ -31,7 +31,7 @@
"browser-demo-no-build": "deno task build-npm && cd datex-browser-demo && npm install && npm run dev",

"fmt": "deno fmt && cargo fmt",
"lint": "deno lint --fix && cargo clippy --fix --features debug"
"lint": "deno lint --fix && cargo clippy --fix"
},
"fmt": {
"indentWidth": 4,
Expand Down
11 changes: 6 additions & 5 deletions rs-lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "datex-web"
version = "0.0.13"
version = "0.0.14"
authors = [
"Benedikt Strehle <benedikt@unyt.org>",
"Jonas Strehle <jonas@unyt.org>",
Expand All @@ -20,17 +20,17 @@ panic = "abort"

[dependencies]
log = { version = "0.4", features = ["std", "serde"] }
datex-core = { version = "0.0.10", default-features = false, features = [
# git = "https://github.com/unyt-org/datex", branch = "release/0.0.11",
datex-core = { version = "0.0.11", default-features = false, features = [
"target_wasm",
"compiler",
"decompiler",
"syntax_highlighting_legacy",
"lsp_wasm",
] }
# git = "https://github.com/unyt-org/datex", branch = "release/0.0.11",
datex-crypto-facade = { version = "0.0.2" }

# datex_macros = { git = "https://github.com/unyt-org/datex", branch = "refactor/update-loop", version = "0.1.3", package = "datex_macros" }

async-trait = "0.1.87"
url = { version = "2.5.7" }
wasm-bindgen = { version = "=0.2.112", features = [] }
Expand Down Expand Up @@ -109,10 +109,11 @@ default = [
"websocket-client",
"serial-client",
"webrtc",
"repl",
"lsp", # Make optional
]
debug = []
lsp = ["datex-core/lsp_wasm"]
repl = []

allow_unsigned_blocks = ["datex-core/allow_unsigned_blocks"]

Expand Down
5 changes: 4 additions & 1 deletion rs-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ pub mod network;
pub mod js_utils;
pub mod utils;

#[cfg(feature = "repl")]
pub mod repl;

#[cfg(feature = "lsp")]
pub mod lsp;

Expand Down Expand Up @@ -78,4 +81,4 @@ pub async fn create_runtime(
});

JSRuntime::run(config).await
}
}
45 changes: 45 additions & 0 deletions rs-lib/src/repl/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use datex_core::runtime::execution::context::{
ExecutionContext, ExecutionMode,
};
use wasm_bindgen::{JsError, JsValue, prelude::wasm_bindgen};

use crate::{js_utils::js_error, runtime::JSRuntime};

#[wasm_bindgen]
pub struct Repl {
runtime: JSRuntime,
execution_context: ExecutionContext,
}

#[wasm_bindgen]
impl Repl {
#[wasm_bindgen(constructor)]
pub fn new(runtime: &JSRuntime, verbose: bool) -> Self {
let execution_context = if verbose {
ExecutionContext::local_debug(
ExecutionMode::unbounded(),
runtime.runtime().internal(),
)
} else {
ExecutionContext::local(
ExecutionMode::unbounded(),
runtime.runtime().internal(),
)
};

Self {
runtime: runtime.clone(),
execution_context,
}
}

pub async fn execute(&mut self, script: &str) -> Result<JsValue, JsError> {
let result = self
.runtime
.runtime()
.execute(script, &[], Some(&mut self.execution_context))
.await
.map_err(js_error)?;
Ok(self.runtime.maybe_value_container_to_dif(result))
}
}
50 changes: 23 additions & 27 deletions rs-lib/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ use datex_core::{
dxb_block::DXBBlock,
protocol_structures::block_header::{BlockHeader, FlagsAndTimestamp},
},
shared_values::{
observers::{ObserveOptions, TransceiverId},
},
serde::deserializer::DatexDeserializer,
shared_values::observers::{ObserveOptions, TransceiverId},
values::{
core_values::endpoint::Endpoint,
value_container::ValueContainer,
core_values::endpoint::Endpoint, value_container::ValueContainer,
},
};
use datex_crypto_facade::crypto::Crypto;
Expand All @@ -37,19 +34,20 @@ use datex_core::{
runtime::{
Runtime, RuntimeConfig, RuntimeInternal, RuntimeRunner, memory::Memory,
},
shared_values::{
pointer_address::PointerAddress,
shared_container::SharedContainerMutability,
},
};
use js_sys::Function;
use log::info;
use serde::{Deserialize, Serialize};
use serde_wasm_bindgen::{Error, from_value};
use std::{cell::RefCell, fmt::Display, rc::Rc, str::FromStr, sync::Arc};
use datex_core::shared_values::pointer_address::PointerAddress;
use datex_core::shared_values::shared_container::SharedContainerMutability;
use serde_wasm_bindgen::from_value;
use std::{cell::RefCell, fmt::Display, rc::Rc};
use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::{future_to_promise, spawn_local};
use web_sys::js_sys::Promise;

#[wasm_bindgen(getter_with_clone)]
#[derive(Clone)]
pub struct JSRuntime {
runtime: Runtime,
pub com_hub: JSComHub,
Expand Down Expand Up @@ -98,6 +96,20 @@ impl JSRuntime {
js_runtime
}

pub fn maybe_value_container_to_dif(
&self,
maybe_value_container: Option<ValueContainer>,
) -> JsValue {
match maybe_value_container {
None => JsValue::NULL,
Some(value_container) => {
let dif_value_container =
DIFValueContainer::from_value_container(&value_container);
to_js_value(&dif_value_container).unwrap()
}
}
}

fn new(runtime: Runtime) -> JSRuntime {
let com_hub = JSComHub::new(runtime.clone());
JSRuntime { runtime, com_hub }
Expand Down Expand Up @@ -388,22 +400,6 @@ impl JSRuntime {
))
}

fn maybe_value_container_to_dif(
&self,
maybe_value_container: Option<ValueContainer>,
) -> JsValue {
match maybe_value_container {
None => JsValue::NULL,
Some(value_container) => {
let dif_value_container =
DIFValueContainer::from_value_container(
&value_container,
);
to_js_value(&dif_value_container).unwrap()
}
}
}

fn js_values_to_value_containers(
&self,
js_values: Option<Vec<JsValue>>,
Expand Down
2 changes: 1 addition & 1 deletion rs-lib/tests/core_types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use datex_core::{
libs::core::{CoreLibPointerId, create_core_lib_types},
values::pointer::PointerAddress,
shared_values::pointer_address::PointerAddress,
};

#[test]
Expand Down
7 changes: 7 additions & 0 deletions src/datex-web/datex_web.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,13 @@ export class JSRuntime {
readonly version: string;
}

export class Repl {
free(): void;
[Symbol.dispose](): void;
execute(script: string): Promise<any>;
constructor(runtime: JSRuntime, verbose: boolean);
}

export class RuntimeDIFHandle {
private constructor();
free(): void;
Expand Down
Loading