import{bE as e,b7 as t}from"./flowdrop.es.js?v=1.4.0";function r(e){switch(e){case"string":return"string";case"number":return"number";case"integer":return"integer";case"boolean":return"boolean";case"array":return"array";case"object":return"object";case"float":return"float";default:return"mixed"}}function i(e,t,o,a){const s={name:e,label:t.title??e,description:t.description,type:r(t.type),sourcePort:o,sourceNode:a};if("object"===t.type&&t.properties){s.properties={};for(const[e,r]of Object.entries(t.properties))s.properties[e]=i(e,r,o,a)}return"array"===t.type&&t.items&&(s.items=i("item",t.items,o,a)),s}function o(e,t){if(e.schema&&e.schema.properties){const r={name:e.id,label:e.name,description:e.description,type:"object",sourcePort:e.id,sourceNode:t,properties:{}};for(const[o,a]of Object.entries(e.schema.properties))r.properties[o]=i(o,a,e.id,t);return r}return{name:e.id,label:e.name,description:e.description,type:r(e.dataType),sourcePort:e.id,sourceNode:t}}function a(e){if(!e)return;const t=e.match(/-output-(.+)$/);if(t)return t[1];const r=e.match(/-input-(.+)$/);return r?r[1]:e}function s(e,t,r,s){const n={},{targetPortIds:c,includePortName:p}=s??{},u=function(e,t,r){const i=[],o=r.filter(t=>t.target===e.id);for(const s of o){const r=t.find(e=>e.id===s.source);if(!r)continue;const o=a(s.sourceHandle),n=a(s.targetHandle),c=r.data.metadata.outputs.find(e=>e.id===o),p=e.data.metadata.inputs.find(e=>e.id===n);i.push({edge:s,sourceNode:r,sourcePort:c,targetPort:p})}return i}(e,t,r);for(const a of u){const{sourceNode:e,sourcePort:t,targetPort:r}=a;if("trigger"===t?.dataType)continue;if("trigger"===r?.dataType)continue;const s=r?.id??t?.id??"data";if((void 0===c||c.includes(s))&&t)if(t.schema?.properties&&!p)for(const[o,a]of Object.entries(t.schema.properties))n[o]||(n[o]=i(o,a,t.id,e.id));else{const i=s;if(n[i])continue;const a=o(t,e.id);a.name=i,a.label=r?.name??t.name,n[i]=a}}return{variables:n}}function n(e,t){const r=t.split(".");let i;for(let o=0;o<r.length;o++){const t=r[o],a=t.match(/^(\w+)\[(\d+|\*)\]$/);if(a){const[,t]=a;0===o?i=e.variables[t]:i?.properties&&(i=i.properties[t]),i?.items&&(i=i.items);continue}if(0===o)i=e.variables[t];else{if(!i?.properties)return[];i=i.properties[t]}}return i?.properties?Object.values(i.properties):[]}function c(e=2){const t=[];for(let r=0;r<=e;r++)t.push(`${r}]`);return t.push("*]"),t}function p(e,t){const r=t.split(".");let i;for(let o=0;o<r.length;o++){const t=r[o],a=t.match(/^(\w+)\[(\d+|\*)\]$/);if(a){const[,t]=a;0===o?i=e.variables[t]:i?.properties&&(i=i.properties[t]),i?.items&&(i=i.items);continue}if(0===o)i=e.variables[t];else{if(!i?.properties)return!1;i=i.properties[t]}}return"array"===i?.type}function u(e,t){const r={...t.variables};for(const[i,o]of Object.entries(e.variables))r[i]=o;return{variables:r}}async function f(r,i,o,a,n,c){let p={variables:{}};if(a.api)try{const{fetchVariableSchema:f}=await e(async()=>{const{fetchVariableSchema:e}=await import("./flowdrop-api-variable-service.js?v=1.4.0");return{fetchVariableSchema:e}},[]),l=await f(n,r.id,a.api,c);if(l.success&&l.schema){if(p=l.schema,!1!==a.api.mergeWithSchema&&a.schema&&(p=u(p,a.schema)),a.api.mergeWithPorts){p=u(p,s(r,i,o,{targetPortIds:a.ports,includePortName:a.includePortName}))}return p}if(!a.api.fallbackOnError)return t.error("Failed to fetch variables from API:",l.error),{variables:{}}}catch(f){if(t.error("Error fetching variables from API:",f),!1===a.api.fallbackOnError)return{variables:{}}}if(void 0!==a.ports||!a.api){p=s(r,i,o,{targetPortIds:a.ports,includePortName:a.includePortName})}return a.schema&&(p=u(a.schema,p)),p}export{n as a,c as b,f as c,s as g,p as i};
//# sourceMappingURL=flowdrop-variable-service.js.map
