use serde_json::{json, Value};
const DRAFT_2020_12: &str = "https://json-schema.org/draft/2020-12/schema";
pub fn target_schema() -> Value {
let one_of = vec![
json!({
"type": "object",
"title": "Empty",
"description": "The shard's current focus.",
"additionalProperties": false,
"maxProperties": 0,
}),
single_key_variant("Oid", "Focus by content address.", "oid", oid_schema()),
single_key_variant(
"Path",
"Focus by working-tree path.",
"path",
json!({ "type": "string" }),
),
single_key_variant("Ref", "Focus by named ref.", "ref", reference_schema()),
single_key_variant(
"Pair",
"Focus on a pair (diff/merge inputs).",
"pair",
json!({
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": { "$ref": "#" },
}),
),
single_key_variant(
"Refs",
"Focus the ref-set.",
"refs",
json!({ "type": "boolean" }),
),
single_key_variant(
"Shard",
"Focus the shard's summary.",
"shard",
json!({ "type": "boolean" }),
),
];
json!({
"$schema": DRAFT_2020_12,
"$id": "https://prism.engineer/pq/target.schema.json",
"title": "pq.Target",
"description": "Focus DSL — per pq spec §5.1.",
"type": "object",
"maxProperties": 1,
"oneOf": one_of,
})
}
pub fn filter_schema() -> Value {
let one_of = vec![
single_key_variant(
"Prefix",
"String-prefix narrowing.",
"prefix",
json!({ "type": "string" }),
),
single_key_variant(
"Match",
"Pattern/substring narrowing.",
"match",
json!({ "type": "string" }),
),
single_key_variant(
"Walk",
"DAG walk direction (history traversal).",
"walk",
json!({ "type": "string", "enum": ["back", "forward"] }),
),
single_key_variant(
"Compare",
"Structural diff of a focused pair.",
"compare",
json!({ "type": "boolean" }),
),
single_key_variant(
"Kintsugi",
"Tournament merge of a focused pair.",
"kintsugi",
json!({ "type": "boolean" }),
),
single_key_variant(
"Order",
"Ordering.",
"order",
json!({
"type": "array",
"items": order_spec_schema(),
}),
),
single_key_variant(
"Limit",
"Bounded results.",
"limit",
json!({
"type": "integer",
"minimum": 0,
"maximum": u32::MAX,
}),
),
single_key_variant(
"Where",
"Typed predicate.",
"where",
json!({
"type": "array",
"items": where_clause_schema(),
}),
),
];
json!({
"$schema": DRAFT_2020_12,
"$id": "https://prism.engineer/pq/filter.schema.json",
"title": "pq.Filter",
"description": "Project DSL — per pq spec §5.2.",
"type": "object",
"oneOf": one_of,
})
}
pub fn output_schema() -> Value {
let one_of = vec![
json!({
"type": "object",
"title": "ToPath",
"description": "Commit to a path.",
"additionalProperties": false,
"required": ["to_path"],
"properties": {
"to_path": { "type": "string" },
"message": { "type": "string" },
},
}),
single_key_variant(
"Ref",
"Advance a ref (branch creation / update).",
"ref",
reference_schema(),
),
single_key_variant(
"Cas",
"CAS-safe ref update.",
"cas",
json!({
"type": "object",
"additionalProperties": false,
"required": ["old", "new"],
"properties": {
"old": oid_schema(),
"new": oid_schema(),
},
}),
),
single_key_variant(
"ToRef",
"Write merged result to a ref.",
"to_ref",
reference_schema(),
),
single_key_variant(
"Snapshot",
"Crystallize without committing.",
"snapshot",
json!({ "type": "boolean" }),
),
single_key_variant(
"Flush",
"Shard flush to disk.",
"flush",
json!({ "type": "boolean" }),
),
];
json!({
"$schema": DRAFT_2020_12,
"$id": "https://prism.engineer/pq/output.schema.json",
"title": "pq.Output",
"description": "Settle DSL — per pq spec §5.3.",
"type": "object",
"oneOf": one_of,
})
}
fn single_key_variant(title: &str, description: &str, key: &str, value_schema: Value) -> Value {
json!({
"type": "object",
"title": title,
"description": description,
"additionalProperties": false,
"required": [key],
"properties": {
key: value_schema,
},
})
}
fn oid_schema() -> Value {
json!({
"type": "string",
"description": "Content-addressed identifier (hex).",
})
}
fn reference_schema() -> Value {
json!({
"type": "string",
"description": "Wire-layer reference name (HEAD, main, feature/x, ...).",
})
}
fn order_spec_schema() -> Value {
json!({
"type": "object",
"additionalProperties": false,
"required": ["field", "direction"],
"properties": {
"field": { "type": "string" },
"direction": { "type": "string", "enum": ["asc", "desc"] },
},
})
}
fn where_clause_schema() -> Value {
json!({
"type": "object",
"additionalProperties": false,
"required": ["field", "op", "value"],
"properties": {
"field": { "type": "string" },
"op": {
"type": "string",
"enum": ["eq", "neq", "gt", "lt", "gte", "lte", "contains", "matches"],
},
"value": true,
},
})
}