UNPKG

@tokens-studio/graph-engine

Version:

An execution engine to handle Token Studios generators and resolvers

49 lines 1.77 kB
import { Node } from '../../programmatic/node.js'; import { annotatedDynamicInputs, annotatedSingleton } from '../../annotations/index.js'; import { getAllOutputs } from "../../utils/node.js"; /** * Acts as an output node for the graph. There should only be a single output node per graph. */ export default class NodeDefinition extends Node { static title = 'Output'; static type = 'studio.tokens.generic.output'; static description = 'Allows you to expose outputs of the node'; constructor(props) { super(props); this.annotations[annotatedSingleton] = true; this.annotations[annotatedDynamicInputs] = true; } static async deserialize(opts) { const node = await super.deserialize(opts); //Create the outputs immediately as we are just a passthrough Object.keys(node.inputs).forEach(input => { const rawInput = node.inputs[input]; node.addOutput(input, { visible: false, type: rawInput.type }); }); return node; } execute() { const inputs = this.getAllInputs(); const outputs = getAllOutputs(this); //Passthrough all Object.keys(inputs).forEach(input => { const rawInput = this.inputs[input]; if (!(input in outputs)) { this.addOutput(input, { type: rawInput.type, visible: false }); } this.outputs[input].set(rawInput.value, rawInput.type); }); Object.keys(outputs).forEach(output => { if (!(output in inputs)) { delete this.outputs[output]; } }); } } //# sourceMappingURL=output.js.map