Skip to content

Commit 87d236c

Browse files
committed
fix: rename convertTypeofObject to convertClassInstanceToMap
Reason: we already convert null, binary, array, sets, pure JavaScript objects which also belong to Object.Prototype inheritance chain. This configuration converts other objects, aka different constructor.
1 parent 0c7658b commit 87d236c

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

packages/util-dynamodb/src/convertToAttr.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { NativeAttributeValue } from "./models";
77
describe("convertToAttr", () => {
88
describe("null", () => {
99
it(`returns for null`, () => {
10-
[false, true].forEach((convertTypeofObject) => {
11-
expect(convertToAttr(null, { convertTypeofObject })).toEqual({ NULL: true });
10+
[false, true].forEach((convertClassInstanceToMap) => {
11+
expect(convertToAttr(null, { convertClassInstanceToMap })).toEqual({ NULL: true });
1212
});
1313
});
1414
});
@@ -119,15 +119,15 @@ describe("convertToAttr", () => {
119119
new BigUint64Array(arr.map(BigInt)),
120120
].forEach((data) => {
121121
it(`returns for binary: ${data.constructor.name}`, () => {
122-
[false, true].forEach((convertTypeofObject) => {
123-
expect(convertToAttr(data, { convertTypeofObject })).toEqual({ B: data });
122+
[false, true].forEach((convertClassInstanceToMap) => {
123+
expect(convertToAttr(data, { convertClassInstanceToMap })).toEqual({ B: data });
124124
});
125125
});
126126
});
127127

128128
it("returns null for Binary when options.convertEmptyValues=true", () => {
129-
[false, true].forEach((convertTypeofObject) => {
130-
expect(convertToAttr(new Uint8Array(), { convertTypeofObject, convertEmptyValues: true })).toEqual({
129+
[false, true].forEach((convertClassInstanceToMap) => {
130+
expect(convertToAttr(new Uint8Array(), { convertClassInstanceToMap, convertEmptyValues: true })).toEqual({
131131
NULL: true,
132132
});
133133
});
@@ -399,13 +399,13 @@ describe("convertToAttr", () => {
399399
}).toThrowError(
400400
`Unsupported type passed: ${String(
401401
data
402-
)}. Pass options.convertTypeofObject=true to marshall typeof object as map attribute.`
402+
)}. Pass options.convertClassInstanceToMap=true to marshall typeof object as map attribute.`
403403
);
404404
});
405405
});
406406
});
407407

408-
describe("typeof object with options.convertTypeofObject=true", () => {
408+
describe("typeof object with options.convertClassInstanceToMap=true", () => {
409409
it("returns map for class", () => {
410410
class FooClass {
411411
constructor(
@@ -437,7 +437,7 @@ describe("convertToAttr", () => {
437437
}
438438
),
439439
{
440-
convertTypeofObject: true,
440+
convertClassInstanceToMap: true,
441441
}
442442
)
443443
).toEqual({
@@ -457,7 +457,7 @@ describe("convertToAttr", () => {
457457
});
458458

459459
it("returns empty for Date object", () => {
460-
expect(convertToAttr(new Date(), { convertTypeofObject: true })).toEqual({ M: {} });
460+
expect(convertToAttr(new Date(), { convertClassInstanceToMap: true })).toEqual({ M: {} });
461461
});
462462
});
463463
});

packages/util-dynamodb/src/convertToAttr.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const convertToAttr = (data: NativeAttributeValue, options?: marshallOpti
2727
// Do not alter binary data passed https://github.com/aws/aws-sdk-js-v3/issues/1530
2828
// @ts-expect-error Type '{ B: NativeAttributeBinary; }' is not assignable to type 'AttributeValue'
2929
return convertToBinaryAttr(data);
30-
} else if (options?.convertTypeofObject && typeof data === "object") {
30+
} else if (options?.convertClassInstanceToMap && typeof data === "object") {
3131
return convertToMapAttr(data as { [key: string]: NativeAttributeValue }, options);
3232
} else {
3333
return convertToScalarAttr(data as NativeScalarAttributeValue, options);
@@ -121,7 +121,7 @@ const convertToScalarAttr = (data: NativeScalarAttributeValue, options?: marshal
121121
return convertToStringAttr(data);
122122
}
123123
throw new Error(
124-
`Unsupported type passed: ${data}. Pass options.convertTypeofObject=true to marshall typeof object as map attribute.`
124+
`Unsupported type passed: ${data}. Pass options.convertClassInstanceToMap=true to marshall typeof object as map attribute.`
125125
);
126126
};
127127

packages/util-dynamodb/src/marshall.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export interface marshallOptions {
1818
/**
1919
* Whether to convert typeof object to map attribute.
2020
*/
21-
convertTypeofObject?: boolean;
21+
convertClassInstanceToMap?: boolean;
2222
}
2323

2424
/**

packages/util-dynamodb/src/models.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type NativeAttributeValue =
1515
| { [key: string]: NativeAttributeValue }
1616
| NativeAttributeValue[]
1717
| Set<number | bigint | NumberValue | string | NativeAttributeBinary | undefined>
18-
| InstanceType<{ new (...args: any[]): any }>; // accepts any class instance with options.convertTypeofObject
18+
| InstanceType<{ new (...args: any[]): any }>; // accepts any class instance with options.convertClassInstanceToMap
1919

2020
export type NativeScalarAttributeValue =
2121
| null

0 commit comments

Comments
 (0)