{
  "type": "object",
  "properties": {
    "slug": {
      "type": "string",
      "pattern": "^(@[a-z0-9-]+\\/([a-z0-9-]*)|[a-z0-9-]+)$",
      "description": "Unique identifier for this sync manifest, only use hyphens and alphanumeric characters."
    },
    "manifestVersion": {
      "type": "number",
      "description": "Version of the manifest file format."
    },
    "$schema": {
      "type": "string",
      "description": "URL for the self-describing JSON schema."
    },
    "connections": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "slug": {
            "type": "string",
            "description": "Unique identifier for the connection."
          },
          "config": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "connectionType": {
                    "type": "string",
                    "const": "postgres",
                    "description": "Postgres connection type."
                  },
                  "host": {
                    "type": "string"
                  },
                  "port": {
                    "type": "number"
                  },
                  "user": {
                    "type": "string"
                  },
                  "password": {
                    "type": "string"
                  },
                  "database": {
                    "type": "string"
                  }
                },
                "required": [
                  "connectionType",
                  "host",
                  "port",
                  "user",
                  "password",
                  "database"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "connectionType": {
                    "type": "string",
                    "const": "in-memory"
                  }
                },
                "required": [
                  "connectionType"
                ],
                "additionalProperties": false
              }
            ],
            "description": "Configuration details specific to the connection type."
          }
        },
        "required": [
          "slug",
          "config"
        ],
        "additionalProperties": false
      }
    },
    "dataStores": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "connectionSlug": {
            "type": "string",
            "description": "Slug of the connection to use for this data store."
          },
          "config": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "connectionType": {
                    "type": "string",
                    "const": "postgres",
                    "description": "Postgres connection type."
                  },
                  "slotName": {
                    "type": "string",
                    "pattern": "^[a-z0-9_]+$",
                    "description": "Name of the replication slot."
                  },
                  "publicationName": {
                    "type": "string",
                    "pattern": "^[a-z0-9_]+$",
                    "description": "Name of the publication."
                  },
                  "tables": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    },
                    "description": "Tables to replicate."
                  },
                  "allTables": {
                    "type": "boolean",
                    "description": "When true, all tables are replicated."
                  }
                },
                "required": [
                  "connectionType",
                  "slotName",
                  "publicationName"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "connectionType": {
                    "type": "string",
                    "const": "in-memory"
                  }
                },
                "required": [
                  "connectionType"
                ],
                "additionalProperties": false
              }
            ],
            "description": "Configuration details specific to the data store type."
          }
        },
        "required": [
          "connectionSlug"
        ],
        "additionalProperties": false
      }
    },
    "eventStores": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "connectionSlug": {
            "type": "string",
            "description": "Slug of the connection to use for this event store."
          }
        },
        "required": [
          "connectionSlug"
        ],
        "additionalProperties": false
      }
    },
    "publicSchemas": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "Unique name for the public schema."
          },
          "source": {
            "type": "object",
            "properties": {
              "dataStoreSlug": {
                "type": "string",
                "minLength": 1,
                "description": "Slug of the data store that contains the source data."
              }
            },
            "required": [
              "dataStoreSlug"
            ],
            "additionalProperties": false
          },
          "outputSchema": {
            "$ref": "http://json-schema.org/draft-07/schema#"
          },
          "version": {
            "type": "object",
            "properties": {
              "major": {
                "type": "number"
              },
              "minor": {
                "type": "number"
              }
            },
            "required": [
              "major",
              "minor"
            ],
            "additionalProperties": false
          },
          "definitionFile": {
            "type": "string",
            "description": "Path to the source file defining this schema."
          },
          "config": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "publicSchemaType": {
                    "type": "string",
                    "const": "postgres"
                  },
                  "transformations": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "operation": {
                          "type": "string",
                          "enum": [
                            "insert",
                            "update",
                            "delete"
                          ],
                          "description": "This transformation will be used when this operation is executed on the source table."
                        },
                        "table": {
                          "type": "string",
                          "description": "This transformation will be applied when this source table is changed."
                        },
                        "sql": {
                          "type": "string",
                          "description": "The SQL query to execute when a relevant operation is performed on the source table. This query supports positional query parameters ($1, $2), or named parameters (:name), but not both at the same time. Note that positional parameters will be ordered according to the column order in the table definition."
                        }
                      },
                      "required": [
                        "operation",
                        "table",
                        "sql"
                      ],
                      "additionalProperties": false
                    }
                  }
                },
                "required": [
                  "publicSchemaType",
                  "transformations"
                ],
                "additionalProperties": false
              }
            ],
            "description": "Configuration details specific to the public schema type."
          }
        },
        "required": [
          "name",
          "source",
          "outputSchema",
          "version",
          "config"
        ],
        "additionalProperties": false
      },
      "description": "Public Schemas governed by this manifest."
    },
    "consumerSchemas": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "Unique name for the consumer schema."
          },
          "sourceManifestSlug": {
            "type": "string",
            "minLength": 1,
            "description": "Slug of the manifest containing the definition of the public schema."
          },
          "publicSchema": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1
              },
              "majorVersion": {
                "type": "number"
              }
            },
            "required": [
              "name",
              "majorVersion"
            ],
            "additionalProperties": false,
            "description": "Reference to a specific version of a public schema."
          },
          "definitionFile": {
            "type": "string",
            "description": "Path to the source file defining this schema."
          },
          "config": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "consumerSchemaType": {
                    "type": "string",
                    "const": "postgres",
                    "description": "Postgres consumer schema type."
                  },
                  "destinationDataStoreSlug": {
                    "type": "string",
                    "description": "Slug of the data store to write to."
                  },
                  "sql": {
                    "type": "string",
                    "description": "SQL to execute when an insert or update operation is performed in the referenced public schema."
                  },
                  "deleteSql": {
                    "type": "string",
                    "description": "SQL to execute when a delete operation is performed in the referenced public schema."
                  }
                },
                "required": [
                  "consumerSchemaType",
                  "destinationDataStoreSlug",
                  "sql"
                ],
                "additionalProperties": false
              }
            ],
            "description": "Configuration details specific to the consumer schema type."
          }
        },
        "required": [
          "name",
          "sourceManifestSlug",
          "publicSchema",
          "config"
        ],
        "additionalProperties": false
      },
      "description": "Consumer Schemas governed by this manifest."
    },
    "workspaces": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "(Relative) path(s) to other manifest files that should be combined to create the workspace."
    }
  },
  "required": [
    "slug",
    "manifestVersion"
  ],
  "additionalProperties": false,
  "$schema": "http://json-schema.org/draft-07/schema#"
}
