@object-ui/core 0.3.0 → 0.5.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 (90) hide show
  1. package/.turbo/turbo-build.log +4 -0
  2. package/CHANGELOG.md +8 -0
  3. package/dist/actions/ActionRunner.d.ts +40 -0
  4. package/dist/actions/ActionRunner.js +160 -0
  5. package/dist/actions/index.d.ts +8 -0
  6. package/dist/actions/index.js +8 -0
  7. package/dist/adapters/index.d.ts +7 -0
  8. package/dist/adapters/index.js +10 -0
  9. package/dist/builder/schema-builder.d.ts +7 -0
  10. package/dist/builder/schema-builder.js +4 -6
  11. package/dist/evaluator/ExpressionCache.d.ts +101 -0
  12. package/dist/evaluator/ExpressionCache.js +135 -0
  13. package/dist/evaluator/ExpressionContext.d.ts +51 -0
  14. package/dist/evaluator/ExpressionContext.js +110 -0
  15. package/dist/evaluator/ExpressionEvaluator.d.ts +117 -0
  16. package/dist/evaluator/ExpressionEvaluator.js +220 -0
  17. package/dist/evaluator/index.d.ts +10 -0
  18. package/dist/evaluator/index.js +10 -0
  19. package/dist/index.d.ts +17 -4
  20. package/dist/index.js +16 -5
  21. package/dist/query/index.d.ts +6 -0
  22. package/dist/query/index.js +6 -0
  23. package/dist/query/query-ast.d.ts +32 -0
  24. package/dist/query/query-ast.js +268 -0
  25. package/dist/registry/PluginScopeImpl.d.ts +80 -0
  26. package/dist/registry/PluginScopeImpl.js +243 -0
  27. package/dist/registry/PluginSystem.d.ts +66 -0
  28. package/dist/registry/PluginSystem.js +142 -0
  29. package/dist/registry/Registry.d.ts +80 -4
  30. package/dist/registry/Registry.js +119 -7
  31. package/dist/types/index.d.ts +7 -0
  32. package/dist/types/index.js +7 -0
  33. package/dist/utils/filter-converter.d.ts +57 -0
  34. package/dist/utils/filter-converter.js +100 -0
  35. package/dist/validation/index.d.ts +9 -0
  36. package/dist/validation/index.js +9 -0
  37. package/dist/validation/schema-validator.d.ts +7 -0
  38. package/dist/validation/schema-validator.js +4 -6
  39. package/dist/validation/validation-engine.d.ts +70 -0
  40. package/dist/validation/validation-engine.js +363 -0
  41. package/dist/validation/validators/index.d.ts +16 -0
  42. package/dist/validation/validators/index.js +16 -0
  43. package/dist/validation/validators/object-validation-engine.d.ts +118 -0
  44. package/dist/validation/validators/object-validation-engine.js +538 -0
  45. package/package.json +26 -7
  46. package/src/actions/ActionRunner.ts +195 -0
  47. package/src/actions/index.ts +9 -0
  48. package/src/adapters/README.md +180 -0
  49. package/src/adapters/index.ts +10 -0
  50. package/src/builder/schema-builder.ts +8 -0
  51. package/src/evaluator/ExpressionCache.ts +192 -0
  52. package/src/evaluator/ExpressionContext.ts +118 -0
  53. package/src/evaluator/ExpressionEvaluator.ts +267 -0
  54. package/src/evaluator/__tests__/ExpressionCache.test.ts +135 -0
  55. package/src/evaluator/__tests__/ExpressionEvaluator.test.ts +101 -0
  56. package/src/evaluator/index.ts +11 -0
  57. package/src/index.test.ts +8 -0
  58. package/src/index.ts +18 -5
  59. package/src/query/__tests__/query-ast.test.ts +211 -0
  60. package/src/query/__tests__/window-functions.test.ts +275 -0
  61. package/src/query/index.ts +7 -0
  62. package/src/query/query-ast.ts +341 -0
  63. package/src/registry/PluginScopeImpl.ts +259 -0
  64. package/src/registry/PluginSystem.ts +161 -0
  65. package/src/registry/Registry.ts +133 -8
  66. package/src/registry/__tests__/PluginSystem.test.ts +226 -0
  67. package/src/registry/__tests__/Registry.test.ts +293 -0
  68. package/src/registry/__tests__/plugin-scope-integration.test.ts +283 -0
  69. package/src/types/index.ts +8 -0
  70. package/src/utils/__tests__/filter-converter.test.ts +118 -0
  71. package/src/utils/filter-converter.ts +133 -0
  72. package/src/validation/__tests__/object-validation-engine.test.ts +567 -0
  73. package/src/validation/__tests__/validation-engine.test.ts +102 -0
  74. package/src/validation/index.ts +10 -0
  75. package/src/validation/schema-validator.ts +8 -0
  76. package/src/validation/validation-engine.ts +461 -0
  77. package/src/validation/validators/index.ts +25 -0
  78. package/src/validation/validators/object-validation-engine.ts +722 -0
  79. package/tsconfig.tsbuildinfo +1 -1
  80. package/vitest.config.ts +2 -0
  81. package/src/builder/schema-builder.d.ts +0 -287
  82. package/src/builder/schema-builder.js +0 -505
  83. package/src/index.d.ts +0 -4
  84. package/src/index.js +0 -7
  85. package/src/registry/Registry.d.ts +0 -49
  86. package/src/registry/Registry.js +0 -36
  87. package/src/types/index.d.ts +0 -12
  88. package/src/types/index.js +0 -1
  89. package/src/validation/schema-validator.d.ts +0 -87
  90. package/src/validation/schema-validator.js +0 -280
@@ -1,280 +0,0 @@
1
- /**
2
- * @object-ui/core - Schema Validation
3
- *
4
- * Runtime validation utilities for Object UI schemas.
5
- * These utilities help ensure schemas are valid before rendering.
6
- *
7
- * @module validation
8
- * @packageDocumentation
9
- */
10
- /**
11
- * Validation rules for base schema
12
- */
13
- const BASE_SCHEMA_RULES = {
14
- type: {
15
- required: true,
16
- validate: (value) => typeof value === 'string' && value.length > 0,
17
- message: 'type must be a non-empty string'
18
- },
19
- id: {
20
- required: false,
21
- validate: (value) => typeof value === 'string',
22
- message: 'id must be a string'
23
- },
24
- className: {
25
- required: false,
26
- validate: (value) => typeof value === 'string',
27
- message: 'className must be a string'
28
- },
29
- visible: {
30
- required: false,
31
- validate: (value) => typeof value === 'boolean',
32
- message: 'visible must be a boolean'
33
- },
34
- disabled: {
35
- required: false,
36
- validate: (value) => typeof value === 'boolean',
37
- message: 'disabled must be a boolean'
38
- }
39
- };
40
- /**
41
- * Validate a schema against base rules
42
- */
43
- function validateBaseSchema(schema, path = 'schema') {
44
- const errors = [];
45
- if (!schema || typeof schema !== 'object') {
46
- errors.push({
47
- path,
48
- message: 'Schema must be an object',
49
- type: 'error',
50
- code: 'INVALID_SCHEMA'
51
- });
52
- return errors;
53
- }
54
- // Validate required and optional properties
55
- Object.entries(BASE_SCHEMA_RULES).forEach(([key, rule]) => {
56
- const value = schema[key];
57
- if (rule.required && value === undefined) {
58
- errors.push({
59
- path: `${path}.${key}`,
60
- message: `${key} is required`,
61
- type: 'error',
62
- code: 'MISSING_REQUIRED'
63
- });
64
- }
65
- if (value !== undefined && !rule.validate(value)) {
66
- errors.push({
67
- path: `${path}.${key}`,
68
- message: rule.message,
69
- type: 'error',
70
- code: 'INVALID_TYPE'
71
- });
72
- }
73
- });
74
- return errors;
75
- }
76
- /**
77
- * Validate CRUD schema specific properties
78
- */
79
- function validateCRUDSchema(schema, path = 'schema') {
80
- const errors = [];
81
- if (schema.type === 'crud') {
82
- // Check required properties for CRUD
83
- if (!schema.columns || !Array.isArray(schema.columns)) {
84
- errors.push({
85
- path: `${path}.columns`,
86
- message: 'CRUD schema requires columns array',
87
- type: 'error',
88
- code: 'MISSING_COLUMNS'
89
- });
90
- }
91
- if (!schema.api && !schema.dataSource) {
92
- errors.push({
93
- path: `${path}.api`,
94
- message: 'CRUD schema requires api or dataSource',
95
- type: 'warning',
96
- code: 'MISSING_DATA_SOURCE'
97
- });
98
- }
99
- // Validate columns
100
- if (schema.columns && Array.isArray(schema.columns)) {
101
- schema.columns.forEach((column, index) => {
102
- if (!column.name) {
103
- errors.push({
104
- path: `${path}.columns[${index}]`,
105
- message: 'Column requires name property',
106
- type: 'error',
107
- code: 'MISSING_COLUMN_NAME'
108
- });
109
- }
110
- });
111
- }
112
- // Validate fields if present
113
- if (schema.fields && Array.isArray(schema.fields)) {
114
- schema.fields.forEach((field, index) => {
115
- if (!field.name) {
116
- errors.push({
117
- path: `${path}.fields[${index}]`,
118
- message: 'Field requires name property',
119
- type: 'error',
120
- code: 'MISSING_FIELD_NAME'
121
- });
122
- }
123
- });
124
- }
125
- }
126
- return errors;
127
- }
128
- /**
129
- * Validate form schema specific properties
130
- */
131
- function validateFormSchema(schema, path = 'schema') {
132
- const errors = [];
133
- if (schema.type === 'form') {
134
- if (schema.fields && Array.isArray(schema.fields)) {
135
- schema.fields.forEach((field, index) => {
136
- if (!field.name) {
137
- errors.push({
138
- path: `${path}.fields[${index}]`,
139
- message: 'Form field requires name property',
140
- type: 'error',
141
- code: 'MISSING_FIELD_NAME'
142
- });
143
- }
144
- // Check for duplicate field names
145
- const duplicates = schema.fields.filter((f) => f.name === field.name);
146
- if (duplicates.length > 1) {
147
- errors.push({
148
- path: `${path}.fields[${index}]`,
149
- message: `Duplicate field name: ${field.name}`,
150
- type: 'warning',
151
- code: 'DUPLICATE_FIELD_NAME'
152
- });
153
- }
154
- });
155
- }
156
- }
157
- return errors;
158
- }
159
- /**
160
- * Validate child schemas recursively
161
- */
162
- function validateChildren(schema, path = 'schema') {
163
- const errors = [];
164
- const children = schema.children || schema.body;
165
- if (children) {
166
- if (Array.isArray(children)) {
167
- children.forEach((child, index) => {
168
- if (typeof child === 'object' && child !== null) {
169
- const childResult = validateSchema(child, `${path}.children[${index}]`);
170
- errors.push(...childResult.errors, ...childResult.warnings);
171
- }
172
- });
173
- }
174
- else if (typeof children === 'object' && children !== null) {
175
- const childResult = validateSchema(children, `${path}.children`);
176
- errors.push(...childResult.errors, ...childResult.warnings);
177
- }
178
- }
179
- return errors;
180
- }
181
- /**
182
- * Validate a complete schema
183
- *
184
- * @param schema - The schema to validate
185
- * @param options - Validation options
186
- * @returns Validation result with errors and warnings
187
- *
188
- * @example
189
- * ```typescript
190
- * const result = validateSchema({
191
- * type: 'form',
192
- * fields: [
193
- * { name: 'email', type: 'input' }
194
- * ]
195
- * });
196
- *
197
- * if (!result.valid) {
198
- * console.error('Validation errors:', result.errors);
199
- * }
200
- * ```
201
- */
202
- export function validateSchema(schema, path = 'schema') {
203
- const allErrors = [];
204
- // Validate base schema
205
- allErrors.push(...validateBaseSchema(schema, path));
206
- // Validate type-specific schemas
207
- allErrors.push(...validateCRUDSchema(schema, path));
208
- allErrors.push(...validateFormSchema(schema, path));
209
- // Validate children recursively
210
- allErrors.push(...validateChildren(schema, path));
211
- const errors = allErrors.filter(e => e.type === 'error');
212
- const warnings = allErrors.filter(e => e.type === 'warning');
213
- return {
214
- valid: errors.length === 0,
215
- errors,
216
- warnings
217
- };
218
- }
219
- /**
220
- * Assert that a schema is valid, throwing an error if not
221
- *
222
- * @param schema - The schema to validate
223
- * @throws Error if schema is invalid
224
- *
225
- * @example
226
- * ```typescript
227
- * try {
228
- * assertValidSchema(schema);
229
- * // Schema is valid, continue rendering
230
- * } catch (error) {
231
- * console.error('Invalid schema:', error.message);
232
- * }
233
- * ```
234
- */
235
- export function assertValidSchema(schema) {
236
- const result = validateSchema(schema);
237
- if (!result.valid) {
238
- const errorMessages = result.errors.map(e => `${e.path}: ${e.message}`).join('\n');
239
- throw new Error(`Schema validation failed:\n${errorMessages}`);
240
- }
241
- }
242
- /**
243
- * Check if a value is a valid schema
244
- *
245
- * @param value - The value to check
246
- * @returns True if the value is a valid schema
247
- *
248
- * @example
249
- * ```typescript
250
- * if (isValidSchema(data)) {
251
- * renderSchema(data);
252
- * }
253
- * ```
254
- */
255
- export function isValidSchema(value) {
256
- const result = validateSchema(value);
257
- return result.valid;
258
- }
259
- /**
260
- * Get a human-readable error summary
261
- *
262
- * @param result - The validation result
263
- * @returns Formatted error summary
264
- */
265
- export function formatValidationErrors(result) {
266
- const parts = [];
267
- if (result.errors.length > 0) {
268
- parts.push('Errors:');
269
- result.errors.forEach(error => {
270
- parts.push(` - ${error.path}: ${error.message}`);
271
- });
272
- }
273
- if (result.warnings.length > 0) {
274
- parts.push('Warnings:');
275
- result.warnings.forEach(warning => {
276
- parts.push(` - ${warning.path}: ${warning.message}`);
277
- });
278
- }
279
- return parts.join('\n');
280
- }