@object-ui/core 3.3.0 → 3.3.2

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 (101) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +20 -1
  3. package/dist/actions/ActionRunner.d.ts +9 -0
  4. package/dist/actions/ActionRunner.js +41 -4
  5. package/dist/adapters/ValueDataSource.js +3 -1
  6. package/dist/registry/Registry.d.ts +47 -0
  7. package/dist/registry/Registry.js +92 -0
  8. package/dist/utils/filter-converter.js +25 -5
  9. package/package.json +32 -8
  10. package/.turbo/turbo-build.log +0 -4
  11. package/src/__benchmarks__/core.bench.ts +0 -64
  12. package/src/__tests__/protocols/DndProtocol.test.ts +0 -186
  13. package/src/__tests__/protocols/KeyboardProtocol.test.ts +0 -177
  14. package/src/__tests__/protocols/NotificationProtocol.test.ts +0 -142
  15. package/src/__tests__/protocols/ResponsiveProtocol.test.ts +0 -176
  16. package/src/__tests__/protocols/SharingProtocol.test.ts +0 -188
  17. package/src/actions/ActionEngine.ts +0 -268
  18. package/src/actions/ActionRunner.ts +0 -717
  19. package/src/actions/TransactionManager.ts +0 -521
  20. package/src/actions/UndoManager.ts +0 -215
  21. package/src/actions/__tests__/ActionEngine.test.ts +0 -206
  22. package/src/actions/__tests__/ActionRunner.params.test.ts +0 -134
  23. package/src/actions/__tests__/ActionRunner.test.ts +0 -711
  24. package/src/actions/__tests__/TransactionManager.test.ts +0 -447
  25. package/src/actions/__tests__/UndoManager.test.ts +0 -320
  26. package/src/actions/index.ts +0 -12
  27. package/src/adapters/ApiDataSource.ts +0 -376
  28. package/src/adapters/README.md +0 -180
  29. package/src/adapters/ValueDataSource.ts +0 -459
  30. package/src/adapters/__tests__/ApiDataSource.test.ts +0 -418
  31. package/src/adapters/__tests__/ValueDataSource.test.ts +0 -571
  32. package/src/adapters/__tests__/resolveDataSource.test.ts +0 -144
  33. package/src/adapters/index.ts +0 -15
  34. package/src/adapters/resolveDataSource.ts +0 -79
  35. package/src/builder/__tests__/schema-builder.test.ts +0 -235
  36. package/src/builder/schema-builder.ts +0 -584
  37. package/src/data-scope/DataScopeManager.ts +0 -269
  38. package/src/data-scope/ViewDataProvider.ts +0 -282
  39. package/src/data-scope/__tests__/DataScopeManager.test.ts +0 -211
  40. package/src/data-scope/__tests__/ViewDataProvider.test.ts +0 -270
  41. package/src/data-scope/index.ts +0 -24
  42. package/src/errors/__tests__/errors.test.ts +0 -292
  43. package/src/errors/index.ts +0 -269
  44. package/src/evaluator/ExpressionCache.ts +0 -206
  45. package/src/evaluator/ExpressionContext.ts +0 -118
  46. package/src/evaluator/ExpressionEvaluator.ts +0 -315
  47. package/src/evaluator/FormulaFunctions.ts +0 -398
  48. package/src/evaluator/SafeExpressionParser.ts +0 -893
  49. package/src/evaluator/__tests__/ExpressionCache.test.ts +0 -135
  50. package/src/evaluator/__tests__/ExpressionContext.test.ts +0 -110
  51. package/src/evaluator/__tests__/ExpressionEvaluator.test.ts +0 -558
  52. package/src/evaluator/__tests__/FormulaFunctions.test.ts +0 -447
  53. package/src/evaluator/index.ts +0 -13
  54. package/src/index.ts +0 -38
  55. package/src/protocols/DndProtocol.ts +0 -168
  56. package/src/protocols/KeyboardProtocol.ts +0 -181
  57. package/src/protocols/NotificationProtocol.ts +0 -150
  58. package/src/protocols/ResponsiveProtocol.ts +0 -210
  59. package/src/protocols/SharingProtocol.ts +0 -185
  60. package/src/protocols/index.ts +0 -13
  61. package/src/query/__tests__/query-ast.test.ts +0 -211
  62. package/src/query/__tests__/window-functions.test.ts +0 -275
  63. package/src/query/index.ts +0 -7
  64. package/src/query/query-ast.ts +0 -341
  65. package/src/registry/PluginScopeImpl.ts +0 -259
  66. package/src/registry/PluginSystem.ts +0 -206
  67. package/src/registry/Registry.ts +0 -219
  68. package/src/registry/WidgetRegistry.ts +0 -316
  69. package/src/registry/__tests__/PluginSystem.test.ts +0 -309
  70. package/src/registry/__tests__/Registry.test.ts +0 -293
  71. package/src/registry/__tests__/WidgetRegistry.test.ts +0 -321
  72. package/src/registry/__tests__/plugin-scope-integration.test.ts +0 -283
  73. package/src/theme/ThemeEngine.ts +0 -530
  74. package/src/theme/__tests__/ThemeEngine.test.ts +0 -668
  75. package/src/theme/index.ts +0 -24
  76. package/src/types/index.ts +0 -21
  77. package/src/utils/__tests__/debug-collector.test.ts +0 -102
  78. package/src/utils/__tests__/debug.test.ts +0 -134
  79. package/src/utils/__tests__/expand-fields.test.ts +0 -120
  80. package/src/utils/__tests__/extract-records.test.ts +0 -50
  81. package/src/utils/__tests__/filter-converter.test.ts +0 -118
  82. package/src/utils/__tests__/merge-views-into-objects.test.ts +0 -110
  83. package/src/utils/__tests__/normalize-quick-filter.test.ts +0 -123
  84. package/src/utils/debug-collector.ts +0 -100
  85. package/src/utils/debug.ts +0 -148
  86. package/src/utils/expand-fields.ts +0 -76
  87. package/src/utils/extract-records.ts +0 -33
  88. package/src/utils/filter-converter.ts +0 -133
  89. package/src/utils/merge-views-into-objects.ts +0 -36
  90. package/src/utils/normalize-quick-filter.ts +0 -78
  91. package/src/validation/__tests__/object-validation-engine.test.ts +0 -567
  92. package/src/validation/__tests__/schema-validator.test.ts +0 -118
  93. package/src/validation/__tests__/validation-engine.test.ts +0 -102
  94. package/src/validation/index.ts +0 -10
  95. package/src/validation/schema-validator.ts +0 -344
  96. package/src/validation/validation-engine.ts +0 -528
  97. package/src/validation/validators/index.ts +0 -25
  98. package/src/validation/validators/object-validation-engine.ts +0 -722
  99. package/tsconfig.json +0 -15
  100. package/tsconfig.tsbuildinfo +0 -1
  101. package/vitest.config.ts +0 -2
@@ -1,528 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
-
9
- /**
10
- * @object-ui/core - Validation Engine
11
- *
12
- * Phase 3.5: Complete validation engine implementation with support for:
13
- * - Sync and async validation
14
- * - Cross-field validation
15
- * - Custom validation functions
16
- * - Improved error messages
17
- *
18
- * @module validation-engine
19
- * @packageDocumentation
20
- */
21
-
22
- import type {
23
- AdvancedValidationSchema,
24
- AdvancedValidationRule,
25
- ValidationRuleType,
26
- ValidationFunction,
27
- AsyncValidationFunction,
28
- ValidationContext,
29
- AdvancedValidationResult,
30
- AdvancedValidationError,
31
- } from '@object-ui/types';
32
-
33
- /**
34
- * Validation Engine - Executes validation rules
35
- */
36
- export class ValidationEngine {
37
- private customValidators = new Map<string, ValidationFunction>();
38
- private customAsyncValidators = new Map<string, AsyncValidationFunction>();
39
-
40
- /**
41
- * Register a custom synchronous validator by name
42
- */
43
- registerValidator(name: string, fn: ValidationFunction): void {
44
- this.customValidators.set(name, fn);
45
- }
46
-
47
- /**
48
- * Register a custom asynchronous validator by name
49
- */
50
- registerAsyncValidator(name: string, fn: AsyncValidationFunction): void {
51
- this.customAsyncValidators.set(name, fn);
52
- }
53
-
54
- /**
55
- * Check if a custom validator is registered
56
- */
57
- hasValidator(name: string): boolean {
58
- return this.customValidators.has(name) || this.customAsyncValidators.has(name);
59
- }
60
-
61
- /**
62
- * Get all registered custom validator names
63
- */
64
- getValidatorNames(): string[] {
65
- return [
66
- ...Array.from(this.customValidators.keys()),
67
- ...Array.from(this.customAsyncValidators.keys()),
68
- ];
69
- }
70
- /**
71
- * Validate a value against validation schema
72
- */
73
- async validate(
74
- value: any,
75
- schema: AdvancedValidationSchema,
76
- context?: ValidationContext
77
- ): Promise<AdvancedValidationResult> {
78
- const errors: AdvancedValidationError[] = [];
79
- const warnings: AdvancedValidationError[] = [];
80
-
81
- for (const rule of schema.rules) {
82
- const result = await this.validateRule(value, rule, context);
83
-
84
- if (result) {
85
- const error: AdvancedValidationError = {
86
- field: schema.field || 'unknown',
87
- message: result,
88
- code: rule.type,
89
- rule: rule.type,
90
- severity: rule.severity || 'error',
91
- };
92
-
93
- if (rule.severity === 'warning' || rule.severity === 'info') {
94
- warnings.push(error);
95
- } else {
96
- errors.push(error);
97
- }
98
- }
99
- }
100
-
101
- return {
102
- valid: errors.length === 0,
103
- errors,
104
- warnings,
105
- };
106
- }
107
-
108
- /**
109
- * Validate a single rule
110
- */
111
- private async validateRule(
112
- value: any,
113
- rule: AdvancedValidationRule,
114
- context?: ValidationContext
115
- ): Promise<string | null> {
116
- // Custom async validator (inline)
117
- if (rule.async_validator) {
118
- const result = await rule.async_validator(value, context);
119
- if (result === false) {
120
- return rule.message || 'Async validation failed';
121
- }
122
- if (typeof result === 'string') {
123
- return result;
124
- }
125
- return null;
126
- }
127
-
128
- // Custom sync validator (inline)
129
- if (rule.validator) {
130
- const result = rule.validator(value, context);
131
- if (result === false) {
132
- return rule.message || 'Validation failed';
133
- }
134
- if (typeof result === 'string') {
135
- return result;
136
- }
137
- return null;
138
- }
139
-
140
- // Registered custom async validator (by name)
141
- const registeredAsync = this.customAsyncValidators.get(rule.type);
142
- if (registeredAsync) {
143
- const result = await registeredAsync(value, context);
144
- if (result === false) {
145
- return rule.message || 'Async validation failed';
146
- }
147
- if (typeof result === 'string') {
148
- return result;
149
- }
150
- return null;
151
- }
152
-
153
- // Registered custom sync validator (by name)
154
- const registeredSync = this.customValidators.get(rule.type);
155
- if (registeredSync) {
156
- const result = registeredSync(value, context);
157
- if (result === false) {
158
- return rule.message || 'Validation failed';
159
- }
160
- if (typeof result === 'string') {
161
- return result;
162
- }
163
- return null;
164
- }
165
-
166
- // Built-in validators
167
- return this.validateBuiltInRule(value, rule, context);
168
- }
169
-
170
- /**
171
- * Validate built-in rules
172
- */
173
- private async validateBuiltInRule(
174
- value: any,
175
- rule: AdvancedValidationRule,
176
- context?: ValidationContext
177
- ): Promise<string | null> {
178
- const { type, params, message } = rule;
179
-
180
- switch (type) {
181
- case 'required':
182
- if (value === null || value === undefined || value === '') {
183
- return message || 'This field is required';
184
- }
185
- break;
186
-
187
- case 'min_length':
188
- if (typeof value === 'string' && value.length < params) {
189
- return message || `Minimum length is ${params} characters`;
190
- }
191
- break;
192
-
193
- case 'max_length':
194
- if (typeof value === 'string' && value.length > params) {
195
- return message || `Maximum length is ${params} characters`;
196
- }
197
- break;
198
-
199
- case 'pattern':
200
- if (typeof value === 'string') {
201
- try {
202
- const regex = typeof params === 'string' ? new RegExp(params) : params;
203
- if (!regex.test(value)) {
204
- return message || 'Invalid format';
205
- }
206
- } catch (error) {
207
- return message || 'Invalid pattern configuration';
208
- }
209
- }
210
- break;
211
-
212
- case 'email':
213
- if (typeof value === 'string') {
214
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
215
- if (!emailRegex.test(value)) {
216
- return message || 'Invalid email address';
217
- }
218
- }
219
- break;
220
-
221
- case 'url':
222
- if (typeof value === 'string') {
223
- try {
224
- new URL(value);
225
- } catch {
226
- return message || 'Invalid URL';
227
- }
228
- }
229
- break;
230
-
231
- case 'phone':
232
- if (typeof value === 'string') {
233
- const phoneRegex = /^[\d\s\-+()]+$/;
234
- if (!phoneRegex.test(value)) {
235
- return message || 'Invalid phone number';
236
- }
237
- }
238
- break;
239
-
240
- case 'min':
241
- if (typeof value === 'number' && value < params) {
242
- return message || `Minimum value is ${params}`;
243
- }
244
- break;
245
-
246
- case 'max':
247
- if (typeof value === 'number' && value > params) {
248
- return message || `Maximum value is ${params}`;
249
- }
250
- break;
251
-
252
- case 'integer':
253
- if (typeof value === 'number' && !Number.isInteger(value)) {
254
- return message || 'Value must be an integer';
255
- }
256
- break;
257
-
258
- case 'positive':
259
- if (typeof value === 'number' && value <= 0) {
260
- return message || 'Value must be positive';
261
- }
262
- break;
263
-
264
- case 'negative':
265
- if (typeof value === 'number' && value >= 0) {
266
- return message || 'Value must be negative';
267
- }
268
- break;
269
-
270
- case 'date_min':
271
- if (value instanceof Date || typeof value === 'string') {
272
- const date = value instanceof Date ? value : new Date(value);
273
- const minDate = params instanceof Date ? params : new Date(params);
274
- if (date < minDate) {
275
- return message || `Date must be after ${minDate.toLocaleDateString()}`;
276
- }
277
- }
278
- break;
279
-
280
- case 'date_max':
281
- if (value instanceof Date || typeof value === 'string') {
282
- const date = value instanceof Date ? value : new Date(value);
283
- const maxDate = params instanceof Date ? params : new Date(params);
284
- if (date > maxDate) {
285
- return message || `Date must be before ${maxDate.toLocaleDateString()}`;
286
- }
287
- }
288
- break;
289
-
290
- case 'date_future':
291
- if (value instanceof Date || typeof value === 'string') {
292
- const date = value instanceof Date ? value : new Date(value);
293
- if (date <= new Date()) {
294
- return message || 'Date must be in the future';
295
- }
296
- }
297
- break;
298
-
299
- case 'date_past':
300
- if (value instanceof Date || typeof value === 'string') {
301
- const date = value instanceof Date ? value : new Date(value);
302
- if (date >= new Date()) {
303
- return message || 'Date must be in the past';
304
- }
305
- }
306
- break;
307
-
308
- case 'min_items':
309
- if (Array.isArray(value) && value.length < params) {
310
- return message || `Minimum ${params} items required`;
311
- }
312
- break;
313
-
314
- case 'max_items':
315
- if (Array.isArray(value) && value.length > params) {
316
- return message || `Maximum ${params} items allowed`;
317
- }
318
- break;
319
-
320
- case 'unique_items':
321
- if (Array.isArray(value)) {
322
- const unique = new Set(value);
323
- if (unique.size !== value.length) {
324
- return message || 'All items must be unique';
325
- }
326
- }
327
- break;
328
-
329
- case 'field_match':
330
- if (context?.values && params) {
331
- const otherValue = context.values[params];
332
- if (value !== otherValue) {
333
- return message || `Value must match ${params}`;
334
- }
335
- }
336
- break;
337
-
338
- case 'field_compare':
339
- if (context?.values && params) {
340
- const { field: otherField, operator } = params;
341
- const otherValue = context.values[otherField];
342
-
343
- switch (operator) {
344
- case '>':
345
- if (value <= otherValue) {
346
- return message || `Value must be greater than ${otherField}`;
347
- }
348
- break;
349
- case '<':
350
- if (value >= otherValue) {
351
- return message || `Value must be less than ${otherField}`;
352
- }
353
- break;
354
- case '>=':
355
- if (value < otherValue) {
356
- return message || `Value must be greater than or equal to ${otherField}`;
357
- }
358
- break;
359
- case '<=':
360
- if (value > otherValue) {
361
- return message || `Value must be less than or equal to ${otherField}`;
362
- }
363
- break;
364
- }
365
- }
366
- break;
367
-
368
- case 'conditional':
369
- if (context?.values && params) {
370
- const { condition, rules } = params;
371
-
372
- if (!Array.isArray(rules) || rules.length === 0) {
373
- break;
374
- }
375
-
376
- const conditionMet = this.evaluateCondition(condition, context.values);
377
-
378
- if (conditionMet) {
379
- for (const conditionalRule of rules) {
380
- const result = await this.validateRule(value, conditionalRule, context);
381
- if (result) {
382
- return result;
383
- }
384
- }
385
- }
386
- }
387
- break;
388
-
389
- default:
390
- // Unhandled validation rule type
391
- console.warn(`Unsupported validation rule type: ${type}`);
392
- return null;
393
- }
394
-
395
- return null;
396
- }
397
-
398
- /**
399
- * Evaluate a condition
400
- * Note: Conditions must be declarative objects, not functions, for security.
401
- */
402
- private evaluateCondition(condition: any, values: Record<string, any>): boolean {
403
- if (typeof condition === 'function') {
404
- console.warn(
405
- 'Function-based conditions are deprecated and will be removed. Use declarative conditions instead.\n\n' +
406
- ' Migration:\n' +
407
- ' // Before (deprecated):\n' +
408
- ' { condition: (values) => values.age > 18 }\n\n' +
409
- ' // After:\n' +
410
- ' { condition: { field: "age", operator: ">", value: 18 } }\n\n' +
411
- ' See: https://github.com/objectstack-ai/objectui/blob/main/MIGRATION_GUIDE.md'
412
- );
413
- return false; // Security: reject function-based conditions
414
- }
415
-
416
- if (typeof condition === 'object' && condition.field) {
417
- const fieldValue = values[condition.field];
418
- const { operator = '=', value } = condition;
419
-
420
- switch (operator) {
421
- case '=':
422
- return fieldValue === value;
423
- case '!=':
424
- return fieldValue !== value;
425
- case '>':
426
- return fieldValue > value;
427
- case '<':
428
- return fieldValue < value;
429
- case '>=':
430
- return fieldValue >= value;
431
- case '<=':
432
- return fieldValue <= value;
433
- case 'in':
434
- return Array.isArray(value) && value.includes(fieldValue);
435
- default:
436
- return false;
437
- }
438
- }
439
-
440
- return false;
441
- }
442
-
443
- /**
444
- * Validate multiple fields
445
- */
446
- async validateFields(
447
- values: Record<string, any>,
448
- schemas: Record<string, AdvancedValidationSchema>
449
- ): Promise<Record<string, AdvancedValidationResult>> {
450
- const results: Record<string, AdvancedValidationResult> = {};
451
-
452
- const context: ValidationContext = {
453
- values,
454
- };
455
-
456
- for (const [field, schema] of Object.entries(schemas)) {
457
- const value = values[field];
458
- const schemaWithField: AdvancedValidationSchema = {
459
- ...schema,
460
- field: schema.field ?? field,
461
- };
462
- results[field] = await this.validate(value, schemaWithField, context);
463
- }
464
-
465
- return results;
466
- }
467
-
468
- /**
469
- * Check if all fields are valid
470
- */
471
- isValid(results: Record<string, AdvancedValidationResult>): boolean {
472
- return Object.values(results).every(result => result.valid);
473
- }
474
-
475
- /**
476
- * Get all errors from validation results
477
- */
478
- getAllErrors(results: Record<string, AdvancedValidationResult>): AdvancedValidationError[] {
479
- const errors: AdvancedValidationError[] = [];
480
-
481
- for (const result of Object.values(results)) {
482
- errors.push(...result.errors);
483
- }
484
-
485
- return errors;
486
- }
487
-
488
- /**
489
- * Get all warnings from validation results
490
- */
491
- getAllWarnings(results: Record<string, AdvancedValidationResult>): AdvancedValidationError[] {
492
- const warnings: AdvancedValidationError[] = [];
493
-
494
- for (const result of Object.values(results)) {
495
- if (result.warnings) {
496
- warnings.push(...result.warnings);
497
- }
498
- }
499
-
500
- return warnings;
501
- }
502
- }
503
-
504
- /**
505
- * Default validation engine instance
506
- */
507
- export const defaultValidationEngine = new ValidationEngine();
508
-
509
- /**
510
- * Convenience function to validate a value
511
- */
512
- export async function validate(
513
- value: any,
514
- schema: AdvancedValidationSchema,
515
- context?: ValidationContext
516
- ): Promise<AdvancedValidationResult> {
517
- return defaultValidationEngine.validate(value, schema, context);
518
- }
519
-
520
- /**
521
- * Convenience function to validate multiple fields
522
- */
523
- export async function validateFields(
524
- values: Record<string, any>,
525
- schemas: Record<string, AdvancedValidationSchema>
526
- ): Promise<Record<string, AdvancedValidationResult>> {
527
- return defaultValidationEngine.validateFields(values, schemas);
528
- }
@@ -1,25 +0,0 @@
1
- /**
2
- * ObjectUI
3
- * Copyright (c) 2024-present ObjectStack Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
-
9
- /**
10
- * @object-ui/core - Validators
11
- *
12
- * ObjectStack Spec v2.0.1 compliant validators
13
- *
14
- * @module validators
15
- * @packageDocumentation
16
- */
17
-
18
- export {
19
- ObjectValidationEngine,
20
- defaultObjectValidationEngine,
21
- validateRecord,
22
- type ObjectValidationContext,
23
- type ObjectValidationResult,
24
- type ValidationExpressionEvaluator,
25
- } from './object-validation-engine.js';