Skip to content

Commit 87b1628

Browse files
committed
fix(lib-dynamodb): support exactOptionalPropertyTypes
1 parent ccc521c commit 87b1628

File tree

14 files changed

+100
-73
lines changed

14 files changed

+100
-73
lines changed

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

Lines changed: 7 additions & 6 deletions
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() {

lib/lib-dynamodb/src/commands/BatchExecuteStatementCommand.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
/**

lib/lib-dynamodb/src/commands/BatchGetCommand.ts

Lines changed: 9 additions & 7 deletions
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
/**

lib/lib-dynamodb/src/commands/BatchWriteCommand.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,31 @@ export type BatchWriteCommandOutput = Omit<
4242
__BatchWriteItemCommandOutput,
4343
"UnprocessedItems" | "ItemCollectionMetrics"
4444
> & {
45-
UnprocessedItems?: Record<
46-
string,
47-
(Omit<WriteRequest, "PutRequest" | "DeleteRequest"> & {
48-
PutRequest?: Omit<PutRequest, "Item"> & {
49-
Item: Record<string, NativeAttributeValue> | undefined;
50-
};
51-
DeleteRequest?: Omit<DeleteRequest, "Key"> & {
52-
Key: Record<string, NativeAttributeValue> | undefined;
53-
};
54-
})[]
55-
>;
56-
ItemCollectionMetrics?: Record<
57-
string,
58-
(Omit<ItemCollectionMetrics, "ItemCollectionKey"> & {
59-
ItemCollectionKey?: Record<string, NativeAttributeValue>;
60-
})[]
61-
>;
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;
6270
};
6371

6472
/**

lib/lib-dynamodb/src/commands/DeleteCommand.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ export type DeleteCommandInput = Omit<__DeleteItemCommandInput, "Key" | "Expecte
2020
Expected?:
2121
| Record<
2222
string,
23-
| Omit<ExpectedAttributeValue, "Value" | "AttributeValueList"> & {
24-
Value?: NativeAttributeValue;
25-
AttributeValueList?: NativeAttributeValue[] | undefined;
26-
}
23+
Omit<ExpectedAttributeValue, "Value" | "AttributeValueList"> & {
24+
Value?: NativeAttributeValue | undefined;
25+
AttributeValueList?: NativeAttributeValue[] | undefined;
26+
}
2727
>
2828
| undefined;
2929
ExpressionAttributeValues?: Record<string, NativeAttributeValue> | undefined;
@@ -33,10 +33,12 @@ export type DeleteCommandInput = Omit<__DeleteItemCommandInput, "Key" | "Expecte
3333
* @public
3434
*/
3535
export type DeleteCommandOutput = Omit<__DeleteItemCommandOutput, "Attributes" | "ItemCollectionMetrics"> & {
36-
Attributes?: Record<string, NativeAttributeValue>;
37-
ItemCollectionMetrics?: Omit<ItemCollectionMetrics, "ItemCollectionKey"> & {
38-
ItemCollectionKey?: Record<string, NativeAttributeValue>;
39-
};
36+
Attributes?: Record<string, NativeAttributeValue> | undefined;
37+
ItemCollectionMetrics?:
38+
| (Omit<ItemCollectionMetrics, "ItemCollectionKey"> & {
39+
ItemCollectionKey?: Record<string, NativeAttributeValue> | undefined;
40+
})
41+
| undefined;
4042
};
4143

4244
/**

lib/lib-dynamodb/src/commands/ExecuteStatementCommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export type ExecuteStatementCommandInput = Omit<__ExecuteStatementCommandInput,
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
/**

lib/lib-dynamodb/src/commands/ExecuteTransactionCommand.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
/**

lib/lib-dynamodb/src/commands/GetCommand.ts

Lines changed: 1 addition & 1 deletion
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
/**

lib/lib-dynamodb/src/commands/PutCommand.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ export type PutCommandInput = Omit<__PutItemCommandInput, "Item" | "Expected" |
3333
* @public
3434
*/
3535
export type PutCommandOutput = Omit<__PutItemCommandOutput, "Attributes" | "ItemCollectionMetrics"> & {
36-
Attributes?: Record<string, NativeAttributeValue>;
37-
ItemCollectionMetrics?: Omit<ItemCollectionMetrics, "ItemCollectionKey"> & {
38-
ItemCollectionKey?: Record<string, NativeAttributeValue>;
39-
};
36+
Attributes?: Record<string, NativeAttributeValue> | undefined;
37+
ItemCollectionMetrics?:
38+
| (Omit<ItemCollectionMetrics, "ItemCollectionKey"> & {
39+
ItemCollectionKey?: Record<string, NativeAttributeValue> | undefined;
40+
})
41+
| undefined;
4042
};
4143

4244
/**

lib/lib-dynamodb/src/commands/QueryCommand.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ export type QueryCommandInput = Omit<
4343
* @public
4444
*/
4545
export type QueryCommandOutput = Omit<__QueryCommandOutput, "Items" | "LastEvaluatedKey"> & {
46-
Items?: Record<string, NativeAttributeValue>[];
47-
LastEvaluatedKey?: Record<string, NativeAttributeValue>;
46+
Items?: Record<string, NativeAttributeValue>[] | undefined;
47+
LastEvaluatedKey?: Record<string, NativeAttributeValue> | undefined;
4848
};
4949

5050
/**

0 commit comments

Comments
 (0)