diff --git a/lib/entry-points.js b/lib/entry-points.js index 335aa3905..277472778 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -146744,6 +146744,10 @@ var versionInfoBaseSchema = { }; // src/cli/output-cache.ts +var outputCacheSchema = { + cmd: string, + entries: object({}) +}; var COMMAND_CACHE_FILENAME = "codeql-action-command-cache.json"; var cachedCodeQlVersion = void 0; function getCommandCacheFilePath(env) { @@ -146794,13 +146798,7 @@ function isVersionInfo(x) { return isObject(x) && validateSchema(versionInfoBaseSchema, x); } function isOutputCache(x) { - return isObject(x) && validateSchema( - { - cmd: string, - entries: object({}) - }, - x - ) && isObject(x.entries) && isVersionInfo(x.entries.version); + return isObject(x) && validateSchema(outputCacheSchema, 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 bc91e88bd..51e74e8a4 100644 --- a/src/cli/output-cache.ts +++ b/src/cli/output-cache.ts @@ -14,12 +14,20 @@ import { VersionInfo, versionInfoBaseSchema } from "./types"; export type CommandCacheKey = string; /** - * The type of the command cache that is persisted to disk. + * The JSON schema of the command cache that is persisted to disk. */ -export interface OutputCache { - cmd: string; - entries: Record; -} +const outputCacheSchema = { + cmd: json.string, + entries: json.object({}), +} as const satisfies json.Schema; + +/** + * The type that describes the command cache that is persisted to disk. This type + * is partially derived from {@link outputCacheSchema}. + */ +export type OutputCache = json.FromSchema & { + entries: { version: VersionInfo }; +}; /** * The name of the temporary file that backs the on-disk cache of @@ -138,13 +146,7 @@ function isVersionInfo(x: unknown): x is VersionInfo { function isOutputCache(x: unknown): x is OutputCache { return ( json.isObject(x) && - json.validateSchema( - { - cmd: json.string, - entries: json.object({}), - } as const satisfies json.Schema, - x, - ) && + json.validateSchema(outputCacheSchema, x) && json.isObject<{ version: unknown }>(x.entries) && isVersionInfo(x.entries.version) );