Skip to content
Merged
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
2 changes: 1 addition & 1 deletion connect/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@permaweb/aoconnect",
"version": "0.0.92",
"version": "0.0.93",
"repository": {
"type": "git",
"url": "https://github.com/permaweb/ao.git",
Expand Down
37 changes: 20 additions & 17 deletions connect/src/client/ao-core.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import { debugLog } from '../logger.js'

function convertToLegacyOutput(jsonRes) {
let body = {}
function normalizeOutput(jsonRes) {
debugLog('info', 'HyperBEAM Response Body Raw:', jsonRes);

let body = {};
try {
body = JSON.parse(jsonRes?.results?.json?.body)
debugLog('info', 'HyperBEAM Response Body:', body)
} catch (_) { }
body = typeof jsonRes === 'string'
? JSON.parse(jsonRes?.results?.json?.body)
: jsonRes?.results?.raw ?? {};
} catch {}

debugLog('info', 'Parsed HyperBEAM Response Body:', body)
debugLog('info', 'Parsed HyperBEAM Response Body:', body);

return {
Output: body?.Output || {},
Messages: body?.Messages || [],
Assignments: body?.Assignments || [],
Spawns: body?.Spawns || [],
Error: body?.Error,
...(body ?? {})
}
Output: body.Output ?? {},
Messages: body.Messages ?? [],
Assignments: body.Assignments ?? [],
Spawns: body.Spawns ?? [],
Error: body.Error,
...body,
};
}

const baseParams = {
Expand Down Expand Up @@ -122,7 +125,7 @@ export function messageWith(deps) {
if (response.ok) {
const parsedResponse = await response.json()

if (args.opts?.fullResponse) return convertToLegacyOutput(parsedResponse)
if (args.opts?.fullResponse) return normalizeOutput(parsedResponse)
else return parsedResponse.slot
}
else throw new Error('Error sending message')
Expand All @@ -145,7 +148,7 @@ export function resultWith(deps) {
const response = await deps.aoCore.request(params)
if (response.ok) {
const parsedResponse = await response.json()
return convertToLegacyOutput(parsedResponse)
return normalizeOutput(parsedResponse)
}
else throw new Error('Error getting result')
} catch (e) {
Expand Down Expand Up @@ -182,7 +185,7 @@ export function resultsWith(deps) {
{
cursor: currentSlot,
node: {
...convertToLegacyOutput(parsedResultsResponse)
...normalizeOutput(parsedResultsResponse)
}
}
]
Expand Down Expand Up @@ -220,7 +223,7 @@ export function dryrunWith(deps) {
const response = await deps.aoCore.request(params)
if (response.ok) {
const parsedResponse = await response.json()
return convertToLegacyOutput(parsedResponse)
return normalizeOutput(parsedResponse)
}
else throw new Error('Error running dryrun')
} catch (e) {
Expand Down
Loading