@pluv/crdt-loro 0.17.3 → 0.18.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/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +8 -0
- package/dist/index.js +17 -33
- package/dist/index.mjs +17 -33
- package/package.json +5 -5
- package/src/array/CrdtLoroArray.ts +2 -8
- package/src/array/array.ts +1 -3
- package/src/doc/CrdtLoroDoc.ts +19 -42
- package/src/doc/CrdtLoroDocFactory.ts +4 -12
- package/src/doc/doc.ts +1 -3
- package/src/map/CrdtLoroMap.ts +1 -3
- package/src/map/map.ts +1 -3
- package/src/object/CrdtLoroObject.ts +2 -6
- package/src/object/object.ts +1 -3
- package/src/shared/cloneType.ts +2 -6
- package/src/shared/isWrapper.ts +1 -5
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/crdt-loro@0.
|
|
2
|
+
> @pluv/crdt-loro@0.18.0 build /home/runner/work/pluv/pluv/packages/crdt-loro
|
|
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[32m18.
|
|
12
|
-
[32mESM[39m ⚡️ Build success in
|
|
13
|
-
[32mCJS[39m [1mdist/index.js [22m[32m19.
|
|
14
|
-
[32mCJS[39m ⚡️ Build success in
|
|
11
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m18.36 KB[39m
|
|
12
|
+
[32mESM[39m ⚡️ Build success in 132ms
|
|
13
|
+
[32mCJS[39m [1mdist/index.js [22m[32m19.37 KB[39m
|
|
14
|
+
[32mCJS[39m ⚡️ Build success in 132ms
|
|
15
15
|
[34mDTS[39m Build start
|
|
16
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 3106ms
|
|
17
17
|
[32mDTS[39m [1mdist/index.d.mts [22m[32m7.04 KB[39m
|
|
18
18
|
[32mDTS[39m [1mdist/index.d.ts [22m[32m7.04 KB[39m
|
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -72,9 +72,7 @@ var CrdtLoroMap = class extends import_crdt.AbstractCrdtType {
|
|
|
72
72
|
this._doc = null;
|
|
73
73
|
this._initialized = false;
|
|
74
74
|
this._value = new import_loro_crdt.LoroMap();
|
|
75
|
-
this.initialValue = value.map(
|
|
76
|
-
([k, v]) => [k, v]
|
|
77
|
-
);
|
|
75
|
+
this.initialValue = value.map(([k, v]) => [k, v]);
|
|
78
76
|
}
|
|
79
77
|
set doc(doc2) {
|
|
80
78
|
if (this._doc)
|
|
@@ -143,9 +141,7 @@ var CrdtLoroObject = class extends import_crdt2.AbstractCrdtType {
|
|
|
143
141
|
this._doc = null;
|
|
144
142
|
this._initialized = false;
|
|
145
143
|
this._value = new import_loro_crdt2.LoroMap();
|
|
146
|
-
this.initialValue = Object.entries(value).map(
|
|
147
|
-
([k, v]) => [k, v]
|
|
148
|
-
);
|
|
144
|
+
this.initialValue = Object.entries(value).map(([k, v]) => [k, v]);
|
|
149
145
|
}
|
|
150
146
|
set doc(doc2) {
|
|
151
147
|
if (this._doc)
|
|
@@ -454,10 +450,7 @@ var CrdtLoroArray = class extends import_crdt5.AbstractCrdtType {
|
|
|
454
450
|
throw new Error("This type is not yet supported");
|
|
455
451
|
}
|
|
456
452
|
const containerType = getLoroContainerType(item);
|
|
457
|
-
const container = this.value.insertContainer(
|
|
458
|
-
index + i,
|
|
459
|
-
containerType
|
|
460
|
-
);
|
|
453
|
+
const container = this.value.insertContainer(index + i, containerType);
|
|
461
454
|
cloneType({ source: item, target: container });
|
|
462
455
|
if (this._doc)
|
|
463
456
|
item.doc = this._doc;
|
|
@@ -603,25 +596,20 @@ var CrdtLoroDoc = class extends import_crdt6.AbstractCrdtDoc {
|
|
|
603
596
|
update
|
|
604
597
|
});
|
|
605
598
|
};
|
|
606
|
-
const subscriptionIds = Object.entries(this._storage).reduce(
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
},
|
|
612
|
-
/* @__PURE__ */ new Map()
|
|
613
|
-
);
|
|
599
|
+
const subscriptionIds = Object.entries(this._storage).reduce((map2, [key, crdtType]) => {
|
|
600
|
+
const container = crdtType.value;
|
|
601
|
+
const subscriptionId = container.subscribe(this.value, fn);
|
|
602
|
+
return map2.set(key, subscriptionId);
|
|
603
|
+
}, /* @__PURE__ */ new Map());
|
|
614
604
|
return () => {
|
|
615
|
-
Array.from(subscriptionIds.entries()).forEach(
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
throw new Error("Storage could not be found");
|
|
621
|
-
}
|
|
622
|
-
container.unsubscribe(this.value, subscriptionId);
|
|
605
|
+
Array.from(subscriptionIds.entries()).forEach(([key, subscriptionId]) => {
|
|
606
|
+
var _a, _b;
|
|
607
|
+
const container = (_b = (_a = this._storage[key]) == null ? void 0 : _a.value) != null ? _b : null;
|
|
608
|
+
if (!container) {
|
|
609
|
+
throw new Error("Storage could not be found");
|
|
623
610
|
}
|
|
624
|
-
|
|
611
|
+
container.unsubscribe(this.value, subscriptionId);
|
|
612
|
+
});
|
|
625
613
|
};
|
|
626
614
|
}
|
|
627
615
|
/**
|
|
@@ -659,9 +647,7 @@ var CrdtLoroDocFactory = class _CrdtLoroDocFactory extends import_crdt7.Abstract
|
|
|
659
647
|
return new CrdtLoroDoc();
|
|
660
648
|
}
|
|
661
649
|
getFactory(initialStorage) {
|
|
662
|
-
return new _CrdtLoroDocFactory(
|
|
663
|
-
initialStorage != null ? initialStorage : this._initialStorage
|
|
664
|
-
);
|
|
650
|
+
return new _CrdtLoroDocFactory(initialStorage != null ? initialStorage : this._initialStorage);
|
|
665
651
|
}
|
|
666
652
|
getFresh() {
|
|
667
653
|
const storage = this._initialStorage();
|
|
@@ -685,9 +671,7 @@ var CrdtLoroDocFactory = class _CrdtLoroDocFactory extends import_crdt7.Abstract
|
|
|
685
671
|
}
|
|
686
672
|
getInitialized(initialStorage) {
|
|
687
673
|
var _a;
|
|
688
|
-
return new CrdtLoroDoc(
|
|
689
|
-
(_a = initialStorage == null ? void 0 : initialStorage()) != null ? _a : this._initialStorage()
|
|
690
|
-
);
|
|
674
|
+
return new CrdtLoroDoc((_a = initialStorage == null ? void 0 : initialStorage()) != null ? _a : this._initialStorage());
|
|
691
675
|
}
|
|
692
676
|
};
|
|
693
677
|
|
package/dist/index.mjs
CHANGED
|
@@ -53,9 +53,7 @@ var CrdtLoroMap = class extends AbstractCrdtType {
|
|
|
53
53
|
this._doc = null;
|
|
54
54
|
this._initialized = false;
|
|
55
55
|
this._value = new LoroMap();
|
|
56
|
-
this.initialValue = value.map(
|
|
57
|
-
([k, v]) => [k, v]
|
|
58
|
-
);
|
|
56
|
+
this.initialValue = value.map(([k, v]) => [k, v]);
|
|
59
57
|
}
|
|
60
58
|
set doc(doc2) {
|
|
61
59
|
if (this._doc)
|
|
@@ -124,9 +122,7 @@ var CrdtLoroObject = class extends AbstractCrdtType2 {
|
|
|
124
122
|
this._doc = null;
|
|
125
123
|
this._initialized = false;
|
|
126
124
|
this._value = new LoroMap2();
|
|
127
|
-
this.initialValue = Object.entries(value).map(
|
|
128
|
-
([k, v]) => [k, v]
|
|
129
|
-
);
|
|
125
|
+
this.initialValue = Object.entries(value).map(([k, v]) => [k, v]);
|
|
130
126
|
}
|
|
131
127
|
set doc(doc2) {
|
|
132
128
|
if (this._doc)
|
|
@@ -435,10 +431,7 @@ var CrdtLoroArray = class extends AbstractCrdtType5 {
|
|
|
435
431
|
throw new Error("This type is not yet supported");
|
|
436
432
|
}
|
|
437
433
|
const containerType = getLoroContainerType(item);
|
|
438
|
-
const container = this.value.insertContainer(
|
|
439
|
-
index + i,
|
|
440
|
-
containerType
|
|
441
|
-
);
|
|
434
|
+
const container = this.value.insertContainer(index + i, containerType);
|
|
442
435
|
cloneType({ source: item, target: container });
|
|
443
436
|
if (this._doc)
|
|
444
437
|
item.doc = this._doc;
|
|
@@ -584,25 +577,20 @@ var CrdtLoroDoc = class extends AbstractCrdtDoc {
|
|
|
584
577
|
update
|
|
585
578
|
});
|
|
586
579
|
};
|
|
587
|
-
const subscriptionIds = Object.entries(this._storage).reduce(
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
},
|
|
593
|
-
/* @__PURE__ */ new Map()
|
|
594
|
-
);
|
|
580
|
+
const subscriptionIds = Object.entries(this._storage).reduce((map2, [key, crdtType]) => {
|
|
581
|
+
const container = crdtType.value;
|
|
582
|
+
const subscriptionId = container.subscribe(this.value, fn);
|
|
583
|
+
return map2.set(key, subscriptionId);
|
|
584
|
+
}, /* @__PURE__ */ new Map());
|
|
595
585
|
return () => {
|
|
596
|
-
Array.from(subscriptionIds.entries()).forEach(
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
throw new Error("Storage could not be found");
|
|
602
|
-
}
|
|
603
|
-
container.unsubscribe(this.value, subscriptionId);
|
|
586
|
+
Array.from(subscriptionIds.entries()).forEach(([key, subscriptionId]) => {
|
|
587
|
+
var _a, _b;
|
|
588
|
+
const container = (_b = (_a = this._storage[key]) == null ? void 0 : _a.value) != null ? _b : null;
|
|
589
|
+
if (!container) {
|
|
590
|
+
throw new Error("Storage could not be found");
|
|
604
591
|
}
|
|
605
|
-
|
|
592
|
+
container.unsubscribe(this.value, subscriptionId);
|
|
593
|
+
});
|
|
606
594
|
};
|
|
607
595
|
}
|
|
608
596
|
/**
|
|
@@ -640,9 +628,7 @@ var CrdtLoroDocFactory = class _CrdtLoroDocFactory extends AbstractCrdtDocFactor
|
|
|
640
628
|
return new CrdtLoroDoc();
|
|
641
629
|
}
|
|
642
630
|
getFactory(initialStorage) {
|
|
643
|
-
return new _CrdtLoroDocFactory(
|
|
644
|
-
initialStorage != null ? initialStorage : this._initialStorage
|
|
645
|
-
);
|
|
631
|
+
return new _CrdtLoroDocFactory(initialStorage != null ? initialStorage : this._initialStorage);
|
|
646
632
|
}
|
|
647
633
|
getFresh() {
|
|
648
634
|
const storage = this._initialStorage();
|
|
@@ -666,9 +652,7 @@ var CrdtLoroDocFactory = class _CrdtLoroDocFactory extends AbstractCrdtDocFactor
|
|
|
666
652
|
}
|
|
667
653
|
getInitialized(initialStorage) {
|
|
668
654
|
var _a;
|
|
669
|
-
return new CrdtLoroDoc(
|
|
670
|
-
(_a = initialStorage == null ? void 0 : initialStorage()) != null ? _a : this._initialStorage()
|
|
671
|
-
);
|
|
655
|
+
return new CrdtLoroDoc((_a = initialStorage == null ? void 0 : initialStorage()) != null ? _a : this._initialStorage());
|
|
672
656
|
}
|
|
673
657
|
};
|
|
674
658
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/crdt-loro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "loro for @pluv/io",
|
|
5
5
|
"author": "leedavidcs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"js-base64": "^3.7.7",
|
|
21
|
-
"@pluv/crdt": "^0.
|
|
22
|
-
"@pluv/types": "^0.
|
|
21
|
+
"@pluv/crdt": "^0.18.0",
|
|
22
|
+
"@pluv/types": "^0.18.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"loro-crdt": "^0.11.0"
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"loro-crdt": "^0.11.1",
|
|
30
30
|
"tsup": "^8.0.2",
|
|
31
31
|
"typescript": "^5.4.5",
|
|
32
|
-
"@pluv/tsconfig": "^0.
|
|
33
|
-
"eslint-config-pluv": "^0.
|
|
32
|
+
"@pluv/tsconfig": "^0.18.0",
|
|
33
|
+
"eslint-config-pluv": "^0.18.0"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
@@ -4,10 +4,7 @@ import type { CrdtLoroDoc } from "../doc/CrdtLoroDoc";
|
|
|
4
4
|
import { cloneType, getLoroContainerType, isWrapper } from "../shared";
|
|
5
5
|
import type { InferLoroJson } from "../types";
|
|
6
6
|
|
|
7
|
-
export class CrdtLoroArray<T extends unknown> extends AbstractCrdtType<
|
|
8
|
-
LoroList<T[]>,
|
|
9
|
-
InferLoroJson<T>[]
|
|
10
|
-
> {
|
|
7
|
+
export class CrdtLoroArray<T extends unknown> extends AbstractCrdtType<LoroList<T[]>, InferLoroJson<T>[]> {
|
|
11
8
|
public readonly initialValue: T[] | readonly T[];
|
|
12
9
|
|
|
13
10
|
private _doc: CrdtLoroDoc<any> | null = null;
|
|
@@ -68,10 +65,7 @@ export class CrdtLoroArray<T extends unknown> extends AbstractCrdtType<
|
|
|
68
65
|
}
|
|
69
66
|
|
|
70
67
|
const containerType = getLoroContainerType(item);
|
|
71
|
-
const container = this.value.insertContainer(
|
|
72
|
-
index + i,
|
|
73
|
-
containerType,
|
|
74
|
-
);
|
|
68
|
+
const container = this.value.insertContainer(index + i, containerType);
|
|
75
69
|
|
|
76
70
|
cloneType({ source: item, target: container as any });
|
|
77
71
|
if (this._doc) item.doc = this._doc;
|
package/src/array/array.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { CrdtLoroArray } from "./CrdtLoroArray";
|
|
2
2
|
|
|
3
|
-
export const array = <T extends unknown>(
|
|
4
|
-
value: T[] | readonly T[] = [],
|
|
5
|
-
): CrdtLoroArray<T> => {
|
|
3
|
+
export const array = <T extends unknown>(value: T[] | readonly T[] = []): CrdtLoroArray<T> => {
|
|
6
4
|
return new CrdtLoroArray<T>(value);
|
|
7
5
|
};
|
package/src/doc/CrdtLoroDoc.ts
CHANGED
|
@@ -56,10 +56,7 @@ export class CrdtLoroDoc<
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
public applyEncodedState(params: DocApplyEncodedStateParams): this {
|
|
59
|
-
const update =
|
|
60
|
-
typeof params.update === "string"
|
|
61
|
-
? toUint8Array(params.update)
|
|
62
|
-
: params.update;
|
|
59
|
+
const update = typeof params.update === "string" ? toUint8Array(params.update) : params.update;
|
|
63
60
|
|
|
64
61
|
if (!update) return this;
|
|
65
62
|
|
|
@@ -68,14 +65,7 @@ export class CrdtLoroDoc<
|
|
|
68
65
|
return this;
|
|
69
66
|
}
|
|
70
67
|
|
|
71
|
-
public batchApplyEncodedState(
|
|
72
|
-
updates: readonly (
|
|
73
|
-
| DocApplyEncodedStateParams
|
|
74
|
-
| string
|
|
75
|
-
| null
|
|
76
|
-
| undefined
|
|
77
|
-
)[],
|
|
78
|
-
): this {
|
|
68
|
+
public batchApplyEncodedState(updates: readonly (DocApplyEncodedStateParams | string | null | undefined)[]): this {
|
|
79
69
|
const _updates = updates.reduce<Uint8Array[]>((acc, item) => {
|
|
80
70
|
if (!item) return acc;
|
|
81
71
|
|
|
@@ -86,10 +76,7 @@ export class CrdtLoroDoc<
|
|
|
86
76
|
}
|
|
87
77
|
|
|
88
78
|
if (typeof item === "object") {
|
|
89
|
-
const update =
|
|
90
|
-
typeof item.update === "string"
|
|
91
|
-
? toUint8Array(item.update)
|
|
92
|
-
: item.update;
|
|
79
|
+
const update = typeof item.update === "string" ? toUint8Array(item.update) : item.update;
|
|
93
80
|
|
|
94
81
|
if (!update) return acc;
|
|
95
82
|
|
|
@@ -138,9 +125,7 @@ export class CrdtLoroDoc<
|
|
|
138
125
|
|
|
139
126
|
public get(key?: undefined): TStorage;
|
|
140
127
|
public get<TKey extends keyof TStorage>(key: TKey): TStorage[TKey];
|
|
141
|
-
public get<TKey extends keyof TStorage>(
|
|
142
|
-
key?: TKey,
|
|
143
|
-
): TStorage | TStorage[TKey] {
|
|
128
|
+
public get<TKey extends keyof TStorage>(key?: TKey): TStorage | TStorage[TKey] {
|
|
144
129
|
if (typeof key === "undefined") return this._storage;
|
|
145
130
|
|
|
146
131
|
return this._storage[key as TKey];
|
|
@@ -171,9 +156,7 @@ export class CrdtLoroDoc<
|
|
|
171
156
|
throw new Error("This is not yet supported");
|
|
172
157
|
}
|
|
173
158
|
|
|
174
|
-
public subscribe(
|
|
175
|
-
listener: (params: DocSubscribeCallbackParams<TStorage>) => void,
|
|
176
|
-
): () => void {
|
|
159
|
+
public subscribe(listener: (params: DocSubscribeCallbackParams<TStorage>) => void): () => void {
|
|
177
160
|
const fn = (event: LoroEventBatch) => {
|
|
178
161
|
const update = fromUint8Array(this.value.exportFrom());
|
|
179
162
|
|
|
@@ -185,29 +168,23 @@ export class CrdtLoroDoc<
|
|
|
185
168
|
});
|
|
186
169
|
};
|
|
187
170
|
|
|
188
|
-
const subscriptionIds = Object.entries(this._storage).reduce(
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const subscriptionId = container.subscribe(this.value, fn);
|
|
171
|
+
const subscriptionIds = Object.entries(this._storage).reduce((map, [key, crdtType]) => {
|
|
172
|
+
const container = crdtType.value as Container;
|
|
173
|
+
const subscriptionId = container.subscribe(this.value, fn);
|
|
192
174
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
new Map<string, number>(),
|
|
196
|
-
);
|
|
175
|
+
return map.set(key, subscriptionId);
|
|
176
|
+
}, new Map<string, number>());
|
|
197
177
|
|
|
198
178
|
return () => {
|
|
199
|
-
Array.from(subscriptionIds.entries()).forEach(
|
|
200
|
-
([key
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
container.unsubscribe(this.value, subscriptionId);
|
|
209
|
-
},
|
|
210
|
-
);
|
|
179
|
+
Array.from(subscriptionIds.entries()).forEach(([key, subscriptionId]) => {
|
|
180
|
+
const container = (this._storage[key]?.value ?? null) as Container | null;
|
|
181
|
+
|
|
182
|
+
if (!container) {
|
|
183
|
+
throw new Error("Storage could not be found");
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
container.unsubscribe(this.value, subscriptionId);
|
|
187
|
+
});
|
|
211
188
|
};
|
|
212
189
|
}
|
|
213
190
|
|
|
@@ -21,12 +21,8 @@ export class CrdtLoroDocFactory<
|
|
|
21
21
|
return new CrdtLoroDoc<TStorage>();
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
public getFactory(
|
|
25
|
-
|
|
26
|
-
): CrdtLoroDocFactory<TStorage> {
|
|
27
|
-
return new CrdtLoroDocFactory<TStorage>(
|
|
28
|
-
initialStorage ?? this._initialStorage,
|
|
29
|
-
);
|
|
24
|
+
public getFactory(initialStorage?: (() => TStorage) | undefined): CrdtLoroDocFactory<TStorage> {
|
|
25
|
+
return new CrdtLoroDocFactory<TStorage>(initialStorage ?? this._initialStorage);
|
|
30
26
|
}
|
|
31
27
|
|
|
32
28
|
public getFresh(): CrdtLoroDoc<TStorage> {
|
|
@@ -55,11 +51,7 @@ export class CrdtLoroDocFactory<
|
|
|
55
51
|
);
|
|
56
52
|
}
|
|
57
53
|
|
|
58
|
-
public getInitialized(
|
|
59
|
-
|
|
60
|
-
): CrdtLoroDoc<TStorage> {
|
|
61
|
-
return new CrdtLoroDoc<TStorage>(
|
|
62
|
-
initialStorage?.() ?? this._initialStorage(),
|
|
63
|
-
);
|
|
54
|
+
public getInitialized(initialStorage?: () => TStorage): CrdtLoroDoc<TStorage> {
|
|
55
|
+
return new CrdtLoroDoc<TStorage>(initialStorage?.() ?? this._initialStorage());
|
|
64
56
|
}
|
|
65
57
|
}
|
package/src/doc/doc.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { AbstractCrdtType } from "@pluv/crdt";
|
|
2
2
|
import { CrdtLoroDocFactory } from "./CrdtLoroDocFactory";
|
|
3
3
|
|
|
4
|
-
export const doc = <
|
|
5
|
-
TStorage extends Record<string, AbstractCrdtType<any, any>>,
|
|
6
|
-
>(
|
|
4
|
+
export const doc = <TStorage extends Record<string, AbstractCrdtType<any, any>>>(
|
|
7
5
|
value: () => TStorage = () => ({}) as TStorage,
|
|
8
6
|
): CrdtLoroDocFactory<TStorage> => {
|
|
9
7
|
return new CrdtLoroDocFactory<TStorage>(value);
|
package/src/map/CrdtLoroMap.ts
CHANGED
|
@@ -18,9 +18,7 @@ export class CrdtLoroMap<T extends unknown> extends AbstractCrdtType<
|
|
|
18
18
|
constructor(value: readonly (readonly [key: string, value: T])[] = []) {
|
|
19
19
|
super();
|
|
20
20
|
|
|
21
|
-
this.initialValue = value.map(
|
|
22
|
-
([k, v]) => [k, v] as [key: string, value: T],
|
|
23
|
-
);
|
|
21
|
+
this.initialValue = value.map(([k, v]) => [k, v] as [key: string, value: T]);
|
|
24
22
|
}
|
|
25
23
|
|
|
26
24
|
public set doc(doc: CrdtLoroDoc<any>) {
|
package/src/map/map.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { CrdtLoroMap } from "./CrdtLoroMap";
|
|
2
2
|
|
|
3
|
-
export const map = <T extends unknown>(
|
|
4
|
-
value: readonly (readonly [key: string, value: T])[] = [],
|
|
5
|
-
): CrdtLoroMap<T> => {
|
|
3
|
+
export const map = <T extends unknown>(value: readonly (readonly [key: string, value: T])[] = []): CrdtLoroMap<T> => {
|
|
6
4
|
return new CrdtLoroMap<T>(value);
|
|
7
5
|
};
|
|
@@ -4,9 +4,7 @@ import type { CrdtLoroDoc } from "../doc/CrdtLoroDoc";
|
|
|
4
4
|
import { cloneType, getLoroContainerType, isWrapper } from "../shared";
|
|
5
5
|
import type { InferLoroJson } from "../types";
|
|
6
6
|
|
|
7
|
-
export class CrdtLoroObject<
|
|
8
|
-
T extends Record<string, any>,
|
|
9
|
-
> extends AbstractCrdtType<LoroMap<T>, InferLoroJson<T>> {
|
|
7
|
+
export class CrdtLoroObject<T extends Record<string, any>> extends AbstractCrdtType<LoroMap<T>, InferLoroJson<T>> {
|
|
10
8
|
public readonly initialValue: readonly (readonly [key: string, value: T])[];
|
|
11
9
|
|
|
12
10
|
private _doc: CrdtLoroDoc<any> | null = null;
|
|
@@ -16,9 +14,7 @@ export class CrdtLoroObject<
|
|
|
16
14
|
constructor(value: T) {
|
|
17
15
|
super();
|
|
18
16
|
|
|
19
|
-
this.initialValue = Object.entries(value).map(
|
|
20
|
-
([k, v]) => [k, v] as [key: string, value: T],
|
|
21
|
-
);
|
|
17
|
+
this.initialValue = Object.entries(value).map(([k, v]) => [k, v] as [key: string, value: T]);
|
|
22
18
|
}
|
|
23
19
|
|
|
24
20
|
public set doc(doc: CrdtLoroDoc<any>) {
|
package/src/object/object.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { CrdtLoroObject } from "./CrdtLoroObject";
|
|
2
2
|
|
|
3
|
-
export const object = <T extends Record<string, any>>(
|
|
4
|
-
value: T,
|
|
5
|
-
): CrdtLoroObject<T> => {
|
|
3
|
+
export const object = <T extends Record<string, any>>(value: T): CrdtLoroObject<T> => {
|
|
6
4
|
return new CrdtLoroObject<T>(value);
|
|
7
5
|
};
|
package/src/shared/cloneType.ts
CHANGED
|
@@ -144,9 +144,7 @@ function cloneMap<T extends unknown>(params: CloneMapParams<T>): void {
|
|
|
144
144
|
});
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
function cloneObject<T extends Record<string, any>>(
|
|
148
|
-
params: CloneObjectParams<T>,
|
|
149
|
-
): void {
|
|
147
|
+
function cloneObject<T extends Record<string, any>>(params: CloneObjectParams<T>): void {
|
|
150
148
|
const { source, target } = params;
|
|
151
149
|
|
|
152
150
|
const items = source.initialValue;
|
|
@@ -205,9 +203,7 @@ function cloneText(params: CloneTextParams): void {
|
|
|
205
203
|
source.insert(0, source.initalValue);
|
|
206
204
|
}
|
|
207
205
|
|
|
208
|
-
export const cloneType = <TType extends Container>(
|
|
209
|
-
params: CloneTypeParams<TType>,
|
|
210
|
-
) => {
|
|
206
|
+
export const cloneType = <TType extends Container>(params: CloneTypeParams<TType>) => {
|
|
211
207
|
const { source, target } = params;
|
|
212
208
|
|
|
213
209
|
if (source instanceof CrdtLoroArray) {
|
package/src/shared/isWrapper.ts
CHANGED
|
@@ -5,11 +5,7 @@ import { CrdtLoroText } from "../text/CrdtLoroText";
|
|
|
5
5
|
|
|
6
6
|
export const isWrapper = (
|
|
7
7
|
item: any,
|
|
8
|
-
): item is
|
|
9
|
-
| CrdtLoroArray<any>
|
|
10
|
-
| CrdtLoroMap<any>
|
|
11
|
-
| CrdtLoroObject<any>
|
|
12
|
-
| CrdtLoroText => {
|
|
8
|
+
): item is CrdtLoroArray<any> | CrdtLoroMap<any> | CrdtLoroObject<any> | CrdtLoroText => {
|
|
13
9
|
return (
|
|
14
10
|
item instanceof CrdtLoroArray ||
|
|
15
11
|
item instanceof CrdtLoroMap ||
|