@fluidframework/tree-agent 2.74.0 → 2.81.0-374083

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/api-report/tree-agent.alpha.api.md +163 -20
  3. package/dist/alpha.d.ts +26 -1
  4. package/dist/index.d.ts +3 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +5 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/methodBinding.d.ts +54 -10
  9. package/dist/methodBinding.d.ts.map +1 -1
  10. package/dist/methodBinding.js.map +1 -1
  11. package/dist/propertyBinding.d.ts +52 -2
  12. package/dist/propertyBinding.d.ts.map +1 -1
  13. package/dist/propertyBinding.js +28 -3
  14. package/dist/propertyBinding.js.map +1 -1
  15. package/dist/renderSchemaTypeScript.d.ts.map +1 -1
  16. package/dist/renderSchemaTypeScript.js +17 -8
  17. package/dist/renderSchemaTypeScript.js.map +1 -1
  18. package/dist/renderTypeFactoryTypeScript.d.ts +13 -0
  19. package/dist/renderTypeFactoryTypeScript.d.ts.map +1 -0
  20. package/dist/renderTypeFactoryTypeScript.js +222 -0
  21. package/dist/renderTypeFactoryTypeScript.js.map +1 -0
  22. package/dist/subtree.d.ts.map +1 -1
  23. package/dist/subtree.js +4 -4
  24. package/dist/subtree.js.map +1 -1
  25. package/dist/treeAgentTypes.d.ts +345 -0
  26. package/dist/treeAgentTypes.d.ts.map +1 -0
  27. package/dist/treeAgentTypes.js +190 -0
  28. package/dist/treeAgentTypes.js.map +1 -0
  29. package/dist/utils.d.ts +0 -4
  30. package/dist/utils.d.ts.map +1 -1
  31. package/dist/utils.js +2 -9
  32. package/dist/utils.js.map +1 -1
  33. package/eslint.config.mts +4 -4
  34. package/lib/alpha.d.ts +26 -1
  35. package/lib/index.d.ts +3 -1
  36. package/lib/index.d.ts.map +1 -1
  37. package/lib/index.js +1 -0
  38. package/lib/index.js.map +1 -1
  39. package/lib/methodBinding.d.ts +54 -10
  40. package/lib/methodBinding.d.ts.map +1 -1
  41. package/lib/methodBinding.js.map +1 -1
  42. package/lib/propertyBinding.d.ts +52 -2
  43. package/lib/propertyBinding.d.ts.map +1 -1
  44. package/lib/propertyBinding.js +28 -3
  45. package/lib/propertyBinding.js.map +1 -1
  46. package/lib/renderSchemaTypeScript.d.ts.map +1 -1
  47. package/lib/renderSchemaTypeScript.js +17 -8
  48. package/lib/renderSchemaTypeScript.js.map +1 -1
  49. package/lib/renderTypeFactoryTypeScript.d.ts +13 -0
  50. package/lib/renderTypeFactoryTypeScript.d.ts.map +1 -0
  51. package/lib/renderTypeFactoryTypeScript.js +217 -0
  52. package/lib/renderTypeFactoryTypeScript.js.map +1 -0
  53. package/lib/subtree.d.ts.map +1 -1
  54. package/lib/subtree.js +4 -4
  55. package/lib/subtree.js.map +1 -1
  56. package/lib/treeAgentTypes.d.ts +345 -0
  57. package/lib/treeAgentTypes.d.ts.map +1 -0
  58. package/lib/treeAgentTypes.js +186 -0
  59. package/lib/treeAgentTypes.js.map +1 -0
  60. package/lib/utils.d.ts +0 -4
  61. package/lib/utils.d.ts.map +1 -1
  62. package/lib/utils.js +2 -8
  63. package/lib/utils.js.map +1 -1
  64. package/package.json +17 -17
  65. package/src/index.ts +31 -0
  66. package/src/methodBinding.ts +94 -15
  67. package/src/propertyBinding.ts +66 -9
  68. package/src/renderSchemaTypeScript.ts +25 -9
  69. package/src/renderTypeFactoryTypeScript.ts +259 -0
  70. package/src/subtree.ts +6 -5
  71. package/src/treeAgentTypes.ts +490 -0
  72. package/src/utils.ts +2 -9
  73. package/.eslintrc.cjs +0 -48
@@ -1 +1 @@
1
- {"version":3,"file":"propertyBinding.d.ts","sourceRoot":"","sources":["../src/propertyBinding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChF,OAAO,KAAK,EAAE,OAAO,EAAE,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AC,SAAS,mBAAmB,EACvC,MAAM,EAAE,CAAC,GACP,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;CACzD;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,kBAAkB;IAClC;;OAEG;IACH,CAAC,sBAAsB,CAAC,CAAC,CAAC,UAAU,EAAE,iBAAiB,GAAG,IAAI,CAAC;CAC/D;AAkED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,cAAc,GAAG;IAClE,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACxC,eAAe,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC;CACrC,CAEA"}
@@ -6,6 +6,7 @@
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.getExposedProperties = exports.PropertyDef = exports.exposePropertiesSymbol = void 0;
8
8
  const renderZodTypeScript_js_1 = require("./renderZodTypeScript.js");
9
+ const treeAgentTypes_js_1 = require("./treeAgentTypes.js");
9
10
  /**
10
11
  * A symbol used to expose properties to the LLM.
11
12
  * @alpha
@@ -16,7 +17,23 @@ exports.exposePropertiesSymbol = Symbol.for("@fluidframework/tree-agent/exposePr
16
17
  * @alpha
17
18
  */
18
19
  class PropertyDef {
19
- constructor(name, description, schema, readOnly) {
20
+ constructor(
21
+ /**
22
+ * The name of the property.
23
+ */
24
+ name,
25
+ /**
26
+ * Optional description of the property.
27
+ */
28
+ description,
29
+ /**
30
+ * The schema defining the property's type (either Zod or TypeFactory).
31
+ */
32
+ schema,
33
+ /**
34
+ * Whether the property is readonly.
35
+ */
36
+ readOnly) {
20
37
  this.name = name;
21
38
  this.description = description;
22
39
  this.schema = schema;
@@ -30,11 +47,19 @@ class ExposedPropertiesI {
30
47
  this.properties = {};
31
48
  this.referencedTypes = new Set();
32
49
  }
33
- exposeProperty(schema, name, def) {
50
+ exposeProperty(schema, name, defOrType) {
34
51
  if (schema !== this.schemaClass) {
35
52
  throw new Error('Must expose properties on the "this" schema class');
36
53
  }
37
- this.properties[name] = new PropertyDef(name, def.description, def.schema, def.readOnly === true);
54
+ // Handle TypeFactoryType (simple case - type passed directly)
55
+ if ((0, treeAgentTypes_js_1.isTypeFactoryType)(defOrType)) {
56
+ this.properties[name] = new PropertyDef(name, undefined, defOrType, false);
57
+ }
58
+ else {
59
+ // Handle object with schema property (works for both Zod and TypeFactory)
60
+ const def = defOrType;
61
+ this.properties[name] = new PropertyDef(name, def.description, def.schema, def.readOnly === true);
62
+ }
38
63
  }
39
64
  instanceOf(schema) {
40
65
  this.referencedTypes.add(schema);
@@ -1 +1 @@
1
- {"version":3,"file":"propertyBinding.js","sourceRoot":"","sources":["../src/propertyBinding.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,qEAAsD;AAEtD;;;GAGG;AACU,QAAA,sBAAsB,GAAkB,MAAM,CAAC,GAAG,CAC9D,6CAA6C,CAC7C,CAAC;AAmDF;;;GAGG;AACH,MAAa,WAAW;IACvB,YACiB,IAAY,EACZ,WAA+B,EAC/B,MAAkB,EAClB,QAAiB;QAHjB,SAAI,GAAJ,IAAI,CAAQ;QACZ,gBAAW,GAAX,WAAW,CAAoB;QAC/B,WAAM,GAAN,MAAM,CAAY;QAClB,aAAQ,GAAR,QAAQ,CAAS;IAC/B,CAAC;CACJ;AAPD,kCAOC;AAyCD,MAAM,kBAAkB;IAIvB,YAAoC,WAA2B;QAA3B,gBAAW,GAAX,WAAW,CAAgB;QAH9C,eAAU,GAAgC,EAAE,CAAC;QAC7C,oBAAe,GAAG,IAAI,GAAG,EAAkB,CAAC;IAEK,CAAC;IAE5D,cAAc,CAKpB,MAAS,EACT,IAAO,EACP,GACmD;QAEnD,IAAI,MAAM,KAAK,IAAI,CAAC,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;QACtE,CAAC;QACD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,IAAI,WAAW,CACtC,IAAI,EACJ,GAAG,CAAC,WAAW,EACf,GAAG,CAAC,MAAM,EACV,GAAG,CAAC,QAAQ,KAAK,IAAI,CACrB,CAAC;IACH,CAAC;IAEM,UAAU,CAChB,MAAS;QAET,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACjC,OAAO,IAAA,mCAAU,EAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IAEM,MAAM,CAAC,oBAAoB,CAAC,WAA2B;QAI7D,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC,WAAW,CAAC,CAAC;QACpD,MAAM,WAAW,GAAG,WAA4C,CAAC;QACjE,IAAI,WAAW,CAAC,8BAAsB,CAAC,KAAK,SAAS,EAAE,CAAC;YACvD,WAAW,CAAC,8BAAsB,CAAC,CAAC,OAAO,CAAC,CAAC;QAC9C,CAAC;QACD,OAAO;YACN,UAAU,EAAE,OAAO,CAAC,UAAU;YAC9B,eAAe,EAAE,OAAO,CAAC,eAAe;SACxC,CAAC;IACH,CAAC;CACD;AAED;;;;GAIG;AACH,SAAgB,oBAAoB,CAAC,WAA2B;IAI/D,OAAO,kBAAkB,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;AAC7D,CAAC;AALD,oDAKC","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-explicit-any */\nimport type { TreeNodeSchema, TreeNodeSchemaClass } from \"@fluidframework/tree\";\nimport type { ZodType, ZodTypeAny, ZodTypeDef, infer as ZodInfer } from \"zod\";\n\nimport type { BindableSchema, Ctor } from \"./methodBinding.js\";\nimport { instanceOf } from \"./renderZodTypeScript.js\";\n\n/**\n * A symbol used to expose properties to the LLM.\n * @alpha\n */\nexport const exposePropertiesSymbol: unique symbol = Symbol.for(\n\t\"@fluidframework/tree-agent/exposeProperties\",\n);\n\n/**\n * Set of property keys from `T` that are not methods.\n * @alpha\n */\nexport type ExposableKeys<T> = {\n\t[K in keyof T]?: T[K] extends (...args: any[]) => any ? never : K;\n}[keyof T];\n\n/**\n * Type-level equality test used as a helper to evaluate readonly keys.\n * - If X and Y are the same type, it evaluates to A.\n * - If X and Y are different, it evaluates to B.\n * @alpha\n */\nexport type IfEquals<X, Y, A = true, B = false> = (<T>() => T extends X ? 1 : 2) extends <\n\tT,\n>() => T extends Y ? 1 : 2\n\t? A\n\t: B;\n\n/**\n * Produces a union of keys of `T` which are readonly.\n * @alpha\n */\nexport type ReadonlyKeys<T> = {\n\t// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style\n\t[P in keyof T]-?: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, never, P>;\n}[keyof T];\n\n/**\n * Type to enforce `readOnly: true` for readonly properties.\n * @alpha\n */\nexport type ReadOnlyRequirement<TObj, K extends keyof TObj> = {\n\t[P in K]-?: P extends ReadonlyKeys<TObj> ? { readOnly: true } : { readOnly?: false };\n}[K];\n\n/**\n * Emits compile-time error when there is a type mismatch.\n * @alpha\n */\nexport type TypeMatchOrError<Expected, Received> = [Received] extends [Expected]\n\t? unknown\n\t: {\n\t\t\t__error__: \"Zod schema value type does not match the property's declared type\";\n\t\t\texpected: Expected;\n\t\t\treceived: Received;\n\t\t};\n\n/**\n * A property definition class that describes the structure of the property\n * @alpha\n */\nexport class PropertyDef {\n\tpublic constructor(\n\t\tpublic readonly name: string,\n\t\tpublic readonly description: string | undefined,\n\t\tpublic readonly schema: ZodTypeAny,\n\t\tpublic readonly readOnly: boolean,\n\t) {}\n}\n\n/**\n * An interface for exposing properties of schema classes to an agent.\n * @alpha\n */\nexport interface ExposedProperties {\n\texposeProperty<\n\t\tS extends BindableSchema & Ctor,\n\t\tK extends string & ExposableKeys<InstanceType<S>>,\n\t\tTZ extends ZodTypeAny,\n\t>(\n\t\tschema: S,\n\t\tname: K,\n\t\tdef: { schema: TZ; description?: string } & ReadOnlyRequirement<InstanceType<S>, K> &\n\t\t\tTypeMatchOrError<InstanceType<S>[K], ZodInfer<TZ>>,\n\t): void;\n\n\tinstanceOf<T extends TreeNodeSchemaClass>(\n\t\tschema: T,\n\t): ZodType<InstanceType<T>, ZodTypeDef, InstanceType<T>>;\n}\n\n/**\n * An interface that SharedTree schema classes should implement to expose their properties to the LLM.\n *\n * @remarks\n * The `getExposedProperties` free function will cause the method here to be called on the class passed to it.\n *\n * @privateremarks\n * Implementing this interface correctly seems tricky?\n * To actually implement it in a way that satisfies TypeScript,\n * classes need to declare both a static version and an instance version of the method\n * (the instance one can just delegate to the static one).\n *\n * @alpha\n */\nexport interface IExposedProperties {\n\t[exposePropertiesSymbol]?(properties: ExposedProperties): void;\n}\n\nclass ExposedPropertiesI implements ExposedProperties {\n\tprivate readonly properties: Record<string, PropertyDef> = {};\n\tprivate readonly referencedTypes = new Set<TreeNodeSchema>();\n\n\tpublic constructor(private readonly schemaClass: BindableSchema) {}\n\n\tpublic exposeProperty<\n\t\tS extends BindableSchema & Ctor,\n\t\tK extends string & ExposableKeys<InstanceType<S>>,\n\t\tTZ extends ZodTypeAny,\n\t>(\n\t\tschema: S,\n\t\tname: K,\n\t\tdef: { schema: TZ; description?: string } & ReadOnlyRequirement<InstanceType<S>, K> &\n\t\t\tTypeMatchOrError<InstanceType<S>[K], ZodInfer<TZ>>,\n\t): void {\n\t\tif (schema !== this.schemaClass) {\n\t\t\tthrow new Error('Must expose properties on the \"this\" schema class');\n\t\t}\n\t\tthis.properties[name] = new PropertyDef(\n\t\t\tname,\n\t\t\tdef.description,\n\t\t\tdef.schema,\n\t\t\tdef.readOnly === true,\n\t\t);\n\t}\n\n\tpublic instanceOf<T extends TreeNodeSchemaClass>(\n\t\tschema: T,\n\t): ZodType<InstanceType<T>, ZodTypeDef, InstanceType<T>> {\n\t\tthis.referencedTypes.add(schema);\n\t\treturn instanceOf(schema);\n\t}\n\n\tpublic static getExposedProperties(schemaClass: BindableSchema): {\n\t\tproperties: Record<string, PropertyDef>;\n\t\treferencedTypes: Set<TreeNodeSchema>;\n\t} {\n\t\tconst exposed = new ExposedPropertiesI(schemaClass);\n\t\tconst extractable = schemaClass as unknown as IExposedProperties;\n\t\tif (extractable[exposePropertiesSymbol] !== undefined) {\n\t\t\textractable[exposePropertiesSymbol](exposed);\n\t\t}\n\t\treturn {\n\t\t\tproperties: exposed.properties,\n\t\t\treferencedTypes: exposed.referencedTypes,\n\t\t};\n\t}\n}\n\n/**\n * Get the exposed properties of a schema class.\n * @param schemaClass - The schema class to extract properties from.\n * @returns A record of property names and their corresponding Zod types.\n */\nexport function getExposedProperties(schemaClass: BindableSchema): {\n\tproperties: Record<string, PropertyDef>;\n\treferencedTypes: Set<TreeNodeSchema>;\n} {\n\treturn ExposedPropertiesI.getExposedProperties(schemaClass);\n}\n"]}
1
+ {"version":3,"file":"propertyBinding.js","sourceRoot":"","sources":["../src/propertyBinding.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,qEAAsD;AAEtD,2DAAwD;AAExD;;;GAGG;AACU,QAAA,sBAAsB,GAAkB,MAAM,CAAC,GAAG,CAC9D,6CAA6C,CAC7C,CAAC;AAmDF;;;GAGG;AACH,MAAa,WAAW;IACvB;IACC;;OAEG;IACa,IAAY;IAC5B;;OAEG;IACa,WAA+B;IAC/C;;OAEG;IACa,MAAoC;IACpD;;OAEG;IACa,QAAiB;QAZjB,SAAI,GAAJ,IAAI,CAAQ;QAIZ,gBAAW,GAAX,WAAW,CAAoB;QAI/B,WAAM,GAAN,MAAM,CAA8B;QAIpC,aAAQ,GAAR,QAAQ,CAAS;IAC/B,CAAC;CACJ;AAnBD,kCAmBC;AAsED,MAAM,kBAAkB;IAIvB,YAAoC,WAA2B;QAA3B,gBAAW,GAAX,WAAW,CAAgB;QAH9C,eAAU,GAAgC,EAAE,CAAC;QAC7C,oBAAe,GAAG,IAAI,GAAG,EAAkB,CAAC;IAEK,CAAC;IAE5D,cAAc,CAKpB,MAAS,EACT,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D,CAAC;AALD,oDAKC","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-explicit-any */\nimport type { TreeNodeSchema, TreeNodeSchemaClass } from \"@fluidframework/tree\";\nimport type { ZodType, ZodTypeAny, ZodTypeDef, infer as ZodInfer } from \"zod\";\n\nimport type { BindableSchema, Ctor } from \"./methodBinding.js\";\nimport { instanceOf } from \"./renderZodTypeScript.js\";\nimport type { TypeFactoryType } from \"./treeAgentTypes.js\";\nimport { isTypeFactoryType } from \"./treeAgentTypes.js\";\n\n/**\n * A symbol used to expose properties to the LLM.\n * @alpha\n */\nexport const exposePropertiesSymbol: unique symbol = Symbol.for(\n\t\"@fluidframework/tree-agent/exposeProperties\",\n);\n\n/**\n * Set of property keys from `T` that are not methods.\n * @alpha\n */\nexport type ExposableKeys<T> = {\n\t[K in keyof T]?: T[K] extends (...args: any[]) => any ? never : K;\n}[keyof T];\n\n/**\n * Type-level equality test used as a helper to evaluate readonly keys.\n * - If X and Y are the same type, it evaluates to A.\n * - If X and Y are different, it evaluates to B.\n * @alpha\n */\nexport type IfEquals<X, Y, A = true, B = false> = (<T>() => T extends X ? 1 : 2) extends <\n\tT,\n>() => T extends Y ? 1 : 2\n\t? A\n\t: B;\n\n/**\n * Produces a union of keys of `T` which are readonly.\n * @alpha\n */\nexport type ReadonlyKeys<T> = {\n\t// eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style\n\t[P in keyof T]-?: IfEquals<{ [Q in P]: T[P] }, { -readonly [Q in P]: T[P] }, never, P>;\n}[keyof T];\n\n/**\n * Type to enforce `readOnly: true` for readonly properties.\n * @alpha\n */\nexport type ReadOnlyRequirement<TObj, K extends keyof TObj> = {\n\t[P in K]-?: P extends ReadonlyKeys<TObj> ? { readOnly: true } : { readOnly?: false };\n}[K];\n\n/**\n * Emits compile-time error when there is a type mismatch.\n * @alpha\n */\nexport type TypeMatchOrError<Expected, Received> = [Received] extends [Expected]\n\t? unknown\n\t: {\n\t\t\t__error__: \"Zod schema value type does not match the property's declared type\";\n\t\t\texpected: Expected;\n\t\t\treceived: Received;\n\t\t};\n\n/**\n * A property definition class that describes the structure of the property\n * @alpha\n */\nexport class PropertyDef {\n\tpublic constructor(\n\t\t/**\n\t\t * The name of the property.\n\t\t */\n\t\tpublic readonly name: string,\n\t\t/**\n\t\t * Optional description of the property.\n\t\t */\n\t\tpublic readonly description: string | undefined,\n\t\t/**\n\t\t * The schema defining the property's type (either Zod or TypeFactory).\n\t\t */\n\t\tpublic readonly schema: ZodTypeAny | TypeFactoryType,\n\t\t/**\n\t\t * Whether the property is readonly.\n\t\t */\n\t\tpublic readonly readOnly: boolean,\n\t) {}\n}\n\n/**\n * An interface for exposing properties of schema classes to an agent.\n * @alpha\n */\nexport interface ExposedProperties {\n\t/**\n\t * Expose a property with Zod type checking.\n\t */\n\texposeProperty<\n\t\tS extends BindableSchema & Ctor,\n\t\tK extends string & ExposableKeys<InstanceType<S>>,\n\t\tTZ extends ZodTypeAny,\n\t>(\n\t\tschema: S,\n\t\tname: K,\n\t\tdef: { schema: TZ; description?: string } & ReadOnlyRequirement<InstanceType<S>, K> &\n\t\t\tTypeMatchOrError<InstanceType<S>[K], ZodInfer<TZ>>,\n\t): void;\n\n\t/**\n\t * Expose a property with type factory type and metadata.\n\t */\n\texposeProperty<\n\t\tS extends BindableSchema & Ctor,\n\t\tK extends string & ExposableKeys<InstanceType<S>>,\n\t>(\n\t\tschema: S,\n\t\tname: K,\n\t\tdef: { schema: TypeFactoryType; description?: string; readOnly?: boolean },\n\t): void;\n\n\t/**\n\t * Expose a property with type factory type (simple form).\n\t */\n\texposeProperty<\n\t\tS extends BindableSchema & Ctor,\n\t\tK extends string & ExposableKeys<InstanceType<S>>,\n\t>(schema: S, name: K, tfType: TypeFactoryType): void;\n\n\t/**\n\t * Create a Zod type that references a SharedTree schema class.\n\t */\n\tinstanceOf<T extends TreeNodeSchemaClass>(\n\t\tschema: T,\n\t): ZodType<InstanceType<T>, ZodTypeDef, InstanceType<T>>;\n}\n\n/**\n * An interface that SharedTree schema classes should implement to expose their properties to the LLM.\n *\n * @remarks\n * The `getExposedProperties` free function will cause the method here to be called on the class passed to it.\n *\n * @privateremarks\n * Implementing this interface correctly seems tricky?\n * To actually implement it in a way that satisfies TypeScript,\n * classes need to declare both a static version and an instance version of the method\n * (the instance one can just delegate to the static one).\n *\n * @alpha\n */\nexport interface IExposedProperties {\n\t/**\n\t * Static method that exposes properties of this schema class to an agent.\n\t */\n\t[exposePropertiesSymbol]?(properties: ExposedProperties): void;\n}\n\nclass ExposedPropertiesI implements ExposedProperties {\n\tprivate readonly properties: Record<string, PropertyDef> = {};\n\tprivate readonly referencedTypes = new Set<TreeNodeSchema>();\n\n\tpublic constructor(private readonly schemaClass: BindableSchema) {}\n\n\tpublic exposeProperty<\n\t\tS extends BindableSchema & Ctor,\n\t\tK extends string & ExposableKeys<InstanceType<S>>,\n\t\tTZ extends ZodTypeAny,\n\t>(\n\t\tschema: S,\n\t\tname: K,\n\t\tdefOrType:\n\t\t\t| ({ schema: TZ; description?: string } & ReadOnlyRequirement<InstanceType<S>, K> &\n\t\t\t\t\tTypeMatchOrError<InstanceType<S>[K], ZodInfer<TZ>>)\n\t\t\t| TypeFactoryType,\n\t): void {\n\t\tif (schema !== this.schemaClass) {\n\t\t\tthrow new Error('Must expose properties on the \"this\" schema class');\n\t\t}\n\n\t\t// Handle TypeFactoryType (simple case - type passed directly)\n\t\tif (isTypeFactoryType(defOrType)) {\n\t\t\tthis.properties[name] = new PropertyDef(name, undefined, defOrType, false);\n\t\t} else {\n\t\t\t// Handle object with schema property (works for both Zod and TypeFactory)\n\t\t\tconst def = defOrType as {\n\t\t\t\tschema: TZ | TypeFactoryType;\n\t\t\t\tdescription?: string;\n\t\t\t\treadOnly?: boolean;\n\t\t\t};\n\t\t\tthis.properties[name] = new PropertyDef(\n\t\t\t\tname,\n\t\t\t\tdef.description,\n\t\t\t\tdef.schema,\n\t\t\t\tdef.readOnly === true,\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic instanceOf<T extends TreeNodeSchemaClass>(\n\t\tschema: T,\n\t): ZodType<InstanceType<T>, ZodTypeDef, InstanceType<T>> {\n\t\tthis.referencedTypes.add(schema);\n\t\treturn instanceOf(schema);\n\t}\n\n\tpublic static getExposedProperties(schemaClass: BindableSchema): {\n\t\tproperties: Record<string, PropertyDef>;\n\t\treferencedTypes: Set<TreeNodeSchema>;\n\t} {\n\t\tconst exposed = new ExposedPropertiesI(schemaClass);\n\t\tconst extractable = schemaClass as unknown as IExposedProperties;\n\t\tif (extractable[exposePropertiesSymbol] !== undefined) {\n\t\t\textractable[exposePropertiesSymbol](exposed);\n\t\t}\n\t\treturn {\n\t\t\tproperties: exposed.properties,\n\t\t\treferencedTypes: exposed.referencedTypes,\n\t\t};\n\t}\n}\n\n/**\n * Get the exposed properties of a schema class.\n * @param schemaClass - The schema class to extract properties from.\n * @returns A record of property names and their corresponding Zod types.\n */\nexport function getExposedProperties(schemaClass: BindableSchema): {\n\tproperties: Record<string, PropertyDef>;\n\treferencedTypes: Set<TreeNodeSchema>;\n} {\n\treturn ExposedPropertiesI.getExposedProperties(schemaClass);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"renderSchemaTypeScript.d.ts","sourceRoot":"","sources":["../src/renderSchemaTypeScript.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAIX,gBAAgB,EAGhB,MAAM,+BAA+B,CAAC;AAGvC,OAAO,KAAK,EAAE,cAAc,EAAmB,MAAM,oBAAoB,CAAC;AAiC1E;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC5C,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACrC,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,EAClD,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,GAC1C,4BAA4B,CAkV9B"}
1
+ {"version":3,"file":"renderSchemaTypeScript.d.ts","sourceRoot":"","sources":["../src/renderSchemaTypeScript.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAIX,gBAAgB,EAGhB,MAAM,+BAA+B,CAAC;AAGvC,OAAO,KAAK,EAAE,cAAc,EAAmB,MAAM,oBAAoB,CAAC;AAuC1E;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC5C,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,EAAE,OAAO,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACrC,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,EAClD,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,GAC1C,4BAA4B,CAkV9B"}
@@ -10,8 +10,10 @@ const internal_2 = require("@fluidframework/tree/internal");
10
10
  const zod_1 = require("zod");
11
11
  const methodBinding_js_1 = require("./methodBinding.js");
12
12
  const propertyBinding_js_1 = require("./propertyBinding.js");
13
- const utils_js_1 = require("./utils.js");
13
+ const renderTypeFactoryTypeScript_js_1 = require("./renderTypeFactoryTypeScript.js");
14
14
  const renderZodTypeScript_js_1 = require("./renderZodTypeScript.js");
15
+ const treeAgentTypes_js_1 = require("./treeAgentTypes.js");
16
+ const utils_js_1 = require("./utils.js");
15
17
  var TypePrecedence;
16
18
  (function (TypePrecedence) {
17
19
  TypePrecedence[TypePrecedence["Union"] = 0] = "Union";
@@ -327,7 +329,7 @@ function renderPropertyLines(properties) {
327
329
  }
328
330
  }
329
331
  const modifier = property.readOnly ? "readonly " : "";
330
- lines.push(`${modifier}${name}: ${renderZodType(property.schema)};`);
332
+ lines.push(`${modifier}${name}: ${renderType(property.schema)};`);
331
333
  }
332
334
  return lines;
333
335
  }
@@ -335,13 +337,13 @@ function formatMethod(name, method) {
335
337
  const args = [];
336
338
  for (const [argName, argType] of method.args) {
337
339
  const { innerType, optional } = unwrapOptional(argType);
338
- const renderedType = renderZodType(innerType);
340
+ const renderedType = renderType(innerType);
339
341
  args.push(`${argName}${optional ? "?" : ""}: ${renderedType}`);
340
342
  }
341
343
  if (method.rest !== null) {
342
- args.push(`...rest: ${renderZodType(method.rest)}[]`);
344
+ args.push(`...rest: ${renderType(method.rest)}[]`);
343
345
  }
344
- return `${name}(${args.join(", ")}): ${renderZodType(method.returns)};`;
346
+ return `${name}(${args.join(", ")}): ${renderType(method.returns)};`;
345
347
  }
346
348
  function renderLeaf(leafKind) {
347
349
  switch (leafKind) {
@@ -369,6 +371,11 @@ function formatExpression(expression, minPrecedence = 2 /* TypePrecedence.Object
369
371
  * Detects optional zod wrappers so argument lists can keep TypeScript optional markers in sync.
370
372
  */
371
373
  function unwrapOptional(type) {
374
+ // Handle type factory optional type
375
+ if ((0, treeAgentTypes_js_1.isTypeFactoryType)(type) && type._kind === "optional") {
376
+ return { innerType: type.innerType, optional: true };
377
+ }
378
+ // Handle Zod optional type
372
379
  if (type instanceof zod_1.z.ZodOptional) {
373
380
  const inner = type.unwrap();
374
381
  return { innerType: inner, optional: true };
@@ -391,9 +398,11 @@ function ensureNoMemberConflicts(definition, fieldNames, methods, properties) {
391
398
  }
392
399
  }
393
400
  /**
394
- * Converts schema metadata into TypeScript declarations suitable for prompt inclusion.
401
+ * Dispatches to the correct renderer based on whether the type is Zod or type factory.
395
402
  */
396
- function renderZodType(type) {
397
- return (0, renderZodTypeScript_js_1.renderZodTypeScript)(type, utils_js_1.getFriendlyName, renderZodTypeScript_js_1.instanceOfs);
403
+ function renderType(type) {
404
+ return (0, treeAgentTypes_js_1.isTypeFactoryType)(type)
405
+ ? (0, renderTypeFactoryTypeScript_js_1.renderTypeFactoryTypeScript)(type, utils_js_1.getFriendlyName, renderTypeFactoryTypeScript_js_1.instanceOfsTypeFactory)
406
+ : (0, renderZodTypeScript_js_1.renderZodTypeScript)(type, utils_js_1.getFriendlyName, renderZodTypeScript_js_1.instanceOfs);
398
407
  }
399
408
  //# sourceMappingURL=renderSchemaTypeScript.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"renderSchemaTypeScript.js","sourceRoot":"","sources":["../src/renderSchemaTypeScript.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,uEAAsE;AACtE,4DAAiF;AASjF,6BAAwB;AAGxB,yDAAuD;AACvD,6DAA8E;AAC9E,yCAAyF;AACzF,qEAA4E;AAuB5E,IAAW,cAIV;AAJD,WAAW,cAAc;IACxB,qDAAS,CAAA;IACT,mEAAgB,CAAA;IAChB,uDAAU,CAAA;AACX,CAAC,EAJU,cAAc,KAAd,cAAc,QAIxB;AAUD;;GAEG;AACH,SAAgB,sBAAsB,CACrC,WAAkD,EAClD,eAA4C;IAE5C,MAAM,aAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;IAChD,IAAI,gBAAgB,GAAG,KAAK,CAAC;IAE7B,KAAK,MAAM,UAAU,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC;QAC7C,IAAI,IAAA,wBAAa,EAAC,UAAU,CAAC,EAAE,CAAC;YAC/B,aAAa,CAAC,GAAG,CAAC,UAAU,EAAE,IAAA,0BAAe,EAAC,UAAU,CAAC,CAAC,CAAC;QAC5D,CAAC;IACF,CAAC;IAED,MAAM,YAAY,GAAa,EAAE,CAAC;IAClC,KAAK,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC;QAChD,IAAI,CAAC,IAAA,wBAAa,EAAC,UAAU,CAAC,EAAE,CAAC;YAChC,SAAS;QACV,CAAC;QACD,MAAM,YAAY,GAAG,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,IAAA,0BAAe,EAAC,UAAU,CAAC,CAAC;QAClF,MAAM,QAAQ,GAAG,iBAAiB,CAAC,UAAU,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;QACrE,IAAI,QAAQ,KAAK,SAAS,EAAE,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AChF,CAAC;QACH,CAAC;IACF,CAAC;AACF,CAAC;AAED;;GAEG;AACH,SAAS,aAAa,CAAC,IAAkB;IACxC,OAAO,IAAA,4CAAmB,EAAC,IAAI,EAAE,0BAAe,EAAE,oCAAW,CAAC,CAAC;AAChE,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { FieldKind, NodeKind, ValueSchema } from \"@fluidframework/tree/internal\";\nimport type {\n\tSimpleArrayNodeSchema,\n\tSimpleFieldSchema,\n\tSimpleMapNodeSchema,\n\tSimpleNodeSchema,\n\tSimpleObjectNodeSchema,\n\tSimpleRecordNodeSchema,\n} from \"@fluidframework/tree/internal\";\nimport { z } from \"zod\";\n\nimport type { BindableSchema, FunctionWrapper } from \"./methodBinding.js\";\nimport { getExposedMethods } from \"./methodBinding.js\";\nimport { getExposedProperties, type PropertyDef } from \"./propertyBinding.js\";\nimport { getFriendlyName, isNamedSchema, llmDefault, unqualifySchema } from \"./utils.js\";\nimport { instanceOfs, renderZodTypeScript } from \"./renderZodTypeScript.js\";\n\ninterface BoundMembers {\n\tmethods: Record<string, FunctionWrapper>;\n\tproperties: Record<string, PropertyDef>;\n}\n\ninterface RenderResult {\n\tdeclaration: string;\n\tdescription?: string;\n}\n\ninterface BindingIntersectionResult {\n\thasMethods: boolean;\n\thasProperties: boolean;\n\tsuffix: string;\n}\n\ninterface TypeExpression {\n\tprecedence: TypePrecedence;\n\ttext: string;\n}\n\nconst enum TypePrecedence {\n\tUnion = 0,\n\tIntersection = 1,\n\tObject = 2,\n}\n\n/**\n * Output of rendering schema metadata into TypeScript declaration text.\n */\nexport interface SchemaTypeScriptRenderResult {\n\tschemaText: string;\n\thasHelperMethods: boolean;\n}\n\n/**\n * Converts schema metadata into TypeScript declarations suitable for prompt inclusion.\n */\nexport function renderSchemaTypeScript(\n\tdefinitions: ReadonlyMap<string, SimpleNodeSchema>,\n\tbindableSchemas: Map<string, BindableSchema>,\n): SchemaTypeScriptRenderResult {\n\tconst friendlyNames = new Map<string, string>();\n\tlet hasHelperMethods = false;\n\n\tfor (const identifier of definitions.keys()) {\n\t\tif (isNamedSchema(identifier)) {\n\t\t\tfriendlyNames.set(identifier, unqualifySchema(identifier));\n\t\t}\n\t}\n\n\tconst declarations: string[] = [];\n\tfor (const [identifier, schema] of definitions) {\n\t\tif (!isNamedSchema(identifier)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst friendlyName = friendlyNames.get(identifier) ?? unqualifySchema(identifier);\n\t\tconst rendered = renderNamedSchema(identifier, friendlyName, schema);\n\t\tif (rendered === undefined) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst lines: string[] = [];\n\t\tif (rendered.description !== undefined && rendered.description !== \"\") {\n\t\t\tfor (const comment of rendered.description.split(\"\\n\")) {\n\t\t\t\tlines.push(`// ${comment}`);\n\t\t\t}\n\t\t}\n\t\tlines.push(rendered.declaration);\n\t\tdeclarations.push(lines.join(\"\\n\"));\n\t}\n\n\tconst schemaText = declarations.join(\"\\n\\n\");\n\treturn {\n\t\tschemaText: schemaText === \"\" ? \"\" : `${schemaText}\\n`,\n\t\thasHelperMethods,\n\t};\n\n\tfunction renderNamedSchema(\n\t\tidentifier: string,\n\t\tfriendlyName: string,\n\t\tschema: SimpleNodeSchema,\n\t): RenderResult | undefined {\n\t\tswitch (schema.kind) {\n\t\t\tcase NodeKind.Object: {\n\t\t\t\treturn renderObjectDeclaration(identifier, friendlyName, schema);\n\t\t\t}\n\t\t\tcase NodeKind.Array: {\n\t\t\t\treturn renderArrayDeclaration(identifier, friendlyName, schema);\n\t\t\t}\n\t\t\tcase NodeKind.Map: {\n\t\t\t\treturn renderMapDeclaration(identifier, friendlyName, schema);\n\t\t\t}\n\t\t\tcase NodeKind.Record: {\n\t\t\t\treturn renderRecordDeclaration(identifier, friendlyName, schema);\n\t\t\t}\n\t\t\tcase NodeKind.Leaf: {\n\t\t\t\treturn {\n\t\t\t\t\tdeclaration: `type ${friendlyName} = ${renderLeaf(schema.leafKind)};`,\n\t\t\t\t\tdescription: schema.metadata?.description,\n\t\t\t\t};\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction renderObjectDeclaration(\n\t\tdefinition: string,\n\t\tname: string,\n\t\tschema: SimpleObjectNodeSchema,\n\t): RenderResult {\n\t\tconst fieldLines: string[] = [];\n\t\tconst fieldNames = new Set<string>();\n\n\t\tfor (const [fieldName, fieldSchema] of schema.fields) {\n\t\t\tfieldNames.add(fieldName);\n\t\t\tfieldLines.push(...renderFieldLine(fieldName, fieldSchema));\n\t\t}\n\n\t\tconst { methods, properties } = getBoundMembers(definition);\n\t\tensureNoMemberConflicts(definition, fieldNames, methods, properties);\n\t\tfieldLines.push(...renderPropertyLines(properties));\n\t\tfieldLines.push(...renderMethodLines(methods));\n\n\t\tconst members = fieldLines.map((line) => ` ${line}`).join(\"\\n\");\n\t\tconst body = members === \"\" ? \"\" : `\\n${members}`;\n\t\treturn {\n\t\t\tdeclaration: `interface ${name} {${body}\\n}`,\n\t\t\tdescription: schema.metadata?.description,\n\t\t};\n\t}\n\n\tfunction renderArrayDeclaration(\n\t\tdefinition: string,\n\t\tname: string,\n\t\tschema: SimpleArrayNodeSchema,\n\t): RenderResult {\n\t\tconst elementTypes = renderAllowedTypes(schema.simpleAllowedTypes.keys());\n\t\tconst base = `${formatExpression(elementTypes)}[]`;\n\t\tconst binding = renderBindingIntersection(definition);\n\t\treturn {\n\t\t\tdeclaration: `type ${name} = ${base}${binding.suffix};`,\n\t\t\tdescription: describeBinding(schema.metadata?.description, \"array\", binding),\n\t\t};\n\t}\n\n\tfunction renderMapDeclaration(\n\t\tdefinition: string,\n\t\tname: string,\n\t\tschema: SimpleMapNodeSchema,\n\t): RenderResult {\n\t\tconst valueType = renderAllowedTypes(schema.simpleAllowedTypes.keys());\n\t\tconst base = `Map<string, ${valueType.text}>`;\n\t\tconst binding = renderBindingIntersection(definition);\n\t\treturn {\n\t\t\tdeclaration: `type ${name} = ${base}${binding.suffix};`,\n\t\t\tdescription: describeBinding(schema.metadata?.description, \"map\", binding),\n\t\t};\n\t}\n\n\tfunction renderRecordDeclaration(\n\t\tdefinition: string,\n\t\tname: string,\n\t\tschema: SimpleRecordNodeSchema,\n\t): RenderResult {\n\t\tconst valueType = renderAllowedTypes(schema.simpleAllowedTypes.keys());\n\t\tconst base = `Record<string, ${valueType.text}>`;\n\t\tconst binding = renderBindingIntersection(definition);\n\t\treturn {\n\t\t\tdeclaration: `type ${name} = ${base}${binding.suffix};`,\n\t\t\tdescription: describeBinding(schema.metadata?.description, \"record\", binding),\n\t\t};\n\t}\n\n\tfunction renderFieldLine(name: string, field: SimpleFieldSchema): string[] {\n\t\tconst { comment, optional, type } = describeField(field);\n\t\tconst lines: string[] = [];\n\t\tif (comment !== undefined && comment !== \"\") {\n\t\t\tfor (const note of comment.split(\"\\n\")) {\n\t\t\t\tlines.push(`// ${note}`);\n\t\t\t}\n\t\t}\n\t\tlines.push(`${name}${optional ? \"?\" : \"\"}: ${type};`);\n\t\treturn lines;\n\t}\n\n\tfunction describeField(field: SimpleFieldSchema): {\n\t\tcomment?: string;\n\t\toptional: boolean;\n\t\ttype: string;\n\t} {\n\t\tconst allowedTypes = renderAllowedTypes(field.simpleAllowedTypes.keys());\n\t\tconst type = formatExpression(allowedTypes);\n\t\tconst optional = field.kind !== FieldKind.Required;\n\t\tconst customMetadata = field.metadata.custom as\n\t\t\t| Record<string | symbol, unknown>\n\t\t\t| undefined;\n\t\tconst getDefault = customMetadata?.[llmDefault];\n\n\t\tif (getDefault !== undefined) {\n\t\t\tif (typeof getDefault !== \"function\") {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Expected value of ${llmDefault.description} property to be a function, but got ${typeof getDefault}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (field.kind !== FieldKind.Optional) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`The ${llmDefault.description} property is only permitted on optional fields.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\toptional,\n\t\t\t\ttype,\n\t\t\t\tcomment:\n\t\t\t\t\t\"Do not populate this field. It will be automatically supplied by the system after insertion.\",\n\t\t\t};\n\t\t}\n\n\t\tif (field.kind === FieldKind.Identifier) {\n\t\t\treturn {\n\t\t\t\toptional: true,\n\t\t\t\ttype,\n\t\t\t\tcomment:\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};\n\t\t}\n\n\t\tconst description = field.metadata?.description;\n\t\treturn {\n\t\t\toptional,\n\t\t\ttype,\n\t\t\tcomment: description === undefined || description === \"\" ? undefined : description,\n\t\t};\n\t}\n\n\tfunction renderBindingIntersection(definition: string): BindingIntersectionResult {\n\t\tconst { methods, properties } = getBoundMembers(definition);\n\t\tconst propertyLines = renderPropertyLines(properties);\n\t\tconst methodLines = renderMethodLines(methods);\n\n\t\tif (propertyLines.length === 0 && methodLines.length === 0) {\n\t\t\treturn { hasMethods: false, hasProperties: false, suffix: \"\" };\n\t\t}\n\n\t\tconst lines = [...propertyLines, ...methodLines].map((line) => ` ${line}`);\n\t\tconst suffix = ` & {\\n${lines.join(\"\\n\")}\\n}`;\n\t\treturn {\n\t\t\thasMethods: methodLines.length > 0,\n\t\t\thasProperties: propertyLines.length > 0,\n\t\t\tsuffix,\n\t\t};\n\t}\n\n\tfunction renderMethodLines(methods: Record<string, FunctionWrapper>): string[] {\n\t\tconst lines: string[] = [];\n\t\tfor (const [name, method] of Object.entries(methods)) {\n\t\t\tif (method.description !== undefined && method.description !== \"\") {\n\t\t\t\tfor (const note of method.description.split(\"\\n\")) {\n\t\t\t\t\tlines.push(`// ${note}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tlines.push(formatMethod(name, method));\n\t\t}\n\t\tif (lines.length > 0) {\n\t\t\thasHelperMethods = true;\n\t\t}\n\t\treturn lines;\n\t}\n\n\tfunction getBoundMembers(definition: string): BoundMembers {\n\t\tconst schemaClass = bindableSchemas.get(definition);\n\t\tif (schemaClass === undefined) {\n\t\t\treturn { methods: {}, properties: {} };\n\t\t}\n\t\treturn {\n\t\t\tmethods: getExposedMethods(schemaClass).methods,\n\t\t\tproperties: getExposedProperties(schemaClass).properties,\n\t\t};\n\t}\n\n\tfunction renderAllowedTypes(allowedTypes: Iterable<string>): TypeExpression {\n\t\tconst expressions: TypeExpression[] = [];\n\t\tfor (const identifier of allowedTypes) {\n\t\t\texpressions.push(renderTypeReference(identifier));\n\t\t}\n\t\tif (expressions.length === 0) {\n\t\t\treturn { precedence: TypePrecedence.Object, text: \"never\" };\n\t\t}\n\t\tif (expressions.length === 1) {\n\t\t\treturn expressions[0] ?? { precedence: TypePrecedence.Object, text: \"never\" };\n\t\t}\n\t\treturn {\n\t\t\tprecedence: TypePrecedence.Union,\n\t\t\ttext: expressions\n\t\t\t\t.map((expr) => formatExpression(expr, TypePrecedence.Union))\n\t\t\t\t.join(\" | \"),\n\t\t};\n\t}\n\n\tfunction renderTypeReference(identifier: string): TypeExpression {\n\t\tconst schema = definitions.get(identifier);\n\t\tif (schema === undefined) {\n\t\t\treturn {\n\t\t\t\tprecedence: TypePrecedence.Object,\n\t\t\t\ttext: friendlyNames.get(identifier) ?? unqualifySchema(identifier),\n\t\t\t};\n\t\t}\n\t\tif (isNamedSchema(identifier)) {\n\t\t\treturn {\n\t\t\t\tprecedence: TypePrecedence.Object,\n\t\t\t\ttext: friendlyNames.get(identifier) ?? unqualifySchema(identifier),\n\t\t\t};\n\t\t}\n\t\treturn renderInlineSchema(schema);\n\t}\n\n\tfunction renderInlineSchema(schema: SimpleNodeSchema): TypeExpression {\n\t\tswitch (schema.kind) {\n\t\t\tcase NodeKind.Object: {\n\t\t\t\treturn renderInlineObject(schema);\n\t\t\t}\n\t\t\tcase NodeKind.Array: {\n\t\t\t\treturn renderInlineArray(schema);\n\t\t\t}\n\t\t\tcase NodeKind.Map: {\n\t\t\t\treturn renderInlineMap(schema);\n\t\t\t}\n\t\t\tcase NodeKind.Record: {\n\t\t\t\treturn renderInlineRecord(schema);\n\t\t\t}\n\t\t\tcase NodeKind.Leaf: {\n\t\t\t\treturn { precedence: TypePrecedence.Object, text: renderLeaf(schema.leafKind) };\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn { precedence: TypePrecedence.Object, text: \"unknown\" };\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction renderInlineObject(schema: SimpleObjectNodeSchema): TypeExpression {\n\t\tconst fieldLines: string[] = [];\n\t\tfor (const [fieldName, fieldSchema] of schema.fields) {\n\t\t\tfieldLines.push(...renderFieldLine(fieldName, fieldSchema));\n\t\t}\n\t\tconst members = fieldLines.map((line) => ` ${line}`).join(\"\\n\");\n\t\tconst text =\n\t\t\tmembers === \"\"\n\t\t\t\t? \"{\\n}\"\n\t\t\t\t: `{\n${members}\n}`;\n\t\treturn { precedence: TypePrecedence.Object, text };\n\t}\n\n\tfunction renderInlineArray(schema: SimpleArrayNodeSchema): TypeExpression {\n\t\tconst elementTypes = renderAllowedTypes(schema.simpleAllowedTypes.keys());\n\t\treturn {\n\t\t\tprecedence: TypePrecedence.Object,\n\t\t\ttext: `${formatExpression(elementTypes)}[]`,\n\t\t};\n\t}\n\n\tfunction renderInlineMap(schema: SimpleMapNodeSchema): TypeExpression {\n\t\tconst valueType = renderAllowedTypes(schema.simpleAllowedTypes.keys());\n\t\treturn {\n\t\t\tprecedence: TypePrecedence.Object,\n\t\t\ttext: `Map<string, ${valueType.text}>`,\n\t\t};\n\t}\n\n\tfunction renderInlineRecord(schema: SimpleRecordNodeSchema): TypeExpression {\n\t\tconst valueType = renderAllowedTypes(schema.simpleAllowedTypes.keys());\n\t\treturn {\n\t\t\tprecedence: TypePrecedence.Object,\n\t\t\ttext: `Record<string, ${valueType.text}>`,\n\t\t};\n\t}\n}\n\nfunction describeBinding(\n\tdescription: string | undefined,\n\ttypeLabel: \"array\" | \"map\" | \"record\",\n\tbinding: BindingIntersectionResult,\n): string | undefined {\n\tlet note = \"\";\n\tif (binding.hasMethods && binding.hasProperties) {\n\t\tnote = `Note: this ${typeLabel} has custom user-defined methods and properties directly on it.`;\n\t} else if (binding.hasMethods) {\n\t\tnote = `Note: this ${typeLabel} has custom user-defined methods directly on it.`;\n\t} else if (binding.hasProperties) {\n\t\tnote = `Note: this ${typeLabel} has custom user-defined properties directly on it.`;\n\t}\n\n\tif (note === \"\") {\n\t\treturn description === undefined || description === \"\" ? undefined : description;\n\t}\n\tif (description === undefined || description === \"\") {\n\t\treturn note;\n\t}\n\treturn `${description} - ${note}`;\n}\n\nfunction renderPropertyLines(properties: Record<string, PropertyDef>): string[] {\n\tconst lines: string[] = [];\n\tfor (const [name, property] of Object.entries(properties)) {\n\t\tif (property.description !== undefined && property.description !== \"\") {\n\t\t\tfor (const note of property.description.split(\"\\n\")) {\n\t\t\t\tlines.push(`// ${note}`);\n\t\t\t}\n\t\t}\n\t\tconst modifier = property.readOnly ? \"readonly \" : \"\";\n\t\tlines.push(`${modifier}${name}: ${renderZodType(property.schema)};`);\n\t}\n\treturn lines;\n}\n\nfunction formatMethod(name: string, method: FunctionWrapper): string {\n\tconst args: string[] = [];\n\tfor (const [argName, argType] of method.args) {\n\t\tconst { innerType, optional } = unwrapOptional(argType);\n\t\tconst renderedType = renderZodType(innerType);\n\t\targs.push(`${argName}${optional ? \"?\" : \"\"}: ${renderedType}`);\n\t}\n\tif (method.rest !== null) {\n\t\targs.push(`...rest: ${renderZodType(method.rest)}[]`);\n\t}\n\treturn `${name}(${args.join(\", \")}): ${renderZodType(method.returns)};`;\n}\n\nfunction renderLeaf(leafKind: ValueSchema): string {\n\tswitch (leafKind) {\n\t\tcase ValueSchema.Boolean: {\n\t\t\treturn \"boolean\";\n\t\t}\n\t\tcase ValueSchema.Number: {\n\t\t\treturn \"number\";\n\t\t}\n\t\tcase ValueSchema.String: {\n\t\t\treturn \"string\";\n\t\t}\n\t\tcase ValueSchema.Null: {\n\t\t\treturn \"null\";\n\t\t}\n\t\tdefault: {\n\t\t\tthrow new Error(`Unsupported leaf kind ${NodeKind[leafKind]}.`);\n\t\t}\n\t}\n}\n\nfunction formatExpression(\n\texpression: TypeExpression,\n\tminPrecedence: TypePrecedence = TypePrecedence.Object,\n): string {\n\treturn expression.precedence < minPrecedence ? `(${expression.text})` : expression.text;\n}\n\n/**\n * Detects optional zod wrappers so argument lists can keep TypeScript optional markers in sync.\n */\nfunction unwrapOptional(type: z.ZodTypeAny): { innerType: z.ZodTypeAny; optional: boolean } {\n\tif (type instanceof z.ZodOptional) {\n\t\tconst inner = type.unwrap() as z.ZodTypeAny;\n\t\treturn { innerType: inner, optional: true };\n\t}\n\treturn { innerType: type, optional: false };\n}\n\n/**\n * Verifies that helper members do not clobber structural fields and fails fast if they do.\n */\nfunction ensureNoMemberConflicts(\n\tdefinition: string,\n\tfieldNames: ReadonlySet<string>,\n\tmethods: Record<string, FunctionWrapper>,\n\tproperties: Record<string, PropertyDef>,\n): void {\n\tfor (const name of Object.keys(methods)) {\n\t\tif (fieldNames.has(name)) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Method ${name} conflicts with field of the same name in schema ${definition}`,\n\t\t\t);\n\t\t}\n\t}\n\tfor (const name of Object.keys(properties)) {\n\t\tif (fieldNames.has(name)) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Property ${name} conflicts with field of the same name in schema ${definition}`,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * Converts schema metadata into TypeScript declarations suitable for prompt inclusion.\n */\nfunction renderZodType(type: z.ZodTypeAny): string {\n\treturn renderZodTypeScript(type, getFriendlyName, instanceOfs);\n}\n"]}
1
+ {"version":3,"file":"renderSchemaTypeScript.js","sourceRoot":"","sources":["../src/renderSchemaTypeScript.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,uEAAsE;AACtE,4DAAiF;AASjF,6BAAwB;AAGxB,yDAAu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AE,CAChF,CAAC;QACH,CAAC;IACF,CAAC;AACF,CAAC;AAED;;GAEG;AACH,SAAS,UAAU,CAAC,IAAoC;IACvD,OAAO,IAAA,qCAAiB,EAAC,IAAI,CAAC;QAC7B,CAAC,CAAC,IAAA,4DAA2B,EAAC,IAAI,EAAE,0BAAe,EAAE,uDAAsB,CAAC;QAC5E,CAAC,CAAC,IAAA,4CAAmB,EAAC,IAAI,EAAE,0BAAe,EAAE,oCAAW,CAAC,CAAC;AAC5D,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { FieldKind, NodeKind, ValueSchema } from \"@fluidframework/tree/internal\";\nimport type {\n\tSimpleArrayNodeSchema,\n\tSimpleFieldSchema,\n\tSimpleMapNodeSchema,\n\tSimpleNodeSchema,\n\tSimpleObjectNodeSchema,\n\tSimpleRecordNodeSchema,\n} from \"@fluidframework/tree/internal\";\nimport { z } from \"zod\";\n\nimport type { BindableSchema, FunctionWrapper } from \"./methodBinding.js\";\nimport { getExposedMethods } from \"./methodBinding.js\";\nimport { getExposedProperties, type PropertyDef } from \"./propertyBinding.js\";\nimport {\n\tinstanceOfsTypeFactory,\n\trenderTypeFactoryTypeScript,\n} from \"./renderTypeFactoryTypeScript.js\";\nimport { instanceOfs, renderZodTypeScript } from \"./renderZodTypeScript.js\";\nimport type { TypeFactoryOptional, TypeFactoryType } from \"./treeAgentTypes.js\";\nimport { isTypeFactoryType } from \"./treeAgentTypes.js\";\nimport { getFriendlyName, isNamedSchema, llmDefault, unqualifySchema } from \"./utils.js\";\n\ninterface BoundMembers {\n\tmethods: Record<string, FunctionWrapper>;\n\tproperties: Record<string, PropertyDef>;\n}\n\ninterface RenderResult {\n\tdeclaration: string;\n\tdescription?: string;\n}\n\ninterface BindingIntersectionResult {\n\thasMethods: boolean;\n\thasProperties: boolean;\n\tsuffix: string;\n}\n\ninterface TypeExpression {\n\tprecedence: TypePrecedence;\n\ttext: string;\n}\n\nconst enum TypePrecedence {\n\tUnion = 0,\n\tIntersection = 1,\n\tObject = 2,\n}\n\n/**\n * Output of rendering schema metadata into TypeScript declaration text.\n */\nexport interface SchemaTypeScriptRenderResult {\n\tschemaText: string;\n\thasHelperMethods: boolean;\n}\n\n/**\n * Converts schema metadata into TypeScript declarations suitable for prompt inclusion.\n */\nexport function renderSchemaTypeScript(\n\tdefinitions: ReadonlyMap<string, SimpleNodeSchema>,\n\tbindableSchemas: Map<string, BindableSchema>,\n): SchemaTypeScriptRenderResult {\n\tconst friendlyNames = new Map<string, string>();\n\tlet hasHelperMethods = false;\n\n\tfor (const identifier of definitions.keys()) {\n\t\tif (isNamedSchema(identifier)) {\n\t\t\tfriendlyNames.set(identifier, unqualifySchema(identifier));\n\t\t}\n\t}\n\n\tconst declarations: string[] = [];\n\tfor (const [identifier, schema] of definitions) {\n\t\tif (!isNamedSchema(identifier)) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst friendlyName = friendlyNames.get(identifier) ?? unqualifySchema(identifier);\n\t\tconst rendered = renderNamedSchema(identifier, friendlyName, schema);\n\t\tif (rendered === undefined) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst lines: string[] = [];\n\t\tif (rendered.description !== undefined && rendered.description !== \"\") {\n\t\t\tfor (const comment of rendered.description.split(\"\\n\")) {\n\t\t\t\tlines.push(`// ${comment}`);\n\t\t\t}\n\t\t}\n\t\tlines.push(rendered.declaration);\n\t\tdeclarations.push(lines.join(\"\\n\"));\n\t}\n\n\tconst schemaText = declarations.join(\"\\n\\n\");\n\treturn {\n\t\tschemaText: schemaText === \"\" ? \"\" : `${schemaText}\\n`,\n\t\thasHelperMethods,\n\t};\n\n\tfunction renderNamedSchema(\n\t\tidentifier: string,\n\t\tfriendlyName: string,\n\t\tschema: SimpleNodeSchema,\n\t): RenderResult | undefined {\n\t\tswitch (schema.kind) {\n\t\t\tcase NodeKind.Object: {\n\t\t\t\treturn renderObjectDeclaration(identifier, friendlyName, schema);\n\t\t\t}\n\t\t\tcase NodeKind.Array: {\n\t\t\t\treturn renderArrayDeclaration(identifier, friendlyName, schema);\n\t\t\t}\n\t\t\tcase NodeKind.Map: {\n\t\t\t\treturn renderMapDeclaration(identifier, friendlyName, schema);\n\t\t\t}\n\t\t\tcase NodeKind.Record: {\n\t\t\t\treturn renderRecordDeclaration(identifier, friendlyName, schema);\n\t\t\t}\n\t\t\tcase NodeKind.Leaf: {\n\t\t\t\treturn {\n\t\t\t\t\tdeclaration: `type ${friendlyName} = ${renderLeaf(schema.leafKind)};`,\n\t\t\t\t\tdescription: schema.metadata?.description,\n\t\t\t\t};\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction renderObjectDeclaration(\n\t\tdefinition: string,\n\t\tname: string,\n\t\tschema: SimpleObjectNodeSchema,\n\t): RenderResult {\n\t\tconst fieldLines: string[] = [];\n\t\tconst fieldNames = new Set<string>();\n\n\t\tfor (const [fieldName, fieldSchema] of schema.fields) {\n\t\t\tfieldNames.add(fieldName);\n\t\t\tfieldLines.push(...renderFieldLine(fieldName, fieldSchema));\n\t\t}\n\n\t\tconst { methods, properties } = getBoundMembers(definition);\n\t\tensureNoMemberConflicts(definition, fieldNames, methods, properties);\n\t\tfieldLines.push(...renderPropertyLines(properties));\n\t\tfieldLines.push(...renderMethodLines(methods));\n\n\t\tconst members = fieldLines.map((line) => ` ${line}`).join(\"\\n\");\n\t\tconst body = members === \"\" ? \"\" : `\\n${members}`;\n\t\treturn {\n\t\t\tdeclaration: `interface ${name} {${body}\\n}`,\n\t\t\tdescription: schema.metadata?.description,\n\t\t};\n\t}\n\n\tfunction renderArrayDeclaration(\n\t\tdefinition: string,\n\t\tname: string,\n\t\tschema: SimpleArrayNodeSchema,\n\t): RenderResult {\n\t\tconst elementTypes = renderAllowedTypes(schema.simpleAllowedTypes.keys());\n\t\tconst base = `${formatExpression(elementTypes)}[]`;\n\t\tconst binding = renderBindingIntersection(definition);\n\t\treturn {\n\t\t\tdeclaration: `type ${name} = ${base}${binding.suffix};`,\n\t\t\tdescription: describeBinding(schema.metadata?.description, \"array\", binding),\n\t\t};\n\t}\n\n\tfunction renderMapDeclaration(\n\t\tdefinition: string,\n\t\tname: string,\n\t\tschema: SimpleMapNodeSchema,\n\t): RenderResult {\n\t\tconst valueType = renderAllowedTypes(schema.simpleAllowedTypes.keys());\n\t\tconst base = `Map<string, ${valueType.text}>`;\n\t\tconst binding = renderBindingIntersection(definition);\n\t\treturn {\n\t\t\tdeclaration: `type ${name} = ${base}${binding.suffix};`,\n\t\t\tdescription: describeBinding(schema.metadata?.description, \"map\", binding),\n\t\t};\n\t}\n\n\tfunction renderRecordDeclaration(\n\t\tdefinition: string,\n\t\tname: string,\n\t\tschema: SimpleRecordNodeSchema,\n\t): RenderResult {\n\t\tconst valueType = renderAllowedTypes(schema.simpleAllowedTypes.keys());\n\t\tconst base = `Record<string, ${valueType.text}>`;\n\t\tconst binding = renderBindingIntersection(definition);\n\t\treturn {\n\t\t\tdeclaration: `type ${name} = ${base}${binding.suffix};`,\n\t\t\tdescription: describeBinding(schema.metadata?.description, \"record\", binding),\n\t\t};\n\t}\n\n\tfunction renderFieldLine(name: string, field: SimpleFieldSchema): string[] {\n\t\tconst { comment, optional, type } = describeField(field);\n\t\tconst lines: string[] = [];\n\t\tif (comment !== undefined && comment !== \"\") {\n\t\t\tfor (const note of comment.split(\"\\n\")) {\n\t\t\t\tlines.push(`// ${note}`);\n\t\t\t}\n\t\t}\n\t\tlines.push(`${name}${optional ? \"?\" : \"\"}: ${type};`);\n\t\treturn lines;\n\t}\n\n\tfunction describeField(field: SimpleFieldSchema): {\n\t\tcomment?: string;\n\t\toptional: boolean;\n\t\ttype: string;\n\t} {\n\t\tconst allowedTypes = renderAllowedTypes(field.simpleAllowedTypes.keys());\n\t\tconst type = formatExpression(allowedTypes);\n\t\tconst optional = field.kind !== FieldKind.Required;\n\t\tconst customMetadata = field.metadata.custom as\n\t\t\t| Record<string | symbol, unknown>\n\t\t\t| undefined;\n\t\tconst getDefault = customMetadata?.[llmDefault];\n\n\t\tif (getDefault !== undefined) {\n\t\t\tif (typeof getDefault !== \"function\") {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Expected value of ${llmDefault.description} property to be a function, but got ${typeof getDefault}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (field.kind !== FieldKind.Optional) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`The ${llmDefault.description} property is only permitted on optional fields.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn {\n\t\t\t\toptional,\n\t\t\t\ttype,\n\t\t\t\tcomment:\n\t\t\t\t\t\"Do not populate this field. It will be automatically supplied by the system after insertion.\",\n\t\t\t};\n\t\t}\n\n\t\tif (field.kind === FieldKind.Identifier) {\n\t\t\treturn {\n\t\t\t\toptional: true,\n\t\t\t\ttype,\n\t\t\t\tcomment:\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};\n\t\t}\n\n\t\tconst description = field.metadata?.description;\n\t\treturn {\n\t\t\toptional,\n\t\t\ttype,\n\t\t\tcomment: description === undefined || description === \"\" ? undefined : description,\n\t\t};\n\t}\n\n\tfunction renderBindingIntersection(definition: string): BindingIntersectionResult {\n\t\tconst { methods, properties } = getBoundMembers(definition);\n\t\tconst propertyLines = renderPropertyLines(properties);\n\t\tconst methodLines = renderMethodLines(methods);\n\n\t\tif (propertyLines.length === 0 && methodLines.length === 0) {\n\t\t\treturn { hasMethods: false, hasProperties: false, suffix: \"\" };\n\t\t}\n\n\t\tconst lines = [...propertyLines, ...methodLines].map((line) => ` ${line}`);\n\t\tconst suffix = ` & {\\n${lines.join(\"\\n\")}\\n}`;\n\t\treturn {\n\t\t\thasMethods: methodLines.length > 0,\n\t\t\thasProperties: propertyLines.length > 0,\n\t\t\tsuffix,\n\t\t};\n\t}\n\n\tfunction renderMethodLines(methods: Record<string, FunctionWrapper>): string[] {\n\t\tconst lines: string[] = [];\n\t\tfor (const [name, method] of Object.entries(methods)) {\n\t\t\tif (method.description !== undefined && method.description !== \"\") {\n\t\t\t\tfor (const note of method.description.split(\"\\n\")) {\n\t\t\t\t\tlines.push(`// ${note}`);\n\t\t\t\t}\n\t\t\t}\n\t\t\tlines.push(formatMethod(name, method));\n\t\t}\n\t\tif (lines.length > 0) {\n\t\t\thasHelperMethods = true;\n\t\t}\n\t\treturn lines;\n\t}\n\n\tfunction getBoundMembers(definition: string): BoundMembers {\n\t\tconst schemaClass = bindableSchemas.get(definition);\n\t\tif (schemaClass === undefined) {\n\t\t\treturn { methods: {}, properties: {} };\n\t\t}\n\t\treturn {\n\t\t\tmethods: getExposedMethods(schemaClass).methods,\n\t\t\tproperties: getExposedProperties(schemaClass).properties,\n\t\t};\n\t}\n\n\tfunction renderAllowedTypes(allowedTypes: Iterable<string>): TypeExpression {\n\t\tconst expressions: TypeExpression[] = [];\n\t\tfor (const identifier of allowedTypes) {\n\t\t\texpressions.push(renderTypeReference(identifier));\n\t\t}\n\t\tif (expressions.length === 0) {\n\t\t\treturn { precedence: TypePrecedence.Object, text: \"never\" };\n\t\t}\n\t\tif (expressions.length === 1) {\n\t\t\treturn expressions[0] ?? { precedence: TypePrecedence.Object, text: \"never\" };\n\t\t}\n\t\treturn {\n\t\t\tprecedence: TypePrecedence.Union,\n\t\t\ttext: expressions\n\t\t\t\t.map((expr) => formatExpression(expr, TypePrecedence.Union))\n\t\t\t\t.join(\" | \"),\n\t\t};\n\t}\n\n\tfunction renderTypeReference(identifier: string): TypeExpression {\n\t\tconst schema = definitions.get(identifier);\n\t\tif (schema === undefined) {\n\t\t\treturn {\n\t\t\t\tprecedence: TypePrecedence.Object,\n\t\t\t\ttext: friendlyNames.get(identifier) ?? unqualifySchema(identifier),\n\t\t\t};\n\t\t}\n\t\tif (isNamedSchema(identifier)) {\n\t\t\treturn {\n\t\t\t\tprecedence: TypePrecedence.Object,\n\t\t\t\ttext: friendlyNames.get(identifier) ?? unqualifySchema(identifier),\n\t\t\t};\n\t\t}\n\t\treturn renderInlineSchema(schema);\n\t}\n\n\tfunction renderInlineSchema(schema: SimpleNodeSchema): TypeExpression {\n\t\tswitch (schema.kind) {\n\t\t\tcase NodeKind.Object: {\n\t\t\t\treturn renderInlineObject(schema);\n\t\t\t}\n\t\t\tcase NodeKind.Array: {\n\t\t\t\treturn renderInlineArray(schema);\n\t\t\t}\n\t\t\tcase NodeKind.Map: {\n\t\t\t\treturn renderInlineMap(schema);\n\t\t\t}\n\t\t\tcase NodeKind.Record: {\n\t\t\t\treturn renderInlineRecord(schema);\n\t\t\t}\n\t\t\tcase NodeKind.Leaf: {\n\t\t\t\treturn { precedence: TypePrecedence.Object, text: renderLeaf(schema.leafKind) };\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\treturn { precedence: TypePrecedence.Object, text: \"unknown\" };\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction renderInlineObject(schema: SimpleObjectNodeSchema): TypeExpression {\n\t\tconst fieldLines: string[] = [];\n\t\tfor (const [fieldName, fieldSchema] of schema.fields) {\n\t\t\tfieldLines.push(...renderFieldLine(fieldName, fieldSchema));\n\t\t}\n\t\tconst members = fieldLines.map((line) => ` ${line}`).join(\"\\n\");\n\t\tconst text =\n\t\t\tmembers === \"\"\n\t\t\t\t? \"{\\n}\"\n\t\t\t\t: `{\n${members}\n}`;\n\t\treturn { precedence: TypePrecedence.Object, text };\n\t}\n\n\tfunction renderInlineArray(schema: SimpleArrayNodeSchema): TypeExpression {\n\t\tconst elementTypes = renderAllowedTypes(schema.simpleAllowedTypes.keys());\n\t\treturn {\n\t\t\tprecedence: TypePrecedence.Object,\n\t\t\ttext: `${formatExpression(elementTypes)}[]`,\n\t\t};\n\t}\n\n\tfunction renderInlineMap(schema: SimpleMapNodeSchema): TypeExpression {\n\t\tconst valueType = renderAllowedTypes(schema.simpleAllowedTypes.keys());\n\t\treturn {\n\t\t\tprecedence: TypePrecedence.Object,\n\t\t\ttext: `Map<string, ${valueType.text}>`,\n\t\t};\n\t}\n\n\tfunction renderInlineRecord(schema: SimpleRecordNodeSchema): TypeExpression {\n\t\tconst valueType = renderAllowedTypes(schema.simpleAllowedTypes.keys());\n\t\treturn {\n\t\t\tprecedence: TypePrecedence.Object,\n\t\t\ttext: `Record<string, ${valueType.text}>`,\n\t\t};\n\t}\n}\n\nfunction describeBinding(\n\tdescription: string | undefined,\n\ttypeLabel: \"array\" | \"map\" | \"record\",\n\tbinding: BindingIntersectionResult,\n): string | undefined {\n\tlet note = \"\";\n\tif (binding.hasMethods && binding.hasProperties) {\n\t\tnote = `Note: this ${typeLabel} has custom user-defined methods and properties directly on it.`;\n\t} else if (binding.hasMethods) {\n\t\tnote = `Note: this ${typeLabel} has custom user-defined methods directly on it.`;\n\t} else if (binding.hasProperties) {\n\t\tnote = `Note: this ${typeLabel} has custom user-defined properties directly on it.`;\n\t}\n\n\tif (note === \"\") {\n\t\treturn description === undefined || description === \"\" ? undefined : description;\n\t}\n\tif (description === undefined || description === \"\") {\n\t\treturn note;\n\t}\n\treturn `${description} - ${note}`;\n}\n\nfunction renderPropertyLines(properties: Record<string, PropertyDef>): string[] {\n\tconst lines: string[] = [];\n\tfor (const [name, property] of Object.entries(properties)) {\n\t\tif (property.description !== undefined && property.description !== \"\") {\n\t\t\tfor (const note of property.description.split(\"\\n\")) {\n\t\t\t\tlines.push(`// ${note}`);\n\t\t\t}\n\t\t}\n\t\tconst modifier = property.readOnly ? \"readonly \" : \"\";\n\t\tlines.push(`${modifier}${name}: ${renderType(property.schema)};`);\n\t}\n\treturn lines;\n}\n\nfunction formatMethod(name: string, method: FunctionWrapper): string {\n\tconst args: string[] = [];\n\tfor (const [argName, argType] of method.args) {\n\t\tconst { innerType, optional } = unwrapOptional(argType);\n\t\tconst renderedType = renderType(innerType);\n\t\targs.push(`${argName}${optional ? \"?\" : \"\"}: ${renderedType}`);\n\t}\n\tif (method.rest !== null) {\n\t\targs.push(`...rest: ${renderType(method.rest)}[]`);\n\t}\n\treturn `${name}(${args.join(\", \")}): ${renderType(method.returns)};`;\n}\n\nfunction renderLeaf(leafKind: ValueSchema): string {\n\tswitch (leafKind) {\n\t\tcase ValueSchema.Boolean: {\n\t\t\treturn \"boolean\";\n\t\t}\n\t\tcase ValueSchema.Number: {\n\t\t\treturn \"number\";\n\t\t}\n\t\tcase ValueSchema.String: {\n\t\t\treturn \"string\";\n\t\t}\n\t\tcase ValueSchema.Null: {\n\t\t\treturn \"null\";\n\t\t}\n\t\tdefault: {\n\t\t\tthrow new Error(`Unsupported leaf kind ${NodeKind[leafKind]}.`);\n\t\t}\n\t}\n}\n\nfunction formatExpression(\n\texpression: TypeExpression,\n\tminPrecedence: TypePrecedence = TypePrecedence.Object,\n): string {\n\treturn expression.precedence < minPrecedence ? `(${expression.text})` : expression.text;\n}\n\n/**\n * Detects optional zod wrappers so argument lists can keep TypeScript optional markers in sync.\n */\nfunction unwrapOptional(type: z.ZodTypeAny | TypeFactoryType): {\n\tinnerType: z.ZodTypeAny | TypeFactoryType;\n\toptional: boolean;\n} {\n\t// Handle type factory optional type\n\tif (isTypeFactoryType(type) && type._kind === \"optional\") {\n\t\treturn { innerType: (type as TypeFactoryOptional).innerType, optional: true };\n\t}\n\t// Handle Zod optional type\n\tif (type instanceof z.ZodOptional) {\n\t\tconst inner = type.unwrap() as z.ZodTypeAny;\n\t\treturn { innerType: inner, optional: true };\n\t}\n\treturn { innerType: type, optional: false };\n}\n\n/**\n * Verifies that helper members do not clobber structural fields and fails fast if they do.\n */\nfunction ensureNoMemberConflicts(\n\tdefinition: string,\n\tfieldNames: ReadonlySet<string>,\n\tmethods: Record<string, FunctionWrapper>,\n\tproperties: Record<string, PropertyDef>,\n): void {\n\tfor (const name of Object.keys(methods)) {\n\t\tif (fieldNames.has(name)) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Method ${name} conflicts with field of the same name in schema ${definition}`,\n\t\t\t);\n\t\t}\n\t}\n\tfor (const name of Object.keys(properties)) {\n\t\tif (fieldNames.has(name)) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Property ${name} conflicts with field of the same name in schema ${definition}`,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * Dispatches to the correct renderer based on whether the type is Zod or type factory.\n */\nfunction renderType(type: z.ZodTypeAny | TypeFactoryType): string {\n\treturn isTypeFactoryType(type)\n\t\t? renderTypeFactoryTypeScript(type, getFriendlyName, instanceOfsTypeFactory)\n\t\t: renderZodTypeScript(type, getFriendlyName, instanceOfs);\n}\n"]}
@@ -0,0 +1,13 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import type { ObjectNodeSchema, TreeNodeSchema } from "@fluidframework/tree/alpha";
6
+ import type { TypeFactoryType } from "./treeAgentTypes.js";
7
+ export { instanceOfsTypeFactory } from "./treeAgentTypes.js";
8
+ /**
9
+ * Converts type factory type definitions into TypeScript declaration text.
10
+ * @alpha
11
+ */
12
+ export declare function renderTypeFactoryTypeScript(typeFactoryType: TypeFactoryType, getFriendlyName: (schema: TreeNodeSchema) => string, instanceOfLookup: WeakMap<TypeFactoryType, ObjectNodeSchema>): string;
13
+ //# sourceMappingURL=renderTypeFactoryTypeScript.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderTypeFactoryTypeScript.d.ts","sourceRoot":"","sources":["../src/renderTypeFactoryTypeScript.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAEnF,OAAO,KAAK,EACX,eAAe,EAUf,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAE7D;;;GAGG;AACH,wBAAgB,2BAA2B,CAC1C,eAAe,EAAE,eAAe,EAChC,eAAe,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,MAAM,EACnD,gBAAgB,EAAE,OAAO,CAAC,eAAe,EAAE,gBAAgB,CAAC,GAC1D,MAAM,CAkNR"}
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.renderTypeFactoryTypeScript = exports.instanceOfsTypeFactory = void 0;
8
+ const internal_1 = require("@fluidframework/telemetry-utils/internal");
9
+ var treeAgentTypes_js_1 = require("./treeAgentTypes.js");
10
+ Object.defineProperty(exports, "instanceOfsTypeFactory", { enumerable: true, get: function () { return treeAgentTypes_js_1.instanceOfsTypeFactory; } });
11
+ /**
12
+ * Converts type factory type definitions into TypeScript declaration text.
13
+ * @alpha
14
+ */
15
+ function renderTypeFactoryTypeScript(typeFactoryType, getFriendlyName, instanceOfLookup) {
16
+ let result = "";
17
+ let startOfLine = true;
18
+ let indent = 0;
19
+ appendType(typeFactoryType, 0 /* TypePrecedence.Union */);
20
+ return result;
21
+ function appendType(type, minPrecedence = 2 /* TypePrecedence.Object */) {
22
+ const shouldParenthesize = getTypePrecedence(type) < minPrecedence;
23
+ if (shouldParenthesize) {
24
+ append("(");
25
+ }
26
+ appendTypeDefinition(type);
27
+ if (shouldParenthesize) {
28
+ append(")");
29
+ }
30
+ }
31
+ function append(s) {
32
+ if (startOfLine) {
33
+ result += " ".repeat(indent);
34
+ startOfLine = false;
35
+ }
36
+ result += s;
37
+ }
38
+ function appendNewLine() {
39
+ append("\n");
40
+ startOfLine = true;
41
+ }
42
+ function appendTypeDefinition(type) {
43
+ switch (type._kind) {
44
+ case "string": {
45
+ append("string");
46
+ return;
47
+ }
48
+ case "number": {
49
+ append("number");
50
+ return;
51
+ }
52
+ case "boolean": {
53
+ append("boolean");
54
+ return;
55
+ }
56
+ case "void": {
57
+ append("void");
58
+ return;
59
+ }
60
+ case "undefined": {
61
+ append("undefined");
62
+ return;
63
+ }
64
+ case "null": {
65
+ append("null");
66
+ return;
67
+ }
68
+ case "unknown": {
69
+ append("unknown");
70
+ return;
71
+ }
72
+ case "array": {
73
+ appendArrayType(type);
74
+ return;
75
+ }
76
+ case "object": {
77
+ appendObjectType(type);
78
+ return;
79
+ }
80
+ case "union": {
81
+ appendUnionTypes(type.options, 0 /* TypePrecedence.Union */);
82
+ return;
83
+ }
84
+ case "tuple": {
85
+ appendTupleType(type);
86
+ return;
87
+ }
88
+ case "record": {
89
+ appendRecordType(type);
90
+ return;
91
+ }
92
+ case "map": {
93
+ appendMapType(type);
94
+ return;
95
+ }
96
+ case "literal": {
97
+ appendLiteral(type.value);
98
+ return;
99
+ }
100
+ case "optional": {
101
+ appendUnionTypes([type.innerType, { _kind: "undefined" }], 0 /* TypePrecedence.Union */);
102
+ return;
103
+ }
104
+ case "readonly": {
105
+ appendReadonlyType(type);
106
+ return;
107
+ }
108
+ case "instanceof": {
109
+ const schema = instanceOfLookup.get(type);
110
+ if (schema === undefined) {
111
+ throw new internal_1.UsageError("instanceof type not found in lookup - this typically indicates the type was not created via typeFactory.instanceOf");
112
+ }
113
+ append(getFriendlyName(schema));
114
+ return;
115
+ }
116
+ default: {
117
+ throw new internal_1.UsageError(`Unsupported type when formatting helper types: ${String(type._kind ?? "unknown")}. Expected one of: string, number, boolean, void, undefined, null, unknown, array, object, union, tuple, record, map, literal, optional, readonly, instanceof.`);
118
+ }
119
+ }
120
+ }
121
+ function appendArrayType(arrayType) {
122
+ appendType(arrayType.element, 2 /* TypePrecedence.Object */);
123
+ append("[]");
124
+ }
125
+ function appendObjectType(objectType) {
126
+ append("{");
127
+ appendNewLine();
128
+ indent++;
129
+ for (const [name, propertyType] of Object.entries(objectType.shape)) {
130
+ append(name);
131
+ if (propertyType._kind === "optional") {
132
+ append("?");
133
+ append(": ");
134
+ appendType(propertyType.innerType);
135
+ }
136
+ else {
137
+ append(": ");
138
+ appendType(propertyType);
139
+ }
140
+ append(";");
141
+ appendNewLine();
142
+ }
143
+ indent--;
144
+ append("}");
145
+ }
146
+ function appendUnionTypes(types, minPrecedence) {
147
+ let first = true;
148
+ for (const innerType of types) {
149
+ if (!first) {
150
+ append(" | ");
151
+ }
152
+ appendType(innerType, minPrecedence);
153
+ first = false;
154
+ }
155
+ }
156
+ function appendTupleType(tupleType) {
157
+ append("[");
158
+ let first = true;
159
+ for (const innerType of tupleType.items) {
160
+ if (!first) {
161
+ append(", ");
162
+ }
163
+ if (innerType._kind === "optional") {
164
+ appendType(innerType.innerType, 2 /* TypePrecedence.Object */);
165
+ append("?");
166
+ }
167
+ else {
168
+ appendType(innerType);
169
+ }
170
+ first = false;
171
+ }
172
+ if (tupleType.rest !== undefined) {
173
+ if (!first) {
174
+ append(", ");
175
+ }
176
+ append("...");
177
+ appendType(tupleType.rest, 2 /* TypePrecedence.Object */);
178
+ append("[]");
179
+ }
180
+ append("]");
181
+ }
182
+ function appendRecordType(recordType) {
183
+ append("Record<");
184
+ appendType(recordType.keyType, 0 /* TypePrecedence.Union */);
185
+ append(", ");
186
+ appendType(recordType.valueType, 0 /* TypePrecedence.Union */);
187
+ append(">");
188
+ }
189
+ function appendMapType(mapType) {
190
+ append("Map<");
191
+ appendType(mapType.keyType, 0 /* TypePrecedence.Union */);
192
+ append(", ");
193
+ appendType(mapType.valueType, 0 /* TypePrecedence.Union */);
194
+ append(">");
195
+ }
196
+ function appendLiteral(value) {
197
+ append(JSON.stringify(value));
198
+ }
199
+ function appendReadonlyType(readonlyType) {
200
+ append("Readonly<");
201
+ appendType(readonlyType.innerType);
202
+ append(">");
203
+ }
204
+ }
205
+ exports.renderTypeFactoryTypeScript = renderTypeFactoryTypeScript;
206
+ var TypePrecedence;
207
+ (function (TypePrecedence) {
208
+ TypePrecedence[TypePrecedence["Union"] = 0] = "Union";
209
+ TypePrecedence[TypePrecedence["Intersection"] = 1] = "Intersection";
210
+ TypePrecedence[TypePrecedence["Object"] = 2] = "Object";
211
+ })(TypePrecedence || (TypePrecedence = {}));
212
+ function getTypePrecedence(type) {
213
+ switch (type._kind) {
214
+ case "union": {
215
+ return 0 /* TypePrecedence.Union */;
216
+ }
217
+ default: {
218
+ return 2 /* TypePrecedence.Object */;
219
+ }
220
+ }
221
+ }
222
+ //# sourceMappingURL=renderTypeFactoryTypeScript.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderTypeFactoryTypeScript.js","sourceRoot":"","sources":["../src/renderTypeFactoryTypeScript.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,uEAAsE;AAgBtE,yDAA6D;AAApD,2HAAA,sBAAsB,OAAA;AAE/B;;;GAGG;AACH,SAAgB,2BAA2B,CAC1C,eAAgC,EAChC,eAAmD,EACnD,gBAA4D;IAE5D,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,WAAW,GAAG,IAAI,CAAC;IACvB,IAAI,MAAM,GAAG,CAAC,CAAC;IAEf,UAAU,CAAC,eAAe,+BAAuB,CAAC;IAClD,OAAO,MAAM,CAAC;IAEd,SAAS,UAAU,CAAC,IAAqB,EAAE,aAAa,gCAAwB;QAC/E,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,IAAI,CAAC,GAAG,aAAa,CAAC;QACnE,IAAI,kBAAkB,EAAE,CAAC;YACxB,MAAM,CAAC,GAAG,CAAC,CAAC;QACb,CAAC;QACD,oBAAoB,CAAC,IAAI,CAAC,CAAC;QAC3B,IAAI,kBAAkB,EAAE,CAAC;YACxB,MAAM,CAAC,GAAG,CAAC,CAAC;QACb,CAAC;IACF,CAAC;IAED,SAAS,MAAM,CAAC,CAAS;QACxB,IAAI,WAAW,EAAE,CAAC;YACjB,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAChC,WAAW,GAAG,KAAK,CAAC;QACrB,CAAC;QACD,MAAM,IAAI,CAAC,CAAC;IACb,CAAC;IAED,SAAS,aAAa;QACrB,MAAM,CAAC,IAAI,CAAC,CAAC;QACb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AG,CAAC,CAAC;IACb,CAAC;AACF,CAAC;AAtND,kEAsNC;AAED,IAAW,cAIV;AAJD,WAAW,cAAc;IACxB,qDAAS,CAAA;IACT,mEAAgB,CAAA;IAChB,uDAAU,CAAA;AACX,CAAC,EAJU,cAAc,KAAd,cAAc,QAIxB;AAED,SAAS,iBAAiB,CAAC,IAAqB;IAC/C,QAAQ,IAAI,CAAC,KAAK,EAAE,CAAC;QACpB,KAAK,OAAO,CAAC,CAAC,CAAC;YACd,oCAA4B;QAC7B,CAAC;QACD,OAAO,CAAC,CAAC,CAAC;YACT,qCAA6B;QAC9B,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport type { ObjectNodeSchema, TreeNodeSchema } from \"@fluidframework/tree/alpha\";\n\nimport type {\n\tTypeFactoryType,\n\tTypeFactoryArray,\n\tTypeFactoryObject,\n\tTypeFactoryTuple,\n\tTypeFactoryRecord,\n\tTypeFactoryMap,\n\tTypeFactoryLiteral,\n\tTypeFactoryOptional,\n\tTypeFactoryReadonly,\n\tTypeFactoryUnion,\n} from \"./treeAgentTypes.js\";\n\nexport { instanceOfsTypeFactory } from \"./treeAgentTypes.js\";\n\n/**\n * Converts type factory type definitions into TypeScript declaration text.\n * @alpha\n */\nexport function renderTypeFactoryTypeScript(\n\ttypeFactoryType: TypeFactoryType,\n\tgetFriendlyName: (schema: TreeNodeSchema) => string,\n\tinstanceOfLookup: WeakMap<TypeFactoryType, ObjectNodeSchema>,\n): string {\n\tlet result = \"\";\n\tlet startOfLine = true;\n\tlet indent = 0;\n\n\tappendType(typeFactoryType, TypePrecedence.Union);\n\treturn result;\n\n\tfunction appendType(type: TypeFactoryType, minPrecedence = TypePrecedence.Object): void {\n\t\tconst shouldParenthesize = getTypePrecedence(type) < minPrecedence;\n\t\tif (shouldParenthesize) {\n\t\t\tappend(\"(\");\n\t\t}\n\t\tappendTypeDefinition(type);\n\t\tif (shouldParenthesize) {\n\t\t\tappend(\")\");\n\t\t}\n\t}\n\n\tfunction append(s: string): void {\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(): void {\n\t\tappend(\"\\n\");\n\t\tstartOfLine = true;\n\t}\n\n\tfunction appendTypeDefinition(type: TypeFactoryType): void {\n\t\tswitch (type._kind) {\n\t\t\tcase \"string\": {\n\t\t\t\tappend(\"string\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"number\": {\n\t\t\t\tappend(\"number\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"boolean\": {\n\t\t\t\tappend(\"boolean\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"void\": {\n\t\t\t\tappend(\"void\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"undefined\": {\n\t\t\t\tappend(\"undefined\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"null\": {\n\t\t\t\tappend(\"null\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"unknown\": {\n\t\t\t\tappend(\"unknown\");\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"array\": {\n\t\t\t\tappendArrayType(type as TypeFactoryArray);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"object\": {\n\t\t\t\tappendObjectType(type as TypeFactoryObject);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"union\": {\n\t\t\t\tappendUnionTypes((type as TypeFactoryUnion).options, TypePrecedence.Union);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"tuple\": {\n\t\t\t\tappendTupleType(type as TypeFactoryTuple);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"record\": {\n\t\t\t\tappendRecordType(type as TypeFactoryRecord);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"map\": {\n\t\t\t\tappendMapType(type as TypeFactoryMap);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"literal\": {\n\t\t\t\tappendLiteral((type as TypeFactoryLiteral).value);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"optional\": {\n\t\t\t\tappendUnionTypes(\n\t\t\t\t\t[(type as TypeFactoryOptional).innerType, { _kind: \"undefined\" }],\n\t\t\t\t\tTypePrecedence.Union,\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"readonly\": {\n\t\t\t\tappendReadonlyType(type as TypeFactoryReadonly);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase \"instanceof\": {\n\t\t\t\tconst schema = instanceOfLookup.get(type);\n\t\t\t\tif (schema === undefined) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\"instanceof type not found in lookup - this typically indicates the type was not created via typeFactory.instanceOf\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tappend(getFriendlyName(schema));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t`Unsupported type when formatting helper types: ${String(type._kind ?? \"unknown\")}. Expected one of: string, number, boolean, void, undefined, null, unknown, array, object, union, tuple, record, map, literal, optional, readonly, instanceof.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction appendArrayType(arrayType: TypeFactoryArray): void {\n\t\tappendType(arrayType.element, TypePrecedence.Object);\n\t\tappend(\"[]\");\n\t}\n\n\tfunction appendObjectType(objectType: TypeFactoryObject): void {\n\t\tappend(\"{\");\n\t\tappendNewLine();\n\t\tindent++;\n\t\tfor (const [name, propertyType] of Object.entries(objectType.shape)) {\n\t\t\tappend(name);\n\t\t\tif (propertyType._kind === \"optional\") {\n\t\t\t\tappend(\"?\");\n\t\t\t\tappend(\": \");\n\t\t\t\tappendType((propertyType as TypeFactoryOptional).innerType);\n\t\t\t} else {\n\t\t\t\tappend(\": \");\n\t\t\t\tappendType(propertyType);\n\t\t\t}\n\t\t\tappend(\";\");\n\t\t\tappendNewLine();\n\t\t}\n\t\tindent--;\n\t\tappend(\"}\");\n\t}\n\n\tfunction appendUnionTypes(\n\t\ttypes: readonly TypeFactoryType[],\n\t\tminPrecedence: TypePrecedence,\n\t): void {\n\t\tlet first = true;\n\t\tfor (const innerType of types) {\n\t\t\tif (!first) {\n\t\t\t\tappend(\" | \");\n\t\t\t}\n\t\t\tappendType(innerType, minPrecedence);\n\t\t\tfirst = false;\n\t\t}\n\t}\n\n\tfunction appendTupleType(tupleType: TypeFactoryTuple): void {\n\t\tappend(\"[\");\n\t\tlet first = true;\n\t\tfor (const innerType of tupleType.items) {\n\t\t\tif (!first) {\n\t\t\t\tappend(\", \");\n\t\t\t}\n\t\t\tif (innerType._kind === \"optional\") {\n\t\t\t\tappendType((innerType as TypeFactoryOptional).innerType, TypePrecedence.Object);\n\t\t\t\tappend(\"?\");\n\t\t\t} else {\n\t\t\t\tappendType(innerType);\n\t\t\t}\n\t\t\tfirst = false;\n\t\t}\n\t\tif (tupleType.rest !== undefined) {\n\t\t\tif (!first) {\n\t\t\t\tappend(\", \");\n\t\t\t}\n\t\t\tappend(\"...\");\n\t\t\tappendType(tupleType.rest, TypePrecedence.Object);\n\t\t\tappend(\"[]\");\n\t\t}\n\t\tappend(\"]\");\n\t}\n\n\tfunction appendRecordType(recordType: TypeFactoryRecord): void {\n\t\tappend(\"Record<\");\n\t\tappendType(recordType.keyType, TypePrecedence.Union);\n\t\tappend(\", \");\n\t\tappendType(recordType.valueType, TypePrecedence.Union);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendMapType(mapType: TypeFactoryMap): void {\n\t\tappend(\"Map<\");\n\t\tappendType(mapType.keyType, TypePrecedence.Union);\n\t\tappend(\", \");\n\t\tappendType(mapType.valueType, TypePrecedence.Union);\n\t\tappend(\">\");\n\t}\n\n\tfunction appendLiteral(value: string | number | boolean): void {\n\t\tappend(JSON.stringify(value));\n\t}\n\n\tfunction appendReadonlyType(readonlyType: TypeFactoryReadonly): void {\n\t\tappend(\"Readonly<\");\n\t\tappendType(readonlyType.innerType);\n\t\tappend(\">\");\n\t}\n}\n\nconst enum TypePrecedence {\n\tUnion = 0,\n\tIntersection = 1,\n\tObject = 2,\n}\n\nfunction getTypePrecedence(type: TypeFactoryType): TypePrecedence {\n\tswitch (type._kind) {\n\t\tcase \"union\": {\n\t\t\treturn TypePrecedence.Union;\n\t\t}\n\t\tdefault: {\n\t\t\treturn TypePrecedence.Object;\n\t\t}\n\t}\n}\n"]}
@@ -1 +1 @@
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"}
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,C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