@budibase/server 2.4.42-alpha.7 → 2.4.42-alpha.8
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/builder/assets/{index.3cb1022d.css → index.7f9a008b.css} +1 -1
- package/builder/assets/{index.8b525942.js → index.89bb7cf4.js} +240 -239
- package/builder/index.html +2 -2
- package/dist/api/controllers/table/utils.js +3 -4
- package/dist/integrations/googlesheets.js +4 -0
- package/dist/package.json +7 -7
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +8 -8
- package/src/api/controllers/table/tests/utils.spec.ts +97 -0
- package/src/api/controllers/table/utils.ts +21 -12
- package/src/db/defaultData/datasource_bb_default.ts +1 -1
- package/src/integrations/googlesheets.ts +4 -0
- package/src/utilities/rowProcessor/index.ts +1 -1
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.42-alpha.
|
|
4
|
+
"version": "2.4.42-alpha.8",
|
|
5
5
|
"description": "Budibase Web Server",
|
|
6
6
|
"main": "src/index.ts",
|
|
7
7
|
"repository": {
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
"license": "GPL-3.0",
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"@apidevtools/swagger-parser": "10.0.3",
|
|
47
|
-
"@budibase/backend-core": "2.4.42-alpha.
|
|
48
|
-
"@budibase/client": "2.4.42-alpha.
|
|
49
|
-
"@budibase/pro": "2.4.42-alpha.
|
|
50
|
-
"@budibase/shared-core": "2.4.42-alpha.
|
|
51
|
-
"@budibase/string-templates": "2.4.42-alpha.
|
|
52
|
-
"@budibase/types": "2.4.42-alpha.
|
|
47
|
+
"@budibase/backend-core": "2.4.42-alpha.8",
|
|
48
|
+
"@budibase/client": "2.4.42-alpha.8",
|
|
49
|
+
"@budibase/pro": "2.4.42-alpha.7",
|
|
50
|
+
"@budibase/shared-core": "2.4.42-alpha.8",
|
|
51
|
+
"@budibase/string-templates": "2.4.42-alpha.8",
|
|
52
|
+
"@budibase/types": "2.4.42-alpha.8",
|
|
53
53
|
"@bull-board/api": "3.7.0",
|
|
54
54
|
"@bull-board/koa": "3.9.4",
|
|
55
55
|
"@elastic/elasticsearch": "7.10.0",
|
|
@@ -176,5 +176,5 @@
|
|
|
176
176
|
"optionalDependencies": {
|
|
177
177
|
"oracledb": "5.3.0"
|
|
178
178
|
},
|
|
179
|
-
"gitHead": "
|
|
179
|
+
"gitHead": "41669d5513e4c0c199aae0d1d85bdca3ecceaaf6"
|
|
180
180
|
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { FieldType } from "@budibase/types"
|
|
2
|
+
import { AutoFieldSubTypes } from "../../../../constants"
|
|
3
|
+
import TestConfiguration from "../../../../tests/utilities/TestConfiguration"
|
|
4
|
+
import { importToRows } from "../utils"
|
|
5
|
+
|
|
6
|
+
describe("utils", () => {
|
|
7
|
+
const config = new TestConfiguration()
|
|
8
|
+
|
|
9
|
+
beforeEach(async () => {
|
|
10
|
+
await config.init()
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
afterAll(config.end)
|
|
14
|
+
|
|
15
|
+
describe("importToRows", () => {
|
|
16
|
+
it("consecutive row have consecutive auto ids", async () => {
|
|
17
|
+
await config.doInContext(config.appId, async () => {
|
|
18
|
+
const table = await config.createTable({
|
|
19
|
+
name: "table",
|
|
20
|
+
type: "table",
|
|
21
|
+
schema: {
|
|
22
|
+
autoId: {
|
|
23
|
+
name: "autoId",
|
|
24
|
+
type: FieldType.NUMBER,
|
|
25
|
+
subtype: AutoFieldSubTypes.AUTO_ID,
|
|
26
|
+
autocolumn: true,
|
|
27
|
+
constraints: {
|
|
28
|
+
type: FieldType.NUMBER,
|
|
29
|
+
presence: true,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
name: {
|
|
33
|
+
name: "name",
|
|
34
|
+
type: FieldType.STRING,
|
|
35
|
+
constraints: {
|
|
36
|
+
type: FieldType.STRING,
|
|
37
|
+
presence: true,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const data = [{ name: "Alice" }, { name: "Bob" }, { name: "Claire" }]
|
|
44
|
+
|
|
45
|
+
const result = importToRows(data, table, config.user)
|
|
46
|
+
expect(result).toEqual([
|
|
47
|
+
expect.objectContaining({
|
|
48
|
+
autoId: 1,
|
|
49
|
+
name: "Alice",
|
|
50
|
+
}),
|
|
51
|
+
expect.objectContaining({
|
|
52
|
+
autoId: 2,
|
|
53
|
+
name: "Bob",
|
|
54
|
+
}),
|
|
55
|
+
expect.objectContaining({
|
|
56
|
+
autoId: 3,
|
|
57
|
+
name: "Claire",
|
|
58
|
+
}),
|
|
59
|
+
])
|
|
60
|
+
})
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it("can import data without a specific user performing the action", async () => {
|
|
64
|
+
await config.doInContext(config.appId, async () => {
|
|
65
|
+
const table = await config.createTable({
|
|
66
|
+
name: "table",
|
|
67
|
+
type: "table",
|
|
68
|
+
schema: {
|
|
69
|
+
autoId: {
|
|
70
|
+
name: "autoId",
|
|
71
|
+
type: FieldType.NUMBER,
|
|
72
|
+
subtype: AutoFieldSubTypes.AUTO_ID,
|
|
73
|
+
autocolumn: true,
|
|
74
|
+
constraints: {
|
|
75
|
+
type: FieldType.NUMBER,
|
|
76
|
+
presence: true,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
name: {
|
|
80
|
+
name: "name",
|
|
81
|
+
type: FieldType.STRING,
|
|
82
|
+
constraints: {
|
|
83
|
+
type: FieldType.STRING,
|
|
84
|
+
presence: true,
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const data = [{ name: "Alice" }, { name: "Bob" }, { name: "Claire" }]
|
|
91
|
+
|
|
92
|
+
const result = importToRows(data, table)
|
|
93
|
+
expect(result).toHaveLength(3)
|
|
94
|
+
})
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
})
|
|
@@ -20,7 +20,13 @@ import viewTemplate from "../view/viewBuilder"
|
|
|
20
20
|
import { cloneDeep } from "lodash/fp"
|
|
21
21
|
import { quotas } from "@budibase/pro"
|
|
22
22
|
import { events, context } from "@budibase/backend-core"
|
|
23
|
-
import {
|
|
23
|
+
import {
|
|
24
|
+
ContextUser,
|
|
25
|
+
Database,
|
|
26
|
+
Datasource,
|
|
27
|
+
SourceName,
|
|
28
|
+
Table,
|
|
29
|
+
} from "@budibase/types"
|
|
24
30
|
|
|
25
31
|
export async function clearColumns(table: any, columnNames: any) {
|
|
26
32
|
const db: Database = context.getAppDB()
|
|
@@ -99,32 +105,35 @@ export function makeSureTableUpToDate(table: any, tableToSave: any) {
|
|
|
99
105
|
return tableToSave
|
|
100
106
|
}
|
|
101
107
|
|
|
102
|
-
export function importToRows(
|
|
108
|
+
export function importToRows(
|
|
109
|
+
data: any[],
|
|
110
|
+
table: Table,
|
|
111
|
+
user: ContextUser | null = null
|
|
112
|
+
) {
|
|
103
113
|
let finalData: any = []
|
|
104
114
|
for (let i = 0; i < data.length; i++) {
|
|
105
115
|
let row = data[i]
|
|
106
|
-
row._id = generateRowID(table._id)
|
|
116
|
+
row._id = generateRowID(table._id!)
|
|
107
117
|
row.tableId = table._id
|
|
108
|
-
const processed
|
|
118
|
+
const processed = inputProcessing(user, table, row, {
|
|
109
119
|
noAutoRelationships: true,
|
|
110
120
|
})
|
|
111
121
|
row = processed.row
|
|
122
|
+
table = processed.table
|
|
112
123
|
|
|
113
|
-
|
|
114
|
-
let schema: any
|
|
115
|
-
for ([fieldName, schema] of Object.entries(table.schema)) {
|
|
124
|
+
for (const [fieldName, schema] of Object.entries(table.schema)) {
|
|
116
125
|
// check whether the options need to be updated for inclusion as part of the data import
|
|
117
126
|
if (
|
|
118
127
|
schema.type === FieldTypes.OPTIONS &&
|
|
119
128
|
row[fieldName] &&
|
|
120
|
-
(!schema.constraints
|
|
121
|
-
schema.constraints
|
|
129
|
+
(!schema.constraints!.inclusion ||
|
|
130
|
+
schema.constraints!.inclusion.indexOf(row[fieldName]) === -1)
|
|
122
131
|
) {
|
|
123
|
-
schema.constraints
|
|
124
|
-
...schema.constraints
|
|
132
|
+
schema.constraints!.inclusion = [
|
|
133
|
+
...schema.constraints!.inclusion!,
|
|
125
134
|
row[fieldName],
|
|
126
135
|
]
|
|
127
|
-
schema.constraints
|
|
136
|
+
schema.constraints!.inclusion.sort()
|
|
128
137
|
}
|
|
129
138
|
}
|
|
130
139
|
|
|
@@ -34,7 +34,7 @@ function syncLastIds(table: Table, rowCount: number) {
|
|
|
34
34
|
})
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
function tableImport(table: Table, data: Row) {
|
|
37
|
+
function tableImport(table: Table, data: Row[]) {
|
|
38
38
|
const cloneTable = cloneDeep(table)
|
|
39
39
|
const rowDocs = importToRows(data, cloneTable)
|
|
40
40
|
syncLastIds(cloneTable, rowDocs.length)
|
|
@@ -245,6 +245,10 @@ class GoogleSheetsIntegration implements DatasourcePlus {
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
async buildSchema(datasourceId: string, entities: Record<string, Table>) {
|
|
248
|
+
// not fully configured yet
|
|
249
|
+
if (!this.config.auth) {
|
|
250
|
+
return
|
|
251
|
+
}
|
|
248
252
|
await this.connect()
|
|
249
253
|
const sheets = this.client.sheetsByIndex
|
|
250
254
|
const tables: Record<string, Table> = {}
|
|
@@ -131,7 +131,7 @@ export function coerce(row: any, type: string) {
|
|
|
131
131
|
* @returns {object} the row which has been prepared to be written to the DB.
|
|
132
132
|
*/
|
|
133
133
|
export function inputProcessing(
|
|
134
|
-
user: ContextUser,
|
|
134
|
+
user: ContextUser | null,
|
|
135
135
|
table: Table,
|
|
136
136
|
row: Row,
|
|
137
137
|
opts?: AutoColumnProcessingOpts
|