Skip to content

Commit 7b0543b

Browse files
Embedded json schema (#139)
* Implement basic zoom; TODO: fix angle in skewT * Add logarithmic zoom for skew-T diagram; TODO: T calculations should use real axis extent rather than fixes base/top pressure * Fix skew-T lines responding to original extent instead of actual; now they don't tilt anymore * Add panning effect, but it is stroboscopic and doesn't work for skewT yet * combine side-effects for both axes in a single callback * Remove animationframe * Use produce to update both scales in a single call * Don't update panstart; this fixes the jittering * Also work in log space * Make consistent for x-direction * zoom towards cursor * Add reset plot button * Thinner lines * Higher resolution plot * Round time to steps of 10 minutes * Use runClass from package, skipping BMI altogher + rich metadata for output vars; however, app/model hangs on second or third run * Fix hanging issue: wrap only once... * Make sure initial state is included in output * Reset pan/zoom when variable changes * formatting * Use output metadata in plot labels and variable pickers * ditch BMI * Fix xlabel in timeseries plot; fix axes extent for non-time on x-axis * Remove config.JSON everywhere; only keep the embedded version * Change units to use superscript * Add `pnpx @classmodel/class schema` cli subcommand * Update lockfile --------- Co-authored-by: sverhoeven <[email protected]>
1 parent 7bbeb86 commit 7b0543b

File tree

8 files changed

+61
-464
lines changed

8 files changed

+61
-464
lines changed

apps/class-solid/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ This allows you to trigger tests from the [playwright ui](https://playwright.dev
5454
An experiment can get started from a preset.
5555

5656
The presets are stored in the `src/lib/presets/` directory.
57-
The format is JSON with content adhering to the [JSON schema](https://github.com/classmodel/class-web/blob/main/packages/class/src/config.json).
57+
The format is JSON with content adhering to the [JSON schema](https://github.com/classmodel/class-web/blob/main/packages/class/src/config.ts).
5858

5959
The `src/lib/presets.ts` is used as an index of presets.
6060
If you add a preset the `src/lib/presets.ts` file needs to be updated.

packages/class/README.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ pnpx @classmodel/class run --output output.csv --format csv config.json
3636

3737
# To read from stdin use
3838
cat config.json | pnpx @classmodel/class -
39+
40+
# To get the JSON schema of the config file use
41+
pnpx @classmodel/class schema -o config.schema.json
3942
```
4043
If you do not have `pnpx` installed you can use `npx` instead.
4144

@@ -70,20 +73,10 @@ This package is part of a [monorepo](https://github.com/classmodel/class-web) wi
7073

7174
### JSON schema
7275

73-
The Class model uses a JSON schema to validate the input configuration. The schema is defined in the `@classmodel/class` package and can be found at [src/config.json](https://github.com/classmodel/class-web/blob/main/packages/class/src/config.json) (in [repo](./src/config.json)). The schema is used to validate the input configuration and to generate a form to input the configuration.
76+
The Class model uses a JSON schema to validate the input configuration. The schema is defined in the `@classmodel/class` package and can be found at [src/config.ts](https://github.com/classmodel/class-web/blob/main/packages/class/src/config.ts) (in [repo](./src/config.ts)). The schema is used to validate the input configuration and to generate a form to input the configuration.
7477

7578
The `src/config.ts` file contains the embedded JSON schema and its Typescript type definition.
7679

77-
<!-- When runnning `pnpm dev` or `pnpm build` the `src/config.ts` file is generated from the `src/config.json` file.
78-
79-
To manually generate the `src/config.ts` file run the following command:
80-
81-
```shell
82-
pnpm json2ts
83-
``` -->
84-
85-
At the moment you manually have to keep the `src/config.ts` file in sync with the `src/config.json` file. By copying the content over and updating the TypeScript Config type.
86-
8780
See the [form package](../form/README.md#json-schema) for additional keywords in the JSON schema.
8881

8982
#### Conditional properties

packages/class/package.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"types": "./dist/config.d.ts"
2424
}
2525
},
26-
"./config.json": "./dist/config.json",
2726
"./config_utils": {
2827
"import": {
2928
"default": "./dist/config_utils.js",
@@ -54,23 +53,17 @@
5453
"files": ["dist"],
5554
"license": "GPL-3.0-only",
5655
"scripts": {
57-
"dev": "concurrently -n \"tsc,json2ts\" -c \"blue,green\" \"pnpm dev:tsc\" \"pnpm json2ts --watch\"",
58-
"dev:tsc": "tsc --watch",
59-
"build:tsc": "tsc",
60-
"build:config": "cp src/config.json dist/config.json",
61-
"build": "pnpm json2ts && pnpm build:tsc && pnpm build:config",
56+
"dev": "tsc --watch",
57+
"build": "tsc",
6258
"prepack": "pnpm build",
6359
"test": "tsx --test src/*.test.ts",
6460
"typecheck": "tsc --noEmit",
65-
"json2ts": "node scripts/json2ts.mjs",
6661
"docs": "typedoc",
6762
"clean": "rm -rf dist"
6863
},
6964
"bin": "./dist/cli.js",
7065
"devDependencies": {
7166
"@types/node": "^20.13.1",
72-
"concurrently": "^9.0.1",
73-
"json-schema-to-typescript": "^15.0.2",
7467
"tsx": "^4.16.5",
7568
"typedoc": "^0.26.10",
7669
"typescript": "^5.3.3"

packages/class/scripts/json2ts.mjs

Lines changed: 0 additions & 135 deletions
This file was deleted.

packages/class/src/cli.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import { readFile, writeFile } from "node:fs/promises";
77
import { EOL } from "node:os";
88
import { Command, Option } from "@commander-js/extra-typings";
9+
import { jsonSchemaOfConfig } from "./config.js";
910
import type { ClassOutput } from "./runner.js";
1011
import { runClass } from "./runner.js";
1112
import { parse } from "./validate.js";
@@ -142,6 +143,19 @@ function buildCommand() {
142143
}
143144
});
144145

146+
program
147+
.command("schema")
148+
.description("Print the JSON schema for the configuration file")
149+
.option("-o, --output <output-file>", "Output file. Default is stdout", "-")
150+
.action((options) => {
151+
const output = JSON.stringify(jsonSchemaOfConfig, null, 2);
152+
if (options.output === "-") {
153+
console.log(output);
154+
} else {
155+
writeTextFile(output, options.output);
156+
}
157+
});
158+
145159
return program;
146160
}
147161

0 commit comments

Comments
 (0)