@lifi/composer-sdk
Version:
Public Composer SDK for building and submitting flows
30 lines (29 loc) • 1.3 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
// 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;
exports.handleToRef = handleToRef;
exports.isInputHandle = isInputHandle;
exports.isOutputHandle = isOutputHandle;
exports.toBindValue = toBindValue;
//# sourceMappingURL=handles.cjs.map