forked from web-platform-dx/web-features
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassertions.ts
More file actions
29 lines (27 loc) · 952 Bytes
/
assertions.ts
File metadata and controls
29 lines (27 loc) · 952 Bytes
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
import { isOrdinaryFeatureData } from "./type-guards";
import { WebFeaturesData } from "./types.quicktype";
/**
* Assert that a reference from one feature to another is an ordinary feature
* reference (i.e., it's defined and not some kind of redirect).
*
* @export
* @param {string} sourceId The feature that is referencing another feature
* @param {string} targetId The feature being referenced
* @param {WebFeaturesData["features"]} features Feature data
*/
export function assertValidFeatureReference(
sourceId: string,
targetId: string,
features: WebFeaturesData["features"],
) {
const target: unknown = features[targetId];
if (target === undefined) {
throw new Error(`${sourceId} references a non-existent feature`);
}
if (!isOrdinaryFeatureData(target)) {
throw new Error(
`${sourceId} references a redirect "${targetId} instead of an ordinary feature ID`,
);
}
}
// TODO: assertValidSnapshotReference