@zvenigora/ng-eval-core 0.1.105 → 0.1.106

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,6 +1,7 @@
1
1
  import { Context, Registry, Stack } from '../common';
2
2
  import { EvalLookup } from './eval-lookup';
3
3
  import { EvalOptions } from './eval-options';
4
+ import { EvalScope } from './eval-scope';
4
5
  /**
5
6
  * Represents the evaluation context for the code execution.
6
7
  */
@@ -18,7 +19,7 @@ export declare class EvalContext {
18
19
  /**
19
20
  * Gets the scopes registry.
20
21
  */
21
- get priorScopes(): Readonly<Context[]>;
22
+ get priorScopes(): EvalScope[];
22
23
  /**
23
24
  * Gets the scopes registry.
24
25
  */
@@ -82,4 +83,11 @@ export declare class EvalContext {
82
83
  * Pops a context from the scope stack.
83
84
  */
84
85
  pop(): void;
86
+ /**
87
+ * Converts the EvalContext instance to an object representation.
88
+ * If the original value is an instance of Registry, it converts it to an object using the toObject method of the registry.
89
+ * If the original value is an object, it returns the original object.
90
+ * @returns The object representation of the EvalContext instance.
91
+ */
92
+ toObject(): Record<string | number | symbol, unknown> | undefined;
85
93
  }
@@ -1,6 +1,7 @@
1
- import { Registry, Stack } from "../common";
1
+ import { Stack } from "../common";
2
2
  import { EvalContext } from "./eval-context";
3
3
  import { EvalOptions } from "./eval-options";
4
+ import { EvalTrace } from "./eval-trace";
4
5
  type UnknownValue = unknown | Promise<unknown>;
5
6
  /**
6
7
  * Represents the result of an evaluation.
@@ -17,10 +18,11 @@ export declare class EvalResult {
17
18
  private _context;
18
19
  private _startDate?;
19
20
  private _endDate?;
21
+ private _expression?;
20
22
  /**
21
23
  * Gets the stack of evaluated values.
22
24
  */
23
- get stack(): Readonly<Stack<UnknownValue>>;
25
+ get stack(): Stack<UnknownValue>;
24
26
  /**
25
27
  * Gets the evaluated value.
26
28
  */
@@ -48,7 +50,7 @@ export declare class EvalResult {
48
50
  /**
49
51
  * Gets the trace of evaluated values.
50
52
  */
51
- get trace(): Readonly<Registry<unknown, UnknownValue>>;
53
+ get trace(): EvalTrace;
52
54
  /**
53
55
  * Gets the evaluation context.
54
56
  */
@@ -62,6 +64,17 @@ export declare class EvalResult {
62
64
  * @returns The duration in milliseconds.
63
65
  */
64
66
  get duration(): number | undefined;
67
+ /**
68
+ * Gets the expression associated with the evaluation result.
69
+ * @returns The expression as a string, or undefined if no expression is associated.
70
+ */
71
+ get expression(): string | undefined;
72
+ /**
73
+ * Sets the expression for the evaluation result.
74
+ *
75
+ * @param value - The expression to be set.
76
+ */
77
+ set expression(value: string | undefined);
65
78
  /**
66
79
  * Creates a new instance of EvalResult.
67
80
  * @param trace The trace of evaluated values.
@@ -0,0 +1,51 @@
1
+ import { Context } from "../common";
2
+ export interface EvalScopeOptions {
3
+ global?: boolean;
4
+ caseInsensitive?: boolean;
5
+ namespace?: string;
6
+ thisArg?: unknown;
7
+ }
8
+ /**
9
+ * Represents an evaluation scope.
10
+ */
11
+ export declare class EvalScope {
12
+ type: string;
13
+ private _context;
14
+ private _options;
15
+ /**
16
+ * Gets the context of the evaluation scope.
17
+ * @returns The context object.
18
+ */
19
+ get context(): Context;
20
+ /**
21
+ * Gets the options for evaluating the scope.
22
+ * @returns The evaluation options.
23
+ */
24
+ get options(): EvalScopeOptions;
25
+ /**
26
+ * Creates a new instance of EvalScope.
27
+ * @param context - The context of the evaluation scope.
28
+ * @param options - The options for evaluating the scope.
29
+ */
30
+ constructor(context?: Context, options?: EvalScopeOptions);
31
+ /**
32
+ * Creates an instance of EvalScope from the given context and options.
33
+ *
34
+ * @param context - The context object.
35
+ * @param options - The options object.
36
+ * @returns An instance of EvalScope.
37
+ */
38
+ static fromObject(context?: Context, options?: EvalScopeOptions): EvalScope;
39
+ /**
40
+ * Gets the value of the specified key.
41
+ * @param key - The key to retrieve the value for.
42
+ * @returns The value of the specified key, or undefined if the key is not found.
43
+ */
44
+ get(key: unknown): unknown | undefined;
45
+ /**
46
+ * Sets the value of the specified key.
47
+ * @param key - The key to set the value for.
48
+ * @param value - The value to set.
49
+ */
50
+ set(key: string, value: unknown): void;
51
+ }
@@ -13,19 +13,19 @@ export declare class EvalState {
13
13
  /**
14
14
  * Gets the evaluation context.
15
15
  */
16
- get context(): Readonly<EvalContext | undefined>;
16
+ get context(): EvalContext | undefined;
17
17
  /**
18
18
  * Gets the evaluation result.
19
19
  */
20
- get result(): Readonly<EvalResult>;
20
+ get result(): EvalResult;
21
21
  /**
22
22
  * Gets the evaluation options.
23
23
  */
24
- get options(): Readonly<EvalOptions | undefined>;
24
+ get options(): EvalOptions | undefined;
25
25
  /**
26
26
  * Gets whether the evaluation is asynchronous.
27
27
  */
28
- get isAsync(): Readonly<boolean | undefined>;
28
+ get isAsync(): boolean | undefined;
29
29
  /**
30
30
  * Represents the state of an evaluation.
31
31
  * @param context The evaluation context.
@@ -0,0 +1,20 @@
1
+ import { AnyNode } from "acorn";
2
+ export interface EvalTraceItem {
3
+ start?: number;
4
+ end?: number;
5
+ type: string;
6
+ expression?: string;
7
+ value: unknown;
8
+ }
9
+ /**
10
+ * Represents a trace of evaluation for a specific code execution.
11
+ */
12
+ export declare class EvalTrace extends Array<EvalTraceItem> {
13
+ /**
14
+ * Adds a new trace item to the evaluation trace.
15
+ * @param node - The AST node associated with the trace item.
16
+ * @param value - The value of the evaluated expression.
17
+ * @param expression - The expression being evaluated.
18
+ */
19
+ add(node: AnyNode, value?: unknown, expression?: string): void;
20
+ }
@@ -4,3 +4,5 @@ export { EvalResult } from './eval-result';
4
4
  export { EvalState } from './eval-state';
5
5
  export { EvalLookup } from './eval-lookup';
6
6
  export { defaultParserOptions } from './parser-options';
7
+ export { EvalTraceItem, EvalTrace } from './eval-trace';
8
+ export { EvalScope, EvalScopeOptions } from './eval-scope';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zvenigora/ng-eval-core",
3
- "version": "0.1.105",
3
+ "version": "0.1.106",
4
4
  "description": "An expression evaluator for Angular",
5
5
  "repository": {
6
6
  "type": "git",