Files
Sebastian Poxhofer c0501194c0 feat(datasource/gitlab-packages): replace getJsonUnchecked with validated getJson (#44143)
* fix(datasource/gitlab-packages): replace getJsonUnchecked with validated getJson

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* fix(datasource/gitlab-packages): use LooseArray and drop types.ts

Apply review feedback: tolerate malformed entries via LooseArray, remove
the now unused types.ts, use the fetchJson base helper and cover the
failed validation paths.

* fix(datasource/gitlab-packages): accept null for optional fields

Wrap the package schema in DeepNullish so a null conan_package_name
validates like an absent one.

* refactor(datasource/gitlab-packages): map releases in schema transform

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-08 12:14:07 +00:00

27 lines
768 B
TypeScript

import { z } from 'zod/v4';
import { DeepNullish, LooseArray } from '../../../util/schema-utils/index.ts';
import { asTimestamp } from '../../../util/timestamp.ts';
import type { Release } from '../types.ts';
export const GitlabPackage = DeepNullish(
z.object({
version: z.string(),
created_at: z.string(),
name: z.string(),
conan_package_name: z.string().optional(),
}),
).transform(
({
version,
created_at,
name,
conan_package_name,
}): { packageName: string; release: Release } => ({
packageName: conan_package_name ?? name,
release: { version, releaseTimestamp: asTimestamp(created_at) },
}),
);
export type GitlabPackage = z.infer<typeof GitlabPackage>;
export const GitlabPackages = LooseArray(GitlabPackage);