UNPKG

@lifi/composer-sdk

Version:

Public Composer SDK for building and submitting flows

31 lines (30 loc) • 1.32 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); //#region 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; //#endregion exports.handleToRef = handleToRef; exports.isInputHandle = isInputHandle; exports.isOutputHandle = isOutputHandle; exports.toBindValue = toBindValue; //# sourceMappingURL=handles.cjs.map