From 55e8a453fe123cd3bb3496d69ca92bc780e3a833 Mon Sep 17 00:00:00 2001 From: benStre Date: Thu, 5 Mar 2026 01:15:16 +0000 Subject: [PATCH 01/10] Bump version to 0.0.14 --- Cargo.lock | 2 +- deno.json | 2 +- rs-lib/Cargo.toml | 2 +- src/runtime/runtime.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bee6202c..e3b2dd6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -437,7 +437,7 @@ dependencies = [ [[package]] name = "datex-web" -version = "0.0.13" +version = "0.0.14" dependencies = [ "async-trait", "cfg-if", diff --git a/deno.json b/deno.json index 393ab24f..0e8571f6 100644 --- a/deno.json +++ b/deno.json @@ -1,6 +1,6 @@ { "name": "@unyt/datex", - "version": "0.0.13", + "version": "0.0.14", "license": "MIT", "exports": { ".": "./src/mod.ts", diff --git a/rs-lib/Cargo.toml b/rs-lib/Cargo.toml index 72eabf64..9b797513 100644 --- a/rs-lib/Cargo.toml +++ b/rs-lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "datex-web" -version = "0.0.13" +version = "0.0.14" authors = [ "Benedikt Strehle ", "Jonas Strehle ", diff --git a/src/runtime/runtime.ts b/src/runtime/runtime.ts index 91ca8515..8a0203d1 100644 --- a/src/runtime/runtime.ts +++ b/src/runtime/runtime.ts @@ -7,7 +7,7 @@ import { unimplemented } from "../utils/exceptions.ts"; // TODO: move to global.ts /** auto-generated version - do not edit: */ -const VERSION: string = "0.0.13"; +const VERSION: string = "0.0.14"; /** debug flags for the runtime */ interface DebugConfig { From 601b9a8e6bf85843dfd233673a86c6fe05190204 Mon Sep 17 00:00:00 2001 From: Jonas Strehle Date: Thu, 5 Mar 2026 20:05:07 +0100 Subject: [PATCH 02/10] fix #56 --- Cargo.lock | 26 ++++++++++++---------- rs-lib/Cargo.toml | 6 ++--- src/dif/core.ts | 1 + src/dif/dif-handler.ts | 15 +++++++++++++ src/lib/special-core-types/range.ts | 34 +++++++++++++++++++++++++++++ test/runtime/execute.test.ts | 9 ++++++++ 6 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 src/lib/special-core-types/range.ts diff --git a/Cargo.lock b/Cargo.lock index e3b2dd6c..7b398b39 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -350,9 +350,8 @@ dependencies = [ [[package]] name = "datex-core" -version = "0.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "828f8fd2544e3e7062641e6e1bc64cf2d05d749f8f0765d0f4fd4e588c2a080d" +version = "0.0.11" +source = "git+https://github.com/unyt-org/datex?branch=release%2F0.0.11#fe3421a6e19ef07285ab914fd3436805e477f000" dependencies = [ "ariadne", "async-select", @@ -406,8 +405,7 @@ dependencies = [ [[package]] name = "datex-crypto-facade" version = "0.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56ea2af04cab3b42b4ab122ed2e850a7837e6d402bb4b9a9ffe0b9cfca7ad26d" +source = "git+https://github.com/unyt-org/datex?branch=release%2F0.0.11#fe3421a6e19ef07285ab914fd3436805e477f000" dependencies = [ "bs58", ] @@ -415,8 +413,7 @@ dependencies = [ [[package]] name = "datex-crypto-web" version = "0.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07a56e4ff8e888b4609dd502a1f63e17fd669ae050eee06af97f2a195bdb77c0" +source = "git+https://github.com/unyt-org/datex?branch=release%2F0.0.11#fe3421a6e19ef07285ab914fd3436805e477f000" dependencies = [ "datex-crypto-facade", "wasm-bindgen", @@ -427,8 +424,7 @@ dependencies = [ [[package]] name = "datex-macros-internal" version = "0.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6717768303603f37c8d6fd393ae7da7b78ae33b1ad0d6980253fa19005d0b84" +source = "git+https://github.com/unyt-org/datex?branch=release%2F0.0.11#fe3421a6e19ef07285ab914fd3436805e477f000" dependencies = [ "proc-macro2", "quote", @@ -2283,9 +2279,9 @@ dependencies = [ [[package]] name = "winnow" -version = "0.7.14" +version = "0.7.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829" +checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945" dependencies = [ "memchr", ] @@ -2393,3 +2389,11 @@ name = "zmij" version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" + +[[patch.unused]] +name = "datex-core" +version = "0.0.11" + +[[patch.unused]] +name = "datex-crypto-facade" +version = "0.0.2" diff --git a/rs-lib/Cargo.toml b/rs-lib/Cargo.toml index 9b797513..80d25c60 100644 --- a/rs-lib/Cargo.toml +++ b/rs-lib/Cargo.toml @@ -20,16 +20,14 @@ panic = "abort" [dependencies] log = { version = "0.4", features = ["std", "serde"] } -datex-core = { version = "0.0.10", default-features = false, features = [ +datex-core = { git = "https://github.com/unyt-org/datex", branch = "release/0.0.11", version = "0.0.11", default-features = false, features = [ "target_wasm", "compiler", "decompiler", "syntax_highlighting_legacy", "lsp_wasm", ] } -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" } +datex-crypto-facade = { git = "https://github.com/unyt-org/datex", branch = "release/0.0.11", version = "0.0.2" } async-trait = "0.1.87" url = { version = "2.5.7" } diff --git a/src/dif/core.ts b/src/dif/core.ts index d12aac14..4a1e0c2f 100644 --- a/src/dif/core.ts +++ b/src/dif/core.ts @@ -13,6 +13,7 @@ export const CoreTypeAddress = { map: "0c0000", never: "0d0000", unknown: "0e0000", + range: "100000", decimal: "2c0100", decimal_f32: "2d0100", decimal_f64: "2e0100", diff --git a/src/dif/dif-handler.ts b/src/dif/dif-handler.ts index a27bca2b..575e7b74 100644 --- a/src/dif/dif-handler.ts +++ b/src/dif/dif-handler.ts @@ -1,6 +1,7 @@ import type { JSRuntime, RuntimeDIFHandle } from "../datex.ts"; import { Ref } from "../refs/ref.ts"; import { Endpoint } from "../lib/special-core-types/endpoint.ts"; +import { Range } from "../lib/special-core-types/range.ts"; import { type DIFArray, type DIFMap, @@ -410,6 +411,20 @@ export class DIFHandler { } // endpoint types are resolved to Endpoint instances else if (type === CoreTypeAddress.endpoint) { return Endpoint.get(value.value as string) as T; + } else if (type === CoreTypeAddress.range) { + const [start, end] = value.value as DIFArray; + const result = this.promiseAllOrSync([ + this.resolveDIFValueContainer(start), + this.resolveDIFValueContainer(end), + ]); + if (result instanceof Promise) { + return result.then(([start, end]) => { + return Range.get(start, end) as T; + }); + } else { + const [start, end] = result as number[]; + return Range.get(start, end) as T; + } } else if (type === CoreTypeAddress.list) { return this.promiseAllOrSync( (value.value as DIFArray).map((v) => this.resolveDIFValueContainer(v)), diff --git a/src/lib/special-core-types/range.ts b/src/lib/special-core-types/range.ts new file mode 100644 index 00000000..c751a60d --- /dev/null +++ b/src/lib/special-core-types/range.ts @@ -0,0 +1,34 @@ +/** + * Represents a range of numbers with a start and end. + */ +export class Range { + constructor(public start: number, public end: number) {} + + /** + * Gets the length of the range (end - start). + */ + get length(): number { + return this.end - this.start; + } + + /** + * Checks if a given value is within the range (inclusive of start, exclusive of end). + * @param value The number to check. + * @returns True if the value is within the range, false otherwise. + */ + public contains(value: number): boolean { + return value >= this.start && value < this.end; + } + + /** + * Turns a string representation of the range in the format "[start, end)". + * @returns The string representation of the range. + */ + public toString(): string { + return `[${this.start}, ${this.end})`; + } + + public static get(start: number, end: number): Range { + return new Range(start, end); + } +} diff --git a/test/runtime/execute.test.ts b/test/runtime/execute.test.ts index 56f1d210..f8b2cf9c 100644 --- a/test/runtime/execute.test.ts +++ b/test/runtime/execute.test.ts @@ -2,6 +2,7 @@ import { Runtime } from "../../src/runtime/runtime.ts"; import { assertEquals } from "@std/assert"; import { Endpoint } from "../../src/lib/special-core-types/endpoint.ts"; import { CoreTypeAddress } from "../../src/dif/core.ts"; +import { Range } from "../../src/lib/special-core-types/range.ts"; Deno.test("execute sync with string result", async () => { const runtime = await Runtime.create({ endpoint: "@jonas" }); const script = "1 + 2"; @@ -112,6 +113,14 @@ Deno.test("execute sync endpoint", async () => { assertEquals(result, Endpoint.get("@jonas")); }); +Deno.test("execute sync range", async () => { + const runtime = await Runtime.create({ endpoint: "@jonas" }); + const result = runtime.executeSync("1..2"); + assertEquals(result.start, 1); + assertEquals(result.end, 2); + assertEquals(result, Range.get(1, 2)); +}); + Deno.test("execute sync pass number from JS", async () => { const runtime = await Runtime.create({ endpoint: "@jonas" }); const result = runtime.executeSync("1 + ?", [41]); From a3a5c550fe261e2162ad2c5172c029cc5c95a77c Mon Sep 17 00:00:00 2001 From: Jonas Strehle Date: Thu, 5 Mar 2026 20:30:48 +0100 Subject: [PATCH 03/10] add dev tool formatting for range --- datex-browser-demo/package-lock.json | 2 +- src/lib/special-core-types/range.ts | 9 ++++++++- src/utils/devtools-formatter.ts | 7 +++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/datex-browser-demo/package-lock.json b/datex-browser-demo/package-lock.json index 3f0646ec..7c3fff41 100644 --- a/datex-browser-demo/package-lock.json +++ b/datex-browser-demo/package-lock.json @@ -37,7 +37,7 @@ }, "../npm": { "name": "@unyt/datex", - "version": "0.0.12", + "version": "0.0.14", "license": "MIT" }, "node_modules/@babel/code-frame": { diff --git a/src/lib/special-core-types/range.ts b/src/lib/special-core-types/range.ts index c751a60d..da1588b7 100644 --- a/src/lib/special-core-types/range.ts +++ b/src/lib/special-core-types/range.ts @@ -25,7 +25,14 @@ export class Range { * @returns The string representation of the range. */ public toString(): string { - return `[${this.start}, ${this.end})`; + return `${this.start}...${this.end}`; + } + + get [Symbol.toStringTag](): string { + return this.toString(); + } + get [Symbol.toPrimitive](): string { + return this.toString(); } public static get(start: number, end: number): Range { diff --git a/src/utils/devtools-formatter.ts b/src/utils/devtools-formatter.ts index 13998e48..f6c31455 100644 --- a/src/utils/devtools-formatter.ts +++ b/src/utils/devtools-formatter.ts @@ -1,4 +1,5 @@ import { Endpoint } from "../lib/special-core-types/endpoint.ts"; +import { Range } from "../lib/special-core-types/range.ts"; import { Ref } from "../refs/ref.ts"; // @ts-ignore devtoolsFormatters @@ -27,6 +28,12 @@ globalThis.devtoolsFormatters = [ ], ], ]; + } else if (obj instanceof Range) { + return [ + "span", + { style: "color: #d58e12" }, + `${obj.start}...${obj.end}`, + ]; } return null; // fall back to default }, From e69d86ece7418af8e597d6ccc142871ada3ca1c0 Mon Sep 17 00:00:00 2001 From: Jonas Strehle Date: Thu, 5 Mar 2026 20:39:28 +0100 Subject: [PATCH 04/10] add js to dif tests for range --- src/dif/dif-handler.ts | 12 ++++++++++-- src/lib/special-core-types/range.ts | 4 ---- test/runtime/execute.test.ts | 2 +- test/runtime/value-parity.test.ts | 6 +++++- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/dif/dif-handler.ts b/src/dif/dif-handler.ts index 575e7b74..ca6b1ea1 100644 --- a/src/dif/dif-handler.ts +++ b/src/dif/dif-handler.ts @@ -419,11 +419,11 @@ export class DIFHandler { ]); if (result instanceof Promise) { return result.then(([start, end]) => { - return Range.get(start, end) as T; + return new Range(start, end) as T; }); } else { const [start, end] = result as number[]; - return Range.get(start, end) as T; + return new Range(start, end) as T; } } else if (type === CoreTypeAddress.list) { return this.promiseAllOrSync( @@ -1157,6 +1157,14 @@ export class DIFHandler { type: CoreTypeAddress.endpoint, value: value.toString(), }; + } else if (value instanceof Range) { + return { + type: CoreTypeAddress.range, + value: [ + this.convertJSValueToDIFValueContainer(value.start), + this.convertJSValueToDIFValueContainer(value.end), + ], + }; } else if (Array.isArray(value)) { return { value: value.map((v) => this.convertJSValueToDIFValueContainer(v)), diff --git a/src/lib/special-core-types/range.ts b/src/lib/special-core-types/range.ts index da1588b7..059b091d 100644 --- a/src/lib/special-core-types/range.ts +++ b/src/lib/special-core-types/range.ts @@ -34,8 +34,4 @@ export class Range { get [Symbol.toPrimitive](): string { return this.toString(); } - - public static get(start: number, end: number): Range { - return new Range(start, end); - } } diff --git a/test/runtime/execute.test.ts b/test/runtime/execute.test.ts index f8b2cf9c..3061cd6e 100644 --- a/test/runtime/execute.test.ts +++ b/test/runtime/execute.test.ts @@ -118,7 +118,7 @@ Deno.test("execute sync range", async () => { const result = runtime.executeSync("1..2"); assertEquals(result.start, 1); assertEquals(result.end, 2); - assertEquals(result, Range.get(1, 2)); + assertEquals(result, new Range(1, 2)); }); Deno.test("execute sync pass number from JS", async () => { diff --git a/test/runtime/value-parity.test.ts b/test/runtime/value-parity.test.ts index 4367cc61..cf3fc3c9 100644 --- a/test/runtime/value-parity.test.ts +++ b/test/runtime/value-parity.test.ts @@ -4,7 +4,9 @@ * This is a test for the full integration of the JS runtime with the DATEX runtime. * NOTE: as more JS values are supported, this test should be extended to cover all of them. */ -import { Runtime } from "../../src/runtime/runtime.ts"; +import { Endpoint } from "datex/lib/special-core-types/endpoint.ts"; +import { Runtime } from "datex/runtime/runtime.ts"; +import { Range } from "datex/lib/special-core-types/range.ts"; import { assertEquals } from "@std/assert"; /** @@ -38,6 +40,8 @@ const TEST_VALUES = [ Infinity, -Infinity, 2000n, + Endpoint.get("@test"), + new Range(1, 2), ] as const; // initialization of the test cases From d7532c7b17749400c1d5310ccae3d03b6f8cb9f8 Mon Sep 17 00:00:00 2001 From: Jonas Strehle Date: Thu, 5 Mar 2026 20:49:02 +0100 Subject: [PATCH 05/10] Enhance range support: update websocket URL, refine Range toString method, and improve devtools formatting for Range instances --- datex-browser-demo/src/demo/demo-runtime.ts | 10 ++++++++-- src/lib/special-core-types/range.ts | 4 ++-- src/mod.ts | 2 ++ src/utils/devtools-formatter.ts | 18 ++++++++++++++++-- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/datex-browser-demo/src/demo/demo-runtime.ts b/datex-browser-demo/src/demo/demo-runtime.ts index fe27390f..1efb1b01 100644 --- a/datex-browser-demo/src/demo/demo-runtime.ts +++ b/datex-browser-demo/src/demo/demo-runtime.ts @@ -1,4 +1,4 @@ -import { Ref, Runtime } from "datex"; +import { Endpoint, Range, Ref, Runtime } from "datex"; export const runtime = await Runtime.create( { @@ -6,7 +6,7 @@ export const runtime = await Runtime.create( { type: "websocket-client", config: { - url: "ws://localhost:8043", + url: "wss://example.unyt.land", }, }, ], @@ -25,3 +25,9 @@ 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; diff --git a/src/lib/special-core-types/range.ts b/src/lib/special-core-types/range.ts index 059b091d..0b272c8d 100644 --- a/src/lib/special-core-types/range.ts +++ b/src/lib/special-core-types/range.ts @@ -21,11 +21,11 @@ export class Range { } /** - * Turns a string representation of the range in the format "[start, end)". + * Turns a string representation of the range in the format * @returns The string representation of the range. */ public toString(): string { - return `${this.start}...${this.end}`; + return `${this.start}..${this.end}`; } get [Symbol.toStringTag](): string { diff --git a/src/mod.ts b/src/mod.ts index 88027378..c643a755 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -23,5 +23,7 @@ export * from "./runtime/runtime.ts"; export * as DIF from "./dif/mod.ts"; export * as Network from "./network/mod.ts"; +export * from "./lib/special-core-types/endpoint.ts"; +export * from "./lib/special-core-types/range.ts"; export * from "./refs/ref.ts"; import "./utils/devtools-formatter.ts"; diff --git a/src/utils/devtools-formatter.ts b/src/utils/devtools-formatter.ts index f6c31455..c9d14b20 100644 --- a/src/utils/devtools-formatter.ts +++ b/src/utils/devtools-formatter.ts @@ -31,8 +31,22 @@ globalThis.devtoolsFormatters = [ } else if (obj instanceof Range) { return [ "span", - { style: "color: #d58e12" }, - `${obj.start}...${obj.end}`, + {}, + [ + "span", + {}, + ["span", { style: "color: #d57258" }, `${obj.start}`], + ], + [ + "span", + {}, + ["span", {}, `..`], + ], + [ + "span", + {}, + ["span", { style: "color: #d57258" }, `${obj.end}`], + ], ]; } return null; // fall back to default From b8873e1ca041fdd309b2872b5ab1cacfbf47e96d Mon Sep 17 00:00:00 2001 From: Jonas Strehle Date: Thu, 5 Mar 2026 20:58:10 +0100 Subject: [PATCH 06/10] fix lint --- .github/workflows/test.yml | 29 ++++++++++++++++++-------- src/lib/special-core-types/endpoint.ts | 4 ++-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1cbd653b..3dc85fd9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,6 +4,26 @@ on: pull_request: types: [opened, synchronize] jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + submodules: "true" + - uses: denoland/setup-deno@v2 + with: + deno-version: v2.x + + - name: Check formatting + run: deno fmt --check + + - name: Lint + run: deno lint + + - name: Type Checking + run: deno check -I ./src ./test + build: name: Build runs-on: ubuntu-latest @@ -43,15 +63,6 @@ jobs: with: deno-version: v2.x - - name: Check formatting - run: deno fmt --check - - - name: Lint - run: deno lint - - - name: Type Checking - run: deno check -I ./src ./test - - name: Run Tests run: deno task test-no-build diff --git a/src/lib/special-core-types/endpoint.ts b/src/lib/special-core-types/endpoint.ts index 48e515a2..94ac3be3 100644 --- a/src/lib/special-core-types/endpoint.ts +++ b/src/lib/special-core-types/endpoint.ts @@ -52,11 +52,11 @@ export class Endpoint { return this.#endpoint; } - get [Symbol.toStringTag]() { + get [Symbol.toStringTag](): string { return this.#endpoint; } - get [Symbol.toPrimitive]() { + get [Symbol.toPrimitive](): string { return this.#endpoint; } } From 403d31f0f5379f1c286c60754be44893c9af63ce Mon Sep 17 00:00:00 2001 From: Jonas Strehle Date: Thu, 5 Mar 2026 21:01:26 +0100 Subject: [PATCH 07/10] fix lint --- .github/workflows/test.yml | 44 +++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3dc85fd9..438dc288 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -4,26 +4,6 @@ on: pull_request: types: [opened, synchronize] jobs: - lint: - name: Lint - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - with: - submodules: "true" - - uses: denoland/setup-deno@v2 - with: - deno-version: v2.x - - - name: Check formatting - run: deno fmt --check - - - name: Lint - run: deno lint - - - name: Type Checking - run: deno check -I ./src ./test - build: name: Build runs-on: ubuntu-latest @@ -44,6 +24,30 @@ jobs: ./src/datex-web/datex_web.internal.js ./src/datex-web/datex_web.wasm retention-days: 5 + 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 + - name: Check formatting + run: deno fmt --check + + - name: Lint + run: deno lint + + - name: Type Checking + run: deno check -I ./src ./test test: runs-on: ubuntu-latest From 1d4a5a4a5b6e67ba6467395b181d47dab4ae84ff Mon Sep 17 00:00:00 2001 From: Jonas Strehle Date: Thu, 5 Mar 2026 21:04:49 +0100 Subject: [PATCH 08/10] remove debug flag --- .github/workflows/test.yml | 2 +- deno.json | 6 +++--- rs-lib/Cargo.toml | 1 - 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 438dc288..db0e4841 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: diff --git a/deno.json b/deno.json index 0e8571f6..9c82bfc9 100644 --- a/deno.json +++ b/deno.json @@ -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", @@ -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, diff --git a/rs-lib/Cargo.toml b/rs-lib/Cargo.toml index 80d25c60..973df437 100644 --- a/rs-lib/Cargo.toml +++ b/rs-lib/Cargo.toml @@ -109,7 +109,6 @@ default = [ "webrtc", "lsp", # Make optional ] -debug = [] lsp = ["datex-core/lsp_wasm"] allow_unsigned_blocks = ["datex-core/allow_unsigned_blocks"] From 63c715cb165ce913bc0d760fac10bfc2515d2689 Mon Sep 17 00:00:00 2001 From: Jonas Strehle Date: Thu, 5 Mar 2026 22:35:18 +0100 Subject: [PATCH 09/10] Add REPL support: implement Repl class, update Cargo.toml dependencies, and adjust settings --- .vscode/settings.json | 2 +- Cargo.lock | 12 ----- datex-browser-demo/src/demo/demo-runtime.ts | 7 ++- rs-lib/Cargo.toml | 8 +++- rs-lib/src/lib.rs | 5 ++- rs-lib/src/repl/mod.rs | 45 +++++++++++++++++++ rs-lib/src/runtime.rs | 50 ++++++++++----------- rs-lib/tests/core_types.rs | 2 +- src/datex-web/datex_web.d.ts | 7 +++ src/mod.ts | 1 + src/repl/mod.ts | 14 ++++++ 11 files changed, 107 insertions(+), 46 deletions(-) create mode 100644 rs-lib/src/repl/mod.rs create mode 100644 src/repl/mod.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 58367c64..9391f542 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -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": [] } diff --git a/Cargo.lock b/Cargo.lock index 7b398b39..c267468c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -351,7 +351,6 @@ dependencies = [ [[package]] name = "datex-core" version = "0.0.11" -source = "git+https://github.com/unyt-org/datex?branch=release%2F0.0.11#fe3421a6e19ef07285ab914fd3436805e477f000" dependencies = [ "ariadne", "async-select", @@ -405,7 +404,6 @@ dependencies = [ [[package]] name = "datex-crypto-facade" version = "0.0.2" -source = "git+https://github.com/unyt-org/datex?branch=release%2F0.0.11#fe3421a6e19ef07285ab914fd3436805e477f000" dependencies = [ "bs58", ] @@ -413,7 +411,6 @@ dependencies = [ [[package]] name = "datex-crypto-web" version = "0.0.2" -source = "git+https://github.com/unyt-org/datex?branch=release%2F0.0.11#fe3421a6e19ef07285ab914fd3436805e477f000" dependencies = [ "datex-crypto-facade", "wasm-bindgen", @@ -424,7 +421,6 @@ dependencies = [ [[package]] name = "datex-macros-internal" version = "0.0.1" -source = "git+https://github.com/unyt-org/datex?branch=release%2F0.0.11#fe3421a6e19ef07285ab914fd3436805e477f000" dependencies = [ "proc-macro2", "quote", @@ -2389,11 +2385,3 @@ name = "zmij" version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" - -[[patch.unused]] -name = "datex-core" -version = "0.0.11" - -[[patch.unused]] -name = "datex-crypto-facade" -version = "0.0.2" diff --git a/datex-browser-demo/src/demo/demo-runtime.ts b/datex-browser-demo/src/demo/demo-runtime.ts index 1efb1b01..e2a0c31b 100644 --- a/datex-browser-demo/src/demo/demo-runtime.ts +++ b/datex-browser-demo/src/demo/demo-runtime.ts @@ -1,4 +1,4 @@ -import { Endpoint, Range, Ref, Runtime } from "datex"; +import { Endpoint, Range, Ref, Repl, Runtime } from "datex"; export const runtime = await Runtime.create( { @@ -15,7 +15,7 @@ export const runtime = await Runtime.create( }, }, { - log_level: "warn", + log_level: "info", }, ); @@ -31,3 +31,6 @@ globalThis.Range = Range; // @ts-ignore global variable for debugging globalThis.Endpoint = Endpoint; + +// @ts-ignore global variable for debugging +globalThis.Repl = Repl; diff --git a/rs-lib/Cargo.toml b/rs-lib/Cargo.toml index 973df437..85fecdf8 100644 --- a/rs-lib/Cargo.toml +++ b/rs-lib/Cargo.toml @@ -20,14 +20,16 @@ panic = "abort" [dependencies] log = { version = "0.4", features = ["std", "serde"] } -datex-core = { git = "https://github.com/unyt-org/datex", branch = "release/0.0.11", version = "0.0.11", 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", ] } -datex-crypto-facade = { git = "https://github.com/unyt-org/datex", branch = "release/0.0.11", version = "0.0.2" } +# git = "https://github.com/unyt-org/datex", branch = "release/0.0.11", +datex-crypto-facade = { version = "0.0.2" } async-trait = "0.1.87" url = { version = "2.5.7" } @@ -107,9 +109,11 @@ default = [ "websocket-client", "serial-client", "webrtc", + "repl", "lsp", # Make optional ] lsp = ["datex-core/lsp_wasm"] +repl = [] allow_unsigned_blocks = ["datex-core/allow_unsigned_blocks"] diff --git a/rs-lib/src/lib.rs b/rs-lib/src/lib.rs index c19b4bc9..086d2701 100644 --- a/rs-lib/src/lib.rs +++ b/rs-lib/src/lib.rs @@ -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; @@ -78,4 +81,4 @@ pub async fn create_runtime( }); JSRuntime::run(config).await -} \ No newline at end of file +} diff --git a/rs-lib/src/repl/mod.rs b/rs-lib/src/repl/mod.rs new file mode 100644 index 00000000..f3b73fff --- /dev/null +++ b/rs-lib/src/repl/mod.rs @@ -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 { + 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)) + } +} diff --git a/rs-lib/src/runtime.rs b/rs-lib/src/runtime.rs index 67fe9e60..f43d2b3b 100644 --- a/rs-lib/src/runtime.rs +++ b/rs-lib/src/runtime.rs @@ -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; @@ -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, @@ -98,6 +96,20 @@ impl JSRuntime { js_runtime } + pub fn maybe_value_container_to_dif( + &self, + maybe_value_container: Option, + ) -> 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 } @@ -388,22 +400,6 @@ impl JSRuntime { )) } - fn maybe_value_container_to_dif( - &self, - maybe_value_container: Option, - ) -> 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>, diff --git a/rs-lib/tests/core_types.rs b/rs-lib/tests/core_types.rs index eee4279b..0323ff8b 100644 --- a/rs-lib/tests/core_types.rs +++ b/rs-lib/tests/core_types.rs @@ -1,6 +1,6 @@ use datex_core::{ libs::core::{CoreLibPointerId, create_core_lib_types}, - values::pointer::PointerAddress, + shared_values::pointer_address::PointerAddress, }; #[test] diff --git a/src/datex-web/datex_web.d.ts b/src/datex-web/datex_web.d.ts index 9cd277a0..ac787f37 100644 --- a/src/datex-web/datex_web.d.ts +++ b/src/datex-web/datex_web.d.ts @@ -299,6 +299,13 @@ export class JSRuntime { readonly version: string; } +export class Repl { + free(): void; + [Symbol.dispose](): void; + execute(script: string): Promise; + constructor(runtime: JSRuntime, verbose: boolean); +} + export class RuntimeDIFHandle { private constructor(); free(): void; diff --git a/src/mod.ts b/src/mod.ts index c643a755..a60c2bc7 100644 --- a/src/mod.ts +++ b/src/mod.ts @@ -26,4 +26,5 @@ export * as Network from "./network/mod.ts"; export * from "./lib/special-core-types/endpoint.ts"; export * from "./lib/special-core-types/range.ts"; export * from "./refs/ref.ts"; +export * from "./repl/mod.ts"; import "./utils/devtools-formatter.ts"; diff --git a/src/repl/mod.ts b/src/repl/mod.ts new file mode 100644 index 00000000..1cd42e07 --- /dev/null +++ b/src/repl/mod.ts @@ -0,0 +1,14 @@ +import type { Runtime } from "../runtime/runtime.ts"; +import { Repl as ReplInternal } from "../datex.ts"; +export class Repl { + #repl: ReplInternal; + constructor(private runtime: Runtime, verbose = false) { + this.#repl = new ReplInternal(runtime._runtime, verbose); + } + + public async execute(script: string): Promise { + const result = await this.#repl.execute(script); + const jsValue = this.runtime.dif.resolveDIFValueContainerSync(result); + return this.runtime.valueToString(jsValue); + } +} From fd0b001f30facd825986e267321c86d0d8909284 Mon Sep 17 00:00:00 2001 From: Jonas Strehle Date: Thu, 5 Mar 2026 22:51:07 +0100 Subject: [PATCH 10/10] fix cargo lock --- Cargo.lock | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index c267468c..2a0f3f49 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -351,6 +351,8 @@ dependencies = [ [[package]] name = "datex-core" version = "0.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1471cd0f342832e2a44603ce2c910359d2fd3325f15476359ca99493df421f05" dependencies = [ "ariadne", "async-select", @@ -404,6 +406,8 @@ dependencies = [ [[package]] name = "datex-crypto-facade" version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56ea2af04cab3b42b4ab122ed2e850a7837e6d402bb4b9a9ffe0b9cfca7ad26d" dependencies = [ "bs58", ] @@ -411,6 +415,8 @@ dependencies = [ [[package]] name = "datex-crypto-web" version = "0.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07a56e4ff8e888b4609dd502a1f63e17fd669ae050eee06af97f2a195bdb77c0" dependencies = [ "datex-crypto-facade", "wasm-bindgen", @@ -421,6 +427,8 @@ dependencies = [ [[package]] name = "datex-macros-internal" version = "0.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6717768303603f37c8d6fd393ae7da7b78ae33b1ad0d6980253fa19005d0b84" dependencies = [ "proc-macro2", "quote",