Skip to content

Commit f3deecb

Browse files
committed
Refactor OutputCache with json module
1 parent c8ba2d2 commit f3deecb

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

lib/entry-points.js

Lines changed: 5 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli/output-cache.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,20 @@ import { VersionInfo, versionInfoBaseSchema } from "./types";
1414
export type CommandCacheKey = string;
1515

1616
/**
17-
* The type of the command cache that is persisted to disk.
17+
* The JSON schema of the command cache that is persisted to disk.
1818
*/
19-
export interface OutputCache {
20-
cmd: string;
21-
entries: Record<CommandCacheKey, unknown>;
22-
}
19+
const outputCacheSchema = {
20+
cmd: json.string,
21+
entries: json.object({}),
22+
} as const satisfies json.Schema;
23+
24+
/**
25+
* The type that describes the command cache that is persisted to disk. This type
26+
* is partially derived from {@link outputCacheSchema}.
27+
*/
28+
export type OutputCache = json.FromSchema<typeof outputCacheSchema> & {
29+
entries: { version: VersionInfo };
30+
};
2331

2432
/**
2533
* The name of the temporary file that backs the on-disk cache of
@@ -138,13 +146,7 @@ function isVersionInfo(x: unknown): x is VersionInfo {
138146
function isOutputCache(x: unknown): x is OutputCache {
139147
return (
140148
json.isObject(x) &&
141-
json.validateSchema(
142-
{
143-
cmd: json.string,
144-
entries: json.object({}),
145-
} as const satisfies json.Schema,
146-
x,
147-
) &&
149+
json.validateSchema(outputCacheSchema, x) &&
148150
json.isObject<{ version: unknown }>(x.entries) &&
149151
isVersionInfo(x.entries.version)
150152
);

0 commit comments

Comments
 (0)