Skip to content

Commit

Permalink
Replace use of contentSnapshot in dev tools visualizer with newer APIs (
Browse files Browse the repository at this point in the history
microsoft#23256)

## Description

contentSnapshot being package exported is the only cause for many
internal tree types being package exported, and its only being used due
to there being no way to read data from a tree without a schema.

Now that proper types exist for reading such data, this change
implements exporters in those formats that work without view schema to
replace the external use of contentSnapshot.
  • Loading branch information
CraigMacomber authored Dec 10, 2024
1 parent 96092b1 commit a62bbe9
Show file tree
Hide file tree
Showing 25 changed files with 413 additions and 293 deletions.
3 changes: 0 additions & 3 deletions packages/dds/tree/src/core/schema-stored/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const version = 1 as const;
* Key (aka Name or Label) for a field which is scoped to a specific TreeNodeStoredSchema.
*
* Stable identifier, used when persisting data.
* @internal
*/
export type FieldKey = Brand<string, "tree.FieldKey">;

Expand All @@ -28,7 +27,6 @@ export const FieldKeySchema = brandedStringType<FieldKey>();
* Also known as "Definition"
*
* Stable identifier, used when persisting data.
* @internal
*/
export type TreeNodeSchemaIdentifier<TName extends string = string> = Brand<
TName,
Expand All @@ -40,7 +38,6 @@ export type TreeNodeSchemaIdentifier<TName extends string = string> = Brand<
* Refers to an exact stable policy (ex: specific version of a policy),
* for how to handle (ex: edit and merge edits to) fields marked with this kind.
* Persisted in documents as part of stored schema.
* @internal
*/
export type FieldKindIdentifier = Brand<string, "tree.FieldKindIdentifier">;
export const FieldKindIdentifierSchema = brandedStringType<FieldKindIdentifier>();
Expand Down
13 changes: 3 additions & 10 deletions packages/dds/tree/src/core/schema-stored/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import {
import type { Multiplicity } from "./multiplicity.js";

/**
* Schema for what {@link TreeValue} is allowed on a Leaf node.
* Schema for what {@link TreeLeafValue} is allowed on a Leaf node.
* @privateRemarks
* See also {@link TreeValue}.
* @internal
*/
export enum ValueSchema {
Expand Down Expand Up @@ -51,7 +53,6 @@ export enum ValueSchema {
* - Constrain the types allowed based on which types guarantee their data will always meet the constraints.
*
* Care would need to be taken to make sure this is sound for the schema updating mechanisms.
* @internal
*/
export type TreeTypeSet = ReadonlySet<TreeNodeSchemaIdentifier>;

Expand Down Expand Up @@ -96,7 +97,6 @@ export interface SchemaPolicy {
/**
* Schema for a field.
* Object implementing this interface should never be modified.
* @internal
*/
export interface TreeFieldStoredSchema {
readonly kind: FieldKindIdentifier;
Expand Down Expand Up @@ -136,7 +136,6 @@ export const identifierFieldKindIdentifier = "Identifier";

/**
* Opaque type erased handle to the encoded representation of the contents of a stored schema.
* @internal
*/
export interface ErasedTreeNodeSchemaDataFormat
extends ErasedType<"TreeNodeSchemaDataFormat"> {}
Expand All @@ -154,7 +153,6 @@ export function toTreeNodeSchemaDataFormat(
}

/**
* @internal
*/
export abstract class TreeNodeStoredSchema {
protected _typeCheck!: MakeNominal;
Expand All @@ -174,7 +172,6 @@ export abstract class TreeNodeStoredSchema {
}

/**
* @internal
*/
export class ObjectNodeStoredSchema extends TreeNodeStoredSchema {
/**
Expand Down Expand Up @@ -214,7 +211,6 @@ export class ObjectNodeStoredSchema extends TreeNodeStoredSchema {
}

/**
* @internal
*/
export class MapNodeStoredSchema extends TreeNodeStoredSchema {
/**
Expand All @@ -241,7 +237,6 @@ export class MapNodeStoredSchema extends TreeNodeStoredSchema {
}

/**
* @internal
*/
export class LeafNodeStoredSchema extends TreeNodeStoredSchema {
/**
Expand Down Expand Up @@ -330,7 +325,6 @@ export function decodeFieldSchema(schema: FieldSchemaFormat): TreeFieldStoredSch
* @remarks
* Note: the owner of this may modify it over time:
* thus if needing to hand onto a specific version, make a copy.
* @internal
*/
export interface TreeStoredSchema extends StoredSchemaCollection {
/**
Expand All @@ -345,7 +339,6 @@ export interface TreeStoredSchema extends StoredSchemaCollection {
* @remarks
* Note: the owner of this may modify it over time:
* thus if needing to hang onto a specific version, make a copy.
* @internal
*/
export interface StoredSchemaCollection {
/**
Expand Down
5 changes: 0 additions & 5 deletions packages/dds/tree/src/core/tree/treeTextFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ import type { NodeData } from "./types.js";
* Only use this type when needed for json compatible maps,
* but even in those cases consider lists of key value pairs for serialization and using `Map`
* for runtime.
*
* @internal
*/
export interface FieldMapObject<TChild> {
[key: string]: TChild[];
Expand All @@ -59,14 +57,12 @@ export interface FieldMapObject<TChild> {
/**
* Json comparable tree node, generic over child type.
* Json compatibility assumes `TChild` is also json compatible.
* @internal
*/
export interface GenericTreeNode<TChild> extends GenericFieldsNode<TChild>, NodeData {}

/**
* Json comparable field collection, generic over child type.
* Json compatibility assumes `TChild` is also json compatible.
* @internal
*/
export interface GenericFieldsNode<TChild> {
fields?: FieldMapObject<TChild>;
Expand All @@ -79,7 +75,6 @@ export interface GenericFieldsNode<TChild> {
* {@link @fluidframework/shared-object-base#IFluidSerializer.stringify} must be used instead of `JSON.stringify`.
*
* JsonableTrees should not store empty fields.
* @internal
*/
export interface JsonableTree extends GenericTreeNode<JsonableTree> {}

Expand Down
5 changes: 0 additions & 5 deletions packages/dds/tree/src/core/tree/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export type TreeType = TreeNodeSchemaIdentifier;
* This has to be a FieldKey since different nodes will have different TreeFieldStoredSchema for it.
* This makes it prone to collisions and suggests
* that this intention may be better conveyed by metadata on the ITreeSchema.
* @internal
*/
export const EmptyKey: FieldKey = brand("");

Expand Down Expand Up @@ -116,7 +115,6 @@ export interface FieldKind {

/**
* Value that may be stored on a leaf node.
* @internal
*/
export type TreeValue<TSchema extends ValueSchema = ValueSchema> = [
{
Expand All @@ -131,7 +129,6 @@ export type TreeValue<TSchema extends ValueSchema = ValueSchema> = [

/**
* Value stored on a node.
* @internal
*/
export type Value = undefined | TreeValue;

Expand All @@ -141,8 +138,6 @@ export type Value = undefined | TreeValue;
* @privateRemarks A forked version of this type is used in `persistedTreeTextFormat.ts`.
* Changes to this type might necessitate changes to `EncodedNodeData` or codecs.
* See persistedTreeTextFormat's module documentation for more details.
*
* @internal
*/
export interface NodeData {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import { fail } from "../../util/index.js";
import type { FullSchemaPolicy } from "./fieldKind.js";

/**
* @internal
*/

export function isNeverField(
policy: FullSchemaPolicy,
originalData: TreeStoredSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export interface HasMoveId {
}

/**
* @internal
*/
export interface CellId extends ChangeAtomId {}

Expand Down
30 changes: 1 addition & 29 deletions packages/dds/tree/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,15 @@
*/

export {
EmptyKey,
type FieldKey,
type TreeValue,
type FieldMapObject,
type NodeData,
type GenericTreeNode,
type JsonableTree,
type GenericFieldsNode,
type TreeNodeSchemaIdentifier,
type TreeFieldStoredSchema,
ValueSchema,
TreeNodeStoredSchema,
type FieldKindIdentifier,
type TreeTypeSet,
type TreeStoredSchema,
type Revertible,
CommitKind,
RevertibleStatus,
type CommitMetadata,
type StoredSchemaCollection,
type ErasedTreeNodeSchemaDataFormat,
ObjectNodeStoredSchema,
MapNodeStoredSchema,
LeafNodeStoredSchema,
type RevertibleFactory,
type RevertibleAlphaFactory,
type RevertibleAlpha,
} from "./core/index.js";
export { type Brand } from "./util/index.js";

export type {
Listeners,
Expand All @@ -50,10 +30,9 @@ export {
} from "./feature-libraries/index.js";

export {
type ISharedTree,
type ITreeInternal,
type SharedTreeOptions,
ForestType,
type SharedTreeContentSnapshot,
type SharedTreeFormatOptions,
SharedTreeFormatVersion,
Tree,
Expand Down Expand Up @@ -190,11 +169,6 @@ export {
type SimpleObjectNodeSchema,
normalizeAllowedTypes,
getSimpleSchema,
numberSchema,
stringSchema,
booleanSchema,
handleSchema,
nullSchema,
type ReadonlyArrayNode,
type InsertableTreeNodeFromAllowedTypes,
type Input,
Expand All @@ -217,8 +191,6 @@ export { noopValidator } from "./codec/index.js";
export { typeboxValidator } from "./external-utilities/index.js";

export {
type Covariant,
BrandedType,
type RestrictiveReadonlyRecord,
type RestrictiveStringRecord,
type MakeNominal,
Expand Down
1 change: 1 addition & 0 deletions packages/dds/tree/src/shared-tree/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export {
buildConfiguredForest,
defaultSharedTreeOptions,
type ForestOptions,
type ITreeInternal,
} from "./sharedTree.js";

export {
Expand Down
Loading

0 comments on commit a62bbe9

Please sign in to comment.