findTransactionPlan

function findTransactionPlan(
    transactionPlan,
    predicate,
): TransactionPlan | undefined;

Finds the first transaction plan in the tree that matches the given predicate.

This function performs a depth-first search through the transaction plan tree, returning the first plan that satisfies the predicate. It checks the root plan first, then recursively searches through nested plans.

Parameters

ParameterTypeDescription
transactionPlanTransactionPlanThe transaction plan tree to search.
predicate(plan) => booleanA function that returns true for the plan to find.

Returns

TransactionPlan | undefined

The first matching transaction plan, or undefined if no match is found.

Examples

Finding a non-divisible sequential plan.

const plan = parallelTransactionPlan([
  sequentialTransactionPlan([messageA, messageB]),
  nonDivisibleSequentialTransactionPlan([messageC, messageD]),
]);
 
const nonDivisible = findTransactionPlan(
  plan,
  (p) => p.kind === 'sequential' && !p.divisible,
);
// Returns the non-divisible sequential plan containing messageC and messageD.

Finding a specific single transaction plan.

const plan = sequentialTransactionPlan([messageA, messageB, messageC]);
 
const found = findTransactionPlan(
  plan,
  (p) => p.kind === 'single' && p.message === messageB,
);
// Returns the SingleTransactionPlan wrapping messageB.

See

On this page