Skip to content

Commit

Permalink
Use cleaner-config
Browse files Browse the repository at this point in the history
  • Loading branch information
paullinator committed Oct 13, 2023
1 parent d97f01d commit 0a0f9eb
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"axios": "^0.21.2",
"biggystring": "^3.0.2",
"body-parser": "^1.19.0",
"cleaner-config": "^0.1.9",
"cleaners": "^0.3.13",
"commander": "^6.1.0",
"cors": "^2.8.5",
Expand Down
2 changes: 1 addition & 1 deletion src/cacheEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import startOfMonth from 'date-fns/startOfMonth'
import sub from 'date-fns/sub'
import nano from 'nano'

import config from '../config.json'
import { config } from './config'
import { getAnalytic } from './dbutils'
import { initDbs } from './initDbs'
import { asApps } from './types'
Expand Down
17 changes: 17 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { makeConfig } from 'cleaner-config'
import { asArray, asNumber, asObject, asOptional, asString } from 'cleaners'

export const asConfig = asObject({
couchDbFullpath: asOptional(
asString,
'http://username:password@localhost:5984'
),
httpPort: asOptional(asNumber, 8008),
soloAppIds: asOptional(asArray(asString), undefined),
soloPartnerIds: asOptional(asArray(asString), undefined),
timeoutOverrideMins: asOptional(asNumber, 1200),
apiHost: asOptional(asString, undefined),
cacheLookbackMonths: asOptional(asNumber, 24)
})

export const config = makeConfig(asConfig, 'config.json')
2 changes: 1 addition & 1 deletion src/dbutils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { asArray, asNumber, asObject, asString } from 'cleaners'
import nano from 'nano'

import config from '../config.json'
import { getAnalytics } from './apiAnalytics'
import { config } from './config'
import { AnalyticsResult, asCacheQuery } from './types'
import { datelog, promiseTimeout } from './util'

Expand Down
3 changes: 2 additions & 1 deletion src/indexApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import cors from 'cors'
import express from 'express'
import nano from 'nano'

import config from '../config.json'
import { config } from './config'
import { cacheAnalytic } from './dbutils'
import { asApps, asDbTx } from './types'

Expand Down Expand Up @@ -81,6 +81,7 @@ async function main(): Promise<void> {
},
limit: 1000000
}
console.log(config)
const rawApps = await reportsApps.find(query)
const apps = asApps(rawApps.docs)

Expand Down
2 changes: 1 addition & 1 deletion src/initDbs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import nano from 'nano'

import config from '../config.json'
import { config } from './config'
import { datelog } from './util'

const nanoDb = nano(config.couchDbFullpath)
Expand Down
2 changes: 1 addition & 1 deletion src/queryEngine.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import nano from 'nano'

import config from '../config.json'
import { config } from './config'
import { pagination } from './dbutils'
import { initDbs } from './initDbs'
import { banxa } from './partners/banxa'
Expand Down
2 changes: 1 addition & 1 deletion src/ratesEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { asArray, asObject, asUnknown } from 'cleaners'
import nano, { MangoQuery } from 'nano'
import fetch from 'node-fetch'

import config from '../config.json'
import { config } from './config'
import {
asDbCurrencyCodeMappings,
asDbTx,
Expand Down
2 changes: 1 addition & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import startOfMonth from 'date-fns/startOfMonth'
import sub from 'date-fns/sub'
import fetch, { RequestInfo, RequestInit, Response } from 'node-fetch'

import config from '../config.json'
import { config } from './config'
import { Data, DataPlusSevenDayAve } from './demo/components/Graphs'
import Partners from './demo/partners'
import { AnalyticsResult, asAnalyticsResult, Bucket } from './types'
Expand Down
36 changes: 36 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@
"@jridgewell/sourcemap-codec" "^1.4.10"
"@jridgewell/trace-mapping" "^0.3.9"

"@jridgewell/gen-mapping@^0.3.2":
version "0.3.3"
resolved "https://registry.yarnpkg.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.3.tgz#7e02e6eb5df901aaedb08514203b096614024098"
integrity sha512-HLhSWOLRi875zjjMG/r+Nv0oCW8umGb0BgEhyX3dDX3egwZtB8PqLnjz3yedt8R5StBrzcg4aBpnh8UA9D1BoQ==
dependencies:
"@jridgewell/set-array" "^1.0.1"
"@jridgewell/sourcemap-codec" "^1.4.10"
"@jridgewell/trace-mapping" "^0.3.9"

"@jridgewell/[email protected]":
version "3.1.0"
resolved "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.0.tgz"
Expand Down Expand Up @@ -1753,11 +1762,25 @@ clean-stack@^2.0.0:
resolved "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz"
integrity sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==

cleaner-config@^0.1.9:
version "0.1.9"
resolved "https://registry.yarnpkg.com/cleaner-config/-/cleaner-config-0.1.9.tgz#cf44f92b7c0d6ce01268b526fd108b50ed8777a1"
integrity sha512-hcojU0ppPMDBC65c1VBb1yyPgHg6fdZWJAOhbEPQscye2aidNQN3LtfKLnTS5hJVv/70X6fk5ZuPnMWZYCFasA==
dependencies:
cleaners "^0.3.8"
minimist "^1.2.5"
sucrase "^3.17.1"

cleaners@^0.3.13:
version "0.3.13"
resolved "https://registry.npmjs.org/cleaners/-/cleaners-0.3.13.tgz"
integrity sha512-sCedc8LIXUhLmXT9rkkAToi9mjYhI7J/gKRWiF0Qw6eC0ymILHxq+vhuaKoKdcSWpYi2YqqwSlvNtD+92gf4pA==

cleaners@^0.3.8:
version "0.3.16"
resolved "https://registry.yarnpkg.com/cleaners/-/cleaners-0.3.16.tgz#d3a7ab936cb78b0d6ac19ba87b2d28ec41f30502"
integrity sha512-Ecu8Fwv3wT7GV44K4Zas2CQJI11ZV/yPwoh8Gg9BSV6rAmhNsqFeWceA1RII1czbarFSG3XClUePrpI806OvRw==

cli-cursor@^3.1.0:
version "3.1.0"
resolved "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz"
Expand Down Expand Up @@ -6286,6 +6309,19 @@ [email protected], strip-json-comments@^3.1.0, strip-json-comments@^3.1.
resolved "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz"
integrity sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==

sucrase@^3.17.1:
version "3.34.0"
resolved "https://registry.yarnpkg.com/sucrase/-/sucrase-3.34.0.tgz#1e0e2d8fcf07f8b9c3569067d92fbd8690fb576f"
integrity sha512-70/LQEZ07TEcxiU2dz51FKaE6hCTWC6vr7FOk3Gr0U60C3shtAN+H+BFr9XlYe5xqf3RA8nrc+VIwzCfnxuXJw==
dependencies:
"@jridgewell/gen-mapping" "^0.3.2"
commander "^4.0.0"
glob "7.1.6"
lines-and-columns "^1.1.6"
mz "^2.7.0"
pirates "^4.0.1"
ts-interface-checker "^0.1.9"

sucrase@^3.20.0:
version "3.20.0"
resolved "https://registry.npmjs.org/sucrase/-/sucrase-3.20.0.tgz"
Expand Down

0 comments on commit 0a0f9eb

Please sign in to comment.