@pluv/crdt 0.18.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,18 +1,18 @@
1
1
 
2
- > @pluv/crdt@0.18.0 build /home/runner/work/pluv/pluv/packages/crdt
2
+ > @pluv/crdt@0.20.0 build /home/runner/work/pluv/pluv/packages/crdt
3
3
  > tsup src/index.ts --format esm,cjs --dts
4
4
 
5
- CLI Building entry: src/index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v8.0.2
8
- CLI Target: es6
9
- ESM Build start
10
- CJS Build start
11
- ESM dist/index.mjs 1.34 KB
12
- ESM ⚡️ Build success in 27ms
13
- CJS dist/index.js 2.54 KB
14
- CJS ⚡️ Build success in 27ms
15
- DTS Build start
16
- DTS ⚡️ Build success in 596ms
17
- DTS dist/index.d.mts 3.31 KB
18
- DTS dist/index.d.ts 3.31 KB
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v8.1.0
8
+ CLI Target: es6
9
+ ESM Build start
10
+ CJS Build start
11
+ ESM dist/index.mjs 1.26 KB
12
+ ESM ⚡️ Build success in 22ms
13
+ CJS dist/index.js 2.42 KB
14
+ CJS ⚡️ Build success in 23ms
15
+ DTS Build start
16
+ DTS ⚡️ Build success in 500ms
17
+ DTS dist/index.d.mts 3.22 KB
18
+ DTS dist/index.d.ts 3.22 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,86 @@
1
1
  # @pluv/crdt
2
2
 
3
+ ## 0.20.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 9492085: **BREAKING**: `@pluv/crdt-yjs` and `@pluv/crdt-loro` have been updated so that the utilities to create shared-types/containers no-longer return a wrapper around the underlying shared-types and containers, but rather return the shared-types/containers directly.
8
+
9
+ This means that for methods such as `getStorage` from `@pluv/client` and `useStorage` from `@pluv/react`, the shared-types/containers are also returned instead of the wrapper types.
10
+
11
+ The motivation for these changes are so that pluv.io is supplementary to `yjs` and `loro-crdt`, instead of having these libraries be an internal implementation of pluv.io.
12
+
13
+ ```ts
14
+ // Before
15
+
16
+ import { yjs } from "@pluv/crdt-yjs";
17
+
18
+ yjs.array([]); // Returns CrdtYjsArray
19
+ yjs.object([]); // Returns CrdtYjsObject
20
+
21
+ const room: PluvRoom = /* ... */;
22
+
23
+ room.getStorage("messages"); // Returns AbstractCrdtType
24
+
25
+ const [, sharedType] = useStorage("messages"); // sharedType is an AbstractCrdtType
26
+ ```
27
+
28
+ ```ts
29
+ // Now
30
+
31
+ import { yjs } from "@pluv/crdt-yjs";
32
+
33
+ yjs.array([]); // Returns yjs.Array
34
+ yjs.object([]); // Returns yjs.Map
35
+
36
+ const room: PluvRoom = /* ... */;
37
+
38
+ room.getStorage("messages"); // Returns yjs.AbstractType
39
+
40
+ const [, sharedType] = useStorage("messages"); // sharedType is a yjs.AbstractType
41
+ ```
42
+
43
+ For `@pluv/crdt-loro` specifically, `@pluv/client` relies on [loro events and subscriptions](https://www.loro.dev/docs/tutorial/get_started#event) to detect changes. The `AbstractLoroCrdt` types previously called `Loro.commit` after each change as an abstraction, but now this no-longer happens. To ensure that changes to loro containers are properly handled in `@pluv/react`, make sure to commit your changes whenever possible:
44
+
45
+ ```ts
46
+ // Before
47
+
48
+ const [data, container] = useStorage("messages");
49
+
50
+ // This automatically called Loro.commit under the hood and rerendered the page with updated data.
51
+ container.push(loro.object({ name: "John Doe", age: 35 }));
52
+ ```
53
+
54
+ ```ts
55
+ // Now
56
+
57
+ const [data, container] = useStorage("messages");
58
+
59
+ const doc = useDoc();
60
+ const transact = useTransact();
61
+
62
+ // Updates need to be committed back to the doc whenever the changes need to be emitted to other users
63
+ // The returned data also will not update until the changes are commited
64
+
65
+ // The two operations below are functionally equivalent
66
+ transact(() => {
67
+ container.push(loro.object({ name: "John Doe", age: 35 }));
68
+ });
69
+
70
+ container.push(loro.object({ name: "John Doe", age: 35 }));
71
+ doc.value.commit();
72
+ ```
73
+
74
+ ### Patch Changes
75
+
76
+ - @pluv/types@0.20.0
77
+
78
+ ## 0.19.0
79
+
80
+ ### Patch Changes
81
+
82
+ - @pluv/types@0.19.0
83
+
3
84
  ## 0.18.0
4
85
 
5
86
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -1,25 +1,23 @@
1
1
  import { Json } from '@pluv/types';
2
2
 
3
- type InferCrdtStorageJson<T extends unknown> = T extends AbstractCrdtType<any, infer ICrdtJson> ? InferCrdtStorageJson<ICrdtJson> : T extends Record<string, any> ? {
4
- [P in keyof T]: InferCrdtStorageJson<T[P]>;
5
- } : T extends (infer IArrayCrdtItem)[] ? InferCrdtStorageJson<IArrayCrdtItem>[] : T extends readonly (infer IReadonlyArrayCrdtItem)[] ? InferCrdtStorageJson<IReadonlyArrayCrdtItem> : T extends Json ? T : string;
6
-
7
- declare abstract class AbstractCrdtType<TValue extends unknown, TJson extends unknown> {
8
- abstract value: TValue;
9
- abstract toJson(): InferCrdtStorageJson<TJson>;
10
- }
3
+ type CrdtType<TValue extends unknown, TJson extends unknown = any> = Omit<TValue, "__pluvType"> & {
4
+ __pluvType: () => TJson;
5
+ };
6
+ type InferCrdtJson<T extends unknown> = T extends CrdtType<any, infer IJson> ? InferCrdtJson<IJson> : T extends Record<string, any> ? {
7
+ [P in keyof T]: InferCrdtJson<T[P]>;
8
+ } : T extends (infer IJson)[] ? InferCrdtJson<IJson>[] : T extends readonly (infer IJson)[] ? readonly InferCrdtJson<IJson>[] : T extends Json ? T : string;
11
9
 
12
10
  interface DocApplyEncodedStateParams {
13
11
  origin?: string;
14
12
  update?: string | Uint8Array;
15
13
  }
16
- interface DocSubscribeCallbackParams<T extends Record<string, AbstractCrdtType<any, any>>> {
14
+ interface DocSubscribeCallbackParams<T extends Record<string, CrdtType<any, any>>> {
17
15
  doc: AbstractCrdtDoc<T>;
18
16
  local: boolean;
19
17
  origin?: string | null;
20
18
  update: string;
21
19
  }
22
- declare abstract class AbstractCrdtDoc<T extends Record<string, AbstractCrdtType<any, any>>> {
20
+ declare abstract class AbstractCrdtDoc<T extends Record<string, CrdtType<any, any>>> {
23
21
  abstract applyEncodedState(params: DocApplyEncodedStateParams): this;
24
22
  abstract batchApplyEncodedState(updates: readonly (DocApplyEncodedStateParams | string | null | undefined)[]): this;
25
23
  abstract canRedo(): boolean;
@@ -31,13 +29,14 @@ declare abstract class AbstractCrdtDoc<T extends Record<string, AbstractCrdtType
31
29
  abstract isEmpty(): boolean;
32
30
  abstract redo(): this;
33
31
  abstract subscribe(listener: (params: DocSubscribeCallbackParams<T>) => void): () => void;
34
- abstract toJson(): InferCrdtStorageJson<T>;
32
+ abstract toJson(): InferCrdtJson<T>;
33
+ abstract toJson<TKey extends keyof T>(type: TKey): InferCrdtJson<T[TKey]>;
35
34
  abstract track(): this;
36
35
  abstract transact(fn: () => void, origin?: string): this;
37
36
  abstract undo(): this;
38
37
  }
39
38
 
40
- declare abstract class AbstractCrdtDocFactory<TStorage extends Record<string, AbstractCrdtType<any, any>>> {
39
+ declare abstract class AbstractCrdtDocFactory<TStorage extends Record<string, CrdtType<any, any>>> {
41
40
  abstract getEmpty(): AbstractCrdtDoc<TStorage>;
42
41
  abstract getFactory(initialStorage?: () => TStorage): AbstractCrdtDocFactory<TStorage>;
43
42
  abstract getFresh(): AbstractCrdtDoc<TStorage>;
@@ -73,4 +72,4 @@ declare const noop: {
73
72
  doc: (args?: any) => NoopCrdtDocFactory;
74
73
  };
75
74
 
76
- export { AbstractCrdtDoc, AbstractCrdtDocFactory, AbstractCrdtType, type DocApplyEncodedStateParams, type DocSubscribeCallbackParams, type InferCrdtStorageJson, NoopCrdtDoc, NoopCrdtDocFactory, noop };
75
+ export { AbstractCrdtDoc, AbstractCrdtDocFactory, type CrdtType, type DocApplyEncodedStateParams, type DocSubscribeCallbackParams, type InferCrdtJson, NoopCrdtDoc, NoopCrdtDocFactory, noop };
package/dist/index.d.ts CHANGED
@@ -1,25 +1,23 @@
1
1
  import { Json } from '@pluv/types';
2
2
 
3
- type InferCrdtStorageJson<T extends unknown> = T extends AbstractCrdtType<any, infer ICrdtJson> ? InferCrdtStorageJson<ICrdtJson> : T extends Record<string, any> ? {
4
- [P in keyof T]: InferCrdtStorageJson<T[P]>;
5
- } : T extends (infer IArrayCrdtItem)[] ? InferCrdtStorageJson<IArrayCrdtItem>[] : T extends readonly (infer IReadonlyArrayCrdtItem)[] ? InferCrdtStorageJson<IReadonlyArrayCrdtItem> : T extends Json ? T : string;
6
-
7
- declare abstract class AbstractCrdtType<TValue extends unknown, TJson extends unknown> {
8
- abstract value: TValue;
9
- abstract toJson(): InferCrdtStorageJson<TJson>;
10
- }
3
+ type CrdtType<TValue extends unknown, TJson extends unknown = any> = Omit<TValue, "__pluvType"> & {
4
+ __pluvType: () => TJson;
5
+ };
6
+ type InferCrdtJson<T extends unknown> = T extends CrdtType<any, infer IJson> ? InferCrdtJson<IJson> : T extends Record<string, any> ? {
7
+ [P in keyof T]: InferCrdtJson<T[P]>;
8
+ } : T extends (infer IJson)[] ? InferCrdtJson<IJson>[] : T extends readonly (infer IJson)[] ? readonly InferCrdtJson<IJson>[] : T extends Json ? T : string;
11
9
 
12
10
  interface DocApplyEncodedStateParams {
13
11
  origin?: string;
14
12
  update?: string | Uint8Array;
15
13
  }
16
- interface DocSubscribeCallbackParams<T extends Record<string, AbstractCrdtType<any, any>>> {
14
+ interface DocSubscribeCallbackParams<T extends Record<string, CrdtType<any, any>>> {
17
15
  doc: AbstractCrdtDoc<T>;
18
16
  local: boolean;
19
17
  origin?: string | null;
20
18
  update: string;
21
19
  }
22
- declare abstract class AbstractCrdtDoc<T extends Record<string, AbstractCrdtType<any, any>>> {
20
+ declare abstract class AbstractCrdtDoc<T extends Record<string, CrdtType<any, any>>> {
23
21
  abstract applyEncodedState(params: DocApplyEncodedStateParams): this;
24
22
  abstract batchApplyEncodedState(updates: readonly (DocApplyEncodedStateParams | string | null | undefined)[]): this;
25
23
  abstract canRedo(): boolean;
@@ -31,13 +29,14 @@ declare abstract class AbstractCrdtDoc<T extends Record<string, AbstractCrdtType
31
29
  abstract isEmpty(): boolean;
32
30
  abstract redo(): this;
33
31
  abstract subscribe(listener: (params: DocSubscribeCallbackParams<T>) => void): () => void;
34
- abstract toJson(): InferCrdtStorageJson<T>;
32
+ abstract toJson(): InferCrdtJson<T>;
33
+ abstract toJson<TKey extends keyof T>(type: TKey): InferCrdtJson<T[TKey]>;
35
34
  abstract track(): this;
36
35
  abstract transact(fn: () => void, origin?: string): this;
37
36
  abstract undo(): this;
38
37
  }
39
38
 
40
- declare abstract class AbstractCrdtDocFactory<TStorage extends Record<string, AbstractCrdtType<any, any>>> {
39
+ declare abstract class AbstractCrdtDocFactory<TStorage extends Record<string, CrdtType<any, any>>> {
41
40
  abstract getEmpty(): AbstractCrdtDoc<TStorage>;
42
41
  abstract getFactory(initialStorage?: () => TStorage): AbstractCrdtDocFactory<TStorage>;
43
42
  abstract getFresh(): AbstractCrdtDoc<TStorage>;
@@ -73,4 +72,4 @@ declare const noop: {
73
72
  doc: (args?: any) => NoopCrdtDocFactory;
74
73
  };
75
74
 
76
- export { AbstractCrdtDoc, AbstractCrdtDocFactory, AbstractCrdtType, type DocApplyEncodedStateParams, type DocSubscribeCallbackParams, type InferCrdtStorageJson, NoopCrdtDoc, NoopCrdtDocFactory, noop };
75
+ export { AbstractCrdtDoc, AbstractCrdtDocFactory, type CrdtType, type DocApplyEncodedStateParams, type DocSubscribeCallbackParams, type InferCrdtJson, NoopCrdtDoc, NoopCrdtDocFactory, noop };
package/dist/index.js CHANGED
@@ -22,7 +22,6 @@ var src_exports = {};
22
22
  __export(src_exports, {
23
23
  AbstractCrdtDoc: () => AbstractCrdtDoc,
24
24
  AbstractCrdtDocFactory: () => AbstractCrdtDocFactory,
25
- AbstractCrdtType: () => AbstractCrdtType,
26
25
  NoopCrdtDoc: () => NoopCrdtDoc,
27
26
  NoopCrdtDocFactory: () => NoopCrdtDocFactory,
28
27
  noop: () => noop
@@ -37,10 +36,6 @@ var AbstractCrdtDoc = class {
37
36
  var AbstractCrdtDocFactory = class {
38
37
  };
39
38
 
40
- // src/AbstractCrdtType.ts
41
- var AbstractCrdtType = class {
42
- };
43
-
44
39
  // src/NoopCrdtDoc.ts
45
40
  var NoopCrdtDoc = class extends AbstractCrdtDoc {
46
41
  applyEncodedState(params) {
@@ -112,7 +107,6 @@ var noop = {
112
107
  0 && (module.exports = {
113
108
  AbstractCrdtDoc,
114
109
  AbstractCrdtDocFactory,
115
- AbstractCrdtType,
116
110
  NoopCrdtDoc,
117
111
  NoopCrdtDocFactory,
118
112
  noop
package/dist/index.mjs CHANGED
@@ -6,10 +6,6 @@ var AbstractCrdtDoc = class {
6
6
  var AbstractCrdtDocFactory = class {
7
7
  };
8
8
 
9
- // src/AbstractCrdtType.ts
10
- var AbstractCrdtType = class {
11
- };
12
-
13
9
  // src/NoopCrdtDoc.ts
14
10
  var NoopCrdtDoc = class extends AbstractCrdtDoc {
15
11
  applyEncodedState(params) {
@@ -80,7 +76,6 @@ var noop = {
80
76
  export {
81
77
  AbstractCrdtDoc,
82
78
  AbstractCrdtDocFactory,
83
- AbstractCrdtType,
84
79
  NoopCrdtDoc,
85
80
  NoopCrdtDocFactory,
86
81
  noop
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pluv/crdt",
3
- "version": "0.18.0",
3
+ "version": "0.20.0",
4
4
  "description": "crdt base for @pluv/io",
5
5
  "author": "leedavidcs",
6
6
  "license": "MIT",
@@ -17,14 +17,14 @@
17
17
  "access": "public"
18
18
  },
19
19
  "dependencies": {
20
- "@pluv/types": "^0.18.0"
20
+ "@pluv/types": "^0.20.0"
21
21
  },
22
22
  "devDependencies": {
23
23
  "eslint": "^8.57.0",
24
- "tsup": "^8.0.2",
24
+ "tsup": "^8.1.0",
25
25
  "typescript": "^5.4.5",
26
- "@pluv/tsconfig": "^0.18.0",
27
- "eslint-config-pluv": "^0.18.0"
26
+ "@pluv/tsconfig": "^0.20.0",
27
+ "eslint-config-pluv": "^0.20.0"
28
28
  },
29
29
  "scripts": {
30
30
  "build": "tsup src/index.ts --format esm,cjs --dts",
@@ -1,19 +1,18 @@
1
- import { AbstractCrdtType } from "./AbstractCrdtType";
2
- import type { InferCrdtStorageJson } from "./types";
1
+ import type { CrdtType, InferCrdtJson } from "./types";
3
2
 
4
3
  export interface DocApplyEncodedStateParams {
5
4
  origin?: string;
6
5
  update?: string | Uint8Array;
7
6
  }
8
7
 
9
- export interface DocSubscribeCallbackParams<T extends Record<string, AbstractCrdtType<any, any>>> {
8
+ export interface DocSubscribeCallbackParams<T extends Record<string, CrdtType<any, any>>> {
10
9
  doc: AbstractCrdtDoc<T>;
11
10
  local: boolean;
12
11
  origin?: string | null;
13
12
  update: string;
14
13
  }
15
14
 
16
- export abstract class AbstractCrdtDoc<T extends Record<string, AbstractCrdtType<any, any>>> {
15
+ export abstract class AbstractCrdtDoc<T extends Record<string, CrdtType<any, any>>> {
17
16
  public abstract applyEncodedState(params: DocApplyEncodedStateParams): this;
18
17
  public abstract batchApplyEncodedState(
19
18
  updates: readonly (DocApplyEncodedStateParams | string | null | undefined)[],
@@ -27,7 +26,8 @@ export abstract class AbstractCrdtDoc<T extends Record<string, AbstractCrdtType<
27
26
  public abstract isEmpty(): boolean;
28
27
  public abstract redo(): this;
29
28
  public abstract subscribe(listener: (params: DocSubscribeCallbackParams<T>) => void): () => void;
30
- public abstract toJson(): InferCrdtStorageJson<T>;
29
+ public abstract toJson(): InferCrdtJson<T>;
30
+ public abstract toJson<TKey extends keyof T>(type: TKey): InferCrdtJson<T[TKey]>;
31
31
  public abstract track(): this;
32
32
  public abstract transact(fn: () => void, origin?: string): this;
33
33
  public abstract undo(): this;
@@ -1,7 +1,7 @@
1
- import { AbstractCrdtDoc } from "./AbstractCrdtDoc";
2
- import type { AbstractCrdtType } from "./AbstractCrdtType";
1
+ import type { AbstractCrdtDoc } from "./AbstractCrdtDoc";
2
+ import type { CrdtType } from "./types";
3
3
 
4
- export abstract class AbstractCrdtDocFactory<TStorage extends Record<string, AbstractCrdtType<any, any>>> {
4
+ export abstract class AbstractCrdtDocFactory<TStorage extends Record<string, CrdtType<any, any>>> {
5
5
  public abstract getEmpty(): AbstractCrdtDoc<TStorage>;
6
6
  public abstract getFactory(initialStorage?: () => TStorage): AbstractCrdtDocFactory<TStorage>;
7
7
  public abstract getFresh(): AbstractCrdtDoc<TStorage>;
package/src/index.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  export { AbstractCrdtDoc } from "./AbstractCrdtDoc";
2
2
  export type { DocApplyEncodedStateParams, DocSubscribeCallbackParams } from "./AbstractCrdtDoc";
3
3
  export { AbstractCrdtDocFactory } from "./AbstractCrdtDocFactory";
4
- export { AbstractCrdtType } from "./AbstractCrdtType";
5
4
  export { NoopCrdtDoc } from "./NoopCrdtDoc";
6
5
  export { NoopCrdtDocFactory } from "./NoopCrdtDocFactory";
7
6
  export { noop } from "./noop";
8
- export type { InferCrdtStorageJson } from "./types";
7
+ export type { CrdtType, InferCrdtJson } from "./types";
package/src/types.ts CHANGED
@@ -1,15 +1,18 @@
1
1
  import type { Json } from "@pluv/types";
2
- import type { AbstractCrdtType } from "./AbstractCrdtType";
3
2
 
4
- export type InferCrdtStorageJson<T extends unknown> =
5
- T extends AbstractCrdtType<any, infer ICrdtJson>
6
- ? InferCrdtStorageJson<ICrdtJson>
3
+ export type CrdtType<TValue extends unknown, TJson extends unknown = any> = Omit<TValue, "__pluvType"> & {
4
+ __pluvType: () => TJson;
5
+ };
6
+
7
+ export type InferCrdtJson<T extends unknown> =
8
+ T extends CrdtType<any, infer IJson>
9
+ ? InferCrdtJson<IJson>
7
10
  : T extends Record<string, any>
8
- ? { [P in keyof T]: InferCrdtStorageJson<T[P]> }
9
- : T extends (infer IArrayCrdtItem)[]
10
- ? InferCrdtStorageJson<IArrayCrdtItem>[]
11
- : T extends readonly (infer IReadonlyArrayCrdtItem)[]
12
- ? InferCrdtStorageJson<IReadonlyArrayCrdtItem>
11
+ ? { [P in keyof T]: InferCrdtJson<T[P]> }
12
+ : T extends (infer IJson)[]
13
+ ? InferCrdtJson<IJson>[]
14
+ : T extends readonly (infer IJson)[]
15
+ ? readonly InferCrdtJson<IJson>[]
13
16
  : T extends Json
14
17
  ? T
15
18
  : string;
@@ -1,7 +0,0 @@
1
- import type { InferCrdtStorageJson } from "./types";
2
-
3
- export abstract class AbstractCrdtType<TValue extends unknown, TJson extends unknown> {
4
- public abstract value: TValue;
5
-
6
- public abstract toJson(): InferCrdtStorageJson<TJson>;
7
- }