@@ -71,6 +71,10 @@ declare module 'fabric-shim' {
7171 ERROR : number ;
7272 }
7373
74+ interface AsyncIterable < T > {
75+ [ Symbol . asyncIterator ] : ( ) => AsyncIterator < T > ;
76+ }
77+
7478 export class ChaincodeStub {
7579 getArgs ( ) : string [ ] ;
7680 getStringArgs ( ) : string [ ] ;
@@ -90,14 +94,14 @@ declare module 'fabric-shim' {
9094 deleteState ( key : string ) : Promise < void > ;
9195 setStateValidationParameter ( key : string , ep : Buffer ) : Promise < void > ;
9296 getStateValidationParameter ( key : string ) : Promise < Buffer > ;
93- getStateByRange ( startKey : string , endKey : string ) : Promise < Iterators . StateQueryIterator > ;
94- getStateByRangeWithPagination ( startKey : string , endKey : string , pageSize : number , bookmark ?: string ) : Promise < StateQueryResponse < Iterators . StateQueryIterator > > ;
95- getStateByPartialCompositeKey ( objectType : string , attributes : string [ ] ) : Promise < Iterators . StateQueryIterator > ;
96- getStateByPartialCompositeKeyWithPagination ( objectType : string , attributes : string [ ] , pageSize : number , bookmark ?: string ) : Promise < StateQueryResponse < Iterators . StateQueryIterator > > ;
97+ getStateByRange ( startKey : string , endKey : string ) : Promise < Iterators . StateQueryIterator > & AsyncIterable < Iterators . KV > ;
98+ getStateByRangeWithPagination ( startKey : string , endKey : string , pageSize : number , bookmark ?: string ) : Promise < StateQueryResponse < Iterators . StateQueryIterator > > & AsyncIterable < Iterators . KV > ;
99+ getStateByPartialCompositeKey ( objectType : string , attributes : string [ ] ) : Promise < Iterators . StateQueryIterator > & AsyncIterable < Iterators . KV > ;
100+ getStateByPartialCompositeKeyWithPagination ( objectType : string , attributes : string [ ] , pageSize : number , bookmark ?: string ) : Promise < StateQueryResponse < Iterators . StateQueryIterator > > & AsyncIterable < Iterators . KV > ;
97101
98- getQueryResult ( query : string ) : Promise < Iterators . StateQueryIterator > ;
99- getQueryResultWithPagination ( query : string , pageSize : number , bookmark ?: string ) : Promise < StateQueryResponse < Iterators . StateQueryIterator > > ;
100- getHistoryForKey ( key : string ) : Promise < Iterators . HistoryQueryIterator > ;
102+ getQueryResult ( query : string ) : Promise < Iterators . StateQueryIterator > & AsyncIterable < Iterators . KV > ;
103+ getQueryResultWithPagination ( query : string , pageSize : number , bookmark ?: string ) : Promise < StateQueryResponse < Iterators . StateQueryIterator > > & AsyncIterable < Iterators . KV > ;
104+ getHistoryForKey ( key : string ) : Promise < Iterators . HistoryQueryIterator > & AsyncIterable < Iterators . KeyModification > ;
101105
102106 invokeChaincode ( chaincodeName : string , args : string [ ] , channel : string ) : Promise < ChaincodeResponse > ;
103107 setEvent ( name : string , payload : Buffer ) : void ;
@@ -111,9 +115,9 @@ declare module 'fabric-shim' {
111115 deletePrivateData ( collection : string , key : string ) : Promise < void > ;
112116 setPrivateDataValidationParameter ( collection : string , key : string , ep : Buffer ) : Promise < void > ;
113117 getPrivateDataValidationParameter ( collection : string , key : string ) : Promise < Buffer > ;
114- getPrivateDataByRange ( collection : string , startKey : string , endKey : string ) : Promise < Iterators . StateQueryIterator > ;
115- getPrivateDataByPartialCompositeKey ( collection : string , objectType : string , attributes : string [ ] ) : Promise < Iterators . StateQueryIterator > ;
116- getPrivateDataQueryResult ( collection : string , query : string ) : Promise < Iterators . StateQueryIterator > ;
118+ getPrivateDataByRange ( collection : string , startKey : string , endKey : string ) : Promise < Iterators . StateQueryIterator > & AsyncIterable < Iterators . KV > ;
119+ getPrivateDataByPartialCompositeKey ( collection : string , objectType : string , attributes : string [ ] ) : Promise < Iterators . StateQueryIterator > & AsyncIterable < Iterators . KV > ;
120+ getPrivateDataQueryResult ( collection : string , query : string ) : Promise < Iterators . StateQueryIterator > & AsyncIterable < Iterators . KV > ;
117121
118122 static RESPONSE_CODE : ResponseCode ;
119123 }
@@ -130,32 +134,29 @@ declare module 'fabric-shim' {
130134
131135 export namespace Iterators {
132136
133- interface CommonIterator extends EventEmitter {
137+ interface CommonIterator < T > {
134138 close ( ) : Promise < void > ;
135- next ( ) : Promise < any > ;
136- }
137-
138- interface HistoryQueryIterator extends CommonIterator {
139- next ( ) : Promise < NextKeyModificationResult > ;
139+ next ( ) : Promise < NextResult < T > > ;
140140 }
141141
142- interface StateQueryIterator extends CommonIterator {
143- next ( ) : Promise < NextResult > ;
144- }
145-
146- interface NextResult {
147- value : KV ;
142+ interface NextResult < T > {
143+ value : T ;
148144 done : boolean ;
149145 }
150146
147+ type HistoryQueryIterator = CommonIterator < KeyModification > ;
148+ type StateQueryIterator = CommonIterator < KV > ;
149+
151150 interface NextKeyModificationResult {
152151 value : KeyModification ;
153152 done : boolean ;
154153 }
155154
156155 interface KV {
156+ namespace : string ;
157157 key : string ;
158158 value : ProtobufBytes ;
159+ getNamespace ( ) : string ;
159160 getKey ( ) : string ;
160161 getValue ( ) : ProtobufBytes ;
161162 }
0 commit comments