( adapter: MongoAdapter, docName: string, update: Uint8Array, )
| 118 | } |
| 119 | |
| 120 | export const storeUpdate = async ( |
| 121 | adapter: MongoAdapter, |
| 122 | docName: string, |
| 123 | update: Uint8Array, |
| 124 | ): Promise<number> => { |
| 125 | const clock = await getCurrentUpdateClock(adapter, docName) |
| 126 | if (clock === -1) { |
| 127 | // make sure that a state vector is always written, so we can search for available documents |
| 128 | const ydoc = new Y.Doc() |
| 129 | Y.applyUpdate(ydoc, update) |
| 130 | const sv = Y.encodeStateVector(ydoc) |
| 131 | await writeStateVector(adapter, docName, sv, 0) |
| 132 | } |
| 133 | |
| 134 | await adapter.put(createDocumentUpdateKey(docName, clock + 1), { |
| 135 | value: Buffer.from(update), |
| 136 | }) |
| 137 | |
| 138 | return clock + 1 |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * For now this is a helper method that creates a Y.Doc and then re-encodes a document update. |
no test coverage detected
searching dependent graphs…