@dabble/patches 0.4.5 → 0.4.6
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/dist/algorithms/client/applyCommittedChanges.d.ts +8 -2
- package/dist/algorithms/client/applyCommittedChanges.js +30 -38
- package/dist/algorithms/client/batching.d.ts +8 -2
- package/dist/algorithms/client/batching.js +38 -37
- package/dist/algorithms/client/breakChange.d.ts +8 -2
- package/dist/algorithms/client/breakChange.js +191 -240
- package/dist/algorithms/client/createStateFromSnapshot.d.ts +8 -2
- package/dist/algorithms/client/createStateFromSnapshot.js +7 -8
- package/dist/algorithms/client/getJSONByteSize.d.ts +3 -1
- package/dist/algorithms/client/getJSONByteSize.js +12 -11
- package/dist/algorithms/client/makeChange.d.ts +8 -2
- package/dist/algorithms/client/makeChange.js +28 -36
- package/dist/algorithms/server/commitChanges.d.ts +9 -3
- package/dist/algorithms/server/commitChanges.js +69 -78
- package/dist/algorithms/server/createVersion.d.ts +9 -3
- package/dist/algorithms/server/createVersion.js +21 -27
- package/dist/algorithms/server/getSnapshotAtRevision.d.ts +9 -3
- package/dist/algorithms/server/getSnapshotAtRevision.js +27 -28
- package/dist/algorithms/server/getStateAtRevision.d.ts +9 -3
- package/dist/algorithms/server/getStateAtRevision.js +13 -17
- package/dist/algorithms/server/handleOfflineSessionsAndBatches.d.ts +9 -3
- package/dist/algorithms/server/handleOfflineSessionsAndBatches.js +60 -77
- package/dist/algorithms/server/transformIncomingChanges.d.ts +8 -2
- package/dist/algorithms/server/transformIncomingChanges.js +27 -39
- package/dist/algorithms/shared/applyChanges.d.ts +8 -2
- package/dist/algorithms/shared/applyChanges.js +11 -16
- package/dist/algorithms/shared/rebaseChanges.d.ts +8 -2
- package/dist/algorithms/shared/rebaseChanges.js +30 -49
- package/dist/chunk-IZ2YBCUP.js +56 -0
- package/dist/client/InMemoryStore.d.ts +9 -3
- package/dist/client/InMemoryStore.js +92 -101
- package/dist/client/IndexedDBStore.d.ts +9 -3
- package/dist/client/IndexedDBStore.js +378 -491
- package/dist/client/Patches.d.ts +18 -13
- package/dist/client/Patches.js +152 -207
- package/dist/client/PatchesDoc.d.ts +14 -8
- package/dist/client/PatchesDoc.js +147 -154
- package/dist/client/PatchesHistoryClient.d.ts +12 -5
- package/dist/client/PatchesHistoryClient.js +110 -117
- package/dist/client/PatchesStore.d.ts +9 -3
- package/dist/client/PatchesStore.js +0 -1
- package/dist/client/index.d.ts +12 -6
- package/dist/client/index.js +5 -5
- package/dist/data/change.d.ts +9 -3
- package/dist/data/change.js +23 -15
- package/dist/data/version.d.ts +9 -3
- package/dist/data/version.js +11 -15
- package/dist/event-signal.d.ts +7 -6
- package/dist/event-signal.js +24 -39
- package/dist/index-CvQws3AB.d.ts +36 -0
- package/dist/index.d.ts +27 -5
- package/dist/index.js +10 -4
- package/dist/json-patch/JSONPatch.d.ts +9 -5
- package/dist/json-patch/JSONPatch.js +175 -183
- package/dist/json-patch/applyPatch.d.ts +5 -2
- package/dist/json-patch/applyPatch.js +27 -35
- package/dist/json-patch/composePatch.d.ts +5 -2
- package/dist/json-patch/composePatch.js +34 -34
- package/dist/json-patch/createJSONPatch.d.ts +7 -2
- package/dist/json-patch/createJSONPatch.js +11 -38
- package/dist/json-patch/index.d.ts +14 -6
- package/dist/json-patch/index.js +20 -9
- package/dist/json-patch/invertPatch.d.ts +5 -2
- package/dist/json-patch/invertPatch.js +31 -30
- package/dist/json-patch/ops/add.d.ts +5 -2
- package/dist/json-patch/ops/add.js +53 -51
- package/dist/json-patch/ops/bitmask.d.ts +8 -5
- package/dist/json-patch/ops/bitmask.js +41 -44
- package/dist/json-patch/ops/copy.d.ts +5 -2
- package/dist/json-patch/ops/copy.js +32 -33
- package/dist/json-patch/ops/increment.d.ts +5 -2
- package/dist/json-patch/ops/increment.js +21 -20
- package/dist/json-patch/ops/index.d.ts +10 -21
- package/dist/json-patch/ops/index.js +34 -24
- package/dist/json-patch/ops/move.d.ts +5 -2
- package/dist/json-patch/ops/move.js +132 -198
- package/dist/json-patch/ops/remove.d.ts +5 -2
- package/dist/json-patch/ops/remove.js +33 -30
- package/dist/json-patch/ops/replace.d.ts +5 -2
- package/dist/json-patch/ops/replace.js +45 -43
- package/dist/json-patch/ops/test.d.ts +5 -2
- package/dist/json-patch/ops/test.js +25 -21
- package/dist/json-patch/ops/text.d.ts +5 -2
- package/dist/json-patch/ops/text.js +54 -54
- package/dist/json-patch/pathProxy.d.ts +9 -3
- package/dist/json-patch/pathProxy.js +27 -48
- package/dist/json-patch/state.d.ts +5 -2
- package/dist/json-patch/state.js +11 -7
- package/dist/json-patch/transformPatch.d.ts +6 -2
- package/dist/json-patch/transformPatch.js +21 -24
- package/dist/json-patch/types.d.ts +9 -7
- package/dist/json-patch/types.js +0 -1
- package/dist/json-patch/utils/deepEqual.d.ts +3 -1
- package/dist/json-patch/utils/deepEqual.js +32 -28
- package/dist/json-patch/utils/exit.d.ts +5 -2
- package/dist/json-patch/utils/exit.js +7 -3
- package/dist/json-patch/utils/get.d.ts +5 -2
- package/dist/json-patch/utils/get.js +8 -4
- package/dist/json-patch/utils/getOpData.d.ts +5 -2
- package/dist/json-patch/utils/getOpData.js +12 -9
- package/dist/json-patch/utils/getType.d.ts +6 -3
- package/dist/json-patch/utils/getType.js +9 -4
- package/dist/json-patch/utils/index.d.ts +15 -14
- package/dist/json-patch/utils/index.js +14 -14
- package/dist/json-patch/utils/log.d.ts +4 -2
- package/dist/json-patch/utils/log.js +8 -3
- package/dist/json-patch/utils/ops.d.ts +8 -5
- package/dist/json-patch/utils/ops.js +83 -100
- package/dist/json-patch/utils/paths.d.ts +12 -9
- package/dist/json-patch/utils/paths.js +54 -51
- package/dist/json-patch/utils/pluck.d.ts +8 -5
- package/dist/json-patch/utils/pluck.js +32 -26
- package/dist/json-patch/utils/shallowCopy.d.ts +3 -1
- package/dist/json-patch/utils/shallowCopy.js +22 -18
- package/dist/json-patch/utils/softWrites.d.ts +6 -3
- package/dist/json-patch/utils/softWrites.js +17 -16
- package/dist/json-patch/utils/toArrayIndex.d.ts +3 -1
- package/dist/json-patch/utils/toArrayIndex.js +14 -10
- package/dist/json-patch/utils/toKeys.d.ts +3 -1
- package/dist/json-patch/utils/toKeys.js +15 -11
- package/dist/json-patch/utils/updateArrayIndexes.d.ts +5 -2
- package/dist/json-patch/utils/updateArrayIndexes.js +33 -37
- package/dist/json-patch/utils/updateArrayPath.d.ts +5 -2
- package/dist/json-patch/utils/updateArrayPath.js +29 -42
- package/dist/net/PatchesClient.d.ts +128 -0
- package/dist/net/PatchesClient.js +161 -0
- package/dist/net/PatchesSync.d.ts +19 -9
- package/dist/net/PatchesSync.js +291 -386
- package/dist/net/error.d.ts +3 -1
- package/dist/net/error.js +9 -6
- package/dist/net/http/FetchTransport.d.ts +21 -0
- package/dist/net/http/FetchTransport.js +34 -0
- package/dist/net/index.d.ts +26 -12
- package/dist/net/index.js +12 -10
- package/dist/net/protocol/JSONRPCClient.d.ts +11 -4
- package/dist/net/protocol/JSONRPCClient.js +95 -103
- package/dist/net/protocol/JSONRPCServer.d.ts +15 -8
- package/dist/net/protocol/JSONRPCServer.js +101 -123
- package/dist/net/protocol/types.d.ts +21 -15
- package/dist/net/protocol/types.js +0 -1
- package/dist/net/protocol/utils.d.ts +12 -0
- package/dist/net/protocol/utils.js +15 -0
- package/dist/net/types.d.ts +4 -2
- package/dist/net/types.js +0 -1
- package/dist/net/webrtc/WebRTCAwareness.d.ts +14 -4
- package/dist/net/webrtc/WebRTCAwareness.js +111 -120
- package/dist/net/webrtc/WebRTCTransport.d.ts +16 -8
- package/dist/net/webrtc/WebRTCTransport.js +149 -157
- package/dist/net/webrtc/index.d.ts +10 -2
- package/dist/net/webrtc/index.js +2 -2
- package/dist/net/websocket/AuthorizationProvider.d.ts +7 -5
- package/dist/net/websocket/AuthorizationProvider.js +12 -17
- package/dist/net/websocket/PatchesWebSocket.d.ts +14 -109
- package/dist/net/websocket/PatchesWebSocket.js +37 -184
- package/dist/net/websocket/RPCServer.d.ts +19 -10
- package/dist/net/websocket/RPCServer.js +190 -192
- package/dist/net/websocket/SignalingService.d.ts +12 -32
- package/dist/net/websocket/SignalingService.js +126 -133
- package/dist/net/websocket/WebSocketServer.d.ts +17 -4
- package/dist/net/websocket/WebSocketServer.js +64 -72
- package/dist/net/websocket/WebSocketTransport.d.ts +13 -5
- package/dist/net/websocket/WebSocketTransport.js +178 -207
- package/dist/net/websocket/onlineState.d.ts +6 -3
- package/dist/net/websocket/onlineState.js +25 -21
- package/dist/server/PatchesBranchManager.d.ts +12 -5
- package/dist/server/PatchesBranchManager.js +132 -142
- package/dist/server/PatchesHistoryManager.d.ts +11 -3
- package/dist/server/PatchesHistoryManager.js +81 -84
- package/dist/server/PatchesServer.d.ts +16 -10
- package/dist/server/PatchesServer.js +131 -137
- package/dist/server/index.d.ts +7 -2
- package/dist/server/index.js +9 -3
- package/dist/server/types.d.ts +9 -3
- package/dist/server/types.js +0 -1
- package/dist/types.d.ts +38 -19
- package/dist/types.js +1 -1
- package/dist/utils/concurrency.d.ts +7 -5
- package/dist/utils/concurrency.js +43 -53
- package/dist/utils/deferred.d.ts +4 -2
- package/dist/utils/deferred.js +25 -21
- package/package.json +5 -7
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { State, JSONPatchOp } from '../types.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Check whether this operation is an add operation of some sort (add, copy, move).
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
declare function isAdd(state: State, op: JSONPatchOp, pathName: 'from' | 'path'): boolean;
|
|
6
7
|
/**
|
|
7
8
|
* Transforms an array of ops, returning the original if there is no change, filtering out ops that are dropped.
|
|
8
9
|
*/
|
|
9
|
-
|
|
10
|
+
declare function mapAndFilterOps(ops: JSONPatchOp[], iterator: (op: JSONPatchOp, index: number, breakAfter: (keepRest?: boolean) => void) => JSONPatchOp | JSONPatchOp[] | null): JSONPatchOp[];
|
|
10
11
|
/**
|
|
11
12
|
* Remove operations that apply to a value which was removed.
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
declare function updateRemovedOps(state: State, thisPath: string, otherOps: JSONPatchOp[], isRemove?: boolean, updatableObject?: boolean, opOp?: string, customHandler?: (op: JSONPatchOp) => any): JSONPatchOp[];
|
|
15
|
+
declare function transformRemove(state: State, thisPath: string, otherOps: JSONPatchOp[], isRemove?: boolean): JSONPatchOp[];
|
|
16
|
+
|
|
17
|
+
export { isAdd, mapAndFilterOps, transformRemove, updateRemovedOps };
|
|
@@ -1,106 +1,89 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const like = getTypeLike(state, op);
|
|
10
|
-
return (like === 'add' || like === 'copy' || like === 'move') && pathName === 'path';
|
|
1
|
+
import "../../chunk-IZ2YBCUP.js";
|
|
2
|
+
import { getTypeLike } from "./getType.js";
|
|
3
|
+
import { log } from "./log.js";
|
|
4
|
+
import { isArrayPath } from "./paths.js";
|
|
5
|
+
import { updateArrayIndexes } from "./updateArrayIndexes.js";
|
|
6
|
+
function isAdd(state, op, pathName) {
|
|
7
|
+
const like = getTypeLike(state, op);
|
|
8
|
+
return (like === "add" || like === "copy" || like === "move") && pathName === "path";
|
|
11
9
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
// If an op was copied or moved to the same path, it is a no-op and should be removed
|
|
27
|
-
if (original.from === original.path) {
|
|
28
|
-
if (!changed)
|
|
29
|
-
changed = true;
|
|
30
|
-
continue;
|
|
31
|
-
}
|
|
32
|
-
let value = iterator(original, i, breakAfter);
|
|
33
|
-
if (value && !Array.isArray(value) && value.from === value.path)
|
|
34
|
-
value = null;
|
|
35
|
-
if (!changed && value !== original)
|
|
36
|
-
changed = true;
|
|
37
|
-
if (Array.isArray(value))
|
|
38
|
-
mapped.push(...value);
|
|
39
|
-
else if (value)
|
|
40
|
-
mapped.push(value);
|
|
41
|
-
if (shouldBreak) {
|
|
42
|
-
if (keepRest)
|
|
43
|
-
mapped.push(...ops.slice(i + 1));
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
10
|
+
function mapAndFilterOps(ops, iterator) {
|
|
11
|
+
let changed = false;
|
|
12
|
+
const mapped = [];
|
|
13
|
+
let shouldBreak = false;
|
|
14
|
+
let keepRest;
|
|
15
|
+
const breakAfter = (keep) => {
|
|
16
|
+
shouldBreak = true;
|
|
17
|
+
keepRest = keep;
|
|
18
|
+
};
|
|
19
|
+
for (let i = 0; i < ops.length; i++) {
|
|
20
|
+
const original = ops[i];
|
|
21
|
+
if (original.from === original.path) {
|
|
22
|
+
if (!changed) changed = true;
|
|
23
|
+
continue;
|
|
46
24
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// Once an operation sets this value again, we can assume the following ops were working on that and not the
|
|
59
|
-
// old value so they can be kept
|
|
60
|
-
if (op.op !== 'test') {
|
|
61
|
-
breakAfter(true); // stop and keep the remaining ops as-is
|
|
62
|
-
}
|
|
63
|
-
return op;
|
|
64
|
-
}
|
|
65
|
-
const { path, from } = op;
|
|
66
|
-
if (path === thisPath && canMergeCustom) {
|
|
67
|
-
const customOp = customHandler(op);
|
|
68
|
-
if (customOp)
|
|
69
|
-
return customOp;
|
|
70
|
-
}
|
|
71
|
-
if (isRemove && !updatableObject && from === thisPath) {
|
|
72
|
-
// Because of the check above, moves and copies will only hit here when the "from" field matches
|
|
73
|
-
if (opLike === 'move') {
|
|
74
|
-
// We need the rest of the otherOps to be adjusted against this "move"
|
|
75
|
-
breakAfter();
|
|
76
|
-
return transformRemove(state, op.path, otherOps.slice(index + 1));
|
|
77
|
-
}
|
|
78
|
-
else if (opLike === 'copy') {
|
|
79
|
-
// We need future ops on the copied object to be removed
|
|
80
|
-
breakAfter();
|
|
81
|
-
let rest = transformRemove(state, thisPath, otherOps.slice(index + 1));
|
|
82
|
-
rest = transformRemove(state, op.path, rest);
|
|
83
|
-
return rest;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
if (op.soft && path === thisPath) {
|
|
87
|
-
softPrefixes.add(path);
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
const samePath = (!updatableObject && path === thisPath) || (!softPrefixes.has(thisPath) && path.startsWith(`${thisPath}/`));
|
|
91
|
-
const sameFrom = (!updatableObject && from === thisPath) || (!softPrefixes.has(thisPath) && from?.startsWith(`${thisPath}/`));
|
|
92
|
-
if (samePath || sameFrom) {
|
|
93
|
-
log('Removing', op);
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
return op;
|
|
97
|
-
});
|
|
25
|
+
let value = iterator(original, i, breakAfter);
|
|
26
|
+
if (value && !Array.isArray(value) && value.from === value.path) value = null;
|
|
27
|
+
if (!changed && value !== original) changed = true;
|
|
28
|
+
if (Array.isArray(value)) mapped.push(...value);
|
|
29
|
+
else if (value) mapped.push(value);
|
|
30
|
+
if (shouldBreak) {
|
|
31
|
+
if (keepRest) mapped.push(...ops.slice(i + 1));
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return changed ? mapped : ops;
|
|
98
36
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
37
|
+
function updateRemovedOps(state, thisPath, otherOps, isRemove = false, updatableObject = false, opOp, customHandler) {
|
|
38
|
+
const softPrefixes = /* @__PURE__ */ new Set();
|
|
39
|
+
return mapAndFilterOps(otherOps, (op, index, breakAfter) => {
|
|
40
|
+
const opLike = getTypeLike(state, op);
|
|
41
|
+
const canMergeCustom = customHandler && opOp === op.op;
|
|
42
|
+
if (thisPath === op.path && opLike !== "remove" && !canMergeCustom && !op.soft) {
|
|
43
|
+
if (op.op !== "test") {
|
|
44
|
+
breakAfter(true);
|
|
45
|
+
}
|
|
46
|
+
return op;
|
|
47
|
+
}
|
|
48
|
+
const { path, from } = op;
|
|
49
|
+
if (path === thisPath && canMergeCustom) {
|
|
50
|
+
const customOp = customHandler(op);
|
|
51
|
+
if (customOp) return customOp;
|
|
102
52
|
}
|
|
103
|
-
|
|
104
|
-
|
|
53
|
+
if (isRemove && !updatableObject && from === thisPath) {
|
|
54
|
+
if (opLike === "move") {
|
|
55
|
+
breakAfter();
|
|
56
|
+
return transformRemove(state, op.path, otherOps.slice(index + 1));
|
|
57
|
+
} else if (opLike === "copy") {
|
|
58
|
+
breakAfter();
|
|
59
|
+
let rest = transformRemove(state, thisPath, otherOps.slice(index + 1));
|
|
60
|
+
rest = transformRemove(state, op.path, rest);
|
|
61
|
+
return rest;
|
|
62
|
+
}
|
|
105
63
|
}
|
|
64
|
+
if (op.soft && path === thisPath) {
|
|
65
|
+
softPrefixes.add(path);
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const samePath = !updatableObject && path === thisPath || !softPrefixes.has(thisPath) && path.startsWith(`${thisPath}/`);
|
|
69
|
+
const sameFrom = !updatableObject && from === thisPath || !softPrefixes.has(thisPath) && from?.startsWith(`${thisPath}/`);
|
|
70
|
+
if (samePath || sameFrom) {
|
|
71
|
+
log("Removing", op);
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
return op;
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function transformRemove(state, thisPath, otherOps, isRemove) {
|
|
78
|
+
if (isArrayPath(thisPath, state)) {
|
|
79
|
+
return updateArrayIndexes(state, thisPath, otherOps, -1, isRemove);
|
|
80
|
+
} else {
|
|
81
|
+
return updateRemovedOps(state, thisPath, otherOps, isRemove);
|
|
82
|
+
}
|
|
106
83
|
}
|
|
84
|
+
export {
|
|
85
|
+
isAdd,
|
|
86
|
+
mapAndFilterOps,
|
|
87
|
+
transformRemove,
|
|
88
|
+
updateRemovedOps
|
|
89
|
+
};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { State } from '../types.js';
|
|
2
|
+
|
|
3
|
+
declare function getPrefix(path: string): string;
|
|
4
|
+
declare function getProp(path: string): string;
|
|
5
|
+
declare function getPrefixAndProp(path: string): [string, string];
|
|
6
|
+
declare function getPropAfter(path: string, index: number): string;
|
|
7
|
+
declare function isArrayPath(path: string, state?: State): boolean;
|
|
8
|
+
declare function getArrayPrefixAndIndex(state: State, path: string, pathLength?: number): [string, number];
|
|
9
|
+
declare function getArrayIndex(state: State, path: string, pathLength?: number): number;
|
|
10
|
+
declare function getIndexAndEnd(state: State, path: string | undefined, maxLength: number): number[];
|
|
11
|
+
|
|
12
|
+
export { getArrayIndex, getArrayPrefixAndIndex, getIndexAndEnd, getPrefix, getPrefixAndProp, getProp, getPropAfter, isArrayPath };
|
|
@@ -1,53 +1,56 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "../../chunk-IZ2YBCUP.js";
|
|
2
|
+
import { getOpData } from "./getOpData.js";
|
|
2
3
|
const arrayPathExp = /\/(0|[1-9]\d*)$/;
|
|
3
4
|
const EMPTY = [];
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
5
|
+
function getPrefix(path) {
|
|
6
|
+
const lastSlash = path.lastIndexOf("/");
|
|
7
|
+
return path.slice(0, lastSlash + 1);
|
|
8
|
+
}
|
|
9
|
+
function getProp(path) {
|
|
10
|
+
const lastSlash = path.lastIndexOf("/");
|
|
11
|
+
return path.slice(lastSlash + 1);
|
|
12
|
+
}
|
|
13
|
+
function getPrefixAndProp(path) {
|
|
14
|
+
const prefix = getPrefix(path);
|
|
15
|
+
return [prefix, path.slice(prefix.length)];
|
|
16
|
+
}
|
|
17
|
+
function getPropAfter(path, index) {
|
|
18
|
+
const lastSlash = path.indexOf("/", index);
|
|
19
|
+
return path.slice(index, lastSlash === -1 ? void 0 : lastSlash);
|
|
20
|
+
}
|
|
21
|
+
function isArrayPath(path, state) {
|
|
22
|
+
if (!arrayPathExp.test(path)) return false;
|
|
23
|
+
if (!state || !state.root || !state.root[""]) return true;
|
|
24
|
+
const [, , target] = getOpData(state, path);
|
|
25
|
+
return Array.isArray(target) || target == null;
|
|
26
|
+
}
|
|
27
|
+
function getArrayPrefixAndIndex(state, path, pathLength) {
|
|
28
|
+
if (pathLength) path = path.slice(0, path.indexOf("/", pathLength));
|
|
29
|
+
if (!arrayPathExp.test(path)) return EMPTY;
|
|
30
|
+
const [, , target] = getOpData(state, path);
|
|
31
|
+
if (!Array.isArray(target)) return EMPTY;
|
|
32
|
+
const [prefix, indexStr] = getPrefixAndProp(path);
|
|
33
|
+
const index = parseInt(indexStr);
|
|
34
|
+
return [prefix, index];
|
|
35
|
+
}
|
|
36
|
+
function getArrayIndex(state, path, pathLength) {
|
|
37
|
+
return getArrayPrefixAndIndex(state, path, pathLength)[1];
|
|
38
|
+
}
|
|
39
|
+
function getIndexAndEnd(state, path, maxLength) {
|
|
40
|
+
if (!path) return [];
|
|
41
|
+
const prop = getPropAfter(path, maxLength);
|
|
42
|
+
const end = maxLength + prop.length;
|
|
43
|
+
if (!isArrayPath(path.slice(0, end), state)) return [];
|
|
44
|
+
const index = parseInt(prop);
|
|
45
|
+
return [index, end];
|
|
46
|
+
}
|
|
47
|
+
export {
|
|
48
|
+
getArrayIndex,
|
|
49
|
+
getArrayPrefixAndIndex,
|
|
50
|
+
getIndexAndEnd,
|
|
51
|
+
getPrefix,
|
|
52
|
+
getPrefixAndProp,
|
|
53
|
+
getProp,
|
|
54
|
+
getPropAfter,
|
|
55
|
+
isArrayPath
|
|
56
|
+
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { State } from '../types.js';
|
|
2
|
+
|
|
3
|
+
declare const EMPTY: {};
|
|
4
|
+
declare function pluck(state: State, keys: string[]): any;
|
|
5
|
+
declare function pluckWithShallowCopy(state: State, keys: string[], createMissingObjects?: boolean): any;
|
|
6
|
+
declare function getValue(state: State, value: any, addKey?: string, addValue?: any): any;
|
|
7
|
+
|
|
8
|
+
export { EMPTY, getValue, pluck, pluckWithShallowCopy };
|
|
@@ -1,30 +1,36 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
object = object[key];
|
|
1
|
+
import "../../chunk-IZ2YBCUP.js";
|
|
2
|
+
import { shallowCopy } from "./shallowCopy.js";
|
|
3
|
+
const EMPTY = {};
|
|
4
|
+
function pluck(state, keys) {
|
|
5
|
+
let object = state.root;
|
|
6
|
+
for (let i = 0, imax = keys.length - 1; i < imax; i++) {
|
|
7
|
+
const key = keys[i];
|
|
8
|
+
if (!object[key]) {
|
|
9
|
+
return null;
|
|
11
10
|
}
|
|
12
|
-
|
|
11
|
+
object = object[key];
|
|
12
|
+
}
|
|
13
|
+
return object;
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
function pluckWithShallowCopy(state, keys, createMissingObjects) {
|
|
16
|
+
let object = state.root;
|
|
17
|
+
for (let i = 0, imax = keys.length - 1; i < imax; i++) {
|
|
18
|
+
const key = keys[i];
|
|
19
|
+
object = object[key] = createMissingObjects && !object[key] ? getValue(state, EMPTY) : getValue(state, object[key]);
|
|
20
|
+
}
|
|
21
|
+
return object;
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return value;
|
|
23
|
+
function getValue(state, value, addKey, addValue) {
|
|
24
|
+
if (!state.cache?.has(value)) {
|
|
25
|
+
value = shallowCopy(value);
|
|
26
|
+
state.cache?.add(value);
|
|
27
|
+
}
|
|
28
|
+
if (addKey) value[addKey] = addValue;
|
|
29
|
+
return value;
|
|
30
30
|
}
|
|
31
|
+
export {
|
|
32
|
+
EMPTY,
|
|
33
|
+
getValue,
|
|
34
|
+
pluck,
|
|
35
|
+
pluckWithShallowCopy
|
|
36
|
+
};
|
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import "../../chunk-IZ2YBCUP.js";
|
|
2
|
+
function shallowCopy(obj) {
|
|
3
|
+
if (!obj || typeof obj !== "object") {
|
|
4
|
+
return obj;
|
|
5
|
+
}
|
|
6
|
+
if (Array.isArray(obj)) {
|
|
7
|
+
const len = obj.length;
|
|
8
|
+
const ary = new Array(len);
|
|
9
|
+
for (let i = 0; i < len; i++) {
|
|
10
|
+
ary[i] = obj[i];
|
|
4
11
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const copy = {};
|
|
15
|
-
for (let j = 0, jmax = keys.length; j < jmax; j++) {
|
|
16
|
-
const key = keys[j];
|
|
17
|
-
copy[key] = obj[key];
|
|
18
|
-
}
|
|
19
|
-
return copy;
|
|
12
|
+
return ary;
|
|
13
|
+
}
|
|
14
|
+
const keys = Object.keys(obj);
|
|
15
|
+
const copy = {};
|
|
16
|
+
for (let j = 0, jmax = keys.length; j < jmax; j++) {
|
|
17
|
+
const key = keys[j];
|
|
18
|
+
copy[key] = obj[key];
|
|
19
|
+
}
|
|
20
|
+
return copy;
|
|
20
21
|
}
|
|
22
|
+
export {
|
|
23
|
+
shallowCopy
|
|
24
|
+
};
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { JSONPatchOp } from '../types.js';
|
|
2
|
+
|
|
3
|
+
declare function isEmptyObject(value: any): boolean;
|
|
3
4
|
/**
|
|
4
5
|
* If other objects were added to this same path, assume they are maps/hashes/lookups and don't overwrite, allow
|
|
5
6
|
* subsequent ops to merge onto the first map created. `soft` will also do this for any value that already exists.
|
|
6
7
|
*/
|
|
7
|
-
|
|
8
|
+
declare function updateSoftWrites(overPath: string, ops: JSONPatchOp[]): JSONPatchOp[];
|
|
9
|
+
|
|
10
|
+
export { isEmptyObject, updateSoftWrites };
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import "../../chunk-IZ2YBCUP.js";
|
|
2
|
+
import { log } from "./log.js";
|
|
3
|
+
import { mapAndFilterOps } from "./ops.js";
|
|
4
|
+
function isEmptyObject(value) {
|
|
5
|
+
return Boolean(value && typeof value === "object" && Object.keys(value).length === 0);
|
|
5
6
|
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
return op;
|
|
17
|
-
});
|
|
7
|
+
function updateSoftWrites(overPath, ops) {
|
|
8
|
+
return mapAndFilterOps(ops, (op) => {
|
|
9
|
+
if (op.op === "add" && op.path === overPath && isEmptyObject(op.value)) {
|
|
10
|
+
log("Removing empty object", op);
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
return op;
|
|
14
|
+
});
|
|
18
15
|
}
|
|
16
|
+
export {
|
|
17
|
+
isEmptyObject,
|
|
18
|
+
updateSoftWrites
|
|
19
|
+
};
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import "../../chunk-IZ2YBCUP.js";
|
|
2
|
+
function toArrayIndex(array, str) {
|
|
3
|
+
if (str === "-") {
|
|
4
|
+
return array.length;
|
|
5
|
+
}
|
|
6
|
+
for (let i = 0, imax = str.length; i < imax; i++) {
|
|
7
|
+
const ch = str.charCodeAt(i);
|
|
8
|
+
if (57 < ch || ch < 48) {
|
|
9
|
+
return -1;
|
|
4
10
|
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
if (57 < ch || ch < 48) {
|
|
8
|
-
return -1;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return +str;
|
|
11
|
+
}
|
|
12
|
+
return +str;
|
|
12
13
|
}
|
|
14
|
+
export {
|
|
15
|
+
toArrayIndex
|
|
16
|
+
};
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
+
import "../../chunk-IZ2YBCUP.js";
|
|
1
2
|
function esc(m) {
|
|
2
|
-
|
|
3
|
+
return m === "~0" ? "~" : "/";
|
|
3
4
|
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return keys;
|
|
8
|
-
}
|
|
9
|
-
for (let i = 0, imax = keys.length; i < imax; i++) {
|
|
10
|
-
if (keys[i].includes('~')) {
|
|
11
|
-
keys[i] = keys[i].replace(/~[01]/g, esc);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
5
|
+
function toKeys(path) {
|
|
6
|
+
const keys = path.split("/");
|
|
7
|
+
if (!path.includes("~")) {
|
|
14
8
|
return keys;
|
|
9
|
+
}
|
|
10
|
+
for (let i = 0, imax = keys.length; i < imax; i++) {
|
|
11
|
+
if (keys[i].includes("~")) {
|
|
12
|
+
keys[i] = keys[i].replace(/~[01]/g, esc);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return keys;
|
|
15
16
|
}
|
|
17
|
+
export {
|
|
18
|
+
toKeys
|
|
19
|
+
};
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { State, JSONPatchOp } from '../types.js';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Update array indexes to account for values being added or removed from an array.
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
|
+
declare function updateArrayIndexes(state: State, thisPath: string, otherOps: JSONPatchOp[], modifier: 1 | -1, isRemove?: boolean): JSONPatchOp[];
|
|
7
|
+
|
|
8
|
+
export { updateArrayIndexes };
|