@budibase/server 2.6.19-alpha.10 → 2.6.19-alpha.11

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.6.19-alpha.10",
4
+ "version": "2.6.19-alpha.11",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -45,12 +45,12 @@
45
45
  "license": "GPL-3.0",
46
46
  "dependencies": {
47
47
  "@apidevtools/swagger-parser": "10.0.3",
48
- "@budibase/backend-core": "2.6.19-alpha.10",
49
- "@budibase/client": "2.6.19-alpha.10",
50
- "@budibase/pro": "2.6.19-alpha.10",
51
- "@budibase/shared-core": "2.6.19-alpha.10",
52
- "@budibase/string-templates": "2.6.19-alpha.10",
53
- "@budibase/types": "2.6.19-alpha.10",
48
+ "@budibase/backend-core": "2.6.19-alpha.11",
49
+ "@budibase/client": "2.6.19-alpha.11",
50
+ "@budibase/pro": "2.6.19-alpha.11",
51
+ "@budibase/shared-core": "2.6.19-alpha.11",
52
+ "@budibase/string-templates": "2.6.19-alpha.11",
53
+ "@budibase/types": "2.6.19-alpha.11",
54
54
  "@bull-board/api": "3.7.0",
55
55
  "@bull-board/koa": "3.9.4",
56
56
  "@elastic/elasticsearch": "7.10.0",
@@ -193,5 +193,5 @@
193
193
  }
194
194
  }
195
195
  },
196
- "gitHead": "7143391429a9d3685a0c443a32c7b3c3d82b78cf"
196
+ "gitHead": "01a98bcf8dbedde393d2ad3b4019da79826ba2a1"
197
197
  }
@@ -186,11 +186,7 @@ export async function destroy(ctx: any) {
186
186
  export async function bulkImport(ctx: any) {
187
187
  const db = context.getAppDB()
188
188
  const table = await sdk.tables.getTable(ctx.params.tableId)
189
- const { rows } = ctx.request.body
190
- await handleDataImport(ctx.user, table, rows)
191
-
192
- // Ensure auto id and other table updates are persisted
193
- await db.put(table)
194
-
189
+ const { rows, identifierFields } = ctx.request.body
190
+ await handleDataImport(ctx.user, table, rows, identifierFields)
195
191
  return table
196
192
  }
@@ -149,7 +149,12 @@ export function importToRows(
149
149
  return finalData
150
150
  }
151
151
 
152
- export async function handleDataImport(user: any, table: any, rows: any) {
152
+ export async function handleDataImport(
153
+ user: any,
154
+ table: any,
155
+ rows: any,
156
+ identifierFields: Array<string> = []
157
+ ) {
153
158
  const schema: unknown = table.schema
154
159
 
155
160
  if (!rows || !isRows(rows) || !isSchema(schema)) {
@@ -161,6 +166,32 @@ export async function handleDataImport(user: any, table: any, rows: any) {
161
166
 
162
167
  let finalData: any = importToRows(data, table, user)
163
168
 
169
+ //Set IDs of finalData to match existing row if an update is expected
170
+ if (identifierFields.length > 0) {
171
+ const allDocs = await db.allDocs(
172
+ getRowParams(table._id, null, {
173
+ include_docs: true,
174
+ })
175
+ )
176
+ allDocs.rows
177
+ .map(existingRow => existingRow.doc)
178
+ .forEach((doc: any) => {
179
+ finalData.forEach((finalItem: any) => {
180
+ let match = true
181
+ for (const field of identifierFields) {
182
+ if (finalItem[field] !== doc[field]) {
183
+ match = false
184
+ break
185
+ }
186
+ }
187
+ if (match) {
188
+ finalItem._id = doc._id
189
+ finalItem._rev = doc._rev
190
+ }
191
+ })
192
+ })
193
+ }
194
+
164
195
  await quotas.addRows(finalData.length, () => db.bulkDocs(finalData), {
165
196
  tableId: table._id,
166
197
  })