fix compiling issues
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import utf8 from 'utf-8'
|
||||
import '../../node_modules/utf8/utf8.js'
|
||||
|
||||
export default class BinaryDecoder {
|
||||
constructor (buffer) {
|
||||
@@ -11,25 +11,36 @@ export default class BinaryDecoder {
|
||||
}
|
||||
this.pos = 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone this decoder instance
|
||||
* Optionally set a new position parameter
|
||||
*/
|
||||
clone (newPos = this.pos) {
|
||||
let decoder = new BinaryDecoder(this.uint8arr)
|
||||
decoder.pos = newPos
|
||||
return decoder
|
||||
}
|
||||
|
||||
/**
|
||||
* Number of bytes
|
||||
*/
|
||||
get length () {
|
||||
return this.uint8arr.length
|
||||
}
|
||||
|
||||
/**
|
||||
* Skip one byte, jump to the next position
|
||||
*/
|
||||
skip8 () {
|
||||
this.pos++
|
||||
}
|
||||
|
||||
/**
|
||||
* Read one byte as unsigned integer
|
||||
*/
|
||||
readUint8 () {
|
||||
return this.uint8arr[this.pos++]
|
||||
}
|
||||
|
||||
/**
|
||||
* Read 4 bytes as unsigned integer
|
||||
*/
|
||||
readUint32 () {
|
||||
let uint =
|
||||
this.uint8arr[this.pos] +
|
||||
@@ -39,11 +50,20 @@ export default class BinaryDecoder {
|
||||
this.pos += 4
|
||||
return uint
|
||||
}
|
||||
|
||||
/**
|
||||
* Look ahead without incrementing position
|
||||
* to the next byte and read it as unsigned integer
|
||||
*/
|
||||
peekUint8 () {
|
||||
return this.uint8arr[this.pos]
|
||||
}
|
||||
|
||||
/**
|
||||
* Read unsigned integer (32bit) with variable length
|
||||
* 1/8th of the storage is used as encoding overhead
|
||||
* - numbers < 2^7 is stored in one byte
|
||||
* - numbers < 2^14 is stored in two bytes
|
||||
* ..
|
||||
*/
|
||||
readVarUint () {
|
||||
let num = 0
|
||||
let len = 0
|
||||
@@ -59,7 +79,10 @@ export default class BinaryDecoder {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read string of variable length
|
||||
* - varUint is used to store the length of the string
|
||||
*/
|
||||
readVarString () {
|
||||
let len = this.readVarUint()
|
||||
let bytes = new Array(len)
|
||||
@@ -68,20 +91,26 @@ export default class BinaryDecoder {
|
||||
}
|
||||
return utf8.getStringFromBytes(bytes)
|
||||
}
|
||||
|
||||
/**
|
||||
* Look ahead and read varString without incrementing position
|
||||
*/
|
||||
peekVarString () {
|
||||
let pos = this.pos
|
||||
let s = this.readVarString()
|
||||
this.pos = pos
|
||||
return s
|
||||
}
|
||||
|
||||
readOpID () {
|
||||
/**
|
||||
* Read ID
|
||||
* - If first varUint read is 0xFFFFFF a RootID is returned
|
||||
* - Otherwise an ID is returned
|
||||
*/
|
||||
readID () {
|
||||
let user = this.readVarUint()
|
||||
if (user !== 0xFFFFFF) {
|
||||
return [user, this.readVarUint()]
|
||||
} else {
|
||||
return [user, this.readVarString()]
|
||||
if (user === 0xFFFFFF) {
|
||||
// read property name and type id
|
||||
return new RootID(this.readVarString(), this.readVarUint())
|
||||
}
|
||||
return new ID(user, this.readVarUint())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import utf8 from 'utf-8'
|
||||
import '../../node_modules/utf8/utf8.js'
|
||||
|
||||
const bits7 = 0b1111111
|
||||
const bits8 = 0b11111111
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { BinaryEncoder, BinaryDecoder } from './Encoding.js'
|
||||
import BinaryEncoder from './Binary/Encoder.js'
|
||||
import BinaryDecoder from './Binary/Decoder.js'
|
||||
|
||||
import { sendSyncStep1, readSyncStep1 } from './MessageHandler/syncStep1'
|
||||
import { readSyncStep2 } from './MessageHandler/syncStep2'
|
||||
import { sendSyncStep1, readSyncStep1 } from './MessageHandler/syncStep1.js'
|
||||
import { readSyncStep2 } from './MessageHandler/syncStep2.js'
|
||||
import { readUpdate } from './MessageHandler/update.js'
|
||||
|
||||
import debug from 'debug'
|
||||
import { debug } from './Y.js'
|
||||
|
||||
export default class AbstractConnector {
|
||||
constructor (y, opts) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { getStruct } from '../Util/StructReferences'
|
||||
import BinaryDecoder from '../Util/Binary/Decoder'
|
||||
import { getStruct } from '../Util/StructReferences.js'
|
||||
import BinaryDecoder from '../Binary/Decoder.js'
|
||||
|
||||
class MissingEntry {
|
||||
constructor (decoder, missing, struct) {
|
||||
@@ -39,7 +39,7 @@ function _integrateRemoteStructHelper (y, struct) {
|
||||
}
|
||||
}
|
||||
|
||||
export default function integrateRemoteStructs (decoder, encoder, y) {
|
||||
export function integrateRemoteStructs (decoder, encoder, y) {
|
||||
while (decoder.length !== decoder.pos) {
|
||||
let decoderPos = decoder.pos
|
||||
let reference = decoder.readVarUint()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import BinaryDecoder from '../Utily/Binary/Decoder'
|
||||
import { stringifyUpdate } from './update'
|
||||
import { stringifySyncStep1 } from './syncStep1'
|
||||
import { stringifySyncStep2 } from './syncStep2'
|
||||
import BinaryDecoder from '../Binary/Decoder.js'
|
||||
import { stringifyUpdate } from './update.js'
|
||||
import { stringifySyncStep1 } from './syncStep1.js'
|
||||
import { stringifySyncStep2 } from './syncStep2.js'
|
||||
|
||||
export function messageToString (buffer) {
|
||||
let decoder = new BinaryDecoder(buffer)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import BinaryEncoder from './Util/Binary/Encoder.js'
|
||||
import BinaryEncoder from '../Binary/Encoder.js'
|
||||
|
||||
export function stringifySyncStep1 (decoder, strBuilder) {
|
||||
let auth = decoder.readVarString()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import integrateRemoteStructs from './integrateRemoteStructs'
|
||||
import { integrateRemoteStructs } from './integrateRemoteStructs.js'
|
||||
import { stringifyUpdate } from './update.js'
|
||||
import ID from '../Util/ID'
|
||||
import ID from '../Util/ID.js'
|
||||
|
||||
export function stringifySyncStep2 (decoder, strBuilder) {
|
||||
strBuilder.push(' - auth: ' + decoder.readVarString() + '\n')
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
|
||||
import { getStruct } from '../Util/StructReferences'
|
||||
import { getStruct } from '../Util/StructReferences.js'
|
||||
|
||||
export function stringifyUpdate (decoder, strBuilder) {
|
||||
while (decoder.length !== decoder.pos) {
|
||||
@@ -16,4 +16,4 @@ export function stringifyUpdate (decoder, strBuilder) {
|
||||
}
|
||||
}
|
||||
|
||||
export { integrateRemoteStructs as readUpdate } from './integrateRemoteStructs'
|
||||
export { integrateRemoteStructs as readUpdate } from './integrateRemoteStructs.js'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BinaryEncoder } from './Encoding.js'
|
||||
import BinaryEncoder from './Binary/Encoder.js'
|
||||
|
||||
export default function extendPersistence (Y) {
|
||||
class AbstractPersistence {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Tree from '../Util/Tree'
|
||||
import ID from '../Util/ID'
|
||||
import Tree from '../Util/Tree.js'
|
||||
import ID from '../Util/ID.js'
|
||||
|
||||
class DSNode {
|
||||
constructor (id, len, gc) {
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import Tree from '../Util/Tree'
|
||||
import RootID from '../Util/ID'
|
||||
import { getStruct } from '../Util/structReferences'
|
||||
import Tree from '../Util/Tree.js'
|
||||
import RootID from '../Util/ID.js'
|
||||
import { getStruct } from '../Util/structReferences.js'
|
||||
|
||||
export default class OperationStore extends Tree {
|
||||
constructor () {
|
||||
|
||||
}
|
||||
get (id) {
|
||||
let struct = this.find(id)
|
||||
if (struct === null && id instanceof RootID) {
|
||||
@@ -27,7 +24,7 @@ export default class OperationStore extends Tree {
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// Return an insertion such that id is the first element of content
|
||||
// This function manipulates an operation, if necessary
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import ID from '../Util/ID'
|
||||
import ID from '../Util/ID.js'
|
||||
|
||||
export default class StateStore {
|
||||
constructor (y) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import StructManager from '../Util/StructManager'
|
||||
import StructManager from '../Util/StructManager.js'
|
||||
|
||||
export default class Delete {
|
||||
constructor () {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import StructManager from '../Util/StructManager'
|
||||
|
||||
export default class Item {
|
||||
constructor () {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Item from './Item'
|
||||
import Item from './Item.js'
|
||||
|
||||
export default class ItemJSON extends Item {
|
||||
constructor () {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Item from './Item'
|
||||
import Item from './Item.js'
|
||||
|
||||
export default class ItemString extends Item {
|
||||
constructor () {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Item from './Item'
|
||||
import Item from './Item.js'
|
||||
|
||||
export default class Type extends Item {
|
||||
constructor () {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Type from '../Struct/Type'
|
||||
import ItemJSON from '../Struct/ItemJSON'
|
||||
import Type from '../Struct/Type.js'
|
||||
import ItemJSON from '../Struct/ItemJSON.js'
|
||||
|
||||
export default class YArray extends Type {
|
||||
forEach (f) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Type from '../Struct/Type'
|
||||
import Item from '../Struct/Item'
|
||||
import ItemJSON from '../Struct/ItemJSON'
|
||||
import Type from '../Struct/Type.js'
|
||||
import Item from '../Struct/Item.js'
|
||||
import ItemJSON from '../Struct/ItemJSON.js'
|
||||
|
||||
export default class YMap extends Type {
|
||||
set (key, value) {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
import YArray from './YArray.js'
|
||||
|
||||
export default class YText extends YArray {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
import YArray from './YArray.js'
|
||||
|
||||
export default class YXml extends YArray {
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
import StructManager from './StructManager'
|
||||
import { getReference } from './structReferences.js'
|
||||
|
||||
export class ID {
|
||||
export default class ID {
|
||||
constructor (user, clock) {
|
||||
this.user = user
|
||||
this.clock = clock
|
||||
@@ -16,17 +16,3 @@ export class ID {
|
||||
return this.user < id.user || (this.user === id.user && this.clock < id.clock)
|
||||
}
|
||||
}
|
||||
|
||||
export class RootID {
|
||||
constructor (name, typeConstructor) {
|
||||
this.user = -1
|
||||
this.name = name
|
||||
this.type = StructManager.getReference(typeConstructor)
|
||||
}
|
||||
equals (id) {
|
||||
return id !== null && id.user === this.user && id.name === this.name && id.type === this.type
|
||||
}
|
||||
lessThan (id) {
|
||||
return this.user < id.user || (this.user === id.user && (this.name < id.name || (this.name === id.name && this.type < id.type)))
|
||||
}
|
||||
}
|
||||
|
||||
14
src/Util/RootID.js
Normal file
14
src/Util/RootID.js
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
export default class RootID {
|
||||
constructor (name, typeConstructor) {
|
||||
this.user = -1
|
||||
this.name = name
|
||||
this.type = StructManager.getReference(typeConstructor)
|
||||
}
|
||||
equals (id) {
|
||||
return id !== null && id.user === this.user && id.name === this.name && id.type === this.type
|
||||
}
|
||||
lessThan (id) {
|
||||
return this.user < id.user || (this.user === id.user && (this.name < id.name || (this.name === id.name && this.type < id.type)))
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import Delete from '../Struct/Delete'
|
||||
import ID from './ID'
|
||||
|
||||
export default function deleteItemRange (y, user, clock, length) {
|
||||
export function deleteItemRange (y, user, clock, length) {
|
||||
let del = new Delete()
|
||||
del._target = new ID(user, clock)
|
||||
del._length = length
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* global crypto */
|
||||
|
||||
export default function generateUserID () {
|
||||
export function generateUserID () {
|
||||
if (typeof crypto !== 'undefined' && crypto.getRandomValue != null) {
|
||||
// browser
|
||||
let arr = new Uint32Array(1)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import YArray from '../Type/YArray'
|
||||
import YMap from '../Type/YMap'
|
||||
import YText from '../Type/YText'
|
||||
import YXml from '../Type/YXml'
|
||||
import YArray from '../Type/YArray.js'
|
||||
import YMap from '../Type/YMap.js'
|
||||
import YText from '../Type/YText.js'
|
||||
import YXml from '../Type/YXml.js'
|
||||
|
||||
import ItemJSON from '../Struct/ItemJSON'
|
||||
import ItemString from '../Struct/ItemString'
|
||||
import ItemJSON from '../Struct/ItemJSON.js'
|
||||
import ItemString from '../Struct/ItemString.js'
|
||||
|
||||
const structs = new Map()
|
||||
const references = new Map()
|
||||
|
||||
35
src/Y.js
35
src/Y.js
@@ -1,20 +1,25 @@
|
||||
|
||||
import debug from 'debug'
|
||||
// import debug from 'debug'
|
||||
export function debug (namespace) {
|
||||
return function log (message) {
|
||||
console.log(namespace, message)
|
||||
}
|
||||
}
|
||||
|
||||
import DeleteStore from './Store/DeleteStore'
|
||||
import OperationStore from './Store/OperationStore'
|
||||
import StateStore from './Store/StateStore'
|
||||
import generateUserID from './Function/generateUserID'
|
||||
import { RootID } from './Util/ID.js'
|
||||
import DeleteStore from './Store/DeleteStore.js'
|
||||
import OperationStore from './Store/OperationStore.js'
|
||||
import StateStore from './Store/StateStore.js'
|
||||
import { generateUserID } from './Util/generateUserID.js'
|
||||
import RootID from './Util/RootID.js'
|
||||
|
||||
import { formatYjsMessage, formatYjsMessageType } from './MessageHandler'
|
||||
import { messageToString, messageToRoomname } from './MessageHandler/messageToString.js'
|
||||
|
||||
import Connector from './Connector'
|
||||
import Persistence from './Persistence'
|
||||
import YArray from './Type/YArray'
|
||||
import YMap from './Type/YMap'
|
||||
import YText from './Type/YText'
|
||||
import YXml from './Type/YXml'
|
||||
import Connector from './Connector.js'
|
||||
import Persistence from './Persistence.js'
|
||||
import YArray from './Type/YArray.js'
|
||||
import YMap from './Type/YMap.js'
|
||||
import YText from './Type/YText.js'
|
||||
import YXml from './Type/YXml.js'
|
||||
|
||||
export default class Y {
|
||||
constructor (opts) {
|
||||
@@ -97,5 +102,5 @@ Y.Text = YText
|
||||
Y.Xml = YXml
|
||||
|
||||
Y.debug = debug
|
||||
debug.formatters.Y = formatYjsMessage
|
||||
debug.formatters.y = formatYjsMessageType
|
||||
debug.formatters.Y = messageToString
|
||||
debug.formatters.y = messageToRoomname
|
||||
|
||||
Reference in New Issue
Block a user