Skip to content

Commit

Permalink
validate and extend typings by testing it against runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
sod committed Jun 13, 2018
1 parent 14bfa6e commit c822d90
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,50 @@
namespace Receptacle {
export interface Options {
id?: string;
export interface Options<T> {
id?: number|string;
max?: number;
items?: any[];
items?: Items<T>[];
lastModified?: Date;
}

export interface Export<T, X> {
id: number|string;
max: number|undefined;
items: (Items<T> & InternalItemData<T>)[];
lastModified: Date;
}

export interface SetOptions<X> {
ttl?: number;
refresh?: boolean;
meta?: X;
}

export interface InternalItemData<X> {
meta: X|undefined;
refresh: number|undefined;
expires: number|undefined;
}

export interface Items<T> {
key: string;
value: T;
}
}

class Receptacle<T, X = undefined> {
constructor(options?: Receptacle.Options);
public id: string;
constructor(options?: Receptacle.Options<T>);
public id: number|string;
public max: number;
public items: T[];
public items: Receptacle.Items<T>[];
public size: number;
public has(key: string): boolean;
public get(key: string): T;
public meta(key: string): X;
public set(key: string, value: T, options?: Receptacle.SetOptions<X>): void;
public get(key: string): T|null;
public meta(key: string): X|undefined;
public set(key: string, value: T, options?: Receptacle.SetOptions<X>): Receptacle;
public delete(key: string): void;
public expire(key: string, ms: number = 0): void;
public clear(): void;
public toJSON(): Receptacle.Export<T, X>;
}

export = Receptacle;

0 comments on commit c822d90

Please sign in to comment.