@budibase/server 2.4.38 → 2.4.40

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.4.38",
4
+ "version": "2.4.40",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -43,12 +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.38",
47
- "@budibase/client": "^2.4.38",
48
- "@budibase/pro": "2.4.37",
49
- "@budibase/shared-core": "^2.4.38",
50
- "@budibase/string-templates": "^2.4.38",
51
- "@budibase/types": "^2.4.38",
46
+ "@budibase/backend-core": "^2.4.40",
47
+ "@budibase/client": "^2.4.40",
48
+ "@budibase/pro": "2.4.39",
49
+ "@budibase/shared-core": "^2.4.40",
50
+ "@budibase/string-templates": "^2.4.40",
51
+ "@budibase/types": "^2.4.40",
52
52
  "@bull-board/api": "3.7.0",
53
53
  "@bull-board/koa": "3.9.4",
54
54
  "@elastic/elasticsearch": "7.10.0",
@@ -175,5 +175,5 @@
175
175
  "optionalDependencies": {
176
176
  "oracledb": "5.3.0"
177
177
  },
178
- "gitHead": "39c732f4384c9a3d6095803b23443fcd8857329f"
178
+ "gitHead": "8d1f12dfbecf020366571d81c5dc8db9f968afc7"
179
179
  }
@@ -84,9 +84,8 @@ export async function buildSchemaFromDb(ctx: UserCtx) {
84
84
  setDefaultDisplayColumns(datasource)
85
85
  const dbResp = await db.put(datasource)
86
86
  datasource._rev = dbResp.rev
87
- const cleanedDatasource = await sdk.datasources.removeSecretSingle(datasource)
88
87
 
89
- const response: any = { datasource: cleanedDatasource }
88
+ const response: any = { datasource }
90
89
  if (error) {
91
90
  response.error = error
92
91
  }
@@ -12,7 +12,7 @@ import * as exporters from "../view/exporters"
12
12
  import { apiFileReturn } from "../../../utilities/fileSystem"
13
13
  import {
14
14
  Operation,
15
- UserCtx,
15
+ BBContext,
16
16
  Row,
17
17
  PaginationJson,
18
18
  Table,
@@ -21,7 +21,6 @@ import {
21
21
  SortJson,
22
22
  } from "@budibase/types"
23
23
  import sdk from "../../../sdk"
24
- import * as utils from "./utils"
25
24
 
26
25
  const { cleanExportRows } = require("./utils")
27
26
 
@@ -50,19 +49,12 @@ export async function handleRequest(
50
49
  )
51
50
  }
52
51
 
53
- export async function patch(ctx: UserCtx) {
52
+ export async function patch(ctx: BBContext) {
54
53
  const inputs = ctx.request.body
55
54
  const tableId = ctx.params.tableId
56
55
  const id = inputs._id
57
56
  // don't save the ID to db
58
57
  delete inputs._id
59
- const validateResult = await utils.validate({
60
- row: inputs,
61
- tableId,
62
- })
63
- if (!validateResult.valid) {
64
- throw { validation: validateResult.errors }
65
- }
66
58
  return handleRequest(Operation.UPDATE, tableId, {
67
59
  id: breakRowIdField(id),
68
60
  row: inputs,
@@ -70,23 +62,16 @@ export async function patch(ctx: UserCtx) {
70
62
  })
71
63
  }
72
64
 
73
- export async function save(ctx: UserCtx) {
65
+ export async function save(ctx: BBContext) {
74
66
  const inputs = ctx.request.body
75
67
  const tableId = ctx.params.tableId
76
- const validateResult = await utils.validate({
77
- row: inputs,
78
- tableId,
79
- })
80
- if (!validateResult.valid) {
81
- throw { validation: validateResult.errors }
82
- }
83
68
  return handleRequest(Operation.CREATE, tableId, {
84
69
  row: inputs,
85
70
  includeSqlRelationships: IncludeRelationship.EXCLUDE,
86
71
  })
87
72
  }
88
73
 
89
- export async function fetchView(ctx: UserCtx) {
74
+ export async function fetchView(ctx: BBContext) {
90
75
  // there are no views in external datasources, shouldn't ever be called
91
76
  // for now just fetch
92
77
  const split = ctx.params.viewName.split("all_")
@@ -94,14 +79,14 @@ export async function fetchView(ctx: UserCtx) {
94
79
  return fetch(ctx)
95
80
  }
96
81
 
97
- export async function fetch(ctx: UserCtx) {
82
+ export async function fetch(ctx: BBContext) {
98
83
  const tableId = ctx.params.tableId
99
84
  return handleRequest(Operation.READ, tableId, {
100
85
  includeSqlRelationships: IncludeRelationship.INCLUDE,
101
86
  })
102
87
  }
103
88
 
104
- export async function find(ctx: UserCtx) {
89
+ export async function find(ctx: BBContext) {
105
90
  const id = ctx.params.rowId
106
91
  const tableId = ctx.params.tableId
107
92
  const response = (await handleRequest(Operation.READ, tableId, {
@@ -111,7 +96,7 @@ export async function find(ctx: UserCtx) {
111
96
  return response ? response[0] : response
112
97
  }
113
98
 
114
- export async function destroy(ctx: UserCtx) {
99
+ export async function destroy(ctx: BBContext) {
115
100
  const tableId = ctx.params.tableId
116
101
  const id = ctx.request.body._id
117
102
  const { row } = (await handleRequest(Operation.DELETE, tableId, {
@@ -121,7 +106,7 @@ export async function destroy(ctx: UserCtx) {
121
106
  return { response: { ok: true }, row }
122
107
  }
123
108
 
124
- export async function bulkDestroy(ctx: UserCtx) {
109
+ export async function bulkDestroy(ctx: BBContext) {
125
110
  const { rows } = ctx.request.body
126
111
  const tableId = ctx.params.tableId
127
112
  let promises: Promise<Row[] | { row: Row; table: Table }>[] = []
@@ -137,7 +122,7 @@ export async function bulkDestroy(ctx: UserCtx) {
137
122
  return { response: { ok: true }, rows: responses.map(resp => resp.row) }
138
123
  }
139
124
 
140
- export async function search(ctx: UserCtx) {
125
+ export async function search(ctx: BBContext) {
141
126
  const tableId = ctx.params.tableId
142
127
  const { paginate, query, ...params } = ctx.request.body
143
128
  let { bookmark, limit } = params
@@ -200,7 +185,12 @@ export async function search(ctx: UserCtx) {
200
185
  }
201
186
  }
202
187
 
203
- export async function exportRows(ctx: UserCtx) {
188
+ export async function validate(ctx: BBContext) {
189
+ // can't validate external right now - maybe in future
190
+ return { valid: true }
191
+ }
192
+
193
+ export async function exportRows(ctx: BBContext) {
204
194
  const { datasourceId, tableName } = breakExternalTableId(ctx.params.tableId)
205
195
  const format = ctx.query.format
206
196
  const { columns } = ctx.request.body
@@ -254,7 +244,7 @@ export async function exportRows(ctx: UserCtx) {
254
244
  return apiFileReturn(exporter(headers, exportRows))
255
245
  }
256
246
 
257
- export async function fetchEnrichedRow(ctx: UserCtx) {
247
+ export async function fetchEnrichedRow(ctx: BBContext) {
258
248
  const id = ctx.params.rowId
259
249
  const tableId = ctx.params.tableId
260
250
  const { datasourceId, tableName } = breakExternalTableId(tableId)
@@ -2,8 +2,6 @@ import { quotas } from "@budibase/pro"
2
2
  import * as internal from "./internal"
3
3
  import * as external from "./external"
4
4
  import { isExternalTable } from "../../../integrations/utils"
5
- import { Ctx } from "@budibase/types"
6
- import * as utils from "./utils"
7
5
 
8
6
  function pickApi(tableId: any) {
9
7
  if (isExternalTable(tableId)) {
@@ -131,12 +129,9 @@ export async function search(ctx: any) {
131
129
  })
132
130
  }
133
131
 
134
- export async function validate(ctx: Ctx) {
132
+ export async function validate(ctx: any) {
135
133
  const tableId = getTableId(ctx)
136
- ctx.body = await utils.validate({
137
- row: ctx.request.body,
138
- tableId,
139
- })
134
+ ctx.body = await pickApi(tableId).validate(ctx)
140
135
  }
141
136
 
142
137
  export async function fetchEnrichedRow(ctx: any) {
@@ -387,6 +387,13 @@ export async function search(ctx: Ctx) {
387
387
  return response
388
388
  }
389
389
 
390
+ export async function validate(ctx: Ctx) {
391
+ return utils.validate({
392
+ tableId: ctx.params.tableId,
393
+ row: ctx.request.body,
394
+ })
395
+ }
396
+
390
397
  export async function exportRows(ctx: Ctx) {
391
398
  const db = context.getAppDB()
392
399
  const table = await db.get(ctx.params.tableId)
@@ -4,11 +4,11 @@ import { FieldTypes } from "../../../constants"
4
4
  import { context } from "@budibase/backend-core"
5
5
  import { makeExternalQuery } from "../../../integrations/base/query"
6
6
  import { Row, Table } from "@budibase/types"
7
+ const validateJs = require("validate.js")
8
+ const { cloneDeep } = require("lodash/fp")
7
9
  import { Format } from "../view/exporters"
8
10
  import { Ctx } from "@budibase/types"
9
11
  import sdk from "../../../sdk"
10
- const validateJs = require("validate.js")
11
- const { cloneDeep } = require("lodash/fp")
12
12
 
13
13
  validateJs.extend(validateJs.validators.datetime, {
14
14
  parse: function (value: string) {
@@ -56,7 +56,8 @@ export async function validate({
56
56
  }) {
57
57
  let fetchedTable: Table
58
58
  if (!table) {
59
- fetchedTable = await sdk.tables.getTable(tableId)
59
+ const db = context.getAppDB()
60
+ fetchedTable = await db.get(tableId)
60
61
  } else {
61
62
  fetchedTable = table
62
63
  }
@@ -7,7 +7,6 @@ import {
7
7
  generateJunctionTableName,
8
8
  foreignKeyStructure,
9
9
  hasTypeChanged,
10
- setStaticSchemas,
11
10
  } from "./utils"
12
11
  import { FieldTypes } from "../../../constants"
13
12
  import { makeExternalQuery } from "../../../integrations/base/query"
@@ -21,7 +20,7 @@ import {
21
20
  Operation,
22
21
  RenameColumn,
23
22
  FieldSchema,
24
- UserCtx,
23
+ BBContext,
25
24
  TableRequest,
26
25
  RelationshipTypes,
27
26
  } from "@budibase/types"
@@ -195,20 +194,20 @@ function isRelationshipSetup(column: FieldSchema) {
195
194
  return column.foreignKey || column.through
196
195
  }
197
196
 
198
- export async function save(ctx: UserCtx) {
199
- const inputs: TableRequest = ctx.request.body
200
- const renamed = inputs?._rename
197
+ export async function save(ctx: BBContext) {
198
+ const table: TableRequest = ctx.request.body
199
+ const renamed = table?._rename
201
200
  // can't do this right now
202
- delete inputs.rows
201
+ delete table.rows
203
202
  const datasourceId = getDatasourceId(ctx.request.body)!
204
203
  // table doesn't exist already, note that it is created
205
- if (!inputs._id) {
206
- inputs.created = true
204
+ if (!table._id) {
205
+ table.created = true
207
206
  }
208
207
  let tableToSave: TableRequest = {
209
208
  type: "table",
210
- _id: buildExternalTableId(datasourceId, inputs.name),
211
- ...inputs,
209
+ _id: buildExternalTableId(datasourceId, table.name),
210
+ ...table,
212
211
  }
213
212
 
214
213
  let oldTable
@@ -225,10 +224,6 @@ export async function save(ctx: UserCtx) {
225
224
  if (!datasource.entities) {
226
225
  datasource.entities = {}
227
226
  }
228
-
229
- // GSheets is a specific case - only ever has a static primary key
230
- tableToSave = setStaticSchemas(datasource, tableToSave)
231
-
232
227
  const oldTables = cloneDeep(datasource.entities)
233
228
  const tables: Record<string, Table> = datasource.entities
234
229
 
@@ -251,7 +246,7 @@ export async function save(ctx: UserCtx) {
251
246
  const junctionTable = generateManyLinkSchema(
252
247
  datasource,
253
248
  schema,
254
- tableToSave,
249
+ table,
255
250
  relatedTable
256
251
  )
257
252
  if (tables[junctionTable.name]) {
@@ -261,12 +256,10 @@ export async function save(ctx: UserCtx) {
261
256
  extraTablesToUpdate.push(junctionTable)
262
257
  } else {
263
258
  const fkTable =
264
- relationType === RelationshipTypes.ONE_TO_MANY
265
- ? tableToSave
266
- : relatedTable
259
+ relationType === RelationshipTypes.ONE_TO_MANY ? table : relatedTable
267
260
  const foreignKey = generateLinkSchema(
268
261
  schema,
269
- tableToSave,
262
+ table,
270
263
  relatedTable,
271
264
  relationType
272
265
  )
@@ -278,11 +271,11 @@ export async function save(ctx: UserCtx) {
278
271
  fkTable.constrained.push(foreignKey)
279
272
  }
280
273
  // foreign key is in other table, need to save it to external
281
- if (fkTable._id !== tableToSave._id) {
274
+ if (fkTable._id !== table._id) {
282
275
  extraTablesToUpdate.push(fkTable)
283
276
  }
284
277
  }
285
- generateRelatedSchema(schema, relatedTable, tableToSave, relatedColumnName)
278
+ generateRelatedSchema(schema, relatedTable, table, relatedColumnName)
286
279
  schema.main = true
287
280
  }
288
281
 
@@ -320,7 +313,7 @@ export async function save(ctx: UserCtx) {
320
313
  return tableToSave
321
314
  }
322
315
 
323
- export async function destroy(ctx: UserCtx) {
316
+ export async function destroy(ctx: BBContext) {
324
317
  const tableToDelete: TableRequest = await sdk.tables.getTable(
325
318
  ctx.params.tableId
326
319
  )
@@ -346,7 +339,7 @@ export async function destroy(ctx: UserCtx) {
346
339
  return tableToDelete
347
340
  }
348
341
 
349
- export async function bulkImport(ctx: UserCtx) {
342
+ export async function bulkImport(ctx: BBContext) {
350
343
  const table = await sdk.tables.getTable(ctx.params.tableId)
351
344
  const { rows }: { rows: unknown } = ctx.request.body
352
345
  const schema: unknown = table.schema
@@ -355,7 +348,7 @@ export async function bulkImport(ctx: UserCtx) {
355
348
  ctx.throw(400, "Provided data import information is invalid.")
356
349
  }
357
350
 
358
- const parsedRows = parse(rows, schema)
351
+ const parsedRows = await parse(rows, schema)
359
352
  await handleRequest(Operation.BULK_CREATE, table._id!, {
360
353
  rows: parsedRows,
361
354
  })
@@ -8,7 +8,7 @@ import {
8
8
  import { isExternalTable, isSQL } from "../../../integrations/utils"
9
9
  import { getDatasourceParams } from "../../../db/utils"
10
10
  import { context, events } from "@budibase/backend-core"
11
- import { Table, UserCtx } from "@budibase/types"
11
+ import { Table, BBContext } from "@budibase/types"
12
12
  import sdk from "../../../sdk"
13
13
  import csv from "csvtojson"
14
14
 
@@ -25,7 +25,7 @@ function pickApi({ tableId, table }: { tableId?: string; table?: Table }) {
25
25
  }
26
26
 
27
27
  // covers both internal and external
28
- export async function fetch(ctx: UserCtx) {
28
+ export async function fetch(ctx: BBContext) {
29
29
  const db = context.getAppDB()
30
30
 
31
31
  const internal = await sdk.tables.getAllInternalTables()
@@ -53,12 +53,12 @@ export async function fetch(ctx: UserCtx) {
53
53
  ctx.body = [...internal, ...external]
54
54
  }
55
55
 
56
- export async function find(ctx: UserCtx) {
56
+ export async function find(ctx: BBContext) {
57
57
  const tableId = ctx.params.tableId
58
58
  ctx.body = await sdk.tables.getTable(tableId)
59
59
  }
60
60
 
61
- export async function save(ctx: UserCtx) {
61
+ export async function save(ctx: BBContext) {
62
62
  const appId = ctx.appId
63
63
  const table = ctx.request.body
64
64
  const isImport = table.rows
@@ -79,7 +79,7 @@ export async function save(ctx: UserCtx) {
79
79
  ctx.body = savedTable
80
80
  }
81
81
 
82
- export async function destroy(ctx: UserCtx) {
82
+ export async function destroy(ctx: BBContext) {
83
83
  const appId = ctx.appId
84
84
  const tableId = ctx.params.tableId
85
85
  const deletedTable = await pickApi({ tableId }).destroy(ctx)
@@ -91,7 +91,7 @@ export async function destroy(ctx: UserCtx) {
91
91
  ctx.body = { message: `Table ${tableId} deleted.` }
92
92
  }
93
93
 
94
- export async function bulkImport(ctx: UserCtx) {
94
+ export async function bulkImport(ctx: BBContext) {
95
95
  const tableId = ctx.params.tableId
96
96
  await pickApi({ tableId }).bulkImport(ctx)
97
97
  // right now we don't trigger anything for bulk import because it
@@ -101,7 +101,7 @@ export async function bulkImport(ctx: UserCtx) {
101
101
  ctx.body = { message: `Bulk rows created.` }
102
102
  }
103
103
 
104
- export async function csvToJson(ctx: UserCtx) {
104
+ export async function csvToJson(ctx: BBContext) {
105
105
  const { csvString } = ctx.request.body
106
106
 
107
107
  const result = await csv().fromString(csvString)
@@ -110,7 +110,7 @@ export async function csvToJson(ctx: UserCtx) {
110
110
  ctx.body = result
111
111
  }
112
112
 
113
- export async function validateNewTableImport(ctx: UserCtx) {
113
+ export async function validateNewTableImport(ctx: BBContext) {
114
114
  const { rows, schema }: { rows: unknown; schema: unknown } = ctx.request.body
115
115
 
116
116
  if (isRows(rows) && isSchema(schema)) {
@@ -121,7 +121,7 @@ export async function validateNewTableImport(ctx: UserCtx) {
121
121
  }
122
122
  }
123
123
 
124
- export async function validateExistingTableImport(ctx: UserCtx) {
124
+ export async function validateExistingTableImport(ctx: BBContext) {
125
125
  const { rows, tableId }: { rows: unknown; tableId: unknown } =
126
126
  ctx.request.body
127
127
 
@@ -1,11 +1,7 @@
1
1
  import { parse, isSchema, isRows } from "../../../utilities/schema"
2
2
  import { getRowParams, generateRowID, InternalTables } from "../../../db/utils"
3
3
  import { isEqual } from "lodash"
4
- import {
5
- AutoFieldSubTypes,
6
- FieldTypes,
7
- GOOGLE_SHEETS_PRIMARY_KEY,
8
- } from "../../../constants"
4
+ import { AutoFieldSubTypes, FieldTypes } from "../../../constants"
9
5
  import {
10
6
  inputProcessing,
11
7
  cleanupAttachments,
@@ -20,7 +16,7 @@ import viewTemplate from "../view/viewBuilder"
20
16
  import { cloneDeep } from "lodash/fp"
21
17
  import { quotas } from "@budibase/pro"
22
18
  import { events, context } from "@budibase/backend-core"
23
- import { Database, Datasource, SourceName, Table } from "@budibase/types"
19
+ import { Database } from "@budibase/types"
24
20
 
25
21
  export async function clearColumns(table: any, columnNames: any) {
26
22
  const db: Database = context.getAppDB()
@@ -396,17 +392,5 @@ export function hasTypeChanged(table: any, oldTable: any) {
396
392
  return false
397
393
  }
398
394
 
399
- // used for external tables, some of them will have static schemas that need
400
- // to be hard set
401
- export function setStaticSchemas(datasource: Datasource, table: Table) {
402
- // GSheets is a specific case - only ever has a static primary key
403
- if (table && datasource.source === SourceName.GOOGLE_SHEETS) {
404
- table.primary = [GOOGLE_SHEETS_PRIMARY_KEY]
405
- // if there is an id column, remove it, should never exist in GSheets
406
- delete table.schema?.id
407
- }
408
- return table
409
- }
410
-
411
395
  const _TableSaveFunctions = TableSaveFunctions
412
396
  export { _TableSaveFunctions as TableSaveFunctions }
@@ -180,4 +180,3 @@ export enum AutomationErrors {
180
180
  // pass through the list from the auth/core lib
181
181
  export const ObjectStoreBuckets = objectStore.ObjectStoreBuckets
182
182
  export const MAX_AUTOMATION_RECURRING_ERRORS = 5
183
- export const GOOGLE_SHEETS_PRIMARY_KEY = "rowNumber"