@cadenza.io/service 2.17.51 → 2.17.52

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.js CHANGED
@@ -6575,6 +6575,67 @@ var SCHEMA_TYPES = [
6575
6575
  // src/database/DatabaseController.ts
6576
6576
  var import_pg = require("pg");
6577
6577
  var import_lodash_es = require("lodash-es");
6578
+ var AUTHORITY_SYNC_DEBUG_PREFIX = "[CADENZA_DB_TASK_DEBUG]";
6579
+ var AUTHORITY_SYNC_DEBUG_TASK_NAMES = /* @__PURE__ */ new Set([
6580
+ "Query service_instance",
6581
+ "Query service_instance_transport",
6582
+ "Query intent_to_task_map",
6583
+ "Query signal_to_task_map",
6584
+ "Forward service instance sync",
6585
+ "Forward service transport sync",
6586
+ "Forward intent to task map sync",
6587
+ "Forward signal to task map sync",
6588
+ "Compile sync data and broadcast",
6589
+ "Prepare for signal sync"
6590
+ ]);
6591
+ var AUTHORITY_SYNC_DEBUG_ROUTINE_NAMES = /* @__PURE__ */ new Set(["Sync services"]);
6592
+ function logAuthoritySyncDebug(event, payload) {
6593
+ console.log(`${AUTHORITY_SYNC_DEBUG_PREFIX} ${event}`, payload);
6594
+ }
6595
+ function resolveAuthoritySyncPayloadName(payload, tableName) {
6596
+ const data = payload.data && typeof payload.data === "object" && !Array.isArray(payload.data) ? payload.data : null;
6597
+ if (!data) {
6598
+ return null;
6599
+ }
6600
+ if (tableName === "task") {
6601
+ const taskName = data.name;
6602
+ return typeof taskName === "string" ? taskName : null;
6603
+ }
6604
+ if (tableName === "task_to_routine_map") {
6605
+ const taskName = data.taskName ?? data.task_name;
6606
+ return typeof taskName === "string" ? taskName : null;
6607
+ }
6608
+ return null;
6609
+ }
6610
+ function shouldDebugAuthoritySyncPayload(tableName, payload) {
6611
+ if (tableName !== "task" && tableName !== "task_to_routine_map") {
6612
+ return false;
6613
+ }
6614
+ const payloadName = resolveAuthoritySyncPayloadName(payload, tableName);
6615
+ if (payloadName && AUTHORITY_SYNC_DEBUG_TASK_NAMES.has(payloadName)) {
6616
+ return true;
6617
+ }
6618
+ if (tableName === "task_to_routine_map") {
6619
+ const data = payload.data && typeof payload.data === "object" && !Array.isArray(payload.data) ? payload.data : null;
6620
+ const routineName = data?.routineName ?? data?.routine_name;
6621
+ return typeof routineName === "string" && AUTHORITY_SYNC_DEBUG_ROUTINE_NAMES.has(routineName);
6622
+ }
6623
+ return false;
6624
+ }
6625
+ function buildAuthoritySyncDebugSummary(payload, context) {
6626
+ const data = payload.data && typeof payload.data === "object" && !Array.isArray(payload.data) ? payload.data : {};
6627
+ return {
6628
+ taskName: data.name ?? data.taskName ?? data.task_name ?? context.__taskName ?? null,
6629
+ routineName: data.routineName ?? data.routine_name ?? context.__routineName ?? null,
6630
+ serviceName: data.serviceName ?? data.service_name ?? context.__syncServiceName ?? null,
6631
+ predecessorTaskName: data.predecessorTaskName ?? data.predecessor_task_name ?? null,
6632
+ queryDataKeys: context.queryData && typeof context.queryData === "object" ? Object.keys(context.queryData) : [],
6633
+ dataKeys: Object.keys(data),
6634
+ onConflict: payload.onConflict && typeof payload.onConflict === "object" ? payload.onConflict : null,
6635
+ rowCount: context.rowCount ?? null,
6636
+ error: context.__error ?? null
6637
+ };
6638
+ }
6578
6639
  function normalizeIntentToken(value) {
6579
6640
  const normalized = (0, import_lodash_es.kebabCase)(String(value ?? "").trim());
6580
6641
  if (!normalized) {
@@ -7927,16 +7988,39 @@ var DatabaseController = class _DatabaseController {
7927
7988
  }
7928
7989
  }
7929
7990
  const operationPayload = typeof context.queryData === "object" && context.queryData ? context.queryData : context;
7930
- this.validateOperationPayload(
7931
- registration,
7932
- op,
7991
+ const shouldDebugAuthoritySync = shouldDebugAuthoritySyncPayload(
7933
7992
  tableName,
7934
- table,
7935
- operationPayload,
7936
- {
7937
- enforceFieldAllowlist: registration.options.securityProfile === "low" || payloadModifiedByTriggers
7938
- }
7993
+ operationPayload
7939
7994
  );
7995
+ if (shouldDebugAuthoritySync) {
7996
+ logAuthoritySyncDebug("input", {
7997
+ tableName,
7998
+ operation: op,
7999
+ summary: buildAuthoritySyncDebugSummary(operationPayload, context)
8000
+ });
8001
+ }
8002
+ try {
8003
+ this.validateOperationPayload(
8004
+ registration,
8005
+ op,
8006
+ tableName,
8007
+ table,
8008
+ operationPayload,
8009
+ {
8010
+ enforceFieldAllowlist: registration.options.securityProfile === "low" || payloadModifiedByTriggers
8011
+ }
8012
+ );
8013
+ } catch (error) {
8014
+ if (shouldDebugAuthoritySync) {
8015
+ logAuthoritySyncDebug("validation_failed", {
8016
+ tableName,
8017
+ operation: op,
8018
+ summary: buildAuthoritySyncDebugSummary(operationPayload, context),
8019
+ error: error instanceof Error ? error.message : String(error)
8020
+ });
8021
+ }
8022
+ throw error;
8023
+ }
7940
8024
  let result;
7941
8025
  if (op === "query") {
7942
8026
  result = await this.queryFunction(registration, tableName, operationPayload);
@@ -7951,6 +8035,14 @@ var DatabaseController = class _DatabaseController {
7951
8035
  ...context,
7952
8036
  ...result
7953
8037
  };
8038
+ if (shouldDebugAuthoritySync) {
8039
+ logAuthoritySyncDebug("result", {
8040
+ tableName,
8041
+ operation: op,
8042
+ summary: buildAuthoritySyncDebugSummary(operationPayload, context),
8043
+ resultKeys: result && typeof result === "object" ? Object.keys(result) : []
8044
+ });
8045
+ }
7954
8046
  if (!context.errored) {
7955
8047
  for (const signal of table.customSignals?.emissions?.[op] ?? []) {
7956
8048
  if (typeof signal === "string") {