@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.
- package/dist/algorithms/client/applyCommittedChanges.d.ts +8 -2
- package/dist/algorithms/client/applyCommittedChanges.js +30 -38
- package/dist/algorithms/client/batching.d.ts +8 -2
- package/dist/algorithms/client/batching.js +38 -37
- package/dist/algorithms/client/breakChange.d.ts +8 -2
- package/dist/algorithms/client/breakChange.js +191 -240
- package/dist/algorithms/client/createStateFromSnapshot.d.ts +8 -2
- package/dist/algorithms/client/createStateFromSnapshot.js +7 -8
- package/dist/algorithms/client/getJSONByteSize.d.ts +3 -1
- package/dist/algorithms/client/getJSONByteSize.js +12 -11
- package/dist/algorithms/client/makeChange.d.ts +8 -2
- package/dist/algorithms/client/makeChange.js +28 -36
- package/dist/algorithms/server/commitChanges.d.ts +9 -3
- package/dist/algorithms/server/commitChanges.js +69 -78
- package/dist/algorithms/server/createVersion.d.ts +9 -3
- package/dist/algorithms/server/createVersion.js +21 -27
- package/dist/algorithms/server/getSnapshotAtRevision.d.ts +9 -3
- package/dist/algorithms/server/getSnapshotAtRevision.js +27 -28
- package/dist/algorithms/server/getStateAtRevision.d.ts +9 -3
- package/dist/algorithms/server/getStateAtRevision.js +13 -17
- package/dist/algorithms/server/handleOfflineSessionsAndBatches.d.ts +9 -3
- package/dist/algorithms/server/handleOfflineSessionsAndBatches.js +60 -77
- package/dist/algorithms/server/transformIncomingChanges.d.ts +8 -2
- package/dist/algorithms/server/transformIncomingChanges.js +27 -39
- package/dist/algorithms/shared/applyChanges.d.ts +8 -2
- package/dist/algorithms/shared/applyChanges.js +11 -16
- package/dist/algorithms/shared/rebaseChanges.d.ts +8 -2
- package/dist/algorithms/shared/rebaseChanges.js +30 -49
- package/dist/chunk-IZ2YBCUP.js +56 -0
- package/dist/client/InMemoryStore.d.ts +9 -3
- package/dist/client/InMemoryStore.js +92 -101
- package/dist/client/IndexedDBStore.d.ts +9 -3
- package/dist/client/IndexedDBStore.js +378 -491
- package/dist/client/Patches.d.ts +18 -13
- package/dist/client/Patches.js +152 -207
- package/dist/client/PatchesDoc.d.ts +14 -8
- package/dist/client/PatchesDoc.js +147 -154
- package/dist/client/PatchesHistoryClient.d.ts +12 -5
- package/dist/client/PatchesHistoryClient.js +110 -117
- package/dist/client/PatchesStore.d.ts +9 -3
- package/dist/client/PatchesStore.js +0 -1
- package/dist/client/index.d.ts +12 -6
- package/dist/client/index.js +5 -5
- package/dist/data/change.d.ts +9 -3
- package/dist/data/change.js +23 -15
- package/dist/data/version.d.ts +9 -3
- package/dist/data/version.js +11 -15
- package/dist/event-signal.d.ts +7 -6
- package/dist/event-signal.js +24 -39
- package/dist/index-CvQws3AB.d.ts +36 -0
- package/dist/index.d.ts +27 -5
- package/dist/index.js +10 -4
- package/dist/json-patch/JSONPatch.d.ts +9 -5
- package/dist/json-patch/JSONPatch.js +175 -183
- package/dist/json-patch/applyPatch.d.ts +5 -2
- package/dist/json-patch/applyPatch.js +27 -35
- package/dist/json-patch/composePatch.d.ts +5 -2
- package/dist/json-patch/composePatch.js +34 -34
- package/dist/json-patch/createJSONPatch.d.ts +7 -2
- package/dist/json-patch/createJSONPatch.js +11 -38
- package/dist/json-patch/index.d.ts +14 -6
- package/dist/json-patch/index.js +20 -9
- package/dist/json-patch/invertPatch.d.ts +5 -2
- package/dist/json-patch/invertPatch.js +31 -30
- package/dist/json-patch/ops/add.d.ts +5 -2
- package/dist/json-patch/ops/add.js +53 -51
- package/dist/json-patch/ops/bitmask.d.ts +8 -5
- package/dist/json-patch/ops/bitmask.js +41 -44
- package/dist/json-patch/ops/copy.d.ts +5 -2
- package/dist/json-patch/ops/copy.js +32 -33
- package/dist/json-patch/ops/increment.d.ts +5 -2
- package/dist/json-patch/ops/increment.js +21 -20
- package/dist/json-patch/ops/index.d.ts +10 -21
- package/dist/json-patch/ops/index.js +34 -24
- package/dist/json-patch/ops/move.d.ts +5 -2
- package/dist/json-patch/ops/move.js +132 -198
- package/dist/json-patch/ops/remove.d.ts +5 -2
- package/dist/json-patch/ops/remove.js +33 -30
- package/dist/json-patch/ops/replace.d.ts +5 -2
- package/dist/json-patch/ops/replace.js +45 -43
- package/dist/json-patch/ops/test.d.ts +5 -2
- package/dist/json-patch/ops/test.js +25 -21
- package/dist/json-patch/ops/text.d.ts +5 -2
- package/dist/json-patch/ops/text.js +54 -54
- package/dist/json-patch/pathProxy.d.ts +9 -3
- package/dist/json-patch/pathProxy.js +27 -48
- package/dist/json-patch/state.d.ts +5 -2
- package/dist/json-patch/state.js +11 -7
- package/dist/json-patch/transformPatch.d.ts +6 -2
- package/dist/json-patch/transformPatch.js +21 -24
- package/dist/json-patch/types.d.ts +9 -7
- package/dist/json-patch/types.js +0 -1
- package/dist/json-patch/utils/deepEqual.d.ts +3 -1
- package/dist/json-patch/utils/deepEqual.js +32 -28
- package/dist/json-patch/utils/exit.d.ts +5 -2
- package/dist/json-patch/utils/exit.js +7 -3
- package/dist/json-patch/utils/get.d.ts +5 -2
- package/dist/json-patch/utils/get.js +8 -4
- package/dist/json-patch/utils/getOpData.d.ts +5 -2
- package/dist/json-patch/utils/getOpData.js +12 -9
- package/dist/json-patch/utils/getType.d.ts +6 -3
- package/dist/json-patch/utils/getType.js +9 -4
- package/dist/json-patch/utils/index.d.ts +15 -14
- package/dist/json-patch/utils/index.js +14 -14
- package/dist/json-patch/utils/log.d.ts +4 -2
- package/dist/json-patch/utils/log.js +8 -3
- package/dist/json-patch/utils/ops.d.ts +8 -5
- package/dist/json-patch/utils/ops.js +83 -100
- package/dist/json-patch/utils/paths.d.ts +12 -9
- package/dist/json-patch/utils/paths.js +54 -51
- package/dist/json-patch/utils/pluck.d.ts +8 -5
- package/dist/json-patch/utils/pluck.js +32 -26
- package/dist/json-patch/utils/shallowCopy.d.ts +3 -1
- package/dist/json-patch/utils/shallowCopy.js +22 -18
- package/dist/json-patch/utils/softWrites.d.ts +6 -3
- package/dist/json-patch/utils/softWrites.js +17 -16
- package/dist/json-patch/utils/toArrayIndex.d.ts +3 -1
- package/dist/json-patch/utils/toArrayIndex.js +14 -10
- package/dist/json-patch/utils/toKeys.d.ts +3 -1
- package/dist/json-patch/utils/toKeys.js +15 -11
- package/dist/json-patch/utils/updateArrayIndexes.d.ts +5 -2
- package/dist/json-patch/utils/updateArrayIndexes.js +33 -37
- package/dist/json-patch/utils/updateArrayPath.d.ts +5 -2
- package/dist/json-patch/utils/updateArrayPath.js +29 -42
- package/dist/net/PatchesClient.d.ts +128 -0
- package/dist/net/PatchesClient.js +161 -0
- package/dist/net/PatchesSync.d.ts +19 -9
- package/dist/net/PatchesSync.js +291 -386
- package/dist/net/error.d.ts +3 -1
- package/dist/net/error.js +9 -6
- package/dist/net/http/FetchTransport.d.ts +21 -0
- package/dist/net/http/FetchTransport.js +34 -0
- package/dist/net/index.d.ts +26 -12
- package/dist/net/index.js +12 -10
- package/dist/net/protocol/JSONRPCClient.d.ts +11 -4
- package/dist/net/protocol/JSONRPCClient.js +95 -103
- package/dist/net/protocol/JSONRPCServer.d.ts +15 -8
- package/dist/net/protocol/JSONRPCServer.js +101 -123
- package/dist/net/protocol/types.d.ts +21 -15
- package/dist/net/protocol/types.js +0 -1
- package/dist/net/protocol/utils.d.ts +12 -0
- package/dist/net/protocol/utils.js +15 -0
- package/dist/net/types.d.ts +4 -2
- package/dist/net/types.js +0 -1
- package/dist/net/webrtc/WebRTCAwareness.d.ts +14 -4
- package/dist/net/webrtc/WebRTCAwareness.js +111 -120
- package/dist/net/webrtc/WebRTCTransport.d.ts +16 -8
- package/dist/net/webrtc/WebRTCTransport.js +149 -157
- package/dist/net/webrtc/index.d.ts +10 -2
- package/dist/net/webrtc/index.js +2 -2
- package/dist/net/websocket/AuthorizationProvider.d.ts +7 -5
- package/dist/net/websocket/AuthorizationProvider.js +12 -17
- package/dist/net/websocket/PatchesWebSocket.d.ts +14 -109
- package/dist/net/websocket/PatchesWebSocket.js +37 -184
- package/dist/net/websocket/RPCServer.d.ts +19 -10
- package/dist/net/websocket/RPCServer.js +190 -192
- package/dist/net/websocket/SignalingService.d.ts +12 -32
- package/dist/net/websocket/SignalingService.js +126 -133
- package/dist/net/websocket/WebSocketServer.d.ts +17 -4
- package/dist/net/websocket/WebSocketServer.js +64 -72
- package/dist/net/websocket/WebSocketTransport.d.ts +13 -5
- package/dist/net/websocket/WebSocketTransport.js +178 -207
- package/dist/net/websocket/onlineState.d.ts +6 -3
- package/dist/net/websocket/onlineState.js +25 -21
- package/dist/server/PatchesBranchManager.d.ts +12 -5
- package/dist/server/PatchesBranchManager.js +132 -142
- package/dist/server/PatchesHistoryManager.d.ts +11 -3
- package/dist/server/PatchesHistoryManager.js +81 -84
- package/dist/server/PatchesServer.d.ts +16 -10
- package/dist/server/PatchesServer.js +131 -137
- package/dist/server/index.d.ts +7 -2
- package/dist/server/index.js +9 -3
- package/dist/server/types.d.ts +9 -3
- package/dist/server/types.js +0 -1
- package/dist/types.d.ts +49 -19
- package/dist/types.js +1 -1
- package/dist/utils/concurrency.d.ts +7 -5
- package/dist/utils/concurrency.js +43 -53
- package/dist/utils/deferred.d.ts +4 -2
- package/dist/utils/deferred.js +25 -21
- package/package.json +5 -7
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
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
|
-
|
|
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
|
|
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
|
-
|
|
22
|
-
|
|
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
|
-
|
|
1
|
+
import "../chunk-IZ2YBCUP.js";
|
|
2
2
|
const proxyFodder = {};
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
|
2
|
-
|
|
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 };
|
package/dist/json-patch/state.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
14
|
-
import { runWithObject } from
|
|
15
|
-
import { getType } from
|
|
16
|
-
import { log } from
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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
|
-
|
|
8
|
+
interface JSONPatchOpHandlerMap {
|
|
9
9
|
[key: string]: JSONPatchOpHandler;
|
|
10
10
|
}
|
|
11
|
-
|
|
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
|
-
|
|
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
|
-
|
|
44
|
+
interface Root {
|
|
45
45
|
'': any;
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
type State = {
|
|
48
48
|
root: Root;
|
|
49
49
|
types: JSONPatchOpHandlerMap;
|
|
50
50
|
cache: Set<any> | null;
|
|
51
51
|
};
|
|
52
|
-
|
|
52
|
+
type Runner = (state: State) => any;
|
|
53
|
+
|
|
54
|
+
export type { ApplyJSONPatchOptions, JSONPatchOp, JSONPatchOpHandler, JSONPatchOpHandlerMap, Root, Runner, State };
|
package/dist/json-patch/types.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,33 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
23
|
-
|
|
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
|
|
2
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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,5 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
2
|
-
|
|
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
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
2
|
-
|
|
3
|
-
|
|
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
|
-
|
|
2
|
-
|
|
1
|
+
import "../../chunk-IZ2YBCUP.js";
|
|
2
|
+
function getType(state, patch) {
|
|
3
|
+
return state.types?.[patch.op];
|
|
3
4
|
}
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
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
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
13
|
-
export * from
|
|
14
|
-
export * from
|
|
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
|
-
|
|
1
|
+
declare let log: {
|
|
2
2
|
(...data: any[]): void;
|
|
3
3
|
(message?: any, ...optionalParams: any[]): void;
|
|
4
4
|
};
|
|
5
|
-
|
|
5
|
+
declare function verbose(value: boolean): void;
|
|
6
|
+
|
|
7
|
+
export { log, verbose };
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
};
|