@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.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 = JSON.parse(msg.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(query, sqlParams, req.requesterDetails);
1897
- const insertId = createdItem == null ? void 0 : createdItem.id;
1898
- const whereData = [
1899
- {
1900
- tableName: routeData.table,
1901
- value: insertId,
1902
- columnName: "id",
1903
- operator: "="
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 ${item.name}`;
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(totalQuery, sqlParams, req.requesterDetails);
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 = `%${item.value}%`;
2086
+ item.value = `'%${item.value}%'`;
2078
2087
  } else if (operator === "STARTS WITH") {
2079
2088
  operator = "LIKE";
2080
- item.value = `${item.value}%`;
2089
+ item.value = `'${item.value}%'`;
2081
2090
  } else if (operator === "ENDS WITH") {
2082
2091
  operator = "LIKE";
2083
- item.value = `%${item.value}`;
2092
+ item.value = `'%${item.value}'`;
2084
2093
  }
2085
2094
  const replacedValue = this.replaceParamKeywords(item.value, routeData, req, sqlParams);
2086
- const escapedValue = SQL`${replacedValue}`;
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;
@@ -2692,6 +2700,7 @@ var PsqlTransaction = class extends PsqlConnection {
2692
2700
  export {
2693
2701
  HtmlStatusCodes,
2694
2702
  PsqlConnection,
2703
+ PsqlEngine,
2695
2704
  PsqlPool,
2696
2705
  PsqlTransaction,
2697
2706
  RsError,