@json-render/core API
核心类型、模式和实用工具。
createCatalog
创建目录定义。
function createCatalog(config: CatalogConfig): Catalog
interface CatalogConfig {
components: Record<string, ComponentDefinition>;
actions?: Record<string, ActionDefinition>;
validationFunctions?: Record<string, ValidationFunctionDef>;
}
interface ComponentDefinition {
props: ZodObject;
hasChildren?: boolean;
description?: string;
}
interface ActionDefinition {
params?: ZodObject;
description?: string;
}generateCatalogPrompt
为 AI 模型生成系统提示词。
function generateCatalogPrompt(catalog: Catalog): stringevaluateVisibility
根据数据和身份验证状态评估可见性条件。
function evaluateVisibility(
condition: VisibilityCondition | undefined,
data: Record<string, unknown>,
auth?: AuthState
): boolean
type VisibilityCondition =
| { path: string }
| { auth: 'signedIn' | 'signedOut' | string }
| { and: VisibilityCondition[] }
| { or: VisibilityCondition[] }
| { not: VisibilityCondition }
| { eq: [DynamicValue, DynamicValue] }
| { gt: [DynamicValue, DynamicValue] }
| { gte: [DynamicValue, DynamicValue] }
| { lt: [DynamicValue, DynamicValue] }
| { lte: [DynamicValue, DynamicValue] };类型
UIElement
interface UIElement {
key: string;
type: string;
props: Record<string, unknown>;
children?: UIElement[];
visible?: VisibilityCondition;
validation?: ValidationSchema;
}UITree
interface UITree {
root: UIElement | null;
elements: Record<string, UIElement>;
}Action
interface Action {
name: string;
params?: Record<string, unknown>;
confirm?: {
title: string;
message: string;
variant?: 'default' | 'danger';
};
onSuccess?: { set: Record<string, unknown> };
onError?: { set: Record<string, unknown> };
}ValidationSchema
interface ValidationSchema {
checks: ValidationCheck[];
validateOn?: 'change' | 'blur' | 'submit';
}
interface ValidationCheck {
fn: string;
args?: Record<string, unknown>;
message: string;
}