@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.
Files changed (181) hide show
  1. package/dist/algorithms/client/applyCommittedChanges.d.ts +8 -2
  2. package/dist/algorithms/client/applyCommittedChanges.js +30 -38
  3. package/dist/algorithms/client/batching.d.ts +8 -2
  4. package/dist/algorithms/client/batching.js +38 -37
  5. package/dist/algorithms/client/breakChange.d.ts +8 -2
  6. package/dist/algorithms/client/breakChange.js +191 -240
  7. package/dist/algorithms/client/createStateFromSnapshot.d.ts +8 -2
  8. package/dist/algorithms/client/createStateFromSnapshot.js +7 -8
  9. package/dist/algorithms/client/getJSONByteSize.d.ts +3 -1
  10. package/dist/algorithms/client/getJSONByteSize.js +12 -11
  11. package/dist/algorithms/client/makeChange.d.ts +8 -2
  12. package/dist/algorithms/client/makeChange.js +28 -36
  13. package/dist/algorithms/server/commitChanges.d.ts +9 -3
  14. package/dist/algorithms/server/commitChanges.js +69 -78
  15. package/dist/algorithms/server/createVersion.d.ts +9 -3
  16. package/dist/algorithms/server/createVersion.js +21 -27
  17. package/dist/algorithms/server/getSnapshotAtRevision.d.ts +9 -3
  18. package/dist/algorithms/server/getSnapshotAtRevision.js +27 -28
  19. package/dist/algorithms/server/getStateAtRevision.d.ts +9 -3
  20. package/dist/algorithms/server/getStateAtRevision.js +13 -17
  21. package/dist/algorithms/server/handleOfflineSessionsAndBatches.d.ts +9 -3
  22. package/dist/algorithms/server/handleOfflineSessionsAndBatches.js +60 -77
  23. package/dist/algorithms/server/transformIncomingChanges.d.ts +8 -2
  24. package/dist/algorithms/server/transformIncomingChanges.js +27 -39
  25. package/dist/algorithms/shared/applyChanges.d.ts +8 -2
  26. package/dist/algorithms/shared/applyChanges.js +11 -16
  27. package/dist/algorithms/shared/rebaseChanges.d.ts +8 -2
  28. package/dist/algorithms/shared/rebaseChanges.js +30 -49
  29. package/dist/chunk-IZ2YBCUP.js +56 -0
  30. package/dist/client/InMemoryStore.d.ts +9 -3
  31. package/dist/client/InMemoryStore.js +92 -101
  32. package/dist/client/IndexedDBStore.d.ts +9 -3
  33. package/dist/client/IndexedDBStore.js +378 -491
  34. package/dist/client/Patches.d.ts +18 -13
  35. package/dist/client/Patches.js +152 -207
  36. package/dist/client/PatchesDoc.d.ts +14 -8
  37. package/dist/client/PatchesDoc.js +147 -154
  38. package/dist/client/PatchesHistoryClient.d.ts +12 -5
  39. package/dist/client/PatchesHistoryClient.js +110 -117
  40. package/dist/client/PatchesStore.d.ts +9 -3
  41. package/dist/client/PatchesStore.js +0 -1
  42. package/dist/client/index.d.ts +12 -6
  43. package/dist/client/index.js +5 -5
  44. package/dist/data/change.d.ts +9 -3
  45. package/dist/data/change.js +23 -15
  46. package/dist/data/version.d.ts +9 -3
  47. package/dist/data/version.js +11 -15
  48. package/dist/event-signal.d.ts +7 -6
  49. package/dist/event-signal.js +24 -39
  50. package/dist/index-CvQws3AB.d.ts +36 -0
  51. package/dist/index.d.ts +27 -5
  52. package/dist/index.js +10 -4
  53. package/dist/json-patch/JSONPatch.d.ts +9 -5
  54. package/dist/json-patch/JSONPatch.js +175 -183
  55. package/dist/json-patch/applyPatch.d.ts +5 -2
  56. package/dist/json-patch/applyPatch.js +27 -35
  57. package/dist/json-patch/composePatch.d.ts +5 -2
  58. package/dist/json-patch/composePatch.js +34 -34
  59. package/dist/json-patch/createJSONPatch.d.ts +7 -2
  60. package/dist/json-patch/createJSONPatch.js +11 -38
  61. package/dist/json-patch/index.d.ts +14 -6
  62. package/dist/json-patch/index.js +20 -9
  63. package/dist/json-patch/invertPatch.d.ts +5 -2
  64. package/dist/json-patch/invertPatch.js +31 -30
  65. package/dist/json-patch/ops/add.d.ts +5 -2
  66. package/dist/json-patch/ops/add.js +53 -51
  67. package/dist/json-patch/ops/bitmask.d.ts +8 -5
  68. package/dist/json-patch/ops/bitmask.js +41 -44
  69. package/dist/json-patch/ops/copy.d.ts +5 -2
  70. package/dist/json-patch/ops/copy.js +32 -33
  71. package/dist/json-patch/ops/increment.d.ts +5 -2
  72. package/dist/json-patch/ops/increment.js +21 -20
  73. package/dist/json-patch/ops/index.d.ts +10 -21
  74. package/dist/json-patch/ops/index.js +34 -24
  75. package/dist/json-patch/ops/move.d.ts +5 -2
  76. package/dist/json-patch/ops/move.js +132 -198
  77. package/dist/json-patch/ops/remove.d.ts +5 -2
  78. package/dist/json-patch/ops/remove.js +33 -30
  79. package/dist/json-patch/ops/replace.d.ts +5 -2
  80. package/dist/json-patch/ops/replace.js +45 -43
  81. package/dist/json-patch/ops/test.d.ts +5 -2
  82. package/dist/json-patch/ops/test.js +25 -21
  83. package/dist/json-patch/ops/text.d.ts +5 -2
  84. package/dist/json-patch/ops/text.js +54 -54
  85. package/dist/json-patch/pathProxy.d.ts +9 -3
  86. package/dist/json-patch/pathProxy.js +27 -48
  87. package/dist/json-patch/state.d.ts +5 -2
  88. package/dist/json-patch/state.js +11 -7
  89. package/dist/json-patch/transformPatch.d.ts +6 -2
  90. package/dist/json-patch/transformPatch.js +21 -24
  91. package/dist/json-patch/types.d.ts +9 -7
  92. package/dist/json-patch/types.js +0 -1
  93. package/dist/json-patch/utils/deepEqual.d.ts +3 -1
  94. package/dist/json-patch/utils/deepEqual.js +32 -28
  95. package/dist/json-patch/utils/exit.d.ts +5 -2
  96. package/dist/json-patch/utils/exit.js +7 -3
  97. package/dist/json-patch/utils/get.d.ts +5 -2
  98. package/dist/json-patch/utils/get.js +8 -4
  99. package/dist/json-patch/utils/getOpData.d.ts +5 -2
  100. package/dist/json-patch/utils/getOpData.js +12 -9
  101. package/dist/json-patch/utils/getType.d.ts +6 -3
  102. package/dist/json-patch/utils/getType.js +9 -4
  103. package/dist/json-patch/utils/index.d.ts +15 -14
  104. package/dist/json-patch/utils/index.js +14 -14
  105. package/dist/json-patch/utils/log.d.ts +4 -2
  106. package/dist/json-patch/utils/log.js +8 -3
  107. package/dist/json-patch/utils/ops.d.ts +8 -5
  108. package/dist/json-patch/utils/ops.js +83 -100
  109. package/dist/json-patch/utils/paths.d.ts +12 -9
  110. package/dist/json-patch/utils/paths.js +54 -51
  111. package/dist/json-patch/utils/pluck.d.ts +8 -5
  112. package/dist/json-patch/utils/pluck.js +32 -26
  113. package/dist/json-patch/utils/shallowCopy.d.ts +3 -1
  114. package/dist/json-patch/utils/shallowCopy.js +22 -18
  115. package/dist/json-patch/utils/softWrites.d.ts +6 -3
  116. package/dist/json-patch/utils/softWrites.js +17 -16
  117. package/dist/json-patch/utils/toArrayIndex.d.ts +3 -1
  118. package/dist/json-patch/utils/toArrayIndex.js +14 -10
  119. package/dist/json-patch/utils/toKeys.d.ts +3 -1
  120. package/dist/json-patch/utils/toKeys.js +15 -11
  121. package/dist/json-patch/utils/updateArrayIndexes.d.ts +5 -2
  122. package/dist/json-patch/utils/updateArrayIndexes.js +33 -37
  123. package/dist/json-patch/utils/updateArrayPath.d.ts +5 -2
  124. package/dist/json-patch/utils/updateArrayPath.js +29 -42
  125. package/dist/net/PatchesClient.d.ts +128 -0
  126. package/dist/net/PatchesClient.js +161 -0
  127. package/dist/net/PatchesSync.d.ts +19 -9
  128. package/dist/net/PatchesSync.js +291 -386
  129. package/dist/net/error.d.ts +3 -1
  130. package/dist/net/error.js +9 -6
  131. package/dist/net/http/FetchTransport.d.ts +21 -0
  132. package/dist/net/http/FetchTransport.js +34 -0
  133. package/dist/net/index.d.ts +26 -12
  134. package/dist/net/index.js +12 -10
  135. package/dist/net/protocol/JSONRPCClient.d.ts +11 -4
  136. package/dist/net/protocol/JSONRPCClient.js +95 -103
  137. package/dist/net/protocol/JSONRPCServer.d.ts +15 -8
  138. package/dist/net/protocol/JSONRPCServer.js +101 -123
  139. package/dist/net/protocol/types.d.ts +21 -15
  140. package/dist/net/protocol/types.js +0 -1
  141. package/dist/net/protocol/utils.d.ts +12 -0
  142. package/dist/net/protocol/utils.js +15 -0
  143. package/dist/net/types.d.ts +4 -2
  144. package/dist/net/types.js +0 -1
  145. package/dist/net/webrtc/WebRTCAwareness.d.ts +14 -4
  146. package/dist/net/webrtc/WebRTCAwareness.js +111 -120
  147. package/dist/net/webrtc/WebRTCTransport.d.ts +16 -8
  148. package/dist/net/webrtc/WebRTCTransport.js +149 -157
  149. package/dist/net/webrtc/index.d.ts +10 -2
  150. package/dist/net/webrtc/index.js +2 -2
  151. package/dist/net/websocket/AuthorizationProvider.d.ts +7 -5
  152. package/dist/net/websocket/AuthorizationProvider.js +12 -17
  153. package/dist/net/websocket/PatchesWebSocket.d.ts +14 -109
  154. package/dist/net/websocket/PatchesWebSocket.js +37 -184
  155. package/dist/net/websocket/RPCServer.d.ts +19 -10
  156. package/dist/net/websocket/RPCServer.js +190 -192
  157. package/dist/net/websocket/SignalingService.d.ts +12 -32
  158. package/dist/net/websocket/SignalingService.js +126 -133
  159. package/dist/net/websocket/WebSocketServer.d.ts +17 -4
  160. package/dist/net/websocket/WebSocketServer.js +64 -72
  161. package/dist/net/websocket/WebSocketTransport.d.ts +13 -5
  162. package/dist/net/websocket/WebSocketTransport.js +178 -207
  163. package/dist/net/websocket/onlineState.d.ts +6 -3
  164. package/dist/net/websocket/onlineState.js +25 -21
  165. package/dist/server/PatchesBranchManager.d.ts +12 -5
  166. package/dist/server/PatchesBranchManager.js +132 -142
  167. package/dist/server/PatchesHistoryManager.d.ts +11 -3
  168. package/dist/server/PatchesHistoryManager.js +81 -84
  169. package/dist/server/PatchesServer.d.ts +16 -10
  170. package/dist/server/PatchesServer.js +131 -137
  171. package/dist/server/index.d.ts +7 -2
  172. package/dist/server/index.js +9 -3
  173. package/dist/server/types.d.ts +9 -3
  174. package/dist/server/types.js +0 -1
  175. package/dist/types.d.ts +38 -19
  176. package/dist/types.js +1 -1
  177. package/dist/utils/concurrency.d.ts +7 -5
  178. package/dist/utils/concurrency.js +43 -53
  179. package/dist/utils/deferred.d.ts +4 -2
  180. package/dist/utils/deferred.js +25 -21
  181. package/package.json +5 -7
@@ -1,211 +1,145 @@
1
- import { getOpData } from '../utils/getOpData.js';
2
- import { getTypeLike } from '../utils/getType.js';
3
- import { log } from '../utils/log.js';
4
- import { isAdd, mapAndFilterOps, updateRemovedOps } from '../utils/ops.js';
5
- import { getArrayPrefixAndIndex, getIndexAndEnd, isArrayPath } from '../utils/paths.js';
6
- import { getValue, pluckWithShallowCopy } from '../utils/pluck.js';
7
- import { toArrayIndex } from '../utils/toArrayIndex.js';
8
- import { updateArrayIndexes } from '../utils/updateArrayIndexes.js';
9
- import { add } from './add.js';
10
- export const move = {
11
- like: 'move',
12
- apply(state, path, from) {
13
- if (path === from)
14
- return;
15
- let value;
16
- const [keys, lastKey, target] = getOpData(state, from);
17
- if (target === null) {
18
- return `[op:move] path not found: ${from}`;
19
- }
20
- if (Array.isArray(target)) {
21
- const index = toArrayIndex(target, lastKey);
22
- if (index < 0 || target.length <= index) {
23
- return `[op:move] invalid array index: ${path}`;
24
- }
25
- value = target[index];
26
- pluckWithShallowCopy(state, keys, true).splice(index, 1);
27
- }
28
- else {
29
- value = target[lastKey];
30
- delete pluckWithShallowCopy(state, keys, true)[lastKey];
31
- }
32
- return add.apply(state, path, value);
33
- },
34
- invert(_state, { path, from }) {
35
- return { op: 'move', from: path, path: '' + from };
36
- },
37
- transform(state, thisOp, otherOps) {
38
- log('Transforming', otherOps, 'against "move"', thisOp);
39
- let removed = false;
40
- const { from, path } = thisOp;
41
- if (from === path)
42
- return otherOps;
43
- const [fromPrefix, fromIndex] = getArrayPrefixAndIndex(state, from);
44
- const [pathPrefix, pathIndex] = getArrayPrefixAndIndex(state, path);
45
- const isPathArray = pathPrefix !== undefined;
46
- const isSameArray = isPathArray && pathPrefix === fromPrefix;
47
- /*
48
- A move needs to do a "remove" and an "add" at once with `from` and `path`. If it is being moved from one location in
49
- an array to another in the same array, this needs to be handled special.
50
-
51
- 1. Ops that were added to where the move lands when not an array should be removed just like with an add/copy
52
- 2. Ops that were added to where the move came from should be translated to the new path
53
- 3. Ops that are in an array with the moved item after need to be adjusted up or down
54
- 3a. But, ops that were translated to the new path shouldn't get adjusted up or down by these adjustments
55
- */
56
- // A move removes the value from one place then adds it to another, update the paths and add a marker to them so
57
- // they won't be altered by `updateArrayIndexes`, then remove the markers afterwards
58
- otherOps = mapAndFilterOps(otherOps, otherOp => {
59
- if (removed) {
60
- return otherOp;
61
- }
62
- const opLike = getTypeLike(state, otherOp);
63
- if (opLike === 'remove' && from === otherOp.path) {
64
- // Once an operation removes the moved value, the following ops should be working on the old location and not
65
- // not the new one. Allow the following operations (which may include add/remove) to affect the old location
66
- removed = true;
67
- }
68
- const original = otherOp;
69
- otherOp = updateMovePath(state, otherOp, 'path', from, path, original);
70
- otherOp = updateMovePath(state, otherOp, 'from', from, path, original);
71
- return otherOp;
72
- });
73
- // Remove/adjust items that were affected by this item moving (those that actually moved because of it will not
74
- // be affected because they have a temporary $ marker prefix that will keep them from doing so)
75
- if (isSameArray) {
76
- // need special logic when a move is within one array
77
- otherOps = updateArrayIndexesForMove(state, fromPrefix, fromIndex, pathIndex, otherOps);
78
- }
79
- else {
80
- // if a move is not within one array, treat it as a remove then add
81
- if (isArrayPath(from, state)) {
82
- otherOps = updateArrayIndexes(state, from, otherOps, -1);
83
- }
84
- else {
85
- otherOps = updateRemovedOps(state, from, otherOps);
86
- }
87
- if (isArrayPath(path, state)) {
88
- otherOps = updateArrayIndexes(state, path, otherOps, 1);
89
- }
90
- else {
91
- otherOps = updateRemovedOps(state, path, otherOps);
92
- }
93
- }
94
- // Remove the move markers added with `updateMovePath`
95
- return mapAndFilterOps(otherOps, removeMoveMarkers);
96
- },
97
- };
98
- /**
99
- * Update paths for a move operation, adding a marker so the path will not be altered by array updates.
100
- */
101
- function updateMovePath(state, op, pathName, from, to, original) {
102
- const path = op[pathName];
103
- if (!path)
104
- return op; // No adjustment needed on a property that doesn't exist
105
- // If a value is being added or copied to the old location it should not be adjusted
106
- if (isAdd(state, op, pathName) && op.path === from) {
107
- return op;
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ import { getOpData } from "../utils/getOpData.js";
3
+ import { getTypeLike } from "../utils/getType.js";
4
+ import { log } from "../utils/log.js";
5
+ import { isAdd, mapAndFilterOps, updateRemovedOps } from "../utils/ops.js";
6
+ import { getArrayPrefixAndIndex, getIndexAndEnd, isArrayPath } from "../utils/paths.js";
7
+ import { getValue, pluckWithShallowCopy } from "../utils/pluck.js";
8
+ import { toArrayIndex } from "../utils/toArrayIndex.js";
9
+ import { updateArrayIndexes } from "../utils/updateArrayIndexes.js";
10
+ import { add } from "./add.js";
11
+ const move = {
12
+ like: "move",
13
+ apply(state, path, from) {
14
+ if (path === from) return;
15
+ let value;
16
+ const [keys, lastKey, target] = getOpData(state, from);
17
+ if (target === null) {
18
+ return `[op:move] path not found: ${from}`;
108
19
  }
109
- // If this path needs to be changed due to a move operation, change it, but prefix it with a $ temporarily so when we
110
- // adjust the array indexes to account for this change, we aren't changing this path we JUST set. We will remove the
111
- // $ prefix right after we adjust arrays affected by this move.
112
- if (path === from || path.indexOf(from + '/') === 0) {
113
- if (op === original)
114
- op = Object.assign({}, op);
115
- log('Moving', op, 'from', from, 'to', to);
116
- // Add a marker "$" so this path will not be double-updated by array index updates
117
- op[pathName] = '$' + path.replace(from, to);
20
+ if (Array.isArray(target)) {
21
+ const index = toArrayIndex(target, lastKey);
22
+ if (index < 0 || target.length <= index) {
23
+ return `[op:move] invalid array index: ${path}`;
24
+ }
25
+ value = target[index];
26
+ pluckWithShallowCopy(state, keys, true).splice(index, 1);
27
+ } else {
28
+ value = target[lastKey];
29
+ delete pluckWithShallowCopy(state, keys, true)[lastKey];
30
+ }
31
+ return add.apply(state, path, value);
32
+ },
33
+ invert(_state, { path, from }) {
34
+ return { op: "move", from: path, path: "" + from };
35
+ },
36
+ transform(state, thisOp, otherOps) {
37
+ log("Transforming", otherOps, 'against "move"', thisOp);
38
+ let removed = false;
39
+ const { from, path } = thisOp;
40
+ if (from === path) return otherOps;
41
+ const [fromPrefix, fromIndex] = getArrayPrefixAndIndex(state, from);
42
+ const [pathPrefix, pathIndex] = getArrayPrefixAndIndex(state, path);
43
+ const isPathArray = pathPrefix !== void 0;
44
+ const isSameArray = isPathArray && pathPrefix === fromPrefix;
45
+ otherOps = mapAndFilterOps(otherOps, (otherOp) => {
46
+ if (removed) {
47
+ return otherOp;
48
+ }
49
+ const opLike = getTypeLike(state, otherOp);
50
+ if (opLike === "remove" && from === otherOp.path) {
51
+ removed = true;
52
+ }
53
+ const original = otherOp;
54
+ otherOp = updateMovePath(state, otherOp, "path", from, path, original);
55
+ otherOp = updateMovePath(state, otherOp, "from", from, path, original);
56
+ return otherOp;
57
+ });
58
+ if (isSameArray) {
59
+ otherOps = updateArrayIndexesForMove(state, fromPrefix, fromIndex, pathIndex, otherOps);
60
+ } else {
61
+ if (isArrayPath(from, state)) {
62
+ otherOps = updateArrayIndexes(state, from, otherOps, -1);
63
+ } else {
64
+ otherOps = updateRemovedOps(state, from, otherOps);
65
+ }
66
+ if (isArrayPath(path, state)) {
67
+ otherOps = updateArrayIndexes(state, path, otherOps, 1);
68
+ } else {
69
+ otherOps = updateRemovedOps(state, path, otherOps);
70
+ }
118
71
  }
72
+ return mapAndFilterOps(otherOps, removeMoveMarkers);
73
+ }
74
+ };
75
+ function updateMovePath(state, op, pathName, from, to, original) {
76
+ const path = op[pathName];
77
+ if (!path) return op;
78
+ if (isAdd(state, op, pathName) && op.path === from) {
119
79
  return op;
80
+ }
81
+ if (path === from || path.indexOf(from + "/") === 0) {
82
+ if (op === original) op = Object.assign({}, op);
83
+ log("Moving", op, "from", from, "to", to);
84
+ op[pathName] = "$" + path.replace(from, to);
85
+ }
86
+ return op;
120
87
  }
121
- /**
122
- * Update array indexes to account for values being added or removed from an array. If the path is not an array index
123
- * or if nothing is changed then the original array is returned.
124
- */
125
88
  function updateArrayIndexesForMove(state, prefix, fromIndex, pathIndex, otherOps) {
126
- // Check ops for any that need to be replaced
127
- log(`Shifting array indexes for a move between ${prefix}/${fromIndex} and ${prefix}/${pathIndex}`);
128
- return mapAndFilterOps(otherOps, otherOp => {
129
- // check for items from the same array that will be affected
130
- const fromUpdate = updateArrayPathForMove(state, otherOp, 'from', prefix, fromIndex, pathIndex);
131
- const pathUpdate = updateArrayPathForMove(state, otherOp, 'path', prefix, fromIndex, pathIndex);
132
- if (!fromUpdate || !pathUpdate)
133
- return null;
134
- if (fromUpdate !== otherOp || pathUpdate !== otherOp) {
135
- otherOp = { ...otherOp, path: pathUpdate.path };
136
- if (fromUpdate.from)
137
- otherOp.from = fromUpdate.from;
138
- }
139
- return otherOp;
140
- });
89
+ log(`Shifting array indexes for a move between ${prefix}/${fromIndex} and ${prefix}/${pathIndex}`);
90
+ return mapAndFilterOps(otherOps, (otherOp) => {
91
+ const fromUpdate = updateArrayPathForMove(state, otherOp, "from", prefix, fromIndex, pathIndex);
92
+ const pathUpdate = updateArrayPathForMove(state, otherOp, "path", prefix, fromIndex, pathIndex);
93
+ if (!fromUpdate || !pathUpdate) return null;
94
+ if (fromUpdate !== otherOp || pathUpdate !== otherOp) {
95
+ otherOp = { ...otherOp, path: pathUpdate.path };
96
+ if (fromUpdate.from) otherOp.from = fromUpdate.from;
97
+ }
98
+ return otherOp;
99
+ });
141
100
  }
142
- /**
143
- * Get the adjusted path if it is higher, or undefined if not.
144
- */
145
101
  function updateArrayPathForMove(state, otherOp, pathName, prefix, from, to) {
146
- const path = otherOp[pathName];
147
- if (!path || !path.startsWith(prefix))
102
+ const path = otherOp[pathName];
103
+ if (!path || !path.startsWith(prefix)) return otherOp;
104
+ const min = Math.min(from, to);
105
+ const max = Math.max(from, to);
106
+ const [otherIndex, end] = getIndexAndEnd(state, path, prefix.length);
107
+ if (otherIndex === void 0) return otherOp;
108
+ const isFinalProp = end === path.length;
109
+ const opLike = getTypeLike(state, otherOp);
110
+ if (otherIndex < min || otherIndex > max) {
111
+ return otherOp;
112
+ }
113
+ if (isFinalProp && isAdd(state, otherOp, pathName)) {
114
+ if (otherIndex === min) {
115
+ if (min === from) {
148
116
  return otherOp;
149
- const min = Math.min(from, to);
150
- const max = Math.max(from, to);
151
- const [otherIndex, end] = getIndexAndEnd(state, path, prefix.length);
152
- if (otherIndex === undefined)
153
- return otherOp; // if a prop on an array is being set, for e.g.
154
- const isFinalProp = end === path.length;
155
- const opLike = getTypeLike(state, otherOp);
156
- // If this index is not within the movement boundary, don't touch it
157
- if (otherIndex < min || otherIndex > max) {
117
+ } else {
158
118
  return otherOp;
119
+ }
120
+ } else if (otherIndex === max) {
121
+ if (max === from) {
122
+ const fromIndex = getIndexAndEnd(state, otherOp.from, prefix.length)[0];
123
+ if (opLike === "move" && pathName === "path" && to <= fromIndex && fromIndex < from) return otherOp;
124
+ } else {
125
+ return otherOp;
126
+ }
159
127
  }
160
- // If the index touches the boundary on an unaffected side, don't touch it
161
- if (isFinalProp && isAdd(state, otherOp, pathName)) {
162
- /*
163
- if the move is from low to high (min is a remove, max is an add) then
164
- use the remove logic with an add
165
-
166
- if the move is from high to low (min is an add, max is a remove) then
167
- use the add logic at the bottom
168
- */
169
- if (otherIndex === min) {
170
- if (min === from) {
171
- // treat like a remove
172
- return otherOp;
173
- }
174
- else {
175
- // treat like an add
176
- return otherOp;
177
- }
178
- }
179
- else if (otherIndex === max) {
180
- if (max === from) {
181
- // treat like a remove
182
- const fromIndex = getIndexAndEnd(state, otherOp.from, prefix.length)[0];
183
- if (opLike === 'move' && pathName === 'path' && to <= fromIndex && fromIndex < from)
184
- return otherOp;
185
- // continue
186
- }
187
- else {
188
- // treat like an add
189
- return otherOp;
190
- }
191
- }
192
- }
193
- const modifier = from === min ? -1 : 1;
194
- const newPath = prefix + (otherIndex + modifier) + path.slice(end);
195
- return getValue(state, otherOp, pathName, newPath);
128
+ }
129
+ const modifier = from === min ? -1 : 1;
130
+ const newPath = prefix + (otherIndex + modifier) + path.slice(end);
131
+ return getValue(state, otherOp, pathName, newPath);
196
132
  }
197
- /**
198
- * Remove any move markers placed during updateMovePath. This occurs in-place since these objects have already been
199
- * cloned.
200
- */
201
133
  function removeMoveMarkers(op) {
202
- if (op.path[0] === '$') {
203
- op.path = op.path.slice(1);
204
- }
205
- if (op.from && op.from[0] === '$') {
206
- op.from = op.from.slice(1);
207
- }
208
- if (op.from === op.path)
209
- return null;
210
- return op;
134
+ if (op.path[0] === "$") {
135
+ op.path = op.path.slice(1);
136
+ }
137
+ if (op.from && op.from[0] === "$") {
138
+ op.from = op.from.slice(1);
139
+ }
140
+ if (op.from === op.path) return null;
141
+ return op;
211
142
  }
143
+ export {
144
+ move
145
+ };
@@ -1,2 +1,5 @@
1
- import type { JSONPatchOpHandler } from '../types.js';
2
- export declare const remove: JSONPatchOpHandler;
1
+ import { JSONPatchOpHandler } from '../types.js';
2
+
3
+ declare const remove: JSONPatchOpHandler;
4
+
5
+ export { remove };
@@ -1,31 +1,34 @@
1
- import { getOpData } from '../utils/getOpData.js';
2
- import { log } from '../utils/log.js';
3
- import { transformRemove } from '../utils/ops.js';
4
- import { pluckWithShallowCopy } from '../utils/pluck.js';
5
- import { toArrayIndex } from '../utils/toArrayIndex.js';
6
- export const remove = {
7
- like: 'remove',
8
- apply(state, path) {
9
- const [keys, lastKey, target] = getOpData(state, path);
10
- if (target === null) {
11
- return;
12
- }
13
- if (Array.isArray(target)) {
14
- const index = toArrayIndex(target, lastKey);
15
- if (index < 0 || target.length <= index) {
16
- return '[op:remove] invalid array index: ' + path;
17
- }
18
- pluckWithShallowCopy(state, keys).splice(index, 1);
19
- }
20
- else {
21
- delete pluckWithShallowCopy(state, keys)[lastKey];
22
- }
23
- },
24
- invert(_state, { path }, value) {
25
- return { op: 'add', path, value };
26
- },
27
- transform(state, thisOp, otherOps) {
28
- log('Transforming', otherOps, 'against "remove"', thisOp);
29
- return transformRemove(state, thisOp.path, otherOps, true);
30
- },
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ import { getOpData } from "../utils/getOpData.js";
3
+ import { log } from "../utils/log.js";
4
+ import { transformRemove } from "../utils/ops.js";
5
+ import { pluckWithShallowCopy } from "../utils/pluck.js";
6
+ import { toArrayIndex } from "../utils/toArrayIndex.js";
7
+ const remove = {
8
+ like: "remove",
9
+ apply(state, path) {
10
+ const [keys, lastKey, target] = getOpData(state, path);
11
+ if (target === null) {
12
+ return;
13
+ }
14
+ if (Array.isArray(target)) {
15
+ const index = toArrayIndex(target, lastKey);
16
+ if (index < 0 || target.length <= index) {
17
+ return "[op:remove] invalid array index: " + path;
18
+ }
19
+ pluckWithShallowCopy(state, keys).splice(index, 1);
20
+ } else {
21
+ delete pluckWithShallowCopy(state, keys)[lastKey];
22
+ }
23
+ },
24
+ invert(_state, { path }, value) {
25
+ return { op: "add", path, value };
26
+ },
27
+ transform(state, thisOp, otherOps) {
28
+ log("Transforming", otherOps, 'against "remove"', thisOp);
29
+ return transformRemove(state, thisOp.path, otherOps, true);
30
+ }
31
+ };
32
+ export {
33
+ remove
31
34
  };
@@ -1,2 +1,5 @@
1
- import type { JSONPatchOpHandler } from '../types.js';
2
- export declare const replace: JSONPatchOpHandler;
1
+ import { JSONPatchOpHandler } from '../types.js';
2
+
3
+ declare const replace: JSONPatchOpHandler;
4
+
5
+ export { replace };
@@ -1,44 +1,46 @@
1
- import { deepEqual } from '../utils/deepEqual.js';
2
- import { getOpData } from '../utils/getOpData.js';
3
- import { log } from '../utils/log.js';
4
- import { updateRemovedOps } from '../utils/ops.js';
5
- import { pluckWithShallowCopy } from '../utils/pluck.js';
6
- import { toArrayIndex } from '../utils/toArrayIndex.js';
7
- export const replace = {
8
- like: 'replace',
9
- apply(state, path, value) {
10
- if (typeof value === 'undefined') {
11
- return '[op:replace] require value, but got undefined';
12
- }
13
- const [keys, lastKey, target] = getOpData(state, path, true);
14
- if (target === null) {
15
- return `[op:replace] path not found: ${path}`;
16
- }
17
- if (Array.isArray(target)) {
18
- const index = toArrayIndex(target, lastKey);
19
- if (index < 0 || target.length <= index) {
20
- return `[op:replace] invalid array index: ${path}`;
21
- }
22
- if (!deepEqual(target[index], value)) {
23
- pluckWithShallowCopy(state, keys, true).splice(index, 1, value);
24
- }
25
- }
26
- else {
27
- if (!deepEqual(target[lastKey], value)) {
28
- pluckWithShallowCopy(state, keys, true)[lastKey] = value;
29
- }
30
- }
31
- },
32
- invert(_state, { path }, value, changedObj) {
33
- if (path.endsWith('/-'))
34
- path = path.replace('-', changedObj.length);
35
- return value === undefined ? { op: 'remove', path } : { op: 'replace', path, value };
36
- },
37
- transform(state, thisOp, otherOps) {
38
- log('Transforming ', otherOps, ' against "replace"', thisOp);
39
- return updateRemovedOps(state, thisOp.path, otherOps);
40
- },
41
- compose(_state, _value1, value2) {
42
- return value2;
43
- },
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ import { deepEqual } from "../utils/deepEqual.js";
3
+ import { getOpData } from "../utils/getOpData.js";
4
+ import { log } from "../utils/log.js";
5
+ import { updateRemovedOps } from "../utils/ops.js";
6
+ import { pluckWithShallowCopy } from "../utils/pluck.js";
7
+ import { toArrayIndex } from "../utils/toArrayIndex.js";
8
+ const replace = {
9
+ like: "replace",
10
+ apply(state, path, value) {
11
+ if (typeof value === "undefined") {
12
+ return "[op:replace] require value, but got undefined";
13
+ }
14
+ const [keys, lastKey, target] = getOpData(state, path, true);
15
+ if (target === null) {
16
+ return `[op:replace] path not found: ${path}`;
17
+ }
18
+ if (Array.isArray(target)) {
19
+ const index = toArrayIndex(target, lastKey);
20
+ if (index < 0 || target.length <= index) {
21
+ return `[op:replace] invalid array index: ${path}`;
22
+ }
23
+ if (!deepEqual(target[index], value)) {
24
+ pluckWithShallowCopy(state, keys, true).splice(index, 1, value);
25
+ }
26
+ } else {
27
+ if (!deepEqual(target[lastKey], value)) {
28
+ pluckWithShallowCopy(state, keys, true)[lastKey] = value;
29
+ }
30
+ }
31
+ },
32
+ invert(_state, { path }, value, changedObj) {
33
+ if (path.endsWith("/-")) path = path.replace("-", changedObj.length);
34
+ return value === void 0 ? { op: "remove", path } : { op: "replace", path, value };
35
+ },
36
+ transform(state, thisOp, otherOps) {
37
+ log("Transforming ", otherOps, ' against "replace"', thisOp);
38
+ return updateRemovedOps(state, thisOp.path, otherOps);
39
+ },
40
+ compose(_state, _value1, value2) {
41
+ return value2;
42
+ }
43
+ };
44
+ export {
45
+ replace
44
46
  };
@@ -1,2 +1,5 @@
1
- import type { JSONPatchOpHandler } from '../types.js';
2
- export declare const test: JSONPatchOpHandler;
1
+ import { JSONPatchOpHandler } from '../types.js';
2
+
3
+ declare const test: JSONPatchOpHandler;
4
+
5
+ export { test };
@@ -1,22 +1,26 @@
1
- import { deepEqual } from '../utils/deepEqual.js';
2
- import { getOpData } from '../utils/getOpData.js';
3
- export const test = {
4
- like: 'test',
5
- apply(state, path, expected) {
6
- const [, lastKey, target] = getOpData(state, path);
7
- if (target === null) {
8
- return `[op:test] path not found: ${path}`;
9
- }
10
- if (!deepEqual(target[lastKey], expected)) {
11
- const a = JSON.stringify(target[lastKey]);
12
- const b = JSON.stringify(expected);
13
- return `[op:test] not matched: ${a} ${b}`;
14
- }
15
- },
16
- invert() {
17
- return undefined;
18
- },
19
- transform(_state, _other, ops) {
20
- return ops;
21
- },
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ import { deepEqual } from "../utils/deepEqual.js";
3
+ import { getOpData } from "../utils/getOpData.js";
4
+ const test = {
5
+ like: "test",
6
+ apply(state, path, expected) {
7
+ const [, lastKey, target] = getOpData(state, path);
8
+ if (target === null) {
9
+ return `[op:test] path not found: ${path}`;
10
+ }
11
+ if (!deepEqual(target[lastKey], expected)) {
12
+ const a = JSON.stringify(target[lastKey]);
13
+ const b = JSON.stringify(expected);
14
+ return `[op:test] not matched: ${a} ${b}`;
15
+ }
16
+ },
17
+ invert() {
18
+ return void 0;
19
+ },
20
+ transform(_state, _other, ops) {
21
+ return ops;
22
+ }
23
+ };
24
+ export {
25
+ test
22
26
  };
@@ -1,2 +1,5 @@
1
- import type { JSONPatchOpHandler } from '../types.js';
2
- export declare const text: JSONPatchOpHandler;
1
+ import { JSONPatchOpHandler } from '../types.js';
2
+
3
+ declare const text: JSONPatchOpHandler;
4
+
5
+ export { text };