@scx-js/scx-data 0.1.3 → 0.1.5
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/field_policy/FieldPolicy.js +40 -0
- package/field_policy/FieldPolicyBuilder.js +45 -0
- package/{field_filter/FieldFilterImpl.js → field_policy/FieldPolicyImpl.js} +25 -17
- package/field_policy/serializer/FieldPolicySerializer.js +29 -0
- package/index.js +5 -5
- package/package.json +2 -2
- package/query/Query.js +6 -6
- package/query/QueryImpl.js +1 -1
- package/field_filter/FieldFilter.js +0 -40
- package/field_filter/FieldFilterBuilder.js +0 -25
- package/field_filter/serializer/FieldFilterSerializer.js +0 -28
- /package/{field_filter → field_policy}/FilterMode.js +0 -0
@@ -0,0 +1,40 @@
|
|
1
|
+
class FieldPolicy {
|
2
|
+
|
3
|
+
included(...fieldNames) {
|
4
|
+
return this;
|
5
|
+
}
|
6
|
+
|
7
|
+
excluded(...fieldNames) {
|
8
|
+
return this;
|
9
|
+
}
|
10
|
+
|
11
|
+
filterMode() {
|
12
|
+
}
|
13
|
+
|
14
|
+
fieldNames() {
|
15
|
+
}
|
16
|
+
|
17
|
+
clearFieldNames() {
|
18
|
+
}
|
19
|
+
|
20
|
+
ignoreNullValue(ignoreNullValue) {
|
21
|
+
return this;
|
22
|
+
}
|
23
|
+
|
24
|
+
ignoreNullValue_() {
|
25
|
+
}
|
26
|
+
|
27
|
+
fieldExpression(fieldName, expression) {
|
28
|
+
}
|
29
|
+
|
30
|
+
fieldExpressions() {
|
31
|
+
}
|
32
|
+
|
33
|
+
clearFieldExpressions() {
|
34
|
+
}
|
35
|
+
|
36
|
+
}
|
37
|
+
|
38
|
+
export {
|
39
|
+
FieldPolicy,
|
40
|
+
};
|
@@ -0,0 +1,45 @@
|
|
1
|
+
import {FieldPolicyImpl} from "./FieldPolicyImpl.js";
|
2
|
+
import {EXCLUDED, INCLUDED} from "./FilterMode.js";
|
3
|
+
|
4
|
+
function includedAll() {
|
5
|
+
return new FieldPolicyImpl(EXCLUDED);
|
6
|
+
}
|
7
|
+
|
8
|
+
function excludedAll() {
|
9
|
+
return new FieldPolicyImpl(INCLUDED);
|
10
|
+
}
|
11
|
+
|
12
|
+
/**
|
13
|
+
*
|
14
|
+
* @param fieldNames
|
15
|
+
* @return {FieldPolicy}
|
16
|
+
*/
|
17
|
+
function included(...fieldNames) {
|
18
|
+
return excludedAll().included(fieldNames);
|
19
|
+
}
|
20
|
+
|
21
|
+
/**
|
22
|
+
*
|
23
|
+
* @param fieldNames
|
24
|
+
* @return {FieldPolicy}
|
25
|
+
*/
|
26
|
+
function excluded(...fieldNames) {
|
27
|
+
return includedAll().excluded(fieldNames);
|
28
|
+
}
|
29
|
+
|
30
|
+
function ignoreNullValue(ignoreNullValue) {
|
31
|
+
return includedAll().ignoreNullValue(ignoreNullValue);
|
32
|
+
}
|
33
|
+
|
34
|
+
function fieldExpression(fieldName, expression) {
|
35
|
+
return includedAll().fieldExpression(fieldName, expression);
|
36
|
+
}
|
37
|
+
|
38
|
+
export {
|
39
|
+
includedAll,
|
40
|
+
excludedAll,
|
41
|
+
included,
|
42
|
+
excluded,
|
43
|
+
ignoreNullValue,
|
44
|
+
fieldExpression,
|
45
|
+
};
|
@@ -1,20 +1,22 @@
|
|
1
1
|
import {EXCLUDED, INCLUDED} from "./FilterMode.js";
|
2
|
-
import {
|
2
|
+
import {FieldPolicy} from "./FieldPolicy.js";
|
3
3
|
|
4
|
-
class
|
4
|
+
class FieldPolicyImpl extends FieldPolicy {
|
5
5
|
|
6
6
|
#filterMode;
|
7
7
|
#fieldNames;
|
8
|
+
#fieldExpressions;
|
8
9
|
#ignoreNullValue;
|
9
10
|
|
10
11
|
constructor(filterMode) {
|
11
12
|
super();
|
12
13
|
this.#filterMode = filterMode;
|
13
14
|
this.#fieldNames = new Set();
|
15
|
+
this.#fieldExpressions = new Map();
|
14
16
|
this.#ignoreNullValue = true;
|
15
17
|
}
|
16
18
|
|
17
|
-
|
19
|
+
included(...fieldNames) {
|
18
20
|
if (this.#filterMode === INCLUDED) {
|
19
21
|
this.addFieldNames(...fieldNames);
|
20
22
|
} else if (this.#filterMode === EXCLUDED) {
|
@@ -23,7 +25,7 @@ class FieldFilterImpl extends FieldFilter {
|
|
23
25
|
return this;
|
24
26
|
}
|
25
27
|
|
26
|
-
|
28
|
+
excluded(...fieldNames) {
|
27
29
|
if (this.#filterMode === EXCLUDED) {
|
28
30
|
this.addFieldNames(...fieldNames);
|
29
31
|
} else if (this.#filterMode === INCLUDED) {
|
@@ -32,12 +34,17 @@ class FieldFilterImpl extends FieldFilter {
|
|
32
34
|
return this;
|
33
35
|
}
|
34
36
|
|
35
|
-
|
36
|
-
return this
|
37
|
+
filterMode() {
|
38
|
+
return this.#filterMode;
|
39
|
+
}
|
40
|
+
|
41
|
+
fieldNames() {
|
42
|
+
return Array.from(this.#fieldNames);
|
37
43
|
}
|
38
44
|
|
39
|
-
|
40
|
-
|
45
|
+
clearFieldNames() {
|
46
|
+
this.#fieldNames.clear();
|
47
|
+
return this;
|
41
48
|
}
|
42
49
|
|
43
50
|
ignoreNullValue(ignoreNullValue) {
|
@@ -45,20 +52,21 @@ class FieldFilterImpl extends FieldFilter {
|
|
45
52
|
return this;
|
46
53
|
}
|
47
54
|
|
48
|
-
|
49
|
-
return this.#
|
55
|
+
ignoreNullValue_() {
|
56
|
+
return this.#ignoreNullValue;
|
50
57
|
}
|
51
58
|
|
52
|
-
|
53
|
-
|
59
|
+
fieldExpression(fieldName, expression) {
|
60
|
+
this.#fieldExpressions.set(fieldName, expression);
|
61
|
+
return this;
|
54
62
|
}
|
55
63
|
|
56
|
-
|
57
|
-
return this.#
|
64
|
+
fieldExpressions() {
|
65
|
+
return this.#fieldExpressions;
|
58
66
|
}
|
59
67
|
|
60
|
-
|
61
|
-
this.#
|
68
|
+
clearFieldExpressions() {
|
69
|
+
this.#fieldExpressions.clear();
|
62
70
|
return this;
|
63
71
|
}
|
64
72
|
|
@@ -78,4 +86,4 @@ class FieldFilterImpl extends FieldFilter {
|
|
78
86
|
|
79
87
|
}
|
80
88
|
|
81
|
-
export {
|
89
|
+
export {FieldPolicyImpl};
|
@@ -0,0 +1,29 @@
|
|
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.filterMode(),
|
16
|
+
"fieldNames": fieldPolicy.fieldNames(),
|
17
|
+
"ignoreNullValue": fieldPolicy.ignoreNullValue_(),
|
18
|
+
"fieldExpressions": fieldPolicy.fieldExpressions(),
|
19
|
+
};
|
20
|
+
}
|
21
|
+
|
22
|
+
}
|
23
|
+
|
24
|
+
const FIELD_POLICY_SERIALIZER = new FieldPolicySerializer();
|
25
|
+
|
26
|
+
export {
|
27
|
+
FIELD_POLICY_SERIALIZER,
|
28
|
+
FieldPolicySerializer,
|
29
|
+
};
|
package/index.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
export * from "./
|
2
|
-
export * from "./
|
3
|
-
export * from "./
|
4
|
-
export * from "./
|
5
|
-
export * from "./
|
1
|
+
export * from "./field_policy/serializer/FieldPolicySerializer.js";
|
2
|
+
export * from "./field_policy/FieldPolicy.js";
|
3
|
+
export * from "./field_policy/FieldPolicyBuilder.js";
|
4
|
+
export * from "./field_policy/FieldPolicyImpl.js";
|
5
|
+
export * from "./field_policy/FilterMode.js";
|
6
6
|
export * from "./query/serializer/GroupBySerializer.js";
|
7
7
|
export * from "./query/serializer/OrderBySerializer.js";
|
8
8
|
export * from "./query/serializer/QuerySerializer.js";
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@scx-js/scx-data",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.5",
|
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.1.
|
14
|
+
"@scx-js/scx-common": "0.1.5"
|
15
15
|
}
|
16
16
|
}
|
package/query/Query.js
CHANGED
@@ -55,27 +55,27 @@ class Query {
|
|
55
55
|
return this;
|
56
56
|
}
|
57
57
|
|
58
|
-
addWhere(...
|
58
|
+
addWhere(...whereClauses) {
|
59
59
|
return this;
|
60
60
|
}
|
61
61
|
|
62
|
-
addGroupBy(...
|
62
|
+
addGroupBy(...groupByClauses) {
|
63
63
|
return this;
|
64
64
|
}
|
65
65
|
|
66
|
-
addOrderBy(...
|
66
|
+
addOrderBy(...orderByClauses) {
|
67
67
|
return this;
|
68
68
|
}
|
69
69
|
|
70
|
-
removeWhereIf(filter){
|
70
|
+
removeWhereIf(filter) {
|
71
71
|
return this;
|
72
72
|
}
|
73
73
|
|
74
|
-
removeGroupByIf(filter){
|
74
|
+
removeGroupByIf(filter) {
|
75
75
|
return this;
|
76
76
|
}
|
77
77
|
|
78
|
-
removeOrderByIf(filter){
|
78
|
+
removeOrderByIf(filter) {
|
79
79
|
return this;
|
80
80
|
}
|
81
81
|
|
package/query/QueryImpl.js
CHANGED
@@ -1,40 +0,0 @@
|
|
1
|
-
class FieldFilter {
|
2
|
-
|
3
|
-
addIncluded(...fieldNames) {
|
4
|
-
return this;
|
5
|
-
}
|
6
|
-
|
7
|
-
addExcluded(...fieldNames) {
|
8
|
-
return this;
|
9
|
-
}
|
10
|
-
|
11
|
-
removeIncluded(...fieldNames) {
|
12
|
-
return this;
|
13
|
-
}
|
14
|
-
|
15
|
-
removeExcluded(...fieldNames) {
|
16
|
-
return this;
|
17
|
-
}
|
18
|
-
|
19
|
-
ignoreNullValue(ignoreNullValue) {
|
20
|
-
return this;
|
21
|
-
}
|
22
|
-
|
23
|
-
getFilterMode() {
|
24
|
-
}
|
25
|
-
|
26
|
-
getFieldNames() {
|
27
|
-
}
|
28
|
-
|
29
|
-
getIgnoreNullValue() {
|
30
|
-
}
|
31
|
-
|
32
|
-
clear() {
|
33
|
-
return this;
|
34
|
-
}
|
35
|
-
|
36
|
-
}
|
37
|
-
|
38
|
-
export {
|
39
|
-
FieldFilter,
|
40
|
-
};
|
@@ -1,25 +0,0 @@
|
|
1
|
-
import {FieldFilterImpl} from "./FieldFilterImpl.js";
|
2
|
-
import {EXCLUDED, INCLUDED} from "./FilterMode.js";
|
3
|
-
|
4
|
-
/**
|
5
|
-
*
|
6
|
-
* @param fieldNames
|
7
|
-
* @return {FieldFilter}
|
8
|
-
*/
|
9
|
-
function ofIncluded(...fieldNames) {
|
10
|
-
return new FieldFilterImpl(INCLUDED).addIncluded(...fieldNames);
|
11
|
-
}
|
12
|
-
|
13
|
-
/**
|
14
|
-
*
|
15
|
-
* @param fieldNames
|
16
|
-
* @return {FieldFilter}
|
17
|
-
*/
|
18
|
-
function ofExcluded(...fieldNames) {
|
19
|
-
return new FieldFilterImpl(EXCLUDED).addExcluded(...fieldNames);
|
20
|
-
}
|
21
|
-
|
22
|
-
export {
|
23
|
-
ofIncluded,
|
24
|
-
ofExcluded,
|
25
|
-
};
|
@@ -1,28 +0,0 @@
|
|
1
|
-
import {FieldFilter} from "../FieldFilter.js";
|
2
|
-
|
3
|
-
class FieldFilterSerializer {
|
4
|
-
|
5
|
-
serialize(obj) {
|
6
|
-
if (obj instanceof FieldFilter) {
|
7
|
-
return this.serializeFieldFilter(obj);
|
8
|
-
}
|
9
|
-
return obj;
|
10
|
-
}
|
11
|
-
|
12
|
-
serializeFieldFilter(fieldFilter) {
|
13
|
-
return {
|
14
|
-
"@type": "FieldFilter",
|
15
|
-
"filterMode": fieldFilter.getFilterMode(),
|
16
|
-
"fieldNames": fieldFilter.getFieldNames(),
|
17
|
-
"ignoreNullValue": fieldFilter.getIgnoreNullValue(),
|
18
|
-
};
|
19
|
-
}
|
20
|
-
|
21
|
-
}
|
22
|
-
|
23
|
-
const FIELD_FILTER_SERIALIZER = new FieldFilterSerializer();
|
24
|
-
|
25
|
-
export {
|
26
|
-
FIELD_FILTER_SERIALIZER,
|
27
|
-
FieldFilterSerializer,
|
28
|
-
};
|
File without changes
|