@loro-dev/flock 1.0.0 → 1.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
@@ -470,9 +470,8 @@ function normalizeImportDecision(
470
470
  return { accept: true };
471
471
  }
472
472
  if ("accept" in decision) {
473
- const typed = decision as ImportAccept | ImportSkip;
474
- if (typed.accept === false) {
475
- return { accept: false, reason: typed.reason ?? "rejected" };
473
+ if (!decision.accept) {
474
+ return { accept: false, reason: decision.reason ?? "rejected" };
476
475
  }
477
476
  return { accept: true };
478
477
  }
@@ -572,15 +571,25 @@ export class Flock {
572
571
  this.putWithMetaInternal(key, value, options.metadata, options.now);
573
572
  return;
574
573
  }
575
- await transform(
574
+ const workingPayload = clonePayload(basePayload);
575
+ const transformed = await transform(
576
576
  { key: key.slice(), now: options.now },
577
- clonePayload(basePayload),
577
+ workingPayload,
578
578
  );
579
- const finalValue = basePayload.data;
579
+ const finalPayload = mergePayload(
580
+ basePayload,
581
+ transformed ?? workingPayload,
582
+ );
583
+ const finalValue = finalPayload.data;
580
584
  if (finalValue === undefined) {
581
585
  throw new TypeError("putWithMeta requires a data value");
582
586
  }
583
- this.putWithMetaInternal(key, finalValue, basePayload.metadata, options.now);
587
+ this.putWithMetaInternal(
588
+ key,
589
+ finalValue,
590
+ finalPayload.metadata,
591
+ options.now,
592
+ );
584
593
  }
585
594
 
586
595
  put(key: KeyPart[], value: Value, now?: number): void {
@@ -629,8 +638,12 @@ export class Flock {
629
638
  for (const [key, record] of Object.entries(base)) {
630
639
  const context = buildContext(key, record);
631
640
  const basePayload = createExportPayload(record);
632
- const transformed = await transform(context, clonePayload(basePayload));
633
- const finalPayload = mergePayload(basePayload, transformed);
641
+ const workingPayload = clonePayload(basePayload);
642
+ const transformed = await transform(context, workingPayload);
643
+ const finalPayload = mergePayload(
644
+ basePayload,
645
+ transformed ?? workingPayload,
646
+ );
634
647
  result[key] = buildRecord(record.c, finalPayload);
635
648
  }
636
649
  return result;