@marianmeres/condition-parser 1.3.0 → 1.5.0

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/parser.d.ts CHANGED
@@ -1,8 +1,14 @@
1
1
  import type { ConditionDump, ExpressionContext } from "@marianmeres/condition-builder";
2
+ interface ExpressionData {
3
+ key: string;
4
+ operator: string;
5
+ value: string;
6
+ }
2
7
  interface Meta {
3
8
  keys: string[];
4
9
  operators: string[];
5
10
  values: any[];
11
+ expressions: ExpressionData[];
6
12
  }
7
13
  /** ConditionParser.parse options */
8
14
  export interface ConditionParserOptions {
package/dist/parser.js CHANGED
@@ -20,13 +20,14 @@ export class ConditionParser {
20
20
  keys: new Set([]),
21
21
  operators: new Set([]),
22
22
  values: new Set([]),
23
+ expressions: new Set([]),
23
24
  };
24
25
  #transform;
25
26
  #preAddHook;
26
27
  constructor(input, options = {}) {
27
28
  input = `${input}`.trim();
28
- if (!input)
29
- throw new TypeError(`Expecting non empty input`);
29
+ // removing this... makes no sense
30
+ // if (!input) throw new TypeError(`Expecting non empty input`);
30
31
  const { defaultOperator = ConditionParser.DEFAULT_OPERATOR, debug = false, transform = (c) => c, preAddHook, } = options ?? {};
31
32
  this.#input = input;
32
33
  this.#length = input.length;
@@ -258,6 +259,8 @@ export class ConditionParser {
258
259
  this.#meta.keys.add(expression.key);
259
260
  this.#meta.operators.add(expression.operator);
260
261
  this.#meta.values.add(expression.value);
262
+ // need to make it unique... so just quick-n-dirty
263
+ this.#meta.expressions.add(JSON.stringify([expression.key, expression.operator, expression.value]));
261
264
  out.push(result);
262
265
  }
263
266
  /** Will recursively parse (...) */
@@ -387,6 +390,10 @@ export class ConditionParser {
387
390
  keys: [...parser.#meta.keys],
388
391
  operators: [...parser.#meta.operators],
389
392
  values: [...parser.#meta.values],
393
+ expressions: [...parser.#meta.expressions].map((v) => {
394
+ const [key, operator, value] = JSON.parse(v);
395
+ return { key, operator, value };
396
+ }),
390
397
  },
391
398
  };
392
399
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/condition-parser",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "type": "module",
5
5
  "main": "dist/mod.js",
6
6
  "types": "dist/mod.d.ts",