UNPKG

@1hive/connect-core

Version:

Access and interact with Aragon Organizations and their apps.

66 lines 2.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.describeTransaction = exports.describePath = exports.describeStep = void 0; const index_1 = require("../radspec/index"); async function describeStep(step, installedApps, provider) { let decoratedStep; // TODO: Add intent Basket support // Single transaction step // First see if the step can be handled with a specialized descriptor try { decoratedStep = await index_1.tryDescribingUpdateAppIntent(step, installedApps); } catch (err) { } // Finally, if the step wasn't handled yet, evaluate via radspec normally if (!decoratedStep) { try { decoratedStep = await index_1.tryEvaluatingRadspec(step, installedApps, provider); } catch (err) { } } // Annotate the description, if one was found if (decoratedStep === null || decoratedStep === void 0 ? void 0 : decoratedStep.description) { try { const { description, annotatedDescription } = await index_1.postprocessRadspecDescription(decoratedStep.description, installedApps); decoratedStep.description = description; decoratedStep.annotatedDescription = annotatedDescription !== null && annotatedDescription !== void 0 ? annotatedDescription : []; } catch (err) { } } if (decoratedStep === null || decoratedStep === void 0 ? void 0 : decoratedStep.children) { decoratedStep.children = await describePath(decoratedStep.children, installedApps, provider); } return decoratedStep || { ...step, description: '' }; } exports.describeStep = describeStep; /** * Use radspec to create a human-readable description for each step in the given `path` * */ async function describePath(path, installedApps, provider) { return Promise.all(path.map(async (step) => describeStep(step, installedApps, provider))); } exports.describePath = describePath; async function describeTransaction(transaction, installedApps, provider) { if (!transaction.to) { throw new Error(`Could not describe transaction: missing 'to'`); } if (!transaction.data) { throw new Error(`Could not describe transaction: missing 'data'`); } let description; try { description = await index_1.tryEvaluatingRadspec(transaction, installedApps, provider); if (description) { return index_1.postprocessRadspecDescription(description.description, installedApps); } } catch (err) { throw new Error(`Could not describe transaction: ${err}`); } return { description, }; } exports.describeTransaction = describeTransaction; //# sourceMappingURL=describe.js.map