@fluidframework/tree-agent 2.81.0-374083 → 2.81.1
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 +95 -0
- package/api-report/tree-agent.alpha.api.md +33 -1
- package/dist/alpha.d.ts +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/prompt.d.ts +4 -0
- package/dist/prompt.d.ts.map +1 -1
- package/dist/prompt.js +20 -2
- package/dist/prompt.js.map +1 -1
- package/dist/renderSchemaTypeScript.d.ts.map +1 -1
- package/dist/renderSchemaTypeScript.js +18 -8
- package/dist/renderSchemaTypeScript.js.map +1 -1
- package/dist/renderTypeFactoryTypeScript.d.ts +1 -1
- package/dist/renderTypeFactoryTypeScript.d.ts.map +1 -1
- package/dist/renderTypeFactoryTypeScript.js +71 -3
- package/dist/renderTypeFactoryTypeScript.js.map +1 -1
- package/dist/treeAgentTypes.d.ts +86 -1
- package/dist/treeAgentTypes.d.ts.map +1 -1
- package/dist/treeAgentTypes.js +37 -0
- package/dist/treeAgentTypes.js.map +1 -1
- package/lib/alpha.d.ts +5 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/prompt.d.ts +4 -0
- package/lib/prompt.d.ts.map +1 -1
- package/lib/prompt.js +20 -2
- package/lib/prompt.js.map +1 -1
- package/lib/renderSchemaTypeScript.d.ts.map +1 -1
- package/lib/renderSchemaTypeScript.js +18 -8
- package/lib/renderSchemaTypeScript.js.map +1 -1
- package/lib/renderTypeFactoryTypeScript.d.ts +1 -1
- package/lib/renderTypeFactoryTypeScript.d.ts.map +1 -1
- package/lib/renderTypeFactoryTypeScript.js +71 -3
- package/lib/renderTypeFactoryTypeScript.js.map +1 -1
- package/lib/treeAgentTypes.d.ts +86 -1
- package/lib/treeAgentTypes.d.ts.map +1 -1
- package/lib/treeAgentTypes.js +37 -0
- package/lib/treeAgentTypes.js.map +1 -1
- package/package.json +10 -10
- package/src/index.ts +5 -0
- package/src/prompt.ts +21 -2
- package/src/renderSchemaTypeScript.ts +18 -8
- package/src/renderTypeFactoryTypeScript.ts +82 -2
- package/src/treeAgentTypes.ts +121 -0
|
@@ -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,qFAG0C;AAC1C,qEAA4E;AAE5E,2DAAwD;AACxD,yCAAyF;AAuBzF,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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AC;QACzC,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,MAAM,IAAI,qBAAU,CACnB,UAAU,IAAI,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;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"]}
|
|
1
|
+
{"version":3,"file":"renderSchemaTypeScript.js","sourceRoot":"","sources":["../src/renderSchemaTypeScript.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,uEAAsE;AACtE,4DAAiF;AASjF,6BAAwB;AAGxB,yDAAuD;AACvD,2CAAkD;AAClD,6DAA8E;AAC9E,qFAG0C;AAC1C,qEAA4E;AAE5E,2DAAwD;AACxD,yCAAyF;AAuBzF,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,GAA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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 { fluidHandleTypeName } from \"./prompt.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\tcase ValueSchema.FluidHandle: {\n\t\t\treturn fluidHandleTypeName;\n\t\t}\n\t\tdefault: {\n\t\t\tthrow new Error(`Unsupported leaf kind.`);\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"]}
|
|
@@ -9,5 +9,5 @@ export { instanceOfsTypeFactory } from "./treeAgentTypes.js";
|
|
|
9
9
|
* Converts type factory type definitions into TypeScript declaration text.
|
|
10
10
|
* @alpha
|
|
11
11
|
*/
|
|
12
|
-
export declare function renderTypeFactoryTypeScript(typeFactoryType: TypeFactoryType, getFriendlyName: (schema: TreeNodeSchema) => string, instanceOfLookup: WeakMap<TypeFactoryType, ObjectNodeSchema
|
|
12
|
+
export declare function renderTypeFactoryTypeScript(typeFactoryType: TypeFactoryType, getFriendlyName: (schema: TreeNodeSchema) => string, instanceOfLookup: WeakMap<TypeFactoryType, ObjectNodeSchema>, initialIndent?: number): string;
|
|
13
13
|
//# sourceMappingURL=renderTypeFactoryTypeScript.d.ts.map
|
|
@@ -1 +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,
|
|
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"}
|
|
@@ -12,10 +12,10 @@ Object.defineProperty(exports, "instanceOfsTypeFactory", { enumerable: true, get
|
|
|
12
12
|
* Converts type factory type definitions into TypeScript declaration text.
|
|
13
13
|
* @alpha
|
|
14
14
|
*/
|
|
15
|
-
function renderTypeFactoryTypeScript(typeFactoryType, getFriendlyName, instanceOfLookup) {
|
|
15
|
+
function renderTypeFactoryTypeScript(typeFactoryType, getFriendlyName, instanceOfLookup, initialIndent = 0) {
|
|
16
16
|
let result = "";
|
|
17
|
-
let startOfLine =
|
|
18
|
-
let indent =
|
|
17
|
+
let startOfLine = false;
|
|
18
|
+
let indent = initialIndent;
|
|
19
19
|
appendType(typeFactoryType, 0 /* TypePrecedence.Union */);
|
|
20
20
|
return result;
|
|
21
21
|
function appendType(type, minPrecedence = 2 /* TypePrecedence.Object */) {
|
|
@@ -53,6 +53,10 @@ function renderTypeFactoryTypeScript(typeFactoryType, getFriendlyName, instanceO
|
|
|
53
53
|
append("boolean");
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
|
+
case "date": {
|
|
57
|
+
append("Date");
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
56
60
|
case "void": {
|
|
57
61
|
append("void");
|
|
58
62
|
return;
|
|
@@ -73,6 +77,10 @@ function renderTypeFactoryTypeScript(typeFactoryType, getFriendlyName, instanceO
|
|
|
73
77
|
appendArrayType(type);
|
|
74
78
|
return;
|
|
75
79
|
}
|
|
80
|
+
case "promise": {
|
|
81
|
+
appendPromiseType(type);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
76
84
|
case "object": {
|
|
77
85
|
appendObjectType(type);
|
|
78
86
|
return;
|
|
@@ -81,6 +89,10 @@ function renderTypeFactoryTypeScript(typeFactoryType, getFriendlyName, instanceO
|
|
|
81
89
|
appendUnionTypes(type.options, 0 /* TypePrecedence.Union */);
|
|
82
90
|
return;
|
|
83
91
|
}
|
|
92
|
+
case "intersection": {
|
|
93
|
+
appendIntersectionTypes(type.types, 1 /* TypePrecedence.Intersection */);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
84
96
|
case "tuple": {
|
|
85
97
|
appendTupleType(type);
|
|
86
98
|
return;
|
|
@@ -105,6 +117,10 @@ function renderTypeFactoryTypeScript(typeFactoryType, getFriendlyName, instanceO
|
|
|
105
117
|
appendReadonlyType(type);
|
|
106
118
|
return;
|
|
107
119
|
}
|
|
120
|
+
case "function": {
|
|
121
|
+
appendFunctionType(type);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
108
124
|
case "instanceof": {
|
|
109
125
|
const schema = instanceOfLookup.get(type);
|
|
110
126
|
if (schema === undefined) {
|
|
@@ -122,6 +138,11 @@ function renderTypeFactoryTypeScript(typeFactoryType, getFriendlyName, instanceO
|
|
|
122
138
|
appendType(arrayType.element, 2 /* TypePrecedence.Object */);
|
|
123
139
|
append("[]");
|
|
124
140
|
}
|
|
141
|
+
function appendPromiseType(promiseType) {
|
|
142
|
+
append("Promise<");
|
|
143
|
+
appendType(promiseType.innerType, 0 /* TypePrecedence.Union */);
|
|
144
|
+
append(">");
|
|
145
|
+
}
|
|
125
146
|
function appendObjectType(objectType) {
|
|
126
147
|
append("{");
|
|
127
148
|
appendNewLine();
|
|
@@ -153,6 +174,16 @@ function renderTypeFactoryTypeScript(typeFactoryType, getFriendlyName, instanceO
|
|
|
153
174
|
first = false;
|
|
154
175
|
}
|
|
155
176
|
}
|
|
177
|
+
function appendIntersectionTypes(types, minPrecedence) {
|
|
178
|
+
let first = true;
|
|
179
|
+
for (const innerType of types) {
|
|
180
|
+
if (!first) {
|
|
181
|
+
append(" & ");
|
|
182
|
+
}
|
|
183
|
+
appendType(innerType, minPrecedence);
|
|
184
|
+
first = false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
156
187
|
function appendTupleType(tupleType) {
|
|
157
188
|
append("[");
|
|
158
189
|
let first = true;
|
|
@@ -201,6 +232,40 @@ function renderTypeFactoryTypeScript(typeFactoryType, getFriendlyName, instanceO
|
|
|
201
232
|
appendType(readonlyType.innerType);
|
|
202
233
|
append(">");
|
|
203
234
|
}
|
|
235
|
+
function appendFunctionType(functionType) {
|
|
236
|
+
append("(");
|
|
237
|
+
let first = true;
|
|
238
|
+
for (const param of functionType.parameters) {
|
|
239
|
+
if (!first) {
|
|
240
|
+
append(", ");
|
|
241
|
+
}
|
|
242
|
+
const [name, type] = param;
|
|
243
|
+
append(name);
|
|
244
|
+
if (type._kind === "optional") {
|
|
245
|
+
append("?");
|
|
246
|
+
append(": ");
|
|
247
|
+
appendType(type.innerType, 0 /* TypePrecedence.Union */);
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
append(": ");
|
|
251
|
+
appendType(type, 0 /* TypePrecedence.Union */);
|
|
252
|
+
}
|
|
253
|
+
first = false;
|
|
254
|
+
}
|
|
255
|
+
if (functionType.restParameter !== undefined) {
|
|
256
|
+
if (!first) {
|
|
257
|
+
append(", ");
|
|
258
|
+
}
|
|
259
|
+
const [name, type] = functionType.restParameter;
|
|
260
|
+
append("...");
|
|
261
|
+
append(name);
|
|
262
|
+
append(": ");
|
|
263
|
+
appendType(type, 2 /* TypePrecedence.Object */);
|
|
264
|
+
append("[]");
|
|
265
|
+
}
|
|
266
|
+
append(") => ");
|
|
267
|
+
appendType(functionType.returnType, 0 /* TypePrecedence.Union */);
|
|
268
|
+
}
|
|
204
269
|
}
|
|
205
270
|
exports.renderTypeFactoryTypeScript = renderTypeFactoryTypeScript;
|
|
206
271
|
var TypePrecedence;
|
|
@@ -214,6 +279,9 @@ function getTypePrecedence(type) {
|
|
|
214
279
|
case "union": {
|
|
215
280
|
return 0 /* TypePrecedence.Union */;
|
|
216
281
|
}
|
|
282
|
+
case "intersection": {
|
|
283
|
+
return 1 /* TypePrecedence.Intersection */;
|
|
284
|
+
}
|
|
217
285
|
default: {
|
|
218
286
|
return 2 /* TypePrecedence.Object */;
|
|
219
287
|
}
|
|
@@ -1 +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,C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uB;QAC7C,MAAM,CAAC,MAAM,CAAC,CAAC;QACf,UAAU,CAAC,OAAO,CAAC,OAAO,+BAAuB,CAAC;QAClD,MAAM,CAAC,IAAI,CAAC,CAAC;QACb,UAAU,CAAC,OAAO,CAAC,SAAS,+BAAuB,CAAC;QACpD,MAAM,CAAC,GAAG,CAAC,CAAC;IACb,CAAC;IAED,SAAS,aAAa,CAAC,KAAgC;QACtD,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/B,CAAC;IAED,SAAS,kBAAkB,CAAC,YAAiC;QAC5D,MAAM,CAAC,WAAW,CAAC,CAAC;QACpB,UAAU,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;QACnC,MAAM,CAAC,GAAG,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
|
+
{"version":3,"file":"renderTypeFactoryTypeScript.js","sourceRoot":"","sources":["../src/renderTypeFactoryTypeScript.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,uEAAsE;AAmBtE,yDAA6D;AAApD,2HAAA,sBAAsB,OAAA;AAE/B;;;GAGG;AACH,SAAgB,2BAA2B,CAC1C,eAAgC,EAChC,eAAmD,EACnD,gBAA4D,EAC5D,gBAAwB,CAAC;IAEzB,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,WAAW,GAAG,KAAK,CAAC;IACxB,IAAI,MAAM,GA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aAAa,CAAC;YAChD,MAAM,CAAC,KAAK,CAAC,CAAC;YACd,MAAM,CAAC,IAAI,CAAC,CAAC;YACb,MAAM,CAAC,IAAI,CAAC,CAAC;YACb,UAAU,CAAC,IAAI,gCAAwB,CAAC;YACxC,MAAM,CAAC,IAAI,CAAC,CAAC;QACd,CAAC;QACD,MAAM,CAAC,OAAO,CAAC,CAAC;QAChB,UAAU,CAAC,YAAY,CAAC,UAAU,+BAAuB,CAAC;IAC3D,CAAC;AACF,CAAC;AAhSD,kEAgSC;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,KAAK,cAAc,CAAC,CAAC,CAAC;YACrB,2CAAmC;QACpC,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\tTypeFactoryPromise,\n\tTypeFactoryObject,\n\tTypeFactoryTuple,\n\tTypeFactoryRecord,\n\tTypeFactoryMap,\n\tTypeFactoryLiteral,\n\tTypeFactoryOptional,\n\tTypeFactoryReadonly,\n\tTypeFactoryUnion,\n\tTypeFactoryIntersection,\n\tTypeFactoryFunction,\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\tinitialIndent: number = 0,\n): string {\n\tlet result = \"\";\n\tlet startOfLine = false;\n\tlet indent = initialIndent;\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 \"date\": {\n\t\t\t\tappend(\"Date\");\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 \"promise\": {\n\t\t\t\tappendPromiseType(type as TypeFactoryPromise);\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 \"intersection\": {\n\t\t\t\tappendIntersectionTypes(\n\t\t\t\t\t(type as TypeFactoryIntersection).types,\n\t\t\t\t\tTypePrecedence.Intersection,\n\t\t\t\t);\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 \"function\": {\n\t\t\t\tappendFunctionType(type as TypeFactoryFunction);\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 appendPromiseType(promiseType: TypeFactoryPromise): void {\n\t\tappend(\"Promise<\");\n\t\tappendType(promiseType.innerType, TypePrecedence.Union);\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 appendIntersectionTypes(\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\tfunction appendFunctionType(functionType: TypeFactoryFunction): void {\n\t\tappend(\"(\");\n\t\tlet first = true;\n\t\tfor (const param of functionType.parameters) {\n\t\t\tif (!first) {\n\t\t\t\tappend(\", \");\n\t\t\t}\n\t\t\tconst [name, type] = param;\n\t\t\tappend(name);\n\t\t\tif (type._kind === \"optional\") {\n\t\t\t\tappend(\"?\");\n\t\t\t\tappend(\": \");\n\t\t\t\tappendType((type as TypeFactoryOptional).innerType, TypePrecedence.Union);\n\t\t\t} else {\n\t\t\t\tappend(\": \");\n\t\t\t\tappendType(type, TypePrecedence.Union);\n\t\t\t}\n\t\t\tfirst = false;\n\t\t}\n\t\tif (functionType.restParameter !== undefined) {\n\t\t\tif (!first) {\n\t\t\t\tappend(\", \");\n\t\t\t}\n\t\t\tconst [name, type] = functionType.restParameter;\n\t\t\tappend(\"...\");\n\t\t\tappend(name);\n\t\t\tappend(\": \");\n\t\t\tappendType(type, TypePrecedence.Object);\n\t\t\tappend(\"[]\");\n\t\t}\n\t\tappend(\") => \");\n\t\tappendType(functionType.returnType, TypePrecedence.Union);\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\tcase \"intersection\": {\n\t\t\treturn TypePrecedence.Intersection;\n\t\t}\n\t\tdefault: {\n\t\t\treturn TypePrecedence.Object;\n\t\t}\n\t}\n}\n"]}
|
package/dist/treeAgentTypes.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { ObjectNodeSchema } from "@fluidframework/tree/alpha";
|
|
|
8
8
|
* Type kinds for the type factory type system.
|
|
9
9
|
* @alpha
|
|
10
10
|
*/
|
|
11
|
-
export type TypeFactoryTypeKind = "string" | "number" | "boolean" | "void" | "undefined" | "null" | "unknown" | "array" | "object" | "record" | "map" | "tuple" | "union" | "literal" | "optional" | "readonly" | "instanceof";
|
|
11
|
+
export type TypeFactoryTypeKind = "string" | "number" | "boolean" | "void" | "undefined" | "null" | "unknown" | "date" | "promise" | "array" | "object" | "record" | "map" | "tuple" | "union" | "intersection" | "literal" | "optional" | "readonly" | "function" | "instanceof";
|
|
12
12
|
/**
|
|
13
13
|
* Base interface for type factory types.
|
|
14
14
|
* @alpha
|
|
@@ -54,6 +54,16 @@ export interface TypeFactoryBoolean extends TypeFactoryType {
|
|
|
54
54
|
*/
|
|
55
55
|
readonly _kind: "boolean";
|
|
56
56
|
}
|
|
57
|
+
/**
|
|
58
|
+
* Represents a Date type in the type factory system.
|
|
59
|
+
* @alpha
|
|
60
|
+
*/
|
|
61
|
+
export interface TypeFactoryDate extends TypeFactoryType {
|
|
62
|
+
/**
|
|
63
|
+
* {@inheritDoc TypeFactoryType._kind}
|
|
64
|
+
*/
|
|
65
|
+
readonly _kind: "date";
|
|
66
|
+
}
|
|
57
67
|
/**
|
|
58
68
|
* Represents a void type in the type factory system.
|
|
59
69
|
* @alpha
|
|
@@ -108,6 +118,20 @@ export interface TypeFactoryArray extends TypeFactoryType {
|
|
|
108
118
|
*/
|
|
109
119
|
readonly element: TypeFactoryType;
|
|
110
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Represents a Promise type in the type factory system.
|
|
123
|
+
* @alpha
|
|
124
|
+
*/
|
|
125
|
+
export interface TypeFactoryPromise extends TypeFactoryType {
|
|
126
|
+
/**
|
|
127
|
+
* {@inheritDoc TypeFactoryType._kind}
|
|
128
|
+
*/
|
|
129
|
+
readonly _kind: "promise";
|
|
130
|
+
/**
|
|
131
|
+
* The type that the Promise resolves to.
|
|
132
|
+
*/
|
|
133
|
+
readonly innerType: TypeFactoryType;
|
|
134
|
+
}
|
|
111
135
|
/**
|
|
112
136
|
* Represents an object type with a fixed shape in the type factory system.
|
|
113
137
|
* @alpha
|
|
@@ -190,6 +214,20 @@ export interface TypeFactoryUnion extends TypeFactoryType {
|
|
|
190
214
|
*/
|
|
191
215
|
readonly options: readonly TypeFactoryType[];
|
|
192
216
|
}
|
|
217
|
+
/**
|
|
218
|
+
* Represents an intersection type in the type factory system.
|
|
219
|
+
* @alpha
|
|
220
|
+
*/
|
|
221
|
+
export interface TypeFactoryIntersection extends TypeFactoryType {
|
|
222
|
+
/**
|
|
223
|
+
* {@inheritDoc TypeFactoryType._kind}
|
|
224
|
+
*/
|
|
225
|
+
readonly _kind: "intersection";
|
|
226
|
+
/**
|
|
227
|
+
* The types to intersect.
|
|
228
|
+
*/
|
|
229
|
+
readonly types: readonly TypeFactoryType[];
|
|
230
|
+
}
|
|
193
231
|
/**
|
|
194
232
|
* Represents a literal type (specific string, number, or boolean value) in the type factory system.
|
|
195
233
|
* @alpha
|
|
@@ -232,6 +270,33 @@ export interface TypeFactoryReadonly extends TypeFactoryType {
|
|
|
232
270
|
*/
|
|
233
271
|
readonly innerType: TypeFactoryType;
|
|
234
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* Represents a function parameter as a tuple of [name, type].
|
|
275
|
+
* @alpha
|
|
276
|
+
*/
|
|
277
|
+
export type TypeFactoryFunctionParameter = readonly [name: string, type: TypeFactoryType];
|
|
278
|
+
/**
|
|
279
|
+
* Represents a function type in the type factory system.
|
|
280
|
+
* @alpha
|
|
281
|
+
*/
|
|
282
|
+
export interface TypeFactoryFunction extends TypeFactoryType {
|
|
283
|
+
/**
|
|
284
|
+
* {@inheritDoc TypeFactoryType._kind}
|
|
285
|
+
*/
|
|
286
|
+
readonly _kind: "function";
|
|
287
|
+
/**
|
|
288
|
+
* The function parameters.
|
|
289
|
+
*/
|
|
290
|
+
readonly parameters: readonly TypeFactoryFunctionParameter[];
|
|
291
|
+
/**
|
|
292
|
+
* The function return type.
|
|
293
|
+
*/
|
|
294
|
+
readonly returnType: TypeFactoryType;
|
|
295
|
+
/**
|
|
296
|
+
* Optional rest parameter for variable-length argument lists.
|
|
297
|
+
*/
|
|
298
|
+
readonly restParameter?: TypeFactoryFunctionParameter;
|
|
299
|
+
}
|
|
235
300
|
/**
|
|
236
301
|
* Represents an instanceof type that references a SharedTree schema class in the type factory system.
|
|
237
302
|
* @alpha
|
|
@@ -266,6 +331,11 @@ export declare const typeFactory: {
|
|
|
266
331
|
* @alpha
|
|
267
332
|
*/
|
|
268
333
|
boolean(): TypeFactoryBoolean;
|
|
334
|
+
/**
|
|
335
|
+
* Create a Date type.
|
|
336
|
+
* @alpha
|
|
337
|
+
*/
|
|
338
|
+
date(): TypeFactoryDate;
|
|
269
339
|
/**
|
|
270
340
|
* Create a void type.
|
|
271
341
|
* @alpha
|
|
@@ -291,6 +361,11 @@ export declare const typeFactory: {
|
|
|
291
361
|
* @alpha
|
|
292
362
|
*/
|
|
293
363
|
array(element: TypeFactoryType): TypeFactoryArray;
|
|
364
|
+
/**
|
|
365
|
+
* Create a Promise type.
|
|
366
|
+
* @alpha
|
|
367
|
+
*/
|
|
368
|
+
promise(innerType: TypeFactoryType): TypeFactoryPromise;
|
|
294
369
|
/**
|
|
295
370
|
* Create an object type.
|
|
296
371
|
* @alpha
|
|
@@ -316,6 +391,11 @@ export declare const typeFactory: {
|
|
|
316
391
|
* @alpha
|
|
317
392
|
*/
|
|
318
393
|
union(options: readonly TypeFactoryType[]): TypeFactoryUnion;
|
|
394
|
+
/**
|
|
395
|
+
* Create an intersection type.
|
|
396
|
+
* @alpha
|
|
397
|
+
*/
|
|
398
|
+
intersection(types: readonly TypeFactoryType[]): TypeFactoryIntersection;
|
|
319
399
|
/**
|
|
320
400
|
* Create a literal type.
|
|
321
401
|
* @alpha
|
|
@@ -331,6 +411,11 @@ export declare const typeFactory: {
|
|
|
331
411
|
* @alpha
|
|
332
412
|
*/
|
|
333
413
|
readonly(innerType: TypeFactoryType): TypeFactoryReadonly;
|
|
414
|
+
/**
|
|
415
|
+
* Create a function type.
|
|
416
|
+
* @alpha
|
|
417
|
+
*/
|
|
418
|
+
function(parameters: readonly TypeFactoryFunctionParameter[], returnType: TypeFactoryType, restParameter?: TypeFactoryFunctionParameter): TypeFactoryFunction;
|
|
334
419
|
/**
|
|
335
420
|
* Create an instanceOf type for a SharedTree schema class.
|
|
336
421
|
* @alpha
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"treeAgentTypes.d.ts","sourceRoot":"","sources":["../src/treeAgentTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAC5B,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,MAAM,GACN,WAAW,GACX,MAAM,GACN,SAAS,GACT,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,KAAK,GACL,OAAO,GACP,OAAO,GACP,SAAS,GACT,UAAU,GACV,UAAU,GACV,YAAY,CAAC;AAEhB;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC/B;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,mBAAmB,CAAC;CACpC;
|
|
1
|
+
{"version":3,"file":"treeAgentTypes.d.ts","sourceRoot":"","sources":["../src/treeAgentTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAE9D;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAC5B,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,MAAM,GACN,WAAW,GACX,MAAM,GACN,SAAS,GACT,MAAM,GACN,SAAS,GACT,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,KAAK,GACL,OAAO,GACP,OAAO,GACP,cAAc,GACd,SAAS,GACT,UAAU,GACV,U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js
CHANGED
|
@@ -19,15 +19,19 @@ const validTypeKinds = new Set([
|
|
|
19
19
|
"undefined",
|
|
20
20
|
"null",
|
|
21
21
|
"unknown",
|
|
22
|
+
"date",
|
|
23
|
+
"promise",
|
|
22
24
|
"array",
|
|
23
25
|
"object",
|
|
24
26
|
"record",
|
|
25
27
|
"map",
|
|
26
28
|
"tuple",
|
|
27
29
|
"union",
|
|
30
|
+
"intersection",
|
|
28
31
|
"literal",
|
|
29
32
|
"optional",
|
|
30
33
|
"readonly",
|
|
34
|
+
"function",
|
|
31
35
|
"instanceof",
|
|
32
36
|
]);
|
|
33
37
|
/**
|
|
@@ -68,6 +72,13 @@ exports.typeFactory = {
|
|
|
68
72
|
boolean() {
|
|
69
73
|
return { _kind: "boolean" };
|
|
70
74
|
},
|
|
75
|
+
/**
|
|
76
|
+
* Create a Date type.
|
|
77
|
+
* @alpha
|
|
78
|
+
*/
|
|
79
|
+
date() {
|
|
80
|
+
return { _kind: "date" };
|
|
81
|
+
},
|
|
71
82
|
/**
|
|
72
83
|
* Create a void type.
|
|
73
84
|
* @alpha
|
|
@@ -103,6 +114,13 @@ exports.typeFactory = {
|
|
|
103
114
|
array(element) {
|
|
104
115
|
return { _kind: "array", element };
|
|
105
116
|
},
|
|
117
|
+
/**
|
|
118
|
+
* Create a Promise type.
|
|
119
|
+
* @alpha
|
|
120
|
+
*/
|
|
121
|
+
promise(innerType) {
|
|
122
|
+
return { _kind: "promise", innerType };
|
|
123
|
+
},
|
|
106
124
|
/**
|
|
107
125
|
* Create an object type.
|
|
108
126
|
* @alpha
|
|
@@ -144,6 +162,16 @@ exports.typeFactory = {
|
|
|
144
162
|
}
|
|
145
163
|
return { _kind: "union", options };
|
|
146
164
|
},
|
|
165
|
+
/**
|
|
166
|
+
* Create an intersection type.
|
|
167
|
+
* @alpha
|
|
168
|
+
*/
|
|
169
|
+
intersection(types) {
|
|
170
|
+
if (types.length === 0) {
|
|
171
|
+
throw new internal_1.UsageError("typeFactory.intersection requires at least one type. Empty intersections are not valid TypeScript types.");
|
|
172
|
+
}
|
|
173
|
+
return { _kind: "intersection", types };
|
|
174
|
+
},
|
|
147
175
|
/**
|
|
148
176
|
* Create a literal type.
|
|
149
177
|
* @alpha
|
|
@@ -165,6 +193,15 @@ exports.typeFactory = {
|
|
|
165
193
|
readonly(innerType) {
|
|
166
194
|
return { _kind: "readonly", innerType };
|
|
167
195
|
},
|
|
196
|
+
/**
|
|
197
|
+
* Create a function type.
|
|
198
|
+
* @alpha
|
|
199
|
+
*/
|
|
200
|
+
function(parameters, returnType, restParameter) {
|
|
201
|
+
return restParameter === undefined
|
|
202
|
+
? { _kind: "function", parameters, returnType }
|
|
203
|
+
: { _kind: "function", parameters, returnType, restParameter };
|
|
204
|
+
},
|
|
168
205
|
/**
|
|
169
206
|
* Create an instanceOf type for a SharedTree schema class.
|
|
170
207
|
* @alpha
|