Repository navigation
Expand file tree
/
Copy pathloaderLayerCompatState.ts
More file actions
191 lines (181 loc) · 6.11 KB
/
Copy pathloaderLayerCompatState.ts
File metadata and controls
191 lines (181 loc) · 6.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*!
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
* Licensed under the MIT License.
*/
import {
generation,
defaultLayerCompatDetails,
LayerCompatibilityPolicyWindowMonths,
type ILayerCompatDetails,
type ILayerCompatSupportRequirements,
} from "@fluid-internal/client-utils";
import type { ICriticalContainerError } from "@fluidframework/container-definitions";
import {
validateLayerCompatibility,
type MonitoringContext,
} from "@fluidframework/telemetry-utils/internal";
import { pkgVersion } from "./packageVersion.js";
/**
* The core compatibility details of the Loader layer that is the same across all layer boundaries.
* @internal
*/
export const loaderCoreCompatDetails = {
/**
* The package version of the Loader layer.
*/
pkgVersion,
/**
* The current generation of the Loader layer.
*/
generation,
} as const;
/**
* Loader's compatibility details that is exposed to the Runtime layer.
* @internal
*/
export const loaderCompatDetailsForRuntime: ILayerCompatDetails = {
...loaderCoreCompatDetails,
/**
* The features supported by the Loader layer across the Loader / Runtime boundary.
*/
supportedFeatures: new Set<string>(),
};
/**
* Loader's compatibility details that is validated against the Driver layer's requirements.
* @internal
*/
export const loaderCompatDetailsForDriver: ILayerCompatDetails = {
...loaderCoreCompatDetails,
/**
* The features supported by the Loader layer across the Loader / Driver boundary.
*/
supportedFeatures: new Set<string>(),
};
/**
* The requirements that the Runtime layer must meet to be compatible with this Loader.
* @internal
*/
export const runtimeSupportRequirementsForLoader: ILayerCompatSupportRequirements = {
/**
* Minimum generation that Runtime must be at to be compatible with this Loader. This is calculated
* based on the LayerCompatibilityPolicyWindowMonths.NewLoaderOldRuntime value which defines how many months
* old can the Runtime layer be compared to the Loader layer for them to still be considered compatible.
* The minimum valid generation value is 0.
*/
minSupportedGeneration: Math.max(
0,
loaderCoreCompatDetails.generation -
LayerCompatibilityPolicyWindowMonths.NewLoaderOldRuntime,
),
/**
* The features that the Runtime must support to be compatible with Loader.
*/
requiredFeatures: [],
};
/**
* The requirements that the Driver layer must meet to be compatible with this Loader.
* @internal
*/
export const driverSupportRequirementsForLoader: ILayerCompatSupportRequirements = {
/**
* Minimum generation that Driver must be at to be compatible with this Loader. This is calculated
* based on the LayerCompatibilityPolicyWindowMonths.NewLoaderOldDriver value which defines how many months
* old can the Driver layer be compared to the Loader layer for them to still be considered compatible.
* The minimum valid generation value is 0.
*/
minSupportedGeneration: Math.max(
0,
loaderCoreCompatDetails.generation -
LayerCompatibilityPolicyWindowMonths.NewLoaderOldDriver,
),
/**
* The features that the Driver must support to be compatible with Loader.
*/
requiredFeatures: [],
};
/**
* Validates that the Runtime layer is compatible with the Loader. *
* @internal
*/
export function validateRuntimeCompatibility(
maybeRuntimeCompatDetails: ILayerCompatDetails | undefined,
mc: MonitoringContext,
): void {
validateLayerCompatibility(
/* validatingLayer */ {
layer: "loader",
packageInfo: loaderCoreCompatDetails,
compatSupportRequirements: runtimeSupportRequirementsForLoader,
},
/* targetLayer */ {
layer: "runtime",
compatDetails: maybeRuntimeCompatDetails,
},
{
disposeFn: () => {} /* no op. This will be handled by the caller */,
mc,
},
);
}
/**
* Validates that the Driver layer is compatible with the Loader.
* @internal
*/
export function validateDriverCompatibility(
maybeDriverCompatDetails: ILayerCompatDetails | undefined,
disposeFn: (error?: ICriticalContainerError) => void,
mc: MonitoringContext,
): void {
validateLayerCompatibility(
/* validatingLayer */ {
layer: "loader",
packageInfo: loaderCoreCompatDetails,
compatSupportRequirements: driverSupportRequirementsForLoader,
},
/* targetLayer */ {
layer: "driver",
compatDetails: maybeDriverCompatDetails,
},
{ disposeFn, mc },
);
}
/**
* Validates that the Loader layer is compatible with the Driver.
*
* @remarks
* This is the reverse of {@link validateDriverCompatibility} and is intentionally a separate function because it
* does not follow the standard layer-validation pattern. Normally each layer validates the layer it holds a
* reference to - the Loader validates the Driver, the Runtime validates the Loader, and so on. The Driver, however,
* has no reference to the Loader and therefore cannot run this validation itself. To still enforce compatibility in
* both directions across the Driver / Loader boundary, the Driver publishes the requirements it has for the Loader
* (via ILayerCompatSupportRequirements) and the Loader validates itself against them here, on the Driver's behalf.
*
* @param maybeDriverCompatDetails - The Driver's compatibility details, used only to attribute the version /
* generation of the Driver in telemetry if the Loader is found to be incompatible.
* @param maybeDriverCompatRequirements - The requirements the Driver has for the Loader. Older Drivers may not
* publish these, in which case there is nothing to validate in this direction.
*
* @internal
*/
export function validateLoaderCompatibilityWithDriver(
maybeDriverCompatDetails: ILayerCompatDetails | undefined,
maybeDriverCompatRequirements: ILayerCompatSupportRequirements | undefined,
disposeFn: (error?: ICriticalContainerError) => void,
mc: MonitoringContext,
): void {
if (maybeDriverCompatRequirements === undefined) {
return;
}
validateLayerCompatibility(
/* validatingLayer */ {
layer: "driver",
packageInfo: maybeDriverCompatDetails ?? defaultLayerCompatDetails,
compatSupportRequirements: maybeDriverCompatRequirements,
},
/* targetLayer */ {
layer: "loader",
compatDetails: loaderCompatDetailsForDriver,
},
{ disposeFn, mc },
);
}