{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:junexis:schema:package:0.1",
  "title": "Manifest pakietu aplikacyjnego Junexis 0.1",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "id", "namespace", "version", "language", "targets", "capabilities", "exports", "dependencies", "files"],
  "properties": {
    "schemaVersion": { "const": "junexis.package/0.1" },
    "id": { "$ref": "#/$defs/packageId" },
    "namespace": { "$ref": "#/$defs/moduleIdentity" },
    "version": { "$ref": "#/$defs/semver" },
    "language": {
      "type": "object",
      "additionalProperties": false,
      "required": ["minimum", "maximumExclusive"],
      "properties": {
        "minimum": { "$ref": "#/$defs/semver" },
        "maximumExclusive": { "$ref": "#/$defs/semver" }
      }
    },
    "targets": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": { "enum": ["embedded", "server", "report"] }
    },
    "capabilities": {
      "type": "array",
      "uniqueItems": true,
      "items": { "type": "string", "pattern": "^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$" }
    },
    "exports": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["module", "path"],
        "properties": {
          "module": { "$ref": "#/$defs/moduleIdentity" },
          "path": { "$ref": "#/$defs/sourcePath" }
        }
      }
    },
    "dependencies": {
      "type": "array",
      "uniqueItems": true,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "version"],
        "properties": {
          "id": { "$ref": "#/$defs/packageId" },
          "version": { "$ref": "#/$defs/semver" }
        }
      }
    },
    "files": {
      "type": "array",
      "minItems": 1,
      "maxItems": 10000,
      "uniqueItems": true,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["path", "sizeBytes", "sha256"],
        "properties": {
          "path": { "$ref": "#/$defs/packagePath" },
          "sizeBytes": { "type": "integer", "minimum": 1, "maximum": 67108864 },
          "sha256": { "$ref": "#/$defs/sha256" }
        }
      }
    }
  },
  "$defs": {
    "packageId": { "type": "string", "pattern": "^[a-z][a-z0-9]*(?:[.-][a-z0-9]+)*$" },
    "moduleIdentity": { "type": "string", "pattern": "^[A-Za-z_][A-Za-z0-9_]*(?:::[A-Za-z_][A-Za-z0-9_]*)*$" },
    "sourcePath": {
      "type": "string",
      "maxLength": 1024,
      "pattern": "^(?!.*(?:^|/)\\.{1,2}(?:/|$))[A-Za-z0-9_-]+(?:/[A-Za-z0-9_-]+)*\\.jnx$",
      "not": { "$ref": "#/$defs/windowsDevicePath" }
    },
    "packagePath": {
      "type": "string",
      "maxLength": 1024,
      "pattern": "^(?!.*(?:^|/)\\.{1,2}(?:/|$))[A-Za-z0-9._-]+(?:/[A-Za-z0-9._-]+)*$",
      "not": { "$ref": "#/$defs/windowsDevicePath" }
    },
    "windowsDevicePath": {
      "type": "string",
      "pattern": "(?:^|/)(?:[Cc][Oo][Nn]|[Pp][Rr][Nn]|[Aa][Uu][Xx]|[Nn][Uu][Ll]|[Cc][Oo][Mm][1-9]|[Ll][Pp][Tt][1-9])(?:\\.|/|$)"
    },
    "semver": {
      "type": "string",
      "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(?:-((?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*)(?:\\.(?:0|[1-9][0-9]*|[0-9]*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\\+([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?$"
    },
    "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" }
  }
}