Move wasm package under packages
This commit is contained in:
parent
e4b9247c45
commit
16006d000a
|
|
@ -30,10 +30,13 @@ Important paths:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
crates/decodal-wasm/
|
crates/decodal-wasm/
|
||||||
site/decodal-site/src/wasm/
|
packages/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 npm package is `decodal-wasm`.
|
||||||
|
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 `site/decodal-site/src/wasm/` is published to npm and JSR.
|
The generated WebAssembly package under `packages/decodal-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,6 +72,8 @@ 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
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -87,7 +89,7 @@ npm run build
|
||||||
`npm run build:wasm` writes generated files into:
|
`npm run build:wasm` writes generated files into:
|
||||||
|
|
||||||
```text
|
```text
|
||||||
site/decodal-site/src/wasm/
|
packages/decodal-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.
|
||||||
|
|
@ -95,7 +97,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 site/decodal-site/src/wasm
|
cd packages/decodal-wasm
|
||||||
npm publish
|
npm publish
|
||||||
npx jsr publish
|
npx jsr publish
|
||||||
```
|
```
|
||||||
|
|
|
||||||
1
packages/decodal-wasm/.gitignore
vendored
Normal file
1
packages/decodal-wasm/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
# wasm-pack output is committed for the browser runtime package.
|
||||||
39
packages/decodal-wasm/README.md
Normal file
39
packages/decodal-wasm/README.md
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
# 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,6 +16,7 @@
|
||||||
"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": {
|
||||||
|
|
@ -32,6 +33,10 @@
|
||||||
"@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",
|
||||||
|
|
@ -3250,6 +3255,10 @@
|
||||||
"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 ../../site/decodal-site/src/wasm --release",
|
"build:wasm": "wasm-pack build ../../crates/decodal-wasm --target web --out-dir ../../packages/decodal-wasm --release && node scripts/prepare-wasm-package.mjs",
|
||||||
"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,6 +20,7 @@
|
||||||
"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": {
|
||||||
|
|
|
||||||
53
site/decodal-site/scripts/prepare-wasm-package.mjs
Normal file
53
site/decodal-site/scripts/prepare-wasm-package.mjs
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
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 '../wasm/decodal_wasm.js';
|
import init, { evaluateProject } from 'decodal-wasm';
|
||||||
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
1
site/decodal-site/src/wasm/.gitignore
vendored
|
|
@ -1 +0,0 @@
|
||||||
# wasm-pack output is committed for the playground build.
|
|
||||||
|
|
@ -1,82 +0,0 @@
|
||||||
# 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