@budibase/backend-core 2.29.20 → 2.29.22
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 +76 -43
- package/dist/index.js.map +3 -3
- package/dist/index.js.meta.json +1 -1
- package/dist/package.json +4 -4
- package/dist/plugins.js +1 -0
- package/dist/plugins.js.map +2 -2
- package/dist/plugins.js.meta.json +1 -1
- package/dist/src/middleware/joi-validator.d.ts +2 -1
- package/dist/src/middleware/joi-validator.js +7 -3
- package/dist/src/middleware/joi-validator.js.map +1 -1
- package/dist/src/sql/sql.d.ts +2 -2
- package/dist/src/sql/sql.js +68 -42
- package/dist/src/sql/sql.js.map +1 -1
- package/dist/src/sql/sqlTable.d.ts +3 -3
- package/dist/src/sql/sqlTable.js.map +1 -1
- package/package.json +4 -4
- package/src/middleware/joi-validator.ts +7 -4
- package/src/sql/sql.ts +103 -44
- package/src/sql/sqlTable.ts +3 -3
package/dist/index.js
CHANGED
|
@@ -54551,6 +54551,7 @@ var AutomationCustomIOType = /* @__PURE__ */ ((AutomationCustomIOType2) => {
|
|
|
54551
54551
|
AutomationCustomIOType2["AUTOMATION"] = "automation";
|
|
54552
54552
|
AutomationCustomIOType2["AUTOMATION_FIELDS"] = "automationFields";
|
|
54553
54553
|
AutomationCustomIOType2["MULTI_ATTACHMENTS"] = "multi_attachments";
|
|
54554
|
+
AutomationCustomIOType2["TRIGGER_FILTER"] = "trigger_filter";
|
|
54554
54555
|
return AutomationCustomIOType2;
|
|
54555
54556
|
})(AutomationCustomIOType || {});
|
|
54556
54557
|
var AutomationTriggerStepId = /* @__PURE__ */ ((AutomationTriggerStepId2) => {
|
|
@@ -54644,6 +54645,7 @@ var DocumentType = /* @__PURE__ */ ((DocumentType2) => {
|
|
|
54644
54645
|
DocumentType2["AUDIT_LOG"] = "al";
|
|
54645
54646
|
DocumentType2["APP_MIGRATION_METADATA"] = "_design/migrations";
|
|
54646
54647
|
DocumentType2["SCIM_LOG"] = "scimlog";
|
|
54648
|
+
DocumentType2["ROW_ACTIONS"] = "ra";
|
|
54647
54649
|
return DocumentType2;
|
|
54648
54650
|
})(DocumentType || {});
|
|
54649
54651
|
var InternalTable = /* @__PURE__ */ ((InternalTable2) => {
|
|
@@ -66891,7 +66893,8 @@ __export(joi_validator_exports, {
|
|
|
66891
66893
|
params: () => params
|
|
66892
66894
|
});
|
|
66893
66895
|
var import_joi = __toESM(require("joi"));
|
|
66894
|
-
function validate2(schema, property, opts
|
|
66896
|
+
function validate2(schema, property, opts) {
|
|
66897
|
+
const errorPrefix = opts?.errorPrefix ?? `Invalid ${property}`;
|
|
66895
66898
|
return (ctx, next) => {
|
|
66896
66899
|
if (!schema) {
|
|
66897
66900
|
return next();
|
|
@@ -66909,10 +66912,12 @@ function validate2(schema, property, opts = { errorPrefix: `Invalid ${property}`
|
|
|
66909
66912
|
updatedAt: import_joi.default.any().optional()
|
|
66910
66913
|
});
|
|
66911
66914
|
}
|
|
66912
|
-
const { error } = schema.validate(params2
|
|
66915
|
+
const { error } = schema.validate(params2, {
|
|
66916
|
+
allowUnknown: opts?.allowUnknown
|
|
66917
|
+
});
|
|
66913
66918
|
if (error) {
|
|
66914
66919
|
let message = error.message;
|
|
66915
|
-
if (
|
|
66920
|
+
if (errorPrefix) {
|
|
66916
66921
|
message = `Invalid ${property} - ${message}`;
|
|
66917
66922
|
}
|
|
66918
66923
|
ctx.throw(400, message);
|
|
@@ -67616,27 +67621,20 @@ var sqlTable_default = SqlTableQueryBuilder;
|
|
|
67616
67621
|
// src/sql/sql.ts
|
|
67617
67622
|
var envLimit = environment_default.SQL_MAX_ROWS ? parseInt(environment_default.SQL_MAX_ROWS) : null;
|
|
67618
67623
|
var BASE_LIMIT = envLimit || 5e3;
|
|
67619
|
-
function
|
|
67620
|
-
let start2, end2;
|
|
67624
|
+
function quote(client, str) {
|
|
67621
67625
|
switch (client) {
|
|
67622
|
-
case "mysql2" /* MY_SQL */:
|
|
67623
|
-
start2 = end2 = "`";
|
|
67624
|
-
break;
|
|
67625
67626
|
case "sqlite3" /* SQL_LITE */:
|
|
67626
67627
|
case "oracledb" /* ORACLE */:
|
|
67627
67628
|
case "pg" /* POSTGRES */:
|
|
67628
|
-
|
|
67629
|
-
break;
|
|
67629
|
+
return `"${str}"`;
|
|
67630
67630
|
case "mssql" /* MS_SQL */:
|
|
67631
|
-
|
|
67632
|
-
|
|
67633
|
-
|
|
67634
|
-
default:
|
|
67635
|
-
throw new Error("Unknown client generating like key");
|
|
67631
|
+
return `[${str}]`;
|
|
67632
|
+
case "mysql2" /* MY_SQL */:
|
|
67633
|
+
return `\`${str}\``;
|
|
67636
67634
|
}
|
|
67637
|
-
|
|
67638
|
-
|
|
67639
|
-
return key;
|
|
67635
|
+
}
|
|
67636
|
+
function quotedIdentifier(client, key) {
|
|
67637
|
+
return key.split(".").map((part) => quote(client, part)).join(".");
|
|
67640
67638
|
}
|
|
67641
67639
|
function parse(input) {
|
|
67642
67640
|
if (Array.isArray(input)) {
|
|
@@ -67679,27 +67677,51 @@ function parseFilters(filters) {
|
|
|
67679
67677
|
}
|
|
67680
67678
|
function generateSelectStatement(json, knex3) {
|
|
67681
67679
|
const { resource, meta } = json;
|
|
67680
|
+
const client = knex3.client.config.client;
|
|
67682
67681
|
if (!resource || !resource.fields || resource.fields.length === 0) {
|
|
67683
67682
|
return "*";
|
|
67684
67683
|
}
|
|
67685
|
-
const schema = meta
|
|
67684
|
+
const schema = meta.table.schema;
|
|
67686
67685
|
return resource.fields.map((field) => {
|
|
67687
|
-
const
|
|
67688
|
-
|
|
67689
|
-
|
|
67690
|
-
|
|
67691
|
-
|
|
67692
|
-
|
|
67693
|
-
|
|
67694
|
-
|
|
67695
|
-
|
|
67696
|
-
|
|
67697
|
-
|
|
67686
|
+
const parts = field.split(/\./g);
|
|
67687
|
+
let table = void 0;
|
|
67688
|
+
let column = void 0;
|
|
67689
|
+
if (parts.length === 1) {
|
|
67690
|
+
column = parts[0];
|
|
67691
|
+
}
|
|
67692
|
+
if (parts.length === 2) {
|
|
67693
|
+
table = parts[0];
|
|
67694
|
+
column = parts[1];
|
|
67695
|
+
}
|
|
67696
|
+
if (parts.length > 2) {
|
|
67697
|
+
table = parts[0];
|
|
67698
|
+
column = parts.slice(1).join(".");
|
|
67699
|
+
}
|
|
67700
|
+
if (!column) {
|
|
67701
|
+
throw new Error(`Invalid field name: ${field}`);
|
|
67702
|
+
}
|
|
67703
|
+
const columnSchema = schema[column];
|
|
67704
|
+
if (client === "pg" /* POSTGRES */ && columnSchema?.externalType?.includes("money")) {
|
|
67705
|
+
return knex3.raw(
|
|
67706
|
+
`${quotedIdentifier(
|
|
67707
|
+
client,
|
|
67708
|
+
[table, column].join(".")
|
|
67709
|
+
)}::money::numeric as ${quote(client, field)}`
|
|
67710
|
+
);
|
|
67698
67711
|
}
|
|
67699
|
-
if (
|
|
67712
|
+
if (client === "mssql" /* MS_SQL */ && columnSchema?.type === "datetime" /* DATETIME */ && columnSchema.timeOnly) {
|
|
67700
67713
|
return knex3.raw(`CONVERT(varchar, ${field}, 108) as "${field}"`);
|
|
67701
67714
|
}
|
|
67702
|
-
|
|
67715
|
+
if (table) {
|
|
67716
|
+
return knex3.raw(
|
|
67717
|
+
`${quote(client, table)}.${quote(client, column)} as ${quote(
|
|
67718
|
+
client,
|
|
67719
|
+
field
|
|
67720
|
+
)}`
|
|
67721
|
+
);
|
|
67722
|
+
} else {
|
|
67723
|
+
return knex3.raw(`${quote(client, field)} as ${quote(client, field)}`);
|
|
67724
|
+
}
|
|
67703
67725
|
});
|
|
67704
67726
|
}
|
|
67705
67727
|
function getTableName(table) {
|
|
@@ -67775,9 +67797,10 @@ var InternalBuilder = class {
|
|
|
67775
67797
|
query = query[fnc](key, "ilike", `%${value}%`);
|
|
67776
67798
|
} else {
|
|
67777
67799
|
const rawFnc = `${fnc}Raw`;
|
|
67778
|
-
query = query[rawFnc](
|
|
67779
|
-
|
|
67780
|
-
|
|
67800
|
+
query = query[rawFnc](
|
|
67801
|
+
`LOWER(${quotedIdentifier(this.client, key)}) LIKE ?`,
|
|
67802
|
+
[`%${value.toLowerCase()}%`]
|
|
67803
|
+
);
|
|
67781
67804
|
}
|
|
67782
67805
|
};
|
|
67783
67806
|
const contains = (mode, any = false) => {
|
|
@@ -67824,7 +67847,10 @@ var InternalBuilder = class {
|
|
|
67824
67847
|
} else {
|
|
67825
67848
|
value[i] = `%${value[i]}%`;
|
|
67826
67849
|
}
|
|
67827
|
-
statement += (statement ? andOr : "") + `COALESCE(LOWER(${
|
|
67850
|
+
statement += (statement ? andOr : "") + `COALESCE(LOWER(${quotedIdentifier(
|
|
67851
|
+
this.client,
|
|
67852
|
+
key
|
|
67853
|
+
)}), '') LIKE ?`;
|
|
67828
67854
|
}
|
|
67829
67855
|
if (statement === "") {
|
|
67830
67856
|
return;
|
|
@@ -67852,9 +67878,10 @@ var InternalBuilder = class {
|
|
|
67852
67878
|
query = query[fnc](key, "ilike", `${value}%`);
|
|
67853
67879
|
} else {
|
|
67854
67880
|
const rawFnc = `${fnc}Raw`;
|
|
67855
|
-
query = query[rawFnc](
|
|
67856
|
-
|
|
67857
|
-
|
|
67881
|
+
query = query[rawFnc](
|
|
67882
|
+
`LOWER(${quotedIdentifier(this.client, key)}) LIKE ?`,
|
|
67883
|
+
[`${value.toLowerCase()}%`]
|
|
67884
|
+
);
|
|
67858
67885
|
}
|
|
67859
67886
|
});
|
|
67860
67887
|
}
|
|
@@ -67887,12 +67914,15 @@ var InternalBuilder = class {
|
|
|
67887
67914
|
const fnc = allOr ? "orWhereRaw" : "whereRaw";
|
|
67888
67915
|
if (this.client === "mssql" /* MS_SQL */) {
|
|
67889
67916
|
query = query[fnc](
|
|
67890
|
-
`CASE WHEN ${
|
|
67917
|
+
`CASE WHEN ${quotedIdentifier(
|
|
67918
|
+
this.client,
|
|
67919
|
+
key
|
|
67920
|
+
)} = ? THEN 1 ELSE 0 END = 1`,
|
|
67891
67921
|
[value]
|
|
67892
67922
|
);
|
|
67893
67923
|
} else {
|
|
67894
67924
|
query = query[fnc](
|
|
67895
|
-
`COALESCE(${
|
|
67925
|
+
`COALESCE(${quotedIdentifier(this.client, key)} = ?, FALSE)`,
|
|
67896
67926
|
[value]
|
|
67897
67927
|
);
|
|
67898
67928
|
}
|
|
@@ -67903,12 +67933,15 @@ var InternalBuilder = class {
|
|
|
67903
67933
|
const fnc = allOr ? "orWhereRaw" : "whereRaw";
|
|
67904
67934
|
if (this.client === "mssql" /* MS_SQL */) {
|
|
67905
67935
|
query = query[fnc](
|
|
67906
|
-
`CASE WHEN ${
|
|
67936
|
+
`CASE WHEN ${quotedIdentifier(
|
|
67937
|
+
this.client,
|
|
67938
|
+
key
|
|
67939
|
+
)} = ? THEN 1 ELSE 0 END = 0`,
|
|
67907
67940
|
[value]
|
|
67908
67941
|
);
|
|
67909
67942
|
} else {
|
|
67910
67943
|
query = query[fnc](
|
|
67911
|
-
`COALESCE(${
|
|
67944
|
+
`COALESCE(${quotedIdentifier(this.client, key)} != ?, TRUE)`,
|
|
67912
67945
|
[value]
|
|
67913
67946
|
);
|
|
67914
67947
|
}
|