bump typescript and fix type issues

This commit is contained in:
Kevin Jahns 2023-01-31 12:16:03 +01:00
parent 370d0c138d
commit 7f6c12a541
13 changed files with 972 additions and 615 deletions

View File

@ -58,8 +58,9 @@ on Yjs. [![Become a Sponsor](https://img.shields.io/static/v1?label=Become%20a%2
* [Skiff](https://skiff.org/) Private, decentralized workspace. * [Skiff](https://skiff.org/) Private, decentralized workspace.
* [Hyperquery](https://hyperquery.ai/) A collaborative data workspace for * [Hyperquery](https://hyperquery.ai/) A collaborative data workspace for
sharing analyses, documentation, spreadsheets, and dashboards. sharing analyses, documentation, spreadsheets, and dashboards.
* [Nosgestesclimat](https://nosgestesclimat.fr/groupe) The french carbon footprint calculator has a group P2P mode based on yjs * [Nosgestesclimat](https://nosgestesclimat.fr/groupe) The french carbon
footprint calculator has a group P2P mode based on yjs
## Table of Contents ## Table of Contents
* [Overview](#Overview) * [Overview](#Overview)

1472
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -81,13 +81,13 @@
"@rollup/plugin-commonjs": "^17.0.0", "@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.2.1", "@rollup/plugin-node-resolve": "^11.2.1",
"concurrently": "^3.6.1", "concurrently": "^3.6.1",
"typescript": "^4.9.5",
"http-server": "^0.12.3", "http-server": "^0.12.3",
"jsdoc": "^3.6.7", "jsdoc": "^3.6.7",
"markdownlint-cli": "^0.23.2", "markdownlint-cli": "^0.23.2",
"rollup": "^2.60.0", "rollup": "^2.60.0",
"standard": "^16.0.4", "standard": "^16.0.4",
"tui-jsdoc-template": "^1.2.2", "tui-jsdoc-template": "^1.2.2",
"typescript": "^4.4.4",
"y-protocols": "^1.0.5" "y-protocols": "^1.0.5"
} }
} }

View File

@ -324,9 +324,9 @@ export class AbstractType {
} }
/** /**
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder * @param {UpdateEncoderV1 | UpdateEncoderV2} _encoder
*/ */
_write (encoder) { } _write (_encoder) { }
/** /**
* The first non-deleted item * The first non-deleted item
@ -344,9 +344,9 @@ export class AbstractType {
* Must be implemented by each type. * Must be implemented by each type.
* *
* @param {Transaction} transaction * @param {Transaction} transaction
* @param {Set<null|string>} parentSubs Keys changed on this type. `null` if list was modified. * @param {Set<null|string>} _parentSubs Keys changed on this type. `null` if list was modified.
*/ */
_callObserver (transaction, parentSubs) { _callObserver (transaction, _parentSubs) {
if (!transaction.local && this._searchMarker) { if (!transaction.local && this._searchMarker) {
this._searchMarker.length = 0 this._searchMarker.length = 0
} }

View File

@ -58,11 +58,14 @@ export class YArray extends AbstractType {
/** /**
* Construct a new YArray containing the specified items. * Construct a new YArray containing the specified items.
* @template T * @template {Object<string,any>|Array<any>|number|null|string|Uint8Array} T
* @param {Array<T>} items * @param {Array<T>} items
* @return {YArray<T>} * @return {YArray<T>}
*/ */
static from (items) { static from (items) {
/**
* @type {YArray<T>}
*/
const a = new YArray() const a = new YArray()
a.push(items) a.push(items)
return a return a
@ -84,6 +87,9 @@ export class YArray extends AbstractType {
this._prelimContent = null this._prelimContent = null
} }
/**
* @return {YArray<T>}
*/
_copy () { _copy () {
return new YArray() return new YArray()
} }
@ -92,9 +98,12 @@ export class YArray extends AbstractType {
* @return {YArray<T>} * @return {YArray<T>}
*/ */
clone () { clone () {
/**
* @type {YArray<T>}
*/
const arr = new YArray() const arr = new YArray()
arr.insert(0, this.toArray().map(el => arr.insert(0, this.toArray().map(el =>
el instanceof AbstractType ? el.clone() : el el instanceof AbstractType ? /** @type {typeof el} */ (el.clone()) : el
)) ))
return arr return arr
} }
@ -133,7 +142,7 @@ export class YArray extends AbstractType {
insert (index, content) { insert (index, content) {
if (this.doc !== null) { if (this.doc !== null) {
transact(this.doc, transaction => { transact(this.doc, transaction => {
typeListInsertGenerics(transaction, this, index, content) typeListInsertGenerics(transaction, this, index, /** @type {any} */ (content))
}) })
} else { } else {
/** @type {Array<any>} */ (this._prelimContent).splice(index, 0, ...content) /** @type {Array<any>} */ (this._prelimContent).splice(index, 0, ...content)
@ -150,7 +159,7 @@ export class YArray extends AbstractType {
push (content) { push (content) {
if (this.doc !== null) { if (this.doc !== null) {
transact(this.doc, transaction => { transact(this.doc, transaction => {
typeListPushGenerics(transaction, this, content) typeListPushGenerics(transaction, this, /** @type {any} */ (content))
}) })
} else { } else {
/** @type {Array<any>} */ (this._prelimContent).push(...content) /** @type {Array<any>} */ (this._prelimContent).push(...content)
@ -259,9 +268,9 @@ export class YArray extends AbstractType {
} }
/** /**
* @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * @param {UpdateDecoderV1 | UpdateDecoderV2} _decoder
* *
* @private * @private
* @function * @function
*/ */
export const readYArray = decoder => new YArray() export const readYArray = _decoder => new YArray()

View File

@ -81,6 +81,9 @@ export class YMap extends AbstractType {
this._prelimContent = null this._prelimContent = null
} }
/**
* @return {YMap<MapType>}
*/
_copy () { _copy () {
return new YMap() return new YMap()
} }
@ -89,9 +92,12 @@ export class YMap extends AbstractType {
* @return {YMap<MapType>} * @return {YMap<MapType>}
*/ */
clone () { clone () {
/**
* @type {YMap<MapType>}
*/
const map = new YMap() const map = new YMap()
this.forEach((value, key) => { this.forEach((value, key) => {
map.set(key, value instanceof AbstractType ? value.clone() : value) map.set(key, value instanceof AbstractType ? /** @type {typeof value} */ (value.clone()) : value)
}) })
return map return map
} }
@ -207,7 +213,7 @@ export class YMap extends AbstractType {
set (key, value) { set (key, value) {
if (this.doc !== null) { if (this.doc !== null) {
transact(this.doc, transaction => { transact(this.doc, transaction => {
typeMapSet(transaction, this, key, value) typeMapSet(transaction, this, key, /** @type {any} */ (value))
}) })
} else { } else {
/** @type {Map<string, any>} */ (this._prelimContent).set(key, value) /** @type {Map<string, any>} */ (this._prelimContent).set(key, value)
@ -241,7 +247,7 @@ export class YMap extends AbstractType {
clear () { clear () {
if (this.doc !== null) { if (this.doc !== null) {
transact(this.doc, transaction => { transact(this.doc, transaction => {
this.forEach(function (value, key, map) { this.forEach(function (_value, key, map) {
typeMapDelete(transaction, map, key) typeMapDelete(transaction, map, key)
}) })
}) })
@ -259,9 +265,9 @@ export class YMap extends AbstractType {
} }
/** /**
* @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * @param {UpdateDecoderV1 | UpdateDecoderV2} _decoder
* *
* @private * @private
* @function * @function
*/ */
export const readYMap = decoder => new YMap() export const readYMap = _decoder => new YMap()

View File

@ -251,7 +251,7 @@ const insertAttributes = (transaction, parent, currPos, attributes) => {
* @function * @function
**/ **/
const insertText = (transaction, parent, currPos, text, attributes) => { const insertText = (transaction, parent, currPos, text, attributes) => {
currPos.currentAttributes.forEach((val, key) => { currPos.currentAttributes.forEach((_val, key) => {
if (attributes[key] === undefined) { if (attributes[key] === undefined) {
attributes[key] = null attributes[key] = null
} }
@ -927,7 +927,7 @@ export class YText extends AbstractType {
* Apply a {@link Delta} on this shared YText type. * Apply a {@link Delta} on this shared YText type.
* *
* @param {any} delta The changes to apply on this element. * @param {any} delta The changes to apply on this element.
* @param {object} [opts] * @param {object} opts
* @param {boolean} [opts.sanitize] Sanitize input delta. Removes ending newlines if set to true. * @param {boolean} [opts.sanitize] Sanitize input delta. Removes ending newlines if set to true.
* *
* *
@ -1229,12 +1229,11 @@ export class YText extends AbstractType {
* *
* @note Xml-Text nodes don't have attributes. You can use this feature to assign properties to complete text-blocks. * @note Xml-Text nodes don't have attributes. You can use this feature to assign properties to complete text-blocks.
* *
* @param {Snapshot} [snapshot]
* @return {Object<string, any>} A JSON Object that describes the attributes. * @return {Object<string, any>} A JSON Object that describes the attributes.
* *
* @public * @public
*/ */
getAttributes (snapshot) { getAttributes () {
return typeMapGetAll(this) return typeMapGetAll(this)
} }
@ -1247,10 +1246,10 @@ export class YText extends AbstractType {
} }
/** /**
* @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * @param {UpdateDecoderV1 | UpdateDecoderV2} _decoder
* @return {YText} * @return {YText}
* *
* @private * @private
* @function * @function
*/ */
export const readYText = decoder => new YText() export const readYText = _decoder => new YText()

View File

@ -9,7 +9,7 @@ import {
typeMapGetAll, typeMapGetAll,
typeListForEach, typeListForEach,
YXmlElementRefID, YXmlElementRefID,
YXmlText, ContentType, AbstractType, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Snapshot, Doc, Item // eslint-disable-line YXmlText, ContentType, AbstractType, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Item // eslint-disable-line
} from '../internals.js' } from '../internals.js'
/** /**

View File

@ -17,7 +17,7 @@ import {
transact, transact,
typeListGet, typeListGet,
typeListSlice, typeListSlice,
UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, ContentType, Transaction, Item, YXmlText, YXmlHook, Snapshot // eslint-disable-line UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, ContentType, Transaction, Item, YXmlText, YXmlHook // eslint-disable-line
} from '../internals.js' } from '../internals.js'
import * as error from 'lib0/error' import * as error from 'lib0/error'
@ -407,7 +407,7 @@ export class YXmlFragment extends AbstractType {
/** /**
* Executes a provided function on once on overy child element. * Executes a provided function on once on overy child element.
* *
* @param {function(YXmlElement|YXmlText,number, typeof this):void} f A function to execute on every element of this YArray. * @param {function(YXmlElement|YXmlText,number, typeof self):void} f A function to execute on every element of this YArray.
*/ */
forEach (f) { forEach (f) {
typeListForEach(this, f) typeListForEach(this, f)
@ -427,10 +427,10 @@ export class YXmlFragment extends AbstractType {
} }
/** /**
* @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * @param {UpdateDecoderV1 | UpdateDecoderV2} _decoder
* @return {YXmlFragment} * @return {YXmlFragment}
* *
* @private * @private
* @function * @function
*/ */
export const readYXmlFragment = decoder => new YXmlFragment() export const readYXmlFragment = _decoder => new YXmlFragment()

View File

@ -38,7 +38,7 @@ export const generateNewClientId = random.uint32
*/ */
export class Doc extends Observable { export class Doc extends Observable {
/** /**
* @param {DocOpts} [opts] configuration * @param {DocOpts} opts configuration
*/ */
constructor ({ guid = random.uuidv4(), collectionid = null, gc = true, gcFilter = () => true, meta = null, autoLoad = false, shouldLoad = true } = {}) { constructor ({ guid = random.uuidv4(), collectionid = null, gc = true, gcFilter = () => true, meta = null, autoLoad = false, shouldLoad = true } = {}) {
super() super()

View File

@ -71,7 +71,7 @@ export class PermanentUserData {
* @param {Doc} doc * @param {Doc} doc
* @param {number} clientid * @param {number} clientid
* @param {string} userDescription * @param {string} userDescription
* @param {Object} [conf] * @param {Object} conf
* @param {function(Transaction, DeleteSet):boolean} [conf.filter] * @param {function(Transaction, DeleteSet):boolean} [conf.filter]
*/ */
setUserMapping (doc, clientid, userDescription, { filter = () => true } = {}) { setUserMapping (doc, clientid, userDescription, { filter = () => true } = {}) {
@ -84,7 +84,7 @@ export class PermanentUserData {
users.set(userDescription, user) users.set(userDescription, user)
} }
user.get('ids').push([clientid]) user.get('ids').push([clientid])
users.observe(event => { users.observe(_event => {
setTimeout(() => { setTimeout(() => {
const userOverwrite = users.get(userDescription) const userOverwrite = users.get(userDescription)
if (userOverwrite !== user) { if (userOverwrite !== user) {

View File

@ -30,9 +30,9 @@ export const testOriginInTransaction = _tc => {
/** /**
* Client id should be changed when an instance receives updates from another client using the same client id. * Client id should be changed when an instance receives updates from another client using the same client id.
* *
* @param {t.TestCase} tc * @param {t.TestCase} _tc
*/ */
export const testClientIdDuplicateChange = tc => { export const testClientIdDuplicateChange = _tc => {
const doc1 = new Y.Doc() const doc1 = new Y.Doc()
doc1.clientID = 0 doc1.clientID = 0
const doc2 = new Y.Doc() const doc2 = new Y.Doc()
@ -44,9 +44,9 @@ export const testClientIdDuplicateChange = tc => {
} }
/** /**
* @param {t.TestCase} tc * @param {t.TestCase} _tc
*/ */
export const testGetTypeEmptyId = tc => { export const testGetTypeEmptyId = _tc => {
const doc1 = new Y.Doc() const doc1 = new Y.Doc()
doc1.getText('').insert(0, 'h') doc1.getText('').insert(0, 'h')
doc1.getText().insert(1, 'i') doc1.getText().insert(1, 'i')
@ -57,9 +57,9 @@ export const testGetTypeEmptyId = tc => {
} }
/** /**
* @param {t.TestCase} tc * @param {t.TestCase} _tc
*/ */
export const testToJSON = tc => { export const testToJSON = _tc => {
const doc = new Y.Doc() const doc = new Y.Doc()
t.compare(doc.toJSON(), {}, 'doc.toJSON yields empty object') t.compare(doc.toJSON(), {}, 'doc.toJSON yields empty object')
@ -84,9 +84,9 @@ export const testToJSON = tc => {
} }
/** /**
* @param {t.TestCase} tc * @param {t.TestCase} _tc
*/ */
export const testSubdoc = tc => { export const testSubdoc = _tc => {
const doc = new Y.Doc() const doc = new Y.Doc()
doc.load() // doesn't do anything doc.load() // doesn't do anything
{ {
@ -151,9 +151,9 @@ export const testSubdoc = tc => {
} }
/** /**
* @param {t.TestCase} tc * @param {t.TestCase} _tc
*/ */
export const testSubdocLoadEdgeCases = tc => { export const testSubdocLoadEdgeCases = _tc => {
const ydoc = new Y.Doc() const ydoc = new Y.Doc()
const yarray = ydoc.getArray() const yarray = ydoc.getArray()
const subdoc1 = new Y.Doc() const subdoc1 = new Y.Doc()
@ -198,9 +198,9 @@ export const testSubdocLoadEdgeCases = tc => {
} }
/** /**
* @param {t.TestCase} tc * @param {t.TestCase} _tc
*/ */
export const testSubdocLoadEdgeCasesAutoload = tc => { export const testSubdocLoadEdgeCasesAutoload = _tc => {
const ydoc = new Y.Doc() const ydoc = new Y.Doc()
const yarray = ydoc.getArray() const yarray = ydoc.getArray()
const subdoc1 = new Y.Doc({ autoLoad: true }) const subdoc1 = new Y.Doc({ autoLoad: true })
@ -240,9 +240,9 @@ export const testSubdocLoadEdgeCasesAutoload = tc => {
} }
/** /**
* @param {t.TestCase} tc * @param {t.TestCase} _tc
*/ */
export const testSubdocsUndo = tc => { export const testSubdocsUndo = _tc => {
const ydoc = new Y.Doc() const ydoc = new Y.Doc()
const elems = ydoc.getXmlFragment() const elems = ydoc.getXmlFragment()
const undoManager = new Y.UndoManager(elems) const undoManager = new Y.UndoManager(elems)
@ -255,9 +255,9 @@ export const testSubdocsUndo = tc => {
} }
/** /**
* @param {t.TestCase} tc * @param {t.TestCase} _tc
*/ */
export const testLoadDocs = async tc => { export const testLoadDocs = async _tc => {
const ydoc = new Y.Doc() const ydoc = new Y.Doc()
t.assert(ydoc.isLoaded === false) t.assert(ydoc.isLoaded === false)
let loadedEvent = false let loadedEvent = false

View File

@ -455,9 +455,9 @@ export const testChangeEvent = tc => {
} }
/** /**
* @param {t.TestCase} tc * @param {t.TestCase} _tc
*/ */
export const testYmapEventExceptionsShouldCompleteTransaction = tc => { export const testYmapEventExceptionsShouldCompleteTransaction = _tc => {
const doc = new Y.Doc() const doc = new Y.Doc()
const map = doc.getMap('map') const map = doc.getMap('map')