@cadenza.io/service 2.17.59 → 2.17.60

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
@@ -8770,93 +8770,23 @@ function wireSyncTaskGraph(predecessorTask, graph, ...completionTasks) {
8770
8770
  }
8771
8771
  return graph.completionTask;
8772
8772
  }
8773
- function resolveLocalDatabaseTaskIntent(task, operation, tableName) {
8774
- if (!task) {
8775
- return void 0;
8776
- }
8777
- const expectedPrefix = `${operation}-pg-`;
8778
- const expectedSuffix = `-${tableName}`;
8779
- const handledIntents = Array.from(task.handlesIntents ?? []);
8780
- const directMatch = handledIntents.find(
8781
- (intent) => typeof intent === "string" && intent.startsWith(expectedPrefix) && intent.endsWith(expectedSuffix)
8782
- );
8783
- if (directMatch) {
8784
- return directMatch;
8785
- }
8786
- return handledIntents.find(
8787
- (intent) => typeof intent === "string" && intent.startsWith(expectedPrefix)
8788
- );
8789
- }
8790
- function buildAuthoritySyncIntentName(operation, tableName) {
8791
- return `${operation}-pg-cadenza-db-postgres-actor-${tableName}`;
8792
- }
8793
- function createDatabaseInquiryTask(intentName, operation, tableName, options = {}) {
8794
- return CadenzaService.createMetaTask(
8795
- `Execute graph sync ${operation} for ${tableName}`,
8796
- async (ctx, _emit, inquire) => {
8797
- if (!intentName) {
8798
- return {
8799
- ...ctx,
8800
- errored: true,
8801
- __success: false,
8802
- __error: `No ${operation} intent found for ${tableName}`
8803
- };
8804
- }
8805
- const inquiryContext = {
8806
- ...ctx,
8807
- queryData: ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : {}
8808
- };
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
- }
8827
- return {
8828
- ...ctx,
8829
- ...normalizedResult
8830
- };
8831
- },
8832
- `Executes the ${tableName} ${operation} operation through the generated database intent.`,
8833
- {
8834
- ...options,
8835
- register: false,
8836
- isHidden: true
8837
- }
8838
- );
8839
- }
8840
8773
  function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, options = {}) {
8841
8774
  const localInsertTask = CadenzaService.getLocalCadenzaDBInsertTask(tableName);
8842
8775
  const debugTable = shouldDebugSyncTable(tableName);
8843
8776
  if (!localInsertTask && !isCadenzaDBReady) {
8844
8777
  return void 0;
8845
8778
  }
8846
- const targetIntentName = resolveLocalDatabaseTaskIntent(localInsertTask, "insert", tableName) ?? buildAuthoritySyncIntentName("insert", tableName);
8847
- const targetTask = createDatabaseInquiryTask(
8848
- targetIntentName,
8849
- "insert",
8850
- tableName,
8851
- options
8852
- );
8779
+ const targetTask = localInsertTask ?? CadenzaService.createCadenzaDBInsertTask(tableName, queryData, {
8780
+ ...options,
8781
+ register: false,
8782
+ isHidden: true
8783
+ });
8853
8784
  if (debugTable) {
8854
8785
  logSyncDebug("insert_task_resolved", {
8855
8786
  tableName,
8856
8787
  localInsertTaskName: localInsertTask?.name ?? null,
8857
- remoteInsertTaskName: isCadenzaDBReady ? targetIntentName : null,
8788
+ remoteInsertTaskName: isCadenzaDBReady ? targetTask.name : null,
8858
8789
  targetTaskName: targetTask.name,
8859
- targetIntentName,
8860
8790
  queryData,
8861
8791
  options
8862
8792
  });
@@ -9127,13 +9057,11 @@ function resolveSyncQueryTask(isCadenzaDBReady, tableName, queryData = {}, optio
9127
9057
  if (!localQueryTask && !isCadenzaDBReady) {
9128
9058
  return void 0;
9129
9059
  }
9130
- const targetIntentName = resolveLocalDatabaseTaskIntent(localQueryTask, "query", tableName) ?? buildAuthoritySyncIntentName("query", tableName);
9131
- const targetTask = createDatabaseInquiryTask(
9132
- targetIntentName,
9133
- "query",
9134
- tableName,
9135
- options
9136
- );
9060
+ const targetTask = localQueryTask ?? CadenzaService.createCadenzaDBQueryTask(tableName, queryData, {
9061
+ ...options,
9062
+ register: false,
9063
+ isHidden: true
9064
+ });
9137
9065
  const prepareQueryTask = CadenzaService.createMetaTask(
9138
9066
  `Prepare graph sync query for ${tableName}`,
9139
9067
  (ctx) => ({