Skip to content

Commit

Permalink
tree: Remove getFlexSchema (microsoft#22649)
Browse files Browse the repository at this point in the history
## Description

Remove use of getFlexSchema as part of removing flex tree schema.
  • Loading branch information
CraigMacomber authored Sep 26, 2024
1 parent 5c700c6 commit 5575b1e
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 109 deletions.
2 changes: 1 addition & 1 deletion packages/dds/tree/src/simple-tree/api/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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() },
);
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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";
Expand All @@ -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");
Expand Down Expand Up @@ -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)]]),
};

/**
Expand All @@ -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", () => {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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
Expand All @@ -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 = {
Expand All @@ -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]],
Expand Down Expand Up @@ -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,
Expand Down
62 changes: 43 additions & 19 deletions packages/dds/tree/src/test/testTrees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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) {}
Expand All @@ -134,10 +152,12 @@ export class RecursiveType extends factory.objectRecursive("recursiveType", {
type _check = ValidateRecursiveSchema<typeof RecursiveType>;
}

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<TreeStoredSchema>;
Expand All @@ -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])),
),
Expand Down Expand Up @@ -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 }] },
},
],
Expand All @@ -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 }],
Expand Down

0 comments on commit 5575b1e

Please sign in to comment.