diff --git a/packages/dds/tree/src/simple-tree/api/view.ts b/packages/dds/tree/src/simple-tree/api/view.ts index 9f721df3b024..108066ef76d5 100644 --- a/packages/dds/tree/src/simple-tree/api/view.ts +++ b/packages/dds/tree/src/simple-tree/api/view.ts @@ -98,7 +98,7 @@ export class ViewSchema { */ public adaptRepo(stored: TreeStoredSchema): AdaptedViewSchema { // Sanity check on adapters: - // it's probably a bug it they use the never types, + // it's probably a bug if they use the never types, // since there never is a reason to have a never type as an adapter input, // and its impossible for an adapter to be correctly implemented if its output type is never // (unless its input is also never). diff --git a/packages/dds/tree/src/test/feature-libraries/chunked-forest/codec/schemaBasedEncoding.spec.ts b/packages/dds/tree/src/test/feature-libraries/chunked-forest/codec/schemaBasedEncoding.spec.ts index 6e4c6a6b7ff1..6981531808ce 100644 --- a/packages/dds/tree/src/test/feature-libraries/chunked-forest/codec/schemaBasedEncoding.spec.ts +++ b/packages/dds/tree/src/test/feature-libraries/chunked-forest/codec/schemaBasedEncoding.spec.ts @@ -36,7 +36,6 @@ import { // eslint-disable-next-line import/no-internal-modules import { FieldKinds, fieldKinds } from "../../../../feature-libraries/default-schema/index.js"; import { - FlexFieldSchema, TreeCompressionStrategy, cursorForJsonableTreeField, defaultSchemaPolicy, @@ -60,7 +59,6 @@ import { assertIsSessionId, testIdCompressor } from "../../../utils.js"; import { SpecialField } from "../../../../feature-libraries/chunked-forest/codec/format.js"; import { createIdCompressor } from "@fluidframework/id-compressor/internal"; import { - getFlexSchema, getStoredSchema, toStoredSchema, // eslint-disable-next-line import/no-internal-modules @@ -154,7 +152,7 @@ describe("schemaBasedEncoding", () => { return onlyTypeShape; }, }, - FlexFieldSchema.create(FieldKinds.sequence, [getFlexSchema(Minimal)]).stored, + { kind: FieldKinds.sequence.identifier, types: new Set([brand(Minimal.identifier)]) }, cache, { nodeSchema: new Map() }, ); @@ -181,10 +179,11 @@ describe("schemaBasedEncoding", () => { testIdCompressor, ); const log: string[] = []; - const identifierField = FlexFieldSchema.create(FieldKinds.identifier, [ - getFlexSchema(stringSchema), - ]); - const storedSchema = identifierField.stored; + const storedSchema: TreeFieldStoredSchema = { + kind: FieldKinds.identifier.identifier, + types: new Set([brand(stringSchema.identifier)]), + }; + const shape = fieldShaper( { shapeFromTree(schemaName: TreeNodeSchemaIdentifier): NodeEncoder { diff --git a/packages/dds/tree/src/test/feature-libraries/flex-tree/lazyField.spec.ts b/packages/dds/tree/src/test/feature-libraries/flex-tree/lazyField.spec.ts index 4154322969ad..8c939c58712d 100644 --- a/packages/dds/tree/src/test/feature-libraries/flex-tree/lazyField.spec.ts +++ b/packages/dds/tree/src/test/feature-libraries/flex-tree/lazyField.spec.ts @@ -12,6 +12,8 @@ import { validateAssertionError } from "@fluidframework/test-runtime-utils/inter import { type FieldAnchor, type FieldKey, + type TreeFieldStoredSchema, + type TreeStoredSchema, TreeStoredSchemaRepository, type UpPath, rootFieldKey, @@ -25,14 +27,11 @@ import { } from "../../../feature-libraries/flex-tree/lazyField.js"; import { FieldKinds, - FlexFieldSchema, MockNodeKeyManager, cursorForJsonableTreeNode, defaultSchemaPolicy, getTreeContext, - intoStoredSchema, mapTreeFromCursor, - type FlexTreeSchema, } from "../../../feature-libraries/index.js"; import { brand, disposeSymbol } from "../../../util/index.js"; import { flexTreeViewWithContent, forestWithContent, MockTreeCheckout } from "../../utils.js"; @@ -49,7 +48,7 @@ import { SchemaFactory, stringSchema, } from "../../../simple-tree/index.js"; -import { getFlexSchema, toStoredSchema } from "../../../simple-tree/toFlexSchema.js"; +import { getStoredSchema, toStoredSchema } from "../../../simple-tree/toFlexSchema.js"; import { JsonObject, singleJsonCursor } from "../../json/index.js"; const detachedField: FieldKey = brand("detached"); @@ -377,14 +376,13 @@ describe("LazyValueField", () => { }); describe("LazySequence", () => { - const rootSchema = FlexFieldSchema.create(FieldKinds.sequence, [ - getFlexSchema(numberSchema), - ]); - const schema: FlexTreeSchema = { + const rootSchema: TreeFieldStoredSchema = { + kind: FieldKinds.sequence.identifier, + types: new Set([brand(numberSchema.identifier)]), + }; + const schema: TreeStoredSchema = { rootFieldSchema: rootSchema, - nodeSchema: new Map([[brand(numberSchema.identifier), getFlexSchema(numberSchema)]]), - policy: defaultSchemaPolicy, - adapters: {}, + nodeSchema: new Map([[brand(numberSchema.identifier), getStoredSchema(numberSchema)]]), }; /** @@ -393,19 +391,19 @@ describe("LazySequence", () => { function testSequence(data: number[]) { const content = data.map((n) => singleJsonCursor(n)); const forest = forestWithContent({ - schema: intoStoredSchema(schema), + schema, initialTree: content, }); const context = getTreeContext( - schema.policy, + defaultSchemaPolicy, new MockTreeCheckout(forest, { - schema: new TreeStoredSchemaRepository(intoStoredSchema(schema)), + schema: new TreeStoredSchemaRepository(schema), }), new MockNodeKeyManager(), ); const cursor = initializeCursor(context, rootFieldAnchor); - return new LazySequence(context, rootSchema.stored.kind, cursor, rootFieldAnchor); + return new LazySequence(context, rootSchema.kind, cursor, rootFieldAnchor); } it("atIndex", () => { diff --git a/packages/dds/tree/src/test/feature-libraries/typedSchema/typedTreeSchema.spec.ts b/packages/dds/tree/src/test/feature-libraries/typedSchema/typedTreeSchema.spec.ts deleted file mode 100644 index aa3ecde4426f..000000000000 --- a/packages/dds/tree/src/test/feature-libraries/typedSchema/typedTreeSchema.spec.ts +++ /dev/null @@ -1,57 +0,0 @@ -/*! - * Copyright (c) Microsoft Corporation and contributors. All rights reserved. - * Licensed under the MIT License. - */ - -import { strict as assert } from "assert"; - -import { FieldKinds } from "../../../feature-libraries/index.js"; -import { - FlexFieldSchema, - schemaIsLeaf, - // eslint-disable-next-line import/no-internal-modules -} from "../../../feature-libraries/typed-schema/typedTreeSchema.js"; - -import { - SchemaFactory, - booleanSchema, - getFlexSchema, - numberSchema, -} from "../../../simple-tree/index.js"; - -describe("typedTreeSchema", () => { - const builder = new SchemaFactory("test"); - const emptyObjectSchema = getFlexSchema(builder.object("empty", {})); - const basicObjectSchema = getFlexSchema( - builder.object("basicObject", { foo: builder.number }), - ); - - const recursiveObject = builder.objectRecursive("recursiveObject", { - foo: builder.optionalRecursive([() => recursiveObject]), - }); - - it("schemaIsLeaf", () => { - assert(schemaIsLeaf(getFlexSchema(booleanSchema))); - assert(!schemaIsLeaf(emptyObjectSchema)); - assert(!schemaIsLeaf(basicObjectSchema)); - }); - - describe("TreeFieldSchema", () => { - it("types - single", () => { - const schema = FlexFieldSchema.create(FieldKinds.optional, [ - getFlexSchema(numberSchema), - ]); - assert.deepEqual(schema.allowedTypes, [getFlexSchema(numberSchema)]); - assert.deepEqual(schema.allowedTypeSet, new Set([getFlexSchema(numberSchema)])); - assert.deepEqual(schema.types, new Set([numberSchema.identifier])); - }); - - it("types - lazy", () => { - const schema = FlexFieldSchema.create(FieldKinds.optional, [ - () => getFlexSchema(numberSchema), - ]); - assert.deepEqual(schema.allowedTypeSet, new Set([getFlexSchema(numberSchema)])); - assert.deepEqual(schema.types, new Set([numberSchema.identifier])); - }); - }); -}); diff --git a/packages/dds/tree/src/test/simple-tree/core/unhydratedFlexTree.spec.ts b/packages/dds/tree/src/test/simple-tree/core/unhydratedFlexTree.spec.ts index 5bdbbef45045..a8413d988036 100644 --- a/packages/dds/tree/src/test/simple-tree/core/unhydratedFlexTree.spec.ts +++ b/packages/dds/tree/src/test/simple-tree/core/unhydratedFlexTree.spec.ts @@ -17,7 +17,7 @@ import { UnhydratedFlexTreeNode, // eslint-disable-next-line import/no-internal-modules } from "../../../simple-tree/core/unhydratedFlexTree.js"; -import { getFlexSchema, SchemaFactory, stringSchema } from "../../../simple-tree/index.js"; +import { SchemaFactory, stringSchema } from "../../../simple-tree/index.js"; // eslint-disable-next-line import/no-internal-modules import { getUnhydratedContext } from "../../../simple-tree/createContext.js"; @@ -34,9 +34,6 @@ describe("unhydratedFlexTree", () => { [objectFieldNodeKey]: arrayNodeSchemaSimple, }); - const mapSchema = getFlexSchema(mapSchemaSimple); - const arrayNodeSchema = getFlexSchema(arrayNodeSchemaSimple); - const objectSchema = getFlexSchema(objectSchemaSimple); // #endregion // #region The `MapTree`s used to construct the `MapTreeNode`s @@ -48,7 +45,7 @@ describe("unhydratedFlexTree", () => { }; const mapKey = "key" as FieldKey; const mapMapTree: ExclusiveMapTree = { - type: mapSchema.name, + type: brand(mapSchemaSimple.identifier), fields: new Map([[mapKey, [mapChildMapTree]]]), }; const fieldNodeChildMapTree: ExclusiveMapTree = { @@ -57,11 +54,11 @@ describe("unhydratedFlexTree", () => { fields: new Map(), }; const fieldNodeMapTree: ExclusiveMapTree = { - type: arrayNodeSchema.name, + type: brand(arrayNodeSchemaSimple.identifier), fields: new Map([[EmptyKey, [fieldNodeChildMapTree]]]), }; const objectMapTree: ExclusiveMapTree = { - type: objectSchema.name, + type: brand(objectSchemaSimple.identifier), fields: new Map([ [objectMapKey, [mapMapTree]], [objectFieldNodeKey, [fieldNodeMapTree]], @@ -100,9 +97,9 @@ describe("unhydratedFlexTree", () => { }); it("can get their schema", () => { - assert.equal(map.schema, mapSchema.name); - assert.equal(arrayNode.schema, arrayNodeSchema.name); - assert.equal(object.schema, objectSchema.name); + assert.equal(map.schema, mapSchemaSimple.identifier); + assert.equal(arrayNode.schema, arrayNodeSchemaSimple.identifier); + assert.equal(object.schema, objectSchemaSimple.identifier); assert.equal(map.tryGetField(mapKey)?.boxedAt(0)?.schema, schemaFactory.string.identifier); assert.equal( arrayNode.tryGetField(EmptyKey)?.boxedAt(0)?.schema, diff --git a/packages/dds/tree/src/test/testTrees.ts b/packages/dds/tree/src/test/testTrees.ts index 4630e5ea63ae..b7f6c1f9e8fe 100644 --- a/packages/dds/tree/src/test/testTrees.ts +++ b/packages/dds/tree/src/test/testTrees.ts @@ -11,13 +11,14 @@ import { type ITreeCursorSynchronous, type JsonableTree, Multiplicity, + ObjectNodeStoredSchema, + type TreeNodeSchemaIdentifier, type TreeStoredSchema, + type TreeTypeSet, } from "../core/index.js"; import { FieldKinds, type FlexFieldKind, - FlexFieldSchema, - FlexObjectNodeSchema, type FullSchemaPolicy, cursorForJsonableTreeNode, defaultSchemaPolicy, @@ -28,7 +29,6 @@ import type { TreeStoredContent } from "../shared-tree/index.js"; import type { IIdCompressor } from "@fluidframework/id-compressor"; import { cursorFromInsertable, - getFlexSchema, getStoredSchema, numberSchema, SchemaFactory, @@ -115,14 +115,32 @@ export class HasOptionalField extends factory.object("hasOptionalField", { export class HasIdentifierField extends factory.object("hasIdentifierField", { field: factory.identifier, }) {} -export const allTheFields = FlexObjectNodeSchema.create( - { name: "test" }, - brand("test.allTheFields"), - { - optional: FlexFieldSchema.create(FieldKinds.optional, [getFlexSchema(numberSchema)]), - valueField: FlexFieldSchema.create(FieldKinds.required, [getFlexSchema(numberSchema)]), - sequence: FlexFieldSchema.create(FieldKinds.sequence, [getFlexSchema(numberSchema)]), - }, + +const numberSet: TreeTypeSet = new Set([brand(numberSchema.identifier)]); +export const allTheFields = new ObjectNodeStoredSchema( + new Map([ + [ + brand("optional"), + { + kind: FieldKinds.optional.identifier, + types: numberSet, + }, + ], + [ + brand("valueField"), + { + kind: FieldKinds.required.identifier, + types: numberSet, + }, + ], + [ + brand("sequence"), + { + kind: FieldKinds.sequence.identifier, + types: numberSet, + }, + ], + ]), ); export class NumericMap extends factory.map("numericMap", factory.number) {} @@ -134,10 +152,12 @@ export class RecursiveType extends factory.objectRecursive("recursiveType", { type _check = ValidateRecursiveSchema; } +const allTheFieldsName: TreeNodeSchemaIdentifier = brand("test.allTheFields"); + const library = { nodeSchema: new Map([ [brand(Minimal.identifier), getStoredSchema(Minimal)], - [allTheFields.name, allTheFields.stored], + [allTheFieldsName, allTheFields], [brand(factory.number.identifier), getStoredSchema(factory.number)], ]), } satisfies Partial; @@ -152,9 +172,7 @@ export const testTrees: readonly TestTree[] = [ "numericSequence", { ...toStoredSchema(factory.number), - rootFieldSchema: FlexFieldSchema.create(FieldKinds.sequence, [ - getFlexSchema(numberSchema), - ]).stored, + rootFieldSchema: { kind: FieldKinds.sequence.identifier, types: numberSet }, }, jsonableTreesFromFieldCursor(fieldJsonCursor([1, 2, 3])), ), @@ -188,11 +206,14 @@ export const testTrees: readonly TestTree[] = [ "allTheFields-minimal", { ...library, - rootFieldSchema: FlexFieldSchema.create(FieldKinds.required, [allTheFields]).stored, + rootFieldSchema: { + kind: FieldKinds.required.identifier, + types: new Set([allTheFieldsName]), + }, }, [ { - type: allTheFields.name, + type: allTheFieldsName, fields: { valueField: [{ type: brand(numberSchema.identifier), value: 5 }] }, }, ], @@ -201,11 +222,14 @@ export const testTrees: readonly TestTree[] = [ "allTheFields-full", { ...library, - rootFieldSchema: FlexFieldSchema.create(FieldKinds.required, [allTheFields]).stored, + rootFieldSchema: { + kind: FieldKinds.required.identifier, + types: new Set([allTheFieldsName]), + }, }, [ { - type: allTheFields.name, + type: allTheFieldsName, fields: { valueField: [{ type: brand(numberSchema.identifier), value: 5 }], optional: [{ type: brand(numberSchema.identifier), value: 5 }],