{
  "$type": "com.atproto.lexicon.schema",
  "defs": {
    "create": {
      "description": "Creates a record.",
      "properties": {
        "collection": {
          "description": "The record's collection.",
          "format": "nsid",
          "type": "string"
        },
        "rkey": {
          "description": "Defaults to a new TID.",
          "format": "record-key",
          "type": "string"
        },
        "value": {
          "description": "The record itself.",
          "type": "unknown"
        }
      },
      "required": [
        "collection",
        "value"
      ],
      "type": "object"
    },
    "createResult": {
      "description": "The outcome of a create.",
      "properties": {
        "cid": {
          "description": "The CID of the record or blob.",
          "format": "cid",
          "type": "string"
        },
        "uri": {
          "description": "The record's URI, the same one it keeps after a migration.",
          "format": "at-uri",
          "type": "string"
        }
      },
      "required": [
        "uri",
        "cid"
      ],
      "type": "object"
    },
    "delete": {
      "description": "Deletes a record.",
      "properties": {
        "collection": {
          "description": "The record's collection.",
          "format": "nsid",
          "type": "string"
        },
        "rkey": {
          "description": "The record key.",
          "format": "record-key",
          "type": "string"
        }
      },
      "required": [
        "collection",
        "rkey"
      ],
      "type": "object"
    },
    "deleteResult": {
      "description": "The outcome of a delete.",
      "properties": {},
      "type": "object"
    },
    "main": {
      "description": "Writes records to the requesting user's repo in a space the AppView hosts for them. The write is authorized the way the space's authority would authorize it, stored, and indexed like a synced write. Records keep the URIs they will have on the user's PDS after a migration.",
      "errors": [
        {
          "description": "The request has no valid service auth.",
          "name": "AuthRequired"
        },
        {
          "description": "The arguments are inconsistent or malformed beyond schema validation.",
          "name": "InvalidRequest"
        },
        {
          "description": "No space matches the given space reference.",
          "name": "SpaceNotFound"
        },
        {
          "description": "The caller may not write to or read from this repo in the space.",
          "name": "NotAuthorized"
        },
        {
          "description": "The AppView does not host the caller's repo in this space, because it lives on the caller's PDS. Write to the PDS instead.",
          "name": "RepoNotHosted"
        },
        {
          "description": "A record failed validation against its lexicon.",
          "name": "InvalidRecord"
        },
        {
          "description": "An update or delete names a record that does not exist.",
          "name": "RecordNotFound"
        }
      ],
      "input": {
        "encoding": "application/json",
        "schema": {
          "properties": {
            "space": {
              "description": "The space holding the repo.",
              "format": "space-ref",
              "type": "string"
            },
            "writes": {
              "description": "The writes, applied in order as one revision.",
              "items": {
                "closed": true,
                "refs": [
                  "#create",
                  "#update",
                  "#delete"
                ],
                "type": "union"
              },
              "maxLength": 200,
              "minLength": 1,
              "type": "array"
            }
          },
          "required": [
            "space",
            "writes"
          ],
          "type": "object"
        }
      },
      "output": {
        "encoding": "application/json",
        "schema": {
          "properties": {
            "results": {
              "description": "One result per write, in the same order.",
              "items": {
                "closed": true,
                "refs": [
                  "#createResult",
                  "#updateResult",
                  "#deleteResult"
                ],
                "type": "union"
              },
              "type": "array"
            },
            "rev": {
              "description": "The repo revision after the writes.",
              "format": "tid",
              "type": "string"
            }
          },
          "required": [
            "results",
            "rev"
          ],
          "type": "object"
        }
      },
      "type": "procedure"
    },
    "update": {
      "description": "Replaces a record.",
      "properties": {
        "collection": {
          "description": "The record's collection.",
          "format": "nsid",
          "type": "string"
        },
        "rkey": {
          "description": "The record key.",
          "format": "record-key",
          "type": "string"
        },
        "value": {
          "description": "The record itself.",
          "type": "unknown"
        }
      },
      "required": [
        "collection",
        "rkey",
        "value"
      ],
      "type": "object"
    },
    "updateResult": {
      "description": "The outcome of an update.",
      "properties": {
        "cid": {
          "description": "The CID of the record or blob.",
          "format": "cid",
          "type": "string"
        },
        "uri": {
          "description": "The record's URI, the same one it keeps after a migration.",
          "format": "at-uri",
          "type": "string"
        }
      },
      "required": [
        "uri",
        "cid"
      ],
      "type": "object"
    }
  },
  "id": "social.colibri.beta.polyfill.applyWrites",
  "lexicon": 1
}
