@revealui/contracts 1.0.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.
Files changed (191) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +160 -0
  3. package/dist/a2a/index.d.ts +383 -0
  4. package/dist/a2a/index.d.ts.map +1 -0
  5. package/dist/a2a/index.js +276 -0
  6. package/dist/a2a/index.js.map +1 -0
  7. package/dist/actions/action-validator.d.ts +48 -0
  8. package/dist/actions/action-validator.d.ts.map +1 -0
  9. package/dist/actions/action-validator.js +288 -0
  10. package/dist/actions/action-validator.js.map +1 -0
  11. package/dist/actions/index.d.ts +7 -0
  12. package/dist/actions/index.d.ts.map +1 -0
  13. package/dist/actions/index.js +7 -0
  14. package/dist/actions/index.js.map +1 -0
  15. package/dist/agents/index.d.ts +628 -0
  16. package/dist/agents/index.d.ts.map +1 -0
  17. package/dist/agents/index.js +511 -0
  18. package/dist/agents/index.js.map +1 -0
  19. package/dist/agents/types.d.ts +22 -0
  20. package/dist/agents/types.d.ts.map +1 -0
  21. package/dist/agents/types.js +2 -0
  22. package/dist/agents/types.js.map +1 -0
  23. package/dist/api/auth.d.ts +60 -0
  24. package/dist/api/auth.d.ts.map +1 -0
  25. package/dist/api/auth.js +84 -0
  26. package/dist/api/auth.js.map +1 -0
  27. package/dist/api/chat.d.ts +45 -0
  28. package/dist/api/chat.d.ts.map +1 -0
  29. package/dist/api/chat.js +55 -0
  30. package/dist/api/chat.js.map +1 -0
  31. package/dist/api/gdpr.d.ts +39 -0
  32. package/dist/api/gdpr.d.ts.map +1 -0
  33. package/dist/api/gdpr.js +53 -0
  34. package/dist/api/gdpr.js.map +1 -0
  35. package/dist/cms/collection.d.ts +108 -0
  36. package/dist/cms/collection.d.ts.map +1 -0
  37. package/dist/cms/collection.js +144 -0
  38. package/dist/cms/collection.js.map +1 -0
  39. package/dist/cms/compat.d.ts +128 -0
  40. package/dist/cms/compat.d.ts.map +1 -0
  41. package/dist/cms/compat.js +141 -0
  42. package/dist/cms/compat.js.map +1 -0
  43. package/dist/cms/config-contract.d.ts +278 -0
  44. package/dist/cms/config-contract.d.ts.map +1 -0
  45. package/dist/cms/config-contract.js +220 -0
  46. package/dist/cms/config-contract.js.map +1 -0
  47. package/dist/cms/config.d.ts +351 -0
  48. package/dist/cms/config.d.ts.map +1 -0
  49. package/dist/cms/config.js +50 -0
  50. package/dist/cms/config.js.map +1 -0
  51. package/dist/cms/errors.d.ts +122 -0
  52. package/dist/cms/errors.d.ts.map +1 -0
  53. package/dist/cms/errors.js +163 -0
  54. package/dist/cms/errors.js.map +1 -0
  55. package/dist/cms/extensibility.d.ts +211 -0
  56. package/dist/cms/extensibility.d.ts.map +1 -0
  57. package/dist/cms/extensibility.js +313 -0
  58. package/dist/cms/extensibility.js.map +1 -0
  59. package/dist/cms/field.d.ts +69 -0
  60. package/dist/cms/field.d.ts.map +1 -0
  61. package/dist/cms/field.js +94 -0
  62. package/dist/cms/field.js.map +1 -0
  63. package/dist/cms/functions.d.ts +466 -0
  64. package/dist/cms/functions.d.ts.map +1 -0
  65. package/dist/cms/functions.js +19 -0
  66. package/dist/cms/functions.js.map +1 -0
  67. package/dist/cms/global.d.ts +45 -0
  68. package/dist/cms/global.d.ts.map +1 -0
  69. package/dist/cms/global.js +62 -0
  70. package/dist/cms/global.js.map +1 -0
  71. package/dist/cms/index.d.ts +23 -0
  72. package/dist/cms/index.d.ts.map +1 -0
  73. package/dist/cms/index.js +42 -0
  74. package/dist/cms/index.js.map +1 -0
  75. package/dist/cms/structure.d.ts +1601 -0
  76. package/dist/cms/structure.d.ts.map +1 -0
  77. package/dist/cms/structure.js +757 -0
  78. package/dist/cms/structure.js.map +1 -0
  79. package/dist/content/index.d.ts +1542 -0
  80. package/dist/content/index.d.ts.map +1 -0
  81. package/dist/content/index.js +522 -0
  82. package/dist/content/index.js.map +1 -0
  83. package/dist/database/bridge.d.ts +177 -0
  84. package/dist/database/bridge.d.ts.map +1 -0
  85. package/dist/database/bridge.js +139 -0
  86. package/dist/database/bridge.js.map +1 -0
  87. package/dist/database/index.d.ts +8 -0
  88. package/dist/database/index.d.ts.map +1 -0
  89. package/dist/database/index.js +9 -0
  90. package/dist/database/index.js.map +1 -0
  91. package/dist/database/type-bridge.d.ts +178 -0
  92. package/dist/database/type-bridge.d.ts.map +1 -0
  93. package/dist/database/type-bridge.js +154 -0
  94. package/dist/database/type-bridge.js.map +1 -0
  95. package/dist/entities/agent-context.d.ts +280 -0
  96. package/dist/entities/agent-context.d.ts.map +1 -0
  97. package/dist/entities/agent-context.js +390 -0
  98. package/dist/entities/agent-context.js.map +1 -0
  99. package/dist/entities/agent-memory.d.ts +661 -0
  100. package/dist/entities/agent-memory.d.ts.map +1 -0
  101. package/dist/entities/agent-memory.js +544 -0
  102. package/dist/entities/agent-memory.js.map +1 -0
  103. package/dist/entities/board.d.ts +95 -0
  104. package/dist/entities/board.d.ts.map +1 -0
  105. package/dist/entities/board.js +99 -0
  106. package/dist/entities/board.js.map +1 -0
  107. package/dist/entities/code-provenance.d.ts +270 -0
  108. package/dist/entities/code-provenance.d.ts.map +1 -0
  109. package/dist/entities/code-provenance.js +339 -0
  110. package/dist/entities/code-provenance.js.map +1 -0
  111. package/dist/entities/index.d.ts +22 -0
  112. package/dist/entities/index.d.ts.map +1 -0
  113. package/dist/entities/index.js +22 -0
  114. package/dist/entities/index.js.map +1 -0
  115. package/dist/entities/media.d.ts +485 -0
  116. package/dist/entities/media.d.ts.map +1 -0
  117. package/dist/entities/media.js +606 -0
  118. package/dist/entities/media.js.map +1 -0
  119. package/dist/entities/page-revision.d.ts +390 -0
  120. package/dist/entities/page-revision.d.ts.map +1 -0
  121. package/dist/entities/page-revision.js +406 -0
  122. package/dist/entities/page-revision.js.map +1 -0
  123. package/dist/entities/page.d.ts +2349 -0
  124. package/dist/entities/page.d.ts.map +1 -0
  125. package/dist/entities/page.js +377 -0
  126. package/dist/entities/page.js.map +1 -0
  127. package/dist/entities/post.d.ts +619 -0
  128. package/dist/entities/post.d.ts.map +1 -0
  129. package/dist/entities/post.js +555 -0
  130. package/dist/entities/post.js.map +1 -0
  131. package/dist/entities/price.d.ts +772 -0
  132. package/dist/entities/price.d.ts.map +1 -0
  133. package/dist/entities/price.js +308 -0
  134. package/dist/entities/price.js.map +1 -0
  135. package/dist/entities/product.d.ts +753 -0
  136. package/dist/entities/product.d.ts.map +1 -0
  137. package/dist/entities/product.js +307 -0
  138. package/dist/entities/product.js.map +1 -0
  139. package/dist/entities/session.d.ts +222 -0
  140. package/dist/entities/session.d.ts.map +1 -0
  141. package/dist/entities/session.js +253 -0
  142. package/dist/entities/session.js.map +1 -0
  143. package/dist/entities/site.d.ts +387 -0
  144. package/dist/entities/site.d.ts.map +1 -0
  145. package/dist/entities/site.js +348 -0
  146. package/dist/entities/site.js.map +1 -0
  147. package/dist/entities/ticket-comment.d.ts +49 -0
  148. package/dist/entities/ticket-comment.d.ts.map +1 -0
  149. package/dist/entities/ticket-comment.js +58 -0
  150. package/dist/entities/ticket-comment.js.map +1 -0
  151. package/dist/entities/ticket-label.d.ts +64 -0
  152. package/dist/entities/ticket-label.d.ts.map +1 -0
  153. package/dist/entities/ticket-label.js +77 -0
  154. package/dist/entities/ticket-label.js.map +1 -0
  155. package/dist/entities/ticket.d.ts +204 -0
  156. package/dist/entities/ticket.d.ts.map +1 -0
  157. package/dist/entities/ticket.js +205 -0
  158. package/dist/entities/ticket.js.map +1 -0
  159. package/dist/entities/user.d.ts +336 -0
  160. package/dist/entities/user.d.ts.map +1 -0
  161. package/dist/entities/user.js +255 -0
  162. package/dist/entities/user.js.map +1 -0
  163. package/dist/foundation/contract.d.ts +221 -0
  164. package/dist/foundation/contract.d.ts.map +1 -0
  165. package/dist/foundation/contract.js +133 -0
  166. package/dist/foundation/contract.js.map +1 -0
  167. package/dist/foundation/index.d.ts +7 -0
  168. package/dist/foundation/index.d.ts.map +1 -0
  169. package/dist/foundation/index.js +7 -0
  170. package/dist/foundation/index.js.map +1 -0
  171. package/dist/generated/contracts.d.ts +1514 -0
  172. package/dist/generated/contracts.d.ts.map +1 -0
  173. package/dist/generated/contracts.js +959 -0
  174. package/dist/generated/contracts.js.map +1 -0
  175. package/dist/generated/database.d.ts +48 -0
  176. package/dist/generated/database.d.ts.map +1 -0
  177. package/dist/generated/database.js +17 -0
  178. package/dist/generated/database.js.map +1 -0
  179. package/dist/generated/zod-schemas.d.ts +14793 -0
  180. package/dist/generated/zod-schemas.d.ts.map +1 -0
  181. package/dist/generated/zod-schemas.js +547 -0
  182. package/dist/generated/zod-schemas.js.map +1 -0
  183. package/dist/index.d.ts +50 -0
  184. package/dist/index.d.ts.map +1 -0
  185. package/dist/index.js +81 -0
  186. package/dist/index.js.map +1 -0
  187. package/dist/representation/index.d.ts +304 -0
  188. package/dist/representation/index.d.ts.map +1 -0
  189. package/dist/representation/index.js +280 -0
  190. package/dist/representation/index.js.map +1 -0
  191. package/package.json +117 -0
@@ -0,0 +1,122 @@
1
+ /**
2
+ * Configuration Validation Errors
3
+ *
4
+ * Provides detailed error reporting for config validation failures.
5
+ * Errors include:
6
+ * - Specific field paths that failed
7
+ * - Human-readable error messages
8
+ * - Links to documentation
9
+ *
10
+ * @module @revealui/contracts/core/contracts/errors
11
+ */
12
+ import type { ZodError, ZodIssue } from 'zod/v4';
13
+ /**
14
+ * Configuration validation error with detailed diagnostics
15
+ */
16
+ export declare class ConfigValidationError extends Error {
17
+ /** All validation issues found */
18
+ readonly issues: ZodIssue[];
19
+ /** Type of configuration being validated */
20
+ readonly configType: 'collection' | 'global' | 'field' | 'config';
21
+ /** Name/slug of the config (if available) */
22
+ readonly configName?: string;
23
+ /** The original Zod error */
24
+ readonly zodError: ZodError;
25
+ constructor(error: ZodError, configType: 'collection' | 'global' | 'field' | 'config', configName?: string);
26
+ /**
27
+ * Format error message with all issues
28
+ */
29
+ static formatMessage(error: ZodError, configType: string, configName?: string): string;
30
+ /**
31
+ * Get documentation URL for config type
32
+ */
33
+ static getDocsUrl(configType: string): string;
34
+ /**
35
+ * Get a specific issue by path
36
+ */
37
+ getIssue(path: string): ZodIssue | undefined;
38
+ /**
39
+ * Get all issues for a specific path prefix
40
+ */
41
+ getIssuesForPath(pathPrefix: string): ZodIssue[];
42
+ /**
43
+ * Check if a specific field has an error
44
+ */
45
+ hasFieldError(fieldName: string): boolean;
46
+ /**
47
+ * Get error messages as a simple array of strings
48
+ */
49
+ getMessages(): string[];
50
+ /**
51
+ * Convert to a plain object for serialization
52
+ */
53
+ toJSON(): {
54
+ name: string;
55
+ message: string;
56
+ configType: string;
57
+ configName?: string;
58
+ issues: Array<{
59
+ path: (string | number)[];
60
+ message: string;
61
+ code: string;
62
+ }>;
63
+ };
64
+ }
65
+ /**
66
+ * Result type for validation operations
67
+ */
68
+ export type ValidationResult<T> = {
69
+ success: true;
70
+ data: T;
71
+ } | {
72
+ success: false;
73
+ error: ConfigValidationError;
74
+ };
75
+ /**
76
+ * Validate data against a Zod schema with detailed error reporting
77
+ *
78
+ * @param schema - Zod schema to validate against
79
+ * @param data - Data to validate
80
+ * @param configType - Type of config for error messages
81
+ * @param configName - Optional name/slug for error messages
82
+ * @returns Validated data
83
+ * @throws {ConfigValidationError} If validation fails
84
+ *
85
+ * @example
86
+ * ```typescript
87
+ * const config = validateWithErrors(
88
+ * CollectionStructureSchema,
89
+ * userInput,
90
+ * 'collection',
91
+ * userInput.slug
92
+ * );
93
+ * ```
94
+ */
95
+ export declare function validateWithErrors<T>(schema: {
96
+ safeParse: (data: unknown) => {
97
+ success: boolean;
98
+ data?: T;
99
+ error?: ZodError;
100
+ };
101
+ }, data: unknown, configType: 'collection' | 'global' | 'field' | 'config', configName?: string): T;
102
+ /**
103
+ * Safe validation that returns a result object instead of throwing
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * const result = safeValidate(CollectionStructureSchema, userInput, 'collection');
108
+ * if (result.success) {
109
+ * console.log(result.data);
110
+ * } else {
111
+ * console.error(result.error.getMessages());
112
+ * }
113
+ * ```
114
+ */
115
+ export declare function safeValidate<T>(schema: {
116
+ safeParse: (data: unknown) => {
117
+ success: boolean;
118
+ data?: T;
119
+ error?: ZodError;
120
+ };
121
+ }, data: unknown, configType: 'collection' | 'global' | 'field' | 'config', configName?: string): ValidationResult<T>;
122
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/cms/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAEhD;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,kCAAkC;IAClC,SAAgB,MAAM,EAAE,QAAQ,EAAE,CAAA;IAClC,4CAA4C;IAC5C,SAAgB,UAAU,EAAE,YAAY,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,CAAA;IACxE,6CAA6C;IAC7C,SAAgB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnC,6BAA6B;IAC7B,SAAgB,QAAQ,EAAE,QAAQ,CAAA;gBAGhC,KAAK,EAAE,QAAQ,EACf,UAAU,EAAE,YAAY,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,EACxD,UAAU,CAAC,EAAE,MAAM;IAkBrB;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM;IAiBtF;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAc7C;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAI5C;;OAEG;IACH,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,QAAQ,EAAE;IAIhD;;OAEG;IACH,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO;IAIzC;;OAEG;I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,YAAY,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,EACxD,UAAU,CAAC,EAAE,MAAM,GAClB,gBAAgB,CAAC,CAAC,CAAC,CAWrB"}
@@ -0,0 +1,163 @@
1
+ /**
2
+ * Configuration Validation Errors
3
+ *
4
+ * Provides detailed error reporting for config validation failures.
5
+ * Errors include:
6
+ * - Specific field paths that failed
7
+ * - Human-readable error messages
8
+ * - Links to documentation
9
+ *
10
+ * @module @revealui/contracts/core/contracts/errors
11
+ */
12
+ /**
13
+ * Configuration validation error with detailed diagnostics
14
+ */
15
+ export class ConfigValidationError extends Error {
16
+ /** All validation issues found */
17
+ issues;
18
+ /** Type of configuration being validated */
19
+ configType;
20
+ /** Name/slug of the config (if available) */
21
+ configName;
22
+ /** The original Zod error */
23
+ zodError;
24
+ constructor(error, configType, configName) {
25
+ const message = ConfigValidationError.formatMessage(error, configType, configName);
26
+ super(message);
27
+ this.name = 'ConfigValidationError';
28
+ this.issues = error.issues;
29
+ this.configType = configType;
30
+ if (configName !== undefined) {
31
+ this.configName = configName;
32
+ }
33
+ this.zodError = error;
34
+ // Maintains proper stack trace in V8 environments
35
+ if (Error.captureStackTrace) {
36
+ Error.captureStackTrace(this, ConfigValidationError);
37
+ }
38
+ }
39
+ /**
40
+ * Format error message with all issues
41
+ */
42
+ static formatMessage(error, configType, configName) {
43
+ const header = configName
44
+ ? `Invalid ${configType} configuration "${configName}":`
45
+ : `Invalid ${configType} configuration:`;
46
+ const issueLines = error.issues.map((issue, i) => {
47
+ const path = issue.path.length > 0 ? issue.path.join('.') : '(root)';
48
+ return ` ${i + 1}. [${path}] ${issue.message}`;
49
+ });
50
+ const docsUrl = ConfigValidationError.getDocsUrl(configType);
51
+ return [header, '', ...issueLines, '', `See ${docsUrl} for valid configuration options.`].join('\n');
52
+ }
53
+ /**
54
+ * Get documentation URL for config type
55
+ */
56
+ static getDocsUrl(configType) {
57
+ const baseUrl = 'https://revealui.dev/docs';
58
+ switch (configType) {
59
+ case 'collection':
60
+ return `${baseUrl}/api-reference/collections`;
61
+ case 'global':
62
+ return `${baseUrl}/api-reference/globals`;
63
+ case 'field':
64
+ return `${baseUrl}/api-reference/fields`;
65
+ default:
66
+ return `${baseUrl}/api-reference/config`;
67
+ }
68
+ }
69
+ /**
70
+ * Get a specific issue by path
71
+ */
72
+ getIssue(path) {
73
+ return this.issues.find((issue) => issue.path.join('.') === path);
74
+ }
75
+ /**
76
+ * Get all issues for a specific path prefix
77
+ */
78
+ getIssuesForPath(pathPrefix) {
79
+ return this.issues.filter((issue) => issue.path.join('.').startsWith(pathPrefix));
80
+ }
81
+ /**
82
+ * Check if a specific field has an error
83
+ */
84
+ hasFieldError(fieldName) {
85
+ return this.issues.some((issue) => issue.path.includes(fieldName));
86
+ }
87
+ /**
88
+ * Get error messages as a simple array of strings
89
+ */
90
+ getMessages() {
91
+ return this.issues.map((issue) => {
92
+ const path = issue.path.length > 0 ? `[${issue.path.join('.')}] ` : '';
93
+ return `${path}${issue.message}`;
94
+ });
95
+ }
96
+ /**
97
+ * Convert to a plain object for serialization
98
+ */
99
+ toJSON() {
100
+ return {
101
+ name: this.name,
102
+ message: this.message,
103
+ configType: this.configType,
104
+ ...(this.configName && { configName: this.configName }),
105
+ issues: this.issues.map((issue) => ({
106
+ path: issue.path,
107
+ message: issue.message,
108
+ code: issue.code,
109
+ })),
110
+ };
111
+ }
112
+ }
113
+ /**
114
+ * Validate data against a Zod schema with detailed error reporting
115
+ *
116
+ * @param schema - Zod schema to validate against
117
+ * @param data - Data to validate
118
+ * @param configType - Type of config for error messages
119
+ * @param configName - Optional name/slug for error messages
120
+ * @returns Validated data
121
+ * @throws {ConfigValidationError} If validation fails
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * const config = validateWithErrors(
126
+ * CollectionStructureSchema,
127
+ * userInput,
128
+ * 'collection',
129
+ * userInput.slug
130
+ * );
131
+ * ```
132
+ */
133
+ export function validateWithErrors(schema, data, configType, configName) {
134
+ const result = schema.safeParse(data);
135
+ if (!result.success) {
136
+ throw new ConfigValidationError(result.error, configType, configName);
137
+ }
138
+ return result.data;
139
+ }
140
+ /**
141
+ * Safe validation that returns a result object instead of throwing
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * const result = safeValidate(CollectionStructureSchema, userInput, 'collection');
146
+ * if (result.success) {
147
+ * console.log(result.data);
148
+ * } else {
149
+ * console.error(result.error.getMessages());
150
+ * }
151
+ * ```
152
+ */
153
+ export function safeValidate(schema, data, configType, configName) {
154
+ const result = schema.safeParse(data);
155
+ if (!result.success) {
156
+ return {
157
+ success: false,
158
+ error: new ConfigValidationError(result.error, configType, configName),
159
+ };
160
+ }
161
+ return { success: true, data: result.data };
162
+ }
163
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/cms/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C,kCAAkC;IAClB,MAAM,CAAY;IAClC,4CAA4C;IAC5B,UAAU,CAA8C;IACxE,6CAA6C;IAC7B,UAAU,CAAS;IACnC,6BAA6B;IACb,QAAQ,CAAU;IAElC,YACE,KAAe,EACf,UAAwD,EACxD,UAAmB;QAEnB,MAAM,OAAO,GAAG,qBAAqB,CAAC,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,UAAU,CAAC,CAAA;QAClF,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAA;QACnC,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAA;QAC1B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;YAC7B,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC9B,CAAC;QACD,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAA;QAErB,kDAAkD;QAClD,I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AU,EAAE,CAAC;YACvD,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;gBAClC,IAAI,EAAE,KAAK,CAAC,IAA2B;gBACvC,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,IAAI,EAAE,KAAK,CAAC,IAAc;aAC3B,CAAC,CAAC;SACJ,CAAA;IACH,CAAC;CACF;AASD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAMC,EACD,IAAa,EACb,UAAwD,EACxD,UAAmB;IAEnB,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IAErC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,MAAM,IAAI,qBAAqB,CAAC,MAAM,CAAC,KAAiB,EAAE,UAAU,EAAE,UAAU,CAAC,CAAA;IACnF,CAAC;IAED,OAAO,MAAM,CAAC,IAAS,CAAA;AACzB,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAC1B,MAMC,EACD,IAAa,EACb,UAAwD,EACxD,UAAmB;IAEnB,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IAErC,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,OAAO;YACL,OAAO,EAAE,KAAK;YACd,KAAK,EAAE,IAAI,qBAAqB,CAAC,MAAM,CAAC,KAAiB,EAAE,UAAU,EAAE,UAAU,CAAC;SACnF,CAAA;IACH,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,IAAS,EAAE,CAAA;AAClD,CAAC"}
@@ -0,0 +1,211 @@
1
+ /**
2
+ * Extensibility Contracts
3
+ *
4
+ * Contracts for extending the CMS type system with:
5
+ * - Custom field types (from plugins)
6
+ * - Plugin field extensions
7
+ * - Custom validation rules
8
+ *
9
+ * @module @revealui/contracts/core/contracts/extensibility
10
+ */
11
+ import { z } from 'zod/v4';
12
+ import type { CollectionConfig, Field } from './config.js';
13
+ /**
14
+ * Configuration for a custom field type
15
+ */
16
+ export interface CustomFieldTypeConfig {
17
+ /** Zod schema for validating field config (optional) */
18
+ schema?: z.ZodType<unknown>;
19
+ /** Default value for this field type */
20
+ defaultValue?: unknown;
21
+ /** Custom validation function for field values */
22
+ validate?: (value: unknown) => boolean | string;
23
+ /** Description for documentation */
24
+ description?: string;
25
+ /** Whether this field can have nested fields */
26
+ hasNestedFields?: boolean;
27
+ /** Additional metadata */
28
+ meta?: Record<string, unknown>;
29
+ }
30
+ /**
31
+ * Registry of custom field types
32
+ */
33
+ export interface CustomFieldTypeRegistry {
34
+ [typeName: string]: CustomFieldTypeConfig;
35
+ }
36
+ /**
37
+ * Register a custom field type
38
+ *
39
+ * Call this from plugins to add new field types.
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * // In your plugin
44
+ * registerCustomFieldType('color-picker', {
45
+ * description: 'A color picker field',
46
+ * defaultValue: '#000000',
47
+ * validate: (value) => {
48
+ * if (typeof value !== 'string') return 'Color must be a string';
49
+ * if (!/^#[0-9a-f]{6}$/i.test(value)) return 'Invalid hex color';
50
+ * return true;
51
+ * },
52
+ * });
53
+ * ```
54
+ */
55
+ export declare function registerCustomFieldType(typeName: string, config: CustomFieldTypeConfig): void;
56
+ /**
57
+ * Get a registered custom field type
58
+ */
59
+ export declare function getCustomFieldType(typeName: string): CustomFieldTypeConfig | undefined;
60
+ /**
61
+ * Get all registered custom field types
62
+ */
63
+ export declare function getCustomFieldTypes(): CustomFieldTypeRegistry;
64
+ /**
65
+ * Unregister a custom field type (mainly for testing)
66
+ */
67
+ export declare function unregisterCustomFieldType(typeName: string): void;
68
+ /**
69
+ * Clear all custom field types (mainly for testing)
70
+ */
71
+ export declare function clearCustomFieldTypes(): void;
72
+ /**
73
+ * Built-in field types in RevealUI CMS
74
+ */
75
+ export declare const BUILTIN_FIELD_TYPES: readonly ["text", "textarea", "number", "email", "password", "code", "date", "checkbox", "select", "radio", "relationship", "upload", "array", "blocks", "group", "row", "collapsible", "tabs", "richText", "json", "point", "ui"];
76
+ export type BuiltinFieldType = (typeof BUILTIN_FIELD_TYPES)[number];
77
+ /**
78
+ * Check if a field type is valid (built-in or custom)
79
+ */
80
+ export declare function isValidFieldType(type: string): boolean;
81
+ /**
82
+ * Get all valid field types (built-in + custom)
83
+ */
84
+ export declare function getValidFieldTypes(): string[];
85
+ /**
86
+ * Extended field type schema that includes custom types
87
+ *
88
+ * Use this schema when validating field configs that may include
89
+ * custom field types from plugins.
90
+ */
91
+ export declare const ExtendedFieldTypeSchema: z.ZodString;
92
+ /**
93
+ * Plugin field extension configuration
94
+ *
95
+ * Allows plugins to add fields to collections.
96
+ */
97
+ export interface PluginFieldExtension {
98
+ /** Plugin name (for debugging and conflict resolution) */
99
+ pluginName: string;
100
+ /** Priority for ordering when multiple plugins add fields (higher = later) */
101
+ priority?: number;
102
+ /** Fields to add to ALL collections */
103
+ globalFields?: Field[];
104
+ /** Fields to add to specific collections (by slug) */
105
+ collectionFields?: Record<string, Field[]>;
106
+ /** Custom field type definitions provided by this plugin */
107
+ customFieldTypes?: Array<{
108
+ name: string;
109
+ config: CustomFieldTypeConfig;
110
+ }>;
111
+ /** Hook to modify collection config before finalization */
112
+ beforeFinalize?: (config: CollectionConfig) => CollectionConfig;
113
+ }
114
+ /**
115
+ * Register a plugin field extension
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * registerPluginExtension({
120
+ * pluginName: 'seo-plugin',
121
+ * globalFields: [
122
+ * { name: 'metaTitle', type: 'text', admin: { position: 'sidebar' } },
123
+ * { name: 'metaDescription', type: 'textarea' },
124
+ * ],
125
+ * collectionFields: {
126
+ * posts: [
127
+ * { name: 'canonicalUrl', type: 'text' },
128
+ * ],
129
+ * },
130
+ * });
131
+ * ```
132
+ */
133
+ export declare function registerPluginExtension(extension: PluginFieldExtension): void;
134
+ /**
135
+ * Get all registered plugin extensions
136
+ */
137
+ export declare function getPluginExtensions(): PluginFieldExtension[];
138
+ /**
139
+ * Clear all plugin extensions (mainly for testing)
140
+ */
141
+ export declare function clearPluginExtensions(): void;
142
+ /**
143
+ * Apply plugin field extensions to a collection config
144
+ *
145
+ * This is called during config finalization to add plugin-provided fields.
146
+ *
147
+ * @param config - The base collection config
148
+ * @returns The config with plugin fields added
149
+ */
150
+ export declare function applyPluginExtensions(config: CollectionConfig): CollectionConfig;
151
+ /**
152
+ * Custom validation rule configuration
153
+ */
154
+ export interface CustomValidationRule {
155
+ /** Rule name (for error messages) */
156
+ name: string;
157
+ /** Validation function */
158
+ validate: (value: unknown, options?: unknown) => boolean | string;
159
+ /** Default error message */
160
+ message?: string;
161
+ /** Description for documentation */
162
+ description?: string;
163
+ }
164
+ /**
165
+ * Registry of custom validation rules
166
+ */
167
+ export interface ValidationRuleRegistry {
168
+ [ruleName: string]: CustomValidationRule;
169
+ }
170
+ /**
171
+ * Register a custom validation rule
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * registerValidationRule({
176
+ * name: 'slug-format',
177
+ * validate: (value) => {
178
+ * if (typeof value !== 'string') return 'Must be a string';
179
+ * if (!/^[a-z0-9-]+$/.test(value)) {
180
+ * return 'Slug must contain only lowercase letters, numbers, and hyphens';
181
+ * }
182
+ * return true;
183
+ * },
184
+ * description: 'Validates URL-safe slug format',
185
+ * });
186
+ * ```
187
+ */
188
+ export declare function registerValidationRule(rule: CustomValidationRule): void;
189
+ /**
190
+ * Get a validation rule by name
191
+ */
192
+ export declare function getValidationRule(name: string): CustomValidationRule | undefined;
193
+ /**
194
+ * Get all registered validation rules
195
+ */
196
+ export declare function getValidationRules(): ValidationRuleRegistry;
197
+ /**
198
+ * Run a validation rule against a value
199
+ */
200
+ export declare function runValidationRule(ruleName: string, value: unknown, options?: unknown): boolean | string;
201
+ /**
202
+ * Merge field arrays, handling conflicts by name
203
+ *
204
+ * Later fields override earlier fields with the same name.
205
+ */
206
+ export declare function mergeFields(base: Field[], additions: Field[]): Field[];
207
+ /**
208
+ * Deep merge two collection configs
209
+ */
210
+ export declare function mergeCollectionConfigs(base: CollectionConfig, overrides: Partial<CollectionConfig>): CollectionConfig;
211
+ //# sourceMappingURL=extensibility.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extensibility.d.ts","sourceRoot":"","sources":["../../src/cms/extensibility.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAA;AAC1B,OAAO,KAAK,EAAE,gBAAgB,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAM1D;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,wDAAwD;IACxD,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAE3B,wCAAwC;IACxC,YAAY,CAAC,EAAE,OAAO,CAAA;IAEtB,kDAAkD;IAClD,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,GAAG,MAAM,CAAA;IAE/C,oCAAoC;IACpC,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB,gDAAgD;IAChD,eAAe,CAAC,EAAE,OAAO,CAAA;IAEzB,0BAA0B;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,CAAC,QAAQ,EAAE,MAAM,GAAG,qBAAqB,CAAA;CAC1C;AAKD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,qBAAqB,GAAG,IAAI,CAG7F;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAEtF;AAED;;GAEG;AACH,wBAAgB,mBAAmB,IAAI,uB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