-
Notifications
You must be signed in to change notification settings - Fork 107
refactoring to reduce code size #1720
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
Conversation
9d7757c
to
83ddb1c
Compare
9df9c78
to
b342ac7
Compare
const isKnownSchema = (() => { | ||
const struct = unionSchema.getSchema() as StructureSchema; | ||
return struct.memberNames.includes(unionMember); | ||
})(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the only call to hasMemberSchema, so I inlined the function here and removed it from the alpha API.
const [type, value] = event[unionMember]; | ||
eventType = type; | ||
serializer.write(SCHEMA.DOCUMENT, value); | ||
serializer.write(15 satisfies DocumentSchema, value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
importing even a numeric constant creates a lot of code under certain bundling conditions.
Rather than having a "magic number" 15, the TS satisfies
keyword is useful to indicate and type-check the number, allowing usage-finding.
? ((sc as MapSchema | ListSchema).valueSchema as typeof sc) | ||
: isDoc | ||
? (15 satisfies DocumentSchema) | ||
: void 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥺 forgive my triple nested ternary please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file contains date-parsers that are written differently from the ones used for model-ignorant-codegen but have the same interface.
To save on code size, they do less validation work by trusting the server timestamps. For example, no client-side validation of whether a year contains a leap-day.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same test suite as the regular date parsers is used, except for the aforementioned edge cases.
const maxLetterValue = 0b111111; | ||
|
||
export { alphabetByEncoding, alphabetByValue, bitsPerLetter, bitsPerByte, maxLetterValue }; | ||
const chars = `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😉
fix base64 alphabetByValue date util testing chore: inline schema magic numbers
b342ac7
to
8b4fc1e
Compare
* @param indicator - numeric indicator for preset trait combination. | ||
* @returns equivalent trait object. | ||
*/ | ||
export function translateTraits(indicator: SchemaTraits): SchemaTraitsObject { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: move this function to new file translateTraits.ts
?
Related: #1600
Rewrites parts of the schema-serde core for reduced code size.
@smithy/core
@smithy/util-base64