@object-ui/core 0.5.0 → 3.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 (96) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +28 -0
  3. package/dist/__benchmarks__/core.bench.d.ts +8 -0
  4. package/dist/__benchmarks__/core.bench.js +53 -0
  5. package/dist/actions/ActionRunner.d.ts +228 -4
  6. package/dist/actions/ActionRunner.js +397 -45
  7. package/dist/actions/TransactionManager.d.ts +193 -0
  8. package/dist/actions/TransactionManager.js +410 -0
  9. package/dist/actions/index.d.ts +1 -0
  10. package/dist/actions/index.js +1 -0
  11. package/dist/adapters/ApiDataSource.d.ts +69 -0
  12. package/dist/adapters/ApiDataSource.js +293 -0
  13. package/dist/adapters/ValueDataSource.d.ts +55 -0
  14. package/dist/adapters/ValueDataSource.js +287 -0
  15. package/dist/adapters/index.d.ts +3 -0
  16. package/dist/adapters/index.js +5 -2
  17. package/dist/adapters/resolveDataSource.d.ts +40 -0
  18. package/dist/adapters/resolveDataSource.js +59 -0
  19. package/dist/data-scope/DataScopeManager.d.ts +127 -0
  20. package/dist/data-scope/DataScopeManager.js +229 -0
  21. package/dist/data-scope/index.d.ts +10 -0
  22. package/dist/data-scope/index.js +10 -0
  23. package/dist/errors/index.d.ts +75 -0
  24. package/dist/errors/index.js +224 -0
  25. package/dist/evaluator/ExpressionEvaluator.d.ts +11 -1
  26. package/dist/evaluator/ExpressionEvaluator.js +32 -8
  27. package/dist/evaluator/FormulaFunctions.d.ts +58 -0
  28. package/dist/evaluator/FormulaFunctions.js +350 -0
  29. package/dist/evaluator/index.d.ts +1 -0
  30. package/dist/evaluator/index.js +1 -0
  31. package/dist/index.d.ts +6 -0
  32. package/dist/index.js +6 -2
  33. package/dist/query/query-ast.d.ts +2 -2
  34. package/dist/query/query-ast.js +3 -3
  35. package/dist/registry/Registry.d.ts +10 -0
  36. package/dist/registry/Registry.js +9 -2
  37. package/dist/registry/WidgetRegistry.d.ts +120 -0
  38. package/dist/registry/WidgetRegistry.js +275 -0
  39. package/dist/theme/ThemeEngine.d.ts +105 -0
  40. package/dist/theme/ThemeEngine.js +469 -0
  41. package/dist/theme/index.d.ts +8 -0
  42. package/dist/theme/index.js +8 -0
  43. package/dist/utils/debug.d.ts +31 -0
  44. package/dist/utils/debug.js +62 -0
  45. package/dist/validation/index.d.ts +1 -1
  46. package/dist/validation/index.js +1 -1
  47. package/dist/validation/validation-engine.d.ts +19 -1
  48. package/dist/validation/validation-engine.js +74 -3
  49. package/dist/validation/validators/index.d.ts +1 -1
  50. package/dist/validation/validators/index.js +1 -1
  51. package/dist/validation/validators/object-validation-engine.d.ts +2 -2
  52. package/dist/validation/validators/object-validation-engine.js +1 -1
  53. package/package.json +4 -3
  54. package/src/__benchmarks__/core.bench.ts +64 -0
  55. package/src/actions/ActionRunner.ts +577 -55
  56. package/src/actions/TransactionManager.ts +521 -0
  57. package/src/actions/__tests__/ActionRunner.params.test.ts +134 -0
  58. package/src/actions/__tests__/ActionRunner.test.ts +711 -0
  59. package/src/actions/__tests__/TransactionManager.test.ts +447 -0
  60. package/src/actions/index.ts +1 -0
  61. package/src/adapters/ApiDataSource.ts +349 -0
  62. package/src/adapters/ValueDataSource.ts +332 -0
  63. package/src/adapters/__tests__/ApiDataSource.test.ts +418 -0
  64. package/src/adapters/__tests__/ValueDataSource.test.ts +325 -0
  65. package/src/adapters/__tests__/resolveDataSource.test.ts +144 -0
  66. package/src/adapters/index.ts +6 -1
  67. package/src/adapters/resolveDataSource.ts +79 -0
  68. package/src/builder/__tests__/schema-builder.test.ts +235 -0
  69. package/src/data-scope/DataScopeManager.ts +269 -0
  70. package/src/data-scope/__tests__/DataScopeManager.test.ts +211 -0
  71. package/src/data-scope/index.ts +16 -0
  72. package/src/errors/__tests__/errors.test.ts +292 -0
  73. package/src/errors/index.ts +270 -0
  74. package/src/evaluator/ExpressionEvaluator.ts +34 -8
  75. package/src/evaluator/FormulaFunctions.ts +398 -0
  76. package/src/evaluator/__tests__/ExpressionContext.test.ts +110 -0
  77. package/src/evaluator/__tests__/FormulaFunctions.test.ts +447 -0
  78. package/src/evaluator/index.ts +1 -0
  79. package/src/index.ts +6 -3
  80. package/src/query/__tests__/window-functions.test.ts +1 -1
  81. package/src/query/query-ast.ts +3 -3
  82. package/src/registry/Registry.ts +19 -2
  83. package/src/registry/WidgetRegistry.ts +316 -0
  84. package/src/registry/__tests__/WidgetRegistry.test.ts +321 -0
  85. package/src/theme/ThemeEngine.ts +530 -0
  86. package/src/theme/__tests__/ThemeEngine.test.ts +668 -0
  87. package/src/theme/index.ts +24 -0
  88. package/src/utils/__tests__/debug.test.ts +83 -0
  89. package/src/utils/debug.ts +66 -0
  90. package/src/validation/__tests__/object-validation-engine.test.ts +1 -1
  91. package/src/validation/__tests__/schema-validator.test.ts +118 -0
  92. package/src/validation/index.ts +1 -1
  93. package/src/validation/validation-engine.ts +70 -3
  94. package/src/validation/validators/index.ts +1 -1
  95. package/src/validation/validators/object-validation-engine.ts +2 -2
  96. package/tsconfig.tsbuildinfo +1 -1
@@ -9,6 +9,47 @@
9
9
  * Validation Engine - Executes validation rules
10
10
  */
11
11
  export class ValidationEngine {
12
+ constructor() {
13
+ Object.defineProperty(this, "customValidators", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: new Map()
18
+ });
19
+ Object.defineProperty(this, "customAsyncValidators", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: new Map()
24
+ });
25
+ }
26
+ /**
27
+ * Register a custom synchronous validator by name
28
+ */
29
+ registerValidator(name, fn) {
30
+ this.customValidators.set(name, fn);
31
+ }
32
+ /**
33
+ * Register a custom asynchronous validator by name
34
+ */
35
+ registerAsyncValidator(name, fn) {
36
+ this.customAsyncValidators.set(name, fn);
37
+ }
38
+ /**
39
+ * Check if a custom validator is registered
40
+ */
41
+ hasValidator(name) {
42
+ return this.customValidators.has(name) || this.customAsyncValidators.has(name);
43
+ }
44
+ /**
45
+ * Get all registered custom validator names
46
+ */
47
+ getValidatorNames() {
48
+ return [
49
+ ...Array.from(this.customValidators.keys()),
50
+ ...Array.from(this.customAsyncValidators.keys()),
51
+ ];
52
+ }
12
53
  /**
13
54
  * Validate a value against validation schema
14
55
  */
@@ -43,7 +84,7 @@ export class ValidationEngine {
43
84
  * Validate a single rule
44
85
  */
45
86
  async validateRule(value, rule, context) {
46
- // Custom async validator
87
+ // Custom async validator (inline)
47
88
  if (rule.async_validator) {
48
89
  const result = await rule.async_validator(value, context);
49
90
  if (result === false) {
@@ -54,7 +95,7 @@ export class ValidationEngine {
54
95
  }
55
96
  return null;
56
97
  }
57
- // Custom sync validator
98
+ // Custom sync validator (inline)
58
99
  if (rule.validator) {
59
100
  const result = rule.validator(value, context);
60
101
  if (result === false) {
@@ -65,6 +106,30 @@ export class ValidationEngine {
65
106
  }
66
107
  return null;
67
108
  }
109
+ // Registered custom async validator (by name)
110
+ const registeredAsync = this.customAsyncValidators.get(rule.type);
111
+ if (registeredAsync) {
112
+ const result = await registeredAsync(value, context);
113
+ if (result === false) {
114
+ return rule.message || 'Async validation failed';
115
+ }
116
+ if (typeof result === 'string') {
117
+ return result;
118
+ }
119
+ return null;
120
+ }
121
+ // Registered custom sync validator (by name)
122
+ const registeredSync = this.customValidators.get(rule.type);
123
+ if (registeredSync) {
124
+ const result = registeredSync(value, context);
125
+ if (result === false) {
126
+ return rule.message || 'Validation failed';
127
+ }
128
+ if (typeof result === 'string') {
129
+ return result;
130
+ }
131
+ return null;
132
+ }
68
133
  // Built-in validators
69
134
  return this.validateBuiltInRule(value, rule, context);
70
135
  }
@@ -271,7 +336,13 @@ export class ValidationEngine {
271
336
  */
272
337
  evaluateCondition(condition, values) {
273
338
  if (typeof condition === 'function') {
274
- console.warn('Function-based conditions are deprecated and will be removed. Use declarative conditions instead.');
339
+ console.warn('Function-based conditions are deprecated and will be removed. Use declarative conditions instead.\n\n' +
340
+ ' Migration:\n' +
341
+ ' // Before (deprecated):\n' +
342
+ ' { condition: (values) => values.age > 18 }\n\n' +
343
+ ' // After:\n' +
344
+ ' { condition: { field: "age", operator: ">", value: 18 } }\n\n' +
345
+ ' See: https://github.com/objectstack-ai/objectui/blob/main/MIGRATION_GUIDE.md');
275
346
  return false; // Security: reject function-based conditions
276
347
  }
277
348
  if (typeof condition === 'object' && condition.field) {
@@ -8,7 +8,7 @@
8
8
  /**
9
9
  * @object-ui/core - Validators
10
10
  *
11
- * ObjectStack Spec v0.7.1 compliant validators
11
+ * ObjectStack Spec v2.0.1 compliant validators
12
12
  *
13
13
  * @module validators
14
14
  * @packageDocumentation
@@ -8,7 +8,7 @@
8
8
  /**
9
9
  * @object-ui/core - Validators
10
10
  *
11
- * ObjectStack Spec v0.7.1 compliant validators
11
+ * ObjectStack Spec v2.0.1 compliant validators
12
12
  *
13
13
  * @module validators
14
14
  * @packageDocumentation
@@ -8,7 +8,7 @@
8
8
  /**
9
9
  * @object-ui/core - Object-Level Validation Engine
10
10
  *
11
- * ObjectStack Spec v0.7.1 compliant validation engine for object-level validation rules.
11
+ * ObjectStack Spec v2.0.1 compliant validation engine for object-level validation rules.
12
12
  * Supports all 9 validation types from the specification:
13
13
  * - ScriptValidation
14
14
  * - UniquenessValidation
@@ -57,7 +57,7 @@ export interface ValidationExpressionEvaluator {
57
57
  }
58
58
  /**
59
59
  * Object-Level Validation Engine
60
- * Implements ObjectStack Spec v0.7.1 validation framework
60
+ * Implements ObjectStack Spec v2.0.1 validation framework
61
61
  */
62
62
  export declare class ObjectValidationEngine {
63
63
  private expressionEvaluator;
@@ -170,7 +170,7 @@ class SimpleExpressionEvaluator {
170
170
  }
171
171
  /**
172
172
  * Object-Level Validation Engine
173
- * Implements ObjectStack Spec v0.7.1 validation framework
173
+ * Implements ObjectStack Spec v2.0.1 validation framework
174
174
  */
175
175
  export class ObjectValidationEngine {
176
176
  constructor(expressionEvaluator, uniquenessChecker) {
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@object-ui/core",
3
- "version": "0.5.0",
3
+ "version": "3.0.0",
4
4
  "type": "module",
5
+ "sideEffects": false,
5
6
  "license": "MIT",
6
7
  "description": "Core logic, types, and validation for Object UI. Zero React dependencies.",
7
8
  "homepage": "https://www.objectui.org",
@@ -23,10 +24,10 @@
23
24
  }
24
25
  },
25
26
  "dependencies": {
26
- "@objectstack/spec": "^0.9.1",
27
+ "@objectstack/spec": "^3.0.2",
27
28
  "lodash": "^4.17.23",
28
29
  "zod": "^4.3.6",
29
- "@object-ui/types": "0.5.0"
30
+ "@object-ui/types": "3.0.0"
30
31
  },
31
32
  "devDependencies": {
32
33
  "typescript": "^5.9.3",
@@ -0,0 +1,64 @@
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
+ * Performance benchmark suite for @object-ui/core.
11
+ *
12
+ * Part of Q1 2026 roadmap §1.4 Test Coverage Improvement.
13
+ *
14
+ * Run with: npx vitest bench packages/core/src/__benchmarks__/
15
+ */
16
+
17
+ import { bench, describe } from 'vitest';
18
+ import { ExpressionEvaluator } from '@object-ui/core';
19
+ import { ComponentRegistry } from '@object-ui/core';
20
+ import { contrastRatio, meetsContrastLevel, hexToHSL } from '@object-ui/core';
21
+
22
+ describe('ExpressionEvaluator performance', () => {
23
+ const evaluator = new ExpressionEvaluator({ data: { name: 'Alice', age: 30, active: true } });
24
+
25
+ bench('evaluate simple string', () => {
26
+ evaluator.evaluate('Hello ${data.name}');
27
+ });
28
+
29
+ bench('evaluate 100 expressions', () => {
30
+ for (let i = 0; i < 100; i++) {
31
+ evaluator.evaluate('Hello ${data.name}');
32
+ }
33
+ });
34
+ });
35
+
36
+ describe('ComponentRegistry performance', () => {
37
+ bench('get registered component', () => {
38
+ ComponentRegistry.get('button');
39
+ });
40
+
41
+ bench('has check', () => {
42
+ ComponentRegistry.has('button');
43
+ });
44
+ });
45
+
46
+ describe('Theme utilities performance', () => {
47
+ bench('hexToHSL conversion', () => {
48
+ hexToHSL('#336699');
49
+ });
50
+
51
+ bench('contrastRatio calculation', () => {
52
+ contrastRatio('#000000', '#ffffff');
53
+ });
54
+
55
+ bench('meetsContrastLevel check', () => {
56
+ meetsContrastLevel('#000000', '#ffffff', 'AA');
57
+ });
58
+
59
+ bench('100 contrast checks', () => {
60
+ for (let i = 0; i < 100; i++) {
61
+ meetsContrastLevel('#336699', '#ffffff', 'AA');
62
+ }
63
+ });
64
+ });