Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(tree): remove internal tree types from public export #21330

Merged
merged 7 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 24 additions & 9 deletions packages/dds/tree/api-report/tree.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type AllowedTypeSet = Any | ReadonlySet<FlexTreeNodeSchema>;

// @internal
export type AllowedTypesToFlexInsertableTree<T extends FlexAllowedTypes> = [
T extends readonly LazyItem<FlexTreeNodeSchema>[] ? InsertableFlexNode<Assume<FlexListToUnion<T>, FlexTreeNodeSchema>> : ContextuallyTypedNodeData
T extends readonly LazyItem<FlexTreeNodeSchema>[] ? InsertableFlexNode<Assume<InternalFlexListTypes.FlexListToUnion<T>, FlexTreeNodeSchema>> : ContextuallyTypedNodeData
][_InlineTrick];

// @internal
Expand Down Expand Up @@ -135,7 +135,7 @@ export const Any: "Any";
export type Any = typeof Any;

// @public
export type ApplyKind<T, Kind extends FieldKind, DefaultsAreOptional extends boolean> = {
type ApplyKind<T, Kind extends FieldKind, DefaultsAreOptional extends boolean> = {
[FieldKind.Required]: T;
[FieldKind.Optional]: T | undefined;
[FieldKind.Identifier]: DefaultsAreOptional extends true ? T | undefined : T;
Expand Down Expand Up @@ -441,7 +441,7 @@ export type ExtractFromOpaque<TOpaque extends BrandedType<any, unknown>> = TOpaq
export function extractFromOpaque<TOpaque extends BrandedType<any, unknown>>(value: TOpaque): ExtractFromOpaque<TOpaque>;

// @public
export type ExtractItemType<Item extends LazyItem> = Item extends () => infer Result ? Result : Item;
type ExtractItemType<Item extends LazyItem> = Item extends () => infer Result ? Result : Item;

// @internal (undocumented)
export function fail(message: string): never;
Expand Down Expand Up @@ -593,7 +593,7 @@ export type FlexImplicitFieldSchema = FlexFieldSchema | FlexImplicitAllowedTypes
export type FlexList<Item = unknown> = readonly LazyItem<Item>[];

// @public
export type FlexListToUnion<TList extends FlexList> = ExtractItemType<TList[number]>;
type FlexListToUnion<TList extends FlexList> = ExtractItemType<TList[number]>;

// @internal
export type FlexMapFieldSchema = FlexFieldSchema<typeof FieldKinds.optional | typeof FieldKinds.sequence>;
Expand Down Expand Up @@ -839,7 +839,7 @@ export type FlexTreeTypedFieldInner<Kind extends FlexFieldKind, Types extends Fl
export type FlexTreeTypedNode<TSchema extends FlexTreeNodeSchema> = TSchema extends LeafNodeSchema ? FlexTreeLeafNode<TSchema> : TSchema extends FlexMapNodeSchema ? FlexTreeMapNode<TSchema> : TSchema extends FlexFieldNodeSchema ? FlexTreeFieldNode<TSchema> : TSchema extends FlexObjectNodeSchema ? FlexTreeObjectNodeTyped<TSchema> : FlexTreeNode;

// @internal
export type FlexTreeTypedNodeUnion<T extends FlexAllowedTypes> = T extends FlexList<FlexTreeNodeSchema> ? FlexTreeTypedNode<Assume<FlexListToUnion<T>, FlexTreeNodeSchema>> : FlexTreeNode;
export type FlexTreeTypedNodeUnion<T extends FlexAllowedTypes> = T extends FlexList<FlexTreeNodeSchema> ? FlexTreeTypedNode<Assume<InternalFlexListTypes.FlexListToUnion<T>, FlexTreeNodeSchema>> : FlexTreeNode;

// @internal
export type FlexTreeUnboxField<TSchema extends FlexFieldSchema, Emptiness extends "maybeEmpty" | "notEmpty" = "maybeEmpty"> = FlexTreeUnboxFieldInner<TSchema["kind"], TSchema["allowedTypes"], Emptiness>;
Expand Down Expand Up @@ -1006,10 +1006,10 @@ export type InsertableTreeFieldFromImplicitField<TSchema extends ImplicitFieldSc
export type InsertableTreeFieldFromImplicitFieldUnsafe<TSchema extends Unenforced<ImplicitFieldSchema>> = TSchema extends FieldSchemaUnsafe<infer Kind, infer Types> ? ApplyKind<InsertableTreeNodeFromImplicitAllowedTypesUnsafe<Types>, Kind, true> : InsertableTreeNodeFromImplicitAllowedTypesUnsafe<TSchema>;

// @public
export type InsertableTreeNodeFromImplicitAllowedTypes<TSchema extends ImplicitAllowedTypes = TreeNodeSchema> = TSchema extends TreeNodeSchema ? InsertableTypedNode<TSchema> : TSchema extends AllowedTypes ? InsertableTypedNode<FlexListToUnion<TSchema>> : never;
export type InsertableTreeNodeFromImplicitAllowedTypes<TSchema extends ImplicitAllowedTypes = TreeNodeSchema> = TSchema extends TreeNodeSchema ? InsertableTypedNode<TSchema> : TSchema extends AllowedTypes ? InsertableTypedNode<InternalFlexListTypes.FlexListToUnion<TSchema>> : never;

// @public
export type InsertableTreeNodeFromImplicitAllowedTypesUnsafe<TSchema extends Unenforced<ImplicitAllowedTypes>> = TSchema extends AllowedTypes ? InsertableTypedNodeUnsafe<FlexListToUnion<TSchema>> : InsertableTypedNodeUnsafe<TSchema>;
export type InsertableTreeNodeFromImplicitAllowedTypesUnsafe<TSchema extends Unenforced<ImplicitAllowedTypes>> = TSchema extends AllowedTypes ? InsertableTypedNodeUnsafe<InternalFlexListTypes.FlexListToUnion<TSchema>> : InsertableTypedNodeUnsafe<TSchema>;

// @public
export type InsertableTypedNode<T extends TreeNodeSchema> = (T extends {
Expand All @@ -1021,6 +1021,21 @@ export type InsertableTypedNodeUnsafe<T extends Unenforced<TreeNodeSchema>> = Un
implicitlyConstructable: true;
} ? NodeBuilderDataUnsafe<T> : never);

declare namespace InternalFlexListTypes {
export {
FlexListToUnion,
ExtractItemType
}
}
export { InternalFlexListTypes }

declare namespace InternalSimpleTreeTypes {
export {
ApplyKind
}
}
export { InternalSimpleTreeTypes }

// @public
export interface InternalTreeNode extends ErasedType<"@fluidframework/tree.InternalTreeNode"> {
}
Expand Down Expand Up @@ -1938,10 +1953,10 @@ export interface TreeNodeApi {
}

// @public
export type TreeNodeFromImplicitAllowedTypes<TSchema extends ImplicitAllowedTypes = TreeNodeSchema> = TSchema extends TreeNodeSchema ? NodeFromSchema<TSchema> : TSchema extends AllowedTypes ? NodeFromSchema<FlexListToUnion<TSchema>> : unknown;
export type TreeNodeFromImplicitAllowedTypes<TSchema extends ImplicitAllowedTypes = TreeNodeSchema> = TSchema extends TreeNodeSchema ? NodeFromSchema<TSchema> : TSchema extends AllowedTypes ? NodeFromSchema<InternalFlexListTypes.FlexListToUnion<TSchema>> : unknown;

// @public
export type TreeNodeFromImplicitAllowedTypesUnsafe<TSchema extends Unenforced<ImplicitAllowedTypes>> = TSchema extends ImplicitAllowedTypes ? TreeNodeFromImplicitAllowedTypes<TSchema> : TSchema extends TreeNodeSchema ? NodeFromSchema<TSchema> : TSchema extends AllowedTypes ? NodeFromSchema<FlexListToUnion<TSchema>> : unknown;
export type TreeNodeFromImplicitAllowedTypesUnsafe<TSchema extends Unenforced<ImplicitAllowedTypes>> = TSchema extends ImplicitAllowedTypes ? TreeNodeFromImplicitAllowedTypes<TSchema> : TSchema extends TreeNodeSchema ? NodeFromSchema<TSchema> : TSchema extends AllowedTypes ? NodeFromSchema<InternalFlexListTypes.FlexListToUnion<TSchema>> : unknown;

// @public
export type TreeNodeSchema<Name extends string = string, Kind extends NodeKind = NodeKind, TNode = unknown, TBuild = never, ImplicitlyConstructable extends boolean = boolean, Info = unknown> = TreeNodeSchemaClass<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info> | TreeNodeSchemaNonClass<Name, Kind, TNode, TBuild, ImplicitlyConstructable, Info>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import {
FlexFieldNodeSchema,
FlexFieldSchema,
FlexList,
FlexListToUnion,
FlexMapNodeSchema,
FlexObjectNodeFields,
FlexObjectNodeSchema,
FlexTreeNodeSchema,
InternalFlexListTypes,
LazyItem,
LeafNodeSchema,
} from "../typed-schema/index.js";
Expand Down Expand Up @@ -1021,7 +1021,7 @@ export type FlexTreeTypedFieldInner<
*/
export type FlexTreeTypedNodeUnion<T extends FlexAllowedTypes> =
T extends FlexList<FlexTreeNodeSchema>
? FlexTreeTypedNode<Assume<FlexListToUnion<T>, FlexTreeNodeSchema>>
? FlexTreeTypedNode<Assume<InternalFlexListTypes.FlexListToUnion<T>, FlexTreeNodeSchema>>
: FlexTreeNode;

/**
Expand Down
3 changes: 1 addition & 2 deletions packages/dds/tree/src/feature-libraries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,14 @@ export {
FlexMapFieldSchema,
SchemaCollection,
TreeNodeSchemaBase,
FlexListToUnion,
LazyItem,
InternalFlexListTypes,
isLazy,
NormalizeObjectNodeFields,
NormalizeField as NormalizeFieldSchema,
FlexObjectNodeFields,
intoStoredSchema,
intoStoredSchemaCollection,
ExtractItemType,
NormalizeLazyItem,
FlexList,
} from "./typed-schema/index.js";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import {
FlexAllowedTypes,
FlexFieldNodeSchema,
FlexFieldSchema,
FlexListToUnion,
FlexMapNodeSchema,
FlexObjectNodeFields,
FlexObjectNodeSchema,
FlexTreeNodeSchema,
InternalFlexListTypes,
LazyItem,
LeafNodeSchema,
} from "../typed-schema/index.js";
Expand Down Expand Up @@ -102,7 +102,7 @@ export type ApplyMultiplicity<TMultiplicity extends Multiplicity, TypedChild> =
*/
export type AllowedTypesToFlexInsertableTree<T extends FlexAllowedTypes> = [
T extends readonly LazyItem<FlexTreeNodeSchema>[]
? InsertableFlexNode<Assume<FlexListToUnion<T>, FlexTreeNodeSchema>>
? InsertableFlexNode<Assume<InternalFlexListTypes.FlexListToUnion<T>, FlexTreeNodeSchema>>
: ContextuallyTypedNodeData,
][_InlineTrick];

Expand Down
13 changes: 4 additions & 9 deletions packages/dds/tree/src/feature-libraries/typed-schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ export {
schemaLintDefault,
} from "./schemaCollection.js";

export {
FlexList,
markEager,
FlexListToUnion,
LazyItem,
isLazy,
ExtractItemType,
NormalizeLazyItem,
} from "./flexList.js";
export { FlexList, markEager, LazyItem, isLazy, NormalizeLazyItem } from "./flexList.js";

import * as InternalFlexListTypes from "./internalTypes.js";
export { InternalFlexListTypes };
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/

// Used by public types, but not part of the desired API surface

export { FlexListToUnion, ExtractItemType } from "./flexList.js";
5 changes: 2 additions & 3 deletions packages/dds/tree/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ export {
NormalizeFieldSchema,
FlexObjectNodeFields,
FlexMapFieldSchema,
ExtractItemType,
LazyItem,
PropertyNameFromFieldKey,
ReservedObjectNodeFieldPropertyNames,
Expand Down Expand Up @@ -290,13 +289,13 @@ export {
type,
WithType,
AllowedTypes,
ApplyKind,
FieldKind,
FieldSchema,
ImplicitAllowedTypes,
InsertableObjectFromSchemaRecord,
InsertableTreeFieldFromImplicitField,
InsertableTypedNode,
InternalSimpleTreeTypes,
NodeBuilderData,
NodeKind,
ObjectFromSchemaRecord,
Expand Down Expand Up @@ -384,7 +383,7 @@ export {
UnbrandedName,
EmptyObject,
FlexList,
FlexListToUnion,
InternalFlexListTypes,

// These field kind types really only need to show up via FieldKinds.name, and not as top level names in the package.
// These names also are collision prone.
Expand Down
3 changes: 2 additions & 1 deletion packages/dds/tree/src/simple-tree/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export {
type,
WithType,
AllowedTypes,
ApplyKind,
FieldKind,
FieldSchema,
InsertableTreeFieldFromImplicitField,
Expand All @@ -37,6 +36,8 @@ export {
type FieldProps,
normalizeFieldSchema,
} from "./schemaTypes.js";
import * as InternalSimpleTreeTypes from "./internalTypes.js";
export { InternalSimpleTreeTypes };
export { SchemaFactory, type ScopedSchemaName } from "./schemaFactory.js";
export { getFlexNode } from "./proxyBinding.js";
export { treeNodeApi, TreeNodeApi, TreeChangeEvents } from "./treeNodeApi.js";
Expand Down
8 changes: 8 additions & 0 deletions packages/dds/tree/src/simple-tree/internalTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/

// Used by public types, but not part of the desired API surface

export { ApplyKind } from "./schemaTypes.js";
11 changes: 8 additions & 3 deletions packages/dds/tree/src/simple-tree/schemaTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { ErasedType, IFluidHandle } from "@fluidframework/core-interfaces";
import { Lazy } from "@fluidframework/core-utils/internal";
import { UsageError } from "@fluidframework/telemetry-utils/internal";

import { FlexListToUnion, LazyItem, NodeKeyManager, isLazy } from "../feature-libraries/index.js";
import {
InternalFlexListTypes,
LazyItem,
NodeKeyManager,
isLazy,
} from "../feature-libraries/index.js";
import { MakeNominal, brand, isReadonlyArray } from "../util/index.js";
import { InternalTreeNode, Unhydrated } from "./types.js";
import { FieldKey } from "../core/index.js";
Expand Down Expand Up @@ -442,7 +447,7 @@ export type TreeNodeFromImplicitAllowedTypes<
> = TSchema extends TreeNodeSchema
? NodeFromSchema<TSchema>
: TSchema extends AllowedTypes
? NodeFromSchema<FlexListToUnion<TSchema>>
? NodeFromSchema<InternalFlexListTypes.FlexListToUnion<TSchema>>
: unknown;

/**
Expand All @@ -454,7 +459,7 @@ export type InsertableTreeNodeFromImplicitAllowedTypes<
> = TSchema extends TreeNodeSchema
? InsertableTypedNode<TSchema>
: TSchema extends AllowedTypes
? InsertableTypedNode<FlexListToUnion<TSchema>>
? InsertableTypedNode<InternalFlexListTypes.FlexListToUnion<TSchema>>
: never;

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/dds/tree/src/simple-tree/typesUnsafe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import { FlexListToUnion, Unenforced } from "../feature-libraries/index.js";
import { InternalFlexListTypes, Unenforced } from "../feature-libraries/index.js";
import { RestrictiveReadonlyRecord } from "../util/index.js";

import {
Expand Down Expand Up @@ -75,7 +75,7 @@ export type TreeNodeFromImplicitAllowedTypesUnsafe<
: TSchema extends TreeNodeSchema
? NodeFromSchema<TSchema>
: TSchema extends AllowedTypes
? NodeFromSchema<FlexListToUnion<TSchema>>
? NodeFromSchema<InternalFlexListTypes.FlexListToUnion<TSchema>>
: unknown;

/**
Expand All @@ -85,7 +85,7 @@ export type TreeNodeFromImplicitAllowedTypesUnsafe<
export type InsertableTreeNodeFromImplicitAllowedTypesUnsafe<
TSchema extends Unenforced<ImplicitAllowedTypes>,
> = TSchema extends AllowedTypes
? InsertableTypedNodeUnsafe<FlexListToUnion<TSchema>>
? InsertableTypedNodeUnsafe<InternalFlexListTypes.FlexListToUnion<TSchema>>
: InsertableTypedNodeUnsafe<TSchema>;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import { strict as assert } from "node:assert";
import { createIdCompressor } from "@fluidframework/id-compressor/internal";
import { MockFluidDataStoreRuntime } from "@fluidframework/test-runtime-utils/internal";

import { FlexListToUnion } from "../../feature-libraries/index.js";
import { InternalFlexListTypes } from "../../feature-libraries/index.js";
import {
ApplyKind,
FieldSchema,
InsertableTreeNodeFromImplicitAllowedTypes,
InternalSimpleTreeTypes,
NodeFromSchema,
TreeConfiguration,
TreeNodeFromImplicitAllowedTypes,
Expand Down Expand Up @@ -119,11 +119,15 @@ describe("SchemaFactory Recursive methods", () => {

type XSchema = typeof ObjectRecursive.info.x;
type Field2 = XSchema extends FieldSchema<infer Kind, infer Types>
? ApplyKind<TreeNodeFromImplicitAllowedTypes<Types>, Kind, false>
? InternalSimpleTreeTypes.ApplyKind<
TreeNodeFromImplicitAllowedTypes<Types>,
Kind,
false
>
: "zzz";
type XTypes = XSchema extends FieldSchemaUnsafe<infer Kind, infer Types> ? Types : "Q";
type Field3 = TreeNodeFromImplicitAllowedTypes<XTypes>;
type Field4 = FlexListToUnion<XTypes>;
type Field4 = InternalFlexListTypes.FlexListToUnion<XTypes>;
type _check1 = requireTrue<areSafelyAssignable<Field3, ObjectRecursive>>;
type _check2 = requireTrue<areSafelyAssignable<Field4, typeof ObjectRecursive>>;

Expand Down
Loading
Loading