{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://woven-docs-yl1.pages.dev/data/zooid-dataview-manifest.schema.json",
  "title": "Zooid DataView manifest",
  "type": "object",
  "required": ["format", "version", "views"],
  "properties": {
    "$schema": { "type": "string" },
    "format": { "const": "zooid-dataview-manifest" },
    "version": { "const": 1 },
    "title": { "type": "string" },
    "description": { "type": "string" },
    "views": {
      "type": "array",
      "minItems": 2,
      "maxItems": 2,
      "items": { "$ref": "#/$defs/view" }
    }
  },
  "additionalProperties": false,
  "$defs": {
    "view": {
      "type": "object",
      "required": ["id", "name", "source", "worker", "contract"],
      "properties": {
        "id": { "enum": ["personal", "registry"] },
        "name": { "type": "string" },
        "source": {
          "type": "object",
          "required": ["repository", "revision", "files", "workerConfig"],
          "properties": {
            "repository": { "type": "string" },
            "revision": { "type": "string", "pattern": "^[0-9a-f]{40}$" },
            "files": {
              "type": "array",
              "minItems": 1,
              "items": {
                "type": "object",
                "required": ["path", "sha256"],
                "properties": {
                  "path": { "type": "string", "minLength": 1 },
                  "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
                },
                "additionalProperties": false
              }
            },
            "workerConfig": {
              "type": "object",
              "required": ["path", "sha256"],
              "properties": {
                "path": { "type": "string", "minLength": 1 },
                "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
              },
              "additionalProperties": false
            }
          },
          "additionalProperties": false
        },
        "worker": {
          "type": "object",
          "required": ["name", "entry", "compatibilityDate", "durableObject", "deployments", "dependencies"],
          "properties": {
            "name": { "type": "string" },
            "entry": { "type": "string" },
            "compatibilityDate": { "type": "string", "format": "date" },
            "durableObject": {
              "type": "object",
              "required": ["binding", "class", "object", "migration"],
              "properties": {
                "binding": { "type": "string" },
                "class": { "type": "string" },
                "object": { "type": "string" },
                "migration": {
                  "type": "object",
                  "required": ["tag", "newSqliteClasses"],
                  "properties": {
                    "tag": { "type": "string" },
                    "newSqliteClasses": { "type": "array", "items": { "type": "string" } }
                  },
                  "additionalProperties": false
                }
              },
              "additionalProperties": false
            },
            "deployments": {
              "type": "object",
              "required": ["production", "staging"],
              "properties": {
                "production": { "$ref": "#/$defs/deployment" },
                "staging": { "$ref": "#/$defs/deployment" }
              },
              "additionalProperties": false
            },
            "dependencies": { "type": "array", "items": { "type": "string" } },
            "environment": {
              "type": "object",
              "properties": {
                "required": { "type": "array", "items": { "type": "string" } },
                "optional": { "type": "array", "items": { "type": "string" } }
              },
              "additionalProperties": false
            }
          },
          "additionalProperties": false
        },
        "contract": {
          "type": "object",
          "required": ["summary", "tables", "routes"],
          "properties": {
            "summary": { "type": "string" },
            "tables": { "type": "array", "items": { "type": "string" } },
            "routes": {
              "type": "array",
              "items": {
                "type": "object",
                "required": ["method", "path", "behavior"],
                "properties": {
                  "method": { "enum": ["GET", "POST", "DELETE"] },
                  "path": { "type": "string" },
                  "behavior": { "type": "string" }
                },
                "additionalProperties": false
              }
            },
            "storage": { "type": "array", "items": { "type": "object" } },
            "indexedEvents": { "type": "array", "items": { "type": "string" } },
            "invariants": { "type": "array", "items": { "type": "string" } }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "deployment": {
      "type": "object",
      "required": ["name", "durableObjectBinding"],
      "properties": {
        "name": { "type": "string" },
        "durableObjectBinding": {
          "type": "object",
          "required": ["name", "class"],
          "properties": {
            "name": { "type": "string" },
            "class": { "type": "string" }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    }
  }
}
