@graview/core 0.2.15 → 0.2.16
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/README.md +8 -2
- package/dist/cli/document-schema.js +1 -1
- package/dist/cli/document-schema.js.map +1 -1
- package/dist/document/connection-findings.d.ts.map +1 -1
- package/dist/document/connection-findings.js +103 -10
- package/dist/document/connection-findings.js.map +1 -1
- package/dist/document/connection-spec.d.ts +43 -3
- package/dist/document/connection-spec.d.ts.map +1 -1
- package/dist/document/connection-spec.js +51 -4
- package/dist/document/connection-spec.js.map +1 -1
- package/dist/document/describe-place.d.ts.map +1 -1
- package/dist/document/describe-place.js +2 -0
- package/dist/document/describe-place.js.map +1 -1
- package/dist/document/described.d.ts +6 -0
- package/dist/document/described.d.ts.map +1 -1
- package/dist/document/edit.js +1 -1
- package/dist/document/edit.js.map +1 -1
- package/dist/document/kept-in-step-with.d.ts +4 -4
- package/dist/document/kept-in-step-with.d.ts.map +1 -1
- package/dist/document/kept-in-step-with.js +5 -1
- package/dist/document/kept-in-step-with.js.map +1 -1
- package/dist/document/kept-in-step.js +1 -1
- package/dist/document/kept-in-step.js.map +1 -1
- package/dist/document.schema.json +154 -3
- package/dist/sync/connection.d.ts +22 -5
- package/dist/sync/connection.d.ts.map +1 -1
- package/dist/sync/connection.js +274 -6
- package/dist/sync/connection.js.map +1 -1
- package/dist/sync/engine.d.ts +38 -1
- package/dist/sync/engine.d.ts.map +1 -1
- package/dist/sync/engine.js +184 -12
- package/dist/sync/engine.js.map +1 -1
- package/dist/sync/google-calendar.d.ts.map +1 -1
- package/dist/sync/google-calendar.js +27 -4
- package/dist/sync/google-calendar.js.map +1 -1
- package/dist/sync/guests.d.ts +7 -2
- package/dist/sync/guests.d.ts.map +1 -1
- package/dist/sync/guests.js +33 -15
- package/dist/sync/guests.js.map +1 -1
- package/dist/sync/index.d.ts +10 -3
- package/dist/sync/index.d.ts.map +1 -1
- package/dist/sync/index.js +6 -2
- package/dist/sync/index.js.map +1 -1
- package/dist/sync/notion.d.ts.map +1 -1
- package/dist/sync/notion.js +18 -10
- package/dist/sync/notion.js.map +1 -1
- package/dist/sync/todoist-due.d.ts +35 -0
- package/dist/sync/todoist-due.d.ts.map +1 -0
- package/dist/sync/todoist-due.js +132 -0
- package/dist/sync/todoist-due.js.map +1 -0
- package/dist/sync/todoist-stub.d.ts +85 -0
- package/dist/sync/todoist-stub.d.ts.map +1 -0
- package/dist/sync/todoist-stub.js +316 -0
- package/dist/sync/todoist-stub.js.map +1 -0
- package/dist/sync/todoist-types.d.ts +27 -0
- package/dist/sync/todoist-types.d.ts.map +1 -0
- package/dist/sync/todoist-types.js +46 -0
- package/dist/sync/todoist-types.js.map +1 -0
- package/dist/sync/todoist.d.ts +112 -0
- package/dist/sync/todoist.d.ts.map +1 -0
- package/dist/sync/todoist.js +892 -0
- package/dist/sync/todoist.js.map +1 -0
- package/dist/sync/types.d.ts +53 -2
- package/dist/sync/types.d.ts.map +1 -1
- package/dist/sync/types.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/sync/engine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/sync/engine.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAA0B,aAAa,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAGhF,OAAO,KAAK,EAAE,SAAS,EAAgB,MAAM,qBAAqB,CAAC;AACnE,OAAO,KAAK,EAAyB,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAIjF,OAAO,EAIL,KAAK,cAAc,EAEnB,KAAK,YAAY,EAGjB,KAAK,YAAY,EACjB,KAAK,WAAW,EAEhB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,SAAS,EAGf,MAAM,YAAY,CAAC;AAEpB,o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IAYlB,yDAAyD;IACzD,OAAO,CAAC,aAAa;IA6BrB;;;;;OAKG;IACH,OAAO,CAAC,IAAI;IAeZ;;;;;OAKG;IACH,OAAO,CAAC,OAAO;IAqBf;;;;;;;OAOG;IACH,OAAO,CAAC,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI;IA0C9D;;;;OAIG;IACH,KAAK,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI;IAoCnC;;;;;OAKG;IACH,KAAK,IAAI,MAAM,IAAI;IAsCnB,mGAAmG;IACnG,OAAO,CAAC,WAAW;IAInB,6GAA6G;IAC7G,OAAO,CAAC,YAAY;IAKpB;;;;OAIG;IACH,OAAO,CAAC,WAAW;IAUnB,oHAAoH;IACpH,OAAO,CAAC,KAAK;CAkBd"}
|
package/dist/sync/engine.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { computedValues } from "../document/computed-values.js";
|
|
2
|
+
import { isArchived } from "../graph/archived.js";
|
|
2
3
|
import { splicedRecord } from "../graph/primitives.js";
|
|
3
4
|
import { PermissionDeniedError } from "../permissions/types.js";
|
|
4
5
|
import { labelOf, nounOf, pluralOf } from "../schema/define-node.js";
|
|
@@ -52,6 +53,17 @@ function remoteFields(values, mapping, node = values) {
|
|
|
52
53
|
}
|
|
53
54
|
return out;
|
|
54
55
|
}
|
|
56
|
+
/** A value as a short hash. */
|
|
57
|
+
function shortHash(value) {
|
|
58
|
+
const text = JSON.stringify(value);
|
|
59
|
+
let one = 0x811c9dc5;
|
|
60
|
+
let two = 0x1000193;
|
|
61
|
+
for (let at = 0; at < text.length; at++) {
|
|
62
|
+
one = Math.imul(one ^ text.charCodeAt(at), 0x01000193) >>> 0;
|
|
63
|
+
two = Math.imul(two ^ text.charCodeAt(text.length - 1 - at), 0x01000193) >>> 0;
|
|
64
|
+
}
|
|
65
|
+
return one.toString(36) + two.toString(36);
|
|
66
|
+
}
|
|
55
67
|
const same = (a, b) => JSON.stringify(a ?? null) === JSON.stringify(b ?? null);
|
|
56
68
|
/** Where a conflict is held: by node and field, and a record deleted here by node alone. */
|
|
57
69
|
const heldKey = (localId, field = "") => `${localId}\u0000${field}`;
|
|
@@ -224,7 +236,7 @@ export class SyncEngine {
|
|
|
224
236
|
continue;
|
|
225
237
|
const call = this.options.disconnectInbound?.({ ...about, to });
|
|
226
238
|
if (call)
|
|
227
|
-
calls.push(call);
|
|
239
|
+
calls.push(...(Array.isArray(call) ? call : [call]));
|
|
228
240
|
}
|
|
229
241
|
for (const to of reach) {
|
|
230
242
|
if (now.includes(to))
|
|
@@ -326,6 +338,54 @@ export class SyncEngine {
|
|
|
326
338
|
}
|
|
327
339
|
return found;
|
|
328
340
|
}
|
|
341
|
+
/** What a record holds of its own, whatever is mapped. */
|
|
342
|
+
ownOf(node) {
|
|
343
|
+
const fields = {};
|
|
344
|
+
for (const [field, value] of Object.entries(node))
|
|
345
|
+
if (value !== undefined && value !== null && /^[a-z]/.test(field))
|
|
346
|
+
fields[field] = shortHash(value);
|
|
347
|
+
const links = {};
|
|
348
|
+
for (const edge of this.options.store.graph.outEdges(node["id"]))
|
|
349
|
+
(links[edge.kind] ??= []).push(edge.to);
|
|
350
|
+
return { fields, ...(Object.keys(links).length > 0 ? { links } : {}) };
|
|
351
|
+
}
|
|
352
|
+
/** The records here before the first pass, kept once as they stand: read before the pull, so what it makes is not among them. Their count, when this pass is the first. */
|
|
353
|
+
keepExisting() {
|
|
354
|
+
if (!this.options.holdExisting || this.options.holdExisting.send || this.state.existing || this.options.mapping.resources.every((resource) => resource.readonly))
|
|
355
|
+
return undefined;
|
|
356
|
+
const existing = {};
|
|
357
|
+
for (const node of this.options.store.graph.allNodes({ archived: "all" })) {
|
|
358
|
+
const id = node["id"];
|
|
359
|
+
const mapping = this.mappingFor(node["kind"]);
|
|
360
|
+
if (!mapping || mapping.kind !== node["kind"] || mapping.readonly || this.state.links[id] || (mapping.match && !mapping.match(node)))
|
|
361
|
+
continue;
|
|
362
|
+
existing[id] = this.ownOf(node);
|
|
363
|
+
}
|
|
364
|
+
this.state = { ...this.state, existing };
|
|
365
|
+
return Object.keys(existing).length;
|
|
366
|
+
}
|
|
367
|
+
/** Whether a record not linked was here before the first pass and has not changed since: each mapped field as it was, and no link it did not have. */
|
|
368
|
+
isExisting(node, mapping) {
|
|
369
|
+
const was = this.options.holdExisting && !this.options.holdExisting.send ? this.state.existing?.[node["id"]] : undefined;
|
|
370
|
+
if (!was)
|
|
371
|
+
return false;
|
|
372
|
+
const now = this.ownOf(node);
|
|
373
|
+
return (Object.keys(mapping.fields).every((field) => now.fields[field] === was.fields[field]) &&
|
|
374
|
+
Object.keys(mapping.edges ?? {}).every((edge) => (now.links?.[edge] ?? []).every((to) => was.links?.[edge]?.includes(to))));
|
|
375
|
+
}
|
|
376
|
+
/** Whether two values of ours say the same there. */
|
|
377
|
+
alike(mapping, field, one, other) {
|
|
378
|
+
const by = mapping.compare?.[field];
|
|
379
|
+
return same(one, other) || (by !== undefined && same(by(one), by(other)));
|
|
380
|
+
}
|
|
381
|
+
/** Whether a record is set aside here and its mapping keeps the remote's as it is. */
|
|
382
|
+
isAside(localId, mapping) {
|
|
383
|
+
return mapping?.aside === "keep" && isArchived(this.options.store.graph.getNode(localId));
|
|
384
|
+
}
|
|
385
|
+
/** Our ids of the records set aside that have nothing there, as the last pass left them. */
|
|
386
|
+
alone() {
|
|
387
|
+
return new Set(this.options.setAside ? (this.state.alone ?? []) : []);
|
|
388
|
+
}
|
|
329
389
|
/** A link for every participant whose mapping names its version field and that carries one. */
|
|
330
390
|
seededLinks() {
|
|
331
391
|
const links = {};
|
|
@@ -480,13 +540,17 @@ export class SyncEngine {
|
|
|
480
540
|
const seen = new Set();
|
|
481
541
|
const held = this.held();
|
|
482
542
|
const gone = new Set(this.state.gone ?? []);
|
|
543
|
+
const alone = this.alone();
|
|
483
544
|
for (const [localId, { node, mapping }] of this.participants()) {
|
|
484
545
|
seen.add(localId);
|
|
485
546
|
if (mapping.readonly || gone.has(localId))
|
|
486
547
|
continue;
|
|
487
|
-
|
|
548
|
+
// Brought back with nothing there: new, whatever it was linked to.
|
|
549
|
+
const link = alone.has(localId) ? undefined : this.state.links[localId];
|
|
488
550
|
const values = this.valuesOf(node, mapping);
|
|
489
551
|
if (!link) {
|
|
552
|
+
if (this.isExisting(node, mapping))
|
|
553
|
+
continue;
|
|
490
554
|
writes.push({
|
|
491
555
|
resource: mapping.resource,
|
|
492
556
|
localId,
|
|
@@ -495,7 +559,7 @@ export class SyncEngine {
|
|
|
495
559
|
continue;
|
|
496
560
|
}
|
|
497
561
|
const free = Object.fromEntries(Object.entries(values).filter(([field]) => !held.has(heldKey(localId, field))));
|
|
498
|
-
const changed = Object.keys(free).filter((field) => !
|
|
562
|
+
const changed = Object.keys(free).filter((field) => !this.alike(mapping, field, free[field], link.fields[field]));
|
|
499
563
|
if (changed.length === 0)
|
|
500
564
|
continue;
|
|
501
565
|
writes.push({
|
|
@@ -503,6 +567,7 @@ export class SyncEngine {
|
|
|
503
567
|
id: link.id,
|
|
504
568
|
localId,
|
|
505
569
|
fields: remoteFields(free, mapping, node),
|
|
570
|
+
changed: changed.map((field) => keptOf(mapping)[field]),
|
|
506
571
|
});
|
|
507
572
|
}
|
|
508
573
|
// Something we had linked and no longer have is a deletion, and saying so
|
|
@@ -510,7 +575,7 @@ export class SyncEngine {
|
|
|
510
575
|
// remote owns is not deleted there from here: `run` refuses it, once. A
|
|
511
576
|
// delete held against the remote's edit waits for `resolve`.
|
|
512
577
|
for (const [localId, link] of Object.entries(this.state.links)) {
|
|
513
|
-
if (seen.has(localId) || this.mappingFor(link.resource)?.readonly || held.has(heldKey(localId)))
|
|
578
|
+
if (seen.has(localId) || this.mappingFor(link.resource)?.readonly || held.has(heldKey(localId)) || alone.has(localId) || this.isAside(localId, this.mappingFor(link.resource)))
|
|
514
579
|
continue;
|
|
515
580
|
writes.push({ resource: link.resource, id: link.id, localId, deleted: true });
|
|
516
581
|
}
|
|
@@ -532,6 +597,15 @@ export class SyncEngine {
|
|
|
532
597
|
this.release();
|
|
533
598
|
const held = this.held();
|
|
534
599
|
const policy = this.policy;
|
|
600
|
+
const alone = this.alone();
|
|
601
|
+
const goneAside = [];
|
|
602
|
+
// Aside and linked as the last pass left them, and brought back since: what became of them there is asked.
|
|
603
|
+
const wasAside = new Set(this.options.setAside ? (this.state.aside ?? []) : []);
|
|
604
|
+
const back = new Set([...wasAside].filter((id) => !alone.has(id) && this.state.links[id] && this.options.store.graph.getNode(id) && !isArchived(this.options.store.graph.getNode(id))));
|
|
605
|
+
let pulled = false;
|
|
606
|
+
// No longer among those kept here with nothing sent (`gone`).
|
|
607
|
+
const returned = new Set();
|
|
608
|
+
const unsent = this.keepExisting();
|
|
535
609
|
let offline = false;
|
|
536
610
|
let problem;
|
|
537
611
|
let said;
|
|
@@ -564,7 +638,10 @@ export class SyncEngine {
|
|
|
564
638
|
}
|
|
565
639
|
// --------------------------------------------------------------- inbound
|
|
566
640
|
try {
|
|
567
|
-
const result = await
|
|
641
|
+
const result = await (back.size > 0
|
|
642
|
+
? this.options.remote.pull(cursor, [...back].map((id) => ({ resource: links[id].resource, id: links[id].id })))
|
|
643
|
+
: this.options.remote.pull(cursor));
|
|
644
|
+
pulled = true;
|
|
568
645
|
cursor = result.cursor;
|
|
569
646
|
said = result.said;
|
|
570
647
|
// Each sentence with its kind: the transport's resource, read through the mapping (request:notion-said-names-its-source).
|
|
@@ -579,6 +656,50 @@ export class SyncEngine {
|
|
|
579
656
|
if (!mapping)
|
|
580
657
|
continue;
|
|
581
658
|
const localId = byRemoteId.get(`${change.resource}:${change.id}`);
|
|
659
|
+
if (localId && this.options.setAside) {
|
|
660
|
+
/*
|
|
661
|
+
* A RECORD SET ASIDE HERE, its counterpart out of what the sync
|
|
662
|
+
* keeps: still its counterpart. Deleted there: the record stays,
|
|
663
|
+
* said once, and linked as it was, so one restored there before it
|
|
664
|
+
* is brought back is the same record's again.
|
|
665
|
+
*/
|
|
666
|
+
// Out of what the sync keeps as it was brought back, and in it again: in step again.
|
|
667
|
+
const out = this.state.gone?.includes(localId) === true && !returned.has(localId);
|
|
668
|
+
if (!change.deleted) {
|
|
669
|
+
alone.delete(localId);
|
|
670
|
+
returned.add(localId);
|
|
671
|
+
}
|
|
672
|
+
else if (alone.has(localId))
|
|
673
|
+
continue;
|
|
674
|
+
else if (!mapping.readonly && this.isAside(localId, mapping)) {
|
|
675
|
+
if (change.left)
|
|
676
|
+
continue;
|
|
677
|
+
alone.add(localId);
|
|
678
|
+
returned.add(localId);
|
|
679
|
+
// Its conflicts are nobody's to choose between any more.
|
|
680
|
+
for (const key of [...held.keys()])
|
|
681
|
+
if (held.get(key).localId === localId)
|
|
682
|
+
held.delete(key);
|
|
683
|
+
goneAside.push({ kind: mapping.kind, sentence: this.options.setAside.gone(this.labelOf(localId)) });
|
|
684
|
+
continue;
|
|
685
|
+
}
|
|
686
|
+
else if (!mapping.readonly && back.has(localId)) {
|
|
687
|
+
// Brought back, and gone there while it was aside: made there anew; one that only left is kept here, unlinked.
|
|
688
|
+
for (const key of [...held.keys()])
|
|
689
|
+
if (held.get(key).localId === localId)
|
|
690
|
+
held.delete(key);
|
|
691
|
+
if (!change.left) {
|
|
692
|
+
alone.add(localId);
|
|
693
|
+
returned.add(localId);
|
|
694
|
+
continue;
|
|
695
|
+
}
|
|
696
|
+
gone.push(localId);
|
|
697
|
+
goneAside.push({ kind: mapping.kind, sentence: this.options.setAside.left(this.labelOf(localId)) });
|
|
698
|
+
continue;
|
|
699
|
+
}
|
|
700
|
+
else if (out)
|
|
701
|
+
continue;
|
|
702
|
+
}
|
|
582
703
|
/*
|
|
583
704
|
* OUR OWN WRITE, COMING BACK.
|
|
584
705
|
*
|
|
@@ -700,17 +821,17 @@ export class SyncEngine {
|
|
|
700
821
|
for (const [field, value] of Object.entries(theirs)) {
|
|
701
822
|
const key = heldKey(localId, field);
|
|
702
823
|
const base = link.fields[field];
|
|
703
|
-
if (
|
|
824
|
+
if (this.alike(mapping, field, value, ours[field])) {
|
|
704
825
|
agreed[field] = value;
|
|
705
826
|
held.delete(key);
|
|
706
827
|
continue;
|
|
707
828
|
}
|
|
708
|
-
if (
|
|
829
|
+
if (this.alike(mapping, field, value, base)) {
|
|
709
830
|
// Only we changed it: ours goes out in this pass.
|
|
710
831
|
held.delete(key);
|
|
711
832
|
continue;
|
|
712
833
|
}
|
|
713
|
-
if (
|
|
834
|
+
if (this.alike(mapping, field, ours[field], base) || mapping.readonly) {
|
|
714
835
|
lands[field] = agreed[field] = value;
|
|
715
836
|
held.delete(key);
|
|
716
837
|
continue;
|
|
@@ -758,10 +879,38 @@ export class SyncEngine {
|
|
|
758
879
|
offline = true;
|
|
759
880
|
problem = error instanceof Error ? error.message : String(error);
|
|
760
881
|
}
|
|
882
|
+
const say = (sentence, kind) => {
|
|
883
|
+
saidBy = [{ ...(kind ? { kind } : {}), sentence }, ...(saidBy ?? said?.map((one) => ({ sentence: one })) ?? [])];
|
|
884
|
+
said = [sentence, ...(said ?? [])];
|
|
885
|
+
};
|
|
886
|
+
if (unsent)
|
|
887
|
+
say(this.options.holdExisting.say(unsent));
|
|
888
|
+
for (const one of goneAside)
|
|
889
|
+
say(one.sentence, one.kind);
|
|
890
|
+
// Deleted there while it was aside, and brought back or removed here since: linked to nothing.
|
|
891
|
+
for (const localId of alone) {
|
|
892
|
+
const node = this.options.store.graph.getNode(localId);
|
|
893
|
+
if (isArchived(node))
|
|
894
|
+
continue;
|
|
895
|
+
const { [localId]: _gone, ...rest } = links;
|
|
896
|
+
links = rest;
|
|
897
|
+
for (const key of [...held.keys()])
|
|
898
|
+
if (held.get(key).localId === localId)
|
|
899
|
+
held.delete(key);
|
|
900
|
+
if (!node)
|
|
901
|
+
alone.delete(localId);
|
|
902
|
+
}
|
|
761
903
|
// What the inbound pass decided is what the outbound pass sends from.
|
|
762
904
|
const { conflicts: _before, gone: _gone, skipped: _skipped, ...kept } = this.state;
|
|
763
|
-
const
|
|
764
|
-
|
|
905
|
+
for (const id of this.state.gone ?? []) {
|
|
906
|
+
if (this.options.store.graph.getNode(id) || !links[id])
|
|
907
|
+
continue;
|
|
908
|
+
// Removed here while out of what the sync keeps: not the sync's to delete.
|
|
909
|
+
const { [id]: _out, ...rest } = links;
|
|
910
|
+
links = rest;
|
|
911
|
+
}
|
|
912
|
+
const unsynced = [...new Set([...(this.state.gone ?? []).filter((id) => !returned.has(id)), ...gone])].filter((id) => this.options.store.graph.getNode(id));
|
|
913
|
+
this.state = { ...kept, links, ...(this.options.setAside ? { alone: [...alone] } : {}), ...this.heldState(held), ...(unsynced.length > 0 ? { gone: unsynced } : {}), ...(Object.keys(skipped).length > 0 ? { skipped } : {}) };
|
|
765
914
|
// What a relation reached that was not linked yet, linked now that this pull may have made it.
|
|
766
915
|
if (!offline)
|
|
767
916
|
for (const id of this.resolveHeld(refused))
|
|
@@ -775,7 +924,7 @@ export class SyncEngine {
|
|
|
775
924
|
const participants = this.participants();
|
|
776
925
|
for (const [localId, link] of Object.entries(links)) {
|
|
777
926
|
const mapping = this.mappingFor(link.resource);
|
|
778
|
-
if (participants.has(localId) || !mapping?.readonly)
|
|
927
|
+
if (participants.has(localId) || !mapping?.readonly || this.isAside(localId, mapping))
|
|
779
928
|
continue;
|
|
780
929
|
refused.push({ localId, error: this.because(mapping) });
|
|
781
930
|
const { [localId]: _gone, ...rest } = links;
|
|
@@ -839,6 +988,10 @@ export class SyncEngine {
|
|
|
839
988
|
continue;
|
|
840
989
|
}
|
|
841
990
|
pushed.push(ack.localId);
|
|
991
|
+
if (alone.delete(ack.localId))
|
|
992
|
+
say(this.options.setAside.again(this.labelOf(ack.localId)), String(this.options.store.graph.getNode(ack.localId)?.["kind"]));
|
|
993
|
+
if (ack.held)
|
|
994
|
+
refused.push({ localId: ack.localId, error: ack.held });
|
|
842
995
|
const out = guests ? outgoing.get(ack.localId) : undefined;
|
|
843
996
|
if (guests && out) {
|
|
844
997
|
guestsKept[ack.localId] = { sent: { addresses: out.addresses, notified: guests.notify === true, at } };
|
|
@@ -862,6 +1015,9 @@ export class SyncEngine {
|
|
|
862
1015
|
problem = error instanceof Error ? error.message : String(error);
|
|
863
1016
|
}
|
|
864
1017
|
}
|
|
1018
|
+
// A pass that sent what was here leaves nothing to hold, should the declaration stop saying so.
|
|
1019
|
+
if (this.options.holdExisting?.send && !offline && !this.state.existing && this.options.mapping.resources.some((resource) => !resource.readonly))
|
|
1020
|
+
this.state = { ...this.state, existing: {} };
|
|
865
1021
|
this.sayGuests(lines, changes);
|
|
866
1022
|
for (const id of Object.keys(guestsKept))
|
|
867
1023
|
if (!links[id] && !this.options.store.graph.getNode(id))
|
|
@@ -886,7 +1042,9 @@ export class SyncEngine {
|
|
|
886
1042
|
...(this.state.gone ? { gone: this.state.gone } : {}),
|
|
887
1043
|
...(this.state.unresolved ? { unresolved: this.state.unresolved } : {}),
|
|
888
1044
|
...(this.state.skipped ? { skipped: this.state.skipped } : {}),
|
|
1045
|
+
...(this.state.existing ? { existing: Object.fromEntries(Object.entries(this.state.existing).filter(([id]) => !links[id])) } : {}),
|
|
889
1046
|
...(Object.keys(guestsKept).length > 0 ? { guests: guestsKept } : {}),
|
|
1047
|
+
...this.aloneState(alone, links, pulled ? new Set() : back),
|
|
890
1048
|
lastPass,
|
|
891
1049
|
};
|
|
892
1050
|
return {
|
|
@@ -987,6 +1145,20 @@ export class SyncEngine {
|
|
|
987
1145
|
heldState(held) {
|
|
988
1146
|
return held.size > 0 ? { conflicts: [...held.values()] } : {};
|
|
989
1147
|
}
|
|
1148
|
+
/** The records set aside that have nothing there: those known of, and every one no link is for. */
|
|
1149
|
+
aloneState(alone, links, unasked) {
|
|
1150
|
+
if (!this.options.setAside)
|
|
1151
|
+
return {};
|
|
1152
|
+
const all = new Set(alone);
|
|
1153
|
+
const aside = new Set(unasked);
|
|
1154
|
+
for (const node of this.options.store.graph.allNodes({ archived: true })) {
|
|
1155
|
+
const id = node["id"];
|
|
1156
|
+
const mapping = this.mappingFor(node["kind"]);
|
|
1157
|
+
if (mapping?.aside === "keep" && mapping.kind === node["kind"] && !mapping.readonly && (!mapping.match || mapping.match(node)))
|
|
1158
|
+
(links[id] ? aside : all).add(id);
|
|
1159
|
+
}
|
|
1160
|
+
return { ...(all.size > 0 ? { alone: [...all] } : {}), ...(aside.size > 0 ? { aside: [...aside] } : {}) };
|
|
1161
|
+
}
|
|
990
1162
|
/** Records what the remote made of one of our writes. */
|
|
991
1163
|
linkAfterPush(links, ack, writes) {
|
|
992
1164
|
const write = writes.find((candidate) => candidate.localId === ack.localId);
|
|
@@ -1010,7 +1182,7 @@ export class SyncEngine {
|
|
|
1010
1182
|
// compares against — comparing a decoded remote value with an encoded
|
|
1011
1183
|
// local one reports a change on every single pass. A field the write
|
|
1012
1184
|
// left out (held in conflict) keeps the base it had.
|
|
1013
|
-
fields: { ...links[ack.localId]?.fields, ...ourFields(write.fields
|
|
1185
|
+
fields: { ...links[ack.localId]?.fields, ...ourFields({ ...write.fields, ...ack.fields }, mapping, true) },
|
|
1014
1186
|
},
|
|
1015
1187
|
};
|
|
1016
1188
|
}
|