gitea push

This commit is contained in:
2026-05-09 12:19:29 -06:00
parent 06113c95b8
commit 429461e985
1481 changed files with 74306 additions and 52475 deletions
+31 -16
View File
@@ -35,7 +35,7 @@ const z = {
iso: _iso,
};
// Keys that are recognized and handled by the conversion logic
const RECOGNIZED_KEYS = new Set([
const RECOGNIZED_KEYS = /*@__PURE__*/ new Set([
// Schema identification
"$schema",
"$ref",
@@ -511,13 +511,6 @@ function convertBaseSchema(schema, ctx) {
default:
throw new Error(`Unsupported type: ${type}`);
}
// Apply metadata
if (schema.description) {
zodSchema = zodSchema.describe(schema.description);
}
if (schema.default !== undefined) {
zodSchema = zodSchema.default(schema.default);
}
return zodSchema;
}
function convertSchema(schema, ctx) {
@@ -562,23 +555,28 @@ function convertSchema(schema, ctx) {
if (schema.readOnly === true) {
baseSchema = z.readonly(baseSchema);
}
// Collect metadata: core schema keywords and unrecognized keys
// Apply `default` so it wraps the fully-composed schema. This ensures
// `parse(undefined) -> default` works regardless of which branch of
// `convertBaseSchema` produced the inner schema (enum/const/not/typed/etc.).
if (schema.default !== undefined) {
baseSchema = baseSchema.default(schema.default);
}
// Collect non-description annotation metadata into the user-supplied
// registry. Description is handled separately below via `.describe()` to
// preserve the contract that `schema.description` reads from globalRegistry.
const extraMeta = {};
// Core schema keywords that should be captured as metadata
const coreMetadataKeys = ["$id", "id", "$comment", "$anchor", "$vocabulary", "$dynamicRef", "$dynamicAnchor"];
for (const key of coreMetadataKeys) {
if (key in schema) {
extraMeta[key] = schema[key];
}
}
// Content keywords - store as metadata
const contentMetadataKeys = ["contentEncoding", "contentMediaType", "contentSchema"];
for (const key of contentMetadataKeys) {
if (key in schema) {
extraMeta[key] = schema[key];
}
}
// Unrecognized keys (custom metadata)
for (const key of Object.keys(schema)) {
if (!RECOGNIZED_KEYS.has(key)) {
extraMeta[key] = schema[key];
@@ -587,6 +585,12 @@ function convertSchema(schema, ctx) {
if (Object.keys(extraMeta).length > 0) {
ctx.registry.add(baseSchema, extraMeta);
}
// Apply description last. `.describe()` clones the schema and sets
// `_zod.parent` on the clone, so registry lookups on the returned reference
// still resolve `extraMeta` via parent inheritance.
if (schema.description) {
baseSchema = baseSchema.describe(schema.description);
}
return baseSchema;
}
/**
@@ -596,15 +600,26 @@ function fromJSONSchema(schema, params) {
if (typeof schema === "boolean") {
return schema ? z.any() : z.never();
}
const version = detectVersion(schema, params?.defaultTarget);
const defs = (schema.$defs || schema.definitions || {});
// Normalize input via a JSON round-trip. This guarantees the converter
// walks a plain, finite, JSON-valid object graph: cyclic inputs fail here,
// getter/Proxy-based properties are materialized into static values, and
// class instances collapse to plain objects.
let normalized;
try {
normalized = JSON.parse(JSON.stringify(schema));
}
catch {
throw new Error("fromJSONSchema input is not valid JSON (possibly cyclic); use $defs/$ref for recursive schemas");
}
const version = detectVersion(normalized, params?.defaultTarget);
const defs = (normalized.$defs || normalized.definitions || {});
const ctx = {
version,
defs,
refs: new Map(),
processing: new Set(),
rootSchema: schema,
rootSchema: normalized,
registry: params?.registry ?? registries_js_1.globalRegistry,
};
return convertSchema(schema, ctx);
return convertSchema(normalized, ctx);
}