@fluidframework/tree-agent 2.70.0-361248 → 2.70.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"subtree.js","sourceRoot":"","sources":["../src/subtree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAQhE,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AASvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD;;GAEG;AACH,MAAM,OAAO,OAAO;IACnB,YACkB,UAA+D;QAA/D,eAAU,GAAV,UAAU,CAAqD;QAEhF,IAAI,UAAU,YAAY,QAAQ,IAAI,SAAS,CAAC,MAAM,CAAC,UAAU,CAAC,KAAK,SAAS,EAAE,CAAC;YAClF,MAAM,IAAI,UAAU,CAAC,4CAA4C,CAAC,CAAC;QACpE,CAAC;IACF,CAAC;IAED,IAAW,MAAM;QAChB,OAAO,IAAI,CAAC,UAAU,YAAY,QAAQ;YACzC,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,qBAAqB,CAAC,CAAC;YACpE,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC;IACpB,CAAC;IAED,IAAW,KAAK;QACf,OAAO,IAAI,CAAC,UAAU,YAAY,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;IACrF,CAAC;IAED,IAAW,KAAK,CAAC,KAAoD;QACpE,IAAI,IAAI,CAAC,UAAU,YAAY,QAAQ,EAAE,CAAC;YACzC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,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","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\tTreeNodeSchema,\n} from \"@fluidframework/tree\";\nimport { TreeAlpha } from \"@fluidframework/tree/alpha\";\nimport type {\n\tUnsafeUnknownSchema,\n\tReadableField,\n\tTreeBranch,\n\tTreeRecordNode,\n\tReadSchema,\n} from \"@fluidframework/tree/alpha\";\n\nimport { getNodeOnBranch } from \"./getNodeOnBranch.js\";\nimport type { TreeView } from \"./utils.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 | UnsafeUnknownSchema> {\n\tpublic constructor(\n\t\tprivate readonly viewOrNode: TreeView<TRoot> | (ReadableField<TRoot> & TreeNode),\n\t) {\n\t\tif (viewOrNode instanceof TreeNode && TreeAlpha.branch(viewOrNode) === 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(): TreeBranch {\n\t\treturn this.viewOrNode instanceof TreeNode\n\t\t\t? (TreeAlpha.branch(this.viewOrNode) ?? fail(\"Node cannot be raw.\"))\n\t\t\t: this.viewOrNode;\n\t}\n\n\tpublic get field(): ReadableField<TRoot> {\n\t\treturn this.viewOrNode instanceof TreeNode ? this.viewOrNode : this.viewOrNode.root;\n\t}\n\n\tpublic set field(value: TreeFieldFromImplicitField<ReadSchema<TRoot>>) {\n\t\tif (this.viewOrNode instanceof TreeNode) {\n\t\t\tconst parent = Tree.parent(this.viewOrNode);\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.viewOrNode) 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.viewOrNode) 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.viewOrNode) 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.viewOrNode) 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.viewOrNode.root = value;\n\t\t}\n\t}\n\n\tpublic get schema(): TreeNodeSchema | ReadSchema<TRoot> {\n\t\treturn this.viewOrNode instanceof TreeNode\n\t\t\t? Tree.schema(this.viewOrNode)\n\t\t\t: this.viewOrNode.schema;\n\t}\n\n\tpublic fork(): Subtree<TRoot> {\n\t\tif (this.viewOrNode instanceof TreeNode) {\n\t\t\tconst branch = TreeAlpha.branch(this.viewOrNode) ?? fail(\"Node cannot be raw.\");\n\t\t\tconst node =\n\t\t\t\tgetNodeOnBranch(this.viewOrNode, 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.viewOrNode.fork());\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"subtree.js","sourceRoot":"","sources":["../src/subtree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAQhE,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AASvD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD;;GAEG;AACH,MAAM,OAAO,OAAO;IACnB,YACkB,UAA+D;QAA/D,eAA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C,CAAC,CAAC;wBACT,IAAI,CAAC,sBAAsB,CAAC,CAAC;oBAC9B,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;aAAM,CAAC;YACP,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,KAAK,CAAC;QAC9B,CAAC;IACF,CAAC;IAED,IAAW,MAAM;QAChB,OAAO,IAAI,CAAC,UAAU,YAAY,QAAQ;YACzC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;YAC9B,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;IAC3B,CAAC;IAEM,IAAI;QACV,IAAI,IAAI,CAAC,UAAU,YAAY,QAAQ,EAAE,CAAC;YACzC,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,qBAAqB,CAAC,CAAC;YAChF,MAAM,IAAI,GACT,eAAe,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;gBAC/C,IAAI,CAAC,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","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\tTreeNodeSchema,\n} from \"@fluidframework/tree\";\nimport { TreeAlpha } from \"@fluidframework/tree/alpha\";\nimport type {\n\tUnsafeUnknownSchema,\n\tReadableField,\n\tTreeRecordNode,\n\tReadSchema,\n\tTreeBranchAlpha,\n} from \"@fluidframework/tree/alpha\";\n\nimport { getNodeOnBranch } from \"./getNodeOnBranch.js\";\nimport type { TreeView } from \"./utils.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 | UnsafeUnknownSchema> {\n\tpublic constructor(\n\t\tprivate readonly viewOrNode: TreeView<TRoot> | (ReadableField<TRoot> & TreeNode),\n\t) {\n\t\tif (viewOrNode instanceof TreeNode && TreeAlpha.branch(viewOrNode) === 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.viewOrNode instanceof TreeNode\n\t\t\t? (TreeAlpha.branch(this.viewOrNode) ?? fail(\"Node cannot be raw.\"))\n\t\t\t: this.viewOrNode;\n\t}\n\n\tpublic get field(): ReadableField<TRoot> {\n\t\treturn this.viewOrNode instanceof TreeNode ? this.viewOrNode : this.viewOrNode.root;\n\t}\n\n\tpublic set field(value: TreeFieldFromImplicitField<ReadSchema<TRoot>>) {\n\t\tif (this.viewOrNode instanceof TreeNode) {\n\t\t\tconst parent = Tree.parent(this.viewOrNode);\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.viewOrNode) 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.viewOrNode) 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.viewOrNode) 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.viewOrNode) 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.viewOrNode.root = value;\n\t\t}\n\t}\n\n\tpublic get schema(): TreeNodeSchema | ReadSchema<TRoot> {\n\t\treturn this.viewOrNode instanceof TreeNode\n\t\t\t? Tree.schema(this.viewOrNode)\n\t\t\t: this.viewOrNode.schema;\n\t}\n\n\tpublic fork(): Subtree<TRoot> {\n\t\tif (this.viewOrNode instanceof TreeNode) {\n\t\t\tconst branch = TreeAlpha.branch(this.viewOrNode) ?? fail(\"Node cannot be raw.\");\n\t\t\tconst node =\n\t\t\t\tgetNodeOnBranch(this.viewOrNode, 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.viewOrNode.fork());\n\t\t}\n\t}\n}\n"]}
package/lib/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, TreeBranch, TreeNode, TreeNodeSchema, TreeViewAlpha, UnsafeUnknownSchema } from "@fluidframework/tree/alpha";
6
+ import type { InsertableContent, TreeBranchAlpha, TreeNode, TreeNodeSchema, TreeViewAlpha, UnsafeUnknownSchema } from "@fluidframework/tree/alpha";
7
7
  import { z } from "zod";
8
8
  /**
9
9
  * Subset of Map interface.
@@ -42,7 +42,7 @@ export declare function getOrCreate<K, V>(map: MapGetSet<K, V>, key: K, defaultV
42
42
  * @alpha
43
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
44
  */
45
- export type TreeView<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema> = Pick<TreeViewAlpha<TRoot>, "root" | "fork" | "merge" | "rebaseOnto" | "schema" | "events"> & TreeBranch;
45
+ export type TreeView<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema> = Pick<TreeViewAlpha<TRoot>, "root" | "fork" | "merge" | "rebaseOnto" | "schema" | "events"> & TreeBranchAlpha;
46
46
  /**
47
47
  * TODO
48
48
  */
@@ -114,12 +114,10 @@ export declare function getZodSchemaAsTypeScript(schema: Record<string, z.ZodTyp
114
114
  */
115
115
  export declare function instanceOf<T extends TreeNodeSchemaClass>(schema: T): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>>;
116
116
  /**
117
- * Adds all named object, map, array, and record schemas reachable from the given schema to the given set.
118
- * @remarks This includes transitive child/descendant schemas.
119
- * It does not include primitive schemas or inlined array/map/record schemas.
120
- * @returns The set of named schemas added (same as the `schemas` parameter, if supplied).
117
+ * Adds all (optionally filtered) schemas reachable from the given schema to the given set.
118
+ * @returns The set of schemas added (same as the `schemas` parameter, if supplied).
121
119
  */
122
- export declare function findNamedSchemas(schema: ImplicitFieldSchema, schemas?: Set<TreeNodeSchema>): Set<TreeNodeSchema>;
120
+ export declare function findSchemas(schema: ImplicitFieldSchema, filter?: (schema: TreeNodeSchema) => boolean, schemas?: Set<TreeNodeSchema>): Set<TreeNodeSchema>;
123
121
  /**
124
122
  * De-capitalize (the first letter of) a string.
125
123
  */
@@ -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,MAAM,sBAAsB,CAAC;AACrF,OAAO,KAAK,EACX,iBAAiB,EACjB,UAAU,EACV,QAAQ,EACR,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,MAAM,4BAA4B,CAAC;AASpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB;;;;GAIG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,EAAE,CAAC;IAC9B,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IAC3B,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAE3C;AAED;;;;;;;GAOG;AACH,wBAAiB,WAAW,CAAC,CAAC,EAAE,CAAC,EAChC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,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CAOxF;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,cAAc,GAAG,MAAM,CAoB9D;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAU/D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,gBAAgB,EAAE,MAAM,GAAG,MAAM,CAOhE;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC7B,gBAAgB,EAAE,OAAO,CAAC;CAC1B;AAOD;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CACvC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,EACjC,OAAO,CAAC,EAAE,aAAa,GACrB,MAAM,CAuSR;AA6CD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,CAAC,SAAS,mBAAmB,EACvD,MAAM,EAAE,CAAC,GACP,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAO3D;AAID;;;GAGG;AACH,wBAAgB,WAAW,CAC1B,MAAM,EAAE,mBAAmB,EAC3B,MAAM,GAAE,CAAC,MAAM,EAAE,cAAc,KAAK,OAAoB,EACxD,OAAO,sBAA4B,GACjC,GAAG,CAAC,cAAc,CAAC,CAUrB;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CASpD"}
package/lib/utils.js CHANGED
@@ -478,22 +478,19 @@ export function instanceOf(schema) {
478
478
  }
479
479
  const instanceOfs = new WeakMap();
480
480
  /**
481
- * Adds all named object, map, array, and record schemas reachable from the given schema to the given set.
482
- * @remarks This includes transitive child/descendant schemas.
483
- * It does not include primitive schemas or inlined array/map/record schemas.
484
- * @returns The set of named schemas added (same as the `schemas` parameter, if supplied).
481
+ * Adds all (optionally filtered) schemas reachable from the given schema to the given set.
482
+ * @returns The set of schemas added (same as the `schemas` parameter, if supplied).
485
483
  */
486
- export function findNamedSchemas(schema, schemas = new Set()) {
487
- const set = schemas ?? new Set();
484
+ export function findSchemas(schema, filter = () => true, schemas = new Set()) {
488
485
  for (const nodeSchema of normalizeFieldSchema(schema).allowedTypeSet) {
489
- if (!set.has(nodeSchema)) {
490
- if (isNamedSchema(nodeSchema.identifier)) {
491
- set.add(nodeSchema);
486
+ if (!schemas.has(nodeSchema)) {
487
+ if (filter(nodeSchema)) {
488
+ schemas.add(nodeSchema);
492
489
  }
493
- findNamedSchemas([...nodeSchema.childTypes], set);
490
+ findSchemas([...nodeSchema.childTypes], filter, schemas);
494
491
  }
495
492
  }
496
- return set;
493
+ return schemas;
497
494
  }
498
495
  /**
499
496
  * De-capitalize (the first letter of) a string.
package/lib/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,0DAA0D;AAC1D,qEAAqE;AAErE,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAUtE,OAAO,EACN,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,GACT,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAYrD;;GAEG;AACH,MAAM,UAAU,IAAI,CAAC,OAAe;IACnC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAC1B,CAAC;AAED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AAG,CAAC,CAAC;QACnD,CAAC;IACF,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW;IACpC,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC3C,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC,OAAO,CAAC;IACtB,CAAC;IACD,IAAI,CAAC;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\n/* eslint-disable @typescript-eslint/explicit-function-return-type */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport type { ImplicitFieldSchema, TreeNodeSchemaClass } from \"@fluidframework/tree\";\nimport type {\n\tInsertableContent,\n\tTreeBranch,\n\tTreeNode,\n\tTreeNodeSchema,\n\tTreeViewAlpha,\n\tUnsafeUnknownSchema,\n} from \"@fluidframework/tree/alpha\";\nimport {\n\tArrayNodeSchema,\n\tMapNodeSchema,\n\tObjectNodeSchema,\n\tRecordNodeSchema,\n\tTreeAlpha,\n} from \"@fluidframework/tree/alpha\";\nimport { NodeKind, normalizeFieldSchema } from \"@fluidframework/tree/internal\";\nimport { z } from \"zod\";\n\nimport { FunctionWrapper } from \"./methodBinding.js\";\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\n/**\n * TODO\n * @alpha\n * @privateRemarks This is a subset of the TreeViewAlpha functionality because if take it wholesale, it causes problems with invariance of the generic parameters.\n */\nexport type TreeView<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema> = Pick<\n\tTreeViewAlpha<TRoot>,\n\t\"root\" | \"fork\" | \"merge\" | \"rebaseOnto\" | \"schema\" | \"events\"\n> &\n\tTreeBranch;\n\n/**\n * TODO\n */\nexport function tryGetSingleton<T>(set: ReadonlySet<T>): T | undefined {\n\tif (set.size === 1) {\n\t\tfor (const item of set) {\n\t\t\treturn item;\n\t\t}\n\t}\n}\n\n/**\n * Does it have at least two elements?\n */\nexport function hasAtLeastTwo<T>(array: T[]): array is [T, T, ...T[]] {\n\treturn array.length >= 2;\n}\n\n/**\n * Include this property in a field's schema metadata to indicate that the field's value should be generated via a provided function rather than by the LLM.\n * @example\n * ```ts\n * class Object extends schemaFactory.object(\"Object\", {\n * created: sf.required(sf.number, {\n * custom: {\n * // The LLM will ignore this field, and instead it will be populated with the result of the function\n * [llmDefault]: () => Date.now(),\n * },\n * }),\n * }) {};\n * ```\n * @alpha\n */\nexport const llmDefault = Symbol(\"tree-agent/llmDefault\");\n// TODO: make this a wrapper function instead, and hide the symbol.\n// function llmDefault<T extends FieldSchemaMetadata>(metadata: T): T { ... }\n\n/**\n * Usage fail\n */\nexport function failUsage(message: string): never {\n\tthrow new UsageError(message);\n}\n\n/**\n * Construct an object node from a schema and value.\n */\nexport function constructNode(schema: TreeNodeSchema, value: InsertableContent): TreeNode {\n\tconst node = TreeAlpha.create<UnsafeUnknownSchema>(schema, value);\n\tassert(\n\t\tnode !== undefined && node !== null && typeof node === \"object\" && !isFluidHandle(node),\n\t\t0xc1e /* Expected a constructed node to be an object */,\n\t);\n\treturn node;\n}\n\n/**\n * Returns the unqualified name of a tree value's schema (e.g. a node with schema identifier `\"my.scope.MyNode\"` returns `\"MyNode\"`).\n * @remarks If the schema is an inlined array, map, or record type, then it has no name and this function will return a string representation of the type (e.g., `\"MyNode[]\"` or `\"Map<string, MyNode>\"`).\n */\nexport function getFriendlyName(schema: TreeNodeSchema): string {\n\tif (schema.kind === NodeKind.Leaf || isNamedSchema(schema.identifier)) {\n\t\treturn unqualifySchema(schema.identifier);\n\t}\n\n\tconst childNames = Array.from(schema.childTypes, (t) => getFriendlyName(t));\n\tif (schema instanceof ArrayNodeSchema) {\n\t\treturn childNames.length > 1 ? `(${childNames.join(\" | \")})[]` : `${childNames[0]}[]`;\n\t}\n\tif (schema instanceof MapNodeSchema) {\n\t\treturn childNames.length > 1\n\t\t\t? `Map<string, (${childNames.join(\" | \")})>`\n\t\t\t: `Map<string, ${childNames[0]}>`;\n\t}\n\tif (schema instanceof RecordNodeSchema) {\n\t\treturn childNames.length > 1\n\t\t\t? `Record<string, (${childNames.join(\" | \")})>`\n\t\t\t: `Record<string, ${childNames[0]}>`;\n\t}\n\tfail(\"Unexpected node schema\");\n}\n\n/**\n * Returns true if the schema identifier represents a named schema (object, named array, named map, or named record).\n * @remarks This does not include primitive schemas or inlined array/map/record schemas.\n */\nexport function isNamedSchema(schemaIdentifier: string): boolean {\n\tif (\n\t\t[\"string\", \"number\", \"boolean\", \"null\", \"handle\"].includes(\n\t\t\tunqualifySchema(schemaIdentifier),\n\t\t)\n\t) {\n\t\treturn false;\n\t}\n\n\treturn schemaIdentifier.match(/(?:Array|Map|Record)<\\[\"(.*)\"]>/) === null;\n}\n\n/**\n * Returns the unqualified name of a schema (e.g. `\"my.scope.MyNode\"` returns `\"MyNode\"`).\n * @remarks This works by removing all characters before the last dot in the schema name.\n * If there is a dot in a user's schema name, this might produce unexpected results.\n */\nexport function unqualifySchema(schemaIdentifier: string): string {\n\t// Get the unqualified name by removing the scope (everything before the last dot).\n\tconst matches = schemaIdentifier.match(/[^.]+$/);\n\tif (matches === null) {\n\t\treturn schemaIdentifier; // Return the original name if it is unscoped.\n\t}\n\treturn matches[0];\n}\n\n/**\n * Details about the properties of a TypeScript schema represented as Zod.\n */\nexport interface SchemaDetails {\n\thasHelperMethods: boolean;\n}\n\n// TODO: yuck, this entire file has too many statics. we should rewrite it as a generic zod schema walk.\nlet detailsI: SchemaDetails = {\n\thasHelperMethods: false,\n};\n\n/**\n * Returns the TypeScript source code corresponding to a Zod schema. The schema is supplied as an object where each\n * property provides a name for an associated Zod type. The return value is a string containing the TypeScript source\n * code corresponding to the schema. Each property of the schema object is emitted as a named `interface` or `type`\n * declaration for the associated type and is referenced by that name in the emitted type declarations. Other types\n * referenced in the schema are emitted in their structural form.\n * @param schema - A schema object where each property provides a name for an associated Zod type.\n * @param details - Optional details about the schema. The fields will be set according to the details in the given schema.\n * @returns The TypeScript source code corresponding to the schema.\n */\nexport function getZodSchemaAsTypeScript(\n\tschema: Record<string, z.ZodType>,\n\tdetails?: SchemaDetails,\n): string {\n\tdetailsI = details ?? { hasHelperMethods: false };\n\tlet result = \"\";\n\tlet startOfLine = true;\n\tlet indent = 0;\n\tconst entries = [...Object.entries(schema)];\n\tconst namedTypes = new Map<object, string>(\n\t\tentries.map(([name, type]) => [getTypeIdentity(type), name]),\n\t);\n\tfor (const [name, type] of entries) {\n\t\tif (result) {\n\t\t\tappendNewLine();\n\t\t}\n\t\tconst description = type._def.description;\n\t\tif (description !== undefined && description !== \"\") {\n\t\t\tfor (const comment of description.split(\"\\n\")) {\n\t\t\t\tappend(`// ${comment}`);\n\t\t\t\tappendNewLine();\n\t\t\t}\n\t\t}\n\t\tif (getTypeKind(type) === z.ZodFirstPartyTypeKind.ZodObject) {\n\t\t\tappend(`interface ${name} `);\n\t\t\tappendObjectType(type as z.ZodObject<z.ZodRawShape>);\n\t\t} else {\n\t\t\tappend(`type ${name} = `);\n\t\t\tappendTypeDefinition(type);\n\t\t\tappend(\";\");\n\t\t}\n\t\tappendNewLine();\n\t}\n\treturn result;\n\n\tfunction append(s: string) {\n\t\tif (startOfLine) {\n\t\t\tresult += \" \".repeat(indent);\n\t\t\tstartOfLine = false;\n\t\t}\n\t\tresult += s;\n\t}\n\n\tfunction appendNewLine() {\n\t\tappend(\"\\n\");\n\t\tstartOfLine = true;\n\t}\n\n\tfunction appendType(type: z.ZodType, minPrecedence = TypePrecedence.Object) {\n\t\tconst name = namedTypes.get(getTypeIdentity(type));\n\t\tif (name === undefined) {\n\t\t\tconst parenthesize = getTypePrecendece(type) < minPrecedence;\n\t\t\tif (parenthesize) append(\"(\");\n\t\t\tappendTypeDefinition(type);\n\t\t\tif (parenthesize) append(\")\");\n\t\t} else {\n\t\t\tappend(name);\n\t\t}\n\t}\n\n\tfunction appendTypeDefinition(type: z.ZodType) {\n\t\tswitch (getTypeKind(type)) {\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodString: {\n\t\t\t\treturn append(\"string\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodNumber: {\n\t\t\t\treturn append(\"number\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodBoolean: {\n\t\t\t\treturn append(\"boolean\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodDate: {\n\t\t\t\treturn append(\"Date\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodUndefined: {\n\t\t\t\treturn append(\"undefined\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodNull: {\n\t\t\t\treturn append(\"null\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodUnknown: {\n\t\t\t\treturn append(\"unknown\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodArray: {\n\t\t\t\treturn appendArrayType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodObject: {\n\t\t\t\treturn appendObjectType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodUnion: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t(type._def as z.ZodUnionDef).options,\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t[...(type._def as z.ZodDiscriminatedUnionDef<string>).options.values()],\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodIntersection: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t[\n\t\t\t\t\t\t(type._def as z.ZodIntersectionDef).left,\n\t\t\t\t\t\t(type._def as z.ZodIntersectionDef).right,\n\t\t\t\t\t],\n\t\t\t\t\tTypePrecedence.Intersection,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodTuple: {\n\t\t\t\treturn appendTupleType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodRecord: {\n\t\t\t\treturn appendRecordType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodMap: {\n\t\t\t\treturn appendMapType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodLiteral: {\n\t\t\t\treturn appendLiteral((type._def as z.ZodLiteralDef).value);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodEnum: {\n\t\t\t\treturn append(\n\t\t\t\t\t(type._def as z.ZodEnumDef).values.map((value) => JSON.stringify(value)).join(\" | \"),\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodOptional: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t[(type._def as z.ZodOptionalDef).innerType, z.undefined()],\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodReadonly: {\n\t\t\t\treturn appendReadonlyType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodEffects: {\n\t\t\t\t// Currently, this only handles schema class instances, but there are other cases in which a ZodEffects could theoretically be used.\n\t\t\t\tif (instanceOfs.has(type)) {\n\t\t\t\t\tconst objectNodeSchema = instanceOfs.get(type);\n\t\t\t\t\tif (objectNodeSchema === undefined) {\n\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t`Unsupported zod effects type when transforming class method: ${getTypeKind(type)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn append(getFriendlyName(objectNodeSchema));\n\t\t\t\t}\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Unsupported zod effects type. Did you use z.instanceOf? Use ExposedMethods.instanceOf function to reference schema classes in methods.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodVoid: {\n\t\t\t\treturn append(\"void\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodLazy: {\n\t\t\t\treturn appendType((type._def as z.ZodLazyDef).getter());\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Unsupported type when transforming class method: ${getTypeKind(type)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction appendBoundMethods(boundType: z.ZodType): void {\n\t\t// eslint-disable-next-line prefer-const\n\t\tfor (let [name, type] of Object.entries((boundType._def as z.ZodObjectDef).shape())) {\n\t\t\t// Special handling of methods on objects\n\t\t\tconst method = (type as unknown as { method: object | undefined }).method;\n\t\t\tif (method !== undefined && method instanceof FunctionWrapper) {\n\t\t\t\tdetailsI.hasHelperMethods = true;\n\t\t\t\tappend(name);\n\t\t\t\tappend(\"(\");\n\t\t\t\tlet first = true;\n\t\t\t\tfor (const [argName, argType] of method.args) {\n\t\t\t\t\tif (!first) append(\", \");\n\t\t\t\t\tif (getTypeKind(argType) === z.ZodFirstPartyTypeKind.ZodOptional) {\n\t\t\t\t\t\tappend(`${argName}?: `);\n\t\t\t\t\t\tappendType((argType._def as z.ZodOptionalDef).innerType, TypePrecedence.Object);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tappend(`${argName}: `);\n\t\t\t\t\t\tappendType(argType);\n\t\t\t\t\t}\n\t\t\t\t\tfirst = false;\n\t\t\t\t}\n\t\t\t\tif (method.rest !== null) {\n\t\t\t\t\tif (!first) append(\", \");\n\t\t\t\t\tappend(\"...rest: \");\n\t\t\t\t\tappendType(method.rest, TypePrecedence.Object);\n\t\t\t\t\tappend(\"[]\");\n\t\t\t\t}\n\t\t\t\tappend(`): `);\n\t\t\t\tappendType(method.returns, TypePrecedence.Object);\n\t\t\t\tappend(\";\");\n\t\t\t\tif (method.description !== undefined) {\n\t\t\t\t\tappend(` // ${method.description}`);\n\t\t\t\t}\n\t\t\t\tappendNewLine();\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction appendArrayType(arrayType: z.ZodType) {\n\t\tappendType((arrayType._def as z.ZodArrayDef).type, TypePrecedence.Object);\n\t\tappend(\"[]\");\n\t}\n\n\tfunction appendObjectType(objectType: z.ZodType) {\n\t\tappend(\"{\");\n\t\tappendNewLine();\n\t\tindent++;\n\t\t// eslint-disable-next-line prefer-const\n\t\tfor (let [name, type] of Object.entries((objectType._def as z.ZodObjectDef).shape())) {\n\t\t\tconst method = (type as unknown as { method: object | undefined }).method;\n\t\t\tif (method === undefined || !(method instanceof FunctionWrapper)) {\n\t\t\t\tappend(name);\n\t\t\t\tif (getTypeKind(type) === z.ZodFirstPartyTypeKind.ZodOptional) {\n\t\t\t\t\tappend(\"?\");\n\t\t\t\t\ttype = (type._def as z.ZodOptionalDef).innerType;\n\t\t\t\t}\n\t\t\t\tappend(\": \");\n\t\t\t\tappendType(type);\n\t\t\t\tappend(\";\");\n\t\t\t\tconst comment = type.description;\n\t\t\t\tif (comment !== undefined && comment !== \"\") append(` // ${comment}`);\n\t\t\t\tappendNewLine();\n\t\t\t}\n\t\t}\n\t\tappendBoundMethods(objectType);\n\t\tindent--;\n\t\tappend(\"}\");\n\t}\n\n\tfunction appendUnionOrIntersectionTypes(\n\t\ttypes: readonly z.ZodType[],\n\t\tminPrecedence: TypePrecedence,\n\t) {\n\t\tlet first = true;\n\t\tfor (const type of types) {\n\t\t\tif (!first) append(minPrecedence === TypePrecedence.Intersection ? \" & \" : \" | \");\n\t\t\tappendType(type, minPrecedence);\n\t\t\tfirst = false;\n\t\t}\n\t}\n\n\tfunction appendTupleType(tupleType: z.ZodType) {\n\t\tappend(\"[\");\n\t\tlet first = true;\n\t\tfor (const type of (tupleType._def as z.ZodTupleDef<z.ZodTupleItems, z.ZodType>).items) {\n\t\t\tif (!first) append(\", \");\n\t\t\tif (getTypeKind(type) === z.ZodFirstPartyTypeKind.ZodOptional) {\n\t\t\t\tappendType((type._def as z.ZodOptionalDef).innerType, TypePrecedence.Object);\n\t\t\t\tappend(\"?\");\n\t\t\t} else {\n\t\t\t\tappendType(type);\n\t\t\t}\n\t\t\tfirst = false;\n\t\t}\n\t\tconst rest = (tupleType._def as z.ZodTupleDef<z.ZodTupleItems, z.ZodType | null>).rest;\n\t\tif (rest !== null) {\n\t\t\tif (!first) append(\", \");\n\t\t\tappend(\"...\");\n\t\t\tappendType(rest, TypePrecedence.Object);\n\t\t\tappend(\"[]\");\n\t\t}\n\t\tappend(\"]\");\n\t}\n\n\tfunction appendRecordType(recordType: z.ZodType) {\n\t\tappend(\"Record<\");\n\t\tappendType((recordType._def as z.ZodRecordDef).keyType);\n\t\tappend(\", \");\n\t\tappendType((recordType._def as z.ZodRecordDef).valueType);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendMapType(mapType: z.ZodType) {\n\t\tappend(\"Map<\");\n\t\tappendType((mapType._def as z.ZodMapDef).keyType);\n\t\tappend(\", \");\n\t\tappendType((mapType._def as z.ZodMapDef).valueType);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendLiteral(value: unknown) {\n\t\tappend(\n\t\t\ttypeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\"\n\t\t\t\t? JSON.stringify(value)\n\t\t\t\t: \"any\",\n\t\t);\n\t}\n\n\tfunction appendReadonlyType(readonlyType: z.ZodType) {\n\t\tappend(\"Readonly<\");\n\t\tappendType((readonlyType._def as z.ZodReadonlyDef).innerType);\n\t\tappend(\">\");\n\t}\n}\n\nfunction getTypeKind(type: z.ZodType): z.ZodFirstPartyTypeKind {\n\treturn (type._def as z.ZodTypeDef & { typeName: z.ZodFirstPartyTypeKind }).typeName;\n}\n\nfunction getTypeIdentity(type: z.ZodType): object {\n\tswitch (getTypeKind(type)) {\n\t\tcase z.ZodFirstPartyTypeKind.ZodObject: {\n\t\t\treturn (type._def as z.ZodObjectDef).shape();\n\t\t}\n\t\tcase z.ZodFirstPartyTypeKind.ZodEnum: {\n\t\t\treturn (type._def as z.ZodEnumDef).values;\n\t\t}\n\t\tcase z.ZodFirstPartyTypeKind.ZodUnion: {\n\t\t\treturn (type._def as z.ZodUnionDef).options;\n\t\t}\n\t\tdefault: {\n\t\t\treturn type;\n\t\t}\n\t}\n}\n\nconst enum TypePrecedence {\n\tUnion = 0,\n\tIntersection = 1,\n\tObject = 2,\n}\n\nfunction getTypePrecendece(type: z.ZodType): TypePrecedence {\n\tswitch (getTypeKind(type)) {\n\t\tcase z.ZodFirstPartyTypeKind.ZodEnum:\n\t\tcase z.ZodFirstPartyTypeKind.ZodUnion:\n\t\tcase z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {\n\t\t\treturn TypePrecedence.Union;\n\t\t}\n\t\tcase z.ZodFirstPartyTypeKind.ZodIntersection: {\n\t\t\treturn TypePrecedence.Intersection;\n\t\t}\n\t\tdefault: {\n\t\t\treturn TypePrecedence.Object;\n\t\t}\n\t}\n}\n\n/**\n * Create a Zod schema for a SharedTree schema class.\n * @alpha\n */\nexport function instanceOf<T extends TreeNodeSchemaClass>(\n\tschema: T,\n): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>> {\n\tif (!(schema instanceof ObjectNodeSchema)) {\n\t\tthrow new UsageError(`${schema.identifier} must be an instance of ObjectNodeSchema.`);\n\t}\n\tconst effect = z.instanceof(schema);\n\tinstanceOfs.set(effect, schema);\n\treturn effect;\n}\n\nconst instanceOfs = new WeakMap<z.ZodTypeAny, ObjectNodeSchema>();\n\n/**\n * Adds all named object, map, array, and record schemas reachable from the given schema to the given set.\n * @remarks This includes transitive child/descendant schemas.\n * It does not include primitive schemas or inlined array/map/record schemas.\n * @returns The set of named schemas added (same as the `schemas` parameter, if supplied).\n */\nexport function findNamedSchemas(\n\tschema: ImplicitFieldSchema,\n\tschemas = new Set<TreeNodeSchema>(),\n): Set<TreeNodeSchema> {\n\tconst set = schemas ?? new Set();\n\tfor (const nodeSchema of normalizeFieldSchema(schema).allowedTypeSet) {\n\t\tif (!set.has(nodeSchema)) {\n\t\t\tif (isNamedSchema(nodeSchema.identifier)) {\n\t\t\t\tset.add(nodeSchema);\n\t\t\t}\n\t\t\tfindNamedSchemas([...nodeSchema.childTypes], set);\n\t\t}\n\t}\n\treturn set;\n}\n\n/**\n * De-capitalize (the first letter of) a string.\n */\nexport function communize(str: string): string {\n\treturn str.charAt(0).toLowerCase() + str.slice(1);\n}\n\n/**\n * Stringify an unknown error value\n */\nexport function toErrorString(error: unknown): string {\n\tif (error instanceof Error) {\n\t\treturn error.message;\n\t}\n\ttry {\n\t\treturn JSON.stringify(error);\n\t} catch {\n\t\treturn String(error);\n\t}\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,0DAA0D;AAC1D,qEAAqE;AAErE,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAUtE,OAAO,EACN,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,gBAAgB,EAChB,SAAS,GACT,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAYrD;;GAEG;AACH,MAAM,UAAU,IAAI,CAAC,OAAe;IACnC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;AAC1B,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,SAAS,CAAC,CAAC,WAAW,CAC3B,QAAqB,EACrB,GAAgB;IAEhB,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QAC1B,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IACd,CAAC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,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC3C,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC,OAAO,CAAC;IACtB,CAAC;IACD,IAAI,CAAC;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-unsafe-argument */\n/* eslint-disable @typescript-eslint/explicit-function-return-type */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport type { ImplicitFieldSchema, TreeNodeSchemaClass } from \"@fluidframework/tree\";\nimport type {\n\tInsertableContent,\n\tTreeBranchAlpha,\n\tTreeNode,\n\tTreeNodeSchema,\n\tTreeViewAlpha,\n\tUnsafeUnknownSchema,\n} from \"@fluidframework/tree/alpha\";\nimport {\n\tArrayNodeSchema,\n\tMapNodeSchema,\n\tObjectNodeSchema,\n\tRecordNodeSchema,\n\tTreeAlpha,\n} from \"@fluidframework/tree/alpha\";\nimport { NodeKind, normalizeFieldSchema } from \"@fluidframework/tree/internal\";\nimport { z } from \"zod\";\n\nimport { FunctionWrapper } from \"./methodBinding.js\";\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\n/**\n * TODO\n * @alpha\n * @privateRemarks This is a subset of the TreeViewAlpha functionality because if take it wholesale, it causes problems with invariance of the generic parameters.\n */\nexport type TreeView<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema> = Pick<\n\tTreeViewAlpha<TRoot>,\n\t\"root\" | \"fork\" | \"merge\" | \"rebaseOnto\" | \"schema\" | \"events\"\n> &\n\tTreeBranchAlpha;\n\n/**\n * TODO\n */\nexport function tryGetSingleton<T>(set: ReadonlySet<T>): T | undefined {\n\tif (set.size === 1) {\n\t\tfor (const item of set) {\n\t\t\treturn item;\n\t\t}\n\t}\n}\n\n/**\n * Does it have at least two elements?\n */\nexport function hasAtLeastTwo<T>(array: T[]): array is [T, T, ...T[]] {\n\treturn array.length >= 2;\n}\n\n/**\n * Include this property in a field's schema metadata to indicate that the field's value should be generated via a provided function rather than by the LLM.\n * @example\n * ```ts\n * class Object extends schemaFactory.object(\"Object\", {\n * created: sf.required(sf.number, {\n * custom: {\n * // The LLM will ignore this field, and instead it will be populated with the result of the function\n * [llmDefault]: () => Date.now(),\n * },\n * }),\n * }) {};\n * ```\n * @alpha\n */\nexport const llmDefault = Symbol(\"tree-agent/llmDefault\");\n// TODO: make this a wrapper function instead, and hide the symbol.\n// function llmDefault<T extends FieldSchemaMetadata>(metadata: T): T { ... }\n\n/**\n * Usage fail\n */\nexport function failUsage(message: string): never {\n\tthrow new UsageError(message);\n}\n\n/**\n * Construct an object node from a schema and value.\n */\nexport function constructNode(schema: TreeNodeSchema, value: InsertableContent): TreeNode {\n\tconst node = TreeAlpha.create<UnsafeUnknownSchema>(schema, value);\n\tassert(\n\t\tnode !== undefined && node !== null && typeof node === \"object\" && !isFluidHandle(node),\n\t\t0xc1e /* Expected a constructed node to be an object */,\n\t);\n\treturn node;\n}\n\n/**\n * Returns the unqualified name of a tree value's schema (e.g. a node with schema identifier `\"my.scope.MyNode\"` returns `\"MyNode\"`).\n * @remarks If the schema is an inlined array, map, or record type, then it has no name and this function will return a string representation of the type (e.g., `\"MyNode[]\"` or `\"Map<string, MyNode>\"`).\n */\nexport function getFriendlyName(schema: TreeNodeSchema): string {\n\tif (schema.kind === NodeKind.Leaf || isNamedSchema(schema.identifier)) {\n\t\treturn unqualifySchema(schema.identifier);\n\t}\n\n\tconst childNames = Array.from(schema.childTypes, (t) => getFriendlyName(t));\n\tif (schema instanceof ArrayNodeSchema) {\n\t\treturn childNames.length > 1 ? `(${childNames.join(\" | \")})[]` : `${childNames[0]}[]`;\n\t}\n\tif (schema instanceof MapNodeSchema) {\n\t\treturn childNames.length > 1\n\t\t\t? `Map<string, (${childNames.join(\" | \")})>`\n\t\t\t: `Map<string, ${childNames[0]}>`;\n\t}\n\tif (schema instanceof RecordNodeSchema) {\n\t\treturn childNames.length > 1\n\t\t\t? `Record<string, (${childNames.join(\" | \")})>`\n\t\t\t: `Record<string, ${childNames[0]}>`;\n\t}\n\tfail(\"Unexpected node schema\");\n}\n\n/**\n * Returns true if the schema identifier represents a named schema (object, named array, named map, or named record).\n * @remarks This does not include primitive schemas or inlined array/map/record schemas.\n */\nexport function isNamedSchema(schemaIdentifier: string): boolean {\n\tif (\n\t\t[\"string\", \"number\", \"boolean\", \"null\", \"handle\"].includes(\n\t\t\tunqualifySchema(schemaIdentifier),\n\t\t)\n\t) {\n\t\treturn false;\n\t}\n\n\treturn schemaIdentifier.match(/(?:Array|Map|Record)<\\[\"(.*)\"]>/) === null;\n}\n\n/**\n * Returns the unqualified name of a schema (e.g. `\"my.scope.MyNode\"` returns `\"MyNode\"`).\n * @remarks This works by removing all characters before the last dot in the schema name.\n * If there is a dot in a user's schema name, this might produce unexpected results.\n */\nexport function unqualifySchema(schemaIdentifier: string): string {\n\t// Get the unqualified name by removing the scope (everything before the last dot).\n\tconst matches = schemaIdentifier.match(/[^.]+$/);\n\tif (matches === null) {\n\t\treturn schemaIdentifier; // Return the original name if it is unscoped.\n\t}\n\treturn matches[0];\n}\n\n/**\n * Details about the properties of a TypeScript schema represented as Zod.\n */\nexport interface SchemaDetails {\n\thasHelperMethods: boolean;\n}\n\n// TODO: yuck, this entire file has too many statics. we should rewrite it as a generic zod schema walk.\nlet detailsI: SchemaDetails = {\n\thasHelperMethods: false,\n};\n\n/**\n * Returns the TypeScript source code corresponding to a Zod schema. The schema is supplied as an object where each\n * property provides a name for an associated Zod type. The return value is a string containing the TypeScript source\n * code corresponding to the schema. Each property of the schema object is emitted as a named `interface` or `type`\n * declaration for the associated type and is referenced by that name in the emitted type declarations. Other types\n * referenced in the schema are emitted in their structural form.\n * @param schema - A schema object where each property provides a name for an associated Zod type.\n * @param details - Optional details about the schema. The fields will be set according to the details in the given schema.\n * @returns The TypeScript source code corresponding to the schema.\n */\nexport function getZodSchemaAsTypeScript(\n\tschema: Record<string, z.ZodType>,\n\tdetails?: SchemaDetails,\n): string {\n\tdetailsI = details ?? { hasHelperMethods: false };\n\tlet result = \"\";\n\tlet startOfLine = true;\n\tlet indent = 0;\n\tconst entries = [...Object.entries(schema)];\n\tconst namedTypes = new Map<object, string>(\n\t\tentries.map(([name, type]) => [getTypeIdentity(type), name]),\n\t);\n\tfor (const [name, type] of entries) {\n\t\tif (result) {\n\t\t\tappendNewLine();\n\t\t}\n\t\tconst description = type._def.description;\n\t\tif (description !== undefined && description !== \"\") {\n\t\t\tfor (const comment of description.split(\"\\n\")) {\n\t\t\t\tappend(`// ${comment}`);\n\t\t\t\tappendNewLine();\n\t\t\t}\n\t\t}\n\t\tif (getTypeKind(type) === z.ZodFirstPartyTypeKind.ZodObject) {\n\t\t\tappend(`interface ${name} `);\n\t\t\tappendObjectType(type as z.ZodObject<z.ZodRawShape>);\n\t\t} else {\n\t\t\tappend(`type ${name} = `);\n\t\t\tappendTypeDefinition(type);\n\t\t\tappend(\";\");\n\t\t}\n\t\tappendNewLine();\n\t}\n\treturn result;\n\n\tfunction append(s: string) {\n\t\tif (startOfLine) {\n\t\t\tresult += \" \".repeat(indent);\n\t\t\tstartOfLine = false;\n\t\t}\n\t\tresult += s;\n\t}\n\n\tfunction appendNewLine() {\n\t\tappend(\"\\n\");\n\t\tstartOfLine = true;\n\t}\n\n\tfunction appendType(type: z.ZodType, minPrecedence = TypePrecedence.Object) {\n\t\tconst name = namedTypes.get(getTypeIdentity(type));\n\t\tif (name === undefined) {\n\t\t\tconst parenthesize = getTypePrecendece(type) < minPrecedence;\n\t\t\tif (parenthesize) append(\"(\");\n\t\t\tappendTypeDefinition(type);\n\t\t\tif (parenthesize) append(\")\");\n\t\t} else {\n\t\t\tappend(name);\n\t\t}\n\t}\n\n\tfunction appendTypeDefinition(type: z.ZodType) {\n\t\tswitch (getTypeKind(type)) {\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodString: {\n\t\t\t\treturn append(\"string\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodNumber: {\n\t\t\t\treturn append(\"number\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodBoolean: {\n\t\t\t\treturn append(\"boolean\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodDate: {\n\t\t\t\treturn append(\"Date\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodUndefined: {\n\t\t\t\treturn append(\"undefined\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodNull: {\n\t\t\t\treturn append(\"null\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodUnknown: {\n\t\t\t\treturn append(\"unknown\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodArray: {\n\t\t\t\treturn appendArrayType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodObject: {\n\t\t\t\treturn appendObjectType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodUnion: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t(type._def as z.ZodUnionDef).options,\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t[...(type._def as z.ZodDiscriminatedUnionDef<string>).options.values()],\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodIntersection: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t[\n\t\t\t\t\t\t(type._def as z.ZodIntersectionDef).left,\n\t\t\t\t\t\t(type._def as z.ZodIntersectionDef).right,\n\t\t\t\t\t],\n\t\t\t\t\tTypePrecedence.Intersection,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodTuple: {\n\t\t\t\treturn appendTupleType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodRecord: {\n\t\t\t\treturn appendRecordType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodMap: {\n\t\t\t\treturn appendMapType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodLiteral: {\n\t\t\t\treturn appendLiteral((type._def as z.ZodLiteralDef).value);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodEnum: {\n\t\t\t\treturn append(\n\t\t\t\t\t(type._def as z.ZodEnumDef).values.map((value) => JSON.stringify(value)).join(\" | \"),\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodOptional: {\n\t\t\t\treturn appendUnionOrIntersectionTypes(\n\t\t\t\t\t[(type._def as z.ZodOptionalDef).innerType, z.undefined()],\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodReadonly: {\n\t\t\t\treturn appendReadonlyType(type);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodEffects: {\n\t\t\t\t// Currently, this only handles schema class instances, but there are other cases in which a ZodEffects could theoretically be used.\n\t\t\t\tif (instanceOfs.has(type)) {\n\t\t\t\t\tconst objectNodeSchema = instanceOfs.get(type);\n\t\t\t\t\tif (objectNodeSchema === undefined) {\n\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t`Unsupported zod effects type when transforming class method: ${getTypeKind(type)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn append(getFriendlyName(objectNodeSchema));\n\t\t\t\t}\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Unsupported zod effects type. Did you use z.instanceOf? Use ExposedMethods.instanceOf function to reference schema classes in methods.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodVoid: {\n\t\t\t\treturn append(\"void\");\n\t\t\t}\n\t\t\tcase z.ZodFirstPartyTypeKind.ZodLazy: {\n\t\t\t\treturn appendType((type._def as z.ZodLazyDef).getter());\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Unsupported type when transforming class method: ${getTypeKind(type)}`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction appendBoundMethods(boundType: z.ZodType): void {\n\t\t// eslint-disable-next-line prefer-const\n\t\tfor (let [name, type] of Object.entries((boundType._def as z.ZodObjectDef).shape())) {\n\t\t\t// Special handling of methods on objects\n\t\t\tconst method = (type as unknown as { method: object | undefined }).method;\n\t\t\tif (method !== undefined && method instanceof FunctionWrapper) {\n\t\t\t\tdetailsI.hasHelperMethods = true;\n\t\t\t\tappend(name);\n\t\t\t\tappend(\"(\");\n\t\t\t\tlet first = true;\n\t\t\t\tfor (const [argName, argType] of method.args) {\n\t\t\t\t\tif (!first) append(\", \");\n\t\t\t\t\tif (getTypeKind(argType) === z.ZodFirstPartyTypeKind.ZodOptional) {\n\t\t\t\t\t\tappend(`${argName}?: `);\n\t\t\t\t\t\tappendType((argType._def as z.ZodOptionalDef).innerType, TypePrecedence.Object);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tappend(`${argName}: `);\n\t\t\t\t\t\tappendType(argType);\n\t\t\t\t\t}\n\t\t\t\t\tfirst = false;\n\t\t\t\t}\n\t\t\t\tif (method.rest !== null) {\n\t\t\t\t\tif (!first) append(\", \");\n\t\t\t\t\tappend(\"...rest: \");\n\t\t\t\t\tappendType(method.rest, TypePrecedence.Object);\n\t\t\t\t\tappend(\"[]\");\n\t\t\t\t}\n\t\t\t\tappend(`): `);\n\t\t\t\tappendType(method.returns, TypePrecedence.Object);\n\t\t\t\tappend(\";\");\n\t\t\t\tif (method.description !== undefined) {\n\t\t\t\t\tappend(` // ${method.description}`);\n\t\t\t\t}\n\t\t\t\tappendNewLine();\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction appendArrayType(arrayType: z.ZodType) {\n\t\tappendType((arrayType._def as z.ZodArrayDef).type, TypePrecedence.Object);\n\t\tappend(\"[]\");\n\t}\n\n\tfunction appendObjectType(objectType: z.ZodType) {\n\t\tappend(\"{\");\n\t\tappendNewLine();\n\t\tindent++;\n\t\t// eslint-disable-next-line prefer-const\n\t\tfor (let [name, type] of Object.entries((objectType._def as z.ZodObjectDef).shape())) {\n\t\t\tconst method = (type as unknown as { method: object | undefined }).method;\n\t\t\tif (method === undefined || !(method instanceof FunctionWrapper)) {\n\t\t\t\tappend(name);\n\t\t\t\tif (getTypeKind(type) === z.ZodFirstPartyTypeKind.ZodOptional) {\n\t\t\t\t\tappend(\"?\");\n\t\t\t\t\ttype = (type._def as z.ZodOptionalDef).innerType;\n\t\t\t\t}\n\t\t\t\tappend(\": \");\n\t\t\t\tappendType(type);\n\t\t\t\tappend(\";\");\n\t\t\t\tconst comment = type.description;\n\t\t\t\tif (comment !== undefined && comment !== \"\") append(` // ${comment}`);\n\t\t\t\tappendNewLine();\n\t\t\t}\n\t\t}\n\t\tappendBoundMethods(objectType);\n\t\tindent--;\n\t\tappend(\"}\");\n\t}\n\n\tfunction appendUnionOrIntersectionTypes(\n\t\ttypes: readonly z.ZodType[],\n\t\tminPrecedence: TypePrecedence,\n\t) {\n\t\tlet first = true;\n\t\tfor (const type of types) {\n\t\t\tif (!first) append(minPrecedence === TypePrecedence.Intersection ? \" & \" : \" | \");\n\t\t\tappendType(type, minPrecedence);\n\t\t\tfirst = false;\n\t\t}\n\t}\n\n\tfunction appendTupleType(tupleType: z.ZodType) {\n\t\tappend(\"[\");\n\t\tlet first = true;\n\t\tfor (const type of (tupleType._def as z.ZodTupleDef<z.ZodTupleItems, z.ZodType>).items) {\n\t\t\tif (!first) append(\", \");\n\t\t\tif (getTypeKind(type) === z.ZodFirstPartyTypeKind.ZodOptional) {\n\t\t\t\tappendType((type._def as z.ZodOptionalDef).innerType, TypePrecedence.Object);\n\t\t\t\tappend(\"?\");\n\t\t\t} else {\n\t\t\t\tappendType(type);\n\t\t\t}\n\t\t\tfirst = false;\n\t\t}\n\t\tconst rest = (tupleType._def as z.ZodTupleDef<z.ZodTupleItems, z.ZodType | null>).rest;\n\t\tif (rest !== null) {\n\t\t\tif (!first) append(\", \");\n\t\t\tappend(\"...\");\n\t\t\tappendType(rest, TypePrecedence.Object);\n\t\t\tappend(\"[]\");\n\t\t}\n\t\tappend(\"]\");\n\t}\n\n\tfunction appendRecordType(recordType: z.ZodType) {\n\t\tappend(\"Record<\");\n\t\tappendType((recordType._def as z.ZodRecordDef).keyType);\n\t\tappend(\", \");\n\t\tappendType((recordType._def as z.ZodRecordDef).valueType);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendMapType(mapType: z.ZodType) {\n\t\tappend(\"Map<\");\n\t\tappendType((mapType._def as z.ZodMapDef).keyType);\n\t\tappend(\", \");\n\t\tappendType((mapType._def as z.ZodMapDef).valueType);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendLiteral(value: unknown) {\n\t\tappend(\n\t\t\ttypeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\"\n\t\t\t\t? JSON.stringify(value)\n\t\t\t\t: \"any\",\n\t\t);\n\t}\n\n\tfunction appendReadonlyType(readonlyType: z.ZodType) {\n\t\tappend(\"Readonly<\");\n\t\tappendType((readonlyType._def as z.ZodReadonlyDef).innerType);\n\t\tappend(\">\");\n\t}\n}\n\nfunction getTypeKind(type: z.ZodType): z.ZodFirstPartyTypeKind {\n\treturn (type._def as z.ZodTypeDef & { typeName: z.ZodFirstPartyTypeKind }).typeName;\n}\n\nfunction getTypeIdentity(type: z.ZodType): object {\n\tswitch (getTypeKind(type)) {\n\t\tcase z.ZodFirstPartyTypeKind.ZodObject: {\n\t\t\treturn (type._def as z.ZodObjectDef).shape();\n\t\t}\n\t\tcase z.ZodFirstPartyTypeKind.ZodEnum: {\n\t\t\treturn (type._def as z.ZodEnumDef).values;\n\t\t}\n\t\tcase z.ZodFirstPartyTypeKind.ZodUnion: {\n\t\t\treturn (type._def as z.ZodUnionDef).options;\n\t\t}\n\t\tdefault: {\n\t\t\treturn type;\n\t\t}\n\t}\n}\n\nconst enum TypePrecedence {\n\tUnion = 0,\n\tIntersection = 1,\n\tObject = 2,\n}\n\nfunction getTypePrecendece(type: z.ZodType): TypePrecedence {\n\tswitch (getTypeKind(type)) {\n\t\tcase z.ZodFirstPartyTypeKind.ZodEnum:\n\t\tcase z.ZodFirstPartyTypeKind.ZodUnion:\n\t\tcase z.ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {\n\t\t\treturn TypePrecedence.Union;\n\t\t}\n\t\tcase z.ZodFirstPartyTypeKind.ZodIntersection: {\n\t\t\treturn TypePrecedence.Intersection;\n\t\t}\n\t\tdefault: {\n\t\t\treturn TypePrecedence.Object;\n\t\t}\n\t}\n}\n\n/**\n * Create a Zod schema for a SharedTree schema class.\n * @alpha\n */\nexport function instanceOf<T extends TreeNodeSchemaClass>(\n\tschema: T,\n): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>> {\n\tif (!(schema instanceof ObjectNodeSchema)) {\n\t\tthrow new UsageError(`${schema.identifier} must be an instance of ObjectNodeSchema.`);\n\t}\n\tconst effect = z.instanceof(schema);\n\tinstanceOfs.set(effect, schema);\n\treturn effect;\n}\n\nconst instanceOfs = new WeakMap<z.ZodTypeAny, ObjectNodeSchema>();\n\n/**\n * Adds all (optionally filtered) schemas reachable from the given schema to the given set.\n * @returns The set of schemas added (same as the `schemas` parameter, if supplied).\n */\nexport function findSchemas(\n\tschema: ImplicitFieldSchema,\n\tfilter: (schema: TreeNodeSchema) => boolean = () => true,\n\tschemas = new Set<TreeNodeSchema>(),\n): Set<TreeNodeSchema> {\n\tfor (const nodeSchema of normalizeFieldSchema(schema).allowedTypeSet) {\n\t\tif (!schemas.has(nodeSchema)) {\n\t\t\tif (filter(nodeSchema)) {\n\t\t\t\tschemas.add(nodeSchema);\n\t\t\t}\n\t\t\tfindSchemas([...nodeSchema.childTypes], filter, schemas);\n\t\t}\n\t}\n\treturn schemas;\n}\n\n/**\n * De-capitalize (the first letter of) a string.\n */\nexport function communize(str: string): string {\n\treturn str.charAt(0).toLowerCase() + str.slice(1);\n}\n\n/**\n * Stringify an unknown error value\n */\nexport function toErrorString(error: unknown): string {\n\tif (error instanceof Error) {\n\t\treturn error.message;\n\t}\n\ttry {\n\t\treturn JSON.stringify(error);\n\t} catch {\n\t\treturn String(error);\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/tree-agent",
3
- "version": "2.70.0-361248",
3
+ "version": "2.70.0",
4
4
  "description": "Experimental package to simplify integrating AI into Fluid-based applications",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -70,24 +70,24 @@
70
70
  },
71
71
  "dependencies": {
72
72
  "@anthropic-ai/sdk": "^0.39.0",
73
- "@fluidframework/core-utils": "2.70.0-361248",
74
- "@fluidframework/runtime-utils": "2.70.0-361248",
75
- "@fluidframework/telemetry-utils": "2.70.0-361248",
76
- "@fluidframework/tree": "2.70.0-361248",
73
+ "@fluidframework/core-utils": "~2.70.0",
74
+ "@fluidframework/runtime-utils": "~2.70.0",
75
+ "@fluidframework/telemetry-utils": "~2.70.0",
76
+ "@fluidframework/tree": "~2.70.0",
77
77
  "uuid": "^11.1.0",
78
78
  "zod": "^3.25.32"
79
79
  },
80
80
  "devDependencies": {
81
81
  "@arethetypeswrong/cli": "^0.17.1",
82
82
  "@biomejs/biome": "~1.9.3",
83
- "@fluid-internal/mocha-test-setup": "2.70.0-361248",
83
+ "@fluid-internal/mocha-test-setup": "~2.70.0",
84
84
  "@fluid-tools/build-cli": "^0.58.3",
85
85
  "@fluidframework/build-common": "^2.0.3",
86
86
  "@fluidframework/build-tools": "^0.58.3",
87
87
  "@fluidframework/eslint-config-fluid": "^6.1.0",
88
- "@fluidframework/id-compressor": "2.70.0-361248",
89
- "@fluidframework/runtime-utils": "2.70.0-361248",
90
- "@fluidframework/test-runtime-utils": "2.70.0-361248",
88
+ "@fluidframework/id-compressor": "~2.70.0",
89
+ "@fluidframework/runtime-utils": "~2.70.0",
90
+ "@fluidframework/test-runtime-utils": "~2.70.0",
91
91
  "@langchain/anthropic": "^0.3.24",
92
92
  "@langchain/core": "^0.3.78",
93
93
  "@langchain/google-genai": "^0.2.16",
package/src/agent.ts CHANGED
@@ -15,7 +15,7 @@ import type {
15
15
  InsertableContent,
16
16
  ReadSchema,
17
17
  } from "@fluidframework/tree/alpha";
18
- import { ObjectNodeSchema, Tree } from "@fluidframework/tree/alpha";
18
+ import { ObjectNodeSchema, Tree, TreeAlpha } from "@fluidframework/tree/alpha";
19
19
 
20
20
  import type {
21
21
  SharedTreeChatModel,
@@ -29,12 +29,12 @@ import type {
29
29
  import { getPrompt, stringifyTree } from "./prompt.js";
30
30
  import { Subtree } from "./subtree.js";
31
31
  import {
32
- constructNode,
33
- getFriendlyName,
34
32
  llmDefault,
35
33
  type TreeView,
36
- findNamedSchemas,
34
+ findSchemas,
37
35
  toErrorString,
36
+ unqualifySchema,
37
+ isNamedSchema,
38
38
  } from "./utils.js";
39
39
 
40
40
  /**
@@ -173,11 +173,12 @@ export class SharedTreeSemanticAgent<TSchema extends ImplicitFieldSchema> {
173
173
  * Creates an unhydrated node of the given schema with the given value.
174
174
  * @remarks If the schema is an object with {@link llmDefault | default values}, this function populates the node with those defaults.
175
175
  */
176
- function constructTreeNode(schema: TreeNodeSchema, value: FactoryContentObject): TreeNode {
176
+ function constructTreeNode(schema: TreeNodeSchema, content: FactoryContentObject): TreeNode {
177
+ let toInsert = content;
177
178
  if (schema instanceof ObjectNodeSchema) {
178
- const inputWithDefaults: Record<string, InsertableContent | undefined> = {};
179
+ const contentWithDefaults: Record<string, InsertableContent | undefined> = {};
179
180
  for (const [key, field] of schema.fields) {
180
- if (value[key] === undefined) {
181
+ if (content[key] === undefined) {
181
182
  if (
182
183
  typeof field.metadata.custom === "object" &&
183
184
  field.metadata.custom !== null &&
@@ -187,17 +188,19 @@ function constructTreeNode(schema: TreeNodeSchema, value: FactoryContentObject):
187
188
  if (typeof defaulter === "function") {
188
189
  const defaultValue: unknown = defaulter();
189
190
  if (defaultValue !== undefined) {
190
- inputWithDefaults[key] = defaultValue;
191
+ contentWithDefaults[key] = defaultValue;
191
192
  }
192
193
  }
193
194
  }
194
195
  } else {
195
- inputWithDefaults[key] = value[key];
196
+ contentWithDefaults[key] = content[key];
196
197
  }
197
198
  }
198
- return constructNode(schema, inputWithDefaults);
199
+ toInsert = contentWithDefaults;
199
200
  }
200
- return constructNode(schema, value);
201
+
202
+ // Cast to never because tagContentSchema is typed to only accept InsertableContent, but we know that 'toInsert' (either the original content or contentWithDefaults) produces valid content for the schema.
203
+ return TreeAlpha.tagContentSchema(schema, toInsert as never);
201
204
  }
202
205
 
203
206
  /**
@@ -298,8 +301,8 @@ function bindEditorToSubtree<TSchema extends ImplicitFieldSchema>(
298
301
  // Stick the tree schema constructors on an object passed to the function so that the LLM can create new nodes.
299
302
  const create: Record<string, (input: FactoryContentObject) => TreeNode> = {};
300
303
  const is: Record<string, <T extends TreeNode>(input: unknown) => input is T> = {};
301
- for (const schema of findNamedSchemas(tree.schema)) {
302
- const name = getFriendlyName(schema);
304
+ for (const schema of findSchemas(tree.schema, (s) => isNamedSchema(s.identifier))) {
305
+ const name = unqualifySchema(schema.identifier);
303
306
  create[name] = (input: FactoryContentObject) => constructTreeNode(schema, input);
304
307
  is[name] = <T extends TreeNode>(input: unknown): input is T => Tree.is(input, schema);
305
308
  }
package/src/prompt.ts CHANGED
@@ -19,6 +19,7 @@ import {
19
19
  communize,
20
20
  unqualifySchema,
21
21
  type SchemaDetails,
22
+ findSchemas,
22
23
  } from "./utils.js";
23
24
 
24
25
  /**
@@ -33,7 +34,6 @@ export function getPrompt<TRoot extends ImplicitFieldSchema>(args: {
33
34
  const { field, schema } = subtree;
34
35
  const arrayInterfaceName = "TreeArray";
35
36
  const mapInterfaceName = "TreeMap";
36
- const simpleSchema = getSimpleSchema(schema);
37
37
  // Inspect the schema to determine what kinds of nodes are possible - this will affect how much information we need to include in the prompt.
38
38
  const rootTypes = [...normalizeFieldSchema(schema).allowedTypeSet];
39
39
  const rootTypeUnion = `${rootTypes.map((t) => getFriendlyName(t)).join(" | ")}`;
@@ -41,15 +41,15 @@ export function getPrompt<TRoot extends ImplicitFieldSchema>(args: {
41
41
  let hasArrays = false;
42
42
  let hasMaps = false;
43
43
  let exampleObjectName: string | undefined;
44
- for (const [definition, nodeSchema] of simpleSchema.definitions) {
45
- if (nodeSchema.kind !== NodeKind.Leaf) {
44
+ for (const s of findSchemas(schema)) {
45
+ if (s.kind !== NodeKind.Leaf) {
46
46
  nodeTypeUnion =
47
47
  nodeTypeUnion === undefined
48
- ? unqualifySchema(definition)
49
- : `${nodeTypeUnion} | ${unqualifySchema(definition)}`;
48
+ ? getFriendlyName(s)
49
+ : `${nodeTypeUnion} | ${getFriendlyName(s)}`;
50
50
  }
51
51
 
52
- switch (nodeSchema.kind) {
52
+ switch (s.kind) {
53
53
  case NodeKind.Array: {
54
54
  hasArrays = true;
55
55
  break;
@@ -59,14 +59,14 @@ export function getPrompt<TRoot extends ImplicitFieldSchema>(args: {
59
59
  break;
60
60
  }
61
61
  case NodeKind.Object: {
62
- exampleObjectName ??= unqualifySchema(definition);
62
+ exampleObjectName ??= getFriendlyName(s);
63
63
  break;
64
64
  }
65
65
  // No default
66
66
  }
67
67
  }
68
68
 
69
- const { domainTypes } = generateEditTypesForPrompt(schema, simpleSchema);
69
+ const { domainTypes } = generateEditTypesForPrompt(schema, getSimpleSchema(schema));
70
70
  for (const [key, value] of Object.entries(domainTypes)) {
71
71
  // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
72
72
  delete domainTypes[key];
package/src/subtree.ts CHANGED
@@ -17,9 +17,9 @@ import { TreeAlpha } from "@fluidframework/tree/alpha";
17
17
  import type {
18
18
  UnsafeUnknownSchema,
19
19
  ReadableField,
20
- TreeBranch,
21
20
  TreeRecordNode,
22
21
  ReadSchema,
22
+ TreeBranchAlpha,
23
23
  } from "@fluidframework/tree/alpha";
24
24
 
25
25
  import { getNodeOnBranch } from "./getNodeOnBranch.js";
@@ -37,7 +37,7 @@ export class Subtree<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema> {
37
37
  }
38
38
  }
39
39
 
40
- public get branch(): TreeBranch {
40
+ public get branch(): TreeBranchAlpha {
41
41
  return this.viewOrNode instanceof TreeNode
42
42
  ? (TreeAlpha.branch(this.viewOrNode) ?? fail("Node cannot be raw."))
43
43
  : this.viewOrNode;
package/src/utils.ts CHANGED
@@ -12,7 +12,7 @@ import { UsageError } from "@fluidframework/telemetry-utils/internal";
12
12
  import type { ImplicitFieldSchema, TreeNodeSchemaClass } from "@fluidframework/tree";
13
13
  import type {
14
14
  InsertableContent,
15
- TreeBranch,
15
+ TreeBranchAlpha,
16
16
  TreeNode,
17
17
  TreeNodeSchema,
18
18
  TreeViewAlpha,
@@ -95,7 +95,7 @@ export type TreeView<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema> =
95
95
  TreeViewAlpha<TRoot>,
96
96
  "root" | "fork" | "merge" | "rebaseOnto" | "schema" | "events"
97
97
  > &
98
- TreeBranch;
98
+ TreeBranchAlpha;
99
99
 
100
100
  /**
101
101
  * TODO
@@ -592,25 +592,23 @@ export function instanceOf<T extends TreeNodeSchemaClass>(
592
592
  const instanceOfs = new WeakMap<z.ZodTypeAny, ObjectNodeSchema>();
593
593
 
594
594
  /**
595
- * Adds all named object, map, array, and record schemas reachable from the given schema to the given set.
596
- * @remarks This includes transitive child/descendant schemas.
597
- * It does not include primitive schemas or inlined array/map/record schemas.
598
- * @returns The set of named schemas added (same as the `schemas` parameter, if supplied).
595
+ * Adds all (optionally filtered) schemas reachable from the given schema to the given set.
596
+ * @returns The set of schemas added (same as the `schemas` parameter, if supplied).
599
597
  */
600
- export function findNamedSchemas(
598
+ export function findSchemas(
601
599
  schema: ImplicitFieldSchema,
600
+ filter: (schema: TreeNodeSchema) => boolean = () => true,
602
601
  schemas = new Set<TreeNodeSchema>(),
603
602
  ): Set<TreeNodeSchema> {
604
- const set = schemas ?? new Set();
605
603
  for (const nodeSchema of normalizeFieldSchema(schema).allowedTypeSet) {
606
- if (!set.has(nodeSchema)) {
607
- if (isNamedSchema(nodeSchema.identifier)) {
608
- set.add(nodeSchema);
604
+ if (!schemas.has(nodeSchema)) {
605
+ if (filter(nodeSchema)) {
606
+ schemas.add(nodeSchema);
609
607
  }
610
- findNamedSchemas([...nodeSchema.childTypes], set);
608
+ findSchemas([...nodeSchema.childTypes], filter, schemas);
611
609
  }
612
610
  }
613
- return set;
611
+ return schemas;
614
612
  }
615
613
 
616
614
  /**