core-3nweb-client-lib 0.42.15 → 0.42.16

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.
@@ -11,9 +11,9 @@ export declare class Msg {
11
11
  readonly r: ResourcesForSending;
12
12
  readonly progress: DeliveryProgress;
13
13
  private readonly msgFS;
14
+ private static readonly progressSavingProcs;
14
15
  private readonly sendingProc;
15
16
  private completionPromise;
16
- private readonly progressSavingProc;
17
17
  private cancelled;
18
18
  private sender;
19
19
  private recipients;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2016 - 2018, 2020, 2023 3NSoft Inc.
3
+ Copyright (C) 2016 - 2018, 2020, 2023, 2025 3NSoft Inc.
4
4
 
5
5
  This program is free software: you can redistribute it and/or modify it under
6
6
  the terms of the GNU General Public License as published by the Free Software
@@ -65,7 +65,7 @@ class Msg {
65
65
  this.msgFS = msgFS;
66
66
  this.sendingProc = new synced_1.SingleProc();
67
67
  this.completionPromise = undefined;
68
- this.progressSavingProc = new synced_1.SingleProc();
68
+ // private readonly progressSavingProc = new SingleProc();
69
69
  this.cancelled = false;
70
70
  this.sender = undefined;
71
71
  this.recipients = undefined;
@@ -101,7 +101,9 @@ class Msg {
101
101
  return msg;
102
102
  }
103
103
  static async forRestart(id, msgFS, r) {
104
- const progress = await msgFS.readJSONFile(PROGRESS_INFO_FILE_NAME);
104
+ const progress = await Msg.progressSavingProcs.startOrChain(id, async () => {
105
+ return await msgFS.readJSONFile(PROGRESS_INFO_FILE_NAME);
106
+ });
105
107
  if (progress.allDone) {
106
108
  return new Msg(id, undefined, progress, undefined);
107
109
  }
@@ -148,11 +150,13 @@ class Msg {
148
150
  this.r.notifyMsgProgress(this.id, (0, json_utils_1.copy)(this.progress));
149
151
  this.progressPublisher.next((0, json_utils_1.copy)(this.progress));
150
152
  if (saveProgress) {
151
- this.progressSavingProc.startOrChain(() => this.msgFS.writeJSONFile(PROGRESS_INFO_FILE_NAME, this.progress, {}));
153
+ Msg.progressSavingProcs.startOrChain(this.id, async () => {
154
+ await this.msgFS.writeJSONFile(PROGRESS_INFO_FILE_NAME, this.progress, {});
155
+ });
152
156
  }
153
157
  if (this.isDone()) {
154
158
  this.progressPublisher.complete();
155
- this.progressSavingProc.startOrChain(async () => {
159
+ Msg.progressSavingProcs.startOrChain(this.id, async () => {
156
160
  await this.msgFS.deleteFile(WIPS_INFO_FILE_NAME).catch(noop);
157
161
  if (this.attachments) {
158
162
  await this.attachments.deleteFrom(this.msgFS);
@@ -160,7 +164,7 @@ class Msg {
160
164
  });
161
165
  }
162
166
  else if (saveWIPs) {
163
- this.progressSavingProc.startOrChain(async () => {
167
+ Msg.progressSavingProcs.startOrChain(this.id, async () => {
164
168
  await this.msgFS.writeJSONFile(WIPS_INFO_FILE_NAME, this.wipsInfo);
165
169
  });
166
170
  }
@@ -227,7 +231,7 @@ class Msg {
227
231
  return;
228
232
  }
229
233
  this.cancelled = true;
230
- const filesProc = this.progressSavingProc.latestTaskAtThisMoment();
234
+ const filesProc = Msg.progressSavingProcs.latestTaskAtThisMoment(this.id);
231
235
  if (!filesProc) {
232
236
  return;
233
237
  }
@@ -341,6 +345,7 @@ class Msg {
341
345
  }
342
346
  }
343
347
  exports.Msg = Msg;
348
+ Msg.progressSavingProcs = new synced_1.NamedProcs();
344
349
  Object.freeze(Msg.prototype);
345
350
  Object.freeze(Msg);
346
351
  function noop() { }
@@ -89,9 +89,9 @@ class MailRecipient extends user_with_mid_session_1.ServiceUser {
89
89
  responseType: 'json'
90
90
  });
91
91
  if (rep.status === api.msgMetadata.SC.ok) {
92
- const meta = api.sanitizedMeta(rep.data);
92
+ const { meta, errMsg } = api.sanitizedMeta(rep.data);
93
93
  if (!meta) {
94
- throw (0, request_utils_1.makeException)(rep, 'Malformed response');
94
+ throw (0, request_utils_1.makeException)(rep, `Malformed message metadata in a server response: ${errMsg}`);
95
95
  }
96
96
  return meta;
97
97
  }
@@ -75,7 +75,10 @@ export declare namespace msgMetadata {
75
75
  * passes as message meta, or undefined, otherwise.
76
76
  * @param meta is an object that is expected to be message meta
77
77
  */
78
- export declare function sanitizedMeta(meta: MsgMeta): MsgMeta | undefined;
78
+ export declare function sanitizedMeta(meta: MsgMeta): {
79
+ meta?: MsgMeta;
80
+ errMsg?: string;
81
+ };
79
82
  export interface GetObjQueryOpts {
80
83
  /**
81
84
  * This is a boolean flag, which true value indicates that header should be
@@ -97,23 +97,22 @@ Object.freeze(msgMetadata);
97
97
  */
98
98
  function sanitizedMeta(meta) {
99
99
  if (typeof meta !== 'object') {
100
- return;
100
+ return { errMsg: `is not a json object: ${JSON.stringify(meta)}` };
101
101
  }
102
102
  if (typeof meta.objs !== 'object') {
103
- return;
103
+ return { errMsg: `objs field is not an object in: ${JSON.stringify(meta)}` };
104
104
  }
105
105
  for (const objId of Object.keys(meta.objs)) {
106
106
  const st = meta.objs[objId];
107
107
  if (typeof st.size.header !== 'number') {
108
- return;
108
+ return { errMsg: `obj's header is not a number in: ${JSON.stringify(meta)}` };
109
109
  }
110
- if (st.completed &&
111
- (st.size.segments === undefined)) {
112
- return;
110
+ if (st.completed && (st.size.segments === undefined)) {
111
+ return { errMsg: `obj's segments is not a number in: ${JSON.stringify(meta)}` };
113
112
  }
114
113
  }
115
114
  // TODO add more checks and return new object instead of a given one
116
- return meta;
115
+ return { meta };
117
116
  }
118
117
  var msgObj;
119
118
  (function (msgObj) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "core-3nweb-client-lib",
3
- "version": "0.42.15",
3
+ "version": "0.42.16",
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",