Compare commits
No commits in common. "master" and "v0.1.2" have entirely different histories.
|
|
@ -30,13 +30,10 @@ Important paths:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
crates/decodal-wasm/
|
crates/decodal-wasm/
|
||||||
packages/decodal-wasm/
|
site/decodal-site/src/wasm/
|
||||||
```
|
```
|
||||||
|
|
||||||
The npm package is `decodal-wasm`.
|
The generated files in `site/decodal-site/src/wasm/` are committed so the site can build without requiring every consumer to run `wasm-pack` first.
|
||||||
The JSR package is `@hare/decodal-wasm`.
|
|
||||||
|
|
||||||
The generated files in `packages/decodal-wasm/` are committed so the site can build without requiring every consumer to run `wasm-pack` first.
|
|
||||||
The WebAssembly package is for execution, not syntax highlighting.
|
The WebAssembly package is for execution, not syntax highlighting.
|
||||||
|
|
||||||
## Web editor components
|
## Web editor components
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ cargo run -q -p decodal-cli --features regex -- examples/regex/main.dcdl
|
||||||
The primary crates.io package is `decodal`, which contains the embeddable library.
|
The primary crates.io package is `decodal`, which contains the embeddable library.
|
||||||
`decodal-derive` provides optional derive macros for Rust struct integration and is published only when the derive crate changes.
|
`decodal-derive` provides optional derive macros for Rust struct integration and is published only when the derive crate changes.
|
||||||
Workspace support crates such as `decodal-cli` and the Rust source crate `decodal-wasm` are not published to crates.io.
|
Workspace support crates such as `decodal-cli` and the Rust source crate `decodal-wasm` are not published to crates.io.
|
||||||
The generated WebAssembly package under `packages/decodal-wasm/` is published to npm and JSR.
|
The generated WebAssembly package under `site/decodal-site/src/wasm/` is published to npm and JSR.
|
||||||
The project is dual licensed as `MIT OR Apache-2.0`.
|
The project is dual licensed as `MIT OR Apache-2.0`.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
|
@ -72,8 +72,6 @@ site/decodal-site/src/lib/docs.js
|
||||||
site/decodal-site/src/lib/highlight.js
|
site/decodal-site/src/lib/highlight.js
|
||||||
packages/decodal-codemirror/src/decodal.js
|
packages/decodal-codemirror/src/decodal.js
|
||||||
packages/decodal-codemirror/src/decodal-parser.js
|
packages/decodal-codemirror/src/decodal-parser.js
|
||||||
packages/decodal-wasm/decodal_wasm.js
|
|
||||||
packages/decodal-wasm/decodal_wasm_bg.wasm
|
|
||||||
crates/decodal-wasm/src/lib.rs
|
crates/decodal-wasm/src/lib.rs
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -89,7 +87,7 @@ npm run build
|
||||||
`npm run build:wasm` writes generated files into:
|
`npm run build:wasm` writes generated files into:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
packages/decodal-wasm/
|
site/decodal-site/src/wasm/
|
||||||
```
|
```
|
||||||
|
|
||||||
These generated files are committed so the site can be built without requiring every consumer to regenerate the wasm package first.
|
These generated files are committed so the site can be built without requiring every consumer to regenerate the wasm package first.
|
||||||
|
|
@ -97,7 +95,7 @@ These generated files are committed so the site can be built without requiring e
|
||||||
Publish the generated WebAssembly package from its package directory:
|
Publish the generated WebAssembly package from its package directory:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cd packages/decodal-wasm
|
cd site/decodal-site/src/wasm
|
||||||
npm publish
|
npm publish
|
||||||
npx jsr publish
|
npx jsr publish
|
||||||
```
|
```
|
||||||
|
|
|
||||||
1
packages/decodal-wasm/.gitignore
vendored
1
packages/decodal-wasm/.gitignore
vendored
|
|
@ -1 +0,0 @@
|
||||||
# wasm-pack output is committed for the browser runtime package.
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
# decodal-wasm
|
|
||||||
|
|
||||||
WebAssembly runtime package for Decodal.
|
|
||||||
|
|
||||||
This package exposes the Decodal evaluator to browsers and other JavaScript runtimes that can load WebAssembly modules.
|
|
||||||
It is generated from the Rust crate in `crates/decodal-wasm` with `wasm-pack` and is used by the official playground.
|
|
||||||
|
|
||||||
Use `decodal-codemirror` separately when you need CodeMirror 6 language support.
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
```sh
|
|
||||||
npm install decodal-wasm
|
|
||||||
```
|
|
||||||
|
|
||||||
JSR:
|
|
||||||
|
|
||||||
```sh
|
|
||||||
deno add jsr:@hare/decodal-wasm
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```js
|
|
||||||
import init, { evaluateProject } from 'decodal-wasm';
|
|
||||||
|
|
||||||
await init();
|
|
||||||
|
|
||||||
const result = evaluateProject(JSON.stringify({
|
|
||||||
entry: 'main.dcdl',
|
|
||||||
files: {
|
|
||||||
'main.dcdl': 'Server = { port = Int default 8080; };',
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
console.log(JSON.parse(result));
|
|
||||||
```
|
|
||||||
|
|
||||||
The exported functions return JSON strings so callers can handle diagnostics and successful results without depending on Rust data structures.
|
|
||||||
9
site/decodal-site/package-lock.json
generated
9
site/decodal-site/package-lock.json
generated
|
|
@ -16,7 +16,6 @@
|
||||||
"astro": "^4.16.18",
|
"astro": "^4.16.18",
|
||||||
"codemirror": "^6.0.2",
|
"codemirror": "^6.0.2",
|
||||||
"decodal-codemirror": "file:../../packages/decodal-codemirror",
|
"decodal-codemirror": "file:../../packages/decodal-codemirror",
|
||||||
"decodal-wasm": "file:../../packages/decodal-wasm",
|
|
||||||
"marked": "^12.0.2"
|
"marked": "^12.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
@ -33,10 +32,6 @@
|
||||||
"@lezer/lr": "^1.4.10"
|
"@lezer/lr": "^1.4.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"../../packages/decodal-wasm": {
|
|
||||||
"version": "0.1.2",
|
|
||||||
"license": "MIT OR Apache-2.0"
|
|
||||||
},
|
|
||||||
"node_modules/@astrojs/check": {
|
"node_modules/@astrojs/check": {
|
||||||
"version": "0.9.9",
|
"version": "0.9.9",
|
||||||
"resolved": "https://registry.npmjs.org/@astrojs/check/-/check-0.9.9.tgz",
|
"resolved": "https://registry.npmjs.org/@astrojs/check/-/check-0.9.9.tgz",
|
||||||
|
|
@ -3255,10 +3250,6 @@
|
||||||
"resolved": "../../packages/decodal-codemirror",
|
"resolved": "../../packages/decodal-codemirror",
|
||||||
"link": true
|
"link": true
|
||||||
},
|
},
|
||||||
"node_modules/decodal-wasm": {
|
|
||||||
"resolved": "../../packages/decodal-wasm",
|
|
||||||
"link": true
|
|
||||||
},
|
|
||||||
"node_modules/decode-named-character-reference": {
|
"node_modules/decode-named-character-reference": {
|
||||||
"version": "1.3.0",
|
"version": "1.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/decode-named-character-reference/-/decode-named-character-reference-1.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/decode-named-character-reference/-/decode-named-character-reference-1.3.0.tgz",
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
"dev": "astro dev --host 0.0.0.0",
|
"dev": "astro dev --host 0.0.0.0",
|
||||||
"build": "astro build",
|
"build": "astro build",
|
||||||
"preview": "astro preview --host 0.0.0.0",
|
"preview": "astro preview --host 0.0.0.0",
|
||||||
"build:wasm": "wasm-pack build ../../crates/decodal-wasm --target web --out-dir ../../packages/decodal-wasm --release && node scripts/prepare-wasm-package.mjs",
|
"build:wasm": "wasm-pack build ../../crates/decodal-wasm --target web --out-dir ../../site/decodal-site/src/wasm --release",
|
||||||
"deploy": "npm run build && node scripts/deploy-pages.mjs",
|
"deploy": "npm run build && node scripts/deploy-pages.mjs",
|
||||||
"deploy:wasm": "npm run build:wasm && npm run deploy"
|
"deploy:wasm": "npm run build:wasm && npm run deploy"
|
||||||
},
|
},
|
||||||
|
|
@ -20,7 +20,6 @@
|
||||||
"astro": "^4.16.18",
|
"astro": "^4.16.18",
|
||||||
"codemirror": "^6.0.2",
|
"codemirror": "^6.0.2",
|
||||||
"decodal-codemirror": "file:../../packages/decodal-codemirror",
|
"decodal-codemirror": "file:../../packages/decodal-codemirror",
|
||||||
"decodal-wasm": "file:../../packages/decodal-wasm",
|
|
||||||
"marked": "^12.0.2"
|
"marked": "^12.0.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
import { writeFileSync } from 'node:fs';
|
|
||||||
import { resolve } from 'node:path';
|
|
||||||
|
|
||||||
const packageDir = resolve(import.meta.dirname, '../../../packages/decodal-wasm');
|
|
||||||
|
|
||||||
writeFileSync(
|
|
||||||
resolve(packageDir, '.gitignore'),
|
|
||||||
'# wasm-pack output is committed for the browser runtime package.\n',
|
|
||||||
);
|
|
||||||
|
|
||||||
writeFileSync(
|
|
||||||
resolve(packageDir, 'README.md'),
|
|
||||||
`# decodal-wasm
|
|
||||||
|
|
||||||
WebAssembly runtime package for Decodal.
|
|
||||||
|
|
||||||
This package exposes the Decodal evaluator to browsers and other JavaScript runtimes that can load WebAssembly modules.
|
|
||||||
It is generated from the Rust crate in \`crates/decodal-wasm\` with \`wasm-pack\` and is used by the official playground.
|
|
||||||
|
|
||||||
Use \`decodal-codemirror\` separately when you need CodeMirror 6 language support.
|
|
||||||
|
|
||||||
## Install
|
|
||||||
|
|
||||||
\`\`\`sh
|
|
||||||
npm install decodal-wasm
|
|
||||||
\`\`\`
|
|
||||||
|
|
||||||
JSR:
|
|
||||||
|
|
||||||
\`\`\`sh
|
|
||||||
deno add jsr:@hare/decodal-wasm
|
|
||||||
\`\`\`
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
\`\`\`js
|
|
||||||
import init, { evaluateProject } from 'decodal-wasm';
|
|
||||||
|
|
||||||
await init();
|
|
||||||
|
|
||||||
const result = evaluateProject(JSON.stringify({
|
|
||||||
entry: 'main.dcdl',
|
|
||||||
files: {
|
|
||||||
'main.dcdl': 'Server = { port = Int default 8080; };',
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
|
|
||||||
console.log(JSON.parse(result));
|
|
||||||
\`\`\`
|
|
||||||
|
|
||||||
The exported functions return JSON strings so callers can handle diagnostics and successful results without depending on Rust data structures.
|
|
||||||
`,
|
|
||||||
);
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import init, { evaluateProject } from 'decodal-wasm';
|
import init, { evaluateProject } from '../wasm/decodal_wasm.js';
|
||||||
import { EditorView, basicSetup } from 'codemirror';
|
import { EditorView, basicSetup } from 'codemirror';
|
||||||
import { keymap } from '@codemirror/view';
|
import { keymap } from '@codemirror/view';
|
||||||
import { decodal } from 'decodal-codemirror';
|
import { decodal } from 'decodal-codemirror';
|
||||||
|
|
|
||||||
1
site/decodal-site/src/wasm/.gitignore
vendored
Normal file
1
site/decodal-site/src/wasm/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
# wasm-pack output is committed for the playground build.
|
||||||
82
site/decodal-site/src/wasm/README.md
Normal file
82
site/decodal-site/src/wasm/README.md
Normal file
|
|
@ -0,0 +1,82 @@
|
||||||
|
# Decodal
|
||||||
|
|
||||||
|
Decodal is a small deterministic DSL for describing, composing, validating, and materializing structured data.
|
||||||
|
|
||||||
|
It is designed around a lightweight Rust library:
|
||||||
|
|
||||||
|
- host-supplied imports through `SourceLoader`
|
||||||
|
- no filesystem access in the library core
|
||||||
|
- concrete and abstract values with constraints and defaults
|
||||||
|
- deterministic expression evaluation
|
||||||
|
- optional regex support behind a Cargo feature
|
||||||
|
- browser playground support through WebAssembly
|
||||||
|
|
||||||
|
## Library crate
|
||||||
|
|
||||||
|
Embedded hosts should depend on `decodal` and provide imports with a `SourceLoader`.
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[dependencies]
|
||||||
|
decodal = "0.1"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Derive support
|
||||||
|
|
||||||
|
For embedded Rust applications, Decodal can generate a schema and typed decoder from a Rust struct with the `derive` feature.
|
||||||
|
|
||||||
|
```toml
|
||||||
|
[dependencies]
|
||||||
|
decodal = { version = "0.1", features = ["derive"] }
|
||||||
|
```
|
||||||
|
|
||||||
|
```rust
|
||||||
|
use decodal::{Decodal, DecodalDecode, DecodalSchema, Engine};
|
||||||
|
|
||||||
|
#[derive(Decodal)]
|
||||||
|
struct Service {
|
||||||
|
name: String,
|
||||||
|
#[decodal(gt = 443, default = 8443)]
|
||||||
|
port: i64,
|
||||||
|
#[decodal(rename = "feature.enable", default = true)]
|
||||||
|
feature_enabled: bool,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The derive implements:
|
||||||
|
|
||||||
|
- `DecodalSchema`, which produces a host schema for `Engine::bind_global`
|
||||||
|
- `DecodalDecode`, which converts materialized `Data` into the Rust struct
|
||||||
|
|
||||||
|
## CLI
|
||||||
|
|
||||||
|
A standalone CLI is kept in this repository as the `decodal-cli` workspace package.
|
||||||
|
It builds a `decodal` binary, but it is not the primary crates.io package.
|
||||||
|
|
||||||
|
Run a Decodal file from the repository:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cargo run -q -p decodal-cli -- examples/advanced/main.dcdl
|
||||||
|
```
|
||||||
|
|
||||||
|
Enable optional regex support when needed:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
cargo run -q -p decodal-cli --features regex -- examples/regex/main.dcdl
|
||||||
|
```
|
||||||
|
|
||||||
|
## Web playground
|
||||||
|
|
||||||
|
The static documentation site and browser playground live under:
|
||||||
|
|
||||||
|
```text
|
||||||
|
site/decodal-site/
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
Licensed under either of:
|
||||||
|
|
||||||
|
- Apache License, Version 2.0
|
||||||
|
- MIT license
|
||||||
|
|
||||||
|
at your option.
|
||||||
Loading…
Reference in New Issue
Block a user