@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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +28 -0
- package/dist/__benchmarks__/core.bench.d.ts +8 -0
- package/dist/__benchmarks__/core.bench.js +53 -0
- package/dist/actions/ActionRunner.d.ts +228 -4
- package/dist/actions/ActionRunner.js +397 -45
- package/dist/actions/TransactionManager.d.ts +193 -0
- package/dist/actions/TransactionManager.js +410 -0
- package/dist/actions/index.d.ts +1 -0
- package/dist/actions/index.js +1 -0
- package/dist/adapters/ApiDataSource.d.ts +69 -0
- package/dist/adapters/ApiDataSource.js +293 -0
- package/dist/adapters/ValueDataSource.d.ts +55 -0
- package/dist/adapters/ValueDataSource.js +287 -0
- package/dist/adapters/index.d.ts +3 -0
- package/dist/adapters/index.js +5 -2
- package/dist/adapters/resolveDataSource.d.ts +40 -0
- package/dist/adapters/resolveDataSource.js +59 -0
- package/dist/data-scope/DataScopeManager.d.ts +127 -0
- package/dist/data-scope/DataScopeManager.js +229 -0
- package/dist/data-scope/index.d.ts +10 -0
- package/dist/data-scope/index.js +10 -0
- package/dist/errors/index.d.ts +75 -0
- package/dist/errors/index.js +224 -0
- package/dist/evaluator/ExpressionEvaluator.d.ts +11 -1
- package/dist/evaluator/ExpressionEvaluator.js +32 -8
- package/dist/evaluator/FormulaFunctions.d.ts +58 -0
- package/dist/evaluator/FormulaFunctions.js +350 -0
- package/dist/evaluator/index.d.ts +1 -0
- package/dist/evaluator/index.js +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -2
- package/dist/query/query-ast.d.ts +2 -2
- package/dist/query/query-ast.js +3 -3
- package/dist/registry/Registry.d.ts +10 -0
- package/dist/registry/Registry.js +9 -2
- package/dist/registry/WidgetRegistry.d.ts +120 -0
- package/dist/registry/WidgetRegistry.js +275 -0
- package/dist/theme/ThemeEngine.d.ts +105 -0
- package/dist/theme/ThemeEngine.js +469 -0
- package/dist/theme/index.d.ts +8 -0
- package/dist/theme/index.js +8 -0
- package/dist/utils/debug.d.ts +31 -0
- package/dist/utils/debug.js +62 -0
- package/dist/validation/index.d.ts +1 -1
- package/dist/validation/index.js +1 -1
- package/dist/validation/validation-engine.d.ts +19 -1
- package/dist/validation/validation-engine.js +74 -3
- package/dist/validation/validators/index.d.ts +1 -1
- package/dist/validation/validators/index.js +1 -1
- package/dist/validation/validators/object-validation-engine.d.ts +2 -2
- package/dist/validation/validators/object-validation-engine.js +1 -1
- package/package.json +4 -3
- package/src/__benchmarks__/core.bench.ts +64 -0
- package/src/actions/ActionRunner.ts +577 -55
- package/src/actions/TransactionManager.ts +521 -0
- package/src/actions/__tests__/ActionRunner.params.test.ts +134 -0
- package/src/actions/__tests__/ActionRunner.test.ts +711 -0
- package/src/actions/__tests__/TransactionManager.test.ts +447 -0
- package/src/actions/index.ts +1 -0
- package/src/adapters/ApiDataSource.ts +349 -0
- package/src/adapters/ValueDataSource.ts +332 -0
- package/src/adapters/__tests__/ApiDataSource.test.ts +418 -0
- package/src/adapters/__tests__/ValueDataSource.test.ts +325 -0
- package/src/adapters/__tests__/resolveDataSource.test.ts +144 -0
- package/src/adapters/index.ts +6 -1
- package/src/adapters/resolveDataSource.ts +79 -0
- package/src/builder/__tests__/schema-builder.test.ts +235 -0
- package/src/data-scope/DataScopeManager.ts +269 -0
- package/src/data-scope/__tests__/DataScopeManager.test.ts +211 -0
- package/src/data-scope/index.ts +16 -0
- package/src/errors/__tests__/errors.test.ts +292 -0
- package/src/errors/index.ts +270 -0
- package/src/evaluator/ExpressionEvaluator.ts +34 -8
- package/src/evaluator/FormulaFunctions.ts +398 -0
- package/src/evaluator/__tests__/ExpressionContext.test.ts +110 -0
- package/src/evaluator/__tests__/FormulaFunctions.test.ts +447 -0
- package/src/evaluator/index.ts +1 -0
- package/src/index.ts +6 -3
- package/src/query/__tests__/window-functions.test.ts +1 -1
- package/src/query/query-ast.ts +3 -3
- package/src/registry/Registry.ts +19 -2
- package/src/registry/WidgetRegistry.ts +316 -0
- package/src/registry/__tests__/WidgetRegistry.test.ts +321 -0
- package/src/theme/ThemeEngine.ts +530 -0
- package/src/theme/__tests__/ThemeEngine.test.ts +668 -0
- package/src/theme/index.ts +24 -0
- package/src/utils/__tests__/debug.test.ts +83 -0
- package/src/utils/debug.ts +66 -0
- package/src/validation/__tests__/object-validation-engine.test.ts +1 -1
- package/src/validation/__tests__/schema-validator.test.ts +118 -0
- package/src/validation/index.ts +1 -1
- package/src/validation/validation-engine.ts +70 -3
- package/src/validation/validators/index.ts +1 -1
- package/src/validation/validators/object-validation-engine.ts +2 -2
- 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 - Object-Level Validation Engine
|
|
10
10
|
*
|
|
11
|
-
* ObjectStack Spec
|
|
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
|
|
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
|
|
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.
|
|
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.
|
|
27
|
+
"@objectstack/spec": "^3.0.2",
|
|
27
28
|
"lodash": "^4.17.23",
|
|
28
29
|
"zod": "^4.3.6",
|
|
29
|
-
"@object-ui/types": "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
|
+
});
|