-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathscenario-schema.ts
More file actions
39 lines (34 loc) · 1.26 KB
/
scenario-schema.ts
File metadata and controls
39 lines (34 loc) · 1.26 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
import type { ScenarioDefinition } from "../types.ts";
export function isScenarioDefinition(
value: unknown,
): value is ScenarioDefinition {
if (typeof value !== "object" || value === null) {
return false;
}
const obj = value as Record<string, unknown>;
return (
typeof obj.description === "string" &&
typeof obj.repo === "string" &&
typeof obj.commit === "string" &&
(obj.packageManager === "npm" ||
obj.packageManager === "bun" ||
obj.packageManager === "pnpm" ||
obj.packageManager === "yarn") &&
typeof obj.defaultCommand === "string" &&
Array.isArray(obj.tags) &&
obj.tags.every((t: unknown) => typeof t === "string") &&
(obj.env === undefined || isStringRecord(obj.env)) &&
(obj.preinstall === undefined || typeof obj.preinstall === "string") &&
(obj.install === undefined || typeof obj.install === "string") &&
(obj.submodules === undefined || typeof obj.submodules === "boolean") &&
(obj.disabled === undefined || obj.disabled === true)
);
}
function isStringRecord(value: unknown): value is Record<string, string> {
if (typeof value !== "object" || value === null) {
return false;
}
return Object.values(value as Record<string, unknown>).every(
(v) => typeof v === "string",
);
}