@pluv/crdt 1.0.0 → 1.0.2
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.
- package/.turbo/turbo-build.log +8 -8
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +15 -14
- package/dist/index.d.ts +15 -14
- package/dist/index.js +8 -3
- package/dist/index.mjs +8 -3
- package/package.json +4 -4
- package/src/AbstractCrdtDoc.ts +11 -8
- package/src/AbstractCrdtDocFactory.ts +7 -1
- package/src/NoopCrdtDoc.ts +6 -2
- package/src/NoopCrdtDocFactory.ts +2 -6
- package/src/types.ts +4 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/crdt@1.0.
|
|
2
|
+
> @pluv/crdt@1.0.2 build /home/runner/work/pluv/pluv/packages/crdt
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
[34mCLI[39m Target: es6
|
|
9
9
|
[34mESM[39m Build start
|
|
10
10
|
[34mCJS[39m Build start
|
|
11
|
-
[32mESM[39m [1mdist/index.mjs [22m[32m1.
|
|
12
|
-
[32mESM[39m ⚡️ Build success in
|
|
13
|
-
[32mCJS[39m [1mdist/index.js [22m[32m2.
|
|
14
|
-
[32mCJS[39m ⚡️ Build success in
|
|
11
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m1.46 KB[39m
|
|
12
|
+
[32mESM[39m ⚡️ Build success in 32ms
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m2.63 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 32ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[32m3.
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m3.
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 475ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m3.48 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m3.48 KB[39m
|
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -15,26 +15,27 @@ interface DocBatchApplyEncodedStateParams {
|
|
|
15
15
|
origin?: string;
|
|
16
16
|
updates?: Maybe<readonly Maybe<string | Uint8Array>[]>;
|
|
17
17
|
}
|
|
18
|
-
interface DocSubscribeCallbackParams<
|
|
19
|
-
doc: AbstractCrdtDoc<
|
|
18
|
+
interface DocSubscribeCallbackParams<TStorage extends Record<string, CrdtType<any, any>>> {
|
|
19
|
+
doc: AbstractCrdtDoc<TStorage>;
|
|
20
20
|
local: boolean;
|
|
21
21
|
origin?: string | null;
|
|
22
22
|
update: string;
|
|
23
23
|
}
|
|
24
|
-
declare abstract class AbstractCrdtDoc<
|
|
24
|
+
declare abstract class AbstractCrdtDoc<TStorage extends Record<string, CrdtType<any, any>>> {
|
|
25
25
|
abstract applyEncodedState(params: DocApplyEncodedStateParams): this;
|
|
26
26
|
abstract batchApplyEncodedState(params: DocBatchApplyEncodedStateParams): this;
|
|
27
27
|
abstract canRedo(): boolean;
|
|
28
28
|
abstract canUndo(): boolean;
|
|
29
29
|
abstract destroy(): void;
|
|
30
|
-
abstract get(key?: undefined):
|
|
31
|
-
abstract get<TKey extends keyof
|
|
30
|
+
abstract get(key?: undefined): TStorage;
|
|
31
|
+
abstract get<TKey extends keyof TStorage>(key: TKey): TStorage[TKey];
|
|
32
32
|
abstract getEncodedState(): string;
|
|
33
33
|
abstract isEmpty(): boolean;
|
|
34
|
+
abstract rebuildStorage(reference: TStorage): this;
|
|
34
35
|
abstract redo(): this;
|
|
35
|
-
abstract subscribe(listener: (params: DocSubscribeCallbackParams<
|
|
36
|
-
abstract toJson(): InferCrdtJson<
|
|
37
|
-
abstract toJson<TKey extends keyof
|
|
36
|
+
abstract subscribe(listener: (params: DocSubscribeCallbackParams<TStorage>) => void): () => void;
|
|
37
|
+
abstract toJson(): InferCrdtJson<TStorage>;
|
|
38
|
+
abstract toJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]>;
|
|
38
39
|
abstract track(): this;
|
|
39
40
|
abstract transact(fn: () => void, origin?: string): this;
|
|
40
41
|
abstract undo(): this;
|
|
@@ -43,8 +44,8 @@ declare abstract class AbstractCrdtDoc<T extends Record<string, CrdtType<any, an
|
|
|
43
44
|
declare abstract class AbstractCrdtDocFactory<TStorage extends Record<string, CrdtType<any, any>>> {
|
|
44
45
|
abstract getEmpty(): AbstractCrdtDoc<TStorage>;
|
|
45
46
|
abstract getFactory(initialStorage?: () => TStorage): AbstractCrdtDocFactory<TStorage>;
|
|
46
|
-
abstract getFresh(): AbstractCrdtDoc<TStorage>;
|
|
47
47
|
abstract getInitialized(initialStorage?: () => TStorage): AbstractCrdtDoc<TStorage>;
|
|
48
|
+
resolveEncodedState(updates: string | string[] | readonly string[]): string | null;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
declare class NoopCrdtDoc extends AbstractCrdtDoc<any> {
|
|
@@ -57,9 +58,10 @@ declare class NoopCrdtDoc extends AbstractCrdtDoc<any> {
|
|
|
57
58
|
get<TKey extends never>(key: TKey): {}[TKey];
|
|
58
59
|
getEncodedState(): string;
|
|
59
60
|
isEmpty(): boolean;
|
|
61
|
+
rebuildStorage(): this;
|
|
60
62
|
redo(): this;
|
|
61
|
-
subscribe(listener: (params: DocSubscribeCallbackParams<
|
|
62
|
-
toJson():
|
|
63
|
+
subscribe(listener: (params: DocSubscribeCallbackParams<any>) => void): () => void;
|
|
64
|
+
toJson(): any;
|
|
63
65
|
track(): this;
|
|
64
66
|
transact(fn: () => void, origin?: string | undefined): this;
|
|
65
67
|
undo(): this;
|
|
@@ -67,9 +69,8 @@ declare class NoopCrdtDoc extends AbstractCrdtDoc<any> {
|
|
|
67
69
|
|
|
68
70
|
declare class NoopCrdtDocFactory extends AbstractCrdtDocFactory<any> {
|
|
69
71
|
getEmpty(): NoopCrdtDoc;
|
|
70
|
-
getFactory(initialStorage?: (() =>
|
|
71
|
-
|
|
72
|
-
getInitialized(initialStorage?: (() => {}) | undefined): NoopCrdtDoc;
|
|
72
|
+
getFactory(initialStorage?: (() => any) | undefined): NoopCrdtDocFactory;
|
|
73
|
+
getInitialized(initialStorage?: (() => any) | undefined): NoopCrdtDoc;
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
declare const noop: {
|
package/dist/index.d.ts
CHANGED
|
@@ -15,26 +15,27 @@ interface DocBatchApplyEncodedStateParams {
|
|
|
15
15
|
origin?: string;
|
|
16
16
|
updates?: Maybe<readonly Maybe<string | Uint8Array>[]>;
|
|
17
17
|
}
|
|
18
|
-
interface DocSubscribeCallbackParams<
|
|
19
|
-
doc: AbstractCrdtDoc<
|
|
18
|
+
interface DocSubscribeCallbackParams<TStorage extends Record<string, CrdtType<any, any>>> {
|
|
19
|
+
doc: AbstractCrdtDoc<TStorage>;
|
|
20
20
|
local: boolean;
|
|
21
21
|
origin?: string | null;
|
|
22
22
|
update: string;
|
|
23
23
|
}
|
|
24
|
-
declare abstract class AbstractCrdtDoc<
|
|
24
|
+
declare abstract class AbstractCrdtDoc<TStorage extends Record<string, CrdtType<any, any>>> {
|
|
25
25
|
abstract applyEncodedState(params: DocApplyEncodedStateParams): this;
|
|
26
26
|
abstract batchApplyEncodedState(params: DocBatchApplyEncodedStateParams): this;
|
|
27
27
|
abstract canRedo(): boolean;
|
|
28
28
|
abstract canUndo(): boolean;
|
|
29
29
|
abstract destroy(): void;
|
|
30
|
-
abstract get(key?: undefined):
|
|
31
|
-
abstract get<TKey extends keyof
|
|
30
|
+
abstract get(key?: undefined): TStorage;
|
|
31
|
+
abstract get<TKey extends keyof TStorage>(key: TKey): TStorage[TKey];
|
|
32
32
|
abstract getEncodedState(): string;
|
|
33
33
|
abstract isEmpty(): boolean;
|
|
34
|
+
abstract rebuildStorage(reference: TStorage): this;
|
|
34
35
|
abstract redo(): this;
|
|
35
|
-
abstract subscribe(listener: (params: DocSubscribeCallbackParams<
|
|
36
|
-
abstract toJson(): InferCrdtJson<
|
|
37
|
-
abstract toJson<TKey extends keyof
|
|
36
|
+
abstract subscribe(listener: (params: DocSubscribeCallbackParams<TStorage>) => void): () => void;
|
|
37
|
+
abstract toJson(): InferCrdtJson<TStorage>;
|
|
38
|
+
abstract toJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]>;
|
|
38
39
|
abstract track(): this;
|
|
39
40
|
abstract transact(fn: () => void, origin?: string): this;
|
|
40
41
|
abstract undo(): this;
|
|
@@ -43,8 +44,8 @@ declare abstract class AbstractCrdtDoc<T extends Record<string, CrdtType<any, an
|
|
|
43
44
|
declare abstract class AbstractCrdtDocFactory<TStorage extends Record<string, CrdtType<any, any>>> {
|
|
44
45
|
abstract getEmpty(): AbstractCrdtDoc<TStorage>;
|
|
45
46
|
abstract getFactory(initialStorage?: () => TStorage): AbstractCrdtDocFactory<TStorage>;
|
|
46
|
-
abstract getFresh(): AbstractCrdtDoc<TStorage>;
|
|
47
47
|
abstract getInitialized(initialStorage?: () => TStorage): AbstractCrdtDoc<TStorage>;
|
|
48
|
+
resolveEncodedState(updates: string | string[] | readonly string[]): string | null;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
declare class NoopCrdtDoc extends AbstractCrdtDoc<any> {
|
|
@@ -57,9 +58,10 @@ declare class NoopCrdtDoc extends AbstractCrdtDoc<any> {
|
|
|
57
58
|
get<TKey extends never>(key: TKey): {}[TKey];
|
|
58
59
|
getEncodedState(): string;
|
|
59
60
|
isEmpty(): boolean;
|
|
61
|
+
rebuildStorage(): this;
|
|
60
62
|
redo(): this;
|
|
61
|
-
subscribe(listener: (params: DocSubscribeCallbackParams<
|
|
62
|
-
toJson():
|
|
63
|
+
subscribe(listener: (params: DocSubscribeCallbackParams<any>) => void): () => void;
|
|
64
|
+
toJson(): any;
|
|
63
65
|
track(): this;
|
|
64
66
|
transact(fn: () => void, origin?: string | undefined): this;
|
|
65
67
|
undo(): this;
|
|
@@ -67,9 +69,8 @@ declare class NoopCrdtDoc extends AbstractCrdtDoc<any> {
|
|
|
67
69
|
|
|
68
70
|
declare class NoopCrdtDocFactory extends AbstractCrdtDocFactory<any> {
|
|
69
71
|
getEmpty(): NoopCrdtDoc;
|
|
70
|
-
getFactory(initialStorage?: (() =>
|
|
71
|
-
|
|
72
|
-
getInitialized(initialStorage?: (() => {}) | undefined): NoopCrdtDoc;
|
|
72
|
+
getFactory(initialStorage?: (() => any) | undefined): NoopCrdtDocFactory;
|
|
73
|
+
getInitialized(initialStorage?: (() => any) | undefined): NoopCrdtDoc;
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
declare const noop: {
|
package/dist/index.js
CHANGED
|
@@ -34,6 +34,11 @@ var AbstractCrdtDoc = class {
|
|
|
34
34
|
|
|
35
35
|
// src/AbstractCrdtDocFactory.ts
|
|
36
36
|
var AbstractCrdtDocFactory = class {
|
|
37
|
+
resolveEncodedState(updates) {
|
|
38
|
+
if (typeof updates === "string") return updates;
|
|
39
|
+
if (!updates.length) return null;
|
|
40
|
+
return this.getEmpty().batchApplyEncodedState({ updates }).getEncodedState();
|
|
41
|
+
}
|
|
37
42
|
};
|
|
38
43
|
|
|
39
44
|
// src/NoopCrdtDoc.ts
|
|
@@ -62,6 +67,9 @@ var NoopCrdtDoc = class extends AbstractCrdtDoc {
|
|
|
62
67
|
isEmpty() {
|
|
63
68
|
return true;
|
|
64
69
|
}
|
|
70
|
+
rebuildStorage() {
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
65
73
|
redo() {
|
|
66
74
|
return this;
|
|
67
75
|
}
|
|
@@ -91,9 +99,6 @@ var NoopCrdtDocFactory = class extends AbstractCrdtDocFactory {
|
|
|
91
99
|
getFactory(initialStorage) {
|
|
92
100
|
return this;
|
|
93
101
|
}
|
|
94
|
-
getFresh() {
|
|
95
|
-
return new NoopCrdtDoc();
|
|
96
|
-
}
|
|
97
102
|
getInitialized(initialStorage) {
|
|
98
103
|
return new NoopCrdtDoc();
|
|
99
104
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -4,6 +4,11 @@ var AbstractCrdtDoc = class {
|
|
|
4
4
|
|
|
5
5
|
// src/AbstractCrdtDocFactory.ts
|
|
6
6
|
var AbstractCrdtDocFactory = class {
|
|
7
|
+
resolveEncodedState(updates) {
|
|
8
|
+
if (typeof updates === "string") return updates;
|
|
9
|
+
if (!updates.length) return null;
|
|
10
|
+
return this.getEmpty().batchApplyEncodedState({ updates }).getEncodedState();
|
|
11
|
+
}
|
|
7
12
|
};
|
|
8
13
|
|
|
9
14
|
// src/NoopCrdtDoc.ts
|
|
@@ -32,6 +37,9 @@ var NoopCrdtDoc = class extends AbstractCrdtDoc {
|
|
|
32
37
|
isEmpty() {
|
|
33
38
|
return true;
|
|
34
39
|
}
|
|
40
|
+
rebuildStorage() {
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
35
43
|
redo() {
|
|
36
44
|
return this;
|
|
37
45
|
}
|
|
@@ -61,9 +69,6 @@ var NoopCrdtDocFactory = class extends AbstractCrdtDocFactory {
|
|
|
61
69
|
getFactory(initialStorage) {
|
|
62
70
|
return this;
|
|
63
71
|
}
|
|
64
|
-
getFresh() {
|
|
65
|
-
return new NoopCrdtDoc();
|
|
66
|
-
}
|
|
67
72
|
getInitialized(initialStorage) {
|
|
68
73
|
return new NoopCrdtDoc();
|
|
69
74
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/crdt",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
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": "^1.0.
|
|
20
|
+
"@pluv/types": "^1.0.2"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"eslint": "^9.25.1",
|
|
24
24
|
"tsup": "^8.4.0",
|
|
25
25
|
"typescript": "^5.8.3",
|
|
26
|
-
"@pluv/tsconfig": "^1.0.
|
|
27
|
-
"eslint-config-pluv": "^1.0.
|
|
26
|
+
"@pluv/tsconfig": "^1.0.2",
|
|
27
|
+
"eslint-config-pluv": "^1.0.2"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
package/src/AbstractCrdtDoc.ts
CHANGED
|
@@ -11,27 +11,30 @@ export interface DocBatchApplyEncodedStateParams {
|
|
|
11
11
|
updates?: Maybe<readonly Maybe<string | Uint8Array>[]>;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export interface DocSubscribeCallbackParams<
|
|
15
|
-
doc: AbstractCrdtDoc<
|
|
14
|
+
export interface DocSubscribeCallbackParams<TStorage extends Record<string, CrdtType<any, any>>> {
|
|
15
|
+
doc: AbstractCrdtDoc<TStorage>;
|
|
16
16
|
local: boolean;
|
|
17
17
|
origin?: string | null;
|
|
18
18
|
update: string;
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
export abstract class AbstractCrdtDoc<
|
|
21
|
+
export abstract class AbstractCrdtDoc<TStorage extends Record<string, CrdtType<any, any>>> {
|
|
22
22
|
public abstract applyEncodedState(params: DocApplyEncodedStateParams): this;
|
|
23
23
|
public abstract batchApplyEncodedState(params: DocBatchApplyEncodedStateParams): this;
|
|
24
24
|
public abstract canRedo(): boolean;
|
|
25
25
|
public abstract canUndo(): boolean;
|
|
26
26
|
public abstract destroy(): void;
|
|
27
|
-
public abstract get(key?: undefined):
|
|
28
|
-
public abstract get<TKey extends keyof
|
|
27
|
+
public abstract get(key?: undefined): TStorage;
|
|
28
|
+
public abstract get<TKey extends keyof TStorage>(key: TKey): TStorage[TKey];
|
|
29
29
|
public abstract getEncodedState(): string;
|
|
30
30
|
public abstract isEmpty(): boolean;
|
|
31
|
+
public abstract rebuildStorage(reference: TStorage): this;
|
|
31
32
|
public abstract redo(): this;
|
|
32
|
-
public abstract subscribe(
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
public abstract subscribe(
|
|
34
|
+
listener: (params: DocSubscribeCallbackParams<TStorage>) => void,
|
|
35
|
+
): () => void;
|
|
36
|
+
public abstract toJson(): InferCrdtJson<TStorage>;
|
|
37
|
+
public abstract toJson<TKey extends keyof TStorage>(type: TKey): InferCrdtJson<TStorage[TKey]>;
|
|
35
38
|
public abstract track(): this;
|
|
36
39
|
public abstract transact(fn: () => void, origin?: string): this;
|
|
37
40
|
public abstract undo(): this;
|
|
@@ -4,6 +4,12 @@ import type { CrdtType } from "./types";
|
|
|
4
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
|
-
public abstract getFresh(): AbstractCrdtDoc<TStorage>;
|
|
8
7
|
public abstract getInitialized(initialStorage?: () => TStorage): AbstractCrdtDoc<TStorage>;
|
|
8
|
+
|
|
9
|
+
public resolveEncodedState(updates: string | string[] | readonly string[]): string | null {
|
|
10
|
+
if (typeof updates === "string") return updates;
|
|
11
|
+
if (!updates.length) return null;
|
|
12
|
+
|
|
13
|
+
return this.getEmpty().batchApplyEncodedState({ updates }).getEncodedState();
|
|
14
|
+
}
|
|
9
15
|
}
|
package/src/NoopCrdtDoc.ts
CHANGED
|
@@ -40,15 +40,19 @@ export class NoopCrdtDoc extends AbstractCrdtDoc<any> {
|
|
|
40
40
|
return true;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
public rebuildStorage(): this {
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
|
|
43
47
|
public redo(): this {
|
|
44
48
|
return this;
|
|
45
49
|
}
|
|
46
50
|
|
|
47
|
-
public subscribe(listener: (params: DocSubscribeCallbackParams<
|
|
51
|
+
public subscribe(listener: (params: DocSubscribeCallbackParams<any>) => void): () => void {
|
|
48
52
|
return () => undefined;
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
public toJson():
|
|
55
|
+
public toJson(): any {
|
|
52
56
|
return {};
|
|
53
57
|
}
|
|
54
58
|
|
|
@@ -6,15 +6,11 @@ export class NoopCrdtDocFactory extends AbstractCrdtDocFactory<any> {
|
|
|
6
6
|
return new NoopCrdtDoc();
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
public getFactory(initialStorage?: (() =>
|
|
9
|
+
public getFactory(initialStorage?: (() => any) | undefined): NoopCrdtDocFactory {
|
|
10
10
|
return this;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
public
|
|
14
|
-
return new NoopCrdtDoc();
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public getInitialized(initialStorage?: (() => {}) | undefined): NoopCrdtDoc {
|
|
13
|
+
public getInitialized(initialStorage?: (() => any) | undefined): NoopCrdtDoc {
|
|
18
14
|
return new NoopCrdtDoc();
|
|
19
15
|
}
|
|
20
16
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { Json } from "@pluv/types";
|
|
2
2
|
|
|
3
|
-
export type CrdtType<TValue extends unknown, TJson extends unknown = any> = Omit<
|
|
3
|
+
export type CrdtType<TValue extends unknown, TJson extends unknown = any> = Omit<
|
|
4
|
+
TValue,
|
|
5
|
+
"__pluvType"
|
|
6
|
+
> & {
|
|
4
7
|
__pluvType: () => TJson;
|
|
5
8
|
};
|
|
6
9
|
|