@budibase/server 0.9.190-alpha.7 → 1.0.1

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 (185) hide show
  1. package/builder/assets/{index.59c6065f.js → index.e95b024a.js} +140 -140
  2. package/builder/index.html +1 -1
  3. package/coverage/clover.xml +42 -45
  4. package/coverage/coverage-final.json +3 -3
  5. package/coverage/lcov-report/api/controllers/analytics.js.html +1 -1
  6. package/coverage/lcov-report/api/controllers/apikeys.js.html +1 -1
  7. package/coverage/lcov-report/api/controllers/application.js.html +1 -1
  8. package/coverage/lcov-report/api/controllers/auth.js.html +1 -1
  9. package/coverage/lcov-report/api/controllers/automation.js.html +1 -1
  10. package/coverage/lcov-report/api/controllers/backup.js.html +1 -1
  11. package/coverage/lcov-report/api/controllers/cloud.js.html +1 -1
  12. package/coverage/lcov-report/api/controllers/component.js.html +1 -1
  13. package/coverage/lcov-report/api/controllers/datasource.js.html +1 -1
  14. package/coverage/lcov-report/api/controllers/dev.js.html +1 -1
  15. package/coverage/lcov-report/api/controllers/hosting.js.html +1 -1
  16. package/coverage/lcov-report/api/controllers/index.html +1 -1
  17. package/coverage/lcov-report/api/controllers/integration.js.html +1 -1
  18. package/coverage/lcov-report/api/controllers/layout.js.html +1 -1
  19. package/coverage/lcov-report/api/controllers/metadata.js.html +1 -1
  20. package/coverage/lcov-report/api/controllers/permission.js.html +1 -1
  21. package/coverage/lcov-report/api/controllers/query.js.html +1 -1
  22. package/coverage/lcov-report/api/controllers/role.js.html +1 -1
  23. package/coverage/lcov-report/api/controllers/routing.js.html +1 -1
  24. package/coverage/lcov-report/api/controllers/row/external.js.html +1 -1
  25. package/coverage/lcov-report/api/controllers/row/index.html +1 -1
  26. package/coverage/lcov-report/api/controllers/row/index.js.html +1 -1
  27. package/coverage/lcov-report/api/controllers/row/internal.js.html +1 -1
  28. package/coverage/lcov-report/api/controllers/row/internalSearch.js.html +1 -1
  29. package/coverage/lcov-report/api/controllers/row/utils.js.html +1 -1
  30. package/coverage/lcov-report/api/controllers/screen.js.html +1 -1
  31. package/coverage/lcov-report/api/controllers/script.js.html +1 -1
  32. package/coverage/lcov-report/api/controllers/table/external.js.html +1 -1
  33. package/coverage/lcov-report/api/controllers/table/index.html +14 -14
  34. package/coverage/lcov-report/api/controllers/table/index.js.html +1 -1
  35. package/coverage/lcov-report/api/controllers/table/internal.js.html +8 -20
  36. package/coverage/lcov-report/api/controllers/table/utils.js.html +1 -1
  37. package/coverage/lcov-report/api/controllers/templates.js.html +1 -1
  38. package/coverage/lcov-report/api/controllers/user.js.html +1 -1
  39. package/coverage/lcov-report/api/controllers/view/exporters.js.html +1 -1
  40. package/coverage/lcov-report/api/controllers/view/index.html +1 -1
  41. package/coverage/lcov-report/api/controllers/view/index.js.html +1 -1
  42. package/coverage/lcov-report/api/controllers/view/utils.js.html +1 -1
  43. package/coverage/lcov-report/api/controllers/view/viewBuilder.js.html +1 -1
  44. package/coverage/lcov-report/api/controllers/webhook.js.html +1 -1
  45. package/coverage/lcov-report/api/index.html +1 -1
  46. package/coverage/lcov-report/api/index.js.html +1 -1
  47. package/coverage/lcov-report/api/routes/analytics.js.html +1 -1
  48. package/coverage/lcov-report/api/routes/apikeys.js.html +1 -1
  49. package/coverage/lcov-report/api/routes/application.js.html +1 -1
  50. package/coverage/lcov-report/api/routes/auth.js.html +1 -1
  51. package/coverage/lcov-report/api/routes/automation.js.html +1 -1
  52. package/coverage/lcov-report/api/routes/backup.js.html +1 -1
  53. package/coverage/lcov-report/api/routes/cloud.js.html +1 -1
  54. package/coverage/lcov-report/api/routes/component.js.html +1 -1
  55. package/coverage/lcov-report/api/routes/datasource.js.html +1 -1
  56. package/coverage/lcov-report/api/routes/deploy.js.html +1 -1
  57. package/coverage/lcov-report/api/routes/dev.js.html +1 -1
  58. package/coverage/lcov-report/api/routes/hosting.js.html +1 -1
  59. package/coverage/lcov-report/api/routes/index.html +1 -1
  60. package/coverage/lcov-report/api/routes/index.js.html +1 -1
  61. package/coverage/lcov-report/api/routes/integration.js.html +1 -1
  62. package/coverage/lcov-report/api/routes/layout.js.html +1 -1
  63. package/coverage/lcov-report/api/routes/metadata.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/row.js.html +536 -2
  69. package/coverage/lcov-report/api/routes/screen.js.html +1 -1
  70. package/coverage/lcov-report/api/routes/script.js.html +1 -1
  71. package/coverage/lcov-report/api/routes/static.js.html +1 -1
  72. package/coverage/lcov-report/api/routes/table.js.html +436 -7
  73. package/coverage/lcov-report/api/routes/templates.js.html +1 -1
  74. package/coverage/lcov-report/api/routes/user.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/createRow.js.html +1 -1
  84. package/coverage/lcov-report/automations/steps/delay.js.html +1 -1
  85. package/coverage/lcov-report/automations/steps/deleteRow.js.html +1 -1
  86. package/coverage/lcov-report/automations/steps/discord.js.html +1 -1
  87. package/coverage/lcov-report/automations/steps/executeQuery.js.html +1 -1
  88. package/coverage/lcov-report/automations/steps/executeScript.js.html +1 -1
  89. package/coverage/lcov-report/automations/steps/filter.js.html +1 -1
  90. package/coverage/lcov-report/automations/steps/index.html +1 -1
  91. package/coverage/lcov-report/automations/steps/integromat.js.html +1 -1
  92. package/coverage/lcov-report/automations/steps/outgoingWebhook.js.html +1 -1
  93. package/coverage/lcov-report/automations/steps/queryRows.js.html +1 -1
  94. package/coverage/lcov-report/automations/steps/sendSmtpEmail.js.html +1 -1
  95. package/coverage/lcov-report/automations/steps/serverLog.js.html +1 -1
  96. package/coverage/lcov-report/automations/steps/slack.js.html +1 -1
  97. package/coverage/lcov-report/automations/steps/updateRow.js.html +1 -1
  98. package/coverage/lcov-report/automations/steps/utils.js.html +1 -1
  99. package/coverage/lcov-report/automations/steps/zapier.js.html +1 -1
  100. package/coverage/lcov-report/automations/triggerInfo/app.js.html +1 -1
  101. package/coverage/lcov-report/automations/triggerInfo/cron.js.html +1 -1
  102. package/coverage/lcov-report/automations/triggerInfo/index.html +1 -1
  103. package/coverage/lcov-report/automations/triggerInfo/index.js.html +1 -1
  104. package/coverage/lcov-report/automations/triggerInfo/rowDeleted.js.html +1 -1
  105. package/coverage/lcov-report/automations/triggerInfo/rowSaved.js.html +1 -1
  106. package/coverage/lcov-report/automations/triggerInfo/rowUpdated.js.html +1 -1
  107. package/coverage/lcov-report/automations/triggerInfo/webhook.js.html +1 -1
  108. package/coverage/lcov-report/automations/triggers.js.html +1 -1
  109. package/coverage/lcov-report/automations/utils.js.html +1 -1
  110. package/coverage/lcov-report/constants/index.html +1 -1
  111. package/coverage/lcov-report/constants/index.js.html +1 -1
  112. package/coverage/lcov-report/constants/layouts.js.html +1 -1
  113. package/coverage/lcov-report/constants/screens.js.html +1 -1
  114. package/coverage/lcov-report/db/client.js.html +1 -1
  115. package/coverage/lcov-report/db/inMemoryView.js.html +1 -1
  116. package/coverage/lcov-report/db/index.html +1 -1
  117. package/coverage/lcov-report/db/index.js.html +1 -1
  118. package/coverage/lcov-report/db/linkedRows/LinkController.js.html +1 -1
  119. package/coverage/lcov-report/db/linkedRows/index.html +1 -1
  120. package/coverage/lcov-report/db/linkedRows/index.js.html +1 -1
  121. package/coverage/lcov-report/db/linkedRows/linkUtils.js.html +1 -1
  122. package/coverage/lcov-report/db/newid.js.html +1 -1
  123. package/coverage/lcov-report/db/utils.js.html +1 -1
  124. package/coverage/lcov-report/events/AutomationEmitter.js.html +1 -1
  125. package/coverage/lcov-report/events/index.html +1 -1
  126. package/coverage/lcov-report/events/index.js.html +1 -1
  127. package/coverage/lcov-report/events/utils.js.html +1 -1
  128. package/coverage/lcov-report/index.html +13 -13
  129. package/coverage/lcov-report/integrations/tests/TestConfiguration.js.html +1 -1
  130. package/coverage/lcov-report/integrations/tests/index.html +1 -1
  131. package/coverage/lcov-report/middleware/appInfo.js.html +1 -1
  132. package/coverage/lcov-report/middleware/authorized.js.html +1 -1
  133. package/coverage/lcov-report/middleware/builder.js.html +1 -1
  134. package/coverage/lcov-report/middleware/currentapp.js.html +1 -1
  135. package/coverage/lcov-report/middleware/index.html +1 -1
  136. package/coverage/lcov-report/middleware/joi-validator.js.html +1 -1
  137. package/coverage/lcov-report/middleware/resourceId.js.html +1 -1
  138. package/coverage/lcov-report/middleware/selfhost.js.html +1 -1
  139. package/coverage/lcov-report/middleware/usageQuota.js.html +1 -1
  140. package/coverage/lcov-report/middleware/utils.js.html +1 -1
  141. package/coverage/lcov-report/threads/automation.js.html +1 -1
  142. package/coverage/lcov-report/threads/index.html +1 -1
  143. package/coverage/lcov-report/threads/index.js.html +1 -1
  144. package/coverage/lcov-report/threads/query.js.html +1 -1
  145. package/coverage/lcov-report/utilities/bcrypt.js.html +1 -1
  146. package/coverage/lcov-report/utilities/budibaseDir.js.html +1 -1
  147. package/coverage/lcov-report/utilities/centralPath.js.html +1 -1
  148. package/coverage/lcov-report/utilities/csvParser.js.html +1 -1
  149. package/coverage/lcov-report/utilities/global.js.html +1 -1
  150. package/coverage/lcov-report/utilities/index.html +1 -1
  151. package/coverage/lcov-report/utilities/index.js.html +1 -1
  152. package/coverage/lcov-report/utilities/queue/inMemoryQueue.js.html +1 -1
  153. package/coverage/lcov-report/utilities/queue/index.html +1 -1
  154. package/coverage/lcov-report/utilities/routing/index.html +1 -1
  155. package/coverage/lcov-report/utilities/routing/index.js.html +1 -1
  156. package/coverage/lcov-report/utilities/rowProcessor/index.html +1 -1
  157. package/coverage/lcov-report/utilities/rowProcessor/index.js.html +1 -1
  158. package/coverage/lcov-report/utilities/rowProcessor/utils.js.html +1 -1
  159. package/coverage/lcov-report/utilities/scriptRunner.js.html +1 -1
  160. package/coverage/lcov-report/utilities/security.js.html +1 -1
  161. package/coverage/lcov-report/utilities/statusCodes.js.html +1 -1
  162. package/coverage/lcov-report/utilities/users.js.html +1 -1
  163. package/coverage/lcov-report/utilities/workerRequests.js.html +1 -1
  164. package/coverage/lcov.info +63 -70
  165. package/dist/api/controllers/row/ExternalRequest.js +5 -2
  166. package/dist/api/controllers/table/internal.js +0 -4
  167. package/dist/api/routes/row.js +178 -0
  168. package/dist/api/routes/table.js +148 -5
  169. package/dist/definitions/datasource.js +12 -1
  170. package/dist/integrations/base/sql.js +1 -4
  171. package/dist/integrations/oracle.js +42 -22
  172. package/dist/package.json +10 -6
  173. package/dist/tsconfig.tsbuildinfo +1 -1
  174. package/package.json +11 -7
  175. package/scripts/docs/README.md +31 -0
  176. package/scripts/docs/generate.js +74 -0
  177. package/scripts/docs/toSwagger.js +320 -0
  178. package/scripts/integrations/oracle/docker-compose.yml +1 -1
  179. package/src/api/controllers/row/ExternalRequest.ts +8 -2
  180. package/src/api/controllers/table/internal.js +0 -4
  181. package/src/api/routes/row.js +178 -0
  182. package/src/api/routes/table.js +148 -5
  183. package/src/definitions/datasource.ts +11 -0
  184. package/src/integrations/base/sql.ts +1 -3
  185. package/src/integrations/oracle.ts +41 -35
@@ -7,15 +7,193 @@ const { paramResource, paramSubResource, } = require("../../middleware/resourceI
7
7
  const { PermissionLevels, PermissionTypes, } = require("@budibase/auth/permissions");
8
8
  const router = Router();
9
9
  router
10
+ /**
11
+ * @api {get} /api/:tableId/:rowId/enrich Get an enriched row
12
+ * @apiName Get an enriched row
13
+ * @apiGroup rows
14
+ * @apiPermission table read access
15
+ * @apiDescription This API is only useful when dealing with rows that have relationships.
16
+ * Normally when a row is a returned from the API relationships will only have the structure
17
+ * `{ primaryDisplay: "name", _id: ... }` but this call will return the full related rows
18
+ * for each relationship instead.
19
+ *
20
+ * @apiParam {string} rowId The ID of the row which is to be retrieved and enriched.
21
+ *
22
+ * @apiSuccess {object} row The response body will be the enriched row.
23
+ */
10
24
  .get("/api/:tableId/:rowId/enrich", paramSubResource("tableId", "rowId"), authorized(PermissionTypes.TABLE, PermissionLevels.READ), rowController.fetchEnrichedRow)
25
+ /**
26
+ * @api {get} /api/:tableId/rows Get all rows in a table
27
+ * @apiName Get all rows in a table
28
+ * @apiGroup rows
29
+ * @apiPermission table read access
30
+ * @apiDescription This is a deprecated endpoint that should not be used anymore, instead use the search endpoint.
31
+ * This endpoint gets all of the rows within the specified table - it is not heavily used
32
+ * due to its lack of support for pagination. With SQL tables this will retrieve up to a limit and then
33
+ * will simply stop.
34
+ *
35
+ * @apiParam {string} tableId The ID of the table to retrieve all rows within.
36
+ *
37
+ * @apiSuccess {object[]} rows The response body will be an array of all rows found.
38
+ */
11
39
  .get("/api/:tableId/rows", paramResource("tableId"), authorized(PermissionTypes.TABLE, PermissionLevels.READ), rowController.fetch)
40
+ /**
41
+ * @api {get} /api/:tableId/rows/:rowId Retrieve a single row
42
+ * @apiName Retrieve a single row
43
+ * @apiGroup rows
44
+ * @apiPermission table read access
45
+ * @apiDescription This endpoint retrieves only the specified row. If you wish to retrieve
46
+ * a row by anything other than its _id field, use the search endpoint.
47
+ *
48
+ * @apiParam {string} tableId The ID of the table to retrieve a row from.
49
+ * @apiParam {string} rowId The ID of the row to retrieve.
50
+ *
51
+ * @apiSuccess {object} body The response body will be the row that was found.
52
+ */
12
53
  .get("/api/:tableId/rows/:rowId", paramSubResource("tableId", "rowId"), authorized(PermissionTypes.TABLE, PermissionLevels.READ), rowController.find)
54
+ /**
55
+ * @api {post} /api/:tableId/search Search for rows in a table
56
+ * @apiName Search for rows in a table
57
+ * @apiGroup rows
58
+ * @apiPermission table read access
59
+ * @apiDescription This is the primary method of accessing rows in Budibase, the data provider
60
+ * and data UI in the builder are built atop this. All filtering, sorting and pagination is
61
+ * handled through this, for internal and external (datasource plus, e.g. SQL) tables.
62
+ *
63
+ * @apiParam {string} tableId The ID of the table to retrieve rows from.
64
+ *
65
+ * @apiParam (Body) {boolean} [paginate] If pagination is required then this should be set to true,
66
+ * defaults to false.
67
+ * @apiParam (Body) {object} [query] This contains a set of filters which should be applied, if none
68
+ * specified then the request will be unfiltered. An example with all of the possible query
69
+ * options has been supplied below.
70
+ * @apiParam (Body) {number} [limit] This sets a limit for the number of rows that will be returned,
71
+ * this will be implemented at the database level if supported for performance reasons. This
72
+ * is useful when paginating to set exactly how many rows per page.
73
+ * @apiParam (Body) {string} [bookmark] If pagination is enabled then a bookmark will be returned
74
+ * with each successful search request, this should be supplied back to get the next page.
75
+ * @apiParam (Body) {object} [sort] If sort is desired this should contain the name of the column to
76
+ * sort on.
77
+ * @apiParam (Body) {string} [sortOrder] If sort is enabled then this can be either "descending" or
78
+ * "ascending" as required.
79
+ * @apiParam (Body) {string} [sortType] If sort is enabled then you must specify the type of search
80
+ * being used, either "string" or "number". This is only used for internal tables.
81
+ *
82
+ * @apiParamExample {json} Example:
83
+ * {
84
+ * "tableId": "ta_70260ff0b85c467ca74364aefc46f26d",
85
+ * "query": {
86
+ * "string": {},
87
+ * "fuzzy": {},
88
+ * "range": {
89
+ * "columnName": {
90
+ * "high": 20,
91
+ * "low": 10,
92
+ * }
93
+ * },
94
+ * "equal": {
95
+ * "columnName": "someValue"
96
+ * },
97
+ * "notEqual": {},
98
+ * "empty": {},
99
+ * "notEmpty": {},
100
+ * "contains": {},
101
+ * "notContains": {}
102
+ * "oneOf": {
103
+ * "columnName": ["value"]
104
+ * }
105
+ * },
106
+ * "limit": 10,
107
+ * "sort": "name",
108
+ * "sortOrder": "descending",
109
+ * "sortType": "string",
110
+ * "paginate": true
111
+ * }
112
+ *
113
+ * @apiSuccess {object[]} rows An array of rows that was found based on the supplied parameters.
114
+ * @apiSuccess {boolean} hasNextPage If pagination was enabled then this specifies whether or
115
+ * not there is another page after this request.
116
+ * @apiSuccess {string} bookmark The bookmark to be sent with the next request to get the next
117
+ * page.
118
+ */
13
119
  .post("/api/:tableId/search", paramResource("tableId"), authorized(PermissionTypes.TABLE, PermissionLevels.READ), rowController.search)
14
120
  // DEPRECATED - this is an old API, but for backwards compat it needs to be
15
121
  // supported still
16
122
  .post("/api/search/:tableId/rows", paramResource("tableId"), authorized(PermissionTypes.TABLE, PermissionLevels.READ), rowController.search)
123
+ /**
124
+ * @api {post} /api/:tableId/rows Creates a new row
125
+ * @apiName Creates a new row
126
+ * @apiGroup rows
127
+ * @apiPermission table write access
128
+ * @apiDescription This API will create a new row based on the supplied body. If the
129
+ * body includes an "_id" field then it will update an existing row if the field
130
+ * links to one. Please note that "_id", "_rev" and "tableId" are fields that are
131
+ * already used by Budibase tables and cannot be used for columns.
132
+ *
133
+ * @apiParam {string} tableId The ID of the table to save a row to.
134
+ *
135
+ * @apiParam (Body) {string} [_id] If the row exists already then an ID for the row must be provided.
136
+ * @apiParam (Body) {string} [_rev] If working with an existing row for an internal table its revision
137
+ * must also be provided.
138
+ * @apiParam (Body) {string} tableId The ID of the table should also be specified in the row body itself.
139
+ * @apiParam (Body) {any} [any] Any field supplied in the body will be assessed to see if it matches
140
+ * a column in the specified table. All other fields will be dropped and not stored.
141
+ *
142
+ * @apiSuccess {string} _id The ID of the row that was just saved, if it was just created this
143
+ * is the rows new ID.
144
+ * @apiSuccess {string} [_rev] If saving to an internal table a revision will also be returned.
145
+ * @apiSuccess {object} body The contents of the row that was saved will be returned as well.
146
+ */
17
147
  .post("/api/:tableId/rows", paramResource("tableId"), authorized(PermissionTypes.TABLE, PermissionLevels.WRITE), usage, rowController.save)
148
+ /**
149
+ * @api {patch} /api/:tableId/rows Updates a row
150
+ * @apiName Update a row
151
+ * @apiGroup rows
152
+ * @apiPermission table write access
153
+ * @apiDescription This endpoint is identical to the row creation endpoint but instead it will
154
+ * error if an _id isn't provided, it will only function for existing rows.
155
+ */
18
156
  .patch("/api/:tableId/rows", paramResource("tableId"), authorized(PermissionTypes.TABLE, PermissionLevels.WRITE), rowController.patch)
157
+ /**
158
+ * @api {post} /api/:tableId/rows/validate Validate inputs for a row
159
+ * @apiName Validate inputs for a row
160
+ * @apiGroup rows
161
+ * @apiPermission table write access
162
+ * @apiDescription When attempting to save a row you may want to check if the row is valid
163
+ * given the table schema, this will iterate through all the constraints on the table and
164
+ * check if the request body is valid.
165
+ *
166
+ * @apiParam {string} tableId The ID of the table the row is to be validated for.
167
+ *
168
+ * @apiParam (Body) {any} [any] Any fields provided in the request body will be tested
169
+ * against the table schema and constraints.
170
+ *
171
+ * @apiSuccess {boolean} valid If inputs provided are acceptable within the table schema this
172
+ * will be true, if it is not then then errors property will be populated.
173
+ * @apiSuccess {object} [errors] A key value map of information about fields on the input
174
+ * which do not match the table schema. The key name will be the column names that have breached
175
+ * the schema.
176
+ */
19
177
  .post("/api/:tableId/rows/validate", paramResource("tableId"), authorized(PermissionTypes.TABLE, PermissionLevels.WRITE), rowController.validate)
178
+ /**
179
+ * @api {delete} /api/:tableId/rows Delete rows
180
+ * @apiName Delete rows
181
+ * @apiGroup rows
182
+ * @apiPermission table write access
183
+ * @apiDescription This endpoint can delete a single row, or delete them in a bulk
184
+ * fashion.
185
+ *
186
+ * @apiParam {string} tableId The ID of the table the row is to be deleted from.
187
+ *
188
+ * @apiParam (Body) {object[]} [rows] If bulk deletion is desired then provide the rows in this
189
+ * key of the request body that are to be deleted.
190
+ * @apiParam (Body) {string} [_id] If deleting a single row then provide its ID in this field.
191
+ * @apiParam (Body) {string} [_rev] If deleting a single row from an internal table then provide its
192
+ * revision here.
193
+ *
194
+ * @apiSuccess {object[]|object} body If deleting bulk then the response body will be an array
195
+ * of the deleted rows, if deleting a single row then the body will contain a "row" property which
196
+ * is the deleted row.
197
+ */
20
198
  .delete("/api/:tableId/rows", paramResource("tableId"), authorized(PermissionTypes.TABLE, PermissionLevels.WRITE), usage, rowController.destroy);
21
199
  module.exports = router;
@@ -21,17 +21,160 @@ function generateSaveValidator() {
21
21
  }).unknown(true));
22
22
  }
23
23
  router
24
+ /**
25
+ * @api {get} /api/tables Fetch all tables
26
+ * @apiName Fetch all tables
27
+ * @apiGroup tables
28
+ * @apiPermission table read access
29
+ * @apiDescription This endpoint retrieves all of the tables which have been created in
30
+ * an app. This includes all of the external and internal tables; to tell the difference
31
+ * between these look for the "type" property on each table, either being "internal" or "external".
32
+ *
33
+ * @apiSuccess {object[]} body The response body will be the list of tables that was found - as
34
+ * this does not take any parameters the only error scenario is no access.
35
+ */
24
36
  .get("/api/tables", authorized(BUILDER), tableController.fetch)
37
+ /**
38
+ * @api {get} /api/tables/:id Fetch a single table
39
+ * @apiName Fetch a single table
40
+ * @apiGroup tables
41
+ * @apiPermission table read access
42
+ * @apiDescription Retrieves a single table this could be be internal or external based on
43
+ * the provided table ID.
44
+ *
45
+ * @apiParam {string} id The ID of the table which is to be retrieved.
46
+ *
47
+ * @apiSuccess {object[]} body The response body will be the table that was found.
48
+ */
25
49
  .get("/api/tables/:id", paramResource("id"), authorized(PermissionTypes.TABLE, PermissionLevels.READ), tableController.find)
50
+ /**
51
+ * @api {post} /api/tables Save a table
52
+ * @apiName Save a table
53
+ * @apiGroup tables
54
+ * @apiPermission builder
55
+ * @apiDescription Create or update a table with this endpoint, this will function for both internal
56
+ * external tables.
57
+ *
58
+ * @apiParam (Body) {string} [_id] If updating an existing table then the ID of the table must be specified.
59
+ * @apiParam (Body) {string} [_rev] If updating an existing internal table then the revision must also be specified.
60
+ * @apiParam (Body) {string} type] This should either be "internal" or "external" depending on the table type -
61
+ * this will default to internal.
62
+ * @apiParam (Body) {string} [sourceId] If creating an external table then this should be set to the data source ID. If
63
+ * building an internal table this does not need to be set, although it will be returned as "bb_internal".
64
+ * @apiParam (Body) {string} name The name of the table, this will be used in the UI. To rename the table simply
65
+ * supply the table structure to this endpoint with the name changed.
66
+ * @apiParam (Body) {object} schema A key value object which has all of the columns in the table as the keys in this
67
+ * object. For each column a "type" and "constraints" must be specified, with some types requiring further information.
68
+ * More information about the schema structure can be found in the Typescript definitions.
69
+ * @apiParam (Body) {string} [primaryDisplay] The name of the column which should be used when displaying rows
70
+ * from this table as relationships.
71
+ * @apiParam (Body) {object[]} [indexes] Specifies the search indexes - this is deprecated behaviour with the introduction
72
+ * of lucene indexes. This functionality is only available for internal tables.
73
+ * @apiParam (Body) {object} [_rename] If a column is to be renamed then the "old" column name should be set in this
74
+ * structure, and the "updated", new column name should also be supplied. The schema should also be updated, this field
75
+ * lets the server know that a field hasn't just been deleted, that the data has moved to a new name, this will fix
76
+ * the rows in the table. This functionality is only available for internal tables.
77
+ * @apiParam (Body) {object} [dataImport] When creating an internal table it can be built from a CSV, by using the
78
+ * CSV validation endpoint. Send the CSV data to the validation endpoint, then put the results of that call
79
+ * into this property, along with the CSV and a table/rows will be built from it. This is not supported when updating
80
+ * or for external tables.
81
+ *
82
+ * @apiParamExample {json} Example:
83
+ * {
84
+ * "_id": "ta_05541307fa0f4044abee071ca2a82119",
85
+ * "_rev": "10-0fbe4e78f69b255d79f1017e2eeef807",
86
+ * "type": "internal",
87
+ * "views": {},
88
+ * "name": "tableName",
89
+ * "schema": {
90
+ * "column": {
91
+ * "type": "string",
92
+ * "constraints": {
93
+ * "type": "string",
94
+ * "length": {
95
+ * "maximum": null
96
+ * },
97
+ * "presence": false
98
+ * },
99
+ * "name": "column"
100
+ * },
101
+ * },
102
+ * "primaryDisplay": "column",
103
+ * "indexes": [],
104
+ * "sourceId": "bb_internal",
105
+ * "_rename": {
106
+ * "old": "columnName",
107
+ * "updated": "newColumnName",
108
+ * },
109
+ * "dataImport": {
110
+ * "csvString": "column\nvalue",
111
+ * "primaryDisplay": "column",
112
+ * "schema": {
113
+ * "column": {
114
+ * "type": "string"
115
+ * }
116
+ * }
117
+ * }
118
+ * }
119
+ *
120
+ * @apiSuccess {object} table The response body will contain the table structure after being cleaned up and
121
+ * saved to the database.
122
+ */
26
123
  .post("/api/tables",
27
124
  // allows control over updating a table
28
125
  bodyResource("_id"), authorized(BUILDER), generateSaveValidator(), tableController.save)
126
+ /**
127
+ * @api {post} /api/tables/csv/validate Validate a CSV for a table
128
+ * @apiName Validate a CSV for a table
129
+ * @apiGroup tables
130
+ * @apiPermission builder
131
+ * @apiDescription When creating a new table, or importing a CSV to an existing table the CSV must be validated and
132
+ * converted into a Budibase schema; this endpoint does this.
133
+ *
134
+ * @apiParam (Body) {string} csvString The CSV which is to be validated as a string.
135
+ * @apiParam (Body) {object} [schema] When a CSV has been validated it is possible to re-validate after changing the
136
+ * type of a field, by default everything will be strings as there is no way to infer types. The returned schema can
137
+ * be updated and then returned to the endpoint to re-validate and check if the type will work for the CSV, e.g.
138
+ * using a number instead of strings.
139
+ * @apiParam (Body) {string} [tableId] If importing data to an existing table this will pull the current table and
140
+ * remove any fields from the CSV schema which do not exist on the table/don't match the type of the table. When
141
+ * importing a CSV to an existing table only fields that are present on the table can be imported.
142
+ *
143
+ * @apiSuccess {object} schema The response body will contain a "schema" object that represents the schema found for
144
+ * the CSV - this will be in the same format used for table schema.s
145
+ */
29
146
  .post("/api/tables/csv/validate", authorized(BUILDER), tableController.validateCSVSchema)
147
+ /**
148
+ * @api {post} /api/tables/:tableId/:revId Delete a table
149
+ * @apiName Delete a table
150
+ * @apiGroup tables
151
+ * @apiPermission builder
152
+ * @apiDescription This endpoint will delete a table and all of its associated data, for this reason it is
153
+ * quite dangerous - it will work for internal and external tables.
154
+ *
155
+ * @apiParam {string} tableId The ID of the table which is to be deleted.
156
+ * @apiParam {string} [revId] If deleting an internal table then the revision must also be supplied (_rev), for
157
+ * external tables this can simply be set to anything, e.g. "external".
158
+ *
159
+ * @apiSuccess {string} message A message stating that the table was deleted successfully.
160
+ */
30
161
  .delete("/api/tables/:tableId/:revId", paramResource("tableId"), authorized(BUILDER), tableController.destroy)
31
- // this is currently builder only, but in the future
32
- // it could be carried out by an end user in app,
33
- // however some thought will need to be had about
34
- // implications for automations (triggers)
35
- // new trigger type, bulk rows created
162
+ /**
163
+ * @api {post} /api/tables/:tableId/:revId Import CSV to existing table
164
+ * @apiName Import CSV to existing table
165
+ * @apiGroup tables
166
+ * @apiPermission builder
167
+ * @apiDescription This endpoint will import data to existing tables, internal or external. It is used in combination
168
+ * with the CSV validation endpoint. Take the output of the CSV validation endpoint and pass it to this endpoint to
169
+ * import the data; please note this will only import fields that already exist on the table/match the type.
170
+ *
171
+ * @apiParam {string} tableId The ID of the table which the data should be imported to.
172
+ *
173
+ * @apiParam (Body) {object} dataImport This is the same as the structure used when creating an internal table with
174
+ * a CSV, it will have the "schema" returned from the CSV validation endpoint and the "csvString" which is to be
175
+ * turned into rows.
176
+ *
177
+ * @apiSuccess {string} message A message stating that the data was imported successfully.
178
+ */
36
179
  .post("/api/tables/:tableId/import", paramResource("tableId"), authorized(BUILDER), tableController.bulkImport);
37
180
  module.exports = router;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IncludeRelationships = exports.SourceNames = exports.DatasourceFieldTypes = exports.QueryTypes = exports.SortDirection = exports.Operation = void 0;
3
+ exports.FilterTypes = exports.IncludeRelationships = exports.SourceNames = exports.DatasourceFieldTypes = exports.QueryTypes = exports.SortDirection = exports.Operation = void 0;
4
4
  var Operation;
5
5
  (function (Operation) {
6
6
  Operation["CREATE"] = "CREATE";
@@ -55,3 +55,14 @@ var IncludeRelationships;
55
55
  IncludeRelationships[IncludeRelationships["INCLUDE"] = 1] = "INCLUDE";
56
56
  IncludeRelationships[IncludeRelationships["EXCLUDE"] = 0] = "EXCLUDE";
57
57
  })(IncludeRelationships = exports.IncludeRelationships || (exports.IncludeRelationships = {}));
58
+ var FilterTypes;
59
+ (function (FilterTypes) {
60
+ FilterTypes["STRING"] = "string";
61
+ FilterTypes["FUZZY"] = "fuzzy";
62
+ FilterTypes["RANGE"] = "range";
63
+ FilterTypes["EQUAL"] = "equal";
64
+ FilterTypes["NOT_EQUAL"] = "notEqual";
65
+ FilterTypes["EMPTY"] = "empty";
66
+ FilterTypes["NOT_EMPTY"] = "notEmpty";
67
+ FilterTypes["ONE_OF"] = "oneOf";
68
+ })(FilterTypes = exports.FilterTypes || (exports.FilterTypes = {}));
@@ -84,7 +84,7 @@ class InternalBuilder {
84
84
  if (filters.oneOf) {
85
85
  iterate(filters.oneOf, (key, array) => {
86
86
  const fnc = allOr ? "orWhereIn" : "whereIn";
87
- query = query[fnc](key, array);
87
+ query = query[fnc](key, Array.isArray(array) ? array : [array]);
88
88
  });
89
89
  }
90
90
  if (filters.string) {
@@ -397,9 +397,6 @@ class SqlQueryBuilder extends sqlTable_1.default {
397
397
  else if (sqlClient === utils_1.SqlClients.MY_SQL) {
398
398
  id = results === null || results === void 0 ? void 0 : results.insertId;
399
399
  }
400
- else if (sqlClient === utils_1.SqlClients.ORACLE) {
401
- id = response.outBinds[0][0];
402
- }
403
400
  row = processFn(yield this.getReturningRow(queryFn, this.checkLookupKeys(id, json)));
404
401
  }
405
402
  if (operation !== datasource_1.Operation.READ) {
@@ -262,28 +262,13 @@ var OracleModule;
262
262
  this.schemaErrors = final.errors;
263
263
  });
264
264
  }
265
- /**
266
- * Knex default returning behaviour does not work with oracle
267
- * Manually add the behaviour for the return column
268
- */
269
- addReturning(query, bindings, returnColumn) {
270
- if (bindings instanceof Array) {
271
- bindings.push({ dir: oracledb_1.default.BIND_OUT });
272
- query.sql =
273
- query.sql + ` returning \"${returnColumn}\" into :${bindings.length}`;
274
- }
275
- }
276
- internalQuery(query, returnColum, operation) {
265
+ internalQuery(query) {
277
266
  return __awaiter(this, void 0, void 0, function* () {
278
267
  let connection;
279
268
  try {
280
269
  connection = yield this.getConnection();
281
270
  const options = { autoCommit: true };
282
271
  const bindings = query.bindings || [];
283
- if (returnColum &&
284
- (operation === datasource_1.Operation.CREATE || operation === datasource_1.Operation.UPDATE)) {
285
- this.addReturning(query, bindings, returnColum);
286
- }
287
272
  const result = yield connection.execute(query.sql, bindings, options);
288
273
  return result;
289
274
  }
@@ -330,13 +315,48 @@ var OracleModule;
330
315
  });
331
316
  }
332
317
  query(json) {
318
+ var _a, _b, _c;
333
319
  return __awaiter(this, void 0, void 0, function* () {
334
- const primaryKeys = json.meta.table.primary;
335
- const primaryKey = primaryKeys ? primaryKeys[0] : undefined;
336
- const queryFn = (query, operation) => this.internalQuery(query, primaryKey, operation);
337
- const processFn = (response) => (response.rows ? response.rows : []);
338
- const output = yield this.queryWithReturning(json, queryFn, processFn);
339
- return output;
320
+ const operation = this._operation(json);
321
+ const input = this._query(json, { disableReturning: true });
322
+ if (Array.isArray(input)) {
323
+ const responses = [];
324
+ for (let query of input) {
325
+ responses.push(yield this.internalQuery(query));
326
+ }
327
+ return responses;
328
+ }
329
+ else {
330
+ // read the row to be deleted up front for the return
331
+ let deletedRows;
332
+ if (operation === datasource_1.Operation.DELETE) {
333
+ const queryFn = (query) => this.internalQuery(query);
334
+ deletedRows = yield this.getReturningRow(queryFn, json);
335
+ }
336
+ // run the query
337
+ const response = yield this.internalQuery(input);
338
+ // get the results or return the created / updated / deleted row
339
+ if ((_a = deletedRows === null || deletedRows === void 0 ? void 0 : deletedRows.rows) === null || _a === void 0 ? void 0 : _a.length) {
340
+ return deletedRows.rows;
341
+ }
342
+ else if ((_b = response.rows) === null || _b === void 0 ? void 0 : _b.length) {
343
+ return response.rows;
344
+ }
345
+ else {
346
+ // get the last row that was updated
347
+ if (response.lastRowid &&
348
+ ((_c = json.endpoint) === null || _c === void 0 ? void 0 : _c.entityId) &&
349
+ operation !== datasource_1.Operation.DELETE) {
350
+ const lastRow = yield this.internalQuery({
351
+ sql: `SELECT * FROM \"${json.endpoint.entityId}\" WHERE ROWID = '${response.lastRowid}'`,
352
+ });
353
+ return lastRow.rows;
354
+ }
355
+ else {
356
+ return [{ [operation.toLowerCase()]: true }];
357
+ }
358
+ }
359
+ }
340
360
  });
341
361
  }
342
362
  }
package/dist/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@budibase/server",
3
3
  "email": "hi@budibase.com",
4
- "version": "0.9.190-alpha.6",
4
+ "version": "1.0.0",
5
5
  "description": "Budibase Web Server",
6
- "main": "src/index.js",
6
+ "main": "src/index.ts",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "https://github.com/Budibase/budibase.git"
@@ -15,6 +15,7 @@
15
15
  "test:watch": "jest --watch",
16
16
  "predocker": "copyfiles -f ../client/dist/budibase-client.js ../client/manifest.json client",
17
17
  "build:docker": "yarn run predocker && docker build . -t app-service --label version=$BUDIBASE_RELEASE_VERSION",
18
+ "build:docs": "node ./scripts/docs/generate.js open",
18
19
  "run:docker": "node dist/index.js",
19
20
  "dev:stack:up": "node scripts/dev/manage.js up",
20
21
  "dev:stack:down": "node scripts/dev/manage.js down",
@@ -68,9 +69,9 @@
68
69
  "author": "Budibase",
69
70
  "license": "GPL-3.0",
70
71
  "dependencies": {
71
- "@budibase/auth": "^0.9.190-alpha.6",
72
- "@budibase/client": "^0.9.190-alpha.6",
73
- "@budibase/string-templates": "^0.9.190-alpha.6",
72
+ "@budibase/auth": "^1.0.0",
73
+ "@budibase/client": "^1.0.0",
74
+ "@budibase/string-templates": "^1.0.0",
74
75
  "@bull-board/api": "^3.7.0",
75
76
  "@bull-board/koa": "^3.7.0",
76
77
  "@elastic/elasticsearch": "7.10.0",
@@ -106,7 +107,7 @@
106
107
  "mssql": "6.2.3",
107
108
  "mysql2": "^2.3.1",
108
109
  "node-fetch": "2.6.0",
109
- "open": "7.3.0",
110
+ "open": "^8.4.0",
110
111
  "pg": "8.5.1",
111
112
  "pino-pretty": "4.0.0",
112
113
  "posthog-node": "^1.1.4",
@@ -130,6 +131,7 @@
130
131
  "@babel/preset-env": "^7.14.4",
131
132
  "@budibase/standard-components": "^0.9.139",
132
133
  "@jest/test-sequencer": "^24.8.0",
134
+ "@types/apidoc": "^0.50.0",
133
135
  "@types/bull": "^3.15.1",
134
136
  "@types/jest": "^26.0.23",
135
137
  "@types/koa": "^2.13.3",
@@ -137,12 +139,14 @@
137
139
  "@types/node": "^15.12.4",
138
140
  "@types/oracledb": "^5.2.1",
139
141
  "@typescript-eslint/parser": "4.28.0",
142
+ "apidoc": "^0.50.2",
140
143
  "babel-jest": "^27.0.2",
141
144
  "copyfiles": "^2.4.1",
142
145
  "docker-compose": "^0.23.6",
143
146
  "eslint": "^6.8.0",
144
147
  "jest": "^27.0.5",
145
148
  "nodemon": "^2.0.4",
149
+ "path-to-regexp": "^6.2.0",
146
150
  "prettier": "^2.3.1",
147
151
  "rimraf": "^3.0.2",
148
152
  "supertest": "^4.0.2",