-
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.
## Description Cleans input type down-casting logic. This removes some dead code, does some refactors, and fixes a couple issues: 1. fields with defaults did not translate the API key to the stored key. This is not called out in the changeset since the only fields with defaults that matter for this are identifiers, and the current API makes it impossible to select a different stored key. 2. the types for implicit node construction of arrays and maps did not match the runtime behavior. This is improved, tested and documented, but not fully fixed.
- Loading branch information
1 parent
4c9e611
commit 977f96c
Showing
29 changed files
with
501 additions
and
321 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,15 @@ | ||
--- | ||
"fluid-framework": minor | ||
"@fluidframework/tree": minor | ||
--- | ||
|
||
Implicit TreeNode construction improvements | ||
|
||
ArrayNodes and MapNodes could always be explicitly constructed (using `new`) from iterables. | ||
The types also allowed using of iterables to construct implicitly construct array nodes and map nodes, | ||
but this did not work at runtime. | ||
This has been fixed for all cases except implicitly constructing an ArrayNode form an `Iterable` that is actually a `Map`, | ||
and implicitly constructing a MapNode from an `Iterable` that is actually an `Array`. | ||
These cases may be fixed in the future, but require additional work to ensure unions of array nodes and map nodes work correctly. | ||
|
||
Additionally MapNodes can now be constructed from `Iterator<readonly [string, content]>` where previously the inner arrays had to be mutable. |
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
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
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
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
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
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,64 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation and contributors. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import type { RestrictiveReadonlyRecord } from "../util/index.js"; | ||
import type { | ||
TreeObjectNode, | ||
InsertableObjectFromSchemaRecord, | ||
SimpleKeyMap, | ||
} from "./objectNode.js"; | ||
import { | ||
type ImplicitFieldSchema, | ||
type TreeNodeSchemaClass, | ||
NodeKind, | ||
type FieldSchema, | ||
type TreeNodeSchema, | ||
} from "./schemaTypes.js"; | ||
|
||
/** | ||
* A schema for {@link TreeObjectNode}s. | ||
* @privateRemarks | ||
* This is a candidate for being promoted to the public package API. | ||
*/ | ||
export interface ObjectNodeSchema< | ||
TName extends string = string, | ||
T extends RestrictiveReadonlyRecord<string, ImplicitFieldSchema> = RestrictiveReadonlyRecord< | ||
string, | ||
ImplicitFieldSchema | ||
>, | ||
ImplicitlyConstructable extends boolean = boolean, | ||
> extends TreeNodeSchemaClass< | ||
TName, | ||
NodeKind.Object, | ||
TreeObjectNode<T, TName>, | ||
object & InsertableObjectFromSchemaRecord<T>, | ||
ImplicitlyConstructable, | ||
T | ||
> { | ||
readonly fields: ReadonlyMap<string, FieldSchema>; | ||
} | ||
|
||
/** | ||
* Extra data provided on all {@link ObjectNodeSchema} that is not included in the (soon possibly public) ObjectNodeSchema type. | ||
*/ | ||
export interface ObjectNodeSchemaInternalData { | ||
/** | ||
* {@inheritdoc SimpleKeyMap} | ||
*/ | ||
readonly flexKeyMap: SimpleKeyMap; | ||
} | ||
|
||
export const ObjectNodeSchema = { | ||
// instanceof-based narrowing support for Javascript and TypeScript 5.3 or newer. | ||
[Symbol.hasInstance](value: TreeNodeSchema): value is ObjectNodeSchema { | ||
return isObjectNodeSchema(value); | ||
}, | ||
} as const; | ||
|
||
export function isObjectNodeSchema( | ||
schema: TreeNodeSchema, | ||
): schema is ObjectNodeSchema & ObjectNodeSchemaInternalData { | ||
return schema.kind === NodeKind.Object; | ||
} |
Oops, something went wrong.