Skip to content

Commit c073de1

Browse files
committed
Prototype: Update how shared tree codec versions are generated
1 parent 15415d3 commit c073de1

File tree

14 files changed

+88
-6
lines changed

14 files changed

+88
-6
lines changed

packages/dds/tree/src/core/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ export {
104104
type ChunkedCursor,
105105
type DetachedFieldIndexFormatVersion,
106106
getCodecTreeForDetachedFieldIndexFormat,
107+
getDetachedFieldIndexCodecVersion,
107108
} from "./tree/index.js";
108109

109110
export {
@@ -153,6 +154,7 @@ export {
153154
type SchemaPolicy,
154155
SchemaVersion,
155156
type SchemaFormatVersion,
157+
getSchemaCodecVersion,
156158
} from "./schema-stored/index.js";
157159

158160
export {

packages/dds/tree/src/core/schema-stored/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export {
2525
type SchemaPolicy,
2626
SchemaVersion,
2727
type SchemaFormatVersion,
28+
getSchemaCodecVersion,
2829
} from "./schema.js";
2930
export {
3031
type TreeStoredSchemaSubscription,

packages/dds/tree/src/core/schema-stored/schema.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ import type {
2929
TreeNodeSchemaDataFormat as TreeNodeSchemaDataFormatV2,
3030
} from "./formatV2.js";
3131
import type { Multiplicity } from "./multiplicity.js";
32+
import type { MinimumVersionForCollab } from "@fluidframework/runtime-definitions/internal";
33+
34+
export function getSchemaCodecVersion(
35+
minVersionForCollab: MinimumVersionForCollab,
36+
): SchemaFormatVersion {
37+
// Currently only two versions exists.
38+
// In the future, this function can be expanded to select different versions based on the minimum version required.
39+
return brand(SchemaVersion.v2);
40+
}
3241

3342
/**
3443
* The format version for the schema.

packages/dds/tree/src/core/tree/detachedFieldIndexCodecs.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import { version2 } from "./detachedFieldIndexFormatV2.js";
2121
import { makeDetachedNodeToFieldCodecV1 } from "./detachedFieldIndexCodecV1.js";
2222
import { makeDetachedNodeToFieldCodecV2 } from "./detachedFieldIndexCodecV2.js";
2323
import type { DetachedFieldSummaryData } from "./detachedFieldIndexTypes.js";
24-
import type { Brand } from "../../util/index.js";
24+
import { brand, type Brand } from "../../util/index.js";
25+
import type { MinimumVersionForCollab } from "@fluidframework/runtime-definitions/internal";
2526

2627
export function makeDetachedFieldIndexCodec(
2728
revisionTagCodec: RevisionTagCodec,
@@ -51,3 +52,11 @@ export function getCodecTreeForDetachedFieldIndexFormat(
5152
): CodecTree {
5253
return { name: "DetachedFieldIndex", version };
5354
}
55+
56+
export function getDetachedFieldIndexCodecVersion(
57+
minVersionForCollab: MinimumVersionForCollab,
58+
): DetachedFieldIndexFormatVersion {
59+
// Currently two versions exists.
60+
// In the future, this function can be expanded to select different versions based on the minimum version required.
61+
return minVersionForCollab < FluidClientVersion.v2_52 ? brand(version1) : brand(version2);
62+
}

packages/dds/tree/src/core/tree/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export { DetachedFieldIndex } from "./detachedFieldIndex.js";
122122
export {
123123
type DetachedFieldIndexFormatVersion,
124124
getCodecTreeForDetachedFieldIndexFormat,
125+
getDetachedFieldIndexCodecVersion,
125126
} from "./detachedFieldIndexCodecs.js";
126127

127128
export { type ForestRootId } from "./detachedFieldIndexTypes.js";

packages/dds/tree/src/feature-libraries/chunked-forest/codec/format.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
import { type Static, Type } from "@sinclair/typebox";
77

8+
import type { MinimumVersionForCollab } from "@fluidframework/runtime-definitions/internal";
9+
810
import { unionOptions } from "../../../codec/index.js";
911

1012
import {
@@ -13,7 +15,15 @@ import {
1315
IdentifierOrIndex,
1416
ShapeIndex,
1517
} from "./formatGeneric.js";
16-
import type { Brand } from "../../../util/index.js";
18+
import { brand, type Brand } from "../../../util/index.js";
19+
20+
export function getFieldBatchCodecVersion(
21+
minVersionForCollab: MinimumVersionForCollab,
22+
): FieldBatchFormatVersion {
23+
// Currently only one version exists.
24+
// In the future, this function can be expanded to select different versions based on the minimum version required.
25+
return brand(version);
26+
}
1727

1828
export const version = 1;
1929
export type FieldBatchFormatVersion = Brand<1, "FieldBatchFormatVersion">;

packages/dds/tree/src/feature-libraries/chunked-forest/codec/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
* Licensed under the MIT License.
44
*/
55

6-
export { EncodedFieldBatch, type FieldBatchFormatVersion } from "./format.js";
6+
export {
7+
EncodedFieldBatch,
8+
type FieldBatchFormatVersion,
9+
getFieldBatchCodecVersion,
10+
} from "./format.js";
711
export type { FieldBatch } from "./fieldBatch.js";
812
export {
913
type FieldBatchCodec,

packages/dds/tree/src/feature-libraries/chunked-forest/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ export {
2828
type ChunkReferenceId,
2929
type IncrementalEncodingPolicy,
3030
defaultIncrementalEncodingPolicy,
31+
getFieldBatchCodecVersion,
3132
} from "./codec/index.js";
3233
export { emptyChunk } from "./emptyChunk.js";

packages/dds/tree/src/feature-libraries/forest-summary/codec.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import type { FieldKey, ITreeCursorSynchronous } from "../../core/index.js";
1515
import type { FieldBatchCodec, FieldBatchEncodingContext } from "../chunked-forest/index.js";
1616

1717
import { Format } from "./format.js";
18-
import type { Brand } from "../../util/index.js";
18+
import { brand, type Brand } from "../../util/index.js";
19+
import type { MinimumVersionForCollab } from "@fluidframework/runtime-definitions/internal";
1920

2021
/**
2122
* Uses field cursors
@@ -57,3 +58,11 @@ export type ForestFormatVersion = Brand<1, "ForestFormatVersion">;
5758
export function getCodecTreeForForestFormat(version: ForestFormatVersion): CodecTree {
5859
return { name: "Forest", version };
5960
}
61+
62+
export function getForestCodecVersion(
63+
minVersionForCollab: MinimumVersionForCollab,
64+
): ForestFormatVersion {
65+
// Currently only one version exists.
66+
// In the future, this function can be expanded to select different versions based on the minimum version required.
67+
return brand(1);
68+
}

packages/dds/tree/src/feature-libraries/forest-summary/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@
44
*/
55

66
export { forestSummaryKey, ForestSummarizer } from "./forestSummarizer.js";
7-
export { getCodecTreeForForestFormat, type ForestFormatVersion } from "./codec.js";
7+
export {
8+
getCodecTreeForForestFormat,
9+
type ForestFormatVersion,
10+
getForestCodecVersion,
11+
} from "./codec.js";

0 commit comments

Comments
 (0)