File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { CID } from 'multiformats'
3
3
import { extractVerifiedContent } from './utils/car.js'
4
4
import { asAsyncIterable , asyncIteratorToBuffer } from './utils/itr.js'
5
5
import { randomUUID } from './utils/uuid.js'
6
+ import { memoryStorage } from './utils/storage.js'
6
7
7
8
class Saturn {
8
9
/**
@@ -12,6 +13,7 @@ class Saturn {
12
13
* @param {string } [opts.cdnURL=saturn.ms]
13
14
* @param {number } [opts.connectTimeout=5000]
14
15
* @param {number } [opts.downloadTimeout=0]
16
+ * @param {import('./utils/storage.js').Storage } [opts.storage]
15
17
*/
16
18
constructor ( opts = { } ) {
17
19
this . opts = Object . assign ( { } , {
@@ -20,9 +22,11 @@ class Saturn {
20
22
logURL : 'https://twb3qukm2i654i3tnvx36char40aymqq.lambda-url.us-west-2.on.aws/' ,
21
23
connectTimeout : 5_000 ,
22
24
downloadTimeout : 0
25
+
23
26
} , opts )
24
27
25
28
this . logs = [ ]
29
+ this . storage = this . opts . storage || memoryStorage ( )
26
30
this . reportingLogs = process ?. env ?. NODE_ENV !== 'development'
27
31
this . hasPerformanceAPI = typeof window !== 'undefined' && window ?. performance
28
32
if ( this . reportingLogs && this . hasPerformanceAPI ) {
Original file line number Diff line number Diff line change @@ -36,3 +36,24 @@ export function indexedDbStorage () {
36
36
delete : async ( key ) => indexedDbExists && ( await dbPromise ) . delete ( DEFAULT_SATURN_STORAGE_NAME , key )
37
37
}
38
38
}
39
+
40
+ /**
41
+ * @function memoryStorage
42
+ * @returns {Storage }
43
+ */
44
+ export function memoryStorage ( ) {
45
+ const storageObject = { }
46
+
47
+ return {
48
+ check : ( ) => true , // Memory storage is always accessible
49
+ get : ( key ) => Promise . resolve ( storageObject [ key ] ) ,
50
+ set : ( key , value ) => {
51
+ storageObject [ key ] = value
52
+ return Promise . resolve ( )
53
+ } ,
54
+ delete : ( key ) => {
55
+ delete storageObject [ key ]
56
+ return Promise . resolve ( )
57
+ }
58
+ }
59
+ }
You can’t perform that action at this time.
0 commit comments