@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
@@ -1,4 +1,4 @@
1
1
 
2
- > @object-ui/core@0.5.0 build /home/runner/work/objectui/objectui/packages/core
2
+ > @object-ui/core@3.0.0 build /home/runner/work/objectui/objectui/packages/core
3
3
  > tsc
4
4
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # @object-ui/core
2
2
 
3
+ ## 3.0.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 87979c3: Upgrade to @objectstack v3.0.0 and console bundle optimization
8
+ - Upgraded all @objectstack/\* packages from ^2.0.7 to ^3.0.0
9
+ - Breaking change migrations: Hub → Cloud namespace, definePlugin removed, PaginatedResult.value → .records, PaginatedResult.count → .total, client.meta.getObject() → client.meta.getItem()
10
+ - Console bundle optimization: split monolithic 3.7 MB chunk into 17 granular cacheable chunks (95% main entry reduction)
11
+ - Added gzip + brotli pre-compression via vite-plugin-compression2
12
+ - Lazy MSW loading for build:server (~150 KB gzip saved)
13
+ - Added bundle analysis with rollup-plugin-visualizer
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies [87979c3]
18
+ - @object-ui/types@3.0.0
19
+
20
+ ## 2.0.0
21
+
22
+ ### Major Changes
23
+
24
+ - b859617: Release v1.0.0 — unify all package versions to 1.0.0
25
+
26
+ ### Patch Changes
27
+
28
+ - Updated dependencies [b859617]
29
+ - @object-ui/types@2.0.0
30
+
3
31
  ## 0.3.1
4
32
 
5
33
  ### Patch Changes
@@ -0,0 +1,8 @@
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 {};
@@ -0,0 +1,53 @@
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
+ * Performance benchmark suite for @object-ui/core.
10
+ *
11
+ * Part of Q1 2026 roadmap §1.4 Test Coverage Improvement.
12
+ *
13
+ * Run with: npx vitest bench packages/core/src/__benchmarks__/
14
+ */
15
+ import { bench, describe } from 'vitest';
16
+ import { ExpressionEvaluator } from '@object-ui/core';
17
+ import { ComponentRegistry } from '@object-ui/core';
18
+ import { contrastRatio, meetsContrastLevel, hexToHSL } from '@object-ui/core';
19
+ describe('ExpressionEvaluator performance', () => {
20
+ const evaluator = new ExpressionEvaluator({ data: { name: 'Alice', age: 30, active: true } });
21
+ bench('evaluate simple string', () => {
22
+ evaluator.evaluate('Hello ${data.name}');
23
+ });
24
+ bench('evaluate 100 expressions', () => {
25
+ for (let i = 0; i < 100; i++) {
26
+ evaluator.evaluate('Hello ${data.name}');
27
+ }
28
+ });
29
+ });
30
+ describe('ComponentRegistry performance', () => {
31
+ bench('get registered component', () => {
32
+ ComponentRegistry.get('button');
33
+ });
34
+ bench('has check', () => {
35
+ ComponentRegistry.has('button');
36
+ });
37
+ });
38
+ describe('Theme utilities performance', () => {
39
+ bench('hexToHSL conversion', () => {
40
+ hexToHSL('#336699');
41
+ });
42
+ bench('contrastRatio calculation', () => {
43
+ contrastRatio('#000000', '#ffffff');
44
+ });
45
+ bench('meetsContrastLevel check', () => {
46
+ meetsContrastLevel('#000000', '#ffffff', 'AA');
47
+ });
48
+ bench('100 contrast checks', () => {
49
+ for (let i = 0; i < 100; i++) {
50
+ meetsContrastLevel('#336699', '#ffffff', 'AA');
51
+ }
52
+ });
53
+ });
@@ -5,6 +5,15 @@
5
5
  * This source code is licensed under the MIT license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
+ /**
9
+ * @object-ui/core - Action Runner
10
+ *
11
+ * Executes actions defined in ActionSchema and EventHandler.
12
+ * Supports all spec v2.0.1 action types: script, url, modal, flow, api.
13
+ * Features: conditional execution, confirmation, toast notifications,
14
+ * redirect handling, action chaining, custom handler registration.
15
+ */
16
+ import { ExpressionEvaluator } from '../evaluator/ExpressionEvaluator';
8
17
  export interface ActionResult {
9
18
  success: boolean;
10
19
  data?: any;
@@ -12,29 +21,244 @@ export interface ActionResult {
12
21
  reload?: boolean;
13
22
  close?: boolean;
14
23
  redirect?: string;
24
+ /** Modal schema to render (for type: 'modal') */
25
+ modal?: any;
15
26
  }
16
27
  export interface ActionContext {
17
28
  data?: Record<string, any>;
18
29
  record?: any;
30
+ selectedRecords?: Record<string, any>[];
19
31
  user?: any;
20
32
  [key: string]: any;
21
33
  }
22
- export type ActionHandler = (action: any, context: ActionContext) => Promise<ActionResult> | ActionResult;
34
+ /**
35
+ * API configuration for complex requests.
36
+ */
37
+ export interface ApiConfig {
38
+ /** API endpoint URL */
39
+ url: string;
40
+ /** HTTP method */
41
+ method?: string;
42
+ /** Request headers */
43
+ headers?: Record<string, string>;
44
+ /** Request body (will be JSON-stringified if object) */
45
+ body?: any;
46
+ /** Query parameters */
47
+ queryParams?: Record<string, string>;
48
+ /** Response type */
49
+ responseType?: 'json' | 'text' | 'blob';
50
+ }
51
+ /**
52
+ * Action definition accepted by the runner.
53
+ * Compatible with both UIActionSchema (spec v2.0.1) and legacy crud.ts ActionSchema.
54
+ */
55
+ export interface ActionDef {
56
+ /** Action type identifier: 'script' | 'url' | 'modal' | 'flow' | 'api' | 'navigation' | custom */
57
+ type?: string;
58
+ /** Legacy action type field */
59
+ actionType?: string;
60
+ /** Action name (from UIActionSchema) */
61
+ name?: string;
62
+ /** Display label */
63
+ label?: string;
64
+ /** Confirmation text — shows a confirm dialog before executing */
65
+ confirmText?: string;
66
+ /** Structured confirmation (from crud.ts) */
67
+ confirm?: {
68
+ title?: string;
69
+ message?: string;
70
+ confirmText?: string;
71
+ cancelText?: string;
72
+ };
73
+ /** Condition expression — if falsy, skip action */
74
+ condition?: string;
75
+ /** Disabled expression — if truthy, skip action */
76
+ disabled?: string | boolean;
77
+ /** API endpoint (string URL or complex config) */
78
+ api?: string | ApiConfig;
79
+ /** API endpoint URL (spec v2.0.1 alias) */
80
+ endpoint?: string;
81
+ /** HTTP method */
82
+ method?: string;
83
+ /** Navigation target */
84
+ navigate?: any;
85
+ /** onClick callback (legacy) */
86
+ onClick?: () => void | Promise<void>;
87
+ /** Whether to reload data after success */
88
+ reload?: boolean;
89
+ /** Whether to close dialog after success */
90
+ close?: boolean;
91
+ /** Redirect URL expression */
92
+ redirect?: string;
93
+ /** Toast configuration */
94
+ toast?: {
95
+ showOnSuccess?: boolean;
96
+ showOnError?: boolean;
97
+ duration?: number;
98
+ };
99
+ /** Success message (from UIActionSchema) */
100
+ successMessage?: string;
101
+ /** Error message (from UIActionSchema) */
102
+ errorMessage?: string;
103
+ /** Whether to refresh data after execution (from UIActionSchema) */
104
+ refreshAfter?: boolean;
105
+ /** Params object (for custom handlers) */
106
+ params?: Record<string, any>;
107
+ /** ActionParam definitions to collect from user before execution (from spec ActionSchema.params) */
108
+ actionParams?: ActionParamDef[];
109
+ /** Script/expression to execute (for type: 'script') */
110
+ execute?: string;
111
+ /** Target URL or identifier (for type: 'url', 'modal', 'flow') */
112
+ target?: string;
113
+ /** Modal schema to open (for type: 'modal') */
114
+ modal?: any;
115
+ /** Chained actions to execute after this one */
116
+ chain?: ActionDef[];
117
+ /** Chain execution mode */
118
+ chainMode?: 'sequential' | 'parallel';
119
+ /** Callback on success */
120
+ onSuccess?: ActionDef | ActionDef[];
121
+ /** Callback on failure */
122
+ onFailure?: ActionDef | ActionDef[];
123
+ /** Any additional properties */
124
+ [key: string]: any;
125
+ }
126
+ export type ActionHandler = (action: ActionDef, context: ActionContext) => Promise<ActionResult> | ActionResult;
127
+ /**
128
+ * Confirmation handler — replaces window.confirm.
129
+ * Consumers can provide an async implementation (e.g., Shadcn AlertDialog).
130
+ */
131
+ export type ConfirmationHandler = (message: string, options?: {
132
+ title?: string;
133
+ confirmText?: string;
134
+ cancelText?: string;
135
+ }) => Promise<boolean>;
136
+ /**
137
+ * Toast handler — consumers can wire to Sonner or any toast library.
138
+ */
139
+ export type ToastHandler = (message: string, options?: {
140
+ type?: 'success' | 'error' | 'info' | 'warning';
141
+ duration?: number;
142
+ }) => void;
143
+ /**
144
+ * Modal handler — consumers provide to render modal dialogs.
145
+ */
146
+ export type ModalHandler = (schema: any, context: ActionContext) => Promise<ActionResult>;
147
+ /**
148
+ * Navigation handler — consumers provide for SPA-aware routing.
149
+ */
150
+ export type NavigationHandler = (url: string, options?: {
151
+ external?: boolean;
152
+ newTab?: boolean;
153
+ replace?: boolean;
154
+ }) => void;
155
+ /**
156
+ * Param collection handler — consumers provide to show a dialog
157
+ * for collecting ActionParam values before action execution.
158
+ * Returns collected values, or null if cancelled.
159
+ */
160
+ export type ParamCollectionHandler = (params: ActionParamDef[]) => Promise<Record<string, any> | null>;
161
+ /**
162
+ * ActionParam definition accepted by the runner.
163
+ * Compatible with @objectstack/spec ActionParam.
164
+ */
165
+ export interface ActionParamDef {
166
+ name: string;
167
+ label: string;
168
+ type: string;
169
+ required?: boolean;
170
+ options?: Array<{
171
+ label: string;
172
+ value: string;
173
+ }>;
174
+ defaultValue?: unknown;
175
+ helpText?: string;
176
+ placeholder?: string;
177
+ validation?: string;
178
+ }
23
179
  export declare class ActionRunner {
24
180
  private handlers;
25
181
  private evaluator;
26
182
  private context;
183
+ private confirmHandler;
184
+ private toastHandler;
185
+ private modalHandler;
186
+ private navigationHandler;
187
+ private paramCollectionHandler;
27
188
  constructor(context?: ActionContext);
189
+ /**
190
+ * Set a custom confirmation handler (e.g., Shadcn AlertDialog).
191
+ */
192
+ setConfirmHandler(handler: ConfirmationHandler): void;
193
+ /**
194
+ * Set a custom toast handler (e.g., Sonner).
195
+ */
196
+ setToastHandler(handler: ToastHandler): void;
197
+ /**
198
+ * Set a modal handler (e.g., render a Dialog via React state).
199
+ */
200
+ setModalHandler(handler: ModalHandler): void;
201
+ /**
202
+ * Set a navigation handler (e.g., React Router navigate).
203
+ */
204
+ setNavigationHandler(handler: NavigationHandler): void;
205
+ /**
206
+ * Set a param collection handler — shows a dialog to collect
207
+ * ActionParam values before action execution.
208
+ */
209
+ setParamCollectionHandler(handler: ParamCollectionHandler): void;
28
210
  registerHandler(actionName: string, handler: ActionHandler): void;
29
- execute(action: any): Promise<ActionResult>;
211
+ unregisterHandler(actionName: string): void;
212
+ execute(action: ActionDef): Promise<ActionResult>;
213
+ /**
214
+ * Execute multiple actions in sequence or parallel.
215
+ */
216
+ executeChain(actions: ActionDef[], mode?: 'sequential' | 'parallel'): Promise<ActionResult>;
217
+ /**
218
+ * Post-execution: emit toast notifications, handle chaining, callbacks.
219
+ */
220
+ private handlePostExecution;
221
+ /**
222
+ * Execute script action — evaluates client-side expression via ExpressionEvaluator.
223
+ * Supports ${} template expressions referencing data, record, user context.
224
+ */
225
+ private executeScript;
226
+ /**
227
+ * Execute URL action — navigate to a URL.
228
+ * Uses navigationHandler for SPA routing, falls back to window.location.
229
+ */
230
+ private executeUrl;
231
+ /**
232
+ * Execute modal action — open a dialog.
233
+ * Delegates to the registered modalHandler; returns modal schema if no handler.
234
+ */
235
+ private executeModal;
236
+ /**
237
+ * Execute flow action — trigger a workflow/automation.
238
+ * Delegates to a registered 'flow' handler; otherwise returns not-implemented.
239
+ */
240
+ private executeFlow;
30
241
  private executeActionSchema;
31
242
  /**
32
243
  * Execute navigation action
33
244
  */
34
245
  private executeNavigation;
246
+ /**
247
+ * Execute API action — supports both simple string endpoint and complex ApiConfig.
248
+ */
35
249
  private executeAPI;
36
- private showConfirmation;
250
+ /**
251
+ * Validate URL to prevent javascript: or data: protocol injection.
252
+ */
253
+ private isValidUrl;
37
254
  updateContext(newContext: Partial<ActionContext>): void;
38
255
  getContext(): ActionContext;
256
+ /**
257
+ * Get the expression evaluator (for components that need to evaluate visibility, etc.)
258
+ */
259
+ getEvaluator(): ExpressionEvaluator;
39
260
  }
40
- export declare function executeAction(action: any, context?: ActionContext): Promise<ActionResult>;
261
+ /**
262
+ * Convenience function to execute a single action with a one-off runner.
263
+ */
264
+ export declare function executeAction(action: ActionDef, context?: ActionContext): Promise<ActionResult>;