1- import { Buffer } from 'buffer' ;
1+ import { Buffer } from 'buffer' ;
22
33const service = 'http://localhost:5984/hyperglosae' ;
44
5- function Hyperglosae ( logger ) {
5+ function Hyperglosae ( logger ) {
66
77 this . credentials = { } ;
88
9- this . getView = ( { view, id, options = [ ] } ) =>
9+ this . getView = ( { view, id, options = [ ] } ) =>
1010 fetch ( `${
1111 service
1212 } /_design/app/_view/${
@@ -23,8 +23,8 @@ function Hyperglosae(logger) {
2323 fetch ( `${ service } /${ id } ` )
2424 . then ( x => x . json ( ) ) ;
2525
26- let basicAuthentication = ( { force} ) => {
27- let { name, password} = this . credentials ;
26+ let basicAuthentication = ( { force } ) => {
27+ let { name, password } = this . credentials ;
2828 if ( ! force && ! name && ! password ) return ( { } ) ;
2929 return ( {
3030 'Authorization' : 'Basic ' + Buffer . from ( `${ name } :${ password } ` ) . toString ( 'base64' )
@@ -34,7 +34,7 @@ function Hyperglosae(logger) {
3434 this . putDocument = ( doc ) =>
3535 fetch ( `${ service } /${ doc . _id } ` , {
3636 method : 'PUT' ,
37- headers : basicAuthentication ( { force : false } ) ,
37+ headers : basicAuthentication ( { force : false } ) ,
3838 body : JSON . stringify ( doc )
3939 } )
4040 . then ( x => x . json ( ) )
@@ -46,13 +46,14 @@ function Hyperglosae(logger) {
4646 return x ;
4747 } ) ;
4848
49- this . getDocumentMetadata = ( id ) =>
50- fetch ( `${ service } /${ id } ` , {
49+ this . getDocumentMetadata = ( id ) => {
50+ return fetch ( `${ service } /${ id } ` , {
5151 method : 'HEAD' ,
5252 headers : basicAuthentication ( { force : false } )
5353 } ) ;
54+ } ;
5455
55- this . putAttachment = ( id , attachment , callback ) =>
56+ this . putAttachment = ( id , attachment , callback ) => {
5657 this . getDocumentMetadata ( id ) . then ( x => {
5758 const reader = new FileReader ( ) ;
5859 reader . readAsArrayBuffer ( attachment ) ;
@@ -71,12 +72,13 @@ function Hyperglosae(logger) {
7172 } ) . then ( response => callback ( response ) ) ;
7273 } ;
7374 } ) ;
75+ } ;
7476
75- this . authenticate = ( { name, password} ) => {
76- this . credentials = { name, password} ;
77+ this . authenticate = ( { name, password } ) => {
78+ this . credentials = { name, password } ;
7779 return fetch ( `${ service } ` , {
7880 method : 'GET' ,
79- headers : basicAuthentication ( { force : true } )
81+ headers : basicAuthentication ( { force : true } )
8082 } )
8183 . then ( x => x . json ( ) )
8284 . then ( x => {
@@ -89,7 +91,7 @@ function Hyperglosae(logger) {
8991 } ;
9092
9193 this . refreshMetadata = ( id , callback ) => {
92- this . getView ( { view : 'metadata' , id, options : [ 'include_docs' ] } )
94+ this . getView ( { view : 'metadata' , id, options : [ 'include_docs' ] } )
9395 . then (
9496 ( rows ) => {
9597 let documents = rows . map ( x => x . doc ) ;
@@ -99,7 +101,7 @@ function Hyperglosae(logger) {
99101 } ;
100102
101103 this . refreshContent = ( id , callback ) => {
102- this . getView ( { view : 'content' , id, options : [ 'include_docs' ] } )
104+ this . getView ( { view : 'content' , id, options : [ 'include_docs' ] } )
103105 . then (
104106 ( rows ) => {
105107 callback ( rows ) ;
@@ -112,11 +114,11 @@ function Hyperglosae(logger) {
112114
113115 this . refreshDocuments = ( callback ) => {
114116 let id = this . credentials . name || 'PUBLIC' ;
115- this . getView ( { view : 'all_documents' , id, options : [ 'group' ] } )
117+ this . getView ( { view : 'all_documents' , id, options : [ 'group' ] } )
116118 . then ( ( rows ) => {
117119 callback (
118120 rows . map (
119- ( { value} ) => ( { ...value . metadata , referenced : value . referenced } )
121+ ( { value } ) => ( { ...value . metadata , referenced : value . referenced } )
120122 )
121123 ) ;
122124 } ) ;
0 commit comments