@entity-access/entity-access 1.0.495 → 1.0.497
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/compiler/QueryCompiler.d.ts +7 -1
- package/dist/compiler/QueryCompiler.d.ts.map +1 -1
- package/dist/compiler/QueryCompiler.js +9 -3
- package/dist/compiler/QueryCompiler.js.map +1 -1
- package/dist/model/EntityQuery.js +2 -2
- package/dist/model/EntityQuery.js.map +1 -1
- package/dist/query/expander/QueryExpander.js +1 -2
- package/dist/query/expander/QueryExpander.js.map +1 -1
- package/dist/query/parser/ArrowToExpression.d.ts +1 -1
- package/dist/query/parser/ArrowToExpression.d.ts.map +1 -1
- package/dist/query/parser/ArrowToExpression.js +43 -51
- package/dist/query/parser/ArrowToExpression.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/compiler/QueryCompiler.ts +11 -3
- package/src/model/EntityQuery.ts +3 -3
- package/src/query/expander/QueryExpander.ts +1 -1
- package/src/query/parser/ArrowToExpression.ts +44 -56
|
@@ -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
|
|
29
|
-
|
|
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,
|
|
36
|
+
private static transformUncached(node: bpe.Node, target?: ParameterExpression, outerParameter?: ParameterExpression): { params: ParameterExpression[], body: Expression, target: ParameterExpression } {
|
|
44
37
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
-
|
|
42
|
+
const paramSet = new Map<string, any>();
|
|
54
43
|
|
|
55
|
-
|
|
44
|
+
let firstOuterParam = null;
|
|
56
45
|
|
|
57
|
-
|
|
46
|
+
const params = [];
|
|
58
47
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
75
|
-
paramSet.set(
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
63
|
+
if (outerParameter && firstOuterParam) {
|
|
64
|
+
paramSet.set(firstOuterParam, outerParameter);
|
|
65
|
+
}
|
|
82
66
|
|
|
83
|
-
|
|
67
|
+
let body = node.body;
|
|
68
|
+
if (body.type !== "ArrowFunctionExpression") {
|
|
69
|
+
throw new Error("Expecting an arrow function");
|
|
70
|
+
}
|
|
84
71
|
|
|
85
|
-
|
|
72
|
+
const firstTarget = body.params[0];
|
|
86
73
|
|
|
87
|
-
|
|
74
|
+
let name = "____x";
|
|
88
75
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
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
|
-
|
|
85
|
+
target ??= ParameterExpression.create({ name});
|
|
97
86
|
|
|
98
|
-
|
|
87
|
+
body = body.body;
|
|
99
88
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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[] = [];
|