@budibase/backend-core 2.27.4 → 2.27.6
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/dist/index.js +1414 -163
- package/dist/index.js.map +4 -4
- package/dist/index.js.meta.json +1 -1
- package/dist/package.json +5 -4
- package/dist/plugins.js.map +1 -1
- package/dist/plugins.js.meta.json +1 -1
- package/dist/src/constants/db.d.ts +6 -0
- package/dist/src/constants/db.js +7 -1
- package/dist/src/constants/db.js.map +1 -1
- package/dist/src/environment.d.ts +2 -0
- package/dist/src/environment.js +2 -0
- package/dist/src/environment.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +2 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/objectStore/objectStore.d.ts +10 -2
- package/dist/src/objectStore/objectStore.js +13 -2
- package/dist/src/objectStore/objectStore.js.map +1 -1
- package/dist/src/sql/designDoc.d.ts +2 -0
- package/dist/src/sql/designDoc.js +20 -0
- package/dist/src/sql/designDoc.js.map +1 -0
- package/dist/src/sql/index.d.ts +4 -0
- package/dist/src/sql/index.js +36 -0
- package/dist/src/sql/index.js.map +1 -0
- package/dist/src/sql/sql.d.ts +21 -0
- package/dist/src/sql/sql.js +752 -0
- package/dist/src/sql/sql.js.map +1 -0
- package/dist/src/sql/sqlStatements.d.ts +14 -0
- package/dist/src/sql/sqlStatements.js +60 -0
- package/dist/src/sql/sqlStatements.js.map +1 -0
- package/dist/src/sql/sqlTable.d.ts +13 -0
- package/dist/src/sql/sqlTable.js +231 -0
- package/dist/src/sql/sqlTable.js.map +1 -0
- package/dist/src/sql/utils.d.ts +22 -0
- package/dist/src/sql/utils.js +133 -0
- package/dist/src/sql/utils.js.map +1 -0
- package/dist/tests/core/utilities/mocks/licenses.d.ts +1 -0
- package/dist/tests/core/utilities/mocks/licenses.js +5 -1
- package/dist/tests/core/utilities/mocks/licenses.js.map +1 -1
- package/package.json +5 -4
- package/src/constants/db.ts +6 -0
- package/src/environment.ts +3 -0
- package/src/index.ts +1 -0
- package/src/objectStore/objectStore.ts +21 -7
- package/src/sql/designDoc.ts +17 -0
- package/src/sql/index.ts +5 -0
- package/src/sql/sql.ts +852 -0
- package/src/sql/sqlStatements.ts +79 -0
- package/src/sql/sqlTable.ts +289 -0
- package/src/sql/utils.ts +134 -0
- package/tests/core/utilities/mocks/licenses.ts +4 -0
package/dist/index.js
CHANGED
|
@@ -1045,11 +1045,11 @@ var require_Condition = __commonJS({
|
|
|
1045
1045
|
return schema.concat(branch.resolve(options3));
|
|
1046
1046
|
};
|
|
1047
1047
|
}
|
|
1048
|
-
resolve(
|
|
1048
|
+
resolve(base2, options2) {
|
|
1049
1049
|
let values2 = this.refs.map((ref) => ref.getValue(options2 == null ? void 0 : options2.value, options2 == null ? void 0 : options2.parent, options2 == null ? void 0 : options2.context));
|
|
1050
|
-
let schema = this.fn.apply(
|
|
1051
|
-
if (schema === void 0 || schema ===
|
|
1052
|
-
return
|
|
1050
|
+
let schema = this.fn.apply(base2, values2.concat(base2, options2));
|
|
1051
|
+
if (schema === void 0 || schema === base2)
|
|
1052
|
+
return base2;
|
|
1053
1053
|
if (!(0, _isSchema.default)(schema))
|
|
1054
1054
|
throw new TypeError("conditions must return a schema object");
|
|
1055
1055
|
return schema.resolve(options2);
|
|
@@ -1439,7 +1439,7 @@ var require_createValidation = __commonJS({
|
|
|
1439
1439
|
return target;
|
|
1440
1440
|
}
|
|
1441
1441
|
function createValidation(config) {
|
|
1442
|
-
function
|
|
1442
|
+
function validate4(_ref, cb) {
|
|
1443
1443
|
let {
|
|
1444
1444
|
value,
|
|
1445
1445
|
path: path3 = "",
|
|
@@ -1514,8 +1514,8 @@ var require_createValidation = __commonJS({
|
|
|
1514
1514
|
else
|
|
1515
1515
|
cb(null, result);
|
|
1516
1516
|
}
|
|
1517
|
-
|
|
1518
|
-
return
|
|
1517
|
+
validate4.OPTIONS = config;
|
|
1518
|
+
return validate4;
|
|
1519
1519
|
}
|
|
1520
1520
|
}
|
|
1521
1521
|
});
|
|
@@ -1759,17 +1759,17 @@ var require_schema = __commonJS({
|
|
|
1759
1759
|
return this;
|
|
1760
1760
|
if (schema.type !== this.type && this.type !== "mixed")
|
|
1761
1761
|
throw new TypeError(`You cannot \`concat()\` schema's of different types: ${this.type} and ${schema.type}`);
|
|
1762
|
-
let
|
|
1762
|
+
let base2 = this;
|
|
1763
1763
|
let combined = schema.clone();
|
|
1764
|
-
const mergedSpec = _extends({},
|
|
1764
|
+
const mergedSpec = _extends({}, base2.spec, combined.spec);
|
|
1765
1765
|
combined.spec = mergedSpec;
|
|
1766
|
-
combined._typeError || (combined._typeError =
|
|
1767
|
-
combined._whitelistError || (combined._whitelistError =
|
|
1768
|
-
combined._blacklistError || (combined._blacklistError =
|
|
1769
|
-
combined._whitelist =
|
|
1770
|
-
combined._blacklist =
|
|
1771
|
-
combined.tests =
|
|
1772
|
-
combined.exclusiveTests =
|
|
1766
|
+
combined._typeError || (combined._typeError = base2._typeError);
|
|
1767
|
+
combined._whitelistError || (combined._whitelistError = base2._whitelistError);
|
|
1768
|
+
combined._blacklistError || (combined._blacklistError = base2._blacklistError);
|
|
1769
|
+
combined._whitelist = base2._whitelist.merge(schema._whitelist, schema._blacklist);
|
|
1770
|
+
combined._blacklist = base2._blacklist.merge(schema._blacklist, schema._whitelist);
|
|
1771
|
+
combined.tests = base2.tests;
|
|
1772
|
+
combined.exclusiveTests = base2.exclusiveTests;
|
|
1773
1773
|
combined.withMutation((next) => {
|
|
1774
1774
|
schema.tests.forEach((fn) => {
|
|
1775
1775
|
next.test(fn.OPTIONS);
|
|
@@ -2024,7 +2024,7 @@ attempted value: ${formattedValue}
|
|
|
2024
2024
|
if (typeof opts.test !== "function")
|
|
2025
2025
|
throw new TypeError("`test` is a required parameters");
|
|
2026
2026
|
let next = this.clone();
|
|
2027
|
-
let
|
|
2027
|
+
let validate4 = (0, _createValidation.default)(opts);
|
|
2028
2028
|
let isExclusive = opts.exclusive || opts.name && next.exclusiveTests[opts.name] === true;
|
|
2029
2029
|
if (opts.exclusive) {
|
|
2030
2030
|
if (!opts.name)
|
|
@@ -2036,12 +2036,12 @@ attempted value: ${formattedValue}
|
|
|
2036
2036
|
if (fn.OPTIONS.name === opts.name) {
|
|
2037
2037
|
if (isExclusive)
|
|
2038
2038
|
return false;
|
|
2039
|
-
if (fn.OPTIONS.test ===
|
|
2039
|
+
if (fn.OPTIONS.test === validate4.OPTIONS.test)
|
|
2040
2040
|
return false;
|
|
2041
2041
|
}
|
|
2042
2042
|
return true;
|
|
2043
2043
|
});
|
|
2044
|
-
next.tests.push(
|
|
2044
|
+
next.tests.push(validate4);
|
|
2045
2045
|
return next;
|
|
2046
2046
|
}
|
|
2047
2047
|
when(keys2, options2) {
|
|
@@ -3145,9 +3145,9 @@ var require_object = __commonJS({
|
|
|
3145
3145
|
return this.transformKeys((key) => (0, _snakeCase.default)(key).toUpperCase());
|
|
3146
3146
|
}
|
|
3147
3147
|
describe() {
|
|
3148
|
-
let
|
|
3149
|
-
|
|
3150
|
-
return
|
|
3148
|
+
let base2 = super.describe();
|
|
3149
|
+
base2.fields = (0, _mapValues.default)(this.fields, (value) => value.describe());
|
|
3150
|
+
return base2;
|
|
3151
3151
|
}
|
|
3152
3152
|
};
|
|
3153
3153
|
exports.default = ObjectSchema;
|
|
@@ -3354,10 +3354,10 @@ var require_array = __commonJS({
|
|
|
3354
3354
|
return this.transform((values2) => values2 != null ? values2.filter(reject) : values2);
|
|
3355
3355
|
}
|
|
3356
3356
|
describe() {
|
|
3357
|
-
let
|
|
3357
|
+
let base2 = super.describe();
|
|
3358
3358
|
if (this.innerType)
|
|
3359
|
-
|
|
3360
|
-
return
|
|
3359
|
+
base2.innerType = this.innerType.describe();
|
|
3360
|
+
return base2;
|
|
3361
3361
|
}
|
|
3362
3362
|
nullable(isNullable = true) {
|
|
3363
3363
|
return super.nullable(isNullable);
|
|
@@ -15440,7 +15440,7 @@ var require_cookie = __commonJS({
|
|
|
15440
15440
|
c.value = cookieValue;
|
|
15441
15441
|
return c;
|
|
15442
15442
|
}
|
|
15443
|
-
function
|
|
15443
|
+
function parse2(str, options2) {
|
|
15444
15444
|
if (!options2 || typeof options2 !== "object") {
|
|
15445
15445
|
options2 = {};
|
|
15446
15446
|
}
|
|
@@ -15622,7 +15622,7 @@ var require_cookie = __commonJS({
|
|
|
15622
15622
|
});
|
|
15623
15623
|
}
|
|
15624
15624
|
Cookie2.cookiesCreated = 0;
|
|
15625
|
-
Cookie2.parse =
|
|
15625
|
+
Cookie2.parse = parse2;
|
|
15626
15626
|
Cookie2.fromJSON = fromJSON;
|
|
15627
15627
|
Cookie2.prototype.key = "";
|
|
15628
15628
|
Cookie2.prototype.value = "";
|
|
@@ -15685,7 +15685,7 @@ var require_cookie = __commonJS({
|
|
|
15685
15685
|
Cookie2.prototype.clone = function() {
|
|
15686
15686
|
return fromJSON(this.toJSON());
|
|
15687
15687
|
};
|
|
15688
|
-
Cookie2.prototype.validate = function
|
|
15688
|
+
Cookie2.prototype.validate = function validate4() {
|
|
15689
15689
|
if (!COOKIE_OCTETS.test(this.value)) {
|
|
15690
15690
|
return false;
|
|
15691
15691
|
}
|
|
@@ -16179,7 +16179,7 @@ var require_cookie = __commonJS({
|
|
|
16179
16179
|
exports.MemoryCookieStore = MemoryCookieStore;
|
|
16180
16180
|
exports.parseDate = parseDate;
|
|
16181
16181
|
exports.formatDate = formatDate;
|
|
16182
|
-
exports.parse =
|
|
16182
|
+
exports.parse = parse2;
|
|
16183
16183
|
exports.fromJSON = fromJSON;
|
|
16184
16184
|
exports.domainMatch = domainMatch;
|
|
16185
16185
|
exports.defaultPath = defaultPath;
|
|
@@ -16381,7 +16381,7 @@ var require_aws_sign2 = __commonJS({
|
|
|
16381
16381
|
"../../node_modules/aws-sign2/index.js"(exports, module2) {
|
|
16382
16382
|
"use strict";
|
|
16383
16383
|
var crypto2 = require("crypto");
|
|
16384
|
-
var
|
|
16384
|
+
var parse2 = require("url").parse;
|
|
16385
16385
|
var keys2 = [
|
|
16386
16386
|
"acl",
|
|
16387
16387
|
"location",
|
|
@@ -16447,7 +16447,7 @@ var require_aws_sign2 = __commonJS({
|
|
|
16447
16447
|
}
|
|
16448
16448
|
module2.exports.canonicalizeHeaders = canonicalizeHeaders;
|
|
16449
16449
|
function canonicalizeResource(resource) {
|
|
16450
|
-
var url =
|
|
16450
|
+
var url = parse2(resource, true), path3 = url.pathname, buf = [];
|
|
16451
16451
|
Object.keys(url.query).forEach(function(key) {
|
|
16452
16452
|
if (!~keys2.indexOf(key))
|
|
16453
16453
|
return;
|
|
@@ -29966,7 +29966,7 @@ var require_validate = __commonJS({
|
|
|
29966
29966
|
root.jsonSchema = factory();
|
|
29967
29967
|
}
|
|
29968
29968
|
})(exports, function() {
|
|
29969
|
-
var exports2 =
|
|
29969
|
+
var exports2 = validate4;
|
|
29970
29970
|
exports2.Integer = { type: "integer" };
|
|
29971
29971
|
var primitiveConstructors = {
|
|
29972
29972
|
String,
|
|
@@ -29976,15 +29976,15 @@ var require_validate = __commonJS({
|
|
|
29976
29976
|
Array,
|
|
29977
29977
|
Date
|
|
29978
29978
|
};
|
|
29979
|
-
exports2.validate =
|
|
29980
|
-
function
|
|
29981
|
-
return
|
|
29979
|
+
exports2.validate = validate4;
|
|
29980
|
+
function validate4(instance, schema) {
|
|
29981
|
+
return validate4(instance, schema, { changing: false });
|
|
29982
29982
|
}
|
|
29983
29983
|
;
|
|
29984
29984
|
exports2.checkPropertyChange = function(value, schema, property) {
|
|
29985
|
-
return
|
|
29985
|
+
return validate4(value, schema, { changing: property || "property" });
|
|
29986
29986
|
};
|
|
29987
|
-
var
|
|
29987
|
+
var validate4 = exports2._validate = function(instance, schema, options2) {
|
|
29988
29988
|
if (!options2)
|
|
29989
29989
|
options2 = {};
|
|
29990
29990
|
var _changing = options2.changing;
|
|
@@ -30460,7 +30460,7 @@ var require_jsprim = __commonJS({
|
|
|
30460
30460
|
}
|
|
30461
30461
|
var c;
|
|
30462
30462
|
var pbase = -1;
|
|
30463
|
-
var
|
|
30463
|
+
var base2 = options2.base;
|
|
30464
30464
|
var start2;
|
|
30465
30465
|
var mult = 1;
|
|
30466
30466
|
var value = 0;
|
|
@@ -30482,19 +30482,19 @@ var require_jsprim = __commonJS({
|
|
|
30482
30482
|
if (str[idx] === "0") {
|
|
30483
30483
|
if (options2.allowPrefix) {
|
|
30484
30484
|
pbase = prefixToBase(str.charCodeAt(idx + 1));
|
|
30485
|
-
if (pbase !== -1 && (!baseOverride || pbase ===
|
|
30486
|
-
|
|
30485
|
+
if (pbase !== -1 && (!baseOverride || pbase === base2)) {
|
|
30486
|
+
base2 = pbase;
|
|
30487
30487
|
idx += 2;
|
|
30488
30488
|
}
|
|
30489
30489
|
}
|
|
30490
30490
|
if (pbase === -1 && options2.leadingZeroIsOctal) {
|
|
30491
|
-
|
|
30491
|
+
base2 = 8;
|
|
30492
30492
|
}
|
|
30493
30493
|
}
|
|
30494
30494
|
for (start2 = idx; idx < len; ++idx) {
|
|
30495
30495
|
c = translateDigit(str.charCodeAt(idx));
|
|
30496
|
-
if (c !== -1 && c <
|
|
30497
|
-
value *=
|
|
30496
|
+
if (c !== -1 && c < base2) {
|
|
30497
|
+
value *= base2;
|
|
30498
30498
|
value += c;
|
|
30499
30499
|
} else {
|
|
30500
30500
|
break;
|
|
@@ -41274,11 +41274,11 @@ var require_lib7 = __commonJS({
|
|
|
41274
41274
|
"../../node_modules/request/node_modules/qs/lib/index.js"(exports, module2) {
|
|
41275
41275
|
"use strict";
|
|
41276
41276
|
var stringify = require_stringify2();
|
|
41277
|
-
var
|
|
41277
|
+
var parse2 = require_parse();
|
|
41278
41278
|
var formats2 = require_formats();
|
|
41279
41279
|
module2.exports = {
|
|
41280
41280
|
formats: formats2,
|
|
41281
|
-
parse,
|
|
41281
|
+
parse: parse2,
|
|
41282
41282
|
stringify
|
|
41283
41283
|
};
|
|
41284
41284
|
}
|
|
@@ -41444,7 +41444,7 @@ var require_uri_all = __commonJS({
|
|
|
41444
41444
|
}
|
|
41445
41445
|
};
|
|
41446
41446
|
var maxInt = 2147483647;
|
|
41447
|
-
var
|
|
41447
|
+
var base2 = 36;
|
|
41448
41448
|
var tMin = 1;
|
|
41449
41449
|
var tMax = 26;
|
|
41450
41450
|
var skew = 38;
|
|
@@ -41460,7 +41460,7 @@ var require_uri_all = __commonJS({
|
|
|
41460
41460
|
"not-basic": "Illegal input >= 0x80 (not a basic code point)",
|
|
41461
41461
|
"invalid-input": "Invalid input"
|
|
41462
41462
|
};
|
|
41463
|
-
var baseMinusTMin =
|
|
41463
|
+
var baseMinusTMin = base2 - tMin;
|
|
41464
41464
|
var floor = Math.floor;
|
|
41465
41465
|
var stringFromCharCode = String.fromCharCode;
|
|
41466
41466
|
function error$1(type) {
|
|
@@ -41519,7 +41519,7 @@ var require_uri_all = __commonJS({
|
|
|
41519
41519
|
if (codePoint - 97 < 26) {
|
|
41520
41520
|
return codePoint - 97;
|
|
41521
41521
|
}
|
|
41522
|
-
return
|
|
41522
|
+
return base2;
|
|
41523
41523
|
};
|
|
41524
41524
|
var digitToBasic = function digitToBasic2(digit, flag) {
|
|
41525
41525
|
return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5);
|
|
@@ -41532,7 +41532,7 @@ var require_uri_all = __commonJS({
|
|
|
41532
41532
|
;
|
|
41533
41533
|
/* no initialization */
|
|
41534
41534
|
delta > baseMinusTMin * tMax >> 1;
|
|
41535
|
-
k +=
|
|
41535
|
+
k += base2
|
|
41536
41536
|
) {
|
|
41537
41537
|
delta = floor(delta / baseMinusTMin);
|
|
41538
41538
|
}
|
|
@@ -41557,16 +41557,16 @@ var require_uri_all = __commonJS({
|
|
|
41557
41557
|
for (var index2 = basic > 0 ? basic + 1 : 0; index2 < inputLength; ) {
|
|
41558
41558
|
var oldi = i;
|
|
41559
41559
|
for (
|
|
41560
|
-
var w = 1, k =
|
|
41560
|
+
var w = 1, k = base2;
|
|
41561
41561
|
;
|
|
41562
41562
|
/* no condition */
|
|
41563
|
-
k +=
|
|
41563
|
+
k += base2
|
|
41564
41564
|
) {
|
|
41565
41565
|
if (index2 >= inputLength) {
|
|
41566
41566
|
error$1("invalid-input");
|
|
41567
41567
|
}
|
|
41568
41568
|
var digit = basicToDigit(input.charCodeAt(index2++));
|
|
41569
|
-
if (digit >=
|
|
41569
|
+
if (digit >= base2 || digit > floor((maxInt - i) / w)) {
|
|
41570
41570
|
error$1("overflow");
|
|
41571
41571
|
}
|
|
41572
41572
|
i += digit * w;
|
|
@@ -41574,7 +41574,7 @@ var require_uri_all = __commonJS({
|
|
|
41574
41574
|
if (digit < t) {
|
|
41575
41575
|
break;
|
|
41576
41576
|
}
|
|
41577
|
-
var baseMinusT =
|
|
41577
|
+
var baseMinusT = base2 - t;
|
|
41578
41578
|
if (w > floor(maxInt / baseMinusT)) {
|
|
41579
41579
|
error$1("overflow");
|
|
41580
41580
|
}
|
|
@@ -41671,17 +41671,17 @@ var require_uri_all = __commonJS({
|
|
|
41671
41671
|
if (_currentValue == n) {
|
|
41672
41672
|
var q2 = delta;
|
|
41673
41673
|
for (
|
|
41674
|
-
var k =
|
|
41674
|
+
var k = base2;
|
|
41675
41675
|
;
|
|
41676
41676
|
/* no condition */
|
|
41677
|
-
k +=
|
|
41677
|
+
k += base2
|
|
41678
41678
|
) {
|
|
41679
41679
|
var t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias;
|
|
41680
41680
|
if (q2 < t) {
|
|
41681
41681
|
break;
|
|
41682
41682
|
}
|
|
41683
41683
|
var qMinusT = q2 - t;
|
|
41684
|
-
var baseMinusT =
|
|
41684
|
+
var baseMinusT = base2 - t;
|
|
41685
41685
|
output.push(stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0)));
|
|
41686
41686
|
q2 = floor(qMinusT / baseMinusT);
|
|
41687
41687
|
}
|
|
@@ -41870,7 +41870,7 @@ var require_uri_all = __commonJS({
|
|
|
41870
41870
|
}
|
|
41871
41871
|
var URI_PARSE = /^(?:([^:\/?#]+):)?(?:\/\/((?:([^\/?#@]*)@)?(\[[^\/?#\]]+\]|[^\/?#:]*)(?:\:(\d*))?))?([^?#]*)(?:\?([^#]*))?(?:#((?:.|\n|\r)*))?/i;
|
|
41872
41872
|
var NO_MATCH_IS_UNDEFINED = "".match(/(){0}/)[1] === void 0;
|
|
41873
|
-
function
|
|
41873
|
+
function parse2(uriString) {
|
|
41874
41874
|
var options2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
41875
41875
|
var components = {};
|
|
41876
41876
|
var protocol = options2.iri !== false ? IRI_PROTOCOL : URI_PROTOCOL;
|
|
@@ -42036,13 +42036,13 @@ var require_uri_all = __commonJS({
|
|
|
42036
42036
|
}
|
|
42037
42037
|
return uriTokens.join("");
|
|
42038
42038
|
}
|
|
42039
|
-
function resolveComponents(
|
|
42039
|
+
function resolveComponents(base3, relative) {
|
|
42040
42040
|
var options2 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
42041
42041
|
var skipNormalization = arguments[3];
|
|
42042
42042
|
var target = {};
|
|
42043
42043
|
if (!skipNormalization) {
|
|
42044
|
-
|
|
42045
|
-
relative =
|
|
42044
|
+
base3 = parse2(serialize(base3, options2), options2);
|
|
42045
|
+
relative = parse2(serialize(relative, options2), options2);
|
|
42046
42046
|
}
|
|
42047
42047
|
options2 = options2 || {};
|
|
42048
42048
|
if (!options2.tolerant && relative.scheme) {
|
|
@@ -42061,56 +42061,56 @@ var require_uri_all = __commonJS({
|
|
|
42061
42061
|
target.query = relative.query;
|
|
42062
42062
|
} else {
|
|
42063
42063
|
if (!relative.path) {
|
|
42064
|
-
target.path =
|
|
42064
|
+
target.path = base3.path;
|
|
42065
42065
|
if (relative.query !== void 0) {
|
|
42066
42066
|
target.query = relative.query;
|
|
42067
42067
|
} else {
|
|
42068
|
-
target.query =
|
|
42068
|
+
target.query = base3.query;
|
|
42069
42069
|
}
|
|
42070
42070
|
} else {
|
|
42071
42071
|
if (relative.path.charAt(0) === "/") {
|
|
42072
42072
|
target.path = removeDotSegments(relative.path);
|
|
42073
42073
|
} else {
|
|
42074
|
-
if ((
|
|
42074
|
+
if ((base3.userinfo !== void 0 || base3.host !== void 0 || base3.port !== void 0) && !base3.path) {
|
|
42075
42075
|
target.path = "/" + relative.path;
|
|
42076
|
-
} else if (!
|
|
42076
|
+
} else if (!base3.path) {
|
|
42077
42077
|
target.path = relative.path;
|
|
42078
42078
|
} else {
|
|
42079
|
-
target.path =
|
|
42079
|
+
target.path = base3.path.slice(0, base3.path.lastIndexOf("/") + 1) + relative.path;
|
|
42080
42080
|
}
|
|
42081
42081
|
target.path = removeDotSegments(target.path);
|
|
42082
42082
|
}
|
|
42083
42083
|
target.query = relative.query;
|
|
42084
42084
|
}
|
|
42085
|
-
target.userinfo =
|
|
42086
|
-
target.host =
|
|
42087
|
-
target.port =
|
|
42085
|
+
target.userinfo = base3.userinfo;
|
|
42086
|
+
target.host = base3.host;
|
|
42087
|
+
target.port = base3.port;
|
|
42088
42088
|
}
|
|
42089
|
-
target.scheme =
|
|
42089
|
+
target.scheme = base3.scheme;
|
|
42090
42090
|
}
|
|
42091
42091
|
target.fragment = relative.fragment;
|
|
42092
42092
|
return target;
|
|
42093
42093
|
}
|
|
42094
42094
|
function resolve(baseURI, relativeURI, options2) {
|
|
42095
42095
|
var schemelessOptions = assign({ scheme: "null" }, options2);
|
|
42096
|
-
return serialize(resolveComponents(
|
|
42096
|
+
return serialize(resolveComponents(parse2(baseURI, schemelessOptions), parse2(relativeURI, schemelessOptions), schemelessOptions, true), schemelessOptions);
|
|
42097
42097
|
}
|
|
42098
42098
|
function normalize(uri, options2) {
|
|
42099
42099
|
if (typeof uri === "string") {
|
|
42100
|
-
uri = serialize(
|
|
42100
|
+
uri = serialize(parse2(uri, options2), options2);
|
|
42101
42101
|
} else if (typeOf(uri) === "object") {
|
|
42102
|
-
uri =
|
|
42102
|
+
uri = parse2(serialize(uri, options2), options2);
|
|
42103
42103
|
}
|
|
42104
42104
|
return uri;
|
|
42105
42105
|
}
|
|
42106
42106
|
function equal(uriA, uriB, options2) {
|
|
42107
42107
|
if (typeof uriA === "string") {
|
|
42108
|
-
uriA = serialize(
|
|
42108
|
+
uriA = serialize(parse2(uriA, options2), options2);
|
|
42109
42109
|
} else if (typeOf(uriA) === "object") {
|
|
42110
42110
|
uriA = serialize(uriA, options2);
|
|
42111
42111
|
}
|
|
42112
42112
|
if (typeof uriB === "string") {
|
|
42113
|
-
uriB = serialize(
|
|
42113
|
+
uriB = serialize(parse2(uriB, options2), options2);
|
|
42114
42114
|
} else if (typeOf(uriB) === "object") {
|
|
42115
42115
|
uriB = serialize(uriB, options2);
|
|
42116
42116
|
}
|
|
@@ -42125,7 +42125,7 @@ var require_uri_all = __commonJS({
|
|
|
42125
42125
|
var handler = {
|
|
42126
42126
|
scheme: "http",
|
|
42127
42127
|
domainHost: true,
|
|
42128
|
-
parse: function
|
|
42128
|
+
parse: function parse3(components, options2) {
|
|
42129
42129
|
if (!components.host) {
|
|
42130
42130
|
components.error = components.error || "HTTP URIs must have a host.";
|
|
42131
42131
|
}
|
|
@@ -42154,7 +42154,7 @@ var require_uri_all = __commonJS({
|
|
|
42154
42154
|
var handler$2 = {
|
|
42155
42155
|
scheme: "ws",
|
|
42156
42156
|
domainHost: true,
|
|
42157
|
-
parse: function
|
|
42157
|
+
parse: function parse3(components, options2) {
|
|
42158
42158
|
var wsComponents = components;
|
|
42159
42159
|
wsComponents.secure = isSecure(wsComponents);
|
|
42160
42160
|
wsComponents.resourceName = (wsComponents.path || "/") + (wsComponents.query ? "?" + wsComponents.query : "");
|
|
@@ -42330,7 +42330,7 @@ var require_uri_all = __commonJS({
|
|
|
42330
42330
|
var UUID = /^[0-9A-Fa-f]{8}(?:\-[0-9A-Fa-f]{4}){3}\-[0-9A-Fa-f]{12}$/;
|
|
42331
42331
|
var handler$6 = {
|
|
42332
42332
|
scheme: "urn:uuid",
|
|
42333
|
-
parse: function
|
|
42333
|
+
parse: function parse3(urnComponents, options2) {
|
|
42334
42334
|
var uuidComponents = urnComponents;
|
|
42335
42335
|
uuidComponents.uuid = uuidComponents.nss;
|
|
42336
42336
|
uuidComponents.nss = void 0;
|
|
@@ -42355,7 +42355,7 @@ var require_uri_all = __commonJS({
|
|
|
42355
42355
|
exports2.SCHEMES = SCHEMES;
|
|
42356
42356
|
exports2.pctEncChar = pctEncChar;
|
|
42357
42357
|
exports2.pctDecChars = pctDecChars;
|
|
42358
|
-
exports2.parse =
|
|
42358
|
+
exports2.parse = parse2;
|
|
42359
42359
|
exports2.removeDotSegments = removeDotSegments;
|
|
42360
42360
|
exports2.serialize = serialize;
|
|
42361
42361
|
exports2.resolveComponents = resolveComponents;
|
|
@@ -43588,9 +43588,9 @@ var require_compile = __commonJS({
|
|
|
43588
43588
|
endCompiling.call(this, schema, root, baseId);
|
|
43589
43589
|
}
|
|
43590
43590
|
function callValidate() {
|
|
43591
|
-
var
|
|
43592
|
-
var result =
|
|
43593
|
-
callValidate.errors =
|
|
43591
|
+
var validate4 = compilation.validate;
|
|
43592
|
+
var result = validate4.apply(this, arguments);
|
|
43593
|
+
callValidate.errors = validate4.errors;
|
|
43594
43594
|
return result;
|
|
43595
43595
|
}
|
|
43596
43596
|
function localCompile(_schema, _root, localRefs2, baseId2) {
|
|
@@ -43624,7 +43624,7 @@ var require_compile = __commonJS({
|
|
|
43624
43624
|
sourceCode = vars(refVal, refValCode) + vars(patterns, patternCode) + vars(defaults, defaultCode) + vars(customRules, customRuleCode) + sourceCode;
|
|
43625
43625
|
if (opts.processCode)
|
|
43626
43626
|
sourceCode = opts.processCode(sourceCode, _schema);
|
|
43627
|
-
var
|
|
43627
|
+
var validate4;
|
|
43628
43628
|
try {
|
|
43629
43629
|
var makeValidate = new Function(
|
|
43630
43630
|
"self",
|
|
@@ -43639,7 +43639,7 @@ var require_compile = __commonJS({
|
|
|
43639
43639
|
"ValidationError",
|
|
43640
43640
|
sourceCode
|
|
43641
43641
|
);
|
|
43642
|
-
|
|
43642
|
+
validate4 = makeValidate(
|
|
43643
43643
|
self2,
|
|
43644
43644
|
RULES,
|
|
43645
43645
|
formats2,
|
|
@@ -43651,26 +43651,26 @@ var require_compile = __commonJS({
|
|
|
43651
43651
|
ucs2length,
|
|
43652
43652
|
ValidationError
|
|
43653
43653
|
);
|
|
43654
|
-
refVal[0] =
|
|
43654
|
+
refVal[0] = validate4;
|
|
43655
43655
|
} catch (e) {
|
|
43656
43656
|
self2.logger.error("Error compiling schema, function code:", sourceCode);
|
|
43657
43657
|
throw e;
|
|
43658
43658
|
}
|
|
43659
|
-
|
|
43660
|
-
|
|
43661
|
-
|
|
43662
|
-
|
|
43663
|
-
|
|
43659
|
+
validate4.schema = _schema;
|
|
43660
|
+
validate4.errors = null;
|
|
43661
|
+
validate4.refs = refs;
|
|
43662
|
+
validate4.refVal = refVal;
|
|
43663
|
+
validate4.root = isRoot ? validate4 : _root;
|
|
43664
43664
|
if ($async)
|
|
43665
|
-
|
|
43665
|
+
validate4.$async = true;
|
|
43666
43666
|
if (opts.sourceCode === true) {
|
|
43667
|
-
|
|
43667
|
+
validate4.source = {
|
|
43668
43668
|
code: sourceCode,
|
|
43669
43669
|
patterns,
|
|
43670
43670
|
defaults
|
|
43671
43671
|
};
|
|
43672
43672
|
}
|
|
43673
|
-
return
|
|
43673
|
+
return validate4;
|
|
43674
43674
|
}
|
|
43675
43675
|
function resolveRef(baseId2, ref, isRoot) {
|
|
43676
43676
|
ref = resolve.url(baseId2, ref);
|
|
@@ -43767,27 +43767,27 @@ var require_compile = __commonJS({
|
|
|
43767
43767
|
}
|
|
43768
43768
|
}
|
|
43769
43769
|
var compile2 = rule.definition.compile, inline = rule.definition.inline, macro = rule.definition.macro;
|
|
43770
|
-
var
|
|
43770
|
+
var validate4;
|
|
43771
43771
|
if (compile2) {
|
|
43772
|
-
|
|
43772
|
+
validate4 = compile2.call(self2, schema2, parentSchema, it);
|
|
43773
43773
|
} else if (macro) {
|
|
43774
|
-
|
|
43774
|
+
validate4 = macro.call(self2, schema2, parentSchema, it);
|
|
43775
43775
|
if (opts.validateSchema !== false)
|
|
43776
|
-
self2.validateSchema(
|
|
43776
|
+
self2.validateSchema(validate4, true);
|
|
43777
43777
|
} else if (inline) {
|
|
43778
|
-
|
|
43778
|
+
validate4 = inline.call(self2, it, rule.keyword, schema2, parentSchema);
|
|
43779
43779
|
} else {
|
|
43780
|
-
|
|
43781
|
-
if (!
|
|
43780
|
+
validate4 = rule.definition.validate;
|
|
43781
|
+
if (!validate4)
|
|
43782
43782
|
return;
|
|
43783
43783
|
}
|
|
43784
|
-
if (
|
|
43784
|
+
if (validate4 === void 0)
|
|
43785
43785
|
throw new Error('custom keyword "' + rule.keyword + '"failed to compile');
|
|
43786
43786
|
var index2 = customRules.length;
|
|
43787
|
-
customRules[index2] =
|
|
43787
|
+
customRules[index2] = validate4;
|
|
43788
43788
|
return {
|
|
43789
43789
|
code: "customRule" + index2,
|
|
43790
|
-
validate:
|
|
43790
|
+
validate: validate4
|
|
43791
43791
|
};
|
|
43792
43792
|
}
|
|
43793
43793
|
}
|
|
@@ -47338,7 +47338,7 @@ var require_ajv = __commonJS({
|
|
|
47338
47338
|
var $dataMetaSchema = require_data();
|
|
47339
47339
|
var util = require_util2();
|
|
47340
47340
|
module2.exports = Ajv;
|
|
47341
|
-
Ajv.prototype.validate =
|
|
47341
|
+
Ajv.prototype.validate = validate4;
|
|
47342
47342
|
Ajv.prototype.compile = compile;
|
|
47343
47343
|
Ajv.prototype.addSchema = addSchema;
|
|
47344
47344
|
Ajv.prototype.addMetaSchema = addMetaSchema;
|
|
@@ -47393,7 +47393,7 @@ var require_ajv = __commonJS({
|
|
|
47393
47393
|
this.addKeyword("nullable", { metaSchema: { type: "boolean" } });
|
|
47394
47394
|
addInitialSchemas(this);
|
|
47395
47395
|
}
|
|
47396
|
-
function
|
|
47396
|
+
function validate4(schemaKeyRef, data) {
|
|
47397
47397
|
var v;
|
|
47398
47398
|
if (typeof schemaKeyRef == "string") {
|
|
47399
47399
|
v = this.getSchema(schemaKeyRef);
|
|
@@ -48611,68 +48611,68 @@ var require_promise = __commonJS({
|
|
|
48611
48611
|
ajv2.addSchema(schemas);
|
|
48612
48612
|
return ajv2;
|
|
48613
48613
|
}
|
|
48614
|
-
function
|
|
48614
|
+
function validate4(name, data) {
|
|
48615
48615
|
data = data || {};
|
|
48616
48616
|
ajv = ajv || createAjvInstance();
|
|
48617
|
-
var
|
|
48617
|
+
var validate5 = ajv.getSchema(name + ".json");
|
|
48618
48618
|
return new Promise(function(resolve, reject) {
|
|
48619
|
-
var valid =
|
|
48620
|
-
!valid ? reject(new HARError(
|
|
48619
|
+
var valid = validate5(data);
|
|
48620
|
+
!valid ? reject(new HARError(validate5.errors)) : resolve(data);
|
|
48621
48621
|
});
|
|
48622
48622
|
}
|
|
48623
48623
|
exports.afterRequest = function(data) {
|
|
48624
|
-
return
|
|
48624
|
+
return validate4("afterRequest", data);
|
|
48625
48625
|
};
|
|
48626
48626
|
exports.beforeRequest = function(data) {
|
|
48627
|
-
return
|
|
48627
|
+
return validate4("beforeRequest", data);
|
|
48628
48628
|
};
|
|
48629
48629
|
exports.browser = function(data) {
|
|
48630
|
-
return
|
|
48630
|
+
return validate4("browser", data);
|
|
48631
48631
|
};
|
|
48632
48632
|
exports.cache = function(data) {
|
|
48633
|
-
return
|
|
48633
|
+
return validate4("cache", data);
|
|
48634
48634
|
};
|
|
48635
48635
|
exports.content = function(data) {
|
|
48636
|
-
return
|
|
48636
|
+
return validate4("content", data);
|
|
48637
48637
|
};
|
|
48638
48638
|
exports.cookie = function(data) {
|
|
48639
|
-
return
|
|
48639
|
+
return validate4("cookie", data);
|
|
48640
48640
|
};
|
|
48641
48641
|
exports.creator = function(data) {
|
|
48642
|
-
return
|
|
48642
|
+
return validate4("creator", data);
|
|
48643
48643
|
};
|
|
48644
48644
|
exports.entry = function(data) {
|
|
48645
|
-
return
|
|
48645
|
+
return validate4("entry", data);
|
|
48646
48646
|
};
|
|
48647
48647
|
exports.har = function(data) {
|
|
48648
|
-
return
|
|
48648
|
+
return validate4("har", data);
|
|
48649
48649
|
};
|
|
48650
48650
|
exports.header = function(data) {
|
|
48651
|
-
return
|
|
48651
|
+
return validate4("header", data);
|
|
48652
48652
|
};
|
|
48653
48653
|
exports.log = function(data) {
|
|
48654
|
-
return
|
|
48654
|
+
return validate4("log", data);
|
|
48655
48655
|
};
|
|
48656
48656
|
exports.page = function(data) {
|
|
48657
|
-
return
|
|
48657
|
+
return validate4("page", data);
|
|
48658
48658
|
};
|
|
48659
48659
|
exports.pageTimings = function(data) {
|
|
48660
|
-
return
|
|
48660
|
+
return validate4("pageTimings", data);
|
|
48661
48661
|
};
|
|
48662
48662
|
exports.postData = function(data) {
|
|
48663
|
-
return
|
|
48663
|
+
return validate4("postData", data);
|
|
48664
48664
|
};
|
|
48665
48665
|
exports.query = function(data) {
|
|
48666
|
-
return
|
|
48666
|
+
return validate4("query", data);
|
|
48667
48667
|
};
|
|
48668
48668
|
exports.request = function(data) {
|
|
48669
|
-
return
|
|
48669
|
+
return validate4("request", data);
|
|
48670
48670
|
};
|
|
48671
48671
|
exports.response = function(data) {
|
|
48672
|
-
return
|
|
48672
|
+
return validate4("response", data);
|
|
48673
48673
|
};
|
|
48674
48674
|
exports.timings = function(data) {
|
|
48675
|
-
return
|
|
48675
|
+
return validate4("timings", data);
|
|
48676
48676
|
};
|
|
48677
48677
|
}
|
|
48678
48678
|
});
|
|
@@ -48683,7 +48683,7 @@ var require_har2 = __commonJS({
|
|
|
48683
48683
|
"use strict";
|
|
48684
48684
|
var fs5 = require("fs");
|
|
48685
48685
|
var qs2 = require("querystring");
|
|
48686
|
-
var
|
|
48686
|
+
var validate4 = require_promise();
|
|
48687
48687
|
var extend = require_extend();
|
|
48688
48688
|
function Har(request) {
|
|
48689
48689
|
this.request = request;
|
|
@@ -48780,7 +48780,7 @@ var require_har2 = __commonJS({
|
|
|
48780
48780
|
har.bodySize = 0;
|
|
48781
48781
|
har.headersSize = 0;
|
|
48782
48782
|
har.postData.size = 0;
|
|
48783
|
-
if (!
|
|
48783
|
+
if (!validate4.request(har)) {
|
|
48784
48784
|
return options2;
|
|
48785
48785
|
}
|
|
48786
48786
|
var req = this.prep(har);
|
|
@@ -49012,33 +49012,33 @@ var require_oauth_sign = __commonJS({
|
|
|
49012
49012
|
}).map(function(p) {
|
|
49013
49013
|
return p.join("=");
|
|
49014
49014
|
}).join("&");
|
|
49015
|
-
var
|
|
49015
|
+
var base2 = [
|
|
49016
49016
|
rfc3986(httpMethod ? httpMethod.toUpperCase() : "GET"),
|
|
49017
49017
|
rfc3986(base_uri),
|
|
49018
49018
|
rfc3986(normalized)
|
|
49019
49019
|
].join("&");
|
|
49020
|
-
return
|
|
49020
|
+
return base2;
|
|
49021
49021
|
}
|
|
49022
49022
|
function hmacsign(httpMethod, base_uri, params2, consumer_secret, token_secret) {
|
|
49023
|
-
var
|
|
49023
|
+
var base2 = generateBase(httpMethod, base_uri, params2);
|
|
49024
49024
|
var key = [
|
|
49025
49025
|
consumer_secret || "",
|
|
49026
49026
|
token_secret || ""
|
|
49027
49027
|
].map(rfc3986).join("&");
|
|
49028
|
-
return sha(key,
|
|
49028
|
+
return sha(key, base2, "sha1");
|
|
49029
49029
|
}
|
|
49030
49030
|
function hmacsign256(httpMethod, base_uri, params2, consumer_secret, token_secret) {
|
|
49031
|
-
var
|
|
49031
|
+
var base2 = generateBase(httpMethod, base_uri, params2);
|
|
49032
49032
|
var key = [
|
|
49033
49033
|
consumer_secret || "",
|
|
49034
49034
|
token_secret || ""
|
|
49035
49035
|
].map(rfc3986).join("&");
|
|
49036
|
-
return sha(key,
|
|
49036
|
+
return sha(key, base2, "sha256");
|
|
49037
49037
|
}
|
|
49038
49038
|
function rsasign(httpMethod, base_uri, params2, private_key, token_secret) {
|
|
49039
|
-
var
|
|
49039
|
+
var base2 = generateBase(httpMethod, base_uri, params2);
|
|
49040
49040
|
var key = private_key || "";
|
|
49041
|
-
return rsa(key,
|
|
49041
|
+
return rsa(key, base2);
|
|
49042
49042
|
}
|
|
49043
49043
|
function plaintext(consumer_secret, token_secret) {
|
|
49044
49044
|
var key = [
|
|
@@ -50836,16 +50836,16 @@ var require_request2 = __commonJS({
|
|
|
50836
50836
|
};
|
|
50837
50837
|
Request.prototype.qs = function(q2, clobber) {
|
|
50838
50838
|
var self2 = this;
|
|
50839
|
-
var
|
|
50839
|
+
var base2;
|
|
50840
50840
|
if (!clobber && self2.uri.query) {
|
|
50841
|
-
|
|
50841
|
+
base2 = self2._qs.parse(self2.uri.query);
|
|
50842
50842
|
} else {
|
|
50843
|
-
|
|
50843
|
+
base2 = {};
|
|
50844
50844
|
}
|
|
50845
50845
|
for (var i in q2) {
|
|
50846
|
-
|
|
50846
|
+
base2[i] = q2[i];
|
|
50847
50847
|
}
|
|
50848
|
-
var qs2 = self2._qs.stringify(
|
|
50848
|
+
var qs2 = self2._qs.stringify(base2);
|
|
50849
50849
|
if (qs2 === "") {
|
|
50850
50850
|
return self2;
|
|
50851
50851
|
}
|
|
@@ -54139,6 +54139,11 @@ __export(src_exports, {
|
|
|
54139
54139
|
BudibaseError: () => BudibaseError,
|
|
54140
54140
|
Config: () => Config,
|
|
54141
54141
|
Cookie: () => Cookie,
|
|
54142
|
+
DEFAULT_BB_DATASOURCE_ID: () => DEFAULT_BB_DATASOURCE_ID,
|
|
54143
|
+
DEFAULT_EMPLOYEE_TABLE_ID: () => DEFAULT_EMPLOYEE_TABLE_ID,
|
|
54144
|
+
DEFAULT_EXPENSES_TABLE_ID: () => DEFAULT_EXPENSES_TABLE_ID,
|
|
54145
|
+
DEFAULT_INVENTORY_TABLE_ID: () => DEFAULT_INVENTORY_TABLE_ID,
|
|
54146
|
+
DEFAULT_JOBS_TABLE_ID: () => DEFAULT_JOBS_TABLE_ID,
|
|
54142
54147
|
DEFAULT_TENANT_ID: () => DEFAULT_TENANT_ID,
|
|
54143
54148
|
DeprecatedViews: () => DeprecatedViews,
|
|
54144
54149
|
DocumentType: () => DocumentType,
|
|
@@ -54158,6 +54163,7 @@ __export(src_exports, {
|
|
|
54158
54163
|
RedisClient: () => redis_default,
|
|
54159
54164
|
SEPARATOR: () => SEPARATOR,
|
|
54160
54165
|
SQLITE_DESIGN_DOC_ID: () => SQLITE_DESIGN_DOC_ID,
|
|
54166
|
+
SQS_DATASOURCE_INTERNAL: () => SQS_DATASOURCE_INTERNAL,
|
|
54161
54167
|
StaticDatabases: () => StaticDatabases,
|
|
54162
54168
|
UNICODE_MAX: () => UNICODE_MAX,
|
|
54163
54169
|
UsageLimitError: () => UsageLimitError,
|
|
@@ -54195,6 +54201,7 @@ __export(src_exports, {
|
|
|
54195
54201
|
roles: () => roles_exports,
|
|
54196
54202
|
security: () => security_exports,
|
|
54197
54203
|
sessions: () => sessions_exports,
|
|
54204
|
+
sql: () => sql_exports,
|
|
54198
54205
|
tenancy: () => tenancy,
|
|
54199
54206
|
timers: () => timers_exports,
|
|
54200
54207
|
userUtils: () => utils_exports4,
|
|
@@ -54563,6 +54570,19 @@ var AutomationStepIdArray = [
|
|
|
54563
54570
|
...Object.values(AutomationTriggerStepId)
|
|
54564
54571
|
];
|
|
54565
54572
|
|
|
54573
|
+
// ../types/src/documents/app/table/table.ts
|
|
54574
|
+
var INTERNAL_TABLE_SOURCE_ID = "bb_internal";
|
|
54575
|
+
|
|
54576
|
+
// ../types/src/documents/app/row.ts
|
|
54577
|
+
var JsonTypes = [
|
|
54578
|
+
"attachment_single" /* ATTACHMENT_SINGLE */,
|
|
54579
|
+
"attachment" /* ATTACHMENTS */,
|
|
54580
|
+
// only BB_REFERENCE is JSON, it's an array, BB_REFERENCE_SINGLE is a string type
|
|
54581
|
+
"bb_reference" /* BB_REFERENCE */,
|
|
54582
|
+
"json" /* JSON */,
|
|
54583
|
+
"array" /* ARRAY */
|
|
54584
|
+
];
|
|
54585
|
+
|
|
54566
54586
|
// ../types/src/documents/document.ts
|
|
54567
54587
|
var SEPARATOR = "_";
|
|
54568
54588
|
var UNICODE_MAX = "\uFFF0";
|
|
@@ -54645,6 +54665,11 @@ __export(constants_exports2, {
|
|
|
54645
54665
|
BUDIBASE_DATASOURCE_TYPE: () => BUDIBASE_DATASOURCE_TYPE,
|
|
54646
54666
|
Config: () => Config,
|
|
54647
54667
|
Cookie: () => Cookie,
|
|
54668
|
+
DEFAULT_BB_DATASOURCE_ID: () => DEFAULT_BB_DATASOURCE_ID,
|
|
54669
|
+
DEFAULT_EMPLOYEE_TABLE_ID: () => DEFAULT_EMPLOYEE_TABLE_ID,
|
|
54670
|
+
DEFAULT_EXPENSES_TABLE_ID: () => DEFAULT_EXPENSES_TABLE_ID,
|
|
54671
|
+
DEFAULT_INVENTORY_TABLE_ID: () => DEFAULT_INVENTORY_TABLE_ID,
|
|
54672
|
+
DEFAULT_JOBS_TABLE_ID: () => DEFAULT_JOBS_TABLE_ID,
|
|
54648
54673
|
DEFAULT_TENANT_ID: () => DEFAULT_TENANT_ID,
|
|
54649
54674
|
DeprecatedViews: () => DeprecatedViews,
|
|
54650
54675
|
DocumentType: () => DocumentType,
|
|
@@ -54655,6 +54680,7 @@ __export(constants_exports2, {
|
|
|
54655
54680
|
MIN_VALID_DATE: () => MIN_VALID_DATE,
|
|
54656
54681
|
SEPARATOR: () => SEPARATOR,
|
|
54657
54682
|
SQLITE_DESIGN_DOC_ID: () => SQLITE_DESIGN_DOC_ID,
|
|
54683
|
+
SQS_DATASOURCE_INTERNAL: () => SQS_DATASOURCE_INTERNAL,
|
|
54658
54684
|
StaticDatabases: () => StaticDatabases,
|
|
54659
54685
|
UNICODE_MAX: () => UNICODE_MAX,
|
|
54660
54686
|
UserStatus: () => UserStatus,
|
|
@@ -54715,8 +54741,14 @@ var StaticDatabases = {
|
|
|
54715
54741
|
var APP_PREFIX = prefixed("app" /* APP */);
|
|
54716
54742
|
var APP_DEV = prefixed("app_dev" /* APP_DEV */);
|
|
54717
54743
|
var APP_DEV_PREFIX = APP_DEV;
|
|
54744
|
+
var SQS_DATASOURCE_INTERNAL = "internal";
|
|
54718
54745
|
var BUDIBASE_DATASOURCE_TYPE = "budibase";
|
|
54719
54746
|
var SQLITE_DESIGN_DOC_ID = "_design/sqlite";
|
|
54747
|
+
var DEFAULT_JOBS_TABLE_ID = "ta_bb_jobs";
|
|
54748
|
+
var DEFAULT_INVENTORY_TABLE_ID = "ta_bb_inventory";
|
|
54749
|
+
var DEFAULT_EXPENSES_TABLE_ID = "ta_bb_expenses";
|
|
54750
|
+
var DEFAULT_EMPLOYEE_TABLE_ID = "ta_bb_employee";
|
|
54751
|
+
var DEFAULT_BB_DATASOURCE_ID = "datasource_internal_bb_default";
|
|
54720
54752
|
|
|
54721
54753
|
// ../shared-core/src/constants/api.ts
|
|
54722
54754
|
var Header = /* @__PURE__ */ ((Header2) => {
|
|
@@ -54854,6 +54886,19 @@ __export(filters_exports, {
|
|
|
54854
54886
|
});
|
|
54855
54887
|
var import_dayjs = __toESM(require_dayjs_min());
|
|
54856
54888
|
|
|
54889
|
+
// ../shared-core/src/helpers/index.ts
|
|
54890
|
+
var helpers_exports = {};
|
|
54891
|
+
__export(helpers_exports, {
|
|
54892
|
+
cron: () => cron_exports,
|
|
54893
|
+
deepGet: () => deepGet,
|
|
54894
|
+
getUserColor: () => getUserColor,
|
|
54895
|
+
getUserInitials: () => getUserInitials,
|
|
54896
|
+
getUserLabel: () => getUserLabel,
|
|
54897
|
+
isGoogleSheets: () => isGoogleSheets,
|
|
54898
|
+
isSQL: () => isSQL,
|
|
54899
|
+
schema: () => schema_exports
|
|
54900
|
+
});
|
|
54901
|
+
|
|
54857
54902
|
// ../shared-core/src/helpers/helpers.ts
|
|
54858
54903
|
var deepGet = (obj, key) => {
|
|
54859
54904
|
if (!obj || !key) {
|
|
@@ -54868,9 +54913,110 @@ var deepGet = (obj, key) => {
|
|
|
54868
54913
|
}
|
|
54869
54914
|
return obj;
|
|
54870
54915
|
};
|
|
54916
|
+
var getUserInitials = (user) => {
|
|
54917
|
+
if (!user) {
|
|
54918
|
+
return "?";
|
|
54919
|
+
}
|
|
54920
|
+
let initials = "";
|
|
54921
|
+
initials += user.firstName ? user.firstName[0] : "";
|
|
54922
|
+
initials += user.lastName ? user.lastName[0] : "";
|
|
54923
|
+
if (initials !== "") {
|
|
54924
|
+
return initials;
|
|
54925
|
+
}
|
|
54926
|
+
return user.email?.[0] || "U";
|
|
54927
|
+
};
|
|
54928
|
+
var getUserColor = (user) => {
|
|
54929
|
+
let id = user?._id;
|
|
54930
|
+
if (!id) {
|
|
54931
|
+
return "var(--spectrum-global-color-blue-400)";
|
|
54932
|
+
}
|
|
54933
|
+
id = id.replace("ro_ta_users_", "");
|
|
54934
|
+
let hue = 1;
|
|
54935
|
+
for (let i = 0; i < id.length; i++) {
|
|
54936
|
+
hue += id.charCodeAt(i);
|
|
54937
|
+
hue = hue % 36;
|
|
54938
|
+
}
|
|
54939
|
+
return `hsl(${hue * 10}, 50%, 40%)`;
|
|
54940
|
+
};
|
|
54941
|
+
var getUserLabel = (user) => {
|
|
54942
|
+
if (!user) {
|
|
54943
|
+
return "";
|
|
54944
|
+
}
|
|
54945
|
+
const { firstName, lastName, email } = user;
|
|
54946
|
+
if (firstName && lastName) {
|
|
54947
|
+
return `${firstName} ${lastName}`;
|
|
54948
|
+
} else if (firstName) {
|
|
54949
|
+
return firstName;
|
|
54950
|
+
} else if (lastName) {
|
|
54951
|
+
return lastName;
|
|
54952
|
+
} else {
|
|
54953
|
+
return email;
|
|
54954
|
+
}
|
|
54955
|
+
};
|
|
54956
|
+
|
|
54957
|
+
// ../shared-core/src/helpers/integrations.ts
|
|
54958
|
+
function isGoogleSheets(type) {
|
|
54959
|
+
return type === "GOOGLE_SHEETS" /* GOOGLE_SHEETS */;
|
|
54960
|
+
}
|
|
54961
|
+
function isSQL(datasource2) {
|
|
54962
|
+
if (!datasource2 || !datasource2.source) {
|
|
54963
|
+
return false;
|
|
54964
|
+
}
|
|
54965
|
+
const SQL = [
|
|
54966
|
+
"POSTGRES" /* POSTGRES */,
|
|
54967
|
+
"SQL_SERVER" /* SQL_SERVER */,
|
|
54968
|
+
"MYSQL" /* MYSQL */,
|
|
54969
|
+
"ORACLE" /* ORACLE */
|
|
54970
|
+
];
|
|
54971
|
+
return SQL.indexOf(datasource2.source) !== -1 || datasource2.isSQL === true;
|
|
54972
|
+
}
|
|
54871
54973
|
|
|
54872
54974
|
// ../shared-core/src/helpers/cron.ts
|
|
54975
|
+
var cron_exports = {};
|
|
54976
|
+
__export(cron_exports, {
|
|
54977
|
+
validate: () => validate
|
|
54978
|
+
});
|
|
54873
54979
|
var import_cron_validate = __toESM(require_lib2());
|
|
54980
|
+
var INPUT_CRON_START = "(Input cron: ";
|
|
54981
|
+
var ERROR_SWAPS = {
|
|
54982
|
+
"smaller than lower limit": "less than",
|
|
54983
|
+
"bigger than upper limit": "greater than",
|
|
54984
|
+
daysOfMonth: "'days of the month'",
|
|
54985
|
+
daysOfWeek: "'days of the week'",
|
|
54986
|
+
years: "'years'",
|
|
54987
|
+
months: "'months'",
|
|
54988
|
+
hours: "'hours'",
|
|
54989
|
+
minutes: "'minutes'",
|
|
54990
|
+
seconds: "'seconds'"
|
|
54991
|
+
};
|
|
54992
|
+
function improveErrors(errors) {
|
|
54993
|
+
const finalErrors = [];
|
|
54994
|
+
for (let error of errors) {
|
|
54995
|
+
if (error.includes(INPUT_CRON_START)) {
|
|
54996
|
+
error = error.split(INPUT_CRON_START)[0].trim();
|
|
54997
|
+
}
|
|
54998
|
+
for (let [oldErr, newErr] of Object.entries(ERROR_SWAPS)) {
|
|
54999
|
+
if (error.includes(oldErr)) {
|
|
55000
|
+
error = error.replace(new RegExp(oldErr, "g"), newErr);
|
|
55001
|
+
}
|
|
55002
|
+
}
|
|
55003
|
+
finalErrors.push(error);
|
|
55004
|
+
}
|
|
55005
|
+
return finalErrors;
|
|
55006
|
+
}
|
|
55007
|
+
function validate(cronExpression) {
|
|
55008
|
+
const result = (0, import_cron_validate.default)(cronExpression, {
|
|
55009
|
+
preset: "npm-node-cron",
|
|
55010
|
+
override: {
|
|
55011
|
+
useSeconds: false
|
|
55012
|
+
}
|
|
55013
|
+
});
|
|
55014
|
+
if (!result.isValid()) {
|
|
55015
|
+
return { valid: false, err: improveErrors(result.getError()) };
|
|
55016
|
+
} else {
|
|
55017
|
+
return { valid: true };
|
|
55018
|
+
}
|
|
55019
|
+
}
|
|
54874
55020
|
|
|
54875
55021
|
// ../shared-core/src/helpers/schema.ts
|
|
54876
55022
|
var schema_exports = {};
|
|
@@ -55191,10 +55337,10 @@ var luceneSort = (docs, sort, sortOrder, sortType = "string" /* STRING */) => {
|
|
|
55191
55337
|
if (!sort || !sortOrder || !sortType) {
|
|
55192
55338
|
return docs;
|
|
55193
55339
|
}
|
|
55194
|
-
const
|
|
55340
|
+
const parse2 = sortType === "string" ? (x) => `${x}` : (x) => parseFloat(x);
|
|
55195
55341
|
return docs.slice().sort((a, b) => {
|
|
55196
|
-
const colA =
|
|
55197
|
-
const colB =
|
|
55342
|
+
const colA = parse2(a[sort]);
|
|
55343
|
+
const colB = parse2(b[sort]);
|
|
55198
55344
|
if (sortOrder.toLowerCase() === "descending") {
|
|
55199
55345
|
return colA > colB ? -1 : 1;
|
|
55200
55346
|
} else {
|
|
@@ -55749,6 +55895,9 @@ var environment = {
|
|
|
55749
55895
|
DEPLOYMENT_ENVIRONMENT: process.env.DEPLOYMENT_ENVIRONMENT || "docker-compose",
|
|
55750
55896
|
HTTP_LOGGING: httpLogging(),
|
|
55751
55897
|
ENABLE_AUDIT_LOG_IP_ADDR: process.env.ENABLE_AUDIT_LOG_IP_ADDR,
|
|
55898
|
+
// Couch/search
|
|
55899
|
+
SQL_LOGGING_ENABLE: process.env.SQL_LOGGING_ENABLE,
|
|
55900
|
+
SQL_MAX_ROWS: process.env.SQL_MAX_ROWS,
|
|
55752
55901
|
// smtp
|
|
55753
55902
|
SMTP_FALLBACK_ENABLED: process.env.SMTP_FALLBACK_ENABLED,
|
|
55754
55903
|
SMTP_USER: process.env.SMTP_USER,
|
|
@@ -57089,6 +57238,11 @@ __export(db_exports, {
|
|
|
57089
57238
|
BUDIBASE_DATASOURCE_TYPE: () => BUDIBASE_DATASOURCE_TYPE,
|
|
57090
57239
|
CONSTANT_EXTERNAL_ROW_COLS: () => CONSTANT_EXTERNAL_ROW_COLS,
|
|
57091
57240
|
CONSTANT_INTERNAL_ROW_COLS: () => CONSTANT_INTERNAL_ROW_COLS,
|
|
57241
|
+
DEFAULT_BB_DATASOURCE_ID: () => DEFAULT_BB_DATASOURCE_ID,
|
|
57242
|
+
DEFAULT_EMPLOYEE_TABLE_ID: () => DEFAULT_EMPLOYEE_TABLE_ID,
|
|
57243
|
+
DEFAULT_EXPENSES_TABLE_ID: () => DEFAULT_EXPENSES_TABLE_ID,
|
|
57244
|
+
DEFAULT_INVENTORY_TABLE_ID: () => DEFAULT_INVENTORY_TABLE_ID,
|
|
57245
|
+
DEFAULT_JOBS_TABLE_ID: () => DEFAULT_JOBS_TABLE_ID,
|
|
57092
57246
|
DatabaseImpl: () => DatabaseImpl,
|
|
57093
57247
|
DatabaseWithConnection: () => DatabaseWithConnection,
|
|
57094
57248
|
DeprecatedViews: () => DeprecatedViews,
|
|
@@ -57098,6 +57252,7 @@ __export(db_exports, {
|
|
|
57098
57252
|
Replication: () => Replication_default,
|
|
57099
57253
|
SEPARATOR: () => SEPARATOR,
|
|
57100
57254
|
SQLITE_DESIGN_DOC_ID: () => SQLITE_DESIGN_DOC_ID,
|
|
57255
|
+
SQS_DATASOURCE_INTERNAL: () => SQS_DATASOURCE_INTERNAL,
|
|
57101
57256
|
StaticDatabases: () => StaticDatabases,
|
|
57102
57257
|
UNICODE_MAX: () => UNICODE_MAX,
|
|
57103
57258
|
ViewName: () => ViewName,
|
|
@@ -57798,7 +57953,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
57798
57953
|
static {
|
|
57799
57954
|
this.maxLimit = 200;
|
|
57800
57955
|
}
|
|
57801
|
-
constructor(dbName, index2,
|
|
57956
|
+
constructor(dbName, index2, base2) {
|
|
57802
57957
|
this.#dbName = dbName;
|
|
57803
57958
|
this.#index = index2;
|
|
57804
57959
|
this.#query = {
|
|
@@ -57815,7 +57970,7 @@ var QueryBuilder = class _QueryBuilder {
|
|
|
57815
57970
|
contains: {},
|
|
57816
57971
|
notContains: {},
|
|
57817
57972
|
containsAny: {},
|
|
57818
|
-
...
|
|
57973
|
+
...base2
|
|
57819
57974
|
};
|
|
57820
57975
|
this.#limit = 50;
|
|
57821
57976
|
this.#sortOrder = "ascending";
|
|
@@ -58531,6 +58686,9 @@ async function streamUpload({
|
|
|
58531
58686
|
extra,
|
|
58532
58687
|
ttl
|
|
58533
58688
|
}) {
|
|
58689
|
+
if (!stream3) {
|
|
58690
|
+
throw new Error("Stream to upload is invalid/undefined");
|
|
58691
|
+
}
|
|
58534
58692
|
const extension = filename.split(".").pop();
|
|
58535
58693
|
const objectStore = ObjectStore(bucketName);
|
|
58536
58694
|
const bucketCreated = await createBucketIfNotExists(objectStore, bucketName);
|
|
@@ -58553,14 +58711,23 @@ async function streamUpload({
|
|
|
58553
58711
|
if (!contentType) {
|
|
58554
58712
|
contentType = extension ? CONTENT_TYPE_MAP[extension.toLowerCase()] : CONTENT_TYPE_MAP.txt;
|
|
58555
58713
|
}
|
|
58714
|
+
const bucket = sanitizeBucket(bucketName), objKey = sanitizeKey(filename);
|
|
58556
58715
|
const params2 = {
|
|
58557
|
-
Bucket:
|
|
58558
|
-
Key:
|
|
58716
|
+
Bucket: bucket,
|
|
58717
|
+
Key: objKey,
|
|
58559
58718
|
Body: stream3,
|
|
58560
58719
|
ContentType: contentType,
|
|
58561
58720
|
...extra
|
|
58562
58721
|
};
|
|
58563
|
-
|
|
58722
|
+
const details = await objectStore.upload(params2).promise();
|
|
58723
|
+
const headDetails = await objectStore.headObject({
|
|
58724
|
+
Bucket: bucket,
|
|
58725
|
+
Key: objKey
|
|
58726
|
+
}).promise();
|
|
58727
|
+
return {
|
|
58728
|
+
...details,
|
|
58729
|
+
ContentLength: headDetails.ContentLength
|
|
58730
|
+
};
|
|
58564
58731
|
}
|
|
58565
58732
|
async function retrieve(bucketName, filepath) {
|
|
58566
58733
|
const objectStore = ObjectStore(bucketName);
|
|
@@ -64577,14 +64744,14 @@ function removePortalUserPermissions(user) {
|
|
|
64577
64744
|
delete user.builder;
|
|
64578
64745
|
return user;
|
|
64579
64746
|
}
|
|
64580
|
-
function cleanseUserObject(user,
|
|
64747
|
+
function cleanseUserObject(user, base2) {
|
|
64581
64748
|
delete user.admin;
|
|
64582
64749
|
delete user.builder;
|
|
64583
64750
|
delete user.roles;
|
|
64584
|
-
if (
|
|
64585
|
-
user.admin =
|
|
64586
|
-
user.builder =
|
|
64587
|
-
user.roles =
|
|
64751
|
+
if (base2) {
|
|
64752
|
+
user.admin = base2.admin;
|
|
64753
|
+
user.builder = base2.builder;
|
|
64754
|
+
user.roles = base2.roles;
|
|
64588
64755
|
}
|
|
64589
64756
|
return user;
|
|
64590
64757
|
}
|
|
@@ -65835,9 +66002,9 @@ function encrypt(input, secretOption = "api" /* API */) {
|
|
|
65835
66002
|
const salt = import_crypto.default.randomBytes(SALT_LENGTH);
|
|
65836
66003
|
const stretched = stretchString(getSecret(secretOption), salt);
|
|
65837
66004
|
const cipher = import_crypto.default.createCipheriv(ALGO, stretched, salt);
|
|
65838
|
-
const
|
|
66005
|
+
const base2 = cipher.update(input);
|
|
65839
66006
|
const final = cipher.final();
|
|
65840
|
-
const encrypted = Buffer.concat([
|
|
66007
|
+
const encrypted = Buffer.concat([base2, final]).toString("hex");
|
|
65841
66008
|
return `${salt.toString("hex")}${SEPARATOR3}${encrypted}`;
|
|
65842
66009
|
}
|
|
65843
66010
|
function decrypt(input, secretOption = "api" /* API */) {
|
|
@@ -65845,9 +66012,9 @@ function decrypt(input, secretOption = "api" /* API */) {
|
|
|
65845
66012
|
const saltBuffer = Buffer.from(salt, "hex");
|
|
65846
66013
|
const stretched = stretchString(getSecret(secretOption), saltBuffer);
|
|
65847
66014
|
const decipher = import_crypto.default.createDecipheriv(ALGO, stretched, saltBuffer);
|
|
65848
|
-
const
|
|
66015
|
+
const base2 = decipher.update(Buffer.from(encrypted, "hex"));
|
|
65849
66016
|
const final = decipher.final();
|
|
65850
|
-
return Buffer.concat([
|
|
66017
|
+
return Buffer.concat([base2, final]).toString();
|
|
65851
66018
|
}
|
|
65852
66019
|
async function encryptFile({ dir, filename }, secret) {
|
|
65853
66020
|
const outputFileName = `${filename}.enc`;
|
|
@@ -66299,7 +66466,7 @@ __export(joi_validator_exports, {
|
|
|
66299
66466
|
params: () => params
|
|
66300
66467
|
});
|
|
66301
66468
|
var import_joi = __toESM(require("joi"));
|
|
66302
|
-
function
|
|
66469
|
+
function validate2(schema, property) {
|
|
66303
66470
|
return (ctx, next) => {
|
|
66304
66471
|
if (!schema) {
|
|
66305
66472
|
return next();
|
|
@@ -66325,10 +66492,10 @@ function validate(schema, property) {
|
|
|
66325
66492
|
};
|
|
66326
66493
|
}
|
|
66327
66494
|
function body(schema) {
|
|
66328
|
-
return
|
|
66495
|
+
return validate2(schema, "body");
|
|
66329
66496
|
}
|
|
66330
66497
|
function params(schema) {
|
|
66331
|
-
return
|
|
66498
|
+
return validate2(schema, "params");
|
|
66332
66499
|
}
|
|
66333
66500
|
|
|
66334
66501
|
// src/middleware/index.ts
|
|
@@ -66464,7 +66631,7 @@ async function platformLogout(opts) {
|
|
|
66464
66631
|
// src/plugin/index.ts
|
|
66465
66632
|
var plugin_exports = {};
|
|
66466
66633
|
__export(plugin_exports, {
|
|
66467
|
-
validate: () =>
|
|
66634
|
+
validate: () => validate3
|
|
66468
66635
|
});
|
|
66469
66636
|
|
|
66470
66637
|
// src/plugin/utils.ts
|
|
@@ -66581,7 +66748,7 @@ function validateAutomation(schema) {
|
|
|
66581
66748
|
});
|
|
66582
66749
|
runJoi(validator, schema);
|
|
66583
66750
|
}
|
|
66584
|
-
function
|
|
66751
|
+
function validate3(schema) {
|
|
66585
66752
|
switch (schema?.type) {
|
|
66586
66753
|
case "component" /* COMPONENT */:
|
|
66587
66754
|
validateComponent(schema);
|
|
@@ -66738,6 +66905,1083 @@ function init8(processors2) {
|
|
|
66738
66905
|
}
|
|
66739
66906
|
}
|
|
66740
66907
|
|
|
66908
|
+
// src/sql/index.ts
|
|
66909
|
+
var sql_exports = {};
|
|
66910
|
+
__export(sql_exports, {
|
|
66911
|
+
Sql: () => sql_default,
|
|
66912
|
+
SqlTable: () => sqlTable_default,
|
|
66913
|
+
designDoc: () => designDoc_exports,
|
|
66914
|
+
utils: () => utils_exports5
|
|
66915
|
+
});
|
|
66916
|
+
|
|
66917
|
+
// src/sql/utils.ts
|
|
66918
|
+
var utils_exports5 = {};
|
|
66919
|
+
__export(utils_exports5, {
|
|
66920
|
+
breakExternalTableId: () => breakExternalTableId,
|
|
66921
|
+
breakRowIdField: () => breakRowIdField,
|
|
66922
|
+
buildExternalTableId: () => buildExternalTableId,
|
|
66923
|
+
convertRowId: () => convertRowId,
|
|
66924
|
+
generateRowIdField: () => generateRowIdField,
|
|
66925
|
+
getNativeSql: () => getNativeSql,
|
|
66926
|
+
isExternalTable: () => isExternalTable,
|
|
66927
|
+
isExternalTableID: () => isExternalTableID,
|
|
66928
|
+
isInternalTableID: () => isInternalTableID,
|
|
66929
|
+
isIsoDateString: () => isIsoDateString,
|
|
66930
|
+
isRowId: () => isRowId,
|
|
66931
|
+
isValidFilter: () => isValidFilter
|
|
66932
|
+
});
|
|
66933
|
+
var DOUBLE_SEPARATOR = `${SEPARATOR}${SEPARATOR}`;
|
|
66934
|
+
var ROW_ID_REGEX = /^\[.*]$/g;
|
|
66935
|
+
var ENCODED_SPACE = encodeURIComponent(" ");
|
|
66936
|
+
function isExternalTableID(tableId) {
|
|
66937
|
+
return tableId.startsWith("datasource" /* DATASOURCE */ + SEPARATOR);
|
|
66938
|
+
}
|
|
66939
|
+
function isInternalTableID(tableId) {
|
|
66940
|
+
return !isExternalTableID(tableId);
|
|
66941
|
+
}
|
|
66942
|
+
function getNativeSql(query) {
|
|
66943
|
+
let sql = query.toSQL();
|
|
66944
|
+
if (Array.isArray(sql)) {
|
|
66945
|
+
return sql;
|
|
66946
|
+
}
|
|
66947
|
+
let native;
|
|
66948
|
+
if (sql.toNative) {
|
|
66949
|
+
native = sql.toNative();
|
|
66950
|
+
}
|
|
66951
|
+
return {
|
|
66952
|
+
sql: native?.sql || sql.sql,
|
|
66953
|
+
bindings: native?.bindings || sql.bindings
|
|
66954
|
+
};
|
|
66955
|
+
}
|
|
66956
|
+
function isExternalTable(table) {
|
|
66957
|
+
if (table?.sourceId && table.sourceId.includes("datasource" /* DATASOURCE */ + SEPARATOR) && table?.sourceId !== DEFAULT_BB_DATASOURCE_ID) {
|
|
66958
|
+
return true;
|
|
66959
|
+
} else if (table?.sourceType === "external" /* EXTERNAL */) {
|
|
66960
|
+
return true;
|
|
66961
|
+
} else if (table?._id && isExternalTableID(table._id)) {
|
|
66962
|
+
return true;
|
|
66963
|
+
}
|
|
66964
|
+
return false;
|
|
66965
|
+
}
|
|
66966
|
+
function buildExternalTableId(datasourceId, tableName) {
|
|
66967
|
+
if (tableName.includes(" ")) {
|
|
66968
|
+
tableName = encodeURIComponent(tableName);
|
|
66969
|
+
}
|
|
66970
|
+
return `${datasourceId}${DOUBLE_SEPARATOR}${tableName}`;
|
|
66971
|
+
}
|
|
66972
|
+
function breakExternalTableId(tableId) {
|
|
66973
|
+
if (!tableId) {
|
|
66974
|
+
return {};
|
|
66975
|
+
}
|
|
66976
|
+
const parts = tableId.split(DOUBLE_SEPARATOR);
|
|
66977
|
+
let datasourceId = parts.shift();
|
|
66978
|
+
let tableName = parts.join(DOUBLE_SEPARATOR);
|
|
66979
|
+
if (tableName.includes(ENCODED_SPACE)) {
|
|
66980
|
+
tableName = decodeURIComponent(tableName);
|
|
66981
|
+
}
|
|
66982
|
+
return { datasourceId, tableName };
|
|
66983
|
+
}
|
|
66984
|
+
function generateRowIdField(keyProps = []) {
|
|
66985
|
+
if (!Array.isArray(keyProps)) {
|
|
66986
|
+
keyProps = [keyProps];
|
|
66987
|
+
}
|
|
66988
|
+
for (let index2 in keyProps) {
|
|
66989
|
+
if (keyProps[index2] instanceof Buffer) {
|
|
66990
|
+
keyProps[index2] = keyProps[index2].toString();
|
|
66991
|
+
}
|
|
66992
|
+
}
|
|
66993
|
+
return encodeURIComponent(JSON.stringify(keyProps).replace(/"/g, "'"));
|
|
66994
|
+
}
|
|
66995
|
+
function isRowId(field) {
|
|
66996
|
+
return Array.isArray(field) || typeof field === "string" && field.match(ROW_ID_REGEX) != null;
|
|
66997
|
+
}
|
|
66998
|
+
function convertRowId(field) {
|
|
66999
|
+
if (Array.isArray(field)) {
|
|
67000
|
+
return field[0];
|
|
67001
|
+
}
|
|
67002
|
+
if (typeof field === "string" && field.match(ROW_ID_REGEX) != null) {
|
|
67003
|
+
return field.substring(1, field.length - 1);
|
|
67004
|
+
}
|
|
67005
|
+
return field;
|
|
67006
|
+
}
|
|
67007
|
+
function breakRowIdField(_id) {
|
|
67008
|
+
if (!_id) {
|
|
67009
|
+
return [];
|
|
67010
|
+
}
|
|
67011
|
+
const id = typeof _id === "string" ? _id : _id._id;
|
|
67012
|
+
const decoded = decodeURIComponent(id).replace(/'/g, '"');
|
|
67013
|
+
try {
|
|
67014
|
+
const parsed = JSON.parse(decoded);
|
|
67015
|
+
return Array.isArray(parsed) ? parsed : [parsed];
|
|
67016
|
+
} catch (err) {
|
|
67017
|
+
return [_id];
|
|
67018
|
+
}
|
|
67019
|
+
}
|
|
67020
|
+
function isIsoDateString(str) {
|
|
67021
|
+
const trimmedValue = str.trim();
|
|
67022
|
+
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z$/.test(trimmedValue)) {
|
|
67023
|
+
return false;
|
|
67024
|
+
}
|
|
67025
|
+
let d = new Date(trimmedValue);
|
|
67026
|
+
return d.toISOString() === trimmedValue;
|
|
67027
|
+
}
|
|
67028
|
+
function isValidFilter(value) {
|
|
67029
|
+
return value != null && value !== "";
|
|
67030
|
+
}
|
|
67031
|
+
|
|
67032
|
+
// src/sql/sql.ts
|
|
67033
|
+
var import_knex2 = require("knex");
|
|
67034
|
+
|
|
67035
|
+
// src/sql/sqlStatements.ts
|
|
67036
|
+
var SqlStatements = class {
|
|
67037
|
+
constructor(client, table, { allOr } = {}) {
|
|
67038
|
+
this.client = client;
|
|
67039
|
+
this.table = table;
|
|
67040
|
+
this.allOr = allOr;
|
|
67041
|
+
}
|
|
67042
|
+
getField(key) {
|
|
67043
|
+
const fieldName = key.split(".")[1];
|
|
67044
|
+
return this.table.schema[fieldName];
|
|
67045
|
+
}
|
|
67046
|
+
between(query, key, low, high) {
|
|
67047
|
+
const field = this.getField(key);
|
|
67048
|
+
if (field?.type === "bigint" /* BIGINT */ && this.client === "sqlite3" /* SQL_LITE */) {
|
|
67049
|
+
query = query.whereRaw(
|
|
67050
|
+
`CAST(${key} AS INTEGER) BETWEEN CAST(? AS INTEGER) AND CAST(? AS INTEGER)`,
|
|
67051
|
+
[low, high]
|
|
67052
|
+
);
|
|
67053
|
+
} else {
|
|
67054
|
+
const fnc = this.allOr ? "orWhereBetween" : "whereBetween";
|
|
67055
|
+
query = query[fnc](key, [low, high]);
|
|
67056
|
+
}
|
|
67057
|
+
return query;
|
|
67058
|
+
}
|
|
67059
|
+
lte(query, key, low) {
|
|
67060
|
+
const field = this.getField(key);
|
|
67061
|
+
if (field?.type === "bigint" /* BIGINT */ && this.client === "sqlite3" /* SQL_LITE */) {
|
|
67062
|
+
query = query.whereRaw(`CAST(${key} AS INTEGER) >= CAST(? AS INTEGER)`, [
|
|
67063
|
+
low
|
|
67064
|
+
]);
|
|
67065
|
+
} else {
|
|
67066
|
+
const fnc = this.allOr ? "orWhere" : "where";
|
|
67067
|
+
query = query[fnc](key, ">=", low);
|
|
67068
|
+
}
|
|
67069
|
+
return query;
|
|
67070
|
+
}
|
|
67071
|
+
gte(query, key, high) {
|
|
67072
|
+
const field = this.getField(key);
|
|
67073
|
+
if (field?.type === "bigint" /* BIGINT */ && this.client === "sqlite3" /* SQL_LITE */) {
|
|
67074
|
+
query = query.whereRaw(`CAST(${key} AS INTEGER) <= CAST(? AS INTEGER)`, [
|
|
67075
|
+
high
|
|
67076
|
+
]);
|
|
67077
|
+
} else {
|
|
67078
|
+
const fnc = this.allOr ? "orWhere" : "where";
|
|
67079
|
+
query = query[fnc](key, "<=", high);
|
|
67080
|
+
}
|
|
67081
|
+
return query;
|
|
67082
|
+
}
|
|
67083
|
+
};
|
|
67084
|
+
|
|
67085
|
+
// src/sql/sqlTable.ts
|
|
67086
|
+
var import_knex = require("knex");
|
|
67087
|
+
function isIgnoredType(type) {
|
|
67088
|
+
const ignored = ["link" /* LINK */, "formula" /* FORMULA */];
|
|
67089
|
+
return ignored.indexOf(type) !== -1;
|
|
67090
|
+
}
|
|
67091
|
+
function generateSchema(schema, table, tables, oldTable = null, renamed) {
|
|
67092
|
+
let primaryKey = table && table.primary ? table.primary[0] : null;
|
|
67093
|
+
const columns = Object.values(table.schema);
|
|
67094
|
+
let metaCols = columns.filter((col) => col.meta);
|
|
67095
|
+
let isJunction = metaCols.length === columns.length;
|
|
67096
|
+
if (primaryKey && !oldTable && !isJunction) {
|
|
67097
|
+
schema.increments(primaryKey).primary();
|
|
67098
|
+
} else if (!oldTable && isJunction) {
|
|
67099
|
+
schema.primary(metaCols.map((col) => col.name));
|
|
67100
|
+
}
|
|
67101
|
+
const foreignKeys = Object.values(table.schema).map(
|
|
67102
|
+
(col) => col.foreignKey
|
|
67103
|
+
);
|
|
67104
|
+
for (let [key, column] of Object.entries(table.schema)) {
|
|
67105
|
+
const oldColumn = oldTable ? oldTable.schema[key] : null;
|
|
67106
|
+
if (oldColumn && oldColumn.type || primaryKey === key && !isJunction || renamed?.updated === key) {
|
|
67107
|
+
continue;
|
|
67108
|
+
}
|
|
67109
|
+
const columnType = column.type;
|
|
67110
|
+
switch (columnType) {
|
|
67111
|
+
case "string" /* STRING */:
|
|
67112
|
+
case "options" /* OPTIONS */:
|
|
67113
|
+
case "longform" /* LONGFORM */:
|
|
67114
|
+
case "barcodeqr" /* BARCODEQR */:
|
|
67115
|
+
case "bb_reference_single" /* BB_REFERENCE_SINGLE */:
|
|
67116
|
+
schema.text(key);
|
|
67117
|
+
break;
|
|
67118
|
+
case "number" /* NUMBER */:
|
|
67119
|
+
if (column.meta && column.meta.toKey && column.meta.toTable) {
|
|
67120
|
+
const { toKey, toTable } = column.meta;
|
|
67121
|
+
schema.integer(key).unsigned();
|
|
67122
|
+
schema.foreign(key).references(`${toTable}.${toKey}`);
|
|
67123
|
+
} else if (foreignKeys.indexOf(key) === -1) {
|
|
67124
|
+
schema.float(key);
|
|
67125
|
+
}
|
|
67126
|
+
break;
|
|
67127
|
+
case "bigint" /* BIGINT */:
|
|
67128
|
+
schema.bigint(key);
|
|
67129
|
+
break;
|
|
67130
|
+
case "boolean" /* BOOLEAN */:
|
|
67131
|
+
schema.boolean(key);
|
|
67132
|
+
break;
|
|
67133
|
+
case "datetime" /* DATETIME */:
|
|
67134
|
+
if (!column.timeOnly) {
|
|
67135
|
+
schema.datetime(key, {
|
|
67136
|
+
useTz: !column.ignoreTimezones
|
|
67137
|
+
});
|
|
67138
|
+
} else {
|
|
67139
|
+
schema.time(key);
|
|
67140
|
+
}
|
|
67141
|
+
break;
|
|
67142
|
+
case "array" /* ARRAY */:
|
|
67143
|
+
case "bb_reference" /* BB_REFERENCE */:
|
|
67144
|
+
if (helpers_exports.schema.isDeprecatedSingleUserColumn(column)) {
|
|
67145
|
+
schema.text(key);
|
|
67146
|
+
} else {
|
|
67147
|
+
schema.json(key);
|
|
67148
|
+
}
|
|
67149
|
+
break;
|
|
67150
|
+
case "link" /* LINK */:
|
|
67151
|
+
if (column.relationshipType !== "many-to-one" /* MANY_TO_ONE */ && column.relationshipType !== "many-to-many" /* MANY_TO_MANY */) {
|
|
67152
|
+
if (!column.foreignKey || !column.tableId) {
|
|
67153
|
+
throw new Error("Invalid relationship schema");
|
|
67154
|
+
}
|
|
67155
|
+
const { tableName } = breakExternalTableId(column.tableId);
|
|
67156
|
+
const relatedTable = tables[tableName];
|
|
67157
|
+
if (!relatedTable) {
|
|
67158
|
+
throw new Error("Referenced table doesn't exist");
|
|
67159
|
+
}
|
|
67160
|
+
const relatedPrimary = relatedTable.primary[0];
|
|
67161
|
+
const externalType = relatedTable.schema[relatedPrimary].externalType;
|
|
67162
|
+
if (externalType) {
|
|
67163
|
+
schema.specificType(column.foreignKey, externalType);
|
|
67164
|
+
} else {
|
|
67165
|
+
schema.integer(column.foreignKey).unsigned();
|
|
67166
|
+
}
|
|
67167
|
+
schema.foreign(column.foreignKey).references(`${tableName}.${relatedPrimary}`);
|
|
67168
|
+
}
|
|
67169
|
+
break;
|
|
67170
|
+
case "formula" /* FORMULA */:
|
|
67171
|
+
break;
|
|
67172
|
+
case "attachment" /* ATTACHMENTS */:
|
|
67173
|
+
case "attachment_single" /* ATTACHMENT_SINGLE */:
|
|
67174
|
+
case "signature_single" /* SIGNATURE_SINGLE */:
|
|
67175
|
+
case "auto" /* AUTO */:
|
|
67176
|
+
case "json" /* JSON */:
|
|
67177
|
+
case "internal" /* INTERNAL */:
|
|
67178
|
+
throw `${column.type} is not a valid SQL type`;
|
|
67179
|
+
default:
|
|
67180
|
+
utils_exports.unreachable(columnType);
|
|
67181
|
+
}
|
|
67182
|
+
}
|
|
67183
|
+
const oldType = renamed ? oldTable?.schema[renamed.old].type : void 0;
|
|
67184
|
+
if (renamed && oldType && !isIgnoredType(oldType)) {
|
|
67185
|
+
schema.renameColumn(renamed.old, renamed.updated);
|
|
67186
|
+
}
|
|
67187
|
+
if (oldTable) {
|
|
67188
|
+
const deletedColumns = Object.entries(oldTable.schema).filter(
|
|
67189
|
+
([key, column]) => !isIgnoredType(column.type) && table.schema[key] == null
|
|
67190
|
+
);
|
|
67191
|
+
deletedColumns.forEach(([key, column]) => {
|
|
67192
|
+
if (renamed?.old === key || isIgnoredType(column.type)) {
|
|
67193
|
+
return;
|
|
67194
|
+
}
|
|
67195
|
+
if (oldTable.constrained && oldTable.constrained.indexOf(key) !== -1) {
|
|
67196
|
+
schema.dropForeign(key);
|
|
67197
|
+
}
|
|
67198
|
+
schema.dropColumn(key);
|
|
67199
|
+
});
|
|
67200
|
+
}
|
|
67201
|
+
return schema;
|
|
67202
|
+
}
|
|
67203
|
+
function buildCreateTable(knex3, table, tables) {
|
|
67204
|
+
return knex3.createTable(table.name, (schema) => {
|
|
67205
|
+
generateSchema(schema, table, tables);
|
|
67206
|
+
});
|
|
67207
|
+
}
|
|
67208
|
+
function buildUpdateTable(knex3, table, tables, oldTable, renamed) {
|
|
67209
|
+
return knex3.alterTable(table.name, (schema) => {
|
|
67210
|
+
generateSchema(schema, table, tables, oldTable, renamed);
|
|
67211
|
+
});
|
|
67212
|
+
}
|
|
67213
|
+
function buildDeleteTable(knex3, table) {
|
|
67214
|
+
return knex3.dropTable(table.name);
|
|
67215
|
+
}
|
|
67216
|
+
var SqlTableQueryBuilder = class {
|
|
67217
|
+
// pass through client to get flavour of SQL
|
|
67218
|
+
constructor(client) {
|
|
67219
|
+
this.sqlClient = client;
|
|
67220
|
+
}
|
|
67221
|
+
getSqlClient() {
|
|
67222
|
+
return this.sqlClient;
|
|
67223
|
+
}
|
|
67224
|
+
/**
|
|
67225
|
+
* @param json the input JSON structure from which an SQL query will be built.
|
|
67226
|
+
* @return the operation that was found in the JSON.
|
|
67227
|
+
*/
|
|
67228
|
+
_operation(json) {
|
|
67229
|
+
return json.endpoint.operation;
|
|
67230
|
+
}
|
|
67231
|
+
_tableQuery(json) {
|
|
67232
|
+
let client = (0, import_knex.knex)({ client: this.sqlClient }).schema;
|
|
67233
|
+
let schemaName = json?.endpoint?.schema;
|
|
67234
|
+
if (schemaName) {
|
|
67235
|
+
client = client.withSchema(schemaName);
|
|
67236
|
+
}
|
|
67237
|
+
let query;
|
|
67238
|
+
if (!json.table || !json.meta || !json.meta.tables) {
|
|
67239
|
+
throw new Error("Cannot execute without table being specified");
|
|
67240
|
+
}
|
|
67241
|
+
if (json.table.sourceType === "internal" /* INTERNAL */) {
|
|
67242
|
+
throw new Error("Cannot perform table actions for SQS.");
|
|
67243
|
+
}
|
|
67244
|
+
switch (this._operation(json)) {
|
|
67245
|
+
case "CREATE_TABLE" /* CREATE_TABLE */:
|
|
67246
|
+
query = buildCreateTable(client, json.table, json.meta.tables);
|
|
67247
|
+
break;
|
|
67248
|
+
case "UPDATE_TABLE" /* UPDATE_TABLE */:
|
|
67249
|
+
if (!json.meta || !json.meta.table) {
|
|
67250
|
+
throw new Error("Must specify old table for update");
|
|
67251
|
+
}
|
|
67252
|
+
if (this.sqlClient === "mysql2" /* MY_SQL */ && json.meta.renamed) {
|
|
67253
|
+
const updatedColumn = json.meta.renamed.updated;
|
|
67254
|
+
const tableName = schemaName ? `\`${schemaName}\`.\`${json.table.name}\`` : `\`${json.table.name}\``;
|
|
67255
|
+
return {
|
|
67256
|
+
sql: `alter table ${tableName} rename column \`${json.meta.renamed.old}\` to \`${updatedColumn}\`;`,
|
|
67257
|
+
bindings: []
|
|
67258
|
+
};
|
|
67259
|
+
}
|
|
67260
|
+
query = buildUpdateTable(
|
|
67261
|
+
client,
|
|
67262
|
+
json.table,
|
|
67263
|
+
json.meta.tables,
|
|
67264
|
+
json.meta.table,
|
|
67265
|
+
json.meta.renamed
|
|
67266
|
+
);
|
|
67267
|
+
if (this.sqlClient === "mssql" /* MS_SQL */ && json.meta.renamed) {
|
|
67268
|
+
const oldColumn = json.meta.renamed.old;
|
|
67269
|
+
const updatedColumn = json.meta.renamed.updated;
|
|
67270
|
+
const tableName = schemaName ? `${schemaName}.${json.table.name}` : `${json.table.name}`;
|
|
67271
|
+
const sql = getNativeSql(query);
|
|
67272
|
+
if (Array.isArray(sql)) {
|
|
67273
|
+
for (const query2 of sql) {
|
|
67274
|
+
if (query2.sql.startsWith("exec sp_rename")) {
|
|
67275
|
+
query2.sql = `exec sp_rename '${tableName}.${oldColumn}', '${updatedColumn}', 'COLUMN'`;
|
|
67276
|
+
query2.bindings = [];
|
|
67277
|
+
}
|
|
67278
|
+
}
|
|
67279
|
+
}
|
|
67280
|
+
return sql;
|
|
67281
|
+
}
|
|
67282
|
+
break;
|
|
67283
|
+
case "DELETE_TABLE" /* DELETE_TABLE */:
|
|
67284
|
+
query = buildDeleteTable(client, json.table);
|
|
67285
|
+
break;
|
|
67286
|
+
default:
|
|
67287
|
+
throw new Error("Table operation is of unknown type");
|
|
67288
|
+
}
|
|
67289
|
+
return getNativeSql(query);
|
|
67290
|
+
}
|
|
67291
|
+
};
|
|
67292
|
+
var sqlTable_default = SqlTableQueryBuilder;
|
|
67293
|
+
|
|
67294
|
+
// src/sql/sql.ts
|
|
67295
|
+
var envLimit = environment_default.SQL_MAX_ROWS ? parseInt(environment_default.SQL_MAX_ROWS) : null;
|
|
67296
|
+
var BASE_LIMIT = envLimit || 5e3;
|
|
67297
|
+
var MIN_ISO_DATE = "0000-00-00T00:00:00.000Z";
|
|
67298
|
+
var MAX_ISO_DATE = "9999-00-00T00:00:00.000Z";
|
|
67299
|
+
function likeKey(client, key) {
|
|
67300
|
+
let start2, end2;
|
|
67301
|
+
switch (client) {
|
|
67302
|
+
case "mysql2" /* MY_SQL */:
|
|
67303
|
+
start2 = end2 = "`";
|
|
67304
|
+
break;
|
|
67305
|
+
case "sqlite3" /* SQL_LITE */:
|
|
67306
|
+
case "oracledb" /* ORACLE */:
|
|
67307
|
+
case "pg" /* POSTGRES */:
|
|
67308
|
+
start2 = end2 = '"';
|
|
67309
|
+
break;
|
|
67310
|
+
case "mssql" /* MS_SQL */:
|
|
67311
|
+
start2 = "[";
|
|
67312
|
+
end2 = "]";
|
|
67313
|
+
break;
|
|
67314
|
+
default:
|
|
67315
|
+
throw new Error("Unknown client generating like key");
|
|
67316
|
+
}
|
|
67317
|
+
const parts = key.split(".");
|
|
67318
|
+
key = parts.map((part) => `${start2}${part}${end2}`).join(".");
|
|
67319
|
+
return key;
|
|
67320
|
+
}
|
|
67321
|
+
function parse(input) {
|
|
67322
|
+
if (Array.isArray(input)) {
|
|
67323
|
+
return JSON.stringify(input);
|
|
67324
|
+
}
|
|
67325
|
+
if (input == void 0) {
|
|
67326
|
+
return null;
|
|
67327
|
+
}
|
|
67328
|
+
if (typeof input !== "string") {
|
|
67329
|
+
return input;
|
|
67330
|
+
}
|
|
67331
|
+
if (input === MAX_ISO_DATE || input === MIN_ISO_DATE) {
|
|
67332
|
+
return null;
|
|
67333
|
+
}
|
|
67334
|
+
if (isIsoDateString(input)) {
|
|
67335
|
+
return new Date(input.trim());
|
|
67336
|
+
}
|
|
67337
|
+
return input;
|
|
67338
|
+
}
|
|
67339
|
+
function parseBody(body2) {
|
|
67340
|
+
for (let [key, value] of Object.entries(body2)) {
|
|
67341
|
+
body2[key] = parse(value);
|
|
67342
|
+
}
|
|
67343
|
+
return body2;
|
|
67344
|
+
}
|
|
67345
|
+
function parseFilters(filters) {
|
|
67346
|
+
if (!filters) {
|
|
67347
|
+
return {};
|
|
67348
|
+
}
|
|
67349
|
+
for (let [key, value] of Object.entries(filters)) {
|
|
67350
|
+
let parsed;
|
|
67351
|
+
if (typeof value === "object") {
|
|
67352
|
+
parsed = parseFilters(value);
|
|
67353
|
+
} else {
|
|
67354
|
+
parsed = parse(value);
|
|
67355
|
+
}
|
|
67356
|
+
filters[key] = parsed;
|
|
67357
|
+
}
|
|
67358
|
+
return filters;
|
|
67359
|
+
}
|
|
67360
|
+
function generateSelectStatement(json, knex3) {
|
|
67361
|
+
const { resource, meta } = json;
|
|
67362
|
+
if (!resource) {
|
|
67363
|
+
return "*";
|
|
67364
|
+
}
|
|
67365
|
+
const schema = meta?.table?.schema;
|
|
67366
|
+
return resource.fields.map((field) => {
|
|
67367
|
+
const fieldNames = field.split(/\./g);
|
|
67368
|
+
const tableName = fieldNames[0];
|
|
67369
|
+
const columnName = fieldNames[1];
|
|
67370
|
+
const columnSchema = schema?.[columnName];
|
|
67371
|
+
if (columnSchema && knex3.client.config.client === "pg" /* POSTGRES */) {
|
|
67372
|
+
const externalType = schema[columnName].externalType;
|
|
67373
|
+
if (externalType?.includes("money")) {
|
|
67374
|
+
return knex3.raw(
|
|
67375
|
+
`"${tableName}"."${columnName}"::money::numeric as "${field}"`
|
|
67376
|
+
);
|
|
67377
|
+
}
|
|
67378
|
+
}
|
|
67379
|
+
if (knex3.client.config.client === "mssql" /* MS_SQL */ && columnSchema?.type === "datetime" /* DATETIME */ && columnSchema.timeOnly) {
|
|
67380
|
+
return knex3.raw(`CONVERT(varchar, ${field}, 108) as "${field}"`);
|
|
67381
|
+
}
|
|
67382
|
+
return `${field} as ${field}`;
|
|
67383
|
+
});
|
|
67384
|
+
}
|
|
67385
|
+
function getTableName(table) {
|
|
67386
|
+
if (table?.sourceType === "internal" /* INTERNAL */ || table?.sourceId === INTERNAL_TABLE_SOURCE_ID) {
|
|
67387
|
+
return table?._id;
|
|
67388
|
+
} else {
|
|
67389
|
+
return table?.name;
|
|
67390
|
+
}
|
|
67391
|
+
}
|
|
67392
|
+
function convertBooleans(query) {
|
|
67393
|
+
if (Array.isArray(query)) {
|
|
67394
|
+
return query.map((q2) => convertBooleans(q2));
|
|
67395
|
+
} else {
|
|
67396
|
+
if (query.bindings) {
|
|
67397
|
+
query.bindings = query.bindings.map((binding) => {
|
|
67398
|
+
if (typeof binding === "boolean") {
|
|
67399
|
+
return binding ? 1 : 0;
|
|
67400
|
+
}
|
|
67401
|
+
return binding;
|
|
67402
|
+
});
|
|
67403
|
+
}
|
|
67404
|
+
}
|
|
67405
|
+
return query;
|
|
67406
|
+
}
|
|
67407
|
+
var InternalBuilder = class {
|
|
67408
|
+
constructor(client) {
|
|
67409
|
+
this.client = client;
|
|
67410
|
+
}
|
|
67411
|
+
// right now we only do filters on the specific table being queried
|
|
67412
|
+
addFilters(query, filters, table, opts) {
|
|
67413
|
+
if (!filters) {
|
|
67414
|
+
return query;
|
|
67415
|
+
}
|
|
67416
|
+
filters = parseFilters(filters);
|
|
67417
|
+
const allOr = filters.allOr;
|
|
67418
|
+
const sqlStatements = new SqlStatements(this.client, table, { allOr });
|
|
67419
|
+
const tableName = this.client === "sqlite3" /* SQL_LITE */ ? table._id : table.name;
|
|
67420
|
+
function getTableAlias(name) {
|
|
67421
|
+
const alias = opts.aliases?.[name];
|
|
67422
|
+
return alias || name;
|
|
67423
|
+
}
|
|
67424
|
+
function iterate(structure, fn) {
|
|
67425
|
+
for (let [key, value] of Object.entries(structure)) {
|
|
67426
|
+
const updatedKey = removeKeyNumbering2(key);
|
|
67427
|
+
const isRelationshipField = updatedKey.includes(".");
|
|
67428
|
+
if (!opts.relationship && !isRelationshipField) {
|
|
67429
|
+
const alias = getTableAlias(tableName);
|
|
67430
|
+
fn(alias ? `${alias}.${updatedKey}` : updatedKey, value);
|
|
67431
|
+
}
|
|
67432
|
+
if (opts.relationship && isRelationshipField) {
|
|
67433
|
+
const [filterTableName, property] = updatedKey.split(".");
|
|
67434
|
+
const alias = getTableAlias(filterTableName);
|
|
67435
|
+
fn(alias ? `${alias}.${property}` : property, value);
|
|
67436
|
+
}
|
|
67437
|
+
}
|
|
67438
|
+
}
|
|
67439
|
+
const like = (key, value) => {
|
|
67440
|
+
const fuzzyOr = filters?.fuzzyOr;
|
|
67441
|
+
const fnc = fuzzyOr || allOr ? "orWhere" : "where";
|
|
67442
|
+
if (this.client === "pg" /* POSTGRES */) {
|
|
67443
|
+
query = query[fnc](key, "ilike", `%${value}%`);
|
|
67444
|
+
} else {
|
|
67445
|
+
const rawFnc = `${fnc}Raw`;
|
|
67446
|
+
query = query[rawFnc](`LOWER(${likeKey(this.client, key)}) LIKE ?`, [
|
|
67447
|
+
`%${value.toLowerCase()}%`
|
|
67448
|
+
]);
|
|
67449
|
+
}
|
|
67450
|
+
};
|
|
67451
|
+
const contains = (mode, any = false) => {
|
|
67452
|
+
const rawFnc = allOr ? "orWhereRaw" : "whereRaw";
|
|
67453
|
+
const not = mode === filters?.notContains ? "NOT " : "";
|
|
67454
|
+
function stringifyArray(value, quoteStyle = '"') {
|
|
67455
|
+
for (let i in value) {
|
|
67456
|
+
if (typeof value[i] === "string") {
|
|
67457
|
+
value[i] = `${quoteStyle}${value[i]}${quoteStyle}`;
|
|
67458
|
+
}
|
|
67459
|
+
}
|
|
67460
|
+
return `[${value.join(",")}]`;
|
|
67461
|
+
}
|
|
67462
|
+
if (this.client === "pg" /* POSTGRES */) {
|
|
67463
|
+
iterate(mode, (key, value) => {
|
|
67464
|
+
const wrap = any ? "" : "'";
|
|
67465
|
+
const op = any ? "\\?| array" : "@>";
|
|
67466
|
+
const fieldNames = key.split(/\./g);
|
|
67467
|
+
const table2 = fieldNames[0];
|
|
67468
|
+
const col = fieldNames[1];
|
|
67469
|
+
query = query[rawFnc](
|
|
67470
|
+
`${not}COALESCE("${table2}"."${col}"::jsonb ${op} ${wrap}${stringifyArray(
|
|
67471
|
+
value,
|
|
67472
|
+
any ? "'" : '"'
|
|
67473
|
+
)}${wrap}, FALSE)`
|
|
67474
|
+
);
|
|
67475
|
+
});
|
|
67476
|
+
} else if (this.client === "mysql2" /* MY_SQL */) {
|
|
67477
|
+
const jsonFnc = any ? "JSON_OVERLAPS" : "JSON_CONTAINS";
|
|
67478
|
+
iterate(mode, (key, value) => {
|
|
67479
|
+
query = query[rawFnc](
|
|
67480
|
+
`${not}COALESCE(${jsonFnc}(${key}, '${stringifyArray(
|
|
67481
|
+
value
|
|
67482
|
+
)}'), FALSE)`
|
|
67483
|
+
);
|
|
67484
|
+
});
|
|
67485
|
+
} else {
|
|
67486
|
+
const andOr = mode === filters?.containsAny ? " OR " : " AND ";
|
|
67487
|
+
iterate(mode, (key, value) => {
|
|
67488
|
+
let statement = "";
|
|
67489
|
+
for (let i in value) {
|
|
67490
|
+
if (typeof value[i] === "string") {
|
|
67491
|
+
value[i] = `%"${value[i].toLowerCase()}"%`;
|
|
67492
|
+
} else {
|
|
67493
|
+
value[i] = `%${value[i]}%`;
|
|
67494
|
+
}
|
|
67495
|
+
statement += (statement ? andOr : "") + `COALESCE(LOWER(${likeKey(this.client, key)}), '') LIKE ?`;
|
|
67496
|
+
}
|
|
67497
|
+
if (statement === "") {
|
|
67498
|
+
return;
|
|
67499
|
+
}
|
|
67500
|
+
query = query[rawFnc](`${not}(${statement})`, value);
|
|
67501
|
+
});
|
|
67502
|
+
}
|
|
67503
|
+
};
|
|
67504
|
+
if (filters.oneOf) {
|
|
67505
|
+
iterate(filters.oneOf, (key, array) => {
|
|
67506
|
+
const fnc = allOr ? "orWhereIn" : "whereIn";
|
|
67507
|
+
query = query[fnc](key, Array.isArray(array) ? array : [array]);
|
|
67508
|
+
});
|
|
67509
|
+
}
|
|
67510
|
+
if (filters.string) {
|
|
67511
|
+
iterate(filters.string, (key, value) => {
|
|
67512
|
+
const fnc = allOr ? "orWhere" : "where";
|
|
67513
|
+
if (this.client === "pg" /* POSTGRES */) {
|
|
67514
|
+
query = query[fnc](key, "ilike", `${value}%`);
|
|
67515
|
+
} else {
|
|
67516
|
+
const rawFnc = `${fnc}Raw`;
|
|
67517
|
+
query = query[rawFnc](`LOWER(${likeKey(this.client, key)}) LIKE ?`, [
|
|
67518
|
+
`${value.toLowerCase()}%`
|
|
67519
|
+
]);
|
|
67520
|
+
}
|
|
67521
|
+
});
|
|
67522
|
+
}
|
|
67523
|
+
if (filters.fuzzy) {
|
|
67524
|
+
iterate(filters.fuzzy, like);
|
|
67525
|
+
}
|
|
67526
|
+
if (filters.range) {
|
|
67527
|
+
iterate(filters.range, (key, value) => {
|
|
67528
|
+
const isEmptyObject = (val) => {
|
|
67529
|
+
return val && Object.keys(val).length === 0 && Object.getPrototypeOf(val) === Object.prototype;
|
|
67530
|
+
};
|
|
67531
|
+
if (isEmptyObject(value.low)) {
|
|
67532
|
+
value.low = "";
|
|
67533
|
+
}
|
|
67534
|
+
if (isEmptyObject(value.high)) {
|
|
67535
|
+
value.high = "";
|
|
67536
|
+
}
|
|
67537
|
+
const lowValid = isValidFilter(value.low), highValid = isValidFilter(value.high);
|
|
67538
|
+
if (lowValid && highValid) {
|
|
67539
|
+
query = sqlStatements.between(query, key, value.low, value.high);
|
|
67540
|
+
} else if (lowValid) {
|
|
67541
|
+
query = sqlStatements.lte(query, key, value.low);
|
|
67542
|
+
} else if (highValid) {
|
|
67543
|
+
query = sqlStatements.gte(query, key, value.high);
|
|
67544
|
+
}
|
|
67545
|
+
});
|
|
67546
|
+
}
|
|
67547
|
+
if (filters.equal) {
|
|
67548
|
+
iterate(filters.equal, (key, value) => {
|
|
67549
|
+
const fnc = allOr ? "orWhereRaw" : "whereRaw";
|
|
67550
|
+
if (this.client === "mssql" /* MS_SQL */) {
|
|
67551
|
+
query = query[fnc](
|
|
67552
|
+
`CASE WHEN ${likeKey(this.client, key)} = ? THEN 1 ELSE 0 END = 1`,
|
|
67553
|
+
[value]
|
|
67554
|
+
);
|
|
67555
|
+
} else {
|
|
67556
|
+
query = query[fnc](
|
|
67557
|
+
`COALESCE(${likeKey(this.client, key)} = ?, FALSE)`,
|
|
67558
|
+
[value]
|
|
67559
|
+
);
|
|
67560
|
+
}
|
|
67561
|
+
});
|
|
67562
|
+
}
|
|
67563
|
+
if (filters.notEqual) {
|
|
67564
|
+
iterate(filters.notEqual, (key, value) => {
|
|
67565
|
+
const fnc = allOr ? "orWhereRaw" : "whereRaw";
|
|
67566
|
+
if (this.client === "mssql" /* MS_SQL */) {
|
|
67567
|
+
query = query[fnc](
|
|
67568
|
+
`CASE WHEN ${likeKey(this.client, key)} = ? THEN 1 ELSE 0 END = 0`,
|
|
67569
|
+
[value]
|
|
67570
|
+
);
|
|
67571
|
+
} else {
|
|
67572
|
+
query = query[fnc](
|
|
67573
|
+
`COALESCE(${likeKey(this.client, key)} != ?, TRUE)`,
|
|
67574
|
+
[value]
|
|
67575
|
+
);
|
|
67576
|
+
}
|
|
67577
|
+
});
|
|
67578
|
+
}
|
|
67579
|
+
if (filters.empty) {
|
|
67580
|
+
iterate(filters.empty, (key) => {
|
|
67581
|
+
const fnc = allOr ? "orWhereNull" : "whereNull";
|
|
67582
|
+
query = query[fnc](key);
|
|
67583
|
+
});
|
|
67584
|
+
}
|
|
67585
|
+
if (filters.notEmpty) {
|
|
67586
|
+
iterate(filters.notEmpty, (key) => {
|
|
67587
|
+
const fnc = allOr ? "orWhereNotNull" : "whereNotNull";
|
|
67588
|
+
query = query[fnc](key);
|
|
67589
|
+
});
|
|
67590
|
+
}
|
|
67591
|
+
if (filters.contains) {
|
|
67592
|
+
contains(filters.contains);
|
|
67593
|
+
}
|
|
67594
|
+
if (filters.notContains) {
|
|
67595
|
+
contains(filters.notContains);
|
|
67596
|
+
}
|
|
67597
|
+
if (filters.containsAny) {
|
|
67598
|
+
contains(filters.containsAny, true);
|
|
67599
|
+
}
|
|
67600
|
+
if (filters.documentType && !isExternalTable(table)) {
|
|
67601
|
+
const tableRef = opts?.aliases?.[table._id] || table._id;
|
|
67602
|
+
query.andWhereLike(
|
|
67603
|
+
`${tableRef}._id`,
|
|
67604
|
+
`${prefixed(filters.documentType)}%`
|
|
67605
|
+
);
|
|
67606
|
+
}
|
|
67607
|
+
return query;
|
|
67608
|
+
}
|
|
67609
|
+
addSorting(query, json) {
|
|
67610
|
+
let { sort, paginate } = json;
|
|
67611
|
+
const table = json.meta.table;
|
|
67612
|
+
const tableName = getTableName(table);
|
|
67613
|
+
const aliases = json.tableAliases;
|
|
67614
|
+
const aliased = tableName && aliases?.[tableName] ? aliases[tableName] : table?.name;
|
|
67615
|
+
if (sort && Object.keys(sort || {}).length > 0) {
|
|
67616
|
+
for (let [key, value] of Object.entries(sort)) {
|
|
67617
|
+
const direction = value.direction === "ASCENDING" /* ASCENDING */ ? "asc" : "desc";
|
|
67618
|
+
let nulls;
|
|
67619
|
+
if (this.client === "pg" /* POSTGRES */) {
|
|
67620
|
+
nulls = value.direction === "ASCENDING" /* ASCENDING */ ? "first" : "last";
|
|
67621
|
+
}
|
|
67622
|
+
query = query.orderBy(`${aliased}.${key}`, direction, nulls);
|
|
67623
|
+
}
|
|
67624
|
+
} else if (this.client === "mssql" /* MS_SQL */ && paginate?.limit) {
|
|
67625
|
+
query = query.orderBy(`${aliased}.${table?.primary[0]}`);
|
|
67626
|
+
}
|
|
67627
|
+
return query;
|
|
67628
|
+
}
|
|
67629
|
+
tableNameWithSchema(tableName, opts) {
|
|
67630
|
+
let withSchema = opts?.schema ? `${opts.schema}.${tableName}` : tableName;
|
|
67631
|
+
if (opts?.alias) {
|
|
67632
|
+
withSchema += ` as ${opts.alias}`;
|
|
67633
|
+
}
|
|
67634
|
+
return withSchema;
|
|
67635
|
+
}
|
|
67636
|
+
addRelationships(query, fromTable, relationships, schema, aliases) {
|
|
67637
|
+
if (!relationships) {
|
|
67638
|
+
return query;
|
|
67639
|
+
}
|
|
67640
|
+
const tableSets = {};
|
|
67641
|
+
for (let relationship of relationships) {
|
|
67642
|
+
const keyObj = {
|
|
67643
|
+
toTable: relationship.tableName,
|
|
67644
|
+
throughTable: void 0
|
|
67645
|
+
};
|
|
67646
|
+
if (relationship.through) {
|
|
67647
|
+
keyObj.throughTable = relationship.through;
|
|
67648
|
+
}
|
|
67649
|
+
const key = JSON.stringify(keyObj);
|
|
67650
|
+
if (tableSets[key]) {
|
|
67651
|
+
tableSets[key].push(relationship);
|
|
67652
|
+
} else {
|
|
67653
|
+
tableSets[key] = [relationship];
|
|
67654
|
+
}
|
|
67655
|
+
}
|
|
67656
|
+
for (let [key, relationships2] of Object.entries(tableSets)) {
|
|
67657
|
+
const { toTable, throughTable } = JSON.parse(key);
|
|
67658
|
+
const toAlias = aliases?.[toTable] || toTable, throughAlias = aliases?.[throughTable] || throughTable, fromAlias = aliases?.[fromTable] || fromTable;
|
|
67659
|
+
let toTableWithSchema = this.tableNameWithSchema(toTable, {
|
|
67660
|
+
alias: toAlias,
|
|
67661
|
+
schema
|
|
67662
|
+
});
|
|
67663
|
+
let throughTableWithSchema = this.tableNameWithSchema(throughTable, {
|
|
67664
|
+
alias: throughAlias,
|
|
67665
|
+
schema
|
|
67666
|
+
});
|
|
67667
|
+
if (!throughTable) {
|
|
67668
|
+
query = query.leftJoin(toTableWithSchema, function() {
|
|
67669
|
+
for (let relationship of relationships2) {
|
|
67670
|
+
const from = relationship.from, to = relationship.to;
|
|
67671
|
+
this.orOn(`${fromAlias}.${from}`, "=", `${toAlias}.${to}`);
|
|
67672
|
+
}
|
|
67673
|
+
});
|
|
67674
|
+
} else {
|
|
67675
|
+
query = query.leftJoin(throughTableWithSchema, function() {
|
|
67676
|
+
for (let relationship of relationships2) {
|
|
67677
|
+
const fromPrimary = relationship.fromPrimary;
|
|
67678
|
+
const from = relationship.from;
|
|
67679
|
+
this.orOn(
|
|
67680
|
+
`${fromAlias}.${fromPrimary}`,
|
|
67681
|
+
"=",
|
|
67682
|
+
`${throughAlias}.${from}`
|
|
67683
|
+
);
|
|
67684
|
+
}
|
|
67685
|
+
}).leftJoin(toTableWithSchema, function() {
|
|
67686
|
+
for (let relationship of relationships2) {
|
|
67687
|
+
const toPrimary = relationship.toPrimary;
|
|
67688
|
+
const to = relationship.to;
|
|
67689
|
+
this.orOn(`${toAlias}.${toPrimary}`, `${throughAlias}.${to}`);
|
|
67690
|
+
}
|
|
67691
|
+
});
|
|
67692
|
+
}
|
|
67693
|
+
}
|
|
67694
|
+
return query.limit(BASE_LIMIT);
|
|
67695
|
+
}
|
|
67696
|
+
knexWithAlias(knex3, endpoint, aliases) {
|
|
67697
|
+
const tableName = endpoint.entityId;
|
|
67698
|
+
const tableAlias = aliases?.[tableName];
|
|
67699
|
+
const query = knex3(
|
|
67700
|
+
this.tableNameWithSchema(tableName, {
|
|
67701
|
+
alias: tableAlias,
|
|
67702
|
+
schema: endpoint.schema
|
|
67703
|
+
})
|
|
67704
|
+
);
|
|
67705
|
+
return query;
|
|
67706
|
+
}
|
|
67707
|
+
create(knex3, json, opts) {
|
|
67708
|
+
const { endpoint, body: body2 } = json;
|
|
67709
|
+
let query = this.knexWithAlias(knex3, endpoint);
|
|
67710
|
+
const parsedBody = parseBody(body2);
|
|
67711
|
+
for (let [key, value] of Object.entries(parsedBody)) {
|
|
67712
|
+
if (value == null) {
|
|
67713
|
+
delete parsedBody[key];
|
|
67714
|
+
}
|
|
67715
|
+
}
|
|
67716
|
+
if (opts.disableReturning) {
|
|
67717
|
+
return query.insert(parsedBody);
|
|
67718
|
+
} else {
|
|
67719
|
+
return query.insert(parsedBody).returning("*");
|
|
67720
|
+
}
|
|
67721
|
+
}
|
|
67722
|
+
bulkCreate(knex3, json) {
|
|
67723
|
+
const { endpoint, body: body2 } = json;
|
|
67724
|
+
let query = this.knexWithAlias(knex3, endpoint);
|
|
67725
|
+
if (!Array.isArray(body2)) {
|
|
67726
|
+
return query;
|
|
67727
|
+
}
|
|
67728
|
+
const parsedBody = body2.map((row) => parseBody(row));
|
|
67729
|
+
return query.insert(parsedBody);
|
|
67730
|
+
}
|
|
67731
|
+
read(knex3, json, limit) {
|
|
67732
|
+
let { endpoint, resource, filters, paginate, relationships, tableAliases } = json;
|
|
67733
|
+
const tableName = endpoint.entityId;
|
|
67734
|
+
if (!resource) {
|
|
67735
|
+
resource = { fields: [] };
|
|
67736
|
+
}
|
|
67737
|
+
let selectStatement = "*";
|
|
67738
|
+
if (resource.fields && resource.fields.length > 0) {
|
|
67739
|
+
selectStatement = generateSelectStatement(json, knex3);
|
|
67740
|
+
}
|
|
67741
|
+
let foundLimit = limit || BASE_LIMIT;
|
|
67742
|
+
let foundOffset = null;
|
|
67743
|
+
if (paginate && paginate.page && paginate.limit) {
|
|
67744
|
+
const page = paginate.page <= 1 ? 0 : paginate.page - 1;
|
|
67745
|
+
const offset = page * paginate.limit;
|
|
67746
|
+
foundLimit = paginate.limit;
|
|
67747
|
+
foundOffset = offset;
|
|
67748
|
+
} else if (paginate && paginate.limit) {
|
|
67749
|
+
foundLimit = paginate.limit;
|
|
67750
|
+
}
|
|
67751
|
+
let query = this.knexWithAlias(knex3, endpoint, tableAliases);
|
|
67752
|
+
query = query.limit(foundLimit);
|
|
67753
|
+
if (foundOffset) {
|
|
67754
|
+
query = query.offset(foundOffset);
|
|
67755
|
+
}
|
|
67756
|
+
query = this.addFilters(query, filters, json.meta.table, {
|
|
67757
|
+
aliases: tableAliases
|
|
67758
|
+
});
|
|
67759
|
+
query = this.addSorting(query, json);
|
|
67760
|
+
const alias = tableAliases?.[tableName] || tableName;
|
|
67761
|
+
let preQuery = knex3({
|
|
67762
|
+
[alias]: query
|
|
67763
|
+
}).select(selectStatement);
|
|
67764
|
+
if (this.client !== "mssql" /* MS_SQL */) {
|
|
67765
|
+
preQuery = this.addSorting(preQuery, json);
|
|
67766
|
+
}
|
|
67767
|
+
query = this.addRelationships(
|
|
67768
|
+
preQuery,
|
|
67769
|
+
tableName,
|
|
67770
|
+
relationships,
|
|
67771
|
+
endpoint.schema,
|
|
67772
|
+
tableAliases
|
|
67773
|
+
);
|
|
67774
|
+
return this.addFilters(query, filters, json.meta.table, {
|
|
67775
|
+
relationship: true,
|
|
67776
|
+
aliases: tableAliases
|
|
67777
|
+
});
|
|
67778
|
+
}
|
|
67779
|
+
update(knex3, json, opts) {
|
|
67780
|
+
const { endpoint, body: body2, filters, tableAliases } = json;
|
|
67781
|
+
let query = this.knexWithAlias(knex3, endpoint, tableAliases);
|
|
67782
|
+
const parsedBody = parseBody(body2);
|
|
67783
|
+
query = this.addFilters(query, filters, json.meta.table, {
|
|
67784
|
+
aliases: tableAliases
|
|
67785
|
+
});
|
|
67786
|
+
if (opts.disableReturning) {
|
|
67787
|
+
return query.update(parsedBody);
|
|
67788
|
+
} else {
|
|
67789
|
+
return query.update(parsedBody).returning("*");
|
|
67790
|
+
}
|
|
67791
|
+
}
|
|
67792
|
+
delete(knex3, json, opts) {
|
|
67793
|
+
const { endpoint, filters, tableAliases } = json;
|
|
67794
|
+
let query = this.knexWithAlias(knex3, endpoint, tableAliases);
|
|
67795
|
+
query = this.addFilters(query, filters, json.meta.table, {
|
|
67796
|
+
aliases: tableAliases
|
|
67797
|
+
});
|
|
67798
|
+
if (opts.disableReturning) {
|
|
67799
|
+
return query.delete();
|
|
67800
|
+
} else {
|
|
67801
|
+
return query.delete().returning(generateSelectStatement(json, knex3));
|
|
67802
|
+
}
|
|
67803
|
+
}
|
|
67804
|
+
};
|
|
67805
|
+
var SqlQueryBuilder = class extends sqlTable_default {
|
|
67806
|
+
// pass through client to get flavour of SQL
|
|
67807
|
+
constructor(client, limit = BASE_LIMIT) {
|
|
67808
|
+
super(client);
|
|
67809
|
+
this.limit = limit;
|
|
67810
|
+
}
|
|
67811
|
+
/**
|
|
67812
|
+
* @param json The JSON query DSL which is to be converted to SQL.
|
|
67813
|
+
* @param opts extra options which are to be passed into the query builder, e.g. disableReturning
|
|
67814
|
+
* which for the sake of mySQL stops adding the returning statement to inserts, updates and deletes.
|
|
67815
|
+
* @return the query ready to be passed to the driver.
|
|
67816
|
+
*/
|
|
67817
|
+
_query(json, opts = {}) {
|
|
67818
|
+
const sqlClient = this.getSqlClient();
|
|
67819
|
+
const config = {
|
|
67820
|
+
client: sqlClient
|
|
67821
|
+
};
|
|
67822
|
+
if (sqlClient === "sqlite3" /* SQL_LITE */) {
|
|
67823
|
+
config.useNullAsDefault = true;
|
|
67824
|
+
}
|
|
67825
|
+
const client = (0, import_knex2.knex)(config);
|
|
67826
|
+
let query;
|
|
67827
|
+
const builder = new InternalBuilder(sqlClient);
|
|
67828
|
+
switch (this._operation(json)) {
|
|
67829
|
+
case "CREATE" /* CREATE */:
|
|
67830
|
+
query = builder.create(client, json, opts);
|
|
67831
|
+
break;
|
|
67832
|
+
case "READ" /* READ */:
|
|
67833
|
+
query = builder.read(client, json, this.limit);
|
|
67834
|
+
break;
|
|
67835
|
+
case "UPDATE" /* UPDATE */:
|
|
67836
|
+
query = builder.update(client, json, opts);
|
|
67837
|
+
break;
|
|
67838
|
+
case "DELETE" /* DELETE */:
|
|
67839
|
+
query = builder.delete(client, json, opts);
|
|
67840
|
+
break;
|
|
67841
|
+
case "BULK_CREATE" /* BULK_CREATE */:
|
|
67842
|
+
query = builder.bulkCreate(client, json);
|
|
67843
|
+
break;
|
|
67844
|
+
case "CREATE_TABLE" /* CREATE_TABLE */:
|
|
67845
|
+
case "UPDATE_TABLE" /* UPDATE_TABLE */:
|
|
67846
|
+
case "DELETE_TABLE" /* DELETE_TABLE */:
|
|
67847
|
+
return this._tableQuery(json);
|
|
67848
|
+
default:
|
|
67849
|
+
throw `Operation type is not supported by SQL query builder`;
|
|
67850
|
+
}
|
|
67851
|
+
if (opts?.disableBindings) {
|
|
67852
|
+
return { sql: query.toString() };
|
|
67853
|
+
} else {
|
|
67854
|
+
let native = getNativeSql(query);
|
|
67855
|
+
if (sqlClient === "sqlite3" /* SQL_LITE */) {
|
|
67856
|
+
native = convertBooleans(native);
|
|
67857
|
+
}
|
|
67858
|
+
return native;
|
|
67859
|
+
}
|
|
67860
|
+
}
|
|
67861
|
+
async getReturningRow(queryFn, json) {
|
|
67862
|
+
if (!json.extra || !json.extra.idFilter) {
|
|
67863
|
+
return {};
|
|
67864
|
+
}
|
|
67865
|
+
const input = this._query({
|
|
67866
|
+
endpoint: {
|
|
67867
|
+
...json.endpoint,
|
|
67868
|
+
operation: "READ" /* READ */
|
|
67869
|
+
},
|
|
67870
|
+
resource: {
|
|
67871
|
+
fields: []
|
|
67872
|
+
},
|
|
67873
|
+
filters: json.extra?.idFilter,
|
|
67874
|
+
paginate: {
|
|
67875
|
+
limit: 1
|
|
67876
|
+
},
|
|
67877
|
+
meta: json.meta
|
|
67878
|
+
});
|
|
67879
|
+
return queryFn(input, "READ" /* READ */);
|
|
67880
|
+
}
|
|
67881
|
+
// when creating if an ID has been inserted need to make sure
|
|
67882
|
+
// the id filter is enriched with it before trying to retrieve the row
|
|
67883
|
+
checkLookupKeys(id, json) {
|
|
67884
|
+
if (!id || !json.meta.table || !json.meta.table.primary) {
|
|
67885
|
+
return json;
|
|
67886
|
+
}
|
|
67887
|
+
const primaryKey = json.meta.table.primary?.[0];
|
|
67888
|
+
json.extra = {
|
|
67889
|
+
idFilter: {
|
|
67890
|
+
equal: {
|
|
67891
|
+
[primaryKey]: id
|
|
67892
|
+
}
|
|
67893
|
+
}
|
|
67894
|
+
};
|
|
67895
|
+
return json;
|
|
67896
|
+
}
|
|
67897
|
+
// this function recreates the returning functionality of postgres
|
|
67898
|
+
async queryWithReturning(json, queryFn, processFn = (result) => result) {
|
|
67899
|
+
const sqlClient = this.getSqlClient();
|
|
67900
|
+
const operation = this._operation(json);
|
|
67901
|
+
const input = this._query(json, { disableReturning: true });
|
|
67902
|
+
if (Array.isArray(input)) {
|
|
67903
|
+
const responses = [];
|
|
67904
|
+
for (let query of input) {
|
|
67905
|
+
responses.push(await queryFn(query, operation));
|
|
67906
|
+
}
|
|
67907
|
+
return responses;
|
|
67908
|
+
}
|
|
67909
|
+
let row;
|
|
67910
|
+
if (operation === "DELETE" /* DELETE */) {
|
|
67911
|
+
row = processFn(await this.getReturningRow(queryFn, json));
|
|
67912
|
+
}
|
|
67913
|
+
const response = await queryFn(input, operation);
|
|
67914
|
+
const results = processFn(response);
|
|
67915
|
+
if (operation === "CREATE" /* CREATE */ || operation === "UPDATE" /* UPDATE */) {
|
|
67916
|
+
let id;
|
|
67917
|
+
if (sqlClient === "mssql" /* MS_SQL */) {
|
|
67918
|
+
id = results?.[0].id;
|
|
67919
|
+
} else if (sqlClient === "mysql2" /* MY_SQL */) {
|
|
67920
|
+
id = results?.insertId;
|
|
67921
|
+
}
|
|
67922
|
+
row = processFn(
|
|
67923
|
+
await this.getReturningRow(queryFn, this.checkLookupKeys(id, json))
|
|
67924
|
+
);
|
|
67925
|
+
}
|
|
67926
|
+
if (operation !== "READ" /* READ */) {
|
|
67927
|
+
return row;
|
|
67928
|
+
}
|
|
67929
|
+
return results.length ? results : [{ [operation.toLowerCase()]: true }];
|
|
67930
|
+
}
|
|
67931
|
+
convertJsonStringColumns(table, results, aliases) {
|
|
67932
|
+
const tableName = getTableName(table);
|
|
67933
|
+
for (const [name, field] of Object.entries(table.schema)) {
|
|
67934
|
+
if (!this._isJsonColumn(field)) {
|
|
67935
|
+
continue;
|
|
67936
|
+
}
|
|
67937
|
+
const aliasedTableName = tableName && aliases?.[tableName] || tableName;
|
|
67938
|
+
const fullName = `${aliasedTableName}.${name}`;
|
|
67939
|
+
for (let row of results) {
|
|
67940
|
+
if (typeof row[fullName] === "string") {
|
|
67941
|
+
row[fullName] = JSON.parse(row[fullName]);
|
|
67942
|
+
}
|
|
67943
|
+
if (typeof row[name] === "string") {
|
|
67944
|
+
row[name] = JSON.parse(row[name]);
|
|
67945
|
+
}
|
|
67946
|
+
}
|
|
67947
|
+
}
|
|
67948
|
+
return results;
|
|
67949
|
+
}
|
|
67950
|
+
_isJsonColumn(field) {
|
|
67951
|
+
return JsonTypes.includes(field.type) && !helpers_exports.schema.isDeprecatedSingleUserColumn(field);
|
|
67952
|
+
}
|
|
67953
|
+
log(query, values2) {
|
|
67954
|
+
if (!environment_default.SQL_LOGGING_ENABLE) {
|
|
67955
|
+
return;
|
|
67956
|
+
}
|
|
67957
|
+
const sqlClient = this.getSqlClient();
|
|
67958
|
+
let string = `[SQL] [${sqlClient.toUpperCase()}] query="${query}"`;
|
|
67959
|
+
if (values2) {
|
|
67960
|
+
string += ` values="${values2.join(", ")}"`;
|
|
67961
|
+
}
|
|
67962
|
+
console.log(string);
|
|
67963
|
+
}
|
|
67964
|
+
};
|
|
67965
|
+
var sql_default = SqlQueryBuilder;
|
|
67966
|
+
|
|
67967
|
+
// src/sql/designDoc.ts
|
|
67968
|
+
var designDoc_exports = {};
|
|
67969
|
+
__export(designDoc_exports, {
|
|
67970
|
+
base: () => base
|
|
67971
|
+
});
|
|
67972
|
+
function base(tableIdProp) {
|
|
67973
|
+
return {
|
|
67974
|
+
_id: SQLITE_DESIGN_DOC_ID,
|
|
67975
|
+
language: "sqlite",
|
|
67976
|
+
sql: {
|
|
67977
|
+
tables: {},
|
|
67978
|
+
options: {
|
|
67979
|
+
table_name: tableIdProp
|
|
67980
|
+
}
|
|
67981
|
+
}
|
|
67982
|
+
};
|
|
67983
|
+
}
|
|
67984
|
+
|
|
66741
67985
|
// src/index.ts
|
|
66742
67986
|
var tenancy = {
|
|
66743
67987
|
...tenancy_exports,
|
|
@@ -66757,6 +68001,11 @@ var init9 = (opts = {}) => {
|
|
|
66757
68001
|
BudibaseError,
|
|
66758
68002
|
Config,
|
|
66759
68003
|
Cookie,
|
|
68004
|
+
DEFAULT_BB_DATASOURCE_ID,
|
|
68005
|
+
DEFAULT_EMPLOYEE_TABLE_ID,
|
|
68006
|
+
DEFAULT_EXPENSES_TABLE_ID,
|
|
68007
|
+
DEFAULT_INVENTORY_TABLE_ID,
|
|
68008
|
+
DEFAULT_JOBS_TABLE_ID,
|
|
66760
68009
|
DEFAULT_TENANT_ID,
|
|
66761
68010
|
DeprecatedViews,
|
|
66762
68011
|
DocumentType,
|
|
@@ -66776,6 +68025,7 @@ var init9 = (opts = {}) => {
|
|
|
66776
68025
|
RedisClient,
|
|
66777
68026
|
SEPARATOR,
|
|
66778
68027
|
SQLITE_DESIGN_DOC_ID,
|
|
68028
|
+
SQS_DATASOURCE_INTERNAL,
|
|
66779
68029
|
StaticDatabases,
|
|
66780
68030
|
UNICODE_MAX,
|
|
66781
68031
|
UsageLimitError,
|
|
@@ -66813,6 +68063,7 @@ var init9 = (opts = {}) => {
|
|
|
66813
68063
|
roles,
|
|
66814
68064
|
security,
|
|
66815
68065
|
sessions,
|
|
68066
|
+
sql,
|
|
66816
68067
|
tenancy,
|
|
66817
68068
|
timers,
|
|
66818
68069
|
userUtils,
|