@cadenza.io/service 2.17.57 → 2.17.59

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
@@ -8787,17 +8787,19 @@ function resolveLocalDatabaseTaskIntent(task, operation, tableName) {
8787
8787
  (intent) => typeof intent === "string" && intent.startsWith(expectedPrefix)
8788
8788
  );
8789
8789
  }
8790
- function createLocalDatabaseInquiryTask(localTask, operation, tableName, options = {}) {
8791
- const intentName = resolveLocalDatabaseTaskIntent(localTask, operation, tableName);
8790
+ function buildAuthoritySyncIntentName(operation, tableName) {
8791
+ return `${operation}-pg-cadenza-db-postgres-actor-${tableName}`;
8792
+ }
8793
+ function createDatabaseInquiryTask(intentName, operation, tableName, options = {}) {
8792
8794
  return CadenzaService.createMetaTask(
8793
- `Execute local graph sync ${operation} for ${tableName}`,
8795
+ `Execute graph sync ${operation} for ${tableName}`,
8794
8796
  async (ctx, _emit, inquire) => {
8795
8797
  if (!intentName) {
8796
8798
  return {
8797
8799
  ...ctx,
8798
8800
  errored: true,
8799
8801
  __success: false,
8800
- __error: `No local ${operation} intent found for ${tableName}`
8802
+ __error: `No ${operation} intent found for ${tableName}`
8801
8803
  };
8802
8804
  }
8803
8805
  const inquiryContext = {
@@ -8805,12 +8807,29 @@ function createLocalDatabaseInquiryTask(localTask, operation, tableName, options
8805
8807
  queryData: ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : {}
8806
8808
  };
8807
8809
  const result = await inquire(intentName, inquiryContext, {});
8810
+ const normalizedResult = result && typeof result === "object" ? result : {};
8811
+ if (Object.keys(normalizedResult).length === 0 && normalizedResult.errored !== true && normalizedResult.__success !== true && normalizedResult.__inquiryMeta === void 0) {
8812
+ return {
8813
+ ...ctx,
8814
+ errored: true,
8815
+ __success: false,
8816
+ __error: `No responders available for ${intentName}`,
8817
+ __inquiryMeta: {
8818
+ inquiry: intentName,
8819
+ eligibleResponders: 0,
8820
+ responded: 0,
8821
+ failed: 0,
8822
+ timedOut: 0,
8823
+ pending: 0
8824
+ }
8825
+ };
8826
+ }
8808
8827
  return {
8809
8828
  ...ctx,
8810
- ...result
8829
+ ...normalizedResult
8811
8830
  };
8812
8831
  },
8813
- `Executes the local ${tableName} ${operation} operation through the generated database intent.`,
8832
+ `Executes the ${tableName} ${operation} operation through the generated database intent.`,
8814
8833
  {
8815
8834
  ...options,
8816
8835
  register: false,
@@ -8820,18 +8839,24 @@ function createLocalDatabaseInquiryTask(localTask, operation, tableName, options
8820
8839
  }
8821
8840
  function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, options = {}) {
8822
8841
  const localInsertTask = CadenzaService.getLocalCadenzaDBInsertTask(tableName);
8823
- const remoteInsertTask = isCadenzaDBReady ? CadenzaService.createCadenzaDBInsertTask(tableName, queryData, options) : void 0;
8824
8842
  const debugTable = shouldDebugSyncTable(tableName);
8825
- if (!localInsertTask && !remoteInsertTask) {
8843
+ if (!localInsertTask && !isCadenzaDBReady) {
8826
8844
  return void 0;
8827
8845
  }
8828
- const targetTask = localInsertTask ? createLocalDatabaseInquiryTask(localInsertTask, "insert", tableName, options) : remoteInsertTask;
8846
+ const targetIntentName = resolveLocalDatabaseTaskIntent(localInsertTask, "insert", tableName) ?? buildAuthoritySyncIntentName("insert", tableName);
8847
+ const targetTask = createDatabaseInquiryTask(
8848
+ targetIntentName,
8849
+ "insert",
8850
+ tableName,
8851
+ options
8852
+ );
8829
8853
  if (debugTable) {
8830
8854
  logSyncDebug("insert_task_resolved", {
8831
8855
  tableName,
8832
8856
  localInsertTaskName: localInsertTask?.name ?? null,
8833
- remoteInsertTaskName: remoteInsertTask?.name ?? null,
8857
+ remoteInsertTaskName: isCadenzaDBReady ? targetIntentName : null,
8834
8858
  targetTaskName: targetTask.name,
8859
+ targetIntentName,
8835
8860
  queryData,
8836
8861
  options
8837
8862
  });
@@ -8990,10 +9015,10 @@ var SYNC_DEBUG_INTENT_NAMES = /* @__PURE__ */ new Set([
8990
9015
  "iot-anomaly-runtime-get",
8991
9016
  "iot-prediction-compute",
8992
9017
  "iot-db-telemetry-insert",
8993
- "query-pg-CadenzaDBPostgresActor-service_instance",
8994
- "query-pg-CadenzaDBPostgresActor-service_instance_transport",
8995
- "query-pg-CadenzaDBPostgresActor-intent_to_task_map",
8996
- "query-pg-CadenzaDBPostgresActor-signal_to_task_map"
9018
+ "query-pg-cadenza-db-postgres-actor-service_instance",
9019
+ "query-pg-cadenza-db-postgres-actor-service_instance_transport",
9020
+ "query-pg-cadenza-db-postgres-actor-intent_to_task_map",
9021
+ "query-pg-cadenza-db-postgres-actor-signal_to_task_map"
8997
9022
  ]);
8998
9023
  function shouldDebugSyncTable(tableName) {
8999
9024
  return SYNC_DEBUG_TABLES.has(tableName);
@@ -9099,11 +9124,16 @@ function resolveSyncQueryRows(ctx, tableName) {
9099
9124
  }
9100
9125
  function resolveSyncQueryTask(isCadenzaDBReady, tableName, queryData = {}, options = {}) {
9101
9126
  const localQueryTask = CadenzaService.getLocalCadenzaDBQueryTask(tableName);
9102
- const remoteQueryTask = isCadenzaDBReady ? CadenzaService.createCadenzaDBQueryTask(tableName, queryData, options) : void 0;
9103
- if (!localQueryTask && !remoteQueryTask) {
9127
+ if (!localQueryTask && !isCadenzaDBReady) {
9104
9128
  return void 0;
9105
9129
  }
9106
- const targetTask = localQueryTask ? createLocalDatabaseInquiryTask(localQueryTask, "query", tableName, options) : remoteQueryTask;
9130
+ const targetIntentName = resolveLocalDatabaseTaskIntent(localQueryTask, "query", tableName) ?? buildAuthoritySyncIntentName("query", tableName);
9131
+ const targetTask = createDatabaseInquiryTask(
9132
+ targetIntentName,
9133
+ "query",
9134
+ tableName,
9135
+ options
9136
+ );
9107
9137
  const prepareQueryTask = CadenzaService.createMetaTask(
9108
9138
  `Prepare graph sync query for ${tableName}`,
9109
9139
  (ctx) => ({