core-3nweb-client-lib 0.25.6 → 0.27.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.
- package/README.md +2 -2
- package/build/api-defs/asmail.d.ts +1 -1
- package/build/api-defs/files.d.ts +282 -70
- package/build/core/app-files.js +7 -7
- package/build/core/asmail/config/common.js +4 -4
- package/build/core/asmail/config/index.js +2 -2
- package/build/core/asmail/config/published-intro-key.js +1 -1
- package/build/core/asmail/delivery/common.js +7 -7
- package/build/core/asmail/delivery/index.js +7 -6
- package/build/core/asmail/delivery/msg.js +8 -7
- package/build/core/asmail/delivery/per-recipient-wip.js +3 -3
- package/build/core/asmail/inbox/attachments/fs.js +11 -1
- package/build/core/asmail/inbox/cached-msgs.js +3 -3
- package/build/core/asmail/inbox/inbox-events.js +5 -4
- package/build/core/asmail/inbox/index.js +12 -12
- package/build/core/asmail/inbox/msg-downloader.js +3 -3
- package/build/core/asmail/inbox/msg-indexing.js +4 -4
- package/build/core/asmail/inbox/msg-on-disk.js +7 -7
- package/build/core/asmail/index.d.ts +3 -3
- package/build/core/asmail/index.js +13 -8
- package/build/core/asmail/key-verification.js +5 -5
- package/build/core/asmail/keyring/common.js +7 -6
- package/build/core/asmail/keyring/correspondent-keys.js +8 -7
- package/build/core/asmail/keyring/id-to-email-map.js +2 -1
- package/build/core/asmail/keyring/index.d.ts +7 -8
- package/build/core/asmail/keyring/index.js +15 -14
- package/build/core/asmail/keyring/keyring-storage.js +4 -3
- package/build/core/asmail/msg/opener.js +3 -3
- package/build/core/asmail/msg/packer.js +13 -13
- package/build/core/asmail/sending-params/own-params.js +4 -4
- package/build/core/asmail/sending-params/params-from-others.js +3 -3
- package/build/core/id-manager.js +8 -5
- package/build/core/index.d.ts +2 -1
- package/build/core/index.js +14 -14
- package/build/core/sign-in.d.ts +5 -4
- package/build/core/sign-in.js +12 -14
- package/build/core/sign-up.d.ts +1 -0
- package/build/core/sign-up.js +15 -11
- package/build/core/storage/common/json-saving.d.ts +21 -0
- package/build/core/storage/common/json-saving.js +82 -0
- package/build/core/storage/common/obj-info-file.d.ts +51 -0
- package/build/core/storage/common/obj-info-file.js +153 -5
- package/build/core/storage/common/utils.d.ts +2 -0
- package/build/core/storage/common/utils.js +32 -0
- package/build/core/storage/index.d.ts +3 -17
- package/build/core/storage/index.js +57 -77
- package/build/core/storage/local/obj-files-gc.d.ts +2 -0
- package/build/core/storage/local/obj-files-gc.js +53 -39
- package/build/core/storage/local/obj-files.d.ts +6 -9
- package/build/core/storage/local/obj-files.js +16 -19
- package/build/core/storage/local/obj-status.d.ts +20 -30
- package/build/core/storage/local/obj-status.js +46 -113
- package/build/core/storage/local/storage.d.ts +15 -5
- package/build/core/storage/local/storage.js +37 -18
- package/build/core/storage/synced/downloader.js +7 -6
- package/build/core/storage/synced/obj-files-gc.d.ts +6 -1
- package/build/core/storage/synced/obj-files-gc.js +106 -13
- package/build/core/storage/synced/obj-files.d.ts +46 -47
- package/build/core/storage/synced/obj-files.js +207 -154
- package/build/core/storage/synced/obj-status.d.ts +103 -42
- package/build/core/storage/synced/obj-status.js +525 -137
- package/build/core/storage/synced/remote-events.d.ts +11 -12
- package/build/core/storage/synced/remote-events.js +80 -57
- package/build/core/storage/synced/storage.d.ts +24 -5
- package/build/core/storage/synced/storage.js +123 -38
- package/build/core/storage/synced/upload-header-file.d.ts +4 -0
- package/build/core/storage/synced/upload-header-file.js +64 -0
- package/build/core/storage/synced/upsyncer.d.ts +15 -9
- package/build/core/storage/synced/upsyncer.js +219 -246
- package/build/core/storage/system-folders/apps-data.d.ts +16 -0
- package/build/core/storage/system-folders/apps-data.js +110 -0
- package/build/core/storage/system-folders/index.d.ts +18 -0
- package/build/core/storage/system-folders/index.js +77 -0
- package/build/core-ipc/common-caps.js +3 -3
- package/build/core-ipc/generic.js +8 -8
- package/build/core-ipc/startup-caps.js +2 -2
- package/build/cryptors.js +6 -2
- package/build/ipc-via-protobuf/asmail-cap.js +67 -83
- package/build/ipc-via-protobuf/bytes.js +16 -17
- package/build/ipc-via-protobuf/connector-clients-side.d.ts +3 -0
- package/build/ipc-via-protobuf/connector-clients-side.js +62 -25
- package/build/ipc-via-protobuf/connector-services-side.js +10 -10
- package/build/ipc-via-protobuf/connector.js +4 -4
- package/build/ipc-via-protobuf/file.d.ts +48 -12
- package/build/ipc-via-protobuf/file.js +476 -120
- package/build/ipc-via-protobuf/fs.d.ts +8 -0
- package/build/ipc-via-protobuf/fs.js +592 -159
- package/build/ipc-via-protobuf/log-cap.js +2 -2
- package/build/ipc-via-protobuf/mailerid.js +3 -3
- package/build/ipc-via-protobuf/protobuf-msg.d.ts +1 -0
- package/build/ipc-via-protobuf/protobuf-msg.js +11 -7
- package/build/ipc-via-protobuf/startup-cap.js +23 -23
- package/build/ipc-via-protobuf/storage-cap.js +12 -12
- package/build/ipc.js +7 -2
- package/build/lib-client/3nstorage/exceptions.d.ts +12 -8
- package/build/lib-client/3nstorage/exceptions.js +31 -10
- package/build/lib-client/3nstorage/service.d.ts +16 -2
- package/build/lib-client/3nstorage/service.js +109 -39
- package/build/lib-client/3nstorage/util/file-based-json.d.ts +2 -1
- package/build/lib-client/3nstorage/util/file-based-json.js +1 -1
- package/build/lib-client/3nstorage/xsp-fs/attrs.js +17 -17
- package/build/lib-client/3nstorage/xsp-fs/common.d.ts +52 -14
- package/build/lib-client/3nstorage/xsp-fs/common.js +31 -16
- package/build/lib-client/3nstorage/xsp-fs/file-node.d.ts +1 -0
- package/build/lib-client/3nstorage/xsp-fs/file-node.js +18 -14
- package/build/lib-client/3nstorage/xsp-fs/file.d.ts +31 -6
- package/build/lib-client/3nstorage/xsp-fs/file.js +74 -23
- package/build/lib-client/3nstorage/xsp-fs/folder-node-serialization.js +4 -4
- package/build/lib-client/3nstorage/xsp-fs/folder-node.d.ts +24 -11
- package/build/lib-client/3nstorage/xsp-fs/folder-node.js +599 -189
- package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +45 -9
- package/build/lib-client/3nstorage/xsp-fs/fs.js +326 -74
- package/build/lib-client/3nstorage/xsp-fs/link-node.d.ts +1 -0
- package/build/lib-client/3nstorage/xsp-fs/link-node.js +7 -2
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +30 -20
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +239 -106
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.d.ts +1 -1
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.js +18 -19
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.js +5 -5
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.js +56 -56
- package/build/lib-client/3nweb-signup.js +4 -4
- package/build/lib-client/asmail/recipient.js +15 -15
- package/build/lib-client/asmail/sender.js +22 -22
- package/build/lib-client/asmail/service-config.js +3 -3
- package/build/lib-client/cryptor/cryptor-in-worker.js +19 -17
- package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
- package/build/lib-client/cryptor/cryptor.js +4 -2
- package/build/lib-client/cryptor/cryptor.wasm +0 -0
- package/build/lib-client/cryptor/in-proc-js.js +1 -1
- package/build/lib-client/cryptor/in-proc-wasm.js +7 -7
- package/build/lib-client/cryptor/worker-js.js +2 -2
- package/build/lib-client/cryptor/worker-wasm.js +2 -2
- package/build/lib-client/files-select.js +1 -1
- package/build/lib-client/files.d.ts +1 -1
- package/build/lib-client/files.js +71 -4
- package/build/lib-client/fs-collection.js +3 -2
- package/build/lib-client/fs-sync-utils.d.ts +5 -0
- package/build/lib-client/fs-sync-utils.js +61 -0
- package/build/lib-client/fs-view.d.ts +14 -0
- package/build/lib-client/fs-view.js +33 -0
- package/build/lib-client/key-derivation.js +1 -1
- package/build/lib-client/local-files/dev-file-sink.js +9 -9
- package/build/lib-client/local-files/dev-file-src.js +2 -2
- package/build/lib-client/local-files/device-fs.d.ts +1 -1
- package/build/lib-client/local-files/device-fs.js +56 -54
- package/build/lib-client/logging/log-to-file.d.ts +1 -1
- package/build/lib-client/logging/log-to-file.js +11 -11
- package/build/lib-client/mailer-id/login.js +7 -7
- package/build/lib-client/mailer-id/provisioner.js +12 -12
- package/build/lib-client/objs-on-disk/file-writing-proc.js +5 -5
- package/build/lib-client/objs-on-disk/obj-folders.js +33 -33
- package/build/lib-client/objs-on-disk/obj-on-disk.d.ts +13 -2
- package/build/lib-client/objs-on-disk/obj-on-disk.js +24 -9
- package/build/lib-client/request-utils.d.ts +1 -0
- package/build/lib-client/request-utils.js +14 -14
- package/build/lib-client/server-events.d.ts +3 -3
- package/build/lib-client/server-events.js +12 -10
- package/build/lib-client/service-locator.js +10 -10
- package/build/lib-client/user-with-mid-session.js +7 -7
- package/build/lib-client/user-with-pkl-session.js +25 -25
- package/build/lib-client/ws-utils.js +3 -3
- package/build/lib-common/async-cryptor-wrap.js +4 -4
- package/build/lib-common/async-fs-node.d.ts +5 -3
- package/build/lib-common/async-fs-node.js +19 -18
- package/build/lib-common/byte-streaming/pipe.js +1 -1
- package/build/lib-common/byte-streaming/wrapping.js +17 -17
- package/build/lib-common/canonical-address.js +1 -1
- package/build/lib-common/exceptions/error.d.ts +1 -0
- package/build/lib-common/exceptions/error.js +7 -6
- package/build/lib-common/exceptions/file.js +10 -1
- package/build/lib-common/ipc/generic-ipc.js +2 -2
- package/build/lib-common/ipc/ws-ipc.js +2 -2
- package/build/lib-common/json-utils.js +2 -1
- package/build/lib-common/mid-sigs-NaCl-Ed.js +14 -14
- package/build/lib-common/objs-on-disk/file-layout.d.ts +19 -0
- package/build/lib-common/objs-on-disk/file-layout.js +130 -12
- package/build/lib-common/objs-on-disk/obj-file.d.ts +13 -2
- package/build/lib-common/objs-on-disk/obj-file.js +99 -37
- package/build/lib-common/objs-on-disk/utils.d.ts +1 -0
- package/build/lib-common/objs-on-disk/utils.js +4 -4
- package/build/lib-common/objs-on-disk/v1-obj-file-format.js +14 -14
- package/build/lib-common/processes/deferred.d.ts +6 -0
- package/build/lib-common/processes/deferred.js +30 -0
- package/build/lib-common/processes/labelled-exec-pools.d.ts +33 -0
- package/build/lib-common/processes/labelled-exec-pools.js +141 -0
- package/build/lib-common/processes/pressure.d.ts +7 -0
- package/build/lib-common/processes/pressure.js +56 -0
- package/build/lib-common/processes/sleep.d.ts +1 -0
- package/build/lib-common/processes/sleep.js +26 -0
- package/build/lib-common/{processes.d.ts → processes/synced.d.ts} +0 -40
- package/build/lib-common/{processes.js → processes/synced.js} +187 -204
- package/build/lib-common/processes/timeout.d.ts +1 -0
- package/build/lib-common/processes/timeout.js +51 -0
- package/build/lib-common/random-node.js +7 -7
- package/build/lib-common/service-api/3nstorage/owner.d.ts +100 -39
- package/build/lib-common/service-api/3nstorage/owner.js +85 -42
- package/build/lib-common/service-api/asmail/delivery.js +2 -2
- package/build/lib-common/service-api/asmail/retrieval.js +1 -1
- package/build/lib-common/timed-cache.d.ts +1 -0
- package/build/lib-common/timed-non-weak-cache.d.ts +1 -0
- package/build/lib-common/timed-non-weak-cache.js +11 -0
- package/build/lib-common/utils-for-observables.d.ts +15 -1
- package/build/lib-common/utils-for-observables.js +70 -19
- package/build/lib-common/weak-cache.d.ts +1 -0
- package/build/lib-common/weak-cache.js +12 -1
- package/build/lib-index.d.ts +2 -1
- package/build/lib-index.js +10 -7
- package/build/protos/asmail.proto.js +12912 -7127
- package/build/protos/file.proto.js +4848 -2399
- package/build/protos/fs.proto.js +9230 -3445
- package/package.json +8 -7
- package/protos/file.proto +91 -11
- package/protos/fs.proto +107 -8
- package/build/core/storage/synced/upsync-status.d.ts +0 -41
- 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.
|
|
20
|
-
const
|
|
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 = (0, 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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
class
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
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 = (0, 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
|
+
(0, 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);
|
|
@@ -19,11 +19,11 @@ exports.stringOfB64Chars = exports.stringOfB64UrlSafeChars = exports.stringOfB64
|
|
|
19
19
|
const buffer_utils_1 = require("./buffer-utils");
|
|
20
20
|
const crypto_1 = require("crypto");
|
|
21
21
|
function bytesSync(numOfBytes) {
|
|
22
|
-
return crypto_1.randomBytes(numOfBytes);
|
|
22
|
+
return (0, crypto_1.randomBytes)(numOfBytes);
|
|
23
23
|
}
|
|
24
24
|
exports.bytesSync = bytesSync;
|
|
25
25
|
function bytes(numOfBytes) {
|
|
26
|
-
return new Promise((res, rej) => crypto_1.randomBytes(numOfBytes, (err, buf) => {
|
|
26
|
+
return new Promise((res, rej) => (0, crypto_1.randomBytes)(numOfBytes, (err, buf) => {
|
|
27
27
|
if (err) {
|
|
28
28
|
rej(err);
|
|
29
29
|
}
|
|
@@ -34,15 +34,15 @@ function bytes(numOfBytes) {
|
|
|
34
34
|
}
|
|
35
35
|
exports.bytes = bytes;
|
|
36
36
|
function uint8Sync() {
|
|
37
|
-
return crypto_1.randomBytes(1)[0];
|
|
37
|
+
return (0, crypto_1.randomBytes)(1)[0];
|
|
38
38
|
}
|
|
39
39
|
exports.uint8Sync = uint8Sync;
|
|
40
40
|
async function uint8() {
|
|
41
|
-
return (await crypto_1.randomBytes(1))[0];
|
|
41
|
+
return (await (0, crypto_1.randomBytes)(1))[0];
|
|
42
42
|
}
|
|
43
43
|
exports.uint8 = uint8;
|
|
44
44
|
function uint48Sync() {
|
|
45
|
-
const b = crypto_1.randomBytes(6);
|
|
45
|
+
const b = (0, crypto_1.randomBytes)(6);
|
|
46
46
|
const l = b[0] + (b[1] << 8) + (b[2] << 16) + (b[3] << 24);
|
|
47
47
|
const h = b[4] + (b[5] << 8);
|
|
48
48
|
return h * 0x100000000 + l;
|
|
@@ -57,13 +57,13 @@ async function uint48() {
|
|
|
57
57
|
exports.uint48 = uint48;
|
|
58
58
|
function stringOfB64UrlSafeCharsSync(numOfChars) {
|
|
59
59
|
const numOfbytes = 3 * (1 + Math.floor(numOfChars / 4));
|
|
60
|
-
const byteArr = crypto_1.randomBytes(numOfbytes);
|
|
60
|
+
const byteArr = (0, crypto_1.randomBytes)(numOfbytes);
|
|
61
61
|
return buffer_utils_1.base64urlSafe.pack(byteArr).substring(0, numOfChars);
|
|
62
62
|
}
|
|
63
63
|
exports.stringOfB64UrlSafeCharsSync = stringOfB64UrlSafeCharsSync;
|
|
64
64
|
function stringOfB64CharsSync(numOfChars) {
|
|
65
65
|
const numOfbytes = 3 * (1 + Math.floor(numOfChars / 4));
|
|
66
|
-
return crypto_1.randomBytes(numOfbytes).toString('base64').substring(0, numOfChars);
|
|
66
|
+
return (0, crypto_1.randomBytes)(numOfbytes).toString('base64').substring(0, numOfChars);
|
|
67
67
|
}
|
|
68
68
|
exports.stringOfB64CharsSync = stringOfB64CharsSync;
|
|
69
69
|
async function stringOfB64UrlSafeChars(numOfChars) {
|