core-3nweb-client-lib 0.52.0 → 0.52.1

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.
@@ -34,6 +34,7 @@ export declare class InboxEvents {
34
34
  constructor(msgReceiver: MailRecipient, getMsg: (msgId: string) => Promise<IncomingMessage>, listNewMsgs: (fromTS: number) => Promise<MsgInfo[]>, rmMsg: (msgId: string) => Promise<void>, logError: LogError);
35
35
  private makeProc;
36
36
  whenConnected(): Promise<void>;
37
+ isConnected(): boolean;
37
38
  private getMessage;
38
39
  subscribe<T>(event: InboxEventType, observer: Observer<T>): () => void;
39
40
  close(): void;
@@ -87,6 +87,9 @@ class InboxEvents {
87
87
  async whenConnected() {
88
88
  return this.msgReceiver.connectedState.whenStateIsSet();
89
89
  }
90
+ isConnected() {
91
+ return this.msgReceiver.connectedState.isSet();
92
+ }
90
93
  getMessage(msgId) {
91
94
  return this.getMsg(msgId).catch(async (exc) => {
92
95
  if ((exc.type === 'connect') || (exc.type === 'inbox')) {
@@ -30,6 +30,8 @@ const msg_downloader_1 = require("./msg-downloader");
30
30
  const cached_msgs_1 = require("./cached-msgs");
31
31
  const timed_cache_1 = require("../../../lib-common/timed-cache");
32
32
  const fs_sync_utils_1 = require("../../../lib-client/fs-utils/fs-sync-utils");
33
+ const periodic_trigger_1 = require("../../../lib-common/periodic-trigger");
34
+ const CONNECTION_CHECK_WAIT_SECS = 30;
33
35
  const MSG_INDEX_FOLDER = 'msg-index';
34
36
  async function makeInboxOnServer(cachePath, syncedFS, localFS, r) {
35
37
  const procs = new synced_1.NamedProcs();
@@ -43,7 +45,10 @@ async function makeInboxOnServer(cachePath, syncedFS, localFS, r) {
43
45
  const cache = await cached_msgs_1.CachedMessages.makeFor(cachePath, downloader, r.logError);
44
46
  const index = await (0, msg_indexing_1.makeMsgIndex)(indexSyncedFS, indexLocalFS, r.logError);
45
47
  const inboxEvents = new inbox_events_1.InboxEvents(msgReceiver, getMsg, listNewMsgs, removeMsg, r.logError);
48
+ let stopConnectionCheckingProc = (0, periodic_trigger_1.startPeriodicConditionalTriggerProc)(() => !inboxEvents.isConnected(), () => inboxEvents.resumeNetworkActivity(), CONNECTION_CHECK_WAIT_SECS);
46
49
  async function close() {
50
+ stopConnectionCheckingProc === null || stopConnectionCheckingProc === void 0 ? void 0 : stopConnectionCheckingProc();
51
+ stopConnectionCheckingProc = undefined;
47
52
  index.stopSyncing();
48
53
  inboxEvents.close();
49
54
  }
@@ -24,6 +24,7 @@ export declare class RemoteEvents {
24
24
  startListening(): void;
25
25
  close(): Promise<void>;
26
26
  whenConnected(): Promise<void>;
27
+ isConnected(): boolean;
27
28
  private absorbObjChange;
28
29
  private absorbObjRemoval;
29
30
  private absorbObjVersionArchival;
@@ -77,6 +77,9 @@ class RemoteEvents {
77
77
  whenConnected() {
78
78
  return this.remoteStorage.connectedState.whenStateIsSet();
79
79
  }
80
+ isConnected() {
81
+ return this.remoteStorage.connectedState.isSet();
82
+ }
80
83
  absorbObjChange(client) {
81
84
  return (new rxjs_1.Observable(obs => client.subscribe(owner_1.events.objChanged.EVENT_NAME, obs)))
82
85
  .pipe((0, operators_1.mergeMap)(async ({ newVer: newRemoteVersion, objId }) => {
@@ -25,6 +25,7 @@ export declare class SyncedStore implements SyncedStorage {
25
25
  private readonly remoteEvents;
26
26
  private readonly uploader;
27
27
  private readonly events;
28
+ private stopConnectionCheckingProc;
28
29
  private constructor();
29
30
  static makeAndStart(path: string, user: string, getSigner: IGetMailerIdSigner, getStorages: StorageGetter, cryptor: AsyncSBoxCryptor, random: AsyncRNG, remoteServiceUrl: () => Promise<string>, net: NetClient, logError: LogError): Promise<{
30
31
  syncedStore: SyncedStorage;
@@ -65,5 +66,6 @@ export declare class SyncedStore implements SyncedStorage {
65
66
  resumeNetworkActivity(): void;
66
67
  get connectionEvent$(): Observable<import("./remote-events").StorageConnectionStatus>;
67
68
  whenConnected(): Promise<void>;
69
+ private startConnectionCheckingProc;
68
70
  }
69
71
  export {};
@@ -27,6 +27,8 @@ const remote_events_1 = require("./remote-events");
27
27
  const upsyncer_1 = require("./upsyncer");
28
28
  const rxjs_1 = require("rxjs");
29
29
  const utils_for_observables_1 = require("../../../lib-common/utils-for-observables");
30
+ const periodic_trigger_1 = require("../../../lib-common/periodic-trigger");
31
+ const CONNECTION_CHECK_WAIT_SECS = 30;
30
32
  class SyncedStore {
31
33
  constructor(files, remoteStorage, getStorages, cryptor, random, logError) {
32
34
  this.files = files;
@@ -39,6 +41,7 @@ class SyncedStore {
39
41
  this.versioned = true;
40
42
  this.nodes = new common_1.NodesContainer();
41
43
  this.events = new utils_for_observables_1.Broadcast();
44
+ this.stopConnectionCheckingProc = undefined;
42
45
  this.remoteEvents = new remote_events_1.RemoteEvents(this.remoteStorage, this.files, this.broadcastNodeEvent.bind(this), this.logError);
43
46
  this.uploader = new upsyncer_1.UpSyncer(this.remoteStorage, this.logError);
44
47
  Object.seal(this);
@@ -52,6 +55,7 @@ class SyncedStore {
52
55
  syncedStore: (0, common_1.wrapSyncStorageImplementation)(s),
53
56
  startObjProcs: () => {
54
57
  s.remoteEvents.startListening();
58
+ s.startConnectionCheckingProc();
55
59
  }
56
60
  };
57
61
  }
@@ -65,6 +69,7 @@ class SyncedStore {
65
69
  setMid(getSigner);
66
70
  s.uploader.start();
67
71
  s.remoteEvents.startListening();
72
+ s.startConnectionCheckingProc();
68
73
  }
69
74
  };
70
75
  }
@@ -229,7 +234,9 @@ class SyncedStore {
229
234
  return obj.getNumOfBytesNeedingDownload(version);
230
235
  }
231
236
  async close() {
237
+ var _a;
232
238
  try {
239
+ (_a = this.stopConnectionCheckingProc) === null || _a === void 0 ? void 0 : _a.call(this);
233
240
  await this.uploader.stop();
234
241
  this.events.done();
235
242
  await this.remoteEvents.close();
@@ -251,6 +258,12 @@ class SyncedStore {
251
258
  whenConnected() {
252
259
  return this.remoteStorage.connectedState.whenStateIsSet();
253
260
  }
261
+ startConnectionCheckingProc() {
262
+ if (this.stopConnectionCheckingProc) {
263
+ this.stopConnectionCheckingProc();
264
+ }
265
+ this.stopConnectionCheckingProc = (0, periodic_trigger_1.startPeriodicConditionalTriggerProc)(() => !this.remoteStorage.connectedState.isSet(), () => this.remoteEvents.resumeNetworkActivity(), CONNECTION_CHECK_WAIT_SECS);
266
+ }
254
267
  }
255
268
  exports.SyncedStore = SyncedStore;
256
269
  Object.freeze(SyncedStore.prototype);
@@ -1,6 +1,7 @@
1
1
  export declare class AwaitableState {
2
2
  private deferredStateSetPoint;
3
3
  constructor();
4
+ isSet(): boolean;
4
5
  setState(): void;
5
6
  clearState(): void;
6
7
  whenStateIsSet(): Promise<void>;
@@ -23,6 +23,9 @@ class AwaitableState {
23
23
  this.deferredStateSetPoint = (0, deferred_1.defer)();
24
24
  Object.seal(this);
25
25
  }
26
+ isSet() {
27
+ return !this.deferredStateSetPoint;
28
+ }
26
29
  setState() {
27
30
  if (this.deferredStateSetPoint) {
28
31
  this.deferredStateSetPoint.resolve();
@@ -0,0 +1 @@
1
+ export declare function startPeriodicConditionalTriggerProc(shouldTrigger: () => boolean, trigger: () => void, timeoutSecond: number): (() => void);
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (C) 2026 3NSoft Inc.
4
+
5
+ This program is free software: you can redistribute it and/or modify it under
6
+ the terms of the GNU General Public License as published by the Free Software
7
+ Foundation, either version 3 of the License, or (at your option) any later
8
+ version.
9
+
10
+ This program is distributed in the hope that it will be useful, but
11
+ WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
+ See the GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License along with
16
+ this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.startPeriodicConditionalTriggerProc = startPeriodicConditionalTriggerProc;
20
+ function startPeriodicConditionalTriggerProc(shouldTrigger, trigger, timeoutSecond) {
21
+ let checkActive = true;
22
+ function checkAndTrigger() {
23
+ if (!checkActive) {
24
+ return;
25
+ }
26
+ if (shouldTrigger()) {
27
+ trigger();
28
+ }
29
+ setNext();
30
+ }
31
+ let triggerTime = undefined;
32
+ function setNext() {
33
+ var _a;
34
+ triggerTime = setTimeout(checkAndTrigger, timeoutSecond * 1000);
35
+ if (typeof triggerTime === 'object') {
36
+ (_a = triggerTime.unref) === null || _a === void 0 ? void 0 : _a.call(triggerTime);
37
+ }
38
+ }
39
+ return () => {
40
+ checkActive = false;
41
+ clearTimeout(triggerTime);
42
+ };
43
+ }
44
+ Object.freeze(exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.52.0",
3
+ "version": "0.52.1",
4
4
  "description": "3NWeb client core library, embeddable into different environments",
5
5
  "main": "build/lib-index.js",
6
6
  "types": "build/lib-index.d.ts",