@carbonorm/carbonnode 6.0.7 → 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 +445 -169
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.esm.js +437 -170
- package/dist/index.esm.js.map +1 -1
- package/dist/types/ormInterfaces.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/isVerbose.d.ts +1 -1
- package/package.json +2 -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__/versionColor.test.ts +42 -0
- package/src/api/convertForRequestBody.ts +8 -1
- package/src/api/restRequest.ts +5 -4
- package/src/executors/Executor.ts +11 -2
- package/src/executors/HttpExecutor.ts +91 -53
- package/src/executors/SqlExecutor.ts +151 -40
- package/src/handlers/ExpressHandler.ts +7 -1
- package/src/index.ts +5 -0
- 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 -14
- 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 +2 -2
- 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 +6 -4
- package/src/variables/isVerbose.ts +4 -4
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,102 +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
|
-
/** biome-ignore-all lint/suspicious/noExplicitAny: working with global browser objects */
|
|
438
|
-
function getRuntimeEnv(key) {
|
|
439
|
-
var _a;
|
|
440
|
-
return typeof window !== "undefined" && ((_a = window.__ENV__) === null || _a === void 0 ? void 0 : _a[key]);
|
|
441
|
-
}
|
|
442
|
-
// Do not import anything here
|
|
443
|
-
function getViteEnv(key) {
|
|
444
|
-
var _a;
|
|
445
|
-
// @ts-expect-error
|
|
446
|
-
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]);
|
|
447
|
-
}
|
|
448
|
-
function getEnv(key, fallback) {
|
|
449
|
-
var _a;
|
|
450
|
-
try {
|
|
451
|
-
var viteEnv = getViteEnv(key);
|
|
452
|
-
if (viteEnv !== undefined)
|
|
453
|
-
return viteEnv;
|
|
454
|
-
}
|
|
455
|
-
catch (_b) { }
|
|
456
|
-
var runtimeEnv = getRuntimeEnv(key);
|
|
457
|
-
if (runtimeEnv !== undefined)
|
|
458
|
-
return runtimeEnv;
|
|
459
|
-
if (typeof process !== "undefined" && ((_a = process.env) === null || _a === void 0 ? void 0 : _a[key]) !== undefined) {
|
|
460
|
-
return process.env[key];
|
|
461
|
-
}
|
|
462
|
-
if (fallback !== undefined)
|
|
463
|
-
return fallback;
|
|
464
|
-
throw new Error("Missing environment variable: ".concat(key));
|
|
465
|
-
}
|
|
466
|
-
function getEnvBool(key, fallback) {
|
|
467
|
-
if (fallback === void 0) { fallback = false; }
|
|
468
|
-
var raw = getEnv(key, fallback);
|
|
469
|
-
var v = String(raw).trim().toLowerCase();
|
|
470
|
-
return (v === "true" ||
|
|
471
|
-
v === "1" ||
|
|
472
|
-
v === "yes" ||
|
|
473
|
-
v === "y" ||
|
|
474
|
-
v === "on" ||
|
|
475
|
-
v === "enabled");
|
|
476
|
-
}
|
|
477
|
-
function getEnvDebug(key, fallback) {
|
|
478
|
-
var _a;
|
|
479
|
-
try {
|
|
480
|
-
var viteEnv = getViteEnv(key);
|
|
481
|
-
if (viteEnv !== undefined) {
|
|
482
|
-
return { key: key, value: viteEnv, source: "vite" };
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
catch (_b) { }
|
|
486
|
-
var runtimeEnv = getRuntimeEnv(key);
|
|
487
|
-
if (runtimeEnv !== undefined) {
|
|
488
|
-
return { key: key, value: runtimeEnv, source: "runtime" };
|
|
489
|
-
}
|
|
490
|
-
if (typeof process !== "undefined" && ((_a = process.env) === null || _a === void 0 ? void 0 : _a[key]) !== undefined) {
|
|
491
|
-
return { key: key, value: process.env[key], source: "process" };
|
|
492
|
-
}
|
|
493
|
-
if (fallback !== undefined) {
|
|
494
|
-
return { key: key, value: fallback, source: "fallback" };
|
|
495
|
-
}
|
|
496
|
-
return { key: key, value: undefined, source: "missing" };
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
function isVerbose () {
|
|
500
|
-
return getEnvBool('VERBOSE', false) || getEnvBool('REACT_APP_VERBOSE', false) || getEnvBool('VITE_VERBOSE', false);
|
|
501
|
-
}
|
|
502
|
-
|
|
503
641
|
/**
|
|
504
642
|
* Facade: routes API calls to SQL or HTTP executors based on runtime context.
|
|
505
643
|
*/
|
|
506
644
|
function restRequest(configX) {
|
|
507
645
|
var _this = this;
|
|
508
646
|
return function (request) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
509
|
-
var config, SqlExecutor, executor, HttpExecutor, http;
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
switch (_b.label) {
|
|
647
|
+
var config, logContext, SqlExecutor, executor, HttpExecutor, http;
|
|
648
|
+
return tslib.__generator(this, function (_a) {
|
|
649
|
+
switch (_a.label) {
|
|
513
650
|
case 0:
|
|
514
651
|
config = typeof configX === "function" ? configX() : configX;
|
|
515
|
-
(
|
|
652
|
+
applyLogLevelDefaults(config, request);
|
|
653
|
+
logContext = getLogContext(config, request);
|
|
516
654
|
if (!config.mysqlPool && !config.axios) {
|
|
517
655
|
throw new Error("No execution method available: neither mysqlPool nor axios instance provided in config.");
|
|
518
656
|
}
|
|
519
657
|
if (!config.mysqlPool) return [3 /*break*/, 2];
|
|
520
|
-
|
|
658
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "Using SQL Executor");
|
|
521
659
|
return [4 /*yield*/, Promise.resolve().then(function () { return SqlExecutor$1; })];
|
|
522
660
|
case 1:
|
|
523
|
-
SqlExecutor = (
|
|
661
|
+
SqlExecutor = (_a.sent()).SqlExecutor;
|
|
524
662
|
executor = new SqlExecutor(config, request);
|
|
525
663
|
return [2 /*return*/, executor.execute()];
|
|
526
664
|
case 2:
|
|
527
|
-
|
|
665
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "Using HTTP Executor", {
|
|
528
666
|
isNode: isNode(),
|
|
529
667
|
});
|
|
530
668
|
return [4 /*yield*/, Promise.resolve().then(function () { return HttpExecutor$1; })];
|
|
531
669
|
case 3:
|
|
532
|
-
HttpExecutor = (
|
|
670
|
+
HttpExecutor = (_a.sent()).HttpExecutor;
|
|
533
671
|
http = new HttpExecutor(config, request);
|
|
534
672
|
return [2 /*return*/, http.execute()];
|
|
535
673
|
}
|
|
@@ -566,10 +704,11 @@ var Executor = /** @class */ (function () {
|
|
|
566
704
|
this.config = config;
|
|
567
705
|
this.request = request;
|
|
568
706
|
this.useNamedParams = useNamedParams;
|
|
707
|
+
applyLogLevelDefaults(this.config, this.request);
|
|
569
708
|
}
|
|
570
709
|
Executor.prototype.runLifecycleHooks = function (phase, args) {
|
|
571
710
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
572
|
-
var lifecycleGroup, _i, _a, _b, key, fn, err_1;
|
|
711
|
+
var lifecycleGroup, logContext, _i, _a, _b, key, fn, err_1;
|
|
573
712
|
var _c;
|
|
574
713
|
return tslib.__generator(this, function (_d) {
|
|
575
714
|
switch (_d.label) {
|
|
@@ -577,13 +716,14 @@ var Executor = /** @class */ (function () {
|
|
|
577
716
|
lifecycleGroup = (_c = this.config.restModel.LIFECYCLE_HOOKS[this.config.requestMethod]) === null || _c === void 0 ? void 0 : _c[phase];
|
|
578
717
|
if (!lifecycleGroup)
|
|
579
718
|
return [2 /*return*/];
|
|
719
|
+
logContext = getLogContext(this.config, args.request);
|
|
580
720
|
_i = 0, _a = Object.entries(lifecycleGroup);
|
|
581
721
|
_d.label = 1;
|
|
582
722
|
case 1:
|
|
583
723
|
if (!(_i < _a.length)) return [3 /*break*/, 6];
|
|
584
724
|
_b = _a[_i], key = _b[0], fn = _b[1];
|
|
585
725
|
if (!(typeof fn === "function")) return [3 /*break*/, 5];
|
|
586
|
-
if (
|
|
726
|
+
if (shouldLog(exports.LogLevel.DEBUG, logContext)) {
|
|
587
727
|
console.groupCollapsed("[LIFECYCLE] ".concat(this.config.requestMethod, ".").concat(String(phase), ":").concat(key));
|
|
588
728
|
console.log("config:", args.config);
|
|
589
729
|
console.log("request:", args.request);
|
|
@@ -603,7 +743,7 @@ var Executor = /** @class */ (function () {
|
|
|
603
743
|
return [3 /*break*/, 5];
|
|
604
744
|
case 4:
|
|
605
745
|
err_1 = _d.sent();
|
|
606
|
-
console.error
|
|
746
|
+
logWithLevel(exports.LogLevel.ERROR, logContext, console.error, "[LIFECYCLE ERROR] ".concat(this.config.requestMethod, ".").concat(String(phase), ":").concat(key), err_1);
|
|
607
747
|
throw err_1;
|
|
608
748
|
case 5:
|
|
609
749
|
_i++;
|
|
@@ -711,7 +851,9 @@ function removeInvalidKeys(request, c6Tables) {
|
|
|
711
851
|
intersection[key] = request[key];
|
|
712
852
|
}
|
|
713
853
|
});
|
|
714
|
-
isTest()
|
|
854
|
+
if (!isTest()) {
|
|
855
|
+
logWithLevel(exports.LogLevel.DEBUG, undefined, console.log, 'intersection', intersection);
|
|
856
|
+
}
|
|
715
857
|
return intersection;
|
|
716
858
|
}
|
|
717
859
|
|
|
@@ -743,7 +885,7 @@ function makeCacheKey(method, tableName, requestData) {
|
|
|
743
885
|
// -----------------------------------------------------------------------------
|
|
744
886
|
function clearCache(props) {
|
|
745
887
|
if (!(props === null || props === void 0 ? void 0 : props.ignoreWarning)) {
|
|
746
|
-
console.warn
|
|
888
|
+
logWithLevel(exports.LogLevel.WARN, undefined, console.warn, "The REST API clearCache should only be used with extreme care!");
|
|
747
889
|
}
|
|
748
890
|
for (var _i = 0, userCustomClearCache_1 = userCustomClearCache; _i < userCustomClearCache_1.length; _i++) {
|
|
749
891
|
var fn = userCustomClearCache_1[_i];
|
|
@@ -762,9 +904,11 @@ function checkCache(method, tableName, requestData) {
|
|
|
762
904
|
var cached = apiRequestCache.get(key);
|
|
763
905
|
if (!cached)
|
|
764
906
|
return false;
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
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
|
+
}
|
|
768
912
|
return cached.request;
|
|
769
913
|
}
|
|
770
914
|
// -----------------------------------------------------------------------------
|
|
@@ -829,7 +973,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
829
973
|
catch ( /* best-effort */_d) { /* best-effort */ }
|
|
830
974
|
}
|
|
831
975
|
else if (isLocal()) {
|
|
832
|
-
console.error
|
|
976
|
+
logWithLevel(exports.LogLevel.ERROR, getLogContext(this.config, this.request), console.error, "C6 received unexpected results given the primary key length");
|
|
833
977
|
}
|
|
834
978
|
(_b = this.config.reactBootstrap) === null || _b === void 0 ? void 0 : _b.updateRestfulObjectArrays({
|
|
835
979
|
callback: callback,
|
|
@@ -860,11 +1004,10 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
860
1004
|
};
|
|
861
1005
|
HttpExecutor.prototype.execute = function () {
|
|
862
1006
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
863
|
-
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;
|
|
864
1008
|
var _this = this;
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
switch (_c.label) {
|
|
1009
|
+
return tslib.__generator(this, function (_b) {
|
|
1010
|
+
switch (_b.label) {
|
|
868
1011
|
case 0:
|
|
869
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;
|
|
870
1013
|
return [4 /*yield*/, this.runLifecycleHooks("beforeProcessing", {
|
|
@@ -872,7 +1015,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
872
1015
|
request: this.request,
|
|
873
1016
|
})];
|
|
874
1017
|
case 1:
|
|
875
|
-
|
|
1018
|
+
_b.sent();
|
|
876
1019
|
tableName = restModel.TABLE_NAME;
|
|
877
1020
|
fullTableList = Array.isArray(tableName) ? tableName : [tableName];
|
|
878
1021
|
operatingTableFullName = fullTableList[0];
|
|
@@ -890,7 +1033,10 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
890
1033
|
if (clearCache != null) {
|
|
891
1034
|
userCustomClearCache.push(clearCache);
|
|
892
1035
|
}
|
|
893
|
-
|
|
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)) {
|
|
894
1040
|
console.groupCollapsed('%c API:', 'color: #0c0', "(".concat(requestMethod, ") Request for (").concat(tableName, ")"));
|
|
895
1041
|
console.log('request', this.request);
|
|
896
1042
|
console.groupEnd();
|
|
@@ -900,15 +1046,16 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
900
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;
|
|
901
1047
|
var _e;
|
|
902
1048
|
var _this = this;
|
|
903
|
-
var _f, _g, _h, _j, _k, _l
|
|
904
|
-
return tslib.__generator(this, function (
|
|
905
|
-
switch (
|
|
1049
|
+
var _f, _g, _h, _j, _k, _l;
|
|
1050
|
+
return tslib.__generator(this, function (_m) {
|
|
1051
|
+
switch (_m.label) {
|
|
906
1052
|
case 0:
|
|
907
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;
|
|
908
1054
|
if (C6.GET === requestMethod
|
|
909
1055
|
&& undefined !== ((_f = query === null || query === void 0 ? void 0 : query[C6.PAGINATION]) === null || _f === void 0 ? void 0 : _f[C6.PAGE])
|
|
910
1056
|
&& 1 !== query[C6.PAGINATION][C6.PAGE]
|
|
911
|
-
&& isLocal()
|
|
1057
|
+
&& isLocal()
|
|
1058
|
+
&& shouldLog(exports.LogLevel.DEBUG, logContext)) {
|
|
912
1059
|
console.groupCollapsed("Request (".concat(tableName, ") page (").concat(query[C6.PAGINATION][C6.PAGE], ")"));
|
|
913
1060
|
console.log('request', this.request);
|
|
914
1061
|
console.groupEnd();
|
|
@@ -933,7 +1080,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
933
1080
|
}
|
|
934
1081
|
if (!cachedRequest) return [3 /*break*/, 2];
|
|
935
1082
|
return [4 /*yield*/, cachedRequest];
|
|
936
|
-
case 1: return [2 /*return*/, (
|
|
1083
|
+
case 1: return [2 /*return*/, (_m.sent()).data];
|
|
937
1084
|
case 2:
|
|
938
1085
|
if (cacheResults) {
|
|
939
1086
|
cachingConfirmed = true;
|
|
@@ -958,7 +1105,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
958
1105
|
(Array.isArray(whereVal) && whereVal.length === 0) ||
|
|
959
1106
|
(typeof whereVal === 'object' && !Array.isArray(whereVal) && Object.keys(whereVal).length === 0);
|
|
960
1107
|
if (whereIsEmpty) {
|
|
961
|
-
console.error
|
|
1108
|
+
logWithLevel(exports.LogLevel.ERROR, logContext, console.error, query);
|
|
962
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 + ').');
|
|
963
1110
|
}
|
|
964
1111
|
}
|
|
@@ -988,23 +1135,23 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
988
1135
|
primaryVal = (_l = query[primaryKey]) !== null && _l !== void 0 ? _l : (primaryKeyFullyQualified ? query[primaryKeyFullyQualified] : undefined);
|
|
989
1136
|
if (undefined !== primaryVal) {
|
|
990
1137
|
restRequestUri += primaryVal + '/';
|
|
991
|
-
if (isLocal() && (
|
|
1138
|
+
if (isLocal() && shouldLog(exports.LogLevel.DEBUG, logContext)) {
|
|
992
1139
|
console.log('query', query, 'primaryKey', primaryKey);
|
|
993
1140
|
}
|
|
994
1141
|
}
|
|
995
1142
|
else {
|
|
996
|
-
if (isLocal() && (
|
|
1143
|
+
if (isLocal() && shouldLog(exports.LogLevel.DEBUG, logContext)) {
|
|
997
1144
|
console.log('query', query);
|
|
998
1145
|
}
|
|
999
1146
|
}
|
|
1000
1147
|
}
|
|
1001
1148
|
else {
|
|
1002
|
-
if (isLocal() && (
|
|
1149
|
+
if (isLocal() && shouldLog(exports.LogLevel.DEBUG, logContext)) {
|
|
1003
1150
|
console.log('query', query);
|
|
1004
1151
|
}
|
|
1005
1152
|
}
|
|
1006
1153
|
try {
|
|
1007
|
-
if (isLocal() && (
|
|
1154
|
+
if (isLocal() && shouldLog(exports.LogLevel.DEBUG, logContext)) {
|
|
1008
1155
|
console.groupCollapsed('%c API:', 'color: #A020F0', "(".concat(requestMethod, ") (").concat(operatingTable, ") firing"));
|
|
1009
1156
|
console.log(this.request);
|
|
1010
1157
|
console.groupEnd();
|
|
@@ -1065,7 +1212,9 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1065
1212
|
});
|
|
1066
1213
|
}
|
|
1067
1214
|
if (isTest()) {
|
|
1068
|
-
|
|
1215
|
+
if (shouldLog(exports.LogLevel.TRACE, logContext)) {
|
|
1216
|
+
console.trace();
|
|
1217
|
+
}
|
|
1069
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 + ')');
|
|
1070
1219
|
}
|
|
1071
1220
|
return [2 /*return*/, Promise.reject(response)];
|
|
@@ -1139,7 +1288,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1139
1288
|
final: !hasNext,
|
|
1140
1289
|
});
|
|
1141
1290
|
}
|
|
1142
|
-
if ((
|
|
1291
|
+
if (isLocal() && shouldLog(exports.LogLevel.DEBUG, logContext)) {
|
|
1143
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], ")"));
|
|
1144
1293
|
console.log('request', this.request);
|
|
1145
1294
|
console.log('response.rest', responseData_1.rest);
|
|
@@ -1148,14 +1297,18 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1148
1297
|
if (!(fetchDependencies
|
|
1149
1298
|
&& 'number' === typeof fetchDependencies
|
|
1150
1299
|
&& ((_d = responseData_1.rest) === null || _d === void 0 ? void 0 : _d.length) > 0)) return [3 /*break*/, 2];
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
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
|
+
}
|
|
1159
1312
|
dependencies_1 = {};
|
|
1160
1313
|
// Remember this is a binary bitwise operation, so we can check for multiple dependencies at once
|
|
1161
1314
|
if (fetchDependencies & exports.eFetchDependencies.C6ENTITY) {
|
|
@@ -1190,7 +1343,9 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1190
1343
|
}
|
|
1191
1344
|
fetchReferences_1 = {};
|
|
1192
1345
|
apiRequestPromises = [];
|
|
1193
|
-
|
|
1346
|
+
if (debugEnabled) {
|
|
1347
|
+
console.log('%c Dependencies', 'color: #005555', dependencies_1);
|
|
1348
|
+
}
|
|
1194
1349
|
Object.keys(dependencies_1)
|
|
1195
1350
|
.forEach(function (column) { return dependencies_1[column]
|
|
1196
1351
|
.forEach(function (constraint) {
|
|
@@ -1216,7 +1371,9 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1216
1371
|
(_d = (_f = fetchReferences_1[constraint.TABLE])[_g = constraint.COLUMN]) !== null && _d !== void 0 ? _d : (_f[_g] = []);
|
|
1217
1372
|
fetchReferences_1[constraint.TABLE][constraint.COLUMN].push(columnValues);
|
|
1218
1373
|
}); });
|
|
1219
|
-
|
|
1374
|
+
if (debugEnabled) {
|
|
1375
|
+
console.log('fetchReferences', fetchReferences_1);
|
|
1376
|
+
}
|
|
1220
1377
|
_loop_1 = function (tableToFetch) {
|
|
1221
1378
|
var _g;
|
|
1222
1379
|
if (fetchDependencies & exports.eFetchDependencies.C6ENTITY
|
|
@@ -1232,17 +1389,23 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1232
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(); });
|
|
1233
1390
|
var shouldContinue = referencesTables.find(function (referencesTable) { return tableToFetch.endsWith(referencesTable); });
|
|
1234
1391
|
if (!shouldContinue) {
|
|
1235
|
-
|
|
1392
|
+
if (debugEnabled) {
|
|
1393
|
+
console.log('%c C6ENTITY: The constraintTableName (' + tableToFetch + ') did not end with any value in referencesTables', 'color: #c00', referencesTables);
|
|
1394
|
+
}
|
|
1236
1395
|
return "continue";
|
|
1237
1396
|
}
|
|
1238
|
-
|
|
1397
|
+
if (debugEnabled) {
|
|
1398
|
+
console.log('%c C6ENTITY: The constraintTableName (' + tableToFetch + ') will be fetched.', 'color: #0c0');
|
|
1399
|
+
}
|
|
1239
1400
|
}
|
|
1240
1401
|
var ormKey = tableToFetch
|
|
1241
1402
|
.split('_')
|
|
1242
1403
|
.map(function (part) { return part.charAt(0).toUpperCase() + part.slice(1); })
|
|
1243
1404
|
.join('_');
|
|
1244
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(', '), " ]"));
|
|
1245
|
-
|
|
1406
|
+
if (debugEnabled) {
|
|
1407
|
+
console.log('%c Fetch Dependencies will select (' + tableToFetch + ') using GET request', 'color: #33ccff');
|
|
1408
|
+
}
|
|
1246
1409
|
var nextFetchDependencies = exports.eFetchDependencies.NONE;
|
|
1247
1410
|
if (fetchDependencies & exports.eFetchDependencies.RECURSIVE) {
|
|
1248
1411
|
var hasParents = !!(fetchDependencies & exports.eFetchDependencies.PARENTS);
|
|
@@ -1261,17 +1424,21 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1261
1424
|
nextFetchDependencies = fetchDependencies ^ exports.eFetchDependencies.C6ENTITY;
|
|
1262
1425
|
}
|
|
1263
1426
|
}
|
|
1264
|
-
|
|
1427
|
+
if (debugEnabled) {
|
|
1428
|
+
console.log('fetchReferences', fetchReferences_1[tableToFetch], "Current fetchDependencies for (" + operatingTable + "):", fetchDependencies, "New fetchDependencies for (" + tableToFetch + "): ", nextFetchDependencies);
|
|
1429
|
+
}
|
|
1265
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
|
|
1266
1431
|
// it not certain that they are using carbons' entities either
|
|
1267
|
-
|
|
1432
|
+
if (debugEnabled) {
|
|
1433
|
+
console.log('RestApi object', RestApi);
|
|
1434
|
+
}
|
|
1268
1435
|
// this is a dynamic call to the rest api, any generated table may resolve with (RestApi)
|
|
1269
1436
|
// todo - using value to avoid joins.... but. maybe this should be a parameterizable option -- think race conditions; its safer to join
|
|
1270
1437
|
apiRequestPromises.push(RestApi.Get((_g = {},
|
|
1271
1438
|
_g[C6.WHERE] = Object.keys(fetchReferences_1[tableToFetch]).reduce(function (sum, column) {
|
|
1272
1439
|
fetchReferences_1[tableToFetch][column] = fetchReferences_1[tableToFetch][column].flat(Infinity);
|
|
1273
1440
|
if (0 === fetchReferences_1[tableToFetch][column].length) {
|
|
1274
|
-
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);
|
|
1275
1442
|
return false;
|
|
1276
1443
|
}
|
|
1277
1444
|
sum["".concat(tableToFetch, ".").concat(column)] = fetchReferences_1[tableToFetch][column].length === 1
|
|
@@ -1287,7 +1454,9 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1287
1454
|
for (tableToFetch in fetchReferences_1) {
|
|
1288
1455
|
_loop_1(tableToFetch);
|
|
1289
1456
|
}
|
|
1290
|
-
|
|
1457
|
+
if (debugEnabled) {
|
|
1458
|
+
console.groupEnd();
|
|
1459
|
+
}
|
|
1291
1460
|
return [4 /*yield*/, Promise.all(apiRequestPromises)];
|
|
1292
1461
|
case 1:
|
|
1293
1462
|
_f.sent();
|
|
@@ -1328,11 +1497,15 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1328
1497
|
}); }).then(function (response) { return response.data; })]; // this escapes from axios context
|
|
1329
1498
|
}
|
|
1330
1499
|
catch (throwableError) {
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
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
|
+
}
|
|
1336
1509
|
throw throwableError;
|
|
1337
1510
|
}
|
|
1338
1511
|
return [2 /*return*/];
|
|
@@ -1340,7 +1513,7 @@ var HttpExecutor = /** @class */ (function (_super) {
|
|
|
1340
1513
|
});
|
|
1341
1514
|
}); };
|
|
1342
1515
|
return [4 /*yield*/, apiRequest()];
|
|
1343
|
-
case 2: return [2 /*return*/,
|
|
1516
|
+
case 2: return [2 /*return*/, _b.sent()];
|
|
1344
1517
|
}
|
|
1345
1518
|
});
|
|
1346
1519
|
});
|
|
@@ -1433,7 +1606,7 @@ var AggregateBuilder = /** @class */ (function (_super) {
|
|
|
1433
1606
|
this.selectAliases.add(alias);
|
|
1434
1607
|
expr_1 += " AS ".concat(alias);
|
|
1435
1608
|
}
|
|
1436
|
-
this.config.
|
|
1609
|
+
logWithLevel(exports.LogLevel.DEBUG, getLogContext(this.config, this.request), console.log, "[SELECT] ".concat(expr_1));
|
|
1437
1610
|
return expr_1;
|
|
1438
1611
|
}
|
|
1439
1612
|
var identifierPathRegex = /^[A-Za-z_][A-Za-z0-9_]*\.[A-Za-z_][A-Za-z0-9_]*$/;
|
|
@@ -1474,7 +1647,7 @@ var AggregateBuilder = /** @class */ (function (_super) {
|
|
|
1474
1647
|
this.selectAliases.add(alias);
|
|
1475
1648
|
expr += " AS ".concat(alias);
|
|
1476
1649
|
}
|
|
1477
|
-
this.config.
|
|
1650
|
+
logWithLevel(exports.LogLevel.DEBUG, getLogContext(this.config, this.request), console.log, "[SELECT] ".concat(expr));
|
|
1478
1651
|
return expr;
|
|
1479
1652
|
};
|
|
1480
1653
|
return AggregateBuilder;
|
|
@@ -2123,7 +2296,7 @@ var ConditionBuilder = /** @class */ (function (_super) {
|
|
|
2123
2296
|
break;
|
|
2124
2297
|
}
|
|
2125
2298
|
var clause = "(MATCH(".concat(leftInfo_1.sql, ") ").concat(againstClause, ")");
|
|
2126
|
-
this.config.
|
|
2299
|
+
logWithLevel(exports.LogLevel.DEBUG, getLogContext(this.config, this.request), console.log, "[MATCH_AGAINST] ".concat(clause));
|
|
2127
2300
|
return clause;
|
|
2128
2301
|
}
|
|
2129
2302
|
var operands = Array.isArray(rawOperands) ? rawOperands : [rawOperands];
|
|
@@ -2372,7 +2545,7 @@ var ConditionBuilder = /** @class */ (function (_super) {
|
|
|
2372
2545
|
}
|
|
2373
2546
|
}
|
|
2374
2547
|
}
|
|
2375
|
-
this.config.
|
|
2548
|
+
logWithLevel(exports.LogLevel.DEBUG, getLogContext(this.config, this.request), console.log, "[WHERE] ".concat(trimmed));
|
|
2376
2549
|
return " WHERE ".concat(trimmed);
|
|
2377
2550
|
};
|
|
2378
2551
|
return ConditionBuilder;
|
|
@@ -2602,7 +2775,7 @@ var JoinBuilder = /** @class */ (function (_super) {
|
|
|
2602
2775
|
var _a = joinTypeEntries_1[_i], joinTypeRaw = _a[0], joinSection = _a[1];
|
|
2603
2776
|
_loop_1(joinTypeRaw, joinSection);
|
|
2604
2777
|
}
|
|
2605
|
-
this.config.
|
|
2778
|
+
logWithLevel(exports.LogLevel.DEBUG, getLogContext(this.config, this.request), console.log, "[JOIN] ".concat(sql.trim()));
|
|
2606
2779
|
return sql;
|
|
2607
2780
|
};
|
|
2608
2781
|
JoinBuilder.prototype.integrateSubSelectParams = function (subSql, subParams, target) {
|
|
@@ -2719,7 +2892,7 @@ var PaginationBuilder = /** @class */ (function (_super) {
|
|
|
2719
2892
|
sql += " LIMIT ".concat(offset, ", ").concat(lim);
|
|
2720
2893
|
}
|
|
2721
2894
|
}
|
|
2722
|
-
this.config.
|
|
2895
|
+
logWithLevel(exports.LogLevel.DEBUG, getLogContext(this.config, this.request), console.log, "[PAGINATION] ".concat(sql.trim()));
|
|
2723
2896
|
return sql;
|
|
2724
2897
|
};
|
|
2725
2898
|
return PaginationBuilder;
|
|
@@ -2736,7 +2909,7 @@ var C$1 = {
|
|
|
2736
2909
|
/* ---------- ANSI helpers ---------- */
|
|
2737
2910
|
var ansi256 = function (n) { return "\u001B[38;5;".concat(n, "m"); };
|
|
2738
2911
|
/* ---------- hashing ---------- */
|
|
2739
|
-
function hashString(str) {
|
|
2912
|
+
function hashString$1(str) {
|
|
2740
2913
|
var hash = 0;
|
|
2741
2914
|
for (var i = 0; i < str.length; i++) {
|
|
2742
2915
|
hash = (hash * 31 + str.charCodeAt(i)) | 0;
|
|
@@ -2746,7 +2919,7 @@ function hashString(str) {
|
|
|
2746
2919
|
/* ---------- table color ---------- */
|
|
2747
2920
|
function tableRGB(tableName) {
|
|
2748
2921
|
var name = tableName.replace(/[`"]/g, "").toLowerCase();
|
|
2749
|
-
var hash = hashString(name);
|
|
2922
|
+
var hash = hashString$1(name);
|
|
2750
2923
|
// Stable hue bucket by first letter
|
|
2751
2924
|
var first = name.charCodeAt(0) || 97;
|
|
2752
2925
|
var hueBase = (first - 97) % 6;
|
|
@@ -2794,20 +2967,101 @@ function colorSql(sql) {
|
|
|
2794
2967
|
return "".concat(C$1.KEYWORD).concat(kw).concat(RESET, " ").concat(tableColor(table)).concat(table).concat(RESET);
|
|
2795
2968
|
});
|
|
2796
2969
|
/* 4️⃣ SQL keywords */
|
|
2797
|
-
s = s.replace(/\b(SELECT|WHERE|AND|OR|ON|IN|BETWEEN|EXISTS|ORDER BY)\b/gi, "".concat(C$1.KEYWORD, "$1").concat(RESET));
|
|
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));
|
|
2798
2971
|
/* 5️⃣ LIMIT */
|
|
2799
2972
|
s = s.replace(/\bLIMIT\s+(\d+)/gi, "".concat(C$1.LIMIT, "LIMIT").concat(RESET, " ").concat(C$1.NUMBER, "$1").concat(RESET));
|
|
2800
2973
|
return s;
|
|
2801
2974
|
}
|
|
2802
2975
|
|
|
2803
|
-
var version = "6.0.
|
|
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
|
+
}
|
|
2804
3014
|
|
|
2805
3015
|
var C = {
|
|
2806
3016
|
SSR: "\x1b[95m", // bright magenta
|
|
2807
3017
|
HTTP: "\x1b[94m", // bright blue
|
|
2808
|
-
|
|
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
|
+
],
|
|
2809
3033
|
RESET: "\x1b[0m",
|
|
2810
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
|
+
|
|
2811
3065
|
var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
2812
3066
|
tslib.__extends(SelectQueryBuilder, _super);
|
|
2813
3067
|
function SelectQueryBuilder() {
|
|
@@ -2859,8 +3113,7 @@ var SelectQueryBuilder = /** @class */ (function (_super) {
|
|
|
2859
3113
|
else if (!isSubSelect) {
|
|
2860
3114
|
sql += " LIMIT 100";
|
|
2861
3115
|
}
|
|
2862
|
-
|
|
2863
|
-
console.log("[".concat(version, "] ").concat(preText).concat(C.SQL, "[SELECT]").concat(C.RESET, " ").concat(colorSql(sql)));
|
|
3116
|
+
logSql("SELECT", sql, getLogContext(this.config, this.request));
|
|
2864
3117
|
return { sql: sql, params: params };
|
|
2865
3118
|
};
|
|
2866
3119
|
return SelectQueryBuilder;
|
|
@@ -2885,6 +3138,7 @@ var DeleteQueryBuilder = /** @class */ (function (_super) {
|
|
|
2885
3138
|
if (this.request.WHERE) {
|
|
2886
3139
|
sql += this.buildWhereClause(this.request.WHERE, params);
|
|
2887
3140
|
}
|
|
3141
|
+
logSql("DELETE", sql, getLogContext(this.config, this.request));
|
|
2888
3142
|
return { sql: sql, params: params };
|
|
2889
3143
|
};
|
|
2890
3144
|
return DeleteQueryBuilder;
|
|
@@ -2929,6 +3183,7 @@ var PostQueryBuilder = /** @class */ (function (_super) {
|
|
|
2929
3183
|
var updateClause = updateData.map(function (k) { return "`".concat(k, "` = VALUES(`").concat(k, "`)"); }).join(', ');
|
|
2930
3184
|
sql += " ON DUPLICATE KEY UPDATE ".concat(updateClause);
|
|
2931
3185
|
}
|
|
3186
|
+
logSql(verb, sql, getLogContext(this.config, this.request));
|
|
2932
3187
|
return { sql: sql, params: params };
|
|
2933
3188
|
};
|
|
2934
3189
|
return PostQueryBuilder;
|
|
@@ -2980,6 +3235,7 @@ var UpdateQueryBuilder = /** @class */ (function (_super) {
|
|
|
2980
3235
|
if (args.PAGINATION) {
|
|
2981
3236
|
sql += this.buildPaginationClause(args.PAGINATION, params);
|
|
2982
3237
|
}
|
|
3238
|
+
logSql("UPDATE", sql, getLogContext(this.config, this.request));
|
|
2983
3239
|
return { sql: sql, params: params };
|
|
2984
3240
|
};
|
|
2985
3241
|
return UpdateQueryBuilder;
|
|
@@ -3238,7 +3494,7 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3238
3494
|
}
|
|
3239
3495
|
SqlExecutor.prototype.execute = function () {
|
|
3240
3496
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
3241
|
-
var TABLE_NAME, method, _a, rest, result, result, result;
|
|
3497
|
+
var TABLE_NAME, method, logContext, _a, rest, result, result, result;
|
|
3242
3498
|
return tslib.__generator(this, function (_b) {
|
|
3243
3499
|
switch (_b.label) {
|
|
3244
3500
|
case 0:
|
|
@@ -3252,8 +3508,9 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3252
3508
|
// Surface normalization errors early
|
|
3253
3509
|
throw e;
|
|
3254
3510
|
}
|
|
3255
|
-
|
|
3256
|
-
|
|
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);
|
|
3257
3514
|
_a = method;
|
|
3258
3515
|
switch (_a) {
|
|
3259
3516
|
case 'GET': return [3 /*break*/, 1];
|
|
@@ -3301,22 +3558,23 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3301
3558
|
};
|
|
3302
3559
|
SqlExecutor.prototype.withConnection = function (cb) {
|
|
3303
3560
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
3304
|
-
var conn;
|
|
3561
|
+
var logContext, conn;
|
|
3305
3562
|
return tslib.__generator(this, function (_a) {
|
|
3306
3563
|
switch (_a.label) {
|
|
3307
3564
|
case 0:
|
|
3308
|
-
this.config
|
|
3565
|
+
logContext = getLogContext(this.config, this.request);
|
|
3566
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] \uD83D\uDCE1 Getting DB connection");
|
|
3309
3567
|
return [4 /*yield*/, this.config.mysqlPool.getConnection()];
|
|
3310
3568
|
case 1:
|
|
3311
3569
|
conn = _a.sent();
|
|
3312
3570
|
_a.label = 2;
|
|
3313
3571
|
case 2:
|
|
3314
3572
|
_a.trys.push([2, , 4, 5]);
|
|
3315
|
-
|
|
3573
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] \u2705 Connection acquired");
|
|
3316
3574
|
return [4 /*yield*/, cb(conn)];
|
|
3317
3575
|
case 3: return [2 /*return*/, _a.sent()];
|
|
3318
3576
|
case 4:
|
|
3319
|
-
|
|
3577
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] \uD83D\uDD0C Releasing DB connection");
|
|
3320
3578
|
conn.release();
|
|
3321
3579
|
return [7 /*endfinally*/];
|
|
3322
3580
|
case 5: return [2 /*return*/];
|
|
@@ -3492,19 +3750,20 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3492
3750
|
};
|
|
3493
3751
|
SqlExecutor.prototype.broadcastWebsocketIfConfigured = function (response) {
|
|
3494
3752
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
3495
|
-
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;
|
|
3496
3754
|
var _a, _b;
|
|
3497
3755
|
var _c, _d, _e;
|
|
3498
3756
|
return tslib.__generator(this, function (_f) {
|
|
3499
3757
|
switch (_f.label) {
|
|
3500
3758
|
case 0:
|
|
3501
3759
|
broadcast = this.config.websocketBroadcast;
|
|
3502
|
-
this.config
|
|
3760
|
+
logContext = getLogContext(this.config, this.request);
|
|
3761
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] 📣 broadcastWebsocketIfConfigured start", {
|
|
3503
3762
|
method: this.config.requestMethod,
|
|
3504
3763
|
hasBroadcast: Boolean(broadcast),
|
|
3505
3764
|
});
|
|
3506
3765
|
if (!broadcast || this.config.requestMethod === C6Constants.GET) {
|
|
3507
|
-
|
|
3766
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] 📣 websocket broadcast skipped", {
|
|
3508
3767
|
reason: !broadcast ? "no broadcast configured" : "GET request",
|
|
3509
3768
|
});
|
|
3510
3769
|
return [2 /*return*/];
|
|
@@ -3515,22 +3774,22 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3515
3774
|
validColumns = new Set(Object.values(columns));
|
|
3516
3775
|
responseRest = response === null || response === void 0 ? void 0 : response.rest;
|
|
3517
3776
|
responsePrimaryKey = this.extractPrimaryKeyValuesFromData(responseRest);
|
|
3518
|
-
|
|
3777
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] 📣 websocket request payload", {
|
|
3519
3778
|
normalizedRequest: normalizedRequest,
|
|
3520
3779
|
requestPrimaryKey: this.extractPrimaryKeyValues(),
|
|
3521
3780
|
pkShorts: pkShorts,
|
|
3522
3781
|
});
|
|
3523
|
-
|
|
3782
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] 📣 websocket response payload", {
|
|
3524
3783
|
responseRest: responseRest,
|
|
3525
3784
|
responsePrimaryKey: responsePrimaryKey,
|
|
3526
3785
|
});
|
|
3527
3786
|
if ((responseRest === null || (Array.isArray(responseRest) && responseRest.length === 0))
|
|
3528
3787
|
&& this.config.requestMethod === C6Constants.POST) {
|
|
3529
|
-
|
|
3788
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] 📣 response rest empty, attempting synthesize", {
|
|
3530
3789
|
responseRest: responseRest,
|
|
3531
3790
|
});
|
|
3532
3791
|
insertId = response === null || response === void 0 ? void 0 : response.insertId;
|
|
3533
|
-
|
|
3792
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] 📣 POST insertId lookup", {
|
|
3534
3793
|
insertId: insertId,
|
|
3535
3794
|
});
|
|
3536
3795
|
if (insertId !== undefined && pkShorts.length === 1) {
|
|
@@ -3551,7 +3810,7 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3551
3810
|
responsePrimaryKey = (_b = {},
|
|
3552
3811
|
_b[pkShorts[0]] = insertId,
|
|
3553
3812
|
_b);
|
|
3554
|
-
|
|
3813
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] 📣 synthesized response payload", {
|
|
3555
3814
|
synthesized: synthesized,
|
|
3556
3815
|
responsePrimaryKey: responsePrimaryKey,
|
|
3557
3816
|
});
|
|
@@ -3568,21 +3827,19 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3568
3827
|
RESPONSE_PRIMARY_KEY: responsePrimaryKey,
|
|
3569
3828
|
},
|
|
3570
3829
|
};
|
|
3571
|
-
|
|
3830
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] 📣 websocket payload ready", payload);
|
|
3572
3831
|
_f.label = 1;
|
|
3573
3832
|
case 1:
|
|
3574
3833
|
_f.trys.push([1, 3, , 4]);
|
|
3575
|
-
|
|
3834
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] 📣 websocket broadcast dispatch start");
|
|
3576
3835
|
return [4 /*yield*/, broadcast(payload)];
|
|
3577
3836
|
case 2:
|
|
3578
3837
|
_f.sent();
|
|
3579
|
-
|
|
3838
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] 📣 websocket broadcast dispatch complete");
|
|
3580
3839
|
return [3 /*break*/, 4];
|
|
3581
3840
|
case 3:
|
|
3582
3841
|
error_1 = _f.sent();
|
|
3583
|
-
|
|
3584
|
-
console.error("[SQL EXECUTOR] websocketBroadcast failed", error_1);
|
|
3585
|
-
}
|
|
3842
|
+
logWithLevel(exports.LogLevel.ERROR, logContext, console.error, "[SQL EXECUTOR] websocketBroadcast failed", error_1);
|
|
3586
3843
|
return [3 /*break*/, 4];
|
|
3587
3844
|
case 4: return [2 /*return*/];
|
|
3588
3845
|
}
|
|
@@ -3591,7 +3848,7 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3591
3848
|
};
|
|
3592
3849
|
SqlExecutor.prototype.runQuery = function () {
|
|
3593
3850
|
return tslib.__awaiter(this, void 0, void 0, function () {
|
|
3594
|
-
var TABLE_NAME, method, builder, QueryResult, formatted, toUnnamed, _a, sql, values;
|
|
3851
|
+
var TABLE_NAME, method, builder, QueryResult, logContext, formatted, toUnnamed, _a, sql, values;
|
|
3595
3852
|
var _this = this;
|
|
3596
3853
|
return tslib.__generator(this, function (_b) {
|
|
3597
3854
|
switch (_b.label) {
|
|
@@ -3615,9 +3872,10 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3615
3872
|
throw new Error("Unsupported query method: ".concat(method));
|
|
3616
3873
|
}
|
|
3617
3874
|
QueryResult = builder.build(TABLE_NAME);
|
|
3618
|
-
|
|
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);
|
|
3619
3877
|
formatted = this.formatSQLWithParams(QueryResult.sql, QueryResult.params);
|
|
3620
|
-
|
|
3878
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] \uD83E\uDDE0 Formatted ".concat(method.toUpperCase(), " SQL:"), formatted);
|
|
3621
3879
|
toUnnamed = namedPlaceholders();
|
|
3622
3880
|
_a = toUnnamed(QueryResult.sql, QueryResult.params), sql = _a[0], values = _a[1];
|
|
3623
3881
|
return [4 /*yield*/, this.validateSqlAllowList(sql)];
|
|
@@ -3637,7 +3895,7 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3637
3895
|
}];
|
|
3638
3896
|
}
|
|
3639
3897
|
else {
|
|
3640
|
-
|
|
3898
|
+
logWithLevel(exports.LogLevel.DEBUG, logContext, console.log, "[SQL EXECUTOR] \u270F\uFE0F Rows affected:", result.affectedRows);
|
|
3641
3899
|
return [2 /*return*/, {
|
|
3642
3900
|
affected: result.affectedRows,
|
|
3643
3901
|
insertId: result.insertId,
|
|
@@ -3712,7 +3970,7 @@ function ExpressHandler(_a) {
|
|
|
3712
3970
|
}
|
|
3713
3971
|
// Warn for unsupported overrides but continue normally
|
|
3714
3972
|
if (incomingMethod !== 'GET' && methodOverride && methodOverride !== 'GET') {
|
|
3715
|
-
console.warn
|
|
3973
|
+
logWithLevel(exports.LogLevel.WARN, undefined, console.warn, "Ignoring unsupported METHOD override: ".concat(methodOverride));
|
|
3716
3974
|
}
|
|
3717
3975
|
if (!(table in C6.TABLES)) {
|
|
3718
3976
|
res.status(400).json({ error: "Invalid table: ".concat(table) });
|
|
@@ -3836,10 +4094,9 @@ function getPrimaryKeyTypes(table) {
|
|
|
3836
4094
|
return result;
|
|
3837
4095
|
}
|
|
3838
4096
|
|
|
3839
|
-
/**
|
|
3840
|
-
* Conditionally group a log if verbose.
|
|
3841
|
-
*/
|
|
3842
4097
|
function group(title, data) {
|
|
4098
|
+
if (!shouldLog(exports.LogLevel.DEBUG))
|
|
4099
|
+
return;
|
|
3843
4100
|
console.groupCollapsed("%c".concat(title), "color: #007acc");
|
|
3844
4101
|
if (data !== undefined)
|
|
3845
4102
|
console.log(data);
|
|
@@ -3850,6 +4107,8 @@ function info(message) {
|
|
|
3850
4107
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
3851
4108
|
optional[_i - 1] = arguments[_i];
|
|
3852
4109
|
}
|
|
4110
|
+
if (!shouldLog(exports.LogLevel.INFO))
|
|
4111
|
+
return;
|
|
3853
4112
|
console.info.apply(console, tslib.__spreadArray(["%cINFO: ".concat(message), "color: #0a0"], optional, false));
|
|
3854
4113
|
}
|
|
3855
4114
|
function warn(message) {
|
|
@@ -3857,6 +4116,8 @@ function warn(message) {
|
|
|
3857
4116
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
3858
4117
|
optional[_i - 1] = arguments[_i];
|
|
3859
4118
|
}
|
|
4119
|
+
if (!shouldLog(exports.LogLevel.WARN))
|
|
4120
|
+
return;
|
|
3860
4121
|
console.warn.apply(console, tslib.__spreadArray(["%cWARN: ".concat(message), "color: #e90"], optional, false));
|
|
3861
4122
|
}
|
|
3862
4123
|
function error(message) {
|
|
@@ -3864,6 +4125,8 @@ function error(message) {
|
|
|
3864
4125
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
3865
4126
|
optional[_i - 1] = arguments[_i];
|
|
3866
4127
|
}
|
|
4128
|
+
if (!shouldLog(exports.LogLevel.ERROR))
|
|
4129
|
+
return;
|
|
3867
4130
|
console.error.apply(console, tslib.__spreadArray(["%cERROR: ".concat(message), "color: #c00"], optional, false));
|
|
3868
4131
|
}
|
|
3869
4132
|
|
|
@@ -3875,7 +4138,7 @@ function checkAllRequestsComplete() {
|
|
|
3875
4138
|
throw new Error('document is undefined while waiting for API requests to complete (' + JSON.stringify(cacheEntries) + ')');
|
|
3876
4139
|
}
|
|
3877
4140
|
// when requests return emtpy sets in full renders, it may not be possible to track their progress.
|
|
3878
|
-
console.warn
|
|
4141
|
+
logWithLevel(exports.LogLevel.WARN, undefined, console.warn, 'stillRunning...', stillRunning);
|
|
3879
4142
|
return stillRunning.map(function (cache) { return cache.requestArgumentsSerialized; });
|
|
3880
4143
|
}
|
|
3881
4144
|
return true;
|
|
@@ -3888,6 +4151,10 @@ function onError(message) {
|
|
|
3888
4151
|
notifyToast("error", message, isLocal() ? toastOptionsDevs : toastOptions);
|
|
3889
4152
|
}
|
|
3890
4153
|
|
|
4154
|
+
function isVerbose() {
|
|
4155
|
+
return resolveLogLevel() >= exports.LogLevel.DEBUG;
|
|
4156
|
+
}
|
|
4157
|
+
|
|
3891
4158
|
exports.A = A;
|
|
3892
4159
|
exports.AggregateBuilder = AggregateBuilder;
|
|
3893
4160
|
exports.C6C = C6C;
|
|
@@ -3910,6 +4177,7 @@ exports.SqlExecutor = SqlExecutor;
|
|
|
3910
4177
|
exports.TestRestfulResponse = TestRestfulResponse;
|
|
3911
4178
|
exports.UpdateQueryBuilder = UpdateQueryBuilder;
|
|
3912
4179
|
exports.apiRequestCache = apiRequestCache;
|
|
4180
|
+
exports.applyLogLevelDefaults = applyLogLevelDefaults;
|
|
3913
4181
|
exports.axiosInstance = axiosInstance;
|
|
3914
4182
|
exports.bbox = bbox;
|
|
3915
4183
|
exports.carbonNodeQsStringify = carbonNodeQsStringify;
|
|
@@ -3930,6 +4198,8 @@ exports.fieldEq = fieldEq;
|
|
|
3930
4198
|
exports.getEnv = getEnv;
|
|
3931
4199
|
exports.getEnvBool = getEnvBool;
|
|
3932
4200
|
exports.getEnvDebug = getEnvDebug;
|
|
4201
|
+
exports.getEnvLogLevel = getEnvLogLevel;
|
|
4202
|
+
exports.getLogContext = getLogContext;
|
|
3933
4203
|
exports.getPrimaryKeyTypes = getPrimaryKeyTypes;
|
|
3934
4204
|
exports.group = group;
|
|
3935
4205
|
exports.info = info;
|
|
@@ -3939,23 +4209,29 @@ exports.isNode = isNode;
|
|
|
3939
4209
|
exports.isTest = isTest;
|
|
3940
4210
|
exports.isVerbose = isVerbose;
|
|
3941
4211
|
exports.loadSqlAllowList = loadSqlAllowList;
|
|
4212
|
+
exports.logSql = logSql;
|
|
4213
|
+
exports.logWithLevel = logWithLevel;
|
|
3942
4214
|
exports.normalizeSingularRequest = normalizeSingularRequest;
|
|
3943
4215
|
exports.normalizeSql = normalizeSql;
|
|
3944
4216
|
exports.notifyToast = notifyToast;
|
|
3945
4217
|
exports.onError = onError;
|
|
3946
4218
|
exports.onSuccess = onSuccess;
|
|
4219
|
+
exports.parseLogLevel = parseLogLevel;
|
|
3947
4220
|
exports.removeInvalidKeys = removeInvalidKeys;
|
|
3948
4221
|
exports.removePrefixIfExists = removePrefixIfExists;
|
|
3949
4222
|
exports.resolveDerivedTable = resolveDerivedTable;
|
|
4223
|
+
exports.resolveLogLevel = resolveLogLevel;
|
|
3950
4224
|
exports.restOrm = restOrm;
|
|
3951
4225
|
exports.restRequest = restRequest;
|
|
3952
4226
|
exports.setCache = setCache;
|
|
3953
4227
|
exports.setToastHandler = setToastHandler;
|
|
4228
|
+
exports.shouldLog = shouldLog;
|
|
3954
4229
|
exports.sortAndSerializeQueryObject = sortAndSerializeQueryObject;
|
|
3955
4230
|
exports.stContains = stContains;
|
|
3956
4231
|
exports.timeout = timeout;
|
|
3957
4232
|
exports.toastOptions = toastOptions;
|
|
3958
4233
|
exports.toastOptionsDevs = toastOptionsDevs;
|
|
3959
4234
|
exports.userCustomClearCache = userCustomClearCache;
|
|
4235
|
+
exports.versionColor = versionToRgb;
|
|
3960
4236
|
exports.warn = warn;
|
|
3961
4237
|
//# sourceMappingURL=index.cjs.js.map
|