@@ -3,6 +3,7 @@ import path from "path";
33
44import { getTemporaryDirectory } from "../actions-util" ;
55import { Env } from "../environment" ;
6+ import * as json from "../json" ;
67import { Logger } from "../logging" ;
78
89import type { VersionInfo } from "./types" ;
@@ -127,16 +128,16 @@ export function getCachedCodeQlVersion(
127128 * @param x The value to test
128129 */
129130function isVersionInfo ( x : unknown ) : x is VersionInfo {
130- const candidate = x as Partial < VersionInfo > | null ;
131131 return (
132- typeof candidate === "object" &&
133- candidate !== null &&
134- typeof candidate . version === "string" &&
135- ( candidate . features === undefined ||
136- ( typeof candidate . features === "object" &&
137- candidate . features !== null ) ) &&
138- ( candidate . overlayVersion === undefined ||
139- typeof candidate . overlayVersion === "number" )
132+ json . isObject ( x ) &&
133+ json . validateSchema (
134+ {
135+ version : json . string ,
136+ features : json . optional ( json . object ( { } ) ) ,
137+ overlayVersion : json . optional ( json . number ) ,
138+ } as const satisfies json . Schema ,
139+ x ,
140+ )
140141 ) ;
141142}
142143
@@ -145,12 +146,16 @@ function isVersionInfo(x: unknown): x is VersionInfo {
145146 * @param x The value to test
146147 */
147148function isOutputCache ( x : unknown ) : x is OutputCache {
148- const candidate = x as Partial < OutputCache > | null ;
149149 return (
150- typeof candidate === "object" &&
151- candidate !== null &&
152- typeof candidate . cmd === "string" &&
153- candidate . entries !== undefined &&
154- isVersionInfo ( candidate . entries . version )
150+ json . isObject ( x ) &&
151+ json . validateSchema (
152+ {
153+ cmd : json . string ,
154+ entries : json . object ( { } ) ,
155+ } as const satisfies json . Schema ,
156+ x ,
157+ ) &&
158+ json . isObject < { version : unknown } > ( x . entries ) &&
159+ isVersionInfo ( x . entries . version )
155160 ) ;
156161}
0 commit comments