Comparing version 0.2.0 to 0.3.0
@@ -12,7 +12,13 @@ export interface Data<V> { | ||
}; | ||
export declare function makeField<T = any>(kv: KeyvFile, key: string, defaults?: T): { | ||
get(def?: T | undefined): T | undefined; | ||
set(val?: T | undefined): void; | ||
delete(): any; | ||
}; | ||
export declare class Field<T, D extends T | void> { | ||
protected kv: KeyvFile; | ||
protected key: string; | ||
protected defaults?: D | undefined; | ||
constructor(kv: KeyvFile, key: string, defaults?: D | undefined); | ||
get(): D; | ||
get(def: D): D; | ||
set(val?: T): Promise<any>; | ||
delete(): boolean; | ||
} | ||
export declare function makeField<T = any>(kv: KeyvFile, key: string, defaults?: T): Field<{}, T>; | ||
export declare class KeyvFile<V = any> { | ||
@@ -23,7 +29,6 @@ ttlSupport: boolean; | ||
private _lastExpire; | ||
private _saveTimer?; | ||
constructor(opts?: Partial<typeof defaultOpts>); | ||
isExpired(data: Data<V>): boolean; | ||
get<T = V>(key: string, defaults: T): T; | ||
get<T = V>(key: string): T | undefined; | ||
get<T = V>(key: string): T | void; | ||
has(key: string): boolean; | ||
@@ -37,5 +42,5 @@ keys(): string[]; | ||
*/ | ||
set<T = V>(key: string, value: T, ttl?: number): void; | ||
delete<T = V>(key: string): T; | ||
clear(): void; | ||
set<T = V>(key: string, value: T, ttl?: number): Promise<any>; | ||
delete(key: string): boolean; | ||
clear(): Promise<any>; | ||
clearExpire(): void; | ||
@@ -42,0 +47,0 @@ saveToDisk(): Promise<void>; |
@@ -18,14 +18,21 @@ 'use strict'; | ||
}; | ||
class Field { | ||
constructor(kv, key, defaults) { | ||
this.kv = kv; | ||
this.key = key; | ||
this.defaults = defaults; | ||
} | ||
get(def = this.defaults) { | ||
return this.kv.get(this.key, def); | ||
} | ||
set(val) { | ||
return this.kv.set(this.key, val); | ||
} | ||
delete() { | ||
return this.kv.delete(this.key); | ||
} | ||
} | ||
exports.Field = Field; | ||
function makeField(kv, key, defaults) { | ||
return { | ||
get(def = defaults) { | ||
return kv.get(key, def); | ||
}, | ||
set(val) { | ||
return kv.set(key, val); | ||
}, | ||
delete() { | ||
return kv.delete(key); | ||
}, | ||
}; | ||
return new Field(kv, key, defaults); | ||
} | ||
@@ -105,3 +112,3 @@ exports.makeField = makeField; | ||
}); | ||
this.save(); | ||
return this.save(); | ||
} | ||
@@ -116,3 +123,3 @@ delete(key) { | ||
this._lastExpire = Date.now(); | ||
this.save(); | ||
return this.save(); | ||
} | ||
@@ -158,6 +165,6 @@ clearExpire() { | ||
this._savePromise = new Promise((resolve, reject) => { | ||
this._saveTimer = setTimeout(() => { | ||
this.saveToDisk().then(resolve, reject).then(() => { | ||
setTimeout(() => { | ||
this.saveToDisk().then(() => { | ||
this._savePromise = void 0; | ||
}); | ||
}).then(resolve, reject); | ||
}, this._opts.writeDelay); | ||
@@ -164,0 +171,0 @@ }); |
{ | ||
"name": "keyv-file", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "File storage adapter for Keyv, using msgpack to serialize data fast and small.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -23,3 +23,3 @@ # keyv-file [<img width="100" align="right" src="https://rawgit.com/lukechilds/keyv/master/media/logo.svg" alt="keyv">](https://github.com/lukechilds/keyv) | ||
const Keyv = require('keyv') | ||
const KeyvFile = require('keyv-file').KeyvFile | ||
const { KeyvFile } = require('keyv-file') | ||
@@ -26,0 +26,0 @@ const keyv = new Keyv({ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10112
220