UNPKG

@mora-light/core

Version:
58 lines (46 loc) 1.68 kB
import '@dfinity/agent'; import '@dfinity/principal'; import { b as findChildTypeAndValue } from './running-8a3c3f51.esm.js'; import { doTransform } from '../types/transform/dist/mora-light-core-types-transform.esm.js'; // transmits 2 - show data for user const doTransmitShow = async (transmit, runtime, running) => { // 0. return err if there is error message if (runtime.err !== undefined) { transmit.view.runtime = runtime; return; } // console.error("check candid value 0", JSON.stringify(transmit), JSON.stringify(runtime.ok)); // 1. fetch child type let { value } = findChildTypeAndValue(runtime.ok, transmit.from, transmit.child); // console.error("check candid value 1", JSON.stringify(runtime), JSON.stringify(value)); // 2. do transform const transformResult = await doTransform(transmit.transform, value, running); if (transformResult.err !== undefined) { transmit.view.runtime = transformResult; return; } value = transformResult.ok; // console.error( // "check candid value 2", // transmit.constraint.need, // JSON.stringify(value), // JSON.stringify(runtime), // checkCandidValue(transmit.constraint.need, value), // ); // 3. check value and type // if (!checkCandidValue(transmit.constraint.need, value, [])) { // transmit.constraint.runtime = { // err: `wrong value ${JSON.stringify(value)} for type '${unwrapCandidType( // transmit.constraint.need, // )}'`, // }; // return; // } // console.error("check candid value set", value); transmit.view.runtime = { ok: value }; }; export { doTransmitShow as d };