Skip to content

Commit

Permalink
fix compiling issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Oct 14, 2017
1 parent 82015d5 commit 0e426f8
Show file tree
Hide file tree
Showing 36 changed files with 192 additions and 309 deletions.
2 changes: 2 additions & 0 deletions .flowconfig
Expand Up @@ -5,6 +5,8 @@

[include]
./src/
./tests-lib/
./test/

[libs]
./declarations/
Expand Down
3 changes: 1 addition & 2 deletions package.json
Expand Up @@ -64,7 +64,6 @@
"tag-dist-files": "^0.1.6"
},
"dependencies": {
"debug": "^2.6.8",
"utf-8": "^1.0.0"
"debug": "^2.6.8"
}
}
2 changes: 1 addition & 1 deletion rollup.browser.js
Expand Up @@ -5,7 +5,7 @@ import commonjs from 'rollup-plugin-commonjs'
var pkg = require('./package.json')

export default {
entry: 'src/y.js',
entry: 'src/Y.js',
moduleName: 'Y',
format: 'umd',
plugins: [
Expand Down
2 changes: 1 addition & 1 deletion rollup.node.js
Expand Up @@ -3,7 +3,7 @@ import commonjs from 'rollup-plugin-commonjs'
var pkg = require('./package.json')

export default {
entry: 'src/y.js',
entry: 'src/Y.js',
moduleName: 'Y',
format: 'umd',
plugins: [
Expand Down
61 changes: 45 additions & 16 deletions src/Binary/Decoder.js
@@ -1,4 +1,4 @@
import utf8 from 'utf-8'
import '../../node_modules/utf8/utf8.js'

export default class BinaryDecoder {
constructor (buffer) {
Expand All @@ -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] +
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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())
}
}
2 changes: 1 addition & 1 deletion src/Binary/Encoder.js
@@ -1,4 +1,4 @@
import utf8 from 'utf-8'
import '../../node_modules/utf8/utf8.js'

const bits7 = 0b1111111
const bits8 = 0b11111111
Expand Down
9 changes: 5 additions & 4 deletions src/Connector.js
@@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/MessageHandler/integrateRemoteStructs.js
@@ -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) {
Expand Down Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions src/MessageHandler/messageToString.js
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/MessageHandler/syncStep1.js
@@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/MessageHandler/syncStep2.js
@@ -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')
Expand Down
4 changes: 2 additions & 2 deletions src/MessageHandler/update.js
@@ -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) {
Expand All @@ -16,4 +16,4 @@ export function stringifyUpdate (decoder, strBuilder) {
}
}

export { integrateRemoteStructs as readUpdate } from './integrateRemoteStructs'
export { integrateRemoteStructs as readUpdate } from './integrateRemoteStructs.js'
2 changes: 1 addition & 1 deletion src/Persistence.js
@@ -1,4 +1,4 @@
import { BinaryEncoder } from './Encoding.js'
import BinaryEncoder from './Binary/Encoder.js'

export default function extendPersistence (Y) {
class AbstractPersistence {
Expand Down
4 changes: 2 additions & 2 deletions src/Store/DeleteStore.js
@@ -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) {
Expand Down
11 changes: 4 additions & 7 deletions src/Store/OperationStore.js
@@ -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) {
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Store/StateStore.js
@@ -1,4 +1,4 @@
import ID from '../Util/ID'
import ID from '../Util/ID.js'

export default class StateStore {
constructor (y) {
Expand Down
2 changes: 1 addition & 1 deletion src/Struct/Delete.js
@@ -1,4 +1,4 @@
import StructManager from '../Util/StructManager'
import StructManager from '../Util/StructManager.js'

export default class Delete {
constructor () {
Expand Down
1 change: 0 additions & 1 deletion src/Struct/Item.js
@@ -1,4 +1,3 @@
import StructManager from '../Util/StructManager'

export default class Item {
constructor () {
Expand Down
2 changes: 1 addition & 1 deletion src/Struct/ItemJSON.js
@@ -1,4 +1,4 @@
import Item from './Item'
import Item from './Item.js'

export default class ItemJSON extends Item {
constructor () {
Expand Down
2 changes: 1 addition & 1 deletion src/Struct/ItemString.js
@@ -1,4 +1,4 @@
import Item from './Item'
import Item from './Item.js'

export default class ItemString extends Item {
constructor () {
Expand Down
2 changes: 1 addition & 1 deletion src/Struct/Type.js
@@ -1,4 +1,4 @@
import Item from './Item'
import Item from './Item.js'

export default class Type extends Item {
constructor () {
Expand Down
4 changes: 2 additions & 2 deletions src/Type/YArray.js
@@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/Type/YMap.js
@@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions src/Type/YText.js
@@ -0,0 +1,4 @@
import YArray from './YArray.js'

export default class YText extends YArray {
}
4 changes: 4 additions & 0 deletions src/Type/YXml.js
@@ -0,0 +1,4 @@
import YArray from './YArray.js'

export default class YXml extends YArray {
}
18 changes: 2 additions & 16 deletions src/Util/ID.js
@@ -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
Expand All @@ -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 changes: 14 additions & 0 deletions src/Util/RootID.js
@@ -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)))
}
}
2 changes: 1 addition & 1 deletion src/Util/deleteItemRange.js
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/Util/generateUserID.js
@@ -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)
Expand Down

0 comments on commit 0e426f8

Please sign in to comment.