Skip to content

Shared Tree: In-memory format and API changes for persisted schema metadata #24759

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

Merged
merged 67 commits into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from 57 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
bd8406a
Initial change.
TommyBrosman May 12, 2025
3165fe3
persistedMetadata is now backed by an object instead of a string.
TommyBrosman May 13, 2025
9709ede
Updated codec.spec.ts to cover FormatV2.
TommyBrosman May 13, 2025
ba058e1
Removed extraneous whitespace change.
TommyBrosman May 13, 2025
b819742
- Changed TreeNodeStoredSchema implementations to take the write vers…
TommyBrosman May 13, 2025
0b5c842
- Changed the stored schema implementation to handle multiple schema …
TommyBrosman May 13, 2025
ecdca7a
Merge branch 'main' into metadata-schema-3
TommyBrosman May 13, 2025
1117c2c
Apply suggestions from code review
TommyBrosman May 14, 2025
94a5c39
- Switched to using the SchemaCodecVersion in public APIs. Eventually…
TommyBrosman May 14, 2025
302cb21
Merge branch 'metadata-schema-3' of https://github.com/TommyBrosman/F…
TommyBrosman May 14, 2025
0ba34d1
- Removed the schema version constant and replaced it with SchemaCode…
TommyBrosman May 14, 2025
3275ee0
Minor: reverted changes to FluidClientVersion utils.
TommyBrosman May 15, 2025
7c48b9d
Switched back to using min client version for importCompressed.
TommyBrosman May 15, 2025
a2f4195
Minor: reverted accidental change.
TommyBrosman May 15, 2025
4786dcc
Apply suggestions from code review
TommyBrosman May 15, 2025
6fa8836
Made persisted metadata schema field naming consistent.
TommyBrosman May 15, 2025
e4064c7
- Created a separate storedSchemaDecodeDispatcher for v2 schemas.
TommyBrosman May 16, 2025
ab1b882
- Refactored the node kind dispatch.
TommyBrosman May 19, 2025
1027daa
Updated snapshots.
TommyBrosman May 19, 2025
e527eba
- Removed minimum client version changes. Equivalent changes will be …
TommyBrosman May 19, 2025
3eae1f6
Removed more minimumClientVersion glue.
TommyBrosman May 19, 2025
98e1b76
Updated API files.
TommyBrosman May 19, 2025
ecc77c9
Rename: SchemaCodecVersion -> SchemaVersion.
TommyBrosman May 20, 2025
37e900f
Merge branch 'main' into metadata-schema-3
TommyBrosman May 20, 2025
737633b
Removed top-level persisted metadata.
TommyBrosman May 21, 2025
4bb136c
Fixed comments.
TommyBrosman May 22, 2025
0bcb90f
Exposed persistedMetadata as a JsonCompatibleReadOnlyObject.
TommyBrosman May 22, 2025
a675338
Changeset.
TommyBrosman May 22, 2025
1d1ef5f
Wired up toStoredSchema. Still needs tests.
TommyBrosman May 22, 2025
b9898e8
- Updated an old snapshot that didn't include the metadata field.
TommyBrosman May 22, 2025
6ca189a
Refactor: persistedMetadata -> metadata on persisted types.
TommyBrosman May 27, 2025
85240dc
Apply suggestions from code review
TommyBrosman May 27, 2025
8883d45
- Updated the changeset description
TommyBrosman May 28, 2025
9c2c13f
Reverted unnecessary change.
TommyBrosman May 28, 2025
c62f7ec
Wired up node schema metadata persistence. Currently errors on tests …
TommyBrosman May 29, 2025
2f6b519
Reverted unneeded change.
TommyBrosman May 29, 2025
ae1779b
Removed tests for the alpha API I removed in a previous revision.
TommyBrosman May 29, 2025
7eff8ab
This revision adds simple-tree persistence for node and field schema …
TommyBrosman May 30, 2025
f3f572c
- Fixed missing persistedMetadata on fields. toStoredSchema.ts and sh…
TommyBrosman Jun 2, 2025
faaf2f7
Merge branch 'main' into metadata-schema-3
TommyBrosman Jun 2, 2025
f80d027
Removed changes for persisted format, codecs. A few tests are failing.
TommyBrosman Jun 3, 2025
a7e72f0
Minor cleanup.
TommyBrosman Jun 3, 2025
3dcfb10
Updated changeset description.
TommyBrosman Jun 4, 2025
dcf4e0e
Merge branch 'main' into metadata-in-memory
TommyBrosman Jun 4, 2025
bca4c8c
Regenerated API Extractor output.
TommyBrosman Jun 4, 2025
b66c928
Renamed the in-memory version of the persistedMetadata field to persi…
TommyBrosman Jun 6, 2025
98c853e
Merge branch 'main' into metadata-in-memory
TommyBrosman Jun 6, 2025
155b320
- Added a simple default comparison for persistedMetadata.
TommyBrosman Jun 9, 2025
4ff48d8
Minor: clarified use of persistedMetadata in tests.
TommyBrosman Jun 9, 2025
6400590
- Removed redundant alpha APIs. For now they are exposed only as static
TommyBrosman Jun 10, 2025
b329851
Reverted changes that belong in a different PR.
TommyBrosman Jun 10, 2025
6b425b2
Removed more changes that shouldn't be in this PR.
TommyBrosman Jun 10, 2025
c0eb6dc
Apply suggestions from code review
TommyBrosman Jun 10, 2025
c9a1346
Reverted another unrelated change.
TommyBrosman Jun 10, 2025
03d3bc4
Merge branch 'main' into metadata-in-memory
TommyBrosman Jun 10, 2025
002a80c
Updated API Extractor output.
TommyBrosman Jun 10, 2025
e3443bd
Changed SchemaFactoryAlpha calls to use instance methods.
TommyBrosman Jun 10, 2025
72e32ab
- Cleaned up the type for in-memory persistedMetadata.
TommyBrosman Jun 11, 2025
9d86b72
Merge branch 'main' into metadata-in-memory
TommyBrosman Jun 11, 2025
f4b258a
Regenerated API Extractor output.
TommyBrosman Jun 11, 2025
a743d39
Update packages/dds/tree/src/simple-tree/api/schemaFactory.ts
TommyBrosman Jun 11, 2025
01d5eae
Docs.
TommyBrosman Jun 11, 2025
58bbeb7
Merge branch 'metadata-in-memory' of https://github.com/TommyBrosman/…
TommyBrosman Jun 11, 2025
c4e29c8
Merge branch 'main' into metadata-in-memory
TommyBrosman Jun 11, 2025
e2f350c
- Cleaned up comparators and added tests.
TommyBrosman Jun 11, 2025
ea00cc9
Merge branch 'main' into metadata-in-memory
TommyBrosman Jun 11, 2025
a6348b4
Merge branch 'main' into metadata-in-memory
TommyBrosman Jun 12, 2025
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
65 changes: 45 additions & 20 deletions packages/dds/tree/api-report/tree.alpha.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ export interface FieldProps<TCustomMetadata = unknown> {
readonly metadata?: FieldSchemaMetadata<TCustomMetadata>;
}

// @alpha @input
export interface FieldPropsAlpha<TCustomMetadata = unknown> extends FieldProps<TCustomMetadata> {
readonly persistedMetadata?: JsonCompatibleReadOnlyObject | undefined;
}

// @public @sealed
export class FieldSchema<out Kind extends FieldKind = FieldKind, out Types extends ImplicitAllowedTypes = ImplicitAllowedTypes, out TCustomMetadata = unknown> {
protected constructor(
Expand All @@ -203,13 +208,14 @@ export class FieldSchema<out Kind extends FieldKind = FieldKind, out Types exten

// @alpha @sealed
export class FieldSchemaAlpha<Kind extends FieldKind = FieldKind, Types extends ImplicitAllowedTypes = ImplicitAllowedTypes, TCustomMetadata = unknown> extends FieldSchema<Kind, Types, TCustomMetadata> implements SimpleFieldSchema {
protected constructor(kind: Kind, types: Types, annotatedAllowedTypes: ImplicitAnnotatedAllowedTypes, props?: FieldProps<TCustomMetadata>);
protected constructor(kind: Kind, types: Types, annotatedAllowedTypes: ImplicitAnnotatedAllowedTypes, props?: FieldPropsAlpha<TCustomMetadata>);
// (undocumented)
get allowedTypesIdentifiers(): ReadonlySet<string>;
readonly allowedTypesMetadata: AllowedTypesMetadata;
// (undocumented)
readonly annotatedAllowedTypes: ImplicitAnnotatedAllowedTypes;
get annotatedAllowedTypeSet(): ReadonlyMap<TreeNodeSchema, AllowedTypeMetadata>;
get persistedMetadata(): JsonCompatibleReadOnlyObject | undefined;
}

// @alpha @sealed @system
Expand Down Expand Up @@ -448,6 +454,14 @@ export type JsonCompatibleObject<TExtra = never> = {
[P in string]?: JsonCompatible<TExtra>;
};

// @alpha
export type JsonCompatibleReadOnly = string | number | boolean | null | readonly JsonCompatibleReadOnly[] | JsonCompatibleReadOnlyObject;

// @alpha
export type JsonCompatibleReadOnlyObject = {
readonly [P in string]?: JsonCompatibleReadOnly;
};

// @alpha @sealed
export type JsonFieldSchema = {
readonly description?: string | undefined;
Expand Down Expand Up @@ -596,6 +610,11 @@ export interface NodeSchemaOptions<out TCustomMetadata = unknown> {
readonly metadata?: NodeSchemaMetadata<TCustomMetadata> | undefined;
}

// @alpha @sealed
export interface NodeSchemaOptionsAlpha<out TCustomMetadata = unknown> extends NodeSchemaOptions<TCustomMetadata> {
readonly persistedMetadata?: JsonCompatibleReadOnlyObject | undefined;
}

// @alpha
export const noopValidator: JsonValidator;

Expand Down Expand Up @@ -761,42 +780,42 @@ export class SchemaFactory<out TScope extends string | undefined = string | unde

// @alpha
export class SchemaFactoryAlpha<out TScope extends string | undefined = string | undefined, TName extends number | string = string> extends SchemaFactory<TScope, TName> {
arrayAlpha<const Name extends TName, const T extends ImplicitAnnotatedAllowedTypes, const TCustomMetadata = unknown>(name: Name, allowedTypes: T, options?: NodeSchemaOptions<TCustomMetadata>): ArrayNodeCustomizableSchema<ScopedSchemaName<TScope, Name>, T, true, TCustomMetadata>;
arrayAlpha<const Name extends TName, const T extends ImplicitAnnotatedAllowedTypes, const TCustomMetadata = unknown>(name: Name, allowedTypes: T, options?: NodeSchemaOptionsAlpha<TCustomMetadata>): ArrayNodeCustomizableSchema<ScopedSchemaName<TScope, Name>, T, true, TCustomMetadata>;
arrayRecursive<const Name extends TName, const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(name: Name, allowedTypes: T, options?: NodeSchemaOptions<TCustomMetadata>): ArrayNodeCustomizableSchemaUnsafe<ScopedSchemaName<TScope, Name>, T, TCustomMetadata>;
static readonly identifier: <const TCustomMetadata = unknown>(props?: Omit<FieldProps_2<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlpha_2<FieldKind_2.Identifier, LeafSchema_2<"string", string> & SimpleLeafNodeSchema_2, TCustomMetadata>;
static readonly leaves: readonly [LeafSchema_2<"string", string> & SimpleLeafNodeSchema_2, LeafSchema_2<"number", number> & SimpleLeafNodeSchema_2, LeafSchema_2<"boolean", boolean> & SimpleLeafNodeSchema_2, LeafSchema_2<"null", null> & SimpleLeafNodeSchema_2, LeafSchema_2<"handle", IFluidHandle<unknown>> & SimpleLeafNodeSchema_2];
readonly leaves: readonly [LeafSchema_2<"string", string> & SimpleLeafNodeSchema_2, LeafSchema_2<"number", number> & SimpleLeafNodeSchema_2, LeafSchema_2<"boolean", boolean> & SimpleLeafNodeSchema_2, LeafSchema_2<"null", null> & SimpleLeafNodeSchema_2, LeafSchema_2<"handle", IFluidHandle<unknown>> & SimpleLeafNodeSchema_2];
mapAlpha<Name extends TName, const T extends ImplicitAnnotatedAllowedTypes, const TCustomMetadata = unknown>(name: Name, allowedTypes: T, options?: NodeSchemaOptions<TCustomMetadata>): MapNodeCustomizableSchema<ScopedSchemaName<TScope, Name>, T, true, TCustomMetadata>;
mapAlpha<Name extends TName, const T extends ImplicitAnnotatedAllowedTypes, const TCustomMetadata = unknown>(name: Name, allowedTypes: T, options?: NodeSchemaOptionsAlpha<TCustomMetadata>): MapNodeCustomizableSchema<ScopedSchemaName<TScope, Name>, T, true, TCustomMetadata>;
mapRecursive<Name extends TName, const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(name: Name, allowedTypes: T, options?: NodeSchemaOptions<TCustomMetadata>): MapNodeCustomizableSchemaUnsafe<ScopedSchemaName<TScope, Name>, T, TCustomMetadata>;
objectAlpha<const Name extends TName, const T extends RestrictiveStringRecord<ImplicitAnnotatedFieldSchema>, const TCustomMetadata = unknown>(name: Name, fields: T, options?: SchemaFactoryObjectOptions<TCustomMetadata>): ObjectNodeSchema<ScopedSchemaName<TScope, Name>, T, true, TCustomMetadata> & {
readonly createFromInsertable: unknown;
};
objectRecursive<const Name extends TName, const T extends RestrictiveStringRecord<System_Unsafe.ImplicitFieldSchemaUnsafe>, const TCustomMetadata = unknown>(name: Name, t: T, options?: SchemaFactoryObjectOptions<TCustomMetadata>): TreeNodeSchemaClass<ScopedSchemaName<TScope, Name>, NodeKind.Object, System_Unsafe.TreeObjectNodeUnsafe<T, ScopedSchemaName<TScope, Name>>, object & System_Unsafe.InsertableObjectFromSchemaRecordUnsafe<T>, false, T, never, TCustomMetadata> & SimpleObjectNodeSchema<TCustomMetadata> & Pick<ObjectNodeSchema, "fields">;
static readonly optional: {
<const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldProps_2<TCustomMetadata>, "defaultProvider"> | undefined): FieldSchemaAlpha_2<FieldKind_2.Optional, T, TCustomMetadata>;
<const T_1 extends ImplicitAnnotatedAllowedTypes, const TCustomMetadata_1 = unknown>(t: T_1, props?: Omit<FieldProps_2<TCustomMetadata_1>, "defaultProvider"> | undefined): FieldSchemaAlpha_2<FieldKind_2.Optional, UnannotateImplicitAllowedTypes_2<T_1>, TCustomMetadata_1>;
<const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha_2<TCustomMetadata>, "defaultProvider"> | undefined): FieldSchemaAlpha_2<FieldKind_2.Optional, T, TCustomMetadata>;
<const T_1 extends ImplicitAnnotatedAllowedTypes, const TCustomMetadata_1 = unknown>(t: T_1, props?: Omit<FieldPropsAlpha_2<TCustomMetadata_1>, "defaultProvider"> | undefined): FieldSchemaAlpha_2<FieldKind_2.Optional, UnannotateImplicitAllowedTypes_2<T_1>, TCustomMetadata_1>;
};
readonly optional: {
<const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldProps_2<TCustomMetadata>, "defaultProvider"> | undefined): FieldSchemaAlpha_2<FieldKind_2.Optional, T, TCustomMetadata>;
<const T_1 extends ImplicitAnnotatedAllowedTypes, const TCustomMetadata_1 = unknown>(t: T_1, props?: Omit<FieldProps_2<TCustomMetadata_1>, "defaultProvider"> | undefined): FieldSchemaAlpha_2<FieldKind_2.Optional, UnannotateImplicitAllowedTypes_2<T_1>, TCustomMetadata_1>;
<const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha_2<TCustomMetadata>, "defaultProvider"> | undefined): FieldSchemaAlpha_2<FieldKind_2.Optional, T, TCustomMetadata>;
<const T_1 extends ImplicitAnnotatedAllowedTypes, const TCustomMetadata_1 = unknown>(t: T_1, props?: Omit<FieldPropsAlpha_2<TCustomMetadata_1>, "defaultProvider"> | undefined): FieldSchemaAlpha_2<FieldKind_2.Optional, UnannotateImplicitAllowedTypes_2<T_1>, TCustomMetadata_1>;
};
static readonly optionalRecursive: <const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldProps_2<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe_2<FieldKind_2.Optional, T, TCustomMetadata>;
readonly optionalRecursive: <const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldProps_2<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe_2<FieldKind_2.Optional, T, TCustomMetadata>;
static readonly optionalRecursive: <const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha_2<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe_2<FieldKind_2.Optional, T, TCustomMetadata>;
readonly optionalRecursive: <const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha_2<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe_2<FieldKind_2.Optional, T, TCustomMetadata>;
static readonly required: {
<const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldProps_2<TCustomMetadata>, "defaultProvider"> | undefined): FieldSchemaAlpha_2<FieldKind_2.Required, T, TCustomMetadata>;
<const T_1 extends ImplicitAnnotatedAllowedTypes, const TCustomMetadata_1 = unknown>(t: T_1, props?: Omit<FieldProps_2<TCustomMetadata_1>, "defaultProvider"> | undefined): FieldSchemaAlpha_2<FieldKind_2.Required, UnannotateImplicitAllowedTypes_2<T_1>, TCustomMetadata_1>;
<const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha_2<TCustomMetadata>, "defaultProvider"> | undefined): FieldSchemaAlpha_2<FieldKind_2.Required, T, TCustomMetadata>;
<const T_1 extends ImplicitAnnotatedAllowedTypes, const TCustomMetadata_1 = unknown>(t: T_1, props?: Omit<FieldPropsAlpha_2<TCustomMetadata_1>, "defaultProvider"> | undefined): FieldSchemaAlpha_2<FieldKind_2.Required, UnannotateImplicitAllowedTypes_2<T_1>, TCustomMetadata_1>;
};
readonly required: {
<const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldProps_2<TCustomMetadata>, "defaultProvider"> | undefined): FieldSchemaAlpha_2<FieldKind_2.Required, T, TCustomMetadata>;
<const T_1 extends ImplicitAnnotatedAllowedTypes, const TCustomMetadata_1 = unknown>(t: T_1, props?: Omit<FieldProps_2<TCustomMetadata_1>, "defaultProvider"> | undefined): FieldSchemaAlpha_2<FieldKind_2.Required, UnannotateImplicitAllowedTypes_2<T_1>, TCustomMetadata_1>;
<const T extends ImplicitAllowedTypes, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha_2<TCustomMetadata>, "defaultProvider"> | undefined): FieldSchemaAlpha_2<FieldKind_2.Required, T, TCustomMetadata>;
<const T_1 extends ImplicitAnnotatedAllowedTypes, const TCustomMetadata_1 = unknown>(t: T_1, props?: Omit<FieldPropsAlpha_2<TCustomMetadata_1>, "defaultProvider"> | undefined): FieldSchemaAlpha_2<FieldKind_2.Required, UnannotateImplicitAllowedTypes_2<T_1>, TCustomMetadata_1>;
};
static readonly requiredRecursive: <const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldProps_2<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe_2<FieldKind_2.Required, T, TCustomMetadata>;
readonly requiredRecursive: <const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldProps_2<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe_2<FieldKind_2.Required, T, TCustomMetadata>;
static readonly requiredRecursive: <const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha_2<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe_2<FieldKind_2.Required, T, TCustomMetadata>;
readonly requiredRecursive: <const T extends System_Unsafe.ImplicitAllowedTypesUnsafe, const TCustomMetadata = unknown>(t: T, props?: Omit<FieldPropsAlpha_2<TCustomMetadata>, "defaultProvider"> | undefined) => FieldSchemaAlphaUnsafe_2<FieldKind_2.Required, T, TCustomMetadata>;
scopedFactory<const T extends TName, TNameInner extends number | string = string>(name: T): SchemaFactoryAlpha<ScopedSchemaName<TScope, T>, TNameInner>;
}

// @alpha
export interface SchemaFactoryObjectOptions<TCustomMetadata = unknown> extends NodeSchemaOptions<TCustomMetadata> {
export interface SchemaFactoryObjectOptions<TCustomMetadata = unknown> extends NodeSchemaOptionsAlpha<TCustomMetadata> {
allowUnknownOptionalFields?: boolean;
}

Expand Down Expand Up @@ -848,7 +867,7 @@ export type SharedTreeFormatVersion = typeof SharedTreeFormatVersion;
export type SharedTreeOptions = Partial<CodecWriteOptions> & Partial<SharedTreeFormatOptions> & ForestOptions;

// @alpha @sealed
export interface SimpleArrayNodeSchema<out TCustomMetadata = unknown> extends SimpleNodeSchemaBase<NodeKind.Array, TCustomMetadata> {
export interface SimpleArrayNodeSchema<out TCustomMetadata = unknown> extends SimpleNodeSchemaBaseAlpha<NodeKind.Array, TCustomMetadata> {
readonly allowedTypesIdentifiers: ReadonlySet<string>;
}

Expand All @@ -857,15 +876,16 @@ export interface SimpleFieldSchema {
readonly allowedTypesIdentifiers: ReadonlySet<string>;
readonly kind: FieldKind;
readonly metadata: FieldSchemaMetadata;
readonly persistedMetadata?: JsonCompatibleReadOnlyObject | undefined;
}

// @alpha @sealed
export interface SimpleLeafNodeSchema extends SimpleNodeSchemaBase<NodeKind.Leaf> {
export interface SimpleLeafNodeSchema extends SimpleNodeSchemaBaseAlpha<NodeKind.Leaf> {
readonly leafKind: ValueSchema;
}

// @alpha @sealed
export interface SimpleMapNodeSchema<out TCustomMetadata = unknown> extends SimpleNodeSchemaBase<NodeKind.Map, TCustomMetadata> {
export interface SimpleMapNodeSchema<out TCustomMetadata = unknown> extends SimpleNodeSchemaBaseAlpha<NodeKind.Map, TCustomMetadata> {
readonly allowedTypesIdentifiers: ReadonlySet<string>;
}

Expand All @@ -878,13 +898,18 @@ export interface SimpleNodeSchemaBase<out TNodeKind extends NodeKind, out TCusto
readonly metadata: NodeSchemaMetadata<TCustomMetadata>;
}

// @alpha @sealed @system
export interface SimpleNodeSchemaBaseAlpha<out TNodeKind extends NodeKind, out TCustomMetadata = unknown> extends SimpleNodeSchemaBase<TNodeKind, TCustomMetadata> {
readonly persistedMetadata: JsonCompatibleReadOnlyObject | undefined;
}

// @alpha @sealed
export interface SimpleObjectFieldSchema extends SimpleFieldSchema {
readonly storedKey: string;
}

// @alpha @sealed
export interface SimpleObjectNodeSchema<out TCustomMetadata = unknown> extends SimpleNodeSchemaBase<NodeKind.Object, TCustomMetadata> {
export interface SimpleObjectNodeSchema<out TCustomMetadata = unknown> extends SimpleNodeSchemaBaseAlpha<NodeKind.Object, TCustomMetadata> {
readonly fields: ReadonlyMap<string, SimpleObjectFieldSchema>;
}

Expand Down
30 changes: 29 additions & 1 deletion packages/dds/tree/src/core/schema-stored/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
import { fail } from "@fluidframework/core-utils/internal";

import { DiscriminatedUnionDispatcher } from "../../codec/index.js";
import { type MakeNominal, brand, invertMap } from "../../util/index.js";
import {
JsonCompatibleReadOnlySchema,
type MakeNominal,
brand,
invertMap,
} from "../../util/index.js";

import {
type FieldKey,
Expand All @@ -17,6 +22,7 @@ import {
type TreeNodeSchemaIdentifier,
} from "./formatV1.js";
import type { Multiplicity } from "./multiplicity.js";
import { Type, type Static } from "@sinclair/typebox";

/**
* The format version for the schema.
Expand Down Expand Up @@ -116,6 +122,16 @@ export interface SchemaPolicy {
allowUnknownOptionalFields(identifier: TreeNodeSchemaIdentifier): boolean;
}

/**
* In-memory format for persisted schema metadata.
*
* @privateRemarks
* TODO: Move to schema FormatV2 once it has been defined.
*/
export const PersistedMetadataFormat = Type.Optional(JsonCompatibleReadOnlySchema);

export type PersistedMetadataFormat = Static<typeof PersistedMetadataFormat>;

/**
* Schema for a field.
* Object implementing this interface should never be modified.
Expand All @@ -128,6 +144,15 @@ export interface TreeFieldStoredSchema {
* If not specified, types are unconstrained.
*/
readonly types: TreeTypeSet;

/**
* Portion of the metadata which can be persisted.
* @remarks
* Discarded when encoding to {@link SchemaFormatVersion.V1}.
* @privateRemarks
* This field corresponds to the `metadata` field in the persisted schema format.
*/
readonly persistedMetadata: PersistedMetadataFormat | undefined;
}

/**
Expand All @@ -151,6 +176,7 @@ export const storedEmptyFieldSchema: TreeFieldStoredSchema = {
kind: brand(forbiddenFieldKindIdentifier),
// This type set also forces the field to be empty not not allowing any types as all.
types: new Set(),
persistedMetadata: undefined,
};

/**
Expand Down Expand Up @@ -323,6 +349,8 @@ export function decodeFieldSchema(schema: FieldSchemaFormat): TreeFieldStoredSch
// TODO: maybe provide actual FieldKind objects here, error on unrecognized kinds.
kind: schema.kind,
types: new Set(schema.types),
// TODO: Persist metadata once schema FormatV2 has been added.
persistedMetadata: undefined,
};
return out;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export class FieldKindWithEditor<
isNeverField(policy, originalData, {
kind: this.identifier,
types: originalTypes,
// Metadata is not used for this check.
persistedMetadata: undefined,
})
) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ export class ObjectForest implements IEditableForest, WithBreakable {
// Some detached fields may have multiple nodes, so we must treat them as sequences:
kind: FieldKinds.sequence.identifier,
types: new Set(documentRoot.map((node) => node.type)),

// Metadata is not used for schema checks
persistedMetadata: undefined,
};
const maybeError = isFieldInSchema(documentRoot, fieldSchema, {
schema,
Expand Down
5 changes: 5 additions & 0 deletions packages/dds/tree/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export {
type TreeNodeSchemaClass,
type SchemaCompatibilityStatus,
type FieldProps,
type FieldPropsAlpha,
type InternalTreeNode,
type WithType,
type NodeChangedData,
Expand Down Expand Up @@ -198,6 +199,7 @@ export {
type LazyItem,
type Unenforced,
type SimpleNodeSchemaBase,
type SimpleNodeSchemaBaseAlpha,
type SimpleTreeSchema,
type SimpleNodeSchema,
type SimpleFieldSchema,
Expand All @@ -215,6 +217,7 @@ export {
type TreeBranchEvents,
asTreeViewAlpha,
type NodeSchemaOptions,
type NodeSchemaOptionsAlpha,
type NodeSchemaMetadata,
type SchemaStatics,
type ITreeAlpha,
Expand Down Expand Up @@ -282,6 +285,8 @@ export type {
PopUnion,
JsonCompatible,
JsonCompatibleObject,
JsonCompatibleReadOnly,
JsonCompatibleReadOnlyObject,
} from "./util/index.js";
export { cloneWithReplacements } from "./util/index.js";

Expand Down
1 change: 1 addition & 0 deletions packages/dds/tree/src/shared-tree/schematizeTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export function initializeContent(
rootFieldSchema: {
kind: FieldKinds.optional.identifier,
types: rootSchema.types,
persistedMetadata: rootSchema.persistedMetadata,
},
};
}
Expand Down
Loading
Loading