cms-renderer 0.2.9 → 0.3.0

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.
@@ -0,0 +1,94 @@
1
+ import { FieldDefinition } from '@repo/cms-schema/documents';
2
+ import { ZodObject, ZodRawShape } from 'zod';
3
+ import { CmsConfig } from './cms-api.js';
4
+ import '@repo/cms-schema/trpc';
5
+ import '@trpc/client';
6
+
7
+ /**
8
+ * Custom Schema Fetcher
9
+ *
10
+ * Fetches custom schema definitions (field metadata as JSON) from the CMS API
11
+ * for a given website. Uses the tRPC client to call the customSchema router.
12
+ */
13
+
14
+ interface CustomSchemaFields {
15
+ name: string;
16
+ displayName: string;
17
+ description: string | null;
18
+ fields: FieldDefinition[];
19
+ routeSlugField: string | null;
20
+ version: number;
21
+ }
22
+ type FetchCustomSchemasOptions = CmsConfig & {
23
+ websiteId: string;
24
+ };
25
+ /**
26
+ * Fetches all custom schemas with their field definitions for a website.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * const schemas = await fetchAllCustomSchemaFields({
31
+ * cmsUrl: 'http://localhost:3000',
32
+ * apiKey: 'my-api-key',
33
+ * websiteId: 'uuid-here',
34
+ * });
35
+ *
36
+ * for (const schema of schemas) {
37
+ * console.log(schema.name, schema.fields);
38
+ * }
39
+ * ```
40
+ */
41
+ declare function fetchAllCustomSchemaFields(options: FetchCustomSchemasOptions): Promise<CustomSchemaFields[]>;
42
+ /**
43
+ * Fetches a single custom schema's field definitions by name.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * const schema = await fetchCustomSchemaFields({
48
+ * cmsUrl: 'http://localhost:3000',
49
+ * apiKey: 'my-api-key',
50
+ * websiteId: 'uuid-here',
51
+ * }, 'blog_post');
52
+ *
53
+ * console.log(schema.fields);
54
+ * ```
55
+ */
56
+ declare function fetchCustomSchemaFields(options: FetchCustomSchemasOptions, schemaName: string): Promise<CustomSchemaFields>;
57
+ /**
58
+ * Converts an array of custom schema definitions into a record of Zod schemas,
59
+ * keyed by schema name.
60
+ *
61
+ * @example
62
+ * ```ts
63
+ * const schemas = await fetchAllCustomSchemaFields(options);
64
+ * const zodSchemas = buildZodSchemas(schemas);
65
+ *
66
+ * // Validate a blog post document
67
+ * const result = zodSchemas['blog_post'].safeParse(data);
68
+ * ```
69
+ */
70
+ declare function buildZodSchemas(schemas: CustomSchemaFields[]): Record<string, ZodObject<ZodRawShape>>;
71
+ /**
72
+ * Converts an array of custom schema definitions into a record of Zod source
73
+ * code strings, keyed by schema name.
74
+ *
75
+ * @example
76
+ * ```ts
77
+ * const schemas = await fetchAllCustomSchemaFields(options);
78
+ * const codeMap = buildZodSchemaCode(schemas);
79
+ *
80
+ * // Write blog_post schema to a file
81
+ * fs.writeFileSync('blog-post.ts', codeMap['blog_post']);
82
+ * ```
83
+ */
84
+ declare function buildZodSchemaCode(schemas: CustomSchemaFields[]): Record<string, string>;
85
+ /**
86
+ * Generates combined Zod schema code from all custom schemas and writes it
87
+ * to the specified file path.
88
+ *
89
+ * @param schemas - Array of custom schema definitions
90
+ * @param filePath - Absolute or relative path to write the generated file
91
+ */
92
+ declare function saveZodSchemaCode(schemas: CustomSchemaFields[], filePath: string): Promise<void>;
93
+
94
+ export { type CustomSchemaFields, type FetchCustomSchemasOptions, buildZodSchemaCode, buildZodSchemas, fetchAllCustomSchemaFields, fetchCustomSchemaFields, saveZodSchemaCode };