@@ -35,16 +35,16 @@ const MAX_SIMULTANEOUS_REVS = 50;
3535const CHANGES_TIMEOUT_BUFFER = 5000 ;
3636const DEFAULT_HEARTBEAT = 10000 ;
3737
38- let supportsBulkGetMap = { } ;
38+ const supportsBulkGetMap = { } ;
3939
4040function readAttachmentsAsBlobOrBuffer ( row ) {
41- let doc = row . doc || row . ok ;
42- let atts = doc && doc . _attachments ;
41+ const doc = row . doc || row . ok ;
42+ const atts = doc && doc . _attachments ;
4343 if ( ! atts ) {
4444 return ;
4545 }
4646 Object . keys ( atts ) . forEach ( function ( filename ) {
47- let att = atts [ filename ] ;
47+ const att = atts [ filename ] ;
4848 att . data = b64StringToBluffer ( att . data , att . content_type ) ;
4949 } ) ;
5050}
@@ -65,7 +65,7 @@ function preprocessAttachments(doc) {
6565 }
6666
6767 return Promise . all ( Object . keys ( doc . _attachments ) . map ( function ( key ) {
68- let attachment = doc . _attachments [ key ] ;
68+ const attachment = doc . _attachments [ key ] ;
6969 if ( attachment . data && typeof attachment . data !== 'string' ) {
7070 return new Promise ( function ( resolve ) {
7171 blufferToBase64 ( attachment . data , resolve ) ;
@@ -80,7 +80,7 @@ function hasUrlPrefix(opts) {
8080 if ( ! opts . prefix ) {
8181 return false ;
8282 }
83- let protocol = parseUri ( opts . prefix ) . protocol ;
83+ const protocol = parseUri ( opts . prefix ) . protocol ;
8484 return protocol === 'http' || protocol === 'https' ;
8585}
8686
@@ -89,20 +89,20 @@ function hasUrlPrefix(opts) {
8989function getHost ( name , opts ) {
9090 // encode db name if opts.prefix is a url (#5574)
9191 if ( hasUrlPrefix ( opts ) ) {
92- let dbName = opts . name . substr ( opts . prefix . length ) ;
92+ const dbName = opts . name . substr ( opts . prefix . length ) ;
9393 // Ensure prefix has a trailing slash
94- let prefix = opts . prefix . replace ( / \/ ? $ / , '/' ) ;
94+ const prefix = opts . prefix . replace ( / \/ ? $ / , '/' ) ;
9595 name = prefix + encodeURIComponent ( dbName ) ;
9696 }
9797
98- let uri = parseUri ( name ) ;
98+ const uri = parseUri ( name ) ;
9999 if ( uri . user || uri . password ) {
100100 uri . auth = { username : uri . user , password : uri . password } ;
101101 }
102102
103103 // Split the path part of the URI into parts using '/' as the delimiter
104104 // after removing any leading '/' and any trailing '/'
105- let parts = uri . path . replace ( / ( ^ \/ | \/ $ ) / g, '' ) . split ( '/' ) ;
105+ const parts = uri . path . replace ( / ( ^ \/ | \/ $ ) / g, '' ) . split ( '/' ) ;
106106
107107 uri . db = parts . pop ( ) ;
108108 // Prevent double encoding of URI component
@@ -124,7 +124,7 @@ function genDBUrl(opts, path) {
124124function genUrl ( opts , path ) {
125125 // If the host already has a path, then we need to have a path delimiter
126126 // Otherwise, the path delimiter is the empty string
127- let pathDel = ! opts . path ? '' : '/' ;
127+ const pathDel = ! opts . path ? '' : '/' ;
128128
129129 // If the host already has a path, then we need to have a path delimiter
130130 // Otherwise, the path delimiter is the empty string
@@ -140,23 +140,23 @@ function paramsToStr(params) {
140140}
141141
142142function shouldCacheBust ( opts ) {
143- let ua = ( typeof navigator !== 'undefined' && navigator . userAgent ) ?
143+ const ua = ( typeof navigator !== 'undefined' && navigator . userAgent ) ?
144144 navigator . userAgent . toLowerCase ( ) : '' ;
145- let isIE = ua . indexOf ( 'msie' ) !== - 1 ;
146- let isTrident = ua . indexOf ( 'trident' ) !== - 1 ;
147- let isEdge = ua . indexOf ( 'edge' ) !== - 1 ;
148- let isGET = ! ( 'method' in opts ) || opts . method === 'GET' ;
145+ const isIE = ua . indexOf ( 'msie' ) !== - 1 ;
146+ const isTrident = ua . indexOf ( 'trident' ) !== - 1 ;
147+ const isEdge = ua . indexOf ( 'edge' ) !== - 1 ;
148+ const isGET = ! ( 'method' in opts ) || opts . method === 'GET' ;
149149 return ( isIE || isTrident || isEdge ) && isGET ;
150150}
151151
152152// Implements the PouchDB API for dealing with CouchDB instances over HTTP
153153function HttpPouch ( opts , callback ) {
154154
155155 // The functions that will be publicly available for HttpPouch
156- let api = this ;
156+ const api = this ;
157157
158- let host = getHost ( opts . name , opts ) ;
159- let dbUrl = genDBUrl ( host , '' ) ;
158+ const host = getHost ( opts . name , opts ) ;
159+ const dbUrl = genDBUrl ( host , '' ) ;
160160
161161 opts = clone ( opts ) ;
162162
@@ -168,13 +168,13 @@ function HttpPouch(opts, callback) {
168168 options . credentials = 'include' ;
169169
170170 if ( opts . auth || host . auth ) {
171- let nAuth = opts . auth || host . auth ;
172- let str = nAuth . username + ':' + nAuth . password ;
173- let token = btoa ( unescape ( encodeURIComponent ( str ) ) ) ;
171+ const nAuth = opts . auth || host . auth ;
172+ const str = nAuth . username + ':' + nAuth . password ;
173+ const token = btoa ( unescape ( encodeURIComponent ( str ) ) ) ;
174174 options . headers . set ( 'Authorization' , 'Basic ' + token ) ;
175175 }
176176
177- let headers = opts . headers || { } ;
177+ const headers = opts . headers || { } ;
178178 Object . keys ( headers ) . forEach ( function ( key ) {
179179 options . headers . append ( key , headers [ key ] ) ;
180180 } ) ;
@@ -184,7 +184,7 @@ function HttpPouch(opts, callback) {
184184 url += ( url . indexOf ( '?' ) === - 1 ? '?' : '&' ) + '_nonce=' + Date . now ( ) ;
185185 }
186186
187- let fetchFun = opts . fetch || fetch ;
187+ const fetchFun = opts . fetch || fetch ;
188188 return await fetchFun ( url , options ) ;
189189 } ;
190190
@@ -193,15 +193,15 @@ function HttpPouch(opts, callback) {
193193 setup ( ) . then ( function ( ) {
194194 return fun . apply ( this , args ) ;
195195 } ) . catch ( function ( e ) {
196- let callback = args . pop ( ) ;
196+ const callback = args . pop ( ) ;
197197 callback ( e ) ;
198198 } ) ;
199199 } ) . bind ( api ) ;
200200 }
201201
202202 async function fetchJSON ( url , options ) {
203203
204- let result = { } ;
204+ const result = { } ;
205205
206206 options = options || { } ;
207207 options . headers = options . headers || new Headers ( ) ;
@@ -221,7 +221,7 @@ function HttpPouch(opts, callback) {
221221 result . data = json ;
222222 if ( ! result . ok ) {
223223 result . data . status = result . status ;
224- let err = generateErrorFromResponse ( result . data ) ;
224+ const err = generateErrorFromResponse ( result . data ) ;
225225 throw err ;
226226 }
227227
@@ -298,7 +298,7 @@ function HttpPouch(opts, callback) {
298298 }
299299
300300 // Bad response or missing `uuid` should not prevent ID generation.
301- let uuid = ( result && result . uuid ) ? ( result . uuid + host . db ) : genDBUrl ( host , '' ) ;
301+ const uuid = ( result && result . uuid ) ? ( result . uuid + host . db ) : genDBUrl ( host , '' ) ;
302302 callback ( null , uuid ) ;
303303 } ) ;
304304
@@ -330,10 +330,10 @@ function HttpPouch(opts, callback) {
330330 } ) ;
331331
332332 api . bulkGet = coreAdapterFun ( 'bulkGet' , function ( opts , callback ) {
333- let self = this ;
333+ const self = this ;
334334
335335 async function doBulkGet ( cb ) {
336- let params = { } ;
336+ const params = { } ;
337337 if ( opts . revs ) {
338338 params . revs = true ;
339339 }
@@ -364,10 +364,10 @@ function HttpPouch(opts, callback) {
364364 /* istanbul ignore next */
365365 function doBulkGetShim ( ) {
366366 // avoid "url too long error" by splitting up into multiple requests
367- let batchSize = MAX_SIMULTANEOUS_REVS ;
368- let numBatches = Math . ceil ( opts . docs . length / batchSize ) ;
367+ const batchSize = MAX_SIMULTANEOUS_REVS ;
368+ const numBatches = Math . ceil ( opts . docs . length / batchSize ) ;
369369 let numDone = 0 ;
370- let results = new Array ( numBatches ) ;
370+ const results = new Array ( numBatches ) ;
371371
372372 function onResult ( batchNum ) {
373373 return function ( err , res ) {
@@ -380,16 +380,16 @@ function HttpPouch(opts, callback) {
380380 }
381381
382382 for ( let i = 0 ; i < numBatches ; i ++ ) {
383- let subOpts = pick ( opts , [ 'revs' , 'attachments' , 'binary' , 'latest' ] ) ;
383+ const subOpts = pick ( opts , [ 'revs' , 'attachments' , 'binary' , 'latest' ] ) ;
384384 subOpts . docs = opts . docs . slice ( i * batchSize ,
385385 Math . min ( opts . docs . length , ( i + 1 ) * batchSize ) ) ;
386386 bulkGetShim ( self , subOpts , onResult ( i ) ) ;
387387 }
388388 }
389389
390390 // mark the whole database as either supporting or not supporting _bulk_get
391- let dbUrl = genUrl ( host , '' ) ;
392- let supportsBulkGet = supportsBulkGetMap [ dbUrl ] ;
391+ const dbUrl = genUrl ( host , '' ) ;
392+ const supportsBulkGet = supportsBulkGetMap [ dbUrl ] ;
393393
394394 /* istanbul ignore next */
395395 if ( typeof supportsBulkGet !== 'boolean' ) {
@@ -450,7 +450,7 @@ function HttpPouch(opts, callback) {
450450 opts = clone ( opts ) ;
451451
452452 // List of parameters to add to the GET request
453- let params = { } ;
453+ const params = { } ;
454454
455455 if ( opts . revs ) {
456456 params . revs = true ;
@@ -487,8 +487,8 @@ function HttpPouch(opts, callback) {
487487 id = encodeDocId ( id ) ;
488488
489489 function fetchAttachments ( doc ) {
490- let atts = doc . _attachments ;
491- let filenames = atts && Object . keys ( atts ) ;
490+ const atts = doc . _attachments ;
491+ const filenames = atts && Object . keys ( atts ) ;
492492 if ( ! atts || ! filenames . length ) {
493493 return ;
494494 }
@@ -513,7 +513,7 @@ function HttpPouch(opts, callback) {
513513
514514 let data ;
515515 if ( opts . binary ) {
516- let typeFieldDescriptor = Object . getOwnPropertyDescriptor ( blob . __proto__ , 'type' ) ;
516+ const typeFieldDescriptor = Object . getOwnPropertyDescriptor ( blob . __proto__ , 'type' ) ;
517517 if ( ! typeFieldDescriptor || typeFieldDescriptor . set ) {
518518 blob . type = att . content_type ;
519519 }
@@ -529,7 +529,7 @@ function HttpPouch(opts, callback) {
529529 att . data = data ;
530530 }
531531
532- let promiseFactories = filenames . map ( function ( filename ) {
532+ const promiseFactories = filenames . map ( function ( filename ) {
533533 return function ( ) {
534534 return fetchData ( filename ) ;
535535 } ;
@@ -634,7 +634,7 @@ function HttpPouch(opts, callback) {
634634
635635 // TODO: also remove
636636 if ( typeof process !== 'undefined' && ! process . browser ) {
637- var typeFieldDescriptor = Object . getOwnPropertyDescriptor ( blob . __proto__ , 'type' ) ;
637+ const typeFieldDescriptor = Object . getOwnPropertyDescriptor ( blob . __proto__ , 'type' ) ;
638638 if ( ! typeFieldDescriptor || typeFieldDescriptor . set ) {
639639 blob . type = contentType ;
640640 }
@@ -761,7 +761,7 @@ function HttpPouch(opts, callback) {
761761 opts = clone ( opts ) ;
762762
763763 // List of parameters to add to the GET request
764- let params = { } ;
764+ const params = { } ;
765765 let body ;
766766 let method = 'GET' ;
767767
@@ -819,7 +819,7 @@ function HttpPouch(opts, callback) {
819819 params . skip = opts . skip ;
820820 }
821821
822- let paramStr = paramsToStr ( params ) ;
822+ const paramStr = paramsToStr ( params ) ;
823823
824824 if ( typeof opts . keys !== 'undefined' ) {
825825 method = 'POST' ;
@@ -849,7 +849,7 @@ function HttpPouch(opts, callback) {
849849 // if there is a large set of changes to be returned we can start
850850 // processing them quicker instead of waiting on the entire
851851 // set of changes to return and attempting to process them at once
852- let batchSize = 'batch_size' in opts ? opts . batch_size : CHANGES_BATCH_SIZE ;
852+ const batchSize = 'batch_size' in opts ? opts . batch_size : CHANGES_BATCH_SIZE ;
853853
854854 opts = clone ( opts ) ;
855855
@@ -871,12 +871,12 @@ function HttpPouch(opts, callback) {
871871 requestTimeout = opts . heartbeat + CHANGES_TIMEOUT_BUFFER ;
872872 }
873873
874- let params = { } ;
874+ const params = { } ;
875875 if ( 'timeout' in opts && opts . timeout ) {
876876 params . timeout = opts . timeout ;
877877 }
878878
879- let limit = ( typeof opts . limit !== 'undefined' ) ? opts . limit : false ;
879+ const limit = ( typeof opts . limit !== 'undefined' ) ? opts . limit : false ;
880880 let leftToFetch = limit ;
881881
882882 if ( opts . style ) {
@@ -931,7 +931,7 @@ function HttpPouch(opts, callback) {
931931 // If opts.query_params exists, pass it through to the changes request.
932932 // These parameters may be used by the filter on the source database.
933933 if ( opts . query_params && typeof opts . query_params === 'object' ) {
934- for ( let param_name in opts . query_params ) {
934+ for ( const param_name in opts . query_params ) {
935935 /* istanbul ignore else */
936936 if ( Object . prototype . hasOwnProperty . call ( opts . query_params , param_name ) ) {
937937 params [ param_name ] = opts . query_params [ param_name ] ;
@@ -957,7 +957,7 @@ function HttpPouch(opts, callback) {
957957 body = { selector : opts . selector } ;
958958 }
959959
960- let controller = new AbortController ( ) ;
960+ const controller = new AbortController ( ) ;
961961 let lastFetchedSeq ;
962962
963963 // Get all the changes starting wtih the one immediately after the
@@ -983,8 +983,8 @@ function HttpPouch(opts, callback) {
983983 }
984984
985985 // Set the options for the ajax call
986- let url = genDBUrl ( host , '_changes' + paramsToStr ( params ) ) ;
987- let fetchOpts = {
986+ const url = genDBUrl ( host , '_changes' + paramsToStr ( params ) ) ;
987+ const fetchOpts = {
988988 signal : controller . signal ,
989989 method : method ,
990990 body : JSON . stringify ( body )
@@ -1009,7 +1009,7 @@ function HttpPouch(opts, callback) {
10091009 // If opts.since exists, get all the changes from the sequence
10101010 // number given by opts.since. Otherwise, get all the changes
10111011 // from the sequence number 0.
1012- let results = { results : [ ] } ;
1012+ const results = { results : [ ] } ;
10131013
10141014 const fetched = function ( err , res ) {
10151015 if ( opts . aborted ) {
@@ -1031,11 +1031,11 @@ function HttpPouch(opts, callback) {
10311031 lastSeq = results . last_seq ;
10321032 }
10331033 // For each change
1034- let req = { } ;
1034+ const req = { } ;
10351035 req . query = opts . query_params ;
10361036 res . results = res . results . filter ( function ( c ) {
10371037 leftToFetch -- ;
1038- let ret = filterChange ( opts ) ( c ) ;
1038+ const ret = filterChange ( opts ) ( c ) ;
10391039 if ( ret ) {
10401040 if ( opts . include_docs && opts . attachments && opts . binary ) {
10411041 readAttachmentsAsBlobOrBuffer ( c ) ;
@@ -1061,7 +1061,7 @@ function HttpPouch(opts, callback) {
10611061 lastFetchedSeq = res . last_seq ;
10621062 }
10631063
1064- let finished = ( limit && leftToFetch <= 0 ) ||
1064+ const finished = ( limit && leftToFetch <= 0 ) ||
10651065 ( res && raw_results_length < batchSize ) ||
10661066 ( opts . descending ) ;
10671067
0 commit comments