Skip to content

Commit

Permalink
fix export json input deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
mhmd-azeez committed Dec 15, 2024
1 parent 518896c commit 5d74e5f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions bindgen-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ case $1 in
# Using ../../bundle so we test the bindgen template
PLUGIN_NAME=exampleplugin
echo "generating initial plugin code in '$(pwd)/$PLUGIN_NAME'..."
xtp plugin init --schema-file schema.yaml --template ../../bundle --path $PLUGIN_NAME --name $PLUGIN_NAME --feature stub-with-code-samples
xtp plugin init --schema-file schema.yaml --template ../../bundle --path $PLUGIN_NAME --name $PLUGIN_NAME --feature stub-with-code-samples --yes
echo "building '$PLUGIN_NAME'..."
xtp plugin build --path $PLUGIN_NAME
echo "testing '$PLUGIN_NAME'..."
xtp plugin test $PLUGIN_NAME/dist/plugin.wasm --with test.wasm --mock-host mock.wasm
xtp plugin test $PLUGIN_NAME/dist/plugin.wasm --with test.wasm --mock-host mock.wasm --log-level debug
;;
esac
6 changes: 3 additions & 3 deletions template/src/index.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ export function <%- ex.name %>(): number {
<% if (isJsonEncoded(ex.input)) { -%>
const jsonInput = Host.inputString()
let input = <%- getDefault(ex.input) %>;
let input: <%- toTypeScriptType(ex.input) %> = <%- getDefault(ex.input) %>;
if (jsonInput) {
<% if (isBuffer(ex.input)) { -%>
let input: <%- toTypeScriptType(ex.input) %> = Host.base64ToArrayBuffer(JSON.parse(Host.inputString()))
input = Host.base64ToArrayBuffer(JSON.parse(Host.inputString()))
<% } else if (isObject(ex.input)) { -%>
const untypedInput = JSON.parse(Host.inputString())
input = <%- toTypeScriptType(ex.input) %>.fromJson(untypedInput)
<% } else { -%>
let input: <%- toTypeScriptType(ex.input) %> = JSON.parse(Host.inputString())
input = JSON.parse(Host.inputString())
<% } -%>
}
<% } else if (ex.input.type === 'string') { -%>
Expand Down

0 comments on commit 5d74e5f

Please sign in to comment.