@restura/core 0.1.0-alpha.18 → 0.1.0-alpha.19
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.d.mts +1017 -1
- package/dist/index.d.ts +1017 -1
- package/dist/index.js +29 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -69,6 +69,7 @@ var src_exports = {};
|
|
|
69
69
|
__export(src_exports, {
|
|
70
70
|
HtmlStatusCodes: () => HtmlStatusCodes,
|
|
71
71
|
PsqlConnection: () => PsqlConnection,
|
|
72
|
+
PsqlEngine: () => PsqlEngine,
|
|
72
73
|
PsqlPool: () => PsqlPool,
|
|
73
74
|
PsqlTransaction: () => PsqlTransaction,
|
|
74
75
|
RsError: () => RsError,
|
|
@@ -1738,7 +1739,7 @@ var PsqlEngine = class extends SqlEngine {
|
|
|
1738
1739
|
await Promise.all(promises);
|
|
1739
1740
|
this.triggerClient.on("notification", async (msg) => {
|
|
1740
1741
|
if (msg.channel === "insert" || msg.channel === "update" || msg.channel === "delete") {
|
|
1741
|
-
const payload =
|
|
1742
|
+
const payload = import_core_utils5.ObjectUtils.safeParse(msg.payload);
|
|
1742
1743
|
await this.handleTrigger(payload, msg.channel.toUpperCase());
|
|
1743
1744
|
}
|
|
1744
1745
|
});
|
|
@@ -1938,16 +1939,19 @@ var PsqlEngine = class extends SqlEngine {
|
|
|
1938
1939
|
parameterObj[assignment.name] = this.replaceParamKeywords(assignment.value, routeData, req, sqlParams);
|
|
1939
1940
|
});
|
|
1940
1941
|
const query = insertObjectQuery(routeData.table, __spreadValues(__spreadValues({}, req.data), parameterObj));
|
|
1941
|
-
const createdItem = await this.psqlConnectionPool.queryOne(
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1942
|
+
const createdItem = await this.psqlConnectionPool.queryOne(
|
|
1943
|
+
query,
|
|
1944
|
+
sqlParams,
|
|
1945
|
+
req.requesterDetails
|
|
1946
|
+
);
|
|
1947
|
+
const insertId = createdItem.id;
|
|
1948
|
+
const whereId = {
|
|
1949
|
+
tableName: routeData.table,
|
|
1950
|
+
value: insertId,
|
|
1951
|
+
columnName: "id",
|
|
1952
|
+
operator: "="
|
|
1953
|
+
};
|
|
1954
|
+
const whereData = [whereId];
|
|
1951
1955
|
req.data = { id: insertId };
|
|
1952
1956
|
return this.executeGetRequest(req, __spreadProps(__spreadValues({}, routeData), { where: whereData }), schema);
|
|
1953
1957
|
}
|
|
@@ -1966,7 +1970,9 @@ var PsqlEngine = class extends SqlEngine {
|
|
|
1966
1970
|
let selectStatement = "SELECT \n";
|
|
1967
1971
|
selectStatement += ` ${selectColumns.map((item) => {
|
|
1968
1972
|
if (item.subquery) {
|
|
1969
|
-
return `${this.createNestedSelect(req, schema, item, routeData, userRole, sqlParams)} AS ${
|
|
1973
|
+
return `${this.createNestedSelect(req, schema, item, routeData, userRole, sqlParams)} AS ${escapeColumnName(
|
|
1974
|
+
item.name
|
|
1975
|
+
)}`;
|
|
1970
1976
|
}
|
|
1971
1977
|
return `${escapeColumnName(item.selector)} AS ${escapeColumnName(item.name)}`;
|
|
1972
1978
|
}).join(",\n ")}
|
|
@@ -2006,7 +2012,11 @@ var PsqlEngine = class extends SqlEngine {
|
|
|
2006
2012
|
);
|
|
2007
2013
|
const totalQuery = `SELECT COUNT(${routeData.groupBy ? `DISTINCT ${routeData.groupBy.tableName}.${routeData.groupBy.columnName}` : "*"}) AS total
|
|
2008
2014
|
${sqlStatement};`;
|
|
2009
|
-
const totalPromise = await this.psqlConnectionPool.runQuery(
|
|
2015
|
+
const totalPromise = await this.psqlConnectionPool.runQuery(
|
|
2016
|
+
totalQuery,
|
|
2017
|
+
sqlParams,
|
|
2018
|
+
req.requesterDetails
|
|
2019
|
+
);
|
|
2010
2020
|
const [pageResults, totalResponse] = await Promise.all([pagePromise, totalPromise]);
|
|
2011
2021
|
let total = 0;
|
|
2012
2022
|
if (import_core_utils5.ObjectUtils.isArrayWithData(totalResponse)) {
|
|
@@ -2119,17 +2129,16 @@ DELETE FROM "${routeData.table}" ${joinStatement} ${whereClause}`;
|
|
|
2119
2129
|
);
|
|
2120
2130
|
let operator = item.operator;
|
|
2121
2131
|
if (operator === "LIKE") {
|
|
2122
|
-
item.value =
|
|
2132
|
+
item.value = `'%${item.value}%'`;
|
|
2123
2133
|
} else if (operator === "STARTS WITH") {
|
|
2124
2134
|
operator = "LIKE";
|
|
2125
|
-
item.value =
|
|
2135
|
+
item.value = `'${item.value}%'`;
|
|
2126
2136
|
} else if (operator === "ENDS WITH") {
|
|
2127
2137
|
operator = "LIKE";
|
|
2128
|
-
item.value =
|
|
2138
|
+
item.value = `'%${item.value}'`;
|
|
2129
2139
|
}
|
|
2130
2140
|
const replacedValue = this.replaceParamKeywords(item.value, routeData, req, sqlParams);
|
|
2131
|
-
|
|
2132
|
-
whereClause += ` ${item.conjunction || ""} "${item.tableName}"."${item.columnName}" ${operator.replace("LIKE", "ILIKE")} ${["IN", "NOT IN"].includes(operator) ? `(${escapedValue})` : escapedValue}
|
|
2141
|
+
whereClause += ` ${item.conjunction || ""} "${item.tableName}"."${item.columnName}" ${operator.replace("LIKE", "ILIKE")} ${["IN", "NOT IN"].includes(operator) ? `(${replacedValue})` : replacedValue}
|
|
2133
2142
|
`;
|
|
2134
2143
|
});
|
|
2135
2144
|
const data = req.data;
|
|
@@ -2343,7 +2352,7 @@ var ResturaEngine = class {
|
|
|
2343
2352
|
async init(app, authenticationHandler, psqlConnectionPool) {
|
|
2344
2353
|
this.resturaConfig = import_internal2.config.validate("restura", resturaConfigSchema);
|
|
2345
2354
|
this.psqlConnectionPool = psqlConnectionPool;
|
|
2346
|
-
this.psqlEngine = new PsqlEngine(this.psqlConnectionPool);
|
|
2355
|
+
this.psqlEngine = new PsqlEngine(this.psqlConnectionPool, true);
|
|
2347
2356
|
setupPgReturnTypes();
|
|
2348
2357
|
await customApiFactory_default.loadApiFiles(this.resturaConfig.customApiFolderPath);
|
|
2349
2358
|
this.authenticationHandler = authenticationHandler;
|
|
@@ -2738,6 +2747,7 @@ var PsqlTransaction = class extends PsqlConnection {
|
|
|
2738
2747
|
0 && (module.exports = {
|
|
2739
2748
|
HtmlStatusCodes,
|
|
2740
2749
|
PsqlConnection,
|
|
2750
|
+
PsqlEngine,
|
|
2741
2751
|
PsqlPool,
|
|
2742
2752
|
PsqlTransaction,
|
|
2743
2753
|
RsError,
|