# social.colibri.beta.polyfill.applyWrites

> 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.

- Kind: procedure
- Authority: polyfill.beta.colibri.social
- Lexicon: 1
- Published by [colibri.social](https://lexicon.garden/identity/did:plc:mprdjqjluoswa7awzggaggj3), the NSID's authority

## Links

- [Documentation](https://lexicon.garden/lexicon/did:plc:mprdjqjluoswa7awzggaggj3/social.colibri.beta.polyfill.applyWrites)
- [Schema JSON](https://lexicon.garden/lexicon/did:plc:mprdjqjluoswa7awzggaggj3/social.colibri.beta.polyfill.applyWrites/schema.json)
- [Analytics](https://lexicon.garden/lexicon/did:plc:mprdjqjluoswa7awzggaggj3/social.colibri.beta.polyfill.applyWrites/analytics)

## Procedure (`social.colibri.beta.polyfill.applyWrites`)

Type: procedure · POST

### Input (application/json)

- `space` (string · space-ref, required): The space holding the repo.
- `writes` (array, required): The writes, applied in order as one revision.
  - Constraints: minLength: 1, maxLength: 200
  - `items` (union)
    - One of (closed): `#create`, `#update`, `#delete`

### Output (application/json)

- `results` (array, required): One result per write, in the same order.
  - `items` (union)
    - One of (closed): `#createResult`, `#updateResult`, `#deleteResult`
- `rev` (string · tid, required): The repo revision after the writes.

### Errors

- `AuthRequired`: The request has no valid service auth.
- `InvalidRequest`: The arguments are inconsistent or malformed beyond schema validation.
- `SpaceNotFound`: No space matches the given space reference.
- `NotAuthorized`: The caller may not write to or read from this repo in the space.
- `RepoNotHosted`: 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.
- `InvalidRecord`: A record failed validation against its lexicon.
- `RecordNotFound`: An update or delete names a record that does not exist.

## #create (`social.colibri.beta.polyfill.applyWrites#create`)

Type: object

Creates a record.

### Properties

- `collection` (string · nsid, required): The record's collection.
- `rkey` (string · record-key): Defaults to a new TID.
- `value` (unknown, required): The record itself.

## #createResult (`social.colibri.beta.polyfill.applyWrites#createResult`)

Type: object

The outcome of a create.

### Properties

- `cid` (string · cid, required): The CID of the record or blob.
- `uri` (string · at-uri, required): The record's URI, the same one it keeps after a migration.

## #delete (`social.colibri.beta.polyfill.applyWrites#delete`)

Type: object

Deletes a record.

### Properties

- `collection` (string · nsid, required): The record's collection.
- `rkey` (string · record-key, required): The record key.

## #deleteResult (`social.colibri.beta.polyfill.applyWrites#deleteResult`)

Type: object

The outcome of a delete.

### Properties


## #update (`social.colibri.beta.polyfill.applyWrites#update`)

Type: object

Replaces a record.

### Properties

- `collection` (string · nsid, required): The record's collection.
- `rkey` (string · record-key, required): The record key.
- `value` (unknown, required): The record itself.

## #updateResult (`social.colibri.beta.polyfill.applyWrites#updateResult`)

Type: object

The outcome of an update.

### Properties

- `cid` (string · cid, required): The CID of the record or blob.
- `uri` (string · at-uri, required): The record's URI, the same one it keeps after a migration.

## Schema

```json
{
  "$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
}
```
