@lifi/composer-sdk
Version:
Public Composer SDK for building and submitting flows
26 lines (25 loc) • 1.14 kB
JavaScript
// src/authoring/handles.ts
/** Type guard that narrows an {@link AnyHandle} to an {@link InputHandle}. */
const isInputHandle = (h) => h._tag === "input";
/** Type guard that narrows an {@link AnyHandle} to an {@link OutputHandle}. */
const isOutputHandle = (h) => h._tag === "output";
/**
* Converts a handle to a JSON `$ref` pointer used in the flow document.
* Input handles become `"input.<name>"`; output handles become `"<nodeId>.<port>"`.
*/
const handleToRef = (h) => {
if (h._tag === "input") {
if (!h.inputName) throw new Error("InputHandle has empty inputName");
return { $ref: `input.${h.inputName}` };
}
if (!h.nodeId) throw new Error("OutputHandle has empty nodeId");
if (!h.portName) throw new Error("OutputHandle has empty portName");
return { $ref: `${h.nodeId}.${h.portName}` };
};
/**
* Converts a bindable to the wire `bind` value it denotes: handles become
* `$ref` pointers, refs and literals pass through as-is.
*/
const toBindValue = (bindable) => "_tag" in bindable ? handleToRef(bindable) : bindable;
export { handleToRef, isInputHandle, isOutputHandle, toBindValue };
//# sourceMappingURL=handles.js.map