lint & typechecks for lib0 upgrade

This commit is contained in:
Kevin Jahns
2026-02-25 15:55:42 +01:00
parent b9ede1b453
commit ae7dc2dedd
11 changed files with 55 additions and 53 deletions

18
package-lock.json generated
View File

@@ -3,13 +3,17 @@
"version": "14.0.0-22",
"lockfileVersion": 3,
"requires": true,
"dev": true,
"peer": true,
"packages": {
"": {
"name": "@y/y",
"version": "14.0.0-22",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"lib0": "^1.0.0-rc.1"
"lib0": "^1.0.0-rc.2"
},
"devDependencies": {
"@types/node": "^22.14.1",
@@ -355,7 +359,6 @@
"integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
"dev": true,
"license": "MIT",
"peer": true,
"bin": {
"acorn": "bin/acorn"
},
@@ -1253,7 +1256,6 @@
"deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@eslint-community/eslint-utils": "^4.2.0",
"@eslint-community/regexpp": "^4.6.1",
@@ -1461,7 +1463,6 @@
"integrity": "sha512-whOE1HFo/qJDyX4SnXzP4N6zOWn79WhnCUY/iDR0mPfQZO8wcYE4JClzI2oZrhBnnMUCBCHZhO6VQyoBU95mZA==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"@rtsao/scc": "^1.1.0",
"array-includes": "^3.1.9",
@@ -1532,7 +1533,6 @@
"integrity": "sha512-jDex9s7D/Qial8AGVIHq4W7NswpUD5DPDL2RH8Lzd9EloWUuvUkHfv4FRLMipH5q2UtyurorBkPeNi1wVWNh3Q==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"builtins": "^5.0.1",
"eslint-plugin-es": "^4.1.0",
@@ -1595,7 +1595,6 @@
"integrity": "sha512-57Zzfw8G6+Gq7axm2Pdo3gW/Rx3h9Yywgn61uE/3elTCOePEHVrn2i5CdfBwA1BLK0Q0WqctICIUSqXZW/VprQ==",
"dev": true,
"license": "ISC",
"peer": true,
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
@@ -1612,7 +1611,6 @@
"integrity": "sha512-Qteup0SqU15kdocexFNAJMvCJEfa2xUKNV4CC1xsVMrIIqEy3SQ/rqyxCWNzfrd3/ldy6HMlD2e0JDVpDg2qIA==",
"dev": true,
"license": "MIT",
"peer": true,
"dependencies": {
"array-includes": "^3.1.8",
"array.prototype.findlast": "^1.2.5",
@@ -3044,9 +3042,9 @@
}
},
"node_modules/lib0": {
"version": "1.0.0-rc.1",
"resolved": "https://registry.npmjs.org/lib0/-/lib0-1.0.0-rc.1.tgz",
"integrity": "sha512-UN5phQQuoCsP8zaXAbTNR2h5GneN6bliHQ57XkNvhRBG/qT6ce6z7yGr67osccefM1iXiLb/drYp6+msDvs4hQ==",
"version": "1.0.0-rc.2",
"resolved": "https://registry.npmjs.org/lib0/-/lib0-1.0.0-rc.2.tgz",
"integrity": "sha512-5rksKU/3m9m04Ra9i5ajA4qNIT+34/qB0srPl/9pZxqm4R2e4w1go5xL32U+CrNdnFXpU3TKrSHS6rxZZVJ3hQ==",
"license": "MIT",
"bin": {
"0ecdsa-generate-keypair": "src/bin/0ecdsa-generate-keypair.js",

View File

@@ -76,7 +76,7 @@
},
"homepage": "https://docs.yjs.dev",
"dependencies": {
"lib0": "^1.0.0-rc.1"
"lib0": "^1.0.0-rc.2"
},
"devDependencies": {
"@types/node": "^22.14.1",

View File

@@ -1179,7 +1179,7 @@ export class YType {
* @param {delta.FormattingAttributes} [format]
*/
insert (index, content, format) {
this.applyDelta(delta.create().retain(index).insert(/** @type {any} */ (content), format))
this.applyDelta(delta.create().retain(index).insert(/** @type {any} */ (content), format).done())
}
/**

View File

@@ -41,14 +41,14 @@ export const testAttributedEvents = _tc => {
})
const am = Y.createAttributionManagerFromDiff(v1, ydoc)
const c1 = ytext.toDelta(am)
t.compare(c1, delta.create().insert('hello ').insert('world', null, { delete: [] }))
t.compare(c1, delta.create().insert('hello ').insert('world', null, { delete: [] }).done())
let calledObserver = false
ytext.observe(event => {
const d = event.getDelta(am)
t.compare(d, delta.create().retain(11).insert('!', null, { insert: [] }))
t.compare(d, delta.create().retain(11).insert('!', null, { insert: [] }).done())
calledObserver = true
})
ytext.applyDelta(delta.create().retain(11).insert('!'), am)
ytext.applyDelta(delta.create().retain(11).insert('!').done(), am)
t.assert(calledObserver)
}
@@ -65,8 +65,8 @@ export const testInsertionsMindingAttributedContent = _tc => {
})
const am = Y.createAttributionManagerFromDiff(v1, ydoc)
const c1 = ytext.toDelta(am)
t.compare(c1, delta.create().insert('hello ').insert('world', null, { delete: [] }))
ytext.applyDelta(delta.create().retain(11).insert('content'), am)
t.compare(c1, delta.create().insert('hello ').insert('world', null, { delete: [] }).done())
ytext.applyDelta(delta.create().retain(11).insert('content').done(), am)
t.assert(ytext.toString() === 'hello content')
}
@@ -83,8 +83,8 @@ export const testInsertionsIntoAttributedContent = _tc => {
})
const am = Y.createAttributionManagerFromDiff(v1, ydoc)
const c1 = ytext.toDelta(am)
t.compare(c1, delta.create().insert('hello ').insert('word', null, { insert: [] }))
ytext.applyDelta(delta.create().retain(9).insert('l'), am)
t.compare(c1, delta.create().insert('hello ').insert('word', null, { insert: [] }).done())
ytext.applyDelta(delta.create().retain(9).insert('l').done(), am)
t.assert(ytext.toString() === 'hello world')
}
@@ -107,7 +107,7 @@ export const testYdocDiff = () => {
.modifyAttr('array', delta.create().retain(1).insert(['x'], null, { insert: [] }))
.modifyAttr('map', delta.create().setAttr('newk', 42, { insert: [] }).modifyAttr('nested', delta.create().insert([1], null, { insert: [] })))
const expectedDone = expected.done()
t.compare(d, expectedDone)
t.compare(d, expectedDone)
}
export const testChildListContent = () => {
@@ -115,7 +115,7 @@ export const testChildListContent = () => {
const ydocUpdated = Y.cloneDoc(ydocStart)
const yf = new Y.Type('test')
let calledEvent = 0
yf.applyDelta(delta.create().insert('test content').setAttr('k', 'v'))
yf.applyDelta(delta.create().insert('test content').setAttr('k', 'v').done())
const yarray = ydocUpdated.get('array')
yarray.observeDeep(event => {
@@ -129,7 +129,7 @@ export const testChildListContent = () => {
const d = Y.diffDocsToDelta(ydocStart, ydocUpdated)
console.log('calculated diff', d.toJSON())
const expected = delta.create()
.modifyAttr('array', delta.create().insert([delta.create('test').insert('test content', null, { insert: [] }).setAttr('k', 'v', { insert: [] })], null, { insert: [] }))
.modifyAttr('array', delta.create().insert([delta.create('test').insert('test content', null, { insert: [] }).setAttr('k', 'v', { insert: [] })], null, { insert: [] }).done())
t.compare(d.done(), expected.done())
}
@@ -152,13 +152,13 @@ export const testAttributionSession1 = tc => {
text1.insert(0, 'b')
testConnector.flushAllMessages()
const d1 = text0.toDelta(Y.createAttributionManagerFromDiff(v1, users[0], { attrs: globalAttributions }))
t.compare(d1, delta.create().insert('a', null, { insert: ['0'] }).insert('b', null, { insert: ['1'] }))
t.compare(d1, delta.create().insert('a', null, { insert: ['0'] }).insert('b', null, { insert: ['1'] }).done())
const v2 = Y.cloneDoc(users[0])
text0.delete(1, 1)
text1.insert(2, 'c')
testConnector.flushAllMessages()
const d2 = text0.toDelta(Y.createAttributionManagerFromDiff(v2, users[0], { attrs: globalAttributions }))
t.compare(d2, delta.create().insert('a').insert('b', null, { delete: ['0'] }).insert('c', null, { insert: ['1'] }))
t.compare(d2, delta.create().insert('a').insert('b', null, { delete: ['0'] }).insert('c', null, { insert: ['1'] }).done())
const onlyUser0ChangesAttributed = {
inserts: Y.filterIdMap(globalAttributions.inserts, attrs => attrs.some(attr => attr.name === 'insert' && attr.val === '0')),
@@ -166,9 +166,9 @@ export const testAttributionSession1 = tc => {
}
const amUser0 = new Y.TwosetAttributionManager(onlyUser0ChangesAttributed.inserts, onlyUser0ChangesAttributed.deletes)
const d3 = text0.toDelta(amUser0)
t.compare(d3, delta.create().insert('a', null, { insert: ['0'] }).insert('b', null, { delete: ['0'] }).insert('c'))
t.compare(d3, delta.create().insert('a', null, { insert: ['0'] }).insert('b', null, { delete: ['0'] }).insert('c').done())
Y.undoContentIds(users[0], Y.createContentIdsFromContentMap(onlyUser0ChangesAttributed))
const d4 = text0.toDelta()
t.compare(d4, delta.create().insert('bc'))
t.compare(d4, delta.create().insert('bc').done())
}

View File

@@ -42,7 +42,7 @@ export const testDeltaBasics = _tc => {
// apply changes to state
state.apply(change)
// compare state to expected state
t.assert(state.equals(delta.create().insert('hello!')))
t.assert(state.equals(delta.create().insert('hello!').done()))
}
/**
@@ -159,26 +159,26 @@ export const testBasics = _tc => {
export const testAttributions = _tc => {
const ydocV1 = new Y.Doc()
const ytypeV1 = ydocV1.get('txt')
ytypeV1.applyDelta(delta.create().insert('hello world'))
ytypeV1.applyDelta(delta.create().insert('hello world').done())
// create a new version with updated content
const ydoc = new Y.Doc()
Y.applyUpdate(ydoc, Y.encodeStateAsUpdate(ydocV1))
const ytype = ydoc.get('txt')
// delete " world" and insert exclamation mark "!".
ytype.applyDelta(delta.create().retain(5).delete(6).insert('!'))
ytype.applyDelta(delta.create().retain(5).delete(6).insert('!').done())
const am = Y.createAttributionManagerFromDiff(ydocV1, ydoc)
// get the attributed differences
const attributedContent = ytype.toDelta(am)
console.log('attributed content', attributedContent.toJSON())
t.assert(attributedContent.equals(delta.create().insert('hello').insert(' world', null, { delete: [] }).insert('!', null, { insert: [] })))
t.assert(attributedContent.equals(delta.create().insert('hello').insert(' world', null, { delete: [] }).insert('!', null, { insert: [] }).done()))
// for editor bindings, it is also necessary to observe changes and get the attributed changes
ytype.observe(event => {
const attributedChange = event.getDelta(am)
console.log('the attributed change', attributedChange.toJSON())
t.assert(attributedChange.done().equals(delta.create().retain(11).insert('!', null, { insert: [] })))
t.assert(attributedChange.done().equals(delta.create().retain(11).insert('!', null, { insert: [] }).done()))
const unattributedChange = event.delta
console.log('the UNattributed change', unattributedChange.toJSON())
t.assert(unattributedChange.equals(delta.create().retain(5).insert('!')))
t.assert(unattributedChange.equals(delta.create().retain(5).insert('!').done()))
})
/**
* Content now has different representations.
@@ -189,7 +189,7 @@ export const testAttributions = _tc => {
* UNattributed: 'world!'
*/
// Apply a change to the attributed content
ytype.applyDelta(delta.create().retain(11).insert('!'), am)
ytype.applyDelta(delta.create().retain(11).insert('!').done(), am)
// // Equivalent to applying a change to the UNattributed content:
// ytype.applyDelta(delta.create().retain(5).insert('!'))
}

View File

@@ -12,7 +12,7 @@ export const testBasic = _tc => {
const snapshot = Y.snapshot(ydoc)
ydoc.get().insert(0, 'hello ')
const restored = Y.createDocFromSnapshot(ydoc, snapshot)
t.assert(restored.get().toDelta().equals(delta.create().insert('world!')))
t.assert(restored.get().toDelta().equals(delta.create().insert('world!').done()))
}
/**

View File

@@ -85,11 +85,11 @@ export const testUndoText = tc => {
t.assert(text0.toString() === 'bcxyz')
// test marks
text0.format(1, 3, { bold: true })
t.compare(text0.toDelta(), delta.create().insert('b').insert('cxy', { bold: true }).insert('z'))
t.compare(text0.toDelta(), delta.create().insert('b').insert('cxy', { bold: true }).insert('z').done())
undoManager.undo()
t.compare(text0.toDelta(), delta.create().insert('bcxyz'))
t.compare(text0.toDelta(), delta.create().insert('bcxyz').done())
undoManager.redo()
t.compare(text0.toDelta(), delta.create().insert('b').insert('cxy', { bold: true }).insert('z'))
t.compare(text0.toDelta(), delta.create().insert('b').insert('cxy', { bold: true }).insert('z').done())
}
/**

View File

@@ -275,11 +275,11 @@ export const testMergePendingUpdates = _tc => {
serverUpdates.splice(serverUpdates.length, 0, update)
})
const yText = yDoc.get('textBlock')
yText.applyDelta(delta.create().insert('r'))
yText.applyDelta(delta.create().insert('o'))
yText.applyDelta(delta.create().insert('n'))
yText.applyDelta(delta.create().insert('e'))
yText.applyDelta(delta.create().insert('n'))
yText.applyDelta(delta.create().insert('r').done())
yText.applyDelta(delta.create().insert('o').done())
yText.applyDelta(delta.create().insert('n').done())
yText.applyDelta(delta.create().insert('e').done())
yText.applyDelta(delta.create().insert('n').done())
const yDoc1 = new Y.Doc()
Y.applyUpdate(yDoc1, serverUpdates[0])
@@ -318,7 +318,7 @@ export const testObfuscateUpdates = _tc => {
const ymap = ydoc.get('map')
const yarray = ydoc.get('array')
// test ytext
ytext.applyDelta(delta.create().insert('text', { bold: true }).insert([{ href: 'supersecreturl' }]))
ytext.applyDelta(delta.create().insert('text', { bold: true }).insert([{ href: 'supersecreturl' }]).done())
// test ymap
ymap.setAttr('key', 'secret1')
ymap.setAttr('key', 'secret2')

View File

@@ -162,9 +162,9 @@ export const testDeleteInsert = tc => {
export const testInsertThreeElementsTryRegetProperty = tc => {
const { testConnector, users, array0, array1 } = init(tc, { users: 2 })
array0.insert(0, [1, true, false])
t.compare(array0.toDelta(), delta.create().insert([1, true, false]), 'content works')
t.compare(array0.toDelta(), delta.create().insert([1, true, false]).done(), 'content works')
testConnector.flushAllMessages()
t.compare(array1.toDelta(), delta.create().insert([1, true, false]), 'comparison works after sync')
t.compare(array1.toDelta(), delta.create().insert([1, true, false]).done(), 'comparison works after sync')
compare(users)
}
@@ -342,7 +342,7 @@ export const testChangeEvent = tc => {
const newArr = new Y.Type()
array0.insert(0, [newArr, 4, 'dtrn'])
t.assert(d !== null && d.children.len === 1)
t.compare(d, delta.create().insert([newArr, 4, 'dtrn']))
t.compare(d, delta.create().insert([newArr, 4, 'dtrn']).done())
array0.delete(0, 2)
t.assert(d !== null && d.children.len === 1)
t.compare(d.toJSON().children, [{ delete: 2 }])

View File

@@ -44,7 +44,7 @@ export const testNestedMapEvent = () => {
ymap.observeDeep(event => {
const d = event.deltaDeep
called++
t.compare(d, delta.create().modifyAttr('nested', delta.create().setAttr('k', 'v')))
t.compare(d, delta.create().modifyAttr('nested', delta.create().setAttr('k', 'v')).done())
})
ymapNested.setAttr('k', 'v')
t.assert(called === 1)

View File

@@ -1380,7 +1380,7 @@ export const testNotMergeEmptyLinesFormat = _tc => {
.insert('Text')
.insert('\n', { title: true })
.insert('\nText')
.insert('\n', { title: true })
.insert('\n', { title: true }).done()
)
t.compare(
testText.toDelta(),
@@ -1403,6 +1403,7 @@ export const testPreserveAttributesThroughDelete = _tc => {
.insert('Text')
.insert('\n', { title: true })
.insert('\n')
.done()
)
testText.applyDelta(delta.create()
.retain(4)
@@ -1422,7 +1423,7 @@ export const testPreserveAttributesThroughDelete = _tc => {
*/
export const testGetDeltaWithEmbeds = tc => {
const { text0 } = init(tc, { users: 1 })
text0.applyDelta(delta.create().insert([{ linebreak: 's' }]))
text0.applyDelta(delta.create().insert([{ linebreak: 's' }]).done())
t.compare(text0.toDelta(),
delta.create()
.insert([{ linebreak: 's' }])
@@ -1437,6 +1438,7 @@ export const testTypesAsEmbed = tc => {
const { text0, text1, testConnector } = init(tc, { users: 2 })
text0.applyDelta(delta.create()
.insert([Y.Type.from(delta.create().setAttr('key', 'val'))])
.done()
)
t.compare(/** @type {any} */ (text0).toDeltaDeep().toJSON().children, [{ type: 'insert', insert: [{ type: 'delta', attrs: { key: { type: 'insert', value: 'val' } } }] }])
let firedEvent = false
@@ -1460,7 +1462,7 @@ export const testSnapshot = tc => {
const { text0 } = init(tc, { users: 1 })
const doc0 = /** @type {Y.Doc} */ (text0.doc)
doc0.gc = false
text0.applyDelta(delta.create().insert('abcd'))
text0.applyDelta(delta.create().insert('abcd').done())
const snapshot1 = Y.snapshot(doc0)
text0.applyDelta(delta.create()
.retain(1)
@@ -1498,14 +1500,16 @@ export const testSnapshotDeleteAfter = tc => {
doc0.gc = false
text0.applyDelta(delta.create()
.insert('abcd')
.done()
)
const snapshot1 = Y.snapshot(doc0)
text0.applyDelta(delta.create()
.retain(4)
.insert('e')
.done()
)
const state1 = text0.toDelta(createAttributionManagerFromSnapshots(snapshot1))
t.compare(state1, delta.create().insert('abcd'))
t.compare(state1, delta.create().insert('abcd').done())
}
/**
@@ -1902,7 +1906,7 @@ export const testAttributedContent = _tc => {
attributionManager = new TwosetAttributionManager(createIdMapFromIdSet(tr.insertSet, []), createIdMapFromIdSet(tr.deleteSet, []))
})
t.group('insert / delete / format', () => {
ytext.applyDelta(delta.create().retain(4, { italic: true }).retain(2).delete(5).insert('attributions'))
ytext.applyDelta(delta.create().retain(4, { italic: true }).retain(2).delete(5).insert('attributions').done())
const expectedContent = delta.create().insert('Hell', { italic: true }, { format: { italic: [] } }).insert('o ').insert('World', {}, { delete: [] }).insert('attributions', {}, { insert: [] }).insert('!')
const attributedContent = ytext.toDelta(attributionManager)
console.log(attributedContent.toJSON())
@@ -1928,7 +1932,7 @@ export const testAttributedDiffing = _tc => {
ydoc.clientID = 1
Y.applyUpdate(ydoc, Y.encodeStateAsUpdate(ydocVersion0))
const ytext = ydoc.get()
ytext.applyDelta(delta.create().retain(4, { italic: true }).retain(2).delete(5).insert('attributions'))
ytext.applyDelta(delta.create().retain(4, { italic: true }).retain(2).delete(5).insert('attributions').done())
// this represents to all insertions of ydoc
const insertionSet = Y.createInsertSetFromStructStore(ydoc.store, false)
const deleteSet = Y.createDeleteSetFromStructStore(ydoc.store)