@leyyo/query 1.3.5 → 1.3.6
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/error/index.d.ts +2 -2
- package/dist/error/index.js +2 -2
- package/dist/error/index.types.d.ts +1 -1
- package/dist/field/index.d.ts +1 -1
- package/dist/field/index.js +1 -1
- package/dist/group-by/index.d.ts +1 -1
- package/dist/group-by/index.js +1 -1
- package/dist/index.d.ts +12 -12
- package/dist/index.foretell.js +4 -4
- package/dist/index.js +12 -12
- package/dist/index.loader.js +3 -3
- package/dist/operation/index.d.ts +1 -1
- package/dist/operation/index.js +1 -1
- package/dist/operation/operation-type.d.ts +1 -1
- package/dist/operation/operation-type.js +130 -130
- package/dist/order-by/index.d.ts +1 -1
- package/dist/order-by/index.js +1 -1
- package/dist/order-type/index.d.ts +1 -1
- package/dist/order-type/index.js +1 -1
- package/dist/order-type/order-type.d.ts +1 -1
- package/dist/order-type/order-type.js +1 -1
- package/dist/pagination/index.d.ts +1 -1
- package/dist/pagination/index.js +1 -1
- package/dist/parser/index.d.ts +2 -2
- package/dist/parser/index.js +2 -2
- package/dist/parser/index.types.d.ts +1 -1
- package/dist/parser/query.parser.js +53 -59
- package/dist/query/index.d.ts +1 -1
- package/dist/query/index.js +1 -1
- package/dist/select/index.d.ts +1 -1
- package/dist/select/index.js +1 -1
- package/dist/select/index.types.d.ts +1 -1
- package/dist/where/index.d.ts +1 -1
- package/dist/where/index.js +1 -1
- package/package.json +19 -33
package/dist/error/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./invalid-query-value.error.js";
|
|
2
|
+
export * from "./index.types.js";
|
package/dist/error/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./invalid-query-value.error.js";
|
|
2
|
+
export * from "./index.types.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type QueryErrorCode =
|
|
1
|
+
export type QueryErrorCode = "xxx" | "field:invalid" | "field:empty" | "field:raw-both" | "field:raw-none" | "as:invalid" | "raw:invalid" | "raw:empty" | "op:invalid-key" | "op:invalid-type" | "asc:invalid-key" | "asc:invalid-type" | "value:invalid-type" | "value:invalid-item" | "integer:invalid" | "integer:min" | "select:item" | "select:body" | "where:item" | "where:body" | "having:item" | "having:body" | "groupBy:item" | "groupBy:body" | "orderBy:item" | "orderBy:body" | "page:conflict" | "limit:conflict" | "pagination:invalid-key" | "pagination:invalid-type";
|
package/dist/field/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
package/dist/field/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
package/dist/group-by/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
package/dist/group-by/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
1
|
+
export * from "./operation/index.js";
|
|
2
|
+
export * from "./error/index.js";
|
|
3
|
+
export * from "./field/index.js";
|
|
4
|
+
export * from "./group-by/index.js";
|
|
5
|
+
export * from "./order-by/index.js";
|
|
6
|
+
export * from "./pagination/index.js";
|
|
7
|
+
export * from "./parser/index.js";
|
|
8
|
+
export * from "./query/index.js";
|
|
9
|
+
export * from "./select/index.js";
|
|
10
|
+
export * from "./where/index.js";
|
|
11
|
+
export * from "./index.foretell.js";
|
|
12
|
+
export * from "./index.loader.js";
|
package/dist/index.foretell.js
CHANGED
|
@@ -5,13 +5,13 @@ export const foretell_leyyoQuery = [
|
|
|
5
5
|
// dependencies
|
|
6
6
|
...foretell_leyyoCommon,
|
|
7
7
|
// errors
|
|
8
|
-
() => errorPool.lazy(FQN,
|
|
8
|
+
() => errorPool.lazy(FQN, "InvalidQueryValueError", import("./error/invalid-query-value.error.js").then((m) => m.InvalidQueryValueError), { i18n: true, emit: true }),
|
|
9
9
|
// enums
|
|
10
10
|
() => literalPool.register({
|
|
11
|
-
name:
|
|
11
|
+
name: "OperationType",
|
|
12
12
|
fqn: FQN,
|
|
13
13
|
i18n: true,
|
|
14
|
-
lazyTarget: import(
|
|
15
|
-
lazyAlt: import(
|
|
14
|
+
lazyTarget: import("./operation/operation-type.js").then((m) => m.OperationTypeItems),
|
|
15
|
+
lazyAlt: import("./operation/operation-type.js").then((m) => m.OperationTypeMap),
|
|
16
16
|
}),
|
|
17
17
|
];
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from
|
|
12
|
-
export * from
|
|
1
|
+
export * from "./operation/index.js";
|
|
2
|
+
export * from "./error/index.js";
|
|
3
|
+
export * from "./field/index.js";
|
|
4
|
+
export * from "./group-by/index.js";
|
|
5
|
+
export * from "./order-by/index.js";
|
|
6
|
+
export * from "./pagination/index.js";
|
|
7
|
+
export * from "./parser/index.js";
|
|
8
|
+
export * from "./query/index.js";
|
|
9
|
+
export * from "./select/index.js";
|
|
10
|
+
export * from "./where/index.js";
|
|
11
|
+
export * from "./index.foretell.js";
|
|
12
|
+
export * from "./index.loader.js";
|
package/dist/index.loader.js
CHANGED
|
@@ -5,8 +5,8 @@ export const loader_leyyoQuery = defineLoader(FQN,
|
|
|
5
5
|
// dependencies
|
|
6
6
|
...loader_leyyoCommon,
|
|
7
7
|
// errors
|
|
8
|
-
() => import(
|
|
8
|
+
() => import("./error/invalid-query-value.error.js").then((m) => m.InvalidQueryValueError),
|
|
9
9
|
// enums
|
|
10
|
-
() => import(
|
|
10
|
+
() => import("./operation/operation-type.js").then((m) => m.OperationTypeItems),
|
|
11
11
|
// classes
|
|
12
|
-
() => import(
|
|
12
|
+
() => import("./parser/query.parser.js").then((m) => m.queryParser));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./operation-type.js";
|
package/dist/operation/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./operation-type.js";
|
|
@@ -2,7 +2,7 @@ declare const literals: readonly ["eq", "ne", "null", "!null", "missing", "!miss
|
|
|
2
2
|
/**
|
|
3
3
|
* Operation Type
|
|
4
4
|
* */
|
|
5
|
-
export type OperationType = typeof literals[number];
|
|
5
|
+
export type OperationType = (typeof literals)[number];
|
|
6
6
|
export declare const OperationTypeItems: ReadonlyArray<OperationType>;
|
|
7
7
|
export declare const OperationTypeMap: Record<string, OperationType>;
|
|
8
8
|
export {};
|
|
@@ -1,147 +1,147 @@
|
|
|
1
1
|
const literals = [
|
|
2
2
|
// all
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
"eq",
|
|
4
|
+
"ne",
|
|
5
|
+
"null",
|
|
6
|
+
"!null",
|
|
7
|
+
"missing",
|
|
8
|
+
"!missing",
|
|
9
9
|
// string, number
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
"gt",
|
|
11
|
+
"gte",
|
|
12
|
+
"lt",
|
|
13
|
+
"lte",
|
|
14
|
+
"between",
|
|
15
|
+
"!between",
|
|
16
|
+
"in",
|
|
17
|
+
"!in",
|
|
18
18
|
// string
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
19
|
+
"starts",
|
|
20
|
+
"!starts",
|
|
21
|
+
"ends",
|
|
22
|
+
"!ends",
|
|
23
|
+
"matches",
|
|
24
|
+
"!matches",
|
|
25
|
+
"contains", // left includes right
|
|
26
|
+
"!contains", // left does not include right
|
|
27
|
+
"contained", // right includes left
|
|
28
|
+
"!contained", // right does not include left
|
|
29
29
|
// boolean
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
"true",
|
|
31
|
+
"false",
|
|
32
32
|
// array object
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
"includes",
|
|
34
|
+
"!includes",
|
|
35
|
+
"intersects",
|
|
36
|
+
"!intersects",
|
|
37
37
|
// json object
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
"exists",
|
|
39
|
+
"!exists",
|
|
40
40
|
];
|
|
41
41
|
export const OperationTypeItems = literals;
|
|
42
42
|
// noinspection JSUnusedGlobalSymbols
|
|
43
43
|
export const OperationTypeMap = {
|
|
44
44
|
// all
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
45
|
+
"=": "eq",
|
|
46
|
+
"==": "eq",
|
|
47
|
+
equals: "eq",
|
|
48
|
+
equal: "eq",
|
|
49
|
+
"!equals": "ne",
|
|
50
|
+
"!equal": "ne",
|
|
51
|
+
"!=": "ne",
|
|
52
|
+
"<>": "ne",
|
|
53
|
+
"not-equals": "ne",
|
|
54
|
+
"not-equal": "ne",
|
|
55
|
+
"is-null": "null",
|
|
56
|
+
"!": "null",
|
|
57
|
+
nil: "null",
|
|
58
|
+
"!!": "!null",
|
|
59
|
+
"not-null": "!null",
|
|
60
|
+
"is-missing": "missing",
|
|
61
|
+
"is-undefined": "missing",
|
|
62
|
+
undefined: "missing",
|
|
63
|
+
"not-missing": "!missing",
|
|
64
|
+
"not-undefined": "!missing",
|
|
65
|
+
defined: "!missing",
|
|
66
66
|
// string, number
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
67
|
+
"greater-than": "gt",
|
|
68
|
+
">": "gt",
|
|
69
|
+
"greater-than-or-equals": "gte",
|
|
70
|
+
">=": "gte",
|
|
71
|
+
"=>": "gte",
|
|
72
|
+
"less-than": "lt",
|
|
73
|
+
less: "lt",
|
|
74
|
+
"<": "lt",
|
|
75
|
+
"less-than-or-equals": "lte",
|
|
76
|
+
"=<": "lte",
|
|
77
|
+
"<=": "lte",
|
|
78
|
+
"()": "between",
|
|
79
|
+
"not-between": "!between",
|
|
80
|
+
")(": "!between",
|
|
81
|
+
"[]": "in",
|
|
82
|
+
"][": "!in",
|
|
83
|
+
"not-in": "!in",
|
|
84
84
|
// string
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
85
|
+
"starts-with": "starts",
|
|
86
|
+
"start-with": "starts",
|
|
87
|
+
"^": "starts",
|
|
88
|
+
start: "starts",
|
|
89
|
+
"not-starts-with": "!starts",
|
|
90
|
+
"not-start-with": "!starts",
|
|
91
|
+
"not-starts": "!starts",
|
|
92
|
+
"not-start": "!starts",
|
|
93
|
+
"!starts-with": "!starts",
|
|
94
|
+
"!start-with": "!starts",
|
|
95
|
+
"!^": "!starts",
|
|
96
|
+
"!start": "!starts",
|
|
97
|
+
"ends-with": "ends",
|
|
98
|
+
"end-with": "ends",
|
|
99
|
+
$: "ends",
|
|
100
|
+
end: "ends",
|
|
101
|
+
"not-end-with": "!ends",
|
|
102
|
+
"not-ends": "!ends",
|
|
103
|
+
"not-end": "!ends",
|
|
104
|
+
"!$": "!ends",
|
|
105
|
+
"!ends-with": "!ends",
|
|
106
|
+
"!end-with": "!ends",
|
|
107
|
+
"!end": "!ends",
|
|
108
|
+
match: "matches",
|
|
109
|
+
"not-matches": "!matches",
|
|
110
|
+
"not-match": "!matches",
|
|
111
|
+
"!match": "!matches",
|
|
112
|
+
"!matches": "!matches",
|
|
113
|
+
like: "contains",
|
|
114
|
+
likes: "contains",
|
|
115
|
+
contain: "contains",
|
|
116
|
+
"not-contains": "!contains",
|
|
117
|
+
"not-contain": "!contains",
|
|
118
|
+
"!contain": "!contains",
|
|
119
|
+
"not-likes": "!contains",
|
|
120
|
+
"not-like": "!contains",
|
|
121
|
+
"!likes": "!contains",
|
|
122
|
+
"!like": "!contains",
|
|
123
123
|
// boolean
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
124
|
+
yes: "true",
|
|
125
|
+
no: "false",
|
|
126
|
+
on: "true",
|
|
127
|
+
off: "false",
|
|
128
|
+
ok: "true",
|
|
129
|
+
none: "false",
|
|
130
130
|
// array object
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
131
|
+
include: "includes",
|
|
132
|
+
"not-includes": "!includes",
|
|
133
|
+
"not-include": "!includes",
|
|
134
|
+
"!include": "!includes",
|
|
135
|
+
intersect: "intersects",
|
|
136
|
+
"not-intersects": "!intersects",
|
|
137
|
+
"not-intersect": "!intersects",
|
|
138
|
+
"!intersect": "!intersects",
|
|
139
|
+
exist: "exists",
|
|
140
|
+
"?": "exists",
|
|
141
|
+
"??": "exists",
|
|
142
|
+
"not-exists": "!exists",
|
|
143
|
+
"not-exist": "!exists",
|
|
144
|
+
"!?": "!exists",
|
|
145
|
+
"!??": "!exists",
|
|
146
|
+
"!exist": "!exists",
|
|
147
147
|
};
|
package/dist/order-by/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
package/dist/order-by/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./order-type.js";
|
package/dist/order-type/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./order-type.js";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const literals = [
|
|
1
|
+
const literals = ["asc", "desc"];
|
|
2
2
|
export const OrderTypeItems = literals;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
package/dist/pagination/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
package/dist/parser/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
|
2
|
+
export * from "./query.parser.js";
|
package/dist/parser/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
|
2
|
+
export * from "./query.parser.js";
|
|
@@ -3,4 +3,4 @@ import { BasicType } from "@leyyo/common";
|
|
|
3
3
|
export interface QueryParserLike {
|
|
4
4
|
exec<K extends string>(query: QueryAny<K>, availableFields: Array<K | string>, name?: string): QueryRegular<K>;
|
|
5
5
|
}
|
|
6
|
-
export type QueryValueType = BasicType |
|
|
6
|
+
export type QueryValueType = BasicType | "array" | "null" | "integer" | "*";
|
|
@@ -8,14 +8,14 @@ class QueryParser {
|
|
|
8
8
|
return new InvalidQueryValueError(code, message, path);
|
|
9
9
|
}
|
|
10
10
|
_invalid(value, path, expected, code) {
|
|
11
|
-
const ex = Array.isArray(expected) ? `[${expected.join(
|
|
11
|
+
const ex = Array.isArray(expected) ? `[${expected.join(", ")}]` : expected;
|
|
12
12
|
return this._error(code, `It's expected as ${ex}, but it's type: ${typeof value}`, path);
|
|
13
13
|
}
|
|
14
14
|
_emptyOrInvalid(value, path, expected, empty, invalid) {
|
|
15
15
|
if (isEmpty(value)) {
|
|
16
16
|
return this._error(empty, `It's empty`, path);
|
|
17
17
|
}
|
|
18
|
-
if (typeof value ===
|
|
18
|
+
if (typeof value === "string" && value.trim() === "") {
|
|
19
19
|
return this._error(empty, `It's empty`, path);
|
|
20
20
|
}
|
|
21
21
|
return this._invalid(value, path, expected, invalid);
|
|
@@ -24,31 +24,31 @@ class QueryParser {
|
|
|
24
24
|
if (isEmpty(value)) {
|
|
25
25
|
return true;
|
|
26
26
|
}
|
|
27
|
-
if (typeof value ===
|
|
27
|
+
if (typeof value === "boolean") {
|
|
28
28
|
return value;
|
|
29
29
|
}
|
|
30
30
|
else if (isText(value)) {
|
|
31
|
-
if (value.toLowerCase() ===
|
|
31
|
+
if (value.toLowerCase() === "asc") {
|
|
32
32
|
return true;
|
|
33
33
|
}
|
|
34
|
-
else if (value.toLowerCase() ===
|
|
34
|
+
else if (value.toLowerCase() === "desc") {
|
|
35
35
|
return false;
|
|
36
36
|
}
|
|
37
|
-
throw this._error(
|
|
37
|
+
throw this._error("asc:invalid-key", `It should be [asc, desc], but it's value: ${value}`, path);
|
|
38
38
|
}
|
|
39
|
-
throw this._invalid(value, path, [
|
|
39
|
+
throw this._invalid(value, path, ["boolean", "string"], "asc:invalid-type");
|
|
40
40
|
}
|
|
41
41
|
_field(value, path) {
|
|
42
42
|
if (isText(value)) {
|
|
43
43
|
return value;
|
|
44
44
|
}
|
|
45
|
-
throw this._emptyOrInvalid(value, path,
|
|
45
|
+
throw this._emptyOrInvalid(value, path, "string", "field:empty", "field:invalid");
|
|
46
46
|
}
|
|
47
47
|
_raw(value, path) {
|
|
48
48
|
if (isText(value)) {
|
|
49
49
|
return value;
|
|
50
50
|
}
|
|
51
|
-
throw this._emptyOrInvalid(value, path,
|
|
51
|
+
throw this._emptyOrInvalid(value, path, "string", "raw:empty", "raw:invalid");
|
|
52
52
|
}
|
|
53
53
|
_as(value, path) {
|
|
54
54
|
if (isEmpty(value)) {
|
|
@@ -57,11 +57,11 @@ class QueryParser {
|
|
|
57
57
|
else if (isText(value)) {
|
|
58
58
|
return value;
|
|
59
59
|
}
|
|
60
|
-
throw this._invalid(value, path,
|
|
60
|
+
throw this._invalid(value, path, "string", "as:invalid");
|
|
61
61
|
}
|
|
62
62
|
_operation(value, path) {
|
|
63
63
|
if (isEmpty(value)) {
|
|
64
|
-
return
|
|
64
|
+
return "eq";
|
|
65
65
|
}
|
|
66
66
|
else if (isText(value)) {
|
|
67
67
|
const key = value;
|
|
@@ -71,9 +71,9 @@ class QueryParser {
|
|
|
71
71
|
if (OperationTypeMap[key] !== undefined) {
|
|
72
72
|
return OperationTypeMap[key];
|
|
73
73
|
}
|
|
74
|
-
throw this._error(
|
|
74
|
+
throw this._error("op:invalid-key", `It should be [@see operations], but it's value: ${value}`, path);
|
|
75
75
|
}
|
|
76
|
-
throw this._invalid(value, path,
|
|
76
|
+
throw this._invalid(value, path, "string", "op:invalid-type");
|
|
77
77
|
}
|
|
78
78
|
_value(value, path) {
|
|
79
79
|
if (value === undefined) {
|
|
@@ -83,7 +83,7 @@ class QueryParser {
|
|
|
83
83
|
case "string":
|
|
84
84
|
value = value.trim();
|
|
85
85
|
if (!value) {
|
|
86
|
-
throw this._error(
|
|
86
|
+
throw this._error("value:invalid-type", `It should not be empty string`, path);
|
|
87
87
|
}
|
|
88
88
|
return [value];
|
|
89
89
|
case "number":
|
|
@@ -96,8 +96,8 @@ class QueryParser {
|
|
|
96
96
|
if (Array.isArray(value)) {
|
|
97
97
|
let index = 0;
|
|
98
98
|
for (const item of value) {
|
|
99
|
-
if (!isText(item) && typeof value !==
|
|
100
|
-
throw this._invalid(item, `${path}[${index}]`, [
|
|
99
|
+
if (!isText(item) && typeof value !== "number" && typeof value !== "boolean") {
|
|
100
|
+
throw this._invalid(item, `${path}[${index}]`, ["string", "number", "boolean", "array", "number"], "value:invalid-item");
|
|
101
101
|
}
|
|
102
102
|
index++;
|
|
103
103
|
}
|
|
@@ -105,7 +105,7 @@ class QueryParser {
|
|
|
105
105
|
}
|
|
106
106
|
break;
|
|
107
107
|
}
|
|
108
|
-
throw this._invalid(value, path, [
|
|
108
|
+
throw this._invalid(value, path, ["string", "number", "boolean", "array", "number"], "value:invalid-type");
|
|
109
109
|
}
|
|
110
110
|
_num(value, path, min) {
|
|
111
111
|
if (isEmpty(value)) {
|
|
@@ -115,16 +115,16 @@ class QueryParser {
|
|
|
115
115
|
if (value >= min) {
|
|
116
116
|
return value;
|
|
117
117
|
}
|
|
118
|
-
throw this._error(
|
|
118
|
+
throw this._error("integer:min", `It should be gte ${min}`, path);
|
|
119
119
|
}
|
|
120
|
-
throw this._invalid(value, path, [
|
|
120
|
+
throw this._invalid(value, path, ["integer"], "integer:invalid");
|
|
121
121
|
}
|
|
122
122
|
_fieldXorRaw(field, raw, path) {
|
|
123
123
|
if (!raw && !field) {
|
|
124
|
-
throw this._error(
|
|
124
|
+
throw this._error("field:raw-none", `Field or raw are not provided, one of them should be`, path);
|
|
125
125
|
}
|
|
126
126
|
else if (raw && field) {
|
|
127
|
-
throw this._error(
|
|
127
|
+
throw this._error("field:raw-both", `Field and raw are provided together, Field or raw are not provided, only one of them should be`, path);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
// endregion private
|
|
@@ -137,7 +137,7 @@ class QueryParser {
|
|
|
137
137
|
// 1 - '*'
|
|
138
138
|
// 2 - Array<K | [K, string] | SelectGiven<K> | SelectGivenRaw>
|
|
139
139
|
// case 1: string as K
|
|
140
|
-
if (given ===
|
|
140
|
+
if (given === "*") {
|
|
141
141
|
return { all: true };
|
|
142
142
|
}
|
|
143
143
|
const newSelect = { fields: [] };
|
|
@@ -159,11 +159,10 @@ class QueryParser {
|
|
|
159
159
|
let [field, as] = item;
|
|
160
160
|
field = this._field(field, `select[${index}][0]`);
|
|
161
161
|
as = this._as(as, `select[${index}][1]`);
|
|
162
|
-
newSelect.fields.push({ field, as
|
|
162
|
+
newSelect.fields.push({ field, as });
|
|
163
163
|
}
|
|
164
164
|
// Case 2C: SelectGiven<K> | SelectGivenRaw
|
|
165
165
|
else if (isFilledObj(item)) {
|
|
166
|
-
let as;
|
|
167
166
|
let field;
|
|
168
167
|
let raw;
|
|
169
168
|
const obj = item;
|
|
@@ -174,7 +173,7 @@ class QueryParser {
|
|
|
174
173
|
field = this._field(obj.field, `select[${index}].field`);
|
|
175
174
|
}
|
|
176
175
|
this._fieldXorRaw(field, raw, `select[${index}].field`);
|
|
177
|
-
as = this._as(obj.as, `select[${index}].as`);
|
|
176
|
+
const as = this._as(obj.as, `select[${index}].as`);
|
|
178
177
|
if (field) {
|
|
179
178
|
newSelect.fields.push({ field, as });
|
|
180
179
|
}
|
|
@@ -184,13 +183,13 @@ class QueryParser {
|
|
|
184
183
|
}
|
|
185
184
|
// other
|
|
186
185
|
else {
|
|
187
|
-
throw this._invalid(item, `select[${index}]`, [
|
|
186
|
+
throw this._invalid(item, `select[${index}]`, ["string", "array", "object"], "select:item");
|
|
188
187
|
}
|
|
189
188
|
});
|
|
190
189
|
}
|
|
191
190
|
// case: other
|
|
192
191
|
else {
|
|
193
|
-
throw this._invalid(given, `select`, [
|
|
192
|
+
throw this._invalid(given, `select`, ["*", "array"], "select:body");
|
|
194
193
|
}
|
|
195
194
|
return newSelect;
|
|
196
195
|
}
|
|
@@ -205,10 +204,10 @@ class QueryParser {
|
|
|
205
204
|
// case 1: WhereValue<K>
|
|
206
205
|
if (isFilledObj(given)) {
|
|
207
206
|
let index = 0;
|
|
208
|
-
for (
|
|
207
|
+
for (const [k, v] of Object.entries(given)) {
|
|
209
208
|
const field = this._field(k, `${scope}(key=${index})`);
|
|
210
209
|
const value = this._value(v, `${scope}.${field}`);
|
|
211
|
-
newWhere.push({ field, value, op:
|
|
210
|
+
newWhere.push({ field, value, op: "eq" });
|
|
212
211
|
index++;
|
|
213
212
|
}
|
|
214
213
|
}
|
|
@@ -223,8 +222,6 @@ class QueryParser {
|
|
|
223
222
|
if (isFilledObj(item)) {
|
|
224
223
|
let field;
|
|
225
224
|
let raw;
|
|
226
|
-
let op;
|
|
227
|
-
let value;
|
|
228
225
|
let fullRaw;
|
|
229
226
|
const obj = item;
|
|
230
227
|
if (!isEmpty(obj.raw)) {
|
|
@@ -238,8 +235,8 @@ class QueryParser {
|
|
|
238
235
|
if (raw && isEmpty(whereItem.op) && isEmpty(whereItem.value)) {
|
|
239
236
|
fullRaw = true;
|
|
240
237
|
}
|
|
241
|
-
op = this._operation(whereItem.op, `${scope}[${index}].op`);
|
|
242
|
-
value = this._value(whereItem.value, `${scope}[${index}].value`);
|
|
238
|
+
const op = this._operation(whereItem.op, `${scope}[${index}].op`);
|
|
239
|
+
const value = this._value(whereItem.value, `${scope}[${index}].value`);
|
|
243
240
|
if (field) {
|
|
244
241
|
newWhere.push({ field, op, value });
|
|
245
242
|
}
|
|
@@ -249,20 +246,18 @@ class QueryParser {
|
|
|
249
246
|
}
|
|
250
247
|
// Case 2B: |[K, unknown]
|
|
251
248
|
else if (Array.isArray(item) && item.length > 0) {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
value = this._value(item[1], `${scope}[${index}][1]`);
|
|
256
|
-
newWhere.push({ field, value, op: 'eq' });
|
|
249
|
+
const field = this._field(item[0], `${scope}[${index}][0]`);
|
|
250
|
+
const value = this._value(item[1], `${scope}[${index}][1]`);
|
|
251
|
+
newWhere.push({ field, value, op: "eq" });
|
|
257
252
|
}
|
|
258
253
|
else {
|
|
259
|
-
throw this._invalid(item, `${scope}[${index}]`, [
|
|
254
|
+
throw this._invalid(item, `${scope}[${index}]`, ["object", "array"], scope === "where" ? "where:item" : "having:item");
|
|
260
255
|
}
|
|
261
256
|
});
|
|
262
257
|
}
|
|
263
258
|
// case: other
|
|
264
259
|
else {
|
|
265
|
-
throw this._invalid(given, scope, [
|
|
260
|
+
throw this._invalid(given, scope, ["object", "array"], scope === "where" ? "where:body" : "having:body");
|
|
266
261
|
}
|
|
267
262
|
return newWhere;
|
|
268
263
|
}
|
|
@@ -304,13 +299,13 @@ class QueryParser {
|
|
|
304
299
|
newGroup.push({ field: item });
|
|
305
300
|
}
|
|
306
301
|
else {
|
|
307
|
-
throw this._invalid(item, `groupBy[${index}]`, [
|
|
302
|
+
throw this._invalid(item, `groupBy[${index}]`, ["string", "object"], "groupBy:item");
|
|
308
303
|
}
|
|
309
304
|
});
|
|
310
305
|
}
|
|
311
306
|
// case: other
|
|
312
307
|
else {
|
|
313
|
-
throw this._invalid(given, `groupBy`, [
|
|
308
|
+
throw this._invalid(given, `groupBy`, ["array"], "groupBy:body");
|
|
314
309
|
}
|
|
315
310
|
return newGroup;
|
|
316
311
|
}
|
|
@@ -336,7 +331,6 @@ class QueryParser {
|
|
|
336
331
|
arr.forEach((item, index) => {
|
|
337
332
|
// Case 2A: OrderByGiven<K>|OrderByGivenRaw
|
|
338
333
|
if (isFilledObj(item)) {
|
|
339
|
-
let asc;
|
|
340
334
|
let field;
|
|
341
335
|
let raw;
|
|
342
336
|
const obj = item;
|
|
@@ -347,7 +341,7 @@ class QueryParser {
|
|
|
347
341
|
field = this._field(obj.field, `orderBy[${index}].field`);
|
|
348
342
|
}
|
|
349
343
|
this._fieldXorRaw(field, raw, `orderBy[${index}].field`);
|
|
350
|
-
asc = this._asc(obj.asc, `orderBy[${index}].asc`);
|
|
344
|
+
const asc = this._asc(obj.asc, `orderBy[${index}].asc`);
|
|
351
345
|
if (field) {
|
|
352
346
|
newOrder.push({ field, asc });
|
|
353
347
|
}
|
|
@@ -357,18 +351,18 @@ class QueryParser {
|
|
|
357
351
|
}
|
|
358
352
|
// Case 2B: K
|
|
359
353
|
else if (isText(item)) {
|
|
360
|
-
newOrder.push({ field: this._field(item,
|
|
354
|
+
newOrder.push({ field: this._field(item, ""), asc: true });
|
|
361
355
|
}
|
|
362
356
|
// other
|
|
363
357
|
else {
|
|
364
|
-
throw this._invalid(item, `orderBy[${index}]`, [
|
|
358
|
+
throw this._invalid(item, `orderBy[${index}]`, ["string", "object"], "orderBy:item");
|
|
365
359
|
}
|
|
366
360
|
});
|
|
367
361
|
}
|
|
368
362
|
// case 3: {'id': true, name: true, ...} as OrderByValue<K>
|
|
369
363
|
else if (isFilledObj(given)) {
|
|
370
364
|
let index = 0;
|
|
371
|
-
for (
|
|
365
|
+
for (const [k, v] of Object.entries(given)) {
|
|
372
366
|
const field = this._field(k, `orderBy(key=${index})`);
|
|
373
367
|
const asc = this._asc(v, `orderBy.${field}`);
|
|
374
368
|
newOrder.push({ field, asc });
|
|
@@ -377,7 +371,7 @@ class QueryParser {
|
|
|
377
371
|
}
|
|
378
372
|
// case: other
|
|
379
373
|
else {
|
|
380
|
-
throw this._invalid(given, `orderBy`, [
|
|
374
|
+
throw this._invalid(given, `orderBy`, ["string", "array", "object"], "orderBy:body");
|
|
381
375
|
}
|
|
382
376
|
return newOrder;
|
|
383
377
|
}
|
|
@@ -392,7 +386,7 @@ class QueryParser {
|
|
|
392
386
|
}
|
|
393
387
|
return {
|
|
394
388
|
limit: this._num(given[0], `pagination[0]`, 1),
|
|
395
|
-
offset: this._num(given[1], `pagination[1]`, 0)
|
|
389
|
+
offset: this._num(given[1], `pagination[1]`, 0),
|
|
396
390
|
};
|
|
397
391
|
}
|
|
398
392
|
// Case 2: PaginationPage | PaginationLimit
|
|
@@ -404,37 +398,37 @@ class QueryParser {
|
|
|
404
398
|
if (!isEmpty(obj.page)) {
|
|
405
399
|
const page = this._num(obj.page, `pagination.page`, 1);
|
|
406
400
|
const size = this._num(obj.size, `pagination.size`, 1) ?? 50;
|
|
407
|
-
[
|
|
401
|
+
["limit", "offset"].forEach((f) => {
|
|
408
402
|
if (!isEmpty(given[f])) {
|
|
409
|
-
throw this._error(
|
|
403
|
+
throw this._error("page:conflict", "If you give page; limit and offset can not be used anymore", `pagination.page`);
|
|
410
404
|
}
|
|
411
405
|
});
|
|
412
406
|
return {
|
|
413
407
|
limit: size,
|
|
414
|
-
offset: (page - 1) * size
|
|
408
|
+
offset: (page - 1) * size,
|
|
415
409
|
};
|
|
416
410
|
}
|
|
417
411
|
if (!isEmpty(obj.limit)) {
|
|
418
|
-
[
|
|
412
|
+
["page", "size"].forEach((f) => {
|
|
419
413
|
if (!isEmpty(obj[f])) {
|
|
420
|
-
throw this._error(
|
|
414
|
+
throw this._error("limit:conflict", "If you give limit; page and size can not be used anymore", `pagination.limit`);
|
|
421
415
|
}
|
|
422
416
|
});
|
|
423
417
|
return {
|
|
424
418
|
limit: this._num(obj.limit, `pagination.limit`, 1),
|
|
425
|
-
offset: this._num(obj.offset, `pagination.offset`, 0)
|
|
419
|
+
offset: this._num(obj.offset, `pagination.offset`, 0),
|
|
426
420
|
};
|
|
427
421
|
}
|
|
428
|
-
throw this._error(
|
|
422
|
+
throw this._error("pagination:invalid-key", "Pagination should have limit/offset or page/size keys", "pagination");
|
|
429
423
|
}
|
|
430
|
-
throw this._invalid(given,
|
|
424
|
+
throw this._invalid(given, "pagination", ["array", "object"], "pagination:invalid-type");
|
|
431
425
|
}
|
|
432
426
|
// endregion parts
|
|
433
427
|
exec(query, availableFields, name) {
|
|
434
428
|
return {
|
|
435
429
|
select: this._select(query?.select, availableFields, name),
|
|
436
|
-
where: this._where(
|
|
437
|
-
having: this._where(
|
|
430
|
+
where: this._where("where", query?.where, availableFields, name),
|
|
431
|
+
having: this._where("having", query?.having, availableFields, name),
|
|
438
432
|
groupBy: this._groupBy(query?.groupBy, availableFields, name),
|
|
439
433
|
orderBy: this._orderBy(query?.orderBy, availableFields, name),
|
|
440
434
|
pagination: this._pagination(query?.pagination, name),
|
package/dist/query/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
package/dist/query/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
package/dist/select/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
package/dist/select/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { FieldAs, FieldRaw, FieldRegular } from "../field/index.js";
|
|
2
|
-
export type SelectAny<K extends string> =
|
|
2
|
+
export type SelectAny<K extends string> = "*" | Array<K | [K, string] | SelectGiven<K> | SelectGivenRaw>;
|
|
3
3
|
export type SelectGiven<K extends string> = FieldRegular<K> & FieldAs;
|
|
4
4
|
export type SelectGivenRaw = FieldRaw & FieldAs;
|
|
5
5
|
export interface Select<K extends string> {
|
package/dist/where/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
package/dist/where/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "./index.types.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leyyo/query",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.6",
|
|
4
4
|
"description": "Query common component",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Query"
|
|
@@ -21,51 +21,37 @@
|
|
|
21
21
|
"main": "dist/index.js",
|
|
22
22
|
"type": "module",
|
|
23
23
|
"scripts": {
|
|
24
|
-
"clear": "rimraf dist
|
|
25
|
-
"
|
|
26
|
-
"lint": "eslint src/**/*.ts --
|
|
27
|
-
"
|
|
24
|
+
"clear": "rimraf dist",
|
|
25
|
+
"lint": "eslint src/**/*.ts",
|
|
26
|
+
"lint:fix": "eslint src/**/*.ts --fix",
|
|
27
|
+
"format": "prettier --check \"{src,test}/**/*.{ts,tsx,js}\"",
|
|
28
|
+
"format:force": "prettier --write \"{src,test}/**/*.{ts,tsx,js}\"",
|
|
29
|
+
"test": "vitest run",
|
|
30
|
+
"test:watch": "vitest",
|
|
31
|
+
"test:coverage": "vitest run --coverage",
|
|
28
32
|
"asset": "node -r ts-node/register commands/assets.js",
|
|
29
33
|
"build": "npm run clear && tsc && npm run asset",
|
|
30
|
-
"
|
|
31
|
-
"coverage": "rimraf coverage && jest --config=jest.json --coverage --coverageDirectory=coverage",
|
|
32
|
-
"sample": "node -r ts-node/register src/sample.ts",
|
|
33
|
-
"publish:public": "npm run build && npm publish -access=public"
|
|
34
|
+
"publish:public": "npm run lint && npm run format:force && npm run test && npm run build && npm publish --access=public"
|
|
34
35
|
},
|
|
35
36
|
"files": [
|
|
36
37
|
"dist/*"
|
|
37
38
|
],
|
|
38
39
|
"license": "ISC",
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@
|
|
41
|
-
"@babel/preset-typescript": "^7.27.1",
|
|
42
|
-
"@eslint/js": "^9.33.0",
|
|
43
|
-
"@types/jest": "^30.0.0",
|
|
41
|
+
"@eslint/js": "^9.0.0",
|
|
44
42
|
"@types/node": "^24.2.1",
|
|
45
|
-
"@
|
|
46
|
-
"
|
|
47
|
-
"eslint": "^9.33.0",
|
|
43
|
+
"@vitest/coverage-istanbul": "^4.0.18",
|
|
44
|
+
"eslint": "^9.0.0",
|
|
48
45
|
"eslint-config-prettier": "^10.1.8",
|
|
49
|
-
"eslint-
|
|
50
|
-
"
|
|
51
|
-
"eslint-plugin-jsdoc": "^54.0.0",
|
|
52
|
-
"eslint-plugin-node": "^11.1.0",
|
|
53
|
-
"husky": "^9.1.7",
|
|
54
|
-
"jest": "^29.7.0",
|
|
55
|
-
"prettier": "^3.6.2",
|
|
46
|
+
"eslint-plugin-n": "^17.24.0",
|
|
47
|
+
"prettier": "^3.8.1",
|
|
56
48
|
"rimraf": "^6.0.1",
|
|
57
|
-
"test": "^3.3.0",
|
|
58
|
-
"ts-jest": "^29.4.1",
|
|
59
49
|
"ts-node": "^10.9.2",
|
|
60
|
-
"typescript": "^5.9.
|
|
61
|
-
"typescript-eslint": "^8.
|
|
62
|
-
|
|
63
|
-
"overrides": {
|
|
64
|
-
"eslint-config-standard": {
|
|
65
|
-
"eslint": "^9.33.0"
|
|
66
|
-
}
|
|
50
|
+
"typescript": "^5.9.3",
|
|
51
|
+
"typescript-eslint": "^8.0.0",
|
|
52
|
+
"vitest": "^4.0.18"
|
|
67
53
|
},
|
|
68
54
|
"dependencies": {
|
|
69
|
-
"@leyyo/common": "^1.3.
|
|
55
|
+
"@leyyo/common": "^1.3.21"
|
|
70
56
|
}
|
|
71
57
|
}
|