@cadenza.io/service 2.17.25 → 2.17.26

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
@@ -715,6 +715,38 @@ function buildServiceRegistryInsertQueryData(ctx, queryData) {
715
715
  }
716
716
  return nextQueryData;
717
717
  }
718
+ function normalizeServiceRegistryInsertResult(tableName, ctx, queryData, rawResult) {
719
+ if (!rawResult || typeof rawResult !== "object") {
720
+ return rawResult;
721
+ }
722
+ const result = { ...rawResult };
723
+ const normalizedQueryData = result.queryData && typeof result.queryData === "object" ? { ...result.queryData } : { ...queryData };
724
+ const resolvedData = result.data ?? normalizedQueryData.data ?? queryData.data ?? ctx.data ?? ctx.__registrationData;
725
+ if (resolvedData !== void 0 && result.data === void 0) {
726
+ result.data = resolvedData;
727
+ }
728
+ if (resolvedData !== void 0 && (normalizedQueryData.data === void 0 || normalizedQueryData.data === null)) {
729
+ normalizedQueryData.data = resolvedData;
730
+ }
731
+ result.queryData = normalizedQueryData;
732
+ if (tableName === "service") {
733
+ const resolvedServiceName = String(
734
+ result.__serviceName ?? resolvedData?.name ?? resolvedData?.service_name ?? ctx.__serviceName ?? ""
735
+ ).trim();
736
+ if (resolvedServiceName) {
737
+ result.__serviceName = resolvedServiceName;
738
+ }
739
+ }
740
+ if (tableName === "service_instance" || tableName === "service_instance_transport") {
741
+ const resolvedUuid = String(
742
+ result.uuid ?? resolvedData?.uuid ?? ctx.__serviceInstanceId ?? ""
743
+ ).trim();
744
+ if (resolvedUuid) {
745
+ result.uuid = resolvedUuid;
746
+ }
747
+ }
748
+ return result;
749
+ }
718
750
  function resolveServiceRegistryInsertTask(tableName, queryData = {}, options = {}) {
719
751
  const remoteInsertTask = CadenzaService.createCadenzaDBInsertTask(
720
752
  tableName,
@@ -738,14 +770,26 @@ function resolveServiceRegistryInsertTask(tableName, queryData = {}, options = {
738
770
  );
739
771
  }
740
772
  const targetTask = CadenzaService.getLocalCadenzaDBInsertTask(tableName) ?? remoteInsertTask;
741
- return targetTask.taskFunction(
742
- {
743
- ...ctx,
744
- queryData: nextQueryData
745
- },
746
- emit,
747
- inquire,
748
- progressCallback
773
+ const delegationContext = ensureDelegationContextMetadata({
774
+ ...ctx,
775
+ queryData: nextQueryData
776
+ });
777
+ delegationContext.__metadata.__skipRemoteExecution = delegationContext.__metadata.__skipRemoteExecution ?? delegationContext.__skipRemoteExecution ?? false;
778
+ delegationContext.__metadata.__blockRemoteExecution = delegationContext.__metadata.__blockRemoteExecution ?? delegationContext.__blockRemoteExecution ?? false;
779
+ return Promise.resolve(
780
+ targetTask.taskFunction(
781
+ delegationContext,
782
+ emit,
783
+ inquire,
784
+ progressCallback
785
+ )
786
+ ).then(
787
+ (result) => normalizeServiceRegistryInsertResult(
788
+ tableName,
789
+ ctx,
790
+ nextQueryData,
791
+ result
792
+ )
749
793
  );
750
794
  },
751
795
  `Resolves ${tableName} inserts through the local CadenzaDB task when available.`,
@@ -8317,7 +8361,22 @@ function getJoinedContextValue(ctx, key) {
8317
8361
  return void 0;
8318
8362
  }
8319
8363
  function didSyncInsertSucceed(ctx) {
8320
- return !ctx.errored && ctx.__success !== false;
8364
+ if (ctx.errored || ctx.__success === false) {
8365
+ return false;
8366
+ }
8367
+ const inquiryMeta = ctx.__inquiryMeta && typeof ctx.__inquiryMeta === "object" ? ctx.__inquiryMeta : null;
8368
+ if (!inquiryMeta) {
8369
+ return true;
8370
+ }
8371
+ const eligibleResponders = Number(inquiryMeta.eligibleResponders);
8372
+ if (Number.isFinite(eligibleResponders) && eligibleResponders === 0) {
8373
+ return false;
8374
+ }
8375
+ const responded = Number(inquiryMeta.responded);
8376
+ if (Number.isFinite(responded) && responded === 0) {
8377
+ return false;
8378
+ }
8379
+ return true;
8321
8380
  }
8322
8381
  function buildSyncInsertQueryData(ctx, queryData = {}) {
8323
8382
  const joinedQueryData = getJoinedContextValue(ctx, "queryData");
@@ -9441,6 +9500,11 @@ var GraphSyncController = class _GraphSyncController {
9441
9500
  { __syncing: true },
9442
9501
  18e4
9443
9502
  );
9503
+ CadenzaService.schedule(
9504
+ "meta.sync_controller.sync_tick",
9505
+ { __syncing: true },
9506
+ 250
9507
+ );
9444
9508
  CadenzaService.schedule("meta.sync_requested", { __syncing: true }, 2e3);
9445
9509
  }
9446
9510
  }
@@ -9841,20 +9905,28 @@ var CadenzaService = class {
9841
9905
  return false;
9842
9906
  });
9843
9907
  if (responders.length === 0) {
9908
+ const inquiryMeta = {
9909
+ inquiry,
9910
+ isMetaInquiry,
9911
+ totalResponders: allResponders.length,
9912
+ eligibleResponders: 0,
9913
+ filteredOutResponders: allResponders.length,
9914
+ responded: 0,
9915
+ failed: 0,
9916
+ timedOut: 0,
9917
+ pending: 0,
9918
+ durationMs: 0,
9919
+ responders: []
9920
+ };
9921
+ if (options.requireComplete) {
9922
+ throw {
9923
+ __inquiryMeta: inquiryMeta,
9924
+ __error: `Inquiry '${inquiry}' had no eligible responders`,
9925
+ errored: true
9926
+ };
9927
+ }
9844
9928
  return {
9845
- __inquiryMeta: {
9846
- inquiry,
9847
- isMetaInquiry,
9848
- totalResponders: allResponders.length,
9849
- eligibleResponders: 0,
9850
- filteredOutResponders: allResponders.length,
9851
- responded: 0,
9852
- failed: 0,
9853
- timedOut: 0,
9854
- pending: 0,
9855
- durationMs: 0,
9856
- responders: []
9857
- }
9929
+ __inquiryMeta: inquiryMeta
9858
9930
  };
9859
9931
  }
9860
9932
  responders.sort(this.compareInquiryResponders.bind(this));