diff --git a/lib/entry-points.js b/lib/entry-points.js index 56914e8848..627d51c28b 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -146774,12 +146774,23 @@ function getCachedCodeQlVersion(logger, env, cmd) { return cachedCodeQlVersion; } function isVersionInfo(x) { - const candidate = x; - return typeof candidate === "object" && candidate !== null && typeof candidate.version === "string" && (candidate.features === void 0 || typeof candidate.features === "object" && candidate.features !== null) && (candidate.overlayVersion === void 0 || typeof candidate.overlayVersion === "number"); + return isObject(x) && validateSchema( + { + version: string, + features: optional(object({})), + overlayVersion: optional(number) + }, + x + ); } function isOutputCache(x) { - const candidate = x; - return typeof candidate === "object" && candidate !== null && typeof candidate.cmd === "string" && candidate.entries !== void 0 && isVersionInfo(candidate.entries.version); + return isObject(x) && validateSchema( + { + cmd: string, + entries: object({}) + }, + x + ) && isObject(x.entries) && isVersionInfo(x.entries.version); } // src/config/pack-registries.ts diff --git a/src/cli/output-cache.ts b/src/cli/output-cache.ts index 8bf8c27abe..f27167c427 100644 --- a/src/cli/output-cache.ts +++ b/src/cli/output-cache.ts @@ -3,6 +3,7 @@ import path from "path"; import { getTemporaryDirectory } from "../actions-util"; import { Env } from "../environment"; +import * as json from "../json"; import { Logger } from "../logging"; import type { VersionInfo } from "./types"; @@ -127,16 +128,16 @@ export function getCachedCodeQlVersion( * @param x The value to test */ function isVersionInfo(x: unknown): x is VersionInfo { - const candidate = x as Partial | null; return ( - typeof candidate === "object" && - candidate !== null && - typeof candidate.version === "string" && - (candidate.features === undefined || - (typeof candidate.features === "object" && - candidate.features !== null)) && - (candidate.overlayVersion === undefined || - typeof candidate.overlayVersion === "number") + json.isObject(x) && + json.validateSchema( + { + version: json.string, + features: json.optional(json.object({})), + overlayVersion: json.optional(json.number), + } as const satisfies json.Schema, + x, + ) ); } @@ -145,12 +146,16 @@ function isVersionInfo(x: unknown): x is VersionInfo { * @param x The value to test */ function isOutputCache(x: unknown): x is OutputCache { - const candidate = x as Partial | null; return ( - typeof candidate === "object" && - candidate !== null && - typeof candidate.cmd === "string" && - candidate.entries !== undefined && - isVersionInfo(candidate.entries.version) + json.isObject(x) && + json.validateSchema( + { + cmd: json.string, + entries: json.object({}), + } as const satisfies json.Schema, + x, + ) && + json.isObject<{ version: unknown }>(x.entries) && + isVersionInfo(x.entries.version) ); }