@powerhousedao/ph-cli 6.0.0-dev.96 → 6.0.0-dev.97

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/src/cli.js CHANGED
@@ -2273,7 +2273,7 @@ var require_ms = __commonJS((exports, module2) => {
2273
2273
  }
2274
2274
  });
2275
2275
 
2276
- // ../../node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/common.js
2276
+ // ../../node_modules/.pnpm/debug@4.4.3_supports-color@5.5.0/node_modules/debug/src/common.js
2277
2277
  var require_common = __commonJS((exports, module2) => {
2278
2278
  function setup(env2) {
2279
2279
  createDebug.debug = createDebug;
@@ -2448,7 +2448,7 @@ var require_common = __commonJS((exports, module2) => {
2448
2448
  module2.exports = setup;
2449
2449
  });
2450
2450
 
2451
- // ../../node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/browser.js
2451
+ // ../../node_modules/.pnpm/debug@4.4.3_supports-color@5.5.0/node_modules/debug/src/browser.js
2452
2452
  var require_browser = __commonJS((exports, module2) => {
2453
2453
  exports.formatArgs = formatArgs;
2454
2454
  exports.save = save;
@@ -2608,38 +2608,30 @@ var require_browser = __commonJS((exports, module2) => {
2608
2608
  };
2609
2609
  });
2610
2610
 
2611
- // ../../node_modules/.pnpm/has-flag@4.0.0/node_modules/has-flag/index.js
2611
+ // ../../node_modules/.pnpm/has-flag@3.0.0/node_modules/has-flag/index.js
2612
2612
  var require_has_flag = __commonJS((exports, module2) => {
2613
- module2.exports = (flag, argv = process.argv) => {
2613
+ module2.exports = (flag, argv) => {
2614
+ argv = argv || process.argv;
2614
2615
  const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
2615
- const position = argv.indexOf(prefix + flag);
2616
- const terminatorPosition = argv.indexOf("--");
2617
- return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
2616
+ const pos = argv.indexOf(prefix + flag);
2617
+ const terminatorPos = argv.indexOf("--");
2618
+ return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
2618
2619
  };
2619
2620
  });
2620
2621
 
2621
- // ../../node_modules/.pnpm/supports-color@8.1.1/node_modules/supports-color/index.js
2622
+ // ../../node_modules/.pnpm/supports-color@5.5.0/node_modules/supports-color/index.js
2622
2623
  var require_supports_color = __commonJS((exports, module2) => {
2623
2624
  var os2 = __require("os");
2624
- var tty2 = __require("tty");
2625
2625
  var hasFlag2 = require_has_flag();
2626
- var { env: env2 } = process;
2627
- var flagForceColor2;
2628
- if (hasFlag2("no-color") || hasFlag2("no-colors") || hasFlag2("color=false") || hasFlag2("color=never")) {
2629
- flagForceColor2 = 0;
2626
+ var env2 = process.env;
2627
+ var forceColor;
2628
+ if (hasFlag2("no-color") || hasFlag2("no-colors") || hasFlag2("color=false")) {
2629
+ forceColor = false;
2630
2630
  } else if (hasFlag2("color") || hasFlag2("colors") || hasFlag2("color=true") || hasFlag2("color=always")) {
2631
- flagForceColor2 = 1;
2631
+ forceColor = true;
2632
2632
  }
2633
- function envForceColor2() {
2634
- if ("FORCE_COLOR" in env2) {
2635
- if (env2.FORCE_COLOR === "true") {
2636
- return 1;
2637
- }
2638
- if (env2.FORCE_COLOR === "false") {
2639
- return 0;
2640
- }
2641
- return env2.FORCE_COLOR.length === 0 ? 1 : Math.min(Number.parseInt(env2.FORCE_COLOR, 10), 3);
2642
- }
2633
+ if ("FORCE_COLOR" in env2) {
2634
+ forceColor = env2.FORCE_COLOR.length === 0 || parseInt(env2.FORCE_COLOR, 10) !== 0;
2643
2635
  }
2644
2636
  function translateLevel2(level) {
2645
2637
  if (level === 0) {
@@ -2652,39 +2644,29 @@ var require_supports_color = __commonJS((exports, module2) => {
2652
2644
  has16m: level >= 3
2653
2645
  };
2654
2646
  }
2655
- function supportsColor2(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
2656
- const noFlagForceColor = envForceColor2();
2657
- if (noFlagForceColor !== undefined) {
2658
- flagForceColor2 = noFlagForceColor;
2659
- }
2660
- const forceColor = sniffFlags ? flagForceColor2 : noFlagForceColor;
2661
- if (forceColor === 0) {
2647
+ function supportsColor2(stream) {
2648
+ if (forceColor === false) {
2662
2649
  return 0;
2663
2650
  }
2664
- if (sniffFlags) {
2665
- if (hasFlag2("color=16m") || hasFlag2("color=full") || hasFlag2("color=truecolor")) {
2666
- return 3;
2667
- }
2668
- if (hasFlag2("color=256")) {
2669
- return 2;
2670
- }
2651
+ if (hasFlag2("color=16m") || hasFlag2("color=full") || hasFlag2("color=truecolor")) {
2652
+ return 3;
2671
2653
  }
2672
- if (haveStream && !streamIsTTY && forceColor === undefined) {
2673
- return 0;
2654
+ if (hasFlag2("color=256")) {
2655
+ return 2;
2674
2656
  }
2675
- const min = forceColor || 0;
2676
- if (env2.TERM === "dumb") {
2677
- return min;
2657
+ if (stream && !stream.isTTY && forceColor !== true) {
2658
+ return 0;
2678
2659
  }
2660
+ const min = forceColor ? 1 : 0;
2679
2661
  if (process.platform === "win32") {
2680
2662
  const osRelease = os2.release().split(".");
2681
- if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
2663
+ if (Number(process.versions.node.split(".")[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
2682
2664
  return Number(osRelease[2]) >= 14931 ? 3 : 2;
2683
2665
  }
2684
2666
  return 1;
2685
2667
  }
2686
2668
  if ("CI" in env2) {
2687
- if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI", "GITHUB_ACTIONS", "BUILDKITE", "DRONE"].some((sign) => (sign in env2)) || env2.CI_NAME === "codeship") {
2669
+ if (["TRAVIS", "CIRCLECI", "APPVEYOR", "GITLAB_CI"].some((sign) => (sign in env2)) || env2.CI_NAME === "codeship") {
2688
2670
  return 1;
2689
2671
  }
2690
2672
  return min;
@@ -2696,7 +2678,7 @@ var require_supports_color = __commonJS((exports, module2) => {
2696
2678
  return 3;
2697
2679
  }
2698
2680
  if ("TERM_PROGRAM" in env2) {
2699
- const version = Number.parseInt((env2.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
2681
+ const version = parseInt((env2.TERM_PROGRAM_VERSION || "").split(".")[0], 10);
2700
2682
  switch (env2.TERM_PROGRAM) {
2701
2683
  case "iTerm.app":
2702
2684
  return version >= 3 ? 3 : 2;
@@ -2713,23 +2695,23 @@ var require_supports_color = __commonJS((exports, module2) => {
2713
2695
  if ("COLORTERM" in env2) {
2714
2696
  return 1;
2715
2697
  }
2698
+ if (env2.TERM === "dumb") {
2699
+ return min;
2700
+ }
2716
2701
  return min;
2717
2702
  }
2718
- function getSupportLevel(stream, options = {}) {
2719
- const level = supportsColor2(stream, {
2720
- streamIsTTY: stream && stream.isTTY,
2721
- ...options
2722
- });
2703
+ function getSupportLevel(stream) {
2704
+ const level = supportsColor2(stream);
2723
2705
  return translateLevel2(level);
2724
2706
  }
2725
2707
  module2.exports = {
2726
2708
  supportsColor: getSupportLevel,
2727
- stdout: getSupportLevel({ isTTY: tty2.isatty(1) }),
2728
- stderr: getSupportLevel({ isTTY: tty2.isatty(2) })
2709
+ stdout: getSupportLevel(process.stdout),
2710
+ stderr: getSupportLevel(process.stderr)
2729
2711
  };
2730
2712
  });
2731
2713
 
2732
- // ../../node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/node.js
2714
+ // ../../node_modules/.pnpm/debug@4.4.3_supports-color@5.5.0/node_modules/debug/src/node.js
2733
2715
  var require_node = __commonJS((exports, module2) => {
2734
2716
  var tty2 = __require("tty");
2735
2717
  var util = __require("util");
@@ -2900,7 +2882,7 @@ var require_node = __commonJS((exports, module2) => {
2900
2882
  };
2901
2883
  });
2902
2884
 
2903
- // ../../node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/index.js
2885
+ // ../../node_modules/.pnpm/debug@4.4.3_supports-color@5.5.0/node_modules/debug/src/index.js
2904
2886
  var require_src = __commonJS((exports, module2) => {
2905
2887
  if (typeof process === "undefined" || process.type === "renderer" || false || process.__nwjs) {
2906
2888
  module2.exports = require_browser();
@@ -4402,7 +4384,7 @@ var init_common = __esm(() => {
4402
4384
  type: import_cmd_ts.string,
4403
4385
  description: "Base path for the app",
4404
4386
  env: "PH_CONNECT_BASE_PATH",
4405
- defaultValue: () => ""
4387
+ defaultValue: () => "/"
4406
4388
  });
4407
4389
  drivesPreserveStrategy = import_cmd_ts.option({
4408
4390
  type: import_cmd_ts.oneOf(DRIVES_PRESERVE_STRATEGIES),
@@ -331794,13 +331776,15 @@ class SimpleJobExecutorManager {
331794
331776
  totalJobsProcessed = 0;
331795
331777
  unsubscribe;
331796
331778
  deferredJobs = new Map;
331797
- constructor(executorFactory, eventBus, queue, jobTracker, logger3, resolver) {
331779
+ jobTimeoutMs;
331780
+ constructor(executorFactory, eventBus, queue, jobTracker, logger3, resolver, jobTimeoutMs = 30000) {
331798
331781
  this.executorFactory = executorFactory;
331799
331782
  this.eventBus = eventBus;
331800
331783
  this.queue = queue;
331801
331784
  this.jobTracker = jobTracker;
331802
331785
  this.logger = logger3;
331803
331786
  this.resolver = resolver;
331787
+ this.jobTimeoutMs = jobTimeoutMs;
331804
331788
  }
331805
331789
  async start(numExecutors) {
331806
331790
  if (this.isRunning) {
@@ -331881,9 +331865,23 @@ class SimpleJobExecutorManager {
331881
331865
  this.eventBus.emit(ReactorEventTypes.JOB_RUNNING, runningEvent).catch(() => {});
331882
331866
  const executorIndex = this.totalJobsProcessed % this.executors.length;
331883
331867
  const executor = this.executors[executorIndex];
331868
+ const signal = AbortSignal.timeout(this.jobTimeoutMs);
331869
+ const toError = (reason) => reason instanceof Error ? reason : new Error(String(reason));
331870
+ const abortPromise = new Promise((_3, reject) => {
331871
+ if (signal.aborted) {
331872
+ reject(toError(signal.reason));
331873
+ return;
331874
+ }
331875
+ signal.addEventListener("abort", () => reject(toError(signal.reason)), {
331876
+ once: true
331877
+ });
331878
+ });
331884
331879
  let result;
331885
331880
  try {
331886
- result = await executor.executeJob(handle2.job);
331881
+ result = await Promise.race([
331882
+ executor.executeJob(handle2.job, signal),
331883
+ abortPromise
331884
+ ]);
331887
331885
  } catch (error48) {
331888
331886
  const errorInfo = this.toErrorInfo(error48 instanceof Error ? error48 : String(error48));
331889
331887
  handle2.fail(errorInfo);
@@ -333249,6 +333247,9 @@ class Mailbox {
333249
333247
  init(ackOrdinal) {
333250
333248
  this._ack = this._latestOrdinal = ackOrdinal;
333251
333249
  }
333250
+ advanceOrdinal(ordinal) {
333251
+ this._latestOrdinal = Math.max(this._latestOrdinal, ordinal);
333252
+ }
333252
333253
  get items() {
333253
333254
  return Array.from(this.itemsMap.values());
333254
333255
  }
@@ -333383,6 +333384,9 @@ class BufferedMailbox {
333383
333384
  init(ackOrdinal) {
333384
333385
  this._ack = this._latestOrdinal = ackOrdinal;
333385
333386
  }
333387
+ advanceOrdinal(ordinal) {
333388
+ this._latestOrdinal = Math.max(this._latestOrdinal, ordinal);
333389
+ }
333386
333390
  get items() {
333387
333391
  return Array.from(this.itemsMap.values());
333388
333392
  }
@@ -333897,6 +333901,8 @@ class GqlRequestChannel {
333897
333901
  pushFailureCount = 0;
333898
333902
  pushRetryTimer = null;
333899
333903
  pushBlocked = false;
333904
+ isPushing = false;
333905
+ pendingDrain = false;
333900
333906
  connectionState = "connecting";
333901
333907
  connectionStateCallbacks = new Set;
333902
333908
  constructor(logger3, channelId, remoteName, cursorStorage, config2, operationIndex, pollTimer) {
@@ -333921,20 +333927,19 @@ class GqlRequestChannel {
333921
333927
  this.bufferedOutbox = new BufferedMailbox(500, 25);
333922
333928
  this.outbox = this.bufferedOutbox;
333923
333929
  this.deadLetter = new Mailbox;
333924
- this.deadLetter.onAdded(() => {
333925
- this.pollTimer.stop();
333926
- if (this.pushRetryTimer) {
333927
- clearTimeout(this.pushRetryTimer);
333928
- this.pushRetryTimer = null;
333930
+ this.deadLetter.onAdded((syncOps) => {
333931
+ for (const syncOp of syncOps) {
333932
+ this.logger.warn("Dead letter added for document @DocumentId on channel @ChannelId", syncOp.documentId, this.channelId);
333929
333933
  }
333930
- this.transitionConnectionState("error");
333931
333934
  });
333932
333935
  this.outbox.onAdded((syncOps) => {
333933
333936
  if (this.isShutdown)
333934
333937
  return;
333935
- if (this.pushBlocked)
333938
+ if (this.isPushing) {
333939
+ this.pendingDrain = true;
333936
333940
  return;
333937
- if (this.deadLetter.items.length > 0)
333941
+ }
333942
+ if (this.pushBlocked)
333938
333943
  return;
333939
333944
  this.attemptPush(syncOps);
333940
333945
  });
@@ -334250,13 +334255,18 @@ class GqlRequestChannel {
334250
334255
  return { ackOrdinal: data.touchChannel.ackOrdinal };
334251
334256
  }
334252
334257
  attemptPush(syncOps) {
334258
+ this.isPushing = true;
334253
334259
  this.pushSyncOperations(syncOps).then(() => {
334260
+ this.isPushing = false;
334254
334261
  this.pushBlocked = false;
334255
334262
  this.pushFailureCount = 0;
334256
334263
  if (this.connectionState === "reconnecting" || this.connectionState === "error") {
334257
334264
  this.transitionConnectionState("connected");
334258
334265
  }
334266
+ this.drainOutbox();
334259
334267
  }).catch((error48) => {
334268
+ this.isPushing = false;
334269
+ this.pendingDrain = false;
334260
334270
  if (this.isShutdown)
334261
334271
  return;
334262
334272
  const err2 = error48 instanceof Error ? error48 : new Error(String(error48));
@@ -334295,6 +334305,17 @@ class GqlRequestChannel {
334295
334305
  this.attemptPush([...allItems]);
334296
334306
  }, delay);
334297
334307
  }
334308
+ drainOutbox() {
334309
+ if (!this.pendingDrain)
334310
+ return;
334311
+ this.pendingDrain = false;
334312
+ if (this.isShutdown)
334313
+ return;
334314
+ const items = this.outbox.items;
334315
+ if (items.length === 0)
334316
+ return;
334317
+ this.attemptPush([...items]);
334318
+ }
334298
334319
  classifyError(error48) {
334299
334320
  if (!(error48 instanceof GraphQLRequestError)) {
334300
334321
  return "recoverable";
@@ -334970,7 +334991,7 @@ class SyncManager {
334970
334991
  syncStatusTracker;
334971
334992
  maxDeadLettersPerRemote;
334972
334993
  connectionStateUnsubscribes = new Map;
334973
- loadJobs = new Map;
334994
+ quarantinedDocumentIds = new Set;
334974
334995
  constructor(logger3, remoteStorage, cursorStorage, deadLetterStorage, channelFactory, operationIndex, reactor, eventBus, maxDeadLettersPerRemote = 100) {
334975
334996
  this.logger = logger3;
334976
334997
  this.remoteStorage = remoteStorage;
@@ -334992,6 +335013,14 @@ class SyncManager {
334992
335013
  if (this.isShutdown) {
334993
335014
  throw new Error("SyncManager is already shutdown and cannot be started");
334994
335015
  }
335016
+ try {
335017
+ const quarantinedIds = await this.deadLetterStorage.listQuarantinedDocumentIds();
335018
+ for (const id of quarantinedIds) {
335019
+ this.quarantinedDocumentIds.add(id);
335020
+ }
335021
+ } catch (error48) {
335022
+ this.logger.error("Failed to load quarantined document IDs (@error)", error48 instanceof Error ? error48.message : String(error48));
335023
+ }
334995
335024
  const remoteRecords = await this.remoteStorage.list();
334996
335025
  for (const record2 of remoteRecords) {
334997
335026
  const channel = this.channelFactory.instance(record2.id, record2.name, record2.channelConfig, this.cursorStorage, record2.collectionId, record2.filter, this.operationIndex);
@@ -335156,6 +335185,7 @@ class SyncManager {
335156
335185
  remote.channel.deadLetter.onAdded((syncOps) => {
335157
335186
  for (const syncOp of syncOps) {
335158
335187
  this.logger.error("Dead letter (@remote, @documentId, @jobId, @error, @dependencies)", remote.name, syncOp.documentId, syncOp.jobId, syncOp.error?.message ?? "unknown", syncOp.jobDependencies);
335188
+ this.quarantinedDocumentIds.add(syncOp.documentId);
335159
335189
  const record2 = {
335160
335190
  id: syncOp.id,
335161
335191
  jobId: syncOp.jobId,
@@ -335241,9 +335271,12 @@ class SyncManager {
335241
335271
  if (this.isShutdown) {
335242
335272
  return;
335243
335273
  }
335274
+ const eligible = syncOps.filter((op) => !this.quarantinedDocumentIds.has(op.documentId));
335275
+ if (eligible.length === 0)
335276
+ return;
335244
335277
  const keyed = [];
335245
335278
  const nonKeyed = [];
335246
- for (const syncOp of syncOps) {
335279
+ for (const syncOp of eligible) {
335247
335280
  if (syncOp.jobId) {
335248
335281
  keyed.push(syncOp);
335249
335282
  } else {
@@ -335287,8 +335320,8 @@ class SyncManager {
335287
335320
  remote.channel.inbox.remove(syncOp);
335288
335321
  return;
335289
335322
  }
335290
- const jobKey = `${syncOp.documentId}:${syncOp.branch}`;
335291
- this.loadJobs.set(jobKey, completedJobInfo);
335323
+ if (this.isShutdown)
335324
+ return;
335292
335325
  if (completedJobInfo.status === "FAILED") {
335293
335326
  const errorMessage = completedJobInfo.error?.message || "Unknown error";
335294
335327
  this.logger.error("Failed to apply operations from inbox (@remote, @documentId, @jobId, @error)", remote.name, syncOp.documentId, completedJobInfo.id, errorMessage);
@@ -335325,6 +335358,8 @@ class SyncManager {
335325
335358
  }
335326
335359
  return;
335327
335360
  }
335361
+ if (this.isShutdown)
335362
+ return;
335328
335363
  for (const { remote, syncOp } of items) {
335329
335364
  if (!(syncOp.jobId in result.jobs)) {
335330
335365
  this.logger.error("Job key missing from batch load result (@remote, @documentId, @jobId)", remote.name, syncOp.documentId, syncOp.jobId);
@@ -335347,8 +335382,8 @@ class SyncManager {
335347
335382
  remote.channel.inbox.remove(syncOp);
335348
335383
  continue;
335349
335384
  }
335350
- const jobKey = `${syncOp.documentId}:${syncOp.branch}`;
335351
- this.loadJobs.set(jobKey, completedJobInfo);
335385
+ if (this.isShutdown)
335386
+ return;
335352
335387
  if (completedJobInfo.status === "FAILED") {
335353
335388
  const errorMessage = completedJobInfo.error?.message || "Unknown error";
335354
335389
  const channelError = new ChannelError("inbox", new Error(`Failed to apply operations: ${errorMessage}`));
@@ -335361,39 +335396,48 @@ class SyncManager {
335361
335396
  }
335362
335397
  }
335363
335398
  async updateOutbox(remote, ackOrdinal) {
335364
- const operations2 = await this.getOperationsForRemote(remote, ackOrdinal);
335365
- if (operations2.length === 0) {
335366
- return;
335367
- }
335368
- operations2.sort((a2, b3) => {
335369
- if (a2.context.documentId !== b3.context.documentId) {
335370
- return a2.context.documentId < b3.context.documentId ? -1 : 1;
335371
- }
335372
- if (a2.context.scope !== b3.context.scope) {
335373
- return a2.context.scope < b3.context.scope ? -1 : 1;
335374
- }
335375
- return a2.context.ordinal - b3.context.ordinal;
335376
- });
335377
- const batches = batchOperationsByDocument(operations2);
335399
+ let maxOrdinal = ackOrdinal;
335378
335400
  const lastJobByDoc = new Map;
335379
- const syncOps = [];
335380
- for (const batch of batches) {
335381
- const jobId = crypto.randomUUID();
335382
- const prevJobId = lastJobByDoc.get(batch.documentId);
335383
- const syncOp = new SyncOperation(crypto.randomUUID(), jobId, prevJobId ? [prevJobId] : [], remote.name, batch.documentId, [batch.scope], batch.branch, batch.operations);
335384
- syncOps.push(syncOp);
335385
- lastJobByDoc.set(batch.documentId, jobId);
335386
- }
335387
- remote.channel.outbox.add(...syncOps);
335388
- }
335389
- async getOperationsForRemote(remote, ackOrdinal) {
335390
- const results = await this.operationIndex.find(remote.collectionId, ackOrdinal, { excludeSourceRemote: remote.name }, undefined, this.abortController.signal);
335391
- let operations2 = results.results.map((entry) => toOperationWithContext(entry));
335392
335401
  const sinceTimestamp = remote.options.sinceTimestampUtcMs;
335393
- if (sinceTimestamp && sinceTimestamp !== "0") {
335394
- operations2 = operations2.filter((op) => op.operation.timestampUtcMs >= sinceTimestamp);
335395
- }
335396
- return filterOperations(operations2, remote.filter);
335402
+ let page = await this.operationIndex.find(remote.collectionId, ackOrdinal, { excludeSourceRemote: remote.name }, undefined, this.abortController.signal);
335403
+ let hasMore;
335404
+ do {
335405
+ for (const entry of page.results) {
335406
+ maxOrdinal = Math.max(maxOrdinal, entry.ordinal ?? 0);
335407
+ }
335408
+ let operations2 = page.results.map((entry) => toOperationWithContext(entry));
335409
+ if (sinceTimestamp && sinceTimestamp !== "0") {
335410
+ operations2 = operations2.filter((op) => op.operation.timestampUtcMs >= sinceTimestamp);
335411
+ }
335412
+ operations2 = filterOperations(operations2, remote.filter);
335413
+ operations2 = operations2.filter((op) => !this.quarantinedDocumentIds.has(op.context.documentId));
335414
+ if (operations2.length > 0) {
335415
+ operations2.sort((a2, b3) => {
335416
+ if (a2.context.documentId !== b3.context.documentId) {
335417
+ return a2.context.documentId < b3.context.documentId ? -1 : 1;
335418
+ }
335419
+ if (a2.context.scope !== b3.context.scope) {
335420
+ return a2.context.scope < b3.context.scope ? -1 : 1;
335421
+ }
335422
+ return a2.context.ordinal - b3.context.ordinal;
335423
+ });
335424
+ const batches = batchOperationsByDocument(operations2);
335425
+ const syncOps = [];
335426
+ for (const batch of batches) {
335427
+ const jobId = crypto.randomUUID();
335428
+ const prevJobId = lastJobByDoc.get(batch.documentId);
335429
+ const syncOp = new SyncOperation(crypto.randomUUID(), jobId, prevJobId ? [prevJobId] : [], remote.name, batch.documentId, [batch.scope], batch.branch, batch.operations);
335430
+ syncOps.push(syncOp);
335431
+ lastJobByDoc.set(batch.documentId, jobId);
335432
+ }
335433
+ remote.channel.outbox.add(...syncOps);
335434
+ }
335435
+ hasMore = !!page.next;
335436
+ if (hasMore) {
335437
+ page = await page.next();
335438
+ }
335439
+ } while (hasMore);
335440
+ remote.channel.outbox.advanceOrdinal(maxOrdinal);
335397
335441
  }
335398
335442
  }
335399
335443
  var __defProp2, __returnValue2 = (v3) => v3, __export2 = (target, all) => {