From dacef7dfdbb5df2d81f1ef81469940f008a4f18c Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 4 Mar 2024 14:35:31 +0100 Subject: [PATCH 1/7] =?UTF-8?q?refactor(json-crdt-extensions):=20?= =?UTF-8?q?=F0=9F=92=A1=20rename=20MV-Register=20folder=20to=20/mval?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/json-crdt-extensions/{mv-value => mval}/ValueMv.ts | 0 src/json-crdt-extensions/{mv-value => mval}/ValueMvApi.ts | 0 .../{mv-value => mval}/__tests__/ValueMv.spec.ts | 0 .../{mv-value => mval}/__tests__/extension.spec.ts | 0 src/json-crdt-extensions/{mv-value => mval}/index.ts | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename src/json-crdt-extensions/{mv-value => mval}/ValueMv.ts (100%) rename src/json-crdt-extensions/{mv-value => mval}/ValueMvApi.ts (100%) rename src/json-crdt-extensions/{mv-value => mval}/__tests__/ValueMv.spec.ts (100%) rename src/json-crdt-extensions/{mv-value => mval}/__tests__/extension.spec.ts (100%) rename src/json-crdt-extensions/{mv-value => mval}/index.ts (100%) diff --git a/src/json-crdt-extensions/mv-value/ValueMv.ts b/src/json-crdt-extensions/mval/ValueMv.ts similarity index 100% rename from src/json-crdt-extensions/mv-value/ValueMv.ts rename to src/json-crdt-extensions/mval/ValueMv.ts diff --git a/src/json-crdt-extensions/mv-value/ValueMvApi.ts b/src/json-crdt-extensions/mval/ValueMvApi.ts similarity index 100% rename from src/json-crdt-extensions/mv-value/ValueMvApi.ts rename to src/json-crdt-extensions/mval/ValueMvApi.ts diff --git a/src/json-crdt-extensions/mv-value/__tests__/ValueMv.spec.ts b/src/json-crdt-extensions/mval/__tests__/ValueMv.spec.ts similarity index 100% rename from src/json-crdt-extensions/mv-value/__tests__/ValueMv.spec.ts rename to src/json-crdt-extensions/mval/__tests__/ValueMv.spec.ts diff --git a/src/json-crdt-extensions/mv-value/__tests__/extension.spec.ts b/src/json-crdt-extensions/mval/__tests__/extension.spec.ts similarity index 100% rename from src/json-crdt-extensions/mv-value/__tests__/extension.spec.ts rename to src/json-crdt-extensions/mval/__tests__/extension.spec.ts diff --git a/src/json-crdt-extensions/mv-value/index.ts b/src/json-crdt-extensions/mval/index.ts similarity index 100% rename from src/json-crdt-extensions/mv-value/index.ts rename to src/json-crdt-extensions/mval/index.ts From a39817f96fa0ec8d9d2673ac8c873b8330738eef Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 4 Mar 2024 14:55:56 +0100 Subject: [PATCH 2/7] =?UTF-8?q?feat(json-crdt-extensions):=20=F0=9F=8E=B8?= =?UTF-8?q?=20add=20ability=20to=20specify=20extension=20definition=20name?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/json-crdt-extensions/constants.ts | 2 +- src/json-crdt-extensions/mval/__tests__/extension.spec.ts | 4 ++++ src/json-crdt-extensions/mval/index.ts | 5 +++-- src/json-crdt/extensions/Extensions.ts | 2 +- src/json-crdt/extensions/types.ts | 1 + 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/json-crdt-extensions/constants.ts b/src/json-crdt-extensions/constants.ts index 7b3d08040d..7996350a3b 100644 --- a/src/json-crdt-extensions/constants.ts +++ b/src/json-crdt-extensions/constants.ts @@ -1,5 +1,5 @@ export const enum ExtensionId { - MvValue = 0, + mval = 0, Peritext = 1, QuillDelta = 2, } diff --git a/src/json-crdt-extensions/mval/__tests__/extension.spec.ts b/src/json-crdt-extensions/mval/__tests__/extension.spec.ts index 5134bd77f9..054f003820 100644 --- a/src/json-crdt-extensions/mval/__tests__/extension.spec.ts +++ b/src/json-crdt-extensions/mval/__tests__/extension.spec.ts @@ -2,6 +2,10 @@ import {ValueMvExt} from '..'; import {konst} from '../../../json-crdt-patch/builder/Konst'; import {Model} from '../../../json-crdt/model'; +test('can specify extension name', () => { + expect(ValueMvExt.name).toBe('mval'); +}); + test('can create a new multi-value register', () => { const model = Model.withLogicalClock(); model.ext.register(ValueMvExt); diff --git a/src/json-crdt-extensions/mval/index.ts b/src/json-crdt-extensions/mval/index.ts index c955ea04ce..5e1c7a074e 100644 --- a/src/json-crdt-extensions/mval/index.ts +++ b/src/json-crdt-extensions/mval/index.ts @@ -8,10 +8,11 @@ import type {ArrNode} from '../../json-crdt/nodes/arr/ArrNode'; import type {ExtensionDefinition} from '../../json-crdt'; export const ValueMvExt: ExtensionDefinition = { - id: ExtensionId.MvValue, + id: ExtensionId.mval, + name: 'mval', new: (value: unknown | ITimestampStruct) => ext( - ExtensionId.MvValue, + ExtensionId.mval, delayed((builder) => builder.jsonArr([value])), ), Node: ValueMv, diff --git a/src/json-crdt/extensions/Extensions.ts b/src/json-crdt/extensions/Extensions.ts index 7745bc10f1..e3fd7e4ebb 100644 --- a/src/json-crdt/extensions/Extensions.ts +++ b/src/json-crdt/extensions/Extensions.ts @@ -31,7 +31,7 @@ export class Extensions implements Printable { this.constructor.name + printTree( tab, - keys.map((k) => (tab) => `${k}: ${this.ext[k].Node.name}`), + keys.map((k) => (tab) => `${k}: ${this.ext[k].name}`), ) ); } diff --git a/src/json-crdt/extensions/types.ts b/src/json-crdt/extensions/types.ts index 270966b3a9..182d4222a8 100644 --- a/src/json-crdt/extensions/types.ts +++ b/src/json-crdt/extensions/types.ts @@ -15,6 +15,7 @@ export interface ExtensionDefinition< EApi extends ExtensionApi = ExtensionApi, > { id: number; + name: string; new: (...args: any[]) => NodeBuilder; Node: new (data: Node) => ENode; Api: new (node: ENode, api: ModelApi) => EApi; From 953108ca5168efb4b2b15f58d55b4477a8ea6677 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 4 Mar 2024 15:25:20 +0100 Subject: [PATCH 3/7] =?UTF-8?q?feat(json-crdt-extensions):=20=F0=9F=8E=B8?= =?UTF-8?q?=20display=20mval=20extension=20name=20on=20print?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/json-crdt-extensions/mval/ValueMv.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/json-crdt-extensions/mval/ValueMv.ts b/src/json-crdt-extensions/mval/ValueMv.ts index 06d1567d40..d88af29160 100644 --- a/src/json-crdt-extensions/mval/ValueMv.ts +++ b/src/json-crdt-extensions/mval/ValueMv.ts @@ -36,6 +36,6 @@ export class ValueMv implements ExtensionJsonNode, Printable { // ---------------------------------------------------------------- Printable public toString(tab?: string): string { - return this.constructor.name + printTree(tab, [(tab) => this.data.toString(tab)]); + return this.name() + printTree(tab, [(tab) => this.data.toString(tab)]); } } From 0c600f94a806e65736e8cc96eca23c4f9d4753a9 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 4 Mar 2024 15:33:37 +0100 Subject: [PATCH 4/7] =?UTF-8?q?docs(json-crdt-extensions):=20=E2=9C=8F?= =?UTF-8?q?=EF=B8=8F=20add=20MV-Register=20demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mval/__demos__/usage.ts | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/json-crdt-extensions/mval/__demos__/usage.ts diff --git a/src/json-crdt-extensions/mval/__demos__/usage.ts b/src/json-crdt-extensions/mval/__demos__/usage.ts new file mode 100644 index 0000000000..938954a693 --- /dev/null +++ b/src/json-crdt-extensions/mval/__demos__/usage.ts @@ -0,0 +1,44 @@ +/* tslint:disable no-console */ + +/** + * Run this demo with: + * + * npx nodemon -q -x ts-node src/json-crdt-extensions/mval/__demos__/usage.ts + */ + +import {Model} from '../../../json-crdt'; +import {ValueMvExt} from '..'; + +console.clear(); + +const model = Model.withLogicalClock(1234); + +model.ext.register(ValueMvExt) + +model.api.root({ + mv: ValueMvExt.new(1), +}); + +console.log(''); +console.log('Initial value:'); +console.log(model + ''); + +const api = model.api.in('mv').asExt(ValueMvExt); + +api.set(5); + +console.log(''); +console.log('After update:'); +console.log(model + ''); + +const model2 = model.fork(); + +const api2 = model2.api.in('mv').asExt(ValueMvExt); + +api.set(10); +api2.set(20); +model.applyPatch(model2.api.flush()); + +console.log(''); +console.log('After two users update concurrently:'); +console.log(model + ''); From 0a01ade3bc20a2753b15f1b74aa9f00cffbfe3d1 Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 4 Mar 2024 15:37:31 +0100 Subject: [PATCH 5/7] =?UTF-8?q?docs(json-crdt-extensions):=20=E2=9C=8F?= =?UTF-8?q?=EF=B8=8F=20update=20MV-Register=20demo=20to=20use=20deeper=20o?= =?UTF-8?q?bject?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/json-crdt-extensions/mval/__demos__/usage.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/json-crdt-extensions/mval/__demos__/usage.ts b/src/json-crdt-extensions/mval/__demos__/usage.ts index 938954a693..99e85e6768 100644 --- a/src/json-crdt-extensions/mval/__demos__/usage.ts +++ b/src/json-crdt-extensions/mval/__demos__/usage.ts @@ -16,14 +16,16 @@ const model = Model.withLogicalClock(1234); model.ext.register(ValueMvExt) model.api.root({ - mv: ValueMvExt.new(1), + obj: { + mv: ValueMvExt.new(1), + }, }); console.log(''); console.log('Initial value:'); console.log(model + ''); -const api = model.api.in('mv').asExt(ValueMvExt); +const api = model.api.in(['obj', 'mv']).asExt(ValueMvExt); api.set(5); @@ -33,7 +35,7 @@ console.log(model + ''); const model2 = model.fork(); -const api2 = model2.api.in('mv').asExt(ValueMvExt); +const api2 = model2.api.in(['obj', 'mv']).asExt(ValueMvExt); api.set(10); api2.set(20); From 990dc92efd9d38650ef894302b6a75d66631699d Mon Sep 17 00:00:00 2001 From: streamich Date: Mon, 4 Mar 2024 15:51:03 +0100 Subject: [PATCH 6/7] =?UTF-8?q?fix(json-crdt-extensions):=20=F0=9F=90=9B?= =?UTF-8?q?=20allow=20any=20value=20in=20MV-Register?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/json-crdt-extensions/mval/ValueMvApi.ts | 2 +- src/json-crdt-extensions/mval/__demos__/usage.ts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/json-crdt-extensions/mval/ValueMvApi.ts b/src/json-crdt-extensions/mval/ValueMvApi.ts index ff239d1110..bf145a97fe 100644 --- a/src/json-crdt-extensions/mval/ValueMvApi.ts +++ b/src/json-crdt-extensions/mval/ValueMvApi.ts @@ -9,7 +9,7 @@ export class ValueMvApi extends NodeApi implements ExtensionApi Date: Mon, 4 Mar 2024 19:26:01 +0100 Subject: [PATCH 7/7] =?UTF-8?q?style(json-crdt-extensions):=20=F0=9F=92=84?= =?UTF-8?q?=20run=20Prettier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/json-crdt-extensions/mval/__demos__/usage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/json-crdt-extensions/mval/__demos__/usage.ts b/src/json-crdt-extensions/mval/__demos__/usage.ts index 10f2a4650a..638c5814d7 100644 --- a/src/json-crdt-extensions/mval/__demos__/usage.ts +++ b/src/json-crdt-extensions/mval/__demos__/usage.ts @@ -13,7 +13,7 @@ console.clear(); const model = Model.withLogicalClock(1234); -model.ext.register(ValueMvExt) +model.ext.register(ValueMvExt); model.api.root({ obj: {