mirror of
https://github.com/github/codeql-action.git
synced 2026-10-03 17:41:28 +00:00
Refactor OutputCache with json module
This commit is contained in:
12
lib/entry-points.js
generated
12
lib/entry-points.js
generated
@@ -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
|
||||
|
||||
@@ -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)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user