@zvenigora/ng-eval-core 0.1.104 → 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.
@@ -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
- call(fn: stateCallback | undefined, context?: EvalContext | Context, options?: EvalOptions): unknown;
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
- callAsync(fn: stateCallbackAsync | undefined, context?: EvalContext | Context, options?: EvalOptions): Promise<unknown>;
57
+ simpleCallAsync(fn: stateCallbackAsync | undefined, context?: EvalContext | Context, options?: EvalOptions): Promise<unknown>;
48
58
  /**
49
- * Compiles the given expression into an asynchronous state callback function.
50
- * @param expression - The expression to compile.
51
- * @returns The compiled asynchronous state callback function.
52
- * @throws Error if there is an error during compilation.
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
- compileAsync(expression: string | AnyNode | undefined): stateCallbackAsync | undefined;
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
- eval(expression: string | AnyNode | undefined, context?: EvalContext | Context, options?: EvalOptions): unknown | undefined;
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
- evalAsync(expression: string | AnyNode | undefined, context?: EvalContext | Context, options?: EvalOptions): Promise<unknown | undefined>;
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 extends BaseEval {
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
  */
@@ -0,0 +1,2 @@
1
+ import { ParserOptions } from "../../interfaces";
2
+ export declare const defaultParserOptions: ParserOptions;
@@ -3,3 +3,4 @@ export { EvalContext } from './eval-context';
3
3
  export { EvalResult } from './eval-result';
4
4
  export { EvalState } from './eval-state';
5
5
  export { EvalLookup } from './eval-lookup';
6
+ export { defaultParserOptions } from './parser-options';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zvenigora/ng-eval-core",
3
- "version": "0.1.104",
3
+ "version": "0.1.105",
4
4
  "description": "An expression evaluator for Angular",
5
5
  "repository": {
6
6
  "type": "git",