@budibase/shared-core 2.8.32-alpha.5 → 2.8.32-alpha.7

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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. 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.8.32-alpha.5",
3
+ "version": "2.8.32-alpha.7",
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.8.32-alpha.5"
23
+ "@budibase/types": "2.8.32-alpha.7"
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": "6ed56e07e6b867cfc7b7a13f153659a5b4395ca8"
30
+ "gitHead": "abbacc22865a1a0bd25ddf57f555299e1cd3473d"
31
31
  }
package/src/filters.ts CHANGED
@@ -1,4 +1,12 @@
1
- import { Datasource, FieldType, SortDirection, SortType } from "@budibase/types"
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 QueryFields)[]
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: 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: Filter[]) => {
172
- let query: 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[externalType]?.min || Number.MIN_SAFE_INTEGER
184
+ SqlNumberTypeRangeMap[
185
+ externalType as keyof typeof SqlNumberTypeRangeMap
186
+ ]?.min || Number.MIN_SAFE_INTEGER
231
187
  const maxint =
232
- SqlNumberTypeRangeMap[externalType]?.max || Number.MAX_SAFE_INTEGER
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?: 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: QueryFieldsType,
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?: Query) => {
417
+ export const hasFilters = (query?: SearchQuery) => {
460
418
  if (!query) {
461
419
  return false
462
420
  }