decodal-wasm 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -65
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,82 +1,36 @@
|
|
|
1
|
-
#
|
|
1
|
+
# decodal-wasm
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
WebAssembly runtime package for Decodal.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
This package exposes the Decodal evaluator to browsers and other JavaScript runtimes that can load WebAssembly modules.
|
|
6
|
+
It is generated from the Rust crate in `crates/decodal-wasm` with `wasm-pack` and is used by the official playground.
|
|
6
7
|
|
|
7
|
-
|
|
8
|
-
- no filesystem access in the library core
|
|
9
|
-
- concrete and abstract values with constraints and defaults
|
|
10
|
-
- deterministic expression evaluation
|
|
11
|
-
- optional regex support behind a Cargo feature
|
|
12
|
-
- browser playground support through WebAssembly
|
|
8
|
+
Use `decodal-codemirror` separately when you need CodeMirror 6 language support.
|
|
13
9
|
|
|
14
|
-
##
|
|
15
|
-
|
|
16
|
-
Embedded hosts should depend on `decodal` and provide imports with a `SourceLoader`.
|
|
17
|
-
|
|
18
|
-
```toml
|
|
19
|
-
[dependencies]
|
|
20
|
-
decodal = "0.1"
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## Derive support
|
|
24
|
-
|
|
25
|
-
For embedded Rust applications, Decodal can generate a schema and typed decoder from a Rust struct with the `derive` feature.
|
|
26
|
-
|
|
27
|
-
```toml
|
|
28
|
-
[dependencies]
|
|
29
|
-
decodal = { version = "0.1", features = ["derive"] }
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
```rust
|
|
33
|
-
use decodal::{Decodal, DecodalDecode, DecodalSchema, Engine};
|
|
34
|
-
|
|
35
|
-
#[derive(Decodal)]
|
|
36
|
-
struct Service {
|
|
37
|
-
name: String,
|
|
38
|
-
#[decodal(gt = 443, default = 8443)]
|
|
39
|
-
port: i64,
|
|
40
|
-
#[decodal(rename = "feature.enable", default = true)]
|
|
41
|
-
feature_enabled: bool,
|
|
42
|
-
}
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
The derive implements:
|
|
46
|
-
|
|
47
|
-
- `DecodalSchema`, which produces a host schema for `Engine::bind_global`
|
|
48
|
-
- `DecodalDecode`, which converts materialized `Data` into the Rust struct
|
|
49
|
-
|
|
50
|
-
## CLI
|
|
51
|
-
|
|
52
|
-
A standalone CLI is kept in this repository as the `decodal-cli` workspace package.
|
|
53
|
-
It builds a `decodal` binary, but it is not the primary crates.io package.
|
|
54
|
-
|
|
55
|
-
Run a Decodal file from the repository:
|
|
10
|
+
## Install
|
|
56
11
|
|
|
57
12
|
```sh
|
|
58
|
-
|
|
13
|
+
npm install decodal-wasm
|
|
59
14
|
```
|
|
60
15
|
|
|
61
|
-
|
|
16
|
+
JSR:
|
|
62
17
|
|
|
63
18
|
```sh
|
|
64
|
-
|
|
19
|
+
deno add jsr:@hare/decodal-wasm
|
|
65
20
|
```
|
|
66
21
|
|
|
67
|
-
##
|
|
68
|
-
|
|
69
|
-
The static documentation site and browser playground live under:
|
|
22
|
+
## Usage
|
|
70
23
|
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
```
|
|
24
|
+
```js
|
|
25
|
+
import init, { evaluateProject } from 'decodal-wasm';
|
|
74
26
|
|
|
75
|
-
|
|
27
|
+
await init();
|
|
76
28
|
|
|
77
|
-
|
|
29
|
+
const result = evaluateProject('main.dcdl', JSON.stringify({
|
|
30
|
+
'main.dcdl': 'Server = { port = Int default 8080; };',
|
|
31
|
+
}));
|
|
78
32
|
|
|
79
|
-
|
|
80
|
-
|
|
33
|
+
console.log(JSON.parse(result));
|
|
34
|
+
```
|
|
81
35
|
|
|
82
|
-
|
|
36
|
+
The exported functions return JSON strings so callers can handle diagnostics and successful results without depending on Rust data structures.
|
package/package.json
CHANGED