Skip to content

Conversation

kuhe
Copy link
Contributor

@kuhe kuhe commented Sep 30, 2025

Related: #1600

Rewrites parts of the schema-serde core for reduced code size.

  • @smithy/core
  • @smithy/util-base64

@kuhe kuhe requested a review from a team as a code owner September 30, 2025 20:18
@kuhe kuhe force-pushed the feat/code-cleanup branch from 9d7757c to 83ddb1c Compare September 30, 2025 20:20
@kuhe kuhe marked this pull request as draft October 2, 2025 15:10
@kuhe kuhe force-pushed the feat/code-cleanup branch 17 times, most recently from 9df9c78 to b342ac7 Compare October 8, 2025 15:36
const isKnownSchema = (() => {
const struct = unionSchema.getSchema() as StructureSchema;
return struct.memberNames.includes(unionMember);
})();
Copy link
Contributor Author

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);
Copy link
Contributor Author

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;
Copy link
Contributor Author

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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+/`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😉

@kuhe kuhe marked this pull request as ready for review October 8, 2025 16:00
fix base64 alphabetByValue

date util testing

chore: inline schema magic numbers
@kuhe kuhe force-pushed the feat/code-cleanup branch from b342ac7 to 8b4fc1e Compare October 8, 2025 16:37
* @param indicator - numeric indicator for preset trait combination.
* @returns equivalent trait object.
*/
export function translateTraits(indicator: SchemaTraits): SchemaTraitsObject {
Copy link
Contributor

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?

@kuhe kuhe merged commit 813c9a5 into main Oct 8, 2025
13 checks passed
@kuhe kuhe deleted the feat/code-cleanup branch October 8, 2025 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants