@@ -17,12 +17,16 @@ import {
1717 GetCommandOutput ,
1818 NumberValue ,
1919 PutCommandOutput ,
20+ QueryCommandInput ,
2021 QueryCommandOutput ,
22+ ScanCommandInput ,
2123 ScanCommandOutput ,
2224 TransactGetCommandOutput ,
2325 TransactWriteCommandOutput ,
2426 UpdateCommandOutput ,
2527} from "@aws-sdk/lib-dynamodb" ;
28+ import { GetCommandInput } from "@aws-sdk/lib-lib-dynamodb/src" ;
29+ import { HttpRequest } from "@smithy/protocol-http" ;
2630import { afterAll , beforeAll , describe , expect , test as it , vi } from "vitest" ;
2731
2832// expected running time: table creation (~20s) + operations 10s
@@ -81,6 +85,43 @@ describe(
8185 } ,
8286 } ) ;
8387
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+
84125 function throwIfError ( e : unknown ) {
85126 if ( e instanceof Error ) {
86127 throw e ;
@@ -243,7 +284,6 @@ describe(
243284
244285 log . read [ id ] = await doc
245286 . get ( {
246- ConsistentRead : true ,
247287 TableName,
248288 Key : {
249289 id,
@@ -338,7 +378,6 @@ describe(
338378 for ( const [ k ] of Object . entries ( data ) ) {
339379 log . executeTransactionReadBack [ k ] = await doc
340380 . get ( {
341- ConsistentRead : true ,
342381 TableName,
343382 Key : {
344383 id : k + "-exec-transact" ,
@@ -358,7 +397,6 @@ describe(
358397 for ( const [ k ] of Object . entries ( data ) ) {
359398 log . executeStatementReadBack [ k ] = await doc
360399 . get ( {
361- ConsistentRead : true ,
362400 TableName,
363401 Key : {
364402 id : k + "-statement" ,
@@ -400,7 +438,6 @@ describe(
400438 ExpressionAttributeValues : {
401439 ":id" : "map" ,
402440 } ,
403- ConsistentRead : true ,
404441 } )
405442 . catch ( passError ) ;
406443
@@ -415,7 +452,6 @@ describe(
415452 ":data1" : data . list ,
416453 ":data2" : data . map ,
417454 } ,
418- ConsistentRead : true ,
419455 } )
420456 . catch ( passError ) ;
421457
@@ -439,7 +475,6 @@ describe(
439475 Key : {
440476 id : "undefinedColumns" ,
441477 } ,
442- ConsistentRead : true ,
443478 } )
444479 . catch ( passError ) ;
445480
@@ -461,7 +496,6 @@ describe(
461496
462497 log . updateReadBack [ id ] = await doc
463498 . get ( {
464- ConsistentRead : true ,
465499 TableName,
466500 Key : {
467501 id,
@@ -530,7 +564,6 @@ describe(
530564
531565 log . classInstanceConversion . read = await doc
532566 . get ( {
533- ConsistentRead : true ,
534567 TableName,
535568 Key : {
536569 id : "classInstance" ,
0 commit comments