@budibase/shared-core 2.9.7 → 2.9.8-alpha.1
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/package.json +3 -3
- package/src/filters.ts +22 -64
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@budibase/shared-core",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.8-alpha.1",
|
|
4
4
|
"description": "Shared data utils",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"check:types": "tsc -p tsconfig.json --noEmit --paths null"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@budibase/types": "2.9.
|
|
23
|
+
"@budibase/types": "2.9.8-alpha.1"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"concurrently": "^7.6.0",
|
|
27
27
|
"rimraf": "3.0.2",
|
|
28
28
|
"typescript": "4.7.3"
|
|
29
29
|
},
|
|
30
|
-
"gitHead": "
|
|
30
|
+
"gitHead": "883fde170093315cfb1cca4f665b48a0f469a234"
|
|
31
31
|
}
|
package/src/filters.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Datasource,
|
|
3
|
+
FieldType,
|
|
4
|
+
SearchFilter,
|
|
5
|
+
SearchQuery,
|
|
6
|
+
SearchQueryFields,
|
|
7
|
+
SortDirection,
|
|
8
|
+
SortType,
|
|
9
|
+
} from "@budibase/types"
|
|
2
10
|
import { OperatorOptions, SqlNumberTypeRangeMap } from "./constants"
|
|
3
11
|
import { deepGet } from "./helpers"
|
|
4
12
|
|
|
@@ -73,13 +81,13 @@ export const NoEmptyFilterStrings = [
|
|
|
73
81
|
OperatorOptions.NotEquals.value,
|
|
74
82
|
OperatorOptions.Contains.value,
|
|
75
83
|
OperatorOptions.NotContains.value,
|
|
76
|
-
] as (keyof
|
|
84
|
+
] as (keyof SearchQueryFields)[]
|
|
77
85
|
|
|
78
86
|
/**
|
|
79
87
|
* Removes any fields that contain empty strings that would cause inconsistent
|
|
80
88
|
* behaviour with how backend tables are filtered (no value means no filter).
|
|
81
89
|
*/
|
|
82
|
-
const cleanupQuery = (query:
|
|
90
|
+
const cleanupQuery = (query: SearchQuery) => {
|
|
83
91
|
if (!query) {
|
|
84
92
|
return query
|
|
85
93
|
}
|
|
@@ -110,66 +118,12 @@ const removeKeyNumbering = (key: string) => {
|
|
|
110
118
|
}
|
|
111
119
|
}
|
|
112
120
|
|
|
113
|
-
type Filter = {
|
|
114
|
-
operator: keyof Query
|
|
115
|
-
field: string
|
|
116
|
-
type: any
|
|
117
|
-
value: any
|
|
118
|
-
externalType: keyof typeof SqlNumberTypeRangeMap
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
type Query = QueryFields & QueryConfig
|
|
122
|
-
type QueryFields = {
|
|
123
|
-
string?: {
|
|
124
|
-
[key: string]: string
|
|
125
|
-
}
|
|
126
|
-
fuzzy?: {
|
|
127
|
-
[key: string]: string
|
|
128
|
-
}
|
|
129
|
-
range?: {
|
|
130
|
-
[key: string]: {
|
|
131
|
-
high: number | string
|
|
132
|
-
low: number | string
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
equal?: {
|
|
136
|
-
[key: string]: any
|
|
137
|
-
}
|
|
138
|
-
notEqual?: {
|
|
139
|
-
[key: string]: any
|
|
140
|
-
}
|
|
141
|
-
empty?: {
|
|
142
|
-
[key: string]: any
|
|
143
|
-
}
|
|
144
|
-
notEmpty?: {
|
|
145
|
-
[key: string]: any
|
|
146
|
-
}
|
|
147
|
-
oneOf?: {
|
|
148
|
-
[key: string]: any[]
|
|
149
|
-
}
|
|
150
|
-
contains?: {
|
|
151
|
-
[key: string]: any[]
|
|
152
|
-
}
|
|
153
|
-
notContains?: {
|
|
154
|
-
[key: string]: any[]
|
|
155
|
-
}
|
|
156
|
-
containsAny?: {
|
|
157
|
-
[key: string]: any[]
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
type QueryConfig = {
|
|
162
|
-
allOr?: boolean
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
type QueryFieldsType = keyof QueryFields
|
|
166
|
-
|
|
167
121
|
/**
|
|
168
122
|
* Builds a lucene JSON query from the filter structure generated in the builder
|
|
169
123
|
* @param filter the builder filter structure
|
|
170
124
|
*/
|
|
171
|
-
export const buildLuceneQuery = (filter:
|
|
172
|
-
let query:
|
|
125
|
+
export const buildLuceneQuery = (filter: SearchFilter[]) => {
|
|
126
|
+
let query: SearchQuery = {
|
|
173
127
|
string: {},
|
|
174
128
|
fuzzy: {},
|
|
175
129
|
range: {},
|
|
@@ -227,9 +181,13 @@ export const buildLuceneQuery = (filter: Filter[]) => {
|
|
|
227
181
|
}
|
|
228
182
|
if (operator.startsWith("range") && query.range) {
|
|
229
183
|
const minint =
|
|
230
|
-
SqlNumberTypeRangeMap[
|
|
184
|
+
SqlNumberTypeRangeMap[
|
|
185
|
+
externalType as keyof typeof SqlNumberTypeRangeMap
|
|
186
|
+
]?.min || Number.MIN_SAFE_INTEGER
|
|
231
187
|
const maxint =
|
|
232
|
-
SqlNumberTypeRangeMap[
|
|
188
|
+
SqlNumberTypeRangeMap[
|
|
189
|
+
externalType as keyof typeof SqlNumberTypeRangeMap
|
|
190
|
+
]?.max || Number.MAX_SAFE_INTEGER
|
|
233
191
|
if (!query.range[field]) {
|
|
234
192
|
query.range[field] = {
|
|
235
193
|
low: type === "number" ? minint : "0000-00-00T00:00:00.000Z",
|
|
@@ -275,7 +233,7 @@ export const buildLuceneQuery = (filter: Filter[]) => {
|
|
|
275
233
|
* @param docs the data
|
|
276
234
|
* @param query the JSON lucene query
|
|
277
235
|
*/
|
|
278
|
-
export const runLuceneQuery = (docs: any[], query?:
|
|
236
|
+
export const runLuceneQuery = (docs: any[], query?: SearchQuery) => {
|
|
279
237
|
if (!docs || !Array.isArray(docs)) {
|
|
280
238
|
return []
|
|
281
239
|
}
|
|
@@ -289,7 +247,7 @@ export const runLuceneQuery = (docs: any[], query?: Query) => {
|
|
|
289
247
|
// Iterates over a set of filters and evaluates a fail function against a doc
|
|
290
248
|
const match =
|
|
291
249
|
(
|
|
292
|
-
type:
|
|
250
|
+
type: keyof SearchQueryFields,
|
|
293
251
|
failFn: (docValue: any, testValue: any) => boolean
|
|
294
252
|
) =>
|
|
295
253
|
(doc: any) => {
|
|
@@ -456,7 +414,7 @@ export const luceneLimit = (docs: any[], limit: string) => {
|
|
|
456
414
|
return docs.slice(0, numLimit)
|
|
457
415
|
}
|
|
458
416
|
|
|
459
|
-
export const hasFilters = (query?:
|
|
417
|
+
export const hasFilters = (query?: SearchQuery) => {
|
|
460
418
|
if (!query) {
|
|
461
419
|
return false
|
|
462
420
|
}
|