@@ -14,15 +14,19 @@ import {
14
14
DynamoDBDocument ,
15
15
ExecuteStatementCommandOutput ,
16
16
ExecuteTransactionCommandOutput ,
17
+ GetCommandInput ,
17
18
GetCommandOutput ,
18
19
NumberValue ,
19
20
PutCommandOutput ,
21
+ QueryCommandInput ,
20
22
QueryCommandOutput ,
23
+ ScanCommandInput ,
21
24
ScanCommandOutput ,
22
25
TransactGetCommandOutput ,
23
26
TransactWriteCommandOutput ,
24
27
UpdateCommandOutput ,
25
28
} from "@aws-sdk/lib-dynamodb" ;
29
+ import { HttpRequest } from "@smithy/protocol-http" ;
26
30
import { afterAll , beforeAll , describe , expect , test as it , vi } from "vitest" ;
27
31
28
32
// expected running time: table creation (~20s) + operations 10s
@@ -81,6 +85,43 @@ describe(
81
85
} ,
82
86
} ) ;
83
87
88
+ doc . middlewareStack . add (
89
+ ( next , context ) => async ( args ) => {
90
+ if ( context . commandName === "GetCommand" || context . commandName === "GetItemCommand" ) {
91
+ ( args . input as GetCommandInput ) . ConsistentRead = true ;
92
+ }
93
+ if ( context . commandName === "QueryCommand" ) {
94
+ ( args . input as QueryCommandInput ) . ConsistentRead = true ;
95
+ }
96
+ if ( context . commandName === "ScanCommand" ) {
97
+ ( args . input as ScanCommandInput ) . ConsistentRead = true ;
98
+ }
99
+ return next ( args ) ;
100
+ } ,
101
+ {
102
+ step : "initialize" ,
103
+ name : "SetConsistentReadMiddleware" ,
104
+ override : true ,
105
+ }
106
+ ) ;
107
+
108
+ doc . middlewareStack . add (
109
+ ( next , context ) => async ( args ) => {
110
+ const { request } = args ;
111
+ if ( HttpRequest . isInstance ( request ) ) {
112
+ if ( [ "GetCommand" , "GetItemCommand" , "QueryCommand" , "ScanCommand" ] . includes ( context . commandName ?? "" ) ) {
113
+ expect ( request . body ) . toContain ( `"ConsistentRead":true` ) ;
114
+ }
115
+ }
116
+ return next ( args ) ;
117
+ } ,
118
+ {
119
+ step : "finalizeRequest" ,
120
+ name : "VerifyConsistentReadMiddleware" ,
121
+ override : true ,
122
+ }
123
+ ) ;
124
+
84
125
function throwIfError ( e : unknown ) {
85
126
if ( e instanceof Error ) {
86
127
throw e ;
@@ -243,7 +284,6 @@ describe(
243
284
244
285
log . read [ id ] = await doc
245
286
. get ( {
246
- ConsistentRead : true ,
247
287
TableName,
248
288
Key : {
249
289
id,
@@ -338,7 +378,6 @@ describe(
338
378
for ( const [ k ] of Object . entries ( data ) ) {
339
379
log . executeTransactionReadBack [ k ] = await doc
340
380
. get ( {
341
- ConsistentRead : true ,
342
381
TableName,
343
382
Key : {
344
383
id : k + "-exec-transact" ,
@@ -358,7 +397,6 @@ describe(
358
397
for ( const [ k ] of Object . entries ( data ) ) {
359
398
log . executeStatementReadBack [ k ] = await doc
360
399
. get ( {
361
- ConsistentRead : true ,
362
400
TableName,
363
401
Key : {
364
402
id : k + "-statement" ,
@@ -400,7 +438,6 @@ describe(
400
438
ExpressionAttributeValues : {
401
439
":id" : "map" ,
402
440
} ,
403
- ConsistentRead : true ,
404
441
} )
405
442
. catch ( passError ) ;
406
443
@@ -415,7 +452,6 @@ describe(
415
452
":data1" : data . list ,
416
453
":data2" : data . map ,
417
454
} ,
418
- ConsistentRead : true ,
419
455
} )
420
456
. catch ( passError ) ;
421
457
@@ -439,7 +475,6 @@ describe(
439
475
Key : {
440
476
id : "undefinedColumns" ,
441
477
} ,
442
- ConsistentRead : true ,
443
478
} )
444
479
. catch ( passError ) ;
445
480
@@ -461,7 +496,6 @@ describe(
461
496
462
497
log . updateReadBack [ id ] = await doc
463
498
. get ( {
464
- ConsistentRead : true ,
465
499
TableName,
466
500
Key : {
467
501
id,
@@ -530,7 +564,6 @@ describe(
530
564
531
565
log . classInstanceConversion . read = await doc
532
566
. get ( {
533
- ConsistentRead : true ,
534
567
TableName,
535
568
Key : {
536
569
id : "classInstance" ,
0 commit comments