@pluv/crdt 0.16.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.
- package/.eslintrc.js +4 -0
- package/.turbo/turbo-build.log +18 -0
- package/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/dist/index.d.mts +76 -0
- package/dist/index.d.ts +76 -0
- package/dist/index.js +119 -0
- package/dist/index.mjs +87 -0
- package/package.json +35 -0
- package/src/AbstractCrdtDoc.ts +45 -0
- package/src/AbstractCrdtDocFactory.ts +15 -0
- package/src/AbstractCrdtType.ts +10 -0
- package/src/NoopCrdtDoc.ts +76 -0
- package/src/NoopCrdtDocFactory.ts +24 -0
- package/src/index.ts +11 -0
- package/src/noop.ts +5 -0
- package/src/types.ts +15 -0
- package/tsconfig.json +8 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
> @pluv/crdt@0.16.0 build /home/runner/work/pluv/pluv/packages/crdt
|
|
3
|
+
> tsup src/index.ts --format esm,cjs --dts
|
|
4
|
+
|
|
5
|
+
[34mCLI[39m Building entry: src/index.ts
|
|
6
|
+
[34mCLI[39m Using tsconfig: tsconfig.json
|
|
7
|
+
[34mCLI[39m tsup v8.0.2
|
|
8
|
+
[34mCLI[39m Target: es6
|
|
9
|
+
[34mESM[39m Build start
|
|
10
|
+
[34mCJS[39m Build start
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m2.54 KB[39m
|
|
12
|
+
[32mCJS[39m ⚡️ Build success in 28ms
|
|
13
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m1.34 KB[39m
|
|
14
|
+
[32mESM[39m ⚡️ Build success in 29ms
|
|
15
|
+
[34mDTS[39m Build start
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 577ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m3.31 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m3.31 KB[39m
|
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Shoubhit Dash
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Json } from '@pluv/types';
|
|
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
|
+
}
|
|
11
|
+
|
|
12
|
+
interface DocApplyEncodedStateParams {
|
|
13
|
+
origin?: string;
|
|
14
|
+
update?: string | Uint8Array;
|
|
15
|
+
}
|
|
16
|
+
interface DocSubscribeCallbackParams<T extends Record<string, AbstractCrdtType<any, any>>> {
|
|
17
|
+
doc: AbstractCrdtDoc<T>;
|
|
18
|
+
local: boolean;
|
|
19
|
+
origin?: string | null;
|
|
20
|
+
update: string;
|
|
21
|
+
}
|
|
22
|
+
declare abstract class AbstractCrdtDoc<T extends Record<string, AbstractCrdtType<any, any>>> {
|
|
23
|
+
abstract applyEncodedState(params: DocApplyEncodedStateParams): this;
|
|
24
|
+
abstract batchApplyEncodedState(updates: readonly (DocApplyEncodedStateParams | string | null | undefined)[]): this;
|
|
25
|
+
abstract canRedo(): boolean;
|
|
26
|
+
abstract canUndo(): boolean;
|
|
27
|
+
abstract destroy(): void;
|
|
28
|
+
abstract get(key?: undefined): T;
|
|
29
|
+
abstract get<TKey extends keyof T>(key: TKey): T[TKey];
|
|
30
|
+
abstract getEncodedState(): string;
|
|
31
|
+
abstract isEmpty(): boolean;
|
|
32
|
+
abstract redo(): this;
|
|
33
|
+
abstract subscribe(listener: (params: DocSubscribeCallbackParams<T>) => void): () => void;
|
|
34
|
+
abstract toJson(): InferCrdtStorageJson<T>;
|
|
35
|
+
abstract track(): this;
|
|
36
|
+
abstract transact(fn: () => void, origin?: string): this;
|
|
37
|
+
abstract undo(): this;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
declare abstract class AbstractCrdtDocFactory<TStorage extends Record<string, AbstractCrdtType<any, any>>> {
|
|
41
|
+
abstract getEmpty(): AbstractCrdtDoc<TStorage>;
|
|
42
|
+
abstract getFactory(initialStorage?: () => TStorage): AbstractCrdtDocFactory<TStorage>;
|
|
43
|
+
abstract getFresh(): AbstractCrdtDoc<TStorage>;
|
|
44
|
+
abstract getInitialized(initialStorage?: () => TStorage): AbstractCrdtDoc<TStorage>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
declare class NoopCrdtDoc extends AbstractCrdtDoc<any> {
|
|
48
|
+
applyEncodedState(params: DocApplyEncodedStateParams): this;
|
|
49
|
+
batchApplyEncodedState(updates: readonly (string | DocApplyEncodedStateParams | null | undefined)[]): this;
|
|
50
|
+
canRedo(): boolean;
|
|
51
|
+
canUndo(): boolean;
|
|
52
|
+
destroy(): void;
|
|
53
|
+
get(key?: undefined): {};
|
|
54
|
+
get<TKey extends never>(key: TKey): {}[TKey];
|
|
55
|
+
getEncodedState(): string;
|
|
56
|
+
isEmpty(): boolean;
|
|
57
|
+
redo(): this;
|
|
58
|
+
subscribe(listener: (params: DocSubscribeCallbackParams<{}>) => void): () => void;
|
|
59
|
+
toJson(): {};
|
|
60
|
+
track(): this;
|
|
61
|
+
transact(fn: () => void, origin?: string | undefined): this;
|
|
62
|
+
undo(): this;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
declare class NoopCrdtDocFactory extends AbstractCrdtDocFactory<any> {
|
|
66
|
+
getEmpty(): NoopCrdtDoc;
|
|
67
|
+
getFactory(initialStorage?: (() => {}) | undefined): NoopCrdtDocFactory;
|
|
68
|
+
getFresh(): NoopCrdtDoc;
|
|
69
|
+
getInitialized(initialStorage?: (() => {}) | undefined): NoopCrdtDoc;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
declare const noop: {
|
|
73
|
+
doc: (args?: any) => NoopCrdtDocFactory;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export { AbstractCrdtDoc, AbstractCrdtDocFactory, AbstractCrdtType, type DocApplyEncodedStateParams, type DocSubscribeCallbackParams, type InferCrdtStorageJson, NoopCrdtDoc, NoopCrdtDocFactory, noop };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { Json } from '@pluv/types';
|
|
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
|
+
}
|
|
11
|
+
|
|
12
|
+
interface DocApplyEncodedStateParams {
|
|
13
|
+
origin?: string;
|
|
14
|
+
update?: string | Uint8Array;
|
|
15
|
+
}
|
|
16
|
+
interface DocSubscribeCallbackParams<T extends Record<string, AbstractCrdtType<any, any>>> {
|
|
17
|
+
doc: AbstractCrdtDoc<T>;
|
|
18
|
+
local: boolean;
|
|
19
|
+
origin?: string | null;
|
|
20
|
+
update: string;
|
|
21
|
+
}
|
|
22
|
+
declare abstract class AbstractCrdtDoc<T extends Record<string, AbstractCrdtType<any, any>>> {
|
|
23
|
+
abstract applyEncodedState(params: DocApplyEncodedStateParams): this;
|
|
24
|
+
abstract batchApplyEncodedState(updates: readonly (DocApplyEncodedStateParams | string | null | undefined)[]): this;
|
|
25
|
+
abstract canRedo(): boolean;
|
|
26
|
+
abstract canUndo(): boolean;
|
|
27
|
+
abstract destroy(): void;
|
|
28
|
+
abstract get(key?: undefined): T;
|
|
29
|
+
abstract get<TKey extends keyof T>(key: TKey): T[TKey];
|
|
30
|
+
abstract getEncodedState(): string;
|
|
31
|
+
abstract isEmpty(): boolean;
|
|
32
|
+
abstract redo(): this;
|
|
33
|
+
abstract subscribe(listener: (params: DocSubscribeCallbackParams<T>) => void): () => void;
|
|
34
|
+
abstract toJson(): InferCrdtStorageJson<T>;
|
|
35
|
+
abstract track(): this;
|
|
36
|
+
abstract transact(fn: () => void, origin?: string): this;
|
|
37
|
+
abstract undo(): this;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
declare abstract class AbstractCrdtDocFactory<TStorage extends Record<string, AbstractCrdtType<any, any>>> {
|
|
41
|
+
abstract getEmpty(): AbstractCrdtDoc<TStorage>;
|
|
42
|
+
abstract getFactory(initialStorage?: () => TStorage): AbstractCrdtDocFactory<TStorage>;
|
|
43
|
+
abstract getFresh(): AbstractCrdtDoc<TStorage>;
|
|
44
|
+
abstract getInitialized(initialStorage?: () => TStorage): AbstractCrdtDoc<TStorage>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
declare class NoopCrdtDoc extends AbstractCrdtDoc<any> {
|
|
48
|
+
applyEncodedState(params: DocApplyEncodedStateParams): this;
|
|
49
|
+
batchApplyEncodedState(updates: readonly (string | DocApplyEncodedStateParams | null | undefined)[]): this;
|
|
50
|
+
canRedo(): boolean;
|
|
51
|
+
canUndo(): boolean;
|
|
52
|
+
destroy(): void;
|
|
53
|
+
get(key?: undefined): {};
|
|
54
|
+
get<TKey extends never>(key: TKey): {}[TKey];
|
|
55
|
+
getEncodedState(): string;
|
|
56
|
+
isEmpty(): boolean;
|
|
57
|
+
redo(): this;
|
|
58
|
+
subscribe(listener: (params: DocSubscribeCallbackParams<{}>) => void): () => void;
|
|
59
|
+
toJson(): {};
|
|
60
|
+
track(): this;
|
|
61
|
+
transact(fn: () => void, origin?: string | undefined): this;
|
|
62
|
+
undo(): this;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
declare class NoopCrdtDocFactory extends AbstractCrdtDocFactory<any> {
|
|
66
|
+
getEmpty(): NoopCrdtDoc;
|
|
67
|
+
getFactory(initialStorage?: (() => {}) | undefined): NoopCrdtDocFactory;
|
|
68
|
+
getFresh(): NoopCrdtDoc;
|
|
69
|
+
getInitialized(initialStorage?: (() => {}) | undefined): NoopCrdtDoc;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
declare const noop: {
|
|
73
|
+
doc: (args?: any) => NoopCrdtDocFactory;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export { AbstractCrdtDoc, AbstractCrdtDocFactory, AbstractCrdtType, type DocApplyEncodedStateParams, type DocSubscribeCallbackParams, type InferCrdtStorageJson, NoopCrdtDoc, NoopCrdtDocFactory, noop };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
AbstractCrdtDoc: () => AbstractCrdtDoc,
|
|
24
|
+
AbstractCrdtDocFactory: () => AbstractCrdtDocFactory,
|
|
25
|
+
AbstractCrdtType: () => AbstractCrdtType,
|
|
26
|
+
NoopCrdtDoc: () => NoopCrdtDoc,
|
|
27
|
+
NoopCrdtDocFactory: () => NoopCrdtDocFactory,
|
|
28
|
+
noop: () => noop
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(src_exports);
|
|
31
|
+
|
|
32
|
+
// src/AbstractCrdtDoc.ts
|
|
33
|
+
var AbstractCrdtDoc = class {
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// src/AbstractCrdtDocFactory.ts
|
|
37
|
+
var AbstractCrdtDocFactory = class {
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// src/AbstractCrdtType.ts
|
|
41
|
+
var AbstractCrdtType = class {
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// src/NoopCrdtDoc.ts
|
|
45
|
+
var NoopCrdtDoc = class extends AbstractCrdtDoc {
|
|
46
|
+
applyEncodedState(params) {
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
batchApplyEncodedState(updates) {
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
canRedo() {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
canUndo() {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
destroy() {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
get(key) {
|
|
62
|
+
return typeof key === "string" ? void 0 : {};
|
|
63
|
+
}
|
|
64
|
+
getEncodedState() {
|
|
65
|
+
return "";
|
|
66
|
+
}
|
|
67
|
+
isEmpty() {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
redo() {
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
subscribe(listener) {
|
|
74
|
+
return () => void 0;
|
|
75
|
+
}
|
|
76
|
+
toJson() {
|
|
77
|
+
return {};
|
|
78
|
+
}
|
|
79
|
+
track() {
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
transact(fn, origin) {
|
|
83
|
+
fn();
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
undo() {
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// src/NoopCrdtDocFactory.ts
|
|
92
|
+
var NoopCrdtDocFactory = class extends AbstractCrdtDocFactory {
|
|
93
|
+
getEmpty() {
|
|
94
|
+
return new NoopCrdtDoc();
|
|
95
|
+
}
|
|
96
|
+
getFactory(initialStorage) {
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
getFresh() {
|
|
100
|
+
return new NoopCrdtDoc();
|
|
101
|
+
}
|
|
102
|
+
getInitialized(initialStorage) {
|
|
103
|
+
return new NoopCrdtDoc();
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// src/noop.ts
|
|
108
|
+
var noop = {
|
|
109
|
+
doc: (args) => new NoopCrdtDocFactory()
|
|
110
|
+
};
|
|
111
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
112
|
+
0 && (module.exports = {
|
|
113
|
+
AbstractCrdtDoc,
|
|
114
|
+
AbstractCrdtDocFactory,
|
|
115
|
+
AbstractCrdtType,
|
|
116
|
+
NoopCrdtDoc,
|
|
117
|
+
NoopCrdtDocFactory,
|
|
118
|
+
noop
|
|
119
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// src/AbstractCrdtDoc.ts
|
|
2
|
+
var AbstractCrdtDoc = class {
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
// src/AbstractCrdtDocFactory.ts
|
|
6
|
+
var AbstractCrdtDocFactory = class {
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
// src/AbstractCrdtType.ts
|
|
10
|
+
var AbstractCrdtType = class {
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// src/NoopCrdtDoc.ts
|
|
14
|
+
var NoopCrdtDoc = class extends AbstractCrdtDoc {
|
|
15
|
+
applyEncodedState(params) {
|
|
16
|
+
return this;
|
|
17
|
+
}
|
|
18
|
+
batchApplyEncodedState(updates) {
|
|
19
|
+
return this;
|
|
20
|
+
}
|
|
21
|
+
canRedo() {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
canUndo() {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
destroy() {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
get(key) {
|
|
31
|
+
return typeof key === "string" ? void 0 : {};
|
|
32
|
+
}
|
|
33
|
+
getEncodedState() {
|
|
34
|
+
return "";
|
|
35
|
+
}
|
|
36
|
+
isEmpty() {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
redo() {
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
subscribe(listener) {
|
|
43
|
+
return () => void 0;
|
|
44
|
+
}
|
|
45
|
+
toJson() {
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
track() {
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
transact(fn, origin) {
|
|
52
|
+
fn();
|
|
53
|
+
return this;
|
|
54
|
+
}
|
|
55
|
+
undo() {
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// src/NoopCrdtDocFactory.ts
|
|
61
|
+
var NoopCrdtDocFactory = class extends AbstractCrdtDocFactory {
|
|
62
|
+
getEmpty() {
|
|
63
|
+
return new NoopCrdtDoc();
|
|
64
|
+
}
|
|
65
|
+
getFactory(initialStorage) {
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
getFresh() {
|
|
69
|
+
return new NoopCrdtDoc();
|
|
70
|
+
}
|
|
71
|
+
getInitialized(initialStorage) {
|
|
72
|
+
return new NoopCrdtDoc();
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/noop.ts
|
|
77
|
+
var noop = {
|
|
78
|
+
doc: (args) => new NoopCrdtDocFactory()
|
|
79
|
+
};
|
|
80
|
+
export {
|
|
81
|
+
AbstractCrdtDoc,
|
|
82
|
+
AbstractCrdtDocFactory,
|
|
83
|
+
AbstractCrdtType,
|
|
84
|
+
NoopCrdtDoc,
|
|
85
|
+
NoopCrdtDocFactory,
|
|
86
|
+
noop
|
|
87
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pluv/crdt",
|
|
3
|
+
"version": "0.16.0",
|
|
4
|
+
"description": "crdt base for @pluv/io",
|
|
5
|
+
"author": "leedavidcs",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/pluv-io/pluv",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/pluv-io/pluv.git",
|
|
11
|
+
"directory": "packages/crdt"
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"module": "./dist/index.mjs",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@pluv/types": "^0.16.0"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"eslint": "^8.56.0",
|
|
24
|
+
"tsup": "^8.0.2",
|
|
25
|
+
"typescript": "^5.3.3",
|
|
26
|
+
"@pluv/tsconfig": "^0.16.0",
|
|
27
|
+
"eslint-config-pluv": "^0.16.0"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
31
|
+
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
|
|
32
|
+
"lint": "eslint src/**/*.ts* --fix",
|
|
33
|
+
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { AbstractCrdtType } from "./AbstractCrdtType";
|
|
2
|
+
import type { InferCrdtStorageJson } from "./types";
|
|
3
|
+
|
|
4
|
+
export interface DocApplyEncodedStateParams {
|
|
5
|
+
origin?: string;
|
|
6
|
+
update?: string | Uint8Array;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface DocSubscribeCallbackParams<
|
|
10
|
+
T extends Record<string, AbstractCrdtType<any, any>>,
|
|
11
|
+
> {
|
|
12
|
+
doc: AbstractCrdtDoc<T>;
|
|
13
|
+
local: boolean;
|
|
14
|
+
origin?: string | null;
|
|
15
|
+
update: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export abstract class AbstractCrdtDoc<
|
|
19
|
+
T extends Record<string, AbstractCrdtType<any, any>>,
|
|
20
|
+
> {
|
|
21
|
+
public abstract applyEncodedState(params: DocApplyEncodedStateParams): this;
|
|
22
|
+
public abstract batchApplyEncodedState(
|
|
23
|
+
updates: readonly (
|
|
24
|
+
| DocApplyEncodedStateParams
|
|
25
|
+
| string
|
|
26
|
+
| null
|
|
27
|
+
| undefined
|
|
28
|
+
)[],
|
|
29
|
+
): this;
|
|
30
|
+
public abstract canRedo(): boolean;
|
|
31
|
+
public abstract canUndo(): boolean;
|
|
32
|
+
public abstract destroy(): void;
|
|
33
|
+
public abstract get(key?: undefined): T;
|
|
34
|
+
public abstract get<TKey extends keyof T>(key: TKey): T[TKey];
|
|
35
|
+
public abstract getEncodedState(): string;
|
|
36
|
+
public abstract isEmpty(): boolean;
|
|
37
|
+
public abstract redo(): this;
|
|
38
|
+
public abstract subscribe(
|
|
39
|
+
listener: (params: DocSubscribeCallbackParams<T>) => void,
|
|
40
|
+
): () => void;
|
|
41
|
+
public abstract toJson(): InferCrdtStorageJson<T>;
|
|
42
|
+
public abstract track(): this;
|
|
43
|
+
public abstract transact(fn: () => void, origin?: string): this;
|
|
44
|
+
public abstract undo(): this;
|
|
45
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AbstractCrdtDoc } from "./AbstractCrdtDoc";
|
|
2
|
+
import type { AbstractCrdtType } from "./AbstractCrdtType";
|
|
3
|
+
|
|
4
|
+
export abstract class AbstractCrdtDocFactory<
|
|
5
|
+
TStorage extends Record<string, AbstractCrdtType<any, any>>,
|
|
6
|
+
> {
|
|
7
|
+
public abstract getEmpty(): AbstractCrdtDoc<TStorage>;
|
|
8
|
+
public abstract getFactory(
|
|
9
|
+
initialStorage?: () => TStorage,
|
|
10
|
+
): AbstractCrdtDocFactory<TStorage>;
|
|
11
|
+
public abstract getFresh(): AbstractCrdtDoc<TStorage>;
|
|
12
|
+
public abstract getInitialized(
|
|
13
|
+
initialStorage?: () => TStorage,
|
|
14
|
+
): AbstractCrdtDoc<TStorage>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
DocApplyEncodedStateParams,
|
|
3
|
+
DocSubscribeCallbackParams,
|
|
4
|
+
} from "./AbstractCrdtDoc";
|
|
5
|
+
import { AbstractCrdtDoc } from "./AbstractCrdtDoc";
|
|
6
|
+
|
|
7
|
+
export class NoopCrdtDoc extends AbstractCrdtDoc<any> {
|
|
8
|
+
public applyEncodedState(params: DocApplyEncodedStateParams): this {
|
|
9
|
+
return this;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
public batchApplyEncodedState(
|
|
13
|
+
updates: readonly (
|
|
14
|
+
| string
|
|
15
|
+
| DocApplyEncodedStateParams
|
|
16
|
+
| null
|
|
17
|
+
| undefined
|
|
18
|
+
)[],
|
|
19
|
+
): this {
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public canRedo(): boolean {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public canUndo(): boolean {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public destroy(): void {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public get(key?: undefined): {};
|
|
36
|
+
public get<TKey extends never>(key: TKey): {}[TKey];
|
|
37
|
+
public get(key?: string): {} | undefined {
|
|
38
|
+
return typeof key === "string" ? undefined : {};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public getEncodedState(): string {
|
|
42
|
+
return "";
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public isEmpty(): boolean {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public redo(): this {
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public subscribe(
|
|
54
|
+
listener: (params: DocSubscribeCallbackParams<{}>) => void,
|
|
55
|
+
): () => void {
|
|
56
|
+
return () => undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public toJson(): {} {
|
|
60
|
+
return {};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public track(): this {
|
|
64
|
+
return this;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public transact(fn: () => void, origin?: string | undefined): this {
|
|
68
|
+
fn();
|
|
69
|
+
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public undo(): this {
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AbstractCrdtDocFactory } from "./AbstractCrdtDocFactory";
|
|
2
|
+
import { NoopCrdtDoc } from "./NoopCrdtDoc";
|
|
3
|
+
|
|
4
|
+
export class NoopCrdtDocFactory extends AbstractCrdtDocFactory<any> {
|
|
5
|
+
public getEmpty(): NoopCrdtDoc {
|
|
6
|
+
return new NoopCrdtDoc();
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
public getFactory(
|
|
10
|
+
initialStorage?: (() => {}) | undefined,
|
|
11
|
+
): NoopCrdtDocFactory {
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public getFresh(): NoopCrdtDoc {
|
|
16
|
+
return new NoopCrdtDoc();
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public getInitialized(
|
|
20
|
+
initialStorage?: (() => {}) | undefined,
|
|
21
|
+
): NoopCrdtDoc {
|
|
22
|
+
return new NoopCrdtDoc();
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { AbstractCrdtDoc } from "./AbstractCrdtDoc";
|
|
2
|
+
export type {
|
|
3
|
+
DocApplyEncodedStateParams,
|
|
4
|
+
DocSubscribeCallbackParams,
|
|
5
|
+
} from "./AbstractCrdtDoc";
|
|
6
|
+
export { AbstractCrdtDocFactory } from "./AbstractCrdtDocFactory";
|
|
7
|
+
export { AbstractCrdtType } from "./AbstractCrdtType";
|
|
8
|
+
export { NoopCrdtDoc } from "./NoopCrdtDoc";
|
|
9
|
+
export { NoopCrdtDocFactory } from "./NoopCrdtDocFactory";
|
|
10
|
+
export { noop } from "./noop";
|
|
11
|
+
export type { InferCrdtStorageJson } from "./types";
|
package/src/noop.ts
ADDED
package/src/types.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Json } from "@pluv/types";
|
|
2
|
+
import type { AbstractCrdtType } from "./AbstractCrdtType";
|
|
3
|
+
|
|
4
|
+
export type InferCrdtStorageJson<T extends unknown> =
|
|
5
|
+
T extends AbstractCrdtType<any, infer ICrdtJson>
|
|
6
|
+
? InferCrdtStorageJson<ICrdtJson>
|
|
7
|
+
: 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>
|
|
13
|
+
: T extends Json
|
|
14
|
+
? T
|
|
15
|
+
: string;
|