Files
Sebastian Poxhofer be4d2e0892 refactor(nuget): replace getJsonUnchecked with schema validated getJson (#43700)
* fix(nuget): replace getJsonUnchecked with validated getJson

Migrate NuGet v3 datasource from unvalidated HTTP responses to Zod-schema
validated ones. Creates schema.ts with ServicesIndexRaw, CatalogPage, and
PackageRegistration schemas derived from the existing TypeScript interfaces.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* fix(nuget): migrate zod import from v3 to v4

Update schema.ts to use 'zod/v4' instead of 'zod/v3' following the
upstream migration in renovatebot/renovate PR #43691.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* chore: some manual improvements

* refactor: rename schema

* fix linter errors

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-03 12:26:44 +00:00

47 lines
1.2 KiB
TypeScript

import { z } from 'zod/v4';
import { LooseArray } from '../../../util/schema-utils/index.ts';
export const ServicesIndexRaw = z.object({
resources: LooseArray(
z.object({
'@id': z.string(),
'@type': z.string(),
}),
).catch([]),
});
export type ServicesIndexRaw = z.infer<typeof ServicesIndexRaw>;
const Deprecation = z.object({
reasons: z.array(z.string()),
});
// See https://learn.microsoft.com/en-us/nuget/api/registration-base-url-resource#catalog-entry
export const CatalogEntry = z.object({
version: z.string(),
published: z.string().optional(),
projectUrl: z.string().optional(),
listed: z.boolean().optional(),
packageContent: z.string().optional(),
deprecation: Deprecation.optional(),
});
export type CatalogEntry = z.infer<typeof CatalogEntry>;
const CatalogItem = z.object({
catalogEntry: CatalogEntry,
});
export const CatalogPage = z.object({
'@id': z.string().optional(),
items: LooseArray(CatalogItem).optional(),
});
export type CatalogPage = z.infer<typeof CatalogPage>;
export const PackageRegistration = z.object({
items: LooseArray(CatalogPage).default([]),
});
export type PackageRegistration = z.infer<typeof PackageRegistration>;