From da5c5ed3f61f02ed69b67b7117d736a38ae9779f Mon Sep 17 00:00:00 2001 From: Sergei Zharinov <zharinov@users.noreply.github.com> Date: Wed, 22 Jan 2025 18:48:43 -0300 Subject: [PATCH] feat: Drop older `timeStamp` field support (#33734) --- .../cache/abstract-http-cache-provider.ts | 4 +-- .../repository-http-cache-provider.spec.ts | 23 +------------ .../cache/repository-http-cache-provider.ts | 2 +- lib/util/http/cache/schema.ts | 34 +++++-------------- lib/util/http/cache/types.ts | 7 ---- 5 files changed, 12 insertions(+), 58 deletions(-) diff --git a/lib/util/http/cache/abstract-http-cache-provider.ts b/lib/util/http/cache/abstract-http-cache-provider.ts index 938e60b836..3204cd24bf 100644 --- a/lib/util/http/cache/abstract-http-cache-provider.ts +++ b/lib/util/http/cache/abstract-http-cache-provider.ts @@ -2,8 +2,8 @@ import { logger } from '../../../logger'; import { HttpCacheStats } from '../../stats'; import type { GotOptions, HttpResponse } from '../types'; import { copyResponse } from '../util'; -import { HttpCacheSchema } from './schema'; -import type { HttpCache, HttpCacheProvider } from './types'; +import { type HttpCache, HttpCacheSchema } from './schema'; +import type { HttpCacheProvider } from './types'; export abstract class AbstractHttpCacheProvider implements HttpCacheProvider { protected abstract load(url: string): Promise<unknown>; diff --git a/lib/util/http/cache/repository-http-cache-provider.spec.ts b/lib/util/http/cache/repository-http-cache-provider.spec.ts index da8c1806d0..5b070114ce 100644 --- a/lib/util/http/cache/repository-http-cache-provider.spec.ts +++ b/lib/util/http/cache/repository-http-cache-provider.spec.ts @@ -1,7 +1,7 @@ import { Http } from '..'; import * as httpMock from '../../../../test/http-mock'; import { logger } from '../../../../test/util'; -import { getCache, resetCache } from '../../cache/repository'; +import { resetCache } from '../../cache/repository'; import { repoCacheProvider } from './repository-http-cache-provider'; describe('util/http/cache/repository-http-cache-provider', () => { @@ -59,27 +59,6 @@ describe('util/http/cache/repository-http-cache-provider', () => { }); }); - it('uses older cache format', async () => { - const repoCache = getCache(); - repoCache.httpCache = { - 'https://example.com/foo/bar': { - etag: '123', - lastModified: 'Mon, 01 Jan 2000 00:00:00 GMT', - httpResponse: { statusCode: 200, body: { msg: 'Hello, world!' } }, - timeStamp: new Date().toISOString(), - }, - }; - httpMock.scope('https://example.com').get('/foo/bar').reply(304); - - const res = await http.getJsonUnchecked('https://example.com/foo/bar'); - - expect(res).toMatchObject({ - statusCode: 200, - body: { msg: 'Hello, world!' }, - authorization: false, - }); - }); - it('reports if cache could not be persisted', async () => { httpMock .scope('https://example.com') diff --git a/lib/util/http/cache/repository-http-cache-provider.ts b/lib/util/http/cache/repository-http-cache-provider.ts index 9cf9c8cfa3..8ec1909d19 100644 --- a/lib/util/http/cache/repository-http-cache-provider.ts +++ b/lib/util/http/cache/repository-http-cache-provider.ts @@ -1,6 +1,6 @@ import { getCache } from '../../cache/repository'; import { AbstractHttpCacheProvider } from './abstract-http-cache-provider'; -import type { HttpCache } from './types'; +import type { HttpCache } from './schema'; export class RepositoryHttpCacheProvider extends AbstractHttpCacheProvider { override load(url: string): Promise<unknown> { diff --git a/lib/util/http/cache/schema.ts b/lib/util/http/cache/schema.ts index d1d71fda9b..c9b9db1e29 100644 --- a/lib/util/http/cache/schema.ts +++ b/lib/util/http/cache/schema.ts @@ -1,34 +1,16 @@ import { z } from 'zod'; -const invalidFieldsMsg = - 'Cache object should have `etag` or `lastModified` fields'; - export const HttpCacheSchema = z .object({ - // TODO: remove this migration part during the Christmas eve 2024 - timeStamp: z.string().optional(), - timestamp: z.string().optional(), - }) - .passthrough() - .transform((data) => { - if (data.timeStamp) { - data.timestamp = data.timeStamp; - delete data.timeStamp; - } - return data; + etag: z.string().optional(), + lastModified: z.string().optional(), + httpResponse: z.unknown(), + timestamp: z.string(), }) - .pipe( - z - .object({ - etag: z.string().optional(), - lastModified: z.string().optional(), - httpResponse: z.unknown(), - timestamp: z.string(), - }) - .refine( - ({ etag, lastModified }) => etag ?? lastModified, - invalidFieldsMsg, - ), + .refine( + ({ etag, lastModified }) => etag ?? lastModified, + 'Cache object should have `etag` or `lastModified` fields', ) .nullable() .catch(null); +export type HttpCache = z.infer<typeof HttpCacheSchema>; diff --git a/lib/util/http/cache/types.ts b/lib/util/http/cache/types.ts index 1159f58028..d6ab883112 100644 --- a/lib/util/http/cache/types.ts +++ b/lib/util/http/cache/types.ts @@ -1,12 +1,5 @@ import type { GotOptions, HttpResponse } from '../types'; -export interface HttpCache { - etag?: string; - lastModified?: string; - httpResponse: unknown; - timestamp: string; -} - export interface HttpCacheProvider { setCacheHeaders<T extends Pick<GotOptions, 'headers'>>( url: string, -- GitLab