@budibase/server 1.2.41-alpha.4 → 1.2.42

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 (194) hide show
  1. package/__mocks__/mongodb.ts +0 -4
  2. package/__mocks__/node-fetch.ts +1 -8
  3. package/builder/assets/index.08dd0c5e.css +6 -0
  4. package/builder/assets/index.b0f613b5.js +975 -0
  5. package/builder/assets/{vendor.67dbd8fa.js → vendor.6bcafa60.js} +1 -1
  6. package/builder/index.html +3 -3
  7. package/coverage/clover.xml +399 -422
  8. package/coverage/coverage-final.json +10 -10
  9. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  12. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  13. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/component.js.html +1 -1
  15. package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
  16. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  17. package/coverage/lcov-report/api/controllers/index.html +1 -1
  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/migrations.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/query/index.html +1 -1
  24. package/coverage/lcov-report/api/controllers/query/validation.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  26. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/index.html +25 -25
  29. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +191 -317
  31. package/coverage/lcov-report/api/controllers/row/staticFormula.js.html +1 -1
  32. package/coverage/lcov-report/api/controllers/row/utils.js.html +18 -27
  33. package/coverage/lcov-report/api/controllers/screen.js.html +1 -1
  34. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/table/bulkFormula.js.html +1 -1
  36. package/coverage/lcov-report/api/controllers/table/external.js.html +2 -2
  37. package/coverage/lcov-report/api/controllers/table/index.html +1 -1
  38. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/user.js.html +19 -19
  41. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  43. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  44. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  45. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  46. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  47. package/coverage/lcov-report/api/index.html +1 -1
  48. package/coverage/lcov-report/api/index.js.html +1 -1
  49. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/apikeys.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/index.html +1 -1
  60. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/metadata.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/migrations.js.html +1 -1
  64. package/coverage/lcov-report/api/routes/permission.js.html +1 -1
  65. package/coverage/lcov-report/api/routes/query.js.html +1 -1
  66. package/coverage/lcov-report/api/routes/role.js.html +1 -1
  67. package/coverage/lcov-report/api/routes/routing.js.html +1 -1
  68. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  69. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/table.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/user.js.html +1 -1
  73. package/coverage/lcov-report/api/routes/utils/index.html +1 -1
  74. package/coverage/lcov-report/api/routes/utils/validators.js.html +1 -1
  75. package/coverage/lcov-report/api/routes/view.js.html +1 -1
  76. package/coverage/lcov-report/api/routes/webhook.js.html +1 -1
  77. package/coverage/lcov-report/automations/actions.js.html +1 -1
  78. package/coverage/lcov-report/automations/automationUtils.js.html +1 -1
  79. package/coverage/lcov-report/automations/bullboard.js.html +1 -1
  80. package/coverage/lcov-report/automations/index.html +1 -1
  81. package/coverage/lcov-report/automations/index.js.html +1 -1
  82. package/coverage/lcov-report/automations/steps/bash.js.html +1 -1
  83. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/index.html +1 -1
  89. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/loop.js.html +1 -1
  91. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  95. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  96. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  97. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  98. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  99. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  100. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  101. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  102. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  103. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  104. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  105. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  106. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  107. package/coverage/lcov-report/automations/triggers.js.html +1 -1
  108. package/coverage/lcov-report/constants/index.html +1 -1
  109. package/coverage/lcov-report/constants/index.js.html +30 -30
  110. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  111. package/coverage/lcov-report/constants/screens.js.html +1 -1
  112. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  113. package/coverage/lcov-report/db/index.html +1 -1
  114. package/coverage/lcov-report/db/index.js.html +1 -1
  115. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  116. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  117. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  118. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  119. package/coverage/lcov-report/db/newid.js.html +3 -3
  120. package/coverage/lcov-report/db/utils.js.html +61 -61
  121. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  122. package/coverage/lcov-report/events/index.html +1 -1
  123. package/coverage/lcov-report/events/index.js.html +1 -1
  124. package/coverage/lcov-report/events/utils.js.html +1 -1
  125. package/coverage/lcov-report/index.html +19 -19
  126. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  127. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  128. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  129. package/coverage/lcov-report/middleware/builder.js.html +1 -1
  130. package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
  131. package/coverage/lcov-report/middleware/index.html +1 -1
  132. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  133. package/coverage/lcov-report/middleware/publicApi.js.html +1 -1
  134. package/coverage/lcov-report/middleware/resourceId.js.html +12 -12
  135. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  136. package/coverage/lcov-report/middleware/utils.js.html +1 -1
  137. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  138. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  139. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  140. package/coverage/lcov-report/utilities/global.js.html +16 -16
  141. package/coverage/lcov-report/utilities/index.html +1 -1
  142. package/coverage/lcov-report/utilities/index.js.html +23 -23
  143. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
  144. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  145. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  146. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  147. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  148. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  149. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  150. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  151. package/coverage/lcov-report/utilities/security.js.html +1 -1
  152. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  153. package/coverage/lcov-report/utilities/usageQuota/index.html +1 -1
  154. package/coverage/lcov-report/utilities/usageQuota/rows.js.html +1 -1
  155. package/coverage/lcov-report/utilities/usageQuota/usageQuoteReset.js.html +1 -1
  156. package/coverage/lcov-report/utilities/users.js.html +7 -7
  157. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  158. package/coverage/lcov.info +622 -662
  159. package/dist/api/controllers/row/internalSearch.js +4 -39
  160. package/dist/api/controllers/row/utils.js +1 -3
  161. package/dist/api/controllers/static/index.js +2 -8
  162. package/dist/api/controllers/table/external.js +1 -1
  163. package/dist/api/routes/static.js +0 -2
  164. package/dist/automations/logging/index.js +0 -3
  165. package/dist/integrations/base/sql.js +30 -62
  166. package/dist/integrations/base/utils.js +27 -13
  167. package/dist/integrations/microsoftSqlServer.js +2 -5
  168. package/dist/integrations/mongodb.js +8 -35
  169. package/dist/integrations/mysql.js +2 -2
  170. package/dist/integrations/postgres.js +2 -5
  171. package/dist/package.json +7 -7
  172. package/dist/tsconfig.build.tsbuildinfo +1 -1
  173. package/dist/utilities/fileSystem/index.js +1 -2
  174. package/package.json +8 -8
  175. package/src/api/controllers/row/internalSearch.js +3 -45
  176. package/src/api/controllers/row/utils.js +1 -4
  177. package/src/api/controllers/static/index.ts +1 -5
  178. package/src/api/controllers/table/external.js +1 -1
  179. package/src/api/routes/static.ts +0 -11
  180. package/src/automations/logging/index.ts +0 -3
  181. package/src/integrations/base/sql.ts +30 -67
  182. package/src/integrations/base/utils.ts +18 -9
  183. package/src/integrations/microsoftSqlServer.ts +2 -3
  184. package/src/integrations/mongodb.ts +8 -35
  185. package/src/integrations/mysql.ts +1 -1
  186. package/src/integrations/postgres.ts +1 -2
  187. package/src/integrations/tests/mongo.spec.js +0 -218
  188. package/src/integrations/tests/sql.spec.js +11 -101
  189. package/src/utilities/fileSystem/index.js +0 -2
  190. package/builder/assets/index.6b1c808b.css +0 -6
  191. package/builder/assets/index.ee769a71.js +0 -977
  192. package/dist/integrations/base/query.js +0 -27
  193. package/src/api/routes/tests/internalSearch.spec.js +0 -176
  194. package/src/integrations/base/query.ts +0 -16
@@ -14,7 +14,7 @@ const { join } = require("path");
14
14
  const uuid = require("uuid/v4");
15
15
  const { doWithDB, dangerousGetDB, closeDB, } = require("@budibase/backend-core/db");
16
16
  const { ObjectStoreBuckets } = require("../../constants");
17
- const { upload, retrieve, retrieveToTmp, streamUpload, deleteFolder, downloadTarball, deleteFiles, } = require("./utilities");
17
+ const { upload, retrieve, retrieveToTmp, streamUpload, deleteFolder, downloadTarball, } = require("./utilities");
18
18
  const { updateClientLibrary } = require("./clientLibrary");
19
19
  const env = require("../../environment");
20
20
  const { USER_METDATA_PREFIX, LINK_USER_METADATA_PREFIX, TABLE_ROW_PREFIX, } = require("../../db/utils");
@@ -289,6 +289,5 @@ exports.cleanup = appIds => {
289
289
  exports.upload = upload;
290
290
  exports.retrieve = retrieve;
291
291
  exports.retrieveToTmp = retrieveToTmp;
292
- exports.deleteFiles = deleteFiles;
293
292
  exports.TOP_LEVEL_PATH = TOP_LEVEL_PATH;
294
293
  exports.NODE_MODULES_PATH = NODE_MODULES_PATH;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@budibase/server",
3
3
  "email": "hi@budibase.com",
4
- "version": "1.2.41-alpha.4",
4
+ "version": "1.2.42",
5
5
  "description": "Budibase Web Server",
6
6
  "main": "src/index.ts",
7
7
  "repository": {
@@ -77,11 +77,11 @@
77
77
  "license": "GPL-3.0",
78
78
  "dependencies": {
79
79
  "@apidevtools/swagger-parser": "10.0.3",
80
- "@budibase/backend-core": "1.2.41-alpha.4",
81
- "@budibase/client": "1.2.41-alpha.4",
82
- "@budibase/pro": "1.2.41-alpha.3",
83
- "@budibase/string-templates": "1.2.41-alpha.4",
84
- "@budibase/types": "1.2.41-alpha.4",
80
+ "@budibase/backend-core": "^1.2.42",
81
+ "@budibase/client": "^1.2.42",
82
+ "@budibase/pro": "1.2.41",
83
+ "@budibase/string-templates": "^1.2.42",
84
+ "@budibase/types": "^1.2.42",
85
85
  "@bull-board/api": "3.7.0",
86
86
  "@bull-board/koa": "3.9.4",
87
87
  "@elastic/elasticsearch": "7.10.0",
@@ -106,7 +106,7 @@
106
106
  "google-auth-library": "7.12.0",
107
107
  "google-spreadsheet": "3.2.0",
108
108
  "jimp": "0.16.1",
109
- "joi": "17.6.0",
109
+ "joi": "17.2.1",
110
110
  "js-yaml": "4.1.0",
111
111
  "jsonschema": "1.4.0",
112
112
  "knex": "0.95.15",
@@ -195,5 +195,5 @@
195
195
  "optionalDependencies": {
196
196
  "oracledb": "5.3.0"
197
197
  },
198
- "gitHead": "1d79a9f3506ed748ab167afe925a85065d845437"
198
+ "gitHead": "111226abbd5e491027931e272d2267f25057fb13"
199
199
  }
@@ -1,5 +1,4 @@
1
1
  const { SearchIndexes } = require("../../../db/utils")
2
- const { removeKeyNumbering } = require("./utils")
3
2
  const fetch = require("node-fetch")
4
3
  const { getCouchInfo } = require("@budibase/backend-core/db")
5
4
  const { getAppId } = require("@budibase/backend-core/context")
@@ -21,8 +20,6 @@ class QueryBuilder {
21
20
  notEmpty: {},
22
21
  oneOf: {},
23
22
  contains: {},
24
- notContains: {},
25
- containsAny: {},
26
23
  ...base,
27
24
  }
28
25
  this.limit = 50
@@ -128,16 +125,6 @@ class QueryBuilder {
128
125
  return this
129
126
  }
130
127
 
131
- addNotContains(key, value) {
132
- this.query.notContains[key] = value
133
- return this
134
- }
135
-
136
- addContainsAny(key, value) {
137
- this.query.containsAny[key] = value
138
- return this
139
- }
140
-
141
128
  /**
142
129
  * Preprocesses a value before going into a lucene search.
143
130
  * Transforms strings to lowercase and wraps strings and bools in quotes.
@@ -183,29 +170,11 @@ class QueryBuilder {
183
170
  return `${key}:${builder.preprocess(value, allPreProcessingOpts)}`
184
171
  }
185
172
 
186
- const contains = (key, value, mode = "AND") => {
187
- if (Array.isArray(value) && value.length === 0) {
173
+ const contains = (key, value) => {
174
+ if (!value && value !== 0) {
188
175
  return null
189
176
  }
190
- if (!Array.isArray(value)) {
191
- return `${key}:${value}`
192
- }
193
- let statement = `${builder.preprocess(value[0], { escape: true })}`
194
- for (let i = 1; i < value.length; i++) {
195
- statement += ` ${mode} ${builder.preprocess(value[i], {
196
- escape: true,
197
- })}`
198
- }
199
- return `${key}:(${statement})`
200
- }
201
-
202
- const notContains = (key, value) => {
203
- const allPrefix = allOr === "" ? "*:* AND" : ""
204
- return allPrefix + "NOT " + contains(key, value)
205
- }
206
-
207
- const containsAny = (key, value) => {
208
- return contains(key, value, "OR")
177
+ return `${key}:${builder.preprocess(value, { escape: true })}`
209
178
  }
210
179
 
211
180
  const oneOf = (key, value) => {
@@ -228,8 +197,6 @@ class QueryBuilder {
228
197
 
229
198
  function build(structure, queryFn) {
230
199
  for (let [key, value] of Object.entries(structure)) {
231
- // check for new format - remove numbering if needed
232
- key = removeKeyNumbering(key)
233
200
  key = builder.preprocess(key.replace(/ /g, "_"), {
234
201
  escape: true,
235
202
  })
@@ -308,12 +275,6 @@ class QueryBuilder {
308
275
  if (this.query.contains) {
309
276
  build(this.query.contains, contains)
310
277
  }
311
- if (this.query.notContains) {
312
- build(this.query.notContains, notContains)
313
- }
314
- if (this.query.containsAny) {
315
- build(this.query.containsAny, containsAny)
316
- }
317
278
  // make sure table ID is always added as an AND
318
279
  if (tableId) {
319
280
  query = `(${query})`
@@ -349,9 +310,6 @@ class QueryBuilder {
349
310
  }
350
311
  }
351
312
 
352
- // exported for unit testing
353
- exports.QueryBuilder = QueryBuilder
354
-
355
313
  /**
356
314
  * Executes a lucene search query.
357
315
  * @param url The query URL
@@ -3,9 +3,8 @@ const { cloneDeep } = require("lodash/fp")
3
3
  const { InternalTables } = require("../../../db/utils")
4
4
  const userController = require("../user")
5
5
  const { FieldTypes } = require("../../../constants")
6
+ const { makeExternalQuery } = require("../../../integrations/base/utils")
6
7
  const { getAppDB } = require("@budibase/backend-core/context")
7
- const { makeExternalQuery } = require("../../../integrations/base/query")
8
- const { removeKeyNumbering } = require("../../../integrations/base/utils")
9
8
 
10
9
  validateJs.extend(validateJs.validators.datetime, {
11
10
  parse: function (value) {
@@ -17,8 +16,6 @@ validateJs.extend(validateJs.validators.datetime, {
17
16
  },
18
17
  })
19
18
 
20
- exports.removeKeyNumbering = removeKeyNumbering
21
-
22
19
  exports.getDatasourceAndQuery = async json => {
23
20
  const datasourceId = json.endpoint.datasourceId
24
21
  const db = getAppDB()
@@ -12,7 +12,7 @@ const {
12
12
  } = require("../../../utilities/fileSystem")
13
13
  const env = require("../../../environment")
14
14
  const { clientLibraryPath } = require("../../../utilities")
15
- const { upload, deleteFiles } = require("../../../utilities/fileSystem")
15
+ const { upload } = require("../../../utilities/fileSystem")
16
16
  const { attachmentsRelativeURL } = require("../../../utilities")
17
17
  const { DocumentType } = require("../../../db/utils")
18
18
  const { getAppDB, getAppId } = require("@budibase/backend-core/context")
@@ -97,10 +97,6 @@ export const uploadFile = async function (ctx: any) {
97
97
  ctx.body = await Promise.all(uploads)
98
98
  }
99
99
 
100
- export const deleteObjects = async function (ctx: any) {
101
- ctx.body = await deleteFiles(ObjectStoreBuckets.APPS, ctx.request.body.keys)
102
- }
103
-
104
100
  export const serveApp = async function (ctx: any) {
105
101
  const db = getAppDB({ skip_setup: true })
106
102
  const appInfo = await db.get(DocumentType.APP_METADATA)
@@ -14,7 +14,7 @@ const {
14
14
  FieldTypes,
15
15
  RelationshipTypes,
16
16
  } = require("../../../constants")
17
- const { makeExternalQuery } = require("../../../integrations/base/query")
17
+ const { makeExternalQuery } = require("../../../integrations/base/utils")
18
18
  const { cloneDeep } = require("lodash/fp")
19
19
  const csvParser = require("../../../utilities/csvParser")
20
20
  const { handleRequest } = require("../row/external")
@@ -38,11 +38,6 @@ router
38
38
  // TODO: for now this builder endpoint is not authorized/secured, will need to be
39
39
  .get("/builder/:file*", controller.serveBuilder)
40
40
  .post("/api/attachments/process", authorized(BUILDER), controller.uploadFile)
41
- .post(
42
- "/api/attachments/delete",
43
- authorized(BUILDER),
44
- controller.deleteObjects
45
- )
46
41
  .post("/api/beta/:feature", controller.toggleBetaUiFeature)
47
42
  .post(
48
43
  "/api/attachments/:tableId/upload",
@@ -50,12 +45,6 @@ router
50
45
  authorized(PermissionTypes.TABLE, PermissionLevels.WRITE),
51
46
  controller.uploadFile
52
47
  )
53
- .post(
54
- "/api/attachments/:tableId/delete",
55
- paramResource("tableId"),
56
- authorized(PermissionTypes.TABLE, PermissionLevels.WRITE),
57
- controller.deleteObjects
58
- )
59
48
  .get("/:appId/:path*", controller.serveApp)
60
49
  .get("/app/:appUrl/:path*", controller.serveApp)
61
50
  .post(
@@ -23,9 +23,6 @@ export async function checkAppMetadata(apps: App[]) {
23
23
  for (let [key, errors] of Object.entries(metadata.automationErrors)) {
24
24
  const updated = []
25
25
  for (let error of errors) {
26
- if (!error) {
27
- continue
28
- }
29
26
  const startDate = error.split(dbUtils.SEPARATOR)[2]
30
27
  if (startDate > maxStartDate) {
31
28
  updated.push(error)
@@ -10,7 +10,6 @@ import { QueryOptions } from "../../definitions/datasource"
10
10
  import { isIsoDateString, SqlClient } from "../utils"
11
11
  import SqlTableQueryBuilder from "./sqlTable"
12
12
  import environment from "../../environment"
13
- import { removeKeyNumbering } from "./utils"
14
13
 
15
14
  const envLimit = environment.SQL_MAX_ROWS
16
15
  ? parseInt(environment.SQL_MAX_ROWS)
@@ -134,13 +133,12 @@ class InternalBuilder {
134
133
  fn: (key: string, value: any) => void
135
134
  ) {
136
135
  for (let [key, value] of Object.entries(structure)) {
137
- const updatedKey = removeKeyNumbering(key)
138
- const isRelationshipField = updatedKey.includes(".")
136
+ const isRelationshipField = key.includes(".")
139
137
  if (!opts.relationship && !isRelationshipField) {
140
- fn(`${opts.tableName}.${updatedKey}`, value)
138
+ fn(`${opts.tableName}.${key}`, value)
141
139
  }
142
140
  if (opts.relationship && isRelationshipField) {
143
- fn(updatedKey, value)
141
+ fn(key, value)
144
142
  }
145
143
  }
146
144
  }
@@ -159,61 +157,6 @@ class InternalBuilder {
159
157
  }
160
158
  }
161
159
 
162
- const contains = (mode: object, any: boolean = false) => {
163
- const fnc = allOr ? "orWhere" : "where"
164
- const rawFnc = `${fnc}Raw`
165
- const not = mode === filters?.notContains ? "NOT " : ""
166
- function stringifyArray(value: Array<any>, quoteStyle = '"'): string {
167
- for (let i in value) {
168
- if (typeof value[i] === "string") {
169
- value[i] = `${quoteStyle}${value[i]}${quoteStyle}`
170
- }
171
- }
172
- return `[${value.join(",")}]`
173
- }
174
- if (this.client === SqlClient.POSTGRES) {
175
- iterate(mode, (key: string, value: Array<any>) => {
176
- const wrap = any ? "" : "'"
177
- const containsOp = any ? "\\?| array" : "@>"
178
- const fieldNames = key.split(/\./g)
179
- const tableName = fieldNames[0]
180
- const columnName = fieldNames[1]
181
- // @ts-ignore
182
- query = query[rawFnc](
183
- `${not}"${tableName}"."${columnName}"::jsonb ${containsOp} ${wrap}${stringifyArray(
184
- value,
185
- any ? "'" : '"'
186
- )}${wrap}`
187
- )
188
- })
189
- } else if (this.client === SqlClient.MY_SQL) {
190
- const jsonFnc = any ? "JSON_OVERLAPS" : "JSON_CONTAINS"
191
- iterate(mode, (key: string, value: Array<any>) => {
192
- // @ts-ignore
193
- query = query[rawFnc](
194
- `${not}${jsonFnc}(${key}, '${stringifyArray(value)}')`
195
- )
196
- })
197
- } else {
198
- const andOr = mode === filters?.containsAny ? " OR " : " AND "
199
- iterate(mode, (key: string, value: Array<any>) => {
200
- let statement = ""
201
- for (let i in value) {
202
- if (typeof value[i] === "string") {
203
- value[i] = `%"${value[i]}"%`
204
- } else {
205
- value[i] = `%${value[i]}%`
206
- }
207
- statement +=
208
- (statement ? andOr : "") +
209
- `LOWER(${likeKey(this.client, key)}) LIKE ?`
210
- }
211
- // @ts-ignore
212
- query = query[rawFnc](`${not}(${statement})`, value)
213
- })
214
- }
215
- }
216
-
217
160
  if (!filters) {
218
161
  return query
219
162
  }
@@ -284,13 +227,32 @@ class InternalBuilder {
284
227
  })
285
228
  }
286
229
  if (filters.contains) {
287
- contains(filters.contains)
288
- }
289
- if (filters.notContains) {
290
- contains(filters.notContains)
291
- }
292
- if (filters.containsAny) {
293
- contains(filters.containsAny, true)
230
+ const fnc = allOr ? "orWhere" : "where"
231
+ const rawFnc = `${fnc}Raw`
232
+ if (this.client === SqlClient.POSTGRES) {
233
+ iterate(filters.contains, (key: string, value: any) => {
234
+ const fieldNames = key.split(/\./g)
235
+ const tableName = fieldNames[0]
236
+ const columnName = fieldNames[1]
237
+ if (typeof value === "string") {
238
+ value = `"${value}"`
239
+ }
240
+ // @ts-ignore
241
+ query = query[rawFnc](
242
+ `"${tableName}"."${columnName}"::jsonb @> '[${value}]'`
243
+ )
244
+ })
245
+ } else if (this.client === SqlClient.MY_SQL) {
246
+ iterate(filters.contains, (key: string, value: any) => {
247
+ if (typeof value === "string") {
248
+ value = `"${value}"`
249
+ }
250
+ // @ts-ignore
251
+ query = query[rawFnc](`JSON_CONTAINS(${key}, '${value}')`)
252
+ })
253
+ } else {
254
+ iterate(filters.contains, like)
255
+ }
294
256
  }
295
257
  return query
296
258
  }
@@ -620,3 +582,4 @@ class SqlQueryBuilder extends SqlTableQueryBuilder {
620
582
  }
621
583
 
622
584
  export default SqlQueryBuilder
585
+ module.exports = SqlQueryBuilder
@@ -1,12 +1,21 @@
1
- const QUERY_START_REGEX = /\d[0-9]*:/g
1
+ import { QueryJson, Datasource } from "@budibase/types"
2
2
 
3
- export function removeKeyNumbering(key: any): string {
4
- if (typeof key === "string" && key.match(QUERY_START_REGEX) != null) {
5
- const parts = key.split(":")
6
- // remove the number
7
- parts.shift()
8
- return parts.join(":")
9
- } else {
10
- return key
3
+ module DatasourceUtils {
4
+ const { integrations } = require("../index")
5
+
6
+ export async function makeExternalQuery(
7
+ datasource: Datasource,
8
+ json: QueryJson
9
+ ) {
10
+ const Integration = integrations[datasource.source]
11
+ // query is the opinionated function
12
+ if (Integration.prototype.query) {
13
+ const integration = new Integration(datasource.config)
14
+ return integration.query(json)
15
+ } else {
16
+ throw "Datasource does not support query."
17
+ }
11
18
  }
19
+
20
+ module.exports.makeExternalQuery = makeExternalQuery
12
21
  }
@@ -16,10 +16,10 @@ import {
16
16
  finaliseExternalTables,
17
17
  SqlClient,
18
18
  } from "./utils"
19
- import Sql from "./base/sql"
20
19
 
21
20
  module MSSQLModule {
22
21
  const sqlServer = require("mssql")
22
+ const Sql = require("./base/sql")
23
23
  const DEFAULT_SCHEMA = "dbo"
24
24
 
25
25
  interface MSSQLConfig {
@@ -97,8 +97,7 @@ module MSSQLModule {
97
97
  class SqlServerIntegration extends Sql implements DatasourcePlus {
98
98
  private readonly config: MSSQLConfig
99
99
  private index: number = 0
100
- private readonly pool: any
101
- private client: any
100
+ static pool: any
102
101
  public tables: Record<string, Table> = {}
103
102
  public schemaErrors: Record<string, string> = {}
104
103
 
@@ -92,15 +92,12 @@ module MongoDBModule {
92
92
  if (json[field] instanceof Object) {
93
93
  json[field] = self.createObjectIds(json[field])
94
94
  }
95
- if (
96
- (field === "_id" || field?.startsWith("$")) &&
97
- typeof json[field] === "string"
98
- ) {
99
- const id = json[field].match(
95
+ if (field === "_id" && typeof json[field] === "string") {
96
+ const id = json["_id"].match(
100
97
  /(?<=objectid\(['"]).*(?=['"]\))/gi
101
98
  )?.[0]
102
99
  if (id) {
103
- json[field] = ObjectID.createFromHexString(id)
100
+ json["_id"] = ObjectID.createFromHexString(id)
104
101
  }
105
102
  }
106
103
  }
@@ -117,31 +114,10 @@ module MongoDBModule {
117
114
  }
118
115
 
119
116
  parseQueryParams(params: string, mode: string) {
120
- let queryParams = []
121
- let openCount = 0
122
- let inQuotes = false
123
- let i = 0
124
- let startIndex = 0
125
- for (let c of params) {
126
- if (c === '"' && i > 0 && params[i - 1] !== "\\") {
127
- inQuotes = !inQuotes
128
- }
129
- if (c === "{" && !inQuotes) {
130
- openCount++
131
- if (openCount === 1) {
132
- startIndex = i
133
- }
134
- } else if (c === "}" && !inQuotes) {
135
- if (openCount === 1) {
136
- queryParams.push(JSON.parse(params.substring(startIndex, i + 1)))
137
- }
138
- openCount--
139
- }
140
- i++
141
- }
142
- let group1 = queryParams[0] ?? {}
143
- let group2 = queryParams[1] ?? {}
144
- let group3 = queryParams[2] ?? {}
117
+ let queryParams = params.split(/(?<=}),[\n\s]*(?={)/g)
118
+ let group1 = queryParams[0] ? JSON.parse(queryParams[0]) : {}
119
+ let group2 = queryParams[1] ? JSON.parse(queryParams[1]) : {}
120
+ let group3 = queryParams[2] ? JSON.parse(queryParams[2]) : {}
145
121
  if (mode === "update") {
146
122
  return {
147
123
  filter: group1,
@@ -200,10 +176,7 @@ module MongoDBModule {
200
176
  return await collection.findOne(json)
201
177
  }
202
178
  case "findOneAndUpdate": {
203
- if (typeof query.json === "string") {
204
- json = this.parseQueryParams(query.json, "update")
205
- }
206
- let findAndUpdateJson = this.createObjectIds(json) as {
179
+ let findAndUpdateJson = json as {
207
180
  filter: FilterQuery<any>
208
181
  update: UpdateQuery<any>
209
182
  options: FindOneAndUpdateOption<any>
@@ -17,10 +17,10 @@ import {
17
17
  } from "./utils"
18
18
  import dayjs from "dayjs"
19
19
  const { NUMBER_REGEX } = require("../utilities")
20
- import Sql from "./base/sql"
21
20
 
22
21
  module MySQLModule {
23
22
  const mysql = require("mysql2/promise")
23
+ const Sql = require("./base/sql")
24
24
 
25
25
  interface MySQLConfig {
26
26
  host: string
@@ -14,10 +14,10 @@ import {
14
14
  finaliseExternalTables,
15
15
  SqlClient,
16
16
  } from "./utils"
17
- import Sql from "./base/sql"
18
17
 
19
18
  module PostgresModule {
20
19
  const { Client, types } = require("pg")
20
+ const Sql = require("./base/sql")
21
21
  const { escapeDangerousCharacters } = require("../utilities")
22
22
 
23
23
  // Return "date" and "timestamp" types as plain strings.
@@ -117,7 +117,6 @@ module PostgresModule {
117
117
  private readonly client: any
118
118
  private readonly config: PostgresConfig
119
119
  private index: number = 1
120
- private open: boolean
121
120
  public tables: Record<string, Table> = {}
122
121
  public schemaErrors: Record<string, string> = {}
123
122