@dabble/patches 0.7.3 → 0.7.4
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.
|
@@ -43,7 +43,7 @@ declare class LWWBatcher<T extends object = object> {
|
|
|
43
43
|
*
|
|
44
44
|
* @param newOps Array of JSON Patch operations to add (timestamps optional)
|
|
45
45
|
*/
|
|
46
|
-
add(newOps: JSONPatchOp[] | JSONPatch): void;
|
|
46
|
+
add(newOps: JSONPatchOp[] | JSONPatch, timestamp?: number): void;
|
|
47
47
|
/**
|
|
48
48
|
* Captures operations using a mutator function (like LWWDoc.change).
|
|
49
49
|
* The mutator receives a JSONPatch instance and a type-safe path proxy.
|
|
@@ -59,7 +59,7 @@ declare class LWWBatcher<T extends object = object> {
|
|
|
59
59
|
* });
|
|
60
60
|
* ```
|
|
61
61
|
*/
|
|
62
|
-
change(mutator: ChangeMutator<T
|
|
62
|
+
change(mutator: ChangeMutator<T>, timestamp?: number): void;
|
|
63
63
|
/**
|
|
64
64
|
* Returns the consolidated operations as a ChangeInput object and clears the batch.
|
|
65
65
|
*
|
|
@@ -10,17 +10,18 @@ class LWWBatcher {
|
|
|
10
10
|
*
|
|
11
11
|
* @param newOps Array of JSON Patch operations to add (timestamps optional)
|
|
12
12
|
*/
|
|
13
|
-
add(newOps) {
|
|
13
|
+
add(newOps, timestamp = Date.now()) {
|
|
14
14
|
if (!Array.isArray(newOps)) {
|
|
15
15
|
newOps = newOps.ops;
|
|
16
16
|
}
|
|
17
17
|
if (newOps.length === 0) {
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
if (timestamp) {
|
|
21
|
+
newOps = newOps.map((op) => op.ts ? op : { ...op, ts: timestamp });
|
|
22
|
+
}
|
|
22
23
|
const existingOps = Array.from(this.ops.values());
|
|
23
|
-
const { opsToSave, pathsToDelete } = consolidateOps(existingOps,
|
|
24
|
+
const { opsToSave, pathsToDelete } = consolidateOps(existingOps, newOps);
|
|
24
25
|
for (const path of pathsToDelete) {
|
|
25
26
|
this.ops.delete(path);
|
|
26
27
|
}
|
|
@@ -43,10 +44,10 @@ class LWWBatcher {
|
|
|
43
44
|
* });
|
|
44
45
|
* ```
|
|
45
46
|
*/
|
|
46
|
-
change(mutator) {
|
|
47
|
+
change(mutator, timestamp) {
|
|
47
48
|
const patch = createJSONPatch(mutator);
|
|
48
49
|
if (patch.ops.length > 0) {
|
|
49
|
-
this.add(patch.ops);
|
|
50
|
+
this.add(patch.ops, timestamp);
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dabble/patches",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
4
4
|
"description": "Immutable JSON Patch implementation based on RFC 6902 supporting operational transformation and last-writer-wins",
|
|
5
5
|
"author": "Jacob Wright <jacwright@gmail.com>",
|
|
6
6
|
"bugs": {
|