@carbonorm/carbonnode 6.0.4 → 6.0.6
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/handlers/ExpressHandler.d.ts +3 -2
- package/dist/index.cjs.js +51 -3
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +51 -3
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- 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/api/restRequest.ts +10 -0
- package/src/executors/HttpExecutor.ts +2 -1
- package/src/executors/SqlExecutor.ts +56 -16
- package/src/handlers/ExpressHandler.ts +4 -1
package/dist/index.esm.js
CHANGED
|
@@ -465,12 +465,22 @@ function restRequest(configX) {
|
|
|
465
465
|
config = typeof configX === "function" ? configX() : configX;
|
|
466
466
|
(_a = config.verbose) !== null && _a !== void 0 ? _a : (config.verbose = isVerbose()); // Default to env-driven verbosity if not set
|
|
467
467
|
if (!(isNode() && config.mysqlPool)) return [3 /*break*/, 2];
|
|
468
|
+
if (config.verbose) {
|
|
469
|
+
console.log("Using SQL Executor");
|
|
470
|
+
}
|
|
468
471
|
return [4 /*yield*/, Promise.resolve().then(function () { return SqlExecutor$1; })];
|
|
469
472
|
case 1:
|
|
470
473
|
SqlExecutor = (_b.sent()).SqlExecutor;
|
|
471
474
|
executor = new SqlExecutor(config, request);
|
|
472
475
|
return [2 /*return*/, executor.execute()];
|
|
473
|
-
case 2:
|
|
476
|
+
case 2:
|
|
477
|
+
if (config.verbose) {
|
|
478
|
+
console.log("Using HTTP Executor", {
|
|
479
|
+
isNode: isNode(),
|
|
480
|
+
hasPool: !!config.mysqlPool
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
return [4 /*yield*/, Promise.resolve().then(function () { return HttpExecutor$1; })];
|
|
474
484
|
case 3:
|
|
475
485
|
HttpExecutor = (_b.sent()).HttpExecutor;
|
|
476
486
|
http = new HttpExecutor(config, request);
|
|
@@ -3124,6 +3134,13 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3124
3134
|
case 1: return [4 /*yield*/, this.runQuery()];
|
|
3125
3135
|
case 2:
|
|
3126
3136
|
rest = _b.sent();
|
|
3137
|
+
if (this.config.reactBootstrap) {
|
|
3138
|
+
this.config.reactBootstrap.updateRestfulObjectArrays({
|
|
3139
|
+
dataOrCallback: rest.rest,
|
|
3140
|
+
stateKey: this.config.restModel.TABLE_NAME,
|
|
3141
|
+
uniqueObjectId: this.config.restModel.PRIMARY_SHORT,
|
|
3142
|
+
});
|
|
3143
|
+
}
|
|
3127
3144
|
return [2 /*return*/, rest];
|
|
3128
3145
|
case 3: return [4 /*yield*/, this.runQuery()];
|
|
3129
3146
|
case 4:
|
|
@@ -3351,17 +3368,40 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3351
3368
|
switch (_f.label) {
|
|
3352
3369
|
case 0:
|
|
3353
3370
|
broadcast = this.config.websocketBroadcast;
|
|
3354
|
-
|
|
3371
|
+
this.config.verbose && console.log("[SQL EXECUTOR] 📣 broadcastWebsocketIfConfigured start", {
|
|
3372
|
+
method: this.config.requestMethod,
|
|
3373
|
+
hasBroadcast: Boolean(broadcast),
|
|
3374
|
+
});
|
|
3375
|
+
if (!broadcast || this.config.requestMethod === C6Constants.GET) {
|
|
3376
|
+
this.config.verbose && console.log("[SQL EXECUTOR] 📣 websocket broadcast skipped", {
|
|
3377
|
+
reason: !broadcast ? "no broadcast configured" : "GET request",
|
|
3378
|
+
});
|
|
3355
3379
|
return [2 /*return*/];
|
|
3380
|
+
}
|
|
3356
3381
|
normalizedRequest = this.normalizeRequestPayload(this.extractRequestBody());
|
|
3357
3382
|
pkShorts = (_c = this.config.restModel.PRIMARY_SHORT) !== null && _c !== void 0 ? _c : [];
|
|
3358
3383
|
columns = this.config.restModel.COLUMNS;
|
|
3359
3384
|
validColumns = new Set(Object.values(columns));
|
|
3360
3385
|
responseRest = response === null || response === void 0 ? void 0 : response.rest;
|
|
3361
3386
|
responsePrimaryKey = this.extractPrimaryKeyValuesFromData(responseRest);
|
|
3387
|
+
this.config.verbose && console.log("[SQL EXECUTOR] 📣 websocket request payload", {
|
|
3388
|
+
normalizedRequest: normalizedRequest,
|
|
3389
|
+
requestPrimaryKey: this.extractPrimaryKeyValues(),
|
|
3390
|
+
pkShorts: pkShorts,
|
|
3391
|
+
});
|
|
3392
|
+
this.config.verbose && console.log("[SQL EXECUTOR] 📣 websocket response payload", {
|
|
3393
|
+
responseRest: responseRest,
|
|
3394
|
+
responsePrimaryKey: responsePrimaryKey,
|
|
3395
|
+
});
|
|
3362
3396
|
if ((responseRest === null || (Array.isArray(responseRest) && responseRest.length === 0))
|
|
3363
3397
|
&& this.config.requestMethod === C6Constants.POST) {
|
|
3398
|
+
this.config.verbose && console.log("[SQL EXECUTOR] 📣 response rest empty, attempting synthesize", {
|
|
3399
|
+
responseRest: responseRest,
|
|
3400
|
+
});
|
|
3364
3401
|
insertId = response === null || response === void 0 ? void 0 : response.insertId;
|
|
3402
|
+
this.config.verbose && console.log("[SQL EXECUTOR] 📣 POST insertId lookup", {
|
|
3403
|
+
insertId: insertId,
|
|
3404
|
+
});
|
|
3365
3405
|
if (insertId !== undefined && pkShorts.length === 1) {
|
|
3366
3406
|
synthesizedRequest = __assign({}, normalizedRequest);
|
|
3367
3407
|
now = new Date().toISOString();
|
|
@@ -3380,6 +3420,10 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3380
3420
|
responsePrimaryKey = (_b = {},
|
|
3381
3421
|
_b[pkShorts[0]] = insertId,
|
|
3382
3422
|
_b);
|
|
3423
|
+
this.config.verbose && console.log("[SQL EXECUTOR] 📣 synthesized response payload", {
|
|
3424
|
+
synthesized: synthesized,
|
|
3425
|
+
responsePrimaryKey: responsePrimaryKey,
|
|
3426
|
+
});
|
|
3383
3427
|
}
|
|
3384
3428
|
}
|
|
3385
3429
|
payload = {
|
|
@@ -3393,12 +3437,15 @@ var SqlExecutor = /** @class */ (function (_super) {
|
|
|
3393
3437
|
RESPONSE_PRIMARY_KEY: responsePrimaryKey,
|
|
3394
3438
|
},
|
|
3395
3439
|
};
|
|
3440
|
+
this.config.verbose && console.log("[SQL EXECUTOR] 📣 websocket payload ready", payload);
|
|
3396
3441
|
_f.label = 1;
|
|
3397
3442
|
case 1:
|
|
3398
3443
|
_f.trys.push([1, 3, , 4]);
|
|
3444
|
+
this.config.verbose && console.log("[SQL EXECUTOR] 📣 websocket broadcast dispatch start");
|
|
3399
3445
|
return [4 /*yield*/, broadcast(payload)];
|
|
3400
3446
|
case 2:
|
|
3401
3447
|
_f.sent();
|
|
3448
|
+
this.config.verbose && console.log("[SQL EXECUTOR] 📣 websocket broadcast dispatch complete");
|
|
3402
3449
|
return [3 /*break*/, 4];
|
|
3403
3450
|
case 3:
|
|
3404
3451
|
error_1 = _f.sent();
|
|
@@ -3509,7 +3556,7 @@ var SqlExecutor$1 = /*#__PURE__*/Object.freeze({
|
|
|
3509
3556
|
// note sure how it would help anyone actually...
|
|
3510
3557
|
function ExpressHandler(_a) {
|
|
3511
3558
|
var _this = this;
|
|
3512
|
-
var C6 = _a.C6, mysqlPool = _a.mysqlPool, sqlAllowListPath = _a.sqlAllowListPath;
|
|
3559
|
+
var C6 = _a.C6, mysqlPool = _a.mysqlPool, sqlAllowListPath = _a.sqlAllowListPath, websocketBroadcast = _a.websocketBroadcast;
|
|
3513
3560
|
return function (req, res, next) { return __awaiter(_this, void 0, void 0, function () {
|
|
3514
3561
|
var incomingMethod, table, primary, methodOverrideRaw, methodOverride, treatAsGet, method, payload, restModel, primaryKeys_1, primaryShortKeys_1, columnMap_1, resolveShortKey_1, hasPrimaryKeyValues, primaryKeyName, response, err_1;
|
|
3515
3562
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
@@ -3596,6 +3643,7 @@ function ExpressHandler(_a) {
|
|
|
3596
3643
|
C6: C6,
|
|
3597
3644
|
mysqlPool: mysqlPool,
|
|
3598
3645
|
sqlAllowListPath: sqlAllowListPath,
|
|
3646
|
+
websocketBroadcast: websocketBroadcast,
|
|
3599
3647
|
requestMethod: method,
|
|
3600
3648
|
restModel: C6.TABLES[table]
|
|
3601
3649
|
})(payload)];
|