Repository navigation
Contents
🌳 SharedTree DDS Changes
Import trees that contain unknown optional fields (#28676)
TreeAlpha.importVerbose now supports KeyEncodingOptions.allStoredKeys. Before this change, you could use allStoredKeys only for export. Data that TreeAlpha.exportVerbose exports with allStoredKeys includes unknown optional fields, and the import could not read them. Now you can export a tree and import it again without losing data.
To import with allStoredKeys, use the new TreeImportOptions. Set keys to KeyEncodingOptions.allStoredKeys. Set view to a view of the document. The import then uses the stored schema of the view's document. All of the data must agree with this stored schema, and you can insert the result into that document. The view must be able to view its document (see TreeView.compatibility). The import must use the same schema objects as the view. Each node schema in the schema that you give to the import must come from the TreeViewConfiguration of the view. If you give a different schema object that has the same identifier, the import throws an error. This occurs also if the two schema objects define the same schema.
To find the unknown optional fields in the imported tree, use TreeContextAlpha.unknownFieldSchemas of the view.
Example
Version 1 of an application defines a Person with a name field, and allows unknown optional fields:
const sf = new SchemaFactoryBeta("com.example");
class Person extends sf.object(
"Person",
{ name: sf.string },
{ allowUnknownOptionalFields: true },
) {}Version 2 of the application adds an optional nickname field to Person:
class Person extends sf.object(
"Person",
{ name: sf.string, nickname: sf.optional(sf.string) },
{ allowUnknownOptionalFields: true },
) {}After version 2 upgrades the schema of a document, the nickname field is unknown to version 1. Version 1 can export a Person, keep the data outside of the tree, and import it again without losing nickname:
// In version 1 of the application:
// `importVerbose` needs an alpha view: use `asAlpha` to get one from a `TreeView`.
const view = asAlpha(
tree.viewWith(new TreeViewConfiguration({ schema: Person })),
);
const person = view.root;
const data = TreeAlpha.exportVerbose(person, {
keys: KeyEncodingOptions.allStoredKeys,
});
// { type: "com.example.Person", fields: { name: "Alice", nickname: "Al" } }
// Keep `data` outside of the tree, for example in a file.
// ...
// Later, import `data` into the same document:
const copy = TreeAlpha.importVerbose(Person, data, {
keys: KeyEncodingOptions.allStoredKeys,
view,
});
view.root = copy; // The copy keeps `nickname`.Change details
Commit: 1582be0
Affected packages:
- @fluidframework/tree
- fluid-framework
SharedTree preserves the schema of an initialized empty root (#28826)
An empty tree is not necessarily a new tree. Previously, if you initialized a tree with an optional root that allowed no node types, reopening it reported view.compatibility.canInitialize as true. A second call to view.initialize() could then replace its schema. Now canInitialize is false, and a second initialization throws without replacing the schema.
Change details
Commit: e5a1480
Affected packages:
- @fluidframework/tree
- fluid-framework
SharedTree applies schema upgrades needed to make a view usable (#28827)
Previously, view.upgradeSchema() could return successfully while view.compatibility.canView remained false. It now applies the permitted schema change needed to make the view usable.
Change details
Commit: ddca9a5
Affected packages:
- @fluidframework/tree
- fluid-framework
🛠️ Start Building Today!
Please continue to engage with us on GitHub Discussion and Issue pages as you adopt Fluid Framework!