Skip to content

Commit

Permalink
tree: Misc cleanup from after flex-tree schema removal (microsoft#22718)
Browse files Browse the repository at this point in the history
## Description

This does some cleanups enabled by the removal of the tree schema.
  • Loading branch information
CraigMacomber authored Oct 3, 2024
1 parent 40d3648 commit fba24a8
Show file tree
Hide file tree
Showing 30 changed files with 92 additions and 149 deletions.
14 changes: 0 additions & 14 deletions packages/dds/tree/.dependency-cruiser-known-violations.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,5 @@
"src/feature-libraries/flex-tree/lazyNode.ts",
"src/feature-libraries/flex-tree/lazyField.ts"
]
},
{
"type": "cycle",
"from": "src/feature-libraries/flex-tree/lazyField.ts",
"to": "src/feature-libraries/flex-tree/unboxed.ts",
"rule": {
"severity": "error",
"name": "no-circular"
},
"cycle": [
"src/feature-libraries/flex-tree/unboxed.ts",
"src/feature-libraries/flex-tree/lazyNode.ts",
"src/feature-libraries/flex-tree/lazyField.ts"
]
}
]
10 changes: 0 additions & 10 deletions packages/dds/tree/src/feature-libraries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,6 @@ export {
isNeverTree,
} from "./modular-schema/index.js";

export {
type Unenforced,
markEager,
type LazyItem,
type FlexListToUnion,
type ExtractItemType,
isLazy,
type FlexList,
} from "./typed-schema/index.js";

export { mapRootChanges } from "./deltaUtils.js";

export {
Expand Down

This file was deleted.

16 changes: 0 additions & 16 deletions packages/dds/tree/src/feature-libraries/typed-schema/index.ts

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions packages/dds/tree/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ export {
} from "./events/index.js";

export {
type LazyItem,
TreeStatus,
type Unenforced,
TreeCompressionStrategy,
} from "./feature-libraries/index.js";

Expand Down Expand Up @@ -150,6 +148,8 @@ export {
type JsonSchemaType,
type JsonLeafSchemaType,
getJsonSchema,
type LazyItem,
type Unenforced,
} from "./simple-tree/index.js";
export {
SharedTree,
Expand Down
2 changes: 1 addition & 1 deletion packages/dds/tree/src/internalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ export type {
NodeFromSchemaUnsafe,
ReadonlyMapInlined,
} from "./simple-tree/index.js";
export type { FlexList, FlexListToUnion, ExtractItemType } from "./feature-libraries/index.js";
export type { FlexList, FlexListToUnion, ExtractItemType } from "./simple-tree/index.js";

export type { TreeApi } from "./shared-tree/index.js";
18 changes: 18 additions & 0 deletions packages/dds/tree/src/simple-tree/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ export {
export { getJsonSchema } from "./getJsonSchema.js";
export { getSimpleSchema } from "./getSimpleSchema.js";
export { ViewSchema } from "./view.js";
export type {
Unenforced,
FieldHasDefaultUnsafe,
ObjectFromSchemaRecordUnsafe,
TreeObjectNodeUnsafe,
TreeFieldFromImplicitFieldUnsafe,
TreeNodeFromImplicitAllowedTypesUnsafe,
FieldSchemaUnsafe,
InsertableTreeNodeFromImplicitAllowedTypesUnsafe,
TreeArrayNodeUnsafe,
TreeMapNodeUnsafe,
InsertableObjectFromSchemaRecordUnsafe,
InsertableTreeFieldFromImplicitFieldUnsafe,
InsertableTypedNodeUnsafe,
NodeBuilderDataUnsafe,
NodeFromSchemaUnsafe,
ReadonlyMapInlined,
} from "./typesUnsafe.js";

export { TreeBeta, type NodeChangedData, type TreeChangeEventsBeta } from "./treeApiBeta.js";

Expand Down
10 changes: 4 additions & 6 deletions packages/dds/tree/src/simple-tree/api/schemaFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ import { UsageError } from "@fluidframework/telemetry-utils/internal";
import { isFluidHandle } from "@fluidframework/runtime-utils/internal";

import type { TreeValue } from "../../core/index.js";
import {
type NodeKeyManager,
type Unenforced,
isLazy,
} from "../../feature-libraries/index.js";
import type { NodeKeyManager } from "../../feature-libraries/index.js";
import {
type RestrictiveStringRecord,
getOrCreate,
Expand Down Expand Up @@ -73,9 +69,11 @@ import type {
TreeArrayNodeUnsafe,
TreeMapNodeUnsafe,
TreeObjectNodeUnsafe,
} from "../typesUnsafe.js";
Unenforced,
} from "./typesUnsafe.js";
import { createFieldSchemaUnsafe } from "./schemaFactoryRecursive.js";
import { TreeNodeValid } from "../treeNodeValid.js";
import { isLazy } from "../flexList.js";
/**
* Gets the leaf domain schema compatible with a given {@link TreeValue}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* Licensed under the MIT License.
*/

import type { Unenforced } from "../../feature-libraries/index.js";
import type { RestrictiveStringRecord } from "../../util/index.js";
import type { InsertableObjectFromSchemaRecord } from "../objectNode.js";

Expand All @@ -22,7 +21,7 @@ import type {
WithType,
TreeNode,
} from "../core/index.js";
import type { FieldSchemaUnsafe } from "../typesUnsafe.js";
import type { FieldSchemaUnsafe, Unenforced } from "./typesUnsafe.js";

export function createFieldSchemaUnsafe<
Kind extends FieldKind,
Expand Down
11 changes: 3 additions & 8 deletions packages/dds/tree/src/simple-tree/api/treeNodeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@
import { assert, oob } from "@fluidframework/core-utils/internal";

import { EmptyKey, rootFieldKey } from "../../core/index.js";
import {
type LazyItem,
type TreeStatus,
isLazy,
isTreeValue,
FieldKinds,
} from "../../feature-libraries/index.js";
import { type TreeStatus, isTreeValue, FieldKinds } from "../../feature-libraries/index.js";
import { fail, extractFromOpaque, isReadonlyArray } from "../../util/index.js";
import { getOrCreateInnerNode } from "../proxyBinding.js";
import {
type TreeLeafValue,
type ImplicitFieldSchema,
Expand Down Expand Up @@ -43,8 +36,10 @@ import {
getOrCreateNodeFromInnerNode,
UnhydratedFlexTreeNode,
typeSchemaSymbol,
getOrCreateInnerNode,
} from "../core/index.js";
import { isObjectNodeSchema } from "../objectNodeTypes.js";
import { isLazy, type LazyItem } from "../flexList.js";

/**
* Provides various functions for analyzing {@link TreeNode}s.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
* Licensed under the MIT License.
*/

import type { FlexListToUnion, Unenforced } from "../feature-libraries/index.js";
import type { RestrictiveStringRecord, _InlineTrick } from "../util/index.js";
import type { RestrictiveStringRecord, _InlineTrick } from "../../util/index.js";

import type {
AllowedTypes,
Expand All @@ -15,15 +14,16 @@ import type {
ImplicitFieldSchema,
NodeFromSchema,
TreeNodeFromImplicitAllowedTypes,
} from "./schemaTypes.js";
} from "../schemaTypes.js";
import type {
NodeKind,
TreeNodeSchema,
WithType,
TreeNode,
Unhydrated,
} from "./core/index.js";
import type { TreeArrayNodeBase, TreeArrayNode } from "./arrayNode.js";
} from "../core/index.js";
import type { TreeArrayNodeBase, TreeArrayNode } from "../arrayNode.js";
import type { FlexListToUnion } from "../flexList.js";

/*
* TODO:
Expand All @@ -37,6 +37,16 @@ import type { TreeArrayNodeBase, TreeArrayNode } from "./arrayNode.js";
*/
/* eslint-disable @typescript-eslint/no-explicit-any */

/**
* A placeholder to use in {@link https://www.typescriptlang.org/docs/handbook/2/generics.html#generic-constraints | extends constraints} when using the real type breaks compilation of some recursive types due to {@link https://github.com/microsoft/TypeScript/issues/55758 | a design limitation of TypeScript}.
*
* These extends constraints only serve as documentation:
* to avoid breaking compilation, this type has to not actually enforce anything, and thus is just `unknown`.
* Therefore the type safety is the responsibility of the user of the API.
* @public
*/
export type Unenforced<_DesiredExtendsConstraint> = unknown;

/**
* {@link Unenforced} version of `ObjectFromSchemaRecord`.
* @remarks
Expand Down
2 changes: 1 addition & 1 deletion packages/dds/tree/src/simple-tree/arrayNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
isFlexTreeNode,
} from "../feature-libraries/index.js";
import { prepareContentForHydration } from "./proxies.js";
import { getOrCreateInnerNode } from "./proxyBinding.js";
import {
normalizeAllowedTypes,
type ImplicitAllowedTypes,
Expand All @@ -34,6 +33,7 @@ import {
getOrCreateNodeFromInnerNode,
type TreeNodeSchemaBoth,
getSimpleNodeSchemaFromInnerNode,
getOrCreateInnerNode,
} from "./core/index.js";
import { type InsertableContent, mapTreeFromNodeData } from "./toMapTree.js";
import { fail } from "../util/index.js";
Expand Down
1 change: 1 addition & 0 deletions packages/dds/tree/src/simple-tree/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export {
type InnerNode,
tryDisposeTreeNode,
tryGetTreeNodeFromMapNode,
getOrCreateInnerNode,
} from "./treeNodeKernel.js";
export { type WithType, typeNameSymbol, typeSchemaSymbol } from "./withType.js";
export {
Expand Down
13 changes: 13 additions & 0 deletions packages/dds/tree/src/simple-tree/core/treeNodeKernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,16 @@ export function getTreeNodeSchemaFromHydratedFlexNode(flexNode: FlexTreeNode): T

return context.schema.get(flexNode.schema) ?? fail("Missing schema");
}

/**
* Retrieves the flex node associated with the given target via {@link setInnerNode}.
* @remarks
* For {@link Unhydrated} nodes, this returns the MapTreeNode.
*
* For hydrated nodes it returns a FlexTreeNode backed by the forest.
* Note that for "marinated" nodes, this FlexTreeNode exists and returns it: it does not return the MapTreeNode which is the current InnerNode.
*/
export function getOrCreateInnerNode(treeNode: TreeNode, allowFreed = false): InnerNode {
const kernel = getKernel(treeNode);
return kernel.getOrCreateInnerNode(allowFreed);
}
37 changes: 18 additions & 19 deletions packages/dds/tree/src/simple-tree/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export {
tryDisposeTreeNode,
HydratedContext,
SimpleContextSlot,
getOrCreateInnerNode,
} from "./core/index.js";
export {
type ITree,
Expand Down Expand Up @@ -68,6 +69,22 @@ export {
getJsonSchema,
getSimpleSchema,
ViewSchema,
type Unenforced,
type FieldHasDefaultUnsafe,
type ObjectFromSchemaRecordUnsafe,
type TreeObjectNodeUnsafe,
type TreeFieldFromImplicitFieldUnsafe,
type TreeNodeFromImplicitAllowedTypesUnsafe,
type FieldSchemaUnsafe,
type InsertableTreeNodeFromImplicitAllowedTypesUnsafe,
type TreeArrayNodeUnsafe,
type TreeMapNodeUnsafe,
type InsertableObjectFromSchemaRecordUnsafe,
type InsertableTreeFieldFromImplicitFieldUnsafe,
type InsertableTypedNodeUnsafe,
type NodeBuilderDataUnsafe,
type NodeFromSchemaUnsafe,
type ReadonlyMapInlined,
} from "./api/index.js";
export {
type NodeFromSchema,
Expand All @@ -90,29 +107,10 @@ export {
type ApplyKind,
type FieldSchemaMetadata,
} from "./schemaTypes.js";
export { getOrCreateInnerNode } from "./proxyBinding.js";
export type {
FieldHasDefaultUnsafe,
ObjectFromSchemaRecordUnsafe,
TreeObjectNodeUnsafe,
TreeFieldFromImplicitFieldUnsafe,
TreeNodeFromImplicitAllowedTypesUnsafe,
FieldSchemaUnsafe,
InsertableTreeNodeFromImplicitAllowedTypesUnsafe,
TreeArrayNodeUnsafe,
TreeMapNodeUnsafe,
InsertableObjectFromSchemaRecordUnsafe,
InsertableTreeFieldFromImplicitFieldUnsafe,
InsertableTypedNodeUnsafe,
NodeBuilderDataUnsafe,
NodeFromSchemaUnsafe,
ReadonlyMapInlined,
} from "./typesUnsafe.js";
export {
getTreeNodeForField,
prepareContentForHydration,
} from "./proxies.js";

export {
TreeArrayNode,
IterableTreeArrayContent,
Expand All @@ -135,3 +133,4 @@ export {
handleSchema,
nullSchema,
} from "./leafNodeSchema.js";
export type { LazyItem, FlexList, FlexListToUnion, ExtractItemType } from "./flexList.js";
2 changes: 1 addition & 1 deletion packages/dds/tree/src/simple-tree/mapNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
getSchemaAndPolicy,
} from "../feature-libraries/index.js";
import { getTreeNodeForField, prepareContentForHydration } from "./proxies.js";
import { getOrCreateInnerNode } from "./proxyBinding.js";
import {
createFieldSchema,
FieldKind,
Expand All @@ -33,6 +32,7 @@ import {
typeSchemaSymbol,
type Context,
UnhydratedFlexTreeNode,
getOrCreateInnerNode,
} from "./core/index.js";
import {
mapTreeFromNodeData,
Expand Down
2 changes: 1 addition & 1 deletion packages/dds/tree/src/simple-tree/objectNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
getSchemaAndPolicy,
} from "../feature-libraries/index.js";
import { getTreeNodeForField, prepareContentForHydration } from "./proxies.js";
import { getOrCreateInnerNode } from "./proxyBinding.js";
import {
type ImplicitFieldSchema,
getStoredKey,
Expand All @@ -39,6 +38,7 @@ import {
type TreeNode,
type Context,
UnhydratedFlexTreeNode,
getOrCreateInnerNode,
} from "./core/index.js";
import { mapTreeFromNodeData, type InsertableContent } from "./toMapTree.js";
import { type RestrictiveStringRecord, fail, type FlattenKeys } from "../util/index.js";
Expand Down
Loading

0 comments on commit fba24a8

Please sign in to comment.