Fix flow triggers being registered multiple times (#13783)

Fixes #13739
This commit is contained in:
Nicola Krumschmidt
2022-06-08 16:27:00 +02:00
committed by GitHub
parent ef2b629c9b
commit 2efff9fd16
4 changed files with 146 additions and 57 deletions

View File

@@ -1,49 +1,64 @@
import { FlowRaw } from '@directus/shared/types';
import { getMessenger, Messenger } from '../messenger';
import { getFlowManager } from '../flows';
import { AbstractServiceOptions, Item, MutationOptions, PrimaryKey } from '../types';
import { ItemsService } from './items';
export class FlowsService extends ItemsService<FlowRaw> {
messenger: Messenger;
constructor(options: AbstractServiceOptions) {
super('directus_flows', options);
this.messenger = getMessenger();
}
async createOne(data: Partial<Item>, opts?: MutationOptions): Promise<PrimaryKey> {
const flowManager = getFlowManager();
const result = await super.createOne(data, opts);
this.messenger.publish('flows', { type: 'reload' });
await flowManager.reload();
return result;
}
async createMany(data: Partial<Item>[], opts?: MutationOptions): Promise<PrimaryKey[]> {
const flowManager = getFlowManager();
const result = await super.createMany(data, opts);
this.messenger.publish('flows', { type: 'reload' });
await flowManager.reload();
return result;
}
async updateOne(key: PrimaryKey, data: Partial<Item>, opts?: MutationOptions): Promise<PrimaryKey> {
const flowManager = getFlowManager();
const result = await super.updateOne(key, data, opts);
this.messenger.publish('flows', { type: 'reload' });
await flowManager.reload();
return result;
}
async updateMany(keys: PrimaryKey[], data: Partial<Item>, opts?: MutationOptions): Promise<PrimaryKey[]> {
const flowManager = getFlowManager();
const result = await super.updateMany(keys, data, opts);
this.messenger.publish('flows', { type: 'reload' });
await flowManager.reload();
return result;
}
async deleteOne(key: PrimaryKey, opts?: MutationOptions): Promise<PrimaryKey> {
const flowManager = getFlowManager();
const result = await super.deleteOne(key, opts);
this.messenger.publish('flows', { type: 'reload' });
await flowManager.reload();
return result;
}
async deleteMany(keys: PrimaryKey[], opts?: MutationOptions): Promise<PrimaryKey[]> {
const flowManager = getFlowManager();
const result = await super.deleteMany(keys, opts);
this.messenger.publish('flows', { type: 'reload' });
await flowManager.reload();
return result;
}
}

View File

@@ -1,49 +1,64 @@
import { OperationRaw } from '@directus/shared/types';
import { getMessenger, Messenger } from '../messenger';
import { getFlowManager } from '../flows';
import { AbstractServiceOptions, Item, MutationOptions, PrimaryKey } from '../types';
import { ItemsService } from './items';
export class OperationsService extends ItemsService<OperationRaw> {
messenger: Messenger;
constructor(options: AbstractServiceOptions) {
super('directus_operations', options);
this.messenger = getMessenger();
}
async createOne(data: Partial<Item>, opts?: MutationOptions): Promise<PrimaryKey> {
const flowManager = getFlowManager();
const result = await super.createOne(data, opts);
this.messenger.publish('flows', { type: 'reload' });
await flowManager.reload();
return result;
}
async createMany(data: Partial<Item>[], opts?: MutationOptions): Promise<PrimaryKey[]> {
const flowManager = getFlowManager();
const result = await super.createMany(data, opts);
this.messenger.publish('flows', { type: 'reload' });
await flowManager.reload();
return result;
}
async updateOne(key: PrimaryKey, data: Partial<Item>, opts?: MutationOptions): Promise<PrimaryKey> {
const flowManager = getFlowManager();
const result = await super.updateOne(key, data, opts);
this.messenger.publish('flows', { type: 'reload' });
await flowManager.reload();
return result;
}
async updateMany(keys: PrimaryKey[], data: Partial<Item>, opts?: MutationOptions): Promise<PrimaryKey[]> {
const flowManager = getFlowManager();
const result = await super.updateMany(keys, data, opts);
this.messenger.publish('flows', { type: 'reload' });
await flowManager.reload();
return result;
}
async deleteOne(key: PrimaryKey, opts?: MutationOptions): Promise<PrimaryKey> {
const flowManager = getFlowManager();
const result = await super.deleteOne(key, opts);
this.messenger.publish('flows', { type: 'reload' });
await flowManager.reload();
return result;
}
async deleteMany(keys: PrimaryKey[], opts?: MutationOptions): Promise<PrimaryKey[]> {
const flowManager = getFlowManager();
const result = await super.deleteMany(keys, opts);
this.messenger.publish('flows', { type: 'reload' });
await flowManager.reload();
return result;
}
}