@powerhousedao/connect 1.0.9-dev.0 → 1.0.10-dev.0

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.
Files changed (37) hide show
  1. package/LICENSE +661 -0
  2. package/dist/assets/{app-D9QJBr8i.css → app-BIIVKAZr.css} +223 -60
  3. package/dist/assets/{app-Uu65do7x.js → app-CsiwsM42.js} +2107 -1027
  4. package/dist/assets/{app-loader-BnxLpX27.js → app-loader-C7A2YjX4.js} +365 -191
  5. package/dist/assets/{app-loader-Bnp0H-wa.css → app-loader-pcztQTL4.css} +173 -26
  6. package/dist/assets/{ccip-CpD5P3bc.js → ccip-BG1d6viz.js} +3 -3
  7. package/dist/assets/{content-DV_bRXbH.js → content-0UFgs2d1.js} +37 -7
  8. package/dist/assets/{index-B4m3ucR9.js → index-BMDqhr-9.js} +3 -3
  9. package/dist/assets/{index-Ch_NXi_f.js → index-CTEGX1We.js} +670 -519
  10. package/dist/assets/{index-yrCJMRn6.js → index-yr0-SqYf.js} +4 -4
  11. package/dist/assets/{main.CpORyZoE.js → main.BmcV9296.js} +1 -1
  12. package/dist/assets/{style-D4JhTt_m.css → style-Ce3V83BE.css} +31 -36
  13. package/dist/hmr.js +1 -1
  14. package/dist/index.html +1 -1
  15. package/dist/modules/@powerhousedao/reactor-browser/{chunk-G6LMXRY5.js → chunk-2ONJ2PX4.js} +1 -1
  16. package/dist/modules/@powerhousedao/reactor-browser/{chunk-OYYVE7RP.js → chunk-3C54663M.js} +1 -1
  17. package/dist/modules/@powerhousedao/reactor-browser/{chunk-UDKYG6I4.js → chunk-5QJXNK35.js} +1 -1
  18. package/dist/modules/@powerhousedao/reactor-browser/{chunk-FW7N6EJH.js → chunk-C7QRY43M.js} +3 -3
  19. package/dist/modules/@powerhousedao/reactor-browser/{chunk-45DCPCA7.js → chunk-CO2RVWYY.js} +1 -1
  20. package/dist/modules/@powerhousedao/reactor-browser/{chunk-6MBHOHAA.js → chunk-ISDEPHKP.js} +1 -1
  21. package/dist/modules/@powerhousedao/reactor-browser/{chunk-F3RCGUF6.js → chunk-NHD6VUCD.js} +2 -2
  22. package/dist/modules/@powerhousedao/reactor-browser/{chunk-N5UNGAA6.js → chunk-SQ5HIKYV.js} +346 -172
  23. package/dist/modules/@powerhousedao/reactor-browser/{chunk-M2UUQ5LH.js → chunk-U34SEKEB.js} +2 -2
  24. package/dist/modules/@powerhousedao/reactor-browser/{chunk-IC6B3767.js → chunk-XV42KZK3.js} +1 -1
  25. package/dist/modules/@powerhousedao/reactor-browser/context/index.js +2 -2
  26. package/dist/modules/@powerhousedao/reactor-browser/context/read-mode.js +2 -2
  27. package/dist/modules/@powerhousedao/reactor-browser/hooks/index.js +8 -8
  28. package/dist/modules/@powerhousedao/reactor-browser/hooks/useAddDebouncedOperations.js +3 -3
  29. package/dist/modules/@powerhousedao/reactor-browser/hooks/useConnectCrypto.js +2 -2
  30. package/dist/modules/@powerhousedao/reactor-browser/hooks/useDocumentDrives.js +2 -2
  31. package/dist/modules/@powerhousedao/reactor-browser/hooks/useDocumentEditor.js +5 -5
  32. package/dist/modules/@powerhousedao/reactor-browser/hooks/useDriveActions.js +2 -2
  33. package/dist/modules/@powerhousedao/reactor-browser/hooks/useDriveActionsWithUiNodes.js +3 -3
  34. package/dist/modules/@powerhousedao/reactor-browser/index.js +10 -10
  35. package/dist/modules/@powerhousedao/reactor-browser/reactor.js +2 -2
  36. package/dist/vite-envs.sh +1 -1
  37. package/package.json +9 -9
@@ -11898,11 +11898,14 @@ var PULL_DRIVE_INTERVAL = 1500;
11898
11898
 
11899
11899
  // ../../packages/document-drive/dist/src/server/listener/transmitter/pull-responder.js
11900
11900
  var MAX_REVISIONS_PER_ACK = 100;
11901
+ var _staticLogger;
11902
+ var staticLogger = () => {
11903
+ if (!_staticLogger) {
11904
+ _staticLogger = childLogger(["PullResponderTransmitter", "static"]);
11905
+ }
11906
+ return _staticLogger;
11907
+ };
11901
11908
  var PullResponderTransmitter = class _PullResponderTransmitter {
11902
- static staticLogger = childLogger([
11903
- "PullResponderTransmitter",
11904
- "static"
11905
- ]);
11906
11909
  logger = childLogger([
11907
11910
  "PullResponderTransmitter",
11908
11911
  Math.floor(Math.random() * 999).toString()
@@ -11915,8 +11918,18 @@ var PullResponderTransmitter = class _PullResponderTransmitter {
11915
11918
  this.logger.verbose(`constructor(listener: ${listener.listenerId})`);
11916
11919
  }
11917
11920
  getStrands(options) {
11918
- this.logger.verbose(`getStrands(drive: ${this.listener.driveId}, listener: ${this.listener.listenerId})`);
11919
- return this.manager.getStrands(this.listener.driveId, this.listener.listenerId, options);
11921
+ this.logger.verbose(`[SYNC DEBUG] PullResponderTransmitter.getStrands called for drive: ${this.listener.driveId}, listener: ${this.listener.listenerId}, options: ${JSON.stringify(options || {})}`);
11922
+ return this.manager.getStrands(this.listener.driveId, this.listener.listenerId, options).then((strands) => {
11923
+ this.logger.verbose(`[SYNC DEBUG] PullResponderTransmitter.getStrands returning ${strands.length} strands for drive: ${this.listener.driveId}, listener: ${this.listener.listenerId}`);
11924
+ if (strands.length === 0) {
11925
+ this.logger.verbose(`[SYNC DEBUG] No strands returned for drive: ${this.listener.driveId}, listener: ${this.listener.listenerId}`);
11926
+ } else {
11927
+ for (const strand of strands) {
11928
+ this.logger.verbose(`[SYNC DEBUG] Strand for drive: ${strand.driveId}, document: ${strand.documentId}, scope: ${strand.scope}, operations: ${strand.operations.length}`);
11929
+ }
11930
+ }
11931
+ return strands;
11932
+ });
11920
11933
  }
11921
11934
  disconnect() {
11922
11935
  return Promise.resolve();
@@ -11936,15 +11949,21 @@ var PullResponderTransmitter = class _PullResponderTransmitter {
11936
11949
  }
11937
11950
  return success;
11938
11951
  }
11939
- static async registerPullResponder(driveId, url, filter) {
11940
- _PullResponderTransmitter.staticLogger.verbose(`registerPullResponder(url: ${url})`, filter);
11952
+ static async registerPullResponder(driveId, url, filter, listenerId) {
11953
+ staticLogger().verbose(`registerPullResponder(url: ${url})`, filter);
11941
11954
  const result = await requestGraphql(url, gql`
11942
- mutation registerPullResponderListener($filter: InputListenerFilter!) {
11943
- registerPullResponderListener(filter: $filter) {
11955
+ mutation registerPullResponderListener(
11956
+ $filter: InputListenerFilter!
11957
+ $listenerId: String
11958
+ ) {
11959
+ registerPullResponderListener(
11960
+ filter: $filter
11961
+ listenerId: $listenerId
11962
+ ) {
11944
11963
  listenerId
11945
11964
  }
11946
11965
  }
11947
- `, { filter });
11966
+ `, { filter, listenerId });
11948
11967
  const error = result.errors?.at(0);
11949
11968
  if (error) {
11950
11969
  throw error;
@@ -11955,7 +11974,7 @@ var PullResponderTransmitter = class _PullResponderTransmitter {
11955
11974
  return result.registerPullResponderListener.listenerId;
11956
11975
  }
11957
11976
  static async pullStrands(driveId, url, listenerId, options) {
11958
- this.staticLogger.verbose(`pullStrands(url: ${url}, listener: ${listenerId})`);
11977
+ staticLogger().verbose(`[SYNC DEBUG] PullResponderTransmitter.pullStrands called for drive: ${driveId}, url: ${url}, listener: ${listenerId}, options: ${JSON.stringify(options || {})}`);
11959
11978
  const result = await requestGraphql(url, gql`
11960
11979
  query strands($listenerId: ID!) {
11961
11980
  system {
@@ -11995,27 +12014,34 @@ var PullResponderTransmitter = class _PullResponderTransmitter {
11995
12014
  `, { listenerId });
11996
12015
  const error = result.errors?.at(0);
11997
12016
  if (error) {
12017
+ staticLogger().verbose(`[SYNC DEBUG] Error pulling strands for drive: ${driveId}, listener: ${listenerId}, error: ${JSON.stringify(error)}`);
11998
12018
  throw error;
11999
12019
  }
12000
12020
  if (!result.system) {
12021
+ staticLogger().verbose(`[SYNC DEBUG] No system data returned when pulling strands for drive: ${driveId}, listener: ${listenerId}`);
12001
12022
  return [];
12002
12023
  }
12003
- return result.system.sync.strands.map((s) => ({
12024
+ const strands = result.system.sync.strands.map((s) => ({
12004
12025
  ...s,
12005
12026
  operations: s.operations.map((o) => ({
12006
12027
  ...o,
12007
12028
  input: JSON.parse(o.input)
12008
12029
  }))
12009
12030
  }));
12031
+ staticLogger().verbose(`[SYNC DEBUG] PullResponderTransmitter.pullStrands returning ${strands.length} strands for drive: ${driveId}, listener: ${listenerId}`);
12032
+ if (strands.length > 0) {
12033
+ staticLogger().verbose(`[SYNC DEBUG] Strands being returned: ${strands.map((s) => `${s.documentId}:${s.scope}`).join(", ")}`);
12034
+ }
12035
+ return strands;
12010
12036
  }
12011
12037
  static async acknowledgeStrands(url, listenerId, revisions) {
12012
- this.staticLogger.verbose(`acknowledgeStrands(url: ${url}, listener: ${listenerId})`, revisions);
12038
+ staticLogger().verbose(`acknowledgeStrands(url: ${url}, listener: ${listenerId})`, revisions);
12013
12039
  const chunks = [];
12014
12040
  for (let i = 0; i < revisions.length; i += MAX_REVISIONS_PER_ACK) {
12015
12041
  chunks.push(revisions.slice(i, i + MAX_REVISIONS_PER_ACK));
12016
12042
  }
12017
12043
  if (chunks.length > 1) {
12018
- this.staticLogger.verbose(`Breaking strand acknowledgement into ${chunks.length} chunks...`);
12044
+ staticLogger().verbose(`Breaking strand acknowledgement into ${chunks.length} chunks...`);
12019
12045
  }
12020
12046
  const results = await Promise.allSettled(chunks.map(async (chunk) => {
12021
12047
  const result = await requestGraphql(url, gql`
@@ -12039,74 +12065,124 @@ var PullResponderTransmitter = class _PullResponderTransmitter {
12039
12065
  throw new Error("Error acknowledging strands");
12040
12066
  }
12041
12067
  }
12068
+ /**
12069
+ * This function will only throw if `onError` throws an error (or there is
12070
+ * an unintentionally unhandled error in the pull loop).
12071
+ *
12072
+ * All other errors are caught, logged, and passed to `onError`.
12073
+ *
12074
+ * Because of this, `onError` _may be called multiple times_.
12075
+ */
12042
12076
  static async executePull(driveId, trigger, onStrandUpdate, onError, onRevisions, onAcknowledge) {
12043
- this.staticLogger.verbose(`executePull(driveId: ${driveId}), trigger:`, trigger);
12077
+ staticLogger().verbose(`executePull(driveId: ${driveId}), trigger:`, trigger);
12078
+ staticLogger().info(`[SYNC DEBUG] PullResponderTransmitter.executePull starting for drive: ${driveId}, listenerId: ${trigger.data.listenerId}`);
12079
+ const { url } = trigger.data;
12080
+ let strands;
12081
+ let error;
12082
+ const listenerId = trigger.data.listenerId;
12044
12083
  try {
12045
- const { url, listenerId } = trigger.data;
12046
- const strands = await _PullResponderTransmitter.pullStrands(driveId, url, listenerId);
12047
- this.staticLogger.verbose("Pulled strands...");
12048
- if (!strands.length) {
12049
- onRevisions?.([]);
12050
- this.staticLogger.verbose("No new strands, skipping...");
12051
- return;
12052
- }
12053
- const listenerRevisions = [];
12054
- for (const strand of strands) {
12055
- const operations = strand.operations.map((op) => ({
12056
- ...op,
12057
- scope: strand.scope,
12058
- branch: strand.branch
12059
- }));
12060
- this.staticLogger.verbose("Processing strand...");
12061
- let error = void 0;
12062
- try {
12063
- const result = await onStrandUpdate(strand, {
12064
- type: "trigger",
12065
- trigger
12066
- });
12067
- if (result.error) {
12068
- throw result.error;
12084
+ strands = await _PullResponderTransmitter.pullStrands(driveId, url, listenerId);
12085
+ } catch (e) {
12086
+ error = e;
12087
+ const graphqlError = error;
12088
+ const errors = graphqlError.response?.errors ?? [];
12089
+ for (const err of errors) {
12090
+ if (err.message === "Listener not found") {
12091
+ staticLogger().verbose(`[SYNC DEBUG] Auto-registering pull responder for drive: ${driveId}`);
12092
+ await _PullResponderTransmitter.registerPullResponder(trigger.driveId, url, trigger.filter, listenerId);
12093
+ try {
12094
+ strands = await _PullResponderTransmitter.pullStrands(driveId, url, listenerId);
12095
+ staticLogger().verbose(`Successfully auto-registered and pulled strands for drive: ${driveId}, listenerId: ${listenerId}`);
12096
+ } catch (error2) {
12097
+ staticLogger().error(`Could not resolve 'Listener not found' error by registering a new pull responder for drive: ${driveId}, listenerId: ${listenerId}: ${error2}`);
12098
+ onError(error2);
12099
+ return;
12069
12100
  }
12070
- } catch (e) {
12071
- error = e;
12072
- onError(error);
12073
- }
12074
- listenerRevisions.push({
12075
- branch: strand.branch,
12076
- documentId: strand.documentId || "",
12077
- driveId: strand.driveId,
12078
- revision: operations.pop()?.index ?? -1,
12079
- scope: strand.scope,
12080
- status: error ? error instanceof OperationError ? error.status : "ERROR" : "SUCCESS",
12081
- error
12082
- });
12101
+ break;
12102
+ }
12083
12103
  }
12084
- this.staticLogger.verbose("Processed strands...");
12085
- onRevisions?.(listenerRevisions);
12086
- this.staticLogger.verbose("Acknowledging strands...");
12087
- let success = false;
12104
+ }
12105
+ if (!strands) {
12106
+ staticLogger().error(`Error pulling strands for drive, and could not auto-register: ${driveId}, listenerId: ${trigger.data.listenerId}: ${error}`);
12107
+ onError(error);
12108
+ return;
12109
+ }
12110
+ if (!strands.length) {
12111
+ staticLogger().verbose(`[SYNC DEBUG] No strands returned in pull cycle for drive: ${driveId}, listenerId: ${trigger.data.listenerId}`);
12088
12112
  try {
12089
- await _PullResponderTransmitter.acknowledgeStrands(url, listenerId, listenerRevisions.map((revision) => {
12090
- const { error, ...rest } = revision;
12091
- return rest;
12092
- }));
12093
- success = true;
12094
- } catch (error) {
12095
- this.staticLogger.error("ACK error", error);
12113
+ onRevisions?.([]);
12114
+ } catch (error2) {
12115
+ staticLogger().error(`Error calling onRevisions for drive: ${driveId}, listenerId: ${trigger.data.listenerId}: ${error2}`);
12116
+ onError(error2);
12096
12117
  }
12097
- if (success) {
12098
- this.staticLogger.verbose("Acknowledged strands successfully.");
12099
- } else {
12100
- this.staticLogger.error("Failed to acknowledge strands");
12118
+ return;
12119
+ }
12120
+ staticLogger().verbose(`[SYNC DEBUG] Processing ${strands.length} strands in pull cycle for drive: ${driveId}, listenerId: ${trigger.data.listenerId}`);
12121
+ const listenerRevisions = [];
12122
+ for (const strand of strands) {
12123
+ const operations = strand.operations.map((op) => ({
12124
+ ...op,
12125
+ scope: strand.scope,
12126
+ branch: strand.branch
12127
+ }));
12128
+ staticLogger().verbose(`[SYNC DEBUG] Processing strand for drive: ${strand.driveId}, document: ${strand.documentId}, scope: ${strand.scope}, with ${operations.length} operations`);
12129
+ let error2 = void 0;
12130
+ try {
12131
+ const result = await onStrandUpdate(strand, {
12132
+ type: "trigger",
12133
+ trigger
12134
+ });
12135
+ if (result.error) {
12136
+ throw result.error;
12137
+ }
12138
+ } catch (e) {
12139
+ staticLogger().error(`Error processing strand for drive: ${strand.driveId}, document: ${strand.documentId}, scope: ${strand.scope}, with ${operations.length} operations: ${e}`);
12140
+ error2 = e;
12141
+ onError(error2);
12101
12142
  }
12143
+ listenerRevisions.push({
12144
+ branch: strand.branch,
12145
+ documentId: strand.documentId || "",
12146
+ driveId: strand.driveId,
12147
+ revision: operations.pop()?.index ?? -1,
12148
+ scope: strand.scope,
12149
+ status: error2 ? error2 instanceof OperationError ? error2.status : "ERROR" : "SUCCESS",
12150
+ error: error2
12151
+ });
12152
+ }
12153
+ staticLogger().verbose("Processed strands...");
12154
+ try {
12155
+ onRevisions?.(listenerRevisions);
12156
+ } catch (error2) {
12157
+ staticLogger().error(`Error calling onRevisions for drive: ${driveId}, listenerId: ${trigger.data.listenerId}: ${error2}`);
12158
+ onError(error2);
12159
+ }
12160
+ staticLogger().verbose(`[SYNC DEBUG] Acknowledging ${listenerRevisions.length} strands for drive: ${driveId}, listenerId: ${trigger.data.listenerId}`);
12161
+ let success = false;
12162
+ try {
12163
+ await _PullResponderTransmitter.acknowledgeStrands(url, trigger.data.listenerId, listenerRevisions.map((revision) => {
12164
+ const { error: error2, ...rest } = revision;
12165
+ return rest;
12166
+ }));
12167
+ success = true;
12168
+ } catch (error2) {
12169
+ staticLogger().error(`Error acknowledging strands for drive: ${driveId}, listenerId: ${trigger.data.listenerId}: ${error2}`);
12170
+ onError(error2);
12171
+ }
12172
+ if (success) {
12173
+ staticLogger().verbose(`[SYNC DEBUG] Successfully acknowledged strands for drive: ${driveId}, listenerId: ${trigger.data.listenerId}`);
12174
+ } else {
12175
+ staticLogger().error("Failed to acknowledge strands");
12176
+ }
12177
+ try {
12102
12178
  onAcknowledge?.(success);
12103
- } catch (error) {
12104
- this.staticLogger.error("Pull error", error);
12105
- onError(error);
12179
+ } catch (error2) {
12180
+ staticLogger().error(`Error calling onAcknowledge for drive: ${driveId}, listenerId: ${trigger.data.listenerId}: ${error2}`);
12181
+ onError(error2);
12106
12182
  }
12107
12183
  }
12108
12184
  static setupPull(driveId, trigger, onStrandUpdate, onError, onRevisions, onAcknowledge) {
12109
- this.staticLogger.verbose(`setupPull(drive: ${driveId}), trigger:`, trigger);
12185
+ staticLogger().verbose(`[SYNC DEBUG] PullResponderTransmitter.setupPull initiated for drive: ${driveId}, listenerId: ${trigger.data.listenerId}`);
12110
12186
  const { interval } = trigger.data;
12111
12187
  let loopInterval = PULL_DRIVE_INTERVAL;
12112
12188
  if (interval) {
@@ -12118,20 +12194,25 @@ var PullResponderTransmitter = class _PullResponderTransmitter {
12118
12194
  } catch {
12119
12195
  }
12120
12196
  }
12197
+ staticLogger().verbose(`[SYNC DEBUG] Pull interval set to ${loopInterval}ms for drive: ${driveId}, listenerId: ${trigger.data.listenerId}`);
12121
12198
  let isCancelled = false;
12122
12199
  let timeout;
12123
12200
  const executeLoop = async () => {
12124
12201
  while (!isCancelled) {
12125
- this.staticLogger.verbose("Execute loop...");
12202
+ staticLogger().verbose(`[SYNC DEBUG] Starting pull cycle for drive: ${driveId}, listenerId: ${trigger.data.listenerId}`);
12126
12203
  await this.executePull(driveId, trigger, onStrandUpdate, onError, onRevisions, onAcknowledge);
12204
+ staticLogger().verbose(`[SYNC DEBUG] Completed pull cycle for drive: ${driveId}, listenerId: ${trigger.data.listenerId}, waiting ${loopInterval}ms for next cycle`);
12127
12205
  await new Promise((resolve) => {
12128
- this.staticLogger.verbose(`Scheduling next pull in ${loopInterval} ms`);
12206
+ staticLogger().verbose(`Scheduling next pull in ${loopInterval} ms`);
12129
12207
  timeout = setTimeout(resolve, loopInterval);
12130
12208
  });
12131
12209
  }
12132
12210
  };
12133
- executeLoop().catch(this.staticLogger.error);
12211
+ executeLoop().catch((error) => {
12212
+ staticLogger().error(`Error in executeLoop for drive: ${driveId}, listenerId: ${trigger.data.listenerId}: ${error}`);
12213
+ });
12134
12214
  return () => {
12215
+ staticLogger().verbose(`[SYNC DEBUG] Cancelling pull loop for drive: ${driveId}, listenerId: ${trigger.data.listenerId}`);
12135
12216
  isCancelled = true;
12136
12217
  if (timeout !== void 0) {
12137
12218
  clearTimeout(timeout);
@@ -12139,17 +12220,20 @@ var PullResponderTransmitter = class _PullResponderTransmitter {
12139
12220
  };
12140
12221
  }
12141
12222
  static async createPullResponderTrigger(driveId, url, options) {
12142
- this.staticLogger.verbose(`createPullResponderTrigger(drive: ${driveId}, url: ${url})`);
12223
+ staticLogger().verbose(`createPullResponderTrigger(drive: ${driveId}, url: ${url})`);
12143
12224
  const { pullFilter, pullInterval } = options;
12144
- const listenerId = await _PullResponderTransmitter.registerPullResponder(driveId, url, pullFilter ?? {
12225
+ const filter = pullFilter ?? {
12145
12226
  documentId: ["*"],
12146
12227
  documentType: ["*"],
12147
12228
  branch: ["*"],
12148
12229
  scope: ["*"]
12149
- });
12230
+ };
12231
+ const listenerId = await _PullResponderTransmitter.registerPullResponder(driveId, url, filter);
12150
12232
  const pullTrigger = {
12151
12233
  id: generateUUID(),
12152
12234
  type: "PullResponder",
12235
+ driveId,
12236
+ filter,
12153
12237
  data: {
12154
12238
  url,
12155
12239
  listenerId,
@@ -12276,6 +12360,7 @@ function isAtRevision(document, revisions) {
12276
12360
 
12277
12361
  // ../../packages/document-drive/dist/src/server/base-server.js
12278
12362
  var BaseDocumentDriveServer = class {
12363
+ logger = childLogger(["BaseDocumentDriveServer"]);
12279
12364
  // external dependencies
12280
12365
  documentModelModules;
12281
12366
  storage;
@@ -12347,19 +12432,19 @@ var BaseDocumentDriveServer = class {
12347
12432
  async _initialize() {
12348
12433
  await this.listenerManager.initialize(this.handleListenerError);
12349
12434
  await this.queueManager.init(this.queueDelegate, (error) => {
12350
- logger.error(`Error initializing queue manager`, error);
12435
+ this.logger.error(`Error initializing queue manager`, error);
12351
12436
  errors.push(error);
12352
12437
  });
12353
12438
  try {
12354
12439
  await this.defaultDrivesManager.removeOldremoteDrives();
12355
12440
  } catch (error) {
12356
- logger.error(error);
12441
+ this.logger.error(error);
12357
12442
  }
12358
12443
  const errors = [];
12359
12444
  const drives = await this.getDrives();
12360
12445
  for (const drive of drives) {
12361
12446
  await this._initializeDrive(drive).catch((error) => {
12362
- logger.error(`Error initializing drive ${drive}`, error);
12447
+ this.logger.error(`Error initializing drive ${drive}`, error);
12363
12448
  errors.push(error);
12364
12449
  });
12365
12450
  }
@@ -12389,7 +12474,7 @@ var BaseDocumentDriveServer = class {
12389
12474
  return source.type === "local" ? "push" : "pull";
12390
12475
  }
12391
12476
  handleListenerError(error, driveId, listener) {
12392
- logger.error(`Listener ${listener.listener.label ?? listener.listener.listenerId} error:`, error);
12477
+ this.logger.error(`Listener ${listener.listener.label ?? listener.listener.listenerId} error:`, error);
12393
12478
  const status = error instanceof OperationError ? error.status : "ERROR";
12394
12479
  this.synchronizationManager.updateSyncStatus(driveId, { push: status }, error);
12395
12480
  }
@@ -12449,9 +12534,9 @@ var BaseDocumentDriveServer = class {
12449
12534
  if (pushListener) {
12450
12535
  this.getSynchronizationUnitsRevision(driveId, syncUnits).then((syncUnitRevisions) => {
12451
12536
  for (const revision of syncUnitRevisions) {
12452
- this.listenerManager.updateListenerRevision(pushListener.listenerId, driveId, revision.syncId, revision.revision).catch(logger.error);
12537
+ this.listenerManager.updateListenerRevision(pushListener.listenerId, driveId, revision.syncId, revision.revision).catch(this.logger.error);
12453
12538
  }
12454
- }).catch(logger.error);
12539
+ }).catch(this.logger.error);
12455
12540
  }
12456
12541
  }
12457
12542
  });
@@ -12473,14 +12558,19 @@ var BaseDocumentDriveServer = class {
12473
12558
  }
12474
12559
  async _initializeDrive(driveId) {
12475
12560
  const drive = await this.getDrive(driveId);
12561
+ this.logger.verbose(`[SYNC DEBUG] Initializing drive ${driveId} with slug "${drive.state.global.slug}"`);
12476
12562
  await this.synchronizationManager.initializeDriveSyncStatus(driveId, drive);
12477
12563
  if (this.shouldSyncRemoteDrive(drive)) {
12564
+ this.logger.verbose(`[SYNC DEBUG] Starting sync for remote drive ${driveId}`);
12478
12565
  await this.startSyncRemoteDrive(driveId);
12479
12566
  }
12567
+ this.logger.verbose(`[SYNC DEBUG] Processing ${drive.state.local.listeners.length} listeners for drive ${driveId}`);
12480
12568
  for (const zodListener of drive.state.local.listeners) {
12481
12569
  if (zodListener.callInfo?.transmitterType === "SwitchboardPush") {
12570
+ this.logger.verbose(`[SYNC DEBUG] Setting up SwitchboardPush listener ${zodListener.listenerId} for drive ${driveId}`);
12482
12571
  const transmitter = new SwitchboardPushTransmitter(zodListener.callInfo?.data ?? "");
12483
- this.listenerManager.setListener(driveId, {
12572
+ this.logger.verbose(`[SYNC DEBUG] Created SwitchboardPush transmitter with URL: ${zodListener.callInfo?.data || "none"}`);
12573
+ await this.listenerManager.setListener(driveId, {
12484
12574
  block: zodListener.block,
12485
12575
  driveId: drive.state.global.id,
12486
12576
  filter: {
@@ -12494,7 +12584,29 @@ var BaseDocumentDriveServer = class {
12494
12584
  system: zodListener.system,
12495
12585
  label: zodListener.label ?? "",
12496
12586
  transmitter
12587
+ }).then(() => {
12588
+ this.logger.verbose(`[SYNC DEBUG] Successfully set up listener ${zodListener.listenerId} for drive ${driveId}`);
12497
12589
  });
12590
+ } else if (zodListener.callInfo?.transmitterType === "PullResponder") {
12591
+ this.logger.verbose(`[SYNC DEBUG] Setting up PullResponder listener ${zodListener.listenerId} for drive ${driveId}`);
12592
+ const pullResponderListener = {
12593
+ driveId,
12594
+ listenerId: zodListener.listenerId,
12595
+ block: false,
12596
+ filter: zodListener.filter,
12597
+ system: false,
12598
+ label: `PullResponder #${zodListener.listenerId}`,
12599
+ callInfo: {
12600
+ data: "",
12601
+ name: "PullResponder",
12602
+ transmitterType: "PullResponder"
12603
+ }
12604
+ };
12605
+ const pullResponder = new PullResponderTransmitter(pullResponderListener, this.listenerManager);
12606
+ pullResponderListener.transmitter = pullResponder;
12607
+ await this.listenerManager.setListener(driveId, pullResponderListener);
12608
+ } else {
12609
+ this.logger.error(`Skipping listener ${zodListener.listenerId} with unsupported type ${zodListener.callInfo?.transmitterType || "unknown"}`);
12498
12610
  }
12499
12611
  }
12500
12612
  }
@@ -12593,7 +12705,7 @@ var BaseDocumentDriveServer = class {
12593
12705
  }
12594
12706
  }
12595
12707
  } catch (e) {
12596
- logger.error("Error getting drive from cache", e);
12708
+ this.logger.error("Error getting drive from cache", e);
12597
12709
  }
12598
12710
  const driveStorage = document ?? await this.storage.getDrive(driveId);
12599
12711
  const result = this._buildDocument(driveStorage, options);
@@ -12601,7 +12713,7 @@ var BaseDocumentDriveServer = class {
12601
12713
  throw new Error(`Document with id ${driveId} is not a Document Drive`);
12602
12714
  } else {
12603
12715
  if (!options?.revisions) {
12604
- this.cache.setDrive(driveId, result).catch(logger.error);
12716
+ this.cache.setDrive(driveId, result).catch(this.logger.error);
12605
12717
  }
12606
12718
  return result;
12607
12719
  }
@@ -12613,14 +12725,14 @@ var BaseDocumentDriveServer = class {
12613
12725
  return drive;
12614
12726
  }
12615
12727
  } catch (e) {
12616
- logger.error("Error getting drive from cache", e);
12728
+ this.logger.error("Error getting drive from cache", e);
12617
12729
  }
12618
12730
  const driveStorage = await this.storage.getDriveBySlug(slug);
12619
12731
  const document = this._buildDocument(driveStorage, options);
12620
12732
  if (!isDocumentDrive(document)) {
12621
12733
  throw new Error(`Document with slug ${slug} is not a Document Drive`);
12622
12734
  } else {
12623
- this.cache.setDriveBySlug(slug, document).catch(logger.error);
12735
+ this.cache.setDriveBySlug(slug, document).catch(this.logger.error);
12624
12736
  return document;
12625
12737
  }
12626
12738
  }
@@ -12632,12 +12744,12 @@ var BaseDocumentDriveServer = class {
12632
12744
  return cachedDocument;
12633
12745
  }
12634
12746
  } catch (e) {
12635
- logger.error("Error getting document from cache", e);
12747
+ this.logger.error("Error getting document from cache", e);
12636
12748
  }
12637
12749
  const documentStorage = cachedDocument ?? await this.storage.getDocument(driveId, documentId);
12638
12750
  const document = this._buildDocument(documentStorage, options);
12639
12751
  if (!options?.revisions) {
12640
- this.cache.setDocument(documentId, document).catch(logger.error);
12752
+ this.cache.setDocument(documentId, document).catch(this.logger.error);
12641
12753
  }
12642
12754
  return document;
12643
12755
  }
@@ -12692,7 +12804,7 @@ var BaseDocumentDriveServer = class {
12692
12804
  }
12693
12805
  await this.listenerManager.removeSyncUnits(driveId, syncUnits);
12694
12806
  } catch (error) {
12695
- logger.warn("Error deleting document", error);
12807
+ this.logger.warn("Error deleting document", error);
12696
12808
  }
12697
12809
  await this.cache.deleteDocument(documentId);
12698
12810
  return this.storage.deleteDocument(driveId, documentId);
@@ -12864,33 +12976,35 @@ var BaseDocumentDriveServer = class {
12864
12976
  if (result) {
12865
12977
  return result;
12866
12978
  }
12979
+ let jobId;
12980
+ const promise = new Promise((resolve, reject) => {
12981
+ const unsubscribe = this.queueManager.on("jobCompleted", (job, result2) => {
12982
+ if (job.jobId === jobId) {
12983
+ unsubscribe();
12984
+ unsubscribeError();
12985
+ resolve(result2);
12986
+ }
12987
+ });
12988
+ const unsubscribeError = this.queueManager.on("jobFailed", (job, error) => {
12989
+ if (job.jobId === jobId) {
12990
+ unsubscribe();
12991
+ unsubscribeError();
12992
+ reject(error);
12993
+ }
12994
+ });
12995
+ });
12867
12996
  try {
12868
- const jobId = await this.queueManager.addJob({
12997
+ jobId = await this.queueManager.addJob({
12869
12998
  driveId,
12870
12999
  documentId,
12871
13000
  operations,
12872
13001
  options
12873
13002
  });
12874
- return new Promise((resolve, reject) => {
12875
- const unsubscribe = this.queueManager.on("jobCompleted", (job, result2) => {
12876
- if (job.jobId === jobId) {
12877
- unsubscribe();
12878
- unsubscribeError();
12879
- resolve(result2);
12880
- }
12881
- });
12882
- const unsubscribeError = this.queueManager.on("jobFailed", (job, error) => {
12883
- if (job.jobId === jobId) {
12884
- unsubscribe();
12885
- unsubscribeError();
12886
- reject(error);
12887
- }
12888
- });
12889
- });
12890
13003
  } catch (error) {
12891
- logger.error("Error adding job", error);
13004
+ this.logger.error("Error adding job", error);
12892
13005
  throw error;
12893
13006
  }
13007
+ return promise;
12894
13008
  }
12895
13009
  async queueAction(driveId, documentId, action, options) {
12896
13010
  return this.queueActions(driveId, documentId, [action], options);
@@ -12920,7 +13034,7 @@ var BaseDocumentDriveServer = class {
12920
13034
  });
12921
13035
  });
12922
13036
  } catch (error) {
12923
- logger.error("Error adding job", error);
13037
+ this.logger.error("Error adding job", error);
12924
13038
  throw error;
12925
13039
  }
12926
13040
  }
@@ -12951,7 +13065,7 @@ var BaseDocumentDriveServer = class {
12951
13065
  });
12952
13066
  });
12953
13067
  } catch (error) {
12954
- logger.error("Error adding drive job", error);
13068
+ this.logger.error("Error adding drive job", error);
12955
13069
  throw error;
12956
13070
  }
12957
13071
  }
@@ -12968,7 +13082,7 @@ var BaseDocumentDriveServer = class {
12968
13082
  await this._addOperations(driveId, documentId, async (documentStorage) => {
12969
13083
  const result2 = await this._processOperations(driveId, documentId, documentStorage, operations);
12970
13084
  if (!result2.document) {
12971
- logger.error("Invalid document");
13085
+ this.logger.error("Invalid document");
12972
13086
  throw result2.error ?? new Error("Invalid document");
12973
13087
  }
12974
13088
  document = result2.document;
@@ -12982,7 +13096,7 @@ var BaseDocumentDriveServer = class {
12982
13096
  };
12983
13097
  });
12984
13098
  if (document) {
12985
- this.cache.setDocument(documentId, document).catch(logger.error);
13099
+ this.cache.setDocument(documentId, document).catch(this.logger.error);
12986
13100
  }
12987
13101
  const { scopes, branches } = operationsApplied.reduce((acc, operation) => {
12988
13102
  if (!acc.scopes.includes(operation.scope)) {
@@ -13015,7 +13129,7 @@ var BaseDocumentDriveServer = class {
13015
13129
  });
13016
13130
  }
13017
13131
  }).catch((error2) => {
13018
- logger.error("Non handled error updating sync revision", error2);
13132
+ this.logger.error("Non handled error updating sync revision", error2);
13019
13133
  this.synchronizationManager.updateSyncStatus(driveId, {
13020
13134
  [operationSource]: "ERROR"
13021
13135
  }, error2);
@@ -13116,7 +13230,7 @@ var BaseDocumentDriveServer = class {
13116
13230
  });
13117
13231
  });
13118
13232
  } catch (error) {
13119
- logger.error("Error adding drive job", error);
13233
+ this.logger.error("Error adding drive job", error);
13120
13234
  throw error;
13121
13235
  }
13122
13236
  }
@@ -13144,7 +13258,7 @@ var BaseDocumentDriveServer = class {
13144
13258
  if (!document || !isDocumentDrive(document)) {
13145
13259
  throw error ?? new Error("Invalid Document Drive document");
13146
13260
  }
13147
- this.cache.setDrive(driveId, document).catch(logger.error);
13261
+ this.cache.setDrive(driveId, document).catch(this.logger.error);
13148
13262
  const lastOperation = operationsApplied.filter((op) => op.scope === "global").slice().pop();
13149
13263
  if (lastOperation) {
13150
13264
  const newOp = operationsApplied.find((appliedOp) => !operations.find((o) => o.id === appliedOp.id && o.index === appliedOp.index && o.skip === appliedOp.skip && o.hash === appliedOp.hash));
@@ -13171,7 +13285,7 @@ var BaseDocumentDriveServer = class {
13171
13285
  });
13172
13286
  }
13173
13287
  }).catch((error2) => {
13174
- logger.error("Non handled error updating sync revision", error2);
13288
+ this.logger.error("Non handled error updating sync revision", error2);
13175
13289
  this.synchronizationManager.updateSyncStatus(driveId, {
13176
13290
  [operationSource]: "ERROR"
13177
13291
  }, error2);
@@ -13273,9 +13387,26 @@ var BaseDocumentDriveServer = class {
13273
13387
  scope: strand.scope,
13274
13388
  branch: strand.branch
13275
13389
  }));
13276
- const result = await (!strand.documentId ? this.queueDriveOperations(strand.driveId, operations, { source }) : this.queueOperations(strand.driveId, strand.documentId, operations, {
13277
- source
13278
- }));
13390
+ let result;
13391
+ if (strand.documentId) {
13392
+ try {
13393
+ result = await this.queueOperations(strand.driveId, strand.documentId, operations, {
13394
+ source
13395
+ });
13396
+ } catch (error) {
13397
+ this.logger.error("Error queueing operations", error);
13398
+ throw error;
13399
+ }
13400
+ } else {
13401
+ try {
13402
+ result = await this.queueDriveOperations(strand.driveId, operations, {
13403
+ source
13404
+ });
13405
+ } catch (error) {
13406
+ this.logger.error("Error queueing operations", error);
13407
+ throw error;
13408
+ }
13409
+ }
13279
13410
  if (result.status === "ERROR") {
13280
13411
  const syncUnits = strand.documentId !== "" ? (await this.getSynchronizationUnitsIds(strand.driveId, [strand.documentId], [strand.scope], [strand.branch])).map((s) => s.syncId) : [strand.driveId];
13281
13412
  const operationSource = this.getOperationSource(source);
@@ -13447,11 +13578,10 @@ var ListenerManager = class _ListenerManager {
13447
13578
  throw new Error("Maximum retries exhausted.");
13448
13579
  }
13449
13580
  const listenerUpdates = [];
13450
- for (const [driveId, drive] of this.listenerStateByDriveId) {
13451
- for (const [listenerId, listenerState] of drive) {
13581
+ for (const [driveId, listenerStateById] of this.listenerStateByDriveId) {
13582
+ for (const [listenerId, listenerState] of listenerStateById) {
13452
13583
  const transmitter = listenerState.listener.transmitter;
13453
13584
  if (!transmitter?.transmit) {
13454
- this.logger.verbose(`Transmitter not set on listener: ${listenerId}`);
13455
13585
  continue;
13456
13586
  }
13457
13587
  const syncUnits = await this.getListenerSyncUnits(driveId, listenerId);
@@ -13602,57 +13732,78 @@ var ListenerManager = class _ListenerManager {
13602
13732
  }
13603
13733
  }
13604
13734
  async getStrands(driveId, listenerId, options) {
13605
- const listenerState = this.getListenerState(driveId, listenerId);
13735
+ this.logger.verbose(`[SYNC DEBUG] ListenerManager.getStrands called for drive: ${driveId}, listener: ${listenerId}, options: ${JSON.stringify(options || {})}`);
13736
+ let listenerState;
13737
+ try {
13738
+ listenerState = this.getListenerState(driveId, listenerId);
13739
+ this.logger.verbose(`[SYNC DEBUG] Found listener state for drive: ${driveId}, listener: ${listenerId}, status: ${listenerState.listenerStatus}`);
13740
+ } catch (error) {
13741
+ this.logger.error(`[SYNC DEBUG] Failed to find listener state for drive: ${driveId}, listener: ${listenerId}. Error: ${error}`);
13742
+ throw error;
13743
+ }
13606
13744
  const strands = [];
13607
- const syncUnits = await this.getListenerSyncUnits(driveId, listenerId);
13608
- const limit = options?.limit;
13609
- let operationsCount = 0;
13610
- const tasks = syncUnits.map((syncUnit) => async () => {
13611
- if (limit && operationsCount >= limit) {
13612
- return;
13613
- }
13614
- if (syncUnit.revision < 0) {
13615
- return;
13616
- }
13617
- const entry = listenerState.syncUnits.get(syncUnit.syncId);
13618
- if (entry && entry.listenerRev >= syncUnit.revision) {
13619
- return;
13620
- }
13621
- const { documentId, scope, branch } = syncUnit;
13622
- try {
13623
- const operations = await this.syncManager.getOperationData(
13624
- // DEAL WITH INVALID SYNC ID ERROR
13625
- driveId,
13626
- syncUnit.syncId,
13627
- {
13628
- since: options?.since,
13629
- fromRevision: options?.fromRevision ?? entry?.listenerRev,
13630
- limit: limit ? limit - operationsCount : void 0
13745
+ try {
13746
+ const syncUnits = await this.getListenerSyncUnits(driveId, listenerId);
13747
+ this.logger.verbose(`[SYNC DEBUG] Retrieved ${syncUnits.length} sync units for drive: ${driveId}, listener: ${listenerId}`);
13748
+ const limit = options?.limit;
13749
+ let operationsCount = 0;
13750
+ const tasks = syncUnits.map((syncUnit) => async () => {
13751
+ if (limit && operationsCount >= limit) {
13752
+ return;
13753
+ }
13754
+ if (syncUnit.revision < 0) {
13755
+ this.logger.verbose(`[SYNC DEBUG] Skipping sync unit with negative revision: ${syncUnit.syncId}, revision: ${syncUnit.revision}`);
13756
+ return;
13757
+ }
13758
+ const entry = listenerState.syncUnits.get(syncUnit.syncId);
13759
+ if (entry && entry.listenerRev >= syncUnit.revision) {
13760
+ this.logger.verbose(`[SYNC DEBUG] Skipping sync unit - listener already up to date: ${syncUnit.syncId}, listenerRev: ${entry.listenerRev}, revision: ${syncUnit.revision}`);
13761
+ return;
13762
+ }
13763
+ const { documentId, scope, branch } = syncUnit;
13764
+ try {
13765
+ this.logger.verbose(`[SYNC DEBUG] Getting operations for syncUnit: ${syncUnit.syncId}, documentId: ${documentId}, scope: ${scope}, branch: ${branch}`);
13766
+ const operations = await this.syncManager.getOperationData(
13767
+ // DEAL WITH INVALID SYNC ID ERROR
13768
+ driveId,
13769
+ syncUnit.syncId,
13770
+ {
13771
+ since: options?.since,
13772
+ fromRevision: options?.fromRevision ?? entry?.listenerRev,
13773
+ limit: limit ? limit - operationsCount : void 0
13774
+ }
13775
+ );
13776
+ this.logger.verbose(`[SYNC DEBUG] Retrieved ${operations.length} operations for syncUnit: ${syncUnit.syncId}`);
13777
+ if (!operations.length) {
13778
+ return;
13631
13779
  }
13632
- );
13633
- if (!operations.length) {
13780
+ operationsCount += operations.length;
13781
+ strands.push({
13782
+ driveId,
13783
+ documentId,
13784
+ scope,
13785
+ branch,
13786
+ operations
13787
+ });
13788
+ this.logger.verbose(`[SYNC DEBUG] Added strand with ${operations.length} operations for syncUnit: ${syncUnit.syncId}`);
13789
+ } catch (error) {
13790
+ this.logger.error(`Error getting operations for syncUnit: ${syncUnit.syncId}, error: ${error}`);
13634
13791
  return;
13635
13792
  }
13636
- operationsCount += operations.length;
13637
- strands.push({
13638
- driveId,
13639
- documentId,
13640
- scope,
13641
- branch,
13642
- operations
13643
- });
13644
- } catch (error) {
13645
- this.logger.error(error);
13646
- return;
13647
- }
13648
- });
13649
- if (this.options.sequentialUpdates) {
13650
- for (const task of tasks) {
13651
- await task();
13793
+ });
13794
+ if (this.options.sequentialUpdates) {
13795
+ this.logger.verbose(`[SYNC DEBUG] Processing ${tasks.length} sync units sequentially`);
13796
+ for (const task of tasks) {
13797
+ await task();
13798
+ }
13799
+ } else {
13800
+ this.logger.verbose(`[SYNC DEBUG] Processing ${tasks.length} sync units in parallel`);
13801
+ await Promise.all(tasks.map((task) => task()));
13652
13802
  }
13653
- } else {
13654
- await Promise.all(tasks.map((task) => task()));
13803
+ } catch (error) {
13804
+ this.logger.error(`Error in getStrands: ${error}`);
13655
13805
  }
13806
+ this.logger.verbose(`ListenerManager.getStrands returning ${strands.length} strands for drive: ${driveId}, listener: ${listenerId}`);
13656
13807
  return strands;
13657
13808
  }
13658
13809
  getListenerState(driveId, listenerId) {
@@ -13717,23 +13868,33 @@ var SynchronizationManager = class {
13717
13868
  }
13718
13869
  async getSynchronizationUnits(driveId, documentId, scope, branch, documentType2) {
13719
13870
  const synchronizationUnitsQuery = await this.getSynchronizationUnitsIds(driveId, documentId, scope, branch, documentType2);
13871
+ this.logger.verbose(`getSynchronizationUnits query: ${JSON.stringify(synchronizationUnitsQuery)}`);
13720
13872
  return this.getSynchronizationUnitsRevision(driveId, synchronizationUnitsQuery);
13721
13873
  }
13722
13874
  async getSynchronizationUnitsRevision(driveId, syncUnitsQuery) {
13723
13875
  const drive = await this.getDrive(driveId);
13724
13876
  const revisions = await this.storage.getSynchronizationUnitsRevision(syncUnitsQuery);
13725
- return syncUnitsQuery.map((s) => ({
13877
+ this.logger.verbose(`getSynchronizationUnitsRevision: ${JSON.stringify(revisions)}`);
13878
+ const synchronizationUnits = syncUnitsQuery.map((s) => ({
13726
13879
  ...s,
13727
13880
  lastUpdated: drive.created,
13728
- revision: revisions.find((r) => r.documentId === s.documentId && r.scope === s.scope && r.branch === s.branch)?.revision ?? -1
13881
+ revision: -1
13729
13882
  }));
13883
+ for (const revision of revisions) {
13884
+ const syncUnit = synchronizationUnits.find((s) => revision.documentId === s.documentId && revision.scope === s.scope && revision.branch === s.branch);
13885
+ if (syncUnit) {
13886
+ syncUnit.revision = revision.revision;
13887
+ syncUnit.lastUpdated = revision.lastUpdated;
13888
+ }
13889
+ }
13890
+ return synchronizationUnits;
13730
13891
  }
13731
13892
  async getSynchronizationUnitsIds(driveId, documentId, scope, branch, documentType2) {
13732
13893
  const drive = await this.getDrive(driveId);
13733
13894
  const nodes = drive.state.global.nodes.filter((node) => isFileNode(node) && (!documentId?.length || documentId.includes(node.id) || documentId.includes("*")) && (!documentType2?.length || documentType2.includes(node.documentType) || documentType2.includes("*")));
13734
13895
  if ((!documentId || documentId.includes("*") || documentId.includes("")) && (!documentType2?.length || documentType2.includes("powerhouse/document-drive") || documentType2.includes("*"))) {
13735
13896
  nodes.unshift({
13736
- id: drive.state.global.id,
13897
+ id: driveId,
13737
13898
  documentType: "powerhouse/document-drive",
13738
13899
  synchronizationUnits: [
13739
13900
  {
@@ -13799,14 +13960,27 @@ var SynchronizationManager = class {
13799
13960
  };
13800
13961
  }
13801
13962
  async getOperationData(driveId, syncId, filter) {
13963
+ this.logger.verbose(`[SYNC DEBUG] SynchronizationManager.getOperationData called for drive: ${driveId}, syncId: ${syncId}, filter: ${JSON.stringify(filter)}`);
13802
13964
  const syncUnit = syncId === "0" ? { documentId: "", scope: "global" } : await this.getSynchronizationUnitIdInfo(driveId, syncId);
13803
13965
  if (!syncUnit) {
13966
+ this.logger.error(`SYNC DEBUG] Invalid Sync Id ${syncId} in drive ${driveId}`);
13804
13967
  throw new Error(`Invalid Sync Id ${syncId} in drive ${driveId}`);
13805
13968
  }
13969
+ this.logger.verbose(`[SYNC DEBUG] Found sync unit: documentId: ${syncUnit.documentId}, scope: ${syncUnit.scope}`);
13806
13970
  const document = syncId === "0" ? await this.getDrive(driveId) : await this.getDocument(driveId, syncUnit.documentId);
13971
+ this.logger.verbose(`[SYNC DEBUG] Retrieved document ${syncUnit.documentId} with type: ${document.documentType}`);
13807
13972
  const operations = document.operations[syncUnit.scope] ?? [];
13973
+ this.logger.verbose(`[SYNC DEBUG] Found ${operations.length} total operations in scope ${syncUnit.scope}`);
13808
13974
  const filteredOperations = operations.filter((operation) => Object.keys(filter).length === 0 || (filter.since === void 0 || isBefore(filter.since, operation.timestamp)) && (filter.fromRevision === void 0 || operation.index > filter.fromRevision));
13975
+ this.logger.verbose(`[SYNC DEBUG] Filtered to ${filteredOperations.length} operations based on filter criteria` + (filter.fromRevision !== void 0 ? ` (fromRevision: ${filter.fromRevision})` : ""));
13809
13976
  const limitedOperations = filter.limit ? filteredOperations.slice(0, filter.limit) : filteredOperations;
13977
+ this.logger.verbose(`[SYNC DEBUG] Returning ${limitedOperations.length} operations after applying limit`);
13978
+ if (limitedOperations.length > 0) {
13979
+ const firstOp = limitedOperations[0];
13980
+ const lastOp = limitedOperations[limitedOperations.length - 1];
13981
+ this.logger.verbose(`[SYNC DEBUG] First operation: index=${firstOp.index}, type=${firstOp.type}`);
13982
+ this.logger.verbose(`[SYNC DEBUG] Last operation: index=${lastOp.index}, type=${lastOp.type}`);
13983
+ }
13810
13984
  return limitedOperations.map((operation) => ({
13811
13985
  hash: operation.hash,
13812
13986
  index: operation.index,