<commit_before>import Immutable, { Map } from 'immutable';
import * as l from '../lock/index';
import * as client from '../lock/client/index';
import { clearFields } from '../field/index';
import { dataFns } from '../utils/data_utils';

const { get, initNS, tget, tset } = dataFns(["database"]);

export function initDatabase(m, options) {
  return initNS(m, Immutable.fromJS(processDatabaseOptions(options)));
}

function processDatabaseOptions(options) {
  let {
    signUpFields,
    disableResetAction,
    disableSignUpAction,
    initialScreen,
    loginAfterSignUp,
    resetLink,
    signUpLink,
    usernameStyle
  } = options;

  // TODO: add a warning if it is not "username" or "email", leave it
  // undefined, and change accesor fn.
  usernameStyle = usernameStyle === "username" ? "username" : "email";

  let screens = ["login", "signUp", "resetPassword"];<commit_msg>Allow empty custom sign up fields<commit_after>import Immutable, { Map } from 'immutable';
import * as l from '../lock/index';
import * as client from '../lock/client/index';
import { clearFields, setField } from '../field/index';
import { dataFns } from '../utils/data_utils';

const { get, initNS, tget, tset } = dataFns(["database"]);

export function initDatabase(m, options) {
  m = initNS(m, Immutable.fromJS(processDatabaseOptions(options)));
  signUpFields(m).forEach((v, k) => m = setField(m, k, "", v.get("validator")));
  return m;
}

function processDatabaseOptions(options) {
  let {
    signUpFields,
    disableResetAction,
    disableSignUpAction,
    initialScreen,
    loginAfterSignUp,
    resetLink,
    signUpLink,
    usernameStyle
  } = options;

  // TODO: add a warning if it is not "username" or "email", leave it
  // undefined, and change accesor fn.
  usernameStyle = usernameStyle === "username" ? "username" : "email";

  let screens = ["login", "signUp", "resetPassword"];
{'fraction_non_alphanumeric': 0.14353813559322035, 'fraction_numerical': 0.0, 'mean_word_length': 4.091644204851752, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1420408', 'n_tokens_mistral': 576, 'n_tokens_neox': 575, 'n_words': 165}