@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
@@ -0,0 +1,59 @@
1
+ /**
2
+ * ObjectUI — resolveDataSource
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
+ * Factory function to create the right DataSource from a ViewData config.
9
+ */
10
+ import { ApiDataSource } from './ApiDataSource.js';
11
+ import { ValueDataSource } from './ValueDataSource.js';
12
+ /**
13
+ * Resolve a ViewData configuration into a concrete DataSource instance.
14
+ *
15
+ * - `provider: 'object'` → returns `fallback` (the context DataSource — typically ObjectStackAdapter)
16
+ * - `provider: 'api'` → returns a new `ApiDataSource`
17
+ * - `provider: 'value'` → returns a new `ValueDataSource`
18
+ *
19
+ * @param viewData - The ViewData configuration from the schema
20
+ * @param fallback - The default DataSource from context (for `provider: 'object'`)
21
+ * @param options - Additional options for adapter construction
22
+ * @returns A DataSource instance, or null if neither viewData nor fallback is available
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * const ds = resolveDataSource(
27
+ * { provider: 'api', read: { url: '/api/users' } },
28
+ * contextDataSource,
29
+ * );
30
+ * const result = await ds.find('users');
31
+ * ```
32
+ */
33
+ export function resolveDataSource(viewData, fallback, options) {
34
+ if (!viewData) {
35
+ return fallback ?? null;
36
+ }
37
+ switch (viewData.provider) {
38
+ case 'object':
39
+ // Delegate to the context DataSource (ObjectStackAdapter, etc.)
40
+ return fallback ?? null;
41
+ case 'api': {
42
+ const config = {
43
+ read: viewData.read,
44
+ write: viewData.write,
45
+ fetch: options?.fetch,
46
+ defaultHeaders: options?.defaultHeaders,
47
+ };
48
+ return new ApiDataSource(config);
49
+ }
50
+ case 'value':
51
+ return new ValueDataSource({
52
+ items: (viewData.items ?? []),
53
+ idField: options?.idField,
54
+ });
55
+ default:
56
+ // Unknown provider — fall back to context
57
+ return fallback ?? null;
58
+ }
59
+ }
@@ -0,0 +1,127 @@
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
+ * @object-ui/core - DataScope Manager
10
+ *
11
+ * Runtime implementation of the DataContext interface for managing
12
+ * named data scopes. Provides row-level data access control and
13
+ * reactive data state management within the UI component tree.
14
+ *
15
+ * @module data-scope
16
+ * @packageDocumentation
17
+ */
18
+ import type { DataScope, DataContext, DataSource } from '@object-ui/types';
19
+ /**
20
+ * Row-level filter for restricting data access within a scope
21
+ */
22
+ export interface RowLevelFilter {
23
+ /** Field to filter on */
24
+ field: string;
25
+ /** Filter operator */
26
+ operator: 'eq' | 'ne' | 'gt' | 'lt' | 'gte' | 'lte' | 'in' | 'nin' | 'contains';
27
+ /** Filter value */
28
+ value: any;
29
+ }
30
+ /**
31
+ * Configuration for creating a data scope
32
+ */
33
+ export interface DataScopeConfig {
34
+ /** Data source instance */
35
+ dataSource?: DataSource;
36
+ /** Initial data */
37
+ data?: any;
38
+ /** Row-level filters to apply */
39
+ filters?: RowLevelFilter[];
40
+ /** Whether this scope is read-only */
41
+ readOnly?: boolean;
42
+ }
43
+ /**
44
+ * DataScopeManager — Runtime implementation of DataContext.
45
+ *
46
+ * Manages named data scopes for the component tree, providing:
47
+ * - Scope registration and lookup
48
+ * - Row-level security via filters
49
+ * - Data state management (data, loading, error)
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * const manager = new DataScopeManager();
54
+ * manager.registerScope('contacts', {
55
+ * dataSource: myDataSource,
56
+ * data: [],
57
+ * });
58
+ * const scope = manager.getScope('contacts');
59
+ * ```
60
+ */
61
+ export declare class DataScopeManager implements DataContext {
62
+ scopes: Record<string, DataScope>;
63
+ private filters;
64
+ private readOnlyScopes;
65
+ private listeners;
66
+ /**
67
+ * Register a data scope
68
+ */
69
+ registerScope(name: string, scope: DataScope): void;
70
+ /**
71
+ * Register a data scope with configuration
72
+ */
73
+ registerScopeWithConfig(name: string, config: DataScopeConfig): void;
74
+ /**
75
+ * Get a data scope by name
76
+ */
77
+ getScope(name: string): DataScope | undefined;
78
+ /**
79
+ * Remove a data scope
80
+ */
81
+ removeScope(name: string): void;
82
+ /**
83
+ * Check if a scope is read-only
84
+ */
85
+ isReadOnly(name: string): boolean;
86
+ /**
87
+ * Get row-level filters for a scope
88
+ */
89
+ getFilters(name: string): RowLevelFilter[];
90
+ /**
91
+ * Set row-level filters for a scope
92
+ */
93
+ setFilters(name: string, filters: RowLevelFilter[]): void;
94
+ /**
95
+ * Apply row-level filters to a dataset
96
+ */
97
+ applyFilters(name: string, data: any[]): any[];
98
+ /**
99
+ * Update data in a scope
100
+ */
101
+ updateScopeData(name: string, data: any): void;
102
+ /**
103
+ * Update loading state for a scope
104
+ */
105
+ updateScopeLoading(name: string, loading: boolean): void;
106
+ /**
107
+ * Update error state for a scope
108
+ */
109
+ updateScopeError(name: string, error: Error | string | null): void;
110
+ /**
111
+ * Subscribe to scope changes
112
+ */
113
+ onScopeChange(name: string, listener: (scope: DataScope) => void): () => void;
114
+ /**
115
+ * Get all registered scope names
116
+ */
117
+ getScopeNames(): string[];
118
+ /**
119
+ * Clear all scopes
120
+ */
121
+ clear(): void;
122
+ private notifyListeners;
123
+ }
124
+ /**
125
+ * Default DataScopeManager instance
126
+ */
127
+ export declare const defaultDataScopeManager: DataScopeManager;
@@ -0,0 +1,229 @@
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
+ * DataScopeManager — Runtime implementation of DataContext.
10
+ *
11
+ * Manages named data scopes for the component tree, providing:
12
+ * - Scope registration and lookup
13
+ * - Row-level security via filters
14
+ * - Data state management (data, loading, error)
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * const manager = new DataScopeManager();
19
+ * manager.registerScope('contacts', {
20
+ * dataSource: myDataSource,
21
+ * data: [],
22
+ * });
23
+ * const scope = manager.getScope('contacts');
24
+ * ```
25
+ */
26
+ export class DataScopeManager {
27
+ constructor() {
28
+ Object.defineProperty(this, "scopes", {
29
+ enumerable: true,
30
+ configurable: true,
31
+ writable: true,
32
+ value: {}
33
+ });
34
+ Object.defineProperty(this, "filters", {
35
+ enumerable: true,
36
+ configurable: true,
37
+ writable: true,
38
+ value: {}
39
+ });
40
+ Object.defineProperty(this, "readOnlyScopes", {
41
+ enumerable: true,
42
+ configurable: true,
43
+ writable: true,
44
+ value: new Set()
45
+ });
46
+ Object.defineProperty(this, "listeners", {
47
+ enumerable: true,
48
+ configurable: true,
49
+ writable: true,
50
+ value: new Map()
51
+ });
52
+ }
53
+ /**
54
+ * Register a data scope
55
+ */
56
+ registerScope(name, scope) {
57
+ this.scopes[name] = scope;
58
+ this.notifyListeners(name, scope);
59
+ }
60
+ /**
61
+ * Register a data scope with configuration
62
+ */
63
+ registerScopeWithConfig(name, config) {
64
+ const scope = {
65
+ dataSource: config.dataSource,
66
+ data: config.data,
67
+ loading: false,
68
+ error: null,
69
+ };
70
+ if (config.filters) {
71
+ this.filters[name] = config.filters;
72
+ }
73
+ if (config.readOnly) {
74
+ this.readOnlyScopes.add(name);
75
+ }
76
+ this.scopes[name] = scope;
77
+ this.notifyListeners(name, scope);
78
+ }
79
+ /**
80
+ * Get a data scope by name
81
+ */
82
+ getScope(name) {
83
+ return this.scopes[name];
84
+ }
85
+ /**
86
+ * Remove a data scope
87
+ */
88
+ removeScope(name) {
89
+ delete this.scopes[name];
90
+ delete this.filters[name];
91
+ this.readOnlyScopes.delete(name);
92
+ this.listeners.delete(name);
93
+ }
94
+ /**
95
+ * Check if a scope is read-only
96
+ */
97
+ isReadOnly(name) {
98
+ return this.readOnlyScopes.has(name);
99
+ }
100
+ /**
101
+ * Get row-level filters for a scope
102
+ */
103
+ getFilters(name) {
104
+ return this.filters[name] || [];
105
+ }
106
+ /**
107
+ * Set row-level filters for a scope
108
+ */
109
+ setFilters(name, filters) {
110
+ this.filters[name] = filters;
111
+ }
112
+ /**
113
+ * Apply row-level filters to a dataset
114
+ */
115
+ applyFilters(name, data) {
116
+ const scopeFilters = this.filters[name];
117
+ if (!scopeFilters || scopeFilters.length === 0) {
118
+ return data;
119
+ }
120
+ return data.filter(row => {
121
+ return scopeFilters.every(filter => {
122
+ const fieldValue = row[filter.field];
123
+ return evaluateFilter(fieldValue, filter.operator, filter.value);
124
+ });
125
+ });
126
+ }
127
+ /**
128
+ * Update data in a scope
129
+ */
130
+ updateScopeData(name, data) {
131
+ const scope = this.scopes[name];
132
+ if (!scope)
133
+ return;
134
+ if (this.readOnlyScopes.has(name)) {
135
+ throw new Error(`Cannot update read-only scope: ${name}`);
136
+ }
137
+ scope.data = data;
138
+ this.notifyListeners(name, scope);
139
+ }
140
+ /**
141
+ * Update loading state for a scope
142
+ */
143
+ updateScopeLoading(name, loading) {
144
+ const scope = this.scopes[name];
145
+ if (!scope)
146
+ return;
147
+ scope.loading = loading;
148
+ this.notifyListeners(name, scope);
149
+ }
150
+ /**
151
+ * Update error state for a scope
152
+ */
153
+ updateScopeError(name, error) {
154
+ const scope = this.scopes[name];
155
+ if (!scope)
156
+ return;
157
+ scope.error = error;
158
+ this.notifyListeners(name, scope);
159
+ }
160
+ /**
161
+ * Subscribe to scope changes
162
+ */
163
+ onScopeChange(name, listener) {
164
+ if (!this.listeners.has(name)) {
165
+ this.listeners.set(name, []);
166
+ }
167
+ this.listeners.get(name).push(listener);
168
+ return () => {
169
+ const arr = this.listeners.get(name);
170
+ if (arr) {
171
+ const idx = arr.indexOf(listener);
172
+ if (idx >= 0)
173
+ arr.splice(idx, 1);
174
+ }
175
+ };
176
+ }
177
+ /**
178
+ * Get all registered scope names
179
+ */
180
+ getScopeNames() {
181
+ return Object.keys(this.scopes);
182
+ }
183
+ /**
184
+ * Clear all scopes
185
+ */
186
+ clear() {
187
+ this.scopes = {};
188
+ this.filters = {};
189
+ this.readOnlyScopes.clear();
190
+ this.listeners.clear();
191
+ }
192
+ notifyListeners(name, scope) {
193
+ const arr = this.listeners.get(name);
194
+ if (arr) {
195
+ arr.forEach(listener => listener(scope));
196
+ }
197
+ }
198
+ }
199
+ /**
200
+ * Evaluate a single filter condition against a field value
201
+ */
202
+ function evaluateFilter(fieldValue, operator, filterValue) {
203
+ switch (operator) {
204
+ case 'eq':
205
+ return fieldValue === filterValue;
206
+ case 'ne':
207
+ return fieldValue !== filterValue;
208
+ case 'gt':
209
+ return fieldValue > filterValue;
210
+ case 'lt':
211
+ return fieldValue < filterValue;
212
+ case 'gte':
213
+ return fieldValue >= filterValue;
214
+ case 'lte':
215
+ return fieldValue <= filterValue;
216
+ case 'in':
217
+ return Array.isArray(filterValue) && filterValue.includes(fieldValue);
218
+ case 'nin':
219
+ return Array.isArray(filterValue) && !filterValue.includes(fieldValue);
220
+ case 'contains':
221
+ return typeof fieldValue === 'string' && fieldValue.includes(String(filterValue));
222
+ default:
223
+ return true;
224
+ }
225
+ }
226
+ /**
227
+ * Default DataScopeManager instance
228
+ */
229
+ export const defaultDataScopeManager = new DataScopeManager();
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @object-ui/core - DataScope Module
3
+ *
4
+ * Runtime data scope management for row-level security and
5
+ * reactive data state within the UI component tree.
6
+ *
7
+ * @module data-scope
8
+ * @packageDocumentation
9
+ */
10
+ export { DataScopeManager, defaultDataScopeManager, type RowLevelFilter, type DataScopeConfig, } from './DataScopeManager.js';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @object-ui/core - DataScope Module
3
+ *
4
+ * Runtime data scope management for row-level security and
5
+ * reactive data state within the UI component tree.
6
+ *
7
+ * @module data-scope
8
+ * @packageDocumentation
9
+ */
10
+ export { DataScopeManager, defaultDataScopeManager, } from './DataScopeManager.js';
@@ -0,0 +1,75 @@
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
+ export interface ErrorCodeEntry {
9
+ code: string;
10
+ message: string;
11
+ suggestion: string;
12
+ docUrl: string;
13
+ }
14
+ export declare const ERROR_CODES: Record<string, ErrorCodeEntry>;
15
+ /**
16
+ * Check whether a string is a known ObjectUI error code.
17
+ */
18
+ export declare function isErrorCode(code: unknown): code is keyof typeof ERROR_CODES;
19
+ /**
20
+ * Base error class for all ObjectUI errors.
21
+ */
22
+ export declare class ObjectUIError extends Error {
23
+ code: string;
24
+ details?: Record<string, unknown> | undefined;
25
+ constructor(message: string, code: string, details?: Record<string, unknown> | undefined);
26
+ /**
27
+ * Convert error to JSON for logging / debugging.
28
+ */
29
+ toJSON(): {
30
+ name: string;
31
+ message: string;
32
+ code: string;
33
+ details: Record<string, unknown> | undefined;
34
+ stack: string | undefined;
35
+ };
36
+ }
37
+ /**
38
+ * Type guard to check if an error is an ObjectUIError.
39
+ */
40
+ export declare function isObjectUIError(error: unknown): error is ObjectUIError;
41
+ /** Thrown when a schema is invalid or fails validation. */
42
+ export declare class SchemaError extends ObjectUIError {
43
+ constructor(message: string, details?: Record<string, unknown>);
44
+ }
45
+ /** Thrown when a registry operation fails. */
46
+ export declare class RegistryError extends ObjectUIError {
47
+ constructor(message: string, code: string, details?: Record<string, unknown>);
48
+ }
49
+ /** Thrown when expression evaluation fails. */
50
+ export declare class ExpressionError extends ObjectUIError {
51
+ constructor(message: string, details?: Record<string, unknown>);
52
+ }
53
+ /** Thrown when a plugin operation fails. */
54
+ export declare class PluginError extends ObjectUIError {
55
+ constructor(message: string, code: string, details?: Record<string, unknown>);
56
+ }
57
+ /** Thrown when validation of user input / field config fails. */
58
+ export declare class FieldValidationError extends ObjectUIError {
59
+ constructor(message: string, details?: Record<string, unknown>);
60
+ }
61
+ /**
62
+ * Create an `ObjectUIError` (or subclass) from a known error code.
63
+ *
64
+ * @param code - A registered error code (e.g. `"OBJUI-001"`).
65
+ * @param params - Values to interpolate into the message template.
66
+ * @param details - Optional extra details attached to the error.
67
+ */
68
+ export declare function createError(code: string, params?: Record<string, string>, details?: Record<string, unknown>): ObjectUIError;
69
+ /**
70
+ * Format an error message with actionable fix suggestions in development mode.
71
+ *
72
+ * @param error - The `ObjectUIError` to format.
73
+ * @param isDev - When `true`, appends the suggestion and documentation link.
74
+ */
75
+ export declare function formatErrorMessage(error: ObjectUIError, isDev?: boolean): string;