-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JSON doesn't constrain numeric values to be specific sizes. In most languages this isn't an issue thanks to proper support for a wide variety of number precision. Unfortunately JavaScript struggles with integer numbers bigger than `Number.MAX_SAFE_INTEGER`. This is due to JavaScript's implementation of integer values as `double`. For anything bigger than this max safe integer value JavaScript provides a `BigInt` type. The first issue with this behavior is that when parsing JSON, there is no way of telling which "number flavor" to expect, APIs just don't allow us to define so. Another issue is that the default JSON serializer/deserializer doesn't even know how to handle `BigInt`. This commit fixes those issues as followed: 1. Use a custom JSON parser `json-bigint` that can serialize and deserialze `BigInt` values. A quirk is that it will only deserialize a number into a `BigInt` if the serialized value ends up being bigger than JavaScript's max safe integer. This means there is ambiguity when deserialing data. 2. To address the ambiguity issue, I added a TypeScript mapped type `Deserialized<T>` that given a type `T` will replace all fields that are either `bigint` or `number`. Note that this is only static typing to teach TypeScript about this behavior. Then when receiving messages, one has to define `Normalizer` functions which will take this ambiguous type as input and return a "normalized" version that matches the original type `T`. See this as post-processing to make sure the received data is using the proper data types in the right places. 3. To help with the normalization I added a `createNormalizer` helper function that should statically figure out what fields need to be normalized for a given type and ensure that those are properly handled. 4. Rewrite all the tests to validate this logic using test data as coming out of the current Trace Server. Signed-off-by: Paul Marechal <paul.marechal@ericsson.com> Co-Authored-by: Patrick Tasse <patrick.tasse@ericsson.com>
- Loading branch information
1 parent
fa7ee18
commit f6f2d26
Showing
46 changed files
with
1,351 additions
and
435 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.ts] | ||
indent_size = 4 | ||
indent_style = space | ||
|
||
[*.test.ts] | ||
indent_size = 2 | ||
indent_style = space | ||
|
||
[*.json] | ||
indent_size = 2 | ||
indent_style = space |
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,3 @@ | ||
{ | ||
"typescript.tsdk": "node_modules/typescript/lib" | ||
} |
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 |
---|---|---|
|
@@ -20,4 +20,4 @@ | |
"json", | ||
"node" | ||
] | ||
} | ||
} |
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
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
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
Oops, something went wrong.