@dabble/patches 0.4.4 → 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 +49 -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,57 +1,57 @@
1
- import { Delta } from '@dabble/delta';
2
- import { replace } from '../ops/replace.js';
3
- import { get } from '../utils/get.js';
4
- import { log } from '../utils/log.js';
5
- import { updateRemovedOps } from '../utils/ops.js';
6
- export const text = {
7
- like: 'replace',
8
- apply(state, path, value) {
9
- const delta = Array.isArray(value) ? new Delta(value) : value;
10
- if (!delta || !Array.isArray(delta.ops)) {
11
- return 'Invalid delta';
12
- }
13
- const existingData = get(state, path);
14
- let doc;
15
- if (Array.isArray(existingData)) {
16
- if (existingData.length && existingData[0].insert) {
17
- doc = new Delta(existingData);
18
- }
19
- }
20
- else if (existingData && existingData.ops) {
21
- doc = new Delta(existingData.ops);
22
- }
23
- if (!doc) {
24
- doc = new Delta().insert('\n');
25
- }
26
- doc = doc.compose(delta);
27
- if (hasInvalidOps(doc)) {
28
- return 'Invalid text delta provided for this text document';
29
- }
30
- return replace.apply(state, path, doc);
31
- },
32
- transform(state, thisOp, otherOps) {
33
- log('Transforming ', otherOps, ' against "@txt"', thisOp);
34
- return updateRemovedOps(state, thisOp.path, otherOps, false, true, thisOp.op, op => {
35
- if (op.path !== thisOp.path)
36
- return null; // If a subpath, it is overwritten
37
- if (!op.value || !Array.isArray(op.value))
38
- return null; // If not a delta, it is overwritten
39
- const thisDelta = new Delta(thisOp.value);
40
- let otherDelta = new Delta(op.value);
41
- otherDelta = thisDelta.transform(otherDelta, true);
42
- return { ...op, value: otherDelta.ops };
43
- });
44
- },
45
- invert(state, { path, value }, oldValue, changedObj) {
46
- if (path.endsWith('/-'))
47
- path = path.replace('-', changedObj.length);
48
- const delta = new Delta(value);
49
- return oldValue === undefined ? { op: 'remove', path } : { op: '@txt', path, value: delta.invert(oldValue) };
50
- },
51
- compose(state, delta1, delta2) {
52
- return new Delta(delta1).compose(new Delta(delta2));
53
- },
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ import { Delta } from "@dabble/delta";
3
+ import { replace } from "../ops/replace.js";
4
+ import { get } from "../utils/get.js";
5
+ import { log } from "../utils/log.js";
6
+ import { updateRemovedOps } from "../utils/ops.js";
7
+ const text = {
8
+ like: "replace",
9
+ apply(state, path, value) {
10
+ const delta = Array.isArray(value) ? new Delta(value) : value;
11
+ if (!delta || !Array.isArray(delta.ops)) {
12
+ return "Invalid delta";
13
+ }
14
+ const existingData = get(state, path);
15
+ let doc;
16
+ if (Array.isArray(existingData)) {
17
+ if (existingData.length && existingData[0].insert) {
18
+ doc = new Delta(existingData);
19
+ }
20
+ } else if (existingData && existingData.ops) {
21
+ doc = new Delta(existingData.ops);
22
+ }
23
+ if (!doc) {
24
+ doc = new Delta().insert("\n");
25
+ }
26
+ doc = doc.compose(delta);
27
+ if (hasInvalidOps(doc)) {
28
+ return "Invalid text delta provided for this text document";
29
+ }
30
+ return replace.apply(state, path, doc);
31
+ },
32
+ transform(state, thisOp, otherOps) {
33
+ log("Transforming ", otherOps, ' against "@txt"', thisOp);
34
+ return updateRemovedOps(state, thisOp.path, otherOps, false, true, thisOp.op, (op) => {
35
+ if (op.path !== thisOp.path) return null;
36
+ if (!op.value || !Array.isArray(op.value)) return null;
37
+ const thisDelta = new Delta(thisOp.value);
38
+ let otherDelta = new Delta(op.value);
39
+ otherDelta = thisDelta.transform(otherDelta, true);
40
+ return { ...op, value: otherDelta.ops };
41
+ });
42
+ },
43
+ invert(state, { path, value }, oldValue, changedObj) {
44
+ if (path.endsWith("/-")) path = path.replace("-", changedObj.length);
45
+ const delta = new Delta(value);
46
+ return oldValue === void 0 ? { op: "remove", path } : { op: "@txt", path, value: delta.invert(oldValue) };
47
+ },
48
+ compose(state, delta1, delta2) {
49
+ return new Delta(delta1).compose(new Delta(delta2));
50
+ }
54
51
  };
55
52
  function hasInvalidOps(doc) {
56
- return doc.ops.some(op => typeof op.insert !== 'string' && (typeof op.insert !== 'object' || op.insert === null));
53
+ return doc.ops.some((op) => typeof op.insert !== "string" && (typeof op.insert !== "object" || op.insert === null));
57
54
  }
55
+ export {
56
+ text
57
+ };
@@ -1,4 +1,8 @@
1
- import type { PathProxy } from '../types.js';
1
+ import { PathProxy } from '../types.js';
2
+ import './JSONPatch.js';
3
+ import '@dabble/delta';
4
+ import './types.js';
5
+
2
6
  /**
3
7
  * Creates a path proxy for generating JSON Pointer paths in a type-safe way.
4
8
  * This proxy should ONLY be used for path creation with JSONPatch methods.
@@ -18,5 +22,7 @@ import type { PathProxy } from '../types.js';
18
22
  * @template T The type of the object to create paths for.
19
23
  * @returns A path proxy object.
20
24
  */
21
- export declare const createPathProxy: <T>() => PathProxy<T>;
22
- export declare function pathProxy<T>(path?: string): PathProxy<T>;
25
+ declare const createPathProxy: <T = any>() => PathProxy<T>;
26
+ declare function pathProxy<T>(path?: string): PathProxy<T>;
27
+
28
+ export { createPathProxy, pathProxy };
@@ -1,50 +1,29 @@
1
- // We use a function as the target so that `push` and other array methods can be called without error.
1
+ import "../chunk-IZ2YBCUP.js";
2
2
  const proxyFodder = {};
3
- /**
4
- * Creates a path proxy for generating JSON Pointer paths in a type-safe way.
5
- * This proxy should ONLY be used for path creation with JSONPatch methods.
6
- *
7
- * Usage:
8
- * ```ts
9
- * const patch = new JSONPatch();
10
- * const path = createPathProxy<MyType>();
11
- * patch.replace(path.content, 'new text'); // Path is '/content'
12
- * patch.increment(path.counter, 5); // Path is '/counter'
13
- * patch.add(path.items[0], newItem); // Path is '/items/0'
14
- * ```
15
- *
16
- * The proxy will throw errors if you attempt to set properties or delete properties.
17
- * This prevents accidental mutation and ensures explicit patch operations are used.
18
- *
19
- * @template T The type of the object to create paths for.
20
- * @returns A path proxy object.
21
- */
22
- export const createPathProxy = pathProxy;
23
- // Internal implementation with the path parameter
24
- export function pathProxy(path = '') {
25
- // Always use an empty function as the proxy target
26
- // This allows us to proxy any type of value, including primitives and undefined,
27
- // and enables calling array methods like push/splice directly on array proxies.
28
- return new Proxy(proxyFodder, {
29
- get(_, prop) {
30
- // Handle toString specially to make properties work as PathLike
31
- if (prop === 'toString') {
32
- return function () {
33
- return path;
34
- };
35
- }
36
- // Create a proxy for the property to continue path building
37
- return pathProxy(`${path}/${prop}`);
38
- },
39
- set(_, prop) {
40
- throw new Error(`Cannot set property '${prop}' on path proxy. ` +
41
- `Path proxies are for generating JSON Pointer paths only. ` +
42
- `Use JSONPatch methods instead: patch.replace(path.${prop}, value)`);
43
- },
44
- deleteProperty(_, prop) {
45
- throw new Error(`Cannot delete property '${prop}' on path proxy. ` +
46
- `Path proxies are for generating JSON Pointer paths only. ` +
47
- `Use JSONPatch methods instead: patch.remove(path.${prop})`);
48
- },
49
- });
3
+ const createPathProxy = pathProxy;
4
+ function pathProxy(path = "") {
5
+ return new Proxy(proxyFodder, {
6
+ get(_, prop) {
7
+ if (prop === "toString") {
8
+ return function() {
9
+ return path;
10
+ };
11
+ }
12
+ return pathProxy(`${path}/${prop}`);
13
+ },
14
+ set(_, prop) {
15
+ throw new Error(
16
+ `Cannot set property '${prop}' on path proxy. Path proxies are for generating JSON Pointer paths only. Use JSONPatch methods instead: patch.replace(path.${prop}, value)`
17
+ );
18
+ },
19
+ deleteProperty(_, prop) {
20
+ throw new Error(
21
+ `Cannot delete property '${prop}' on path proxy. Path proxies are for generating JSON Pointer paths only. Use JSONPatch methods instead: patch.remove(path.${prop})`
22
+ );
23
+ }
24
+ });
50
25
  }
26
+ export {
27
+ createPathProxy,
28
+ pathProxy
29
+ };
@@ -1,2 +1,5 @@
1
- import type { JSONPatchOpHandlerMap, Runner } from './types.js';
2
- export declare function runWithObject(object: any, allTypes: JSONPatchOpHandlerMap, shouldCache: boolean, callback: Runner): any;
1
+ import { JSONPatchOpHandlerMap, Runner } from './types.js';
2
+
3
+ declare function runWithObject(object: any, allTypes: JSONPatchOpHandlerMap, shouldCache: boolean, callback: Runner): any;
4
+
5
+ export { runWithObject };
@@ -1,8 +1,12 @@
1
- export function runWithObject(object, allTypes, shouldCache, callback) {
2
- const state = {
3
- root: { '': object },
4
- types: allTypes,
5
- cache: shouldCache ? new Set() : null,
6
- };
7
- return callback(state) || state.root[''];
1
+ import "../chunk-IZ2YBCUP.js";
2
+ function runWithObject(object, allTypes, shouldCache, callback) {
3
+ const state = {
4
+ root: { "": object },
5
+ types: allTypes,
6
+ cache: shouldCache ? /* @__PURE__ */ new Set() : null
7
+ };
8
+ return callback(state) || state.root[""];
8
9
  }
10
+ export {
11
+ runWithObject
12
+ };
@@ -1,3 +1,5 @@
1
+ import { JSONPatchOp, JSONPatchOpHandlerMap } from './types.js';
2
+
1
3
  /*!
2
4
  * Based on work from
3
5
  * https://github.com/Palindrom/JSONPatchOT
@@ -10,10 +12,12 @@
10
12
  * WARNING: using /array/- syntax to indicate the end of the array makes it impossible to transform arrays correctly in
11
13
  * all situaions. Please avoid using this syntax when using Operational Transformations.
12
14
  */
13
- import type { JSONPatchOp, JSONPatchOpHandlerMap } from './types.js';
15
+
14
16
  /**
15
17
  * Transform an array of JSON Patch operations against another array of JSON Patch operations. Returns a new array with
16
18
  * transformed operations. Operations that change are cloned, making the results of this function immutable.
17
19
  * `otherOps` are transformed over `thisOps` with thisOps considered to have happened first.
18
20
  */
19
- export declare function transformPatch(obj: any, thisOps: JSONPatchOp[], otherOps: JSONPatchOp[], custom?: JSONPatchOpHandlerMap): JSONPatchOp[];
21
+ declare function transformPatch(obj: any, thisOps: JSONPatchOp[], otherOps: JSONPatchOp[], custom?: JSONPatchOpHandlerMap): JSONPatchOp[];
22
+
23
+ export { transformPatch };
@@ -1,3 +1,4 @@
1
+ import "../chunk-IZ2YBCUP.js";
1
2
  /*!
2
3
  * Based on work from
3
4
  * https://github.com/Palindrom/JSONPatchOT
@@ -10,28 +11,24 @@
10
11
  * WARNING: using /array/- syntax to indicate the end of the array makes it impossible to transform arrays correctly in
11
12
  * all situaions. Please avoid using this syntax when using Operational Transformations.
12
13
  */
13
- import { getTypes } from './ops/index.js';
14
- import { runWithObject } from './state.js';
15
- import { getType } from './utils/getType.js';
16
- import { log } from './utils/log.js';
17
- /**
18
- * Transform an array of JSON Patch operations against another array of JSON Patch operations. Returns a new array with
19
- * transformed operations. Operations that change are cloned, making the results of this function immutable.
20
- * `otherOps` are transformed over `thisOps` with thisOps considered to have happened first.
21
- */
22
- export function transformPatch(obj, thisOps, otherOps, custom) {
23
- const types = getTypes(custom);
24
- return runWithObject(obj, types, false, state => {
25
- return thisOps.reduce((otherOps, thisOp) => {
26
- // transform ops with patch operation
27
- const handler = getType(state, thisOp)?.transform;
28
- if (typeof handler === 'function') {
29
- otherOps = handler(state, thisOp, otherOps);
30
- }
31
- else {
32
- log('No function to transform against for', thisOp.op);
33
- }
34
- return otherOps;
35
- }, otherOps);
36
- });
14
+ import { getTypes } from "./ops/index.js";
15
+ import { runWithObject } from "./state.js";
16
+ import { getType } from "./utils/getType.js";
17
+ import { log } from "./utils/log.js";
18
+ function transformPatch(obj, thisOps, otherOps, custom) {
19
+ const types = getTypes(custom);
20
+ return runWithObject(obj, types, false, (state) => {
21
+ return thisOps.reduce((otherOps2, thisOp) => {
22
+ const handler = getType(state, thisOp)?.transform;
23
+ if (typeof handler === "function") {
24
+ otherOps2 = handler(state, thisOp, otherOps2);
25
+ } else {
26
+ log("No function to transform against for", thisOp.op);
27
+ }
28
+ return otherOps2;
29
+ }, otherOps);
30
+ });
37
31
  }
32
+ export {
33
+ transformPatch
34
+ };
@@ -1,14 +1,14 @@
1
- export interface JSONPatchOpHandler {
1
+ interface JSONPatchOpHandler {
2
2
  like: 'add' | 'remove' | 'replace' | 'move' | 'copy' | 'test';
3
3
  apply(state: State, path: string, valueOrFrom: any): string | void;
4
4
  transform(state: State, other: JSONPatchOp, ops: JSONPatchOp[]): JSONPatchOp[];
5
5
  invert(state: State, op: JSONPatchOp, value: any, changedObj: any, isIndex: boolean): JSONPatchOp;
6
6
  compose?(state: State, value1: any, value2: any): any;
7
7
  }
8
- export interface JSONPatchOpHandlerMap {
8
+ interface JSONPatchOpHandlerMap {
9
9
  [key: string]: JSONPatchOpHandler;
10
10
  }
11
- export interface ApplyJSONPatchOptions {
11
+ interface ApplyJSONPatchOptions {
12
12
  /**
13
13
  * Do not reject patches if error occurs (partial patching)
14
14
  */
@@ -34,19 +34,21 @@ export interface ApplyJSONPatchOptions {
34
34
  */
35
35
  atPath?: string;
36
36
  }
37
- export interface JSONPatchOp {
37
+ interface JSONPatchOp {
38
38
  op: string;
39
39
  path: string;
40
40
  from?: string;
41
41
  value?: any;
42
42
  soft?: boolean;
43
43
  }
44
- export interface Root {
44
+ interface Root {
45
45
  '': any;
46
46
  }
47
- export type State = {
47
+ type State = {
48
48
  root: Root;
49
49
  types: JSONPatchOpHandlerMap;
50
50
  cache: Set<any> | null;
51
51
  };
52
- export type Runner = (state: State) => any;
52
+ type Runner = (state: State) => any;
53
+
54
+ export type { ApplyJSONPatchOptions, JSONPatchOp, JSONPatchOpHandler, JSONPatchOpHandlerMap, Root, Runner, State };
@@ -1 +0,0 @@
1
- export {};
@@ -1 +1,3 @@
1
- export declare function deepEqual(a: any, b: any): boolean;
1
+ declare function deepEqual(a: any, b: any): boolean;
2
+
3
+ export { deepEqual };
@@ -1,33 +1,37 @@
1
- export function deepEqual(a, b) {
2
- if (a === b) {
3
- return true;
4
- }
5
- if (!(a && b) || typeof a !== 'object' || typeof b !== 'object') {
6
- return false;
7
- }
8
- if (a.length !== b.length) {
9
- return false;
10
- }
11
- if (Array.isArray(a)) {
12
- if (!Array.isArray(b)) {
13
- return false;
14
- }
15
- for (let i = 0, imax = a.length; i < imax; i++) {
16
- if (!deepEqual(a[i], b[i])) {
17
- return false;
18
- }
19
- }
20
- return true;
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ function deepEqual(a, b) {
3
+ if (a === b) {
4
+ return true;
5
+ }
6
+ if (!(a && b) || typeof a !== "object" || typeof b !== "object") {
7
+ return false;
8
+ }
9
+ if (a.length !== b.length) {
10
+ return false;
11
+ }
12
+ if (Array.isArray(a)) {
13
+ if (!Array.isArray(b)) {
14
+ return false;
21
15
  }
22
- const aKeys = Object.keys(a);
23
- if (aKeys.length !== Object.keys(b).length) {
16
+ for (let i = 0, imax = a.length; i < imax; i++) {
17
+ if (!deepEqual(a[i], b[i])) {
24
18
  return false;
25
- }
26
- for (let j = 0, jmax = aKeys.length; j < jmax; j++) {
27
- const key = aKeys[j];
28
- if (!deepEqual(a[key], b[key])) {
29
- return false;
30
- }
19
+ }
31
20
  }
32
21
  return true;
22
+ }
23
+ const aKeys = Object.keys(a);
24
+ if (aKeys.length !== Object.keys(b).length) {
25
+ return false;
26
+ }
27
+ for (let j = 0, jmax = aKeys.length; j < jmax; j++) {
28
+ const key = aKeys[j];
29
+ if (!deepEqual(a[key], b[key])) {
30
+ return false;
31
+ }
32
+ }
33
+ return true;
33
34
  }
35
+ export {
36
+ deepEqual
37
+ };
@@ -1,2 +1,5 @@
1
- import type { ApplyJSONPatchOptions, JSONPatchOp, State } from '../types.js';
2
- export declare function exit(state: State, object: any, patch: JSONPatchOp, opts: ApplyJSONPatchOptions): any;
1
+ import { State, JSONPatchOp, ApplyJSONPatchOptions } from '../types.js';
2
+
3
+ declare function exit(state: State, object: any, patch: JSONPatchOp, opts: ApplyJSONPatchOptions): any;
4
+
5
+ export { exit };
@@ -1,4 +1,8 @@
1
- export function exit(state, object, patch, opts) {
2
- opts.error = patch;
3
- return opts.partial && state.root ? state.root[''] : object;
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ function exit(state, object, patch, opts) {
3
+ opts.error = patch;
4
+ return opts.partial && state.root ? state.root[""] : object;
4
5
  }
6
+ export {
7
+ exit
8
+ };
@@ -1,2 +1,5 @@
1
- import type { State } from '../types.js';
2
- export declare function get(state: State, path: string): any;
1
+ import { State } from '../types.js';
2
+
3
+ declare function get(state: State, path: string): any;
4
+
5
+ export { get };
@@ -1,5 +1,9 @@
1
- import { getOpData } from './getOpData.js';
2
- export function get(state, path) {
3
- const [, lastKey, target] = getOpData(state, path);
4
- return target ? target[lastKey] : undefined;
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ import { getOpData } from "./getOpData.js";
3
+ function get(state, path) {
4
+ const [, lastKey, target] = getOpData(state, path);
5
+ return target ? target[lastKey] : void 0;
5
6
  }
7
+ export {
8
+ get
9
+ };
@@ -1,2 +1,5 @@
1
- import type { State } from '../types.js';
2
- export declare function getOpData(state: State, path: string, createMissingObjects?: boolean): any[];
1
+ import { State } from '../types.js';
2
+
3
+ declare function getOpData(state: State, path: string, createMissingObjects?: boolean): any[];
4
+
5
+ export { getOpData };
@@ -1,10 +1,13 @@
1
- import { EMPTY, pluck } from './pluck.js';
2
- import { toKeys } from './toKeys.js';
3
- export function getOpData(state, path, createMissingObjects) {
4
- const keys = toKeys(path);
5
- const lastKey = keys[keys.length - 1];
6
- let target = pluck(state, keys);
7
- if (createMissingObjects)
8
- target = target || EMPTY;
9
- return [keys, lastKey, target];
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ import { EMPTY, pluck } from "./pluck.js";
3
+ import { toKeys } from "./toKeys.js";
4
+ function getOpData(state, path, createMissingObjects) {
5
+ const keys = toKeys(path);
6
+ const lastKey = keys[keys.length - 1];
7
+ let target = pluck(state, keys);
8
+ if (createMissingObjects) target = target || EMPTY;
9
+ return [keys, lastKey, target];
10
10
  }
11
+ export {
12
+ getOpData
13
+ };
@@ -1,3 +1,6 @@
1
- import type { JSONPatchOp, State } from '../types.js';
2
- export declare function getType(state: State, patch: JSONPatchOp): import("../types.js").JSONPatchOpHandler;
3
- export declare function getTypeLike(state: State, patch: JSONPatchOp): "add" | "remove" | "replace" | "move" | "copy" | "test";
1
+ import { State, JSONPatchOp, JSONPatchOpHandler } from '../types.js';
2
+
3
+ declare function getType(state: State, patch: JSONPatchOp): JSONPatchOpHandler;
4
+ declare function getTypeLike(state: State, patch: JSONPatchOp): "add" | "remove" | "replace" | "move" | "copy" | "test";
5
+
6
+ export { getType, getTypeLike };
@@ -1,6 +1,11 @@
1
- export function getType(state, patch) {
2
- return state.types?.[patch.op];
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ function getType(state, patch) {
3
+ return state.types?.[patch.op];
3
4
  }
4
- export function getTypeLike(state, patch) {
5
- return state.types?.[patch.op]?.like;
5
+ function getTypeLike(state, patch) {
6
+ return state.types?.[patch.op]?.like;
6
7
  }
8
+ export {
9
+ getType,
10
+ getTypeLike
11
+ };
@@ -1,14 +1,15 @@
1
- export * from './deepEqual.js';
2
- export * from './get.js';
3
- export * from './getOpData.js';
4
- export * from './getType.js';
5
- export * from './log.js';
6
- export * from './ops.js';
7
- export * from './paths.js';
8
- export * from './pluck.js';
9
- export * from './shallowCopy.js';
10
- export * from './softWrites.js';
11
- export * from './toArrayIndex.js';
12
- export * from './toKeys.js';
13
- export * from './updateArrayIndexes.js';
14
- export * from './updateArrayPath.js';
1
+ export { deepEqual } from './deepEqual.js';
2
+ export { get } from './get.js';
3
+ export { getOpData } from './getOpData.js';
4
+ export { getType, getTypeLike } from './getType.js';
5
+ export { log, verbose } from './log.js';
6
+ export { isAdd, mapAndFilterOps, transformRemove, updateRemovedOps } from './ops.js';
7
+ export { getArrayIndex, getArrayPrefixAndIndex, getIndexAndEnd, getPrefix, getPrefixAndProp, getProp, getPropAfter, isArrayPath } from './paths.js';
8
+ export { EMPTY, getValue, pluck, pluckWithShallowCopy } from './pluck.js';
9
+ export { shallowCopy } from './shallowCopy.js';
10
+ export { isEmptyObject, updateSoftWrites } from './softWrites.js';
11
+ export { toArrayIndex } from './toArrayIndex.js';
12
+ export { toKeys } from './toKeys.js';
13
+ export { updateArrayIndexes } from './updateArrayIndexes.js';
14
+ export { updateArrayPath } from './updateArrayPath.js';
15
+ import '../types.js';
@@ -1,14 +1,14 @@
1
- export * from './deepEqual.js';
2
- export * from './get.js';
3
- export * from './getOpData.js';
4
- export * from './getType.js';
5
- export * from './log.js';
6
- export * from './ops.js';
7
- export * from './paths.js';
8
- export * from './pluck.js';
9
- export * from './shallowCopy.js';
10
- export * from './softWrites.js';
11
- export * from './toArrayIndex.js';
12
- export * from './toKeys.js';
13
- export * from './updateArrayIndexes.js';
14
- export * from './updateArrayPath.js';
1
+ export * from "./deepEqual.js";
2
+ export * from "./get.js";
3
+ export * from "./getOpData.js";
4
+ export * from "./getType.js";
5
+ export * from "./log.js";
6
+ export * from "./ops.js";
7
+ export * from "./paths.js";
8
+ export * from "./pluck.js";
9
+ export * from "./shallowCopy.js";
10
+ export * from "./softWrites.js";
11
+ export * from "./toArrayIndex.js";
12
+ export * from "./toKeys.js";
13
+ export * from "./updateArrayIndexes.js";
14
+ export * from "./updateArrayPath.js";
@@ -1,5 +1,7 @@
1
- export declare let log: {
1
+ declare let log: {
2
2
  (...data: any[]): void;
3
3
  (message?: any, ...optionalParams: any[]): void;
4
4
  };
5
- export declare function verbose(value: boolean): void;
5
+ declare function verbose(value: boolean): void;
6
+
7
+ export { log, verbose };
@@ -1,4 +1,9 @@
1
- export let log = console.log;
2
- export function verbose(value) {
3
- log = value ? console.log : () => undefined;
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ let log = console.log;
3
+ function verbose(value) {
4
+ log = value ? console.log : () => void 0;
4
5
  }
6
+ export {
7
+ log,
8
+ verbose
9
+ };