@blocklet/pages-kit-block-studio 0.4.91 → 0.4.92
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
|
@@ -38,6 +38,7 @@ exports.generatePropertiesJsonSchemaWithZod = generatePropertiesJsonSchemaWithZo
|
|
|
38
38
|
exports.generatePageDataJsonSchemasWithZod = generatePageDataJsonSchemasWithZod;
|
|
39
39
|
exports.generatePageDataTypesWithZod = generatePageDataTypesWithZod;
|
|
40
40
|
exports.generatePropertiesTypesWithZod = generatePropertiesTypesWithZod;
|
|
41
|
+
exports.serializeZodSchema = serializeZodSchema;
|
|
41
42
|
exports.generatePageSectionsDataZod = generatePageSectionsDataZod;
|
|
42
43
|
// 导入 Zod 工具集
|
|
43
44
|
const property_1 = require("@blocklet/pages-kit/utils/property");
|
|
@@ -503,16 +504,88 @@ function generatePropertiesTypesWithZod(properties) {
|
|
|
503
504
|
const typeString = (0, zod_utils_1.zodSchemaToTypeString)(zodSchema, 'Props');
|
|
504
505
|
return typeString;
|
|
505
506
|
}
|
|
507
|
+
/**
|
|
508
|
+
* 将 Zod schema 序列化为 JSON 描述结构
|
|
509
|
+
*/
|
|
510
|
+
function serializeZodSchema(schema) {
|
|
511
|
+
// 处理不同类型的 schema
|
|
512
|
+
if (schema instanceof zod_1.z.ZodObject) {
|
|
513
|
+
const shape = schema._def.shape();
|
|
514
|
+
const properties = {};
|
|
515
|
+
Object.entries(shape).forEach(([key, value]) => {
|
|
516
|
+
properties[key] = serializeZodSchema(value);
|
|
517
|
+
});
|
|
518
|
+
return {
|
|
519
|
+
type: 'object',
|
|
520
|
+
properties,
|
|
521
|
+
description: schema.description,
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
if (schema instanceof zod_1.z.ZodString) {
|
|
525
|
+
return {
|
|
526
|
+
type: 'string',
|
|
527
|
+
description: schema.description,
|
|
528
|
+
optional: schema.isOptional(),
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
if (schema instanceof zod_1.z.ZodNumber) {
|
|
532
|
+
return {
|
|
533
|
+
type: 'number',
|
|
534
|
+
description: schema.description,
|
|
535
|
+
optional: schema.isOptional(),
|
|
536
|
+
};
|
|
537
|
+
}
|
|
538
|
+
if (schema instanceof zod_1.z.ZodBoolean) {
|
|
539
|
+
return {
|
|
540
|
+
type: 'boolean',
|
|
541
|
+
description: schema.description,
|
|
542
|
+
optional: schema.isOptional(),
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
if (schema instanceof zod_1.z.ZodArray) {
|
|
546
|
+
return {
|
|
547
|
+
type: 'array',
|
|
548
|
+
items: serializeZodSchema(schema._def.type),
|
|
549
|
+
description: schema.description,
|
|
550
|
+
optional: schema.isOptional(),
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
if (schema instanceof zod_1.z.ZodRecord) {
|
|
554
|
+
return {
|
|
555
|
+
type: 'record',
|
|
556
|
+
valueType: serializeZodSchema(schema._def.valueType),
|
|
557
|
+
description: schema.description,
|
|
558
|
+
optional: schema.isOptional(),
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
if (schema instanceof zod_1.z.ZodOptional) {
|
|
562
|
+
const innerType = serializeZodSchema(schema._def.innerType);
|
|
563
|
+
innerType.optional = true;
|
|
564
|
+
return innerType;
|
|
565
|
+
}
|
|
566
|
+
if (schema instanceof zod_1.z.ZodAny) {
|
|
567
|
+
return {
|
|
568
|
+
type: 'any',
|
|
569
|
+
description: schema.description,
|
|
570
|
+
optional: schema.isOptional(),
|
|
571
|
+
};
|
|
572
|
+
}
|
|
573
|
+
// 默认情况
|
|
574
|
+
return {
|
|
575
|
+
type: 'unknown',
|
|
576
|
+
description: schema.description,
|
|
577
|
+
};
|
|
578
|
+
}
|
|
506
579
|
/**
|
|
507
580
|
* 生成特定页面所有 section 数据的 Zod 类型定义
|
|
508
581
|
* @param state 应用状态
|
|
509
582
|
* @param pageId 目标页面ID
|
|
510
|
-
* @returns 包含所有 section 数据类型的 Zod schema
|
|
583
|
+
* @returns 包含所有 section 数据类型的 Zod schema 的序列化描述
|
|
511
584
|
*/
|
|
512
585
|
function generatePageSectionsDataZod(state, pageId) {
|
|
513
586
|
const page = state.pages[pageId];
|
|
514
587
|
if (!page) {
|
|
515
|
-
return zod_1.z.object({}).describe('Empty page data');
|
|
588
|
+
return serializeZodSchema(zod_1.z.object({}).describe('Empty page data'));
|
|
516
589
|
}
|
|
517
590
|
const sectionSchemas = {};
|
|
518
591
|
// 收集页面所有section的配置信息
|
|
@@ -570,7 +643,8 @@ function generatePageSectionsDataZod(state, pageId) {
|
|
|
570
643
|
sectionSchemas[sectionName] = zod_1.z.object({}).describe(section.templateDescription || '');
|
|
571
644
|
}
|
|
572
645
|
});
|
|
573
|
-
//
|
|
574
|
-
|
|
646
|
+
// FIXME: 这里需要优化,AIGNE Framework 校验修改后,不需要序列化,直接使用
|
|
647
|
+
// 创建包含所有section的schema并序列化返回
|
|
648
|
+
return serializeZodSchema(zod_1.z.object(sectionSchemas).describe(`Page ${page.title || pageId} sections data`));
|
|
575
649
|
}
|
|
576
650
|
exports.default = generateWrapperCode;
|