@drakkar.software/starfish-client 3.0.0-alpha.37 → 3.0.0-alpha.39

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/sync.d.ts CHANGED
@@ -71,10 +71,28 @@ export declare class SyncManager {
71
71
  private localData;
72
72
  private aborted;
73
73
  private lastFromCache;
74
+ /** True once {@link seedFromCache} has successfully seeded localData from the cache. */
75
+ private seeded;
74
76
  constructor(options: SyncManagerOptions);
75
77
  abort(): void;
76
78
  get isAborted(): boolean;
77
79
  getData(): Record<string, unknown>;
80
+ /**
81
+ * Returns true when `pull()` / `ingest()` should merge against the current
82
+ * `localData` rather than replace it wholesale.
83
+ *
84
+ * Two situations establish a merge baseline:
85
+ * - A successful prior pull/ingest advanced `lastCheckpoint` beyond 0 (the
86
+ * normal steady-state case, unchanged since alpha.36).
87
+ * - A cache seed painted `localData` via {@link seedFromCache} AND the store
88
+ * uses a custom conflict resolver (i.e. NOT the default `deepMerge`). For a
89
+ * union/custom resolver the seeded snapshot is a real baseline that must not
90
+ * be clobbered by a short first live response (a cache-fallback on 429/5xx
91
+ * or a momentarily-short concurrent server snapshot). For the default
92
+ * `deepMerge` resolver we keep the pre-fix wholesale-replace behaviour so
93
+ * non-union stores are byte-identical to alpha.36.
94
+ */
95
+ private hasMergeBaseline;
78
96
  /**
79
97
  * Merge a remote snapshot with local (optimistic) data using this manager's
80
98
  * conflict resolver — the same resolver the push-conflict path uses. A plain
@@ -101,7 +119,19 @@ export declare class SyncManager {
101
119
  * WITHOUT touching the network, decrypting in memory for E2E collections.
102
120
  * Returns whether anything was seeded (false on a miss, an expired entry, or
103
121
  * a decrypt failure — e.g. keyring skew). Call once on store creation before
104
- * the initial live {@link pull}, which then supersedes the seeded snapshot.
122
+ * the initial live {@link pull}.
123
+ *
124
+ * `lastCheckpoint` is intentionally left at 0 so the first live pull sends a
125
+ * full (re)sync request to the server, not a delta. However, for stores with
126
+ * a custom conflict resolver (e.g. `createUnionMerge`) the seeded snapshot is
127
+ * treated as a merge baseline: {@link hasMergeBaseline} returns true, so the
128
+ * first pull/ingest merges against the seed rather than replacing it wholesale.
129
+ * This closes the bootstrap window where a short first-pull response (a cache-
130
+ * fallback on 429/5xx or a momentarily-short concurrent snapshot) would
131
+ * silently drop items the resolver was configured to preserve. For the default
132
+ * `deepMerge` resolver the first pull still takes the snapshot wholesale —
133
+ * behaviour is byte-identical to alpha.36.
134
+ *
105
135
  * Requires the client to have been built with a `cache`.
106
136
  */
107
137
  seedFromCache(): Promise<boolean>;
@@ -113,12 +143,15 @@ export declare class SyncManager {
113
143
  * {@link StarfishClientOptions.onRevalidated}) into the store.
114
144
  *
115
145
  * Like {@link pull}, `ingest` conflict-merges the snapshot against the
116
- * established baseline via `this.onConflict` when a checkpoint exists — so a
117
- * union-merge store does not lose array items when a revalidation result
118
- * (e.g. a stale cache-fallback on 429/5xx) is a shorter snapshot. The first
119
- * ingest (no checkpoint yet) takes the snapshot wholesale. Sets
120
- * `lastFromCache = false` (a revalidation is a live response) so the binding
121
- * can clear its `stale` flag.
146
+ * established baseline via `this.onConflict` when a merge baseline exists
147
+ * ({@link hasMergeBaseline}) — so a union-merge store does not lose array
148
+ * items when a revalidation result (e.g. a stale cache-fallback on 429/5xx)
149
+ * is a shorter snapshot. The baseline is established by either a prior
150
+ * pull/ingest that advanced `lastCheckpoint`, or by a successful
151
+ * {@link seedFromCache} for a store with a custom resolver. The first ingest
152
+ * without such a baseline takes the snapshot wholesale (default `deepMerge`
153
+ * stores are byte-identical to alpha.36). Sets `lastFromCache = false` (a
154
+ * revalidation is a live response) so the binding can clear its `stale` flag.
122
155
  *
123
156
  * **Staleness guard**: if a `push()` advanced `lastCheckpoint` between the
124
157
  * time the revalidation request was sent and the time it resolves, the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drakkar.software/starfish-client",
3
- "version": "3.0.0-alpha.37",
3
+ "version": "3.0.0-alpha.39",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/Drakkar-Software/starfish.git",
@@ -69,7 +69,7 @@
69
69
  }
70
70
  },
71
71
  "dependencies": {
72
- "@drakkar.software/starfish-protocol": "3.0.0-alpha.37"
72
+ "@drakkar.software/starfish-protocol": "3.0.0-alpha.39"
73
73
  },
74
74
  "devDependencies": {
75
75
  "@legendapp/state": "^2.0.0",