# Proto record schema

All proto records emitted by a parser have target type,
defined at parser creation time. All types are based on an archetype, and the
archetype is defined at type creation time.

The archetype base schema and additional type-level configurations, such as the
data field schema and metadata bucket references, define the schema to which
individual records emitted by a parser must conform.

Schemas make dynamic references to the user-defined schemas at
type-level.

## Numeric archetype family

The following is an example of a schema for proto records in the numeric
archetype family.

    {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "Proto record schema for parsers targeting the Numeric archetype family",
      "type": "object",
      "properties": {
        "tagName": {
          "type": "string"
        },
        "data": {
          "type": "object",
          "properties": {
            "numeric": {
              "type": "number"
            }
          },
          "description": "Numeric measurement",
          "required": ["numeric"]
        },
        "embeddedMetadata": {
          "type": "object",
          "description": "Rapidly changing metadata"
        },
        "cloudMetadata": {
          "type": "array",
          "items": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "bucketReference": {
                    "type": "object",
                    "properties": {
                      "bucketName": {
                        "type": "string"
                      },
                      "version": {
                        "type": "number"
                      }
                    },
                    "required": ["bucketName", "version"]
                  },
                  "naturalKey": {
                    "type": "string"
                  }
                },
                "required": ["bucketReference", "naturalKey"]
              },
              {
                "type": "object",
                "properties": {
                  "bucketReference": {
                    "type": "object",
                    "properties": {
                      "bucketName": {
                        "type": "string"
                      },
                      "version": {
                        "type": "number"
                      }
                    },
                    "required": ["bucketName", "version"]
                  },
                  "instance": {
                    "type": "object",
                    "description": "The metadata instance",
                    "properties": {
                      "naturalKey": {
                        "type": "string"
                      },
                      "attributes": {
                        "$ref": "<Dynamic reference to the schema of the metadata bucket version>"
                      }
                    },
                    "required": ["attributes"]
                  }
                },
                "required": ["bucketReference", "instance"]
              }
            ]
          }
        },
        "timestamps": {
          "type": "object",
          "properties": {
            "eventTimestamp": {
              "type": "number",
              "description": "Event timestamp",
              "format": "unix-epoch-millis"
            }
          },
          "required": ["eventTimestamp"]
        },
        "clusterFields": {
          "type": "object",
          "description": "Optional fields for types of Cluster archetype",
          "properties": {
            "clusteredColumn1": {
              "type": "string"
            },
            "clusteredColumn2": {
              "type": "string"
            },
            "clusteredColumn3": {
              "type": "string"
            },
            "clusteredColumn4": {
              "type": "string"
            }
          }
        }
      },
      "required": ["tagName", "data", "timestamps"]
    }

## Discrete archetype family

The following is an example of a proto record schema for parsers targeting types
in the discrete archetype family.

    {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "Proto record schema for parsers targeting the Discrete archetype family",
      "type": "object",
      "properties": {
        "tagName": {
          "type": "string"
        },
        "data": {
          "type": "object",
          "properties": {
            "complex": {
              "$ref": "<Dynamic reference to the data field schema of the type version>"
            }
          },
          "required": ["complex"]
        },
        "embeddedMetadata": {
          "type": "object",
          "description": "Rapidly changing metadata"
        },
        "cloudMetadata": {
          "type": "array",
          "items": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "bucketReference": {
                    "type": "object",
                    "properties": {
                      "bucketName": {
                        "type": "string"
                      },
                      "version": {
                        "type": "number"
                      }
                    },
                    "required": ["bucketName", "version"]
                  },
                  "naturalKey": {
                    "type": "string"
                  }
                },
                "required": ["bucketReference", "naturalKey"]
              },
              {
                "type": "object",
                "properties": {
                  "bucketReference": {
                    "type": "object",
                    "properties": {
                      "bucketName": {
                        "type": "string"
                      },
                      "version": {
                        "type": "number"
                      }
                    },
                    "required": ["bucketName", "version"]
                  },
                  "instance": {
                    "type": "object",
                    "description": "The metadata instance",
                    "properties": {
                      "naturalKey": {
                        "type": "string"
                      },
                      "attributes": {
                        "$ref": "<Dynamic reference to the schema of the metadata bucket version>"
                      }
                    },
                    "required": ["attributes"]
                  }
                },
                "required": ["bucketReference", "instance"]
              }
            ]
          }
        },
        "timestamps": {
          "type": "object",
          "properties": {
            "eventTimestamp": {
              "type": "number",
              "description": "Event timestamp",
              "format": "unix-epoch-millis"
            }
          },
          "required": ["eventTimestamp"]
        },
        "clusterFields": {
          "type": "object",
          "description": "Optional fields for types of Cluster archetype",
          "properties": {
            "clusteredColumn1": {
              "type": "string"
            },
            "clusteredColumn2": {
              "type": "string"
            },
            "clusteredColumn3": {
              "type": "string"
            },
            "clusteredColumn4": {
              "type": "string"
            }
          }
        }
      },
      "required": ["tagName", "data", "timestamps"]
    }

## Continuous archetype family

The following is an example of a proto record schema for parsers targeting types
in the continuous archetype family.

    {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "title": "Proto record schema for parsers targeting the Discrete archetype family",
      "type": "object",
      "properties": {
        "tagName": {
          "type": "string"
        },
        "data": {
          "type": "object",
          "properties": {
            "complex": {
              "$ref": "<Dynamic reference to the data field schema of the type version>"
            }
          },
          "required": ["complex"]
        },
        "embeddedMetadata": {
          "type": "object",
          "description": "Rapidly changing metadata"
        },
        "cloudMetadata": {
          "type": "array",
          "items": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "bucketReference": {
                    "type": "object",
                    "properties": {
                      "bucketName": {
                        "type": "string"
                      },
                      "version": {
                        "type": "number"
                      }
                    },
                    "required": ["bucketName", "version"]
                  },
                  "naturalKey": {
                    "type": "string"
                  }
                },
                "required": ["bucketReference", "naturalKey"]
              },
              {
                "type": "object",
                "properties": {
                  "bucketReference": {
                    "type": "object",
                    "properties": {
                      "bucketName": {
                        "type": "string"
                      },
                      "version": {
                        "type": "number"
                      }
                    },
                    "required": ["bucketName", "version"]
                  },
                  "instance": {
                    "type": "object",
                    "description": "The metadata instance",
                    "properties": {
                      "naturalKey": {
                        "type": "string"
                      },
                      "attributes": {
                        "$ref": "<Dynamic reference to the schema of the metadata bucket version>"
                      }
                    },
                    "required": ["attributes"]
                  }
                },
                "required": ["bucketReference", "instance"]
              }
            ]
          }
        },
        "timestamps": {
          "type": "object",
          "properties": {
            "continuousTimestamp": {
              "type": "object",
              "properties": {
                "eventTimestampStart": {
                  "type": "number",
                  "description": "Event start timestamp",
                  "format": "unix-epoch-millis"
                },
                "eventTimestampEnd": {
                  "type": "number",
                  "description": "Event end timestamp",
                  "format": "unix-epoch-millis"
                }
              },
              "required": ["eventTimestampStart", "eventTimestampEnd"]
            }
          },
          "required": ["continuousTimestamp"]
        },
        "clusterFields": {
          "type": "object",
          "description": "Optional fields for types of Cluster archetype",
          "properties": {
            "clusteredColumn1": {
              "type": "string"
            },
            "clusteredColumn2": {
              "type": "string"
            },
            "clusteredColumn3": {
              "type": "string"
            },
            "clusteredColumn4": {
              "type": "string"
            }
          }
        }
      },
      "required": ["tagName", "data", "timestamps"]
    }