page.tsx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import { Code } from "@/components/code";
  2. export const metadata = {
  3. title: "@json-render/core API | json-render",
  4. };
  5. export default function CoreApiPage() {
  6. return (
  7. <article>
  8. <h1 className="text-3xl font-bold mb-4">@json-render/core</h1>
  9. <p className="text-muted-foreground mb-8">
  10. Core types, schemas, and utilities.
  11. </p>
  12. <h2 className="text-xl font-semibold mt-12 mb-4">createCatalog</h2>
  13. <p className="text-sm text-muted-foreground mb-4">
  14. Creates a catalog definition.
  15. </p>
  16. <Code lang="typescript">{`function createCatalog(config: CatalogConfig): Catalog
  17. interface CatalogConfig {
  18. components: Record<string, ComponentDefinition>;
  19. actions?: Record<string, ActionDefinition>;
  20. validationFunctions?: Record<string, ValidationFunctionDef>;
  21. }
  22. interface ComponentDefinition {
  23. props: ZodObject;
  24. hasChildren?: boolean;
  25. description?: string;
  26. }
  27. interface ActionDefinition {
  28. params?: ZodObject;
  29. description?: string;
  30. }`}</Code>
  31. <h2 className="text-xl font-semibold mt-12 mb-4">generateCatalogPrompt</h2>
  32. <p className="text-sm text-muted-foreground mb-4">
  33. Generates a system prompt for AI models.
  34. </p>
  35. <Code lang="typescript">{`function generateCatalogPrompt(catalog: Catalog): string`}</Code>
  36. <h2 className="text-xl font-semibold mt-12 mb-4">evaluateVisibility</h2>
  37. <p className="text-sm text-muted-foreground mb-4">
  38. Evaluates a visibility condition against data and auth state.
  39. </p>
  40. <Code lang="typescript">{`function evaluateVisibility(
  41. condition: VisibilityCondition | undefined,
  42. data: Record<string, unknown>,
  43. auth?: AuthState
  44. ): boolean
  45. type VisibilityCondition =
  46. | { path: string }
  47. | { auth: 'signedIn' | 'signedOut' | string }
  48. | { and: VisibilityCondition[] }
  49. | { or: VisibilityCondition[] }
  50. | { not: VisibilityCondition }
  51. | { eq: [DynamicValue, DynamicValue] }
  52. | { gt: [DynamicValue, DynamicValue] }
  53. | { gte: [DynamicValue, DynamicValue] }
  54. | { lt: [DynamicValue, DynamicValue] }
  55. | { lte: [DynamicValue, DynamicValue] };`}</Code>
  56. <h2 className="text-xl font-semibold mt-12 mb-4">Types</h2>
  57. <h3 className="text-lg font-semibold mt-8 mb-4">UIElement</h3>
  58. <Code lang="typescript">{`interface UIElement {
  59. key: string;
  60. type: string;
  61. props: Record<string, unknown>;
  62. children?: UIElement[];
  63. visible?: VisibilityCondition;
  64. validation?: ValidationSchema;
  65. }`}</Code>
  66. <h3 className="text-lg font-semibold mt-8 mb-4">UITree</h3>
  67. <Code lang="typescript">{`interface UITree {
  68. root: UIElement | null;
  69. elements: Record<string, UIElement>;
  70. }`}</Code>
  71. <h3 className="text-lg font-semibold mt-8 mb-4">Action</h3>
  72. <Code lang="typescript">{`interface Action {
  73. name: string;
  74. params?: Record<string, unknown>;
  75. confirm?: {
  76. title: string;
  77. message: string;
  78. variant?: 'default' | 'danger';
  79. };
  80. onSuccess?: { set: Record<string, unknown> };
  81. onError?: { set: Record<string, unknown> };
  82. }`}</Code>
  83. <h3 className="text-lg font-semibold mt-8 mb-4">ValidationSchema</h3>
  84. <Code lang="typescript">{`interface ValidationSchema {
  85. checks: ValidationCheck[];
  86. validateOn?: 'change' | 'blur' | 'submit';
  87. }
  88. interface ValidationCheck {
  89. fn: string;
  90. args?: Record<string, unknown>;
  91. message: string;
  92. }`}</Code>
  93. </article>
  94. );
  95. }