@object-ui/core 0.5.0 → 2.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 +11 -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/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 +4 -0
- package/dist/index.js +4 -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 +2 -1
- package/dist/registry/WidgetRegistry.d.ts +120 -0
- package/dist/registry/WidgetRegistry.js +275 -0
- package/dist/theme/ThemeEngine.d.ts +82 -0
- package/dist/theme/ThemeEngine.js +400 -0
- package/dist/theme/index.d.ts +8 -0
- package/dist/theme/index.js +8 -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 +67 -2
- 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/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/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 +4 -3
- package/src/query/__tests__/window-functions.test.ts +1 -1
- package/src/query/query-ast.ts +3 -3
- package/src/registry/Registry.ts +12 -1
- package/src/registry/WidgetRegistry.ts +316 -0
- package/src/registry/__tests__/WidgetRegistry.test.ts +321 -0
- package/src/theme/ThemeEngine.ts +452 -0
- package/src/theme/__tests__/ThemeEngine.test.ts +606 -0
- package/src/theme/index.ts +22 -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 +61 -2
- package/src/validation/validators/index.ts +1 -1
- package/src/validation/validators/object-validation-engine.ts +2 -2
- package/tsconfig.tsbuildinfo +1 -1
package/.turbo/turbo-build.log
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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>;
|