Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
45ed7f7
Initial change. Implemented viewSchemaToViewCompatibilitySchema. No t…
TommyBrosman Oct 23, 2025
f76e1eb
Added test coverage using the existing toSimpleSchema tests as a star…
TommyBrosman Oct 23, 2025
491c2ed
Refactored the schema copying code.
TommyBrosman Oct 23, 2025
25eef86
Removed persistedMetadata and metadata from Node schemas copied in Vi…
TommyBrosman Oct 23, 2025
d80bee6
Minor: better typing in copy methods.
TommyBrosman Oct 23, 2025
15fa315
Added snapshot tests.
TommyBrosman Oct 24, 2025
a239d88
Got snapshotting working correctly. It currently involves a lot of ca…
TommyBrosman Oct 24, 2025
b168cd4
Cleanup.
TommyBrosman Oct 24, 2025
95c255a
Added a test around hasStagedSchemaUpgrades.
TommyBrosman Oct 24, 2025
7559289
Added staged allowed type info to SimpleSchema. Started replacing all…
TommyBrosman Oct 28, 2025
2e443d4
Replaced SimpleSchema allowedTypesIdentifiers with simpleAllowedTypes.
TommyBrosman Oct 29, 2025
4e970d2
- Fixed a couple references to allowedTypesIdentifiers.
TommyBrosman Oct 29, 2025
55ca84b
Minor refactors. Addressed some PR feedback.
TommyBrosman Oct 29, 2025
f48aa8a
- PR feedback.
TommyBrosman Oct 29, 2025
ee473df
Removed change that shouldn't be in this PR.
TommyBrosman Oct 29, 2025
8dc387a
Merge branch 'main' into simple-allowed-types
TommyBrosman Oct 29, 2025
9bf1810
- Removed evaluateSimpleAllowedTypes from AnnotatedAllowedTypes (whic…
TommyBrosman Oct 29, 2025
97e1b12
Apply suggestion from @noencke
TommyBrosman Oct 29, 2025
6eddd77
Rename.
TommyBrosman Oct 29, 2025
1464268
Merge branch 'simple-allowed-types' of https://github.com/TommyBrosma…
TommyBrosman Oct 29, 2025
f4e16ea
API Extractor.
TommyBrosman Oct 29, 2025
d00a237
Rename.
TommyBrosman Oct 29, 2025
e17113c
Merge branch 'main' into simple-allowed-types
TommyBrosman Oct 30, 2025
550240b
Fixed exports.
TommyBrosman Oct 30, 2025
7a218b1
Fix for failing test and cases where `toSimpleTreeSchema` should not …
TommyBrosman Oct 30, 2025
69c3674
Minor rename.
TommyBrosman Oct 30, 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
32 changes: 20 additions & 12 deletions packages/dds/tree/api-report/tree.alpha.api.md

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/dds/tree/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ export {
type TreeParsingOptions,
type SchemaFactory_base,
type NumberKeys,
type AllowedTypeInfo,
} from "./simple-tree/index.js";
export {
SharedTree,
Expand Down
19 changes: 16 additions & 3 deletions packages/dds/tree/src/shared-tree/sharedTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
type TreeStoredSchema,
TreeStoredSchemaRepository,
type TreeStoredSchemaSubscription,
type TreeTypeSet,
getCodecTreeForDetachedFieldIndexFormat,
makeDetachedFieldIndex,
moveToDetachedField,
Expand Down Expand Up @@ -98,6 +99,7 @@ import {
FieldKind,
type ITreeAlpha,
type SimpleObjectFieldSchema,
type AllowedTypeInfo,
} from "../simple-tree/index.js";

import { SchematizingSimpleTreeView } from "./schematizingTreeView.js";
Expand Down Expand Up @@ -950,6 +952,16 @@ export const defaultSharedTreeOptions: Required<SharedTreeOptionsInternal> = {
shouldEncodeIncrementally: defaultIncrementalEncodingPolicy,
};

function buildSimpleAllowedTypes(types: TreeTypeSet): ReadonlyMap<string, AllowedTypeInfo> {
const allowedTypesInfo = new Map<string, AllowedTypeInfo>();
for (const type of types) {
allowedTypesInfo.set(type, {
isStaged: false,
});
}
return allowedTypesInfo;
}

function exportSimpleFieldSchemaStored(schema: TreeFieldStoredSchema): SimpleFieldSchema {
let kind: FieldKind;
switch (schema.kind) {
Expand All @@ -971,7 +983,8 @@ function exportSimpleFieldSchemaStored(schema: TreeFieldStoredSchema): SimpleFie
}
return {
kind,
allowedTypesIdentifiers: schema.types,
// TODO: Refactor
simpleAllowedTypes: buildSimpleAllowedTypes(schema.types),
metadata: {},
persistedMetadata: schema.persistedMetadata,
};
Expand All @@ -987,7 +1000,7 @@ function exportSimpleNodeSchemaStored(schema: TreeNodeStoredSchema): SimpleNodeS
if (arrayTypes !== undefined) {
return {
kind: NodeKind.Array,
allowedTypesIdentifiers: arrayTypes,
simpleAllowedTypes: buildSimpleAllowedTypes(arrayTypes),
metadata: {},
persistedMetadata: schema.metadata,
};
Expand All @@ -1006,7 +1019,7 @@ function exportSimpleNodeSchemaStored(schema: TreeNodeStoredSchema): SimpleNodeS
);
return {
kind: NodeKind.Map,
allowedTypesIdentifiers: schema.mapFields.types,
simpleAllowedTypes: buildSimpleAllowedTypes(schema.mapFields.types),
metadata: {},
persistedMetadata: schema.metadata,
};
Expand Down
30 changes: 16 additions & 14 deletions packages/dds/tree/src/simple-tree/api/schemaFromSimple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
type FieldProps,
} from "../fieldSchema.js";
import type {
SimpleAllowedTypes,
SimpleFieldSchema,
SimpleNodeSchema,
SimpleTreeSchema,
Expand Down Expand Up @@ -65,7 +66,7 @@ function generateFieldSchema(
context: Context,
storedKey: string | undefined,
): FieldSchemaAlpha {
const allowed = generateAllowedTypes(simple.allowedTypesIdentifiers, context);
const allowed = generateAllowedTypes(simple.simpleAllowedTypes, context);
const props: Omit<FieldProps, "defaultProvider"> = {
metadata: simple.metadata,
key: storedKey,
Expand All @@ -84,8 +85,13 @@ function generateFieldSchema(
}
}

function generateAllowedTypes(allowed: ReadonlySet<string>, context: Context): AllowedTypes {
return [...allowed].map((id) => context.get(id) ?? fail(0xb5a /* Missing schema */));
function generateAllowedTypes(
allowed: ReadonlyMap<string, SimpleAllowedTypes>,
context: Context,
): AllowedTypes {
return [...new Set(allowed.keys())].map(
(id) => context.get(id) ?? fail(0xb5a /* Missing schema */),
);
}

function generateNode(
Expand All @@ -104,21 +110,17 @@ function generateNode(
return factory.objectAlpha(id, fields, { metadata: schema.metadata });
}
case NodeKind.Array:
return factory.arrayAlpha(
id,
generateAllowedTypes(schema.allowedTypesIdentifiers, context),
{ metadata: schema.metadata },
);
return factory.arrayAlpha(id, generateAllowedTypes(schema.simpleAllowedTypes, context), {
metadata: schema.metadata,
});
case NodeKind.Map:
return factory.mapAlpha(
id,
generateAllowedTypes(schema.allowedTypesIdentifiers, context),
{ metadata: schema.metadata },
);
return factory.mapAlpha(id, generateAllowedTypes(schema.simpleAllowedTypes, context), {
metadata: schema.metadata,
});
case NodeKind.Record:
return factory.recordAlpha(
id,
generateAllowedTypes(schema.allowedTypesIdentifiers, context),
generateAllowedTypes(schema.simpleAllowedTypes, context),
{ metadata: schema.metadata },
);
case NodeKind.Leaf:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ function convertNodeSchema(

function convertArrayNodeSchema(schema: SimpleArrayNodeSchema): JsonArrayNodeSchema {
const allowedTypes: JsonSchemaRef[] = [];
schema.allowedTypesIdentifiers.forEach((type) => {
const allowedTypesIdentifiers: ReadonlySet<string> = new Set(
schema.simpleAllowedTypes.keys(),
);
allowedTypesIdentifiers.forEach((type) => {
allowedTypes.push(createSchemaRef(type));
});

Expand Down Expand Up @@ -206,7 +209,10 @@ function convertRecordLikeNodeSchema(
schema: SimpleRecordNodeSchema | SimpleMapNodeSchema,
): JsonMapNodeSchema | JsonRecordNodeSchema {
const allowedTypes: JsonSchemaRef[] = [];
schema.allowedTypesIdentifiers.forEach((type) => {
const allowedTypesIdentifiers: ReadonlySet<string> = new Set(
schema.simpleAllowedTypes.keys(),
);
allowedTypesIdentifiers.forEach((type) => {
allowedTypes.push(createSchemaRef(type));
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function toSimpleTreeSchema(
return {
root: copySchemaObjects
? ({
allowedTypesIdentifiers: normalizedSchema.allowedTypesIdentifiers,
simpleAllowedTypes: normalizedSchema.simpleAllowedTypes,
kind: normalizedSchema.kind,
metadata: normalizedSchema.metadata,
persistedMetadata: normalizedSchema.persistedMetadata,
Expand Down Expand Up @@ -112,7 +112,7 @@ function copySimpleSchemaWithAllowedTypes(
): SimpleMapNodeSchema | SimpleArrayNodeSchema | SimpleRecordNodeSchema {
return {
kind: schema.kind,
allowedTypesIdentifiers: schema.allowedTypesIdentifiers,
simpleAllowedTypes: schema.simpleAllowedTypes,
metadata: schema.metadata,
persistedMetadata: schema.persistedMetadata,
};
Expand All @@ -124,7 +124,7 @@ function copySimpleObjectSchema(schema: SimpleObjectNodeSchema): SimpleObjectNod
// field already is a SimpleObjectFieldSchema, but copy the subset of the properties needed by this interface to get a clean simple object.
fields.set(propertyKey, {
kind: field.kind,
allowedTypesIdentifiers: field.allowedTypesIdentifiers,
simpleAllowedTypes: field.simpleAllowedTypes,
metadata: field.metadata,
persistedMetadata: field.persistedMetadata,
storedKey: field.storedKey,
Expand Down
15 changes: 14 additions & 1 deletion packages/dds/tree/src/simple-tree/fieldSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import type {
} from "./core/index.js";
import { normalizeAllowedTypes } from "./core/index.js";

import type { SimpleFieldSchema } from "./simpleSchema.js";
import type { SimpleAllowedTypes, SimpleFieldSchema } from "./simpleSchema.js";
import type { UnsafeUnknownSchema } from "./unsafeUnknownSchema.js";
import type { InsertableContent } from "./unhydratedFlexTreeFromInsertable.js";

Expand Down Expand Up @@ -412,6 +412,19 @@ export class FieldSchemaAlpha<
return this.allowedTypesFull.evaluateIdentifiers();
}

public get simpleAllowedTypes(): Map<string, SimpleAllowedTypes> {
const types = this.allowedTypesFull.evaluate().types;
const info = new Map<string, SimpleAllowedTypes>();

for (const type of types) {
info.set(type.type.identifier, {
isStaged: type.metadata.stagedSchemaUpgrade !== undefined,
});
}

return info;
}

protected constructor(
kind: Kind,
types: Types,
Expand Down
1 change: 1 addition & 0 deletions packages/dds/tree/src/simple-tree/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export type {
SimpleNodeSchemaBaseAlpha,
SimpleObjectFieldSchema,
SimpleRecordNodeSchema,
SimpleAllowedTypes as AllowedTypeInfo,
} from "./simpleSchema.js";
export {
type ImplicitFieldSchema,
Expand Down
14 changes: 14 additions & 0 deletions packages/dds/tree/src/simple-tree/node-kinds/array/arrayNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import type {
import { brand, type JsonCompatibleReadOnlyObject } from "../../../util/index.js";
import { nullSchema } from "../../leafNodeSchema.js";
import { arrayNodeStoredSchema } from "../../toStoredSchema.js";
import type { SimpleAllowedTypes } from "../../simpleSchema.js";

/**
* A covariant base type for {@link (TreeArrayNode:interface)}.
Expand Down Expand Up @@ -1168,6 +1169,15 @@ export function arraySchema<
const lazyAllowedTypesIdentifiers = new Lazy(
() => new Set(normalizedTypes.evaluate().map((type) => type.identifier)),
);
const lazySimpleAllowedTypes = new Lazy(() => {
const map = new Map<string, SimpleAllowedTypes>();
for (const type of normalizedTypes.evaluate()) {
map.set(type.identifier, {
isStaged: false,
});
}
return map;
});

let privateData: TreeNodeSchemaPrivateData | undefined;

Expand Down Expand Up @@ -1206,6 +1216,10 @@ export function arraySchema<
return lazyAllowedTypesIdentifiers.value;
}

public static get simpleAllowedTypes(): ReadonlyMap<string, SimpleAllowedTypes> {
return lazySimpleAllowedTypes.value;
}

protected static override constructorCached: MostDerivedData | undefined = undefined;

protected static override oneTimeSetup(): TreeNodeSchemaInitializedData {
Expand Down
14 changes: 14 additions & 0 deletions packages/dds/tree/src/simple-tree/node-kinds/map/mapNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import type {
import { recordLikeDataToFlexContent } from "../common.js";
import { MapNodeStoredSchema } from "../../../core/index.js";
import type { NodeSchemaOptionsAlpha } from "../../api/index.js";
import type { SimpleAllowedTypes } from "../../simpleSchema.js";

/**
* A map of string keys to tree objects.
Expand Down Expand Up @@ -275,6 +276,15 @@ export function mapSchema<
const lazyAllowedTypesIdentifiers = new Lazy(
() => new Set(normalizedTypes.evaluate().map((type) => type.identifier)),
);
const lazySimpleAllowedTypes = new Lazy(() => {
const map = new Map<string, SimpleAllowedTypes>();
for (const type of normalizedTypes.evaluate()) {
map.set(type.identifier, {
isStaged: false,
});
}
return map;
});

let privateData: TreeNodeSchemaPrivateData | undefined;
const persistedMetadata = nodeOptions.persistedMetadata;
Expand Down Expand Up @@ -303,6 +313,10 @@ export function mapSchema<
return lazyAllowedTypesIdentifiers.value;
}

public static get simpleAllowedTypes(): ReadonlyMap<string, SimpleAllowedTypes> {
return lazySimpleAllowedTypes.value;
}

protected static override constructorCached: MostDerivedData | undefined = undefined;

protected static override oneTimeSetup(): TreeNodeSchemaInitializedData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import { prepareForInsertion } from "../../prepareForInsertion.js";
import { recordLikeDataToFlexContent } from "../common.js";
import { MapNodeStoredSchema } from "../../../core/index.js";
import type { NodeSchemaOptionsAlpha } from "../../api/index.js";
import type { SimpleAllowedTypes } from "../../simpleSchema.js";

/**
* Create a proxy which implements the {@link TreeRecordNode} API.
Expand Down Expand Up @@ -258,6 +259,15 @@ export function recordSchema<
const lazyAllowedTypesIdentifiers = new Lazy(
() => new Set(normalizedTypes.evaluate().map((type) => type.identifier)),
);
const lazySimpleAllowedTypes = new Lazy(() => {
const map = new Map<string, SimpleAllowedTypes>();
for (const type of normalizedTypes.evaluate()) {
map.set(type.identifier, {
isStaged: false,
});
}
return map;
});

let privateData: TreeNodeSchemaPrivateData | undefined;

Expand Down Expand Up @@ -347,6 +357,10 @@ export function recordSchema<
return lazyAllowedTypesIdentifiers.value;
}

public static get simpleAllowedTypes(): ReadonlyMap<string, SimpleAllowedTypes> {
return lazySimpleAllowedTypes.value;
}

protected static override constructorCached: MostDerivedData | undefined = undefined;

public static readonly identifier = identifier;
Expand Down
Loading