@zvenigora/ng-eval-core 0.1.102

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.
Files changed (141) hide show
  1. package/README.md +9 -0
  2. package/esm2022/index.mjs +2 -0
  3. package/esm2022/lib/actual/services/base-eval.mjs +19 -0
  4. package/esm2022/lib/actual/services/compiler.service.mjs +142 -0
  5. package/esm2022/lib/actual/services/discovery.service.mjs +75 -0
  6. package/esm2022/lib/actual/services/eval.service.mjs +99 -0
  7. package/esm2022/lib/actual/services/index.mjs +2 -0
  8. package/esm2022/lib/actual/services/parser.service.mjs +91 -0
  9. package/esm2022/lib/actual/services/public-api.mjs +5 -0
  10. package/esm2022/lib/internal/classes/common/base-registry.mjs +119 -0
  11. package/esm2022/lib/internal/classes/common/cache.mjs +132 -0
  12. package/esm2022/lib/internal/classes/common/case-insensitive-registry.mjs +138 -0
  13. package/esm2022/lib/internal/classes/common/context.mjs +62 -0
  14. package/esm2022/lib/internal/classes/common/index.mjs +2 -0
  15. package/esm2022/lib/internal/classes/common/public-api.mjs +10 -0
  16. package/esm2022/lib/internal/classes/common/queue.mjs +42 -0
  17. package/esm2022/lib/internal/classes/common/registry.mjs +110 -0
  18. package/esm2022/lib/internal/classes/common/scope-registry.mjs +116 -0
  19. package/esm2022/lib/internal/classes/common/scope.mjs +55 -0
  20. package/esm2022/lib/internal/classes/common/stack.mjs +59 -0
  21. package/esm2022/lib/internal/classes/eval/eval-context.mjs +155 -0
  22. package/esm2022/lib/internal/classes/eval/eval-lookup.mjs +2 -0
  23. package/esm2022/lib/internal/classes/eval/eval-options.mjs +42 -0
  24. package/esm2022/lib/internal/classes/eval/eval-result.mjs +125 -0
  25. package/esm2022/lib/internal/classes/eval/eval-state.mjs +59 -0
  26. package/esm2022/lib/internal/classes/eval/index.mjs +2 -0
  27. package/esm2022/lib/internal/classes/eval/public-api.mjs +4 -0
  28. package/esm2022/lib/internal/functions/compile.mjs +41 -0
  29. package/esm2022/lib/internal/functions/evaluate.mjs +42 -0
  30. package/esm2022/lib/internal/functions/extract.mjs +20 -0
  31. package/esm2022/lib/internal/functions/index.mjs +2 -0
  32. package/esm2022/lib/internal/functions/parse.mjs +31 -0
  33. package/esm2022/lib/internal/functions/public-api.mjs +5 -0
  34. package/esm2022/lib/internal/interfaces/cache-type.mjs +2 -0
  35. package/esm2022/lib/internal/interfaces/index.mjs +2 -0
  36. package/esm2022/lib/internal/interfaces/parser-types.mjs +2 -0
  37. package/esm2022/lib/internal/interfaces/public-api.mjs +3 -0
  38. package/esm2022/lib/internal/interfaces/queue-type.mjs +2 -0
  39. package/esm2022/lib/internal/interfaces/recursive-visitors.mjs +6 -0
  40. package/esm2022/lib/internal/interfaces/registry-type.mjs +2 -0
  41. package/esm2022/lib/internal/interfaces/scope-type.mjs +2 -0
  42. package/esm2022/lib/internal/interfaces/stack-type.mjs +2 -0
  43. package/esm2022/lib/internal/public-api.mjs +3 -0
  44. package/esm2022/lib/internal/visitors/after-visitor.mjs +10 -0
  45. package/esm2022/lib/internal/visitors/array-expression.mjs +29 -0
  46. package/esm2022/lib/internal/visitors/arrow-function-expression.mjs +18 -0
  47. package/esm2022/lib/internal/visitors/assignment-expression.mjs +50 -0
  48. package/esm2022/lib/internal/visitors/await-expression.mjs +14 -0
  49. package/esm2022/lib/internal/visitors/before-visitor.mjs +10 -0
  50. package/esm2022/lib/internal/visitors/binary-expression.mjs +37 -0
  51. package/esm2022/lib/internal/visitors/call-expression.mjs +36 -0
  52. package/esm2022/lib/internal/visitors/conditional-expression.mjs +18 -0
  53. package/esm2022/lib/internal/visitors/identifier.mjs +11 -0
  54. package/esm2022/lib/internal/visitors/index.mjs +2 -0
  55. package/esm2022/lib/internal/visitors/literal.mjs +10 -0
  56. package/esm2022/lib/internal/visitors/logical-expression.mjs +26 -0
  57. package/esm2022/lib/internal/visitors/member-expression.mjs +32 -0
  58. package/esm2022/lib/internal/visitors/new-expression.mjs +21 -0
  59. package/esm2022/lib/internal/visitors/object-expression.mjs +53 -0
  60. package/esm2022/lib/internal/visitors/pattern.mjs +132 -0
  61. package/esm2022/lib/internal/visitors/public-api.mjs +24 -0
  62. package/esm2022/lib/internal/visitors/recursive-visitors.mjs +28 -0
  63. package/esm2022/lib/internal/visitors/tagged-template-expression.mjs +20 -0
  64. package/esm2022/lib/internal/visitors/template-literal.mjs +21 -0
  65. package/esm2022/lib/internal/visitors/this-expression.mjs +10 -0
  66. package/esm2022/lib/internal/visitors/unary-expression.mjs +19 -0
  67. package/esm2022/lib/internal/visitors/update-expression.mjs +26 -0
  68. package/esm2022/lib/internal/visitors/visitor-result.mjs +29 -0
  69. package/esm2022/public-api.mjs +6 -0
  70. package/esm2022/zvenigora-ng-eval-core.mjs +5 -0
  71. package/fesm2022/zvenigora-ng-eval-core.mjs +2300 -0
  72. package/fesm2022/zvenigora-ng-eval-core.mjs.map +1 -0
  73. package/index.d.ts +1 -0
  74. package/lib/actual/services/base-eval.d.ts +16 -0
  75. package/lib/actual/services/compiler.service.d.ts +57 -0
  76. package/lib/actual/services/discovery.service.d.ts +33 -0
  77. package/lib/actual/services/eval.service.d.ts +41 -0
  78. package/lib/actual/services/index.d.ts +1 -0
  79. package/lib/actual/services/parser.service.d.ts +36 -0
  80. package/lib/actual/services/public-api.d.ts +4 -0
  81. package/lib/internal/classes/common/base-registry.d.ts +78 -0
  82. package/lib/internal/classes/common/cache.d.ts +91 -0
  83. package/lib/internal/classes/common/case-insensitive-registry.d.ts +79 -0
  84. package/lib/internal/classes/common/context.d.ts +31 -0
  85. package/lib/internal/classes/common/index.d.ts +1 -0
  86. package/lib/internal/classes/common/public-api.d.ts +9 -0
  87. package/lib/internal/classes/common/queue.d.ts +33 -0
  88. package/lib/internal/classes/common/registry.d.ts +80 -0
  89. package/lib/internal/classes/common/scope-registry.d.ts +83 -0
  90. package/lib/internal/classes/common/scope.d.ts +30 -0
  91. package/lib/internal/classes/common/stack.d.ts +43 -0
  92. package/lib/internal/classes/eval/eval-context.d.ts +78 -0
  93. package/lib/internal/classes/eval/eval-lookup.d.ts +2 -0
  94. package/lib/internal/classes/eval/eval-options.d.ts +6 -0
  95. package/lib/internal/classes/eval/eval-result.d.ts +92 -0
  96. package/lib/internal/classes/eval/eval-state.d.ts +46 -0
  97. package/lib/internal/classes/eval/index.d.ts +1 -0
  98. package/lib/internal/classes/eval/public-api.d.ts +5 -0
  99. package/lib/internal/functions/compile.d.ts +33 -0
  100. package/lib/internal/functions/evaluate.d.ts +17 -0
  101. package/lib/internal/functions/extract.d.ts +10 -0
  102. package/lib/internal/functions/index.d.ts +1 -0
  103. package/lib/internal/functions/parse.d.ts +15 -0
  104. package/lib/internal/functions/public-api.d.ts +4 -0
  105. package/lib/internal/interfaces/cache-type.d.ts +6 -0
  106. package/lib/internal/interfaces/index.d.ts +1 -0
  107. package/lib/internal/interfaces/parser-types.d.ts +7 -0
  108. package/lib/internal/interfaces/public-api.d.ts +7 -0
  109. package/lib/internal/interfaces/queue-type.d.ts +6 -0
  110. package/lib/internal/interfaces/recursive-visitors.d.ts +43 -0
  111. package/lib/internal/interfaces/registry-type.d.ts +73 -0
  112. package/lib/internal/interfaces/scope-type.d.ts +15 -0
  113. package/lib/internal/interfaces/stack-type.d.ts +6 -0
  114. package/lib/internal/public-api.d.ts +2 -0
  115. package/lib/internal/visitors/after-visitor.d.ts +3 -0
  116. package/lib/internal/visitors/array-expression.d.ts +5 -0
  117. package/lib/internal/visitors/arrow-function-expression.d.ts +4 -0
  118. package/lib/internal/visitors/assignment-expression.d.ts +4 -0
  119. package/lib/internal/visitors/await-expression.d.ts +4 -0
  120. package/lib/internal/visitors/before-visitor.d.ts +3 -0
  121. package/lib/internal/visitors/binary-expression.d.ts +4 -0
  122. package/lib/internal/visitors/call-expression.d.ts +5 -0
  123. package/lib/internal/visitors/conditional-expression.d.ts +4 -0
  124. package/lib/internal/visitors/identifier.d.ts +3 -0
  125. package/lib/internal/visitors/index.d.ts +1 -0
  126. package/lib/internal/visitors/literal.d.ts +3 -0
  127. package/lib/internal/visitors/logical-expression.d.ts +4 -0
  128. package/lib/internal/visitors/member-expression.d.ts +5 -0
  129. package/lib/internal/visitors/new-expression.d.ts +5 -0
  130. package/lib/internal/visitors/object-expression.d.ts +4 -0
  131. package/lib/internal/visitors/pattern.d.ts +6 -0
  132. package/lib/internal/visitors/public-api.d.ts +23 -0
  133. package/lib/internal/visitors/recursive-visitors.d.ts +7 -0
  134. package/lib/internal/visitors/tagged-template-expression.d.ts +4 -0
  135. package/lib/internal/visitors/template-literal.d.ts +4 -0
  136. package/lib/internal/visitors/this-expression.d.ts +3 -0
  137. package/lib/internal/visitors/unary-expression.d.ts +4 -0
  138. package/lib/internal/visitors/update-expression.d.ts +4 -0
  139. package/lib/internal/visitors/visitor-result.d.ts +6 -0
  140. package/package.json +40 -0
  141. package/public-api.d.ts +5 -0
@@ -0,0 +1,92 @@
1
+ import { Registry, Stack } from "../common";
2
+ import { EvalContext } from "./eval-context";
3
+ import { EvalOptions } from "./eval-options";
4
+ type UnknownValue = unknown | Promise<unknown>;
5
+ /**
6
+ * Represents the result of an evaluation.
7
+ */
8
+ export declare class EvalResult {
9
+ private _stack;
10
+ private _value?;
11
+ private _error?;
12
+ private _errorMessage?;
13
+ private _isError?;
14
+ private _isSuccess?;
15
+ private _isUndefined?;
16
+ private _trace;
17
+ private _context;
18
+ private _startDate?;
19
+ private _endDate?;
20
+ /**
21
+ * Gets the stack of evaluated values.
22
+ */
23
+ get stack(): Readonly<Stack<UnknownValue>>;
24
+ /**
25
+ * Gets the evaluated value.
26
+ */
27
+ get value(): UnknownValue | undefined;
28
+ /**
29
+ * Gets the error that occurred during evaluation.
30
+ */
31
+ get error(): unknown | undefined;
32
+ /**
33
+ * Gets the error message associated with the evaluation error.
34
+ */
35
+ get errorMessage(): string | undefined;
36
+ /**
37
+ * Gets whether the evaluation resulted in an error.
38
+ */
39
+ get isError(): boolean | undefined;
40
+ /**
41
+ * Gets whether the evaluation was successful.
42
+ */
43
+ get isSuccess(): boolean | undefined;
44
+ /**
45
+ * Gets whether the evaluated value is undefined.
46
+ */
47
+ get isUndefined(): boolean | undefined;
48
+ /**
49
+ * Gets the trace of evaluated values.
50
+ */
51
+ get trace(): Readonly<Registry<unknown, UnknownValue>>;
52
+ /**
53
+ * Gets the evaluation context.
54
+ */
55
+ get context(): EvalContext;
56
+ /**
57
+ * Gets the evaluation options.
58
+ */
59
+ get options(): EvalOptions;
60
+ /**
61
+ * Gets the duration of the evaluation result.
62
+ * @returns The duration in milliseconds.
63
+ */
64
+ get duration(): number | undefined;
65
+ /**
66
+ * Creates a new instance of EvalResult.
67
+ * @param trace The trace of evaluated values.
68
+ * @param context The evaluation context.
69
+ */
70
+ constructor(context: EvalContext);
71
+ /**
72
+ * Starts the evaluation process.
73
+ */
74
+ start(): void;
75
+ /**
76
+ * Stops the evaluation and records the end date.
77
+ */
78
+ stop(): number | undefined;
79
+ /**
80
+ * Sets the success value of the evaluation result.
81
+ *
82
+ * @param value The value to set as the success value.
83
+ * @returns void
84
+ */
85
+ setSuccess(value: UnknownValue): void;
86
+ /**
87
+ * Sets the failure state of the evaluation result.
88
+ * @param error The error object associated with the failure.
89
+ */
90
+ setFailure(error: unknown): void;
91
+ }
92
+ export {};
@@ -0,0 +1,46 @@
1
+ import { EvalContext } from './eval-context';
2
+ import { EvalOptions } from './eval-options';
3
+ import { EvalResult } from './eval-result';
4
+ import { Context } from '../common';
5
+ /**
6
+ * Represents the evaluation state, which includes the context, result, and options.
7
+ */
8
+ export declare class EvalState {
9
+ private _context;
10
+ private _result;
11
+ private _options;
12
+ private _isAsync;
13
+ /**
14
+ * Gets the evaluation context.
15
+ */
16
+ get context(): Readonly<EvalContext | undefined>;
17
+ /**
18
+ * Gets the evaluation result.
19
+ */
20
+ get result(): Readonly<EvalResult>;
21
+ /**
22
+ * Gets the evaluation options.
23
+ */
24
+ get options(): Readonly<EvalOptions | undefined>;
25
+ /**
26
+ * Gets whether the evaluation is asynchronous.
27
+ */
28
+ get isAsync(): Readonly<boolean | undefined>;
29
+ /**
30
+ * Represents the state of an evaluation.
31
+ * @param context The evaluation context.
32
+ * @param result The evaluation result.
33
+ * @param options The evaluation options.
34
+ * @param isAsync Indicates whether the evaluation is asynchronous.
35
+ */
36
+ constructor(context: EvalContext | undefined, result: EvalResult, options?: EvalOptions, isAsync?: boolean);
37
+ /**
38
+ * Creates an instance of EvalState from a given context, options, and async flag.
39
+ *
40
+ * @param context - The evaluation context or context object.
41
+ * @param options - The evaluation options.
42
+ * @param isAsync - A flag indicating whether the evaluation is asynchronous.
43
+ * @returns The created EvalState instance.
44
+ */
45
+ static fromContext(context?: EvalContext | Context, options?: EvalOptions, isAsync?: boolean): EvalState;
46
+ }
@@ -0,0 +1 @@
1
+ export * from './public-api';
@@ -0,0 +1,5 @@
1
+ export { EvalOptions } from './eval-options';
2
+ export { EvalContext } from './eval-context';
3
+ export { EvalResult } from './eval-result';
4
+ export { EvalState } from './eval-state';
5
+ export { EvalLookup } from './eval-lookup';
@@ -0,0 +1,33 @@
1
+ import { AnyNode } from 'acorn';
2
+ import { EvalState } from '../classes/eval';
3
+ export type stateCallback = (state: EvalState) => unknown;
4
+ export type stateCallbackAsync = (state: EvalState) => Promise<unknown | undefined>;
5
+ /**
6
+ * Compiles the given node and returns a function that can be used to evaluate it.
7
+ *
8
+ * @param node The node to compile.
9
+ * @returns A function that takes an `EvalState` and returns the result of evaluating the node.
10
+ */
11
+ export declare const compile: (node: AnyNode | undefined) => stateCallback;
12
+ /**
13
+ * Compiles the given node asynchronously.
14
+ *
15
+ * @param node - The node to compile.
16
+ * @returns A function that takes an `EvalState` object and returns a `Promise` that resolves to the compiled result.
17
+ */
18
+ export declare const compileAsync: (node: AnyNode | undefined) => stateCallbackAsync;
19
+ /**
20
+ * Calls the provided function with the given state and returns the result.
21
+ *
22
+ * @param fn The function to be called.
23
+ * @param state The state to be passed to the function.
24
+ * @returns The result of calling the function.
25
+ */
26
+ export declare const call: (fn: stateCallback, state: EvalState) => unknown | undefined;
27
+ /**
28
+ * Calls an asynchronous function with the given state and returns a promise that resolves to the result.
29
+ * @param fn The asynchronous function to call.
30
+ * @param state The state to pass to the function.
31
+ * @returns A promise that resolves to the result of the function.
32
+ */
33
+ export declare const callAsync: (fn: stateCallbackAsync, state: EvalState) => Promise<unknown | undefined>;
@@ -0,0 +1,17 @@
1
+ import { EvalState } from '../classes/eval';
2
+ import { AnyNode } from 'acorn';
3
+ /**
4
+ * Evaluates the given node and returns the result.
5
+ *
6
+ * @param node The node to evaluate.
7
+ * @param state The evaluation state.
8
+ * @returns The result of the evaluation.
9
+ */
10
+ export declare const evaluate: (node: AnyNode | undefined, state: EvalState) => unknown | undefined;
11
+ /**
12
+ * Asynchronously evaluates the given abstract syntax tree (AST) using the provided evaluation state.
13
+ * @param ast The abstract syntax tree to evaluate.
14
+ * @param state The evaluation state.
15
+ * @returns A promise that resolves to the evaluated value or undefined.
16
+ */
17
+ export declare const evaluateAsync: (ast: AnyNode | undefined, state: EvalState) => Promise<unknown | undefined>;
@@ -0,0 +1,10 @@
1
+ import { AnyNode } from 'acorn';
2
+ import { AnyNodeTypes } from '../interfaces';
3
+ /**
4
+ * Finds all nodes of a specific type in the given AST.
5
+ *
6
+ * @param ast The AST to search in.
7
+ * @param searchType The type of nodes to search for.
8
+ * @returns An array of nodes of the specified type if found, otherwise undefined.
9
+ */
10
+ export declare const extract: (node: AnyNode | undefined, searchType: AnyNodeTypes) => AnyNode[] | undefined;
@@ -0,0 +1 @@
1
+ export * from './public-api';
@@ -0,0 +1,15 @@
1
+ import { AnyNode, Expression, Program } from "acorn";
2
+ import { ParserOptions } from "../interfaces";
3
+ /**
4
+ * @description
5
+ * Parses expression and returns ES6/ES2020 AST.
6
+ * @param expr expression to parse
7
+ * @param options parser options
8
+ */
9
+ export declare const parse: (expr: string, options: ParserOptions) => Program | AnyNode | undefined;
10
+ /**
11
+ * @description
12
+ * Walks through the AST and extracts first expression.
13
+ * @param expr expression to parse
14
+ */
15
+ export declare const extractExpression: (program: Program) => Expression | undefined;
@@ -0,0 +1,4 @@
1
+ export { parse, extractExpression } from './parse';
2
+ export { evaluate, evaluateAsync } from './evaluate';
3
+ export { compile, compileAsync, stateCallback, stateCallbackAsync, call, callAsync } from './compile';
4
+ export { extract } from './extract';
@@ -0,0 +1,6 @@
1
+ import { RegistryType } from "../public-api";
2
+ export interface CacheType<TValue> extends RegistryType<string, TValue> {
3
+ type: Readonly<'Cache' | string>;
4
+ maxCacheSize: number;
5
+ getHashKey: (namespace: string, value: string) => string;
6
+ }
@@ -0,0 +1 @@
1
+ export * from './public-api';
@@ -0,0 +1,7 @@
1
+ import * as acorn from 'acorn';
2
+ export type ParserOptions = Partial<acorn.Options> & {
3
+ extractExpressions?: boolean;
4
+ cacheSize?: number;
5
+ ecmaVersion?: acorn.ecmaVersion;
6
+ };
7
+ export type AnyNodeTypes = acorn.AnyNode['type'];
@@ -0,0 +1,7 @@
1
+ export * from './parser-types';
2
+ export { RegistryType, ScopeRegistryOptions, RegistryEntries } from './registry-type';
3
+ export { StackType } from './stack-type';
4
+ export { QueueType } from './queue-type';
5
+ export { ScopeType, RegistryOptionType, ScopeOptions } from './scope-type';
6
+ export { CacheType } from './cache-type';
7
+ export { RecursiveVisitorState, RecursiveVisitorOptions, RecursiveVisitorContext, RecursiveVisitorResultType, RecursiveVisitorResult, RecursiveVisitorStackResult, RecursiveVisitorRegistryResult, RecursiveVisitor, RecursiveAggregateVisitor, AggregateType } from './recursive-visitors';
@@ -0,0 +1,6 @@
1
+ export interface QueueType<T> {
2
+ length: number;
3
+ dequeue(): T | undefined;
4
+ enqueue(value: T): number;
5
+ peek(): T;
6
+ }
@@ -0,0 +1,43 @@
1
+ import { WalkerCallback } from 'acorn-walk';
2
+ import * as acorn from 'acorn';
3
+ import { StackType } from './stack-type';
4
+ import { AnyNode } from 'acorn';
5
+ import { RegistryType } from './registry-type';
6
+ import { AnyNodeTypes } from './parser-types';
7
+ import { BaseRegistry, Registry } from '../public-api';
8
+ export interface RecursiveVisitorState {
9
+ scope: Registry<unknown, unknown>;
10
+ result: RecursiveVisitorResult<unknown | undefined>;
11
+ option: RecursiveVisitorOptions;
12
+ beforeVisitors?: RegistryType<AnyNodeTypes, (node: AnyNode, st: RecursiveVisitorState) => number | undefined>;
13
+ afterVisitors?: RegistryType<AnyNodeTypes, (node: AnyNode, st: RecursiveVisitorState) => number | undefined>;
14
+ }
15
+ export interface RecursiveVisitorOptions {
16
+ trackTime?: boolean;
17
+ resultType?: 'stack' | 'registry';
18
+ }
19
+ export interface RecursiveVisitorContext {
20
+ }
21
+ export declare enum RecursiveVisitorResultType {
22
+ Stack = 0,
23
+ Registry = 1
24
+ }
25
+ export type RecursiveVisitorResult<TValue> = RecursiveVisitorStackResult<TValue> | RecursiveVisitorRegistryResult<TValue>;
26
+ export interface RecursiveVisitorStackResult<TValue> {
27
+ type: 'stack';
28
+ stack: StackType<TValue>;
29
+ }
30
+ export interface RecursiveVisitorRegistryResult<TValue> {
31
+ type: 'registry';
32
+ registry: BaseRegistry<AnyNode, TValue>;
33
+ }
34
+ export type AggregateType = {
35
+ Expression: acorn.Expression;
36
+ Statement: acorn.Statement;
37
+ Function: acorn.Function;
38
+ Class: acorn.Class;
39
+ Pattern: acorn.Pattern;
40
+ ForInit: acorn.VariableDeclaration | acorn.Expression;
41
+ };
42
+ export type RecursiveVisitor<TState> = (node: acorn.AnyNode, state: TState, callback: WalkerCallback<TState>) => void;
43
+ export type RecursiveAggregateVisitor<TState> = (node: AggregateType, state: TState, callback: WalkerCallback<TState>) => void;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Represents a registry that stores key-value pairs.
3
+ * @template TKey - The type of the keys in the registry.
4
+ * @template TValue - The type of the values in the registry.
5
+ */
6
+ export interface RegistryType<TKey, TValue> extends Iterable<[TKey, TValue]> {
7
+ type: Readonly<'Registry' | string>;
8
+ options: Readonly<{
9
+ caseInsensitive: boolean;
10
+ } | Record<string, unknown>>;
11
+ /**
12
+ * Retrieves the value associated with the specified key.
13
+ * @param key - The key to retrieve the value for.
14
+ * @returns The value associated with the key, or undefined if the key does not exist.
15
+ */
16
+ get(key: TKey): TValue | undefined;
17
+ /**
18
+ * Sets the value for the specified key.
19
+ * @param key - The key to set the value for.
20
+ * @param value - The value to set.
21
+ */
22
+ set(key: TKey, value: TValue): void;
23
+ /**
24
+ * Checks if the registry contains the specified key.
25
+ * @param key - The key to check.
26
+ * @returns True if the registry contains the key, false otherwise.
27
+ */
28
+ has(key: TKey): boolean;
29
+ /**
30
+ * Deletes the key-value pair associated with the specified key.
31
+ * @param key - The key to delete.
32
+ * @returns True if the key-value pair was deleted, false if the key does not exist.
33
+ */
34
+ delete(key: TKey): boolean;
35
+ /**
36
+ * Clears all key-value pairs from the registry.
37
+ */
38
+ clear(): void;
39
+ /**
40
+ * Gets the number of key-value pairs in the registry.
41
+ */
42
+ readonly size: number;
43
+ /**
44
+ * Gets an iterator for the keys in the registry.
45
+ */
46
+ readonly keys: IterableIterator<TKey>;
47
+ /**
48
+ * Gets an iterator for the values in the registry.
49
+ */
50
+ readonly values: IterableIterator<TValue>;
51
+ /**
52
+ * Gets an iterator for the key-value pairs in the registry.
53
+ */
54
+ readonly entries: IterableIterator<[TKey, TValue]>;
55
+ /**
56
+ * Executes a provided function once for each key-value pair in the registry.
57
+ * @param callbackfn - The function to execute for each key-value pair.
58
+ * @param thisArg - Optional value to use as `this` when executing the callback function.
59
+ */
60
+ forEach(callbackfn: (value: TValue, key: TKey, map: Map<TKey, TValue>) => void, thisArg?: unknown): void;
61
+ /**
62
+ * Returns an iterator for the entries of the registry.
63
+ * @returns An iterator that yields key-value pairs of type [TKey, unknown].
64
+ */
65
+ [Symbol.iterator](): IterableIterator<[TKey, TValue]>;
66
+ }
67
+ export interface ScopeRegistryOptions {
68
+ caseInsensitive: boolean;
69
+ global: boolean;
70
+ namespace: string;
71
+ thisArg: unknown;
72
+ }
73
+ export type RegistryEntries<TKey, TValue> = [TKey, TValue][] | Record<string | number | symbol, TValue>;
@@ -0,0 +1,15 @@
1
+ import { RegistryType } from "./registry-type";
2
+ export interface ScopeOptions {
3
+ global?: boolean;
4
+ caseInsensitive?: boolean;
5
+ namespace?: string;
6
+ }
7
+ export interface RegistryOptionType<TKey, TValue> {
8
+ registry: Readonly<RegistryType<TKey, TValue>>;
9
+ options: Readonly<ScopeOptions>;
10
+ }
11
+ export interface ScopeType<TKey, TValue> {
12
+ registries: RegistryOptionType<TKey, TValue>[];
13
+ add: (registry: RegistryOptionType<TKey, TValue>) => void;
14
+ get: (key: TKey, namespace?: string) => [TKey, TValue] | undefined;
15
+ }
@@ -0,0 +1,6 @@
1
+ export interface StackType<T> {
2
+ peek(): T;
3
+ pop(): T | undefined;
4
+ push(value: T): number;
5
+ swap(): void;
6
+ }
@@ -0,0 +1,2 @@
1
+ export * from './classes/common';
2
+ export * from './interfaces';
@@ -0,0 +1,3 @@
1
+ import { AnyNode } from 'acorn';
2
+ import { EvalState } from '../classes/eval';
3
+ export declare const afterVisitor: (node: AnyNode, st: EvalState) => number | undefined;
@@ -0,0 +1,5 @@
1
+ import { AnyNode, ArrayExpression, Expression, SpreadElement } from 'acorn';
2
+ import * as walk from 'acorn-walk';
3
+ import { EvalState } from '../classes/eval';
4
+ export declare const arrayExpressionVisitor: (node: ArrayExpression, st: EvalState, callback: walk.WalkerCallback<EvalState>) => void;
5
+ export declare const evaluateArray: (node: AnyNode, items: Array<Expression | SpreadElement | null>, st: EvalState, callback: walk.WalkerCallback<EvalState>) => unknown[];
@@ -0,0 +1,4 @@
1
+ import { ArrowFunctionExpression } from 'acorn';
2
+ import * as walk from 'acorn-walk';
3
+ import { EvalState } from '../classes/eval';
4
+ export declare const arrowFunctionExpressionVisitor: (node: ArrowFunctionExpression, st: EvalState, callback: walk.WalkerCallback<EvalState>) => void;
@@ -0,0 +1,4 @@
1
+ import { AssignmentExpression } from 'acorn';
2
+ import * as walk from 'acorn-walk';
3
+ import { EvalState } from '../classes/eval';
4
+ export declare const assignmentExpressionVisitor: (node: AssignmentExpression, st: EvalState, callback: walk.WalkerCallback<EvalState>) => void;
@@ -0,0 +1,4 @@
1
+ import { AwaitExpression } from 'acorn';
2
+ import * as walk from 'acorn-walk';
3
+ import { EvalState } from '../classes/eval';
4
+ export declare const awaitVisitor: (node: AwaitExpression, st: EvalState, callback: walk.WalkerCallback<EvalState>) => void;
@@ -0,0 +1,3 @@
1
+ import { AnyNode } from 'acorn';
2
+ import { EvalState } from '../classes/eval';
3
+ export declare const beforeVisitor: (node: AnyNode, st: EvalState) => number | undefined;
@@ -0,0 +1,4 @@
1
+ import { BinaryExpression } from 'acorn';
2
+ import * as walk from 'acorn-walk';
3
+ import { EvalState } from '../classes/eval';
4
+ export declare const binaryExpressionVisitor: (node: BinaryExpression, st: EvalState, callback: walk.WalkerCallback<EvalState>) => void;
@@ -0,0 +1,5 @@
1
+ import { CallExpression } from 'acorn';
2
+ import * as walk from 'acorn-walk';
3
+ import { EvalState } from '../classes/eval';
4
+ export declare const callExpressionVisitor: (node: CallExpression, st: EvalState, callback: walk.WalkerCallback<EvalState>) => void;
5
+ export declare const evaluateCall: (node: CallExpression, st: EvalState, callback: walk.WalkerCallback<EvalState>) => unknown;
@@ -0,0 +1,4 @@
1
+ import { ConditionalExpression } from 'acorn';
2
+ import * as walk from 'acorn-walk';
3
+ import { EvalState } from '../classes/eval';
4
+ export declare const conditionalExpressionVisitor: (node: ConditionalExpression, st: EvalState, callback: walk.WalkerCallback<EvalState>) => void;
@@ -0,0 +1,3 @@
1
+ import { Identifier } from 'acorn';
2
+ import { EvalState } from '../classes/eval';
3
+ export declare const identifierVisitor: (node: Identifier, st: EvalState) => void;
@@ -0,0 +1 @@
1
+ export * from './public-api';
@@ -0,0 +1,3 @@
1
+ import { Literal } from 'acorn';
2
+ import { EvalState } from '../classes/eval';
3
+ export declare const literalVisitor: (node: Literal, st: EvalState) => void;
@@ -0,0 +1,4 @@
1
+ import { LogicalExpression } from 'acorn';
2
+ import * as walk from 'acorn-walk';
3
+ import { EvalState } from '../classes/eval';
4
+ export declare const logicalExpressionVisitor: (node: LogicalExpression, st: EvalState, callback: walk.WalkerCallback<EvalState>) => void;
@@ -0,0 +1,5 @@
1
+ import { MemberExpression } from 'acorn';
2
+ import * as walk from 'acorn-walk';
3
+ import { EvalState } from '../classes/eval';
4
+ export declare const memberExpressionVisitor: (node: MemberExpression, st: EvalState, callback: walk.WalkerCallback<EvalState>) => void;
5
+ export declare const evaluateMember: (node: MemberExpression, st: EvalState, callback: walk.WalkerCallback<EvalState>) => unknown[];
@@ -0,0 +1,5 @@
1
+ import { NewExpression } from 'acorn';
2
+ import * as walk from 'acorn-walk';
3
+ import { EvalState } from '../classes/eval';
4
+ export declare const newExpressionVisitor: (node: NewExpression, st: EvalState, callback: walk.WalkerCallback<EvalState>) => void;
5
+ export declare const newFunc: (constructor: (...a: unknown[]) => unknown, ...args: unknown[]) => any;
@@ -0,0 +1,4 @@
1
+ import { ObjectExpression } from 'acorn';
2
+ import * as walk from 'acorn-walk';
3
+ import { EvalState } from '../classes/eval';
4
+ export declare const objectExpressionVisitor: (node: ObjectExpression, st: EvalState, callback: walk.WalkerCallback<EvalState>) => void;
@@ -0,0 +1,6 @@
1
+ import { Pattern } from 'acorn';
2
+ import * as walk from 'acorn-walk';
3
+ import { EvalState } from '../classes/eval';
4
+ import { BaseContext } from '../classes/common';
5
+ export declare const evaluatePatterns: (patterns: Pattern[], st: EvalState, callback: walk.WalkerCallback<EvalState>, args: unknown[]) => BaseContext;
6
+ export declare const evaluatePattern: (pattern: Pattern, st: EvalState, callback: walk.WalkerCallback<EvalState>, arg: unknown) => BaseContext;
@@ -0,0 +1,23 @@
1
+ export { pushVisitorResult, popVisitorResult, pushVisitorResultAsync, popVisitorResultAsync } from './visitor-result';
2
+ export { beforeVisitor } from './before-visitor';
3
+ export { afterVisitor } from './after-visitor';
4
+ export { identifierVisitor } from './identifier';
5
+ export { literalVisitor } from './literal';
6
+ export { binaryExpressionVisitor } from './binary-expression';
7
+ export { callExpressionVisitor } from './call-expression';
8
+ export { awaitVisitor } from './await-expression';
9
+ export { conditionalExpressionVisitor } from './conditional-expression';
10
+ export { memberExpressionVisitor, evaluateMember } from './member-expression';
11
+ export { arrayExpressionVisitor, evaluateArray } from './array-expression';
12
+ export { unaryExpressionVisitor } from './unary-expression';
13
+ export { logicalExpressionVisitor } from './logical-expression';
14
+ export { thisExpressionVisitor } from './this-expression';
15
+ export { newExpressionVisitor } from './new-expression';
16
+ export { templateLiteralVisitor } from './template-literal';
17
+ export { taggedTemplateExpressionVisitor } from './tagged-template-expression';
18
+ export { objectExpressionVisitor } from './object-expression';
19
+ export { getDefaultVisitors } from './recursive-visitors';
20
+ export { assignmentExpressionVisitor } from './assignment-expression';
21
+ export { updateExpressionVisitor } from './update-expression';
22
+ export { arrowFunctionExpressionVisitor } from './arrow-function-expression';
23
+ export { evaluatePattern, evaluatePatterns } from './pattern';
@@ -0,0 +1,7 @@
1
+ import { EvalState } from '../classes/eval';
2
+ import * as walk from 'acorn-walk';
3
+ /**
4
+ * Returns the default visitors for the recursive traversal of an abstract syntax tree.
5
+ * @returns The default visitors object.
6
+ */
7
+ export declare const getDefaultVisitors: () => walk.RecursiveVisitors<EvalState>;
@@ -0,0 +1,4 @@
1
+ import { TaggedTemplateExpression } from 'acorn';
2
+ import * as walk from 'acorn-walk';
3
+ import { EvalState } from '../classes/eval';
4
+ export declare const taggedTemplateExpressionVisitor: (node: TaggedTemplateExpression, st: EvalState, callback: walk.WalkerCallback<EvalState>) => void;
@@ -0,0 +1,4 @@
1
+ import { TemplateLiteral } from 'acorn';
2
+ import * as walk from 'acorn-walk';
3
+ import { EvalState } from '../classes/eval';
4
+ export declare const templateLiteralVisitor: (node: TemplateLiteral, st: EvalState, callback: walk.WalkerCallback<EvalState>) => void;
@@ -0,0 +1,3 @@
1
+ import { ThisExpression } from 'acorn';
2
+ import { EvalState } from '../classes/eval';
3
+ export declare const thisExpressionVisitor: (node: ThisExpression, st: EvalState) => void;
@@ -0,0 +1,4 @@
1
+ import { UnaryExpression } from 'acorn';
2
+ import * as walk from 'acorn-walk';
3
+ import { EvalState } from '../classes/eval';
4
+ export declare const unaryExpressionVisitor: (node: UnaryExpression, st: EvalState, callback: walk.WalkerCallback<EvalState>) => void;
@@ -0,0 +1,4 @@
1
+ import { UpdateExpression } from 'acorn';
2
+ import * as walk from 'acorn-walk';
3
+ import { EvalState } from '../classes/eval';
4
+ export declare const updateExpressionVisitor: (node: UpdateExpression, st: EvalState, callback: walk.WalkerCallback<EvalState>) => void;
@@ -0,0 +1,6 @@
1
+ import { AnyNode } from 'acorn';
2
+ import { EvalState } from '../classes/eval';
3
+ export declare const pushVisitorResult: (node: AnyNode, st: EvalState, value: unknown) => unknown;
4
+ export declare const popVisitorResult: (node: AnyNode, st: EvalState) => unknown;
5
+ export declare const pushVisitorResultAsync: (node: AnyNode, st: EvalState, value: Promise<unknown>) => Promise<unknown>;
6
+ export declare const popVisitorResultAsync: (node: AnyNode, st: EvalState) => Promise<unknown>;
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@zvenigora/ng-eval-core",
3
+ "version": "0.1.102",
4
+ "description": "An expression evaluator for Angular",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/zvenigora/ng-eval.git"
8
+ },
9
+ "keywords": [
10
+ "Angular",
11
+ "Eval"
12
+ ],
13
+ "author": "Zvenigora (https://github.com/zvenigora)",
14
+ "license": "MIT",
15
+ "homepage": "https://github.com/zvenigora#readme",
16
+ "peerDependencies": {
17
+ "@angular/common": "^17.0.0",
18
+ "@angular/core": "^17.0.0",
19
+ "acorn": "^8.11.2",
20
+ "acorn-walk": "^8.3.0",
21
+ "js-sha256": "^0.10.1"
22
+ },
23
+ "dependencies": {
24
+ "tslib": "^2.3.0"
25
+ },
26
+ "sideEffects": false,
27
+ "module": "fesm2022/zvenigora-ng-eval-core.mjs",
28
+ "typings": "index.d.ts",
29
+ "exports": {
30
+ "./package.json": {
31
+ "default": "./package.json"
32
+ },
33
+ ".": {
34
+ "types": "./index.d.ts",
35
+ "esm2022": "./esm2022/zvenigora-ng-eval-core.mjs",
36
+ "esm": "./esm2022/zvenigora-ng-eval-core.mjs",
37
+ "default": "./fesm2022/zvenigora-ng-eval-core.mjs"
38
+ }
39
+ }
40
+ }