@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.
Files changed (57) hide show
  1. package/dist/handlers/ExpressHandler.d.ts +3 -2
  2. package/dist/index.cjs.js +51 -3
  3. package/dist/index.cjs.js.map +1 -1
  4. package/dist/index.esm.js +51 -3
  5. package/dist/index.esm.js.map +1 -1
  6. package/package.json +1 -1
  7. package/src/__tests__/sakila-db/C6.js +1 -1
  8. package/src/__tests__/sakila-db/C6.mysqldump.json +1 -1
  9. package/src/__tests__/sakila-db/C6.mysqldump.sql +1 -1
  10. package/src/__tests__/sakila-db/C6.ts +1 -1
  11. package/src/__tests__/sakila-db/sqlResponses/C6.actor.post.json +3 -3
  12. package/src/__tests__/sakila-db/sqlResponses/C6.actor.post.latest.json +3 -3
  13. package/src/__tests__/sakila-db/sqlResponses/C6.actor.put.json +1 -1
  14. package/src/__tests__/sakila-db/sqlResponses/C6.actor.put.lookup.json +3 -3
  15. package/src/__tests__/sakila-db/sqlResponses/C6.address.post.json +5 -5
  16. package/src/__tests__/sakila-db/sqlResponses/C6.address.post.latest.json +5 -5
  17. package/src/__tests__/sakila-db/sqlResponses/C6.address.put.json +1 -1
  18. package/src/__tests__/sakila-db/sqlResponses/C6.address.put.lookup.json +5 -5
  19. package/src/__tests__/sakila-db/sqlResponses/C6.category.post.json +2 -2
  20. package/src/__tests__/sakila-db/sqlResponses/C6.category.post.latest.json +2 -2
  21. package/src/__tests__/sakila-db/sqlResponses/C6.category.put.json +1 -1
  22. package/src/__tests__/sakila-db/sqlResponses/C6.category.put.lookup.json +2 -2
  23. package/src/__tests__/sakila-db/sqlResponses/C6.city.post.json +2 -2
  24. package/src/__tests__/sakila-db/sqlResponses/C6.city.post.latest.json +2 -2
  25. package/src/__tests__/sakila-db/sqlResponses/C6.city.put.json +1 -1
  26. package/src/__tests__/sakila-db/sqlResponses/C6.city.put.lookup.json +2 -2
  27. package/src/__tests__/sakila-db/sqlResponses/C6.country.post.json +2 -2
  28. package/src/__tests__/sakila-db/sqlResponses/C6.country.post.latest.json +2 -2
  29. package/src/__tests__/sakila-db/sqlResponses/C6.country.put.json +1 -1
  30. package/src/__tests__/sakila-db/sqlResponses/C6.country.put.lookup.json +2 -2
  31. package/src/__tests__/sakila-db/sqlResponses/C6.customer.post.json +5 -5
  32. package/src/__tests__/sakila-db/sqlResponses/C6.customer.post.latest.json +5 -5
  33. package/src/__tests__/sakila-db/sqlResponses/C6.customer.put.json +1 -1
  34. package/src/__tests__/sakila-db/sqlResponses/C6.customer.put.lookup.json +5 -5
  35. package/src/__tests__/sakila-db/sqlResponses/C6.film.post.json +2 -2
  36. package/src/__tests__/sakila-db/sqlResponses/C6.film.post.latest.json +2 -2
  37. package/src/__tests__/sakila-db/sqlResponses/C6.film.put.json +1 -1
  38. package/src/__tests__/sakila-db/sqlResponses/C6.film.put.lookup.json +2 -2
  39. package/src/__tests__/sakila-db/sqlResponses/C6.inventory.post.json +1 -1
  40. package/src/__tests__/sakila-db/sqlResponses/C6.inventory.post.latest.json +1 -1
  41. package/src/__tests__/sakila-db/sqlResponses/C6.inventory.put.json +1 -1
  42. package/src/__tests__/sakila-db/sqlResponses/C6.inventory.put.lookup.json +1 -1
  43. package/src/__tests__/sakila-db/sqlResponses/C6.language.post.json +2 -2
  44. package/src/__tests__/sakila-db/sqlResponses/C6.language.post.latest.json +2 -2
  45. package/src/__tests__/sakila-db/sqlResponses/C6.language.put.json +1 -1
  46. package/src/__tests__/sakila-db/sqlResponses/C6.language.put.lookup.json +2 -2
  47. package/src/__tests__/sakila-db/sqlResponses/C6.payment.post.json +2 -2
  48. package/src/__tests__/sakila-db/sqlResponses/C6.payment.post.latest.json +2 -2
  49. package/src/__tests__/sakila-db/sqlResponses/C6.payment.put.lookup.json +2 -2
  50. package/src/__tests__/sakila-db/sqlResponses/C6.rental.post.json +3 -3
  51. package/src/__tests__/sakila-db/sqlResponses/C6.rental.post.latest.json +3 -3
  52. package/src/__tests__/sakila-db/sqlResponses/C6.rental.put.json +1 -1
  53. package/src/__tests__/sakila-db/sqlResponses/C6.rental.put.lookup.json +3 -3
  54. package/src/api/restRequest.ts +10 -0
  55. package/src/executors/HttpExecutor.ts +2 -1
  56. package/src/executors/SqlExecutor.ts +56 -16
  57. package/src/handlers/ExpressHandler.ts +4 -1
@@ -1,8 +1,9 @@
1
1
  import type { Request, Response, NextFunction } from "express";
2
2
  import type { Pool } from "mysql2/promise";
3
- import type { iC6Object } from "../types/ormInterfaces";
4
- export declare function ExpressHandler({ C6, mysqlPool, sqlAllowListPath, }: {
3
+ import type { iC6Object, tWebsocketBroadcast } from "../types/ormInterfaces";
4
+ export declare function ExpressHandler({ C6, mysqlPool, sqlAllowListPath, websocketBroadcast, }: {
5
5
  C6: iC6Object;
6
6
  mysqlPool: Pool;
7
7
  sqlAllowListPath?: string;
8
+ websocketBroadcast?: tWebsocketBroadcast;
8
9
  }): (req: Request, res: Response, next: NextFunction) => Promise<void>;
package/dist/index.cjs.js CHANGED
@@ -468,12 +468,22 @@ function restRequest(configX) {
468
468
  config = typeof configX === "function" ? configX() : configX;
469
469
  (_a = config.verbose) !== null && _a !== void 0 ? _a : (config.verbose = isVerbose()); // Default to env-driven verbosity if not set
470
470
  if (!(isNode() && config.mysqlPool)) return [3 /*break*/, 2];
471
+ if (config.verbose) {
472
+ console.log("Using SQL Executor");
473
+ }
471
474
  return [4 /*yield*/, Promise.resolve().then(function () { return SqlExecutor$1; })];
472
475
  case 1:
473
476
  SqlExecutor = (_b.sent()).SqlExecutor;
474
477
  executor = new SqlExecutor(config, request);
475
478
  return [2 /*return*/, executor.execute()];
476
- case 2: return [4 /*yield*/, Promise.resolve().then(function () { return HttpExecutor$1; })];
479
+ case 2:
480
+ if (config.verbose) {
481
+ console.log("Using HTTP Executor", {
482
+ isNode: isNode(),
483
+ hasPool: !!config.mysqlPool
484
+ });
485
+ }
486
+ return [4 /*yield*/, Promise.resolve().then(function () { return HttpExecutor$1; })];
477
487
  case 3:
478
488
  HttpExecutor = (_b.sent()).HttpExecutor;
479
489
  http = new HttpExecutor(config, request);
@@ -3127,6 +3137,13 @@ var SqlExecutor = /** @class */ (function (_super) {
3127
3137
  case 1: return [4 /*yield*/, this.runQuery()];
3128
3138
  case 2:
3129
3139
  rest = _b.sent();
3140
+ if (this.config.reactBootstrap) {
3141
+ this.config.reactBootstrap.updateRestfulObjectArrays({
3142
+ dataOrCallback: rest.rest,
3143
+ stateKey: this.config.restModel.TABLE_NAME,
3144
+ uniqueObjectId: this.config.restModel.PRIMARY_SHORT,
3145
+ });
3146
+ }
3130
3147
  return [2 /*return*/, rest];
3131
3148
  case 3: return [4 /*yield*/, this.runQuery()];
3132
3149
  case 4:
@@ -3354,17 +3371,40 @@ var SqlExecutor = /** @class */ (function (_super) {
3354
3371
  switch (_f.label) {
3355
3372
  case 0:
3356
3373
  broadcast = this.config.websocketBroadcast;
3357
- if (!broadcast || this.config.requestMethod === C6Constants.GET)
3374
+ this.config.verbose && console.log("[SQL EXECUTOR] 📣 broadcastWebsocketIfConfigured start", {
3375
+ method: this.config.requestMethod,
3376
+ hasBroadcast: Boolean(broadcast),
3377
+ });
3378
+ if (!broadcast || this.config.requestMethod === C6Constants.GET) {
3379
+ this.config.verbose && console.log("[SQL EXECUTOR] 📣 websocket broadcast skipped", {
3380
+ reason: !broadcast ? "no broadcast configured" : "GET request",
3381
+ });
3358
3382
  return [2 /*return*/];
3383
+ }
3359
3384
  normalizedRequest = this.normalizeRequestPayload(this.extractRequestBody());
3360
3385
  pkShorts = (_c = this.config.restModel.PRIMARY_SHORT) !== null && _c !== void 0 ? _c : [];
3361
3386
  columns = this.config.restModel.COLUMNS;
3362
3387
  validColumns = new Set(Object.values(columns));
3363
3388
  responseRest = response === null || response === void 0 ? void 0 : response.rest;
3364
3389
  responsePrimaryKey = this.extractPrimaryKeyValuesFromData(responseRest);
3390
+ this.config.verbose && console.log("[SQL EXECUTOR] 📣 websocket request payload", {
3391
+ normalizedRequest: normalizedRequest,
3392
+ requestPrimaryKey: this.extractPrimaryKeyValues(),
3393
+ pkShorts: pkShorts,
3394
+ });
3395
+ this.config.verbose && console.log("[SQL EXECUTOR] 📣 websocket response payload", {
3396
+ responseRest: responseRest,
3397
+ responsePrimaryKey: responsePrimaryKey,
3398
+ });
3365
3399
  if ((responseRest === null || (Array.isArray(responseRest) && responseRest.length === 0))
3366
3400
  && this.config.requestMethod === C6Constants.POST) {
3401
+ this.config.verbose && console.log("[SQL EXECUTOR] 📣 response rest empty, attempting synthesize", {
3402
+ responseRest: responseRest,
3403
+ });
3367
3404
  insertId = response === null || response === void 0 ? void 0 : response.insertId;
3405
+ this.config.verbose && console.log("[SQL EXECUTOR] 📣 POST insertId lookup", {
3406
+ insertId: insertId,
3407
+ });
3368
3408
  if (insertId !== undefined && pkShorts.length === 1) {
3369
3409
  synthesizedRequest = tslib.__assign({}, normalizedRequest);
3370
3410
  now = new Date().toISOString();
@@ -3383,6 +3423,10 @@ var SqlExecutor = /** @class */ (function (_super) {
3383
3423
  responsePrimaryKey = (_b = {},
3384
3424
  _b[pkShorts[0]] = insertId,
3385
3425
  _b);
3426
+ this.config.verbose && console.log("[SQL EXECUTOR] 📣 synthesized response payload", {
3427
+ synthesized: synthesized,
3428
+ responsePrimaryKey: responsePrimaryKey,
3429
+ });
3386
3430
  }
3387
3431
  }
3388
3432
  payload = {
@@ -3396,12 +3440,15 @@ var SqlExecutor = /** @class */ (function (_super) {
3396
3440
  RESPONSE_PRIMARY_KEY: responsePrimaryKey,
3397
3441
  },
3398
3442
  };
3443
+ this.config.verbose && console.log("[SQL EXECUTOR] 📣 websocket payload ready", payload);
3399
3444
  _f.label = 1;
3400
3445
  case 1:
3401
3446
  _f.trys.push([1, 3, , 4]);
3447
+ this.config.verbose && console.log("[SQL EXECUTOR] 📣 websocket broadcast dispatch start");
3402
3448
  return [4 /*yield*/, broadcast(payload)];
3403
3449
  case 2:
3404
3450
  _f.sent();
3451
+ this.config.verbose && console.log("[SQL EXECUTOR] 📣 websocket broadcast dispatch complete");
3405
3452
  return [3 /*break*/, 4];
3406
3453
  case 3:
3407
3454
  error_1 = _f.sent();
@@ -3512,7 +3559,7 @@ var SqlExecutor$1 = /*#__PURE__*/Object.freeze({
3512
3559
  // note sure how it would help anyone actually...
3513
3560
  function ExpressHandler(_a) {
3514
3561
  var _this = this;
3515
- var C6 = _a.C6, mysqlPool = _a.mysqlPool, sqlAllowListPath = _a.sqlAllowListPath;
3562
+ var C6 = _a.C6, mysqlPool = _a.mysqlPool, sqlAllowListPath = _a.sqlAllowListPath, websocketBroadcast = _a.websocketBroadcast;
3516
3563
  return function (req, res, next) { return tslib.__awaiter(_this, void 0, void 0, function () {
3517
3564
  var incomingMethod, table, primary, methodOverrideRaw, methodOverride, treatAsGet, method, payload, restModel, primaryKeys_1, primaryShortKeys_1, columnMap_1, resolveShortKey_1, hasPrimaryKeyValues, primaryKeyName, response, err_1;
3518
3565
  var _a, _b, _c, _d, _e, _f, _g;
@@ -3599,6 +3646,7 @@ function ExpressHandler(_a) {
3599
3646
  C6: C6,
3600
3647
  mysqlPool: mysqlPool,
3601
3648
  sqlAllowListPath: sqlAllowListPath,
3649
+ websocketBroadcast: websocketBroadcast,
3602
3650
  requestMethod: method,
3603
3651
  restModel: C6.TABLES[table]
3604
3652
  })(payload)];