chore: version bump typescript, uuid, ... , fix failing tests and typing issues#646
chore: version bump typescript, uuid, ... , fix failing tests and typing issues#646kings1ay3r wants to merge 1 commit into
Conversation
- Update devDependencies in package.json - Fix TypeScript type errors in validation and parsers - Correct header serialization for objects - Resolve date and payload validation in test suites Signed-off-by: Kevin Mathew Sunny <tokevins@protonmail.com>
|
@lance @lholmquist can you please take a look? |
|
@lance @lholmquist can you please take a look? |
| export class DateParser extends Parser { | ||
| parse(payload: string): string { | ||
| let date = new Date(Date.parse(payload)); | ||
| const date = new Date(Date.parse(payload)); |
There was a problem hiding this comment.
Creating Date object is not needed when the date is invalid.
Better simply check isNaN() right after Date.parse().
Source:
If dateString fails to be parsed as a valid date, NaN is returned.
Suggested version of this class:
export class DateParser extends Parser {
parse(payload: string): string {
const timestamp = Date.parse(payload);
return (
isNaN(timestamp)
? new Date()
: new Date(timestamp)
).toISOString();
}
}| } else if (property !== CONSTANTS.DATA_ATTRIBUTE && property !== `${CONSTANTS.DATA_ATTRIBUTE}_base64`) { | ||
| headers[`${CONSTANTS.EXTENSIONS_PREFIX}${property}`] = value as string; | ||
| const headerName = `${CONSTANTS.EXTENSIONS_PREFIX}${property}`; | ||
| if (typeof value === "object") { |
There was a problem hiding this comment.
This might be a breaking change for projects that are using the wrong behavior (with "[object Object]").
Also note that typeof value === "object" is not a reliable check in JavaScript. For example, this check will destroy the error data:
- 🔴
JSON.stringify(new Error('useful message')) - 🟢
String(new Error('useful message'))
|
The only usage of overrides:
'uuid@8.3.2': '14.0.0' |
Proposed Changes
Description
Proper Header Serialization (src/message/http/headers.ts)
Previously, when an extension property was an object, it was improperly cast to a string via value as string. In JavaScript, this results in the exact string "[object Object]" being sent over the network, completely destroying the payload data. The fix properly uses JSON.stringify() when the header value is an object, preserving the data structure.
Type-Safe JSON Parsing (src/parsers.ts)
The JSONParser.parse() method was incorrectly typed to return a string, even though JSON.parse() returns an Object/Array. It was corrected to return unknown (which is standard for parsed JSON in TypeScript), preventing downstream typing assumptions.
Test Predictability (test/conformance/steps.ts & test/integration/emitter_factory_test.ts)
The conformance tests were blindly parsing missing dates, causing Invalid Date crashes if a time was missing. The fix safely checks if time exists before comparing date strings.
In emitter_factory_test.ts, the assertions now handle both pre-parsed objects and stringified JSON properties flexibly rather than blindly asserting deep equality on mismatched types.
Error Message Formatting (src/event/validation.ts)
The validation Error constructor was heavily relying on a dirty hack (// @ts-ignore) to coerce arrays of error objects into a single string. This was refactored to check Array.isArray(errors) and use a type-safe reduce loop to convert ErrorObject validation failures into a legible string.
Dependency Bumps (package.json)
DevDependencies like uuid, mocha, @cucumber/cucumber, axios, and typescript were suffering from legacy versioning that caused some of those implicit compilation errors you might have noticed. They were brought up to modern compatibility.
UUID package had a moderate vulnerability GHSA-w5hq-g745-h8pq
Fixes #647