This repository has been archived by the owner on Sep 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselectpropertyfinder.ts
65 lines (56 loc) · 1.87 KB
/
selectpropertyfinder.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { ExpressionVisitor, Filter, Order, Property, EqBinary, Select, SelectMany, Method, ModelMethod, Expand } from './expressions';
export class SelectPropertyFinder extends ExpressionVisitor {
properties: Array<Property> = [];
filter(filter: Filter) {
this.visit(filter.expression);
}
private addProperty(property: Property) {
if([null,''].some((a)=>property.name == a)) return;
this.properties.push(property);
}
getAsExpressions() {
let getExpand = function (property: Property) {
let allProps = [];
let p = property;
while (p != null) {
allProps.push(p.name);
p = p.parent;
}
allProps.reverse();
return new Expand([{
property: new Property(allProps[0]),
expressions: [new Select(allProps.splice(1, allProps.length).map(a => {
return {
property: a,
}
}))]
}]);
}
let expands = this.properties.filter(x => x.parent != null);
return [].concat(expands.map(getExpand)).concat([new Select(this.properties.filter(x => x.parent == null).map(a => {
return {
property: a,
expressions: []
}
}))]);
}
order(order: Order) {
this.addProperty(order.property);
}
eqBinary(binary: EqBinary) {
this.visit(binary.left);
this.visit(binary.op);
this.visit(binary.right);
}
property(propery: Property) {
this.addProperty(propery);
}
selectMany(selectManay: SelectMany) {
this.addProperty(new Property(selectManay.name, selectManay.parent));
}
modelMethod(method: ModelMethod) {
method.args.forEach((i) => {
this.addProperty(i)
});
}
}