-
Notifications
You must be signed in to change notification settings - Fork 537
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tree: Reduce tree stable/public API surface using InternalTypes (#21482)
## Description Move several types into InternalTypes The stable public API surface for Tree has been reduced. ## Breaking Changes Several types have been moved into InternalTypes, indicating that they are not fully stable nor intended to be referenced by users of Tree. - NodeBuilderData - FieldHasDefault - TreeNodeSchemaNonClass - TreeArrayNodeBase - ScopedSchemaName - DefaultProvider - typeNameSymbol - InsertableObjectFromSchemaRecord - ObjectFromSchemaRecord - FieldHasDefaultUnsafe - ObjectFromSchemaRecordUnsafe - TreeObjectNodeUnsafe - TreeFieldFromImplicitFieldUnsafe - TreeNodeFromImplicitAllowedTypesUnsafe - InsertableTreeNodeFromImplicitAllowedTypesUnsafe - TreeArrayNodeUnsafe - TreeMapNodeUnsafe - InsertableObjectFromSchemaRecordUnsafe - InsertableTreeFieldFromImplicitFieldUnsafe - InsertableTypedNodeUnsafe - NodeBuilderDataUnsafe - NodeFromSchemaUnsafe - FlexList - TreeApi Additionally a few more types which could not be moved due to technically limitations have been documented that they should be treated similarly. - TreeNodeApi - TreeNodeSchemaCore - All \*Unsafe type (use for construction of recursive schema). - WithType - AllowedTypes - FieldSchemaUnsafe Also to reduce confusion `type` was renamed to `typeNameSymbol`, and is now only type exported. `Tree.is` should be used to get type information from `TreeNodes` instead.
- Loading branch information
1 parent
a9cc448
commit 64d49dd
Showing
22 changed files
with
530 additions
and
192 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,45 @@ | ||
--- | ||
"fluid-framework": minor | ||
"@fluidframework/tree": minor | ||
--- | ||
|
||
Move several types into InternalTypes | ||
|
||
The stable public API surface for Tree has been reduced. | ||
Several types have been moved into InternalTypes, indicating that they are not fully stable nor intended to be referenced by users of Tree. | ||
|
||
- NodeBuilderData | ||
- FieldHasDefault | ||
- TreeNodeSchemaNonClass | ||
- TreeArrayNodeBase | ||
- ScopedSchemaName | ||
- DefaultProvider | ||
- typeNameSymbol | ||
- InsertableObjectFromSchemaRecord | ||
- ObjectFromSchemaRecord | ||
- FieldHasDefaultUnsafe | ||
- ObjectFromSchemaRecordUnsafe | ||
- TreeObjectNodeUnsafe | ||
- TreeFieldFromImplicitFieldUnsafe | ||
- TreeNodeFromImplicitAllowedTypesUnsafe | ||
- InsertableTreeNodeFromImplicitAllowedTypesUnsafe | ||
- TreeArrayNodeUnsafe | ||
- TreeMapNodeUnsafe | ||
- InsertableObjectFromSchemaRecordUnsafe | ||
- InsertableTreeFieldFromImplicitFieldUnsafe | ||
- InsertableTypedNodeUnsafe | ||
- NodeBuilderDataUnsafe | ||
- NodeFromSchemaUnsafe | ||
- FlexList | ||
- TreeApi | ||
|
||
Additionally a few more types which could not be moved due to technically limitations have been documented that they should be treated similarly. | ||
|
||
- TreeNodeApi | ||
- TreeNodeSchemaCore | ||
- All \*Unsafe type (use for construction of recursive schema). | ||
- WithType | ||
- AllowedTypes | ||
- FieldSchemaUnsafe | ||
|
||
Also to reduce confusion `type` was renamed to `typeNameSymbol`, and is now only type exported. `Tree.is` should be used to get type information from `TreeNodes` instead. |
71 changes: 71 additions & 0 deletions
71
experimental/framework/tree-react-api/src/test/schema.examples.spec.ts
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,71 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
// This file is full of test exports to ensure the types can be exported, not actually thing anyone will import. | ||
/* eslint-disable jsdoc/require-jsdoc */ | ||
|
||
import { | ||
SchemaFactory, | ||
TreeViewConfiguration, | ||
type NodeFromSchema, | ||
type ValidateRecursiveSchema, | ||
// To diagnose `error TS2742: The inferred type of ...` errors, | ||
// enable this import then look for use of it in the generated d.ts file fo find what needs to be moved out of InternalTypes | ||
// eslint-disable-next-line unused-imports/no-unused-imports | ||
// InternalTypes, | ||
} from "@fluidframework/tree"; | ||
|
||
// Due to limitation of the TypeScript compiler, errors like the following can be produced when exporting types from another package: | ||
// error TS2742: The inferred type of 'Inventory' cannot be named without a reference to '../node_modules/@fluidframework/tree/lib/internalTypes.js'. This is likely not portable. A type annotation is necessary. | ||
// Tree needs tests to make sure it does not trigger such errors, but they can't easily be done from within the tree package. | ||
// Thus tests for this case are included here, in a package which uses tree. | ||
|
||
export const schema = new SchemaFactory("com.example"); | ||
|
||
export const leafAlias = schema.number; | ||
|
||
export class Point extends schema.object("Point", { | ||
x: schema.number, | ||
}) {} | ||
|
||
export class Note extends schema.object("Note", { | ||
text: schema.string, | ||
location: schema.optional(Point), | ||
}) {} | ||
|
||
export class NodeMap extends schema.map("NoteMap", Note) {} | ||
export class NodeList extends schema.array("NoteList", Note) {} | ||
|
||
export class Canvas extends schema.object("Canvas", { stuff: [NodeMap, NodeList] }) {} | ||
|
||
export const POJO = schema.object("POJO", { stuff: [NodeMap, NodeList] }); | ||
export type POJO = NodeFromSchema<typeof POJO>; | ||
|
||
export const config = new TreeViewConfiguration({ schema: Canvas }); | ||
|
||
// Recursive cases | ||
// This lint rule doesn't work well with our schema when using the lazy format | ||
/* eslint-disable @typescript-eslint/explicit-function-return-type */ | ||
|
||
export class RecursiveObject extends schema.objectRecursive("RO", { | ||
x: [() => RecursiveObject, schema.number], | ||
}) {} | ||
{ | ||
type _check = ValidateRecursiveSchema<typeof RecursiveObject>; | ||
} | ||
|
||
export const recursiveField = schema.optionalRecursive([() => RecursiveObject, schema.number]); | ||
|
||
export class RecursiveMap extends schema.mapRecursive("RM", [() => RecursiveMap]) {} | ||
{ | ||
type _check = ValidateRecursiveSchema<typeof RecursiveMap>; | ||
} | ||
|
||
export class RecursiveArray extends schema.arrayRecursive("RA", [() => RecursiveArray]) {} | ||
{ | ||
type _check = ValidateRecursiveSchema<typeof RecursiveArray>; | ||
} | ||
|
||
/* eslint-enable @typescript-eslint/explicit-function-return-type */ |
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
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.