@fluidgrids/fe-sdk 0.0.0-stage → 2026.1203.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (323) hide show
  1. package/README.md +564 -2
  2. package/dist/ActivityOptionsFields-C2u-hY2U.js +142 -0
  3. package/dist/AiStudioPage-B_hNTj-_.js +1137 -0
  4. package/dist/ApprovalInboxPage-ClITra3n.js +1312 -0
  5. package/dist/ChoiceSelect-LkK-uS9J.js +65 -0
  6. package/dist/ConfirmActionDialog-DHWTDRbp.js +31 -0
  7. package/dist/ConnectionFormDialog-C0kDgcrZ.js +153 -0
  8. package/dist/CreateFluidgridsTagDocument-Dtp9KPLJ.js +1055 -0
  9. package/dist/DataSinkDashboardPage-b4ezeqa6.js +278 -0
  10. package/dist/DataTablesPage-C1d9YGHz.js +5575 -0
  11. package/dist/DateTimeField-B1qR4ruo.js +51 -0
  12. package/dist/Disclosure-BNKij7-v.js +45 -0
  13. package/dist/ElementLibraryPage-8jNO6YmE.js +2256 -0
  14. package/dist/ElementLibrarySequenceDocument-B-W8SPzn.js +3979 -0
  15. package/dist/EnsureThemeProvider-BvlNjAd0.js +24 -0
  16. package/dist/EntityTagBadge-1OlP6p0c.js +25 -0
  17. package/dist/EntityTagPicker-BBrU5cE0.js +137 -0
  18. package/dist/ExecuteStepDocument-B4j1mdRT.js +189 -0
  19. package/dist/ExecutionDetailDocument-D6QuM-kp.js +875 -0
  20. package/dist/ExecutionDetailPage-D4CBtFdo.js +12217 -0
  21. package/dist/ExecutionDetailPage-DvQ667OE.d.ts +10 -0
  22. package/dist/ExecutionStatusBadge-BsDVor9t.js +221 -0
  23. package/dist/ExecutionsListDocument-Dan7ZiqB.js +459 -0
  24. package/dist/ExecutionsListPage-B3XT8ITL.js +4307 -0
  25. package/dist/FailureTriagePanel-DOJMaJ0n.js +1285 -0
  26. package/dist/FileDownloadUrlDocument-CVOYKcL5.js +92 -0
  27. package/dist/FluidGridsDocsLink-bX0Hnhxr.js +66 -0
  28. package/dist/FluidGridsMark-CE2blT7K.js +74 -0
  29. package/dist/HeldLoadRegion-BtTxbvOW.js +34 -0
  30. package/dist/HistoryPage-BLoRpJ1R.d.ts +6 -0
  31. package/dist/HistoryPage-BSBISXoj.js +2835 -0
  32. package/dist/Icon-BtQ0HXLh.js +160 -0
  33. package/dist/InsightsPage-D7ybj8N9.js +11245 -0
  34. package/dist/IsolationSetting-vy911E8b.js +1153 -0
  35. package/dist/LibraryParts-DOeNgR8A.js +413 -0
  36. package/dist/ManagedAiPolicyAuthority-BxwJ3ptd.js +40 -0
  37. package/dist/ManagedAiPolicyAuthority-DM3t3wNr.d.ts +18 -0
  38. package/dist/ManagedAiPolicyAuthorityContext-CNkxIOZ1.js +10 -0
  39. package/dist/McpTriggerServers-BCPCAOWB.js +459 -0
  40. package/dist/MissingNodesInstallModal-rO_SEDrC.js +224 -0
  41. package/dist/NavigationV2Provider-DCDt35eG.js +17 -0
  42. package/dist/NodeSchemaIntrospectionDocument-C1vAIcHd.js +95 -0
  43. package/dist/NodesPage-DEbnz9iU.d.ts +6 -0
  44. package/dist/NodesPage-O7KeeKtd.js +653 -0
  45. package/dist/OfflineIcon-TwMKYWjA.js +207 -0
  46. package/dist/OpenTemplateAsCodeButton-BhWJWIF3.js +94 -0
  47. package/dist/PaidTemplateConfirm-_G3ag6S4.js +28 -0
  48. package/dist/PublishCustomNodeAction-CIySbK4c.js +134 -0
  49. package/dist/RecordTaskDialog-BkpCDvhR.js +2078 -0
  50. package/dist/RunActionsMenu-DodOgIQm.js +59 -0
  51. package/dist/RunnerStatusPill-C1v967iq.js +24 -0
  52. package/dist/RunnersPage-dB0RSdY_.js +1929 -0
  53. package/dist/SandboxRuntimeExhaustedNotice-BFOIF93C.js +120 -0
  54. package/dist/SchedulesPage-DPWr1yvf.js +1607 -0
  55. package/dist/SearchBox-BGtYjvfs.js +49 -0
  56. package/dist/SequenceEditor-CFiHeHkR.js +497 -0
  57. package/dist/SettingsPage-0CQBNPZV.js +8695 -0
  58. package/dist/StewardPages-DAJhepen.js +47 -0
  59. package/dist/StewardRunImportPanel-Kva2DO0u.js +2844 -0
  60. package/dist/StoreTemplateCardCompact-CHn5kP7A.js +2166 -0
  61. package/dist/TagFilterSelect-CyA8QrS7.js +42 -0
  62. package/dist/TaskQueuesPage-DdnDCyat.js +3571 -0
  63. package/dist/TechnicalDetails-B0Oi4aZw.js +19 -0
  64. package/dist/TemplateConfigurationModal-CdvCYJLM.js +332 -0
  65. package/dist/TemplateDetailPanel-CbiKciuB.js +222 -0
  66. package/dist/TemplatePreview-cx7-NOeG.js +868 -0
  67. package/dist/TemplatesPage-BG3H-6v6.d.ts +10 -0
  68. package/dist/TemplatesPage-BVQpGYIV.js +3251 -0
  69. package/dist/TerminateExecutionDocument-B_HKNVrN.js +581 -0
  70. package/dist/TranslationBridge-Bd4aJKMs.d.ts +11 -0
  71. package/dist/TranslationBridge-Da-TPgQm.js +68 -0
  72. package/dist/TriggerWorkflowDocument-D9Km2Vv2.js +460 -0
  73. package/dist/UiSequencePickerSequenceDocument-BSYnSDV7.js +607 -0
  74. package/dist/UiStepScreenshot-Qh4QMyUp.js +146 -0
  75. package/dist/UsageTimeSeriesDocument-DcInx9-z.js +177 -0
  76. package/dist/VariablesPage-ChfGuW22.js +2243 -0
  77. package/dist/VersionDiffDialog-Bd2AeUwf.js +1702 -0
  78. package/dist/VersionLifecycleBar-BBeWVtz-.js +143 -0
  79. package/dist/WebhookDeliveriesPage-D66bua0j.js +1563 -0
  80. package/dist/WorkflowBuilder-B6wQD1TK.js +539 -0
  81. package/dist/WorkflowBuilder-DR4ku8Tr.js +1611 -0
  82. package/dist/WorkflowDefinitionDocument-DZLbTPUZ.js +321 -0
  83. package/dist/WorkflowEmbed-BXfFGy0i.js +708 -0
  84. package/dist/WorkflowEmbed-Cbqe1s1z.d.ts +6 -0
  85. package/dist/WorkflowPinnedDataDocument-BODT5omd.js +782 -0
  86. package/dist/WorkflowProposalCard-BruukdeF.js +96 -0
  87. package/dist/WorkflowProposalDocument-BdUbsrd0.js +620 -0
  88. package/dist/WorkflowSearchRedirect-C7zJ2MKH.js +40 -0
  89. package/dist/WorkflowSettingsDrawer-MVU1BKfY.d.ts +18 -0
  90. package/dist/WorkflowSettingsDrawer-gazs97WR.js +196 -0
  91. package/dist/WorkflowShareDialog-e8jJtLjU.js +469 -0
  92. package/dist/WorkflowVersionsDocument-DRVOp8Uj.js +3213 -0
  93. package/dist/WorkflowsList--hR2_8gf.js +4593 -0
  94. package/dist/WorkflowsList-CcNDQge5.d.ts +6 -0
  95. package/dist/WorkflowsListPageDocument-CnzcQm_o.js +934 -0
  96. package/dist/addonCatalog-CbZS4deh.js +58 -0
  97. package/dist/addonCatalog-sjlonAmR.d.ts +15 -0
  98. package/dist/addons.d.ts +3 -0
  99. package/dist/addons.js +4 -0
  100. package/dist/agent-form-Bfvm32j1.js +83 -0
  101. package/dist/agent-tools.d.ts +3 -0
  102. package/dist/agent-tools.js +5 -0
  103. package/dist/agentTools-CyL7DLOF.js +320 -0
  104. package/dist/ai-usage-BrxDgvdR.js +240 -0
  105. package/dist/aiCreditsBridge-BuE92tKo.js +49 -0
  106. package/dist/api-BKq-nIOZ.js +2286 -0
  107. package/dist/api-Ol7I8NxE.js +8289 -0
  108. package/dist/apollo-type-policies.d.ts +11 -0
  109. package/dist/apollo-type-policies.js +64 -0
  110. package/dist/askAboutBridge-ByYsQams.js +106 -0
  111. package/dist/askQuestions-Cmx7VnMm.js +742 -0
  112. package/dist/assert-rules-lfYEMc99.js +318 -0
  113. package/dist/assistant.d.ts +94 -0
  114. package/dist/assistant.js +99 -0
  115. package/dist/attach-node-helpers-HDKQOtrD.js +32 -0
  116. package/dist/badge-CXfPhoMH.js +26 -0
  117. package/dist/basil.generated-BK-EHbwN.js +10 -0
  118. package/dist/browser-steps-DMpS5TyB.js +533 -0
  119. package/dist/builderTimings-pvGnK1m-.js +510 -0
  120. package/dist/button-DG7y_FVJ.js +48 -0
  121. package/dist/canvasNoteTools-BxuP_AYO.js +137 -0
  122. package/dist/card-Bomy_1UG.js +44 -0
  123. package/dist/catalogGrid-BOrfMgi-.js +41 -0
  124. package/dist/channel-CPyQ1NR1.js +212 -0
  125. package/dist/chips-CvNrYJZa.js +27 -0
  126. package/dist/client-holder-C0M5Cfwl.js +68 -0
  127. package/dist/cn-QqidFIgr.js +10 -0
  128. package/dist/code-editor-diagnostics-Zr0cIcx1.js +46 -0
  129. package/dist/code-editor-field-x_JrY8KR.js +113 -0
  130. package/dist/codec-client-DPuD6mw7.js +515 -0
  131. package/dist/conditionBuilder-DwfEF0Q-.js +1144 -0
  132. package/dist/config-DO68jw5k.js +322 -0
  133. package/dist/constants-DgbVc24O.d.ts +296 -0
  134. package/dist/constants-DlRnHBfQ.js +217 -0
  135. package/dist/convert-browser-action-pfecelF7.js +347 -0
  136. package/dist/convert-dialog-B_o22NiJ.js +382 -0
  137. package/dist/create-workflow-first-Azg3JUdX.js +120 -0
  138. package/dist/definition-canvas-Bsda-rDT.js +31 -0
  139. package/dist/dialog-BVd152GS.js +94 -0
  140. package/dist/durable-nodes-BXyYCLxT.js +91 -0
  141. package/dist/duration-CDb7-mT_.js +33 -0
  142. package/dist/edge-mapper-wEAdGVU2.js +4477 -0
  143. package/dist/element-library-DkSlg_VE.js +727 -0
  144. package/dist/entities-I_0kio3q.js +38 -0
  145. package/dist/error-advice-QLr5NCm7.js +65 -0
  146. package/dist/errors-ClKb5sEt.js +188 -0
  147. package/dist/executions.d.ts +3 -0
  148. package/dist/executions.js +5 -0
  149. package/dist/feature-flags-B2qetXKd.js +385 -0
  150. package/dist/field-label-DPZRmE_B.js +153 -0
  151. package/dist/firstWorkflow-C_h0KMB2.js +133 -0
  152. package/dist/flags.d.ts +3 -0
  153. package/dist/flags.js +4 -0
  154. package/dist/flow-builder-DIvLOhz0.js +28038 -0
  155. package/dist/flow-store-holder-CUN7Terz.js +52 -0
  156. package/dist/fluent.generated-CA_e6-4l.js +14 -0
  157. package/dist/fluidgridsEvents-bbEQbwU6.js +175 -0
  158. package/dist/fluidgridsTheme-DUhvOgoy.js +297 -0
  159. package/dist/global-client-BQPuFrFa.js +433 -0
  160. package/dist/global-operations-BG6YgxrM.js +136 -0
  161. package/dist/graphql-types-UTYtujY9.js +21358 -0
  162. package/dist/history.d.ts +3 -0
  163. package/dist/history.js +4 -0
  164. package/dist/index-AoJAa5vU.d.ts +164958 -0
  165. package/dist/index-DEMT3iAM.d.ts +120 -0
  166. package/dist/index-ROZzNGyY.d.ts +76 -0
  167. package/dist/index.d.ts +20 -0
  168. package/dist/index.js +8123 -0
  169. package/dist/ion.generated-mbajjcAg.js +10 -0
  170. package/dist/label-Lzb8ZXf_.js +29 -0
  171. package/dist/labels-rXd9gYQz.js +1236 -0
  172. package/dist/liveCanvas-D5ytXDp8.js +103 -0
  173. package/dist/logos.generated-X6_0kjVR.js +21 -0
  174. package/dist/logs-panel-Cw0DkG0l.js +468 -0
  175. package/dist/lucide.generated-B6NVd3GT.js +29 -0
  176. package/dist/marksStore-a9oIMMot.js +175 -0
  177. package/dist/mcp-trigger-D0nRdvq5.js +307 -0
  178. package/dist/mdi.generated-D1BV74d6.js +292 -0
  179. package/dist/menus-CU3hDGYl.js +160 -0
  180. package/dist/mynaui.generated-DMWr5cXz.js +66 -0
  181. package/dist/navigation-v2.d.ts +3 -0
  182. package/dist/navigation-v2.js +5 -0
  183. package/dist/node-detail-view-Cgm5H1P-.js +1372 -0
  184. package/dist/node-editor-tab-body-CZ0fVuVP.js +187 -0
  185. package/dist/node-operation-selection-CdV3KI_V.js +3534 -0
  186. package/dist/node-registry-refresh-s3okf83X.js +27 -0
  187. package/dist/node-role-TMbnkmeP.js +132 -0
  188. package/dist/node-type-icon-BZa8n4iG.js +33 -0
  189. package/dist/nodes.d.ts +3 -0
  190. package/dist/nodes.js +4 -0
  191. package/dist/notesKey-5EaREBGA.js +12 -0
  192. package/dist/observability.d.ts +3 -0
  193. package/dist/observability.js +5 -0
  194. package/dist/offset-pages-zghoClB3.js +55 -0
  195. package/dist/operations-BBmT9ToP.js +663 -0
  196. package/dist/operations-WxRJWeqO.js +3133 -0
  197. package/dist/output-files-Ba8bu5lv.js +196 -0
  198. package/dist/page-operation-DrWuhd6Y.js +129 -0
  199. package/dist/page-twins.d.ts +13 -0
  200. package/dist/page-twins.js +186 -0
  201. package/dist/pageControlSpecs-DZJ9K37m.js +134 -0
  202. package/dist/pageControlsBridge-0pX9s-3k.js +54 -0
  203. package/dist/pageControlsBridge-DAuT3w7L.d.ts +36 -0
  204. package/dist/panels-PfBBAToE.js +346 -0
  205. package/dist/parts-B7fBcw-B.js +346 -0
  206. package/dist/popover-Dms9Vz3j.js +3389 -0
  207. package/dist/preloadable-lazy-Pp47mqQ9.js +65 -0
  208. package/dist/proactive.d.ts +66 -0
  209. package/dist/proactive.js +237 -0
  210. package/dist/quick-config-panel-DFd77xho.js +451 -0
  211. package/dist/quota-DeA_CJ2e.js +175 -0
  212. package/dist/quota.d.ts +3 -0
  213. package/dist/quota.js +4 -0
  214. package/dist/read-only-context-Dt9N9SIG.js +18 -0
  215. package/dist/relative-time-Dxt8ZIIu.js +55 -0
  216. package/dist/results-CwK_yDxK.js +325 -0
  217. package/dist/rolldown-runtime-hDbaFkMy.js +18 -0
  218. package/dist/route-data.d.ts +12 -0
  219. package/dist/route-data.js +69 -0
  220. package/dist/route-match-C-0_EnAt.d.ts +5 -0
  221. package/dist/route-match-DMkUICYV.js +41 -0
  222. package/dist/route-preload-C4DlGoCd.js +120 -0
  223. package/dist/run-display-UjLAoYqQ.js +81 -0
  224. package/dist/run-history-arGiHzGU.js +285 -0
  225. package/dist/run-list-links-DJn4Mf1T.js +98 -0
  226. package/dist/run-mode-USmM0-Uo.js +82 -0
  227. package/dist/run-parity-CWXqEJqM.js +144 -0
  228. package/dist/runsQuota-B6SyTbne.js +100 -0
  229. package/dist/runsQuota-DsniKiSg.d.ts +20 -0
  230. package/dist/safe-expression-Cw7-SCsm.js +1251 -0
  231. package/dist/save-status-store-C7nEYpfb.js +631 -0
  232. package/dist/schedule-panel-B4GYXzXQ.js +13774 -0
  233. package/dist/schedule-rules-ggVKRkBH.js +358 -0
  234. package/dist/secrets-Re_wSiE3.js +153 -0
  235. package/dist/settings.d.ts +4 -0
  236. package/dist/settings.js +6 -0
  237. package/dist/shared-DAWGGMSM.js +177 -0
  238. package/dist/sidebar-node-editor-6eSSgCzc.js +178 -0
  239. package/dist/solar.generated-CGYuUQAC.js +10 -0
  240. package/dist/stableTabbedDialog-BBhrfXGe.js +20 -0
  241. package/dist/start-url-CT6Yz96K.js +24 -0
  242. package/dist/status-CessxGpm.js +55 -0
  243. package/dist/store-icon-OctYp5zP.js +155 -0
  244. package/dist/styles-WGmTnZ2n.js +26 -0
  245. package/dist/styles.css +139 -0
  246. package/dist/svg-spinners.generated-CIPT7IhM.js +10 -0
  247. package/dist/template-code-CzN6JWNV.js +191 -0
  248. package/dist/template-graph-DLF9dygU.js +20 -0
  249. package/dist/template-preview-DcIIKOOL.js +32 -0
  250. package/dist/template-price-CdUHZRMF.js +40 -0
  251. package/dist/templates.d.ts +3 -0
  252. package/dist/templates.js +5 -0
  253. package/dist/theme-provider-CntfC4_i.js +23 -0
  254. package/dist/transient-DgZfhDfN.js +57 -0
  255. package/dist/typed-calls-C5tO03wq.js +26 -0
  256. package/dist/ui-script-By74Guk3.js +1094 -0
  257. package/dist/ui-script-editor-CqPu2bCN.js +2447 -0
  258. package/dist/ui-step-fix-8uM2_Hft.js +67 -0
  259. package/dist/ui-step-fix-store-CcO1FdRx.js +19 -0
  260. package/dist/ui-step-run-context-o7bLE6KP.js +46 -0
  261. package/dist/ui-target-editor-D2JhB_lD.js +673 -0
  262. package/dist/uiMarkTools-CSznnO1i.js +1054 -0
  263. package/dist/upgradePrompt-BAFBKKW5.js +72 -0
  264. package/dist/use-bare-node-registry-O6mKJO_n.js +11498 -0
  265. package/dist/use-browser-available-hj8wc3Kb.js +241 -0
  266. package/dist/use-edge-mapper-schemas-Bonofxow.js +496 -0
  267. package/dist/use-extension-bridge-B9ZreOkQ.js +608 -0
  268. package/dist/use-mobile-BTqCUjzS.js +27 -0
  269. package/dist/use-sdk-query-C697xZVv.js +116 -0
  270. package/dist/use-workflow-code-editor-CFoRFrZ5.js +753 -0
  271. package/dist/useActionParam-B2tU2BlY.js +85 -0
  272. package/dist/useAgentTokenStream-Bko_J0d0.js +4217 -0
  273. package/dist/useBrowserClients-3v95-gSh.js +103 -0
  274. package/dist/useCodeWorkflowInsights-w0tz9Ap_.js +600 -0
  275. package/dist/useConnections-DsgEJs05.js +439 -0
  276. package/dist/useDebouncedValue-BFekcv6n.js +18 -0
  277. package/dist/useDurableParity-8fnMZmBc.js +1787 -0
  278. package/dist/useEntityTags-D0spL6Ut.js +460 -0
  279. package/dist/useExecutions-2u5nGJJk.js +681 -0
  280. package/dist/useFluidGridsAnalytics-VM8lAi2x.js +238 -0
  281. package/dist/useGlobalStoreClient-BTdhkA2I.js +24 -0
  282. package/dist/useHumanRequests-zlYDp3l1.js +221 -0
  283. package/dist/useNavigationV2-C2WeqN7d.js +29 -0
  284. package/dist/useNavigationV2-DANUmg12.d.ts +9 -0
  285. package/dist/useObservability-BRlQ0tOA.js +285 -0
  286. package/dist/useRequestedProposal-B7uPXfZB.js +51 -0
  287. package/dist/useRunHistory-CXCMUPyf.js +2759 -0
  288. package/dist/useRunLive-D0JvVZT2.js +1060 -0
  289. package/dist/useRunnerList-Dbi59i1K.js +446 -0
  290. package/dist/useRunners-URUc5quU.js +173 -0
  291. package/dist/useRunsPage-DG656UCK.js +2709 -0
  292. package/dist/useVariables-BIelxcWr.js +463 -0
  293. package/dist/useVersionHistoryData-CTjqVw7l.js +292 -0
  294. package/dist/useWorkflowCodeExport-pqxyLHD1.js +522 -0
  295. package/dist/useWorkflowListExport-hcZNvTaB.js +232 -0
  296. package/dist/useWorkflowOrganization-CpBbOrs7.js +1772 -0
  297. package/dist/useWorkflowProposal-BH0VdNMA.js +3280 -0
  298. package/dist/useWorkflows-Cvg-Z_IE.js +1606 -0
  299. package/dist/utils-fvBb5qOD.js +89 -0
  300. package/dist/webhook-deliveries-AvQujaZy.js +99 -0
  301. package/dist/workflow-builder-CJygVkVv.d.ts +2 -0
  302. package/dist/workflow-builder.d.ts +3 -0
  303. package/dist/workflow-builder.js +8 -0
  304. package/dist/workflow-code-transfer-Bsy0JKAZ.js +323 -0
  305. package/dist/workflow-embed.d.ts +3 -0
  306. package/dist/workflow-embed.js +4 -0
  307. package/dist/workflow-git-sync--K9ZsPDC.js +263 -0
  308. package/dist/workflow-host.d.ts +6 -0
  309. package/dist/workflow-host.js +11 -0
  310. package/dist/workflow-pages-D-7ByLTB.d.ts +68 -0
  311. package/dist/workflow-pages.d.ts +3 -0
  312. package/dist/workflow-pages.js +115 -0
  313. package/dist/workflow-preview-canvas-CO8yzdE3.js +848 -0
  314. package/dist/workflow-preview.d.ts +65 -0
  315. package/dist/workflow-preview.js +4 -0
  316. package/dist/workflow-route.d.ts +33 -0
  317. package/dist/workflow-route.js +4 -0
  318. package/dist/workflow-save-state-D0l-DkLf.js +767 -0
  319. package/dist/workflow-transfer-CQnQC-ke.js +104 -0
  320. package/dist/workflowRouteData-BkfVOc-O.js +169 -0
  321. package/dist/workflows-list.d.ts +10 -0
  322. package/dist/workflows-list.js +5 -0
  323. package/package.json +320 -4
@@ -0,0 +1,4477 @@
1
+ "use client";
2
+ import { t as EnsureThemeProvider } from "./EnsureThemeProvider-BvlNjAd0.js";
3
+ import { t as focusDialogOnOpen } from "./stableTabbedDialog-BBhrfXGe.js";
4
+ import { r as useTr } from "./TranslationBridge-Da-TPgQm.js";
5
+ import { n as evaluateSafeExpression, t as SAFE_EXPRESSION_GLOBALS } from "./safe-expression-Cw7-SCsm.js";
6
+ import { ct as commitEdgeMapping, dt as sameMappingValue, ft as toMappingDefinition } from "./use-bare-node-registry-O6mKJO_n.js";
7
+ import { n as useEdgeMapperView, t as nodeDisplayName } from "./use-edge-mapper-schemas-Bonofxow.js";
8
+ import * as React from "react";
9
+ import { createContext, memo, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
10
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
11
+ import "@burdenoff/fe-libs/shared/providers/shell";
12
+ import { Background, Controls, Handle, MiniMap, Panel, Position, ReactFlow, ReactFlowProvider, addEdge, getBezierPath, useEdgesState, useNodesState } from "@xyflow/react";
13
+ import { edgeColor } from "@burdenoff/fe-libs/shared/utils";
14
+ import "@xyflow/react/dist/style.css";
15
+ import { AlertCircle, BookOpen, Braces, CheckCircle2, ChevronDown, ChevronRight, CircleQuestionMark, Code, CodeXml, Hash, List, PlusCircle, Type, WandSparkles, Workflow, X } from "lucide-react";
16
+ import { Badge, Button, Card, CardContent, CardDescription, CardHeader, CardTitle, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, Input, Label, Select, SelectContent, SelectItem, SelectTrigger, SelectValue, SpinnerIcon, TabbedDialog, TabbedDialogContent, TabbedDialogFooter, TabbedDialogHeader, TabbedDialogTabs, Tabs, TabsContent, TabsList, TabsTrigger, Textarea, Toaster, useStableTabbedDialogs } from "@burdenoff/fe-libs/ui";
17
+ import { GraphQLEnumType, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLList, GraphQLNonNull, GraphQLObjectType, GraphQLUnionType, buildSchema } from "graphql";
18
+ import { createPortal } from "react-dom";
19
+
20
+ // src/builder/components/mapper/theme-provider.tsx
21
+ /**
22
+ * The edge mapper's theme. The mapper opens inside the workflow editor, so it
23
+ * uses the theme already around it: the app shell's, or the SDK's own on a
24
+ * page with no provider (see {@link EnsureThemeProvider}).
25
+ *
26
+ * It used to mount a second fe-libs ThemeProvider that defaulted to light.
27
+ * Opening an edge's mapper then rewrote the whole app's theme attributes with
28
+ * that provider's defaults (light unless a mode was saved, and the default
29
+ * brand), and closing it put nothing back (BOFF-14995). The mapper is drawn
30
+ * with semantic tokens only, so it needs no light theme of its own.
31
+ */
32
+ function ThemeProvider$1({ children, storageKey = "vite-ui-theme" }) {
33
+ React.useEffect(() => {
34
+ if (typeof window !== "undefined") try {
35
+ localStorage.removeItem(storageKey);
36
+ } catch (err) {
37
+ console.warn("Failed to clean up legacy theme storage:", err);
38
+ }
39
+ }, [storageKey]);
40
+ return /* @__PURE__ */ jsx(EnsureThemeProvider, { children });
41
+ }
42
+
43
+ // src/builder/components/mapper/config/data.ts
44
+ let parsedSchemas = {};
45
+ let nodeTypes$1 = null;
46
+ let typeCompatibility = null;
47
+ let sampleData = null;
48
+ let nodeStyles = null;
49
+ let currentConfig = null;
50
+ function initializeConfig(schemas, dataConfig) {
51
+ parsedSchemas = schemas;
52
+ currentConfig = dataConfig;
53
+ generateNodeTypes(dataConfig);
54
+ generateTypeCompatibilityFunc(dataConfig);
55
+ generateSampleDataFunc(dataConfig);
56
+ generateVisualStylesFunc(dataConfig);
57
+ }
58
+ function generateNodeTypes(dataConfig) {
59
+ const newNodeTypes = {
60
+ sourceNodes: {},
61
+ targetNodes: {}
62
+ };
63
+ Object.entries(dataConfig.nodes).forEach(([nodeKey, nodeInfo]) => {
64
+ const category = nodeInfo.category;
65
+ if (category === "source" || category === "both") newNodeTypes.sourceNodes[nodeKey] = {
66
+ displayName: nodeInfo.displayName,
67
+ schema: nodeKey,
68
+ inputTypes: [],
69
+ operations: []
70
+ };
71
+ if (category === "target" || category === "both") newNodeTypes.targetNodes[nodeKey] = {
72
+ displayName: nodeInfo.displayName,
73
+ schema: nodeKey,
74
+ inputTypes: [],
75
+ operations: []
76
+ };
77
+ if (!parsedSchemas[nodeKey]) {}
78
+ const schema = parsedSchemas[nodeKey];
79
+ if (schema) {
80
+ const operations = findOperationsWithStateArgs(schema);
81
+ const inputTypes = operations.map((op) => op.stateType).filter((type) => type !== null);
82
+ if (category === "both") {
83
+ newNodeTypes.sourceNodes[nodeKey].inputTypes = [...new Set(inputTypes)];
84
+ newNodeTypes.sourceNodes[nodeKey].operations = operations;
85
+ newNodeTypes.targetNodes[nodeKey].inputTypes = [...new Set(inputTypes)];
86
+ newNodeTypes.targetNodes[nodeKey].operations = operations;
87
+ } else if (category === "source") {
88
+ newNodeTypes.sourceNodes[nodeKey].inputTypes = [...new Set(inputTypes)];
89
+ newNodeTypes.sourceNodes[nodeKey].operations = operations;
90
+ } else if (category === "target") {
91
+ newNodeTypes.targetNodes[nodeKey].inputTypes = [...new Set(inputTypes)];
92
+ newNodeTypes.targetNodes[nodeKey].operations = operations;
93
+ }
94
+ }
95
+ });
96
+ nodeTypes$1 = newNodeTypes;
97
+ }
98
+ function findOperationsWithStateArgs(schema) {
99
+ const operations = [];
100
+ if (schema.queryType) {
101
+ const queryType = schema.types[schema.queryType];
102
+ if (queryType && queryType.fields) for (const fieldName in queryType.fields) {
103
+ const field = queryType.fields[fieldName];
104
+ if (fieldName === "__schema" || fieldName === "__type") continue;
105
+ const stateArg = field.args && field.args.find((arg) => arg.name === "state");
106
+ const contextArg = field.args && field.args.find((arg) => arg.name === "context");
107
+ if (!!stateArg && !!contextArg) operations.push({
108
+ name: fieldName,
109
+ type: "query",
110
+ returnType: field.type,
111
+ stateType: stateArg.type,
112
+ inputType: stateArg.type
113
+ });
114
+ else if (field.args && field.args.length > 0) {
115
+ const firstArg = field.args[0];
116
+ operations.push({
117
+ name: fieldName,
118
+ type: "query",
119
+ returnType: field.type,
120
+ stateType: firstArg.type,
121
+ inputType: firstArg.type
122
+ });
123
+ } else operations.push({
124
+ name: fieldName,
125
+ type: "query",
126
+ returnType: field.type,
127
+ stateType: null,
128
+ inputType: null
129
+ });
130
+ }
131
+ else console.warn(`Query type ${schema.queryType} not found or has no fields`);
132
+ }
133
+ if (schema.mutationType) {
134
+ const mutationType = schema.types[schema.mutationType];
135
+ if (mutationType && mutationType.fields) for (const fieldName in mutationType.fields) {
136
+ const field = mutationType.fields[fieldName];
137
+ const stateArg = field.args && field.args.find((arg) => arg.name === "state");
138
+ const contextArg = field.args && field.args.find((arg) => arg.name === "context");
139
+ if (!!stateArg && !!contextArg) operations.push({
140
+ name: fieldName,
141
+ type: "mutation",
142
+ returnType: field.type,
143
+ stateType: stateArg.type,
144
+ inputType: stateArg.type
145
+ });
146
+ else if (field.args && field.args.length > 0) {
147
+ const firstArg = field.args[0];
148
+ operations.push({
149
+ name: fieldName,
150
+ type: "mutation",
151
+ returnType: field.type,
152
+ stateType: firstArg.type,
153
+ inputType: firstArg.type
154
+ });
155
+ } else operations.push({
156
+ name: fieldName,
157
+ type: "mutation",
158
+ returnType: field.type,
159
+ stateType: null,
160
+ inputType: null
161
+ });
162
+ }
163
+ else console.warn(`Mutation type ${schema.mutationType} not found or has no fields`);
164
+ }
165
+ return operations;
166
+ }
167
+ function generateTypeCompatibilityFunc(dataConfig) {
168
+ typeCompatibility = dataConfig.typeCompatibility;
169
+ }
170
+ function generateSampleDataFunc(dataConfig) {
171
+ sampleData = dataConfig.sampleData;
172
+ }
173
+ function generateVisualStylesFunc(dataConfig) {
174
+ const newNodeStyles = {};
175
+ Object.entries(dataConfig.nodes).forEach(([nodeKey, nodeInfo]) => {
176
+ newNodeStyles[nodeKey] = nodeInfo.style || {};
177
+ });
178
+ nodeStyles = newNodeStyles;
179
+ }
180
+ function getEdgeColor(mappingType, compatible = true) {
181
+ const colorConfig = currentConfig?.mappingTypes[mappingType]?.color;
182
+ if (!colorConfig) return null;
183
+ return typeof colorConfig === "string" ? colorConfig : compatible ? colorConfig.compatible : colorConfig.incompatible;
184
+ }
185
+ function getReturnTypeForOperation(nodeType, operationName) {
186
+ return ((nodeTypes$1?.targetNodes[nodeType] || nodeTypes$1?.sourceNodes[nodeType])?.operations?.find((op) => op.name === operationName))?.returnType;
187
+ }
188
+ function getNodeStyle(nodeType, side) {
189
+ if (!nodeStyles || !nodeStyles[nodeType]) return "";
190
+ const styles = nodeStyles[nodeType];
191
+ if (side) return (side === "source" ? styles.source : styles.target) || "";
192
+ return styles;
193
+ }
194
+ function getInputTypeForOperation(nodeType, operationName) {
195
+ return ((nodeTypes$1?.targetNodes[nodeType] || nodeTypes$1?.sourceNodes[nodeType])?.operations?.find((op) => op.name === operationName))?.inputType;
196
+ }
197
+ function getTypeCompatibility() {
198
+ return typeCompatibility || {};
199
+ }
200
+
201
+ // src/builder/components/lib/type-utils.ts
202
+ function areTypesCompatible(sourceType, targetType) {
203
+ const cleanSourceType = sourceType.replace(/!$/, "").replace(/^\[/, "").replace(/\]!?$/, "");
204
+ const cleanTargetType = targetType.replace(/!$/, "").replace(/\]!?$/, "");
205
+ if (cleanSourceType === cleanTargetType) return true;
206
+ return getTypeCompatibility()[cleanSourceType]?.includes(cleanTargetType) || false;
207
+ }
208
+ function getReadableTypeName(type) {
209
+ const isNonNull = type.endsWith("!");
210
+ const isList = type.includes("[");
211
+ let result = type.replace(/!$/, "").replace(/^\[/, "").replace(/\]!?$/, "");
212
+ if (isList) result = `Array of ${result}`;
213
+ if (isNonNull) result = `${result} (Required)`;
214
+ return result;
215
+ }
216
+
217
+ // src/builder/components/mapper/schema-node.tsx
218
+ const SchemaNode = memo(({ data, isConnectable }) => {
219
+ const { label, type, side, isRequired, isNested, isArray, nodeType, category } = data;
220
+ const readableType = getReadableTypeName(type);
221
+ const borderColor = getNodeStyle(nodeType || "", side);
222
+ const bgColor = side === "source" ? "bg-surface hover:bg-[var(--color-bg-accent)]/10 transition-colors duration-200" : "bg-surface hover:bg-[var(--color-status-success-bg-subtle)] transition-colors duration-200";
223
+ const categoryColor = getCategoryColor(category);
224
+ return /* @__PURE__ */ jsxs(Card, {
225
+ className: `w-56 shadow-sm ${borderColor} ${bgColor} transition-colors duration-200`,
226
+ children: [
227
+ /* @__PURE__ */ jsxs("div", {
228
+ className: `flex items-center px-2 py-1 border-b ${categoryColor}`,
229
+ children: [/* @__PURE__ */ jsx("div", {
230
+ className: "flex-1 font-medium text-xs truncate",
231
+ title: label,
232
+ children: label
233
+ }), /* @__PURE__ */ jsxs("div", {
234
+ className: "flex gap-1 flex-shrink-0",
235
+ children: [
236
+ isRequired && /* @__PURE__ */ jsx(Badge, {
237
+ variant: "destructive",
238
+ className: "text-[10px] px-1 py-0",
239
+ children: "Req"
240
+ }),
241
+ isArray && /* @__PURE__ */ jsx(Badge, {
242
+ variant: "secondary",
243
+ className: "text-[10px] px-1 py-0",
244
+ children: "Array"
245
+ }),
246
+ isNested && /* @__PURE__ */ jsx(Badge, {
247
+ variant: "outline",
248
+ className: "text-[10px] px-1 py-0",
249
+ children: "Obj"
250
+ })
251
+ ]
252
+ })]
253
+ }),
254
+ /* @__PURE__ */ jsx(CardContent, {
255
+ className: "p-1 text-[10px] text-muted-foreground",
256
+ children: /* @__PURE__ */ jsxs("div", {
257
+ className: "flex justify-between items-center",
258
+ children: [/* @__PURE__ */ jsx("span", {
259
+ title: readableType,
260
+ children: readableType
261
+ }), category && /* @__PURE__ */ jsx(Badge, {
262
+ variant: "outline",
263
+ className: "text-[10px] px-1 py-0",
264
+ style: { backgroundColor: getCategoryBgColor(category) },
265
+ children: category
266
+ })]
267
+ })
268
+ }),
269
+ side === "source" ? /* @__PURE__ */ jsx(Handle, {
270
+ type: "source",
271
+ position: Position.Right,
272
+ isConnectable,
273
+ className: "w-2 h-2 bg-accent transition-transform hover:scale-125"
274
+ }) : /* @__PURE__ */ jsx(Handle, {
275
+ type: "target",
276
+ position: Position.Left,
277
+ isConnectable,
278
+ className: "w-2 h-2 bg-[var(--color-status-success-bg)] transition-transform hover:scale-125"
279
+ })
280
+ ]
281
+ });
282
+ });
283
+ function getCategoryColor(category) {
284
+ if (!category) return "";
285
+ switch (category.toLowerCase()) {
286
+ case "input": return "border-[var(--color-border-accent)]/50 bg-[var(--color-bg-accent)]/10";
287
+ case "metadata": return "border-[var(--color-status-warning-border)]/50 bg-[var(--color-status-warning-bg-subtle)]";
288
+ case "context": return "border-[var(--color-status-success-border)]/50 bg-[var(--color-status-success-bg-subtle)]";
289
+ case "output": return "border-[var(--color-border-accent)]/30 bg-[var(--color-bg-accent)]/5";
290
+ case "config": return "border-[var(--color-status-error-border)]/50 bg-[var(--color-status-error-bg-subtle)]";
291
+ default: return "border-border-default";
292
+ }
293
+ }
294
+ /** Translucent category tint for the field badge (semantic tokens, light + dark). */
295
+ function getCategoryBgColor(category) {
296
+ switch (category.toLowerCase()) {
297
+ case "input": return "var(--color-node-integration-subtle)";
298
+ case "metadata": return "var(--color-status-warning-bgSubtle)";
299
+ case "context": return "var(--color-status-success-bgSubtle)";
300
+ case "output": return "var(--color-status-info-bgSubtle)";
301
+ case "config": return "var(--color-status-error-bgSubtle)";
302
+ default: return "var(--color-bg-sunken)";
303
+ }
304
+ }
305
+ SchemaNode.displayName = "SchemaNode";
306
+
307
+ // src/builder/components/mapper/config/mapping-colors.ts
308
+ /**
309
+ * Colours for mapper edges and mapping-type chips (G19).
310
+ *
311
+ * Every value is a semantic token (a CSS `var()` reference to a `--color-`
312
+ * custom property) from fe-libs: the compatible / incompatible pair uses the
313
+ * canvas edge tokens and each mapping type gets a fixed categorical chart
314
+ * colour series, so the mapper follows light / dark mode, the brand and the
315
+ * high-contrast theme. These literal CSS-variable strings work in React Flow
316
+ * edge styles, SVG `style` props and inline styles.
317
+ *
318
+ * NOTE: never write syntactically class-like placeholders (ellipsis or
319
+ * wildcard arbitrary-value examples such as bracketed var references) in this
320
+ * file's docs — Tailwind v4 extracts candidates from published package
321
+ * content, and placeholder prose becomes invalid generated CSS in every
322
+ * consuming app (BOFF-6688 / BOFF-6718).
323
+ */
324
+ const MAPPING_COMPATIBILITY_COLORS = {
325
+ compatible: edgeColor("compatible"),
326
+ incompatible: edgeColor("incompatible")
327
+ };
328
+ const MAPPING_TYPE_COLORS = {
329
+ direct: MAPPING_COMPATIBILITY_COLORS.compatible,
330
+ expression: "var(--color-chart-3)",
331
+ transform: "var(--color-chart-10)",
332
+ cast: "var(--color-chart-2)",
333
+ array: "var(--color-chart-4)",
334
+ object: "var(--color-chart-12)",
335
+ context: "var(--color-chart-11)"
336
+ };
337
+ /** Colour for a mapping type that is unknown or has no colour configured. */
338
+ const MAPPING_FALLBACK_COLOR = edgeColor("default");
339
+ function isMappingTypeKey(value) {
340
+ return Object.prototype.hasOwnProperty.call(MAPPING_TYPE_COLORS, value);
341
+ }
342
+ /** The token colour of a mapping type; unknown types get the default edge colour. */
343
+ function mappingTypeColor(mappingType) {
344
+ return isMappingTypeKey(mappingType) ? MAPPING_TYPE_COLORS[mappingType] : MAPPING_FALLBACK_COLOR;
345
+ }
346
+ /** Edge colour for a direct mapping, by whether the two field types are compatible. */
347
+ function compatibilityColor(isCompatible) {
348
+ return isCompatible ? MAPPING_COMPATIBILITY_COLORS.compatible : MAPPING_COMPATIBILITY_COLORS.incompatible;
349
+ }
350
+
351
+ // src/builder/components/mapper/mapping-edge.tsx
352
+ const MappingEdge = memo(({ id, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, data, style = {}, markerEnd }) => {
353
+ const [edgePath, labelX, labelY] = getBezierPath({
354
+ sourceX,
355
+ sourceY,
356
+ sourcePosition,
357
+ targetX,
358
+ targetY,
359
+ targetPosition
360
+ });
361
+ const mappingType = data?.mappingType || "direct";
362
+ const isCompatible = data?.isCompatible !== false;
363
+ let mappingLabel = "";
364
+ const mappingColor = getEdgeColor(mappingType, isCompatible) || MAPPING_FALLBACK_COLOR;
365
+ switch (mappingType) {
366
+ case "direct":
367
+ mappingLabel = "Direct";
368
+ break;
369
+ case "expression":
370
+ mappingLabel = "Expression";
371
+ break;
372
+ case "transform":
373
+ mappingLabel = data?.mappingData?.function ? `Transform: ${data.mappingData.function}` : "Transform";
374
+ break;
375
+ case "loop":
376
+ mappingLabel = "Loop";
377
+ break;
378
+ case "cast": mappingLabel = data?.mappingData?.type ? `Cast: ${data.mappingData.type}` : "Cast";
379
+ }
380
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("path", {
381
+ id,
382
+ style: {
383
+ ...style,
384
+ stroke: mappingColor,
385
+ strokeWidth: 2
386
+ },
387
+ className: "react-flow__edge-path",
388
+ d: edgePath,
389
+ markerEnd
390
+ }), /* @__PURE__ */ jsx("foreignObject", {
391
+ width: 120,
392
+ height: 40,
393
+ x: labelX - 60,
394
+ y: labelY - 20,
395
+ className: "overflow-visible",
396
+ children: /* @__PURE__ */ jsx("div", {
397
+ className: "flex items-center justify-center bg-surface border border-border-default rounded-md shadow-sm px-2 py-1",
398
+ children: /* @__PURE__ */ jsxs("span", {
399
+ className: "text-xs font-medium",
400
+ style: { color: mappingColor },
401
+ children: [mappingLabel, !isCompatible && mappingType === "direct" && " ⚠️"]
402
+ })
403
+ })
404
+ })] });
405
+ });
406
+ MappingEdge.displayName = "MappingEdge";
407
+
408
+ // src/builder/components/mapper/node-group.tsx
409
+ const NodeGroup = memo(({ data, children }) => {
410
+ const { label, nodeType, side } = data;
411
+ const bgColor = side === "source" ? "bg-[var(--color-bg-accent)]/10" : "bg-[var(--color-status-success-bg-subtle)]";
412
+ const borderColor = side === "source" ? "border-[var(--color-border-accent)]" : "border-[var(--color-status-success-border)]";
413
+ const textColor = side === "source" ? "text-accent" : "text-[var(--color-status-success-text)]";
414
+ return /* @__PURE__ */ jsxs("div", {
415
+ className: `px-4 pt-12 pb-4 rounded-lg border-2 ${borderColor} ${bgColor} min-w-[400px] min-h-[600px] shadow-md relative overflow-visible bg-gradient-to-b ${side === "source" ? "from-[var(--color-bg-accent)]/20 to-transparent" : "from-[var(--color-status-success-bg-subtle)]/50 to-transparent"}`,
416
+ style: { minHeight: "600px" },
417
+ children: [/* @__PURE__ */ jsx("div", {
418
+ className: `absolute top-0 left-0 right-0 ${textColor} font-semibold p-2 border-b ${borderColor} text-center bg-surface/70 backdrop-blur-sm rounded-t-lg flex items-center justify-center`,
419
+ children: /* @__PURE__ */ jsxs("div", {
420
+ className: "text-sm",
421
+ children: [
422
+ label,
423
+ " ",
424
+ /* @__PURE__ */ jsxs("span", {
425
+ className: "text-xs opacity-75",
426
+ children: [
427
+ "(",
428
+ nodeType,
429
+ ")"
430
+ ]
431
+ })
432
+ ]
433
+ })
434
+ }), /* @__PURE__ */ jsx("div", {
435
+ className: "relative w-full h-full overflow-visible",
436
+ children
437
+ })]
438
+ });
439
+ });
440
+ NodeGroup.displayName = "NodeGroup";
441
+
442
+ // src/builder/components/lib/node-generator.ts
443
+ /**
444
+ * Find the return type for an operation directly from the schema
445
+ */
446
+ function findReturnTypeFromSchema(schema, operationName) {
447
+ if (schema.queryType && schema.types[schema.queryType]?.fields[operationName]) return schema.types[schema.queryType].fields[operationName].type;
448
+ if (schema.mutationType && schema.types[schema.mutationType]?.fields[operationName]) return schema.types[schema.mutationType].fields[operationName].type;
449
+ return null;
450
+ }
451
+ function findInputTypeFromSchema(schema, operationName) {
452
+ let field = null;
453
+ if (schema.queryType && schema.types[schema.queryType]?.fields[operationName]) field = schema.types[schema.queryType].fields[operationName];
454
+ if (!field && schema.mutationType && schema.types[schema.mutationType]?.fields[operationName]) field = schema.types[schema.mutationType].fields[operationName];
455
+ if (!field) return {
456
+ typeName: null,
457
+ useArgsDirectly: false,
458
+ field: null
459
+ };
460
+ const stateArg = field.args?.find((a) => a.name === "state" || a.name === "input");
461
+ if (stateArg) {
462
+ const inputType = schema.types[stateArg.type];
463
+ if (inputType && (inputType.inputFields || inputType.fields)) return {
464
+ typeName: stateArg.type,
465
+ useArgsDirectly: false,
466
+ field
467
+ };
468
+ }
469
+ if (field.args && field.args.length > 0) {
470
+ const firstArg = field.args[0];
471
+ const firstArgType = schema.types[firstArg.type];
472
+ if (firstArgType && firstArgType.kind === "input" && (firstArgType.inputFields || firstArgType.fields)) return {
473
+ typeName: firstArg.type,
474
+ useArgsDirectly: false,
475
+ field
476
+ };
477
+ }
478
+ if (field.args && field.args.length > 0) return {
479
+ typeName: null,
480
+ useArgsDirectly: true,
481
+ field
482
+ };
483
+ return {
484
+ typeName: null,
485
+ useArgsDirectly: false,
486
+ field: null
487
+ };
488
+ }
489
+ /**
490
+ * Generate schema nodes for visual mapping
491
+ */
492
+ function generateSchemaNodes(sourceSchema, sourceNode, sourceOperation, targetSchema, targetNode, targetOperation) {
493
+ const nodes = [];
494
+ const edges = [];
495
+ if (targetSchema?.mutationType && targetSchema?.types[targetSchema.mutationType]) {
496
+ const mutationField = targetSchema.types[targetSchema.mutationType].fields?.[targetOperation];
497
+ if (mutationField?.args) {
498
+ for (const arg of mutationField.args) if (targetSchema.types[arg.type]?.inputFields) {}
499
+ }
500
+ }
501
+ let sourceOutputType = null;
502
+ const sourceReturnTypeName = findReturnTypeFromSchema(sourceSchema, sourceOperation);
503
+ if (sourceReturnTypeName) sourceOutputType = sourceSchema.types[sourceReturnTypeName];
504
+ if (!sourceOutputType) for (const typeName of Object.keys(sourceSchema.types)) {
505
+ const type = sourceSchema.types[typeName];
506
+ if (type.kind === "type" && type.fields && Object.keys(type.fields).length > 0) {
507
+ if (typeName === sourceSchema.queryType || typeName === sourceSchema.mutationType || typeName === sourceSchema.subscriptionType) continue;
508
+ sourceOutputType = type;
509
+ break;
510
+ }
511
+ }
512
+ let targetInputType = null;
513
+ let useArgsDirectlyForTarget = false;
514
+ let targetOperationField = null;
515
+ const targetInputResult = findInputTypeFromSchema(targetSchema, targetOperation);
516
+ if (targetInputResult.typeName) targetInputType = targetSchema.types[targetInputResult.typeName];
517
+ else if (targetInputResult.useArgsDirectly && targetInputResult.field) {
518
+ useArgsDirectlyForTarget = true;
519
+ targetOperationField = targetInputResult.field;
520
+ }
521
+ if (!targetInputType && !useArgsDirectlyForTarget) for (const typeName of Object.keys(targetSchema.types)) {
522
+ const type = targetSchema.types[typeName];
523
+ if (type.kind === "input" && (type.inputFields || type.fields)) {
524
+ targetInputType = type;
525
+ break;
526
+ }
527
+ }
528
+ const sourceGroupNode = {
529
+ id: "source-group",
530
+ type: "nodeGroup",
531
+ position: {
532
+ x: 50,
533
+ y: 50
534
+ },
535
+ style: {
536
+ width: 450,
537
+ height: 800
538
+ },
539
+ data: {
540
+ label: `Source: ${sourceOperation}`,
541
+ nodeType: sourceNode,
542
+ side: "source"
543
+ }
544
+ };
545
+ const targetGroupNode = {
546
+ id: "target-group",
547
+ type: "nodeGroup",
548
+ position: {
549
+ x: 650,
550
+ y: 50
551
+ },
552
+ style: {
553
+ width: 450,
554
+ height: 800
555
+ },
556
+ data: {
557
+ label: `Target: ${targetOperation}`,
558
+ nodeType: targetNode,
559
+ side: "target"
560
+ }
561
+ };
562
+ nodes.push(sourceGroupNode, targetGroupNode);
563
+ const yPos = 70;
564
+ const sourceFields = sourceOutputType?.fields || {};
565
+ if (Object.keys(sourceFields).length === 0) {
566
+ console.warn("No source fields found for", sourceNode, sourceOperation);
567
+ nodes.push({
568
+ id: `source-placeholder`,
569
+ position: {
570
+ x: 100,
571
+ y: 70
572
+ },
573
+ data: {
574
+ label: "No fields available",
575
+ type: "String",
576
+ path: "placeholder",
577
+ side: "source",
578
+ isRequired: false,
579
+ isNested: false,
580
+ isArray: false,
581
+ nodeType: sourceNode
582
+ },
583
+ type: "schemaNode",
584
+ parentId: "source-group",
585
+ extent: "parent"
586
+ });
587
+ }
588
+ const generateFieldNodes = (fields, parentPath = "", xPos, startYPos, side, parentNodeType, schema) => {
589
+ let currentYPos = startYPos;
590
+ const generatedNodes = [];
591
+ const xOffset = 100;
592
+ const categorizedFields = {
593
+ input: {},
594
+ metadata: {},
595
+ context: {},
596
+ output: {},
597
+ config: {},
598
+ other: {}
599
+ };
600
+ for (const fieldName in fields) {
601
+ const field = fields[fieldName];
602
+ if (fieldName.toLowerCase().includes("input") || fieldName.toLowerCase().includes("request")) categorizedFields.input[fieldName] = field;
603
+ else if (fieldName.toLowerCase().includes("metadata") || fieldName.toLowerCase().includes("meta")) categorizedFields.metadata[fieldName] = field;
604
+ else if (fieldName.toLowerCase().includes("context") || fieldName.toLowerCase().includes("ctx")) categorizedFields.context[fieldName] = field;
605
+ else if (fieldName.toLowerCase().includes("output") || fieldName.toLowerCase().includes("response") || fieldName.toLowerCase().includes("result")) categorizedFields.output[fieldName] = field;
606
+ else if (fieldName.toLowerCase().includes("config") || fieldName.toLowerCase().includes("setting") || fieldName.toLowerCase().includes("option")) categorizedFields.config[fieldName] = field;
607
+ else categorizedFields.other[fieldName] = field;
608
+ }
609
+ const categories = Object.keys(categorizedFields);
610
+ for (const category of categories) {
611
+ const categoryFields = categorizedFields[category];
612
+ if (Object.keys(categoryFields).length === 0) continue;
613
+ if (generatedNodes.length > 0) currentYPos += 20;
614
+ for (const fieldName in categoryFields) {
615
+ const field = categoryFields[fieldName];
616
+ const fullPath = parentPath ? `${parentPath}.${fieldName}` : fieldName;
617
+ const node = {
618
+ id: `${side}-${fullPath}`,
619
+ position: {
620
+ x: xOffset,
621
+ y: currentYPos
622
+ },
623
+ data: {
624
+ label: fieldName,
625
+ type: field.type,
626
+ path: fullPath,
627
+ side,
628
+ isRequired: field.isNonNull,
629
+ isNested: isComplexType(schema, field.type),
630
+ isArray: field.isList,
631
+ nodeType: parentNodeType,
632
+ category: category !== "other" ? category : void 0
633
+ },
634
+ type: "schemaNode",
635
+ parentId: side === "source" ? "source-group" : "target-group",
636
+ extent: "parent"
637
+ };
638
+ generatedNodes.push(node);
639
+ currentYPos += 70;
640
+ if (isComplexType(schema, field.type) && schema.types[field.type]) {
641
+ const nestedFields = schema.types[field.type].fields || {};
642
+ if (Object.keys(nestedFields).length > 0) {
643
+ const nestedNodes = generateFieldNodes(nestedFields, fullPath, xPos + (side === "source" ? 150 : -150), currentYPos - 20, side, parentNodeType, schema);
644
+ generatedNodes.push(...nestedNodes);
645
+ currentYPos += nestedNodes.length * 60 + 30;
646
+ }
647
+ }
648
+ }
649
+ }
650
+ return generatedNodes;
651
+ };
652
+ const sourceNodes = generateFieldNodes(sourceFields, "", 100, yPos, "source", sourceNode, sourceSchema);
653
+ nodes.push(...sourceNodes);
654
+ const targetFields = {};
655
+ if (useArgsDirectlyForTarget && targetOperationField?.args) for (const arg of targetOperationField.args) targetFields[arg.name] = {
656
+ name: arg.name,
657
+ type: arg.type,
658
+ isNonNull: arg.isNonNull || false,
659
+ isList: arg.isList || false,
660
+ args: []
661
+ };
662
+ else if (targetInputType) {
663
+ const inputFieldsSource = targetInputType.inputFields || targetInputType.fields || {};
664
+ for (const fieldName of Object.keys(inputFieldsSource)) {
665
+ const field = inputFieldsSource[fieldName];
666
+ targetFields[fieldName] = {
667
+ name: field.name,
668
+ type: field.type,
669
+ isNonNull: field.isNonNull,
670
+ isList: field.isList,
671
+ args: field.args || []
672
+ };
673
+ }
674
+ }
675
+ if (Object.keys(targetFields).length === 0) {
676
+ const processOperationArgs = (operationField) => {
677
+ if (!operationField?.args || operationField.args.length === 0) return false;
678
+ const inputArg = operationField.args.find((a) => a.name === "input" || a.name === "state");
679
+ if (inputArg) {
680
+ const inputType = targetSchema.types[inputArg.type];
681
+ if (inputType && inputType.kind === "input" && inputType.inputFields) {
682
+ for (const fieldName of Object.keys(inputType.inputFields)) {
683
+ const field = inputType.inputFields[fieldName];
684
+ targetFields[fieldName] = {
685
+ name: field.name || fieldName,
686
+ type: field.type,
687
+ isNonNull: field.isNonNull || false,
688
+ isList: field.isList || false,
689
+ args: []
690
+ };
691
+ }
692
+ return true;
693
+ }
694
+ }
695
+ if (operationField.args.length > 0) {
696
+ const firstArg = operationField.args[0];
697
+ const firstArgType = targetSchema.types[firstArg.type];
698
+ if (firstArgType && firstArgType.kind === "input" && firstArgType.inputFields) {
699
+ for (const fieldName of Object.keys(firstArgType.inputFields)) {
700
+ const field = firstArgType.inputFields[fieldName];
701
+ targetFields[fieldName] = {
702
+ name: field.name || fieldName,
703
+ type: field.type,
704
+ isNonNull: field.isNonNull || false,
705
+ isList: field.isList || false,
706
+ args: []
707
+ };
708
+ }
709
+ return true;
710
+ }
711
+ }
712
+ for (const arg of operationField.args) targetFields[arg.name] = {
713
+ name: arg.name,
714
+ type: arg.type,
715
+ isNonNull: arg.isNonNull || false,
716
+ isList: arg.isList || false,
717
+ args: []
718
+ };
719
+ return true;
720
+ };
721
+ if (targetSchema.mutationType && targetSchema.types[targetSchema.mutationType]) {
722
+ const mutationField = targetSchema.types[targetSchema.mutationType].fields?.[targetOperation];
723
+ if (mutationField) processOperationArgs(mutationField);
724
+ }
725
+ if (Object.keys(targetFields).length === 0 && targetSchema.queryType && targetSchema.types[targetSchema.queryType]) {
726
+ const queryField = targetSchema.types[targetSchema.queryType].fields?.[targetOperation];
727
+ if (queryField) processOperationArgs(queryField);
728
+ }
729
+ }
730
+ if (Object.keys(targetFields).length === 0) {
731
+ console.warn("No target fields found for", targetNode, targetOperation);
732
+ nodes.push({
733
+ id: `target-placeholder`,
734
+ position: {
735
+ x: 100,
736
+ y: 70
737
+ },
738
+ data: {
739
+ label: "No fields available",
740
+ type: "String",
741
+ path: "placeholder",
742
+ side: "target",
743
+ isRequired: false,
744
+ isNested: false,
745
+ isArray: false,
746
+ nodeType: targetNode
747
+ },
748
+ type: "schemaNode",
749
+ parentId: "target-group",
750
+ extent: "parent"
751
+ });
752
+ }
753
+ const targetNodes = generateFieldNodes(targetFields, "", 100, yPos, "target", targetNode, targetSchema);
754
+ nodes.push(...targetNodes);
755
+ if (sourceNodes.length > 0) {
756
+ const maxSourceY = Math.max(...sourceNodes.map((node) => {
757
+ return node.position.y;
758
+ })) + 150;
759
+ if (sourceGroupNode.style) sourceGroupNode.style.height = Math.max(maxSourceY, 600);
760
+ const maxSourceX = Math.max(...sourceNodes.map((node) => node.position.x + 300));
761
+ if (sourceGroupNode.style) sourceGroupNode.style.width = Math.max(maxSourceX, 400);
762
+ }
763
+ if (targetNodes.length > 0) {
764
+ const maxTargetY = Math.max(...targetNodes.map((node) => {
765
+ return node.position.y;
766
+ })) + 150;
767
+ if (targetGroupNode.style) targetGroupNode.style.height = Math.max(maxTargetY, 600);
768
+ const maxTargetX = Math.max(...targetNodes.map((node) => node.position.x + 300));
769
+ if (targetGroupNode.style) targetGroupNode.style.width = Math.max(maxTargetX, 400);
770
+ }
771
+ return {
772
+ nodes,
773
+ edges
774
+ };
775
+ }
776
+ function isComplexType(schema, typeName) {
777
+ const type = schema.types[typeName];
778
+ if (!type) return false;
779
+ return type.kind === "type" || type.kind === "input";
780
+ }
781
+
782
+ // src/builder/components/hooks/use-toast.ts
783
+ const TOAST_LIMIT = 5;
784
+ const TOAST_REMOVE_DELAY = 1e6;
785
+ const actionTypes = {
786
+ ADD_TOAST: "ADD_TOAST",
787
+ UPDATE_TOAST: "UPDATE_TOAST",
788
+ DISMISS_TOAST: "DISMISS_TOAST",
789
+ REMOVE_TOAST: "REMOVE_TOAST"
790
+ };
791
+ let count = 0;
792
+ function genId() {
793
+ count = (count + 1) % Number.MAX_VALUE;
794
+ return count.toString();
795
+ }
796
+ const toastTimeouts = /* @__PURE__ */ new Map();
797
+ const reducer = (state, action) => {
798
+ switch (action.type) {
799
+ case actionTypes.ADD_TOAST: return {
800
+ ...state,
801
+ toasts: [action.toast, ...state.toasts].slice(0, TOAST_LIMIT)
802
+ };
803
+ case actionTypes.UPDATE_TOAST: return {
804
+ ...state,
805
+ toasts: state.toasts.map((t) => t.id === action.toast.id ? {
806
+ ...t,
807
+ ...action.toast
808
+ } : t)
809
+ };
810
+ case actionTypes.DISMISS_TOAST: {
811
+ const { toastId } = action;
812
+ if (toastId) addToRemoveQueue(toastId);
813
+ else state.toasts.forEach((toast) => {
814
+ addToRemoveQueue(toast.id);
815
+ });
816
+ return {
817
+ ...state,
818
+ toasts: state.toasts.map((t) => t.id === toastId || toastId === void 0 ? {
819
+ ...t,
820
+ open: false
821
+ } : t)
822
+ };
823
+ }
824
+ case actionTypes.REMOVE_TOAST:
825
+ if (action.toastId === void 0) return {
826
+ ...state,
827
+ toasts: []
828
+ };
829
+ return {
830
+ ...state,
831
+ toasts: state.toasts.filter((t) => t.id !== action.toastId)
832
+ };
833
+ }
834
+ };
835
+ const listeners = [];
836
+ let memoryState = { toasts: [] };
837
+ function dispatch(action) {
838
+ memoryState = reducer(memoryState, action);
839
+ listeners.forEach((listener) => {
840
+ listener(memoryState);
841
+ });
842
+ }
843
+ function toast({ ...props }) {
844
+ const id = genId();
845
+ const update = (props) => dispatch({
846
+ type: actionTypes.UPDATE_TOAST,
847
+ toast: {
848
+ ...props,
849
+ id
850
+ }
851
+ });
852
+ const dismiss = () => dispatch({
853
+ type: actionTypes.DISMISS_TOAST,
854
+ toastId: id
855
+ });
856
+ dispatch({
857
+ type: actionTypes.ADD_TOAST,
858
+ toast: {
859
+ ...props,
860
+ id,
861
+ open: true,
862
+ onOpenChange: (open) => {
863
+ if (!open) dismiss();
864
+ }
865
+ }
866
+ });
867
+ return {
868
+ id,
869
+ dismiss,
870
+ update
871
+ };
872
+ }
873
+ function useToast() {
874
+ const [state, setState] = React.useState(memoryState);
875
+ React.useEffect(() => {
876
+ listeners.push(setState);
877
+ return () => {
878
+ const index = listeners.indexOf(setState);
879
+ if (index > -1) listeners.splice(index, 1);
880
+ };
881
+ }, [state]);
882
+ return {
883
+ ...state,
884
+ toast,
885
+ dismiss: (toastId) => dispatch({
886
+ type: actionTypes.DISMISS_TOAST,
887
+ toastId
888
+ })
889
+ };
890
+ }
891
+ function addToRemoveQueue(toastId) {
892
+ if (toastTimeouts.has(toastId)) return;
893
+ const timeout = setTimeout(() => {
894
+ toastTimeouts.delete(toastId);
895
+ dispatch({
896
+ type: actionTypes.REMOVE_TOAST,
897
+ toastId
898
+ });
899
+ }, TOAST_REMOVE_DELAY);
900
+ toastTimeouts.set(toastId, timeout);
901
+ }
902
+
903
+ // src/builder/components/mapper/config/data-config-context.tsx
904
+ const DataConfigContext = createContext(null);
905
+ function DataConfigProvider({ children, config }) {
906
+ return /* @__PURE__ */ jsx(DataConfigContext.Provider, {
907
+ value: config,
908
+ children
909
+ });
910
+ }
911
+ function useDataConfig() {
912
+ const context = useContext(DataConfigContext);
913
+ if (!context) {
914
+ console.warn("useDataConfig: No DataConfigProvider found, using empty config");
915
+ return {
916
+ nodes: {},
917
+ mappingTypes: {},
918
+ typeCompatibility: {},
919
+ sampleData: {}
920
+ };
921
+ }
922
+ return context;
923
+ }
924
+
925
+ // src/builder/components/mapper/mapping-dialog.tsx
926
+ function MappingDialog(props) {
927
+ if (!props.open) return null;
928
+ const dialogKey = `${props.mappingType}-${props.sourceField || ""}-${props.targetField || ""}`;
929
+ return /* @__PURE__ */ jsx(MappingDialogContent, { ...props }, dialogKey);
930
+ }
931
+ function MappingDialogContent({ open, onOpenChange, onSave, mappingType, sourceField, targetField, sourceSchema, sourceOperation, targetSchema, targetOperation }) {
932
+ const [expression, setExpression] = useState(() => sourceField ? `\${output.${sourceField}}` : "");
933
+ const [selectedExample, setSelectedExample] = useState("");
934
+ const [activeTab, setActiveTab] = useState(() => mappingType === "array" || mappingType === "object" ? "builder" : "examples");
935
+ const [targetFieldName, setTargetFieldName] = useState(() => targetField || "");
936
+ const [selectedSourceArray, setSelectedSourceArray] = useState("");
937
+ const [itemExpression, setItemExpression] = useState("");
938
+ const dataConfig = useDataConfig();
939
+ const tr = useTr();
940
+ const stable = useStableTabbedDialogs();
941
+ const sourceFields = useMemo(() => {
942
+ if (!sourceSchema) return [];
943
+ const fields = [];
944
+ const extractFields = (typeName, parentPath = "", depth = 0) => {
945
+ if (depth > 3) return [];
946
+ const typeInfo = sourceSchema.types[typeName];
947
+ if (!typeInfo || !typeInfo.fields) return [];
948
+ const result = [];
949
+ for (const fieldName in typeInfo.fields) {
950
+ const field = typeInfo.fields[fieldName];
951
+ const fieldPath = parentPath ? `${parentPath}.${fieldName}` : fieldName;
952
+ const fieldInfo = {
953
+ path: fieldPath,
954
+ name: fieldName,
955
+ type: field.type,
956
+ isList: field.isList || false,
957
+ isNonNull: field.isNonNull || false
958
+ };
959
+ if (sourceSchema.types[field.type] && sourceSchema.types[field.type].kind === "type") fieldInfo.children = extractFields(field.type, fieldPath, depth + 1);
960
+ result.push(fieldInfo);
961
+ }
962
+ return result;
963
+ };
964
+ const queryType = sourceSchema.types[sourceSchema.queryType || "Query"];
965
+ if (queryType && queryType.fields && sourceOperation) {
966
+ const operationField = queryType.fields[sourceOperation];
967
+ if (operationField) {
968
+ const returnType = operationField.type;
969
+ if (sourceSchema.types[returnType]) return extractFields(returnType, sourceOperation);
970
+ }
971
+ }
972
+ for (const typeName in sourceSchema.types) if (sourceSchema.types[typeName].kind === "type" && !typeName.startsWith("_") && typeName !== "Query" && typeName !== "Mutation") fields.push(...extractFields(typeName, ""));
973
+ return fields;
974
+ }, [sourceSchema, sourceOperation]);
975
+ const arrayFields = useMemo(() => {
976
+ const arrays = [];
977
+ const collectArrays = (fields, prefix = "") => {
978
+ for (const field of fields) {
979
+ if (field.isList) arrays.push({
980
+ ...field,
981
+ path: prefix ? `${prefix}.${field.path}` : field.path
982
+ });
983
+ if (field.children) collectArrays(field.children, prefix);
984
+ }
985
+ };
986
+ collectArrays(sourceFields);
987
+ return arrays;
988
+ }, [sourceFields]);
989
+ const arrayItemFields = useMemo(() => {
990
+ if (!selectedSourceArray || !sourceSchema) return [];
991
+ const findField = (fields, path) => {
992
+ for (const field of fields) {
993
+ if (field.path === path) return field;
994
+ if (field.children) {
995
+ const found = findField(field.children, path);
996
+ if (found) return found;
997
+ }
998
+ }
999
+ return null;
1000
+ };
1001
+ const arrayField = findField(sourceFields, selectedSourceArray);
1002
+ if (!arrayField) return [];
1003
+ const itemType = sourceSchema.types[arrayField.type];
1004
+ if (!itemType || !itemType.fields) return [];
1005
+ const result = [];
1006
+ const extractNestedFields = (typeName, parentPath = "", currentDepth = 0) => {
1007
+ if (currentDepth > 2) return;
1008
+ const type = sourceSchema?.types[typeName];
1009
+ if (!type || !type.fields) return;
1010
+ for (const fieldName in type.fields) {
1011
+ const field = type.fields[fieldName];
1012
+ const fullPath = parentPath ? `${parentPath}.${fieldName}` : fieldName;
1013
+ result.push({
1014
+ name: fieldName,
1015
+ type: field.type,
1016
+ path: fullPath,
1017
+ isNested: currentDepth > 0
1018
+ });
1019
+ const fieldType = sourceSchema?.types[field.type];
1020
+ if (fieldType && fieldType.kind === "type" && !field.isList) extractNestedFields(field.type, fullPath, currentDepth + 1);
1021
+ }
1022
+ };
1023
+ extractNestedFields(arrayField.type);
1024
+ return result;
1025
+ }, [
1026
+ selectedSourceArray,
1027
+ sourceFields,
1028
+ sourceSchema
1029
+ ]);
1030
+ const targetFields = useMemo(() => {
1031
+ if (!targetSchema) return [];
1032
+ const fields = [];
1033
+ const extractFields = (typeName, parentPath = "", depth = 0) => {
1034
+ if (depth > 3) return [];
1035
+ const typeInfo = targetSchema.types[typeName];
1036
+ if (!typeInfo) return [];
1037
+ const fieldsObj = typeInfo.inputFields || typeInfo.fields;
1038
+ if (!fieldsObj) return [];
1039
+ const result = [];
1040
+ for (const fieldName in fieldsObj) {
1041
+ const field = fieldsObj[fieldName];
1042
+ const fieldPath = parentPath ? `${parentPath}.${fieldName}` : fieldName;
1043
+ const fieldInfo = {
1044
+ path: fieldPath,
1045
+ name: fieldName,
1046
+ type: field.type,
1047
+ isList: field.isList || false,
1048
+ isNonNull: field.isNonNull || false
1049
+ };
1050
+ if (targetSchema.types[field.type]) {
1051
+ const nestedType = targetSchema.types[field.type];
1052
+ if (nestedType.kind === "type" || nestedType.kind === "input") fieldInfo.children = extractFields(field.type, fieldPath, depth + 1);
1053
+ }
1054
+ result.push(fieldInfo);
1055
+ }
1056
+ return result;
1057
+ };
1058
+ const mutationType = targetSchema.types[targetSchema.mutationType || "Mutation"];
1059
+ const queryType = targetSchema.types[targetSchema.queryType || "Query"];
1060
+ if (targetOperation) {
1061
+ if (mutationType?.fields?.[targetOperation]) {
1062
+ const operationField = mutationType.fields[targetOperation];
1063
+ if (operationField.args && operationField.args.length > 0) for (const arg of operationField.args) if (targetSchema.types[arg.type]) fields.push(...extractFields(arg.type, ""));
1064
+ else fields.push({
1065
+ path: arg.name,
1066
+ name: arg.name,
1067
+ type: arg.type,
1068
+ isList: arg.isList || false,
1069
+ isNonNull: arg.isNonNull || false
1070
+ });
1071
+ }
1072
+ if (queryType?.fields?.[targetOperation]) {
1073
+ const operationField = queryType.fields[targetOperation];
1074
+ if (operationField.args && operationField.args.length > 0) for (const arg of operationField.args) if (targetSchema.types[arg.type]) fields.push(...extractFields(arg.type, ""));
1075
+ else fields.push({
1076
+ path: arg.name,
1077
+ name: arg.name,
1078
+ type: arg.type,
1079
+ isList: arg.isList || false,
1080
+ isNonNull: arg.isNonNull || false
1081
+ });
1082
+ }
1083
+ }
1084
+ return fields;
1085
+ }, [targetSchema, targetOperation]);
1086
+ const handleSourceArrayChange = (value) => {
1087
+ setSelectedSourceArray(value);
1088
+ if (mappingType === "array" && value && itemExpression) setExpression(`\${output.${value}.map(item => item.${itemExpression})}`);
1089
+ };
1090
+ const handleItemExpressionChange = (value) => {
1091
+ setItemExpression(value);
1092
+ if (mappingType === "array" && selectedSourceArray && value) setExpression(`\${output.${selectedSourceArray}.map(item => item.${value})}`);
1093
+ };
1094
+ const getMappingTypeConfig = () => {
1095
+ return dataConfig?.mappingTypes?.[mappingType] || {};
1096
+ };
1097
+ const mappingTypeConfig = getMappingTypeConfig();
1098
+ const examples = mappingTypeConfig.examples || [];
1099
+ const safeBuiltins = mappingTypeConfig.safeBuiltins || [];
1100
+ const isFormValid = useMemo(() => {
1101
+ if (!targetFieldName.trim()) return false;
1102
+ if (!expression.trim()) return false;
1103
+ return true;
1104
+ }, [targetFieldName, expression]);
1105
+ const getValidationMessage = () => {
1106
+ const missing = [];
1107
+ if (!targetFieldName.trim()) missing.push(tr("fluidgrids.builder.mappingDialog.missingTargetFieldName", "target field name"));
1108
+ if (!expression.trim()) missing.push(tr("fluidgrids.builder.mappingDialog.missingExpression", "expression"));
1109
+ if (missing.length === 0) return null;
1110
+ return `${tr("fluidgrids.builder.mappingDialog.validationPrefix", "Please provide:")} ${missing.join(", ")}`;
1111
+ };
1112
+ const handleExampleChange = (exampleName) => {
1113
+ setSelectedExample(exampleName);
1114
+ if (exampleName && exampleName !== "choose") {
1115
+ const example = examples.find((ex) => ex.name === exampleName);
1116
+ if (example && example.expression) setExpression(example.expression);
1117
+ }
1118
+ };
1119
+ const handleSave = () => {
1120
+ onSave(expression, targetFieldName || void 0);
1121
+ onOpenChange(false);
1122
+ };
1123
+ const getDialogTitle = () => {
1124
+ switch (mappingType) {
1125
+ case "direct": return tr("fluidgrids.builder.mappingDialog.titleDirect", "Direct Field Mapping");
1126
+ case "expression": return tr("fluidgrids.builder.mappingDialog.titleExpression", "Expression Mapping");
1127
+ case "transform": return tr("fluidgrids.builder.mappingDialog.titleTransform", "Transform Mapping");
1128
+ case "cast": return tr("fluidgrids.builder.mappingDialog.titleCast", "Type Cast Mapping");
1129
+ case "array": return tr("fluidgrids.builder.mappingDialog.titleArray", "Array Mapping");
1130
+ case "object": return tr("fluidgrids.builder.mappingDialog.titleObject", "Object Mapping");
1131
+ case "context": return tr("fluidgrids.builder.mappingDialog.titleContext", "Workflow Context");
1132
+ default: return tr("fluidgrids.builder.mappingDialog.titleDefault", "Data Mapping");
1133
+ }
1134
+ };
1135
+ const getDialogDescription = () => {
1136
+ return mappingTypeConfig.description || tr("fluidgrids.builder.mappingDialog.defaultDescription", "Create a mapping using JavaScript template literal syntax");
1137
+ };
1138
+ const getPlaceholder = () => {
1139
+ switch (mappingType) {
1140
+ case "direct": return "${output.fieldName}";
1141
+ case "expression": return "${output.firstName + ' ' + output.lastName}";
1142
+ case "transform": return "${output.field.toUpperCase()}";
1143
+ case "cast": return "${parseInt(output.numberString)}";
1144
+ case "array": return "${output.items.map(item => item.id)}";
1145
+ case "object": return "${({ id: output.user.id, email: output.user.email })}";
1146
+ case "context": return "${TriggerInput.userId}";
1147
+ default: return "${output.field}";
1148
+ }
1149
+ };
1150
+ const getQuickInserts = () => {
1151
+ switch (mappingType) {
1152
+ case "direct": return [
1153
+ {
1154
+ label: "output.",
1155
+ snippet: "output."
1156
+ },
1157
+ {
1158
+ label: "?.",
1159
+ snippet: "?."
1160
+ },
1161
+ {
1162
+ label: "|| ''",
1163
+ snippet: " || ''"
1164
+ },
1165
+ {
1166
+ label: "?? null",
1167
+ snippet: " ?? null"
1168
+ }
1169
+ ];
1170
+ case "expression": return [
1171
+ {
1172
+ label: "output.",
1173
+ snippet: "output."
1174
+ },
1175
+ {
1176
+ label: "? :",
1177
+ snippet: " ? '' : ''"
1178
+ },
1179
+ {
1180
+ label: "&&",
1181
+ snippet: " && "
1182
+ },
1183
+ {
1184
+ label: "||",
1185
+ snippet: " || "
1186
+ },
1187
+ {
1188
+ label: "??",
1189
+ snippet: " ?? "
1190
+ }
1191
+ ];
1192
+ case "transform": return [
1193
+ {
1194
+ label: ".toUpperCase()",
1195
+ snippet: ".toUpperCase()"
1196
+ },
1197
+ {
1198
+ label: ".toLowerCase()",
1199
+ snippet: ".toLowerCase()"
1200
+ },
1201
+ {
1202
+ label: ".trim()",
1203
+ snippet: ".trim()"
1204
+ },
1205
+ {
1206
+ label: ".split(',')",
1207
+ snippet: ".split(',')"
1208
+ },
1209
+ {
1210
+ label: ".join(', ')",
1211
+ snippet: ".join(', ')"
1212
+ },
1213
+ {
1214
+ label: ".replace()",
1215
+ snippet: ".replace('old', 'new')"
1216
+ }
1217
+ ];
1218
+ case "cast": return [
1219
+ {
1220
+ label: "parseInt()",
1221
+ snippet: "parseInt("
1222
+ },
1223
+ {
1224
+ label: "parseFloat()",
1225
+ snippet: "parseFloat("
1226
+ },
1227
+ {
1228
+ label: "String()",
1229
+ snippet: "String("
1230
+ },
1231
+ {
1232
+ label: "Boolean()",
1233
+ snippet: "Boolean("
1234
+ },
1235
+ {
1236
+ label: "Number()",
1237
+ snippet: "Number("
1238
+ }
1239
+ ];
1240
+ case "array": return [
1241
+ {
1242
+ label: ".map()",
1243
+ snippet: ".map(item => item)"
1244
+ },
1245
+ {
1246
+ label: ".filter()",
1247
+ snippet: ".filter(item => item)"
1248
+ },
1249
+ {
1250
+ label: ".reduce()",
1251
+ snippet: ".reduce((acc, item) => acc, 0)"
1252
+ },
1253
+ {
1254
+ label: ".find()",
1255
+ snippet: ".find(item => item)"
1256
+ },
1257
+ {
1258
+ label: ".some()",
1259
+ snippet: ".some(item => item)"
1260
+ },
1261
+ {
1262
+ label: ".every()",
1263
+ snippet: ".every(item => item)"
1264
+ },
1265
+ {
1266
+ label: ".flat()",
1267
+ snippet: ".flat()"
1268
+ },
1269
+ {
1270
+ label: ".slice()",
1271
+ snippet: ".slice(0, 5)"
1272
+ },
1273
+ {
1274
+ label: ".sort()",
1275
+ snippet: ".sort((a, b) => a - b)"
1276
+ }
1277
+ ];
1278
+ case "object": return [
1279
+ {
1280
+ label: "Object.keys()",
1281
+ snippet: "Object.keys("
1282
+ },
1283
+ {
1284
+ label: "Object.values()",
1285
+ snippet: "Object.values("
1286
+ },
1287
+ {
1288
+ label: "Object.entries()",
1289
+ snippet: "Object.entries("
1290
+ },
1291
+ {
1292
+ label: "Object.assign()",
1293
+ snippet: "Object.assign({}, "
1294
+ },
1295
+ {
1296
+ label: "{ ...obj }",
1297
+ snippet: "{ ..."
1298
+ }
1299
+ ];
1300
+ case "context": return [
1301
+ {
1302
+ label: "TriggerInput.",
1303
+ snippet: "TriggerInput."
1304
+ },
1305
+ {
1306
+ label: "WorkflowState.",
1307
+ snippet: "WorkflowState."
1308
+ },
1309
+ {
1310
+ label: "RunContext.",
1311
+ snippet: "RunContext."
1312
+ },
1313
+ {
1314
+ label: ".output.",
1315
+ snippet: ".output."
1316
+ },
1317
+ {
1318
+ label: ".status",
1319
+ snippet: ".status"
1320
+ }
1321
+ ];
1322
+ default: return [];
1323
+ }
1324
+ };
1325
+ const insertSnippet = (snippet) => {
1326
+ const textarea = document.getElementById("expression-input");
1327
+ if (textarea) {
1328
+ const start = textarea.selectionStart;
1329
+ const end = textarea.selectionEnd;
1330
+ const newValue = expression.slice(0, start) + snippet + expression.slice(end);
1331
+ setExpression(newValue);
1332
+ setTimeout(() => {
1333
+ textarea.focus();
1334
+ textarea.setSelectionRange(start + snippet.length, start + snippet.length);
1335
+ }, 0);
1336
+ } else setExpression(expression + snippet);
1337
+ };
1338
+ if (!open) return null;
1339
+ const title = getDialogTitle();
1340
+ const description = getDialogDescription();
1341
+ const targetFieldControls = /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs(Label, {
1342
+ htmlFor: "target-field-name",
1343
+ className: "text-sm font-medium",
1344
+ children: [
1345
+ tr("fluidgrids.builder.mappingDialog.targetFieldNameLabel", "Target Field Name"),
1346
+ " ",
1347
+ /* @__PURE__ */ jsx("span", {
1348
+ className: "text-muted-foreground",
1349
+ children: tr("fluidgrids.builder.mappingDialog.targetFieldNameHint", "(where the result will be stored)")
1350
+ })
1351
+ ]
1352
+ }), targetFields.length > 0 ? /* @__PURE__ */ jsxs("div", {
1353
+ className: "mt-2 space-y-2",
1354
+ children: [
1355
+ /* @__PURE__ */ jsxs(Select, {
1356
+ value: targetFieldName,
1357
+ onValueChange: setTargetFieldName,
1358
+ children: [/* @__PURE__ */ jsx(SelectTrigger, { children: /* @__PURE__ */ jsx(SelectValue, { placeholder: tr("fluidgrids.builder.mappingDialog.selectTargetFieldPlaceholder", "Select target field...") }) }), /* @__PURE__ */ jsx(SelectContent, {
1359
+ className: "z-[100003]",
1360
+ children: targetFields.map((field) => /* @__PURE__ */ jsx(SelectItem, {
1361
+ value: field.path,
1362
+ children: /* @__PURE__ */ jsxs("div", {
1363
+ className: "flex items-center gap-2",
1364
+ children: [
1365
+ /* @__PURE__ */ jsx("span", {
1366
+ className: "font-mono",
1367
+ children: field.path
1368
+ }),
1369
+ /* @__PURE__ */ jsx(Badge, {
1370
+ variant: "outline",
1371
+ className: "text-xs",
1372
+ children: field.isList ? `[${field.type}]` : field.type
1373
+ }),
1374
+ field.isNonNull && /* @__PURE__ */ jsx("span", {
1375
+ className: "text-[var(--color-status-error-text)] text-xs",
1376
+ children: "*"
1377
+ })
1378
+ ]
1379
+ })
1380
+ }, field.path))
1381
+ })]
1382
+ }),
1383
+ /* @__PURE__ */ jsx("p", {
1384
+ className: "text-xs text-muted-foreground",
1385
+ children: tr("fluidgrids.builder.mappingDialog.orCustomFieldName", "Or enter a custom field name:")
1386
+ }),
1387
+ /* @__PURE__ */ jsx(Input, {
1388
+ id: "target-field-name",
1389
+ placeholder: tr("fluidgrids.builder.mappingDialog.targetFieldNamePlaceholder", "e.g., messageIds, userNames, totalPrice"),
1390
+ value: targetFieldName,
1391
+ onChange: (e) => setTargetFieldName(e.target.value),
1392
+ className: "font-mono"
1393
+ })
1394
+ ]
1395
+ }) : /* @__PURE__ */ jsx(Input, {
1396
+ id: "target-field-name",
1397
+ placeholder: tr("fluidgrids.builder.mappingDialog.targetFieldNamePlaceholder", "e.g., messageIds, userNames, totalPrice"),
1398
+ value: targetFieldName,
1399
+ onChange: (e) => setTargetFieldName(e.target.value),
1400
+ className: "mt-2"
1401
+ })] });
1402
+ const tabPanels = {
1403
+ builder: /* @__PURE__ */ jsxs(Fragment$1, { children: [
1404
+ mappingType === "array" && /* @__PURE__ */ jsxs(Fragment$1, { children: [
1405
+ /* @__PURE__ */ jsxs("div", {
1406
+ className: "grid gap-2",
1407
+ children: [/* @__PURE__ */ jsx(Label, { children: tr("fluidgrids.builder.mappingDialog.stepSelectSourceArray", "1. Select Source Array") }), arrayFields.length > 0 ? /* @__PURE__ */ jsxs(Select, {
1408
+ value: selectedSourceArray,
1409
+ onValueChange: handleSourceArrayChange,
1410
+ children: [/* @__PURE__ */ jsx(SelectTrigger, { children: /* @__PURE__ */ jsx(SelectValue, { placeholder: tr("fluidgrids.builder.mappingDialog.chooseArrayFieldPlaceholder", "Choose an array field...") }) }), /* @__PURE__ */ jsx(SelectContent, {
1411
+ className: "z-[100003]",
1412
+ children: arrayFields.map((field) => /* @__PURE__ */ jsx(SelectItem, {
1413
+ value: field.path,
1414
+ children: /* @__PURE__ */ jsxs("div", {
1415
+ className: "flex items-center gap-2",
1416
+ children: [/* @__PURE__ */ jsx("span", {
1417
+ className: "font-mono",
1418
+ children: field.path
1419
+ }), /* @__PURE__ */ jsxs(Badge, {
1420
+ variant: "outline",
1421
+ className: "text-xs",
1422
+ children: [
1423
+ "[",
1424
+ field.type,
1425
+ "]"
1426
+ ]
1427
+ })]
1428
+ })
1429
+ }, field.path))
1430
+ })]
1431
+ }) : /* @__PURE__ */ jsxs("div", {
1432
+ className: "p-3 border border-border-default rounded-md bg-muted",
1433
+ children: [/* @__PURE__ */ jsx("p", {
1434
+ className: "text-sm text-muted-foreground",
1435
+ children: tr("fluidgrids.builder.mappingDialog.noArrayFieldsHint", "No array fields found in schema. Enter the array path manually:")
1436
+ }), /* @__PURE__ */ jsx(Input, {
1437
+ placeholder: tr("fluidgrids.builder.mappingDialog.arrayPathPlaceholder", "e.g., searchEmails.emails"),
1438
+ value: selectedSourceArray,
1439
+ onChange: (e) => handleSourceArrayChange(e.target.value),
1440
+ className: "mt-2 font-mono"
1441
+ })]
1442
+ })]
1443
+ }),
1444
+ /* @__PURE__ */ jsxs("div", {
1445
+ className: "grid gap-2",
1446
+ children: [/* @__PURE__ */ jsx(Label, { children: tr("fluidgrids.builder.mappingDialog.stepExtractProperty", "2. Extract Property from Each Item") }), arrayItemFields.length > 0 ? /* @__PURE__ */ jsxs("div", {
1447
+ className: "space-y-2",
1448
+ children: [
1449
+ /* @__PURE__ */ jsx("div", {
1450
+ className: "flex flex-wrap gap-1 max-h-[120px] overflow-y-auto p-1",
1451
+ children: arrayItemFields.map((field) => /* @__PURE__ */ jsxs(Badge, {
1452
+ variant: itemExpression === field.path ? "default" : "outline",
1453
+ className: `cursor-pointer hover:bg-primary hover:text-primary-foreground ${field.isNested ? "ml-2 border-dashed" : ""}`,
1454
+ onClick: () => handleItemExpressionChange(field.path),
1455
+ children: [field.isNested ? /* @__PURE__ */ jsx("span", {
1456
+ className: "font-mono text-xs",
1457
+ children: field.path
1458
+ }) : field.name, /* @__PURE__ */ jsxs("span", {
1459
+ className: "ml-1 opacity-60 text-[10px]",
1460
+ children: [
1461
+ "(",
1462
+ field.type,
1463
+ ")"
1464
+ ]
1465
+ })]
1466
+ }, field.path))
1467
+ }),
1468
+ /* @__PURE__ */ jsx("p", {
1469
+ className: "text-xs text-muted-foreground",
1470
+ children: tr("fluidgrids.builder.mappingDialog.clickFieldOrCustomPath", "Click a field above or enter a custom path:")
1471
+ }),
1472
+ /* @__PURE__ */ jsx(Input, {
1473
+ placeholder: tr("fluidgrids.builder.mappingDialog.itemPropertyPlaceholder", "e.g., metadata.id, user.email"),
1474
+ value: itemExpression,
1475
+ onChange: (e) => handleItemExpressionChange(e.target.value),
1476
+ className: "font-mono"
1477
+ })
1478
+ ]
1479
+ }) : /* @__PURE__ */ jsx(Input, {
1480
+ placeholder: tr("fluidgrids.builder.mappingDialog.itemPropertyPlaceholderShort", "e.g., metadata.id, user.email, id"),
1481
+ value: itemExpression,
1482
+ onChange: (e) => handleItemExpressionChange(e.target.value),
1483
+ className: "font-mono"
1484
+ })]
1485
+ }),
1486
+ /* @__PURE__ */ jsxs("div", {
1487
+ className: "grid gap-2",
1488
+ children: [/* @__PURE__ */ jsx(Label, { children: tr("fluidgrids.builder.mappingDialog.stepGeneratedExpression", "3. Generated Expression") }), /* @__PURE__ */ jsx("div", {
1489
+ className: "p-3 bg-muted rounded-md border border-border-default",
1490
+ children: /* @__PURE__ */ jsx("code", {
1491
+ className: "text-sm break-all block font-mono",
1492
+ children: expression || "${output.arrayField.map(item => item.property)}"
1493
+ })
1494
+ })]
1495
+ }),
1496
+ selectedSourceArray && itemExpression && /* @__PURE__ */ jsxs("div", {
1497
+ className: "p-3 bg-[var(--color-status-success-bg-subtle)] rounded-md border border-[var(--color-status-success-border)]",
1498
+ children: [/* @__PURE__ */ jsx(Label, {
1499
+ className: "text-[var(--color-status-success-text)]",
1500
+ children: tr("fluidgrids.builder.mappingDialog.resultPreview", "Result Preview:")
1501
+ }), /* @__PURE__ */ jsxs("div", {
1502
+ className: "mt-2 flex items-center gap-2 text-sm",
1503
+ children: [
1504
+ /* @__PURE__ */ jsx("code", {
1505
+ className: "bg-surface px-2 py-1 rounded",
1506
+ children: targetFieldName || "result"
1507
+ }),
1508
+ /* @__PURE__ */ jsx(ChevronRight, { className: "h-4 w-4 text-muted-foreground" }),
1509
+ /* @__PURE__ */ jsxs("code", {
1510
+ className: "bg-surface px-2 py-1 rounded",
1511
+ children: [
1512
+ "[",
1513
+ itemExpression,
1514
+ ", ",
1515
+ itemExpression,
1516
+ ", ...]"
1517
+ ]
1518
+ })
1519
+ ]
1520
+ })]
1521
+ })
1522
+ ] }),
1523
+ mappingType !== "array" && /* @__PURE__ */ jsx("div", {
1524
+ className: "p-4 bg-muted rounded-md",
1525
+ children: /* @__PURE__ */ jsxs("p", {
1526
+ className: "text-sm text-muted-foreground",
1527
+ children: [
1528
+ "The guided builder is optimized for ",
1529
+ /* @__PURE__ */ jsx("strong", { children: "Array" }),
1530
+ " ",
1531
+ "mappings. For ",
1532
+ mappingType,
1533
+ " mappings, use the",
1534
+ " ",
1535
+ /* @__PURE__ */ jsx("strong", { children: "Examples" }),
1536
+ " or ",
1537
+ /* @__PURE__ */ jsx("strong", { children: "Editor" }),
1538
+ " tabs."
1539
+ ]
1540
+ })
1541
+ }),
1542
+ sourceFields.length > 0 && /* @__PURE__ */ jsxs("div", {
1543
+ className: "grid gap-2",
1544
+ children: [/* @__PURE__ */ jsx(Label, { children: tr("fluidgrids.builder.mappingDialog.availableSourceFields", "Available Source Fields") }), /* @__PURE__ */ jsx("div", {
1545
+ className: "p-3 border rounded-md max-h-[150px] overflow-y-auto bg-muted/50",
1546
+ children: /* @__PURE__ */ jsxs("div", {
1547
+ className: "space-y-1",
1548
+ children: [sourceFields.slice(0, 15).map((field) => /* @__PURE__ */ jsxs("div", {
1549
+ className: "flex items-center gap-2 text-xs",
1550
+ children: [/* @__PURE__ */ jsx("code", {
1551
+ className: "font-mono",
1552
+ children: field.path
1553
+ }), /* @__PURE__ */ jsx(Badge, {
1554
+ variant: "outline",
1555
+ className: "text-[10px]",
1556
+ children: field.isList ? `[${field.type}]` : field.type
1557
+ })]
1558
+ }, field.path)), sourceFields.length > 15 && /* @__PURE__ */ jsxs("p", {
1559
+ className: "text-xs text-muted-foreground mt-2",
1560
+ children: [
1561
+ "...and ",
1562
+ sourceFields.length - 15,
1563
+ " more fields"
1564
+ ]
1565
+ })]
1566
+ })
1567
+ })]
1568
+ })
1569
+ ] }),
1570
+ examples: /* @__PURE__ */ jsxs(Fragment$1, { children: [examples.length > 0 && /* @__PURE__ */ jsxs("div", {
1571
+ className: "grid gap-2",
1572
+ children: [/* @__PURE__ */ jsx(Label, { children: tr("fluidgrids.builder.mappingDialog.selectExampleLabel", "Select an example to start with:") }), /* @__PURE__ */ jsxs(Select, {
1573
+ value: selectedExample,
1574
+ onValueChange: handleExampleChange,
1575
+ children: [/* @__PURE__ */ jsx(SelectTrigger, { children: /* @__PURE__ */ jsx(SelectValue, { placeholder: tr("fluidgrids.builder.mappingDialog.chooseExamplePlaceholder", "Choose an example") }) }), /* @__PURE__ */ jsxs(SelectContent, {
1576
+ className: "z-[100003]",
1577
+ children: [/* @__PURE__ */ jsx(SelectItem, {
1578
+ value: "choose",
1579
+ children: tr("fluidgrids.builder.mappingDialog.chooseExamplePlaceholder", "Choose an example")
1580
+ }), examples.map((example) => /* @__PURE__ */ jsxs(SelectItem, {
1581
+ value: example.name,
1582
+ children: [
1583
+ example.name,
1584
+ " - ",
1585
+ example.description
1586
+ ]
1587
+ }, example.name))]
1588
+ })]
1589
+ })]
1590
+ }), /* @__PURE__ */ jsxs("div", {
1591
+ className: "grid gap-2",
1592
+ children: [/* @__PURE__ */ jsx(Label, { children: tr("fluidgrids.builder.mappingDialog.quickExamples", "Quick Examples:") }), /* @__PURE__ */ jsx("div", {
1593
+ className: "grid grid-cols-1 gap-2 max-h-[200px] overflow-y-auto",
1594
+ children: examples.slice(0, 8).map((example) => /* @__PURE__ */ jsxs("button", {
1595
+ type: "button",
1596
+ className: "block w-full p-2 border rounded-md cursor-pointer text-start hover:bg-muted transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
1597
+ onClick: () => {
1598
+ setExpression(example.expression);
1599
+ setActiveTab("editor");
1600
+ },
1601
+ children: [/* @__PURE__ */ jsx("span", {
1602
+ className: "block font-medium text-sm",
1603
+ children: example.name
1604
+ }), /* @__PURE__ */ jsx("code", {
1605
+ className: "text-xs text-muted-foreground block mt-1 break-all",
1606
+ children: example.expression
1607
+ })]
1608
+ }, example.name))
1609
+ })]
1610
+ })] }),
1611
+ editor: /* @__PURE__ */ jsxs(Fragment$1, { children: [
1612
+ /* @__PURE__ */ jsxs("div", {
1613
+ className: "grid gap-2",
1614
+ children: [/* @__PURE__ */ jsx(Label, { children: tr("fluidgrids.builder.mappingDialog.quickInsert", "Quick Insert:") }), /* @__PURE__ */ jsx("div", {
1615
+ className: "flex flex-wrap gap-1",
1616
+ children: getQuickInserts().map((item) => /* @__PURE__ */ jsx(Badge, {
1617
+ variant: "secondary",
1618
+ className: "cursor-pointer hover:bg-primary hover:text-primary-foreground",
1619
+ onClick: () => insertSnippet(item.snippet),
1620
+ children: item.label
1621
+ }, item.label))
1622
+ })]
1623
+ }),
1624
+ /* @__PURE__ */ jsxs("div", {
1625
+ className: "grid gap-2",
1626
+ children: [
1627
+ /* @__PURE__ */ jsx(Label, {
1628
+ htmlFor: "expression-input",
1629
+ children: tr("fluidgrids.builder.mappingDialog.templateExpression", "Template Expression")
1630
+ }),
1631
+ /* @__PURE__ */ jsx(Textarea, {
1632
+ id: "expression-input",
1633
+ placeholder: getPlaceholder(),
1634
+ value: expression,
1635
+ onChange: (e) => setExpression(e.target.value),
1636
+ className: "h-32 font-mono text-sm"
1637
+ }),
1638
+ /* @__PURE__ */ jsxs("p", {
1639
+ className: "text-xs text-muted-foreground",
1640
+ children: [
1641
+ tr("fluidgrids.builder.mappingDialog.templateSyntaxHint", "Use JavaScript template literal syntax:"),
1642
+ " ",
1643
+ /* @__PURE__ */ jsxs("code", {
1644
+ className: "bg-muted px-1 rounded",
1645
+ children: [
1646
+ "$",
1647
+ "{",
1648
+ "expression",
1649
+ "}"
1650
+ ]
1651
+ })
1652
+ ]
1653
+ })
1654
+ ]
1655
+ }),
1656
+ (sourceField || targetField) && /* @__PURE__ */ jsxs("div", {
1657
+ className: "p-3 bg-muted rounded-md",
1658
+ children: [/* @__PURE__ */ jsx("h4", {
1659
+ className: "text-sm font-medium mb-2",
1660
+ children: tr("fluidgrids.builder.mappingDialog.mappingContext", "Mapping Context")
1661
+ }), /* @__PURE__ */ jsxs("div", {
1662
+ className: "text-xs space-y-1",
1663
+ children: [sourceField && /* @__PURE__ */ jsxs("div", { children: [
1664
+ /* @__PURE__ */ jsx("span", {
1665
+ className: "text-muted-foreground",
1666
+ children: tr("fluidgrids.builder.mappingDialog.sourceFieldLabel", "Source field:")
1667
+ }),
1668
+ " ",
1669
+ /* @__PURE__ */ jsx("code", {
1670
+ className: "bg-background px-1 rounded",
1671
+ children: sourceField
1672
+ })
1673
+ ] }), targetField && /* @__PURE__ */ jsxs("div", { children: [
1674
+ /* @__PURE__ */ jsx("span", {
1675
+ className: "text-muted-foreground",
1676
+ children: tr("fluidgrids.builder.mappingDialog.targetFieldLabel", "Target field:")
1677
+ }),
1678
+ " ",
1679
+ /* @__PURE__ */ jsx("code", {
1680
+ className: "bg-background px-1 rounded",
1681
+ children: targetField
1682
+ })
1683
+ ] })]
1684
+ })]
1685
+ }),
1686
+ /* @__PURE__ */ jsxs("div", {
1687
+ className: "p-3 bg-muted rounded-md",
1688
+ children: [/* @__PURE__ */ jsx("h4", {
1689
+ className: "text-sm font-medium mb-2",
1690
+ children: tr("fluidgrids.builder.mappingDialog.mappingValue", "Mapping Value")
1691
+ }), /* @__PURE__ */ jsx("code", {
1692
+ className: "text-xs break-all block",
1693
+ children: expression || tr("fluidgrids.builder.mappingDialog.emptyExpression", "(empty)")
1694
+ })]
1695
+ })
1696
+ ] }),
1697
+ help: /* @__PURE__ */ jsxs(Fragment$1, { children: [
1698
+ /* @__PURE__ */ jsxs("div", {
1699
+ className: "p-3 bg-muted rounded-md",
1700
+ children: [/* @__PURE__ */ jsx("h4", {
1701
+ className: "text-sm font-medium mb-2",
1702
+ children: tr("fluidgrids.builder.mappingDialog.availableVariables", "Available Variables")
1703
+ }), /* @__PURE__ */ jsxs("div", {
1704
+ className: "text-xs space-y-2",
1705
+ children: [
1706
+ /* @__PURE__ */ jsxs("div", { children: [
1707
+ /* @__PURE__ */ jsx("code", {
1708
+ className: "bg-background px-1 rounded",
1709
+ children: "output"
1710
+ }),
1711
+ " -",
1712
+ " ",
1713
+ tr("fluidgrids.builder.mappingDialog.varOutput", "Output from the previous node")
1714
+ ] }),
1715
+ /* @__PURE__ */ jsxs("div", { children: [
1716
+ /* @__PURE__ */ jsx("code", {
1717
+ className: "bg-background px-1 rounded",
1718
+ children: "TriggerInput"
1719
+ }),
1720
+ " -",
1721
+ " ",
1722
+ tr("fluidgrids.builder.mappingDialog.varTriggerInput", "Original trigger payload")
1723
+ ] }),
1724
+ /* @__PURE__ */ jsxs("div", { children: [
1725
+ /* @__PURE__ */ jsx("code", {
1726
+ className: "bg-background px-1 rounded",
1727
+ children: "WorkflowState"
1728
+ }),
1729
+ " ",
1730
+ "-",
1731
+ " ",
1732
+ tr("fluidgrids.builder.mappingDialog.varWorkflowState", "Outputs from all previous nodes")
1733
+ ] }),
1734
+ /* @__PURE__ */ jsxs("div", { children: [
1735
+ /* @__PURE__ */ jsx("code", {
1736
+ className: "bg-background px-1 rounded",
1737
+ children: "RunContext"
1738
+ }),
1739
+ " -",
1740
+ " ",
1741
+ tr("fluidgrids.builder.mappingDialog.varRunContext", "Workflow execution metadata")
1742
+ ] }),
1743
+ /* @__PURE__ */ jsxs("div", { children: [
1744
+ /* @__PURE__ */ jsx("code", {
1745
+ className: "bg-background px-1 rounded",
1746
+ children: "item"
1747
+ }),
1748
+ " -",
1749
+ " ",
1750
+ tr("fluidgrids.builder.mappingDialog.varItem", "Current item (in array operations)")
1751
+ ] }),
1752
+ /* @__PURE__ */ jsxs("div", { children: [
1753
+ /* @__PURE__ */ jsx("code", {
1754
+ className: "bg-background px-1 rounded",
1755
+ children: "index"
1756
+ }),
1757
+ " -",
1758
+ " ",
1759
+ tr("fluidgrids.builder.mappingDialog.varIndex", "Current index (in array operations)")
1760
+ ] })
1761
+ ]
1762
+ })]
1763
+ }),
1764
+ safeBuiltins.length > 0 && /* @__PURE__ */ jsxs("div", {
1765
+ className: "p-3 bg-muted rounded-md",
1766
+ children: [/* @__PURE__ */ jsx("h4", {
1767
+ className: "text-sm font-medium mb-2",
1768
+ children: tr("fluidgrids.builder.mappingDialog.availableFunctions", "Available Functions")
1769
+ }), /* @__PURE__ */ jsx("div", {
1770
+ className: "text-xs grid grid-cols-3 gap-1",
1771
+ children: safeBuiltins.map((func) => /* @__PURE__ */ jsx("code", {
1772
+ className: "bg-background px-1 rounded",
1773
+ children: func
1774
+ }, func))
1775
+ })]
1776
+ }),
1777
+ /* @__PURE__ */ jsxs("div", {
1778
+ className: "p-3 bg-muted rounded-md",
1779
+ children: [/* @__PURE__ */ jsx("h4", {
1780
+ className: "text-sm font-medium mb-2",
1781
+ children: tr("fluidgrids.builder.mappingDialog.syntaxTips", "Syntax Tips")
1782
+ }), /* @__PURE__ */ jsxs("div", {
1783
+ className: "text-xs space-y-1",
1784
+ children: [
1785
+ /* @__PURE__ */ jsxs("div", { children: [
1786
+ /* @__PURE__ */ jsx("strong", { children: tr("fluidgrids.builder.mappingDialog.tipOptionalChaining", "Optional chaining:") }),
1787
+ " ",
1788
+ /* @__PURE__ */ jsx("code", {
1789
+ className: "bg-background px-1 rounded",
1790
+ children: "output.user?.email"
1791
+ })
1792
+ ] }),
1793
+ /* @__PURE__ */ jsxs("div", { children: [
1794
+ /* @__PURE__ */ jsx("strong", { children: tr("fluidgrids.builder.mappingDialog.tipNullishCoalescing", "Nullish coalescing:") }),
1795
+ " ",
1796
+ /* @__PURE__ */ jsx("code", {
1797
+ className: "bg-background px-1 rounded",
1798
+ children: `output.value ?? 'default'`
1799
+ })
1800
+ ] }),
1801
+ /* @__PURE__ */ jsxs("div", { children: [
1802
+ /* @__PURE__ */ jsx("strong", { children: tr("fluidgrids.builder.mappingDialog.tipTernary", "Ternary:") }),
1803
+ " ",
1804
+ /* @__PURE__ */ jsx("code", {
1805
+ className: "bg-background px-1 rounded",
1806
+ children: `output.active ? 'Yes' : 'No'`
1807
+ })
1808
+ ] }),
1809
+ /* @__PURE__ */ jsxs("div", { children: [
1810
+ /* @__PURE__ */ jsx("strong", { children: tr("fluidgrids.builder.mappingDialog.tipArrayAccess", "Array access:") }),
1811
+ " ",
1812
+ /* @__PURE__ */ jsx("code", {
1813
+ className: "bg-background px-1 rounded",
1814
+ children: "output.items[0].name"
1815
+ })
1816
+ ] })
1817
+ ]
1818
+ })]
1819
+ })
1820
+ ] })
1821
+ };
1822
+ const footerContent = /* @__PURE__ */ jsxs(Fragment$1, { children: [!isFormValid && /* @__PURE__ */ jsx("div", {
1823
+ className: "mb-3 p-2 bg-[var(--color-status-warning-bg-subtle)] border border-[var(--color-status-warning-border)] rounded-md",
1824
+ children: /* @__PURE__ */ jsx("p", {
1825
+ className: "text-sm text-[var(--color-status-warning-text)]",
1826
+ children: getValidationMessage()
1827
+ })
1828
+ }), /* @__PURE__ */ jsxs("div", {
1829
+ className: stable ? "flex flex-wrap items-center justify-between gap-x-3 gap-y-2" : "flex justify-between items-center",
1830
+ "data-testid": stable ? "fluidgrids-mapping-footer-row" : void 0,
1831
+ children: [/* @__PURE__ */ jsx("div", {
1832
+ className: stable ? "min-w-0 text-xs text-muted-foreground" : "text-xs text-muted-foreground",
1833
+ children: targetFieldName && expression && /* @__PURE__ */ jsxs("code", {
1834
+ className: "bg-muted px-2 py-1 rounded",
1835
+ children: [
1836
+ targetFieldName,
1837
+ ":",
1838
+ " ",
1839
+ expression.length > 40 ? expression.substring(0, 40) + "..." : expression
1840
+ ]
1841
+ })
1842
+ }), /* @__PURE__ */ jsxs("div", {
1843
+ className: stable ? "ms-auto flex shrink-0 gap-2" : "flex gap-2",
1844
+ children: [/* @__PURE__ */ jsx(Button, {
1845
+ variant: "outline",
1846
+ onClick: () => onOpenChange(false),
1847
+ children: tr("fluidgrids.builder.mappingDialog.cancel", "Cancel")
1848
+ }), /* @__PURE__ */ jsx(Button, {
1849
+ onClick: handleSave,
1850
+ disabled: !isFormValid,
1851
+ children: tr("fluidgrids.builder.mappingDialog.applyMapping", "Apply Mapping")
1852
+ })]
1853
+ })]
1854
+ })] });
1855
+ if (stable) {
1856
+ const tabs = [
1857
+ {
1858
+ value: "builder",
1859
+ label: tr("fluidgrids.builder.mappingDialog.tabBuilder", "Builder"),
1860
+ icon: WandSparkles,
1861
+ testId: "fluidgrids-mapping-tab-builder"
1862
+ },
1863
+ {
1864
+ value: "examples",
1865
+ label: tr("fluidgrids.builder.mappingDialog.tabExamples", "Examples"),
1866
+ icon: BookOpen,
1867
+ testId: "fluidgrids-mapping-tab-examples"
1868
+ },
1869
+ {
1870
+ value: "editor",
1871
+ label: tr("fluidgrids.builder.mappingDialog.tabEditor", "Editor"),
1872
+ icon: CodeXml,
1873
+ testId: "fluidgrids-mapping-tab-editor"
1874
+ },
1875
+ {
1876
+ value: "help",
1877
+ label: tr("fluidgrids.builder.mappingDialog.tabHelp", "Help"),
1878
+ icon: CircleQuestionMark,
1879
+ testId: "fluidgrids-mapping-tab-help"
1880
+ }
1881
+ ];
1882
+ return /* @__PURE__ */ jsx(TabbedDialog, {
1883
+ open,
1884
+ onOpenChange,
1885
+ children: /* @__PURE__ */ jsxs(TabbedDialogContent, {
1886
+ size: "form",
1887
+ className: "z-[100002] sm:max-w-[700px]",
1888
+ overlayClassName: "z-[100001]",
1889
+ onOpenAutoFocus: focusDialogOnOpen,
1890
+ "data-testid": "fluidgrids-mapping-dialog",
1891
+ children: [
1892
+ /* @__PURE__ */ jsx(TabbedDialogHeader, {
1893
+ title,
1894
+ description,
1895
+ closeLabel: tr("fluidgrids.ui.dialog.closeLabel", "Close")
1896
+ }),
1897
+ /* @__PURE__ */ jsx("div", {
1898
+ className: "shrink-0 border-b border-border-subtle px-5 py-3",
1899
+ children: /* @__PURE__ */ jsx("div", {
1900
+ className: "p-3 bg-[var(--color-bg-accent)]/10 rounded-md border border-[var(--color-border-accent)]",
1901
+ children: targetFieldControls
1902
+ })
1903
+ }),
1904
+ /* @__PURE__ */ jsx(TabbedDialogTabs, {
1905
+ tabs,
1906
+ value: activeTab,
1907
+ onValueChange: setActiveTab,
1908
+ "aria-label": title,
1909
+ renderPanel: (tab) => /* @__PURE__ */ jsx("div", {
1910
+ className: "space-y-4",
1911
+ children: tabPanels[tab]
1912
+ })
1913
+ }),
1914
+ /* @__PURE__ */ jsx(TabbedDialogFooter, {
1915
+ className: "block",
1916
+ children: footerContent
1917
+ })
1918
+ ]
1919
+ })
1920
+ });
1921
+ }
1922
+ return createPortal(/* @__PURE__ */ jsx("div", {
1923
+ className: "fixed inset-0 bg-bg-overlay z-[100001] flex items-center justify-center",
1924
+ onClick: () => onOpenChange(false),
1925
+ children: /* @__PURE__ */ jsxs("div", {
1926
+ className: "bg-surface dark:bg-surface z-[100002] flex flex-col w-[700px] max-w-[95vw] max-h-[90vh] rounded-lg overflow-hidden pointer-events-auto shadow-xl",
1927
+ onClick: (e) => e.stopPropagation(),
1928
+ children: [
1929
+ /* @__PURE__ */ jsxs("div", {
1930
+ className: "flex justify-between items-start p-6 border-b",
1931
+ children: [/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("h2", {
1932
+ className: "text-lg font-semibold",
1933
+ children: title
1934
+ }), /* @__PURE__ */ jsx("p", {
1935
+ className: "text-sm text-muted-foreground mt-1",
1936
+ children: description
1937
+ })] }), /* @__PURE__ */ jsx("button", {
1938
+ onClick: () => onOpenChange(false),
1939
+ className: "rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
1940
+ children: /* @__PURE__ */ jsx(X, { className: "h-4 w-4" })
1941
+ })]
1942
+ }),
1943
+ /* @__PURE__ */ jsxs("div", {
1944
+ className: "flex-1 overflow-y-auto p-6",
1945
+ children: [/* @__PURE__ */ jsx("div", {
1946
+ className: "mb-4 p-3 bg-[var(--color-bg-accent)]/10 rounded-md border border-[var(--color-border-accent)]",
1947
+ children: targetFieldControls
1948
+ }), /* @__PURE__ */ jsxs(Tabs, {
1949
+ value: activeTab,
1950
+ onValueChange: setActiveTab,
1951
+ className: "w-full",
1952
+ children: [
1953
+ /* @__PURE__ */ jsxs(TabsList, {
1954
+ className: "grid w-full grid-cols-4",
1955
+ children: [
1956
+ /* @__PURE__ */ jsx(TabsTrigger, {
1957
+ value: "builder",
1958
+ children: tr("fluidgrids.builder.mappingDialog.tabBuilder", "Builder")
1959
+ }),
1960
+ /* @__PURE__ */ jsx(TabsTrigger, {
1961
+ value: "examples",
1962
+ children: tr("fluidgrids.builder.mappingDialog.tabExamples", "Examples")
1963
+ }),
1964
+ /* @__PURE__ */ jsx(TabsTrigger, {
1965
+ value: "editor",
1966
+ children: tr("fluidgrids.builder.mappingDialog.tabEditor", "Editor")
1967
+ }),
1968
+ /* @__PURE__ */ jsx(TabsTrigger, {
1969
+ value: "help",
1970
+ children: tr("fluidgrids.builder.mappingDialog.tabHelp", "Help")
1971
+ })
1972
+ ]
1973
+ }),
1974
+ /* @__PURE__ */ jsx(TabsContent, {
1975
+ value: "builder",
1976
+ className: "space-y-4 mt-4",
1977
+ children: tabPanels.builder
1978
+ }),
1979
+ /* @__PURE__ */ jsx(TabsContent, {
1980
+ value: "examples",
1981
+ className: "space-y-4 mt-4",
1982
+ children: tabPanels.examples
1983
+ }),
1984
+ /* @__PURE__ */ jsx(TabsContent, {
1985
+ value: "editor",
1986
+ className: "space-y-4 mt-4",
1987
+ children: tabPanels.editor
1988
+ }),
1989
+ /* @__PURE__ */ jsx(TabsContent, {
1990
+ value: "help",
1991
+ className: "space-y-4 mt-4",
1992
+ children: tabPanels.help
1993
+ })
1994
+ ]
1995
+ })]
1996
+ }),
1997
+ /* @__PURE__ */ jsx("div", {
1998
+ className: "p-6 border-t",
1999
+ children: footerContent
2000
+ })
2001
+ ]
2002
+ })
2003
+ }), document.body);
2004
+ }
2005
+
2006
+ // src/builder/components/lib/mapping-utils.ts
2007
+ const DEFAULT_CONFIG = {
2008
+ timeout: 5e3,
2009
+ maxTemplateLength: 1e4,
2010
+ debug: false
2011
+ };
2012
+ /**
2013
+ * Built-ins available to `${...}` mapping expressions: the shared frozen
2014
+ * facades (see safe-expression.ts), plus a console that forwards warnings
2015
+ * and errors to the developer console.
2016
+ */
2017
+ const SAFE_GLOBALS = {
2018
+ ...SAFE_EXPRESSION_GLOBALS,
2019
+ console: Object.freeze({
2020
+ log: (..._args) => {},
2021
+ error: (...args) => console.error("[Mapper]", ...args),
2022
+ warn: (...args) => console.warn("[Mapper]", ...args)
2023
+ })
2024
+ };
2025
+ /**
2026
+ * Parse a template string to extract the expression
2027
+ * Template literals must be in the format: ${expression}
2028
+ */
2029
+ function parseTemplate(template) {
2030
+ if (typeof template !== "string") return {
2031
+ isTemplate: false,
2032
+ expression: null,
2033
+ error: null
2034
+ };
2035
+ const match = template.match(/^\$\{(.+)\}$/s);
2036
+ if (!match) return {
2037
+ isTemplate: false,
2038
+ expression: null,
2039
+ error: null
2040
+ };
2041
+ const expression = match[1].trim();
2042
+ if (!expression) return {
2043
+ isTemplate: true,
2044
+ expression: null,
2045
+ error: "Empty template expression"
2046
+ };
2047
+ return {
2048
+ isTemplate: true,
2049
+ expression,
2050
+ error: null
2051
+ };
2052
+ }
2053
+ /**
2054
+ * Build the sandbox with safe globals and scope variables
2055
+ */
2056
+ function buildSandbox(scope) {
2057
+ return {
2058
+ ...SAFE_GLOBALS,
2059
+ output: scope.output,
2060
+ TriggerInput: scope.TriggerInput,
2061
+ WorkflowState: scope.WorkflowState,
2062
+ RunContext: scope.RunContext,
2063
+ item: scope.item,
2064
+ index: scope.index
2065
+ };
2066
+ }
2067
+ /**
2068
+ * Evaluate a mapping expression with the safe expression interpreter
2069
+ * (BOFF-16938). The expression is parsed and walked, never compiled as
2070
+ * JavaScript, so it can reach only the mapping scope and the safe built-ins.
2071
+ */
2072
+ async function evaluateExpression(expression, scope, config = DEFAULT_CONFIG) {
2073
+ try {
2074
+ return evaluateSafeExpression(expression, buildSandbox(scope));
2075
+ } catch (error) {
2076
+ if (config.debug) console.error("[Mapper] Expression evaluation error:", error);
2077
+ throw error;
2078
+ }
2079
+ }
2080
+ /**
2081
+ * Map a definition object using template literals
2082
+ * This is the main entry point for applying mappings
2083
+ */
2084
+ async function mapDefinition(definition, scope, config = DEFAULT_CONFIG) {
2085
+ if (definition === null || definition === void 0) return definition;
2086
+ if (typeof definition !== "object" && typeof definition !== "string") return definition;
2087
+ if (typeof definition === "string") {
2088
+ const parseResult = parseTemplate(definition);
2089
+ if (!parseResult.isTemplate) return definition;
2090
+ if (parseResult.error) throw new Error(parseResult.error);
2091
+ return evaluateExpression(parseResult.expression, scope, config);
2092
+ }
2093
+ if (Array.isArray(definition)) return await Promise.all(definition.map((item) => mapDefinition(item, scope, config)));
2094
+ const result = {};
2095
+ for (const key of Object.keys(definition)) result[key] = await mapDefinition(definition[key], scope, config);
2096
+ return result;
2097
+ }
2098
+ /**
2099
+ * Validate a mapping definition for syntax errors
2100
+ * Returns an array of error messages
2101
+ */
2102
+ function validateMapping(definition, path = "root") {
2103
+ const errors = [];
2104
+ if (definition === null || definition === void 0) return errors;
2105
+ if (typeof definition === "string") {
2106
+ const parseResult = parseTemplate(definition);
2107
+ if (parseResult.isTemplate && parseResult.error) errors.push(`${path}: ${parseResult.error}`);
2108
+ return errors;
2109
+ }
2110
+ if (Array.isArray(definition)) {
2111
+ definition.forEach((item, index) => {
2112
+ errors.push(...validateMapping(item, `${path}[${index}]`));
2113
+ });
2114
+ return errors;
2115
+ }
2116
+ if (typeof definition === "object") for (const key of Object.keys(definition)) errors.push(...validateMapping(definition[key], `${path}.${key}`));
2117
+ return errors;
2118
+ }
2119
+ /**
2120
+ * Generate default mapping between source and target schemas
2121
+ */
2122
+ function generateDefaultMapping(sourceSchema, sourceNode, sourceOperation, targetSchema, targetNode, targetOperation) {
2123
+ const mapping = {};
2124
+ const sourceReturnTypeName = getReturnTypeForOperation(sourceNode, sourceOperation);
2125
+ let sourceOutputType = null;
2126
+ if (sourceReturnTypeName) sourceOutputType = sourceSchema.types[sourceReturnTypeName];
2127
+ else {
2128
+ let sourceOperationField = null;
2129
+ if (sourceSchema.queryType && sourceSchema.types[sourceSchema.queryType]?.fields[sourceOperation]) sourceOperationField = sourceSchema.types[sourceSchema.queryType].fields[sourceOperation];
2130
+ else if (sourceSchema.mutationType && sourceSchema.types[sourceSchema.mutationType]?.fields[sourceOperation]) sourceOperationField = sourceSchema.types[sourceSchema.mutationType].fields[sourceOperation];
2131
+ if (sourceOperationField) {
2132
+ const sourceOutputTypeName = sourceOperationField.type;
2133
+ sourceOutputType = sourceSchema.types[sourceOutputTypeName];
2134
+ }
2135
+ }
2136
+ const targetInputTypeName = getInputTypeForOperation(targetNode, targetOperation);
2137
+ const targetInputType = targetInputTypeName ? targetSchema.types[targetInputTypeName] : null;
2138
+ if (!sourceOutputType || !targetInputType) return mapping;
2139
+ const sourceFields = sourceOutputType.fields || {};
2140
+ const targetFields = targetInputType.inputFields || targetInputType.fields || {};
2141
+ const addMapping = (path, sourcePath) => {
2142
+ const templateValue = `\${output.${sourcePath}}`;
2143
+ if (path.includes(".")) {
2144
+ const pathParts = path.split(".");
2145
+ let currentObj = mapping;
2146
+ for (let i = 0; i < pathParts.length - 1; i++) {
2147
+ const part = pathParts[i];
2148
+ if (!currentObj[part]) currentObj[part] = {};
2149
+ currentObj = currentObj[part];
2150
+ }
2151
+ currentObj[pathParts[pathParts.length - 1]] = templateValue;
2152
+ } else mapping[path] = templateValue;
2153
+ };
2154
+ const processFields = (fields, parentPath = "") => {
2155
+ for (const fieldName in fields) {
2156
+ const field = fields[fieldName];
2157
+ const fullPath = parentPath ? `${parentPath}.${fieldName}` : fieldName;
2158
+ if (field.type && targetSchema.types[field.type] && (targetSchema.types[field.type].kind === "type" || targetSchema.types[field.type].kind === "input")) {
2159
+ const nestedFields = targetSchema.types[field.type].fields || targetSchema.types[field.type].inputFields || {};
2160
+ processFields(nestedFields, fullPath);
2161
+ } else {
2162
+ if (sourceFields[fieldName]) {
2163
+ addMapping(fullPath, fieldName);
2164
+ continue;
2165
+ }
2166
+ const lowerTargetField = fieldName.toLowerCase();
2167
+ for (const sourceFieldName in sourceFields) if (sourceFieldName.toLowerCase() === lowerTargetField) {
2168
+ addMapping(fullPath, sourceFieldName);
2169
+ break;
2170
+ }
2171
+ }
2172
+ }
2173
+ };
2174
+ processFields(targetFields);
2175
+ return mapping;
2176
+ }
2177
+ /**
2178
+ * Apply a mapping to input data using the new template literal syntax
2179
+ * This is used for preview/testing in the UI
2180
+ */
2181
+ async function applyMapping(mapping, inputData, config = DEFAULT_CONFIG) {
2182
+ return await mapDefinition(mapping, {
2183
+ output: inputData,
2184
+ TriggerInput: {},
2185
+ WorkflowState: {},
2186
+ RunContext: {
2187
+ runId: "preview-run",
2188
+ workflowKey: "preview-workflow",
2189
+ version: "1.0.0",
2190
+ tenantId: "preview-tenant",
2191
+ workspaceId: "preview-workspace",
2192
+ triggeredAt: (/* @__PURE__ */ new Date()).toISOString()
2193
+ }
2194
+ }, config);
2195
+ }
2196
+
2197
+ // src/builder/components/mapper/visual-mapper.tsx
2198
+ const nodeTypes = {
2199
+ schemaNode: SchemaNode,
2200
+ nodeGroup: NodeGroup
2201
+ };
2202
+ const edgeTypes = { mappingEdge: MappingEdge };
2203
+ function isSchemaNodeData(data) {
2204
+ return data !== null && typeof data === "object" && "path" in data && "type" in data && "side" in data;
2205
+ }
2206
+ /**
2207
+ * Detect the mapping type from a template literal expression
2208
+ */
2209
+ function detectMappingType(value) {
2210
+ if (typeof value !== "string") return "direct";
2211
+ const parseResult = parseTemplate(value);
2212
+ if (!parseResult.isTemplate) return "direct";
2213
+ const expr = parseResult.expression || "";
2214
+ if (expr.includes(".map(") || expr.includes(".filter(") || expr.includes(".reduce(") || expr.includes(".find(") || expr.includes(".some(") || expr.includes(".every(") || expr.includes(".flat(") || expr.includes(".flatMap(") || expr.includes(".sort(")) return "array";
2215
+ if (expr.includes("Object.keys(") || expr.includes("Object.values(") || expr.includes("Object.entries(") || expr.includes("Object.assign(") || expr.includes("Object.fromEntries(") || expr.startsWith("({") || expr.startsWith("{ ...")) return "object";
2216
+ if (expr.startsWith("parseInt(") || expr.startsWith("parseFloat(") || expr.startsWith("String(") || expr.startsWith("Boolean(") || expr.startsWith("Number(")) return "cast";
2217
+ if (expr.includes("TriggerInput.") || expr.includes("WorkflowState.") || expr.includes("RunContext.")) return "context";
2218
+ if (expr.includes(".toUpperCase()") || expr.includes(".toLowerCase()") || expr.includes(".trim()") || expr.includes(".split(") || expr.includes(".join(") || expr.includes(".replace(") || expr.includes(".substring(") || expr.includes(".slice(")) return "transform";
2219
+ if (expr.includes(" + ") || expr.includes(" - ") || expr.includes(" * ") || expr.includes(" / ") || expr.includes(" ? ") || expr.includes(" && ") || expr.includes(" || ") || expr.includes(" ?? ") || expr.includes("Math.")) return "expression";
2220
+ return "direct";
2221
+ }
2222
+ function VisualMapperContent({ sourceSchema, targetSchema, sourceNode, sourceOperation, targetNode, targetOperation, mapping, onMappingChange }) {
2223
+ const { toast } = useToast();
2224
+ const tr = useTr();
2225
+ const reactFlowWrapper = useRef(null);
2226
+ const [selectedSourceNode, setSelectedSourceNode] = useState(null);
2227
+ const [selectedTargetNode, setSelectedTargetNode] = useState(null);
2228
+ const [mappingDialogOpen, setMappingDialogOpen] = useState(false);
2229
+ const [currentMappingType, setCurrentMappingType] = useState("expression");
2230
+ const [nodes, setNodes, onNodesChange] = useNodesState([]);
2231
+ const [edges, setEdges, onEdgesChange] = useEdgesState([]);
2232
+ useEffect(() => {
2233
+ if (sourceSchema && targetSchema && sourceNode && sourceOperation && targetNode && targetOperation) {
2234
+ const { nodes: generatedNodes } = generateSchemaNodes(sourceSchema, sourceNode, sourceOperation, targetSchema, targetNode, targetOperation);
2235
+ if (generatedNodes.length === 0) toast({
2236
+ title: tr("fluidgrids.builder.visualMapper.noFieldsFoundTitle", "No fields found"),
2237
+ description: tr("fluidgrids.builder.visualMapper.noFieldsFoundDescription", "Could not find fields to map between these nodes and operations."),
2238
+ variant: "destructive"
2239
+ });
2240
+ else {
2241
+ setNodes(generatedNodes);
2242
+ setTimeout(() => {
2243
+ document.querySelector(".react-flow__controls-fitview")?.dispatchEvent(new MouseEvent("click", { bubbles: true }));
2244
+ }, 100);
2245
+ }
2246
+ }
2247
+ }, [
2248
+ sourceSchema,
2249
+ targetSchema,
2250
+ sourceNode,
2251
+ sourceOperation,
2252
+ targetNode,
2253
+ targetOperation,
2254
+ setNodes,
2255
+ toast,
2256
+ tr
2257
+ ]);
2258
+ useEffect(() => {
2259
+ const newEdges = [];
2260
+ const processMapping = (obj, parentPath = "") => {
2261
+ for (const key in obj) {
2262
+ const value = obj[key];
2263
+ const currentPath = parentPath ? `${parentPath}.${key}` : key;
2264
+ if (typeof value === "object" && value !== null && !Array.isArray(value)) processMapping(value, currentPath);
2265
+ else if (typeof value === "string") {
2266
+ const parseResult = parseTemplate(value);
2267
+ const mappingType = detectMappingType(value);
2268
+ const targetNodeObj = nodes.find((n) => isSchemaNodeData(n.data) && n.data.path === currentPath && n.data.side === "target");
2269
+ if (targetNodeObj && isSchemaNodeData(targetNodeObj.data)) {
2270
+ if (parseResult.isTemplate) {
2271
+ const simpleFieldMatch = (parseResult.expression || "").match(/^output\.([a-zA-Z0-9_.]+)$/);
2272
+ if (simpleFieldMatch && mappingType === "direct") {
2273
+ const sourcePath = simpleFieldMatch[1];
2274
+ const sourceNodeObj = nodes.find((n) => isSchemaNodeData(n.data) && n.data.path === sourcePath && n.data.side === "source");
2275
+ if (sourceNodeObj && isSchemaNodeData(sourceNodeObj.data)) {
2276
+ const isCompatible = areTypesCompatible(sourceNodeObj.data.type, targetNodeObj.data.type);
2277
+ newEdges.push({
2278
+ id: `${sourceNodeObj.id}-${targetNodeObj.id}`,
2279
+ source: sourceNodeObj.id,
2280
+ target: targetNodeObj.id,
2281
+ type: "mappingEdge",
2282
+ animated: true,
2283
+ data: {
2284
+ mappingType: "direct",
2285
+ isCompatible,
2286
+ color: compatibilityColor(isCompatible)
2287
+ }
2288
+ });
2289
+ continue;
2290
+ }
2291
+ }
2292
+ newEdges.push({
2293
+ id: `mapping-${currentPath}`,
2294
+ source: "virtual-source",
2295
+ target: targetNodeObj.id,
2296
+ type: "mappingEdge",
2297
+ animated: true,
2298
+ data: {
2299
+ mappingType,
2300
+ expression: value,
2301
+ color: mappingTypeColor(mappingType)
2302
+ }
2303
+ });
2304
+ }
2305
+ }
2306
+ }
2307
+ }
2308
+ };
2309
+ processMapping(mapping);
2310
+ setEdges(newEdges);
2311
+ }, [
2312
+ mapping,
2313
+ nodes,
2314
+ setEdges
2315
+ ]);
2316
+ const onConnect = useCallback((connection) => {
2317
+ const sourceNodeObj = nodes.find((n) => n.id === connection.source);
2318
+ const targetNodeObj = nodes.find((n) => n.id === connection.target);
2319
+ if (sourceNodeObj && targetNodeObj && isSchemaNodeData(sourceNodeObj.data) && isSchemaNodeData(targetNodeObj.data) && sourceNodeObj.data.side === "source" && targetNodeObj.data.side === "target") {
2320
+ const sourceType = sourceNodeObj.data.type;
2321
+ const targetType = targetNodeObj.data.type;
2322
+ const isCompatible = areTypesCompatible(sourceType, targetType);
2323
+ const newEdge = {
2324
+ ...connection,
2325
+ type: "mappingEdge",
2326
+ animated: true,
2327
+ data: {
2328
+ mappingType: "direct",
2329
+ isCompatible,
2330
+ color: compatibilityColor(isCompatible)
2331
+ }
2332
+ };
2333
+ setEdges((eds) => addEdge(newEdge, eds));
2334
+ const updatedMapping = { ...mapping };
2335
+ const sourcePath = sourceNodeObj.data.path;
2336
+ const targetPath = targetNodeObj.data.path;
2337
+ const templateValue = `\${output.${sourcePath}}`;
2338
+ if (targetPath.includes(".")) {
2339
+ const pathParts = targetPath.split(".");
2340
+ let currentObj = updatedMapping;
2341
+ for (let i = 0; i < pathParts.length - 1; i++) {
2342
+ const part = pathParts[i];
2343
+ if (!currentObj[part]) currentObj[part] = {};
2344
+ else if (typeof currentObj[part] !== "object") currentObj[part] = {};
2345
+ currentObj = currentObj[part];
2346
+ }
2347
+ currentObj[pathParts[pathParts.length - 1]] = templateValue;
2348
+ } else updatedMapping[targetPath] = templateValue;
2349
+ onMappingChange(updatedMapping);
2350
+ if (isCompatible) toast({
2351
+ title: tr("fluidgrids.builder.visualMapper.mappingCreatedTitle", "Mapping created"),
2352
+ description: `Mapped ${sourcePath} (${sourceType}) to ${targetPath} (${targetType})`
2353
+ });
2354
+ else toast({
2355
+ title: tr("fluidgrids.builder.visualMapper.typeMismatchTitle", "Type mismatch warning"),
2356
+ description: `Mapped ${sourcePath} (${sourceType}) to ${targetPath} (${targetType}). Types may not be compatible.`,
2357
+ variant: "destructive"
2358
+ });
2359
+ } else toast({
2360
+ title: tr("fluidgrids.builder.visualMapper.invalidMappingTitle", "Invalid mapping"),
2361
+ description: tr("fluidgrids.builder.visualMapper.invalidMappingDescription", "You can only map from source to target fields"),
2362
+ variant: "destructive"
2363
+ });
2364
+ }, [
2365
+ nodes,
2366
+ mapping,
2367
+ onMappingChange,
2368
+ toast,
2369
+ tr,
2370
+ setEdges
2371
+ ]);
2372
+ const onEdgeDelete = useCallback((edge) => {
2373
+ const targetNodeObj = nodes.find((n) => n.id === edge.target);
2374
+ if (targetNodeObj && isSchemaNodeData(targetNodeObj.data)) {
2375
+ const targetPath = targetNodeObj.data.path;
2376
+ const updatedMapping = { ...mapping };
2377
+ if (targetPath.includes(".")) {
2378
+ const pathParts = targetPath.split(".");
2379
+ let currentObj = updatedMapping;
2380
+ let parentObj = null;
2381
+ let lastPart = null;
2382
+ for (let i = 0; i < pathParts.length - 1; i++) {
2383
+ const part = pathParts[i];
2384
+ if (!currentObj[part] || typeof currentObj[part] !== "object") return;
2385
+ parentObj = currentObj;
2386
+ currentObj = currentObj[part];
2387
+ lastPart = pathParts[i + 1];
2388
+ }
2389
+ if (parentObj && lastPart) {
2390
+ delete currentObj[pathParts[pathParts.length - 1]];
2391
+ if (Object.keys(currentObj).length === 0 && pathParts.length > 1) delete parentObj[pathParts[pathParts.length - 2]];
2392
+ }
2393
+ } else delete updatedMapping[targetPath];
2394
+ onMappingChange(updatedMapping);
2395
+ }
2396
+ setEdges((eds) => eds.filter((e) => e.id !== edge.id));
2397
+ }, [
2398
+ nodes,
2399
+ mapping,
2400
+ onMappingChange,
2401
+ setEdges
2402
+ ]);
2403
+ const onNodeClick = useCallback((_event, node) => {
2404
+ if (node.data && typeof node.data === "object" && isSchemaNodeData(node.data)) {
2405
+ const schemaNode = {
2406
+ id: node.id,
2407
+ data: node.data
2408
+ };
2409
+ if (schemaNode.data.side === "source") setSelectedSourceNode(schemaNode);
2410
+ else if (schemaNode.data.side === "target") setSelectedTargetNode(schemaNode);
2411
+ }
2412
+ }, []);
2413
+ const openMappingDialog = (type) => {
2414
+ setCurrentMappingType(type);
2415
+ setMappingDialogOpen(true);
2416
+ };
2417
+ const handleSaveMappingDialog = (expression, targetFieldName) => {
2418
+ const targetPath = targetFieldName || selectedTargetNode?.data?.path;
2419
+ if (!targetPath) {
2420
+ toast({
2421
+ title: tr("fluidgrids.builder.visualMapper.noTargetFieldTitle", "No target field specified"),
2422
+ description: tr("fluidgrids.builder.visualMapper.noTargetFieldDescription", "Please enter a target field name or select a target field in the visual mapper"),
2423
+ variant: "destructive"
2424
+ });
2425
+ return;
2426
+ }
2427
+ const updatedMapping = { ...mapping };
2428
+ if (targetPath.includes(".")) {
2429
+ const pathParts = targetPath.split(".");
2430
+ let currentObj = updatedMapping;
2431
+ for (let i = 0; i < pathParts.length - 1; i++) {
2432
+ const part = pathParts[i];
2433
+ if (!currentObj[part]) currentObj[part] = {};
2434
+ else if (typeof currentObj[part] !== "object") currentObj[part] = {};
2435
+ currentObj = currentObj[part];
2436
+ }
2437
+ currentObj[pathParts[pathParts.length - 1]] = expression;
2438
+ } else updatedMapping[targetPath] = expression;
2439
+ onMappingChange(updatedMapping);
2440
+ const mappingType = detectMappingType(expression);
2441
+ toast({
2442
+ title: `${mappingType.charAt(0).toUpperCase() + mappingType.slice(1)} mapping created`,
2443
+ description: `${tr("fluidgrids.builder.visualMapper.appliedMappingTo", "Applied mapping to")} ${targetPath}`
2444
+ });
2445
+ };
2446
+ const mappingTypeItems = [
2447
+ {
2448
+ type: "direct",
2449
+ label: tr("fluidgrids.builder.visualMapper.typeDirectLabel", "Direct"),
2450
+ icon: Type,
2451
+ description: tr("fluidgrids.builder.visualMapper.typeDirectDescription", "Simple field access")
2452
+ },
2453
+ {
2454
+ type: "expression",
2455
+ label: tr("fluidgrids.builder.visualMapper.typeExpressionLabel", "Expression"),
2456
+ icon: Code,
2457
+ description: tr("fluidgrids.builder.visualMapper.typeExpressionDescription", "Custom JavaScript expression")
2458
+ },
2459
+ {
2460
+ type: "transform",
2461
+ label: tr("fluidgrids.builder.visualMapper.typeTransformLabel", "Transform"),
2462
+ icon: Type,
2463
+ description: tr("fluidgrids.builder.visualMapper.typeTransformDescription", "String transformations")
2464
+ },
2465
+ {
2466
+ type: "cast",
2467
+ label: tr("fluidgrids.builder.visualMapper.typeCastLabel", "Cast"),
2468
+ icon: Hash,
2469
+ description: tr("fluidgrids.builder.visualMapper.typeCastDescription", "Type conversions")
2470
+ },
2471
+ {
2472
+ type: "array",
2473
+ label: tr("fluidgrids.builder.visualMapper.typeArrayLabel", "Array"),
2474
+ icon: List,
2475
+ description: tr("fluidgrids.builder.visualMapper.typeArrayDescription", "Array operations (map, filter, reduce)")
2476
+ },
2477
+ {
2478
+ type: "object",
2479
+ label: tr("fluidgrids.builder.visualMapper.typeObjectLabel", "Object"),
2480
+ icon: Braces,
2481
+ description: tr("fluidgrids.builder.visualMapper.typeObjectDescription", "Object manipulation")
2482
+ },
2483
+ {
2484
+ type: "context",
2485
+ label: tr("fluidgrids.builder.visualMapper.typeContextLabel", "Context"),
2486
+ icon: Workflow,
2487
+ description: tr("fluidgrids.builder.visualMapper.typeContextDescription", "Workflow state access")
2488
+ }
2489
+ ];
2490
+ return /* @__PURE__ */ jsxs("div", {
2491
+ className: "h-[550px] w-full border rounded-md",
2492
+ ref: reactFlowWrapper,
2493
+ children: [/* @__PURE__ */ jsxs(ReactFlow, {
2494
+ nodes,
2495
+ edges,
2496
+ onNodesChange,
2497
+ onEdgesChange,
2498
+ onConnect,
2499
+ onEdgeClick: (_, edge) => onEdgeDelete(edge),
2500
+ onNodeClick,
2501
+ nodeTypes,
2502
+ edgeTypes,
2503
+ fitView: true,
2504
+ fitViewOptions: { padding: .2 },
2505
+ minZoom: .4,
2506
+ maxZoom: 1.5,
2507
+ defaultViewport: {
2508
+ x: 0,
2509
+ y: 0,
2510
+ zoom: .7
2511
+ },
2512
+ attributionPosition: "bottom-right",
2513
+ children: [
2514
+ /* @__PURE__ */ jsx(Controls, {}),
2515
+ /* @__PURE__ */ jsx(MiniMap, {}),
2516
+ /* @__PURE__ */ jsx(Background, {
2517
+ gap: 12,
2518
+ size: 1
2519
+ }),
2520
+ /* @__PURE__ */ jsx(Panel, {
2521
+ position: "top-right",
2522
+ children: /* @__PURE__ */ jsxs("div", {
2523
+ className: "flex flex-col gap-2",
2524
+ children: [/* @__PURE__ */ jsxs(DropdownMenu, { children: [/* @__PURE__ */ jsx(DropdownMenuTrigger, {
2525
+ asChild: true,
2526
+ children: /* @__PURE__ */ jsxs(Button, {
2527
+ variant: "outline",
2528
+ size: "sm",
2529
+ className: "flex items-center gap-1",
2530
+ children: [
2531
+ /* @__PURE__ */ jsx(PlusCircle, { className: "h-4 w-4" }),
2532
+ tr("fluidgrids.builder.visualMapper.addMapping", "Add Mapping"),
2533
+ /* @__PURE__ */ jsx(ChevronDown, { className: "h-3 w-3" })
2534
+ ]
2535
+ })
2536
+ }), /* @__PURE__ */ jsxs(DropdownMenuContent, {
2537
+ align: "end",
2538
+ className: "w-56 z-[100000]",
2539
+ children: [
2540
+ /* @__PURE__ */ jsx(DropdownMenuLabel, { children: tr("fluidgrids.builder.visualMapper.mappingTypes", "Mapping Types") }),
2541
+ /* @__PURE__ */ jsx(DropdownMenuSeparator, {}),
2542
+ mappingTypeItems.map((item) => /* @__PURE__ */ jsxs(DropdownMenuItem, {
2543
+ onClick: () => openMappingDialog(item.type),
2544
+ className: "flex items-start gap-2 cursor-pointer",
2545
+ children: [/* @__PURE__ */ jsx(item.icon, {
2546
+ className: "h-4 w-4 mt-0.5",
2547
+ style: { color: mappingTypeColor(item.type) }
2548
+ }), /* @__PURE__ */ jsxs("div", {
2549
+ className: "flex flex-col",
2550
+ children: [/* @__PURE__ */ jsx("span", {
2551
+ className: "font-medium",
2552
+ children: item.label
2553
+ }), /* @__PURE__ */ jsx("span", {
2554
+ className: "text-xs text-muted-foreground",
2555
+ children: item.description
2556
+ })]
2557
+ })]
2558
+ }, item.type))
2559
+ ]
2560
+ })] }), selectedTargetNode && /* @__PURE__ */ jsxs("div", {
2561
+ className: "p-2 bg-muted rounded-md text-xs",
2562
+ children: [/* @__PURE__ */ jsx("div", {
2563
+ className: "text-muted-foreground",
2564
+ children: tr("fluidgrids.builder.visualMapper.targetIndicator", "Target:")
2565
+ }), /* @__PURE__ */ jsx("div", {
2566
+ className: "font-mono",
2567
+ children: selectedTargetNode.data.path
2568
+ })]
2569
+ })]
2570
+ })
2571
+ })
2572
+ ]
2573
+ }), /* @__PURE__ */ jsx(MappingDialog, {
2574
+ open: mappingDialogOpen,
2575
+ onOpenChange: setMappingDialogOpen,
2576
+ onSave: handleSaveMappingDialog,
2577
+ mappingType: currentMappingType,
2578
+ sourceField: selectedSourceNode?.data?.path,
2579
+ targetField: selectedTargetNode?.data?.path,
2580
+ sourceSchema,
2581
+ sourceOperation,
2582
+ targetSchema,
2583
+ targetOperation
2584
+ })]
2585
+ });
2586
+ }
2587
+ function VisualMapper(props) {
2588
+ return /* @__PURE__ */ jsx(ReactFlowProvider, { children: /* @__PURE__ */ jsx(VisualMapperContent, { ...props }) });
2589
+ }
2590
+
2591
+ // src/builder/components/mapper/code-editor.tsx
2592
+ function CodeEditor({ value, onChange, language: _language = "json", onBlur }) {
2593
+ const editorRef = useRef(null);
2594
+ useEffect(() => {
2595
+ if (editorRef.current) editorRef.current.value = value;
2596
+ }, [value]);
2597
+ return /* @__PURE__ */ jsx(Card, {
2598
+ className: "relative ",
2599
+ children: /* @__PURE__ */ jsx("textarea", {
2600
+ ref: editorRef,
2601
+ className: "w-full h-[400px] p-4 font-mono bg-surface text-sm resize-none focus:outline-none focus:ring-2 focus:ring-primary transition-shadow duration-200",
2602
+ defaultValue: value,
2603
+ onChange,
2604
+ spellCheck: false,
2605
+ onBlur
2606
+ })
2607
+ });
2608
+ }
2609
+
2610
+ // src/builder/components/mapper/mapping-preview.tsx
2611
+ function MappingPreview({ input, mapping, output }) {
2612
+ const tr = useTr();
2613
+ const generatedOutput = useMemo(() => {
2614
+ try {
2615
+ return applyMapping(mapping, input);
2616
+ } catch (error) {
2617
+ console.error("Error applying mapping:", error);
2618
+ return {
2619
+ error: true,
2620
+ message: error instanceof Error ? error.message : tr("fluidgrids.builder.mappingPreview.unknownError", "Unknown error occurred while applying mapping"),
2621
+ input
2622
+ };
2623
+ }
2624
+ }, [
2625
+ input,
2626
+ mapping,
2627
+ tr
2628
+ ]);
2629
+ return /* @__PURE__ */ jsxs(Tabs, {
2630
+ defaultValue: "input",
2631
+ children: [
2632
+ /* @__PURE__ */ jsxs(TabsList, {
2633
+ className: "mb-4",
2634
+ children: [
2635
+ /* @__PURE__ */ jsx(TabsTrigger, {
2636
+ value: "input",
2637
+ children: tr("fluidgrids.builder.mappingPreview.tabInput", "Input")
2638
+ }),
2639
+ /* @__PURE__ */ jsx(TabsTrigger, {
2640
+ value: "mapping",
2641
+ children: tr("fluidgrids.builder.mappingPreview.tabMapping", "Mapping")
2642
+ }),
2643
+ /* @__PURE__ */ jsx(TabsTrigger, {
2644
+ value: "output",
2645
+ children: tr("fluidgrids.builder.mappingPreview.tabOutput", "Output")
2646
+ })
2647
+ ]
2648
+ }),
2649
+ /* @__PURE__ */ jsx(TabsContent, {
2650
+ value: "input",
2651
+ children: /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(CardContent, {
2652
+ className: "p-4",
2653
+ children: /* @__PURE__ */ jsx("pre", {
2654
+ className: "text-sm overflow-auto max-h-[400px]",
2655
+ children: JSON.stringify(input, null, 2)
2656
+ })
2657
+ }) })
2658
+ }),
2659
+ /* @__PURE__ */ jsx(TabsContent, {
2660
+ value: "mapping",
2661
+ children: /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(CardContent, {
2662
+ className: "p-4",
2663
+ children: /* @__PURE__ */ jsx("pre", {
2664
+ className: "text-sm overflow-auto max-h-[400px]",
2665
+ children: JSON.stringify(mapping, null, 2)
2666
+ })
2667
+ }) })
2668
+ }),
2669
+ /* @__PURE__ */ jsx(TabsContent, {
2670
+ value: "output",
2671
+ children: /* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(CardContent, {
2672
+ className: "p-4",
2673
+ children: /* @__PURE__ */ jsx("pre", {
2674
+ className: "text-sm overflow-auto max-h-[400px]",
2675
+ children: output ? JSON.stringify(output, null, 2) : generatedOutput ? JSON.stringify(generatedOutput, null, 2) : tr("fluidgrids.builder.mappingPreview.noOutput", "No output generated yet")
2676
+ })
2677
+ }) })
2678
+ })
2679
+ ]
2680
+ });
2681
+ }
2682
+
2683
+ // src/builder/components/mapper/mapping-editor.tsx
2684
+ function generateSampleValueForType(typeName, schema) {
2685
+ if (typeName.startsWith("[") && typeName.endsWith("]")) return [generateSampleValueForType(typeName.substring(1, typeName.length - 1).replace(/!$/, ""), schema)];
2686
+ const baseType = typeName.endsWith("!") ? typeName.slice(0, -1) : typeName;
2687
+ switch (baseType) {
2688
+ case "String": return "Sample string";
2689
+ case "Int": return 42;
2690
+ case "Float": return 3.14;
2691
+ case "Boolean": return true;
2692
+ case "ID": return "id-123456";
2693
+ default:
2694
+ if (schema.types[baseType]) {
2695
+ const type = schema.types[baseType];
2696
+ if (type.kind === "type" || type.kind === "input") {
2697
+ const obj = {};
2698
+ for (const fieldName in type.fields || {}) obj[fieldName] = generateSampleValueForType(type.fields[fieldName].type, schema);
2699
+ return obj;
2700
+ }
2701
+ if (type.kind === "enum") return `ENUM_${baseType}`;
2702
+ }
2703
+ return null;
2704
+ }
2705
+ }
2706
+ function generateSampleInput(schema, nodeType, operation) {
2707
+ const returnTypeName = getReturnTypeForOperation(nodeType, operation);
2708
+ if (!returnTypeName || !schema.types[returnTypeName]) return {};
2709
+ const returnType = schema.types[returnTypeName];
2710
+ const result = {};
2711
+ for (const fieldName in returnType.fields || {}) {
2712
+ const field = returnType.fields[fieldName];
2713
+ result[fieldName] = generateSampleValueForType(field.type, schema);
2714
+ }
2715
+ return result;
2716
+ }
2717
+ const EMPTY_MAPPING = {};
2718
+ function formatMapping(mapping) {
2719
+ return JSON.stringify(mapping, null, 2);
2720
+ }
2721
+ /**
2722
+ * Read the JSON editor's text as a mapping definition: a JSON object of
2723
+ * mapping values. `invalidJson` tells text that is not JSON apart from JSON
2724
+ * of the wrong shape.
2725
+ */
2726
+ function parseMappingText(text) {
2727
+ let parsed;
2728
+ try {
2729
+ parsed = JSON.parse(text);
2730
+ } catch (error) {
2731
+ return {
2732
+ ok: false,
2733
+ invalidJson: true,
2734
+ message: String(error)
2735
+ };
2736
+ }
2737
+ if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return {
2738
+ ok: false,
2739
+ invalidJson: false,
2740
+ message: "The mapping must be a JSON object of field mappings."
2741
+ };
2742
+ const mapping = toMappingDefinition(parsed);
2743
+ if (Object.keys(mapping).length !== Object.keys(parsed).length) return {
2744
+ ok: false,
2745
+ invalidJson: false,
2746
+ message: "Mapping values must be JSON (numbers must be finite)."
2747
+ };
2748
+ return {
2749
+ ok: true,
2750
+ mapping
2751
+ };
2752
+ }
2753
+ /**
2754
+ * The mapping the editor opens on: the stored one, or, for a connection that
2755
+ * maps nothing yet, the defaults matched by field name.
2756
+ */
2757
+ function initialEditorMapping(stored, generateDefaults) {
2758
+ if (Object.keys(stored).length > 0) return stored;
2759
+ return toMappingDefinition(generateDefaults());
2760
+ }
2761
+ function MappingEditor({ sourceSchema, targetSchema, sourceNode, sourceOperation, targetNode, targetOperation, className, storedMapping = EMPTY_MAPPING, onSaveMapping }) {
2762
+ const { toast } = useToast();
2763
+ const tr = useTr();
2764
+ const dataConfig = useDataConfig();
2765
+ const sourceLabel = dataConfig.nodes[sourceNode]?.displayName || sourceNode;
2766
+ const targetLabel = dataConfig.nodes[targetNode]?.displayName || targetNode;
2767
+ const [baseline, setBaseline] = useState(storedMapping);
2768
+ const [mappingJson, setMappingJson] = useState(() => initialEditorMapping(storedMapping, () => generateDefaultMapping(sourceSchema, sourceNode, sourceOperation, targetSchema, targetNode, targetOperation)));
2769
+ const [jsonDataString, setJsonDataString] = useState(() => formatMapping(mappingJson));
2770
+ const [jsonError, setJsonError] = useState(null);
2771
+ const [validationErrors, setValidationErrors] = useState(() => validateMapping(mappingJson));
2772
+ const [previewOutput, setPreviewOutput] = useState(null);
2773
+ const [isTestingMapping, setIsTestingMapping] = useState(false);
2774
+ const sampleInput = useMemo(() => generateSampleInput(sourceSchema, sourceNode, sourceOperation), [
2775
+ sourceSchema,
2776
+ sourceNode,
2777
+ sourceOperation
2778
+ ]);
2779
+ const storedKey = JSON.stringify(storedMapping);
2780
+ const [seenStoredKey, setSeenStoredKey] = useState(storedKey);
2781
+ if (storedKey !== seenStoredKey) {
2782
+ setSeenStoredKey(storedKey);
2783
+ if (sameMappingValue(mappingJson, baseline) && jsonDataString === formatMapping(mappingJson)) {
2784
+ setBaseline(storedMapping);
2785
+ setMappingJson(storedMapping);
2786
+ setJsonDataString(formatMapping(storedMapping));
2787
+ setValidationErrors(validateMapping(storedMapping));
2788
+ setJsonError(null);
2789
+ }
2790
+ }
2791
+ /** Show a mapping in both views. */
2792
+ const showMapping = (mapping) => {
2793
+ setMappingJson(mapping);
2794
+ setJsonDataString(formatMapping(mapping));
2795
+ setValidationErrors(validateMapping(mapping));
2796
+ };
2797
+ /**
2798
+ * Save `mapping` over the stored one. Returns the stored mapping, or null
2799
+ * when there is nowhere to save it.
2800
+ */
2801
+ const save = (mapping) => {
2802
+ if (!onSaveMapping) return null;
2803
+ const stored = onSaveMapping(baseline, mapping);
2804
+ if (stored === null) return null;
2805
+ setBaseline(stored);
2806
+ setSeenStoredKey(JSON.stringify(stored));
2807
+ showMapping(stored);
2808
+ return stored;
2809
+ };
2810
+ const handleJsonStringChange = (e) => {
2811
+ setJsonDataString(e.target.value);
2812
+ setJsonError(null);
2813
+ };
2814
+ const handleJsonBlur = () => {
2815
+ const result = parseMappingText(jsonDataString);
2816
+ if (!result.ok) {
2817
+ setJsonError(result.invalidJson ? tr("fluidgrids.builder.mappingEditor.invalidJsonFormat", "Invalid JSON format. Please correct it.") : result.message);
2818
+ return;
2819
+ }
2820
+ setMappingJson(result.mapping);
2821
+ setJsonError(null);
2822
+ setValidationErrors(validateMapping(result.mapping));
2823
+ };
2824
+ const handleMappingChange = (newMapping) => {
2825
+ const next = toMappingDefinition(newMapping);
2826
+ showMapping(next);
2827
+ if (validateMapping(next).length === 0) save(next);
2828
+ };
2829
+ /**
2830
+ * The JSON editor's mapping, checked: valid JSON, an object of mapping
2831
+ * values, and valid template syntax. Throws otherwise.
2832
+ */
2833
+ const checkedMapping = () => {
2834
+ setJsonError(null);
2835
+ const result = parseMappingText(jsonDataString);
2836
+ if (!result.ok) {
2837
+ const message = result.invalidJson ? tr("fluidgrids.builder.mappingEditor.cannotSubmitInvalidJson", "Cannot submit: Mapping data must be valid JSON.") : result.message;
2838
+ setJsonError(message);
2839
+ throw new Error(message);
2840
+ }
2841
+ setMappingJson(result.mapping);
2842
+ const errors = validateMapping(result.mapping);
2843
+ setValidationErrors(errors);
2844
+ if (errors.length > 0) throw new Error(`Validation errors: ${errors.join(", ")}`);
2845
+ return result.mapping;
2846
+ };
2847
+ const handleSaveMapping = () => {
2848
+ try {
2849
+ if (save(checkedMapping()) === null) throw new Error(tr("fluidgrids.builder.mappingEditor.connectionMissing", "This connection no longer exists."));
2850
+ toast({
2851
+ title: tr("fluidgrids.builder.mappingEditor.mappingSavedTitle", "Mapping saved"),
2852
+ description: tr("fluidgrids.builder.mappingEditor.mappingSavedDescription", "Your mapping configuration has been saved successfully.")
2853
+ });
2854
+ } catch (error) {
2855
+ toast({
2856
+ title: tr("fluidgrids.builder.mappingEditor.errorSavingTitle", "Error saving mapping"),
2857
+ description: error instanceof Error ? error.message : tr("fluidgrids.builder.mappingEditor.errorSavingFallback", "Invalid mapping configuration"),
2858
+ variant: "destructive"
2859
+ });
2860
+ }
2861
+ };
2862
+ const handleTestMapping = async () => {
2863
+ try {
2864
+ setIsTestingMapping(true);
2865
+ const parsedData = checkedMapping();
2866
+ const result = await applyMapping(parsedData, sampleInput);
2867
+ setPreviewOutput(result);
2868
+ toast({
2869
+ title: tr("fluidgrids.builder.mappingEditor.mappingTestedTitle", "Mapping tested"),
2870
+ description: tr("fluidgrids.builder.mappingEditor.mappingTestedDescription", "Test completed successfully.")
2871
+ });
2872
+ } catch (error) {
2873
+ console.error("Test mapping error:", error);
2874
+ toast({
2875
+ title: tr("fluidgrids.builder.mappingEditor.mappingTestFailedTitle", "Mapping test failed"),
2876
+ description: error instanceof Error ? error.message : tr("fluidgrids.builder.mappingEditor.mappingTestFailedFallback", "Error executing mapping"),
2877
+ variant: "destructive"
2878
+ });
2879
+ } finally {
2880
+ setIsTestingMapping(false);
2881
+ }
2882
+ };
2883
+ const detectMappingTypes = (mapping) => {
2884
+ const types = /* @__PURE__ */ new Set();
2885
+ const processValue = (value) => {
2886
+ if (typeof value === "string") {
2887
+ const parseResult = parseTemplate(value);
2888
+ if (parseResult.isTemplate) {
2889
+ const expr = parseResult.expression || "";
2890
+ if (expr.includes(".map(") || expr.includes(".filter(") || expr.includes(".reduce(")) types.add("array");
2891
+ else if (expr.includes("Object.") || expr.startsWith("({")) types.add("object");
2892
+ else if (expr.startsWith("parseInt(") || expr.startsWith("parseFloat(") || expr.startsWith("String(")) types.add("cast");
2893
+ else if (expr.includes("TriggerInput.") || expr.includes("WorkflowState.") || expr.includes("RunContext.")) types.add("context");
2894
+ else if (expr.includes(".toUpperCase()") || expr.includes(".toLowerCase()") || expr.includes(".trim()")) types.add("transform");
2895
+ else if (expr.includes(" + ") || expr.includes(" ? ") || expr.includes("Math.")) types.add("expression");
2896
+ else types.add("direct");
2897
+ }
2898
+ } else if (typeof value === "object" && value !== null) Object.values(value).forEach(processValue);
2899
+ };
2900
+ Object.values(mapping).forEach(processValue);
2901
+ return types;
2902
+ };
2903
+ const usedMappingTypes = detectMappingTypes(mappingJson);
2904
+ return /* @__PURE__ */ jsx("div", {
2905
+ className,
2906
+ children: /* @__PURE__ */ jsxs(Card, { children: [/* @__PURE__ */ jsxs(CardHeader, { children: [
2907
+ /* @__PURE__ */ jsxs(CardTitle, {
2908
+ className: "flex items-center justify-between",
2909
+ children: [/* @__PURE__ */ jsx("span", { children: tr("fluidgrids.builder.mappingEditor.cardTitle", "Mapping Configuration") }), validationErrors.length === 0 ? /* @__PURE__ */ jsxs(Badge, {
2910
+ variant: "outline",
2911
+ className: "text-[var(--color-status-success-text)] border-[var(--color-status-success-border)]",
2912
+ children: [/* @__PURE__ */ jsx(CheckCircle2, { className: "h-3 w-3 mr-1" }), tr("fluidgrids.builder.mappingEditor.badgeValid", "Valid")]
2913
+ }) : /* @__PURE__ */ jsxs(Badge, {
2914
+ variant: "outline",
2915
+ className: "text-[var(--color-status-error-text)] border-[var(--color-status-error-border)]",
2916
+ children: [
2917
+ /* @__PURE__ */ jsx(AlertCircle, { className: "h-3 w-3 mr-1" }),
2918
+ validationErrors.length,
2919
+ " Error",
2920
+ validationErrors.length > 1 ? "s" : ""
2921
+ ]
2922
+ })]
2923
+ }),
2924
+ /* @__PURE__ */ jsxs(CardDescription, { children: [
2925
+ "Create a mapping from ",
2926
+ sourceLabel,
2927
+ ".",
2928
+ sourceOperation,
2929
+ " to",
2930
+ " ",
2931
+ targetLabel,
2932
+ ".",
2933
+ targetOperation
2934
+ ] }),
2935
+ usedMappingTypes.size > 0 && /* @__PURE__ */ jsx("div", {
2936
+ className: "flex flex-wrap gap-1 mt-2",
2937
+ children: Array.from(usedMappingTypes).map((type) => /* @__PURE__ */ jsx(Badge, {
2938
+ variant: "secondary",
2939
+ className: "text-xs",
2940
+ children: type
2941
+ }, type))
2942
+ })
2943
+ ] }), /* @__PURE__ */ jsxs(CardContent, { children: [/* @__PURE__ */ jsxs(Tabs, {
2944
+ defaultValue: "visual",
2945
+ className: "w-full",
2946
+ children: [
2947
+ /* @__PURE__ */ jsxs(TabsList, {
2948
+ className: "mb-4",
2949
+ children: [
2950
+ /* @__PURE__ */ jsx(TabsTrigger, {
2951
+ value: "visual",
2952
+ children: tr("fluidgrids.builder.mappingEditor.tabVisualMapper", "Visual Mapper")
2953
+ }),
2954
+ /* @__PURE__ */ jsx(TabsTrigger, {
2955
+ value: "code",
2956
+ children: tr("fluidgrids.builder.mappingEditor.tabJsonEditor", "JSON Editor")
2957
+ }),
2958
+ /* @__PURE__ */ jsx(TabsTrigger, {
2959
+ value: "preview",
2960
+ children: tr("fluidgrids.builder.mappingEditor.tabPreview", "Preview")
2961
+ })
2962
+ ]
2963
+ }),
2964
+ /* @__PURE__ */ jsx(TabsContent, {
2965
+ value: "visual",
2966
+ children: /* @__PURE__ */ jsx(VisualMapper, {
2967
+ sourceSchema,
2968
+ targetSchema,
2969
+ sourceNode,
2970
+ sourceOperation,
2971
+ targetNode,
2972
+ targetOperation,
2973
+ mapping: mappingJson,
2974
+ onMappingChange: handleMappingChange
2975
+ })
2976
+ }),
2977
+ /* @__PURE__ */ jsxs(TabsContent, {
2978
+ value: "code",
2979
+ children: [/* @__PURE__ */ jsx(CodeEditor, {
2980
+ value: jsonDataString,
2981
+ onBlur: handleJsonBlur,
2982
+ onChange: handleJsonStringChange
2983
+ }), /* @__PURE__ */ jsxs("div", {
2984
+ className: "mt-2 space-y-1",
2985
+ children: [
2986
+ /* @__PURE__ */ jsxs("p", {
2987
+ className: "text-xs text-muted-foreground",
2988
+ children: [
2989
+ tr("fluidgrids.builder.mappingEditor.templateSyntaxHint", "Use JavaScript template literal syntax:"),
2990
+ " ",
2991
+ /* @__PURE__ */ jsxs("code", {
2992
+ className: "bg-muted px-1 rounded",
2993
+ children: [
2994
+ "$",
2995
+ "{",
2996
+ "output.field",
2997
+ "}"
2998
+ ]
2999
+ })
3000
+ ]
3001
+ }),
3002
+ jsonError && /* @__PURE__ */ jsx("p", {
3003
+ className: "text-sm text-[var(--color-status-error-text)]",
3004
+ children: jsonError
3005
+ }),
3006
+ validationErrors.length > 0 && /* @__PURE__ */ jsxs("div", {
3007
+ className: "p-2 bg-[var(--color-status-error-bg-subtle)] rounded-md",
3008
+ children: [/* @__PURE__ */ jsx("p", {
3009
+ className: "text-sm font-medium text-[var(--color-status-error-text)]",
3010
+ children: tr("fluidgrids.builder.mappingEditor.validationErrors", "Validation Errors:")
3011
+ }), /* @__PURE__ */ jsx("ul", {
3012
+ className: "text-xs text-[var(--color-status-error-text)]/80 mt-1 list-disc list-inside",
3013
+ children: validationErrors.map((error, index) => /* @__PURE__ */ jsx("li", { children: error }, index))
3014
+ })]
3015
+ })
3016
+ ]
3017
+ })]
3018
+ }),
3019
+ /* @__PURE__ */ jsx(TabsContent, {
3020
+ value: "preview",
3021
+ children: /* @__PURE__ */ jsx(MappingPreview, {
3022
+ input: sampleInput,
3023
+ mapping: mappingJson,
3024
+ output: previewOutput
3025
+ })
3026
+ })
3027
+ ]
3028
+ }), /* @__PURE__ */ jsxs("div", {
3029
+ className: "mt-6 flex justify-end space-x-2",
3030
+ children: [/* @__PURE__ */ jsx(Button, {
3031
+ variant: "outline",
3032
+ onClick: handleTestMapping,
3033
+ disabled: isTestingMapping,
3034
+ children: isTestingMapping ? tr("fluidgrids.builder.mappingEditor.testing", "Testing...") : tr("fluidgrids.builder.mappingEditor.testMapping", "Test Mapping")
3035
+ }), /* @__PURE__ */ jsx(Button, {
3036
+ onClick: handleSaveMapping,
3037
+ children: tr("fluidgrids.builder.mappingEditor.saveMapping", "Save Mapping")
3038
+ })]
3039
+ })] })] })
3040
+ });
3041
+ }
3042
+
3043
+ // src/builder/components/lib/schema-parser.ts
3044
+ function parseGraphQLSchema(sdl) {
3045
+ const customSchema = {
3046
+ types: {},
3047
+ queryType: null,
3048
+ mutationType: null,
3049
+ subscriptionType: null
3050
+ };
3051
+ try {
3052
+ const schema = buildSchema(sdl);
3053
+ const queryType = schema.getQueryType();
3054
+ const mutationType = schema.getMutationType();
3055
+ const subscriptionType = schema.getSubscriptionType();
3056
+ if (queryType) customSchema.queryType = queryType.name;
3057
+ if (mutationType) customSchema.mutationType = mutationType.name;
3058
+ if (subscriptionType) customSchema.subscriptionType = subscriptionType.name;
3059
+ const typeMap = schema.getTypeMap();
3060
+ Object.values(typeMap).forEach((type) => {
3061
+ if (type.name.startsWith("__")) return;
3062
+ if (type instanceof GraphQLObjectType) processObjectType(type, customSchema);
3063
+ else if (type instanceof GraphQLInputObjectType) processInputObjectType(type, customSchema);
3064
+ else if (type instanceof GraphQLEnumType) processEnumType(type, customSchema);
3065
+ else if (type instanceof GraphQLInterfaceType) processInterfaceType(type, customSchema);
3066
+ else if (type instanceof GraphQLUnionType) processUnionType(type, customSchema);
3067
+ });
3068
+ return customSchema;
3069
+ } catch (error) {
3070
+ console.error("Error parsing GraphQL schema:", error);
3071
+ return customSchema;
3072
+ }
3073
+ }
3074
+ function processObjectType(type, customSchema) {
3075
+ const fields = type.getFields();
3076
+ const processedFields = {};
3077
+ Object.values(fields).forEach((field) => {
3078
+ processedFields[field.name] = processField(field);
3079
+ });
3080
+ customSchema.types[type.name] = {
3081
+ name: type.name,
3082
+ kind: "type",
3083
+ fields: processedFields
3084
+ };
3085
+ }
3086
+ function processInputObjectType(type, customSchema) {
3087
+ const fields = type.getFields();
3088
+ const processedFields = {};
3089
+ Object.values(fields).forEach((field) => {
3090
+ processedFields[field.name] = processInputField(field);
3091
+ });
3092
+ customSchema.types[type.name] = {
3093
+ name: type.name,
3094
+ kind: "input",
3095
+ fields: processedFields,
3096
+ inputFields: processedFields
3097
+ };
3098
+ }
3099
+ function processEnumType(type, customSchema) {
3100
+ customSchema.types[type.name] = {
3101
+ name: type.name,
3102
+ kind: "enum",
3103
+ fields: {}
3104
+ };
3105
+ }
3106
+ function processInterfaceType(type, customSchema) {
3107
+ const fields = type.getFields();
3108
+ const processedFields = {};
3109
+ Object.values(fields).forEach((field) => {
3110
+ processedFields[field.name] = processField(field);
3111
+ });
3112
+ customSchema.types[type.name] = {
3113
+ name: type.name,
3114
+ kind: "interface",
3115
+ fields: processedFields
3116
+ };
3117
+ }
3118
+ function processUnionType(type, customSchema) {
3119
+ customSchema.types[type.name] = {
3120
+ name: type.name,
3121
+ kind: "union",
3122
+ fields: {}
3123
+ };
3124
+ }
3125
+ function processField(field) {
3126
+ const fieldType = field.type;
3127
+ const typeInfo = getTypeInfo(fieldType);
3128
+ const args = field.args.map((arg) => processArgument(arg));
3129
+ return {
3130
+ name: field.name,
3131
+ type: typeInfo.typeName,
3132
+ isNonNull: typeInfo.isNonNull,
3133
+ isList: typeInfo.isList,
3134
+ args
3135
+ };
3136
+ }
3137
+ function processInputField(field) {
3138
+ const fieldType = field.type;
3139
+ const typeInfo = getTypeInfo(fieldType);
3140
+ return {
3141
+ name: field.name,
3142
+ type: typeInfo.typeName,
3143
+ isNonNull: typeInfo.isNonNull,
3144
+ isList: typeInfo.isList,
3145
+ args: []
3146
+ };
3147
+ }
3148
+ function processArgument(arg) {
3149
+ const argType = arg.type;
3150
+ const typeInfo = getTypeInfo(argType);
3151
+ return {
3152
+ name: arg.name,
3153
+ type: typeInfo.typeName,
3154
+ isNonNull: typeInfo.isNonNull,
3155
+ isList: typeInfo.isList
3156
+ };
3157
+ }
3158
+ function getTypeInfo(inputType) {
3159
+ let typeName = "";
3160
+ let isNonNull = false;
3161
+ let isList = false;
3162
+ let currentType = inputType;
3163
+ if (currentType instanceof GraphQLNonNull) {
3164
+ isNonNull = true;
3165
+ currentType = currentType.ofType;
3166
+ }
3167
+ if (currentType instanceof GraphQLList) {
3168
+ isList = true;
3169
+ currentType = currentType.ofType;
3170
+ if (currentType instanceof GraphQLNonNull) currentType = currentType.ofType;
3171
+ }
3172
+ if (currentType.name) typeName = currentType.name;
3173
+ else if (currentType.ofType?.name) typeName = currentType.ofType.name;
3174
+ return {
3175
+ typeName,
3176
+ isNonNull,
3177
+ isList
3178
+ };
3179
+ }
3180
+
3181
+ // src/builder/components/mapper/config/default-data-config.ts
3182
+ /**
3183
+ * Default data config for the mapper component.
3184
+ *
3185
+ * Note: Node configurations (with schemas) are passed dynamically via props
3186
+ * from the edge component. This default config only contains mapping type
3187
+ * examples and type compatibility rules.
3188
+ */
3189
+ const defaultDataConfig = {
3190
+ nodes: {},
3191
+ mappingTypes: {
3192
+ direct: {
3193
+ displayName: "Direct Mapping",
3194
+ description: "Map a source field directly to a target field using ${output.field} syntax",
3195
+ color: {
3196
+ compatible: MAPPING_COMPATIBILITY_COLORS.compatible,
3197
+ incompatible: MAPPING_COMPATIBILITY_COLORS.incompatible
3198
+ },
3199
+ examples: [
3200
+ {
3201
+ name: "Simple field access",
3202
+ expression: "${output.fieldName}",
3203
+ description: "Access a direct field from the output"
3204
+ },
3205
+ {
3206
+ name: "Nested field access",
3207
+ expression: "${output.user.email}",
3208
+ description: "Access nested properties"
3209
+ },
3210
+ {
3211
+ name: "Array element access",
3212
+ expression: "${output.items[0].name}",
3213
+ description: "Access specific array elements"
3214
+ },
3215
+ {
3216
+ name: "With fallback",
3217
+ expression: "${output.user?.email || 'default@example.com'}",
3218
+ description: "Safe access with default value"
3219
+ }
3220
+ ]
3221
+ },
3222
+ expression: {
3223
+ displayName: "Expression Mapping",
3224
+ description: "Create a custom JavaScript expression to transform the data",
3225
+ color: MAPPING_TYPE_COLORS.expression,
3226
+ examples: [
3227
+ {
3228
+ name: "String concatenation",
3229
+ expression: "${output.firstName + ' ' + output.lastName}",
3230
+ description: "Combine first and last name"
3231
+ },
3232
+ {
3233
+ name: "Template literal string",
3234
+ expression: "${`Hello ${output.name}!`}",
3235
+ description: "Use nested template literals for formatting"
3236
+ },
3237
+ {
3238
+ name: "Mathematical operation",
3239
+ expression: "${output.price * (1 - output.discount)}",
3240
+ description: "Calculate discounted price"
3241
+ },
3242
+ {
3243
+ name: "Conditional logic (ternary)",
3244
+ expression: "${output.age >= 18 ? 'Adult' : 'Minor'}",
3245
+ description: "Determine if adult or minor"
3246
+ },
3247
+ {
3248
+ name: "Nullish coalescing",
3249
+ expression: "${output.value ?? 'default'}",
3250
+ description: "Use default if null/undefined"
3251
+ },
3252
+ {
3253
+ name: "Logical OR fallback",
3254
+ expression: "${output.error || 'Success'}",
3255
+ description: "Fallback for falsy values"
3256
+ },
3257
+ {
3258
+ name: "Array length",
3259
+ expression: "${output.items?.length || 0}",
3260
+ description: "Get the length of an array safely"
3261
+ },
3262
+ {
3263
+ name: "Min value",
3264
+ expression: "${Math.min(...output.values)}",
3265
+ description: "Get the minimum value in an array"
3266
+ },
3267
+ {
3268
+ name: "Max value",
3269
+ expression: "${Math.max(...output.values)}",
3270
+ description: "Get the maximum value in an array"
3271
+ },
3272
+ {
3273
+ name: "Round number",
3274
+ expression: "${Math.round(output.value)}",
3275
+ description: "Round to nearest integer"
3276
+ },
3277
+ {
3278
+ name: "JSON parsing",
3279
+ expression: "${JSON.parse(output.jsonString)}",
3280
+ description: "Parse a JSON string to an object"
3281
+ },
3282
+ {
3283
+ name: "JSON stringify",
3284
+ expression: "${JSON.stringify(output.data)}",
3285
+ description: "Convert object to JSON string"
3286
+ },
3287
+ {
3288
+ name: "Current timestamp",
3289
+ expression: "${new Date().toISOString()}",
3290
+ description: "Get current date/time in ISO format"
3291
+ },
3292
+ {
3293
+ name: "Object creation",
3294
+ expression: "${({ id: output.user.id, email: output.user.email })}",
3295
+ description: "Create a new object from fields"
3296
+ }
3297
+ ],
3298
+ safeBuiltins: [
3299
+ "parseInt",
3300
+ "parseFloat",
3301
+ "isNaN",
3302
+ "isFinite",
3303
+ "Number",
3304
+ "String",
3305
+ "Boolean",
3306
+ "Math.min",
3307
+ "Math.max",
3308
+ "Math.round",
3309
+ "Math.floor",
3310
+ "Math.ceil",
3311
+ "Math.abs",
3312
+ "Array.isArray",
3313
+ "JSON.parse",
3314
+ "JSON.stringify",
3315
+ "Object.keys",
3316
+ "Object.values",
3317
+ "Object.entries",
3318
+ "Object.assign",
3319
+ "Date",
3320
+ "new Date()"
3321
+ ]
3322
+ },
3323
+ transform: {
3324
+ displayName: "Transform Mapping",
3325
+ description: "Apply string and data transformation functions",
3326
+ color: MAPPING_TYPE_COLORS.transform,
3327
+ examples: [
3328
+ {
3329
+ name: "Uppercase",
3330
+ expression: "${output.field.toUpperCase()}",
3331
+ description: "Convert text to uppercase"
3332
+ },
3333
+ {
3334
+ name: "Lowercase",
3335
+ expression: "${output.field.toLowerCase()}",
3336
+ description: "Convert text to lowercase"
3337
+ },
3338
+ {
3339
+ name: "Trim whitespace",
3340
+ expression: "${output.field.trim()}",
3341
+ description: "Remove leading/trailing whitespace"
3342
+ },
3343
+ {
3344
+ name: "Split string",
3345
+ expression: "${output.field.split(',')}",
3346
+ description: "Split string into array by delimiter"
3347
+ },
3348
+ {
3349
+ name: "Join array",
3350
+ expression: "${output.items.join(', ')}",
3351
+ description: "Join array elements with delimiter"
3352
+ },
3353
+ {
3354
+ name: "Replace text",
3355
+ expression: "${output.field.replace(/old/g, 'new')}",
3356
+ description: "Replace all occurrences of text"
3357
+ },
3358
+ {
3359
+ name: "Substring",
3360
+ expression: "${output.field.substring(0, 10)}",
3361
+ description: "Extract part of a string"
3362
+ },
3363
+ {
3364
+ name: "Slice",
3365
+ expression: "${output.field.slice(-5)}",
3366
+ description: "Get last 5 characters"
3367
+ },
3368
+ {
3369
+ name: "Includes check",
3370
+ expression: "${output.field.includes('search')}",
3371
+ description: "Check if string contains text"
3372
+ },
3373
+ {
3374
+ name: "Starts with",
3375
+ expression: "${output.field.startsWith('prefix')}",
3376
+ description: "Check if string starts with text"
3377
+ }
3378
+ ],
3379
+ functions: [
3380
+ {
3381
+ name: "toUpperCase",
3382
+ displayName: "Uppercase",
3383
+ description: "Convert text to uppercase",
3384
+ example: "${output.field.toUpperCase()}"
3385
+ },
3386
+ {
3387
+ name: "toLowerCase",
3388
+ displayName: "Lowercase",
3389
+ description: "Convert text to lowercase",
3390
+ example: "${output.field.toLowerCase()}"
3391
+ },
3392
+ {
3393
+ name: "trim",
3394
+ displayName: "Trim",
3395
+ description: "Remove whitespace from start and end",
3396
+ example: "${output.field.trim()}"
3397
+ },
3398
+ {
3399
+ name: "split",
3400
+ displayName: "Split",
3401
+ description: "Split string into array by delimiter",
3402
+ example: "${output.field.split(',')}"
3403
+ },
3404
+ {
3405
+ name: "join",
3406
+ displayName: "Join",
3407
+ description: "Join array elements with delimiter",
3408
+ example: "${output.items.join('-')}"
3409
+ },
3410
+ {
3411
+ name: "replace",
3412
+ displayName: "Replace",
3413
+ description: "Replace text in string",
3414
+ example: "${output.field.replace('old', 'new')}"
3415
+ },
3416
+ {
3417
+ name: "concat",
3418
+ displayName: "Concatenate",
3419
+ description: "Join multiple strings together",
3420
+ example: "${output.first + ' ' + output.last}"
3421
+ }
3422
+ ]
3423
+ },
3424
+ cast: {
3425
+ displayName: "Cast Mapping",
3426
+ description: "Convert data from one type to another using JavaScript functions",
3427
+ color: MAPPING_TYPE_COLORS.cast,
3428
+ examples: [
3429
+ {
3430
+ name: "String to Integer",
3431
+ expression: "${parseInt(output.numberString)}",
3432
+ description: "Convert string to integer"
3433
+ },
3434
+ {
3435
+ name: "String to Float",
3436
+ expression: "${parseFloat(output.decimalString)}",
3437
+ description: "Convert string to decimal number"
3438
+ },
3439
+ {
3440
+ name: "To String",
3441
+ expression: "${String(output.value)}",
3442
+ description: "Convert any value to string"
3443
+ },
3444
+ {
3445
+ name: "To Boolean",
3446
+ expression: "${Boolean(output.value)}",
3447
+ description: "Convert to true/false"
3448
+ },
3449
+ {
3450
+ name: "Number with default",
3451
+ expression: "${Number(output.value) || 0}",
3452
+ description: "Convert to number with fallback"
3453
+ },
3454
+ {
3455
+ name: "Parse with radix",
3456
+ expression: "${parseInt(output.hex, 16)}",
3457
+ description: "Parse hexadecimal string"
3458
+ },
3459
+ {
3460
+ name: "Fixed decimals",
3461
+ expression: "${parseFloat(output.price).toFixed(2)}",
3462
+ description: "Format number with 2 decimal places"
3463
+ }
3464
+ ],
3465
+ types: [
3466
+ {
3467
+ name: "parseInt",
3468
+ displayName: "Integer",
3469
+ description: "Convert to whole number",
3470
+ example: "${parseInt(output.field)}"
3471
+ },
3472
+ {
3473
+ name: "parseFloat",
3474
+ displayName: "Float",
3475
+ description: "Convert to decimal number",
3476
+ example: "${parseFloat(output.field)}"
3477
+ },
3478
+ {
3479
+ name: "String",
3480
+ displayName: "String",
3481
+ description: "Convert to text",
3482
+ example: "${String(output.field)}"
3483
+ },
3484
+ {
3485
+ name: "Boolean",
3486
+ displayName: "Boolean",
3487
+ description: "Convert to true/false",
3488
+ example: "${Boolean(output.field)}"
3489
+ },
3490
+ {
3491
+ name: "Number",
3492
+ displayName: "Number",
3493
+ description: "Convert to number",
3494
+ example: "${Number(output.field)}"
3495
+ }
3496
+ ]
3497
+ },
3498
+ array: {
3499
+ displayName: "Array Mapping",
3500
+ description: "Transform arrays using map, filter, reduce and other array methods",
3501
+ color: MAPPING_TYPE_COLORS.array,
3502
+ examples: [
3503
+ {
3504
+ name: "Map - Extract IDs",
3505
+ expression: "${output.users.map(u => u.id)}",
3506
+ description: "Extract a single field from each item"
3507
+ },
3508
+ {
3509
+ name: "Map - Transform objects",
3510
+ expression: "${output.items.map(item => ({ name: item.name, value: item.value }))}",
3511
+ description: "Transform each item to new shape"
3512
+ },
3513
+ {
3514
+ name: "Map - With index",
3515
+ expression: "${output.items.map((item, index) => ({ ...item, position: index + 1 }))}",
3516
+ description: "Include index in transformation"
3517
+ },
3518
+ {
3519
+ name: "Filter - Active users",
3520
+ expression: "${output.users.filter(u => u.active)}",
3521
+ description: "Keep only items matching condition"
3522
+ },
3523
+ {
3524
+ name: "Filter - By value",
3525
+ expression: "${output.items.filter(item => item.price > 100)}",
3526
+ description: "Filter by numeric comparison"
3527
+ },
3528
+ {
3529
+ name: "Filter + Map",
3530
+ expression: "${output.users.filter(u => u.active).map(u => u.id)}",
3531
+ description: "Chain filter and map operations"
3532
+ },
3533
+ {
3534
+ name: "Reduce - Sum",
3535
+ expression: "${output.items.reduce((sum, item) => sum + item.price, 0)}",
3536
+ description: "Calculate total of all prices"
3537
+ },
3538
+ {
3539
+ name: "Reduce - Average",
3540
+ expression: "${output.items.reduce((sum, item) => sum + item.value, 0) / output.items.length}",
3541
+ description: "Calculate average value"
3542
+ },
3543
+ {
3544
+ name: "Reduce - Group by",
3545
+ expression: "${output.items.reduce((acc, item) => ({ ...acc, [item.category]: [...(acc[item.category] || []), item] }), {})}",
3546
+ description: "Group items by category"
3547
+ },
3548
+ {
3549
+ name: "Find - First match",
3550
+ expression: "${output.items.find(item => item.id === TriggerInput.itemId)}",
3551
+ description: "Find first item matching condition"
3552
+ },
3553
+ {
3554
+ name: "Some - Any match",
3555
+ expression: "${output.items.some(item => item.active)}",
3556
+ description: "Check if any item matches"
3557
+ },
3558
+ {
3559
+ name: "Every - All match",
3560
+ expression: "${output.items.every(item => item.valid)}",
3561
+ description: "Check if all items match"
3562
+ },
3563
+ {
3564
+ name: "Flat - Flatten array",
3565
+ expression: "${output.nestedArrays.flat()}",
3566
+ description: "Flatten one level of nesting"
3567
+ },
3568
+ {
3569
+ name: "FlatMap - Map and flatten",
3570
+ expression: "${output.users.flatMap(u => u.permissions)}",
3571
+ description: "Map then flatten results"
3572
+ },
3573
+ {
3574
+ name: "Sort - Ascending",
3575
+ expression: "${[...output.items].sort((a, b) => a.price - b.price)}",
3576
+ description: "Sort items by price ascending"
3577
+ },
3578
+ {
3579
+ name: "Sort - Descending",
3580
+ expression: "${[...output.items].sort((a, b) => b.price - a.price)}",
3581
+ description: "Sort items by price descending"
3582
+ },
3583
+ {
3584
+ name: "Slice - First N",
3585
+ expression: "${output.items.slice(0, 5)}",
3586
+ description: "Get first 5 items"
3587
+ },
3588
+ {
3589
+ name: "Slice - Last N",
3590
+ expression: "${output.items.slice(-3)}",
3591
+ description: "Get last 3 items"
3592
+ },
3593
+ {
3594
+ name: "Unique values",
3595
+ expression: "${[...new Set(output.items.map(i => i.category))]}",
3596
+ description: "Get unique categories"
3597
+ },
3598
+ {
3599
+ name: "Concat arrays",
3600
+ expression: "${output.list1.concat(output.list2)}",
3601
+ description: "Combine two arrays"
3602
+ },
3603
+ {
3604
+ name: "Includes check",
3605
+ expression: "${output.tags.includes('important')}",
3606
+ description: "Check if array contains value"
3607
+ },
3608
+ {
3609
+ name: "Index of",
3610
+ expression: "${output.items.findIndex(i => i.id === 'target')}",
3611
+ description: "Find index of matching item"
3612
+ }
3613
+ ]
3614
+ },
3615
+ object: {
3616
+ displayName: "Object Mapping",
3617
+ description: "Transform and manipulate objects",
3618
+ color: MAPPING_TYPE_COLORS.object,
3619
+ examples: [
3620
+ {
3621
+ name: "Get keys",
3622
+ expression: "${Object.keys(output.metadata)}",
3623
+ description: "Get all property names as array"
3624
+ },
3625
+ {
3626
+ name: "Get values",
3627
+ expression: "${Object.values(output.metadata)}",
3628
+ description: "Get all property values as array"
3629
+ },
3630
+ {
3631
+ name: "Get entries",
3632
+ expression: "${Object.entries(output.metadata)}",
3633
+ description: "Get key-value pairs as array"
3634
+ },
3635
+ {
3636
+ name: "Merge objects",
3637
+ expression: "${Object.assign({}, output.user, output.preferences)}",
3638
+ description: "Combine multiple objects"
3639
+ },
3640
+ {
3641
+ name: "Spread merge",
3642
+ expression: "${{ ...output.defaults, ...output.overrides }}",
3643
+ description: "Merge with spread operator"
3644
+ },
3645
+ {
3646
+ name: "Pick fields",
3647
+ expression: "${({ id: output.user.id, email: output.user.email })}",
3648
+ description: "Select specific fields only"
3649
+ },
3650
+ {
3651
+ name: "From entries",
3652
+ expression: "${Object.fromEntries(output.pairs)}",
3653
+ description: "Create object from key-value pairs"
3654
+ },
3655
+ {
3656
+ name: "Has property",
3657
+ expression: "${'email' in output.user}",
3658
+ description: "Check if property exists"
3659
+ }
3660
+ ]
3661
+ },
3662
+ context: {
3663
+ displayName: "Workflow Context",
3664
+ description: "Access workflow execution context and state from previous nodes",
3665
+ color: MAPPING_TYPE_COLORS.context,
3666
+ examples: [
3667
+ {
3668
+ name: "Trigger input",
3669
+ expression: "${TriggerInput.userId}",
3670
+ description: "Access original trigger payload"
3671
+ },
3672
+ {
3673
+ name: "Trigger nested data",
3674
+ expression: "${TriggerInput.webhookData.eventType}",
3675
+ description: "Access nested trigger data"
3676
+ },
3677
+ {
3678
+ name: "Previous node output",
3679
+ expression: "${WorkflowState.fetch_user.output.name}",
3680
+ description: "Access output from a specific previous node"
3681
+ },
3682
+ {
3683
+ name: "Node status",
3684
+ expression: "${WorkflowState.validate_data.status}",
3685
+ description: "Check status of a previous node"
3686
+ },
3687
+ {
3688
+ name: "Combine node outputs",
3689
+ expression: "${WorkflowState.step1.output.count + WorkflowState.step2.output.count}",
3690
+ description: "Combine data from multiple nodes"
3691
+ },
3692
+ {
3693
+ name: "Run ID",
3694
+ expression: "${RunContext.runId}",
3695
+ description: "Current workflow run identifier"
3696
+ },
3697
+ {
3698
+ name: "Workflow key",
3699
+ expression: "${RunContext.workflowKey}",
3700
+ description: "Workflow definition identifier"
3701
+ },
3702
+ {
3703
+ name: "Tenant ID",
3704
+ expression: "${RunContext.tenantId}",
3705
+ description: "Current tenant identifier"
3706
+ },
3707
+ {
3708
+ name: "Workspace ID",
3709
+ expression: "${RunContext.workspaceId}",
3710
+ description: "Current workspace identifier"
3711
+ },
3712
+ {
3713
+ name: "Triggered at",
3714
+ expression: "${RunContext.triggeredAt}",
3715
+ description: "Workflow trigger timestamp"
3716
+ },
3717
+ {
3718
+ name: "Triggered by",
3719
+ expression: "${RunContext.triggeredBy}",
3720
+ description: "User who triggered the workflow"
3721
+ }
3722
+ ]
3723
+ }
3724
+ },
3725
+ typeCompatibility: {
3726
+ String: ["ID", "String"],
3727
+ ID: ["String", "ID"],
3728
+ Int: [
3729
+ "Float",
3730
+ "Int",
3731
+ "String"
3732
+ ],
3733
+ Float: ["String", "Float"],
3734
+ Boolean: ["Boolean", "String"]
3735
+ },
3736
+ sampleData: {
3737
+ search: { response: [{
3738
+ metadata: {
3739
+ title: "Introduction to Machine Learning",
3740
+ source: "https://example.com/ml-intro",
3741
+ sourceLabel: "Example ML Guide",
3742
+ sourceType: "webpage",
3743
+ sourceInfo: "Educational resource",
3744
+ partition: "default",
3745
+ score: .95,
3746
+ images: ["https://example.com/ml-image.jpg"]
3747
+ },
3748
+ content: "Machine learning is a branch of artificial intelligence..."
3749
+ }, {
3750
+ metadata: {
3751
+ title: "Deep Learning Fundamentals",
3752
+ source: "https://example.com/dl-basics",
3753
+ sourceLabel: "Deep Learning Guide",
3754
+ sourceType: "webpage",
3755
+ sourceInfo: "Technical documentation",
3756
+ partition: "default",
3757
+ score: .87,
3758
+ images: ["https://example.com/dl-image.jpg"]
3759
+ },
3760
+ content: "Deep learning is a subset of machine learning..."
3761
+ }] },
3762
+ insert: {
3763
+ success: true,
3764
+ count: 1
3765
+ }
3766
+ }
3767
+ };
3768
+
3769
+ // src/builder/components/mapper/app.tsx
3770
+ function convertInlineSchemaToGraphQL(inlineSchema, nodeType) {
3771
+ const schema = {
3772
+ types: {},
3773
+ queryType: "Query",
3774
+ mutationType: null,
3775
+ subscriptionType: null
3776
+ };
3777
+ if (inlineSchema.outputFields && inlineSchema.outputFields.length > 0) {
3778
+ const outputFields = {};
3779
+ inlineSchema.outputFields.forEach((field) => {
3780
+ outputFields[field.name] = {
3781
+ name: field.name,
3782
+ type: field.type,
3783
+ isNonNull: field.required || false,
3784
+ isList: field.type.startsWith("["),
3785
+ args: []
3786
+ };
3787
+ });
3788
+ const outputTypeName = `${nodeType}Output`;
3789
+ schema.types[outputTypeName] = {
3790
+ name: outputTypeName,
3791
+ kind: "type",
3792
+ fields: outputFields
3793
+ };
3794
+ schema.types["Query"] = {
3795
+ name: "Query",
3796
+ kind: "type",
3797
+ fields: { execute: {
3798
+ name: "execute",
3799
+ type: outputTypeName,
3800
+ isNonNull: false,
3801
+ isList: false,
3802
+ args: []
3803
+ } }
3804
+ };
3805
+ }
3806
+ if (inlineSchema.inputFields && inlineSchema.inputFields.length > 0) {
3807
+ const inputFields = {};
3808
+ inlineSchema.inputFields.forEach((field) => {
3809
+ inputFields[field.name] = {
3810
+ name: field.name,
3811
+ type: field.type,
3812
+ isNonNull: field.required || false,
3813
+ isList: field.type.startsWith("["),
3814
+ args: []
3815
+ };
3816
+ });
3817
+ const inputTypeName = `${nodeType}Input`;
3818
+ schema.types[inputTypeName] = {
3819
+ name: inputTypeName,
3820
+ kind: "input",
3821
+ fields: {},
3822
+ inputFields
3823
+ };
3824
+ }
3825
+ return schema;
3826
+ }
3827
+ function App({ dataConfig = defaultDataConfig, sourceSchema: propSourceSchema, targetSchema: propTargetSchema, sourceOperation, targetOperation, sourceNode, targetNode, storedMapping, onSaveMapping }) {
3828
+ const tr = useTr();
3829
+ const initialParsedSchemas = useMemo(() => {
3830
+ const parsed = {};
3831
+ if (propSourceSchema && sourceNode) parsed[sourceNode] = propSourceSchema;
3832
+ if (propTargetSchema && targetNode) parsed[targetNode] = propTargetSchema;
3833
+ initializeConfig(parsed, dataConfig);
3834
+ return parsed;
3835
+ }, [
3836
+ dataConfig,
3837
+ propSourceSchema,
3838
+ propTargetSchema,
3839
+ sourceNode,
3840
+ targetNode
3841
+ ]);
3842
+ const [parsedSchemas, setParsedSchemas] = useState(initialParsedSchemas);
3843
+ const configInitialized = parsedSchemas === initialParsedSchemas || Object.keys(parsedSchemas).length > 0;
3844
+ const [selectedSourceNode, _setSelectedSourceNode] = useState(sourceNode ?? null);
3845
+ const [selectedSourceOperation, _setSelectedSourceOperation] = useState(sourceOperation ?? null);
3846
+ const [selectedTargetNode, _setSelectedTargetNode] = useState(targetNode ?? null);
3847
+ const [selectedTargetOperation, _setSelectedTargetOperation] = useState(targetOperation ?? null);
3848
+ useEffect(() => {
3849
+ if (configInitialized) {
3850
+ const initializeSchemas = () => {
3851
+ const newParsedSchemas = {};
3852
+ if (propSourceSchema && selectedSourceNode) newParsedSchemas[selectedSourceNode] = propSourceSchema;
3853
+ if (propTargetSchema && selectedTargetNode) newParsedSchemas[selectedTargetNode] = propTargetSchema;
3854
+ Object.keys(dataConfig.nodes).forEach((nodeKey) => {
3855
+ if (!newParsedSchemas[nodeKey]) {
3856
+ const nodeInfo = dataConfig.nodes[nodeKey];
3857
+ if (nodeInfo?.schema && typeof nodeInfo.schema !== "string" && (nodeInfo.schema.inputFields || nodeInfo.schema.outputFields)) newParsedSchemas[nodeKey] = convertInlineSchemaToGraphQL(nodeInfo.schema, nodeKey);
3858
+ else newParsedSchemas[nodeKey] = {
3859
+ types: {},
3860
+ queryType: null,
3861
+ mutationType: null,
3862
+ subscriptionType: null
3863
+ };
3864
+ }
3865
+ });
3866
+ setParsedSchemas((prev) => {
3867
+ return {
3868
+ ...prev,
3869
+ ...newParsedSchemas
3870
+ };
3871
+ });
3872
+ initializeConfig(newParsedSchemas, dataConfig);
3873
+ };
3874
+ initializeSchemas();
3875
+ }
3876
+ }, [
3877
+ configInitialized,
3878
+ dataConfig,
3879
+ propSourceSchema,
3880
+ propTargetSchema,
3881
+ selectedSourceNode,
3882
+ selectedTargetNode
3883
+ ]);
3884
+ const getSchemaForNode = (nodeType, isSource) => {
3885
+ if (!nodeType) return null;
3886
+ if (isSource && propSourceSchema) return propSourceSchema;
3887
+ if (!isSource && propTargetSchema) return propTargetSchema;
3888
+ if (parsedSchemas[nodeType]) return parsedSchemas[nodeType];
3889
+ const nodeInfo = dataConfig.nodes[nodeType];
3890
+ if (nodeInfo) {
3891
+ if (nodeInfo.schema && typeof nodeInfo.schema !== "string" && (nodeInfo.schema.inputFields || nodeInfo.schema.outputFields)) {
3892
+ const convertedSchema = convertInlineSchemaToGraphQL(nodeInfo.schema, nodeType);
3893
+ setParsedSchemas((prev) => ({
3894
+ ...prev,
3895
+ [nodeType]: convertedSchema
3896
+ }));
3897
+ return convertedSchema;
3898
+ }
3899
+ if (typeof nodeInfo.schema === "string") {
3900
+ const parsedSchema = parseGraphQLSchema(nodeInfo.schema);
3901
+ setParsedSchemas((prev) => ({
3902
+ ...prev,
3903
+ [nodeType]: parsedSchema
3904
+ }));
3905
+ return parsedSchema;
3906
+ }
3907
+ }
3908
+ console.warn(`Could not find or parse schema for node type: ${nodeType}`);
3909
+ return null;
3910
+ };
3911
+ const currentSourceSchema = propSourceSchema || getSchemaForNode(selectedSourceNode, true);
3912
+ const currentTargetSchema = propTargetSchema || getSchemaForNode(selectedTargetNode, false);
3913
+ return /* @__PURE__ */ jsx(DataConfigProvider, {
3914
+ config: dataConfig,
3915
+ children: /* @__PURE__ */ jsxs(ThemeProvider$1, { children: [/* @__PURE__ */ jsx("div", {
3916
+ className: "min-h-screen bg-background",
3917
+ children: /* @__PURE__ */ jsxs("main", {
3918
+ className: "container py-6",
3919
+ children: [currentSourceSchema && currentTargetSchema && selectedSourceNode && selectedSourceOperation && selectedTargetNode && selectedTargetOperation && /* @__PURE__ */ jsxs("div", {
3920
+ className: "mt-8 p-4 border rounded-lg",
3921
+ children: [/* @__PURE__ */ jsx("h2", {
3922
+ className: "text-lg font-medium mb-4",
3923
+ children: tr("fluidgrids.builder.mapperApp.dataMappingHeading", "Data Mapping")
3924
+ }), /* @__PURE__ */ jsx(MappingEditor, {
3925
+ sourceSchema: currentSourceSchema,
3926
+ targetSchema: currentTargetSchema,
3927
+ sourceNode: selectedSourceNode,
3928
+ sourceOperation: selectedSourceOperation,
3929
+ targetNode: selectedTargetNode,
3930
+ targetOperation: selectedTargetOperation,
3931
+ storedMapping,
3932
+ onSaveMapping
3933
+ })]
3934
+ }), process.env.NODE_ENV === "development" && /* @__PURE__ */ jsxs("div", {
3935
+ className: "mt-8 p-4 border border-border-default rounded-lg bg-muted",
3936
+ children: [/* @__PURE__ */ jsx("h3", {
3937
+ className: "text-md font-medium mb-2",
3938
+ children: "Debug Information"
3939
+ }), /* @__PURE__ */ jsxs("div", {
3940
+ className: "text-sm",
3941
+ children: [
3942
+ /* @__PURE__ */ jsxs("p", { children: ["Source Node: ", selectedSourceNode || "None"] }),
3943
+ /* @__PURE__ */ jsxs("p", { children: ["Source Operation: ", selectedSourceOperation || "None"] }),
3944
+ /* @__PURE__ */ jsxs("p", { children: ["Target Node: ", selectedTargetNode || "None"] }),
3945
+ /* @__PURE__ */ jsxs("p", { children: ["Target Operation: ", selectedTargetOperation || "None"] }),
3946
+ /* @__PURE__ */ jsxs("p", { children: [
3947
+ "Source Schema:",
3948
+ " ",
3949
+ currentSourceSchema ? "Available" : "Not available"
3950
+ ] }),
3951
+ /* @__PURE__ */ jsxs("p", { children: [
3952
+ "Target Schema:",
3953
+ " ",
3954
+ currentTargetSchema ? "Available" : "Not available"
3955
+ ] }),
3956
+ /* @__PURE__ */ jsxs("p", { children: [
3957
+ "Parsed Schemas:",
3958
+ " ",
3959
+ Object.keys(parsedSchemas).join(", ") || "None"
3960
+ ] }),
3961
+ /* @__PURE__ */ jsxs("details", { children: [/* @__PURE__ */ jsx("summary", { children: "Schema Details" }), /* @__PURE__ */ jsx("pre", {
3962
+ className: "text-xs mt-2 overflow-auto max-h-[200px]",
3963
+ children: JSON.stringify({
3964
+ sourceSchema: currentSourceSchema ? Object.keys(currentSourceSchema.types).length + " types" : "Not available",
3965
+ targetSchema: currentTargetSchema ? Object.keys(currentTargetSchema.types).length + " types" : "Not available"
3966
+ }, null, 2)
3967
+ })] })
3968
+ ]
3969
+ })]
3970
+ })]
3971
+ })
3972
+ }), /* @__PURE__ */ jsx(Toaster, {})] })
3973
+ });
3974
+ }
3975
+
3976
+ // src/builder/components/mapper/edge-mapper-config.ts
3977
+ function edgeMapperDataConfig(tr, source, target) {
3978
+ return {
3979
+ nodes: {
3980
+ [source.key]: {
3981
+ displayName: source.displayName,
3982
+ category: "source",
3983
+ style: {
3984
+ source: "border-[var(--color-status-info-border)]",
3985
+ target: "border-[var(--color-status-info-border)]/60"
3986
+ }
3987
+ },
3988
+ [target.key]: {
3989
+ displayName: target.displayName,
3990
+ category: "target",
3991
+ style: {
3992
+ source: "border-[var(--color-status-warning-border)]",
3993
+ target: "border-[var(--color-status-warning-border)]/60"
3994
+ }
3995
+ }
3996
+ },
3997
+ mappingTypes: {
3998
+ direct: {
3999
+ displayName: tr("fluidgrids.builder.edges.customDeletableEdge.mappingDirectName", "Direct Mapping"),
4000
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.mappingDirectDescription", "Map a source field directly to a target field"),
4001
+ color: {
4002
+ compatible: MAPPING_COMPATIBILITY_COLORS.compatible,
4003
+ incompatible: MAPPING_COMPATIBILITY_COLORS.incompatible
4004
+ }
4005
+ },
4006
+ expression: {
4007
+ displayName: tr("fluidgrids.builder.edges.customDeletableEdge.mappingExpressionName", "Expression Mapping"),
4008
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.mappingExpressionDescription", "Create a custom expression to transform the data"),
4009
+ color: MAPPING_TYPE_COLORS.expression,
4010
+ examples: [
4011
+ {
4012
+ name: "Concatenate strings",
4013
+ expression: "input.firstName + ' ' + input.lastName",
4014
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.expressionConcatDescription", "Combine first and last name")
4015
+ },
4016
+ {
4017
+ name: "Mathematical operation",
4018
+ expression: "input.price * (1 - input.discount)",
4019
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.expressionMathDescription", "Calculate discounted price")
4020
+ },
4021
+ {
4022
+ name: "Conditional logic",
4023
+ expression: "input.age >= 18 ? 'Adult' : 'Minor'",
4024
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.expressionConditionalDescription", "Determine if adult or minor")
4025
+ },
4026
+ {
4027
+ name: "Array length",
4028
+ expression: "input.items ? input.items.length : 0",
4029
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.expressionArrayLengthDescription", "Get the length of an array")
4030
+ },
4031
+ {
4032
+ name: "Min/Max values",
4033
+ expression: "Math.min(...input.values)",
4034
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.expressionMinMaxDescription", "Get the minimum value in an array")
4035
+ },
4036
+ {
4037
+ name: "JSON parsing",
4038
+ expression: "JSON.parse(input.jsonString)",
4039
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.expressionJsonParseDescription", "Parse a JSON string to an object")
4040
+ }
4041
+ ],
4042
+ safeBuiltins: [
4043
+ "parseInt",
4044
+ "parseFloat",
4045
+ "String",
4046
+ "Boolean",
4047
+ "Math.min",
4048
+ "Math.max",
4049
+ "Array.isArray",
4050
+ "JSON.parse",
4051
+ "JSON.stringify",
4052
+ "Object.keys",
4053
+ "Object.values",
4054
+ "Object.entries"
4055
+ ]
4056
+ },
4057
+ transform: {
4058
+ displayName: tr("fluidgrids.builder.edges.customDeletableEdge.mappingTransformName", "Transform Mapping"),
4059
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.mappingTransformDescription", "Apply a predefined transformation function"),
4060
+ color: MAPPING_TYPE_COLORS.transform,
4061
+ functions: [
4062
+ {
4063
+ name: "uppercase",
4064
+ displayName: tr("fluidgrids.builder.edges.customDeletableEdge.transformUppercaseName", "Uppercase"),
4065
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.transformUppercaseDescription", "Convert text to uppercase"),
4066
+ example: "HELLO WORLD"
4067
+ },
4068
+ {
4069
+ name: "lowercase",
4070
+ displayName: tr("fluidgrids.builder.edges.customDeletableEdge.transformLowercaseName", "Lowercase"),
4071
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.transformLowercaseDescription", "Convert text to lowercase"),
4072
+ example: "hello world"
4073
+ },
4074
+ {
4075
+ name: "multiply",
4076
+ displayName: tr("fluidgrids.builder.edges.customDeletableEdge.transformMultiplyName", "Multiply"),
4077
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.transformMultiplyDescription", "Multiply two numbers"),
4078
+ example: "10 (from 5 * 2)"
4079
+ },
4080
+ {
4081
+ name: "concat",
4082
+ displayName: tr("fluidgrids.builder.edges.customDeletableEdge.transformConcatName", "Concatenate"),
4083
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.transformConcatDescription", "Join multiple strings together"),
4084
+ example: "hello world"
4085
+ },
4086
+ {
4087
+ name: "add",
4088
+ displayName: tr("fluidgrids.builder.edges.customDeletableEdge.transformAddName", "Add"),
4089
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.transformAddDescription", "Add two numbers"),
4090
+ example: "8 (from 5 + 3)"
4091
+ },
4092
+ {
4093
+ name: "subtract",
4094
+ displayName: tr("fluidgrids.builder.edges.customDeletableEdge.transformSubtractName", "Subtract"),
4095
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.transformSubtractDescription", "Subtract second number from first"),
4096
+ example: "2 (from 5 - 3)"
4097
+ },
4098
+ {
4099
+ name: "trim",
4100
+ displayName: tr("fluidgrids.builder.edges.customDeletableEdge.transformTrimName", "Trim"),
4101
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.transformTrimDescription", "Remove whitespace from start and end"),
4102
+ example: "hello world"
4103
+ },
4104
+ {
4105
+ name: "split",
4106
+ displayName: tr("fluidgrids.builder.edges.customDeletableEdge.transformSplitName", "Split"),
4107
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.transformSplitDescription", "Split string into array by delimiter"),
4108
+ example: "['hello', 'world']"
4109
+ },
4110
+ {
4111
+ name: "join",
4112
+ displayName: tr("fluidgrids.builder.edges.customDeletableEdge.transformJoinName", "Join"),
4113
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.transformJoinDescription", "Join array elements with delimiter"),
4114
+ example: "hello-world"
4115
+ }
4116
+ ]
4117
+ },
4118
+ cast: {
4119
+ displayName: tr("fluidgrids.builder.edges.customDeletableEdge.mappingCastName", "Cast Mapping"),
4120
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.mappingCastDescription", "Convert data from one type to another"),
4121
+ color: MAPPING_TYPE_COLORS.cast,
4122
+ types: [
4123
+ {
4124
+ name: "int",
4125
+ displayName: tr("fluidgrids.builder.edges.customDeletableEdge.castIntName", "Integer"),
4126
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.castIntDescription", "Convert to whole number"),
4127
+ example: "42"
4128
+ },
4129
+ {
4130
+ name: "float",
4131
+ displayName: tr("fluidgrids.builder.edges.customDeletableEdge.castFloatName", "Float"),
4132
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.castFloatDescription", "Convert to decimal number"),
4133
+ example: "3.14"
4134
+ },
4135
+ {
4136
+ name: "str",
4137
+ displayName: tr("fluidgrids.builder.edges.customDeletableEdge.castStrName", "String"),
4138
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.castStrDescription", "Convert to text"),
4139
+ example: "\"hello\""
4140
+ },
4141
+ {
4142
+ name: "bool",
4143
+ displayName: tr("fluidgrids.builder.edges.customDeletableEdge.castBoolName", "Boolean"),
4144
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.castBoolDescription", "Convert to true/false"),
4145
+ example: "true"
4146
+ }
4147
+ ]
4148
+ },
4149
+ array: {
4150
+ displayName: tr("fluidgrids.builder.edges.customDeletableEdge.mappingArrayName", "Array Mapping"),
4151
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.mappingArrayDescription", "Transform arrays using map, filter, reduce and other array methods"),
4152
+ color: MAPPING_TYPE_COLORS.array,
4153
+ examples: [
4154
+ {
4155
+ name: "Map - Extract IDs",
4156
+ expression: "${output.users.map(u => u.id)}",
4157
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.arrayMapExtractDescription", "Extract a single field from each item")
4158
+ },
4159
+ {
4160
+ name: "Map - Transform objects",
4161
+ expression: "${output.items.map(item => ({ name: item.name, value: item.value }))}",
4162
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.arrayMapTransformDescription", "Transform each item to new shape")
4163
+ },
4164
+ {
4165
+ name: "Map - With index",
4166
+ expression: "${output.items.map((item, index) => ({ ...item, position: index + 1 }))}",
4167
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.arrayMapIndexDescription", "Include index in transformation")
4168
+ },
4169
+ {
4170
+ name: "Filter - Active users",
4171
+ expression: "${output.users.filter(u => u.active)}",
4172
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.arrayFilterActiveDescription", "Keep only items matching condition")
4173
+ },
4174
+ {
4175
+ name: "Filter - By value",
4176
+ expression: "${output.items.filter(item => item.price > 100)}",
4177
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.arrayFilterValueDescription", "Filter by numeric comparison")
4178
+ },
4179
+ {
4180
+ name: "Filter + Map",
4181
+ expression: "${output.users.filter(u => u.active).map(u => u.id)}",
4182
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.arrayFilterMapDescription", "Chain filter and map operations")
4183
+ },
4184
+ {
4185
+ name: "Reduce - Sum",
4186
+ expression: "${output.items.reduce((sum, item) => sum + item.price, 0)}",
4187
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.arrayReduceSumDescription", "Calculate total of all prices")
4188
+ },
4189
+ {
4190
+ name: "Reduce - Average",
4191
+ expression: "${output.items.reduce((sum, item) => sum + item.value, 0) / output.items.length}",
4192
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.arrayReduceAverageDescription", "Calculate average value")
4193
+ },
4194
+ {
4195
+ name: "Find - First match",
4196
+ expression: "${output.items.find(item => item.id === TriggerInput.itemId)}",
4197
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.arrayFindDescription", "Find first item matching condition")
4198
+ },
4199
+ {
4200
+ name: "Some - Any match",
4201
+ expression: "${output.items.some(item => item.active)}",
4202
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.arraySomeDescription", "Check if any item matches")
4203
+ },
4204
+ {
4205
+ name: "Every - All match",
4206
+ expression: "${output.items.every(item => item.valid)}",
4207
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.arrayEveryDescription", "Check if all items match")
4208
+ },
4209
+ {
4210
+ name: "Flat - Flatten array",
4211
+ expression: "${output.nestedArrays.flat()}",
4212
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.arrayFlatDescription", "Flatten one level of nesting")
4213
+ },
4214
+ {
4215
+ name: "FlatMap - Map and flatten",
4216
+ expression: "${output.users.flatMap(u => u.permissions)}",
4217
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.arrayFlatMapDescription", "Map then flatten results")
4218
+ },
4219
+ {
4220
+ name: "Sort - Ascending",
4221
+ expression: "${[...output.items].sort((a, b) => a.price - b.price)}",
4222
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.arraySortAscDescription", "Sort items by price ascending")
4223
+ },
4224
+ {
4225
+ name: "Sort - Descending",
4226
+ expression: "${[...output.items].sort((a, b) => b.price - a.price)}",
4227
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.arraySortDescDescription", "Sort items by price descending")
4228
+ },
4229
+ {
4230
+ name: "Slice - First N",
4231
+ expression: "${output.items.slice(0, 5)}",
4232
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.arraySliceFirstDescription", "Get first 5 items")
4233
+ },
4234
+ {
4235
+ name: "Slice - Last N",
4236
+ expression: "${output.items.slice(-3)}",
4237
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.arraySliceLastDescription", "Get last 3 items")
4238
+ },
4239
+ {
4240
+ name: "Unique values",
4241
+ expression: "${[...new Set(output.items.map(i => i.category))]}",
4242
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.arrayUniqueDescription", "Get unique categories")
4243
+ }
4244
+ ]
4245
+ },
4246
+ object: {
4247
+ displayName: tr("fluidgrids.builder.edges.customDeletableEdge.mappingObjectName", "Object Mapping"),
4248
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.mappingObjectDescription", "Transform and manipulate objects"),
4249
+ color: MAPPING_TYPE_COLORS.object,
4250
+ examples: [
4251
+ {
4252
+ name: "Get keys",
4253
+ expression: "${Object.keys(output.metadata)}",
4254
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.objectKeysDescription", "Get all property names as array")
4255
+ },
4256
+ {
4257
+ name: "Get values",
4258
+ expression: "${Object.values(output.metadata)}",
4259
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.objectValuesDescription", "Get all property values as array")
4260
+ },
4261
+ {
4262
+ name: "Get entries",
4263
+ expression: "${Object.entries(output.metadata)}",
4264
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.objectEntriesDescription", "Get key-value pairs as array")
4265
+ },
4266
+ {
4267
+ name: "Merge objects",
4268
+ expression: "${Object.assign({}, output.user, output.preferences)}",
4269
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.objectMergeDescription", "Combine multiple objects")
4270
+ },
4271
+ {
4272
+ name: "Spread merge",
4273
+ expression: "${{ ...output.defaults, ...output.overrides }}",
4274
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.objectSpreadDescription", "Merge with spread operator")
4275
+ },
4276
+ {
4277
+ name: "Pick fields",
4278
+ expression: "${({ id: output.user.id, email: output.user.email })}",
4279
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.objectPickDescription", "Select specific fields only")
4280
+ },
4281
+ {
4282
+ name: "From entries",
4283
+ expression: "${Object.fromEntries(output.pairs)}",
4284
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.objectFromEntriesDescription", "Create object from key-value pairs")
4285
+ },
4286
+ {
4287
+ name: "Has property",
4288
+ expression: "${'email' in output.user}",
4289
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.objectHasPropertyDescription", "Check if property exists")
4290
+ }
4291
+ ]
4292
+ },
4293
+ context: {
4294
+ displayName: tr("fluidgrids.builder.edges.customDeletableEdge.mappingContextName", "Workflow Context"),
4295
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.mappingContextDescription", "Access workflow execution context and state from previous nodes"),
4296
+ color: MAPPING_TYPE_COLORS.context,
4297
+ examples: [
4298
+ {
4299
+ name: "Trigger input",
4300
+ expression: "${TriggerInput.userId}",
4301
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.contextTriggerInputDescription", "Access original trigger payload")
4302
+ },
4303
+ {
4304
+ name: "Trigger nested data",
4305
+ expression: "${TriggerInput.webhookData.eventType}",
4306
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.contextTriggerNestedDescription", "Access nested trigger data")
4307
+ },
4308
+ {
4309
+ name: "Previous node output",
4310
+ expression: "${WorkflowState.fetch_user.output.name}",
4311
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.contextPreviousOutputDescription", "Access output from a specific previous node")
4312
+ },
4313
+ {
4314
+ name: "Node status",
4315
+ expression: "${WorkflowState.validate_data.status}",
4316
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.contextNodeStatusDescription", "Check status of a previous node")
4317
+ },
4318
+ {
4319
+ name: "Combine node outputs",
4320
+ expression: "${WorkflowState.step1.output.count + WorkflowState.step2.output.count}",
4321
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.contextCombineOutputsDescription", "Combine data from multiple nodes")
4322
+ },
4323
+ {
4324
+ name: "Run ID",
4325
+ expression: "${RunContext.runId}",
4326
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.contextRunIdDescription", "Current workflow run identifier")
4327
+ },
4328
+ {
4329
+ name: "Workflow key",
4330
+ expression: "${RunContext.workflowKey}",
4331
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.contextWorkflowKeyDescription", "Workflow definition identifier")
4332
+ },
4333
+ {
4334
+ name: "Tenant ID",
4335
+ expression: "${RunContext.tenantId}",
4336
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.contextTenantIdDescription", "Current tenant identifier")
4337
+ },
4338
+ {
4339
+ name: "Workspace ID",
4340
+ expression: "${RunContext.workspaceId}",
4341
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.contextWorkspaceIdDescription", "Current workspace identifier")
4342
+ },
4343
+ {
4344
+ name: "Triggered at",
4345
+ expression: "${RunContext.triggeredAt}",
4346
+ description: tr("fluidgrids.builder.edges.customDeletableEdge.contextTriggeredAtDescription", "Workflow trigger timestamp")
4347
+ }
4348
+ ]
4349
+ }
4350
+ },
4351
+ typeCompatibility: {
4352
+ String: ["ID", "String"],
4353
+ ID: ["String", "ID"],
4354
+ Int: [
4355
+ "Float",
4356
+ "Int",
4357
+ "String"
4358
+ ],
4359
+ Float: ["String", "Float"],
4360
+ Boolean: ["Boolean", "String"]
4361
+ },
4362
+ sampleData: {
4363
+ search: { response: [{
4364
+ metadata: {
4365
+ title: "Introduction to Machine Learning",
4366
+ source: "https://example.com/ml-intro",
4367
+ sourceLabel: "Example ML Guide",
4368
+ sourceType: "webpage",
4369
+ sourceInfo: "Educational resource",
4370
+ partition: "default",
4371
+ score: .95,
4372
+ images: ["https://example.com/ml-image.jpg"]
4373
+ },
4374
+ content: "Machine learning is a branch of artificial intelligence..."
4375
+ }, {
4376
+ metadata: {
4377
+ title: "Deep Learning Fundamentals",
4378
+ source: "https://example.com/dl-basics",
4379
+ sourceLabel: "Deep Learning Guide",
4380
+ sourceType: "webpage",
4381
+ sourceInfo: "Technical documentation",
4382
+ partition: "default",
4383
+ score: .87,
4384
+ images: ["https://example.com/dl-image.jpg"]
4385
+ },
4386
+ content: "Deep learning is a subset of machine learning..."
4387
+ }] },
4388
+ insert: {
4389
+ success: true,
4390
+ count: 1
4391
+ }
4392
+ }
4393
+ };
4394
+ }
4395
+
4396
+ // src/builder/components/mapper/edge-mapper.tsx
4397
+ /**
4398
+ * The Mapper of one connection (BOFF-16275), opened from the connection's
4399
+ * Mapper button.
4400
+ *
4401
+ * It reads everything from the flow store: both nodes, their schemas (see
4402
+ * `use-edge-mapper-schemas.ts`) and the connection's stored mapping, which
4403
+ * the editor opens on. Saving merges the edited fields into the stored
4404
+ * mapping through the store (`lib/edge-mapping-writes.ts`), so the step editor's
4405
+ * Expression mode and the Mapper share one mapping and never drop each
4406
+ * other's fields.
4407
+ */
4408
+ /**
4409
+ * The names the Mapper knows the two nodes by. They key its configuration, so
4410
+ * two nodes with the same name (or two Code nodes, before names were shown)
4411
+ * get distinct keys.
4412
+ */
4413
+ function edgeMapperKeys(sourceName, targetName) {
4414
+ const source = sourceName || "source";
4415
+ const target = targetName || "target";
4416
+ if (source !== target) return {
4417
+ source,
4418
+ target
4419
+ };
4420
+ return {
4421
+ source: `${source} (source)`,
4422
+ target: `${target} (target)`
4423
+ };
4424
+ }
4425
+ function EdgeMapper({ edgeId, sourceId, targetId }) {
4426
+ const tr = useTr();
4427
+ const view = useEdgeMapperView(edgeId, sourceId, targetId);
4428
+ const keys = edgeMapperKeys(nodeDisplayName(view.sourceNode), nodeDisplayName(view.targetNode));
4429
+ const dataConfig = useMemo(() => edgeMapperDataConfig(tr, {
4430
+ key: keys.source,
4431
+ displayName: keys.source
4432
+ }, {
4433
+ key: keys.target,
4434
+ displayName: keys.target
4435
+ }), [
4436
+ tr,
4437
+ keys.source,
4438
+ keys.target
4439
+ ]);
4440
+ const { sourceOperation, targetOperation } = view;
4441
+ const onSaveMapping = useCallback((baseline, edited) => commitEdgeMapping(edgeId, baseline, edited, `Mapping from ${keys.source}.${sourceOperation} to ${keys.target}.${targetOperation}`), [
4442
+ edgeId,
4443
+ keys.source,
4444
+ keys.target,
4445
+ sourceOperation,
4446
+ targetOperation
4447
+ ]);
4448
+ if (view.loading) return /* @__PURE__ */ jsxs("div", {
4449
+ className: "flex flex-col items-center justify-center h-64",
4450
+ "data-testid": "edge-mapper-loading",
4451
+ children: [/* @__PURE__ */ jsx(SpinnerIcon, { className: "h-8 w-8 animate-spin text-primary mb-4" }), /* @__PURE__ */ jsx("p", {
4452
+ className: "text-muted-foreground",
4453
+ children: tr("fluidgrids.builder.edges.customDeletableEdge.fetchingNodeSchemas", "Fetching node schemas...")
4454
+ })]
4455
+ });
4456
+ return /* @__PURE__ */ jsxs("div", {
4457
+ "data-testid": "edge-mapper",
4458
+ children: [view.unavailable && /* @__PURE__ */ jsx("p", {
4459
+ role: "status",
4460
+ className: "text-sm text-muted-foreground",
4461
+ "data-testid": "edge-mapper-no-fields",
4462
+ children: tr("fluidgrids.builder.edgeMapper.noDeclaredFields", "These steps declare no fields to map. Write the mapping in the JSON Editor, or run the workflow once to map fields from its real output.")
4463
+ }), /* @__PURE__ */ jsx(App, {
4464
+ dataConfig,
4465
+ sourceNode: keys.source,
4466
+ targetNode: keys.target,
4467
+ sourceOperation,
4468
+ targetOperation,
4469
+ sourceSchema: view.sourceSchema ?? void 0,
4470
+ targetSchema: view.targetSchema ?? void 0,
4471
+ storedMapping: view.storedMapping,
4472
+ onSaveMapping
4473
+ })]
4474
+ });
4475
+ }
4476
+
4477
+ export { EdgeMapper as default };