Skip to content

Commit

Permalink
fix(lib-dynamodb): input types conflicts with client-dynamodb (#6683)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
kuhe and monholm authored Nov 20, 2024
1 parent dfea325 commit fb0e14e
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,11 @@ private void writeStructureMemberOmitType(MemberShape member) {
String optionalSuffix = isRequiredMember(member) ? "" : "?";
writer.openBlock("${L}${L}: ", ";", symbolProvider.toMemberName(member),
optionalSuffix, () -> {
writeMemberOmitType(member);
writeMemberOmitType(member, true);
});
}

private void writeMemberOmitType(MemberShape member) {
private void writeMemberOmitType(MemberShape member, boolean allowUndefined) {
Shape memberTarget = model.expectShape(member.getTarget());
if (memberTarget.isStructureShape()) {
writeStructureOmitType((StructureShape) memberTarget);
Expand All @@ -413,16 +413,17 @@ private void writeMemberOmitType(MemberShape member) {
} else if (memberTarget.isMapShape()) {
MemberShape mapMember = ((MapShape) memberTarget).getValue();
writer.openBlock("Record<string, ", ">", () -> {
writeMemberOmitType(mapMember);
writeMemberOmitType(mapMember, false);
});
} else if (memberTarget instanceof CollectionShape) {
MemberShape collectionMember = ((CollectionShape) memberTarget).getMember();
writer.openBlock("(", ")[]", () -> {
writeMemberOmitType(collectionMember);
writeMemberOmitType(collectionMember, false);
});
}
String typeSuffix = isRequiredMember(member) ? " | undefined" : "";
writer.write("${L}", typeSuffix);
if (allowUndefined) {
writer.write(" | undefined");
}
}

private void writeNativeAttributeValue() {
Expand Down
18 changes: 11 additions & 7 deletions lib/lib-dynamodb/src/commands/BatchExecuteStatementCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export { DynamoDBDocumentClientCommand, $Command };
export type BatchExecuteStatementCommandInput = Omit<__BatchExecuteStatementCommandInput, "Statements"> & {
Statements:
| (Omit<BatchStatementRequest, "Parameters"> & {
Parameters?: NativeAttributeValue[];
Parameters?: NativeAttributeValue[] | undefined;
})[]
| undefined;
};
Expand All @@ -27,12 +27,16 @@ export type BatchExecuteStatementCommandInput = Omit<__BatchExecuteStatementComm
* @public
*/
export type BatchExecuteStatementCommandOutput = Omit<__BatchExecuteStatementCommandOutput, "Responses"> & {
Responses?: (Omit<BatchStatementResponse, "Error" | "Item"> & {
Error?: Omit<BatchStatementError, "Item"> & {
Item?: Record<string, NativeAttributeValue>;
};
Item?: Record<string, NativeAttributeValue>;
})[];
Responses?:
| (Omit<BatchStatementResponse, "Error" | "Item"> & {
Error?:
| (Omit<BatchStatementError, "Item"> & {
Item?: Record<string, NativeAttributeValue> | undefined;
})
| undefined;
Item?: Record<string, NativeAttributeValue> | undefined;
})[]
| undefined;
};

/**
Expand Down
16 changes: 9 additions & 7 deletions lib/lib-dynamodb/src/commands/BatchGetCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ export type BatchGetCommandInput = Omit<__BatchGetItemCommandInput, "RequestItem
* @public
*/
export type BatchGetCommandOutput = Omit<__BatchGetItemCommandOutput, "Responses" | "UnprocessedKeys"> & {
Responses?: Record<string, Record<string, NativeAttributeValue>[]>;
UnprocessedKeys?: Record<
string,
Omit<KeysAndAttributes, "Keys"> & {
Keys: Record<string, NativeAttributeValue>[] | undefined;
}
>;
Responses?: Record<string, Record<string, NativeAttributeValue>[]> | undefined;
UnprocessedKeys?:
| Record<
string,
Omit<KeysAndAttributes, "Keys"> & {
Keys: Record<string, NativeAttributeValue>[] | undefined;
}
>
| undefined;
};

/**
Expand Down
58 changes: 35 additions & 23 deletions lib/lib-dynamodb/src/commands/BatchWriteCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ export type BatchWriteCommandInput = Omit<__BatchWriteItemCommandInput, "Request
| Record<
string,
(Omit<WriteRequest, "PutRequest" | "DeleteRequest"> & {
PutRequest?: Omit<PutRequest, "Item"> & {
Item: Record<string, NativeAttributeValue> | undefined;
};
DeleteRequest?: Omit<DeleteRequest, "Key"> & {
Key: Record<string, NativeAttributeValue> | undefined;
};
PutRequest?:
| (Omit<PutRequest, "Item"> & {
Item: Record<string, NativeAttributeValue> | undefined;
})
| undefined;
DeleteRequest?:
| (Omit<DeleteRequest, "Key"> & {
Key: Record<string, NativeAttributeValue> | undefined;
})
| undefined;
})[]
>
| undefined;
Expand All @@ -38,23 +42,31 @@ export type BatchWriteCommandOutput = Omit<
__BatchWriteItemCommandOutput,
"UnprocessedItems" | "ItemCollectionMetrics"
> & {
UnprocessedItems?: Record<
string,
(Omit<WriteRequest, "PutRequest" | "DeleteRequest"> & {
PutRequest?: Omit<PutRequest, "Item"> & {
Item: Record<string, NativeAttributeValue> | undefined;
};
DeleteRequest?: Omit<DeleteRequest, "Key"> & {
Key: Record<string, NativeAttributeValue> | undefined;
};
})[]
>;
ItemCollectionMetrics?: Record<
string,
(Omit<ItemCollectionMetrics, "ItemCollectionKey"> & {
ItemCollectionKey?: Record<string, NativeAttributeValue>;
})[]
>;
UnprocessedItems?:
| Record<
string,
(Omit<WriteRequest, "PutRequest" | "DeleteRequest"> & {
PutRequest?:
| (Omit<PutRequest, "Item"> & {
Item: Record<string, NativeAttributeValue> | undefined;
})
| undefined;
DeleteRequest?:
| (Omit<DeleteRequest, "Key"> & {
Key: Record<string, NativeAttributeValue> | undefined;
})
| undefined;
})[]
>
| undefined;
ItemCollectionMetrics?:
| Record<
string,
(Omit<ItemCollectionMetrics, "ItemCollectionKey"> & {
ItemCollectionKey?: Record<string, NativeAttributeValue> | undefined;
})[]
>
| undefined;
};

/**
Expand Down
28 changes: 16 additions & 12 deletions lib/lib-dynamodb/src/commands/DeleteCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,28 @@ export { DynamoDBDocumentClientCommand, $Command };
*/
export type DeleteCommandInput = Omit<__DeleteItemCommandInput, "Key" | "Expected" | "ExpressionAttributeValues"> & {
Key: Record<string, NativeAttributeValue> | undefined;
Expected?: Record<
string,
Omit<ExpectedAttributeValue, "Value" | "AttributeValueList"> & {
Value?: NativeAttributeValue;
AttributeValueList?: NativeAttributeValue[];
}
>;
ExpressionAttributeValues?: Record<string, NativeAttributeValue>;
Expected?:
| Record<
string,
Omit<ExpectedAttributeValue, "Value" | "AttributeValueList"> & {
Value?: NativeAttributeValue | undefined;
AttributeValueList?: NativeAttributeValue[] | undefined;
}
>
| undefined;
ExpressionAttributeValues?: Record<string, NativeAttributeValue> | undefined;
};

/**
* @public
*/
export type DeleteCommandOutput = Omit<__DeleteItemCommandOutput, "Attributes" | "ItemCollectionMetrics"> & {
Attributes?: Record<string, NativeAttributeValue>;
ItemCollectionMetrics?: Omit<ItemCollectionMetrics, "ItemCollectionKey"> & {
ItemCollectionKey?: Record<string, NativeAttributeValue>;
};
Attributes?: Record<string, NativeAttributeValue> | undefined;
ItemCollectionMetrics?:
| (Omit<ItemCollectionMetrics, "ItemCollectionKey"> & {
ItemCollectionKey?: Record<string, NativeAttributeValue> | undefined;
})
| undefined;
};

/**
Expand Down
6 changes: 3 additions & 3 deletions lib/lib-dynamodb/src/commands/ExecuteStatementCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ export { DynamoDBDocumentClientCommand, $Command };
* @public
*/
export type ExecuteStatementCommandInput = Omit<__ExecuteStatementCommandInput, "Parameters"> & {
Parameters?: NativeAttributeValue[];
Parameters?: NativeAttributeValue[] | undefined;
};

/**
* @public
*/
export type ExecuteStatementCommandOutput = Omit<__ExecuteStatementCommandOutput, "Items" | "LastEvaluatedKey"> & {
Items?: Record<string, NativeAttributeValue>[];
LastEvaluatedKey?: Record<string, NativeAttributeValue>;
Items?: Record<string, NativeAttributeValue>[] | undefined;
LastEvaluatedKey?: Record<string, NativeAttributeValue> | undefined;
};

/**
Expand Down
10 changes: 6 additions & 4 deletions lib/lib-dynamodb/src/commands/ExecuteTransactionCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export { DynamoDBDocumentClientCommand, $Command };
export type ExecuteTransactionCommandInput = Omit<__ExecuteTransactionCommandInput, "TransactStatements"> & {
TransactStatements:
| (Omit<ParameterizedStatement, "Parameters"> & {
Parameters?: NativeAttributeValue[];
Parameters?: NativeAttributeValue[] | undefined;
})[]
| undefined;
};
Expand All @@ -27,9 +27,11 @@ export type ExecuteTransactionCommandInput = Omit<__ExecuteTransactionCommandInp
* @public
*/
export type ExecuteTransactionCommandOutput = Omit<__ExecuteTransactionCommandOutput, "Responses"> & {
Responses?: (Omit<ItemResponse, "Item"> & {
Item?: Record<string, NativeAttributeValue>;
})[];
Responses?:
| (Omit<ItemResponse, "Item"> & {
Item?: Record<string, NativeAttributeValue> | undefined;
})[]
| undefined;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/lib-dynamodb/src/commands/GetCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type GetCommandInput = Omit<__GetItemCommandInput, "Key"> & {
* @public
*/
export type GetCommandOutput = Omit<__GetItemCommandOutput, "Item"> & {
Item?: Record<string, NativeAttributeValue>;
Item?: Record<string, NativeAttributeValue> | undefined;
};

/**
Expand Down
28 changes: 16 additions & 12 deletions lib/lib-dynamodb/src/commands/PutCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,28 @@ export { DynamoDBDocumentClientCommand, $Command };
*/
export type PutCommandInput = Omit<__PutItemCommandInput, "Item" | "Expected" | "ExpressionAttributeValues"> & {
Item: Record<string, NativeAttributeValue> | undefined;
Expected?: Record<
string,
Omit<ExpectedAttributeValue, "Value" | "AttributeValueList"> & {
Value?: NativeAttributeValue;
AttributeValueList?: NativeAttributeValue[];
}
>;
ExpressionAttributeValues?: Record<string, NativeAttributeValue>;
Expected?:
| Record<
string,
Omit<ExpectedAttributeValue, "Value" | "AttributeValueList"> & {
Value?: NativeAttributeValue | undefined;
AttributeValueList?: NativeAttributeValue[] | undefined;
}
>
| undefined;
ExpressionAttributeValues?: Record<string, NativeAttributeValue> | undefined;
};

/**
* @public
*/
export type PutCommandOutput = Omit<__PutItemCommandOutput, "Attributes" | "ItemCollectionMetrics"> & {
Attributes?: Record<string, NativeAttributeValue>;
ItemCollectionMetrics?: Omit<ItemCollectionMetrics, "ItemCollectionKey"> & {
ItemCollectionKey?: Record<string, NativeAttributeValue>;
};
Attributes?: Record<string, NativeAttributeValue> | undefined;
ItemCollectionMetrics?:
| (Omit<ItemCollectionMetrics, "ItemCollectionKey"> & {
ItemCollectionKey?: Record<string, NativeAttributeValue> | undefined;
})
| undefined;
};

/**
Expand Down
36 changes: 20 additions & 16 deletions lib/lib-dynamodb/src/commands/QueryCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,32 @@ export type QueryCommandInput = Omit<
__QueryCommandInput,
"KeyConditions" | "QueryFilter" | "ExclusiveStartKey" | "ExpressionAttributeValues"
> & {
KeyConditions?: Record<
string,
Omit<Condition, "AttributeValueList"> & {
AttributeValueList?: NativeAttributeValue[];
}
>;
QueryFilter?: Record<
string,
Omit<Condition, "AttributeValueList"> & {
AttributeValueList?: NativeAttributeValue[];
}
>;
ExclusiveStartKey?: Record<string, NativeAttributeValue>;
ExpressionAttributeValues?: Record<string, NativeAttributeValue>;
KeyConditions?:
| Record<
string,
Omit<Condition, "AttributeValueList"> & {
AttributeValueList?: NativeAttributeValue[] | undefined;
}
>
| undefined;
QueryFilter?:
| Record<
string,
Omit<Condition, "AttributeValueList"> & {
AttributeValueList?: NativeAttributeValue[] | undefined;
}
>
| undefined;
ExclusiveStartKey?: Record<string, NativeAttributeValue> | undefined;
ExpressionAttributeValues?: Record<string, NativeAttributeValue> | undefined;
};

/**
* @public
*/
export type QueryCommandOutput = Omit<__QueryCommandOutput, "Items" | "LastEvaluatedKey"> & {
Items?: Record<string, NativeAttributeValue>[];
LastEvaluatedKey?: Record<string, NativeAttributeValue>;
Items?: Record<string, NativeAttributeValue>[] | undefined;
LastEvaluatedKey?: Record<string, NativeAttributeValue> | undefined;
};

/**
Expand Down
22 changes: 12 additions & 10 deletions lib/lib-dynamodb/src/commands/ScanCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,24 @@ export type ScanCommandInput = Omit<
__ScanCommandInput,
"ScanFilter" | "ExclusiveStartKey" | "ExpressionAttributeValues"
> & {
ScanFilter?: Record<
string,
Omit<Condition, "AttributeValueList"> & {
AttributeValueList?: NativeAttributeValue[];
}
>;
ExclusiveStartKey?: Record<string, NativeAttributeValue>;
ExpressionAttributeValues?: Record<string, NativeAttributeValue>;
ScanFilter?:
| Record<
string,
Omit<Condition, "AttributeValueList"> & {
AttributeValueList?: NativeAttributeValue[] | undefined;
}
>
| undefined;
ExclusiveStartKey?: Record<string, NativeAttributeValue> | undefined;
ExpressionAttributeValues?: Record<string, NativeAttributeValue> | undefined;
};

/**
* @public
*/
export type ScanCommandOutput = Omit<__ScanCommandOutput, "Items" | "LastEvaluatedKey"> & {
Items?: Record<string, NativeAttributeValue>[];
LastEvaluatedKey?: Record<string, NativeAttributeValue>;
Items?: Record<string, NativeAttributeValue>[] | undefined;
LastEvaluatedKey?: Record<string, NativeAttributeValue> | undefined;
};

/**
Expand Down
8 changes: 5 additions & 3 deletions lib/lib-dynamodb/src/commands/TransactGetCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ export type TransactGetCommandInput = Omit<__TransactGetItemsCommandInput, "Tran
* @public
*/
export type TransactGetCommandOutput = Omit<__TransactGetItemsCommandOutput, "Responses"> & {
Responses?: (Omit<ItemResponse, "Item"> & {
Item?: Record<string, NativeAttributeValue>;
})[];
Responses?:
| (Omit<ItemResponse, "Item"> & {
Item?: Record<string, NativeAttributeValue> | undefined;
})[]
| undefined;
};

/**
Expand Down
Loading

0 comments on commit fb0e14e

Please sign in to comment.