docs: function decorateWithSessionsData(command, session, options) {
    if (!session) {
      return;
    }
  
    // first apply non-transaction-specific sessions data
    const serverSession = session.serverSession;
    const inTransaction = session.inTransaction() || isTransactionCommand(command);
    const isRetryableWrite = options.willRetryWrite;
  
    if (serverSession.txnNumber && (isRetryableWrite || inTransaction)) {
      command.txnNumber = BSON.Long.fromNumber(serverSession.txnNumber);
    }
  
    // now attempt to apply transaction-specific sessions data
    if (!inTransaction) {
      if (session.transaction.state !== TxnState.NO_TRANSACTION) {
        session.transaction.transition(TxnState.NO_TRANSACTION);
      }
  
      // for causal consistency
      if (session.supports.causalConsistency && session.operationTime) {
        command.readConcern = command.readConcern || {};
        Object.assign(command.readConcern, { afterClusterTime: session.operationTime });
      }
  
      return;
    }
  
    if (options.readPreference && !options.readPreference.equals(ReadPreference.primary)) {
      return new MongoError(
        `Read preference in a transaction must be primary, not: ${options.readPreference.mode}`
      );
    }
  
    // `autocommit` must always be false to differentiate from retryable writes
    command.autocommit = false;
  
    if (session.transaction.state === TxnState.STARTING_TRANSACTION) {
      session.transaction.transition(TxnState.TRANSACTION_IN_PROGRESS);
      command.startTransaction = true;
  
      const readConcern =
        session.transaction.options.readConcern || session.clientOptions.readConcern;
      if (readConcern) {
        command.readConcern = readConcern;
      }
  
      if (session.supports.causalConsistency && session.operationTime) {
        command.readConcern = command.readConcern || {};
        Object.assign(command.readConcern, { afterClusterTime: session.operationTime });
      }
    }
  }