@entity-access/entity-access 1.0.496 → 1.0.498

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.
@@ -4,14 +4,9 @@ import { BabelVisitor } from "./BabelVisitor.js";
4
4
  import * as bpe from "@babel/types";
5
5
  import Restructure from "./Restructure.js";
6
6
  import { NotSupportedError } from "./NotSupportedError.js";
7
- import TimedCache from "../../common/cache/TimedCache.js";
8
7
 
9
8
  type IQueryFragment = string | { name?: string, value?: any };
10
9
 
11
- const parsedCache = new TimedCache<string, bpe.Node>();
12
-
13
- const parameterCacheSymbol = Symbol("parameterCacheSymbol");
14
-
15
10
  const defaultObject = {};
16
11
 
17
12
  export default class ArrowToExpression extends BabelVisitor<Expression> {
@@ -25,10 +20,8 @@ export default class ArrowToExpression extends BabelVisitor<Expression> {
25
20
  */
26
21
  public static transform(fx: (p: any) => (x: any) => any, target?: ParameterExpression, outerParameter?: ParameterExpression) {
27
22
  const key = fx.toString();
28
- const node = parsedCache.getOrCreate(key, fx, (k, f) => {
29
- const rs = new Restructure();
30
- return rs.visit(parseExpression(f.toString()));
31
- });
23
+ const rs = new Restructure();
24
+ const node = rs.visit(parseExpression(key));
32
25
  return this.transformUncached(node, target, outerParameter);
33
26
  }
34
27
 
@@ -40,70 +33,65 @@ export default class ArrowToExpression extends BabelVisitor<Expression> {
40
33
  * @param target parameter to replace
41
34
  * @returns transformed node
42
35
  */
43
- private static transformUncached(node: bpe.Node, tx?: ParameterExpression, outerParameter?: ParameterExpression): { params: Map<string, any>, body: Expression, target: ParameterExpression } {
36
+ private static transformUncached(node: bpe.Node, target?: ParameterExpression, outerParameter?: ParameterExpression): { params: ParameterExpression[], body: Expression, target: ParameterExpression } {
44
37
 
45
- const cache = node[parameterCacheSymbol] ??= new TimedCache<ParameterExpression,bpe.Node>();
46
-
47
- return cache.getOrCreate(tx ?? defaultObject, tx, (_, target) => {
48
-
49
- if (node.type !== "ArrowFunctionExpression") {
50
- throw new Error("Expecting an arrow function");
51
- }
38
+ if (node.type !== "ArrowFunctionExpression") {
39
+ throw new Error("Expecting an arrow function");
40
+ }
52
41
 
53
- const paramSet = new Map<string, any>();
42
+ const paramSet = new Map<string, any>();
54
43
 
55
- let firstOuterParam = null;
44
+ let firstOuterParam = null;
56
45
 
57
- const params = [];
46
+ const params = [];
58
47
 
59
- for (const iterator of node.params) {
60
- if (iterator.type !== "Identifier") {
61
- throw new Error("Expecting an identifier");
62
- }
63
- if (!firstOuterParam && outerParameter) {
64
- firstOuterParam = iterator.name;
65
- paramSet.set(iterator.name, outerParameter);
66
- params.push(outerParameter);
67
- continue;
68
- }
69
- const p1 = ParameterExpression.create({ name: iterator.name });
70
- paramSet.set(iterator.name, p1);
71
- params.push(p1);
48
+ for (const iterator of node.params) {
49
+ if (iterator.type !== "Identifier") {
50
+ throw new Error("Expecting an identifier");
72
51
  }
73
-
74
- if (outerParameter && firstOuterParam) {
75
- paramSet.set(firstOuterParam, outerParameter);
52
+ if (!firstOuterParam && outerParameter) {
53
+ firstOuterParam = iterator.name;
54
+ paramSet.set(iterator.name, outerParameter);
55
+ params.push(outerParameter);
56
+ continue;
76
57
  }
58
+ const p1 = ParameterExpression.create({ name: iterator.name });
59
+ paramSet.set(iterator.name, p1);
60
+ params.push(p1);
61
+ }
77
62
 
78
- let body = node.body;
79
- if (body.type !== "ArrowFunctionExpression") {
80
- throw new Error("Expecting an arrow function");
81
- }
63
+ if (outerParameter && firstOuterParam) {
64
+ paramSet.set(firstOuterParam, outerParameter);
65
+ }
82
66
 
83
- const firstTarget = body.params[0];
67
+ let body = node.body;
68
+ if (body.type !== "ArrowFunctionExpression") {
69
+ throw new Error("Expecting an arrow function");
70
+ }
84
71
 
85
- let name = "____x";
72
+ const firstTarget = body.params[0];
86
73
 
87
- if (firstTarget) {
74
+ let name = "____x";
88
75
 
89
- if (firstTarget.type !== "Identifier") {
90
- throw new Error("Expecting an identifier");
91
- }
92
- name = firstTarget.name;
76
+ if (firstTarget) {
77
+
78
+ if (firstTarget.type !== "Identifier") {
79
+ throw new Error("Expecting an identifier");
93
80
  }
81
+ name = firstTarget.name;
82
+ }
94
83
 
95
84
 
96
- target ??= ParameterExpression.create({ name});
85
+ target ??= ParameterExpression.create({ name});
97
86
 
98
- body = body.body;
87
+ body = body.body;
99
88
 
100
- const visitor = new this(paramSet, target, name);
101
- return {
102
- params,
103
- target,
104
- body: visitor.visit(body)
105
- };
106
- });
89
+ const visitor = new this(paramSet, target, name);
90
+ return {
91
+ params,
92
+ target,
93
+ body: visitor.visit(body)
94
+ };
107
95
  }
108
96
 
109
97
  public readonly leftJoins: string[] = [];