{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://folio.mccal.dev/schema/v1/index.schema.json",
  "title": "Folio source index",
  "type": "object",
  "required": [
    "format",
    "name",
    "packages"
  ],
  "additionalProperties": false,
  "properties": {
    "$schema": {
      "type": "string"
    },
    "format": {
      "const": 1
    },
    "name": {
      "oneOf": [
        {
          "type": "string",
          "minLength": 1,
          "maxLength": 400
        },
        {
          "type": "object",
          "required": [
            "en"
          ],
          "propertyNames": {
            "pattern": "^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$"
          },
          "additionalProperties": {
            "type": "string",
            "minLength": 1,
            "maxLength": 400
          },
          "maxProperties": 64
        }
      ]
    },
    "description": {
      "oneOf": [
        {
          "type": "string",
          "minLength": 1,
          "maxLength": 400
        },
        {
          "type": "object",
          "required": [
            "en"
          ],
          "propertyNames": {
            "pattern": "^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$"
          },
          "additionalProperties": {
            "type": "string",
            "minLength": 1,
            "maxLength": 400
          },
          "maxProperties": 64
        }
      ]
    },
    "icon": {
      "type": "string",
      "pattern": "^(?!/)(?!.*\\.\\.)[A-Za-z0-9._/-]+$",
      "maxLength": 200
    },
    "issuesUrl": {
      "type": "string",
      "pattern": "^https://\\S+$",
      "maxLength": 2048
    },
    "featured": {
      "type": "array",
      "maxItems": 12,
      "items": {
        "type": "object",
        "required": [
          "package"
        ],
        "additionalProperties": false,
        "properties": {
          "package": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)+$",
            "maxLength": 120
          },
          "label": {
            "oneOf": [
              {
                "type": "string",
                "minLength": 1,
                "maxLength": 400
              },
              {
                "type": "object",
                "required": [
                  "en"
                ],
                "propertyNames": {
                  "pattern": "^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$"
                },
                "additionalProperties": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 400
                },
                "maxProperties": 64
              }
            ]
          },
          "image": {
            "type": "string",
            "pattern": "^(?!/)(?!.*\\.\\.)[A-Za-z0-9._/-]+$",
            "maxLength": 200
          }
        }
      }
    },
    "packages": {
      "type": "array",
      "maxItems": 5000,
      "items": {
        "type": "object",
        "required": [
          "id",
          "version",
          "manifest"
        ],
        "additionalProperties": false,
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)+$",
            "maxLength": 120
          },
          "version": {
            "type": "string",
            "pattern": "^([0-9]+:)?[0-9][A-Za-z0-9.+~]*(-[A-Za-z0-9.+~]+)?$",
            "maxLength": 64
          },
          "url": {
            "type": "string",
            "maxLength": 2048,
            "pattern": "^(https://\\S+|(?!/)(?!.*\\.\\.)[A-Za-z0-9._/-]+)$"
          },
          "sha256": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          },
          "size": {
            "type": "integer",
            "minimum": 1,
            "maximum": 20971520
          },
          "manifest": {
            "$ref": "manifest.schema.json"
          },
          "provenance": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "repo",
              "commit"
            ],
            "properties": {
              "repo": {
                "type": "string",
                "pattern": "^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$"
              },
              "commit": {
                "type": "string",
                "pattern": "^[0-9a-f]{7,40}$"
              },
              "workflow": {
                "type": "string",
                "maxLength": 200
              }
            }
          },
          "signedBy": {
            "type": "object",
            "description": "The author's signature over folio-pkg:<id>:<version>:<sha256>, base64. Separate from the source's signature: it says who wrote the package, not who is handing it out.",
            "additionalProperties": false,
            "required": [
              "key",
              "signature"
            ],
            "properties": {
              "key": {
                "type": "string",
                "description": "The author's public key, base64 SPKI (ECDSA P-256).",
                "minLength": 40,
                "maxLength": 512
              },
              "signature": {
                "type": "string",
                "description": "Base64 signature over the payload.",
                "minLength": 40,
                "maxLength": 512
              }
            }
          }
        },
        "dependentRequired": {
          "url": [
            "sha256",
            "size"
          ],
          "sha256": [
            "url",
            "size"
          ],
          "size": [
            "url",
            "sha256"
          ]
        }
      }
    }
  }
}
