@budibase/server 2.3.18-alpha.13 → 2.3.18-alpha.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/builder/assets/{index.5db9630c.js → index.b0911233.js} +352 -351
- package/builder/assets/{index.d4b6aa43.css → index.ca370ee3.css} +2 -2
- package/builder/index.html +2 -2
- package/dist/api/controllers/row/ExternalRequest.js +2 -2
- package/dist/api/controllers/row/internalSearch.js +6 -450
- package/dist/api/controllers/row/utils.js +1 -3
- package/dist/app.js +2 -0
- package/dist/db/index.js +25 -2
- package/dist/db/utils.js +2 -5
- package/dist/db/views/staticViews.js +2 -1
- package/dist/integrations/base/sql.js +2 -2
- package/dist/integrations/googlesheets.js +1 -1
- package/dist/package.json +7 -6
- package/dist/startup.js +3 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/jest.config.ts +1 -0
- package/package.json +8 -7
- package/src/api/controllers/row/ExternalRequest.ts +2 -3
- package/src/api/controllers/row/internalSearch.ts +11 -524
- package/src/api/controllers/row/utils.ts +1 -2
- package/src/app.ts +2 -0
- package/src/db/index.ts +2 -2
- package/src/db/utils.ts +0 -4
- package/src/db/views/staticViews.ts +3 -3
- package/src/integrations/base/sql.ts +2 -2
- package/src/integrations/googlesheets.ts +1 -1
- package/src/startup.ts +4 -1
- package/dist/integrations/base/utils.js +0 -16
- package/src/integrations/base/utils.ts +0 -12
package/builder/index.html
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@400;600;700&display=swap"
|
|
11
11
|
rel="stylesheet"
|
|
12
12
|
/>
|
|
13
|
-
<script type="module" crossorigin src="/builder/assets/index.
|
|
14
|
-
<link rel="stylesheet" href="/builder/assets/index.
|
|
13
|
+
<script type="module" crossorigin src="/builder/assets/index.b0911233.js"></script>
|
|
14
|
+
<link rel="stylesheet" href="/builder/assets/index.ca370ee3.css">
|
|
15
15
|
</head>
|
|
16
16
|
<body id="app">
|
|
17
17
|
|
|
@@ -32,7 +32,7 @@ const utils_3 = require("../../../integrations/utils");
|
|
|
32
32
|
const string_templates_1 = require("@budibase/string-templates");
|
|
33
33
|
const fp_1 = require("lodash/fp");
|
|
34
34
|
const rowProcessor_1 = require("../../../utilities/rowProcessor");
|
|
35
|
-
const
|
|
35
|
+
const backend_core_1 = require("@budibase/backend-core");
|
|
36
36
|
const sdk_1 = __importDefault(require("../../../sdk"));
|
|
37
37
|
function buildFilters(id, filters, table) {
|
|
38
38
|
const primary = table.primary;
|
|
@@ -43,7 +43,7 @@ function buildFilters(id, filters, table) {
|
|
|
43
43
|
let prefix = 1;
|
|
44
44
|
for (let operator of Object.values(filters)) {
|
|
45
45
|
for (let field of Object.keys(operator || {})) {
|
|
46
|
-
if (
|
|
46
|
+
if (backend_core_1.db.removeKeyNumbering(field) === "_id") {
|
|
47
47
|
if (primary) {
|
|
48
48
|
const parts = (0, utils_1.breakRowIdField)(operator[field]);
|
|
49
49
|
for (let field of primary) {
|
|
@@ -8,465 +8,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.fullSearch = exports.paginatedSearch =
|
|
16
|
-
const utils_1 = require("../../../db/utils");
|
|
17
|
-
const utils_2 = require("./utils");
|
|
18
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
12
|
+
exports.fullSearch = exports.paginatedSearch = void 0;
|
|
19
13
|
const backend_core_1 = require("@budibase/backend-core");
|
|
20
|
-
|
|
21
|
-
* Class to build lucene query URLs.
|
|
22
|
-
* Optionally takes a base lucene query object.
|
|
23
|
-
*/
|
|
24
|
-
class QueryBuilder {
|
|
25
|
-
constructor(base) {
|
|
26
|
-
this.query = Object.assign({ allOr: false, string: {}, fuzzy: {}, range: {}, equal: {}, notEqual: {}, empty: {}, notEmpty: {}, oneOf: {}, contains: {}, notContains: {}, containsAny: {} }, base);
|
|
27
|
-
this.limit = 50;
|
|
28
|
-
this.sortOrder = "ascending";
|
|
29
|
-
this.sortType = "string";
|
|
30
|
-
this.includeDocs = true;
|
|
31
|
-
}
|
|
32
|
-
setVersion(version) {
|
|
33
|
-
if (version != null) {
|
|
34
|
-
this.version = version;
|
|
35
|
-
}
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
setTable(tableId) {
|
|
39
|
-
this.query.equal.tableId = tableId;
|
|
40
|
-
return this;
|
|
41
|
-
}
|
|
42
|
-
setLimit(limit) {
|
|
43
|
-
if (limit != null) {
|
|
44
|
-
this.limit = limit;
|
|
45
|
-
}
|
|
46
|
-
return this;
|
|
47
|
-
}
|
|
48
|
-
setSort(sort) {
|
|
49
|
-
if (sort != null) {
|
|
50
|
-
this.sort = sort;
|
|
51
|
-
}
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
setSortOrder(sortOrder) {
|
|
55
|
-
if (sortOrder != null) {
|
|
56
|
-
this.sortOrder = sortOrder;
|
|
57
|
-
}
|
|
58
|
-
return this;
|
|
59
|
-
}
|
|
60
|
-
setSortType(sortType) {
|
|
61
|
-
if (sortType != null) {
|
|
62
|
-
this.sortType = sortType;
|
|
63
|
-
}
|
|
64
|
-
return this;
|
|
65
|
-
}
|
|
66
|
-
setBookmark(bookmark) {
|
|
67
|
-
if (bookmark != null) {
|
|
68
|
-
this.bookmark = bookmark;
|
|
69
|
-
}
|
|
70
|
-
return this;
|
|
71
|
-
}
|
|
72
|
-
excludeDocs() {
|
|
73
|
-
this.includeDocs = false;
|
|
74
|
-
return this;
|
|
75
|
-
}
|
|
76
|
-
addString(key, partial) {
|
|
77
|
-
this.query.string[key] = partial;
|
|
78
|
-
return this;
|
|
79
|
-
}
|
|
80
|
-
addFuzzy(key, fuzzy) {
|
|
81
|
-
this.query.fuzzy[key] = fuzzy;
|
|
82
|
-
return this;
|
|
83
|
-
}
|
|
84
|
-
addRange(key, low, high) {
|
|
85
|
-
this.query.range[key] = {
|
|
86
|
-
low,
|
|
87
|
-
high,
|
|
88
|
-
};
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
addEqual(key, value) {
|
|
92
|
-
this.query.equal[key] = value;
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
addNotEqual(key, value) {
|
|
96
|
-
this.query.notEqual[key] = value;
|
|
97
|
-
return this;
|
|
98
|
-
}
|
|
99
|
-
addEmpty(key, value) {
|
|
100
|
-
this.query.empty[key] = value;
|
|
101
|
-
return this;
|
|
102
|
-
}
|
|
103
|
-
addNotEmpty(key, value) {
|
|
104
|
-
this.query.notEmpty[key] = value;
|
|
105
|
-
return this;
|
|
106
|
-
}
|
|
107
|
-
addOneOf(key, value) {
|
|
108
|
-
this.query.oneOf[key] = value;
|
|
109
|
-
return this;
|
|
110
|
-
}
|
|
111
|
-
addContains(key, value) {
|
|
112
|
-
this.query.contains[key] = value;
|
|
113
|
-
return this;
|
|
114
|
-
}
|
|
115
|
-
addNotContains(key, value) {
|
|
116
|
-
this.query.notContains[key] = value;
|
|
117
|
-
return this;
|
|
118
|
-
}
|
|
119
|
-
addContainsAny(key, value) {
|
|
120
|
-
this.query.containsAny[key] = value;
|
|
121
|
-
return this;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Preprocesses a value before going into a lucene search.
|
|
125
|
-
* Transforms strings to lowercase and wraps strings and bools in quotes.
|
|
126
|
-
* @param value The value to process
|
|
127
|
-
* @param options The preprocess options
|
|
128
|
-
* @returns {string|*}
|
|
129
|
-
*/
|
|
130
|
-
preprocess(value, { escape, lowercase, wrap, type } = {}) {
|
|
131
|
-
const hasVersion = !!this.version;
|
|
132
|
-
// Determine if type needs wrapped
|
|
133
|
-
const originalType = typeof value;
|
|
134
|
-
// Convert to lowercase
|
|
135
|
-
if (value && lowercase) {
|
|
136
|
-
value = value.toLowerCase ? value.toLowerCase() : value;
|
|
137
|
-
}
|
|
138
|
-
// Escape characters
|
|
139
|
-
if (escape && originalType === "string") {
|
|
140
|
-
value = `${value}`.replace(/[ #+\-&|!(){}\]^"~*?:\\]/g, "\\$&");
|
|
141
|
-
}
|
|
142
|
-
// Wrap in quotes
|
|
143
|
-
if (originalType === "string" && !isNaN(value) && !type) {
|
|
144
|
-
value = `"${value}"`;
|
|
145
|
-
}
|
|
146
|
-
else if (hasVersion && wrap) {
|
|
147
|
-
value = originalType === "number" ? value : `"${value}"`;
|
|
148
|
-
}
|
|
149
|
-
return value;
|
|
150
|
-
}
|
|
151
|
-
buildSearchQuery() {
|
|
152
|
-
const builder = this;
|
|
153
|
-
let allOr = this.query && this.query.allOr;
|
|
154
|
-
let query = allOr ? "" : "*:*";
|
|
155
|
-
const allPreProcessingOpts = { escape: true, lowercase: true, wrap: true };
|
|
156
|
-
let tableId;
|
|
157
|
-
if (this.query.equal.tableId) {
|
|
158
|
-
tableId = this.query.equal.tableId;
|
|
159
|
-
delete this.query.equal.tableId;
|
|
160
|
-
}
|
|
161
|
-
const equal = (key, value) => {
|
|
162
|
-
// 0 evaluates to false, which means we would return all rows if we don't check it
|
|
163
|
-
if (!value && value !== 0) {
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
166
|
-
return `${key}:${builder.preprocess(value, allPreProcessingOpts)}`;
|
|
167
|
-
};
|
|
168
|
-
const contains = (key, value, mode = "AND") => {
|
|
169
|
-
if (Array.isArray(value) && value.length === 0) {
|
|
170
|
-
return null;
|
|
171
|
-
}
|
|
172
|
-
if (!Array.isArray(value)) {
|
|
173
|
-
return `${key}:${value}`;
|
|
174
|
-
}
|
|
175
|
-
let statement = `${builder.preprocess(value[0], { escape: true })}`;
|
|
176
|
-
for (let i = 1; i < value.length; i++) {
|
|
177
|
-
statement += ` ${mode} ${builder.preprocess(value[i], {
|
|
178
|
-
escape: true,
|
|
179
|
-
})}`;
|
|
180
|
-
}
|
|
181
|
-
return `${key}:(${statement})`;
|
|
182
|
-
};
|
|
183
|
-
const notContains = (key, value) => {
|
|
184
|
-
// @ts-ignore
|
|
185
|
-
const allPrefix = allOr === "" ? "*:* AND" : "";
|
|
186
|
-
return allPrefix + "NOT " + contains(key, value);
|
|
187
|
-
};
|
|
188
|
-
const containsAny = (key, value) => {
|
|
189
|
-
return contains(key, value, "OR");
|
|
190
|
-
};
|
|
191
|
-
const oneOf = (key, value) => {
|
|
192
|
-
if (!Array.isArray(value)) {
|
|
193
|
-
if (typeof value === "string") {
|
|
194
|
-
value = value.split(",");
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
return "";
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
let orStatement = `${builder.preprocess(value[0], allPreProcessingOpts)}`;
|
|
201
|
-
for (let i = 1; i < value.length; i++) {
|
|
202
|
-
orStatement += ` OR ${builder.preprocess(value[i], allPreProcessingOpts)}`;
|
|
203
|
-
}
|
|
204
|
-
return `${key}:(${orStatement})`;
|
|
205
|
-
};
|
|
206
|
-
function build(structure, queryFn) {
|
|
207
|
-
for (let [key, value] of Object.entries(structure)) {
|
|
208
|
-
// check for new format - remove numbering if needed
|
|
209
|
-
key = (0, utils_2.removeKeyNumbering)(key);
|
|
210
|
-
key = builder.preprocess(key.replace(/ /g, "_"), {
|
|
211
|
-
escape: true,
|
|
212
|
-
});
|
|
213
|
-
const expression = queryFn(key, value);
|
|
214
|
-
if (expression == null) {
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
if (query.length > 0) {
|
|
218
|
-
query += ` ${allOr ? "OR" : "AND"} `;
|
|
219
|
-
}
|
|
220
|
-
query += expression;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
// Construct the actual lucene search query string from JSON structure
|
|
224
|
-
if (this.query.string) {
|
|
225
|
-
build(this.query.string, (key, value) => {
|
|
226
|
-
if (!value) {
|
|
227
|
-
return null;
|
|
228
|
-
}
|
|
229
|
-
value = builder.preprocess(value, {
|
|
230
|
-
escape: true,
|
|
231
|
-
lowercase: true,
|
|
232
|
-
type: "string",
|
|
233
|
-
});
|
|
234
|
-
return `${key}:${value}*`;
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
if (this.query.range) {
|
|
238
|
-
build(this.query.range, (key, value) => {
|
|
239
|
-
if (!value) {
|
|
240
|
-
return null;
|
|
241
|
-
}
|
|
242
|
-
if (value.low == null || value.low === "") {
|
|
243
|
-
return null;
|
|
244
|
-
}
|
|
245
|
-
if (value.high == null || value.high === "") {
|
|
246
|
-
return null;
|
|
247
|
-
}
|
|
248
|
-
const low = builder.preprocess(value.low, allPreProcessingOpts);
|
|
249
|
-
const high = builder.preprocess(value.high, allPreProcessingOpts);
|
|
250
|
-
return `${key}:[${low} TO ${high}]`;
|
|
251
|
-
});
|
|
252
|
-
}
|
|
253
|
-
if (this.query.fuzzy) {
|
|
254
|
-
build(this.query.fuzzy, (key, value) => {
|
|
255
|
-
if (!value) {
|
|
256
|
-
return null;
|
|
257
|
-
}
|
|
258
|
-
value = builder.preprocess(value, {
|
|
259
|
-
escape: true,
|
|
260
|
-
lowercase: true,
|
|
261
|
-
type: "fuzzy",
|
|
262
|
-
});
|
|
263
|
-
return `${key}:${value}~`;
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
if (this.query.equal) {
|
|
267
|
-
build(this.query.equal, equal);
|
|
268
|
-
}
|
|
269
|
-
if (this.query.notEqual) {
|
|
270
|
-
build(this.query.notEqual, (key, value) => {
|
|
271
|
-
if (!value) {
|
|
272
|
-
return null;
|
|
273
|
-
}
|
|
274
|
-
return `!${key}:${builder.preprocess(value, allPreProcessingOpts)}`;
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
if (this.query.empty) {
|
|
278
|
-
build(this.query.empty, (key) => `!${key}:["" TO *]`);
|
|
279
|
-
}
|
|
280
|
-
if (this.query.notEmpty) {
|
|
281
|
-
build(this.query.notEmpty, (key) => `${key}:["" TO *]`);
|
|
282
|
-
}
|
|
283
|
-
if (this.query.oneOf) {
|
|
284
|
-
build(this.query.oneOf, oneOf);
|
|
285
|
-
}
|
|
286
|
-
if (this.query.contains) {
|
|
287
|
-
build(this.query.contains, contains);
|
|
288
|
-
}
|
|
289
|
-
if (this.query.notContains) {
|
|
290
|
-
build(this.query.notContains, notContains);
|
|
291
|
-
}
|
|
292
|
-
if (this.query.containsAny) {
|
|
293
|
-
build(this.query.containsAny, containsAny);
|
|
294
|
-
}
|
|
295
|
-
// make sure table ID is always added as an AND
|
|
296
|
-
if (tableId) {
|
|
297
|
-
query = `(${query})`;
|
|
298
|
-
allOr = false;
|
|
299
|
-
build({ tableId }, equal);
|
|
300
|
-
}
|
|
301
|
-
return query;
|
|
302
|
-
}
|
|
303
|
-
buildSearchBody() {
|
|
304
|
-
let body = {
|
|
305
|
-
q: this.buildSearchQuery(),
|
|
306
|
-
limit: Math.min(this.limit, 200),
|
|
307
|
-
include_docs: this.includeDocs,
|
|
308
|
-
};
|
|
309
|
-
if (this.bookmark) {
|
|
310
|
-
body.bookmark = this.bookmark;
|
|
311
|
-
}
|
|
312
|
-
if (this.sort) {
|
|
313
|
-
const order = this.sortOrder === "descending" ? "-" : "";
|
|
314
|
-
const type = `<${this.sortType}>`;
|
|
315
|
-
body.sort = `${order}${this.sort.replace(/ /g, "_")}${type}`;
|
|
316
|
-
}
|
|
317
|
-
return body;
|
|
318
|
-
}
|
|
319
|
-
run() {
|
|
320
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
321
|
-
const appId = backend_core_1.context.getAppId();
|
|
322
|
-
const { url, cookie } = backend_core_1.db.getCouchInfo();
|
|
323
|
-
const fullPath = `${url}/${appId}/_design/database/_search/${utils_1.SearchIndexes.ROWS}`;
|
|
324
|
-
const body = this.buildSearchBody();
|
|
325
|
-
return yield runQuery(fullPath, body, cookie);
|
|
326
|
-
});
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
exports.QueryBuilder = QueryBuilder;
|
|
330
|
-
/**
|
|
331
|
-
* Executes a lucene search query.
|
|
332
|
-
* @param url The query URL
|
|
333
|
-
* @param body The request body defining search criteria
|
|
334
|
-
* @param cookie The auth cookie for CouchDB
|
|
335
|
-
* @returns {Promise<{rows: []}>}
|
|
336
|
-
*/
|
|
337
|
-
const runQuery = (url, body, cookie) => __awaiter(void 0, void 0, void 0, function* () {
|
|
338
|
-
const response = yield (0, node_fetch_1.default)(url, {
|
|
339
|
-
body: JSON.stringify(body),
|
|
340
|
-
method: "POST",
|
|
341
|
-
headers: {
|
|
342
|
-
Authorization: cookie,
|
|
343
|
-
},
|
|
344
|
-
});
|
|
345
|
-
const json = yield response.json();
|
|
346
|
-
let output = {
|
|
347
|
-
rows: [],
|
|
348
|
-
};
|
|
349
|
-
if (json.rows != null && json.rows.length > 0) {
|
|
350
|
-
output.rows = json.rows.map((row) => row.doc);
|
|
351
|
-
}
|
|
352
|
-
if (json.bookmark) {
|
|
353
|
-
output.bookmark = json.bookmark;
|
|
354
|
-
}
|
|
355
|
-
return output;
|
|
356
|
-
});
|
|
357
|
-
/**
|
|
358
|
-
* Gets round the fixed limit of 200 results from a query by fetching as many
|
|
359
|
-
* pages as required and concatenating the results. This recursively operates
|
|
360
|
-
* until enough results have been found.
|
|
361
|
-
* @param query {object} The JSON query structure
|
|
362
|
-
* @param params {object} The search params including:
|
|
363
|
-
* tableId {string} The table ID to search
|
|
364
|
-
* sort {string} The sort column
|
|
365
|
-
* sortOrder {string} The sort order ("ascending" or "descending")
|
|
366
|
-
* sortType {string} Whether to treat sortable values as strings or
|
|
367
|
-
* numbers. ("string" or "number")
|
|
368
|
-
* limit {number} The number of results to fetch
|
|
369
|
-
* bookmark {string|null} Current bookmark in the recursive search
|
|
370
|
-
* rows {array|null} Current results in the recursive search
|
|
371
|
-
* @returns {Promise<*[]|*>}
|
|
372
|
-
*/
|
|
373
|
-
function recursiveSearch(query, params) {
|
|
374
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
375
|
-
const bookmark = params.bookmark;
|
|
376
|
-
const rows = params.rows || [];
|
|
377
|
-
if (rows.length >= params.limit) {
|
|
378
|
-
return rows;
|
|
379
|
-
}
|
|
380
|
-
let pageSize = 200;
|
|
381
|
-
if (rows.length > params.limit - 200) {
|
|
382
|
-
pageSize = params.limit - rows.length;
|
|
383
|
-
}
|
|
384
|
-
const page = yield new QueryBuilder(query)
|
|
385
|
-
.setVersion(params.version)
|
|
386
|
-
.setTable(params.tableId)
|
|
387
|
-
.setBookmark(bookmark)
|
|
388
|
-
.setLimit(pageSize)
|
|
389
|
-
.setSort(params.sort)
|
|
390
|
-
.setSortOrder(params.sortOrder)
|
|
391
|
-
.setSortType(params.sortType)
|
|
392
|
-
.run();
|
|
393
|
-
if (!page.rows.length) {
|
|
394
|
-
return rows;
|
|
395
|
-
}
|
|
396
|
-
if (page.rows.length < 200) {
|
|
397
|
-
return [...rows, ...page.rows];
|
|
398
|
-
}
|
|
399
|
-
const newParams = Object.assign(Object.assign({}, params), { bookmark: page.bookmark, rows: [...rows, ...page.rows] });
|
|
400
|
-
return yield recursiveSearch(query, newParams);
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
/**
|
|
404
|
-
* Performs a paginated search. A bookmark will be returned to allow the next
|
|
405
|
-
* page to be fetched. There is a max limit off 200 results per page in a
|
|
406
|
-
* paginated search.
|
|
407
|
-
* @param query {object} The JSON query structure
|
|
408
|
-
* @param params {object} The search params including:
|
|
409
|
-
* tableId {string} The table ID to search
|
|
410
|
-
* sort {string} The sort column
|
|
411
|
-
* sortOrder {string} The sort order ("ascending" or "descending")
|
|
412
|
-
* sortType {string} Whether to treat sortable values as strings or
|
|
413
|
-
* numbers. ("string" or "number")
|
|
414
|
-
* limit {number} The desired page size
|
|
415
|
-
* bookmark {string} The bookmark to resume from
|
|
416
|
-
* @returns {Promise<{hasNextPage: boolean, rows: *[]}>}
|
|
417
|
-
*/
|
|
14
|
+
const types_1 = require("@budibase/types");
|
|
418
15
|
function paginatedSearch(query, params) {
|
|
419
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
limit = 50;
|
|
423
|
-
}
|
|
424
|
-
limit = Math.min(limit, 200);
|
|
425
|
-
const search = new QueryBuilder(query)
|
|
426
|
-
.setVersion(params.version)
|
|
427
|
-
.setTable(params.tableId)
|
|
428
|
-
.setSort(params.sort)
|
|
429
|
-
.setSortOrder(params.sortOrder)
|
|
430
|
-
.setSortType(params.sortType);
|
|
431
|
-
const searchResults = yield search
|
|
432
|
-
.setBookmark(params.bookmark)
|
|
433
|
-
.setLimit(limit)
|
|
434
|
-
.run();
|
|
435
|
-
// Try fetching 1 row in the next page to see if another page of results
|
|
436
|
-
// exists or not
|
|
437
|
-
const nextResults = yield search
|
|
438
|
-
.setTable(params.tableId)
|
|
439
|
-
.setBookmark(searchResults.bookmark)
|
|
440
|
-
.setLimit(1)
|
|
441
|
-
.run();
|
|
442
|
-
return Object.assign(Object.assign({}, searchResults), { hasNextPage: nextResults.rows && nextResults.rows.length > 0 });
|
|
17
|
+
const appId = backend_core_1.context.getAppId();
|
|
18
|
+
return backend_core_1.db.paginatedSearch(appId, types_1.SearchIndex.ROWS, query, params);
|
|
443
19
|
});
|
|
444
20
|
}
|
|
445
21
|
exports.paginatedSearch = paginatedSearch;
|
|
446
|
-
/**
|
|
447
|
-
* Performs a full search, fetching multiple pages if required to return the
|
|
448
|
-
* desired amount of results. There is a limit of 1000 results to avoid
|
|
449
|
-
* heavy performance hits, and to avoid client components breaking from
|
|
450
|
-
* handling too much data.
|
|
451
|
-
* @param query {object} The JSON query structure
|
|
452
|
-
* @param params {object} The search params including:
|
|
453
|
-
* tableId {string} The table ID to search
|
|
454
|
-
* sort {string} The sort column
|
|
455
|
-
* sortOrder {string} The sort order ("ascending" or "descending")
|
|
456
|
-
* sortType {string} Whether to treat sortable values as strings or
|
|
457
|
-
* numbers. ("string" or "number")
|
|
458
|
-
* limit {number} The desired number of results
|
|
459
|
-
* @returns {Promise<{rows: *}>}
|
|
460
|
-
*/
|
|
461
22
|
function fullSearch(query, params) {
|
|
462
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
limit = 1000;
|
|
466
|
-
}
|
|
467
|
-
params.limit = Math.min(limit, 1000);
|
|
468
|
-
const rows = yield recursiveSearch(query, params);
|
|
469
|
-
return { rows };
|
|
24
|
+
const appId = backend_core_1.context.getAppId();
|
|
25
|
+
return backend_core_1.db.fullSearch(appId, types_1.SearchIndex.ROWS, query, params);
|
|
470
26
|
});
|
|
471
27
|
}
|
|
472
28
|
exports.fullSearch = fullSearch;
|
|
@@ -35,14 +35,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.cleanExportRows = exports.validate = exports.findRow = exports.getDatasourceAndQuery =
|
|
38
|
+
exports.cleanExportRows = exports.validate = exports.findRow = exports.getDatasourceAndQuery = void 0;
|
|
39
39
|
const utils_1 = require("../../../db/utils");
|
|
40
40
|
const userController = __importStar(require("../user"));
|
|
41
41
|
const constants_1 = require("../../../constants");
|
|
42
42
|
const backend_core_1 = require("@budibase/backend-core");
|
|
43
43
|
const query_1 = require("../../../integrations/base/query");
|
|
44
|
-
var utils_2 = require("../../../integrations/base/utils");
|
|
45
|
-
Object.defineProperty(exports, "removeKeyNumbering", { enumerable: true, get: function () { return utils_2.removeKeyNumbering; } });
|
|
46
44
|
const validateJs = require("validate.js");
|
|
47
45
|
const { cloneDeep } = require("lodash/fp");
|
|
48
46
|
const exporters_1 = require("../view/exporters");
|
package/dist/app.js
CHANGED
|
@@ -64,6 +64,7 @@ const websocket_1 = require("./websocket");
|
|
|
64
64
|
const startup_1 = require("./startup");
|
|
65
65
|
const Sentry = require("@sentry/node");
|
|
66
66
|
const destroyable = require("server-destroy");
|
|
67
|
+
const { userAgent } = require("koa-useragent");
|
|
67
68
|
const app = new koa_1.default();
|
|
68
69
|
let mbNumber = parseInt(environment_1.default.HTTP_MB_LIMIT || "10");
|
|
69
70
|
if (!mbNumber || isNaN(mbNumber)) {
|
|
@@ -80,6 +81,7 @@ app.use((0, koa_body_1.default)({
|
|
|
80
81
|
parsedMethods: ["POST", "PUT", "PATCH", "DELETE"],
|
|
81
82
|
}));
|
|
82
83
|
app.use(backend_core_1.middleware.logging);
|
|
84
|
+
app.use(userAgent);
|
|
83
85
|
if (environment_1.default.isProd()) {
|
|
84
86
|
environment_1.default._set("NODE_ENV", "production");
|
|
85
87
|
Sentry.init();
|
package/dist/db/index.js
CHANGED
|
@@ -1,10 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
27
|
};
|
|
5
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
29
|
exports.init = void 0;
|
|
7
|
-
const
|
|
30
|
+
const core = __importStar(require("@budibase/backend-core"));
|
|
8
31
|
const environment_1 = __importDefault(require("../environment"));
|
|
9
32
|
function init() {
|
|
10
33
|
const dbConfig = {
|
|
@@ -15,6 +38,6 @@ function init() {
|
|
|
15
38
|
dbConfig.inMemory = true;
|
|
16
39
|
dbConfig.allDbs = true;
|
|
17
40
|
}
|
|
18
|
-
|
|
41
|
+
core.init({ db: dbConfig });
|
|
19
42
|
}
|
|
20
43
|
exports.init = init;
|
package/dist/db/utils.js
CHANGED
|
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.generateMemoryViewID = exports.getMetadataParams = exports.generateMetadataID = exports.generateUserFlagID = exports.getQueryParams = exports.getAutomationMetadataParams = exports.generateAutomationMetadataID = exports.generateQueryID = exports.getDatasourceParams = exports.generateDatasourceID = exports.getWebhookParams = exports.generateWebhookID = exports.getScreenParams = exports.generateScreenID = exports.getLayoutParams = exports.generateLayoutID = exports.getLinkParams = exports.generateLinkID = exports.generateAutomationID = exports.getAutomationParams = exports.getTableIDFromRowID = exports.generateTableID = exports.getTableParams = exports.getGlobalIDFromUserMetadataID = exports.generateUserMetadataID = exports.getUserMetadataParams = exports.generateRowID = exports.getRowParams = exports.getDocParams = exports.getQueryIndex = exports.getRoleParams = exports.generateRoleID = exports.generateDevAppID = exports.generateAppID = exports.UNICODE_MAX = exports.InternalTables = exports.ViewName = exports.TABLE_ROW_PREFIX = exports.LINK_USER_METADATA_PREFIX = exports.USER_METDATA_PREFIX = exports.isProdAppID = exports.isDevAppID = exports.APP_DEV_PREFIX = exports.APP_PREFIX = exports.DocumentType = exports.StaticDatabases = exports.SEPARATOR = exports.BudibaseInternalDB = exports.
|
|
7
|
-
exports.getMultiIDParams = exports.generatePluginID =
|
|
6
|
+
exports.getMemoryViewParams = exports.generateMemoryViewID = exports.getMetadataParams = exports.generateMetadataID = exports.generateUserFlagID = exports.getQueryParams = exports.getAutomationMetadataParams = exports.generateAutomationMetadataID = exports.generateQueryID = exports.getDatasourceParams = exports.generateDatasourceID = exports.getWebhookParams = exports.generateWebhookID = exports.getScreenParams = exports.generateScreenID = exports.getLayoutParams = exports.generateLayoutID = exports.getLinkParams = exports.generateLinkID = exports.generateAutomationID = exports.getAutomationParams = exports.getTableIDFromRowID = exports.generateTableID = exports.getTableParams = exports.getGlobalIDFromUserMetadataID = exports.generateUserMetadataID = exports.getUserMetadataParams = exports.generateRowID = exports.getRowParams = exports.getDocParams = exports.getQueryIndex = exports.getRoleParams = exports.generateRoleID = exports.generateDevAppID = exports.generateAppID = exports.UNICODE_MAX = exports.InternalTables = exports.ViewName = exports.TABLE_ROW_PREFIX = exports.LINK_USER_METADATA_PREFIX = exports.USER_METDATA_PREFIX = exports.isProdAppID = exports.isDevAppID = exports.APP_DEV_PREFIX = exports.APP_PREFIX = exports.DocumentType = exports.StaticDatabases = exports.SEPARATOR = exports.BudibaseInternalDB = exports.AppStatus = void 0;
|
|
7
|
+
exports.getMultiIDParams = exports.generatePluginID = void 0;
|
|
8
8
|
const newid_1 = __importDefault(require("./newid"));
|
|
9
9
|
const backend_core_1 = require("@budibase/backend-core");
|
|
10
10
|
exports.AppStatus = {
|
|
@@ -12,9 +12,6 @@ exports.AppStatus = {
|
|
|
12
12
|
ALL: "all",
|
|
13
13
|
DEPLOYED: "published",
|
|
14
14
|
};
|
|
15
|
-
exports.SearchIndexes = {
|
|
16
|
-
ROWS: "rows",
|
|
17
|
-
};
|
|
18
15
|
exports.BudibaseInternalDB = {
|
|
19
16
|
_id: "bb_internal",
|
|
20
17
|
type: backend_core_1.db.BUDIBASE_DATASOURCE_TYPE,
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.createAllSearchIndex = exports.createRoutingView = exports.createLinkView = void 0;
|
|
13
13
|
const backend_core_1 = require("@budibase/backend-core");
|
|
14
14
|
const utils_1 = require("../utils");
|
|
15
|
+
const types_1 = require("@budibase/types");
|
|
15
16
|
const SCREEN_PREFIX = utils_1.DocumentType.SCREEN + utils_1.SEPARATOR;
|
|
16
17
|
/**************************************************
|
|
17
18
|
* INFORMATION *
|
|
@@ -99,7 +100,7 @@ function searchIndex(indexName, fnString) {
|
|
|
99
100
|
}
|
|
100
101
|
function createAllSearchIndex() {
|
|
101
102
|
return __awaiter(this, void 0, void 0, function* () {
|
|
102
|
-
yield searchIndex(
|
|
103
|
+
yield searchIndex(types_1.SearchIndex.ROWS, function (doc) {
|
|
103
104
|
function idx(input, prev) {
|
|
104
105
|
for (let key of Object.keys(input)) {
|
|
105
106
|
let idxKey = prev != null ? `${prev}.${key}` : key;
|
|
@@ -14,10 +14,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const knex_1 = require("knex");
|
|
16
16
|
const types_1 = require("@budibase/types");
|
|
17
|
+
const backend_core_1 = require("@budibase/backend-core");
|
|
17
18
|
const utils_1 = require("../utils");
|
|
18
19
|
const sqlTable_1 = __importDefault(require("./sqlTable"));
|
|
19
20
|
const environment_1 = __importDefault(require("../../environment"));
|
|
20
|
-
const utils_2 = require("./utils");
|
|
21
21
|
const envLimit = environment_1.default.SQL_MAX_ROWS
|
|
22
22
|
? parseInt(environment_1.default.SQL_MAX_ROWS)
|
|
23
23
|
: null;
|
|
@@ -117,7 +117,7 @@ class InternalBuilder {
|
|
|
117
117
|
addFilters(query, filters, opts) {
|
|
118
118
|
function iterate(structure, fn) {
|
|
119
119
|
for (let [key, value] of Object.entries(structure)) {
|
|
120
|
-
const updatedKey =
|
|
120
|
+
const updatedKey = backend_core_1.db.removeKeyNumbering(key);
|
|
121
121
|
const isRelationshipField = updatedKey.includes(".");
|
|
122
122
|
if (!opts.relationship && !isRelationshipField) {
|
|
123
123
|
fn(`${opts.tableName}.${updatedKey}`, value);
|
|
@@ -134,7 +134,7 @@ class GoogleSheetsIntegration {
|
|
|
134
134
|
return __awaiter(this, void 0, void 0, function* () {
|
|
135
135
|
try {
|
|
136
136
|
// Initialise oAuth client
|
|
137
|
-
let googleConfig = yield backend_core_1.configs.
|
|
137
|
+
let googleConfig = yield backend_core_1.configs.getGoogleDatasourceConfig();
|
|
138
138
|
if (!googleConfig) {
|
|
139
139
|
throw new backend_core_1.HTTPError("Google config not found", 400);
|
|
140
140
|
}
|