@restura/core 2.1.0 → 2.1.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 +27 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -259,7 +259,7 @@ var SqlUtils = class _SqlUtils {
|
|
|
259
259
|
if (type.startsWith("decimal") || type.startsWith("numeric")) return "string";
|
|
260
260
|
if (type.indexOf("int") > -1 || type.startsWith("double") || type.startsWith("float") || type.indexOf("serial") > -1 || type.startsWith("real") || type.startsWith("double precision"))
|
|
261
261
|
return "number";
|
|
262
|
-
if (type === "json") {
|
|
262
|
+
if (type === "json" || type === "jsonb") {
|
|
263
263
|
if (!value) return "object";
|
|
264
264
|
return value.split(",").map((val) => {
|
|
265
265
|
return val.replace(/['"]/g, "");
|
|
@@ -2359,23 +2359,31 @@ CREATE INDEX IF NOT EXISTS "${OUTBOX_TABLE_NAME}_processedOn_index" ON "${OUTBOX
|
|
|
2359
2359
|
}
|
|
2360
2360
|
function resolveNotifyColumns(tableName, notify, tableColumns) {
|
|
2361
2361
|
if (!notify) return [];
|
|
2362
|
+
let columns;
|
|
2362
2363
|
if (notify === "ALL") {
|
|
2363
2364
|
if (!tableColumns) {
|
|
2364
2365
|
throw new Error(
|
|
2365
2366
|
`notify: "ALL" on table "${tableName}" requires tableColumns so the sensitive-column denylist can be applied. Pass options.tableColumns or list columns explicitly.`
|
|
2366
2367
|
);
|
|
2367
2368
|
}
|
|
2368
|
-
|
|
2369
|
+
columns = tableColumns.filter((column) => !isSensitiveColumnName(column));
|
|
2370
|
+
} else {
|
|
2371
|
+
columns = notify.map((entry) => {
|
|
2372
|
+
if (entry.startsWith("!")) return entry.slice(1);
|
|
2373
|
+
if (isSensitiveColumnName(entry)) {
|
|
2374
|
+
throw new Error(
|
|
2375
|
+
`Refusing to include sensitive column "${tableName}"."${entry}" in notify trigger payloads. Remove it from the notify list or prefix it with '!' to force-include it.`
|
|
2376
|
+
);
|
|
2377
|
+
}
|
|
2378
|
+
return entry;
|
|
2379
|
+
});
|
|
2369
2380
|
}
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
}
|
|
2377
|
-
return entry;
|
|
2378
|
-
});
|
|
2381
|
+
if (!columns.length) {
|
|
2382
|
+
throw new Error(
|
|
2383
|
+
`notify config on table "${tableName}" resolves to no columns \u2014 remove the notify key or list at least one column.`
|
|
2384
|
+
);
|
|
2385
|
+
}
|
|
2386
|
+
return columns;
|
|
2379
2387
|
}
|
|
2380
2388
|
function sqlStringLiteral(value) {
|
|
2381
2389
|
return value.replace(/'/g, "''");
|
|
@@ -2425,7 +2433,13 @@ function buildTriggerFunctionSql(tableName, operation, notify, options) {
|
|
|
2425
2433
|
const outboxDeclare = delivery === "outbox" ? "\n outbox_id BIGINT;" : "";
|
|
2426
2434
|
const legacyDrop = operation === "update" && tableName !== tableName.toLowerCase() ? `DROP TRIGGER IF EXISTS ${tableName}_update ON "${tableName}";
|
|
2427
2435
|
` : "";
|
|
2428
|
-
|
|
2436
|
+
let updateScope = "";
|
|
2437
|
+
let updateGuard = "";
|
|
2438
|
+
if (operation === "update") {
|
|
2439
|
+
updateScope = ` OF ${columns.map((column) => `"${column}"`).join(", ")}`;
|
|
2440
|
+
updateGuard = `
|
|
2441
|
+
WHEN (${columns.map((column) => `OLD."${column}" IS DISTINCT FROM NEW."${column}"`).join(" OR ")})`;
|
|
2442
|
+
}
|
|
2429
2443
|
return `
|
|
2430
2444
|
CREATE OR REPLACE FUNCTION ${functionName}()
|
|
2431
2445
|
RETURNS TRIGGER AS $$
|
|
@@ -2440,7 +2454,7 @@ END;
|
|
|
2440
2454
|
$$ LANGUAGE plpgsql;
|
|
2441
2455
|
|
|
2442
2456
|
${legacyDrop}CREATE OR REPLACE TRIGGER "${tableName}_${operation}"
|
|
2443
|
-
AFTER ${operation.toUpperCase()} ON "${tableName}"
|
|
2457
|
+
AFTER ${operation.toUpperCase()}${updateScope} ON "${tableName}"
|
|
2444
2458
|
FOR EACH ROW${updateGuard}
|
|
2445
2459
|
EXECUTE FUNCTION ${functionName}();
|
|
2446
2460
|
`;
|