Refactor isVersionInfo with json module

This commit is contained in:
Mario Campos
2026-08-14 11:28:36 -05:00
parent d7d901a925
commit c8ba2d2a05
3 changed files with 46 additions and 25 deletions

View File

@@ -1,6 +1,11 @@
export interface VersionInfo {
version: string;
features?: { [name: string]: boolean };
import * as json from "../json";
/**
* The JSON schema of the expected output of the `codeql version` command.
*/
export const versionInfoBaseSchema = {
version: json.string,
features: json.optional(json.object({})),
/**
* The overlay version helps deal with backward incompatible changes for
* overlay analysis. When a precompiled query pack reports the same overlay
@@ -9,5 +14,21 @@ export interface VersionInfo {
* or if either the pack or the CLI does not report an overlay version,
* we need to revert to non-overlay analysis.
*/
overlayVersion?: number;
}
overlayVersion: json.optional(json.number),
} as const satisfies json.Schema;
/**
* The base type that describes the expected output of the `codeql version` command.
* This type is partially derived from {@link versionInfoBaseSchema}.
*/
export type VersionInfoBase = json.FromSchema<typeof versionInfoBaseSchema>;
/**
* The full type that describes the expected output of the `codeql version` command.
* This type is partially derived from {@link VersionInfoBase}.
*/
export type VersionInfo = VersionInfoBase & {
// `features` remains optional, but the more specific type takes precedence
// over the `any` type derived by `FromSchema`.
features?: { [name: string]: boolean };
};