module worldsibu import * as CouchDB from 'node-couchdb' ; import { BaseStorage , InvalidIdError } from '@worldsibu/convector-core' ; export class CouchDBStorage extends BaseStorage { private couch : any ; constructor ( config , public defaultDB ? ) { super ( ) ; this . couch = new CouchDB ( config ) ; } public updateDefaultDB ( defaultDB ) { this . defaultDB = defaultDB ; } public async query ( ... args ) { let db = this . defaultDB ; if ( args . length > 1 ) { db = args . shift ( ) ; } const result = await this . couch . get ( db , ... args ) ; if ( result ) { if ( result . docs ) { return result . docs ; } if ( result . data && Array . isArray ( result . data . rows ) ) { return result . data . rows . map ( data => data . value ) ; } } return [ ] ; } public async get ( id ) { InvalidIdError . test ( id ) ; const result = await this . couch . get ( this . defaultDB , id ) ; return result . data ; } public async set ( id , content ) { throw new Error ( 'The method `set` in the CouchDB storage is not supported' ) ; } public async delete ( id ) { throw new Error ( 'The method `delete` in the CouchDB storage is not supported' ) ; } public async history ( id ) { throw new Error ( 'The method `history` in the CouchDB storage is not supported' ) ; } }