@dxos/random-access-storage 0.8.3 → 0.8.4-main.28f8d3d

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.
@@ -37,9 +37,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
37
37
  mod
38
38
  ));
39
39
 
40
- // node_modules/.pnpm/random-access-idb@1.2.2_patch_hash=mqfhtwnltd5kq5s4kb4gk7k2k4/node_modules/random-access-idb/lib/blocks.js
40
+ // ../../../node_modules/.pnpm/random-access-idb@1.2.2_patch_hash=207ec2404ef8b5e9e6d9de8ce83586d215ef77b94a7d0cadced03125874a1d9e/node_modules/random-access-idb/lib/blocks.js
41
41
  var require_blocks = __commonJS({
42
- "node_modules/.pnpm/random-access-idb@1.2.2_patch_hash=mqfhtwnltd5kq5s4kb4gk7k2k4/node_modules/random-access-idb/lib/blocks.js"(exports, module) {
42
+ "../../../node_modules/.pnpm/random-access-idb@1.2.2_patch_hash=207ec2404ef8b5e9e6d9de8ce83586d215ef77b94a7d0cadced03125874a1d9e/node_modules/random-access-idb/lib/blocks.js"(exports, module) {
43
43
  module.exports = function(size, start, end) {
44
44
  var result = [];
45
45
  for (var n = Math.floor(start / size) * size; n < end; n += size) {
@@ -54,9 +54,9 @@ var require_blocks = __commonJS({
54
54
  }
55
55
  });
56
56
 
57
- // node_modules/.pnpm/random-access-idb@1.2.2_patch_hash=mqfhtwnltd5kq5s4kb4gk7k2k4/node_modules/random-access-idb/index.js
57
+ // ../../../node_modules/.pnpm/random-access-idb@1.2.2_patch_hash=207ec2404ef8b5e9e6d9de8ce83586d215ef77b94a7d0cadced03125874a1d9e/node_modules/random-access-idb/index.js
58
58
  var require_random_access_idb = __commonJS({
59
- "node_modules/.pnpm/random-access-idb@1.2.2_patch_hash=mqfhtwnltd5kq5s4kb4gk7k2k4/node_modules/random-access-idb/index.js"(exports, module) {
59
+ "../../../node_modules/.pnpm/random-access-idb@1.2.2_patch_hash=207ec2404ef8b5e9e6d9de8ce83586d215ef77b94a7d0cadced03125874a1d9e/node_modules/random-access-idb/index.js"(exports, module) {
60
60
  var RandomAccess = import$random_access_storage;
61
61
  var inherits = import$inherits;
62
62
  var nextTick = import$next_tick;
@@ -228,19 +228,26 @@ var require_random_access_idb = __commonJS({
228
228
  }
229
229
  });
230
230
 
231
- // packages/common/random-access-storage/src/common/abstract-storage.ts
231
+ // src/common/abstract-storage.ts
232
232
  import { join as join2 } from "@dxos/node-std/path";
233
233
  import { inspect } from "@dxos/node-std/util";
234
234
  import { inspectObject } from "@dxos/debug";
235
235
  import { log as log2 } from "@dxos/log";
236
236
 
237
- // packages/common/random-access-storage/src/common/utils.ts
237
+ // src/common/utils.ts
238
238
  import { join } from "@dxos/node-std/path";
239
239
  var stringDiff = (first, second) => first.split(second).join("");
240
240
  var getFullPath = (root, path) => join(root, stringDiff(path, root));
241
241
 
242
- // packages/common/random-access-storage/src/common/directory.ts
242
+ // src/common/directory.ts
243
243
  var Directory = class _Directory {
244
+ type;
245
+ path;
246
+ // TODO(burdon): Create interface for these methods (shared with AbstractStorage).
247
+ _list;
248
+ _getOrCreateFile;
249
+ _remove;
250
+ _onFlush;
244
251
  constructor({ type, path, list, getOrCreateFile, remove, onFlush }) {
245
252
  this.type = type;
246
253
  this.path = path;
@@ -290,10 +297,10 @@ var Directory = class _Directory {
290
297
  }
291
298
  };
292
299
 
293
- // packages/common/random-access-storage/src/common/file.ts
300
+ // src/common/file.ts
294
301
  import pify from "pify";
295
302
  import { log } from "@dxos/log";
296
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/common/random-access-storage/src/common/file.ts";
303
+ var __dxlog_file = "/__w/dxos/dxos/packages/common/random-access-storage/src/common/file.ts";
297
304
  var MAX_STORAGE_OPERATION_TIME = 50;
298
305
  var pifyFields = (object, type, fields) => {
299
306
  for (const field of fields) {
@@ -338,9 +345,11 @@ var wrapFile = (native, type) => {
338
345
  });
339
346
  };
340
347
 
341
- // packages/common/random-access-storage/src/common/abstract-storage.ts
342
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/common/random-access-storage/src/common/abstract-storage.ts";
348
+ // src/common/abstract-storage.ts
349
+ var __dxlog_file2 = "/__w/dxos/dxos/packages/common/random-access-storage/src/common/abstract-storage.ts";
343
350
  var AbstractStorage = class {
351
+ path;
352
+ _files;
344
353
  // TODO(burdon): Make required.
345
354
  constructor(path) {
346
355
  this.path = path;
@@ -375,7 +384,7 @@ var AbstractStorage = class {
375
384
  try {
376
385
  log2.info("Erasing all data...", void 0, {
377
386
  F: __dxlog_file2,
378
- L: 60,
387
+ L: 61,
379
388
  S: this,
380
389
  C: (f, a) => f(...a)
381
390
  });
@@ -384,14 +393,14 @@ var AbstractStorage = class {
384
393
  await this._destroy();
385
394
  log2("Erased...", void 0, {
386
395
  F: __dxlog_file2,
387
- L: 64,
396
+ L: 65,
388
397
  S: this,
389
398
  C: (f, a) => f(...a)
390
399
  });
391
400
  } catch (err) {
392
401
  log2.catch(err, void 0, {
393
402
  F: __dxlog_file2,
394
- L: 66,
403
+ L: 67,
395
404
  S: this,
396
405
  C: (f, a) => f(...a)
397
406
  });
@@ -449,7 +458,7 @@ var AbstractStorage = class {
449
458
  async _closeFilesInPath(path) {
450
459
  await Promise.all(Array.from((await this._getFiles(path)).values()).map((file) => file.close().catch((err) => log2.catch(err, void 0, {
451
460
  F: __dxlog_file2,
452
- L: 134,
461
+ L: 135,
453
462
  S: this,
454
463
  C: (f, a) => f(...a)
455
464
  }))));
@@ -462,7 +471,7 @@ var AbstractStorage = class {
462
471
  await Promise.all(Array.from(await this._getFiles(path)).map(([path2, file]) => {
463
472
  return file.destroy().then(() => this._files.delete(path2)).catch((err) => log2.error(err.message, void 0, {
464
473
  F: __dxlog_file2,
465
- L: 149,
474
+ L: 150,
466
475
  S: this,
467
476
  C: (f, a) => f(...a)
468
477
  }));
@@ -470,11 +479,11 @@ var AbstractStorage = class {
470
479
  }
471
480
  };
472
481
 
473
- // packages/common/random-access-storage/src/common/memory-storage.ts
482
+ // src/common/memory-storage.ts
474
483
  import ram from "random-access-memory";
475
484
  import { arrayToBuffer } from "@dxos/util";
476
485
 
477
- // packages/common/random-access-storage/src/common/storage.ts
486
+ // src/common/storage.ts
478
487
  var StorageType = /* @__PURE__ */ function(StorageType2) {
479
488
  StorageType2["RAM"] = "ram";
480
489
  StorageType2["IDB"] = "idb";
@@ -485,12 +494,9 @@ var StorageType = /* @__PURE__ */ function(StorageType2) {
485
494
  return StorageType2;
486
495
  }({});
487
496
 
488
- // packages/common/random-access-storage/src/common/memory-storage.ts
497
+ // src/common/memory-storage.ts
489
498
  var MemoryStorage = class extends AbstractStorage {
490
- constructor() {
491
- super(...arguments);
492
- this.type = StorageType.RAM;
493
- }
499
+ type = StorageType.RAM;
494
500
  _createFile(path, filename) {
495
501
  return this._patchFile(ram());
496
502
  }
@@ -522,17 +528,19 @@ var MemoryStorage = class extends AbstractStorage {
522
528
  }
523
529
  };
524
530
 
525
- // packages/common/random-access-storage/src/browser/idb-storage.ts
531
+ // src/browser/idb-storage.ts
526
532
  var import_random_access_idb = __toESM(require_random_access_idb(), 1);
527
533
  import { invariant } from "@dxos/invariant";
528
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/common/random-access-storage/src/browser/idb-storage.ts";
534
+ var __dxlog_file3 = "/__w/dxos/dxos/packages/common/random-access-storage/src/browser/idb-storage.ts";
529
535
  var DELIM = "\0";
530
536
  var IDbStorage = class extends AbstractStorage {
537
+ type = StorageType.IDB;
538
+ _db;
539
+ _store = "data";
540
+ _initialized = false;
541
+ _fileStorage;
531
542
  constructor(path) {
532
543
  super(path);
533
- this.type = StorageType.IDB;
534
- this._store = "data";
535
- this._initialized = false;
536
544
  this._fileStorage = this._createFileStorage(path);
537
545
  }
538
546
  _createFileStorage(path) {
@@ -621,7 +629,7 @@ var IDbStorage = class extends AbstractStorage {
621
629
  }
622
630
  };
623
631
 
624
- // packages/common/random-access-storage/src/browser/web-fs.ts
632
+ // src/browser/web-fs.ts
625
633
  import { EventEmitter } from "@dxos/node-std/events";
626
634
  import { callbackify } from "@dxos/node-std/util";
627
635
  import { synchronized } from "@dxos/async";
@@ -634,8 +642,12 @@ function _ts_decorate(decorators, target, key, desc) {
634
642
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
635
643
  return c > 3 && r && Object.defineProperty(target, key, r), r;
636
644
  }
637
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/common/random-access-storage/src/browser/web-fs.ts";
645
+ var __dxlog_file4 = "/__w/dxos/dxos/packages/common/random-access-storage/src/browser/web-fs.ts";
638
646
  var WebFS = class {
647
+ path;
648
+ _files;
649
+ type;
650
+ _root;
639
651
  constructor(path) {
640
652
  this.path = path;
641
653
  this._files = /* @__PURE__ */ new Map();
@@ -670,7 +682,7 @@ var WebFS = class {
670
682
  this._root = await navigator.storage.getDirectory();
671
683
  invariant2(this._root, "Root is undefined", {
672
684
  F: __dxlog_file4,
673
- L: 73,
685
+ L: 74,
674
686
  S: this,
675
687
  A: [
676
688
  "this._root",
@@ -718,7 +730,7 @@ var WebFS = class {
718
730
  await Promise.all(Array.from(this._getFiles(path)).map(async ([path2, file]) => {
719
731
  await file.destroy().catch((err) => log3.warn(err, void 0, {
720
732
  F: __dxlog_file4,
721
- L: 116,
733
+ L: 117,
722
734
  S: this,
723
735
  C: (f, a) => f(...a)
724
736
  }));
@@ -735,7 +747,7 @@ var WebFS = class {
735
747
  err
736
748
  }, {
737
749
  F: __dxlog_file4,
738
- L: 126,
750
+ L: 127,
739
751
  S: this,
740
752
  C: (f, a) => f(...a)
741
753
  }));
@@ -750,7 +762,7 @@ var WebFS = class {
750
762
  e
751
763
  }, {
752
764
  F: __dxlog_file4,
753
- L: 136,
765
+ L: 137,
754
766
  S: this,
755
767
  C: (f, a) => f(...a)
756
768
  }));
@@ -791,64 +803,67 @@ _ts_decorate([
791
803
  synchronized
792
804
  ], WebFS.prototype, "_initialize", null);
793
805
  var WebFile = class extends EventEmitter {
806
+ fileName;
807
+ _fileHandle;
808
+ _destroy;
809
+ /**
810
+ * Current view of the file contents.
811
+ */
812
+ _buffer = null;
813
+ _loadBufferPromise = null;
814
+ _flushScheduled = false;
815
+ _flushPromise = Promise.resolve();
816
+ /**
817
+ * Used to discard unnecessary scheduled flushes.
818
+ * If _flushNow() is called with a lower sequence number it should early exit.
819
+ */
820
+ _flushSequence = 0;
821
+ //
822
+ // Metrics
823
+ //
824
+ _flushes = new TimeSeriesCounter();
825
+ _operations = new TimeSeriesCounter();
826
+ _reads = new TimeSeriesCounter();
827
+ _readBytes = new TimeSeriesCounter();
828
+ _writes = new TimeSeriesCounter();
829
+ _writeBytes = new TimeSeriesCounter();
830
+ get _bufferSize() {
831
+ return this._buffer?.length;
832
+ }
794
833
  constructor({ fileName, file, destroy }) {
795
834
  super();
796
- /**
797
- * Current view of the file contents.
798
- */
799
- this._buffer = null;
800
- this._loadBufferPromise = null;
801
- this._flushScheduled = false;
802
- this._flushPromise = Promise.resolve();
803
- /**
804
- * Used to discard unnecessary scheduled flushes.
805
- * If _flushNow() is called with a lower sequence number it should early exit.
806
- */
807
- this._flushSequence = 0;
808
- //
809
- // Metrics
810
- //
811
- this._flushes = new TimeSeriesCounter();
812
- this._operations = new TimeSeriesCounter();
813
- this._reads = new TimeSeriesCounter();
814
- this._readBytes = new TimeSeriesCounter();
815
- this._writes = new TimeSeriesCounter();
816
- this._writeBytes = new TimeSeriesCounter();
817
- this.type = StorageType.WEBFS;
818
- //
819
- // random-access-storage library compatibility
820
- //
821
- // TODO(dmaretskyi): Are those all needed?
822
- this.opened = true;
823
- this.suspended = false;
824
- this.closed = false;
825
- this.unlinked = false;
826
- this.writing = false;
827
- this.readable = true;
828
- this.writable = true;
829
- this.deletable = true;
830
- this.truncatable = true;
831
- this.statable = true;
832
- this.destroyed = false;
833
- this.directory = "";
834
- // TODO(dmaretskyi): is this used?
835
- this.filename = "";
836
- this.native = {
837
- write: callbackify(this.write.bind(this)),
838
- read: callbackify(this.read.bind(this)),
839
- del: callbackify(this.del.bind(this)),
840
- stat: callbackify(this.stat.bind(this)),
841
- destroy: callbackify(this.destroy.bind(this)),
842
- truncate: callbackify(this.truncate?.bind(this))
843
- };
844
835
  this.fileName = fileName;
845
836
  this._fileHandle = file;
846
837
  this._destroy = destroy;
847
838
  void this._loadBufferGuarded();
848
839
  }
849
- get _bufferSize() {
850
- return this._buffer?.length;
851
- }
840
+ type = StorageType.WEBFS;
841
+ //
842
+ // random-access-storage library compatibility
843
+ //
844
+ // TODO(dmaretskyi): Are those all needed?
845
+ opened = true;
846
+ suspended = false;
847
+ closed = false;
848
+ unlinked = false;
849
+ writing = false;
850
+ readable = true;
851
+ writable = true;
852
+ deletable = true;
853
+ truncatable = true;
854
+ statable = true;
855
+ destroyed = false;
856
+ directory = "";
857
+ // TODO(dmaretskyi): is this used?
858
+ filename = "";
859
+ native = {
860
+ write: callbackify(this.write.bind(this)),
861
+ read: callbackify(this.read.bind(this)),
862
+ del: callbackify(this.del.bind(this)),
863
+ stat: callbackify(this.stat.bind(this)),
864
+ destroy: callbackify(this.destroy.bind(this)),
865
+ truncate: callbackify(this.truncate?.bind(this))
866
+ };
852
867
  async _loadBuffer() {
853
868
  const fileHandle = await this._fileHandle;
854
869
  const file = await fileHandle.getFile();
@@ -867,7 +882,7 @@ var WebFile = class extends EventEmitter {
867
882
  await this._loadBufferGuarded();
868
883
  invariant2(this._buffer, void 0, {
869
884
  F: __dxlog_file4,
870
- L: 300,
885
+ L: 301,
871
886
  S: this,
872
887
  A: [
873
888
  "this._buffer",
@@ -895,7 +910,7 @@ var WebFile = class extends EventEmitter {
895
910
  this._flushScheduled = false;
896
911
  this._flushPromise = this._flushCache(sequence).catch((err) => log3.warn(err, void 0, {
897
912
  F: __dxlog_file4,
898
- L: 318,
913
+ L: 319,
899
914
  S: this,
900
915
  C: (f, a) => f(...a)
901
916
  }));
@@ -906,7 +921,7 @@ var WebFile = class extends EventEmitter {
906
921
  await this._flushPromise;
907
922
  this._flushPromise = this._flushCache(this._flushSequence).catch((err) => log3.warn(err, void 0, {
908
923
  F: __dxlog_file4,
909
- L: 326,
924
+ L: 327,
910
925
  S: this,
911
926
  C: (f, a) => f(...a)
912
927
  }));
@@ -921,7 +936,7 @@ var WebFile = class extends EventEmitter {
921
936
  await this._loadBufferGuarded();
922
937
  invariant2(this._buffer, void 0, {
923
938
  F: __dxlog_file4,
924
- L: 339,
939
+ L: 340,
925
940
  S: this,
926
941
  A: [
927
942
  "this._buffer",
@@ -943,7 +958,7 @@ var WebFile = class extends EventEmitter {
943
958
  await this._loadBufferGuarded();
944
959
  invariant2(this._buffer, void 0, {
945
960
  F: __dxlog_file4,
946
- L: 359,
961
+ L: 360,
947
962
  S: this,
948
963
  A: [
949
964
  "this._buffer",
@@ -971,7 +986,7 @@ var WebFile = class extends EventEmitter {
971
986
  await this._loadBufferGuarded();
972
987
  invariant2(this._buffer, void 0, {
973
988
  F: __dxlog_file4,
974
- L: 386,
989
+ L: 387,
975
990
  S: this,
976
991
  A: [
977
992
  "this._buffer",
@@ -994,7 +1009,7 @@ var WebFile = class extends EventEmitter {
994
1009
  await this._loadBufferGuarded();
995
1010
  invariant2(this._buffer, void 0, {
996
1011
  F: __dxlog_file4,
997
- L: 408,
1012
+ L: 409,
998
1013
  S: this,
999
1014
  A: [
1000
1015
  "this._buffer",
@@ -1013,7 +1028,7 @@ var WebFile = class extends EventEmitter {
1013
1028
  await this._loadBufferGuarded();
1014
1029
  invariant2(this._buffer, void 0, {
1015
1030
  F: __dxlog_file4,
1016
- L: 423,
1031
+ L: 424,
1017
1032
  S: this,
1018
1033
  A: [
1019
1034
  "this._buffer",
@@ -1078,7 +1093,7 @@ _ts_decorate([
1078
1093
  synchronized
1079
1094
  ], WebFile.prototype, "destroy", null);
1080
1095
 
1081
- // packages/common/random-access-storage/src/browser/storage.ts
1096
+ // src/browser/storage.ts
1082
1097
  var createStorage = ({ type, root = "" } = {}) => {
1083
1098
  if (type === void 0) {
1084
1099
  return new IDbStorage(root);