MCPcopy
hub / github.com/directus/directus / executeFlow

Method executeFlow

api/src/flows.ts:393–504  ·  view source on GitHub ↗
(flow: Flow, data: unknown = null, context: Record<string, unknown> = {})

Source from the content-addressed store, hash-verified

391 }
392
393 private async executeFlow(flow: Flow, data: unknown = null, context: Record<string, unknown> = {}): Promise<unknown> {
394 const database = (context['database'] as Knex) ?? getDatabase();
395 const schema = (context['schema'] as SchemaOverview) ?? (await getSchema({ database }));
396
397 const keyedData: Record<string, unknown> = {
398 [TRIGGER_KEY]: data,
399 [LAST_KEY]: data,
400 [ACCOUNTABILITY_KEY]: context?.['accountability'] ?? null,
401 [ENV_KEY]: this.envs,
402 };
403
404 context['flow'] ??= flow;
405
406 let nextOperation = flow.operation;
407 let lastOperationStatus: 'resolve' | 'reject' | 'unknown' = 'unknown';
408
409 const steps: {
410 operation: string;
411 key: string;
412 status: 'resolve' | 'reject' | 'unknown';
413 options: Record<string, any> | null;
414 }[] = [];
415
416 while (nextOperation !== null) {
417 const { successor, data, status, options } = await this.executeOperation(nextOperation, keyedData, context);
418
419 keyedData[nextOperation.key] = data;
420 keyedData[LAST_KEY] = data;
421 lastOperationStatus = status;
422 steps.push({ operation: nextOperation!.id, key: nextOperation.key, status, options });
423
424 nextOperation = successor;
425 }
426
427 if (flow.accountability !== null) {
428 const activityService = new ActivityService({
429 knex: database,
430 schema: schema,
431 });
432
433 const accountability = context?.['accountability'] as Accountability | undefined;
434
435 const activity = await activityService.createOne({
436 action: Action.RUN,
437 user: accountability?.user ?? null,
438 collection: 'directus_flows',
439 ip: accountability?.ip ?? null,
440 user_agent: accountability?.userAgent ?? null,
441 origin: accountability?.origin ?? null,
442 item: flow.id,
443 });
444
445 if (flow.accountability === 'all') {
446 const revisionsService = new RevisionsService({
447 knex: database,
448 schema: schema,
449 });
450

Callers 2

handlerMethod · 0.95
loadMethod · 0.95

Calls 7

executeOperationMethod · 0.95
createOneMethod · 0.95
getDatabaseFunction · 0.85
getSchemaFunction · 0.85
redactObjectFunction · 0.85
createOneMethod · 0.65
getFunction · 0.50

Tested by

no test coverage detected