MCPcopy Create free account
hub / github.com/editablejs/editable / storeUpdate

Function storeUpdate

packages/yjs-websocket/src/server/mongodb/utils.ts:120–139  ·  view source on GitHub ↗
(
  adapter: MongoAdapter,
  docName: string,
  update: Uint8Array,
)

Source from the content-addressed store, hash-verified

118}
119
120export 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.

Callers 1

flushDocumentFunction · 0.85

Calls 4

getCurrentUpdateClockFunction · 0.85
writeStateVectorFunction · 0.85
createDocumentUpdateKeyFunction · 0.85
putMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…