-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolves #3
- Loading branch information
Showing
9 changed files
with
135 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,42 @@ | ||
export type StorageValue = null | string | String | number | Number | boolean | Boolean | object | ||
|
||
export type WatchEvent = 'update' | 'remove' | ||
export type WatchCallback = (event: WatchEvent, key: string) => any | ||
|
||
export interface StorageMeta { | ||
atime?: Date, | ||
mtime?: Date | ||
[key: string]: StorageValue | Date | undefined | ||
} | ||
|
||
export interface Driver { | ||
hasItem: (key: string) => boolean | Promise<boolean> | ||
getItem: (key: string) => StorageValue | ||
setItem: (key: string, value: string) => void | Promise<void> | ||
removeItem: (key: string) => void | Promise<void> | ||
getMeta?: (key: string) => StorageMeta | Promise<StorageMeta> | ||
getKeys: () => string[] | Promise<string[]> | ||
clear: () => void | Promise<void> | ||
dispose?: () => void | Promise<void> | ||
watch?: (callback: WatchCallback) => void | Promise<void> | ||
} | ||
|
||
export interface Storage { | ||
// Item | ||
hasItem: (key: string) => Promise<boolean> | ||
getItem: (key: string) => Promise<StorageValue> | ||
setItem: (key: string, value: StorageValue) => Promise<void> | ||
removeItem: (key: string) => Promise<void> | ||
removeItem: (key: string, removeMeta?: boolean) => Promise<void> | ||
// Meta | ||
getMeta: (key: string, nativeMetaOnly?: true) => StorageMeta | Promise<StorageMeta> | ||
setMeta: (key: string, value: StorageMeta) => Promise<void> | ||
removeMeta: (key: string) => Promise<void> | ||
// Keys | ||
getKeys: (base?: string) => Promise<string[]> | ||
// Utils | ||
clear: (base?: string) => Promise<void> | ||
mount: (base: string, driver: Driver) => Storage | ||
unmount: (base: string, dispose?: boolean) => Promise<void> | ||
dispose: () => Promise<void> | ||
watch: (callback: WatchCallback) => Promise<void> | ||
// Mount | ||
mount: (base: string, driver: Driver) => Storage | ||
unmount: (base: string, dispose?: boolean) => Promise<void> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters