@cadenza.io/service 2.17.69 → 2.17.71

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
@@ -8763,24 +8763,65 @@ function buildMinimalSyncSignalContext(ctx, extra = {}) {
8763
8763
  return nextContext;
8764
8764
  }
8765
8765
  function buildSyncInsertQueryData(ctx, queryData = {}) {
8766
+ const pickQueryData = (source, allowedKeys) => {
8767
+ const next = {};
8768
+ for (const key of allowedKeys) {
8769
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
8770
+ next[key] = source[key];
8771
+ }
8772
+ }
8773
+ return next;
8774
+ };
8766
8775
  const joinedQueryData = getJoinedContextValue(ctx, "queryData");
8767
8776
  const existingQueryData = ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : joinedQueryData && typeof joinedQueryData === "object" ? joinedQueryData : {};
8768
8777
  const nextQueryData = {
8769
- ...existingQueryData,
8778
+ ...pickQueryData(existingQueryData, ["transaction"]),
8770
8779
  ...queryData
8771
8780
  };
8772
8781
  const resolvedData = Object.prototype.hasOwnProperty.call(ctx, "data") || ctx.data !== void 0 ? ctx.data : getJoinedContextValue(ctx, "data");
8773
8782
  const resolvedBatch = Object.prototype.hasOwnProperty.call(ctx, "batch") || ctx.batch !== void 0 ? ctx.batch : getJoinedContextValue(ctx, "batch");
8774
8783
  if (resolvedData !== void 0) {
8775
8784
  nextQueryData.data = resolvedData && typeof resolvedData === "object" && !Array.isArray(resolvedData) ? { ...resolvedData } : resolvedData;
8785
+ } else {
8786
+ delete nextQueryData.data;
8776
8787
  }
8777
8788
  if (resolvedBatch !== void 0) {
8778
8789
  nextQueryData.batch = Array.isArray(resolvedBatch) ? resolvedBatch.map(
8779
8790
  (row) => row && typeof row === "object" ? { ...row } : row
8780
8791
  ) : resolvedBatch;
8792
+ } else {
8793
+ delete nextQueryData.batch;
8781
8794
  }
8782
8795
  return nextQueryData;
8783
8796
  }
8797
+ function buildSyncQueryQueryData(ctx, queryData = {}) {
8798
+ const joinedQueryData = getJoinedContextValue(ctx, "queryData");
8799
+ const existingQueryData = ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : joinedQueryData && typeof joinedQueryData === "object" ? joinedQueryData : {};
8800
+ const nextQueryData = {};
8801
+ const allowedKeys = [
8802
+ "transaction",
8803
+ "filter",
8804
+ "fields",
8805
+ "joins",
8806
+ "sort",
8807
+ "limit",
8808
+ "offset",
8809
+ "queryMode",
8810
+ "aggregates",
8811
+ "groupBy"
8812
+ ];
8813
+ for (const key of allowedKeys) {
8814
+ if (Object.prototype.hasOwnProperty.call(existingQueryData, key)) {
8815
+ nextQueryData[key] = existingQueryData[key];
8816
+ }
8817
+ }
8818
+ return {
8819
+ ...nextQueryData,
8820
+ ...queryData
8821
+ };
8822
+ }
8823
+ var REMOTE_AUTHORITY_SYNC_INSERT_CONCURRENCY = 5;
8824
+ var REMOTE_AUTHORITY_SYNC_QUERY_CONCURRENCY = 3;
8784
8825
  function wireSyncTaskGraph(predecessorTask, graph, ...completionTasks) {
8785
8826
  if (!graph) {
8786
8827
  return void 0;
@@ -8791,6 +8832,20 @@ function wireSyncTaskGraph(predecessorTask, graph, ...completionTasks) {
8791
8832
  }
8792
8833
  return graph.completionTask;
8793
8834
  }
8835
+ function buildSyncExecutionEnvelope(ctx, queryData) {
8836
+ const originalContext = { ...ctx };
8837
+ const nextContext = {
8838
+ __syncing: ctx.__syncing === true || ctx.__metadata?.__syncing === true || false,
8839
+ __preferredTransportProtocol: "rest",
8840
+ __resolverOriginalContext: originalContext,
8841
+ __resolverQueryData: queryData,
8842
+ queryData
8843
+ };
8844
+ if (typeof ctx.__reason === "string" && ctx.__reason.trim().length > 0) {
8845
+ nextContext.__reason = ctx.__reason;
8846
+ }
8847
+ return nextContext;
8848
+ }
8794
8849
  function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, options = {}) {
8795
8850
  const localInsertTask = CadenzaService.getLocalCadenzaDBInsertTask(tableName);
8796
8851
  const debugTable = shouldDebugSyncTable(tableName);
@@ -8799,6 +8854,10 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
8799
8854
  }
8800
8855
  const targetTask = localInsertTask ?? CadenzaService.createCadenzaDBInsertTask(tableName, queryData, {
8801
8856
  ...options,
8857
+ concurrency: Number(options.concurrency) > 0 ? Math.min(
8858
+ Number(options.concurrency),
8859
+ REMOTE_AUTHORITY_SYNC_INSERT_CONCURRENCY
8860
+ ) : REMOTE_AUTHORITY_SYNC_INSERT_CONCURRENCY,
8802
8861
  register: false,
8803
8862
  isHidden: true
8804
8863
  });
@@ -8815,18 +8874,14 @@ function resolveSyncInsertTask(isCadenzaDBReady, tableName, queryData = {}, opti
8815
8874
  const prepareExecutionTask = CadenzaService.createMetaTask(
8816
8875
  `Prepare graph sync insert for ${tableName}`,
8817
8876
  (ctx) => {
8818
- const originalContext = { ...ctx };
8819
8877
  const originalQueryData = buildSyncInsertQueryData(
8820
8878
  ctx,
8821
8879
  queryData
8822
8880
  );
8823
- return {
8824
- ...ctx,
8825
- __preferredTransportProtocol: "rest",
8826
- __resolverOriginalContext: originalContext,
8827
- __resolverQueryData: originalQueryData,
8828
- queryData: originalQueryData
8829
- };
8881
+ return buildSyncExecutionEnvelope(
8882
+ ctx,
8883
+ originalQueryData
8884
+ );
8830
8885
  },
8831
8886
  `Prepares ${tableName} graph-sync insert payloads for runner execution.`,
8832
8887
  {
@@ -9073,19 +9128,19 @@ function resolveSyncQueryTask(isCadenzaDBReady, tableName, queryData = {}, optio
9073
9128
  }
9074
9129
  const targetTask = localQueryTask ?? CadenzaService.createCadenzaDBQueryTask(tableName, queryData, {
9075
9130
  ...options,
9131
+ concurrency: Number(options.concurrency) > 0 ? Math.min(
9132
+ Number(options.concurrency),
9133
+ REMOTE_AUTHORITY_SYNC_QUERY_CONCURRENCY
9134
+ ) : REMOTE_AUTHORITY_SYNC_QUERY_CONCURRENCY,
9076
9135
  register: false,
9077
9136
  isHidden: true
9078
9137
  });
9079
9138
  const prepareQueryTask = CadenzaService.createMetaTask(
9080
9139
  `Prepare graph sync query for ${tableName}`,
9081
- (ctx) => ({
9082
- ...ctx,
9083
- __preferredTransportProtocol: "rest",
9084
- queryData: {
9085
- ...ctx.queryData && typeof ctx.queryData === "object" ? ctx.queryData : {},
9086
- ...queryData
9087
- }
9088
- }),
9140
+ (ctx) => buildSyncExecutionEnvelope(
9141
+ ctx,
9142
+ buildSyncQueryQueryData(ctx, queryData)
9143
+ ),
9089
9144
  `Prepares ${tableName} graph-sync query payloads.`,
9090
9145
  {
9091
9146
  register: false,