{
  "$id": "https://schema.rtemis.org/dataref/v1/schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "rtemis DataRef",
  "description": "A reference from a record to a file written beside it: where it is, how it is encoded, how big it is, and the digest that ties it to the record naming it.",
  "type": "object",
  "properties": {
    "$schema": {
      "description": "JSON Schema URI for this document.",
      "type": "string",
      "const": "https://schema.rtemis.org/dataref/v1/schema.json"
    },
    "path": {
      "description": "Path to the file, relative to the record that names it.",
      "type": "string",
      "x-rtemis": {
        "type": "string"
      }
    },
    "encoding": {
      "description": "How the file is written. Two digests are comparable only if they share one.",
      "type": "string",
      "enum": ["parquet"],
      "x-rtemis": {
        "type": "string"
      }
    },
    "algorithm": {
      "description": "Hash algorithm, recorded so a hash is verifiable rather than merely comparable.",
      "type": "string",
      "enum": ["sha256", "sha512", "sha384", "sha224", "sha3-256", "sha3-512", "blake2b", "blake2s", "sha1", "md5"],
      "x-rtemis": {
        "type": "string"
      }
    },
    "hash": {
      "description": "Hash digest of the file's bytes, as hex.",
      "type": "string",
      "x-rtemis": {
        "type": "string"
      }
    },
    "bytes": {
      "description": "Size of the file.",
      "type": "number",
      "minimum": 0,
      "x-rtemis": {
        "type": "number"
      }
    },
    "n_rows": {
      "description": "Rows, when the referenced file is a table.",
      "type": ["integer", "null"],
      "minimum": 0,
      "x-rtemis": {
        "type": "integer"
      }
    },
    "n_cols": {
      "description": "Columns in the complete referenced table, before selecting columns.",
      "type": ["integer", "null"],
      "minimum": 0,
      "x-rtemis": {
        "type": "integer"
      }
    },
    "layout": {
      "description": "Value shape restored from the selected columns.",
      "type": ["string", "null"],
      "enum": [
        "array",
        "matrix",
        "factor",
        null
      ],
      "x-rtemis": {
        "type": "string"
      }
    },
    "columns": {
      "description": "Selected column names in the order used to reconstruct the value.",
      "type": ["array", "null"],
      "items": {
        "type": "string"
      },
      "minItems": 1,
      "uniqueItems": true,
      "x-rtemis": {
        "type": "string",
        "container": "array"
      }
    },
    "levels": {
      "description": "Ordered categorical levels, including unused levels; null for other layouts.",
      "type": ["array", "null"],
      "items": {
        "type": "string"
      },
      "minItems": 1,
      "uniqueItems": true,
      "x-rtemis": {
        "type": "string",
        "container": "array"
      }
    }
  },
  "additionalProperties": false,
  "allOf": [
    {
      "properties": {
        "path": {
          "minLength": 1
        },
        "hash": {
          "minLength": 1
        }
      },
      "$comment": "dataref.identity"
    }
  ],
  "x-rtemis": {
    "rules": [
      {
        "properties": [
          "path",
          "hash"
        ],
        "id": "dataref.identity",
        "message": "path must name a file and hash must contain its digest.",
        "kind": "NonEmptyStrings"
      }
    ],
    "publication": {
      "producer": "rtemis",
      "language": "r",
      "scope": "shared",
      "domain": "ml",
      "class": "rtemis::DataRef",
      "role": "document",
      "kind": "component",
      "order": 2
    }
  }
}
