refactor: use functional app implementation
This commit is contained in:
@@ -10,28 +10,38 @@ class App {
|
||||
|
||||
// Temporaryly restrict the apps we expose until
|
||||
// their actions/triggers are implemented!
|
||||
static temporaryList = ['slack', 'twitter'];
|
||||
static temporaryList = [
|
||||
'slack',
|
||||
'twitter',
|
||||
'scheduler'
|
||||
];
|
||||
|
||||
static async findAll(name?: string): Promise<IApp[]> {
|
||||
static async findAll(name?: string, stripFuncs = true): Promise<IApp[]> {
|
||||
if (!name)
|
||||
return Promise.all(
|
||||
this.temporaryList.map(async (name) => await this.findOneByName(name))
|
||||
this.temporaryList.map(async (name) => await this.findOneByName(name, stripFuncs))
|
||||
);
|
||||
|
||||
return Promise.all(
|
||||
this.temporaryList
|
||||
.filter((app) => app.includes(name.toLowerCase()))
|
||||
.map((name) => this.findOneByName(name))
|
||||
.map((name) => this.findOneByName(name, stripFuncs))
|
||||
);
|
||||
}
|
||||
|
||||
static async findOneByName(name: string): Promise<IApp> {
|
||||
const rawAppData = await getApp(name.toLocaleLowerCase());
|
||||
static async findOneByName(name: string, stripFuncs = false): Promise<IApp> {
|
||||
const rawAppData = await getApp(name.toLocaleLowerCase(), stripFuncs);
|
||||
|
||||
if (!stripFuncs) return rawAppData;
|
||||
|
||||
return appInfoConverter(rawAppData);
|
||||
}
|
||||
|
||||
static async findOneByKey(key: string): Promise<IApp> {
|
||||
const rawAppData = await getApp(key);
|
||||
static async findOneByKey(key: string, stripFuncs = false): Promise<IApp> {
|
||||
const rawAppData = await getApp(key, stripFuncs);
|
||||
|
||||
if (!stripFuncs) return rawAppData;
|
||||
|
||||
return appInfoConverter(rawAppData);
|
||||
}
|
||||
}
|
||||
|
@@ -97,12 +97,8 @@ class Step extends Base {
|
||||
|
||||
const { appKey, key } = this;
|
||||
|
||||
const connection = await this.$relatedQuery('connection');
|
||||
const flow = await this.$relatedQuery('flow');
|
||||
|
||||
const AppClass = (await import(`../apps/${appKey}`)).default;
|
||||
const appInstance = new AppClass(connection, flow, this);
|
||||
const command = appInstance.triggers[key];
|
||||
const app = await App.findOneByKey(appKey);
|
||||
const command = app.triggers.find((trigger) => trigger.key === key);
|
||||
|
||||
return command;
|
||||
}
|
||||
|
Reference in New Issue
Block a user