@carbonorm/carbonnode 6.0.18 → 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.
- package/dist/executors/SqlExecutor.d.ts +7 -0
- package/dist/index.cjs.js +230 -20
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +230 -20
- package/dist/index.esm.js.map +1 -1
- package/dist/types/ormInterfaces.d.ts +1 -0
- package/dist/utils/cacheManager.d.ts +3 -2
- package/dist/utils/logSql.d.ts +1 -1
- package/package.json +1 -1
- package/src/__tests__/cacheManager.test.ts +55 -1
- package/src/__tests__/logSql.test.ts +16 -0
- package/src/__tests__/sakila-db/C6.js +1 -1
- package/src/__tests__/sakila-db/C6.mysqldump.json +1 -1
- package/src/__tests__/sakila-db/C6.mysqldump.sql +1 -1
- package/src/__tests__/sakila-db/C6.ts +1 -1
- package/src/__tests__/sakila-db/sqlResponses/C6.actor.post.json +11 -4
- package/src/__tests__/sakila-db/sqlResponses/C6.actor.post.latest.json +3 -3
- package/src/__tests__/sakila-db/sqlResponses/C6.actor.put.json +1 -1
- package/src/__tests__/sakila-db/sqlResponses/C6.actor.put.lookup.json +3 -3
- package/src/__tests__/sakila-db/sqlResponses/C6.address.post.json +18 -6
- package/src/__tests__/sakila-db/sqlResponses/C6.address.post.latest.json +5 -5
- package/src/__tests__/sakila-db/sqlResponses/C6.address.put.json +1 -1
- package/src/__tests__/sakila-db/sqlResponses/C6.address.put.lookup.json +5 -5
- package/src/__tests__/sakila-db/sqlResponses/C6.category.post.json +9 -3
- package/src/__tests__/sakila-db/sqlResponses/C6.category.post.latest.json +2 -2
- package/src/__tests__/sakila-db/sqlResponses/C6.category.put.json +1 -1
- package/src/__tests__/sakila-db/sqlResponses/C6.category.put.lookup.json +2 -2
- package/src/__tests__/sakila-db/sqlResponses/C6.city.post.json +10 -3
- package/src/__tests__/sakila-db/sqlResponses/C6.city.post.latest.json +2 -2
- package/src/__tests__/sakila-db/sqlResponses/C6.city.put.json +1 -1
- package/src/__tests__/sakila-db/sqlResponses/C6.city.put.lookup.json +2 -2
- package/src/__tests__/sakila-db/sqlResponses/C6.country.post.json +9 -3
- package/src/__tests__/sakila-db/sqlResponses/C6.country.post.latest.json +2 -2
- package/src/__tests__/sakila-db/sqlResponses/C6.country.put.json +1 -1
- package/src/__tests__/sakila-db/sqlResponses/C6.country.put.lookup.json +2 -2
- package/src/__tests__/sakila-db/sqlResponses/C6.customer.post.json +18 -6
- package/src/__tests__/sakila-db/sqlResponses/C6.customer.post.latest.json +5 -5
- package/src/__tests__/sakila-db/sqlResponses/C6.customer.put.json +1 -1
- package/src/__tests__/sakila-db/sqlResponses/C6.customer.put.lookup.json +5 -5
- package/src/__tests__/sakila-db/sqlResponses/C6.film.post.json +18 -3
- package/src/__tests__/sakila-db/sqlResponses/C6.film.post.latest.json +2 -2
- package/src/__tests__/sakila-db/sqlResponses/C6.film.put.json +1 -1
- package/src/__tests__/sakila-db/sqlResponses/C6.film.put.lookup.json +2 -2
- package/src/__tests__/sakila-db/sqlResponses/C6.inventory.post.json +9 -2
- package/src/__tests__/sakila-db/sqlResponses/C6.inventory.post.latest.json +1 -1
- package/src/__tests__/sakila-db/sqlResponses/C6.inventory.put.json +1 -1
- package/src/__tests__/sakila-db/sqlResponses/C6.inventory.put.lookup.json +1 -1
- package/src/__tests__/sakila-db/sqlResponses/C6.language.post.json +9 -3
- package/src/__tests__/sakila-db/sqlResponses/C6.language.post.latest.json +2 -2
- package/src/__tests__/sakila-db/sqlResponses/C6.language.put.json +1 -1
- package/src/__tests__/sakila-db/sqlResponses/C6.language.put.lookup.json +2 -2
- package/src/__tests__/sakila-db/sqlResponses/C6.payment.post.json +13 -3
- package/src/__tests__/sakila-db/sqlResponses/C6.payment.post.latest.json +2 -2
- package/src/__tests__/sakila-db/sqlResponses/C6.payment.put.lookup.json +2 -2
- package/src/__tests__/sakila-db/sqlResponses/C6.rental.post.json +14 -4
- package/src/__tests__/sakila-db/sqlResponses/C6.rental.post.latest.json +3 -3
- package/src/__tests__/sakila-db/sqlResponses/C6.rental.put.json +1 -1
- package/src/__tests__/sakila-db/sqlResponses/C6.rental.put.lookup.json +3 -3
- package/src/__tests__/sqlExecutorPostUuid.test.ts +185 -0
- package/src/executors/HttpExecutor.ts +33 -5
- package/src/executors/SqlExecutor.ts +207 -3
- package/src/types/ormInterfaces.ts +1 -0
- package/src/utils/cacheManager.ts +22 -5
- package/src/utils/logSql.ts +3 -1
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.
|
|
954
|
+
var version = "6.0.20";
|
|
955
955
|
|
|
956
956
|
var DEFAULT_STEP = 8;
|
|
957
957
|
function parseSemver(version) {
|
|
@@ -1037,6 +1037,8 @@ var cacheLabel = function (cacheStatus) {
|
|
|
1037
1037
|
switch (cacheStatus) {
|
|
1038
1038
|
case "hit":
|
|
1039
1039
|
return "".concat(C.METHOD_COLORS.SELECT, "[CACHE HIT]").concat(C.RESET);
|
|
1040
|
+
case "evicted":
|
|
1041
|
+
return "".concat(C.WARN, "[CACHE EVICTED]").concat(C.RESET);
|
|
1040
1042
|
case "ignored":
|
|
1041
1043
|
return "".concat(C.WARN, "[CACHE IGNORED]").concat(C.RESET);
|
|
1042
1044
|
default:
|
|
@@ -1109,19 +1111,18 @@ function clearCache(props) {
|
|
|
1109
1111
|
// -----------------------------------------------------------------------------
|
|
1110
1112
|
// Check Cache (dedupe via hashed key)
|
|
1111
1113
|
// -----------------------------------------------------------------------------
|
|
1112
|
-
function checkCache(method, tableName, requestData, logContext) {
|
|
1113
|
-
var _a, _b, _c, _d, _e;
|
|
1114
|
+
function checkCache(method, tableName, requestData, logContext, allowListStatus) {
|
|
1115
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1114
1116
|
var key = makeCacheKey(method, tableName, requestData);
|
|
1115
1117
|
var cached = apiRequestCache.get(key);
|
|
1116
1118
|
if (!cached) {
|
|
1117
|
-
console.log('apiRequestCache.size', apiRequestCache.size);
|
|
1118
1119
|
return false;
|
|
1119
1120
|
}
|
|
1120
1121
|
if (shouldLog(LogLevel.INFO, logContext)) {
|
|
1121
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 : "";
|
|
1122
1123
|
var sqlMethod = ((_e = sql.trim().split(/\s+/, 1)[0]) === null || _e === void 0 ? void 0 : _e.toUpperCase()) || method;
|
|
1123
1124
|
logSql({
|
|
1124
|
-
allowListStatus: "not verified",
|
|
1125
|
+
allowListStatus: (_g = (_f = cached.allowListStatus) !== null && _f !== void 0 ? _f : allowListStatus) !== null && _g !== void 0 ? _g : "not verified",
|
|
1125
1126
|
cacheStatus: "hit",
|
|
1126
1127
|
context: logContext,
|
|
1127
1128
|
method: sqlMethod,
|
|
@@ -1137,9 +1138,23 @@ function setCache(method, tableName, requestData, cacheEntry) {
|
|
|
1137
1138
|
var key = makeCacheKey(method, tableName, requestData);
|
|
1138
1139
|
apiRequestCache.set(key, cacheEntry);
|
|
1139
1140
|
}
|
|
1140
|
-
function evictCacheEntry(method, tableName, requestData) {
|
|
1141
|
+
function evictCacheEntry(method, tableName, requestData, logContext, allowListStatus) {
|
|
1142
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1141
1143
|
var key = makeCacheKey(method, tableName, requestData);
|
|
1142
|
-
|
|
1144
|
+
var cached = apiRequestCache.get(key);
|
|
1145
|
+
var deleted = apiRequestCache.delete(key);
|
|
1146
|
+
if (deleted && shouldLog(LogLevel.INFO, logContext)) {
|
|
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
|
+
var sqlMethod = ((_e = sql.trim().split(/\s+/, 1)[0]) === null || _e === void 0 ? void 0 : _e.toUpperCase()) || method;
|
|
1149
|
+
logSql({
|
|
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
|
+
cacheStatus: "evicted",
|
|
1152
|
+
context: logContext,
|
|
1153
|
+
method: sqlMethod,
|
|
1154
|
+
sql: sql,
|
|
1155
|
+
});
|
|
1156
|
+
}
|
|
1157
|
+
return deleted;
|
|
1143
1158
|
}
|
|
1144
1159
|
|
|
1145
1160
|
function sortAndSerializeQueryObject(tables, query) {
|
|
@@ -1187,27 +1202,34 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1187
1202
|
};
|
|
1188
1203
|
HttpExecutor.prototype.postState = function (response, request, callback) {
|
|
1189
1204
|
var _this = this;
|
|
1190
|
-
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] : []);
|
|
1191
1210
|
if (this.config.restModel.PRIMARY_SHORT.length === 1) {
|
|
1192
1211
|
var pk = this.config.restModel.PRIMARY_SHORT[0];
|
|
1193
1212
|
try {
|
|
1194
|
-
|
|
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
|
+
}
|
|
1195
1217
|
}
|
|
1196
|
-
catch ( /* best-effort */
|
|
1218
|
+
catch ( /* best-effort */_g) { /* best-effort */ }
|
|
1197
1219
|
}
|
|
1198
1220
|
else if (isLocal()) {
|
|
1199
1221
|
logWithLevel(LogLevel.ERROR, getLogContext(this.config, this.request), console.error, "C6 received unexpected results given the primary key length");
|
|
1200
1222
|
}
|
|
1201
|
-
(
|
|
1223
|
+
(_e = this.config.reactBootstrap) === null || _e === void 0 ? void 0 : _e.updateRestfulObjectArrays({
|
|
1202
1224
|
callback: callback,
|
|
1203
1225
|
dataOrCallback: undefined !== request.dataInsertMultipleRows
|
|
1204
1226
|
? request.dataInsertMultipleRows.map(function (row, index) {
|
|
1205
1227
|
var _a;
|
|
1206
1228
|
var normalizedRow = _this.stripTableNameFromKeys(row);
|
|
1207
|
-
return removeInvalidKeys(__assign(__assign({}, normalizedRow), (
|
|
1229
|
+
return removeInvalidKeys(__assign(__assign({}, normalizedRow), ((_a = responseRows[index]) !== null && _a !== void 0 ? _a : {})), _this.config.C6.TABLES);
|
|
1208
1230
|
})
|
|
1209
1231
|
: [
|
|
1210
|
-
removeInvalidKeys(__assign(__assign({}, this.stripTableNameFromKeys(request)), (
|
|
1232
|
+
removeInvalidKeys(__assign(__assign({}, this.stripTableNameFromKeys(request)), ((_f = responseRows[0]) !== null && _f !== void 0 ? _f : {})), this.config.C6.TABLES)
|
|
1211
1233
|
],
|
|
1212
1234
|
stateKey: this.config.restModel.TABLE_NAME,
|
|
1213
1235
|
uniqueObjectId: this.config.restModel.PRIMARY_SHORT
|
|
@@ -1266,7 +1288,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1266
1288
|
}
|
|
1267
1289
|
query = this.request;
|
|
1268
1290
|
apiRequest = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1269
|
-
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;
|
|
1270
1292
|
var _e;
|
|
1271
1293
|
var _this = this;
|
|
1272
1294
|
var _f, _g, _h, _j, _k, _l;
|
|
@@ -1296,13 +1318,16 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1296
1318
|
query[C6.PAGINATION][C6.LIMIT] = query[C6.PAGINATION][C6.LIMIT] || 100;
|
|
1297
1319
|
}
|
|
1298
1320
|
cacheRequestData = JSON.parse(JSON.stringify(query !== null && query !== void 0 ? query : {}));
|
|
1321
|
+
cacheAllowListStatus = this.config.sqlAllowListPath
|
|
1322
|
+
? "allowed"
|
|
1323
|
+
: "not verified";
|
|
1299
1324
|
evictFromCache = requestMethod === GET && cacheResults
|
|
1300
|
-
? function () { return evictCacheEntry(requestMethod, tableName, cacheRequestData); }
|
|
1325
|
+
? function () { return evictCacheEntry(requestMethod, tableName, cacheRequestData, logContext, cacheAllowListStatus); }
|
|
1301
1326
|
: undefined;
|
|
1302
1327
|
querySerialized = sortAndSerializeQueryObject(tables, cacheRequestData !== null && cacheRequestData !== void 0 ? cacheRequestData : {});
|
|
1303
1328
|
cachedRequest = false;
|
|
1304
1329
|
if (cacheResults) {
|
|
1305
|
-
cachedRequest = checkCache(requestMethod, tableName, cacheRequestData, logContext);
|
|
1330
|
+
cachedRequest = checkCache(requestMethod, tableName, cacheRequestData, logContext, cacheAllowListStatus);
|
|
1306
1331
|
}
|
|
1307
1332
|
if (!cachedRequest) return [3 /*break*/, 2];
|
|
1308
1333
|
return [4 /*yield*/, cachedRequest];
|
|
@@ -1426,6 +1451,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1426
1451
|
setCache(requestMethod, tableName, cacheRequestData, {
|
|
1427
1452
|
requestArgumentsSerialized: querySerialized,
|
|
1428
1453
|
request: axiosActiveRequest_1,
|
|
1454
|
+
allowListStatus: cacheAllowListStatus,
|
|
1429
1455
|
});
|
|
1430
1456
|
}
|
|
1431
1457
|
// returning the promise with this then is important for tests. todo - we could make that optional.
|
|
@@ -1443,6 +1469,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1443
1469
|
setCache(requestMethod, tableName, cacheRequestData, {
|
|
1444
1470
|
requestArgumentsSerialized: querySerialized,
|
|
1445
1471
|
request: axiosActiveRequest_1,
|
|
1472
|
+
allowListStatus: cacheAllowListStatus,
|
|
1446
1473
|
response: response,
|
|
1447
1474
|
final: true,
|
|
1448
1475
|
});
|
|
@@ -1459,6 +1486,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1459
1486
|
setCache(requestMethod, tableName, cacheRequestData, {
|
|
1460
1487
|
requestArgumentsSerialized: querySerialized,
|
|
1461
1488
|
request: axiosActiveRequest_1,
|
|
1489
|
+
allowListStatus: cacheAllowListStatus,
|
|
1462
1490
|
response: response,
|
|
1463
1491
|
});
|
|
1464
1492
|
}
|
|
@@ -1523,6 +1551,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1523
1551
|
setCache(requestMethod, tableName, cacheRequestData, {
|
|
1524
1552
|
requestArgumentsSerialized: querySerialized,
|
|
1525
1553
|
request: axiosActiveRequest_1,
|
|
1554
|
+
allowListStatus: cacheAllowListStatus,
|
|
1526
1555
|
response: response,
|
|
1527
1556
|
final: !hasNext,
|
|
1528
1557
|
});
|
|
@@ -1722,6 +1751,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1722
1751
|
setCache(requestMethod, tableName, cacheRequestData, {
|
|
1723
1752
|
requestArgumentsSerialized: querySerialized,
|
|
1724
1753
|
request: axiosActiveRequest_1,
|
|
1754
|
+
allowListStatus: cacheAllowListStatus,
|
|
1725
1755
|
response: response,
|
|
1726
1756
|
final: true,
|
|
1727
1757
|
});
|
|
@@ -3670,6 +3700,38 @@ var compileSqlAllowList = function (allowListPath, entries) { return __awaiter(v
|
|
|
3670
3700
|
}); };
|
|
3671
3701
|
|
|
3672
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
|
+
};
|
|
3673
3735
|
var createSqlAllowListBlockedError = function (args) {
|
|
3674
3736
|
var _a, _b;
|
|
3675
3737
|
var error = new Error("SQL statement is not permitted by allowlist (".concat(args.allowListPath, ")."));
|
|
@@ -3698,6 +3760,146 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3698
3760
|
})); };
|
|
3699
3761
|
return _this;
|
|
3700
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
|
+
};
|
|
3701
3903
|
SqlExecutor.prototype.resolveSqlLogMethod = function (method, sql) {
|
|
3702
3904
|
var _a;
|
|
3703
3905
|
var token = (_a = sql.trim().split(/\s+/, 1)[0]) === null || _a === void 0 ? void 0 : _a.toUpperCase();
|
|
@@ -3736,6 +3938,7 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3736
3938
|
// Surface normalization errors early
|
|
3737
3939
|
throw e;
|
|
3738
3940
|
}
|
|
3941
|
+
this.assignMissingPostPrimaryUuids();
|
|
3739
3942
|
logContext = getLogContext(this.config, this.request);
|
|
3740
3943
|
logWithLevel(LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] \u25B6\uFE0F Executing ".concat(method, " on table \"").concat(TABLE_NAME, "\""));
|
|
3741
3944
|
logWithLevel(LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] \uD83E\uDDE9 Request:", this.request);
|
|
@@ -4085,7 +4288,7 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
4085
4288
|
};
|
|
4086
4289
|
SqlExecutor.prototype.runQuery = function () {
|
|
4087
4290
|
return __awaiter(this, void 0, void 0, function () {
|
|
4088
|
-
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;
|
|
4089
4292
|
var _this = this;
|
|
4090
4293
|
var _a, _b;
|
|
4091
4294
|
return __generator(this, function (_c) {
|
|
@@ -4096,6 +4299,9 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
4096
4299
|
logContext = getLogContext(this.config, this.request);
|
|
4097
4300
|
cacheResults = method === C6Constants.GET
|
|
4098
4301
|
&& ((_a = this.request.cacheResults) !== null && _a !== void 0 ? _a : true);
|
|
4302
|
+
cacheAllowListStatus = this.config.sqlAllowListPath
|
|
4303
|
+
? "allowed"
|
|
4304
|
+
: "not verified";
|
|
4099
4305
|
cacheRequestData = cacheResults
|
|
4100
4306
|
? JSON.parse(JSON.stringify((_b = this.request) !== null && _b !== void 0 ? _b : {}))
|
|
4101
4307
|
: undefined;
|
|
@@ -4103,10 +4309,10 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
4103
4309
|
? sortAndSerializeQueryObject(tableName, cacheRequestData !== null && cacheRequestData !== void 0 ? cacheRequestData : {})
|
|
4104
4310
|
: undefined;
|
|
4105
4311
|
evictFromCache = method === C6Constants.GET && cacheResults && cacheRequestData
|
|
4106
|
-
? function () { return evictCacheEntry(method, tableName, cacheRequestData); }
|
|
4312
|
+
? function () { return evictCacheEntry(method, tableName, cacheRequestData, logContext, cacheAllowListStatus); }
|
|
4107
4313
|
: undefined;
|
|
4108
4314
|
if (!cacheResults) return [3 /*break*/, 2];
|
|
4109
|
-
cachedRequest = checkCache(method, tableName, cacheRequestData, logContext);
|
|
4315
|
+
cachedRequest = checkCache(method, tableName, cacheRequestData, logContext, cacheAllowListStatus);
|
|
4110
4316
|
if (!cachedRequest) return [3 /*break*/, 2];
|
|
4111
4317
|
return [4 /*yield*/, cachedRequest];
|
|
4112
4318
|
case 1:
|
|
@@ -4142,6 +4348,7 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
4142
4348
|
setCache(method, tableName, cacheRequestData, {
|
|
4143
4349
|
requestArgumentsSerialized: requestArgumentsSerialized,
|
|
4144
4350
|
request: cacheRequest,
|
|
4351
|
+
allowListStatus: cacheAllowListStatus,
|
|
4145
4352
|
});
|
|
4146
4353
|
return [4 /*yield*/, cacheRequest];
|
|
4147
4354
|
case 5:
|
|
@@ -4149,6 +4356,7 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
4149
4356
|
setCache(method, tableName, cacheRequestData, {
|
|
4150
4357
|
requestArgumentsSerialized: requestArgumentsSerialized,
|
|
4151
4358
|
request: cacheRequest,
|
|
4359
|
+
allowListStatus: cacheAllowListStatus,
|
|
4152
4360
|
response: cacheResponse,
|
|
4153
4361
|
final: true,
|
|
4154
4362
|
});
|
|
@@ -4192,7 +4400,9 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
4192
4400
|
return {
|
|
4193
4401
|
affected: result.affectedRows,
|
|
4194
4402
|
insertId: result.insertId,
|
|
4195
|
-
rest:
|
|
4403
|
+
rest: method === C6Constants.POST
|
|
4404
|
+
? this.buildPostResponseRows(result.insertId)
|
|
4405
|
+
: [],
|
|
4196
4406
|
sql: { sql: sqlExecution.sql, values: sqlExecution.values },
|
|
4197
4407
|
};
|
|
4198
4408
|
};
|