@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,14 +1,17 @@
1
- import type { JSONPatchOp, State } from '../types.js';
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
- export declare function isAdd(state: State, op: JSONPatchOp, pathName: 'from' | 'path'): boolean;
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
- export declare function mapAndFilterOps(ops: JSONPatchOp[], iterator: (op: JSONPatchOp, index: number, breakAfter: (keepRest?: boolean) => void) => JSONPatchOp | JSONPatchOp[] | null): JSONPatchOp[];
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
- export declare function updateRemovedOps(state: State, thisPath: string, otherOps: JSONPatchOp[], isRemove?: boolean, updatableObject?: boolean, opOp?: string, customHandler?: (op: JSONPatchOp) => any): JSONPatchOp[];
14
- export declare function transformRemove(state: State, thisPath: string, otherOps: JSONPatchOp[], isRemove?: boolean): JSONPatchOp[];
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 { getTypeLike } from './getType.js';
2
- import { log } from './log.js';
3
- import { isArrayPath } from './paths.js';
4
- import { updateArrayIndexes } from './updateArrayIndexes.js';
5
- /**
6
- * Check whether this operation is an add operation of some sort (add, copy, move).
7
- */
8
- export function isAdd(state, op, pathName) {
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
- * Transforms an array of ops, returning the original if there is no change, filtering out ops that are dropped.
14
- */
15
- export function mapAndFilterOps(ops, iterator) {
16
- let changed = false;
17
- const mapped = [];
18
- let shouldBreak = false;
19
- let keepRest;
20
- const breakAfter = (keep) => {
21
- shouldBreak = true;
22
- keepRest = keep;
23
- };
24
- for (let i = 0; i < ops.length; i++) {
25
- const original = ops[i];
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
- return changed ? mapped : ops;
48
- }
49
- /**
50
- * Remove operations that apply to a value which was removed.
51
- */
52
- export function updateRemovedOps(state, thisPath, otherOps, isRemove = false, updatableObject = false, opOp, customHandler) {
53
- const softPrefixes = new Set();
54
- return mapAndFilterOps(otherOps, (op, index, breakAfter) => {
55
- const opLike = getTypeLike(state, op);
56
- const canMergeCustom = customHandler && opOp === op.op;
57
- if (thisPath === op.path && opLike !== 'remove' && !canMergeCustom && !op.soft) {
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
- export function transformRemove(state, thisPath, otherOps, isRemove) {
100
- if (isArrayPath(thisPath, state)) {
101
- return updateArrayIndexes(state, thisPath, otherOps, -1, isRemove);
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
- else {
104
- return updateRemovedOps(state, thisPath, otherOps, isRemove);
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 type { State } from '../types.js';
2
- export declare function getPrefix(path: string): string;
3
- export declare function getProp(path: string): string;
4
- export declare function getPrefixAndProp(path: string): [string, string];
5
- export declare function getPropAfter(path: string, index: number): string;
6
- export declare function isArrayPath(path: string, state?: State): boolean;
7
- export declare function getArrayPrefixAndIndex(state: State, path: string, pathLength?: number): [string, number];
8
- export declare function getArrayIndex(state: State, path: string, pathLength?: number): number;
9
- export declare function getIndexAndEnd(state: State, path: string | undefined, maxLength: number): number[];
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 { getOpData } from './getOpData.js';
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ import { getOpData } from "./getOpData.js";
2
3
  const arrayPathExp = /\/(0|[1-9]\d*)$/;
3
4
  const EMPTY = [];
4
- export function getPrefix(path) {
5
- const lastSlash = path.lastIndexOf('/');
6
- return path.slice(0, lastSlash + 1);
7
- }
8
- export function getProp(path) {
9
- const lastSlash = path.lastIndexOf('/');
10
- return path.slice(lastSlash + 1);
11
- }
12
- export function getPrefixAndProp(path) {
13
- const prefix = getPrefix(path);
14
- return [prefix, path.slice(prefix.length)];
15
- }
16
- export function getPropAfter(path, index) {
17
- const lastSlash = path.indexOf('/', index);
18
- return path.slice(index, lastSlash === -1 ? undefined : lastSlash);
19
- }
20
- export function isArrayPath(path, state) {
21
- if (!arrayPathExp.test(path))
22
- return false;
23
- if (!state || !state.root || !state.root[''])
24
- return true;
25
- // Double-check if this is an array or not
26
- const [, , target] = getOpData(state, path);
27
- return Array.isArray(target) || target == null;
28
- }
29
- export function getArrayPrefixAndIndex(state, path, pathLength) {
30
- if (pathLength)
31
- path = path.slice(0, path.indexOf('/', pathLength));
32
- if (!arrayPathExp.test(path))
33
- return EMPTY;
34
- const [, , target] = getOpData(state, path);
35
- if (!Array.isArray(target))
36
- return EMPTY;
37
- const [prefix, indexStr] = getPrefixAndProp(path);
38
- const index = parseInt(indexStr);
39
- return [prefix, index];
40
- }
41
- export function getArrayIndex(state, path, pathLength) {
42
- return getArrayPrefixAndIndex(state, path, pathLength)[1];
43
- }
44
- export function getIndexAndEnd(state, path, maxLength) {
45
- if (!path)
46
- return [];
47
- const prop = getPropAfter(path, maxLength);
48
- const end = maxLength + prop.length;
49
- if (!isArrayPath(path.slice(0, end), state))
50
- return [];
51
- const index = parseInt(prop);
52
- return [index, end];
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 type { State } from '../types.js';
2
- export declare const EMPTY: {};
3
- export declare function pluck(state: State, keys: string[]): any;
4
- export declare function pluckWithShallowCopy(state: State, keys: string[], createMissingObjects?: boolean): any;
5
- export declare function getValue(state: State, value: any, addKey?: string, addValue?: any): any;
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 { shallowCopy } from './shallowCopy.js';
2
- export const EMPTY = {};
3
- export function pluck(state, keys) {
4
- let object = state.root;
5
- for (let i = 0, imax = keys.length - 1; i < imax; i++) {
6
- const key = keys[i];
7
- if (!object[key]) {
8
- return null;
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
- return object;
11
+ object = object[key];
12
+ }
13
+ return object;
13
14
  }
14
- export function pluckWithShallowCopy(state, keys, createMissingObjects) {
15
- let object = state.root;
16
- for (let i = 0, imax = keys.length - 1; i < imax; i++) {
17
- const key = keys[i];
18
- object = object[key] = createMissingObjects && !object[key] ? getValue(state, EMPTY) : getValue(state, object[key]);
19
- }
20
- return object;
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
- export function getValue(state, value, addKey, addValue) {
23
- if (!state.cache?.has(value)) {
24
- value = shallowCopy(value);
25
- state.cache?.add(value);
26
- }
27
- if (addKey)
28
- value[addKey] = addValue;
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 +1,3 @@
1
- export declare function shallowCopy(obj: any): any;
1
+ declare function shallowCopy(obj: any): any;
2
+
3
+ export { shallowCopy };
@@ -1,20 +1,24 @@
1
- export function shallowCopy(obj) {
2
- if (!obj || typeof obj !== 'object') {
3
- return obj;
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
- if (Array.isArray(obj)) {
6
- const len = obj.length;
7
- const ary = new Array(len);
8
- for (let i = 0; i < len; i++) {
9
- ary[i] = obj[i];
10
- }
11
- return ary;
12
- }
13
- const keys = Object.keys(obj);
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 type { JSONPatchOp } from '../types.js';
2
- export declare function isEmptyObject(value: any): boolean;
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
- export declare function updateSoftWrites(overPath: string, ops: JSONPatchOp[]): JSONPatchOp[];
8
+ declare function updateSoftWrites(overPath: string, ops: JSONPatchOp[]): JSONPatchOp[];
9
+
10
+ export { isEmptyObject, updateSoftWrites };
@@ -1,18 +1,19 @@
1
- import { log } from './log.js';
2
- import { mapAndFilterOps } from './ops.js';
3
- export function isEmptyObject(value) {
4
- return Boolean(value && typeof value === 'object' && Object.keys(value).length === 0);
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
- * If other objects were added to this same path, assume they are maps/hashes/lookups and don't overwrite, allow
8
- * subsequent ops to merge onto the first map created. `soft` will also do this for any value that already exists.
9
- */
10
- export function updateSoftWrites(overPath, ops) {
11
- return mapAndFilterOps(ops, op => {
12
- if (op.op === 'add' && op.path === overPath && isEmptyObject(op.value)) {
13
- log('Removing empty object', op);
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 +1,3 @@
1
- export declare function toArrayIndex(array: any[], str: string): number;
1
+ declare function toArrayIndex(array: any[], str: string): number;
2
+
3
+ export { toArrayIndex };
@@ -1,12 +1,16 @@
1
- export function toArrayIndex(array, str) {
2
- if (str === '-') {
3
- return array.length;
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
- for (let i = 0, imax = str.length; i < imax; i++) {
6
- const ch = str.charCodeAt(i);
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 +1,3 @@
1
- export declare function toKeys(path: string): string[];
1
+ declare function toKeys(path: string): string[];
2
+
3
+ export { toKeys };
@@ -1,15 +1,19 @@
1
+ import "../../chunk-IZ2YBCUP.js";
1
2
  function esc(m) {
2
- return m === '~0' ? '~' : '/';
3
+ return m === "~0" ? "~" : "/";
3
4
  }
4
- export function toKeys(path) {
5
- const keys = path.split('/');
6
- if (!path.includes('~')) {
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 type { JSONPatchOp, State } from '../types.js';
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
- export declare function updateArrayIndexes(state: State, thisPath: string, otherOps: JSONPatchOp[], modifier: 1 | -1, isRemove?: boolean): JSONPatchOp[];
6
+ declare function updateArrayIndexes(state: State, thisPath: string, otherOps: JSONPatchOp[], modifier: 1 | -1, isRemove?: boolean): JSONPatchOp[];
7
+
8
+ export { updateArrayIndexes };