@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,9 +1,20 @@
1
- export { applyPatch } from './applyPatch.js';
2
- export { composePatch } from './composePatch.js';
3
- export { invertPatch } from './invertPatch.js';
4
- export { applyBitmask, bitmask, combineBitmasks } from './ops/bitmask.js';
5
- export * as defaultOps from './ops/index.js';
6
- export * from './pathProxy.js';
7
- export { transformPatch } from './transformPatch.js';
8
- export * from './JSONPatch.js';
9
- export * from './ops/index.js';
1
+ import "../chunk-IZ2YBCUP.js";
2
+ import { applyPatch } from "./applyPatch.js";
3
+ import { composePatch } from "./composePatch.js";
4
+ import { invertPatch } from "./invertPatch.js";
5
+ import { applyBitmask, bitmask, combineBitmasks } from "./ops/bitmask.js";
6
+ import * as defaultOps from "./ops/index.js";
7
+ export * from "./pathProxy.js";
8
+ import { transformPatch } from "./transformPatch.js";
9
+ export * from "./JSONPatch.js";
10
+ export * from "./ops/index.js";
11
+ export {
12
+ applyBitmask,
13
+ applyPatch,
14
+ bitmask,
15
+ combineBitmasks,
16
+ composePatch,
17
+ defaultOps,
18
+ invertPatch,
19
+ transformPatch
20
+ };
@@ -1,2 +1,5 @@
1
- import type { JSONPatchOp, JSONPatchOpHandlerMap } from './types.js';
2
- export declare function invertPatch(object: any, ops: JSONPatchOp[], custom?: JSONPatchOpHandlerMap): JSONPatchOp[];
1
+ import { JSONPatchOp, JSONPatchOpHandlerMap } from './types.js';
2
+
3
+ declare function invertPatch(object: any, ops: JSONPatchOp[], custom?: JSONPatchOpHandlerMap): JSONPatchOp[];
4
+
5
+ export { invertPatch };
@@ -1,31 +1,32 @@
1
- import { getTypes } from './ops/index.js';
2
- import { runWithObject } from './state.js';
3
- import { getType } from './utils/getType.js';
4
- export function invertPatch(object, ops, custom = {}) {
5
- const types = getTypes(custom);
6
- return runWithObject({}, types, false, state => {
7
- return ops
8
- .map((op) => {
9
- const pathParts = op.path.split('/').slice(1);
10
- let changedObj = object;
11
- const prop = pathParts.pop();
12
- let value, isIndex;
13
- try {
14
- for (let i = 0; i < pathParts.length; i++) {
15
- changedObj = changedObj[pathParts[i]];
16
- }
17
- value = changedObj[prop];
18
- isIndex = prop >= 0;
19
- }
20
- catch (err) {
21
- throw new Error(`Patch mismatch. This patch was not applied to the provided object and cannot be inverted. ${err.message || err}`);
22
- }
23
- const handler = getType(state, op)?.invert;
24
- if (!handler)
25
- throw new Error('Unknown patch operation, cannot invert');
26
- return handler(state, op, value, changedObj, isIndex);
27
- })
28
- .filter(op => !!op)
29
- .reverse();
30
- });
1
+ import "../chunk-IZ2YBCUP.js";
2
+ import { getTypes } from "./ops/index.js";
3
+ import { runWithObject } from "./state.js";
4
+ import { getType } from "./utils/getType.js";
5
+ function invertPatch(object, ops, custom = {}) {
6
+ const types = getTypes(custom);
7
+ return runWithObject({}, types, false, (state) => {
8
+ return ops.map((op) => {
9
+ const pathParts = op.path.split("/").slice(1);
10
+ let changedObj = object;
11
+ const prop = pathParts.pop();
12
+ let value, isIndex;
13
+ try {
14
+ for (let i = 0; i < pathParts.length; i++) {
15
+ changedObj = changedObj[pathParts[i]];
16
+ }
17
+ value = changedObj[prop];
18
+ isIndex = prop >= 0;
19
+ } catch (err) {
20
+ throw new Error(
21
+ `Patch mismatch. This patch was not applied to the provided object and cannot be inverted. ${err.message || err}`
22
+ );
23
+ }
24
+ const handler = getType(state, op)?.invert;
25
+ if (!handler) throw new Error("Unknown patch operation, cannot invert");
26
+ return handler(state, op, value, changedObj, isIndex);
27
+ }).filter((op) => !!op).reverse();
28
+ });
31
29
  }
30
+ export {
31
+ invertPatch
32
+ };
@@ -1,2 +1,5 @@
1
- import type { JSONPatchOpHandler } from '../types.js';
2
- export declare const add: JSONPatchOpHandler;
1
+ import { JSONPatchOpHandler } from '../types.js';
2
+
3
+ declare const add: JSONPatchOpHandler;
4
+
5
+ export { add };
@@ -1,52 +1,54 @@
1
- import { deepEqual } from '../utils/deepEqual.js';
2
- import { getOpData } from '../utils/getOpData.js';
3
- import { isArrayPath, isEmptyObject, log, updateArrayIndexes, updateRemovedOps, updateSoftWrites, } from '../utils/index.js';
4
- import { pluckWithShallowCopy } from '../utils/pluck.js';
5
- import { toArrayIndex } from '../utils/toArrayIndex.js';
6
- export const add = {
7
- like: 'add',
8
- apply(state, path, value) {
9
- if (typeof value === 'undefined') {
10
- return '[op:add] require value, but got undefined';
11
- }
12
- const [keys, lastKey, target] = getOpData(state, path, true);
13
- if (target === null) {
14
- return `[op:add] path not found: ${path}`;
15
- }
16
- if (Array.isArray(target)) {
17
- const index = toArrayIndex(target, lastKey);
18
- if (index < 0 || target.length < index) {
19
- return `[op:add] invalid array index: ${path}`;
20
- }
21
- pluckWithShallowCopy(state, keys, true).splice(index, 0, value);
22
- }
23
- else {
24
- if (!deepEqual(target[lastKey], value)) {
25
- pluckWithShallowCopy(state, keys, true)[lastKey] = value;
26
- }
27
- }
28
- },
29
- invert(_state, { path }, value, changedObj, isIndex) {
30
- if (path.endsWith('/-'))
31
- return { op: 'remove', path: path.replace('-', changedObj.length) };
32
- else if (isIndex)
33
- return { op: 'remove', path };
34
- return value === undefined ? { op: 'remove', path } : { op: 'replace', path, value };
35
- },
36
- transform(state, thisOp, otherOps) {
37
- log('Transforming', otherOps, 'against "add"', thisOp);
38
- if (isArrayPath(thisOp.path, state)) {
39
- // Adjust any operations on the same array by 1 to account for this new entry
40
- return updateArrayIndexes(state, thisOp.path, otherOps, 1);
41
- }
42
- else if (isEmptyObject(thisOp.value)) {
43
- // Treat empty objects special. If two empty objects are added to the same location, don't overwrite the existing
44
- // one, allowing for the merging of maps together which did not exist before
45
- return updateSoftWrites(thisOp.path, otherOps);
46
- }
47
- else {
48
- // Remove anything that was done at this path since it is being overwritten by the add
49
- return updateRemovedOps(state, thisOp.path, otherOps);
50
- }
51
- },
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ import { deepEqual } from "../utils/deepEqual.js";
3
+ import { getOpData } from "../utils/getOpData.js";
4
+ import {
5
+ isArrayPath,
6
+ isEmptyObject,
7
+ log,
8
+ updateArrayIndexes,
9
+ updateRemovedOps,
10
+ updateSoftWrites
11
+ } from "../utils/index.js";
12
+ import { pluckWithShallowCopy } from "../utils/pluck.js";
13
+ import { toArrayIndex } from "../utils/toArrayIndex.js";
14
+ const add = {
15
+ like: "add",
16
+ apply(state, path, value) {
17
+ if (typeof value === "undefined") {
18
+ return "[op:add] require value, but got undefined";
19
+ }
20
+ const [keys, lastKey, target] = getOpData(state, path, true);
21
+ if (target === null) {
22
+ return `[op:add] path not found: ${path}`;
23
+ }
24
+ if (Array.isArray(target)) {
25
+ const index = toArrayIndex(target, lastKey);
26
+ if (index < 0 || target.length < index) {
27
+ return `[op:add] invalid array index: ${path}`;
28
+ }
29
+ pluckWithShallowCopy(state, keys, true).splice(index, 0, value);
30
+ } else {
31
+ if (!deepEqual(target[lastKey], value)) {
32
+ pluckWithShallowCopy(state, keys, true)[lastKey] = value;
33
+ }
34
+ }
35
+ },
36
+ invert(_state, { path }, value, changedObj, isIndex) {
37
+ if (path.endsWith("/-")) return { op: "remove", path: path.replace("-", changedObj.length) };
38
+ else if (isIndex) return { op: "remove", path };
39
+ return value === void 0 ? { op: "remove", path } : { op: "replace", path, value };
40
+ },
41
+ transform(state, thisOp, otherOps) {
42
+ log("Transforming", otherOps, 'against "add"', thisOp);
43
+ if (isArrayPath(thisOp.path, state)) {
44
+ return updateArrayIndexes(state, thisOp.path, otherOps, 1);
45
+ } else if (isEmptyObject(thisOp.value)) {
46
+ return updateSoftWrites(thisOp.path, otherOps);
47
+ } else {
48
+ return updateRemovedOps(state, thisOp.path, otherOps);
49
+ }
50
+ }
51
+ };
52
+ export {
53
+ add
52
54
  };
@@ -1,14 +1,17 @@
1
- import type { JSONPatchOpHandler } from '../types.js';
1
+ import { JSONPatchOpHandler } from '../types.js';
2
+
2
3
  /**
3
4
  * Create and maintain up to 15 boolean values in a single positive number (a bitmask). This can reduce the size of your
4
5
  * JSON document. Limiting the bits to 15 allows us to keep the number smaller (max of 9 characters), positive, and
5
6
  * allows us to combine multiple operations into a single number.
6
7
  */
7
- export declare const bit: JSONPatchOpHandler;
8
+ declare const bit: JSONPatchOpHandler;
8
9
  /**
9
10
  * A helper function to create a mask number for bitmask operations. The bottom 15 bits are used to turn bits on, and
10
11
  * the top 15 bits are used to turn bits off.
11
12
  */
12
- export declare function bitmask(index: number, value: boolean): number;
13
- export declare function applyBitmask(num: number, mask: number): number;
14
- export declare function combineBitmasks(a: number, b: number): number;
13
+ declare function bitmask(index: number, value: boolean): number;
14
+ declare function applyBitmask(num: number, mask: number): number;
15
+ declare function combineBitmasks(a: number, b: number): number;
16
+
17
+ export { applyBitmask, bit, bitmask, combineBitmasks };
@@ -1,48 +1,45 @@
1
- import { get } from '../utils/get.js';
2
- import { updateRemovedOps } from '../utils/ops.js';
3
- import { replace } from './replace.js';
4
- /**
5
- * Create and maintain up to 15 boolean values in a single positive number (a bitmask). This can reduce the size of your
6
- * JSON document. Limiting the bits to 15 allows us to keep the number smaller (max of 9 characters), positive, and
7
- * allows us to combine multiple operations into a single number.
8
- */
9
- export const bit = {
10
- like: 'replace',
11
- apply(state, path, value) {
12
- return replace.apply(state, path, applyBitmask(get(state, path) || 0, value || 0));
13
- },
14
- transform(state, thisOp, otherOps) {
15
- return updateRemovedOps(state, thisOp.path, otherOps, false, true);
16
- },
17
- invert(state, op, value, changedObj, isIndex) {
18
- return replace.invert(state, op, value, changedObj, isIndex);
19
- },
20
- compose(_state, value1, value2) {
21
- return combineBitmasks(value1, value2);
22
- },
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ import { get } from "../utils/get.js";
3
+ import { updateRemovedOps } from "../utils/ops.js";
4
+ import { replace } from "./replace.js";
5
+ const bit = {
6
+ like: "replace",
7
+ apply(state, path, value) {
8
+ return replace.apply(state, path, applyBitmask(get(state, path) || 0, value || 0));
9
+ },
10
+ transform(state, thisOp, otherOps) {
11
+ return updateRemovedOps(state, thisOp.path, otherOps, false, true);
12
+ },
13
+ invert(state, op, value, changedObj, isIndex) {
14
+ return replace.invert(state, op, value, changedObj, isIndex);
15
+ },
16
+ compose(_state, value1, value2) {
17
+ return combineBitmasks(value1, value2);
18
+ }
23
19
  };
24
- /**
25
- * A helper function to create a mask number for bitmask operations. The bottom 15 bits are used to turn bits on, and
26
- * the top 15 bits are used to turn bits off.
27
- */
28
- export function bitmask(index, value) {
29
- if (index < 0 || index > 14)
30
- throw new Error('Index must be between 0 and 14');
31
- return value ? 1 << index : 1 << (index + 15);
20
+ function bitmask(index, value) {
21
+ if (index < 0 || index > 14) throw new Error("Index must be between 0 and 14");
22
+ return value ? 1 << index : 1 << index + 15;
32
23
  }
33
- export function applyBitmask(num, mask) {
34
- const offMask = (mask >> 15) & 0x7fff;
35
- const onMask = mask & 0x7fff;
36
- num &= ~offMask;
37
- num |= onMask;
38
- return num;
24
+ function applyBitmask(num, mask) {
25
+ const offMask = mask >> 15 & 32767;
26
+ const onMask = mask & 32767;
27
+ num &= ~offMask;
28
+ num |= onMask;
29
+ return num;
39
30
  }
40
- export function combineBitmasks(a, b) {
41
- const aOff = (a >> 15) & 0x7fff;
42
- const aOn = a & 0x7fff;
43
- const bOff = (b >> 15) & 0x7fff;
44
- const bOn = b & 0x7fff;
45
- const combinedOn = (aOn & ~bOff) | bOn;
46
- const combinedOff = (aOff & ~bOn) | bOff;
47
- return (combinedOff << 15) | combinedOn;
31
+ function combineBitmasks(a, b) {
32
+ const aOff = a >> 15 & 32767;
33
+ const aOn = a & 32767;
34
+ const bOff = b >> 15 & 32767;
35
+ const bOn = b & 32767;
36
+ const combinedOn = aOn & ~bOff | bOn;
37
+ const combinedOff = aOff & ~bOn | bOff;
38
+ return combinedOff << 15 | combinedOn;
48
39
  }
40
+ export {
41
+ applyBitmask,
42
+ bit,
43
+ bitmask,
44
+ combineBitmasks
45
+ };
@@ -1,2 +1,5 @@
1
- import type { JSONPatchOpHandler } from '../types.js';
2
- export declare const copy: JSONPatchOpHandler;
1
+ import { JSONPatchOpHandler } from '../types.js';
2
+
3
+ declare const copy: JSONPatchOpHandler;
4
+
5
+ export { copy };
@@ -1,34 +1,33 @@
1
- import { getOpData } from '../utils/getOpData.js';
2
- import { log } from '../utils/log.js';
3
- import { updateRemovedOps } from '../utils/ops.js';
4
- import { isArrayPath } from '../utils/paths.js';
5
- import { updateArrayIndexes } from '../utils/updateArrayIndexes.js';
6
- import { add } from './add.js';
7
- export const copy = {
8
- like: 'copy',
9
- apply(state, path, from) {
10
- const [, lastKey, target] = getOpData(state, from);
11
- if (target === null) {
12
- return `[op:copy] path not found: ${from}`;
13
- }
14
- return add.apply(state, path, target[lastKey]);
15
- },
16
- invert(_state, { path }, value, changedObj, isIndex) {
17
- if (path.endsWith('/-'))
18
- return { op: 'remove', path: path.replace('-', changedObj.length) };
19
- else if (isIndex)
20
- return { op: 'remove', path };
21
- return value === undefined ? { op: 'remove', path } : { op: 'replace', path, value };
22
- },
23
- transform(state, thisOp, otherOps) {
24
- log('Transforming', otherOps, 'against "add"', thisOp);
25
- if (isArrayPath(thisOp.path, state)) {
26
- // Adjust any operations on the same array by 1 to account for this new entry
27
- return updateArrayIndexes(state, thisOp.path, otherOps, 1);
28
- }
29
- else {
30
- // Remove anything that was done at this path since it is being overwritten
31
- return updateRemovedOps(state, thisOp.path, otherOps);
32
- }
33
- },
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ import { getOpData } from "../utils/getOpData.js";
3
+ import { log } from "../utils/log.js";
4
+ import { updateRemovedOps } from "../utils/ops.js";
5
+ import { isArrayPath } from "../utils/paths.js";
6
+ import { updateArrayIndexes } from "../utils/updateArrayIndexes.js";
7
+ import { add } from "./add.js";
8
+ const copy = {
9
+ like: "copy",
10
+ apply(state, path, from) {
11
+ const [, lastKey, target] = getOpData(state, from);
12
+ if (target === null) {
13
+ return `[op:copy] path not found: ${from}`;
14
+ }
15
+ return add.apply(state, path, target[lastKey]);
16
+ },
17
+ invert(_state, { path }, value, changedObj, isIndex) {
18
+ if (path.endsWith("/-")) return { op: "remove", path: path.replace("-", changedObj.length) };
19
+ else if (isIndex) return { op: "remove", path };
20
+ return value === void 0 ? { op: "remove", path } : { op: "replace", path, value };
21
+ },
22
+ transform(state, thisOp, otherOps) {
23
+ log("Transforming", otherOps, 'against "add"', thisOp);
24
+ if (isArrayPath(thisOp.path, state)) {
25
+ return updateArrayIndexes(state, thisOp.path, otherOps, 1);
26
+ } else {
27
+ return updateRemovedOps(state, thisOp.path, otherOps);
28
+ }
29
+ }
30
+ };
31
+ export {
32
+ copy
34
33
  };
@@ -1,5 +1,8 @@
1
- import type { JSONPatchOpHandler } from '../types.js';
1
+ import { JSONPatchOpHandler } from '../types.js';
2
+
2
3
  /**
3
4
  * Increment or decrement a number (using `+` or `-`).
4
5
  */
5
- export declare const increment: JSONPatchOpHandler;
6
+ declare const increment: JSONPatchOpHandler;
7
+
8
+ export { increment };
@@ -1,21 +1,22 @@
1
- import { get } from '../utils/get.js';
2
- import { updateRemovedOps } from '../utils/ops.js';
3
- import { replace } from './replace.js';
4
- /**
5
- * Increment or decrement a number (using `+` or `-`).
6
- */
7
- export const increment = {
8
- like: 'replace',
9
- apply(state, path, value) {
10
- return replace.apply(state, path, (get(state, path) || 0) + value);
11
- },
12
- transform(state, thisOp, otherOps) {
13
- return updateRemovedOps(state, thisOp.path, otherOps, false, true);
14
- },
15
- invert(state, op, value, changedObj, isIndex) {
16
- return replace.invert(state, op, value, changedObj, isIndex);
17
- },
18
- compose(_state, value1, value2) {
19
- return value1 + value2;
20
- },
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ import { get } from "../utils/get.js";
3
+ import { updateRemovedOps } from "../utils/ops.js";
4
+ import { replace } from "./replace.js";
5
+ const increment = {
6
+ like: "replace",
7
+ apply(state, path, value) {
8
+ return replace.apply(state, path, (get(state, path) || 0) + value);
9
+ },
10
+ transform(state, thisOp, otherOps) {
11
+ return updateRemovedOps(state, thisOp.path, otherOps, false, true);
12
+ },
13
+ invert(state, op, value, changedObj, isIndex) {
14
+ return replace.invert(state, op, value, changedObj, isIndex);
15
+ },
16
+ compose(_state, value1, value2) {
17
+ return value1 + value2;
18
+ }
19
+ };
20
+ export {
21
+ increment
21
22
  };
@@ -1,21 +1,10 @@
1
- import type { JSONPatchOpHandlerMap } from '../types.js';
2
- import { add } from './add.js';
3
- import { bit } from './bitmask.js';
4
- import { copy } from './copy.js';
5
- import { increment } from './increment.js';
6
- import { move } from './move.js';
7
- import { remove } from './remove.js';
8
- import { replace } from './replace.js';
9
- import { test } from './test.js';
10
- export { add, bit, copy, increment, move, remove, replace, test };
11
- export declare function getTypes(custom?: JSONPatchOpHandlerMap): {
12
- test: import("../types.js").JSONPatchOpHandler;
13
- add: import("../types.js").JSONPatchOpHandler;
14
- remove: import("../types.js").JSONPatchOpHandler;
15
- replace: import("../types.js").JSONPatchOpHandler;
16
- copy: import("../types.js").JSONPatchOpHandler;
17
- move: import("../types.js").JSONPatchOpHandler;
18
- '@inc': import("../types.js").JSONPatchOpHandler;
19
- '@bit': import("../types.js").JSONPatchOpHandler;
20
- '@txt': import("../types.js").JSONPatchOpHandler;
21
- };
1
+ import '../types.js';
2
+ export { add } from './add.js';
3
+ export { bit } from './bitmask.js';
4
+ export { copy } from './copy.js';
5
+ export { increment } from './increment.js';
6
+ export { move } from './move.js';
7
+ export { remove } from './remove.js';
8
+ export { replace } from './replace.js';
9
+ export { test } from './test.js';
10
+ export { g as getTypes } from '../../index-CvQws3AB.js';
@@ -1,25 +1,35 @@
1
- import { add } from './add.js';
2
- import { bit } from './bitmask.js';
3
- import { copy } from './copy.js';
4
- import { increment } from './increment.js';
5
- import { move } from './move.js';
6
- import { remove } from './remove.js';
7
- import { replace } from './replace.js';
8
- import { test } from './test.js';
9
- import { text } from './text.js';
10
- // Export all patch operations
11
- export { add, bit, copy, increment, move, remove, replace, test };
12
- export function getTypes(custom) {
13
- return {
14
- test,
15
- add,
16
- remove,
17
- replace,
18
- copy,
19
- move,
20
- '@inc': increment,
21
- '@bit': bit,
22
- '@txt': text,
23
- ...custom,
24
- };
1
+ import "../../chunk-IZ2YBCUP.js";
2
+ import { add } from "./add.js";
3
+ import { bit } from "./bitmask.js";
4
+ import { copy } from "./copy.js";
5
+ import { increment } from "./increment.js";
6
+ import { move } from "./move.js";
7
+ import { remove } from "./remove.js";
8
+ import { replace } from "./replace.js";
9
+ import { test } from "./test.js";
10
+ import { text } from "./text.js";
11
+ function getTypes(custom) {
12
+ return {
13
+ test,
14
+ add,
15
+ remove,
16
+ replace,
17
+ copy,
18
+ move,
19
+ "@inc": increment,
20
+ "@bit": bit,
21
+ "@txt": text,
22
+ ...custom
23
+ };
25
24
  }
25
+ export {
26
+ add,
27
+ bit,
28
+ copy,
29
+ getTypes,
30
+ increment,
31
+ move,
32
+ remove,
33
+ replace,
34
+ test
35
+ };
@@ -1,2 +1,5 @@
1
- import type { JSONPatchOpHandler } from '../types.js';
2
- export declare const move: JSONPatchOpHandler;
1
+ import { JSONPatchOpHandler } from '../types.js';
2
+
3
+ declare const move: JSONPatchOpHandler;
4
+
5
+ export { move };