@zvenigora/ng-eval-core 0.2.1 → 0.2.2
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/fesm2022/zvenigora-ng-eval-core.mjs +12 -12
- package/fesm2022/zvenigora-ng-eval-core.mjs.map +1 -1
- package/index.d.ts +1270 -1
- package/package.json +3 -3
- package/lib/actual/services/base-eval.d.ts +0 -35
- package/lib/actual/services/compiler.service.d.ts +0 -96
- package/lib/actual/services/discovery.service.d.ts +0 -27
- package/lib/actual/services/eval.service.d.ts +0 -65
- package/lib/actual/services/index.d.ts +0 -1
- package/lib/actual/services/parser.service.d.ts +0 -57
- package/lib/actual/services/public-api.d.ts +0 -4
- package/lib/internal/classes/common/base-registry.d.ts +0 -84
- package/lib/internal/classes/common/cache.d.ts +0 -91
- package/lib/internal/classes/common/case-insensitive-registry.d.ts +0 -85
- package/lib/internal/classes/common/context.d.ts +0 -42
- package/lib/internal/classes/common/index.d.ts +0 -1
- package/lib/internal/classes/common/public-api.d.ts +0 -7
- package/lib/internal/classes/common/queue.d.ts +0 -33
- package/lib/internal/classes/common/registry.d.ts +0 -86
- package/lib/internal/classes/common/stack.d.ts +0 -60
- package/lib/internal/classes/eval/eval-context.d.ts +0 -93
- package/lib/internal/classes/eval/eval-lookup.d.ts +0 -2
- package/lib/internal/classes/eval/eval-options.d.ts +0 -6
- package/lib/internal/classes/eval/eval-result.d.ts +0 -105
- package/lib/internal/classes/eval/eval-scope.d.ts +0 -51
- package/lib/internal/classes/eval/eval-state.d.ts +0 -46
- package/lib/internal/classes/eval/eval-trace.d.ts +0 -20
- package/lib/internal/classes/eval/index.d.ts +0 -1
- package/lib/internal/classes/eval/parser-options.d.ts +0 -2
- package/lib/internal/classes/eval/public-api.d.ts +0 -8
- package/lib/internal/functions/compile.d.ts +0 -33
- package/lib/internal/functions/evaluate.d.ts +0 -17
- package/lib/internal/functions/extract.d.ts +0 -10
- package/lib/internal/functions/index.d.ts +0 -1
- package/lib/internal/functions/parse.d.ts +0 -15
- package/lib/internal/functions/public-api.d.ts +0 -4
- package/lib/internal/interfaces/cache-type.d.ts +0 -6
- package/lib/internal/interfaces/index.d.ts +0 -1
- package/lib/internal/interfaces/parser-types.d.ts +0 -7
- package/lib/internal/interfaces/public-api.d.ts +0 -7
- package/lib/internal/interfaces/queue-type.d.ts +0 -6
- package/lib/internal/interfaces/recursive-visitors.d.ts +0 -44
- package/lib/internal/interfaces/registry-type.d.ts +0 -67
- package/lib/internal/interfaces/scope-type.d.ts +0 -15
- package/lib/internal/interfaces/stack-type.d.ts +0 -6
- package/lib/internal/public-api.d.ts +0 -2
- package/lib/internal/visitors/after-visitor.d.ts +0 -3
- package/lib/internal/visitors/array-expression.d.ts +0 -5
- package/lib/internal/visitors/arrow-function-expression.d.ts +0 -4
- package/lib/internal/visitors/assignment-expression.d.ts +0 -4
- package/lib/internal/visitors/await-expression.d.ts +0 -4
- package/lib/internal/visitors/before-visitor.d.ts +0 -3
- package/lib/internal/visitors/binary-expression.d.ts +0 -7
- package/lib/internal/visitors/call-expression.d.ts +0 -8
- package/lib/internal/visitors/conditional-expression.d.ts +0 -4
- package/lib/internal/visitors/identifier.d.ts +0 -3
- package/lib/internal/visitors/import-expression.d.ts +0 -6
- package/lib/internal/visitors/index.d.ts +0 -1
- package/lib/internal/visitors/literal.d.ts +0 -3
- package/lib/internal/visitors/logical-expression.d.ts +0 -4
- package/lib/internal/visitors/member-expression.d.ts +0 -5
- package/lib/internal/visitors/new-expression.d.ts +0 -5
- package/lib/internal/visitors/object-expression.d.ts +0 -4
- package/lib/internal/visitors/pattern.d.ts +0 -6
- package/lib/internal/visitors/property-lookup-cache.d.ts +0 -21
- package/lib/internal/visitors/prototype-pollution-guard.d.ts +0 -46
- package/lib/internal/visitors/public-api.d.ts +0 -25
- package/lib/internal/visitors/recursive-visitors.d.ts +0 -7
- package/lib/internal/visitors/tagged-template-expression.d.ts +0 -4
- package/lib/internal/visitors/template-literal.d.ts +0 -4
- package/lib/internal/visitors/this-expression.d.ts +0 -3
- package/lib/internal/visitors/unary-expression.d.ts +0 -4
- package/lib/internal/visitors/update-expression.d.ts +0 -4
- package/lib/internal/visitors/utils.d.ts +0 -23
- package/lib/internal/visitors/visitor-result.d.ts +0 -6
- package/public-api.d.ts +0 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zvenigora/ng-eval-core",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "An expression evaluator for Angular",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"homepage": "https://github.com/Zvenigora/ng-eval#readme",
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@angular/common": "
|
|
18
|
-
"@angular/core": "
|
|
17
|
+
"@angular/common": ">=19.0.0",
|
|
18
|
+
"@angular/core": ">=19.0.0",
|
|
19
19
|
"acorn": "^8.11.2",
|
|
20
20
|
"acorn-walk": "^8.3.0",
|
|
21
21
|
"js-sha256": "^0.10.1"
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { AnyNode } from "acorn";
|
|
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";
|
|
6
|
-
/**
|
|
7
|
-
* Base class for evaluation.
|
|
8
|
-
*/
|
|
9
|
-
export declare abstract class BaseEval {
|
|
10
|
-
protected parserService: ParserService;
|
|
11
|
-
private _parserOptions;
|
|
12
|
-
constructor(parserService: ParserService);
|
|
13
|
-
/**
|
|
14
|
-
* Gets the parser options.
|
|
15
|
-
*/
|
|
16
|
-
protected get parserOptions(): ParserOptions;
|
|
17
|
-
/**
|
|
18
|
-
* Sets the parser options.
|
|
19
|
-
* @param value The parser options to set.
|
|
20
|
-
*/
|
|
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;
|
|
35
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { OnDestroy } from '@angular/core';
|
|
2
|
-
import { BaseEval } from './base-eval';
|
|
3
|
-
import { ParserService } from './parser.service';
|
|
4
|
-
import { EvalService } from './eval.service';
|
|
5
|
-
import { EvalContext, EvalOptions, EvalState } from '../../internal/classes/eval';
|
|
6
|
-
import { Context } from '../../internal/classes/common';
|
|
7
|
-
import { AnyNode } from 'acorn';
|
|
8
|
-
import { stateCallback, stateCallbackAsync } from '../../internal/functions';
|
|
9
|
-
import * as i0 from "@angular/core";
|
|
10
|
-
/**
|
|
11
|
-
* CompilerService class that extends BaseEval.
|
|
12
|
-
* Provides methods for compiling and evaluating expressions with performance caching.
|
|
13
|
-
*/
|
|
14
|
-
export declare class CompilerService extends BaseEval implements OnDestroy {
|
|
15
|
-
protected parserService: ParserService;
|
|
16
|
-
protected evalService: EvalService;
|
|
17
|
-
private readonly _compilationCache;
|
|
18
|
-
private readonly _maxCacheSize;
|
|
19
|
-
private readonly _cacheTTL;
|
|
20
|
-
private readonly _accessOrder;
|
|
21
|
-
private _cacheCleanupInterval?;
|
|
22
|
-
private _isDestroyed;
|
|
23
|
-
constructor(parserService: ParserService, evalService: EvalService);
|
|
24
|
-
/**
|
|
25
|
-
* OnDestroy lifecycle hook for cleanup
|
|
26
|
-
*/
|
|
27
|
-
ngOnDestroy(): void;
|
|
28
|
-
/**
|
|
29
|
-
* Setup periodic cache cleanup to prevent memory leaks and stale entries
|
|
30
|
-
*/
|
|
31
|
-
private setupCacheCleanup;
|
|
32
|
-
/**
|
|
33
|
-
* Clean expired entries and enforce cache size limits
|
|
34
|
-
*/
|
|
35
|
-
private cleanupCache;
|
|
36
|
-
/**
|
|
37
|
-
* Generate cache key for expression
|
|
38
|
-
*/
|
|
39
|
-
private generateCacheKey;
|
|
40
|
-
/**
|
|
41
|
-
* Update access order for LRU cache
|
|
42
|
-
*/
|
|
43
|
-
private updateAccessOrder;
|
|
44
|
-
/**
|
|
45
|
-
* Compiles the given expression into a state callback function with caching.
|
|
46
|
-
* @param expression - The expression to compile.
|
|
47
|
-
* @returns The compiled state callback function.
|
|
48
|
-
* @throws Error if there is an error during compilation.
|
|
49
|
-
*/
|
|
50
|
-
compile(expression: string | AnyNode | undefined): stateCallback | undefined;
|
|
51
|
-
/**
|
|
52
|
-
* Calls the given state callback function with the specified context and options.
|
|
53
|
-
* @param fn - The state callback function to call.
|
|
54
|
-
* @param context - The evaluation context or context object.
|
|
55
|
-
* @param options - The evaluation options.
|
|
56
|
-
* @returns The result of the evaluation.
|
|
57
|
-
* @throws Error if there is an error during the evaluation.
|
|
58
|
-
*/
|
|
59
|
-
simpleCall(fn: stateCallback | undefined, context?: EvalContext | Context, options?: EvalOptions): unknown;
|
|
60
|
-
/**
|
|
61
|
-
* Calls the provided function with the given state.
|
|
62
|
-
*
|
|
63
|
-
* @param fn - The function to be called.
|
|
64
|
-
* @param state - The state to be passed to the function.
|
|
65
|
-
* @returns The value returned by the function.
|
|
66
|
-
* @throws If an error occurs during the function call.
|
|
67
|
-
*/
|
|
68
|
-
call(fn: stateCallback | undefined, state: EvalState): unknown;
|
|
69
|
-
/**
|
|
70
|
-
* Compiles the given expression into an asynchronous state callback function with caching.
|
|
71
|
-
* @param expression - The expression to compile.
|
|
72
|
-
* @returns The compiled asynchronous state callback function.
|
|
73
|
-
* @throws Error if there is an error during compilation.
|
|
74
|
-
*/
|
|
75
|
-
compileAsync(expression: string | AnyNode | undefined): stateCallbackAsync | undefined;
|
|
76
|
-
/**
|
|
77
|
-
* Calls the given asynchronous state callback function with the specified context and options.
|
|
78
|
-
* @param fn - The asynchronous state callback function to call.
|
|
79
|
-
* @param context - The evaluation context or context object.
|
|
80
|
-
* @param options - The evaluation options.
|
|
81
|
-
* @returns A promise that resolves to the result of the evaluation.
|
|
82
|
-
* @throws Error if there is an error during the evaluation.
|
|
83
|
-
*/
|
|
84
|
-
simpleCallAsync(fn: stateCallbackAsync | undefined, context?: EvalContext | Context, options?: EvalOptions): Promise<unknown>;
|
|
85
|
-
/**
|
|
86
|
-
* Calls the provided asynchronous function with the given state.
|
|
87
|
-
*
|
|
88
|
-
* @param fn - The asynchronous function to call.
|
|
89
|
-
* @param state - The state to pass to the function.
|
|
90
|
-
* @returns A promise that resolves to the value returned by the function.
|
|
91
|
-
* @throws If an error occurs during the function call.
|
|
92
|
-
*/
|
|
93
|
-
callAsync(fn: stateCallbackAsync | undefined, state: EvalState): Promise<unknown>;
|
|
94
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<CompilerService, never>;
|
|
95
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<CompilerService>;
|
|
96
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { BaseEval } from './base-eval';
|
|
2
|
-
import { ParserService } from './parser.service';
|
|
3
|
-
import { AnyNode } from 'acorn';
|
|
4
|
-
import { AnyNodeTypes } from '../../internal/interfaces';
|
|
5
|
-
import * as i0 from "@angular/core";
|
|
6
|
-
/**
|
|
7
|
-
* Service responsible for discovering nodes in an abstract syntax tree (AST).
|
|
8
|
-
*/
|
|
9
|
-
export declare class DiscoveryService extends BaseEval {
|
|
10
|
-
protected parserService: ParserService;
|
|
11
|
-
/**
|
|
12
|
-
* Creates a new instance of the DiscoveryService class.
|
|
13
|
-
* @param parserService The parser service to be used.
|
|
14
|
-
*/
|
|
15
|
-
constructor(parserService: ParserService);
|
|
16
|
-
/**
|
|
17
|
-
* Finds all nodes in the AST that match the given expression and search type.
|
|
18
|
-
* @param expression The expression to search for. Can be a string or an AST node.
|
|
19
|
-
* @param searchType The type of nodes to search for.
|
|
20
|
-
* @param options Optional parser options.
|
|
21
|
-
* @returns An array of nodes that match the search criteria, or undefined if no nodes are found.
|
|
22
|
-
* @throws If an error occurs during the search process.
|
|
23
|
-
*/
|
|
24
|
-
extract(expression: string | AnyNode | undefined, searchType: AnyNodeTypes): AnyNode[] | undefined;
|
|
25
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<DiscoveryService, never>;
|
|
26
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<DiscoveryService>;
|
|
27
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { OnDestroy } from '@angular/core';
|
|
2
|
-
import { BaseEval } from './base-eval';
|
|
3
|
-
import { ParserService } from './parser.service';
|
|
4
|
-
import { AnyNode } from 'acorn';
|
|
5
|
-
import { Context } from '../../internal/classes/common';
|
|
6
|
-
import { EvalContext, EvalOptions, EvalState } from '../../internal/classes/eval';
|
|
7
|
-
import * as i0 from "@angular/core";
|
|
8
|
-
/**
|
|
9
|
-
* Service for evaluating and parsing expressions with proper memory management.
|
|
10
|
-
*/
|
|
11
|
-
export declare class EvalService extends BaseEval implements OnDestroy {
|
|
12
|
-
protected parserService: ParserService;
|
|
13
|
-
private _isDestroyed;
|
|
14
|
-
private _activeContexts;
|
|
15
|
-
private _activeStates;
|
|
16
|
-
/**
|
|
17
|
-
* Constructs a new instance of the EvalService class.
|
|
18
|
-
* @param parserService The parser service used for parsing expressions.
|
|
19
|
-
*/
|
|
20
|
-
constructor(parserService: ParserService);
|
|
21
|
-
/**
|
|
22
|
-
* Override createState to track active contexts and states for cleanup
|
|
23
|
-
*/
|
|
24
|
-
createState(context?: EvalContext | Context, options?: EvalOptions): EvalState;
|
|
25
|
-
/**
|
|
26
|
-
* Clean up resources to prevent memory leaks
|
|
27
|
-
*/
|
|
28
|
-
ngOnDestroy(): void;
|
|
29
|
-
/**
|
|
30
|
-
* Evaluates the given expression.
|
|
31
|
-
* @param expression The expression to evaluate.
|
|
32
|
-
* @param context The evaluation context.
|
|
33
|
-
* @param options The evaluation options.
|
|
34
|
-
* @returns The result of the evaluation.
|
|
35
|
-
*/
|
|
36
|
-
simpleEval(expression: string | AnyNode | undefined, context?: EvalContext | Context, options?: EvalOptions): unknown | undefined;
|
|
37
|
-
/**
|
|
38
|
-
* Evaluates an expression using the provided state.
|
|
39
|
-
*
|
|
40
|
-
* @param expression - The expression to evaluate.
|
|
41
|
-
* @param state - The state object containing variables and functions used in the evaluation.
|
|
42
|
-
* @returns The result of the evaluation.
|
|
43
|
-
* @throws If an error occurs during evaluation.
|
|
44
|
-
*/
|
|
45
|
-
eval(expression: string | AnyNode | undefined, state: EvalState): unknown | undefined;
|
|
46
|
-
/**
|
|
47
|
-
* Asynchronously evaluates the given expression.
|
|
48
|
-
* @param expression The expression to evaluate.
|
|
49
|
-
* @param context The evaluation context.
|
|
50
|
-
* @param options The evaluation options.
|
|
51
|
-
* @returns A promise that resolves to the result of the evaluation.
|
|
52
|
-
*/
|
|
53
|
-
simpleEvalAsync(expression: string | AnyNode | undefined, context?: EvalContext | Context, options?: EvalOptions): Promise<unknown | undefined>;
|
|
54
|
-
/**
|
|
55
|
-
* Asynchronously evaluates an expression using the provided state.
|
|
56
|
-
*
|
|
57
|
-
* @param expression - The expression to evaluate. Can be a string or an AST node.
|
|
58
|
-
* @param state - The evaluation state.
|
|
59
|
-
* @returns A promise that resolves to the result of the evaluation.
|
|
60
|
-
* @throws If an error occurs during evaluation.
|
|
61
|
-
*/
|
|
62
|
-
evalAsync(expression: string | AnyNode | undefined, state: EvalState): Promise<unknown | undefined>;
|
|
63
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<EvalService, never>;
|
|
64
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<EvalService>;
|
|
65
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './public-api';
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { OnDestroy } from '@angular/core';
|
|
2
|
-
import { ParserOptions } from '../../internal/interfaces';
|
|
3
|
-
import { Expression, Program, AnyNode } from 'acorn';
|
|
4
|
-
import * as i0 from "@angular/core";
|
|
5
|
-
/**
|
|
6
|
-
* @description
|
|
7
|
-
* Service for parsing expressions and returning ES6/ES2020 AST.
|
|
8
|
-
* Implements OnDestroy for proper memory cleanup.
|
|
9
|
-
*/
|
|
10
|
-
export declare class ParserService implements OnDestroy {
|
|
11
|
-
private _parserOptions;
|
|
12
|
-
private _cache?;
|
|
13
|
-
private _cacheCleanupInterval?;
|
|
14
|
-
private _isDestroyed;
|
|
15
|
-
/**
|
|
16
|
-
* Gets the parser options.
|
|
17
|
-
*/
|
|
18
|
-
get parserOptions(): ParserOptions;
|
|
19
|
-
/**
|
|
20
|
-
* Sets the parser options.
|
|
21
|
-
* @param value The parser options to set.
|
|
22
|
-
*/
|
|
23
|
-
set parserOptions(value: ParserOptions);
|
|
24
|
-
/**
|
|
25
|
-
* Constructs a new instance of the ParserService class.
|
|
26
|
-
*/
|
|
27
|
-
constructor();
|
|
28
|
-
/**
|
|
29
|
-
* Setup periodic cache cleanup to prevent memory leaks
|
|
30
|
-
*/
|
|
31
|
-
private setupCacheCleanup;
|
|
32
|
-
/**
|
|
33
|
-
* Clean up resources to prevent memory leaks
|
|
34
|
-
*/
|
|
35
|
-
ngOnDestroy(): void;
|
|
36
|
-
/**
|
|
37
|
-
* @description
|
|
38
|
-
* Returns acorn version.
|
|
39
|
-
*/
|
|
40
|
-
get version(): string;
|
|
41
|
-
/**
|
|
42
|
-
* Gets the parser options.
|
|
43
|
-
* @returns The parser options.
|
|
44
|
-
*/
|
|
45
|
-
get options(): ParserOptions;
|
|
46
|
-
/**
|
|
47
|
-
* @description
|
|
48
|
-
* Parses expression and returns ES6/ES2023 AST.
|
|
49
|
-
* @param expr expression to parse
|
|
50
|
-
* @param options optional parser options
|
|
51
|
-
* @returns The parsed AST (Abstract Syntax Tree).
|
|
52
|
-
*/
|
|
53
|
-
parse(expr: string, options?: ParserOptions): Program | AnyNode | Expression | undefined;
|
|
54
|
-
private fromCacheOrParse;
|
|
55
|
-
static ɵfac: i0.ɵɵFactoryDeclaration<ParserService, never>;
|
|
56
|
-
static ɵprov: i0.ɵɵInjectableDeclaration<ParserService>;
|
|
57
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
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
|
-
/**
|
|
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>;
|
|
84
|
-
}
|
|
@@ -1,91 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
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
|
-
/**
|
|
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>;
|
|
85
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
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
|
-
export declare function isRegistryContext(context?: Context): boolean;
|
|
6
|
-
/**
|
|
7
|
-
* Converts a context object to a Context instance.
|
|
8
|
-
* @param context - The context object to convert.
|
|
9
|
-
* @param options - Optional evaluation options.
|
|
10
|
-
* @returns The converted Context instance.
|
|
11
|
-
*/
|
|
12
|
-
export declare const fromContext: (context?: Context, options?: EvalOptions) => Context;
|
|
13
|
-
/**
|
|
14
|
-
* Retrieves the value associated with the specified key from the given context.
|
|
15
|
-
* If the context is an instance of Registry, it uses the `get` method to retrieve the value.
|
|
16
|
-
* If the context is an object, it accesses the value using the key as a property name.
|
|
17
|
-
* If the context is neither an instance of Registry nor an object, it returns undefined.
|
|
18
|
-
*
|
|
19
|
-
* @param context The context from which to retrieve the value.
|
|
20
|
-
* @param key The key associated with the value to retrieve.
|
|
21
|
-
* @returns The value associated with the specified key, or undefined if not found.
|
|
22
|
-
*/
|
|
23
|
-
export declare const getContextValue: (context?: Context, key?: unknown) => unknown;
|
|
24
|
-
/**
|
|
25
|
-
* Sets a value in the given context object.
|
|
26
|
-
* If the context is an instance of Registry, the value is set using the key.
|
|
27
|
-
* If the context is a plain object, the value is set using the key as a property name.
|
|
28
|
-
* @param context - The context object.
|
|
29
|
-
* @param key - The key or property name.
|
|
30
|
-
* @param value - The value to be set.
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './public-api';
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { BaseRegistry } from './base-registry';
|
|
2
|
-
export { CaseInsensitiveRegistry } from './case-insensitive-registry';
|
|
3
|
-
export { Registry } from './registry';
|
|
4
|
-
export { Queue } from './queue';
|
|
5
|
-
export { Stack } from './stack';
|
|
6
|
-
export { Cache } from './cache';
|
|
7
|
-
export { BaseContext, Context, isRegistryContext, fromContext, getContextValue, getContextKey } from './context';
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
}
|