<commit_before>/* @flow */

import * as Immutable from 'immutable';
import * as uuid from 'uuid';
import * as commutable from 'commutable';

import * as constants from '../constants';

import type { LanguageInfoMetadata } from '../records';

import { DocumentRecord } from '../records';

// Note that we can't use the type definition of Output from records.js
// because it's an Immutable.Map here. When we have a union on Immutable Records.
// We can swap these out later.

export type ImmutableJSON = | string | number | boolean | null
                            | ImmutableJSONMap | ImmutableJSONList; // eslint-disable-line no-use-before-define
export type ImmutableJSONMap = Immutable.Map<string, ImmutableJSON>;
export type ImmutableJSONList = Immutable.List<ImmutableJSON>;

type ImmutableOutput = Immutable.Map<string, any>;
type ImmutableOutputs = Immutable.List<ImmutableOutput>;

// Non-immutable output
type JSON = | string | number | boolean | null | JSONObject | JSONArray; // eslint-disable-line no-use-before-define
type JSONObject = { [key:string]: JSON };
type JSONArray = Array<JSON>;

type ExecutionCount = number | null;

type CellType = 'code' | 'markdown';

// Until flow, Immutable, and Record play together
export type ImmutableCodeCell = Immutable.Map<string, any>;
export type ImmutableMarkdownCell = Immutable.Map<string, any>;
export type ImmutableCell = ImmutableCodeCell | ImmutableMarkdownCell;

export type CodeCell = {
  cell_type: 'code',
  metadata: ImmutableJSONMap,
  execution_count: ExecutionCount,
  source: string,
  outputs: Immutable.List<ImmutableOutput>,
}

export type MarkdownCell = {
  cell_type: 'markdown',
  source: string,
  metadata: ImmutableJSONMap,
}

export function createCodeCell(cell: CodeCell): ImmutableCodeCell {
  return Immutable.Map(cell);
}

export function createMarkdownCell(cell: MarkdownCell): ImmutableMarkdownCell {
  return Immutable.Map(cell);
}

export const emptyCodeCell = createCodeCell({
  cell_type: 'code',
  execution_count: null,
  metadata: Immutable.Map({
    collapsed: false,
  }),
  source: '',
  outputs: Immutable.List(),
});

export const emptyMarkdownCell = createMarkdownCell({
  cell_type: 'markdown',
  metadata: Immutable.Map(),
  source: '',
});

type MimeBundle = JSONObject;

type Pager = {
  source: 'page',
  data: MimeBundle,
  start: number
}

type ExecuteResult = {
  output_type: 'execute_result',
  execution_count: ExecutionCount,
  data: MimeBundle,
  metadata: JSONObject,<commit_msg>refactor(document): functional style for default parameters<commit_after>/* @flow */

import * as Immutable from 'immutable';
import * as uuid from 'uuid';
import * as commutable from 'commutable';

import * as constants from '../constants';

import type { LanguageInfoMetadata } from '../records';

import { DocumentRecord } from '../records';

// Note that we can't use the type definition of Output from records.js
// because it's an Immutable.Map here. When we have a union on Immutable Records.
// We can swap these out later.

export type ImmutableJSON = | string | number | boolean | null
                            | ImmutableJSONMap | ImmutableJSONList; // eslint-disable-line no-use-before-define
export type ImmutableJSONMap = Immutable.Map<string, ImmutableJSON>;
export type ImmutableJSONList = Immutable.List<ImmutableJSON>;

type ImmutableOutput = Immutable.Map<string, any>;
type ImmutableOutputs = Immutable.List<ImmutableOutput>;

// Non-immutable output
type JSON = | string | number | boolean | null | JSONObject | JSONArray; // eslint-disable-line no-use-before-define
type JSONObject = { [key:string]: JSON };
type JSONArray = Array<JSON>;

type ExecutionCount = number | null;

type CellType = 'code' | 'markdown';

// Until flow, Immutable, and Record play together
export type ImmutableCodeCell = Immutable.Map<string, any>;
export type ImmutableMarkdownCell = Immutable.Map<string, any>;
export type ImmutableCell = ImmutableCodeCell | ImmutableMarkdownCell;

export type CodeCell = {
  cell_type: 'code',
  metadata: ImmutableJSONMap,
  execution_count: ExecutionCount,
  source: string,
  outputs: Immutable.List<ImmutableOutput>,
}

export type MarkdownCell = {
  cell_type: 'markdown',
  source: string,
  metadata: ImmutableJSONMap,
}

const defaultCodeCell = {
  cell_type: 'code',
  execution_count: null,
  metadata: Immutable.Map({
    collapsed: false,
  }),
  source: '',
  outputs: Immutable.List(),
};

const defaultMarkdownCell = {
  cell_type: 'markdown',
  metadata: Immutable.Map(),
  source: '',
};

export function createCodeCell(cell: CodeCell = defaultCodeCell): ImmutableCodeCell { // eslint-disable-line max-len
  return Immutable.Map(cell);
}

export function createMarkdownCell(cell: MarkdownCell = defaultMarkdownCell): ImmutableMarkdownCell { // eslint-disable-line max-len
  return Immutable.Map(cell);
}

export const emptyCodeCell = createCodeCell();
export const emptyMarkdownCell = createMarkdownCell();

type MimeBundle = JSONObject;

type Pager = {
  source: 'page',
  data: MimeBundle,
  start: number
}

type ExecuteResult = {
  output_type: 'execute_result',
  execution_count: ExecutionCount,
  data: MimeBundle,
  metadata: JSONObject,
{'fraction_non_alphanumeric': 0.10910140465653262, 'fraction_numerical': 0.0, 'mean_word_length': 4.6316359696641385, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '4533717', 'n_tokens_mistral': 1531, 'n_tokens_neox': 1528, 'n_words': 452}