@fluidframework/tree-agent 2.74.0 → 2.81.0-374083

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/api-report/tree-agent.alpha.api.md +163 -20
  3. package/dist/alpha.d.ts +26 -1
  4. package/dist/index.d.ts +3 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +5 -1
  7. package/dist/index.js.map +1 -1
  8. package/dist/methodBinding.d.ts +54 -10
  9. package/dist/methodBinding.d.ts.map +1 -1
  10. package/dist/methodBinding.js.map +1 -1
  11. package/dist/propertyBinding.d.ts +52 -2
  12. package/dist/propertyBinding.d.ts.map +1 -1
  13. package/dist/propertyBinding.js +28 -3
  14. package/dist/propertyBinding.js.map +1 -1
  15. package/dist/renderSchemaTypeScript.d.ts.map +1 -1
  16. package/dist/renderSchemaTypeScript.js +17 -8
  17. package/dist/renderSchemaTypeScript.js.map +1 -1
  18. package/dist/renderTypeFactoryTypeScript.d.ts +13 -0
  19. package/dist/renderTypeFactoryTypeScript.d.ts.map +1 -0
  20. package/dist/renderTypeFactoryTypeScript.js +222 -0
  21. package/dist/renderTypeFactoryTypeScript.js.map +1 -0
  22. package/dist/subtree.d.ts.map +1 -1
  23. package/dist/subtree.js +4 -4
  24. package/dist/subtree.js.map +1 -1
  25. package/dist/treeAgentTypes.d.ts +345 -0
  26. package/dist/treeAgentTypes.d.ts.map +1 -0
  27. package/dist/treeAgentTypes.js +190 -0
  28. package/dist/treeAgentTypes.js.map +1 -0
  29. package/dist/utils.d.ts +0 -4
  30. package/dist/utils.d.ts.map +1 -1
  31. package/dist/utils.js +2 -9
  32. package/dist/utils.js.map +1 -1
  33. package/eslint.config.mts +4 -4
  34. package/lib/alpha.d.ts +26 -1
  35. package/lib/index.d.ts +3 -1
  36. package/lib/index.d.ts.map +1 -1
  37. package/lib/index.js +1 -0
  38. package/lib/index.js.map +1 -1
  39. package/lib/methodBinding.d.ts +54 -10
  40. package/lib/methodBinding.d.ts.map +1 -1
  41. package/lib/methodBinding.js.map +1 -1
  42. package/lib/propertyBinding.d.ts +52 -2
  43. package/lib/propertyBinding.d.ts.map +1 -1
  44. package/lib/propertyBinding.js +28 -3
  45. package/lib/propertyBinding.js.map +1 -1
  46. package/lib/renderSchemaTypeScript.d.ts.map +1 -1
  47. package/lib/renderSchemaTypeScript.js +17 -8
  48. package/lib/renderSchemaTypeScript.js.map +1 -1
  49. package/lib/renderTypeFactoryTypeScript.d.ts +13 -0
  50. package/lib/renderTypeFactoryTypeScript.d.ts.map +1 -0
  51. package/lib/renderTypeFactoryTypeScript.js +217 -0
  52. package/lib/renderTypeFactoryTypeScript.js.map +1 -0
  53. package/lib/subtree.d.ts.map +1 -1
  54. package/lib/subtree.js +4 -4
  55. package/lib/subtree.js.map +1 -1
  56. package/lib/treeAgentTypes.d.ts +345 -0
  57. package/lib/treeAgentTypes.d.ts.map +1 -0
  58. package/lib/treeAgentTypes.js +186 -0
  59. package/lib/treeAgentTypes.js.map +1 -0
  60. package/lib/utils.d.ts +0 -4
  61. package/lib/utils.d.ts.map +1 -1
  62. package/lib/utils.js +2 -8
  63. package/lib/utils.js.map +1 -1
  64. package/package.json +17 -17
  65. package/src/index.ts +31 -0
  66. package/src/methodBinding.ts +94 -15
  67. package/src/propertyBinding.ts +66 -9
  68. package/src/renderSchemaTypeScript.ts +25 -9
  69. package/src/renderTypeFactoryTypeScript.ts +259 -0
  70. package/src/subtree.ts +6 -5
  71. package/src/treeAgentTypes.ts +490 -0
  72. package/src/utils.ts +2 -9
  73. package/.eslintrc.cjs +0 -48
@@ -0,0 +1,490 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { UsageError } from "@fluidframework/telemetry-utils/internal";
7
+ import type { TreeNodeSchemaClass } from "@fluidframework/tree/alpha";
8
+ import { ObjectNodeSchema } from "@fluidframework/tree/alpha";
9
+
10
+ /**
11
+ * Type kinds for the type factory type system.
12
+ * @alpha
13
+ */
14
+ export type TypeFactoryTypeKind =
15
+ | "string"
16
+ | "number"
17
+ | "boolean"
18
+ | "void"
19
+ | "undefined"
20
+ | "null"
21
+ | "unknown"
22
+ | "array"
23
+ | "object"
24
+ | "record"
25
+ | "map"
26
+ | "tuple"
27
+ | "union"
28
+ | "literal"
29
+ | "optional"
30
+ | "readonly"
31
+ | "instanceof";
32
+
33
+ /**
34
+ * Base interface for type factory types.
35
+ * @alpha
36
+ */
37
+ export interface TypeFactoryType {
38
+ /**
39
+ * The kind of type this represents.
40
+ */
41
+ readonly _kind: TypeFactoryTypeKind;
42
+ }
43
+
44
+ /**
45
+ * Set of valid type factory type kinds for efficient validation.
46
+ * @internal
47
+ */
48
+ const validTypeKinds: ReadonlySet<TypeFactoryTypeKind> = new Set<TypeFactoryTypeKind>([
49
+ "string",
50
+ "number",
51
+ "boolean",
52
+ "void",
53
+ "undefined",
54
+ "null",
55
+ "unknown",
56
+ "array",
57
+ "object",
58
+ "record",
59
+ "map",
60
+ "tuple",
61
+ "union",
62
+ "literal",
63
+ "optional",
64
+ "readonly",
65
+ "instanceof",
66
+ ]);
67
+
68
+ /**
69
+ * Type guard to check if a value is a type factory type.
70
+ * @alpha
71
+ */
72
+ export function isTypeFactoryType(value: unknown): value is TypeFactoryType {
73
+ if (typeof value !== "object" || value === null || !("_kind" in value)) {
74
+ return false;
75
+ }
76
+ const kind = (value as { _kind: unknown })._kind;
77
+ return typeof kind === "string" && validTypeKinds.has(kind as TypeFactoryTypeKind);
78
+ }
79
+
80
+ // Primitive type factories
81
+
82
+ /**
83
+ * Represents a string type in the type factory system.
84
+ * @alpha
85
+ */
86
+ export interface TypeFactoryString extends TypeFactoryType {
87
+ /**
88
+ * {@inheritDoc TypeFactoryType._kind}
89
+ */
90
+ readonly _kind: "string";
91
+ }
92
+
93
+ /**
94
+ * Represents a number type in the type factory system.
95
+ * @alpha
96
+ */
97
+ export interface TypeFactoryNumber extends TypeFactoryType {
98
+ /**
99
+ * {@inheritDoc TypeFactoryType._kind}
100
+ */
101
+ readonly _kind: "number";
102
+ }
103
+
104
+ /**
105
+ * Represents a boolean type in the type factory system.
106
+ * @alpha
107
+ */
108
+ export interface TypeFactoryBoolean extends TypeFactoryType {
109
+ /**
110
+ * {@inheritDoc TypeFactoryType._kind}
111
+ */
112
+ readonly _kind: "boolean";
113
+ }
114
+
115
+ /**
116
+ * Represents a void type in the type factory system.
117
+ * @alpha
118
+ */
119
+ export interface TypeFactoryVoid extends TypeFactoryType {
120
+ /**
121
+ * {@inheritDoc TypeFactoryType._kind}
122
+ */
123
+ readonly _kind: "void";
124
+ }
125
+
126
+ /**
127
+ * Represents an undefined type in the type factory system.
128
+ * @alpha
129
+ */
130
+ export interface TypeFactoryUndefined extends TypeFactoryType {
131
+ /**
132
+ * {@inheritDoc TypeFactoryType._kind}
133
+ */
134
+ readonly _kind: "undefined";
135
+ }
136
+
137
+ /**
138
+ * Represents a null type in the type factory system.
139
+ * @alpha
140
+ */
141
+ export interface TypeFactoryNull extends TypeFactoryType {
142
+ /**
143
+ * {@inheritDoc TypeFactoryType._kind}
144
+ */
145
+ readonly _kind: "null";
146
+ }
147
+
148
+ /**
149
+ * Represents an unknown type in the type factory system.
150
+ * @alpha
151
+ */
152
+ export interface TypeFactoryUnknown extends TypeFactoryType {
153
+ /**
154
+ * {@inheritDoc TypeFactoryType._kind}
155
+ */
156
+ readonly _kind: "unknown";
157
+ }
158
+
159
+ // Complex type interfaces
160
+
161
+ /**
162
+ * Represents an array type in the type factory system.
163
+ * @alpha
164
+ */
165
+ export interface TypeFactoryArray extends TypeFactoryType {
166
+ /**
167
+ * {@inheritDoc TypeFactoryType._kind}
168
+ */
169
+ readonly _kind: "array";
170
+ /**
171
+ * The type of elements in the array.
172
+ */
173
+ readonly element: TypeFactoryType;
174
+ }
175
+
176
+ /**
177
+ * Represents an object type with a fixed shape in the type factory system.
178
+ * @alpha
179
+ */
180
+ export interface TypeFactoryObject extends TypeFactoryType {
181
+ /**
182
+ * {@inheritDoc TypeFactoryType._kind}
183
+ */
184
+ readonly _kind: "object";
185
+ /**
186
+ * The shape of the object, mapping property names to their types.
187
+ */
188
+ readonly shape: Record<string, TypeFactoryType>;
189
+ }
190
+
191
+ /**
192
+ * Represents a record type (index signature) in the type factory system.
193
+ * @alpha
194
+ */
195
+ export interface TypeFactoryRecord extends TypeFactoryType {
196
+ /**
197
+ * {@inheritDoc TypeFactoryType._kind}
198
+ */
199
+ readonly _kind: "record";
200
+ /**
201
+ * The type of the record's keys.
202
+ */
203
+ readonly keyType: TypeFactoryType;
204
+ /**
205
+ * The type of the record's values.
206
+ */
207
+ readonly valueType: TypeFactoryType;
208
+ }
209
+
210
+ /**
211
+ * Represents a Map type in the type factory system.
212
+ * @alpha
213
+ */
214
+ export interface TypeFactoryMap extends TypeFactoryType {
215
+ /**
216
+ * {@inheritDoc TypeFactoryType._kind}
217
+ */
218
+ readonly _kind: "map";
219
+ /**
220
+ * The type of the map's keys.
221
+ */
222
+ readonly keyType: TypeFactoryType;
223
+ /**
224
+ * The type of the map's values.
225
+ */
226
+ readonly valueType: TypeFactoryType;
227
+ }
228
+
229
+ /**
230
+ * Represents a tuple type with fixed-length items and optional rest elements in the type factory system.
231
+ * @alpha
232
+ */
233
+ export interface TypeFactoryTuple extends TypeFactoryType {
234
+ /**
235
+ * {@inheritDoc TypeFactoryType._kind}
236
+ */
237
+ readonly _kind: "tuple";
238
+ /**
239
+ * The fixed-length items in the tuple.
240
+ */
241
+ readonly items: readonly TypeFactoryType[];
242
+ /**
243
+ * Optional rest element type for variable-length tuples.
244
+ */
245
+ readonly rest?: TypeFactoryType;
246
+ }
247
+
248
+ /**
249
+ * Represents a union type in the type factory system.
250
+ * @alpha
251
+ */
252
+ export interface TypeFactoryUnion extends TypeFactoryType {
253
+ /**
254
+ * {@inheritDoc TypeFactoryType._kind}
255
+ */
256
+ readonly _kind: "union";
257
+ /**
258
+ * The possible types in the union.
259
+ */
260
+ readonly options: readonly TypeFactoryType[];
261
+ }
262
+
263
+ /**
264
+ * Represents a literal type (specific string, number, or boolean value) in the type factory system.
265
+ * @alpha
266
+ */
267
+ export interface TypeFactoryLiteral extends TypeFactoryType {
268
+ /**
269
+ * {@inheritDoc TypeFactoryType._kind}
270
+ */
271
+ readonly _kind: "literal";
272
+ /**
273
+ * The specific literal value.
274
+ */
275
+ readonly value: string | number | boolean;
276
+ }
277
+
278
+ /**
279
+ * Represents an optional type modifier in the type factory system.
280
+ * @alpha
281
+ */
282
+ export interface TypeFactoryOptional extends TypeFactoryType {
283
+ /**
284
+ * {@inheritDoc TypeFactoryType._kind}
285
+ */
286
+ readonly _kind: "optional";
287
+ /**
288
+ * The inner type that is optional.
289
+ */
290
+ readonly innerType: TypeFactoryType;
291
+ }
292
+
293
+ /**
294
+ * Represents a readonly type modifier in the type factory system.
295
+ * @alpha
296
+ */
297
+ export interface TypeFactoryReadonly extends TypeFactoryType {
298
+ /**
299
+ * {@inheritDoc TypeFactoryType._kind}
300
+ */
301
+ readonly _kind: "readonly";
302
+ /**
303
+ * The inner type that is readonly.
304
+ */
305
+ readonly innerType: TypeFactoryType;
306
+ }
307
+
308
+ /**
309
+ * Represents an instanceof type that references a SharedTree schema class in the type factory system.
310
+ * @alpha
311
+ */
312
+ export interface TypeFactoryInstanceOf extends TypeFactoryType {
313
+ /**
314
+ * {@inheritDoc TypeFactoryType._kind}
315
+ */
316
+ readonly _kind: "instanceof";
317
+ /**
318
+ * The SharedTree schema class to reference.
319
+ */
320
+ readonly schema: ObjectNodeSchema;
321
+ }
322
+
323
+ /**
324
+ * Namespace containing type factory functions.
325
+ * @alpha
326
+ */
327
+ export const typeFactory = {
328
+ /**
329
+ * Create a string type.
330
+ * @alpha
331
+ */
332
+ string(): TypeFactoryString {
333
+ return { _kind: "string" };
334
+ },
335
+
336
+ /**
337
+ * Create a number type.
338
+ * @alpha
339
+ */
340
+ number(): TypeFactoryNumber {
341
+ return { _kind: "number" };
342
+ },
343
+
344
+ /**
345
+ * Create a boolean type.
346
+ * @alpha
347
+ */
348
+ boolean(): TypeFactoryBoolean {
349
+ return { _kind: "boolean" };
350
+ },
351
+
352
+ /**
353
+ * Create a void type.
354
+ * @alpha
355
+ */
356
+ void(): TypeFactoryVoid {
357
+ return { _kind: "void" };
358
+ },
359
+
360
+ /**
361
+ * Create an undefined type.
362
+ * @alpha
363
+ */
364
+ undefined(): TypeFactoryUndefined {
365
+ return { _kind: "undefined" };
366
+ },
367
+
368
+ /**
369
+ * Create a null type.
370
+ * @alpha
371
+ */
372
+ null(): TypeFactoryNull {
373
+ return { _kind: "null" };
374
+ },
375
+
376
+ /**
377
+ * Create an unknown type.
378
+ * @alpha
379
+ */
380
+ unknown(): TypeFactoryUnknown {
381
+ return { _kind: "unknown" };
382
+ },
383
+
384
+ /**
385
+ * Create an array type.
386
+ * @alpha
387
+ */
388
+ array(element: TypeFactoryType): TypeFactoryArray {
389
+ return { _kind: "array", element };
390
+ },
391
+
392
+ /**
393
+ * Create an object type.
394
+ * @alpha
395
+ */
396
+ object(shape: Record<string, TypeFactoryType>): TypeFactoryObject {
397
+ return { _kind: "object", shape };
398
+ },
399
+
400
+ /**
401
+ * Create a record type.
402
+ * @alpha
403
+ */
404
+ record(keyType: TypeFactoryType, valueType: TypeFactoryType): TypeFactoryRecord {
405
+ return { _kind: "record", keyType, valueType };
406
+ },
407
+
408
+ /**
409
+ * Create a map type.
410
+ * @alpha
411
+ */
412
+ map(keyType: TypeFactoryType, valueType: TypeFactoryType): TypeFactoryMap {
413
+ return { _kind: "map", keyType, valueType };
414
+ },
415
+
416
+ /**
417
+ * Create a tuple type.
418
+ * @alpha
419
+ */
420
+ tuple(items: readonly TypeFactoryType[], rest?: TypeFactoryType): TypeFactoryTuple {
421
+ if (items.length === 0 && rest === undefined) {
422
+ throw new UsageError(
423
+ "typeFactory.tuple requires at least one item or a rest type. Empty tuples are not supported.",
424
+ );
425
+ }
426
+ return rest === undefined ? { _kind: "tuple", items } : { _kind: "tuple", items, rest };
427
+ },
428
+
429
+ /**
430
+ * Create a union type.
431
+ * @alpha
432
+ */
433
+ union(options: readonly TypeFactoryType[]): TypeFactoryUnion {
434
+ if (options.length === 0) {
435
+ throw new UsageError(
436
+ "typeFactory.union requires at least one option. Empty unions are not valid TypeScript types.",
437
+ );
438
+ }
439
+ return { _kind: "union", options };
440
+ },
441
+
442
+ /**
443
+ * Create a literal type.
444
+ * @alpha
445
+ */
446
+ literal(value: string | number | boolean): TypeFactoryLiteral {
447
+ return { _kind: "literal", value };
448
+ },
449
+
450
+ /**
451
+ * Create an optional type.
452
+ * @alpha
453
+ */
454
+ optional(innerType: TypeFactoryType): TypeFactoryOptional {
455
+ return { _kind: "optional", innerType };
456
+ },
457
+
458
+ /**
459
+ * Create a readonly type.
460
+ * @alpha
461
+ */
462
+ readonly(innerType: TypeFactoryType): TypeFactoryReadonly {
463
+ return { _kind: "readonly", innerType };
464
+ },
465
+
466
+ /**
467
+ * Create an instanceOf type for a SharedTree schema class.
468
+ * @alpha
469
+ */
470
+ instanceOf<T extends TreeNodeSchemaClass>(schema: T): TypeFactoryInstanceOf {
471
+ if (!(schema instanceof ObjectNodeSchema)) {
472
+ throw new UsageError(
473
+ `typeFactory.instanceOf only supports ObjectNodeSchema-based schema classes (created via SchemaFactory.object). ` +
474
+ `Pass a schema class that extends from an object schema (e.g., sf.object(...)), not primitive, array, or map schemas.`,
475
+ );
476
+ }
477
+ const instanceOfType: TypeFactoryInstanceOf = {
478
+ _kind: "instanceof",
479
+ schema,
480
+ };
481
+ instanceOfsTypeFactory.set(instanceOfType, schema);
482
+ return instanceOfType;
483
+ },
484
+ };
485
+
486
+ /**
487
+ * A lookup from type factory instanceOf types to their corresponding ObjectNodeSchema.
488
+ * @alpha
489
+ */
490
+ export const instanceOfsTypeFactory = new WeakMap<TypeFactoryInstanceOf, ObjectNodeSchema>();
package/src/utils.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { assert } from "@fluidframework/core-utils/internal";
6
+ import { assert, fail } from "@fluidframework/core-utils/internal";
7
7
  import { isFluidHandle } from "@fluidframework/runtime-utils";
8
8
  import { UsageError } from "@fluidframework/telemetry-utils/internal";
9
9
  import type { ImplicitFieldSchema } from "@fluidframework/tree";
@@ -31,13 +31,6 @@ export interface MapGetSet<K, V> {
31
31
  set(key: K, value: V): void;
32
32
  }
33
33
 
34
- /**
35
- * TBD
36
- */
37
- export function fail(message: string): never {
38
- throw new Error(message);
39
- }
40
-
41
34
  /**
42
35
  * Map one iterable to another by transforming each element one at a time
43
36
  * @param iterable - the iterable to transform
@@ -156,7 +149,7 @@ export function getFriendlyName(schema: TreeNodeSchema): string {
156
149
  ? `Record<string, (${childNames.join(" | ")})>`
157
150
  : `Record<string, ${childNames[0]}>`;
158
151
  }
159
- fail("Unexpected node schema");
152
+ fail(0xcb7 /* Unexpected node schema */);
160
153
  }
161
154
 
162
155
  /**
package/.eslintrc.cjs DELETED
@@ -1,48 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
-
6
- module.exports = {
7
- extends: [require.resolve("@fluidframework/eslint-config-fluid/strict"), "prettier"],
8
- parserOptions: {
9
- project: ["./tsconfig.json"],
10
- },
11
- rules: {
12
- // Allow reaching into FluidFramework package paths that end with alpha, beta, legacy, or internal
13
- "import-x/no-internal-modules": [
14
- "error",
15
- {
16
- allow: [
17
- "@fluidframework/*/alpha",
18
- "@fluidframework/*/beta",
19
- "@fluidframework/*/legacy",
20
- "@fluidframework/*/internal",
21
- ],
22
- },
23
- ],
24
- },
25
- overrides: [
26
- {
27
- files: ["src/test/**/*"],
28
- parserOptions: {
29
- project: ["./src/test/tsconfig.json"],
30
- },
31
- rules: {
32
- // Test files can import from submodules for testing purposes
33
- "import-x/no-internal-modules": [
34
- "error",
35
- {
36
- allow: [
37
- "*/index.js",
38
- "@fluidframework/*/alpha",
39
- "@fluidframework/*/beta",
40
- "@fluidframework/*/legacy",
41
- "@fluidframework/*/internal",
42
- ],
43
- },
44
- ],
45
- },
46
- },
47
- ],
48
- };