-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(client-sqs): create coercing serializers for awsQueryCompat (#5440
) * chore(client-sqs): use query-compat model * chore(client-sqs): generate as JSON protocol * chore(client-sqs): create coercing serializers for awsQueryCompat * chore(client-sqs): restore default model * chore(client-sqs): restore default client sqs
- Loading branch information
Showing
6 changed files
with
250 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { _toBool, _toNum, _toStr } from "./coercing-serializers"; | ||
|
||
const consoleWarn = console.warn; | ||
|
||
beforeAll(() => { | ||
console.warn = () => {}; | ||
}); | ||
|
||
afterAll(() => { | ||
console.warn = consoleWarn; | ||
}); | ||
|
||
describe(_toBool.name, () => { | ||
it("ignores nullish", () => { | ||
expect(_toBool(null)).toBe(null); | ||
expect(_toBool(undefined)).toBe(undefined); | ||
}); | ||
|
||
it("converts strings", () => { | ||
expect(_toBool("false")).toEqual(false); | ||
expect(_toBool("true")).toEqual(true); | ||
|
||
expect(_toBool("False")).toEqual(false); | ||
expect(_toBool("True")).toEqual(true); | ||
|
||
expect(_toBool("")).toEqual(false); | ||
expect(_toBool("a")).toEqual(true); // warns | ||
}); | ||
|
||
it("does not convert numbers", () => { | ||
expect(_toBool(0)).toEqual(0); | ||
expect(_toBool(1)).toEqual(1); | ||
}); | ||
}); | ||
|
||
describe(_toStr.name, () => { | ||
it("ignores nullish", () => { | ||
expect(_toStr(null)).toBe(null); | ||
expect(_toStr(undefined)).toBe(undefined); | ||
}); | ||
|
||
it("converts numbers", () => { | ||
expect(_toStr(0)).toEqual("0"); | ||
expect(_toStr(1)).toEqual("1"); | ||
}); | ||
|
||
it("converts booleans", () => { | ||
expect(_toStr(false)).toEqual("false"); | ||
expect(_toStr(true)).toEqual("true"); | ||
}); | ||
}); | ||
|
||
describe(_toNum.name, () => { | ||
it("ignores nullish", () => { | ||
expect(_toNum(null)).toBe(null); | ||
expect(_toNum(undefined)).toBe(undefined); | ||
}); | ||
|
||
it("converts numeric strings", () => { | ||
expect(_toNum("1234")).toEqual(1234); | ||
expect(_toNum("1234.56")).toEqual(1234.56); | ||
}); | ||
|
||
it("does not convert prefix-numeric strings", () => { | ||
expect(_toNum("1234abc")).toEqual("1234abc"); | ||
expect(_toNum("1234.56abc")).toEqual("1234.56abc"); | ||
}); | ||
|
||
it("does not convert non-numeric strings", () => { | ||
expect(_toNum("abcdef")).toEqual("abcdef"); | ||
}); | ||
it("does not convert bools", () => { | ||
expect(_toNum(false)).toEqual(false); | ||
expect(_toNum(true)).toEqual(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* @internal | ||
* | ||
* Used for awsQueryCompatibility trait. | ||
*/ | ||
export const _toStr = (val: unknown): string | undefined => { | ||
if (val == null) { | ||
return val as undefined; | ||
} | ||
if (typeof val === "number" || typeof val === "bigint") { | ||
const warning = new Error(`Received number ${val} where a string was expected.`); | ||
warning.name = "Warning"; | ||
console.warn(warning); | ||
return String(val); | ||
} | ||
if (typeof val === "boolean") { | ||
const warning = new Error(`Received boolean ${val} where a string was expected.`); | ||
warning.name = "Warning"; | ||
console.warn(warning); | ||
return String(val); | ||
} | ||
return val as string; | ||
}; | ||
|
||
/** | ||
* @internal | ||
* | ||
* Used for awsQueryCompatibility trait. | ||
*/ | ||
export const _toBool = (val: unknown): boolean | undefined => { | ||
if (val == null) { | ||
return val as undefined; | ||
} | ||
if (typeof val === "number") { | ||
// transmit to service to be rejected. | ||
} | ||
if (typeof val === "string") { | ||
const lowercase = val.toLowerCase(); | ||
if (val !== "" && lowercase !== "false" && lowercase !== "true") { | ||
const warning = new Error(`Received string "${val}" where a boolean was expected.`); | ||
warning.name = "Warning"; | ||
console.warn(warning); | ||
} | ||
return val !== "" && lowercase !== "false"; | ||
} | ||
return val as boolean; | ||
}; | ||
|
||
/** | ||
* @internal | ||
* | ||
* Used for awsQueryCompatibility trait. | ||
*/ | ||
export const _toNum = (val: unknown): number | undefined => { | ||
if (val == null) { | ||
return val as undefined; | ||
} | ||
if (typeof val === "boolean") { | ||
// transmit to service to be rejected. | ||
} | ||
if (typeof val === "string") { | ||
const num = Number(val); | ||
if (num.toString() !== val) { | ||
const warning = new Error(`Received string "${val}" where a number was expected.`); | ||
warning.name = "Warning"; | ||
console.warn(warning); | ||
return val as unknown as undefined; | ||
} | ||
return num; | ||
} | ||
return val as number; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from "./coercing-serializers"; | ||
export * from "./json/awsExpectUnion"; |