core-3nweb-client-lib 0.25.3 → 0.26.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 (113) hide show
  1. package/README.md +2 -2
  2. package/build/api-defs/files.d.ts +23 -20
  3. package/build/core/asmail/config/common.js +2 -2
  4. package/build/core/asmail/delivery/index.js +4 -3
  5. package/build/core/asmail/delivery/msg.js +5 -4
  6. package/build/core/asmail/delivery/per-recipient-wip.js +2 -2
  7. package/build/core/asmail/inbox/attachments/fs.js +6 -0
  8. package/build/core/asmail/inbox/cached-msgs.js +2 -2
  9. package/build/core/asmail/inbox/inbox-events.js +2 -1
  10. package/build/core/asmail/inbox/index.js +2 -2
  11. package/build/core/asmail/inbox/msg-downloader.js +2 -2
  12. package/build/core/asmail/inbox/msg-indexing.js +3 -3
  13. package/build/core/asmail/inbox/msg-on-disk.js +2 -2
  14. package/build/core/asmail/keyring/keyring-storage.js +2 -2
  15. package/build/core/asmail/sending-params/own-params.js +2 -2
  16. package/build/core/asmail/sending-params/params-from-others.js +2 -2
  17. package/build/core/id-manager.js +2 -2
  18. package/build/core/sign-in.d.ts +5 -4
  19. package/build/core/sign-in.js +9 -11
  20. package/build/core/sign-up.d.ts +1 -0
  21. package/build/core/sign-up.js +7 -3
  22. package/build/core/storage/common/json-saving.d.ts +21 -0
  23. package/build/core/storage/common/json-saving.js +82 -0
  24. package/build/core/storage/common/obj-info-file.d.ts +43 -0
  25. package/build/core/storage/common/obj-info-file.js +119 -3
  26. package/build/core/storage/index.js +1 -1
  27. package/build/core/storage/local/obj-files-gc.js +8 -6
  28. package/build/core/storage/local/obj-files.d.ts +3 -3
  29. package/build/core/storage/local/obj-files.js +9 -9
  30. package/build/core/storage/local/obj-status.d.ts +9 -25
  31. package/build/core/storage/local/obj-status.js +28 -110
  32. package/build/core/storage/local/storage.d.ts +8 -1
  33. package/build/core/storage/local/storage.js +10 -2
  34. package/build/core/storage/synced/downloader.js +6 -5
  35. package/build/core/storage/synced/obj-files-gc.d.ts +1 -0
  36. package/build/core/storage/synced/obj-files-gc.js +44 -5
  37. package/build/core/storage/synced/obj-files.d.ts +13 -20
  38. package/build/core/storage/synced/obj-files.js +70 -48
  39. package/build/core/storage/synced/obj-status.d.ts +74 -15
  40. package/build/core/storage/synced/obj-status.js +291 -107
  41. package/build/core/storage/synced/remote-events.js +32 -26
  42. package/build/core/storage/synced/storage.d.ts +11 -1
  43. package/build/core/storage/synced/storage.js +28 -3
  44. package/build/core/storage/synced/upsyncer.d.ts +8 -7
  45. package/build/core/storage/synced/upsyncer.js +211 -163
  46. package/build/ipc-via-protobuf/asmail-cap.js +17 -34
  47. package/build/ipc-via-protobuf/connector-clients-side.js +2 -2
  48. package/build/ipc-via-protobuf/file.js +26 -18
  49. package/build/ipc-via-protobuf/fs.js +33 -35
  50. package/build/ipc-via-protobuf/mailerid.js +3 -2
  51. package/build/ipc-via-protobuf/protobuf-msg.d.ts +2 -0
  52. package/build/ipc-via-protobuf/protobuf-msg.js +11 -1
  53. package/build/ipc-via-protobuf/startup-cap.js +5 -5
  54. package/build/lib-client/3nstorage/exceptions.d.ts +9 -8
  55. package/build/lib-client/3nstorage/exceptions.js +18 -9
  56. package/build/lib-client/3nstorage/service.js +10 -6
  57. package/build/lib-client/3nstorage/xsp-fs/common.d.ts +18 -4
  58. package/build/lib-client/3nstorage/xsp-fs/common.js +6 -1
  59. package/build/lib-client/3nstorage/xsp-fs/file-node.js +3 -3
  60. package/build/lib-client/3nstorage/xsp-fs/file.js +4 -1
  61. package/build/lib-client/3nstorage/xsp-fs/folder-node.js +27 -13
  62. package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +11 -6
  63. package/build/lib-client/3nstorage/xsp-fs/fs.js +189 -58
  64. package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +4 -0
  65. package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +51 -24
  66. package/build/lib-client/3nstorage/xsp-fs/node-persistence.js +2 -2
  67. package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.js +2 -2
  68. package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.js +3 -3
  69. package/build/lib-client/cryptor/cryptor-in-worker.js +4 -4
  70. package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
  71. package/build/lib-client/cryptor/cryptor.wasm +0 -0
  72. package/build/lib-client/cryptor/in-proc-wasm.js +2 -2
  73. package/build/lib-client/files.js +2 -0
  74. package/build/lib-client/fs-collection.js +3 -2
  75. package/build/lib-client/logging/log-to-file.js +6 -14
  76. package/build/lib-client/objs-on-disk/file-writing-proc.js +2 -2
  77. package/build/lib-client/objs-on-disk/obj-folders.d.ts +12 -1
  78. package/build/lib-client/objs-on-disk/obj-folders.js +26 -19
  79. package/build/lib-client/request-utils.js +2 -2
  80. package/build/lib-client/server-events.js +4 -3
  81. package/build/lib-client/ws-utils.js +2 -2
  82. package/build/lib-common/async-fs-node.d.ts +6 -0
  83. package/build/lib-common/async-fs-node.js +28 -4
  84. package/build/lib-common/byte-streaming/wrapping.js +17 -17
  85. package/build/lib-common/exceptions/file.js +6 -1
  86. package/build/lib-common/ipc/generic-ipc.js +2 -2
  87. package/build/lib-common/json-utils.js +2 -1
  88. package/build/lib-common/objs-on-disk/obj-file.js +4 -3
  89. package/build/lib-common/objs-on-disk/utils.js +2 -2
  90. package/build/lib-common/processes/deferred.d.ts +6 -0
  91. package/build/lib-common/processes/deferred.js +30 -0
  92. package/build/lib-common/processes/labelled-exec-pools.d.ts +33 -0
  93. package/build/lib-common/processes/labelled-exec-pools.js +141 -0
  94. package/build/lib-common/processes/pressure.d.ts +7 -0
  95. package/build/lib-common/processes/pressure.js +56 -0
  96. package/build/lib-common/processes/sleep.d.ts +1 -0
  97. package/build/lib-common/processes/sleep.js +26 -0
  98. package/build/lib-common/{processes.d.ts → processes/synced.d.ts} +0 -40
  99. package/build/lib-common/{processes.js → processes/synced.js} +187 -204
  100. package/build/lib-common/processes/timeout.d.ts +1 -0
  101. package/build/lib-common/processes/timeout.js +51 -0
  102. package/build/lib-common/service-api/3nstorage/owner.d.ts +5 -4
  103. package/build/lib-common/service-api/3nstorage/owner.js +3 -2
  104. package/build/lib-common/utils-for-observables.d.ts +15 -1
  105. package/build/lib-common/utils-for-observables.js +68 -17
  106. package/build/protos/asmail.proto.js +404 -78
  107. package/build/protos/file.proto.js +370 -44
  108. package/build/protos/fs.proto.js +404 -78
  109. package/package.json +4 -4
  110. package/protos/file.proto +10 -2
  111. package/protos/fs.proto +2 -2
  112. package/build/core/storage/synced/upsync-status.d.ts +0 -41
  113. package/build/core/storage/synced/upsync-status.js +0 -158
@@ -16,14 +16,8 @@
16
16
  this program. If not, see <http://www.gnu.org/licenses/>.
17
17
  */
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.Worker = exports.callWithTimeout = exports.PressureValve = exports.defer = exports.makeSyncedFunc = exports.DeduppedRunner = exports.SingleProc = exports.NamedProcs = exports.sleep = void 0;
20
- const error_1 = require("./exceptions/error");
21
- function sleep(millis) {
22
- return new Promise((resolve) => {
23
- setTimeout(resolve, millis).unref();
24
- });
25
- }
26
- exports.sleep = sleep;
19
+ exports.makeSyncedFunc = exports.SingleProc = exports.NamedProcs = void 0;
20
+ const deferred_1 = require("./deferred");
27
21
  /**
28
22
  * This is a container of processes, labeled by some ids. It allows to track if
29
23
  * there is a process already in progress with a given id. And, it allows to
@@ -155,7 +149,7 @@ class SingleProc {
155
149
  }
156
150
  }
157
151
  startOrChain(action) {
158
- const deferred = defer();
152
+ const deferred = deferred_1.defer();
159
153
  this.actions.push({ action, deferred });
160
154
  this.runIfIdle();
161
155
  return deferred.promise;
@@ -164,52 +158,49 @@ class SingleProc {
164
158
  exports.SingleProc = SingleProc;
165
159
  Object.freeze(SingleProc.prototype);
166
160
  Object.freeze(SingleProc);
167
- class DeduppedRunner {
168
- constructor(action) {
169
- this.action = action;
170
- this.proc = undefined;
171
- this.waiting = undefined;
172
- Object.seal(this);
173
- }
174
- trigger() {
175
- if (this.proc) {
176
- if (!this.waiting) {
177
- this.waiting = defer();
178
- }
179
- return this.waiting.promise;
180
- }
181
- else {
182
- this.proc = this.startAction();
183
- return this.proc;
184
- }
185
- }
186
- async startAction() {
187
- const deferredBeforeStart = this.waiting;
188
- this.waiting = undefined;
189
- try {
190
- const result = await this.action();
191
- if (deferredBeforeStart) {
192
- deferredBeforeStart.resolve(result);
193
- }
194
- return result;
195
- }
196
- catch (err) {
197
- if (deferredBeforeStart) {
198
- deferredBeforeStart.reject(err);
199
- }
200
- throw err;
201
- }
202
- finally {
203
- this.proc = undefined;
204
- if (this.waiting) {
205
- this.proc = this.startAction();
206
- }
207
- }
208
- }
209
- }
210
- exports.DeduppedRunner = DeduppedRunner;
211
- Object.freeze(DeduppedRunner.prototype);
212
- Object.freeze(DeduppedRunner);
161
+ // export class DeduppedRunner<T> {
162
+ // private proc: Promise<T>|undefined = undefined;
163
+ // private waiting: Deferred<T>|undefined = undefined;
164
+ // constructor(
165
+ // private readonly action: Action<T>
166
+ // ) {
167
+ // Object.seal(this);
168
+ // }
169
+ // trigger(): Promise<T> {
170
+ // if (this.proc) {
171
+ // if (!this.waiting) {
172
+ // this.waiting = defer();
173
+ // }
174
+ // return this.waiting.promise;
175
+ // } else {
176
+ // this.proc = this.startAction();
177
+ // return this.proc;
178
+ // }
179
+ // }
180
+ // private async startAction(): Promise<T> {
181
+ // const deferredBeforeStart = this.waiting;
182
+ // this.waiting = undefined;
183
+ // try {
184
+ // const result = await this.action();
185
+ // if (deferredBeforeStart) {
186
+ // deferredBeforeStart.resolve(result);
187
+ // }
188
+ // return result;
189
+ // } catch (err) {
190
+ // if (deferredBeforeStart) {
191
+ // deferredBeforeStart.reject(err);
192
+ // }
193
+ // throw err;
194
+ // } finally {
195
+ // this.proc = undefined;
196
+ // if (this.waiting) {
197
+ // this.proc = this.startAction();
198
+ // }
199
+ // }
200
+ // }
201
+ // }
202
+ // Object.freeze(DeduppedRunner.prototype);
203
+ // Object.freeze(DeduppedRunner);
213
204
  /**
214
205
  * This wraps given function/method into syncing wrap.
215
206
  */
@@ -217,153 +208,145 @@ function makeSyncedFunc(syncProc, thisArg, func) {
217
208
  return ((...args) => syncProc.startOrChain(() => func.apply(thisArg, args)));
218
209
  }
219
210
  exports.makeSyncedFunc = makeSyncedFunc;
220
- function defer() {
221
- const d = {};
222
- d.promise = new Promise((resolve, reject) => {
223
- d.resolve = resolve;
224
- d.reject = reject;
225
- });
226
- Object.freeze(d);
227
- return d;
228
- }
229
- exports.defer = defer;
230
- class PressureValve {
231
- constructor() {
232
- this.stopper = undefined;
233
- this.pressure = async () => {
234
- if (!this.stopper) {
235
- return;
236
- }
237
- await this.stopper.promise;
238
- };
239
- Object.seal(this);
240
- }
241
- toggle(flag) {
242
- if (flag) {
243
- if (this.stopper) {
244
- return;
245
- }
246
- this.stopper = defer();
247
- }
248
- else {
249
- if (!this.stopper) {
250
- return;
251
- }
252
- this.stopper.resolve();
253
- this.stopper = undefined;
254
- }
255
- }
256
- pressWithError(err) {
257
- this.toggle(true);
258
- this.stopper.reject(error_1.errWithCause(err, `Backpressure error`));
259
- }
260
- }
261
- exports.PressureValve = PressureValve;
262
- Object.freeze(PressureValve.prototype);
263
- Object.freeze(PressureValve);
264
- function callWithTimeout(f, timeout, timeoutErr) {
265
- let isDone = false;
266
- const deferred = defer();
267
- f().then(res => {
268
- if (isDone) {
269
- return;
270
- }
271
- isDone = true;
272
- deferred.resolve(res);
273
- }, err => {
274
- if (isDone) {
275
- return;
276
- }
277
- isDone = true;
278
- deferred.reject(err);
279
- });
280
- sleep(timeout).then(() => {
281
- if (isDone) {
282
- return;
283
- }
284
- isDone = true;
285
- const err = timeoutErr();
286
- if (err) {
287
- deferred.reject(err);
288
- }
289
- });
290
- return deferred.promise;
291
- }
292
- exports.callWithTimeout = callWithTimeout;
293
- class Worker {
294
- constructor(process, stopPendingIn) {
295
- this.process = process;
296
- this.stopPendingIn = stopPendingIn;
297
- this.queue = [];
298
- this.set = new Set();
299
- this.isRunning = false;
300
- this.procs = [];
301
- this.maxProcs = 1;
302
- Object.seal(this);
303
- }
304
- add(w, queueIfNotRunning = false) {
305
- if (this.isRunning) {
306
- this.addToQueueOnce(w);
307
- this.runQueued();
308
- }
309
- else if (queueIfNotRunning) {
310
- this.addToQueueOnce(w);
311
- }
312
- }
313
- addToQueueOnce(w) {
314
- if (!this.set.has(w)) {
315
- this.queue.push(w);
316
- this.set.add(w);
317
- }
318
- }
319
- getFromQueueHead() {
320
- const w = this.queue.shift();
321
- if (!w) {
322
- return;
323
- }
324
- this.set.delete(w);
325
- return w;
326
- }
327
- async runQueued() {
328
- if (!this.isRunning || (this.procs.length >= this.maxProcs)) {
329
- return;
330
- }
331
- const w = this.getFromQueueHead();
332
- if (!w) {
333
- return;
334
- }
335
- const proc = this.process(w);
336
- this.procs.push(proc);
337
- try {
338
- await proc;
339
- }
340
- finally {
341
- const i = this.procs.indexOf(proc);
342
- if (i >= 0) {
343
- this.procs.splice(i, 1);
344
- }
345
- this.runQueued();
346
- }
347
- }
348
- start(maxNumOfProcs) {
349
- this.maxProcs = maxNumOfProcs;
350
- this.isRunning = true;
351
- this.runQueued();
352
- }
353
- pause() {
354
- this.isRunning = false;
355
- }
356
- async stop() {
357
- this.isRunning = false;
358
- const queue = this.queue.splice(0, this.queue.length);
359
- this.set.clear();
360
- await this.stopPendingIn(queue);
361
- while (this.procs.length > 0) {
362
- await this.procs.pop();
363
- }
364
- }
365
- }
366
- exports.Worker = Worker;
367
- Object.freeze(Worker.prototype);
368
- Object.freeze(Worker);
211
+ // export interface Deferred<T> {
212
+ // promise: Promise<T>;
213
+ // resolve: (result?: T|PromiseLike<T>) => void;
214
+ // reject: (err: any) => void;
215
+ // }
216
+ // export function defer<T>(): Deferred<T> {
217
+ // const d = <Deferred<T>> {};
218
+ // d.promise = new Promise<T>((resolve, reject) => {
219
+ // d.resolve = resolve;
220
+ // d.reject = reject;
221
+ // });
222
+ // Object.freeze(d);
223
+ // return d;
224
+ // }
225
+ // export class PressureValve {
226
+ // private stopper: Deferred<void>|undefined = undefined;
227
+ // constructor() {
228
+ // Object.seal(this);
229
+ // }
230
+ // toggle(flag: boolean): void {
231
+ // if (flag) {
232
+ // if (this.stopper) { return; }
233
+ // this.stopper = defer();
234
+ // } else {
235
+ // if (!this.stopper) { return; }
236
+ // this.stopper.resolve();
237
+ // this.stopper = undefined;
238
+ // }
239
+ // }
240
+ // pressWithError(err: any): void {
241
+ // this.toggle(true);
242
+ // this.stopper!.reject(errWithCause(err, `Backpressure error`));
243
+ // }
244
+ // readonly pressure = async (): Promise<void> => {
245
+ // if (!this.stopper) { return; }
246
+ // await this.stopper.promise;
247
+ // }
248
+ // }
249
+ // Object.freeze(PressureValve.prototype);
250
+ // Object.freeze(PressureValve);
251
+ // export function callWithTimeout<T>(
252
+ // f: () => Promise<T>, timeout: number, timeoutErr: () => any
253
+ // ): Promise<T> {
254
+ // let isDone = false;
255
+ // const deferred = defer<T>();
256
+ // f().then(res => {
257
+ // if (isDone) { return; }
258
+ // isDone = true;
259
+ // deferred.resolve(res);
260
+ // }, err => {
261
+ // if (isDone) { return; }
262
+ // isDone = true;
263
+ // deferred.reject(err);
264
+ // });
265
+ // sleep(timeout).then(() => {
266
+ // if (isDone) { return; }
267
+ // isDone = true;
268
+ // const err = timeoutErr();
269
+ // if (err) {
270
+ // deferred.reject(err);
271
+ // }
272
+ // });
273
+ // return deferred.promise;
274
+ // }
275
+ // export interface WorkerTask<WorkerLabel extends string> {
276
+ // neededWorker(): WorkerLabel|undefined;
277
+ // process(): Promise<void>;
278
+ // cancel(): Promise<void>;
279
+ // }
280
+ // interface Worker {
281
+ // readonly procs: Promise<void>[];
282
+ // readonly maxProcs: number;
283
+ // }
284
+ // export class QueueAndWorkers<WorkerLabel extends string> {
285
+ // private readonly queue: WorkerTask<WorkerLabel>[] = [];
286
+ // private readonly workers = new Map<WorkerLabel, Worker>();
287
+ // // private readonly set = new Set<WorkerTask>();
288
+ // private isRunning = false;
289
+ // // private readonly procs: Promise<void>[] = [];
290
+ // // private maxProcs = 1;
291
+ // constructor() {
292
+ // Object.seal(this);
293
+ // }
294
+ // add(w: WorkerTask<WorkerLabel>, queueIfNotRunning = false): void {
295
+ // if (this.isRunning) {
296
+ // this.queue.push();
297
+ // this.processNextQueued();
298
+ // } else if (queueIfNotRunning) {
299
+ // this.addToQueueOnce(w);
300
+ // }
301
+ // }
302
+ // private addToQueueOnce(w: WorkerTask<WorkerLabel>): void {
303
+ // if (!this.set.has(w)) {
304
+ // this.queue.push(w);
305
+ // this.set.add(w);
306
+ // }
307
+ // }
308
+ // private getFromQueueHead(): WorkerTask<WorkerLabel>|undefined {
309
+ // const w = this.queue.shift();
310
+ // if (!w) { return; }
311
+ // this.set.delete(w);
312
+ // return w;
313
+ // }
314
+ // private async processNextQueued(): Promise<void> {
315
+ // if (!this.isRunning || (this.procs.length >= this.maxProcs)) { return; }
316
+ // const w = this.getFromQueueHead();
317
+ // if (!w) { return; }
318
+ // const proc = w.process();
319
+ // this.procs.push(proc);
320
+ // try {
321
+ // await proc;
322
+ // } finally {
323
+ // const i = this.procs.indexOf(proc);
324
+ // if (i >= 0) {
325
+ // this.procs.splice(i, 1);
326
+ // }
327
+ // this.processNextQueued();
328
+ // }
329
+ // }
330
+ // start(maxNumOfProcs = 1): void {
331
+ // this.maxProcs = maxNumOfProcs;
332
+ // this.isRunning = true;
333
+ // this.processNextQueued();
334
+ // }
335
+ // pause(): void {
336
+ // this.isRunning = false;
337
+ // }
338
+ // async stop(): Promise<void> {
339
+ // this.isRunning = false;
340
+ // const queue = this.queue.splice(0, this.queue.length);
341
+ // this.set.clear();
342
+ // for (const w of queue) {
343
+ // await w.cancel();
344
+ // }
345
+ // while (this.procs.length > 0) {
346
+ // await this.procs.pop();
347
+ // }
348
+ // }
349
+ // }
350
+ // Object.freeze(Worker.prototype);
351
+ // Object.freeze(Worker);
369
352
  Object.freeze(exports);
@@ -0,0 +1 @@
1
+ export declare function callWithTimeout<T>(f: () => Promise<T>, timeout: number, timeoutErr: () => any): Promise<T>;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ /*
3
+ Copyright (C) 2015, 2017, 2019 - 2022 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.callWithTimeout = void 0;
20
+ const deferred_1 = require("./deferred");
21
+ const sleep_1 = require("./sleep");
22
+ function callWithTimeout(f, timeout, timeoutErr) {
23
+ let isDone = false;
24
+ const deferred = deferred_1.defer();
25
+ f().then(res => {
26
+ if (isDone) {
27
+ return;
28
+ }
29
+ isDone = true;
30
+ deferred.resolve(res);
31
+ }, err => {
32
+ if (isDone) {
33
+ return;
34
+ }
35
+ isDone = true;
36
+ deferred.reject(err);
37
+ });
38
+ sleep_1.sleep(timeout).then(() => {
39
+ if (isDone) {
40
+ return;
41
+ }
42
+ isDone = true;
43
+ const err = timeoutErr();
44
+ if (err) {
45
+ deferred.reject(err);
46
+ }
47
+ });
48
+ return deferred.promise;
49
+ }
50
+ exports.callWithTimeout = callWithTimeout;
51
+ Object.freeze(exports);
@@ -67,10 +67,11 @@ export interface GetObjQueryOpts {
67
67
  }
68
68
  export interface PutObjFirstQueryOpts {
69
69
  /**
70
- * This is a new object version parameter. When it is 1 (one), new object
71
- * should be created. If it is greater than one, changes are accepted only
72
- * when a current version on the server is (ver-1), ensuring that a client
73
- * knows current version on server to advance it.
70
+ * This is a flag to indicate that new object should be created.
71
+ */
72
+ create?: boolean;
73
+ /**
74
+ * This parameter is object's new version.
74
75
  */
75
76
  ver: number;
76
77
  /**
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2015 - 2017, 2019 3NSoft Inc.
3
+ Copyright (C) 2015 - 2017, 2019, 2022 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
@@ -13,7 +13,8 @@
13
13
  See the GNU General Public License for more details.
14
14
 
15
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/>. */
16
+ this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
17
18
  Object.defineProperty(exports, "__esModule", { value: true });
18
19
  exports.objRemoved = exports.objChanged = exports.wsEventChannel = exports.archiveRoot = exports.archiveObj = exports.cancelRootTransaction = exports.cancelTransaction = exports.addDiffSectionTo = exports.sanitizedDiff = exports.archivedRootVersion = exports.archivedObjVersion = exports.currentRootObj = exports.currentObj = exports.keyDerivParams = exports.PARAM_SC = exports.sessionParams = exports.closeSession = exports.midLogin = exports.BIN_TYPE = exports.HTTP_HEADER = exports.ERR_SC = void 0;
19
20
  /**
@@ -1,4 +1,4 @@
1
- import { Observable } from 'rxjs';
1
+ import { Observable, PartialObserver } from 'rxjs';
2
2
  /**
3
3
  * This is a pipeable operator that runs given async process on completion and
4
4
  * sends result downstream, followed by complete signal.
@@ -22,3 +22,17 @@ export declare function allowOnlySingleStart<T>(): (src: Observable<T>) => Obser
22
22
  * @param onComplete
23
23
  */
24
24
  export declare function flatTap<T>(onNext: ((x: T) => Promise<void>) | undefined | null, onError?: ((err: any) => Promise<void>) | undefined | null, onComplete?: (() => Promise<void>) | undefined | null): (src: Observable<T>) => Observable<T>;
25
+ /**
26
+ * @param obs
27
+ * @return given observer, or one with noop's in place of missing functions
28
+ */
29
+ export declare function toRxObserver<T>(obs: web3n.Observer<T>): PartialObserver<T>;
30
+ export declare class Broadcast<T> {
31
+ private readonly src;
32
+ readonly event$: Observable<T>;
33
+ private sub;
34
+ constructor();
35
+ next(ev: T): void;
36
+ done(err?: any): void;
37
+ isON(): boolean;
38
+ }
@@ -1,14 +1,15 @@
1
1
  "use strict";
2
2
  /*
3
- Copyright (C) 2017, 2019 - 2020 3NSoft Inc.
3
+ Copyright (C) 2017, 2019 - 2020, 2022 3NSoft Inc.
4
4
 
5
5
  This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
6
6
 
7
7
  This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
8
8
 
9
- You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */
9
+ You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
10
+ */
10
11
  Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.flatTap = exports.allowOnlySingleStart = exports.flatMapComplete = void 0;
12
+ exports.Broadcast = exports.toRxObserver = exports.flatTap = exports.allowOnlySingleStart = exports.flatMapComplete = void 0;
12
13
  const rxjs_1 = require("rxjs");
13
14
  const operators_1 = require("rxjs/operators");
14
15
  /**
@@ -18,14 +19,12 @@ const operators_1 = require("rxjs/operators");
18
19
  */
19
20
  function flatMapComplete(mapCompletion) {
20
21
  return src => new rxjs_1.Observable(downstream => src.subscribe({
21
- next(x) { downstream.next(x); },
22
- error(err) { downstream.error(err); },
23
- complete() {
24
- mapCompletion().then(mapped => {
25
- downstream.next(mapped);
26
- downstream.complete();
27
- }, err => downstream.error(err));
28
- }
22
+ next: x => downstream.next(x),
23
+ error: err => downstream.error(err),
24
+ complete: () => mapCompletion().then(mapped => {
25
+ downstream.next(mapped);
26
+ downstream.complete();
27
+ }, err => downstream.error(err))
29
28
  }));
30
29
  }
31
30
  exports.flatMapComplete = flatMapComplete;
@@ -55,12 +54,15 @@ function allowOnlySingleStart() {
55
54
  }
56
55
  else {
57
56
  wasStarted = true;
58
- return src.pipe(operators_1.tap(undefined, e => {
59
- isComplete = true;
60
- err = e;
61
- }, () => {
62
- isComplete = true;
63
- okCompletion = true;
57
+ return src.pipe(operators_1.tap({
58
+ error: e => {
59
+ isComplete = true;
60
+ err = e;
61
+ },
62
+ complete: () => {
63
+ isComplete = true;
64
+ okCompletion = true;
65
+ }
64
66
  })).subscribe(downstream);
65
67
  }
66
68
  });
@@ -91,3 +93,52 @@ function flatTap(onNext, onError, onComplete) {
91
93
  }));
92
94
  }
93
95
  exports.flatTap = flatTap;
96
+ /**
97
+ * @param obs
98
+ * @return given observer, or one with noop's in place of missing functions
99
+ */
100
+ function toRxObserver(obs) {
101
+ if (obs.next && obs.error && obs.complete) {
102
+ return obs;
103
+ }
104
+ else {
105
+ const next = (obs.next ? obs.next.bind(obs) : noop);
106
+ const complete = (obs.complete ? obs.complete.bind(obs) : noop);
107
+ const error = (obs.error ? obs.error.bind(obs) : noop);
108
+ return { next, complete, error };
109
+ }
110
+ }
111
+ exports.toRxObserver = toRxObserver;
112
+ function noop() { }
113
+ class Broadcast {
114
+ constructor() {
115
+ this.src = new rxjs_1.Subject();
116
+ this.event$ = this.src.asObservable().pipe(operators_1.share());
117
+ this.sub = this.event$.subscribe(toRxObserver({}));
118
+ Object.seal(this);
119
+ }
120
+ next(ev) {
121
+ if (!this.sub) {
122
+ return;
123
+ }
124
+ this.src.next(ev);
125
+ }
126
+ done(err) {
127
+ if (!this.sub) {
128
+ return;
129
+ }
130
+ if (err) {
131
+ this.src.error(err);
132
+ }
133
+ else {
134
+ this.src.complete();
135
+ }
136
+ this.sub = undefined;
137
+ }
138
+ isON() {
139
+ return !!this.sub;
140
+ }
141
+ }
142
+ exports.Broadcast = Broadcast;
143
+ Object.freeze(Broadcast.prototype);
144
+ Object.freeze(Broadcast);