Compare commits
No commits in common. "6e2363632b4d22fcc563160eedb02d5ef42a929a" and "d8af980f7d33774d275ddeb67d69dae00327a593" have entirely different histories.
6e2363632b
...
d8af980f7d
19
Cargo.toml
19
Cargo.toml
|
|
@ -4,16 +4,11 @@ members = [
|
|||
"crates/decodal-cli",
|
||||
"crates/decodal-wasm",
|
||||
]
|
||||
resolver = "2"
|
||||
resolver = "3"
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
rust-version = "1.85"
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://gitea.hareworks.net/Hare/Decodal"
|
||||
readme = "README.md"
|
||||
|
||||
[workspace.dependencies]
|
||||
serde_json = "1"
|
||||
wasm-bindgen = "0.2"
|
||||
[profile.release]
|
||||
opt-level = "z"
|
||||
lto = true
|
||||
codegen-units = 1
|
||||
strip = true
|
||||
panic = "abort"
|
||||
|
|
|
|||
173
LICENSE-APACHE
173
LICENSE-APACHE
|
|
@ -1,173 +0,0 @@
|
|||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
21
LICENSE-MIT
21
LICENSE-MIT
|
|
@ -1,21 +0,0 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2026 Decodal contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
56
README.md
56
README.md
|
|
@ -1,56 +0,0 @@
|
|||
# Decodal
|
||||
|
||||
Decodal is a small deterministic DSL for describing, composing, validating, and materializing structured data.
|
||||
|
||||
It is designed around a lightweight Rust core:
|
||||
|
||||
- host-supplied imports through `SourceLoader`
|
||||
- no filesystem access in `decodal-core`
|
||||
- concrete and abstract values with constraints and defaults
|
||||
- deterministic expression evaluation
|
||||
- optional regex support behind a Cargo feature
|
||||
- browser playground support through WebAssembly
|
||||
|
||||
## Install the CLI
|
||||
|
||||
```sh
|
||||
cargo install decodal
|
||||
```
|
||||
|
||||
Run a Decodal file:
|
||||
|
||||
```sh
|
||||
decodal examples/advanced/main.dcdl
|
||||
```
|
||||
|
||||
Enable optional regex support when needed:
|
||||
|
||||
```sh
|
||||
cargo install decodal --features regex
|
||||
```
|
||||
|
||||
## Library crate
|
||||
|
||||
Embedded hosts should depend on `decodal-core` and provide imports with a `SourceLoader`.
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
decodal-core = "0.1"
|
||||
```
|
||||
|
||||
## 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.
|
||||
|
|
@ -1,18 +1,11 @@
|
|||
[package]
|
||||
name = "decodal"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
readme.workspace = true
|
||||
description = "Command-line interface for the Decodal data description language."
|
||||
keywords = ["decodal", "dsl", "config", "cli"]
|
||||
categories = ["command-line-utilities", "config"]
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
regex = ["decodal-core/regex"]
|
||||
|
||||
[dependencies]
|
||||
decodal-core = { version = "0.1.0", path = "../decodal-core" }
|
||||
decodal-core = { path = "../decodal-core" }
|
||||
|
|
|
|||
|
|
@ -1,14 +1,7 @@
|
|||
[package]
|
||||
name = "decodal-core"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
readme.workspace = true
|
||||
description = "Core parser, evaluator, and embedding API for the Decodal data description language."
|
||||
keywords = ["decodal", "dsl", "config", "schema"]
|
||||
categories = ["config", "parser-implementations"]
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
|
|
|
|||
|
|
@ -1,22 +1,15 @@
|
|||
[package]
|
||||
name = "decodal-wasm"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
rust-version.workspace = true
|
||||
license.workspace = true
|
||||
repository.workspace = true
|
||||
readme.workspace = true
|
||||
description = "WebAssembly wrapper for evaluating Decodal in browser playgrounds."
|
||||
keywords = ["decodal", "wasm", "dsl", "config"]
|
||||
categories = ["wasm", "config"]
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[dependencies]
|
||||
decodal-core = { version = "0.1.0", path = "../decodal-core" }
|
||||
serde_json.workspace = true
|
||||
wasm-bindgen.workspace = true
|
||||
decodal-core = { path = "../decodal-core" }
|
||||
serde_json = "1"
|
||||
wasm-bindgen = "0.2"
|
||||
|
||||
[package.metadata.wasm-pack.profile.release]
|
||||
wasm-opt = false
|
||||
|
|
|
|||
|
|
@ -20,29 +20,6 @@ cargo test -p decodal-core --features regex
|
|||
cargo run -q -p decodal --features regex -- examples/regex/main.dcdl
|
||||
```
|
||||
|
||||
## crates.io release
|
||||
|
||||
Crates are published as versioned workspace packages under the dual license `MIT OR Apache-2.0`.
|
||||
The dependency order matters because `decodal` and `decodal-wasm` depend on `decodal-core` from crates.io.
|
||||
|
||||
```sh
|
||||
cargo publish -p decodal-core
|
||||
# wait until crates.io index has decodal-core 0.1.0
|
||||
cargo publish -p decodal
|
||||
cargo publish -p decodal-wasm
|
||||
```
|
||||
|
||||
Before publishing, run:
|
||||
|
||||
```sh
|
||||
cargo fmt --check
|
||||
cargo test
|
||||
cargo check -p decodal-core --no-default-features
|
||||
cargo publish -p decodal-core --dry-run
|
||||
```
|
||||
|
||||
`cargo publish --dry-run` for `decodal` and `decodal-wasm` will fail until the matching `decodal-core` version is already visible in the crates.io index.
|
||||
|
||||
## Web site and playground
|
||||
|
||||
The Astro documentation site and browser playground are kept in:
|
||||
|
|
@ -95,8 +72,7 @@ cd site/decodal-site
|
|||
npm run deploy
|
||||
```
|
||||
|
||||
The deploy script runs `npm run build` and then uploads `dist/` to the Pages project named `decodal-site` on branch `master`.
|
||||
Cloudflare Pages treats this as production when the project production branch is `master`.
|
||||
The deploy script runs `npm run build` and then uploads `dist/` to the Pages project named `decodal-site`.
|
||||
Use `CLOUDFLARE_PROJECT_NAME` when deploying to a differently named Pages project.
|
||||
|
||||
```sh
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
"build": "astro build",
|
||||
"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",
|
||||
"deploy": "npm run build && wrangler pages deploy dist --project-name ${CLOUDFLARE_PROJECT_NAME:-decodal-site} --branch ${CLOUDFLARE_BRANCH:-master}",
|
||||
"deploy": "npm run build && wrangler pages deploy dist --project-name ${CLOUDFLARE_PROJECT_NAME:-decodal-site}",
|
||||
"deploy:wasm": "npm run build:wasm && npm run deploy"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
|
|||
|
|
@ -9,11 +9,6 @@ import ManualLayout from '../layouts/ManualLayout.astro';
|
|||
<p>Virtual files are evaluated in the browser through WebAssembly. Use import paths such as <code>./schemas/service.dcdl</code>.</p>
|
||||
</div>
|
||||
<div class="playground-actions">
|
||||
<label class="example-picker">
|
||||
<span>Example</span>
|
||||
<select id="example-select" aria-label="Playground example"></select>
|
||||
</label>
|
||||
<button id="load-example" type="button">Load</button>
|
||||
<p id="status" class="status">Loading WASM...</p>
|
||||
<button id="run" disabled>Run</button>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,174 +0,0 @@
|
|||
export const playgroundExamples = [
|
||||
{
|
||||
id: 'service-deployment',
|
||||
title: 'Service deployment',
|
||||
activePath: 'main.dcdl',
|
||||
files: {
|
||||
'main.dcdl': `let
|
||||
schema = import "./schemas/service.dcdl";
|
||||
prod = import "./env/prod.dcdl";
|
||||
shared = import "./shared/tags.dcdl";
|
||||
in
|
||||
schema.Service & prod.ServicePatch & {
|
||||
name = "api";
|
||||
image = "registry.example.com/api:2026-06-24";
|
||||
port = 9000 + 443;
|
||||
public = prod.is_public && 9000 + 443 > 9000;
|
||||
tags = shared.common ++ ["api", "edge"];
|
||||
}
|
||||
`,
|
||||
'schemas/service.dcdl': `Service = {
|
||||
name = String;
|
||||
image = String;
|
||||
port = Int & > 443 default 8443;
|
||||
replicas = Int & > 0 default 2;
|
||||
public = Bool default false;
|
||||
feature.metrics = Bool default true;
|
||||
feature.tracing = Bool default false;
|
||||
};
|
||||
`,
|
||||
'env/prod.dcdl': `is_public = true;
|
||||
|
||||
ServicePatch = {
|
||||
replicas = 3;
|
||||
feature.tracing = true;
|
||||
};
|
||||
`,
|
||||
'shared/tags.dcdl': `common = ["decodal", "prod"];
|
||||
`,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'access-policy',
|
||||
title: 'Access policy',
|
||||
activePath: 'main.dcdl',
|
||||
files: {
|
||||
'main.dcdl': `let
|
||||
policy = import "./policy/base.dcdl";
|
||||
teams = import "./policy/teams.dcdl";
|
||||
env = "prod";
|
||||
in
|
||||
{
|
||||
service = "payments";
|
||||
readers = policy.defaultReaders ++ teams.observability;
|
||||
writers = policy.defaultWriters ++ teams.payments;
|
||||
admins = match env {
|
||||
"prod": policy.breakglassAdmins;
|
||||
_: teams.platform;
|
||||
};
|
||||
audit.required = env == "prod";
|
||||
audit.retention_days = match env {
|
||||
"prod": 365;
|
||||
_: 30;
|
||||
};
|
||||
}
|
||||
`,
|
||||
'policy/base.dcdl': `defaultReaders = ["group:engineering", "group:support"];
|
||||
defaultWriters = ["group:platform"];
|
||||
breakglassAdmins = ["user:oncall-primary", "user:oncall-secondary"];
|
||||
`,
|
||||
'policy/teams.dcdl': `platform = ["group:platform-admins"];
|
||||
payments = ["group:payments-api", "group:payments-sre"];
|
||||
observability = ["group:observability"];
|
||||
`,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'edge-worker',
|
||||
title: 'Edge worker config',
|
||||
activePath: 'main.dcdl',
|
||||
files: {
|
||||
'main.dcdl': `let
|
||||
schema = import "./schemas/worker.dcdl";
|
||||
routes = import "./routes.dcdl";
|
||||
production = true;
|
||||
in
|
||||
schema.Worker & {
|
||||
name = "decodal-docs";
|
||||
compatibility_date = "2026-06-15";
|
||||
workers_dev = !production;
|
||||
route.host = routes.primary_host;
|
||||
route.paths = routes.docs_paths ++ routes.playground_paths;
|
||||
cache.ttl_seconds = 60 * 60;
|
||||
cache.bypass = !production;
|
||||
}
|
||||
`,
|
||||
'schemas/worker.dcdl': `Worker = {
|
||||
name = String;
|
||||
compatibility_date = String;
|
||||
workers_dev = Bool default false;
|
||||
route.host = String;
|
||||
cache.ttl_seconds = Int & >= 0 default 300;
|
||||
cache.bypass = Bool default false;
|
||||
};
|
||||
`,
|
||||
'routes.dcdl': `primary_host = "decodal.example.com";
|
||||
docs_paths = ["/docs/*", "/assets/*"];
|
||||
playground_paths = ["/playground/*"];
|
||||
`,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'data-pipeline',
|
||||
title: 'Data pipeline',
|
||||
activePath: 'main.dcdl',
|
||||
files: {
|
||||
'main.dcdl': `let
|
||||
schema = import "./schemas/pipeline.dcdl";
|
||||
presets = import "./presets/batch.dcdl";
|
||||
env = "staging";
|
||||
in
|
||||
schema.Pipeline & presets.Batch & {
|
||||
name = "events-rollup";
|
||||
source.topic = "events.raw";
|
||||
sink.table = "analytics.events_daily";
|
||||
workers = match env {
|
||||
"prod": 8;
|
||||
"staging": 3;
|
||||
_: 1;
|
||||
};
|
||||
alerts.enabled = env != "dev";
|
||||
transforms = presets.standardTransforms ++ ["dedupe", "aggregate_daily"];
|
||||
}
|
||||
`,
|
||||
'schemas/pipeline.dcdl': `Pipeline = {
|
||||
name = String;
|
||||
source.topic = String;
|
||||
sink.table = String;
|
||||
workers = Int & > 0 default 1;
|
||||
batch.size = Int & >= 100 default 1000;
|
||||
batch.timeout_seconds = Int & > 0 default 60;
|
||||
alerts.enabled = Bool default false;
|
||||
};
|
||||
`,
|
||||
'presets/batch.dcdl': `standardTransforms = ["parse_json", "validate_schema", "enrich_metadata"];
|
||||
|
||||
Batch = {
|
||||
batch.size = 5000;
|
||||
batch.timeout_seconds = 30 + 30;
|
||||
};
|
||||
`,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'diagnostics',
|
||||
title: 'Diagnostics: invalid port',
|
||||
activePath: 'main.dcdl',
|
||||
files: {
|
||||
'main.dcdl': `let
|
||||
schema = import "./schemas/service.dcdl";
|
||||
in
|
||||
schema.Service & {
|
||||
name = "broken-api";
|
||||
port = 442;
|
||||
}
|
||||
`,
|
||||
'schemas/service.dcdl': `Service = {
|
||||
name = String;
|
||||
port = Int & > 443 default 8443;
|
||||
replicas = Int & > 0 default 2;
|
||||
};
|
||||
`,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
|
@ -1,9 +1,26 @@
|
|||
import init, { evaluateProject } from '../wasm/decodal_wasm.js';
|
||||
import { highlightDecodal } from '../lib/highlight.js';
|
||||
import { playgroundExamples } from './playground-examples.js';
|
||||
|
||||
const STORAGE_KEY = 'decodal-playground-project-v1';
|
||||
const starterProject = playgroundExamples[0];
|
||||
|
||||
const starterFiles = {
|
||||
'main.dcdl': `let
|
||||
schema = import "./schemas/service.dcdl";
|
||||
in
|
||||
schema.Service & {
|
||||
name = "api";
|
||||
port = 9000 + 443;
|
||||
tags = ["web"] ++ ["prod"];
|
||||
feature.enable = 9000 + 443 > 9000 && true;
|
||||
}
|
||||
`,
|
||||
'schemas/service.dcdl': `Service = {
|
||||
name = String;
|
||||
port = Int & > 443 default 8443;
|
||||
feature.enable = Bool default true;
|
||||
};
|
||||
`,
|
||||
};
|
||||
|
||||
const source = document.getElementById('source');
|
||||
const sourceHighlight = document.getElementById('source-highlight');
|
||||
|
|
@ -14,19 +31,9 @@ const fileTree = document.getElementById('file-tree');
|
|||
const activeFile = document.getElementById('active-file');
|
||||
const newFile = document.getElementById('new-file');
|
||||
const deleteFile = document.getElementById('delete-file');
|
||||
const exampleSelect = document.getElementById('example-select');
|
||||
const loadExample = document.getElementById('load-example');
|
||||
|
||||
const project = loadProject();
|
||||
|
||||
for (const example of playgroundExamples) {
|
||||
const option = document.createElement('option');
|
||||
option.value = example.id;
|
||||
option.textContent = example.title;
|
||||
exampleSelect.append(option);
|
||||
}
|
||||
exampleSelect.value = starterProject.id;
|
||||
|
||||
setActiveFile(project.activePath);
|
||||
renderFileTree();
|
||||
updateHighlight();
|
||||
|
|
@ -42,11 +49,7 @@ function loadProject() {
|
|||
} catch (_error) {
|
||||
// Fall back to the starter project.
|
||||
}
|
||||
return { files: cloneFiles(starterProject.files), activePath: starterProject.activePath };
|
||||
}
|
||||
|
||||
function cloneFiles(files) {
|
||||
return Object.fromEntries(Object.entries(files).map(([path, source]) => [path, source]));
|
||||
return { files: { ...starterFiles }, activePath: 'main.dcdl' };
|
||||
}
|
||||
|
||||
function normalizeFiles(files) {
|
||||
|
|
@ -62,17 +65,6 @@ function saveProject() {
|
|||
localStorage.setItem(STORAGE_KEY, JSON.stringify(project));
|
||||
}
|
||||
|
||||
function loadExampleProject(exampleId) {
|
||||
const example = playgroundExamples.find((item) => item.id === exampleId) ?? starterProject;
|
||||
project.files = cloneFiles(example.files);
|
||||
project.activePath = example.activePath;
|
||||
exampleSelect.value = example.id;
|
||||
setActiveFile(project.activePath);
|
||||
output.textContent = '';
|
||||
output.classList.remove('error');
|
||||
execute();
|
||||
}
|
||||
|
||||
function normalizePath(path) {
|
||||
const parts = [];
|
||||
for (const part of String(path).replaceAll('\\', '/').split('/')) {
|
||||
|
|
@ -173,12 +165,6 @@ try {
|
|||
}
|
||||
|
||||
run.addEventListener('click', execute);
|
||||
loadExample.addEventListener('click', () => {
|
||||
const example = playgroundExamples.find((item) => item.id === exampleSelect.value);
|
||||
if (!example) return;
|
||||
if (!confirm(`Load example "${example.title}"? This replaces the current virtual files.`)) return;
|
||||
loadExampleProject(example.id);
|
||||
});
|
||||
newFile.addEventListener('click', () => {
|
||||
const path = normalizePath(prompt('New virtual file path', 'schemas/types.dcdl') ?? '');
|
||||
if (!path) return;
|
||||
|
|
@ -186,7 +172,7 @@ newFile.addEventListener('click', () => {
|
|||
setActiveFile(path);
|
||||
return;
|
||||
}
|
||||
project.files[path] = 'value = "new";\n';
|
||||
project.files[path] = path.endsWith('.dcdl') ? '' : '// Decodal source\n';
|
||||
setActiveFile(path);
|
||||
});
|
||||
deleteFile.addEventListener('click', () => {
|
||||
|
|
|
|||
|
|
@ -281,30 +281,7 @@ main.playground {
|
|||
.playground-actions {
|
||||
align-items: center;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.example-picker {
|
||||
align-items: center;
|
||||
color: var(--muted);
|
||||
display: flex;
|
||||
font-size: 12px;
|
||||
font-weight: 700;
|
||||
gap: 6px;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.example-picker select {
|
||||
background: var(--surface);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
color: var(--text);
|
||||
font: inherit;
|
||||
min-width: 180px;
|
||||
padding: 7px 10px;
|
||||
text-transform: none;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
button {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user