@nocobase/evaluators 0.19.0-alpha.6 → 0.19.0-alpha.7

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.
Files changed (2) hide show
  1. package/lib/utils/index.js +10 -31
  2. package/package.json +3 -3
@@ -36,44 +36,23 @@ function appendArrayColumn(scope, key) {
36
36
  }
37
37
  }
38
38
  __name(appendArrayColumn, "appendArrayColumn");
39
- function replaceNumberIndex(path, scope) {
40
- const segments = path.split(".");
41
- const paths = [];
42
- for (let i = 0; i < segments.length; i++) {
43
- const p = segments[i];
44
- if (p[0] && "0123456789".indexOf(p[0]) > -1) {
45
- paths.push(Array.isArray((0, import_lodash.get)(scope, segments.slice(0, i))) ? `[${p}]` : `["${p}"]`);
46
- } else {
47
- if (i) {
48
- paths.push(".", p);
49
- } else {
50
- paths.push(p);
51
- }
52
- }
53
- }
54
- return paths.join("");
55
- }
56
- __name(replaceNumberIndex, "replaceNumberIndex");
57
39
  function evaluate(expression, scope = {}) {
58
40
  const context = (0, import_lodash.cloneDeep)(scope);
41
+ const newContext = {};
59
42
  const exp = expression.trim().replace(/{{\s*([^{}]+)\s*}}/g, (_, v) => {
60
43
  appendArrayColumn(context, v);
61
- const item = (0, import_lodash.get)(context, v);
62
- let result;
63
- if (item == null) {
64
- result = "null";
65
- } else if (typeof item === "function") {
66
- result = item();
67
- result = typeof result === "string" ? `'${result.replace(/'/g, "\\'")}'` : result;
68
- } else {
69
- result = replaceNumberIndex(v, context);
44
+ let item = (0, import_lodash.get)(context, v);
45
+ if (typeof item === "function") {
46
+ item = item();
70
47
  }
71
- if (result instanceof Date) {
72
- result = `'${result.toISOString()}'`;
48
+ const randomKey = `$$${Math.random().toString(36).slice(2, 10).padEnd(8, "0")}`;
49
+ if (item == null) {
50
+ return "null";
73
51
  }
74
- return ` ${result} `;
52
+ newContext[randomKey] = item;
53
+ return ` ${randomKey} `;
75
54
  });
76
- return this(exp, context);
55
+ return this(exp, newContext);
77
56
  }
78
57
  __name(evaluate, "evaluate");
79
58
  // Annotate the CommonJS export names for ESM import in node:
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@nocobase/evaluators",
3
- "version": "0.19.0-alpha.6",
3
+ "version": "0.19.0-alpha.7",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
7
7
  "license": "Apache-2.0",
8
8
  "dependencies": {
9
9
  "@formulajs/formulajs": "4.2.0",
10
- "@nocobase/utils": "0.19.0-alpha.6",
10
+ "@nocobase/utils": "0.19.0-alpha.7",
11
11
  "mathjs": "^10.6.0"
12
12
  },
13
13
  "repository": {
@@ -15,5 +15,5 @@
15
15
  "url": "git+https://github.com/nocobase/nocobase.git",
16
16
  "directory": "packages/evaluators"
17
17
  },
18
- "gitHead": "2eb524db98c7f4136fe1a9a1b1259cd72cf6635f"
18
+ "gitHead": "cbbfd4de14b8f73417e613af6927d2fbbdbd2b41"
19
19
  }