File tree Expand file tree Collapse file tree 4 files changed +33
-23
lines changed Expand file tree Collapse file tree 4 files changed +33
-23
lines changed Original file line number Diff line number Diff line change @@ -3,7 +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
+ import { memoryStorage } from './utils/storage/index .js'
7
7
8
8
class Saturn {
9
9
/**
Original file line number Diff line number Diff line change
1
+
2
+ // @ts -check
3
+
4
+ import { indexedDbStorage } from './indexed-db-storage.js'
5
+ import { memoryStorage } from './memory-storage.js'
6
+
7
+ /**
8
+ * @typedef {object } Storage
9
+ * @property {function(string):Promise<any> } get - Retrieves the value associated with the key.
10
+ * @property {function(string,any):Promise<void> } set - Sets a new value for the key.
11
+ * @property {function(string):Promise<any> } delete - Deletes the value associated with the key.
12
+ */
13
+
14
+ export {
15
+ indexedDbStorage ,
16
+ memoryStorage
17
+ }
Original file line number Diff line number Diff line change @@ -6,16 +6,9 @@ const DEFAULT_IDB_VERSION = 1
6
6
const DEFAULT_IDB_STORAGE_NAME = 'saturn-db'
7
7
const DEFAULT_SATURN_STORAGE_NAME = 'saturn-client'
8
8
9
- /**
10
- * @typedef {object } Storage
11
- * @property {function(string):Promise<any> } get - Retrieves the value associated with the key.
12
- * @property {function(string,any):Promise<void> } set - Sets a new value for the key.
13
- * @property {function(string):Promise<any> } delete - Deletes the value associated with the key.
14
- */
15
-
16
9
/**
17
10
* @function indexedDbStorage
18
- * @returns {Storage }
11
+ * @returns {import('./index.js'). Storage }
19
12
*/
20
13
export function indexedDbStorage ( ) {
21
14
const indexedDbExists = ( typeof window !== 'undefined' ) && window ?. indexedDB
@@ -34,17 +27,3 @@ export function indexedDbStorage () {
34
27
delete : async ( key ) => indexedDbExists && ( await dbPromise ) . delete ( DEFAULT_SATURN_STORAGE_NAME , key )
35
28
}
36
29
}
37
-
38
- /**
39
- * @function memoryStorage
40
- * @returns {Storage }
41
- */
42
- export function memoryStorage ( ) {
43
- const storageObject = { }
44
-
45
- return {
46
- get : async ( key ) => storageObject [ key ] ,
47
- set : async ( key , value ) => { storageObject [ key ] = value } ,
48
- delete : async ( key ) => { delete storageObject [ key ] }
49
- }
50
- }
Original file line number Diff line number Diff line change
1
+
2
+ /**
3
+ * @function memoryStorage
4
+ * @returns {import('./index.js').Storage }
5
+ */
6
+ export function memoryStorage ( ) {
7
+ const storageObject = { }
8
+
9
+ return {
10
+ get : async ( key ) => storageObject [ key ] ,
11
+ set : async ( key , value ) => { storageObject [ key ] = value } ,
12
+ delete : async ( key ) => { delete storageObject [ key ] }
13
+ }
14
+ }
You can’t perform that action at this time.
0 commit comments