@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,269 +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 - DataScope Manager
11
- *
12
- * Runtime implementation of the DataContext interface for managing
13
- * named data scopes. Provides row-level data access control and
14
- * reactive data state management within the UI component tree.
15
- *
16
- * @module data-scope
17
- * @packageDocumentation
18
- */
19
-
20
- import type { DataScope, DataContext, DataSource } from '@object-ui/types';
21
-
22
- /**
23
- * Row-level filter for restricting data access within a scope
24
- */
25
- export interface RowLevelFilter {
26
- /** Field to filter on */
27
- field: string;
28
- /** Filter operator */
29
- operator: 'eq' | 'ne' | 'gt' | 'lt' | 'gte' | 'lte' | 'in' | 'nin' | 'contains';
30
- /** Filter value */
31
- value: any;
32
- }
33
-
34
- /**
35
- * Configuration for creating a data scope
36
- */
37
- export interface DataScopeConfig {
38
- /** Data source instance */
39
- dataSource?: DataSource;
40
- /** Initial data */
41
- data?: any;
42
- /** Row-level filters to apply */
43
- filters?: RowLevelFilter[];
44
- /** Whether this scope is read-only */
45
- readOnly?: boolean;
46
- }
47
-
48
- /**
49
- * DataScopeManager — Runtime implementation of DataContext.
50
- *
51
- * Manages named data scopes for the component tree, providing:
52
- * - Scope registration and lookup
53
- * - Row-level security via filters
54
- * - Data state management (data, loading, error)
55
- *
56
- * @example
57
- * ```ts
58
- * const manager = new DataScopeManager();
59
- * manager.registerScope('contacts', {
60
- * dataSource: myDataSource,
61
- * data: [],
62
- * });
63
- * const scope = manager.getScope('contacts');
64
- * ```
65
- */
66
- export class DataScopeManager implements DataContext {
67
- scopes: Record<string, DataScope> = {};
68
- private filters: Record<string, RowLevelFilter[]> = {};
69
- private readOnlyScopes: Set<string> = new Set();
70
- private listeners: Map<string, Array<(scope: DataScope) => void>> = new Map();
71
-
72
- /**
73
- * Register a data scope
74
- */
75
- registerScope(name: string, scope: DataScope): void {
76
- this.scopes[name] = scope;
77
- this.notifyListeners(name, scope);
78
- }
79
-
80
- /**
81
- * Register a data scope with configuration
82
- */
83
- registerScopeWithConfig(name: string, config: DataScopeConfig): void {
84
- const scope: DataScope = {
85
- dataSource: config.dataSource,
86
- data: config.data,
87
- loading: false,
88
- error: null,
89
- };
90
-
91
- if (config.filters) {
92
- this.filters[name] = config.filters;
93
- }
94
-
95
- if (config.readOnly) {
96
- this.readOnlyScopes.add(name);
97
- }
98
-
99
- this.scopes[name] = scope;
100
- this.notifyListeners(name, scope);
101
- }
102
-
103
- /**
104
- * Get a data scope by name
105
- */
106
- getScope(name: string): DataScope | undefined {
107
- return this.scopes[name];
108
- }
109
-
110
- /**
111
- * Remove a data scope
112
- */
113
- removeScope(name: string): void {
114
- delete this.scopes[name];
115
- delete this.filters[name];
116
- this.readOnlyScopes.delete(name);
117
- this.listeners.delete(name);
118
- }
119
-
120
- /**
121
- * Check if a scope is read-only
122
- */
123
- isReadOnly(name: string): boolean {
124
- return this.readOnlyScopes.has(name);
125
- }
126
-
127
- /**
128
- * Get row-level filters for a scope
129
- */
130
- getFilters(name: string): RowLevelFilter[] {
131
- return this.filters[name] || [];
132
- }
133
-
134
- /**
135
- * Set row-level filters for a scope
136
- */
137
- setFilters(name: string, filters: RowLevelFilter[]): void {
138
- this.filters[name] = filters;
139
- }
140
-
141
- /**
142
- * Apply row-level filters to a dataset
143
- */
144
- applyFilters(name: string, data: any[]): any[] {
145
- const scopeFilters = this.filters[name];
146
- if (!scopeFilters || scopeFilters.length === 0) {
147
- return data;
148
- }
149
-
150
- return data.filter(row => {
151
- return scopeFilters.every(filter => {
152
- const fieldValue = row[filter.field];
153
- return evaluateFilter(fieldValue, filter.operator, filter.value);
154
- });
155
- });
156
- }
157
-
158
- /**
159
- * Update data in a scope
160
- */
161
- updateScopeData(name: string, data: any): void {
162
- const scope = this.scopes[name];
163
- if (!scope) return;
164
-
165
- if (this.readOnlyScopes.has(name)) {
166
- throw new Error(`Cannot update read-only scope: ${name}`);
167
- }
168
-
169
- scope.data = data;
170
- this.notifyListeners(name, scope);
171
- }
172
-
173
- /**
174
- * Update loading state for a scope
175
- */
176
- updateScopeLoading(name: string, loading: boolean): void {
177
- const scope = this.scopes[name];
178
- if (!scope) return;
179
-
180
- scope.loading = loading;
181
- this.notifyListeners(name, scope);
182
- }
183
-
184
- /**
185
- * Update error state for a scope
186
- */
187
- updateScopeError(name: string, error: Error | string | null): void {
188
- const scope = this.scopes[name];
189
- if (!scope) return;
190
-
191
- scope.error = error;
192
- this.notifyListeners(name, scope);
193
- }
194
-
195
- /**
196
- * Subscribe to scope changes
197
- */
198
- onScopeChange(name: string, listener: (scope: DataScope) => void): () => void {
199
- if (!this.listeners.has(name)) {
200
- this.listeners.set(name, []);
201
- }
202
- this.listeners.get(name)!.push(listener);
203
-
204
- return () => {
205
- const arr = this.listeners.get(name);
206
- if (arr) {
207
- const idx = arr.indexOf(listener);
208
- if (idx >= 0) arr.splice(idx, 1);
209
- }
210
- };
211
- }
212
-
213
- /**
214
- * Get all registered scope names
215
- */
216
- getScopeNames(): string[] {
217
- return Object.keys(this.scopes);
218
- }
219
-
220
- /**
221
- * Clear all scopes
222
- */
223
- clear(): void {
224
- this.scopes = {};
225
- this.filters = {};
226
- this.readOnlyScopes.clear();
227
- this.listeners.clear();
228
- }
229
-
230
- private notifyListeners(name: string, scope: DataScope): void {
231
- const arr = this.listeners.get(name);
232
- if (arr) {
233
- arr.forEach(listener => listener(scope));
234
- }
235
- }
236
- }
237
-
238
- /**
239
- * Evaluate a single filter condition against a field value
240
- */
241
- function evaluateFilter(fieldValue: any, operator: RowLevelFilter['operator'], filterValue: any): boolean {
242
- switch (operator) {
243
- case 'eq':
244
- return fieldValue === filterValue;
245
- case 'ne':
246
- return fieldValue !== filterValue;
247
- case 'gt':
248
- return fieldValue > filterValue;
249
- case 'lt':
250
- return fieldValue < filterValue;
251
- case 'gte':
252
- return fieldValue >= filterValue;
253
- case 'lte':
254
- return fieldValue <= filterValue;
255
- case 'in':
256
- return Array.isArray(filterValue) && filterValue.includes(fieldValue);
257
- case 'nin':
258
- return Array.isArray(filterValue) && !filterValue.includes(fieldValue);
259
- case 'contains':
260
- return typeof fieldValue === 'string' && fieldValue.includes(String(filterValue));
261
- default:
262
- return true;
263
- }
264
- }
265
-
266
- /**
267
- * Default DataScopeManager instance
268
- */
269
- export const defaultDataScopeManager = new DataScopeManager();
@@ -1,282 +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 - View Data Provider
11
- *
12
- * Resolves @objectstack/spec ViewData discriminated union into
13
- * a unified data access interface. Supports three data modes:
14
- *
15
- * 1. 'object' — Metadata-driven via ObjectStack API (object name → fields/records)
16
- * 2. 'api' — Custom REST API endpoints (read/write URLs)
17
- * 3. 'value' — Static data (pre-loaded items array)
18
- *
19
- * @module data-scope
20
- * @packageDocumentation
21
- */
22
-
23
- /** ViewData union — matches @objectstack/spec ViewDataSchema */
24
- export type ViewDataConfig =
25
- | { provider: 'object'; object: string }
26
- | {
27
- provider: 'api';
28
- read: { url: string; method?: string; headers?: Record<string, string> };
29
- write?: { url: string; method?: string; headers?: Record<string, string> };
30
- }
31
- | { provider: 'value'; items: any[] };
32
-
33
- /** Element-level data source — matches @objectstack/spec ElementDataSourceSchema */
34
- export interface ElementDataSourceConfig {
35
- object: string;
36
- view?: string;
37
- filter?: Record<string, any>;
38
- sort?: Array<{ field: string; order: 'asc' | 'desc' }>;
39
- limit?: number;
40
- }
41
-
42
- /** Fetcher interface — consumers provide the actual fetch implementation */
43
- export interface DataFetcher {
44
- /** Fetch records for an object */
45
- fetchRecords(
46
- object: string,
47
- options?: {
48
- filter?: Record<string, any>;
49
- sort?: Array<{ field: string; order: 'asc' | 'desc' }>;
50
- limit?: number;
51
- offset?: number;
52
- fields?: string[];
53
- },
54
- ): Promise<{ records: any[]; total: number }>;
55
-
56
- /** Fetch object metadata (fields, etc.) */
57
- fetchMetadata?(object: string): Promise<{
58
- name: string;
59
- label?: string;
60
- fields: Array<{
61
- name: string;
62
- label?: string;
63
- type: string;
64
- required?: boolean;
65
- }>;
66
- }>;
67
-
68
- /** Fetch from a custom API URL */
69
- fetchUrl?(
70
- url: string,
71
- options?: {
72
- method?: string;
73
- headers?: Record<string, string>;
74
- body?: any;
75
- },
76
- ): Promise<any>;
77
- }
78
-
79
- /** Resolved data result */
80
- export interface ResolvedData {
81
- /** Data records */
82
- records: any[];
83
- /** Total record count (for pagination) */
84
- total: number;
85
- /** Object metadata (if available) */
86
- metadata?: {
87
- name: string;
88
- label?: string;
89
- fields: Array<{
90
- name: string;
91
- label?: string;
92
- type: string;
93
- required?: boolean;
94
- }>;
95
- };
96
- /** Provider type */
97
- provider: 'object' | 'api' | 'value';
98
- /** Loading state */
99
- loading: boolean;
100
- /** Error */
101
- error?: string;
102
- }
103
-
104
- /** Extract records array from various common API response shapes */
105
- function extractRecords(data: any): any[] {
106
- if (Array.isArray(data)) return data;
107
- if (Array.isArray(data?.records)) return data.records;
108
- if (Array.isArray(data?.data)) return data.data;
109
- if (Array.isArray(data?.items)) return data.items;
110
- return [];
111
- }
112
-
113
- /**
114
- * Resolves ViewData configuration into actual data via a pluggable fetcher.
115
- *
116
- * @example
117
- * ```ts
118
- * const provider = new ViewDataProvider(myFetcher);
119
- * const data = await provider.resolve({ provider: 'object', object: 'Account' });
120
- * ```
121
- */
122
- export class ViewDataProvider {
123
- private fetcher: DataFetcher | null = null;
124
-
125
- constructor(fetcher?: DataFetcher) {
126
- this.fetcher = fetcher ?? null;
127
- }
128
-
129
- /** Set the data fetcher implementation */
130
- setFetcher(fetcher: DataFetcher): void {
131
- this.fetcher = fetcher;
132
- }
133
-
134
- /** Resolve ViewData config into actual data */
135
- async resolve(
136
- config: ViewDataConfig,
137
- options?: {
138
- filter?: Record<string, any>;
139
- sort?: Array<{ field: string; order: 'asc' | 'desc' }>;
140
- limit?: number;
141
- offset?: number;
142
- fields?: string[];
143
- },
144
- ): Promise<ResolvedData> {
145
- switch (config.provider) {
146
- case 'value':
147
- return this.resolveValue(config);
148
- case 'api':
149
- return this.resolveApi(config);
150
- case 'object':
151
- return this.resolveObject(config, options);
152
- default:
153
- return {
154
- records: [],
155
- total: 0,
156
- provider: 'value' as const,
157
- loading: false,
158
- error: `Unknown data provider: ${(config as any).provider}`,
159
- };
160
- }
161
- }
162
-
163
- /** Resolve static value data */
164
- private resolveValue(config: {
165
- provider: 'value';
166
- items: any[];
167
- }): ResolvedData {
168
- const items = Array.isArray(config.items) ? config.items : [];
169
- return {
170
- records: items,
171
- total: items.length,
172
- provider: 'value',
173
- loading: false,
174
- };
175
- }
176
-
177
- /** Resolve API-based data */
178
- private async resolveApi(config: {
179
- provider: 'api';
180
- read: { url: string; method?: string; headers?: Record<string, string> };
181
- }): Promise<ResolvedData> {
182
- if (!this.fetcher?.fetchUrl) {
183
- return {
184
- records: [],
185
- total: 0,
186
- provider: 'api',
187
- loading: false,
188
- error: 'No fetchUrl implementation available for API data provider',
189
- };
190
- }
191
-
192
- try {
193
- const data = await this.fetcher.fetchUrl(config.read.url, {
194
- method: config.read.method,
195
- headers: config.read.headers,
196
- });
197
-
198
- // Handle common response shapes
199
- const records = extractRecords(data);
200
- const total = data?.total ?? data?.count ?? records.length;
201
-
202
- return {
203
- records,
204
- total,
205
- provider: 'api',
206
- loading: false,
207
- };
208
- } catch (error) {
209
- return {
210
- records: [],
211
- total: 0,
212
- provider: 'api',
213
- loading: false,
214
- error: (error as Error).message,
215
- };
216
- }
217
- }
218
-
219
- /** Resolve object-based data (metadata-driven) */
220
- private async resolveObject(
221
- config: { provider: 'object'; object: string },
222
- options?: {
223
- filter?: Record<string, any>;
224
- sort?: Array<{ field: string; order: 'asc' | 'desc' }>;
225
- limit?: number;
226
- offset?: number;
227
- fields?: string[];
228
- },
229
- ): Promise<ResolvedData> {
230
- if (!this.fetcher) {
231
- return {
232
- records: [],
233
- total: 0,
234
- provider: 'object',
235
- loading: false,
236
- error: 'No data fetcher configured for object data provider',
237
- };
238
- }
239
-
240
- try {
241
- // Fetch metadata if available
242
- let metadata: ResolvedData['metadata'];
243
- if (this.fetcher.fetchMetadata) {
244
- metadata = await this.fetcher.fetchMetadata(config.object);
245
- }
246
-
247
- // Fetch records
248
- const result = await this.fetcher.fetchRecords(config.object, options);
249
-
250
- return {
251
- records: result.records,
252
- total: result.total,
253
- metadata,
254
- provider: 'object',
255
- loading: false,
256
- };
257
- } catch (error) {
258
- return {
259
- records: [],
260
- total: 0,
261
- provider: 'object',
262
- loading: false,
263
- error: (error as Error).message,
264
- };
265
- }
266
- }
267
-
268
- /** Resolve element-level data source */
269
- async resolveElementDataSource(
270
- config: ElementDataSourceConfig,
271
- ): Promise<ResolvedData> {
272
- return this.resolve(
273
- { provider: 'object', object: config.object },
274
- {
275
- filter: config.filter,
276
- sort: config.sort,
277
- limit: config.limit,
278
- },
279
- );
280
- }
281
-
282
- }