@object-ui/core 0.3.0 → 0.3.1
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/CHANGELOG.md +8 -0
- package/dist/actions/ActionRunner.d.ts +40 -0
- package/dist/actions/ActionRunner.js +160 -0
- package/dist/actions/index.d.ts +8 -0
- package/dist/actions/index.js +8 -0
- package/dist/adapters/index.d.ts +7 -0
- package/dist/adapters/index.js +10 -0
- package/dist/builder/schema-builder.d.ts +7 -0
- package/dist/builder/schema-builder.js +4 -6
- package/dist/evaluator/ExpressionContext.d.ts +51 -0
- package/dist/evaluator/ExpressionContext.js +110 -0
- package/dist/evaluator/ExpressionEvaluator.d.ts +99 -0
- package/dist/evaluator/ExpressionEvaluator.js +200 -0
- package/dist/evaluator/index.d.ts +9 -0
- package/dist/evaluator/index.js +9 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -1
- package/dist/registry/Registry.d.ts +7 -0
- package/dist/registry/Registry.js +7 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.js +7 -0
- package/dist/utils/filter-converter.d.ts +57 -0
- package/dist/utils/filter-converter.js +100 -0
- package/dist/validation/schema-validator.d.ts +7 -0
- package/dist/validation/schema-validator.js +4 -6
- package/package.json +16 -5
- package/src/actions/ActionRunner.ts +195 -0
- package/src/actions/index.ts +9 -0
- package/src/adapters/README.md +180 -0
- package/src/adapters/index.d.ts +8 -0
- package/src/adapters/index.js +10 -0
- package/src/adapters/index.ts +10 -0
- package/src/builder/schema-builder.d.ts +7 -0
- package/src/builder/schema-builder.js +4 -6
- package/src/builder/schema-builder.ts +8 -0
- package/src/evaluator/ExpressionContext.ts +118 -0
- package/src/evaluator/ExpressionEvaluator.ts +248 -0
- package/src/evaluator/__tests__/ExpressionEvaluator.test.ts +101 -0
- package/src/evaluator/index.ts +10 -0
- package/src/index.d.ts +9 -0
- package/src/index.js +10 -1
- package/src/index.test.ts +8 -0
- package/src/index.ts +11 -1
- package/src/registry/Registry.d.ts +7 -0
- package/src/registry/Registry.js +7 -0
- package/src/registry/Registry.ts +8 -0
- package/src/types/index.d.ts +7 -0
- package/src/types/index.js +7 -0
- package/src/types/index.ts +8 -0
- package/src/utils/__tests__/filter-converter.test.ts +118 -0
- package/src/utils/filter-converter.d.ts +57 -0
- package/src/utils/filter-converter.js +100 -0
- package/src/utils/filter-converter.ts +133 -0
- package/src/validation/schema-validator.d.ts +7 -0
- package/src/validation/schema-validator.js +4 -6
- package/src/validation/schema-validator.ts +8 -0
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,40 @@
|
|
|
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 ActionResult {
|
|
9
|
+
success: boolean;
|
|
10
|
+
data?: any;
|
|
11
|
+
error?: string;
|
|
12
|
+
reload?: boolean;
|
|
13
|
+
close?: boolean;
|
|
14
|
+
redirect?: string;
|
|
15
|
+
}
|
|
16
|
+
export interface ActionContext {
|
|
17
|
+
data?: Record<string, any>;
|
|
18
|
+
record?: any;
|
|
19
|
+
user?: any;
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
}
|
|
22
|
+
export type ActionHandler = (action: any, context: ActionContext) => Promise<ActionResult> | ActionResult;
|
|
23
|
+
export declare class ActionRunner {
|
|
24
|
+
private handlers;
|
|
25
|
+
private evaluator;
|
|
26
|
+
private context;
|
|
27
|
+
constructor(context?: ActionContext);
|
|
28
|
+
registerHandler(actionName: string, handler: ActionHandler): void;
|
|
29
|
+
execute(action: any): Promise<ActionResult>;
|
|
30
|
+
private executeActionSchema;
|
|
31
|
+
/**
|
|
32
|
+
* Execute navigation action
|
|
33
|
+
*/
|
|
34
|
+
private executeNavigation;
|
|
35
|
+
private executeAPI;
|
|
36
|
+
private showConfirmation;
|
|
37
|
+
updateContext(newContext: Partial<ActionContext>): void;
|
|
38
|
+
getContext(): ActionContext;
|
|
39
|
+
}
|
|
40
|
+
export declare function executeAction(action: any, context?: ActionContext): Promise<ActionResult>;
|
|
@@ -0,0 +1,160 @@
|
|
|
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 - Action Runner
|
|
10
|
+
*
|
|
11
|
+
* Executes actions defined in ActionSchema and EventHandler.
|
|
12
|
+
*/
|
|
13
|
+
import { ExpressionEvaluator } from '../evaluator/ExpressionEvaluator';
|
|
14
|
+
export class ActionRunner {
|
|
15
|
+
constructor(context = {}) {
|
|
16
|
+
Object.defineProperty(this, "handlers", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: new Map()
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(this, "evaluator", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: void 0
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(this, "context", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: void 0
|
|
33
|
+
});
|
|
34
|
+
this.context = context;
|
|
35
|
+
this.evaluator = new ExpressionEvaluator(context);
|
|
36
|
+
}
|
|
37
|
+
registerHandler(actionName, handler) {
|
|
38
|
+
this.handlers.set(actionName, handler);
|
|
39
|
+
}
|
|
40
|
+
async execute(action) {
|
|
41
|
+
try {
|
|
42
|
+
if (action.condition) {
|
|
43
|
+
const shouldExecute = this.evaluator.evaluateCondition(action.condition);
|
|
44
|
+
if (!shouldExecute) {
|
|
45
|
+
return { success: false, error: 'Action condition not met' };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (action.disabled) {
|
|
49
|
+
const isDisabled = typeof action.disabled === 'string'
|
|
50
|
+
? this.evaluator.evaluateCondition(action.disabled)
|
|
51
|
+
: action.disabled;
|
|
52
|
+
if (isDisabled) {
|
|
53
|
+
return { success: false, error: 'Action is disabled' };
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (action.type === 'action' || action.actionType) {
|
|
57
|
+
return await this.executeActionSchema(action);
|
|
58
|
+
}
|
|
59
|
+
else if (action.type === 'navigation' || action.navigate) {
|
|
60
|
+
return await this.executeNavigation(action);
|
|
61
|
+
}
|
|
62
|
+
else if (action.type === 'api' || action.api) {
|
|
63
|
+
return await this.executeAPI(action);
|
|
64
|
+
}
|
|
65
|
+
else if (action.onClick) {
|
|
66
|
+
await action.onClick();
|
|
67
|
+
return { success: true };
|
|
68
|
+
}
|
|
69
|
+
return { success: false, error: 'Unknown action type' };
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
return { success: false, error: error.message };
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async executeActionSchema(action) {
|
|
76
|
+
const result = { success: true };
|
|
77
|
+
if (action.confirmText) {
|
|
78
|
+
const confirmed = await this.showConfirmation(action.confirmText);
|
|
79
|
+
if (!confirmed) {
|
|
80
|
+
return { success: false, error: 'Action cancelled by user' };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (action.api) {
|
|
84
|
+
const apiResult = await this.executeAPI(action);
|
|
85
|
+
if (!apiResult.success)
|
|
86
|
+
return apiResult;
|
|
87
|
+
result.data = apiResult.data;
|
|
88
|
+
}
|
|
89
|
+
if (action.onClick) {
|
|
90
|
+
await action.onClick();
|
|
91
|
+
}
|
|
92
|
+
result.reload = action.reload !== false;
|
|
93
|
+
result.close = action.close !== false;
|
|
94
|
+
if (action.redirect) {
|
|
95
|
+
result.redirect = this.evaluator.evaluate(action.redirect);
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Execute navigation action
|
|
101
|
+
*/
|
|
102
|
+
async executeNavigation(action) {
|
|
103
|
+
const nav = action.navigate || action;
|
|
104
|
+
const to = this.evaluator.evaluate(nav.to);
|
|
105
|
+
// Validate URL to prevent javascript: or data: schemes
|
|
106
|
+
const isValidUrl = typeof to === 'string' && (to.startsWith('http://') ||
|
|
107
|
+
to.startsWith('https://') ||
|
|
108
|
+
to.startsWith('/') ||
|
|
109
|
+
to.startsWith('./'));
|
|
110
|
+
if (!isValidUrl) {
|
|
111
|
+
return {
|
|
112
|
+
success: false,
|
|
113
|
+
error: 'Invalid URL scheme. Only http://, https://, and relative URLs are allowed.'
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
if (nav.external) {
|
|
117
|
+
window.open(to, '_blank', 'noopener,noreferrer');
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
return { success: true, redirect: to };
|
|
121
|
+
}
|
|
122
|
+
return { success: true };
|
|
123
|
+
}
|
|
124
|
+
async executeAPI(action) {
|
|
125
|
+
const apiConfig = action.api;
|
|
126
|
+
if (typeof apiConfig === 'string') {
|
|
127
|
+
try {
|
|
128
|
+
const response = await fetch(apiConfig, {
|
|
129
|
+
method: action.method || 'POST',
|
|
130
|
+
headers: { 'Content-Type': 'application/json' },
|
|
131
|
+
body: JSON.stringify(this.context.data || {})
|
|
132
|
+
});
|
|
133
|
+
if (!response.ok) {
|
|
134
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
135
|
+
}
|
|
136
|
+
const data = await response.json();
|
|
137
|
+
return { success: true, data };
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
return { success: false, error: error.message };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return { success: false, error: 'Complex API configuration not yet implemented' };
|
|
144
|
+
}
|
|
145
|
+
async showConfirmation(message) {
|
|
146
|
+
const evaluatedMessage = this.evaluator.evaluate(message);
|
|
147
|
+
return window.confirm(evaluatedMessage);
|
|
148
|
+
}
|
|
149
|
+
updateContext(newContext) {
|
|
150
|
+
this.context = { ...this.context, ...newContext };
|
|
151
|
+
this.evaluator.updateContext(newContext);
|
|
152
|
+
}
|
|
153
|
+
getContext() {
|
|
154
|
+
return this.context;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
export async function executeAction(action, context = {}) {
|
|
158
|
+
const runner = new ActionRunner(context);
|
|
159
|
+
return await runner.execute(action);
|
|
160
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ObjectUI
|
|
4
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
// export { ObjectStackAdapter, createObjectStackAdapter } from './objectstack-adapter';
|
|
10
|
+
// Adapters have been moved to separate packages (e.g. @object-ui/data-objectstack)
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* ObjectUI
|
|
3
|
+
* Copyright (c) 2024-present ObjectStack Inc.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* @module builder
|
|
8
|
-
* @packageDocumentation
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
9
7
|
*/
|
|
10
8
|
/**
|
|
11
9
|
* Base builder class
|
|
@@ -0,0 +1,51 @@
|
|
|
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 - Expression Context
|
|
10
|
+
*
|
|
11
|
+
* Manages variable scope and data context for expression evaluation.
|
|
12
|
+
*
|
|
13
|
+
* @module evaluator
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Expression context for variable resolution
|
|
18
|
+
*/
|
|
19
|
+
export declare class ExpressionContext {
|
|
20
|
+
private scopes;
|
|
21
|
+
constructor(initialData?: Record<string, any>);
|
|
22
|
+
/**
|
|
23
|
+
* Push a new scope onto the context stack
|
|
24
|
+
*/
|
|
25
|
+
pushScope(data: Record<string, any>): void;
|
|
26
|
+
/**
|
|
27
|
+
* Pop the current scope from the context stack
|
|
28
|
+
*/
|
|
29
|
+
popScope(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Get a variable value from the context
|
|
32
|
+
* Searches from innermost to outermost scope
|
|
33
|
+
*/
|
|
34
|
+
get(path: string): any;
|
|
35
|
+
/**
|
|
36
|
+
* Set a variable value in the current scope
|
|
37
|
+
*/
|
|
38
|
+
set(name: string, value: any): void;
|
|
39
|
+
/**
|
|
40
|
+
* Check if a variable exists in any scope
|
|
41
|
+
*/
|
|
42
|
+
has(name: string): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Get all variables from all scopes as a flat object
|
|
45
|
+
*/
|
|
46
|
+
toObject(): Record<string, any>;
|
|
47
|
+
/**
|
|
48
|
+
* Create a child context with additional data
|
|
49
|
+
*/
|
|
50
|
+
createChild(data?: Record<string, any>): ExpressionContext;
|
|
51
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
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 - Expression Context
|
|
10
|
+
*
|
|
11
|
+
* Manages variable scope and data context for expression evaluation.
|
|
12
|
+
*
|
|
13
|
+
* @module evaluator
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Expression context for variable resolution
|
|
18
|
+
*/
|
|
19
|
+
export class ExpressionContext {
|
|
20
|
+
constructor(initialData = {}) {
|
|
21
|
+
Object.defineProperty(this, "scopes", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: []
|
|
26
|
+
});
|
|
27
|
+
this.scopes.push(new Map(Object.entries(initialData)));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Push a new scope onto the context stack
|
|
31
|
+
*/
|
|
32
|
+
pushScope(data) {
|
|
33
|
+
this.scopes.push(new Map(Object.entries(data)));
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Pop the current scope from the context stack
|
|
37
|
+
*/
|
|
38
|
+
popScope() {
|
|
39
|
+
if (this.scopes.length > 1) {
|
|
40
|
+
this.scopes.pop();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get a variable value from the context
|
|
45
|
+
* Searches from innermost to outermost scope
|
|
46
|
+
*/
|
|
47
|
+
get(path) {
|
|
48
|
+
// Split path by dots for nested access
|
|
49
|
+
const parts = path.split('.');
|
|
50
|
+
const varName = parts[0];
|
|
51
|
+
// Search scopes from innermost to outermost
|
|
52
|
+
for (let i = this.scopes.length - 1; i >= 0; i--) {
|
|
53
|
+
if (this.scopes[i].has(varName)) {
|
|
54
|
+
let value = this.scopes[i].get(varName);
|
|
55
|
+
// Navigate nested path
|
|
56
|
+
for (let j = 1; j < parts.length; j++) {
|
|
57
|
+
if (value && typeof value === 'object') {
|
|
58
|
+
value = value[parts[j]];
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Set a variable value in the current scope
|
|
71
|
+
*/
|
|
72
|
+
set(name, value) {
|
|
73
|
+
if (this.scopes.length > 0) {
|
|
74
|
+
this.scopes[this.scopes.length - 1].set(name, value);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Check if a variable exists in any scope
|
|
79
|
+
*/
|
|
80
|
+
has(name) {
|
|
81
|
+
const varName = name.split('.')[0];
|
|
82
|
+
for (let i = this.scopes.length - 1; i >= 0; i--) {
|
|
83
|
+
if (this.scopes[i].has(varName)) {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Get all variables from all scopes as a flat object
|
|
91
|
+
*/
|
|
92
|
+
toObject() {
|
|
93
|
+
const result = {};
|
|
94
|
+
// Merge from outermost to innermost (later scopes override earlier ones)
|
|
95
|
+
for (const scope of this.scopes) {
|
|
96
|
+
for (const [key, value] of scope.entries()) {
|
|
97
|
+
result[key] = value;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return result;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Create a child context with additional data
|
|
104
|
+
*/
|
|
105
|
+
createChild(data = {}) {
|
|
106
|
+
const child = new ExpressionContext();
|
|
107
|
+
child.scopes = [...this.scopes, new Map(Object.entries(data))];
|
|
108
|
+
return child;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
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 - Expression Evaluator
|
|
10
|
+
*
|
|
11
|
+
* Evaluates template string expressions like ${data.amount > 1000} for dynamic UI behavior.
|
|
12
|
+
* Supports variable substitution, comparison operators, and basic JavaScript expressions.
|
|
13
|
+
*
|
|
14
|
+
* @module evaluator
|
|
15
|
+
* @packageDocumentation
|
|
16
|
+
*/
|
|
17
|
+
import { ExpressionContext } from './ExpressionContext';
|
|
18
|
+
/**
|
|
19
|
+
* Options for expression evaluation
|
|
20
|
+
*/
|
|
21
|
+
export interface EvaluationOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Default value to return if evaluation fails
|
|
24
|
+
*/
|
|
25
|
+
defaultValue?: any;
|
|
26
|
+
/**
|
|
27
|
+
* Whether to throw errors on evaluation failure
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
throwOnError?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Whether to sanitize the expression before evaluation
|
|
33
|
+
* @default true
|
|
34
|
+
*/
|
|
35
|
+
sanitize?: boolean;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Expression evaluator for dynamic UI expressions
|
|
39
|
+
*/
|
|
40
|
+
export declare class ExpressionEvaluator {
|
|
41
|
+
private context;
|
|
42
|
+
constructor(context?: ExpressionContext | Record<string, any>);
|
|
43
|
+
/**
|
|
44
|
+
* Evaluate a string that may contain template expressions like ${...}
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const evaluator = new ExpressionEvaluator({ data: { amount: 1500 } });
|
|
49
|
+
* evaluator.evaluate('${data.amount > 1000}'); // Returns: true
|
|
50
|
+
* evaluator.evaluate('Amount is ${data.amount}'); // Returns: "Amount is 1500"
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
evaluate(expression: string | boolean | number | null | undefined, options?: EvaluationOptions): any;
|
|
54
|
+
/**
|
|
55
|
+
* Evaluate a single expression (without ${} wrapper)
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* evaluator.evaluateExpression('data.amount > 1000'); // Returns: true
|
|
60
|
+
* evaluator.evaluateExpression('data.user.name'); // Returns: "John"
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
evaluateExpression(expression: string, options?: {
|
|
64
|
+
sanitize?: boolean;
|
|
65
|
+
}): any;
|
|
66
|
+
/**
|
|
67
|
+
* Check if expression contains potentially dangerous code
|
|
68
|
+
*/
|
|
69
|
+
private isDangerous;
|
|
70
|
+
/**
|
|
71
|
+
* Evaluate a conditional expression and return boolean
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* evaluator.evaluateCondition('${data.age >= 18}'); // Returns: true/false
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
evaluateCondition(condition: string | boolean | undefined, options?: EvaluationOptions): boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Update the context with new data
|
|
81
|
+
*/
|
|
82
|
+
updateContext(data: Record<string, any>): void;
|
|
83
|
+
/**
|
|
84
|
+
* Get the current context
|
|
85
|
+
*/
|
|
86
|
+
getContext(): ExpressionContext;
|
|
87
|
+
/**
|
|
88
|
+
* Create a new evaluator with additional context data
|
|
89
|
+
*/
|
|
90
|
+
withContext(data: Record<string, any>): ExpressionEvaluator;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Convenience function to quickly evaluate an expression
|
|
94
|
+
*/
|
|
95
|
+
export declare function evaluateExpression(expression: string | boolean | number | null | undefined, context?: Record<string, any>, options?: EvaluationOptions): any;
|
|
96
|
+
/**
|
|
97
|
+
* Convenience function to evaluate a condition
|
|
98
|
+
*/
|
|
99
|
+
export declare function evaluateCondition(condition: string | boolean | undefined, context?: Record<string, any>): boolean;
|