iobroker.javascript 9.0.1 → 9.0.3

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.
@@ -198,13 +198,16 @@ class ProtectFs {
198
198
  throw new Error('Permission denied');
199
199
  }
200
200
  }
201
- access(path, callback) {
201
+ access(path, mode, callback) {
202
202
  this.#checkProtected(path, true);
203
- return nodeFS.access(path, callback);
203
+ if (typeof callback === 'function') {
204
+ return nodeFS.access(path, mode, callback);
205
+ }
206
+ return nodeFS.access(path, mode);
204
207
  }
205
208
  accessSync(path, mode) {
206
209
  this.#checkProtected(path, true);
207
- return nodeFS.accessSync(path, mode); // function accessSync(path, mode) {
210
+ return nodeFS.accessSync(path, mode);
208
211
  }
209
212
  cp(source, destination, opts, callback) {
210
213
  this.#checkProtected(source, false);
@@ -220,27 +223,36 @@ class ProtectFs {
220
223
  cpSync(source, destination, opts) {
221
224
  this.#checkProtected(source, false);
222
225
  this.#checkProtected(destination, false);
223
- return nodeFS.cpSync.call(this, source, destination, opts); // function cpSync(src, dest, options) {
226
+ return nodeFS.cpSync.call(this, source, destination, opts);
224
227
  }
225
- readFile(path, callback) {
228
+ readFile(path, options, callback) {
226
229
  if (typeof path !== 'number') {
227
230
  this.#checkProtected(path, true);
228
231
  }
229
- return nodeFS.readFile.call(this, path, callback); // function readFile(path, options, callback) {
232
+ if (typeof callback === 'function') {
233
+ return nodeFS.readFile.call(this, path, options,
234
+ // @ts-expect-error readFile can accept 3 arguments too
235
+ callback);
236
+ }
237
+ return nodeFS.readFile.call(this, path, options);
230
238
  }
231
239
  readFileSync(path, options) {
232
240
  if (typeof path !== 'number') {
233
241
  this.#checkProtected(path, true);
234
242
  }
235
- return nodeFS.readFileSync.call(this, path, options); // function readFileSync(path, options) {
243
+ return nodeFS.readFileSync.call(this, path, options);
236
244
  }
237
- readlink(path, callback) {
245
+ readlink(path, options, callback) {
238
246
  this.#checkProtected(path, true);
239
- return nodeFS.readlink.call(this, path, callback); // function readlink(path, options, callback) {
247
+ if (typeof callback === 'function') {
248
+ // @ts-expect-error should work
249
+ return nodeFS.readlink.call(this, path, options, callback); //
250
+ }
251
+ return nodeFS.readlink.call(this, path, options);
240
252
  }
241
253
  readlinkSync(path, options) {
242
254
  this.#checkProtected(path, true);
243
- return nodeFS.readlinkSync.call(this, path, options); // function readlinkSync(path, options) {
255
+ return nodeFS.readlinkSync.call(this, path, options);
244
256
  }
245
257
  symlink(target, path, type, callback) {
246
258
  this.#checkProtected(target, true);
@@ -249,228 +261,266 @@ class ProtectFs {
249
261
  // @ts-expect-error should work
250
262
  return nodeFS.symlink.call(this, target, path, type, callback);
251
263
  }
252
- return nodeFS.symlink.call(this, target, path, type); // function symlink(target, path, type_, callback_) {
264
+ return nodeFS.symlink.call(this, target, path, type);
253
265
  }
254
266
  symlinkSync(target, path, type) {
255
267
  this.#checkProtected(target, true);
256
268
  this.#checkProtected(path, false);
257
- return nodeFS.symlinkSync.call(this, target, path, type); // function symlinkSync(target, path, type) {
269
+ return nodeFS.symlinkSync.call(this, target, path, type);
258
270
  }
259
271
  writeFile(file, data, options, callback) {
260
272
  if (typeof file !== 'number') {
261
273
  this.#checkProtected(file, false);
262
274
  }
263
- // @ts-expect-error should work
264
- return nodeFS.writeFile.call(this, file, data, options, callback); // function writeFile(path, data, options, callback) {
275
+ if (typeof callback === 'function') {
276
+ // @ts-expect-error should work
277
+ return nodeFS.writeFile.call(this, file, data, options, callback);
278
+ }
279
+ return nodeFS.writeFile.call(this, file, data, options);
265
280
  }
266
281
  writeFileSync(file, data, options) {
267
282
  if (typeof file !== 'number') {
268
283
  this.#checkProtected(file, false);
269
284
  }
270
- return nodeFS.writeFileSync.call(this, file, data, options); // function writeFileSync(path, data, options) {
285
+ return nodeFS.writeFileSync.call(this, file, data, options);
271
286
  }
272
287
  unlink(path, callback) {
273
288
  this.#checkProtected(path, false);
274
- return nodeFS.unlink.call(this, path, callback); // function unlink(path, callback) {
289
+ return nodeFS.unlink.call(this, path, callback || ((_err) => { }));
275
290
  }
276
291
  unlinkSync(path) {
277
292
  this.#checkProtected(path, false);
278
- return nodeFS.unlinkSync.call(this, path); // function unlinkSync(path) {
293
+ return nodeFS.unlinkSync.call(this, path);
279
294
  }
280
- appendFile(file, data, callback) {
295
+ appendFile(file, data, options, callback) {
281
296
  if (typeof file !== 'number') {
282
297
  this.#checkProtected(file, false);
283
298
  }
284
- return nodeFS.appendFile.call(this, file, data, callback); // function appendFile(path, data, options, callback) {
299
+ if (typeof callback === 'function') {
300
+ // @ts-expect-error should work
301
+ return nodeFS.appendFile.call(this, file, data, options, callback);
302
+ }
303
+ return nodeFS.appendFile.call(this, file, data, options);
285
304
  }
286
- appendFileSync(file, data) {
305
+ appendFileSync(file, data, options) {
287
306
  if (typeof file !== 'number') {
288
307
  this.#checkProtected(file, false);
289
308
  }
290
- return nodeFS.appendFileSync.call(this, file, data); // function appendFileSync(path, data, options) {
309
+ return nodeFS.appendFileSync.call(this, file, data, options);
291
310
  }
292
311
  chmod(path, mode, callback) {
293
312
  this.#checkProtected(path, false);
294
- return nodeFS.chmod.call(this, path, mode, callback); // function chmod(path, mode, callback) {
313
+ return nodeFS.chmod.call(this, path, mode, callback || ((_err) => { }));
295
314
  }
296
315
  chmodSync(path, mode) {
297
316
  this.#checkProtected(path, false);
298
- return nodeFS.chmodSync.call(this, path, mode); // function chmodSync(path, mode) {
317
+ return nodeFS.chmodSync.call(this, path, mode);
299
318
  }
300
319
  chown(path, uid, gid, callback) {
301
320
  this.#checkProtected(path, false);
302
- return nodeFS.chown.call(this, path, uid, gid, callback); // function chown(path, uid, gid, callback) {
321
+ return nodeFS.chown.call(this, path, uid, gid, callback || ((_err) => { }));
303
322
  }
304
323
  chownSync(path, uid, gid) {
305
324
  this.#checkProtected(path, false);
306
- return nodeFS.chownSync.call(this, path, uid, gid); // function chownSync(path, uid, gid) {
325
+ return nodeFS.chownSync.call(this, path, uid, gid);
307
326
  }
308
327
  copyFile(src, dest, mode, callback) {
309
328
  this.#checkProtected(src, true);
310
329
  this.#checkProtected(dest, false);
311
330
  // @ts-expect-error should work
312
- return nodeFS.copyFile.call(this, src, dest, mode, callback); // function copyFile(src, dest, mode, callback) {
331
+ return nodeFS.copyFile.call(this, src, dest, mode, callback);
313
332
  }
314
333
  copyFileSync(src, dest, mode) {
315
334
  this.#checkProtected(src, true);
316
335
  this.#checkProtected(dest, false);
317
- return nodeFS.copyFileSync.call(this, src, dest, mode); // function copyFileSync(src, dest, mode) {
336
+ return nodeFS.copyFileSync.call(this, src, dest, mode);
318
337
  }
319
338
  rename(oldPath, newPath, callback) {
320
339
  this.#checkProtected(oldPath, false);
321
340
  this.#checkProtected(newPath, false);
322
- return nodeFS.rename.call(this, oldPath, newPath, callback); // function rename(oldPath, newPath, callback) {
341
+ return nodeFS.rename.call(this, oldPath, newPath, callback || ((_err) => { }));
323
342
  }
324
343
  renameSync(oldPath, newPath) {
325
344
  this.#checkProtected(oldPath, false);
326
345
  this.#checkProtected(newPath, false);
327
- return nodeFS.renameSync.call(this, oldPath, newPath); // function renameSync(oldPath, newPath) {
346
+ return nodeFS.renameSync.call(this, oldPath, newPath);
328
347
  }
329
348
  open(path, callback) {
330
349
  this.#checkProtected(path, true);
331
- return nodeFS.open.call(this, path, callback); // function open(path, flags, mode, callback) {
350
+ return nodeFS.open.call(this, path, callback);
332
351
  }
333
352
  openSync(path, flags, mode) {
334
353
  this.#checkProtected(path, true);
335
- return nodeFS.openSync.call(this, path, flags, mode); // function openSync(path, flags, mode) {
354
+ return nodeFS.openSync.call(this, path, flags, mode);
336
355
  }
337
356
  truncate(path, callback) {
338
357
  this.#checkProtected(path, false);
339
- return nodeFS.truncate.call(this, path, callback); // function truncate(path, len, callback) {
358
+ return nodeFS.truncate.call(this, path, callback || ((_err) => { }));
340
359
  }
341
360
  truncateSync(path) {
342
361
  this.#checkProtected(path, false);
343
- return nodeFS.truncateSync.call(this, path); // function truncateSync(path, len) {
362
+ return nodeFS.truncateSync.call(this, path);
344
363
  }
345
364
  exists(path, callback) {
346
365
  this.#checkProtected(path, true);
347
- return nodeFS.exists.call(this, path, callback); // function exists(path, callback) {
366
+ return nodeFS.exists.call(this, path, callback);
348
367
  }
349
368
  existsSync(path) {
350
369
  this.#checkProtected(path, true);
351
- return nodeFS.existsSync.call(this, path); // function existsSync(path) {
370
+ return nodeFS.existsSync.call(this, path);
352
371
  }
353
372
  stat(path, options, callback) {
354
373
  this.#checkProtected(path, true);
374
+ if (typeof callback === 'function') {
375
+ // @ts-expect-error should work
376
+ return nodeFS.stat.call(this, path, options, callback);
377
+ }
355
378
  // @ts-expect-error should work
356
- return nodeFS.stat.call(this, path, options, callback); // function stat(path, options = { bigint: false }, callback) {
379
+ return nodeFS.stat.call(this, path, options);
357
380
  }
358
381
  statSync(path, options) {
359
382
  this.#checkProtected(path, true);
360
- return nodeFS.statSync.call(this, path, options); // function statSync(path, options = { bigint: false, throwIfNoEntry: true }) {
383
+ return nodeFS.statSync.call(this, path, options);
361
384
  }
362
385
  utimes(path, atime, mtime, callback) {
363
386
  this.#checkProtected(path, false);
364
- return nodeFS.utimes.call(this, path, atime, mtime, callback); // function utimes(path, atime, mtime, callback) {
387
+ return nodeFS.utimes.call(this, path, atime, mtime, callback || ((_err) => { }));
365
388
  }
366
389
  utimesSync(path, atime, mtime) {
367
390
  this.#checkProtected(path, false);
368
- return nodeFS.utimesSync.call(this, path, atime, mtime); // function utimesSync(path, atime, mtime) {
391
+ return nodeFS.utimesSync.call(this, path, atime, mtime);
369
392
  }
370
393
  readdir(path, options, callback) {
371
394
  this.#checkProtected(path, true);
395
+ if (typeof callback === 'function') {
396
+ return nodeFS.readdir.call(this, path, options, callback);
397
+ }
372
398
  // @ts-expect-error should work
373
- return nodeFS.readdir.call(this, path, options, callback); // function readdir(path, options, callback) {
399
+ return nodeFS.readdir.call(this, path, options);
374
400
  }
375
401
  readdirSync(path, options) {
376
402
  this.#checkProtected(path, true);
377
403
  // @ts-expect-error should work
378
- return nodeFS.readdirSync.call(this, path, options); // function readdirSync(path, options) {
404
+ return nodeFS.readdirSync.call(this, path, options);
379
405
  }
380
406
  createReadStream(path, options) {
381
407
  this.#checkProtected(path, true);
382
- return nodeFS.createReadStream.call(this, path, options); // function createReadStream(path, options) {
408
+ return nodeFS.createReadStream.call(this, path, options);
383
409
  }
384
410
  createWriteStream(path, options) {
385
411
  this.#checkProtected(path, false);
386
- return nodeFS.createWriteStream.call(this, path, options); // function createWriteStream(path, options) {
412
+ return nodeFS.createWriteStream.call(this, path, options);
387
413
  }
388
414
  lchmod(path, mode, callback) {
389
415
  this.#checkProtected(path, false);
390
- return nodeFS.lchmod.call(this, path, mode, callback); // function lchmod(path, mode, callback) {
416
+ return nodeFS.lchmod.call(this, path, mode, callback || ((_err) => { }));
391
417
  }
392
418
  lchmodSync(path, mode) {
393
419
  this.#checkProtected(path, false);
394
- return nodeFS.lchmodSync.call(this, path, mode); // function lchmodSync(path, mode) {
420
+ return nodeFS.lchmodSync.call(this, path, mode);
395
421
  }
396
422
  lchown(path, uid, gid, callback) {
397
423
  this.#checkProtected(path, false);
398
- return nodeFS.lchown.call(this, path, uid, gid, callback); // function lchown(path, uid, gid, callback) {
424
+ return nodeFS.lchown.call(this, path, uid, gid, callback || ((_err) => { }));
399
425
  }
400
426
  lchownSync(path, uid, gid) {
401
427
  this.#checkProtected(path, false);
402
- return nodeFS.lchownSync.call(this, path, uid, gid); // function lchownSync(path, uid, gid) {
428
+ return nodeFS.lchownSync.call(this, path, uid, gid);
403
429
  }
404
430
  link(existingPath, newPath, callback) {
405
431
  this.#checkProtected(existingPath, false);
406
432
  this.#checkProtected(newPath, false);
407
- return nodeFS.link.call(this, existingPath, newPath, callback); // function link(existingPath, newPath, callback) {
433
+ return nodeFS.link.call(this, existingPath, newPath, callback || ((_err) => { }));
408
434
  }
409
435
  linkSync(existingPath, newPath) {
410
436
  this.#checkProtected(existingPath, false);
411
437
  this.#checkProtected(newPath, false);
412
- return nodeFS.linkSync.call(this, existingPath, newPath); // function linkSync(existingPath, newPath) {
438
+ return nodeFS.linkSync.call(this, existingPath, newPath);
413
439
  }
414
440
  lstat(path, options, callback) {
415
441
  this.#checkProtected(path, true);
442
+ if (typeof callback === 'function') {
443
+ // @ts-expect-error should work
444
+ return nodeFS.lstat.call(this, path, options, callback);
445
+ }
416
446
  // @ts-expect-error should work
417
- return nodeFS.lstat.call(this, path, options, callback); // function lstat(path, options = { bigint: false }, callback) {
447
+ return nodeFS.lstat.call(this, path, options);
418
448
  }
419
449
  lstatSync(path, options) {
420
450
  this.#checkProtected(path, true);
421
- return nodeFS.lstatSync.call(this, path, options); // function lstatSync(path, options = { bigint: false, throwIfNoEntry: true }) {
451
+ return nodeFS.lstatSync.call(this, path, options);
422
452
  }
423
453
  lutimes(path, atime, mtime, callback) {
424
454
  this.#checkProtected(path, false);
425
- return nodeFS.lutimes.call(this, path, atime, mtime, callback); // function lutimes(path, atime, mtime, callback) {
455
+ return nodeFS.lutimes.call(this, path, atime, mtime, callback || ((_err) => { }));
426
456
  }
427
457
  lutimesSync(path, atime, mtime) {
428
458
  this.#checkProtected(path, false);
429
- return nodeFS.lutimesSync.call(this, path, atime, mtime); // function lutimesSync(path, atime, mtime) {
459
+ return nodeFS.lutimesSync.call(this, path, atime, mtime);
430
460
  }
431
461
  mkdir(path, options, callback) {
432
462
  this.#checkProtected(path, false);
433
- // @ts-expect-error should work
434
- return nodeFS.mkdir.call(this, path, options, callback); // function mkdir(path, options, callback) {
463
+ if (typeof callback === 'function') {
464
+ // @ts-expect-error should work
465
+ return nodeFS.mkdir.call(this, path, options, callback);
466
+ }
467
+ return nodeFS.mkdir.call(this, path, options);
435
468
  }
436
469
  mkdirSync(path, options) {
437
470
  this.#checkProtected(path, false);
438
- return nodeFS.mkdirSync.call(this, path, options); // function mkdirSync(path, options) {
471
+ return nodeFS.mkdirSync.call(this, path, options);
439
472
  }
440
473
  mkdtemp(prefix, options, callback) {
441
474
  this.#checkProtected(prefix, false);
442
- // @ts-expect-error should work
443
- return nodeFS.mkdtemp.call(this, prefix, options, callback); // function mkdtemp(prefix, options, callback) {
475
+ if (typeof callback === 'function') {
476
+ // @ts-expect-error should work
477
+ return nodeFS.mkdtemp.call(this, prefix, options, callback);
478
+ }
479
+ return nodeFS.mkdtemp.call(this, prefix, options);
444
480
  }
445
481
  mkdtempSync(prefix, options) {
446
482
  this.#checkProtected(prefix, false);
447
- return nodeFS.mkdtempSync.call(this, prefix, options); // function mkdtempSync(prefix, options) {
483
+ return nodeFS.mkdtempSync.call(this, prefix, options);
448
484
  }
449
485
  rm(path, options, callback) {
450
486
  this.#checkProtected(path, false);
487
+ if (typeof callback === 'function') {
488
+ return nodeFS.rm.call(this, path, options, callback);
489
+ }
451
490
  // @ts-expect-error should work
452
- return nodeFS.rm.call(this, path, options, callback); // function rm(path, options, callback) {
491
+ return nodeFS.rm.call(this, path, options);
453
492
  }
454
493
  rmSync(path, options) {
455
494
  this.#checkProtected(path, false);
456
- return nodeFS.rmSync.call(this, path, options); // function rmSync(path, options) {
495
+ return nodeFS.rmSync.call(this, path, options);
457
496
  }
458
497
  rmdir(path, options, callback) {
459
498
  this.#checkProtected(path, false);
499
+ if (typeof callback === 'function') {
500
+ return nodeFS.rmdir.call(this, path, options, callback);
501
+ }
460
502
  // @ts-expect-error should work
461
- return nodeFS.rmdir.call(this, path, options, callback); // function rmdir(path, options, callback) {
503
+ return nodeFS.rmdir.call(this, path, options);
462
504
  }
463
505
  rmdirSync(path, options) {
464
506
  this.#checkProtected(path, false);
465
- return nodeFS.rmdirSync.call(this, path, options); // function rmdirSync(path, options) {
507
+ return nodeFS.rmdirSync.call(this, path, options);
466
508
  }
467
- watch(filename, listener) {
509
+ watch(filename, options, listener) {
468
510
  this.#checkProtected(filename, true);
469
- return nodeFS.watch.call(this, filename, listener); // function watch(filename, options, listener) {
511
+ if (typeof listener === 'function') {
512
+ // @ts-expect-error should work
513
+ return nodeFS.watch.call(this, filename, options, listener);
514
+ }
515
+ return nodeFS.watch.call(this, filename, options);
470
516
  }
471
517
  watchFile(filename, listener) {
472
518
  this.#checkProtected(filename, true);
473
- return nodeFS.watchFile.call(this, filename, listener); // function watchFile(filename, options, listener) {
519
+ return nodeFS.watchFile.call(this, filename, listener);
520
+ }
521
+ unwatchFile(filename, listener) {
522
+ this.#checkProtected(filename, true);
523
+ return nodeFS.unwatchFile.call(this, filename, listener);
474
524
  }
475
525
  }
476
526
  exports.default = ProtectFs;