fluid-framework 2.31.0 → 2.32.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  # fluid-framework
2
2
 
3
+ ## 2.32.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Cleanup of several tree and schema alpha APIs for content import and export ([#24350](https://github.com/microsoft/FluidFramework/pull/24350)) [fe924a173b](https://github.com/microsoft/FluidFramework/commit/fe924a173b71abd96ba76da787eec3b4c077d32b)
8
+
9
+ A new `TreeSchema` type has been introduced which extends `SimpleTreeSchema` but contains `TreeNodeSchema` instead of `SimpleNodeSchema`.
10
+
11
+ `TreeViewConfigurationAlpha` is added which is just `TreeViewConfiguration` but implementing `TreeSchema`.
12
+
13
+ `SimpleTreeSchema` was modified to have a `root` property instead of implementing `SimpleFieldSchema` directly:
14
+ this makes it possible for `TreeViewConfigurationAlpha` to implement `TreeSchema` which extends `SimpleTreeSchema`.
15
+
16
+ `generateSchemaFromSimpleSchema` now returns the new `TreeSchema` type.
17
+
18
+ `EncodeOptions` and `ParseOptions` have been unified as `TreeEncodingOptions` which covers both the encoding and parsing cases.
19
+
20
+ `getJsonSchema` now takes in `ImplicitAllowedTypes` instead of `ImplicitFieldSchema` since it can't handle optional roots.
21
+ `getJsonSchema` also takes in the new `TreeSchemaEncodingOptions` to provide options for how to handle stored keys vs property keys, and fields with defaults.
22
+
23
+ Now that `getJsonSchema` takes in configuration options, its results are no longer cached.
24
+
25
+ - Provide alpha APIs for accessing tree content and stored schema without requiring a compatible view schema ([#24350](https://github.com/microsoft/FluidFramework/pull/24350)) [fe924a173b](https://github.com/microsoft/FluidFramework/commit/fe924a173b71abd96ba76da787eec3b4c077d32b)
26
+
27
+ Adds an `ITreeAlpha` interface (which `ITree` can be down-casted to) that provides access to both the tree content and the schema.
28
+ This allows inspecting the content saved in a SharedTree in a generic way that can work on any SharedTree.
29
+
30
+ This can be combined with the existing `generateSchemaFromSimpleSchema` to generate a schema that can be used with [`IIree.viewWith`](https://fluidframework.com/docs/api/fluid-framework/viewabletree-interface#viewwith-methodsignature) to allow constructing a [`TreeView`](https://fluidframework.com/docs/api/fluid-framework/treeview-interface) for any SharedTree, regardless of its schema.
31
+
32
+ Note that the resulting TypeScript typing for such a view will not be friendly: the `TreeView` APIs are designed for statically known schema. Using them is possible with care and a lot of type casts but not recommended if it can be avoided: see disclaimer on `generateSchemaFromSimpleSchema`.
33
+ Example using `ITreeAlpha` and `generateSchemaFromSimpleSchema`:
34
+
35
+ ```typescript
36
+ const viewAlpha = tree as ITreeAlpha;
37
+ const treeSchema = generateSchemaFromSimpleSchema(
38
+ viewAlpha.exportSimpleSchema(),
39
+ );
40
+ const config = new TreeViewConfiguration({ schema: treeSchema.root });
41
+ const view = viewAlpha.viewWith(config);
42
+ ```
43
+
44
+ `getSimpleSchema` is also added as an `@alpha` API to provide a way to clone schema into the simple schema formats.
45
+ Note that when using (or copying) a view schema as a simple schema, more metadata will be preserved than when deriving one from the stored schema using `ITreeAlpha`.
46
+
3
47
  ## 2.31.0
4
48
 
5
49
  ### Minor Changes
@@ -2,5 +2,9 @@
2
2
  "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
3
  "extends": "<projectFolder>/../../../common/build/build-common/api-extractor-report.esm.current.json",
4
4
  "mainEntryPointFilePath": "<projectFolder>/lib/alpha.d.ts",
5
- "bundledPackages": ["@fluidframework/*"]
5
+ "bundledPackages": ["@fluidframework/*"],
6
+ "apiReport": {
7
+ // The base config omits alpha. Explicitly opt into alpha reports (in addition to public/beta) for this package.
8
+ "reportVariants": ["public", "beta", "alpha"]
9
+ }
6
10
  }
@@ -150,11 +150,6 @@ export function createSimpleTreeIndex<TFieldSchema extends ImplicitFieldSchema,
150
150
  interface DefaultProvider extends ErasedType<"@fluidframework/tree.FieldProvider"> {
151
151
  }
152
152
 
153
- // @alpha
154
- export interface EncodeOptions {
155
- readonly useStoredKeys?: boolean;
156
- }
157
-
158
153
  // @alpha
159
154
  export function enumFromStrings<TScope extends string, const Members extends readonly string[]>(factory: SchemaFactory<TScope>, members: Members): (<TValue extends Members[number]>(value: TValue) => TValue extends unknown ? TreeNode & {
160
155
  readonly value: TValue;
@@ -298,7 +293,7 @@ export const ForestTypeOptimized: ForestType;
298
293
  export const ForestTypeReference: ForestType;
299
294
 
300
295
  // @alpha
301
- export function generateSchemaFromSimpleSchema(simple: SimpleTreeSchema): FieldSchemaAlpha;
296
+ export function generateSchemaFromSimpleSchema(simple: SimpleTreeSchema): TreeSchema;
302
297
 
303
298
  // @alpha @deprecated
304
299
  export function getBranch(tree: ITree): BranchableTree;
@@ -307,7 +302,10 @@ export function getBranch(tree: ITree): BranchableTree;
307
302
  export function getBranch<T extends ImplicitFieldSchema | UnsafeUnknownSchema>(view: TreeViewAlpha<T>): BranchableTree;
308
303
 
309
304
  // @alpha
310
- export function getJsonSchema(schema: ImplicitFieldSchema): JsonTreeSchema;
305
+ export function getJsonSchema(schema: ImplicitAllowedTypes, options: Required<TreeSchemaEncodingOptions>): JsonTreeSchema;
306
+
307
+ // @alpha
308
+ export function getSimpleSchema(schema: ImplicitFieldSchema): SimpleTreeSchema;
311
309
 
312
310
  // @alpha
313
311
  export type HandleConverter<TCustom> = (data: IFluidHandle) => TCustom;
@@ -750,6 +748,12 @@ export class IterableTreeArrayContent<T> implements Iterable<T> {
750
748
  export interface ITree extends ViewableTree, IFluidLoadable {
751
749
  }
752
750
 
751
+ // @alpha @sealed
752
+ export interface ITreeAlpha extends ITree {
753
+ exportSimpleSchema(): SimpleTreeSchema;
754
+ exportVerbose(): VerboseTree | undefined;
755
+ }
756
+
753
757
  // @public
754
758
  export interface ITreeConfigurationOptions {
755
759
  enableSchemaValidation?: boolean;
@@ -995,11 +999,6 @@ export type Off = () => void;
995
999
  // @alpha
996
1000
  export function onAssertionFailure(handler: (error: Error) => void): () => void;
997
1001
 
998
- // @alpha
999
- export interface ParseOptions {
1000
- readonly useStoredKeys?: boolean;
1001
- }
1002
-
1003
1002
  // @alpha
1004
1003
  export type PopUnion<Union, AsOverloadedFunction = UnionToIntersection<Union extends unknown ? (f: Union) => void : never>> = AsOverloadedFunction extends (a: infer First) => void ? First : never;
1005
1004
 
@@ -1165,9 +1164,12 @@ export class SchemaFactoryAlpha<out TScope extends string | undefined = string |
1165
1164
  arrayAlpha<const Name extends TName, const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(name: Name, allowedTypes: T, options?: NodeSchemaOptions<TCustomMetadata>): ArrayNodeCustomizableSchema<ScopedSchemaName<TScope, Name>, T, true, TCustomMetadata>;
1166
1165
  arrayRecursive<const Name extends TName, const T extends ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(name: Name, allowedTypes: T, options?: NodeSchemaOptions<TCustomMetadata>): ArrayNodeCustomizableSchemaUnsafe<ScopedSchemaName<TScope, Name>, T, TCustomMetadata>;
1167
1166
  static readonly identifier: <const TCustomMetadata = unknown>(props?: Omit<FieldProps_2<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlpha_2<FieldKind_2.Identifier, LeafSchema_2<"string", string> & SimpleLeafNodeSchema_2, TCustomMetadata>;
1167
+ static readonly leaves: readonly [LeafSchema_2<"string", string> & SimpleLeafNodeSchema_2, LeafSchema_2<"number", number> & SimpleLeafNodeSchema_2, LeafSchema_2<"boolean", boolean> & SimpleLeafNodeSchema_2, LeafSchema_2<"null", null> & SimpleLeafNodeSchema_2, LeafSchema_2<"handle", IFluidHandle_2<unknown>> & SimpleLeafNodeSchema_2];
1168
1168
  mapAlpha<Name extends TName, const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(name: Name, allowedTypes: T, options?: NodeSchemaOptions<TCustomMetadata>): MapNodeCustomizableSchema<ScopedSchemaName<TScope, Name>, T, true, TCustomMetadata>;
1169
1169
  mapRecursive<Name extends TName, const T extends ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(name: Name, allowedTypes: T, options?: NodeSchemaOptions<TCustomMetadata>): MapNodeCustomizableSchemaUnsafe<ScopedSchemaName<TScope, Name>, T, TCustomMetadata>;
1170
- object<const Name extends TName, const T extends RestrictiveStringRecord<ImplicitFieldSchema>, const TCustomMetadata = unknown>(name: Name, fields: T, options?: SchemaFactoryObjectOptions<TCustomMetadata>): ObjectNodeSchema<ScopedSchemaName<TScope, Name>, T, true, TCustomMetadata>;
1170
+ object<const Name extends TName, const T extends RestrictiveStringRecord<ImplicitFieldSchema>, const TCustomMetadata = unknown>(name: Name, fields: T, options?: SchemaFactoryObjectOptions<TCustomMetadata>): ObjectNodeSchema<ScopedSchemaName<TScope, Name>, T, true, TCustomMetadata> & {
1171
+ readonly createFromInsertable: unknown;
1172
+ };
1171
1173
  objectRecursive<const Name extends TName, const T extends RestrictiveStringRecord<ImplicitFieldSchemaUnsafe>, const TCustomMetadata = unknown>(name: Name, t: T, options?: SchemaFactoryObjectOptions<TCustomMetadata>): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Object, TreeObjectNodeUnsafe<T, ScopedSchemaName<TScope, Name>>, object & InsertableObjectFromSchemaRecordUnsafe<T>, false, T, never, TCustomMetadata> & SimpleObjectNodeSchema<TCustomMetadata> & Pick<ObjectNodeSchema, "fields">;
1172
1174
  static readonly optional: <const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldProps_2<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlpha_2<FieldKind_2.Optional, T, TCustomMetadata>;
1173
1175
  static readonly optionalRecursive: <const T extends ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldProps_2<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe_2<FieldKind_2.Optional, T, TCustomMetadata>;
@@ -1280,10 +1282,9 @@ export interface SimpleObjectNodeSchema<out TCustomMetadata = unknown> extends S
1280
1282
  export type SimpleTreeIndex<TKey extends TreeIndexKey, TValue> = TreeIndex<TKey, TValue>;
1281
1283
 
1282
1284
  // @alpha @sealed
1283
- export interface SimpleTreeSchema extends SimpleFieldSchema {
1284
- readonly allowedTypesIdentifiers: ReadonlySet<string>;
1285
+ export interface SimpleTreeSchema {
1285
1286
  readonly definitions: ReadonlyMap<string, SimpleNodeSchema>;
1286
- readonly kind: FieldKind;
1287
+ readonly root: SimpleFieldSchema;
1287
1288
  }
1288
1289
 
1289
1290
  // @alpha
@@ -1345,10 +1346,10 @@ export const TreeAlpha: {
1345
1346
  branch(node: TreeNode): TreeBranch | undefined;
1346
1347
  create<const TSchema extends ImplicitFieldSchema | UnsafeUnknownSchema>(schema: UnsafeUnknownSchema extends TSchema ? ImplicitFieldSchema : TSchema & ImplicitFieldSchema, data: InsertableField<TSchema>): Unhydrated<TSchema extends ImplicitFieldSchema ? TreeFieldFromImplicitField<TSchema> : TreeNode | TreeLeafValue | undefined>;
1347
1348
  importConcise<const TSchema extends ImplicitFieldSchema | UnsafeUnknownSchema>(schema: UnsafeUnknownSchema extends TSchema ? ImplicitFieldSchema : TSchema & ImplicitFieldSchema, data: ConciseTree | undefined): Unhydrated<TSchema extends ImplicitFieldSchema ? TreeFieldFromImplicitField<TSchema> : TreeNode | TreeLeafValue | undefined>;
1348
- importVerbose<const TSchema extends ImplicitFieldSchema>(schema: TSchema, data: VerboseTree | undefined, options?: Partial<ParseOptions>): Unhydrated<TreeFieldFromImplicitField<TSchema>>;
1349
- exportConcise(node: TreeNode | TreeLeafValue, options?: EncodeOptions): ConciseTree;
1350
- exportConcise(node: TreeNode | TreeLeafValue | undefined, options?: EncodeOptions): ConciseTree | undefined;
1351
- exportVerbose(node: TreeNode | TreeLeafValue, options?: EncodeOptions): VerboseTree;
1349
+ importVerbose<const TSchema extends ImplicitFieldSchema>(schema: TSchema, data: VerboseTree | undefined, options?: Partial<TreeEncodingOptions>): Unhydrated<TreeFieldFromImplicitField<TSchema>>;
1350
+ exportConcise(node: TreeNode | TreeLeafValue, options?: TreeEncodingOptions): ConciseTree;
1351
+ exportConcise(node: TreeNode | TreeLeafValue | undefined, options?: TreeEncodingOptions): ConciseTree | undefined;
1352
+ exportVerbose(node: TreeNode | TreeLeafValue, options?: TreeEncodingOptions): VerboseTree;
1352
1353
  exportCompressed(tree: TreeNode | TreeLeafValue, options: {
1353
1354
  oldestCompatibleClient: FluidClientVersion;
1354
1355
  idCompressor?: IIdCompressor;
@@ -1439,6 +1440,11 @@ export enum TreeCompressionStrategy {
1439
1440
  Uncompressed = 1
1440
1441
  }
1441
1442
 
1443
+ // @alpha
1444
+ export interface TreeEncodingOptions {
1445
+ readonly useStoredKeys?: boolean;
1446
+ }
1447
+
1442
1448
  // @public
1443
1449
  export type TreeFieldFromImplicitField<TSchema extends ImplicitFieldSchema = FieldSchema> = TSchema extends FieldSchema<infer Kind, infer Types> ? ApplyKind<TreeNodeFromImplicitAllowedTypes<Types>, Kind> : TSchema extends ImplicitAllowedTypes ? TreeNodeFromImplicitAllowedTypes<TSchema> : TreeNode | TreeLeafValue | undefined;
1444
1450
 
@@ -1550,6 +1556,17 @@ export type TreeObjectNode<T extends RestrictiveStringRecord<ImplicitFieldSchema
1550
1556
  // @public
1551
1557
  export type TreeObjectNodeUnsafe<T extends RestrictiveStringRecord<ImplicitFieldSchemaUnsafe>, TypeName extends string = string> = TreeNode & ObjectFromSchemaRecordUnsafe<T> & WithType<TypeName, NodeKind.Object, T>;
1552
1558
 
1559
+ // @alpha @sealed (undocumented)
1560
+ export interface TreeSchema extends SimpleTreeSchema {
1561
+ readonly definitions: ReadonlyMap<string, SimpleNodeSchema & TreeNodeSchema>;
1562
+ readonly root: FieldSchemaAlpha;
1563
+ }
1564
+
1565
+ // @alpha
1566
+ export interface TreeSchemaEncodingOptions extends TreeEncodingOptions {
1567
+ readonly requireFieldsWithDefaults?: boolean;
1568
+ }
1569
+
1553
1570
  // @public
1554
1571
  export enum TreeStatus {
1555
1572
  Deleted = 2,
@@ -1594,6 +1611,13 @@ export class TreeViewConfiguration<const TSchema extends ImplicitFieldSchema = I
1594
1611
  protected _typeCheck: MakeNominal;
1595
1612
  }
1596
1613
 
1614
+ // @alpha @sealed
1615
+ export class TreeViewConfigurationAlpha<const TSchema extends ImplicitFieldSchema = ImplicitFieldSchema> extends TreeViewConfiguration<TSchema> implements TreeSchema {
1616
+ constructor(props: ITreeViewConfiguration<TSchema>);
1617
+ readonly definitions: ReadonlyMap<string, SimpleNodeSchema & TreeNodeSchema>;
1618
+ readonly root: FieldSchemaAlpha;
1619
+ }
1620
+
1597
1621
  // @public @sealed
1598
1622
  export interface TreeViewEvents {
1599
1623
  commitApplied(data: CommitMetadata, getRevertible?: RevertibleFactory): void;
package/dist/alpha.d.ts CHANGED
@@ -151,7 +151,6 @@ export {
151
151
  ArrayNodeSchema,
152
152
  BranchableTree,
153
153
  ConciseTree,
154
- EncodeOptions,
155
154
  FactoryContent,
156
155
  FactoryContentObject,
157
156
  FieldSchemaAlpha,
@@ -165,6 +164,7 @@ export {
165
164
  ForestTypeReference,
166
165
  HandleConverter,
167
166
  ICodecOptions,
167
+ ITreeAlpha,
168
168
  IdentifierIndex,
169
169
  Insertable,
170
170
  InsertableContent,
@@ -192,7 +192,6 @@ export {
192
192
  MapNodePojoEmulationSchema,
193
193
  MapNodeSchema,
194
194
  ObjectNodeSchema,
195
- ParseOptions,
196
195
  PopUnion,
197
196
  ReadSchema,
198
197
  ReadableField,
@@ -224,10 +223,14 @@ export {
224
223
  TreeBranchEvents,
225
224
  TreeBranchFork,
226
225
  TreeCompressionStrategy,
226
+ TreeEncodingOptions,
227
227
  TreeIndex,
228
228
  TreeIndexKey,
229
229
  TreeIndexNodes,
230
+ TreeSchema,
231
+ TreeSchemaEncodingOptions,
230
232
  TreeViewAlpha,
233
+ TreeViewConfigurationAlpha,
231
234
  UnionToTuple,
232
235
  UnsafeUnknownSchema,
233
236
  ValueSchema,
@@ -248,6 +251,7 @@ export {
248
251
  generateSchemaFromSimpleSchema,
249
252
  getBranch,
250
253
  getJsonSchema,
254
+ getSimpleSchema,
251
255
  independentInitializedView,
252
256
  independentView,
253
257
  noopValidator,
package/lib/alpha.d.ts CHANGED
@@ -151,7 +151,6 @@ export {
151
151
  ArrayNodeSchema,
152
152
  BranchableTree,
153
153
  ConciseTree,
154
- EncodeOptions,
155
154
  FactoryContent,
156
155
  FactoryContentObject,
157
156
  FieldSchemaAlpha,
@@ -165,6 +164,7 @@ export {
165
164
  ForestTypeReference,
166
165
  HandleConverter,
167
166
  ICodecOptions,
167
+ ITreeAlpha,
168
168
  IdentifierIndex,
169
169
  Insertable,
170
170
  InsertableContent,
@@ -192,7 +192,6 @@ export {
192
192
  MapNodePojoEmulationSchema,
193
193
  MapNodeSchema,
194
194
  ObjectNodeSchema,
195
- ParseOptions,
196
195
  PopUnion,
197
196
  ReadSchema,
198
197
  ReadableField,
@@ -224,10 +223,14 @@ export {
224
223
  TreeBranchEvents,
225
224
  TreeBranchFork,
226
225
  TreeCompressionStrategy,
226
+ TreeEncodingOptions,
227
227
  TreeIndex,
228
228
  TreeIndexKey,
229
229
  TreeIndexNodes,
230
+ TreeSchema,
231
+ TreeSchemaEncodingOptions,
230
232
  TreeViewAlpha,
233
+ TreeViewConfigurationAlpha,
231
234
  UnionToTuple,
232
235
  UnsafeUnknownSchema,
233
236
  ValueSchema,
@@ -248,6 +251,7 @@ export {
248
251
  generateSchemaFromSimpleSchema,
249
252
  getBranch,
250
253
  getJsonSchema,
254
+ getSimpleSchema,
251
255
  independentInitializedView,
252
256
  independentView,
253
257
  noopValidator,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fluid-framework",
3
- "version": "2.31.0",
3
+ "version": "2.32.0",
4
4
  "description": "The main entry point into Fluid Framework public packages",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -57,24 +57,24 @@
57
57
  "main": "lib/index.js",
58
58
  "types": "lib/public.d.ts",
59
59
  "dependencies": {
60
- "@fluidframework/container-definitions": "~2.31.0",
61
- "@fluidframework/container-loader": "~2.31.0",
62
- "@fluidframework/core-interfaces": "~2.31.0",
63
- "@fluidframework/core-utils": "~2.31.0",
64
- "@fluidframework/driver-definitions": "~2.31.0",
65
- "@fluidframework/fluid-static": "~2.31.0",
66
- "@fluidframework/map": "~2.31.0",
67
- "@fluidframework/runtime-utils": "~2.31.0",
68
- "@fluidframework/sequence": "~2.31.0",
69
- "@fluidframework/shared-object-base": "~2.31.0",
70
- "@fluidframework/tree": "~2.31.0"
60
+ "@fluidframework/container-definitions": "~2.32.0",
61
+ "@fluidframework/container-loader": "~2.32.0",
62
+ "@fluidframework/core-interfaces": "~2.32.0",
63
+ "@fluidframework/core-utils": "~2.32.0",
64
+ "@fluidframework/driver-definitions": "~2.32.0",
65
+ "@fluidframework/fluid-static": "~2.32.0",
66
+ "@fluidframework/map": "~2.32.0",
67
+ "@fluidframework/runtime-utils": "~2.32.0",
68
+ "@fluidframework/sequence": "~2.32.0",
69
+ "@fluidframework/shared-object-base": "~2.32.0",
70
+ "@fluidframework/tree": "~2.32.0"
71
71
  },
72
72
  "devDependencies": {
73
73
  "@arethetypeswrong/cli": "^0.17.1",
74
74
  "@biomejs/biome": "~1.9.3",
75
- "@fluid-tools/build-cli": "^0.54.0",
75
+ "@fluid-tools/build-cli": "^0.55.0",
76
76
  "@fluidframework/build-common": "^2.0.3",
77
- "@fluidframework/build-tools": "^0.54.0",
77
+ "@fluidframework/build-tools": "^0.55.0",
78
78
  "@fluidframework/eslint-config-fluid": "^5.7.3",
79
79
  "@microsoft/api-extractor": "7.50.1",
80
80
  "@types/node": "^18.19.0",