agent-relay 6.0.2 → 6.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -3
- package/dist/index.cjs +2024 -962
- package/dist/src/cli/commands/cloud.d.ts.map +1 -1
- package/dist/src/cli/commands/cloud.js +17 -144
- package/dist/src/cli/commands/cloud.js.map +1 -1
- package/dist/src/cli/commands/setup.d.ts +2 -39
- package/dist/src/cli/commands/setup.d.ts.map +1 -1
- package/dist/src/cli/commands/setup.js +4 -333
- package/dist/src/cli/commands/setup.js.map +1 -1
- package/dist/src/cli/lib/auth-ssh.d.ts +2 -33
- package/dist/src/cli/lib/auth-ssh.d.ts.map +1 -1
- package/dist/src/cli/lib/auth-ssh.js +3 -39
- package/dist/src/cli/lib/auth-ssh.js.map +1 -1
- package/dist/src/cli/lib/ssh-interactive.d.ts +4 -66
- package/dist/src/cli/lib/ssh-interactive.d.ts.map +1 -1
- package/dist/src/cli/lib/ssh-interactive.js +4 -436
- package/dist/src/cli/lib/ssh-interactive.js.map +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/README.md +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/locales/package.json +2 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/mini/package.json +2 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/package.json +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v3/tests/all-errors.test.ts +3 -3
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v3/tests/object.test.ts +5 -5
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v3/tests/partials.test.ts +3 -3
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/errors.ts +2 -2
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/external.ts +1 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/from-json-schema.ts +39 -23
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/parse.ts +6 -6
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/schemas.ts +389 -148
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/catch.test.ts +4 -2
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/codec.test.ts +142 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/continuability.test.ts +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/datetime.test.ts +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/default.test.ts +44 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/detached-methods.test.ts +197 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/discriminated-unions.test.ts +31 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/error-utils.test.ts +214 -2
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/from-json-schema.test.ts +161 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/function.test.ts +6 -6
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/global-config.test.ts +39 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/index.test.ts +2 -2
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/jitless-allows-eval.test.ts +46 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/locales_ka.test.ts +29 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/locales_ro.test.ts +24 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/number.test.ts +55 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/object.test.ts +83 -6
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/optional.test.ts +114 -4
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/partial.test.ts +28 -2
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/prefault.test.ts +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/record.test.ts +85 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/recursive-types.test.ts +49 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/refine.test.ts +63 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/string.test.ts +50 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/template-literal.test.ts +4 -4
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/to-json-schema.test.ts +128 -14
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/transform.test.ts +17 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/tuple.test.ts +315 -2
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/classic/tests/union.test.ts +54 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/api.ts +25 -2
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/checks.ts +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/core.ts +17 -2
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/errors.ts +31 -24
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/json-schema-processors.ts +15 -17
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/parse.ts +7 -7
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/regexes.ts +8 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/schemas.ts +218 -66
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/tests/locales/el.test.ts +215 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/tests/locales/fr.test.ts +72 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/tests/locales/hr.test.ts +163 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/tests/locales/uz.test.ts +22 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/tests/record-constructor.test.ts +58 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/to-json-schema.ts +9 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/util.ts +52 -35
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/core/versions.ts +2 -2
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/locales/el.ts +121 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/locales/en.ts +4 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/locales/fr.ts +24 -8
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/locales/hr.ts +131 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/locales/index.ts +3 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/locales/it.ts +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/locales/ka.ts +8 -8
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/locales/ro.ts +129 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/locales/uz.ts +1 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/mini/external.ts +1 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/mini/schemas.ts +55 -24
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/mini/tests/codec.test.ts +19 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/mini/tests/index.test.ts +27 -2
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/mini/tests/object.test.ts +9 -9
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/mini/tests/recursive-types.test.ts +51 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/src/v4/mini/tests/string.test.ts +5 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v3/package.json +2 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/errors.js +2 -2
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/external.d.cts +1 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/external.d.ts +1 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/from-json-schema.cjs +31 -16
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/from-json-schema.js +31 -16
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/package.json +2 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/schemas.cjs +346 -117
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/schemas.d.cts +34 -12
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/schemas.d.ts +34 -12
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/classic/schemas.js +345 -117
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/api.cjs +7 -2
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/api.d.cts +20 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/api.d.ts +20 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/api.js +7 -2
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/checks.d.cts +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/checks.d.ts +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/core.cjs +3 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/core.js +4 -2
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/errors.cjs +26 -23
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/errors.d.cts +1 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/errors.d.ts +1 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/errors.js +26 -23
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/json-schema-processors.cjs +14 -19
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/json-schema-processors.js +14 -19
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/package.json +2 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/parse.cjs +7 -7
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/parse.js +7 -7
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/regexes.cjs +9 -3
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/regexes.d.cts +6 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/regexes.d.ts +6 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/regexes.js +7 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/schemas.cjs +196 -59
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/schemas.d.cts +21 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/schemas.d.ts +21 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/schemas.js +196 -59
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/to-json-schema.cjs +10 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/to-json-schema.js +10 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/util.cjs +54 -30
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/util.d.cts +1 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/util.d.ts +1 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/util.js +55 -32
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/versions.cjs +2 -2
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/versions.d.cts +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/versions.d.ts +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/core/versions.js +2 -2
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/el.cjs +136 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/el.d.cts +5 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/el.d.ts +4 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/el.js +109 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/en.cjs +4 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/en.js +4 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/fr.cjs +24 -7
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/fr.js +24 -7
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/hr.cjs +149 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/hr.d.cts +5 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/hr.d.ts +4 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/hr.js +122 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/index.cjs +8 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/index.d.cts +3 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/index.d.ts +3 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/index.js +3 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/it.cjs +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/it.js +1 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/ka.cjs +8 -8
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/ka.js +8 -8
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/package.json +2 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/ro.cjs +146 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/ro.d.cts +5 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/ro.d.ts +4 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/ro.js +119 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/uz.cjs +1 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/locales/uz.js +1 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/mini/external.d.cts +1 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/mini/external.d.ts +1 -0
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/mini/package.json +2 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/mini/schemas.cjs +41 -4
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/mini/schemas.d.cts +27 -9
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/mini/schemas.d.ts +27 -9
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/mini/schemas.js +40 -4
- package/node_modules/@relaycast/sdk/node_modules/zod/v4/package.json +2 -1
- package/node_modules/@relaycast/sdk/node_modules/zod/v4-mini/package.json +2 -1
- package/package.json +10 -10
|
@@ -35,7 +35,7 @@ const z = {
|
|
|
35
35
|
iso: _iso,
|
|
36
36
|
};
|
|
37
37
|
// Keys that are recognized and handled by the conversion logic
|
|
38
|
-
const RECOGNIZED_KEYS = new Set([
|
|
38
|
+
const RECOGNIZED_KEYS = /*@__PURE__*/ new Set([
|
|
39
39
|
// Schema identification
|
|
40
40
|
"$schema",
|
|
41
41
|
"$ref",
|
|
@@ -511,13 +511,6 @@ function convertBaseSchema(schema, ctx) {
|
|
|
511
511
|
default:
|
|
512
512
|
throw new Error(`Unsupported type: ${type}`);
|
|
513
513
|
}
|
|
514
|
-
// Apply metadata
|
|
515
|
-
if (schema.description) {
|
|
516
|
-
zodSchema = zodSchema.describe(schema.description);
|
|
517
|
-
}
|
|
518
|
-
if (schema.default !== undefined) {
|
|
519
|
-
zodSchema = zodSchema.default(schema.default);
|
|
520
|
-
}
|
|
521
514
|
return zodSchema;
|
|
522
515
|
}
|
|
523
516
|
function convertSchema(schema, ctx) {
|
|
@@ -562,23 +555,28 @@ function convertSchema(schema, ctx) {
|
|
|
562
555
|
if (schema.readOnly === true) {
|
|
563
556
|
baseSchema = z.readonly(baseSchema);
|
|
564
557
|
}
|
|
565
|
-
//
|
|
558
|
+
// Apply `default` so it wraps the fully-composed schema. This ensures
|
|
559
|
+
// `parse(undefined) -> default` works regardless of which branch of
|
|
560
|
+
// `convertBaseSchema` produced the inner schema (enum/const/not/typed/etc.).
|
|
561
|
+
if (schema.default !== undefined) {
|
|
562
|
+
baseSchema = baseSchema.default(schema.default);
|
|
563
|
+
}
|
|
564
|
+
// Collect non-description annotation metadata into the user-supplied
|
|
565
|
+
// registry. Description is handled separately below via `.describe()` to
|
|
566
|
+
// preserve the contract that `schema.description` reads from globalRegistry.
|
|
566
567
|
const extraMeta = {};
|
|
567
|
-
// Core schema keywords that should be captured as metadata
|
|
568
568
|
const coreMetadataKeys = ["$id", "id", "$comment", "$anchor", "$vocabulary", "$dynamicRef", "$dynamicAnchor"];
|
|
569
569
|
for (const key of coreMetadataKeys) {
|
|
570
570
|
if (key in schema) {
|
|
571
571
|
extraMeta[key] = schema[key];
|
|
572
572
|
}
|
|
573
573
|
}
|
|
574
|
-
// Content keywords - store as metadata
|
|
575
574
|
const contentMetadataKeys = ["contentEncoding", "contentMediaType", "contentSchema"];
|
|
576
575
|
for (const key of contentMetadataKeys) {
|
|
577
576
|
if (key in schema) {
|
|
578
577
|
extraMeta[key] = schema[key];
|
|
579
578
|
}
|
|
580
579
|
}
|
|
581
|
-
// Unrecognized keys (custom metadata)
|
|
582
580
|
for (const key of Object.keys(schema)) {
|
|
583
581
|
if (!RECOGNIZED_KEYS.has(key)) {
|
|
584
582
|
extraMeta[key] = schema[key];
|
|
@@ -587,6 +585,12 @@ function convertSchema(schema, ctx) {
|
|
|
587
585
|
if (Object.keys(extraMeta).length > 0) {
|
|
588
586
|
ctx.registry.add(baseSchema, extraMeta);
|
|
589
587
|
}
|
|
588
|
+
// Apply description last. `.describe()` clones the schema and sets
|
|
589
|
+
// `_zod.parent` on the clone, so registry lookups on the returned reference
|
|
590
|
+
// still resolve `extraMeta` via parent inheritance.
|
|
591
|
+
if (schema.description) {
|
|
592
|
+
baseSchema = baseSchema.describe(schema.description);
|
|
593
|
+
}
|
|
590
594
|
return baseSchema;
|
|
591
595
|
}
|
|
592
596
|
/**
|
|
@@ -596,15 +600,26 @@ function fromJSONSchema(schema, params) {
|
|
|
596
600
|
if (typeof schema === "boolean") {
|
|
597
601
|
return schema ? z.any() : z.never();
|
|
598
602
|
}
|
|
599
|
-
|
|
600
|
-
|
|
603
|
+
// Normalize input via a JSON round-trip. This guarantees the converter
|
|
604
|
+
// walks a plain, finite, JSON-valid object graph: cyclic inputs fail here,
|
|
605
|
+
// getter/Proxy-based properties are materialized into static values, and
|
|
606
|
+
// class instances collapse to plain objects.
|
|
607
|
+
let normalized;
|
|
608
|
+
try {
|
|
609
|
+
normalized = JSON.parse(JSON.stringify(schema));
|
|
610
|
+
}
|
|
611
|
+
catch {
|
|
612
|
+
throw new Error("fromJSONSchema input is not valid JSON (possibly cyclic); use $defs/$ref for recursive schemas");
|
|
613
|
+
}
|
|
614
|
+
const version = detectVersion(normalized, params?.defaultTarget);
|
|
615
|
+
const defs = (normalized.$defs || normalized.definitions || {});
|
|
601
616
|
const ctx = {
|
|
602
617
|
version,
|
|
603
618
|
defs,
|
|
604
619
|
refs: new Map(),
|
|
605
620
|
processing: new Set(),
|
|
606
|
-
rootSchema:
|
|
621
|
+
rootSchema: normalized,
|
|
607
622
|
registry: params?.registry ?? registries_js_1.globalRegistry,
|
|
608
623
|
};
|
|
609
|
-
return convertSchema(
|
|
624
|
+
return convertSchema(normalized, ctx);
|
|
610
625
|
}
|
|
@@ -9,7 +9,7 @@ const z = {
|
|
|
9
9
|
iso: _iso,
|
|
10
10
|
};
|
|
11
11
|
// Keys that are recognized and handled by the conversion logic
|
|
12
|
-
const RECOGNIZED_KEYS = new Set([
|
|
12
|
+
const RECOGNIZED_KEYS = /*@__PURE__*/ new Set([
|
|
13
13
|
// Schema identification
|
|
14
14
|
"$schema",
|
|
15
15
|
"$ref",
|
|
@@ -485,13 +485,6 @@ function convertBaseSchema(schema, ctx) {
|
|
|
485
485
|
default:
|
|
486
486
|
throw new Error(`Unsupported type: ${type}`);
|
|
487
487
|
}
|
|
488
|
-
// Apply metadata
|
|
489
|
-
if (schema.description) {
|
|
490
|
-
zodSchema = zodSchema.describe(schema.description);
|
|
491
|
-
}
|
|
492
|
-
if (schema.default !== undefined) {
|
|
493
|
-
zodSchema = zodSchema.default(schema.default);
|
|
494
|
-
}
|
|
495
488
|
return zodSchema;
|
|
496
489
|
}
|
|
497
490
|
function convertSchema(schema, ctx) {
|
|
@@ -536,23 +529,28 @@ function convertSchema(schema, ctx) {
|
|
|
536
529
|
if (schema.readOnly === true) {
|
|
537
530
|
baseSchema = z.readonly(baseSchema);
|
|
538
531
|
}
|
|
539
|
-
//
|
|
532
|
+
// Apply `default` so it wraps the fully-composed schema. This ensures
|
|
533
|
+
// `parse(undefined) -> default` works regardless of which branch of
|
|
534
|
+
// `convertBaseSchema` produced the inner schema (enum/const/not/typed/etc.).
|
|
535
|
+
if (schema.default !== undefined) {
|
|
536
|
+
baseSchema = baseSchema.default(schema.default);
|
|
537
|
+
}
|
|
538
|
+
// Collect non-description annotation metadata into the user-supplied
|
|
539
|
+
// registry. Description is handled separately below via `.describe()` to
|
|
540
|
+
// preserve the contract that `schema.description` reads from globalRegistry.
|
|
540
541
|
const extraMeta = {};
|
|
541
|
-
// Core schema keywords that should be captured as metadata
|
|
542
542
|
const coreMetadataKeys = ["$id", "id", "$comment", "$anchor", "$vocabulary", "$dynamicRef", "$dynamicAnchor"];
|
|
543
543
|
for (const key of coreMetadataKeys) {
|
|
544
544
|
if (key in schema) {
|
|
545
545
|
extraMeta[key] = schema[key];
|
|
546
546
|
}
|
|
547
547
|
}
|
|
548
|
-
// Content keywords - store as metadata
|
|
549
548
|
const contentMetadataKeys = ["contentEncoding", "contentMediaType", "contentSchema"];
|
|
550
549
|
for (const key of contentMetadataKeys) {
|
|
551
550
|
if (key in schema) {
|
|
552
551
|
extraMeta[key] = schema[key];
|
|
553
552
|
}
|
|
554
553
|
}
|
|
555
|
-
// Unrecognized keys (custom metadata)
|
|
556
554
|
for (const key of Object.keys(schema)) {
|
|
557
555
|
if (!RECOGNIZED_KEYS.has(key)) {
|
|
558
556
|
extraMeta[key] = schema[key];
|
|
@@ -561,6 +559,12 @@ function convertSchema(schema, ctx) {
|
|
|
561
559
|
if (Object.keys(extraMeta).length > 0) {
|
|
562
560
|
ctx.registry.add(baseSchema, extraMeta);
|
|
563
561
|
}
|
|
562
|
+
// Apply description last. `.describe()` clones the schema and sets
|
|
563
|
+
// `_zod.parent` on the clone, so registry lookups on the returned reference
|
|
564
|
+
// still resolve `extraMeta` via parent inheritance.
|
|
565
|
+
if (schema.description) {
|
|
566
|
+
baseSchema = baseSchema.describe(schema.description);
|
|
567
|
+
}
|
|
564
568
|
return baseSchema;
|
|
565
569
|
}
|
|
566
570
|
/**
|
|
@@ -570,15 +574,26 @@ export function fromJSONSchema(schema, params) {
|
|
|
570
574
|
if (typeof schema === "boolean") {
|
|
571
575
|
return schema ? z.any() : z.never();
|
|
572
576
|
}
|
|
573
|
-
|
|
574
|
-
|
|
577
|
+
// Normalize input via a JSON round-trip. This guarantees the converter
|
|
578
|
+
// walks a plain, finite, JSON-valid object graph: cyclic inputs fail here,
|
|
579
|
+
// getter/Proxy-based properties are materialized into static values, and
|
|
580
|
+
// class instances collapse to plain objects.
|
|
581
|
+
let normalized;
|
|
582
|
+
try {
|
|
583
|
+
normalized = JSON.parse(JSON.stringify(schema));
|
|
584
|
+
}
|
|
585
|
+
catch {
|
|
586
|
+
throw new Error("fromJSONSchema input is not valid JSON (possibly cyclic); use $defs/$ref for recursive schemas");
|
|
587
|
+
}
|
|
588
|
+
const version = detectVersion(normalized, params?.defaultTarget);
|
|
589
|
+
const defs = (normalized.$defs || normalized.definitions || {});
|
|
575
590
|
const ctx = {
|
|
576
591
|
version,
|
|
577
592
|
defs,
|
|
578
593
|
refs: new Map(),
|
|
579
594
|
processing: new Set(),
|
|
580
|
-
rootSchema:
|
|
595
|
+
rootSchema: normalized,
|
|
581
596
|
registry: params?.registry ?? globalRegistry,
|
|
582
597
|
};
|
|
583
|
-
return convertSchema(
|
|
598
|
+
return convertSchema(normalized, ctx);
|
|
584
599
|
}
|