Skip to content

Commit

Permalink
fix castExpr, add back untyped object
Browse files Browse the repository at this point in the history
  • Loading branch information
bhelx committed Oct 30, 2024
1 parent 6d9a0ba commit 095e8f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ function toTypeScriptTypeX(type: XtpNormalizedType): string {
case 'buffer':
return nullify('ArrayBufferLike')
case 'object':
return nullify((type as ObjectType).name)
const oType = (type as ObjectType)
if (oType.properties?.length > 0) {
return nullify(oType.name)
} else {
return nullify('any')
}
case 'enum':
return nullify((type as EnumType).name)
case 'map':
Expand Down
4 changes: 2 additions & 2 deletions template/src/pdk.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export function <%- imp.name %>(<%- imp.input ? `input: ${toTypeScriptType(imp.i
<% if (imp.input) { -%>
<% if (isJsonEncoded(imp.input)) { -%>
<% if (isObject(imp.input)) { %>
const casted = <%- castingFunction(imp.input.xtpType, 'From') %>(input)
const casted = cast(<%- castExpression(imp.input.xtpType, 'From') %>, input)
const mem = Memory.fromJsonObject(casted)
<% } else { %>
const mem = Memory.fromJsonObject(input as any)
Expand All @@ -150,7 +150,7 @@ export function <%- imp.name %>(<%- imp.input ? `input: ${toTypeScriptType(imp.i
<% if (isJsonEncoded(imp.output)) { -%>
<% if (isObject(imp.output)) { -%>
const output = Memory.find(ptr).readJsonObject();
return <%- castingFunction(imp.output.xtpType, 'To') %>(output)
return cast(<%- castExpression(imp.output.xtpType, 'To') %>, output)
<% } else { -%>
return Memory.find(ptr).readJsonObject();
<% } -%>
Expand Down

0 comments on commit 095e8f3

Please sign in to comment.