@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/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/_moon_flock.ts +1237 -1014
- package/src/index.ts +22 -9
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
|
-
|
|
474
|
-
|
|
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
|
-
|
|
574
|
+
const workingPayload = clonePayload(basePayload);
|
|
575
|
+
const transformed = await transform(
|
|
576
576
|
{ key: key.slice(), now: options.now },
|
|
577
|
-
|
|
577
|
+
workingPayload,
|
|
578
578
|
);
|
|
579
|
-
const
|
|
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(
|
|
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
|
|
633
|
-
const
|
|
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;
|