File tree Expand file tree Collapse file tree 3 files changed +38
-1
lines changed
implementation/Client/GRPCClient Expand file tree Collapse file tree 3 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { OperationType } from '../../../types/Operation.type';
6
6
import { IRequestMetadata } from '../../../types/RequestMetadata.type' ;
7
7
import IClientState from '../../../interfaces/Client/IClientState' ;
8
8
import { KeyValueType } from '../../../types/KeyValue.type' ;
9
+ import { merge } from '../../../utils/Map.util' ;
9
10
10
11
// https://docs.dapr.io/reference/api/state_api/
11
12
export default class GRPCClientState implements IClientState {
@@ -16,7 +17,7 @@ export default class GRPCClientState implements IClientState {
16
17
}
17
18
18
19
async save ( storeName : string , stateObjects : KeyValuePairType [ ] ) : Promise < void > {
19
- const stateList = [ ] ;
20
+ const stateList : StateItem [ ] = [ ] ;
20
21
21
22
for ( const stateObject of stateObjects ) {
22
23
const si = new StateItem ( ) ;
@@ -163,6 +164,9 @@ export default class GRPCClientState implements IClientState {
163
164
const msgService = new ExecuteStateTransactionRequest ( ) ;
164
165
msgService . setStorename ( storeName ) ;
165
166
msgService . setOperationsList ( transactionItems ) ;
167
+ if ( metadata ) {
168
+ merge ( msgService . getMetadataMap ( ) , metadata ) ;
169
+ }
166
170
167
171
return new Promise ( ( resolve , reject ) => {
168
172
const client = this . client . getClient ( ) ;
Original file line number Diff line number Diff line change
1
+ import { Map } from 'google-protobuf' ;
2
+ import { IRequestMetadata } from '../types/RequestMetadata.type' ;
3
+
4
+ export function merge ( metadataMap : Map < string , string > , metadata : IRequestMetadata ) : void {
5
+ for ( const key of Object . keys ( metadata ) ) {
6
+ metadataMap . set ( key , metadata [ key ] ) ;
7
+ }
8
+ }
Original file line number Diff line number Diff line change @@ -301,6 +301,31 @@ describe('grpc/main', () => {
301
301
expect ( resTransactionDelete ) . toEqual ( '' ) ;
302
302
expect ( resTransactionUpsert ) . toEqual ( 'my-new-data-1' ) ;
303
303
} ) ;
304
+
305
+ it ( 'should be able to perform a transaction with metadata' , async ( ) => {
306
+ await client . state . transaction ( 'state-redis' , [
307
+ {
308
+ operation : 'upsert' ,
309
+ request : {
310
+ key : 'key-with-metadata-1' ,
311
+ value : 'my-new-data-with-metadata-1' ,
312
+ } ,
313
+ } ,
314
+ {
315
+ operation : 'delete' ,
316
+ request : {
317
+ key : 'key-with-metadata-2' ,
318
+ } ,
319
+ } ,
320
+ ] , {
321
+ trace_id : 'mock trace id here' ,
322
+ } ) ;
323
+
324
+ const resTransactionDelete = await client . state . get ( 'state-redis' , 'key-with-metadata-2' ) ;
325
+ const resTransactionUpsert = await client . state . get ( 'state-redis' , 'key-with-metadata-1' ) ;
326
+ expect ( resTransactionDelete ) . toEqual ( '' ) ;
327
+ expect ( resTransactionUpsert ) . toEqual ( 'my-new-data-with-metadata-1' ) ;
328
+ } ) ;
304
329
} ) ;
305
330
} ) ;
306
331
You can’t perform that action at this time.
0 commit comments