Skip to content

Commit

Permalink
feat: add IStorage
Browse files Browse the repository at this point in the history
feat: add IStorage

closes #16
  • Loading branch information
oljekechoro authored and antongolub committed Apr 13, 2019
1 parent bf4f88b commit 7dab170
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/types/src/main/IStorage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export type TStorageKey = string
export type TStorageValue = any
export type TStorageTTL = number

export interface IStorage {
get: (key: TStorageKey) => TStorageValue
set: (key: TStorageKey, value: TStorageValue, ttl?: TStorageTTL) => void
has: (key: TStorageKey) => boolean
remove: (key: TStorageKey) => void
size: () => number
reset: () => void
}
1 change: 1 addition & 0 deletions packages/types/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export { TUtilMap } from './IUtilMap'
export { ICloneable } from './ICloneable'
export { ICurrency } from './ICurrency'
export { IPromiseConstructor, IPromise } from './IPromise'
export { IStorage } from './IStorage'
export { IMoney } from './IMoney'
32 changes: 32 additions & 0 deletions packages/types/src/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ICurrency,
IPromise,
IPromiseConstructor,
IStorage,
IMoney
} from '../main';

Expand Down Expand Up @@ -149,7 +150,38 @@ const bluebirdPromiseConstructor: IPromiseConstructor = BluebirdPromise;
const nativePromise: IPromise<number> = new Promise<number>(executor);
const bluebirdPromise: IPromise<number> = new BluebirdPromise<number>(executor);

// IStorage

const storage: IStorage = {
get: (key: string): any => key,
set: (key: string, value: any, ttl?: number): any => ttl || key || value,
has: (key: string) => {
key;
return false;
},
remove: (key: string) => {
key;
},
size: () => 42,
reset: () => {}
};

const brokenStorage: IStorage = {
get: (key: string): any => key,
set: (key: string, value: any, ttl?: number): any => ttl || key || value,
has: (key: string) => { // $ExpectError
key;
return 42;
},
remove: (key: string) => {
key;
},
size: () => 42,
reset: () => {}
};

// IMoney

const brokenMoney: IMoney = {
value: 123,
toString() { // $ExpectError
Expand Down

0 comments on commit 7dab170

Please sign in to comment.