@blocklet/pages-kit-block-studio 0.4.91 → 0.4.93
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/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/generate-wrapper-code.js +78 -4
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/generate-wrapper-code.js +77 -4
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/generate-wrapper-code.d.ts +6 -2
- package/package.json +3 -3
|
@@ -462,16 +462,88 @@ export function generatePropertiesTypesWithZod(properties) {
|
|
|
462
462
|
const typeString = zodSchemaToTypeString(zodSchema, 'Props');
|
|
463
463
|
return typeString;
|
|
464
464
|
}
|
|
465
|
+
/**
|
|
466
|
+
* 将 Zod schema 序列化为 JSON 描述结构
|
|
467
|
+
*/
|
|
468
|
+
export function serializeZodSchema(schema) {
|
|
469
|
+
// 处理不同类型的 schema
|
|
470
|
+
if (schema instanceof z.ZodObject) {
|
|
471
|
+
const shape = schema._def.shape();
|
|
472
|
+
const properties = {};
|
|
473
|
+
Object.entries(shape).forEach(([key, value]) => {
|
|
474
|
+
properties[key] = serializeZodSchema(value);
|
|
475
|
+
});
|
|
476
|
+
return {
|
|
477
|
+
type: 'object',
|
|
478
|
+
properties,
|
|
479
|
+
description: schema.description,
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
if (schema instanceof z.ZodString) {
|
|
483
|
+
return {
|
|
484
|
+
type: 'string',
|
|
485
|
+
description: schema.description,
|
|
486
|
+
optional: schema.isOptional(),
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
if (schema instanceof z.ZodNumber) {
|
|
490
|
+
return {
|
|
491
|
+
type: 'number',
|
|
492
|
+
description: schema.description,
|
|
493
|
+
optional: schema.isOptional(),
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
if (schema instanceof z.ZodBoolean) {
|
|
497
|
+
return {
|
|
498
|
+
type: 'boolean',
|
|
499
|
+
description: schema.description,
|
|
500
|
+
optional: schema.isOptional(),
|
|
501
|
+
};
|
|
502
|
+
}
|
|
503
|
+
if (schema instanceof z.ZodArray) {
|
|
504
|
+
return {
|
|
505
|
+
type: 'array',
|
|
506
|
+
items: serializeZodSchema(schema._def.type),
|
|
507
|
+
description: schema.description,
|
|
508
|
+
optional: schema.isOptional(),
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
if (schema instanceof z.ZodRecord) {
|
|
512
|
+
return {
|
|
513
|
+
type: 'record',
|
|
514
|
+
valueType: serializeZodSchema(schema._def.valueType),
|
|
515
|
+
description: schema.description,
|
|
516
|
+
optional: schema.isOptional(),
|
|
517
|
+
};
|
|
518
|
+
}
|
|
519
|
+
if (schema instanceof z.ZodOptional) {
|
|
520
|
+
const innerType = serializeZodSchema(schema._def.innerType);
|
|
521
|
+
innerType.optional = true;
|
|
522
|
+
return innerType;
|
|
523
|
+
}
|
|
524
|
+
if (schema instanceof z.ZodAny) {
|
|
525
|
+
return {
|
|
526
|
+
type: 'any',
|
|
527
|
+
description: schema.description,
|
|
528
|
+
optional: schema.isOptional(),
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
// 默认情况
|
|
532
|
+
return {
|
|
533
|
+
type: 'unknown',
|
|
534
|
+
description: schema.description,
|
|
535
|
+
};
|
|
536
|
+
}
|
|
465
537
|
/**
|
|
466
538
|
* 生成特定页面所有 section 数据的 Zod 类型定义
|
|
467
539
|
* @param state 应用状态
|
|
468
540
|
* @param pageId 目标页面ID
|
|
469
|
-
* @returns 包含所有 section 数据类型的 Zod schema
|
|
541
|
+
* @returns 包含所有 section 数据类型的 Zod schema 的序列化描述
|
|
470
542
|
*/
|
|
471
543
|
export function generatePageSectionsDataZod(state, pageId) {
|
|
472
544
|
const page = state.pages[pageId];
|
|
473
545
|
if (!page) {
|
|
474
|
-
return z.object({}).describe('Empty page data');
|
|
546
|
+
return serializeZodSchema(z.object({}).describe('Empty page data'));
|
|
475
547
|
}
|
|
476
548
|
const sectionSchemas = {};
|
|
477
549
|
// 收集页面所有section的配置信息
|
|
@@ -529,7 +601,8 @@ export function generatePageSectionsDataZod(state, pageId) {
|
|
|
529
601
|
sectionSchemas[sectionName] = z.object({}).describe(section.templateDescription || '');
|
|
530
602
|
}
|
|
531
603
|
});
|
|
532
|
-
//
|
|
533
|
-
|
|
604
|
+
// FIXME: 这里需要优化,AIGNE Framework 校验修改后,不需要序列化,直接使用
|
|
605
|
+
// 创建包含所有section的schema并序列化返回
|
|
606
|
+
return serializeZodSchema(z.object(sectionSchemas).describe(`Page ${page.title || pageId} sections data`));
|
|
534
607
|
}
|
|
535
608
|
export default generateWrapperCode;
|