<commit_before>// @flow
import type {APIResponse, TChannelStore, TFirebaseServiceResponse} from '../types/';
import {statusCode} from './resources';

export * from './firebase';
export * from './resources';
export * from './batches';
export * from './styles';

export const snapshotExists = (snapshot) => {
  if (snapshot.val() === null) {
    return false;
  }
  return true;
};

export const firebaseServiceResponse =
(promise: Promise<any>): Promise<TFirebaseServiceResponse> => {
  return promise.then((snapshot): APIResponse => {
    return {
      status: snapshotExists(snapshot) ? statusCode.Ok : statusCode.NotFound,
      message: '',
      snapshot,
    };
  })
  .catch((): APIResponse => ({
    status: statusCode.InternalError,
    message: '',
    snapshot: null,
  }));
};

export const handleServerError = (promise: Promise<any>): Promise<APIResponse> => {
  return promise
    .catch(() => {
      return {
        status: statusCode.InternalError,
        message: '',
      };
    })
    ;
};

export const isSuccess = (response: APIResponse) => response.status === statusCode.Ok;
export const isNotFound = (response: APIResponse) => response.status === statusCode.NotFound;

export const noop = () => {};

export const channelStoreArrayToObject = (channelsArray: TChannelStore[]) => {
  const channels: {[key: string]: TChannelStore} = {};
  channelsArray.forEach((channel) => {
    channels[channel.id] = channel;
  });
  return channels;
};

export const activeChannelStoreArray = (channelsArray: TChannelStore[]) => {
  // TODO filterって破壊的だっけ？<commit_msg>remove comment<commit_after>// @flow
import type {APIResponse, TChannelStore, TFirebaseServiceResponse} from '../types/';
import {statusCode} from './resources';

export * from './firebase';
export * from './resources';
export * from './batches';
export * from './styles';

export const snapshotExists = (snapshot) => {
  if (snapshot.val() === null) {
    return false;
  }
  return true;
};

export const firebaseServiceResponse =
(promise: Promise<any>): Promise<TFirebaseServiceResponse> => {
  return promise.then((snapshot): APIResponse => {
    return {
      status: snapshotExists(snapshot) ? statusCode.Ok : statusCode.NotFound,
      message: '',
      snapshot,
    };
  })
  .catch((): APIResponse => ({
    status: statusCode.InternalError,
    message: '',
    snapshot: null,
  }));
};

export const handleServerError = (promise: Promise<any>): Promise<APIResponse> => {
  return promise
    .catch(() => {
      return {
        status: statusCode.InternalError,
        message: '',
      };
    })
    ;
};

export const isSuccess = (response: APIResponse) => response.status === statusCode.Ok;
export const isNotFound = (response: APIResponse) => response.status === statusCode.NotFound;

export const noop = () => {};

export const channelStoreArrayToObject = (channelsArray: TChannelStore[]) => {
  const channels: {[key: string]: TChannelStore} = {};
  channelsArray.forEach((channel) => {
    channels[channel.id] = channel;
  });
  return channels;
};

export const activeChannelStoreArray = (channelsArray: TChannelStore[]) => {
{'fraction_non_alphanumeric': 0.15608043408873284, 'fraction_numerical': 0.0, 'mean_word_length': 3.87402799377916, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 35, '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': '4361926', 'n_tokens_mistral': 894, 'n_tokens_neox': 906, 'n_words': 220}