{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://grids365.dev/corpus/language-features.schema.json",
  "title": "Dual-authority Grid controlled language feature registry",
  "type": "object",
  "required": [
    "schemaVersion",
    "generatedBy",
    "language",
    "languageVersion",
    "featureAuthorityVersion",
    "compatibility",
    "provenance",
    "counts",
    "features"
  ],
  "properties": {
    "schemaVersion": { "const": 2 },
    "generatedBy": { "const": "scripts/language-feature-registry.mjs" },
    "language": { "const": "Grid" },
    "languageVersion": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
    },
    "featureAuthorityVersion": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
    },
    "compatibility": {
      "type": "object",
      "required": [
        "languageExportToFeatureAuthority",
        "authorityAdditions",
        "featureMetadataSource",
        "licenseCompatibility"
      ],
      "properties": {
        "languageExportToFeatureAuthority": {
          "const": "pinned-feature-subset-with-identical-status"
        },
        "authorityAdditions": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string",
            "pattern": "^[a-z0-9]+(?:_[a-z0-9]+)*$"
          }
        },
        "featureMetadataSource": { "const": "featureAuthority" },
        "licenseCompatibility": { "const": "byte-identical" }
      },
      "additionalProperties": false
    },
    "provenance": {
      "type": "object",
      "required": ["languageExport", "featureAuthority"],
      "properties": {
        "languageExport": {
          "type": "object",
          "required": [
            "languageVersion",
            "sourceCommit",
            "manifest",
            "featureMatrix",
            "licenseSnapshot"
          ],
          "properties": {
            "languageVersion": { "$ref": "#/$defs/languageVersion" },
            "sourceCommit": { "$ref": "#/$defs/gitObjectId" },
            "manifest": { "$ref": "#/$defs/exportManifestIdentity" },
            "featureMatrix": { "$ref": "#/$defs/featureMatrixIdentity" },
            "licenseSnapshot": { "$ref": "#/$defs/siteLicenseIdentity" }
          },
          "additionalProperties": false
        },
        "featureAuthority": {
          "type": "object",
          "required": [
            "languageVersion",
            "sourceCommit",
            "sourceTree",
            "sourceCommittedAt",
            "manifest",
            "featureMatrix",
            "authoritativeRegistry",
            "traceabilityReport",
            "license",
            "publicDocs"
          ],
          "properties": {
            "languageVersion": { "$ref": "#/$defs/languageVersion" },
            "sourceCommit": { "$ref": "#/$defs/gitObjectId" },
            "sourceTree": { "$ref": "#/$defs/gitObjectId" },
            "sourceCommittedAt": { "$ref": "#/$defs/sourceCommittedAt" },
            "manifest": { "$ref": "#/$defs/authorityManifestIdentity" },
            "featureMatrix": { "$ref": "#/$defs/authorityFeatureMatrixIdentity" },
            "authoritativeRegistry": { "$ref": "#/$defs/authoritativeRegistryIdentity" },
            "traceabilityReport": { "$ref": "#/$defs/traceabilityReportIdentity" },
            "license": { "$ref": "#/$defs/authorityLicenseIdentity" },
            "publicDocs": {
              "type": "array",
              "minItems": 1,
              "uniqueItems": true,
              "items": { "$ref": "#/$defs/authorityPublicDocIdentity" }
            }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "counts": {
      "type": "object",
      "required": ["total", "supported", "syntaxOnly", "diagnostic", "kinds", "metadata"],
      "properties": {
        "total": { "type": "integer", "minimum": 1 },
        "supported": { "type": "integer", "minimum": 0 },
        "syntaxOnly": { "type": "integer", "minimum": 0 },
        "diagnostic": { "type": "integer", "minimum": 0 },
        "kinds": {
          "type": "object",
          "required": ["syntax", "semantic", "diagnostic"],
          "properties": {
            "syntax": { "type": "integer", "minimum": 0 },
            "semantic": { "type": "integer", "minimum": 0 },
            "diagnostic": { "type": "integer", "minimum": 0 }
          },
          "additionalProperties": false
        },
        "metadata": {
          "type": "object",
          "required": [
            "withRuntimeOwner",
            "evidenceReferences"
          ],
          "properties": {
            "withRuntimeOwner": { "type": "integer", "minimum": 0 },
            "evidenceReferences": { "type": "integer", "minimum": 1 }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "features": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": { "$ref": "#/$defs/feature" }
    }
  },
  "$defs": {
    "languageVersion": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
    },
    "gitObjectId": {
      "type": "string",
      "pattern": "^(?:[0-9a-f]{40}|[0-9a-f]{64})$"
    },
    "sourceCommittedAt": {
      "type": "string",
      "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}(?:\\.[0-9]+)?(?:Z|[+-][0-9]{2}:[0-9]{2})$"
    },
    "sha256": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "fileIdentity": {
      "type": "object",
      "required": ["path", "sha256", "bytes"],
      "properties": {
        "path": { "type": "string", "minLength": 1 },
        "sha256": { "$ref": "#/$defs/sha256" },
        "bytes": { "type": "integer", "minimum": 1 }
      },
      "additionalProperties": false
    },
    "mirroredFileIdentity": {
      "type": "object",
      "required": ["path", "sha256", "bytes", "mirroredAt"],
      "properties": {
        "path": { "type": "string", "minLength": 1 },
        "sha256": { "$ref": "#/$defs/sha256" },
        "bytes": { "type": "integer", "minimum": 1 },
        "mirroredAt": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    },
    "exportManifestIdentity": {
      "allOf": [
        { "$ref": "#/$defs/fileIdentity" },
        { "type": "object", "properties": { "path": { "const": "export-manifest.json" } } }
      ]
    },
    "featureMatrixIdentity": {
      "allOf": [
        { "$ref": "#/$defs/fileIdentity" },
        { "type": "object", "properties": { "path": { "const": "docs/language/features.md" } } }
      ]
    },
    "siteLicenseIdentity": {
      "allOf": [
        { "$ref": "#/$defs/fileIdentity" },
        {
          "type": "object",
          "properties": {
            "path": { "const": "content/download-sources/grid-core/LICENSE" }
          }
        }
      ]
    },
    "authorityManifestIdentity": {
      "allOf": [
        { "$ref": "#/$defs/fileIdentity" },
        { "type": "object", "properties": { "path": { "const": "content/language-feature-authority/manifest.json" } } }
      ]
    },
    "authorityFeatureMatrixIdentity": {
      "allOf": [
        { "$ref": "#/$defs/mirroredFileIdentity" },
        {
          "type": "object",
          "properties": {
            "path": { "const": "docs/language/features.md" },
            "mirroredAt": { "const": "content/language-feature-authority/docs/language/features.md" }
          }
        }
      ]
    },
    "authoritativeRegistryIdentity": {
      "allOf": [
        { "$ref": "#/$defs/mirroredFileIdentity" },
        {
          "type": "object",
          "properties": {
            "path": { "const": "docs/specs/language_feature_registry.json" },
            "mirroredAt": { "const": "content/language-feature-authority/docs/specs/language_feature_registry.json" }
          }
        }
      ]
    },
    "traceabilityReportIdentity": {
      "allOf": [
        { "$ref": "#/$defs/mirroredFileIdentity" },
        {
          "type": "object",
          "properties": {
            "path": { "const": "docs/specs/language_feature_traceability.md" },
            "mirroredAt": { "const": "content/language-feature-authority/docs/specs/language_feature_traceability.md" }
          }
        }
      ]
    },
    "authorityLicenseIdentity": {
      "allOf": [
        { "$ref": "#/$defs/mirroredFileIdentity" },
        {
          "type": "object",
          "properties": {
            "path": { "const": "LICENSE" },
            "mirroredAt": { "const": "content/language-feature-authority/LICENSE" }
          }
        }
      ]
    },
    "authorityPublicDocIdentity": {
      "allOf": [
        { "$ref": "#/$defs/mirroredFileIdentity" },
        {
          "type": "object",
          "properties": {
            "path": { "$ref": "#/$defs/publicDocPath" },
            "mirroredAt": {
              "type": "string",
              "pattern": "^content/language-feature-authority/docs/language/(?:[a-z0-9][a-z0-9._-]*/)*[a-z0-9][a-z0-9._-]*\\.md$"
            }
          }
        }
      ]
    },
    "repositoryPath": {
      "type": "string",
      "minLength": 1,
      "pattern": "^(?!/)(?!.*(?:^|/)\\.{1,2}(?:/|$))(?!.*\\\\)(?!.*//)[^\\u0000]+$"
    },
    "publicDocPath": {
      "type": "string",
      "pattern": "^docs/language/(?:[a-z0-9][a-z0-9._-]*/)*[a-z0-9][a-z0-9._-]*\\.md$"
    },
    "nonEmptyString": {
      "type": "string",
      "minLength": 1,
      "pattern": "^.*\\S.*$"
    },
    "owners": {
      "type": "object",
      "required": ["parser", "lowering", "runtime"],
      "properties": {
        "parser": { "$ref": "#/$defs/nonEmptyString" },
        "lowering": { "$ref": "#/$defs/nonEmptyString" },
        "runtime": {
          "oneOf": [
            { "$ref": "#/$defs/nonEmptyString" },
            { "type": "null" }
          ]
        }
      },
      "additionalProperties": false
    },
    "evidence": {
      "type": "object",
      "required": ["path", "test"],
      "properties": {
        "path": { "$ref": "#/$defs/repositoryPath" },
        "test": { "$ref": "#/$defs/nonEmptyString" }
      },
      "additionalProperties": false
    },
    "feature": {
      "type": "object",
      "required": [
        "id",
        "title",
        "status",
        "kind",
        "publicDoc",
        "owners",
        "evidence"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:_[a-z0-9]+)*$"
        },
        "title": { "$ref": "#/$defs/nonEmptyString" },
        "status": { "enum": ["supported", "syntax-only", "diagnostic"] },
        "kind": { "enum": ["syntax", "semantic", "diagnostic"] },
        "publicDoc": { "$ref": "#/$defs/publicDocPath" },
        "owners": { "$ref": "#/$defs/owners" },
        "evidence": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": { "$ref": "#/$defs/evidence" }
        }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
