{
  "$id": "https://uape.dev/schemas/storage-topology-1.0.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Storage Topology",
  "description": "Logical entities + indexes declared by a module. Resolved by daimon-storage indirection layer.",
  "type": "object",
  "additionalProperties": false,
  "required": ["entities"],
  "properties": {
    "entities": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {
        "type": "object",
        "additionalProperties": false,
        "required": ["fields", "primary_key"],
        "properties": {
          "fields": {
            "type": "object",
            "minProperties": 1,
            "additionalProperties": {
              "type": "object",
              "additionalProperties": false,
              "required": ["type"],
              "properties": {
                "type": {
                  "type": "string",
                  "enum": ["string", "u32", "u64", "i64", "bool", "decimal", "bytes", "uuid", "timestamp_ms"]
                },
                "required": { "type": "boolean", "default": true },
                "indexed":  { "type": "boolean", "default": false },
                "max_len":  { "type": "integer", "minimum": 1, "maximum": 1048576 }
              }
            }
          },
          "primary_key": { "type": "string", "minLength": 1, "maxLength": 64 },
          "sub_entities": {
            "type": "array",
            "items": { "$ref": "sub-entity.schema.json" }
          }
        }
      }
    },
    "indexes": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["name", "entity", "field"],
        "properties": {
          "name":   { "type": "string", "pattern": "^[a-z][a-z0-9_]*$" },
          "entity": { "type": "string" },
          "field":  { "type": "string" },
          "unique": { "type": "boolean", "default": false }
        }
      }
    },
    "topology_hash": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$",
      "description": "SHA-256 over canonical entities+indexes. Optional in source; generated by tooling. Used at boot to detect migration need."
    }
  }
}
