@chnak/zod-to-markdown 1.0.4 → 1.0.5

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.
Files changed (2) hide show
  1. package/lib/index.js +27 -0
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -320,6 +320,28 @@ function collectFields(schema, prefix, fields, wrapperType) {
320
320
  });
321
321
  return;
322
322
  }
323
+ // 处理 ZodEffects (transform)
324
+ if (schema instanceof zod_1.z.ZodEffects) {
325
+ const innerFields = [];
326
+ collectFields(schema.innerType(), prefix, innerFields);
327
+ if (innerFields.length > 0) {
328
+ innerFields.forEach(field => {
329
+ fields.push({
330
+ path: field.path,
331
+ type: `Effects(${schema._def.effect.type})<${field.type}>`,
332
+ description: field.description,
333
+ });
334
+ });
335
+ }
336
+ else {
337
+ fields.push({
338
+ path: prefix,
339
+ type: `Effects(${schema._def.effect.type})<${getTypeString(schema.innerType())}>`,
340
+ description: schema.description || '-',
341
+ });
342
+ }
343
+ return;
344
+ }
323
345
  // 其他类型直接添加
324
346
  let typeStr = getTypeString(schema);
325
347
  if (wrapperType === 'Optional' && !typeStr.startsWith('Optional<') && !typeStr.startsWith('Nullable<')) {
@@ -350,6 +372,11 @@ function getTypeString(schema) {
350
372
  if (schema instanceof zod_1.z.ZodArray) {
351
373
  return `Array<${getTypeString(schema.element)}>`;
352
374
  }
375
+ if (schema instanceof zod_1.z.ZodObject) {
376
+ // ZodObject 应该被 collectFields 展开,这里仅作为兜底
377
+ const keys = Object.keys(schema.shape);
378
+ return `Object{${keys.join(', ')}}`;
379
+ }
353
380
  if (schema instanceof zod_1.z.ZodString) {
354
381
  let result = 'String';
355
382
  if (schema.minLength !== null || schema.maxLength !== null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chnak/zod-to-markdown",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "A utility function to convert Zod schemas to Markdown documentation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",