TreeAlpha Interface
Extensions to Tree and TreeBeta which are not yet stable.
For more information about our API support guarantees, see here.
This type is "sealed," meaning that code outside of the library defining it should not implement or extend it. Future versions of this type may add members or make typing of readonly members more specific.
Signature
/** @sealed */
export interface TreeAlpha
Remarks
Use via the TreeAlpha singleton.
The unhydrated node creation APIs in this interface do not support unknown optional fields. This is because unknown optional fields still must have a schema: its just that the schema may come from the document's stored schema. Unhydrated nodes created via this interface are not associated with any document, so there is nowhere for them to get schema for unknown optional fields. Note that clone(node) can create an unhydrated node with unknown optional fields, as it uses the source node's stored schema (if any).
Export APIs in this interface include unknown optional fields if they are using allStoredKeys.
Properties
| Property | Alerts | Modifiers | Type | Description |
|---|---|---|---|---|
| identifier | Alpha |
readonly |
TreeIdentifierUtils | APIs for creating, converting, and retrieving identifiers. |
Methods
| Method | Alerts | Return Type | Description |
|---|---|---|---|
| branch(node) | Alpha |
TreeBranchAlpha | undefined | Retrieve the branch, if any, for the given node. |
| child(node, key) | Alpha |
TreeNode | TreeLeafValue | undefined | Gets the child of the given node with the given property key if a child exists under that key. |
| children(node) | Alpha |
Iterable<[propertyKey: string | number, child: TreeNode | TreeLeafValue]> | Gets the children of the provided node, paired with their property keys under the node. |
| create(schema, data) | Alpha |
Unhydrated<TSchema extends ImplicitFieldSchema ? TreeFieldFromImplicitField<TSchema> : TreeNode | TreeLeafValue | undefined> | Construct tree content that is compatible with the field defined by the provided schema. |
| exportCompressed(tree, options) | Alpha |
JsonCompatible<IFluidHandle> | Export the content of the provided tree in a compressed JSON compatible format. |
| exportConcise(node, options) | Alpha |
ConciseTree | Copy a snapshot of the current version of a TreeNode into a ConciseTree. |
| exportConcise(node, options) | Alpha |
ConciseTree | undefined | Copy a snapshot of the current version of a TreeNode into a ConciseTree, allowing undefined. |
| exportVerbose(node, options) | Alpha |
VerboseTree | Copy a snapshot of the current version of a TreeNode into a JSON compatible plain old JavaScript Object (except for IFluidHandles). Uses the VerboseTree format, with an explicit type on every node. |
| importCompressed(schema, compressedData, options) | Alpha |
Unhydrated<TreeFieldFromImplicitField<TSchema>> | Import data encoded by exportCompressed(tree, options). |
| importConcise(schema, data) | Alpha |
Unhydrated<TSchema extends ImplicitFieldSchema ? TreeFieldFromImplicitField<TSchema> : TreeNode | TreeLeafValue | undefined> | A less type-safe version of create(schema, data), suitable for importing data. |
| importVerbose(schema, data, options) | Alpha |
Unhydrated<TreeFieldFromImplicitField<TSchema>> | Construct tree content compatible with a field defined by the provided schema. |
| key2(node) | Alpha |
string | number | undefined | The key of the given node under its parent. |
| tagContentSchema(schema, content) | Alpha |
TContent | Ensures that the provided content will be interpreted as the given schema when inserting into the tree. |
| trackObservations(onInvalidation, trackDuring) | Alpha |
ObservationResults<TResult> | Track observations of any TreeNode content. |
| trackObservationsOnce(onInvalidation, trackDuring) | Alpha |
ObservationResults<TResult> | trackObservations(onInvalidation, trackDuring) except automatically unsubscribes when the first invalidation occurs. |
Property Details
identifier
APIs for creating, converting, and retrieving identifiers.
For more information about our API support guarantees, see here.
Signature
readonly identifier: TreeIdentifierUtils;
Type: TreeIdentifierUtils
Method Details
branch
Retrieve the branch, if any, for the given node.
For more information about our API support guarantees, see here.
Signature
branch(node: TreeNode): TreeBranchAlpha | undefined;
Remarks
If the node has already been inserted into the tree, this will return the branch associated with that node's view. Otherwise, it will return undefined (because the node has not yet been inserted and is therefore not part of a branch or view).
This does not fork a new branch, but rather retrieves the _existing_ branch for the node. To create a new branch, use e.g. `myBranch.fork()`.
Parameters
| Parameter | Type | Description |
|---|---|---|
| node | TreeNode | The node to query |
Returns
Return type: TreeBranchAlpha | undefined
child
Gets the child of the given node with the given property key if a child exists under that key.
For more information about our API support guarantees, see here.
Signature
child(node: TreeNode, key: string | number): TreeNode | TreeLeafValue | undefined;
Remarks
Unknown optional fields of Object nodes will not be returned by this method.
Parameters
| Parameter | Type | Description |
|---|---|---|
| node | TreeNode | The parent node whose child is being requested. |
| key | string | number | The property key under the node under which the child is being requested. For Object nodes, this is the developer-facing "property key", not the "stored keys". |
Returns
The child node or leaf value under the given key, or undefined if no such child exists.
Return type: TreeNode | TreeLeafValue | undefined
See Also
children
Gets the children of the provided node, paired with their property keys under the node.
For more information about our API support guarantees, see here.
Signature
children(node: TreeNode): Iterable<[propertyKey: string | number, child: TreeNode | TreeLeafValue]>;
Remarks
No guarantees are made regarding the order of the children in the returned array.
Optional properties of Object nodes with no value are not included in the result.
Unknown optional fields of Object nodes are not included in the result.
Parameters
| Parameter | Type | Description |
|---|---|---|
| node | TreeNode | The node whose children are being requested. |
Returns
An array of pairs of the form [propertyKey, child].
For Array nodes, the propertyKey is the index of the child in the array.
For Object nodes, the returned propertyKeys are the developer-facing "property keys", not the "stored keys".
Return type: Iterable<[propertyKey: string | number, child: TreeNode | TreeLeafValue]>
See Also
create
Construct tree content that is compatible with the field defined by the provided schema.
For more information about our API support guarantees, see here.
Signature
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>;
Type Parameters
| Parameter | Constraint | Description |
|---|---|---|
| TSchema | ImplicitFieldSchema | UnsafeUnknownSchema |
Remarks
When providing a TreeNodeSchemaClass, this is the same as invoking its constructor except that an unhydrated node can also be provided. This function exists as a generalization that can be used in other cases as well, such as when undefined might be allowed (for an optional field), or when the type should be inferred from the data when more than one type is possible.
Parameters
| Parameter | Type | Description |
|---|---|---|
| schema | UnsafeUnknownSchema extends TSchema ? ImplicitFieldSchema : TSchema & ImplicitFieldSchema | The schema for what to construct. As this is an ImplicitFieldSchema, a FieldSchema, TreeNodeSchema or AllowedTypes array can be provided. |
| data | InsertableField<TSchema> | The data used to construct the field content. |
Returns
Return type: Unhydrated<TSchema extends ImplicitFieldSchema ? TreeFieldFromImplicitField<TSchema> : TreeNode | TreeLeafValue | undefined>
exportCompressed
Export the content of the provided tree in a compressed JSON compatible format.
For more information about our API support guarantees, see here.
Signature
exportCompressed(tree: TreeNode | TreeLeafValue, options: {
idCompressor?: IIdCompressor;
} & Pick<CodecWriteOptions, "minVersionForCollab">): JsonCompatible<IFluidHandle>;
Remarks
If an idCompressor is provided, it will be used to compress identifiers and thus will be needed to decompress the data.
Always uses "stored" keys. See allStoredKeys for details.
Parameters
| Parameter | Type | Description |
|---|---|---|
| tree | TreeNode | TreeLeafValue | |
| options | { idCompressor?: IIdCompressor; } & Pick<CodecWriteOptions, "minVersionForCollab"> |
Returns
Return type: JsonCompatible<IFluidHandle>
exportConcise
Copy a snapshot of the current version of a TreeNode into a ConciseTree.
For more information about our API support guarantees, see here.
Signature
exportConcise(node: TreeNode | TreeLeafValue, options?: TreeEncodingOptions): ConciseTree;
Parameters
| Parameter | Modifiers | Type | Description |
|---|---|---|---|
| node | TreeNode | TreeLeafValue | ||
| options | optional | TreeEncodingOptions |
Returns
Return type: ConciseTree