@fluidframework/ai-collab 2.10.0-306579
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/.eslintrc.cjs +26 -0
- package/CHANGELOG.md +9 -0
- package/LICENSE +21 -0
- package/README.md +280 -0
- package/alpha.d.ts +11 -0
- package/api-extractor/api-extractor-lint-alpha.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-alpha.esm.json +5 -0
- package/api-extractor/api-extractor-lint-bundle.json +5 -0
- package/api-extractor/api-extractor-lint-index.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-index.esm.json +5 -0
- package/api-extractor/api-extractor-lint-public.cjs.json +5 -0
- package/api-extractor/api-extractor-lint-public.esm.json +5 -0
- package/api-extractor-lint.json +4 -0
- package/api-extractor.json +4 -0
- package/api-report/ai-collab.alpha.api.md +164 -0
- package/api-report/ai-collab.beta.api.md +7 -0
- package/api-report/ai-collab.public.api.md +7 -0
- package/biome.jsonc +4 -0
- package/dist/aiCollab.d.ts +65 -0
- package/dist/aiCollab.d.ts.map +1 -0
- package/dist/aiCollab.js +81 -0
- package/dist/aiCollab.js.map +1 -0
- package/dist/aiCollabApi.d.ts +173 -0
- package/dist/aiCollabApi.d.ts.map +1 -0
- package/dist/aiCollabApi.js +7 -0
- package/dist/aiCollabApi.js.map +1 -0
- package/dist/alpha.d.ts +41 -0
- package/dist/explicit-strategy/agentEditReducer.d.ts +12 -0
- package/dist/explicit-strategy/agentEditReducer.d.ts.map +1 -0
- package/dist/explicit-strategy/agentEditReducer.js +394 -0
- package/dist/explicit-strategy/agentEditReducer.js.map +1 -0
- package/dist/explicit-strategy/agentEditTypes.d.ts +158 -0
- package/dist/explicit-strategy/agentEditTypes.d.ts.map +1 -0
- package/dist/explicit-strategy/agentEditTypes.js +50 -0
- package/dist/explicit-strategy/agentEditTypes.js.map +1 -0
- package/dist/explicit-strategy/idGenerator.d.ts +22 -0
- package/dist/explicit-strategy/idGenerator.d.ts.map +1 -0
- package/dist/explicit-strategy/idGenerator.js +74 -0
- package/dist/explicit-strategy/idGenerator.js.map +1 -0
- package/dist/explicit-strategy/index.d.ts +51 -0
- package/dist/explicit-strategy/index.d.ts.map +1 -0
- package/dist/explicit-strategy/index.js +223 -0
- package/dist/explicit-strategy/index.js.map +1 -0
- package/dist/explicit-strategy/jsonTypes.d.ts +23 -0
- package/dist/explicit-strategy/jsonTypes.d.ts.map +1 -0
- package/dist/explicit-strategy/jsonTypes.js +7 -0
- package/dist/explicit-strategy/jsonTypes.js.map +1 -0
- package/dist/explicit-strategy/promptGeneration.d.ts +51 -0
- package/dist/explicit-strategy/promptGeneration.d.ts.map +1 -0
- package/dist/explicit-strategy/promptGeneration.js +218 -0
- package/dist/explicit-strategy/promptGeneration.js.map +1 -0
- package/dist/explicit-strategy/typeGeneration.d.ts +15 -0
- package/dist/explicit-strategy/typeGeneration.d.ts.map +1 -0
- package/dist/explicit-strategy/typeGeneration.js +264 -0
- package/dist/explicit-strategy/typeGeneration.js.map +1 -0
- package/dist/explicit-strategy/utils.d.ts +37 -0
- package/dist/explicit-strategy/utils.d.ts.map +1 -0
- package/dist/explicit-strategy/utils.js +47 -0
- package/dist/explicit-strategy/utils.js.map +1 -0
- package/dist/implicit-strategy/index.d.ts +8 -0
- package/dist/implicit-strategy/index.d.ts.map +1 -0
- package/dist/implicit-strategy/index.js +18 -0
- package/dist/implicit-strategy/index.js.map +1 -0
- package/dist/implicit-strategy/sharedTreeBranchManager.d.ts +63 -0
- package/dist/implicit-strategy/sharedTreeBranchManager.d.ts.map +1 -0
- package/dist/implicit-strategy/sharedTreeBranchManager.js +212 -0
- package/dist/implicit-strategy/sharedTreeBranchManager.js.map +1 -0
- package/dist/implicit-strategy/sharedTreeDiff.d.ts +102 -0
- package/dist/implicit-strategy/sharedTreeDiff.d.ts.map +1 -0
- package/dist/implicit-strategy/sharedTreeDiff.js +522 -0
- package/dist/implicit-strategy/sharedTreeDiff.js.map +1 -0
- package/dist/implicit-strategy/utils.d.ts +21 -0
- package/dist/implicit-strategy/utils.d.ts.map +1 -0
- package/dist/implicit-strategy/utils.js +49 -0
- package/dist/implicit-strategy/utils.js.map +1 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/package.json +3 -0
- package/dist/public.d.ts +19 -0
- package/eslintrc.cjs +11 -0
- package/internal.d.ts +11 -0
- package/lib/aiCollab.d.ts +65 -0
- package/lib/aiCollab.d.ts.map +1 -0
- package/lib/aiCollab.js +77 -0
- package/lib/aiCollab.js.map +1 -0
- package/lib/aiCollabApi.d.ts +173 -0
- package/lib/aiCollabApi.d.ts.map +1 -0
- package/lib/aiCollabApi.js +6 -0
- package/lib/aiCollabApi.js.map +1 -0
- package/lib/alpha.d.ts +41 -0
- package/lib/explicit-strategy/agentEditReducer.d.ts +12 -0
- package/lib/explicit-strategy/agentEditReducer.d.ts.map +1 -0
- package/lib/explicit-strategy/agentEditReducer.js +390 -0
- package/lib/explicit-strategy/agentEditReducer.js.map +1 -0
- package/lib/explicit-strategy/agentEditTypes.d.ts +158 -0
- package/lib/explicit-strategy/agentEditTypes.d.ts.map +1 -0
- package/lib/explicit-strategy/agentEditTypes.js +47 -0
- package/lib/explicit-strategy/agentEditTypes.js.map +1 -0
- package/lib/explicit-strategy/idGenerator.d.ts +22 -0
- package/lib/explicit-strategy/idGenerator.d.ts.map +1 -0
- package/lib/explicit-strategy/idGenerator.js +70 -0
- package/lib/explicit-strategy/idGenerator.js.map +1 -0
- package/lib/explicit-strategy/index.d.ts +51 -0
- package/lib/explicit-strategy/index.d.ts.map +1 -0
- package/lib/explicit-strategy/index.js +219 -0
- package/lib/explicit-strategy/index.js.map +1 -0
- package/lib/explicit-strategy/jsonTypes.d.ts +23 -0
- package/lib/explicit-strategy/jsonTypes.d.ts.map +1 -0
- package/lib/explicit-strategy/jsonTypes.js +6 -0
- package/lib/explicit-strategy/jsonTypes.js.map +1 -0
- package/lib/explicit-strategy/promptGeneration.d.ts +51 -0
- package/lib/explicit-strategy/promptGeneration.d.ts.map +1 -0
- package/lib/explicit-strategy/promptGeneration.js +208 -0
- package/lib/explicit-strategy/promptGeneration.js.map +1 -0
- package/lib/explicit-strategy/typeGeneration.d.ts +15 -0
- package/lib/explicit-strategy/typeGeneration.d.ts.map +1 -0
- package/lib/explicit-strategy/typeGeneration.js +260 -0
- package/lib/explicit-strategy/typeGeneration.js.map +1 -0
- package/lib/explicit-strategy/utils.d.ts +37 -0
- package/lib/explicit-strategy/utils.d.ts.map +1 -0
- package/lib/explicit-strategy/utils.js +41 -0
- package/lib/explicit-strategy/utils.js.map +1 -0
- package/lib/implicit-strategy/index.d.ts +8 -0
- package/lib/implicit-strategy/index.d.ts.map +1 -0
- package/lib/implicit-strategy/index.js +8 -0
- package/lib/implicit-strategy/index.js.map +1 -0
- package/lib/implicit-strategy/sharedTreeBranchManager.d.ts +63 -0
- package/lib/implicit-strategy/sharedTreeBranchManager.d.ts.map +1 -0
- package/lib/implicit-strategy/sharedTreeBranchManager.js +213 -0
- package/lib/implicit-strategy/sharedTreeBranchManager.js.map +1 -0
- package/lib/implicit-strategy/sharedTreeDiff.d.ts +102 -0
- package/lib/implicit-strategy/sharedTreeDiff.d.ts.map +1 -0
- package/lib/implicit-strategy/sharedTreeDiff.js +515 -0
- package/lib/implicit-strategy/sharedTreeDiff.js.map +1 -0
- package/lib/implicit-strategy/utils.d.ts +21 -0
- package/lib/implicit-strategy/utils.d.ts.map +1 -0
- package/lib/implicit-strategy/utils.js +43 -0
- package/lib/implicit-strategy/utils.js.map +1 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +15 -0
- package/lib/index.js.map +1 -0
- package/lib/public.d.ts +19 -0
- package/lib/tsdoc-metadata.json +11 -0
- package/mocharc.cjs +14 -0
- package/package.json +165 -0
- package/prettier.config.cjs +8 -0
- package/src/aiCollab.ts +86 -0
- package/src/aiCollabApi.ts +184 -0
- package/src/explicit-strategy/agentEditReducer.ts +498 -0
- package/src/explicit-strategy/agentEditTypes.ts +177 -0
- package/src/explicit-strategy/idGenerator.ts +90 -0
- package/src/explicit-strategy/index.ts +364 -0
- package/src/explicit-strategy/jsonTypes.ts +27 -0
- package/src/explicit-strategy/promptGeneration.ts +294 -0
- package/src/explicit-strategy/typeGeneration.ts +374 -0
- package/src/explicit-strategy/utils.ts +60 -0
- package/src/implicit-strategy/README.md +4 -0
- package/src/implicit-strategy/index.ts +21 -0
- package/src/implicit-strategy/sharedTreeBranchManager.ts +294 -0
- package/src/implicit-strategy/sharedTreeDiff.ts +735 -0
- package/src/implicit-strategy/utils.ts +54 -0
- package/src/index.ts +39 -0
- package/tsconfig.cjs.json +7 -0
- package/tsconfig.json +12 -0
- package/tsdoc.json +4 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getOrCreate = exports.mapIterable = exports.fail = void 0;
|
|
8
|
+
/**
|
|
9
|
+
* TBD
|
|
10
|
+
*/
|
|
11
|
+
function fail(message) {
|
|
12
|
+
throw new Error(message);
|
|
13
|
+
}
|
|
14
|
+
exports.fail = fail;
|
|
15
|
+
/**
|
|
16
|
+
* Map one iterable to another by transforming each element one at a time
|
|
17
|
+
* @param iterable - the iterable to transform
|
|
18
|
+
* @param map - the transformation function to run on each element of the iterable
|
|
19
|
+
* @returns a new iterable of elements which have been transformed by the `map` function
|
|
20
|
+
*
|
|
21
|
+
* @remarks originally from tree/src/util/utils.ts
|
|
22
|
+
*/
|
|
23
|
+
function* mapIterable(iterable, map) {
|
|
24
|
+
for (const t of iterable) {
|
|
25
|
+
yield map(t);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.mapIterable = mapIterable;
|
|
29
|
+
/**
|
|
30
|
+
* Retrieve a value from a map with the given key, or create a new entry if the key is not in the map.
|
|
31
|
+
* @param map - The map to query/update
|
|
32
|
+
* @param key - The key to lookup in the map
|
|
33
|
+
* @param defaultValue - a function which returns a default value. This is called and used to set an initial value for the given key in the map if none exists
|
|
34
|
+
* @returns either the existing value for the given key, or the newly-created value (the result of `defaultValue`)
|
|
35
|
+
*
|
|
36
|
+
* @remarks originally from tree/src/util/utils.ts
|
|
37
|
+
*/
|
|
38
|
+
function getOrCreate(map, key, defaultValue) {
|
|
39
|
+
let value = map.get(key);
|
|
40
|
+
if (value === undefined) {
|
|
41
|
+
value = defaultValue(key);
|
|
42
|
+
map.set(key, value);
|
|
43
|
+
}
|
|
44
|
+
return value;
|
|
45
|
+
}
|
|
46
|
+
exports.getOrCreate = getOrCreate;
|
|
47
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/explicit-strategy/utils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAYH;;GAEG;AACH,SAAgB,IAAI,CAAC,OAAe;IACnC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAC1B,CAAC;AAFD,oBAEC;AAED;;;;;;;GAOG;AACH,QAAe,CAAC,CAAC,WAAW,CAC3B,QAAqB,EACrB,GAAgB;IAEhB,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QAC1B,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IACd,CAAC;AACF,CAAC;AAPD,kCAOC;AAED;;;;;;;;GAQG;AACH,SAAgB,WAAW,CAC1B,GAAoB,EACpB,GAAM,EACN,YAA2B;IAE3B,IAAI,KAAK,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACzB,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;QACzB,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;QAC1B,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAXD,kCAWC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * Subset of Map interface.\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport interface MapGetSet<K, V> {\n\tget(key: K): V | undefined;\n\tset(key: K, value: V): void;\n}\n\n/**\n * TBD\n */\nexport function fail(message: string): never {\n\tthrow new Error(message);\n}\n\n/**\n * Map one iterable to another by transforming each element one at a time\n * @param iterable - the iterable to transform\n * @param map - the transformation function to run on each element of the iterable\n * @returns a new iterable of elements which have been transformed by the `map` function\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport function* mapIterable<T, U>(\n\titerable: Iterable<T>,\n\tmap: (t: T) => U,\n): IterableIterator<U> {\n\tfor (const t of iterable) {\n\t\tyield map(t);\n\t}\n}\n\n/**\n * Retrieve a value from a map with the given key, or create a new entry if the key is not in the map.\n * @param map - The map to query/update\n * @param key - The key to lookup in the map\n * @param defaultValue - a function which returns a default value. This is called and used to set an initial value for the given key in the map if none exists\n * @returns either the existing value for the given key, or the newly-created value (the result of `defaultValue`)\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport function getOrCreate<K, V>(\n\tmap: MapGetSet<K, V>,\n\tkey: K,\n\tdefaultValue: (key: K) => V,\n): V {\n\tlet value = map.get(key);\n\tif (value === undefined) {\n\t\tvalue = defaultValue(key);\n\t\tmap.set(key, value);\n\t}\n\treturn value;\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
export { type DifferenceCreate, type DifferenceChange, type DifferenceMove, type DifferenceRemove, type Difference, type ObjectPath, type Options, sharedTreeDiff, createMergableIdDiffSeries, createMergableDiffSeries, } from "./sharedTreeDiff.js";
|
|
6
|
+
export { SharedTreeBranchManager } from "./sharedTreeBranchManager.js";
|
|
7
|
+
export { sharedTreeTraverse, isTreeArrayNode, isTreeMapNode } from "./utils.js";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/implicit-strategy/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,UAAU,EACf,KAAK,UAAU,EACf,KAAK,OAAO,EACZ,cAAc,EACd,0BAA0B,EAC1B,wBAAwB,GACxB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.isTreeMapNode = exports.isTreeArrayNode = exports.sharedTreeTraverse = exports.SharedTreeBranchManager = exports.createMergableDiffSeries = exports.createMergableIdDiffSeries = exports.sharedTreeDiff = void 0;
|
|
8
|
+
var sharedTreeDiff_js_1 = require("./sharedTreeDiff.js");
|
|
9
|
+
Object.defineProperty(exports, "sharedTreeDiff", { enumerable: true, get: function () { return sharedTreeDiff_js_1.sharedTreeDiff; } });
|
|
10
|
+
Object.defineProperty(exports, "createMergableIdDiffSeries", { enumerable: true, get: function () { return sharedTreeDiff_js_1.createMergableIdDiffSeries; } });
|
|
11
|
+
Object.defineProperty(exports, "createMergableDiffSeries", { enumerable: true, get: function () { return sharedTreeDiff_js_1.createMergableDiffSeries; } });
|
|
12
|
+
var sharedTreeBranchManager_js_1 = require("./sharedTreeBranchManager.js");
|
|
13
|
+
Object.defineProperty(exports, "SharedTreeBranchManager", { enumerable: true, get: function () { return sharedTreeBranchManager_js_1.SharedTreeBranchManager; } });
|
|
14
|
+
var utils_js_1 = require("./utils.js");
|
|
15
|
+
Object.defineProperty(exports, "sharedTreeTraverse", { enumerable: true, get: function () { return utils_js_1.sharedTreeTraverse; } });
|
|
16
|
+
Object.defineProperty(exports, "isTreeArrayNode", { enumerable: true, get: function () { return utils_js_1.isTreeArrayNode; } });
|
|
17
|
+
Object.defineProperty(exports, "isTreeMapNode", { enumerable: true, get: function () { return utils_js_1.isTreeMapNode; } });
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/implicit-strategy/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,yDAW6B;AAH5B,mHAAA,cAAc,OAAA;AACd,+HAAA,0BAA0B,OAAA;AAC1B,6HAAA,wBAAwB,OAAA;AAGzB,2EAAuE;AAA9D,qIAAA,uBAAuB,OAAA;AAEhC,uCAAgF;AAAvE,8GAAA,kBAAkB,OAAA;AAAE,2GAAA,eAAe,OAAA;AAAE,yGAAA,aAAa,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\ttype DifferenceCreate,\n\ttype DifferenceChange,\n\ttype DifferenceMove,\n\ttype DifferenceRemove,\n\ttype Difference,\n\ttype ObjectPath,\n\ttype Options,\n\tsharedTreeDiff,\n\tcreateMergableIdDiffSeries,\n\tcreateMergableDiffSeries,\n} from \"./sharedTreeDiff.js\";\n\nexport { SharedTreeBranchManager } from \"./sharedTreeBranchManager.js\";\n\nexport { sharedTreeTraverse, isTreeArrayNode, isTreeMapNode } from \"./utils.js\";\n"]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import type { ImplicitFieldSchema, TreeArrayNode, TreeViewConfiguration } from "@fluidframework/tree";
|
|
6
|
+
import { type BranchableTree, type TreeBranchFork, type TreeViewAlpha } from "@fluidframework/tree/alpha";
|
|
7
|
+
import type { z } from "zod";
|
|
8
|
+
import { type Difference, type ObjectPath } from "./sharedTreeDiff.js";
|
|
9
|
+
/**
|
|
10
|
+
* Manages determining the differences between two branches of a SharedTree represented as an actual tree node or a plain javascript object
|
|
11
|
+
* and applies said differences to the original SharedTree branch.
|
|
12
|
+
*
|
|
13
|
+
* @alpha
|
|
14
|
+
*/
|
|
15
|
+
export declare class SharedTreeBranchManager {
|
|
16
|
+
private readonly objectSchema?;
|
|
17
|
+
private readonly nodeIdAttributeName?;
|
|
18
|
+
constructor(params?: {
|
|
19
|
+
objectSchema?: z.Schema;
|
|
20
|
+
nodeIdAttributeName?: string;
|
|
21
|
+
});
|
|
22
|
+
/**
|
|
23
|
+
* Compares the differences between either two objects or a TreeNode and a plain object.
|
|
24
|
+
* TODO: Should allow comparing two tree nodes? Should we allow comparing two plain objects? Or just leave as tree node vs object?
|
|
25
|
+
*/
|
|
26
|
+
compare(obj: Record<string, unknown> | TreeArrayNode, newObj: Record<string, unknown> | unknown[]): Difference[];
|
|
27
|
+
/**
|
|
28
|
+
* Produces a set of differences based on two versions of an object, applies the changes to the first one,
|
|
29
|
+
* and returns the set of differences.
|
|
30
|
+
*/
|
|
31
|
+
mergeObject(obj: Record<string, unknown> | TreeArrayNode, llmResponse: Record<string, unknown> | unknown[]): Difference[];
|
|
32
|
+
/**
|
|
33
|
+
* produces a diff between two objects and merges the differences.
|
|
34
|
+
*/
|
|
35
|
+
checkoutNewMergedBranch<T extends ImplicitFieldSchema>(treeView: TreeViewAlpha<T>, treeViewConfiguration: TreeViewConfiguration<T>, absolutePathToObjectNode: ObjectPath, llmResponse: Record<string, unknown> | unknown[]): {
|
|
36
|
+
differences: Difference[];
|
|
37
|
+
originalBranch: BranchableTree;
|
|
38
|
+
forkBranch: TreeBranchFork;
|
|
39
|
+
forkView: TreeViewAlpha<T>;
|
|
40
|
+
newBranchTargetNode: Record<string, unknown> | TreeArrayNode;
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Creates a forked branch of a tree view.
|
|
44
|
+
*/
|
|
45
|
+
checkoutNewMergedBranchV2<T extends ImplicitFieldSchema>(treeView: TreeViewAlpha<T>, treeViewConfiguration: TreeViewConfiguration<T>, absolutePathToObjectNode: ObjectPath): {
|
|
46
|
+
originalBranch: BranchableTree;
|
|
47
|
+
forkBranch: TreeBranchFork;
|
|
48
|
+
forkView: TreeViewAlpha<T>;
|
|
49
|
+
newBranchTargetNode: Record<string, unknown> | TreeArrayNode;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Handles applying an array of differences to an object in the proper order and making any necessary adjustments as each diff
|
|
53
|
+
* is applied.
|
|
54
|
+
*
|
|
55
|
+
* @returns an array of differences that were not applied due to some kind of conflict or error.
|
|
56
|
+
*/
|
|
57
|
+
mergeDiffs(diffs: Difference[], objectToUpdate: Record<string, unknown> | TreeArrayNode): Set<Difference>;
|
|
58
|
+
/**
|
|
59
|
+
* Applies an individual diff to the objectToUpdate.
|
|
60
|
+
*/
|
|
61
|
+
applyDiff(diff: Difference, objectToUpdate: Record<string, unknown> | TreeArrayNode): boolean;
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=sharedTreeBranchManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sharedTreeBranchManager.d.ts","sourceRoot":"","sources":["../../src/implicit-strategy/sharedTreeBranchManager.ts"],"names":[],"mappings":"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AAC;QAC1B,cAAc,EAAE,cAAc,CAAC;QAC/B,UAAU,EAAE,cAAc,CAAC;QAC3B,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;QAC3B,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,CAAC;KAC7D;IA2BD;;OAEG;IACI,yBAAyB,CAAC,CAAC,SAAS,mBAAmB,EAC7D,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAC1B,qBAAqB,EAAE,qBAAqB,CAAC,CAAC,CAAC,EAC/C,wBAAwB,EAAE,UAAU,GAElC;QACF,cAAc,EAAE,cAAc,CAAC;QAC/B,UAAU,EAAE,cAAc,CAAC;QAC3B,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;QAC3B,mBAAmB,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,CAAC;KAC7D;IAaD;;;;;OAKG;IACI,UAAU,CAChB,KAAK,EAAE,UAAU,EAAE,EACnB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,GACrD,GAAG,CAAC,UAAU,CAAC;IAclB;;OAEG;IACI,SAAS,CACf,IAAI,EAAE,UAAU,EAChB,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,GACrD,OAAO;CA4FV"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*!
|
|
3
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
4
|
+
* Licensed under the MIT License.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.SharedTreeBranchManager = void 0;
|
|
8
|
+
const alpha_1 = require("@fluidframework/tree/alpha");
|
|
9
|
+
const sharedTreeDiff_js_1 = require("./sharedTreeDiff.js");
|
|
10
|
+
const utils_js_1 = require("./utils.js");
|
|
11
|
+
/**
|
|
12
|
+
* Manages determining the differences between two branches of a SharedTree represented as an actual tree node or a plain javascript object
|
|
13
|
+
* and applies said differences to the original SharedTree branch.
|
|
14
|
+
*
|
|
15
|
+
* @alpha
|
|
16
|
+
*/
|
|
17
|
+
class SharedTreeBranchManager {
|
|
18
|
+
constructor(params) {
|
|
19
|
+
this.objectSchema = params?.objectSchema;
|
|
20
|
+
this.nodeIdAttributeName = params?.nodeIdAttributeName;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Compares the differences between either two objects or a TreeNode and a plain object.
|
|
24
|
+
* TODO: Should allow comparing two tree nodes? Should we allow comparing two plain objects? Or just leave as tree node vs object?
|
|
25
|
+
*/
|
|
26
|
+
compare(obj, newObj) {
|
|
27
|
+
// By validating that the incoming object matches the schema, we can confirm that any property
|
|
28
|
+
// deletions/updates/additions are valid.
|
|
29
|
+
if (this.objectSchema !== undefined) {
|
|
30
|
+
const res = this.objectSchema.safeParse(newObj);
|
|
31
|
+
if (res.success === false) {
|
|
32
|
+
throw new TypeError("Invalid data");
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const diffTotality = (0, sharedTreeDiff_js_1.sharedTreeDiff)(obj, newObj, {
|
|
36
|
+
useObjectIds: this.nodeIdAttributeName === undefined
|
|
37
|
+
? undefined
|
|
38
|
+
: { idAttributeName: this.nodeIdAttributeName },
|
|
39
|
+
cyclesFix: true,
|
|
40
|
+
});
|
|
41
|
+
if (this.nodeIdAttributeName !== undefined) {
|
|
42
|
+
return (0, sharedTreeDiff_js_1.createMergableIdDiffSeries)(obj, diffTotality, this.nodeIdAttributeName);
|
|
43
|
+
}
|
|
44
|
+
return (0, sharedTreeDiff_js_1.createMergableDiffSeries)(diffTotality);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Produces a set of differences based on two versions of an object, applies the changes to the first one,
|
|
48
|
+
* and returns the set of differences.
|
|
49
|
+
*/
|
|
50
|
+
mergeObject(obj, llmResponse) {
|
|
51
|
+
const differences = this.compare(obj, llmResponse);
|
|
52
|
+
this.mergeDiffs(differences, obj);
|
|
53
|
+
return differences;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* produces a diff between two objects and merges the differences.
|
|
57
|
+
*/
|
|
58
|
+
checkoutNewMergedBranch(treeView, treeViewConfiguration, absolutePathToObjectNode, llmResponse) {
|
|
59
|
+
// eslint-disable-next-line import/no-deprecated
|
|
60
|
+
const originalBranch = (0, alpha_1.getBranch)(treeView);
|
|
61
|
+
const forkBranch = originalBranch.branch();
|
|
62
|
+
const forkView = forkBranch.viewWith(treeViewConfiguration);
|
|
63
|
+
console.log("traveling to absolute path from root:", absolutePathToObjectNode);
|
|
64
|
+
const newBranchTargetNode = (0, utils_js_1.sharedTreeTraverse)(forkView.root, absolutePathToObjectNode);
|
|
65
|
+
console.log("initiating compare between old and new branch target nodes", { ...newBranchTargetNode }, { ...llmResponse });
|
|
66
|
+
console.log("newBranchTargetNode", { ...newBranchTargetNode });
|
|
67
|
+
console.log("llmResponse", { ...llmResponse });
|
|
68
|
+
const differences = this.compare(newBranchTargetNode, llmResponse);
|
|
69
|
+
// const differences = [];
|
|
70
|
+
this.mergeDiffs(differences, newBranchTargetNode);
|
|
71
|
+
return { differences, originalBranch, forkBranch, forkView, newBranchTargetNode };
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Creates a forked branch of a tree view.
|
|
75
|
+
*/
|
|
76
|
+
checkoutNewMergedBranchV2(treeView, treeViewConfiguration, absolutePathToObjectNode) {
|
|
77
|
+
// eslint-disable-next-line import/no-deprecated
|
|
78
|
+
const originalBranch = (0, alpha_1.getBranch)(treeView);
|
|
79
|
+
const forkBranch = originalBranch.branch();
|
|
80
|
+
const forkView = forkBranch.viewWith(treeViewConfiguration);
|
|
81
|
+
const newBranchTargetNode = (0, utils_js_1.sharedTreeTraverse)(forkView.root, absolutePathToObjectNode);
|
|
82
|
+
// this.mergeDiffs(differences, newBranchTargetNode);
|
|
83
|
+
return { originalBranch, forkBranch, forkView, newBranchTargetNode };
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Handles applying an array of differences to an object in the proper order and making any necessary adjustments as each diff
|
|
87
|
+
* is applied.
|
|
88
|
+
*
|
|
89
|
+
* @returns an array of differences that were not applied due to some kind of conflict or error.
|
|
90
|
+
*/
|
|
91
|
+
mergeDiffs(diffs, objectToUpdate) {
|
|
92
|
+
const unappliedDiffs = new Set();
|
|
93
|
+
for (const diff of diffs) {
|
|
94
|
+
const isDiffApplied = this.applyDiff(diff, objectToUpdate);
|
|
95
|
+
if (isDiffApplied === false) {
|
|
96
|
+
unappliedDiffs.add(diff);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return unappliedDiffs;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Applies an individual diff to the objectToUpdate.
|
|
103
|
+
*/
|
|
104
|
+
applyDiff(diff, objectToUpdate) {
|
|
105
|
+
const targetObject = getTargetObjectFromPath(diff.path, objectToUpdate);
|
|
106
|
+
if ((0, utils_js_1.isTreeMapNode)(targetObject)) {
|
|
107
|
+
switch (diff.type) {
|
|
108
|
+
case "CHANGE":
|
|
109
|
+
case "CREATE": {
|
|
110
|
+
// This code is doing non-schema aware editing, which is not a supported feature of this API.
|
|
111
|
+
// Casting to any is a way to get this unsupported and rather unsafe operation to compile.
|
|
112
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
113
|
+
targetObject.set(diff.path[diff.path.length - 1], diff.value);
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
case "REMOVE": {
|
|
117
|
+
targetObject.delete(diff.path[diff.path.length - 1]);
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
default: {
|
|
121
|
+
throw new TypeError("Unsupported diff type for Map Tree Node");
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else if ((0, utils_js_1.isTreeArrayNode)(targetObject)) {
|
|
126
|
+
const targetIndex = diff.path[diff.path.length - 1];
|
|
127
|
+
const isTargetIndexValid = targetIndex >= 0 && targetIndex <= targetObject.length - 1;
|
|
128
|
+
switch (diff.type) {
|
|
129
|
+
case "CHANGE":
|
|
130
|
+
case "CREATE": {
|
|
131
|
+
if (isTargetIndexValid) {
|
|
132
|
+
// This code is doing non-schema aware editing, which is not a supported feature of this API.
|
|
133
|
+
// Casting to any is a way to get this unsupported and rather unsafe operation to compile.
|
|
134
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
135
|
+
targetObject.insertAt(targetIndex, diff.value);
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
// This code is doing non-schema aware editing, which is not a supported feature of this API.
|
|
140
|
+
// Casting to any is a way to get this unsupported and rather unsafe operation to compile.
|
|
141
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any
|
|
142
|
+
targetObject.insertAtEnd(diff.value);
|
|
143
|
+
console.warn("CREATE diff specified an invalid index, defaulting to pushing to end of array");
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
case "MOVE": {
|
|
148
|
+
if (isTargetIndexValid) {
|
|
149
|
+
if (diff.newIndex > targetIndex) {
|
|
150
|
+
// forward move must use i + 1
|
|
151
|
+
targetObject.moveToIndex(diff.newIndex + 1, targetIndex);
|
|
152
|
+
}
|
|
153
|
+
else if (diff.newIndex < targetIndex) {
|
|
154
|
+
// backwards move, using i directly is fine
|
|
155
|
+
targetObject.moveToIndex(diff.newIndex, targetIndex);
|
|
156
|
+
}
|
|
157
|
+
return true;
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
console.warn("MOVE diff specified an invalid index, ignoring.");
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
case "REMOVE": {
|
|
165
|
+
if (isTargetIndexValid) {
|
|
166
|
+
targetObject.removeAt(targetIndex);
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
console.warn("REMOVE diff specified an invalid index, ignoring.");
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
default: {
|
|
175
|
+
throw new TypeError("Unsupported diff type for Array Tree Node");
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
else if (typeof targetObject === "object" && targetObject !== null) {
|
|
180
|
+
switch (diff.type) {
|
|
181
|
+
case "CHANGE":
|
|
182
|
+
case "CREATE": {
|
|
183
|
+
targetObject[diff.path[diff.path.length - 1]] = diff.value;
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
case "REMOVE": {
|
|
187
|
+
// We can't use the delete keyword on a tree node.
|
|
188
|
+
targetObject[diff.path[diff.path.length - 1]] = undefined;
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
default: {
|
|
192
|
+
throw new TypeError("Unsupported diff type for Object Tree Node");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
throw new TypeError("Unsupported object type for diff application");
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
exports.SharedTreeBranchManager = SharedTreeBranchManager;
|
|
202
|
+
/**
|
|
203
|
+
* Returns the target object that the given diff should be applied to.
|
|
204
|
+
*/
|
|
205
|
+
function getTargetObjectFromPath(path, object) {
|
|
206
|
+
let targetObject = object;
|
|
207
|
+
if (path.length > 1) {
|
|
208
|
+
targetObject = (0, utils_js_1.sharedTreeTraverse)(object, path.slice(0, -1));
|
|
209
|
+
}
|
|
210
|
+
return targetObject;
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=sharedTreeBranchManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sharedTreeBranchManager.js","sourceRoot":"","sources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I,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAW,CAAC,GAAG,SAAS,CAAC;oBACpE,OAAO,KAAK,CAAC;gBACd,CAAC;gBACD,OAAO,CAAC,CAAC,CAAC;oBACT,MAAM,IAAI,SAAS,CAAC,4CAA4C,CAAC,CAAC;gBACnE,CAAC;YACF,CAAC;QACF,CAAC;aAAM,CAAC;YACP,MAAM,IAAI,SAAS,CAAC,8CAA8C,CAAC,CAAC;QACrE,CAAC;IACF,CAAC;CACD;AAlPD,0DAkPC;AAED;;GAEG;AACH,SAAS,uBAAuB,CAC/B,IAAgB,EAChB,MAA+C;IAE/C,IAAI,YAAY,GAAY,MAAM,CAAC;IACnC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrB,YAAY,GAAG,IAAA,6BAAkB,EAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9D,CAAC;IACD,OAAO,YAAY,CAAC;AACrB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tImplicitFieldSchema,\n\tTreeArrayNode,\n\tTreeMapNode,\n\tTreeViewConfiguration,\n} from \"@fluidframework/tree\";\nimport {\n\t// TODO: Migrate to newer branching API (`TreeContext`)\n\t// eslint-disable-next-line import/no-deprecated\n\tgetBranch,\n\ttype BranchableTree,\n\ttype TreeBranchFork,\n\ttype TreeViewAlpha,\n\t// eslint-disable-next-line import/no-internal-modules -- This package depends on the branching APIs in Tree which are currently alpha\n} from \"@fluidframework/tree/alpha\";\nimport type { z } from \"zod\";\n\nimport {\n\tcreateMergableDiffSeries,\n\tcreateMergableIdDiffSeries,\n\tsharedTreeDiff,\n\ttype Difference,\n\ttype ObjectPath,\n} from \"./sharedTreeDiff.js\";\nimport { isTreeMapNode, isTreeArrayNode, sharedTreeTraverse } from \"./utils.js\";\n\n/**\n * Manages determining the differences between two branches of a SharedTree represented as an actual tree node or a plain javascript object\n * and applies said differences to the original SharedTree branch.\n *\n * @alpha\n */\nexport class SharedTreeBranchManager {\n\tprivate readonly objectSchema?: z.Schema | undefined;\n\tprivate readonly nodeIdAttributeName?: string | undefined;\n\n\tpublic constructor(params?: { objectSchema?: z.Schema; nodeIdAttributeName?: string }) {\n\t\tthis.objectSchema = params?.objectSchema;\n\t\tthis.nodeIdAttributeName = params?.nodeIdAttributeName;\n\t}\n\n\t/**\n\t * Compares the differences between either two objects or a TreeNode and a plain object.\n\t * TODO: Should allow comparing two tree nodes? Should we allow comparing two plain objects? Or just leave as tree node vs object?\n\t */\n\tpublic compare(\n\t\tobj: Record<string, unknown> | TreeArrayNode,\n\t\tnewObj: Record<string, unknown> | unknown[],\n\t): Difference[] {\n\t\t// By validating that the incoming object matches the schema, we can confirm that any property\n\t\t// deletions/updates/additions are valid.\n\t\tif (this.objectSchema !== undefined) {\n\t\t\tconst res = this.objectSchema.safeParse(newObj);\n\t\t\tif (res.success === false) {\n\t\t\t\tthrow new TypeError(\"Invalid data\");\n\t\t\t}\n\t\t}\n\n\t\tconst diffTotality = sharedTreeDiff(obj as Record<string, unknown> | unknown[], newObj, {\n\t\t\tuseObjectIds:\n\t\t\t\tthis.nodeIdAttributeName === undefined\n\t\t\t\t\t? undefined\n\t\t\t\t\t: { idAttributeName: this.nodeIdAttributeName },\n\t\t\tcyclesFix: true,\n\t\t});\n\n\t\tif (this.nodeIdAttributeName !== undefined) {\n\t\t\treturn createMergableIdDiffSeries(obj, diffTotality, this.nodeIdAttributeName);\n\t\t}\n\n\t\treturn createMergableDiffSeries(diffTotality);\n\t}\n\n\t/**\n\t * Produces a set of differences based on two versions of an object, applies the changes to the first one,\n\t * and returns the set of differences.\n\t */\n\tpublic mergeObject(\n\t\tobj: Record<string, unknown> | TreeArrayNode,\n\t\tllmResponse: Record<string, unknown> | unknown[],\n\t): Difference[] {\n\t\tconst differences = this.compare(obj, llmResponse);\n\t\tthis.mergeDiffs(differences, obj);\n\t\treturn differences;\n\t}\n\n\t/**\n\t * produces a diff between two objects and merges the differences.\n\t */\n\tpublic checkoutNewMergedBranch<T extends ImplicitFieldSchema>(\n\t\ttreeView: TreeViewAlpha<T>,\n\t\ttreeViewConfiguration: TreeViewConfiguration<T>,\n\t\tabsolutePathToObjectNode: ObjectPath,\n\t\tllmResponse: Record<string, unknown> | unknown[],\n\t): {\n\t\tdifferences: Difference[];\n\t\toriginalBranch: BranchableTree;\n\t\tforkBranch: TreeBranchFork;\n\t\tforkView: TreeViewAlpha<T>;\n\t\tnewBranchTargetNode: Record<string, unknown> | TreeArrayNode;\n\t} {\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tconst originalBranch = getBranch(treeView);\n\t\tconst forkBranch = originalBranch.branch();\n\t\tconst forkView = forkBranch.viewWith(treeViewConfiguration) as TreeViewAlpha<T>;\n\n\t\tconsole.log(\"traveling to absolute path from root:\", absolutePathToObjectNode);\n\t\tconst newBranchTargetNode = sharedTreeTraverse(\n\t\t\tforkView.root as unknown as TreeMapNode | TreeArrayNode | Record<string, unknown>,\n\t\t\tabsolutePathToObjectNode,\n\t\t) as Record<string, unknown> | TreeArrayNode;\n\n\t\tconsole.log(\n\t\t\t\"initiating compare between old and new branch target nodes\",\n\t\t\t{ ...newBranchTargetNode },\n\t\t\t{ ...llmResponse },\n\t\t);\n\t\tconsole.log(\"newBranchTargetNode\", { ...newBranchTargetNode });\n\t\tconsole.log(\"llmResponse\", { ...llmResponse });\n\n\t\tconst differences = this.compare(newBranchTargetNode, llmResponse);\n\t\t// const differences = [];\n\t\tthis.mergeDiffs(differences, newBranchTargetNode);\n\n\t\treturn { differences, originalBranch, forkBranch, forkView, newBranchTargetNode };\n\t}\n\n\t/**\n\t * Creates a forked branch of a tree view.\n\t */\n\tpublic checkoutNewMergedBranchV2<T extends ImplicitFieldSchema>(\n\t\ttreeView: TreeViewAlpha<T>,\n\t\ttreeViewConfiguration: TreeViewConfiguration<T>,\n\t\tabsolutePathToObjectNode: ObjectPath,\n\t\t// differences: Difference[],\n\t): {\n\t\toriginalBranch: BranchableTree;\n\t\tforkBranch: TreeBranchFork;\n\t\tforkView: TreeViewAlpha<T>;\n\t\tnewBranchTargetNode: Record<string, unknown> | TreeArrayNode;\n\t} {\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tconst originalBranch = getBranch(treeView);\n\t\tconst forkBranch = originalBranch.branch();\n\t\tconst forkView = forkBranch.viewWith(treeViewConfiguration) as TreeViewAlpha<T>;\n\t\tconst newBranchTargetNode = sharedTreeTraverse(\n\t\t\tforkView.root as TreeMapNode | TreeArrayNode | Record<string, unknown>,\n\t\t\tabsolutePathToObjectNode,\n\t\t) as Record<string, unknown> | TreeArrayNode;\n\t\t// this.mergeDiffs(differences, newBranchTargetNode);\n\t\treturn { originalBranch, forkBranch, forkView, newBranchTargetNode };\n\t}\n\n\t/**\n\t * Handles applying an array of differences to an object in the proper order and making any necessary adjustments as each diff\n\t * is applied.\n\t *\n\t * @returns an array of differences that were not applied due to some kind of conflict or error.\n\t */\n\tpublic mergeDiffs(\n\t\tdiffs: Difference[],\n\t\tobjectToUpdate: Record<string, unknown> | TreeArrayNode,\n\t): Set<Difference> {\n\t\tconst unappliedDiffs = new Set<Difference>();\n\n\t\tfor (const diff of diffs) {\n\t\t\tconst isDiffApplied = this.applyDiff(diff, objectToUpdate);\n\n\t\t\tif (isDiffApplied === false) {\n\t\t\t\tunappliedDiffs.add(diff);\n\t\t\t}\n\t\t}\n\n\t\treturn unappliedDiffs;\n\t}\n\n\t/**\n\t * Applies an individual diff to the objectToUpdate.\n\t */\n\tpublic applyDiff(\n\t\tdiff: Difference,\n\t\tobjectToUpdate: Record<string, unknown> | TreeArrayNode,\n\t): boolean {\n\t\tconst targetObject: unknown = getTargetObjectFromPath(diff.path, objectToUpdate);\n\n\t\tif (isTreeMapNode(targetObject)) {\n\t\t\tswitch (diff.type) {\n\t\t\t\tcase \"CHANGE\":\n\t\t\t\tcase \"CREATE\": {\n\t\t\t\t\t// This code is doing non-schema aware editing, which is not a supported feature of this API.\n\t\t\t\t\t// Casting to any is a way to get this unsupported and rather unsafe operation to compile.\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any\n\t\t\t\t\ttargetObject.set(diff.path[diff.path.length - 1] as string, diff.value as any);\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tcase \"REMOVE\": {\n\t\t\t\t\ttargetObject.delete(diff.path[diff.path.length - 1] as string);\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new TypeError(\"Unsupported diff type for Map Tree Node\");\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (isTreeArrayNode(targetObject)) {\n\t\t\tconst targetIndex = diff.path[diff.path.length - 1] as number;\n\t\t\tconst isTargetIndexValid = targetIndex >= 0 && targetIndex <= targetObject.length - 1;\n\t\t\tswitch (diff.type) {\n\t\t\t\tcase \"CHANGE\":\n\t\t\t\tcase \"CREATE\": {\n\t\t\t\t\tif (isTargetIndexValid) {\n\t\t\t\t\t\t// This code is doing non-schema aware editing, which is not a supported feature of this API.\n\t\t\t\t\t\t// Casting to any is a way to get this unsupported and rather unsafe operation to compile.\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any\n\t\t\t\t\t\ttargetObject.insertAt(targetIndex, diff.value as any);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// This code is doing non-schema aware editing, which is not a supported feature of this API.\n\t\t\t\t\t\t// Casting to any is a way to get this unsupported and rather unsafe operation to compile.\n\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any\n\t\t\t\t\t\ttargetObject.insertAtEnd(diff.value as any);\n\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\"CREATE diff specified an invalid index, defaulting to pushing to end of array\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcase \"MOVE\": {\n\t\t\t\t\tif (isTargetIndexValid) {\n\t\t\t\t\t\tif (diff.newIndex > targetIndex) {\n\t\t\t\t\t\t\t// forward move must use i + 1\n\t\t\t\t\t\t\ttargetObject.moveToIndex(diff.newIndex + 1, targetIndex);\n\t\t\t\t\t\t} else if (diff.newIndex < targetIndex) {\n\t\t\t\t\t\t\t// backwards move, using i directly is fine\n\t\t\t\t\t\t\ttargetObject.moveToIndex(diff.newIndex, targetIndex);\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconsole.warn(\"MOVE diff specified an invalid index, ignoring.\");\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcase \"REMOVE\": {\n\t\t\t\t\tif (isTargetIndexValid) {\n\t\t\t\t\t\ttargetObject.removeAt(targetIndex);\n\t\t\t\t\t\treturn true;\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconsole.warn(\"REMOVE diff specified an invalid index, ignoring.\");\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new TypeError(\"Unsupported diff type for Array Tree Node\");\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (typeof targetObject === \"object\" && targetObject !== null) {\n\t\t\tswitch (diff.type) {\n\t\t\t\tcase \"CHANGE\":\n\t\t\t\tcase \"CREATE\": {\n\t\t\t\t\ttargetObject[diff.path[diff.path.length - 1] as string] = diff.value;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\tcase \"REMOVE\": {\n\t\t\t\t\t// We can't use the delete keyword on a tree node.\n\t\t\t\t\ttargetObject[diff.path[diff.path.length - 1] as string] = undefined;\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new TypeError(\"Unsupported diff type for Object Tree Node\");\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthrow new TypeError(\"Unsupported object type for diff application\");\n\t\t}\n\t}\n}\n\n/**\n * Returns the target object that the given diff should be applied to.\n */\nfunction getTargetObjectFromPath(\n\tpath: ObjectPath,\n\tobject: Record<string, unknown> | TreeArrayNode,\n): unknown {\n\tlet targetObject: unknown = object;\n\tif (path.length > 1) {\n\t\ttargetObject = sharedTreeTraverse(object, path.slice(0, -1));\n\t}\n\treturn targetObject;\n}\n"]}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Represents a path through a tree of objects.
|
|
7
|
+
* number values represent array indices whereas string values represent object keys.
|
|
8
|
+
*
|
|
9
|
+
* @alpha
|
|
10
|
+
*/
|
|
11
|
+
export type ObjectPath = (string | number)[];
|
|
12
|
+
/**
|
|
13
|
+
* Represents a create operation between two branches of a tree.
|
|
14
|
+
* Meaning that an attribute (a shared tree node) was identified as being created.
|
|
15
|
+
*
|
|
16
|
+
* @alpha
|
|
17
|
+
*/
|
|
18
|
+
export interface DifferenceCreate {
|
|
19
|
+
type: "CREATE";
|
|
20
|
+
path: ObjectPath;
|
|
21
|
+
value: unknown;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Represents a remove operation between two branches of a tree.
|
|
25
|
+
* Meaning that an attribute (a shared tree node) was identified as being deleted.
|
|
26
|
+
* When using object ids, removes are idenitified by an object with a given id no longer existing.
|
|
27
|
+
*
|
|
28
|
+
* @alpha
|
|
29
|
+
*/
|
|
30
|
+
export interface DifferenceRemove {
|
|
31
|
+
type: "REMOVE";
|
|
32
|
+
path: ObjectPath;
|
|
33
|
+
oldValue: unknown;
|
|
34
|
+
objectId?: string | number | undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Represents a change operation between two branches of a tree.
|
|
38
|
+
* Meaning that an attribute (a shared tree node) was identified as being changed from one value to another.
|
|
39
|
+
*
|
|
40
|
+
* @alpha
|
|
41
|
+
*/
|
|
42
|
+
export interface DifferenceChange {
|
|
43
|
+
type: "CHANGE";
|
|
44
|
+
path: ObjectPath;
|
|
45
|
+
value: unknown;
|
|
46
|
+
oldValue: unknown;
|
|
47
|
+
objectId?: string | number | undefined;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Represents a move operation between two branches of a tree.
|
|
51
|
+
* Meaning that an object (shared tree node) was identified as being moved from one index to another based on its unique id.
|
|
52
|
+
*
|
|
53
|
+
* @alpha
|
|
54
|
+
*/
|
|
55
|
+
export interface DifferenceMove {
|
|
56
|
+
type: "MOVE";
|
|
57
|
+
path: ObjectPath;
|
|
58
|
+
newIndex: number;
|
|
59
|
+
value: unknown;
|
|
60
|
+
objectId?: string | number | undefined;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Union for all possible difference types.
|
|
64
|
+
*
|
|
65
|
+
* @alpha
|
|
66
|
+
*/
|
|
67
|
+
export type Difference = DifferenceCreate | DifferenceRemove | DifferenceChange | DifferenceMove;
|
|
68
|
+
/**
|
|
69
|
+
* Options for tree diffing.
|
|
70
|
+
* @alpha
|
|
71
|
+
*/
|
|
72
|
+
export interface Options {
|
|
73
|
+
cyclesFix: boolean;
|
|
74
|
+
useObjectIds?: {
|
|
75
|
+
idAttributeName: string;
|
|
76
|
+
} | undefined;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Compares two objects and returns an array of differences between them.
|
|
80
|
+
*
|
|
81
|
+
* @alpha
|
|
82
|
+
*/
|
|
83
|
+
export declare function sharedTreeDiff(obj: Record<string, unknown> | unknown[], newObj: Record<string, unknown> | unknown[], options?: Options, _stack?: (Record<string, unknown> | unknown[])[]): Difference[];
|
|
84
|
+
/**
|
|
85
|
+
* Creates a set of mergeable diffs from a series of diffs produced by {@link sharedTreeDiff}
|
|
86
|
+
* that are using the object ID strategy. These diffs don't need any modifications to be applied to the old object.
|
|
87
|
+
*
|
|
88
|
+
* @alpha
|
|
89
|
+
*/
|
|
90
|
+
export declare function createMergableIdDiffSeries(oldObject: unknown, diffs: Difference[], idAttributeName: string | number): Difference[];
|
|
91
|
+
/**
|
|
92
|
+
* Creates a set of mergeable diffs from a series of diffs produced by {@link sharedTreeDiff}
|
|
93
|
+
* that AREN'T using the object ID strategy. These diffs don't need any modifications to be applied to the old object.
|
|
94
|
+
*
|
|
95
|
+
* @alpha
|
|
96
|
+
*/
|
|
97
|
+
export declare function createMergableDiffSeries(diffs: Difference[]): Difference[];
|
|
98
|
+
/**
|
|
99
|
+
* Determines if a given difference is on an array.
|
|
100
|
+
*/
|
|
101
|
+
export declare function isDiffOnArray(diff: Difference): boolean;
|
|
102
|
+
//# sourceMappingURL=sharedTreeDiff.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sharedTreeDiff.d.ts","sourceRoot":"","sources":["../../src/implicit-strategy/sharedTreeDiff.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;AAE7C;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,UAAU,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;CACf;AAED;;;;;;GAMG;AACH,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACvC;AAED;;;;;GAKG;AACH,MAAM,WAAW,gBAAg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