ag-common 0.0.866 → 0.0.867
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/dist/api/helpers/zod.js +11 -3
- package/package.json +1 -1
package/dist/api/helpers/zod.js
CHANGED
|
@@ -22,8 +22,13 @@ function zodSchemaToString(schema) {
|
|
|
22
22
|
const fields = [];
|
|
23
23
|
for (const [key, value] of Object.entries(schema.shape)) {
|
|
24
24
|
const zodType = value;
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
try {
|
|
26
|
+
const typeCode = zodTypeToCode(zodType);
|
|
27
|
+
fields.push(` ${key}: ${typeCode}`);
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
throw new Error(`Failed to convert field "${key}": ${e.message}`);
|
|
31
|
+
}
|
|
27
32
|
}
|
|
28
33
|
return `z.object({\n${fields.join(',\n')}\n})`;
|
|
29
34
|
}
|
|
@@ -94,6 +99,9 @@ function zodTypeToCode(zodType) {
|
|
|
94
99
|
const optionsStr = options.map((opt) => zodTypeToCode(opt)).join(', ');
|
|
95
100
|
return `z.union([${optionsStr}])${describeChain}`;
|
|
96
101
|
}
|
|
102
|
+
if (typeName === 'ZodUndefined') {
|
|
103
|
+
return `z.undefined()${describeChain}`;
|
|
104
|
+
}
|
|
97
105
|
if (typeName === 'ZodRecord') {
|
|
98
106
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
99
107
|
const valueType = zodType._def.valueType;
|
|
@@ -105,5 +113,5 @@ function zodTypeToCode(zodType) {
|
|
|
105
113
|
const itemsStr = items.map((item) => zodTypeToCode(item)).join(', ');
|
|
106
114
|
return `z.tuple([${itemsStr}])${describeChain}`;
|
|
107
115
|
}
|
|
108
|
-
throw new Error(`Unsupported Zod type: ${typeName}`);
|
|
116
|
+
throw new Error(`Unsupported Zod type: ${typeName} (keys: ${Object.keys(zodType._def).join(', ')})`);
|
|
109
117
|
}
|
package/package.json
CHANGED