@pluv/crdt-loro 0.17.3 → 0.19.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 +15 -15
- package/CHANGELOG.md +15 -0
- package/dist/index.js +41 -81
- package/dist/index.mjs +41 -81
- package/package.json +6 -6
- 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,18 +1,18 @@
|
|
|
1
1
|
|
|
2
|
-
> @pluv/crdt-loro@0.
|
|
2
|
+
> @pluv/crdt-loro@0.19.0 build /home/runner/work/pluv/pluv/packages/crdt-loro
|
|
3
3
|
> tsup src/index.ts --format esm,cjs --dts
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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 18.22 KB
|
|
12
|
+
ESM ⚡️ Build success in 114ms
|
|
13
|
+
CJS dist/index.js 19.23 KB
|
|
14
|
+
CJS ⚡️ Build success in 114ms
|
|
15
|
+
DTS Build start
|
|
16
|
+
DTS ⚡️ Build success in 2568ms
|
|
17
|
+
DTS dist/index.d.mts 7.04 KB
|
|
18
|
+
DTS dist/index.d.ts 7.04 KB
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @pluv/crdt-loro
|
|
2
2
|
|
|
3
|
+
## 0.19.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @pluv/crdt@0.19.0
|
|
8
|
+
- @pluv/types@0.19.0
|
|
9
|
+
|
|
10
|
+
## 0.18.0
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [99b5ca9]
|
|
15
|
+
- @pluv/types@0.18.0
|
|
16
|
+
- @pluv/crdt@0.18.0
|
|
17
|
+
|
|
3
18
|
## 0.17.3
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -72,13 +72,10 @@ 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
|
-
if (this._doc)
|
|
81
|
-
throw new Error("Cannot overwrite array doc");
|
|
78
|
+
if (this._doc) throw new Error("Cannot overwrite array doc");
|
|
82
79
|
this._doc = doc2;
|
|
83
80
|
}
|
|
84
81
|
get size() {
|
|
@@ -88,8 +85,7 @@ var CrdtLoroMap = class extends import_crdt.AbstractCrdtType {
|
|
|
88
85
|
return this._value;
|
|
89
86
|
}
|
|
90
87
|
set value(value) {
|
|
91
|
-
if (this._initialized)
|
|
92
|
-
throw new Error("Cannot re-assign map");
|
|
88
|
+
if (this._initialized) throw new Error("Cannot re-assign map");
|
|
93
89
|
this._initialized = true;
|
|
94
90
|
this._value = value;
|
|
95
91
|
cloneType({ source: this, target: this.value });
|
|
@@ -115,8 +111,7 @@ var CrdtLoroMap = class extends import_crdt.AbstractCrdtType {
|
|
|
115
111
|
const containerType = getLoroContainerType(value);
|
|
116
112
|
const container = this.value.setContainer(prop, containerType);
|
|
117
113
|
cloneType({ source: value, target: container });
|
|
118
|
-
if (this._doc)
|
|
119
|
-
value.doc = this._doc;
|
|
114
|
+
if (this._doc) value.doc = this._doc;
|
|
120
115
|
(_b = this._doc) == null ? void 0 : _b.value.commit();
|
|
121
116
|
return this;
|
|
122
117
|
}
|
|
@@ -124,8 +119,7 @@ var CrdtLoroMap = class extends import_crdt.AbstractCrdtType {
|
|
|
124
119
|
return this.value.toJson();
|
|
125
120
|
}
|
|
126
121
|
_guardInitialized() {
|
|
127
|
-
if (!this._initialized)
|
|
128
|
-
throw new Error("Array is not yet initialized");
|
|
122
|
+
if (!this._initialized) throw new Error("Array is not yet initialized");
|
|
129
123
|
}
|
|
130
124
|
};
|
|
131
125
|
|
|
@@ -143,13 +137,10 @@ var CrdtLoroObject = class extends import_crdt2.AbstractCrdtType {
|
|
|
143
137
|
this._doc = null;
|
|
144
138
|
this._initialized = false;
|
|
145
139
|
this._value = new import_loro_crdt2.LoroMap();
|
|
146
|
-
this.initialValue = Object.entries(value).map(
|
|
147
|
-
([k, v]) => [k, v]
|
|
148
|
-
);
|
|
140
|
+
this.initialValue = Object.entries(value).map(([k, v]) => [k, v]);
|
|
149
141
|
}
|
|
150
142
|
set doc(doc2) {
|
|
151
|
-
if (this._doc)
|
|
152
|
-
throw new Error("Cannot overwrite array doc");
|
|
143
|
+
if (this._doc) throw new Error("Cannot overwrite array doc");
|
|
153
144
|
this._doc = doc2;
|
|
154
145
|
}
|
|
155
146
|
get size() {
|
|
@@ -159,8 +150,7 @@ var CrdtLoroObject = class extends import_crdt2.AbstractCrdtType {
|
|
|
159
150
|
return this._value;
|
|
160
151
|
}
|
|
161
152
|
set value(value) {
|
|
162
|
-
if (this._initialized)
|
|
163
|
-
throw new Error("Cannot re-assign map");
|
|
153
|
+
if (this._initialized) throw new Error("Cannot re-assign map");
|
|
164
154
|
this._initialized = true;
|
|
165
155
|
this._value = value;
|
|
166
156
|
cloneType({ source: this, target: this.value });
|
|
@@ -179,8 +169,7 @@ var CrdtLoroObject = class extends import_crdt2.AbstractCrdtType {
|
|
|
179
169
|
const containerType = getLoroContainerType(value);
|
|
180
170
|
const container = this.value.setContainer(prop, containerType);
|
|
181
171
|
cloneType({ source: value, target: container });
|
|
182
|
-
if (this._doc)
|
|
183
|
-
value.doc = this._doc;
|
|
172
|
+
if (this._doc) value.doc = this._doc;
|
|
184
173
|
(_b = this._doc) == null ? void 0 : _b.value.commit();
|
|
185
174
|
return this;
|
|
186
175
|
}
|
|
@@ -188,8 +177,7 @@ var CrdtLoroObject = class extends import_crdt2.AbstractCrdtType {
|
|
|
188
177
|
return this.value.toJson();
|
|
189
178
|
}
|
|
190
179
|
_guardInitialized() {
|
|
191
|
-
if (!this._initialized)
|
|
192
|
-
throw new Error("Array is not yet initialized");
|
|
180
|
+
if (!this._initialized) throw new Error("Array is not yet initialized");
|
|
193
181
|
}
|
|
194
182
|
};
|
|
195
183
|
|
|
@@ -211,8 +199,7 @@ var CrdtLoroText = class extends import_crdt3.AbstractCrdtType {
|
|
|
211
199
|
this.value = new import_loro_crdt3.LoroText();
|
|
212
200
|
}
|
|
213
201
|
set doc(doc2) {
|
|
214
|
-
if (this._doc)
|
|
215
|
-
throw new Error("Cannot overwrite array doc");
|
|
202
|
+
if (this._doc) throw new Error("Cannot overwrite array doc");
|
|
216
203
|
this._doc = doc2;
|
|
217
204
|
}
|
|
218
205
|
get length() {
|
|
@@ -222,8 +209,7 @@ var CrdtLoroText = class extends import_crdt3.AbstractCrdtType {
|
|
|
222
209
|
return this._value;
|
|
223
210
|
}
|
|
224
211
|
set value(value) {
|
|
225
|
-
if (this._initialized)
|
|
226
|
-
throw new Error("Cannot re-assign text");
|
|
212
|
+
if (this._initialized) throw new Error("Cannot re-assign text");
|
|
227
213
|
this._initialized = true;
|
|
228
214
|
this._value = value;
|
|
229
215
|
cloneType({ source: this, target: this.value });
|
|
@@ -246,8 +232,7 @@ var CrdtLoroText = class extends import_crdt3.AbstractCrdtType {
|
|
|
246
232
|
return this.value.toString();
|
|
247
233
|
}
|
|
248
234
|
_guardInitialized() {
|
|
249
|
-
if (!this._initialized)
|
|
250
|
-
throw new Error("Array is not yet initialized");
|
|
235
|
+
if (!this._initialized) throw new Error("Array is not yet initialized");
|
|
251
236
|
}
|
|
252
237
|
};
|
|
253
238
|
|
|
@@ -390,14 +375,10 @@ var cloneType = (params) => {
|
|
|
390
375
|
|
|
391
376
|
// src/shared/getLoroContainerType.ts
|
|
392
377
|
var getLoroContainerType = (value) => {
|
|
393
|
-
if (value instanceof CrdtLoroArray)
|
|
394
|
-
|
|
395
|
-
if (value instanceof
|
|
396
|
-
|
|
397
|
-
if (value instanceof CrdtLoroObject)
|
|
398
|
-
return "Map";
|
|
399
|
-
if (value instanceof CrdtLoroText)
|
|
400
|
-
return "Text";
|
|
378
|
+
if (value instanceof CrdtLoroArray) return "List";
|
|
379
|
+
if (value instanceof CrdtLoroMap) return "Map";
|
|
380
|
+
if (value instanceof CrdtLoroObject) return "Map";
|
|
381
|
+
if (value instanceof CrdtLoroText) return "Text";
|
|
401
382
|
throw new Error("This type is not yet supported");
|
|
402
383
|
};
|
|
403
384
|
|
|
@@ -416,8 +397,7 @@ var CrdtLoroArray = class extends import_crdt5.AbstractCrdtType {
|
|
|
416
397
|
this.initialValue = value.slice();
|
|
417
398
|
}
|
|
418
399
|
set doc(doc2) {
|
|
419
|
-
if (this._doc)
|
|
420
|
-
throw new Error("Cannot overwrite array doc");
|
|
400
|
+
if (this._doc) throw new Error("Cannot overwrite array doc");
|
|
421
401
|
this._doc = doc2;
|
|
422
402
|
}
|
|
423
403
|
get length() {
|
|
@@ -427,8 +407,7 @@ var CrdtLoroArray = class extends import_crdt5.AbstractCrdtType {
|
|
|
427
407
|
return this._value;
|
|
428
408
|
}
|
|
429
409
|
set value(value) {
|
|
430
|
-
if (this._initialized)
|
|
431
|
-
throw new Error("Cannot re-assign array");
|
|
410
|
+
if (this._initialized) throw new Error("Cannot re-assign array");
|
|
432
411
|
this._initialized = true;
|
|
433
412
|
this._value = value;
|
|
434
413
|
cloneType({ source: this, target: this.value });
|
|
@@ -454,13 +433,9 @@ var CrdtLoroArray = class extends import_crdt5.AbstractCrdtType {
|
|
|
454
433
|
throw new Error("This type is not yet supported");
|
|
455
434
|
}
|
|
456
435
|
const containerType = getLoroContainerType(item);
|
|
457
|
-
const container = this.value.insertContainer(
|
|
458
|
-
index + i,
|
|
459
|
-
containerType
|
|
460
|
-
);
|
|
436
|
+
const container = this.value.insertContainer(index + i, containerType);
|
|
461
437
|
cloneType({ source: item, target: container });
|
|
462
|
-
if (this._doc)
|
|
463
|
-
item.doc = this._doc;
|
|
438
|
+
if (this._doc) item.doc = this._doc;
|
|
464
439
|
return this;
|
|
465
440
|
});
|
|
466
441
|
(_a = this._doc) == null ? void 0 : _a.value.commit();
|
|
@@ -476,8 +451,7 @@ var CrdtLoroArray = class extends import_crdt5.AbstractCrdtType {
|
|
|
476
451
|
return this.value.toJson();
|
|
477
452
|
}
|
|
478
453
|
_guardInitialized() {
|
|
479
|
-
if (!this._initialized)
|
|
480
|
-
throw new Error("Array is not yet initialized");
|
|
454
|
+
if (!this._initialized) throw new Error("Array is not yet initialized");
|
|
481
455
|
}
|
|
482
456
|
};
|
|
483
457
|
|
|
@@ -518,31 +492,27 @@ var CrdtLoroDoc = class extends import_crdt6.AbstractCrdtDoc {
|
|
|
518
492
|
}
|
|
519
493
|
applyEncodedState(params) {
|
|
520
494
|
const update = typeof params.update === "string" ? (0, import_js_base64.toUint8Array)(params.update) : params.update;
|
|
521
|
-
if (!update)
|
|
522
|
-
return this;
|
|
495
|
+
if (!update) return this;
|
|
523
496
|
this.value.import(update);
|
|
524
497
|
return this;
|
|
525
498
|
}
|
|
526
499
|
batchApplyEncodedState(updates) {
|
|
527
500
|
var _a;
|
|
528
501
|
const _updates = updates.reduce((acc, item) => {
|
|
529
|
-
if (!item)
|
|
530
|
-
return acc;
|
|
502
|
+
if (!item) return acc;
|
|
531
503
|
if (typeof item === "string") {
|
|
532
504
|
acc.push((0, import_js_base64.toUint8Array)(item));
|
|
533
505
|
return acc;
|
|
534
506
|
}
|
|
535
507
|
if (typeof item === "object") {
|
|
536
508
|
const update = typeof item.update === "string" ? (0, import_js_base64.toUint8Array)(item.update) : item.update;
|
|
537
|
-
if (!update)
|
|
538
|
-
return acc;
|
|
509
|
+
if (!update) return acc;
|
|
539
510
|
acc.push(update);
|
|
540
511
|
return acc;
|
|
541
512
|
}
|
|
542
513
|
return acc;
|
|
543
514
|
}, []);
|
|
544
|
-
if (!_updates.length)
|
|
545
|
-
return this;
|
|
515
|
+
if (!_updates.length) return this;
|
|
546
516
|
if (_updates.length === 1) {
|
|
547
517
|
const update = (_a = _updates[0]) != null ? _a : null;
|
|
548
518
|
update && this.value.import(update);
|
|
@@ -569,8 +539,7 @@ var CrdtLoroDoc = class extends import_crdt6.AbstractCrdtDoc {
|
|
|
569
539
|
return;
|
|
570
540
|
}
|
|
571
541
|
get(key) {
|
|
572
|
-
if (typeof key === "undefined")
|
|
573
|
-
return this._storage;
|
|
542
|
+
if (typeof key === "undefined") return this._storage;
|
|
574
543
|
return this._storage[key];
|
|
575
544
|
}
|
|
576
545
|
getEncodedState() {
|
|
@@ -603,25 +572,20 @@ var CrdtLoroDoc = class extends import_crdt6.AbstractCrdtDoc {
|
|
|
603
572
|
update
|
|
604
573
|
});
|
|
605
574
|
};
|
|
606
|
-
const subscriptionIds = Object.entries(this._storage).reduce(
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
},
|
|
612
|
-
/* @__PURE__ */ new Map()
|
|
613
|
-
);
|
|
575
|
+
const subscriptionIds = Object.entries(this._storage).reduce((map2, [key, crdtType]) => {
|
|
576
|
+
const container = crdtType.value;
|
|
577
|
+
const subscriptionId = container.subscribe(this.value, fn);
|
|
578
|
+
return map2.set(key, subscriptionId);
|
|
579
|
+
}, /* @__PURE__ */ new Map());
|
|
614
580
|
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);
|
|
581
|
+
Array.from(subscriptionIds.entries()).forEach(([key, subscriptionId]) => {
|
|
582
|
+
var _a, _b;
|
|
583
|
+
const container = (_b = (_a = this._storage[key]) == null ? void 0 : _a.value) != null ? _b : null;
|
|
584
|
+
if (!container) {
|
|
585
|
+
throw new Error("Storage could not be found");
|
|
623
586
|
}
|
|
624
|
-
|
|
587
|
+
container.unsubscribe(this.value, subscriptionId);
|
|
588
|
+
});
|
|
625
589
|
};
|
|
626
590
|
}
|
|
627
591
|
/**
|
|
@@ -659,9 +623,7 @@ var CrdtLoroDocFactory = class _CrdtLoroDocFactory extends import_crdt7.Abstract
|
|
|
659
623
|
return new CrdtLoroDoc();
|
|
660
624
|
}
|
|
661
625
|
getFactory(initialStorage) {
|
|
662
|
-
return new _CrdtLoroDocFactory(
|
|
663
|
-
initialStorage != null ? initialStorage : this._initialStorage
|
|
664
|
-
);
|
|
626
|
+
return new _CrdtLoroDocFactory(initialStorage != null ? initialStorage : this._initialStorage);
|
|
665
627
|
}
|
|
666
628
|
getFresh() {
|
|
667
629
|
const storage = this._initialStorage();
|
|
@@ -685,9 +647,7 @@ var CrdtLoroDocFactory = class _CrdtLoroDocFactory extends import_crdt7.Abstract
|
|
|
685
647
|
}
|
|
686
648
|
getInitialized(initialStorage) {
|
|
687
649
|
var _a;
|
|
688
|
-
return new CrdtLoroDoc(
|
|
689
|
-
(_a = initialStorage == null ? void 0 : initialStorage()) != null ? _a : this._initialStorage()
|
|
690
|
-
);
|
|
650
|
+
return new CrdtLoroDoc((_a = initialStorage == null ? void 0 : initialStorage()) != null ? _a : this._initialStorage());
|
|
691
651
|
}
|
|
692
652
|
};
|
|
693
653
|
|
package/dist/index.mjs
CHANGED
|
@@ -53,13 +53,10 @@ 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
|
-
if (this._doc)
|
|
62
|
-
throw new Error("Cannot overwrite array doc");
|
|
59
|
+
if (this._doc) throw new Error("Cannot overwrite array doc");
|
|
63
60
|
this._doc = doc2;
|
|
64
61
|
}
|
|
65
62
|
get size() {
|
|
@@ -69,8 +66,7 @@ var CrdtLoroMap = class extends AbstractCrdtType {
|
|
|
69
66
|
return this._value;
|
|
70
67
|
}
|
|
71
68
|
set value(value) {
|
|
72
|
-
if (this._initialized)
|
|
73
|
-
throw new Error("Cannot re-assign map");
|
|
69
|
+
if (this._initialized) throw new Error("Cannot re-assign map");
|
|
74
70
|
this._initialized = true;
|
|
75
71
|
this._value = value;
|
|
76
72
|
cloneType({ source: this, target: this.value });
|
|
@@ -96,8 +92,7 @@ var CrdtLoroMap = class extends AbstractCrdtType {
|
|
|
96
92
|
const containerType = getLoroContainerType(value);
|
|
97
93
|
const container = this.value.setContainer(prop, containerType);
|
|
98
94
|
cloneType({ source: value, target: container });
|
|
99
|
-
if (this._doc)
|
|
100
|
-
value.doc = this._doc;
|
|
95
|
+
if (this._doc) value.doc = this._doc;
|
|
101
96
|
(_b = this._doc) == null ? void 0 : _b.value.commit();
|
|
102
97
|
return this;
|
|
103
98
|
}
|
|
@@ -105,8 +100,7 @@ var CrdtLoroMap = class extends AbstractCrdtType {
|
|
|
105
100
|
return this.value.toJson();
|
|
106
101
|
}
|
|
107
102
|
_guardInitialized() {
|
|
108
|
-
if (!this._initialized)
|
|
109
|
-
throw new Error("Array is not yet initialized");
|
|
103
|
+
if (!this._initialized) throw new Error("Array is not yet initialized");
|
|
110
104
|
}
|
|
111
105
|
};
|
|
112
106
|
|
|
@@ -124,13 +118,10 @@ var CrdtLoroObject = class extends AbstractCrdtType2 {
|
|
|
124
118
|
this._doc = null;
|
|
125
119
|
this._initialized = false;
|
|
126
120
|
this._value = new LoroMap2();
|
|
127
|
-
this.initialValue = Object.entries(value).map(
|
|
128
|
-
([k, v]) => [k, v]
|
|
129
|
-
);
|
|
121
|
+
this.initialValue = Object.entries(value).map(([k, v]) => [k, v]);
|
|
130
122
|
}
|
|
131
123
|
set doc(doc2) {
|
|
132
|
-
if (this._doc)
|
|
133
|
-
throw new Error("Cannot overwrite array doc");
|
|
124
|
+
if (this._doc) throw new Error("Cannot overwrite array doc");
|
|
134
125
|
this._doc = doc2;
|
|
135
126
|
}
|
|
136
127
|
get size() {
|
|
@@ -140,8 +131,7 @@ var CrdtLoroObject = class extends AbstractCrdtType2 {
|
|
|
140
131
|
return this._value;
|
|
141
132
|
}
|
|
142
133
|
set value(value) {
|
|
143
|
-
if (this._initialized)
|
|
144
|
-
throw new Error("Cannot re-assign map");
|
|
134
|
+
if (this._initialized) throw new Error("Cannot re-assign map");
|
|
145
135
|
this._initialized = true;
|
|
146
136
|
this._value = value;
|
|
147
137
|
cloneType({ source: this, target: this.value });
|
|
@@ -160,8 +150,7 @@ var CrdtLoroObject = class extends AbstractCrdtType2 {
|
|
|
160
150
|
const containerType = getLoroContainerType(value);
|
|
161
151
|
const container = this.value.setContainer(prop, containerType);
|
|
162
152
|
cloneType({ source: value, target: container });
|
|
163
|
-
if (this._doc)
|
|
164
|
-
value.doc = this._doc;
|
|
153
|
+
if (this._doc) value.doc = this._doc;
|
|
165
154
|
(_b = this._doc) == null ? void 0 : _b.value.commit();
|
|
166
155
|
return this;
|
|
167
156
|
}
|
|
@@ -169,8 +158,7 @@ var CrdtLoroObject = class extends AbstractCrdtType2 {
|
|
|
169
158
|
return this.value.toJson();
|
|
170
159
|
}
|
|
171
160
|
_guardInitialized() {
|
|
172
|
-
if (!this._initialized)
|
|
173
|
-
throw new Error("Array is not yet initialized");
|
|
161
|
+
if (!this._initialized) throw new Error("Array is not yet initialized");
|
|
174
162
|
}
|
|
175
163
|
};
|
|
176
164
|
|
|
@@ -192,8 +180,7 @@ var CrdtLoroText = class extends AbstractCrdtType3 {
|
|
|
192
180
|
this.value = new LoroText();
|
|
193
181
|
}
|
|
194
182
|
set doc(doc2) {
|
|
195
|
-
if (this._doc)
|
|
196
|
-
throw new Error("Cannot overwrite array doc");
|
|
183
|
+
if (this._doc) throw new Error("Cannot overwrite array doc");
|
|
197
184
|
this._doc = doc2;
|
|
198
185
|
}
|
|
199
186
|
get length() {
|
|
@@ -203,8 +190,7 @@ var CrdtLoroText = class extends AbstractCrdtType3 {
|
|
|
203
190
|
return this._value;
|
|
204
191
|
}
|
|
205
192
|
set value(value) {
|
|
206
|
-
if (this._initialized)
|
|
207
|
-
throw new Error("Cannot re-assign text");
|
|
193
|
+
if (this._initialized) throw new Error("Cannot re-assign text");
|
|
208
194
|
this._initialized = true;
|
|
209
195
|
this._value = value;
|
|
210
196
|
cloneType({ source: this, target: this.value });
|
|
@@ -227,8 +213,7 @@ var CrdtLoroText = class extends AbstractCrdtType3 {
|
|
|
227
213
|
return this.value.toString();
|
|
228
214
|
}
|
|
229
215
|
_guardInitialized() {
|
|
230
|
-
if (!this._initialized)
|
|
231
|
-
throw new Error("Array is not yet initialized");
|
|
216
|
+
if (!this._initialized) throw new Error("Array is not yet initialized");
|
|
232
217
|
}
|
|
233
218
|
};
|
|
234
219
|
|
|
@@ -371,14 +356,10 @@ var cloneType = (params) => {
|
|
|
371
356
|
|
|
372
357
|
// src/shared/getLoroContainerType.ts
|
|
373
358
|
var getLoroContainerType = (value) => {
|
|
374
|
-
if (value instanceof CrdtLoroArray)
|
|
375
|
-
|
|
376
|
-
if (value instanceof
|
|
377
|
-
|
|
378
|
-
if (value instanceof CrdtLoroObject)
|
|
379
|
-
return "Map";
|
|
380
|
-
if (value instanceof CrdtLoroText)
|
|
381
|
-
return "Text";
|
|
359
|
+
if (value instanceof CrdtLoroArray) return "List";
|
|
360
|
+
if (value instanceof CrdtLoroMap) return "Map";
|
|
361
|
+
if (value instanceof CrdtLoroObject) return "Map";
|
|
362
|
+
if (value instanceof CrdtLoroText) return "Text";
|
|
382
363
|
throw new Error("This type is not yet supported");
|
|
383
364
|
};
|
|
384
365
|
|
|
@@ -397,8 +378,7 @@ var CrdtLoroArray = class extends AbstractCrdtType5 {
|
|
|
397
378
|
this.initialValue = value.slice();
|
|
398
379
|
}
|
|
399
380
|
set doc(doc2) {
|
|
400
|
-
if (this._doc)
|
|
401
|
-
throw new Error("Cannot overwrite array doc");
|
|
381
|
+
if (this._doc) throw new Error("Cannot overwrite array doc");
|
|
402
382
|
this._doc = doc2;
|
|
403
383
|
}
|
|
404
384
|
get length() {
|
|
@@ -408,8 +388,7 @@ var CrdtLoroArray = class extends AbstractCrdtType5 {
|
|
|
408
388
|
return this._value;
|
|
409
389
|
}
|
|
410
390
|
set value(value) {
|
|
411
|
-
if (this._initialized)
|
|
412
|
-
throw new Error("Cannot re-assign array");
|
|
391
|
+
if (this._initialized) throw new Error("Cannot re-assign array");
|
|
413
392
|
this._initialized = true;
|
|
414
393
|
this._value = value;
|
|
415
394
|
cloneType({ source: this, target: this.value });
|
|
@@ -435,13 +414,9 @@ var CrdtLoroArray = class extends AbstractCrdtType5 {
|
|
|
435
414
|
throw new Error("This type is not yet supported");
|
|
436
415
|
}
|
|
437
416
|
const containerType = getLoroContainerType(item);
|
|
438
|
-
const container = this.value.insertContainer(
|
|
439
|
-
index + i,
|
|
440
|
-
containerType
|
|
441
|
-
);
|
|
417
|
+
const container = this.value.insertContainer(index + i, containerType);
|
|
442
418
|
cloneType({ source: item, target: container });
|
|
443
|
-
if (this._doc)
|
|
444
|
-
item.doc = this._doc;
|
|
419
|
+
if (this._doc) item.doc = this._doc;
|
|
445
420
|
return this;
|
|
446
421
|
});
|
|
447
422
|
(_a = this._doc) == null ? void 0 : _a.value.commit();
|
|
@@ -457,8 +432,7 @@ var CrdtLoroArray = class extends AbstractCrdtType5 {
|
|
|
457
432
|
return this.value.toJson();
|
|
458
433
|
}
|
|
459
434
|
_guardInitialized() {
|
|
460
|
-
if (!this._initialized)
|
|
461
|
-
throw new Error("Array is not yet initialized");
|
|
435
|
+
if (!this._initialized) throw new Error("Array is not yet initialized");
|
|
462
436
|
}
|
|
463
437
|
};
|
|
464
438
|
|
|
@@ -499,31 +473,27 @@ var CrdtLoroDoc = class extends AbstractCrdtDoc {
|
|
|
499
473
|
}
|
|
500
474
|
applyEncodedState(params) {
|
|
501
475
|
const update = typeof params.update === "string" ? toUint8Array(params.update) : params.update;
|
|
502
|
-
if (!update)
|
|
503
|
-
return this;
|
|
476
|
+
if (!update) return this;
|
|
504
477
|
this.value.import(update);
|
|
505
478
|
return this;
|
|
506
479
|
}
|
|
507
480
|
batchApplyEncodedState(updates) {
|
|
508
481
|
var _a;
|
|
509
482
|
const _updates = updates.reduce((acc, item) => {
|
|
510
|
-
if (!item)
|
|
511
|
-
return acc;
|
|
483
|
+
if (!item) return acc;
|
|
512
484
|
if (typeof item === "string") {
|
|
513
485
|
acc.push(toUint8Array(item));
|
|
514
486
|
return acc;
|
|
515
487
|
}
|
|
516
488
|
if (typeof item === "object") {
|
|
517
489
|
const update = typeof item.update === "string" ? toUint8Array(item.update) : item.update;
|
|
518
|
-
if (!update)
|
|
519
|
-
return acc;
|
|
490
|
+
if (!update) return acc;
|
|
520
491
|
acc.push(update);
|
|
521
492
|
return acc;
|
|
522
493
|
}
|
|
523
494
|
return acc;
|
|
524
495
|
}, []);
|
|
525
|
-
if (!_updates.length)
|
|
526
|
-
return this;
|
|
496
|
+
if (!_updates.length) return this;
|
|
527
497
|
if (_updates.length === 1) {
|
|
528
498
|
const update = (_a = _updates[0]) != null ? _a : null;
|
|
529
499
|
update && this.value.import(update);
|
|
@@ -550,8 +520,7 @@ var CrdtLoroDoc = class extends AbstractCrdtDoc {
|
|
|
550
520
|
return;
|
|
551
521
|
}
|
|
552
522
|
get(key) {
|
|
553
|
-
if (typeof key === "undefined")
|
|
554
|
-
return this._storage;
|
|
523
|
+
if (typeof key === "undefined") return this._storage;
|
|
555
524
|
return this._storage[key];
|
|
556
525
|
}
|
|
557
526
|
getEncodedState() {
|
|
@@ -584,25 +553,20 @@ var CrdtLoroDoc = class extends AbstractCrdtDoc {
|
|
|
584
553
|
update
|
|
585
554
|
});
|
|
586
555
|
};
|
|
587
|
-
const subscriptionIds = Object.entries(this._storage).reduce(
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
},
|
|
593
|
-
/* @__PURE__ */ new Map()
|
|
594
|
-
);
|
|
556
|
+
const subscriptionIds = Object.entries(this._storage).reduce((map2, [key, crdtType]) => {
|
|
557
|
+
const container = crdtType.value;
|
|
558
|
+
const subscriptionId = container.subscribe(this.value, fn);
|
|
559
|
+
return map2.set(key, subscriptionId);
|
|
560
|
+
}, /* @__PURE__ */ new Map());
|
|
595
561
|
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);
|
|
562
|
+
Array.from(subscriptionIds.entries()).forEach(([key, subscriptionId]) => {
|
|
563
|
+
var _a, _b;
|
|
564
|
+
const container = (_b = (_a = this._storage[key]) == null ? void 0 : _a.value) != null ? _b : null;
|
|
565
|
+
if (!container) {
|
|
566
|
+
throw new Error("Storage could not be found");
|
|
604
567
|
}
|
|
605
|
-
|
|
568
|
+
container.unsubscribe(this.value, subscriptionId);
|
|
569
|
+
});
|
|
606
570
|
};
|
|
607
571
|
}
|
|
608
572
|
/**
|
|
@@ -640,9 +604,7 @@ var CrdtLoroDocFactory = class _CrdtLoroDocFactory extends AbstractCrdtDocFactor
|
|
|
640
604
|
return new CrdtLoroDoc();
|
|
641
605
|
}
|
|
642
606
|
getFactory(initialStorage) {
|
|
643
|
-
return new _CrdtLoroDocFactory(
|
|
644
|
-
initialStorage != null ? initialStorage : this._initialStorage
|
|
645
|
-
);
|
|
607
|
+
return new _CrdtLoroDocFactory(initialStorage != null ? initialStorage : this._initialStorage);
|
|
646
608
|
}
|
|
647
609
|
getFresh() {
|
|
648
610
|
const storage = this._initialStorage();
|
|
@@ -666,9 +628,7 @@ var CrdtLoroDocFactory = class _CrdtLoroDocFactory extends AbstractCrdtDocFactor
|
|
|
666
628
|
}
|
|
667
629
|
getInitialized(initialStorage) {
|
|
668
630
|
var _a;
|
|
669
|
-
return new CrdtLoroDoc(
|
|
670
|
-
(_a = initialStorage == null ? void 0 : initialStorage()) != null ? _a : this._initialStorage()
|
|
671
|
-
);
|
|
631
|
+
return new CrdtLoroDoc((_a = initialStorage == null ? void 0 : initialStorage()) != null ? _a : this._initialStorage());
|
|
672
632
|
}
|
|
673
633
|
};
|
|
674
634
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pluv/crdt-loro",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.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.19.0",
|
|
22
|
+
"@pluv/types": "^0.19.0"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"loro-crdt": "^0.11.0"
|
|
@@ -27,10 +27,10 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"eslint": "^8.57.0",
|
|
29
29
|
"loro-crdt": "^0.11.1",
|
|
30
|
-
"tsup": "^8.0
|
|
30
|
+
"tsup": "^8.1.0",
|
|
31
31
|
"typescript": "^5.4.5",
|
|
32
|
-
"@pluv/tsconfig": "^0.
|
|
33
|
-
"eslint-config-pluv": "^0.
|
|
32
|
+
"@pluv/tsconfig": "^0.19.0",
|
|
33
|
+
"eslint-config-pluv": "^0.19.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 ||
|