Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions package/src/GraphEntityGenTemplates.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package/src/GraphEntityGenTemplates.res
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ let toStringConverter = (paramName, paramType) =>
switch paramType {
| "Bytes" => `${paramName}.toHex()`
| "Address" => `${paramName}.toHex()`
| "BigInt" => `${paramName}.toString()`
| "Int"
| "BigInt" =>
`${paramName}.toString()`
| "BigDecimal" => `${paramName}.toString()`
| "String" => paramName
| unknownType => `"unhandled type in converter ${unknownType} - Please fix the converter"`
Expand Down
31 changes: 29 additions & 2 deletions package/src/Index.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 32 additions & 4 deletions package/src/Index.res
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,31 @@ let getNamedType = (~entityAsIdString, name) => {
}
}

let getAssemblyScriptTypeFromConfigType = configType => {
switch configType {
| #String => "string"
| #Int => "i32"
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the main thing that is needed in this here.

| #BigInt => "BigInt"
| #Bytes => "Bytes"
| #Boolean => "boolean"
| #BigDecimal => "BigDecimal"
| #constant =>
Js.log("Please report a bug on github. This case shouldn't happen")
""
| uncaught =>
let nonStandardTypeString = uncaught->Obj.magic

if entitiesMap->Js.Dict.get(nonStandardTypeString)->Option.isSome {
nonStandardTypeString
} else if enumsMap->Js.Dict.get(nonStandardTypeString)->Option.isSome {
"string"
} else {
Js.log(unhandledTypeMessage(~uncaught))
"UNHANDLED_TYPE"
}
}
}

let rec getFieldType = (~entityAsIdString=false, field) =>
switch field["kind"] {
| #NamedType => field["name"]->getNamedType(~entityAsIdString)
Expand Down Expand Up @@ -285,14 +310,17 @@ let run = (~entityDefinitions, ~codegenConfigPath, ~outputFilePath) => {
->Option.map(idArgs => {
let argsDefinition =
idArgs
->Array.keep(arg => arg["type"] != "constant")
->Array.joinWith(",", arg => `${arg["name"]}: ${arg["type"]}`)
->Array.keep(arg => arg["type"] != #constant)
->Array.joinWith(
",",
arg => `${arg["name"]}: ${getAssemblyScriptTypeFromConfigType(arg["type"])}`,
)
// no string interpolation in assemblyscript :(
let idString = idArgs->Array.joinWith(
` + "-" + `,
arg =>
if arg["type"] != "constant" {
toStringConverter(arg["name"], arg["type"])
if arg["type"] != #constant {
toStringConverter(arg["name"], getAssemblyScriptTypeFromConfigType(arg["type"]))
} else {
`"${arg["value"]}"`
},
Expand Down
1 change: 1 addition & 0 deletions package/src/validation/UncrashableValidation.bs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package/src/validation/UncrashableValidation.res
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let confirmTypeIsSupported = argType => {
switch argType {
| "String"
| "BigInt"
| "Int"
| "Bytes"
| "Boolean"
| "Address"
Expand Down