From f8a507f1c532f0fdd7957fa533415f25b0ffc731 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 29 Jul 2024 11:37:45 +0200 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20bump=20upstream=20de?= =?UTF-8?q?pendencies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 12 ++++++------ yarn.lock | 28 +++++++++++++++++++--------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 89993b8bf7..f7384779ec 100644 --- a/package.json +++ b/package.json @@ -124,14 +124,14 @@ } }, "dependencies": { - "@jsonjoy.com/base64": "^1.1.1", - "@jsonjoy.com/json-pack": "^1.0.2", - "@jsonjoy.com/util": "^1.1.0", + "@jsonjoy.com/base64": "^1.1.2", + "@jsonjoy.com/json-pack": "^1.0.4", + "@jsonjoy.com/util": "^1.3.0", "arg": "^5.0.2", "hyperdyperid": "^1.2.0", - "sonic-forest": "^1.0.2", - "thingies": "^2.0.0", - "tree-dump": "^1.0.1" + "sonic-forest": "^1.0.3", + "thingies": "^2.1.1", + "tree-dump": "^1.0.2" }, "devDependencies": { "@types/benchmark": "^2.1.5", diff --git a/yarn.lock b/yarn.lock index ef5a0b6ec4..5e90d75649 100644 --- a/yarn.lock +++ b/yarn.lock @@ -556,12 +556,12 @@ "@jridgewell/resolve-uri" "^3.1.0" "@jridgewell/sourcemap-codec" "^1.4.14" -"@jsonjoy.com/base64@^1.1.1": +"@jsonjoy.com/base64@^1.1.1", "@jsonjoy.com/base64@^1.1.2": version "1.1.2" resolved "https://registry.yarnpkg.com/@jsonjoy.com/base64/-/base64-1.1.2.tgz#cf8ea9dcb849b81c95f14fc0aaa151c6b54d2578" integrity sha512-q6XAnWQDIMA3+FTiOYajoYqySkO+JSat0ytXGSuRdq9uXE7o92gzuQwQM14xaCRlBLGq3v5miDGC4vkVTn54xA== -"@jsonjoy.com/json-pack@^1.0.2": +"@jsonjoy.com/json-pack@^1.0.4": version "1.0.4" resolved "https://registry.yarnpkg.com/@jsonjoy.com/json-pack/-/json-pack-1.0.4.tgz#ab59c642a2e5368e8bcfd815d817143d4f3035d0" integrity sha512-aOcSN4MeAtFROysrbqG137b7gaDDSmVrl5mpo6sT/w+kcXpWnzhMjmY/Fh/sDx26NBxyIE7MB1seqLeCAzy9Sg== @@ -571,11 +571,16 @@ hyperdyperid "^1.2.0" thingies "^1.20.0" -"@jsonjoy.com/util@^1.1.0", "@jsonjoy.com/util@^1.1.2": +"@jsonjoy.com/util@^1.1.2": version "1.1.3" resolved "https://registry.yarnpkg.com/@jsonjoy.com/util/-/util-1.1.3.tgz#75b1c3cf21b70e665789d1ad3eabeff8b7fd1429" integrity sha512-g//kkF4kOwUjemValCtOc/xiYzmwMRmWq3Bn+YnzOzuZLHq2PpMOxxIayN3cKbo7Ko2Np65t6D9H81IvXbXhqg== +"@jsonjoy.com/util@^1.3.0": + version "1.3.0" + resolved "https://registry.yarnpkg.com/@jsonjoy.com/util/-/util-1.3.0.tgz#e5623885bb5e0c48c1151e4dae422fb03a5887a1" + integrity sha512-Cebt4Vk7k1xHy87kHY7KSPLT77A7Ev7IfOblyLZhtYEhrdQ6fX4EoLq3xOQ3O/DRMEh2ok5nyC180E+ABS8Wmw== + "@sinclair/typebox@^0.27.8": version "0.27.8" resolved "https://registry.yarnpkg.com/@sinclair/typebox/-/typebox-0.27.8.tgz#6667fac16c436b5434a387a34dedb013198f6e6e" @@ -2150,7 +2155,7 @@ slash@^3.0.0: resolved "https://registry.yarnpkg.com/slash/-/slash-3.0.0.tgz#6539be870c165adbd5240220dbe361f1bc4d4634" integrity sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q== -sonic-forest@^1.0.2: +sonic-forest@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/sonic-forest/-/sonic-forest-1.0.3.tgz#81363af60017daba39b794fce24627dc412563cb" integrity sha512-dtwajos6IWMEWXdEbW1IkEkyL2gztCAgDplRIX+OT5aRKnEd5e7r7YCxRgXZdhRP1FBdOBf8axeTPhzDv8T4wQ== @@ -2261,10 +2266,10 @@ thingies@^1.20.0: resolved "https://registry.yarnpkg.com/thingies/-/thingies-1.21.0.tgz#e80fbe58fd6fdaaab8fad9b67bd0a5c943c445c1" integrity sha512-hsqsJsFMsV+aD4s3CWKk85ep/3I9XzYV/IXaSouJMYIoDlgyi11cBhsqYe9/geRfB0YIikBQg6raRaM+nIMP9g== -thingies@^2.0.0: - version "2.1.0" - resolved "https://registry.yarnpkg.com/thingies/-/thingies-2.1.0.tgz#e0f771d5bc42e147fe9518be48f667319e748e25" - integrity sha512-SASxQdAtapX03qTa1V/kt9UGhQLUoP54luRasJxZoleeAL+PSQsBlIAGNxj1FoayglyCGUhxByFgSn7dh2JFog== +thingies@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/thingies/-/thingies-2.1.1.tgz#f7e3902f41d4f8fda6fdf1a47bab0b77b70fcadd" + integrity sha512-0ad16gExX2JBMPXmBQfKOUz7R1KNWAtiY6hjesug4WdV3uV/Qmm/NAu49uQvzV/f3XkMztjq+ncyMoYLPoppVQ== tmpl@1.0.5: version "1.0.5" @@ -2283,11 +2288,16 @@ to-regex-range@^5.0.1: dependencies: is-number "^7.0.0" -tree-dump@^1.0.0, tree-dump@^1.0.1: +tree-dump@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/tree-dump/-/tree-dump-1.0.1.tgz#b448758da7495580e6b7830d6b7834fca4c45b96" integrity sha512-WCkcRBVPSlHHq1dc/px9iOfqklvzCbdRwvlNfxGZsrHqf6aZttfPrd7DJTt6oR10dwUfpFFQeVTkPbBIZxX/YA== +tree-dump@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/tree-dump/-/tree-dump-1.0.2.tgz#c460d5921caeb197bde71d0e9a7b479848c5b8ac" + integrity sha512-dpev9ABuLWdEubk+cIaI9cHwRNNDjkBBLXTwI4UCUFdQ5xXKqNXoK4FEciw/vxf+NQ7Cb7sGUyeUtORvHIdRXQ== + ts-jest@^29.1.2: version "29.1.5" resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.1.5.tgz#d6c0471cc78bffa2cb4664a0a6741ef36cfe8f69" From e62efef8c60b4a971e2558eabbed1a1d785f132f Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 29 Jul 2024 11:38:51 +0200 Subject: [PATCH 2/3] =?UTF-8?q?chore:=20=F0=9F=A4=96=20remove=20unused=20c?= =?UTF-8?q?ode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/json-block/Block.ts | 114 ---------------------------------------- src/json-block/types.ts | 43 --------------- 2 files changed, 157 deletions(-) delete mode 100644 src/json-block/Block.ts delete mode 100644 src/json-block/types.ts diff --git a/src/json-block/Block.ts b/src/json-block/Block.ts deleted file mode 100644 index 562247ba21..0000000000 --- a/src/json-block/Block.ts +++ /dev/null @@ -1,114 +0,0 @@ -import {BehaviorSubject, Observable, of} from 'rxjs'; -import {switchMap} from 'rxjs/operators'; - -/** - * A unified interface which various collaborative editing approaches - * (CRDT with vector clock, CRDT with server clock, OT, client-only OT, - * simple patch, etc.) need to implement. - */ -export interface BlockModel { - /** Unique ID of this block. */ - // id: string; - /** Get latest data of this block. */ - getData(): Data; - /** Create an independent copy of this block. */ - fork(): BlockModel; - /** Apply a single patch of changes. */ - apply(patch: Patch): void; -} - -export class BasicBlock { - public v$: BehaviorSubject; - - constructor( - version: number, - public readonly model: BlockModel, - ) { - this.v$ = new BehaviorSubject(version); - } - - public fork(): BasicBlock { - return new BasicBlock(this.v$.getValue(), this.model.fork()); - } - - /** - * Observable of the latest data value of this block. It is wrapped in - * a function to allow for lazy evaluation. - */ - public data$(): Observable { - return this.v$.pipe(switchMap(() => of(this.model.getData()))); - } - - /** Get the latest value of the block. */ - public getData(): Data { - return this.model.getData(); - } - - public apply(patch: Patch): void { - this.model.apply(patch); - this.v$.next(this.v$.getValue()); - } -} - -export type PatchResponse = true | false | Patch; - -export interface BranchMergeResponse { - version: number; - batches: PatchResponse[][]; -} - -export class Branch { - /** The last known confirmed value on the server. */ - protected readonly base$: BehaviorSubject>; - - /** Block value including all latest changes optimistically applied on the client. */ - protected readonly head$: BehaviorSubject>; - - /** - * List of patches applied locally to the head, but not yet - * added to the `batches` list. - */ - protected patches: Patch[]; - - /** List of batches to be persisted on the server. */ - protected batches: Patch[][] = []; - - constructor(base: BasicBlock) { - this.base$ = new BehaviorSubject(base); - this.patches = []; - this.head$ = new BehaviorSubject(base.fork()); - } - - public cutBatch(): void { - this.batches.push(this.patches); - this.patches = []; - } - - /** Apply a patch locally to the head. */ - public commit(patch: Patch): void { - this.patches.push(patch); - this.head$.getValue().apply(patch); - } - - /** - * Advance the base to the latest known value from the server and - * re-apply all local patches, after optional transformation. - */ - public rebase(patches: Patch[]): void { - const base = this.base$.getValue(); - for (const patch of patches) base.apply(patch); - const head = base.fork(); - // TODO: apply operation transformations here. - for (const patch of this.patches) head.apply(patch); - this.head$.next(head); - } - - /** Set new base and reset all local changes. Returns local changes. */ - public reset(base: BasicBlock): Patch[] { - this.base$.next(base); - const patches = this.patches; - this.patches = []; - this.head$.next(base.fork()); - return patches; - } -} diff --git a/src/json-block/types.ts b/src/json-block/types.ts deleted file mode 100644 index 56242253af..0000000000 --- a/src/json-block/types.ts +++ /dev/null @@ -1,43 +0,0 @@ -import type {Observable} from 'rxjs'; - -export interface BlockServerApi { - create: () => Promise; - merge: (req: BlockClientApiMergeRequest) => Promise; - delete: () => Promise; - listen: () => Observable; -} - -export interface BlockClientApiMergeRequest { - /** Last known batch ID by the client. */ - v: number; - /** List of patches serialized in block-specific codec. */ - b: unknown[]; -} - -/** - * There are a number of scenarios that can happen - * when merging changes. The possible scenarios also depend - * on the collaborative editing algorithm used for the block. - * - * 1. The batch is accepted without any conflicts (changes). - * 2. The batch is accepted with conflicts, hence the batch may be - * be modified to resolve the conflicts. This is relevant for - * OT-based collaborative editing. - * 1. Some patches may still be accepted as-is. - * 2. Some patches may have been transformed. - * 1. Could be meaningful changes, or no-nop changes, for example, - * the predicate operations in JSON Patch, like the "test" operation. - * 3. Some patches may have been rejected. - * 3. The batch is rejected altogether. This can happen for - * various reasons: - * 1. In case of OT-based collaborative editing, the last - * known version of a batch by the client is too far behind. - * 2. Some other reason why the batch is rejected, say schema - * validation. - */ -export interface BlockClientApiMergeResponse { - /** The last batch ID stored on the server. */ - v: number; - /** List of patches serialized in block-specific codec. */ - batch: unknown[]; -} From 6eadb9a4e3a1f7ecddfcca565df16d41f900350b Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 29 Jul 2024 11:43:34 +0200 Subject: [PATCH 3/3] =?UTF-8?q?chore:=20=F0=9F=A4=96=20move=20json-joy=20d?= =?UTF-8?q?ependencies=20to=20peerDependencies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index f7384779ec..66ed8d002c 100644 --- a/package.json +++ b/package.json @@ -116,7 +116,10 @@ }, "peerDependencies": { "rxjs": "7", - "tslib": "2" + "tslib": "2", + "@jsonjoy.com/base64": "^1.1.2", + "@jsonjoy.com/json-pack": "^1.0.4", + "@jsonjoy.com/util": "^1.3.0" }, "peerDependenciesMeta": { "rxjs": { @@ -124,9 +127,6 @@ } }, "dependencies": { - "@jsonjoy.com/base64": "^1.1.2", - "@jsonjoy.com/json-pack": "^1.0.4", - "@jsonjoy.com/util": "^1.3.0", "arg": "^5.0.2", "hyperdyperid": "^1.2.0", "sonic-forest": "^1.0.3", @@ -134,6 +134,9 @@ "tree-dump": "^1.0.2" }, "devDependencies": { + "@jsonjoy.com/base64": "^1.1.2", + "@jsonjoy.com/json-pack": "^1.0.4", + "@jsonjoy.com/util": "^1.3.0", "@types/benchmark": "^2.1.5", "@types/jest": "^29.5.12", "benchmark": "^2.1.4",