<commit_before>// @flow

import Ajv from 'ajv';
import addAjvKeywords from 'ajv-keywords';
import isomorphicWebpackConfigurationSchema from '../schemas/isomorphicWebpackConfigurationSchema.json';
import type {
  UserIsomorphicWebpackConfigurationType,
  IsomorphicWebpackConfigurationType
} from '../types';

const ajv = Ajv();

addAjvKeywords(ajv);

const validate = ajv.compile(isomorphicWebpackConfigurationSchema);

export default (userIsomorphicWebpackConfig: UserIsomorphicWebpackConfigurationType = {}): IsomorphicWebpackConfigurationType => {
  if (!validate(userIsomorphicWebpackConfig)) {
    // eslint-disable-next-line no-console
    console.log('validate.errors', validate.errors);

    throw new Error('Invalid configuration.');
  }

  const isomorphicWebpackConfiguration = {
    // eslint-disable-next-line no-undefined
    isRequireOverride: userIsomorphicWebpackConfig.hasOwnProperty('isRequireOverride') ? userIsomorphicWebpackConfig.isRequireOverride : undefined,
    nodeExternalsWhitelist: userIsomorphicWebpackConfig.hasOwnProperty('nodeExternalsWhitelist') ? userIsomorphicWebpackConfig.nodeExternalsWhitelist : [],
    useCompilationPromise: userIsomorphicWebpackConfig.hasOwnProperty('useCompilationPromise') ? Boolean(userIsomorphicWebpackConfig.useCompilationPromise) : false
  };

  return isomorphicWebpackConfiguration;
};<commit_msg>chore: fix flow types<commit_after>// @flow

import Ajv from 'ajv';
import addAjvKeywords from 'ajv-keywords';
import isomorphicWebpackConfigurationSchema from '../schemas/isomorphicWebpackConfigurationSchema.json';
import type {
  UserIsomorphicWebpackConfigurationType,
  IsomorphicWebpackConfigurationType
} from '../types';

const ajv = Ajv();

addAjvKeywords(ajv);

const validate = ajv.compile(isomorphicWebpackConfigurationSchema);

export default (userIsomorphicWebpackConfig: UserIsomorphicWebpackConfigurationType = {}): IsomorphicWebpackConfigurationType => {
  if (!validate(userIsomorphicWebpackConfig)) {
    // eslint-disable-next-line no-console
    console.log('validate.errors', validate.errors);

    throw new Error('Invalid configuration.');
  }

  const isomorphicWebpackConfiguration = {
    // eslint-disable-next-line no-undefined
    isRequireOverride: userIsomorphicWebpackConfig.isRequireOverride === undefined ? undefined : userIsomorphicWebpackConfig.isRequireOverride,

    // eslint-disable-next-line no-undefined
    nodeExternalsWhitelist: userIsomorphicWebpackConfig.nodeExternalsWhitelist === undefined ? [] : userIsomorphicWebpackConfig.nodeExternalsWhitelist,

    // eslint-disable-next-line no-undefined
    useCompilationPromise: userIsomorphicWebpackConfig.useCompilationPromise === undefined ? false : Boolean(userIsomorphicWebpackConfig.useCompilationPromise)
  };

  return isomorphicWebpackConfiguration;
};
{'fraction_non_alphanumeric': 0.09297374024130589, 'fraction_numerical': 0.0, 'mean_word_length': 6.6603260869565215, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '9262', 'n_tokens_mistral': 771, 'n_tokens_neox': 747, 'n_words': 128}