🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

y-protocols

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

y-protocols - npm Package Compare versions

Comparing version
1.0.6
to
1.0.7
+8
-4
dist/sync.cjs

@@ -104,7 +104,9 @@ 'use strict';

* @param {any} transactionOrigin
* @param {(error:Error)=>any} [errorHandler]
*/
const readSyncStep2 = (decoder, doc, transactionOrigin) => {
const readSyncStep2 = (decoder, doc, transactionOrigin, errorHandler) => {
try {
Y__namespace.applyUpdate(doc, decoding__namespace.readVarUint8Array(decoder), transactionOrigin);
} catch (error) {
if (errorHandler != null) errorHandler(/** @type {Error} */ (error));
// This catches errors that are thrown by event handlers

@@ -130,2 +132,3 @@ console.error('Caught error while handling a Yjs update', error);

* @param {any} transactionOrigin
* @param {(error:Error)=>any} [errorHandler]
*/

@@ -139,4 +142,5 @@ const readUpdate = readSyncStep2;

* @param {any} transactionOrigin
* @param {(error:Error)=>any} [errorHandler] Optional error handler that catches errors when reading Yjs messages.
*/
const readSyncMessage = (decoder, encoder, doc, transactionOrigin) => {
const readSyncMessage = (decoder, encoder, doc, transactionOrigin, errorHandler) => {
const messageType = decoding__namespace.readVarUint(decoder);

@@ -148,6 +152,6 @@ switch (messageType) {

case messageYjsSyncStep2:
readSyncStep2(decoder, doc, transactionOrigin);
readSyncStep2(decoder, doc, transactionOrigin, errorHandler);
break
case messageYjsUpdate:
readUpdate(decoder, doc, transactionOrigin);
readUpdate(decoder, doc, transactionOrigin, errorHandler);
break

@@ -154,0 +158,0 @@ default:

@@ -1,1 +0,1 @@

{"version":3,"file":"sync.cjs","sources":["../sync.js"],"sourcesContent":["/**\n * @module sync-protocol\n */\n\nimport * as encoding from 'lib0/encoding'\nimport * as decoding from 'lib0/decoding'\nimport * as Y from 'yjs'\n\n/**\n * @typedef {Map<number, number>} StateMap\n */\n\n/**\n * Core Yjs defines two message types:\n * • YjsSyncStep1: Includes the State Set of the sending client. When received, the client should reply with YjsSyncStep2.\n * • YjsSyncStep2: Includes all missing structs and the complete delete set. When received, the client is assured that it\n * received all information from the remote client.\n *\n * In a peer-to-peer network, you may want to introduce a SyncDone message type. Both parties should initiate the connection\n * with SyncStep1. When a client received SyncStep2, it should reply with SyncDone. When the local client received both\n * SyncStep2 and SyncDone, it is assured that it is synced to the remote client.\n *\n * In a client-server model, you want to handle this differently: The client should initiate the connection with SyncStep1.\n * When the server receives SyncStep1, it should reply with SyncStep2 immediately followed by SyncStep1. The client replies\n * with SyncStep2 when it receives SyncStep1. Optionally the server may send a SyncDone after it received SyncStep2, so the\n * client knows that the sync is finished. There are two reasons for this more elaborated sync model: 1. This protocol can\n * easily be implemented on top of http and websockets. 2. The server should only reply to requests, and not initiate them.\n * Therefore it is necessary that the client initiates the sync.\n *\n * Construction of a message:\n * [messageType : varUint, message definition..]\n *\n * Note: A message does not include information about the room name. This must to be handled by the upper layer protocol!\n *\n * stringify[messageType] stringifies a message definition (messageType is already read from the bufffer)\n */\n\nexport const messageYjsSyncStep1 = 0\nexport const messageYjsSyncStep2 = 1\nexport const messageYjsUpdate = 2\n\n/**\n * Create a sync step 1 message based on the state of the current shared document.\n *\n * @param {encoding.Encoder} encoder\n * @param {Y.Doc} doc\n */\nexport const writeSyncStep1 = (encoder, doc) => {\n encoding.writeVarUint(encoder, messageYjsSyncStep1)\n const sv = Y.encodeStateVector(doc)\n encoding.writeVarUint8Array(encoder, sv)\n}\n\n/**\n * @param {encoding.Encoder} encoder\n * @param {Y.Doc} doc\n * @param {Uint8Array} [encodedStateVector]\n */\nexport const writeSyncStep2 = (encoder, doc, encodedStateVector) => {\n encoding.writeVarUint(encoder, messageYjsSyncStep2)\n encoding.writeVarUint8Array(encoder, Y.encodeStateAsUpdate(doc, encodedStateVector))\n}\n\n/**\n * Read SyncStep1 message and reply with SyncStep2.\n *\n * @param {decoding.Decoder} decoder The reply to the received message\n * @param {encoding.Encoder} encoder The received message\n * @param {Y.Doc} doc\n */\nexport const readSyncStep1 = (decoder, encoder, doc) =>\n writeSyncStep2(encoder, doc, decoding.readVarUint8Array(decoder))\n\n/**\n * Read and apply Structs and then DeleteStore to a y instance.\n *\n * @param {decoding.Decoder} decoder\n * @param {Y.Doc} doc\n * @param {any} transactionOrigin\n */\nexport const readSyncStep2 = (decoder, doc, transactionOrigin) => {\n try {\n Y.applyUpdate(doc, decoding.readVarUint8Array(decoder), transactionOrigin)\n } catch (error) {\n // This catches errors that are thrown by event handlers\n console.error('Caught error while handling a Yjs update', error)\n }\n}\n\n/**\n * @param {encoding.Encoder} encoder\n * @param {Uint8Array} update\n */\nexport const writeUpdate = (encoder, update) => {\n encoding.writeVarUint(encoder, messageYjsUpdate)\n encoding.writeVarUint8Array(encoder, update)\n}\n\n/**\n * Read and apply Structs and then DeleteStore to a y instance.\n *\n * @param {decoding.Decoder} decoder\n * @param {Y.Doc} doc\n * @param {any} transactionOrigin\n */\nexport const readUpdate = readSyncStep2\n\n/**\n * @param {decoding.Decoder} decoder A message received from another client\n * @param {encoding.Encoder} encoder The reply message. Does not need to be sent if empty.\n * @param {Y.Doc} doc\n * @param {any} transactionOrigin\n */\nexport const readSyncMessage = (decoder, encoder, doc, transactionOrigin) => {\n const messageType = decoding.readVarUint(decoder)\n switch (messageType) {\n case messageYjsSyncStep1:\n readSyncStep1(decoder, encoder, doc)\n break\n case messageYjsSyncStep2:\n readSyncStep2(decoder, doc, transactionOrigin)\n break\n case messageYjsUpdate:\n readUpdate(decoder, doc, transactionOrigin)\n break\n default:\n throw new Error('Unknown message type')\n }\n return messageType\n}\n"],"names":["encoding","Y","decoding"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;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pE,GAAG;AACH,EAAC;AACD;AACA;AACA;AACA;AACA;AACY,MAAC,WAAW,GAAG,CAAC,OAAO,EAAE,MAAM,KAAK;AAChD,EAAEF,mBAAQ,CAAC,YAAY,CAAC,OAAO,EAAE,gBAAgB,EAAC;AAClD,EAAEA,mBAAQ,CAAC,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAC;AAC9C,EAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,UAAU,GAAG,cAAa;AACvC;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,eAAe,GAAG,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,iBAAiB,KAAK;AAC7E,EAAE,MAAM,WAAW,GAAGE,mBAAQ,CAAC,WAAW,CAAC,OAAO,EAAC;AACnD,EAAE,QAAQ,WAAW;AACrB,IAAI,KAAK,mBAAmB;AAC5B,MAAM,aAAa,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAC;AAC1C,MAAM,KAAK;AACX,IAAI,KAAK,mBAAmB;AAC5B,MAAM,aAAa,CAAC,OAAO,EAAE,GAAG,EAAE,iBAAiB,EAAC;AACpD,MAAM,KAAK;AACX,IAAI,KAAK,gBAAgB;AACzB,MAAM,UAAU,CAAC,OAAO,EAAE,GAAG,EAAE,iBAAiB,EAAC;AACjD,MAAM,KAAK;AACX,IAAI;AACJ,MAAM,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC;AAC7C,GAAG;AACH,EAAE,OAAO,WAAW;AACpB;;;;;;;;;;;;;"}
{"version":3,"file":"sync.cjs","sources":["../sync.js"],"sourcesContent":["/**\n * @module sync-protocol\n */\n\nimport * as encoding from 'lib0/encoding'\nimport * as decoding from 'lib0/decoding'\nimport * as Y from 'yjs'\n\n/**\n * @typedef {Map<number, number>} StateMap\n */\n\n/**\n * Core Yjs defines two message types:\n * • YjsSyncStep1: Includes the State Set of the sending client. When received, the client should reply with YjsSyncStep2.\n * • YjsSyncStep2: Includes all missing structs and the complete delete set. When received, the client is assured that it\n * received all information from the remote client.\n *\n * In a peer-to-peer network, you may want to introduce a SyncDone message type. Both parties should initiate the connection\n * with SyncStep1. When a client received SyncStep2, it should reply with SyncDone. When the local client received both\n * SyncStep2 and SyncDone, it is assured that it is synced to the remote client.\n *\n * In a client-server model, you want to handle this differently: The client should initiate the connection with SyncStep1.\n * When the server receives SyncStep1, it should reply with SyncStep2 immediately followed by SyncStep1. The client replies\n * with SyncStep2 when it receives SyncStep1. Optionally the server may send a SyncDone after it received SyncStep2, so the\n * client knows that the sync is finished. There are two reasons for this more elaborated sync model: 1. This protocol can\n * easily be implemented on top of http and websockets. 2. The server should only reply to requests, and not initiate them.\n * Therefore it is necessary that the client initiates the sync.\n *\n * Construction of a message:\n * [messageType : varUint, message definition..]\n *\n * Note: A message does not include information about the room name. This must to be handled by the upper layer protocol!\n *\n * stringify[messageType] stringifies a message definition (messageType is already read from the bufffer)\n */\n\nexport const messageYjsSyncStep1 = 0\nexport const messageYjsSyncStep2 = 1\nexport const messageYjsUpdate = 2\n\n/**\n * Create a sync step 1 message based on the state of the current shared document.\n *\n * @param {encoding.Encoder} encoder\n * @param {Y.Doc} doc\n */\nexport const writeSyncStep1 = (encoder, doc) => {\n encoding.writeVarUint(encoder, messageYjsSyncStep1)\n const sv = Y.encodeStateVector(doc)\n encoding.writeVarUint8Array(encoder, sv)\n}\n\n/**\n * @param {encoding.Encoder} encoder\n * @param {Y.Doc} doc\n * @param {Uint8Array} [encodedStateVector]\n */\nexport const writeSyncStep2 = (encoder, doc, encodedStateVector) => {\n encoding.writeVarUint(encoder, messageYjsSyncStep2)\n encoding.writeVarUint8Array(encoder, Y.encodeStateAsUpdate(doc, encodedStateVector))\n}\n\n/**\n * Read SyncStep1 message and reply with SyncStep2.\n *\n * @param {decoding.Decoder} decoder The reply to the received message\n * @param {encoding.Encoder} encoder The received message\n * @param {Y.Doc} doc\n */\nexport const readSyncStep1 = (decoder, encoder, doc) =>\n writeSyncStep2(encoder, doc, decoding.readVarUint8Array(decoder))\n\n/**\n * Read and apply Structs and then DeleteStore to a y instance.\n *\n * @param {decoding.Decoder} decoder\n * @param {Y.Doc} doc\n * @param {any} transactionOrigin\n * @param {(error:Error)=>any} [errorHandler]\n */\nexport const readSyncStep2 = (decoder, doc, transactionOrigin, errorHandler) => {\n try {\n Y.applyUpdate(doc, decoding.readVarUint8Array(decoder), transactionOrigin)\n } catch (error) {\n if (errorHandler != null) errorHandler(/** @type {Error} */ (error))\n // This catches errors that are thrown by event handlers\n console.error('Caught error while handling a Yjs update', error)\n }\n}\n\n/**\n * @param {encoding.Encoder} encoder\n * @param {Uint8Array} update\n */\nexport const writeUpdate = (encoder, update) => {\n encoding.writeVarUint(encoder, messageYjsUpdate)\n encoding.writeVarUint8Array(encoder, update)\n}\n\n/**\n * Read and apply Structs and then DeleteStore to a y instance.\n *\n * @param {decoding.Decoder} decoder\n * @param {Y.Doc} doc\n * @param {any} transactionOrigin\n * @param {(error:Error)=>any} [errorHandler]\n */\nexport const readUpdate = readSyncStep2\n\n/**\n * @param {decoding.Decoder} decoder A message received from another client\n * @param {encoding.Encoder} encoder The reply message. Does not need to be sent if empty.\n * @param {Y.Doc} doc\n * @param {any} transactionOrigin\n * @param {(error:Error)=>any} [errorHandler] Optional error handler that catches errors when reading Yjs messages.\n */\nexport const readSyncMessage = (decoder, encoder, doc, transactionOrigin, errorHandler) => {\n const messageType = decoding.readVarUint(decoder)\n switch (messageType) {\n case messageYjsSyncStep1:\n readSyncStep1(decoder, encoder, doc)\n break\n case messageYjsSyncStep2:\n readSyncStep2(decoder, doc, transactionOrigin, errorHandler)\n break\n case messageYjsUpdate:\n readUpdate(decoder, doc, transactionOrigin, errorHandler)\n break\n default:\n throw new Error('Unknown message type')\n }\n return messageType\n}\n"],"names":["encoding","Y","decoding"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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Yjs encoding protocols",

@@ -5,0 +5,0 @@ "type": "module",

@@ -35,3 +35,4 @@ # Yjs Protocols

```js
const awareness = new awarenessProtocol.Awareness()
const ydoc = new Y.Doc()
const awareness = new awarenessProtocol.Awareness(ydoc)
```

@@ -38,0 +39,0 @@

@@ -34,6 +34,6 @@ /**

export function readSyncStep1(decoder: decoding.Decoder, encoder: encoding.Encoder, doc: Y.Doc): void;
export function readSyncStep2(decoder: decoding.Decoder, doc: Y.Doc, transactionOrigin: any): void;
export function readSyncStep2(decoder: decoding.Decoder, doc: Y.Doc, transactionOrigin: any, errorHandler?: ((error: Error) => any) | undefined): void;
export function writeUpdate(encoder: encoding.Encoder, update: Uint8Array): void;
export function readUpdate(decoder: decoding.Decoder, doc: Y.Doc, transactionOrigin: any): void;
export function readSyncMessage(decoder: decoding.Decoder, encoder: encoding.Encoder, doc: Y.Doc, transactionOrigin: any): 0 | 2 | 1;
export function readUpdate(decoder: decoding.Decoder, doc: Y.Doc, transactionOrigin: any, errorHandler?: ((error: Error) => any) | undefined): void;
export function readSyncMessage(decoder: decoding.Decoder, encoder: encoding.Encoder, doc: Y.Doc, transactionOrigin: any, errorHandler?: ((error: Error) => any) | undefined): 0 | 2 | 1;
export type StateMap = Map<number, number>;

@@ -40,0 +40,0 @@ import * as encoding from 'lib0/encoding';

@@ -1,1 +0,1 @@

{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["sync.js"],"names":[],"mappings":"AAQA;;GAEG;AAEH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,oCAAoC;AACpC,oCAAoC;AACpC,iCAAiC;AAQ1B,wCAHI,SAAS,OAAO,OAChB,EAAE,GAAG,QAMf;AAOM,wCAJI,SAAS,OAAO,OAChB,EAAE,GAAG,qDAMf;AASM,uCAJI,SAAS,OAAO,WAChB,SAAS,OAAO,OAChB,EAAE,GAAG,QAGmD;AAS5D,uCAJI,SAAS,OAAO,OAChB,EAAE,GAAG,qBACL,GAAG,QASb;AAMM,qCAHI,SAAS,OAAO,UAChB,UAAU,QAKpB;AAhBM,oCAJI,SAAS,OAAO,OAChB,EAAE,GAAG,qBACL,GAAG,QASb;AA0BM,yCALI,SAAS,OAAO,WAChB,SAAS,OAAO,OAChB,EAAE,GAAG,qBACL,GAAG,aAkBb;uBAxHY,IAAI,MAAM,EAAE,MAAM,CAAC;0BALN,eAAe;mBAEtB,KAAK;0BADE,eAAe"}
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["sync.js"],"names":[],"mappings":"AAQA;;GAEG;AAEH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,oCAAoC;AACpC,oCAAoC;AACpC,iCAAiC;AAQ1B,wCAHI,SAAS,OAAO,OAChB,EAAE,GAAG,QAMf;AAOM,wCAJI,SAAS,OAAO,OAChB,EAAE,GAAG,qDAMf;AASM,uCAJI,SAAS,OAAO,WAChB,SAAS,OAAO,OAChB,EAAE,GAAG,QAGmD;AAU5D,uCALI,SAAS,OAAO,OAChB,EAAE,GAAG,qBACL,GAAG,0BACI,KAAK,KAAG,GAAG,qBAU5B;AAMM,qCAHI,SAAS,OAAO,UAChB,UAAU,QAKpB;AAjBM,oCALI,SAAS,OAAO,OAChB,EAAE,GAAG,qBACL,GAAG,0BACI,KAAK,KAAG,GAAG,qBAU5B;AA4BM,yCANI,SAAS,OAAO,WAChB,SAAS,OAAO,OAChB,EAAE,GAAG,qBACL,GAAG,0BACI,KAAK,KAAG,GAAG,0BAkB5B;uBA5HY,IAAI,MAAM,EAAE,MAAM,CAAC;0BALN,eAAe;mBAEtB,KAAK;0BADE,eAAe"}

@@ -80,7 +80,9 @@ /**

* @param {any} transactionOrigin
* @param {(error:Error)=>any} [errorHandler]
*/
export const readSyncStep2 = (decoder, doc, transactionOrigin) => {
export const readSyncStep2 = (decoder, doc, transactionOrigin, errorHandler) => {
try {
Y.applyUpdate(doc, decoding.readVarUint8Array(decoder), transactionOrigin)
} catch (error) {
if (errorHandler != null) errorHandler(/** @type {Error} */ (error))
// This catches errors that are thrown by event handlers

@@ -106,2 +108,3 @@ console.error('Caught error while handling a Yjs update', error)

* @param {any} transactionOrigin
* @param {(error:Error)=>any} [errorHandler]
*/

@@ -115,4 +118,5 @@ export const readUpdate = readSyncStep2

* @param {any} transactionOrigin
* @param {(error:Error)=>any} [errorHandler] Optional error handler that catches errors when reading Yjs messages.
*/
export const readSyncMessage = (decoder, encoder, doc, transactionOrigin) => {
export const readSyncMessage = (decoder, encoder, doc, transactionOrigin, errorHandler) => {
const messageType = decoding.readVarUint(decoder)

@@ -124,6 +128,6 @@ switch (messageType) {

case messageYjsSyncStep2:
readSyncStep2(decoder, doc, transactionOrigin)
readSyncStep2(decoder, doc, transactionOrigin, errorHandler)
break
case messageYjsUpdate:
readUpdate(decoder, doc, transactionOrigin)
readUpdate(decoder, doc, transactionOrigin, errorHandler)
break

@@ -130,0 +134,0 @@ default: