diff --git a/packages/dds/tree/api-report/tree.alpha.api.md b/packages/dds/tree/api-report/tree.alpha.api.md index 631f9024d991..3304fa01c095 100644 --- a/packages/dds/tree/api-report/tree.alpha.api.md +++ b/packages/dds/tree/api-report/tree.alpha.api.md @@ -169,6 +169,9 @@ export type ConciseTree = Exclude; }; +// @alpha +export function configuredSharedTreeAlpha(options: SharedTreeOptions): SharedObjectKind; + // @beta export function configuredSharedTreeBeta(options: SharedTreeOptionsBeta): SharedObjectKind; @@ -427,6 +430,15 @@ export type ImplicitFieldSchema = FieldSchema | ImplicitAllowedTypes; // @alpha export function importCompatibilitySchemaSnapshot(config: JsonCompatibleReadOnly): TreeViewConfiguration; +// @alpha +export type IncrementalEncodingPolicy = (nodeIdentifier: string | undefined, fieldKey: string) => boolean; + +// @alpha +export function incrementalEncodingPolicyForAllowedTypes(rootSchema: TreeSchema): IncrementalEncodingPolicy; + +// @alpha +export const incrementalSummaryHint: unique symbol; + // @alpha export function independentInitializedView(config: TreeViewConfiguration, options: ForestOptions & ICodecOptions, content: ViewContent): TreeViewAlpha; @@ -1022,8 +1034,9 @@ export interface SharedTreeFormatOptions { } // @alpha @input -export interface SharedTreeOptions extends Partial, Partial, SharedTreeOptionsBeta { +export interface SharedTreeOptions extends SharedTreeOptionsBeta, Partial, Partial { readonly enableSharedBranches?: boolean; + shouldEncodeIncrementally?: IncrementalEncodingPolicy; } // @beta @input @@ -1475,6 +1488,7 @@ export interface TreeChangeEventsBeta extends // @alpha export enum TreeCompressionStrategy { Compressed = 0, + CompressedIncremental = 2, Uncompressed = 1 } diff --git a/packages/dds/tree/src/feature-libraries/chunked-forest/codec/codecs.ts b/packages/dds/tree/src/feature-libraries/chunked-forest/codec/codecs.ts index cc9e4a561787..893e9adb8eab 100644 --- a/packages/dds/tree/src/feature-libraries/chunked-forest/codec/codecs.ts +++ b/packages/dds/tree/src/feature-libraries/chunked-forest/codec/codecs.ts @@ -29,11 +29,7 @@ import { type Brand, type JsonCompatibleReadOnly, } from "../../../util/index.js"; -import { - TreeCompressionStrategy, - TreeCompressionStrategyExtended, - type TreeCompressionStrategyPrivate, -} from "../../treeCompressionUtils.js"; +import { TreeCompressionStrategy } from "../../treeCompressionUtils.js"; import { decode } from "./chunkDecoding.js"; import type { FieldBatch } from "./fieldBatch.js"; @@ -109,7 +105,7 @@ export interface IncrementalDecoder { export interface IncrementalEncoderDecoder extends IncrementalEncoder, IncrementalDecoder {} export interface FieldBatchEncodingContext { - readonly encodeType: TreeCompressionStrategyPrivate; + readonly encodeType: TreeCompressionStrategy; readonly idCompressor: IIdCompressor; readonly originatorId: SessionId; readonly schema?: SchemaAndPolicy; @@ -190,7 +186,7 @@ export function makeFieldBatchCodec(options: CodecWriteOptions): FieldBatchCodec case TreeCompressionStrategy.Uncompressed: encoded = uncompressedEncodeFn(data); break; - case TreeCompressionStrategyExtended.CompressedIncremental: + case TreeCompressionStrategy.CompressedIncremental: assert( writeVersion >= FieldBatchFormatVersion.v2, "Unsupported FieldBatchFormatVersion for incremental encoding; must be v2 or higher", diff --git a/packages/dds/tree/src/feature-libraries/chunked-forest/codec/incrementalEncodingPolicy.ts b/packages/dds/tree/src/feature-libraries/chunked-forest/codec/incrementalEncodingPolicy.ts index d35f9a6cf89e..0f7868f278b8 100644 --- a/packages/dds/tree/src/feature-libraries/chunked-forest/codec/incrementalEncodingPolicy.ts +++ b/packages/dds/tree/src/feature-libraries/chunked-forest/codec/incrementalEncodingPolicy.ts @@ -3,8 +3,6 @@ * Licensed under the MIT License. */ -import type { FieldKey, TreeNodeSchemaIdentifier } from "../../../core/index.js"; - /** * Policy to determine whether a node / field should be incrementally encoded. * @param nodeIdentifier - The identifier of the node containing the field. @@ -16,18 +14,19 @@ import type { FieldKey, TreeNodeSchemaIdentifier } from "../../../core/index.js" * but allows reuse of previously encoded unchanged subtrees. * Thus it should only be enabled for large subtrees which are modified infrequently. * TODO: AB#9068: Measure the actual overhead. + * @alpha */ export type IncrementalEncodingPolicy = ( - nodeIdentifier: TreeNodeSchemaIdentifier | undefined, - fieldKey: FieldKey, + nodeIdentifier: string | undefined, + fieldKey: string, ) => boolean; /** * Default policy for incremental encoding is to not encode incrementally. */ export const defaultIncrementalEncodingPolicy: IncrementalEncodingPolicy = ( - nodeIdentifier: TreeNodeSchemaIdentifier | undefined, - fieldKey: FieldKey, + nodeIdentifier: string | undefined, + fieldKey: string, ): boolean => { return false; }; diff --git a/packages/dds/tree/src/feature-libraries/forest-summary/forestSummarizer.ts b/packages/dds/tree/src/feature-libraries/forest-summary/forestSummarizer.ts index 4b43114baa1c..37fc433e6a0e 100644 --- a/packages/dds/tree/src/feature-libraries/forest-summary/forestSummarizer.ts +++ b/packages/dds/tree/src/feature-libraries/forest-summary/forestSummarizer.ts @@ -48,7 +48,7 @@ import { ForestIncrementalSummaryBuilder, forestSummaryContentKey, } from "./incrementalSummaryBuilder.js"; -import { TreeCompressionStrategyExtended } from "../treeCompressionUtils.js"; +import { TreeCompressionStrategy } from "../treeCompressionUtils.js"; import type { IFluidHandle } from "@fluidframework/core-interfaces"; /** @@ -85,7 +85,7 @@ export class ForestSummarizer implements Summarizable { this.codec = makeForestSummarizerCodec(options, fieldBatchCodec); this.incrementalSummaryBuilder = new ForestIncrementalSummaryBuilder( encoderContext.encodeType === - TreeCompressionStrategyExtended.CompressedIncremental /* enableIncrementalSummary */, + TreeCompressionStrategy.CompressedIncremental /* enableIncrementalSummary */, (cursor: ITreeCursorSynchronous) => this.forest.chunkField(cursor), shouldEncodeIncrementally, initialSequenceNumber, diff --git a/packages/dds/tree/src/feature-libraries/index.ts b/packages/dds/tree/src/feature-libraries/index.ts index 5ee1b64be3fc..45b3b6769a58 100644 --- a/packages/dds/tree/src/feature-libraries/index.ts +++ b/packages/dds/tree/src/feature-libraries/index.ts @@ -190,11 +190,7 @@ export { type Observer, } from "./flex-tree/index.js"; -export { - TreeCompressionStrategy, - TreeCompressionStrategyExtended, - type TreeCompressionStrategyPrivate, -} from "./treeCompressionUtils.js"; +export { TreeCompressionStrategy } from "./treeCompressionUtils.js"; export { valueSchemaAllows } from "./valueUtilities.js"; diff --git a/packages/dds/tree/src/feature-libraries/modular-schema/modularChangeCodecs.ts b/packages/dds/tree/src/feature-libraries/modular-schema/modularChangeCodecs.ts index 5fed33e1e7cf..a3a908b62bd5 100644 --- a/packages/dds/tree/src/feature-libraries/modular-schema/modularChangeCodecs.ts +++ b/packages/dds/tree/src/feature-libraries/modular-schema/modularChangeCodecs.ts @@ -40,10 +40,7 @@ import { chunkFieldSingle, defaultChunkPolicy, } from "../chunked-forest/index.js"; -import { - TreeCompressionStrategy, - type TreeCompressionStrategyPrivate, -} from "../treeCompressionUtils.js"; +import { TreeCompressionStrategy } from "../treeCompressionUtils.js"; import type { FieldChangeEncodingContext, FieldChangeHandler } from "./fieldChangeHandler.js"; import type { @@ -81,7 +78,7 @@ export function makeModularChangeCodecFamily( >, fieldsCodec: FieldBatchCodec, codecOptions: ICodecOptions, - chunkCompressionStrategy: TreeCompressionStrategyPrivate = TreeCompressionStrategy.Compressed, + chunkCompressionStrategy: TreeCompressionStrategy = TreeCompressionStrategy.Compressed, ): ICodecFamily { return makeCodecFamily( Array.from(fieldKindConfigurations.entries(), ([version, fieldKinds]) => [ @@ -121,7 +118,7 @@ function makeModularChangeCodec( >, fieldsCodec: FieldBatchCodec, codecOptions: ICodecOptions, - chunkCompressionStrategy: TreeCompressionStrategyPrivate = TreeCompressionStrategy.Compressed, + chunkCompressionStrategy: TreeCompressionStrategy = TreeCompressionStrategy.Compressed, ): ModularChangeCodec { // eslint-disable-next-line @typescript-eslint/explicit-function-return-type const getMapEntry = ({ kind, formatVersion }: FieldKindConfigurationEntry) => { diff --git a/packages/dds/tree/src/feature-libraries/treeCompressionUtils.ts b/packages/dds/tree/src/feature-libraries/treeCompressionUtils.ts index 57983caff7a6..9da3863deae5 100644 --- a/packages/dds/tree/src/feature-libraries/treeCompressionUtils.ts +++ b/packages/dds/tree/src/feature-libraries/treeCompressionUtils.ts @@ -20,23 +20,9 @@ export enum TreeCompressionStrategy { * Use this when debugging or testing and needing to inspect encoded tree content. */ Uncompressed = 1, -} - -/** - * A private extension of {@link TreeCompressionStrategy} for strategies that are not intended for public use just yet. - */ -export enum TreeCompressionStrategyExtended { /** - * Optimized for encoded size, same as TreeCompressionStrategy.Compressed. It also enables incremental encoding + * Optimized for encoded size, same as TreeCompressionStrategy.Compressed but it enables incremental encoding * of the data. - * @remarks - * TODO: AB#41865 - * This needs to be stabilized to allow opting into it. - * It could possibly be made the default instead of {@link TreeCompressionStrategy.Compressed}. */ CompressedIncremental = 2, } - -export type TreeCompressionStrategyPrivate = - | TreeCompressionStrategy - | TreeCompressionStrategyExtended; diff --git a/packages/dds/tree/src/index.ts b/packages/dds/tree/src/index.ts index 4df49147e71b..48af3a1e5104 100644 --- a/packages/dds/tree/src/index.ts +++ b/packages/dds/tree/src/index.ts @@ -52,6 +52,7 @@ export { type TreeIndex, type TreeIndexKey, type TreeIndexNodes, + type IncrementalEncodingPolicy, } from "./feature-libraries/index.js"; export { @@ -287,10 +288,13 @@ export { exportCompatibilitySchemaSnapshot, importCompatibilitySchemaSnapshot, checkCompatibility, + incrementalSummaryHint, + incrementalEncodingPolicyForAllowedTypes, } from "./simple-tree/index.js"; export { SharedTree, configuredSharedTree, + configuredSharedTreeAlpha, configuredSharedTreeBeta, configuredSharedTreeBetaLegacy, } from "./treeFactory.js"; diff --git a/packages/dds/tree/src/shared-tree-core/index.ts b/packages/dds/tree/src/shared-tree-core/index.ts index 03eeb63bdc97..fa51e900b0df 100644 --- a/packages/dds/tree/src/shared-tree-core/index.ts +++ b/packages/dds/tree/src/shared-tree-core/index.ts @@ -27,7 +27,7 @@ export { type SummaryElementParser, type SummaryElementStringifier, type ClonableSchemaAndPolicy, - type SharedTreeCoreOptionsInternal as SharedTreCoreOptionsInternal, + type SharedTreeCoreOptionsInternal, } from "./sharedTreeCore.js"; export type { ResubmitMachine } from "./resubmitMachine.js"; diff --git a/packages/dds/tree/src/shared-tree/sharedTree.ts b/packages/dds/tree/src/shared-tree/sharedTree.ts index 46855153d444..251bfe6e773d 100644 --- a/packages/dds/tree/src/shared-tree/sharedTree.ts +++ b/packages/dds/tree/src/shared-tree/sharedTree.ts @@ -64,7 +64,6 @@ import { makeSchemaCodec, makeTreeChunker, type IncrementalEncodingPolicy, - type TreeCompressionStrategyPrivate, } from "../feature-libraries/index.js"; // eslint-disable-next-line import-x/no-internal-modules import type { FormatV1 } from "../feature-libraries/schema-index/index.js"; @@ -75,7 +74,7 @@ import { type ClonableSchemaAndPolicy, getCodecTreeForEditManagerFormatWithChange, getCodecTreeForMessageFormatWithChange, - type SharedTreCoreOptionsInternal, + type SharedTreeCoreOptionsInternal, MessageFormatVersion, SharedTreeCore, EditManagerFormatVersion, @@ -656,26 +655,19 @@ export function getCodecTreeForSharedTreeFormat( export type SharedTreeOptionsBeta = ForestOptions; /** - * Configuration options for SharedTree. + * Configuration options for SharedTree with alpha features. * @alpha @input */ export interface SharedTreeOptions - extends Partial, - Partial, - SharedTreeOptionsBeta { + extends SharedTreeOptionsBeta, + Partial, + Partial { /** * Experimental feature flag to enable shared branches. * This feature is not yet complete and should not be used in production. * Defaults to false. */ readonly enableSharedBranches?: boolean; -} - -export interface SharedTreeOptionsInternal - extends Partial, - Partial, - Partial { - disposeForksAfterTransaction?: boolean; /** * Returns whether a node / field should be incrementally encoded. * @remarks @@ -684,6 +676,12 @@ export interface SharedTreeOptionsInternal shouldEncodeIncrementally?: IncrementalEncodingPolicy; } +export interface SharedTreeOptionsInternal + extends SharedTreeOptions, + Partial { + disposeForksAfterTransaction?: boolean; +} + /** * Configuration options for SharedTree's internal tree storage. * @beta @input @@ -707,11 +705,6 @@ export interface SharedTreeFormatOptions { treeEncodeType: TreeCompressionStrategy; } -export interface SharedTreeFormatOptionsInternal - extends Omit { - treeEncodeType: TreeCompressionStrategyPrivate; -} - /** * Used to distinguish between different forest types. * @remarks @@ -814,6 +807,7 @@ export const defaultSharedTreeOptions: Required = { shouldEncodeIncrementally: defaultIncrementalEncodingPolicy, editManagerFormatSelector: clientVersionToEditManagerFormatVersion, messageFormatSelector: clientVersionToMessageFormatVersion, + enableSharedBranches: false, }; /** diff --git a/packages/dds/tree/src/shared-tree/sharedTreeChangeFamily.ts b/packages/dds/tree/src/shared-tree/sharedTreeChangeFamily.ts index dc1bfd5aa1be..2440e5424623 100644 --- a/packages/dds/tree/src/shared-tree/sharedTreeChangeFamily.ts +++ b/packages/dds/tree/src/shared-tree/sharedTreeChangeFamily.ts @@ -23,7 +23,7 @@ import { ModularChangeFamily, type ModularChangeset, type TreeChunk, - type TreeCompressionStrategyPrivate, + type TreeCompressionStrategy, fieldKindConfigurations, fieldKinds, makeModularChangeCodecFamily, @@ -61,7 +61,7 @@ export class SharedTreeChangeFamily revisionTagCodec: RevisionTagCodec, fieldBatchCodec: FieldBatchCodec, codecOptions: CodecWriteOptions, - chunkCompressionStrategy?: TreeCompressionStrategyPrivate, + chunkCompressionStrategy?: TreeCompressionStrategy, private readonly idCompressor?: IIdCompressor, ) { const modularChangeCodec = makeModularChangeCodecFamily( diff --git a/packages/dds/tree/src/shared-tree/treeCheckout.ts b/packages/dds/tree/src/shared-tree/treeCheckout.ts index 3ee3fa907f82..7749abc4f1cf 100644 --- a/packages/dds/tree/src/shared-tree/treeCheckout.ts +++ b/packages/dds/tree/src/shared-tree/treeCheckout.ts @@ -51,7 +51,7 @@ import { } from "../core/index.js"; import { type FieldBatchCodec, - type TreeCompressionStrategyPrivate, + type TreeCompressionStrategy, allowsRepoSuperset, buildForest, createNodeIdentifierManager, @@ -287,7 +287,7 @@ export function createTreeCheckout( forest?: IEditableForest; fieldBatchCodec?: FieldBatchCodec; removedRoots?: DetachedFieldIndex; - chunkCompressionStrategy?: TreeCompressionStrategyPrivate; + chunkCompressionStrategy?: TreeCompressionStrategy; logger?: ITelemetryLoggerExt; breaker?: Breakable; disposeForksAfterTransaction?: boolean; diff --git a/packages/dds/tree/src/simple-tree/api/incrementalAllowedTypes.ts b/packages/dds/tree/src/simple-tree/api/incrementalAllowedTypes.ts index f0eeee54f63a..2376d4b4bdd1 100644 --- a/packages/dds/tree/src/simple-tree/api/incrementalAllowedTypes.ts +++ b/packages/dds/tree/src/simple-tree/api/incrementalAllowedTypes.ts @@ -3,21 +3,21 @@ * Licensed under the MIT License. */ -import type { FieldKey, TreeNodeSchemaIdentifier } from "../../core/index.js"; import { getTreeNodeSchemaPrivateData, type AllowedTypesFull } from "../core/index.js"; import { isObjectNodeSchema } from "../node-kinds/index.js"; import type { TreeSchema } from "./configuration.js"; import type { IncrementalEncodingPolicy } from "../../feature-libraries/index.js"; import { oneFromIterable } from "../../util/index.js"; import { assert } from "@fluidframework/core-utils/internal"; +import type { FieldKey } from "../../core/index.js"; /** - * A symbol when present in the {@link AnnotatedAllowedTypes.metadata.custom} property as true, opts in the allowed + * A symbol when present in the {@link AnnotatedAllowedTypes.metadata}'s `custom` property as true, opts in the allowed * types to incremental summary optimization. * These allowed types will be optimized during summary such that if they don't change across summaries, * they will not be encoded and their content will not be included in the summary that is uploaded to the service. * @remarks - * See {@link getShouldIncrementallySummarizeAllowedTypes} for more details. + * See {@link incrementalEncodingPolicyForAllowedTypes} for more details. * * Use {@link SchemaStaticsBeta.types} to add this metadata to allowed types in a schema. * @example @@ -29,6 +29,7 @@ import { assert } from "@fluidframework/core-utils/internal"; * }), * }) {} * ``` + * @alpha */ export const incrementalSummaryHint: unique symbol = Symbol("IncrementalSummaryHint"); @@ -44,31 +45,30 @@ function isIncrementalSummaryHintInAllowedTypes(allowedTypes: AllowedTypesFull): } /** - * This helper function {@link getShouldIncrementallySummarizeAllowedTypes} can be used to generate a callback function - * of type {@link IncrementalEncodingPolicy}. - * This callback can be passed as the value for {@link SharedTreeOptionsInternal.shouldEncodeFieldIncrementally} parameter + * This helper function {@link incrementalEncodingPolicyForAllowedTypes} can be used to generate a callback function + * of type {@link IncrementalEncodingPolicy}. It determines if each {@link AllowedTypes} in a schema should be + * incrementally summarized. + * This callback can be passed as the value for {@link SharedTreeOptions.shouldEncodeIncrementally} parameter * when creating the tree. - * It will be called for each {@link AllowedTypes} in the schema to determine if it should be incrementally summarized. * * @param rootSchema - The schema for the root of the tree. - * @returns A callback function of type {@link IncrementalEncodingPolicy} which can be used to determine if a field - * should be incrementally summarized based on whether it is an allowed types with the - * {@link incrementalAllowedTypesMetadata} metadata. + * @returns A callback function of type {@link IncrementalEncodingPolicy} which determines if allowed types should + * be incrementally summarized based on whether they have opted in via the {@link incrementalSummaryHint} metadata. * * @remarks * This only works for forest type {@link ForestTypeOptimized} and compression strategy - * {@link TreeCompressionStrategyExtended.CompressedIncremental}. + * {@link TreeCompressionStrategy.CompressedIncremental}. * - * The {@link incrementalAllowedTypesMetadata} will be replaced with a specialized metadata property once the + * @privateRemarks + * The {@link incrementalSummaryHint} will be replaced with a specialized metadata property once the * incremental summary feature and APIs are stabilized. + * + * @alpha */ -export function getShouldIncrementallySummarizeAllowedTypes( +export function incrementalEncodingPolicyForAllowedTypes( rootSchema: TreeSchema, ): IncrementalEncodingPolicy { - return ( - targetNodeIdentifier: TreeNodeSchemaIdentifier | undefined, - targetFieldKey: FieldKey, - ) => { + return (targetNodeIdentifier: string | undefined, targetFieldKey: string) => { if (targetNodeIdentifier === undefined) { // Root fields cannot be allowed types, so we don't incrementally summarize them. return false; @@ -85,7 +85,9 @@ export function getShouldIncrementallySummarizeAllowedTypes( } if (isObjectNodeSchema(targetNode)) { - const targetPropertyKey = targetNode.storedKeyToPropertyKey.get(targetFieldKey); + const targetPropertyKey = targetNode.storedKeyToPropertyKey.get( + targetFieldKey as FieldKey, + ); if (targetPropertyKey !== undefined) { const fieldSchema = targetNode.fields.get(targetPropertyKey); if (fieldSchema !== undefined) { diff --git a/packages/dds/tree/src/simple-tree/api/index.ts b/packages/dds/tree/src/simple-tree/api/index.ts index 65c271afa859..d012fcb4a44a 100644 --- a/packages/dds/tree/src/simple-tree/api/index.ts +++ b/packages/dds/tree/src/simple-tree/api/index.ts @@ -164,7 +164,7 @@ export { generateSchemaFromSimpleSchema } from "./schemaFromSimple.js"; export { toSimpleTreeSchema } from "./viewSchemaToSimpleSchema.js"; export type { TreeChangeEvents } from "./treeChangeEvents.js"; export { - getShouldIncrementallySummarizeAllowedTypes, + incrementalEncodingPolicyForAllowedTypes, incrementalSummaryHint, } from "./incrementalAllowedTypes.js"; export { diff --git a/packages/dds/tree/src/simple-tree/index.ts b/packages/dds/tree/src/simple-tree/index.ts index 841be8b38f08..006535ce3cab 100644 --- a/packages/dds/tree/src/simple-tree/index.ts +++ b/packages/dds/tree/src/simple-tree/index.ts @@ -186,7 +186,7 @@ export { KeyEncodingOptions, type TreeParsingOptions, incrementalSummaryHint, - getShouldIncrementallySummarizeAllowedTypes, + incrementalEncodingPolicyForAllowedTypes, type SchemaFactory_base, } from "./api/index.js"; export type { diff --git a/packages/dds/tree/src/test/feature-libraries/chunked-forest/chunkTree.spec.ts b/packages/dds/tree/src/test/feature-libraries/chunked-forest/chunkTree.spec.ts index b4c53ad34867..a8ae36a5b424 100644 --- a/packages/dds/tree/src/test/feature-libraries/chunked-forest/chunkTree.spec.ts +++ b/packages/dds/tree/src/test/feature-libraries/chunked-forest/chunkTree.spec.ts @@ -592,8 +592,8 @@ describe("chunkTree", () => { }); it("incremental", () => { const shouldEncodeIncrementally: IncrementalEncodingPolicy = ( - nodeIdentifier: TreeNodeSchemaIdentifier | undefined, - fieldKey: FieldKey, + nodeIdentifier: string | undefined, + fieldKey: string, ) => { if (nodeIdentifier === structValue.identifier && fieldKey === "x") { return true; @@ -671,8 +671,8 @@ describe("chunkTree", () => { }); it("incrementalField", () => { const shouldEncodeIncrementally: IncrementalEncodingPolicy = ( - nodeIdentifier: TreeNodeSchemaIdentifier | undefined, - fieldKey: FieldKey, + nodeIdentifier: string | undefined, + fieldKey: string, ) => { if (nodeIdentifier === structValue.identifier && fieldKey === "x") { return true; diff --git a/packages/dds/tree/src/test/feature-libraries/chunked-forest/codec/codecs.spec.ts b/packages/dds/tree/src/test/feature-libraries/chunked-forest/codec/codecs.spec.ts index 23430bcb2d22..de8885280c19 100644 --- a/packages/dds/tree/src/test/feature-libraries/chunked-forest/codec/codecs.spec.ts +++ b/packages/dds/tree/src/test/feature-libraries/chunked-forest/codec/codecs.spec.ts @@ -15,7 +15,6 @@ import { } from "../../../../feature-libraries/chunked-forest/codec/index.js"; import { TreeCompressionStrategy, - TreeCompressionStrategyExtended, cursorForJsonableTreeField, jsonableTreeFromFieldCursor, } from "../../../../feature-libraries/index.js"; @@ -64,7 +63,7 @@ describe("makeFieldBatchCodec", () => { }); }); - describe("TreeCompressionStrategyExtended.CompressedIncremental", () => { + describe("TreeCompressionStrategy.CompressedIncremental", () => { it("succeeds for minVersionForCollab FluidClientVersion.v2_73", () => { const codec = makeFieldBatchCodec({ jsonValidator: ajvValidator, @@ -73,7 +72,7 @@ describe("makeFieldBatchCodec", () => { const input = cursorForJsonableTreeField([simpleTestData]); const context = { - encodeType: TreeCompressionStrategyExtended.CompressedIncremental, + encodeType: TreeCompressionStrategy.CompressedIncremental, originatorId: testIdCompressor.localSessionId, idCompressor: testIdCompressor, }; @@ -89,7 +88,7 @@ describe("makeFieldBatchCodec", () => { const input = cursorForJsonableTreeField([simpleTestData]); const context = { - encodeType: TreeCompressionStrategyExtended.CompressedIncremental, + encodeType: TreeCompressionStrategy.CompressedIncremental, originatorId: testIdCompressor.localSessionId, idCompressor: testIdCompressor, }; diff --git a/packages/dds/tree/src/test/feature-libraries/chunked-forest/codec/schemaBasedEncode.spec.ts b/packages/dds/tree/src/test/feature-libraries/chunked-forest/codec/schemaBasedEncode.spec.ts index a5ed1310ad1a..826d5df378ef 100644 --- a/packages/dds/tree/src/test/feature-libraries/chunked-forest/codec/schemaBasedEncode.spec.ts +++ b/packages/dds/tree/src/test/feature-libraries/chunked-forest/codec/schemaBasedEncode.spec.ts @@ -6,7 +6,6 @@ import { strict as assert, fail } from "node:assert"; import type { - FieldKey, ITreeCursorSynchronous, TreeChunk, TreeFieldStoredSchema, @@ -353,8 +352,8 @@ describe("schemaBasedEncoding", () => { const testReferenceId: ChunkReferenceId = brand(123); const mockIncrementalEncoder: IncrementalEncoder = { shouldEncodeIncrementally: ( - nodeIdentifier: TreeNodeSchemaIdentifier | undefined, - fieldKey: FieldKey, + nodeIdentifier: string | undefined, + fieldKey: string, ): boolean => { return ( nodeIdentifier === HasOptionalFields.identifier && fieldKey === "incrementalField" diff --git a/packages/dds/tree/src/test/feature-libraries/forest-summary/forestSummarizer.spec.ts b/packages/dds/tree/src/test/feature-libraries/forest-summary/forestSummarizer.spec.ts index cd8c2736c3bb..5b67270ce808 100644 --- a/packages/dds/tree/src/test/feature-libraries/forest-summary/forestSummarizer.spec.ts +++ b/packages/dds/tree/src/test/feature-libraries/forest-summary/forestSummarizer.spec.ts @@ -17,12 +17,10 @@ import { FluidClientVersion, type CodecWriteOptions } from "../../../codec/index import { ForestSummarizer, TreeCompressionStrategy, - TreeCompressionStrategyExtended, defaultSchemaPolicy, makeFieldBatchCodec, type FieldBatchEncodingContext, type IncrementalEncodingPolicy, - type TreeCompressionStrategyPrivate, } from "../../../feature-libraries/index.js"; import { checkoutWithContent, @@ -39,7 +37,7 @@ import { type TreeCheckout, } from "../../../shared-tree/index.js"; import { - getShouldIncrementallySummarizeAllowedTypes, + incrementalEncodingPolicyForAllowedTypes, incrementalSummaryHint, permissiveStoredSchemaGenerationOptions, SchemaFactory, @@ -51,11 +49,10 @@ import { import { fieldJsonCursor } from "../../json/index.js"; // eslint-disable-next-line import-x/no-internal-modules import { forestSummaryContentKey } from "../../../feature-libraries/forest-summary/incrementalSummaryBuilder.js"; -import type { FieldKey, TreeNodeSchemaIdentifier } from "../../../core/index.js"; function createForestSummarizer(args: { // The encoding strategy to use when summarizing the forest. - encodeType: TreeCompressionStrategyPrivate; + encodeType: TreeCompressionStrategy; // The type of forest to create. forestType: ForestType; // The content and schema to initialize the forest with. By default, it is an empty forest. @@ -288,8 +285,8 @@ describe("ForestSummarizer", () => { }; const shouldEncodeIncrementally = ( - nodeIdentifier: TreeNodeSchemaIdentifier | undefined, - fieldKey: FieldKey, + nodeIdentifier: string | undefined, + fieldKey: string, ): boolean => { if (nodeIdentifier === SimpleObject.identifier && fieldKey === "foo") { return true; @@ -299,7 +296,7 @@ describe("ForestSummarizer", () => { const { forestSummarizer } = createForestSummarizer({ initialContent, - encodeType: TreeCompressionStrategyExtended.CompressedIncremental, + encodeType: TreeCompressionStrategy.CompressedIncremental, forestType: ForestTypeOptimized, shouldEncodeIncrementally, }); @@ -319,7 +316,7 @@ describe("ForestSummarizer", () => { // Validate that the forest can successfully load from the above summary. const mockStorage = MockStorage.createFromSummary(summary.summary); const { forestSummarizer: forestSummarizer2 } = createForestSummarizer({ - encodeType: TreeCompressionStrategyExtended.CompressedIncremental, + encodeType: TreeCompressionStrategy.CompressedIncremental, forestType: ForestTypeOptimized, shouldEncodeIncrementally, }); @@ -363,7 +360,7 @@ describe("ForestSummarizer", () => { * Sets up the forest summarizer for incremental summarization. It creates a forest and sets up some * of the fields to support incremental encoding. * Note that it creates a chunked forest of type `ForestTypeOptimized` with compression strategy - * `TreeCompressionStrategyExtended.CompressedIncremental` since incremental summarization is only + * `TreeCompressionStrategy.CompressedIncremental` since incremental summarization is only * supported by this combination. */ function setupForestForIncrementalSummarization(initialBoard: Root | undefined) { @@ -377,9 +374,9 @@ describe("ForestSummarizer", () => { return createForestSummarizer({ initialContent, - encodeType: TreeCompressionStrategyExtended.CompressedIncremental, + encodeType: TreeCompressionStrategy.CompressedIncremental, forestType: ForestTypeOptimized, - shouldEncodeIncrementally: getShouldIncrementallySummarizeAllowedTypes( + shouldEncodeIncrementally: incrementalEncodingPolicyForAllowedTypes( new TreeViewConfigurationAlpha({ schema: Root }), ), }); diff --git a/packages/dds/tree/src/treeFactory.ts b/packages/dds/tree/src/treeFactory.ts index db29f6eea5be..2d984123188e 100644 --- a/packages/dds/tree/src/treeFactory.ts +++ b/packages/dds/tree/src/treeFactory.ts @@ -148,6 +148,16 @@ export function configuredSharedTreeBetaLegacy( return configuredSharedTree(options); } +/** + * {@link configuredSharedTreeBeta} but including the alpha {@link SharedTreeOptions}. + * @alpha + */ +export function configuredSharedTreeAlpha( + options: SharedTreeOptions, +): SharedObjectKind { + return configuredSharedTree(options); +} + /** * {@link configuredSharedTreeBetaLegacy} but including `@alpha` options. * @@ -195,10 +205,9 @@ export function resolveOptions(options: SharedTreeOptions): SharedTreeOptionsInt const internal: SharedTreeOptionsInternal = { ...resolveSharedBranchesOptions(options.enableSharedBranches), }; - copyProperty(options, "forest", internal); - copyProperty(options, "jsonValidator", internal); - copyProperty(options, "minVersionForCollab", internal); - copyProperty(options, "treeEncodeType", internal); + for (const optionName of Object.keys(options)) { + copyProperty(options, optionName, internal); + } return internal; } diff --git a/packages/framework/fluid-framework/api-report/fluid-framework.alpha.api.md b/packages/framework/fluid-framework/api-report/fluid-framework.alpha.api.md index 594eee2ebc06..41f000a1c5b8 100644 --- a/packages/framework/fluid-framework/api-report/fluid-framework.alpha.api.md +++ b/packages/framework/fluid-framework/api-report/fluid-framework.alpha.api.md @@ -179,6 +179,9 @@ export type ConciseTree = Exclude; +// @alpha +export function configuredSharedTreeAlpha(options: SharedTreeOptions): SharedObjectKind; + // @beta export function configuredSharedTreeBeta(options: SharedTreeOptionsBeta): SharedObjectKind; @@ -741,6 +744,15 @@ export type ImplicitFieldSchema = FieldSchema | ImplicitAllowedTypes; // @alpha export function importCompatibilitySchemaSnapshot(config: JsonCompatibleReadOnly): TreeViewConfiguration; +// @alpha +export type IncrementalEncodingPolicy = (nodeIdentifier: string | undefined, fieldKey: string) => boolean; + +// @alpha +export function incrementalEncodingPolicyForAllowedTypes(rootSchema: TreeSchema): IncrementalEncodingPolicy; + +// @alpha +export const incrementalSummaryHint: unique symbol; + // @alpha export function independentInitializedView(config: TreeViewConfiguration, options: ForestOptions & ICodecOptions, content: ViewContent): TreeViewAlpha; @@ -1401,8 +1413,9 @@ export interface SharedTreeFormatOptions { } // @alpha @input -export interface SharedTreeOptions extends Partial, Partial, SharedTreeOptionsBeta { +export interface SharedTreeOptions extends SharedTreeOptionsBeta, Partial, Partial { readonly enableSharedBranches?: boolean; + shouldEncodeIncrementally?: IncrementalEncodingPolicy; } // @beta @input @@ -1868,6 +1881,7 @@ export interface TreeChangeEventsBeta extends // @alpha export enum TreeCompressionStrategy { Compressed = 0, + CompressedIncremental = 2, Uncompressed = 1 }