@budibase/server 0.9.174 → 0.9.176-alpha.2

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.
Files changed (203) hide show
  1. package/builder/assets/{index.7469e1e4.css → index.75ed4773.css} +1 -1
  2. package/builder/assets/{index.ba2741f9.js → index.d3780441.js} +34 -34
  3. package/builder/index.html +2 -2
  4. package/coverage/clover.xml +383 -207
  5. package/coverage/coverage-final.json +8 -6
  6. package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
  7. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/application.js.html +1 -1
  9. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  12. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  13. package/coverage/lcov-report/api/controllers/component.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/datasource.js.html +120 -24
  15. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  16. package/coverage/lcov-report/api/controllers/hosting.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/index.html +19 -19
  18. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  21. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/query.js.html +9 -3
  23. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  24. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/index.html +14 -14
  27. package/coverage/lcov-report/api/controllers/row/index.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  29. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/row/utils.js.html +11 -32
  31. package/coverage/lcov-report/api/controllers/screen.js.html +1 -1
  32. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  33. package/coverage/lcov-report/api/controllers/table/external.js.html +908 -0
  34. package/coverage/lcov-report/api/controllers/table/index.html +59 -29
  35. package/coverage/lcov-report/api/controllers/table/index.js.html +52 -376
  36. package/coverage/lcov-report/api/controllers/table/internal.js.html +494 -0
  37. package/coverage/lcov-report/api/controllers/table/utils.js.html +70 -10
  38. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  41. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  42. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  43. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  44. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  45. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  46. package/coverage/lcov-report/api/index.html +1 -1
  47. package/coverage/lcov-report/api/index.js.html +1 -1
  48. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  49. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/application.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/hosting.js.html +1 -1
  60. package/coverage/lcov-report/api/routes/index.html +1 -1
  61. package/coverage/lcov-report/api/routes/index.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/row.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/static.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  74. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  75. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  76. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  77. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  78. package/coverage/lcov-report/automations/actions.js.html +1 -1
  79. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  80. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  81. package/coverage/lcov-report/automations/index.html +1 -1
  82. package/coverage/lcov-report/automations/index.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/createRow.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/deleteRow.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  89. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/index.html +1 -1
  92. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  95. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  96. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  97. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  98. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  99. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  100. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  101. package/coverage/lcov-report/automations/thread.js.html +1 -1
  102. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  103. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  104. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  105. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  106. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  107. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  108. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  109. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  110. package/coverage/lcov-report/automations/triggers.js.html +1 -1
  111. package/coverage/lcov-report/automations/utils.js.html +1 -1
  112. package/coverage/lcov-report/constants/index.html +5 -5
  113. package/coverage/lcov-report/constants/index.js.html +25 -4
  114. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  115. package/coverage/lcov-report/constants/screens.js.html +1 -1
  116. package/coverage/lcov-report/db/client.js.html +1 -1
  117. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  118. package/coverage/lcov-report/db/index.html +1 -1
  119. package/coverage/lcov-report/db/index.js.html +1 -1
  120. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  121. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  122. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  123. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  124. package/coverage/lcov-report/db/newid.js.html +1 -1
  125. package/coverage/lcov-report/db/utils.js.html +1 -1
  126. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  127. package/coverage/lcov-report/events/index.html +1 -1
  128. package/coverage/lcov-report/events/index.js.html +1 -1
  129. package/coverage/lcov-report/events/utils.js.html +1 -1
  130. package/coverage/lcov-report/index.html +38 -38
  131. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  132. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  133. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  134. package/coverage/lcov-report/middleware/authorized.js.html +1 -1
  135. package/coverage/lcov-report/middleware/builder.js.html +1 -1
  136. package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
  137. package/coverage/lcov-report/middleware/index.html +1 -1
  138. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  139. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  140. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  141. package/coverage/lcov-report/middleware/usageQuota.js.html +1 -1
  142. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  143. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  144. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  145. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  146. package/coverage/lcov-report/utilities/global.js.html +1 -1
  147. package/coverage/lcov-report/utilities/index.html +1 -1
  148. package/coverage/lcov-report/utilities/index.js.html +1 -1
  149. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
  150. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  151. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  152. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  153. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  154. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  155. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  156. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  157. package/coverage/lcov-report/utilities/security.js.html +1 -1
  158. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  159. package/coverage/lcov-report/utilities/users.js.html +1 -1
  160. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  161. package/coverage/lcov.info +652 -332
  162. package/dist/api/controllers/datasource.js +41 -14
  163. package/dist/api/controllers/query.js +3 -1
  164. package/dist/api/controllers/row/ExternalRequest.js +12 -10
  165. package/dist/api/controllers/row/utils.js +3 -11
  166. package/dist/api/controllers/table/external.js +222 -0
  167. package/dist/api/controllers/table/index.js +28 -121
  168. package/dist/api/controllers/table/internal.js +138 -0
  169. package/dist/api/controllers/table/utils.js +17 -0
  170. package/dist/constants/index.js +6 -0
  171. package/dist/definitions/datasource.js +3 -0
  172. package/dist/integrations/base/datasourcePlus.js +2 -0
  173. package/dist/integrations/base/sql.js +16 -11
  174. package/dist/integrations/base/sqlTable.js +141 -0
  175. package/dist/integrations/base/utils.js +30 -0
  176. package/dist/integrations/mysql.js +13 -7
  177. package/dist/integrations/postgres.js +18 -8
  178. package/dist/integrations/utils.js +21 -6
  179. package/dist/package.json +4 -4
  180. package/dist/tests/utilities/TestConfiguration.js +2 -1
  181. package/dist/tsconfig.tsbuildinfo +1 -1
  182. package/package.json +5 -5
  183. package/src/api/controllers/datasource.js +46 -14
  184. package/src/api/controllers/query.js +3 -1
  185. package/src/api/controllers/row/ExternalRequest.ts +12 -10
  186. package/src/api/controllers/row/utils.js +3 -10
  187. package/src/api/controllers/table/external.js +276 -0
  188. package/src/api/controllers/table/index.js +27 -135
  189. package/src/api/controllers/table/internal.js +138 -0
  190. package/src/api/controllers/table/utils.js +20 -0
  191. package/src/api/routes/tests/datasource.spec.js +2 -2
  192. package/src/api/routes/tests/query.spec.js +0 -1
  193. package/src/constants/index.js +7 -0
  194. package/src/definitions/common.ts +7 -1
  195. package/src/definitions/datasource.ts +5 -0
  196. package/src/integrations/base/datasourcePlus.ts +8 -0
  197. package/src/integrations/base/sql.ts +15 -16
  198. package/src/integrations/base/sqlTable.ts +167 -0
  199. package/src/integrations/base/utils.ts +19 -0
  200. package/src/integrations/mysql.ts +15 -9
  201. package/src/integrations/postgres.ts +19 -9
  202. package/src/integrations/utils.ts +22 -6
  203. package/src/tests/utilities/TestConfiguration.js +2 -1
@@ -0,0 +1,19 @@
1
+ import { QueryJson } from "../../definitions/datasource"
2
+ import { Datasource } from "../../definitions/common"
3
+
4
+ module DatasourceUtils {
5
+ const { integrations } = require("../index")
6
+
7
+ export async function makeExternalQuery(datasource: Datasource, json: QueryJson) {
8
+ const Integration = integrations[datasource.source]
9
+ // query is the opinionated function
10
+ if (Integration.prototype.query) {
11
+ const integration = new Integration(datasource.config)
12
+ return integration.query(json)
13
+ } else {
14
+ throw "Datasource does not support query."
15
+ }
16
+ }
17
+
18
+ module.exports.makeExternalQuery = makeExternalQuery
19
+ }
@@ -8,6 +8,7 @@ import {
8
8
  } from "../definitions/datasource"
9
9
  import { Table, TableSchema } from "../definitions/common"
10
10
  import { getSqlQuery } from "./utils"
11
+ import { DatasourcePlus } from "./base/datasourcePlus"
11
12
 
12
13
  module MySQLModule {
13
14
  const mysql = require("mysql2")
@@ -15,7 +16,7 @@ module MySQLModule {
15
16
  const {
16
17
  buildExternalTableId,
17
18
  convertType,
18
- copyExistingPropsOver,
19
+ finaliseExternalTables,
19
20
  } = require("./utils")
20
21
  const { FieldTypes } = require("../constants")
21
22
 
@@ -131,9 +132,11 @@ module MySQLModule {
131
132
  })
132
133
  }
133
134
 
134
- class MySQLIntegration extends Sql {
135
+ class MySQLIntegration extends Sql implements DatasourcePlus {
135
136
  private config: MySQLConfig
136
137
  private readonly client: any
138
+ public tables: Record<string, Table> = {}
139
+ public schemaErrors: Record<string, string> = {}
137
140
 
138
141
  constructor(config: MySQLConfig) {
139
142
  super("mysql")
@@ -185,10 +188,6 @@ module MySQLModule {
185
188
  constraints,
186
189
  }
187
190
  }
188
- // for now just default to first column
189
- if (primaryKeys.length === 0) {
190
- primaryKeys.push(descResp[0].Field)
191
- }
192
191
  if (!tables[tableName]) {
193
192
  tables[tableName] = {
194
193
  _id: buildExternalTableId(datasourceId, tableName),
@@ -197,12 +196,12 @@ module MySQLModule {
197
196
  schema,
198
197
  }
199
198
  }
200
-
201
- copyExistingPropsOver(tableName, tables, entities)
202
199
  }
203
200
 
204
201
  this.client.end()
205
- this.tables = tables
202
+ const final = finaliseExternalTables(tables, entities)
203
+ this.tables = final.tables
204
+ this.schemaErrors = final.errors
206
205
  }
207
206
 
208
207
  async create(query: SqlQuery | string) {
@@ -263,6 +262,13 @@ module MySQLModule {
263
262
  const operation = this._operation(json)
264
263
  this.client.connect()
265
264
  const input = this._query(json, { disableReturning: true })
265
+ if (Array.isArray(input)) {
266
+ const responses = []
267
+ for (let query of input) {
268
+ responses.push(await internalQuery(this.client, query, false))
269
+ }
270
+ return responses
271
+ }
266
272
  let row
267
273
  // need to manage returning, a feature mySQL can't do
268
274
  if (operation === operation.DELETE) {
@@ -7,6 +7,7 @@ import {
7
7
  } from "../definitions/datasource"
8
8
  import { Table } from "../definitions/common"
9
9
  import { getSqlQuery } from "./utils"
10
+ import { DatasourcePlus } from "./base/datasourcePlus"
10
11
 
11
12
  module PostgresModule {
12
13
  const { Pool } = require("pg")
@@ -15,7 +16,7 @@ module PostgresModule {
15
16
  const {
16
17
  buildExternalTableId,
17
18
  convertType,
18
- copyExistingPropsOver,
19
+ finaliseExternalTables,
19
20
  } = require("./utils")
20
21
  const { escapeDangerousCharacters } = require("../utilities")
21
22
 
@@ -132,10 +133,12 @@ module PostgresModule {
132
133
  }
133
134
  }
134
135
 
135
- class PostgresIntegration extends Sql {
136
+ class PostgresIntegration extends Sql implements DatasourcePlus {
136
137
  static pool: any
137
138
  private readonly client: any
138
139
  private readonly config: PostgresConfig
140
+ public tables: Record<string, Table> = {}
141
+ public schemaErrors: Record<string, string> = {}
139
142
 
140
143
  COLUMNS_SQL =
141
144
  "select * from information_schema.columns where not table_schema = 'information_schema' and not table_schema = 'pg_catalog'"
@@ -207,7 +210,7 @@ module PostgresModule {
207
210
  if (!tables[tableName] || !tables[tableName].schema) {
208
211
  tables[tableName] = {
209
212
  _id: buildExternalTableId(datasourceId, tableName),
210
- primary: tableKeys[tableName] || ["id"],
213
+ primary: tableKeys[tableName] || [],
211
214
  name: tableName,
212
215
  schema: {},
213
216
  }
@@ -232,10 +235,9 @@ module PostgresModule {
232
235
  }
233
236
  }
234
237
 
235
- for (let tableName of Object.keys(tables)) {
236
- copyExistingPropsOver(tableName, tables, entities)
237
- }
238
- this.tables = tables
238
+ const final = finaliseExternalTables(tables, entities)
239
+ this.tables = final.tables
240
+ this.schemaErrors = final.errors
239
241
  }
240
242
 
241
243
  async create(query: SqlQuery | string) {
@@ -261,8 +263,16 @@ module PostgresModule {
261
263
  async query(json: QueryJson) {
262
264
  const operation = this._operation(json).toLowerCase()
263
265
  const input = this._query(json)
264
- const response = await internalQuery(this.client, input)
265
- return response.rows.length ? response.rows : [{ [operation]: true }]
266
+ if (Array.isArray(input)) {
267
+ const responses = []
268
+ for (let query of input) {
269
+ responses.push(await internalQuery(this.client, query))
270
+ }
271
+ return responses
272
+ } else {
273
+ const response = await internalQuery(this.client, input)
274
+ return response.rows.length ? response.rows : [{ [operation]: true }]
275
+ }
266
276
  }
267
277
  }
268
278
 
@@ -1,8 +1,8 @@
1
1
  import { SqlQuery } from "../definitions/datasource"
2
- import { Datasource } from "../definitions/common"
2
+ import { Datasource, Table } from "../definitions/common"
3
3
  import { SourceNames } from "../definitions/datasource"
4
4
  const { DocumentTypes, SEPARATOR } = require("../db/utils")
5
- const { FieldTypes } = require("../constants")
5
+ const { FieldTypes, BuildSchemaErrors } = require("../constants")
6
6
 
7
7
  const DOUBLE_SEPARATOR = `${SEPARATOR}${SEPARATOR}`
8
8
  const ROW_ID_REGEX = /^\[.*]$/g
@@ -102,14 +102,14 @@ export function isIsoDateString(str: string) {
102
102
  }
103
103
 
104
104
  // add the existing relationships from the entities if they exist, to prevent them from being overridden
105
- export function copyExistingPropsOver(
105
+ function copyExistingPropsOver(
106
106
  tableName: string,
107
- tables: { [key: string]: any },
107
+ table: Table,
108
108
  entities: { [key: string]: any }
109
109
  ) {
110
110
  if (entities && entities[tableName]) {
111
111
  if (entities[tableName].primaryDisplay) {
112
- tables[tableName].primaryDisplay = entities[tableName].primaryDisplay
112
+ table.primaryDisplay = entities[tableName].primaryDisplay
113
113
  }
114
114
  const existingTableSchema = entities[tableName].schema
115
115
  for (let key in existingTableSchema) {
@@ -117,8 +117,24 @@ export function copyExistingPropsOver(
117
117
  continue
118
118
  }
119
119
  if (existingTableSchema[key].type === "link") {
120
- tables[tableName].schema[key] = existingTableSchema[key]
120
+ table.schema[key] = existingTableSchema[key]
121
121
  }
122
122
  }
123
123
  }
124
+ return table
125
+ }
126
+
127
+ export function finaliseExternalTables(tables: { [key: string]: any }, entities: { [key: string]: any }) {
128
+ const finalTables: { [key: string]: any } = {}
129
+ const errors: { [key: string]: string } = {}
130
+ for (let [name, table] of Object.entries(tables)) {
131
+ // make sure every table has a key
132
+ if (table.primary == null || table.primary.length === 0) {
133
+ errors[name] = BuildSchemaErrors.NO_KEY
134
+ continue
135
+ }
136
+ // make sure all previous props have been added back
137
+ finalTables[name] = copyExistingPropsOver(name, table, entities)
138
+ }
139
+ return { tables: finalTables, errors }
124
140
  }
@@ -311,7 +311,8 @@ class TestConfiguration {
311
311
 
312
312
  async createDatasource(config = null) {
313
313
  config = config || basicDatasource()
314
- this.datasource = await this._req(config, null, controllers.datasource.save)
314
+ const response = await this._req(config, null, controllers.datasource.save)
315
+ this.datasource = response.datasource
315
316
  return this.datasource
316
317
  }
317
318