@carbonorm/carbonnode 6.0.6 → 6.0.8
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 +537 -130
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.esm.js +525 -130
- package/dist/index.esm.js.map +1 -1
- package/dist/types/ormInterfaces.d.ts +1 -0
- package/dist/utils/colorSql.d.ts +1 -0
- package/dist/utils/logLevel.d.ts +32 -0
- package/dist/utils/logSql.d.ts +2 -0
- package/dist/utils/logger.d.ts +0 -3
- package/dist/utils/versionColor.d.ts +6 -0
- package/dist/variables/getEnv.d.ts +10 -0
- package/dist/variables/isTest.d.ts +1 -1
- package/dist/variables/isVerbose.d.ts +1 -1
- package/package.json +3 -1
- package/src/__tests__/fixtures/c6.fixture.ts +5 -0
- package/src/__tests__/logLevel.test.ts +54 -0
- package/src/__tests__/logSql.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.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__/sqlBuilders.test.ts +21 -1
- package/src/__tests__/versionColor.test.ts +42 -0
- package/src/api/convertForRequestBody.ts +8 -1
- package/src/api/restRequest.ts +12 -12
- package/src/executors/Executor.ts +11 -2
- package/src/executors/HttpExecutor.ts +92 -54
- package/src/executors/SqlExecutor.ts +151 -40
- package/src/handlers/ExpressHandler.ts +7 -1
- package/src/index.ts +8 -1
- package/src/orm/builders/AggregateBuilder.ts +13 -2
- package/src/orm/builders/ConditionBuilder.ts +13 -2
- package/src/orm/builders/JoinBuilder.ts +7 -1
- package/src/orm/builders/PaginationBuilder.ts +7 -1
- package/src/orm/queries/DeleteQueryBuilder.ts +4 -0
- package/src/orm/queries/PostQueryBuilder.ts +4 -0
- package/src/orm/queries/SelectQueryBuilder.ts +3 -1
- package/src/orm/queries/UpdateQueryBuilder.ts +4 -0
- package/src/types/ormInterfaces.ts +1 -0
- package/src/utils/apiHelpers.ts +4 -1
- package/src/utils/cacheManager.ts +13 -7
- package/src/utils/colorSql.ts +112 -0
- package/src/utils/logLevel.ts +157 -0
- package/src/utils/logSql.ts +59 -0
- package/src/utils/logger.ts +7 -1
- package/src/utils/testHelpers.ts +2 -1
- package/src/utils/versionColor.ts +54 -0
- package/src/variables/getEnv.ts +73 -0
- package/src/variables/isLocal.ts +2 -2
- package/src/variables/isTest.ts +4 -4
- package/src/variables/isVerbose.ts +4 -5
- package/dist/variables/getEnvVar.d.ts +0 -1
- package/src/variables/getEnvVar.ts +0 -15
package/dist/index.cjs.js
CHANGED
|
@@ -331,6 +331,210 @@ var C6Constants = {
|
|
|
331
331
|
};
|
|
332
332
|
var C6C = C6Constants;
|
|
333
333
|
|
|
334
|
+
/** biome-ignore-all lint/suspicious/noExplicitAny: working with global browser objects */
|
|
335
|
+
function getRuntimeEnv(key) {
|
|
336
|
+
var _a;
|
|
337
|
+
return typeof window !== "undefined" && ((_a = window.__ENV__) === null || _a === void 0 ? void 0 : _a[key]);
|
|
338
|
+
}
|
|
339
|
+
// Do not import anything here
|
|
340
|
+
function getViteEnv(key) {
|
|
341
|
+
var _a;
|
|
342
|
+
// @ts-expect-error
|
|
343
|
+
return typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs.js', document.baseURI).href)) }) !== "undefined" && ((_a = undefined) === null || _a === void 0 ? void 0 : _a[key]);
|
|
344
|
+
}
|
|
345
|
+
function getEnv(key, fallback) {
|
|
346
|
+
var _a;
|
|
347
|
+
try {
|
|
348
|
+
if (typeof process !== "undefined" && ((_a = process.env) === null || _a === void 0 ? void 0 : _a[key]) !== undefined) {
|
|
349
|
+
return process.env[key];
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
catch (_b) { }
|
|
353
|
+
try {
|
|
354
|
+
var viteEnv = getViteEnv(key);
|
|
355
|
+
if (viteEnv !== undefined)
|
|
356
|
+
return viteEnv;
|
|
357
|
+
}
|
|
358
|
+
catch (_c) { }
|
|
359
|
+
var runtimeEnv = getRuntimeEnv(key);
|
|
360
|
+
if (runtimeEnv !== undefined)
|
|
361
|
+
return runtimeEnv;
|
|
362
|
+
if (fallback !== undefined)
|
|
363
|
+
return fallback;
|
|
364
|
+
throw new Error("Missing environment variable: ".concat(key));
|
|
365
|
+
}
|
|
366
|
+
function getEnvBool(key, fallback) {
|
|
367
|
+
if (fallback === void 0) { fallback = false; }
|
|
368
|
+
var raw = getEnv(key, fallback);
|
|
369
|
+
var v = String(raw).trim().toLowerCase();
|
|
370
|
+
return (v === "true" ||
|
|
371
|
+
v === "1" ||
|
|
372
|
+
v === "yes" ||
|
|
373
|
+
v === "y" ||
|
|
374
|
+
v === "on" ||
|
|
375
|
+
v === "enabled");
|
|
376
|
+
}
|
|
377
|
+
function getEnvDebug(key, fallback) {
|
|
378
|
+
var _a;
|
|
379
|
+
try {
|
|
380
|
+
var viteEnv = getViteEnv(key);
|
|
381
|
+
if (viteEnv !== undefined) {
|
|
382
|
+
return { key: key, value: viteEnv, source: "vite" };
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
catch (_b) { }
|
|
386
|
+
var runtimeEnv = getRuntimeEnv(key);
|
|
387
|
+
if (runtimeEnv !== undefined) {
|
|
388
|
+
return { key: key, value: runtimeEnv, source: "runtime" };
|
|
389
|
+
}
|
|
390
|
+
if (typeof process !== "undefined" && ((_a = process.env) === null || _a === void 0 ? void 0 : _a[key]) !== undefined) {
|
|
391
|
+
return { key: key, value: process.env[key], source: "process" };
|
|
392
|
+
}
|
|
393
|
+
if (fallback !== undefined) {
|
|
394
|
+
return { key: key, value: fallback, source: "fallback" };
|
|
395
|
+
}
|
|
396
|
+
return { key: key, value: undefined, source: "missing" };
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
exports.LogLevel = void 0;
|
|
400
|
+
(function (LogLevel) {
|
|
401
|
+
LogLevel[LogLevel["NONE"] = 0] = "NONE";
|
|
402
|
+
LogLevel[LogLevel["ERROR"] = 1] = "ERROR";
|
|
403
|
+
LogLevel[LogLevel["WARN"] = 2] = "WARN";
|
|
404
|
+
LogLevel[LogLevel["INFO"] = 3] = "INFO";
|
|
405
|
+
LogLevel[LogLevel["DEBUG"] = 4] = "DEBUG";
|
|
406
|
+
LogLevel[LogLevel["TRACE"] = 5] = "TRACE";
|
|
407
|
+
})(exports.LogLevel || (exports.LogLevel = {}));
|
|
408
|
+
var LOG_LEVEL_KEYS = ["LOG_LEVEL", "REACT_APP_LOG_LEVEL", "VITE_LOG_LEVEL"];
|
|
409
|
+
var VERBOSE_KEYS = ["VERBOSE", "REACT_APP_VERBOSE", "VITE_VERBOSE"];
|
|
410
|
+
var TRUE_VALUES = new Set(["true", "1", "yes", "y", "on", "enabled"]);
|
|
411
|
+
var FALSE_VALUES = new Set(["false", "0", "no", "n", "off", "disabled"]);
|
|
412
|
+
var clampLevel = function (level) {
|
|
413
|
+
if (level <= exports.LogLevel.NONE)
|
|
414
|
+
return exports.LogLevel.NONE;
|
|
415
|
+
if (level >= exports.LogLevel.TRACE)
|
|
416
|
+
return exports.LogLevel.TRACE;
|
|
417
|
+
return level;
|
|
418
|
+
};
|
|
419
|
+
var parseBoolean = function (value) {
|
|
420
|
+
if (typeof value === "boolean")
|
|
421
|
+
return value;
|
|
422
|
+
if (typeof value === "number")
|
|
423
|
+
return value !== 0;
|
|
424
|
+
if (typeof value !== "string")
|
|
425
|
+
return undefined;
|
|
426
|
+
var normalized = value.trim().toLowerCase();
|
|
427
|
+
if (TRUE_VALUES.has(normalized))
|
|
428
|
+
return true;
|
|
429
|
+
if (FALSE_VALUES.has(normalized))
|
|
430
|
+
return false;
|
|
431
|
+
return undefined;
|
|
432
|
+
};
|
|
433
|
+
var parseLogLevel = function (value) {
|
|
434
|
+
if (value === null || value === undefined)
|
|
435
|
+
return undefined;
|
|
436
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
437
|
+
return clampLevel(Math.round(value));
|
|
438
|
+
}
|
|
439
|
+
if (typeof value !== "string")
|
|
440
|
+
return undefined;
|
|
441
|
+
var raw = value.trim();
|
|
442
|
+
if (!raw)
|
|
443
|
+
return undefined;
|
|
444
|
+
if (/^-?\d+(\.\d+)?$/.test(raw)) {
|
|
445
|
+
return clampLevel(Math.round(Number(raw)));
|
|
446
|
+
}
|
|
447
|
+
switch (raw.toUpperCase()) {
|
|
448
|
+
case "NONE":
|
|
449
|
+
case "OFF":
|
|
450
|
+
case "SILENT":
|
|
451
|
+
return exports.LogLevel.NONE;
|
|
452
|
+
case "ERROR":
|
|
453
|
+
case "ERR":
|
|
454
|
+
return exports.LogLevel.ERROR;
|
|
455
|
+
case "WARN":
|
|
456
|
+
case "WARNING":
|
|
457
|
+
return exports.LogLevel.WARN;
|
|
458
|
+
case "INFO":
|
|
459
|
+
return exports.LogLevel.INFO;
|
|
460
|
+
case "DEBUG":
|
|
461
|
+
return exports.LogLevel.DEBUG;
|
|
462
|
+
case "TRACE":
|
|
463
|
+
return exports.LogLevel.TRACE;
|
|
464
|
+
default:
|
|
465
|
+
return undefined;
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
var getEnvLogLevel = function () {
|
|
469
|
+
for (var _i = 0, LOG_LEVEL_KEYS_1 = LOG_LEVEL_KEYS; _i < LOG_LEVEL_KEYS_1.length; _i++) {
|
|
470
|
+
var key = LOG_LEVEL_KEYS_1[_i];
|
|
471
|
+
var _a = getEnvDebug(key), value = _a.value, source = _a.source;
|
|
472
|
+
if (source !== "missing") {
|
|
473
|
+
var parsed = parseLogLevel(value);
|
|
474
|
+
if (parsed !== undefined)
|
|
475
|
+
return parsed;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
for (var _b = 0, VERBOSE_KEYS_1 = VERBOSE_KEYS; _b < VERBOSE_KEYS_1.length; _b++) {
|
|
479
|
+
var key = VERBOSE_KEYS_1[_b];
|
|
480
|
+
var _c = getEnvDebug(key), value = _c.value, source = _c.source;
|
|
481
|
+
if (source !== "missing") {
|
|
482
|
+
var parsed = parseBoolean(value);
|
|
483
|
+
if (parsed !== undefined) {
|
|
484
|
+
return parsed ? exports.LogLevel.DEBUG : exports.LogLevel.WARN;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
return undefined;
|
|
489
|
+
};
|
|
490
|
+
var resolveLogLevel = function (context) {
|
|
491
|
+
var _a, _b, _c;
|
|
492
|
+
var configured = parseLogLevel(context === null || context === void 0 ? void 0 : context.logLevel);
|
|
493
|
+
var verbose = context === null || context === void 0 ? void 0 : context.verbose;
|
|
494
|
+
var base = (_b = (_a = configured !== null && configured !== void 0 ? configured : (verbose !== undefined && verbose !== null
|
|
495
|
+
? (verbose ? exports.LogLevel.DEBUG : exports.LogLevel.WARN)
|
|
496
|
+
: undefined)) !== null && _a !== void 0 ? _a : getEnvLogLevel()) !== null && _b !== void 0 ? _b : exports.LogLevel.WARN;
|
|
497
|
+
if (((_c = context === null || context === void 0 ? void 0 : context.request) === null || _c === void 0 ? void 0 : _c.debug) && base < exports.LogLevel.DEBUG) {
|
|
498
|
+
return exports.LogLevel.DEBUG;
|
|
499
|
+
}
|
|
500
|
+
return base;
|
|
501
|
+
};
|
|
502
|
+
var shouldLog = function (requiredLevel, context) {
|
|
503
|
+
return resolveLogLevel(context) >= requiredLevel;
|
|
504
|
+
};
|
|
505
|
+
var applyLogLevelDefaults = function (config, request) {
|
|
506
|
+
var _a;
|
|
507
|
+
if (config.logLevel === null || config.logLevel === undefined) {
|
|
508
|
+
var resolved = resolveLogLevel({
|
|
509
|
+
logLevel: config.logLevel,
|
|
510
|
+
verbose: config.verbose,
|
|
511
|
+
request: request !== null && request !== void 0 ? request : undefined,
|
|
512
|
+
});
|
|
513
|
+
config.logLevel = resolved;
|
|
514
|
+
return resolved;
|
|
515
|
+
}
|
|
516
|
+
return (_a = parseLogLevel(config.logLevel)) !== null && _a !== void 0 ? _a : exports.LogLevel.WARN;
|
|
517
|
+
};
|
|
518
|
+
var getLogContext = function (config, request) {
|
|
519
|
+
var _a, _b;
|
|
520
|
+
if (!config && !request)
|
|
521
|
+
return undefined;
|
|
522
|
+
return {
|
|
523
|
+
logLevel: (_a = config === null || config === void 0 ? void 0 : config.logLevel) !== null && _a !== void 0 ? _a : undefined,
|
|
524
|
+
verbose: (_b = config === null || config === void 0 ? void 0 : config.verbose) !== null && _b !== void 0 ? _b : undefined,
|
|
525
|
+
request: request !== null && request !== void 0 ? request : undefined,
|
|
526
|
+
};
|
|
527
|
+
};
|
|
528
|
+
var logWithLevel = function (requiredLevel, context, logger) {
|
|
529
|
+
var args = [];
|
|
530
|
+
for (var _i = 3; _i < arguments.length; _i++) {
|
|
531
|
+
args[_i - 3] = arguments[_i];
|
|
532
|
+
}
|
|
533
|
+
if (shouldLog(requiredLevel, context)) {
|
|
534
|
+
logger.apply(void 0, args);
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
|
|
334
538
|
function convertForRequestBody (restfulObject, tableName, C6, regexErrorHandler) {
|
|
335
539
|
if (regexErrorHandler === void 0) { regexErrorHandler = alert; }
|
|
336
540
|
var payload = {};
|
|
@@ -338,7 +542,7 @@ function convertForRequestBody (restfulObject, tableName, C6, regexErrorHandler)
|
|
|
338
542
|
var tableDefinitions = tableNames.map(function (name) {
|
|
339
543
|
var tableDefinition = Object.values(C6.TABLES).find(function (t) { return t.TABLE_NAME === name; });
|
|
340
544
|
if (!tableDefinition) {
|
|
341
|
-
console.error
|
|
545
|
+
logWithLevel(exports.LogLevel.ERROR, undefined, console.error, "Table name (".concat(name, ") is not found in the C6.TABLES object."), C6.TABLES);
|
|
342
546
|
throw new Error("Table name (".concat(name, ") is not found in the C6.TABLES object."));
|
|
343
547
|
}
|
|
344
548
|
return tableDefinition;
|
|
@@ -434,58 +638,36 @@ var isNode = function () {
|
|
|
434
638
|
return typeof process !== 'undefined' && !!((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node);
|
|
435
639
|
};
|
|
436
640
|
|
|
437
|
-
function getEnvVar(key, fallback) {
|
|
438
|
-
if (fallback === void 0) { fallback = ''; }
|
|
439
|
-
// Vite-style injection
|
|
440
|
-
// @ts-ignore
|
|
441
|
-
if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs.js', document.baseURI).href)) }) !== 'undefined' && undefined && key in undefined) {
|
|
442
|
-
// @ts-ignore
|
|
443
|
-
return undefined[key];
|
|
444
|
-
}
|
|
445
|
-
// Node or SSR
|
|
446
|
-
if (typeof process !== 'undefined' && process.env && key in process.env) {
|
|
447
|
-
return process.env[key];
|
|
448
|
-
}
|
|
449
|
-
return fallback;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
function isVerbose () {
|
|
453
|
-
var envVerbose = getEnvVar('VERBOSE') || getEnvVar('REACT_APP_VERBOSE') || getEnvVar('VITE_VERBOSE') || '';
|
|
454
|
-
return ['true', '1', 'yes', 'on'].includes(envVerbose.toLowerCase());
|
|
455
|
-
}
|
|
456
|
-
|
|
457
641
|
/**
|
|
458
642
|
* Facade: routes API calls to SQL or HTTP executors based on runtime context.
|
|
459
643
|
*/
|
|
460
644
|
function restRequest(configX) {
|
|
461
645
|
var _this = this;
|
|
462
646
|
return function (request) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
463
|
-
var config, SqlExecutor, executor, HttpExecutor, http;
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
switch (_b.label) {
|
|
647
|
+
var config, logContext, SqlExecutor, executor, HttpExecutor, http;
|
|
648
|
+
return tslib.__generator(this, function (_a) {
|
|
649
|
+
switch (_a.label) {
|
|
467
650
|
case 0:
|
|
468
651
|
config = typeof configX === "function" ? configX() : configX;
|
|
469
|
-
(
|
|
470
|
-
|
|
471
|
-
if (config.
|
|
472
|
-
|
|
652
|
+
applyLogLevelDefaults(config, request);
|
|
653
|
+
logContext = getLogContext(config, request);
|
|
654
|
+
if (!config.mysqlPool && !config.axios) {
|
|
655
|
+
throw new Error("No execution method available: neither mysqlPool nor axios instance provided in config.");
|
|
473
656
|
}
|
|
657
|
+
if (!config.mysqlPool) return [3 /*break*/, 2];
|
|
658
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "Using SQL Executor");
|
|
474
659
|
return [4 /*yield*/, Promise.resolve().then(function () { return SqlExecutor$1; })];
|
|
475
660
|
case 1:
|
|
476
|
-
SqlExecutor = (
|
|
661
|
+
SqlExecutor = (_a.sent()).SqlExecutor;
|
|
477
662
|
executor = new SqlExecutor(config, request);
|
|
478
663
|
return [2 /*return*/, executor.execute()];
|
|
479
664
|
case 2:
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
hasPool: !!config.mysqlPool
|
|
484
|
-
});
|
|
485
|
-
}
|
|
665
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "Using HTTP Executor", {
|
|
666
|
+
isNode: isNode(),
|
|
667
|
+
});
|
|
486
668
|
return [4 /*yield*/, Promise.resolve().then(function () { return HttpExecutor$1; })];
|
|
487
669
|
case 3:
|
|
488
|
-
HttpExecutor = (
|
|
670
|
+
HttpExecutor = (_a.sent()).HttpExecutor;
|
|
489
671
|
http = new HttpExecutor(config, request);
|
|
490
672
|
return [2 /*return*/, http.execute()];
|
|
491
673
|
}
|
|
@@ -522,10 +704,11 @@ var Executor = /** @class */ (function () {
|
|
|
522
704
|
this.config = config;
|
|
523
705
|
this.request = request;
|
|
524
706
|
this.useNamedParams = useNamedParams;
|
|
707
|
+
applyLogLevelDefaults(this.config, this.request);
|
|
525
708
|
}
|
|
526
709
|
Executor.prototype.runLifecycleHooks = function (phase, args) {
|
|
527
710
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
528
|
-
var lifecycleGroup, _i, _a, _b, key, fn, err_1;
|
|
711
|
+
var lifecycleGroup, logContext, _i, _a, _b, key, fn, err_1;
|
|
529
712
|
var _c;
|
|
530
713
|
return tslib.__generator(this, function (_d) {
|
|
531
714
|
switch (_d.label) {
|
|
@@ -533,13 +716,14 @@ var Executor = /** @class */ (function () {
|
|
|
533
716
|
lifecycleGroup = (_c = this.config.restModel.LIFECYCLE_HOOKS[this.config.requestMethod]) === null || _c === void 0 ? void 0 : _c[phase];
|
|
534
717
|
if (!lifecycleGroup)
|
|
535
718
|
return [2 /*return*/];
|
|
719
|
+
logContext = getLogContext(this.config, args.request);
|
|
536
720
|
_i = 0, _a = Object.entries(lifecycleGroup);
|
|
537
721
|
_d.label = 1;
|
|
538
722
|
case 1:
|
|
539
723
|
if (!(_i < _a.length)) return [3 /*break*/, 6];
|
|
540
724
|
_b = _a[_i], key = _b[0], fn = _b[1];
|
|
541
725
|
if (!(typeof fn === "function")) return [3 /*break*/, 5];
|
|
542
|
-
if (
|
|
726
|
+
if (shouldLog(exports.LogLevel.DEBUG, logContext)) {
|
|
543
727
|
console.groupCollapsed("[LIFECYCLE] ".concat(this.config.requestMethod, ".").concat(String(phase), ":").concat(key));
|
|
544
728
|
console.log("config:", args.config);
|
|
545
729
|
console.log("request:", args.request);
|
|
@@ -559,7 +743,7 @@ var Executor = /** @class */ (function () {
|
|
|
559
743
|
return [3 /*break*/, 5];
|
|
560
744
|
case 4:
|
|
561
745
|
err_1 = _d.sent();
|
|
562
|
-
console.error
|
|
746
|
+
logWithLevel(exports.LogLevel.ERROR, logContext, console.error, "[LIFECYCLE ERROR] ".concat(this.config.requestMethod, ".").concat(String(phase), ":").concat(key), err_1);
|
|
563
747
|
throw err_1;
|
|
564
748
|
case 5:
|
|
565
749
|
_i++;
|
|
@@ -573,13 +757,13 @@ var Executor = /** @class */ (function () {
|
|
|
573
757
|
}());
|
|
574
758
|
|
|
575
759
|
function isLocal () {
|
|
576
|
-
return
|
|
760
|
+
return getEnv('NODE_ENV', '') === 'development';
|
|
577
761
|
}
|
|
578
762
|
|
|
579
763
|
function isTest () {
|
|
580
|
-
return
|
|
581
|
-
||
|
|
582
|
-
||
|
|
764
|
+
return getEnv('JEST_WORKER_ID', null) || getEnv('NODE_ENV', "") === 'test'
|
|
765
|
+
|| getEnvBool('REACT_APP_TEST', false) || getEnvBool('VITE_TEST', false)
|
|
766
|
+
|| getEnv('MODE', '') === 'test' || getEnvBool('VITE_TEST_MODE', false);
|
|
583
767
|
}
|
|
584
768
|
|
|
585
769
|
exports.eFetchDependencies = void 0;
|
|
@@ -667,7 +851,9 @@ function removeInvalidKeys(request, c6Tables) {
|
|
|
667
851
|
intersection[key] = request[key];
|
|
668
852
|
}
|
|
669
853
|
});
|
|
670
|
-
isTest()
|
|
854
|
+
if (!isTest()) {
|
|
855
|
+
logWithLevel(exports.LogLevel.DEBUG, undefined, console.log, 'intersection', intersection);
|
|
856
|
+
}
|
|
671
857
|
return intersection;
|
|
672
858
|
}
|
|
673
859
|
|
|
@@ -699,7 +885,7 @@ function makeCacheKey(method, tableName, requestData) {
|
|
|
699
885
|
// -----------------------------------------------------------------------------
|
|
700
886
|
function clearCache(props) {
|
|
701
887
|
if (!(props === null || props === void 0 ? void 0 : props.ignoreWarning)) {
|
|
702
|
-
console.warn
|
|
888
|
+
logWithLevel(exports.LogLevel.WARN, undefined, console.warn, "The REST API clearCache should only be used with extreme care!");
|
|
703
889
|
}
|
|
704
890
|
for (var _i = 0, userCustomClearCache_1 = userCustomClearCache; _i < userCustomClearCache_1.length; _i++) {
|
|
705
891
|
var fn = userCustomClearCache_1[_i];
|
|
@@ -718,9 +904,11 @@ function checkCache(method, tableName, requestData) {
|
|
|
718
904
|
var cached = apiRequestCache.get(key);
|
|
719
905
|
if (!cached)
|
|
720
906
|
return false;
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
907
|
+
if (shouldLog(exports.LogLevel.DEBUG, undefined)) {
|
|
908
|
+
console.groupCollapsed("%c API cache hit for ".concat(method, " ").concat(tableName), "color:#0c0");
|
|
909
|
+
console.log("Request Data:", requestData);
|
|
910
|
+
console.groupEnd();
|
|
911
|
+
}
|
|
724
912
|
return cached.request;
|
|
725
913
|
}
|
|
726
914
|
// -----------------------------------------------------------------------------
|
|
@@ -785,7 +973,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
785
973
|
catch ( /* best-effort */_d) { /* best-effort */ }
|
|
786
974
|
}
|
|
787
975
|
else if (isLocal()) {
|
|
788
|
-
console.error
|
|
976
|
+
logWithLevel(exports.LogLevel.ERROR, getLogContext(this.config, this.request), console.error, "C6 received unexpected results given the primary key length");
|
|
789
977
|
}
|
|
790
978
|
(_b = this.config.reactBootstrap) === null || _b === void 0 ? void 0 : _b.updateRestfulObjectArrays({
|
|
791
979
|
callback: callback,
|
|
@@ -816,11 +1004,10 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
816
1004
|
};
|
|
817
1005
|
HttpExecutor.prototype.execute = function () {
|
|
818
1006
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
819
|
-
var _a, C6, axios, restURL, withCredentials, restModel, reactBootstrap, requestMethod, skipPrimaryCheck, clearCache, tableName, fullTableList, operatingTableFullName, operatingTable, tables, query, apiRequest;
|
|
1007
|
+
var _a, C6, axios, restURL, withCredentials, restModel, reactBootstrap, requestMethod, skipPrimaryCheck, clearCache, tableName, fullTableList, operatingTableFullName, operatingTable, tables, logContext, debugEnabled, traceEnabled, query, apiRequest;
|
|
820
1008
|
var _this = this;
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
switch (_c.label) {
|
|
1009
|
+
return tslib.__generator(this, function (_b) {
|
|
1010
|
+
switch (_b.label) {
|
|
824
1011
|
case 0:
|
|
825
1012
|
_a = this.config, C6 = _a.C6, axios = _a.axios, restURL = _a.restURL, withCredentials = _a.withCredentials, restModel = _a.restModel, reactBootstrap = _a.reactBootstrap, requestMethod = _a.requestMethod, skipPrimaryCheck = _a.skipPrimaryCheck, clearCache = _a.clearCache;
|
|
826
1013
|
return [4 /*yield*/, this.runLifecycleHooks("beforeProcessing", {
|
|
@@ -828,7 +1015,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
828
1015
|
request: this.request,
|
|
829
1016
|
})];
|
|
830
1017
|
case 1:
|
|
831
|
-
|
|
1018
|
+
_b.sent();
|
|
832
1019
|
tableName = restModel.TABLE_NAME;
|
|
833
1020
|
fullTableList = Array.isArray(tableName) ? tableName : [tableName];
|
|
834
1021
|
operatingTableFullName = fullTableList[0];
|
|
@@ -846,7 +1033,10 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
846
1033
|
if (clearCache != null) {
|
|
847
1034
|
userCustomClearCache.push(clearCache);
|
|
848
1035
|
}
|
|
849
|
-
|
|
1036
|
+
logContext = getLogContext(this.config, this.request);
|
|
1037
|
+
debugEnabled = shouldLog(exports.LogLevel.DEBUG, logContext);
|
|
1038
|
+
traceEnabled = shouldLog(exports.LogLevel.TRACE, logContext);
|
|
1039
|
+
if (isLocal() && shouldLog(exports.LogLevel.DEBUG, logContext)) {
|
|
850
1040
|
console.groupCollapsed('%c API:', 'color: #0c0', "(".concat(requestMethod, ") Request for (").concat(tableName, ")"));
|
|
851
1041
|
console.log('request', this.request);
|
|
852
1042
|
console.groupEnd();
|
|
@@ -856,15 +1046,16 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
856
1046
|
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;
|
|
857
1047
|
var _e;
|
|
858
1048
|
var _this = this;
|
|
859
|
-
var _f, _g, _h, _j, _k, _l
|
|
860
|
-
return tslib.__generator(this, function (
|
|
861
|
-
switch (
|
|
1049
|
+
var _f, _g, _h, _j, _k, _l;
|
|
1050
|
+
return tslib.__generator(this, function (_m) {
|
|
1051
|
+
switch (_m.label) {
|
|
862
1052
|
case 0:
|
|
863
1053
|
_a = this.request, debug = _a.debug, _b = _a.cacheResults, cacheResults = _b === void 0 ? (C6.GET === requestMethod) : _b, dataInsertMultipleRows = _a.dataInsertMultipleRows, success = _a.success, _c = _a.fetchDependencies, fetchDependencies = _c === void 0 ? exports.eFetchDependencies.NONE : _c, _d = _a.error, error = _d === void 0 ? "An unexpected API error occurred!" : _d;
|
|
864
1054
|
if (C6.GET === requestMethod
|
|
865
1055
|
&& undefined !== ((_f = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _f === void 0 ? void 0 : _f[C6.PAGE])
|
|
866
1056
|
&& 1 !== query[C6.PAGINATION][C6.PAGE]
|
|
867
|
-
&& isLocal()
|
|
1057
|
+
&& isLocal()
|
|
1058
|
+
&& shouldLog(exports.LogLevel.DEBUG, logContext)) {
|
|
868
1059
|
console.groupCollapsed("Request (".concat(tableName, ") page (").concat(query[C6.PAGINATION][C6.PAGE], ")"));
|
|
869
1060
|
console.log('request', this.request);
|
|
870
1061
|
console.groupEnd();
|
|
@@ -889,7 +1080,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
889
1080
|
}
|
|
890
1081
|
if (!cachedRequest) return [3 /*break*/, 2];
|
|
891
1082
|
return [4 /*yield*/, cachedRequest];
|
|
892
|
-
case 1: return [2 /*return*/, (
|
|
1083
|
+
case 1: return [2 /*return*/, (_m.sent()).data];
|
|
893
1084
|
case 2:
|
|
894
1085
|
if (cacheResults) {
|
|
895
1086
|
cachingConfirmed = true;
|
|
@@ -914,7 +1105,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
914
1105
|
(Array.isArray(whereVal) && whereVal.length === 0) ||
|
|
915
1106
|
(typeof whereVal === 'object' && !Array.isArray(whereVal) && Object.keys(whereVal).length === 0);
|
|
916
1107
|
if (whereIsEmpty) {
|
|
917
|
-
console.error
|
|
1108
|
+
logWithLevel(exports.LogLevel.ERROR, logContext, console.error, query);
|
|
918
1109
|
throw Error('Failed to parse primary key information. Query: (' + JSON.stringify(query) + ') Primary Key: (' + JSON.stringify(primaryKey) + ') TABLES[operatingTable]?.PRIMARY: (' + JSON.stringify((_j = TABLES[operatingTable]) === null || _j === void 0 ? void 0 : _j.PRIMARY) + ') for operatingTable (' + operatingTable + ').');
|
|
919
1110
|
}
|
|
920
1111
|
}
|
|
@@ -944,23 +1135,23 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
944
1135
|
primaryVal = (_l = query[primaryKey]) !== null && _l !== void 0 ? _l : (primaryKeyFullyQualified ? query[primaryKeyFullyQualified] : undefined);
|
|
945
1136
|
if (undefined !== primaryVal) {
|
|
946
1137
|
restRequestUri += primaryVal + '/';
|
|
947
|
-
if (isLocal() && (
|
|
1138
|
+
if (isLocal() && shouldLog(exports.LogLevel.DEBUG, logContext)) {
|
|
948
1139
|
console.log('query', query, 'primaryKey', primaryKey);
|
|
949
1140
|
}
|
|
950
1141
|
}
|
|
951
1142
|
else {
|
|
952
|
-
if (isLocal() && (
|
|
1143
|
+
if (isLocal() && shouldLog(exports.LogLevel.DEBUG, logContext)) {
|
|
953
1144
|
console.log('query', query);
|
|
954
1145
|
}
|
|
955
1146
|
}
|
|
956
1147
|
}
|
|
957
1148
|
else {
|
|
958
|
-
if (isLocal() && (
|
|
1149
|
+
if (isLocal() && shouldLog(exports.LogLevel.DEBUG, logContext)) {
|
|
959
1150
|
console.log('query', query);
|
|
960
1151
|
}
|
|
961
1152
|
}
|
|
962
1153
|
try {
|
|
963
|
-
if (isLocal() && (
|
|
1154
|
+
if (isLocal() && shouldLog(exports.LogLevel.DEBUG, logContext)) {
|
|
964
1155
|
console.groupCollapsed('%c API:', 'color: #A020F0', "(".concat(requestMethod, ") (").concat(operatingTable, ") firing"));
|
|
965
1156
|
console.log(this.request);
|
|
966
1157
|
console.groupEnd();
|
|
@@ -1021,7 +1212,9 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1021
1212
|
});
|
|
1022
1213
|
}
|
|
1023
1214
|
if (isTest()) {
|
|
1024
|
-
|
|
1215
|
+
if (shouldLog(exports.LogLevel.TRACE, logContext)) {
|
|
1216
|
+
console.trace();
|
|
1217
|
+
}
|
|
1025
1218
|
throw new Error('The response data was a string this typically indicated html was sent. Make sure all cookies (' + JSON.stringify(response.config.headers) + ') needed are present! (' + response.data + ')');
|
|
1026
1219
|
}
|
|
1027
1220
|
return [2 /*return*/, Promise.reject(response)];
|
|
@@ -1095,7 +1288,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1095
1288
|
final: !hasNext,
|
|
1096
1289
|
});
|
|
1097
1290
|
}
|
|
1098
|
-
if ((
|
|
1291
|
+
if (isLocal() && shouldLog(exports.LogLevel.DEBUG, logContext)) {
|
|
1099
1292
|
console.groupCollapsed("API: Response (".concat(requestMethod, " ").concat(tableName, ") len (").concat((_b = responseData_1.rest) === null || _b === void 0 ? void 0 : _b.length, ") of (").concat((_c = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _c === void 0 ? void 0 : _c[C6.LIMIT], ")"));
|
|
1100
1293
|
console.log('request', this.request);
|
|
1101
1294
|
console.log('response.rest', responseData_1.rest);
|
|
@@ -1104,14 +1297,18 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1104
1297
|
if (!(fetchDependencies
|
|
1105
1298
|
&& 'number' === typeof fetchDependencies
|
|
1106
1299
|
&& ((_d = responseData_1.rest) === null || _d === void 0 ? void 0 : _d.length) > 0)) return [3 /*break*/, 2];
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1300
|
+
if (debugEnabled) {
|
|
1301
|
+
console.groupCollapsed('%c API: Fetch Dependencies segment (' + requestMethod + ' ' + tableName + ')'
|
|
1302
|
+
+ (fetchDependencies & exports.eFetchDependencies.CHILDREN ? ' | (CHILDREN|REFERENCED) ' : '')
|
|
1303
|
+
+ (fetchDependencies & exports.eFetchDependencies.PARENTS ? ' | (PARENTS|REFERENCED_BY)' : '')
|
|
1304
|
+
+ (fetchDependencies & exports.eFetchDependencies.C6ENTITY ? ' | (C6ENTITY)' : '')
|
|
1305
|
+
+ (fetchDependencies & exports.eFetchDependencies.RECURSIVE ? ' | (RECURSIVE)' : ''), 'color: #33ccff');
|
|
1306
|
+
if (traceEnabled) {
|
|
1307
|
+
console.groupCollapsed('Collapsed JS Trace');
|
|
1308
|
+
console.trace(); // hidden in collapsed group
|
|
1309
|
+
console.groupEnd();
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1115
1312
|
dependencies_1 = {};
|
|
1116
1313
|
// Remember this is a binary bitwise operation, so we can check for multiple dependencies at once
|
|
1117
1314
|
if (fetchDependencies & exports.eFetchDependencies.C6ENTITY) {
|
|
@@ -1146,7 +1343,9 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1146
1343
|
}
|
|
1147
1344
|
fetchReferences_1 = {};
|
|
1148
1345
|
apiRequestPromises = [];
|
|
1149
|
-
|
|
1346
|
+
if (debugEnabled) {
|
|
1347
|
+
console.log('%c Dependencies', 'color: #005555', dependencies_1);
|
|
1348
|
+
}
|
|
1150
1349
|
Object.keys(dependencies_1)
|
|
1151
1350
|
.forEach(function (column) { return dependencies_1[column]
|
|
1152
1351
|
.forEach(function (constraint) {
|
|
@@ -1172,7 +1371,9 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1172
1371
|
(_d = (_f = fetchReferences_1[constraint.TABLE])[_g = constraint.COLUMN]) !== null && _d !== void 0 ? _d : (_f[_g] = []);
|
|
1173
1372
|
fetchReferences_1[constraint.TABLE][constraint.COLUMN].push(columnValues);
|
|
1174
1373
|
}); });
|
|
1175
|
-
|
|
1374
|
+
if (debugEnabled) {
|
|
1375
|
+
console.log('fetchReferences', fetchReferences_1);
|
|
1376
|
+
}
|
|
1176
1377
|
_loop_1 = function (tableToFetch) {
|
|
1177
1378
|
var _g;
|
|
1178
1379
|
if (fetchDependencies & exports.eFetchDependencies.C6ENTITY
|
|
@@ -1188,17 +1389,23 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1188
1389
|
}, []).map(function (entityTag) { var _a, _b; return (_b = (_a = entityTag.split('\\')) === null || _a === void 0 ? void 0 : _a.pop()) === null || _b === void 0 ? void 0 : _b.toLowerCase(); });
|
|
1189
1390
|
var shouldContinue = referencesTables.find(function (referencesTable) { return tableToFetch.endsWith(referencesTable); });
|
|
1190
1391
|
if (!shouldContinue) {
|
|
1191
|
-
|
|
1392
|
+
if (debugEnabled) {
|
|
1393
|
+
console.log('%c C6ENTITY: The constraintTableName (' + tableToFetch + ') did not end with any value in referencesTables', 'color: #c00', referencesTables);
|
|
1394
|
+
}
|
|
1192
1395
|
return "continue";
|
|
1193
1396
|
}
|
|
1194
|
-
|
|
1397
|
+
if (debugEnabled) {
|
|
1398
|
+
console.log('%c C6ENTITY: The constraintTableName (' + tableToFetch + ') will be fetched.', 'color: #0c0');
|
|
1399
|
+
}
|
|
1195
1400
|
}
|
|
1196
1401
|
var ormKey = tableToFetch
|
|
1197
1402
|
.split('_')
|
|
1198
1403
|
.map(function (part) { return part.charAt(0).toUpperCase() + part.slice(1); })
|
|
1199
1404
|
.join('_');
|
|
1200
1405
|
var RestApi = (_e = C6.ORM[ormKey]) !== null && _e !== void 0 ? _e : new Error("Fetch Dependencies could not find table (".concat(ormKey, ") in the set \u2209 [ ").concat(Object.keys(C6.ORM).join(', '), " ]"));
|
|
1201
|
-
|
|
1406
|
+
if (debugEnabled) {
|
|
1407
|
+
console.log('%c Fetch Dependencies will select (' + tableToFetch + ') using GET request', 'color: #33ccff');
|
|
1408
|
+
}
|
|
1202
1409
|
var nextFetchDependencies = exports.eFetchDependencies.NONE;
|
|
1203
1410
|
if (fetchDependencies & exports.eFetchDependencies.RECURSIVE) {
|
|
1204
1411
|
var hasParents = !!(fetchDependencies & exports.eFetchDependencies.PARENTS);
|
|
@@ -1217,17 +1424,21 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1217
1424
|
nextFetchDependencies = fetchDependencies ^ exports.eFetchDependencies.C6ENTITY;
|
|
1218
1425
|
}
|
|
1219
1426
|
}
|
|
1220
|
-
|
|
1427
|
+
if (debugEnabled) {
|
|
1428
|
+
console.log('fetchReferences', fetchReferences_1[tableToFetch], "Current fetchDependencies for (" + operatingTable + "):", fetchDependencies, "New fetchDependencies for (" + tableToFetch + "): ", nextFetchDependencies);
|
|
1429
|
+
}
|
|
1221
1430
|
// todo - filter out ids that exist in state?!? note - remember that this does not necessarily mean the pk, but only known is its an FK to somewhere
|
|
1222
1431
|
// it not certain that they are using carbons' entities either
|
|
1223
|
-
|
|
1432
|
+
if (debugEnabled) {
|
|
1433
|
+
console.log('RestApi object', RestApi);
|
|
1434
|
+
}
|
|
1224
1435
|
// this is a dynamic call to the rest api, any generated table may resolve with (RestApi)
|
|
1225
1436
|
// todo - using value to avoid joins.... but. maybe this should be a parameterizable option -- think race conditions; its safer to join
|
|
1226
1437
|
apiRequestPromises.push(RestApi.Get((_g = {},
|
|
1227
1438
|
_g[C6.WHERE] = Object.keys(fetchReferences_1[tableToFetch]).reduce(function (sum, column) {
|
|
1228
1439
|
fetchReferences_1[tableToFetch][column] = fetchReferences_1[tableToFetch][column].flat(Infinity);
|
|
1229
1440
|
if (0 === fetchReferences_1[tableToFetch][column].length) {
|
|
1230
|
-
console.warn
|
|
1441
|
+
logWithLevel(exports.LogLevel.WARN, logContext, console.warn, 'The column (' + column + ') was not found in the response data. We will not fetch.', responseData_1);
|
|
1231
1442
|
return false;
|
|
1232
1443
|
}
|
|
1233
1444
|
sum["".concat(tableToFetch, ".").concat(column)] = fetchReferences_1[tableToFetch][column].length === 1
|
|
@@ -1243,7 +1454,9 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1243
1454
|
for (tableToFetch in fetchReferences_1) {
|
|
1244
1455
|
_loop_1(tableToFetch);
|
|
1245
1456
|
}
|
|
1246
|
-
|
|
1457
|
+
if (debugEnabled) {
|
|
1458
|
+
console.groupEnd();
|
|
1459
|
+
}
|
|
1247
1460
|
return [4 /*yield*/, Promise.all(apiRequestPromises)];
|
|
1248
1461
|
case 1:
|
|
1249
1462
|
_f.sent();
|
|
@@ -1284,19 +1497,23 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1284
1497
|
}); }).then(function (response) { return response.data; })]; // this escapes from axios context
|
|
1285
1498
|
}
|
|
1286
1499
|
catch (throwableError) {
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1500
|
+
if (shouldLog(exports.LogLevel.ERROR, logContext)) {
|
|
1501
|
+
console.groupCollapsed('%c API: An error occurred in the try catch block. returning null!', 'color: #ff0000');
|
|
1502
|
+
console.log('%c ' + requestMethod + ' ' + tableName, 'color: #A020F0');
|
|
1503
|
+
console.error(throwableError);
|
|
1504
|
+
if (traceEnabled) {
|
|
1505
|
+
console.trace();
|
|
1506
|
+
}
|
|
1507
|
+
console.groupEnd();
|
|
1508
|
+
}
|
|
1509
|
+
throw throwableError;
|
|
1293
1510
|
}
|
|
1294
1511
|
return [2 /*return*/];
|
|
1295
1512
|
}
|
|
1296
1513
|
});
|
|
1297
1514
|
}); };
|
|
1298
1515
|
return [4 /*yield*/, apiRequest()];
|
|
1299
|
-
case 2: return [2 /*return*/,
|
|
1516
|
+
case 2: return [2 /*return*/, _b.sent()];
|
|
1300
1517
|
}
|
|
1301
1518
|
});
|
|
1302
1519
|
});
|
|
@@ -1389,7 +1606,7 @@ var AggregateBuilder = /** @class */ (function (_super) {
|
|
|
1389
1606
|
this.selectAliases.add(alias);
|
|
1390
1607
|
expr_1 += " AS ".concat(alias);
|
|
1391
1608
|
}
|
|
1392
|
-
this.config.
|
|
1609
|
+
logWithLevel(exports.LogLevel.DEBUG, getLogContext(this.config, this.request), console.log, "[SELECT] ".concat(expr_1));
|
|
1393
1610
|
return expr_1;
|
|
1394
1611
|
}
|
|
1395
1612
|
var identifierPathRegex = /^[A-Za-z_][A-Za-z0-9_]*\.[A-Za-z_][A-Za-z0-9_]*$/;
|
|
@@ -1430,7 +1647,7 @@ var AggregateBuilder = /** @class */ (function (_super) {
|
|
|
1430
1647
|
this.selectAliases.add(alias);
|
|
1431
1648
|
expr += " AS ".concat(alias);
|
|
1432
1649
|
}
|
|
1433
|
-
this.config.
|
|
1650
|
+
logWithLevel(exports.LogLevel.DEBUG, getLogContext(this.config, this.request), console.log, "[SELECT] ".concat(expr));
|
|
1434
1651
|
return expr;
|
|
1435
1652
|
};
|
|
1436
1653
|
return AggregateBuilder;
|
|
@@ -2079,7 +2296,7 @@ var ConditionBuilder = /** @class */ (function (_super) {
|
|
|
2079
2296
|
break;
|
|
2080
2297
|
}
|
|
2081
2298
|
var clause = "(MATCH(".concat(leftInfo_1.sql, ") ").concat(againstClause, ")");
|
|
2082
|
-
this.config.
|
|
2299
|
+
logWithLevel(exports.LogLevel.DEBUG, getLogContext(this.config, this.request), console.log, "[MATCH_AGAINST] ".concat(clause));
|
|
2083
2300
|
return clause;
|
|
2084
2301
|
}
|
|
2085
2302
|
var operands = Array.isArray(rawOperands) ? rawOperands : [rawOperands];
|
|
@@ -2328,7 +2545,7 @@ var ConditionBuilder = /** @class */ (function (_super) {
|
|
|
2328
2545
|
}
|
|
2329
2546
|
}
|
|
2330
2547
|
}
|
|
2331
|
-
this.config.
|
|
2548
|
+
logWithLevel(exports.LogLevel.DEBUG, getLogContext(this.config, this.request), console.log, "[WHERE] ".concat(trimmed));
|
|
2332
2549
|
return " WHERE ".concat(trimmed);
|
|
2333
2550
|
};
|
|
2334
2551
|
return ConditionBuilder;
|
|
@@ -2558,7 +2775,7 @@ var JoinBuilder = /** @class */ (function (_super) {
|
|
|
2558
2775
|
var _a = joinTypeEntries_1[_i], joinTypeRaw = _a[0], joinSection = _a[1];
|
|
2559
2776
|
_loop_1(joinTypeRaw, joinSection);
|
|
2560
2777
|
}
|
|
2561
|
-
this.config.
|
|
2778
|
+
logWithLevel(exports.LogLevel.DEBUG, getLogContext(this.config, this.request), console.log, "[JOIN] ".concat(sql.trim()));
|
|
2562
2779
|
return sql;
|
|
2563
2780
|
};
|
|
2564
2781
|
JoinBuilder.prototype.integrateSubSelectParams = function (subSql, subParams, target) {
|
|
@@ -2675,12 +2892,176 @@ var PaginationBuilder = /** @class */ (function (_super) {
|
|
|
2675
2892
|
sql += " LIMIT ".concat(offset, ", ").concat(lim);
|
|
2676
2893
|
}
|
|
2677
2894
|
}
|
|
2678
|
-
this.config.
|
|
2895
|
+
logWithLevel(exports.LogLevel.DEBUG, getLogContext(this.config, this.request), console.log, "[PAGINATION] ".concat(sql.trim()));
|
|
2679
2896
|
return sql;
|
|
2680
2897
|
};
|
|
2681
2898
|
return PaginationBuilder;
|
|
2682
2899
|
}(JoinBuilder));
|
|
2683
2900
|
|
|
2901
|
+
/* eslint-disable no-control-regex */
|
|
2902
|
+
var RESET = "\x1b[0m";
|
|
2903
|
+
var C$1 = {
|
|
2904
|
+
KEYWORD: "\x1b[94m", // blue
|
|
2905
|
+
LIMIT: "\x1b[93m", // yellow
|
|
2906
|
+
NUMBER: "\x1b[92m", // green
|
|
2907
|
+
DIM: "\x1b[90m", // gray
|
|
2908
|
+
};
|
|
2909
|
+
/* ---------- ANSI helpers ---------- */
|
|
2910
|
+
var ansi256 = function (n) { return "\u001B[38;5;".concat(n, "m"); };
|
|
2911
|
+
/* ---------- hashing ---------- */
|
|
2912
|
+
function hashString$1(str) {
|
|
2913
|
+
var hash = 0;
|
|
2914
|
+
for (var i = 0; i < str.length; i++) {
|
|
2915
|
+
hash = (hash * 31 + str.charCodeAt(i)) | 0;
|
|
2916
|
+
}
|
|
2917
|
+
return Math.abs(hash);
|
|
2918
|
+
}
|
|
2919
|
+
/* ---------- table color ---------- */
|
|
2920
|
+
function tableRGB(tableName) {
|
|
2921
|
+
var name = tableName.replace(/[`"]/g, "").toLowerCase();
|
|
2922
|
+
var hash = hashString$1(name);
|
|
2923
|
+
// Stable hue bucket by first letter
|
|
2924
|
+
var first = name.charCodeAt(0) || 97;
|
|
2925
|
+
var hueBase = (first - 97) % 6;
|
|
2926
|
+
var r = (hueBase + (hash % 3)) % 6;
|
|
2927
|
+
var g = (hash >> 3) % 6;
|
|
2928
|
+
var b = (hash >> 6) % 6;
|
|
2929
|
+
return [r, g, Math.max(2, b)]; // avoid muddy dark blues
|
|
2930
|
+
}
|
|
2931
|
+
function tableColor(table) {
|
|
2932
|
+
var _a = tableRGB(table), r = _a[0], g = _a[1], b = _a[2];
|
|
2933
|
+
return ansi256(16 + 36 * r + 6 * g + b);
|
|
2934
|
+
}
|
|
2935
|
+
/* ---------- column color (same hue, lighter) ---------- */
|
|
2936
|
+
function columnColorFromTable(table) {
|
|
2937
|
+
var _a = tableRGB(table), r = _a[0], g = _a[1], b = _a[2];
|
|
2938
|
+
// Lift toward white, preserve hue
|
|
2939
|
+
var lr = Math.min(5, r + 1);
|
|
2940
|
+
var lg = Math.min(5, g + 1);
|
|
2941
|
+
var lb = Math.min(5, b + 2);
|
|
2942
|
+
return ansi256(16 + 36 * lr + 6 * lg + lb);
|
|
2943
|
+
}
|
|
2944
|
+
/* ---------- bind collapsing ---------- */
|
|
2945
|
+
/**
|
|
2946
|
+
* ?, ?, ?, ?, ?, ? → ? ×6
|
|
2947
|
+
* triggers at 4+
|
|
2948
|
+
*/
|
|
2949
|
+
function collapseBinds(sql) {
|
|
2950
|
+
return sql.replace(/(\?\s*,\s*){3,}\?/g, function (match) {
|
|
2951
|
+
var count = match.split("?").length - 1;
|
|
2952
|
+
return "".concat(C$1.DIM, "? \u00D7").concat(count).concat(RESET);
|
|
2953
|
+
});
|
|
2954
|
+
}
|
|
2955
|
+
/* ---------- main formatter ---------- */
|
|
2956
|
+
function colorSql(sql) {
|
|
2957
|
+
var s = sql.trim();
|
|
2958
|
+
/* 1️⃣ collapse bind noise */
|
|
2959
|
+
s = collapseBinds(s);
|
|
2960
|
+
/* 2️⃣ table.column coloring (core visual grouping) */
|
|
2961
|
+
s = s.replace(/\b(`?\w+`?)\.(\w+)\b/g, function (_, table, column) {
|
|
2962
|
+
return "".concat(tableColor(table)).concat(table).concat(RESET, ".") +
|
|
2963
|
+
"".concat(columnColorFromTable(table)).concat(column).concat(RESET);
|
|
2964
|
+
});
|
|
2965
|
+
/* 3️⃣ FROM / JOIN tables */
|
|
2966
|
+
s = s.replace(/\b(FROM|JOIN|UPDATE|INTO)\s+(`[^`]+`|\w+)/gi, function (_, kw, table) {
|
|
2967
|
+
return "".concat(C$1.KEYWORD).concat(kw).concat(RESET, " ").concat(tableColor(table)).concat(table).concat(RESET);
|
|
2968
|
+
});
|
|
2969
|
+
/* 4️⃣ SQL keywords */
|
|
2970
|
+
s = s.replace(/\b(SELECT|WHERE|AND|OR|ON|IN|BETWEEN|EXISTS|ORDER BY|GROUP BY|HAVING|SET|VALUES|INSERT|REPLACE|DELETE|UPDATE|DUPLICATE|KEY)\b/gi, "".concat(C$1.KEYWORD, "$1").concat(RESET));
|
|
2971
|
+
/* 5️⃣ LIMIT */
|
|
2972
|
+
s = s.replace(/\bLIMIT\s+(\d+)/gi, "".concat(C$1.LIMIT, "LIMIT").concat(RESET, " ").concat(C$1.NUMBER, "$1").concat(RESET));
|
|
2973
|
+
return s;
|
|
2974
|
+
}
|
|
2975
|
+
|
|
2976
|
+
var version = "6.0.8";
|
|
2977
|
+
|
|
2978
|
+
var DEFAULT_STEP = 8;
|
|
2979
|
+
function parseSemver(version) {
|
|
2980
|
+
var _a = version.trim().split("-"), core = _a[0], prerelease = _a[1];
|
|
2981
|
+
var _b = core.split("."), majorRaw = _b[0], minorRaw = _b[1], patchRaw = _b[2];
|
|
2982
|
+
var major = Number.parseInt(majorRaw !== null && majorRaw !== void 0 ? majorRaw : "0", 10);
|
|
2983
|
+
var minor = Number.parseInt(minorRaw !== null && minorRaw !== void 0 ? minorRaw : "0", 10);
|
|
2984
|
+
var patch = Number.parseInt(patchRaw !== null && patchRaw !== void 0 ? patchRaw : "0", 10);
|
|
2985
|
+
var prereleaseParts = prerelease ? prerelease.split(".").filter(Boolean).length : 0;
|
|
2986
|
+
return {
|
|
2987
|
+
major: Number.isFinite(major) ? major : 0,
|
|
2988
|
+
minor: Number.isFinite(minor) ? minor : 0,
|
|
2989
|
+
patch: Number.isFinite(patch) ? patch : 0,
|
|
2990
|
+
prereleaseParts: prereleaseParts,
|
|
2991
|
+
};
|
|
2992
|
+
}
|
|
2993
|
+
function channelValue(n, step) {
|
|
2994
|
+
var value = 255 - ((n * step) % 256);
|
|
2995
|
+
return (value + 256) % 256;
|
|
2996
|
+
}
|
|
2997
|
+
function versionToRgb(version, step) {
|
|
2998
|
+
if (step === void 0) { step = DEFAULT_STEP; }
|
|
2999
|
+
var safeStep = Number.isFinite(step) && step > 0 ? Math.floor(step) : DEFAULT_STEP;
|
|
3000
|
+
var _a = parseSemver(version), major = _a.major, minor = _a.minor, patch = _a.patch, prereleaseParts = _a.prereleaseParts;
|
|
3001
|
+
var rotation = (major + minor + patch + prereleaseParts) % 3;
|
|
3002
|
+
var base = [major, minor, patch];
|
|
3003
|
+
var rotated = rotation === 1
|
|
3004
|
+
? [base[2], base[0], base[1]]
|
|
3005
|
+
: rotation === 2
|
|
3006
|
+
? [base[1], base[2], base[0]]
|
|
3007
|
+
: base;
|
|
3008
|
+
return {
|
|
3009
|
+
r: channelValue(rotated[0], safeStep),
|
|
3010
|
+
g: channelValue(rotated[1], safeStep),
|
|
3011
|
+
b: channelValue(rotated[2], safeStep),
|
|
3012
|
+
};
|
|
3013
|
+
}
|
|
3014
|
+
|
|
3015
|
+
var C = {
|
|
3016
|
+
SSR: "\x1b[95m", // bright magenta
|
|
3017
|
+
HTTP: "\x1b[94m", // bright blue
|
|
3018
|
+
METHOD_COLORS: {
|
|
3019
|
+
SELECT: "\x1b[92m", // green
|
|
3020
|
+
INSERT: "\x1b[96m", // cyan
|
|
3021
|
+
REPLACE: "\x1b[96m", // cyan
|
|
3022
|
+
UPDATE: "\x1b[95m", // magenta
|
|
3023
|
+
DELETE: "\x1b[91m", // red
|
|
3024
|
+
},
|
|
3025
|
+
METHOD_FALLBACK: [
|
|
3026
|
+
"\x1b[92m", // green
|
|
3027
|
+
"\x1b[93m", // yellow
|
|
3028
|
+
"\x1b[95m", // magenta
|
|
3029
|
+
"\x1b[96m", // cyan
|
|
3030
|
+
"\x1b[94m", // blue
|
|
3031
|
+
"\x1b[97m", // white
|
|
3032
|
+
],
|
|
3033
|
+
RESET: "\x1b[0m",
|
|
3034
|
+
};
|
|
3035
|
+
var rgbAnsi = function (_a) {
|
|
3036
|
+
var r = _a.r, g = _a.g, b = _a.b;
|
|
3037
|
+
return "\u001B[38;2;".concat(r, ";").concat(g, ";").concat(b, "m");
|
|
3038
|
+
};
|
|
3039
|
+
function hashString(value) {
|
|
3040
|
+
var hash = 0;
|
|
3041
|
+
for (var i = 0; i < value.length; i++) {
|
|
3042
|
+
hash = (hash * 31 + value.charCodeAt(i)) | 0;
|
|
3043
|
+
}
|
|
3044
|
+
return Math.abs(hash);
|
|
3045
|
+
}
|
|
3046
|
+
function methodColor(method) {
|
|
3047
|
+
var key = method.toUpperCase();
|
|
3048
|
+
if (key in C.METHOD_COLORS) {
|
|
3049
|
+
return C.METHOD_COLORS[key];
|
|
3050
|
+
}
|
|
3051
|
+
var idx = hashString(key) % C.METHOD_FALLBACK.length;
|
|
3052
|
+
return C.METHOD_FALLBACK[idx];
|
|
3053
|
+
}
|
|
3054
|
+
function logSql(method, sql, context) {
|
|
3055
|
+
if (!shouldLog(exports.LogLevel.DEBUG, context))
|
|
3056
|
+
return;
|
|
3057
|
+
var preText = getEnvBool("SSR", false)
|
|
3058
|
+
? "".concat(C.SSR, "[SSR]").concat(C.RESET, " ")
|
|
3059
|
+
: "".concat(C.HTTP, "[API]").concat(C.RESET, " ");
|
|
3060
|
+
var labelColor = methodColor(method);
|
|
3061
|
+
var versionColor = rgbAnsi(versionToRgb(version));
|
|
3062
|
+
console.log("".concat(versionColor, "[").concat(version, "]").concat(C.RESET, " ").concat(preText).concat(labelColor, "[").concat(method, "]").concat(C.RESET, " ").concat(colorSql(sql)));
|
|
3063
|
+
}
|
|
3064
|
+
|
|
2684
3065
|
var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
2685
3066
|
tslib.__extends(SelectQueryBuilder, _super);
|
|
2686
3067
|
function SelectQueryBuilder() {
|
|
@@ -2732,7 +3113,7 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
2732
3113
|
else if (!isSubSelect) {
|
|
2733
3114
|
sql += " LIMIT 100";
|
|
2734
3115
|
}
|
|
2735
|
-
|
|
3116
|
+
logSql("SELECT", sql, getLogContext(this.config, this.request));
|
|
2736
3117
|
return { sql: sql, params: params };
|
|
2737
3118
|
};
|
|
2738
3119
|
return SelectQueryBuilder;
|
|
@@ -2757,6 +3138,7 @@ var DeleteQueryBuilder = /** @class */ (function (_super) {
|
|
|
2757
3138
|
if (this.request.WHERE) {
|
|
2758
3139
|
sql += this.buildWhereClause(this.request.WHERE, params);
|
|
2759
3140
|
}
|
|
3141
|
+
logSql("DELETE", sql, getLogContext(this.config, this.request));
|
|
2760
3142
|
return { sql: sql, params: params };
|
|
2761
3143
|
};
|
|
2762
3144
|
return DeleteQueryBuilder;
|
|
@@ -2801,6 +3183,7 @@ var PostQueryBuilder = /** @class */ (function (_super) {
|
|
|
2801
3183
|
var updateClause = updateData.map(function (k) { return "`".concat(k, "` = VALUES(`").concat(k, "`)"); }).join(', ');
|
|
2802
3184
|
sql += " ON DUPLICATE KEY UPDATE ".concat(updateClause);
|
|
2803
3185
|
}
|
|
3186
|
+
logSql(verb, sql, getLogContext(this.config, this.request));
|
|
2804
3187
|
return { sql: sql, params: params };
|
|
2805
3188
|
};
|
|
2806
3189
|
return PostQueryBuilder;
|
|
@@ -2852,6 +3235,7 @@ var UpdateQueryBuilder = /** @class */ (function (_super) {
|
|
|
2852
3235
|
if (args.PAGINATION) {
|
|
2853
3236
|
sql += this.buildPaginationClause(args.PAGINATION, params);
|
|
2854
3237
|
}
|
|
3238
|
+
logSql("UPDATE", sql, getLogContext(this.config, this.request));
|
|
2855
3239
|
return { sql: sql, params: params };
|
|
2856
3240
|
};
|
|
2857
3241
|
return UpdateQueryBuilder;
|
|
@@ -3110,7 +3494,7 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3110
3494
|
}
|
|
3111
3495
|
SqlExecutor.prototype.execute = function () {
|
|
3112
3496
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
3113
|
-
var TABLE_NAME, method, _a, rest, result, result, result;
|
|
3497
|
+
var TABLE_NAME, method, logContext, _a, rest, result, result, result;
|
|
3114
3498
|
return tslib.__generator(this, function (_b) {
|
|
3115
3499
|
switch (_b.label) {
|
|
3116
3500
|
case 0:
|
|
@@ -3124,8 +3508,9 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3124
3508
|
// Surface normalization errors early
|
|
3125
3509
|
throw e;
|
|
3126
3510
|
}
|
|
3127
|
-
|
|
3128
|
-
|
|
3511
|
+
logContext = getLogContext(this.config, this.request);
|
|
3512
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] \u25B6\uFE0F Executing ".concat(method, " on table \"").concat(TABLE_NAME, "\""));
|
|
3513
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] \uD83E\uDDE9 Request:", this.request);
|
|
3129
3514
|
_a = method;
|
|
3130
3515
|
switch (_a) {
|
|
3131
3516
|
case 'GET': return [3 /*break*/, 1];
|
|
@@ -3173,22 +3558,23 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3173
3558
|
};
|
|
3174
3559
|
SqlExecutor.prototype.withConnection = function (cb) {
|
|
3175
3560
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
3176
|
-
var conn;
|
|
3561
|
+
var logContext, conn;
|
|
3177
3562
|
return tslib.__generator(this, function (_a) {
|
|
3178
3563
|
switch (_a.label) {
|
|
3179
3564
|
case 0:
|
|
3180
|
-
this.config
|
|
3565
|
+
logContext = getLogContext(this.config, this.request);
|
|
3566
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] \uD83D\uDCE1 Getting DB connection");
|
|
3181
3567
|
return [4 /*yield*/, this.config.mysqlPool.getConnection()];
|
|
3182
3568
|
case 1:
|
|
3183
3569
|
conn = _a.sent();
|
|
3184
3570
|
_a.label = 2;
|
|
3185
3571
|
case 2:
|
|
3186
3572
|
_a.trys.push([2, , 4, 5]);
|
|
3187
|
-
|
|
3573
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] \u2705 Connection acquired");
|
|
3188
3574
|
return [4 /*yield*/, cb(conn)];
|
|
3189
3575
|
case 3: return [2 /*return*/, _a.sent()];
|
|
3190
3576
|
case 4:
|
|
3191
|
-
|
|
3577
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] \uD83D\uDD0C Releasing DB connection");
|
|
3192
3578
|
conn.release();
|
|
3193
3579
|
return [7 /*endfinally*/];
|
|
3194
3580
|
case 5: return [2 /*return*/];
|
|
@@ -3364,19 +3750,20 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3364
3750
|
};
|
|
3365
3751
|
SqlExecutor.prototype.broadcastWebsocketIfConfigured = function (response) {
|
|
3366
3752
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
3367
|
-
var broadcast, normalizedRequest, pkShorts, columns, validColumns, responseRest, responsePrimaryKey, insertId, synthesizedRequest, now, synthesized, payload, error_1;
|
|
3753
|
+
var broadcast, logContext, normalizedRequest, pkShorts, columns, validColumns, responseRest, responsePrimaryKey, insertId, synthesizedRequest, now, synthesized, payload, error_1;
|
|
3368
3754
|
var _a, _b;
|
|
3369
3755
|
var _c, _d, _e;
|
|
3370
3756
|
return tslib.__generator(this, function (_f) {
|
|
3371
3757
|
switch (_f.label) {
|
|
3372
3758
|
case 0:
|
|
3373
3759
|
broadcast = this.config.websocketBroadcast;
|
|
3374
|
-
this.config
|
|
3760
|
+
logContext = getLogContext(this.config, this.request);
|
|
3761
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] 📣 broadcastWebsocketIfConfigured start", {
|
|
3375
3762
|
method: this.config.requestMethod,
|
|
3376
3763
|
hasBroadcast: Boolean(broadcast),
|
|
3377
3764
|
});
|
|
3378
3765
|
if (!broadcast || this.config.requestMethod === C6Constants.GET) {
|
|
3379
|
-
|
|
3766
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] 📣 websocket broadcast skipped", {
|
|
3380
3767
|
reason: !broadcast ? "no broadcast configured" : "GET request",
|
|
3381
3768
|
});
|
|
3382
3769
|
return [2 /*return*/];
|
|
@@ -3387,22 +3774,22 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3387
3774
|
validColumns = new Set(Object.values(columns));
|
|
3388
3775
|
responseRest = response === null || response === void 0 ? void 0 : response.rest;
|
|
3389
3776
|
responsePrimaryKey = this.extractPrimaryKeyValuesFromData(responseRest);
|
|
3390
|
-
|
|
3777
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] 📣 websocket request payload", {
|
|
3391
3778
|
normalizedRequest: normalizedRequest,
|
|
3392
3779
|
requestPrimaryKey: this.extractPrimaryKeyValues(),
|
|
3393
3780
|
pkShorts: pkShorts,
|
|
3394
3781
|
});
|
|
3395
|
-
|
|
3782
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] 📣 websocket response payload", {
|
|
3396
3783
|
responseRest: responseRest,
|
|
3397
3784
|
responsePrimaryKey: responsePrimaryKey,
|
|
3398
3785
|
});
|
|
3399
3786
|
if ((responseRest === null || (Array.isArray(responseRest) && responseRest.length === 0))
|
|
3400
3787
|
&& this.config.requestMethod === C6Constants.POST) {
|
|
3401
|
-
|
|
3788
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] 📣 response rest empty, attempting synthesize", {
|
|
3402
3789
|
responseRest: responseRest,
|
|
3403
3790
|
});
|
|
3404
3791
|
insertId = response === null || response === void 0 ? void 0 : response.insertId;
|
|
3405
|
-
|
|
3792
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] 📣 POST insertId lookup", {
|
|
3406
3793
|
insertId: insertId,
|
|
3407
3794
|
});
|
|
3408
3795
|
if (insertId !== undefined && pkShorts.length === 1) {
|
|
@@ -3423,7 +3810,7 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3423
3810
|
responsePrimaryKey = (_b = {},
|
|
3424
3811
|
_b[pkShorts[0]] = insertId,
|
|
3425
3812
|
_b);
|
|
3426
|
-
|
|
3813
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] 📣 synthesized response payload", {
|
|
3427
3814
|
synthesized: synthesized,
|
|
3428
3815
|
responsePrimaryKey: responsePrimaryKey,
|
|
3429
3816
|
});
|
|
@@ -3440,21 +3827,19 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3440
3827
|
RESPONSE_PRIMARY_KEY: responsePrimaryKey,
|
|
3441
3828
|
},
|
|
3442
3829
|
};
|
|
3443
|
-
|
|
3830
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] 📣 websocket payload ready", payload);
|
|
3444
3831
|
_f.label = 1;
|
|
3445
3832
|
case 1:
|
|
3446
3833
|
_f.trys.push([1, 3, , 4]);
|
|
3447
|
-
|
|
3834
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] 📣 websocket broadcast dispatch start");
|
|
3448
3835
|
return [4 /*yield*/, broadcast(payload)];
|
|
3449
3836
|
case 2:
|
|
3450
3837
|
_f.sent();
|
|
3451
|
-
|
|
3838
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] 📣 websocket broadcast dispatch complete");
|
|
3452
3839
|
return [3 /*break*/, 4];
|
|
3453
3840
|
case 3:
|
|
3454
3841
|
error_1 = _f.sent();
|
|
3455
|
-
|
|
3456
|
-
console.error("[SQL EXECUTOR] websocketBroadcast failed", error_1);
|
|
3457
|
-
}
|
|
3842
|
+
logWithLevel(exports.LogLevel.ERROR, logContext, console.error, "[SQL EXECUTOR] websocketBroadcast failed", error_1);
|
|
3458
3843
|
return [3 /*break*/, 4];
|
|
3459
3844
|
case 4: return [2 /*return*/];
|
|
3460
3845
|
}
|
|
@@ -3463,7 +3848,7 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3463
3848
|
};
|
|
3464
3849
|
SqlExecutor.prototype.runQuery = function () {
|
|
3465
3850
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
3466
|
-
var TABLE_NAME, method, builder, QueryResult, formatted, toUnnamed, _a, sql, values;
|
|
3851
|
+
var TABLE_NAME, method, builder, QueryResult, logContext, formatted, toUnnamed, _a, sql, values;
|
|
3467
3852
|
var _this = this;
|
|
3468
3853
|
return tslib.__generator(this, function (_b) {
|
|
3469
3854
|
switch (_b.label) {
|
|
@@ -3487,9 +3872,10 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3487
3872
|
throw new Error("Unsupported query method: ".concat(method));
|
|
3488
3873
|
}
|
|
3489
3874
|
QueryResult = builder.build(TABLE_NAME);
|
|
3490
|
-
|
|
3875
|
+
logContext = getLogContext(this.config, this.request);
|
|
3876
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] \uD83E\uDDE0 Generated ".concat(method.toUpperCase(), " SQL:"), QueryResult);
|
|
3491
3877
|
formatted = this.formatSQLWithParams(QueryResult.sql, QueryResult.params);
|
|
3492
|
-
|
|
3878
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] \uD83E\uDDE0 Formatted ".concat(method.toUpperCase(), " SQL:"), formatted);
|
|
3493
3879
|
toUnnamed = namedPlaceholders();
|
|
3494
3880
|
_a = toUnnamed(QueryResult.sql, QueryResult.params), sql = _a[0], values = _a[1];
|
|
3495
3881
|
return [4 /*yield*/, this.validateSqlAllowList(sql)];
|
|
@@ -3509,7 +3895,7 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3509
3895
|
}];
|
|
3510
3896
|
}
|
|
3511
3897
|
else {
|
|
3512
|
-
|
|
3898
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] \u270F\uFE0F Rows affected:", result.affectedRows);
|
|
3513
3899
|
return [2 /*return*/, {
|
|
3514
3900
|
affected: result.affectedRows,
|
|
3515
3901
|
insertId: result.insertId,
|
|
@@ -3584,7 +3970,7 @@ function ExpressHandler(_a) {
|
|
|
3584
3970
|
}
|
|
3585
3971
|
// Warn for unsupported overrides but continue normally
|
|
3586
3972
|
if (incomingMethod !== 'GET' && methodOverride && methodOverride !== 'GET') {
|
|
3587
|
-
console.warn
|
|
3973
|
+
logWithLevel(exports.LogLevel.WARN, undefined, console.warn, "Ignoring unsupported METHOD override: ".concat(methodOverride));
|
|
3588
3974
|
}
|
|
3589
3975
|
if (!(table in C6.TABLES)) {
|
|
3590
3976
|
res.status(400).json({ error: "Invalid table: ".concat(table) });
|
|
@@ -3708,10 +4094,9 @@ function getPrimaryKeyTypes(table) {
|
|
|
3708
4094
|
return result;
|
|
3709
4095
|
}
|
|
3710
4096
|
|
|
3711
|
-
/**
|
|
3712
|
-
* Conditionally group a log if verbose.
|
|
3713
|
-
*/
|
|
3714
4097
|
function group(title, data) {
|
|
4098
|
+
if (!shouldLog(exports.LogLevel.DEBUG))
|
|
4099
|
+
return;
|
|
3715
4100
|
console.groupCollapsed("%c".concat(title), "color: #007acc");
|
|
3716
4101
|
if (data !== undefined)
|
|
3717
4102
|
console.log(data);
|
|
@@ -3722,6 +4107,8 @@ function info(message) {
|
|
|
3722
4107
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
3723
4108
|
optional[_i - 1] = arguments[_i];
|
|
3724
4109
|
}
|
|
4110
|
+
if (!shouldLog(exports.LogLevel.INFO))
|
|
4111
|
+
return;
|
|
3725
4112
|
console.info.apply(console, tslib.__spreadArray(["%cINFO: ".concat(message), "color: #0a0"], optional, false));
|
|
3726
4113
|
}
|
|
3727
4114
|
function warn(message) {
|
|
@@ -3729,6 +4116,8 @@ function warn(message) {
|
|
|
3729
4116
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
3730
4117
|
optional[_i - 1] = arguments[_i];
|
|
3731
4118
|
}
|
|
4119
|
+
if (!shouldLog(exports.LogLevel.WARN))
|
|
4120
|
+
return;
|
|
3732
4121
|
console.warn.apply(console, tslib.__spreadArray(["%cWARN: ".concat(message), "color: #e90"], optional, false));
|
|
3733
4122
|
}
|
|
3734
4123
|
function error(message) {
|
|
@@ -3736,6 +4125,8 @@ function error(message) {
|
|
|
3736
4125
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
3737
4126
|
optional[_i - 1] = arguments[_i];
|
|
3738
4127
|
}
|
|
4128
|
+
if (!shouldLog(exports.LogLevel.ERROR))
|
|
4129
|
+
return;
|
|
3739
4130
|
console.error.apply(console, tslib.__spreadArray(["%cERROR: ".concat(message), "color: #c00"], optional, false));
|
|
3740
4131
|
}
|
|
3741
4132
|
|
|
@@ -3747,7 +4138,7 @@ function checkAllRequestsComplete() {
|
|
|
3747
4138
|
throw new Error('document is undefined while waiting for API requests to complete (' + JSON.stringify(cacheEntries) + ')');
|
|
3748
4139
|
}
|
|
3749
4140
|
// when requests return emtpy sets in full renders, it may not be possible to track their progress.
|
|
3750
|
-
console.warn
|
|
4141
|
+
logWithLevel(exports.LogLevel.WARN, undefined, console.warn, 'stillRunning...', stillRunning);
|
|
3751
4142
|
return stillRunning.map(function (cache) { return cache.requestArgumentsSerialized; });
|
|
3752
4143
|
}
|
|
3753
4144
|
return true;
|
|
@@ -3760,6 +4151,10 @@ function onError(message) {
|
|
|
3760
4151
|
notifyToast("error", message, isLocal() ? toastOptionsDevs : toastOptions);
|
|
3761
4152
|
}
|
|
3762
4153
|
|
|
4154
|
+
function isVerbose() {
|
|
4155
|
+
return resolveLogLevel() >= exports.LogLevel.DEBUG;
|
|
4156
|
+
}
|
|
4157
|
+
|
|
3763
4158
|
exports.A = A;
|
|
3764
4159
|
exports.AggregateBuilder = AggregateBuilder;
|
|
3765
4160
|
exports.C6C = C6C;
|
|
@@ -3782,6 +4177,7 @@ exports.SqlExecutor = SqlExecutor;
|
|
|
3782
4177
|
exports.TestRestfulResponse = TestRestfulResponse;
|
|
3783
4178
|
exports.UpdateQueryBuilder = UpdateQueryBuilder;
|
|
3784
4179
|
exports.apiRequestCache = apiRequestCache;
|
|
4180
|
+
exports.applyLogLevelDefaults = applyLogLevelDefaults;
|
|
3785
4181
|
exports.axiosInstance = axiosInstance;
|
|
3786
4182
|
exports.bbox = bbox;
|
|
3787
4183
|
exports.carbonNodeQsStringify = carbonNodeQsStringify;
|
|
@@ -3789,6 +4185,7 @@ exports.checkAllRequestsComplete = checkAllRequestsComplete;
|
|
|
3789
4185
|
exports.checkCache = checkCache;
|
|
3790
4186
|
exports.clearCache = clearCache;
|
|
3791
4187
|
exports.collectSqlAllowListEntries = collectSqlAllowListEntries;
|
|
4188
|
+
exports.colorSql = colorSql;
|
|
3792
4189
|
exports.compileSqlAllowList = compileSqlAllowList;
|
|
3793
4190
|
exports.convertForRequestBody = convertForRequestBody;
|
|
3794
4191
|
exports.convertHexIfBinary = convertHexIfBinary;
|
|
@@ -3798,7 +4195,11 @@ exports.distSphere = distSphere;
|
|
|
3798
4195
|
exports.error = error;
|
|
3799
4196
|
exports.extractSqlEntries = extractSqlEntries;
|
|
3800
4197
|
exports.fieldEq = fieldEq;
|
|
3801
|
-
exports.
|
|
4198
|
+
exports.getEnv = getEnv;
|
|
4199
|
+
exports.getEnvBool = getEnvBool;
|
|
4200
|
+
exports.getEnvDebug = getEnvDebug;
|
|
4201
|
+
exports.getEnvLogLevel = getEnvLogLevel;
|
|
4202
|
+
exports.getLogContext = getLogContext;
|
|
3802
4203
|
exports.getPrimaryKeyTypes = getPrimaryKeyTypes;
|
|
3803
4204
|
exports.group = group;
|
|
3804
4205
|
exports.info = info;
|
|
@@ -3808,23 +4209,29 @@ exports.isNode = isNode;
|
|
|
3808
4209
|
exports.isTest = isTest;
|
|
3809
4210
|
exports.isVerbose = isVerbose;
|
|
3810
4211
|
exports.loadSqlAllowList = loadSqlAllowList;
|
|
4212
|
+
exports.logSql = logSql;
|
|
4213
|
+
exports.logWithLevel = logWithLevel;
|
|
3811
4214
|
exports.normalizeSingularRequest = normalizeSingularRequest;
|
|
3812
4215
|
exports.normalizeSql = normalizeSql;
|
|
3813
4216
|
exports.notifyToast = notifyToast;
|
|
3814
4217
|
exports.onError = onError;
|
|
3815
4218
|
exports.onSuccess = onSuccess;
|
|
4219
|
+
exports.parseLogLevel = parseLogLevel;
|
|
3816
4220
|
exports.removeInvalidKeys = removeInvalidKeys;
|
|
3817
4221
|
exports.removePrefixIfExists = removePrefixIfExists;
|
|
3818
4222
|
exports.resolveDerivedTable = resolveDerivedTable;
|
|
4223
|
+
exports.resolveLogLevel = resolveLogLevel;
|
|
3819
4224
|
exports.restOrm = restOrm;
|
|
3820
4225
|
exports.restRequest = restRequest;
|
|
3821
4226
|
exports.setCache = setCache;
|
|
3822
4227
|
exports.setToastHandler = setToastHandler;
|
|
4228
|
+
exports.shouldLog = shouldLog;
|
|
3823
4229
|
exports.sortAndSerializeQueryObject = sortAndSerializeQueryObject;
|
|
3824
4230
|
exports.stContains = stContains;
|
|
3825
4231
|
exports.timeout = timeout;
|
|
3826
4232
|
exports.toastOptions = toastOptions;
|
|
3827
4233
|
exports.toastOptionsDevs = toastOptionsDevs;
|
|
3828
4234
|
exports.userCustomClearCache = userCustomClearCache;
|
|
4235
|
+
exports.versionColor = versionToRgb;
|
|
3829
4236
|
exports.warn = warn;
|
|
3830
4237
|
//# sourceMappingURL=index.cjs.js.map
|