@vrtmrz/livesync-commonlib 0.1.25 → 0.1.26
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/interfaces/DatabaseFileAccess.d.ts +31 -3
- package/dist/interfaces/FileReflectionProvenance.d.ts +2 -2
- package/dist/managers/EntryManager/EntryManager.d.ts +4 -2
- package/dist/managers/EntryManager/EntryManager.js +9 -4
- package/dist/managers/EntryManager/EntryManagerImpls.d.ts +12 -4
- package/dist/managers/EntryManager/EntryManagerImpls.js +27 -9
- package/dist/pouchdb/LiveSyncLocalDB.d.ts +4 -2
- package/dist/pouchdb/LiveSyncLocalDB.js +8 -4
- package/dist/serviceModules/ServiceDatabaseFileAccessBase.d.ts +26 -2
- package/dist/serviceModules/ServiceDatabaseFileAccessBase.js +57 -5
- package/dist/serviceModules/ServiceFileHandlerBase.d.ts +119 -1
- package/dist/serviceModules/ServiceFileHandlerBase.js +450 -70
- package/docs/conflict-resolution.md +28 -15
- package/docs/proven-in-use.md +1 -1
- package/package.json +1 -1
|
@@ -31,13 +31,14 @@ Commonlib follows these rules:
|
|
|
31
31
|
- compare file content byte-for-byte; a path, size, modification time, or revision generation is not proof of identity;
|
|
32
32
|
- use the nearest `available` revision shared by both leaves as the base for three-way merge;
|
|
33
33
|
- retain a manual conflict when the common revision or a required body is missing or compacted;
|
|
34
|
-
-
|
|
35
|
-
-
|
|
34
|
+
- recognise an unchanged file by comparing its bytes with its exact readable file-reflection provenance;
|
|
35
|
+
- save a genuine edit as a child of that recorded revision, even when a newer database winner exists;
|
|
36
|
+
- deduplicate unknown-origin content against current non-deleted leaves, preserving differing content as a fresh independent root under the same document ID; and
|
|
36
37
|
- never select the newest modification time as a package-level default.
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
Ordinary saving and incoming reflection share this classification. A historical byte match alone cannot distinguish an unchanged stale file from an intentional revert, and a prefix or suffix relationship does not prove which version the user edited. Unknown-origin content must not acquire an inferred parent from the current winner or its parent.
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
After a resolution has propagated, an exact recorded revision can still identify unchanged content below a deleted losing leaf. The resolved winner may replace those bytes under the existing reflection policy. If the recorded body is unavailable, the file follows the conservative unknown-origin path. General history-query helpers remain available for callers with separate contracts, including existing deletion and rename recovery; ordinary save and overwrite protection do not scan all historical bodies.
|
|
41
42
|
|
|
42
43
|
## Resolution classes
|
|
43
44
|
|
|
@@ -47,8 +48,10 @@ This check matters after a resolution has propagated. If a receiving device stil
|
|
|
47
48
|
| Text or structured data has a shared available base and non-overlapping changes | Perform a conservative three-way merge. |
|
|
48
49
|
| One side deletes content which the other leaves unchanged | Preserve the deletion. |
|
|
49
50
|
| One side deletes content which the other modifies | Retain a manual conflict. |
|
|
50
|
-
| A receiving file matches
|
|
51
|
-
| A receiving file
|
|
51
|
+
| A receiving file matches its exact readable recorded revision | Apply the propagated result under the existing conflict policy. |
|
|
52
|
+
| A receiving file differs from its readable recorded revision | Preserve the edit as a child of that revision. |
|
|
53
|
+
| Origin is unknown and no current non-deleted leaf matches | Preserve a fresh independent root for host conflict resolution. |
|
|
54
|
+
| Origin is unknown and current non-deleted leaves already contain the bytes | Avoid duplicate storage; infer provenance only for a unique match. |
|
|
52
55
|
| A body or common ancestor is missing or compacted | Retain a manual conflict. |
|
|
53
56
|
| Content is binary or otherwise not semantically mergeable | Leave the selection policy to the host; Commonlib cannot infer user intent. |
|
|
54
57
|
|
|
@@ -74,19 +77,29 @@ The compatibility implementation accepts an injected, device-local `FileReflecti
|
|
|
74
77
|
path -> { revision, observedStorageMtime? }
|
|
75
78
|
```
|
|
76
79
|
|
|
77
|
-
`revision` is the exact database revision
|
|
80
|
+
`revision` is the exact database revision most recently saved from or reflected in this device's storage. It identifies the base for subsequent local edits, rather than certifying that the current file still contains those bytes. `observedStorageMtime` is the raw modification time of the saved snapshot or the file observed after reflection. It is neither rounded nor compared across devices, and it is diagnostic only: revision identity never comes from a timestamp, path, size, or content hash.
|
|
78
81
|
|
|
79
82
|
The record is updated only after a successful database-to-storage reflection or storage-to-database write. A plain read does not change provenance. A record remains authoritative when a user edits the displayed file to bytes which happen to equal another branch; content equality must not silently change the branch being extended.
|
|
80
83
|
|
|
84
|
+
File-handler saves and reflections share a lock for the same Metadata document, held from snapshot acquisition through provenance recording. Different documents can proceed concurrently. An ordinary save keeps one captured body and its recorded base through the database write; a later local edit is processed as a subsequent change, without rereading the file to certify that it remained unchanged. The handler acquires the lock before loading a file body from storage. Rename operations acquire both document locks in a consistent order, and internal calls reuse the caller's lock rather than acquiring it again. Host conflict-check hooks run after the locks are released, allowing a hook to await another file-handler operation on the same document. Host queues may count document-lock waiters against their concurrency limits, so a burst for one document can temporarily delay unrelated files.
|
|
85
|
+
|
|
86
|
+
These locks order Commonlib file-handler operations; they do not stop user edits, external filesystem writes, or database replication. Incoming overwrite and deletion protection therefore still checks current storage. Restored storage events also retain bounded rechecks because they finish before the file watcher starts and cannot depend on a subsequent change notification.
|
|
87
|
+
|
|
81
88
|
User-directed reconciliation may select any exact current live revision, including a conflict leaf rather than the deterministic winner. `dbToStorageWithSpecificRev()` rechecks that the selected revision is still live before reflecting its content. `storeFileToDBWithBaseRevision()` performs the same live check before storing current storage content as a child of that revision. If the content already matches the selected non-deleted revision, it records that revision directly without creating a child. A host can set `createIfDifferent` to `false` when it intends only to record an exact content match; differing content then fails instead of changing the revision tree. A host may also create a logical deletion on an explicitly selected branch with `deleteRevisionFromDB()` after performing its own current-live-revision check. This leaves storage unchanged and clears device-local provenance only when that record names the deleted revision.
|
|
82
89
|
|
|
83
90
|
`storeWithBaseRevision()` is the force-write primitive for deliberately preserving a branch below an exact revision, including a revision which is no longer a leaf. It must not be used when an operation means 'advance this revision only if it is still current'. For that compare-and-store boundary, `storeWithLiveBaseRevision()` uses PouchDB's ordinary revision check and returns `false` if the supplied base has already been advanced. Any current revision-tree leaf is eligible, including a non-winning conflict leaf or a logical-deletion leaf. The caller must refresh its state after refusal rather than silently falling back to the deterministic winner.
|
|
84
91
|
|
|
92
|
+
`storeIndependentRevision()` explicitly preserves unknown-origin content through `putDBEntryAsIndependentRoot()`. Passing an undefined base to `storeWithBaseRevision()` retains its existing latest-revision behaviour and does not create an independent root. `findLiveContentRevisions()` compares only current non-deleted leaves using locally available chunks. Additional provenance comparisons also use local-only retrieval, so they do not introduce remote chunk requests or delivery waits; a missing body leads to preservation rather than an inferred base.
|
|
93
|
+
|
|
85
94
|
A successful non-deleted reconciliation records the exact selected or newly created revision as provenance. Applying a logical deletion removes the storage item and its provenance record. Deletion provenance is not retained indefinitely: an absent storage item and a current logical-deletion winner already agree and need no further reconciliation.
|
|
86
95
|
|
|
87
96
|
Hosts may construct the namespaced store handle during service composition, before its backing database is open. Store operations begin only after the host's storage lifecycle is ready. They fail rather than wait when that lifecycle contract is violated, because an implicit readiness wait could hang after failed initialisation or wait on its own initialisation handler. Database reset is a transient unavailable boundary; the host must avoid file processing during it and reconstruct derived provenance after reopening.
|
|
88
97
|
|
|
89
|
-
|
|
98
|
+
For ordinary saving and incoming reflection, an absent or unreadable recorded base permits reconstruction only from exactly one matching current non-deleted leaf. Multiple matches avoid duplicate storage without guessing branch identity. No current match creates a fresh independent root, even when an ancestor has the same bytes. Deletion and rename retain their existing provenance-recovery contracts.
|
|
99
|
+
|
|
100
|
+
An unchanged stale file is not saved below the winner. When the database has advanced without a conflict, the existing database-to-storage path reflects it; a conflict instead remains subject to the host's reflection and resolution policy. Independent roots retain the file's modification time and use the existing Metadata/Chunks format, with fresh revision identifiers and reusable chunks. They have no shared ancestor with unrelated existing branches, including after replication. This does not disable a host's explicit newer-file option.
|
|
101
|
+
|
|
102
|
+
Saving and reflection revalidate captured file content and provenance across asynchronous work. Restored saves reconcile changed storage directly, because host file watchers may not yet be registered. Retries are bounded; a file which keeps changing causes the operation to fail rather than report an uncompleted save as successful. These checks do not make external filesystem edits atomic with a host write: the storage contract has no conditional write operation covering that final interval.
|
|
90
103
|
|
|
91
104
|
## Operations while a conflict exists
|
|
92
105
|
|
|
@@ -99,7 +112,7 @@ With a proven displayed revision:
|
|
|
99
112
|
|
|
100
113
|
When edit provenance cannot be reconstructed, the new bytes are preserved as another manual-resolution branch instead of being attached silently to the deterministic winner. A deletion has no remaining file body from which to reconstruct provenance, so an unproven deletion preserves every live branch and requests conflict review. A cross-path rename with an unproven source keeps the newly stored target and preserves every source branch for review.
|
|
101
114
|
|
|
102
|
-
If
|
|
115
|
+
If the recorded base cannot be read, an ordinary save preserves differing storage bytes on an independent root without guessing the winner's parent. This also works when the existing winner is generation one or has unavailable chunks. Existing unreadable branches remain available for repair. A host may separately offer confirmed exact-revision discard; it must not infer permission for discard from a failed read.
|
|
103
116
|
|
|
104
117
|
These fallbacks favour recoverability. They may temporarily leave a duplicate target or a still-visible source conflict, but they do not discard a branch whose relationship to the user's operation cannot be proved.
|
|
105
118
|
|
|
@@ -145,19 +158,19 @@ For a cross-path rename, such as `draft.md` to `published.md`, Commonlib stores
|
|
|
145
158
|
|
|
146
159
|
### Reconstructing provenance after local state is unavailable
|
|
147
160
|
|
|
148
|
-
Suppose a local-database reset removed the device-local record, but the storage file still has exactly the bytes held by `C2`. If `C2` is the only
|
|
161
|
+
Suppose a local-database reset removed the device-local record, but the storage file still has exactly the bytes held by current non-deleted leaf `C2`. If `C2` is the only matching current leaf, ordinary saving or reflection can reconstruct `C2` as the displayed base and a later edit extends it normally. An unchanged-time scan alone does not guarantee reconstruction.
|
|
149
162
|
|
|
150
|
-
If both
|
|
163
|
+
If both current leaves contain the same bytes, ordinary saving avoids duplicate storage without selecting either as provenance. If neither contains the storage bytes, those bytes are preserved on an independent root. An unproven deletion preserves both existing branches, and a cross-path rename preserves unproven source branches after storing the target. These outcomes may require user review, but they do not guess that the deterministic winner was displayed.
|
|
151
164
|
|
|
152
165
|
### Receiving a resolution while showing the losing branch
|
|
153
166
|
|
|
154
|
-
Device A may resolve the conflict while Device B still displays the bytes from `C2`. When the resolved tree reaches Device B, the
|
|
167
|
+
Device A may resolve the conflict while Device B still displays the bytes from recorded revision `C2`. When the resolved tree reaches Device B, the exact recorded body identifies those bytes as unchanged, even below the deleted losing leaf. Device B can apply the resolution without recreating the conflict. If Device B edited the file after displaying `C2`, its bytes differ from that recorded body and the overwrite guard preserves the edit, including an intentional revert to some other historical content.
|
|
155
168
|
|
|
156
169
|
### Starting and resetting the provenance store
|
|
157
170
|
|
|
158
171
|
A host may create the namespaced provenance handle while composing services. It then opens the backing key-value database in its sequential settings lifecycle before enabling scans, storage watchers, or replication. If opening fails, start-up stops; a provenance operation is not held waiting for a readiness state which may never arrive.
|
|
159
172
|
|
|
160
|
-
During a local-database reset, the store is temporarily unavailable. A racing lookup fails promptly and is treated as unknown provenance, selecting the conservative behaviours above. Once the database has reopened,
|
|
173
|
+
During a local-database reset, the store is temporarily unavailable. A racing lookup fails promptly and is treated as unknown provenance, selecting the conservative behaviours above. Once the database has reopened, saving or reflection can reconstruct a record from a unique matching current non-deleted leaf.
|
|
161
174
|
|
|
162
175
|
## Unsafe shortcuts
|
|
163
176
|
|
|
@@ -167,11 +180,11 @@ Do not:
|
|
|
167
180
|
- select a winner from modification time unless the host exposes and the user selects that destructive policy;
|
|
168
181
|
- assume the PouchDB winner is the content currently displayed in storage;
|
|
169
182
|
- replace a recorded displayed revision merely because current bytes match another branch;
|
|
170
|
-
-
|
|
183
|
+
- infer that a file is unchanged from historical byte equality without its exact provenance;
|
|
171
184
|
- discard storage content because history lookup failed;
|
|
172
185
|
- infer revision identity from path, size, modification time, or hash without the revision identifier; or
|
|
173
186
|
- automatically merge overlapping text changes or unrelated binary contents.
|
|
174
187
|
|
|
175
188
|
## Verification ownership
|
|
176
189
|
|
|
177
|
-
Commonlib unit tests build real in-memory PouchDB trees and inject provenance fakes at the file-handler boundary. They cover
|
|
190
|
+
Commonlib unit tests build real in-memory PouchDB trees and inject provenance fakes at the file-handler boundary. They cover revision ancestry, conservative merge, content preservation, independent roots, repeated events, and the separate explicit reconciliation, deletion, and rename contracts. A maintained host should additionally verify persistent device-local provenance, real file events, restart processing, replication of the resulting revision trees, and dialogue policy. Package-level tests do not establish mobile lifecycle behaviour or the original reporter's environment.
|
package/docs/proven-in-use.md
CHANGED
|
@@ -14,7 +14,7 @@ The consumer contract in `test/contracts/serviceContext.ts` checks shared result
|
|
|
14
14
|
|
|
15
15
|
Commonlib supplies the two sleep preferences and preserves them through Setup URI encoding. Self-hosted LiveSync applies those values once at its injected bounded-activity runner, so remote operations and downloaded-document application share the same host-owned Wake Lock policy. Focused downstream tests cover the platform preference table and both activity categories; operating-system suspend behaviour remains real-platform integration evidence rather than a Commonlib guarantee.
|
|
16
16
|
|
|
17
|
-
Commonlib's real-PouchDB and injected-boundary unit tests prove that conservative merge uses the nearest revision actually shared by both conflict leaves, multiple remaining leaves are selected in a deterministic order, each completed pair is reconstructed from the committed tree, storage content
|
|
17
|
+
Commonlib's real-PouchDB and injected-boundary unit tests prove that conservative merge uses the nearest revision actually shared by both conflict leaves, multiple remaining leaves are selected in a deterministic order, each completed pair is reconstructed from the committed tree, storage content with exact provenance remains recognisable below a deleted losing branch after resolution, and ordinary file saves preserve edits below their recorded base or on an independent root when the base cannot be read. Incoming reflection uses the same classification. Current non-deleted leaf matches prevent duplicate preservation without using historical byte equality as proof of an unchanged file. Conflict-time deletion and rename retain their separate displayed-branch contracts. They also verify that a boolean history check stops after its first exact content match without reading an older unavailable revision, while revision enumeration still returns every match. Unknown-origin local content remains readable on a fresh independent root when the winning body is unavailable, including when the existing winner is generation one. A separately confirmed exact deletion of an unreadable current leaf remains an explicit repair operation. Exact reconciliation tests cover reflecting a selected live leaf, storing Vault content as its child, recording a matching leaf without creating a revision, clearing matching provenance after exact branch deletion, and refusing to record a stale revision or a revision whose content differs. Separate live-base tests advance a selected conflict leaf or logical-deletion leaf through PouchDB's ordinary revision check, retain the other live leaf, and reject reuse of a stale base. Self-hosted LiveSync supplies the host composition, persistent device-local provenance, and the per-revision repair interface. Its optional two-Vault scopes cover post-resolution propagation and edit, logical deletion, case-only rename, and cross-path rename while conflicts remain active. The conflict-operation scope passes in real Obsidian against the exact locally packed Commonlib artefact, including replicated parent revisions and preservation of the other live branches. Its Document History scenario restores readable historical bytes as a new live successor and reflects that exact revision to the Vault.
|
|
18
18
|
|
|
19
19
|
Commonlib's chunk-reachability tests use real PouchDB revision trees. They verify that an ordinary superseded revision releases its unique chunks, a chunk shared by current files remains reachable, live conflict branches and their nearest available shared ancestor remain protected, and losing-branch ancestry becomes eligible after resolution. They also replicate a collected chunk deletion to another PouchDB database and verify that writing the same content can recreate and replicate the content-addressed chunk. Self-hosted LiveSync owns the CouchDB-specific Garbage Collection V3 workflow, including device checks, confirmation, deletion, push-only replication, and remote compaction.
|
|
20
20
|
|
package/package.json
CHANGED