@fluidframework/tree-agent 2.72.0 → 2.74.0-365691
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/CHANGELOG.md +4 -0
- package/api-report/tree-agent.alpha.api.md +89 -20
- package/dist/agent.d.ts +5 -31
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +21 -38
- package/dist/agent.js.map +1 -1
- package/dist/alpha.d.ts +12 -3
- package/dist/api.d.ts +38 -20
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/dist/methodBinding.d.ts +1 -3
- package/dist/methodBinding.d.ts.map +1 -1
- package/dist/methodBinding.js.map +1 -1
- package/dist/prompt.d.ts +2 -2
- package/dist/prompt.d.ts.map +1 -1
- package/dist/prompt.js +4 -4
- package/dist/prompt.js.map +1 -1
- package/dist/propertyBinding.d.ts +106 -0
- package/dist/propertyBinding.d.ts.map +1 -0
- package/dist/propertyBinding.js +64 -0
- package/dist/propertyBinding.js.map +1 -0
- package/dist/subtree.d.ts +8 -9
- package/dist/subtree.d.ts.map +1 -1
- package/dist/subtree.js +21 -21
- package/dist/subtree.js.map +1 -1
- package/dist/typeGeneration.d.ts.map +1 -1
- package/dist/typeGeneration.js +78 -21
- package/dist/typeGeneration.js.map +1 -1
- package/dist/utils.d.ts +1 -7
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +19 -5
- package/dist/utils.js.map +1 -1
- package/lib/agent.d.ts +5 -31
- package/lib/agent.d.ts.map +1 -1
- package/lib/agent.js +19 -35
- package/lib/agent.js.map +1 -1
- package/lib/alpha.d.ts +12 -3
- package/lib/api.d.ts +38 -20
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js.map +1 -1
- package/lib/index.d.ts +4 -3
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/methodBinding.d.ts +1 -3
- package/lib/methodBinding.d.ts.map +1 -1
- package/lib/methodBinding.js.map +1 -1
- package/lib/prompt.d.ts +2 -2
- package/lib/prompt.d.ts.map +1 -1
- package/lib/prompt.js +4 -4
- package/lib/prompt.js.map +1 -1
- package/lib/propertyBinding.d.ts +106 -0
- package/lib/propertyBinding.d.ts.map +1 -0
- package/lib/propertyBinding.js +59 -0
- package/lib/propertyBinding.js.map +1 -0
- package/lib/subtree.d.ts +8 -9
- package/lib/subtree.d.ts.map +1 -1
- package/lib/subtree.js +21 -21
- package/lib/subtree.js.map +1 -1
- package/lib/typeGeneration.d.ts.map +1 -1
- package/lib/typeGeneration.js +78 -21
- package/lib/typeGeneration.js.map +1 -1
- package/lib/utils.d.ts +1 -7
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +19 -5
- package/lib/utils.js.map +1 -1
- package/package.json +10 -10
- package/src/agent.ts +29 -69
- package/src/api.ts +56 -29
- package/src/index.ts +16 -4
- package/src/methodBinding.ts +2 -2
- package/src/prompt.ts +6 -6
- package/src/propertyBinding.ts +182 -0
- package/src/subtree.ts +26 -29
- package/src/typeGeneration.ts +90 -24
- package/src/utils.ts +23 -17
package/dist/subtree.d.ts
CHANGED
|
@@ -2,20 +2,19 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
import type { TreeView } from "./utils.js";
|
|
5
|
+
import type { ImplicitFieldSchema, TreeFieldFromImplicitField } from "@fluidframework/tree";
|
|
6
|
+
import type { ReadableField, TreeBranchAlpha } from "@fluidframework/tree/alpha";
|
|
7
|
+
import type { ViewOrTree } from "./api.js";
|
|
9
8
|
/**
|
|
10
9
|
* Wraps either a {@link TreeView} or a {@link TreeNode} and provides a common interface over them.
|
|
11
10
|
*/
|
|
12
|
-
export declare class Subtree<TRoot extends ImplicitFieldSchema
|
|
13
|
-
|
|
14
|
-
constructor(
|
|
11
|
+
export declare class Subtree<TRoot extends ImplicitFieldSchema> {
|
|
12
|
+
readonly viewOrTree: ViewOrTree<TRoot>;
|
|
13
|
+
constructor(viewOrTree: ViewOrTree<TRoot>);
|
|
15
14
|
get branch(): TreeBranchAlpha;
|
|
16
15
|
get field(): ReadableField<TRoot>;
|
|
17
|
-
set field(value: TreeFieldFromImplicitField<
|
|
18
|
-
get schema():
|
|
16
|
+
set field(value: TreeFieldFromImplicitField<TRoot>);
|
|
17
|
+
get schema(): TRoot;
|
|
19
18
|
fork(): Subtree<TRoot>;
|
|
20
19
|
}
|
|
21
20
|
//# sourceMappingURL=subtree.d.ts.map
|
package/dist/subtree.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subtree.d.ts","sourceRoot":"","sources":["../src/subtree.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"subtree.d.ts","sourceRoot":"","sources":["../src/subtree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EACX,mBAAmB,EACnB,0BAA0B,EAG1B,MAAM,sBAAsB,CAAC;AAE9B,OAAO,KAAK,EACX,aAAa,EAEb,eAAe,EACf,MAAM,4BAA4B,CAAC;AAGpC,OAAO,KAAK,EAAY,UAAU,EAAE,MAAM,UAAU,CAAC;AAErD;;GAEG;AACH,qBAAa,OAAO,CAAC,KAAK,SAAS,mBAAmB;aAClB,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC;gBAA7B,UAAU,EAAE,UAAU,CAAC,KAAK,CAAC;IAMhE,IAAW,MAAM,IAAI,eAAe,CAInC;IAED,IAAW,KAAK,IAAI,aAAa,CAAC,KAAK,CAAC,CAEvC;IAED,IAAW,KAAK,CAAC,KAAK,EAAE,0BAA0B,CAAC,KAAK,CAAC,EAsDxD;IAED,IAAW,MAAM,IAAI,KAAK,CAMzB;IAEM,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC;CAY7B"}
|
package/dist/subtree.js
CHANGED
|
@@ -14,23 +14,23 @@ const getNodeOnBranch_js_1 = require("./getNodeOnBranch.js");
|
|
|
14
14
|
* Wraps either a {@link TreeView} or a {@link TreeNode} and provides a common interface over them.
|
|
15
15
|
*/
|
|
16
16
|
class Subtree {
|
|
17
|
-
constructor(
|
|
18
|
-
this.
|
|
19
|
-
if (
|
|
17
|
+
constructor(viewOrTree) {
|
|
18
|
+
this.viewOrTree = viewOrTree;
|
|
19
|
+
if (viewOrTree instanceof tree_1.TreeNode && alpha_1.TreeAlpha.branch(viewOrTree) === undefined) {
|
|
20
20
|
throw new internal_2.UsageError("The provided node must belong to a branch.");
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
get branch() {
|
|
24
|
-
return this.
|
|
25
|
-
? (alpha_1.TreeAlpha.branch(this.
|
|
26
|
-
: this.
|
|
24
|
+
return this.viewOrTree instanceof tree_1.TreeNode
|
|
25
|
+
? (alpha_1.TreeAlpha.branch(this.viewOrTree) ?? (0, internal_1.fail)("Node cannot be raw."))
|
|
26
|
+
: this.viewOrTree;
|
|
27
27
|
}
|
|
28
28
|
get field() {
|
|
29
|
-
return this.
|
|
29
|
+
return this.viewOrTree instanceof tree_1.TreeNode ? this.viewOrTree : this.viewOrTree.root;
|
|
30
30
|
}
|
|
31
31
|
set field(value) {
|
|
32
|
-
if (this.
|
|
33
|
-
const parent = tree_1.Tree.parent(this.
|
|
32
|
+
if (this.viewOrTree instanceof tree_1.TreeNode) {
|
|
33
|
+
const parent = tree_1.Tree.parent(this.viewOrTree);
|
|
34
34
|
if (parent === undefined) {
|
|
35
35
|
// In general, this is not a correct cast, but we know that the root of the branch at least allows the type of `value`
|
|
36
36
|
const view = this.branch;
|
|
@@ -40,12 +40,12 @@ class Subtree {
|
|
|
40
40
|
const schema = tree_1.Tree.schema(parent);
|
|
41
41
|
switch (schema.kind) {
|
|
42
42
|
case tree_1.NodeKind.Object: {
|
|
43
|
-
const key = tree_1.Tree.key(this.
|
|
43
|
+
const key = tree_1.Tree.key(this.viewOrTree);
|
|
44
44
|
parent[key] = value;
|
|
45
45
|
break;
|
|
46
46
|
}
|
|
47
47
|
case tree_1.NodeKind.Record: {
|
|
48
|
-
const key = tree_1.Tree.key(this.
|
|
48
|
+
const key = tree_1.Tree.key(this.viewOrTree);
|
|
49
49
|
if (value === undefined) {
|
|
50
50
|
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
51
51
|
delete parent[key];
|
|
@@ -56,7 +56,7 @@ class Subtree {
|
|
|
56
56
|
break;
|
|
57
57
|
}
|
|
58
58
|
case tree_1.NodeKind.Map: {
|
|
59
|
-
const key = tree_1.Tree.key(this.
|
|
59
|
+
const key = tree_1.Tree.key(this.viewOrTree);
|
|
60
60
|
if (value === undefined) {
|
|
61
61
|
parent.delete(key);
|
|
62
62
|
}
|
|
@@ -66,7 +66,7 @@ class Subtree {
|
|
|
66
66
|
break;
|
|
67
67
|
}
|
|
68
68
|
case tree_1.NodeKind.Array: {
|
|
69
|
-
const index = tree_1.Tree.key(this.
|
|
69
|
+
const index = tree_1.Tree.key(this.viewOrTree);
|
|
70
70
|
const arrayNode = parent;
|
|
71
71
|
if (value === undefined) {
|
|
72
72
|
arrayNode.removeAt(index);
|
|
@@ -85,23 +85,23 @@ class Subtree {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
else {
|
|
88
|
-
this.
|
|
88
|
+
this.viewOrTree.root = value;
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
get schema() {
|
|
92
|
-
return this.
|
|
93
|
-
? tree_1.Tree.schema(this.
|
|
94
|
-
: this.
|
|
92
|
+
return (this.viewOrTree instanceof tree_1.TreeNode
|
|
93
|
+
? tree_1.Tree.schema(this.viewOrTree)
|
|
94
|
+
: this.viewOrTree.schema);
|
|
95
95
|
}
|
|
96
96
|
fork() {
|
|
97
|
-
if (this.
|
|
98
|
-
const branch = alpha_1.TreeAlpha.branch(this.
|
|
99
|
-
const node = (0, getNodeOnBranch_js_1.getNodeOnBranch)(this.
|
|
97
|
+
if (this.viewOrTree instanceof tree_1.TreeNode) {
|
|
98
|
+
const branch = alpha_1.TreeAlpha.branch(this.viewOrTree) ?? (0, internal_1.fail)("Node cannot be raw.");
|
|
99
|
+
const node = (0, getNodeOnBranch_js_1.getNodeOnBranch)(this.viewOrTree, branch.fork()) ??
|
|
100
100
|
(0, internal_1.fail)("Expected node to be on new fork.");
|
|
101
101
|
return new Subtree(node);
|
|
102
102
|
}
|
|
103
103
|
else {
|
|
104
|
-
return new Subtree(this.
|
|
104
|
+
return new Subtree(this.viewOrTree.fork());
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
}
|
package/dist/subtree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subtree.js","sourceRoot":"","sources":["../src/subtree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA2D;AAC3D,uEAAsE;AACtE,+CAAgE;
|
|
1
|
+
{"version":3,"file":"subtree.js","sourceRoot":"","sources":["../src/subtree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA2D;AAC3D,uEAAsE;AACtE,+CAAgE;AAOhE,sDAAuD;AAOvD,6DAAuD;AAGvD;;GAEG;AACH,MAAa,OAAO;IACnB,YAAmC,UAA6B;QAA7B,eAAU,GAAV,UAAU,CAAmB;QAC/D,IAAI,UAAU,YAAY,eAAQ,IAAI,iBAAS,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,SAAS,EAAE,CAAC;YAClF,MAAM,IAAI,qBAAU,CAAC,4CAA4C,CAAC,CAAC;QACpE,CAAC;IACF,CAAC;IAED,IAAW,MAAM;QAChB,OAAO,IAAI,CAAC,UAAU,YAAY,eAAQ;YACzC,CAAC,CAAC,CAAC,iBAAS,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,I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YAC9B,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAChB,CAAC;IACZ,CAAC;IAEM,IAAI;QACV,IAAI,IAAI,CAAC,UAAU,YAAY,eAAQ,EAAE,CAAC;YACzC,MAAM,MAAM,GAAG,iBAAS,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAA,eAAI,EAAC,qBAAqB,CAAC,CAAC;YAChF,MAAM,IAAI,GACT,IAAA,oCAAe,EAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;gBAC/C,IAAA,eAAI,EAAC,kCAAkC,CAAC,CAAC;YAE1C,OAAO,IAAI,OAAO,CAAQ,IAAI,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACP,OAAO,IAAI,OAAO,CAAQ,IAAI,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;QACnD,CAAC;IACF,CAAC;CACD;AA7FD,0BA6FC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { fail } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { TreeNode, Tree, NodeKind } from \"@fluidframework/tree\";\nimport type {\n\tImplicitFieldSchema,\n\tTreeFieldFromImplicitField,\n\tTreeMapNode,\n\tTreeArrayNode,\n} from \"@fluidframework/tree\";\nimport { TreeAlpha } from \"@fluidframework/tree/alpha\";\nimport type {\n\tReadableField,\n\tTreeRecordNode,\n\tTreeBranchAlpha,\n} from \"@fluidframework/tree/alpha\";\n\nimport { getNodeOnBranch } from \"./getNodeOnBranch.js\";\nimport type { TreeView, ViewOrTree } from \"./api.js\";\n\n/**\n * Wraps either a {@link TreeView} or a {@link TreeNode} and provides a common interface over them.\n */\nexport class Subtree<TRoot extends ImplicitFieldSchema> {\n\tpublic constructor(public readonly viewOrTree: ViewOrTree<TRoot>) {\n\t\tif (viewOrTree instanceof TreeNode && TreeAlpha.branch(viewOrTree) === undefined) {\n\t\t\tthrow new UsageError(\"The provided node must belong to a branch.\");\n\t\t}\n\t}\n\n\tpublic get branch(): TreeBranchAlpha {\n\t\treturn this.viewOrTree instanceof TreeNode\n\t\t\t? (TreeAlpha.branch(this.viewOrTree) ?? fail(\"Node cannot be raw.\"))\n\t\t\t: this.viewOrTree;\n\t}\n\n\tpublic get field(): ReadableField<TRoot> {\n\t\treturn this.viewOrTree instanceof TreeNode ? this.viewOrTree : this.viewOrTree.root;\n\t}\n\n\tpublic set field(value: TreeFieldFromImplicitField<TRoot>) {\n\t\tif (this.viewOrTree instanceof TreeNode) {\n\t\t\tconst parent = Tree.parent(this.viewOrTree);\n\t\t\tif (parent === undefined) {\n\t\t\t\t// In general, this is not a correct cast, but we know that the root of the branch at least allows the type of `value`\n\t\t\t\tconst view = this.branch as TreeView<TRoot>;\n\t\t\t\tview.root = value;\n\t\t\t} else {\n\t\t\t\tconst schema = Tree.schema(parent);\n\t\t\t\tswitch (schema.kind) {\n\t\t\t\t\tcase NodeKind.Object: {\n\t\t\t\t\t\tconst key = Tree.key(this.viewOrTree) as string;\n\t\t\t\t\t\t(parent as unknown as Record<string, unknown>)[key] = value;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase NodeKind.Record: {\n\t\t\t\t\t\tconst key = Tree.key(this.viewOrTree) as string;\n\t\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-dynamic-delete\n\t\t\t\t\t\t\tdelete (parent as TreeRecordNode)[key];\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t(parent as TreeRecordNode)[key] = value;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase NodeKind.Map: {\n\t\t\t\t\t\tconst key = Tree.key(this.viewOrTree) as string;\n\t\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\t\t(parent as TreeMapNode).delete(key);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t(parent as TreeMapNode).set(key, value as never);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase NodeKind.Array: {\n\t\t\t\t\t\tconst index = Tree.key(this.viewOrTree) as number;\n\t\t\t\t\t\tconst arrayNode = parent as TreeArrayNode;\n\t\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\t\tarrayNode.removeAt(index);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tthis.branch.runTransaction(() => {\n\t\t\t\t\t\t\t\tarrayNode.removeAt(index);\n\t\t\t\t\t\t\t\tarrayNode.insertAt(index, value as never);\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tfail(\"Unexpected node kind\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tthis.viewOrTree.root = value;\n\t\t}\n\t}\n\n\tpublic get schema(): TRoot {\n\t\treturn (\n\t\t\tthis.viewOrTree instanceof TreeNode\n\t\t\t\t? Tree.schema(this.viewOrTree)\n\t\t\t\t: this.viewOrTree.schema\n\t\t) as TRoot;\n\t}\n\n\tpublic fork(): Subtree<TRoot> {\n\t\tif (this.viewOrTree instanceof TreeNode) {\n\t\t\tconst branch = TreeAlpha.branch(this.viewOrTree) ?? fail(\"Node cannot be raw.\");\n\t\t\tconst node =\n\t\t\t\tgetNodeOnBranch(this.viewOrTree, branch.fork()) ??\n\t\t\t\tfail(\"Expected node to be on new fork.\");\n\n\t\t\treturn new Subtree<TRoot>(node);\n\t\t} else {\n\t\t\treturn new Subtree<TRoot>(this.viewOrTree.fork());\n\t\t}\n\t}\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeGeneration.d.ts","sourceRoot":"","sources":["../src/typeGeneration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH,OAAO,KAAK,EACX,mBAAmB,EAGnB,gBAAgB,EAEhB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAK,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"typeGeneration.d.ts","sourceRoot":"","sources":["../src/typeGeneration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAeH,OAAO,KAAK,EACX,mBAAmB,EAGnB,gBAAgB,EAEhB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAK,KAAK,UAAU,EAAE,MAAM,KAAK,CAAC;AAkCzC;;GAEG;AACH,wBAAgB,0BAA0B,CACzC,UAAU,EAAE,mBAAmB,EAC/B,MAAM,EAAE,gBAAgB,GACtB;IACF,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;CACxC,CAqCA"}
|
package/dist/typeGeneration.js
CHANGED
|
@@ -10,6 +10,7 @@ const internal_2 = require("@fluidframework/telemetry-utils/internal");
|
|
|
10
10
|
const internal_3 = require("@fluidframework/tree/internal");
|
|
11
11
|
const zod_1 = require("zod");
|
|
12
12
|
const methodBinding_js_1 = require("./methodBinding.js");
|
|
13
|
+
const propertyBinding_js_1 = require("./propertyBinding.js");
|
|
13
14
|
const utils_js_1 = require("./utils.js");
|
|
14
15
|
/**
|
|
15
16
|
*
|
|
@@ -45,6 +46,11 @@ function generateEditTypesForPrompt(rootSchema, schema) {
|
|
|
45
46
|
allSchemas.add(t);
|
|
46
47
|
objectTypeSchemas.add(t);
|
|
47
48
|
}
|
|
49
|
+
const exposedProperties = (0, propertyBinding_js_1.getExposedProperties)(n);
|
|
50
|
+
for (const t of exposedProperties.referencedTypes) {
|
|
51
|
+
allSchemas.add(t);
|
|
52
|
+
objectTypeSchemas.add(t);
|
|
53
|
+
}
|
|
48
54
|
}
|
|
49
55
|
},
|
|
50
56
|
});
|
|
@@ -74,36 +80,86 @@ function generateEditTypes(schemas, objectCache, bindableSchemas) {
|
|
|
74
80
|
domainTypes,
|
|
75
81
|
};
|
|
76
82
|
}
|
|
77
|
-
function
|
|
78
|
-
const
|
|
83
|
+
function getBoundMembersForBindable(bindableSchema) {
|
|
84
|
+
const memberTypes = [];
|
|
79
85
|
const methods = (0, methodBinding_js_1.getExposedMethods)(bindableSchema);
|
|
80
86
|
for (const [name, method] of Object.entries(methods.methods)) {
|
|
81
87
|
const zodFunction = zod_1.z.instanceof(methodBinding_js_1.FunctionWrapper);
|
|
82
88
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
|
83
89
|
zodFunction.method = method;
|
|
84
|
-
|
|
90
|
+
memberTypes.push([name, zodFunction]);
|
|
91
|
+
}
|
|
92
|
+
const props = (0, propertyBinding_js_1.getExposedProperties)(bindableSchema);
|
|
93
|
+
for (const [name, prop] of Object.entries(props.properties)) {
|
|
94
|
+
const schema = prop.schema;
|
|
95
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any
|
|
96
|
+
schema.property = prop;
|
|
97
|
+
memberTypes.push([name, prop.schema]);
|
|
85
98
|
}
|
|
86
|
-
return {
|
|
99
|
+
return {
|
|
100
|
+
members: memberTypes,
|
|
101
|
+
referencedTypes: new Set([...props.referencedTypes, ...methods.referencedTypes]),
|
|
102
|
+
};
|
|
87
103
|
}
|
|
88
|
-
function
|
|
89
|
-
const bindableSchema = bindableSchemas.get(definition) ?? (0, utils_js_1.fail)("
|
|
90
|
-
return
|
|
104
|
+
function getBoundMembers(definition, bindableSchemas) {
|
|
105
|
+
const bindableSchema = bindableSchemas.get(definition) ?? (0, utils_js_1.fail)("unknown definition");
|
|
106
|
+
return getBoundMembersForBindable(bindableSchema).members;
|
|
91
107
|
}
|
|
92
108
|
function addBindingIntersectionIfNeeded(typeString, zodTypeBound, definition, simpleNodeSchema, bindableSchemas) {
|
|
93
109
|
let zodType = zodTypeBound;
|
|
94
110
|
let description = simpleNodeSchema.metadata?.description ?? "";
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
111
|
+
const boundMembers = getBoundMembers(definition, bindableSchemas);
|
|
112
|
+
const methods = {};
|
|
113
|
+
const properties = {};
|
|
114
|
+
let hasProperties = false;
|
|
115
|
+
let hasMethods = false;
|
|
116
|
+
if (boundMembers.length > 0) {
|
|
117
|
+
for (const [name, zodMember] of boundMembers) {
|
|
118
|
+
const kind =
|
|
119
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
|
|
120
|
+
zodMember.method === undefined
|
|
121
|
+
? // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
|
|
122
|
+
zodMember.property === undefined
|
|
123
|
+
? "Unknown"
|
|
124
|
+
: "Property"
|
|
125
|
+
: "Method";
|
|
126
|
+
if (kind === "Unknown") {
|
|
127
|
+
throw new internal_2.UsageError(`Unrecognized bound member ${name} in schema ${definition}`);
|
|
128
|
+
}
|
|
129
|
+
if (kind === "Method") {
|
|
130
|
+
if (methods[name] !== undefined) {
|
|
131
|
+
throw new internal_2.UsageError(`${kind} ${name} conflicts with field of the same name in schema ${definition}`);
|
|
132
|
+
}
|
|
133
|
+
methods[name] = zodMember;
|
|
101
134
|
}
|
|
102
|
-
|
|
135
|
+
if (kind === "Property") {
|
|
136
|
+
if (properties[name] !== undefined) {
|
|
137
|
+
throw new internal_2.UsageError(`${kind} ${name} conflicts with field of the same name in schema ${definition}`);
|
|
138
|
+
}
|
|
139
|
+
properties[name] = zodMember;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
hasMethods = Object.keys(methods).length > 0 ? true : false;
|
|
143
|
+
hasProperties = Object.keys(properties).length > 0 ? true : false;
|
|
144
|
+
if (hasMethods) {
|
|
145
|
+
zodType = zod_1.z.intersection(zodType, zod_1.z.object(methods));
|
|
146
|
+
}
|
|
147
|
+
if (hasProperties) {
|
|
148
|
+
zodType = zod_1.z.intersection(zodType, zod_1.z.object(properties));
|
|
103
149
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
150
|
+
}
|
|
151
|
+
let note = "";
|
|
152
|
+
if (hasMethods && hasProperties) {
|
|
153
|
+
note = `Note: this ${typeString} has custom user-defined methods and properties directly on it.`;
|
|
154
|
+
}
|
|
155
|
+
else if (hasMethods) {
|
|
156
|
+
note = `Note: this ${typeString} has custom user-defined methods directly on it.`;
|
|
157
|
+
}
|
|
158
|
+
else if (hasProperties) {
|
|
159
|
+
note = `Note: this ${typeString} has custom user-defined properties directly on it.`;
|
|
160
|
+
}
|
|
161
|
+
if (note !== "") {
|
|
162
|
+
description = description === "" ? note : `${description} - ${note}`;
|
|
107
163
|
}
|
|
108
164
|
return zodType.describe(description);
|
|
109
165
|
}
|
|
@@ -124,12 +180,13 @@ function getOrCreateType(definitionMap, definition, objectCache, bindableSchemas
|
|
|
124
180
|
];
|
|
125
181
|
})
|
|
126
182
|
.filter(([, value]) => value !== undefined));
|
|
127
|
-
|
|
128
|
-
|
|
183
|
+
for (const [name, zodMember] of getBoundMembers(definition, bindableSchemas)) {
|
|
184
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access
|
|
185
|
+
const kind = zodMember.method === undefined ? "Property" : "Method";
|
|
129
186
|
if (properties[name] !== undefined) {
|
|
130
|
-
throw new internal_2.UsageError(
|
|
187
|
+
throw new internal_2.UsageError(`${kind} ${name} conflicts with field of the same name in schema ${definition}`);
|
|
131
188
|
}
|
|
132
|
-
properties[name] =
|
|
189
|
+
properties[name] = zodMember;
|
|
133
190
|
}
|
|
134
191
|
return (type = zod_1.z
|
|
135
192
|
.object(properties)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typeGeneration.js","sourceRoot":"","sources":["../src/typeGeneration.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA8E;AAC9E,uEAAsE;AACtE,4DAUuC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AAC;IAC7C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG;YACb,GAAG,IAAA,sBAAW,EAAC,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE;gBACrC,OAAO,eAAe,CAAC,aAAa,EAAE,IAAI,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC;YAC3E,CAAC,CAAC;SACF,CAAC;QACF,IAAA,iBAAM,EAAC,IAAA,wBAAa,EAAC,KAAK,CAAC,EAAE,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACtE,OAAO,OAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;SAAM,CAAC;QACP,OAAO,eAAe,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC;IAC7E,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport {\n\tArrayNodeSchema,\n\tFieldKind,\n\tgetSimpleSchema,\n\tMapNodeSchema,\n\tNodeKind,\n\tObjectNodeSchema,\n\tRecordNodeSchema,\n\tValueSchema,\n\twalkFieldSchema,\n} from \"@fluidframework/tree/internal\";\nimport type {\n\tImplicitFieldSchema,\n\tSimpleFieldSchema,\n\tSimpleNodeSchema,\n\tSimpleTreeSchema,\n\tTreeNodeSchema,\n} from \"@fluidframework/tree/internal\";\nimport { z, type ZodTypeAny } from \"zod\";\n\nimport type { BindableSchema } from \"./methodBinding.js\";\nimport { FunctionWrapper, getExposedMethods } from \"./methodBinding.js\";\nimport {\n\tfail,\n\tgetOrCreate,\n\thasAtLeastTwo,\n\tllmDefault,\n\tmapIterable,\n\ttryGetSingleton,\n\ttype MapGetSet,\n} from \"./utils.js\";\n\n/**\n *\n * TODO: Add a prompt suggestion API!\n *\n * TODO: Handle rate limit errors.\n *\n * TODO: Pass descriptions from schema metadata to the generated TS types that we put in the prompt\n *\n * TODO make the Ids be \"Vector-2\" instead of \"Vector2\" (or else it gets weird when you have a type called \"Vector2\")\n */\n\n/**\n * Cache used to prevent repeatedly generating the same Zod validation objects for the same {@link SimpleTreeSchema} as generate propts for repeated calls to an LLM\n */\nconst promptSchemaCache = new WeakMap<\n\tSimpleTreeSchema,\n\tReturnType<typeof generateEditTypes>\n>();\n\n/**\n * TODO\n */\nexport function generateEditTypesForPrompt(\n\trootSchema: ImplicitFieldSchema,\n\tschema: SimpleTreeSchema,\n): {\n\tdomainTypes: Record<string, ZodTypeAny>;\n} {\n\treturn getOrCreate(promptSchemaCache, schema, () => {\n\t\tconst allSchemas = new Set<TreeNodeSchema>();\n\t\tconst objectTypeSchemas = new Set<TreeNodeSchema>();\n\t\twalkFieldSchema(rootSchema, {\n\t\t\tnode: (n) => {\n\t\t\t\tallSchemas.add(n);\n\t\t\t\tif (\n\t\t\t\t\tn instanceof ObjectNodeSchema ||\n\t\t\t\t\tn instanceof MapNodeSchema ||\n\t\t\t\t\tn instanceof ArrayNodeSchema ||\n\t\t\t\t\tn instanceof RecordNodeSchema\n\t\t\t\t) {\n\t\t\t\t\tobjectTypeSchemas.add(n);\n\t\t\t\t\tconst exposedMethods = getExposedMethods(n);\n\t\t\t\t\tfor (const t of exposedMethods.referencedTypes) {\n\t\t\t\t\t\tallSchemas.add(t);\n\t\t\t\t\t\tobjectTypeSchemas.add(t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t\tconst nodeSchemas = [...objectTypeSchemas.values()] as BindableSchema[];\n\t\tconst bindableSchemas = new Map<string, BindableSchema>(\n\t\t\tnodeSchemas.map((nodeSchema) => [nodeSchema.identifier, nodeSchema]),\n\t\t);\n\t\treturn generateEditTypes(\n\t\t\t[...allSchemas.values()].map((s) => getSimpleSchema(s)),\n\t\t\tnew Map(),\n\t\t\tbindableSchemas,\n\t\t);\n\t});\n}\n\n/**\n * Generates a set of ZOD validation objects for the various types of data that can be put into the provided {@link SimpleTreeSchema}\n * and then uses those sets to generate an all-encompassing ZOD object for each type of {@link TreeEdit} that can validate any of the types of data that can be put into the tree.\n *\n * @returns a Record of schema names to Zod validation objects, and the name of the root schema used to encompass all of the other schemas.\n *\n * @remarks The return type of this function is designed to work with Typechat's createZodJsonValidator as well as be used as the JSON schema for OpenAi's structured output response format.\n */\nfunction generateEditTypes(\n\tschemas: Iterable<SimpleTreeSchema>,\n\tobjectCache: MapGetSet<SimpleNodeSchema, ZodTypeAny>,\n\tbindableSchemas: Map<string, BindableSchema>,\n): {\n\tdomainTypes: Record<string, ZodTypeAny>;\n} {\n\tconst domainTypes: Record<string, ZodTypeAny> = {};\n\tfor (const schema of schemas) {\n\t\tfor (const name of schema.definitions.keys()) {\n\t\t\t// If this does overwrite anything in domainTypes, it is guaranteed to be overwritten with an identical value due to the getOrCreate\n\t\t\tdomainTypes[name] = getOrCreateType(\n\t\t\t\tschema.definitions,\n\t\t\t\tname,\n\t\t\t\tobjectCache,\n\t\t\t\tbindableSchemas,\n\t\t\t);\n\t\t}\n\t}\n\n\treturn {\n\t\tdomainTypes,\n\t};\n}\n\nfunction getBoundMethodsForBindable(bindableSchema: BindableSchema): {\n\treferencedTypes: Set<TreeNodeSchema>;\n\tmethods: [string, ZodTypeAny][];\n} {\n\tconst methodTypes: [string, ZodTypeAny][] = [];\n\tconst methods = getExposedMethods(bindableSchema);\n\tfor (const [name, method] of Object.entries(methods.methods)) {\n\t\tconst zodFunction = z.instanceof(FunctionWrapper);\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n\t\t(zodFunction as any).method = method;\n\t\tmethodTypes.push([name, zodFunction]);\n\t}\n\treturn { methods: methodTypes, referencedTypes: methods.referencedTypes };\n}\n\nfunction getBoundMethods(\n\tdefinition: string,\n\tbindableSchemas: Map<string, BindableSchema>,\n): [string, ZodTypeAny][] {\n\tconst bindableSchema = bindableSchemas.get(definition) ?? fail(\"Unknown definition\");\n\treturn getBoundMethodsForBindable(bindableSchema).methods;\n}\n\nfunction addBindingIntersectionIfNeeded(\n\ttypeString: \"array\" | \"map\" | \"record\",\n\tzodTypeBound: ZodTypeAny,\n\tdefinition: string,\n\tsimpleNodeSchema: SimpleNodeSchema,\n\tbindableSchemas: Map<string, BindableSchema>,\n): ZodTypeAny {\n\tlet zodType = zodTypeBound;\n\tlet description = simpleNodeSchema.metadata?.description ?? \"\";\n\tconst boundMethods = getBoundMethods(definition, bindableSchemas);\n\tif (boundMethods.length > 0) {\n\t\tconst methods: Record<string, z.ZodTypeAny> = {};\n\t\tfor (const [name, zodFunction] of boundMethods) {\n\t\t\tif (methods[name] !== undefined) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Method ${name} conflicts with field of the same name in schema ${definition}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tmethods[name] = zodFunction;\n\t\t}\n\t\tzodType = z.intersection(zodType, z.object(methods));\n\t\tconst methodNote = `Note: this ${typeString} has custom user-defined methods directly on it.`;\n\t\tdescription = description === \"\" ? methodNote : `${description} - ${methodNote}`;\n\t}\n\treturn zodType.describe(description);\n}\n\nfunction getOrCreateType(\n\tdefinitionMap: ReadonlyMap<string, SimpleNodeSchema>,\n\tdefinition: string,\n\tobjectCache: MapGetSet<SimpleNodeSchema, ZodTypeAny>,\n\tbindableSchemas: Map<string, BindableSchema>,\n): ZodTypeAny {\n\tconst simpleNodeSchema = definitionMap.get(definition) ?? fail(\"Unexpected definition\");\n\treturn getOrCreate(objectCache, simpleNodeSchema, () => {\n\t\t// Handle recursive types: temporarily create a zod \"lazy\" type that can be referenced by a recursive call to getOrCreateType.\n\t\tlet type: ZodTypeAny | undefined;\n\t\tobjectCache.set(\n\t\t\tsimpleNodeSchema,\n\t\t\tz.lazy(() => type ?? fail(\"Recursive type used before creation\")),\n\t\t);\n\t\tswitch (simpleNodeSchema.kind) {\n\t\t\tcase NodeKind.Object: {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\tconst properties: Record<string, z.ZodTypeAny> = Object.fromEntries(\n\t\t\t\t\t[...simpleNodeSchema.fields]\n\t\t\t\t\t\t.map(([key, field]) => {\n\t\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\tgetOrCreateTypeForField(definitionMap, field, objectCache, bindableSchemas),\n\t\t\t\t\t\t\t];\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.filter(([, value]) => value !== undefined),\n\t\t\t\t);\n\n\t\t\t\t// Unlike arrays/maps/records, object nodes include methods directly on them rather than using an intersection\n\t\t\t\tfor (const [name, zodFunction] of getBoundMethods(definition, bindableSchemas)) {\n\t\t\t\t\tif (properties[name] !== undefined) {\n\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t`Method ${name} conflicts with field of the same name in schema ${definition}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tproperties[name] = zodFunction;\n\t\t\t\t}\n\n\t\t\t\treturn (type = z\n\t\t\t\t\t.object(properties)\n\t\t\t\t\t.describe(simpleNodeSchema.metadata?.description ?? \"\"));\n\t\t\t}\n\t\t\tcase NodeKind.Map: {\n\t\t\t\tconst zodType = z.map(\n\t\t\t\t\tz.string(),\n\t\t\t\t\tgetTypeForAllowedTypes(\n\t\t\t\t\t\tdefinitionMap,\n\t\t\t\t\t\tnew Set(simpleNodeSchema.simpleAllowedTypes.keys()),\n\t\t\t\t\t\tobjectCache,\n\t\t\t\t\t\tbindableSchemas,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\treturn (type = addBindingIntersectionIfNeeded(\n\t\t\t\t\t\"map\",\n\t\t\t\t\tzodType,\n\t\t\t\t\tdefinition,\n\t\t\t\t\tsimpleNodeSchema,\n\t\t\t\t\tbindableSchemas,\n\t\t\t\t));\n\t\t\t}\n\t\t\tcase NodeKind.Record: {\n\t\t\t\tconst zodType = z.record(\n\t\t\t\t\tgetTypeForAllowedTypes(\n\t\t\t\t\t\tdefinitionMap,\n\t\t\t\t\t\tnew Set(simpleNodeSchema.simpleAllowedTypes.keys()),\n\t\t\t\t\t\tobjectCache,\n\t\t\t\t\t\tbindableSchemas,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\treturn (type = addBindingIntersectionIfNeeded(\n\t\t\t\t\t\"record\",\n\t\t\t\t\tzodType,\n\t\t\t\t\tdefinition,\n\t\t\t\t\tsimpleNodeSchema,\n\t\t\t\t\tbindableSchemas,\n\t\t\t\t));\n\t\t\t}\n\t\t\tcase NodeKind.Array: {\n\t\t\t\tconst zodType = z.array(\n\t\t\t\t\tgetTypeForAllowedTypes(\n\t\t\t\t\t\tdefinitionMap,\n\t\t\t\t\t\tnew Set(simpleNodeSchema.simpleAllowedTypes.keys()),\n\t\t\t\t\t\tobjectCache,\n\t\t\t\t\t\tbindableSchemas,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\treturn (type = addBindingIntersectionIfNeeded(\n\t\t\t\t\t\"array\",\n\t\t\t\t\tzodType,\n\t\t\t\t\tdefinition,\n\t\t\t\t\tsimpleNodeSchema,\n\t\t\t\t\tbindableSchemas,\n\t\t\t\t));\n\t\t\t}\n\t\t\tcase NodeKind.Leaf: {\n\t\t\t\tswitch (simpleNodeSchema.leafKind) {\n\t\t\t\t\tcase ValueSchema.Boolean: {\n\t\t\t\t\t\treturn (type = z.boolean());\n\t\t\t\t\t}\n\t\t\t\t\tcase ValueSchema.Number: {\n\t\t\t\t\t\treturn (type = z.number());\n\t\t\t\t\t}\n\t\t\t\t\tcase ValueSchema.String: {\n\t\t\t\t\t\treturn (type = z.string());\n\t\t\t\t\t}\n\t\t\t\t\tcase ValueSchema.Null: {\n\t\t\t\t\t\treturn (type = z.null());\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tthrow new Error(`Unsupported leaf kind ${NodeKind[simpleNodeSchema.leafKind]}.`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn unreachableCase(simpleNodeSchema, \"Unknown node kind\");\n\t\t\t}\n\t\t}\n\t});\n}\n\nfunction getOrCreateTypeForField(\n\tdefinitionMap: ReadonlyMap<string, SimpleNodeSchema>,\n\tfieldSchema: SimpleFieldSchema,\n\tobjectCache: MapGetSet<SimpleNodeSchema, ZodTypeAny>,\n\tbindableSchemas: Map<string, BindableSchema>,\n): ZodTypeAny {\n\tconst customMetadata = fieldSchema.metadata.custom as\n\t\t| Record<string | symbol, unknown>\n\t\t| undefined;\n\tconst getDefault = customMetadata?.[llmDefault];\n\tif (getDefault !== undefined) {\n\t\tif (typeof getDefault !== \"function\") {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Expected value of ${llmDefault.description} property to be a function, but got ${typeof getDefault}`,\n\t\t\t);\n\t\t}\n\n\t\tif (fieldSchema.kind !== FieldKind.Optional) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`The ${llmDefault.description} property is only permitted on optional fields.`,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst field = getTypeForAllowedTypes(\n\t\tdefinitionMap,\n\t\tnew Set(fieldSchema.simpleAllowedTypes.keys()),\n\t\tobjectCache,\n\t\tbindableSchemas,\n\t).describe(\n\t\tgetDefault === undefined\n\t\t\t? (fieldSchema.metadata?.description ?? \"\")\n\t\t\t: \"Do not populate this field. It will be automatically supplied by the system after insertion.\",\n\t);\n\n\tswitch (fieldSchema.kind) {\n\t\tcase FieldKind.Required: {\n\t\t\treturn field;\n\t\t}\n\t\tcase FieldKind.Optional: {\n\t\t\treturn field.optional();\n\t\t}\n\t\tcase FieldKind.Identifier: {\n\t\t\treturn field\n\t\t\t\t.optional()\n\t\t\t\t.describe(\n\t\t\t\t\t\"This is an ID automatically generated by the system. Do not supply it when constructing a new object.\",\n\t\t\t\t);\n\t\t}\n\t\tdefault: {\n\t\t\tthrow new Error(`Unsupported field kind ${NodeKind[fieldSchema.kind]}.`);\n\t\t}\n\t}\n}\n\nfunction getTypeForAllowedTypes(\n\tdefinitionMap: ReadonlyMap<string, SimpleNodeSchema>,\n\tallowedTypes: ReadonlySet<string>,\n\tobjectCache: MapGetSet<SimpleNodeSchema, ZodTypeAny>,\n\tbindableSchemas: Map<string, BindableSchema>,\n): ZodTypeAny {\n\tconst single = tryGetSingleton(allowedTypes);\n\tif (single === undefined) {\n\t\tconst types = [\n\t\t\t...mapIterable(allowedTypes, (name) => {\n\t\t\t\treturn getOrCreateType(definitionMap, name, objectCache, bindableSchemas);\n\t\t\t}),\n\t\t];\n\t\tassert(hasAtLeastTwo(types), 0xa7e /* Expected at least two types */);\n\t\treturn z.union(types);\n\t} else {\n\t\treturn getOrCreateType(definitionMap, single, objectCache, bindableSchemas);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"typeGeneration.js","sourceRoot":"","sources":["../src/typeGeneration.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA8E;AAC9E,uEAAsE;AACtE,4DAUuC;AAQvC,6BAAyC;AAGzC,yDAAwE;AACxE,6DAA4D;AAC5D,yCAQoB;AAEpB;;;;;;;;;GASG;AAEH;;GAEG;AACH,MAAM,iBAAiB,GAAG,IAAI,OAAO,EAGlC,CAAC;AAEJ;;GAEG;AACH,SAAgB,0BAA0B,CACzC,UAA+B,EAC/B,MAAwB;IAIxB,OAAO,IAAA,sBAAW,EAAC,iBAAiB,EAAE,MAAM,EAAE,GAAG,EAAE;QAClD,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC7C,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAkB,CAAC;QACpD,IAAA,0BAAe,EAAC,UAAU,EAAE;YAC3B,IAAI,EAAE,CAAC,CAAC,EAAE,EAAE;gBACX,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBAClB,IACC,CAAC,YAAY,2BAAgB;oBAC7B,CAAC,YAAY,wBAAa;oBAC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AAC,CAAC,CAAC;YACzB,OAAO,KAAK,CAAC;QACd,CAAC;QACD,KAAK,oBAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;YACzB,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;QACzB,CAAC;QACD,KAAK,oBAAS,CAAC,UAAU,CAAC,CAAC,CAAC;YAC3B,OAAO,KAAK;iBACV,QAAQ,EAAE;iBACV,QAAQ,CACR,uGAAuG,CACvG,CAAC;QACJ,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACT,MAAM,IAAI,KAAK,CAAC,0BAA0B,mBAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1E,CAAC;IACF,CAAC;AACF,CAAC;AAED,SAAS,sBAAsB,CAC9B,aAAoD,EACpD,YAAiC,EACjC,WAAoD,EACpD,eAA4C;IAE5C,MAAM,MAAM,GAAG,IAAA,0BAAe,EAAC,YAAY,CAAC,CAAC;IAC7C,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAG;YACb,GAAG,IAAA,sBAAW,EAAC,YAAY,EAAE,CAAC,IAAI,EAAE,EAAE;gBACrC,OAAO,eAAe,CAAC,aAAa,EAAE,IAAI,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC;YAC3E,CAAC,CAAC;SACF,CAAC;QACF,IAAA,iBAAM,EAAC,IAAA,wBAAa,EAAC,KAAK,CAAC,EAAE,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACtE,OAAO,OAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;SAAM,CAAC;QACP,OAAO,eAAe,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC;IAC7E,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport {\n\tArrayNodeSchema,\n\tFieldKind,\n\tgetSimpleSchema,\n\tMapNodeSchema,\n\tNodeKind,\n\tObjectNodeSchema,\n\tRecordNodeSchema,\n\tValueSchema,\n\twalkFieldSchema,\n} from \"@fluidframework/tree/internal\";\nimport type {\n\tImplicitFieldSchema,\n\tSimpleFieldSchema,\n\tSimpleNodeSchema,\n\tSimpleTreeSchema,\n\tTreeNodeSchema,\n} from \"@fluidframework/tree/internal\";\nimport { z, type ZodTypeAny } from \"zod\";\n\nimport type { BindableSchema } from \"./methodBinding.js\";\nimport { FunctionWrapper, getExposedMethods } from \"./methodBinding.js\";\nimport { getExposedProperties } from \"./propertyBinding.js\";\nimport {\n\tfail,\n\tgetOrCreate,\n\thasAtLeastTwo,\n\tllmDefault,\n\tmapIterable,\n\ttryGetSingleton,\n\ttype MapGetSet,\n} from \"./utils.js\";\n\n/**\n *\n * TODO: Add a prompt suggestion API!\n *\n * TODO: Handle rate limit errors.\n *\n * TODO: Pass descriptions from schema metadata to the generated TS types that we put in the prompt\n *\n * TODO make the Ids be \"Vector-2\" instead of \"Vector2\" (or else it gets weird when you have a type called \"Vector2\")\n */\n\n/**\n * Cache used to prevent repeatedly generating the same Zod validation objects for the same {@link SimpleTreeSchema} as generate propts for repeated calls to an LLM\n */\nconst promptSchemaCache = new WeakMap<\n\tSimpleTreeSchema,\n\tReturnType<typeof generateEditTypes>\n>();\n\n/**\n * TODO\n */\nexport function generateEditTypesForPrompt(\n\trootSchema: ImplicitFieldSchema,\n\tschema: SimpleTreeSchema,\n): {\n\tdomainTypes: Record<string, ZodTypeAny>;\n} {\n\treturn getOrCreate(promptSchemaCache, schema, () => {\n\t\tconst allSchemas = new Set<TreeNodeSchema>();\n\t\tconst objectTypeSchemas = new Set<TreeNodeSchema>();\n\t\twalkFieldSchema(rootSchema, {\n\t\t\tnode: (n) => {\n\t\t\t\tallSchemas.add(n);\n\t\t\t\tif (\n\t\t\t\t\tn instanceof ObjectNodeSchema ||\n\t\t\t\t\tn instanceof MapNodeSchema ||\n\t\t\t\t\tn instanceof ArrayNodeSchema ||\n\t\t\t\t\tn instanceof RecordNodeSchema\n\t\t\t\t) {\n\t\t\t\t\tobjectTypeSchemas.add(n);\n\t\t\t\t\tconst exposedMethods = getExposedMethods(n);\n\t\t\t\t\tfor (const t of exposedMethods.referencedTypes) {\n\t\t\t\t\t\tallSchemas.add(t);\n\t\t\t\t\t\tobjectTypeSchemas.add(t);\n\t\t\t\t\t}\n\t\t\t\t\tconst exposedProperties = getExposedProperties(n);\n\t\t\t\t\tfor (const t of exposedProperties.referencedTypes) {\n\t\t\t\t\t\tallSchemas.add(t);\n\t\t\t\t\t\tobjectTypeSchemas.add(t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t});\n\t\tconst nodeSchemas = [...objectTypeSchemas.values()] as BindableSchema[];\n\t\tconst bindableSchemas = new Map<string, BindableSchema>(\n\t\t\tnodeSchemas.map((nodeSchema) => [nodeSchema.identifier, nodeSchema]),\n\t\t);\n\t\treturn generateEditTypes(\n\t\t\t[...allSchemas.values()].map((s) => getSimpleSchema(s)),\n\t\t\tnew Map(),\n\t\t\tbindableSchemas,\n\t\t);\n\t});\n}\n\n/**\n * Generates a set of ZOD validation objects for the various types of data that can be put into the provided {@link SimpleTreeSchema}\n * and then uses those sets to generate an all-encompassing ZOD object for each type of {@link TreeEdit} that can validate any of the types of data that can be put into the tree.\n *\n * @returns a Record of schema names to Zod validation objects, and the name of the root schema used to encompass all of the other schemas.\n *\n * @remarks The return type of this function is designed to work with Typechat's createZodJsonValidator as well as be used as the JSON schema for OpenAi's structured output response format.\n */\nfunction generateEditTypes(\n\tschemas: Iterable<SimpleTreeSchema>,\n\tobjectCache: MapGetSet<SimpleNodeSchema, ZodTypeAny>,\n\tbindableSchemas: Map<string, BindableSchema>,\n): {\n\tdomainTypes: Record<string, ZodTypeAny>;\n} {\n\tconst domainTypes: Record<string, ZodTypeAny> = {};\n\tfor (const schema of schemas) {\n\t\tfor (const name of schema.definitions.keys()) {\n\t\t\t// If this does overwrite anything in domainTypes, it is guaranteed to be overwritten with an identical value due to the getOrCreate\n\t\t\tdomainTypes[name] = getOrCreateType(\n\t\t\t\tschema.definitions,\n\t\t\t\tname,\n\t\t\t\tobjectCache,\n\t\t\t\tbindableSchemas,\n\t\t\t);\n\t\t}\n\t}\n\n\treturn {\n\t\tdomainTypes,\n\t};\n}\n\nfunction getBoundMembersForBindable(bindableSchema: BindableSchema): {\n\treferencedTypes: Set<TreeNodeSchema>;\n\tmembers: [string, ZodTypeAny][];\n} {\n\tconst memberTypes: [string, ZodTypeAny][] = [];\n\n\tconst methods = getExposedMethods(bindableSchema);\n\tfor (const [name, method] of Object.entries(methods.methods)) {\n\t\tconst zodFunction = z.instanceof(FunctionWrapper);\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n\t\t(zodFunction as any).method = method;\n\t\tmemberTypes.push([name, zodFunction]);\n\t}\n\tconst props = getExposedProperties(bindableSchema);\n\tfor (const [name, prop] of Object.entries(props.properties)) {\n\t\tconst schema = prop.schema;\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-explicit-any\n\t\t(schema as any).property = prop;\n\t\tmemberTypes.push([name, prop.schema]);\n\t}\n\n\treturn {\n\t\tmembers: memberTypes,\n\t\treferencedTypes: new Set([...props.referencedTypes, ...methods.referencedTypes]),\n\t};\n}\n\nfunction getBoundMembers(\n\tdefinition: string,\n\tbindableSchemas: Map<string, BindableSchema>,\n): [string, ZodTypeAny][] {\n\tconst bindableSchema = bindableSchemas.get(definition) ?? fail(\"unknown definition\");\n\treturn getBoundMembersForBindable(bindableSchema).members;\n}\n\nfunction addBindingIntersectionIfNeeded(\n\ttypeString: \"array\" | \"map\" | \"record\",\n\tzodTypeBound: ZodTypeAny,\n\tdefinition: string,\n\tsimpleNodeSchema: SimpleNodeSchema,\n\tbindableSchemas: Map<string, BindableSchema>,\n): ZodTypeAny {\n\tlet zodType = zodTypeBound;\n\tlet description = simpleNodeSchema.metadata?.description ?? \"\";\n\n\tconst boundMembers = getBoundMembers(definition, bindableSchemas);\n\tconst methods: Record<string, z.ZodTypeAny> = {};\n\tconst properties: Record<string, z.ZodTypeAny> = {};\n\n\tlet hasProperties: boolean = false;\n\tlet hasMethods: boolean = false;\n\n\tif (boundMembers.length > 0) {\n\t\tfor (const [name, zodMember] of boundMembers) {\n\t\t\tconst kind =\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t(zodMember as any).method === undefined\n\t\t\t\t\t? // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\t\t(zodMember as any).property === undefined\n\t\t\t\t\t\t? \"Unknown\"\n\t\t\t\t\t\t: \"Property\"\n\t\t\t\t\t: \"Method\";\n\n\t\t\tif (kind === \"Unknown\") {\n\t\t\t\tthrow new UsageError(`Unrecognized bound member ${name} in schema ${definition}`);\n\t\t\t}\n\t\t\tif (kind === \"Method\") {\n\t\t\t\tif (methods[name] !== undefined) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t`${kind} ${name} conflicts with field of the same name in schema ${definition}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tmethods[name] = zodMember;\n\t\t\t}\n\t\t\tif (kind === \"Property\") {\n\t\t\t\tif (properties[name] !== undefined) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t`${kind} ${name} conflicts with field of the same name in schema ${definition}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tproperties[name] = zodMember;\n\t\t\t}\n\t\t}\n\t\thasMethods = Object.keys(methods).length > 0 ? true : false;\n\t\thasProperties = Object.keys(properties).length > 0 ? true : false;\n\n\t\tif (hasMethods) {\n\t\t\tzodType = z.intersection(zodType, z.object(methods));\n\t\t}\n\t\tif (hasProperties) {\n\t\t\tzodType = z.intersection(zodType, z.object(properties));\n\t\t}\n\t}\n\n\tlet note = \"\";\n\tif (hasMethods && hasProperties) {\n\t\tnote = `Note: this ${typeString} has custom user-defined methods and properties directly on it.`;\n\t} else if (hasMethods) {\n\t\tnote = `Note: this ${typeString} has custom user-defined methods directly on it.`;\n\t} else if (hasProperties) {\n\t\tnote = `Note: this ${typeString} has custom user-defined properties directly on it.`;\n\t}\n\tif (note !== \"\") {\n\t\tdescription = description === \"\" ? note : `${description} - ${note}`;\n\t}\n\n\treturn zodType.describe(description);\n}\n\nfunction getOrCreateType(\n\tdefinitionMap: ReadonlyMap<string, SimpleNodeSchema>,\n\tdefinition: string,\n\tobjectCache: MapGetSet<SimpleNodeSchema, ZodTypeAny>,\n\tbindableSchemas: Map<string, BindableSchema>,\n): ZodTypeAny {\n\tconst simpleNodeSchema = definitionMap.get(definition) ?? fail(\"Unexpected definition\");\n\treturn getOrCreate(objectCache, simpleNodeSchema, () => {\n\t\t// Handle recursive types: temporarily create a zod \"lazy\" type that can be referenced by a recursive call to getOrCreateType.\n\t\tlet type: ZodTypeAny | undefined;\n\t\tobjectCache.set(\n\t\t\tsimpleNodeSchema,\n\t\t\tz.lazy(() => type ?? fail(\"Recursive type used before creation\")),\n\t\t);\n\t\tswitch (simpleNodeSchema.kind) {\n\t\t\tcase NodeKind.Object: {\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n\t\t\t\tconst properties: Record<string, z.ZodTypeAny> = Object.fromEntries(\n\t\t\t\t\t[...simpleNodeSchema.fields]\n\t\t\t\t\t\t.map(([key, field]) => {\n\t\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\tgetOrCreateTypeForField(definitionMap, field, objectCache, bindableSchemas),\n\t\t\t\t\t\t\t];\n\t\t\t\t\t\t})\n\t\t\t\t\t\t.filter(([, value]) => value !== undefined),\n\t\t\t\t);\n\n\t\t\t\tfor (const [name, zodMember] of getBoundMembers(definition, bindableSchemas)) {\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access\n\t\t\t\t\tconst kind = (zodMember as any).method === undefined ? \"Property\" : \"Method\";\n\t\t\t\t\tif (properties[name] !== undefined) {\n\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t`${kind} ${name} conflicts with field of the same name in schema ${definition}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tproperties[name] = zodMember;\n\t\t\t\t}\n\n\t\t\t\treturn (type = z\n\t\t\t\t\t.object(properties)\n\t\t\t\t\t.describe(simpleNodeSchema.metadata?.description ?? \"\"));\n\t\t\t}\n\t\t\tcase NodeKind.Map: {\n\t\t\t\tconst zodType = z.map(\n\t\t\t\t\tz.string(),\n\t\t\t\t\tgetTypeForAllowedTypes(\n\t\t\t\t\t\tdefinitionMap,\n\t\t\t\t\t\tnew Set(simpleNodeSchema.simpleAllowedTypes.keys()),\n\t\t\t\t\t\tobjectCache,\n\t\t\t\t\t\tbindableSchemas,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\treturn (type = addBindingIntersectionIfNeeded(\n\t\t\t\t\t\"map\",\n\t\t\t\t\tzodType,\n\t\t\t\t\tdefinition,\n\t\t\t\t\tsimpleNodeSchema,\n\t\t\t\t\tbindableSchemas,\n\t\t\t\t));\n\t\t\t}\n\t\t\tcase NodeKind.Record: {\n\t\t\t\tconst zodType = z.record(\n\t\t\t\t\tgetTypeForAllowedTypes(\n\t\t\t\t\t\tdefinitionMap,\n\t\t\t\t\t\tnew Set(simpleNodeSchema.simpleAllowedTypes.keys()),\n\t\t\t\t\t\tobjectCache,\n\t\t\t\t\t\tbindableSchemas,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\treturn (type = addBindingIntersectionIfNeeded(\n\t\t\t\t\t\"record\",\n\t\t\t\t\tzodType,\n\t\t\t\t\tdefinition,\n\t\t\t\t\tsimpleNodeSchema,\n\t\t\t\t\tbindableSchemas,\n\t\t\t\t));\n\t\t\t}\n\t\t\tcase NodeKind.Array: {\n\t\t\t\tconst zodType = z.array(\n\t\t\t\t\tgetTypeForAllowedTypes(\n\t\t\t\t\t\tdefinitionMap,\n\t\t\t\t\t\tnew Set(simpleNodeSchema.simpleAllowedTypes.keys()),\n\t\t\t\t\t\tobjectCache,\n\t\t\t\t\t\tbindableSchemas,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\treturn (type = addBindingIntersectionIfNeeded(\n\t\t\t\t\t\"array\",\n\t\t\t\t\tzodType,\n\t\t\t\t\tdefinition,\n\t\t\t\t\tsimpleNodeSchema,\n\t\t\t\t\tbindableSchemas,\n\t\t\t\t));\n\t\t\t}\n\t\t\tcase NodeKind.Leaf: {\n\t\t\t\tswitch (simpleNodeSchema.leafKind) {\n\t\t\t\t\tcase ValueSchema.Boolean: {\n\t\t\t\t\t\treturn (type = z.boolean());\n\t\t\t\t\t}\n\t\t\t\t\tcase ValueSchema.Number: {\n\t\t\t\t\t\treturn (type = z.number());\n\t\t\t\t\t}\n\t\t\t\t\tcase ValueSchema.String: {\n\t\t\t\t\t\treturn (type = z.string());\n\t\t\t\t\t}\n\t\t\t\t\tcase ValueSchema.Null: {\n\t\t\t\t\t\treturn (type = z.null());\n\t\t\t\t\t}\n\t\t\t\t\tdefault: {\n\t\t\t\t\t\tthrow new Error(`Unsupported leaf kind ${NodeKind[simpleNodeSchema.leafKind]}.`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn unreachableCase(simpleNodeSchema, \"Unknown node kind\");\n\t\t\t}\n\t\t}\n\t});\n}\n\nfunction getOrCreateTypeForField(\n\tdefinitionMap: ReadonlyMap<string, SimpleNodeSchema>,\n\tfieldSchema: SimpleFieldSchema,\n\tobjectCache: MapGetSet<SimpleNodeSchema, ZodTypeAny>,\n\tbindableSchemas: Map<string, BindableSchema>,\n): ZodTypeAny {\n\tconst customMetadata = fieldSchema.metadata.custom as\n\t\t| Record<string | symbol, unknown>\n\t\t| undefined;\n\tconst getDefault = customMetadata?.[llmDefault];\n\tif (getDefault !== undefined) {\n\t\tif (typeof getDefault !== \"function\") {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Expected value of ${llmDefault.description} property to be a function, but got ${typeof getDefault}`,\n\t\t\t);\n\t\t}\n\n\t\tif (fieldSchema.kind !== FieldKind.Optional) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`The ${llmDefault.description} property is only permitted on optional fields.`,\n\t\t\t);\n\t\t}\n\t}\n\n\tconst field = getTypeForAllowedTypes(\n\t\tdefinitionMap,\n\t\tnew Set(fieldSchema.simpleAllowedTypes.keys()),\n\t\tobjectCache,\n\t\tbindableSchemas,\n\t).describe(\n\t\tgetDefault === undefined\n\t\t\t? (fieldSchema.metadata?.description ?? \"\")\n\t\t\t: \"Do not populate this field. It will be automatically supplied by the system after insertion.\",\n\t);\n\n\tswitch (fieldSchema.kind) {\n\t\tcase FieldKind.Required: {\n\t\t\treturn field;\n\t\t}\n\t\tcase FieldKind.Optional: {\n\t\t\treturn field.optional();\n\t\t}\n\t\tcase FieldKind.Identifier: {\n\t\t\treturn field\n\t\t\t\t.optional()\n\t\t\t\t.describe(\n\t\t\t\t\t\"This is an ID automatically generated by the system. Do not supply it when constructing a new object.\",\n\t\t\t\t);\n\t\t}\n\t\tdefault: {\n\t\t\tthrow new Error(`Unsupported field kind ${NodeKind[fieldSchema.kind]}.`);\n\t\t}\n\t}\n}\n\nfunction getTypeForAllowedTypes(\n\tdefinitionMap: ReadonlyMap<string, SimpleNodeSchema>,\n\tallowedTypes: ReadonlySet<string>,\n\tobjectCache: MapGetSet<SimpleNodeSchema, ZodTypeAny>,\n\tbindableSchemas: Map<string, BindableSchema>,\n): ZodTypeAny {\n\tconst single = tryGetSingleton(allowedTypes);\n\tif (single === undefined) {\n\t\tconst types = [\n\t\t\t...mapIterable(allowedTypes, (name) => {\n\t\t\t\treturn getOrCreateType(definitionMap, name, objectCache, bindableSchemas);\n\t\t\t}),\n\t\t];\n\t\tassert(hasAtLeastTwo(types), 0xa7e /* Expected at least two types */);\n\t\treturn z.union(types);\n\t} else {\n\t\treturn getOrCreateType(definitionMap, single, objectCache, bindableSchemas);\n\t}\n}\n"]}
|
package/dist/utils.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import type { ImplicitFieldSchema, TreeNodeSchemaClass } from "@fluidframework/tree";
|
|
6
|
-
import type { InsertableContent,
|
|
6
|
+
import type { InsertableContent, TreeNode, TreeNodeSchema } from "@fluidframework/tree/alpha";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
/**
|
|
9
9
|
* Subset of Map interface.
|
|
@@ -37,12 +37,6 @@ export declare function mapIterable<T, U>(iterable: Iterable<T>, map: (t: T) =>
|
|
|
37
37
|
* @remarks originally from tree/src/util/utils.ts
|
|
38
38
|
*/
|
|
39
39
|
export declare function getOrCreate<K, V>(map: MapGetSet<K, V>, key: K, defaultValue: (key: K) => V): V;
|
|
40
|
-
/**
|
|
41
|
-
* TODO
|
|
42
|
-
* @alpha
|
|
43
|
-
* @privateRemarks This is a subset of the TreeViewAlpha functionality because if take it wholesale, it causes problems with invariance of the generic parameters.
|
|
44
|
-
*/
|
|
45
|
-
export type TreeView<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema> = Pick<TreeViewAlpha<TRoot>, "root" | "fork" | "merge" | "rebaseOnto" | "schema" | "events"> & TreeBranchAlpha;
|
|
46
40
|
/**
|
|
47
41
|
* TODO
|
|
48
42
|
*/
|
package/dist/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAQH,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAA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M,GAAG,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CASpD"}
|
package/dist/utils.js
CHANGED
|
@@ -14,6 +14,7 @@ const alpha_1 = require("@fluidframework/tree/alpha");
|
|
|
14
14
|
const internal_3 = require("@fluidframework/tree/internal");
|
|
15
15
|
const zod_1 = require("zod");
|
|
16
16
|
const methodBinding_js_1 = require("./methodBinding.js");
|
|
17
|
+
const propertyBinding_js_1 = require("./propertyBinding.js");
|
|
17
18
|
/**
|
|
18
19
|
* TBD
|
|
19
20
|
*/
|
|
@@ -138,7 +139,7 @@ function isNamedSchema(schemaIdentifier) {
|
|
|
138
139
|
if (["string", "number", "boolean", "null", "handle"].includes(unqualifySchema(schemaIdentifier))) {
|
|
139
140
|
return false;
|
|
140
141
|
}
|
|
141
|
-
return
|
|
142
|
+
return /(?:Array|Map|Record)<\["(.*)"]>/.exec(schemaIdentifier) === null;
|
|
142
143
|
}
|
|
143
144
|
exports.isNamedSchema = isNamedSchema;
|
|
144
145
|
/**
|
|
@@ -148,7 +149,7 @@ exports.isNamedSchema = isNamedSchema;
|
|
|
148
149
|
*/
|
|
149
150
|
function unqualifySchema(schemaIdentifier) {
|
|
150
151
|
// Get the unqualified name by removing the scope (everything before the last dot).
|
|
151
|
-
const matches =
|
|
152
|
+
const matches = /[^.]+$/.exec(schemaIdentifier);
|
|
152
153
|
if (matches === null) {
|
|
153
154
|
return schemaIdentifier; // Return the original name if it is unscoped.
|
|
154
155
|
}
|
|
@@ -348,6 +349,21 @@ function getZodSchemaAsTypeScript(schema, details) {
|
|
|
348
349
|
}
|
|
349
350
|
}
|
|
350
351
|
}
|
|
352
|
+
function appendBoundProperties(type) {
|
|
353
|
+
const property = type.property;
|
|
354
|
+
if (!(property instanceof propertyBinding_js_1.PropertyDef)) {
|
|
355
|
+
if (type.description !== undefined && type.description !== "") {
|
|
356
|
+
append(` // ${type.description}`);
|
|
357
|
+
}
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
if (property.readOnly === true) {
|
|
361
|
+
append(" // readonly");
|
|
362
|
+
}
|
|
363
|
+
if (property.description !== undefined && property.description !== "") {
|
|
364
|
+
append(` - ${property.description}`);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
351
367
|
function appendArrayType(arrayType) {
|
|
352
368
|
appendType(arrayType._def.type, 2 /* TypePrecedence.Object */);
|
|
353
369
|
append("[]");
|
|
@@ -368,9 +384,7 @@ function getZodSchemaAsTypeScript(schema, details) {
|
|
|
368
384
|
append(": ");
|
|
369
385
|
appendType(type);
|
|
370
386
|
append(";");
|
|
371
|
-
|
|
372
|
-
if (comment !== undefined && comment !== "")
|
|
373
|
-
append(` // ${comment}`);
|
|
387
|
+
appendBoundProperties(type);
|
|
374
388
|
appendNewLine();
|
|
375
389
|
}
|
|
376
390
|
}
|