mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-27 07:50:47 +00:00
15f4bd8eff
* chore: migrate from zod/v3 to zod/v4 This commit contains the logic changes * chore: migrate imports from zod/v3 to zod/v4 This contains import updates and adds explicit record keys as zod/v4 requires these now * ci: enforce usage of zod/v4
69 lines
1.6 KiB
TypeScript
69 lines
1.6 KiB
TypeScript
import { z } from 'zod/v4';
|
|
import { LooseArray } from '../../../util/schema-utils/index.ts';
|
|
import { MaybeTimestamp } from '../../../util/timestamp.ts';
|
|
import type { CpanRelease } from './types.ts';
|
|
|
|
/**
|
|
* https://fastapi.metacpan.org/v1/file/_mapping
|
|
*/
|
|
const MetaCpanApiFile = z
|
|
.object({
|
|
module: LooseArray(
|
|
z.object({
|
|
name: z.string(),
|
|
version: z.string(),
|
|
}),
|
|
),
|
|
distribution: z.string(),
|
|
date: MaybeTimestamp,
|
|
deprecated: z.boolean(),
|
|
maturity: z.string(),
|
|
status: z.union([
|
|
z.literal('backpan'),
|
|
z.literal('cpan'),
|
|
z.literal('latest'),
|
|
]),
|
|
})
|
|
.transform(
|
|
({
|
|
module,
|
|
distribution,
|
|
date,
|
|
deprecated,
|
|
maturity,
|
|
status,
|
|
}): CpanRelease | undefined => {
|
|
if (!module[0]?.version) {
|
|
return undefined;
|
|
}
|
|
return {
|
|
version: module[0].version,
|
|
distribution,
|
|
isDeprecated: deprecated,
|
|
isStable: maturity === 'released',
|
|
releaseTimestamp: date,
|
|
isLatest: status === 'latest',
|
|
};
|
|
},
|
|
)
|
|
.catch(undefined);
|
|
/**
|
|
* https://github.com/metacpan/metacpan-api/blob/master/docs/API-docs.md#available-fields
|
|
*/
|
|
export const MetaCpanApiFileSearchResponse = z
|
|
.object({
|
|
hits: z.object({
|
|
hits: LooseArray(
|
|
z.object({
|
|
_source: MetaCpanApiFile,
|
|
}),
|
|
),
|
|
}),
|
|
})
|
|
.transform((data): CpanRelease[] => {
|
|
// Extract all hits and filter out ones where _source transformed to undefined
|
|
return data.hits.hits
|
|
.map((hit) => hit._source)
|
|
.filter((source) => source !== undefined);
|
|
});
|