@elyx-code/editor-ui 0.0.2

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 (452) hide show
  1. package/README.md +2 -0
  2. package/package.json +109 -0
  3. package/src/App.tsx +31 -0
  4. package/src/Router.tsx +115 -0
  5. package/src/__mocks__/defaultModuleMock.ts +1 -0
  6. package/src/__mocks__/fileMock.ts +1 -0
  7. package/src/__mocks__/styleMock.ts +1 -0
  8. package/src/assets/Clock-11.1s-18px.svg +16 -0
  9. package/src/assets/Clock-11.1s-28px.svg +16 -0
  10. package/src/assets/authentication.svg +1 -0
  11. package/src/assets/canvas-backdrop-0.png +0 -0
  12. package/src/assets/canvas-backdrop-1.png +0 -0
  13. package/src/assets/canvas-backdrop-2.png +0 -0
  14. package/src/assets/canvas-backdrop-3.png +0 -0
  15. package/src/assets/canvas-backdrop-4.png +0 -0
  16. package/src/assets/canvas-backdrop-5.png +0 -0
  17. package/src/assets/canvas-backdrop.png +0 -0
  18. package/src/assets/checkmark-animation.gif +0 -0
  19. package/src/assets/checkmark-animation.mp4 +0 -0
  20. package/src/assets/code-formatting/format-black.svg +6 -0
  21. package/src/assets/code-formatting/format-dark-grey.svg +6 -0
  22. package/src/assets/code-formatting/format-light-grey.svg +6 -0
  23. package/src/assets/code-formatting/format-white.svg +6 -0
  24. package/src/assets/code-formatting/inline-black.svg +5 -0
  25. package/src/assets/code-formatting/inline-dark-grey.svg +5 -0
  26. package/src/assets/code-formatting/inline-light-grey.svg +5 -0
  27. package/src/assets/code-formatting/inline-white.svg +5 -0
  28. package/src/assets/contained-logo-full-word.png +0 -0
  29. package/src/assets/cron-job-color.png +0 -0
  30. package/src/assets/cron-job.png +0 -0
  31. package/src/assets/database-table-color.png +0 -0
  32. package/src/assets/database-table.png +0 -0
  33. package/src/assets/datatype-icons/black/any.svg +1 -0
  34. package/src/assets/datatype-icons/black/binary.svg +1 -0
  35. package/src/assets/datatype-icons/black/boolean.svg +3 -0
  36. package/src/assets/datatype-icons/black/date-time.svg +3 -0
  37. package/src/assets/datatype-icons/black/definition-entity.svg +6 -0
  38. package/src/assets/datatype-icons/black/key-file.svg +1 -0
  39. package/src/assets/datatype-icons/black/list.svg +3 -0
  40. package/src/assets/datatype-icons/black/null.svg +3 -0
  41. package/src/assets/datatype-icons/black/number.svg +13 -0
  42. package/src/assets/datatype-icons/black/project.svg +12 -0
  43. package/src/assets/datatype-icons/black/sql-program.svg +2 -0
  44. package/src/assets/datatype-icons/black/text.svg +3 -0
  45. package/src/assets/datatype-icons/black/unknown.svg +3 -0
  46. package/src/assets/datatype-icons/black/uuid.svg +4 -0
  47. package/src/assets/datatype-icons/black/void.svg +1 -0
  48. package/src/assets/datatype-icons/dark-grey/any.svg +1 -0
  49. package/src/assets/datatype-icons/dark-grey/boolean.svg +3 -0
  50. package/src/assets/datatype-icons/dark-grey/date-time.svg +3 -0
  51. package/src/assets/datatype-icons/dark-grey/definition-entity.svg +6 -0
  52. package/src/assets/datatype-icons/dark-grey/list.svg +3 -0
  53. package/src/assets/datatype-icons/dark-grey/null.svg +3 -0
  54. package/src/assets/datatype-icons/dark-grey/number.svg +13 -0
  55. package/src/assets/datatype-icons/dark-grey/project.svg +12 -0
  56. package/src/assets/datatype-icons/dark-grey/sql-program.svg +2 -0
  57. package/src/assets/datatype-icons/dark-grey/text.svg +3 -0
  58. package/src/assets/datatype-icons/dark-grey/unknown.svg +3 -0
  59. package/src/assets/datatype-icons/dark-grey/uuid.svg +4 -0
  60. package/src/assets/datatype-icons/dark-grey/void.svg +1 -0
  61. package/src/assets/datatype-icons/light-grey/any.svg +1 -0
  62. package/src/assets/datatype-icons/light-grey/boolean.svg +3 -0
  63. package/src/assets/datatype-icons/light-grey/date-time.svg +3 -0
  64. package/src/assets/datatype-icons/light-grey/definition-entity.svg +6 -0
  65. package/src/assets/datatype-icons/light-grey/list.svg +3 -0
  66. package/src/assets/datatype-icons/light-grey/null.svg +3 -0
  67. package/src/assets/datatype-icons/light-grey/number.svg +13 -0
  68. package/src/assets/datatype-icons/light-grey/project.svg +12 -0
  69. package/src/assets/datatype-icons/light-grey/sql-program.svg +2 -0
  70. package/src/assets/datatype-icons/light-grey/text.svg +3 -0
  71. package/src/assets/datatype-icons/light-grey/unknown.svg +3 -0
  72. package/src/assets/datatype-icons/light-grey/uuid.svg +4 -0
  73. package/src/assets/datatype-icons/light-grey/void.svg +1 -0
  74. package/src/assets/edit.png +0 -0
  75. package/src/assets/execution.svg +13 -0
  76. package/src/assets/favicon.svg +14 -0
  77. package/src/assets/file-search.svg +1 -0
  78. package/src/assets/http-endpoint.png +0 -0
  79. package/src/assets/image-input-placeholder.png +0 -0
  80. package/src/assets/logo-full-word-white.png +0 -0
  81. package/src/assets/logo-full-word.png +0 -0
  82. package/src/assets/password.svg +85 -0
  83. package/src/assets/pencil.png +0 -0
  84. package/src/assets/publish-project-rich-icon-2.svg +1 -0
  85. package/src/assets/publish-project-rich-icon.svg +1 -0
  86. package/src/assets/relational-database.png +0 -0
  87. package/src/assets/resources.svg +3 -0
  88. package/src/assets/resume-icon-14px.png +0 -0
  89. package/src/assets/server.png +0 -0
  90. package/src/assets/small-status/checkmark.svg +4 -0
  91. package/src/assets/small-status/error.svg +4 -0
  92. package/src/assets/small-status/loading.svg +4 -0
  93. package/src/assets/small-status/skipped.svg +11 -0
  94. package/src/assets/sql-connection-config.svg +1 -0
  95. package/src/assets/sql-row-transformer.svg +1 -0
  96. package/src/assets/ssl-certificate-config.svg +1 -0
  97. package/src/assets/sync.svg +1 -0
  98. package/src/assets/testing-logic-icon.svg +1 -0
  99. package/src/assets/versions.svg +25 -0
  100. package/src/assets/visual-programming-icon.svg +1 -0
  101. package/src/assets/warning-sign-24px.png +0 -0
  102. package/src/auth/index.ts +318 -0
  103. package/src/components/DialogLoader.tsx +94 -0
  104. package/src/components/EntityDialogHeader.tsx +110 -0
  105. package/src/components/EntityDialogSectionHeader.tsx +214 -0
  106. package/src/components/GalleryAddExternalIntegrationInfoDialog.tsx +87 -0
  107. package/src/components/GenerateProjectStartingLogicPromptDialog.tsx +281 -0
  108. package/src/components/LegacyRouteRedirector.tsx +55 -0
  109. package/src/components/ProPlanChip.tsx +23 -0
  110. package/src/components/ReportBugDialog.tsx +412 -0
  111. package/src/components/RequestIntegrationAccessDialog.tsx +261 -0
  112. package/src/components/UseTemplateProjectDialog.tsx +193 -0
  113. package/src/components/WorkspaceLayout.tsx +152 -0
  114. package/src/components/animated-svg/AnimatedCheckmark.tsx +41 -0
  115. package/src/components/animated-svg/AnimatedCrossmark.tsx +51 -0
  116. package/src/components/animated-svg/AnimatedEmailSending.tsx +38 -0
  117. package/src/components/animated-svg/AnimatedLoading.tsx +72 -0
  118. package/src/components/animated-svg/animated-svg.css +239 -0
  119. package/src/components/canvas/Canvas.tsx +16 -0
  120. package/src/components/canvas/CreateEntityMenu.tsx +2020 -0
  121. package/src/components/canvas/canvas.css +10 -0
  122. package/src/components/canvas/create-entity-menu.css +579 -0
  123. package/src/components/canvas-search/CanvasSearch.tsx +501 -0
  124. package/src/components/canvas-search/canvas-search.css +126 -0
  125. package/src/components/canvas-settings-menu/CanvasSettingsMenuButton.tsx +515 -0
  126. package/src/components/canvas-settings-menu/canvas-settings-menu.css +96 -0
  127. package/src/components/circular-image-upload/CircularImageUpload.tsx +113 -0
  128. package/src/components/circular-image-upload/circular-image-upload.css +69 -0
  129. package/src/components/costs/CostsDialog.tsx +459 -0
  130. package/src/components/data-type/DataTypeBuilder.tsx +3127 -0
  131. package/src/components/data-type/data-type-builder.css +45 -0
  132. package/src/components/dialogs/BetaAcknowledgeDialog.tsx +43 -0
  133. package/src/components/dialogs/ComplexDataDialog.tsx +458 -0
  134. package/src/components/dialogs/CronBuilderDialog.tsx +2145 -0
  135. package/src/components/dialogs/ExternalIntegrationConnections.tsx +565 -0
  136. package/src/components/dialogs/JsonEditorDialog.tsx +1392 -0
  137. package/src/components/dialogs/StringEditorDialog.tsx +268 -0
  138. package/src/components/dialogs/argument-declaration/ArgumentDeclaration.tsx +1167 -0
  139. package/src/components/dialogs/argument-declaration/ArgumentDeclarationDialogContent.tsx +128 -0
  140. package/src/components/dialogs/beta-dialog.css +165 -0
  141. package/src/components/dialogs/condition/Condition.tsx +431 -0
  142. package/src/components/dialogs/condition/ConditionDialogContent.tsx +126 -0
  143. package/src/components/dialogs/definition-entity/DefinitionEntityDialogContent.tsx +973 -0
  144. package/src/components/dialogs/function-call/FunctionCall.tsx +442 -0
  145. package/src/components/dialogs/function-call/FunctionCallDialogContent.tsx +126 -0
  146. package/src/components/dialogs/function-declaration/FunctionDeclaration.tsx +926 -0
  147. package/src/components/dialogs/function-declaration/FunctionDeclarationDialogContent.tsx +124 -0
  148. package/src/components/dialogs/generating-project-starting-logic-overlay/GeneratingProjectStartingLogicOverlay.tsx +176 -0
  149. package/src/components/dialogs/generating-project-starting-logic-overlay/generating-project-starting-logic-overlay.css +13 -0
  150. package/src/components/dialogs/global-event/GlobalEvent.tsx +475 -0
  151. package/src/components/dialogs/global-event/GlobalEventDialogContent.tsx +126 -0
  152. package/src/components/dialogs/help/HelpDialog.tsx +217 -0
  153. package/src/components/dialogs/help/HelpDilalogHomeContent.tsx +178 -0
  154. package/src/components/dialogs/help/help-dialog.css +116 -0
  155. package/src/components/dialogs/help/help-icon/HelpIconButton.tsx +41 -0
  156. package/src/components/dialogs/help/help-icon/help-icon.css +9 -0
  157. package/src/components/dialogs/input-map/InputMap.tsx +635 -0
  158. package/src/components/dialogs/input-map/InputMapDialogContent.tsx +126 -0
  159. package/src/components/dialogs/json-editor-dialog.css +4 -0
  160. package/src/components/dialogs/loop/Loop.tsx +650 -0
  161. package/src/components/dialogs/loop/LoopDialogContent.tsx +122 -0
  162. package/src/components/dialogs/operation/Operation.tsx +440 -0
  163. package/src/components/dialogs/operation/OperationDialogContent.tsx +126 -0
  164. package/src/components/dialogs/output-map/OutputMap.tsx +536 -0
  165. package/src/components/dialogs/output-map/OutputMapDialogContent.tsx +126 -0
  166. package/src/components/dialogs/property/Property.tsx +1490 -0
  167. package/src/components/dialogs/property/PropertyDialogContent.tsx +106 -0
  168. package/src/components/dialogs/search-statement/ColumnSelector.tsx +334 -0
  169. package/src/components/dialogs/search-statement/ConditionBuilder.tsx +750 -0
  170. package/src/components/dialogs/search-statement/DataAggregationSection.tsx +621 -0
  171. package/src/components/dialogs/search-statement/DataSourceSelection.tsx +734 -0
  172. package/src/components/dialogs/search-statement/EntityMetadataSection.tsx +135 -0
  173. package/src/components/dialogs/search-statement/FilterConditionsSection.tsx +151 -0
  174. package/src/components/dialogs/search-statement/InlineInputMap.tsx +153 -0
  175. package/src/components/dialogs/search-statement/LiteralValue.tsx +616 -0
  176. package/src/components/dialogs/search-statement/MainSourceAndInputsSection.tsx +271 -0
  177. package/src/components/dialogs/search-statement/NestedSearchStatementBuilder.tsx +170 -0
  178. package/src/components/dialogs/search-statement/OutputFormatSection.tsx +1779 -0
  179. package/src/components/dialogs/search-statement/ResultsSection.tsx +344 -0
  180. package/src/components/dialogs/search-statement/SearchStatementBuilder.tsx +251 -0
  181. package/src/components/dialogs/search-statement/SearchStatementDialogContent.tsx +398 -0
  182. package/src/components/dialogs/search-statement/ValueSelector.tsx +766 -0
  183. package/src/components/dialogs/search-statement/search-statement-context.tsx +1630 -0
  184. package/src/components/dialogs/search-statement/search-statement-dialog.css +56 -0
  185. package/src/components/dialogs/search-statement/test.sql +111 -0
  186. package/src/components/dialogs/value-descriptor/ValueDescriptor.tsx +824 -0
  187. package/src/components/dialogs/value-descriptor/ValueDescriptorDialogContent.tsx +124 -0
  188. package/src/components/dialogs/variable-declaration/VariableDeclaration.tsx +836 -0
  189. package/src/components/dialogs/variable-declaration/VariableDeclarationDialogContent.tsx +106 -0
  190. package/src/components/dialogs/variable-instance/VariableInstance.tsx +443 -0
  191. package/src/components/dialogs/variable-instance/VariableInstanceDialogContent.tsx +124 -0
  192. package/src/components/draggable-entity-card/ArgumentDeclaration.tsx +736 -0
  193. package/src/components/draggable-entity-card/CollapseEntityButton.tsx +170 -0
  194. package/src/components/draggable-entity-card/ConditionCard.tsx +1062 -0
  195. package/src/components/draggable-entity-card/ConnectionDeleteButton.tsx +309 -0
  196. package/src/components/draggable-entity-card/DataTypeIcon.tsx +624 -0
  197. package/src/components/draggable-entity-card/DraggableEntityCard.tsx +617 -0
  198. package/src/components/draggable-entity-card/ErrorMapProperty.tsx +464 -0
  199. package/src/components/draggable-entity-card/EventCard.tsx +700 -0
  200. package/src/components/draggable-entity-card/ExecutionInProgressValue.tsx +327 -0
  201. package/src/components/draggable-entity-card/FunctionDeclarationCard.tsx +819 -0
  202. package/src/components/draggable-entity-card/InputMapProperty.tsx +1067 -0
  203. package/src/components/draggable-entity-card/InternalCall.tsx +978 -0
  204. package/src/components/draggable-entity-card/InternalCallExecutionNode.tsx +643 -0
  205. package/src/components/draggable-entity-card/LogicScopeCallerNode.tsx +262 -0
  206. package/src/components/draggable-entity-card/LoopCard.tsx +791 -0
  207. package/src/components/draggable-entity-card/MainValueInput.tsx +523 -0
  208. package/src/components/draggable-entity-card/MainValueOutput.tsx +458 -0
  209. package/src/components/draggable-entity-card/MethodDeclaration.tsx +1088 -0
  210. package/src/components/draggable-entity-card/NestedCondition.tsx +1025 -0
  211. package/src/components/draggable-entity-card/OutputMapProperty.tsx +843 -0
  212. package/src/components/draggable-entity-card/PassthroughEntityCard.tsx +1247 -0
  213. package/src/components/draggable-entity-card/ReturnedError.tsx +549 -0
  214. package/src/components/draggable-entity-card/SmallSuccessFailureNodes.tsx +523 -0
  215. package/src/components/draggable-entity-card/SuccessFailureNodes.tsx +509 -0
  216. package/src/components/draggable-entity-card/TestEntityButton.tsx +946 -0
  217. package/src/components/draggable-entity-card/TestMenu.tsx +523 -0
  218. package/src/components/draggable-entity-card/TestMenuValidationDropdown.tsx +84 -0
  219. package/src/components/draggable-entity-card/UnreachableMarker.tsx +114 -0
  220. package/src/components/draggable-entity-card/VariableCard.tsx +1577 -0
  221. package/src/components/draggable-entity-card/VariableScopeMarker.tsx +117 -0
  222. package/src/components/draggable-entity-card/collapse-entity-button.css +44 -0
  223. package/src/components/draggable-entity-card/definition-entity/DefinitionEntityCard.tsx +1181 -0
  224. package/src/components/draggable-entity-card/definition-entity/DefinitionEntityIcon.tsx +36 -0
  225. package/src/components/draggable-entity-card/definition-entity/DefinitionEntityProperty.tsx +478 -0
  226. package/src/components/draggable-entity-card/definition-entity/DynamicFooterActions.tsx +112 -0
  227. package/src/components/draggable-entity-card/definition-entity/actions/external-integration-connection/ExportCredentialsFooterAction.tsx +461 -0
  228. package/src/components/draggable-entity-card/definition-entity/actions/external-integration-connection/RestablishConnectionFooterAction.tsx +199 -0
  229. package/src/components/draggable-entity-card/definition-entity/actions/external-integration-connection/restablish-connection-footer-action.css +85 -0
  230. package/src/components/draggable-entity-card/definition-entity/actions/google-drive/GoogleDriveFilePickerAPIFooterAction.tsx +277 -0
  231. package/src/components/draggable-entity-card/definition-entity/actions/google-drive/google-drive-file-picker-api-footer-action.css +107 -0
  232. package/src/components/draggable-entity-card/definition-entity/actions/persisted-entity/DatabaseFooterAction.tsx +452 -0
  233. package/src/components/draggable-entity-card/definition-entity/actions/persisted-entity/database-footer-action.css +86 -0
  234. package/src/components/draggable-entity-card/definition-entity/definition-entity-card.css +17 -0
  235. package/src/components/draggable-entity-card/draggable-entity-card.css +1140 -0
  236. package/src/components/draggable-entity-card/entity-locked-icon/EntityLockedIcon.tsx +133 -0
  237. package/src/components/draggable-entity-card/entity-locked-icon/entity-locked.css +8 -0
  238. package/src/components/draggable-entity-card/expand-properties-icon-button/ExpandPropertiesIconButton.tsx +84 -0
  239. package/src/components/draggable-entity-card/expand-properties-icon-button/expand-properties-icon-button.css +21 -0
  240. package/src/components/draggable-entity-card/implement-entity-icon/ImplementEntityIcon.tsx +74 -0
  241. package/src/components/draggable-entity-card/implement-entity-icon/implement-entity-icon.css +13 -0
  242. package/src/components/draggable-entity-card/logic-error/LogicErrorIconMenu.tsx +424 -0
  243. package/src/components/draggable-entity-card/logic-error/logic-error.css +23 -0
  244. package/src/components/draggable-entity-card/new-card-input-button/NewCardInputButton.tsx +193 -0
  245. package/src/components/draggable-entity-card/new-card-input-button/NewDynamicInputButton.tsx +214 -0
  246. package/src/components/draggable-entity-card/new-card-input-button/new-card-input-button.css +71 -0
  247. package/src/components/draggable-entity-card/new-card-output-button/NewCardOutputButton.tsx +192 -0
  248. package/src/components/draggable-entity-card/new-card-output-button/new-card-output-button.css +71 -0
  249. package/src/components/draggable-entity-card/termination-statement/TerminationStatementCard.tsx +1543 -0
  250. package/src/components/draggable-entity-card/termination-statement/termination-statement-card.css +17 -0
  251. package/src/components/draggable-entity-card/test-entity-button.css +55 -0
  252. package/src/components/draggable-entity-card/test-menu.css +181 -0
  253. package/src/components/draggable-entity-card/unreachable-marker.css +43 -0
  254. package/src/components/draggable-entity-card/variable-scope-marker.css +22 -0
  255. package/src/components/dynamic-value/DynamicValue.tsx +2395 -0
  256. package/src/components/dynamic-value/DynamicValueEntry.tsx +1957 -0
  257. package/src/components/dynamic-value/dynamic-value.css +230 -0
  258. package/src/components/editor/ElyxMonacoEditor.tsx +38 -0
  259. package/src/components/entity-error/EntityErrorListItem.tsx +47 -0
  260. package/src/components/entity-error/entity-error.css +198 -0
  261. package/src/components/entity-icon/EntityIcon.tsx +292 -0
  262. package/src/components/entity-icon/entity-icon.css +39 -0
  263. package/src/components/gallery-card/CreateNewProject.tsx +222 -0
  264. package/src/components/gallery-card/GalleryCard.tsx +171 -0
  265. package/src/components/gallery-card/MarketplaceCard.tsx +87 -0
  266. package/src/components/gallery-card/ProjectDuplicationCard.tsx +575 -0
  267. package/src/components/gallery-card/gallery-card.css +25 -0
  268. package/src/components/notifications/NotificationsIconButton.tsx +124 -0
  269. package/src/components/notifications/NotificationsPanel.tsx +385 -0
  270. package/src/components/notifications/notifications.css +189 -0
  271. package/src/components/online-users/LocalOnlineUsers.tsx +175 -0
  272. package/src/components/online-users/PageOnlineUsers.tsx +297 -0
  273. package/src/components/online-users/online-users.css +72 -0
  274. package/src/components/page-backdrop/PageBackdrop.tsx +8 -0
  275. package/src/components/page-backdrop/page-backdrop.css +7 -0
  276. package/src/components/project-configuration/DeleteProjectConfirmationDialog.tsx +134 -0
  277. package/src/components/project-configuration/ProjectConfigurationDialog.tsx +972 -0
  278. package/src/components/project-configuration/ProjectDataForm.tsx +121 -0
  279. package/src/components/project-configuration/UnpublishProjectConfirmationDialog.tsx +162 -0
  280. package/src/components/project-configuration/project-configuration-content.css +209 -0
  281. package/src/components/project-name/ProjectName.tsx +2025 -0
  282. package/src/components/project-name/project-name.css +599 -0
  283. package/src/components/publishing/Publication.tsx +133 -0
  284. package/src/components/publishing/history/PublicationHistoryContent.tsx +414 -0
  285. package/src/components/publishing/history/PublicationHistoryDialog.tsx +234 -0
  286. package/src/components/publishing/preview/PublicationPreviewDialog.tsx +1158 -0
  287. package/src/components/publishing/preview/PublishingPriceForecast.tsx +160 -0
  288. package/src/components/publishing/preview/PublishingResourcesDetails.tsx +91 -0
  289. package/src/components/publishing/publication-sequence/PublishingSequenceContent.tsx +375 -0
  290. package/src/components/publishing/publication-sequence/PublishingSequenceDialog.tsx +344 -0
  291. package/src/components/publishing/publishing-dialog.css +142 -0
  292. package/src/components/publishing/utils.ts +227 -0
  293. package/src/components/resources/ResourcesDialog.tsx +591 -0
  294. package/src/components/resources/UpgradeBanner.tsx +102 -0
  295. package/src/components/resources/codebase/CodebaseDetails.tsx +156 -0
  296. package/src/components/resources/cron-job/CronJobsList.tsx +532 -0
  297. package/src/components/resources/functions/FunctionsList.tsx +454 -0
  298. package/src/components/resources/http-api/HttpAPI.tsx +566 -0
  299. package/src/components/resources/http-api/HttpAPIClientModule.tsx +37 -0
  300. package/src/components/resources/logs/LogsViewer.tsx +768 -0
  301. package/src/components/resources/query.ts +74 -0
  302. package/src/components/resources/relational-database/DatabaseTable.tsx +905 -0
  303. package/src/components/resources/relational-database/RelationalDatabase.tsx +83 -0
  304. package/src/components/resources/relational-database/RelationalDatabaseSecrets.tsx +361 -0
  305. package/src/components/resources/resources-dialog.css +74 -0
  306. package/src/components/test-relational-database/DatabaseTable.tsx +913 -0
  307. package/src/components/test-relational-database/TestDatabaseDialogContent.tsx +670 -0
  308. package/src/components/test-relational-database/query.ts +74 -0
  309. package/src/components/toolbar/ToolBar.tsx +236 -0
  310. package/src/components/toolbar/toolbar.css +78 -0
  311. package/src/components/transaction-history/TransactionHistoryDialog.tsx +268 -0
  312. package/src/components/user/CurrentUserAvatar.tsx +65 -0
  313. package/src/components/user/UserChip.tsx +62 -0
  314. package/src/components/user/user.css +39 -0
  315. package/src/components/user-profile/ChangePasswordForm.tsx +67 -0
  316. package/src/components/user-profile/OwnUserProfileContent.tsx +665 -0
  317. package/src/components/user-profile/PublicUserProfileContent.tsx +99 -0
  318. package/src/components/user-profile/UserDataForm.tsx +75 -0
  319. package/src/components/user-profile/UserProfileDialog.tsx +110 -0
  320. package/src/components/user-profile/user-profile-content.css +25 -0
  321. package/src/config.ts +130 -0
  322. package/src/globals.d.ts +13 -0
  323. package/src/index.html +27 -0
  324. package/src/index.tsx +23 -0
  325. package/src/lib/badge/Badge.tsx +35 -0
  326. package/src/lib/badge/badge.css +32 -0
  327. package/src/lib/button/Button.tsx +129 -0
  328. package/src/lib/button/button.css +145 -0
  329. package/src/lib/canvas/canvas-undo-redo.ts +263 -0
  330. package/src/lib/canvas/defs.ts +170 -0
  331. package/src/lib/canvas/index.test.ts +189 -0
  332. package/src/lib/canvas/index.ts +6999 -0
  333. package/src/lib/canvas/utils.ts +59 -0
  334. package/src/lib/card/Card.tsx +62 -0
  335. package/src/lib/card/LoadingCard.tsx +82 -0
  336. package/src/lib/card/card.css +259 -0
  337. package/src/lib/chip/Chip.tsx +79 -0
  338. package/src/lib/chip/chip.css +0 -0
  339. package/src/lib/dialog/Dialog.tsx +122 -0
  340. package/src/lib/dialog/SmallDialog.tsx +61 -0
  341. package/src/lib/dialog/dialog.css +40 -0
  342. package/src/lib/display-data-structure/index.tsx +21 -0
  343. package/src/lib/dropdown/CanvasDropdownMenuCard.tsx +68 -0
  344. package/src/lib/dropdown/CanvasDropdownMenuCardOption.tsx +136 -0
  345. package/src/lib/dropdown/DropdownButton.tsx +104 -0
  346. package/src/lib/dropdown/DropdownMenuCard.tsx +324 -0
  347. package/src/lib/dropdown/DropdownMenuPopup.tsx +27 -0
  348. package/src/lib/dropdown/dropdown-button.css +76 -0
  349. package/src/lib/dropdown/dropdown-menu.css +151 -0
  350. package/src/lib/json-editor/RawJsonEditor.tsx +137 -0
  351. package/src/lib/json-editor/json-editor.css +35 -0
  352. package/src/lib/loader/Loader.tsx +120 -0
  353. package/src/lib/loader/loader.css +38 -0
  354. package/src/lib/pagination/Pagination.tsx +64 -0
  355. package/src/lib/popup/CanvasPopupBaseComponent.tsx +103 -0
  356. package/src/lib/popup/Popup.tsx +243 -0
  357. package/src/lib/popup/popup.css +16 -0
  358. package/src/lib/table/RowForm.tsx +301 -0
  359. package/src/lib/table/Table.tsx +1069 -0
  360. package/src/lib/table/table.css +249 -0
  361. package/src/lib/table/types.ts +108 -0
  362. package/src/lib/text-area/TextArea.tsx +183 -0
  363. package/src/lib/text-area/text-area.css +156 -0
  364. package/src/lib/text-field/TextField.tsx +218 -0
  365. package/src/lib/text-field/index.ts +8 -0
  366. package/src/lib/text-field/text-field.css +201 -0
  367. package/src/lib/tooltip/Tooltip.tsx +24 -0
  368. package/src/lib/tooltip/tooltip.css +17 -0
  369. package/src/localization/index.ts +47 -0
  370. package/src/main.css +343 -0
  371. package/src/pages/Auth.tsx +848 -0
  372. package/src/pages/Editor.tsx +883 -0
  373. package/src/pages/ErrorPage.tsx +179 -0
  374. package/src/pages/Gallery.tsx +1693 -0
  375. package/src/pages/NewPaymentMethodCallback.tsx +53 -0
  376. package/src/pages/NotFoundPage.tsx +126 -0
  377. package/src/pages/PricingPlans.tsx +155 -0
  378. package/src/pages/auth.css +304 -0
  379. package/src/pages/gallery.css +421 -0
  380. package/src/payments/index.ts +187 -0
  381. package/src/popup-notification/index.ts +90 -0
  382. package/src/services/database/index.ts +1 -0
  383. package/src/services/database/utils.ts +1301 -0
  384. package/src/services/editor/CanvasElement.tsx +2934 -0
  385. package/src/services/editor/CanvasElementConnectionDeleteButton.ts +204 -0
  386. package/src/services/editor/CanvasPopup.tsx +749 -0
  387. package/src/services/editor/EditorService.ts +8157 -0
  388. package/src/services/editor/area.ts +1312 -0
  389. package/src/services/editor/connections.ts +1019 -0
  390. package/src/services/editor/create/condition.ts +25 -0
  391. package/src/services/editor/create/definition-entity.ts +29 -0
  392. package/src/services/editor/create/function-call.ts +25 -0
  393. package/src/services/editor/create/global-event.ts +33 -0
  394. package/src/services/editor/create/loop.ts +25 -0
  395. package/src/services/editor/create/operation.ts +30 -0
  396. package/src/services/editor/create/utils.ts +140 -0
  397. package/src/services/editor/create/variable-declaration.ts +135 -0
  398. package/src/services/editor/create/variable-instance.ts +100 -0
  399. package/src/services/editor/editor-ui-extensions-context.ts +43 -0
  400. package/src/services/editor/entities-metadata.json +9310 -0
  401. package/src/services/editor/icons.ts +1093 -0
  402. package/src/services/editor/index.ts +1 -0
  403. package/src/services/editor/layout.ts +102 -0
  404. package/src/services/editor/modules/built-in-function-implementations/base.ts +14 -0
  405. package/src/services/editor/modules/built-in-function-implementations/create-persisted-entity/index.ts +56 -0
  406. package/src/services/editor/modules/built-in-function-implementations/delete-persisted-entity/index.ts +55 -0
  407. package/src/services/editor/modules/built-in-function-implementations/index.ts +4 -0
  408. package/src/services/editor/modules/built-in-function-implementations/update-persisted-entity/index.ts +56 -0
  409. package/src/services/editor/modules/operations-implementations/external-integrations/google-drive/get-files.ts +183 -0
  410. package/src/services/editor/modules/operations-implementations/external-integrations/google-drive/list-drives.ts +124 -0
  411. package/src/services/editor/modules/operations-implementations/external-integrations/google-drive/list-root-folders.ts +125 -0
  412. package/src/services/editor/modules/operations-implementations/external-integrations/google-drive/smart-fetch-document.ts +702 -0
  413. package/src/services/editor/modules/operations-implementations/external-integrations/google-drive/upload-document.ts +535 -0
  414. package/src/services/editor/modules/operations-implementations/external-integrations/google-gemini/generate-content.ts +193 -0
  415. package/src/services/editor/modules/operations-implementations/external-integrations/google-mail/get-emails.ts +586 -0
  416. package/src/services/editor/modules/operations-implementations/external-integrations/google-mail/send-email.ts +386 -0
  417. package/src/services/editor/modules/operations-implementations/external-integrations/index.ts +12 -0
  418. package/src/services/editor/modules/operations-implementations/external-integrations/slack/channels.ts +240 -0
  419. package/src/services/editor/modules/operations-implementations/external-integrations/slack/messages.ts +210 -0
  420. package/src/services/editor/modules/operations-implementations/external-integrations/slack/replies.ts +200 -0
  421. package/src/services/editor/modules/operations-implementations/external-integrations/slack/send-message.ts +177 -0
  422. package/src/services/editor/modules/operations-implementations/index.ts +1 -0
  423. package/src/services/editor/modules/search-node-implementation/index.ts +42 -0
  424. package/src/services/editor/modules/sql-migrations-generation.tsx +1054 -0
  425. package/src/services/editor/publication/publication.ts +578 -0
  426. package/src/services/editor/ui.ts +1348 -0
  427. package/src/services/editor/utils.ts +5868 -0
  428. package/src/services/editor/value-store.ts +619 -0
  429. package/src/services/execution/built-in-function-implementations.ts +422 -0
  430. package/src/services/execution/index.ts +4747 -0
  431. package/src/services/execution/logic.ts +121 -0
  432. package/src/services/execution/test-instance.tsx +2296 -0
  433. package/src/services/execution/utils.ts +33 -0
  434. package/src/services/execution/value-resolution.test.ts +424 -0
  435. package/src/services/execution/value-resolution.ts +4087 -0
  436. package/src/services/integrations/ExternalIntegrationsService.ts +439 -0
  437. package/src/services/integrations/api.ts +175 -0
  438. package/src/services/local-relational-database/idb_helper.ts +66 -0
  439. package/src/services/local-relational-database/index.ts +3308 -0
  440. package/src/services/local-relational-database/utils.ts +403 -0
  441. package/src/services/notifications/index.ts +525 -0
  442. package/src/services/user/index.ts +144 -0
  443. package/src/setupTests.ts +1 -0
  444. package/src/socket/socket.ts +248 -0
  445. package/src/socket/utils.ts +10 -0
  446. package/src/store/workspace.ts +12 -0
  447. package/src/theme.ts +19 -0
  448. package/src/utils/DOM.ts +39 -0
  449. package/src/utils/date.ts +169 -0
  450. package/src/utils/index.ts +158 -0
  451. package/src/utils/react.tsx +679 -0
  452. package/src/utils/testing.ts +103 -0
@@ -0,0 +1,4087 @@
1
+ import {
2
+ EntityType,
3
+ PrimitiveTypes,
4
+ LiteralValueType,
5
+ UntypedObjectValue,
6
+ VARIABLE_TYPES,
7
+ ValueReadingEntityState,
8
+ VariableState,
9
+ generate,
10
+ toCamelCase,
11
+ ChangeSet,
12
+ ILiteralValueTransfer,
13
+ createStateFromTypeAndSubscribe,
14
+ ChangeSetEntityChangeType,
15
+ ValueAsTypeState,
16
+ getDeclaration,
17
+ UntypedValue,
18
+ DefinitionEntityState,
19
+ EntityId,
20
+ filterOutDuplicateEntities,
21
+ checkShouldInputOrOutputBePartOfFinalVariableObjectValue,
22
+ TERMINATION_TYPES,
23
+ EntityWithDefaultValueState,
24
+ checkIsLiteralValueEmpty,
25
+ ENTITY_WITH_DEFAULT_VALUE_TYPES,
26
+ PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS,
27
+ getParentCallableEntity,
28
+ CallableEntityState,
29
+ TerminationEntityState,
30
+ checkIsLiteralValueExplicitlyEmpty,
31
+ OperationState,
32
+ InternalCallState,
33
+ FunctionCallState,
34
+ checkIsRequiredValue,
35
+ SearchState,
36
+ ValueWritingEntityState,
37
+ checkIsNullable,
38
+ generatePlaceholderValueStore,
39
+ isObject,
40
+ BuiltInBaseEntityState,
41
+ OutputMapParentChildRelation,
42
+ resolveEntityName
43
+ } from '@elyx-code/project-logic-tree';
44
+ import {
45
+ ArgumentDeclarationState,
46
+ DraggableCallerEntityState,
47
+ DataTypeState,
48
+ EntityWithValueState,
49
+ DraggableExecutableEntityState,
50
+ OutputMapState,
51
+ InputMapState,
52
+ VariableDeclarationState,
53
+ VariableInstanceState,
54
+ ProjectState,
55
+ PropertyState,
56
+ ValueDescriptorState
57
+ } from '@elyx-code/project-logic-tree';
58
+ import {
59
+ DynamicValueTypes,
60
+ IDynamicValue,
61
+ IValueInheritanceLink,
62
+ IValueStoreClient
63
+ } from '../editor/value-store';
64
+ import { getParentCanvasEntity } from '@elyx-code/project-logic-tree';
65
+ import { LiteralValueState } from '@elyx-code/project-logic-tree';
66
+ import { safeResolveEntityName } from '@elyx-code/project-logic-tree';
67
+ import { Execution, ExecutionState } from '.';
68
+
69
+ const resolving = new Set<string>();
70
+
71
+ // A payload that is passed to the value resolution function
72
+ // To give optional context about the resolution of the value
73
+ // For example, if only a local values' store should be used
74
+ export interface IValueResolutionContext {
75
+ // Current execution instance in progress
76
+ execution?: Execution | null;
77
+ // The parent project
78
+ project: ProjectState;
79
+ // Local test values that the user can set in the canvas
80
+ localTestValues: IValueStoreClient;
81
+ // Resolved values cached so the calculation doesn't have to be done every time
82
+ resolvedValues: IValueStoreClient;
83
+ // Values saved from previous executions results
84
+ persistedExecutionResults: IValueStoreClient;
85
+ // Last execution results values from the last execution of their respective entities
86
+ // This values are temporary and used to save them to the 'persistedExecutionResults' or discard them after the execution
87
+ lastExecutionResults: IValueStoreClient;
88
+
89
+ // Value type preference for the resolution
90
+ getValueTypePreference: (
91
+ valueOwnerId: EntityId
92
+ ) => DynamicValueTypes.DefaultValue | DynamicValueTypes.Testing | null;
93
+ setValueTypePreference: (
94
+ valueOwnerId: EntityId,
95
+ valueTypePreference:
96
+ | DynamicValueTypes.DefaultValue
97
+ | DynamicValueTypes.Testing
98
+ | null
99
+ ) => void;
100
+ }
101
+
102
+ export function generatePlaceholderValueResolutionContext(
103
+ project: ProjectState
104
+ ): IValueResolutionContext {
105
+ return {
106
+ execution: null,
107
+ project: project,
108
+ localTestValues: generatePlaceholderValueStore(
109
+ 'local-test-values',
110
+ project
111
+ ),
112
+ resolvedValues: generatePlaceholderValueStore(
113
+ 'resolved-values',
114
+ project
115
+ ),
116
+ persistedExecutionResults: generatePlaceholderValueStore(
117
+ 'persisted-execution-results',
118
+ project
119
+ ),
120
+ lastExecutionResults: generatePlaceholderValueStore(
121
+ 'last-execution-results',
122
+ project
123
+ ),
124
+ getValueTypePreference: () => null,
125
+ setValueTypePreference: () => {}
126
+ };
127
+ }
128
+
129
+ export function assembleAndAddLiteralValueFromDataType(
130
+ dataType: DataTypeState | null,
131
+ valueOwner: EntityWithDefaultValueState,
132
+ project: ProjectState,
133
+ changeSet: ChangeSet | null
134
+ ): LiteralValueState {
135
+ // Find existing literal value instance
136
+ let primitiveTypeName: PrimitiveTypes;
137
+
138
+ if (dataType?.entity?.type === EntityType.PrimitiveEntity) {
139
+ switch (dataType.entity.name) {
140
+ case PrimitiveTypes.EntityTemplate:
141
+ primitiveTypeName = PrimitiveTypes.EntityTemplate;
142
+ break;
143
+ case PrimitiveTypes.String:
144
+ primitiveTypeName = PrimitiveTypes.String;
145
+ break;
146
+ case PrimitiveTypes.Number:
147
+ primitiveTypeName = PrimitiveTypes.Number;
148
+ break;
149
+ case PrimitiveTypes.Boolean:
150
+ primitiveTypeName = PrimitiveTypes.Boolean;
151
+ break;
152
+ case PrimitiveTypes.Null:
153
+ primitiveTypeName = PrimitiveTypes.Null;
154
+ break;
155
+ case PrimitiveTypes.Enum:
156
+ primitiveTypeName = PrimitiveTypes.Enum;
157
+ break;
158
+ case PrimitiveTypes.KeyValue:
159
+ primitiveTypeName = PrimitiveTypes.KeyValue;
160
+ break;
161
+ case PrimitiveTypes.Untyped:
162
+ primitiveTypeName = PrimitiveTypes.Untyped;
163
+ break;
164
+ case PrimitiveTypes.KeyValue:
165
+ primitiveTypeName = PrimitiveTypes.KeyValue;
166
+ break;
167
+ case PrimitiveTypes.Date:
168
+ primitiveTypeName = PrimitiveTypes.Date;
169
+ break;
170
+ case PrimitiveTypes.UUID:
171
+ primitiveTypeName = PrimitiveTypes.UUID;
172
+ break;
173
+ case PrimitiveTypes.File:
174
+ primitiveTypeName = PrimitiveTypes.File;
175
+ break;
176
+ case PrimitiveTypes.Void:
177
+ primitiveTypeName = PrimitiveTypes.Void;
178
+ break;
179
+ case PrimitiveTypes.ActionDescriptor:
180
+ primitiveTypeName = PrimitiveTypes.ActionDescriptor;
181
+ break;
182
+ case PrimitiveTypes.Bytes:
183
+ primitiveTypeName = PrimitiveTypes.Bytes;
184
+ break;
185
+ case PrimitiveTypes.SqlProgram:
186
+ primitiveTypeName = PrimitiveTypes.SqlProgram;
187
+ break;
188
+ default:
189
+ throw new Error(
190
+ `Primitive type ${safeResolveEntityName(
191
+ dataType.entity,
192
+ project
193
+ )} is not supported`
194
+ );
195
+ }
196
+ } else {
197
+ // This is a definition entity as a data type, so we always use an object
198
+ primitiveTypeName = PrimitiveTypes.Untyped;
199
+ }
200
+
201
+ const newLiteralValueTransfer: ILiteralValueTransfer =
202
+ LiteralValueState.new(changeSet);
203
+ newLiteralValueTransfer.name = primitiveTypeName;
204
+ newLiteralValueTransfer.parent = valueOwner.toReference();
205
+
206
+ const instance: LiteralValueState = createStateFromTypeAndSubscribe(
207
+ newLiteralValueTransfer,
208
+ project
209
+ ) as LiteralValueState;
210
+
211
+ instance.hydrateAncestors();
212
+
213
+ changeSet?.add(instance, ChangeSetEntityChangeType.Added);
214
+
215
+ instance.addSelfToProject(changeSet);
216
+ instance.initChildren(changeSet);
217
+
218
+ return instance;
219
+ }
220
+
221
+ export function getEntitiesToPropagateValuesTo(
222
+ entity: EntityWithValueState,
223
+ project: ProjectState,
224
+ seenInRecursion: Set<EntityId> = new Set<EntityId>()
225
+ ): EntityWithValueState[] {
226
+ if (seenInRecursion.has(entity.id)) {
227
+ return [];
228
+ }
229
+
230
+ seenInRecursion.add(entity.id);
231
+
232
+ if (VARIABLE_TYPES.includes(entity.type)) {
233
+ const declaration = getDeclaration(entity as VariableState);
234
+
235
+ // The value always goes only to the variable declaration, from which all instances read from
236
+ return filterOutDuplicateEntities([
237
+ declaration,
238
+ ...[declaration].flatMap((ent) =>
239
+ getEntitiesToPropagateValuesTo(ent, project, seenInRecursion)
240
+ )
241
+ ]) as EntityWithValueState[];
242
+ } else if (entity.type === EntityType.OutputMap) {
243
+ if (
244
+ VARIABLE_TYPES.includes(entity.parent.type) &&
245
+ entity.declaration?.type === EntityType.Property &&
246
+ entity.declaration.static
247
+ ) {
248
+ return filterOutDuplicateEntities([
249
+ entity,
250
+ entity.declaration,
251
+ ...[entity, entity.declaration].flatMap((ent) =>
252
+ getEntitiesToPropagateValuesTo(
253
+ ent,
254
+ project,
255
+ seenInRecursion
256
+ )
257
+ )
258
+ ]) as EntityWithValueState[];
259
+ }
260
+ } else if (entity.type === EntityType.InputMap) {
261
+ if (
262
+ VARIABLE_TYPES.includes(entity.parent.type) &&
263
+ entity.declaration?.type === EntityType.Property &&
264
+ entity.declaration?.static
265
+ ) {
266
+ return filterOutDuplicateEntities([
267
+ entity.declaration,
268
+ ...[entity.declaration].flatMap((ent) =>
269
+ getEntitiesToPropagateValuesTo(
270
+ ent,
271
+ project,
272
+ seenInRecursion
273
+ )
274
+ )
275
+ ]) as EntityWithValueState[];
276
+ }
277
+ // } else if (TERMINATION_TYPES.includes(entity.parent.type)) {
278
+ // const equivalentInputMaps = [entity, ...entity.getCounterparts()];
279
+
280
+ // return filterOutDuplicateEntities([
281
+ // ...equivalentInputMaps,
282
+ // ...equivalentInputMaps.flatMap((ent) =>
283
+ // getEntitiesToPropagateValuesTo(ent, project, seenInRecursion)
284
+ // ),
285
+ // ]) as EntityWithValueState[];
286
+ // }
287
+ } else if (entity.type === EntityType.ValueDescriptor) {
288
+ if (entity.parent?.type === EntityType.Search) {
289
+ const counterpartInputMap = (
290
+ entity.parent as SearchState
291
+ ).inputs.find((input) => input.declaration?.id === entity.id);
292
+
293
+ if (counterpartInputMap) {
294
+ return [counterpartInputMap];
295
+ }
296
+ }
297
+ }
298
+
299
+ return [entity];
300
+ }
301
+
302
+ /*
303
+ Values could be stale and no longer match the data-type of the entity
304
+ We need to check if the value is still valid,
305
+ if not, we attempt an auto-migration (when possible),
306
+ otherwise we discard the value and return `null`
307
+ */
308
+ export function hydrateOrDiscardLiteralValue(
309
+ value: LiteralValueState,
310
+ _valueOwner: EntityWithValueState,
311
+ _project: ProjectState
312
+ ): LiteralValueState | null {
313
+ return value;
314
+ }
315
+
316
+ export function readValueFromWritter(
317
+ entity: ValueReadingEntityState,
318
+ context: IValueResolutionContext,
319
+ onlyDefault = false
320
+ ): IDynamicValue | null {
321
+ const writerEntity = entity.readsValue;
322
+ let value: IDynamicValue | null = null;
323
+
324
+ const writersValue = resolveValue(
325
+ writerEntity as ValueWritingEntityState,
326
+ context,
327
+ onlyDefault
328
+ );
329
+
330
+ if (writersValue) {
331
+ const valueInheritanceLink: IValueInheritanceLink = {
332
+ sources: [writersValue],
333
+ target: entity
334
+ };
335
+
336
+ value = {
337
+ value: writersValue.value,
338
+ valueOwner: entity,
339
+ type: DynamicValueTypes.Inherited,
340
+ inheritanceLink: valueInheritanceLink
341
+ };
342
+ } else {
343
+ value = {
344
+ value: null,
345
+ valueOwner: entity,
346
+ type: DynamicValueTypes.Inherited,
347
+ inheritanceLink: null
348
+ };
349
+ }
350
+
351
+ return value;
352
+ }
353
+
354
+ export function assembleStandaloneLiteralValueFromDataType(
355
+ dataType: DataTypeState | null,
356
+ valueOwner: EntityWithValueState | ValueDescriptorState | PropertyState,
357
+ project: ProjectState
358
+ ): LiteralValueState | null {
359
+ if (!valueOwner) {
360
+ return null;
361
+ }
362
+
363
+ // Find existing literal value instance
364
+ let primitiveTypeName: PrimitiveTypes;
365
+
366
+ if (dataType?.entity?.type === EntityType.PrimitiveEntity) {
367
+ switch (dataType.entity.name) {
368
+ case PrimitiveTypes.EntityTemplate:
369
+ primitiveTypeName = PrimitiveTypes.EntityTemplate;
370
+ break;
371
+ case PrimitiveTypes.String:
372
+ primitiveTypeName = PrimitiveTypes.String;
373
+ break;
374
+ case PrimitiveTypes.Number:
375
+ primitiveTypeName = PrimitiveTypes.Number;
376
+ break;
377
+ case PrimitiveTypes.Boolean:
378
+ primitiveTypeName = PrimitiveTypes.Boolean;
379
+ break;
380
+ case PrimitiveTypes.Null:
381
+ primitiveTypeName = PrimitiveTypes.Null;
382
+ break;
383
+ case PrimitiveTypes.Enum:
384
+ primitiveTypeName = PrimitiveTypes.Enum;
385
+ break;
386
+ case PrimitiveTypes.KeyValue:
387
+ primitiveTypeName = PrimitiveTypes.KeyValue;
388
+ break;
389
+ case PrimitiveTypes.Untyped:
390
+ primitiveTypeName = PrimitiveTypes.Untyped;
391
+ break;
392
+ case PrimitiveTypes.KeyValue:
393
+ primitiveTypeName = PrimitiveTypes.KeyValue;
394
+ break;
395
+ case PrimitiveTypes.Date:
396
+ primitiveTypeName = PrimitiveTypes.Date;
397
+ break;
398
+ case PrimitiveTypes.UUID:
399
+ primitiveTypeName = PrimitiveTypes.UUID;
400
+ break;
401
+ case PrimitiveTypes.File:
402
+ primitiveTypeName = PrimitiveTypes.File;
403
+ break;
404
+ case PrimitiveTypes.Void:
405
+ primitiveTypeName = PrimitiveTypes.Void;
406
+ break;
407
+ case PrimitiveTypes.ActionDescriptor:
408
+ primitiveTypeName = PrimitiveTypes.ActionDescriptor;
409
+ break;
410
+ case PrimitiveTypes.Bytes:
411
+ primitiveTypeName = PrimitiveTypes.Bytes;
412
+ break;
413
+ case PrimitiveTypes.SqlProgram:
414
+ primitiveTypeName = PrimitiveTypes.SqlProgram;
415
+ break;
416
+ default:
417
+ throw new Error(
418
+ `Primitive type ${safeResolveEntityName(
419
+ dataType.entity,
420
+ project
421
+ )} is not supported`
422
+ );
423
+ }
424
+ } else {
425
+ // This is a definition entity as a data type, so we always use an object
426
+ primitiveTypeName = PrimitiveTypes.Untyped;
427
+ }
428
+
429
+ const valueOwnerIsInProject = project.get(valueOwner.id);
430
+
431
+ if (!valueOwnerIsInProject) {
432
+ return null;
433
+ }
434
+
435
+ const newLiteralValueTransfer: ILiteralValueTransfer =
436
+ LiteralValueState.new(null);
437
+ newLiteralValueTransfer.name = primitiveTypeName;
438
+ newLiteralValueTransfer.standaloneParent = valueOwner.toReference();
439
+
440
+ let instance: LiteralValueState = new LiteralValueState(
441
+ newLiteralValueTransfer,
442
+ project
443
+ );
444
+
445
+ instance.hydrateAncestors();
446
+ instance.standalone = true;
447
+ instance.setStandaloneParent(valueOwner, null);
448
+
449
+ instance.initChildren(null);
450
+
451
+ return instance;
452
+ }
453
+
454
+ export function resolvePassThroughCallableValue(
455
+ entity:
456
+ | OperationState
457
+ | InternalCallState
458
+ | FunctionCallState
459
+ | SearchState,
460
+ context: IValueResolutionContext,
461
+ onlyDefault = false
462
+ ): IDynamicValue | null {
463
+ if (
464
+ !!context.execution &&
465
+ context.execution.hasEntity(entity) &&
466
+ !onlyDefault
467
+ ) {
468
+ const lastExecutionValue = context.lastExecutionResults?.readValue(
469
+ entity.id
470
+ );
471
+
472
+ if (lastExecutionValue) {
473
+ const resolvedValue: IDynamicValue = {
474
+ value: lastExecutionValue,
475
+ valueOwner: entity,
476
+ type: DynamicValueTypes.ExecutionResult,
477
+ inheritanceLink: null
478
+ };
479
+
480
+ return resolvedValue;
481
+ }
482
+ }
483
+
484
+ const testValue = context.localTestValues?.readValue(entity.id);
485
+
486
+ const preferrerType = context.getValueTypePreference(entity.id);
487
+
488
+ if (
489
+ !!testValue &&
490
+ !onlyDefault &&
491
+ (preferrerType === null ||
492
+ preferrerType !== DynamicValueTypes.DefaultValue)
493
+ ) {
494
+ const resolvedValue: IDynamicValue = {
495
+ value: testValue,
496
+ valueOwner: entity,
497
+ type: DynamicValueTypes.Testing,
498
+ inheritanceLink: null
499
+ };
500
+
501
+ return resolvedValue;
502
+ }
503
+
504
+ return {
505
+ value: null,
506
+ valueOwner: entity,
507
+ type: DynamicValueTypes.QueuedAutocalculation,
508
+ inheritanceLink: null
509
+ };
510
+ }
511
+
512
+ export function aggregateVariableInputsValues(
513
+ objectData: UntypedObjectValue,
514
+ entity: VariableDeclarationState | TerminationEntityState,
515
+ context: IValueResolutionContext,
516
+ onlyDefault = false
517
+ ): UntypedObjectValue {
518
+ const workingObject: UntypedObjectValue = {
519
+ ...objectData
520
+ };
521
+ const inputs =
522
+ entity.type === EntityType.VariableDeclaration
523
+ ? entity.inputs
524
+ : TERMINATION_TYPES.includes(entity.type)
525
+ ? entity.outputs
526
+ : [];
527
+
528
+ if (!inputs || inputs.length === 0) {
529
+ return workingObject;
530
+ }
531
+
532
+ for (const input of inputs) {
533
+ if (!checkShouldInputOrOutputBePartOfFinalVariableObjectValue(input)) {
534
+ continue;
535
+ }
536
+
537
+ // We use the standalone value resolution directly
538
+ // so the value is not inherited from the parent which would cause an endless loop
539
+ const value = resolveInputMapStandaloneValue(
540
+ input,
541
+ context,
542
+ onlyDefault
543
+ );
544
+
545
+ if (value && value.value) {
546
+ try {
547
+ // Not 'safe' resolveEntityName because if it fails we want to know, and skip the property
548
+ const resolvedName = resolveEntityName(input, context.project);
549
+ const codeName =
550
+ input.codeName ||
551
+ input.declaration?.codeName ||
552
+ toCamelCase(resolvedName);
553
+
554
+ workingObject[codeName] = checkIsLiteralValueEmpty(
555
+ value?.value || null
556
+ )
557
+ ? workingObject[codeName]
558
+ : value?.value?.value;
559
+ } catch (error) {
560
+ // Do nothing, the name of the property couldn't be resolved, so we skip it
561
+ }
562
+ }
563
+ }
564
+
565
+ return workingObject;
566
+ }
567
+
568
+ export function aggregateVariableInputsNextValues(
569
+ objectData: UntypedObjectValue,
570
+ entity: VariableDeclarationState,
571
+ context: IValueResolutionContext,
572
+ onlyDefault = false
573
+ ): UntypedObjectValue {
574
+ const workingObject: UntypedObjectValue = {
575
+ ...objectData
576
+ };
577
+ const inputs = entity.inputs;
578
+
579
+ if (!inputs) {
580
+ return workingObject;
581
+ }
582
+
583
+ for (const input of inputs) {
584
+ if (!checkShouldInputOrOutputBePartOfFinalVariableObjectValue(input)) {
585
+ continue;
586
+ }
587
+
588
+ // We use the standalone value resolution directly
589
+ // so the value is not inherited from the parent which would cause an endless loop
590
+ const value = resolveInputMapNextStandaloneValue(
591
+ input,
592
+ context,
593
+ onlyDefault
594
+ );
595
+
596
+ if (value && value.value) {
597
+ const resolvedName = safeResolveEntityName(input, context.project);
598
+ const codeName =
599
+ input.codeName ||
600
+ input.declaration?.codeName ||
601
+ toCamelCase(resolvedName);
602
+ workingObject[codeName] = value?.value?.value;
603
+ }
604
+ }
605
+
606
+ return workingObject;
607
+ }
608
+
609
+ /*
610
+ When setting values of a variable in the canvas. The values will be distributed in the following order:
611
+ 1- The full value of the variabe is resolved first. From a connected value writer.
612
+ 2- The full value resolved, pre-existing value.
613
+ 3- Each input-map from their value writers.
614
+ 4- Each input-map pre-existing values.
615
+
616
+ All values wrtte to the variables value state, as the single source of truth. Any test values assigned to the input maps are deleted.
617
+ Static property inputs are skipped, they don't inherit its part of the value from the parent.
618
+ They need to be written directly.
619
+ */
620
+ export function resolveVarDeclarationNextAggregateObjectValue(
621
+ entity: VariableDeclarationState,
622
+ context: IValueResolutionContext,
623
+ onlyDefault = false
624
+ ): IDynamicValue | null {
625
+ // The working object to add data to
626
+ let initialDefaultValue: UntypedObjectValue = {};
627
+
628
+ if (
629
+ entity.getDataType(null)?.entity?.type === EntityType.DefinitionEntity
630
+ ) {
631
+ initialDefaultValue = {
632
+ ...initialDefaultValue,
633
+ ...(
634
+ entity.getDataType(null)?.entity as DefinitionEntityState
635
+ ).getActiveRawDefaultValue()
636
+ };
637
+ }
638
+
639
+ if (
640
+ !!context.execution &&
641
+ context.execution.hasEntity(entity) &&
642
+ !onlyDefault
643
+ ) {
644
+ const lastExecutionValue = context.lastExecutionResults?.readValue(
645
+ entity.id
646
+ );
647
+
648
+ if (lastExecutionValue) {
649
+ if (isObject(lastExecutionValue.value)) {
650
+ const aggregate = {
651
+ ...initialDefaultValue,
652
+ ...(lastExecutionValue.value as UntypedObjectValue)
653
+ };
654
+
655
+ const newRawValue = {
656
+ ...aggregateVariableInputsNextValues(
657
+ aggregate,
658
+ entity,
659
+ context,
660
+ onlyDefault
661
+ )
662
+ };
663
+
664
+ lastExecutionValue.metaSync(
665
+ {
666
+ value: newRawValue
667
+ },
668
+ null
669
+ );
670
+ }
671
+
672
+ const varDeclarationValue: IDynamicValue = {
673
+ value: lastExecutionValue,
674
+ valueOwner: entity,
675
+ type: DynamicValueTypes.ExecutionResult,
676
+ inheritanceLink: null
677
+ };
678
+
679
+ return varDeclarationValue;
680
+ }
681
+ }
682
+
683
+ const isThereActiveTest = !!context.execution?.entities.length;
684
+ const isPartOfTest = context.execution?.hasEntity(entity);
685
+
686
+ const writerEntity = entity.readsValue;
687
+ let value: IDynamicValue | null = null;
688
+
689
+ if (!!writerEntity) {
690
+ const isWriterPartOfTest = context.execution?.hasEntity(writerEntity);
691
+
692
+ // Should only read the value from the entity writing it, if:
693
+ const shouldInheritFromWriter =
694
+ // There isn't an active test
695
+ !isThereActiveTest ||
696
+ // Or there is an active test, and both entities are part of it
697
+ (isThereActiveTest && isWriterPartOfTest && isPartOfTest) ||
698
+ // Or there is an active test, but neither entity is a part it
699
+ (isThereActiveTest && !isWriterPartOfTest && !isPartOfTest);
700
+
701
+ if (shouldInheritFromWriter) {
702
+ value = readValueFromWritter(entity, context, onlyDefault);
703
+
704
+ // Aggregate the inputs values
705
+ if (value && value.value) {
706
+ if (isObject(value.value.value)) {
707
+ const aggregate = {
708
+ ...initialDefaultValue,
709
+ ...(value.value.value as UntypedObjectValue)
710
+ };
711
+
712
+ const newRawValue = {
713
+ ...aggregateVariableInputsNextValues(
714
+ aggregate,
715
+ entity,
716
+ context,
717
+ onlyDefault
718
+ )
719
+ };
720
+
721
+ value.value.metaSync(
722
+ {
723
+ value: newRawValue
724
+ },
725
+ null
726
+ );
727
+ }
728
+ }
729
+ }
730
+ }
731
+
732
+ const defaultValue = entity.defaultValue;
733
+ const preferrerType = context.getValueTypePreference(entity.id);
734
+
735
+ if (!value && defaultValue) {
736
+ const literalValue: LiteralValueState | null = defaultValue;
737
+
738
+ if (
739
+ literalValue &&
740
+ literalValue.value === null &&
741
+ !!literalValue.autogeneration
742
+ ) {
743
+ const autogeneratedValue = generate(literalValue);
744
+
745
+ literalValue.metaSync(
746
+ {
747
+ value: autogeneratedValue
748
+ },
749
+ null
750
+ );
751
+
752
+ if (isObject(autogeneratedValue)) {
753
+ const newRawValue = {
754
+ ...aggregateVariableInputsNextValues(
755
+ autogeneratedValue as UntypedObjectValue,
756
+ entity,
757
+ context,
758
+ onlyDefault
759
+ )
760
+ };
761
+
762
+ literalValue.metaSync(
763
+ {
764
+ value: newRawValue
765
+ },
766
+ null
767
+ );
768
+ }
769
+ }
770
+
771
+ if (
772
+ onlyDefault ||
773
+ preferrerType === null ||
774
+ preferrerType !== DynamicValueTypes.Testing
775
+ ) {
776
+ value = {
777
+ value: literalValue,
778
+ valueOwner: entity,
779
+ type: checkIsLiteralValueEmpty(literalValue)
780
+ ? !!entity.readsValue
781
+ ? DynamicValueTypes.Inherited
782
+ : DynamicValueTypes.Empty
783
+ : DynamicValueTypes.DefaultValue,
784
+ inheritanceLink: null
785
+ };
786
+ }
787
+ }
788
+
789
+ if (
790
+ !value ||
791
+ ((value.type === DynamicValueTypes.DefaultValue ||
792
+ value.type === DynamicValueTypes.External) &&
793
+ !onlyDefault) ||
794
+ preferrerType === DynamicValueTypes.Testing
795
+ ) {
796
+ const localTestValue = context.localTestValues?.readValue(entity.id);
797
+
798
+ if (!!localTestValue) {
799
+ if (isObject(localTestValue.value)) {
800
+ const aggregate = {
801
+ ...initialDefaultValue,
802
+ ...(localTestValue.value as UntypedObjectValue)
803
+ };
804
+
805
+ const newRawValue = {
806
+ ...aggregateVariableInputsNextValues(
807
+ aggregate,
808
+ entity,
809
+ context,
810
+ onlyDefault
811
+ )
812
+ };
813
+
814
+ localTestValue.metaSync(
815
+ {
816
+ value: newRawValue
817
+ },
818
+ null
819
+ );
820
+ }
821
+
822
+ return {
823
+ value: localTestValue,
824
+ valueOwner: entity,
825
+ type: DynamicValueTypes.Testing,
826
+ inheritanceLink: null
827
+ };
828
+ }
829
+ }
830
+
831
+ // Check if it is part of test but not required, then set as "empty"
832
+ if (checkIsLiteralValueEmpty(value?.value || null)) {
833
+ return {
834
+ value: null,
835
+ valueOwner: entity,
836
+ type: !!entity.readsValue
837
+ ? DynamicValueTypes.Inherited
838
+ : DynamicValueTypes.Empty,
839
+ inheritanceLink: null
840
+ };
841
+ }
842
+
843
+ return value;
844
+ }
845
+
846
+ /*
847
+ When variables' data-type is an object, with key-value pairs
848
+ The value of the variable is aggregated from different sources
849
+ The main variable's value as well as the collective resolved values of its inputs
850
+ */
851
+ export function resolveVarDeclarationAggregateObjectValue(
852
+ entity: VariableDeclarationState | TerminationEntityState,
853
+ context: IValueResolutionContext,
854
+ onlyDefault = false
855
+ ): IDynamicValue | null {
856
+ // The working object to add data to
857
+ let initialDefaultValue: UntypedObjectValue = {};
858
+
859
+ if (
860
+ entity.getDataType(null)?.entity?.type === EntityType.DefinitionEntity
861
+ ) {
862
+ initialDefaultValue = {
863
+ ...initialDefaultValue,
864
+ ...(
865
+ entity.getDataType(null)?.entity as DefinitionEntityState
866
+ ).getActiveRawDefaultValue()
867
+ };
868
+ } else if (
869
+ entity.getDataType(null)?.entity?.type === EntityType.BuiltInBaseEntity
870
+ ) {
871
+ initialDefaultValue = {
872
+ ...initialDefaultValue,
873
+ ...(
874
+ entity.getDataType(null)?.entity as BuiltInBaseEntityState
875
+ ).getRawDefaultValue()
876
+ };
877
+ }
878
+
879
+ if (
880
+ !!context.execution &&
881
+ context.execution.hasEntity(entity) &&
882
+ !onlyDefault
883
+ ) {
884
+ const lastExecutionValue = context.lastExecutionResults?.readValue(
885
+ entity.id
886
+ );
887
+
888
+ if (lastExecutionValue) {
889
+ if (isObject(lastExecutionValue.value)) {
890
+ const aggregate = {
891
+ ...initialDefaultValue,
892
+ ...(lastExecutionValue.value as UntypedObjectValue)
893
+ };
894
+
895
+ const valueWithAggregatedInputs = aggregateVariableInputsValues(
896
+ aggregate,
897
+ entity,
898
+ context,
899
+ onlyDefault
900
+ );
901
+
902
+ lastExecutionValue?.metaSync(
903
+ {
904
+ value: valueWithAggregatedInputs
905
+ },
906
+ null
907
+ );
908
+ }
909
+
910
+ const variableDeclarationValue: IDynamicValue = {
911
+ value: lastExecutionValue,
912
+ valueOwner: entity,
913
+ type: DynamicValueTypes.ExecutionResult,
914
+ inheritanceLink: null
915
+ };
916
+
917
+ return variableDeclarationValue;
918
+ }
919
+ }
920
+
921
+ const testValue = context.localTestValues?.readValue(entity.id);
922
+
923
+ let shouldInheritFromWriter = false;
924
+ if (entity.type === EntityType.VariableDeclaration) {
925
+ const varEntity = entity as VariableDeclarationState;
926
+ const isThereActiveTest = !!context.execution?.entities.length;
927
+ const isPartOfTest = context.execution?.hasEntity(entity);
928
+ const writerEntity = varEntity.readsValue;
929
+
930
+ if (!!writerEntity) {
931
+ const isWriterPartOfTest =
932
+ context.execution?.hasEntity(writerEntity);
933
+
934
+ shouldInheritFromWriter =
935
+ !isThereActiveTest ||
936
+ (isThereActiveTest && isWriterPartOfTest && isPartOfTest) ||
937
+ (isThereActiveTest && !isWriterPartOfTest && !isPartOfTest);
938
+ }
939
+ }
940
+
941
+ const preferrerType = context.getValueTypePreference(entity.id);
942
+
943
+ if (
944
+ !!testValue &&
945
+ !onlyDefault &&
946
+ (!shouldInheritFromWriter ||
947
+ preferrerType === DynamicValueTypes.Testing)
948
+ ) {
949
+ if (isObject(testValue.value)) {
950
+ const aggregate = {
951
+ ...initialDefaultValue,
952
+ ...(testValue.value as UntypedObjectValue)
953
+ };
954
+
955
+ const valueWithAggregatedInputs = aggregateVariableInputsValues(
956
+ aggregate,
957
+ entity,
958
+ context,
959
+ onlyDefault
960
+ );
961
+
962
+ testValue.metaSync(
963
+ {
964
+ value: valueWithAggregatedInputs
965
+ },
966
+ null
967
+ );
968
+ }
969
+
970
+ const variableDeclarationValue: IDynamicValue = {
971
+ value: testValue,
972
+ valueOwner: entity,
973
+ type: DynamicValueTypes.Testing,
974
+ inheritanceLink: null
975
+ };
976
+
977
+ return variableDeclarationValue;
978
+ }
979
+
980
+ if (
981
+ !!entity.getDataType(null)?.entity &&
982
+ (entity.getDataType(null)?.entity?.type ===
983
+ EntityType.DefinitionEntity ||
984
+ entity.getDataType(null)?.entity?.type ===
985
+ EntityType.BuiltInBaseEntity) &&
986
+ entity.getDataType(null)?.isObject()
987
+ ) {
988
+ const objectValue = assembleStandaloneLiteralValueFromDataType(
989
+ entity.dataType,
990
+ entity,
991
+ context.project
992
+ );
993
+
994
+ const valueWithAggregatedInputs = aggregateVariableInputsValues(
995
+ initialDefaultValue,
996
+ entity,
997
+ context,
998
+ onlyDefault
999
+ );
1000
+
1001
+ objectValue?.metaSync(
1002
+ {
1003
+ value: valueWithAggregatedInputs
1004
+ },
1005
+ null
1006
+ );
1007
+
1008
+ const variableDeclarationValue: IDynamicValue = {
1009
+ value: objectValue,
1010
+ valueOwner: entity,
1011
+ type: DynamicValueTypes.DefaultValue,
1012
+ inheritanceLink: null
1013
+ };
1014
+
1015
+ return variableDeclarationValue;
1016
+ }
1017
+
1018
+ return null;
1019
+ }
1020
+
1021
+ export function resolveVarDeclarationNextValue(
1022
+ entity: VariableDeclarationState,
1023
+ context: IValueResolutionContext,
1024
+ onlyDefault = false
1025
+ ): IDynamicValue | null {
1026
+ if (entity.dataType?.isObject()) {
1027
+ return resolveVarDeclarationNextAggregateObjectValue(
1028
+ entity,
1029
+ context,
1030
+ onlyDefault
1031
+ );
1032
+ }
1033
+
1034
+ const canvasParent = getParentCanvasEntity(entity) as
1035
+ | DraggableExecutableEntityState
1036
+ | DraggableCallerEntityState
1037
+ | VariableDeclarationState;
1038
+ const isThereActiveTest = !!context.execution?.entities.length;
1039
+ const isPartOfTest = context.execution?.hasEntity(canvasParent);
1040
+
1041
+ const writerEntity = entity.readsValue;
1042
+ let value: IDynamicValue | null = null;
1043
+
1044
+ if (!!writerEntity) {
1045
+ const isWriterPartOfTest = context.execution?.hasEntity(writerEntity);
1046
+
1047
+ // Should only read the value from the entity writing it, if:
1048
+ const shouldInheritFromWriter =
1049
+ // There isn't an active test
1050
+ !isThereActiveTest ||
1051
+ // Or there is an active test, and both entities are part of it
1052
+ (isThereActiveTest && isWriterPartOfTest && isPartOfTest) ||
1053
+ // Or there is an active test, but neither entity is a part it
1054
+ (isThereActiveTest && !isWriterPartOfTest && !isPartOfTest);
1055
+
1056
+ if (shouldInheritFromWriter) {
1057
+ value = readValueFromWritter(entity, context, onlyDefault);
1058
+ }
1059
+ }
1060
+
1061
+ const defaultValue = entity.defaultValue;
1062
+ const preferrerType = context.getValueTypePreference(entity.id);
1063
+
1064
+ if (!value && defaultValue) {
1065
+ const literalValue: LiteralValueState | null = defaultValue;
1066
+
1067
+ if (
1068
+ literalValue &&
1069
+ literalValue.value === null &&
1070
+ !!literalValue.autogeneration
1071
+ ) {
1072
+ const autogeneratedValue = generate(literalValue);
1073
+
1074
+ literalValue.metaSync(
1075
+ {
1076
+ value: autogeneratedValue
1077
+ },
1078
+ null
1079
+ );
1080
+ }
1081
+
1082
+ if (
1083
+ onlyDefault ||
1084
+ preferrerType === null ||
1085
+ preferrerType !== DynamicValueTypes.Testing
1086
+ ) {
1087
+ value = {
1088
+ value: literalValue,
1089
+ valueOwner: entity,
1090
+ type: checkIsLiteralValueEmpty(literalValue)
1091
+ ? !!entity.readsValue
1092
+ ? DynamicValueTypes.Inherited
1093
+ : DynamicValueTypes.Empty
1094
+ : DynamicValueTypes.DefaultValue,
1095
+ inheritanceLink: null
1096
+ };
1097
+ }
1098
+ }
1099
+
1100
+ if (
1101
+ !value ||
1102
+ ((value.type === DynamicValueTypes.DefaultValue ||
1103
+ value.type === DynamicValueTypes.External) &&
1104
+ !onlyDefault) ||
1105
+ preferrerType === DynamicValueTypes.Testing
1106
+ ) {
1107
+ const localTestValue = context.localTestValues?.readValue(entity.id);
1108
+
1109
+ if (!!localTestValue) {
1110
+ return {
1111
+ value: localTestValue,
1112
+ valueOwner: entity,
1113
+ type: DynamicValueTypes.Testing,
1114
+ inheritanceLink: null
1115
+ };
1116
+ }
1117
+ }
1118
+
1119
+ // Check if it is part of test but not required, then set as "empty"
1120
+ if (checkIsLiteralValueEmpty(value?.value || null)) {
1121
+ return {
1122
+ value: null,
1123
+ valueOwner: entity,
1124
+ type: !!entity.readsValue
1125
+ ? DynamicValueTypes.Inherited
1126
+ : DynamicValueTypes.Empty,
1127
+ inheritanceLink: null
1128
+ };
1129
+ }
1130
+
1131
+ return value;
1132
+ }
1133
+
1134
+ export function resolveVarDeclarationValue(
1135
+ entity: VariableDeclarationState,
1136
+ context: IValueResolutionContext,
1137
+ onlyDefault = false
1138
+ ): IDynamicValue | null {
1139
+ if (entity.dataType?.isObject() || !!entity.outputs.length) {
1140
+ return resolveVarDeclarationAggregateObjectValue(
1141
+ entity,
1142
+ context,
1143
+ onlyDefault
1144
+ );
1145
+ }
1146
+
1147
+ if (
1148
+ !!context.execution &&
1149
+ context.execution.hasEntity(entity) &&
1150
+ !onlyDefault
1151
+ ) {
1152
+ const lastExecutionValue = context.lastExecutionResults?.readValue(
1153
+ entity.id
1154
+ );
1155
+
1156
+ if (lastExecutionValue) {
1157
+ const variableDeclarationValue: IDynamicValue = {
1158
+ value: lastExecutionValue,
1159
+ valueOwner: entity,
1160
+ type: DynamicValueTypes.ExecutionResult,
1161
+ inheritanceLink: null
1162
+ };
1163
+
1164
+ return variableDeclarationValue;
1165
+ }
1166
+ }
1167
+
1168
+ const result = resolveVarDeclarationNextValue(entity, context, onlyDefault);
1169
+ return result;
1170
+ }
1171
+
1172
+ export function resolveVarInstanceNextValue(
1173
+ entity: VariableInstanceState,
1174
+ context: IValueResolutionContext,
1175
+ onlyDefault = false
1176
+ ): IDynamicValue | null {
1177
+ const isThereActiveTest = !!context.execution?.entities.length;
1178
+ const isPartOfTest = context.execution?.hasEntity(entity);
1179
+
1180
+ let value: IDynamicValue | null = null;
1181
+
1182
+ const writerEntity = entity.readsValue;
1183
+
1184
+ if (!!writerEntity) {
1185
+ const isWriterPartOfTest = context.execution?.hasEntity(writerEntity);
1186
+
1187
+ // Should only read the value from the entity writing it, if:
1188
+ const shouldInheritFromWriter =
1189
+ // There isn't an active test
1190
+ !isThereActiveTest ||
1191
+ // Or there is an active test, and both entities are part of it
1192
+ (isThereActiveTest && isWriterPartOfTest && isPartOfTest) ||
1193
+ // Or there is an active test, but neither entity is a part it
1194
+ (isThereActiveTest && !isWriterPartOfTest && !isPartOfTest);
1195
+
1196
+ if (shouldInheritFromWriter) {
1197
+ value = readValueFromWritter(entity, context, onlyDefault);
1198
+ }
1199
+ }
1200
+
1201
+ // Get the value of the declaration
1202
+ const varDeclaration = entity.declaration;
1203
+
1204
+ if (!value && varDeclaration) {
1205
+ const declarationValue = resolveVarDeclarationNextValue(
1206
+ varDeclaration,
1207
+ context,
1208
+ onlyDefault
1209
+ );
1210
+
1211
+ if (declarationValue && declarationValue.value) {
1212
+ value = declarationValue;
1213
+ }
1214
+ }
1215
+ const preferrerType = context.getValueTypePreference(entity.id);
1216
+
1217
+ if (
1218
+ !value ||
1219
+ ((value.type === DynamicValueTypes.DefaultValue ||
1220
+ value.type === DynamicValueTypes.External) &&
1221
+ !onlyDefault) ||
1222
+ preferrerType === DynamicValueTypes.Testing
1223
+ ) {
1224
+ const localTestValue = context.localTestValues?.readValue(entity.id);
1225
+
1226
+ if (!!localTestValue) {
1227
+ return {
1228
+ value: localTestValue,
1229
+ valueOwner: entity,
1230
+ type: DynamicValueTypes.Testing,
1231
+ inheritanceLink: null
1232
+ };
1233
+ }
1234
+ }
1235
+
1236
+ const isDefinitionRequired = checkIsRequiredValue(entity);
1237
+
1238
+ const dataType = entity.getDataType(null);
1239
+
1240
+ const isMissing =
1241
+ isDefinitionRequired &&
1242
+ isPartOfTest &&
1243
+ (!value?.value ||
1244
+ (!checkIsNullable(dataType) &&
1245
+ checkIsLiteralValueExplicitlyEmpty(
1246
+ value?.value as LiteralValueState
1247
+ )));
1248
+
1249
+ if (isMissing) {
1250
+ return {
1251
+ value: null,
1252
+ valueOwner: entity,
1253
+ type: DynamicValueTypes.Missing,
1254
+ inheritanceLink: null
1255
+ };
1256
+ }
1257
+
1258
+ // Check if it is part of test but not required, then set as "empty"
1259
+ if (
1260
+ isPartOfTest &&
1261
+ !isDefinitionRequired &&
1262
+ checkIsLiteralValueEmpty(value?.value || null)
1263
+ ) {
1264
+ return {
1265
+ value: null,
1266
+ valueOwner: entity,
1267
+ type: !!entity.readsValue
1268
+ ? DynamicValueTypes.Inherited
1269
+ : DynamicValueTypes.Empty,
1270
+ inheritanceLink: null
1271
+ };
1272
+ }
1273
+
1274
+ // If there is a value return that one, otherwise return the definition of "External"
1275
+ return (
1276
+ value || {
1277
+ value: null,
1278
+ valueOwner: entity,
1279
+ type: DynamicValueTypes.External,
1280
+ inheritanceLink: null
1281
+ }
1282
+ );
1283
+ }
1284
+
1285
+ export function resolveVarInstanceValue(
1286
+ entity: VariableInstanceState,
1287
+ context: IValueResolutionContext,
1288
+ onlyDefault = false
1289
+ ): IDynamicValue | null {
1290
+ return resolveVarDeclarationValue(
1291
+ entity.declaration,
1292
+ context,
1293
+ onlyDefault
1294
+ ) as IDynamicValue | null;
1295
+ }
1296
+
1297
+ export function resolveArgumentDeclarationValue(
1298
+ entity: ArgumentDeclarationState,
1299
+ context: IValueResolutionContext,
1300
+ onlyDefault = false
1301
+ ): IDynamicValue | null {
1302
+ if (
1303
+ !onlyDefault &&
1304
+ !!context.execution &&
1305
+ context.execution.hasEntity(entity)
1306
+ ) {
1307
+ const lastExecutionValue = context.lastExecutionResults?.readValue(
1308
+ entity.id
1309
+ );
1310
+
1311
+ if (lastExecutionValue) {
1312
+ const argumentValue: IDynamicValue = {
1313
+ value: lastExecutionValue,
1314
+ valueOwner: entity,
1315
+ type: DynamicValueTypes.ExecutionResult,
1316
+ inheritanceLink: null
1317
+ };
1318
+
1319
+ return argumentValue;
1320
+ }
1321
+ }
1322
+
1323
+ const isTopLevelExecution =
1324
+ !context.execution || !context.execution.parentExecution;
1325
+ const preferrerType = context.getValueTypePreference(entity.id);
1326
+
1327
+ if (isTopLevelExecution) {
1328
+ const localTestValue = context.localTestValues?.readValue(entity.id);
1329
+
1330
+ if (
1331
+ !!localTestValue &&
1332
+ !onlyDefault &&
1333
+ (preferrerType === null ||
1334
+ preferrerType !== DynamicValueTypes.DefaultValue)
1335
+ ) {
1336
+ return {
1337
+ value: localTestValue,
1338
+ valueOwner: entity,
1339
+ type: DynamicValueTypes.Testing,
1340
+ inheritanceLink: null
1341
+ };
1342
+ }
1343
+ }
1344
+
1345
+ const canvasParent = getParentCanvasEntity(entity) as
1346
+ | DraggableExecutableEntityState
1347
+ | DraggableCallerEntityState
1348
+ | VariableDeclarationState;
1349
+
1350
+ const loopBodyParent =
1351
+ entity.parent.type === EntityType.FunctionDeclaration &&
1352
+ entity.parent.parent.type === EntityType.Loop
1353
+ ? entity.parent
1354
+ : null;
1355
+
1356
+ const isPartOfTest =
1357
+ !!context.execution?.hasEntity(canvasParent) ||
1358
+ (!!loopBodyParent && !!context.execution?.hasEntity(loopBodyParent));
1359
+
1360
+ let value: IDynamicValue | null = null;
1361
+
1362
+ const defaultValue = entity.defaultValue;
1363
+
1364
+ if (defaultValue) {
1365
+ const literalValue: LiteralValueState | null = defaultValue || null;
1366
+
1367
+ if (
1368
+ literalValue &&
1369
+ literalValue.value === null &&
1370
+ !!literalValue.autogeneration
1371
+ ) {
1372
+ const autogeneratedValue = generate(literalValue);
1373
+
1374
+ literalValue.metaSync(
1375
+ {
1376
+ value: autogeneratedValue
1377
+ },
1378
+ null
1379
+ );
1380
+ }
1381
+
1382
+ if (
1383
+ onlyDefault ||
1384
+ preferrerType === null ||
1385
+ preferrerType !== DynamicValueTypes.Testing
1386
+ ) {
1387
+ value = {
1388
+ value: literalValue,
1389
+ valueOwner: entity,
1390
+ type: checkIsLiteralValueEmpty(literalValue)
1391
+ ? DynamicValueTypes.Empty
1392
+ : DynamicValueTypes.DefaultValue,
1393
+ inheritanceLink: null
1394
+ };
1395
+ }
1396
+ }
1397
+
1398
+ if (
1399
+ !value ||
1400
+ ((value.type === DynamicValueTypes.DefaultValue ||
1401
+ value.type === DynamicValueTypes.External) &&
1402
+ !onlyDefault) ||
1403
+ preferrerType === DynamicValueTypes.Testing
1404
+ ) {
1405
+ // Test value has been moved to the top of the function
1406
+ }
1407
+
1408
+ const isDefinitionRequired = checkIsRequiredValue(entity);
1409
+
1410
+ const dataType = entity.getDataType(null);
1411
+
1412
+ let isMissing =
1413
+ isDefinitionRequired &&
1414
+ isPartOfTest &&
1415
+ (!value?.value ||
1416
+ (!checkIsNullable(dataType) &&
1417
+ checkIsLiteralValueExplicitlyEmpty(
1418
+ value?.value as LiteralValueState
1419
+ )));
1420
+
1421
+ // The argument declaration of the body of a loop will be given values dynamically, so we don't need to check if it is missing
1422
+ if (canvasParent.type === EntityType.Loop && isPartOfTest) {
1423
+ isMissing = false;
1424
+ }
1425
+
1426
+ if (isMissing) {
1427
+ return {
1428
+ value: null,
1429
+ valueOwner: entity,
1430
+ type: DynamicValueTypes.Missing,
1431
+ inheritanceLink: null
1432
+ };
1433
+ }
1434
+
1435
+ // Check if it is part of test but not required, then set as "empty"
1436
+ if (
1437
+ isPartOfTest &&
1438
+ !isDefinitionRequired &&
1439
+ checkIsLiteralValueEmpty(value?.value || null)
1440
+ ) {
1441
+ return {
1442
+ value: null,
1443
+ valueOwner: entity,
1444
+ type: DynamicValueTypes.Empty,
1445
+ inheritanceLink: null
1446
+ };
1447
+ }
1448
+
1449
+ // If there is a value return that one, otherwise return the definition of "External"
1450
+ return (
1451
+ value || {
1452
+ value: null,
1453
+ valueOwner: entity,
1454
+ type: DynamicValueTypes.External,
1455
+ inheritanceLink: null
1456
+ }
1457
+ );
1458
+ }
1459
+
1460
+ export function resolveTerminationEntityValue(
1461
+ entity: TerminationEntityState,
1462
+ context: IValueResolutionContext,
1463
+ onlyDefault = false
1464
+ ): IDynamicValue | null {
1465
+ if (entity.getDataType(null)?.isObject() || !!entity.outputs.length) {
1466
+ return resolveVarDeclarationAggregateObjectValue(entity, context);
1467
+ }
1468
+
1469
+ if (
1470
+ !!context.execution &&
1471
+ context.execution.hasEntity(entity) &&
1472
+ !onlyDefault
1473
+ ) {
1474
+ const lastExecutionValue = context.lastExecutionResults?.readValue(
1475
+ entity.id
1476
+ );
1477
+
1478
+ if (lastExecutionValue) {
1479
+ const returnDeclarationValue: IDynamicValue = {
1480
+ value: lastExecutionValue,
1481
+ valueOwner: entity,
1482
+ type: DynamicValueTypes.ExecutionResult,
1483
+ inheritanceLink: null
1484
+ };
1485
+
1486
+ return returnDeclarationValue;
1487
+ }
1488
+ }
1489
+
1490
+ const canvasParent = getParentCanvasEntity(entity) as
1491
+ | DraggableExecutableEntityState
1492
+ | DraggableCallerEntityState
1493
+ | VariableDeclarationState;
1494
+ const isThereActiveTest = !!context.execution?.entities.length;
1495
+ const isPartOfTest = context.execution?.hasEntity(canvasParent);
1496
+
1497
+ const writerEntity = entity.readsValue;
1498
+ let value: IDynamicValue | null = null;
1499
+
1500
+ if (!!writerEntity) {
1501
+ const isWriterPartOfTest = context.execution?.hasEntity(writerEntity);
1502
+
1503
+ // Should only read the value from the entity writing it, if:
1504
+ const shouldInheritFromWriter =
1505
+ // There isn't an active test
1506
+ !isThereActiveTest ||
1507
+ // Or there is an active test, and both entities are part of it
1508
+ (isThereActiveTest && isWriterPartOfTest && isPartOfTest) ||
1509
+ // Or there is an active test, but neither entity is a part it
1510
+ (isThereActiveTest && !isWriterPartOfTest && !isPartOfTest);
1511
+
1512
+ if (shouldInheritFromWriter) {
1513
+ value = readValueFromWritter(entity, context, onlyDefault);
1514
+ }
1515
+ }
1516
+
1517
+ const defaultValue = entity.defaultValue;
1518
+ const preferrerType = context.getValueTypePreference(entity.id);
1519
+
1520
+ if (!value && defaultValue) {
1521
+ const literalValue: LiteralValueState | null = defaultValue;
1522
+
1523
+ if (
1524
+ onlyDefault ||
1525
+ preferrerType === null ||
1526
+ preferrerType !== DynamicValueTypes.Testing
1527
+ ) {
1528
+ value = {
1529
+ value: literalValue,
1530
+ valueOwner: entity,
1531
+ type: DynamicValueTypes.DefaultValue,
1532
+ inheritanceLink: null
1533
+ };
1534
+ }
1535
+ }
1536
+
1537
+ if (
1538
+ !value ||
1539
+ ((value.type === DynamicValueTypes.DefaultValue ||
1540
+ value.type === DynamicValueTypes.External) &&
1541
+ !onlyDefault) ||
1542
+ preferrerType === DynamicValueTypes.Testing
1543
+ ) {
1544
+ const localTestValue = context.localTestValues?.readValue(entity.id);
1545
+
1546
+ if (!!localTestValue) {
1547
+ return {
1548
+ value: localTestValue,
1549
+ valueOwner: entity,
1550
+ type: DynamicValueTypes.Testing,
1551
+ inheritanceLink: null
1552
+ };
1553
+ }
1554
+ }
1555
+
1556
+ const isDefinitionRequired = checkIsRequiredValue(entity);
1557
+
1558
+ const dataType = entity.getDataType(null);
1559
+
1560
+ const isMissing =
1561
+ isDefinitionRequired &&
1562
+ (!value?.value ||
1563
+ (!checkIsNullable(dataType) &&
1564
+ checkIsLiteralValueExplicitlyEmpty(
1565
+ value?.value as LiteralValueState
1566
+ )));
1567
+
1568
+ if (isMissing) {
1569
+ return {
1570
+ value: null,
1571
+ valueOwner: entity,
1572
+ type: DynamicValueTypes.Missing,
1573
+ inheritanceLink: null
1574
+ };
1575
+ }
1576
+
1577
+ if (!entity.defaultValue && !entity.readsValue) {
1578
+ return {
1579
+ value: null,
1580
+ valueOwner: entity,
1581
+ type: DynamicValueTypes.Undefined,
1582
+ inheritanceLink: null
1583
+ };
1584
+ }
1585
+
1586
+ // Check if it is part of test but not required, then set as "empty"
1587
+ if (
1588
+ !isDefinitionRequired &&
1589
+ checkIsLiteralValueEmpty(value?.value || null)
1590
+ ) {
1591
+ return {
1592
+ value: null,
1593
+ valueOwner: entity,
1594
+ type: !!entity.readsValue
1595
+ ? DynamicValueTypes.Inherited
1596
+ : DynamicValueTypes.Empty,
1597
+ inheritanceLink: null
1598
+ };
1599
+ }
1600
+
1601
+ return value;
1602
+ }
1603
+
1604
+ export function resolveOutputMapValue(
1605
+ entity: OutputMapState,
1606
+ context: IValueResolutionContext,
1607
+ onlyDefault = false
1608
+ ): IDynamicValue | null {
1609
+ if (
1610
+ !!context.execution &&
1611
+ context.execution.hasEntity(entity) &&
1612
+ !onlyDefault
1613
+ ) {
1614
+ const lastExecutionValue = context.lastExecutionResults?.readValue(
1615
+ entity.id
1616
+ );
1617
+
1618
+ if (lastExecutionValue) {
1619
+ const outputValue: IDynamicValue = {
1620
+ value: lastExecutionValue,
1621
+ valueOwner: entity,
1622
+ type: DynamicValueTypes.ExecutionResult,
1623
+ inheritanceLink: null
1624
+ };
1625
+
1626
+ return outputValue;
1627
+ }
1628
+ }
1629
+
1630
+ // If the outputMap is part of a test, and it is currently running, we shouldn't resolve the previously persisted execution value
1631
+ // This could confuse users into thinking that this value is a result of the ongoing execution
1632
+ const canvasParent = getParentCallableEntity(entity) as CallableEntityState;
1633
+
1634
+ if (PASS_THROUGH_CALLABLE_TYPES_WITH_OUTPUTS.includes(canvasParent.type)) {
1635
+ const parentVarValue = resolveValue(
1636
+ canvasParent as VariableState,
1637
+ context,
1638
+ onlyDefault
1639
+ );
1640
+
1641
+ // Take own property from the parent variable
1642
+ const resolveCodeName =
1643
+ entity.codeName ||
1644
+ entity.declaration?.codeName ||
1645
+ toCamelCase(safeResolveEntityName(entity, context.project));
1646
+
1647
+ if (
1648
+ !!parentVarValue?.value &&
1649
+ // If the parent has a value, we want to read from it as a property of an object
1650
+ // But that isn't the case for thrown errors. They are standalone values unrelated to the main returned value of the parent node
1651
+ entity.parentRelationType !== OutputMapParentChildRelation.Error
1652
+ ) {
1653
+ const propertyValue = ((parentVarValue.value
1654
+ .value as UntypedObjectValue) || {})[resolveCodeName];
1655
+
1656
+ if (propertyValue === undefined) {
1657
+ return {
1658
+ value: null,
1659
+ valueOwner: entity,
1660
+ type: DynamicValueTypes.Undefined,
1661
+ inheritanceLink: null
1662
+ };
1663
+ }
1664
+
1665
+ const literalValue = assembleStandaloneLiteralValueFromDataType(
1666
+ entity.getDataType(null),
1667
+ entity,
1668
+ context.project
1669
+ );
1670
+
1671
+ literalValue?.metaSync(
1672
+ {
1673
+ value: propertyValue,
1674
+ rawString: typeof propertyValue === 'string' && typeof (parentVarValue?.value as any)?.rawString === 'string' ? (parentVarValue?.value as any)?.rawString : undefined
1675
+ },
1676
+ null
1677
+ );
1678
+
1679
+ return {
1680
+ value: literalValue,
1681
+ valueOwner: entity,
1682
+ type:
1683
+ !VARIABLE_TYPES.includes(canvasParent.type) &&
1684
+ parentVarValue.type === DynamicValueTypes.Empty
1685
+ ? DynamicValueTypes.QueuedAutocalculation
1686
+ : parentVarValue.type,
1687
+ inheritanceLink: {
1688
+ sources: [parentVarValue],
1689
+ target: entity
1690
+ }
1691
+ };
1692
+ }
1693
+
1694
+ return {
1695
+ value: null,
1696
+ valueOwner: entity,
1697
+ type: !VARIABLE_TYPES.includes(canvasParent.type)
1698
+ ? DynamicValueTypes.QueuedAutocalculation
1699
+ : DynamicValueTypes.Empty,
1700
+ inheritanceLink: null
1701
+ };
1702
+ }
1703
+
1704
+ const isPartOfTest = context.execution?.hasEntity(canvasParent);
1705
+ const isTestRunning = context.execution?.state === ExecutionState.Running;
1706
+
1707
+ if (
1708
+ context.persistedExecutionResults?.values[entity.id] &&
1709
+ !isPartOfTest &&
1710
+ !isTestRunning &&
1711
+ !onlyDefault
1712
+ ) {
1713
+ const lastExecutionValue = context.persistedExecutionResults?.readValue(
1714
+ entity.id
1715
+ );
1716
+
1717
+ if (
1718
+ lastExecutionValue?.value !== null ||
1719
+ lastExecutionValue?.valueAsType !== null
1720
+ ) {
1721
+ const outputValue: IDynamicValue = {
1722
+ value: lastExecutionValue,
1723
+ valueOwner: entity,
1724
+ type: DynamicValueTypes.ExecutionResult,
1725
+ inheritanceLink: null
1726
+ };
1727
+
1728
+ return outputValue;
1729
+ }
1730
+ }
1731
+
1732
+ return null;
1733
+ }
1734
+
1735
+ /*
1736
+ The valve resolution of an input-map that belongs to an object variable, should try to resolve its value in the following order:
1737
+ 1- If it is a static property, resolve the global test value assingned to the owning property.
1738
+ 2- If it is a static property, resolve the default value of the owning property.
1739
+ 3- Take its part (object property) from the parent variable's test value.
1740
+ 4- Take its part from the parent var's default value.
1741
+ 5- Take its test value.
1742
+ 6- Take its default value.
1743
+ 7- Take its declaration's default value.
1744
+ */
1745
+ export function resolveInputMapNextValueAsPropertyOfAnObject(
1746
+ entity: InputMapState,
1747
+ context: IValueResolutionContext,
1748
+ onlyDefault = false
1749
+ ): IDynamicValue | null {
1750
+ if (
1751
+ ![...TERMINATION_TYPES, ...VARIABLE_TYPES].includes(entity.parent.type)
1752
+ ) {
1753
+ return null;
1754
+ }
1755
+
1756
+ if (!checkShouldInputOrOutputBePartOfFinalVariableObjectValue(entity)) {
1757
+ return null;
1758
+ }
1759
+
1760
+ // Check if the declaration is a 'static' property
1761
+ if (
1762
+ entity.declaration?.type === EntityType.Property &&
1763
+ entity.declaration.static
1764
+ ) {
1765
+ const propertyValue = resolveValue(entity.declaration, context);
1766
+
1767
+ return propertyValue;
1768
+ }
1769
+
1770
+ const nextValue = resolveInputMapNextStandaloneValue(
1771
+ entity,
1772
+ context,
1773
+ onlyDefault
1774
+ );
1775
+
1776
+ if (
1777
+ !!nextValue &&
1778
+ nextValue.type !== DynamicValueTypes.Empty &&
1779
+ nextValue.type !== DynamicValueTypes.Missing &&
1780
+ nextValue.type !== DynamicValueTypes.Undefined
1781
+ ) {
1782
+ return nextValue;
1783
+ }
1784
+
1785
+ const parentVar = getDeclaration(entity.parent as VariableState);
1786
+ const parentVarValue = resolveNextValue(parentVar, context, onlyDefault);
1787
+
1788
+ // Take its own property from the parent variable
1789
+ const resolveCodeName =
1790
+ entity.codeName ||
1791
+ entity.declaration?.codeName ||
1792
+ toCamelCase(safeResolveEntityName(entity, context.project));
1793
+
1794
+ const literalValue = assembleStandaloneLiteralValueFromDataType(
1795
+ entity.getDataType(null),
1796
+ entity,
1797
+ context.project
1798
+ );
1799
+
1800
+ const isDefinitionRequired = checkIsRequiredValue(entity);
1801
+
1802
+ // If the parent variable has a value, and it is an object, then we can take the property from it
1803
+ const rawParentObjectValue = parentVarValue?.value
1804
+ ?.value as UntypedObjectValue;
1805
+
1806
+ if (!!rawParentObjectValue) {
1807
+ let ownRawValue = (rawParentObjectValue || {})[resolveCodeName];
1808
+
1809
+ // If falsy but not 'false' or '0', set as null
1810
+ if (rawParentObjectValue[resolveCodeName] === undefined) {
1811
+ return {
1812
+ value: null,
1813
+ valueOwner: entity,
1814
+ type: DynamicValueTypes.Undefined,
1815
+ inheritanceLink: {
1816
+ sources: !!parentVarValue
1817
+ ? [parentVarValue as IDynamicValue]
1818
+ : [],
1819
+ target: entity
1820
+ }
1821
+ };
1822
+ }
1823
+
1824
+ literalValue?.metaSync(
1825
+ {
1826
+ value: ownRawValue,
1827
+ rawString: typeof ownRawValue === 'string' && typeof (parentVarValue?.value as any)?.rawString === 'string' ? (parentVarValue?.value as any)?.rawString : undefined
1828
+ },
1829
+ null
1830
+ );
1831
+
1832
+ const isDefinitionRequired = checkIsRequiredValue(entity);
1833
+
1834
+ const dataType = entity.getDataType(null);
1835
+
1836
+ const isMissing =
1837
+ isDefinitionRequired &&
1838
+ (!literalValue ||
1839
+ (!checkIsNullable(dataType) &&
1840
+ checkIsLiteralValueExplicitlyEmpty(
1841
+ literalValue as LiteralValueState
1842
+ )));
1843
+
1844
+ if (isMissing) {
1845
+ return {
1846
+ value: null,
1847
+ valueOwner: entity,
1848
+ type: DynamicValueTypes.Missing,
1849
+ inheritanceLink: null
1850
+ };
1851
+ }
1852
+
1853
+ return {
1854
+ value: literalValue,
1855
+ valueOwner: entity,
1856
+ type: (parentVarValue as IDynamicValue).type,
1857
+ inheritanceLink: {
1858
+ sources: !!parentVarValue
1859
+ ? [parentVarValue as IDynamicValue]
1860
+ : [],
1861
+ target: entity
1862
+ }
1863
+ };
1864
+ }
1865
+
1866
+ if (
1867
+ parentVarValue?.type &&
1868
+ parentVarValue.type !== DynamicValueTypes.Missing &&
1869
+ parentVarValue.type !== DynamicValueTypes.Empty &&
1870
+ parentVarValue.type !== DynamicValueTypes.Undefined
1871
+ ) {
1872
+ return {
1873
+ value: null,
1874
+ valueOwner: entity,
1875
+ type: parentVarValue.type,
1876
+ inheritanceLink: {
1877
+ sources: !!parentVarValue
1878
+ ? [parentVarValue as IDynamicValue]
1879
+ : [],
1880
+ target: entity
1881
+ }
1882
+ };
1883
+ }
1884
+
1885
+ const isMissing = isDefinitionRequired;
1886
+
1887
+ if (isMissing) {
1888
+ return {
1889
+ value: null,
1890
+ valueOwner: entity,
1891
+ type: DynamicValueTypes.Missing,
1892
+ inheritanceLink: null
1893
+ };
1894
+ }
1895
+
1896
+ return {
1897
+ value: null,
1898
+ valueOwner: entity,
1899
+ type: !!entity.readsValue
1900
+ ? DynamicValueTypes.Inherited
1901
+ : DynamicValueTypes.Empty,
1902
+ inheritanceLink: null
1903
+ };
1904
+ }
1905
+
1906
+ export function resolveInputMapValueAsPropertyOfAnObject(
1907
+ entity: InputMapState,
1908
+ context: IValueResolutionContext,
1909
+ onlyDefault = false
1910
+ ): IDynamicValue | null {
1911
+ if (
1912
+ ![...TERMINATION_TYPES, ...VARIABLE_TYPES].includes(entity.parent.type)
1913
+ ) {
1914
+ return null;
1915
+ }
1916
+
1917
+ if (!checkShouldInputOrOutputBePartOfFinalVariableObjectValue(entity)) {
1918
+ return null;
1919
+ }
1920
+
1921
+ // Check if the declaration is a 'static' property
1922
+ if (
1923
+ entity.declaration?.type === EntityType.Property &&
1924
+ entity.declaration.static
1925
+ ) {
1926
+ const propertyValue = resolveValue(
1927
+ entity.declaration,
1928
+ context,
1929
+ onlyDefault
1930
+ );
1931
+
1932
+ return propertyValue;
1933
+ }
1934
+
1935
+ const parentVar: VariableDeclarationState | TerminationEntityState =
1936
+ TERMINATION_TYPES.includes(entity.parent.type)
1937
+ ? (entity.parent as TerminationEntityState)
1938
+ : getDeclaration(entity.parent as VariableState);
1939
+ const parentVarValue = resolveValue(parentVar, context, onlyDefault);
1940
+
1941
+ let entityToUse: InputMapState = entity;
1942
+
1943
+ if (parentVar.type === EntityType.VariableDeclaration) {
1944
+ const counterPartInDeclaration =
1945
+ entity.parent === parentVar
1946
+ ? entity
1947
+ : parentVar.inputs.find(
1948
+ (input) =>
1949
+ input.declaration?.id === entity.declaration?.id
1950
+ );
1951
+
1952
+ entityToUse = counterPartInDeclaration || entity;
1953
+ }
1954
+
1955
+ const ownValue = resolveInputMapStandaloneValue(
1956
+ entityToUse as InputMapState,
1957
+ context,
1958
+ onlyDefault
1959
+ );
1960
+
1961
+ const resolveCodeName =
1962
+ entity.codeName ||
1963
+ entity.declaration?.codeName ||
1964
+ toCamelCase(safeResolveEntityName(entity, context.project));
1965
+
1966
+ const literalValue =
1967
+ entity.defaultValue ||
1968
+ assembleStandaloneLiteralValueFromDataType(
1969
+ entity.getDataType(null),
1970
+ entity,
1971
+ context.project
1972
+ );
1973
+
1974
+ // If the parent variable has a value, and it is an object, then we can take the property from it
1975
+ const rawParentObjectValue = parentVarValue?.value
1976
+ ?.value as UntypedObjectValue;
1977
+
1978
+ if (
1979
+ (parentVarValue?.type === DynamicValueTypes.ExecutionResult ||
1980
+ parentVarValue?.type === DynamicValueTypes.Testing) &&
1981
+ !onlyDefault
1982
+ ) {
1983
+ if (!!rawParentObjectValue) {
1984
+ let ownRawValue = (rawParentObjectValue || {})[resolveCodeName];
1985
+
1986
+ // If falsy but not 'false' or '0', set as null
1987
+ if (
1988
+ rawParentObjectValue[resolveCodeName] === undefined &&
1989
+ !entity.readsValue &&
1990
+ !entity.defaultValue
1991
+ ) {
1992
+ return {
1993
+ value: null,
1994
+ valueOwner: entity,
1995
+ type: DynamicValueTypes.Undefined,
1996
+ inheritanceLink: {
1997
+ sources: !!parentVarValue
1998
+ ? [parentVarValue as IDynamicValue]
1999
+ : [],
2000
+ target: entity
2001
+ }
2002
+ };
2003
+ }
2004
+
2005
+ literalValue?.metaSync(
2006
+ {
2007
+ value: ownRawValue,
2008
+ rawString: typeof ownRawValue === 'string' && typeof (parentVarValue?.value as any)?.rawString === 'string' ? (parentVarValue?.value as any)?.rawString : undefined
2009
+ },
2010
+ null
2011
+ );
2012
+
2013
+ return {
2014
+ value: literalValue,
2015
+ valueOwner: entity,
2016
+ type: (parentVarValue as IDynamicValue).type,
2017
+ inheritanceLink: {
2018
+ sources: !!parentVarValue
2019
+ ? [parentVarValue as IDynamicValue]
2020
+ : [],
2021
+ target: entity
2022
+ }
2023
+ };
2024
+ }
2025
+ }
2026
+
2027
+ if (
2028
+ !!ownValue &&
2029
+ ownValue.type !== DynamicValueTypes.Empty &&
2030
+ ownValue.type !== DynamicValueTypes.Missing &&
2031
+ ownValue.type !== DynamicValueTypes.Undefined
2032
+ ) {
2033
+ return ownValue;
2034
+ }
2035
+
2036
+ if (!!rawParentObjectValue) {
2037
+ let ownRawValue = (rawParentObjectValue || {})[resolveCodeName];
2038
+ // If falsy but not 'false' or '0', set as null
2039
+ if (
2040
+ rawParentObjectValue[resolveCodeName] !== undefined &&
2041
+ !!literalValue?.standaloneParent
2042
+ ) {
2043
+ literalValue?.metaSync(
2044
+ {
2045
+ value: ownRawValue,
2046
+ rawString: typeof ownRawValue === 'string' && typeof (parentVarValue?.value as any)?.rawString === 'string' ? (parentVarValue?.value as any)?.rawString : undefined
2047
+ },
2048
+ null
2049
+ );
2050
+ }
2051
+
2052
+ const isDefinitionRequired = checkIsRequiredValue(entity);
2053
+
2054
+ const dataType = entity.getDataType(null);
2055
+
2056
+ const isMissing =
2057
+ isDefinitionRequired &&
2058
+ (!literalValue ||
2059
+ (!checkIsNullable(dataType) &&
2060
+ checkIsLiteralValueExplicitlyEmpty(
2061
+ literalValue as LiteralValueState
2062
+ )));
2063
+
2064
+ const isThereActiveTest = !!context.execution?.entities.length;
2065
+ const isPartOfTest = context.execution?.hasEntity(parentVar);
2066
+
2067
+ const parentWriterEntity = parentVar.readsValue;
2068
+
2069
+ if (!!parentWriterEntity) {
2070
+ const isWriterPartOfTest =
2071
+ context.execution?.hasEntity(parentWriterEntity);
2072
+
2073
+ // Should only read the value from the entity writing it, if:
2074
+ const parentIsInheriting =
2075
+ // There isn't an active test
2076
+ !isThereActiveTest ||
2077
+ // Or there is an active test, and both entities are part of it
2078
+ (isThereActiveTest && isWriterPartOfTest && isPartOfTest) ||
2079
+ // Or there is an active test, but neither entity is a part it
2080
+ (isThereActiveTest && !isWriterPartOfTest && !isPartOfTest);
2081
+
2082
+ if (isMissing && parentIsInheriting) {
2083
+ return {
2084
+ value: null,
2085
+ valueOwner: entity,
2086
+ type: DynamicValueTypes.Inherited,
2087
+ inheritanceLink: null
2088
+ };
2089
+ }
2090
+ }
2091
+
2092
+ if (!!entity.readsValue) {
2093
+ const isWriterPartOfTest = context.execution?.hasEntity(
2094
+ entity.readsValue
2095
+ );
2096
+
2097
+ // Should only read the value from the entity writing it, if:
2098
+ const isInheriting =
2099
+ // There isn't an active test
2100
+ !isThereActiveTest ||
2101
+ // Or there is an active test, and both entities are part of it
2102
+ (isThereActiveTest && isWriterPartOfTest && isPartOfTest) ||
2103
+ // Or there is an active test, but neither entity is a part it
2104
+ (isThereActiveTest && !isWriterPartOfTest && !isPartOfTest);
2105
+
2106
+ if (isMissing && isInheriting) {
2107
+ return {
2108
+ value: null,
2109
+ valueOwner: entity,
2110
+ type: DynamicValueTypes.Inherited,
2111
+ inheritanceLink: null
2112
+ };
2113
+ }
2114
+ }
2115
+
2116
+ if (isMissing) {
2117
+ return {
2118
+ value: null,
2119
+ valueOwner: entity,
2120
+ type: DynamicValueTypes.Missing,
2121
+ inheritanceLink: null
2122
+ };
2123
+ }
2124
+
2125
+ if (
2126
+ rawParentObjectValue[resolveCodeName] === undefined &&
2127
+ !entity.readsValue &&
2128
+ !entity.defaultValue
2129
+ ) {
2130
+ return {
2131
+ value: null,
2132
+ valueOwner: entity,
2133
+ type: DynamicValueTypes.Undefined,
2134
+ inheritanceLink: {
2135
+ sources: !!parentVarValue
2136
+ ? [parentVarValue as IDynamicValue]
2137
+ : [],
2138
+ target: entity
2139
+ }
2140
+ };
2141
+ }
2142
+
2143
+ return {
2144
+ value: literalValue,
2145
+ valueOwner: entity,
2146
+ type:
2147
+ checkIsLiteralValueEmpty(literalValue) && !entity.readsValue
2148
+ ? DynamicValueTypes.Empty
2149
+ : DynamicValueTypes.Inherited,
2150
+ inheritanceLink: null
2151
+ };
2152
+ }
2153
+
2154
+ return {
2155
+ value: null,
2156
+ valueOwner: entity,
2157
+ type: DynamicValueTypes.Undefined,
2158
+ inheritanceLink: null
2159
+ };
2160
+ }
2161
+
2162
+ export function resolveInputMapNextStandaloneValue(
2163
+ entity: InputMapState,
2164
+ context: IValueResolutionContext,
2165
+ onlyDefault = false
2166
+ ): IDynamicValue | null {
2167
+ const canvasParent = getParentCanvasEntity(entity) as
2168
+ | DraggableExecutableEntityState
2169
+ | DraggableCallerEntityState
2170
+ | VariableDeclarationState;
2171
+ const isThereActiveTest = !!context.execution?.entities.length;
2172
+ const isPartOfTest = context.execution?.hasEntity(canvasParent);
2173
+
2174
+ const writerEntity = entity.readsValue;
2175
+ let value: IDynamicValue | null = null;
2176
+ let shouldInheritFromWriter = false;
2177
+
2178
+ if (!!writerEntity) {
2179
+ const isWriterPartOfTest = context.execution?.hasEntity(writerEntity);
2180
+
2181
+ // Should only read the value from the entity writing it, if:
2182
+ shouldInheritFromWriter =
2183
+ // There isn't an active test
2184
+ !isThereActiveTest ||
2185
+ // Or there is an active test, and both entities are part of it
2186
+ (isThereActiveTest && isWriterPartOfTest && isPartOfTest) ||
2187
+ // Or there is an active test, but neither entity is a part it
2188
+ (isThereActiveTest && !isWriterPartOfTest && !isPartOfTest);
2189
+
2190
+ if (shouldInheritFromWriter) {
2191
+ value = readValueFromWritter(entity, context, onlyDefault);
2192
+ }
2193
+ }
2194
+
2195
+ const hasEffectiveWriter = !!writerEntity && shouldInheritFromWriter;
2196
+
2197
+ const defaultValue = entity.defaultValue;
2198
+ const preferrerType = context.getValueTypePreference(entity.id);
2199
+
2200
+ if (
2201
+ !value &&
2202
+ defaultValue &&
2203
+ (onlyDefault ||
2204
+ preferrerType === null ||
2205
+ preferrerType !== DynamicValueTypes.Testing)
2206
+ ) {
2207
+ value = {
2208
+ value: defaultValue,
2209
+ valueOwner: entity,
2210
+ type: checkIsLiteralValueExplicitlyEmpty(defaultValue)
2211
+ ? DynamicValueTypes.Empty
2212
+ : DynamicValueTypes.DefaultValue,
2213
+ inheritanceLink: null
2214
+ };
2215
+ }
2216
+
2217
+ if (
2218
+ (!value ||
2219
+ value.type === DynamicValueTypes.DefaultValue ||
2220
+ value?.type === DynamicValueTypes.Empty ||
2221
+ preferrerType === DynamicValueTypes.Testing) &&
2222
+ !hasEffectiveWriter
2223
+ ) {
2224
+ const lastExecutionValue = context.persistedExecutionResults?.readValue(
2225
+ entity.id
2226
+ );
2227
+
2228
+ if (!!lastExecutionValue && !onlyDefault) {
2229
+ return {
2230
+ value: lastExecutionValue,
2231
+ valueOwner: entity,
2232
+ type: DynamicValueTypes.Testing,
2233
+ inheritanceLink: null
2234
+ };
2235
+ }
2236
+
2237
+ const localTestValue = context.localTestValues?.readValue(entity.id);
2238
+
2239
+ if (
2240
+ !!localTestValue &&
2241
+ !onlyDefault &&
2242
+ (preferrerType === null ||
2243
+ preferrerType === DynamicValueTypes.Testing)
2244
+ ) {
2245
+ return {
2246
+ value: localTestValue,
2247
+ valueOwner: entity,
2248
+ type: DynamicValueTypes.Testing,
2249
+ inheritanceLink: null
2250
+ };
2251
+ }
2252
+ }
2253
+
2254
+ const isDefinitionRequired = checkIsRequiredValue(entity);
2255
+
2256
+ const dataType = entity.getDataType(null);
2257
+
2258
+ const isMissing =
2259
+ isDefinitionRequired &&
2260
+ (!value?.value ||
2261
+ (!checkIsNullable(dataType) &&
2262
+ checkIsLiteralValueExplicitlyEmpty(
2263
+ value?.value as LiteralValueState
2264
+ )));
2265
+
2266
+ if (hasEffectiveWriter) {
2267
+ if (isMissing) {
2268
+ return {
2269
+ value: null,
2270
+ valueOwner: entity,
2271
+ type: DynamicValueTypes.Inherited,
2272
+ inheritanceLink: null
2273
+ };
2274
+ }
2275
+ }
2276
+
2277
+ if (isMissing) {
2278
+ return {
2279
+ value: null,
2280
+ valueOwner: entity,
2281
+ type: DynamicValueTypes.Missing,
2282
+ inheritanceLink: value?.inheritanceLink || null
2283
+ };
2284
+ }
2285
+
2286
+ if (!value && !entity.defaultValue && !hasEffectiveWriter) {
2287
+ return {
2288
+ value: null,
2289
+ valueOwner: entity,
2290
+ type: DynamicValueTypes.Undefined,
2291
+ inheritanceLink: null
2292
+ };
2293
+ }
2294
+
2295
+ if (
2296
+ !isDefinitionRequired &&
2297
+ (!value || value.type === DynamicValueTypes.Inherited) &&
2298
+ !value?.inheritanceLink
2299
+ ) {
2300
+ return {
2301
+ value: null,
2302
+ valueOwner: entity,
2303
+ type: hasEffectiveWriter
2304
+ ? DynamicValueTypes.Inherited
2305
+ : DynamicValueTypes.Empty,
2306
+ inheritanceLink: null
2307
+ };
2308
+ }
2309
+
2310
+ return value;
2311
+ }
2312
+
2313
+ // Resolved its own value ignoring the value of any potential parent object
2314
+ export function resolveInputMapStandaloneValue(
2315
+ entity: InputMapState,
2316
+ context: IValueResolutionContext,
2317
+ onlyDefault = false
2318
+ ): IDynamicValue | null {
2319
+ if (
2320
+ !!context.execution &&
2321
+ context.execution.hasEntity(entity) &&
2322
+ !onlyDefault
2323
+ ) {
2324
+ const lastExecutionValue = context.lastExecutionResults?.readValue(
2325
+ entity.id
2326
+ );
2327
+
2328
+ if (lastExecutionValue) {
2329
+ const inputMapValue: IDynamicValue = {
2330
+ value: lastExecutionValue,
2331
+ valueOwner: entity,
2332
+ type: DynamicValueTypes.ExecutionResult,
2333
+ inheritanceLink: null
2334
+ };
2335
+
2336
+ return inputMapValue;
2337
+ }
2338
+ }
2339
+
2340
+ const result = resolveInputMapNextStandaloneValue(
2341
+ entity,
2342
+ context,
2343
+ onlyDefault
2344
+ );
2345
+ return result;
2346
+ }
2347
+
2348
+ export function resolveInputMapNextValue(
2349
+ entity: InputMapState,
2350
+ context: IValueResolutionContext,
2351
+ onlyDefault = false
2352
+ ): IDynamicValue | null {
2353
+ if (VARIABLE_TYPES.includes(entity.parent.type)) {
2354
+ const variableDeclaration = getDeclaration(
2355
+ entity.parent as VariableState
2356
+ );
2357
+
2358
+ if (variableDeclaration.dataType?.isObject()) {
2359
+ return resolveInputMapNextValueAsPropertyOfAnObject(
2360
+ entity,
2361
+ context,
2362
+ onlyDefault
2363
+ );
2364
+ }
2365
+ }
2366
+
2367
+ if (TERMINATION_TYPES.includes(entity.parent.type)) {
2368
+ if (entity.parent.getDataType(null)?.isObject()) {
2369
+ return resolveInputMapNextValueAsPropertyOfAnObject(
2370
+ entity,
2371
+ context,
2372
+ onlyDefault
2373
+ );
2374
+ }
2375
+ }
2376
+
2377
+ return resolveInputMapNextStandaloneValue(entity, context, onlyDefault);
2378
+ }
2379
+
2380
+ export function resolveInputMapValue(
2381
+ entity: InputMapState,
2382
+ context: IValueResolutionContext,
2383
+ onlyDefault = false
2384
+ ): IDynamicValue | null {
2385
+ if (VARIABLE_TYPES.includes(entity.parent.type)) {
2386
+ const variableDeclaration = getDeclaration(
2387
+ entity.parent as VariableState
2388
+ );
2389
+
2390
+ if (
2391
+ variableDeclaration.dataType?.isObject() ||
2392
+ !!variableDeclaration.inputs.length
2393
+ ) {
2394
+ return resolveInputMapValueAsPropertyOfAnObject(
2395
+ entity,
2396
+ context,
2397
+ onlyDefault
2398
+ );
2399
+ }
2400
+ }
2401
+
2402
+ if (TERMINATION_TYPES.includes(entity.parent.type)) {
2403
+ if (
2404
+ entity.parent.getDataType(null)?.isObject() ||
2405
+ !!(entity.parent as TerminationEntityState).outputs.length
2406
+ ) {
2407
+ return resolveInputMapValueAsPropertyOfAnObject(
2408
+ entity,
2409
+ context,
2410
+ onlyDefault
2411
+ );
2412
+ }
2413
+ }
2414
+
2415
+ return resolveInputMapStandaloneValue(entity, context, onlyDefault);
2416
+ }
2417
+
2418
+ export function resolvePropertyValue(
2419
+ entity: PropertyState,
2420
+ context: IValueResolutionContext,
2421
+ onlyDefault = false
2422
+ ): IDynamicValue | null {
2423
+ if (!entity.static) {
2424
+ // Only static properties can hold value at the 'property' or prototype level
2425
+ // When a property is part of a living value or instance, it is represented by input and output maps
2426
+ return null;
2427
+ }
2428
+
2429
+ // We don't check whether it is part of the test, because it is a global value (static property)
2430
+ if (!!context.execution) {
2431
+ const lastExecutionValue = context.lastExecutionResults?.readValue(
2432
+ entity.id
2433
+ );
2434
+
2435
+ if (lastExecutionValue && !onlyDefault) {
2436
+ const returnDeclarationValue: IDynamicValue = {
2437
+ value: lastExecutionValue,
2438
+ valueOwner: entity,
2439
+ type: DynamicValueTypes.ExecutionResult,
2440
+ inheritanceLink: null
2441
+ };
2442
+
2443
+ return returnDeclarationValue;
2444
+ }
2445
+ }
2446
+
2447
+ const isTopLevelExecution =
2448
+ !context.execution || !context.execution.parentExecution;
2449
+ const preferrerType = context.getValueTypePreference(entity.id);
2450
+
2451
+ if (isTopLevelExecution) {
2452
+ const testValue = context.localTestValues?.readValue(entity.id);
2453
+
2454
+ if (
2455
+ !!testValue &&
2456
+ !onlyDefault &&
2457
+ (preferrerType === null ||
2458
+ preferrerType !== DynamicValueTypes.DefaultValue)
2459
+ ) {
2460
+ return {
2461
+ value: testValue,
2462
+ valueOwner: entity,
2463
+ type: DynamicValueTypes.Testing,
2464
+ inheritanceLink: null
2465
+ };
2466
+ }
2467
+ }
2468
+
2469
+ const defaultValue = entity.defaultValue;
2470
+ let value: IDynamicValue | null = null;
2471
+
2472
+ if (
2473
+ defaultValue &&
2474
+ (onlyDefault ||
2475
+ preferrerType === null ||
2476
+ preferrerType !== DynamicValueTypes.Testing)
2477
+ ) {
2478
+ const literalValue: LiteralValueState = defaultValue;
2479
+
2480
+ value = {
2481
+ value: literalValue,
2482
+ valueOwner: entity,
2483
+ type: DynamicValueTypes.DefaultValue,
2484
+ inheritanceLink: null
2485
+ };
2486
+ }
2487
+
2488
+ const isDefinitionRequired = checkIsRequiredValue(entity);
2489
+
2490
+ const dataType = entity.getDataType(null);
2491
+
2492
+ const isMissing =
2493
+ isDefinitionRequired &&
2494
+ (!value?.value ||
2495
+ (!checkIsNullable(dataType) &&
2496
+ checkIsLiteralValueExplicitlyEmpty(
2497
+ value?.value as LiteralValueState
2498
+ )));
2499
+
2500
+ if (isMissing) {
2501
+ return {
2502
+ value: null,
2503
+ valueOwner: entity,
2504
+ type: DynamicValueTypes.Missing,
2505
+ inheritanceLink: null
2506
+ };
2507
+ }
2508
+
2509
+ // Check if it is part of test but not required, then set as "empty"
2510
+ if (checkIsLiteralValueEmpty(value?.value as LiteralValueState)) {
2511
+ return {
2512
+ value: null,
2513
+ valueOwner: entity,
2514
+ type: DynamicValueTypes.Empty,
2515
+ inheritanceLink: null
2516
+ };
2517
+ }
2518
+
2519
+ // If there is a value return that one, otherwise return the definition of "External"
2520
+ return value;
2521
+ }
2522
+
2523
+ export function resolveValueDescriptorValue(
2524
+ entity: ValueDescriptorState,
2525
+ context: IValueResolutionContext,
2526
+ onlyDefault = false
2527
+ ): IDynamicValue | null {
2528
+ if (
2529
+ !!context.execution &&
2530
+ context.execution.hasEntity(entity) &&
2531
+ !onlyDefault
2532
+ ) {
2533
+ const lastExecutionValue = context.lastExecutionResults?.readValue(
2534
+ entity.id
2535
+ );
2536
+
2537
+ if (lastExecutionValue) {
2538
+ const returnDeclarationValue: IDynamicValue = {
2539
+ value: lastExecutionValue,
2540
+ valueOwner: entity,
2541
+ type: DynamicValueTypes.ExecutionResult,
2542
+ inheritanceLink: null
2543
+ };
2544
+
2545
+ return returnDeclarationValue;
2546
+ }
2547
+ }
2548
+
2549
+ const isTopLevelExecution =
2550
+ !context.execution || !context.execution.parentExecution;
2551
+ const preferrerType = context.getValueTypePreference(entity.id);
2552
+
2553
+ if (isTopLevelExecution) {
2554
+ const testValue = context.localTestValues?.readValue(entity.id);
2555
+
2556
+ if (
2557
+ !!testValue &&
2558
+ !onlyDefault &&
2559
+ (preferrerType === null ||
2560
+ preferrerType !== DynamicValueTypes.DefaultValue)
2561
+ ) {
2562
+ return {
2563
+ value: testValue,
2564
+ valueOwner: entity,
2565
+ type: DynamicValueTypes.Testing,
2566
+ inheritanceLink: null
2567
+ };
2568
+ }
2569
+ }
2570
+
2571
+ const defaultValue = entity.defaultValue;
2572
+ let value: IDynamicValue | null = null;
2573
+
2574
+ if (
2575
+ defaultValue &&
2576
+ (onlyDefault ||
2577
+ preferrerType === null ||
2578
+ preferrerType !== DynamicValueTypes.Testing)
2579
+ ) {
2580
+ const literalValue: LiteralValueState = defaultValue;
2581
+
2582
+ value = {
2583
+ value: literalValue,
2584
+ valueOwner: entity,
2585
+ type: DynamicValueTypes.DefaultValue,
2586
+ inheritanceLink: null
2587
+ };
2588
+ }
2589
+
2590
+ /*
2591
+ We don't check wether value-descriptors are missing, because they aren't used at runtime.
2592
+ They are used as templates for how to use other value owning entities,
2593
+ so, forcing the user to give them a value would not make sense.
2594
+
2595
+ Except if they are the "hidden" declaration of a search input
2596
+ */
2597
+
2598
+ if (entity.parent?.type === EntityType.Search) {
2599
+ const counterpartInputMap = (entity.parent as SearchState).inputs.find(
2600
+ (input) => input.declaration?.id === entity.id
2601
+ );
2602
+
2603
+ if (counterpartInputMap) {
2604
+ return resolveInputMapValue(
2605
+ counterpartInputMap,
2606
+ context,
2607
+ onlyDefault
2608
+ );
2609
+ }
2610
+ }
2611
+
2612
+ // Check if it is part of test but not required, then set as "empty"
2613
+ if (checkIsLiteralValueEmpty(value?.value || null)) {
2614
+ return {
2615
+ value: null,
2616
+ valueOwner: entity,
2617
+ type: DynamicValueTypes.Empty,
2618
+ inheritanceLink: null
2619
+ };
2620
+ }
2621
+
2622
+ // If there is a value return that one, otherwise return the definition of "External"
2623
+ return value;
2624
+ }
2625
+
2626
+ export function resolveValue(
2627
+ entity: EntityWithValueState | PropertyState | ValueDescriptorState,
2628
+ context: IValueResolutionContext,
2629
+ onlyDefault = false
2630
+ ): IDynamicValue | null {
2631
+ if (resolving.has(entity.id)) {
2632
+ return {
2633
+ value: null,
2634
+ valueOwner: entity,
2635
+ type: DynamicValueTypes.Undefined,
2636
+ inheritanceLink: null
2637
+ };
2638
+ }
2639
+
2640
+ resolving.add(entity.id);
2641
+ try {
2642
+ switch (entity.type) {
2643
+ case EntityType.ArgumentDeclaration:
2644
+ return resolveArgumentDeclarationValue(
2645
+ entity,
2646
+ context,
2647
+ onlyDefault
2648
+ );
2649
+ case EntityType.InputMap:
2650
+ return resolveInputMapValue(entity, context, onlyDefault);
2651
+ case EntityType.VariableDeclaration:
2652
+ return resolveVarDeclarationValue(entity, context, onlyDefault);
2653
+ case EntityType.VariableInstance:
2654
+ return resolveVarInstanceValue(entity, context, onlyDefault);
2655
+ case EntityType.OutputMap:
2656
+ return resolveOutputMapValue(entity, context, onlyDefault);
2657
+ case EntityType.ReturnStatement:
2658
+ case EntityType.BreakStatement:
2659
+ case EntityType.ContinueStatement:
2660
+ return resolveTerminationEntityValue(entity, context, onlyDefault);
2661
+ case EntityType.Property:
2662
+ return resolvePropertyValue(entity, context, onlyDefault);
2663
+ case EntityType.ValueDescriptor:
2664
+ return resolveValueDescriptorValue(entity, context, onlyDefault);
2665
+ case EntityType.Operation:
2666
+ case EntityType.FunctionCall:
2667
+ case EntityType.InternalCall:
2668
+ case EntityType.Search:
2669
+ return resolvePassThroughCallableValue(
2670
+ entity,
2671
+ context,
2672
+ onlyDefault
2673
+ );
2674
+ default:
2675
+ return null;
2676
+ }
2677
+ } finally {
2678
+ resolving.delete(entity.id);
2679
+ }
2680
+ }
2681
+
2682
+ export function resolveNextValue(
2683
+ entity: ValueReadingEntityState,
2684
+ context: IValueResolutionContext,
2685
+ onlyDefault = false
2686
+ ): IDynamicValue | null {
2687
+ if (resolving.has(entity.id)) {
2688
+ return {
2689
+ value: null,
2690
+ valueOwner: entity,
2691
+ type: DynamicValueTypes.Undefined,
2692
+ inheritanceLink: null
2693
+ };
2694
+ }
2695
+
2696
+ resolving.add(entity.id);
2697
+ try {
2698
+ switch (entity.type) {
2699
+ case EntityType.InputMap:
2700
+ return resolveInputMapNextValue(entity, context, onlyDefault);
2701
+ case EntityType.VariableDeclaration:
2702
+ return resolveVarDeclarationNextValue(entity, context, onlyDefault);
2703
+ case EntityType.VariableInstance:
2704
+ return resolveVarInstanceNextValue(entity, context, onlyDefault);
2705
+ case EntityType.ReturnStatement:
2706
+ case EntityType.BreakStatement:
2707
+ case EntityType.ContinueStatement:
2708
+ return resolveTerminationEntityValue(entity, context, onlyDefault);
2709
+ default:
2710
+ return null;
2711
+ }
2712
+ } finally {
2713
+ resolving.delete(entity.id);
2714
+ }
2715
+ }
2716
+
2717
+ // If the default value which is part of the project logic tree is the one resolved for this entity
2718
+ // We create a new standalone literal-value instance to store the value
2719
+ // This way we create a local test value instead of editing the default value of the entity in the canvas
2720
+ export function generateStandaloneIfDefault(
2721
+ dynamicValue: IDynamicValue
2722
+ ): IDynamicValue {
2723
+ if (
2724
+ !!dynamicValue &&
2725
+ dynamicValue.type === DynamicValueTypes.DefaultValue &&
2726
+ !!dynamicValue.value &&
2727
+ !!dynamicValue.valueOwner &&
2728
+ (!ENTITY_WITH_DEFAULT_VALUE_TYPES.includes(
2729
+ dynamicValue.valueOwner.type
2730
+ ) ||
2731
+ (dynamicValue.valueOwner as EntityWithDefaultValueState)
2732
+ .defaultValue?.id === dynamicValue.value.id)
2733
+ ) {
2734
+ const newInstance = assembleStandaloneLiteralValueFromDataType(
2735
+ dynamicValue.valueOwner.getDataType(null),
2736
+ dynamicValue.valueOwner,
2737
+ dynamicValue.valueOwner.project
2738
+ );
2739
+
2740
+ newInstance?.metaSync(
2741
+ {
2742
+ value: (dynamicValue.value as any)?.value,
2743
+ rawString: typeof (dynamicValue.value as any)?.value === 'string' && typeof (dynamicValue.value as any)?.rawString === 'string' ? (dynamicValue.value as any)?.rawString : undefined
2744
+ },
2745
+ null
2746
+ );
2747
+
2748
+ return {
2749
+ // It is still a default value, but it is now detached from the entity (standalone)
2750
+ type: DynamicValueTypes.DefaultValue,
2751
+ value: newInstance,
2752
+ valueOwner: dynamicValue.valueOwner,
2753
+ inheritanceLink: null
2754
+ };
2755
+ }
2756
+
2757
+ return dynamicValue;
2758
+ }
2759
+
2760
+ export function propagateNewStaticPropertyValueToVariables(
2761
+ entity: PropertyState,
2762
+ project: ProjectState,
2763
+ newValue: LiteralValueType,
2764
+ storage: ChangeSet | IValueStoreClient
2765
+ ): ChangeSet | null {
2766
+ let onlyDefault = false;
2767
+ let changeSet: ChangeSet | null = null;
2768
+ let valueStore: IValueStoreClient | null = null;
2769
+
2770
+ if (storage instanceof ChangeSet) {
2771
+ onlyDefault = true;
2772
+ changeSet = storage as ChangeSet;
2773
+ valueStore = null;
2774
+ } else {
2775
+ changeSet = null;
2776
+ valueStore = storage as IValueStoreClient;
2777
+ }
2778
+
2779
+ // Propagate to the value of any variable declaration whos data-type entity is the parent of this property
2780
+ const parentEntity = entity.parent as DefinitionEntityState;
2781
+
2782
+ const variableDeclarations = project.getVariableDeclarations();
2783
+
2784
+ variableDeclarations.forEach((variableDeclaration) => {
2785
+ const variableDeclarationDataType =
2786
+ variableDeclaration.getDataType(null);
2787
+
2788
+ if (variableDeclarationDataType?.entity?.id === parentEntity.id) {
2789
+ let existingLiteralValue = onlyDefault
2790
+ ? variableDeclaration.defaultValue
2791
+ : valueStore?.readValue(variableDeclaration.id);
2792
+
2793
+ if (!existingLiteralValue) {
2794
+ if (onlyDefault) {
2795
+ // Create new test value
2796
+ existingLiteralValue =
2797
+ assembleAndAddLiteralValueFromDataType(
2798
+ variableDeclaration.getDataType(null),
2799
+ variableDeclaration,
2800
+ project,
2801
+ changeSet
2802
+ );
2803
+ } else {
2804
+ existingLiteralValue =
2805
+ assembleStandaloneLiteralValueFromDataType(
2806
+ variableDeclaration.getDataType(null),
2807
+ variableDeclaration,
2808
+ project
2809
+ );
2810
+ }
2811
+ } else if (
2812
+ !onlyDefault &&
2813
+ !!existingLiteralValue &&
2814
+ existingLiteralValue.id === variableDeclaration.defaultValue?.id
2815
+ ) {
2816
+ // If the value instance is the default value, we should generate a standalone value
2817
+ existingLiteralValue =
2818
+ assembleStandaloneLiteralValueFromDataType(
2819
+ variableDeclaration.getDataType(null),
2820
+ variableDeclaration,
2821
+ project
2822
+ );
2823
+ }
2824
+
2825
+ const propertyName = safeResolveEntityName(entity, project);
2826
+ const resolveCodeName =
2827
+ entity.codeName ||
2828
+ entity.extends?.codeName ||
2829
+ entity.implements[0]?.codeName ||
2830
+ toCamelCase(propertyName);
2831
+
2832
+ let initialDefaultValue: UntypedObjectValue = {};
2833
+
2834
+ if (
2835
+ variableDeclaration.dataType?.entity?.type ===
2836
+ EntityType.DefinitionEntity
2837
+ ) {
2838
+ initialDefaultValue = {
2839
+ ...initialDefaultValue,
2840
+ ...variableDeclaration.dataType.entity.getActiveRawDefaultValue()
2841
+ };
2842
+ }
2843
+
2844
+ if (isObject(existingLiteralValue?.value)) {
2845
+ initialDefaultValue = {
2846
+ ...initialDefaultValue,
2847
+ ...(existingLiteralValue.value as UntypedObjectValue)
2848
+ };
2849
+ }
2850
+
2851
+ initialDefaultValue[resolveCodeName] = newValue;
2852
+
2853
+ existingLiteralValue?.metaSync(
2854
+ {
2855
+ value: initialDefaultValue
2856
+ },
2857
+ changeSet
2858
+ );
2859
+
2860
+ if (!onlyDefault) {
2861
+ valueStore?.writeValue(
2862
+ variableDeclaration,
2863
+ existingLiteralValue as LiteralValueState
2864
+ );
2865
+ }
2866
+ return;
2867
+ }
2868
+ });
2869
+
2870
+ return changeSet;
2871
+ }
2872
+
2873
+ export function propagateNewInputOrOutputMapValueToParentVariable(
2874
+ entity: InputMapState | OutputMapState,
2875
+ project: ProjectState,
2876
+ newValue: LiteralValueType,
2877
+ storage: ChangeSet | IValueStoreClient
2878
+ ): ChangeSet | null {
2879
+ let onlyDefault = false;
2880
+ let changeSet: ChangeSet | null = null;
2881
+ let valueStore: IValueStoreClient | null = null;
2882
+
2883
+ if (storage instanceof ChangeSet) {
2884
+ onlyDefault = true;
2885
+ changeSet = storage as ChangeSet;
2886
+ valueStore = null;
2887
+ } else {
2888
+ changeSet = null;
2889
+ valueStore = storage as IValueStoreClient;
2890
+ }
2891
+
2892
+ const variableDeclaration = getDeclaration(entity.parent as VariableState);
2893
+
2894
+ const variableDeclarationDataType = variableDeclaration.getDataType(null);
2895
+
2896
+ if (!variableDeclarationDataType?.isObject()) {
2897
+ return changeSet;
2898
+ }
2899
+
2900
+ let existingLiteralValue = onlyDefault
2901
+ ? variableDeclaration.defaultValue
2902
+ : valueStore?.readValue(variableDeclaration.id);
2903
+
2904
+ if (!existingLiteralValue) {
2905
+ if (onlyDefault) {
2906
+ // Create new test value
2907
+ existingLiteralValue = assembleAndAddLiteralValueFromDataType(
2908
+ variableDeclaration.getDataType(null),
2909
+ variableDeclaration,
2910
+ project,
2911
+ changeSet
2912
+ );
2913
+ } else {
2914
+ existingLiteralValue = assembleStandaloneLiteralValueFromDataType(
2915
+ variableDeclaration.getDataType(null),
2916
+ variableDeclaration,
2917
+ project
2918
+ );
2919
+ }
2920
+ } else if (
2921
+ !onlyDefault &&
2922
+ !!existingLiteralValue &&
2923
+ existingLiteralValue.id === variableDeclaration.defaultValue?.id
2924
+ ) {
2925
+ // If the value instance is the default value, we should generate a standalone value
2926
+ existingLiteralValue = assembleStandaloneLiteralValueFromDataType(
2927
+ variableDeclaration.getDataType(null),
2928
+ variableDeclaration,
2929
+ project
2930
+ );
2931
+ }
2932
+
2933
+ const resolvedEntityName = safeResolveEntityName(entity, project);
2934
+ const resolveCodeName =
2935
+ entity.codeName ||
2936
+ entity.declaration?.codeName ||
2937
+ toCamelCase(resolvedEntityName);
2938
+
2939
+ let initialDefaultValue: UntypedObjectValue = {};
2940
+
2941
+ if (
2942
+ variableDeclaration.dataType?.entity?.type ===
2943
+ EntityType.DefinitionEntity
2944
+ ) {
2945
+ initialDefaultValue = {
2946
+ ...initialDefaultValue,
2947
+ ...variableDeclaration.dataType.entity.getActiveRawDefaultValue()
2948
+ };
2949
+ }
2950
+
2951
+ if (isObject(existingLiteralValue?.value)) {
2952
+ initialDefaultValue = {
2953
+ ...initialDefaultValue,
2954
+ ...(existingLiteralValue.value as UntypedObjectValue)
2955
+ };
2956
+ }
2957
+
2958
+ initialDefaultValue[resolveCodeName] = newValue;
2959
+
2960
+ existingLiteralValue?.metaSync(
2961
+ {
2962
+ value: initialDefaultValue
2963
+ },
2964
+ changeSet
2965
+ );
2966
+
2967
+ if (!onlyDefault) {
2968
+ valueStore?.writeValue(
2969
+ variableDeclaration,
2970
+ existingLiteralValue as LiteralValueState
2971
+ );
2972
+ }
2973
+
2974
+ if (
2975
+ (newValue === '' || newValue === null || newValue === undefined) &&
2976
+ entity.type === EntityType.OutputMap
2977
+ ) {
2978
+ // Find the corresponding input map and delete its value too
2979
+ const counterpartInput = variableDeclaration.inputs.find(
2980
+ (input) =>
2981
+ input.declaration?.id === entity.declaration?.id ||
2982
+ safeResolveEntityName(input, project) === resolvedEntityName
2983
+ );
2984
+
2985
+ if (counterpartInput) {
2986
+ let existingInputLiteralValue = onlyDefault
2987
+ ? counterpartInput.defaultValue
2988
+ : valueStore?.readValue(counterpartInput.id);
2989
+
2990
+ if (existingInputLiteralValue) {
2991
+ existingInputLiteralValue.metaSync(
2992
+ {
2993
+ value: null
2994
+ },
2995
+ changeSet
2996
+ );
2997
+ }
2998
+
2999
+ if (!onlyDefault) {
3000
+ valueStore?.removeValue(counterpartInput.id);
3001
+ }
3002
+ }
3003
+ }
3004
+
3005
+ return changeSet;
3006
+ }
3007
+
3008
+ export function afterLiteralValueDeleteSideEffects(
3009
+ entity: EntityWithValueState,
3010
+ project: ProjectState,
3011
+ storage: ChangeSet | IValueStoreClient
3012
+ ): ChangeSet | null {
3013
+ let onlyDefault = false;
3014
+ let changeSet: ChangeSet | null = null;
3015
+ let valueStore: IValueStoreClient | null = null;
3016
+
3017
+ if (storage instanceof ChangeSet) {
3018
+ onlyDefault = true;
3019
+ changeSet = storage as ChangeSet;
3020
+ valueStore = null;
3021
+ } else {
3022
+ changeSet = null;
3023
+ valueStore = storage as IValueStoreClient;
3024
+ }
3025
+
3026
+ if (VARIABLE_TYPES.includes(entity.type)) {
3027
+ const declaration = getDeclaration(entity as VariableState);
3028
+
3029
+ if (declaration.dataType?.isObject()) {
3030
+ declaration.inputs.forEach((input) => {
3031
+ if (
3032
+ input.declaration?.type === EntityType.Property &&
3033
+ input.declaration.static
3034
+ ) {
3035
+ let existingLiteralValue = onlyDefault
3036
+ ? (
3037
+ input as EntityWithDefaultValueState
3038
+ ).getDefaultValue?.() || null
3039
+ : valueStore?.readValue(input.declaration.id);
3040
+
3041
+ if (!existingLiteralValue) {
3042
+ if (onlyDefault) {
3043
+ // Create new test value
3044
+ existingLiteralValue =
3045
+ assembleAndAddLiteralValueFromDataType(
3046
+ input.declaration.getDataType(null),
3047
+ input.declaration,
3048
+ project,
3049
+ changeSet
3050
+ );
3051
+ } else {
3052
+ existingLiteralValue =
3053
+ assembleStandaloneLiteralValueFromDataType(
3054
+ input.declaration.getDataType(null),
3055
+ input.declaration,
3056
+ project
3057
+ );
3058
+ }
3059
+ } else if (
3060
+ !onlyDefault &&
3061
+ !!existingLiteralValue &&
3062
+ existingLiteralValue.id ===
3063
+ input.declaration.defaultValue?.id
3064
+ ) {
3065
+ // If the value instance is the default value, we should generate a standalone value
3066
+ existingLiteralValue =
3067
+ assembleStandaloneLiteralValueFromDataType(
3068
+ input.declaration.getDataType(null),
3069
+ input.declaration,
3070
+ project
3071
+ );
3072
+ }
3073
+
3074
+ existingLiteralValue?.metaSync(
3075
+ {
3076
+ value: null
3077
+ },
3078
+ changeSet
3079
+ );
3080
+
3081
+ if (!onlyDefault) {
3082
+ valueStore?.removeValue(input.declaration?.id);
3083
+ }
3084
+ } else if (input.declaration?.type === EntityType.Property) {
3085
+ let existingLiteralValue = onlyDefault
3086
+ ? (
3087
+ input as EntityWithDefaultValueState
3088
+ ).getDefaultValue?.() || null
3089
+ : valueStore?.readValue(input.id);
3090
+
3091
+ // Delete the value if it exists
3092
+ if (existingLiteralValue) {
3093
+ existingLiteralValue.metaSync(
3094
+ {
3095
+ value: null
3096
+ },
3097
+ changeSet
3098
+ );
3099
+ }
3100
+
3101
+ if (!onlyDefault) {
3102
+ valueStore?.removeValue(input.id);
3103
+ }
3104
+ }
3105
+
3106
+ return;
3107
+ });
3108
+ }
3109
+ } else if (entity.type === EntityType.InputMap) {
3110
+ if (
3111
+ entity.declaration?.type === EntityType.Property &&
3112
+ entity.declaration.static
3113
+ ) {
3114
+ propagateNewStaticPropertyValueToVariables(
3115
+ entity.declaration,
3116
+ project,
3117
+ null,
3118
+ storage
3119
+ );
3120
+ } else if (
3121
+ VARIABLE_TYPES.includes(entity.parent.type) &&
3122
+ entity.declaration?.type === EntityType.Property
3123
+ ) {
3124
+ propagateNewInputOrOutputMapValueToParentVariable(
3125
+ entity,
3126
+ project,
3127
+ null,
3128
+ storage
3129
+ );
3130
+ }
3131
+ } else if (entity.type === EntityType.OutputMap) {
3132
+ if (
3133
+ entity.declaration?.type === EntityType.Property &&
3134
+ entity.declaration.static
3135
+ ) {
3136
+ propagateNewStaticPropertyValueToVariables(
3137
+ entity.declaration,
3138
+ project,
3139
+ null,
3140
+ storage
3141
+ );
3142
+ } else if (
3143
+ VARIABLE_TYPES.includes(entity.parent.type) &&
3144
+ entity.declaration?.type === EntityType.Property
3145
+ ) {
3146
+ propagateNewInputOrOutputMapValueToParentVariable(
3147
+ entity,
3148
+ project,
3149
+ null,
3150
+ storage
3151
+ );
3152
+ }
3153
+ } else if (entity.type === EntityType.Property) {
3154
+ if (entity.static) {
3155
+ propagateNewStaticPropertyValueToVariables(
3156
+ entity,
3157
+ project,
3158
+ null,
3159
+ storage
3160
+ );
3161
+ }
3162
+ }
3163
+
3164
+ return changeSet;
3165
+ }
3166
+
3167
+ export function afterLiteralValueChangeSideEffects(
3168
+ newValue: LiteralValueType,
3169
+ entity: EntityWithValueState,
3170
+ project: ProjectState,
3171
+ storage: ChangeSet | IValueStoreClient
3172
+ ): ChangeSet | null {
3173
+ let onlyDefault = false;
3174
+ let changeSet: ChangeSet | null = null;
3175
+ let valueStore: IValueStoreClient | null = null;
3176
+
3177
+ if (storage instanceof ChangeSet) {
3178
+ onlyDefault = true;
3179
+ changeSet = storage as ChangeSet;
3180
+ valueStore = null;
3181
+ } else {
3182
+ changeSet = null;
3183
+ valueStore = storage as IValueStoreClient;
3184
+ }
3185
+
3186
+ if (VARIABLE_TYPES.includes(entity.type)) {
3187
+ const declaration = getDeclaration(entity as VariableState);
3188
+
3189
+ if (declaration.dataType?.isObject()) {
3190
+ let initialDefaultValue: UntypedObjectValue = {};
3191
+
3192
+ if (
3193
+ declaration.dataType?.entity?.type ===
3194
+ EntityType.DefinitionEntity
3195
+ ) {
3196
+ initialDefaultValue = {
3197
+ ...initialDefaultValue,
3198
+ ...declaration.dataType.entity.getActiveRawDefaultValue()
3199
+ };
3200
+ }
3201
+ const parentVariableObjectValue = isObject(newValue)
3202
+ ? (newValue as {
3203
+ [key: string]: UntypedValue;
3204
+ })
3205
+ : initialDefaultValue;
3206
+
3207
+ declaration.inputs.forEach((input) => {
3208
+ if (
3209
+ input.declaration?.type === EntityType.Property &&
3210
+ input.declaration.static
3211
+ ) {
3212
+ let existingLiteralValue = onlyDefault
3213
+ ? (
3214
+ entity as EntityWithDefaultValueState
3215
+ ).getDefaultValue?.() || null
3216
+ : valueStore?.readValue(input.declaration.id);
3217
+
3218
+ if (!existingLiteralValue) {
3219
+ if (onlyDefault) {
3220
+ // Create new test value
3221
+ existingLiteralValue =
3222
+ assembleAndAddLiteralValueFromDataType(
3223
+ input.declaration.getDataType(null),
3224
+ input.declaration,
3225
+ project,
3226
+ changeSet
3227
+ );
3228
+ } else {
3229
+ existingLiteralValue =
3230
+ assembleStandaloneLiteralValueFromDataType(
3231
+ input.declaration.getDataType(null),
3232
+ input.declaration,
3233
+ project
3234
+ );
3235
+ }
3236
+ } else if (
3237
+ !onlyDefault &&
3238
+ !!existingLiteralValue &&
3239
+ existingLiteralValue.id ===
3240
+ input.declaration.defaultValue?.id
3241
+ ) {
3242
+ // If the value instance is the default value, we should generate a standalone value
3243
+ existingLiteralValue =
3244
+ assembleStandaloneLiteralValueFromDataType(
3245
+ input.declaration.getDataType(null),
3246
+ input.declaration,
3247
+ project
3248
+ );
3249
+ }
3250
+
3251
+ const inputName = safeResolveEntityName(input, project);
3252
+ const resolveCodeName =
3253
+ input.codeName ||
3254
+ input.declaration?.codeName ||
3255
+ toCamelCase(inputName);
3256
+
3257
+ const newRawValue =
3258
+ parentVariableObjectValue[resolveCodeName];
3259
+
3260
+ existingLiteralValue?.metaSync(
3261
+ {
3262
+ value: newRawValue
3263
+ },
3264
+ changeSet
3265
+ );
3266
+
3267
+ if (!onlyDefault) {
3268
+ valueStore?.writeValue(
3269
+ input.declaration,
3270
+ existingLiteralValue as LiteralValueState
3271
+ );
3272
+ }
3273
+ } else if (input.declaration?.type === EntityType.Property) {
3274
+ let existingLiteralValue = onlyDefault
3275
+ ? (
3276
+ entity as EntityWithDefaultValueState
3277
+ ).getDefaultValue?.() || null
3278
+ : valueStore?.readValue(input.id);
3279
+
3280
+ // Delete the value if it exists
3281
+ if (existingLiteralValue) {
3282
+ existingLiteralValue.metaSync(
3283
+ {
3284
+ value: null
3285
+ },
3286
+ changeSet
3287
+ );
3288
+ }
3289
+
3290
+ if (!onlyDefault) {
3291
+ valueStore?.removeValue(input.id);
3292
+ }
3293
+ }
3294
+
3295
+ return;
3296
+ });
3297
+ }
3298
+ } else if (entity.type === EntityType.InputMap) {
3299
+ if (
3300
+ entity.declaration?.type === EntityType.Property &&
3301
+ entity.declaration.static
3302
+ ) {
3303
+ propagateNewStaticPropertyValueToVariables(
3304
+ entity.declaration,
3305
+ project,
3306
+ newValue,
3307
+ storage
3308
+ );
3309
+ } else if (
3310
+ VARIABLE_TYPES.includes(entity.parent.type) &&
3311
+ entity.declaration?.type === EntityType.Property
3312
+ ) {
3313
+ propagateNewInputOrOutputMapValueToParentVariable(
3314
+ entity,
3315
+ project,
3316
+ newValue,
3317
+ storage
3318
+ );
3319
+ }
3320
+ } else if (entity.type === EntityType.OutputMap) {
3321
+ if (
3322
+ entity.declaration?.type === EntityType.Property &&
3323
+ entity.declaration.static
3324
+ ) {
3325
+ propagateNewStaticPropertyValueToVariables(
3326
+ entity.declaration,
3327
+ project,
3328
+ null,
3329
+ storage
3330
+ );
3331
+ } else if (
3332
+ VARIABLE_TYPES.includes(entity.parent.type) &&
3333
+ entity.declaration?.type === EntityType.Property
3334
+ ) {
3335
+ propagateNewInputOrOutputMapValueToParentVariable(
3336
+ entity,
3337
+ project,
3338
+ null,
3339
+ storage
3340
+ );
3341
+ }
3342
+ } else if (entity.type === EntityType.Property) {
3343
+ if (entity.static) {
3344
+ propagateNewStaticPropertyValueToVariables(
3345
+ entity,
3346
+ project,
3347
+ newValue,
3348
+ storage
3349
+ );
3350
+ }
3351
+ }
3352
+
3353
+ return changeSet;
3354
+ }
3355
+
3356
+ export function handleLiteralValueDelete(
3357
+ entity: EntityWithValueState,
3358
+ project: ProjectState,
3359
+ storage: ChangeSet | IValueStoreClient
3360
+ ): ChangeSet | null {
3361
+ // Propagate values
3362
+ const propagatedValueOwners = getEntitiesToPropagateValuesTo(
3363
+ entity,
3364
+ project
3365
+ );
3366
+
3367
+ let onlyDefault = false;
3368
+ let changeSet: ChangeSet | null = null;
3369
+ let valueStore: IValueStoreClient | null = null;
3370
+
3371
+ if (storage instanceof ChangeSet) {
3372
+ onlyDefault = true;
3373
+ changeSet = storage as ChangeSet;
3374
+ valueStore = null;
3375
+ } else {
3376
+ changeSet = null;
3377
+ valueStore = storage as IValueStoreClient;
3378
+ }
3379
+
3380
+ propagatedValueOwners.forEach((propagatedValueOwner) => {
3381
+ let valueInstance = onlyDefault
3382
+ ? (
3383
+ propagatedValueOwner as EntityWithDefaultValueState
3384
+ ).getDefaultValue?.() || null
3385
+ : valueStore?.readValue(propagatedValueOwner.id);
3386
+
3387
+ if (!onlyDefault) {
3388
+ valueStore?.removeValue(propagatedValueOwner.id);
3389
+ } else {
3390
+ valueInstance?.remove({ ignoreUpstream: false }, changeSet);
3391
+ }
3392
+
3393
+ afterLiteralValueDeleteSideEffects(
3394
+ propagatedValueOwner,
3395
+ project,
3396
+ storage
3397
+ );
3398
+ });
3399
+
3400
+ return changeSet;
3401
+ }
3402
+
3403
+ export function handleLiteralValueChange(
3404
+ newValue: LiteralValueType,
3405
+ entity: EntityWithValueState,
3406
+ project: ProjectState,
3407
+ storage: ChangeSet | IValueStoreClient,
3408
+ asCastedType?: PrimitiveTypes,
3409
+ rawString?: string | null
3410
+ ): ChangeSet | null {
3411
+ // Propagate values
3412
+ const propagatedValueOwners = getEntitiesToPropagateValuesTo(
3413
+ entity,
3414
+ project
3415
+ ) as EntityWithDefaultValueState[];
3416
+
3417
+ let onlyDefault = false;
3418
+ let changeSet: ChangeSet | null = null;
3419
+ let valueStore: IValueStoreClient | null = null;
3420
+
3421
+ if (storage instanceof ChangeSet) {
3422
+ onlyDefault = true;
3423
+ changeSet = storage as ChangeSet;
3424
+ valueStore = null;
3425
+ } else {
3426
+ changeSet = null;
3427
+ valueStore = storage as IValueStoreClient;
3428
+ }
3429
+
3430
+ if (project.diggestedBuiltInBaseEntitiesIds.has(entity.id)) {
3431
+ return changeSet;
3432
+ }
3433
+
3434
+ propagatedValueOwners.forEach((propagatedValueOwner) => {
3435
+ if (
3436
+ project.diggestedBuiltInBaseEntitiesIds.has(propagatedValueOwner.id)
3437
+ ) {
3438
+ return;
3439
+ }
3440
+
3441
+ let valueInstance = null;
3442
+
3443
+ if (onlyDefault) {
3444
+ const resolvedValueInstance =
3445
+ propagatedValueOwner.getDefaultValue?.() || null;
3446
+
3447
+ if (!!resolvedValueInstance) {
3448
+ if (
3449
+ project.diggestedBuiltInBaseEntitiesIds.has(
3450
+ resolvedValueInstance.id
3451
+ ) ||
3452
+ resolvedValueInstance.parent?.id !== propagatedValueOwner.id
3453
+ ) {
3454
+ const clonedValueInstance = resolvedValueInstance.clone(
3455
+ changeSet,
3456
+ propagatedValueOwner
3457
+ );
3458
+
3459
+ valueInstance = clonedValueInstance;
3460
+ } else {
3461
+ valueInstance = resolvedValueInstance;
3462
+ }
3463
+ }
3464
+ } else {
3465
+ valueInstance = valueStore?.readValue(propagatedValueOwner.id);
3466
+ }
3467
+
3468
+ if (!valueInstance) {
3469
+ if (onlyDefault) {
3470
+ // Create new test value
3471
+ valueInstance = assembleAndAddLiteralValueFromDataType(
3472
+ propagatedValueOwner.getDataType(null),
3473
+ propagatedValueOwner as EntityWithDefaultValueState,
3474
+ project,
3475
+ changeSet
3476
+ );
3477
+ changeSet?.add(valueInstance, ChangeSetEntityChangeType.Added);
3478
+ } else {
3479
+ valueInstance = assembleStandaloneLiteralValueFromDataType(
3480
+ propagatedValueOwner.getDataType(null),
3481
+ propagatedValueOwner,
3482
+ project
3483
+ );
3484
+ }
3485
+ } else if (
3486
+ !onlyDefault &&
3487
+ !!valueInstance &&
3488
+ valueInstance.id ===
3489
+ (
3490
+ propagatedValueOwner as EntityWithDefaultValueState
3491
+ ).getDefaultValue?.()?.id
3492
+ ) {
3493
+ // If the value instance is the default value, we should generate a standalone value
3494
+ valueInstance = assembleStandaloneLiteralValueFromDataType(
3495
+ propagatedValueOwner.getDataType(null),
3496
+ propagatedValueOwner,
3497
+ project
3498
+ );
3499
+ }
3500
+
3501
+ valueInstance?.setValueAsType(null, changeSet);
3502
+
3503
+ let newName: PrimitiveTypes =
3504
+ asCastedType || (valueInstance?.name as PrimitiveTypes);
3505
+
3506
+ if (
3507
+ (!valueInstance?.name ||
3508
+ valueInstance?.name === PrimitiveTypes.Untyped) &&
3509
+ !asCastedType
3510
+ ) {
3511
+ if (typeof newValue === 'string') {
3512
+ newName = PrimitiveTypes.String;
3513
+ } else if (newValue === null) {
3514
+ newName = PrimitiveTypes.Null;
3515
+ } else if (typeof newValue === 'number') {
3516
+ newName = PrimitiveTypes.Number;
3517
+ } else if (typeof newValue === 'boolean') {
3518
+ newName = PrimitiveTypes.Boolean;
3519
+ }
3520
+ }
3521
+
3522
+ valueInstance?.metaSync(
3523
+ {
3524
+ value: newValue,
3525
+ name: newName,
3526
+ rawString: rawString !== undefined ? rawString : null
3527
+ },
3528
+ changeSet
3529
+ );
3530
+
3531
+ if (!onlyDefault) {
3532
+ valueStore?.writeValue(
3533
+ propagatedValueOwner,
3534
+ valueInstance as LiteralValueState
3535
+ );
3536
+ }
3537
+
3538
+ afterLiteralValueChangeSideEffects(
3539
+ newValue,
3540
+ propagatedValueOwner,
3541
+ project,
3542
+ storage
3543
+ );
3544
+ });
3545
+
3546
+ return changeSet;
3547
+ }
3548
+
3549
+ export function propagateNewStaticPropertyValueAsTypeToVariables(
3550
+ entity: PropertyState,
3551
+ project: ProjectState,
3552
+ newValue: ValueAsTypeState | ValueAsTypeState[] | null,
3553
+ storage: ChangeSet | IValueStoreClient
3554
+ ): ChangeSet | null {
3555
+ let onlyDefault = false;
3556
+ let changeSet: ChangeSet | null = null;
3557
+ let valueStore: IValueStoreClient | null = null;
3558
+
3559
+ if (storage instanceof ChangeSet) {
3560
+ onlyDefault = true;
3561
+ changeSet = storage as ChangeSet;
3562
+ valueStore = null;
3563
+ } else {
3564
+ changeSet = null;
3565
+ valueStore = storage as IValueStoreClient;
3566
+ }
3567
+
3568
+ // Propagate to the value of any variable declaration whos data-type entity is the parent of this property
3569
+ const parentEntity = entity.parent as DefinitionEntityState;
3570
+
3571
+ const variableDeclarations = project.getVariableDeclarations();
3572
+
3573
+ variableDeclarations.forEach((variableDeclaration) => {
3574
+ const variableDeclarationDataType =
3575
+ variableDeclaration.getDataType(null);
3576
+
3577
+ if (variableDeclarationDataType?.entity?.id === parentEntity.id) {
3578
+ let existingLiteralValue = onlyDefault
3579
+ ? variableDeclaration.defaultValue
3580
+ : valueStore?.readValue(variableDeclaration.id);
3581
+
3582
+ if (!existingLiteralValue) {
3583
+ if (onlyDefault) {
3584
+ // Create new test value
3585
+ existingLiteralValue =
3586
+ assembleAndAddLiteralValueFromDataType(
3587
+ variableDeclaration.getDataType(null),
3588
+ variableDeclaration,
3589
+ project,
3590
+ changeSet
3591
+ );
3592
+ } else {
3593
+ existingLiteralValue =
3594
+ assembleStandaloneLiteralValueFromDataType(
3595
+ variableDeclaration.getDataType(null),
3596
+ variableDeclaration,
3597
+ project
3598
+ );
3599
+ }
3600
+ } else if (
3601
+ !onlyDefault &&
3602
+ !!existingLiteralValue &&
3603
+ existingLiteralValue.id === variableDeclaration.defaultValue?.id
3604
+ ) {
3605
+ // If the value instance is the default value, we should generate a standalone value
3606
+ existingLiteralValue =
3607
+ assembleStandaloneLiteralValueFromDataType(
3608
+ variableDeclaration.getDataType(null),
3609
+ variableDeclaration,
3610
+ project
3611
+ );
3612
+ }
3613
+
3614
+ const propertyName = safeResolveEntityName(entity, project);
3615
+ const resolveCodeName =
3616
+ entity.codeName ||
3617
+ entity.extends?.codeName ||
3618
+ entity.implements[0]?.codeName ||
3619
+ toCamelCase(propertyName);
3620
+
3621
+ let initialDefaultValue: UntypedObjectValue = {};
3622
+
3623
+ if (
3624
+ variableDeclaration.dataType?.entity?.type ===
3625
+ EntityType.DefinitionEntity
3626
+ ) {
3627
+ initialDefaultValue = {
3628
+ ...initialDefaultValue,
3629
+ ...variableDeclaration.dataType.entity.getActiveRawDefaultValue()
3630
+ };
3631
+ }
3632
+
3633
+ if (isObject(existingLiteralValue?.value)) {
3634
+ initialDefaultValue = {
3635
+ ...initialDefaultValue,
3636
+ ...(existingLiteralValue.value as UntypedObjectValue)
3637
+ };
3638
+ }
3639
+
3640
+ if (Array.isArray(newValue)) {
3641
+ // @ts-ignore
3642
+ initialDefaultValue[resolveCodeName] =
3643
+ newValue?.map((val) => val.toShallowJSON()) || null;
3644
+ } else {
3645
+ // @ts-ignore
3646
+ initialDefaultValue[resolveCodeName] =
3647
+ newValue?.toShallowJSON() || null;
3648
+ }
3649
+
3650
+ existingLiteralValue?.metaSync(
3651
+ {
3652
+ value: initialDefaultValue
3653
+ },
3654
+ changeSet
3655
+ );
3656
+
3657
+ if (!onlyDefault) {
3658
+ valueStore?.writeValue(
3659
+ variableDeclaration,
3660
+ existingLiteralValue as LiteralValueState
3661
+ );
3662
+ }
3663
+ return;
3664
+ }
3665
+ });
3666
+
3667
+ return changeSet;
3668
+ }
3669
+
3670
+ export function propagateNewInputOrOutputMapValueAsTypeToParentVariable(
3671
+ entity: InputMapState | OutputMapState,
3672
+ project: ProjectState,
3673
+ newValue: ValueAsTypeState | ValueAsTypeState[] | null,
3674
+ storage: ChangeSet | IValueStoreClient
3675
+ ): ChangeSet | null {
3676
+ let onlyDefault = false;
3677
+ let changeSet: ChangeSet | null = null;
3678
+ let valueStore: IValueStoreClient | null = null;
3679
+
3680
+ if (storage instanceof ChangeSet) {
3681
+ onlyDefault = true;
3682
+ changeSet = storage as ChangeSet;
3683
+ valueStore = null;
3684
+ } else {
3685
+ changeSet = null;
3686
+ valueStore = storage as IValueStoreClient;
3687
+ }
3688
+
3689
+ const variableDeclaration = getDeclaration(entity.parent as VariableState);
3690
+
3691
+ const variableDeclarationDataType = variableDeclaration.getDataType(null);
3692
+
3693
+ if (!variableDeclarationDataType?.isObject()) {
3694
+ return changeSet;
3695
+ }
3696
+
3697
+ let existingLiteralValue = onlyDefault
3698
+ ? variableDeclaration.defaultValue
3699
+ : valueStore?.readValue(variableDeclaration.id);
3700
+
3701
+ if (!existingLiteralValue) {
3702
+ if (onlyDefault) {
3703
+ // Create new test value
3704
+ existingLiteralValue = assembleAndAddLiteralValueFromDataType(
3705
+ variableDeclaration.getDataType(null),
3706
+ variableDeclaration,
3707
+ project,
3708
+ changeSet
3709
+ );
3710
+ } else {
3711
+ existingLiteralValue = assembleStandaloneLiteralValueFromDataType(
3712
+ variableDeclaration.getDataType(null),
3713
+ variableDeclaration,
3714
+ project
3715
+ );
3716
+ }
3717
+ } else if (
3718
+ !onlyDefault &&
3719
+ !!existingLiteralValue &&
3720
+ existingLiteralValue.id === variableDeclaration.defaultValue?.id
3721
+ ) {
3722
+ // If the value instance is the default value, we should generate a standalone value
3723
+ existingLiteralValue = assembleStandaloneLiteralValueFromDataType(
3724
+ variableDeclaration.getDataType(null),
3725
+ variableDeclaration,
3726
+ project
3727
+ );
3728
+ }
3729
+
3730
+ const resolvedEntityName = safeResolveEntityName(entity, project);
3731
+ const resolveCodeName =
3732
+ entity.codeName ||
3733
+ entity.declaration?.codeName ||
3734
+ toCamelCase(resolvedEntityName);
3735
+
3736
+ let initialDefaultValue: UntypedObjectValue = {};
3737
+
3738
+ if (
3739
+ variableDeclaration.dataType?.entity?.type ===
3740
+ EntityType.DefinitionEntity
3741
+ ) {
3742
+ initialDefaultValue = {
3743
+ ...initialDefaultValue,
3744
+ ...variableDeclaration.dataType.entity.getActiveRawDefaultValue()
3745
+ };
3746
+ }
3747
+
3748
+ if (isObject(existingLiteralValue?.value)) {
3749
+ initialDefaultValue = {
3750
+ ...initialDefaultValue,
3751
+ ...(existingLiteralValue.value as UntypedObjectValue)
3752
+ };
3753
+ }
3754
+
3755
+ if (Array.isArray(newValue)) {
3756
+ // @ts-ignore
3757
+ initialDefaultValue[resolveCodeName] =
3758
+ newValue?.map((val) => val.toShallowJSON()) || null;
3759
+ } else {
3760
+ // @ts-ignore
3761
+ initialDefaultValue[resolveCodeName] =
3762
+ newValue?.toShallowJSON() || null;
3763
+ }
3764
+
3765
+ existingLiteralValue?.metaSync(
3766
+ {
3767
+ value: initialDefaultValue
3768
+ },
3769
+ changeSet
3770
+ );
3771
+
3772
+ if (!onlyDefault) {
3773
+ valueStore?.writeValue(
3774
+ variableDeclaration,
3775
+ existingLiteralValue as LiteralValueState
3776
+ );
3777
+ }
3778
+
3779
+ if (
3780
+ (newValue === null || newValue === undefined) &&
3781
+ entity.type === EntityType.OutputMap
3782
+ ) {
3783
+ // Find the corresponding input map and delete its value too
3784
+ const counterpartInput = variableDeclaration.inputs.find(
3785
+ (input) =>
3786
+ input.declaration?.id === entity.declaration?.id ||
3787
+ safeResolveEntityName(input, project) === resolvedEntityName
3788
+ );
3789
+
3790
+ if (counterpartInput) {
3791
+ let existingInputLiteralValue = onlyDefault
3792
+ ? counterpartInput.defaultValue
3793
+ : valueStore?.readValue(counterpartInput.id);
3794
+
3795
+ if (existingInputLiteralValue) {
3796
+ if (Array.isArray(newValue)) {
3797
+ existingInputLiteralValue?.setValueAsTypeList(
3798
+ newValue,
3799
+ changeSet
3800
+ );
3801
+ } else {
3802
+ existingInputLiteralValue?.setValueAsTypeSingle(
3803
+ newValue,
3804
+ changeSet
3805
+ );
3806
+ }
3807
+ }
3808
+
3809
+ if (!onlyDefault) {
3810
+ valueStore?.removeValue(counterpartInput.id);
3811
+ }
3812
+ }
3813
+ }
3814
+
3815
+ return changeSet;
3816
+ }
3817
+
3818
+ export function afterLiteralValueAsTypeDeleteSideEffects(
3819
+ entity: EntityWithValueState,
3820
+ project: ProjectState,
3821
+ storage: ChangeSet | IValueStoreClient
3822
+ ): ChangeSet | null {
3823
+ if (entity.type === EntityType.InputMap) {
3824
+ if (
3825
+ entity.declaration?.type === EntityType.Property &&
3826
+ entity.declaration.static
3827
+ ) {
3828
+ propagateNewStaticPropertyValueAsTypeToVariables(
3829
+ entity.declaration,
3830
+ project,
3831
+ null,
3832
+ storage
3833
+ );
3834
+ } else if (
3835
+ VARIABLE_TYPES.includes(entity.parent.type) &&
3836
+ entity.declaration?.type === EntityType.Property
3837
+ ) {
3838
+ propagateNewInputOrOutputMapValueAsTypeToParentVariable(
3839
+ entity,
3840
+ project,
3841
+ null,
3842
+ storage
3843
+ );
3844
+ }
3845
+ } else if (entity.type === EntityType.OutputMap) {
3846
+ if (
3847
+ entity.declaration?.type === EntityType.Property &&
3848
+ entity.declaration.static
3849
+ ) {
3850
+ propagateNewStaticPropertyValueAsTypeToVariables(
3851
+ entity.declaration,
3852
+ project,
3853
+ null,
3854
+ storage
3855
+ );
3856
+ } else if (
3857
+ VARIABLE_TYPES.includes(entity.parent.type) &&
3858
+ entity.declaration?.type === EntityType.Property
3859
+ ) {
3860
+ propagateNewInputOrOutputMapValueAsTypeToParentVariable(
3861
+ entity,
3862
+ project,
3863
+ null,
3864
+ storage
3865
+ );
3866
+ }
3867
+ } else if (entity.type === EntityType.Property) {
3868
+ if (entity.static) {
3869
+ propagateNewStaticPropertyValueAsTypeToVariables(
3870
+ entity,
3871
+ project,
3872
+ null,
3873
+ storage
3874
+ );
3875
+ }
3876
+ }
3877
+
3878
+ return storage as ChangeSet;
3879
+ }
3880
+
3881
+ export function afterLiteralValueAsTypeChangeSideEffects(
3882
+ newValue: ValueAsTypeState | ValueAsTypeState[] | null,
3883
+ entity: EntityWithValueState,
3884
+ project: ProjectState,
3885
+ storage: ChangeSet | IValueStoreClient
3886
+ ): ChangeSet | null {
3887
+ if (entity.type === EntityType.InputMap) {
3888
+ if (
3889
+ entity.declaration?.type === EntityType.Property &&
3890
+ entity.declaration.static
3891
+ ) {
3892
+ propagateNewStaticPropertyValueAsTypeToVariables(
3893
+ entity.declaration,
3894
+ project,
3895
+ newValue,
3896
+ storage
3897
+ );
3898
+ } else if (
3899
+ VARIABLE_TYPES.includes(entity.parent.type) &&
3900
+ entity.declaration?.type === EntityType.Property
3901
+ ) {
3902
+ propagateNewInputOrOutputMapValueAsTypeToParentVariable(
3903
+ entity,
3904
+ project,
3905
+ newValue,
3906
+ storage
3907
+ );
3908
+ }
3909
+ } else if (entity.type === EntityType.OutputMap) {
3910
+ if (
3911
+ entity.declaration?.type === EntityType.Property &&
3912
+ entity.declaration.static
3913
+ ) {
3914
+ propagateNewStaticPropertyValueAsTypeToVariables(
3915
+ entity.declaration,
3916
+ project,
3917
+ null,
3918
+ storage
3919
+ );
3920
+ } else if (
3921
+ VARIABLE_TYPES.includes(entity.parent.type) &&
3922
+ entity.declaration?.type === EntityType.Property
3923
+ ) {
3924
+ propagateNewInputOrOutputMapValueAsTypeToParentVariable(
3925
+ entity,
3926
+ project,
3927
+ null,
3928
+ storage
3929
+ );
3930
+ }
3931
+ } else if (entity.type === EntityType.Property) {
3932
+ if (entity.static) {
3933
+ propagateNewStaticPropertyValueAsTypeToVariables(
3934
+ entity,
3935
+ project,
3936
+ newValue,
3937
+ storage
3938
+ );
3939
+ }
3940
+ }
3941
+
3942
+ return storage as ChangeSet;
3943
+ }
3944
+
3945
+ export function handleValueAsTypeDelete(
3946
+ entity: EntityWithValueState,
3947
+ project: ProjectState,
3948
+ storage: ChangeSet | IValueStoreClient
3949
+ ): ChangeSet | null {
3950
+ // Propagate values
3951
+ const propagatedValueOwners = getEntitiesToPropagateValuesTo(
3952
+ entity,
3953
+ project
3954
+ );
3955
+
3956
+ let onlyDefault = false;
3957
+ let changeSet: ChangeSet | null = null;
3958
+ let valueStore: IValueStoreClient | null = null;
3959
+
3960
+ if (storage instanceof ChangeSet) {
3961
+ onlyDefault = true;
3962
+ changeSet = storage as ChangeSet;
3963
+ valueStore = null;
3964
+ } else {
3965
+ changeSet = null;
3966
+ valueStore = storage as IValueStoreClient;
3967
+ }
3968
+
3969
+ propagatedValueOwners.forEach((propagatedValueOwner) => {
3970
+ let valueInstance = onlyDefault
3971
+ ? (
3972
+ propagatedValueOwner as EntityWithDefaultValueState
3973
+ ).getDefaultValue?.()
3974
+ : valueStore?.readValue(propagatedValueOwner.id);
3975
+
3976
+ if (!onlyDefault) {
3977
+ valueStore?.removeValue(propagatedValueOwner.id);
3978
+ } else {
3979
+ valueInstance?.remove({ ignoreUpstream: false }, changeSet);
3980
+ }
3981
+
3982
+ afterLiteralValueAsTypeDeleteSideEffects(
3983
+ propagatedValueOwner,
3984
+ project,
3985
+ storage
3986
+ );
3987
+ });
3988
+
3989
+ return changeSet;
3990
+ }
3991
+
3992
+ export function handleValueAsTypeChange(
3993
+ newValue: ValueAsTypeState | ValueAsTypeState[] | null,
3994
+ entity: EntityWithValueState,
3995
+ project: ProjectState,
3996
+ storage: ChangeSet | IValueStoreClient
3997
+ ): ChangeSet | null {
3998
+ // Propagate values
3999
+ const propagatedValueOwners = getEntitiesToPropagateValuesTo(
4000
+ entity,
4001
+ project
4002
+ );
4003
+
4004
+ let onlyDefault = false;
4005
+ let changeSet: ChangeSet | null = null;
4006
+ let valueStore: IValueStoreClient | null = null;
4007
+
4008
+ if (storage instanceof ChangeSet) {
4009
+ onlyDefault = true;
4010
+ changeSet = storage as ChangeSet;
4011
+ valueStore = null;
4012
+ } else {
4013
+ changeSet = null;
4014
+ valueStore = storage as IValueStoreClient;
4015
+ }
4016
+
4017
+ propagatedValueOwners.forEach((propagatedValueOwner) => {
4018
+ let valueInstance = onlyDefault
4019
+ ? (
4020
+ propagatedValueOwner as EntityWithDefaultValueState
4021
+ ).getDefaultValue?.()
4022
+ : valueStore?.readValue(propagatedValueOwner.id);
4023
+
4024
+ if (!valueInstance) {
4025
+ if (onlyDefault) {
4026
+ // Create new test value
4027
+
4028
+ valueInstance = assembleAndAddLiteralValueFromDataType(
4029
+ propagatedValueOwner.getDataType(null),
4030
+ propagatedValueOwner as EntityWithDefaultValueState,
4031
+ project,
4032
+ changeSet
4033
+ );
4034
+ } else {
4035
+ valueInstance = assembleStandaloneLiteralValueFromDataType(
4036
+ propagatedValueOwner.getDataType(null),
4037
+ propagatedValueOwner,
4038
+ project
4039
+ );
4040
+ }
4041
+ } else if (
4042
+ !onlyDefault &&
4043
+ !!valueInstance &&
4044
+ valueInstance.id ===
4045
+ (
4046
+ propagatedValueOwner as EntityWithDefaultValueState
4047
+ ).getDefaultValue?.()?.id
4048
+ ) {
4049
+ // If the value instance is the default value, we should generate a standalone value
4050
+
4051
+ valueInstance = assembleStandaloneLiteralValueFromDataType(
4052
+ propagatedValueOwner.getDataType(null),
4053
+ propagatedValueOwner,
4054
+ propagatedValueOwner.project
4055
+ );
4056
+ }
4057
+
4058
+ if (Array.isArray(newValue)) {
4059
+ valueInstance?.setValueAsTypeList(newValue, changeSet);
4060
+ } else {
4061
+ valueInstance?.setValueAsTypeSingle(newValue, changeSet);
4062
+ }
4063
+
4064
+ valueInstance?.metaSync(
4065
+ {
4066
+ value: null
4067
+ },
4068
+ changeSet
4069
+ );
4070
+
4071
+ if (!onlyDefault) {
4072
+ valueStore?.writeValue(
4073
+ propagatedValueOwner,
4074
+ valueInstance as LiteralValueState
4075
+ );
4076
+ }
4077
+
4078
+ afterLiteralValueAsTypeChangeSideEffects(
4079
+ newValue,
4080
+ propagatedValueOwner,
4081
+ project,
4082
+ storage
4083
+ );
4084
+ });
4085
+
4086
+ return changeSet;
4087
+ }