@fluidframework/tree-agent 2.80.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.
Files changed (73) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/api-report/tree-agent.alpha.api.md +195 -20
  3. package/dist/alpha.d.ts +31 -1
  4. package/dist/index.d.ts +3 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +5 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/methodBinding.d.ts +54 -10
  9. package/dist/methodBinding.d.ts.map +1 -1
  10. package/dist/methodBinding.js.map +1 -1
  11. package/dist/propertyBinding.d.ts +52 -2
  12. package/dist/propertyBinding.d.ts.map +1 -1
  13. package/dist/propertyBinding.js +28 -3
  14. package/dist/propertyBinding.js.map +1 -1
  15. package/dist/renderSchemaTypeScript.d.ts.map +1 -1
  16. package/dist/renderSchemaTypeScript.js +23 -8
  17. package/dist/renderSchemaTypeScript.js.map +1 -1
  18. package/dist/renderTypeFactoryTypeScript.d.ts +13 -0
  19. package/dist/renderTypeFactoryTypeScript.d.ts.map +1 -0
  20. package/dist/renderTypeFactoryTypeScript.js +290 -0
  21. package/dist/renderTypeFactoryTypeScript.js.map +1 -0
  22. package/dist/subtree.d.ts.map +1 -1
  23. package/dist/subtree.js +4 -4
  24. package/dist/subtree.js.map +1 -1
  25. package/dist/treeAgentTypes.d.ts +430 -0
  26. package/dist/treeAgentTypes.d.ts.map +1 -0
  27. package/dist/treeAgentTypes.js +227 -0
  28. package/dist/treeAgentTypes.js.map +1 -0
  29. package/dist/utils.d.ts +0 -4
  30. package/dist/utils.d.ts.map +1 -1
  31. package/dist/utils.js +2 -9
  32. package/dist/utils.js.map +1 -1
  33. package/eslint.config.mts +4 -4
  34. package/lib/alpha.d.ts +31 -1
  35. package/lib/index.d.ts +3 -1
  36. package/lib/index.d.ts.map +1 -1
  37. package/lib/index.js +1 -0
  38. package/lib/index.js.map +1 -1
  39. package/lib/methodBinding.d.ts +54 -10
  40. package/lib/methodBinding.d.ts.map +1 -1
  41. package/lib/methodBinding.js.map +1 -1
  42. package/lib/propertyBinding.d.ts +52 -2
  43. package/lib/propertyBinding.d.ts.map +1 -1
  44. package/lib/propertyBinding.js +28 -3
  45. package/lib/propertyBinding.js.map +1 -1
  46. package/lib/renderSchemaTypeScript.d.ts.map +1 -1
  47. package/lib/renderSchemaTypeScript.js +23 -8
  48. package/lib/renderSchemaTypeScript.js.map +1 -1
  49. package/lib/renderTypeFactoryTypeScript.d.ts +13 -0
  50. package/lib/renderTypeFactoryTypeScript.d.ts.map +1 -0
  51. package/lib/renderTypeFactoryTypeScript.js +285 -0
  52. package/lib/renderTypeFactoryTypeScript.js.map +1 -0
  53. package/lib/subtree.d.ts.map +1 -1
  54. package/lib/subtree.js +4 -4
  55. package/lib/subtree.js.map +1 -1
  56. package/lib/treeAgentTypes.d.ts +430 -0
  57. package/lib/treeAgentTypes.d.ts.map +1 -0
  58. package/lib/treeAgentTypes.js +223 -0
  59. package/lib/treeAgentTypes.js.map +1 -0
  60. package/lib/utils.d.ts +0 -4
  61. package/lib/utils.d.ts.map +1 -1
  62. package/lib/utils.js +2 -8
  63. package/lib/utils.js.map +1 -1
  64. package/package.json +12 -12
  65. package/src/index.ts +36 -0
  66. package/src/methodBinding.ts +93 -15
  67. package/src/propertyBinding.ts +66 -9
  68. package/src/renderSchemaTypeScript.ts +31 -9
  69. package/src/renderTypeFactoryTypeScript.ts +339 -0
  70. package/src/subtree.ts +5 -4
  71. package/src/treeAgentTypes.ts +611 -0
  72. package/src/utils.ts +2 -9
  73. package/.eslintrc.cjs +0 -48
@@ -0,0 +1,223 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { UsageError } from "@fluidframework/telemetry-utils/internal";
6
+ import { ObjectNodeSchema } from "@fluidframework/tree/alpha";
7
+ /**
8
+ * Set of valid type factory type kinds for efficient validation.
9
+ * @internal
10
+ */
11
+ const validTypeKinds = new Set([
12
+ "string",
13
+ "number",
14
+ "boolean",
15
+ "void",
16
+ "undefined",
17
+ "null",
18
+ "unknown",
19
+ "date",
20
+ "promise",
21
+ "array",
22
+ "object",
23
+ "record",
24
+ "map",
25
+ "tuple",
26
+ "union",
27
+ "intersection",
28
+ "literal",
29
+ "optional",
30
+ "readonly",
31
+ "function",
32
+ "instanceof",
33
+ ]);
34
+ /**
35
+ * Type guard to check if a value is a type factory type.
36
+ * @alpha
37
+ */
38
+ export function isTypeFactoryType(value) {
39
+ if (typeof value !== "object" || value === null || !("_kind" in value)) {
40
+ return false;
41
+ }
42
+ const kind = value._kind;
43
+ return typeof kind === "string" && validTypeKinds.has(kind);
44
+ }
45
+ /**
46
+ * Namespace containing type factory functions.
47
+ * @alpha
48
+ */
49
+ export const typeFactory = {
50
+ /**
51
+ * Create a string type.
52
+ * @alpha
53
+ */
54
+ string() {
55
+ return { _kind: "string" };
56
+ },
57
+ /**
58
+ * Create a number type.
59
+ * @alpha
60
+ */
61
+ number() {
62
+ return { _kind: "number" };
63
+ },
64
+ /**
65
+ * Create a boolean type.
66
+ * @alpha
67
+ */
68
+ boolean() {
69
+ return { _kind: "boolean" };
70
+ },
71
+ /**
72
+ * Create a Date type.
73
+ * @alpha
74
+ */
75
+ date() {
76
+ return { _kind: "date" };
77
+ },
78
+ /**
79
+ * Create a void type.
80
+ * @alpha
81
+ */
82
+ void() {
83
+ return { _kind: "void" };
84
+ },
85
+ /**
86
+ * Create an undefined type.
87
+ * @alpha
88
+ */
89
+ undefined() {
90
+ return { _kind: "undefined" };
91
+ },
92
+ /**
93
+ * Create a null type.
94
+ * @alpha
95
+ */
96
+ null() {
97
+ return { _kind: "null" };
98
+ },
99
+ /**
100
+ * Create an unknown type.
101
+ * @alpha
102
+ */
103
+ unknown() {
104
+ return { _kind: "unknown" };
105
+ },
106
+ /**
107
+ * Create an array type.
108
+ * @alpha
109
+ */
110
+ array(element) {
111
+ return { _kind: "array", element };
112
+ },
113
+ /**
114
+ * Create a Promise type.
115
+ * @alpha
116
+ */
117
+ promise(innerType) {
118
+ return { _kind: "promise", innerType };
119
+ },
120
+ /**
121
+ * Create an object type.
122
+ * @alpha
123
+ */
124
+ object(shape) {
125
+ return { _kind: "object", shape };
126
+ },
127
+ /**
128
+ * Create a record type.
129
+ * @alpha
130
+ */
131
+ record(keyType, valueType) {
132
+ return { _kind: "record", keyType, valueType };
133
+ },
134
+ /**
135
+ * Create a map type.
136
+ * @alpha
137
+ */
138
+ map(keyType, valueType) {
139
+ return { _kind: "map", keyType, valueType };
140
+ },
141
+ /**
142
+ * Create a tuple type.
143
+ * @alpha
144
+ */
145
+ tuple(items, rest) {
146
+ if (items.length === 0 && rest === undefined) {
147
+ throw new UsageError("typeFactory.tuple requires at least one item or a rest type. Empty tuples are not supported.");
148
+ }
149
+ return rest === undefined ? { _kind: "tuple", items } : { _kind: "tuple", items, rest };
150
+ },
151
+ /**
152
+ * Create a union type.
153
+ * @alpha
154
+ */
155
+ union(options) {
156
+ if (options.length === 0) {
157
+ throw new UsageError("typeFactory.union requires at least one option. Empty unions are not valid TypeScript types.");
158
+ }
159
+ return { _kind: "union", options };
160
+ },
161
+ /**
162
+ * Create an intersection type.
163
+ * @alpha
164
+ */
165
+ intersection(types) {
166
+ if (types.length === 0) {
167
+ throw new UsageError("typeFactory.intersection requires at least one type. Empty intersections are not valid TypeScript types.");
168
+ }
169
+ return { _kind: "intersection", types };
170
+ },
171
+ /**
172
+ * Create a literal type.
173
+ * @alpha
174
+ */
175
+ literal(value) {
176
+ return { _kind: "literal", value };
177
+ },
178
+ /**
179
+ * Create an optional type.
180
+ * @alpha
181
+ */
182
+ optional(innerType) {
183
+ return { _kind: "optional", innerType };
184
+ },
185
+ /**
186
+ * Create a readonly type.
187
+ * @alpha
188
+ */
189
+ readonly(innerType) {
190
+ return { _kind: "readonly", innerType };
191
+ },
192
+ /**
193
+ * Create a function type.
194
+ * @alpha
195
+ */
196
+ function(parameters, returnType, restParameter) {
197
+ return restParameter === undefined
198
+ ? { _kind: "function", parameters, returnType }
199
+ : { _kind: "function", parameters, returnType, restParameter };
200
+ },
201
+ /**
202
+ * Create an instanceOf type for a SharedTree schema class.
203
+ * @alpha
204
+ */
205
+ instanceOf(schema) {
206
+ if (!(schema instanceof ObjectNodeSchema)) {
207
+ throw new UsageError(`typeFactory.instanceOf only supports ObjectNodeSchema-based schema classes (created via SchemaFactory.object). ` +
208
+ `Pass a schema class that extends from an object schema (e.g., sf.object(...)), not primitive, array, or map schemas.`);
209
+ }
210
+ const instanceOfType = {
211
+ _kind: "instanceof",
212
+ schema,
213
+ };
214
+ instanceOfsTypeFactory.set(instanceOfType, schema);
215
+ return instanceOfType;
216
+ },
217
+ };
218
+ /**
219
+ * A lookup from type factory instanceOf types to their corresponding ObjectNodeSchema.
220
+ * @alpha
221
+ */
222
+ export const instanceOfsTypeFactory = new WeakMap();
223
+ //# sourceMappingURL=treeAgentTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"treeAgentTypes.js","sourceRoot":"","sources":["../src/treeAgentTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAwC9D;;;GAGG;AACH,MAAM,cAAc,GAAqC,IAAI,GAAG,CAAsB;IACrF,QAAQ;IACR,QAAQ;IACR,SAAS;IACT,MAAM;IACN,WAAW;IACX,MAAM;IACN,SAAS;IACT,MAAM;IACN,SAAS;IACT,OAAO;IACP,QAAQ;IACR,QAAQ;IACR,KAAK;IACL,OAAO;IACP,OAAO;IACP,cAAc;IACd,SAAS;IACT,UAAU;IACV,UAAU;IACV,UAAU;IACV,YAAY;CACZ,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAc;IAC/C,IAAI,OAAO,KAAK,KAAK,QAAQ,IAA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,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;IACpC,CAAC;IAED;;;OAGG;IACH,QAAQ,CAAC,SAA0B;QAClC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;IACzC,CAAC;IAED;;;OAGG;IACH,QAAQ,CAAC,SAA0B;QAClC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,CAAC;IACzC,CAAC;IAED;;;OAGG;IACH,QAAQ,CACP,UAAmD,EACnD,UAA2B,EAC3B,aAA4C;QAE5C,OAAO,aAAa,KAAK,SAAS;YACjC,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE;YAC/C,CAAC,CAAC,EAAE,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC;IACjE,CAAC;IAED;;;OAGG;IACH,UAAU,CAAgC,MAAS;QAClD,IAAI,CAAC,CAAC,MAAM,YAAY,gBAAgB,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,UAAU,CACnB,iHAAiH;gBAChH,sHAAsH,CACvH,CAAC;QACH,CAAC;QACD,MAAM,cAAc,GAA0B;YAC7C,KAAK,EAAE,YAAY;YACnB,MAAM;SACN,CAAC;QACF,sBAAsB,CAAC,GAAG,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;QACnD,OAAO,cAAc,CAAC;IACvB,CAAC;CACD,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,OAAO,EAA2C,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 { TreeNodeSchemaClass } from \"@fluidframework/tree/alpha\";\nimport { ObjectNodeSchema } from \"@fluidframework/tree/alpha\";\n\n/**\n * Type kinds for the type factory type system.\n * @alpha\n */\nexport type TypeFactoryTypeKind =\n\t| \"string\"\n\t| \"number\"\n\t| \"boolean\"\n\t| \"void\"\n\t| \"undefined\"\n\t| \"null\"\n\t| \"unknown\"\n\t| \"date\"\n\t| \"promise\"\n\t| \"array\"\n\t| \"object\"\n\t| \"record\"\n\t| \"map\"\n\t| \"tuple\"\n\t| \"union\"\n\t| \"intersection\"\n\t| \"literal\"\n\t| \"optional\"\n\t| \"readonly\"\n\t| \"function\"\n\t| \"instanceof\";\n\n/**\n * Base interface for type factory types.\n * @alpha\n */\nexport interface TypeFactoryType {\n\t/**\n\t * The kind of type this represents.\n\t */\n\treadonly _kind: TypeFactoryTypeKind;\n}\n\n/**\n * Set of valid type factory type kinds for efficient validation.\n * @internal\n */\nconst validTypeKinds: ReadonlySet<TypeFactoryTypeKind> = new Set<TypeFactoryTypeKind>([\n\t\"string\",\n\t\"number\",\n\t\"boolean\",\n\t\"void\",\n\t\"undefined\",\n\t\"null\",\n\t\"unknown\",\n\t\"date\",\n\t\"promise\",\n\t\"array\",\n\t\"object\",\n\t\"record\",\n\t\"map\",\n\t\"tuple\",\n\t\"union\",\n\t\"intersection\",\n\t\"literal\",\n\t\"optional\",\n\t\"readonly\",\n\t\"function\",\n\t\"instanceof\",\n]);\n\n/**\n * Type guard to check if a value is a type factory type.\n * @alpha\n */\nexport function isTypeFactoryType(value: unknown): value is TypeFactoryType {\n\tif (typeof value !== \"object\" || value === null || !(\"_kind\" in value)) {\n\t\treturn false;\n\t}\n\tconst kind = (value as { _kind: unknown })._kind;\n\treturn typeof kind === \"string\" && validTypeKinds.has(kind as TypeFactoryTypeKind);\n}\n\n// Primitive type factories\n\n/**\n * Represents a string type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryString extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"string\";\n}\n\n/**\n * Represents a number type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryNumber extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"number\";\n}\n\n/**\n * Represents a boolean type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryBoolean extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"boolean\";\n}\n\n/**\n * Represents a Date type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryDate extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"date\";\n}\n\n/**\n * Represents a void type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryVoid extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"void\";\n}\n\n/**\n * Represents an undefined type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryUndefined extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"undefined\";\n}\n\n/**\n * Represents a null type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryNull extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"null\";\n}\n\n/**\n * Represents an unknown type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryUnknown extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"unknown\";\n}\n\n// Complex type interfaces\n\n/**\n * Represents an array type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryArray extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"array\";\n\t/**\n\t * The type of elements in the array.\n\t */\n\treadonly element: TypeFactoryType;\n}\n\n/**\n * Represents a Promise type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryPromise extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"promise\";\n\t/**\n\t * The type that the Promise resolves to.\n\t */\n\treadonly innerType: TypeFactoryType;\n}\n\n/**\n * Represents an object type with a fixed shape in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryObject extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"object\";\n\t/**\n\t * The shape of the object, mapping property names to their types.\n\t */\n\treadonly shape: Record<string, TypeFactoryType>;\n}\n\n/**\n * Represents a record type (index signature) in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryRecord extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"record\";\n\t/**\n\t * The type of the record's keys.\n\t */\n\treadonly keyType: TypeFactoryType;\n\t/**\n\t * The type of the record's values.\n\t */\n\treadonly valueType: TypeFactoryType;\n}\n\n/**\n * Represents a Map type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryMap extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"map\";\n\t/**\n\t * The type of the map's keys.\n\t */\n\treadonly keyType: TypeFactoryType;\n\t/**\n\t * The type of the map's values.\n\t */\n\treadonly valueType: TypeFactoryType;\n}\n\n/**\n * Represents a tuple type with fixed-length items and optional rest elements in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryTuple extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"tuple\";\n\t/**\n\t * The fixed-length items in the tuple.\n\t */\n\treadonly items: readonly TypeFactoryType[];\n\t/**\n\t * Optional rest element type for variable-length tuples.\n\t */\n\treadonly rest?: TypeFactoryType;\n}\n\n/**\n * Represents a union type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryUnion extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"union\";\n\t/**\n\t * The possible types in the union.\n\t */\n\treadonly options: readonly TypeFactoryType[];\n}\n\n/**\n * Represents an intersection type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryIntersection extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"intersection\";\n\t/**\n\t * The types to intersect.\n\t */\n\treadonly types: readonly TypeFactoryType[];\n}\n\n/**\n * Represents a literal type (specific string, number, or boolean value) in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryLiteral extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"literal\";\n\t/**\n\t * The specific literal value.\n\t */\n\treadonly value: string | number | boolean;\n}\n\n/**\n * Represents an optional type modifier in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryOptional extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"optional\";\n\t/**\n\t * The inner type that is optional.\n\t */\n\treadonly innerType: TypeFactoryType;\n}\n\n/**\n * Represents a readonly type modifier in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryReadonly extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"readonly\";\n\t/**\n\t * The inner type that is readonly.\n\t */\n\treadonly innerType: TypeFactoryType;\n}\n\n/**\n * Represents a function parameter as a tuple of [name, type].\n * @alpha\n */\nexport type TypeFactoryFunctionParameter = readonly [name: string, type: TypeFactoryType];\n\n/**\n * Represents a function type in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryFunction extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"function\";\n\t/**\n\t * The function parameters.\n\t */\n\treadonly parameters: readonly TypeFactoryFunctionParameter[];\n\t/**\n\t * The function return type.\n\t */\n\treadonly returnType: TypeFactoryType;\n\t/**\n\t * Optional rest parameter for variable-length argument lists.\n\t */\n\treadonly restParameter?: TypeFactoryFunctionParameter;\n}\n\n/**\n * Represents an instanceof type that references a SharedTree schema class in the type factory system.\n * @alpha\n */\nexport interface TypeFactoryInstanceOf extends TypeFactoryType {\n\t/**\n\t * {@inheritDoc TypeFactoryType._kind}\n\t */\n\treadonly _kind: \"instanceof\";\n\t/**\n\t * The SharedTree schema class to reference.\n\t */\n\treadonly schema: ObjectNodeSchema;\n}\n\n/**\n * Namespace containing type factory functions.\n * @alpha\n */\nexport const typeFactory = {\n\t/**\n\t * Create a string type.\n\t * @alpha\n\t */\n\tstring(): TypeFactoryString {\n\t\treturn { _kind: \"string\" };\n\t},\n\n\t/**\n\t * Create a number type.\n\t * @alpha\n\t */\n\tnumber(): TypeFactoryNumber {\n\t\treturn { _kind: \"number\" };\n\t},\n\n\t/**\n\t * Create a boolean type.\n\t * @alpha\n\t */\n\tboolean(): TypeFactoryBoolean {\n\t\treturn { _kind: \"boolean\" };\n\t},\n\n\t/**\n\t * Create a Date type.\n\t * @alpha\n\t */\n\tdate(): TypeFactoryDate {\n\t\treturn { _kind: \"date\" };\n\t},\n\n\t/**\n\t * Create a void type.\n\t * @alpha\n\t */\n\tvoid(): TypeFactoryVoid {\n\t\treturn { _kind: \"void\" };\n\t},\n\n\t/**\n\t * Create an undefined type.\n\t * @alpha\n\t */\n\tundefined(): TypeFactoryUndefined {\n\t\treturn { _kind: \"undefined\" };\n\t},\n\n\t/**\n\t * Create a null type.\n\t * @alpha\n\t */\n\tnull(): TypeFactoryNull {\n\t\treturn { _kind: \"null\" };\n\t},\n\n\t/**\n\t * Create an unknown type.\n\t * @alpha\n\t */\n\tunknown(): TypeFactoryUnknown {\n\t\treturn { _kind: \"unknown\" };\n\t},\n\n\t/**\n\t * Create an array type.\n\t * @alpha\n\t */\n\tarray(element: TypeFactoryType): TypeFactoryArray {\n\t\treturn { _kind: \"array\", element };\n\t},\n\n\t/**\n\t * Create a Promise type.\n\t * @alpha\n\t */\n\tpromise(innerType: TypeFactoryType): TypeFactoryPromise {\n\t\treturn { _kind: \"promise\", innerType };\n\t},\n\n\t/**\n\t * Create an object type.\n\t * @alpha\n\t */\n\tobject(shape: Record<string, TypeFactoryType>): TypeFactoryObject {\n\t\treturn { _kind: \"object\", shape };\n\t},\n\n\t/**\n\t * Create a record type.\n\t * @alpha\n\t */\n\trecord(keyType: TypeFactoryType, valueType: TypeFactoryType): TypeFactoryRecord {\n\t\treturn { _kind: \"record\", keyType, valueType };\n\t},\n\n\t/**\n\t * Create a map type.\n\t * @alpha\n\t */\n\tmap(keyType: TypeFactoryType, valueType: TypeFactoryType): TypeFactoryMap {\n\t\treturn { _kind: \"map\", keyType, valueType };\n\t},\n\n\t/**\n\t * Create a tuple type.\n\t * @alpha\n\t */\n\ttuple(items: readonly TypeFactoryType[], rest?: TypeFactoryType): TypeFactoryTuple {\n\t\tif (items.length === 0 && rest === undefined) {\n\t\t\tthrow new UsageError(\n\t\t\t\t\"typeFactory.tuple requires at least one item or a rest type. Empty tuples are not supported.\",\n\t\t\t);\n\t\t}\n\t\treturn rest === undefined ? { _kind: \"tuple\", items } : { _kind: \"tuple\", items, rest };\n\t},\n\n\t/**\n\t * Create a union type.\n\t * @alpha\n\t */\n\tunion(options: readonly TypeFactoryType[]): TypeFactoryUnion {\n\t\tif (options.length === 0) {\n\t\t\tthrow new UsageError(\n\t\t\t\t\"typeFactory.union requires at least one option. Empty unions are not valid TypeScript types.\",\n\t\t\t);\n\t\t}\n\t\treturn { _kind: \"union\", options };\n\t},\n\n\t/**\n\t * Create an intersection type.\n\t * @alpha\n\t */\n\tintersection(types: readonly TypeFactoryType[]): TypeFactoryIntersection {\n\t\tif (types.length === 0) {\n\t\t\tthrow new UsageError(\n\t\t\t\t\"typeFactory.intersection requires at least one type. Empty intersections are not valid TypeScript types.\",\n\t\t\t);\n\t\t}\n\t\treturn { _kind: \"intersection\", types };\n\t},\n\n\t/**\n\t * Create a literal type.\n\t * @alpha\n\t */\n\tliteral(value: string | number | boolean): TypeFactoryLiteral {\n\t\treturn { _kind: \"literal\", value };\n\t},\n\n\t/**\n\t * Create an optional type.\n\t * @alpha\n\t */\n\toptional(innerType: TypeFactoryType): TypeFactoryOptional {\n\t\treturn { _kind: \"optional\", innerType };\n\t},\n\n\t/**\n\t * Create a readonly type.\n\t * @alpha\n\t */\n\treadonly(innerType: TypeFactoryType): TypeFactoryReadonly {\n\t\treturn { _kind: \"readonly\", innerType };\n\t},\n\n\t/**\n\t * Create a function type.\n\t * @alpha\n\t */\n\tfunction(\n\t\tparameters: readonly TypeFactoryFunctionParameter[],\n\t\treturnType: TypeFactoryType,\n\t\trestParameter?: TypeFactoryFunctionParameter,\n\t): TypeFactoryFunction {\n\t\treturn restParameter === undefined\n\t\t\t? { _kind: \"function\", parameters, returnType }\n\t\t\t: { _kind: \"function\", parameters, returnType, restParameter };\n\t},\n\n\t/**\n\t * Create an instanceOf type for a SharedTree schema class.\n\t * @alpha\n\t */\n\tinstanceOf<T extends TreeNodeSchemaClass>(schema: T): TypeFactoryInstanceOf {\n\t\tif (!(schema instanceof ObjectNodeSchema)) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`typeFactory.instanceOf only supports ObjectNodeSchema-based schema classes (created via SchemaFactory.object). ` +\n\t\t\t\t\t`Pass a schema class that extends from an object schema (e.g., sf.object(...)), not primitive, array, or map schemas.`,\n\t\t\t);\n\t\t}\n\t\tconst instanceOfType: TypeFactoryInstanceOf = {\n\t\t\t_kind: \"instanceof\",\n\t\t\tschema,\n\t\t};\n\t\tinstanceOfsTypeFactory.set(instanceOfType, schema);\n\t\treturn instanceOfType;\n\t},\n};\n\n/**\n * A lookup from type factory instanceOf types to their corresponding ObjectNodeSchema.\n * @alpha\n */\nexport const instanceOfsTypeFactory = new WeakMap<TypeFactoryInstanceOf, ObjectNodeSchema>();\n"]}
package/lib/utils.d.ts CHANGED
@@ -13,10 +13,6 @@ export interface MapGetSet<K, V> {
13
13
  get(key: K): V | undefined;
14
14
  set(key: K, value: V): void;
15
15
  }
16
- /**
17
- * TBD
18
- */
19
- export declare function fail(message: string): never;
20
16
  /**
21
17
  * Map one iterable to another by transforming each element one at a time
22
18
  * @param iterable - the iterable to transform
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAChE,OAAO,KAAK,EACX,iBAAiB,EACjB,QAAQ,EACR,cAAc,EAEd,MAAM,4BAA4B,CAAC;AASpC;;;;GAIG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,EAAE,CAAC;IAC9B,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;IAC3B,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAE3C;AAED;;;;;;;GAOG;AACH,wBAAiB,WAAW,CAAC,CAAC,EAAE,CAAC,EAChC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,EACrB,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GACd,gBAAgB,CAAC,CAAC,CAAC,CAIrB;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,CAAC,EAC/B,GAAG,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EACpB,GAAG,EAAE,CAAC,EACN,YAAY,EAAE,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GACzB,CAAC,CAOH;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,CAMrE;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC,CAAC,EAAE,CA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AACH,wBAAgB,WAAW,CAC1B,MAAM,EAAE,mBAAmB,EAC3B,MAAM,GAAE,CAAC,MAAM,EAAE,cAAc,KAAK,OAAoB,EACxD,OAAO,sBAA4B,GACjC,GAAG,CAAC,cAAc,CAAC,CAUrB;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE7C;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CASpD"}
package/lib/utils.js CHANGED
@@ -2,17 +2,11 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { assert } from "@fluidframework/core-utils/internal";
5
+ import { assert, fail } from "@fluidframework/core-utils/internal";
6
6
  import { isFluidHandle } from "@fluidframework/runtime-utils";
7
7
  import { UsageError } from "@fluidframework/telemetry-utils/internal";
8
8
  import { ArrayNodeSchema, MapNodeSchema, RecordNodeSchema, TreeAlpha, } from "@fluidframework/tree/alpha";
9
9
  import { NodeKind, normalizeFieldSchema } from "@fluidframework/tree/internal";
10
- /**
11
- * TBD
12
- */
13
- export function fail(message) {
14
- throw new Error(message);
15
- }
16
10
  /**
17
11
  * Map one iterable to another by transforming each element one at a time
18
12
  * @param iterable - the iterable to transform
@@ -113,7 +107,7 @@ export function getFriendlyName(schema) {
113
107
  ? `Record<string, (${childNames.join(" | ")})>`
114
108
  : `Record<string, ${childNames[0]}>`;
115
109
  }
116
- fail("Unexpected node schema");
110
+ fail(0xcb7 /* Unexpected node schema */);
117
111
  }
118
112
  /**
119
113
  * Returns true if the schema identifier represents a named schema (object, named array, named map, or named record).
package/lib/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MA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OAAO,aAAa,CAAC;AACtB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW,CAC1B,MAA2B,EAC3B,SAA8C,GAAG,EAAE,CAAC,IAAI,EACxD,UAAU,IAAI,GAAG,EAAkB;IAEnC,KAAK,MAAM,UAAU,IAAI,oBAAoB,CAAC,MAAM,CAAC,CAAC,cAAc,EAAE,CAAC;QACtE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9B,IAAI,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC;gBACxB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YACzB,CAAC;YACD,WAAW,CAAC,CAAC,GAAG,UAAU,CAAC,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;QAC1D,CAAC;IACF,CAAC;IACD,OAAO,OAAO,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW;IACpC,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC3C,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC,OAAO,CAAC;IACtB,CAAC;IACD,IAAI,CAAC;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport type { ImplicitFieldSchema } from \"@fluidframework/tree\";\nimport type {\n\tInsertableContent,\n\tTreeNode,\n\tTreeNodeSchema,\n\tUnsafeUnknownSchema,\n} from \"@fluidframework/tree/alpha\";\nimport {\n\tArrayNodeSchema,\n\tMapNodeSchema,\n\tRecordNodeSchema,\n\tTreeAlpha,\n} from \"@fluidframework/tree/alpha\";\nimport { NodeKind, normalizeFieldSchema } from \"@fluidframework/tree/internal\";\n\n/**\n * Subset of Map interface.\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport interface MapGetSet<K, V> {\n\tget(key: K): V | undefined;\n\tset(key: K, value: V): void;\n}\n\n/**\n * TBD\n */\nexport function fail(message: string): never {\n\tthrow new Error(message);\n}\n\n/**\n * Map one iterable to another by transforming each element one at a time\n * @param iterable - the iterable to transform\n * @param map - the transformation function to run on each element of the iterable\n * @returns a new iterable of elements which have been transformed by the `map` function\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport function* mapIterable<T, U>(\n\titerable: Iterable<T>,\n\tmap: (t: T) => U,\n): IterableIterator<U> {\n\tfor (const t of iterable) {\n\t\tyield map(t);\n\t}\n}\n\n/**\n * Retrieve a value from a map with the given key, or create a new entry if the key is not in the map.\n * @param map - The map to query/update\n * @param key - The key to lookup in the map\n * @param defaultValue - a function which returns a default value. This is called and used to set an initial value for the given key in the map if none exists\n * @returns either the existing value for the given key, or the newly-created value (the result of `defaultValue`)\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport function getOrCreate<K, V>(\n\tmap: MapGetSet<K, V>,\n\tkey: K,\n\tdefaultValue: (key: K) => V,\n): V {\n\tlet value = map.get(key);\n\tif (value === undefined) {\n\t\tvalue = defaultValue(key);\n\t\tmap.set(key, value);\n\t}\n\treturn value;\n}\n\n/**\n * TODO\n */\nexport function tryGetSingleton<T>(set: ReadonlySet<T>): T | undefined {\n\tif (set.size === 1) {\n\t\tfor (const item of set) {\n\t\t\treturn item;\n\t\t}\n\t}\n}\n\n/**\n * Does it have at least two elements?\n */\nexport function hasAtLeastTwo<T>(array: T[]): array is [T, T, ...T[]] {\n\treturn array.length >= 2;\n}\n\n/**\n * Include this property in a field's schema metadata to indicate that the field's value should be generated via a provided function rather than by the LLM.\n * @example\n * ```ts\n * class Object extends schemaFactory.object(\"Object\", {\n * created: sf.required(sf.number, {\n * custom: {\n * // The LLM will ignore this field, and instead it will be populated with the result of the function\n * [llmDefault]: () => Date.now(),\n * },\n * }),\n * }) {};\n * ```\n * @alpha\n */\nexport const llmDefault = Symbol(\"tree-agent/llmDefault\");\n// TODO: make this a wrapper function instead, and hide the symbol.\n// function llmDefault<T extends FieldSchemaMetadata>(metadata: T): T { ... }\n\n/**\n * Usage fail\n */\nexport function failUsage(message: string): never {\n\tthrow new UsageError(message);\n}\n\n/**\n * Construct an object node from a schema and value.\n */\nexport function constructNode(schema: TreeNodeSchema, value: InsertableContent): TreeNode {\n\tconst node = TreeAlpha.create<UnsafeUnknownSchema>(schema, value);\n\tassert(\n\t\tnode !== undefined && node !== null && typeof node === \"object\" && !isFluidHandle(node),\n\t\t0xc1e /* Expected a constructed node to be an object */,\n\t);\n\treturn node;\n}\n\n/**\n * Returns the unqualified name of a tree value's schema (e.g. a node with schema identifier `\"my.scope.MyNode\"` returns `\"MyNode\"`).\n * @remarks If the schema is an inlined array, map, or record type, then it has no name and this function will return a string representation of the type (e.g., `\"MyNode[]\"` or `\"Map<string, MyNode>\"`).\n */\nexport function getFriendlyName(schema: TreeNodeSchema): string {\n\tif (schema.kind === NodeKind.Leaf || isNamedSchema(schema.identifier)) {\n\t\treturn unqualifySchema(schema.identifier);\n\t}\n\n\tconst childNames = Array.from(schema.childTypes, (t) => getFriendlyName(t));\n\tif (schema instanceof ArrayNodeSchema) {\n\t\treturn childNames.length > 1 ? `(${childNames.join(\" | \")})[]` : `${childNames[0]}[]`;\n\t}\n\tif (schema instanceof MapNodeSchema) {\n\t\treturn childNames.length > 1\n\t\t\t? `Map<string, (${childNames.join(\" | \")})>`\n\t\t\t: `Map<string, ${childNames[0]}>`;\n\t}\n\tif (schema instanceof RecordNodeSchema) {\n\t\treturn childNames.length > 1\n\t\t\t? `Record<string, (${childNames.join(\" | \")})>`\n\t\t\t: `Record<string, ${childNames[0]}>`;\n\t}\n\tfail(\"Unexpected node schema\");\n}\n\n/**\n * Returns true if the schema identifier represents a named schema (object, named array, named map, or named record).\n * @remarks This does not include primitive schemas or inlined array/map/record schemas.\n */\nexport function isNamedSchema(schemaIdentifier: string): boolean {\n\tif (\n\t\t[\"string\", \"number\", \"boolean\", \"null\", \"handle\"].includes(\n\t\t\tunqualifySchema(schemaIdentifier),\n\t\t)\n\t) {\n\t\treturn false;\n\t}\n\n\treturn /(?:Array|Map|Record)<\\[\"(.*)\"]>/.exec(schemaIdentifier) === null;\n}\n\n/**\n * Returns the unqualified, sanitized Typescript-safe name of a schema\n * Examples:\n * - `\"my.scope.MyNode\"` returns `\"MyNode\"`\n * - `\"my.scope.MyNode-2\"` returns `\"MyNode_2\"`\n * - `\"my.scope.MyNode!\"` returns `\"MyNode_\"`\n * @remarks\n * - Removes all characters before the last dot in the schema name.\n * - Sanitizes the remainder into a valid Typescript identifier\n * - If there is a dot in a user's schema name, this might produce unexpected results.\n */\nexport function unqualifySchema(schemaIdentifier: string): string {\n\t// Get the unqualified name by removing the scope (everything before the last dot).\n\tconst matches = /[^.]+$/.exec(schemaIdentifier);\n\tconst unqualifiedName = matches === null ? schemaIdentifier : matches[0];\n\n\tlet sanitizedName = unqualifiedName;\n\n\t// Replace invalid characters with \"_\".\n\tsanitizedName = sanitizedName.replace(/[^\\w$]/g, \"_\");\n\n\t// If the first character is a number, prefix it with \"_\".\n\tif (!/^[$A-Z_a-z]/.test(sanitizedName)) {\n\t\tsanitizedName = `_${sanitizedName}`;\n\t}\n\treturn sanitizedName;\n}\n\n/**\n * Adds all (optionally filtered) schemas reachable from the given schema to the given set.\n * @returns The set of schemas added (same as the `schemas` parameter, if supplied).\n */\nexport function findSchemas(\n\tschema: ImplicitFieldSchema,\n\tfilter: (schema: TreeNodeSchema) => boolean = () => true,\n\tschemas = new Set<TreeNodeSchema>(),\n): Set<TreeNodeSchema> {\n\tfor (const nodeSchema of normalizeFieldSchema(schema).allowedTypeSet) {\n\t\tif (!schemas.has(nodeSchema)) {\n\t\t\tif (filter(nodeSchema)) {\n\t\t\t\tschemas.add(nodeSchema);\n\t\t\t}\n\t\t\tfindSchemas([...nodeSchema.childTypes], filter, schemas);\n\t\t}\n\t}\n\treturn schemas;\n}\n\n/**\n * De-capitalize (the first letter of) a string.\n */\nexport function communize(str: string): string {\n\treturn str.charAt(0).toLowerCase() + str.slice(1);\n}\n\n/**\n * Stringify an unknown error value\n */\nexport function toErrorString(error: unknown): string {\n\tif (error instanceof Error) {\n\t\treturn error.message;\n\t}\n\ttry {\n\t\treturn JSON.stringify(error);\n\t} catch {\n\t\treturn String(error);\n\t}\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAQtE,OAAO,EACN,eAAe,EACf,aAAa,EACb,gBAAgB,EAChB,SAAS,GACT,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AAY/E;;;;;;;GAOG;AACH,MAAM,SAAS,CAAC,CAAC,WAAW,CAC3B,QAAqB,EACrB,GAAgB;IAEhB,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;QAC1B,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IACd,CAAC;AACF,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAC1B,GAAoB,EACpB,GAAM,EACN,YAA2B;IAE3B,IAAI,KA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AAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC3C,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC,OAAO,CAAC;IACtB,CAAC;IACD,IAAI,CAAC;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, fail } from \"@fluidframework/core-utils/internal\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport type { ImplicitFieldSchema } from \"@fluidframework/tree\";\nimport type {\n\tInsertableContent,\n\tTreeNode,\n\tTreeNodeSchema,\n\tUnsafeUnknownSchema,\n} from \"@fluidframework/tree/alpha\";\nimport {\n\tArrayNodeSchema,\n\tMapNodeSchema,\n\tRecordNodeSchema,\n\tTreeAlpha,\n} from \"@fluidframework/tree/alpha\";\nimport { NodeKind, normalizeFieldSchema } from \"@fluidframework/tree/internal\";\n\n/**\n * Subset of Map interface.\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport interface MapGetSet<K, V> {\n\tget(key: K): V | undefined;\n\tset(key: K, value: V): void;\n}\n\n/**\n * Map one iterable to another by transforming each element one at a time\n * @param iterable - the iterable to transform\n * @param map - the transformation function to run on each element of the iterable\n * @returns a new iterable of elements which have been transformed by the `map` function\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport function* mapIterable<T, U>(\n\titerable: Iterable<T>,\n\tmap: (t: T) => U,\n): IterableIterator<U> {\n\tfor (const t of iterable) {\n\t\tyield map(t);\n\t}\n}\n\n/**\n * Retrieve a value from a map with the given key, or create a new entry if the key is not in the map.\n * @param map - The map to query/update\n * @param key - The key to lookup in the map\n * @param defaultValue - a function which returns a default value. This is called and used to set an initial value for the given key in the map if none exists\n * @returns either the existing value for the given key, or the newly-created value (the result of `defaultValue`)\n *\n * @remarks originally from tree/src/util/utils.ts\n */\nexport function getOrCreate<K, V>(\n\tmap: MapGetSet<K, V>,\n\tkey: K,\n\tdefaultValue: (key: K) => V,\n): V {\n\tlet value = map.get(key);\n\tif (value === undefined) {\n\t\tvalue = defaultValue(key);\n\t\tmap.set(key, value);\n\t}\n\treturn value;\n}\n\n/**\n * TODO\n */\nexport function tryGetSingleton<T>(set: ReadonlySet<T>): T | undefined {\n\tif (set.size === 1) {\n\t\tfor (const item of set) {\n\t\t\treturn item;\n\t\t}\n\t}\n}\n\n/**\n * Does it have at least two elements?\n */\nexport function hasAtLeastTwo<T>(array: T[]): array is [T, T, ...T[]] {\n\treturn array.length >= 2;\n}\n\n/**\n * Include this property in a field's schema metadata to indicate that the field's value should be generated via a provided function rather than by the LLM.\n * @example\n * ```ts\n * class Object extends schemaFactory.object(\"Object\", {\n * created: sf.required(sf.number, {\n * custom: {\n * // The LLM will ignore this field, and instead it will be populated with the result of the function\n * [llmDefault]: () => Date.now(),\n * },\n * }),\n * }) {};\n * ```\n * @alpha\n */\nexport const llmDefault = Symbol(\"tree-agent/llmDefault\");\n// TODO: make this a wrapper function instead, and hide the symbol.\n// function llmDefault<T extends FieldSchemaMetadata>(metadata: T): T { ... }\n\n/**\n * Usage fail\n */\nexport function failUsage(message: string): never {\n\tthrow new UsageError(message);\n}\n\n/**\n * Construct an object node from a schema and value.\n */\nexport function constructNode(schema: TreeNodeSchema, value: InsertableContent): TreeNode {\n\tconst node = TreeAlpha.create<UnsafeUnknownSchema>(schema, value);\n\tassert(\n\t\tnode !== undefined && node !== null && typeof node === \"object\" && !isFluidHandle(node),\n\t\t0xc1e /* Expected a constructed node to be an object */,\n\t);\n\treturn node;\n}\n\n/**\n * Returns the unqualified name of a tree value's schema (e.g. a node with schema identifier `\"my.scope.MyNode\"` returns `\"MyNode\"`).\n * @remarks If the schema is an inlined array, map, or record type, then it has no name and this function will return a string representation of the type (e.g., `\"MyNode[]\"` or `\"Map<string, MyNode>\"`).\n */\nexport function getFriendlyName(schema: TreeNodeSchema): string {\n\tif (schema.kind === NodeKind.Leaf || isNamedSchema(schema.identifier)) {\n\t\treturn unqualifySchema(schema.identifier);\n\t}\n\n\tconst childNames = Array.from(schema.childTypes, (t) => getFriendlyName(t));\n\tif (schema instanceof ArrayNodeSchema) {\n\t\treturn childNames.length > 1 ? `(${childNames.join(\" | \")})[]` : `${childNames[0]}[]`;\n\t}\n\tif (schema instanceof MapNodeSchema) {\n\t\treturn childNames.length > 1\n\t\t\t? `Map<string, (${childNames.join(\" | \")})>`\n\t\t\t: `Map<string, ${childNames[0]}>`;\n\t}\n\tif (schema instanceof RecordNodeSchema) {\n\t\treturn childNames.length > 1\n\t\t\t? `Record<string, (${childNames.join(\" | \")})>`\n\t\t\t: `Record<string, ${childNames[0]}>`;\n\t}\n\tfail(0xcb7 /* Unexpected node schema */);\n}\n\n/**\n * Returns true if the schema identifier represents a named schema (object, named array, named map, or named record).\n * @remarks This does not include primitive schemas or inlined array/map/record schemas.\n */\nexport function isNamedSchema(schemaIdentifier: string): boolean {\n\tif (\n\t\t[\"string\", \"number\", \"boolean\", \"null\", \"handle\"].includes(\n\t\t\tunqualifySchema(schemaIdentifier),\n\t\t)\n\t) {\n\t\treturn false;\n\t}\n\n\treturn /(?:Array|Map|Record)<\\[\"(.*)\"]>/.exec(schemaIdentifier) === null;\n}\n\n/**\n * Returns the unqualified, sanitized Typescript-safe name of a schema\n * Examples:\n * - `\"my.scope.MyNode\"` returns `\"MyNode\"`\n * - `\"my.scope.MyNode-2\"` returns `\"MyNode_2\"`\n * - `\"my.scope.MyNode!\"` returns `\"MyNode_\"`\n * @remarks\n * - Removes all characters before the last dot in the schema name.\n * - Sanitizes the remainder into a valid Typescript identifier\n * - If there is a dot in a user's schema name, this might produce unexpected results.\n */\nexport function unqualifySchema(schemaIdentifier: string): string {\n\t// Get the unqualified name by removing the scope (everything before the last dot).\n\tconst matches = /[^.]+$/.exec(schemaIdentifier);\n\tconst unqualifiedName = matches === null ? schemaIdentifier : matches[0];\n\n\tlet sanitizedName = unqualifiedName;\n\n\t// Replace invalid characters with \"_\".\n\tsanitizedName = sanitizedName.replace(/[^\\w$]/g, \"_\");\n\n\t// If the first character is a number, prefix it with \"_\".\n\tif (!/^[$A-Z_a-z]/.test(sanitizedName)) {\n\t\tsanitizedName = `_${sanitizedName}`;\n\t}\n\treturn sanitizedName;\n}\n\n/**\n * Adds all (optionally filtered) schemas reachable from the given schema to the given set.\n * @returns The set of schemas added (same as the `schemas` parameter, if supplied).\n */\nexport function findSchemas(\n\tschema: ImplicitFieldSchema,\n\tfilter: (schema: TreeNodeSchema) => boolean = () => true,\n\tschemas = new Set<TreeNodeSchema>(),\n): Set<TreeNodeSchema> {\n\tfor (const nodeSchema of normalizeFieldSchema(schema).allowedTypeSet) {\n\t\tif (!schemas.has(nodeSchema)) {\n\t\t\tif (filter(nodeSchema)) {\n\t\t\t\tschemas.add(nodeSchema);\n\t\t\t}\n\t\t\tfindSchemas([...nodeSchema.childTypes], filter, schemas);\n\t\t}\n\t}\n\treturn schemas;\n}\n\n/**\n * De-capitalize (the first letter of) a string.\n */\nexport function communize(str: string): string {\n\treturn str.charAt(0).toLowerCase() + str.slice(1);\n}\n\n/**\n * Stringify an unknown error value\n */\nexport function toErrorString(error: unknown): string {\n\tif (error instanceof Error) {\n\t\treturn error.message;\n\t}\n\ttry {\n\t\treturn JSON.stringify(error);\n\t} catch {\n\t\treturn String(error);\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/tree-agent",
3
- "version": "2.80.0",
3
+ "version": "2.81.0",
4
4
  "description": "Experimental package to simplify integrating AI into Fluid-based applications",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -70,24 +70,24 @@
70
70
  },
71
71
  "dependencies": {
72
72
  "@anthropic-ai/sdk": "^0.39.0",
73
- "@fluidframework/core-utils": "~2.80.0",
74
- "@fluidframework/runtime-utils": "~2.80.0",
75
- "@fluidframework/telemetry-utils": "~2.80.0",
76
- "@fluidframework/tree": "~2.80.0",
73
+ "@fluidframework/core-utils": "~2.81.0",
74
+ "@fluidframework/runtime-utils": "~2.81.0",
75
+ "@fluidframework/telemetry-utils": "~2.81.0",
76
+ "@fluidframework/tree": "~2.81.0",
77
77
  "uuid": "^11.1.0",
78
78
  "zod": "^3.25.32"
79
79
  },
80
80
  "devDependencies": {
81
81
  "@arethetypeswrong/cli": "^0.18.2",
82
82
  "@biomejs/biome": "~1.9.3",
83
- "@fluid-internal/mocha-test-setup": "~2.80.0",
84
- "@fluid-tools/build-cli": "^0.62.0",
83
+ "@fluid-internal/mocha-test-setup": "~2.81.0",
84
+ "@fluid-tools/build-cli": "^0.63.0",
85
85
  "@fluidframework/build-common": "^2.0.3",
86
- "@fluidframework/build-tools": "^0.62.0",
87
- "@fluidframework/eslint-config-fluid": "~2.80.0",
88
- "@fluidframework/id-compressor": "~2.80.0",
89
- "@fluidframework/runtime-utils": "~2.80.0",
90
- "@fluidframework/test-runtime-utils": "~2.80.0",
86
+ "@fluidframework/build-tools": "^0.63.0",
87
+ "@fluidframework/eslint-config-fluid": "~2.81.0",
88
+ "@fluidframework/id-compressor": "~2.81.0",
89
+ "@fluidframework/runtime-utils": "~2.81.0",
90
+ "@fluidframework/test-runtime-utils": "~2.81.0",
91
91
  "@langchain/anthropic": "^0.3.24",
92
92
  "@langchain/core": "^0.3.78",
93
93
  "@langchain/google-genai": "^0.2.16",
package/src/index.ts CHANGED
@@ -37,6 +37,9 @@ export {
37
37
  type BindableSchema,
38
38
  type Ctor,
39
39
  type Infer,
40
+ type InferZod,
41
+ type InferArgsZod,
42
+ type InferTypeFactory,
40
43
  type IExposedMethods,
41
44
  } from "./methodBinding.js";
42
45
  export type {
@@ -50,3 +53,36 @@ export type {
50
53
  TypeMatchOrError,
51
54
  IfEquals,
52
55
  } from "./propertyBinding.js";
56
+
57
+ export {
58
+ typeFactory,
59
+ isTypeFactoryType,
60
+ instanceOfsTypeFactory,
61
+ } from "./treeAgentTypes.js";
62
+
63
+ export type {
64
+ TypeFactoryType,
65
+ TypeFactoryTypeKind,
66
+ TypeFactoryString,
67
+ TypeFactoryNumber,
68
+ TypeFactoryBoolean,
69
+ TypeFactoryDate,
70
+ TypeFactoryVoid,
71
+ TypeFactoryUndefined,
72
+ TypeFactoryNull,
73
+ TypeFactoryUnknown,
74
+ TypeFactoryArray,
75
+ TypeFactoryPromise,
76
+ TypeFactoryObject,
77
+ TypeFactoryRecord,
78
+ TypeFactoryMap,
79
+ TypeFactoryTuple,
80
+ TypeFactoryUnion,
81
+ TypeFactoryIntersection,
82
+ TypeFactoryLiteral,
83
+ TypeFactoryOptional,
84
+ TypeFactoryReadonly,
85
+ TypeFactoryFunction,
86
+ TypeFactoryFunctionParameter,
87
+ TypeFactoryInstanceOf,
88
+ } from "./treeAgentTypes.js";
@@ -9,6 +9,7 @@ import { NodeKind } from "@fluidframework/tree";
9
9
  import type { z } from "zod";
10
10
 
11
11
  import { instanceOf } from "./renderZodTypeScript.js";
12
+ import type { TypeFactoryType } from "./treeAgentTypes.js";
12
13
 
13
14
  /**
14
15
  * A utility type that extracts the method keys from a given type.
@@ -62,7 +63,8 @@ export function getExposedMethods(schemaClass: BindableSchema): {
62
63
  * A type that represents a function argument.
63
64
  * @alpha
64
65
  */
65
- export type Arg<T extends z.ZodTypeAny = z.ZodTypeAny> = readonly [name: string, type: T];
66
+ export type Arg<T extends z.ZodTypeAny | TypeFactoryType = z.ZodTypeAny | TypeFactoryType> =
67
+ readonly [name: string, type: T];
66
68
 
67
69
  /**
68
70
  * A function definition interface that describes the structure of a function.
@@ -70,12 +72,24 @@ export type Arg<T extends z.ZodTypeAny = z.ZodTypeAny> = readonly [name: string,
70
72
  */
71
73
  export interface FunctionDef<
72
74
  Args extends readonly Arg[],
73
- Return extends z.ZodTypeAny,
74
- Rest extends z.ZodTypeAny | null = null,
75
+ Return extends z.ZodTypeAny | TypeFactoryType,
76
+ Rest extends z.ZodTypeAny | TypeFactoryType | null = null,
75
77
  > {
78
+ /**
79
+ * Optional description of the function.
80
+ */
76
81
  description?: string;
82
+ /**
83
+ * The function's parameters.
84
+ */
77
85
  args: Args;
86
+ /**
87
+ * Optional rest parameter type.
88
+ */
78
89
  rest?: Rest;
90
+ /**
91
+ * The function's return type.
92
+ */
79
93
  returns: Return;
80
94
  }
81
95
 
@@ -83,15 +97,20 @@ export interface FunctionDef<
83
97
  * A class that implements the FunctionDef interface.
84
98
  */
85
99
  export class FunctionWrapper
86
- implements FunctionDef<readonly Arg[], z.ZodTypeAny, z.ZodTypeAny | null>
100
+ implements
101
+ FunctionDef<
102
+ readonly Arg[],
103
+ z.ZodTypeAny | TypeFactoryType,
104
+ z.ZodTypeAny | TypeFactoryType | null
105
+ >
87
106
  {
88
107
  public constructor(
89
108
  public readonly name: string,
90
109
  public readonly description: string | undefined,
91
110
  public readonly args: readonly Arg[],
92
111
  // eslint-disable-next-line @rushstack/no-new-null
93
- public readonly rest: z.ZodTypeAny | null,
94
- public readonly returns: z.ZodTypeAny,
112
+ public readonly rest: z.ZodTypeAny | TypeFactoryType | null,
113
+ public readonly returns: z.ZodTypeAny | TypeFactoryType,
95
114
  ) {}
96
115
  }
97
116
 
@@ -110,9 +129,9 @@ export type ArgsTuple<T extends readonly Arg[]> = T extends readonly [infer Sing
110
129
  * @alpha
111
130
  */
112
131
  export function buildFunc<
113
- const Return extends z.ZodTypeAny,
132
+ const Return extends z.ZodTypeAny | TypeFactoryType,
114
133
  const Args extends readonly Arg[],
115
- const Rest extends z.ZodTypeAny | null = null,
134
+ const Rest extends z.ZodTypeAny | TypeFactoryType | null = null,
116
135
  >(
117
136
  def: { description?: string; returns: Return; rest?: Rest },
118
137
  ...args: Args
@@ -125,12 +144,48 @@ export function buildFunc<
125
144
  };
126
145
  }
127
146
 
147
+ /**
148
+ * A utility type that extracts inferred parameter types from Zod args.
149
+ * @alpha
150
+ */
151
+ export type InferArgsZod<Args extends readonly Arg<z.ZodTypeAny>[]> = Args extends readonly [
152
+ infer Head extends Arg<z.ZodTypeAny>,
153
+ ...infer Tail extends readonly Arg<z.ZodTypeAny>[],
154
+ ]
155
+ ? [z.infer<Head[1]>, ...InferArgsZod<Tail>]
156
+ : [];
157
+
158
+ /**
159
+ * A utility type that infers the function signature from a Zod function definition with strict type checking.
160
+ * @alpha
161
+ */
162
+ export type InferZod<T> = T extends FunctionDef<
163
+ infer Args extends readonly Arg<z.ZodTypeAny>[],
164
+ infer Return extends z.ZodTypeAny,
165
+ any
166
+ >
167
+ ? (...args: InferArgsZod<Args>) => z.infer<Return>
168
+ : never;
169
+
170
+ /**
171
+ * A utility type that infers the function signature from a type factory function definition with relaxed type checking.
172
+ * @alpha
173
+ */
174
+ export type InferTypeFactory<T> = T extends FunctionDef<readonly Arg[], infer Return, any>
175
+ ? (...args: any[]) => any
176
+ : never;
177
+
128
178
  /**
129
179
  * A utility type that infers the return type of a function definition.
130
180
  * @alpha
181
+ * @remarks
182
+ * For Zod types, provides strict compile-time type checking. For type factory types, returns `any`.
183
+ * @deprecated Use InferZod or InferTypeFactory directly for better type safety.
131
184
  */
132
- export type Infer<T> = T extends FunctionDef<infer Args, infer Return, infer Rest>
133
- ? z.infer<z.ZodFunction<z.ZodTuple<ArgsTuple<Args>, Rest>, Return>>
185
+ export type Infer<T> = T extends FunctionDef<readonly Arg[], infer Return, any>
186
+ ? Return extends z.ZodTypeAny
187
+ ? InferZod<T>
188
+ : InferTypeFactory<T>
134
189
  : never;
135
190
 
136
191
  /**
@@ -138,16 +193,32 @@ export type Infer<T> = T extends FunctionDef<infer Args, infer Return, infer Res
138
193
  * @alpha
139
194
  */
140
195
  export interface ExposedMethods {
196
+ /**
197
+ * Expose a method with Zod types (strict compile-time type checking).
198
+ */
141
199
  expose<
142
200
  const K extends string & keyof MethodKeys<InstanceType<S>>,
143
- S extends BindableSchema & Ctor<Record<K, Infer<Z>>> & IExposedMethods,
144
- Z extends FunctionDef<any, any, any>,
201
+ S extends BindableSchema & Ctor<Record<K, InferZod<Z>>> & IExposedMethods,
202
+ Z extends FunctionDef<readonly Arg<z.ZodTypeAny>[], z.ZodTypeAny, z.ZodTypeAny | null>,
145
203
  >(schema: S, methodName: K, zodFunction: Z): void;
146
204
 
205
+ /**
206
+ * Expose a method with type factory types (relaxed compile-time type checking).
207
+ */
208
+ expose<
209
+ const K extends string & keyof MethodKeys<InstanceType<S>>,
210
+ S extends BindableSchema & Ctor & IExposedMethods,
211
+ Z extends FunctionDef<
212
+ readonly Arg<TypeFactoryType>[],
213
+ TypeFactoryType,
214
+ TypeFactoryType | null
215
+ >,
216
+ >(schema: S, methodName: K, tfFunction: Z): void;
217
+
147
218
  /**
148
219
  * Create a Zod schema for a SharedTree schema class.
149
220
  * @remarks
150
- * Use it to "wrap" schema types that are referenced as arguments or return types when exposing methods (with {@link ExposedMethods.expose}).
221
+ * Use it to "wrap" schema types that are referenced as arguments or return types when exposing methods with {@link ExposedMethods}.
151
222
  */
152
223
  instanceOf<T extends TreeNodeSchemaClass>(
153
224
  schema: T,
@@ -175,6 +246,9 @@ export const exposeMethodsSymbol: unique symbol = Symbol("run");
175
246
  * @alpha
176
247
  */
177
248
  export interface IExposedMethods {
249
+ /**
250
+ * Static method that exposes methods of this schema class to an agent.
251
+ */
178
252
  [exposeMethodsSymbol](methods: ExposedMethods): void;
179
253
  }
180
254
 
@@ -186,8 +260,12 @@ class ExposedMethodsI implements ExposedMethods {
186
260
 
187
261
  public expose<
188
262
  const K extends string & keyof MethodKeys<InstanceType<S>>,
189
- S extends BindableSchema & Ctor<Record<K, Infer<Z>>> & IExposedMethods,
190
- Z extends FunctionDef<readonly Arg[], z.ZodTypeAny, z.ZodTypeAny | null>,
263
+ S extends BindableSchema & Ctor & IExposedMethods,
264
+ Z extends FunctionDef<
265
+ readonly Arg[],
266
+ z.ZodTypeAny | TypeFactoryType,
267
+ z.ZodTypeAny | TypeFactoryType | null
268
+ >,
191
269
  >(schema: S, methodName: K, functionDef: Z): void {
192
270
  if (schema !== this.schemaClass) {
193
271
  throw new Error('Must expose methods on the "this" object');