@carbonorm/carbonnode 6.0.19 → 6.0.20

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.
Files changed (61) hide show
  1. package/dist/executors/SqlExecutor.d.ts +7 -0
  2. package/dist/index.cjs.js +215 -20
  3. package/dist/index.cjs.js.map +1 -1
  4. package/dist/index.esm.js +215 -20
  5. package/dist/index.esm.js.map +1 -1
  6. package/dist/types/ormInterfaces.d.ts +1 -0
  7. package/dist/utils/cacheManager.d.ts +3 -2
  8. package/package.json +1 -1
  9. package/src/__tests__/cacheManager.test.ts +28 -0
  10. package/src/__tests__/sakila-db/C6.js +1 -1
  11. package/src/__tests__/sakila-db/C6.mysqldump.json +1 -1
  12. package/src/__tests__/sakila-db/C6.mysqldump.sql +1 -1
  13. package/src/__tests__/sakila-db/C6.ts +1 -1
  14. package/src/__tests__/sakila-db/sqlResponses/C6.actor.post.json +11 -4
  15. package/src/__tests__/sakila-db/sqlResponses/C6.actor.post.latest.json +3 -3
  16. package/src/__tests__/sakila-db/sqlResponses/C6.actor.put.json +1 -1
  17. package/src/__tests__/sakila-db/sqlResponses/C6.actor.put.lookup.json +3 -3
  18. package/src/__tests__/sakila-db/sqlResponses/C6.address.post.json +18 -6
  19. package/src/__tests__/sakila-db/sqlResponses/C6.address.post.latest.json +5 -5
  20. package/src/__tests__/sakila-db/sqlResponses/C6.address.put.json +1 -1
  21. package/src/__tests__/sakila-db/sqlResponses/C6.address.put.lookup.json +5 -5
  22. package/src/__tests__/sakila-db/sqlResponses/C6.category.post.json +9 -3
  23. package/src/__tests__/sakila-db/sqlResponses/C6.category.post.latest.json +2 -2
  24. package/src/__tests__/sakila-db/sqlResponses/C6.category.put.json +1 -1
  25. package/src/__tests__/sakila-db/sqlResponses/C6.category.put.lookup.json +2 -2
  26. package/src/__tests__/sakila-db/sqlResponses/C6.city.post.json +10 -3
  27. package/src/__tests__/sakila-db/sqlResponses/C6.city.post.latest.json +2 -2
  28. package/src/__tests__/sakila-db/sqlResponses/C6.city.put.json +1 -1
  29. package/src/__tests__/sakila-db/sqlResponses/C6.city.put.lookup.json +2 -2
  30. package/src/__tests__/sakila-db/sqlResponses/C6.country.post.json +9 -3
  31. package/src/__tests__/sakila-db/sqlResponses/C6.country.post.latest.json +2 -2
  32. package/src/__tests__/sakila-db/sqlResponses/C6.country.put.json +1 -1
  33. package/src/__tests__/sakila-db/sqlResponses/C6.country.put.lookup.json +2 -2
  34. package/src/__tests__/sakila-db/sqlResponses/C6.customer.post.json +18 -6
  35. package/src/__tests__/sakila-db/sqlResponses/C6.customer.post.latest.json +5 -5
  36. package/src/__tests__/sakila-db/sqlResponses/C6.customer.put.json +1 -1
  37. package/src/__tests__/sakila-db/sqlResponses/C6.customer.put.lookup.json +5 -5
  38. package/src/__tests__/sakila-db/sqlResponses/C6.film.post.json +18 -3
  39. package/src/__tests__/sakila-db/sqlResponses/C6.film.post.latest.json +2 -2
  40. package/src/__tests__/sakila-db/sqlResponses/C6.film.put.json +1 -1
  41. package/src/__tests__/sakila-db/sqlResponses/C6.film.put.lookup.json +2 -2
  42. package/src/__tests__/sakila-db/sqlResponses/C6.inventory.post.json +9 -2
  43. package/src/__tests__/sakila-db/sqlResponses/C6.inventory.post.latest.json +1 -1
  44. package/src/__tests__/sakila-db/sqlResponses/C6.inventory.put.json +1 -1
  45. package/src/__tests__/sakila-db/sqlResponses/C6.inventory.put.lookup.json +1 -1
  46. package/src/__tests__/sakila-db/sqlResponses/C6.language.post.json +9 -3
  47. package/src/__tests__/sakila-db/sqlResponses/C6.language.post.latest.json +2 -2
  48. package/src/__tests__/sakila-db/sqlResponses/C6.language.put.json +1 -1
  49. package/src/__tests__/sakila-db/sqlResponses/C6.language.put.lookup.json +2 -2
  50. package/src/__tests__/sakila-db/sqlResponses/C6.payment.post.json +13 -3
  51. package/src/__tests__/sakila-db/sqlResponses/C6.payment.post.latest.json +2 -2
  52. package/src/__tests__/sakila-db/sqlResponses/C6.payment.put.lookup.json +2 -2
  53. package/src/__tests__/sakila-db/sqlResponses/C6.rental.post.json +14 -4
  54. package/src/__tests__/sakila-db/sqlResponses/C6.rental.post.latest.json +3 -3
  55. package/src/__tests__/sakila-db/sqlResponses/C6.rental.put.json +1 -1
  56. package/src/__tests__/sakila-db/sqlResponses/C6.rental.put.lookup.json +3 -3
  57. package/src/__tests__/sqlExecutorPostUuid.test.ts +185 -0
  58. package/src/executors/HttpExecutor.ts +33 -5
  59. package/src/executors/SqlExecutor.ts +207 -3
  60. package/src/types/ormInterfaces.ts +1 -0
  61. package/src/utils/cacheManager.ts +6 -4
package/dist/index.esm.js CHANGED
@@ -951,7 +951,7 @@ function colorSql(sql) {
951
951
  return s;
952
952
  }
953
953
 
954
- var version = "6.0.19";
954
+ var version = "6.0.20";
955
955
 
956
956
  var DEFAULT_STEP = 8;
957
957
  function parseSemver(version) {
@@ -1111,8 +1111,8 @@ function clearCache(props) {
1111
1111
  // -----------------------------------------------------------------------------
1112
1112
  // Check Cache (dedupe via hashed key)
1113
1113
  // -----------------------------------------------------------------------------
1114
- function checkCache(method, tableName, requestData, logContext) {
1115
- var _a, _b, _c, _d, _e;
1114
+ function checkCache(method, tableName, requestData, logContext, allowListStatus) {
1115
+ var _a, _b, _c, _d, _e, _f, _g;
1116
1116
  var key = makeCacheKey(method, tableName, requestData);
1117
1117
  var cached = apiRequestCache.get(key);
1118
1118
  if (!cached) {
@@ -1122,7 +1122,7 @@ function checkCache(method, tableName, requestData, logContext) {
1122
1122
  var sql = (_d = (_c = (_b = (_a = cached.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.sql) === null || _c === void 0 ? void 0 : _c.sql) !== null && _d !== void 0 ? _d : "";
1123
1123
  var sqlMethod = ((_e = sql.trim().split(/\s+/, 1)[0]) === null || _e === void 0 ? void 0 : _e.toUpperCase()) || method;
1124
1124
  logSql({
1125
- allowListStatus: "not verified",
1125
+ allowListStatus: (_g = (_f = cached.allowListStatus) !== null && _f !== void 0 ? _f : allowListStatus) !== null && _g !== void 0 ? _g : "not verified",
1126
1126
  cacheStatus: "hit",
1127
1127
  context: logContext,
1128
1128
  method: sqlMethod,
@@ -1138,8 +1138,8 @@ function setCache(method, tableName, requestData, cacheEntry) {
1138
1138
  var key = makeCacheKey(method, tableName, requestData);
1139
1139
  apiRequestCache.set(key, cacheEntry);
1140
1140
  }
1141
- function evictCacheEntry(method, tableName, requestData, logContext) {
1142
- var _a, _b, _c, _d, _e;
1141
+ function evictCacheEntry(method, tableName, requestData, logContext, allowListStatus) {
1142
+ var _a, _b, _c, _d, _e, _f, _g;
1143
1143
  var key = makeCacheKey(method, tableName, requestData);
1144
1144
  var cached = apiRequestCache.get(key);
1145
1145
  var deleted = apiRequestCache.delete(key);
@@ -1147,7 +1147,7 @@ function evictCacheEntry(method, tableName, requestData, logContext) {
1147
1147
  var sql = (_d = (_c = (_b = (_a = cached === null || cached === void 0 ? void 0 : cached.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.sql) === null || _c === void 0 ? void 0 : _c.sql) !== null && _d !== void 0 ? _d : "";
1148
1148
  var sqlMethod = ((_e = sql.trim().split(/\s+/, 1)[0]) === null || _e === void 0 ? void 0 : _e.toUpperCase()) || method;
1149
1149
  logSql({
1150
- allowListStatus: "not verified",
1150
+ allowListStatus: (_g = (_f = cached === null || cached === void 0 ? void 0 : cached.allowListStatus) !== null && _f !== void 0 ? _f : allowListStatus) !== null && _g !== void 0 ? _g : "not verified",
1151
1151
  cacheStatus: "evicted",
1152
1152
  context: logContext,
1153
1153
  method: sqlMethod,
@@ -1202,27 +1202,34 @@ var HttpExecutor = /** @class */ (function (_super) {
1202
1202
  };
1203
1203
  HttpExecutor.prototype.postState = function (response, request, callback) {
1204
1204
  var _this = this;
1205
- var _a, _b, _c;
1205
+ var _a, _b, _c, _d, _e, _f;
1206
+ var responseRestRaw = (_a = response.data) === null || _a === void 0 ? void 0 : _a.rest;
1207
+ var responseRows = Array.isArray(responseRestRaw)
1208
+ ? responseRestRaw
1209
+ : (responseRestRaw ? [responseRestRaw] : []);
1206
1210
  if (this.config.restModel.PRIMARY_SHORT.length === 1) {
1207
1211
  var pk = this.config.restModel.PRIMARY_SHORT[0];
1208
1212
  try {
1209
- request[pk] = (_a = response.data) === null || _a === void 0 ? void 0 : _a.created;
1213
+ var created = (_c = (_b = response.data) === null || _b === void 0 ? void 0 : _b.created) !== null && _c !== void 0 ? _c : (_d = responseRows[0]) === null || _d === void 0 ? void 0 : _d[pk];
1214
+ if (created !== undefined) {
1215
+ request[pk] = created;
1216
+ }
1210
1217
  }
1211
- catch ( /* best-effort */_d) { /* best-effort */ }
1218
+ catch ( /* best-effort */_g) { /* best-effort */ }
1212
1219
  }
1213
1220
  else if (isLocal()) {
1214
1221
  logWithLevel(LogLevel.ERROR, getLogContext(this.config, this.request), console.error, "C6 received unexpected results given the primary key length");
1215
1222
  }
1216
- (_b = this.config.reactBootstrap) === null || _b === void 0 ? void 0 : _b.updateRestfulObjectArrays({
1223
+ (_e = this.config.reactBootstrap) === null || _e === void 0 ? void 0 : _e.updateRestfulObjectArrays({
1217
1224
  callback: callback,
1218
1225
  dataOrCallback: undefined !== request.dataInsertMultipleRows
1219
1226
  ? request.dataInsertMultipleRows.map(function (row, index) {
1220
1227
  var _a;
1221
1228
  var normalizedRow = _this.stripTableNameFromKeys(row);
1222
- return removeInvalidKeys(__assign(__assign({}, normalizedRow), (index === 0 ? (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.rest : {})), _this.config.C6.TABLES);
1229
+ return removeInvalidKeys(__assign(__assign({}, normalizedRow), ((_a = responseRows[index]) !== null && _a !== void 0 ? _a : {})), _this.config.C6.TABLES);
1223
1230
  })
1224
1231
  : [
1225
- removeInvalidKeys(__assign(__assign({}, this.stripTableNameFromKeys(request)), (_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.rest), this.config.C6.TABLES)
1232
+ removeInvalidKeys(__assign(__assign({}, this.stripTableNameFromKeys(request)), ((_f = responseRows[0]) !== null && _f !== void 0 ? _f : {})), this.config.C6.TABLES)
1226
1233
  ],
1227
1234
  stateKey: this.config.restModel.TABLE_NAME,
1228
1235
  uniqueObjectId: this.config.restModel.PRIMARY_SHORT
@@ -1281,7 +1288,7 @@ var HttpExecutor = /** @class */ (function (_super) {
1281
1288
  }
1282
1289
  query = this.request;
1283
1290
  apiRequest = function () { return __awaiter(_this, void 0, void 0, function () {
1284
- var _a, debug, _b, cacheResults, dataInsertMultipleRows, success, _c, fetchDependencies, _d, error, cachingConfirmed, cacheRequestData, evictFromCache, querySerialized, cachedRequest, cachedData, apiResponse, restRequestUri, needsConditionOrPrimaryCheck, TABLES, primaryKeyList, primaryKeyFullyQualified, primaryKey, whereVal, whereIsEmpty, providedPrimary, primaryVal, axiosActiveRequest_1;
1291
+ var _a, debug, _b, cacheResults, dataInsertMultipleRows, success, _c, fetchDependencies, _d, error, cachingConfirmed, cacheRequestData, cacheAllowListStatus, evictFromCache, querySerialized, cachedRequest, cachedData, apiResponse, restRequestUri, needsConditionOrPrimaryCheck, TABLES, primaryKeyList, primaryKeyFullyQualified, primaryKey, whereVal, whereIsEmpty, providedPrimary, primaryVal, axiosActiveRequest_1;
1285
1292
  var _e;
1286
1293
  var _this = this;
1287
1294
  var _f, _g, _h, _j, _k, _l;
@@ -1311,13 +1318,16 @@ var HttpExecutor = /** @class */ (function (_super) {
1311
1318
  query[C6.PAGINATION][C6.LIMIT] = query[C6.PAGINATION][C6.LIMIT] || 100;
1312
1319
  }
1313
1320
  cacheRequestData = JSON.parse(JSON.stringify(query !== null && query !== void 0 ? query : {}));
1321
+ cacheAllowListStatus = this.config.sqlAllowListPath
1322
+ ? "allowed"
1323
+ : "not verified";
1314
1324
  evictFromCache = requestMethod === GET && cacheResults
1315
- ? function () { return evictCacheEntry(requestMethod, tableName, cacheRequestData, logContext); }
1325
+ ? function () { return evictCacheEntry(requestMethod, tableName, cacheRequestData, logContext, cacheAllowListStatus); }
1316
1326
  : undefined;
1317
1327
  querySerialized = sortAndSerializeQueryObject(tables, cacheRequestData !== null && cacheRequestData !== void 0 ? cacheRequestData : {});
1318
1328
  cachedRequest = false;
1319
1329
  if (cacheResults) {
1320
- cachedRequest = checkCache(requestMethod, tableName, cacheRequestData, logContext);
1330
+ cachedRequest = checkCache(requestMethod, tableName, cacheRequestData, logContext, cacheAllowListStatus);
1321
1331
  }
1322
1332
  if (!cachedRequest) return [3 /*break*/, 2];
1323
1333
  return [4 /*yield*/, cachedRequest];
@@ -1441,6 +1451,7 @@ var HttpExecutor = /** @class */ (function (_super) {
1441
1451
  setCache(requestMethod, tableName, cacheRequestData, {
1442
1452
  requestArgumentsSerialized: querySerialized,
1443
1453
  request: axiosActiveRequest_1,
1454
+ allowListStatus: cacheAllowListStatus,
1444
1455
  });
1445
1456
  }
1446
1457
  // returning the promise with this then is important for tests. todo - we could make that optional.
@@ -1458,6 +1469,7 @@ var HttpExecutor = /** @class */ (function (_super) {
1458
1469
  setCache(requestMethod, tableName, cacheRequestData, {
1459
1470
  requestArgumentsSerialized: querySerialized,
1460
1471
  request: axiosActiveRequest_1,
1472
+ allowListStatus: cacheAllowListStatus,
1461
1473
  response: response,
1462
1474
  final: true,
1463
1475
  });
@@ -1474,6 +1486,7 @@ var HttpExecutor = /** @class */ (function (_super) {
1474
1486
  setCache(requestMethod, tableName, cacheRequestData, {
1475
1487
  requestArgumentsSerialized: querySerialized,
1476
1488
  request: axiosActiveRequest_1,
1489
+ allowListStatus: cacheAllowListStatus,
1477
1490
  response: response,
1478
1491
  });
1479
1492
  }
@@ -1538,6 +1551,7 @@ var HttpExecutor = /** @class */ (function (_super) {
1538
1551
  setCache(requestMethod, tableName, cacheRequestData, {
1539
1552
  requestArgumentsSerialized: querySerialized,
1540
1553
  request: axiosActiveRequest_1,
1554
+ allowListStatus: cacheAllowListStatus,
1541
1555
  response: response,
1542
1556
  final: !hasNext,
1543
1557
  });
@@ -1737,6 +1751,7 @@ var HttpExecutor = /** @class */ (function (_super) {
1737
1751
  setCache(requestMethod, tableName, cacheRequestData, {
1738
1752
  requestArgumentsSerialized: querySerialized,
1739
1753
  request: axiosActiveRequest_1,
1754
+ allowListStatus: cacheAllowListStatus,
1740
1755
  response: response,
1741
1756
  final: true,
1742
1757
  });
@@ -3685,6 +3700,38 @@ var compileSqlAllowList = function (allowListPath, entries) { return __awaiter(v
3685
3700
  }); };
3686
3701
 
3687
3702
  var SQL_ALLOWLIST_BLOCKED_CODE = "SQL_ALLOWLIST_BLOCKED";
3703
+ var fillRandomBytes = function (bytes) {
3704
+ var cryptoRef = globalThis.crypto;
3705
+ if (!cryptoRef || typeof cryptoRef.getRandomValues !== "function") {
3706
+ throw new Error("Secure random source unavailable: crypto.getRandomValues is required for UUID generation.");
3707
+ }
3708
+ cryptoRef.getRandomValues(bytes);
3709
+ };
3710
+ var generateUuidV7 = function () {
3711
+ var bytes = new Uint8Array(16);
3712
+ var random = new Uint8Array(10);
3713
+ fillRandomBytes(random);
3714
+ var timestampMs = Date.now();
3715
+ bytes[0] = Math.floor(timestampMs / 1099511627776) & 0xff; // 2^40
3716
+ bytes[1] = Math.floor(timestampMs / 4294967296) & 0xff; // 2^32
3717
+ bytes[2] = Math.floor(timestampMs / 16777216) & 0xff; // 2^24
3718
+ bytes[3] = Math.floor(timestampMs / 65536) & 0xff; // 2^16
3719
+ bytes[4] = Math.floor(timestampMs / 256) & 0xff; // 2^8
3720
+ bytes[5] = timestampMs & 0xff;
3721
+ // RFC 9562 UUIDv7 layout
3722
+ bytes[6] = 0x70 | (random[0] & 0x0f); // version 7 + rand_a high bits
3723
+ bytes[7] = random[1]; // rand_a low bits
3724
+ bytes[8] = 0x80 | (random[2] & 0x3f); // variant + rand_b high bits
3725
+ bytes[9] = random[3];
3726
+ bytes[10] = random[4];
3727
+ bytes[11] = random[5];
3728
+ bytes[12] = random[6];
3729
+ bytes[13] = random[7];
3730
+ bytes[14] = random[8];
3731
+ bytes[15] = random[9];
3732
+ var hex = Array.from(bytes, function (byte) { return byte.toString(16).padStart(2, "0"); }).join("");
3733
+ return "".concat(hex.slice(0, 8), "-").concat(hex.slice(8, 12), "-").concat(hex.slice(12, 16), "-").concat(hex.slice(16, 20), "-").concat(hex.slice(20));
3734
+ };
3688
3735
  var createSqlAllowListBlockedError = function (args) {
3689
3736
  var _a, _b;
3690
3737
  var error = new Error("SQL statement is not permitted by allowlist (".concat(args.allowListPath, ")."));
@@ -3713,6 +3760,146 @@ var SqlExecutor = /** @class */ (function (_super) {
3713
3760
  })); };
3714
3761
  return _this;
3715
3762
  }
3763
+ SqlExecutor.prototype.getPostRequestRows = function () {
3764
+ var request = this.request;
3765
+ if (!request)
3766
+ return [];
3767
+ if (Array.isArray(request)) {
3768
+ return request;
3769
+ }
3770
+ if (Array.isArray(request.dataInsertMultipleRows)
3771
+ && request.dataInsertMultipleRows.length > 0) {
3772
+ return request.dataInsertMultipleRows;
3773
+ }
3774
+ var verb = C6Constants.REPLACE in request ? C6Constants.REPLACE : C6Constants.INSERT;
3775
+ if (verb in request && request[verb] && typeof request[verb] === "object") {
3776
+ return [request[verb]];
3777
+ }
3778
+ if (typeof request === "object") {
3779
+ return [request];
3780
+ }
3781
+ return [];
3782
+ };
3783
+ SqlExecutor.prototype.getTypeValidationForColumn = function (shortKey, fullKey) {
3784
+ var _a, _b;
3785
+ var validation = (_a = this.config.restModel) === null || _a === void 0 ? void 0 : _a.TYPE_VALIDATION;
3786
+ if (!validation || typeof validation !== "object")
3787
+ return undefined;
3788
+ return (_b = validation[shortKey]) !== null && _b !== void 0 ? _b : validation[fullKey];
3789
+ };
3790
+ SqlExecutor.prototype.isUuidLikePrimaryColumn = function (columnDef) {
3791
+ var _a, _b;
3792
+ if (!columnDef || typeof columnDef !== "object")
3793
+ return false;
3794
+ if (columnDef.AUTO_INCREMENT === true)
3795
+ return false;
3796
+ var mysqlType = String((_a = columnDef.MYSQL_TYPE) !== null && _a !== void 0 ? _a : "").toLowerCase();
3797
+ var maxLength = String((_b = columnDef.MAX_LENGTH) !== null && _b !== void 0 ? _b : "").trim();
3798
+ if (mysqlType.includes("uuid"))
3799
+ return true;
3800
+ var isBinary16 = mysqlType.includes("binary")
3801
+ && (maxLength === "16" || /\b16\b/.test(mysqlType) || mysqlType === "binary");
3802
+ var isUuidString = (mysqlType.includes("char") || mysqlType.includes("varchar"))
3803
+ && (maxLength === "32" || maxLength === "36");
3804
+ return isBinary16 || isUuidString;
3805
+ };
3806
+ SqlExecutor.prototype.hasDefinedValue = function (value) {
3807
+ if (value === undefined || value === null)
3808
+ return false;
3809
+ if (typeof value === "string" && value.trim() === "")
3810
+ return false;
3811
+ return true;
3812
+ };
3813
+ SqlExecutor.prototype.generatePrimaryUuidValue = function (columnDef) {
3814
+ var _a, _b;
3815
+ var mysqlType = String((_a = columnDef.MYSQL_TYPE) !== null && _a !== void 0 ? _a : "").toLowerCase();
3816
+ var maxLength = String((_b = columnDef.MAX_LENGTH) !== null && _b !== void 0 ? _b : "").trim();
3817
+ var uuid = generateUuidV7();
3818
+ // BINARY(16) and CHAR/VARCHAR(32) commonly persist UUIDs as 32-hex.
3819
+ if (mysqlType.includes("binary") || maxLength === "32") {
3820
+ return uuid.replace(/-/g, "").toUpperCase();
3821
+ }
3822
+ return uuid;
3823
+ };
3824
+ SqlExecutor.prototype.assignMissingPostPrimaryUuids = function () {
3825
+ var _this = this;
3826
+ var _a, _b;
3827
+ if (this.config.requestMethod !== C6Constants.POST)
3828
+ return;
3829
+ var rows = this.getPostRequestRows();
3830
+ if (rows.length === 0)
3831
+ return;
3832
+ var columns = this.config.restModel.COLUMNS;
3833
+ var tableName = this.config.restModel.TABLE_NAME;
3834
+ var primaryShorts = (_a = this.config.restModel.PRIMARY_SHORT) !== null && _a !== void 0 ? _a : [];
3835
+ var primaryColumns = primaryShorts
3836
+ .map(function (shortKey) {
3837
+ var _a;
3838
+ var fullKey = (_a = Object.keys(columns).find(function (key) { return columns[key] === shortKey; })) !== null && _a !== void 0 ? _a : "".concat(tableName, ".").concat(shortKey);
3839
+ var columnDef = _this.getTypeValidationForColumn(shortKey, fullKey);
3840
+ return { shortKey: shortKey, fullKey: fullKey, columnDef: columnDef };
3841
+ })
3842
+ .filter(function (_a) {
3843
+ var columnDef = _a.columnDef;
3844
+ return _this.isUuidLikePrimaryColumn(columnDef);
3845
+ });
3846
+ if (primaryColumns.length === 0)
3847
+ return;
3848
+ for (var _i = 0, rows_1 = rows; _i < rows_1.length; _i++) {
3849
+ var row = rows_1[_i];
3850
+ if (!row || typeof row !== "object")
3851
+ continue;
3852
+ var useQualifiedKeyByDefault = Object.keys(row).some(function (key) { return key.includes("."); });
3853
+ for (var _c = 0, primaryColumns_1 = primaryColumns; _c < primaryColumns_1.length; _c++) {
3854
+ var primaryColumn = primaryColumns_1[_c];
3855
+ var existing = (_b = row[primaryColumn.shortKey]) !== null && _b !== void 0 ? _b : row[primaryColumn.fullKey];
3856
+ if (this.hasDefinedValue(existing))
3857
+ continue;
3858
+ var generated = this.generatePrimaryUuidValue(primaryColumn.columnDef);
3859
+ if (Object.prototype.hasOwnProperty.call(row, primaryColumn.shortKey)) {
3860
+ row[primaryColumn.shortKey] = generated;
3861
+ continue;
3862
+ }
3863
+ if (Object.prototype.hasOwnProperty.call(row, primaryColumn.fullKey)) {
3864
+ row[primaryColumn.fullKey] = generated;
3865
+ continue;
3866
+ }
3867
+ row[useQualifiedKeyByDefault ? primaryColumn.fullKey : primaryColumn.shortKey] = generated;
3868
+ }
3869
+ }
3870
+ };
3871
+ SqlExecutor.prototype.buildPostResponseRows = function (insertId) {
3872
+ var _this = this;
3873
+ var _a;
3874
+ var rows = this.getPostRequestRows();
3875
+ if (rows.length === 0)
3876
+ return [];
3877
+ var columns = this.config.restModel.COLUMNS;
3878
+ var validColumns = new Set(Object.values(columns));
3879
+ var pkShorts = (_a = this.config.restModel.PRIMARY_SHORT) !== null && _a !== void 0 ? _a : [];
3880
+ var now = new Date().toISOString();
3881
+ return rows.map(function (row, index) {
3882
+ var normalized = _this.normalizeRequestPayload(row !== null && row !== void 0 ? row : {});
3883
+ if (validColumns.has("changed_at") && normalized.changed_at === undefined) {
3884
+ normalized.changed_at = now;
3885
+ }
3886
+ if (validColumns.has("created_at") && normalized.created_at === undefined) {
3887
+ normalized.created_at = now;
3888
+ }
3889
+ if (validColumns.has("updated_at") && normalized.updated_at === undefined) {
3890
+ normalized.updated_at = now;
3891
+ }
3892
+ // When DB generated PK is numeric/autoincrement, expose it for the single-row insert.
3893
+ if (index === 0
3894
+ && insertId !== undefined
3895
+ && insertId !== null
3896
+ && pkShorts.length === 1
3897
+ && !_this.hasDefinedValue(normalized[pkShorts[0]])) {
3898
+ normalized[pkShorts[0]] = insertId;
3899
+ }
3900
+ return normalized;
3901
+ });
3902
+ };
3716
3903
  SqlExecutor.prototype.resolveSqlLogMethod = function (method, sql) {
3717
3904
  var _a;
3718
3905
  var token = (_a = sql.trim().split(/\s+/, 1)[0]) === null || _a === void 0 ? void 0 : _a.toUpperCase();
@@ -3751,6 +3938,7 @@ var SqlExecutor = /** @class */ (function (_super) {
3751
3938
  // Surface normalization errors early
3752
3939
  throw e;
3753
3940
  }
3941
+ this.assignMissingPostPrimaryUuids();
3754
3942
  logContext = getLogContext(this.config, this.request);
3755
3943
  logWithLevel(LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] \u25B6\uFE0F Executing ".concat(method, " on table \"").concat(TABLE_NAME, "\""));
3756
3944
  logWithLevel(LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] \uD83E\uDDE9 Request:", this.request);
@@ -4100,7 +4288,7 @@ var SqlExecutor = /** @class */ (function (_super) {
4100
4288
  };
4101
4289
  SqlExecutor.prototype.runQuery = function () {
4102
4290
  return __awaiter(this, void 0, void 0, function () {
4103
- var method, tableName, logContext, cacheResults, cacheRequestData, requestArgumentsSerialized, evictFromCache, cachedRequest, cachedData, sqlExecution, sqlMethod, queryPromise, cacheRequest, cacheResponse;
4291
+ var method, tableName, logContext, cacheResults, cacheAllowListStatus, cacheRequestData, requestArgumentsSerialized, evictFromCache, cachedRequest, cachedData, sqlExecution, sqlMethod, queryPromise, cacheRequest, cacheResponse;
4104
4292
  var _this = this;
4105
4293
  var _a, _b;
4106
4294
  return __generator(this, function (_c) {
@@ -4111,6 +4299,9 @@ var SqlExecutor = /** @class */ (function (_super) {
4111
4299
  logContext = getLogContext(this.config, this.request);
4112
4300
  cacheResults = method === C6Constants.GET
4113
4301
  && ((_a = this.request.cacheResults) !== null && _a !== void 0 ? _a : true);
4302
+ cacheAllowListStatus = this.config.sqlAllowListPath
4303
+ ? "allowed"
4304
+ : "not verified";
4114
4305
  cacheRequestData = cacheResults
4115
4306
  ? JSON.parse(JSON.stringify((_b = this.request) !== null && _b !== void 0 ? _b : {}))
4116
4307
  : undefined;
@@ -4118,10 +4309,10 @@ var SqlExecutor = /** @class */ (function (_super) {
4118
4309
  ? sortAndSerializeQueryObject(tableName, cacheRequestData !== null && cacheRequestData !== void 0 ? cacheRequestData : {})
4119
4310
  : undefined;
4120
4311
  evictFromCache = method === C6Constants.GET && cacheResults && cacheRequestData
4121
- ? function () { return evictCacheEntry(method, tableName, cacheRequestData, logContext); }
4312
+ ? function () { return evictCacheEntry(method, tableName, cacheRequestData, logContext, cacheAllowListStatus); }
4122
4313
  : undefined;
4123
4314
  if (!cacheResults) return [3 /*break*/, 2];
4124
- cachedRequest = checkCache(method, tableName, cacheRequestData, logContext);
4315
+ cachedRequest = checkCache(method, tableName, cacheRequestData, logContext, cacheAllowListStatus);
4125
4316
  if (!cachedRequest) return [3 /*break*/, 2];
4126
4317
  return [4 /*yield*/, cachedRequest];
4127
4318
  case 1:
@@ -4157,6 +4348,7 @@ var SqlExecutor = /** @class */ (function (_super) {
4157
4348
  setCache(method, tableName, cacheRequestData, {
4158
4349
  requestArgumentsSerialized: requestArgumentsSerialized,
4159
4350
  request: cacheRequest,
4351
+ allowListStatus: cacheAllowListStatus,
4160
4352
  });
4161
4353
  return [4 /*yield*/, cacheRequest];
4162
4354
  case 5:
@@ -4164,6 +4356,7 @@ var SqlExecutor = /** @class */ (function (_super) {
4164
4356
  setCache(method, tableName, cacheRequestData, {
4165
4357
  requestArgumentsSerialized: requestArgumentsSerialized,
4166
4358
  request: cacheRequest,
4359
+ allowListStatus: cacheAllowListStatus,
4167
4360
  response: cacheResponse,
4168
4361
  final: true,
4169
4362
  });
@@ -4207,7 +4400,9 @@ var SqlExecutor = /** @class */ (function (_super) {
4207
4400
  return {
4208
4401
  affected: result.affectedRows,
4209
4402
  insertId: result.insertId,
4210
- rest: [],
4403
+ rest: method === C6Constants.POST
4404
+ ? this.buildPostResponseRows(result.insertId)
4405
+ : [],
4211
4406
  sql: { sql: sqlExecution.sql, values: sqlExecution.values },
4212
4407
  };
4213
4408
  };