import * as Datastore from 'nedb' ; export default class NedbDatastore { datastore : Datastore ; constructor ( datastore ) { this . datastore = datastore ; } find < A > ( query ) { return new Promise < Array < A > > ( ( resolve , reject ) => { this . datastore . find < A > ( query , ( error , documents ) => { error ? reject ( error ) : resolve ( documents ) ; } ) ; } ) ; } findOne < A > ( query ) { return new Promise < A > ( ( resolve , reject ) => { this . datastore . findOne < A > ( query , ( error , documents ) => { error ? reject ( error ) : resolve ( documents ) ; } ) ; } ) ; } update < A > ( query , updateQuery , options ? ) { return new Promise < number > ( ( resolve , reject ) => { this . datastore . update < A > ( query , updateQuery , options , ( error , numberOfUpdates , upsert ) => { error ? reject ( error ) : resolve ( numberOfUpdates ) ; } ) ; } ) ; } insert < A > ( newDoc ) { return new Promise < void > ( ( resolve , reject ) => { this . datastore . insert ( newDoc , ( err ) => { err ? reject ( err ) : resolve ( ) ; } ) ; } ) ; } count ( query ) { return new Promise < number > ( ( resolve , reject ) => { this . datastore . count ( query , ( err , count ) => { err ? reject ( err ) : resolve ( count ) ; } ) ; } ) ; } remove ( query , options ) { return new Promise < number > ( ( resolve , reject ) => { this . datastore . remove ( query , options , ( err , count ) => { err ? reject ( err ) : resolve ( count ) ; } ) ; } ) ; } }