@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.
- package/README.md +9 -0
- package/esm2022/index.mjs +2 -0
- package/esm2022/lib/actual/services/base-eval.mjs +19 -0
- package/esm2022/lib/actual/services/compiler.service.mjs +142 -0
- package/esm2022/lib/actual/services/discovery.service.mjs +75 -0
- package/esm2022/lib/actual/services/eval.service.mjs +99 -0
- package/esm2022/lib/actual/services/index.mjs +2 -0
- package/esm2022/lib/actual/services/parser.service.mjs +91 -0
- package/esm2022/lib/actual/services/public-api.mjs +5 -0
- package/esm2022/lib/internal/classes/common/base-registry.mjs +119 -0
- package/esm2022/lib/internal/classes/common/cache.mjs +132 -0
- package/esm2022/lib/internal/classes/common/case-insensitive-registry.mjs +138 -0
- package/esm2022/lib/internal/classes/common/context.mjs +62 -0
- package/esm2022/lib/internal/classes/common/index.mjs +2 -0
- package/esm2022/lib/internal/classes/common/public-api.mjs +10 -0
- package/esm2022/lib/internal/classes/common/queue.mjs +42 -0
- package/esm2022/lib/internal/classes/common/registry.mjs +110 -0
- package/esm2022/lib/internal/classes/common/scope-registry.mjs +116 -0
- package/esm2022/lib/internal/classes/common/scope.mjs +55 -0
- package/esm2022/lib/internal/classes/common/stack.mjs +59 -0
- package/esm2022/lib/internal/classes/eval/eval-context.mjs +155 -0
- package/esm2022/lib/internal/classes/eval/eval-lookup.mjs +2 -0
- package/esm2022/lib/internal/classes/eval/eval-options.mjs +42 -0
- package/esm2022/lib/internal/classes/eval/eval-result.mjs +125 -0
- package/esm2022/lib/internal/classes/eval/eval-state.mjs +59 -0
- package/esm2022/lib/internal/classes/eval/index.mjs +2 -0
- package/esm2022/lib/internal/classes/eval/public-api.mjs +4 -0
- package/esm2022/lib/internal/functions/compile.mjs +41 -0
- package/esm2022/lib/internal/functions/evaluate.mjs +42 -0
- package/esm2022/lib/internal/functions/extract.mjs +20 -0
- package/esm2022/lib/internal/functions/index.mjs +2 -0
- package/esm2022/lib/internal/functions/parse.mjs +31 -0
- package/esm2022/lib/internal/functions/public-api.mjs +5 -0
- package/esm2022/lib/internal/interfaces/cache-type.mjs +2 -0
- package/esm2022/lib/internal/interfaces/index.mjs +2 -0
- package/esm2022/lib/internal/interfaces/parser-types.mjs +2 -0
- package/esm2022/lib/internal/interfaces/public-api.mjs +3 -0
- package/esm2022/lib/internal/interfaces/queue-type.mjs +2 -0
- package/esm2022/lib/internal/interfaces/recursive-visitors.mjs +6 -0
- package/esm2022/lib/internal/interfaces/registry-type.mjs +2 -0
- package/esm2022/lib/internal/interfaces/scope-type.mjs +2 -0
- package/esm2022/lib/internal/interfaces/stack-type.mjs +2 -0
- package/esm2022/lib/internal/public-api.mjs +3 -0
- package/esm2022/lib/internal/visitors/after-visitor.mjs +10 -0
- package/esm2022/lib/internal/visitors/array-expression.mjs +29 -0
- package/esm2022/lib/internal/visitors/arrow-function-expression.mjs +18 -0
- package/esm2022/lib/internal/visitors/assignment-expression.mjs +50 -0
- package/esm2022/lib/internal/visitors/await-expression.mjs +14 -0
- package/esm2022/lib/internal/visitors/before-visitor.mjs +10 -0
- package/esm2022/lib/internal/visitors/binary-expression.mjs +37 -0
- package/esm2022/lib/internal/visitors/call-expression.mjs +36 -0
- package/esm2022/lib/internal/visitors/conditional-expression.mjs +18 -0
- package/esm2022/lib/internal/visitors/identifier.mjs +11 -0
- package/esm2022/lib/internal/visitors/index.mjs +2 -0
- package/esm2022/lib/internal/visitors/literal.mjs +10 -0
- package/esm2022/lib/internal/visitors/logical-expression.mjs +26 -0
- package/esm2022/lib/internal/visitors/member-expression.mjs +32 -0
- package/esm2022/lib/internal/visitors/new-expression.mjs +21 -0
- package/esm2022/lib/internal/visitors/object-expression.mjs +53 -0
- package/esm2022/lib/internal/visitors/pattern.mjs +132 -0
- package/esm2022/lib/internal/visitors/public-api.mjs +24 -0
- package/esm2022/lib/internal/visitors/recursive-visitors.mjs +28 -0
- package/esm2022/lib/internal/visitors/tagged-template-expression.mjs +20 -0
- package/esm2022/lib/internal/visitors/template-literal.mjs +21 -0
- package/esm2022/lib/internal/visitors/this-expression.mjs +10 -0
- package/esm2022/lib/internal/visitors/unary-expression.mjs +19 -0
- package/esm2022/lib/internal/visitors/update-expression.mjs +26 -0
- package/esm2022/lib/internal/visitors/visitor-result.mjs +29 -0
- package/esm2022/public-api.mjs +6 -0
- package/esm2022/zvenigora-ng-eval-core.mjs +5 -0
- package/fesm2022/zvenigora-ng-eval-core.mjs +2300 -0
- package/fesm2022/zvenigora-ng-eval-core.mjs.map +1 -0
- package/index.d.ts +1 -0
- package/lib/actual/services/base-eval.d.ts +16 -0
- package/lib/actual/services/compiler.service.d.ts +57 -0
- package/lib/actual/services/discovery.service.d.ts +33 -0
- package/lib/actual/services/eval.service.d.ts +41 -0
- package/lib/actual/services/index.d.ts +1 -0
- package/lib/actual/services/parser.service.d.ts +36 -0
- package/lib/actual/services/public-api.d.ts +4 -0
- package/lib/internal/classes/common/base-registry.d.ts +78 -0
- package/lib/internal/classes/common/cache.d.ts +91 -0
- package/lib/internal/classes/common/case-insensitive-registry.d.ts +79 -0
- package/lib/internal/classes/common/context.d.ts +31 -0
- package/lib/internal/classes/common/index.d.ts +1 -0
- package/lib/internal/classes/common/public-api.d.ts +9 -0
- package/lib/internal/classes/common/queue.d.ts +33 -0
- package/lib/internal/classes/common/registry.d.ts +80 -0
- package/lib/internal/classes/common/scope-registry.d.ts +83 -0
- package/lib/internal/classes/common/scope.d.ts +30 -0
- package/lib/internal/classes/common/stack.d.ts +43 -0
- package/lib/internal/classes/eval/eval-context.d.ts +78 -0
- package/lib/internal/classes/eval/eval-lookup.d.ts +2 -0
- package/lib/internal/classes/eval/eval-options.d.ts +6 -0
- package/lib/internal/classes/eval/eval-result.d.ts +92 -0
- package/lib/internal/classes/eval/eval-state.d.ts +46 -0
- package/lib/internal/classes/eval/index.d.ts +1 -0
- package/lib/internal/classes/eval/public-api.d.ts +5 -0
- package/lib/internal/functions/compile.d.ts +33 -0
- package/lib/internal/functions/evaluate.d.ts +17 -0
- package/lib/internal/functions/extract.d.ts +10 -0
- package/lib/internal/functions/index.d.ts +1 -0
- package/lib/internal/functions/parse.d.ts +15 -0
- package/lib/internal/functions/public-api.d.ts +4 -0
- package/lib/internal/interfaces/cache-type.d.ts +6 -0
- package/lib/internal/interfaces/index.d.ts +1 -0
- package/lib/internal/interfaces/parser-types.d.ts +7 -0
- package/lib/internal/interfaces/public-api.d.ts +7 -0
- package/lib/internal/interfaces/queue-type.d.ts +6 -0
- package/lib/internal/interfaces/recursive-visitors.d.ts +43 -0
- package/lib/internal/interfaces/registry-type.d.ts +73 -0
- package/lib/internal/interfaces/scope-type.d.ts +15 -0
- package/lib/internal/interfaces/stack-type.d.ts +6 -0
- package/lib/internal/public-api.d.ts +2 -0
- package/lib/internal/visitors/after-visitor.d.ts +3 -0
- package/lib/internal/visitors/array-expression.d.ts +5 -0
- package/lib/internal/visitors/arrow-function-expression.d.ts +4 -0
- package/lib/internal/visitors/assignment-expression.d.ts +4 -0
- package/lib/internal/visitors/await-expression.d.ts +4 -0
- package/lib/internal/visitors/before-visitor.d.ts +3 -0
- package/lib/internal/visitors/binary-expression.d.ts +4 -0
- package/lib/internal/visitors/call-expression.d.ts +5 -0
- package/lib/internal/visitors/conditional-expression.d.ts +4 -0
- package/lib/internal/visitors/identifier.d.ts +3 -0
- package/lib/internal/visitors/index.d.ts +1 -0
- package/lib/internal/visitors/literal.d.ts +3 -0
- package/lib/internal/visitors/logical-expression.d.ts +4 -0
- package/lib/internal/visitors/member-expression.d.ts +5 -0
- package/lib/internal/visitors/new-expression.d.ts +5 -0
- package/lib/internal/visitors/object-expression.d.ts +4 -0
- package/lib/internal/visitors/pattern.d.ts +6 -0
- package/lib/internal/visitors/public-api.d.ts +23 -0
- package/lib/internal/visitors/recursive-visitors.d.ts +7 -0
- package/lib/internal/visitors/tagged-template-expression.d.ts +4 -0
- package/lib/internal/visitors/template-literal.d.ts +4 -0
- package/lib/internal/visitors/this-expression.d.ts +3 -0
- package/lib/internal/visitors/unary-expression.d.ts +4 -0
- package/lib/internal/visitors/update-expression.d.ts +4 -0
- package/lib/internal/visitors/visitor-result.d.ts +6 -0
- package/package.json +40 -0
- package/public-api.d.ts +5 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { RegistryEntries, RegistryType } from "../../interfaces";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a registry that stores key-value pairs.
|
|
4
|
+
*/
|
|
5
|
+
export declare class BaseRegistry<TKey, TValue> implements RegistryType<TKey, TValue> {
|
|
6
|
+
private readonly _registry;
|
|
7
|
+
type: Readonly<string>;
|
|
8
|
+
/**
|
|
9
|
+
* Options for the base registry.
|
|
10
|
+
*/
|
|
11
|
+
options: Readonly<Record<string, unknown>>;
|
|
12
|
+
/**
|
|
13
|
+
* Creates a new Registry instance.
|
|
14
|
+
* @param entries - Optional array of key-value pairs to initialize the registry.
|
|
15
|
+
*/
|
|
16
|
+
constructor(entries?: RegistryEntries<TKey, TValue> | null);
|
|
17
|
+
/**
|
|
18
|
+
* Creates a new Registry instance from an object.
|
|
19
|
+
* @param object - The object containing key-value pairs.
|
|
20
|
+
* @returns A new Registry instance.
|
|
21
|
+
*/
|
|
22
|
+
static fromObject<TKey extends string | number | symbol, TValue>(object: Record<TKey, TValue>): BaseRegistry<TKey, TValue>;
|
|
23
|
+
/**
|
|
24
|
+
* Retrieves the value associated with the specified key.
|
|
25
|
+
* @param key - The key to retrieve the value for.
|
|
26
|
+
* @returns The value associated with the key, or undefined if the key does not exist.
|
|
27
|
+
*/
|
|
28
|
+
get(key: TKey): TValue | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Sets the value for the specified key.
|
|
31
|
+
* @param key - The key to set the value for.
|
|
32
|
+
* @param value - The value to set.
|
|
33
|
+
*/
|
|
34
|
+
set(key: TKey, value: TValue): void;
|
|
35
|
+
/**
|
|
36
|
+
* Checks if the registry contains the specified key.
|
|
37
|
+
* @param key - The key to check.
|
|
38
|
+
* @returns True if the registry contains the key, false otherwise.
|
|
39
|
+
*/
|
|
40
|
+
has(key: TKey): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Deletes the key-value pair associated with the specified key.
|
|
43
|
+
* @param key - The key to delete.
|
|
44
|
+
* @returns True if the key-value pair was deleted, false if the key does not exist.
|
|
45
|
+
*/
|
|
46
|
+
delete(key: TKey): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Clears all key-value pairs from the registry.
|
|
49
|
+
*/
|
|
50
|
+
clear(): void;
|
|
51
|
+
/**
|
|
52
|
+
* Gets the number of key-value pairs in the registry.
|
|
53
|
+
*/
|
|
54
|
+
get size(): number;
|
|
55
|
+
/**
|
|
56
|
+
* Gets an iterator for the keys in the registry.
|
|
57
|
+
*/
|
|
58
|
+
get keys(): IterableIterator<TKey>;
|
|
59
|
+
/**
|
|
60
|
+
* Gets an iterator for the values in the registry.
|
|
61
|
+
*/
|
|
62
|
+
get values(): IterableIterator<TValue>;
|
|
63
|
+
/**
|
|
64
|
+
* Gets an iterator for the key-value pairs in the registry.
|
|
65
|
+
*/
|
|
66
|
+
get entries(): IterableIterator<[TKey, TValue]>;
|
|
67
|
+
/**
|
|
68
|
+
* Executes a provided function once for each key-value pair in the registry.
|
|
69
|
+
* @param callbackfn - The function to execute for each key-value pair.
|
|
70
|
+
* @param thisArg - Optional value to use as `this` when executing the callback function.
|
|
71
|
+
*/
|
|
72
|
+
forEach(callbackfn: (value: TValue, key: TKey, map: Map<TKey, TValue>) => void, thisArg?: TValue): void;
|
|
73
|
+
/**
|
|
74
|
+
* Returns an iterator for the entries of the registry.
|
|
75
|
+
* @returns An iterator that yields key-value pairs of type [TKey, TValue].
|
|
76
|
+
*/
|
|
77
|
+
[Symbol.iterator](): IterableIterator<[TKey, TValue]>;
|
|
78
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { CacheType } from '../../interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a cache implementation that stores key-value pairs.
|
|
4
|
+
* @template TValue The type of values stored in the cache.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Cache<TValue> implements CacheType<TValue> {
|
|
7
|
+
private readonly _maxCacheSize;
|
|
8
|
+
/**
|
|
9
|
+
* The registry that stores the key-value pairs.
|
|
10
|
+
*/
|
|
11
|
+
private readonly _registry;
|
|
12
|
+
/**
|
|
13
|
+
* The queue that keeps track of the keys in the cache.
|
|
14
|
+
*/
|
|
15
|
+
private readonly _keyQueue;
|
|
16
|
+
type: Readonly<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Options for the cache.
|
|
19
|
+
*/
|
|
20
|
+
options: Readonly<Record<string, unknown>>;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new instance of the Cache class.
|
|
23
|
+
* @param _maxCacheSize The maximum size of the cache.
|
|
24
|
+
*/
|
|
25
|
+
constructor(_maxCacheSize: number);
|
|
26
|
+
/**
|
|
27
|
+
* Gets the maximum size of the cache.
|
|
28
|
+
*/
|
|
29
|
+
get maxCacheSize(): number;
|
|
30
|
+
/**
|
|
31
|
+
* Generates a hash key based on the given namespace and value.
|
|
32
|
+
* @param namespace The namespace for the key.
|
|
33
|
+
* @param value The value for the key.
|
|
34
|
+
* @returns The generated hash key.
|
|
35
|
+
*/
|
|
36
|
+
getHashKey(namespace: string, value: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Gets the value associated with the specified key.
|
|
39
|
+
* @param key The key to retrieve the value for.
|
|
40
|
+
* @returns The value associated with the key, or undefined if the key does not exist in the cache.
|
|
41
|
+
*/
|
|
42
|
+
get(key: string): TValue | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Sets the value for the specified key in the cache.
|
|
45
|
+
* @param key The key to set the value for.
|
|
46
|
+
* @param value The value to set.
|
|
47
|
+
*/
|
|
48
|
+
set(key: string, value: TValue): void;
|
|
49
|
+
/**
|
|
50
|
+
* Checks if the cache contains the specified key.
|
|
51
|
+
* @param key The key to check.
|
|
52
|
+
* @returns True if the cache contains the key, false otherwise.
|
|
53
|
+
*/
|
|
54
|
+
has(key: string): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Deletes the value associated with the specified key from the cache.
|
|
57
|
+
* @param key The key to delete.
|
|
58
|
+
* @returns True if the value was successfully deleted, false otherwise.
|
|
59
|
+
*/
|
|
60
|
+
delete(key: string): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Clears the cache, removing all key-value pairs.
|
|
63
|
+
*/
|
|
64
|
+
clear(): void;
|
|
65
|
+
/**
|
|
66
|
+
* Gets the number of key-value pairs in the cache.
|
|
67
|
+
*/
|
|
68
|
+
get size(): number;
|
|
69
|
+
/**
|
|
70
|
+
* Gets an iterator for the keys in the cache.
|
|
71
|
+
*/
|
|
72
|
+
get keys(): IterableIterator<string>;
|
|
73
|
+
/**
|
|
74
|
+
* Gets an iterator for the values in the cache.
|
|
75
|
+
*/
|
|
76
|
+
get values(): IterableIterator<TValue>;
|
|
77
|
+
/**
|
|
78
|
+
* Gets an iterator for the entries (key-value pairs) in the cache.
|
|
79
|
+
*/
|
|
80
|
+
get entries(): IterableIterator<[string, TValue]>;
|
|
81
|
+
/**
|
|
82
|
+
* Executes a provided function once for each key-value pair in the cache.
|
|
83
|
+
* @param callbackfn The function to execute for each key-value pair.
|
|
84
|
+
* @param thisArg The value to use as `this` when executing the callback function.
|
|
85
|
+
*/
|
|
86
|
+
forEach(callbackfn: (value: TValue, key: string, map: Map<string, TValue>) => void, thisArg?: TValue): void;
|
|
87
|
+
/**
|
|
88
|
+
* Returns an iterator for the entries (key-value pairs) in the cache.
|
|
89
|
+
*/
|
|
90
|
+
[Symbol.iterator](): IterableIterator<[string, TValue]>;
|
|
91
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { RegistryEntries, RegistryType } from "../../interfaces";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a case-insensitive registry that maps keys to values.
|
|
4
|
+
*/
|
|
5
|
+
export declare class CaseInsensitiveRegistry<TKey, TValue> implements RegistryType<TKey, TValue> {
|
|
6
|
+
private readonly registry;
|
|
7
|
+
private keysMap;
|
|
8
|
+
type: Readonly<string>;
|
|
9
|
+
/**
|
|
10
|
+
* Options for the registry.
|
|
11
|
+
*/
|
|
12
|
+
options: Readonly<Record<string, unknown>>;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new instance of CaseInsensitiveRegistry.
|
|
15
|
+
* @param entries - Optional initial entries to populate the registry.
|
|
16
|
+
*/
|
|
17
|
+
constructor(entries?: RegistryEntries<TKey, TValue> | null);
|
|
18
|
+
/**
|
|
19
|
+
* Creates a new CaseInsensitiveRegistry from an object.
|
|
20
|
+
* @param object - The object containing key-value pairs.
|
|
21
|
+
* @returns A new CaseInsensitiveRegistry instance.
|
|
22
|
+
*/
|
|
23
|
+
static fromObject<TKey extends string | number | symbol, TValue>(object: Record<TKey, TValue>): CaseInsensitiveRegistry<TKey, TValue>;
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves the value associated with the specified key.
|
|
26
|
+
* @param key - The key.
|
|
27
|
+
* @returns The value associated with the key, or undefined if the key is not found.
|
|
28
|
+
*/
|
|
29
|
+
get(key: TKey): TValue | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Sets a key-value pair in the registry.
|
|
32
|
+
* @param key - The key.
|
|
33
|
+
* @param value - The value.
|
|
34
|
+
*/
|
|
35
|
+
set(key: TKey, value: TValue): void;
|
|
36
|
+
/**
|
|
37
|
+
* Checks if the registry contains the specified key.
|
|
38
|
+
* @param key - The key.
|
|
39
|
+
* @returns True if the key is found, false otherwise.
|
|
40
|
+
*/
|
|
41
|
+
has(key: TKey): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Deletes the key-value pair associated with the specified key.
|
|
44
|
+
* @param key - The key.
|
|
45
|
+
* @returns True if the key-value pair is deleted, false if the key is not found.
|
|
46
|
+
*/
|
|
47
|
+
delete(key: TKey): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Clears all key-value pairs from the registry.
|
|
50
|
+
*/
|
|
51
|
+
clear(): void;
|
|
52
|
+
/**
|
|
53
|
+
* Gets the number of key-value pairs in the registry.
|
|
54
|
+
*/
|
|
55
|
+
get size(): number;
|
|
56
|
+
/**
|
|
57
|
+
* Gets an iterator for the keys in the registry.
|
|
58
|
+
*/
|
|
59
|
+
get keys(): IterableIterator<TKey>;
|
|
60
|
+
/**
|
|
61
|
+
* Gets an iterator for the values in the registry.
|
|
62
|
+
*/
|
|
63
|
+
get values(): IterableIterator<TValue>;
|
|
64
|
+
/**
|
|
65
|
+
* Gets an iterator for the key-value pairs in the registry.
|
|
66
|
+
*/
|
|
67
|
+
get entries(): IterableIterator<[TKey, TValue]>;
|
|
68
|
+
/**
|
|
69
|
+
* Executes a provided function once for each key-value pair in the registry.
|
|
70
|
+
* @param callbackfn - The function to execute for each key-value pair.
|
|
71
|
+
*/
|
|
72
|
+
forEach(callbackfn: (value: TValue, key: TKey, map: Map<TKey, TValue>) => void): void;
|
|
73
|
+
/**
|
|
74
|
+
* Returns an iterator for the entries of the registry.
|
|
75
|
+
* @returns An iterator that yields key-value pairs of type [string, unknown].
|
|
76
|
+
*/
|
|
77
|
+
[Symbol.iterator](): IterableIterator<[TKey, TValue]>;
|
|
78
|
+
private getKey;
|
|
79
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Registry } from '../common';
|
|
2
|
+
import { EvalOptions } from '../eval';
|
|
3
|
+
export type BaseContext = Record<string | number | symbol, unknown>;
|
|
4
|
+
export type Context = Registry<unknown, unknown> | BaseContext;
|
|
5
|
+
/**
|
|
6
|
+
* Converts a context object to a Context instance.
|
|
7
|
+
* @param context - The context object to convert.
|
|
8
|
+
* @param options - Optional evaluation options.
|
|
9
|
+
* @returns The converted Context instance.
|
|
10
|
+
*/
|
|
11
|
+
export declare const fromContext: (context?: Context, options?: EvalOptions) => Context;
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves the value associated with the specified key from the given context.
|
|
14
|
+
* If the context is an instance of Registry, it uses the `get` method to retrieve the value.
|
|
15
|
+
* If the context is an object, it accesses the value using the key as a property name.
|
|
16
|
+
* If the context is neither an instance of Registry nor an object, it returns undefined.
|
|
17
|
+
*
|
|
18
|
+
* @param context The context from which to retrieve the value.
|
|
19
|
+
* @param key The key associated with the value to retrieve.
|
|
20
|
+
* @returns The value associated with the specified key, or undefined if not found.
|
|
21
|
+
*/
|
|
22
|
+
export declare const getContextValue: (context?: Context, key?: unknown) => unknown;
|
|
23
|
+
/**
|
|
24
|
+
* Sets a value in the given context object.
|
|
25
|
+
* If the context is an instance of Registry, the value is set using the key.
|
|
26
|
+
* If the context is a plain object, the value is set using the key as a property name.
|
|
27
|
+
* @param context - The context object.
|
|
28
|
+
* @param key - The key or property name.
|
|
29
|
+
* @param value - The value to be set.
|
|
30
|
+
*/
|
|
31
|
+
export declare const setContextValue: (context: Context, key: unknown, value: unknown) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public-api';
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { BaseRegistry } from './base-registry';
|
|
2
|
+
export { CaseInsensitiveRegistry } from './case-insensitive-registry';
|
|
3
|
+
export { ScopeRegistry, RegistryScopeOptionType } from './scope-registry';
|
|
4
|
+
export { Registry } from './registry';
|
|
5
|
+
export { Queue } from './queue';
|
|
6
|
+
export { Stack } from './stack';
|
|
7
|
+
export { Scope } from './scope';
|
|
8
|
+
export { Cache } from './cache';
|
|
9
|
+
export { BaseContext, Context, fromContext, getContextValue as get } from './context';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { QueueType } from '../../interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a generic queue data structure.
|
|
4
|
+
* @template T The type of elements stored in the queue.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Queue<T> implements QueueType<T> {
|
|
7
|
+
private readonly _queue;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new instance of the Queue class.
|
|
10
|
+
* @param _queue Optional initial array of elements.
|
|
11
|
+
*/
|
|
12
|
+
constructor(_queue?: T[]);
|
|
13
|
+
/**
|
|
14
|
+
* Gets the number of elements in the queue.
|
|
15
|
+
*/
|
|
16
|
+
get length(): number;
|
|
17
|
+
/**
|
|
18
|
+
* Removes and returns the first element in the queue.
|
|
19
|
+
* @returns The first element in the queue, or undefined if the queue is empty.
|
|
20
|
+
*/
|
|
21
|
+
dequeue(): T | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Adds an element to the end of the queue.
|
|
24
|
+
* @param value The element to add to the queue.
|
|
25
|
+
* @returns The new length of the queue.
|
|
26
|
+
*/
|
|
27
|
+
enqueue(value: T): number;
|
|
28
|
+
/**
|
|
29
|
+
* Returns the first element in the queue without removing it.
|
|
30
|
+
* @returns The first element in the queue.
|
|
31
|
+
*/
|
|
32
|
+
peek(): T;
|
|
33
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a generic 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
|
+
import { RegistryEntries, RegistryType } from "../../interfaces";
|
|
7
|
+
export declare class Registry<TKey, TValue> implements RegistryType<TKey, TValue> {
|
|
8
|
+
private readonly _registry;
|
|
9
|
+
type: Readonly<string>;
|
|
10
|
+
/**
|
|
11
|
+
* Options for the registry.
|
|
12
|
+
*/
|
|
13
|
+
options: Readonly<Record<string, unknown>>;
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new Registry instance.
|
|
16
|
+
* @param entries - Optional array of key-value pairs to initialize the registry.
|
|
17
|
+
*/
|
|
18
|
+
constructor(entries?: RegistryEntries<TKey, TValue> | null, options?: Record<string, unknown>);
|
|
19
|
+
/**
|
|
20
|
+
* Creates a new Registry instance from an object.
|
|
21
|
+
* @param object - The object containing key-value pairs.
|
|
22
|
+
* @returns A new Registry instance.
|
|
23
|
+
*/
|
|
24
|
+
static fromObject<TKey extends string | number | symbol, TValue>(object: Record<TKey, TValue>, options?: Record<string, unknown>): Registry<TKey, TValue>;
|
|
25
|
+
/**
|
|
26
|
+
* Retrieves the value associated with the specified key.
|
|
27
|
+
* @param key - The key to retrieve the value for.
|
|
28
|
+
* @returns The value associated with the key, or undefined if the key does not exist.
|
|
29
|
+
*/
|
|
30
|
+
get(key: TKey): TValue | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Sets the value for the specified key.
|
|
33
|
+
* @param key - The key to set the value for.
|
|
34
|
+
* @param value - The value to set.
|
|
35
|
+
*/
|
|
36
|
+
set(key: TKey, value: TValue): void;
|
|
37
|
+
/**
|
|
38
|
+
* Checks if the registry contains the specified key.
|
|
39
|
+
* @param key - The key to check.
|
|
40
|
+
* @returns True if the registry contains the key, false otherwise.
|
|
41
|
+
*/
|
|
42
|
+
has(key: TKey): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Deletes the key-value pair associated with the specified key.
|
|
45
|
+
* @param key - The key to delete.
|
|
46
|
+
* @returns True if the key-value pair was deleted, false if the key does not exist.
|
|
47
|
+
*/
|
|
48
|
+
delete(key: TKey): boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Clears all key-value pairs from the registry.
|
|
51
|
+
*/
|
|
52
|
+
clear(): void;
|
|
53
|
+
/**
|
|
54
|
+
* Gets the number of key-value pairs in the registry.
|
|
55
|
+
*/
|
|
56
|
+
get size(): number;
|
|
57
|
+
/**
|
|
58
|
+
* Gets an iterator for the keys in the registry.
|
|
59
|
+
*/
|
|
60
|
+
get keys(): IterableIterator<TKey>;
|
|
61
|
+
/**
|
|
62
|
+
* Gets an iterator for the values in the registry.
|
|
63
|
+
*/
|
|
64
|
+
get values(): IterableIterator<TValue>;
|
|
65
|
+
/**
|
|
66
|
+
* Gets an iterator for the key-value pairs in the registry.
|
|
67
|
+
*/
|
|
68
|
+
get entries(): IterableIterator<[TKey, TValue]>;
|
|
69
|
+
/**
|
|
70
|
+
* Executes a provided function once for each key-value pair in the registry.
|
|
71
|
+
* @param callbackfn - The function to execute for each key-value pair.
|
|
72
|
+
* @param thisArg - Optional value to use as `this` when executing the callback function.
|
|
73
|
+
*/
|
|
74
|
+
forEach(callbackfn: (value: TValue, key: TKey, map: Map<TKey, TValue>) => void, thisArg?: TValue): void;
|
|
75
|
+
/**
|
|
76
|
+
* Returns an iterator for the entries of the registry.
|
|
77
|
+
* @returns An iterator that yields key-value pairs of type [TKey, TValue].
|
|
78
|
+
*/
|
|
79
|
+
[Symbol.iterator](): IterableIterator<[TKey, TValue]>;
|
|
80
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { RegistryType, ScopeRegistryOptions } from "../../interfaces";
|
|
2
|
+
export type RegistryScopeOptionType = Readonly<Record<string, unknown> | ScopeRegistryOptions>;
|
|
3
|
+
/**
|
|
4
|
+
* Represents a registry that stores key-value pairs within a specific scope.
|
|
5
|
+
* @template TKey The type of the keys in the registry.
|
|
6
|
+
* @template TValue The type of the values in the registry.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ScopeRegistry<TKey, TValue> implements RegistryType<TKey, TValue> {
|
|
9
|
+
private readonly _registry;
|
|
10
|
+
type: Readonly<string>;
|
|
11
|
+
/**
|
|
12
|
+
* Options for the registry.
|
|
13
|
+
*/
|
|
14
|
+
options: Readonly<RegistryScopeOptionType>;
|
|
15
|
+
/**
|
|
16
|
+
* Creates a new instance of ScopeRegistry.
|
|
17
|
+
* @param entries Optional. An array of key-value pairs to initialize the registry.
|
|
18
|
+
* @param options Optional. Options for the registry.
|
|
19
|
+
*/
|
|
20
|
+
constructor(entries?: [TKey, TValue][] | null, options?: RegistryScopeOptionType);
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new ScopeRegistry instance from an object.
|
|
23
|
+
* @param object The object containing key-value pairs.
|
|
24
|
+
* @param options Optional. Options for the registry.
|
|
25
|
+
* @returns A new ScopeRegistry instance.
|
|
26
|
+
*/
|
|
27
|
+
static fromObject<TKey extends string | number | symbol, TValue>(object: Record<TKey, TValue>, options?: RegistryScopeOptionType): RegistryType<TKey, TValue>;
|
|
28
|
+
/**
|
|
29
|
+
* Gets the value associated with the specified key.
|
|
30
|
+
* @param key The key to retrieve the value for.
|
|
31
|
+
* @returns The value associated with the key, or undefined if the key does not exist.
|
|
32
|
+
*/
|
|
33
|
+
get(key: TKey): TValue | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Sets the value for the specified key.
|
|
36
|
+
* @param key The key to set the value for.
|
|
37
|
+
* @param value The value to set.
|
|
38
|
+
*/
|
|
39
|
+
set(key: TKey, value: TValue): void;
|
|
40
|
+
/**
|
|
41
|
+
* Checks if the registry contains the specified key.
|
|
42
|
+
* @param key The key to check.
|
|
43
|
+
* @returns True if the key exists in the registry, false otherwise.
|
|
44
|
+
*/
|
|
45
|
+
has(key: TKey): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Deletes the key-value pair associated with the specified key.
|
|
48
|
+
* @param key The key to delete.
|
|
49
|
+
* @returns True if the key-value pair was deleted, false if the key does not exist.
|
|
50
|
+
*/
|
|
51
|
+
delete(key: TKey): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Clears all key-value pairs from the registry.
|
|
54
|
+
*/
|
|
55
|
+
clear(): void;
|
|
56
|
+
/**
|
|
57
|
+
* Gets the number of key-value pairs in the registry.
|
|
58
|
+
*/
|
|
59
|
+
get size(): number;
|
|
60
|
+
/**
|
|
61
|
+
* Gets an iterator for the keys in the registry.
|
|
62
|
+
*/
|
|
63
|
+
get keys(): IterableIterator<TKey>;
|
|
64
|
+
/**
|
|
65
|
+
* Gets an iterator for the values in the registry.
|
|
66
|
+
*/
|
|
67
|
+
get values(): IterableIterator<TValue>;
|
|
68
|
+
/**
|
|
69
|
+
* Gets an iterator for the key-value pairs in the registry.
|
|
70
|
+
*/
|
|
71
|
+
get entries(): IterableIterator<[TKey, TValue]>;
|
|
72
|
+
/**
|
|
73
|
+
* Executes a provided function once for each key-value pair in the registry.
|
|
74
|
+
* @param callbackfn The function to execute for each key-value pair.
|
|
75
|
+
* @param thisArg Optional. The value to use as `this` when executing the callback function.
|
|
76
|
+
*/
|
|
77
|
+
forEach(callbackfn: (value: TValue, key: TKey, map: Map<TKey, TValue>) => void, thisArg?: TValue): void;
|
|
78
|
+
/**
|
|
79
|
+
* Gets an iterator for the key-value pairs in the registry.
|
|
80
|
+
* @returns An iterator for the key-value pairs in the registry.
|
|
81
|
+
*/
|
|
82
|
+
[Symbol.iterator](): IterableIterator<[TKey, TValue]>;
|
|
83
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { RegistryOptionType, ScopeType } from '../../interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a scope that holds key-value pairs.
|
|
4
|
+
* @template TKey The type of the keys in the scope.
|
|
5
|
+
* @template TValue The type of the values in the scope.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Scope<TKey, TValue> implements ScopeType<TKey, TValue> {
|
|
8
|
+
private _registries;
|
|
9
|
+
/**
|
|
10
|
+
* Gets the registries in the scope.
|
|
11
|
+
*/
|
|
12
|
+
get registries(): RegistryOptionType<TKey, TValue>[];
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new scope.
|
|
15
|
+
* @param registries Optional array of registries to initialize the scope with.
|
|
16
|
+
*/
|
|
17
|
+
constructor(registries?: RegistryOptionType<TKey, TValue>[]);
|
|
18
|
+
/**
|
|
19
|
+
* Adds a registry to the scope.
|
|
20
|
+
* @param registry The registry to add.
|
|
21
|
+
*/
|
|
22
|
+
add(registry: RegistryOptionType<TKey, TValue>): void;
|
|
23
|
+
/**
|
|
24
|
+
* Gets the value associated with the specified key in the scope.
|
|
25
|
+
* @param key The key to search for.
|
|
26
|
+
* @param namespace Optional namespace to filter the search by.
|
|
27
|
+
* @returns An array containing the key and value if found, otherwise undefined.
|
|
28
|
+
*/
|
|
29
|
+
get(key: TKey, namespace?: string): [TKey, TValue] | undefined;
|
|
30
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { StackType } from '../../interfaces';
|
|
2
|
+
/**
|
|
3
|
+
* Represents a stack data structure.
|
|
4
|
+
* @template T The type of elements in the stack.
|
|
5
|
+
*/
|
|
6
|
+
export declare class Stack<T> implements StackType<T> {
|
|
7
|
+
private readonly _stack;
|
|
8
|
+
/**
|
|
9
|
+
* Creates a new instance of the Stack class.
|
|
10
|
+
* @param _stack An optional array to initialize the stack.
|
|
11
|
+
*/
|
|
12
|
+
constructor(_stack?: T[]);
|
|
13
|
+
/**
|
|
14
|
+
* Gets the number of elements in the stack.
|
|
15
|
+
*/
|
|
16
|
+
get length(): number;
|
|
17
|
+
/**
|
|
18
|
+
* Returns the top element of the stack without removing it.
|
|
19
|
+
* @returns The top element of the stack.
|
|
20
|
+
*/
|
|
21
|
+
peek(): T;
|
|
22
|
+
/**
|
|
23
|
+
* Removes and returns the top element of the stack.
|
|
24
|
+
* @returns The top element of the stack, or undefined if the stack is empty.
|
|
25
|
+
*/
|
|
26
|
+
pop(): T | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Adds an element to the top of the stack.
|
|
29
|
+
* @param value The element to be added to the stack.
|
|
30
|
+
* @returns The new length of the stack.
|
|
31
|
+
*/
|
|
32
|
+
push(value: T): number;
|
|
33
|
+
/**
|
|
34
|
+
* Swaps the positions of the top two elements in the stack.
|
|
35
|
+
*/
|
|
36
|
+
swap(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Returns the elements of the stack as an array in reverse order.
|
|
39
|
+
*
|
|
40
|
+
* @returns An array containing the elements of the stack in reverse order.
|
|
41
|
+
*/
|
|
42
|
+
asArray(): T[];
|
|
43
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Context, Registry, Stack } from '../common';
|
|
2
|
+
import { EvalLookup } from './eval-lookup';
|
|
3
|
+
import { EvalOptions } from './eval-options';
|
|
4
|
+
/**
|
|
5
|
+
* Represents the evaluation context for the code execution.
|
|
6
|
+
*/
|
|
7
|
+
export declare class EvalContext {
|
|
8
|
+
type: string;
|
|
9
|
+
private _original;
|
|
10
|
+
private _priorScopes;
|
|
11
|
+
private _scopes;
|
|
12
|
+
private _lookups;
|
|
13
|
+
private _options;
|
|
14
|
+
/**
|
|
15
|
+
* Gets the original registry.
|
|
16
|
+
*/
|
|
17
|
+
get original(): Context;
|
|
18
|
+
/**
|
|
19
|
+
* Gets the scopes registry.
|
|
20
|
+
*/
|
|
21
|
+
get priorScopes(): Readonly<Context[]>;
|
|
22
|
+
/**
|
|
23
|
+
* Gets the scopes registry.
|
|
24
|
+
*/
|
|
25
|
+
get scopes(): Readonly<Stack<Context>>;
|
|
26
|
+
/**
|
|
27
|
+
* Gets the lookups registry.
|
|
28
|
+
*/
|
|
29
|
+
get lookups(): Readonly<Registry<unknown, EvalLookup>>;
|
|
30
|
+
/**
|
|
31
|
+
* Gets the evaluation options.
|
|
32
|
+
*/
|
|
33
|
+
get options(): EvalOptions;
|
|
34
|
+
/**
|
|
35
|
+
* Creates a new instance of EvalContext.
|
|
36
|
+
* @param original - The original registry or an object to create a registry from.
|
|
37
|
+
* @param options - The evaluation options.
|
|
38
|
+
*/
|
|
39
|
+
constructor(original: Context, options: EvalOptions);
|
|
40
|
+
/**
|
|
41
|
+
* Converts the given context to an instance of EvalContext.
|
|
42
|
+
* @param context - The context to convert.
|
|
43
|
+
* @param options - The evaluation options.
|
|
44
|
+
* @returns The converted EvalContext instance.
|
|
45
|
+
*/
|
|
46
|
+
static fromContext(context?: EvalContext | Context | undefined, options?: EvalOptions): EvalContext;
|
|
47
|
+
/**
|
|
48
|
+
* Gets the value associated with the specified key from the evaluation context.
|
|
49
|
+
* @param key - The key to retrieve the value for.
|
|
50
|
+
* @returns The value associated with the key, or undefined if not found.
|
|
51
|
+
*/
|
|
52
|
+
get(key: unknown): unknown | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Retrieves the `this` value of the specified key from the evaluation context.
|
|
55
|
+
* The value is searched in the original context, prior scopes, and lookup functions.
|
|
56
|
+
* @param key - The key to retrieve the value for.
|
|
57
|
+
* @returns The `this` value associated with the key, or undefined if not found.
|
|
58
|
+
*/
|
|
59
|
+
getThis(key: unknown): unknown | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Sets a key-value pair in the context.
|
|
62
|
+
* If the original context is a Registry, the key-value pair is set using the Registry's set method.
|
|
63
|
+
* If the original context is an Object, the key-value pair is set directly on the object.
|
|
64
|
+
* @param key - The key of the pair.
|
|
65
|
+
* @param value - The value of the pair.
|
|
66
|
+
*/
|
|
67
|
+
set(key: unknown, value: unknown): void;
|
|
68
|
+
/**
|
|
69
|
+
* Pushes a context to the scope stack.
|
|
70
|
+
* @param context - The context to push.
|
|
71
|
+
* @param options - The evaluation options.
|
|
72
|
+
*/
|
|
73
|
+
push(context: Context, options?: EvalOptions): void;
|
|
74
|
+
/**
|
|
75
|
+
* Pops a context from the scope stack.
|
|
76
|
+
*/
|
|
77
|
+
pop(): void;
|
|
78
|
+
}
|