From 095e8f3efd713d7f9c7bd0b8140db144163b15a0 Mon Sep 17 00:00:00 2001 From: Benjamin Eckel Date: Wed, 30 Oct 2024 09:46:30 -0500 Subject: [PATCH] fix castExpr, add back untyped object --- src/index.ts | 7 ++++++- template/src/pdk.ts.ejs | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 3bee259..5e9f114 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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': diff --git a/template/src/pdk.ts.ejs b/template/src/pdk.ts.ejs index f4977be..16018f6 100644 --- a/template/src/pdk.ts.ejs +++ b/template/src/pdk.ts.ejs @@ -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) @@ -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(); <% } -%>