permission protocol + reduce circular dependencies
This commit is contained in:
@@ -4,13 +4,13 @@
|
||||
|
||||
import { getStructReference } from '../utils/structReferences.js'
|
||||
import * as ID from '../utils/ID.js'
|
||||
import { stringifyID } from '../protocols/syncProtocol.js'
|
||||
import { writeStructToTransaction } from '../utils/Transaction.js'
|
||||
import { writeStructToTransaction } from '../utils/structEncoding.js'
|
||||
import * as decoding from '../lib/decoding.js'
|
||||
import * as encoding from '../lib/encoding.js'
|
||||
import { Item } from './Item.js' // eslint-disable-line
|
||||
import { Y } from '../utils/Y.js' // eslint-disable-line
|
||||
// import { Item } from './Item.js' // eslint-disable-line
|
||||
// import { Y } from '../utils/Y.js' // eslint-disable-line
|
||||
import { deleteItemRange } from '../utils/structManipulation.js'
|
||||
import * as stringify from '../utils/structStringify.js'
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -99,6 +99,6 @@ export class Delete {
|
||||
* @private
|
||||
*/
|
||||
_logString () {
|
||||
return `Delete - target: ${stringifyID(this._targetID)}, len: ${this._length}`
|
||||
return `Delete - target: ${stringify.stringifyID(this._targetID)}, len: ${this._length}`
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
|
||||
import { getStructReference } from '../utils/structReferences.js'
|
||||
import * as ID from '../utils/ID.js'
|
||||
import { writeStructToTransaction } from '../utils/Transaction.js'
|
||||
import { writeStructToTransaction } from '../utils/structEncoding.js'
|
||||
import * as decoding from '../lib/decoding.js'
|
||||
import * as encoding from '../lib/encoding.js'
|
||||
import { Y } from '../utils/Y.js' // eslint-disable-line
|
||||
// import { Y } from '../utils/Y.js' // eslint-disable-line
|
||||
|
||||
// TODO should have the same base class as Item
|
||||
export class GC {
|
||||
|
||||
@@ -5,12 +5,27 @@
|
||||
import { getStructReference } from '../utils/structReferences.js'
|
||||
import * as ID from '../utils/ID.js'
|
||||
import { Delete } from './Delete.js'
|
||||
import { transactionTypeChanged, writeStructToTransaction } from '../utils/Transaction.js'
|
||||
import { writeStructToTransaction } from '../utils/structEncoding.js'
|
||||
import { GC } from './GC.js'
|
||||
import * as encoding from '../lib/encoding.js'
|
||||
import * as decoding from '../lib/decoding.js'
|
||||
import { Y } from '../utils/Y.js'
|
||||
import { Type } from './Type.js' // eslint-disable-line
|
||||
// import { Type } from './Type.js' // eslint-disable-line
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
export const transactionTypeChanged = (y, type, sub) => {
|
||||
if (type !== y && !type._deleted && !y._transaction.newTypes.has(type)) {
|
||||
const changedTypes = y._transaction.changedTypes
|
||||
let subs = changedTypes.get(type)
|
||||
if (subs === undefined) {
|
||||
// create if it doesn't exist yet
|
||||
subs = new Set()
|
||||
changedTypes.set(type, subs)
|
||||
}
|
||||
subs.add(sub)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -159,7 +174,7 @@ export class Item {
|
||||
if (this._redone !== null) {
|
||||
return this._redone
|
||||
}
|
||||
if (this._parent instanceof Y) {
|
||||
if (!(this._parent instanceof Item)) {
|
||||
return
|
||||
}
|
||||
let struct = this._copy()
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
import { Item } from './Item.js'
|
||||
import { logItemHelper } from '../protocols/syncProtocol.js'
|
||||
import * as stringify from '../utils/structStringify.js'
|
||||
import * as encoding from '../lib/encoding.js'
|
||||
import * as decoding from '../lib/decoding.js'
|
||||
import { Y } from '../utils/Y.js' // eslint-disable-line
|
||||
@@ -44,6 +44,6 @@ export class ItemEmbed extends Item {
|
||||
* @private
|
||||
*/
|
||||
_logString () {
|
||||
return logItemHelper('ItemEmbed', this, `embed:${JSON.stringify(this.embed)}`)
|
||||
return stringify.logItemHelper('ItemEmbed', this, `embed:${JSON.stringify(this.embed)}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
import { Item } from './Item.js'
|
||||
import { logItemHelper } from '../protocols/syncProtocol.js'
|
||||
import * as stringify from '../utils/structStringify.js'
|
||||
import * as encoding from '../lib/encoding.js'
|
||||
import * as decoding from '../lib/decoding.js'
|
||||
import { Y } from '../utils/Y.js' // eslint-disable-line
|
||||
@@ -51,6 +51,6 @@ export class ItemFormat extends Item {
|
||||
* @private
|
||||
*/
|
||||
_logString () {
|
||||
return logItemHelper('ItemFormat', this, `key:${JSON.stringify(this.key)},value:${JSON.stringify(this.value)}`)
|
||||
return stringify.logItemHelper('ItemFormat', this, `key:${JSON.stringify(this.key)},value:${JSON.stringify(this.value)}`)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
import { Item, splitHelper } from './Item.js'
|
||||
import { logItemHelper } from '../protocols/syncProtocol.js'
|
||||
import * as stringify from '../utils/structStringify.js'
|
||||
import * as encoding from '../lib/encoding.js'
|
||||
import * as decoding from '../lib/decoding.js'
|
||||
import { Y } from '../utils/Y.js' // eslint-disable-line
|
||||
@@ -19,7 +19,8 @@ export class ItemJSON extends Item {
|
||||
return struct
|
||||
}
|
||||
get _length () {
|
||||
return this._content.length
|
||||
const c = this._content
|
||||
return c !== null ? c.length : 0
|
||||
}
|
||||
/**
|
||||
* @param {Y} y
|
||||
@@ -46,11 +47,11 @@ export class ItemJSON extends Item {
|
||||
*/
|
||||
_toBinary (encoder) {
|
||||
super._toBinary(encoder)
|
||||
let len = this._content.length
|
||||
const len = this._length
|
||||
encoding.writeVarUint(encoder, len)
|
||||
for (let i = 0; i < len; i++) {
|
||||
let encoded
|
||||
let content = this._content[i]
|
||||
const content = this._content[i]
|
||||
if (content === undefined) {
|
||||
encoded = 'undefined'
|
||||
} else {
|
||||
@@ -66,7 +67,7 @@ export class ItemJSON extends Item {
|
||||
* @private
|
||||
*/
|
||||
_logString () {
|
||||
return logItemHelper('ItemJSON', this, `content:${JSON.stringify(this._content)}`)
|
||||
return stringify.logItemHelper('ItemJSON', this, `content:${JSON.stringify(this._content)}`)
|
||||
}
|
||||
_splitAt (y, diff) {
|
||||
if (diff === 0) {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
import { Item, splitHelper } from './Item.js'
|
||||
import { logItemHelper } from '../protocols/syncProtocol.js'
|
||||
import * as stringify from '../utils/structStringify.js'
|
||||
import * as encoding from '../lib/encoding.js'
|
||||
import * as decoding from '../lib/decoding.js'
|
||||
import { Y } from '../utils/Y.js' // eslint-disable-line
|
||||
@@ -44,7 +44,7 @@ export class ItemString extends Item {
|
||||
* @private
|
||||
*/
|
||||
_logString () {
|
||||
return logItemHelper('ItemString', this, `content:"${this._content}"`)
|
||||
return stringify.logItemHelper('ItemString', this, `content:"${this._content}"`)
|
||||
}
|
||||
_splitAt (y, diff) {
|
||||
if (diff === 0) {
|
||||
|
||||
Reference in New Issue
Block a user