@fluidframework/container-runtime 2.51.0 → 2.53.0-350190

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/api-report/container-runtime.legacy.alpha.api.md +1 -2
  3. package/container-runtime.test-files.tar +0 -0
  4. package/dist/blobManager/blobManager.d.ts +15 -7
  5. package/dist/blobManager/blobManager.d.ts.map +1 -1
  6. package/dist/blobManager/blobManager.js +72 -186
  7. package/dist/blobManager/blobManager.js.map +1 -1
  8. package/dist/containerCompatibility.d.ts +34 -0
  9. package/dist/containerCompatibility.d.ts.map +1 -0
  10. package/dist/containerCompatibility.js +125 -0
  11. package/dist/containerCompatibility.js.map +1 -0
  12. package/dist/containerRuntime.d.ts +27 -15
  13. package/dist/containerRuntime.d.ts.map +1 -1
  14. package/dist/containerRuntime.js +175 -136
  15. package/dist/containerRuntime.js.map +1 -1
  16. package/dist/dataStoreContext.d.ts +6 -6
  17. package/dist/dataStoreContext.d.ts.map +1 -1
  18. package/dist/dataStoreContext.js.map +1 -1
  19. package/dist/gc/garbageCollection.d.ts.map +1 -1
  20. package/dist/gc/garbageCollection.js +5 -0
  21. package/dist/gc/garbageCollection.js.map +1 -1
  22. package/dist/index.d.ts +5 -1
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/metadata.d.ts +3 -2
  26. package/dist/metadata.d.ts.map +1 -1
  27. package/dist/metadata.js +7 -1
  28. package/dist/metadata.js.map +1 -1
  29. package/dist/packageVersion.d.ts +1 -1
  30. package/dist/packageVersion.d.ts.map +1 -1
  31. package/dist/packageVersion.js +1 -1
  32. package/dist/packageVersion.js.map +1 -1
  33. package/dist/storageServiceWithAttachBlobs.d.ts +40 -5
  34. package/dist/storageServiceWithAttachBlobs.d.ts.map +1 -1
  35. package/dist/storageServiceWithAttachBlobs.js +56 -5
  36. package/dist/storageServiceWithAttachBlobs.js.map +1 -1
  37. package/dist/summary/documentSchema.d.ts +1 -1
  38. package/dist/summary/documentSchema.d.ts.map +1 -1
  39. package/dist/summary/documentSchema.js.map +1 -1
  40. package/dist/summary/summaryFormat.d.ts +3 -3
  41. package/dist/summary/summaryFormat.d.ts.map +1 -1
  42. package/dist/summary/summaryFormat.js.map +1 -1
  43. package/lib/blobManager/blobManager.d.ts +15 -7
  44. package/lib/blobManager/blobManager.d.ts.map +1 -1
  45. package/lib/blobManager/blobManager.js +39 -153
  46. package/lib/blobManager/blobManager.js.map +1 -1
  47. package/lib/containerCompatibility.d.ts +34 -0
  48. package/lib/containerCompatibility.d.ts.map +1 -0
  49. package/lib/containerCompatibility.js +120 -0
  50. package/lib/containerCompatibility.js.map +1 -0
  51. package/lib/containerRuntime.d.ts +27 -15
  52. package/lib/containerRuntime.d.ts.map +1 -1
  53. package/lib/containerRuntime.js +103 -64
  54. package/lib/containerRuntime.js.map +1 -1
  55. package/lib/dataStoreContext.d.ts +6 -6
  56. package/lib/dataStoreContext.d.ts.map +1 -1
  57. package/lib/dataStoreContext.js +1 -1
  58. package/lib/dataStoreContext.js.map +1 -1
  59. package/lib/gc/garbageCollection.d.ts.map +1 -1
  60. package/lib/gc/garbageCollection.js +5 -0
  61. package/lib/gc/garbageCollection.js.map +1 -1
  62. package/lib/index.d.ts +5 -1
  63. package/lib/index.d.ts.map +1 -1
  64. package/lib/index.js.map +1 -1
  65. package/lib/metadata.d.ts +3 -2
  66. package/lib/metadata.d.ts.map +1 -1
  67. package/lib/metadata.js +5 -0
  68. package/lib/metadata.js.map +1 -1
  69. package/lib/packageVersion.d.ts +1 -1
  70. package/lib/packageVersion.d.ts.map +1 -1
  71. package/lib/packageVersion.js +1 -1
  72. package/lib/packageVersion.js.map +1 -1
  73. package/lib/storageServiceWithAttachBlobs.d.ts +40 -5
  74. package/lib/storageServiceWithAttachBlobs.d.ts.map +1 -1
  75. package/lib/storageServiceWithAttachBlobs.js +56 -5
  76. package/lib/storageServiceWithAttachBlobs.js.map +1 -1
  77. package/lib/summary/documentSchema.d.ts +1 -1
  78. package/lib/summary/documentSchema.d.ts.map +1 -1
  79. package/lib/summary/documentSchema.js.map +1 -1
  80. package/lib/summary/summaryFormat.d.ts +3 -3
  81. package/lib/summary/summaryFormat.d.ts.map +1 -1
  82. package/lib/summary/summaryFormat.js.map +1 -1
  83. package/package.json +20 -20
  84. package/src/blobManager/blobManager.ts +53 -195
  85. package/src/containerCompatibility.ts +176 -0
  86. package/src/containerRuntime.ts +157 -122
  87. package/src/dataStoreContext.ts +13 -5
  88. package/src/gc/garbageCollection.ts +6 -0
  89. package/src/index.ts +6 -1
  90. package/src/metadata.ts +10 -2
  91. package/src/packageVersion.ts +1 -1
  92. package/src/storageServiceWithAttachBlobs.ts +92 -10
  93. package/src/summary/documentSchema.ts +1 -1
  94. package/src/summary/summaryFormat.ts +2 -2
  95. package/dist/compatUtils.d.ts +0 -106
  96. package/dist/compatUtils.d.ts.map +0 -1
  97. package/dist/compatUtils.js +0 -251
  98. package/dist/compatUtils.js.map +0 -1
  99. package/lib/compatUtils.d.ts +0 -106
  100. package/lib/compatUtils.d.ts.map +0 -1
  101. package/lib/compatUtils.js +0 -242
  102. package/lib/compatUtils.js.map +0 -1
  103. package/src/compatUtils.ts +0 -365
@@ -4,23 +4,34 @@
4
4
  */
5
5
 
6
6
  import {
7
- IDocumentStorageService,
8
- IDocumentStorageServicePolicies,
7
+ type FetchSource,
8
+ type ICreateBlobResponse,
9
+ type IDocumentStorageServicePolicies,
10
+ type ISnapshot,
11
+ type ISnapshotFetchOptions,
12
+ type ISnapshotTree,
13
+ type ISummaryContext,
14
+ type ISummaryHandle,
15
+ type ISummaryTree,
16
+ type IVersion,
9
17
  } from "@fluidframework/driver-definitions/internal";
10
- import { DocumentStorageServiceProxy } from "@fluidframework/driver-utils/internal";
18
+ import type { IRuntimeStorageService } from "@fluidframework/runtime-definitions/internal";
19
+ import { UsageError } from "@fluidframework/telemetry-utils/internal";
11
20
 
12
21
  /**
13
- * IDocumentStorageService proxy which intercepts requests if they can be satisfied by the blobs received in the
22
+ * IRuntimeStorageService proxy which intercepts requests if they can be satisfied by the blobs received in the
14
23
  * attach message. We use this to avoid an unnecessary request to the storage service.
15
24
  */
16
- export class StorageServiceWithAttachBlobs extends DocumentStorageServiceProxy {
25
+ export class StorageServiceWithAttachBlobs implements IRuntimeStorageService {
17
26
  constructor(
18
- internalStorageService: IDocumentStorageService,
27
+ private readonly internalStorageService: IRuntimeStorageService,
19
28
  private readonly attachBlobs: Map<string, ArrayBufferLike>,
20
- ) {
21
- super(internalStorageService);
22
- }
29
+ ) {}
23
30
 
31
+ /**
32
+ * {@link IRuntimeStorageService.policies}.
33
+ * @deprecated - This will be removed in a future release. The DataStore layer does not need this.
34
+ */
24
35
  public get policies(): IDocumentStorageServicePolicies | undefined {
25
36
  return this.internalStorageService.policies;
26
37
  }
@@ -32,7 +43,78 @@ export class StorageServiceWithAttachBlobs extends DocumentStorageServiceProxy {
32
43
  }
33
44
 
34
45
  // Note that it is intentional not to cache the result of this readBlob - we'll trust the real
35
- // IDocumentStorageService to cache appropriately, no need to double-cache.
46
+ // IRuntimeStorageService to cache appropriately, no need to double-cache.
36
47
  return this.internalStorageService.readBlob(id);
37
48
  }
49
+
50
+ /**
51
+ * {@link IRuntimeStorageService.getSnapshotTree}.
52
+ * @deprecated - This will be removed in a future release. The DataStore layer does not need this.
53
+ */
54
+ public async getSnapshotTree(
55
+ version?: IVersion,
56
+ scenarioName?: string,
57
+ // eslint-disable-next-line @rushstack/no-new-null
58
+ ): Promise<ISnapshotTree | null> {
59
+ return this.internalStorageService.getSnapshotTree(version, scenarioName);
60
+ }
61
+
62
+ /**
63
+ * {@link IRuntimeStorageService.getSnapshot}.
64
+ * @deprecated - This will be removed in a future release. The DataStore layer does not need this.
65
+ */
66
+ public async getSnapshot(snapshotFetchOptions?: ISnapshotFetchOptions): Promise<ISnapshot> {
67
+ if (this.internalStorageService.getSnapshot !== undefined) {
68
+ return this.internalStorageService.getSnapshot(snapshotFetchOptions);
69
+ }
70
+ throw new UsageError(
71
+ "getSnapshot api should exist on internal storage in documentStorageServiceProxy class",
72
+ );
73
+ }
74
+
75
+ /**
76
+ * {@link IRuntimeStorageService.getVersions}.
77
+ * @deprecated - This will be removed in a future release. The DataStore layer does not need this.
78
+ */
79
+ public async getVersions(
80
+ // eslint-disable-next-line @rushstack/no-new-null
81
+ versionId: string | null,
82
+ count: number,
83
+ scenarioName?: string,
84
+ fetchSource?: FetchSource,
85
+ ): Promise<IVersion[]> {
86
+ return this.internalStorageService.getVersions(
87
+ versionId,
88
+ count,
89
+ scenarioName,
90
+ fetchSource,
91
+ );
92
+ }
93
+
94
+ /**
95
+ * {@link IRuntimeStorageService.uploadSummaryWithContext}.
96
+ * @deprecated - This will be removed in a future release. The DataStore layer does not need this.
97
+ */
98
+ public async uploadSummaryWithContext(
99
+ summary: ISummaryTree,
100
+ context: ISummaryContext,
101
+ ): Promise<string> {
102
+ return this.internalStorageService.uploadSummaryWithContext(summary, context);
103
+ }
104
+
105
+ /**
106
+ * {@link IRuntimeStorageService.createBlob}.
107
+ * @deprecated - This will be removed in a future release. The DataStore layer does not need this.
108
+ */
109
+ public async createBlob(file: ArrayBufferLike): Promise<ICreateBlobResponse> {
110
+ return this.internalStorageService.createBlob(file);
111
+ }
112
+
113
+ /**
114
+ * {@link IRuntimeStorageService.downloadSummary}.
115
+ * @deprecated - This will be removed in a future release. The DataStore layer does not need this.
116
+ */
117
+ public async downloadSummary(handle: ISummaryHandle): Promise<ISummaryTree> {
118
+ return this.internalStorageService.downloadSummary(handle);
119
+ }
38
120
  }
@@ -4,11 +4,11 @@
4
4
  */
5
5
 
6
6
  import { assert } from "@fluidframework/core-utils/internal";
7
+ import type { SemanticVersion } from "@fluidframework/runtime-utils/internal";
7
8
  import type { ITelemetryLoggerExt } from "@fluidframework/telemetry-utils/internal";
8
9
  import { DataProcessingError } from "@fluidframework/telemetry-utils/internal";
9
10
  import { gt, lt, parse } from "semver-ts";
10
11
 
11
- import type { SemanticVersion } from "../compatUtils.js";
12
12
  import { pkgVersion } from "../packageVersion.js";
13
13
 
14
14
  /**
@@ -6,7 +6,6 @@
6
6
  import { assert } from "@fluidframework/core-utils/internal";
7
7
  import { SummaryType } from "@fluidframework/driver-definitions";
8
8
  import {
9
- IDocumentStorageService,
10
9
  ISnapshotTree,
11
10
  ISequencedDocumentMessage,
12
11
  } from "@fluidframework/driver-definitions/internal";
@@ -15,6 +14,7 @@ import {
15
14
  ISummaryTreeWithStats,
16
15
  channelsTreeName,
17
16
  gcTreeKey,
17
+ type IRuntimeStorageService,
18
18
  } from "@fluidframework/runtime-definitions/internal";
19
19
 
20
20
  import { blobsTreeName } from "../blobManager/index.js";
@@ -287,7 +287,7 @@ export function wrapSummaryInChannelsTree(summarizeResult: ISummaryTreeWithStats
287
287
  }
288
288
 
289
289
  export async function getFluidDataStoreAttributes(
290
- storage: IDocumentStorageService,
290
+ storage: IRuntimeStorageService,
291
291
  snapshot: ISnapshotTree,
292
292
  ): Promise<ReadFluidDataStoreAttributes> {
293
293
  const attributes = await readAndParse<ReadFluidDataStoreAttributes>(
@@ -1,106 +0,0 @@
1
- /*!
2
- * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
- * Licensed under the MIT License.
4
- */
5
- import type { ContainerRuntimeOptionsInternal } from "./containerRuntime.js";
6
- /**
7
- * Our policy is to support N/N-1 compatibility by default, where N is the most
8
- * recent public major release of the runtime.
9
- * Therefore, if the customer does not provide a minVersionForCollab, we will
10
- * default to use N-1.
11
- *
12
- * However, this is not consistent with today's behavior. Some options (i.e.
13
- * batching, compression) are enabled by default despite not being compatible
14
- * with 1.x clients. Since the policy was introduced during 2.x's lifespan,
15
- * N/N-1 compatibility by **default** will be in effect starting with 3.0.
16
- * Importantly though, N/N-2 compatibility is still guaranteed with the proper
17
- * configurations set.
18
- *
19
- * Further to distinguish unspecified `minVersionForCollab` from a specified
20
- * version and allow `enableExplicitSchemaControl` to default to `true` for
21
- * any 2.0.0+ version, we will use a special value of `2.0.0-defaults`, which
22
- * is semantically less than 2.0.0.
23
- */
24
- export declare const defaultMinVersionForCollab: "2.0.0-defaults";
25
- /**
26
- * String in a valid semver format specifying bottom of a minor version
27
- * or special "defaults" prerelease of a major.
28
- * @remarks Only 2.0.0-defaults is expected, but index signatures cannot be a
29
- * literal; so, just allow any major -defaults prerelease.
30
- */
31
- export type MinimumMinorSemanticVersion = `${bigint}.${bigint}.0` | `${bigint}.0.0-defaults`;
32
- /**
33
- * String in a valid semver format of a specific version at least specifying minor.
34
- *
35
- * @legacy
36
- * @alpha
37
- */
38
- export type MinimumVersionForCollab = `${1 | 2}.${bigint}.${bigint}` | `${1 | 2}.${bigint}.${bigint}-${string}`;
39
- /**
40
- * String in a valid semver format of a specific version at least specifying minor.
41
- * Unlike {@link MinimumVersionForCollab}, this type allows any bigint for the major version.
42
- * Used as a more generic type that allows major versions other than 1 or 2.
43
- *
44
- * @internal
45
- */
46
- export type SemanticVersion = `${bigint}.${bigint}.${bigint}` | `${bigint}.${bigint}.${bigint}-${string}`;
47
- /**
48
- * Generic type for runtimeOptionsAffectingDocSchemaConfigMap
49
- */
50
- export type ConfigMap<T extends Record<string, unknown>> = {
51
- [K in keyof T]-?: {
52
- [version: MinimumMinorSemanticVersion]: T[K];
53
- };
54
- };
55
- /**
56
- * Generic type for runtimeOptionsAffectingDocSchemaConfigValidationMap
57
- */
58
- export type ConfigValidationMap<T extends Record<string, unknown>> = {
59
- [K in keyof T]-?: (configValue: T[K]) => SemanticVersion | undefined;
60
- };
61
- /**
62
- * Subset of the {@link ContainerRuntimeOptionsInternal} properties which
63
- * affect {@link IDocumentSchemaFeatures}.
64
- *
65
- * @remarks
66
- * When a new option is added to {@link ContainerRuntimeOptionsInternal}, we
67
- * must consider if it changes the DocumentSchema. If so, then a corresponding
68
- * entry must be added to {@link runtimeOptionsAffectingDocSchemaConfigMap}
69
- * below. If not, then it must be omitted from this type.
70
- *
71
- * Note: `Omit` is used instead of `Pick` to ensure that all new options are
72
- * included in this type by default. If any new properties are added to
73
- * {@link ContainerRuntimeOptionsInternal}, they will be included in this
74
- * type unless explicitly omitted. This will prevent us from forgetting to
75
- * account for any new properties in the future.
76
- */
77
- export type RuntimeOptionsAffectingDocSchema = Omit<ContainerRuntimeOptionsInternal, "chunkSizeInBytes" | "maxBatchSizeInBytes" | "loadSequenceNumberVerification" | "summaryOptions">;
78
- /**
79
- * Returns the default RuntimeOptionsAffectingDocSchema configuration for a given minVersionForCollab.
80
- */
81
- export declare function getMinVersionForCollabDefaults(minVersionForCollab: MinimumVersionForCollab): RuntimeOptionsAffectingDocSchema;
82
- /**
83
- * Returns a default configuration given minVersionForCollab and configuration version map.
84
- */
85
- export declare function getConfigsForMinVersionForCollab<T extends Record<SemanticVersion, unknown>>(minVersionForCollab: SemanticVersion, configMap: ConfigMap<T>): Partial<T>;
86
- /**
87
- * Checks if the minVersionForCollab is valid.
88
- * A valid minVersionForCollab is a MinimumVersionForCollab that is at least `lowestMinVersionForCollab` and less than or equal to the current package version.
89
- */
90
- export declare function isValidMinVersionForCollab(minVersionForCollab: MinimumVersionForCollab): boolean;
91
- /**
92
- * Validates if the runtime options passed in from the user are compatible with the minVersionForCollab.
93
- * For example, if a user sets the `enableGroupedBatching` option to true, but the minVersionForCollab
94
- * is set to "1.0.0", then we should throw a UsageError since 1.x clients do not support batching.
95
- * */
96
- export declare function validateRuntimeOptions(minVersionForCollab: MinimumVersionForCollab, runtimeOptions: Partial<ContainerRuntimeOptionsInternal>): void;
97
- /**
98
- * Generic function to validate runtime options against the minVersionForCollab.
99
- */
100
- export declare function getValidationForRuntimeOptions<T extends Record<string, unknown>>(minVersionForCollab: SemanticVersion, runtimeOptions: Partial<T>, validationMap: ConfigValidationMap<T>): void;
101
- /**
102
- * Helper function to map ContainerRuntimeOptionsInternal config values to
103
- * minVersionForCollab in {@link runtimeOptionsAffectingDocSchemaConfigValidationMap}.
104
- */
105
- export declare function configValueToMinVersionForCollab<T extends string | number | boolean | undefined | object, Arr extends readonly [T, SemanticVersion][]>(configToMinVer: Arr): (configValue: T) => SemanticVersion | undefined;
106
- //# sourceMappingURL=compatUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compatUtils.d.ts","sourceRoot":"","sources":["../src/compatUtils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,uBAAuB,CAAC;AAG7E;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,0BAA0B,kBACqB,CAAC;AAU7D;;;;;GAKG;AACH,MAAM,MAAM,2BAA2B,GAAG,GAAG,MAAM,IAAI,MAAM,IAAI,GAAG,GAAG,MAAM,eAAe,CAAC;AAE7F;;;;;GAKG;AACH,MAAM,MAAM,uBAAuB,GAChC,GAAG,CAAC,GAAG,CAAC,IAAI,MAAM,IAAI,MAAM,EAAE,GAC9B,GAAG,CAAC,GAAG,CAAC,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GACxB,GAAG,MAAM,IAAI,MAAM,IAAI,MAAM,EAAE,GAC/B,GAAG,MAAM,IAAI,MAAM,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;KACzD,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG;QACjB,CAAC,OAAO,EAAE,2BAA2B,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;KAC7C;CACD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;KACnE,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,eAAe,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4
- * Licensed under the MIT License.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.configValueToMinVersionForCollab = exports.getValidationForRuntimeOptions = exports.validateRuntimeOptions = exports.isValidMinVersionForCollab = exports.getConfigsForMinVersionForCollab = exports.getMinVersionForCollabDefaults = exports.defaultMinVersionForCollab = void 0;
8
- const internal_1 = require("@fluidframework/core-utils/internal");
9
- const internal_2 = require("@fluidframework/runtime-definitions/internal");
10
- const internal_3 = require("@fluidframework/telemetry-utils/internal");
11
- const semver_ts_1 = require("semver-ts");
12
- const compressionDefinitions_js_1 = require("./compressionDefinitions.js");
13
- const packageVersion_js_1 = require("./packageVersion.js");
14
- /**
15
- * Our policy is to support N/N-1 compatibility by default, where N is the most
16
- * recent public major release of the runtime.
17
- * Therefore, if the customer does not provide a minVersionForCollab, we will
18
- * default to use N-1.
19
- *
20
- * However, this is not consistent with today's behavior. Some options (i.e.
21
- * batching, compression) are enabled by default despite not being compatible
22
- * with 1.x clients. Since the policy was introduced during 2.x's lifespan,
23
- * N/N-1 compatibility by **default** will be in effect starting with 3.0.
24
- * Importantly though, N/N-2 compatibility is still guaranteed with the proper
25
- * configurations set.
26
- *
27
- * Further to distinguish unspecified `minVersionForCollab` from a specified
28
- * version and allow `enableExplicitSchemaControl` to default to `true` for
29
- * any 2.0.0+ version, we will use a special value of `2.0.0-defaults`, which
30
- * is semantically less than 2.0.0.
31
- */
32
- exports.defaultMinVersionForCollab = "2.0.0-defaults";
33
- /**
34
- * We don't want allow a version before the major public release of the LTS version.
35
- * Today we use "1.0.0", because our policy supports N/N-1 & N/N-2, which includes
36
- * all minor versions of N. Though LTS starts at 1.4.0, we should stay consistent
37
- * with our policy and allow all 1.x versions to be compatible with 2.x.
38
- */
39
- const lowestMinVersionForCollab = "1.0.0";
40
- /**
41
- * Mapping of RuntimeOptionsAffectingDocSchema to their compatibility related configs.
42
- *
43
- * Each key in this map corresponds to a property in RuntimeOptionsAffectingDocSchema. The value is an object that maps MinimumVersionForCollab
44
- * to the appropriate default value for that property to supporting that MinimumVersionForCollab. If clients running MinimumVersionForCollab X are able to understand
45
- * the format changes introduced by the property, then the default value for that MinimumVersionForCollab will enable the feature associated with the property.
46
- * Otherwise, the feature will be disabled.
47
- *
48
- * For example if the minVersionForCollab is a 1.x version (i.e. "1.5.0"), then the default value for `enableGroupedBatching` will be false since 1.x
49
- * clients do not understand the document format when batching is enabled. If the minVersionForCollab is a 2.x client (i.e. "2.0.0" or later), then the
50
- * default value for `enableGroupedBatching` will be true because clients running 2.0 or later will be able to understand the format changes associated
51
- * with the batching feature.
52
- */
53
- const runtimeOptionsAffectingDocSchemaConfigMap = {
54
- enableGroupedBatching: {
55
- "1.0.0": false,
56
- "2.0.0-defaults": true,
57
- },
58
- compressionOptions: {
59
- "1.0.0": compressionDefinitions_js_1.disabledCompressionConfig,
60
- "2.0.0-defaults": compressionDefinitions_js_1.enabledCompressionConfig,
61
- },
62
- enableRuntimeIdCompressor: {
63
- // For IdCompressorMode, `undefined` represents a logical state (off).
64
- // However, to satisfy the Required<> constraint while
65
- // `exactOptionalPropertyTypes` is `false` (TODO: AB#8215), we need
66
- // to have it defined, so we trick the type checker here.
67
- "1.0.0": undefined,
68
- // We do not yet want to enable idCompressor by default since it will
69
- // increase bundle sizes, and not all customers will benefit from it.
70
- // Therefore, we will require customers to explicitly enable it. We
71
- // are keeping it as a DocSchema affecting option for now as this may
72
- // change in the future.
73
- },
74
- explicitSchemaControl: {
75
- "1.0.0": false,
76
- // This option's intention is to prevent 1.x clients from joining sessions
77
- // when enabled. This is set to true when the minVersionForCollab is set
78
- // to >=2.0.0 (explicitly). This is different than other 2.0 defaults
79
- // because it was not enabled by default prior to the implementation of
80
- // `minVersionForCollab`.
81
- // `defaultMinVersionForCollab` is set to "2.0.0-defaults" which "2.0.0"
82
- // does not satisfy to avoiding enabling this option by default as of
83
- // `minVersionForCollab` introduction, which could be unexpected.
84
- // Only enable as a default when `minVersionForCollab` is specified at
85
- // 2.0.0+.
86
- "2.0.0": true,
87
- },
88
- flushMode: {
89
- // Note: 1.x clients are compatible with TurnBased flushing, but here we elect to remain on Immediate flush mode
90
- // as a work-around for inability to send batches larger than 1Mb. Immediate flushing keeps batches smaller as
91
- // fewer messages will be included per flush.
92
- "1.0.0": internal_2.FlushMode.Immediate,
93
- "2.0.0-defaults": internal_2.FlushMode.TurnBased,
94
- },
95
- gcOptions: {
96
- "1.0.0": {},
97
- // Although sweep is supported in 2.x, it is disabled by default until minVersionForCollab>=3.0.0 to be extra safe.
98
- "3.0.0": { enableGCSweep: true },
99
- },
100
- createBlobPayloadPending: {
101
- // This feature is new and disabled by default. In the future we will enable it by default, but we have not
102
- // closed on the version where that will happen yet. Probably a .10 release since blob functionality is not
103
- // exposed on the `@public` API surface.
104
- "1.0.0": undefined,
105
- },
106
- };
107
- const runtimeOptionsAffectingDocSchemaConfigValidationMap = {
108
- enableGroupedBatching: configValueToMinVersionForCollab([
109
- [false, "1.0.0"],
110
- [true, "2.0.0-defaults"],
111
- ]),
112
- compressionOptions: configValueToMinVersionForCollab([
113
- [{ ...compressionDefinitions_js_1.disabledCompressionConfig }, "1.0.0"],
114
- [{ ...compressionDefinitions_js_1.enabledCompressionConfig }, "2.0.0-defaults"],
115
- ]),
116
- enableRuntimeIdCompressor: configValueToMinVersionForCollab([
117
- [undefined, "1.0.0"],
118
- ["on", "2.0.0-defaults"],
119
- ["delayed", "2.0.0-defaults"],
120
- ]),
121
- explicitSchemaControl: configValueToMinVersionForCollab([
122
- [false, "1.0.0"],
123
- [true, "2.0.0-defaults"],
124
- ]),
125
- flushMode: configValueToMinVersionForCollab([
126
- [internal_2.FlushMode.Immediate, "1.0.0"],
127
- [internal_2.FlushMode.TurnBased, "2.0.0-defaults"],
128
- ]),
129
- gcOptions: configValueToMinVersionForCollab([
130
- [{ enableGCSweep: undefined }, "1.0.0"],
131
- [{ enableGCSweep: true }, "2.0.0-defaults"],
132
- ]),
133
- createBlobPayloadPending: configValueToMinVersionForCollab([
134
- [undefined, "1.0.0"],
135
- [true, "2.40.0"],
136
- ]),
137
- };
138
- /**
139
- * Returns the default RuntimeOptionsAffectingDocSchema configuration for a given minVersionForCollab.
140
- */
141
- function getMinVersionForCollabDefaults(minVersionForCollab) {
142
- return getConfigsForMinVersionForCollab(minVersionForCollab, runtimeOptionsAffectingDocSchemaConfigMap);
143
- }
144
- exports.getMinVersionForCollabDefaults = getMinVersionForCollabDefaults;
145
- /**
146
- * Returns a default configuration given minVersionForCollab and configuration version map.
147
- */
148
- function getConfigsForMinVersionForCollab(minVersionForCollab, configMap) {
149
- const defaultConfigs = {};
150
- // Iterate over configMap to get default values for each option.
151
- for (const key of Object.keys(configMap)) {
152
- const config = configMap[key];
153
- // Sort the versions in ascending order so we can short circuit the loop.
154
- const versions = Object.keys(config).sort(semver_ts_1.compare);
155
- // For each config, we iterate over the keys and check if minVersionForCollab is greater than or equal to the version.
156
- // If so, we set it as the default value for the option. At the end of the loop we should have the most recent default
157
- // value that is compatible with the version specified as the minVersionForCollab.
158
- for (const version of versions) {
159
- if ((0, semver_ts_1.gte)(minVersionForCollab, version)) {
160
- defaultConfigs[key] = config[version];
161
- }
162
- else {
163
- // If the minVersionForCollab is less than the version, we break out of the loop since we don't need to check
164
- // any later versions.
165
- break;
166
- }
167
- }
168
- }
169
- return defaultConfigs;
170
- }
171
- exports.getConfigsForMinVersionForCollab = getConfigsForMinVersionForCollab;
172
- /**
173
- * Checks if the minVersionForCollab is valid.
174
- * A valid minVersionForCollab is a MinimumVersionForCollab that is at least `lowestMinVersionForCollab` and less than or equal to the current package version.
175
- */
176
- function isValidMinVersionForCollab(minVersionForCollab) {
177
- return ((0, semver_ts_1.valid)(minVersionForCollab) !== null &&
178
- (0, semver_ts_1.gte)(minVersionForCollab, lowestMinVersionForCollab) &&
179
- (0, semver_ts_1.lte)(minVersionForCollab, packageVersion_js_1.pkgVersion));
180
- }
181
- exports.isValidMinVersionForCollab = isValidMinVersionForCollab;
182
- /**
183
- * Validates if the runtime options passed in from the user are compatible with the minVersionForCollab.
184
- * For example, if a user sets the `enableGroupedBatching` option to true, but the minVersionForCollab
185
- * is set to "1.0.0", then we should throw a UsageError since 1.x clients do not support batching.
186
- * */
187
- function validateRuntimeOptions(minVersionForCollab, runtimeOptions) {
188
- getValidationForRuntimeOptions(minVersionForCollab, runtimeOptions, runtimeOptionsAffectingDocSchemaConfigValidationMap);
189
- }
190
- exports.validateRuntimeOptions = validateRuntimeOptions;
191
- /**
192
- * Generic function to validate runtime options against the minVersionForCollab.
193
- */
194
- function getValidationForRuntimeOptions(minVersionForCollab, runtimeOptions, validationMap) {
195
- if (minVersionForCollab === exports.defaultMinVersionForCollab) {
196
- // If the minVersionForCollab is set to the default value, then we will not validate the runtime options
197
- // This is to avoid disruption to users who have not yet set the minVersionForCollab value explicitly.
198
- return;
199
- }
200
- // Iterate through each runtime option passed in by the user
201
- for (const [passedRuntimeOption, passedRuntimeOptionValue] of Object.entries(runtimeOptions)) {
202
- // Skip if passedRuntimeOption is not in validation map
203
- if (!(passedRuntimeOption in validationMap)) {
204
- continue;
205
- }
206
- const requiredVersion = validationMap[passedRuntimeOption](passedRuntimeOptionValue);
207
- if (requiredVersion !== undefined && (0, semver_ts_1.gt)(requiredVersion, minVersionForCollab)) {
208
- throw new internal_3.UsageError(`Runtime option ${passedRuntimeOption}:${JSON.stringify(passedRuntimeOptionValue)} requires ` +
209
- `runtime version ${requiredVersion}. Please update minVersionForCollab ` +
210
- `(currently ${minVersionForCollab}) to ${requiredVersion} or later to proceed.`);
211
- }
212
- }
213
- }
214
- exports.getValidationForRuntimeOptions = getValidationForRuntimeOptions;
215
- /**
216
- * Helper function to map ContainerRuntimeOptionsInternal config values to
217
- * minVersionForCollab in {@link runtimeOptionsAffectingDocSchemaConfigValidationMap}.
218
- */
219
- function configValueToMinVersionForCollab(configToMinVer) {
220
- const configValueToRequiredVersionMap = new Map(configToMinVer);
221
- return (configValue) => {
222
- // If the configValue is not an object then we can get the version required directly from the map.
223
- if (typeof configValue !== "object") {
224
- return configValueToRequiredVersionMap.get(configValue);
225
- }
226
- // When the input `configValue` is an object, this logic determines the minimum runtime version it requires.
227
- // It iterates through each entry in `configValueToRequiredVersionMap`. If `possibleConfigValue` shares at
228
- // least one key-value pair with the input `configValue`, its associated `versionRequired` is collected into
229
- // `matchingVersions`. After checking all entries, the highest among the collected versions is returned.
230
- // This represents the overall minimum version required to support the features implied by the input `configValue`.
231
- const matchingVersions = [];
232
- for (const [possibleConfigValue, versionRequired,] of configValueToRequiredVersionMap.entries()) {
233
- (0, internal_1.assert)(typeof possibleConfigValue == "object", 0xbb9 /* possibleConfigValue should be an object */);
234
- // Check if `possibleConfigValue` and the input `configValue` share at least one
235
- // common key-value pair. If they do, the `versionRequired` for this `possibleConfigValue`
236
- // is added to `matchingVersions`.
237
- if (Object.entries(possibleConfigValue).some(([k, v]) => configValue[k] === v)) {
238
- matchingVersions.push(versionRequired);
239
- }
240
- }
241
- if (matchingVersions.length > 0) {
242
- // Return the latest minVersionForCollab among all matches.
243
- return matchingVersions.sort((a, b) => (0, semver_ts_1.compare)(b, a))[0];
244
- }
245
- // If no matches then we return undefined. This means that the config value passed in
246
- // does not require a specific minVersionForCollab to be valid.
247
- return undefined;
248
- };
249
- }
250
- exports.configValueToMinVersionForCollab = configValueToMinVersionForCollab;
251
- //# sourceMappingURL=compatUtils.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compatUtils.js","sourceRoot":"","sources":["../src/compatUtils.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAC7D,2EAAyE;AACzE,uEAAsE;AACtE,yCAAyD;AAEzD,2EAGqC;AAErC,2DAAiD;AAEjD;;;;;;;;;;;;;;;;;GAiBG;AACU,QAAA,0BAA0B,GACtC,gBAA2D,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,yBAAyB,GAAG,OAAkD,CAAC;AAuErF;;;;;;;;;;;;GAYG;AACH,MAAM,yCAAyC,GAAG;IACjD,qBAAqB,EAA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GAAG,CAAC,EAAE,CAAC;YACjC,2DAA2D;YAC3D,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAA,mBAAO,EAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1D,CAAC;QACD,qFAAqF;QACrF,+DAA+D;QAC/D,OAAO,SAAS,CAAC;IAClB,CAAC,CAAC;AACH,CAAC;AAvCD,4EAuCC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { FlushMode } from \"@fluidframework/runtime-definitions/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { compare, gt, gte, lte, valid } from \"semver-ts\";\n\nimport {\n\tdisabledCompressionConfig,\n\tenabledCompressionConfig,\n} from \"./compressionDefinitions.js\";\nimport type { ContainerRuntimeOptionsInternal } from \"./containerRuntime.js\";\nimport { pkgVersion } from \"./packageVersion.js\";\n\n/**\n * Our policy is to support N/N-1 compatibility by default, where N is the most\n * recent public major release of the runtime.\n * Therefore, if the customer does not provide a minVersionForCollab, we will\n * default to use N-1.\n *\n * However, this is not consistent with today's behavior. Some options (i.e.\n * batching, compression) are enabled by default despite not being compatible\n * with 1.x clients. Since the policy was introduced during 2.x's lifespan,\n * N/N-1 compatibility by **default** will be in effect starting with 3.0.\n * Importantly though, N/N-2 compatibility is still guaranteed with the proper\n * configurations set.\n *\n * Further to distinguish unspecified `minVersionForCollab` from a specified\n * version and allow `enableExplicitSchemaControl` to default to `true` for\n * any 2.0.0+ version, we will use a special value of `2.0.0-defaults`, which\n * is semantically less than 2.0.0.\n */\nexport const defaultMinVersionForCollab =\n\t\"2.0.0-defaults\" as const satisfies MinimumVersionForCollab;\n\n/**\n * We don't want allow a version before the major public release of the LTS version.\n * Today we use \"1.0.0\", because our policy supports N/N-1 & N/N-2, which includes\n * all minor versions of N. Though LTS starts at 1.4.0, we should stay consistent\n * with our policy and allow all 1.x versions to be compatible with 2.x.\n */\nconst lowestMinVersionForCollab = \"1.0.0\" as const satisfies MinimumVersionForCollab;\n\n/**\n * String in a valid semver format specifying bottom of a minor version\n * or special \"defaults\" prerelease of a major.\n * @remarks Only 2.0.0-defaults is expected, but index signatures cannot be a\n * literal; so, just allow any major -defaults prerelease.\n */\nexport type MinimumMinorSemanticVersion = `${bigint}.${bigint}.0` | `${bigint}.0.0-defaults`;\n\n/**\n * String in a valid semver format of a specific version at least specifying minor.\n *\n * @legacy\n * @alpha\n */\nexport type MinimumVersionForCollab =\n\t| `${1 | 2}.${bigint}.${bigint}`\n\t| `${1 | 2}.${bigint}.${bigint}-${string}`;\n\n/**\n * String in a valid semver format of a specific version at least specifying minor.\n * Unlike {@link MinimumVersionForCollab}, this type allows any bigint for the major version.\n * Used as a more generic type that allows major versions other than 1 or 2.\n *\n * @internal\n */\nexport type SemanticVersion =\n\t| `${bigint}.${bigint}.${bigint}`\n\t| `${bigint}.${bigint}.${bigint}-${string}`;\n\n/**\n * Generic type for runtimeOptionsAffectingDocSchemaConfigMap\n */\nexport type ConfigMap<T extends Record<string, unknown>> = {\n\t[K in keyof T]-?: {\n\t\t[version: MinimumMinorSemanticVersion]: T[K];\n\t};\n};\n\n/**\n * Generic type for runtimeOptionsAffectingDocSchemaConfigValidationMap\n */\nexport type ConfigValidationMap<T extends Record<string, unknown>> = {\n\t[K in keyof T]-?: (configValue: T[K]) => SemanticVersion | undefined;\n};\n\n/**\n * Subset of the {@link ContainerRuntimeOptionsInternal} properties which\n * affect {@link IDocumentSchemaFeatures}.\n *\n * @remarks\n * When a new option is added to {@link ContainerRuntimeOptionsInternal}, we\n * must consider if it changes the DocumentSchema. If so, then a corresponding\n * entry must be added to {@link runtimeOptionsAffectingDocSchemaConfigMap}\n * below. If not, then it must be omitted from this type.\n *\n * Note: `Omit` is used instead of `Pick` to ensure that all new options are\n * included in this type by default. If any new properties are added to\n * {@link ContainerRuntimeOptionsInternal}, they will be included in this\n * type unless explicitly omitted. This will prevent us from forgetting to\n * account for any new properties in the future.\n */\nexport type RuntimeOptionsAffectingDocSchema = Omit<\n\tContainerRuntimeOptionsInternal,\n\t| \"chunkSizeInBytes\"\n\t| \"maxBatchSizeInBytes\"\n\t| \"loadSequenceNumberVerification\"\n\t| \"summaryOptions\"\n>;\n\n/**\n * Mapping of RuntimeOptionsAffectingDocSchema to their compatibility related configs.\n *\n * Each key in this map corresponds to a property in RuntimeOptionsAffectingDocSchema. The value is an object that maps MinimumVersionForCollab\n * to the appropriate default value for that property to supporting that MinimumVersionForCollab. If clients running MinimumVersionForCollab X are able to understand\n * the format changes introduced by the property, then the default value for that MinimumVersionForCollab will enable the feature associated with the property.\n * Otherwise, the feature will be disabled.\n *\n * For example if the minVersionForCollab is a 1.x version (i.e. \"1.5.0\"), then the default value for `enableGroupedBatching` will be false since 1.x\n * clients do not understand the document format when batching is enabled. If the minVersionForCollab is a 2.x client (i.e. \"2.0.0\" or later), then the\n * default value for `enableGroupedBatching` will be true because clients running 2.0 or later will be able to understand the format changes associated\n * with the batching feature.\n */\nconst runtimeOptionsAffectingDocSchemaConfigMap = {\n\tenableGroupedBatching: {\n\t\t\"1.0.0\": false,\n\t\t\"2.0.0-defaults\": true,\n\t},\n\tcompressionOptions: {\n\t\t\"1.0.0\": disabledCompressionConfig,\n\t\t\"2.0.0-defaults\": enabledCompressionConfig,\n\t},\n\tenableRuntimeIdCompressor: {\n\t\t// For IdCompressorMode, `undefined` represents a logical state (off).\n\t\t// However, to satisfy the Required<> constraint while\n\t\t// `exactOptionalPropertyTypes` is `false` (TODO: AB#8215), we need\n\t\t// to have it defined, so we trick the type checker here.\n\t\t\"1.0.0\": undefined,\n\t\t// We do not yet want to enable idCompressor by default since it will\n\t\t// increase bundle sizes, and not all customers will benefit from it.\n\t\t// Therefore, we will require customers to explicitly enable it. We\n\t\t// are keeping it as a DocSchema affecting option for now as this may\n\t\t// change in the future.\n\t},\n\texplicitSchemaControl: {\n\t\t\"1.0.0\": false,\n\t\t// This option's intention is to prevent 1.x clients from joining sessions\n\t\t// when enabled. This is set to true when the minVersionForCollab is set\n\t\t// to >=2.0.0 (explicitly). This is different than other 2.0 defaults\n\t\t// because it was not enabled by default prior to the implementation of\n\t\t// `minVersionForCollab`.\n\t\t// `defaultMinVersionForCollab` is set to \"2.0.0-defaults\" which \"2.0.0\"\n\t\t// does not satisfy to avoiding enabling this option by default as of\n\t\t// `minVersionForCollab` introduction, which could be unexpected.\n\t\t// Only enable as a default when `minVersionForCollab` is specified at\n\t\t// 2.0.0+.\n\t\t\"2.0.0\": true,\n\t},\n\tflushMode: {\n\t\t// Note: 1.x clients are compatible with TurnBased flushing, but here we elect to remain on Immediate flush mode\n\t\t// as a work-around for inability to send batches larger than 1Mb. Immediate flushing keeps batches smaller as\n\t\t// fewer messages will be included per flush.\n\t\t\"1.0.0\": FlushMode.Immediate,\n\t\t\"2.0.0-defaults\": FlushMode.TurnBased,\n\t},\n\tgcOptions: {\n\t\t\"1.0.0\": {},\n\t\t// Although sweep is supported in 2.x, it is disabled by default until minVersionForCollab>=3.0.0 to be extra safe.\n\t\t\"3.0.0\": { enableGCSweep: true },\n\t},\n\tcreateBlobPayloadPending: {\n\t\t// This feature is new and disabled by default. In the future we will enable it by default, but we have not\n\t\t// closed on the version where that will happen yet. Probably a .10 release since blob functionality is not\n\t\t// exposed on the `@public` API surface.\n\t\t\"1.0.0\": undefined,\n\t},\n} as const satisfies ConfigMap<RuntimeOptionsAffectingDocSchema>;\n\nconst runtimeOptionsAffectingDocSchemaConfigValidationMap = {\n\tenableGroupedBatching: configValueToMinVersionForCollab([\n\t\t[false, \"1.0.0\"],\n\t\t[true, \"2.0.0-defaults\"],\n\t]),\n\tcompressionOptions: configValueToMinVersionForCollab([\n\t\t[{ ...disabledCompressionConfig }, \"1.0.0\"],\n\t\t[{ ...enabledCompressionConfig }, \"2.0.0-defaults\"],\n\t]),\n\tenableRuntimeIdCompressor: configValueToMinVersionForCollab([\n\t\t[undefined, \"1.0.0\"],\n\t\t[\"on\", \"2.0.0-defaults\"],\n\t\t[\"delayed\", \"2.0.0-defaults\"],\n\t]),\n\texplicitSchemaControl: configValueToMinVersionForCollab([\n\t\t[false, \"1.0.0\"],\n\t\t[true, \"2.0.0-defaults\"],\n\t]),\n\tflushMode: configValueToMinVersionForCollab([\n\t\t[FlushMode.Immediate, \"1.0.0\"],\n\t\t[FlushMode.TurnBased, \"2.0.0-defaults\"],\n\t]),\n\tgcOptions: configValueToMinVersionForCollab([\n\t\t[{ enableGCSweep: undefined }, \"1.0.0\"],\n\t\t[{ enableGCSweep: true }, \"2.0.0-defaults\"],\n\t]),\n\tcreateBlobPayloadPending: configValueToMinVersionForCollab([\n\t\t[undefined, \"1.0.0\"],\n\t\t[true, \"2.40.0\"],\n\t]),\n} as const satisfies ConfigValidationMap<RuntimeOptionsAffectingDocSchema>;\n\n/**\n * Returns the default RuntimeOptionsAffectingDocSchema configuration for a given minVersionForCollab.\n */\nexport function getMinVersionForCollabDefaults(\n\tminVersionForCollab: MinimumVersionForCollab,\n): RuntimeOptionsAffectingDocSchema {\n\treturn getConfigsForMinVersionForCollab(\n\t\tminVersionForCollab,\n\t\truntimeOptionsAffectingDocSchemaConfigMap,\n\t\t// This is a bad cast away from Partial that getConfigsForCompatMode provides.\n\t\t// ConfigMap should be restructured to provide RuntimeOptionsAffectingDocSchema guarantee.\n\t) as RuntimeOptionsAffectingDocSchema;\n}\n\n/**\n * Returns a default configuration given minVersionForCollab and configuration version map.\n */\nexport function getConfigsForMinVersionForCollab<T extends Record<SemanticVersion, unknown>>(\n\tminVersionForCollab: SemanticVersion,\n\tconfigMap: ConfigMap<T>,\n): Partial<T> {\n\tconst defaultConfigs: Partial<T> = {};\n\t// Iterate over configMap to get default values for each option.\n\tfor (const key of Object.keys(configMap)) {\n\t\tconst config = configMap[key as keyof T];\n\t\t// Sort the versions in ascending order so we can short circuit the loop.\n\t\tconst versions = Object.keys(config).sort(compare);\n\t\t// For each config, we iterate over the keys and check if minVersionForCollab is greater than or equal to the version.\n\t\t// If so, we set it as the default value for the option. At the end of the loop we should have the most recent default\n\t\t// value that is compatible with the version specified as the minVersionForCollab.\n\t\tfor (const version of versions) {\n\t\t\tif (gte(minVersionForCollab, version)) {\n\t\t\t\tdefaultConfigs[key] = config[version as MinimumMinorSemanticVersion];\n\t\t\t} else {\n\t\t\t\t// If the minVersionForCollab is less than the version, we break out of the loop since we don't need to check\n\t\t\t\t// any later versions.\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\treturn defaultConfigs;\n}\n\n/**\n * Checks if the minVersionForCollab is valid.\n * A valid minVersionForCollab is a MinimumVersionForCollab that is at least `lowestMinVersionForCollab` and less than or equal to the current package version.\n */\nexport function isValidMinVersionForCollab(\n\tminVersionForCollab: MinimumVersionForCollab,\n): boolean {\n\treturn (\n\t\tvalid(minVersionForCollab) !== null &&\n\t\tgte(minVersionForCollab, lowestMinVersionForCollab) &&\n\t\tlte(minVersionForCollab, pkgVersion)\n\t);\n}\n\n/**\n * Validates if the runtime options passed in from the user are compatible with the minVersionForCollab.\n * For example, if a user sets the `enableGroupedBatching` option to true, but the minVersionForCollab\n * is set to \"1.0.0\", then we should throw a UsageError since 1.x clients do not support batching.\n * */\nexport function validateRuntimeOptions(\n\tminVersionForCollab: MinimumVersionForCollab,\n\truntimeOptions: Partial<ContainerRuntimeOptionsInternal>,\n): void {\n\tgetValidationForRuntimeOptions<RuntimeOptionsAffectingDocSchema>(\n\t\tminVersionForCollab,\n\t\truntimeOptions as Partial<RuntimeOptionsAffectingDocSchema>,\n\t\truntimeOptionsAffectingDocSchemaConfigValidationMap,\n\t);\n}\n\n/**\n * Generic function to validate runtime options against the minVersionForCollab.\n */\nexport function getValidationForRuntimeOptions<T extends Record<string, unknown>>(\n\tminVersionForCollab: SemanticVersion,\n\truntimeOptions: Partial<T>,\n\tvalidationMap: ConfigValidationMap<T>,\n): void {\n\tif (minVersionForCollab === defaultMinVersionForCollab) {\n\t\t// If the minVersionForCollab is set to the default value, then we will not validate the runtime options\n\t\t// This is to avoid disruption to users who have not yet set the minVersionForCollab value explicitly.\n\t\treturn;\n\t}\n\t// Iterate through each runtime option passed in by the user\n\tfor (const [passedRuntimeOption, passedRuntimeOptionValue] of Object.entries(\n\t\truntimeOptions,\n\t) as [keyof T & string, T[keyof T & string]][]) {\n\t\t// Skip if passedRuntimeOption is not in validation map\n\t\tif (!(passedRuntimeOption in validationMap)) {\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst requiredVersion = validationMap[passedRuntimeOption](passedRuntimeOptionValue);\n\t\tif (requiredVersion !== undefined && gt(requiredVersion, minVersionForCollab)) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Runtime option ${passedRuntimeOption}:${JSON.stringify(passedRuntimeOptionValue)} requires ` +\n\t\t\t\t\t`runtime version ${requiredVersion}. Please update minVersionForCollab ` +\n\t\t\t\t\t`(currently ${minVersionForCollab}) to ${requiredVersion} or later to proceed.`,\n\t\t\t);\n\t\t}\n\t}\n}\n\n/**\n * Helper function to map ContainerRuntimeOptionsInternal config values to\n * minVersionForCollab in {@link runtimeOptionsAffectingDocSchemaConfigValidationMap}.\n */\nexport function configValueToMinVersionForCollab<\n\tT extends string | number | boolean | undefined | object,\n\tArr extends readonly [T, SemanticVersion][],\n>(configToMinVer: Arr): (configValue: T) => SemanticVersion | undefined {\n\tconst configValueToRequiredVersionMap = new Map(configToMinVer);\n\treturn (configValue: T) => {\n\t\t// If the configValue is not an object then we can get the version required directly from the map.\n\t\tif (typeof configValue !== \"object\") {\n\t\t\treturn configValueToRequiredVersionMap.get(configValue);\n\t\t}\n\t\t// When the input `configValue` is an object, this logic determines the minimum runtime version it requires.\n\t\t// It iterates through each entry in `configValueToRequiredVersionMap`. If `possibleConfigValue` shares at\n\t\t// least one key-value pair with the input `configValue`, its associated `versionRequired` is collected into\n\t\t// `matchingVersions`. After checking all entries, the highest among the collected versions is returned.\n\t\t// This represents the overall minimum version required to support the features implied by the input `configValue`.\n\t\tconst matchingVersions: SemanticVersion[] = [];\n\t\tfor (const [\n\t\t\tpossibleConfigValue,\n\t\t\tversionRequired,\n\t\t] of configValueToRequiredVersionMap.entries()) {\n\t\t\tassert(\n\t\t\t\ttypeof possibleConfigValue == \"object\",\n\t\t\t\t0xbb9 /* possibleConfigValue should be an object */,\n\t\t\t);\n\t\t\t// Check if `possibleConfigValue` and the input `configValue` share at least one\n\t\t\t// common key-value pair. If they do, the `versionRequired` for this `possibleConfigValue`\n\t\t\t// is added to `matchingVersions`.\n\t\t\tif (Object.entries(possibleConfigValue).some(([k, v]) => configValue[k] === v)) {\n\t\t\t\tmatchingVersions.push(versionRequired);\n\t\t\t}\n\t\t}\n\t\tif (matchingVersions.length > 0) {\n\t\t\t// Return the latest minVersionForCollab among all matches.\n\t\t\treturn matchingVersions.sort((a, b) => compare(b, a))[0];\n\t\t}\n\t\t// If no matches then we return undefined. This means that the config value passed in\n\t\t// does not require a specific minVersionForCollab to be valid.\n\t\treturn undefined;\n\t};\n}\n"]}