Wash ydoc content on the server side?

hey all !, i run into a problem washing data on the server side.

in my scene, server encodeStateAsUpdate as snapshot after user click “publish” button, at the same time server should replace/wash some keyword according to the RPC result.

what borthers me is that:
The editor is based on Prosemirror, i can serialize the doc back to prosemirror’state or htmlstring then wash the content, but if i do like that, the doc is less of a collaborative state but more of a initial state, cus i cannot parse the washed state or htmlstring back to snapshot and show version diff, right ? the washed state or htmlstring can only be applied to init the doc and loss all updates once applied on that doc.

i my opinion, i should do something like “y.method()” on the server side to modify doc by update。but i don not have a clue how extract and modify on the server side…
any suggestion ?

What do you mean by washing?

I’m sorry, but I’m struggling to understand the problem.

If you want to show ProseMirror diffs you can’t discard the Yjs document (you need to store the Yjs document, not the ProseMirror document). You can show ProseMirror diffs using state vectors and the latest Yjs document. The Yjs document retains all history. The state vector points to a time in history. You can also use the state vector to compute document updates.

i my opinion, i should do something like “y.method()” on the server side to modify doc by update。but i don not have a clue how extract and modify on the server side…

See here: https://github.com/yjs/yjs#Document-Updates

sorry for not expressing the issue clearly.

“wash” means i need replace sensitive / dirty word text or improper video element on the server side, if the persistenct storeage is based on prosemirror without collaboration, i can handle the json or htmlstring directly, what if i embeded prosemirror with yjs ? should i transform data format between yxml and prosemirror or just add updates like “y.insert()” on the server side…

So you want to do some transformations on the document, before the server persists the document somewhere.

Sure you can just use the Y.Xml* types to do transformations. They work just like normal data types.

There is an expandable section “Y.XmlElement” in https://github.com/yjs/yjs#api that documents all available methods.

For example you could do ydoc.get('prosemirror', Y.XmlFragment).delete(0, 1). in order to delete the first paragraph.

wow!i get it , thanks for your patience