@vrtmrz/livesync-commonlib 0.4.2 → 0.5.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.
Files changed (100) hide show
  1. package/README.md +7 -5
  2. package/dist/API/DirectFileManipulatorV2.d.ts +1 -0
  3. package/dist/API/DirectFileManipulatorV2.js +3 -1
  4. package/dist/API/processSetting.d.ts +1 -0
  5. package/dist/API/processSetting.js +3 -0
  6. package/dist/common/models/setting.const.defaults.js +1 -0
  7. package/dist/common/models/setting.const.qr.js +2 -1
  8. package/dist/common/models/setting.encryption.d.ts +2 -0
  9. package/dist/common/models/setting.encryption.js +6 -0
  10. package/dist/common/models/setting.lifecycle.js +7 -2
  11. package/dist/common/models/setting.policy.d.ts +4 -0
  12. package/dist/common/models/setting.policy.js +9 -0
  13. package/dist/common/models/setting.type.d.ts +2 -0
  14. package/dist/common/models/shared.definition.configNames.js +5 -0
  15. package/dist/common/models/tweak.definition.d.ts +1 -0
  16. package/dist/common/settingConstants.d.ts +1 -0
  17. package/dist/common/utils.js +5 -4
  18. package/dist/diagnostics/couchdb.js +4 -2
  19. package/dist/interfaces/StorageAccess.d.ts +8 -2
  20. package/dist/managers/ChunkFetcher.js +27 -4
  21. package/dist/managers/chunkFetcher.helper.js +1 -1
  22. package/dist/platform/FilePathIndex.d.ts +110 -0
  23. package/dist/platform/FilePathIndex.js +146 -0
  24. package/dist/pouchdb/StreamingFetch.d.ts +1 -2
  25. package/dist/pouchdb/encryption.d.ts +5 -10
  26. package/dist/pouchdb/encryption.eden.d.ts +11 -0
  27. package/dist/pouchdb/encryption.eden.js +37 -0
  28. package/dist/pouchdb/encryption.js +67 -63
  29. package/dist/pouchdb/encryption.policy.d.ts +9 -0
  30. package/dist/pouchdb/encryption.policy.js +125 -0
  31. package/dist/replication/UnencryptedContentRejectedError.d.ts +16 -0
  32. package/dist/replication/UnencryptedContentRejectedError.js +44 -0
  33. package/dist/replication/couchdb/LiveSyncReplicator.js +41 -4
  34. package/dist/replication/index.d.ts +2 -0
  35. package/dist/replication/index.js +3 -0
  36. package/dist/replication/trystero/LiveSyncTrysteroReplicator.d.ts +3 -3
  37. package/dist/replication/trystero/P2PAutomationCoordinator.d.ts +1 -1
  38. package/dist/replication/trystero/P2PReplicationWire.d.ts +1 -1
  39. package/dist/replication/trystero/TrysteroReplicator/changeRelay.d.ts +133 -0
  40. package/dist/replication/trystero/TrysteroReplicator/changeRelay.js +176 -0
  41. package/dist/replication/trystero/TrysteroReplicator/configurationExchange.d.ts +55 -0
  42. package/dist/replication/trystero/TrysteroReplicator/configurationExchange.js +99 -0
  43. package/dist/replication/trystero/TrysteroReplicator/configuredTargets.d.ts +83 -0
  44. package/dist/replication/trystero/TrysteroReplicator/configuredTargets.js +121 -0
  45. package/dist/replication/trystero/TrysteroReplicator/peerAgreement.d.ts +75 -0
  46. package/dist/replication/trystero/TrysteroReplicator/peerAgreement.js +131 -0
  47. package/dist/replication/trystero/TrysteroReplicator/progress.d.ts +57 -0
  48. package/dist/replication/trystero/TrysteroReplicator/progress.js +84 -0
  49. package/dist/replication/trystero/TrysteroReplicator/relayControl.d.ts +20 -0
  50. package/dist/replication/trystero/TrysteroReplicator/relayControl.js +25 -0
  51. package/dist/replication/trystero/TrysteroReplicator/transfers.d.ts +125 -0
  52. package/dist/replication/trystero/TrysteroReplicator/transfers.js +278 -0
  53. package/dist/replication/trystero/TrysteroReplicator.d.ts +65 -481
  54. package/dist/replication/trystero/TrysteroReplicator.js +240 -673
  55. package/dist/replication/trystero/TrysteroReplicatorP2PClient.d.ts +19 -6
  56. package/dist/replication/trystero/TrysteroReplicatorP2PClient.js +29 -25
  57. package/dist/replication/trystero/TrysteroReplicatorP2PServer/peerAdmission.d.ts +66 -0
  58. package/dist/replication/trystero/TrysteroReplicatorP2PServer/peerAdmission.js +142 -0
  59. package/dist/replication/trystero/TrysteroReplicatorP2PServer.d.ts +19 -16
  60. package/dist/replication/trystero/TrysteroReplicatorP2PServer.js +33 -93
  61. package/dist/replication/trystero/p2pReplicationDiagnostics.d.ts +1 -1
  62. package/dist/replication/trystero/p2pReplicationProgress.d.ts +2 -11
  63. package/dist/replication/trystero/replicationTypes.d.ts +88 -0
  64. package/dist/replication/trystero/replicationTypes.js +0 -0
  65. package/dist/replication/trystero/rpcSessionProvider.d.ts +13 -0
  66. package/dist/replication/trystero/rpcSessionProvider.js +0 -0
  67. package/dist/replication/unencryptedContentMessages.d.ts +8 -0
  68. package/dist/replication/unencryptedContentMessages.js +12 -0
  69. package/dist/rpc/RpcRoom/pendingInvocations.d.ts +141 -0
  70. package/dist/rpc/RpcRoom/pendingInvocations.js +225 -0
  71. package/dist/rpc/RpcRoom.d.ts +9 -4
  72. package/dist/rpc/RpcRoom.js +73 -118
  73. package/dist/rpc/RpcSession.d.ts +6 -0
  74. package/dist/rpc/RpcSession.js +11 -0
  75. package/dist/rpc/types.d.ts +2 -0
  76. package/dist/serviceFeatures/targetFilter.d.ts +1 -1
  77. package/dist/serviceFeatures/targetFilter.js +8 -38
  78. package/dist/serviceModules/FileAccessBase.d.ts +4 -0
  79. package/dist/serviceModules/FileAccessBase.js +10 -0
  80. package/dist/serviceModules/Rebuilder.js +29 -5
  81. package/dist/serviceModules/ServiceFileAccessBase/fileNames.d.ts +54 -0
  82. package/dist/serviceModules/ServiceFileAccessBase/fileNames.js +57 -0
  83. package/dist/serviceModules/ServiceFileAccessBase.d.ts +5 -1
  84. package/dist/serviceModules/ServiceFileAccessBase.js +18 -3
  85. package/dist/serviceModules/adapters/IFileSystemAdapter.d.ts +3 -0
  86. package/dist/services/base/RemoteConnection.d.ts +2 -0
  87. package/dist/services/base/RemoteService.js +2 -1
  88. package/dist/services/base/SettingService.js +2 -0
  89. package/dist/settings.d.ts +2 -1
  90. package/dist/settings.js +2 -0
  91. package/dist/storage.d.ts +2 -0
  92. package/dist/storage.js +2 -0
  93. package/dist/worker/bgWorker.js +1 -1
  94. package/docs/development.md +103 -0
  95. package/docs/offline-scanner.md +2 -1
  96. package/docs/p2p-transport-lifecycle.md +24 -0
  97. package/docs/platform-storage.md +22 -0
  98. package/docs/releasing.md +6 -0
  99. package/docs/settings-lifecycle.md +6 -0
  100. package/package.json +1 -1
@@ -76,6 +76,109 @@ class. Its extracted functions and their focused tests live in
76
76
  `src/managers/StorageEventManager/`. These organise the event lifecycle separately
77
77
  from the file handler's database and storage effects.
78
78
 
79
+ ## P2P and RPC implementation
80
+
81
+ `src/replication/trystero/TrysteroReplicator.ts` retains the existing replicator
82
+ interface, wire command assembly, peer-arrival policy, and host lifecycle. Its
83
+ internal modules use narrow capabilities rather than the complete replicator:
84
+
85
+ | Module under `TrysteroReplicator/` | Responsibility |
86
+ | --- | --- |
87
+ | `changeRelay.ts` | Own the changes feed, broadcast state, followed peers, and last sequence; schedule notifications and request pulls. |
88
+ | `peerAgreement.ts` | Request authentication and compare tweak, path-identity, and ID-derivation agreement without exposing the ID key. |
89
+ | `configurationExchange.ts` | Prepare shared settings, obtain passphrases, encrypt or decrypt configuration, and validate imported ID settings. |
90
+ | `progress.ts` | Own acknowledged-attempt state and module-realm attempt numbering, project progress events, and report progress to the peer. |
91
+ | `configuredTargets.ts` | Resolve configured peer names, wait for discovery with listener cleanup, and aggregate sequential baseline synchronisation results. |
92
+ | `transfers.ts` | Own available and active peer sets, apply transfer gates, run the shared replication engine, and finalise progress. |
93
+ | `relayControl.ts` | Adapt shared Trystero relay controls and disconnect a captured socket set without changing host-stop ordering. |
94
+
95
+ The facade's existing relay accessors refer to the relay's single state object.
96
+ Agreement and configuration operations obtain snapshot settings and current
97
+ policy at their documented stages. The host retains peer acceptance, database
98
+ validation, transport binding, and finite-transfer ownership. Public method
99
+ dispatch remains dynamic so host overrides continue to apply. The operations
100
+ use `octagonal-wheels/context` to bind named, standalone functions. Each function
101
+ declares only the dependencies and state it uses, or accepts a composed operation
102
+ instead of that operation's dependencies. Factories allocate state and connect
103
+ these functions; construction starts no database or RPC work. State-bearing
104
+ bindings retain the owner object so existing facade setters remain effective.
105
+
106
+ Shared result, progress, acknowledgement, and peer-admission data contracts live
107
+ in `src/replication/trystero/replicationTypes.ts`, independently of their operation
108
+ owners. The facade, projection, diagnostic, and wire adapters import that leaf
109
+ rather than importing types back from the implementations they support. Local
110
+ failures retain their original error values; the separate wire result uses
111
+ JSON-safe RPC error data. Existing type export paths remain available as
112
+ re-exports. Transfer methods borrow the session owner's
113
+ signal and retain dynamic public dispatch for pull and reverse-sync requests.
114
+ Progress attempts remain ordered across room replacement within one module
115
+ realm; peer departure removes one acknowledgement history, and close clears all
116
+ histories and active transfer sets. Configured-target discovery releases event,
117
+ abort, and timeout hooks before continuing into per-target processing.
118
+
119
+ `TrysteroReplicatorP2PClient` accepts the neutral `rpcSessionProvider.ts`
120
+ capabilities and retains the supplied provider type through its generic parameter.
121
+ Each operation resolves the provider's current room, including calls made through
122
+ a cached database facade. Closing clears the provider and cached facade; `remoteDB`
123
+ then returns `undefined`, while `getRemoteDB()` throws
124
+ `Error('Not connected to any room')`. Calls through an earlier facade also reject.
125
+ Existing call timeouts, notification semantics, and method namespaces remain unchanged.
126
+
127
+ `TrysteroReplicatorP2PServer/peerAdmission.ts` contains the named decision,
128
+ prompt, policy, and admission functions. The Server retains its persisted store,
129
+ temporary decisions, advertisements, and pattern caches; getter capabilities
130
+ keep replacements and public method overrides visible. Policy tests require no
131
+ database, room, or complete host environment. Decision types remain available
132
+ through their previous Server exports.
133
+
134
+ The Server's optional third constructor argument accepts `createRoom`, defaulting
135
+ to Trystero's `joinRoom`. It is called at the original point after diagnostic
136
+ subscriptions, and real `RpcRoom` instances still own message and peer-event
137
+ subscriptions. Registration and the synchronous `beforeAdvertisement` hook
138
+ precede advertisement sending. A separate boundary spec uses real RPC rooms and
139
+ paired fake Trystero rooms to verify calls, notifications, cancellation, and close.
140
+ The replicator facade's optional fourth constructor argument supplies relay
141
+ controls, preserving its third finite-operation-owner argument. Disconnection
142
+ reads sockets, pauses reconnection, closes the captured set, and starts the public
143
+ host-stop operation in the original order. Default controls use the shared
144
+ Trystero registry.
145
+
146
+ `src/rpc/RpcRoom.ts` retains registrations, inbound request routing, transport,
147
+ and chunk state. `RpcRoom/pendingInvocations.ts` owns outbound response waits,
148
+ deadlines, abort subscriptions, settlement, and request-before-cancel ordering.
149
+ The room supplies transport, request IDs, timing, and warning callbacks, and
150
+ forwards peer departure and close events. Notifications bypass this coordinator.
151
+
152
+ The internal modules have focused unit tests beside their implementations.
153
+ Direct function tests supply only the capabilities used by that operation;
154
+ factory tests retain coverage of state sharing and lifetime integration.
155
+ Configured-target discovery returns a Promise to adapt advertisement, abort,
156
+ and timeout callbacks. Registration and the initial predicate run inside its
157
+ executor so setup exceptions remain rejections, while cleanup remains synchronous.
158
+ Their lifetime boundaries retain the existing feed stop boundaries and synchronous
159
+ invocation-wait cleanup. They add no consumer entry points, persistent state,
160
+ retry policy, or new queue policy. Function comments record settings provenance,
161
+ secret exclusions, completion meaning, error boundaries, and cancellation order.
162
+
163
+ ## File-name lookup implementation
164
+
165
+ `ServiceFileAccessBase.ts` forwards name queries to the host adapter or its
166
+ package-private `ServiceFileAccessBase/fileNames.ts` fallback. The fallback
167
+ retains one typed request for the active storage-event count and comparison
168
+ policy, shares its pending listing, and uses `FilePathIndex` to select candidates.
169
+ A fresh read retires that request before listing again. Older completions remain
170
+ visible to their original callers without replacing a newer retained request.
171
+ `StorageAccess` inherits the name-query methods from the shared `FileNameLookup`
172
+ contract. The host adapter's indexed capability remains optional; the facade's
173
+ fallback keeps both methods available without redeclaring their signatures.
174
+
175
+ The fallback factory owns only its active-request state. Index creation, request
176
+ reuse, candidate selection, and rejection retirement are named module-level
177
+ operations with explicit state and dependency parameters. Listing-only operations
178
+ accept just `getFileNames`; observation counting is required only by candidate
179
+ selection. Direct operation tests cover promise sharing, re-entrant invalidation,
180
+ older request rejection, and policy snapshots alongside the factory contract tests.
181
+
79
182
  ## Service composition and state ownership
80
183
 
81
184
  Commonlib uses four related forms of composition. Choose between them by ownership and dependency direction, not merely by whether an implementation has mutable state.
@@ -199,4 +199,5 @@ For `db-only-deleted` pairs, one optional provenance key enumeration identifies
199
199
  stale bookkeeping. Cleanup-only work precedes new deletions and never reads file
200
200
  bodies or invokes physical deletion. All affected paths are revalidated by their
201
201
  handler. See [Deletion recovery](deletion-recovery.md) for completion, error,
202
- concurrency, and cost contracts. This extension is unreleased.
202
+ concurrency, and cost contracts. This opt-in extension is published in
203
+ [Commonlib 0.4.2](https://github.com/vrtmrz/livesync-commonlib/releases/tag/0.4.2).
@@ -126,6 +126,30 @@ batch still supplies final sequences and counts. Older peers can ignore the extr
126
126
  argument and continue using sequence progress. No handshake, retry, heartbeat, or
127
127
  persistent replication state is added.
128
128
 
129
+ ## Best-effort change notifications
130
+
131
+ Implementation note: this notification path is unreleased, reviewed against
132
+ Commonlib 0.4.3 and Self-hosted LiveSync 1.0.49. It does not change the published
133
+ status of the lifecycle and diagnostics described elsewhere in this document.
134
+
135
+ P2P change notifications ask a following peer to fetch database changes; they do
136
+ not carry Vault data or confirm that a transfer has succeeded. The sender uses
137
+ `RpcSession.notify()` through the peer client, so it waits only for transport
138
+ sending and does not register a pending RPC invocation or a response timeout.
139
+ A notification rejected before admission therefore cannot block later change
140
+ notifications, and a long-running pull does not delay the sender's next notification.
141
+
142
+ The `change-notification-sent` observation records transport sending, not peer
143
+ admission, completed replication, or Vault reflection. Pull outcomes remain
144
+ separate observations. A missed final notification is not retried automatically;
145
+ a later notification or explicit synchronisation can initiate a fresh comparison.
146
+
147
+ The optional request field `expectsResponse: false` suppresses both successful
148
+ and failed RPC responses on updated receivers. An older receiver may still reply;
149
+ the sender ignores that response because it has no pending invocation. Existing
150
+ request admission, handler execution, cancellation, and room ownership remain in
151
+ force. This change does not make not-ready or busy replication succeed.
152
+
129
153
  ## Latest diagnostic observations
130
154
 
131
155
  The optional `P2PDiagnostics.getDiagnosticSnapshot()` and
@@ -122,6 +122,28 @@ version. Its ordinary case-mismatch check remains separate from path-version
122
122
  admission. See [Unicode path identity](unicode-path-identity.md#supported-hosts)
123
123
  for the current publication and host-adoption boundaries.
124
124
 
125
+ ## File-name candidate lookup
126
+
127
+ These file-name APIs are an unreleased Commonlib change. `FilePathIndex`,
128
+ exported from `/storage`, keeps original file names and groups
129
+ all candidates under an explicit Unicode and case policy. It performs no I/O
130
+ and owns no watcher or readiness state. The host owns the index lifetime,
131
+ initial listing, supported-path rules, and membership updates; use
132
+ `replaceAll()` for an initial snapshot and `apply({ removed, added })` for a
133
+ membership change. Content-only events do not require an index update.
134
+
135
+ Hosts can expose an asynchronous `FileNameLookup` through the optional
136
+ `fileNameLookup` property of `IFileSystemAdapter`. When `{ fresh: true }` is
137
+ supplied, `getFileNames()` must ask the host's supported listing authority
138
+ again. `findPathIdentityCandidates(path, policy)` returns every matching original
139
+ path whose comparison key matches the requested identity. Multiple results are
140
+ candidates for the caller's collision decision. Keep fresh listing guarantees
141
+ host-specific. A host without this
142
+ capability continues to list through `getFiles()` and uses the storage-access
143
+ fallback.
144
+ Direct `StorageAccess` implementations must also implement the required
145
+ `findPathIdentityCandidates()` method when adopting this pre-1.0 interface.
146
+
125
147
  ## Bundling boundary
126
148
 
127
149
  Browser consumers import only `@vrtmrz/livesync-commonlib/browser`. Packed-package tests build that entry with browser conditions and verify that the Node implementation is absent. Node consumers import `@vrtmrz/livesync-commonlib/node`; the root and context entries do not load Node built-ins.
package/docs/releasing.md CHANGED
@@ -73,6 +73,12 @@ implementations must also provide `registerCleanup(callback: () => void): void`;
73
73
  subclasses of `APIService` inherit its default terminal-unload implementation.
74
74
  These changes use the next minor version under the compatibility policy.
75
75
 
76
+ Version 0.5.0 adds the required `findPathIdentityCandidates()` method to
77
+ `StorageAccess`. Direct implementations must supply it; implementations based
78
+ on `ServiceFileAccessBase` inherit the adapter or listing fallback. The P2P
79
+ client also exposes its closed provider state explicitly in its types. These
80
+ source compatibility changes use the next minor version under the policy.
81
+
76
82
  ## Preparing a release
77
83
 
78
84
  Choose the version explicitly. For the 0.2 line, start at 0.2.0. A stable candidate can use its final version on the `next` dist-tag, then be checked by exact source revision and tarball SHA-256 before the same version is promoted to `latest`. No `-next.N` or `-rc.N` version is required; use a separate prerelease version only when it is useful for a distinct candidate. Package-proof versions are local artefacts and cannot be staged.
@@ -8,6 +8,12 @@ Commonlib separates three values which older integrations commonly treated as on
8
8
 
9
9
  `DEFAULT_SETTINGS` remains an alias of `SETTINGS_SCHEMA_DEFAULTS` for compatibility. New code should choose the named contract which matches its operation.
10
10
 
11
+ ## Plaintext acceptance setting (Commonlib 0.4.3)
12
+
13
+ Available in [Commonlib 0.4.3](https://www.npmjs.com/package/@vrtmrz/livesync-commonlib/v/0.4.3). The corresponding Self-hosted LiveSync dialogue changes are available in [Self-hosted LiveSync 1.0.49](https://github.com/vrtmrz/obsidian-livesync/releases/tag/1.0.49).
14
+
15
+ The `acceptUnencryptedContent` setting defaults to `false`; only the boolean value `true` enables it. With E2EE enabled, it permits receipt of unencrypted file content from third-party tools which do not use the E2EE passphrase. Content sent by the plug-in remains encrypted. Complete Setup URI and QR imports normalise a missing or invalid value to `false`. Settings Markdown includes the value regardless of credential-sharing choice; a partial Markdown import preserves the current value when the field is absent and treats an explicitly invalid value as `false`.
16
+
11
17
  ## Starting a new Vault
12
18
 
13
19
  Use `createNewVaultSettings()` only when the settings store is absent or empty, or when the user explicitly requests a factory reset. `NEW_VAULT_SETTINGS` exposes the values for inspection, while the factory prevents mutable nested settings from being shared between clients:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vrtmrz/livesync-commonlib",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "description": "Shared data, storage, and replication primitives for Self-hosted LiveSync clients.",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",