diff --git a/src/structs/AbstractStruct.js b/src/structs/AbstractStruct.js index fc335a73..889be3ab 100644 --- a/src/structs/AbstractStruct.js +++ b/src/structs/AbstractStruct.js @@ -1,6 +1,6 @@ import { - AbstractUpdateEncoder, ID, Transaction // eslint-disable-line + UpdateEncoderV1, UpdateEncoderV2, ID, Transaction // eslint-disable-line } from '../internals.js' import * as error from 'lib0/error.js' @@ -34,7 +34,7 @@ export class AbstractStruct { } /** - * @param {AbstractUpdateEncoder} encoder The encoder to write data to. + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder The encoder to write data to. * @param {number} offset * @param {number} encodingRef */ diff --git a/src/structs/ContentAny.js b/src/structs/ContentAny.js index f00128df..613144d8 100644 --- a/src/structs/ContentAny.js +++ b/src/structs/ContentAny.js @@ -1,5 +1,5 @@ import { - AbstractUpdateDecoder, AbstractUpdateEncoder, Transaction, Item, StructStore // eslint-disable-line + UpdateEncoderV1, UpdateEncoderV2, UpdateDecoderV1, UpdateDecoderV2, Transaction, Item, StructStore // eslint-disable-line } from '../internals.js' export class ContentAny { @@ -74,7 +74,7 @@ export class ContentAny { */ gc (store) {} /** - * @param {AbstractUpdateEncoder} encoder + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder * @param {number} offset */ write (encoder, offset) { @@ -95,7 +95,7 @@ export class ContentAny { } /** - * @param {AbstractUpdateDecoder} decoder + * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * @return {ContentAny} */ export const readContentAny = decoder => { diff --git a/src/structs/ContentBinary.js b/src/structs/ContentBinary.js index 15d92aa2..30e55fe5 100644 --- a/src/structs/ContentBinary.js +++ b/src/structs/ContentBinary.js @@ -1,5 +1,5 @@ import { - AbstractUpdateDecoder, AbstractUpdateEncoder, StructStore, Item, Transaction // eslint-disable-line + UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Item, Transaction // eslint-disable-line } from '../internals.js' import * as error from 'lib0/error.js' @@ -70,7 +70,7 @@ export class ContentBinary { */ gc (store) {} /** - * @param {AbstractUpdateEncoder} encoder + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder * @param {number} offset */ write (encoder, offset) { @@ -86,7 +86,7 @@ export class ContentBinary { } /** - * @param {AbstractUpdateDecoder} decoder + * @param {UpdateDecoderV1 | UpdateDecoderV2 } decoder * @return {ContentBinary} */ export const readContentBinary = decoder => new ContentBinary(decoder.readBuf()) diff --git a/src/structs/ContentDeleted.js b/src/structs/ContentDeleted.js index 7e00bebe..7225e1f6 100644 --- a/src/structs/ContentDeleted.js +++ b/src/structs/ContentDeleted.js @@ -1,7 +1,7 @@ import { addToDeleteSet, - AbstractUpdateDecoder, AbstractUpdateEncoder, StructStore, Item, Transaction // eslint-disable-line + UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Item, Transaction // eslint-disable-line } from '../internals.js' export class ContentDeleted { @@ -77,7 +77,7 @@ export class ContentDeleted { */ gc (store) {} /** - * @param {AbstractUpdateEncoder} encoder + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder * @param {number} offset */ write (encoder, offset) { @@ -95,7 +95,7 @@ export class ContentDeleted { /** * @private * - * @param {AbstractUpdateDecoder} decoder + * @param {UpdateDecoderV1 | UpdateDecoderV2 } decoder * @return {ContentDeleted} */ export const readContentDeleted = decoder => new ContentDeleted(decoder.readLen()) diff --git a/src/structs/ContentDoc.js b/src/structs/ContentDoc.js index 10101896..939734c1 100644 --- a/src/structs/ContentDoc.js +++ b/src/structs/ContentDoc.js @@ -1,6 +1,6 @@ import { - Doc, AbstractUpdateDecoder, AbstractUpdateEncoder, StructStore, Transaction, Item // eslint-disable-line + Doc, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Transaction, Item // eslint-disable-line } from '../internals.js' import * as error from 'lib0/error.js' @@ -110,7 +110,7 @@ export class ContentDoc { gc (store) { } /** - * @param {AbstractUpdateEncoder} encoder + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder * @param {number} offset */ write (encoder, offset) { @@ -129,7 +129,7 @@ export class ContentDoc { /** * @private * - * @param {AbstractUpdateDecoder} decoder + * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * @return {ContentDoc} */ export const readContentDoc = decoder => new ContentDoc(new Doc({ guid: decoder.readString(), ...decoder.readAny() })) diff --git a/src/structs/ContentEmbed.js b/src/structs/ContentEmbed.js index 66b922e3..27dcd3fa 100644 --- a/src/structs/ContentEmbed.js +++ b/src/structs/ContentEmbed.js @@ -1,6 +1,6 @@ import { - AbstractUpdateDecoder, AbstractUpdateEncoder, StructStore, Item, Transaction // eslint-disable-line + UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Item, Transaction // eslint-disable-line } from '../internals.js' import * as error from 'lib0/error.js' @@ -74,7 +74,7 @@ export class ContentEmbed { */ gc (store) {} /** - * @param {AbstractUpdateEncoder} encoder + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder * @param {number} offset */ write (encoder, offset) { @@ -92,7 +92,7 @@ export class ContentEmbed { /** * @private * - * @param {AbstractUpdateDecoder} decoder + * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * @return {ContentEmbed} */ export const readContentEmbed = decoder => new ContentEmbed(decoder.readJSON()) diff --git a/src/structs/ContentFormat.js b/src/structs/ContentFormat.js index 43716408..fb2610d2 100644 --- a/src/structs/ContentFormat.js +++ b/src/structs/ContentFormat.js @@ -1,6 +1,6 @@ import { - AbstractType, AbstractUpdateDecoder, AbstractUpdateEncoder, Item, StructStore, Transaction // eslint-disable-line + AbstractType, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Item, StructStore, Transaction // eslint-disable-line } from '../internals.js' import * as error from 'lib0/error.js' @@ -80,7 +80,7 @@ export class ContentFormat { */ gc (store) {} /** - * @param {AbstractUpdateEncoder} encoder + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder * @param {number} offset */ write (encoder, offset) { @@ -97,7 +97,7 @@ export class ContentFormat { } /** - * @param {AbstractUpdateDecoder} decoder + * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * @return {ContentFormat} */ export const readContentFormat = decoder => new ContentFormat(decoder.readString(), decoder.readJSON()) diff --git a/src/structs/ContentJSON.js b/src/structs/ContentJSON.js index baf4c46c..29b2f754 100644 --- a/src/structs/ContentJSON.js +++ b/src/structs/ContentJSON.js @@ -1,5 +1,5 @@ import { - AbstractUpdateDecoder, AbstractUpdateEncoder, Transaction, Item, StructStore // eslint-disable-line + UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Transaction, Item, StructStore // eslint-disable-line } from '../internals.js' /** @@ -77,7 +77,7 @@ export class ContentJSON { */ gc (store) {} /** - * @param {AbstractUpdateEncoder} encoder + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder * @param {number} offset */ write (encoder, offset) { @@ -100,7 +100,7 @@ export class ContentJSON { /** * @private * - * @param {AbstractUpdateDecoder} decoder + * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * @return {ContentJSON} */ export const readContentJSON = decoder => { diff --git a/src/structs/ContentString.js b/src/structs/ContentString.js index 10151e67..fa023ef9 100644 --- a/src/structs/ContentString.js +++ b/src/structs/ContentString.js @@ -1,5 +1,5 @@ import { - AbstractUpdateDecoder, AbstractUpdateEncoder, Transaction, Item, StructStore // eslint-disable-line + UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Transaction, Item, StructStore // eslint-disable-line } from '../internals.js' /** @@ -88,7 +88,7 @@ export class ContentString { */ gc (store) {} /** - * @param {AbstractUpdateEncoder} encoder + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder * @param {number} offset */ write (encoder, offset) { @@ -106,7 +106,7 @@ export class ContentString { /** * @private * - * @param {AbstractUpdateDecoder} decoder + * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * @return {ContentString} */ export const readContentString = decoder => new ContentString(decoder.readString()) diff --git a/src/structs/ContentType.js b/src/structs/ContentType.js index 7fd45570..3be38298 100644 --- a/src/structs/ContentType.js +++ b/src/structs/ContentType.js @@ -7,13 +7,13 @@ import { readYXmlFragment, readYXmlHook, readYXmlText, - AbstractUpdateDecoder, AbstractUpdateEncoder, StructStore, Transaction, Item, YEvent, AbstractType // eslint-disable-line + UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Transaction, Item, YEvent, AbstractType // eslint-disable-line } from '../internals.js' import * as error from 'lib0/error.js' /** - * @type {Array>} + * @type {Array>} * @private */ export const typeRefs = [ @@ -148,7 +148,7 @@ export class ContentType { } /** - * @param {AbstractUpdateEncoder} encoder + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder * @param {number} offset */ write (encoder, offset) { @@ -166,7 +166,7 @@ export class ContentType { /** * @private * - * @param {AbstractUpdateDecoder} decoder + * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * @return {ContentType} */ export const readContentType = decoder => new ContentType(typeRefs[decoder.readTypeRef()](decoder)) diff --git a/src/structs/GC.js b/src/structs/GC.js index 110f68b6..42d71f73 100644 --- a/src/structs/GC.js +++ b/src/structs/GC.js @@ -2,7 +2,7 @@ import { AbstractStruct, addStruct, - AbstractUpdateEncoder, StructStore, Transaction, ID // eslint-disable-line + UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Transaction, ID // eslint-disable-line } from '../internals.js' export const structGCRefNumber = 0 @@ -42,7 +42,7 @@ export class GC extends AbstractStruct { } /** - * @param {AbstractUpdateEncoder} encoder + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder * @param {number} offset */ write (encoder, offset) { diff --git a/src/structs/Item.js b/src/structs/Item.js index adc64023..95ef3f6a 100644 --- a/src/structs/Item.js +++ b/src/structs/Item.js @@ -22,7 +22,7 @@ import { readContentFormat, readContentType, addChangedTypeToTransaction, - AbstractUpdateDecoder, AbstractUpdateEncoder, ContentType, ContentDeleted, StructStore, ID, AbstractType, Transaction // eslint-disable-line + UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, ContentType, ContentDeleted, StructStore, ID, AbstractType, Transaction // eslint-disable-line } from '../internals.js' import * as error from 'lib0/error.js' @@ -620,7 +620,7 @@ export class Item extends AbstractStruct { * * This is called when this Item is sent to a remote peer. * - * @param {AbstractUpdateEncoder} encoder The encoder to write data to. + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder The encoder to write data to. * @param {number} offset */ write (encoder, offset) { @@ -670,7 +670,7 @@ export class Item extends AbstractStruct { } /** - * @param {AbstractUpdateDecoder} decoder + * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * @param {number} info */ export const readItemContent = (decoder, info) => contentRefs[info & binary.BITS5](decoder) @@ -678,7 +678,7 @@ export const readItemContent = (decoder, info) => contentRefs[info & binary.BITS /** * A lookup map for reading Item content. * - * @type {Array} + * @type {Array} */ export const contentRefs = [ () => { error.unexpectedCase() }, // GC is not ItemContent @@ -771,7 +771,7 @@ export class AbstractContent { } /** - * @param {AbstractUpdateEncoder} encoder + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder * @param {number} offset */ write (encoder, offset) { diff --git a/src/structs/Skip.js b/src/structs/Skip.js index 5b0f7b35..eaec5c06 100644 --- a/src/structs/Skip.js +++ b/src/structs/Skip.js @@ -1,7 +1,7 @@ import { AbstractStruct, - AbstractUpdateEncoder, StructStore, Transaction, ID // eslint-disable-line + UpdateEncoderV1, UpdateEncoderV2, StructStore, Transaction, ID // eslint-disable-line } from '../internals.js' import * as error from 'lib0/error.js' @@ -39,7 +39,7 @@ export class Skip extends AbstractStruct { } /** - * @param {AbstractUpdateEncoder} encoder + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder * @param {number} offset */ write (encoder, offset) { diff --git a/src/types/AbstractType.js b/src/types/AbstractType.js index 3b6aa581..76a88a33 100644 --- a/src/types/AbstractType.js +++ b/src/types/AbstractType.js @@ -11,7 +11,7 @@ import { ContentAny, ContentBinary, getItemCleanStart, - ContentDoc, YText, YArray, AbstractUpdateEncoder, Doc, Snapshot, Transaction, EventHandler, YEvent, Item, // eslint-disable-line + ContentDoc, YText, YArray, UpdateEncoderV1, UpdateEncoderV2, Doc, Snapshot, Transaction, EventHandler, YEvent, Item, // eslint-disable-line } from '../internals.js' import * as map from 'lib0/map.js' @@ -324,7 +324,7 @@ export class AbstractType { } /** - * @param {AbstractUpdateEncoder} encoder + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder */ _write (encoder) { } diff --git a/src/types/YArray.js b/src/types/YArray.js index cadb16b5..cefc908b 100644 --- a/src/types/YArray.js +++ b/src/types/YArray.js @@ -15,7 +15,7 @@ import { YArrayRefID, callTypeObservers, transact, - ArraySearchMarker, AbstractUpdateDecoder, AbstractUpdateEncoder, Doc, Transaction, Item // eslint-disable-line + ArraySearchMarker, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Transaction, Item // eslint-disable-line } from '../internals.js' import { typeListSlice } from './AbstractType.js' @@ -241,7 +241,7 @@ export class YArray extends AbstractType { } /** - * @param {AbstractUpdateEncoder} encoder + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder */ _write (encoder) { encoder.writeTypeRef(YArrayRefID) @@ -249,7 +249,7 @@ export class YArray extends AbstractType { } /** - * @param {AbstractUpdateDecoder} decoder + * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * * @private * @function diff --git a/src/types/YMap.js b/src/types/YMap.js index efaa16f5..2cb0342a 100644 --- a/src/types/YMap.js +++ b/src/types/YMap.js @@ -14,7 +14,7 @@ import { YMapRefID, callTypeObservers, transact, - AbstractUpdateDecoder, AbstractUpdateEncoder, Doc, Transaction, Item // eslint-disable-line + UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Transaction, Item // eslint-disable-line } from '../internals.js' import * as iterator from 'lib0/iterator.js' @@ -238,7 +238,7 @@ export class YMap extends AbstractType { } /** - * @param {AbstractUpdateEncoder} encoder + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder */ _write (encoder) { encoder.writeTypeRef(YMapRefID) @@ -246,7 +246,7 @@ export class YMap extends AbstractType { } /** - * @param {AbstractUpdateDecoder} decoder + * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * * @private * @function diff --git a/src/types/YText.js b/src/types/YText.js index a12d0747..8457ea4d 100644 --- a/src/types/YText.js +++ b/src/types/YText.js @@ -26,7 +26,7 @@ import { typeMapGet, typeMapGetAll, updateMarkerChanges, - ArraySearchMarker, AbstractUpdateDecoder, AbstractUpdateEncoder, ID, Doc, Item, Snapshot, Transaction // eslint-disable-line + ArraySearchMarker, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, ID, Doc, Item, Snapshot, Transaction // eslint-disable-line } from '../internals.js' import * as object from 'lib0/object.js' @@ -1203,7 +1203,7 @@ export class YText extends AbstractType { } /** - * @param {AbstractUpdateEncoder} encoder + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder */ _write (encoder) { encoder.writeTypeRef(YTextRefID) @@ -1211,7 +1211,7 @@ export class YText extends AbstractType { } /** - * @param {AbstractUpdateDecoder} decoder + * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * @return {YText} * * @private diff --git a/src/types/YXmlElement.js b/src/types/YXmlElement.js index 3b64fa51..b3ce6ef9 100644 --- a/src/types/YXmlElement.js +++ b/src/types/YXmlElement.js @@ -8,7 +8,7 @@ import { typeMapGetAll, typeListForEach, YXmlElementRefID, - YXmlText, ContentType, AbstractType, AbstractUpdateDecoder, AbstractUpdateEncoder, Snapshot, Doc, Item // eslint-disable-line + YXmlText, ContentType, AbstractType, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Snapshot, Doc, Item // eslint-disable-line } from '../internals.js' /** @@ -208,7 +208,7 @@ export class YXmlElement extends YXmlFragment { * * This is called when this Item is sent to a remote peer. * - * @param {AbstractUpdateEncoder} encoder The encoder to write data to. + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder The encoder to write data to. */ _write (encoder) { encoder.writeTypeRef(YXmlElementRefID) @@ -217,7 +217,7 @@ export class YXmlElement extends YXmlFragment { } /** - * @param {AbstractUpdateDecoder} decoder + * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * @return {YXmlElement} * * @function diff --git a/src/types/YXmlFragment.js b/src/types/YXmlFragment.js index 21c6a3a0..1fd060b0 100644 --- a/src/types/YXmlFragment.js +++ b/src/types/YXmlFragment.js @@ -17,7 +17,7 @@ import { transact, typeListGet, typeListSlice, - AbstractUpdateDecoder, AbstractUpdateEncoder, Doc, ContentType, Transaction, Item, YXmlText, YXmlHook, Snapshot // eslint-disable-line + UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, ContentType, Transaction, Item, YXmlText, YXmlHook, Snapshot // eslint-disable-line } from '../internals.js' import * as error from 'lib0/error.js' @@ -410,7 +410,7 @@ export class YXmlFragment extends AbstractType { * * This is called when this Item is sent to a remote peer. * - * @param {AbstractUpdateEncoder} encoder The encoder to write data to. + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder The encoder to write data to. */ _write (encoder) { encoder.writeTypeRef(YXmlFragmentRefID) @@ -418,7 +418,7 @@ export class YXmlFragment extends AbstractType { } /** - * @param {AbstractUpdateDecoder} decoder + * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * @return {YXmlFragment} * * @private diff --git a/src/types/YXmlHook.js b/src/types/YXmlHook.js index e28f70a3..be8c759b 100644 --- a/src/types/YXmlHook.js +++ b/src/types/YXmlHook.js @@ -2,7 +2,7 @@ import { YMap, YXmlHookRefID, - AbstractUpdateDecoder, AbstractUpdateEncoder // eslint-disable-line + UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2 // eslint-disable-line } from '../internals.js' /** @@ -76,7 +76,7 @@ export class YXmlHook extends YMap { * * This is called when this Item is sent to a remote peer. * - * @param {AbstractUpdateEncoder} encoder The encoder to write data to. + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder The encoder to write data to. */ _write (encoder) { encoder.writeTypeRef(YXmlHookRefID) @@ -85,7 +85,7 @@ export class YXmlHook extends YMap { } /** - * @param {AbstractUpdateDecoder} decoder + * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * @return {YXmlHook} * * @private diff --git a/src/types/YXmlText.js b/src/types/YXmlText.js index dd8d892d..470ce70f 100644 --- a/src/types/YXmlText.js +++ b/src/types/YXmlText.js @@ -2,7 +2,7 @@ import { YText, YXmlTextRefID, - ContentType, YXmlElement, AbstractUpdateDecoder, AbstractUpdateEncoder // eslint-disable-line + ContentType, YXmlElement, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, // eslint-disable-line } from '../internals.js' /** @@ -104,7 +104,7 @@ export class YXmlText extends YText { } /** - * @param {AbstractUpdateEncoder} encoder + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder */ _write (encoder) { encoder.writeTypeRef(YXmlTextRefID) @@ -112,7 +112,7 @@ export class YXmlText extends YText { } /** - * @param {AbstractUpdateDecoder} decoder + * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * @return {YXmlText} * * @private diff --git a/src/utils/Snapshot.js b/src/utils/Snapshot.js index 102a9c35..50c64772 100644 --- a/src/utils/Snapshot.js +++ b/src/utils/Snapshot.js @@ -15,14 +15,13 @@ import { findIndexSS, UpdateEncoderV2, applyUpdateV2, - AbstractDSDecoder, DSEncoderV2, DSDecoderV1, DSDecoderV2, Transaction, Doc, DeleteSet, Item // eslint-disable-line + DSEncoderV1, DSEncoderV2, DSDecoderV1, DSDecoderV2, Transaction, Doc, DeleteSet, Item // eslint-disable-line } from '../internals.js' import * as map from 'lib0/map.js' import * as set from 'lib0/set.js' import * as decoding from 'lib0/decoding.js' import * as encoding from 'lib0/encoding.js' -import { DSEncoderV1 } from './UpdateEncoder.js' export class Snapshot { /** @@ -95,7 +94,7 @@ export const encodeSnapshot = snapshot => encodeSnapshotV2(snapshot, new DSEncod /** * @param {Uint8Array} buf - * @param {AbstractDSDecoder} [decoder] + * @param {DSDecoderV1 | DSDecoderV2} [decoder] * @return {Snapshot} */ export const decodeSnapshotV2 = (buf, decoder = new DSDecoderV2(decoding.createDecoder(buf))) => { diff --git a/src/utils/Transaction.js b/src/utils/Transaction.js index 929d061b..1273d26e 100644 --- a/src/utils/Transaction.js +++ b/src/utils/Transaction.js @@ -11,7 +11,7 @@ import { Item, generateNewClientId, createID, - AbstractUpdateEncoder, GC, StructStore, UpdateEncoderV2, AbstractType, AbstractStruct, YEvent, Doc // eslint-disable-line + UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, GC, StructStore, AbstractType, AbstractStruct, YEvent, Doc // eslint-disable-line } from '../internals.js' import * as map from 'lib0/map.js' @@ -19,7 +19,6 @@ import * as math from 'lib0/math.js' import * as set from 'lib0/set.js' import * as logging from 'lib0/logging.js' import { callAll } from 'lib0/function.js' -import { UpdateEncoderV1 } from './UpdateEncoder.js' /** * A transaction is created for every change on the Yjs model. It is possible @@ -119,7 +118,7 @@ export class Transaction { } /** - * @param {AbstractUpdateEncoder} encoder + * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder * @param {Transaction} transaction * @return {boolean} Whether data was written. */ diff --git a/src/utils/UpdateDecoder.js b/src/utils/UpdateDecoder.js index 9f50c7a7..74568650 100644 --- a/src/utils/UpdateDecoder.js +++ b/src/utils/UpdateDecoder.js @@ -1,132 +1,9 @@ import * as buffer from 'lib0/buffer.js' -import * as error from 'lib0/error.js' import * as decoding from 'lib0/decoding.js' import { ID, createID } from '../internals.js' -export class AbstractDSDecoder { - /** - * @param {decoding.Decoder} decoder - */ - constructor (decoder) { - /** - * @type {decoding.Decoder} - */ - this.restDecoder = decoder - error.methodUnimplemented() - } - - resetDsCurVal () { } - - /** - * @return {number} - */ - readDsClock () { - error.methodUnimplemented() - } - - /** - * @return {number} - */ - readDsLen () { - error.methodUnimplemented() - } -} - -export class AbstractUpdateDecoder extends AbstractDSDecoder { - /** - * @return {ID} - */ - readLeftID () { - error.methodUnimplemented() - } - - /** - * @return {ID} - */ - readRightID () { - error.methodUnimplemented() - } - - /** - * Read the next client id. - * Use this in favor of readID whenever possible to reduce the number of objects created. - * - * @return {number} - */ - readClient () { - error.methodUnimplemented() - } - - /** - * @return {number} info An unsigned 8-bit integer - */ - readInfo () { - error.methodUnimplemented() - } - - /** - * @return {string} - */ - readString () { - error.methodUnimplemented() - } - - /** - * @return {boolean} isKey - */ - readParentInfo () { - error.methodUnimplemented() - } - - /** - * @return {number} info An unsigned 8-bit integer - */ - readTypeRef () { - error.methodUnimplemented() - } - - /** - * Write len of a struct - well suited for Opt RLE encoder. - * - * @return {number} len - */ - readLen () { - error.methodUnimplemented() - } - - /** - * @return {any} - */ - readAny () { - error.methodUnimplemented() - } - - /** - * @return {Uint8Array} - */ - readBuf () { - error.methodUnimplemented() - } - - /** - * Legacy implementation uses JSON parse. We use any-decoding in v2. - * - * @return {any} - */ - readJSON () { - error.methodUnimplemented() - } - - /** - * @return {string} - */ - readKey () { - error.methodUnimplemented() - } -} - export class DSDecoderV1 { /** * @param {decoding.Decoder} decoder @@ -250,6 +127,9 @@ export class DSDecoderV2 { * @param {decoding.Decoder} decoder */ constructor (decoder) { + /** + * @private + */ this.dsCurrVal = 0 this.restDecoder = decoder } @@ -258,11 +138,17 @@ export class DSDecoderV2 { this.dsCurrVal = 0 } + /** + * @return {number} + */ readDsClock () { this.dsCurrVal += decoding.readVarUint(this.restDecoder) return this.dsCurrVal } + /** + * @return {number} + */ readDsLen () { const diff = decoding.readVarUint(this.restDecoder) + 1 this.dsCurrVal += diff diff --git a/src/utils/encoding.js b/src/utils/encoding.js index 7a29e7d4..1318cd3d 100644 --- a/src/utils/encoding.js +++ b/src/utils/encoding.js @@ -33,7 +33,7 @@ import { DSEncoderV2, DSDecoderV1, DSEncoderV1, - AbstractDSDecoder, AbstractUpdateDecoder, Doc, Transaction, GC, Item, StructStore, ID // eslint-disable-line + Doc, Transaction, GC, Item, StructStore, ID // eslint-disable-line } from '../internals.js' import * as encoding from 'lib0/encoding.js' @@ -97,7 +97,7 @@ export const writeClientsStructs = (encoder, store, _sm) => { } /** - * @param {AbstractUpdateDecoder} decoder The decoder object to read data from. + * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder The decoder object to read data from. * @param {Map>} clientRefs * @param {Doc} doc * @return {Map>} @@ -370,7 +370,7 @@ const cleanupPendingStructs = pendingClientsStructRefs => { * * This is called when data is received from a remote peer. * - * @param {AbstractUpdateDecoder} decoder The decoder object to read data from. + * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder The decoder object to read data from. * @param {Transaction} transaction * @param {StructStore} store * @@ -405,7 +405,7 @@ export const readStructs = (decoder, transaction, store) => { * @param {decoding.Decoder} decoder * @param {Doc} ydoc * @param {any} [transactionOrigin] This will be stored on `transaction.origin` and `.on('update', (update, origin))` - * @param {AbstractUpdateDecoder} [structDecoder] + * @param {UpdateDecoderV1 | UpdateDecoderV2} [structDecoder] * * @function */ @@ -509,7 +509,7 @@ export const encodeStateAsUpdate = (doc, encodedTargetStateVector) => encodeStat /** * Read state vector from Decoder and return as Map * - * @param {AbstractDSDecoder} decoder + * @param {DSDecoderV1 | DSDecoderV2} decoder * @return {Map} Maps `client` to the number next expected `clock` from that client. * * @function diff --git a/src/utils/updates.js b/src/utils/updates.js index 9794366f..dfdd0bf0 100644 --- a/src/utils/updates.js +++ b/src/utils/updates.js @@ -12,11 +12,11 @@ import { mergeDeleteSets, DSEncoderV1, DSEncoderV2, - Item, GC, AbstractUpdateDecoder, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2 // eslint-disable-line + Item, GC, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2 // eslint-disable-line } from '../internals.js' /** - * @param {AbstractUpdateDecoder} decoder + * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder */ function * lazyStructReaderGenerator (decoder) { const numOfStateUpdates = decoding.readVarUint(decoder.restDecoder) @@ -61,7 +61,7 @@ function * lazyStructReaderGenerator (decoder) { export class LazyStructReader { /** - * @param {AbstractUpdateDecoder} decoder + * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder */ constructor (decoder) { this.gen = lazyStructReaderGenerator(decoder) diff --git a/tests/updates.tests.js b/tests/updates.tests.js index dfa08420..20960d09 100644 --- a/tests/updates.tests.js +++ b/tests/updates.tests.js @@ -2,23 +2,34 @@ import * as t from 'lib0/testing.js' import { init, compare } from './testHelper.js' // eslint-disable-line import * as Y from '../src/index.js' -const useV2 = true +const encV1 = { + mergeUpdates: Y.mergeUpdates, + encodeStateAsUpdate: Y.encodeStateAsUpdate, + applyUpdate: Y.applyUpdate, + logUpdate: Y.logUpdate, + updateEventName: 'update' +} -const encodeStateAsUpdate = useV2 ? Y.encodeStateAsUpdateV2 : Y.encodeStateAsUpdate -const mergeUpdates = useV2 ? Y.mergeUpdatesV2 : Y.mergeUpdates -const applyUpdate = useV2 ? Y.applyUpdateV2 : Y.applyUpdate -const logUpdate = useV2 ? Y.logUpdateV2 : Y.logUpdate -const updateEventName = useV2 ? 'updateV2' : 'update' +const encV2 = { + mergeUpdates: Y.mergeUpdatesV2, + encodeStateAsUpdate: Y.encodeStateAsUpdateV2, + applyUpdate: Y.applyUpdateV2, + logUpdate: Y.logUpdateV2, + updateEventName: 'updateV2' +} + +const encoders = [encV1, encV2] /** * @param {Array} users + * @param {encV1 | encV2} enc */ -const fromUpdates = users => { +const fromUpdates = (users, enc) => { const updates = users.map(user => - encodeStateAsUpdate(user) + enc.encodeStateAsUpdate(user) ) const ydoc = new Y.Doc() - applyUpdate(ydoc, mergeUpdates(updates)) + enc.applyUpdate(ydoc, enc.mergeUpdates(updates)) return ydoc } @@ -31,53 +42,56 @@ export const testMergeUpdates = tc => { array0.insert(0, [1]) array1.insert(0, [2]) - const merged = fromUpdates(users) compare(users) - t.compareArrays(array0.toArray(), merged.getArray('array').toArray()) + encoders.forEach(enc => { + const merged = fromUpdates(users, enc) + t.compareArrays(array0.toArray(), merged.getArray('array').toArray()) + }) } /** * @param {Y.Doc} ydoc * @param {Array} updates - expecting at least 4 updates + * @param {encV1 | encV2} enc */ -const checkUpdateCases = (ydoc, updates) => { +const checkUpdateCases = (ydoc, updates, enc) => { const cases = [] // Case 1: Simple case, simply merge everything - cases.push(mergeUpdates(updates)) + cases.push(enc.mergeUpdates(updates)) // Case 2: Overlapping updates - cases.push(mergeUpdates([ - mergeUpdates(updates.slice(2)), - mergeUpdates(updates.slice(0, 2)) + cases.push(enc.mergeUpdates([ + enc.mergeUpdates(updates.slice(2)), + enc.mergeUpdates(updates.slice(0, 2)) ])) // Case 3: Overlapping updates - cases.push(mergeUpdates([ - mergeUpdates(updates.slice(2)), - mergeUpdates(updates.slice(1, 3)), + cases.push(enc.mergeUpdates([ + enc.mergeUpdates(updates.slice(2)), + enc.mergeUpdates(updates.slice(1, 3)), updates[0] ])) // Case 4: Separated updates (containing skips) - cases.push(mergeUpdates([ - mergeUpdates([updates[0], updates[2]]), - mergeUpdates([updates[1], updates[3]]), - mergeUpdates(updates.slice(4)) + cases.push(enc.mergeUpdates([ + enc.mergeUpdates([updates[0], updates[2]]), + enc.mergeUpdates([updates[1], updates[3]]), + enc.mergeUpdates(updates.slice(4)) ])) // Case 5: overlapping with many duplicates - cases.push(mergeUpdates(cases)) + cases.push(enc.mergeUpdates(cases)) - const targetState = encodeStateAsUpdate(ydoc) + const targetState = enc.encodeStateAsUpdate(ydoc) t.info('Target State: ') - logUpdate(targetState) + enc.logUpdate(targetState) cases.forEach((updates, i) => { t.info('State Case $' + i + ':') - logUpdate(updates) + enc.logUpdate(updates) const merged = new Y.Doc() - applyUpdate(merged, updates) + enc.applyUpdate(merged, updates) t.compareArrays(merged.getArray().toArray(), ydoc.getArray().toArray()) }) } @@ -86,34 +100,40 @@ const checkUpdateCases = (ydoc, updates) => { * @param {t.TestCase} tc */ export const testMergeUpdates1 = tc => { - const ydoc = new Y.Doc({ gc: false }) - const updates = /** @type {Array} */ ([]) - ydoc.on(updateEventName, update => { updates.push(update) }) + encoders.forEach((enc, i) => { + t.info(`Using V${i + 1} encoder.`) + const ydoc = new Y.Doc({ gc: false }) + const updates = /** @type {Array} */ ([]) + ydoc.on(enc.updateEventName, update => { updates.push(update) }) - const array = ydoc.getArray() - array.insert(0, [1]) - array.insert(0, [2]) - array.insert(0, [3]) - array.insert(0, [4]) + const array = ydoc.getArray() + array.insert(0, [1]) + array.insert(0, [2]) + array.insert(0, [3]) + array.insert(0, [4]) - checkUpdateCases(ydoc, updates) + checkUpdateCases(ydoc, updates, enc) + }) } /** * @param {t.TestCase} tc */ export const testMergeUpdates2 = tc => { - const ydoc = new Y.Doc({ gc: false }) - const updates = /** @type {Array} */ ([]) - ydoc.on(updateEventName, update => { updates.push(update) }) + encoders.forEach((enc, i) => { + t.info(`Using V${i + 1} encoder.`) + const ydoc = new Y.Doc({ gc: false }) + const updates = /** @type {Array} */ ([]) + ydoc.on(enc.updateEventName, update => { updates.push(update) }) - const array = ydoc.getArray() - array.insert(0, [1, 2]) - array.delete(1, 1) - array.insert(0, [3, 4]) - array.delete(1, 2) + const array = ydoc.getArray() + array.insert(0, [1, 2]) + array.delete(1, 1) + array.insert(0, [3, 4]) + array.delete(1, 2) - checkUpdateCases(ydoc, updates) + checkUpdateCases(ydoc, updates, enc) + }) } /**