refactor: Specify only the arguments for trigger definitions

This commit is contained in:
Faruk AYDIN
2022-10-31 18:12:12 +01:00
parent 571bf6bfa7
commit b3f216209a
21 changed files with 691 additions and 861 deletions

View File

@@ -1,5 +1,7 @@
import { ITrigger } from '@automatisch/types';
import { IRawTrigger } from '@automatisch/types';
export default function defineTrigger(triggerDefinition: ITrigger): ITrigger {
export default function defineTrigger(
triggerDefinition: IRawTrigger
): IRawTrigger {
return triggerDefinition;
}

View File

@@ -1,4 +1,5 @@
import { IApp } from '@automatisch/types';
import { IApp, IRawTrigger, ITrigger } from '@automatisch/types';
import { omit, cloneDeep } from 'lodash';
async function getDefaultExport(path: string) {
return (await import(path)).default;
@@ -8,8 +9,40 @@ function stripFunctions<C>(data: C): C {
return JSON.parse(JSON.stringify(data));
}
const chooseConnectionStep = {
key: 'chooseConnection',
name: 'Choose connection',
};
const testStep = {
key: 'testStep',
name: 'Test trigger',
};
const getApp = async (appKey: string, stripFuncs = true) => {
const appData: IApp = await getDefaultExport(`../apps/${appKey}`);
const appData: IApp = cloneDeep(await getDefaultExport(`../apps/${appKey}`));
appData.triggers = appData?.triggers?.map((trigger: IRawTrigger) => {
const computedTrigger: ITrigger = omit(trigger, ['arguments']);
computedTrigger.substeps = [];
if (appData.supportsConnections) {
computedTrigger.substeps.push(chooseConnectionStep);
}
if (trigger.arguments) {
computedTrigger.substeps.push({
key: 'chooseTrigger',
name: 'Set up a trigger',
arguments: trigger.arguments,
});
}
computedTrigger.substeps.push(testStep);
return computedTrigger;
});
if (stripFuncs) {
return stripFunctions(appData);