-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
21 changed files
with
285 additions
and
108 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
module.exports = { | ||
"extends": "standard", | ||
"parser": "babel-eslint", | ||
"rules": { | ||
"indent": [2, 4], | ||
"promise/param-names": 0, | ||
"comma-dangle": [2, "always-multiline"], | ||
extends: 'standard', | ||
parser: 'babel-eslint', | ||
rules: { | ||
'indent': [2, 4], | ||
'promise/param-names': 0, | ||
'comma-dangle': [2, 'always-multiline'], | ||
}, | ||
} |
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 |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { PluginFunction } from 'vue' | ||
|
||
/* -- types -- */ | ||
|
||
export type AnyFunction = (...args: any[]) => any | ||
export type AnyPromiseFunction<T = any> = (...args: any[]) => Promise<T> | ||
|
||
export type SaveParamsType = SaveParamsWithKey | SaveParamsWithFullKey | ||
export type LoadParamsType = LoadParamsWithKey | LoadParamsWithFullKey | ||
export type RemoveParamsType = string | RemoveParams | ||
export type LoadSyncParamsType = LoadSyncParamsWithKey | LoadSyncParamsWithFullKey | ||
|
||
/* -- interfaces -- */ | ||
|
||
export interface KeyAndSyncParams { | ||
key: string | ||
syncParams?: object | ||
} | ||
export interface FullKey { | ||
fullKey: string | ||
} | ||
|
||
export interface SaveParams { | ||
data?: any | ||
expires?: number | ||
isEnableCache?: boolean | ||
[k: string]: any | ||
} | ||
export interface SaveParamsWithKey extends KeyAndSyncParams, SaveParams {} | ||
export interface SaveParamsWithFullKey extends FullKey, SaveParams {} | ||
|
||
export interface LoadSyncParams { | ||
isEnableCache?: boolean | ||
[k: string]: any | ||
} | ||
export interface LoadParams extends LoadSyncParams { | ||
syncFn?: AnyPromiseFunction | ||
expires?: number | ||
isAutoSave?: boolean | ||
syncOptions?: object | any[] | ||
isForceUpdate?: boolean | ||
[k: string]: any | ||
} | ||
export interface LoadParamsWithKey extends KeyAndSyncParams, LoadParams {} | ||
export interface LoadParamsWithFullKey extends FullKey, LoadParams {} | ||
export interface LoadSyncParamsWithKey extends KeyAndSyncParams, LoadSyncParams {} | ||
export interface LoadSyncParamsWithFullKey extends FullKey, LoadSyncParams {} | ||
|
||
export interface RemoveParams { | ||
prefix: string | ||
} | ||
|
||
export interface TuaStorageOptions { | ||
whiteList?: string[], | ||
syncFnMap?: object, | ||
autoClearTime?: number, | ||
storageEngine?: null | object, | ||
defaultExpires?: number, | ||
neverExpireMark?: null | string, | ||
storageKeyPrefix?: string, | ||
isEnableAutoClear?: boolean, | ||
} | ||
|
||
export interface TuaStorageClass { | ||
/** | ||
* https://tuateam.github.io/tua-storage/config-methods/default.html | ||
*/ | ||
new (args?: TuaStorageOptions): TuaStorageInstance | ||
|
||
/** | ||
* https://tuateam.github.io/tua-storage/config-methods/default.html | ||
*/ | ||
install: PluginFunction<TuaStorageOptions> | ||
} | ||
|
||
export interface TuaStorageInstance { | ||
// public | ||
save: <T = any>(item: SaveParamsType | SaveParamsType[]) => Promise<T> | ||
load: <T = any>(item: LoadParamsType | LoadParamsType[]) => Promise<T> | ||
clear: <T = any>(whiteList?: string[]) => Promise<T> | ||
remove: <T = any>(prefix: RemoveParamsType | RemoveParamsType[]) => Promise<T> | ||
getInfo: <T = any>() => Promise<T> | ||
saveSync: (item: SaveParamsType | SaveParamsType[]) => any | ||
loadSync: (item: LoadSyncParamsType | LoadSyncParamsType[]) => any | ||
clearSync: (whiteList?: string[]) => any | ||
removeSync: (prefix: RemoveParamsType | RemoveParamsType[]) => any | ||
getInfoSync: () => any | ||
|
||
// private | ||
_cache: object | ||
_clearExpiredData: <T = any>() => Promise<T> | ||
} | ||
|
||
/* -- export default -- */ | ||
|
||
declare const TuaStorage: TuaStorageClass | ||
export default TuaStorage | ||
|
||
/* -- vue plugin -- */ | ||
|
||
declare module 'vue/types/vue' { | ||
interface Vue { | ||
/** | ||
* https://tuateam.github.io/tua-storage/config-methods/methods.html | ||
*/ | ||
$tuaStorage: TuaStorageInstance | ||
} | ||
} |
Oops, something went wrong.