Skip to content
Snippets Groups Projects
Unverified Commit 9e2c81f0 authored by Sergei Zharinov's avatar Sergei Zharinov Committed by GitHub
Browse files

refactor(cache): Explicit types for different cache revisions (#17362)

parent 8f8f059d
No related branches found
No related tags found
No related merge requests found
import is from '@sindresorhus/is'; import is from '@sindresorhus/is';
import type { RepoCacheData, RepoCacheRecord } from './types'; import type {
RepoCacheRecordV10,
RepoCacheRecordV11,
RepoCacheRecordV12,
} from './types';
// Increment this whenever there could be incompatibilities between old and new cache structure // Increment this whenever there could be incompatibilities between old and new cache structure
export const CACHE_REVISION = 12; export const CACHE_REVISION = 12;
...@@ -7,7 +11,7 @@ export const CACHE_REVISION = 12; ...@@ -7,7 +11,7 @@ export const CACHE_REVISION = 12;
export function isValidRev10( export function isValidRev10(
input: unknown, input: unknown,
repo?: string repo?: string
): input is RepoCacheData & { repository?: string; revision?: number } { ): input is RepoCacheRecordV10 {
return ( return (
is.plainObject(input) && is.plainObject(input) &&
is.safeInteger(input.revision) && is.safeInteger(input.revision) &&
...@@ -20,7 +24,7 @@ export function isValidRev10( ...@@ -20,7 +24,7 @@ export function isValidRev10(
export function isValidRev11( export function isValidRev11(
input: unknown, input: unknown,
repo?: string repo?: string
): input is { repository: string; revision: number; data: RepoCacheData } { ): input is RepoCacheRecordV11 {
return ( return (
is.plainObject(input) && is.plainObject(input) &&
is.safeInteger(input.revision) && is.safeInteger(input.revision) &&
...@@ -34,7 +38,7 @@ export function isValidRev11( ...@@ -34,7 +38,7 @@ export function isValidRev11(
export function isValidRev12( export function isValidRev12(
input: unknown, input: unknown,
repo?: string repo?: string
): input is RepoCacheRecord { ): input is RepoCacheRecordV12 {
return ( return (
is.plainObject(input) && is.plainObject(input) &&
is.safeInteger(input.revision) && is.safeInteger(input.revision) &&
......
...@@ -47,13 +47,26 @@ export interface RepoCacheData { ...@@ -47,13 +47,26 @@ export interface RepoCacheData {
prComments?: Record<number, Record<string, string>>; prComments?: Record<number, Record<string, string>>;
} }
export interface RepoCacheRecord { export interface RepoCacheRecordV10 extends RepoCacheData {
repository?: string;
revision?: number;
}
export interface RepoCacheRecordV11 {
repository: string;
revision: number;
data: RepoCacheData;
}
export interface RepoCacheRecordV12 {
repository: string; repository: string;
revision: number; revision: number;
payload: string; payload: string;
hash: string; hash: string;
} }
export type RepoCacheRecord = RepoCacheRecordV12;
export interface RepoCache { export interface RepoCache {
load(): Promise<void>; load(): Promise<void>;
save(): Promise<void>; save(): Promise<void>;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment