@loro-dev/flock 3.0.0 → 3.1.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.
package/src/index.ts CHANGED
@@ -39,6 +39,7 @@ type ExportOptions = {
39
39
  from?: VersionVector;
40
40
  hooks?: ExportHooks;
41
41
  pruneTombstonesBefore?: number;
42
+ peerId?: string;
42
43
  };
43
44
 
44
45
  type ImportOptions = {
@@ -513,7 +514,8 @@ function isExportOptions(value: unknown): value is ExportOptions {
513
514
  Object.prototype.hasOwnProperty.call(
514
515
  value,
515
516
  "pruneTombstonesBefore",
516
- ))
517
+ ) ||
518
+ Object.prototype.hasOwnProperty.call(value, "peerId"))
517
519
  );
518
520
  }
519
521
 
@@ -643,12 +645,15 @@ export class Flock {
643
645
  private exportJsonInternal(
644
646
  from?: VersionVector,
645
647
  pruneTombstonesBefore?: number,
648
+ peerId?: string,
646
649
  ): ExportBundle {
647
650
  const pruneBefore = normalizePruneBefore(pruneTombstonesBefore);
651
+ const normalizedPeerId = peerId !== undefined && isValidPeerId(peerId) ? peerId : undefined;
648
652
  return export_json_ffi(
649
653
  this.inner,
650
654
  encodeVersionVector(from),
651
655
  pruneBefore,
656
+ normalizedPeerId,
652
657
  ) as ExportBundle;
653
658
  }
654
659
 
@@ -656,6 +661,7 @@ export class Flock {
656
661
  const base = this.exportJsonInternal(
657
662
  options.from,
658
663
  options.pruneTombstonesBefore,
664
+ options.peerId,
659
665
  );
660
666
  const transform = options.hooks?.transform;
661
667
  if (!transform) {