@vrtmrz/livesync-commonlib 0.1.17 → 0.1.19-rc.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 (46) hide show
  1. package/dist/API/DirectFileManipulatorV2.js +3 -1
  2. package/dist/common/ConnectionString.js +9 -1
  3. package/dist/common/models/fileaccess.type.d.ts +7 -0
  4. package/dist/common/models/setting.const.d.ts +18 -0
  5. package/dist/common/models/setting.const.defaults.js +10 -1
  6. package/dist/common/models/setting.const.js +12 -0
  7. package/dist/common/models/setting.const.qr.js +3 -1
  8. package/dist/common/models/setting.p2p.d.ts +21 -0
  9. package/dist/common/models/setting.p2p.js +35 -0
  10. package/dist/common/models/setting.type.d.ts +11 -1
  11. package/dist/common/models/shared.definition.configNames.js +8 -0
  12. package/dist/common/models/tweak.definition.d.ts +2 -0
  13. package/dist/common/settingConstants.d.ts +2 -0
  14. package/dist/common/types.d.ts +5 -3
  15. package/dist/common/types.js +17 -1
  16. package/dist/common/utils.js +4 -1
  17. package/dist/interfaces/DatabaseRebuilder.d.ts +4 -2
  18. package/dist/managers/StorageEventManager.d.ts +16 -5
  19. package/dist/managers/StorageEventManager.js +46 -8
  20. package/dist/pouchdb/LiveSyncLocalDB.d.ts +7 -1
  21. package/dist/pouchdb/LiveSyncLocalDB.js +120 -38
  22. package/dist/replication/trystero/LiveSyncTrysteroReplicator.d.ts +8 -0
  23. package/dist/replication/trystero/LiveSyncTrysteroReplicator.js +36 -8
  24. package/dist/replication/trystero/TrysteroReplicatorP2PServer.js +2 -2
  25. package/dist/rpc/transports/TrysteroTransport.d.ts +2 -0
  26. package/dist/rpc/transports/TrysteroTransport.js +18 -2
  27. package/dist/rpc/transports/trysteroUtils.js +12 -1
  28. package/dist/serviceFeatures/prepareDatabaseForUse.js +18 -15
  29. package/dist/serviceModules/Rebuilder.d.ts +27 -4
  30. package/dist/serviceModules/Rebuilder.js +113 -35
  31. package/dist/serviceModules/ServiceFileHandlerBase.d.ts +17 -0
  32. package/dist/serviceModules/ServiceFileHandlerBase.js +145 -9
  33. package/dist/services/base/DatabaseService.d.ts +11 -3
  34. package/dist/services/base/DatabaseService.js +63 -7
  35. package/dist/services/base/IService.d.ts +1 -0
  36. package/dist/services/base/ReplicationService.d.ts +16 -0
  37. package/dist/services/base/ReplicationService.js +36 -4
  38. package/dist/services/base/ReplicatorService.d.ts +1 -0
  39. package/dist/services/base/ReplicatorService.js +32 -13
  40. package/dist/worker/bgWorker.js +1 -1
  41. package/docs/development.md +2 -0
  42. package/docs/p2p-transport-lifecycle.md +4 -2
  43. package/docs/proven-in-use.md +5 -1
  44. package/docs/releasing.md +24 -0
  45. package/docs/remote-configurations.md +2 -0
  46. package/package.json +1 -1
@@ -186,8 +186,7 @@ class ReplicationService extends ServiceBase {
186
186
  }
187
187
  return activeReplicator;
188
188
  }
189
- async replicateAllToRemote(showingNotice = false) {
190
- if (!this.appLifecycleService.isReady()) return false;
189
+ async performReplicateAllToRemote(showingNotice) {
191
190
  if (!await this.onBeforeReplicate(showingNotice)) {
192
191
  this._log(this.context.translate("Replicator.Message.SomeModuleFailed"), LOG_LEVEL_NOTICE);
193
192
  return false;
@@ -204,8 +203,7 @@ class ReplicationService extends ServiceBase {
204
203
  return await activeReplicator.replicateAllToServer(currentSettings, showingNotice);
205
204
  return !checkResult;
206
205
  }
207
- async replicateAllFromRemote(showingNotice = false) {
208
- if (!this.appLifecycleService.isReady()) return false;
206
+ async performReplicateAllFromRemote(showingNotice) {
209
207
  const activeReplicator = this.getActiveReplicatorFor("fetching data from remote");
210
208
  if (!activeReplicator) {
211
209
  return false;
@@ -218,6 +216,40 @@ class ReplicationService extends ServiceBase {
218
216
  return await activeReplicator.replicateAllFromServer(currentSettings, showingNotice);
219
217
  return !checkResult;
220
218
  }
219
+ async replicateAllToRemote(showingNotice = false) {
220
+ if (!this.appLifecycleService.isReady()) return false;
221
+ return await this.performReplicateAllToRemote(showingNotice);
222
+ }
223
+ async replicateAllFromRemote(showingNotice = false) {
224
+ if (!this.appLifecycleService.isReady()) return false;
225
+ return await this.performReplicateAllFromRemote(showingNotice);
226
+ }
227
+ /**
228
+ * Perform a full upload owned by an active rebuild while the physical database is ready.
229
+ *
230
+ * This concrete maintenance entry point is intentionally absent from `IReplicationService`;
231
+ * it is not a general application-readiness bypass.
232
+ */
233
+ async replicateAllToRemoteForRebuild(showingNotice = false) {
234
+ if (!this.databaseService.isDatabaseReady()) {
235
+ this._log("The selected local database is not ready for the rebuild upload.", LOG_LEVEL_NOTICE);
236
+ return false;
237
+ }
238
+ return await this.performReplicateAllToRemote(showingNotice);
239
+ }
240
+ /**
241
+ * Perform a full download owned by an active rebuild while the physical database is ready.
242
+ *
243
+ * This concrete maintenance entry point is intentionally absent from `IReplicationService`;
244
+ * it is not a general application-readiness bypass.
245
+ */
246
+ async replicateAllFromRemoteForRebuild(showingNotice = false) {
247
+ if (!this.databaseService.isDatabaseReady()) {
248
+ this._log("The selected local database is not ready for the rebuild download.", LOG_LEVEL_NOTICE);
249
+ return false;
250
+ }
251
+ return await this.performReplicateAllFromRemote(showingNotice);
252
+ }
221
253
  _getReplicatorAndPerform(action, perform) {
222
254
  const activeReplicator = this.getActiveReplicatorFor(action);
223
255
  if (!activeReplicator) {
@@ -39,6 +39,7 @@ export declare abstract class ReplicatorService<T extends ServiceContext = Servi
39
39
  private suspendReplication;
40
40
  private reinitialiseReplicator;
41
41
  private disposeReplicator;
42
+ private discardFailedReplicator;
42
43
  private _initialiseReplicator;
43
44
  /**
44
45
  * Close the active replication if any.
@@ -15,7 +15,10 @@ class ReplicatorService extends ServiceBase {
15
15
  super(context);
16
16
  this.dependencies = dependencies;
17
17
  this.appLifecycleService = dependencies.appLifecycleService;
18
- this._unresolvedErrorManager = new UnresolvedErrorManager(dependencies.appLifecycleService, this.context.events);
18
+ this._unresolvedErrorManager = new UnresolvedErrorManager(
19
+ dependencies.appLifecycleService,
20
+ this.context.events
21
+ );
19
22
  this.settingService = dependencies.settingService;
20
23
  this.databaseEventService = dependencies.databaseEventService;
21
24
  if (dependencies.registerLifecycleHandlers ?? true) {
@@ -83,6 +86,18 @@ class ReplicatorService extends ServiceBase {
83
86
  this._replicatorType = void 0;
84
87
  return true;
85
88
  }
89
+ async discardFailedReplicator(replicator) {
90
+ if (this._activeReplicator === replicator) {
91
+ this._activeReplicator = void 0;
92
+ this._replicatorType = void 0;
93
+ }
94
+ try {
95
+ await Promise.resolve(replicator.closeReplication());
96
+ } catch (error) {
97
+ this._log("Failed to close a replicator after its initialisation failed.", LOG_LEVEL_VERBOSE);
98
+ this._log(error, LOG_LEVEL_VERBOSE);
99
+ }
100
+ }
86
101
  async _initialiseReplicator() {
87
102
  const message = this.context.translate("Replicator.Message.InitialiseFatalError");
88
103
  const setting = this.settingService.currentSettings();
@@ -123,19 +138,23 @@ class ReplicatorService extends ServiceBase {
123
138
  this._replicatorType = replicatorType;
124
139
  this.replicationStatics.value = { ...DEFAULT_REPLICATION_STATICS };
125
140
  await yieldMicrotask();
126
- if (!await newReplicator.initializeDatabaseForReplication()) {
127
- this._log("Failed to initialise the replicator's local node information.");
128
- this._activeReplicator = void 0;
129
- this._replicatorType = void 0;
141
+ try {
142
+ if (!await newReplicator.initializeDatabaseForReplication()) {
143
+ this._log("Failed to initialise the replicator's local node information.");
144
+ await this.discardFailedReplicator(newReplicator);
145
+ this._unresolvedErrorManager.showError(message, LOG_LEVEL_NOTICE);
146
+ return false;
147
+ }
148
+ if (!await this.onReplicatorInitialised()) {
149
+ this._log("Failed to initialise the replicator, onReplicatorInitialised reported some problems.");
150
+ await this.discardFailedReplicator(newReplicator);
151
+ this._unresolvedErrorManager.showError(message, LOG_LEVEL_NOTICE);
152
+ return false;
153
+ }
154
+ } catch (error) {
155
+ await this.discardFailedReplicator(newReplicator);
130
156
  this._unresolvedErrorManager.showError(message, LOG_LEVEL_NOTICE);
131
- return false;
132
- }
133
- if (!await this.onReplicatorInitialised()) {
134
- this._log("Failed to initialise the replicator, onReplicatorInitialised reported some problems.");
135
- this._activeReplicator = void 0;
136
- this._replicatorType = void 0;
137
- this._unresolvedErrorManager.showError(message, LOG_LEVEL_NOTICE);
138
- return false;
157
+ throw error;
139
158
  }
140
159
  const remoteTypeDisplay = replicatorType === RemoteTypes.REMOTE_COUCHDB ? "CouchDB" : replicatorType;
141
160
  this._log(`Replicator (${remoteTypeDisplay}) initialised and activated`, LOG_LEVEL_VERBOSE);