<commit_before>/** @flow */
import type {Manager} from '../../../src/types'

function randomString() {
  return Math.random().toString(36).substring(7)
}

function range(from, to) {
  return Array.from(new Uint32Array(to - from + 1).map((val, index) => index + from))
}

export function createFixtureManager(manager: Manager) {

  let usersCount = 0

  function createUser() {
    return manager.getRepository('users')
      .create({
        login: 'user' + (++usersCount),
        password: <PASSWORD>()
      })
      .save()
  }

  function createUsers(count: number = 1) {
    return Promise.all(range(0, count).map(createUser))
  }

  function createPostToUser(id: number) {
    return manager.getRepository('posts')
      .create({
        title: 'post ' + randomString(),
        body: randomString(),
        creator_id: id
      })
      .save()
  }

  async function createPost() {
    const user = await createUser()
    return createPostToUser(user.id)
  }

  function createPostsToUser(count: number = 1, id: number) {
    return Promise.all(range(0, count).map(createPostsToUser.bind(id)))
  }

  async function createPosts(userCount?: number = 1, postsPerUser?: number = 1) {
    const users = await createUsers(usersCount)
    return Promise.all(users.map(user => createPostsToUser(postsPerUser, user.id)))
  }

  function createPostComment(postId: number, userId: number) {
    return manager.getRepository('comments')
      .create({
        creator_id: userId,
        post_id: postId,
        body: randomString()
      })
      .save()
  }

  async function createPostCommentWithUser(postId: number) {
    const user = await createUser()
    return createPostComment(postId, user.id)
  }

  async function createPostWithComments(count: number = 1) {
    const post = await createPost()
    return Promise.all(range(0, count).map(createPostCommentWithUser.bind(post.id)))
  }

  return {
    createUser,
    createUsers,

    createPost,<commit_msg>Fix for flow strange error<commit_after>/** @flow */
import type {Manager} from '../../../src/types'

function randomString() {
  return Math.random().toString(36).substring(7)
}

function range(from, to): Array<number> {
  return Array.from(new Uint32Array(to - from + 1).map((val, index) => index + from))
}

export function createFixtureManager(manager: Manager) {

  let usersCount = 0

  function createUser(): Promise<Object> {
    return manager.getRepository('users')
      .create({
        login: 'user' + (++usersCount),
        password: <PASSWORD>()
      })
      .save()
  }

  function createUsers(count: number = 1): Promise<Array<Object>> {
    return Promise.all(range(0, count).map(createUser))
  }

  function createPostToUser(id: number): Promise<Object> {
    return manager.getRepository('posts')
      .create({
        title: 'post ' + randomString(),
        body: randomString(),
        creator_id: id
      })
      .save()
  }

  async function createPost(): Promise<Object> {
    const user = await createUser()
    return createPostToUser(user.id)
  }

  function createPostsToUser(count: number = 1, id: number): Promise<Array<Object>> {
    return Promise.all(range(0, count).map(createPostsToUser.bind(id)))
  }

  async function createPosts(userCount?: number = 1, postsPerUser?: number = 1): Promise<Array<Array<Object>>> {
    const users = await createUsers(usersCount)
    return Promise.all(users.map(user => createPostsToUser(postsPerUser, user.id)))
  }

  function createPostComment(postId: number, userId: number): Promise<Object> {
    return manager.getRepository('comments')
      .create({
        creator_id: userId,
        post_id: postId,
        body: randomString()
      })
      .save()
  }

  async function createPostCommentWithUser(postId: number): Promise<Object> {
    const user = await createUser()
    return createPostComment(postId, user.id)
  }

  async function createPostWithComments(count: number = 1): Promise<Array<Object>> {
    const post = await createPost()
    return Promise.all(range(0, count).map(createPostCommentWithUser.bind(post.id)))
  }

  return {
    createUser,
    createUsers,

    createPost,
{'fraction_non_alphanumeric': 0.13426371511068336, 'fraction_numerical': 0.007218479307025986, 'mean_word_length': 3.408271474019088, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 24, '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': '6640538', 'n_tokens_mistral': 1285, 'n_tokens_neox': 1242, 'n_words': 287}