-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tree): Add the ability to associate metadata with Node Schema (#…
…23321) Users of TreeView can now specify metadata when creating Node Schema, via `SchemaFactoryAlpha`. This metadata may include system-understood properties like `description`. Example: ```typescript const schemaFactory = new SchemaFactoryAlpha(...); class Point extends schemaFactory.object("Point", { x: schemaFactory.required(schemaFactory.number), y: schemaFactory.required(schemaFactory.number), }, { metadata: { description: "A point in 2D space", }, }) {} ```
- Loading branch information
Showing
31 changed files
with
952 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
"@fluidframework/tree": minor | ||
--- | ||
--- | ||
section: tree | ||
--- | ||
|
||
Metadata can be associated with Node Schema | ||
|
||
Users of TreeView can now specify metadata when creating Node Schema, via `SchemaFactoryAlpha`. | ||
This metadata may include system-understood properties like `description`. | ||
|
||
Example: | ||
|
||
```typescript | ||
const schemaFactory = new SchemaFactoryAlpha(...); | ||
class Point extends schemaFactory.object("Point", { | ||
x: schemaFactory.required(schemaFactory.number), | ||
y: schemaFactory.required(schemaFactory.number), | ||
}, | ||
{ | ||
metadata: { | ||
description: "A point in 2D space", | ||
}, | ||
}) {} | ||
|
||
``` | ||
|
||
Functionality like the experimental conversion of Tree Schema to [JSON Schema](https://json-schema.org/) ([getJsonSchema](https://github.com/microsoft/FluidFramework/releases/tag/client_v2.4.0#user-content-metadata-can-now-be-associated-with-field-schema-22564)) leverages such system-understood metadata to generate useful information. | ||
In the case of the `description` property, it is mapped directly to the `description` property supported by JSON Schema. | ||
|
||
Custom, user-defined properties can also be specified. | ||
These properties will not be used by the system by default, but can be used to associate common application-specific properties with Node Schema. | ||
|
||
#### `SchemaFactoryAlpha` Updates | ||
|
||
- `object` and `objectRecursive`, `arrayRecursive`, and `mapRecursive` now support `metadata` in their `options` parameter. | ||
- (new) `arrayAlpha` - Variant of `array` that accepts an options parameter which supports `metadata` | ||
- (new) `mapAlpha` - Variant of `map` that accepts an options parameter which supports `metadata` | ||
|
||
#### Example | ||
|
||
An application is implementing search functionality. | ||
By default, the app author wishes for all app content to be potentially indexable by search, unless otherwise specified. | ||
They can leverage schema metadata to decorate types of nodes that should be ignored by search, and leverage that information when walking the tree during a search. | ||
|
||
```typescript | ||
|
||
interface AppMetadata { | ||
/** | ||
* Whether or not nodes of this type should be ignored by search. | ||
* @defaultValue `false` | ||
*/ | ||
searchIgnore?: boolean; | ||
} | ||
|
||
const schemaFactory = new SchemaFactoryAlpha(...); | ||
class Point extends schemaFactory.object("Point", { | ||
x: schemaFactory.required(schemaFactory.number), | ||
y: schemaFactory.required(schemaFactory.number), | ||
}, | ||
{ | ||
metadata: { | ||
description: "A point in 2D space", | ||
custom: { | ||
searchIgnore: true, | ||
}, | ||
} | ||
}) {} | ||
|
||
``` | ||
|
||
Search can then be implemented to look for the appropriate metadata, and leverage it to omit the unwanted position data from search. | ||
|
||
#### Potential for breaking existing code | ||
|
||
These changes add the new property "metadata" to the base type from which all node schema derive. | ||
If you have existing node schema subclasses that include a property of this name, there is a chance for potential conflict here that could be breaking. | ||
If you encounter issues here, consider renaming your property or leveraging the new metadata support. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,6 +43,7 @@ | |
"handletable", | ||
"incrementality", | ||
"injective", | ||
"insertable", | ||
"losslessly", | ||
"mitigations", | ||
"mocharc", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.