@axi-engine/expressions 0.2.3 → 0.2.4
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/dist/index.d.mts +73 -55
- package/dist/index.d.ts +73 -55
- package/dist/index.js +53 -18
- package/dist/index.mjs +50 -16
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -302,6 +302,53 @@ interface ExpressionEvaluatorContext {
|
|
|
302
302
|
*/
|
|
303
303
|
source(): DataSource;
|
|
304
304
|
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Defines the contract for a class that can evaluate a specific type of expression.
|
|
308
|
+
*
|
|
309
|
+
* Each expression type in the system (e.g., `comparison`, `and`, `in`) must have a
|
|
310
|
+
* corresponding class that implements this interface. The `ExpressionEvaluator` uses these
|
|
311
|
+
* handlers to delegate the actual evaluation logic.
|
|
312
|
+
*
|
|
313
|
+
* @interface
|
|
314
|
+
* @template T - The specific `Expression` subtype that this handler is responsible for.
|
|
315
|
+
* This provides strong typing within the `resolve` method.
|
|
316
|
+
*/
|
|
317
|
+
interface ExpressionHandler<T extends Expression = Expression> {
|
|
318
|
+
/**
|
|
319
|
+
* The unique key for the expression type this handler processes.
|
|
320
|
+
* This must match one of the keys in the `ExpressionDefinitions` interface.
|
|
321
|
+
*/
|
|
322
|
+
type: ExpressionName;
|
|
323
|
+
/**
|
|
324
|
+
* The core evaluation logic for the expression.
|
|
325
|
+
*
|
|
326
|
+
* @param exp The specific expression object to be evaluated, strongly typed to `T`.
|
|
327
|
+
* @param context The `ExpressionEvaluatorContext` which provides tools for the
|
|
328
|
+
* handler, such as a way to recursively resolve child expressions or access the
|
|
329
|
+
* data source.
|
|
330
|
+
* @returns {Promise<boolean>} A promise that resolves to the boolean result of the evaluation.
|
|
331
|
+
*/
|
|
332
|
+
resolve(exp: T, context: ExpressionEvaluatorContext): Promise<boolean>;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
*
|
|
337
|
+
* Defines the contract for an engine capable of evaluating logical expression trees.
|
|
338
|
+
*
|
|
339
|
+
* @interface
|
|
340
|
+
*/
|
|
341
|
+
interface ExpressionEvaluator {
|
|
342
|
+
/**
|
|
343
|
+
* Evaluates a logical expression against a provided data source.
|
|
344
|
+
*
|
|
345
|
+
* @param expression The expression tree to evaluate.
|
|
346
|
+
* @param data The data source used to resolve variable references within the expression.
|
|
347
|
+
* @returns A promise that resolves to `true` or `false` based on the evaluation result.
|
|
348
|
+
*/
|
|
349
|
+
resolve(expression: Expression, data: DataSource): Promise<boolean>;
|
|
350
|
+
}
|
|
351
|
+
|
|
305
352
|
/**
|
|
306
353
|
* The class responsible for evaluating expression trees.
|
|
307
354
|
*
|
|
@@ -315,7 +362,7 @@ interface ExpressionEvaluatorContext {
|
|
|
315
362
|
*
|
|
316
363
|
* @class
|
|
317
364
|
*/
|
|
318
|
-
declare class ExpressionEvaluator {
|
|
365
|
+
declare class CoreExpressionEvaluator implements ExpressionEvaluator {
|
|
319
366
|
/** @internal A map of registered expression handlers. */
|
|
320
367
|
handlers: Registry<keyof ExpressionDefinitions, ExpressionHandler<Expression>>;
|
|
321
368
|
/**
|
|
@@ -344,35 +391,6 @@ declare class ExpressionEvaluator {
|
|
|
344
391
|
resolve(expression: Expression, data: DataSource): Promise<boolean>;
|
|
345
392
|
}
|
|
346
393
|
|
|
347
|
-
/**
|
|
348
|
-
* Defines the contract for a class that can evaluate a specific type of expression.
|
|
349
|
-
*
|
|
350
|
-
* Each expression type in the system (e.g., `comparison`, `and`, `in`) must have a
|
|
351
|
-
* corresponding class that implements this interface. The `ExpressionEvaluator` uses these
|
|
352
|
-
* handlers to delegate the actual evaluation logic.
|
|
353
|
-
*
|
|
354
|
-
* @interface
|
|
355
|
-
* @template T - The specific `Expression` subtype that this handler is responsible for.
|
|
356
|
-
* This provides strong typing within the `resolve` method.
|
|
357
|
-
*/
|
|
358
|
-
interface ExpressionHandler<T extends Expression = Expression> {
|
|
359
|
-
/**
|
|
360
|
-
* The unique key for the expression type this handler processes.
|
|
361
|
-
* This must match one of the keys in the `ExpressionDefinitions` interface.
|
|
362
|
-
*/
|
|
363
|
-
type: ExpressionName;
|
|
364
|
-
/**
|
|
365
|
-
* The core evaluation logic for the expression.
|
|
366
|
-
*
|
|
367
|
-
* @param exp The specific expression object to be evaluated, strongly typed to `T`.
|
|
368
|
-
* @param context The `ExpressionEvaluatorContext` which provides tools for the
|
|
369
|
-
* handler, such as a way to recursively resolve child expressions or access the
|
|
370
|
-
* data source.
|
|
371
|
-
* @returns {Promise<boolean>} A promise that resolves to the boolean result of the evaluation.
|
|
372
|
-
*/
|
|
373
|
-
resolve(exp: T, context: ExpressionEvaluatorContext): Promise<boolean>;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
394
|
declare class AndExpressionHandler implements ExpressionHandler<AndExpression> {
|
|
377
395
|
type: ExpressionName;
|
|
378
396
|
resolve(exp: AndExpression, context: ExpressionEvaluatorContext): Promise<boolean>;
|
|
@@ -461,30 +479,30 @@ declare class OrExpressionHandler implements ExpressionHandler<OrExpression> {
|
|
|
461
479
|
}
|
|
462
480
|
|
|
463
481
|
/**
|
|
464
|
-
* A
|
|
465
|
-
*
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
*
|
|
486
|
-
*
|
|
482
|
+
* A builder class for configuring and creating a `CoreExpressionEvaluator`.
|
|
483
|
+
* Allows enabling standard handlers or registering custom ones via a fluent API.
|
|
484
|
+
*/
|
|
485
|
+
declare class ExpressionEvaluatorBuilder {
|
|
486
|
+
private handlers;
|
|
487
|
+
/**
|
|
488
|
+
* Adds the complete set of standard expression handlers to the configuration.
|
|
489
|
+
* This is the recommended starting point for most applications.
|
|
490
|
+
*/
|
|
491
|
+
withDefaults(): this;
|
|
492
|
+
/**
|
|
493
|
+
* Registers one or more custom expression handlers.
|
|
494
|
+
* @param handler A single handler instance or an array of handlers.
|
|
495
|
+
*/
|
|
496
|
+
add(handler: ExpressionHandler | ExpressionHandler[]): this;
|
|
497
|
+
/**
|
|
498
|
+
* @return CoreExpressionEvaluator
|
|
499
|
+
*/
|
|
500
|
+
build(): CoreExpressionEvaluator;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Entry point to start configuring the expression evaluator.
|
|
504
|
+
* @returns A new builder instance.
|
|
487
505
|
*/
|
|
488
|
-
declare function
|
|
506
|
+
declare function configureExpressions(): ExpressionEvaluatorBuilder;
|
|
489
507
|
|
|
490
|
-
export { type AndExpression, AndExpressionHandler, type ArithmeticOperand, type ChanceExpression, ChanceExpressionHandler, type ComparisonExpression, ComparisonExpressionHandler, type ComparisonOperationType, type ExistsExpression, ExistsExpressionHandler, type Expression, type ExpressionDefinitions, ExpressionEvaluator, type ExpressionEvaluatorContext, type ExpressionHandler, type ExpressionName, type InExpression, InExpressionHandler, type LiteralExpression, LiteralExpressionHandler, type MathOperationType, type NotExpression, NotExpressionHandler, type Operand, type OrExpression, OrExpressionHandler, type ReferenceOperand, type ValueOperand,
|
|
508
|
+
export { type AndExpression, AndExpressionHandler, type ArithmeticOperand, type ChanceExpression, ChanceExpressionHandler, type ComparisonExpression, ComparisonExpressionHandler, type ComparisonOperationType, CoreExpressionEvaluator, type ExistsExpression, ExistsExpressionHandler, type Expression, type ExpressionDefinitions, type ExpressionEvaluator, ExpressionEvaluatorBuilder, type ExpressionEvaluatorContext, type ExpressionHandler, type ExpressionName, type InExpression, InExpressionHandler, type LiteralExpression, LiteralExpressionHandler, type MathOperationType, type NotExpression, NotExpressionHandler, type Operand, type OrExpression, OrExpressionHandler, type ReferenceOperand, type ValueOperand, configureExpressions, isArithmeticOperand, isOperand, isReferenceOperand, isValueOperand, resolveMath, resolveOperand, resolveOperandAsScalar };
|
package/dist/index.d.ts
CHANGED
|
@@ -302,6 +302,53 @@ interface ExpressionEvaluatorContext {
|
|
|
302
302
|
*/
|
|
303
303
|
source(): DataSource;
|
|
304
304
|
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Defines the contract for a class that can evaluate a specific type of expression.
|
|
308
|
+
*
|
|
309
|
+
* Each expression type in the system (e.g., `comparison`, `and`, `in`) must have a
|
|
310
|
+
* corresponding class that implements this interface. The `ExpressionEvaluator` uses these
|
|
311
|
+
* handlers to delegate the actual evaluation logic.
|
|
312
|
+
*
|
|
313
|
+
* @interface
|
|
314
|
+
* @template T - The specific `Expression` subtype that this handler is responsible for.
|
|
315
|
+
* This provides strong typing within the `resolve` method.
|
|
316
|
+
*/
|
|
317
|
+
interface ExpressionHandler<T extends Expression = Expression> {
|
|
318
|
+
/**
|
|
319
|
+
* The unique key for the expression type this handler processes.
|
|
320
|
+
* This must match one of the keys in the `ExpressionDefinitions` interface.
|
|
321
|
+
*/
|
|
322
|
+
type: ExpressionName;
|
|
323
|
+
/**
|
|
324
|
+
* The core evaluation logic for the expression.
|
|
325
|
+
*
|
|
326
|
+
* @param exp The specific expression object to be evaluated, strongly typed to `T`.
|
|
327
|
+
* @param context The `ExpressionEvaluatorContext` which provides tools for the
|
|
328
|
+
* handler, such as a way to recursively resolve child expressions or access the
|
|
329
|
+
* data source.
|
|
330
|
+
* @returns {Promise<boolean>} A promise that resolves to the boolean result of the evaluation.
|
|
331
|
+
*/
|
|
332
|
+
resolve(exp: T, context: ExpressionEvaluatorContext): Promise<boolean>;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
*
|
|
337
|
+
* Defines the contract for an engine capable of evaluating logical expression trees.
|
|
338
|
+
*
|
|
339
|
+
* @interface
|
|
340
|
+
*/
|
|
341
|
+
interface ExpressionEvaluator {
|
|
342
|
+
/**
|
|
343
|
+
* Evaluates a logical expression against a provided data source.
|
|
344
|
+
*
|
|
345
|
+
* @param expression The expression tree to evaluate.
|
|
346
|
+
* @param data The data source used to resolve variable references within the expression.
|
|
347
|
+
* @returns A promise that resolves to `true` or `false` based on the evaluation result.
|
|
348
|
+
*/
|
|
349
|
+
resolve(expression: Expression, data: DataSource): Promise<boolean>;
|
|
350
|
+
}
|
|
351
|
+
|
|
305
352
|
/**
|
|
306
353
|
* The class responsible for evaluating expression trees.
|
|
307
354
|
*
|
|
@@ -315,7 +362,7 @@ interface ExpressionEvaluatorContext {
|
|
|
315
362
|
*
|
|
316
363
|
* @class
|
|
317
364
|
*/
|
|
318
|
-
declare class ExpressionEvaluator {
|
|
365
|
+
declare class CoreExpressionEvaluator implements ExpressionEvaluator {
|
|
319
366
|
/** @internal A map of registered expression handlers. */
|
|
320
367
|
handlers: Registry<keyof ExpressionDefinitions, ExpressionHandler<Expression>>;
|
|
321
368
|
/**
|
|
@@ -344,35 +391,6 @@ declare class ExpressionEvaluator {
|
|
|
344
391
|
resolve(expression: Expression, data: DataSource): Promise<boolean>;
|
|
345
392
|
}
|
|
346
393
|
|
|
347
|
-
/**
|
|
348
|
-
* Defines the contract for a class that can evaluate a specific type of expression.
|
|
349
|
-
*
|
|
350
|
-
* Each expression type in the system (e.g., `comparison`, `and`, `in`) must have a
|
|
351
|
-
* corresponding class that implements this interface. The `ExpressionEvaluator` uses these
|
|
352
|
-
* handlers to delegate the actual evaluation logic.
|
|
353
|
-
*
|
|
354
|
-
* @interface
|
|
355
|
-
* @template T - The specific `Expression` subtype that this handler is responsible for.
|
|
356
|
-
* This provides strong typing within the `resolve` method.
|
|
357
|
-
*/
|
|
358
|
-
interface ExpressionHandler<T extends Expression = Expression> {
|
|
359
|
-
/**
|
|
360
|
-
* The unique key for the expression type this handler processes.
|
|
361
|
-
* This must match one of the keys in the `ExpressionDefinitions` interface.
|
|
362
|
-
*/
|
|
363
|
-
type: ExpressionName;
|
|
364
|
-
/**
|
|
365
|
-
* The core evaluation logic for the expression.
|
|
366
|
-
*
|
|
367
|
-
* @param exp The specific expression object to be evaluated, strongly typed to `T`.
|
|
368
|
-
* @param context The `ExpressionEvaluatorContext` which provides tools for the
|
|
369
|
-
* handler, such as a way to recursively resolve child expressions or access the
|
|
370
|
-
* data source.
|
|
371
|
-
* @returns {Promise<boolean>} A promise that resolves to the boolean result of the evaluation.
|
|
372
|
-
*/
|
|
373
|
-
resolve(exp: T, context: ExpressionEvaluatorContext): Promise<boolean>;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
394
|
declare class AndExpressionHandler implements ExpressionHandler<AndExpression> {
|
|
377
395
|
type: ExpressionName;
|
|
378
396
|
resolve(exp: AndExpression, context: ExpressionEvaluatorContext): Promise<boolean>;
|
|
@@ -461,30 +479,30 @@ declare class OrExpressionHandler implements ExpressionHandler<OrExpression> {
|
|
|
461
479
|
}
|
|
462
480
|
|
|
463
481
|
/**
|
|
464
|
-
* A
|
|
465
|
-
*
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
*
|
|
486
|
-
*
|
|
482
|
+
* A builder class for configuring and creating a `CoreExpressionEvaluator`.
|
|
483
|
+
* Allows enabling standard handlers or registering custom ones via a fluent API.
|
|
484
|
+
*/
|
|
485
|
+
declare class ExpressionEvaluatorBuilder {
|
|
486
|
+
private handlers;
|
|
487
|
+
/**
|
|
488
|
+
* Adds the complete set of standard expression handlers to the configuration.
|
|
489
|
+
* This is the recommended starting point for most applications.
|
|
490
|
+
*/
|
|
491
|
+
withDefaults(): this;
|
|
492
|
+
/**
|
|
493
|
+
* Registers one or more custom expression handlers.
|
|
494
|
+
* @param handler A single handler instance or an array of handlers.
|
|
495
|
+
*/
|
|
496
|
+
add(handler: ExpressionHandler | ExpressionHandler[]): this;
|
|
497
|
+
/**
|
|
498
|
+
* @return CoreExpressionEvaluator
|
|
499
|
+
*/
|
|
500
|
+
build(): CoreExpressionEvaluator;
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Entry point to start configuring the expression evaluator.
|
|
504
|
+
* @returns A new builder instance.
|
|
487
505
|
*/
|
|
488
|
-
declare function
|
|
506
|
+
declare function configureExpressions(): ExpressionEvaluatorBuilder;
|
|
489
507
|
|
|
490
|
-
export { type AndExpression, AndExpressionHandler, type ArithmeticOperand, type ChanceExpression, ChanceExpressionHandler, type ComparisonExpression, ComparisonExpressionHandler, type ComparisonOperationType, type ExistsExpression, ExistsExpressionHandler, type Expression, type ExpressionDefinitions, ExpressionEvaluator, type ExpressionEvaluatorContext, type ExpressionHandler, type ExpressionName, type InExpression, InExpressionHandler, type LiteralExpression, LiteralExpressionHandler, type MathOperationType, type NotExpression, NotExpressionHandler, type Operand, type OrExpression, OrExpressionHandler, type ReferenceOperand, type ValueOperand,
|
|
508
|
+
export { type AndExpression, AndExpressionHandler, type ArithmeticOperand, type ChanceExpression, ChanceExpressionHandler, type ComparisonExpression, ComparisonExpressionHandler, type ComparisonOperationType, CoreExpressionEvaluator, type ExistsExpression, ExistsExpressionHandler, type Expression, type ExpressionDefinitions, type ExpressionEvaluator, ExpressionEvaluatorBuilder, type ExpressionEvaluatorContext, type ExpressionHandler, type ExpressionName, type InExpression, InExpressionHandler, type LiteralExpression, LiteralExpressionHandler, type MathOperationType, type NotExpression, NotExpressionHandler, type Operand, type OrExpression, OrExpressionHandler, type ReferenceOperand, type ValueOperand, configureExpressions, isArithmeticOperand, isOperand, isReferenceOperand, isValueOperand, resolveMath, resolveOperand, resolveOperandAsScalar };
|
package/dist/index.js
CHANGED
|
@@ -23,13 +23,14 @@ __export(index_exports, {
|
|
|
23
23
|
AndExpressionHandler: () => AndExpressionHandler,
|
|
24
24
|
ChanceExpressionHandler: () => ChanceExpressionHandler,
|
|
25
25
|
ComparisonExpressionHandler: () => ComparisonExpressionHandler,
|
|
26
|
+
CoreExpressionEvaluator: () => CoreExpressionEvaluator,
|
|
26
27
|
ExistsExpressionHandler: () => ExistsExpressionHandler,
|
|
27
|
-
|
|
28
|
+
ExpressionEvaluatorBuilder: () => ExpressionEvaluatorBuilder,
|
|
28
29
|
InExpressionHandler: () => InExpressionHandler,
|
|
29
30
|
LiteralExpressionHandler: () => LiteralExpressionHandler,
|
|
30
31
|
NotExpressionHandler: () => NotExpressionHandler,
|
|
31
32
|
OrExpressionHandler: () => OrExpressionHandler,
|
|
32
|
-
|
|
33
|
+
configureExpressions: () => configureExpressions,
|
|
33
34
|
isArithmeticOperand: () => isArithmeticOperand,
|
|
34
35
|
isOperand: () => isOperand,
|
|
35
36
|
isReferenceOperand: () => isReferenceOperand,
|
|
@@ -101,9 +102,9 @@ function resolveOperandAsScalar(op, source) {
|
|
|
101
102
|
return value;
|
|
102
103
|
}
|
|
103
104
|
|
|
104
|
-
// src/expression-evaluator.ts
|
|
105
|
+
// src/core-expression-evaluator.ts
|
|
105
106
|
var import_utils4 = require("@axi-engine/utils");
|
|
106
|
-
var
|
|
107
|
+
var CoreExpressionEvaluator = class {
|
|
107
108
|
/** @internal A map of registered expression handlers. */
|
|
108
109
|
handlers = new import_utils4.Registry();
|
|
109
110
|
/**
|
|
@@ -287,31 +288,65 @@ var OrExpressionHandler = class {
|
|
|
287
288
|
};
|
|
288
289
|
|
|
289
290
|
// src/setup.ts
|
|
290
|
-
function
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
291
|
+
function createDefaultExpressionHandlers() {
|
|
292
|
+
return [
|
|
293
|
+
new AndExpressionHandler(),
|
|
294
|
+
new ChanceExpressionHandler(),
|
|
295
|
+
new ComparisonExpressionHandler(),
|
|
296
|
+
new ExistsExpressionHandler(),
|
|
297
|
+
new InExpressionHandler(),
|
|
298
|
+
new LiteralExpressionHandler(),
|
|
299
|
+
new NotExpressionHandler(),
|
|
300
|
+
new OrExpressionHandler()
|
|
301
|
+
];
|
|
302
|
+
}
|
|
303
|
+
var ExpressionEvaluatorBuilder = class {
|
|
304
|
+
handlers = [];
|
|
305
|
+
/**
|
|
306
|
+
* Adds the complete set of standard expression handlers to the configuration.
|
|
307
|
+
* This is the recommended starting point for most applications.
|
|
308
|
+
*/
|
|
309
|
+
withDefaults() {
|
|
310
|
+
this.handlers.push(...createDefaultExpressionHandlers());
|
|
311
|
+
return this;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Registers one or more custom expression handlers.
|
|
315
|
+
* @param handler A single handler instance or an array of handlers.
|
|
316
|
+
*/
|
|
317
|
+
add(handler) {
|
|
318
|
+
if (!Array.isArray(handler)) {
|
|
319
|
+
this.handlers.push(handler);
|
|
320
|
+
} else {
|
|
321
|
+
this.handlers.push(...handler);
|
|
322
|
+
}
|
|
323
|
+
return this;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* @return CoreExpressionEvaluator
|
|
327
|
+
*/
|
|
328
|
+
build() {
|
|
329
|
+
const evaluator = new CoreExpressionEvaluator();
|
|
330
|
+
this.handlers.forEach((handler) => evaluator.register(handler));
|
|
331
|
+
return evaluator;
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
function configureExpressions() {
|
|
335
|
+
return new ExpressionEvaluatorBuilder();
|
|
302
336
|
}
|
|
303
337
|
// Annotate the CommonJS export names for ESM import in node:
|
|
304
338
|
0 && (module.exports = {
|
|
305
339
|
AndExpressionHandler,
|
|
306
340
|
ChanceExpressionHandler,
|
|
307
341
|
ComparisonExpressionHandler,
|
|
342
|
+
CoreExpressionEvaluator,
|
|
308
343
|
ExistsExpressionHandler,
|
|
309
|
-
|
|
344
|
+
ExpressionEvaluatorBuilder,
|
|
310
345
|
InExpressionHandler,
|
|
311
346
|
LiteralExpressionHandler,
|
|
312
347
|
NotExpressionHandler,
|
|
313
348
|
OrExpressionHandler,
|
|
314
|
-
|
|
349
|
+
configureExpressions,
|
|
315
350
|
isArithmeticOperand,
|
|
316
351
|
isOperand,
|
|
317
352
|
isReferenceOperand,
|
package/dist/index.mjs
CHANGED
|
@@ -59,12 +59,12 @@ function resolveOperandAsScalar(op, source) {
|
|
|
59
59
|
return value;
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
// src/expression-evaluator.ts
|
|
62
|
+
// src/core-expression-evaluator.ts
|
|
63
63
|
import {
|
|
64
64
|
firstKeyOf,
|
|
65
65
|
Registry
|
|
66
66
|
} from "@axi-engine/utils";
|
|
67
|
-
var
|
|
67
|
+
var CoreExpressionEvaluator = class {
|
|
68
68
|
/** @internal A map of registered expression handlers. */
|
|
69
69
|
handlers = new Registry();
|
|
70
70
|
/**
|
|
@@ -248,30 +248,64 @@ var OrExpressionHandler = class {
|
|
|
248
248
|
};
|
|
249
249
|
|
|
250
250
|
// src/setup.ts
|
|
251
|
-
function
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
251
|
+
function createDefaultExpressionHandlers() {
|
|
252
|
+
return [
|
|
253
|
+
new AndExpressionHandler(),
|
|
254
|
+
new ChanceExpressionHandler(),
|
|
255
|
+
new ComparisonExpressionHandler(),
|
|
256
|
+
new ExistsExpressionHandler(),
|
|
257
|
+
new InExpressionHandler(),
|
|
258
|
+
new LiteralExpressionHandler(),
|
|
259
|
+
new NotExpressionHandler(),
|
|
260
|
+
new OrExpressionHandler()
|
|
261
|
+
];
|
|
262
|
+
}
|
|
263
|
+
var ExpressionEvaluatorBuilder = class {
|
|
264
|
+
handlers = [];
|
|
265
|
+
/**
|
|
266
|
+
* Adds the complete set of standard expression handlers to the configuration.
|
|
267
|
+
* This is the recommended starting point for most applications.
|
|
268
|
+
*/
|
|
269
|
+
withDefaults() {
|
|
270
|
+
this.handlers.push(...createDefaultExpressionHandlers());
|
|
271
|
+
return this;
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Registers one or more custom expression handlers.
|
|
275
|
+
* @param handler A single handler instance or an array of handlers.
|
|
276
|
+
*/
|
|
277
|
+
add(handler) {
|
|
278
|
+
if (!Array.isArray(handler)) {
|
|
279
|
+
this.handlers.push(handler);
|
|
280
|
+
} else {
|
|
281
|
+
this.handlers.push(...handler);
|
|
282
|
+
}
|
|
283
|
+
return this;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* @return CoreExpressionEvaluator
|
|
287
|
+
*/
|
|
288
|
+
build() {
|
|
289
|
+
const evaluator = new CoreExpressionEvaluator();
|
|
290
|
+
this.handlers.forEach((handler) => evaluator.register(handler));
|
|
291
|
+
return evaluator;
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
function configureExpressions() {
|
|
295
|
+
return new ExpressionEvaluatorBuilder();
|
|
263
296
|
}
|
|
264
297
|
export {
|
|
265
298
|
AndExpressionHandler,
|
|
266
299
|
ChanceExpressionHandler,
|
|
267
300
|
ComparisonExpressionHandler,
|
|
301
|
+
CoreExpressionEvaluator,
|
|
268
302
|
ExistsExpressionHandler,
|
|
269
|
-
|
|
303
|
+
ExpressionEvaluatorBuilder,
|
|
270
304
|
InExpressionHandler,
|
|
271
305
|
LiteralExpressionHandler,
|
|
272
306
|
NotExpressionHandler,
|
|
273
307
|
OrExpressionHandler,
|
|
274
|
-
|
|
308
|
+
configureExpressions,
|
|
275
309
|
isArithmeticOperand,
|
|
276
310
|
isOperand,
|
|
277
311
|
isReferenceOperand,
|