Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,28 @@ jobs:
exit "$status"
fi

schema:
name: Project schema
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable
with:
# `cargo xtask schema --check` lints the code behind the `schema` feature first.
components: clippy
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2
with:
# Only main saves the cache (see test-rust.yml).
save-if: ${{ github.ref == 'refs/heads/main' }}
# The committed schema matches the types the project is saved from, and the fixture projects
# open. `--locked` on the outer run too, so a stale Cargo.lock is refused before xtask starts.
- name: Check the project file's schema
run: cargo run --locked -q -p xtask -- schema --check
# Every fixture, not only those the pull request changes (as pre-commit does), so a change
# to the schema alone is checked against them too.
- name: Validate the fixture projects against the schema
run: pipx run check-jsonschema==0.39.0 --schemafile schema/project.schema.json --default-filetype json schema/fixtures/*.rgis

plan:
name: Platforms
runs-on: ubuntu-latest
Expand Down
9 changes: 9 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ repos:
- id: trailing-whitespace
- id: check-added-large-files
args: ["--maxkb=1024"]
# Fixture projects match the project file's schema (generated by `cargo xtask schema`).
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.39.0
hooks:
- id: check-jsonschema
name: fixture projects match the project schema
files: ^schema/fixtures/.*\.rgis$
types: [file]
args: ["--schemafile", "schema/project.schema.json", "--default-filetype", "json"]
- repo: local
hooks:
- id: cargo-fmt
Expand Down
3 changes: 3 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Before picking work, read [ROADMAP.md](ROADMAP.md) (check Underway) and
- A file or setting from a newer RustGIS is refused or kept unchanged, never saved again without
what this version couldn't read; a reader checks the version it is given
([saved files](docs/maintaining.md#saved-files-and-settings)).
- A change to what a project saves runs `cargo xtask schema` and commits
`schema/project.schema.json` with it; a change to how a project is read adds or updates a fixture
in `schema/fixtures/`.

## Never hold the window
On the desktop, a command whose work grows with its input (features, cells, tiles, files,
Expand Down
65 changes: 65 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ serde = { version = "1", features = ["derive", "rc"] }
# baselines (row hashes) see every reopened row as changed.
serde_json = { version = "1", features = ["raw_value", "float_roundtrip"] }
sha2 = "0.11"
# JSON Schema of the project file, generated from the saved types (`cargo xtask schema`); only
# behind the `schema` features, so the app, the browser build and the packages never compile it.
schemars = "1.2"
log = "0.4"
# std::time that also works in the browser (std panics on wasm32-unknown-unknown).
web-time = "1"
Expand Down
5 changes: 5 additions & 0 deletions crates/data/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ workspace = true
rustgis-geom = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
schemars = { workspace = true, optional = true }
thiserror = { workspace = true }
csv = { workspace = true }
# Streaming gzip text imports; use the pure-Rust backend in the browser too.
Expand Down Expand Up @@ -75,6 +76,10 @@ rustls-native-certs = "0.8"
# Safe effective-UID and no-follow operations for private Shapefile index caches.
rustix = { version = "1.1", features = ["process", "fs"] }

[features]
# The JSON Schema of the saved types (`cargo xtask schema`).
schema = ["dep:schemars", "rustgis-geom/schema"]

[dev-dependencies]
# Writing sample GeoParquet files.
parquet = { workspace = true, features = ["arrow"] }
Expand Down
33 changes: 33 additions & 0 deletions crates/data/src/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,39 @@ impl<'de> Deserialize<'de> for Date {
}
}

/// A date is saved as its ISO 8601 text (`2026-03-05`), from year 1 to 9999.
#[cfg(feature = "schema")]
impl schemars::JsonSchema for Date {
fn schema_name() -> std::borrow::Cow<'static, str> {
"Date".into()
}
fn json_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
schemars::json_schema!({
"type": "string",
"description": "A calendar day as ISO 8601 text (YYYY-MM-DD), years 1 to 9999, maybe with spaces around it. The pattern can't tell a day that doesn't exist (2026-02-30); the reader refuses it.",
"pattern": "^\\s*([1-9][0-9]{3}|0[1-9][0-9]{2}|00[1-9][0-9]|000[1-9])-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])\\s*$"
})
}
}

/// A date-time is saved as its ISO 8601 text, with its offset when it has one.
#[cfg(feature = "schema")]
impl schemars::JsonSchema for DateTime {
fn schema_name() -> std::borrow::Cow<'static, str> {
"DateTime".into()
}
fn json_schema(_: &mut schemars::SchemaGenerator) -> schemars::Schema {
// The day as for `Date`, then maybe a clock after `T`, `t` or a space (HH:MM, seconds and
// up to six fraction digits optional, zeros past them), then maybe `Z` or an offset
// (+02, +0200, +02:00) of at most 18 hours, as `MAX_OFFSET_MIN`.
schemars::json_schema!({
"type": "string",
"description": "A date and time as ISO 8601 text, years 1 to 9999, with its offset (Z, +02:00) when it has one, without one when it has none, maybe with spaces around it. The pattern can't tell a day that doesn't exist (2026-02-30) or an instant before year 1 or past year 9999 once its offset is applied (0001-01-01T00:00:00+01:00); the reader refuses them.",
"pattern": "^\\s*([1-9][0-9]{3}|0[1-9][0-9]{2}|00[1-9][0-9]|000[1-9])-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])([Tt ]([01][0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9](\\.[0-9]{1,6}0*)?)?([Zz]|[+-]((0[0-9]|1[0-7])(:?[0-5][0-9])?|18(:?00)?))?)?\\s*$"
})
}
}

impl Serialize for DateTime {
/// As its ISO 8601 text, with its offset when it has one (`2026-03-05T14:30:00+02:00`).
fn serialize<S: Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
Expand Down
2 changes: 2 additions & 0 deletions crates/data/src/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub fn ambiguous_area_message<'a>(geometries: impl Iterator<Item = &'a Geometry>
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub enum GeometryType {
Point,
Polyline,
Expand Down Expand Up @@ -96,6 +97,7 @@ impl Measure {

/// A geometry. Lines hold parts; polygons hold polygons of rings (first ring = exterior).
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub enum Geometry {
Point(Coord),
MultiPoint(Vec<Coord>),
Expand Down
12 changes: 12 additions & 0 deletions crates/data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ mod secret_redaction_tests {

/// One row: an optional geometry and one value per field.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct Feature {
pub id: u64,
pub geometry: Option<Geometry>,
Expand Down Expand Up @@ -316,6 +317,17 @@ impl Serialize for Features {
}
}

/// Features are saved as a list of [`Feature`]s.
#[cfg(feature = "schema")]
impl schemars::JsonSchema for Features {
fn schema_name() -> std::borrow::Cow<'static, str> {
"Features".into()
}
fn json_schema(generator: &mut schemars::SchemaGenerator) -> schemars::Schema {
<Vec<Feature>>::json_schema(generator)
}
}

impl<'de> Deserialize<'de> for Features {
fn deserialize<D: serde::Deserializer<'de>>(d: D) -> std::result::Result<Features, D::Error> {
Vec::<Feature>::deserialize(d).map(Features::from)
Expand Down
2 changes: 2 additions & 0 deletions crates/data/src/raster/crs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub fn esri_codes() -> impl Iterator<Item = u32> {

/// A raster's coordinate system. Saved as its EPSG code, or a custom one as its definition.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(into = "SavedCrs", try_from = "SavedCrs")]
pub enum Crs {
/// WGS 84 longitude/latitude in degrees (EPSG:4326).
Expand All @@ -51,6 +52,7 @@ pub enum Crs {
/// How a [`Crs`] is saved: a custom system by its PROJ definition, never by its number in a run's
/// table.
#[derive(Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
enum SavedCrs {
LonLat,
WebMercator,
Expand Down
3 changes: 3 additions & 0 deletions crates/data/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::date::{Date, DateTime};
use serde::{Deserialize, Serialize};

#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub enum FieldType {
Integer,
Double,
Expand Down Expand Up @@ -36,6 +37,7 @@ impl FieldType {
}

#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct Field {
pub name: String,
pub ty: FieldType,
Expand All @@ -54,6 +56,7 @@ impl Field {
}

#[derive(Clone, Debug, Default, PartialEq, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub enum Value {
#[default]
Null,
Expand Down
8 changes: 8 additions & 0 deletions crates/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ iana-time-zone = { version = "0.1", features = ["fallback"] }
sys-locale = { version = "0.3", features = ["js"] }
# The GeoLibre tool suite (native only: its tools read and write files).
rustgis-geolibre = { workspace = true, optional = true }
schemars = { workspace = true, optional = true }

[features]
geolibre = ["dep:rustgis-geolibre"]
# Existing in-tree Wasm fixtures for adapter tests; no guest or production interface change.
testing = ["rustgis-plugins/testing"]
# The JSON Schema of the project file (`cargo xtask schema`).
schema = ["dep:schemars", "rustgis-data/schema", "rustgis-geom/schema"]

[dev-dependencies]
miniz_oxide = { workspace = true }
Expand All @@ -51,3 +54,8 @@ image = { workspace = true, features = ["gif"] }
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
postgres = { workspace = true }
rustls = { workspace = true }

# The project file's JSON Schema (`cargo xtask schema [--check]`).
[[example]]
name = "project_schema"
required-features = ["schema"]
Loading
Loading