Skip to content

Use Record type in place of Object in SSDK libs #558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions smithy-typescript-ssdk-libs/server-apigateway/src/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function convertVersion1Response(response: HttpResponse): APIGatewayProxy
};
}
function convertResponseHeaders(headers: HeaderBag) {
const retVal: { [key: string]: string[] } = {};
const retVal: Record<string, string[]> = {};
for (const [key, val] of Object.entries(headers)) {
retVal[key] = val.split(",").map((v) => v.trim());
}
Expand All @@ -93,7 +93,7 @@ function hasVersion(event: any): event is Record<"version", string> {
}

function convertMultiValueHeaders(multiValueHeaders: APIGatewayProxyEventMultiValueHeaders | null) {
const retVal: { [key: string]: string } = {};
const retVal: Record<string, string> = {};

if (multiValueHeaders === null) {
return retVal;
Expand All @@ -112,7 +112,7 @@ function convertMultiValueHeaders(multiValueHeaders: APIGatewayProxyEventMultiVa
// but first we need to split up generated client and servers so we can have different
// language version targets.
function convertHeaders(headers: APIGatewayProxyEventHeaders): HeaderBag {
const retVal: { [key: string]: string } = {};
const retVal: Record<string, string> = {};

for (const [key, val] of Object.entries(headers)) {
if (val !== undefined) {
Expand All @@ -128,7 +128,7 @@ function convertMultiValueQueryStringParameters(params: APIGatewayProxyEventMult
return undefined;
}

const retVal: { [key: string]: string[] } = {};
const retVal: Record<string, string[]> = {};

for (const [key, val] of Object.entries(params)) {
if (val !== undefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,13 @@ export class CompositeCollectionValidator<T> implements MultiConstraintValidator
}
}

export class CompositeMapValidator<T> implements MultiConstraintValidator<{ [key: string]: T }> {
private readonly referenceValidator: MultiConstraintValidator<{ [key: string]: T }>;
export class CompositeMapValidator<T> implements MultiConstraintValidator<Record<string, T>> {
private readonly referenceValidator: MultiConstraintValidator<Record<string, T>>;
private readonly keyValidator: MultiConstraintValidator<string>;
private readonly valueValidator: MultiConstraintValidator<T>;

constructor(
referenceValidator: MultiConstraintValidator<{ [key: string]: T }>,
referenceValidator: MultiConstraintValidator<Record<string, T>>,
keyValidator: MultiConstraintValidator<string>,
valueValidator: MultiConstraintValidator<T>
) {
Expand All @@ -105,7 +105,7 @@ export class CompositeMapValidator<T> implements MultiConstraintValidator<{ [key
this.valueValidator = valueValidator;
}

validate(input: { [key: string]: T } | undefined | null, path: string): ValidationFailure[] {
validate(input: Record<string, T> | undefined | null, path: string): ValidationFailure[] {
const retVal: ValidationFailure[] = [];
retVal.push(...this.referenceValidator.validate(input, path));
if (input !== null && input !== undefined) {
Expand Down Expand Up @@ -175,7 +175,7 @@ export class EnumValidator implements SingleConstraintValidator<string, EnumVali
}
}

type LengthCheckable = string | { length: number } | { [key: string]: any };
type LengthCheckable = string | { length: number } | Record<string, any>;

export class LengthValidator implements SingleConstraintValidator<LengthCheckable, LengthValidationFailure> {
private readonly min?: number;
Expand Down