@scx-js/scx-data 0.2.2 → 0.2.3
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/Condition.js +1 -1
- package/query/QueryImpl.js +4 -4
- 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.3",
|
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.3"
|
15
15
|
}
|
16
16
|
}
|
package/query/Condition.js
CHANGED
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,14 +86,14 @@ 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
95
|
let useExpression = checkUseExpression(controls);
|
96
|
-
let o= new OrderBy(selector, ASC, useExpression);
|
96
|
+
let o = new OrderBy(selector, ASC, useExpression);
|
97
97
|
this.orderBy(o);
|
98
98
|
return this;
|
99
99
|
}
|
@@ -101,7 +101,7 @@ class QueryImpl extends Query {
|
|
101
101
|
|
102
102
|
desc(selector, ...controls) {
|
103
103
|
let useExpression = checkUseExpression(controls);
|
104
|
-
let o= new OrderBy(selector, DESC, useExpression);
|
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
|
-
};
|