@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.mjs CHANGED
@@ -6524,6 +6524,67 @@ var SCHEMA_TYPES = [
6524
6524
  // src/database/DatabaseController.ts
6525
6525
  import { Pool } from "pg";
6526
6526
  import { camelCase, kebabCase, snakeCase } from "lodash-es";
6527
+ var AUTHORITY_SYNC_DEBUG_PREFIX = "[CADENZA_DB_TASK_DEBUG]";
6528
+ var AUTHORITY_SYNC_DEBUG_TASK_NAMES = /* @__PURE__ */ new Set([
6529
+ "Query service_instance",
6530
+ "Query service_instance_transport",
6531
+ "Query intent_to_task_map",
6532
+ "Query signal_to_task_map",
6533
+ "Forward service instance sync",
6534
+ "Forward service transport sync",
6535
+ "Forward intent to task map sync",
6536
+ "Forward signal to task map sync",
6537
+ "Compile sync data and broadcast",
6538
+ "Prepare for signal sync"
6539
+ ]);
6540
+ var AUTHORITY_SYNC_DEBUG_ROUTINE_NAMES = /* @__PURE__ */ new Set(["Sync services"]);
6541
+ function logAuthoritySyncDebug(event, payload) {
6542
+ console.log(`${AUTHORITY_SYNC_DEBUG_PREFIX} ${event}`, payload);
6543
+ }
6544
+ function resolveAuthoritySyncPayloadName(payload, tableName) {
6545
+ const data = payload.data && typeof payload.data === "object" && !Array.isArray(payload.data) ? payload.data : null;
6546
+ if (!data) {
6547
+ return null;
6548
+ }
6549
+ if (tableName === "task") {
6550
+ const taskName = data.name;
6551
+ return typeof taskName === "string" ? taskName : null;
6552
+ }
6553
+ if (tableName === "task_to_routine_map") {
6554
+ const taskName = data.taskName ?? data.task_name;
6555
+ return typeof taskName === "string" ? taskName : null;
6556
+ }
6557
+ return null;
6558
+ }
6559
+ function shouldDebugAuthoritySyncPayload(tableName, payload) {
6560
+ if (tableName !== "task" && tableName !== "task_to_routine_map") {
6561
+ return false;
6562
+ }
6563
+ const payloadName = resolveAuthoritySyncPayloadName(payload, tableName);
6564
+ if (payloadName && AUTHORITY_SYNC_DEBUG_TASK_NAMES.has(payloadName)) {
6565
+ return true;
6566
+ }
6567
+ if (tableName === "task_to_routine_map") {
6568
+ const data = payload.data && typeof payload.data === "object" && !Array.isArray(payload.data) ? payload.data : null;
6569
+ const routineName = data?.routineName ?? data?.routine_name;
6570
+ return typeof routineName === "string" && AUTHORITY_SYNC_DEBUG_ROUTINE_NAMES.has(routineName);
6571
+ }
6572
+ return false;
6573
+ }
6574
+ function buildAuthoritySyncDebugSummary(payload, context) {
6575
+ const data = payload.data && typeof payload.data === "object" && !Array.isArray(payload.data) ? payload.data : {};
6576
+ return {
6577
+ taskName: data.name ?? data.taskName ?? data.task_name ?? context.__taskName ?? null,
6578
+ routineName: data.routineName ?? data.routine_name ?? context.__routineName ?? null,
6579
+ serviceName: data.serviceName ?? data.service_name ?? context.__syncServiceName ?? null,
6580
+ predecessorTaskName: data.predecessorTaskName ?? data.predecessor_task_name ?? null,
6581
+ queryDataKeys: context.queryData && typeof context.queryData === "object" ? Object.keys(context.queryData) : [],
6582
+ dataKeys: Object.keys(data),
6583
+ onConflict: payload.onConflict && typeof payload.onConflict === "object" ? payload.onConflict : null,
6584
+ rowCount: context.rowCount ?? null,
6585
+ error: context.__error ?? null
6586
+ };
6587
+ }
6527
6588
  function normalizeIntentToken(value) {
6528
6589
  const normalized = kebabCase(String(value ?? "").trim());
6529
6590
  if (!normalized) {
@@ -7876,16 +7937,39 @@ var DatabaseController = class _DatabaseController {
7876
7937
  }
7877
7938
  }
7878
7939
  const operationPayload = typeof context.queryData === "object" && context.queryData ? context.queryData : context;
7879
- this.validateOperationPayload(
7880
- registration,
7881
- op,
7940
+ const shouldDebugAuthoritySync = shouldDebugAuthoritySyncPayload(
7882
7941
  tableName,
7883
- table,
7884
- operationPayload,
7885
- {
7886
- enforceFieldAllowlist: registration.options.securityProfile === "low" || payloadModifiedByTriggers
7887
- }
7942
+ operationPayload
7888
7943
  );
7944
+ if (shouldDebugAuthoritySync) {
7945
+ logAuthoritySyncDebug("input", {
7946
+ tableName,
7947
+ operation: op,
7948
+ summary: buildAuthoritySyncDebugSummary(operationPayload, context)
7949
+ });
7950
+ }
7951
+ try {
7952
+ this.validateOperationPayload(
7953
+ registration,
7954
+ op,
7955
+ tableName,
7956
+ table,
7957
+ operationPayload,
7958
+ {
7959
+ enforceFieldAllowlist: registration.options.securityProfile === "low" || payloadModifiedByTriggers
7960
+ }
7961
+ );
7962
+ } catch (error) {
7963
+ if (shouldDebugAuthoritySync) {
7964
+ logAuthoritySyncDebug("validation_failed", {
7965
+ tableName,
7966
+ operation: op,
7967
+ summary: buildAuthoritySyncDebugSummary(operationPayload, context),
7968
+ error: error instanceof Error ? error.message : String(error)
7969
+ });
7970
+ }
7971
+ throw error;
7972
+ }
7889
7973
  let result;
7890
7974
  if (op === "query") {
7891
7975
  result = await this.queryFunction(registration, tableName, operationPayload);
@@ -7900,6 +7984,14 @@ var DatabaseController = class _DatabaseController {
7900
7984
  ...context,
7901
7985
  ...result
7902
7986
  };
7987
+ if (shouldDebugAuthoritySync) {
7988
+ logAuthoritySyncDebug("result", {
7989
+ tableName,
7990
+ operation: op,
7991
+ summary: buildAuthoritySyncDebugSummary(operationPayload, context),
7992
+ resultKeys: result && typeof result === "object" ? Object.keys(result) : []
7993
+ });
7994
+ }
7903
7995
  if (!context.errored) {
7904
7996
  for (const signal of table.customSignals?.emissions?.[op] ?? []) {
7905
7997
  if (typeof signal === "string") {