@restura/core 0.1.0-alpha.17 → 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 +1019 -1
- package/dist/index.d.ts +1019 -1
- package/dist/index.js +38 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1693,7 +1693,7 @@ var PsqlEngine = class extends SqlEngine {
|
|
|
1693
1693
|
await Promise.all(promises);
|
|
1694
1694
|
this.triggerClient.on("notification", async (msg) => {
|
|
1695
1695
|
if (msg.channel === "insert" || msg.channel === "update" || msg.channel === "delete") {
|
|
1696
|
-
const payload =
|
|
1696
|
+
const payload = ObjectUtils4.safeParse(msg.payload);
|
|
1697
1697
|
await this.handleTrigger(payload, msg.channel.toUpperCase());
|
|
1698
1698
|
}
|
|
1699
1699
|
});
|
|
@@ -1893,16 +1893,19 @@ var PsqlEngine = class extends SqlEngine {
|
|
|
1893
1893
|
parameterObj[assignment.name] = this.replaceParamKeywords(assignment.value, routeData, req, sqlParams);
|
|
1894
1894
|
});
|
|
1895
1895
|
const query = insertObjectQuery(routeData.table, __spreadValues(__spreadValues({}, req.data), parameterObj));
|
|
1896
|
-
const createdItem = await this.psqlConnectionPool.queryOne(
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1896
|
+
const createdItem = await this.psqlConnectionPool.queryOne(
|
|
1897
|
+
query,
|
|
1898
|
+
sqlParams,
|
|
1899
|
+
req.requesterDetails
|
|
1900
|
+
);
|
|
1901
|
+
const insertId = createdItem.id;
|
|
1902
|
+
const whereId = {
|
|
1903
|
+
tableName: routeData.table,
|
|
1904
|
+
value: insertId,
|
|
1905
|
+
columnName: "id",
|
|
1906
|
+
operator: "="
|
|
1907
|
+
};
|
|
1908
|
+
const whereData = [whereId];
|
|
1906
1909
|
req.data = { id: insertId };
|
|
1907
1910
|
return this.executeGetRequest(req, __spreadProps(__spreadValues({}, routeData), { where: whereData }), schema);
|
|
1908
1911
|
}
|
|
@@ -1921,7 +1924,9 @@ var PsqlEngine = class extends SqlEngine {
|
|
|
1921
1924
|
let selectStatement = "SELECT \n";
|
|
1922
1925
|
selectStatement += ` ${selectColumns.map((item) => {
|
|
1923
1926
|
if (item.subquery) {
|
|
1924
|
-
return `${this.createNestedSelect(req, schema, item, routeData, userRole, sqlParams)} AS ${
|
|
1927
|
+
return `${this.createNestedSelect(req, schema, item, routeData, userRole, sqlParams)} AS ${escapeColumnName(
|
|
1928
|
+
item.name
|
|
1929
|
+
)}`;
|
|
1925
1930
|
}
|
|
1926
1931
|
return `${escapeColumnName(item.selector)} AS ${escapeColumnName(item.name)}`;
|
|
1927
1932
|
}).join(",\n ")}
|
|
@@ -1961,7 +1966,11 @@ var PsqlEngine = class extends SqlEngine {
|
|
|
1961
1966
|
);
|
|
1962
1967
|
const totalQuery = `SELECT COUNT(${routeData.groupBy ? `DISTINCT ${routeData.groupBy.tableName}.${routeData.groupBy.columnName}` : "*"}) AS total
|
|
1963
1968
|
${sqlStatement};`;
|
|
1964
|
-
const totalPromise = await this.psqlConnectionPool.runQuery(
|
|
1969
|
+
const totalPromise = await this.psqlConnectionPool.runQuery(
|
|
1970
|
+
totalQuery,
|
|
1971
|
+
sqlParams,
|
|
1972
|
+
req.requesterDetails
|
|
1973
|
+
);
|
|
1965
1974
|
const [pageResults, totalResponse] = await Promise.all([pagePromise, totalPromise]);
|
|
1966
1975
|
let total = 0;
|
|
1967
1976
|
if (ObjectUtils4.isArrayWithData(totalResponse)) {
|
|
@@ -2074,17 +2083,16 @@ DELETE FROM "${routeData.table}" ${joinStatement} ${whereClause}`;
|
|
|
2074
2083
|
);
|
|
2075
2084
|
let operator = item.operator;
|
|
2076
2085
|
if (operator === "LIKE") {
|
|
2077
|
-
item.value =
|
|
2086
|
+
item.value = `'%${item.value}%'`;
|
|
2078
2087
|
} else if (operator === "STARTS WITH") {
|
|
2079
2088
|
operator = "LIKE";
|
|
2080
|
-
item.value =
|
|
2089
|
+
item.value = `'${item.value}%'`;
|
|
2081
2090
|
} else if (operator === "ENDS WITH") {
|
|
2082
2091
|
operator = "LIKE";
|
|
2083
|
-
item.value =
|
|
2092
|
+
item.value = `'%${item.value}'`;
|
|
2084
2093
|
}
|
|
2085
2094
|
const replacedValue = this.replaceParamKeywords(item.value, routeData, req, sqlParams);
|
|
2086
|
-
|
|
2087
|
-
whereClause += ` ${item.conjunction || ""} "${item.tableName}"."${item.columnName}" ${operator.replace("LIKE", "ILIKE")} ${["IN", "NOT IN"].includes(operator) ? `(${escapedValue})` : escapedValue}
|
|
2095
|
+
whereClause += ` ${item.conjunction || ""} "${item.tableName}"."${item.columnName}" ${operator.replace("LIKE", "ILIKE")} ${["IN", "NOT IN"].includes(operator) ? `(${replacedValue})` : replacedValue}
|
|
2088
2096
|
`;
|
|
2089
2097
|
});
|
|
2090
2098
|
const data = req.data;
|
|
@@ -2298,7 +2306,7 @@ var ResturaEngine = class {
|
|
|
2298
2306
|
async init(app, authenticationHandler, psqlConnectionPool) {
|
|
2299
2307
|
this.resturaConfig = config2.validate("restura", resturaConfigSchema);
|
|
2300
2308
|
this.psqlConnectionPool = psqlConnectionPool;
|
|
2301
|
-
this.psqlEngine = new PsqlEngine(this.psqlConnectionPool);
|
|
2309
|
+
this.psqlEngine = new PsqlEngine(this.psqlConnectionPool, true);
|
|
2302
2310
|
setupPgReturnTypes();
|
|
2303
2311
|
await customApiFactory_default.loadApiFiles(this.resturaConfig.customApiFolderPath);
|
|
2304
2312
|
this.authenticationHandler = authenticationHandler;
|
|
@@ -2662,10 +2670,17 @@ var PsqlTransaction = class extends PsqlConnection {
|
|
|
2662
2670
|
super();
|
|
2663
2671
|
this.clientConfig = clientConfig;
|
|
2664
2672
|
this.client = new Client2(clientConfig);
|
|
2673
|
+
this.connectPromise = this.client.connect();
|
|
2665
2674
|
this.beginTransactionPromise = this.beginTransaction();
|
|
2666
2675
|
}
|
|
2676
|
+
async close() {
|
|
2677
|
+
if (this.client) {
|
|
2678
|
+
await this.client.end();
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2667
2681
|
async beginTransaction() {
|
|
2668
|
-
|
|
2682
|
+
await this.connectPromise;
|
|
2683
|
+
return this.client.query("BEGIN");
|
|
2669
2684
|
}
|
|
2670
2685
|
async rollback() {
|
|
2671
2686
|
return this.query("ROLLBACK");
|
|
@@ -2677,7 +2692,7 @@ var PsqlTransaction = class extends PsqlConnection {
|
|
|
2677
2692
|
return this.client.end();
|
|
2678
2693
|
}
|
|
2679
2694
|
async query(query, values) {
|
|
2680
|
-
await this.
|
|
2695
|
+
await this.connectPromise;
|
|
2681
2696
|
await this.beginTransactionPromise;
|
|
2682
2697
|
return this.client.query(query, values);
|
|
2683
2698
|
}
|
|
@@ -2685,6 +2700,7 @@ var PsqlTransaction = class extends PsqlConnection {
|
|
|
2685
2700
|
export {
|
|
2686
2701
|
HtmlStatusCodes,
|
|
2687
2702
|
PsqlConnection,
|
|
2703
|
+
PsqlEngine,
|
|
2688
2704
|
PsqlPool,
|
|
2689
2705
|
PsqlTransaction,
|
|
2690
2706
|
RsError,
|