@carbonorm/carbonnode 6.0.19 → 6.1.0
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/README.md +46 -1
- package/dist/constants/C6Constants.d.ts +342 -338
- package/dist/executors/SqlExecutor.d.ts +8 -0
- package/dist/index.cjs.js +751 -272
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +744 -273
- package/dist/index.esm.js.map +1 -1
- package/dist/orm/builders/AggregateBuilder.d.ts +5 -1
- package/dist/orm/builders/ConditionBuilder.d.ts +2 -3
- package/dist/orm/builders/ExpressionSerializer.d.ts +22 -0
- package/dist/orm/builders/PaginationBuilder.d.ts +4 -6
- package/dist/orm/queryHelpers.d.ts +12 -1
- package/dist/types/mysqlTypes.d.ts +6 -1
- package/dist/types/ormInterfaces.d.ts +7 -5
- package/dist/utils/cacheManager.d.ts +3 -2
- package/package.json +2 -2
- package/scripts/assets/handlebars/C6.test.ts.handlebars +4 -4
- package/src/__tests__/cacheManager.test.ts +28 -0
- package/src/__tests__/expressServer.e2e.test.ts +26 -17
- package/src/__tests__/httpExecutorSingular.e2e.test.ts +53 -14
- package/src/__tests__/normalizeSingularRequest.test.ts +26 -8
- 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.sqlAllowList.json +1 -1
- package/src/__tests__/sakila-db/C6.test.ts +4 -4
- 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 +26 -7
- 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.join.json +10 -10
- 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__/sqlBuilders.complex.test.ts +62 -74
- package/src/__tests__/sqlBuilders.expressions.test.ts +58 -30
- package/src/__tests__/sqlBuilders.test.ts +68 -4
- package/src/__tests__/sqlExecutorPostUuid.test.ts +185 -0
- package/src/constants/C6Constants.ts +3 -1
- package/src/executors/HttpExecutor.ts +35 -6
- package/src/executors/SqlExecutor.ts +232 -4
- package/src/index.ts +1 -0
- package/src/orm/builders/AggregateBuilder.ts +67 -106
- package/src/orm/builders/ConditionBuilder.ts +69 -93
- package/src/orm/builders/ExpressionSerializer.ts +275 -0
- package/src/orm/builders/PaginationBuilder.ts +24 -34
- package/src/orm/queryHelpers.ts +29 -0
- package/src/types/mysqlTypes.ts +130 -9
- package/src/types/ormInterfaces.ts +7 -7
- package/src/utils/cacheManager.ts +6 -4
- package/src/utils/normalizeSingularRequest.ts +11 -4
package/dist/index.cjs.js
CHANGED
|
@@ -163,6 +163,7 @@ var C6Constants = {
|
|
|
163
163
|
AND: 'AND',
|
|
164
164
|
BETWEEN: 'BETWEEN',
|
|
165
165
|
CONCAT: 'CONCAT',
|
|
166
|
+
CALL: 'CALL',
|
|
166
167
|
CONVERT_TZ: 'CONVERT_TZ',
|
|
167
168
|
COUNT: 'COUNT',
|
|
168
169
|
COUNT_ALL: 'COUNT_ALL',
|
|
@@ -217,6 +218,7 @@ var C6Constants = {
|
|
|
217
218
|
LESS_THAN: '<',
|
|
218
219
|
LESS_THAN_OR_EQUAL_TO: '<=',
|
|
219
220
|
LIKE: 'LIKE',
|
|
221
|
+
LIT: 'LIT',
|
|
220
222
|
LIMIT: 'LIMIT',
|
|
221
223
|
LOCALTIME: 'LOCALTIME',
|
|
222
224
|
LOCALTIMESTAMP: 'LOCALTIMESTAMP',
|
|
@@ -954,7 +956,7 @@ function colorSql(sql) {
|
|
|
954
956
|
return s;
|
|
955
957
|
}
|
|
956
958
|
|
|
957
|
-
var version = "6.0
|
|
959
|
+
var version = "6.1.0";
|
|
958
960
|
|
|
959
961
|
var DEFAULT_STEP = 8;
|
|
960
962
|
function parseSemver(version) {
|
|
@@ -1114,8 +1116,8 @@ function clearCache(props) {
|
|
|
1114
1116
|
// -----------------------------------------------------------------------------
|
|
1115
1117
|
// Check Cache (dedupe via hashed key)
|
|
1116
1118
|
// -----------------------------------------------------------------------------
|
|
1117
|
-
function checkCache(method, tableName, requestData, logContext) {
|
|
1118
|
-
var _a, _b, _c, _d, _e;
|
|
1119
|
+
function checkCache(method, tableName, requestData, logContext, allowListStatus) {
|
|
1120
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1119
1121
|
var key = makeCacheKey(method, tableName, requestData);
|
|
1120
1122
|
var cached = apiRequestCache.get(key);
|
|
1121
1123
|
if (!cached) {
|
|
@@ -1125,7 +1127,7 @@ function checkCache(method, tableName, requestData, logContext) {
|
|
|
1125
1127
|
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 : "";
|
|
1126
1128
|
var sqlMethod = ((_e = sql.trim().split(/\s+/, 1)[0]) === null || _e === void 0 ? void 0 : _e.toUpperCase()) || method;
|
|
1127
1129
|
logSql({
|
|
1128
|
-
allowListStatus: "not verified",
|
|
1130
|
+
allowListStatus: (_g = (_f = cached.allowListStatus) !== null && _f !== void 0 ? _f : allowListStatus) !== null && _g !== void 0 ? _g : "not verified",
|
|
1129
1131
|
cacheStatus: "hit",
|
|
1130
1132
|
context: logContext,
|
|
1131
1133
|
method: sqlMethod,
|
|
@@ -1141,8 +1143,8 @@ function setCache(method, tableName, requestData, cacheEntry) {
|
|
|
1141
1143
|
var key = makeCacheKey(method, tableName, requestData);
|
|
1142
1144
|
apiRequestCache.set(key, cacheEntry);
|
|
1143
1145
|
}
|
|
1144
|
-
function evictCacheEntry(method, tableName, requestData, logContext) {
|
|
1145
|
-
var _a, _b, _c, _d, _e;
|
|
1146
|
+
function evictCacheEntry(method, tableName, requestData, logContext, allowListStatus) {
|
|
1147
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
1146
1148
|
var key = makeCacheKey(method, tableName, requestData);
|
|
1147
1149
|
var cached = apiRequestCache.get(key);
|
|
1148
1150
|
var deleted = apiRequestCache.delete(key);
|
|
@@ -1150,7 +1152,7 @@ function evictCacheEntry(method, tableName, requestData, logContext) {
|
|
|
1150
1152
|
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 : "";
|
|
1151
1153
|
var sqlMethod = ((_e = sql.trim().split(/\s+/, 1)[0]) === null || _e === void 0 ? void 0 : _e.toUpperCase()) || method;
|
|
1152
1154
|
logSql({
|
|
1153
|
-
allowListStatus: "not verified",
|
|
1155
|
+
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",
|
|
1154
1156
|
cacheStatus: "evicted",
|
|
1155
1157
|
context: logContext,
|
|
1156
1158
|
method: sqlMethod,
|
|
@@ -1205,27 +1207,34 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1205
1207
|
};
|
|
1206
1208
|
HttpExecutor.prototype.postState = function (response, request, callback) {
|
|
1207
1209
|
var _this = this;
|
|
1208
|
-
var _a, _b, _c;
|
|
1210
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1211
|
+
var responseRestRaw = (_a = response.data) === null || _a === void 0 ? void 0 : _a.rest;
|
|
1212
|
+
var responseRows = Array.isArray(responseRestRaw)
|
|
1213
|
+
? responseRestRaw
|
|
1214
|
+
: (responseRestRaw ? [responseRestRaw] : []);
|
|
1209
1215
|
if (this.config.restModel.PRIMARY_SHORT.length === 1) {
|
|
1210
1216
|
var pk = this.config.restModel.PRIMARY_SHORT[0];
|
|
1211
1217
|
try {
|
|
1212
|
-
|
|
1218
|
+
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];
|
|
1219
|
+
if (created !== undefined) {
|
|
1220
|
+
request[pk] = created;
|
|
1221
|
+
}
|
|
1213
1222
|
}
|
|
1214
|
-
catch ( /* best-effort */
|
|
1223
|
+
catch ( /* best-effort */_g) { /* best-effort */ }
|
|
1215
1224
|
}
|
|
1216
1225
|
else if (isLocal()) {
|
|
1217
1226
|
logWithLevel(exports.LogLevel.ERROR, getLogContext(this.config, this.request), console.error, "C6 received unexpected results given the primary key length");
|
|
1218
1227
|
}
|
|
1219
|
-
(
|
|
1228
|
+
(_e = this.config.reactBootstrap) === null || _e === void 0 ? void 0 : _e.updateRestfulObjectArrays({
|
|
1220
1229
|
callback: callback,
|
|
1221
1230
|
dataOrCallback: undefined !== request.dataInsertMultipleRows
|
|
1222
1231
|
? request.dataInsertMultipleRows.map(function (row, index) {
|
|
1223
1232
|
var _a;
|
|
1224
1233
|
var normalizedRow = _this.stripTableNameFromKeys(row);
|
|
1225
|
-
return removeInvalidKeys(tslib.__assign(tslib.__assign({}, normalizedRow), (
|
|
1234
|
+
return removeInvalidKeys(tslib.__assign(tslib.__assign({}, normalizedRow), ((_a = responseRows[index]) !== null && _a !== void 0 ? _a : {})), _this.config.C6.TABLES);
|
|
1226
1235
|
})
|
|
1227
1236
|
: [
|
|
1228
|
-
removeInvalidKeys(tslib.__assign(tslib.__assign({}, this.stripTableNameFromKeys(request)), (
|
|
1237
|
+
removeInvalidKeys(tslib.__assign(tslib.__assign({}, this.stripTableNameFromKeys(request)), ((_f = responseRows[0]) !== null && _f !== void 0 ? _f : {})), this.config.C6.TABLES)
|
|
1229
1238
|
],
|
|
1230
1239
|
stateKey: this.config.restModel.TABLE_NAME,
|
|
1231
1240
|
uniqueObjectId: this.config.restModel.PRIMARY_SHORT
|
|
@@ -1284,16 +1293,16 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1284
1293
|
}
|
|
1285
1294
|
query = this.request;
|
|
1286
1295
|
apiRequest = function () { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
1287
|
-
var _a, debug, _b, cacheResults, dataInsertMultipleRows, success,
|
|
1288
|
-
var
|
|
1296
|
+
var _a, debug, _b, cacheResults, _c, skipReactBootstrap, dataInsertMultipleRows, success, _d, fetchDependencies, _e, error, cachingConfirmed, cacheRequestData, cacheAllowListStatus, evictFromCache, querySerialized, cachedRequest, cachedData, apiResponse, restRequestUri, needsConditionOrPrimaryCheck, TABLES, primaryKeyList, primaryKeyFullyQualified, primaryKey, whereVal, whereIsEmpty, providedPrimary, primaryVal, axiosActiveRequest_1;
|
|
1297
|
+
var _f;
|
|
1289
1298
|
var _this = this;
|
|
1290
|
-
var
|
|
1291
|
-
return tslib.__generator(this, function (
|
|
1292
|
-
switch (
|
|
1299
|
+
var _g, _h, _j, _k, _l, _m;
|
|
1300
|
+
return tslib.__generator(this, function (_o) {
|
|
1301
|
+
switch (_o.label) {
|
|
1293
1302
|
case 0:
|
|
1294
|
-
_a = this.request, debug = _a.debug, _b = _a.cacheResults, cacheResults = _b === void 0 ? (C6.GET === requestMethod) : _b, dataInsertMultipleRows = _a.dataInsertMultipleRows, success = _a.success,
|
|
1303
|
+
_a = this.request, debug = _a.debug, _b = _a.cacheResults, cacheResults = _b === void 0 ? (C6.GET === requestMethod) : _b, _c = _a.skipReactBootstrap, skipReactBootstrap = _c === void 0 ? false : _c, dataInsertMultipleRows = _a.dataInsertMultipleRows, success = _a.success, _d = _a.fetchDependencies, fetchDependencies = _d === void 0 ? exports.eFetchDependencies.NONE : _d, _e = _a.error, error = _e === void 0 ? "An unexpected API error occurred!" : _e;
|
|
1295
1304
|
if (C6.GET === requestMethod
|
|
1296
|
-
&& undefined !== ((
|
|
1305
|
+
&& undefined !== ((_g = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _g === void 0 ? void 0 : _g[C6.PAGE])
|
|
1297
1306
|
&& 1 !== query[C6.PAGINATION][C6.PAGE]
|
|
1298
1307
|
&& isLocal()
|
|
1299
1308
|
&& shouldLog(exports.LogLevel.DEBUG, logContext)) {
|
|
@@ -1314,18 +1323,21 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1314
1323
|
query[C6.PAGINATION][C6.LIMIT] = query[C6.PAGINATION][C6.LIMIT] || 100;
|
|
1315
1324
|
}
|
|
1316
1325
|
cacheRequestData = JSON.parse(JSON.stringify(query !== null && query !== void 0 ? query : {}));
|
|
1326
|
+
cacheAllowListStatus = this.config.sqlAllowListPath
|
|
1327
|
+
? "allowed"
|
|
1328
|
+
: "not verified";
|
|
1317
1329
|
evictFromCache = requestMethod === GET && cacheResults
|
|
1318
|
-
? function () { return evictCacheEntry(requestMethod, tableName, cacheRequestData, logContext); }
|
|
1330
|
+
? function () { return evictCacheEntry(requestMethod, tableName, cacheRequestData, logContext, cacheAllowListStatus); }
|
|
1319
1331
|
: undefined;
|
|
1320
1332
|
querySerialized = sortAndSerializeQueryObject(tables, cacheRequestData !== null && cacheRequestData !== void 0 ? cacheRequestData : {});
|
|
1321
1333
|
cachedRequest = false;
|
|
1322
1334
|
if (cacheResults) {
|
|
1323
|
-
cachedRequest = checkCache(requestMethod, tableName, cacheRequestData, logContext);
|
|
1335
|
+
cachedRequest = checkCache(requestMethod, tableName, cacheRequestData, logContext, cacheAllowListStatus);
|
|
1324
1336
|
}
|
|
1325
1337
|
if (!cachedRequest) return [3 /*break*/, 2];
|
|
1326
1338
|
return [4 /*yield*/, cachedRequest];
|
|
1327
1339
|
case 1:
|
|
1328
|
-
cachedData = (
|
|
1340
|
+
cachedData = (_o.sent()).data;
|
|
1329
1341
|
if (evictFromCache
|
|
1330
1342
|
&& cachedData
|
|
1331
1343
|
&& typeof cachedData === "object"
|
|
@@ -1347,9 +1359,9 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1347
1359
|
needsConditionOrPrimaryCheck = (PUT === requestMethod || DELETE === requestMethod)
|
|
1348
1360
|
&& false === skipPrimaryCheck;
|
|
1349
1361
|
TABLES = C6.TABLES;
|
|
1350
|
-
primaryKeyList = structuredClone((
|
|
1362
|
+
primaryKeyList = structuredClone((_h = TABLES[operatingTable]) === null || _h === void 0 ? void 0 : _h.PRIMARY);
|
|
1351
1363
|
primaryKeyFullyQualified = primaryKeyList === null || primaryKeyList === void 0 ? void 0 : primaryKeyList.pop();
|
|
1352
|
-
primaryKey = (
|
|
1364
|
+
primaryKey = (_j = primaryKeyFullyQualified === null || primaryKeyFullyQualified === void 0 ? void 0 : primaryKeyFullyQualified.split('.')) === null || _j === void 0 ? void 0 : _j.pop();
|
|
1353
1365
|
if (needsConditionOrPrimaryCheck) {
|
|
1354
1366
|
if (undefined === primaryKey) {
|
|
1355
1367
|
whereVal = query === null || query === void 0 ? void 0 : query[C6.WHERE];
|
|
@@ -1358,7 +1370,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1358
1370
|
(typeof whereVal === 'object' && !Array.isArray(whereVal) && Object.keys(whereVal).length === 0);
|
|
1359
1371
|
if (whereIsEmpty) {
|
|
1360
1372
|
logWithLevel(exports.LogLevel.ERROR, logContext, console.error, query);
|
|
1361
|
-
throw Error('Failed to parse primary key information. Query: (' + JSON.stringify(query) + ') Primary Key: (' + JSON.stringify(primaryKey) + ') TABLES[operatingTable]?.PRIMARY: (' + JSON.stringify((
|
|
1373
|
+
throw Error('Failed to parse primary key information. Query: (' + JSON.stringify(query) + ') Primary Key: (' + JSON.stringify(primaryKey) + ') TABLES[operatingTable]?.PRIMARY: (' + JSON.stringify((_k = TABLES[operatingTable]) === null || _k === void 0 ? void 0 : _k.PRIMARY) + ') for operatingTable (' + operatingTable + ').');
|
|
1362
1374
|
}
|
|
1363
1375
|
}
|
|
1364
1376
|
else {
|
|
@@ -1370,7 +1382,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1370
1382
|
}
|
|
1371
1383
|
throw Error('You must provide the primary key (' + primaryKey + ') for table (' + operatingTable + '). Request (' + JSON.stringify(this.request, undefined, 4) + ') Query (' + JSON.stringify(query) + ')');
|
|
1372
1384
|
}
|
|
1373
|
-
providedPrimary = (
|
|
1385
|
+
providedPrimary = (_l = query === null || query === void 0 ? void 0 : query[primaryKey]) !== null && _l !== void 0 ? _l : (primaryKeyFullyQualified ? query === null || query === void 0 ? void 0 : query[primaryKeyFullyQualified] : undefined);
|
|
1374
1386
|
if (undefined === providedPrimary || null === providedPrimary) {
|
|
1375
1387
|
notifyToast("error", "The primary key (".concat(primaryKey, ") provided is undefined or null explicitly!!"));
|
|
1376
1388
|
throw Error('The primary key (' + primaryKey + ') provided in the request was exactly equal to undefined.');
|
|
@@ -1384,7 +1396,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1384
1396
|
&& undefined !== query
|
|
1385
1397
|
&& null !== query
|
|
1386
1398
|
&& undefined !== primaryKey) {
|
|
1387
|
-
primaryVal = (
|
|
1399
|
+
primaryVal = (_m = query[primaryKey]) !== null && _m !== void 0 ? _m : (primaryKeyFullyQualified ? query[primaryKeyFullyQualified] : undefined);
|
|
1388
1400
|
if (undefined !== primaryVal) {
|
|
1389
1401
|
restRequestUri += primaryVal + '/';
|
|
1390
1402
|
if (isLocal() && shouldLog(exports.LogLevel.DEBUG, logContext)) {
|
|
@@ -1412,7 +1424,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1412
1424
|
config: this.config,
|
|
1413
1425
|
request: this.request
|
|
1414
1426
|
});
|
|
1415
|
-
axiosActiveRequest_1 = (
|
|
1427
|
+
axiosActiveRequest_1 = (_f = axios)[requestMethod.toLowerCase()].apply(_f, tslib.__spreadArray([restRequestUri], (function () {
|
|
1416
1428
|
var convert = function (data) {
|
|
1417
1429
|
return convertForRequestBody(data, fullTableList, C6, function (message) { return notifyToast("error", message, toastOptions); });
|
|
1418
1430
|
};
|
|
@@ -1444,6 +1456,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1444
1456
|
setCache(requestMethod, tableName, cacheRequestData, {
|
|
1445
1457
|
requestArgumentsSerialized: querySerialized,
|
|
1446
1458
|
request: axiosActiveRequest_1,
|
|
1459
|
+
allowListStatus: cacheAllowListStatus,
|
|
1447
1460
|
});
|
|
1448
1461
|
}
|
|
1449
1462
|
// returning the promise with this then is important for tests. todo - we could make that optional.
|
|
@@ -1461,6 +1474,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1461
1474
|
setCache(requestMethod, tableName, cacheRequestData, {
|
|
1462
1475
|
requestArgumentsSerialized: querySerialized,
|
|
1463
1476
|
request: axiosActiveRequest_1,
|
|
1477
|
+
allowListStatus: cacheAllowListStatus,
|
|
1464
1478
|
response: response,
|
|
1465
1479
|
final: true,
|
|
1466
1480
|
});
|
|
@@ -1477,6 +1491,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1477
1491
|
setCache(requestMethod, tableName, cacheRequestData, {
|
|
1478
1492
|
requestArgumentsSerialized: querySerialized,
|
|
1479
1493
|
request: axiosActiveRequest_1,
|
|
1494
|
+
allowListStatus: cacheAllowListStatus,
|
|
1480
1495
|
response: response,
|
|
1481
1496
|
});
|
|
1482
1497
|
}
|
|
@@ -1498,7 +1513,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1498
1513
|
request: _this.request,
|
|
1499
1514
|
response: response
|
|
1500
1515
|
}); };
|
|
1501
|
-
if (undefined !== reactBootstrap && response) {
|
|
1516
|
+
if (undefined !== reactBootstrap && response && !skipReactBootstrap) {
|
|
1502
1517
|
switch (requestMethod) {
|
|
1503
1518
|
case GET:
|
|
1504
1519
|
response.data && reactBootstrap.updateRestfulObjectArrays({
|
|
@@ -1541,6 +1556,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1541
1556
|
setCache(requestMethod, tableName, cacheRequestData, {
|
|
1542
1557
|
requestArgumentsSerialized: querySerialized,
|
|
1543
1558
|
request: axiosActiveRequest_1,
|
|
1559
|
+
allowListStatus: cacheAllowListStatus,
|
|
1544
1560
|
response: response,
|
|
1545
1561
|
final: !hasNext,
|
|
1546
1562
|
});
|
|
@@ -1740,6 +1756,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1740
1756
|
setCache(requestMethod, tableName, cacheRequestData, {
|
|
1741
1757
|
requestArgumentsSerialized: querySerialized,
|
|
1742
1758
|
request: axiosActiveRequest_1,
|
|
1759
|
+
allowListStatus: cacheAllowListStatus,
|
|
1743
1760
|
response: response,
|
|
1744
1761
|
final: true,
|
|
1745
1762
|
});
|
|
@@ -1793,6 +1810,318 @@ function convertHexIfBinary(_col, val, columnDef) {
|
|
|
1793
1810
|
return val;
|
|
1794
1811
|
}
|
|
1795
1812
|
|
|
1813
|
+
// ========================
|
|
1814
|
+
// SQL Operators & Expressions
|
|
1815
|
+
// ========================
|
|
1816
|
+
var SQL_KNOWN_FUNCTIONS = [
|
|
1817
|
+
'ADDDATE',
|
|
1818
|
+
'ADDTIME',
|
|
1819
|
+
'CONCAT',
|
|
1820
|
+
'CONVERT_TZ',
|
|
1821
|
+
'COUNT',
|
|
1822
|
+
'COUNT_ALL',
|
|
1823
|
+
'CURRENT_DATE',
|
|
1824
|
+
'CURRENT_TIMESTAMP',
|
|
1825
|
+
'DAY',
|
|
1826
|
+
'DAY_HOUR',
|
|
1827
|
+
'DAY_MICROSECOND',
|
|
1828
|
+
'DAY_MINUTE',
|
|
1829
|
+
'DAY_SECOND',
|
|
1830
|
+
'DAYNAME',
|
|
1831
|
+
'DAYOFMONTH',
|
|
1832
|
+
'DAYOFWEEK',
|
|
1833
|
+
'DAYOFYEAR',
|
|
1834
|
+
'DATE',
|
|
1835
|
+
'DATE_ADD',
|
|
1836
|
+
'DATEDIFF',
|
|
1837
|
+
'DATE_SUB',
|
|
1838
|
+
'DATE_FORMAT',
|
|
1839
|
+
'EXTRACT',
|
|
1840
|
+
'FROM_DAYS',
|
|
1841
|
+
'FROM_UNIXTIME',
|
|
1842
|
+
'GET_FORMAT',
|
|
1843
|
+
'GROUP_CONCAT',
|
|
1844
|
+
'HEX',
|
|
1845
|
+
'HOUR',
|
|
1846
|
+
'HOUR_MICROSECOND',
|
|
1847
|
+
'HOUR_MINUTE',
|
|
1848
|
+
'HOUR_SECOND',
|
|
1849
|
+
'INTERVAL',
|
|
1850
|
+
'LOCALTIME',
|
|
1851
|
+
'LOCALTIMESTAMP',
|
|
1852
|
+
'MAKEDATE',
|
|
1853
|
+
'MAKETIME',
|
|
1854
|
+
'MAX',
|
|
1855
|
+
'MBRContains',
|
|
1856
|
+
'MICROSECOND',
|
|
1857
|
+
'MIN',
|
|
1858
|
+
'MINUTE',
|
|
1859
|
+
'MINUTE_MICROSECOND',
|
|
1860
|
+
'MINUTE_SECOND',
|
|
1861
|
+
'MONTH',
|
|
1862
|
+
'MONTHNAME',
|
|
1863
|
+
'NOW',
|
|
1864
|
+
'POINT',
|
|
1865
|
+
'POLYGON',
|
|
1866
|
+
'SECOND',
|
|
1867
|
+
'SECOND_MICROSECOND',
|
|
1868
|
+
'ST_Area',
|
|
1869
|
+
'ST_AsBinary',
|
|
1870
|
+
'ST_AsText',
|
|
1871
|
+
'ST_Buffer',
|
|
1872
|
+
'ST_Contains',
|
|
1873
|
+
'ST_Crosses',
|
|
1874
|
+
'ST_Difference',
|
|
1875
|
+
'ST_Dimension',
|
|
1876
|
+
'ST_Disjoint',
|
|
1877
|
+
'ST_Distance',
|
|
1878
|
+
'ST_Distance_Sphere',
|
|
1879
|
+
'ST_EndPoint',
|
|
1880
|
+
'ST_Envelope',
|
|
1881
|
+
'ST_Equals',
|
|
1882
|
+
'ST_GeomFromGeoJSON',
|
|
1883
|
+
'ST_GeomFromText',
|
|
1884
|
+
'ST_GeomFromWKB',
|
|
1885
|
+
'ST_Intersects',
|
|
1886
|
+
'ST_Length',
|
|
1887
|
+
'ST_MakeEnvelope',
|
|
1888
|
+
'ST_Overlaps',
|
|
1889
|
+
'ST_Point',
|
|
1890
|
+
'ST_SetSRID',
|
|
1891
|
+
'ST_SRID',
|
|
1892
|
+
'ST_StartPoint',
|
|
1893
|
+
'ST_SymDifference',
|
|
1894
|
+
'ST_Touches',
|
|
1895
|
+
'ST_Union',
|
|
1896
|
+
'ST_Within',
|
|
1897
|
+
'ST_X',
|
|
1898
|
+
'ST_Y',
|
|
1899
|
+
'STR_TO_DATE',
|
|
1900
|
+
'SUBDATE',
|
|
1901
|
+
'SUBTIME',
|
|
1902
|
+
'SUM',
|
|
1903
|
+
'SYSDATE',
|
|
1904
|
+
'TIME',
|
|
1905
|
+
'TIME_FORMAT',
|
|
1906
|
+
'TIME_TO_SEC',
|
|
1907
|
+
'TIMEDIFF',
|
|
1908
|
+
'TIMESTAMP',
|
|
1909
|
+
'TIMESTAMPADD',
|
|
1910
|
+
'TIMESTAMPDIFF',
|
|
1911
|
+
'TO_DAYS',
|
|
1912
|
+
'TO_SECONDS',
|
|
1913
|
+
'TRANSACTION_TIMESTAMP',
|
|
1914
|
+
'UNHEX',
|
|
1915
|
+
'UNIX_TIMESTAMP',
|
|
1916
|
+
'UTC_DATE',
|
|
1917
|
+
'UTC_TIME',
|
|
1918
|
+
'UTC_TIMESTAMP',
|
|
1919
|
+
'WEEKDAY',
|
|
1920
|
+
'WEEKOFYEAR',
|
|
1921
|
+
'YEARWEEK',
|
|
1922
|
+
];
|
|
1923
|
+
|
|
1924
|
+
var IDENTIFIER_REGEX = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
1925
|
+
var isFiniteNumber = function (value) {
|
|
1926
|
+
return typeof value === 'number' && Number.isFinite(value);
|
|
1927
|
+
};
|
|
1928
|
+
var normalizeToken = function (token) { return token.trim(); };
|
|
1929
|
+
var ensureParams = function (opts) {
|
|
1930
|
+
if (!opts.params) {
|
|
1931
|
+
throw new Error("".concat(opts.context, " requires parameter tracking for literal bindings."));
|
|
1932
|
+
}
|
|
1933
|
+
if (!opts.hooks.addParam) {
|
|
1934
|
+
throw new Error("".concat(opts.context, " requires addParam support for literal bindings."));
|
|
1935
|
+
}
|
|
1936
|
+
return opts.params;
|
|
1937
|
+
};
|
|
1938
|
+
var serializeStringReference = function (raw, opts) {
|
|
1939
|
+
var value = raw.trim();
|
|
1940
|
+
if (value === '*') {
|
|
1941
|
+
return {
|
|
1942
|
+
sql: value,
|
|
1943
|
+
isReference: true,
|
|
1944
|
+
isExpression: false,
|
|
1945
|
+
isSubSelect: false,
|
|
1946
|
+
};
|
|
1947
|
+
}
|
|
1948
|
+
if (!opts.hooks.isReference(value)) {
|
|
1949
|
+
throw new Error("Bare string '".concat(raw, "' is not a reference in ").concat(opts.context, ". Wrap literal strings with [C6C.LIT, value]."));
|
|
1950
|
+
}
|
|
1951
|
+
if (value.includes('.')) {
|
|
1952
|
+
opts.hooks.assertValidIdentifier(value, opts.context);
|
|
1953
|
+
}
|
|
1954
|
+
return {
|
|
1955
|
+
sql: value,
|
|
1956
|
+
isReference: true,
|
|
1957
|
+
isExpression: false,
|
|
1958
|
+
isSubSelect: false,
|
|
1959
|
+
};
|
|
1960
|
+
};
|
|
1961
|
+
var serializeLiteralValue = function (value, opts) {
|
|
1962
|
+
var _a;
|
|
1963
|
+
if (value === null || value === C6C.NULL) {
|
|
1964
|
+
return {
|
|
1965
|
+
sql: 'NULL',
|
|
1966
|
+
isReference: false,
|
|
1967
|
+
isExpression: false,
|
|
1968
|
+
isSubSelect: false,
|
|
1969
|
+
};
|
|
1970
|
+
}
|
|
1971
|
+
if (isFiniteNumber(value)) {
|
|
1972
|
+
return {
|
|
1973
|
+
sql: String(value),
|
|
1974
|
+
isReference: false,
|
|
1975
|
+
isExpression: false,
|
|
1976
|
+
isSubSelect: false,
|
|
1977
|
+
};
|
|
1978
|
+
}
|
|
1979
|
+
if (typeof value === 'boolean') {
|
|
1980
|
+
return {
|
|
1981
|
+
sql: value ? 'TRUE' : 'FALSE',
|
|
1982
|
+
isReference: false,
|
|
1983
|
+
isExpression: false,
|
|
1984
|
+
isSubSelect: false,
|
|
1985
|
+
};
|
|
1986
|
+
}
|
|
1987
|
+
if (typeof Buffer !== 'undefined' && Buffer.isBuffer && Buffer.isBuffer(value)) {
|
|
1988
|
+
var params = ensureParams(opts);
|
|
1989
|
+
return {
|
|
1990
|
+
sql: opts.hooks.addParam(params, (_a = opts.contextColumn) !== null && _a !== void 0 ? _a : '', value),
|
|
1991
|
+
isReference: false,
|
|
1992
|
+
isExpression: false,
|
|
1993
|
+
isSubSelect: false,
|
|
1994
|
+
};
|
|
1995
|
+
}
|
|
1996
|
+
throw new Error("Unsupported literal value in ".concat(opts.context, ". Use [C6C.LIT, value] for non-reference strings or complex values."));
|
|
1997
|
+
};
|
|
1998
|
+
var validateAlias = function (aliasRaw, context) {
|
|
1999
|
+
if (typeof aliasRaw !== 'string' || aliasRaw.trim() === '') {
|
|
2000
|
+
throw new Error("[C6C.AS] in ".concat(context, " expects a non-empty alias string."));
|
|
2001
|
+
}
|
|
2002
|
+
var alias = aliasRaw.trim();
|
|
2003
|
+
if (!IDENTIFIER_REGEX.test(alias)) {
|
|
2004
|
+
throw new Error("[C6C.AS] alias '".concat(alias, "' in ").concat(context, " must be a valid SQL identifier."));
|
|
2005
|
+
}
|
|
2006
|
+
return alias;
|
|
2007
|
+
};
|
|
2008
|
+
var validateFunctionName = function (nameRaw, context) {
|
|
2009
|
+
if (typeof nameRaw !== 'string' || nameRaw.trim() === '') {
|
|
2010
|
+
throw new Error("[C6C.CALL] in ".concat(context, " expects the custom function name as a non-empty string."));
|
|
2011
|
+
}
|
|
2012
|
+
var name = normalizeToken(nameRaw);
|
|
2013
|
+
if (!IDENTIFIER_REGEX.test(name)) {
|
|
2014
|
+
throw new Error("[C6C.CALL] function '".concat(name, "' in ").concat(context, " must be a valid SQL identifier."));
|
|
2015
|
+
}
|
|
2016
|
+
return name;
|
|
2017
|
+
};
|
|
2018
|
+
var serializeFunctionArgs = function (args, opts) { return args
|
|
2019
|
+
.map(function (arg) { return serializeSqlExpression(arg, opts).sql; })
|
|
2020
|
+
.join(', '); };
|
|
2021
|
+
var serializeSqlExpression = function (value, opts) {
|
|
2022
|
+
var _a, _b, _c;
|
|
2023
|
+
if (value instanceof Map) {
|
|
2024
|
+
value = Object.fromEntries(value);
|
|
2025
|
+
}
|
|
2026
|
+
if (Array.isArray(value)) {
|
|
2027
|
+
if (value.length === 0) {
|
|
2028
|
+
throw new Error("Invalid empty expression array in ".concat(opts.context, "."));
|
|
2029
|
+
}
|
|
2030
|
+
var headRaw = value[0], tail = value.slice(1);
|
|
2031
|
+
if (typeof headRaw !== 'string') {
|
|
2032
|
+
throw new Error("Expression arrays in ".concat(opts.context, " must start with a string token."));
|
|
2033
|
+
}
|
|
2034
|
+
var head = normalizeToken(headRaw);
|
|
2035
|
+
var token = head.toUpperCase();
|
|
2036
|
+
if (token === C6C.AS) {
|
|
2037
|
+
if (tail.length !== 2) {
|
|
2038
|
+
throw new Error("[C6C.AS] in ".concat(opts.context, " expects [C6C.AS, expression, alias]."));
|
|
2039
|
+
}
|
|
2040
|
+
var inner = serializeSqlExpression(tail[0], opts);
|
|
2041
|
+
var alias = validateAlias(tail[1], opts.context);
|
|
2042
|
+
(_b = (_a = opts.hooks).onAlias) === null || _b === void 0 ? void 0 : _b.call(_a, alias);
|
|
2043
|
+
return {
|
|
2044
|
+
sql: "".concat(inner.sql, " AS ").concat(alias),
|
|
2045
|
+
isReference: false,
|
|
2046
|
+
isExpression: true,
|
|
2047
|
+
isSubSelect: inner.isSubSelect,
|
|
2048
|
+
};
|
|
2049
|
+
}
|
|
2050
|
+
if (token === C6C.DISTINCT) {
|
|
2051
|
+
if (tail.length !== 1) {
|
|
2052
|
+
throw new Error("[C6C.DISTINCT] in ".concat(opts.context, " expects [C6C.DISTINCT, expression]."));
|
|
2053
|
+
}
|
|
2054
|
+
var inner = serializeSqlExpression(tail[0], opts);
|
|
2055
|
+
return {
|
|
2056
|
+
sql: "DISTINCT ".concat(inner.sql),
|
|
2057
|
+
isReference: false,
|
|
2058
|
+
isExpression: true,
|
|
2059
|
+
isSubSelect: inner.isSubSelect,
|
|
2060
|
+
};
|
|
2061
|
+
}
|
|
2062
|
+
if (token === C6C.LIT || token === C6C.PARAM) {
|
|
2063
|
+
if (tail.length !== 1) {
|
|
2064
|
+
throw new Error("[".concat(head, "] in ").concat(opts.context, " expects [").concat(head, ", value]."));
|
|
2065
|
+
}
|
|
2066
|
+
var params = ensureParams(opts);
|
|
2067
|
+
return {
|
|
2068
|
+
sql: opts.hooks.addParam(params, (_c = opts.contextColumn) !== null && _c !== void 0 ? _c : '', tail[0]),
|
|
2069
|
+
isReference: false,
|
|
2070
|
+
isExpression: false,
|
|
2071
|
+
isSubSelect: false,
|
|
2072
|
+
};
|
|
2073
|
+
}
|
|
2074
|
+
if (token === C6C.SUBSELECT) {
|
|
2075
|
+
if (tail.length !== 1) {
|
|
2076
|
+
throw new Error("[C6C.SUBSELECT] in ".concat(opts.context, " expects [C6C.SUBSELECT, payload]."));
|
|
2077
|
+
}
|
|
2078
|
+
if (!opts.hooks.buildScalarSubSelect) {
|
|
2079
|
+
throw new Error("Scalar subselects in ".concat(opts.context, " require subselect builder support."));
|
|
2080
|
+
}
|
|
2081
|
+
var params = ensureParams(opts);
|
|
2082
|
+
var subSql = opts.hooks.buildScalarSubSelect(tail[0], params);
|
|
2083
|
+
return {
|
|
2084
|
+
sql: subSql,
|
|
2085
|
+
isReference: false,
|
|
2086
|
+
isExpression: true,
|
|
2087
|
+
isSubSelect: true,
|
|
2088
|
+
};
|
|
2089
|
+
}
|
|
2090
|
+
if (token === C6C.CALL) {
|
|
2091
|
+
var fnNameRaw = tail[0], args = tail.slice(1);
|
|
2092
|
+
var fnName = validateFunctionName(fnNameRaw, opts.context);
|
|
2093
|
+
var sqlArgs_1 = serializeFunctionArgs(args, opts);
|
|
2094
|
+
return {
|
|
2095
|
+
sql: "".concat(fnName, "(").concat(sqlArgs_1, ")"),
|
|
2096
|
+
isReference: false,
|
|
2097
|
+
isExpression: true,
|
|
2098
|
+
isSubSelect: false,
|
|
2099
|
+
};
|
|
2100
|
+
}
|
|
2101
|
+
if (tail.length >= 2 && String(tail[tail.length - 2]).toUpperCase() === C6C.AS) {
|
|
2102
|
+
throw new Error("Legacy positional AS syntax is not supported in ".concat(opts.context, ". Use [C6C.AS, expression, alias]."));
|
|
2103
|
+
}
|
|
2104
|
+
if (opts.hooks.isKnownFunction && !opts.hooks.isKnownFunction(head)) {
|
|
2105
|
+
throw new Error("Unknown SQL function '".concat(head, "' in ").concat(opts.context, ". Use [C6C.CALL, 'FUNCTION_NAME', ...args] for custom functions."));
|
|
2106
|
+
}
|
|
2107
|
+
var sqlArgs = serializeFunctionArgs(tail, opts);
|
|
2108
|
+
return {
|
|
2109
|
+
sql: "".concat(token, "(").concat(sqlArgs, ")"),
|
|
2110
|
+
isReference: false,
|
|
2111
|
+
isExpression: true,
|
|
2112
|
+
isSubSelect: false,
|
|
2113
|
+
};
|
|
2114
|
+
}
|
|
2115
|
+
if (typeof value === 'string') {
|
|
2116
|
+
return serializeStringReference(value, opts);
|
|
2117
|
+
}
|
|
2118
|
+
if (value && typeof value === 'object') {
|
|
2119
|
+
throw new Error("Object-rooted expressions are not supported in ".concat(opts.context, ". Use tuple syntax instead."));
|
|
2120
|
+
}
|
|
2121
|
+
return serializeLiteralValue(value, opts);
|
|
2122
|
+
};
|
|
2123
|
+
|
|
2124
|
+
var KNOWN_FUNCTION_LOOKUP = new Set(SQL_KNOWN_FUNCTIONS.map(function (name) { return String(name).toUpperCase(); }));
|
|
1796
2125
|
var AggregateBuilder = /** @class */ (function (_super) {
|
|
1797
2126
|
tslib.__extends(AggregateBuilder, _super);
|
|
1798
2127
|
function AggregateBuilder() {
|
|
@@ -1805,112 +2134,71 @@ var AggregateBuilder = /** @class */ (function (_super) {
|
|
|
1805
2134
|
AggregateBuilder.prototype.assertValidIdentifier = function (_identifier, _context) {
|
|
1806
2135
|
// no-op placeholder for subclasses that do not implement alias validation
|
|
1807
2136
|
};
|
|
1808
|
-
AggregateBuilder.prototype.
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
return
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
// function call like [FN, ...args], serialize the list as a comma-separated
|
|
1820
|
-
// literal sequence so parent calls (like ORDER BY FN(<here>)) can embed it.
|
|
1821
|
-
var isNumericString = function (s) { return /^-?\d+(?:\.\d+)?$/.test(String(s).trim()); };
|
|
1822
|
-
if (typeof field[0] !== 'string' || isNumericString(field[0])) {
|
|
1823
|
-
return field
|
|
1824
|
-
.map(function (arg) {
|
|
1825
|
-
if (Array.isArray(arg))
|
|
1826
|
-
return _this.buildAggregateField(arg, params);
|
|
1827
|
-
return String(arg);
|
|
1828
|
-
})
|
|
1829
|
-
.join(', ');
|
|
1830
|
-
}
|
|
1831
|
-
var fn = field[0], args = field.slice(1);
|
|
1832
|
-
var alias;
|
|
1833
|
-
if (args.length >= 2 && String(args[args.length - 2]).toUpperCase() === 'AS') {
|
|
1834
|
-
alias = String(args.pop());
|
|
1835
|
-
args.pop();
|
|
1836
|
-
}
|
|
1837
|
-
var F = String(fn).toUpperCase();
|
|
1838
|
-
var isGeomFromText = F === C6C.ST_GEOMFROMTEXT.toUpperCase();
|
|
1839
|
-
if (args.length === 1 && Array.isArray(args[0])) {
|
|
1840
|
-
args = args[0];
|
|
1841
|
-
}
|
|
1842
|
-
// Parameter placeholder helper: [C6C.PARAM, value]
|
|
1843
|
-
if (F === C6C.PARAM) {
|
|
1844
|
-
if (!params) {
|
|
1845
|
-
throw new Error('PARAM requires parameter tracking.');
|
|
1846
|
-
}
|
|
1847
|
-
var value = args[0];
|
|
1848
|
-
// Use empty column context; ORDER/SELECT literals have no column typing.
|
|
1849
|
-
// @ts-ignore addParam is provided by ConditionBuilder in our hierarchy.
|
|
1850
|
-
return this.addParam(params, '', value);
|
|
1851
|
-
}
|
|
1852
|
-
if (F === C6C.SUBSELECT) {
|
|
1853
|
-
if (!params) {
|
|
1854
|
-
throw new Error('Scalar subselects in SELECT require parameter tracking.');
|
|
1855
|
-
}
|
|
1856
|
-
var subRequest = args[0];
|
|
1857
|
-
var subSql = (_b = (_a = this).buildScalarSubSelect) === null || _b === void 0 ? void 0 : _b.call(_a, subRequest, params);
|
|
1858
|
-
if (!subSql) {
|
|
1859
|
-
throw new Error('Failed to build scalar subselect.');
|
|
1860
|
-
}
|
|
1861
|
-
var expr_1 = subSql;
|
|
1862
|
-
if (alias) {
|
|
1863
|
-
this.selectAliases.add(alias);
|
|
1864
|
-
expr_1 += " AS ".concat(alias);
|
|
1865
|
-
}
|
|
1866
|
-
logWithLevel(exports.LogLevel.DEBUG, getLogContext(this.config, this.request), console.log, "[SELECT] ".concat(expr_1));
|
|
1867
|
-
return expr_1;
|
|
1868
|
-
}
|
|
1869
|
-
var identifierPathRegex = /^[A-Za-z_][A-Za-z0-9_]*\.[A-Za-z_][A-Za-z0-9_]*$/;
|
|
1870
|
-
var argList = args
|
|
1871
|
-
.map(function (arg, index) {
|
|
1872
|
-
if (Array.isArray(arg))
|
|
1873
|
-
return _this.buildAggregateField(arg, params);
|
|
1874
|
-
if (typeof arg === 'string') {
|
|
1875
|
-
if (identifierPathRegex.test(arg)) {
|
|
1876
|
-
_this.assertValidIdentifier(arg, 'SELECT expression');
|
|
1877
|
-
return arg;
|
|
1878
|
-
}
|
|
1879
|
-
// Treat numeric-looking strings as literals, not identifier paths
|
|
1880
|
-
if (isNumericString(arg))
|
|
1881
|
-
return arg;
|
|
1882
|
-
if (isGeomFromText && index === 0) {
|
|
1883
|
-
var trimmed = arg.trim();
|
|
1884
|
-
var alreadyQuoted = trimmed.startsWith("'") && trimmed.endsWith("'") && trimmed.length >= 2;
|
|
1885
|
-
if (alreadyQuoted) {
|
|
1886
|
-
return trimmed;
|
|
1887
|
-
}
|
|
1888
|
-
var escaped = arg.replace(/'/g, "''");
|
|
1889
|
-
return "'".concat(escaped, "'");
|
|
1890
|
-
}
|
|
1891
|
-
return arg;
|
|
1892
|
-
}
|
|
1893
|
-
return String(arg);
|
|
1894
|
-
})
|
|
1895
|
-
.join(', ');
|
|
1896
|
-
var expr;
|
|
1897
|
-
if (F === 'DISTINCT') {
|
|
1898
|
-
expr = "DISTINCT ".concat(argList);
|
|
2137
|
+
AggregateBuilder.prototype.isReferenceExpression = function (value) {
|
|
2138
|
+
if (typeof value !== 'string')
|
|
2139
|
+
return false;
|
|
2140
|
+
var trimmed = value.trim();
|
|
2141
|
+
if (trimmed.length === 0)
|
|
2142
|
+
return false;
|
|
2143
|
+
if (trimmed === '*')
|
|
2144
|
+
return true;
|
|
2145
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*\.\*$/.test(trimmed)) {
|
|
2146
|
+
this.assertValidIdentifier(trimmed, 'SQL reference');
|
|
2147
|
+
return true;
|
|
1899
2148
|
}
|
|
1900
|
-
|
|
1901
|
-
|
|
2149
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*\.[A-Za-z_][A-Za-z0-9_]*$/.test(trimmed)) {
|
|
2150
|
+
this.assertValidIdentifier(trimmed, 'SQL reference');
|
|
2151
|
+
return true;
|
|
1902
2152
|
}
|
|
1903
|
-
if (
|
|
1904
|
-
|
|
1905
|
-
expr += " AS ".concat(alias);
|
|
2153
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*$/.test(trimmed) && this.selectAliases.has(trimmed)) {
|
|
2154
|
+
return true;
|
|
1906
2155
|
}
|
|
1907
|
-
|
|
1908
|
-
|
|
2156
|
+
return false;
|
|
2157
|
+
};
|
|
2158
|
+
AggregateBuilder.prototype.isKnownFunction = function (functionName) {
|
|
2159
|
+
return KNOWN_FUNCTION_LOOKUP.has(functionName.trim().toUpperCase());
|
|
2160
|
+
};
|
|
2161
|
+
AggregateBuilder.prototype.serializeExpression = function (expression, params, context, contextColumn) {
|
|
2162
|
+
var _this = this;
|
|
2163
|
+
if (context === void 0) { context = 'SQL expression'; }
|
|
2164
|
+
return serializeSqlExpression(expression, {
|
|
2165
|
+
params: params,
|
|
2166
|
+
context: context,
|
|
2167
|
+
contextColumn: contextColumn,
|
|
2168
|
+
hooks: {
|
|
2169
|
+
assertValidIdentifier: function (identifier, hookContext) {
|
|
2170
|
+
_this.assertValidIdentifier(identifier, hookContext);
|
|
2171
|
+
},
|
|
2172
|
+
isReference: function (value) { return _this.isReferenceExpression(value); },
|
|
2173
|
+
addParam: function (target, column, value) {
|
|
2174
|
+
var addParam = _this.addParam;
|
|
2175
|
+
if (typeof addParam !== 'function') {
|
|
2176
|
+
throw new Error('Expression literal binding requires addParam support.');
|
|
2177
|
+
}
|
|
2178
|
+
return addParam.call(_this, target, column, value);
|
|
2179
|
+
},
|
|
2180
|
+
buildScalarSubSelect: function (subRequest, target) {
|
|
2181
|
+
var builder = _this.buildScalarSubSelect;
|
|
2182
|
+
if (typeof builder !== 'function') {
|
|
2183
|
+
throw new Error('Scalar subselects require SelectQueryBuilder context.');
|
|
2184
|
+
}
|
|
2185
|
+
return builder.call(_this, subRequest, target);
|
|
2186
|
+
},
|
|
2187
|
+
onAlias: function (alias) {
|
|
2188
|
+
_this.selectAliases.add(alias);
|
|
2189
|
+
},
|
|
2190
|
+
isKnownFunction: function (functionName) { return _this.isKnownFunction(functionName); },
|
|
2191
|
+
},
|
|
2192
|
+
});
|
|
2193
|
+
};
|
|
2194
|
+
AggregateBuilder.prototype.buildAggregateField = function (field, params) {
|
|
2195
|
+
var serialized = this.serializeExpression(field, params, 'SELECT expression');
|
|
2196
|
+
logWithLevel(exports.LogLevel.DEBUG, getLogContext(this.config, this.request), console.log, "[SELECT] ".concat(serialized.sql));
|
|
2197
|
+
return serialized.sql;
|
|
1909
2198
|
};
|
|
1910
2199
|
return AggregateBuilder;
|
|
1911
2200
|
}(Executor));
|
|
1912
2201
|
|
|
1913
|
-
// Alias a table name with a given alias
|
|
1914
2202
|
var DERIVED_TABLE_PREFIX = '__c6DerivedTable__';
|
|
1915
2203
|
var DERIVED_ID_SYMBOL = Symbol('c6DerivedTableId');
|
|
1916
2204
|
var derivedTableLookup = new Map();
|
|
@@ -1988,6 +2276,29 @@ var bbox = function (minLng, minLat, maxLng, maxLat) {
|
|
|
1988
2276
|
var stContains = function (envelope, shape) {
|
|
1989
2277
|
return [C6C.ST_CONTAINS, envelope, shape];
|
|
1990
2278
|
};
|
|
2279
|
+
// Strongly-typed known function helper.
|
|
2280
|
+
var fn = function (functionName) {
|
|
2281
|
+
var args = [];
|
|
2282
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
2283
|
+
args[_i - 1] = arguments[_i];
|
|
2284
|
+
}
|
|
2285
|
+
return tslib.__spreadArray([functionName], args, true);
|
|
2286
|
+
};
|
|
2287
|
+
// Escape hatch for custom function names.
|
|
2288
|
+
var call = function (functionName) {
|
|
2289
|
+
var args = [];
|
|
2290
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
2291
|
+
args[_i - 1] = arguments[_i];
|
|
2292
|
+
}
|
|
2293
|
+
return tslib.__spreadArray([C6C.CALL, functionName], args, true);
|
|
2294
|
+
};
|
|
2295
|
+
var alias = function (expression, aliasName) { return [C6C.AS, expression, aliasName]; };
|
|
2296
|
+
var distinct = function (expression) { return [C6C.DISTINCT, expression]; };
|
|
2297
|
+
var lit = function (value) { return [C6C.LIT, value]; };
|
|
2298
|
+
var order = function (expression, direction) {
|
|
2299
|
+
if (direction === void 0) { direction = C6C.ASC; }
|
|
2300
|
+
return [expression, direction];
|
|
2301
|
+
};
|
|
1991
2302
|
|
|
1992
2303
|
var ConditionBuilder = /** @class */ (function (_super) {
|
|
1993
2304
|
tslib.__extends(ConditionBuilder, _super);
|
|
@@ -2094,6 +2405,26 @@ var ConditionBuilder = /** @class */ (function (_super) {
|
|
|
2094
2405
|
return true;
|
|
2095
2406
|
return false;
|
|
2096
2407
|
};
|
|
2408
|
+
ConditionBuilder.prototype.isReferenceExpression = function (value) {
|
|
2409
|
+
var trimmed = value.trim();
|
|
2410
|
+
if (trimmed === '*') {
|
|
2411
|
+
return true;
|
|
2412
|
+
}
|
|
2413
|
+
if (trimmed.includes('.')) {
|
|
2414
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*\.\*$/.test(trimmed)) {
|
|
2415
|
+
return true;
|
|
2416
|
+
}
|
|
2417
|
+
if (this.isTableReference(trimmed) || this.isColumnRef(trimmed)) {
|
|
2418
|
+
return true;
|
|
2419
|
+
}
|
|
2420
|
+
if (/^[A-Za-z_][A-Za-z0-9_]*\.[A-Za-z_][A-Za-z0-9_]*$/.test(trimmed)) {
|
|
2421
|
+
this.assertValidIdentifier(trimmed, 'SQL reference');
|
|
2422
|
+
return true;
|
|
2423
|
+
}
|
|
2424
|
+
return false;
|
|
2425
|
+
}
|
|
2426
|
+
return _super.prototype.isReferenceExpression.call(this, trimmed);
|
|
2427
|
+
};
|
|
2097
2428
|
ConditionBuilder.prototype.execute = function () {
|
|
2098
2429
|
throw new Error("Method not implemented.");
|
|
2099
2430
|
};
|
|
@@ -2168,41 +2499,6 @@ var ConditionBuilder = /** @class */ (function (_super) {
|
|
|
2168
2499
|
ConditionBuilder.prototype.isOperator = function (op) {
|
|
2169
2500
|
return !!this.normalizeOperatorKey(op);
|
|
2170
2501
|
};
|
|
2171
|
-
ConditionBuilder.prototype.looksLikeSafeFunctionExpression = function (value) {
|
|
2172
|
-
if (typeof value !== 'string')
|
|
2173
|
-
return false;
|
|
2174
|
-
var trimmed = value.trim();
|
|
2175
|
-
if (trimmed.length === 0)
|
|
2176
|
-
return false;
|
|
2177
|
-
if (trimmed.includes(';') || trimmed.includes('--') || trimmed.includes('/*') || trimmed.includes('*/')) {
|
|
2178
|
-
return false;
|
|
2179
|
-
}
|
|
2180
|
-
if (!trimmed.includes('(') || !trimmed.endsWith(')')) {
|
|
2181
|
-
return false;
|
|
2182
|
-
}
|
|
2183
|
-
var functionMatch = trimmed.match(/^([A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*)\s*\(/);
|
|
2184
|
-
if (!functionMatch) {
|
|
2185
|
-
return false;
|
|
2186
|
-
}
|
|
2187
|
-
var allowedCharacters = /^[A-Za-z0-9_().,'"\s-]+$/;
|
|
2188
|
-
if (!allowedCharacters.test(trimmed)) {
|
|
2189
|
-
return false;
|
|
2190
|
-
}
|
|
2191
|
-
var depth = 0;
|
|
2192
|
-
for (var _i = 0, trimmed_1 = trimmed; _i < trimmed_1.length; _i++) {
|
|
2193
|
-
var char = trimmed_1[_i];
|
|
2194
|
-
if (char === '(') {
|
|
2195
|
-
depth += 1;
|
|
2196
|
-
}
|
|
2197
|
-
else if (char === ')') {
|
|
2198
|
-
depth -= 1;
|
|
2199
|
-
if (depth < 0) {
|
|
2200
|
-
return false;
|
|
2201
|
-
}
|
|
2202
|
-
}
|
|
2203
|
-
}
|
|
2204
|
-
return depth === 0;
|
|
2205
|
-
};
|
|
2206
2502
|
ConditionBuilder.prototype.ensureWrapped = function (expression) {
|
|
2207
2503
|
var trimmed = expression.trim();
|
|
2208
2504
|
if (!trimmed)
|
|
@@ -2230,42 +2526,6 @@ var ConditionBuilder = /** @class */ (function (_super) {
|
|
|
2230
2526
|
})
|
|
2231
2527
|
.join(" ".concat(operator, " "));
|
|
2232
2528
|
};
|
|
2233
|
-
ConditionBuilder.prototype.normalizeFunctionField = function (field, params) {
|
|
2234
|
-
var _this = this;
|
|
2235
|
-
if (field instanceof Map) {
|
|
2236
|
-
field = Object.fromEntries(field);
|
|
2237
|
-
}
|
|
2238
|
-
if (Array.isArray(field)) {
|
|
2239
|
-
if (field.length === 0)
|
|
2240
|
-
return field;
|
|
2241
|
-
var fn = field[0], args = field.slice(1);
|
|
2242
|
-
var normalizedArgs = args.map(function (arg) { return _this.normalizeFunctionField(arg, params); });
|
|
2243
|
-
return tslib.__spreadArray([fn], normalizedArgs, true);
|
|
2244
|
-
}
|
|
2245
|
-
if (field && typeof field === 'object') {
|
|
2246
|
-
if (C6C.SUBSELECT in field) {
|
|
2247
|
-
var builder = this.buildScalarSubSelect;
|
|
2248
|
-
if (typeof builder !== 'function') {
|
|
2249
|
-
throw new Error('Scalar subselect handling requires JoinBuilder context.');
|
|
2250
|
-
}
|
|
2251
|
-
return builder.call(this, field[C6C.SUBSELECT], params);
|
|
2252
|
-
}
|
|
2253
|
-
var entries = Object.entries(field);
|
|
2254
|
-
if (entries.length === 1) {
|
|
2255
|
-
var _a = entries[0], key = _a[0], value = _a[1];
|
|
2256
|
-
if (this.isOperator(key)) {
|
|
2257
|
-
return this.buildOperatorExpression(key, value, params);
|
|
2258
|
-
}
|
|
2259
|
-
return this.buildFunctionCall(key, value, params);
|
|
2260
|
-
}
|
|
2261
|
-
}
|
|
2262
|
-
return field;
|
|
2263
|
-
};
|
|
2264
|
-
ConditionBuilder.prototype.buildFunctionCall = function (fn, value, params) {
|
|
2265
|
-
var args = Array.isArray(value) ? value : [value];
|
|
2266
|
-
var normalized = this.normalizeFunctionField(tslib.__spreadArray([fn], args, true), params);
|
|
2267
|
-
return this.buildAggregateField(normalized, params);
|
|
2268
|
-
};
|
|
2269
2529
|
ConditionBuilder.prototype.serializeOperand = function (operand, params, contextColumn) {
|
|
2270
2530
|
var _a;
|
|
2271
2531
|
var _this = this;
|
|
@@ -2280,18 +2540,14 @@ var ConditionBuilder = /** @class */ (function (_super) {
|
|
|
2280
2540
|
return { sql: asParam(operand), isReference: false, isExpression: false, isSubSelect: false };
|
|
2281
2541
|
}
|
|
2282
2542
|
if (typeof operand === 'string') {
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
if (this.looksLikeSafeFunctionExpression(operand)) {
|
|
2287
|
-
return { sql: operand.trim(), isReference: false, isExpression: true, isSubSelect: false };
|
|
2543
|
+
var trimmed = operand.trim();
|
|
2544
|
+
if (this.isReferenceExpression(trimmed) || this.isTableReference(trimmed) || this.isColumnRef(trimmed)) {
|
|
2545
|
+
return { sql: trimmed, isReference: true, isExpression: false, isSubSelect: false };
|
|
2288
2546
|
}
|
|
2289
|
-
|
|
2547
|
+
throw new Error("Bare string '".concat(operand, "' is not a reference. Wrap literal strings with [C6C.LIT, value]."));
|
|
2290
2548
|
}
|
|
2291
2549
|
if (Array.isArray(operand)) {
|
|
2292
|
-
|
|
2293
|
-
var sql = this.buildAggregateField(normalized, params);
|
|
2294
|
-
return { sql: sql, isReference: false, isExpression: true, isSubSelect: false };
|
|
2550
|
+
return this.serializeExpression(operand, params, 'SQL expression', contextColumn);
|
|
2295
2551
|
}
|
|
2296
2552
|
if (operand instanceof Map) {
|
|
2297
2553
|
operand = Object.fromEntries(operand);
|
|
@@ -2309,24 +2565,38 @@ var ConditionBuilder = /** @class */ (function (_super) {
|
|
|
2309
2565
|
if (entries.length === 1) {
|
|
2310
2566
|
var _b = entries[0], key = _b[0], value = _b[1];
|
|
2311
2567
|
if (this.isOperator(key)) {
|
|
2312
|
-
var
|
|
2313
|
-
return { sql: this.ensureWrapped(
|
|
2568
|
+
var sql = this.buildOperatorExpression(key, value, params);
|
|
2569
|
+
return { sql: this.ensureWrapped(sql), isReference: false, isExpression: true, isSubSelect: false };
|
|
2314
2570
|
}
|
|
2315
2571
|
if (this.BOOLEAN_OPERATORS.has(key)) {
|
|
2316
|
-
var
|
|
2317
|
-
return { sql: this.ensureWrapped(
|
|
2572
|
+
var sql = this.buildBooleanExpression((_a = {}, _a[key] = value, _a), params, 'AND');
|
|
2573
|
+
return { sql: this.ensureWrapped(sql), isReference: false, isExpression: true, isSubSelect: false };
|
|
2318
2574
|
}
|
|
2319
|
-
|
|
2320
|
-
return { sql: sql, isReference: false, isExpression: true, isSubSelect: false };
|
|
2575
|
+
throw new Error('Object-rooted expressions are not supported. Use tuple syntax instead.');
|
|
2321
2576
|
}
|
|
2322
2577
|
}
|
|
2323
2578
|
throw new Error('Unsupported operand type in SQL expression.');
|
|
2324
2579
|
};
|
|
2580
|
+
ConditionBuilder.prototype.isExpressionTuple = function (value) {
|
|
2581
|
+
if (!Array.isArray(value) || value.length === 0 || typeof value[0] !== 'string') {
|
|
2582
|
+
return false;
|
|
2583
|
+
}
|
|
2584
|
+
var token = String(value[0]).toUpperCase();
|
|
2585
|
+
return (token === C6C.AS
|
|
2586
|
+
|| token === C6C.DISTINCT
|
|
2587
|
+
|| token === C6C.CALL
|
|
2588
|
+
|| token === C6C.LIT
|
|
2589
|
+
|| token === C6C.PARAM
|
|
2590
|
+
|| token === C6C.SUBSELECT
|
|
2591
|
+
|| this.isKnownFunction(value[0]));
|
|
2592
|
+
};
|
|
2325
2593
|
ConditionBuilder.prototype.isPlainArrayLiteral = function (value, allowColumnRefs) {
|
|
2326
2594
|
var _this = this;
|
|
2327
2595
|
if (allowColumnRefs === void 0) { allowColumnRefs = false; }
|
|
2328
2596
|
if (!Array.isArray(value))
|
|
2329
2597
|
return false;
|
|
2598
|
+
if (this.isExpressionTuple(value))
|
|
2599
|
+
return false;
|
|
2330
2600
|
return value.every(function (item) {
|
|
2331
2601
|
if (item === null)
|
|
2332
2602
|
return true;
|
|
@@ -2396,6 +2666,16 @@ var ConditionBuilder = /** @class */ (function (_super) {
|
|
|
2396
2666
|
|| this.isPlainObjectLiteral(normalized, allowColumnRefs)) {
|
|
2397
2667
|
return this.addParam(params, contextColumn !== null && contextColumn !== void 0 ? contextColumn : '', JSON.stringify(normalized));
|
|
2398
2668
|
}
|
|
2669
|
+
if (normalized === C6C.NULL
|
|
2670
|
+
|| normalized === null
|
|
2671
|
+
|| typeof normalized === 'string'
|
|
2672
|
+
|| typeof normalized === 'number'
|
|
2673
|
+
|| typeof normalized === 'boolean'
|
|
2674
|
+
|| normalized instanceof Date
|
|
2675
|
+
|| (typeof Buffer !== 'undefined' && Buffer.isBuffer && Buffer.isBuffer(normalized))) {
|
|
2676
|
+
var scalar = normalized === C6C.NULL ? null : normalized;
|
|
2677
|
+
return this.addParam(params, contextColumn !== null && contextColumn !== void 0 ? contextColumn : '', scalar);
|
|
2678
|
+
}
|
|
2399
2679
|
var sql;
|
|
2400
2680
|
var isReference;
|
|
2401
2681
|
var isExpression;
|
|
@@ -2479,7 +2759,10 @@ var ConditionBuilder = /** @class */ (function (_super) {
|
|
|
2479
2759
|
}
|
|
2480
2760
|
var payload = this.ensurePlainObject(payloadRaw);
|
|
2481
2761
|
var subSelect;
|
|
2482
|
-
if (payload &&
|
|
2762
|
+
if (Array.isArray(payload) && payload.length === 2 && String(payload[0]).toUpperCase() === C6C.SUBSELECT) {
|
|
2763
|
+
subSelect = this.ensurePlainObject(payload[1]);
|
|
2764
|
+
}
|
|
2765
|
+
else if (payload && typeof payload === 'object' && C6C.SUBSELECT in payload) {
|
|
2483
2766
|
subSelect = this.ensurePlainObject(payload[C6C.SUBSELECT]);
|
|
2484
2767
|
}
|
|
2485
2768
|
else if (payload && typeof payload === 'object') {
|
|
@@ -2573,7 +2856,11 @@ var ConditionBuilder = /** @class */ (function (_super) {
|
|
|
2573
2856
|
throw new Error('MATCH_AGAINST expects an array [search, mode?].');
|
|
2574
2857
|
}
|
|
2575
2858
|
var search = right[0], mode = right[1];
|
|
2576
|
-
var
|
|
2859
|
+
var searchInfo = this.serializeOperand(search, params, leftInfo_1.sql);
|
|
2860
|
+
if (searchInfo.isReference || searchInfo.isExpression || searchInfo.isSubSelect) {
|
|
2861
|
+
throw new Error('MATCH_AGAINST search payload must be a literal value (wrap strings with [C6C.LIT, value]).');
|
|
2862
|
+
}
|
|
2863
|
+
var placeholder = searchInfo.sql;
|
|
2577
2864
|
var againstClause = void 0;
|
|
2578
2865
|
switch (typeof mode === 'string' ? mode.toUpperCase() : '') {
|
|
2579
2866
|
case 'BOOLEAN':
|
|
@@ -2675,7 +2962,7 @@ var ConditionBuilder = /** @class */ (function (_super) {
|
|
|
2675
2962
|
if (!Array.isArray(value)) {
|
|
2676
2963
|
throw new Error("".concat(column, " expects an array of arguments."));
|
|
2677
2964
|
}
|
|
2678
|
-
return this.
|
|
2965
|
+
return this.serializeExpression(tslib.__spreadArray([column], value, true), params, "WHERE function ".concat(column), column).sql;
|
|
2679
2966
|
}
|
|
2680
2967
|
}
|
|
2681
2968
|
if (typeof Buffer !== 'undefined' && Buffer.isBuffer && Buffer.isBuffer(value)) {
|
|
@@ -3118,56 +3405,34 @@ var PaginationBuilder = /** @class */ (function (_super) {
|
|
|
3118
3405
|
*
|
|
3119
3406
|
* Accepted structures:
|
|
3120
3407
|
* ```ts
|
|
3121
|
-
* ORDER:
|
|
3122
|
-
*
|
|
3123
|
-
* [property_units.
|
|
3124
|
-
*
|
|
3125
|
-
* [C6Constants.ST_DISTANCE_SPHERE]: [property_units.LOCATION, F(property_units.LOCATION, "pu_target")]
|
|
3126
|
-
* }
|
|
3408
|
+
* ORDER: [
|
|
3409
|
+
* [property_units.UNIT_ID, "DESC"],
|
|
3410
|
+
* [[C6Constants.ST_DISTANCE_SPHERE, property_units.LOCATION, F(property_units.LOCATION, "pu_target")], "ASC"],
|
|
3411
|
+
* ]
|
|
3127
3412
|
* ```
|
|
3128
3413
|
*/
|
|
3129
3414
|
PaginationBuilder.prototype.buildPaginationClause = function (pagination, params) {
|
|
3130
|
-
var _this = this;
|
|
3131
3415
|
var sql = "";
|
|
3132
3416
|
/* -------- ORDER BY -------- */
|
|
3133
3417
|
if (pagination === null || pagination === void 0 ? void 0 : pagination[C6Constants.ORDER]) {
|
|
3134
3418
|
var orderParts = [];
|
|
3135
|
-
var
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
_this.assertValidIdentifier(arg, 'ORDER BY argument');
|
|
3150
|
-
return arg;
|
|
3151
|
-
}
|
|
3152
|
-
// numeric-looking strings should be treated as literals
|
|
3153
|
-
if (isNumericString_1(arg))
|
|
3154
|
-
return arg;
|
|
3155
|
-
return arg;
|
|
3156
|
-
}
|
|
3157
|
-
return String(arg);
|
|
3158
|
-
})
|
|
3159
|
-
.join(", ");
|
|
3160
|
-
orderParts.push("".concat(key, "(").concat(args, ")"));
|
|
3161
|
-
}
|
|
3162
|
-
// SIMPLE COLUMN + DIR (ASC/DESC)
|
|
3163
|
-
else {
|
|
3164
|
-
orderParts.push("".concat(key, " ").concat(String(val).toUpperCase()));
|
|
3419
|
+
var orderSpec = pagination[C6Constants.ORDER];
|
|
3420
|
+
if (!Array.isArray(orderSpec)) {
|
|
3421
|
+
throw new Error('PAGINATION.ORDER expects an array of terms using [expression, direction?] syntax.');
|
|
3422
|
+
}
|
|
3423
|
+
for (var _i = 0, orderSpec_1 = orderSpec; _i < orderSpec_1.length; _i++) {
|
|
3424
|
+
var rawTerm = orderSpec_1[_i];
|
|
3425
|
+
var expression = rawTerm;
|
|
3426
|
+
var direction = C6Constants.ASC;
|
|
3427
|
+
if (Array.isArray(rawTerm)
|
|
3428
|
+
&& rawTerm.length === 2
|
|
3429
|
+
&& typeof rawTerm[1] === 'string'
|
|
3430
|
+
&& (String(rawTerm[1]).toUpperCase() === C6Constants.ASC || String(rawTerm[1]).toUpperCase() === C6Constants.DESC)) {
|
|
3431
|
+
expression = rawTerm[0];
|
|
3432
|
+
direction = String(rawTerm[1]).toUpperCase();
|
|
3165
3433
|
}
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
for (var _i = 0, _a = Object.entries(pagination[C6Constants.ORDER]); _i < _a.length; _i++) {
|
|
3169
|
-
var _b = _a[_i], key = _b[0], val = _b[1];
|
|
3170
|
-
_loop_1(key, val);
|
|
3434
|
+
var serialized = this.serializeExpression(expression, params, 'ORDER BY expression');
|
|
3435
|
+
orderParts.push("".concat(serialized.sql, " ").concat(direction));
|
|
3171
3436
|
}
|
|
3172
3437
|
if (orderParts.length)
|
|
3173
3438
|
sql += " ORDER BY ".concat(orderParts.join(", "));
|
|
@@ -3457,7 +3722,7 @@ function normalizeSingularRequest(requestMethod, request, restModel, removedPrim
|
|
|
3457
3722
|
throw new Error("Singular request requires all primary key(s) [".concat(pkShorts.join(', '), "] for table (").concat(restModel.TABLE_NAME, "). Missing: [").concat(missing.join(', '), "]"));
|
|
3458
3723
|
}
|
|
3459
3724
|
// Strip API metadata that should remain at root
|
|
3460
|
-
var _d = request, dataInsertMultipleRows = _d.dataInsertMultipleRows, cacheResults = _d.cacheResults, fetchDependencies = _d.fetchDependencies, debug = _d.debug, success = _d.success, error = _d.error, rest = tslib.__rest(_d, ["dataInsertMultipleRows", "cacheResults", "fetchDependencies", "debug", "success", "error"]);
|
|
3725
|
+
var _d = request, dataInsertMultipleRows = _d.dataInsertMultipleRows, cacheResults = _d.cacheResults, skipReactBootstrap = _d.skipReactBootstrap, fetchDependencies = _d.fetchDependencies, debug = _d.debug, success = _d.success, error = _d.error, rest = tslib.__rest(_d, ["dataInsertMultipleRows", "cacheResults", "skipReactBootstrap", "fetchDependencies", "debug", "success", "error"]);
|
|
3461
3726
|
// Map short primary keys to fully-qualified column names
|
|
3462
3727
|
var shortToFull = {};
|
|
3463
3728
|
for (var _e = 0, _f = Object.entries(restModel.COLUMNS || {}); _e < _f.length; _e++) {
|
|
@@ -3469,22 +3734,26 @@ function normalizeSingularRequest(requestMethod, request, restModel, removedPrim
|
|
|
3469
3734
|
var k = _a[0], v = _a[1];
|
|
3470
3735
|
return [(_b = shortToFull[k]) !== null && _b !== void 0 ? _b : k, v];
|
|
3471
3736
|
}));
|
|
3737
|
+
var pkWhereExpressions = Object.fromEntries(Object.entries(pkFullValues).map(function (_a) {
|
|
3738
|
+
var column = _a[0], value = _a[1];
|
|
3739
|
+
return [column, [C6Constants.EQUAL, [C6Constants.LIT, value]]];
|
|
3740
|
+
}));
|
|
3472
3741
|
if (requestMethod === C6Constants.GET) {
|
|
3473
3742
|
var normalized_1 = {
|
|
3474
|
-
WHERE: tslib.__assign({},
|
|
3743
|
+
WHERE: tslib.__assign({}, pkWhereExpressions),
|
|
3475
3744
|
};
|
|
3476
3745
|
// Preserve pagination if any was added previously
|
|
3477
3746
|
if (request[C6Constants.PAGINATION]) {
|
|
3478
3747
|
normalized_1[C6Constants.PAGINATION] = request[C6Constants.PAGINATION];
|
|
3479
3748
|
}
|
|
3480
|
-
return tslib.__assign(tslib.__assign({}, normalized_1), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
3749
|
+
return tslib.__assign(tslib.__assign({}, normalized_1), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, skipReactBootstrap: skipReactBootstrap, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
3481
3750
|
}
|
|
3482
3751
|
if (requestMethod === C6Constants.DELETE) {
|
|
3483
3752
|
var normalized_2 = (_a = {},
|
|
3484
3753
|
_a[C6Constants.DELETE] = true,
|
|
3485
|
-
_a.WHERE = tslib.__assign({},
|
|
3754
|
+
_a.WHERE = tslib.__assign({}, pkWhereExpressions),
|
|
3486
3755
|
_a);
|
|
3487
|
-
return tslib.__assign(tslib.__assign({}, normalized_2), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
3756
|
+
return tslib.__assign(tslib.__assign({}, normalized_2), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, skipReactBootstrap: skipReactBootstrap, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
3488
3757
|
}
|
|
3489
3758
|
// PUT
|
|
3490
3759
|
var updateBody = {};
|
|
@@ -3503,9 +3772,9 @@ function normalizeSingularRequest(requestMethod, request, restModel, removedPrim
|
|
|
3503
3772
|
}
|
|
3504
3773
|
var normalized = (_b = {},
|
|
3505
3774
|
_b[C6Constants.UPDATE] = updateBody,
|
|
3506
|
-
_b.WHERE = tslib.__assign({},
|
|
3775
|
+
_b.WHERE = tslib.__assign({}, pkWhereExpressions),
|
|
3507
3776
|
_b);
|
|
3508
|
-
return tslib.__assign(tslib.__assign({}, normalized), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
3777
|
+
return tslib.__assign(tslib.__assign({}, normalized), { dataInsertMultipleRows: dataInsertMultipleRows, cacheResults: cacheResults, skipReactBootstrap: skipReactBootstrap, fetchDependencies: fetchDependencies, debug: debug, success: success, error: error });
|
|
3509
3778
|
}
|
|
3510
3779
|
|
|
3511
3780
|
var allowListCache = new Map();
|
|
@@ -3688,6 +3957,38 @@ var compileSqlAllowList = function (allowListPath, entries) { return tslib.__awa
|
|
|
3688
3957
|
}); };
|
|
3689
3958
|
|
|
3690
3959
|
var SQL_ALLOWLIST_BLOCKED_CODE = "SQL_ALLOWLIST_BLOCKED";
|
|
3960
|
+
var fillRandomBytes = function (bytes) {
|
|
3961
|
+
var cryptoRef = globalThis.crypto;
|
|
3962
|
+
if (!cryptoRef || typeof cryptoRef.getRandomValues !== "function") {
|
|
3963
|
+
throw new Error("Secure random source unavailable: crypto.getRandomValues is required for UUID generation.");
|
|
3964
|
+
}
|
|
3965
|
+
cryptoRef.getRandomValues(bytes);
|
|
3966
|
+
};
|
|
3967
|
+
var generateUuidV7 = function () {
|
|
3968
|
+
var bytes = new Uint8Array(16);
|
|
3969
|
+
var random = new Uint8Array(10);
|
|
3970
|
+
fillRandomBytes(random);
|
|
3971
|
+
var timestampMs = Date.now();
|
|
3972
|
+
bytes[0] = Math.floor(timestampMs / 1099511627776) & 0xff; // 2^40
|
|
3973
|
+
bytes[1] = Math.floor(timestampMs / 4294967296) & 0xff; // 2^32
|
|
3974
|
+
bytes[2] = Math.floor(timestampMs / 16777216) & 0xff; // 2^24
|
|
3975
|
+
bytes[3] = Math.floor(timestampMs / 65536) & 0xff; // 2^16
|
|
3976
|
+
bytes[4] = Math.floor(timestampMs / 256) & 0xff; // 2^8
|
|
3977
|
+
bytes[5] = timestampMs & 0xff;
|
|
3978
|
+
// RFC 9562 UUIDv7 layout
|
|
3979
|
+
bytes[6] = 0x70 | (random[0] & 0x0f); // version 7 + rand_a high bits
|
|
3980
|
+
bytes[7] = random[1]; // rand_a low bits
|
|
3981
|
+
bytes[8] = 0x80 | (random[2] & 0x3f); // variant + rand_b high bits
|
|
3982
|
+
bytes[9] = random[3];
|
|
3983
|
+
bytes[10] = random[4];
|
|
3984
|
+
bytes[11] = random[5];
|
|
3985
|
+
bytes[12] = random[6];
|
|
3986
|
+
bytes[13] = random[7];
|
|
3987
|
+
bytes[14] = random[8];
|
|
3988
|
+
bytes[15] = random[9];
|
|
3989
|
+
var hex = Array.from(bytes, function (byte) { return byte.toString(16).padStart(2, "0"); }).join("");
|
|
3990
|
+
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));
|
|
3991
|
+
};
|
|
3691
3992
|
var createSqlAllowListBlockedError = function (args) {
|
|
3692
3993
|
var _a, _b;
|
|
3693
3994
|
var error = new Error("SQL statement is not permitted by allowlist (".concat(args.allowListPath, ")."));
|
|
@@ -3716,6 +4017,146 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3716
4017
|
})); };
|
|
3717
4018
|
return _this;
|
|
3718
4019
|
}
|
|
4020
|
+
SqlExecutor.prototype.getPostRequestRows = function () {
|
|
4021
|
+
var request = this.request;
|
|
4022
|
+
if (!request)
|
|
4023
|
+
return [];
|
|
4024
|
+
if (Array.isArray(request)) {
|
|
4025
|
+
return request;
|
|
4026
|
+
}
|
|
4027
|
+
if (Array.isArray(request.dataInsertMultipleRows)
|
|
4028
|
+
&& request.dataInsertMultipleRows.length > 0) {
|
|
4029
|
+
return request.dataInsertMultipleRows;
|
|
4030
|
+
}
|
|
4031
|
+
var verb = C6Constants.REPLACE in request ? C6Constants.REPLACE : C6Constants.INSERT;
|
|
4032
|
+
if (verb in request && request[verb] && typeof request[verb] === "object") {
|
|
4033
|
+
return [request[verb]];
|
|
4034
|
+
}
|
|
4035
|
+
if (typeof request === "object") {
|
|
4036
|
+
return [request];
|
|
4037
|
+
}
|
|
4038
|
+
return [];
|
|
4039
|
+
};
|
|
4040
|
+
SqlExecutor.prototype.getTypeValidationForColumn = function (shortKey, fullKey) {
|
|
4041
|
+
var _a, _b;
|
|
4042
|
+
var validation = (_a = this.config.restModel) === null || _a === void 0 ? void 0 : _a.TYPE_VALIDATION;
|
|
4043
|
+
if (!validation || typeof validation !== "object")
|
|
4044
|
+
return undefined;
|
|
4045
|
+
return (_b = validation[shortKey]) !== null && _b !== void 0 ? _b : validation[fullKey];
|
|
4046
|
+
};
|
|
4047
|
+
SqlExecutor.prototype.isUuidLikePrimaryColumn = function (columnDef) {
|
|
4048
|
+
var _a, _b;
|
|
4049
|
+
if (!columnDef || typeof columnDef !== "object")
|
|
4050
|
+
return false;
|
|
4051
|
+
if (columnDef.AUTO_INCREMENT === true)
|
|
4052
|
+
return false;
|
|
4053
|
+
var mysqlType = String((_a = columnDef.MYSQL_TYPE) !== null && _a !== void 0 ? _a : "").toLowerCase();
|
|
4054
|
+
var maxLength = String((_b = columnDef.MAX_LENGTH) !== null && _b !== void 0 ? _b : "").trim();
|
|
4055
|
+
if (mysqlType.includes("uuid"))
|
|
4056
|
+
return true;
|
|
4057
|
+
var isBinary16 = mysqlType.includes("binary")
|
|
4058
|
+
&& (maxLength === "16" || /\b16\b/.test(mysqlType) || mysqlType === "binary");
|
|
4059
|
+
var isUuidString = (mysqlType.includes("char") || mysqlType.includes("varchar"))
|
|
4060
|
+
&& (maxLength === "32" || maxLength === "36");
|
|
4061
|
+
return isBinary16 || isUuidString;
|
|
4062
|
+
};
|
|
4063
|
+
SqlExecutor.prototype.hasDefinedValue = function (value) {
|
|
4064
|
+
if (value === undefined || value === null)
|
|
4065
|
+
return false;
|
|
4066
|
+
if (typeof value === "string" && value.trim() === "")
|
|
4067
|
+
return false;
|
|
4068
|
+
return true;
|
|
4069
|
+
};
|
|
4070
|
+
SqlExecutor.prototype.generatePrimaryUuidValue = function (columnDef) {
|
|
4071
|
+
var _a, _b;
|
|
4072
|
+
var mysqlType = String((_a = columnDef.MYSQL_TYPE) !== null && _a !== void 0 ? _a : "").toLowerCase();
|
|
4073
|
+
var maxLength = String((_b = columnDef.MAX_LENGTH) !== null && _b !== void 0 ? _b : "").trim();
|
|
4074
|
+
var uuid = generateUuidV7();
|
|
4075
|
+
// BINARY(16) and CHAR/VARCHAR(32) commonly persist UUIDs as 32-hex.
|
|
4076
|
+
if (mysqlType.includes("binary") || maxLength === "32") {
|
|
4077
|
+
return uuid.replace(/-/g, "").toUpperCase();
|
|
4078
|
+
}
|
|
4079
|
+
return uuid;
|
|
4080
|
+
};
|
|
4081
|
+
SqlExecutor.prototype.assignMissingPostPrimaryUuids = function () {
|
|
4082
|
+
var _this = this;
|
|
4083
|
+
var _a, _b;
|
|
4084
|
+
if (this.config.requestMethod !== C6Constants.POST)
|
|
4085
|
+
return;
|
|
4086
|
+
var rows = this.getPostRequestRows();
|
|
4087
|
+
if (rows.length === 0)
|
|
4088
|
+
return;
|
|
4089
|
+
var columns = this.config.restModel.COLUMNS;
|
|
4090
|
+
var tableName = this.config.restModel.TABLE_NAME;
|
|
4091
|
+
var primaryShorts = (_a = this.config.restModel.PRIMARY_SHORT) !== null && _a !== void 0 ? _a : [];
|
|
4092
|
+
var primaryColumns = primaryShorts
|
|
4093
|
+
.map(function (shortKey) {
|
|
4094
|
+
var _a;
|
|
4095
|
+
var fullKey = (_a = Object.keys(columns).find(function (key) { return columns[key] === shortKey; })) !== null && _a !== void 0 ? _a : "".concat(tableName, ".").concat(shortKey);
|
|
4096
|
+
var columnDef = _this.getTypeValidationForColumn(shortKey, fullKey);
|
|
4097
|
+
return { shortKey: shortKey, fullKey: fullKey, columnDef: columnDef };
|
|
4098
|
+
})
|
|
4099
|
+
.filter(function (_a) {
|
|
4100
|
+
var columnDef = _a.columnDef;
|
|
4101
|
+
return _this.isUuidLikePrimaryColumn(columnDef);
|
|
4102
|
+
});
|
|
4103
|
+
if (primaryColumns.length === 0)
|
|
4104
|
+
return;
|
|
4105
|
+
for (var _i = 0, rows_1 = rows; _i < rows_1.length; _i++) {
|
|
4106
|
+
var row = rows_1[_i];
|
|
4107
|
+
if (!row || typeof row !== "object")
|
|
4108
|
+
continue;
|
|
4109
|
+
var useQualifiedKeyByDefault = Object.keys(row).some(function (key) { return key.includes("."); });
|
|
4110
|
+
for (var _c = 0, primaryColumns_1 = primaryColumns; _c < primaryColumns_1.length; _c++) {
|
|
4111
|
+
var primaryColumn = primaryColumns_1[_c];
|
|
4112
|
+
var existing = (_b = row[primaryColumn.shortKey]) !== null && _b !== void 0 ? _b : row[primaryColumn.fullKey];
|
|
4113
|
+
if (this.hasDefinedValue(existing))
|
|
4114
|
+
continue;
|
|
4115
|
+
var generated = this.generatePrimaryUuidValue(primaryColumn.columnDef);
|
|
4116
|
+
if (Object.prototype.hasOwnProperty.call(row, primaryColumn.shortKey)) {
|
|
4117
|
+
row[primaryColumn.shortKey] = generated;
|
|
4118
|
+
continue;
|
|
4119
|
+
}
|
|
4120
|
+
if (Object.prototype.hasOwnProperty.call(row, primaryColumn.fullKey)) {
|
|
4121
|
+
row[primaryColumn.fullKey] = generated;
|
|
4122
|
+
continue;
|
|
4123
|
+
}
|
|
4124
|
+
row[useQualifiedKeyByDefault ? primaryColumn.fullKey : primaryColumn.shortKey] = generated;
|
|
4125
|
+
}
|
|
4126
|
+
}
|
|
4127
|
+
};
|
|
4128
|
+
SqlExecutor.prototype.buildPostResponseRows = function (insertId) {
|
|
4129
|
+
var _this = this;
|
|
4130
|
+
var _a;
|
|
4131
|
+
var rows = this.getPostRequestRows();
|
|
4132
|
+
if (rows.length === 0)
|
|
4133
|
+
return [];
|
|
4134
|
+
var columns = this.config.restModel.COLUMNS;
|
|
4135
|
+
var validColumns = new Set(Object.values(columns));
|
|
4136
|
+
var pkShorts = (_a = this.config.restModel.PRIMARY_SHORT) !== null && _a !== void 0 ? _a : [];
|
|
4137
|
+
var now = new Date().toISOString();
|
|
4138
|
+
return rows.map(function (row, index) {
|
|
4139
|
+
var normalized = _this.normalizeRequestPayload(row !== null && row !== void 0 ? row : {});
|
|
4140
|
+
if (validColumns.has("changed_at") && normalized.changed_at === undefined) {
|
|
4141
|
+
normalized.changed_at = now;
|
|
4142
|
+
}
|
|
4143
|
+
if (validColumns.has("created_at") && normalized.created_at === undefined) {
|
|
4144
|
+
normalized.created_at = now;
|
|
4145
|
+
}
|
|
4146
|
+
if (validColumns.has("updated_at") && normalized.updated_at === undefined) {
|
|
4147
|
+
normalized.updated_at = now;
|
|
4148
|
+
}
|
|
4149
|
+
// When DB generated PK is numeric/autoincrement, expose it for the single-row insert.
|
|
4150
|
+
if (index === 0
|
|
4151
|
+
&& insertId !== undefined
|
|
4152
|
+
&& insertId !== null
|
|
4153
|
+
&& pkShorts.length === 1
|
|
4154
|
+
&& !_this.hasDefinedValue(normalized[pkShorts[0]])) {
|
|
4155
|
+
normalized[pkShorts[0]] = insertId;
|
|
4156
|
+
}
|
|
4157
|
+
return normalized;
|
|
4158
|
+
});
|
|
4159
|
+
};
|
|
3719
4160
|
SqlExecutor.prototype.resolveSqlLogMethod = function (method, sql) {
|
|
3720
4161
|
var _a;
|
|
3721
4162
|
var token = (_a = sql.trim().split(/\s+/, 1)[0]) === null || _a === void 0 ? void 0 : _a.toUpperCase();
|
|
@@ -3754,6 +4195,7 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3754
4195
|
// Surface normalization errors early
|
|
3755
4196
|
throw e;
|
|
3756
4197
|
}
|
|
4198
|
+
this.assignMissingPostPrimaryUuids();
|
|
3757
4199
|
logContext = getLogContext(this.config, this.request);
|
|
3758
4200
|
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] \u25B6\uFE0F Executing ".concat(method, " on table \"").concat(TABLE_NAME, "\""));
|
|
3759
4201
|
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] \uD83E\uDDE9 Request:", this.request);
|
|
@@ -3880,6 +4322,7 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3880
4322
|
C6Constants.REPLACE,
|
|
3881
4323
|
"dataInsertMultipleRows",
|
|
3882
4324
|
"cacheResults",
|
|
4325
|
+
"skipReactBootstrap",
|
|
3883
4326
|
"fetchDependencies",
|
|
3884
4327
|
"debug",
|
|
3885
4328
|
"success",
|
|
@@ -3963,9 +4406,10 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3963
4406
|
}
|
|
3964
4407
|
}
|
|
3965
4408
|
if (value !== undefined) {
|
|
3966
|
-
pkValues[pkShort] = value;
|
|
4409
|
+
pkValues[pkShort] = this_1.unwrapPrimaryKeyValue(value);
|
|
3967
4410
|
}
|
|
3968
4411
|
};
|
|
4412
|
+
var this_1 = this;
|
|
3969
4413
|
for (var _i = 0, primaryShorts_1 = primaryShorts; _i < primaryShorts_1.length; _i++) {
|
|
3970
4414
|
var pkShort = primaryShorts_1[_i];
|
|
3971
4415
|
_loop_1(pkShort);
|
|
@@ -3975,6 +4419,26 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3975
4419
|
}
|
|
3976
4420
|
return Object.keys(pkValues).length > 0 ? pkValues : null;
|
|
3977
4421
|
};
|
|
4422
|
+
SqlExecutor.prototype.unwrapPrimaryKeyValue = function (value) {
|
|
4423
|
+
if (!Array.isArray(value))
|
|
4424
|
+
return value;
|
|
4425
|
+
if (value.length === 2) {
|
|
4426
|
+
var head = value[0], tail = value[1];
|
|
4427
|
+
if (head === C6Constants.EQUAL) {
|
|
4428
|
+
return this.unwrapPrimaryKeyValue(tail);
|
|
4429
|
+
}
|
|
4430
|
+
if (head === C6Constants.LIT || head === C6Constants.PARAM) {
|
|
4431
|
+
return tail;
|
|
4432
|
+
}
|
|
4433
|
+
}
|
|
4434
|
+
if (value.length === 3) {
|
|
4435
|
+
var operator = value[1], right = value[2];
|
|
4436
|
+
if (operator === C6Constants.EQUAL) {
|
|
4437
|
+
return this.unwrapPrimaryKeyValue(right);
|
|
4438
|
+
}
|
|
4439
|
+
}
|
|
4440
|
+
return value;
|
|
4441
|
+
};
|
|
3978
4442
|
SqlExecutor.prototype.extractPrimaryKeyValuesFromData = function (data) {
|
|
3979
4443
|
if (!data)
|
|
3980
4444
|
return null;
|
|
@@ -4103,7 +4567,7 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
4103
4567
|
};
|
|
4104
4568
|
SqlExecutor.prototype.runQuery = function () {
|
|
4105
4569
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
4106
|
-
var method, tableName, logContext, cacheResults, cacheRequestData, requestArgumentsSerialized, evictFromCache, cachedRequest, cachedData, sqlExecution, sqlMethod, queryPromise, cacheRequest, cacheResponse;
|
|
4570
|
+
var method, tableName, logContext, cacheResults, cacheAllowListStatus, cacheRequestData, requestArgumentsSerialized, evictFromCache, cachedRequest, cachedData, sqlExecution, sqlMethod, queryPromise, cacheRequest, cacheResponse;
|
|
4107
4571
|
var _this = this;
|
|
4108
4572
|
var _a, _b;
|
|
4109
4573
|
return tslib.__generator(this, function (_c) {
|
|
@@ -4114,6 +4578,9 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
4114
4578
|
logContext = getLogContext(this.config, this.request);
|
|
4115
4579
|
cacheResults = method === C6Constants.GET
|
|
4116
4580
|
&& ((_a = this.request.cacheResults) !== null && _a !== void 0 ? _a : true);
|
|
4581
|
+
cacheAllowListStatus = this.config.sqlAllowListPath
|
|
4582
|
+
? "allowed"
|
|
4583
|
+
: "not verified";
|
|
4117
4584
|
cacheRequestData = cacheResults
|
|
4118
4585
|
? JSON.parse(JSON.stringify((_b = this.request) !== null && _b !== void 0 ? _b : {}))
|
|
4119
4586
|
: undefined;
|
|
@@ -4121,10 +4588,10 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
4121
4588
|
? sortAndSerializeQueryObject(tableName, cacheRequestData !== null && cacheRequestData !== void 0 ? cacheRequestData : {})
|
|
4122
4589
|
: undefined;
|
|
4123
4590
|
evictFromCache = method === C6Constants.GET && cacheResults && cacheRequestData
|
|
4124
|
-
? function () { return evictCacheEntry(method, tableName, cacheRequestData, logContext); }
|
|
4591
|
+
? function () { return evictCacheEntry(method, tableName, cacheRequestData, logContext, cacheAllowListStatus); }
|
|
4125
4592
|
: undefined;
|
|
4126
4593
|
if (!cacheResults) return [3 /*break*/, 2];
|
|
4127
|
-
cachedRequest = checkCache(method, tableName, cacheRequestData, logContext);
|
|
4594
|
+
cachedRequest = checkCache(method, tableName, cacheRequestData, logContext, cacheAllowListStatus);
|
|
4128
4595
|
if (!cachedRequest) return [3 /*break*/, 2];
|
|
4129
4596
|
return [4 /*yield*/, cachedRequest];
|
|
4130
4597
|
case 1:
|
|
@@ -4160,6 +4627,7 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
4160
4627
|
setCache(method, tableName, cacheRequestData, {
|
|
4161
4628
|
requestArgumentsSerialized: requestArgumentsSerialized,
|
|
4162
4629
|
request: cacheRequest,
|
|
4630
|
+
allowListStatus: cacheAllowListStatus,
|
|
4163
4631
|
});
|
|
4164
4632
|
return [4 /*yield*/, cacheRequest];
|
|
4165
4633
|
case 5:
|
|
@@ -4167,6 +4635,7 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
4167
4635
|
setCache(method, tableName, cacheRequestData, {
|
|
4168
4636
|
requestArgumentsSerialized: requestArgumentsSerialized,
|
|
4169
4637
|
request: cacheRequest,
|
|
4638
|
+
allowListStatus: cacheAllowListStatus,
|
|
4170
4639
|
response: cacheResponse,
|
|
4171
4640
|
final: true,
|
|
4172
4641
|
});
|
|
@@ -4210,7 +4679,9 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
4210
4679
|
return {
|
|
4211
4680
|
affected: result.affectedRows,
|
|
4212
4681
|
insertId: result.insertId,
|
|
4213
|
-
rest:
|
|
4682
|
+
rest: method === C6Constants.POST
|
|
4683
|
+
? this.buildPostResponseRows(result.insertId)
|
|
4684
|
+
: [],
|
|
4214
4685
|
sql: { sql: sqlExecution.sql, values: sqlExecution.values },
|
|
4215
4686
|
};
|
|
4216
4687
|
};
|
|
@@ -4605,14 +5076,17 @@ exports.POST = POST;
|
|
|
4605
5076
|
exports.PUT = PUT;
|
|
4606
5077
|
exports.PaginationBuilder = PaginationBuilder;
|
|
4607
5078
|
exports.PostQueryBuilder = PostQueryBuilder;
|
|
5079
|
+
exports.SQL_KNOWN_FUNCTIONS = SQL_KNOWN_FUNCTIONS;
|
|
4608
5080
|
exports.SelectQueryBuilder = SelectQueryBuilder;
|
|
4609
5081
|
exports.SqlExecutor = SqlExecutor;
|
|
4610
5082
|
exports.TestRestfulResponse = TestRestfulResponse;
|
|
4611
5083
|
exports.UpdateQueryBuilder = UpdateQueryBuilder;
|
|
5084
|
+
exports.alias = alias;
|
|
4612
5085
|
exports.apiRequestCache = apiRequestCache;
|
|
4613
5086
|
exports.applyLogLevelDefaults = applyLogLevelDefaults;
|
|
4614
5087
|
exports.axiosInstance = axiosInstance;
|
|
4615
5088
|
exports.bbox = bbox;
|
|
5089
|
+
exports.call = call;
|
|
4616
5090
|
exports.carbonNodeQsStringify = carbonNodeQsStringify;
|
|
4617
5091
|
exports.checkAllRequestsComplete = checkAllRequestsComplete;
|
|
4618
5092
|
exports.checkCache = checkCache;
|
|
@@ -4625,10 +5099,12 @@ exports.convertHexIfBinary = convertHexIfBinary;
|
|
|
4625
5099
|
exports.derivedTable = derivedTable;
|
|
4626
5100
|
exports.determineRuntimeJsType = determineRuntimeJsType;
|
|
4627
5101
|
exports.distSphere = distSphere;
|
|
5102
|
+
exports.distinct = distinct;
|
|
4628
5103
|
exports.error = error;
|
|
4629
5104
|
exports.evictCacheEntry = evictCacheEntry;
|
|
4630
5105
|
exports.extractSqlEntries = extractSqlEntries;
|
|
4631
5106
|
exports.fieldEq = fieldEq;
|
|
5107
|
+
exports.fn = fn;
|
|
4632
5108
|
exports.getEnv = getEnv;
|
|
4633
5109
|
exports.getEnvBool = getEnvBool;
|
|
4634
5110
|
exports.getEnvDebug = getEnvDebug;
|
|
@@ -4642,6 +5118,7 @@ exports.isLocal = isLocal;
|
|
|
4642
5118
|
exports.isNode = isNode;
|
|
4643
5119
|
exports.isTest = isTest;
|
|
4644
5120
|
exports.isVerbose = isVerbose;
|
|
5121
|
+
exports.lit = lit;
|
|
4645
5122
|
exports.loadSqlAllowList = loadSqlAllowList;
|
|
4646
5123
|
exports.logSql = logSql;
|
|
4647
5124
|
exports.logWithLevel = logWithLevel;
|
|
@@ -4650,6 +5127,7 @@ exports.normalizeSql = normalizeSql;
|
|
|
4650
5127
|
exports.notifyToast = notifyToast;
|
|
4651
5128
|
exports.onError = onError;
|
|
4652
5129
|
exports.onSuccess = onSuccess;
|
|
5130
|
+
exports.order = order;
|
|
4653
5131
|
exports.parseLogLevel = parseLogLevel;
|
|
4654
5132
|
exports.removeInvalidKeys = removeInvalidKeys;
|
|
4655
5133
|
exports.removePrefixIfExists = removePrefixIfExists;
|
|
@@ -4658,6 +5136,7 @@ exports.resolveLogLevel = resolveLogLevel;
|
|
|
4658
5136
|
exports.restExpressRequest = restExpressRequest;
|
|
4659
5137
|
exports.restOrm = restOrm;
|
|
4660
5138
|
exports.restRequest = restRequest;
|
|
5139
|
+
exports.serializeSqlExpression = serializeSqlExpression;
|
|
4661
5140
|
exports.setCache = setCache;
|
|
4662
5141
|
exports.setToastHandler = setToastHandler;
|
|
4663
5142
|
exports.shouldLog = shouldLog;
|