mjs nodejs support

This commit is contained in:
Kevin Jahns
2018-11-25 22:39:30 +01:00
parent e4a5f2caec
commit c12d00b227
122 changed files with 669 additions and 503 deletions

View File

@@ -2,8 +2,8 @@
* @module utils
*/
import { Tree } from '../lib/Tree.js'
import * as ID from './ID.js'
import { Tree } from '../lib/Tree.mjs'
import * as ID from './ID.mjs'
class DSNode {
constructor (id, len, gc) {

View File

@@ -2,9 +2,9 @@
* @module utils
*/
import { getStructReference } from './structReferences.js'
import * as decoding from '../lib/decoding.js'
import * as encoding from '../lib/encoding.js'
import { getStructReference } from './structReferences.mjs'
import * as decoding from '../lib/decoding.mjs'
import * as encoding from '../lib/encoding.mjs'
export class ID {
constructor (user, clock) {

View File

@@ -2,11 +2,11 @@
* @module utils
*/
import { Tree } from '../lib/Tree.js'
import * as ID from '../utils/ID.js'
import { getStruct } from '../utils/structReferences.js'
import { stringifyID, stringifyItemID } from '../protocols/syncProtocol.js'
import { GC } from '../structs/GC.js'
import { Tree } from '../lib/Tree.mjs'
import * as ID from '../utils/ID.mjs'
import { getStruct } from '../utils/structReferences.mjs'
import { stringifyID, stringifyItemID } from '../protocols/syncProtocol.mjs'
import { GC } from '../structs/GC.mjs'
export class OperationStore extends Tree {
constructor (y) {

View File

@@ -2,7 +2,7 @@
* @module utils
*/
import * as ID from '../utils/ID.js'
import * as ID from '../utils/ID.mjs'
/**
* @typedef {Map<number, number>} StateSet

View File

@@ -2,11 +2,11 @@
* @module utils
*/
import * as encoding from '../lib/encoding.js'
import { Y } from '../utils/Y.js' // eslint-disable-line
import { Type } from '../structs/Type.js' // eslint-disable-line
import { Item } from '../structs/Item.js' // eslint-disable-line
import { YEvent } from './YEvent.js' // eslint-disable-line
import * as encoding from '../lib/encoding.mjs'
import { Y } from '../utils/Y.mjs' // eslint-disable-line
import { Type } from '../structs/Type.mjs' // eslint-disable-line
import { Item } from '../structs/Item.mjs' // eslint-disable-line
import { YEvent } from './YEvent.mjs' // eslint-disable-line
/**
* A transaction is created for every change on the Yjs model. It is possible
* to bundle changes on the Yjs model in a single transaction to

View File

@@ -1,6 +1,6 @@
import * as ID from './ID.js'
import { isParentOf } from './isParentOf.js'
import * as ID from './ID.mjs'
import { isParentOf } from './isParentOf.mjs'
class ReverseOperation {
constructor (y, transaction, bindingInfos) {

View File

@@ -1,15 +1,15 @@
import { DeleteStore } from './DeleteStore.js'
import { OperationStore } from './OperationStore.js'
import { StateStore } from './StateStore.js'
import { generateRandomUint32 } from './generateRandomUint32.js'
import { createRootID } from './ID.js'
import { NamedEventHandler } from '../lib/NamedEventHandler.js'
import { Transaction } from './Transaction.js'
import * as encoding from '../lib/encoding.js'
import * as message from '../protocols/syncProtocol.js'
import { integrateRemoteStructs } from './integrateRemoteStructs.js'
import { Type } from '../structs/Type.js' // eslint-disable-line
import { Decoder } from '../lib/decoding.js' // eslint-disable-line
import { DeleteStore } from './DeleteStore.mjs'
import { OperationStore } from './OperationStore.mjs'
import { StateStore } from './StateStore.mjs'
import { generateRandomUint32 } from './generateRandomUint32.mjs'
import { createRootID } from './ID.mjs'
import { NamedEventHandler } from '../lib/NamedEventHandler.mjs'
import { Transaction } from './Transaction.mjs'
import * as encoding from '../lib/encoding.mjs'
import * as message from '../protocols/syncProtocol.mjs'
import { integrateRemoteStructs } from './integrateRemoteStructs.mjs'
import { Type } from '../structs/Type.mjs' // eslint-disable-line
import { Decoder } from '../lib/decoding.mjs' // eslint-disable-line
/**
* Anything that can be encoded with `JSON.stringify` and can be decoded with
@@ -135,16 +135,18 @@ export class Y extends NamedEventHandler {
}
/**
* @private
* Fake _start for root properties (y.set('name', type))
*
* @private
*/
get _start () {
return null
}
/**
* @private
* Fake _start for root properties (y.set('name', type))
*
* @private
*/
set _start (start) {}

View File

@@ -2,7 +2,7 @@
* @module utils
*/
import { Type } from '../structs/Type.js' // eslint-disable-line
import { Type } from '../structs/Type.mjs' // eslint-disable-line
/**
* YEvent describes the changes on a YType.

View File

@@ -3,9 +3,9 @@
* @module utils
*/
import * as ID from '../utils/ID.js'
import { ItemJSON } from '../structs/ItemJSON.js'
import { ItemString } from '../structs/ItemString.js'
import * as ID from '../utils/ID.mjs'
import { ItemJSON } from '../structs/ItemJSON.mjs'
import { ItemString } from '../structs/ItemString.mjs'
/**
* Try to merge all items in os with their successors.

View File

@@ -2,11 +2,11 @@
* @module utils
*/
import { getStruct } from '../utils/structReferences.js'
import * as decoding from '../lib/decoding.js'
import { GC } from '../structs/GC.js'
import { Y } from '../utils/Y.js' // eslint-disable-line
import { Item } from '../structs/Item.js' // eslint-disable-line
import { getStruct } from '../utils/structReferences.mjs'
import * as decoding from '../lib/decoding.mjs'
import { GC } from '../structs/GC.mjs'
import { Y } from '../utils/Y.mjs' // eslint-disable-line
import { Item } from '../structs/Item.mjs' // eslint-disable-line
class MissingEntry {
constructor (decoder, missing, struct) {

View File

@@ -2,8 +2,8 @@
* @module utils
*/
import { Y } from '../utils/Y.js' // eslint-disable-line
import { Type } from '../structs/Type.js' // eslint-disable-line
import { Y } from '../utils/Y.mjs' // eslint-disable-line
import { Type } from '../structs/Type.mjs' // eslint-disable-line
/**
* Check if `parent` is a parent of `child`.

View File

@@ -2,8 +2,8 @@
* @module utils
*/
import * as ID from './ID.js'
import { GC } from '../structs/GC.js'
import * as ID from './ID.mjs'
import { GC } from '../structs/GC.mjs'
// TODO: Implement function to describe ranges

View File

@@ -0,0 +1,35 @@
import * as ID from '../utils/ID.mjs'
/**
* @private
* Delete all items in an ID-range.
* Does not create delete operations!
* TODO: implement getItemCleanStartNode for better performance (only one lookup).
*/
export const deleteItemRange = (y, user, clock, range, gcChildren) => {
let item = y.os.getItemCleanStart(ID.createID(user, clock))
if (item !== null) {
if (!item._deleted) {
item._splitAt(y, range)
item._delete(y, false, true)
}
let itemLen = item._length
range -= itemLen
clock += itemLen
if (range > 0) {
let node = y.os.findNode(ID.createID(user, clock))
while (node !== null && node.val !== null && range > 0 && node.val._id.equals(ID.createID(user, clock))) {
const nodeVal = node.val
if (!nodeVal._deleted) {
nodeVal._splitAt(y, range)
nodeVal._delete(y, false, gcChildren)
}
const nodeLen = nodeVal._length
range -= nodeLen
clock += nodeLen
node = node.next()
}
}
}
}