-
Notifications
You must be signed in to change notification settings - Fork 7
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
int64 handling #164
Comments
@ronanyeah do you have an example schema (or portion of one) with an |
Thank you! This puts further emphasis on needing to figure out how to handle I don't really know what this config looks like yet but more discussion in the Discord is very welcome. |
One issue specific to int64 is that Elm uses I'm personally up for considering it as a config option in the new config-file approach, but I'm not going to write a JSON parser in Elm from scratch 😅 Compare what is needed in JS to use const bigJSON = '{"gross_gdp": 12345678901234567890}';
const bigObj = JSON.parse(bigJSON, (key, value, context) => {
if (key === "gross_gdp") {
// Ignore the value because it has already lost precision
return BigInt(context.source);
}
return value;
}); |
If you control the server the simplest path is to encode the number as a string and then parse it on the client after the JSON decoding |
This would be an int64Format : CliMonad.Format
int64Format =
{ basicType = Common.Integer
, format = "int64"
, annotation = Gen.Int64.annotation_.int64
, encode =
\int64 ->
int64
|> Gen.Int64.toSignedString
|> Gen.String.call_.toInt
|> Gen.Maybe.withDefault (Elm.int 0)
|> Gen.Json.Encode.call_.int
, decoder = Gen.Json.Decode.int |> Gen.Json.Decode.map Gen.Int64.call_.fromInt
, toParamString = Gen.Int64.toSignedString
, sharedDeclarations = []
, requiresPackages = [ "folkertdev/elm-int64" ]
} |
int64
is being handled as an ElmInt
, which is unsafe. It should beString
or someBigInt
type.The text was updated successfully, but these errors were encountered: