{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://dreamweave-mp.github.io/AsHyAmS/schemas/dreamweave-network-jess-packages-1.schema.json",
  "title": "DreamWeave Network Jess packages, format version 1",
  "description": "The Jess package claims one DreamWeave Network index observed: every package some enrolled site's project publishes as jpk releases (protocol schema_version 3), with the site that published it, the project it is, the manifest URL that remains the authority, every version the manifest lists, and id collisions between sites. A discovery cache for Jess clients, not a registry: nothing here was downloaded or verified by the index, and a client reads the publisher's manifest before it believes anything.",
  "type": "object",
  "required": [
    "format",
    "format_version",
    "notice",
    "index",
    "observed_at",
    "crawler",
    "packages",
    "conflicts"
  ],
  "additionalProperties": false,
  "properties": {
    "format": {
      "const": "dreamweave-network-jess-packages"
    },
    "format_version": {
      "const": 1
    },
    "notice": {
      "type": "string"
    },
    "index": {
      "$ref": "#/$defs/index"
    },
    "observed_at": {
      "$ref": "#/$defs/optional_time"
    },
    "crawler": {
      "$ref": "#/$defs/optional_string"
    },
    "packages": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/package_claim"
      }
    },
    "conflicts": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/conflict"
      }
    }
  },
  "$defs": {
    "package_id": {
      "description": "A Jess package id: reverse-DNS, lowercase, as jess.toml's [package] id.",
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9.-]*$",
      "maxLength": 200
    },
    "version": {
      "description": "An exact Jess package version: major.minor.patch, no leading zeros, with the dot-separated identifiers of a pre-release after a hyphen (0.1.2-dev.6, a development build), which only a requirement naming it exactly chooses.",
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-(0|[1-9][0-9]*|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*)(\\.(0|[1-9][0-9]*|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*))*)?$"
    },
    "requirement": {
      "description": "A Jess version requirement as jess.toml writes one: ^1.2 (or 1.2, the same), =1.2.3, or a pre-release named exactly, 0.1.2-dev.6.",
      "type": "string",
      "pattern": "^[=^]?(0|[1-9][0-9]*)(\\.(0|[1-9][0-9]*)){0,2}(-(0|[1-9][0-9]*|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*)(\\.(0|[1-9][0-9]*|[0-9A-Za-z-]*[A-Za-z-][0-9A-Za-z-]*))*)?$"
    },
    "uuid": {
      "type": "string",
      "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
    },
    "hex64": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "url": {
      "type": "string",
      "pattern": "^https?://"
    },
    "date": {
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
    },
    "time": {
      "description": "UTC, second precision: when this index observed something. Never a publisher's date.",
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z$"
    },
    "optional_time": {
      "oneOf": [
        {
          "$ref": "#/$defs/time"
        },
        {
          "type": "null"
        }
      ]
    },
    "optional_string": {
      "type": [
        "string",
        "null"
      ]
    },
    "origin_id": {
      "description": "This index's name for a site: readable host and path plus eight hex digits of the site index URL's SHA-256.",
      "type": "string",
      "pattern": "^[a-z0-9-]+$"
    },
    "index": {
      "type": "object",
      "required": [
        "name",
        "url",
        "repository"
      ],
      "additionalProperties": false,
      "properties": {
        "name": {
          "type": "string"
        },
        "url": {
          "$ref": "#/$defs/url"
        },
        "repository": {
          "$ref": "#/$defs/url"
        }
      }
    },
    "package_ref": {
      "type": "object",
      "required": [
        "id",
        "origin"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/package_id"
        },
        "origin": {
          "$ref": "#/$defs/origin_id"
        }
      }
    },
    "package_version": {
      "description": "One release of the project that is the package, as its manifest describes it.",
      "type": "object",
      "required": [
        "version",
        "channel",
        "status",
        "jess_api",
        "content_digest",
        "dependencies",
        "artifact"
      ],
      "additionalProperties": false,
      "properties": {
        "version": {
          "$ref": "#/$defs/version"
        },
        "channel": {
          "type": "string",
          "minLength": 1
        },
        "status": {
          "enum": [
            "available",
            "yanked",
            "deprecated"
          ]
        },
        "yanked": {
          "$ref": "#/$defs/notice"
        },
        "deprecated": {
          "$ref": "#/$defs/notice"
        },
        "date": {
          "$ref": "#/$defs/date"
        },
        "jess_api": {
          "type": "string",
          "minLength": 1
        },
        "content_digest": {
          "$ref": "#/$defs/hex64"
        },
        "dependencies": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/requirement"
          }
        },
        "artifact": {
          "$ref": "#/$defs/artifact"
        }
      }
    },
    "artifact": {
      "description": "The JPK archive as the manifest lists it, copied unchanged: its own digest, where it downloads from, how it was signed.",
      "type": "object",
      "required": [
        "id",
        "format",
        "filename",
        "media_type",
        "size",
        "digests",
        "jess",
        "sources",
        "signatures"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "format": {
          "const": "jpk"
        },
        "filename": {
          "type": "string",
          "minLength": 1
        },
        "media_type": {
          "const": "application/vnd.jess.jpk"
        },
        "size": {
          "type": "integer",
          "minimum": 1
        },
        "digests": {
          "type": "object",
          "required": [
            "sha256"
          ],
          "additionalProperties": false,
          "properties": {
            "sha256": {
              "$ref": "#/$defs/hex64"
            }
          }
        },
        "platform": {
          "type": "object"
        },
        "layout": {
          "type": "object"
        },
        "jess": {
          "$ref": "#/$defs/jess"
        },
        "sources": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/artifact_source"
          }
        },
        "signatures": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/signature"
          }
        }
      }
    },
    "application_version": {
      "description": "One release of the project as a Jess application (protocol schema_version 4): what its jsw artifact's jess_workspace block says it runs and holds, and the packed workspace. The packages it holds are pins, not requirements.",
      "type": "object",
      "required": [
        "version",
        "channel",
        "status",
        "builtin",
        "targets",
        "commands",
        "packages",
        "artifact"
      ],
      "additionalProperties": false,
      "properties": {
        "version": {
          "$ref": "#/$defs/version"
        },
        "channel": {
          "type": "string",
          "minLength": 1
        },
        "status": {
          "enum": [
            "available",
            "yanked",
            "deprecated"
          ]
        },
        "yanked": {
          "$ref": "#/$defs/notice"
        },
        "deprecated": {
          "$ref": "#/$defs/notice"
        },
        "date": {
          "$ref": "#/$defs/date"
        },
        "builtin": {
          "type": "string",
          "minLength": 1
        },
        "default": {
          "type": "string",
          "minLength": 1
        },
        "targets": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "commands": {
          "type": "object",
          "additionalProperties": {
            "type": "string",
            "minLength": 1
          }
        },
        "packages": {
          "type": "object",
          "additionalProperties": {
            "type": "object",
            "required": [
              "version",
              "content_digest"
            ],
            "additionalProperties": false,
            "properties": {
              "version": {
                "type": "string",
                "minLength": 1
              },
              "content_digest": {
                "$ref": "#/$defs/hex64"
              }
            }
          }
        },
        "artifact": {
          "description": "The jsw artifact as the manifest lists it, copied unchanged.",
          "type": "object",
          "required": [
            "id",
            "format",
            "filename",
            "media_type",
            "size",
            "digests",
            "jess_workspace",
            "sources",
            "signatures"
          ],
          "properties": {
            "format": {
              "const": "jsw"
            },
            "media_type": {
              "const": "application/vnd.jess.jsw"
            }
          }
        }
      }
    },
    "package_claim": {
      "description": "One site's publication of one Jess package: the releases of its project that are the package, copied from its manifest, with where that came from and how fresh this index's copy is.",
      "type": "object",
      "required": [
        "id",
        "origin",
        "project",
        "name",
        "manifest_url",
        "manifest_sha256",
        "health",
        "cached",
        "first_observed",
        "last_attempt",
        "current",
        "versions",
        "conflict",
        "network_page",
        "project_page"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/package_id"
        },
        "origin": {
          "type": "string",
          "minLength": 1
        },
        "project": {
          "$ref": "#/$defs/uuid"
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "summary": {
          "type": [
            "string",
            "null"
          ]
        },
        "manifest_url": {
          "$ref": "#/$defs/url",
          "description": "The publisher's manifest: the authority for every version below."
        },
        "manifest_sha256": {
          "$ref": "#/$defs/hex64",
          "description": "The digest of the manifest this index holds and copied these versions from."
        },
        "health": {
          "type": "string",
          "minLength": 1,
          "description": "The project claim's health as the index records it: current, or why the copy is a cached one."
        },
        "cached": {
          "type": "boolean"
        },
        "problem": {
          "type": [
            "string",
            "null"
          ]
        },
        "first_observed": {
          "$ref": "#/$defs/time"
        },
        "last_changed": {
          "$ref": "#/$defs/optional_time"
        },
        "last_attempt": {
          "$ref": "#/$defs/time"
        },
        "last_success": {
          "$ref": "#/$defs/optional_time"
        },
        "current": {
          "oneOf": [
            {
              "$ref": "#/$defs/version"
            },
            {
              "type": "null"
            }
          ],
          "description": "The newest release the publisher offers for new installs: never a pre-release, which only a requirement naming it exactly chooses; null when nothing else is available."
        },
        "versions": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/package_version"
          },
          "description": "The releases that are the package as a JPK. Empty only for a package published solely as an application."
        },
        "applications": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/application_version"
          },
          "description": "The releases that carry the package as a Jess application, a jsw. Absent when there are none."
        },
        "conflict": {
          "type": "boolean"
        },
        "network_page": {
          "$ref": "#/$defs/url"
        },
        "project_page": {
          "$ref": "#/$defs/url"
        }
      },
      "anyOf": [
        {
          "properties": {
            "versions": {
              "minItems": 1
            }
          }
        },
        {
          "required": [
            "applications"
          ]
        }
      ]
    },
    "conflict": {
      "type": "object",
      "required": [
        "id",
        "claims",
        "shared_versions",
        "same_bytes"
      ],
      "additionalProperties": false,
      "properties": {
        "id": {
          "$ref": "#/$defs/package_id"
        },
        "claims": {
          "type": "array",
          "minItems": 2,
          "items": {
            "$ref": "#/$defs/package_ref"
          }
        },
        "shared_versions": {
          "description": "Versions more than one of the claims lists.",
          "type": "integer",
          "minimum": 0
        },
        "same_bytes": {
          "description": "Every shared version names the same content digest and archive digest in every claim: the sites mirror one publication. False when any differs, or when no version is shared.",
          "type": "boolean"
        }
      }
    },
    "notice": {
      "type": "object",
      "required": [
        "reason"
      ],
      "additionalProperties": false,
      "properties": {
        "reason": {
          "type": "string"
        },
        "replacement": {
          "type": "string"
        }
      }
    },
    "artifact_source": {
      "type": "object",
      "required": [
        "url",
        "kind"
      ],
      "additionalProperties": false,
      "properties": {
        "url": {
          "$ref": "#/$defs/url"
        },
        "kind": {
          "enum": [
            "publisher",
            "mirror"
          ]
        },
        "name": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "signature": {
      "type": "object",
      "required": [
        "format",
        "url"
      ],
      "additionalProperties": false,
      "properties": {
        "format": {
          "type": "string"
        },
        "url": {
          "$ref": "#/$defs/url"
        },
        "issuer": {
          "$ref": "#/$defs/url"
        },
        "identity": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "jess": {
      "description": "The artifact's jess block as the manifest carries it.",
      "type": "object",
      "required": [
        "package",
        "jess_api",
        "content_digest",
        "dependencies"
      ],
      "additionalProperties": false,
      "properties": {
        "package": {
          "$ref": "#/$defs/package_id"
        },
        "jess_api": {
          "type": "string",
          "minLength": 1
        },
        "content_digest": {
          "$ref": "#/$defs/hex64"
        },
        "dependencies": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/$defs/requirement"
          }
        }
      }
    }
  }
}
