@budibase/server 2.4.8-alpha.1 → 2.4.8-alpha.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/jest.config.ts CHANGED
@@ -14,6 +14,7 @@ const baseConfig: Config.InitialProjectOptions = {
14
14
  moduleNameMapper: {
15
15
  "@budibase/backend-core/(.*)": "<rootDir>/../backend-core/$1",
16
16
  "@budibase/backend-core": "<rootDir>/../backend-core/src",
17
+ "@budibase/shared-core": "<rootDir>/../shared-core/src",
17
18
  "@budibase/types": "<rootDir>/../types/src",
18
19
  },
19
20
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/server",
3
3
  "email": "hi@budibase.com",
4
- "version": "2.4.8-alpha.1",
4
+ "version": "2.4.8-alpha.3",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -43,11 +43,12 @@
43
43
  "license": "GPL-3.0",
44
44
  "dependencies": {
45
45
  "@apidevtools/swagger-parser": "10.0.3",
46
- "@budibase/backend-core": "2.4.8-alpha.1",
47
- "@budibase/client": "2.4.8-alpha.1",
48
- "@budibase/pro": "2.4.8-alpha.0",
49
- "@budibase/string-templates": "2.4.8-alpha.1",
50
- "@budibase/types": "2.4.8-alpha.1",
46
+ "@budibase/backend-core": "2.4.8-alpha.3",
47
+ "@budibase/client": "2.4.8-alpha.3",
48
+ "@budibase/pro": "2.4.8-alpha.2",
49
+ "@budibase/shared-core": "2.4.8-alpha.3",
50
+ "@budibase/string-templates": "2.4.8-alpha.3",
51
+ "@budibase/types": "2.4.8-alpha.3",
51
52
  "@bull-board/api": "3.7.0",
52
53
  "@bull-board/koa": "3.9.4",
53
54
  "@elastic/elasticsearch": "7.10.0",
@@ -174,5 +175,5 @@
174
175
  "optionalDependencies": {
175
176
  "oracledb": "5.3.0"
176
177
  },
177
- "gitHead": "e09a5d2aa5fb497cd237b890701687699d84a097"
178
+ "gitHead": "3f7d463051131da3c711f3286a8ae7269c0a233e"
178
179
  }
@@ -11,6 +11,8 @@ import {
11
11
  Row,
12
12
  Table,
13
13
  RelationshipTypes,
14
+ FieldType,
15
+ SortType,
14
16
  } from "@budibase/types"
15
17
  import {
16
18
  breakRowIdField,
@@ -749,8 +751,16 @@ export class ExternalRequest {
749
751
  )
750
752
  //if the sort column is a formula, remove it
751
753
  for (let sortColumn of Object.keys(sort || {})) {
752
- if (table.schema[sortColumn]?.type === "formula") {
753
- delete sort?.[sortColumn]
754
+ if (!sort?.[sortColumn]) {
755
+ continue
756
+ }
757
+ switch (table.schema[sortColumn]?.type) {
758
+ case FieldType.FORMULA:
759
+ delete sort?.[sortColumn]
760
+ break
761
+ case FieldType.NUMBER:
762
+ sort[sortColumn].type = SortType.number
763
+ break
754
764
  }
755
765
  }
756
766
  filters = buildFilters(id, filters || {}, table)
@@ -8,7 +8,6 @@ import {
8
8
  breakRowIdField,
9
9
  } from "../../../integrations/utils"
10
10
  import { ExternalRequest, RunConfig } from "./ExternalRequest"
11
- import { context } from "@budibase/backend-core"
12
11
  import * as exporters from "../view/exporters"
13
12
  import { apiFileReturn } from "../../../utilities/fileSystem"
14
13
  import {
@@ -19,6 +18,7 @@ import {
19
18
  Table,
20
19
  Datasource,
21
20
  IncludeRelationship,
21
+ SortJson,
22
22
  } from "@budibase/types"
23
23
  import sdk from "../../../sdk"
24
24
 
@@ -142,14 +142,14 @@ export async function search(ctx: BBContext) {
142
142
  limit: limit,
143
143
  }
144
144
  }
145
- let sort
145
+ let sort: SortJson | undefined
146
146
  if (params.sort) {
147
147
  const direction =
148
148
  params.sortOrder === "descending"
149
149
  ? SortDirection.DESCENDING
150
150
  : SortDirection.ASCENDING
151
151
  sort = {
152
- [params.sort]: direction,
152
+ [params.sort]: { direction },
153
153
  }
154
154
  }
155
155
  try {
@@ -317,7 +317,8 @@ class InternalBuilder {
317
317
  const table = json.meta?.table
318
318
  if (sort) {
319
319
  for (let [key, value] of Object.entries(sort)) {
320
- const direction = value === SortDirection.ASCENDING ? "asc" : "desc"
320
+ const direction =
321
+ value.direction === SortDirection.ASCENDING ? "asc" : "desc"
321
322
  query = query.orderBy(`${table?.name}.${key}`, direction)
322
323
  }
323
324
  } else if (this.client === SqlClient.MS_SQL && paginate?.limit) {
@@ -2,8 +2,11 @@ import {
2
2
  DatasourceFieldType,
3
3
  DatasourcePlus,
4
4
  Integration,
5
+ PaginationJson,
5
6
  QueryJson,
6
7
  QueryType,
8
+ SearchFilters,
9
+ SortJson,
7
10
  Table,
8
11
  TableSchema,
9
12
  } from "@budibase/types"
@@ -13,6 +16,7 @@ import { DataSourceOperation, FieldTypes } from "../constants"
13
16
  import { GoogleSpreadsheet } from "google-spreadsheet"
14
17
  import fetch from "node-fetch"
15
18
  import { configs, HTTPError } from "@budibase/backend-core"
19
+ import { dataFilters } from "@budibase/shared-core"
16
20
 
17
21
  interface GoogleSheetsConfig {
18
22
  spreadsheetId: string
@@ -237,7 +241,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
237
241
  const handlers = {
238
242
  [DataSourceOperation.CREATE]: () =>
239
243
  this.create({ sheet, row: json.body }),
240
- [DataSourceOperation.READ]: () => this.read({ sheet }),
244
+ [DataSourceOperation.READ]: () => this.read({ ...json, sheet }),
241
245
  [DataSourceOperation.UPDATE]: () =>
242
246
  this.update({
243
247
  // exclude the header row and zero index
@@ -345,18 +349,40 @@ class GoogleSheetsIntegration implements DatasourcePlus {
345
349
  }
346
350
  }
347
351
 
348
- async read(query: { sheet: string }) {
352
+ async read(query: {
353
+ sheet: string
354
+ filters?: SearchFilters
355
+ sort?: SortJson
356
+ paginate?: PaginationJson
357
+ }) {
349
358
  try {
350
359
  await this.connect()
351
360
  const sheet = this.client.sheetsByTitle[query.sheet]
352
361
  const rows = await sheet.getRows()
362
+ const filtered = dataFilters.runLuceneQuery(rows, query.filters)
353
363
  const headerValues = sheet.headerValues
354
- const response = []
355
- for (let row of rows) {
364
+ let response = []
365
+ for (let row of filtered) {
356
366
  response.push(
357
367
  this.buildRowObject(headerValues, row._rawData, row._rowNumber)
358
368
  )
359
369
  }
370
+
371
+ if (query.sort) {
372
+ if (Object.keys(query.sort).length !== 1) {
373
+ console.warn("Googlesheets does not support multiple sorting", {
374
+ sortInfo: query.sort,
375
+ })
376
+ }
377
+ const [sortField, sortInfo] = Object.entries(query.sort)[0]
378
+ response = dataFilters.luceneSort(
379
+ response,
380
+ sortField,
381
+ sortInfo.direction,
382
+ sortInfo.type
383
+ )
384
+ }
385
+
360
386
  return response
361
387
  } catch (err) {
362
388
  console.error("Error reading from google sheets", err)
package/tsconfig.json CHANGED
@@ -9,6 +9,7 @@
9
9
  "@budibase/types": ["../types/src"],
10
10
  "@budibase/backend-core": ["../backend-core/src"],
11
11
  "@budibase/backend-core/*": ["../backend-core/*"],
12
+ "@budibase/shared-core": ["../shared-core/src"],
12
13
  "@budibase/pro": ["../../../budibase-pro/packages/pro/src"]
13
14
  }
14
15
  },
@@ -19,15 +20,9 @@
19
20
  "references": [
20
21
  { "path": "../types" },
21
22
  { "path": "../backend-core" },
23
+ { "path": "../shared-core" },
22
24
  { "path": "../../../budibase-pro/packages/pro" }
23
25
  ],
24
- "include": [
25
- "src/**/*",
26
- "specs",
27
- "package.json"
28
- ],
29
- "exclude": [
30
- "node_modules",
31
- "dist"
32
- ]
33
- }
26
+ "include": ["src/**/*", "specs", "package.json"],
27
+ "exclude": ["node_modules", "dist"]
28
+ }