@carbonorm/carbonnode 6.0.17 → 6.0.18
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.cjs.js +42 -6
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +42 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/types/ormInterfaces.d.ts +1 -0
- package/dist/utils/cacheManager.d.ts +1 -0
- package/package.json +2 -2
- package/src/__tests__/httpExecutor.cacheEviction.test.ts +70 -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 +3 -3
- 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 +5 -5
- 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 +2 -2
- 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 +2 -2
- 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 +2 -2
- 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 +5 -5
- 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 +2 -2
- 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 +1 -1
- 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 +2 -2
- 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 +2 -2
- 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.join.json +10 -10
- package/src/__tests__/sakila-db/sqlResponses/C6.rental.post.json +3 -3
- 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__/sqlExecutor.cacheEviction.test.ts +79 -0
- package/src/executors/HttpExecutor.ts +19 -3
- package/src/executors/SqlExecutor.ts +23 -5
- package/src/types/ormInterfaces.ts +4 -1
- package/src/utils/cacheManager.ts +9 -0
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.18";
|
|
955
955
|
|
|
956
956
|
var DEFAULT_STEP = 8;
|
|
957
957
|
function parseSemver(version) {
|
|
@@ -1137,6 +1137,10 @@ function setCache(method, tableName, requestData, cacheEntry) {
|
|
|
1137
1137
|
var key = makeCacheKey(method, tableName, requestData);
|
|
1138
1138
|
apiRequestCache.set(key, cacheEntry);
|
|
1139
1139
|
}
|
|
1140
|
+
function evictCacheEntry(method, tableName, requestData) {
|
|
1141
|
+
var key = makeCacheKey(method, tableName, requestData);
|
|
1142
|
+
return apiRequestCache.delete(key);
|
|
1143
|
+
}
|
|
1140
1144
|
|
|
1141
1145
|
function sortAndSerializeQueryObject(tables, query) {
|
|
1142
1146
|
var orderedQuery = Object.keys(query).sort().reduce(function (obj, key) {
|
|
@@ -1262,7 +1266,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1262
1266
|
}
|
|
1263
1267
|
query = this.request;
|
|
1264
1268
|
apiRequest = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1265
|
-
var _a, debug, _b, cacheResults, dataInsertMultipleRows, success, _c, fetchDependencies, _d, error, cachingConfirmed, cacheRequestData, querySerialized, cachedRequest, apiResponse, restRequestUri, needsConditionOrPrimaryCheck, TABLES, primaryKeyList, primaryKeyFullyQualified, primaryKey, whereVal, whereIsEmpty, providedPrimary, primaryVal, axiosActiveRequest_1;
|
|
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;
|
|
1266
1270
|
var _e;
|
|
1267
1271
|
var _this = this;
|
|
1268
1272
|
var _f, _g, _h, _j, _k, _l;
|
|
@@ -1292,6 +1296,9 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1292
1296
|
query[C6.PAGINATION][C6.LIMIT] = query[C6.PAGINATION][C6.LIMIT] || 100;
|
|
1293
1297
|
}
|
|
1294
1298
|
cacheRequestData = JSON.parse(JSON.stringify(query !== null && query !== void 0 ? query : {}));
|
|
1299
|
+
evictFromCache = requestMethod === GET && cacheResults
|
|
1300
|
+
? function () { return evictCacheEntry(requestMethod, tableName, cacheRequestData); }
|
|
1301
|
+
: undefined;
|
|
1295
1302
|
querySerialized = sortAndSerializeQueryObject(tables, cacheRequestData !== null && cacheRequestData !== void 0 ? cacheRequestData : {});
|
|
1296
1303
|
cachedRequest = false;
|
|
1297
1304
|
if (cacheResults) {
|
|
@@ -1299,7 +1306,15 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1299
1306
|
}
|
|
1300
1307
|
if (!cachedRequest) return [3 /*break*/, 2];
|
|
1301
1308
|
return [4 /*yield*/, cachedRequest];
|
|
1302
|
-
case 1:
|
|
1309
|
+
case 1:
|
|
1310
|
+
cachedData = (_m.sent()).data;
|
|
1311
|
+
if (evictFromCache
|
|
1312
|
+
&& cachedData
|
|
1313
|
+
&& typeof cachedData === "object"
|
|
1314
|
+
&& Array.isArray(cachedData.rest)) {
|
|
1315
|
+
cachedData.evictFromCache = evictFromCache;
|
|
1316
|
+
}
|
|
1317
|
+
return [2 /*return*/, cachedData];
|
|
1303
1318
|
case 2:
|
|
1304
1319
|
if (cacheResults) {
|
|
1305
1320
|
cachingConfirmed = true;
|
|
@@ -1490,7 +1505,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1490
1505
|
else {
|
|
1491
1506
|
callback();
|
|
1492
1507
|
}
|
|
1493
|
-
if (!(
|
|
1508
|
+
if (!(requestMethod === GET && this.isRestResponse(response))) return [3 /*break*/, 2];
|
|
1494
1509
|
responseData_1 = response.data;
|
|
1495
1510
|
pageLimit = (_a = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _a === void 0 ? void 0 : _a[C6.LIMIT];
|
|
1496
1511
|
got = responseData_1.rest.length;
|
|
@@ -1501,6 +1516,9 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1501
1516
|
else {
|
|
1502
1517
|
responseData_1.next = undefined; // short page => done
|
|
1503
1518
|
}
|
|
1519
|
+
if (cachingConfirmed && evictFromCache) {
|
|
1520
|
+
responseData_1.evictFromCache = evictFromCache;
|
|
1521
|
+
}
|
|
1504
1522
|
if (cachingConfirmed) {
|
|
1505
1523
|
setCache(requestMethod, tableName, cacheRequestData, {
|
|
1506
1524
|
requestArgumentsSerialized: querySerialized,
|
|
@@ -4067,7 +4085,7 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
4067
4085
|
};
|
|
4068
4086
|
SqlExecutor.prototype.runQuery = function () {
|
|
4069
4087
|
return __awaiter(this, void 0, void 0, function () {
|
|
4070
|
-
var method, tableName, logContext, cacheResults, cacheRequestData, requestArgumentsSerialized, cachedRequest, sqlExecution, sqlMethod, queryPromise, cacheRequest, cacheResponse;
|
|
4088
|
+
var method, tableName, logContext, cacheResults, cacheRequestData, requestArgumentsSerialized, evictFromCache, cachedRequest, cachedData, sqlExecution, sqlMethod, queryPromise, cacheRequest, cacheResponse;
|
|
4071
4089
|
var _this = this;
|
|
4072
4090
|
var _a, _b;
|
|
4073
4091
|
return __generator(this, function (_c) {
|
|
@@ -4084,11 +4102,22 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
4084
4102
|
requestArgumentsSerialized = cacheResults
|
|
4085
4103
|
? sortAndSerializeQueryObject(tableName, cacheRequestData !== null && cacheRequestData !== void 0 ? cacheRequestData : {})
|
|
4086
4104
|
: undefined;
|
|
4105
|
+
evictFromCache = method === C6Constants.GET && cacheResults && cacheRequestData
|
|
4106
|
+
? function () { return evictCacheEntry(method, tableName, cacheRequestData); }
|
|
4107
|
+
: undefined;
|
|
4087
4108
|
if (!cacheResults) return [3 /*break*/, 2];
|
|
4088
4109
|
cachedRequest = checkCache(method, tableName, cacheRequestData, logContext);
|
|
4089
4110
|
if (!cachedRequest) return [3 /*break*/, 2];
|
|
4090
4111
|
return [4 /*yield*/, cachedRequest];
|
|
4091
|
-
case 1:
|
|
4112
|
+
case 1:
|
|
4113
|
+
cachedData = (_c.sent()).data;
|
|
4114
|
+
if (evictFromCache
|
|
4115
|
+
&& cachedData
|
|
4116
|
+
&& typeof cachedData === "object"
|
|
4117
|
+
&& Array.isArray(cachedData.rest)) {
|
|
4118
|
+
cachedData.evictFromCache = evictFromCache;
|
|
4119
|
+
}
|
|
4120
|
+
return [2 /*return*/, cachedData];
|
|
4092
4121
|
case 2:
|
|
4093
4122
|
sqlExecution = this.buildSqlExecutionContext(method, tableName, logContext);
|
|
4094
4123
|
sqlMethod = this.resolveSqlLogMethod(method, sqlExecution.sql);
|
|
@@ -4102,6 +4131,12 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
4102
4131
|
case 3: return [2 /*return*/, _c.sent()];
|
|
4103
4132
|
case 4:
|
|
4104
4133
|
cacheRequest = queryPromise.then(function (data) {
|
|
4134
|
+
if (evictFromCache
|
|
4135
|
+
&& data
|
|
4136
|
+
&& typeof data === "object"
|
|
4137
|
+
&& Array.isArray(data.rest)) {
|
|
4138
|
+
data.evictFromCache = evictFromCache;
|
|
4139
|
+
}
|
|
4105
4140
|
return _this.createCacheResponseEnvelope(method, tableName, data);
|
|
4106
4141
|
});
|
|
4107
4142
|
setCache(method, tableName, cacheRequestData, {
|
|
@@ -4535,5 +4570,5 @@ function isVerbose() {
|
|
|
4535
4570
|
return resolveLogLevel() >= LogLevel.DEBUG;
|
|
4536
4571
|
}
|
|
4537
4572
|
|
|
4538
|
-
export { A, AggregateBuilder, C6C, C6Constants, ConditionBuilder, DELETE, DeleteQueryBuilder, Executor, ExpressHandler, F, GET, HttpExecutor, JoinBuilder, LogLevel, POST, PUT, PaginationBuilder, PostQueryBuilder, SelectQueryBuilder, SqlExecutor, TestRestfulResponse, UpdateQueryBuilder, apiRequestCache, applyLogLevelDefaults, axiosInstance, bbox, carbonNodeQsStringify, checkAllRequestsComplete, checkCache, clearCache, collectSqlAllowListEntries, colorSql, compileSqlAllowList, convertForRequestBody, convertHexIfBinary, derivedTable, determineRuntimeJsType, distSphere, eFetchDependencies, error, extractSqlEntries, fieldEq, getEnv, getEnvBool, getEnvDebug, getEnvLogLevel, getLogContext, getPrimaryKeyTypes, group, info, isDerivedTableKey, isLocal, isNode, isTest, isVerbose, loadSqlAllowList, logSql, logWithLevel, normalizeSingularRequest, normalizeSql, notifyToast, onError, onSuccess, parseLogLevel, removeInvalidKeys, removePrefixIfExists, resolveDerivedTable, resolveLogLevel, restExpressRequest, restOrm, restRequest, setCache, setToastHandler, shouldLog, sortAndSerializeQueryObject, stContains, timeout, toastOptions, toastOptionsDevs, userCustomClearCache, versionToRgb as versionColor, warn };
|
|
4573
|
+
export { A, AggregateBuilder, C6C, C6Constants, ConditionBuilder, DELETE, DeleteQueryBuilder, Executor, ExpressHandler, F, GET, HttpExecutor, JoinBuilder, LogLevel, POST, PUT, PaginationBuilder, PostQueryBuilder, SelectQueryBuilder, SqlExecutor, TestRestfulResponse, UpdateQueryBuilder, apiRequestCache, applyLogLevelDefaults, axiosInstance, bbox, carbonNodeQsStringify, checkAllRequestsComplete, checkCache, clearCache, collectSqlAllowListEntries, colorSql, compileSqlAllowList, convertForRequestBody, convertHexIfBinary, derivedTable, determineRuntimeJsType, distSphere, eFetchDependencies, error, evictCacheEntry, extractSqlEntries, fieldEq, getEnv, getEnvBool, getEnvDebug, getEnvLogLevel, getLogContext, getPrimaryKeyTypes, group, info, isDerivedTableKey, isLocal, isNode, isTest, isVerbose, loadSqlAllowList, logSql, logWithLevel, normalizeSingularRequest, normalizeSql, notifyToast, onError, onSuccess, parseLogLevel, removeInvalidKeys, removePrefixIfExists, resolveDerivedTable, resolveLogLevel, restExpressRequest, restOrm, restRequest, setCache, setToastHandler, shouldLog, sortAndSerializeQueryObject, stContains, timeout, toastOptions, toastOptionsDevs, userCustomClearCache, versionToRgb as versionColor, warn };
|
|
4539
4574
|
//# sourceMappingURL=index.esm.js.map
|