chore: server code formatting
This commit is contained in:
parent
aedabcbdee
commit
68517170e2
234 changed files with 9824 additions and 6195 deletions
|
|
@ -2,20 +2,18 @@ const fs = require('fs')
|
|||
const ndjson = require('ndjson')
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
|
||||
const mapAliases = _.curry((iteratee, individuals) => {
|
||||
const mapIndividual = individual => {
|
||||
const {id, aliases} = individual
|
||||
const { id, aliases } = individual
|
||||
return _.map(alias => iteratee(id, alias), aliases)
|
||||
}
|
||||
return _.flatMap(mapIndividual, individuals)
|
||||
})
|
||||
|
||||
|
||||
const getPhoneticEntries = (individualId, alias) => {
|
||||
const pairPhoneticsWithValues = word => {
|
||||
const {value, phonetics} = word
|
||||
const makeEntry = phonetic => ({value, phonetic, aliasId: alias.id})
|
||||
const { value, phonetics } = word
|
||||
const makeEntry = phonetic => ({ value, phonetic, aliasId: alias.id })
|
||||
return _.map(makeEntry, phonetics)
|
||||
}
|
||||
return _.flatMap(pairPhoneticsWithValues, alias.words)
|
||||
|
|
@ -25,17 +23,13 @@ const producePhoneticMap = _.flow(
|
|||
mapAliases(getPhoneticEntries),
|
||||
_.flatten,
|
||||
_.groupBy(_.get('phonetic')),
|
||||
_.mapValues(_.flow(
|
||||
_.map(_.get('aliasId')),
|
||||
_.uniq
|
||||
)),
|
||||
_.mapValues(_.flow(_.map(_.get('aliasId')), _.uniq)),
|
||||
_.toPairs,
|
||||
entries => new Map(entries)
|
||||
entries => new Map(entries),
|
||||
)
|
||||
|
||||
|
||||
const getWords = (individualId, alias) => {
|
||||
const pairWordsWithIds = word => ({value: word.value, aliasId: alias.id})
|
||||
const pairWordsWithIds = word => ({ value: word.value, aliasId: alias.id })
|
||||
return _.map(pairWordsWithIds, alias.words)
|
||||
}
|
||||
|
||||
|
|
@ -45,7 +39,7 @@ const produceWordList = _.flow(
|
|||
_.groupBy(_.get('value')),
|
||||
_.mapValues(_.map(_.get('aliasId'))),
|
||||
_.toPairs,
|
||||
_.map(_.zipObject(['value', 'aliasIds']))
|
||||
_.map(_.zipObject(['value', 'aliasIds'])),
|
||||
)
|
||||
|
||||
const parseSource = source => {
|
||||
|
|
@ -55,10 +49,13 @@ const parseSource = source => {
|
|||
const jsonStream = readStream.pipe(ndjson.parse())
|
||||
jsonStream.on('data', individual => {
|
||||
_.forEach(period => {
|
||||
_.forEach(date => {
|
||||
const {year, month, day} = date
|
||||
date.date = new Date(year, month - 1, day)
|
||||
}, [period.start, period.end])
|
||||
_.forEach(
|
||||
date => {
|
||||
const { year, month, day } = date
|
||||
date.date = new Date(year, month - 1, day)
|
||||
},
|
||||
[period.start, period.end],
|
||||
)
|
||||
}, individual.birthDatePeriods)
|
||||
individuals.push(individual)
|
||||
})
|
||||
|
|
@ -71,18 +68,14 @@ const parseSource = source => {
|
|||
})
|
||||
}
|
||||
|
||||
const load = sources => Promise.all(_.map(parseSource, sources))
|
||||
.then(_.flow(
|
||||
_.flatten,
|
||||
_.compact,
|
||||
_.uniqBy(_.get('id')),
|
||||
individuals => {
|
||||
|
||||
const load = sources =>
|
||||
Promise.all(_.map(parseSource, sources)).then(
|
||||
_.flow(_.flatten, _.compact, _.uniqBy(_.get('id')), individuals => {
|
||||
const individualsMap = _.flow(
|
||||
_.groupBy(_.get('id')),
|
||||
_.mapValues(_.first),
|
||||
_.toPairs,
|
||||
entries => new Map(entries)
|
||||
entries => new Map(entries),
|
||||
)(individuals)
|
||||
|
||||
const makeEntries = (individualId, alias) => [alias.id, alias]
|
||||
|
|
@ -101,9 +94,9 @@ const load = sources => Promise.all(_.map(parseSource, sources))
|
|||
aliasesMap,
|
||||
aliasToIndividual,
|
||||
phoneticMap,
|
||||
wordList
|
||||
wordList,
|
||||
}
|
||||
}
|
||||
))
|
||||
}),
|
||||
)
|
||||
|
||||
module.exports = {load}
|
||||
module.exports = { load }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue