@budibase/frontend-core 3.5.1 → 3.5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@budibase/frontend-core",
3
- "version": "3.5.1",
3
+ "version": "3.5.3",
4
4
  "description": "Budibase frontend core libraries used in builder and client",
5
5
  "author": "Budibase",
6
6
  "license": "MPL-2.0",
@@ -17,5 +17,5 @@
17
17
  "shortid": "2.2.15",
18
18
  "socket.io-client": "^4.7.5"
19
19
  },
20
- "gitHead": "e64de415ddc908b22282579f37fcead199ab1b78"
20
+ "gitHead": "0f586f33c25c04b35a7dc72b7217fdbaa3e843c0"
21
21
  }
package/src/api/ai.ts CHANGED
@@ -1,7 +1,9 @@
1
+ import { GenerateJsRequest, GenerateJsResponse } from "@budibase/types"
1
2
  import { BaseAPIClient } from "./types"
2
3
 
3
4
  export interface AIEndpoints {
4
5
  generateCronExpression: (prompt: string) => Promise<{ message: string }>
6
+ generateJs: (req: GenerateJsRequest) => Promise<GenerateJsResponse>
5
7
  }
6
8
 
7
9
  export const buildAIEndpoints = (API: BaseAPIClient): AIEndpoints => ({
@@ -14,4 +16,11 @@ export const buildAIEndpoints = (API: BaseAPIClient): AIEndpoints => ({
14
16
  body: { prompt },
15
17
  })
16
18
  },
19
+
20
+ generateJs: async req => {
21
+ return await API.post({
22
+ url: "/api/ai/js",
23
+ body: req,
24
+ })
25
+ },
17
26
  })
@@ -8,6 +8,7 @@ import {
8
8
  Row,
9
9
  SearchFilters,
10
10
  SortOrder,
11
+ SortType,
11
12
  TableSchema,
12
13
  } from "@budibase/types"
13
14
  import { APIClient } from "../api/types"
@@ -71,6 +72,8 @@ export default abstract class BaseDataFetch<
71
72
  options: DataFetchOptions<TQuery> & {
72
73
  datasource: TDatasource
73
74
 
75
+ sortType: SortType | null
76
+
74
77
  // Client side feature customisation
75
78
  clientSideSearching: boolean
76
79
  clientSideSorting: boolean
@@ -103,6 +106,7 @@ export default abstract class BaseDataFetch<
103
106
  // Sorting config
104
107
  sortColumn: null,
105
108
  sortOrder: SortOrder.ASCENDING,
109
+ sortType: null,
106
110
 
107
111
  // Pagination config
108
112
  paginate: true,
@@ -223,12 +227,31 @@ export default abstract class BaseDataFetch<
223
227
  this.options.sortColumn = this.getDefaultSortColumn(definition, schema)
224
228
  }
225
229
 
226
- // If no sort order, default to ascending
227
- if (!this.options.sortOrder) {
230
+ // If we don't have a sort column specified then just ensure we don't set
231
+ // any sorting params
232
+ if (!this.options.sortColumn) {
228
233
  this.options.sortOrder = SortOrder.ASCENDING
234
+ this.options.sortType = null
229
235
  } else {
230
- // Ensure sortOrder matches the enum
231
- this.options.sortOrder = this.options.sortOrder.toLowerCase() as SortOrder
236
+ // Otherwise determine what sort type to use base on sort column
237
+ this.options.sortType = SortType.STRING
238
+ const fieldSchema = schema?.[this.options.sortColumn]
239
+ if (
240
+ fieldSchema?.type === FieldType.NUMBER ||
241
+ fieldSchema?.type === FieldType.BIGINT ||
242
+ ("calculationType" in fieldSchema && fieldSchema?.calculationType)
243
+ ) {
244
+ this.options.sortType = SortType.NUMBER
245
+ }
246
+
247
+ // If no sort order, default to ascending
248
+ if (!this.options.sortOrder) {
249
+ this.options.sortOrder = SortOrder.ASCENDING
250
+ } else {
251
+ // Ensure sortOrder matches the enum
252
+ this.options.sortOrder =
253
+ this.options.sortOrder.toLowerCase() as SortOrder
254
+ }
232
255
  }
233
256
 
234
257
  // Build the query
@@ -271,6 +294,7 @@ export default abstract class BaseDataFetch<
271
294
  const {
272
295
  sortColumn,
273
296
  sortOrder,
297
+ sortType,
274
298
  limit,
275
299
  clientSideSearching,
276
300
  clientSideSorting,
@@ -287,8 +311,8 @@ export default abstract class BaseDataFetch<
287
311
  }
288
312
 
289
313
  // If we don't support sorting, do a client-side sort
290
- if (!this.features.supportsSort && clientSideSorting && sortColumn) {
291
- rows = sort(rows, sortColumn, sortOrder)
314
+ if (!this.features.supportsSort && clientSideSorting && sortType) {
315
+ rows = sort(rows, sortColumn as any, sortOrder, sortType)
292
316
  }
293
317
 
294
318
  // If we don't support pagination, do a client-side limit
@@ -29,7 +29,8 @@ export default class TableFetch extends BaseDataFetch<TableDatasource, Table> {
29
29
  }
30
30
 
31
31
  async getData() {
32
- const { datasource, limit, sortColumn, sortOrder, paginate } = this.options
32
+ const { datasource, limit, sortColumn, sortOrder, sortType, paginate } =
33
+ this.options
33
34
  const { tableId } = datasource
34
35
  const { cursor, query } = get(this.store)
35
36
 
@@ -40,6 +41,7 @@ export default class TableFetch extends BaseDataFetch<TableDatasource, Table> {
40
41
  limit,
41
42
  sort: sortColumn,
42
43
  sortOrder: sortOrder ?? SortOrder.ASCENDING,
44
+ sortType,
43
45
  paginate,
44
46
  bookmark: cursor,
45
47
  })
@@ -1,5 +1,4 @@
1
1
  import {
2
- SearchViewRowRequest,
3
2
  SortOrder,
4
3
  ViewDatasource,
5
4
  ViewV2Enriched,
@@ -41,7 +40,8 @@ export default class ViewV2Fetch extends BaseDataFetch<
41
40
  }
42
41
 
43
42
  async getData() {
44
- const { datasource, limit, sortColumn, sortOrder, paginate } = this.options
43
+ const { datasource, limit, sortColumn, sortOrder, sortType, paginate } =
44
+ this.options
45
45
  const { cursor, query, definition } = get(this.store)
46
46
 
47
47
  // If this is a calculation view and we have no calculations, return nothing
@@ -68,13 +68,14 @@ export default class ViewV2Fetch extends BaseDataFetch<
68
68
  }
69
69
 
70
70
  try {
71
- const request: SearchViewRowRequest = {
71
+ const request = {
72
72
  query,
73
73
  paginate,
74
74
  limit,
75
75
  bookmark: cursor,
76
76
  sort: sortColumn,
77
77
  sortOrder: sortOrder,
78
+ sortType,
78
79
  }
79
80
  if (paginate) {
80
81
  const res = await this.API.viewV2.fetch(datasource.id, {