@budibase/server 2.7.7-alpha.3 → 2.7.7-alpha.5

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/server",
3
3
  "email": "hi@budibase.com",
4
- "version": "2.7.7-alpha.3",
4
+ "version": "2.7.7-alpha.5",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -46,12 +46,12 @@
46
46
  "license": "GPL-3.0",
47
47
  "dependencies": {
48
48
  "@apidevtools/swagger-parser": "10.0.3",
49
- "@budibase/backend-core": "2.7.7-alpha.3",
50
- "@budibase/client": "2.7.7-alpha.3",
51
- "@budibase/pro": "2.7.7-alpha.3",
52
- "@budibase/shared-core": "2.7.7-alpha.3",
53
- "@budibase/string-templates": "2.7.7-alpha.3",
54
- "@budibase/types": "2.7.7-alpha.3",
49
+ "@budibase/backend-core": "2.7.7-alpha.5",
50
+ "@budibase/client": "2.7.7-alpha.5",
51
+ "@budibase/pro": "2.7.7-alpha.5",
52
+ "@budibase/shared-core": "2.7.7-alpha.5",
53
+ "@budibase/string-templates": "2.7.7-alpha.5",
54
+ "@budibase/types": "2.7.7-alpha.5",
55
55
  "@bull-board/api": "3.7.0",
56
56
  "@bull-board/koa": "3.9.4",
57
57
  "@elastic/elasticsearch": "7.10.0",
@@ -97,7 +97,7 @@
97
97
  "koa2-ratelimit": "1.1.1",
98
98
  "lodash": "4.17.21",
99
99
  "memorystream": "0.3.1",
100
- "mongodb": "4.9",
100
+ "mongodb": "5.6",
101
101
  "mssql": "6.2.3",
102
102
  "mysql2": "2.3.3",
103
103
  "node-fetch": "2.6.7",
@@ -195,5 +195,5 @@
195
195
  }
196
196
  }
197
197
  },
198
- "gitHead": "4066481ab4d8e674be19bed0517878f7f9c276f9"
198
+ "gitHead": "3864187987faae18d05f7a056b7d152c651ca288"
199
199
  }
@@ -103,6 +103,22 @@ async function buildSchemaHelper(datasource: Datasource) {
103
103
  return { tables: connector.tables, error }
104
104
  }
105
105
 
106
+ async function buildFilteredSchema(datasource: Datasource, filter?: string[]) {
107
+ let { tables, error } = await buildSchemaHelper(datasource)
108
+ let finalTables = tables
109
+ if (filter) {
110
+ finalTables = {}
111
+ for (let key in tables) {
112
+ if (
113
+ filter.some((filter: any) => filter.toLowerCase() === key.toLowerCase())
114
+ ) {
115
+ finalTables[key] = tables[key]
116
+ }
117
+ }
118
+ }
119
+ return { tables: finalTables, error }
120
+ }
121
+
106
122
  export async function fetch(ctx: UserCtx) {
107
123
  // Get internal tables
108
124
  const db = context.getAppDB()
@@ -174,43 +190,28 @@ export async function information(
174
190
  }
175
191
  const tableNames = await connector.getTableNames()
176
192
  ctx.body = {
177
- tableNames,
193
+ tableNames: tableNames.sort(),
178
194
  }
179
195
  }
180
196
 
181
197
  export async function buildSchemaFromDb(ctx: UserCtx) {
182
198
  const db = context.getAppDB()
183
- const datasource = await sdk.datasources.get(ctx.params.datasourceId)
184
199
  const tablesFilter = ctx.request.body.tablesFilter
200
+ const datasource = await sdk.datasources.get(ctx.params.datasourceId)
185
201
 
186
- let { tables, error } = await buildSchemaHelper(datasource)
187
- if (tablesFilter) {
188
- if (!datasource.entities) {
189
- datasource.entities = {}
190
- }
191
- for (let key in tables) {
192
- if (
193
- tablesFilter.some(
194
- (filter: any) => filter.toLowerCase() === key.toLowerCase()
195
- )
196
- ) {
197
- datasource.entities[key] = tables[key]
198
- }
199
- }
200
- } else {
201
- datasource.entities = tables
202
- }
202
+ const { tables, error } = await buildFilteredSchema(datasource, tablesFilter)
203
+ datasource.entities = tables
203
204
 
204
205
  setDefaultDisplayColumns(datasource)
205
206
  const dbResp = await db.put(datasource)
206
207
  datasource._rev = dbResp.rev
207
208
  const cleanedDatasource = await sdk.datasources.removeSecretSingle(datasource)
208
209
 
209
- const response: any = { datasource: cleanedDatasource }
210
+ const res: any = { datasource: cleanedDatasource }
210
211
  if (error) {
211
- response.error = error
212
+ res.error = error
212
213
  }
213
- ctx.body = response
214
+ ctx.body = res
214
215
  }
215
216
 
216
217
  /**
@@ -320,6 +321,7 @@ export async function save(
320
321
  const db = context.getAppDB()
321
322
  const plus = ctx.request.body.datasource.plus
322
323
  const fetchSchema = ctx.request.body.fetchSchema
324
+ const tablesFilter = ctx.request.body.tablesFilter
323
325
 
324
326
  const datasource = {
325
327
  _id: generateDatasourceID({ plus }),
@@ -329,7 +331,10 @@ export async function save(
329
331
 
330
332
  let schemaError = null
331
333
  if (fetchSchema) {
332
- const { tables, error } = await buildSchemaHelper(datasource)
334
+ const { tables, error } = await buildFilteredSchema(
335
+ datasource,
336
+ tablesFilter
337
+ )
333
338
  schemaError = error
334
339
  datasource.entities = tables
335
340
  setDefaultDisplayColumns(datasource)
@@ -21,7 +21,7 @@ import { buildExternalTableId, finaliseExternalTables } from "./utils"
21
21
  import { GoogleSpreadsheet, GoogleSpreadsheetRow } from "google-spreadsheet"
22
22
  import fetch from "node-fetch"
23
23
  import { cache, configs, context, HTTPError } from "@budibase/backend-core"
24
- import { dataFilters } from "@budibase/shared-core"
24
+ import { dataFilters, utils } from "@budibase/shared-core"
25
25
  import { GOOGLE_SHEETS_PRIMARY_KEY } from "../constants"
26
26
  import sdk from "../sdk"
27
27
 
@@ -150,7 +150,6 @@ class GoogleSheetsIntegration implements DatasourcePlus {
150
150
 
151
151
  async testConnection(): Promise<ConnectionInfo> {
152
152
  try {
153
- await setupCreationAuth(this.config)
154
153
  await this.connect()
155
154
  return { connected: true }
156
155
  } catch (e: any) {
@@ -211,6 +210,8 @@ class GoogleSheetsIntegration implements DatasourcePlus {
211
210
 
212
211
  async connect() {
213
212
  try {
213
+ await setupCreationAuth(this.config)
214
+
214
215
  // Initialise oAuth client
215
216
  let googleConfig = await configs.getGoogleDatasourceConfig()
216
217
  if (!googleConfig) {
@@ -273,24 +274,24 @@ class GoogleSheetsIntegration implements DatasourcePlus {
273
274
  }
274
275
 
275
276
  async buildSchema(datasourceId: string, entities: Record<string, Table>) {
276
- // not fully configured yet
277
- if (!this.config.auth) {
278
- return
279
- }
280
277
  await this.connect()
281
278
  const sheets = this.client.sheetsByIndex
282
279
  const tables: Record<string, Table> = {}
283
- for (let sheet of sheets) {
284
- // must fetch rows to determine schema
285
- await sheet.getRows()
286
-
287
- const id = buildExternalTableId(datasourceId, sheet.title)
288
- tables[sheet.title] = this.getTableSchema(
289
- sheet.title,
290
- sheet.headerValues,
291
- id
292
- )
293
- }
280
+ await utils.parallelForeach(
281
+ sheets,
282
+ async sheet => {
283
+ // must fetch rows to determine schema
284
+ await sheet.getRows({ limit: 0, offset: 0 })
285
+
286
+ const id = buildExternalTableId(datasourceId, sheet.title)
287
+ tables[sheet.title] = this.getTableSchema(
288
+ sheet.title,
289
+ sheet.headerValues,
290
+ id
291
+ )
292
+ },
293
+ 10
294
+ )
294
295
  const final = finaliseExternalTables(tables, entities)
295
296
  this.tables = final.tables
296
297
  this.schemaErrors = final.errors
@@ -351,7 +351,7 @@ const SCHEMA: Integration = getSchema()
351
351
 
352
352
  class MongoIntegration implements IntegrationBase {
353
353
  private config: MongoDBConfig
354
- private client: any
354
+ private client: MongoClient
355
355
 
356
356
  constructor(config: MongoDBConfig) {
357
357
  this.config = config
@@ -372,6 +372,8 @@ class MongoIntegration implements IntegrationBase {
372
372
  response.connected = true
373
373
  } catch (e: any) {
374
374
  response.error = e.message as string
375
+ } finally {
376
+ await this.client.close()
375
377
  }
376
378
  return response
377
379
  }
@@ -380,7 +382,7 @@ class MongoIntegration implements IntegrationBase {
380
382
  return this.client.connect()
381
383
  }
382
384
 
383
- createObjectIds(json: any): object {
385
+ createObjectIds(json: any) {
384
386
  const self = this
385
387
  function interpolateObjectIds(json: any) {
386
388
  for (let field of Object.keys(json)) {
@@ -322,7 +322,8 @@ class PostgresIntegration extends Sql implements DatasourcePlus {
322
322
  await this.openConnection()
323
323
  const columnsResponse: { rows: PostgresColumn[] } =
324
324
  await this.client.query(this.COLUMNS_SQL)
325
- return columnsResponse.rows.map(row => row.table_name)
325
+ const names = columnsResponse.rows.map(row => row.table_name)
326
+ return [...new Set(names)]
326
327
  } finally {
327
328
  await this.closeConnection()
328
329
  }
@@ -164,5 +164,6 @@ export function mergeConfigs(update: Datasource, old: Datasource) {
164
164
  delete update.config[key]
165
165
  }
166
166
  }
167
+
167
168
  return update
168
169
  }