@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.
@@ -6280,17 +6280,19 @@ function resolveLocalDatabaseTaskIntent(task, operation, tableName) {
6280
6280
  (intent) => typeof intent === "string" && intent.startsWith(expectedPrefix)
6281
6281
  );
6282
6282
  }
6283
- function createLocalDatabaseInquiryTask(localTask, operation, tableName, options = {}) {
6284
- const intentName = resolveLocalDatabaseTaskIntent(localTask, operation, tableName);
6283
+ function buildAuthoritySyncIntentName(operation, tableName) {
6284
+ return `${operation}-pg-cadenza-db-postgres-actor-${tableName}`;
6285
+ }
6286
+ function createDatabaseInquiryTask(intentName, operation, tableName, options = {}) {
6285
6287
  return CadenzaService.createMetaTask(
6286
- `Execute local graph sync ${operation} for ${tableName}`,
6288
+ `Execute graph sync ${operation} for ${tableName}`,
6287
6289
  async (ctx, _emit, inquire) => {
6288
6290
  if (!intentName) {
6289
6291
  return {
6290
6292
  ...ctx,
6291
6293
  errored: true,
6292
6294
  __success: false,
6293
- __error: `No local ${operation} intent found for ${tableName}`
6295
+ __error: `No ${operation} intent found for ${tableName}`
6294
6296
  };
6295
6297
  }
6296
6298
  const inquiryContext = {
@@ -6298,12 +6300,29 @@ function createLocalDatabaseInquiryTask(localTask, operation, tableName, options
6298
6300
  queryData: ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : {}
6299
6301
  };
6300
6302
  const result = await inquire(intentName, inquiryContext, {});
6303
+ const normalizedResult = result && typeof result === "object" ? result : {};
6304
+ if (Object.keys(normalizedResult).length === 0 && normalizedResult.errored !== true && normalizedResult.__success !== true && normalizedResult.__inquiryMeta === void 0) {
6305
+ return {
6306
+ ...ctx,
6307
+ errored: true,
6308
+ __success: false,
6309
+ __error: `No responders available for ${intentName}`,
6310
+ __inquiryMeta: {
6311
+ inquiry: intentName,
6312
+ eligibleResponders: 0,
6313
+ responded: 0,
6314
+ failed: 0,
6315
+ timedOut: 0,
6316
+ pending: 0
6317
+ }
6318
+ };
6319
+ }
6301
6320
  return {
6302
6321
  ...ctx,
6303
- ...result
6322
+ ...normalizedResult
6304
6323
  };
6305
6324
  },
6306
- `Executes the local ${tableName} ${operation} operation through the generated database intent.`,
6325
+ `Executes the ${tableName} ${operation} operation through the generated database intent.`,
6307
6326
  {
6308
6327
  ...options,
6309
6328
  register: false,
@@ -6313,18 +6332,24 @@ function createLocalDatabaseInquiryTask(localTask, operation, tableName, options
6313
6332
  }
6314
6333
  function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, options = {}) {
6315
6334
  const localInsertTask = CadenzaService.getLocalCadenzaDBInsertTask(tableName);
6316
- const remoteInsertTask = isCadenzaDBReady ? CadenzaService.createCadenzaDBInsertTask(tableName, queryData, options) : void 0;
6317
6335
  const debugTable = shouldDebugSyncTable(tableName);
6318
- if (!localInsertTask && !remoteInsertTask) {
6336
+ if (!localInsertTask && !isCadenzaDBReady) {
6319
6337
  return void 0;
6320
6338
  }
6321
- const targetTask = localInsertTask ? createLocalDatabaseInquiryTask(localInsertTask, "insert", tableName, options) : remoteInsertTask;
6339
+ const targetIntentName = resolveLocalDatabaseTaskIntent(localInsertTask, "insert", tableName) ?? buildAuthoritySyncIntentName("insert", tableName);
6340
+ const targetTask = createDatabaseInquiryTask(
6341
+ targetIntentName,
6342
+ "insert",
6343
+ tableName,
6344
+ options
6345
+ );
6322
6346
  if (debugTable) {
6323
6347
  logSyncDebug("insert_task_resolved", {
6324
6348
  tableName,
6325
6349
  localInsertTaskName: localInsertTask?.name ?? null,
6326
- remoteInsertTaskName: remoteInsertTask?.name ?? null,
6350
+ remoteInsertTaskName: isCadenzaDBReady ? targetIntentName : null,
6327
6351
  targetTaskName: targetTask.name,
6352
+ targetIntentName,
6328
6353
  queryData,
6329
6354
  options
6330
6355
  });
@@ -6483,10 +6508,10 @@ var SYNC_DEBUG_INTENT_NAMES = /* @__PURE__ */ new Set([
6483
6508
  "iot-anomaly-runtime-get",
6484
6509
  "iot-prediction-compute",
6485
6510
  "iot-db-telemetry-insert",
6486
- "query-pg-CadenzaDBPostgresActor-service_instance",
6487
- "query-pg-CadenzaDBPostgresActor-service_instance_transport",
6488
- "query-pg-CadenzaDBPostgresActor-intent_to_task_map",
6489
- "query-pg-CadenzaDBPostgresActor-signal_to_task_map"
6511
+ "query-pg-cadenza-db-postgres-actor-service_instance",
6512
+ "query-pg-cadenza-db-postgres-actor-service_instance_transport",
6513
+ "query-pg-cadenza-db-postgres-actor-intent_to_task_map",
6514
+ "query-pg-cadenza-db-postgres-actor-signal_to_task_map"
6490
6515
  ]);
6491
6516
  function shouldDebugSyncTable(tableName) {
6492
6517
  return SYNC_DEBUG_TABLES.has(tableName);
@@ -6592,11 +6617,16 @@ function resolveSyncQueryRows(ctx, tableName) {
6592
6617
  }
6593
6618
  function resolveSyncQueryTask(isCadenzaDBReady, tableName, queryData = {}, options = {}) {
6594
6619
  const localQueryTask = CadenzaService.getLocalCadenzaDBQueryTask(tableName);
6595
- const remoteQueryTask = isCadenzaDBReady ? CadenzaService.createCadenzaDBQueryTask(tableName, queryData, options) : void 0;
6596
- if (!localQueryTask && !remoteQueryTask) {
6620
+ if (!localQueryTask && !isCadenzaDBReady) {
6597
6621
  return void 0;
6598
6622
  }
6599
- const targetTask = localQueryTask ? createLocalDatabaseInquiryTask(localQueryTask, "query", tableName, options) : remoteQueryTask;
6623
+ const targetIntentName = resolveLocalDatabaseTaskIntent(localQueryTask, "query", tableName) ?? buildAuthoritySyncIntentName("query", tableName);
6624
+ const targetTask = createDatabaseInquiryTask(
6625
+ targetIntentName,
6626
+ "query",
6627
+ tableName,
6628
+ options
6629
+ );
6600
6630
  const prepareQueryTask = CadenzaService.createMetaTask(
6601
6631
  `Prepare graph sync query for ${tableName}`,
6602
6632
  (ctx) => ({