@fluidframework/tree-agent 2.74.0 → 2.81.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.
- package/CHANGELOG.md +99 -0
- package/api-report/tree-agent.alpha.api.md +195 -20
- package/dist/alpha.d.ts +31 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -1
- package/dist/index.js.map +1 -1
- package/dist/methodBinding.d.ts +54 -10
- package/dist/methodBinding.d.ts.map +1 -1
- package/dist/methodBinding.js.map +1 -1
- package/dist/propertyBinding.d.ts +52 -2
- package/dist/propertyBinding.d.ts.map +1 -1
- package/dist/propertyBinding.js +28 -3
- package/dist/propertyBinding.js.map +1 -1
- package/dist/renderSchemaTypeScript.d.ts.map +1 -1
- package/dist/renderSchemaTypeScript.js +24 -9
- package/dist/renderSchemaTypeScript.js.map +1 -1
- package/dist/renderTypeFactoryTypeScript.d.ts +13 -0
- package/dist/renderTypeFactoryTypeScript.d.ts.map +1 -0
- package/dist/renderTypeFactoryTypeScript.js +290 -0
- package/dist/renderTypeFactoryTypeScript.js.map +1 -0
- package/dist/subtree.d.ts.map +1 -1
- package/dist/subtree.js +4 -4
- package/dist/subtree.js.map +1 -1
- package/dist/treeAgentTypes.d.ts +430 -0
- package/dist/treeAgentTypes.d.ts.map +1 -0
- package/dist/treeAgentTypes.js +227 -0
- package/dist/treeAgentTypes.js.map +1 -0
- package/dist/utils.d.ts +0 -4
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +2 -9
- package/dist/utils.js.map +1 -1
- package/eslint.config.mts +4 -4
- package/lib/alpha.d.ts +31 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/methodBinding.d.ts +54 -10
- package/lib/methodBinding.d.ts.map +1 -1
- package/lib/methodBinding.js.map +1 -1
- package/lib/propertyBinding.d.ts +52 -2
- package/lib/propertyBinding.d.ts.map +1 -1
- package/lib/propertyBinding.js +28 -3
- package/lib/propertyBinding.js.map +1 -1
- package/lib/renderSchemaTypeScript.d.ts.map +1 -1
- package/lib/renderSchemaTypeScript.js +24 -9
- package/lib/renderSchemaTypeScript.js.map +1 -1
- package/lib/renderTypeFactoryTypeScript.d.ts +13 -0
- package/lib/renderTypeFactoryTypeScript.d.ts.map +1 -0
- package/lib/renderTypeFactoryTypeScript.js +285 -0
- package/lib/renderTypeFactoryTypeScript.js.map +1 -0
- package/lib/subtree.d.ts.map +1 -1
- package/lib/subtree.js +4 -4
- package/lib/subtree.js.map +1 -1
- package/lib/treeAgentTypes.d.ts +430 -0
- package/lib/treeAgentTypes.d.ts.map +1 -0
- package/lib/treeAgentTypes.js +223 -0
- package/lib/treeAgentTypes.js.map +1 -0
- package/lib/utils.d.ts +0 -4
- package/lib/utils.d.ts.map +1 -1
- package/lib/utils.js +2 -8
- package/lib/utils.js.map +1 -1
- package/package.json +17 -17
- package/src/index.ts +36 -0
- package/src/methodBinding.ts +94 -15
- package/src/propertyBinding.ts +66 -9
- package/src/renderSchemaTypeScript.ts +32 -10
- package/src/renderTypeFactoryTypeScript.ts +339 -0
- package/src/subtree.ts +6 -5
- package/src/treeAgentTypes.ts +611 -0
- package/src/utils.ts +2 -9
- package/.eslintrc.cjs +0 -48
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"methodBinding.js","sourceRoot":"","sources":["../src/methodBinding.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,+CAAgD;AAEhD,qEAAsD;AA0BtD;;GAEG;AACH,SAAgB,gBAAgB,CAAC,MAAsB;IACtD,OAAO,CACN,MAAM,CAAC,IAAI,KAAK,eAAQ,CAAC,MAAM;QAC/B,MAAM,CAAC,IAAI,KAAK,eAAQ,CAAC,MAAM;QAC/B,MAAM,CAAC,IAAI,KAAK,eAAQ,CAAC,KAAK;QAC9B,MAAM,CAAC,IAAI,KAAK,eAAQ,CAAC,GAAG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,IAAI;QAChB,2CAA2C;QAC3C,WAAW,CAAC,IAAI,IAAI,IAAI,EACxB,WAAW,CAAC,OAAO,CACnB,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,iBAAiB,CAAC,WAA2B;QAI1D,MAAM,cAAc,GAAG,IAAI,eAAe,CAAC,WAAW,CAAC,CAAC;QACxD,MAAM,WAAW,GAAG,WAAyC,CAAC;QAC9D,IAAI,WAAW,CAAC,2BAAmB,CAAC,KAAK,SAAS,EAAE,CAAC;YACpD,WAAW,CAAC,2BAAmB,CAAC,CAAC,cAAc,CAAC,CAAC;QAClD,CAAC;QACD,OAAO;YACN,OAAO,EAAE,cAAc,CAAC,OAAO;YAC/B,eAAe,EAAE,cAAc,CAAC,eAAe;SAC/C,CAAC;IACH,CAAC;CACD","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 { NodeKind } from \"@fluidframework/tree\";\nimport type { z } from \"zod\";\nimport { instanceOf } from \"./renderZodTypeScript.js\";\n\n/**\n * A utility type that extracts the method keys from a given type.\n * @alpha\n */\nexport type MethodKeys<T> = {\n\t[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;\n};\n\n/**\n * A type that represents a constructor function.\n * @alpha\n */\nexport type Ctor<T = any> = new (...args: any[]) => T;\n\n/**\n * A type that represents an object schema class.\n * @alpha\n */\nexport type BindableSchema =\n\t| TreeNodeSchema<string, NodeKind.Object>\n\t| TreeNodeSchema<string, NodeKind.Record>\n\t| TreeNodeSchema<string, NodeKind.Array>\n\t| TreeNodeSchema<string, NodeKind.Map>;\n\n/**\n * A type guard to check if a schema is {@link BindableSchema | bindable}.\n */\nexport function isBindableSchema(schema: TreeNodeSchema): schema is BindableSchema {\n\treturn (\n\t\tschema.kind === NodeKind.Object ||\n\t\tschema.kind === NodeKind.Record ||\n\t\tschema.kind === NodeKind.Array ||\n\t\tschema.kind === NodeKind.Map\n\t);\n}\n\n/**\n * Get the exposed methods of a schema class.\n * @param schemaClass - The schema class to extract methods from.\n * @returns A record of method names and their corresponding Zod types.\n */\nexport function getExposedMethods(schemaClass: BindableSchema): {\n\tmethods: Record<string, FunctionWrapper>;\n\treferencedTypes: Set<TreeNodeSchema>;\n} {\n\treturn ExposedMethodsI.getExposedMethods(schemaClass);\n}\n\n/**\n * A type that represents a function argument.\n * @alpha\n */\nexport type Arg<T extends z.ZodTypeAny = z.ZodTypeAny> = readonly [name: string, type: T];\n\n/**\n * A function definition interface that describes the structure of a function.\n * @alpha\n */\nexport interface FunctionDef<\n\tArgs extends readonly Arg[],\n\tReturn extends z.ZodTypeAny,\n\tRest extends z.ZodTypeAny | null = null,\n> {\n\tdescription?: string;\n\targs: Args;\n\trest?: Rest;\n\treturns: Return;\n}\n\n/**\n * A class that implements the FunctionDef interface.\n */\nexport class FunctionWrapper\n\timplements FunctionDef<readonly Arg[], z.ZodTypeAny, z.ZodTypeAny | null>\n{\n\tpublic constructor(\n\t\tpublic readonly name: string,\n\t\tpublic readonly description: string | undefined,\n\t\tpublic readonly args: readonly Arg[],\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tpublic readonly rest: z.ZodTypeAny | null,\n\t\tpublic readonly returns: z.ZodTypeAny,\n\t) {}\n}\n\n/**\n * A utility type that extracts the argument types from a function definition.\n * @alpha\n */\nexport type ArgsTuple<T extends readonly Arg[]> = T extends readonly [infer Single extends Arg]\n\t? [Single[1]]\n\t: T extends readonly [infer Head extends Arg, ...infer Tail extends readonly Arg[]]\n\t\t? [Head[1], ...ArgsTuple<Tail>]\n\t\t: never;\n\n/**\n * A utility function to build a function definition.\n * @alpha\n */\nexport function buildFunc<\n\tconst Return extends z.ZodTypeAny,\n\tconst Args extends readonly Arg[],\n\tconst Rest extends z.ZodTypeAny | null = null,\n>(\n\tdef: { description?: string; returns: Return; rest?: Rest },\n\t...args: Args\n): FunctionDef<Args, Return, Rest> {\n\treturn {\n\t\tdescription: def.description,\n\t\treturns: def.returns,\n\t\targs,\n\t\trest: def.rest,\n\t};\n}\n\n/**\n * A utility type that infers the return type of a function definition.\n * @alpha\n */\nexport type Infer<T> = T extends FunctionDef<infer Args, infer Return, infer Rest>\n\t? z.infer<z.ZodFunction<z.ZodTuple<ArgsTuple<Args>, Rest>, Return>>\n\t: never;\n\n/**\n * An interface for exposing methods of schema classes to an agent.\n * @alpha\n */\nexport interface ExposedMethods {\n\texpose<\n\t\tconst K extends string & keyof MethodKeys<InstanceType<S>>,\n\t\tS extends BindableSchema & Ctor<Record<K, Infer<Z>>> & IExposedMethods,\n\t\tZ extends FunctionDef<any, any, any>,\n\t>(schema: S, methodName: K, zodFunction: Z): void;\n\n\t/**\n\t * Create a Zod schema for a SharedTree schema class.\n\t * @remarks\n\t * Use it to \"wrap\" schema types that are referenced as arguments or return types when exposing methods (with {@link ExposedMethods.expose}).\n\t */\n\tinstanceOf<T extends TreeNodeSchemaClass>(\n\t\tschema: T,\n\t): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>>;\n}\n\n/**\n * A symbol used to expose methods to the LLM.\n * @alpha\n */\nexport const exposeMethodsSymbol: unique symbol = Symbol(\"run\");\n\n/**\n * An interface that SharedTree schema classes should implement to expose their methods to the LLM.\n *\n * @remarks\n * The `getExposedMethods` 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 IExposedMethods {\n\t[exposeMethodsSymbol](methods: ExposedMethods): void;\n}\n\nclass ExposedMethodsI implements ExposedMethods {\n\tprivate readonly methods: Record<string, FunctionWrapper> = {};\n\tprivate readonly referencedTypes = new Set<TreeNodeSchema>();\n\n\tpublic constructor(private readonly schemaClass: BindableSchema) {}\n\n\tpublic expose<\n\t\tconst K extends string & keyof MethodKeys<InstanceType<S>>,\n\t\tS extends BindableSchema & Ctor<Record<K, Infer<Z>>> & IExposedMethods,\n\t\tZ extends FunctionDef<readonly Arg[], z.ZodTypeAny, z.ZodTypeAny | null>,\n\t>(schema: S, methodName: K, functionDef: Z): void {\n\t\tif (schema !== this.schemaClass) {\n\t\t\tthrow new Error('Must expose methods on the \"this\" object');\n\t\t}\n\t\tthis.methods[methodName] = new FunctionWrapper(\n\t\t\tmethodName,\n\t\t\tfunctionDef.description,\n\t\t\tfunctionDef.args,\n\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\tfunctionDef.rest ?? null,\n\t\t\tfunctionDef.returns,\n\t\t);\n\t}\n\n\tpublic instanceOf<T extends TreeNodeSchemaClass>(\n\t\tschema: T,\n\t): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>> {\n\t\tthis.referencedTypes.add(schema);\n\t\treturn instanceOf(schema);\n\t}\n\n\tpublic static getExposedMethods(schemaClass: BindableSchema): {\n\t\tmethods: Record<string, FunctionWrapper>;\n\t\treferencedTypes: Set<TreeNodeSchema>;\n\t} {\n\t\tconst exposedMethods = new ExposedMethodsI(schemaClass);\n\t\tconst extractable = schemaClass as unknown as IExposedMethods;\n\t\tif (extractable[exposeMethodsSymbol] !== undefined) {\n\t\t\textractable[exposeMethodsSymbol](exposedMethods);\n\t\t}\n\t\treturn {\n\t\t\tmethods: exposedMethods.methods,\n\t\t\treferencedTypes: exposedMethods.referencedTypes,\n\t\t};\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"methodBinding.js","sourceRoot":"","sources":["../src/methodBinding.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,+CAAgD;AAGhD,qEAAsD;AA2BtD;;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AS,EAAE,UAAa,EAAE,WAAc;QACzC,IAAI,MAAM,KAAK,IAAI,CAAC,WAAW,EAAE,CAAC;YACjC,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAC7D,CAAC;QACD,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,eAAe,CAC7C,UAAU,EACV,WAAW,CAAC,WAAW,EACvB,WAAW,CAAC,IAAI;QAChB,2CAA2C;QAC3C,WAAW,CAAC,IAAI,IAAI,IAAI,EACxB,WAAW,CAAC,OAAO,CACnB,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,iBAAiB,CAAC,WAA2B;QAI1D,MAAM,cAAc,GAAG,IAAI,eAAe,CAAC,WAAW,CAAC,CAAC;QACxD,MAAM,WAAW,GAAG,WAAyC,CAAC;QAC9D,IAAI,WAAW,CAAC,2BAAmB,CAAC,KAAK,SAAS,EAAE,CAAC;YACpD,WAAW,CAAC,2BAAmB,CAAC,CAAC,cAAc,CAAC,CAAC;QAClD,CAAC;QACD,OAAO;YACN,OAAO,EAAE,cAAc,CAAC,OAAO;YAC/B,eAAe,EAAE,cAAc,CAAC,eAAe;SAC/C,CAAC;IACH,CAAC;CACD","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 { NodeKind } from \"@fluidframework/tree\";\nimport type { z } from \"zod\";\n\nimport { instanceOf } from \"./renderZodTypeScript.js\";\nimport type { TypeFactoryType } from \"./treeAgentTypes.js\";\n\n/**\n * A utility type that extracts the method keys from a given type.\n * @alpha\n */\nexport type MethodKeys<T> = {\n\t[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never;\n};\n\n/**\n * A type that represents a constructor function.\n * @alpha\n */\nexport type Ctor<T = any> = new (...args: any[]) => T;\n\n/**\n * A type that represents an object schema class.\n * @alpha\n */\nexport type BindableSchema =\n\t| TreeNodeSchema<string, NodeKind.Object>\n\t| TreeNodeSchema<string, NodeKind.Record>\n\t| TreeNodeSchema<string, NodeKind.Array>\n\t| TreeNodeSchema<string, NodeKind.Map>;\n\n/**\n * A type guard to check if a schema is {@link BindableSchema | bindable}.\n */\nexport function isBindableSchema(schema: TreeNodeSchema): schema is BindableSchema {\n\treturn (\n\t\tschema.kind === NodeKind.Object ||\n\t\tschema.kind === NodeKind.Record ||\n\t\tschema.kind === NodeKind.Array ||\n\t\tschema.kind === NodeKind.Map\n\t);\n}\n\n/**\n * Get the exposed methods of a schema class.\n * @param schemaClass - The schema class to extract methods from.\n * @returns A record of method names and their corresponding Zod types.\n */\nexport function getExposedMethods(schemaClass: BindableSchema): {\n\tmethods: Record<string, FunctionWrapper>;\n\treferencedTypes: Set<TreeNodeSchema>;\n} {\n\treturn ExposedMethodsI.getExposedMethods(schemaClass);\n}\n\n/**\n * A type that represents a function argument.\n * @alpha\n */\nexport type Arg<T extends z.ZodTypeAny | TypeFactoryType = z.ZodTypeAny | TypeFactoryType> =\n\treadonly [name: string, type: T];\n\n/**\n * A function definition interface that describes the structure of a function.\n * @alpha\n */\nexport interface FunctionDef<\n\tArgs extends readonly Arg[],\n\tReturn extends z.ZodTypeAny | TypeFactoryType,\n\tRest extends z.ZodTypeAny | TypeFactoryType | null = null,\n> {\n\t/**\n\t * Optional description of the function.\n\t */\n\tdescription?: string;\n\t/**\n\t * The function's parameters.\n\t */\n\targs: Args;\n\t/**\n\t * Optional rest parameter type.\n\t */\n\trest?: Rest;\n\t/**\n\t * The function's return type.\n\t */\n\treturns: Return;\n}\n\n/**\n * A class that implements the FunctionDef interface.\n */\nexport class FunctionWrapper\n\timplements\n\t\tFunctionDef<\n\t\t\treadonly Arg[],\n\t\t\tz.ZodTypeAny | TypeFactoryType,\n\t\t\tz.ZodTypeAny | TypeFactoryType | null\n\t\t>\n{\n\tpublic constructor(\n\t\tpublic readonly name: string,\n\t\tpublic readonly description: string | undefined,\n\t\tpublic readonly args: readonly Arg[],\n\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\tpublic readonly rest: z.ZodTypeAny | TypeFactoryType | null,\n\t\tpublic readonly returns: z.ZodTypeAny | TypeFactoryType,\n\t) {}\n}\n\n/**\n * A utility type that extracts the argument types from a function definition.\n * @alpha\n */\nexport type ArgsTuple<T extends readonly Arg[]> = T extends readonly [infer Single extends Arg]\n\t? [Single[1]]\n\t: T extends readonly [infer Head extends Arg, ...infer Tail extends readonly Arg[]]\n\t\t? [Head[1], ...ArgsTuple<Tail>]\n\t\t: never;\n\n/**\n * A utility function to build a function definition.\n * @alpha\n */\nexport function buildFunc<\n\tconst Return extends z.ZodTypeAny | TypeFactoryType,\n\tconst Args extends readonly Arg[],\n\tconst Rest extends z.ZodTypeAny | TypeFactoryType | null = null,\n>(\n\tdef: { description?: string; returns: Return; rest?: Rest },\n\t...args: Args\n): FunctionDef<Args, Return, Rest> {\n\treturn {\n\t\tdescription: def.description,\n\t\treturns: def.returns,\n\t\targs,\n\t\trest: def.rest,\n\t};\n}\n\n/**\n * A utility type that extracts inferred parameter types from Zod args.\n * @alpha\n */\nexport type InferArgsZod<Args extends readonly Arg<z.ZodTypeAny>[]> = Args extends readonly [\n\tinfer Head extends Arg<z.ZodTypeAny>,\n\t...infer Tail extends readonly Arg<z.ZodTypeAny>[],\n]\n\t? [z.infer<Head[1]>, ...InferArgsZod<Tail>]\n\t: [];\n\n/**\n * A utility type that infers the function signature from a Zod function definition with strict type checking.\n * @alpha\n */\nexport type InferZod<T> = T extends FunctionDef<\n\tinfer Args extends readonly Arg<z.ZodTypeAny>[],\n\tinfer Return extends z.ZodTypeAny,\n\tany\n>\n\t? (...args: InferArgsZod<Args>) => z.infer<Return>\n\t: never;\n\n/**\n * A utility type that infers the function signature from a type factory function definition with relaxed type checking.\n * @alpha\n */\nexport type InferTypeFactory<T> = T extends FunctionDef<readonly Arg[], infer Return, any>\n\t? (...args: any[]) => any\n\t: never;\n\n/**\n * A utility type that infers the return type of a function definition.\n * @alpha\n * @remarks\n * For Zod types, provides strict compile-time type checking. For type factory types, returns `any`.\n * @deprecated Use InferZod or InferTypeFactory directly for better type safety.\n */\nexport type Infer<T> = T extends FunctionDef<readonly Arg[], infer Return, any>\n\t? Return extends z.ZodTypeAny\n\t\t? InferZod<T>\n\t\t: InferTypeFactory<T>\n\t: never;\n\n/**\n * An interface for exposing methods of schema classes to an agent.\n * @alpha\n */\nexport interface ExposedMethods {\n\t/**\n\t * Expose a method with Zod types (strict compile-time type checking).\n\t */\n\texpose<\n\t\tconst K extends string & keyof MethodKeys<InstanceType<S>>,\n\t\tS extends BindableSchema & Ctor<Record<K, InferZod<Z>>> & IExposedMethods,\n\t\tZ extends FunctionDef<readonly Arg<z.ZodTypeAny>[], z.ZodTypeAny, z.ZodTypeAny | null>,\n\t>(schema: S, methodName: K, zodFunction: Z): void;\n\n\t/**\n\t * Expose a method with type factory types (relaxed compile-time type checking).\n\t */\n\texpose<\n\t\tconst K extends string & keyof MethodKeys<InstanceType<S>>,\n\t\tS extends BindableSchema & Ctor & IExposedMethods,\n\t\tZ extends FunctionDef<\n\t\t\treadonly Arg<TypeFactoryType>[],\n\t\t\tTypeFactoryType,\n\t\t\tTypeFactoryType | null\n\t\t>,\n\t>(schema: S, methodName: K, tfFunction: Z): void;\n\n\t/**\n\t * Create a Zod schema for a SharedTree schema class.\n\t * @remarks\n\t * Use it to \"wrap\" schema types that are referenced as arguments or return types when exposing methods with {@link ExposedMethods}.\n\t */\n\tinstanceOf<T extends TreeNodeSchemaClass>(\n\t\tschema: T,\n\t): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>>;\n}\n\n/**\n * A symbol used to expose methods to the LLM.\n * @alpha\n */\nexport const exposeMethodsSymbol: unique symbol = Symbol(\"run\");\n\n/**\n * An interface that SharedTree schema classes should implement to expose their methods to the LLM.\n *\n * @remarks\n * The `getExposedMethods` 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 IExposedMethods {\n\t/**\n\t * Static method that exposes methods of this schema class to an agent.\n\t */\n\t[exposeMethodsSymbol](methods: ExposedMethods): void;\n}\n\nclass ExposedMethodsI implements ExposedMethods {\n\tprivate readonly methods: Record<string, FunctionWrapper> = {};\n\tprivate readonly referencedTypes = new Set<TreeNodeSchema>();\n\n\tpublic constructor(private readonly schemaClass: BindableSchema) {}\n\n\tpublic expose<\n\t\tconst K extends string & keyof MethodKeys<InstanceType<S>>,\n\t\tS extends BindableSchema & Ctor & IExposedMethods,\n\t\tZ extends FunctionDef<\n\t\t\treadonly Arg[],\n\t\t\tz.ZodTypeAny | TypeFactoryType,\n\t\t\tz.ZodTypeAny | TypeFactoryType | null\n\t\t>,\n\t>(schema: S, methodName: K, functionDef: Z): void {\n\t\tif (schema !== this.schemaClass) {\n\t\t\tthrow new Error('Must expose methods on the \"this\" object');\n\t\t}\n\t\tthis.methods[methodName] = new FunctionWrapper(\n\t\t\tmethodName,\n\t\t\tfunctionDef.description,\n\t\t\tfunctionDef.args,\n\t\t\t// eslint-disable-next-line unicorn/no-null\n\t\t\tfunctionDef.rest ?? null,\n\t\t\tfunctionDef.returns,\n\t\t);\n\t}\n\n\tpublic instanceOf<T extends TreeNodeSchemaClass>(\n\t\tschema: T,\n\t): z.ZodType<InstanceType<T>, z.ZodTypeDef, InstanceType<T>> {\n\t\tthis.referencedTypes.add(schema);\n\t\treturn instanceOf(schema);\n\t}\n\n\tpublic static getExposedMethods(schemaClass: BindableSchema): {\n\t\tmethods: Record<string, FunctionWrapper>;\n\t\treferencedTypes: Set<TreeNodeSchema>;\n\t} {\n\t\tconst exposedMethods = new ExposedMethodsI(schemaClass);\n\t\tconst extractable = schemaClass as unknown as IExposedMethods;\n\t\tif (extractable[exposeMethodsSymbol] !== undefined) {\n\t\t\textractable[exposeMethodsSymbol](exposedMethods);\n\t\t}\n\t\treturn {\n\t\t\tmethods: exposedMethods.methods,\n\t\t\treferencedTypes: exposedMethods.referencedTypes,\n\t\t};\n\t}\n}\n"]}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
import type { TreeNodeSchema, TreeNodeSchemaClass } from "@fluidframework/tree";
|
|
6
6
|
import type { ZodType, ZodTypeAny, ZodTypeDef, infer as ZodInfer } from "zod";
|
|
7
7
|
import type { BindableSchema, Ctor } from "./methodBinding.js";
|
|
8
|
+
import type { TypeFactoryType } from "./treeAgentTypes.js";
|
|
8
9
|
/**
|
|
9
10
|
* A symbol used to expose properties to the LLM.
|
|
10
11
|
* @alpha
|
|
@@ -60,21 +61,67 @@ export type TypeMatchOrError<Expected, Received> = [Received] extends [Expected]
|
|
|
60
61
|
* @alpha
|
|
61
62
|
*/
|
|
62
63
|
export declare class PropertyDef {
|
|
64
|
+
/**
|
|
65
|
+
* The name of the property.
|
|
66
|
+
*/
|
|
63
67
|
readonly name: string;
|
|
68
|
+
/**
|
|
69
|
+
* Optional description of the property.
|
|
70
|
+
*/
|
|
64
71
|
readonly description: string | undefined;
|
|
65
|
-
|
|
72
|
+
/**
|
|
73
|
+
* The schema defining the property's type (either Zod or TypeFactory).
|
|
74
|
+
*/
|
|
75
|
+
readonly schema: ZodTypeAny | TypeFactoryType;
|
|
76
|
+
/**
|
|
77
|
+
* Whether the property is readonly.
|
|
78
|
+
*/
|
|
66
79
|
readonly readOnly: boolean;
|
|
67
|
-
constructor(
|
|
80
|
+
constructor(
|
|
81
|
+
/**
|
|
82
|
+
* The name of the property.
|
|
83
|
+
*/
|
|
84
|
+
name: string,
|
|
85
|
+
/**
|
|
86
|
+
* Optional description of the property.
|
|
87
|
+
*/
|
|
88
|
+
description: string | undefined,
|
|
89
|
+
/**
|
|
90
|
+
* The schema defining the property's type (either Zod or TypeFactory).
|
|
91
|
+
*/
|
|
92
|
+
schema: ZodTypeAny | TypeFactoryType,
|
|
93
|
+
/**
|
|
94
|
+
* Whether the property is readonly.
|
|
95
|
+
*/
|
|
96
|
+
readOnly: boolean);
|
|
68
97
|
}
|
|
69
98
|
/**
|
|
70
99
|
* An interface for exposing properties of schema classes to an agent.
|
|
71
100
|
* @alpha
|
|
72
101
|
*/
|
|
73
102
|
export interface ExposedProperties {
|
|
103
|
+
/**
|
|
104
|
+
* Expose a property with Zod type checking.
|
|
105
|
+
*/
|
|
74
106
|
exposeProperty<S extends BindableSchema & Ctor, K extends string & ExposableKeys<InstanceType<S>>, TZ extends ZodTypeAny>(schema: S, name: K, def: {
|
|
75
107
|
schema: TZ;
|
|
76
108
|
description?: string;
|
|
77
109
|
} & ReadOnlyRequirement<InstanceType<S>, K> & TypeMatchOrError<InstanceType<S>[K], ZodInfer<TZ>>): void;
|
|
110
|
+
/**
|
|
111
|
+
* Expose a property with type factory type and metadata.
|
|
112
|
+
*/
|
|
113
|
+
exposeProperty<S extends BindableSchema & Ctor, K extends string & ExposableKeys<InstanceType<S>>>(schema: S, name: K, def: {
|
|
114
|
+
schema: TypeFactoryType;
|
|
115
|
+
description?: string;
|
|
116
|
+
readOnly?: boolean;
|
|
117
|
+
}): void;
|
|
118
|
+
/**
|
|
119
|
+
* Expose a property with type factory type (simple form).
|
|
120
|
+
*/
|
|
121
|
+
exposeProperty<S extends BindableSchema & Ctor, K extends string & ExposableKeys<InstanceType<S>>>(schema: S, name: K, tfType: TypeFactoryType): void;
|
|
122
|
+
/**
|
|
123
|
+
* Create a Zod type that references a SharedTree schema class.
|
|
124
|
+
*/
|
|
78
125
|
instanceOf<T extends TreeNodeSchemaClass>(schema: T): ZodType<InstanceType<T>, ZodTypeDef, InstanceType<T>>;
|
|
79
126
|
}
|
|
80
127
|
/**
|
|
@@ -92,6 +139,9 @@ export interface ExposedProperties {
|
|
|
92
139
|
* @alpha
|
|
93
140
|
*/
|
|
94
141
|
export interface IExposedProperties {
|
|
142
|
+
/**
|
|
143
|
+
* Static method that exposes properties of this schema class to an agent.
|
|
144
|
+
*/
|
|
95
145
|
[exposePropertiesSymbol]?(properties: ExposedProperties): void;
|
|
96
146
|
}
|
|
97
147
|
/**
|
|
@@ -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,UAAU,EAAE,UAAU,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,KAAK,CAAC;AAE9E,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;
|
|
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,UAAU,EAAE,UAAU,EAAE,KAAK,IAAI,QAAQ,EAAE,MAAM,KAAK,CAAC;AAE9E,OAAO,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG3D;;;GAGG;AACH,eAAO,MAAM,sBAAsB,EAAE,OAAO,MAE3C,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI;KAC7B,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IA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OAEG;IACH,cAAc,CACb,CAAC,SAAS,cAAc,GAAG,IAAI,EAC/B,CAAC,SAAS,MAAM,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,EAChD,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,eAAe,GAAG,IAAI,CAAC;IAErD;;OAEG;IACH,UAAU,CAAC,CAAC,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"}
|
package/dist/propertyBinding.js
CHANGED
|
@@ -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(
|
|
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,
|
|
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
|
-
|
|
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;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GAAG,CAAC,WAAW,EACf,GAAG,CAAC,MAAM,EACV,GAAG,CAAC,QAAQ,KAAK,IAAI,CACrB,CAAC;QACH,CAAC;IACF,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\";\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;
|
|
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,CAoV9B"}
|
|
@@ -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
|
|
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";
|
|
@@ -190,7 +192,9 @@ function renderSchemaTypeScript(definitions, bindableSchemas) {
|
|
|
190
192
|
lines.push(`// ${note}`);
|
|
191
193
|
}
|
|
192
194
|
}
|
|
193
|
-
|
|
195
|
+
const methodString = formatMethod(name, method);
|
|
196
|
+
const methodLines = methodString.split("\n");
|
|
197
|
+
lines.push(...methodLines);
|
|
194
198
|
}
|
|
195
199
|
if (lines.length > 0) {
|
|
196
200
|
hasHelperMethods = true;
|
|
@@ -327,7 +331,11 @@ function renderPropertyLines(properties) {
|
|
|
327
331
|
}
|
|
328
332
|
}
|
|
329
333
|
const modifier = property.readOnly ? "readonly " : "";
|
|
330
|
-
|
|
334
|
+
const typeString = renderType(property.schema, 0);
|
|
335
|
+
const propertyLine = `${modifier}${name}: ${typeString};`;
|
|
336
|
+
// Split multi-line type strings and add to lines array
|
|
337
|
+
const propertyLines = propertyLine.split("\n");
|
|
338
|
+
lines.push(...propertyLines);
|
|
331
339
|
}
|
|
332
340
|
return lines;
|
|
333
341
|
}
|
|
@@ -335,13 +343,13 @@ function formatMethod(name, method) {
|
|
|
335
343
|
const args = [];
|
|
336
344
|
for (const [argName, argType] of method.args) {
|
|
337
345
|
const { innerType, optional } = unwrapOptional(argType);
|
|
338
|
-
const renderedType =
|
|
346
|
+
const renderedType = renderType(innerType, 0);
|
|
339
347
|
args.push(`${argName}${optional ? "?" : ""}: ${renderedType}`);
|
|
340
348
|
}
|
|
341
349
|
if (method.rest !== null) {
|
|
342
|
-
args.push(`...rest: ${
|
|
350
|
+
args.push(`...rest: ${renderType(method.rest, 0)}[]`);
|
|
343
351
|
}
|
|
344
|
-
return `${name}(${args.join(", ")}): ${
|
|
352
|
+
return `${name}(${args.join(", ")}): ${renderType(method.returns, 0)};`;
|
|
345
353
|
}
|
|
346
354
|
function renderLeaf(leafKind) {
|
|
347
355
|
switch (leafKind) {
|
|
@@ -369,6 +377,11 @@ function formatExpression(expression, minPrecedence = 2 /* TypePrecedence.Object
|
|
|
369
377
|
* Detects optional zod wrappers so argument lists can keep TypeScript optional markers in sync.
|
|
370
378
|
*/
|
|
371
379
|
function unwrapOptional(type) {
|
|
380
|
+
// Handle type factory optional type
|
|
381
|
+
if ((0, treeAgentTypes_js_1.isTypeFactoryType)(type) && type._kind === "optional") {
|
|
382
|
+
return { innerType: type.innerType, optional: true };
|
|
383
|
+
}
|
|
384
|
+
// Handle Zod optional type
|
|
372
385
|
if (type instanceof zod_1.z.ZodOptional) {
|
|
373
386
|
const inner = type.unwrap();
|
|
374
387
|
return { innerType: inner, optional: true };
|
|
@@ -391,9 +404,11 @@ function ensureNoMemberConflicts(definition, fieldNames, methods, properties) {
|
|
|
391
404
|
}
|
|
392
405
|
}
|
|
393
406
|
/**
|
|
394
|
-
*
|
|
407
|
+
* Dispatches to the correct renderer based on whether the type is Zod or type factory.
|
|
395
408
|
*/
|
|
396
|
-
function
|
|
397
|
-
return (0,
|
|
409
|
+
function renderType(type, indentLevel = 0) {
|
|
410
|
+
return (0, treeAgentTypes_js_1.isTypeFactoryType)(type)
|
|
411
|
+
? (0, renderTypeFactoryTypeScript_js_1.renderTypeFactoryTypeScript)(type, utils_js_1.getFriendlyName, renderTypeFactoryTypeScript_js_1.instanceOfsTypeFactory, indentLevel)
|
|
412
|
+
: (0, renderZodTypeScript_js_1.renderZodTypeScript)(type, utils_js_1.getFriendlyName, renderZodTypeScript_js_1.instanceOfs);
|
|
398
413
|
}
|
|
399
414
|
//# sourceMappingURL=renderSchemaTypeScript.js.map
|
|
@@ -1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AAC,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,yDAAuD;AACvD,6DAA8E;AAC9E,qFAG0C;AAC1C,qEAA4E;AAE5E,2DAAwD;AAC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,oDAAoD,UAAU,EAAE,CAC9E,CAAC;QACH,CAAC;IACF,CAAC;IACD,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;QAC5C,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,qBAAU,CACnB,YAAY,IAAI,oDAAoD,UAAU,EAAE,CAChF,CAAC;QACH,CAAC;IACF,CAAC;AACF,CAAC;AAED;;GAEG;AACH,SAAS,UAAU,CAAC,IAAoC,EAAE,cAAsB,CAAC;IAChF,OAAO,IAAA,qCAAiB,EAAC,IAAI,CAAC;QAC7B,CAAC,CAAC,IAAA,4DAA2B,EAAC,IAAI,EAAE,0BAAe,EAAE,uDAAsB,EAAE,WAAW,CAAC;QACzF,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\tconst methodString = formatMethod(name, method);\n\t\t\tconst methodLines = methodString.split(\"\\n\");\n\t\t\tlines.push(...methodLines);\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\tconst typeString = renderType(property.schema, 0);\n\t\tconst propertyLine = `${modifier}${name}: ${typeString};`;\n\t\t// Split multi-line type strings and add to lines array\n\t\tconst propertyLines = propertyLine.split(\"\\n\");\n\t\tlines.push(...propertyLines);\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, 0);\n\t\targs.push(`${argName}${optional ? \"?\" : \"\"}: ${renderedType}`);\n\t}\n\tif (method.rest !== null) {\n\t\targs.push(`...rest: ${renderType(method.rest, 0)}[]`);\n\t}\n\treturn `${name}(${args.join(\", \")}): ${renderType(method.returns, 0)};`;\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, indentLevel: number = 0): string {\n\treturn isTypeFactoryType(type)\n\t\t? renderTypeFactoryTypeScript(type, getFriendlyName, instanceOfsTypeFactory, indentLevel)\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>, initialIndent?: number): 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,EAaf,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,EAC5D,aAAa,GAAE,MAAU,GACvB,MAAM,CA2RR"}
|