This repository was archived by the owner on Sep 30, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +29
-6
lines changed
Expand file tree Collapse file tree 2 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -13,9 +13,20 @@ class DocumentIndex {
1313
1414 updateIndex ( oplog , onProgressCallback ) {
1515 const reducer = ( handled , item , idx ) => {
16- if ( handled [ item . payload . key ] !== true ) {
16+ if ( item . payload . op === 'PUTALL' ) {
17+ for ( const doc of item . payload . docs ) {
18+ if ( handled [ doc . key ] !== true ) {
19+ handled [ doc . key ] = true
20+ this . _index [ doc . key ] = {
21+ op : item . payload . op ,
22+ key : doc . key ,
23+ value : doc . value
24+ }
25+ }
26+ }
27+ } else if ( handled [ item . payload . key ] !== true ) {
1728 handled [ item . payload . key ] = true
18- if ( item . payload . op === 'PUT' ) {
29+ if ( item . payload . op === 'PUT' ) {
1930 this . _index [ item . payload . key ] = item
2031 } else if ( item . payload . op === 'DEL' ) {
2132 delete this . _index [ item . payload . key ]
Original file line number Diff line number Diff line change @@ -65,8 +65,7 @@ class DocumentStore extends Store {
6565 }
6666
6767 put ( doc , options = { } ) {
68- if ( ! doc [ this . options . indexBy ] )
69- throw new Error ( `The provided document doesn't contain field '${ this . options . indexBy } '` )
68+ if ( ! doc [ this . options . indexBy ] ) { throw new Error ( `The provided document doesn't contain field '${ this . options . indexBy } '` ) }
7069
7170 return this . _addOperation ( {
7271 op : 'PUT' ,
@@ -75,9 +74,22 @@ class DocumentStore extends Store {
7574 } , options )
7675 }
7776
77+ putAll ( docs , options = { } ) {
78+ if ( ! ( Array . isArray ( docs ) ) ) {
79+ docs = [ docs ]
80+ }
81+ if ( ! ( docs . every ( d => d [ this . options . indexBy ] ) ) ) { throw new Error ( `The provided document doesn't contain field '${ this . options . indexBy } '` ) }
82+ return this . _addOperation ( {
83+ op : 'PUTALL' ,
84+ docs : docs . map ( ( value ) => ( {
85+ key : value [ this . options . indexBy ] ,
86+ value
87+ } ) )
88+ } , options )
89+ }
90+
7891 del ( key , options = { } ) {
79- if ( ! this . _index . get ( key ) )
80- throw new Error ( `No entry with key '${ key } ' in the database` )
92+ if ( ! this . _index . get ( key ) ) { throw new Error ( `No entry with key '${ key } ' in the database` ) }
8193
8294 return this . _addOperation ( {
8395 op : 'DEL' ,
You can’t perform that action at this time.
0 commit comments