Skip to content

Commit

Permalink
bump typescript and fix type issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Jan 31, 2023
1 parent 370d0c1 commit 7f6c12a
Show file tree
Hide file tree
Showing 13 changed files with 972 additions and 615 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* [Hyperquery](https://hyperquery.ai/) A collaborative data workspace for
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

* [Overview](#Overview)
Expand Down
1,472 changes: 907 additions & 565 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"concurrently": "^3.6.1",
"typescript": "^4.9.5",
"http-server": "^0.12.3",
"jsdoc": "^3.6.7",
"markdownlint-cli": "^0.23.2",
"rollup": "^2.60.0",
"standard": "^16.0.4",
"tui-jsdoc-template": "^1.2.2",
"typescript": "^4.4.4",
"y-protocols": "^1.0.5"
}
}
8 changes: 4 additions & 4 deletions src/types/AbstractType.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,9 @@ export class AbstractType {
}

/**
* @param {UpdateEncoderV1 | UpdateEncoderV2} encoder
* @param {UpdateEncoderV1 | UpdateEncoderV2} _encoder
*/
_write (encoder) { }
_write (_encoder) { }

/**
* The first non-deleted item
Expand All @@ -344,9 +344,9 @@ export class AbstractType {
* Must be implemented by each type.
*
* @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) {
this._searchMarker.length = 0
}
Expand Down
21 changes: 15 additions & 6 deletions src/types/YArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ export class YArray extends AbstractType {

/**
* 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
* @return {YArray<T>}
*/
static from (items) {
/**
* @type {YArray<T>}
*/
const a = new YArray()
a.push(items)
return a
Expand All @@ -84,6 +87,9 @@ export class YArray extends AbstractType {
this._prelimContent = null
}

/**
* @return {YArray<T>}
*/
_copy () {
return new YArray()
}
Expand All @@ -92,9 +98,12 @@ export class YArray extends AbstractType {
* @return {YArray<T>}
*/
clone () {
/**
* @type {YArray<T>}
*/
const arr = new YArray()
arr.insert(0, this.toArray().map(el =>
el instanceof AbstractType ? el.clone() : el
el instanceof AbstractType ? /** @type {typeof el} */ (el.clone()) : el
))
return arr
}
Expand Down Expand Up @@ -133,7 +142,7 @@ export class YArray extends AbstractType {
insert (index, content) {
if (this.doc !== null) {
transact(this.doc, transaction => {
typeListInsertGenerics(transaction, this, index, content)
typeListInsertGenerics(transaction, this, index, /** @type {any} */ (content))
})
} else {
/** @type {Array<any>} */ (this._prelimContent).splice(index, 0, ...content)
Expand All @@ -150,7 +159,7 @@ export class YArray extends AbstractType {
push (content) {
if (this.doc !== null) {
transact(this.doc, transaction => {
typeListPushGenerics(transaction, this, content)
typeListPushGenerics(transaction, this, /** @type {any} */ (content))
})
} else {
/** @type {Array<any>} */ (this._prelimContent).push(...content)
Expand Down Expand Up @@ -259,9 +268,9 @@ export class YArray extends AbstractType {
}

/**
* @param {UpdateDecoderV1 | UpdateDecoderV2} decoder
* @param {UpdateDecoderV1 | UpdateDecoderV2} _decoder
*
* @private
* @function
*/
export const readYArray = decoder => new YArray()
export const readYArray = _decoder => new YArray()
16 changes: 11 additions & 5 deletions src/types/YMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ export class YMap extends AbstractType {
this._prelimContent = null
}

/**
* @return {YMap<MapType>}
*/
_copy () {
return new YMap()
}
Expand All @@ -89,9 +92,12 @@ export class YMap extends AbstractType {
* @return {YMap<MapType>}
*/
clone () {
/**
* @type {YMap<MapType>}
*/
const map = new YMap()
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
}
Expand Down Expand Up @@ -207,7 +213,7 @@ export class YMap extends AbstractType {
set (key, value) {
if (this.doc !== null) {
transact(this.doc, transaction => {
typeMapSet(transaction, this, key, value)
typeMapSet(transaction, this, key, /** @type {any} */ (value))
})
} else {
/** @type {Map<string, any>} */ (this._prelimContent).set(key, value)
Expand Down Expand Up @@ -241,7 +247,7 @@ export class YMap extends AbstractType {
clear () {
if (this.doc !== null) {
transact(this.doc, transaction => {
this.forEach(function (value, key, map) {
this.forEach(function (_value, key, map) {
typeMapDelete(transaction, map, key)
})
})
Expand All @@ -259,9 +265,9 @@ export class YMap extends AbstractType {
}

/**
* @param {UpdateDecoderV1 | UpdateDecoderV2} decoder
* @param {UpdateDecoderV1 | UpdateDecoderV2} _decoder
*
* @private
* @function
*/
export const readYMap = decoder => new YMap()
export const readYMap = _decoder => new YMap()
11 changes: 5 additions & 6 deletions src/types/YText.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ const insertAttributes = (transaction, parent, currPos, attributes) => {
* @function
**/
const insertText = (transaction, parent, currPos, text, attributes) => {
currPos.currentAttributes.forEach((val, key) => {
currPos.currentAttributes.forEach((_val, key) => {
if (attributes[key] === undefined) {
attributes[key] = null
}
Expand Down Expand Up @@ -927,7 +927,7 @@ export class YText extends AbstractType {
* Apply a {@link Delta} on this shared YText type.
*
* @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.
*
*
Expand Down Expand Up @@ -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.
*
* @param {Snapshot} [snapshot]
* @return {Object<string, any>} A JSON Object that describes the attributes.
*
* @public
*/
getAttributes (snapshot) {
getAttributes () {
return typeMapGetAll(this)
}

Expand All @@ -1247,10 +1246,10 @@ export class YText extends AbstractType {
}

/**
* @param {UpdateDecoderV1 | UpdateDecoderV2} decoder
* @param {UpdateDecoderV1 | UpdateDecoderV2} _decoder
* @return {YText}
*
* @private
* @function
*/
export const readYText = decoder => new YText()
export const readYText = _decoder => new YText()
2 changes: 1 addition & 1 deletion src/types/YXmlElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
typeMapGetAll,
typeListForEach,
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'

/**
Expand Down
8 changes: 4 additions & 4 deletions src/types/YXmlFragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
transact,
typeListGet,
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'

import * as error from 'lib0/error'
Expand Down Expand Up @@ -407,7 +407,7 @@ export class YXmlFragment extends AbstractType {
/**
* 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) {
typeListForEach(this, f)
Expand All @@ -427,10 +427,10 @@ export class YXmlFragment extends AbstractType {
}

/**
* @param {UpdateDecoderV1 | UpdateDecoderV2} decoder
* @param {UpdateDecoderV1 | UpdateDecoderV2} _decoder
* @return {YXmlFragment}
*
* @private
* @function
*/
export const readYXmlFragment = decoder => new YXmlFragment()
export const readYXmlFragment = _decoder => new YXmlFragment()
2 changes: 1 addition & 1 deletion src/utils/Doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const generateNewClientId = random.uint32
*/
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 } = {}) {
super()
Expand Down
4 changes: 2 additions & 2 deletions src/utils/PermanentUserData.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class PermanentUserData {
* @param {Doc} doc
* @param {number} clientid
* @param {string} userDescription
* @param {Object} [conf]
* @param {Object} conf
* @param {function(Transaction, DeleteSet):boolean} [conf.filter]
*/
setUserMapping (doc, clientid, userDescription, { filter = () => true } = {}) {
Expand All @@ -84,7 +84,7 @@ export class PermanentUserData {
users.set(userDescription, user)
}
user.get('ids').push([clientid])
users.observe(event => {
users.observe(_event => {
setTimeout(() => {
const userOverwrite = users.get(userDescription)
if (userOverwrite !== user) {
Expand Down
32 changes: 16 additions & 16 deletions tests/doc.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* @param {t.TestCase} tc
* @param {t.TestCase} _tc
*/
export const testClientIdDuplicateChange = tc => {
export const testClientIdDuplicateChange = _tc => {
const doc1 = new Y.Doc()
doc1.clientID = 0
const doc2 = new Y.Doc()
Expand All @@ -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()
doc1.getText('').insert(0, 'h')
doc1.getText().insert(1, 'i')
Expand All @@ -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()
t.compare(doc.toJSON(), {}, 'doc.toJSON yields empty object')

Expand All @@ -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()
doc.load() // doesn't do anything
{
Expand Down Expand Up @@ -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 yarray = ydoc.getArray()
const subdoc1 = new Y.Doc()
Expand Down Expand Up @@ -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 yarray = ydoc.getArray()
const subdoc1 = new Y.Doc({ autoLoad: true })
Expand Down Expand Up @@ -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 elems = ydoc.getXmlFragment()
const undoManager = new Y.UndoManager(elems)
Expand All @@ -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()
t.assert(ydoc.isLoaded === false)
let loadedEvent = false
Expand Down
4 changes: 2 additions & 2 deletions tests/y-map.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 map = doc.getMap('map')

Expand Down

0 comments on commit 7f6c12a

Please sign in to comment.