@zvenigora/ng-eval-core 0.1.102 → 0.1.105
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/esm2022/lib/actual/services/base-eval.mjs +32 -1
- package/esm2022/lib/actual/services/compiler.service.mjs +66 -40
- package/esm2022/lib/actual/services/discovery.service.mjs +4 -23
- package/esm2022/lib/actual/services/eval.service.mjs +53 -30
- package/esm2022/lib/actual/services/parser.service.mjs +19 -9
- package/esm2022/lib/internal/classes/common/base-registry.mjs +10 -1
- package/esm2022/lib/internal/classes/common/case-insensitive-registry.mjs +10 -1
- package/esm2022/lib/internal/classes/common/context.mjs +36 -4
- package/esm2022/lib/internal/classes/common/public-api.mjs +2 -2
- package/esm2022/lib/internal/classes/common/registry.mjs +10 -1
- package/esm2022/lib/internal/classes/eval/eval-context.mjs +30 -2
- package/esm2022/lib/internal/classes/eval/parser-options.mjs +8 -0
- package/esm2022/lib/internal/classes/eval/public-api.mjs +2 -1
- package/esm2022/lib/internal/visitors/assignment-expression.mjs +4 -2
- package/esm2022/lib/internal/visitors/identifier.mjs +24 -2
- package/esm2022/lib/internal/visitors/member-expression.mjs +27 -15
- package/esm2022/lib/internal/visitors/public-api.mjs +2 -1
- package/esm2022/lib/internal/visitors/update-expression.mjs +10 -4
- package/esm2022/lib/internal/visitors/utils.mjs +59 -0
- package/fesm2022/zvenigora-ng-eval-core.mjs +1398 -1135
- package/fesm2022/zvenigora-ng-eval-core.mjs.map +1 -1
- package/lib/actual/services/base-eval.d.ts +21 -2
- package/lib/actual/services/compiler.service.d.ts +28 -16
- package/lib/actual/services/discovery.service.d.ts +1 -7
- package/lib/actual/services/eval.service.d.ts +22 -10
- package/lib/actual/services/parser.service.d.ts +11 -2
- package/lib/internal/classes/common/base-registry.d.ts +6 -0
- package/lib/internal/classes/common/case-insensitive-registry.d.ts +6 -0
- package/lib/internal/classes/common/context.d.ts +11 -0
- package/lib/internal/classes/common/public-api.d.ts +1 -1
- package/lib/internal/classes/common/registry.d.ts +6 -0
- package/lib/internal/classes/eval/eval-context.d.ts +7 -0
- package/lib/internal/classes/eval/parser-options.d.ts +2 -0
- package/lib/internal/classes/eval/public-api.d.ts +1 -0
- package/lib/internal/visitors/public-api.d.ts +1 -0
- package/lib/internal/visitors/utils.d.ts +26 -0
- package/package.json +2 -2
|
@@ -1,16 +1,35 @@
|
|
|
1
|
+
import { AnyNode } from "acorn";
|
|
1
2
|
import { ParserOptions } from "../../internal/interfaces";
|
|
3
|
+
import { ParserService } from "./parser.service";
|
|
4
|
+
import { EvalContext, EvalOptions, EvalState } from "../../internal/classes/eval";
|
|
5
|
+
import { Context } from "../../internal/public-api";
|
|
2
6
|
/**
|
|
3
7
|
* Base class for evaluation.
|
|
4
8
|
*/
|
|
5
9
|
export declare abstract class BaseEval {
|
|
10
|
+
protected parserService: ParserService;
|
|
6
11
|
private _parserOptions;
|
|
12
|
+
constructor(parserService: ParserService);
|
|
7
13
|
/**
|
|
8
14
|
* Gets the parser options.
|
|
9
15
|
*/
|
|
10
|
-
get parserOptions(): ParserOptions;
|
|
16
|
+
protected get parserOptions(): ParserOptions;
|
|
11
17
|
/**
|
|
12
18
|
* Sets the parser options.
|
|
13
19
|
* @param value The parser options to set.
|
|
14
20
|
*/
|
|
15
|
-
set parserOptions(value: ParserOptions);
|
|
21
|
+
protected set parserOptions(value: ParserOptions);
|
|
22
|
+
/**
|
|
23
|
+
* Parses the given expression into an abstract syntax tree (AST).
|
|
24
|
+
* @param expression - The expression to parse.
|
|
25
|
+
* @returns The parsed AST.
|
|
26
|
+
*/
|
|
27
|
+
protected parse(expression: string | AnyNode | undefined): AnyNode | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Creates an instance of EvalState.
|
|
30
|
+
* @param context - The evaluation context or context object.
|
|
31
|
+
* @param options - The evaluation options.
|
|
32
|
+
* @returns The created EvalState instance.
|
|
33
|
+
*/
|
|
34
|
+
createState(context?: EvalContext | Context, options?: EvalOptions): EvalState;
|
|
16
35
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseEval } from './base-eval';
|
|
2
2
|
import { ParserService } from './parser.service';
|
|
3
3
|
import { EvalService } from './eval.service';
|
|
4
|
-
import { EvalContext, EvalOptions } from '../../internal/classes/eval';
|
|
4
|
+
import { EvalContext, EvalOptions, EvalState } from '../../internal/classes/eval';
|
|
5
5
|
import { Context } from '../../internal/classes/common';
|
|
6
6
|
import { AnyNode } from 'acorn';
|
|
7
7
|
import { stateCallback, stateCallbackAsync } from '../../internal/functions';
|
|
@@ -11,15 +11,9 @@ import * as i0 from "@angular/core";
|
|
|
11
11
|
* Provides methods for compiling and evaluating expressions.
|
|
12
12
|
*/
|
|
13
13
|
export declare class CompilerService extends BaseEval {
|
|
14
|
-
parserService: ParserService;
|
|
15
|
-
evalService: EvalService;
|
|
14
|
+
protected parserService: ParserService;
|
|
15
|
+
protected evalService: EvalService;
|
|
16
16
|
constructor(parserService: ParserService, evalService: EvalService);
|
|
17
|
-
/**
|
|
18
|
-
* Parses the given expression into an abstract syntax tree (AST).
|
|
19
|
-
* @param expression - The expression to parse.
|
|
20
|
-
* @returns The parsed AST.
|
|
21
|
-
*/
|
|
22
|
-
private parse;
|
|
23
17
|
/**
|
|
24
18
|
* Compiles the given expression into a state callback function.
|
|
25
19
|
* @param expression - The expression to compile.
|
|
@@ -35,7 +29,23 @@ export declare class CompilerService extends BaseEval {
|
|
|
35
29
|
* @returns The result of the evaluation.
|
|
36
30
|
* @throws Error if there is an error during the evaluation.
|
|
37
31
|
*/
|
|
38
|
-
|
|
32
|
+
simpleCall(fn: stateCallback | undefined, context?: EvalContext | Context, options?: EvalOptions): unknown;
|
|
33
|
+
/**
|
|
34
|
+
* Calls the provided function with the given state.
|
|
35
|
+
*
|
|
36
|
+
* @param fn - The function to be called.
|
|
37
|
+
* @param state - The state to be passed to the function.
|
|
38
|
+
* @returns The value returned by the function.
|
|
39
|
+
* @throws If an error occurs during the function call.
|
|
40
|
+
*/
|
|
41
|
+
call(fn: stateCallback | undefined, state: EvalState): unknown;
|
|
42
|
+
/**
|
|
43
|
+
* Compiles the given expression into an asynchronous state callback function.
|
|
44
|
+
* @param expression - The expression to compile.
|
|
45
|
+
* @returns The compiled asynchronous state callback function.
|
|
46
|
+
* @throws Error if there is an error during compilation.
|
|
47
|
+
*/
|
|
48
|
+
compileAsync(expression: string | AnyNode | undefined): stateCallbackAsync | undefined;
|
|
39
49
|
/**
|
|
40
50
|
* Calls the given asynchronous state callback function with the specified context and options.
|
|
41
51
|
* @param fn - The asynchronous state callback function to call.
|
|
@@ -44,14 +54,16 @@ export declare class CompilerService extends BaseEval {
|
|
|
44
54
|
* @returns A promise that resolves to the result of the evaluation.
|
|
45
55
|
* @throws Error if there is an error during the evaluation.
|
|
46
56
|
*/
|
|
47
|
-
|
|
57
|
+
simpleCallAsync(fn: stateCallbackAsync | undefined, context?: EvalContext | Context, options?: EvalOptions): Promise<unknown>;
|
|
48
58
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* @
|
|
52
|
-
* @
|
|
59
|
+
* Calls the provided asynchronous function with the given state.
|
|
60
|
+
*
|
|
61
|
+
* @param fn - The asynchronous function to call.
|
|
62
|
+
* @param state - The state to pass to the function.
|
|
63
|
+
* @returns A promise that resolves to the value returned by the function.
|
|
64
|
+
* @throws If an error occurs during the function call.
|
|
53
65
|
*/
|
|
54
|
-
|
|
66
|
+
callAsync(fn: stateCallbackAsync | undefined, state: EvalState): Promise<unknown>;
|
|
55
67
|
static ɵfac: i0.ɵɵFactoryDeclaration<CompilerService, never>;
|
|
56
68
|
static ɵprov: i0.ɵɵInjectableDeclaration<CompilerService>;
|
|
57
69
|
}
|
|
@@ -7,7 +7,7 @@ import * as i0 from "@angular/core";
|
|
|
7
7
|
* Service responsible for discovering nodes in an abstract syntax tree (AST).
|
|
8
8
|
*/
|
|
9
9
|
export declare class DiscoveryService extends BaseEval {
|
|
10
|
-
parserService: ParserService;
|
|
10
|
+
protected parserService: ParserService;
|
|
11
11
|
/**
|
|
12
12
|
* Creates a new instance of the DiscoveryService class.
|
|
13
13
|
* @param parserService The parser service to be used.
|
|
@@ -22,12 +22,6 @@ export declare class DiscoveryService extends BaseEval {
|
|
|
22
22
|
* @throws If an error occurs during the search process.
|
|
23
23
|
*/
|
|
24
24
|
extract(expression: string | AnyNode | undefined, searchType: AnyNodeTypes): AnyNode[] | undefined;
|
|
25
|
-
/**
|
|
26
|
-
* Parses the given expression into an abstract syntax tree (AST).
|
|
27
|
-
* @param expression The expression to parse.
|
|
28
|
-
* @returns The AST representing the expression.
|
|
29
|
-
*/
|
|
30
|
-
private parse;
|
|
31
25
|
static ɵfac: i0.ɵɵFactoryDeclaration<DiscoveryService, never>;
|
|
32
26
|
static ɵprov: i0.ɵɵInjectableDeclaration<DiscoveryService>;
|
|
33
27
|
}
|
|
@@ -2,24 +2,18 @@ import { BaseEval } from './base-eval';
|
|
|
2
2
|
import { ParserService } from './parser.service';
|
|
3
3
|
import { AnyNode } from 'acorn';
|
|
4
4
|
import { Context } from '../../internal/classes/common';
|
|
5
|
-
import { EvalContext, EvalOptions } from '../../internal/classes/eval';
|
|
5
|
+
import { EvalContext, EvalOptions, EvalState } from '../../internal/classes/eval';
|
|
6
6
|
import * as i0 from "@angular/core";
|
|
7
7
|
/**
|
|
8
8
|
* Service for evaluating and parsing expressions.
|
|
9
9
|
*/
|
|
10
10
|
export declare class EvalService extends BaseEval {
|
|
11
|
-
parserService: ParserService;
|
|
11
|
+
protected parserService: ParserService;
|
|
12
12
|
/**
|
|
13
13
|
* Constructs a new instance of the EvalService class.
|
|
14
14
|
* @param parserService The parser service used for parsing expressions.
|
|
15
15
|
*/
|
|
16
16
|
constructor(parserService: ParserService);
|
|
17
|
-
/**
|
|
18
|
-
* Parses the given expression into an abstract syntax tree (AST).
|
|
19
|
-
* @param expression The expression to parse.
|
|
20
|
-
* @returns The AST representing the expression.
|
|
21
|
-
*/
|
|
22
|
-
private parse;
|
|
23
17
|
/**
|
|
24
18
|
* Evaluates the given expression.
|
|
25
19
|
* @param expression The expression to evaluate.
|
|
@@ -27,7 +21,16 @@ export declare class EvalService extends BaseEval {
|
|
|
27
21
|
* @param options The evaluation options.
|
|
28
22
|
* @returns The result of the evaluation.
|
|
29
23
|
*/
|
|
30
|
-
|
|
24
|
+
simpleEval(expression: string | AnyNode | undefined, context?: EvalContext | Context, options?: EvalOptions): unknown | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* Evaluates an expression using the provided state.
|
|
27
|
+
*
|
|
28
|
+
* @param expression - The expression to evaluate.
|
|
29
|
+
* @param state - The state object containing variables and functions used in the evaluation.
|
|
30
|
+
* @returns The result of the evaluation.
|
|
31
|
+
* @throws If an error occurs during evaluation.
|
|
32
|
+
*/
|
|
33
|
+
eval(expression: string | AnyNode | undefined, state: EvalState): unknown | undefined;
|
|
31
34
|
/**
|
|
32
35
|
* Asynchronously evaluates the given expression.
|
|
33
36
|
* @param expression The expression to evaluate.
|
|
@@ -35,7 +38,16 @@ export declare class EvalService extends BaseEval {
|
|
|
35
38
|
* @param options The evaluation options.
|
|
36
39
|
* @returns A promise that resolves to the result of the evaluation.
|
|
37
40
|
*/
|
|
38
|
-
|
|
41
|
+
simpleEvalAsync(expression: string | AnyNode | undefined, context?: EvalContext | Context, options?: EvalOptions): Promise<unknown | undefined>;
|
|
42
|
+
/**
|
|
43
|
+
* Asynchronously evaluates an expression using the provided state.
|
|
44
|
+
*
|
|
45
|
+
* @param expression - The expression to evaluate. Can be a string or an AST node.
|
|
46
|
+
* @param state - The evaluation state.
|
|
47
|
+
* @returns A promise that resolves to the result of the evaluation.
|
|
48
|
+
* @throws If an error occurs during evaluation.
|
|
49
|
+
*/
|
|
50
|
+
evalAsync(expression: string | AnyNode | undefined, state: EvalState): Promise<unknown | undefined>;
|
|
39
51
|
static ɵfac: i0.ɵɵFactoryDeclaration<EvalService, never>;
|
|
40
52
|
static ɵprov: i0.ɵɵInjectableDeclaration<EvalService>;
|
|
41
53
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { BaseEval } from './base-eval';
|
|
2
1
|
import { ParserOptions } from '../../internal/interfaces';
|
|
3
2
|
import { Expression, Program, AnyNode } from 'acorn';
|
|
4
3
|
import * as i0 from "@angular/core";
|
|
@@ -6,8 +5,18 @@ import * as i0 from "@angular/core";
|
|
|
6
5
|
* @description
|
|
7
6
|
* Service for parsing expressions and returning ES6/ES2020 AST.
|
|
8
7
|
*/
|
|
9
|
-
export declare class ParserService
|
|
8
|
+
export declare class ParserService {
|
|
9
|
+
private _parserOptions;
|
|
10
10
|
private _cache?;
|
|
11
|
+
/**
|
|
12
|
+
* Gets the parser options.
|
|
13
|
+
*/
|
|
14
|
+
get parserOptions(): ParserOptions;
|
|
15
|
+
/**
|
|
16
|
+
* Sets the parser options.
|
|
17
|
+
* @param value The parser options to set.
|
|
18
|
+
*/
|
|
19
|
+
set parserOptions(value: ParserOptions);
|
|
11
20
|
/**
|
|
12
21
|
* Constructs a new instance of the ParserService class.
|
|
13
22
|
*/
|
|
@@ -75,4 +75,10 @@ export declare class BaseRegistry<TKey, TValue> implements RegistryType<TKey, TV
|
|
|
75
75
|
* @returns An iterator that yields key-value pairs of type [TKey, TValue].
|
|
76
76
|
*/
|
|
77
77
|
[Symbol.iterator](): IterableIterator<[TKey, TValue]>;
|
|
78
|
+
/**
|
|
79
|
+
* Converts a BaseRegistry instance to an object.
|
|
80
|
+
* @param registry The BaseRegistry instance to convert.
|
|
81
|
+
* @returns An object representing the key-value pairs in the registry.
|
|
82
|
+
*/
|
|
83
|
+
toObject(): Record<string | number | symbol, TValue>;
|
|
78
84
|
}
|
|
@@ -76,4 +76,10 @@ export declare class CaseInsensitiveRegistry<TKey, TValue> implements RegistryTy
|
|
|
76
76
|
*/
|
|
77
77
|
[Symbol.iterator](): IterableIterator<[TKey, TValue]>;
|
|
78
78
|
private getKey;
|
|
79
|
+
/**
|
|
80
|
+
* Converts a BaseRegistry instance to an object.
|
|
81
|
+
* @param registry The BaseRegistry instance to convert.
|
|
82
|
+
* @returns An object representing the key-value pairs in the registry.
|
|
83
|
+
*/
|
|
84
|
+
toObject(): Record<string | number | symbol, TValue>;
|
|
79
85
|
}
|
|
@@ -2,6 +2,7 @@ import { Registry } from '../common';
|
|
|
2
2
|
import { EvalOptions } from '../eval';
|
|
3
3
|
export type BaseContext = Record<string | number | symbol, unknown>;
|
|
4
4
|
export type Context = Registry<unknown, unknown> | BaseContext;
|
|
5
|
+
export declare function isRegistryContext(context?: Context): boolean;
|
|
5
6
|
/**
|
|
6
7
|
* Converts a context object to a Context instance.
|
|
7
8
|
* @param context - The context object to convert.
|
|
@@ -29,3 +30,13 @@ export declare const getContextValue: (context?: Context, key?: unknown) => unkn
|
|
|
29
30
|
* @param value - The value to be set.
|
|
30
31
|
*/
|
|
31
32
|
export declare const setContextValue: (context: Context, key: unknown, value: unknown) => void;
|
|
33
|
+
/**
|
|
34
|
+
* Retrieves the key from the given context object.
|
|
35
|
+
* If the context is an instance of Registry, it searches for the key in a case-insensitive manner if specified.
|
|
36
|
+
* If the context is an instance of Object, it uses the getKeyValue function to retrieve the key-value pair.
|
|
37
|
+
* @param context - The context object.
|
|
38
|
+
* @param key - The key to retrieve.
|
|
39
|
+
* @param caseInsensitive - Specifies whether the search should be case-insensitive (only applicable for Registry instances).
|
|
40
|
+
* @returns The retrieved key, or undefined if the key is not found.
|
|
41
|
+
*/
|
|
42
|
+
export declare const getContextKey: (context: Context, key: string | number | symbol, caseInsensitive: boolean) => string | number | symbol | undefined;
|
|
@@ -6,4 +6,4 @@ export { Queue } from './queue';
|
|
|
6
6
|
export { Stack } from './stack';
|
|
7
7
|
export { Scope } from './scope';
|
|
8
8
|
export { Cache } from './cache';
|
|
9
|
-
export { BaseContext, Context, fromContext, getContextValue
|
|
9
|
+
export { BaseContext, Context, isRegistryContext, fromContext, getContextValue, getContextKey } from './context';
|
|
@@ -77,4 +77,10 @@ export declare class Registry<TKey, TValue> implements RegistryType<TKey, TValue
|
|
|
77
77
|
* @returns An iterator that yields key-value pairs of type [TKey, TValue].
|
|
78
78
|
*/
|
|
79
79
|
[Symbol.iterator](): IterableIterator<[TKey, TValue]>;
|
|
80
|
+
/**
|
|
81
|
+
* Converts a BaseRegistry instance to an object.
|
|
82
|
+
* @param registry The BaseRegistry instance to convert.
|
|
83
|
+
* @returns An object representing the key-value pairs in the registry.
|
|
84
|
+
*/
|
|
85
|
+
toObject(): Record<string | number | symbol, TValue>;
|
|
80
86
|
}
|
|
@@ -57,6 +57,13 @@ export declare class EvalContext {
|
|
|
57
57
|
* @returns The `this` value associated with the key, or undefined if not found.
|
|
58
58
|
*/
|
|
59
59
|
getThis(key: unknown): unknown | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves the value associated with the specified key from the evaluation context.
|
|
62
|
+
*
|
|
63
|
+
* @param key - The key to retrieve the value for.
|
|
64
|
+
* @returns The value associated with the key, or undefined if the key is not found.
|
|
65
|
+
*/
|
|
66
|
+
getKey(key: string | number | symbol): string | number | symbol | undefined;
|
|
60
67
|
/**
|
|
61
68
|
* Sets a key-value pair in the context.
|
|
62
69
|
* If the original context is a Registry, the key-value pair is set using the Registry's set method.
|
|
@@ -21,3 +21,4 @@ export { assignmentExpressionVisitor } from './assignment-expression';
|
|
|
21
21
|
export { updateExpressionVisitor } from './update-expression';
|
|
22
22
|
export { arrowFunctionExpressionVisitor } from './arrow-function-expression';
|
|
23
23
|
export { evaluatePattern, evaluatePatterns } from './pattern';
|
|
24
|
+
export { getKeyValue, equalIgnoreCase, getValueIgnoreCase } from './utils';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { BaseContext } from "../classes/common/context";
|
|
2
|
+
/**
|
|
3
|
+
* Retrieves the key-value pair from an object based on the provided key.
|
|
4
|
+
* @param obj - The object to search for the key-value pair.
|
|
5
|
+
* @param key - The key to search for in the object.
|
|
6
|
+
* @param caseInsesitive - Specifies whether the key comparison should be case-insensitive.
|
|
7
|
+
* @returns The key-value pair as an array, or undefined if the key is not found.
|
|
8
|
+
*/
|
|
9
|
+
export declare const getKeyValue: (obj: BaseContext, key: string | number | symbol, caseInsesitive: boolean) => [
|
|
10
|
+
string | number | symbol,
|
|
11
|
+
unknown
|
|
12
|
+
] | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Compares two values for equality, ignoring case sensitivity.
|
|
15
|
+
* @param a - The first value to compare.
|
|
16
|
+
* @param b - The second value to compare.
|
|
17
|
+
* @returns `true` if the values are equal, `false` otherwise.
|
|
18
|
+
*/
|
|
19
|
+
export declare const equalIgnoreCase: (a: string | number | symbol, b: string | number | symbol) => boolean | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Retrieves the value from an object, ignoring the case of the key.
|
|
22
|
+
* @param obj - The object to retrieve the value from.
|
|
23
|
+
* @param key - The key to search for, ignoring the case.
|
|
24
|
+
* @returns The value associated with the key, or undefined if the key is not found.
|
|
25
|
+
*/
|
|
26
|
+
export declare const getValueIgnoreCase: (obj: BaseContext, key: string | number | symbol) => unknown | undefined;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zvenigora/ng-eval-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.105",
|
|
4
4
|
"description": "An expression evaluator for Angular",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
],
|
|
13
13
|
"author": "Zvenigora (https://github.com/zvenigora)",
|
|
14
14
|
"license": "MIT",
|
|
15
|
-
"homepage": "https://github.com/
|
|
15
|
+
"homepage": "https://github.com/Zvenigora/ng-eval#readme",
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"@angular/common": "^17.0.0",
|
|
18
18
|
"@angular/core": "^17.0.0",
|