From 9e2c81f0efbe5f031fd24dc577f93ea8b174bb36 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov <zharinov@users.noreply.github.com> Date: Tue, 23 Aug 2022 18:35:09 +0300 Subject: [PATCH] refactor(cache): Explicit types for different cache revisions (#17362) --- lib/util/cache/repository/common.ts | 12 ++++++++---- lib/util/cache/repository/types.ts | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/util/cache/repository/common.ts b/lib/util/cache/repository/common.ts index 11cb26a26a..eb31e92242 100644 --- a/lib/util/cache/repository/common.ts +++ b/lib/util/cache/repository/common.ts @@ -1,5 +1,9 @@ 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 export const CACHE_REVISION = 12; @@ -7,7 +11,7 @@ export const CACHE_REVISION = 12; export function isValidRev10( input: unknown, repo?: string -): input is RepoCacheData & { repository?: string; revision?: number } { +): input is RepoCacheRecordV10 { return ( is.plainObject(input) && is.safeInteger(input.revision) && @@ -20,7 +24,7 @@ export function isValidRev10( export function isValidRev11( input: unknown, repo?: string -): input is { repository: string; revision: number; data: RepoCacheData } { +): input is RepoCacheRecordV11 { return ( is.plainObject(input) && is.safeInteger(input.revision) && @@ -34,7 +38,7 @@ export function isValidRev11( export function isValidRev12( input: unknown, repo?: string -): input is RepoCacheRecord { +): input is RepoCacheRecordV12 { return ( is.plainObject(input) && is.safeInteger(input.revision) && diff --git a/lib/util/cache/repository/types.ts b/lib/util/cache/repository/types.ts index ceda2315f9..3a24bab188 100644 --- a/lib/util/cache/repository/types.ts +++ b/lib/util/cache/repository/types.ts @@ -47,13 +47,26 @@ export interface RepoCacheData { 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; revision: number; payload: string; hash: string; } +export type RepoCacheRecord = RepoCacheRecordV12; + export interface RepoCache { load(): Promise<void>; save(): Promise<void>; -- GitLab