Refactor OutputCache with json module

This commit is contained in:
Mario Campos
2026-08-14 11:38:38 -05:00
parent c8ba2d2a05
commit f3deecb42d
2 changed files with 19 additions and 19 deletions

12
lib/entry-points.js generated
View File

@@ -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

View File

@@ -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<CommandCacheKey, unknown>;
}
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<typeof outputCacheSchema> & {
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)
);