@dxos/random-access-storage 0.8.4-main.3a94e84 → 0.8.4-main.3c1ae3b
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/dist/lib/browser/index.mjs +92 -80
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +20 -18
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/browser/storage.d.ts.map +1 -1
- package/dist/types/src/browser/web-fs.d.ts.map +1 -1
- package/dist/types/src/common/abstract-storage.d.ts.map +1 -1
- package/dist/types/src/node/node-storage.d.ts.map +1 -1
- package/dist/types/src/node/storage.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -8
- package/src/browser/bench.browser.test.ts +2 -1
- package/src/browser/storage.browser.test.ts +3 -2
- package/src/browser/storage.ts +2 -1
- package/src/browser/web-fs.ts +2 -1
- package/src/common/abstract-storage.ts +1 -0
- package/src/node/bench.node.test.ts +4 -2
- package/src/node/node-storage.ts +2 -1
- package/src/node/storage.node.test.ts +5 -3
- package/src/node/storage.ts +2 -1
|
@@ -241,6 +241,13 @@ var getFullPath = (root, path) => join(root, stringDiff(path, root));
|
|
|
241
241
|
|
|
242
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;
|
|
@@ -341,10 +348,11 @@ var wrapFile = (native, type) => {
|
|
|
341
348
|
// src/common/abstract-storage.ts
|
|
342
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 = /* @__PURE__ */ new Map();
|
|
344
353
|
// TODO(burdon): Make required.
|
|
345
354
|
constructor(path) {
|
|
346
355
|
this.path = path;
|
|
347
|
-
this._files = /* @__PURE__ */ new Map();
|
|
348
356
|
}
|
|
349
357
|
[inspect.custom]() {
|
|
350
358
|
return inspectObject(this);
|
|
@@ -375,7 +383,7 @@ var AbstractStorage = class {
|
|
|
375
383
|
try {
|
|
376
384
|
log2.info("Erasing all data...", void 0, {
|
|
377
385
|
F: __dxlog_file2,
|
|
378
|
-
L:
|
|
386
|
+
L: 61,
|
|
379
387
|
S: this,
|
|
380
388
|
C: (f, a) => f(...a)
|
|
381
389
|
});
|
|
@@ -384,14 +392,14 @@ var AbstractStorage = class {
|
|
|
384
392
|
await this._destroy();
|
|
385
393
|
log2("Erased...", void 0, {
|
|
386
394
|
F: __dxlog_file2,
|
|
387
|
-
L:
|
|
395
|
+
L: 65,
|
|
388
396
|
S: this,
|
|
389
397
|
C: (f, a) => f(...a)
|
|
390
398
|
});
|
|
391
399
|
} catch (err) {
|
|
392
400
|
log2.catch(err, void 0, {
|
|
393
401
|
F: __dxlog_file2,
|
|
394
|
-
L:
|
|
402
|
+
L: 67,
|
|
395
403
|
S: this,
|
|
396
404
|
C: (f, a) => f(...a)
|
|
397
405
|
});
|
|
@@ -449,7 +457,7 @@ var AbstractStorage = class {
|
|
|
449
457
|
async _closeFilesInPath(path) {
|
|
450
458
|
await Promise.all(Array.from((await this._getFiles(path)).values()).map((file) => file.close().catch((err) => log2.catch(err, void 0, {
|
|
451
459
|
F: __dxlog_file2,
|
|
452
|
-
L:
|
|
460
|
+
L: 135,
|
|
453
461
|
S: this,
|
|
454
462
|
C: (f, a) => f(...a)
|
|
455
463
|
}))));
|
|
@@ -462,7 +470,7 @@ var AbstractStorage = class {
|
|
|
462
470
|
await Promise.all(Array.from(await this._getFiles(path)).map(([path2, file]) => {
|
|
463
471
|
return file.destroy().then(() => this._files.delete(path2)).catch((err) => log2.error(err.message, void 0, {
|
|
464
472
|
F: __dxlog_file2,
|
|
465
|
-
L:
|
|
473
|
+
L: 150,
|
|
466
474
|
S: this,
|
|
467
475
|
C: (f, a) => f(...a)
|
|
468
476
|
}));
|
|
@@ -475,7 +483,7 @@ import ram from "random-access-memory";
|
|
|
475
483
|
import { arrayToBuffer } from "@dxos/util";
|
|
476
484
|
|
|
477
485
|
// src/common/storage.ts
|
|
478
|
-
var StorageType = /* @__PURE__ */ function(StorageType2) {
|
|
486
|
+
var StorageType = /* @__PURE__ */ (function(StorageType2) {
|
|
479
487
|
StorageType2["RAM"] = "ram";
|
|
480
488
|
StorageType2["IDB"] = "idb";
|
|
481
489
|
StorageType2["CHROME"] = "chrome";
|
|
@@ -483,14 +491,11 @@ var StorageType = /* @__PURE__ */ function(StorageType2) {
|
|
|
483
491
|
StorageType2["NODE"] = "node";
|
|
484
492
|
StorageType2["WEBFS"] = "webfs";
|
|
485
493
|
return StorageType2;
|
|
486
|
-
}({});
|
|
494
|
+
})({});
|
|
487
495
|
|
|
488
496
|
// src/common/memory-storage.ts
|
|
489
497
|
var MemoryStorage = class extends AbstractStorage {
|
|
490
|
-
|
|
491
|
-
super(...arguments);
|
|
492
|
-
this.type = StorageType.RAM;
|
|
493
|
-
}
|
|
498
|
+
type = StorageType.RAM;
|
|
494
499
|
_createFile(path, filename) {
|
|
495
500
|
return this._patchFile(ram());
|
|
496
501
|
}
|
|
@@ -528,11 +533,13 @@ import { invariant } from "@dxos/invariant";
|
|
|
528
533
|
var __dxlog_file3 = "/__w/dxos/dxos/packages/common/random-access-storage/src/browser/idb-storage.ts";
|
|
529
534
|
var DELIM = "\0";
|
|
530
535
|
var IDbStorage = class extends AbstractStorage {
|
|
536
|
+
type = StorageType.IDB;
|
|
537
|
+
_db;
|
|
538
|
+
_store = "data";
|
|
539
|
+
_initialized = false;
|
|
540
|
+
_fileStorage;
|
|
531
541
|
constructor(path) {
|
|
532
542
|
super(path);
|
|
533
|
-
this.type = StorageType.IDB;
|
|
534
|
-
this._store = "data";
|
|
535
|
-
this._initialized = false;
|
|
536
543
|
this._fileStorage = this._createFileStorage(path);
|
|
537
544
|
}
|
|
538
545
|
_createFileStorage(path) {
|
|
@@ -636,10 +643,12 @@ function _ts_decorate(decorators, target, key, desc) {
|
|
|
636
643
|
}
|
|
637
644
|
var __dxlog_file4 = "/__w/dxos/dxos/packages/common/random-access-storage/src/browser/web-fs.ts";
|
|
638
645
|
var WebFS = class {
|
|
646
|
+
path;
|
|
647
|
+
_files = /* @__PURE__ */ new Map();
|
|
648
|
+
type = StorageType.WEBFS;
|
|
649
|
+
_root;
|
|
639
650
|
constructor(path) {
|
|
640
651
|
this.path = path;
|
|
641
|
-
this._files = /* @__PURE__ */ new Map();
|
|
642
|
-
this.type = StorageType.WEBFS;
|
|
643
652
|
}
|
|
644
653
|
get size() {
|
|
645
654
|
return this._files.size;
|
|
@@ -670,7 +679,7 @@ var WebFS = class {
|
|
|
670
679
|
this._root = await navigator.storage.getDirectory();
|
|
671
680
|
invariant2(this._root, "Root is undefined", {
|
|
672
681
|
F: __dxlog_file4,
|
|
673
|
-
L:
|
|
682
|
+
L: 74,
|
|
674
683
|
S: this,
|
|
675
684
|
A: [
|
|
676
685
|
"this._root",
|
|
@@ -718,7 +727,7 @@ var WebFS = class {
|
|
|
718
727
|
await Promise.all(Array.from(this._getFiles(path)).map(async ([path2, file]) => {
|
|
719
728
|
await file.destroy().catch((err) => log3.warn(err, void 0, {
|
|
720
729
|
F: __dxlog_file4,
|
|
721
|
-
L:
|
|
730
|
+
L: 117,
|
|
722
731
|
S: this,
|
|
723
732
|
C: (f, a) => f(...a)
|
|
724
733
|
}));
|
|
@@ -735,7 +744,7 @@ var WebFS = class {
|
|
|
735
744
|
err
|
|
736
745
|
}, {
|
|
737
746
|
F: __dxlog_file4,
|
|
738
|
-
L:
|
|
747
|
+
L: 127,
|
|
739
748
|
S: this,
|
|
740
749
|
C: (f, a) => f(...a)
|
|
741
750
|
}));
|
|
@@ -750,7 +759,7 @@ var WebFS = class {
|
|
|
750
759
|
e
|
|
751
760
|
}, {
|
|
752
761
|
F: __dxlog_file4,
|
|
753
|
-
L:
|
|
762
|
+
L: 137,
|
|
754
763
|
S: this,
|
|
755
764
|
C: (f, a) => f(...a)
|
|
756
765
|
}));
|
|
@@ -791,64 +800,67 @@ _ts_decorate([
|
|
|
791
800
|
synchronized
|
|
792
801
|
], WebFS.prototype, "_initialize", null);
|
|
793
802
|
var WebFile = class extends EventEmitter {
|
|
803
|
+
fileName;
|
|
804
|
+
_fileHandle;
|
|
805
|
+
_destroy;
|
|
806
|
+
/**
|
|
807
|
+
* Current view of the file contents.
|
|
808
|
+
*/
|
|
809
|
+
_buffer = null;
|
|
810
|
+
_loadBufferPromise = null;
|
|
811
|
+
_flushScheduled = false;
|
|
812
|
+
_flushPromise = Promise.resolve();
|
|
813
|
+
/**
|
|
814
|
+
* Used to discard unnecessary scheduled flushes.
|
|
815
|
+
* If _flushNow() is called with a lower sequence number it should early exit.
|
|
816
|
+
*/
|
|
817
|
+
_flushSequence = 0;
|
|
818
|
+
//
|
|
819
|
+
// Metrics
|
|
820
|
+
//
|
|
821
|
+
_flushes = new TimeSeriesCounter();
|
|
822
|
+
_operations = new TimeSeriesCounter();
|
|
823
|
+
_reads = new TimeSeriesCounter();
|
|
824
|
+
_readBytes = new TimeSeriesCounter();
|
|
825
|
+
_writes = new TimeSeriesCounter();
|
|
826
|
+
_writeBytes = new TimeSeriesCounter();
|
|
827
|
+
get _bufferSize() {
|
|
828
|
+
return this._buffer?.length;
|
|
829
|
+
}
|
|
794
830
|
constructor({ fileName, file, destroy }) {
|
|
795
831
|
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
832
|
this.fileName = fileName;
|
|
845
833
|
this._fileHandle = file;
|
|
846
834
|
this._destroy = destroy;
|
|
847
835
|
void this._loadBufferGuarded();
|
|
848
836
|
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
837
|
+
type = StorageType.WEBFS;
|
|
838
|
+
//
|
|
839
|
+
// random-access-storage library compatibility
|
|
840
|
+
//
|
|
841
|
+
// TODO(dmaretskyi): Are those all needed?
|
|
842
|
+
opened = true;
|
|
843
|
+
suspended = false;
|
|
844
|
+
closed = false;
|
|
845
|
+
unlinked = false;
|
|
846
|
+
writing = false;
|
|
847
|
+
readable = true;
|
|
848
|
+
writable = true;
|
|
849
|
+
deletable = true;
|
|
850
|
+
truncatable = true;
|
|
851
|
+
statable = true;
|
|
852
|
+
destroyed = false;
|
|
853
|
+
directory = "";
|
|
854
|
+
// TODO(dmaretskyi): is this used?
|
|
855
|
+
filename = "";
|
|
856
|
+
native = {
|
|
857
|
+
write: callbackify(this.write.bind(this)),
|
|
858
|
+
read: callbackify(this.read.bind(this)),
|
|
859
|
+
del: callbackify(this.del.bind(this)),
|
|
860
|
+
stat: callbackify(this.stat.bind(this)),
|
|
861
|
+
destroy: callbackify(this.destroy.bind(this)),
|
|
862
|
+
truncate: callbackify(this.truncate?.bind(this))
|
|
863
|
+
};
|
|
852
864
|
async _loadBuffer() {
|
|
853
865
|
const fileHandle = await this._fileHandle;
|
|
854
866
|
const file = await fileHandle.getFile();
|
|
@@ -867,7 +879,7 @@ var WebFile = class extends EventEmitter {
|
|
|
867
879
|
await this._loadBufferGuarded();
|
|
868
880
|
invariant2(this._buffer, void 0, {
|
|
869
881
|
F: __dxlog_file4,
|
|
870
|
-
L:
|
|
882
|
+
L: 301,
|
|
871
883
|
S: this,
|
|
872
884
|
A: [
|
|
873
885
|
"this._buffer",
|
|
@@ -895,7 +907,7 @@ var WebFile = class extends EventEmitter {
|
|
|
895
907
|
this._flushScheduled = false;
|
|
896
908
|
this._flushPromise = this._flushCache(sequence).catch((err) => log3.warn(err, void 0, {
|
|
897
909
|
F: __dxlog_file4,
|
|
898
|
-
L:
|
|
910
|
+
L: 319,
|
|
899
911
|
S: this,
|
|
900
912
|
C: (f, a) => f(...a)
|
|
901
913
|
}));
|
|
@@ -906,7 +918,7 @@ var WebFile = class extends EventEmitter {
|
|
|
906
918
|
await this._flushPromise;
|
|
907
919
|
this._flushPromise = this._flushCache(this._flushSequence).catch((err) => log3.warn(err, void 0, {
|
|
908
920
|
F: __dxlog_file4,
|
|
909
|
-
L:
|
|
921
|
+
L: 327,
|
|
910
922
|
S: this,
|
|
911
923
|
C: (f, a) => f(...a)
|
|
912
924
|
}));
|
|
@@ -921,7 +933,7 @@ var WebFile = class extends EventEmitter {
|
|
|
921
933
|
await this._loadBufferGuarded();
|
|
922
934
|
invariant2(this._buffer, void 0, {
|
|
923
935
|
F: __dxlog_file4,
|
|
924
|
-
L:
|
|
936
|
+
L: 340,
|
|
925
937
|
S: this,
|
|
926
938
|
A: [
|
|
927
939
|
"this._buffer",
|
|
@@ -943,7 +955,7 @@ var WebFile = class extends EventEmitter {
|
|
|
943
955
|
await this._loadBufferGuarded();
|
|
944
956
|
invariant2(this._buffer, void 0, {
|
|
945
957
|
F: __dxlog_file4,
|
|
946
|
-
L:
|
|
958
|
+
L: 360,
|
|
947
959
|
S: this,
|
|
948
960
|
A: [
|
|
949
961
|
"this._buffer",
|
|
@@ -971,7 +983,7 @@ var WebFile = class extends EventEmitter {
|
|
|
971
983
|
await this._loadBufferGuarded();
|
|
972
984
|
invariant2(this._buffer, void 0, {
|
|
973
985
|
F: __dxlog_file4,
|
|
974
|
-
L:
|
|
986
|
+
L: 387,
|
|
975
987
|
S: this,
|
|
976
988
|
A: [
|
|
977
989
|
"this._buffer",
|
|
@@ -994,7 +1006,7 @@ var WebFile = class extends EventEmitter {
|
|
|
994
1006
|
await this._loadBufferGuarded();
|
|
995
1007
|
invariant2(this._buffer, void 0, {
|
|
996
1008
|
F: __dxlog_file4,
|
|
997
|
-
L:
|
|
1009
|
+
L: 409,
|
|
998
1010
|
S: this,
|
|
999
1011
|
A: [
|
|
1000
1012
|
"this._buffer",
|
|
@@ -1013,7 +1025,7 @@ var WebFile = class extends EventEmitter {
|
|
|
1013
1025
|
await this._loadBufferGuarded();
|
|
1014
1026
|
invariant2(this._buffer, void 0, {
|
|
1015
1027
|
F: __dxlog_file4,
|
|
1016
|
-
L:
|
|
1028
|
+
L: 424,
|
|
1017
1029
|
S: this,
|
|
1018
1030
|
A: [
|
|
1019
1031
|
"this._buffer",
|