@briza/illogical 1.7.0 → 1.7.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@briza/illogical",
3
- "version": "1.7.0",
3
+ "version": "1.7.2",
4
4
  "description": "A micro conditional javascript engine used to parse the raw logical and comparison expressions, evaluate the expression in the given data context, and provide access to a text form of the given expressions.",
5
5
  "main": "lib/illogical.js",
6
6
  "module": "lib/illogical.esm.js",
package/readme.md CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  A micro conditional javascript engine used to parse the raw logical and comparison expressions, evaluate the expression in the given data context, and provide access to a text form of the given expressions.
4
4
 
5
- > Revision: March 22, 2022.
6
-
7
5
  ## About
8
6
 
9
7
  This project has been developed to provide a shared conditional logic between front-end and back-end code, stored in JSON or in any other data serialization format.
@@ -224,19 +222,6 @@ engine.simplify(
224
222
  ) // ['==', '$b', 20]
225
223
  ```
226
224
 
227
- ### Unsafe Simplify
228
-
229
- Simplifies an expression with a given context, but without parsing and ensuring the condition is
230
- syntatically correct. This can be used in situations where you can decouple the parsing from
231
- the simplification and extra performance is needed in runtime.
232
-
233
- ```js
234
- engine.unsafeSimplify(
235
- ['OR', ['==', '$a', 10], ['==', '$b', 20], ['==', '$c', 20]],
236
- { a: 10 }
237
- ) // true due to $a. Expressions for $b and $c won't even be parsed.
238
- ```
239
-
240
225
  ## Working with Expressions
241
226
 
242
227
  ### Evaluation Data Context
@@ -35,13 +35,15 @@ export interface Evaluable {
35
35
  * Simplifies this Evaluable when possible.
36
36
  *
37
37
  * @param {Context} ctx context for the evaluation
38
- * @param {string[]} strictKeys keys to be considered present even if they are not present in the context
39
- * @param {string[]} optionalKeys keys to be considered not present unless they are in the context or in
38
+ * @param {string[] | Set<string>} strictKeys keys to be considered present even if they are not present in the
39
+ * context. Passing as a Set is recommended for performance reasons.
40
+ * @param {string[] | Set<string>} optionalKeys keys to be considered not present unless they are in the context or in
40
41
  * `strictKeys`; when `strictKeys` is `undefined` and `optionalKeys` is an array, every key that is not in
41
- * `optionalKeys` is considered to be present and thus will be evaluated
42
+ * `optionalKeys` is considered to be present and thus will be evaluated. Passing as a Set is recommended for
43
+ * performance reasons.
42
44
  * @returns {Result | Evaluable} simplified value or itself
43
45
  */
44
- simplify(ctx: Context, strictKeys?: string[], optionalKeys?: string[]): Result | Evaluable;
46
+ simplify(ctx: Context, strictKeys?: string[] | Set<string>, optionalKeys?: string[] | Set<string>): Result | Evaluable;
45
47
  /**
46
48
  * Serializes the Evaluable to its input format.
47
49
  *
@@ -22,7 +22,7 @@ export declare abstract class Logical implements Evaluable {
22
22
  /**
23
23
  * {@link Evaluable.simplify}
24
24
  */
25
- abstract simplify(ctx: Context, strictKeys?: string[], optionalKeys?: string[]): Result | Evaluable;
25
+ abstract simplify(ctx: Context, strictKeys?: string[] | Set<string>, optionalKeys?: string[] | Set<string>): Result | Evaluable;
26
26
  /**
27
27
  * Get the strict representation of the expression.
28
28
  * @return {string}
package/types/index.d.ts CHANGED
@@ -68,13 +68,14 @@ declare class Engine {
68
68
  *
69
69
  * @param {ExpressionInput} exp Raw expression.
70
70
  * @param {Context} context Evaluation data context.
71
- * @param {string[]} strictKeys keys to be considered present even if they are not present in the context
72
- * @param {string[]} optionalKeys keys to be considered not present unless they are in the context or in
71
+ * @param {string[] | Set<string>} strictKeys keys to be considered present even if they are not present in the
72
+ * context. Passing as a Set is recommended for performance reasons.
73
+ * @param {string[] | Set<string>} optionalKeys keys to be considered not present unless they are in the context or in
73
74
  * `strictKeys`; when `strictKeys` is `undefined` and `optionalKeys` is an array, every key that is not in
74
- * `optionalKeys` is considered to be present and thus will be evaluated
75
+ * `optionalKeys` is considered to be present and thus will be evaluated. Passing as a Set is recommended for
76
+ * performance reasons.
75
77
  * @returns {Inpunt | boolean}
76
78
  */
77
- simplify(exp: ExpressionInput, context: Context, strictKeys?: string[], optionalKeys?: string[]): Input | boolean;
78
- unsafeSimplify(exp: ExpressionInput, context: Context, strictKeys?: string[], optionalKeys?: string[]): Input | boolean;
79
+ simplify(exp: ExpressionInput, context: Context, strictKeys?: string[] | Set<string>, optionalKeys?: string[] | Set<string>): Input | boolean;
79
80
  }
80
81
  export default Engine;
@@ -13,7 +13,7 @@ export declare abstract class Operand implements Evaluable {
13
13
  /**
14
14
  * {@link Evaluable.simplify}
15
15
  */
16
- abstract simplify(ctx: Context, strictKeys?: string[], optionalKeys?: string[]): Result | Evaluable;
16
+ abstract simplify(ctx: Context, strictKeys?: string[] | Set<string>, optionalKeys?: string[] | Set<string>): Result | Evaluable;
17
17
  /**
18
18
  * {@link Evaluable.serialize}
19
19
  */
@@ -24,10 +24,11 @@ export declare class Reference extends Operand {
24
24
  * @return {boolean}
25
25
  */
26
26
  evaluate(ctx: Context): Result;
27
+ private checkStrictAndOptional;
27
28
  /**
28
29
  * {@link Evaluable.simplify}
29
30
  */
30
- simplify(ctx: Context, strictKeys?: string[], optionalKeys?: string[]): Result | Evaluable;
31
+ simplify(ctx: Context, strictKeys?: string[] | Set<string>, optionalKeys?: string[] | Set<string>): Result | Evaluable;
31
32
  /**
32
33
  * {@link Evaluable.serialize}
33
34
  */
@@ -10,6 +10,7 @@ export declare class Parser {
10
10
  private readonly opts;
11
11
  private readonly expectedRootOperators;
12
12
  private readonly unexpectedRootSymbols;
13
+ private readonly referenceCache;
13
14
  /**
14
15
  * @constructor
15
16
  * @param {Options?} options Parser options.
@@ -20,6 +21,8 @@ export declare class Parser {
20
21
  * @type {Options}
21
22
  */
22
23
  get options(): Options;
24
+ private getReference;
25
+ private resolve;
23
26
  /**
24
27
  * Parse raw expression into evaluable expression.
25
28
  * @param {ExpressionInput} raw Raw expression.
@@ -1,4 +1,4 @@
1
1
  import { Context, Evaluable } from '../common/evaluable';
2
2
  import { Input } from '../parser';
3
3
  import { Options } from '../parser/options';
4
- export declare const unsafeSimplify: (context: Context, opts: Options, strictKeys?: string[], optionalKeys?: string[]) => (input: Input) => Input | Evaluable;
4
+ export declare const unsafeSimplify: (context: Context, opts: Options, strictKeys?: Set<string>, optionalKeys?: Set<string>) => (input: Input) => Input | Evaluable;