Compare commits

...

10 Commits

Author SHA1 Message Date
cba404b0a2 Fix TS5 compability 2025-03-26 18:58:52 +03:00
Kevin Jahns
34b9343b2e Merge pull request #702 from kapv89/patch-1
Update README.md to add https://github.com/kapv89/k_yrs_go to persistence providers
2025-03-26 12:57:27 +01:00
kapil verma
d5b5e7a9a1 Update README.md to add https://github.com/kapv89/k_yrs_go to persistence providers
Ref: https://x.com/kevin_jahns/status/1904252641124753641
2025-03-26 01:55:02 +05:30
Kevin Jahns
ad0d915794 Merge pull request #701 from hacklschorsch/patch-2
README: Remove duplicate btw mention
2025-03-18 20:18:35 +01:00
Florian Sesser
2ef9ccd170 README: Remove duplicate btw mention
'btw' was mentioned twice; remove one mention.
2025-03-18 19:23:51 +01:00
Kevin Jahns
3ecfb4e898 add rowsncolumns 2025-03-09 20:57:52 +01:00
Kevin Jahns
35c030d834 improve reject update example 2025-03-06 10:36:18 +01:00
Kevin Jahns
e3739bce8e test example for rejecting updates 2025-03-05 14:15:26 +01:00
Kevin Jahns
afa4c35866 update titanic funding information - closes #696 2025-03-05 14:15:12 +01:00
Kevin Jahns
09fbb62ba9 improve documentation on global UndoManager 2025-03-04 14:52:19 +01:00
6 changed files with 85 additions and 27 deletions

View File

@@ -99,7 +99,6 @@ Showcase](https://yjs-diagram.synergy.codes/).
* [AWS SageMaker](https://aws.amazon.com/sagemaker/) Tools for building Machine * [AWS SageMaker](https://aws.amazon.com/sagemaker/) Tools for building Machine
Learning Models Learning Models
* [linear](https://linear.app) Streamline issues, projects, and product roadmaps. * [linear](https://linear.app) Streamline issues, projects, and product roadmaps.
* [btw](https://www.btw.so) - Personal website builder
* [AWS SageMaker](https://aws.amazon.com/sagemaker/) - Machine Learning Service * [AWS SageMaker](https://aws.amazon.com/sagemaker/) - Machine Learning Service
* [Arkiter](https://www.arkiter.com/) - Live interview software * [Arkiter](https://www.arkiter.com/) - Live interview software
* [Appflowy](https://www.appflowy.io/) - They use Yrs * [Appflowy](https://www.appflowy.io/) - They use Yrs
@@ -165,6 +164,7 @@ are implemented in separate modules.
| React / Vue / Svelte / MobX | | [SyncedStore](https://syncedstore.org) | [demo](https://syncedstore.org/docs/react) | | React / Vue / Svelte / MobX | | [SyncedStore](https://syncedstore.org) | [demo](https://syncedstore.org/docs/react) |
| [mobx-keystone](https://mobx-keystone.js.org/) | | [mobx-keystone-yjs](https://github.com/xaviergonz/mobx-keystone/tree/master/packages/mobx-keystone-yjs) | [demo](https://mobx-keystone.js.org/examples/yjs-binding) | | [mobx-keystone](https://mobx-keystone.js.org/) | | [mobx-keystone-yjs](https://github.com/xaviergonz/mobx-keystone/tree/master/packages/mobx-keystone-yjs) | [demo](https://mobx-keystone.js.org/examples/yjs-binding) |
| [PSPDFKit](https://www.nutrient.io/) | | [yjs-pspdfkit](https://github.com/hoangqwe159/yjs-pspdfkit) | [demo](https://github.com/hoangqwe159/yjs-pspdfkit) | | [PSPDFKit](https://www.nutrient.io/) | | [yjs-pspdfkit](https://github.com/hoangqwe159/yjs-pspdfkit) | [demo](https://github.com/hoangqwe159/yjs-pspdfkit) |
| [Rows n'Columns](https://www.rowsncolumns.app/) | ✔ | [@rowsncolumns/y-spreadsheet](https://docs.rowsncolumns.app/collaboration/yjs-collaboration) | |
### Providers ### Providers
@@ -300,6 +300,10 @@ A database and connection provider for Yjs based on Firestore.
Provides persistent storage for a web server using PostgreSQL and Provides persistent storage for a web server using PostgreSQL and
is easily compatible with y-websocket. is easily compatible with y-websocket.
</dd> </dd>
<dt><a href="https://github.com/kapv89/k_yrs_go">k_yrs_go</a></dt>
<dd>
Golang database server for YJS CRDT using Postgres + Redis
</dd>
</dl> </dl>
### Tooling ### Tooling

View File

@@ -34,20 +34,19 @@
] ]
}, },
{ {
"guid": "ystream", "guid": "Titanic",
"name": "Y/Stream", "name": "Y/Titanic",
"description": "A provider for syncing millions of docs efficiently with other peers. This will become the foundation for building real local-first apps with Yjs.", "description": "A provider for syncing millions of docs efficiently with other peers. This will become the foundation for building real local-first apps with Yjs.",
"webpageUrl": { "webpageUrl": {
"url": "https://github.com/yjs/ystream", "url": "https://github.com/yjs/titanic",
"wellKnown": "https://github.com/yjs/ystream/blob/main/.well-known/funding-manifest-urls" "wellKnown": "https://github.com/yjs/titanic/blob/main/.well-known/funding-manifest-urls"
}, },
"repositoryUrl": { "repositoryUrl": {
"url": "https://github.com/yjs/ystream", "url": "https://github.com/yjs/titanic",
"wellKnown": "https://github.com/yjs/ystream/blob/main/.well-known/funding-manifest-urls" "wellKnown": "https://github.com/yjs/titanic/blob/main/.well-known/funding-manifest-urls"
}, },
"licenses": [ "licenses": [
"spdx:MIT", "spdx:MIT"
"spdx:GPL-3.0"
], ],
"tags": [ "tags": [
"privacy", "privacy",
@@ -90,9 +89,9 @@
] ]
}, },
{ {
"guid": "ystream-funding", "guid": "titanic-funding",
"status": "active", "status": "active",
"name": "YStream Funding", "name": "Titanic Funding",
"description": "Fund the next generation of local-first providers.", "description": "Fund the next generation of local-first providers.",
"amount": 30000, "amount": 30000,
"currency": "USD", "currency": "USD",

26
package-lock.json generated
View File

@@ -14,7 +14,7 @@
"devDependencies": { "devDependencies": {
"@rollup/plugin-commonjs": "^24.0.1", "@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-node-resolve": "^15.0.1", "@rollup/plugin-node-resolve": "^15.0.1",
"@types/node": "^18.15.5", "@types/node": "^22.13.13",
"concurrently": "^3.6.1", "concurrently": "^3.6.1",
"http-server": "^0.12.3", "http-server": "^0.12.3",
"jsdoc": "^3.6.7", "jsdoc": "^3.6.7",
@@ -22,7 +22,7 @@
"rollup": "^3.20.0", "rollup": "^3.20.0",
"standard": "^16.0.4", "standard": "^16.0.4",
"tui-jsdoc-template": "^1.2.2", "tui-jsdoc-template": "^1.2.2",
"typescript": "^4.9.5", "typescript": "^5.8.2",
"y-protocols": "^1.0.5" "y-protocols": "^1.0.5"
}, },
"engines": { "engines": {
@@ -356,12 +356,12 @@
"dev": true "dev": true
}, },
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "18.19.15", "version": "22.13.13",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.15.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.13.tgz",
"integrity": "sha512-AMZ2UWx+woHNfM11PyAEQmfSxi05jm9OlkxczuHeEqmvwPkYj6MWv44gbzDPefYOLysTOFyI3ziiy2ONmUZfpA==", "integrity": "sha512-ClsL5nMwKaBRwPcCvH8E7+nU4GxHVx1axNvMZTFHMEfNI7oahimt26P5zjVCRrjiIWj6YFXfE1v3dEp94wLcGQ==",
"dev": true, "dev": true,
"dependencies": { "dependencies": {
"undici-types": "~5.26.4" "undici-types": "~6.20.0"
} }
}, },
"node_modules/@types/resolve": { "node_modules/@types/resolve": {
@@ -4644,16 +4644,16 @@
} }
}, },
"node_modules/typescript": { "node_modules/typescript": {
"version": "4.9.5", "version": "5.8.2",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-4.9.5.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.2.tgz",
"integrity": "sha512-1FXk9E2Hm+QzZQ7z+McJiHL4NW1F2EzMu9Nq9i3zAaGqibafqYwCVU6WyWAuyQRRzOlxou8xZSyXLEN8oKj24g==", "integrity": "sha512-aJn6wq13/afZp/jT9QZmwEjDqqvSGp1VT5GVg+f/t6/oVyrgXM6BY1h9BRh/O5p3PlUPAe+WuiEZOmb/49RqoQ==",
"dev": true, "dev": true,
"bin": { "bin": {
"tsc": "bin/tsc", "tsc": "bin/tsc",
"tsserver": "bin/tsserver" "tsserver": "bin/tsserver"
}, },
"engines": { "engines": {
"node": ">=4.2.0" "node": ">=14.17"
} }
}, },
"node_modules/uc.micro": { "node_modules/uc.micro": {
@@ -4684,9 +4684,9 @@
"dev": true "dev": true
}, },
"node_modules/undici-types": { "node_modules/undici-types": {
"version": "5.26.5", "version": "6.20.0",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.20.0.tgz",
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", "integrity": "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==",
"dev": true "dev": true
}, },
"node_modules/union": { "node_modules/union": {

View File

@@ -81,7 +81,7 @@
"devDependencies": { "devDependencies": {
"@rollup/plugin-commonjs": "^24.0.1", "@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-node-resolve": "^15.0.1", "@rollup/plugin-node-resolve": "^15.0.1",
"@types/node": "^18.15.5", "@types/node": "^22.13.13",
"concurrently": "^3.6.1", "concurrently": "^3.6.1",
"http-server": "^0.12.3", "http-server": "^0.12.3",
"jsdoc": "^3.6.7", "jsdoc": "^3.6.7",
@@ -89,7 +89,7 @@
"rollup": "^3.20.0", "rollup": "^3.20.0",
"standard": "^16.0.4", "standard": "^16.0.4",
"tui-jsdoc-template": "^1.2.2", "tui-jsdoc-template": "^1.2.2",
"typescript": "^4.9.5", "typescript": "^5.8.2",
"y-protocols": "^1.0.5" "y-protocols": "^1.0.5"
}, },
"engines": { "engines": {

View File

@@ -159,7 +159,7 @@ const popStackItem = (undoManager, stack, eventType) => {
*/ */
export class UndoManager extends ObservableV2 { export class UndoManager extends ObservableV2 {
/** /**
* @param {Doc|AbstractType<any>|Array<AbstractType<any>>} typeScope Accepts either a single type, or an array of types * @param {Doc|AbstractType<any>|Array<AbstractType<any>>} typeScope Limits the scope of the UndoManager. If this is set to a ydoc instance, all changes on that ydoc will be undone. If set to a specific type, only changes on that type or its children will be undone. Also accepts an array of types.
* @param {UndoManagerOptions} options * @param {UndoManagerOptions} options
*/ */
constructor (typeScope, { constructor (typeScope, {
@@ -272,6 +272,8 @@ export class UndoManager extends ObservableV2 {
} }
/** /**
* Extend the scope.
*
* @param {Array<AbstractType<any> | Doc> | AbstractType<any> | Doc} ytypes * @param {Array<AbstractType<any> | Doc> | AbstractType<any> | Doc} ytypes
*/ */
addToScope (ytypes) { addToScope (ytypes) {

View File

@@ -116,6 +116,59 @@ export const testEmptyTypeScope = _tc => {
t.assert(yarray.length === 0) t.assert(yarray.length === 0)
} }
/**
* @param {t.TestCase} _tc
*/
export const testRejectUpdateExample = _tc => {
const tmpydoc1 = new Y.Doc()
tmpydoc1.getArray('restricted').insert(0, [1])
tmpydoc1.getArray('public').insert(0, [1])
const update1 = Y.encodeStateAsUpdate(tmpydoc1)
const tmpydoc2 = new Y.Doc()
tmpydoc2.getArray('public').insert(0, [2])
const update2 = Y.encodeStateAsUpdate(tmpydoc2)
const ydoc = new Y.Doc()
const restrictedType = ydoc.getArray('restricted')
/**
* Assume this function handles incoming updates via a communication channel like websockets.
* Changes to the `ydoc.getMap('restricted')` type should be rejected.
*
* - set up undo manager on the restricted types
* - cache pending* updates from the Ydoc to avoid certain attacks
* - apply received update and check whether the restricted type (or any of its children) has been changed.
* - catch errors that might try to circumvent the restrictions
* - undo changes on restricted types
* - reapply pending* updates
*
* @param {Uint8Array} update
*/
const updateHandler = (update) => {
// don't handle changes of the local undo manager, which is used to undo invalid changes
const um = new Y.UndoManager(restrictedType, { trackedOrigins: new Set(['remote change']) })
const beforePendingDs = ydoc.store.pendingDs
const beforePendingStructs = ydoc.store.pendingStructs?.update
try {
Y.applyUpdate(ydoc, update, 'remote change')
} finally {
while (um.undoStack.length) {
um.undo()
}
um.destroy()
ydoc.store.pendingDs = beforePendingDs
ydoc.store.pendingStructs = null
if (beforePendingStructs) {
Y.applyUpdateV2(ydoc, beforePendingStructs)
}
}
}
updateHandler(update1)
updateHandler(update2)
t.assert(restrictedType.length === 0)
t.assert(ydoc.getArray('public').length === 2)
}
/** /**
* Test case to fix #241 * Test case to fix #241
* @param {t.TestCase} _tc * @param {t.TestCase} _tc