<commit_before>const dir = require(`${global.baseDir}/global-dirs`)
const Enum = require(`${dir.api}enum`)

const Table = (name = '', props = {}) => {
	const data = new Map()
	const primaryKey = `${name}Id`
	let nextId = 0
	let schema = {}

	// Setup Schema
	Object.keys(props).forEach(key => (
		schema[key] = Enum(key, props[key])
	))

	Object.freeze(schema)

	// Private
	const getId = () => {
		const id = nextId
		nextId += 1
		return id
	}

	// Public
	const get = id => data.get(Number(id))
	const getAll = () => Array.from(data.values())

	const getByManyValues = lookupParams => {
		const keys = Object.keys(lookupParams)

		return getAll().find(entry => (
			keys.every(key => entry[key] === lookupParams[key])
		))
	}
	const getByKeyValue = (key, value) => getByManyValues({ [key]: value })

	const getAllByManyValues = lookupParams => {
		const keys = Object.keys(lookupParams)

		// console.log('filtered', getAll().filter(entry => {
		// 	return keys.every(key => {
		// 		console.log('key', key)
		// 		console.log('entry[key]', entry[key])
		// 		console.log('lookupParams[key]', lookupParams[key])
		// 		return entry[key] === lookupParams[key]
		// 	})
		// }));
		return getAll().filter(entry => (
			keys.every(key => entry[key] === lookupParams[key])
		))
	}
	const getAllByKeyValue = (key, value) => getAllByManyValues({ [key]: value })

	const update = (itemId, entry) => {
		const id = Number(itemId)
		const currentEntry = get(id) || {}
		const newEntry = {}

		Object.keys(schema).forEach(key => {
			const schemaEnum = schema[key]
			const entryValue = entry[key]
			const currentValue = currentEntry[key]

			// Account for 0 being falsy
			const isPrimaryKey = key === primaryKey && (id === 0 || id)
			const hasValueInEntry = entryValue || entryValue === 0
			const hasValueInCurrentEntry = currentValue || currentValue === 0

			if (key === primaryKey && (id || id === 0)) {
				value = id
			} else if (entryValue || entryValue === 0) {
				value = entryValue
			} else if (currentValue || currentValue === 0) {
				value = currentValue
			} else {
				value = schemaEnum.default()
			}

			newEntry[key] = value
		})

		data.set(id, newEntry)
		return newEntry
	}

	const add = entry => {
		const id = getId()
		return update(id, entry)
	}

	const remove = id => data.delete(id)
<commit_msg>Fixed getting tweets for user by making 0 truthy<commit_after>const dir = require(`${global.baseDir}/global-dirs`)
const Enum = require(`${dir.api}enum`)

const Table = (name = '', props = {}) => {
	const data = new Map()
	const primaryKey = `${name}Id`
	let nextId = 0
	let schema = {}

	// Setup Schema
	Object.keys(props).forEach(key => (
		schema[key] = Enum(key, props[key])
	))

	Object.freeze(schema)

	// Private
	const getId = () => {
		const id = nextId
		nextId += 1
		return id
	}

	// Public
	const get = id => data.get(Number(id))
	const getAll = () => Array.from(data.values())

	const getByManyValues = lookupParams => {
		const keys = Object.keys(lookupParams)

		return getAll().find(entry => (
			keys.every(key => entry[key] === lookupParams[key])
		))
	}
	const getByKeyValue = (key, value) => getByManyValues({ [key]: value })

	const getAllByManyValues = lookupParams => {
		const keys = Object.keys(lookupParams)

		// console.log('filtered', getAll().filter(entry => {
		// 	return keys.every(key => {
		// 		console.log('key', key)
		// 		console.log('entry[key]', entry[key])
		// 		console.log('lookupParams[key]', lookupParams[key])
		// 		return entry[key] === lookupParams[key]
		// 	})
		// }));
		return getAll().filter(entry => (
			keys.every(key => entry[key] === lookupParams[key])
		))
	}
	const getAllByKeyValue = (key, value) => getAllByManyValues({ [key]: value })

	const update = (itemId, entry) => {
		const id = Number(itemId)
		const currentEntry = get(id) || {}
		const newEntry = {}

		Object.keys(schema).forEach(key => {
			const schemaEnum = schema[key]
			const entryValue = entry[key]
			const currentValue = currentEntry[key]
			let value

			// HACK: Make 0 truthy
			if (key === primaryKey && (id || id === 0)) {
				value = id == 0 ? 0 : id
			} else if (entryValue || entryValue === 0) {
				value = entryValue == 0 ? 0 : entryValue
			} else if (currentValue || currentValue === 0) {
				value = currentValue == 0 ? 0 : currentValue
			} else {
				value = schemaEnum.default()
			}

			newEntry[key] = value
		})

		data.set(id, newEntry)
		return newEntry
	}

	const add = entry => {
		const id = getId()
		return update(id, entry)
	}

	const remove = id => data.delete(id)

{'fraction_non_alphanumeric': 0.17152884404474666, 'fraction_numerical': 0.00482561965343277, 'mean_word_length': 3.314096499526963, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, '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': '5578034', 'n_tokens_mistral': 1725, 'n_tokens_neox': 1534, 'n_words': 369}