Skip to content

Commit fb0e14e

Browse files
kuhemonholm
andauthored
fix(lib-dynamodb): input types conflicts with client-dynamodb (#6683)
* fix(lib-dynamodb): input types conflicts with client-dynamodb #6654 added `| undefined` to optional model props, but the types in lib-dynamodb wasn't updated to reflect that change. This leaves consumers using `exactOptionalPropertyTypes: true` with ts errors when trying to use almost any of the commands in lib-dynamodb Fixes #6668 * fix(lib-dynamodb): support exactOptionalPropertyTypes --------- Co-authored-by: monholm <[email protected]>
1 parent dfea325 commit fb0e14e

14 files changed

+197
-144
lines changed

Diff for: codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/DocumentClientCommandGenerator.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,11 @@ private void writeStructureMemberOmitType(MemberShape member) {
392392
String optionalSuffix = isRequiredMember(member) ? "" : "?";
393393
writer.openBlock("${L}${L}: ", ";", symbolProvider.toMemberName(member),
394394
optionalSuffix, () -> {
395-
writeMemberOmitType(member);
395+
writeMemberOmitType(member, true);
396396
});
397397
}
398398

399-
private void writeMemberOmitType(MemberShape member) {
399+
private void writeMemberOmitType(MemberShape member, boolean allowUndefined) {
400400
Shape memberTarget = model.expectShape(member.getTarget());
401401
if (memberTarget.isStructureShape()) {
402402
writeStructureOmitType((StructureShape) memberTarget);
@@ -413,16 +413,17 @@ private void writeMemberOmitType(MemberShape member) {
413413
} else if (memberTarget.isMapShape()) {
414414
MemberShape mapMember = ((MapShape) memberTarget).getValue();
415415
writer.openBlock("Record<string, ", ">", () -> {
416-
writeMemberOmitType(mapMember);
416+
writeMemberOmitType(mapMember, false);
417417
});
418418
} else if (memberTarget instanceof CollectionShape) {
419419
MemberShape collectionMember = ((CollectionShape) memberTarget).getMember();
420420
writer.openBlock("(", ")[]", () -> {
421-
writeMemberOmitType(collectionMember);
421+
writeMemberOmitType(collectionMember, false);
422422
});
423423
}
424-
String typeSuffix = isRequiredMember(member) ? " | undefined" : "";
425-
writer.write("${L}", typeSuffix);
424+
if (allowUndefined) {
425+
writer.write(" | undefined");
426+
}
426427
}
427428

428429
private void writeNativeAttributeValue() {

Diff for: lib/lib-dynamodb/src/commands/BatchExecuteStatementCommand.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export { DynamoDBDocumentClientCommand, $Command };
1818
export type BatchExecuteStatementCommandInput = Omit<__BatchExecuteStatementCommandInput, "Statements"> & {
1919
Statements:
2020
| (Omit<BatchStatementRequest, "Parameters"> & {
21-
Parameters?: NativeAttributeValue[];
21+
Parameters?: NativeAttributeValue[] | undefined;
2222
})[]
2323
| undefined;
2424
};
@@ -27,12 +27,16 @@ export type BatchExecuteStatementCommandInput = Omit<__BatchExecuteStatementComm
2727
* @public
2828
*/
2929
export type BatchExecuteStatementCommandOutput = Omit<__BatchExecuteStatementCommandOutput, "Responses"> & {
30-
Responses?: (Omit<BatchStatementResponse, "Error" | "Item"> & {
31-
Error?: Omit<BatchStatementError, "Item"> & {
32-
Item?: Record<string, NativeAttributeValue>;
33-
};
34-
Item?: Record<string, NativeAttributeValue>;
35-
})[];
30+
Responses?:
31+
| (Omit<BatchStatementResponse, "Error" | "Item"> & {
32+
Error?:
33+
| (Omit<BatchStatementError, "Item"> & {
34+
Item?: Record<string, NativeAttributeValue> | undefined;
35+
})
36+
| undefined;
37+
Item?: Record<string, NativeAttributeValue> | undefined;
38+
})[]
39+
| undefined;
3640
};
3741

3842
/**

Diff for: lib/lib-dynamodb/src/commands/BatchGetCommand.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ export type BatchGetCommandInput = Omit<__BatchGetItemCommandInput, "RequestItem
3030
* @public
3131
*/
3232
export type BatchGetCommandOutput = Omit<__BatchGetItemCommandOutput, "Responses" | "UnprocessedKeys"> & {
33-
Responses?: Record<string, Record<string, NativeAttributeValue>[]>;
34-
UnprocessedKeys?: Record<
35-
string,
36-
Omit<KeysAndAttributes, "Keys"> & {
37-
Keys: Record<string, NativeAttributeValue>[] | undefined;
38-
}
39-
>;
33+
Responses?: Record<string, Record<string, NativeAttributeValue>[]> | undefined;
34+
UnprocessedKeys?:
35+
| Record<
36+
string,
37+
Omit<KeysAndAttributes, "Keys"> & {
38+
Keys: Record<string, NativeAttributeValue>[] | undefined;
39+
}
40+
>
41+
| undefined;
4042
};
4143

4244
/**

Diff for: lib/lib-dynamodb/src/commands/BatchWriteCommand.ts

+35-23
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,16 @@ export type BatchWriteCommandInput = Omit<__BatchWriteItemCommandInput, "Request
2020
| Record<
2121
string,
2222
(Omit<WriteRequest, "PutRequest" | "DeleteRequest"> & {
23-
PutRequest?: Omit<PutRequest, "Item"> & {
24-
Item: Record<string, NativeAttributeValue> | undefined;
25-
};
26-
DeleteRequest?: Omit<DeleteRequest, "Key"> & {
27-
Key: Record<string, NativeAttributeValue> | undefined;
28-
};
23+
PutRequest?:
24+
| (Omit<PutRequest, "Item"> & {
25+
Item: Record<string, NativeAttributeValue> | undefined;
26+
})
27+
| undefined;
28+
DeleteRequest?:
29+
| (Omit<DeleteRequest, "Key"> & {
30+
Key: Record<string, NativeAttributeValue> | undefined;
31+
})
32+
| undefined;
2933
})[]
3034
>
3135
| undefined;
@@ -38,23 +42,31 @@ export type BatchWriteCommandOutput = Omit<
3842
__BatchWriteItemCommandOutput,
3943
"UnprocessedItems" | "ItemCollectionMetrics"
4044
> & {
41-
UnprocessedItems?: Record<
42-
string,
43-
(Omit<WriteRequest, "PutRequest" | "DeleteRequest"> & {
44-
PutRequest?: Omit<PutRequest, "Item"> & {
45-
Item: Record<string, NativeAttributeValue> | undefined;
46-
};
47-
DeleteRequest?: Omit<DeleteRequest, "Key"> & {
48-
Key: Record<string, NativeAttributeValue> | undefined;
49-
};
50-
})[]
51-
>;
52-
ItemCollectionMetrics?: Record<
53-
string,
54-
(Omit<ItemCollectionMetrics, "ItemCollectionKey"> & {
55-
ItemCollectionKey?: Record<string, NativeAttributeValue>;
56-
})[]
57-
>;
45+
UnprocessedItems?:
46+
| Record<
47+
string,
48+
(Omit<WriteRequest, "PutRequest" | "DeleteRequest"> & {
49+
PutRequest?:
50+
| (Omit<PutRequest, "Item"> & {
51+
Item: Record<string, NativeAttributeValue> | undefined;
52+
})
53+
| undefined;
54+
DeleteRequest?:
55+
| (Omit<DeleteRequest, "Key"> & {
56+
Key: Record<string, NativeAttributeValue> | undefined;
57+
})
58+
| undefined;
59+
})[]
60+
>
61+
| undefined;
62+
ItemCollectionMetrics?:
63+
| Record<
64+
string,
65+
(Omit<ItemCollectionMetrics, "ItemCollectionKey"> & {
66+
ItemCollectionKey?: Record<string, NativeAttributeValue> | undefined;
67+
})[]
68+
>
69+
| undefined;
5870
};
5971

6072
/**

Diff for: lib/lib-dynamodb/src/commands/DeleteCommand.ts

+16-12
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,28 @@ export { DynamoDBDocumentClientCommand, $Command };
1717
*/
1818
export type DeleteCommandInput = Omit<__DeleteItemCommandInput, "Key" | "Expected" | "ExpressionAttributeValues"> & {
1919
Key: Record<string, NativeAttributeValue> | undefined;
20-
Expected?: Record<
21-
string,
22-
Omit<ExpectedAttributeValue, "Value" | "AttributeValueList"> & {
23-
Value?: NativeAttributeValue;
24-
AttributeValueList?: NativeAttributeValue[];
25-
}
26-
>;
27-
ExpressionAttributeValues?: Record<string, NativeAttributeValue>;
20+
Expected?:
21+
| Record<
22+
string,
23+
Omit<ExpectedAttributeValue, "Value" | "AttributeValueList"> & {
24+
Value?: NativeAttributeValue | undefined;
25+
AttributeValueList?: NativeAttributeValue[] | undefined;
26+
}
27+
>
28+
| undefined;
29+
ExpressionAttributeValues?: Record<string, NativeAttributeValue> | undefined;
2830
};
2931

3032
/**
3133
* @public
3234
*/
3335
export type DeleteCommandOutput = Omit<__DeleteItemCommandOutput, "Attributes" | "ItemCollectionMetrics"> & {
34-
Attributes?: Record<string, NativeAttributeValue>;
35-
ItemCollectionMetrics?: Omit<ItemCollectionMetrics, "ItemCollectionKey"> & {
36-
ItemCollectionKey?: Record<string, NativeAttributeValue>;
37-
};
36+
Attributes?: Record<string, NativeAttributeValue> | undefined;
37+
ItemCollectionMetrics?:
38+
| (Omit<ItemCollectionMetrics, "ItemCollectionKey"> & {
39+
ItemCollectionKey?: Record<string, NativeAttributeValue> | undefined;
40+
})
41+
| undefined;
3842
};
3943

4044
/**

Diff for: lib/lib-dynamodb/src/commands/ExecuteStatementCommand.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ export { DynamoDBDocumentClientCommand, $Command };
1616
* @public
1717
*/
1818
export type ExecuteStatementCommandInput = Omit<__ExecuteStatementCommandInput, "Parameters"> & {
19-
Parameters?: NativeAttributeValue[];
19+
Parameters?: NativeAttributeValue[] | undefined;
2020
};
2121

2222
/**
2323
* @public
2424
*/
2525
export type ExecuteStatementCommandOutput = Omit<__ExecuteStatementCommandOutput, "Items" | "LastEvaluatedKey"> & {
26-
Items?: Record<string, NativeAttributeValue>[];
27-
LastEvaluatedKey?: Record<string, NativeAttributeValue>;
26+
Items?: Record<string, NativeAttributeValue>[] | undefined;
27+
LastEvaluatedKey?: Record<string, NativeAttributeValue> | undefined;
2828
};
2929

3030
/**

Diff for: lib/lib-dynamodb/src/commands/ExecuteTransactionCommand.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export { DynamoDBDocumentClientCommand, $Command };
1818
export type ExecuteTransactionCommandInput = Omit<__ExecuteTransactionCommandInput, "TransactStatements"> & {
1919
TransactStatements:
2020
| (Omit<ParameterizedStatement, "Parameters"> & {
21-
Parameters?: NativeAttributeValue[];
21+
Parameters?: NativeAttributeValue[] | undefined;
2222
})[]
2323
| undefined;
2424
};
@@ -27,9 +27,11 @@ export type ExecuteTransactionCommandInput = Omit<__ExecuteTransactionCommandInp
2727
* @public
2828
*/
2929
export type ExecuteTransactionCommandOutput = Omit<__ExecuteTransactionCommandOutput, "Responses"> & {
30-
Responses?: (Omit<ItemResponse, "Item"> & {
31-
Item?: Record<string, NativeAttributeValue>;
32-
})[];
30+
Responses?:
31+
| (Omit<ItemResponse, "Item"> & {
32+
Item?: Record<string, NativeAttributeValue> | undefined;
33+
})[]
34+
| undefined;
3335
};
3436

3537
/**

Diff for: lib/lib-dynamodb/src/commands/GetCommand.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export type GetCommandInput = Omit<__GetItemCommandInput, "Key"> & {
2323
* @public
2424
*/
2525
export type GetCommandOutput = Omit<__GetItemCommandOutput, "Item"> & {
26-
Item?: Record<string, NativeAttributeValue>;
26+
Item?: Record<string, NativeAttributeValue> | undefined;
2727
};
2828

2929
/**

Diff for: lib/lib-dynamodb/src/commands/PutCommand.ts

+16-12
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,28 @@ export { DynamoDBDocumentClientCommand, $Command };
1717
*/
1818
export type PutCommandInput = Omit<__PutItemCommandInput, "Item" | "Expected" | "ExpressionAttributeValues"> & {
1919
Item: Record<string, NativeAttributeValue> | undefined;
20-
Expected?: Record<
21-
string,
22-
Omit<ExpectedAttributeValue, "Value" | "AttributeValueList"> & {
23-
Value?: NativeAttributeValue;
24-
AttributeValueList?: NativeAttributeValue[];
25-
}
26-
>;
27-
ExpressionAttributeValues?: Record<string, NativeAttributeValue>;
20+
Expected?:
21+
| Record<
22+
string,
23+
Omit<ExpectedAttributeValue, "Value" | "AttributeValueList"> & {
24+
Value?: NativeAttributeValue | undefined;
25+
AttributeValueList?: NativeAttributeValue[] | undefined;
26+
}
27+
>
28+
| undefined;
29+
ExpressionAttributeValues?: Record<string, NativeAttributeValue> | undefined;
2830
};
2931

3032
/**
3133
* @public
3234
*/
3335
export type PutCommandOutput = Omit<__PutItemCommandOutput, "Attributes" | "ItemCollectionMetrics"> & {
34-
Attributes?: Record<string, NativeAttributeValue>;
35-
ItemCollectionMetrics?: Omit<ItemCollectionMetrics, "ItemCollectionKey"> & {
36-
ItemCollectionKey?: Record<string, NativeAttributeValue>;
37-
};
36+
Attributes?: Record<string, NativeAttributeValue> | undefined;
37+
ItemCollectionMetrics?:
38+
| (Omit<ItemCollectionMetrics, "ItemCollectionKey"> & {
39+
ItemCollectionKey?: Record<string, NativeAttributeValue> | undefined;
40+
})
41+
| undefined;
3842
};
3943

4044
/**

Diff for: lib/lib-dynamodb/src/commands/QueryCommand.ts

+20-16
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,32 @@ export type QueryCommandInput = Omit<
1919
__QueryCommandInput,
2020
"KeyConditions" | "QueryFilter" | "ExclusiveStartKey" | "ExpressionAttributeValues"
2121
> & {
22-
KeyConditions?: Record<
23-
string,
24-
Omit<Condition, "AttributeValueList"> & {
25-
AttributeValueList?: NativeAttributeValue[];
26-
}
27-
>;
28-
QueryFilter?: Record<
29-
string,
30-
Omit<Condition, "AttributeValueList"> & {
31-
AttributeValueList?: NativeAttributeValue[];
32-
}
33-
>;
34-
ExclusiveStartKey?: Record<string, NativeAttributeValue>;
35-
ExpressionAttributeValues?: Record<string, NativeAttributeValue>;
22+
KeyConditions?:
23+
| Record<
24+
string,
25+
Omit<Condition, "AttributeValueList"> & {
26+
AttributeValueList?: NativeAttributeValue[] | undefined;
27+
}
28+
>
29+
| undefined;
30+
QueryFilter?:
31+
| Record<
32+
string,
33+
Omit<Condition, "AttributeValueList"> & {
34+
AttributeValueList?: NativeAttributeValue[] | undefined;
35+
}
36+
>
37+
| undefined;
38+
ExclusiveStartKey?: Record<string, NativeAttributeValue> | undefined;
39+
ExpressionAttributeValues?: Record<string, NativeAttributeValue> | undefined;
3640
};
3741

3842
/**
3943
* @public
4044
*/
4145
export type QueryCommandOutput = Omit<__QueryCommandOutput, "Items" | "LastEvaluatedKey"> & {
42-
Items?: Record<string, NativeAttributeValue>[];
43-
LastEvaluatedKey?: Record<string, NativeAttributeValue>;
46+
Items?: Record<string, NativeAttributeValue>[] | undefined;
47+
LastEvaluatedKey?: Record<string, NativeAttributeValue> | undefined;
4448
};
4549

4650
/**

Diff for: lib/lib-dynamodb/src/commands/ScanCommand.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,24 @@ export type ScanCommandInput = Omit<
1919
__ScanCommandInput,
2020
"ScanFilter" | "ExclusiveStartKey" | "ExpressionAttributeValues"
2121
> & {
22-
ScanFilter?: Record<
23-
string,
24-
Omit<Condition, "AttributeValueList"> & {
25-
AttributeValueList?: NativeAttributeValue[];
26-
}
27-
>;
28-
ExclusiveStartKey?: Record<string, NativeAttributeValue>;
29-
ExpressionAttributeValues?: Record<string, NativeAttributeValue>;
22+
ScanFilter?:
23+
| Record<
24+
string,
25+
Omit<Condition, "AttributeValueList"> & {
26+
AttributeValueList?: NativeAttributeValue[] | undefined;
27+
}
28+
>
29+
| undefined;
30+
ExclusiveStartKey?: Record<string, NativeAttributeValue> | undefined;
31+
ExpressionAttributeValues?: Record<string, NativeAttributeValue> | undefined;
3032
};
3133

3234
/**
3335
* @public
3436
*/
3537
export type ScanCommandOutput = Omit<__ScanCommandOutput, "Items" | "LastEvaluatedKey"> & {
36-
Items?: Record<string, NativeAttributeValue>[];
37-
LastEvaluatedKey?: Record<string, NativeAttributeValue>;
38+
Items?: Record<string, NativeAttributeValue>[] | undefined;
39+
LastEvaluatedKey?: Record<string, NativeAttributeValue> | undefined;
3840
};
3941

4042
/**

Diff for: lib/lib-dynamodb/src/commands/TransactGetCommand.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ export type TransactGetCommandInput = Omit<__TransactGetItemsCommandInput, "Tran
3131
* @public
3232
*/
3333
export type TransactGetCommandOutput = Omit<__TransactGetItemsCommandOutput, "Responses"> & {
34-
Responses?: (Omit<ItemResponse, "Item"> & {
35-
Item?: Record<string, NativeAttributeValue>;
36-
})[];
34+
Responses?:
35+
| (Omit<ItemResponse, "Item"> & {
36+
Item?: Record<string, NativeAttributeValue> | undefined;
37+
})[]
38+
| undefined;
3739
};
3840

3941
/**

0 commit comments

Comments
 (0)