@scx-js/scx-data 0.2.2 → 0.2.4
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/index.js +2 -2
- package/package.json +2 -2
- package/query/BuildControl.js +2 -0
- package/query/Condition.js +1 -1
- package/query/Junction.js +35 -35
- package/query/QueryBuilder.js +2 -2
- package/query/QueryImpl.js +6 -6
- package/query/QueryLike.js +7 -21
- package/serialization/FieldPolicySerializer.js +47 -0
- package/serialization/QuerySerializer.js +120 -0
- package/field_policy/serializer/FieldPolicySerializer.js +0 -55
- package/query/serializer/QuerySerializer.js +0 -133
package/index.js
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
export * from "./field_policy/serializer/FieldPolicySerializer.js";
|
2
1
|
export * from "./field_policy/AssignField.js";
|
3
2
|
export * from "./field_policy/FieldPolicy.js";
|
4
3
|
export * from "./field_policy/FieldPolicyBuilder.js";
|
@@ -6,7 +5,6 @@ export * from "./field_policy/FieldPolicyImpl.js";
|
|
6
5
|
export * from "./field_policy/FieldPolicyLike.js";
|
7
6
|
export * from "./field_policy/FilterMode.js";
|
8
7
|
export * from "./field_policy/VirtualField.js";
|
9
|
-
export * from "./query/serializer/QuerySerializer.js";
|
10
8
|
export * from "./query/Junction.js";
|
11
9
|
export * from "./query/And.js";
|
12
10
|
export * from "./query/Or.js";
|
@@ -21,3 +19,5 @@ export * from "./query/BuildControl.js";
|
|
21
19
|
export * from "./query/Condition.js";
|
22
20
|
export * from "./query/WhereClause.js";
|
23
21
|
export * from "./query/ConditionType.js";
|
22
|
+
export * from "./serialization/QuerySerializer.js";
|
23
|
+
export * from "./serialization/FieldPolicySerializer.js";
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@scx-js/scx-data",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.4",
|
4
4
|
"description": "SCX Data",
|
5
5
|
"license": "MIT",
|
6
6
|
"author": "scx567888",
|
@@ -11,6 +11,6 @@
|
|
11
11
|
"url": "https://github.com/scx567888/scx-js.git"
|
12
12
|
},
|
13
13
|
"dependencies": {
|
14
|
-
"@scx-js/scx-common": "0.2.
|
14
|
+
"@scx-js/scx-common": "0.2.4"
|
15
15
|
}
|
16
16
|
}
|
package/query/BuildControl.js
CHANGED
package/query/Condition.js
CHANGED
package/query/Junction.js
CHANGED
@@ -16,9 +16,11 @@ import {
|
|
16
16
|
NOT_LIKE_REGEX,
|
17
17
|
} from "./ConditionType.js";
|
18
18
|
import {Condition} from "./Condition.js";
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
import {QueryImpl} from "./QueryImpl.js";
|
20
|
+
import {Not} from "./Not.js";
|
21
|
+
import {WhereClause} from "./WhereClause.js";
|
22
|
+
import {checkUseExpression, checkUseExpressionValue} from "./BuildControl.js";
|
23
|
+
import {ofSkipIfInfo} from "./SkipIfInfo.js";
|
22
24
|
|
23
25
|
class Junction extends QueryLike {
|
24
26
|
|
@@ -34,16 +36,7 @@ class Junction extends QueryLike {
|
|
34
36
|
}
|
35
37
|
|
36
38
|
add(...logicCauses) {
|
37
|
-
|
38
|
-
if (logicCause == null) {
|
39
|
-
continue;
|
40
|
-
}
|
41
|
-
if (Array.isArray(logicCause)) {
|
42
|
-
this.add(...logicCause);
|
43
|
-
continue;
|
44
|
-
}
|
45
|
-
this.#clauses.push(logicCause);
|
46
|
-
}
|
39
|
+
this.#clauses.push(...logicCauses);
|
47
40
|
return this;
|
48
41
|
}
|
49
42
|
|
@@ -53,67 +46,59 @@ class Junction extends QueryLike {
|
|
53
46
|
}
|
54
47
|
|
55
48
|
eq(fieldName, value, ...options) {
|
56
|
-
return this.add(
|
49
|
+
return this.add(condition(fieldName, EQ, value, ...options));
|
57
50
|
}
|
58
51
|
|
59
52
|
ne(fieldName, value, ...options) {
|
60
|
-
return this.add(
|
53
|
+
return this.add(condition(fieldName, NE, value, ...options));
|
61
54
|
}
|
62
55
|
|
63
56
|
lt(fieldName, value, ...options) {
|
64
|
-
return this.add(
|
57
|
+
return this.add(condition(fieldName, LT, value, ...options));
|
65
58
|
}
|
66
59
|
|
67
60
|
lte(fieldName, value, ...options) {
|
68
|
-
return this.add(
|
61
|
+
return this.add(condition(fieldName, LTE, value, ...options));
|
69
62
|
}
|
70
63
|
|
71
64
|
gt(fieldName, value, ...options) {
|
72
|
-
return this.add(
|
65
|
+
return this.add(condition(fieldName, GT, value, ...options));
|
73
66
|
}
|
74
67
|
|
75
68
|
gte(fieldName, value, ...options) {
|
76
|
-
return this.add(
|
69
|
+
return this.add(condition(fieldName, GTE, value, ...options));
|
77
70
|
}
|
78
71
|
|
79
72
|
like(fieldName, value, ...options) {
|
80
|
-
return this.add(
|
73
|
+
return this.add(condition(fieldName, LIKE, value, ...options));
|
81
74
|
}
|
82
75
|
|
83
76
|
notLike(fieldName, value, ...options) {
|
84
|
-
return this.add(
|
77
|
+
return this.add(condition(fieldName, NOT_LIKE, value, ...options));
|
85
78
|
}
|
86
79
|
|
87
80
|
likeRegex(fieldName, value, ...options) {
|
88
|
-
return this.add(
|
81
|
+
return this.add(condition(fieldName, LIKE_REGEX, value, ...options));
|
89
82
|
}
|
90
83
|
|
91
84
|
notLikeRegex(fieldName, value, ...options) {
|
92
|
-
return this.add(
|
85
|
+
return this.add(condition(fieldName, NOT_LIKE_REGEX, value, ...options));
|
93
86
|
}
|
94
87
|
|
95
88
|
in(fieldName, value, ...options) {
|
96
|
-
return this.add(
|
89
|
+
return this.add(condition(fieldName, IN, value, ...options));
|
97
90
|
}
|
98
91
|
|
99
92
|
notIn(fieldName, value, ...options) {
|
100
|
-
return this.add(
|
93
|
+
return this.add(condition(fieldName, NOT_IN, value, ...options));
|
101
94
|
}
|
102
95
|
|
103
96
|
between(fieldName, value1, value2, ...options) {
|
104
|
-
return this.add(
|
97
|
+
return this.add(condition2(fieldName, BETWEEN, value1, value2, ...options));
|
105
98
|
}
|
106
99
|
|
107
100
|
notBetween(fieldName, value1, value2, ...options) {
|
108
|
-
return this.add(
|
109
|
-
}
|
110
|
-
|
111
|
-
jsonContains(fieldName, value, ...options) {
|
112
|
-
return this.add(new Condition(fieldName, JSON_CONTAINS, value, null, ...options));
|
113
|
-
}
|
114
|
-
|
115
|
-
jsonOverlaps(fieldName, value, ...options) {
|
116
|
-
return this.add(new Condition(fieldName, JSON_OVERLAPS, value, null, ...options));
|
101
|
+
return this.add(condition2(fieldName, NOT_BETWEEN, value1, value2, ...options));
|
117
102
|
}
|
118
103
|
|
119
104
|
and(...clauses) {
|
@@ -138,6 +123,21 @@ class Junction extends QueryLike {
|
|
138
123
|
|
139
124
|
}
|
140
125
|
|
126
|
+
|
127
|
+
function condition(fieldName, conditionType, value, ...controls) {
|
128
|
+
let useExpression = checkUseExpression(...controls);
|
129
|
+
let useExpressionValue = checkUseExpressionValue(...controls);
|
130
|
+
let skipIfInfo = ofSkipIfInfo(...controls);
|
131
|
+
return new Condition(fieldName, conditionType, value, null, useExpression, useExpressionValue, skipIfInfo);
|
132
|
+
}
|
133
|
+
|
134
|
+
function condition2(fieldName, conditionType, value1, value2, ...controls) {
|
135
|
+
let useExpression = checkUseExpression(...controls);
|
136
|
+
let useExpressionValue = checkUseExpressionValue(...controls);
|
137
|
+
let skipIfInfo = ofSkipIfInfo(...controls);
|
138
|
+
return new Condition(fieldName, conditionType, value1, value2, useExpression, useExpressionValue, skipIfInfo);
|
139
|
+
}
|
140
|
+
|
141
141
|
export {
|
142
142
|
Junction,
|
143
143
|
};
|
package/query/QueryBuilder.js
CHANGED
@@ -72,12 +72,12 @@ function condition2(fieldName, conditionType, value1, value2, ...controls) {
|
|
72
72
|
}
|
73
73
|
|
74
74
|
function orderBy(selector, orderByType, ...controls) {
|
75
|
-
let useExpression = checkUseExpression(controls);
|
75
|
+
let useExpression = checkUseExpression(...controls);
|
76
76
|
return new OrderBy(selector, orderByType, useExpression);
|
77
77
|
}
|
78
78
|
|
79
79
|
function whereClause(expression, ...params) {
|
80
|
-
return new WhereClause(expression, params);
|
80
|
+
return new WhereClause(expression, ...params);
|
81
81
|
}
|
82
82
|
|
83
83
|
function asc(name, ...options) {
|
package/query/QueryImpl.js
CHANGED
@@ -28,7 +28,7 @@ class QueryImpl extends Query {
|
|
28
28
|
|
29
29
|
|
30
30
|
orderBys(...orderBys) {
|
31
|
-
this.#orderBys = orderBys;
|
31
|
+
this.#orderBys = [...orderBys];
|
32
32
|
return this;
|
33
33
|
}
|
34
34
|
|
@@ -86,22 +86,22 @@ class QueryImpl extends Query {
|
|
86
86
|
}
|
87
87
|
|
88
88
|
orderBy(...orderBys) {
|
89
|
-
this.#orderBys.push(orderBys);
|
89
|
+
this.#orderBys.push(...orderBys);
|
90
90
|
return this;
|
91
91
|
}
|
92
92
|
|
93
93
|
|
94
94
|
asc(selector, ...controls) {
|
95
|
-
let useExpression = checkUseExpression(controls);
|
96
|
-
let o= new OrderBy(selector, ASC, useExpression);
|
95
|
+
let useExpression = checkUseExpression(...controls);
|
96
|
+
let o = new OrderBy(selector, ASC, useExpression);
|
97
97
|
this.orderBy(o);
|
98
98
|
return this;
|
99
99
|
}
|
100
100
|
|
101
101
|
|
102
102
|
desc(selector, ...controls) {
|
103
|
-
let useExpression = checkUseExpression(controls);
|
104
|
-
let o= new OrderBy(selector, DESC, useExpression);
|
103
|
+
let useExpression = checkUseExpression(...controls);
|
104
|
+
let o = new OrderBy(selector, DESC, useExpression);
|
105
105
|
this.orderBy(o);
|
106
106
|
return this;
|
107
107
|
}
|
package/query/QueryLike.js
CHANGED
@@ -16,8 +16,8 @@ class QueryLike extends Query {
|
|
16
16
|
return this;
|
17
17
|
}
|
18
18
|
|
19
|
-
orderBys(...
|
20
|
-
this.query().orderBy(...
|
19
|
+
orderBys(...orderBys) {
|
20
|
+
this.query().orderBy(...orderBys);
|
21
21
|
return this;
|
22
22
|
}
|
23
23
|
|
@@ -35,12 +35,8 @@ class QueryLike extends Query {
|
|
35
35
|
return this.query().getWhere();
|
36
36
|
}
|
37
37
|
|
38
|
-
|
39
|
-
return this.query().
|
40
|
-
}
|
41
|
-
|
42
|
-
getOrderBy() {
|
43
|
-
return this.query().getOrderBy();
|
38
|
+
getOrderBys() {
|
39
|
+
return this.query().getOrderBys();
|
44
40
|
}
|
45
41
|
|
46
42
|
getOffset() {
|
@@ -56,16 +52,6 @@ class QueryLike extends Query {
|
|
56
52
|
return this;
|
57
53
|
}
|
58
54
|
|
59
|
-
clearGroupBy() {
|
60
|
-
this.query().clearGroupBy();
|
61
|
-
return this;
|
62
|
-
}
|
63
|
-
|
64
|
-
clearOrderBy() {
|
65
|
-
this.query().clearOrderBy();
|
66
|
-
return this;
|
67
|
-
}
|
68
|
-
|
69
55
|
clearOffset() {
|
70
56
|
this.query().clearOffset();
|
71
57
|
return this;
|
@@ -77,17 +63,17 @@ class QueryLike extends Query {
|
|
77
63
|
}
|
78
64
|
|
79
65
|
orderBy(...orderByClauses) {
|
80
|
-
this.query().orderBy(orderByClauses);
|
66
|
+
this.query().orderBy(...orderByClauses);
|
81
67
|
return this;
|
82
68
|
}
|
83
69
|
|
84
70
|
asc(selector, ...controls) {
|
85
|
-
this.query().asc(selector
|
71
|
+
this.query().asc(selector, ...controls);
|
86
72
|
return this;
|
87
73
|
}
|
88
74
|
|
89
75
|
desc(selector, ...controls) {
|
90
|
-
this.query().desc(selector
|
76
|
+
this.query().desc(selector, ...controls);
|
91
77
|
return this;
|
92
78
|
}
|
93
79
|
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import {FieldPolicy} from "../field_policy/FieldPolicy.js";
|
2
|
+
|
3
|
+
function serializeFieldPolicyToJson(fieldPolicy) {
|
4
|
+
return JSON.stringify(serializeFieldPolicy(fieldPolicy));
|
5
|
+
}
|
6
|
+
|
7
|
+
function serializeFieldPolicy(fieldPolicy) {
|
8
|
+
return {
|
9
|
+
"@type": "FieldPolicy",
|
10
|
+
"filterMode": fieldPolicy.getFilterMode(),
|
11
|
+
"fieldNames": fieldPolicy.getFieldNames(),
|
12
|
+
"virtualFields": serializeVirtualFields(fieldPolicy.getVirtualFields()),
|
13
|
+
"ignoreNull": fieldPolicy.getIgnoreNull(),
|
14
|
+
"ignoreNulls": fieldPolicy.getIgnoreNulls(),
|
15
|
+
"assignFields": serializeAssignFields(fieldPolicy.getAssignFields()),
|
16
|
+
};
|
17
|
+
}
|
18
|
+
|
19
|
+
function serializeVirtualField(virtualField) {
|
20
|
+
return {
|
21
|
+
"@type": "VirtualField",
|
22
|
+
"expression": virtualField.expression(),
|
23
|
+
"virtualFieldName": virtualField.virtualFieldName(),
|
24
|
+
};
|
25
|
+
}
|
26
|
+
|
27
|
+
|
28
|
+
function serializeAssignField(assignField) {
|
29
|
+
return {
|
30
|
+
"@type": "AssignField",
|
31
|
+
"fieldName": assignField.fieldName(),
|
32
|
+
"expression": assignField.expression(),
|
33
|
+
};
|
34
|
+
}
|
35
|
+
|
36
|
+
function serializeVirtualFields(virtualFields) {
|
37
|
+
return virtualFields.map(s => serializeVirtualField(s));
|
38
|
+
}
|
39
|
+
|
40
|
+
function serializeAssignFields(assignFields) {
|
41
|
+
return assignFields.map(s => serializeAssignField(s));
|
42
|
+
}
|
43
|
+
|
44
|
+
export {
|
45
|
+
serializeFieldPolicyToJson,
|
46
|
+
serializeFieldPolicy,
|
47
|
+
};
|
@@ -0,0 +1,120 @@
|
|
1
|
+
import {WhereClause} from "../query/WhereClause.js";
|
2
|
+
import {And} from "../query/And.js";
|
3
|
+
import {Or} from "../query/Or.js";
|
4
|
+
import {Not} from "../query/Not.js";
|
5
|
+
import {Condition} from "../query/Condition.js";
|
6
|
+
|
7
|
+
function serializeQueryToJson(query) {
|
8
|
+
return JSON.stringify(serializeQuery(query));
|
9
|
+
}
|
10
|
+
|
11
|
+
function serializeQuery(query) {
|
12
|
+
return {
|
13
|
+
"@type": "Query",
|
14
|
+
where: serializeWhere(query.getWhere()),
|
15
|
+
orderBys: serializeOrderBys(query.getOrderBys()),
|
16
|
+
offset: query.getOffset(),
|
17
|
+
limit: query.getLimit(),
|
18
|
+
};
|
19
|
+
}
|
20
|
+
|
21
|
+
function serializeWhere(obj) {
|
22
|
+
if (!obj) {
|
23
|
+
return null;
|
24
|
+
}
|
25
|
+
|
26
|
+
if (obj instanceof WhereClause) {
|
27
|
+
return serializeWhereClause(obj);
|
28
|
+
}
|
29
|
+
if (obj instanceof And) {
|
30
|
+
return serializeAnd(obj);
|
31
|
+
}
|
32
|
+
if (obj instanceof Or) {
|
33
|
+
return serializeOr(obj);
|
34
|
+
}
|
35
|
+
|
36
|
+
if (obj instanceof Not) {
|
37
|
+
return serializeNot(obj);
|
38
|
+
}
|
39
|
+
|
40
|
+
if (obj instanceof Condition) {
|
41
|
+
return serializeCondition(obj);
|
42
|
+
}
|
43
|
+
|
44
|
+
throw new Error(`Unknown Where type: ${obj}`);
|
45
|
+
|
46
|
+
}
|
47
|
+
|
48
|
+
function serializeWhereClause(w) {
|
49
|
+
return {
|
50
|
+
"@type": "WhereClause",
|
51
|
+
expression: w.expression(),
|
52
|
+
params: w.params(),
|
53
|
+
};
|
54
|
+
}
|
55
|
+
|
56
|
+
function serializeAnd(a) {
|
57
|
+
return {
|
58
|
+
"@type": "And",
|
59
|
+
clauses: serializeWhereAll(a.clauses()),
|
60
|
+
};
|
61
|
+
}
|
62
|
+
|
63
|
+
function serializeOr(o) {
|
64
|
+
return {
|
65
|
+
"@type": "Or",
|
66
|
+
clauses: serializeWhereAll(o.clauses()),
|
67
|
+
};
|
68
|
+
}
|
69
|
+
|
70
|
+
function serializeNot(n) {
|
71
|
+
return {
|
72
|
+
"@type": "Not",
|
73
|
+
clause: serializeWhere(n.clause()),
|
74
|
+
};
|
75
|
+
}
|
76
|
+
|
77
|
+
function serializeCondition(w) {
|
78
|
+
return {
|
79
|
+
"@type": "Condition",
|
80
|
+
selector: w.selector(),
|
81
|
+
conditionType: w.conditionType(),
|
82
|
+
value1: w.value1(),
|
83
|
+
value2: w.value2(),
|
84
|
+
useExpression: w.useExpression(),
|
85
|
+
useExpressionValue: w.useExpressionValue(),
|
86
|
+
skipIfInfo: serializeSkipIfInfo(w.skipIfInfo()),
|
87
|
+
};
|
88
|
+
}
|
89
|
+
|
90
|
+
function serializeWhereAll(objs) {
|
91
|
+
return objs.map(obj => serializeWhere(obj));
|
92
|
+
}
|
93
|
+
|
94
|
+
function serializeOrderBys(objs) {
|
95
|
+
return objs.map(obj => serializeOrderBy(obj));
|
96
|
+
}
|
97
|
+
|
98
|
+
function serializeOrderBy(orderBy) {
|
99
|
+
return {
|
100
|
+
"@type": "OrderBy",
|
101
|
+
selector: orderBy.selector(),
|
102
|
+
orderByType: orderBy.orderByType(),
|
103
|
+
useExpression: orderBy.useExpression(),
|
104
|
+
};
|
105
|
+
}
|
106
|
+
|
107
|
+
function serializeSkipIfInfo(info) {
|
108
|
+
return {
|
109
|
+
"@type": "SkipIfInfo",
|
110
|
+
skipIfNull: info.skipIfNull,
|
111
|
+
skipIfEmptyList: info.skipIfEmptyList,
|
112
|
+
skipIfEmptyString: info.skipIfEmptyString,
|
113
|
+
skipIfBlankString: info.skipIfBlankString,
|
114
|
+
};
|
115
|
+
}
|
116
|
+
|
117
|
+
export {
|
118
|
+
serializeQueryToJson,
|
119
|
+
serializeQuery,
|
120
|
+
};
|
@@ -1,55 +0,0 @@
|
|
1
|
-
import {FieldPolicy} from "../FieldPolicy.js";
|
2
|
-
|
3
|
-
class FieldPolicySerializer {
|
4
|
-
|
5
|
-
serialize(obj) {
|
6
|
-
if (obj instanceof FieldPolicy) {
|
7
|
-
return this.serializeFieldPolicy(obj);
|
8
|
-
}
|
9
|
-
return obj;
|
10
|
-
}
|
11
|
-
|
12
|
-
serializeFieldPolicy(fieldPolicy) {
|
13
|
-
return {
|
14
|
-
"@type": "FieldPolicy",
|
15
|
-
"filterMode": fieldPolicy.getFilterMode(),
|
16
|
-
"fieldNames": fieldPolicy.getFieldNames(),
|
17
|
-
"virtualFields": this.serializeVirtualFields(fieldPolicy.getVirtualFields()),
|
18
|
-
"ignoreNull": fieldPolicy.getIgnoreNull(),
|
19
|
-
"ignoreNulls": fieldPolicy.getIgnoreNulls(),
|
20
|
-
"assignFields": this.serializeAssignFields(fieldPolicy.getAssignFields()),
|
21
|
-
};
|
22
|
-
}
|
23
|
-
|
24
|
-
serializeVirtualFields(v) {
|
25
|
-
return v.map(s => this.serializeVirtualField(s));
|
26
|
-
}
|
27
|
-
|
28
|
-
serializeVirtualField(v) {
|
29
|
-
return {
|
30
|
-
"@type": "VirtualField",
|
31
|
-
"expression": v.expression(),
|
32
|
-
"virtualFieldName": v.virtualFieldName(),
|
33
|
-
};
|
34
|
-
}
|
35
|
-
|
36
|
-
serializeAssignFields(v) {
|
37
|
-
return v.map(s => this.serializeAssignField(s));
|
38
|
-
}
|
39
|
-
|
40
|
-
serializeAssignField(v) {
|
41
|
-
return {
|
42
|
-
"@type": "AssignField",
|
43
|
-
"fieldName": v.fieldName(),
|
44
|
-
"expression": v.expression(),
|
45
|
-
};
|
46
|
-
}
|
47
|
-
|
48
|
-
}
|
49
|
-
|
50
|
-
const FIELD_POLICY_SERIALIZER = new FieldPolicySerializer();
|
51
|
-
|
52
|
-
export {
|
53
|
-
FIELD_POLICY_SERIALIZER,
|
54
|
-
FieldPolicySerializer,
|
55
|
-
};
|
@@ -1,133 +0,0 @@
|
|
1
|
-
import {WhereClause} from "../WhereClause.js";
|
2
|
-
import {And} from "../And.js";
|
3
|
-
import {Or} from "../Or.js";
|
4
|
-
import {Not} from "../Not.js";
|
5
|
-
import {Condition} from "../Condition.js";
|
6
|
-
|
7
|
-
class QuerySerializer {
|
8
|
-
|
9
|
-
toJson(query) {
|
10
|
-
return JSON.stringify(this.serialize(query), null, 2);
|
11
|
-
}
|
12
|
-
|
13
|
-
serialize(query) {
|
14
|
-
return this.serializeQuery(query);
|
15
|
-
}
|
16
|
-
|
17
|
-
serializeQuery(query) {
|
18
|
-
return {
|
19
|
-
"@type": "Query",
|
20
|
-
where: this.serializeWhere(query.getWhere?.()),
|
21
|
-
orderBys: this.serializeOrderBys(...(query.getOrderBys?.() ?? [])),
|
22
|
-
offset: query.getOffset?.(),
|
23
|
-
limit: query.getLimit?.(),
|
24
|
-
};
|
25
|
-
}
|
26
|
-
|
27
|
-
serializeWhere(obj) {
|
28
|
-
if (!obj) {
|
29
|
-
return null;
|
30
|
-
}
|
31
|
-
|
32
|
-
if (obj instanceof WhereClause) {
|
33
|
-
return this.serializeWhereClause(obj);
|
34
|
-
}
|
35
|
-
if (obj instanceof And) {
|
36
|
-
return this.serializeAnd(obj);
|
37
|
-
}
|
38
|
-
if (obj instanceof Or) {
|
39
|
-
return this.serializeOr(obj);
|
40
|
-
}
|
41
|
-
|
42
|
-
if (obj instanceof Not) {
|
43
|
-
return this.serializeNot(obj);
|
44
|
-
}
|
45
|
-
|
46
|
-
if (obj instanceof Condition) {
|
47
|
-
return this.serializeCondition(obj);
|
48
|
-
}
|
49
|
-
|
50
|
-
throw new Error(`Unknown Where type: ${obj?.type}`);
|
51
|
-
|
52
|
-
}
|
53
|
-
|
54
|
-
serializeWhereClause(w) {
|
55
|
-
return {
|
56
|
-
"@type": "WhereClause",
|
57
|
-
expression: w.expression(),
|
58
|
-
params: w.params(),
|
59
|
-
};
|
60
|
-
}
|
61
|
-
|
62
|
-
serializeAnd(a) {
|
63
|
-
return {
|
64
|
-
"@type": "And",
|
65
|
-
clauses: this.serializeWhereAll(a.clauses),
|
66
|
-
};
|
67
|
-
}
|
68
|
-
|
69
|
-
serializeOr(o) {
|
70
|
-
return {
|
71
|
-
"@type": "Or",
|
72
|
-
clauses: this.serializeWhereAll(o.clauses),
|
73
|
-
};
|
74
|
-
}
|
75
|
-
|
76
|
-
serializeNot(n) {
|
77
|
-
return {
|
78
|
-
"@type": "Not",
|
79
|
-
clause: this.serializeWhere(n.clause),
|
80
|
-
};
|
81
|
-
}
|
82
|
-
|
83
|
-
serializeCondition(w) {
|
84
|
-
return {
|
85
|
-
"@type": "Condition",
|
86
|
-
selector: w.selector(),
|
87
|
-
conditionType: w.conditionType(),
|
88
|
-
value1: w.value1(),
|
89
|
-
value2: w.value2(),
|
90
|
-
useExpression: w.useExpression(),
|
91
|
-
useExpressionValue: w.useExpressionValue(),
|
92
|
-
skipIfInfo: this.serializeSkipIfInfo(w.skipIfInfo()),
|
93
|
-
};
|
94
|
-
}
|
95
|
-
|
96
|
-
serializeWhereAll(objs) {
|
97
|
-
return objs.map(obj => this.serializeWhere(obj));
|
98
|
-
}
|
99
|
-
|
100
|
-
serializeOrderBys(...objs) {
|
101
|
-
return objs.map(obj => this.serializeOrderBy(obj));
|
102
|
-
}
|
103
|
-
|
104
|
-
serializeOrderBy(orderBy) {
|
105
|
-
return {
|
106
|
-
"@type": "OrderBy",
|
107
|
-
selector: orderBy.selector(),
|
108
|
-
orderByType: orderBy.orderByType(),
|
109
|
-
useExpression: orderBy.useExpression(),
|
110
|
-
};
|
111
|
-
}
|
112
|
-
|
113
|
-
serializeSkipIfInfo(info) {
|
114
|
-
if (!info) {
|
115
|
-
return null;
|
116
|
-
}
|
117
|
-
return {
|
118
|
-
"@type": "SkipIfInfo",
|
119
|
-
skipIfNull: info.skipIfNull,
|
120
|
-
skipIfEmptyList: info.skipIfEmptyList,
|
121
|
-
skipIfEmptyString: info.skipIfEmptyString,
|
122
|
-
skipIfBlankString: info.skipIfBlankString,
|
123
|
-
};
|
124
|
-
}
|
125
|
-
|
126
|
-
}
|
127
|
-
|
128
|
-
const QUERY_SERIALIZER = new QuerySerializer();
|
129
|
-
|
130
|
-
export {
|
131
|
-
QuerySerializer,
|
132
|
-
QUERY_SERIALIZER,
|
133
|
-
};
|