windmill-components 1.35.42 → 1.36.0

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 (245) hide show
  1. package/components/AppConnect.svelte +85 -59
  2. package/components/ArgInput.svelte +50 -33
  3. package/components/ArgInput.svelte.d.ts +1 -1
  4. package/components/Button.svelte +15 -48
  5. package/components/Button.svelte.d.ts +1 -1
  6. package/components/CronInput.svelte +1 -1
  7. package/components/DisplayResult.svelte +75 -67
  8. package/components/Dropdown.svelte +9 -7
  9. package/components/Editor.svelte +187 -178
  10. package/components/Editor.svelte.d.ts +4 -2
  11. package/components/EditorBar.svelte +135 -98
  12. package/components/EditorBar.svelte.d.ts +2 -1
  13. package/components/FlowBuilder.svelte +115 -134
  14. package/components/FlowJobResult.svelte +4 -5
  15. package/components/FlowModulesViewer.svelte +89 -7
  16. package/components/FlowModulesViewer.svelte.d.ts +1 -0
  17. package/components/FlowPreviewContent.svelte +88 -27
  18. package/components/FlowPreviewContent.svelte.d.ts +1 -1
  19. package/components/FlowStatusViewer.svelte +39 -24
  20. package/components/FlowStatusViewer.svelte.d.ts +0 -1
  21. package/components/FlowViewer.svelte +17 -11
  22. package/components/GroupModal.svelte +10 -1
  23. package/components/HighlightCode.svelte +22 -0
  24. package/components/HighlightCode.svelte.d.ts +17 -0
  25. package/components/IconedPath.svelte +9 -7
  26. package/components/InputTransformForm.svelte +97 -115
  27. package/components/InputTransformForm.svelte.d.ts +0 -1
  28. package/components/InputTransformsViewer.svelte +1 -1
  29. package/components/InviteGlobalUser.svelte +8 -8
  30. package/components/InviteUser.svelte +9 -9
  31. package/components/ItemPicker.svelte +37 -30
  32. package/components/ItemPicker.svelte.d.ts +2 -1
  33. package/components/JobStatus.svelte +2 -1
  34. package/components/LogViewer.svelte +23 -0
  35. package/components/LogViewer.svelte.d.ts +19 -0
  36. package/components/ModulePreview.svelte +107 -0
  37. package/components/ModulePreview.svelte.d.ts +24 -0
  38. package/components/Path.svelte +1 -1
  39. package/components/RadioButton.svelte +3 -2
  40. package/components/ResourceEditor.svelte +22 -34
  41. package/components/ResourceTypePicker.svelte +23 -34
  42. package/components/RunForm.svelte +34 -31
  43. package/components/RunForm.svelte.d.ts +6 -2
  44. package/components/SchemaEditor.svelte +19 -11
  45. package/components/SchemaForm.svelte +3 -3
  46. package/components/SchemaForm.svelte.d.ts +1 -1
  47. package/components/SchemaModal.svelte +18 -7
  48. package/components/ScriptBuilder.svelte +99 -83
  49. package/components/ScriptBuilder.svelte.d.ts +2 -4
  50. package/components/ScriptEditor.svelte +71 -143
  51. package/components/ScriptEditor.svelte.d.ts +0 -5
  52. package/components/ScriptPicker.svelte +24 -14
  53. package/components/ScriptPicker.svelte.d.ts +2 -1
  54. package/components/ScriptSchema.svelte +8 -11
  55. package/components/ScriptSchema.svelte.d.ts +0 -1
  56. package/components/ShareModal.svelte +6 -6
  57. package/components/SharedBadge.svelte +5 -13
  58. package/components/SimpleEditor.svelte +14 -10
  59. package/components/StringTypeNarrowing.svelte +24 -30
  60. package/components/TestJobLoader.svelte +106 -0
  61. package/components/TestJobLoader.svelte.d.ts +26 -0
  62. package/components/Tooltip.svelte +3 -2
  63. package/components/VariableEditor.svelte +15 -24
  64. package/components/common/actionRow/ActionRow.svelte +31 -0
  65. package/components/common/actionRow/ActionRow.svelte.d.ts +22 -0
  66. package/components/common/alert/Alert.svelte +53 -0
  67. package/components/common/alert/Alert.svelte.d.ts +20 -0
  68. package/components/common/alert/model.d.ts +1 -0
  69. package/components/common/alert/model.js +1 -0
  70. package/components/common/badge/Badge.svelte +76 -0
  71. package/components/common/badge/Badge.svelte.d.ts +28 -0
  72. package/components/common/badge/model.d.ts +8 -0
  73. package/components/common/badge/model.js +1 -0
  74. package/components/common/button/Button.svelte +110 -0
  75. package/components/common/button/Button.svelte.d.ts +39 -0
  76. package/components/common/button/model.d.ts +6 -0
  77. package/components/common/button/model.js +1 -0
  78. package/components/common/confirmationModal/ConfirmationModal.svelte +72 -0
  79. package/components/common/confirmationModal/ConfirmationModal.svelte.d.ts +23 -0
  80. package/components/common/confirmationModal/UnsavedConfirmationModal.svelte +41 -0
  81. package/components/common/confirmationModal/UnsavedConfirmationModal.svelte.d.ts +14 -0
  82. package/components/common/confirmationModal/dirtyStore.d.ts +1 -0
  83. package/components/common/confirmationModal/dirtyStore.js +2 -0
  84. package/components/common/drawer/Drawer.svelte +3 -0
  85. package/components/common/drawer/Drawer.svelte.d.ts +2 -0
  86. package/components/common/index.d.ts +14 -0
  87. package/components/common/index.js +14 -0
  88. package/components/common/tabs/TabContent.svelte +3 -2
  89. package/components/common/tabs/TabContent.svelte.d.ts +1 -0
  90. package/components/common/tabs/Tabs.svelte +8 -1
  91. package/components/common/tabs/Tabs.svelte.d.ts +2 -0
  92. package/components/common/toggleButton/ToggleButton.svelte +20 -0
  93. package/components/common/toggleButton/ToggleButton.svelte.d.ts +19 -0
  94. package/components/common/toggleButton/ToggleButtonGroup.svelte +33 -0
  95. package/components/common/toggleButton/ToggleButtonGroup.svelte.d.ts +24 -0
  96. package/components/flows/FlowEditor.svelte +30 -0
  97. package/components/{FlowEditor.svelte.d.ts → flows/FlowEditor.svelte.d.ts} +1 -6
  98. package/components/flows/common/FlowCard.svelte +9 -0
  99. package/components/flows/common/FlowCard.svelte.d.ts +21 -0
  100. package/components/flows/common/FlowCardHeader.svelte +39 -0
  101. package/components/flows/common/FlowCardHeader.svelte.d.ts +20 -0
  102. package/components/flows/content/CopyFirstStepSchema.svelte +13 -0
  103. package/components/flows/{CopyFirstStepSchema.svelte.d.ts → content/CopyFirstStepSchema.svelte.d.ts} +0 -0
  104. package/components/flows/{DynamicInputHelpBox.svelte → content/DynamicInputHelpBox.svelte} +0 -0
  105. package/components/flows/{DynamicInputHelpBox.svelte.d.ts → content/DynamicInputHelpBox.svelte.d.ts} +0 -0
  106. package/components/flows/content/FlowEditorPanel.svelte +25 -0
  107. package/components/flows/content/FlowEditorPanel.svelte.d.ts +16 -0
  108. package/components/flows/content/FlowFailureModule.svelte +15 -0
  109. package/components/flows/content/FlowFailureModule.svelte.d.ts +14 -0
  110. package/components/flows/content/FlowInput.svelte +26 -0
  111. package/components/flows/{FlowInput.svelte.d.ts → content/FlowInput.svelte.d.ts} +0 -0
  112. package/components/flows/content/FlowInputs.svelte +91 -0
  113. package/components/flows/{FlowInputs.svelte.d.ts → content/FlowInputs.svelte.d.ts} +1 -0
  114. package/components/flows/content/FlowLoop.svelte +168 -0
  115. package/components/flows/content/FlowLoop.svelte.d.ts +18 -0
  116. package/components/flows/content/FlowLoopWrapper.svelte +9 -0
  117. package/components/flows/content/FlowLoopWrapper.svelte.d.ts +14 -0
  118. package/components/flows/content/FlowModule.svelte +211 -0
  119. package/components/flows/content/FlowModule.svelte.d.ts +29 -0
  120. package/components/flows/content/FlowModuleEarlyStop.svelte +76 -0
  121. package/components/flows/content/FlowModuleEarlyStop.svelte.d.ts +17 -0
  122. package/components/flows/content/FlowModuleHeader.svelte +157 -0
  123. package/components/flows/{FlowModuleHeader.svelte.d.ts → content/FlowModuleHeader.svelte.d.ts} +5 -3
  124. package/components/flows/content/FlowModuleScript.svelte +21 -0
  125. package/components/flows/content/FlowModuleScript.svelte.d.ts +17 -0
  126. package/components/flows/content/FlowModuleSuspend.svelte +27 -0
  127. package/components/flows/content/FlowModuleSuspend.svelte.d.ts +17 -0
  128. package/components/flows/content/FlowModuleWrapper.svelte +45 -0
  129. package/components/flows/content/FlowModuleWrapper.svelte.d.ts +14 -0
  130. package/components/flows/content/FlowRetries.svelte +80 -0
  131. package/components/flows/content/FlowRetries.svelte.d.ts +17 -0
  132. package/components/flows/content/FlowSchedules.svelte +18 -0
  133. package/components/flows/content/FlowSchedules.svelte.d.ts +14 -0
  134. package/components/flows/content/FlowSettings.svelte +78 -0
  135. package/components/flows/{FlowSettings.svelte.d.ts → content/FlowSettings.svelte.d.ts} +2 -6
  136. package/components/flows/content/RemoveStepConfirmationModal.svelte +32 -0
  137. package/components/flows/content/RemoveStepConfirmationModal.svelte.d.ts +19 -0
  138. package/components/flows/flowState.d.ts +8 -7
  139. package/components/flows/flowState.js +25 -46
  140. package/components/flows/flowStateUtils.d.ts +16 -14
  141. package/components/flows/flowStateUtils.js +81 -73
  142. package/components/flows/flowStore.js +7 -4
  143. package/components/flows/header/FlowImportExportMenu.svelte +55 -0
  144. package/components/flows/header/FlowImportExportMenu.svelte.d.ts +14 -0
  145. package/components/flows/header/FlowPreviewButtons.svelte +57 -0
  146. package/components/flows/header/FlowPreviewButtons.svelte.d.ts +14 -0
  147. package/components/flows/map/FlowErrorHandlerItem.svelte +60 -0
  148. package/components/flows/map/FlowErrorHandlerItem.svelte.d.ts +14 -0
  149. package/components/flows/map/FlowModuleSchemaItem.svelte +80 -0
  150. package/components/flows/map/FlowModuleSchemaItem.svelte.d.ts +32 -0
  151. package/components/flows/map/FlowModuleSchemaMap.svelte +241 -0
  152. package/components/flows/map/FlowModuleSchemaMap.svelte.d.ts +20 -0
  153. package/components/flows/pickers/PickHubScript.svelte +5 -3
  154. package/components/flows/pickers/PickHubScript.svelte.d.ts +2 -1
  155. package/components/flows/pickers/PickScript.svelte +4 -12
  156. package/components/flows/pickers/PickScript.svelte.d.ts +1 -1
  157. package/components/flows/propPicker/PropPickerWrapper.svelte +44 -0
  158. package/components/flows/propPicker/PropPickerWrapper.svelte.d.ts +33 -0
  159. package/components/flows/scheduleUtils.d.ts +0 -1
  160. package/components/flows/scheduleUtils.js +0 -1
  161. package/components/flows/types.d.ts +8 -0
  162. package/components/flows/types.js +1 -0
  163. package/components/flows/utils.d.ts +3 -1
  164. package/components/flows/utils.js +26 -10
  165. package/components/icons/AirtableIcon.svelte +1 -1
  166. package/components/icons/DiscordIcon.svelte +1 -1
  167. package/components/icons/GCloudIcon.svelte +1 -1
  168. package/components/icons/GItlabIcon.svelte +1 -1
  169. package/components/icons/GSheetsIcon.svelte +1 -1
  170. package/components/icons/GcalIcon.svelte +1 -1
  171. package/components/icons/GdriveIcon.svelte +1 -1
  172. package/components/icons/GithubIcon.svelte +1 -1
  173. package/components/icons/GmailIcon.svelte +1 -1
  174. package/components/icons/HatIcon.svelte +19 -0
  175. package/components/icons/HatIcon.svelte.d.ts +16 -0
  176. package/components/icons/MastodonIcon.svelte +1 -1
  177. package/components/icons/MatrixIcon.svelte +1 -1
  178. package/components/icons/PostgresIcon.svelte +1 -1
  179. package/components/icons/S3Icon.svelte +1 -1
  180. package/components/icons/Slack.svelte +1 -1
  181. package/components/icons/TogglIcon.svelte +8 -46
  182. package/components/jobs/JobDetail.svelte +1 -1
  183. package/components/landing/FlowGettingStarted.svelte +22 -68
  184. package/components/landing/FlowLandingBox.svelte +1 -1
  185. package/components/landing/RessourceGettingStarted.svelte +7 -37
  186. package/components/landing/ScriptBox.svelte +33 -60
  187. package/components/landing/ScriptGettingStarted.svelte +23 -69
  188. package/components/propertyPicker/ObjectViewer.svelte +18 -12
  189. package/components/propertyPicker/ObjectViewer.svelte.d.ts +1 -0
  190. package/components/propertyPicker/PropPicker.svelte +108 -11
  191. package/components/propertyPicker/WarningMessage.svelte +2 -15
  192. package/components/script_editor/LogPanel.svelte +108 -119
  193. package/components/script_editor/LogPanel.svelte.d.ts +2 -0
  194. package/components/sidebar/SidebarContent.svelte +2 -2
  195. package/editorUtils.d.ts +3 -0
  196. package/editorUtils.js +1 -0
  197. package/gen/core/OpenAPI.js +1 -1
  198. package/gen/index.d.ts +1 -0
  199. package/gen/models/CompletedJob.d.ts +2 -1
  200. package/gen/models/CompletedJob.js +1 -0
  201. package/gen/models/FlowModule.d.ts +3 -0
  202. package/gen/models/FlowStatus.d.ts +3 -0
  203. package/gen/models/FlowStatusModule.d.ts +1 -1
  204. package/gen/models/Preview.d.ts +2 -1
  205. package/gen/models/Preview.js +1 -0
  206. package/gen/models/QueuedJob.d.ts +2 -1
  207. package/gen/models/QueuedJob.js +1 -0
  208. package/gen/models/RawScript.d.ts +2 -1
  209. package/gen/models/RawScript.js +1 -0
  210. package/gen/models/Retry.d.ts +11 -0
  211. package/gen/models/Retry.js +4 -0
  212. package/gen/models/Script.d.ts +9 -2
  213. package/gen/models/Script.js +8 -0
  214. package/gen/services/JobService.d.ts +40 -0
  215. package/gen/services/JobService.js +70 -0
  216. package/gen/services/ScriptService.d.ts +14 -3
  217. package/gen/services/ScriptService.js +13 -0
  218. package/infer.d.ts +1 -1
  219. package/infer.js +6 -1
  220. package/package.json +71 -38
  221. package/script_helpers.d.ts +8 -2
  222. package/script_helpers.js +88 -16
  223. package/stores.d.ts +1 -1
  224. package/utils.d.ts +8 -6
  225. package/utils.js +57 -21
  226. package/components/FlowEditor.svelte +0 -55
  227. package/components/FlowPreview.svelte +0 -107
  228. package/components/FlowPreview.svelte.d.ts +0 -23
  229. package/components/ModuleStep.svelte +0 -131
  230. package/components/ModuleStep.svelte.d.ts +0 -25
  231. package/components/flows/CopyFirstStepSchema.svelte +0 -13
  232. package/components/flows/FlowBox.svelte +0 -16
  233. package/components/flows/FlowBox.svelte.d.ts +0 -23
  234. package/components/flows/FlowBoxHeader.svelte +0 -16
  235. package/components/flows/FlowBoxHeader.svelte.d.ts +0 -21
  236. package/components/flows/FlowInput.svelte +0 -22
  237. package/components/flows/FlowInputs.svelte +0 -65
  238. package/components/flows/FlowModuleHeader.svelte +0 -109
  239. package/components/flows/FlowSettings.svelte +0 -165
  240. package/components/flows/FlowTimeline.svelte +0 -169
  241. package/components/flows/FlowTimeline.svelte.d.ts +0 -21
  242. package/components/flows/stepOpenedStore.d.ts +0 -1
  243. package/components/flows/stepOpenedStore.js +0 -6
  244. package/components/propertyPicker/OverlayPropertyPicker.svelte +0 -69
  245. package/components/propertyPicker/OverlayPropertyPicker.svelte.d.ts +0 -24
package/script_helpers.js CHANGED
@@ -46,16 +46,60 @@ export async function main(
46
46
  return { foo: a };
47
47
  }
48
48
  `;
49
+ export const GO_INIT_CODE = `import (
50
+ "fmt"
51
+ "rsc.io/quote"
52
+ )
53
+
54
+ func main(x string) (interface{}, error) {
55
+ fmt.Println("Hello, World")
56
+ fmt.Println(quote.Opt())
57
+ return x, nil
58
+ }
59
+ `;
60
+ export const GO_FAILURE_MODULE_CODE = `import (
61
+ "fmt"
62
+ "os"
63
+ )
64
+
65
+ // connect the error parameter to 'previous_result.error'
66
+
67
+ func main(error string) (interface{}, error) {
68
+ fmt.Println(error)
69
+ fmt.Println("job", os.Getenv("WM_JOB_ID"))
70
+ return x, nil
71
+ }
72
+ `;
49
73
  export const DENO_INIT_CODE_CLEAR = `// import * as wmill from "https://deno.land/x/windmill@v${__pkg__.version}/mod.ts"
50
74
 
51
- export async function main() {
52
- return
75
+ export async function main(x: string) {
76
+ return x
77
+ }
78
+ `;
79
+ export const DENO_FAILURE_MODULE_CODE = `
80
+ // connect the error parameter to 'previous_result.error'
81
+
82
+ export async function main(error: string) {
83
+ const job = Deno.env.get("WM_JOB_ID")
84
+ console.log("error", error)
85
+ console.log("job", job)
86
+ return { error, job }
53
87
  }
54
88
  `;
55
89
  export const PYTHON_INIT_CODE_CLEAR = `#import wmill
56
90
 
57
- def main():
58
- return
91
+ def main(x: str):
92
+ return x
93
+ `;
94
+ export const PYTHON_FAILURE_MODULE_CODE = `import os
95
+
96
+ # connect the error parameter to 'previous_result.error'
97
+
98
+ def main(error: str):
99
+ job = os.environ.get("WM_JOB_ID")
100
+ print("error", error)
101
+ print("job", job)
102
+ return error, job
59
103
  `;
60
104
  export const POSTGRES_INIT_CODE = `import {
61
105
  pgSql,
@@ -79,41 +123,69 @@ export async function main() {
79
123
 
80
124
  // A common trigger script would follow this pattern:
81
125
  // 1. Get the last saved state
82
- // const state = wmill.getInternalState()
126
+ // const state = await wmill.getInternalState()
83
127
  // 2. Get the actual state from the external service
84
128
  // const newState = await (await fetch('https://hacker-news.firebaseio.com/v0/topstories.json')).json()
85
129
  // 3. Compare the two states and update the internal state
86
- // wmill.setInternalState(newState)
130
+ // await wmill.setInternalState(newState)
87
131
  // 4. Return the new rows
88
132
  // return range from (state to newState)
89
133
 
90
- return [1,2,3]
134
+ return [1,2,3]
91
135
 
92
136
  // In subsequent scripts, you may refer to each row/value returned by the trigger script using
93
137
  // 'flow_input._value'
94
138
  }
95
139
  `;
96
- export function initialCode(language, type) {
140
+ const ALL_INITIAL_CODE = [PYTHON_INIT_CODE, DENO_INIT_CODE, POSTGRES_INIT_CODE, DENO_INIT_CODE_TRIGGER, DENO_INIT_CODE_CLEAR, PYTHON_INIT_CODE_CLEAR];
141
+ export function isInitialCode(content) {
142
+ for (const code of ALL_INITIAL_CODE) {
143
+ if (content === code) {
144
+ return true;
145
+ }
146
+ }
147
+ return false;
148
+ }
149
+ export function initialCode(language, kind, subkind) {
97
150
  if (language === 'deno') {
98
- if (type === 'trigger') {
151
+ if (kind === 'trigger') {
99
152
  return DENO_INIT_CODE_TRIGGER;
100
153
  }
101
- else if (type === 'flow') {
102
- return DENO_INIT_CODE_CLEAR;
103
- }
104
- else if (type === 'pgsql') {
105
- return POSTGRES_INIT_CODE;
154
+ else if (kind === 'script') {
155
+ if (subkind === 'flow') {
156
+ return DENO_INIT_CODE_CLEAR;
157
+ }
158
+ else if (subkind === 'failure') {
159
+ return DENO_FAILURE_MODULE_CODE;
160
+ }
161
+ else if (subkind === 'pgsql') {
162
+ return POSTGRES_INIT_CODE;
163
+ }
164
+ else {
165
+ return DENO_INIT_CODE;
166
+ }
106
167
  }
107
168
  else {
108
169
  return DENO_INIT_CODE;
109
170
  }
110
171
  }
111
- else {
112
- if (type === 'flow') {
172
+ else if (language === 'python3') {
173
+ if (subkind === 'flow') {
113
174
  return PYTHON_INIT_CODE_CLEAR;
114
175
  }
176
+ else if (subkind === 'failure') {
177
+ return PYTHON_FAILURE_MODULE_CODE;
178
+ }
115
179
  else {
116
180
  return PYTHON_INIT_CODE;
117
181
  }
118
182
  }
183
+ else {
184
+ if (subkind === 'failure') {
185
+ return GO_FAILURE_MODULE_CODE;
186
+ }
187
+ else {
188
+ return GO_INIT_CODE;
189
+ }
190
+ }
119
191
  }
package/stores.d.ts CHANGED
@@ -17,7 +17,7 @@ export declare const hubScripts: import("svelte/store").Writable<{
17
17
  path: string;
18
18
  summary: string;
19
19
  approved: boolean;
20
- is_trigger: boolean;
20
+ kind: string;
21
21
  app: string;
22
22
  }[] | undefined>;
23
23
  export declare function clearStores(): void;
package/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type Flow, type FlowModule, type User } from './gen';
1
+ import { Script, type Flow, type FlowModule, type User } from './gen';
2
2
  import type { Schema } from './common';
3
3
  import { type UserExt } from './stores';
4
4
  export declare function validateUsername(username: string): string;
@@ -18,7 +18,7 @@ export declare type DropdownType = 'action' | 'delete';
18
18
  export interface DropdownItem {
19
19
  displayName: string;
20
20
  eventName?: string;
21
- action?: (() => Promise<void>) | (() => void);
21
+ action?: ((event?: MouseEvent) => Promise<void>) | ((event?: MouseEvent) => void);
22
22
  href?: string;
23
23
  separatorTop?: boolean;
24
24
  separatorBottom?: boolean;
@@ -73,7 +73,7 @@ export declare function setInputCat(type: string | undefined, format: string | u
73
73
  export declare function scriptPathToHref(path: string): string;
74
74
  export declare function getScriptByPath(path: string): Promise<{
75
75
  content: string;
76
- language: 'deno' | 'python3';
76
+ language: 'deno' | 'python3' | 'go';
77
77
  }>;
78
78
  export declare function loadHubScripts(): Promise<void>;
79
79
  export declare function loadHubFlows(): Promise<{
@@ -83,8 +83,10 @@ export declare function loadHubFlows(): Promise<{
83
83
  apps: string[];
84
84
  approved: boolean;
85
85
  votes: number;
86
- }[]>;
86
+ }[] | undefined>;
87
87
  export declare function formatCron(inp: string): string;
88
88
  export declare function flowToHubUrl(flow: Flow): URL;
89
- export declare function scriptToHubUrl(content: string, summary: string, description: string, trigger: boolean): URL;
90
- export declare function classNames(...classes: string[]): string;
89
+ export declare function scriptToHubUrl(content: string, summary: string, description: string, kind: Script.kind): URL;
90
+ export declare function classNames(...classes: Array<string | undefined>): string;
91
+ export declare function scriptLangToEditorLang(lang: Script.language): 'typescript' | 'python' | 'go';
92
+ export declare function copyToClipboard(value: string, sendToast?: boolean): Promise<boolean>;
package/utils.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2
2
  import { goto } from '$app/navigation';
3
- import { FlowService, ScriptService } from './gen';
3
+ import { FlowService, Script, ScriptService } from './gen';
4
4
  import { toast } from '@zerodevx/svelte-toast';
5
5
  import { get } from 'svelte/store';
6
6
  import { hubScripts, workspaceStore } from './stores';
@@ -39,8 +39,11 @@ export function displayDaysAgo(dateString) {
39
39
  if (dAgo == 0) {
40
40
  return `yday at ${date.toLocaleTimeString()}`;
41
41
  }
42
+ else if (dAgo > 7) {
43
+ return `${dAgo + 1} days ago at ${date.toLocaleTimeString()}`;
44
+ }
42
45
  else {
43
- return `${dAgo + 1} days ago`;
46
+ return displayDate(dateString);
44
47
  }
45
48
  }
46
49
  }
@@ -422,25 +425,35 @@ export async function getScriptByPath(path) {
422
425
  }
423
426
  }
424
427
  export async function loadHubScripts() {
425
- const scripts = (await ScriptService.listHubScripts()).asks ?? [];
426
- const processed = scripts
427
- .map((x) => ({
428
- path: `hub/${x.id}/${x.app}/${x.summary.toLowerCase().replaceAll(/\s+/g, '_')}`,
429
- summary: `${x.summary} (${x.app}) ${x.views} uses`,
430
- approved: x.approved,
431
- is_trigger: x.is_trigger,
432
- app: x.app,
433
- views: x.views,
434
- votes: x.votes,
435
- ask_id: x.ask_id
436
- }))
437
- .sort((a, b) => b.views - a.views);
438
- hubScripts.set(processed);
428
+ try {
429
+ const scripts = (await ScriptService.listHubScripts()).asks ?? [];
430
+ const processed = scripts
431
+ .map((x) => ({
432
+ path: `hub/${x.id}/${x.app}/${x.summary.toLowerCase().replaceAll(/\s+/g, '_')}`,
433
+ summary: `${x.summary} (${x.app}) ${x.views} uses`,
434
+ approved: x.approved,
435
+ kind: x.kind,
436
+ app: x.app,
437
+ views: x.views,
438
+ votes: x.votes,
439
+ ask_id: x.ask_id
440
+ }))
441
+ .sort((a, b) => b.views - a.views);
442
+ hubScripts.set(processed);
443
+ }
444
+ catch {
445
+ console.error('Hub is not available');
446
+ }
439
447
  }
440
448
  export async function loadHubFlows() {
441
- const flows = (await FlowService.listHubFlows()).flows ?? [];
442
- const processed = flows.sort((a, b) => b.votes - a.votes);
443
- return processed;
449
+ try {
450
+ const flows = (await FlowService.listHubFlows()).flows ?? [];
451
+ const processed = flows.sort((a, b) => b.votes - a.votes);
452
+ return processed;
453
+ }
454
+ catch {
455
+ console.error('Hub is not available');
456
+ }
444
457
  }
445
458
  export function formatCron(inp) {
446
459
  // Allow for cron expressions inputted by the user to omit month and year
@@ -464,14 +477,37 @@ export function flowToHubUrl(flow) {
464
477
  url.searchParams.append('flow', encodeState(openFlow));
465
478
  return url;
466
479
  }
467
- export function scriptToHubUrl(content, summary, description, trigger) {
480
+ export function scriptToHubUrl(content, summary, description, kind) {
468
481
  const url = new URL('https://hub.windmill.dev/scripts/add');
469
482
  url.searchParams.append('content', content);
470
483
  url.searchParams.append('summary', summary);
471
484
  url.searchParams.append('description', description);
472
- url.searchParams.append('trigger', trigger.toString());
485
+ url.searchParams.append('kind', kind);
473
486
  return url;
474
487
  }
475
488
  export function classNames(...classes) {
476
489
  return classes.filter(Boolean).join(' ');
477
490
  }
491
+ export function scriptLangToEditorLang(lang) {
492
+ if (lang == 'deno') {
493
+ return 'typescript';
494
+ }
495
+ else if (lang == 'python3') {
496
+ return 'python';
497
+ }
498
+ else {
499
+ return lang;
500
+ }
501
+ }
502
+ export async function copyToClipboard(value, sendToast = true) {
503
+ let success = false;
504
+ if (navigator?.clipboard) {
505
+ success = await navigator.clipboard
506
+ .writeText(value)
507
+ .then(() => true)
508
+ .catch(() => false);
509
+ }
510
+ sendToast &&
511
+ sendUserToast(success ? 'Copied to clipboard!' : "Couldn't copy to clipboard", !success);
512
+ return success;
513
+ }
@@ -1,55 +0,0 @@
1
- <script>import { ScheduleService } from '../gen';
2
- import { workspaceStore } from '../stores';
3
- import FlowSettings from './flows/FlowSettings.svelte';
4
- import { flowStateStore } from './flows/flowState';
5
- import { flowStore } from './flows/flowStore';
6
- import FlowTimeline from './flows/FlowTimeline.svelte';
7
- export let pathError = '';
8
- export let initialPath = '';
9
- export let scheduleArgs = {};
10
- export let scheduleEnabled = false;
11
- export let scheduleCron = '0 */5 * * *';
12
- export let previewArgs = {};
13
- let scheduleLoaded = false;
14
- async function loadSchedule() {
15
- if (!scheduleLoaded) {
16
- scheduleLoaded = true;
17
- const existsSchedule = await ScheduleService.existsSchedule({
18
- workspace: $workspaceStore ?? '',
19
- path: initialPath
20
- });
21
- if (existsSchedule) {
22
- const schedule = await ScheduleService.getSchedule({
23
- workspace: $workspaceStore ?? '',
24
- path: initialPath
25
- });
26
- scheduleEnabled = schedule.enabled;
27
- scheduleCron = schedule.schedule;
28
- scheduleArgs = schedule.args ?? {};
29
- previewArgs = JSON.parse(JSON.stringify(scheduleArgs));
30
- }
31
- }
32
- }
33
- $: if ($flowStore && $workspaceStore && initialPath != '') {
34
- loadSchedule();
35
- }
36
- </script>
37
-
38
- {#if $flowStateStore}
39
- <div class="flex space-y-8 flex-col items-center">
40
- <FlowTimeline bind:args={previewArgs} bind:flowModuleSchemas={$flowStateStore}>
41
- <div slot="settings">
42
- <FlowSettings
43
- bind:pathError
44
- bind:initialPath
45
- bind:scheduleArgs
46
- {previewArgs}
47
- bind:scheduleCron
48
- bind:scheduleEnabled
49
- />
50
- </div>
51
- </FlowTimeline>
52
- </div>
53
- {:else}
54
- <h3>Loading flow</h3>
55
- {/if}
@@ -1,107 +0,0 @@
1
- <script>import { sendUserToast, truncateRev } from '../utils';
2
- import { faChevronDown, faChevronUp } from '@fortawesome/free-solid-svg-icons';
3
- import Icon from 'svelte-awesome';
4
- import { flowStateStore, flowStateToFlow } from './flows/flowState';
5
- import { mapJobResultsToFlowState } from './flows/flowStateUtils';
6
- import { runFlowPreview } from './flows/utils';
7
- import FlowStatusViewer from './FlowStatusViewer.svelte';
8
- import RunForm from './RunForm.svelte';
9
- import Tab from './common/tabs/Tab.svelte';
10
- import TabContent from './common/tabs/TabContent.svelte';
11
- import Tabs from './common/tabs/Tabs.svelte';
12
- export let i;
13
- export let flow;
14
- export let schema;
15
- export let args = {};
16
- let stepArgs = {};
17
- let tab = 'upto';
18
- let viewPreview = false;
19
- let uptoText = i >= flow.value.modules.length - 1 ? 'Preview whole flow' : 'Preview up to this step';
20
- let jobId;
21
- export async function runPreview(args) {
22
- viewPreview = true;
23
- flow = flowStateToFlow($flowStateStore, flow);
24
- let newFlow = tab == 'upto' ? truncateFlow(flow) : setInputTransformFromArgs(extractStep(flow), args);
25
- jobId = await runFlowPreview(args, newFlow);
26
- sendUserToast(`started preview ${truncateRev(jobId, 10)}`);
27
- }
28
- function truncateFlow(flow) {
29
- const localFlow = JSON.parse(JSON.stringify(flow));
30
- localFlow.value.modules = flow.value.modules.slice(0, i + 1);
31
- return localFlow;
32
- }
33
- function extractStep(flow) {
34
- const localFlow = JSON.parse(JSON.stringify(flow));
35
- localFlow.value.modules = flow.value.modules.slice(i, i + 1);
36
- localFlow.schema = schema;
37
- return localFlow;
38
- }
39
- function setInputTransformFromArgs(flow, args) {
40
- let input_transforms = {};
41
- Object.entries(args).forEach(([key, value]) => {
42
- input_transforms[key] = {
43
- type: 'static',
44
- value: value
45
- };
46
- });
47
- flow.value.modules[0].input_transforms = input_transforms;
48
- return flow;
49
- }
50
- </script>
51
-
52
- <button
53
- class="w-full rounded border-1 border border-gray-200"
54
- on:click={() => {
55
- viewPreview = !viewPreview
56
- }}
57
- >
58
- <h2 class="flex justify-center text-gray-600">
59
- <div>
60
- Preview
61
- <Icon class="ml-1" data={viewPreview ? faChevronUp : faChevronDown} scale={1} />
62
- </div>
63
- </h2>
64
- </button>
65
-
66
- {#if viewPreview}
67
- {#if i != flow.value.modules.length}
68
- <div class="mt-2">
69
- <Tabs bind:selected={tab}>
70
- <Tab value="upto">{uptoText}</Tab>
71
- <Tab value="justthis">Preview just this step</Tab>
72
- <svelte:fragment slot="content">
73
- <TabContent value="upto">
74
- <RunForm
75
- runnable={truncateFlow(flow)}
76
- runAction={(_, args) => runPreview(args)}
77
- schedulable={false}
78
- buttonText={uptoText}
79
- detailed={false}
80
- bind:args
81
- />
82
- </TabContent>
83
- <TabContent value="justthis">
84
- <RunForm
85
- runnable={extractStep(flow)}
86
- runAction={(_, args) => runPreview(args)}
87
- schedulable={false}
88
- buttonText="Preview just this step"
89
- detailed={false}
90
- args={stepArgs}
91
- />
92
- </TabContent>
93
- </svelte:fragment>
94
- </Tabs>
95
- </div>
96
- {/if}
97
-
98
- {#if jobId}
99
- <div class="w-full flex justify-center">
100
- <FlowStatusViewer
101
- {jobId}
102
- on:jobsLoaded={(e) => mapJobResultsToFlowState(e.detail, tab, i)}
103
- root={true}
104
- />
105
- </div>
106
- {/if}
107
- {/if}
@@ -1,23 +0,0 @@
1
- import { SvelteComponentTyped } from "svelte";
2
- import type { Schema } from '../common';
3
- import type { Flow } from '../gen';
4
- declare const __propDef: {
5
- props: {
6
- i: number;
7
- flow: Flow;
8
- schema: Schema;
9
- args?: Record<string, any> | undefined;
10
- runPreview?: ((args: any) => Promise<void>) | undefined;
11
- };
12
- events: {
13
- [evt: string]: CustomEvent<any>;
14
- };
15
- slots: {};
16
- };
17
- export declare type FlowPreviewProps = typeof __propDef.props;
18
- export declare type FlowPreviewEvents = typeof __propDef.events;
19
- export declare type FlowPreviewSlots = typeof __propDef.slots;
20
- export default class FlowPreview extends SvelteComponentTyped<FlowPreviewProps, FlowPreviewEvents, FlowPreviewSlots> {
21
- get runPreview(): (args: any) => Promise<void>;
22
- }
23
- export {};
@@ -1,131 +0,0 @@
1
- <script>import { RawScript } from '../gen';
2
- import { faChevronDown, faChevronUp } from '@fortawesome/free-solid-svg-icons';
3
- import Icon from 'svelte-awesome';
4
- import Editor from './Editor.svelte';
5
- import EditorBar from './EditorBar.svelte';
6
- import FlowPreview from './FlowPreview.svelte';
7
- import FlowBox from './flows/FlowBox.svelte';
8
- import FlowInputs from './flows/FlowInputs.svelte';
9
- import FlowModuleHeader from './flows/FlowModuleHeader.svelte';
10
- import { flowStore } from './flows/flowStore';
11
- import { createInlineScriptModule, createLoop, fork, loadFlowModuleSchema, pickScript, createScriptFromInlineScript, isEmptyFlowModule, getStepPropPicker } from './flows/flowStateUtils';
12
- import SchemaForm from './SchemaForm.svelte';
13
- import { flowStateStore } from './flows/flowState';
14
- import { stepOpened } from './flows/stepOpenedStore';
15
- export let indexes;
16
- export let mod;
17
- export let args = {};
18
- export let schema;
19
- export let childFlowModules = undefined;
20
- let editor;
21
- let websocketAlive = { pyright: false, black: false, deno: false };
22
- let bigEditor = false;
23
- const i = indexes[0];
24
- $: shouldPick = isEmptyFlowModule(mod);
25
- $: stepPropPicker = getStepPropPicker(indexes, $flowStore.schema, $flowStateStore, args);
26
- async function apply(fn, arg) {
27
- const flowModuleSchema = await fn(arg);
28
- mod = flowModuleSchema.flowModule;
29
- schema = flowModuleSchema.schema;
30
- if (flowModuleSchema.childFlowModules) {
31
- childFlowModules = flowModuleSchema.childFlowModules;
32
- }
33
- }
34
- async function reload(flowModule) {
35
- apply(loadFlowModuleSchema, flowModule);
36
- }
37
- async function applyCreateLoop() {
38
- await apply(createLoop, null);
39
- stepOpened.update(() => `${indexes[0]}-0`);
40
- }
41
- $: opened = $stepOpened === String(indexes.join('-'));
42
- </script>
43
-
44
- <FlowBox
45
- headerClickable={true}
46
- on:clickheader={() => ($stepOpened = !opened ? String(indexes.join('-')) : undefined)}
47
- >
48
- <svelte:fragment slot="header">
49
- <FlowModuleHeader
50
- bind:mod
51
- bind:indexes
52
- on:delete
53
- on:fork={() => apply(fork, mod)}
54
- on:createScriptFromInlineScript={() => {
55
- apply(createScriptFromInlineScript, {
56
- flowModule: mod,
57
- suffix: indexes.join('-'),
58
- schema
59
- })
60
- }}
61
- />
62
- </svelte:fragment>
63
-
64
- <div slot="content">
65
- {#if opened}
66
- <div class="p-6 border-t border-gray-300">
67
- {#if shouldPick}
68
- <FlowInputs
69
- shouldDisableTriggerScripts={i != 0}
70
- shouldDisableLoopCreation={indexes.length > 1 || i == 0}
71
- on:pick={(e) => apply(pickScript, e.detail.path)}
72
- on:new={(e) =>
73
- apply(createInlineScriptModule, {
74
- language: e.detail.language,
75
- type: e.detail.type
76
- })}
77
- on:loop={() => applyCreateLoop()}
78
- />
79
- {/if}
80
- {#if mod.value.type === 'rawscript'}
81
- <div class="mb-2 overflow-hidden">
82
- <EditorBar {editor} {websocketAlive} lang={mod.value.language ?? 'deno'} />
83
- </div>
84
- <div on:mouseleave={() => reload(mod)}>
85
- <Editor
86
- bind:websocketAlive
87
- bind:this={editor}
88
- class="{bigEditor ? 'h-2/3' : 'h-80'} border p-2 rounded"
89
- bind:code={mod.value.content}
90
- deno={mod.value.language === RawScript.language.DENO}
91
- automaticLayout={true}
92
- formatAction={() => reload(mod)}
93
- />
94
- <button
95
- class="w-full text-center"
96
- on:click={() => {
97
- bigEditor = !bigEditor
98
- }}
99
- >
100
- <Icon data={bigEditor ? faChevronUp : faChevronDown} scale={1.0} />
101
- </button>
102
- </div>
103
- <div class="mt-2 mb-8">
104
- <p class="text-gray-500 italic">
105
- Move the focus outside of the text editor to recompute the input schema or press
106
- Ctrl/Cmd+S
107
- </p>
108
- </div>
109
- {/if}
110
- {#if !shouldPick}
111
- <p class="text-lg font-bold text-gray-900 mb-2">Step inputs</p>
112
- <SchemaForm
113
- {schema}
114
- inputTransform={true}
115
- importPath={String(indexes.join('-'))}
116
- bind:pickableProperties={stepPropPicker.pickableProperties}
117
- bind:args={mod.input_transforms}
118
- bind:extraLib={stepPropPicker.extraLib}
119
- />
120
- {/if}
121
-
122
- {#if !shouldPick}
123
- <div class="border-b border-gray-200" />
124
- <div class="pt-2">
125
- <FlowPreview bind:args flow={$flowStore} {i} {schema} />
126
- </div>
127
- {/if}
128
- </div>
129
- {/if}
130
- </div>
131
- </FlowBox>
@@ -1,25 +0,0 @@
1
- import { SvelteComponentTyped } from "svelte";
2
- import { type FlowModule } from '../gen';
3
- import type { Schema } from '../common';
4
- import { type FlowModuleSchema } from './flows/flowState';
5
- declare const __propDef: {
6
- props: {
7
- indexes: number[];
8
- mod: FlowModule;
9
- args?: Record<string, any> | undefined;
10
- schema: Schema;
11
- childFlowModules?: FlowModuleSchema[] | undefined;
12
- };
13
- events: {
14
- delete: CustomEvent<any>;
15
- } & {
16
- [evt: string]: CustomEvent<any>;
17
- };
18
- slots: {};
19
- };
20
- export declare type ModuleStepProps = typeof __propDef.props;
21
- export declare type ModuleStepEvents = typeof __propDef.events;
22
- export declare type ModuleStepSlots = typeof __propDef.slots;
23
- export default class ModuleStep extends SvelteComponentTyped<ModuleStepProps, ModuleStepEvents, ModuleStepSlots> {
24
- }
25
- export {};
@@ -1,13 +0,0 @@
1
- <script>import { Button } from 'flowbite-svelte';
2
- import { isCopyFirstStepSchemaDisabled } from './flowState';
3
- import { copyFirstStepSchema } from './flowStore';
4
- </script>
5
-
6
- <Button
7
- color="light"
8
- size="xs"
9
- disabled={$isCopyFirstStepSchemaDisabled}
10
- on:click={copyFirstStepSchema}
11
- >
12
- Copy from first step schema
13
- </Button>
@@ -1,16 +0,0 @@
1
- <script>import { createEventDispatcher } from 'svelte';
2
- import FlowBoxHeader from './FlowBoxHeader.svelte';
3
- export let title = undefined;
4
- export let headerClickable = false;
5
- const dispatch = createEventDispatcher();
6
- let slots = $$props.$$slots;
7
- </script>
8
-
9
- <div class="bg-white border border-gray-300 rounded-md shadow-md">
10
- <FlowBoxHeader clickable={headerClickable} on:click={() => dispatch('clickheader')} {title}>
11
- <slot name="header" />
12
- </FlowBoxHeader>
13
- {#if slots.content}
14
- <slot name="content" />
15
- {/if}
16
- </div>