windmill-components 1.28.7 → 1.34.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.
- package/common.d.ts +3 -0
- package/components/AppConnect.svelte +28 -12
- package/components/ArgInput.svelte +25 -14
- package/components/ArgInput.svelte.d.ts +4 -0
- package/components/CenteredPage.svelte +1 -1
- package/components/DisplayResult.svelte +3 -3
- package/components/Drawer.svelte +108 -0
- package/components/Drawer.svelte.d.ts +23 -0
- package/components/Editor.svelte +70 -78
- package/components/Editor.svelte.d.ts +3 -0
- package/components/EditorBar.svelte +23 -10
- package/components/FlowBuilder.svelte +39 -33
- package/components/FlowEditor.svelte +17 -58
- package/components/FlowJobResult.svelte +18 -17
- package/components/FlowPreview.svelte +13 -34
- package/components/FlowPreview.svelte.d.ts +2 -4
- package/components/FlowPreviewContent.svelte +56 -44
- package/components/FlowPreviewContent.svelte.d.ts +0 -1
- package/components/FlowStatusViewer.svelte +123 -205
- package/components/FlowStatusViewer.svelte.d.ts +7 -4
- package/components/FlowViewer.svelte +4 -1
- package/components/IconedPath.svelte +12 -0
- package/components/IconedPath.svelte.d.ts +16 -0
- package/components/IconedResourceType.svelte +21 -2
- package/components/IconedResourceType.svelte.d.ts +1 -0
- package/components/InputTransformForm.svelte +9 -8
- package/components/InputTransformForm.svelte.d.ts +1 -1
- package/components/InviteGlobalUser.svelte +1 -1
- package/components/ItemPicker.svelte +6 -1
- package/components/JobStatus.svelte +1 -1
- package/components/ModuleStep.svelte +73 -93
- package/components/ModuleStep.svelte.d.ts +7 -2
- package/components/Path.svelte +62 -40
- package/components/Path.svelte.d.ts +2 -0
- package/components/ProgressBar.svelte +31 -0
- package/components/ProgressBar.svelte.d.ts +17 -0
- package/components/ProgressBarPart.svelte +20 -0
- package/components/ProgressBarPart.svelte.d.ts +20 -0
- package/components/ResourceEditor.svelte +2 -1
- package/components/ResourcePicker.svelte +9 -0
- package/components/SchemaForm.svelte +9 -4
- package/components/SchemaForm.svelte.d.ts +1 -1
- package/components/SchemaModal.svelte +20 -3
- package/components/ScriptBuilder.svelte +58 -21
- package/components/ScriptBuilder.svelte.d.ts +1 -0
- package/components/ScriptEditor.svelte +4 -2
- package/components/SharedBadge.svelte +8 -3
- package/components/VariableEditor.svelte +1 -1
- package/components/flows/CopyFirstStepSchema.svelte +4 -3
- package/components/flows/DynamicInputHelpBox.svelte +6 -4
- package/components/flows/DynamicInputHelpBox.svelte.d.ts +1 -1
- package/components/flows/FlowBox.svelte +15 -2
- package/components/flows/FlowBox.svelte.d.ts +14 -14
- package/components/flows/FlowBoxHeader.svelte +10 -3
- package/components/flows/FlowBoxHeader.svelte.d.ts +3 -0
- package/components/flows/FlowInput.svelte +14 -12
- package/components/flows/FlowInputs.svelte +55 -35
- package/components/flows/FlowInputs.svelte.d.ts +3 -1
- package/components/flows/FlowModuleHeader.svelte +71 -55
- package/components/flows/FlowModuleHeader.svelte.d.ts +6 -6
- package/components/flows/FlowSettings.svelte +34 -57
- package/components/flows/FlowSettings.svelte.d.ts +0 -1
- package/components/flows/FlowTimeline.svelte +169 -0
- package/components/flows/FlowTimeline.svelte.d.ts +21 -0
- package/components/flows/flowState.d.ts +14 -0
- package/components/flows/flowState.js +52 -0
- package/components/flows/flowStateUtils.d.ts +37 -0
- package/components/flows/flowStateUtils.js +222 -0
- package/components/flows/flowStore.d.ts +1 -16
- package/components/flows/flowStore.js +7 -208
- package/components/flows/pickers/FlowScriptPicker.svelte +5 -9
- package/components/flows/pickers/FlowScriptPicker.svelte.d.ts +0 -1
- package/components/flows/pickers/PickHubScript.svelte +1 -1
- package/components/flows/pickers/PickHubScript.svelte.d.ts +1 -1
- package/components/flows/pickers/PickScript.svelte +1 -1
- package/components/flows/pickers/PickScript.svelte.d.ts +1 -1
- package/components/flows/scheduleUtils.d.ts +7 -0
- package/components/flows/scheduleUtils.js +21 -0
- package/components/flows/stepOpenedStore.d.ts +1 -0
- package/components/flows/stepOpenedStore.js +6 -0
- package/components/flows/utils.d.ts +5 -12
- package/components/flows/utils.js +40 -112
- package/components/icons/DiscordIcon.svelte +16 -0
- package/components/icons/DiscordIcon.svelte.d.ts +17 -0
- package/components/icons/HttpIcon.svelte +21 -0
- package/components/icons/HttpIcon.svelte.d.ts +17 -0
- package/components/icons/MastodonIcon.svelte +16 -0
- package/components/icons/MastodonIcon.svelte.d.ts +17 -0
- package/components/icons/MatrixIcon.svelte +16 -0
- package/components/icons/MatrixIcon.svelte.d.ts +17 -0
- package/components/icons/S3Icon.svelte +16 -0
- package/components/icons/S3Icon.svelte.d.ts +17 -0
- package/components/icons/WindmillIcon.svelte +68 -0
- package/components/icons/WindmillIcon.svelte.d.ts +17 -0
- package/components/preview/FlowPreviewStatus.svelte +28 -0
- package/components/preview/FlowPreviewStatus.svelte.d.ts +17 -0
- package/components/propertyPicker/ObjectViewer.svelte +13 -13
- package/components/propertyPicker/utils.js +3 -2
- package/components/tabs/Tab.svelte +12 -0
- package/components/tabs/Tab.svelte.d.ts +19 -0
- package/components/tabs/TabPanel.svelte +11 -0
- package/components/tabs/TabPanel.svelte.d.ts +20 -0
- package/components/tabs/Tabs.svelte +3 -0
- package/components/tabs/Tabs.svelte.d.ts +23 -0
- package/gen/core/OpenAPI.js +1 -1
- package/gen/core/request.js +1 -0
- package/gen/models/MainArgSignature.d.ts +14 -3
- package/gen/services/JobService.d.ts +10 -2
- package/gen/services/JobService.js +4 -2
- package/gen/services/ScriptService.d.ts +18 -0
- package/gen/services/ScriptService.js +30 -0
- package/infer.js +47 -24
- package/package.json +39 -20
- package/script_helpers.d.ts +4 -1
- package/script_helpers.js +68 -17
- package/stores.d.ts +1 -2
- package/stores.js +1 -4
- package/utils.d.ts +4 -2
- package/utils.js +33 -5
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { CompletedJob, Job, ScriptService } from '../../gen';
|
|
2
|
+
import { initialCode } from '../../script_helpers';
|
|
3
|
+
import { userStore, workspaceStore } from '../../stores';
|
|
4
|
+
import { buildExtraLib, emptyModule, emptySchema, getScriptByPath, objectToTsType, schemaToObject, schemaToTsType } from '../../utils';
|
|
5
|
+
import { get } from 'svelte/store';
|
|
6
|
+
import { flowStateStore } from './flowState';
|
|
7
|
+
import { flowStore } from './flowStore';
|
|
8
|
+
import { jobsToResults, loadSchemaFromModule } from './utils';
|
|
9
|
+
export function emptyFlowModuleSchema() {
|
|
10
|
+
return {
|
|
11
|
+
flowModule: emptyModule(),
|
|
12
|
+
schema: emptySchema()
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export async function loadFlowModuleSchema(flowModule) {
|
|
16
|
+
try {
|
|
17
|
+
const { input_transform, schema } = await loadSchemaFromModule(flowModule);
|
|
18
|
+
flowModule.input_transform = input_transform;
|
|
19
|
+
return { flowModule, schema };
|
|
20
|
+
}
|
|
21
|
+
catch (e) {
|
|
22
|
+
return { flowModule, schema: emptySchema() };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export async function pickScript(path) {
|
|
26
|
+
const flowModule = {
|
|
27
|
+
value: { type: 'script', path },
|
|
28
|
+
input_transform: {}
|
|
29
|
+
};
|
|
30
|
+
return await loadFlowModuleSchema(flowModule);
|
|
31
|
+
}
|
|
32
|
+
export async function createInlineScriptModule({ language, type }) {
|
|
33
|
+
const code = initialCode(language, type);
|
|
34
|
+
const flowModule = {
|
|
35
|
+
value: { type: 'rawscript', content: code, language },
|
|
36
|
+
input_transform: {}
|
|
37
|
+
};
|
|
38
|
+
return await loadFlowModuleSchema(flowModule);
|
|
39
|
+
}
|
|
40
|
+
export async function createLoop() {
|
|
41
|
+
const loopFlowModule = {
|
|
42
|
+
value: {
|
|
43
|
+
type: 'forloopflow',
|
|
44
|
+
value: {
|
|
45
|
+
modules: []
|
|
46
|
+
},
|
|
47
|
+
iterator: { type: 'javascript', expr: 'result' },
|
|
48
|
+
skip_failures: true
|
|
49
|
+
},
|
|
50
|
+
input_transform: {}
|
|
51
|
+
};
|
|
52
|
+
const { flowModule, schema } = await loadFlowModuleSchema(loopFlowModule);
|
|
53
|
+
return {
|
|
54
|
+
flowModule,
|
|
55
|
+
schema,
|
|
56
|
+
childFlowModules: [emptyFlowModuleSchema()],
|
|
57
|
+
previewResult: undefined
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export async function fork(flowModule) {
|
|
61
|
+
if (flowModule.value.type !== 'script') {
|
|
62
|
+
throw new Error('Can only fork a script module');
|
|
63
|
+
}
|
|
64
|
+
const fm = await createInlineScriptModuleFromPath(flowModule.value.path ?? '');
|
|
65
|
+
return await loadFlowModuleSchema(fm);
|
|
66
|
+
}
|
|
67
|
+
export async function createInlineScriptModuleFromPath(path) {
|
|
68
|
+
const { content, language } = await getScriptByPath(path);
|
|
69
|
+
return {
|
|
70
|
+
value: {
|
|
71
|
+
type: 'rawscript',
|
|
72
|
+
language: language,
|
|
73
|
+
content: content,
|
|
74
|
+
path
|
|
75
|
+
},
|
|
76
|
+
input_transform: {}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
export async function createScriptFromInlineScript({ flowModule, suffix, schema }) {
|
|
80
|
+
const flow = get(flowStore);
|
|
81
|
+
const user = get(userStore);
|
|
82
|
+
if (flowModule.value.type != 'rawscript') {
|
|
83
|
+
throw new Error("Can't create script from non-inline script");
|
|
84
|
+
}
|
|
85
|
+
const originalScriptPath = flowModule.value.path;
|
|
86
|
+
const wasForked = Boolean(originalScriptPath);
|
|
87
|
+
if (wasForked && originalScriptPath) {
|
|
88
|
+
const [first, second, ...others] = originalScriptPath.split('/');
|
|
89
|
+
suffix = others.join('/');
|
|
90
|
+
}
|
|
91
|
+
const path = `${flow.path}/${suffix}`;
|
|
92
|
+
const forkedDescription = wasForked ? `as a fork of ${originalScriptPath}` : '';
|
|
93
|
+
const description = `This script was edited in place of flow ${flow.path} ${forkedDescription} by ${user?.username}}.`;
|
|
94
|
+
const availablePath = await findNextAvailablePath(path);
|
|
95
|
+
await ScriptService.createScript({
|
|
96
|
+
workspace: get(workspaceStore),
|
|
97
|
+
requestBody: {
|
|
98
|
+
path: availablePath,
|
|
99
|
+
summary: '',
|
|
100
|
+
description,
|
|
101
|
+
content: flowModule.value.content,
|
|
102
|
+
parent_hash: undefined,
|
|
103
|
+
schema,
|
|
104
|
+
is_template: false,
|
|
105
|
+
language: flowModule.value.language
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
return pickScript(availablePath);
|
|
109
|
+
}
|
|
110
|
+
async function findNextAvailablePath(path) {
|
|
111
|
+
try {
|
|
112
|
+
await ScriptService.getScriptByPath({
|
|
113
|
+
workspace: get(workspaceStore),
|
|
114
|
+
path
|
|
115
|
+
});
|
|
116
|
+
const [_, version] = path.split(/.*_([0-9]*)/);
|
|
117
|
+
if (version.length > 0) {
|
|
118
|
+
path = path.slice(0, -(version.length + 1));
|
|
119
|
+
}
|
|
120
|
+
path = `${path}_${Number(version) + 1}`;
|
|
121
|
+
return findNextAvailablePath(path);
|
|
122
|
+
}
|
|
123
|
+
catch (e) {
|
|
124
|
+
// Catching an error means the path is available
|
|
125
|
+
return path;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
export function isEmptyFlowModule(flowModule) {
|
|
129
|
+
return flowModule.value.type === 'script' && flowModule.value.path === '';
|
|
130
|
+
}
|
|
131
|
+
export function getStepPropPicker(indexes, flowInputSchema, flowState, args) {
|
|
132
|
+
const isInsideLoop = indexes.length > 1;
|
|
133
|
+
const [parentIndex] = indexes;
|
|
134
|
+
const flowInput = schemaToObject(flowInputSchema, args);
|
|
135
|
+
const results = getPreviousResults(flowState, parentIndex);
|
|
136
|
+
const lastResult = results.length > 0 ? results[results.length - 1] : undefined;
|
|
137
|
+
if (isInsideLoop) {
|
|
138
|
+
const forLoopFlowInput = {
|
|
139
|
+
...flowInput,
|
|
140
|
+
iter: {
|
|
141
|
+
value: "Iteration's value",
|
|
142
|
+
index: "Iteration's index"
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
if (Array.isArray(lastResult) && lastResult.length > 0) {
|
|
146
|
+
const last = lastResult[lastResult.length - 1];
|
|
147
|
+
forLoopFlowInput.iter = {
|
|
148
|
+
value: last,
|
|
149
|
+
index: `Iteration's index (0 to ${lastResult.length - 1})`
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
const extraLib = buildExtraLib(objectToTsType(forLoopFlowInput), undefined);
|
|
153
|
+
return {
|
|
154
|
+
extraLib,
|
|
155
|
+
pickableProperties: {
|
|
156
|
+
flow_input: forLoopFlowInput,
|
|
157
|
+
step: [],
|
|
158
|
+
previous_result: {}
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
const extraLib = buildExtraLib(schemaToTsType(flowInputSchema), objectToTsType(lastResult));
|
|
164
|
+
return {
|
|
165
|
+
extraLib,
|
|
166
|
+
pickableProperties: {
|
|
167
|
+
flow_input: flowInput,
|
|
168
|
+
step: results,
|
|
169
|
+
previous_result: lastResult
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function getPreviousResults(flowModuleSchemas, target) {
|
|
175
|
+
if (!Array.isArray(flowModuleSchemas) || target < 1) {
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
const results = extractPreviewResults(flowModuleSchemas);
|
|
179
|
+
return results.splice(0, target);
|
|
180
|
+
}
|
|
181
|
+
function extractPreviewResults(flowModuleSchemas) {
|
|
182
|
+
return flowModuleSchemas.map((fms) => fms.previewResult);
|
|
183
|
+
}
|
|
184
|
+
export function mapJobResultsToFlowState(jobs, config, configIndex) {
|
|
185
|
+
if (!Array.isArray(jobs.innerJobs) || jobs.innerJobs.length === 0) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (config === 'justthis') {
|
|
189
|
+
const job = jobs.job;
|
|
190
|
+
flowStateStore.update((flowState) => {
|
|
191
|
+
flowState[configIndex] = job.result;
|
|
192
|
+
return flowState;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
const results = jobs.innerJobs.map(({ job, loopJobs }) => {
|
|
197
|
+
if (Array.isArray(loopJobs) && loopJobs.length > 0) {
|
|
198
|
+
return loopJobs.map(({ job }) => {
|
|
199
|
+
if (job && 'result' in job) {
|
|
200
|
+
return job.result;
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
if (job && 'result' in job) {
|
|
206
|
+
return job.result;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
flowStateStore.update((flowState) => {
|
|
211
|
+
if (!Array.isArray(flowState)) {
|
|
212
|
+
return flowState;
|
|
213
|
+
}
|
|
214
|
+
return flowState.map((flowModuleSchema, index) => {
|
|
215
|
+
if (index <= configIndex) {
|
|
216
|
+
flowModuleSchema.previewResult = results[index];
|
|
217
|
+
}
|
|
218
|
+
return flowModuleSchema;
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
}
|
|
@@ -1,20 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import { RawScript, type Flow } from '../../gen';
|
|
1
|
+
import type { Flow } from '../../gen';
|
|
3
2
|
export declare type FlowMode = 'push' | 'pull';
|
|
4
|
-
export declare const mode: import("svelte/store").Writable<FlowMode>;
|
|
5
3
|
export declare const flowStore: import("svelte/store").Writable<Flow>;
|
|
6
|
-
export declare const schemasStore: import("svelte/store").Writable<Schema[]>;
|
|
7
4
|
export declare function initFlow(flow: Flow): void;
|
|
8
|
-
export declare function codeToStaticTemplate(code?: string): string | undefined;
|
|
9
|
-
export declare function flattenForloopFlows(flow: Flow): Flow;
|
|
10
|
-
export declare const isCopyFirstStepSchemaDisabled: import("svelte/store").Readable<boolean>;
|
|
11
|
-
export declare function addModule(i?: number): void;
|
|
12
|
-
export declare function pickScript(path: string, step: number): Promise<void>;
|
|
13
|
-
export declare function createInlineScriptModule(language: RawScript.language, step: number, mode: FlowMode): Promise<void>;
|
|
14
|
-
export declare function loadSchema(step: number): Promise<void>;
|
|
15
|
-
export declare function fork(step: number): Promise<void>;
|
|
16
|
-
export declare function createScriptFromInlineScript(step: number): Promise<void>;
|
|
17
|
-
export declare function removeModule(step: number): void;
|
|
18
5
|
export declare function copyFirstStepSchema(): Promise<void>;
|
|
19
|
-
export declare function findNextAvailablePath(path: string): Promise<string>;
|
|
20
|
-
export declare function shouldPickOrCreateScript(flow: Flow, step: number): boolean;
|
|
@@ -1,217 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { userStore, workspaceStore } from '../../stores';
|
|
4
|
-
import { emptySchema } from '../../utils';
|
|
5
|
-
import { derived, get, writable } from 'svelte/store';
|
|
6
|
-
import { createInlineScriptModuleFromPath, getFirstStepSchema, loadSchemaFromModule, scrollIntoView } from './utils';
|
|
7
|
-
export const mode = writable('push');
|
|
1
|
+
import { get, writable } from 'svelte/store';
|
|
2
|
+
import { flowStateStore, initFlowState } from './flowState';
|
|
8
3
|
export const flowStore = writable(undefined);
|
|
9
|
-
export const schemasStore = writable([]);
|
|
10
4
|
export function initFlow(flow) {
|
|
11
|
-
const newMode = flow.value.modules[1]?.value.type === 'forloopflow' ? 'pull' : 'push';
|
|
12
|
-
mode.set(newMode);
|
|
13
|
-
flow = flattenForloopFlows(flow);
|
|
14
|
-
flow.value.modules.forEach((mod) => {
|
|
15
|
-
Object.values(mod.input_transform).forEach((inp) => {
|
|
16
|
-
if (inp.type == 'javascript') {
|
|
17
|
-
// for now we use the value for dynamic expression when done in the static editor so we have to resort to this
|
|
18
|
-
//@ts-ignore
|
|
19
|
-
inp.value = codeToStaticTemplate(inp.expr);
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
schemasStore.set([]);
|
|
24
5
|
flowStore.set(flow);
|
|
25
|
-
|
|
26
|
-
flow.value.modules.forEach((_, index) => {
|
|
27
|
-
loadSchema(index);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
export function codeToStaticTemplate(code) {
|
|
31
|
-
if (!code)
|
|
32
|
-
return undefined;
|
|
33
|
-
const lines = code
|
|
34
|
-
.split('\n')
|
|
35
|
-
.slice(1)
|
|
36
|
-
.filter((x) => x != '');
|
|
37
|
-
if (lines.length == 1) {
|
|
38
|
-
const line = lines[0].trim();
|
|
39
|
-
if (line[0] == '`' && line.charAt(line.length - 1) == '`') {
|
|
40
|
-
return line.slice(1, line.length - 1);
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
export function flattenForloopFlows(flow) {
|
|
46
|
-
let newFlow = JSON.parse(JSON.stringify(flow));
|
|
47
|
-
const mod = newFlow.value.modules[1]?.value;
|
|
48
|
-
if (mod?.type === 'forloopflow') {
|
|
49
|
-
const oldModules = mod.value?.modules ?? [];
|
|
50
|
-
newFlow.value.modules = newFlow.value.modules.slice(0, 1);
|
|
51
|
-
newFlow.value.modules.push(...oldModules);
|
|
52
|
-
}
|
|
53
|
-
return newFlow;
|
|
54
|
-
}
|
|
55
|
-
export const isCopyFirstStepSchemaDisabled = derived(flowStore, (flow) => {
|
|
56
|
-
if (flow) {
|
|
57
|
-
const modules = flow.value.modules;
|
|
58
|
-
const [firstModule] = modules;
|
|
59
|
-
return (modules.length === 0 || (firstModule.value.type === 'script' && firstModule.value.path === ''));
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
export function addModule(i) {
|
|
66
|
-
const newModule = {
|
|
67
|
-
value: { type: 'script', path: '' },
|
|
68
|
-
input_transform: {}
|
|
69
|
-
};
|
|
70
|
-
flowStore.update((flow) => {
|
|
71
|
-
const insertAt = i ?? flow.value.modules.length;
|
|
72
|
-
flow.value.modules.splice(insertAt, 0, newModule);
|
|
73
|
-
flow.value.modules = flow.value.modules;
|
|
74
|
-
setTimeout(() => scrollIntoView(document.querySelector(`#module-${insertAt}`)), 100);
|
|
75
|
-
return flow;
|
|
76
|
-
});
|
|
77
|
-
schemasStore.update((schemas) => {
|
|
78
|
-
if (typeof i !== 'undefined') {
|
|
79
|
-
const previousSchema = schemas[i];
|
|
80
|
-
const hadSchema = Boolean(previousSchema);
|
|
81
|
-
if (hadSchema) {
|
|
82
|
-
schemas[i] = emptySchema();
|
|
83
|
-
schemas[i + 1] = previousSchema;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return schemas;
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
export async function pickScript(path, step) {
|
|
90
|
-
flowStore.update((flow) => {
|
|
91
|
-
if (flow.value.modules[step]) {
|
|
92
|
-
flow.value.modules[step].value = { type: 'script', path };
|
|
93
|
-
}
|
|
94
|
-
return flow;
|
|
95
|
-
});
|
|
96
|
-
await loadSchema(step);
|
|
97
|
-
}
|
|
98
|
-
export async function createInlineScriptModule(language, step, mode) {
|
|
99
|
-
const code = initialCode(language, mode === 'pull' && step == 0);
|
|
100
|
-
flowStore.update((flow) => {
|
|
101
|
-
flow.value.modules[step].value = {
|
|
102
|
-
type: 'rawscript',
|
|
103
|
-
content: code,
|
|
104
|
-
language
|
|
105
|
-
};
|
|
106
|
-
return flow;
|
|
107
|
-
});
|
|
108
|
-
await loadSchema(step);
|
|
109
|
-
}
|
|
110
|
-
export async function loadSchema(step) {
|
|
111
|
-
const flow = get(flowStore);
|
|
112
|
-
const module = flow.value.modules[step];
|
|
113
|
-
const { input_transform, schema } = await loadSchemaFromModule(module);
|
|
114
|
-
flowStore.update((flow) => {
|
|
115
|
-
flow.value.modules[step].input_transform = input_transform;
|
|
116
|
-
return flow;
|
|
117
|
-
});
|
|
118
|
-
schemasStore.update((schemas) => {
|
|
119
|
-
schemas[step] = schema;
|
|
120
|
-
return schemas;
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
export async function fork(step) {
|
|
124
|
-
const flow = get(flowStore);
|
|
125
|
-
const flowModuleValue = flow.value.modules[step].value;
|
|
126
|
-
if (flowModuleValue.type !== 'script') {
|
|
127
|
-
throw new Error('Can only fork a script module');
|
|
128
|
-
}
|
|
129
|
-
if (flowModuleValue.path) {
|
|
130
|
-
const moduleValue = await createInlineScriptModuleFromPath(flowModuleValue.path);
|
|
131
|
-
flowStore.update((flow) => {
|
|
132
|
-
flow.value.modules[step].value = moduleValue;
|
|
133
|
-
return flow;
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
export async function createScriptFromInlineScript(step) {
|
|
138
|
-
const flow = get(flowStore);
|
|
139
|
-
const schemas = get(schemasStore);
|
|
140
|
-
const user = get(userStore);
|
|
141
|
-
const flowModuleValue = flow.value.modules[step].value;
|
|
142
|
-
if (flowModuleValue.type != 'rawscript') {
|
|
143
|
-
throw new Error("Can't create script from non-inline script");
|
|
144
|
-
}
|
|
145
|
-
const originalScriptPath = flowModuleValue.path;
|
|
146
|
-
const wasForked = Boolean(originalScriptPath);
|
|
147
|
-
let suffix = `step-${step}`;
|
|
148
|
-
if (wasForked && originalScriptPath) {
|
|
149
|
-
const [first, second, ...others] = originalScriptPath.split('/');
|
|
150
|
-
suffix = others.join('/');
|
|
151
|
-
}
|
|
152
|
-
const path = `${flow.path}/${suffix}`;
|
|
153
|
-
const forkedDescription = wasForked ? `as a fork of ${originalScriptPath}` : '';
|
|
154
|
-
const description = `This script was edited in place of flow ${flow.path} ${forkedDescription} by ${user?.username} at step ${step}.`;
|
|
155
|
-
const availablePath = await findNextAvailablePath(path);
|
|
156
|
-
await ScriptService.createScript({
|
|
157
|
-
workspace: get(workspaceStore),
|
|
158
|
-
requestBody: {
|
|
159
|
-
path: availablePath,
|
|
160
|
-
summary: '',
|
|
161
|
-
description,
|
|
162
|
-
content: flowModuleValue.content,
|
|
163
|
-
parent_hash: undefined,
|
|
164
|
-
schema: schemas[step],
|
|
165
|
-
is_template: false,
|
|
166
|
-
language: flowModuleValue.language
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
flowStore.update((flow) => {
|
|
170
|
-
flow.value.modules[step].value = {
|
|
171
|
-
type: 'script',
|
|
172
|
-
path: availablePath
|
|
173
|
-
};
|
|
174
|
-
return flow;
|
|
175
|
-
});
|
|
176
|
-
await loadSchema(step);
|
|
177
|
-
}
|
|
178
|
-
export function removeModule(step) {
|
|
179
|
-
flowStore.update((flow) => {
|
|
180
|
-
flow.value.modules.splice(step, 1);
|
|
181
|
-
return flow;
|
|
182
|
-
});
|
|
183
|
-
schemasStore.update((schemas) => {
|
|
184
|
-
schemas.splice(step, 1);
|
|
185
|
-
return schemas;
|
|
186
|
-
});
|
|
6
|
+
initFlowState(flow);
|
|
187
7
|
}
|
|
188
8
|
export async function copyFirstStepSchema() {
|
|
189
|
-
const
|
|
190
|
-
const flowSchema = await getFirstStepSchema(flow);
|
|
9
|
+
const flowState = get(flowStateStore);
|
|
191
10
|
flowStore.update((flow) => {
|
|
192
|
-
|
|
11
|
+
if (flowState[0].schema) {
|
|
12
|
+
flow.schema = flowState[0].schema;
|
|
13
|
+
}
|
|
193
14
|
return flow;
|
|
194
15
|
});
|
|
195
16
|
}
|
|
196
|
-
export async function findNextAvailablePath(path) {
|
|
197
|
-
try {
|
|
198
|
-
await ScriptService.getScriptByPath({
|
|
199
|
-
workspace: get(workspaceStore),
|
|
200
|
-
path
|
|
201
|
-
});
|
|
202
|
-
const [_, version] = path.split(/.*_([0-9]*)/);
|
|
203
|
-
if (version.length > 0) {
|
|
204
|
-
path = path.slice(0, -(version.length + 1));
|
|
205
|
-
}
|
|
206
|
-
path = `${path}_${Number(version) + 1}`;
|
|
207
|
-
return findNextAvailablePath(path);
|
|
208
|
-
}
|
|
209
|
-
catch (e) {
|
|
210
|
-
// Catching an error means the path is available
|
|
211
|
-
return path;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
export function shouldPickOrCreateScript(flow, step) {
|
|
215
|
-
const module = flow.value.modules[step];
|
|
216
|
-
return module.value.type === 'script' && module.value.path === '';
|
|
217
|
-
}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
<script>import {
|
|
1
|
+
<script>import { Button } from 'flowbite-svelte';
|
|
2
2
|
import Icon from 'svelte-awesome';
|
|
3
3
|
export let disabled = false;
|
|
4
4
|
export let icon;
|
|
5
5
|
export let label;
|
|
6
6
|
export let iconColor;
|
|
7
|
-
export let tooltip = undefined;
|
|
8
7
|
</script>
|
|
9
8
|
|
|
10
|
-
<
|
|
11
|
-
<Icon data={icon} class={`
|
|
12
|
-
{label}
|
|
13
|
-
|
|
14
|
-
<Tooltip placement="bottom" content={tooltip}>(?)</Tooltip>
|
|
15
|
-
{/if}
|
|
16
|
-
</button>
|
|
9
|
+
<Button {disabled} on:click size="md" class="text-left" color="alternative">
|
|
10
|
+
<Icon data={icon} class={`mr-2 ${iconColor} w-4`} scale={1.5} />
|
|
11
|
+
<span class="text-sm text-left"> {label} </span>
|
|
12
|
+
</Button>
|
|
@@ -3,7 +3,7 @@ import FlowScriptPicker from './FlowScriptPicker.svelte';
|
|
|
3
3
|
import ItemPicker from '../../ItemPicker.svelte';
|
|
4
4
|
import { hubScripts } from '../../../stores';
|
|
5
5
|
import { createEventDispatcher } from 'svelte';
|
|
6
|
-
export let isTrigger;
|
|
6
|
+
export let isTrigger = false;
|
|
7
7
|
let items;
|
|
8
8
|
$: items = $hubScripts?.filter((x) => x.is_trigger == isTrigger) ?? [];
|
|
9
9
|
let itemPicker;
|
|
@@ -4,7 +4,7 @@ import { ScriptService } from '../../../gen';
|
|
|
4
4
|
import { workspaceStore } from '../../../stores';
|
|
5
5
|
import { createEventDispatcher } from 'svelte';
|
|
6
6
|
import FlowScriptPicker from './FlowScriptPicker.svelte';
|
|
7
|
-
export let isTrigger;
|
|
7
|
+
export let isTrigger = false;
|
|
8
8
|
let items = [];
|
|
9
9
|
let itemPicker;
|
|
10
10
|
const dispatch = createEventDispatcher();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ScheduleService } from '../../gen';
|
|
2
|
+
// Load the schedule of a flow given its path and the workspace
|
|
3
|
+
export async function loadFlowSchedule(path, workspace = '') {
|
|
4
|
+
const existsSchedule = await ScheduleService.existsSchedule({
|
|
5
|
+
workspace,
|
|
6
|
+
path
|
|
7
|
+
});
|
|
8
|
+
if (!existsSchedule) {
|
|
9
|
+
throw new Error(`Flow at path: ${path} doesn't exit`);
|
|
10
|
+
}
|
|
11
|
+
const schedule = await ScheduleService.getSchedule({
|
|
12
|
+
workspace,
|
|
13
|
+
path
|
|
14
|
+
});
|
|
15
|
+
return {
|
|
16
|
+
enabled: schedule.enabled,
|
|
17
|
+
cron: schedule.schedule,
|
|
18
|
+
args: schedule.args ?? {},
|
|
19
|
+
previewArgs: JSON.parse(JSON.stringify(schedule.args))
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const stepOpened: import("svelte/store").Writable<string | undefined>;
|
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
import type { Schema } from '../../common';
|
|
2
|
-
import { type Flow, type FlowModule, type
|
|
3
|
-
|
|
4
|
-
export declare function flowToMode(flow: Flow | any, mode: FlowMode): Flow;
|
|
2
|
+
import { type Flow, type FlowModule, type InputTransform, type Job } from '../../gen';
|
|
3
|
+
export declare function cleanInputs(flow: Flow | any): Flow;
|
|
5
4
|
export declare function getTypeAsString(arg: any): string;
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function createInlineScriptModuleFromPath(path: string): Promise<FlowModuleValue>;
|
|
8
|
-
export declare function scrollIntoView(el: any): void;
|
|
5
|
+
export declare function scrollIntoView(element: any): void;
|
|
9
6
|
export declare function loadSchemaFromModule(module: FlowModule): Promise<{
|
|
10
7
|
input_transform: Record<string, InputTransform>;
|
|
11
8
|
schema: Schema;
|
|
12
9
|
}>;
|
|
13
10
|
export declare function isCodeInjection(expr: string | undefined): boolean;
|
|
14
|
-
export declare function getDefaultExpr(
|
|
15
|
-
export declare function getPickableProperties(schema: Schema, args: Record<string, any>, previewResults: Record<number, Object>, mode: FlowMode, i: number): {
|
|
16
|
-
flow_input: any;
|
|
17
|
-
previous_result: any;
|
|
18
|
-
step: any[];
|
|
19
|
-
};
|
|
11
|
+
export declare function getDefaultExpr(importPath?: string | undefined, key?: string, previousExpr?: string): string;
|
|
20
12
|
export declare function jobsToResults(jobs: Job[]): any;
|
|
21
13
|
export declare function runFlowPreview(args: Record<string, any>, flow: Flow): Promise<string>;
|
|
14
|
+
export declare function codeToStaticTemplate(code?: string): string | undefined;
|