@budibase/backend-core 2.32.0 → 2.32.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +86 -77
- 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.map +1 -1
- package/dist/plugins.js.meta.json +1 -1
- package/dist/src/cache/user.d.ts +7 -1
- package/dist/src/cache/user.js +4 -3
- package/dist/src/cache/user.js.map +1 -1
- package/dist/src/events/index.d.ts +1 -0
- package/dist/src/events/index.js +3 -1
- package/dist/src/events/index.js.map +1 -1
- package/dist/src/middleware/authenticated.js +16 -3
- package/dist/src/middleware/authenticated.js.map +1 -1
- package/dist/src/sql/sql.js +35 -58
- package/dist/src/sql/sql.js.map +1 -1
- package/package.json +4 -4
- package/src/cache/user.ts +17 -6
- package/src/events/index.ts +1 -0
- package/src/middleware/authenticated.ts +25 -8
- package/src/sql/sql.ts +39 -66
package/dist/index.js
CHANGED
|
@@ -55068,6 +55068,12 @@ function decodeNonAscii(str) {
|
|
|
55068
55068
|
// ../shared-core/src/filters.ts
|
|
55069
55069
|
var import_lodash = require("lodash");
|
|
55070
55070
|
var HBS_REGEX = /{{([^{].*?)}}/g;
|
|
55071
|
+
var LOGICAL_OPERATORS = Object.values(LogicalOperator);
|
|
55072
|
+
var SEARCH_OPERATORS = [
|
|
55073
|
+
...Object.values(BasicOperator),
|
|
55074
|
+
...Object.values(ArrayOperator),
|
|
55075
|
+
...Object.values(RangeOperator)
|
|
55076
|
+
];
|
|
55071
55077
|
var getValidOperatorsForType = (fieldType, field, datasource2) => {
|
|
55072
55078
|
const Op = OperatorOptions;
|
|
55073
55079
|
const stringOps = [
|
|
@@ -55128,7 +55134,7 @@ var NoEmptyFilterStrings = [
|
|
|
55128
55134
|
OperatorOptions.In.value
|
|
55129
55135
|
];
|
|
55130
55136
|
function recurseLogicalOperators(filters, fn) {
|
|
55131
|
-
for (const logical of
|
|
55137
|
+
for (const logical of LOGICAL_OPERATORS) {
|
|
55132
55138
|
if (filters[logical]) {
|
|
55133
55139
|
filters[logical].conditions = filters[logical].conditions.map(
|
|
55134
55140
|
(condition) => fn(condition)
|
|
@@ -55139,7 +55145,7 @@ function recurseLogicalOperators(filters, fn) {
|
|
|
55139
55145
|
}
|
|
55140
55146
|
function recurseSearchFilters(filters, processFn) {
|
|
55141
55147
|
filters = processFn(filters);
|
|
55142
|
-
for (const logical of
|
|
55148
|
+
for (const logical of LOGICAL_OPERATORS) {
|
|
55143
55149
|
if (filters[logical]) {
|
|
55144
55150
|
filters[logical].conditions = filters[logical].conditions.map(
|
|
55145
55151
|
(condition) => recurseSearchFilters(condition, processFn)
|
|
@@ -55602,7 +55608,9 @@ function runQuery(docs, query) {
|
|
|
55602
55608
|
).map(([key]) => {
|
|
55603
55609
|
return filterFunctions[key]?.(doc) ?? false;
|
|
55604
55610
|
});
|
|
55605
|
-
if (query
|
|
55611
|
+
if (!hasFilters(query)) {
|
|
55612
|
+
return true;
|
|
55613
|
+
} else if (query.allOr) {
|
|
55606
55614
|
return results.some((result) => result === true);
|
|
55607
55615
|
} else {
|
|
55608
55616
|
return results.every((result) => result === true);
|
|
@@ -55644,16 +55652,33 @@ var hasFilters = (query) => {
|
|
|
55644
55652
|
if (!query) {
|
|
55645
55653
|
return false;
|
|
55646
55654
|
}
|
|
55647
|
-
const
|
|
55648
|
-
|
|
55649
|
-
|
|
55650
|
-
|
|
55655
|
+
const check = (filters) => {
|
|
55656
|
+
for (const logical of LOGICAL_OPERATORS) {
|
|
55657
|
+
if (filters[logical]) {
|
|
55658
|
+
for (const condition of filters[logical]?.conditions || []) {
|
|
55659
|
+
const result = check(condition);
|
|
55660
|
+
if (result) {
|
|
55661
|
+
return result;
|
|
55662
|
+
}
|
|
55663
|
+
}
|
|
55664
|
+
}
|
|
55651
55665
|
}
|
|
55652
|
-
|
|
55653
|
-
|
|
55666
|
+
for (const search2 of SEARCH_OPERATORS) {
|
|
55667
|
+
const searchValue = filters[search2];
|
|
55668
|
+
if (!searchValue || typeof searchValue !== "object") {
|
|
55669
|
+
continue;
|
|
55670
|
+
}
|
|
55671
|
+
const filtered2 = Object.entries(searchValue).filter((entry2) => {
|
|
55672
|
+
const valueDefined = entry2[1] !== void 0 || entry2[1] !== null || entry2[1] !== "";
|
|
55673
|
+
return search2 === "notEmpty" /* NOT_EMPTY */ || valueDefined;
|
|
55674
|
+
});
|
|
55675
|
+
if (filtered2.length !== 0) {
|
|
55676
|
+
return true;
|
|
55677
|
+
}
|
|
55654
55678
|
}
|
|
55655
|
-
|
|
55656
|
-
|
|
55679
|
+
return false;
|
|
55680
|
+
};
|
|
55681
|
+
return check(query);
|
|
55657
55682
|
};
|
|
55658
55683
|
|
|
55659
55684
|
// ../shared-core/src/utils.ts
|
|
@@ -62344,6 +62369,7 @@ __export(events_exports, {
|
|
|
62344
62369
|
org: () => org_default,
|
|
62345
62370
|
plugin: () => plugin_default,
|
|
62346
62371
|
processors: () => processors_exports,
|
|
62372
|
+
publishEvent: () => publishEvent,
|
|
62347
62373
|
query: () => query_default,
|
|
62348
62374
|
role: () => role_default,
|
|
62349
62375
|
rows: () => rows_default,
|
|
@@ -65708,7 +65734,12 @@ async function populateUsersFromDB(userIds) {
|
|
|
65708
65734
|
}
|
|
65709
65735
|
return { users };
|
|
65710
65736
|
}
|
|
65711
|
-
async function getUser(
|
|
65737
|
+
async function getUser({
|
|
65738
|
+
userId,
|
|
65739
|
+
tenantId,
|
|
65740
|
+
email,
|
|
65741
|
+
populateUser
|
|
65742
|
+
}) {
|
|
65712
65743
|
if (!populateUser) {
|
|
65713
65744
|
populateUser = populateFromDB2;
|
|
65714
65745
|
}
|
|
@@ -65722,7 +65753,7 @@ async function getUser(userId, tenantId, populateUser) {
|
|
|
65722
65753
|
const client = await getUserClient();
|
|
65723
65754
|
let user = await client.get(userId);
|
|
65724
65755
|
if (!user) {
|
|
65725
|
-
user = await populateUser(userId, tenantId);
|
|
65756
|
+
user = await populateUser(userId, tenantId, email);
|
|
65726
65757
|
await client.store(userId, user, EXPIRY_SECONDS3);
|
|
65727
65758
|
}
|
|
65728
65759
|
if (user && !user.tenantId && tenantId) {
|
|
@@ -66953,7 +66984,11 @@ async function checkApiKey(apiKey, populateUser) {
|
|
|
66953
66984
|
if (userId) {
|
|
66954
66985
|
return {
|
|
66955
66986
|
valid: true,
|
|
66956
|
-
user: await getUser(
|
|
66987
|
+
user: await getUser({
|
|
66988
|
+
userId,
|
|
66989
|
+
tenantId,
|
|
66990
|
+
populateUser
|
|
66991
|
+
})
|
|
66957
66992
|
};
|
|
66958
66993
|
} else {
|
|
66959
66994
|
throw new InvalidAPIKeyError();
|
|
@@ -66987,13 +67022,18 @@ function authenticated_default(noAuthPatterns = [], opts = {
|
|
|
66987
67022
|
try {
|
|
66988
67023
|
session = await getSession(userId, sessionId);
|
|
66989
67024
|
if (opts && opts.populateUser) {
|
|
66990
|
-
user = await getUser(
|
|
67025
|
+
user = await getUser({
|
|
66991
67026
|
userId,
|
|
66992
|
-
session.tenantId,
|
|
66993
|
-
|
|
66994
|
-
|
|
67027
|
+
tenantId: session.tenantId,
|
|
67028
|
+
email: session.email,
|
|
67029
|
+
populateUser: opts.populateUser(ctx)
|
|
67030
|
+
});
|
|
66995
67031
|
} else {
|
|
66996
|
-
user = await getUser(
|
|
67032
|
+
user = await getUser({
|
|
67033
|
+
userId,
|
|
67034
|
+
tenantId: session.tenantId,
|
|
67035
|
+
email: session.email
|
|
67036
|
+
});
|
|
66997
67037
|
}
|
|
66998
67038
|
user.csrfToken = session.csrfToken;
|
|
66999
67039
|
if (session?.lastAccessedAt < timeMinusOneMinute()) {
|
|
@@ -68619,32 +68659,25 @@ var InternalBuilder = class {
|
|
|
68619
68659
|
}
|
|
68620
68660
|
return withSchema;
|
|
68621
68661
|
}
|
|
68662
|
+
buildJsonField(field) {
|
|
68663
|
+
const parts = field.split(".");
|
|
68664
|
+
let tableField, unaliased;
|
|
68665
|
+
if (parts.length > 1) {
|
|
68666
|
+
const alias = parts.shift();
|
|
68667
|
+
unaliased = parts.join(".");
|
|
68668
|
+
tableField = `${this.quote(alias)}.${this.quote(unaliased)}`;
|
|
68669
|
+
} else {
|
|
68670
|
+
unaliased = parts.join(".");
|
|
68671
|
+
tableField = this.quote(unaliased);
|
|
68672
|
+
}
|
|
68673
|
+
const separator = this.client === "oracledb" /* ORACLE */ ? " VALUE " : ",";
|
|
68674
|
+
return `'${unaliased}'${separator}${tableField}`;
|
|
68675
|
+
}
|
|
68622
68676
|
addJsonRelationships(query, fromTable, relationships) {
|
|
68623
68677
|
const sqlClient = this.client;
|
|
68624
68678
|
const knex3 = this.knex;
|
|
68625
68679
|
const { resource, tableAliases: aliases, endpoint } = this.query;
|
|
68626
68680
|
const fields = resource?.fields || [];
|
|
68627
|
-
const jsonField = (field) => {
|
|
68628
|
-
const parts = field.split(".");
|
|
68629
|
-
let tableField, unaliased;
|
|
68630
|
-
if (parts.length > 1) {
|
|
68631
|
-
const alias = parts.shift();
|
|
68632
|
-
unaliased = parts.join(".");
|
|
68633
|
-
tableField = `${this.quote(alias)}.${this.quote(unaliased)}`;
|
|
68634
|
-
} else {
|
|
68635
|
-
unaliased = parts.join(".");
|
|
68636
|
-
tableField = this.quote(unaliased);
|
|
68637
|
-
}
|
|
68638
|
-
let separator = ",";
|
|
68639
|
-
switch (sqlClient) {
|
|
68640
|
-
case "oracledb" /* ORACLE */:
|
|
68641
|
-
separator = " VALUE ";
|
|
68642
|
-
break;
|
|
68643
|
-
case "mssql" /* MS_SQL */:
|
|
68644
|
-
separator = ":";
|
|
68645
|
-
}
|
|
68646
|
-
return `'${unaliased}'${separator}${tableField}`;
|
|
68647
|
-
};
|
|
68648
68681
|
for (let relationship of relationships) {
|
|
68649
68682
|
const {
|
|
68650
68683
|
tableName: toTable,
|
|
@@ -68671,7 +68704,7 @@ var InternalBuilder = class {
|
|
|
68671
68704
|
MAX_SQS_RELATIONSHIP_FIELDS
|
|
68672
68705
|
);
|
|
68673
68706
|
}
|
|
68674
|
-
const fieldList = relationshipFields.map((field) =>
|
|
68707
|
+
const fieldList = relationshipFields.map((field) => this.buildJsonField(field)).join(",");
|
|
68675
68708
|
const primaryKey = `${toAlias}.${toPrimary || toKey}`;
|
|
68676
68709
|
let subQuery = knex3.from(toTableWithSchema).limit(getRelationshipLimit()).orderBy(primaryKey);
|
|
68677
68710
|
if (throughTable && toPrimary && fromPrimary) {
|
|
@@ -68778,37 +68811,6 @@ var InternalBuilder = class {
|
|
|
68778
68811
|
}
|
|
68779
68812
|
return query;
|
|
68780
68813
|
}
|
|
68781
|
-
addRelationships(query, fromTable, relationships) {
|
|
68782
|
-
const tableSets = {};
|
|
68783
|
-
for (let relationship of relationships) {
|
|
68784
|
-
const keyObj = {
|
|
68785
|
-
toTable: relationship.tableName,
|
|
68786
|
-
throughTable: void 0
|
|
68787
|
-
};
|
|
68788
|
-
if (relationship.through) {
|
|
68789
|
-
keyObj.throughTable = relationship.through;
|
|
68790
|
-
}
|
|
68791
|
-
const key = JSON.stringify(keyObj);
|
|
68792
|
-
if (tableSets[key]) {
|
|
68793
|
-
tableSets[key].push(relationship);
|
|
68794
|
-
} else {
|
|
68795
|
-
tableSets[key] = [relationship];
|
|
68796
|
-
}
|
|
68797
|
-
}
|
|
68798
|
-
for (let [key, relationships2] of Object.entries(tableSets)) {
|
|
68799
|
-
const { toTable, throughTable } = JSON.parse(key);
|
|
68800
|
-
query = this.addJoin(
|
|
68801
|
-
query,
|
|
68802
|
-
{
|
|
68803
|
-
from: fromTable,
|
|
68804
|
-
to: toTable,
|
|
68805
|
-
through: throughTable
|
|
68806
|
-
},
|
|
68807
|
-
relationships2
|
|
68808
|
-
);
|
|
68809
|
-
}
|
|
68810
|
-
return query;
|
|
68811
|
-
}
|
|
68812
68814
|
qualifiedKnex(opts) {
|
|
68813
68815
|
let alias = this.query.tableAliases?.[this.query.endpoint.entityId];
|
|
68814
68816
|
if (opts?.alias === false) {
|
|
@@ -68873,8 +68875,7 @@ var InternalBuilder = class {
|
|
|
68873
68875
|
if (!primary) {
|
|
68874
68876
|
throw new Error("Primary key is required for upsert");
|
|
68875
68877
|
}
|
|
68876
|
-
|
|
68877
|
-
return ret;
|
|
68878
|
+
return query.insert(parsedBody).onConflict(primary).merge();
|
|
68878
68879
|
} else if (this.client === "mssql" /* MS_SQL */ || this.client === "oracledb" /* ORACLE */) {
|
|
68879
68880
|
return query.insert(parsedBody);
|
|
68880
68881
|
}
|
|
@@ -68911,10 +68912,18 @@ var InternalBuilder = class {
|
|
|
68911
68912
|
if (!counting) {
|
|
68912
68913
|
query = this.addSorting(query);
|
|
68913
68914
|
}
|
|
68914
|
-
|
|
68915
|
-
|
|
68915
|
+
query = this.addFilters(query, filters, { relationship: true });
|
|
68916
|
+
if (relationships?.length) {
|
|
68917
|
+
const mainTable = this.query.tableAliases?.[this.query.endpoint.entityId] || this.query.endpoint.entityId;
|
|
68918
|
+
const cte = this.addSorting(
|
|
68919
|
+
this.knex.with("paginated", query).select(this.generateSelectStatement()).from({
|
|
68920
|
+
[mainTable]: "paginated"
|
|
68921
|
+
})
|
|
68922
|
+
);
|
|
68923
|
+
return this.addJsonRelationships(cte, tableName, relationships);
|
|
68924
|
+
} else {
|
|
68925
|
+
return query;
|
|
68916
68926
|
}
|
|
68917
|
-
return this.addFilters(query, filters, { relationship: true });
|
|
68918
68927
|
}
|
|
68919
68928
|
update(opts) {
|
|
68920
68929
|
const { body: body2, filters } = this.query;
|