Skip to content
This repository has been archived by the owner on May 19, 2023. It is now read-only.

Commit

Permalink
feat: improved conf store
Browse files Browse the repository at this point in the history
  • Loading branch information
AuHau committed Feb 25, 2020
1 parent f193e71 commit a74baa9
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 14 deletions.
8 changes: 5 additions & 3 deletions config/default.json5
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
filter: null,
path: null
},

// Specifies if configuration using Conf() should be persisted between restarts
persistConf: true,
conf: {
name: 'config',
// Specifies if configuration using Conf() should be persisted between restarts
persist: true
},

// Settings for blockchain related function
blockchain: {
Expand Down
5 changes: 4 additions & 1 deletion config/development.json5
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
host: "localhost",
port: 3030,
persistConf: false,
conf: {
name: 'dev-config',
persist: true
},
db: {
dialect: "postgres",
host: "localhost",
Expand Down
4 changes: 2 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import services from './services'
import appHooks from './app.hooks'
import sequelize from './sequelize'
import blockchain from './blockchain/'
import conf from './conf'
import { configure as confConfigure } from './conf'
// Don't remove this comment. It's needed to format import lines nicely.

const app: Application = express(feathers())
Expand All @@ -30,7 +30,7 @@ app.configure(express.rest())
app.configure(socketio())

app.configure(sequelize)
app.configure(conf)
app.configure(confConfigure)

// Configure other middleware (see `middleware/index.js`)
app.configure(middleware)
Expand Down
6 changes: 3 additions & 3 deletions src/blockchain/events.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Contract, EventData } from 'web3-eth-contract'
import { BlockHeader, Eth } from 'web3-eth'
import { Subscription } from 'web3-core-subscriptions'
import Conf from 'conf'
import confFactory from '../conf'
import config from 'config'
import { EventEmitter } from 'events'
import { NotImplemented } from '@feathersjs/errors'
Expand Down Expand Up @@ -177,11 +177,11 @@ abstract class BaseEventsEmitter extends AutoStartStopEventEmitter {
if (options.blockTracker instanceof BlockTracker) {
this.blockTracker = options.blockTracker
} else {
const confStore = options.blockTracker.store || new Conf()
const confStore = options.blockTracker.store || confFactory()
this.blockTracker = new BlockTracker(confStore)
}
} else {
this.blockTracker = new BlockTracker(new Conf())
this.blockTracker = new BlockTracker(confFactory())
}

if (options?.newBlockEmitter) {
Expand Down
41 changes: 36 additions & 5 deletions src/conf.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,44 @@
import { Application } from './declarations'
import config from 'config'
import Conf from 'conf'
import { factory } from './logger'
import { factory as logFactory } from './logger'

const logger = factory('conf')
const logger = logFactory('conf')

export default function conf (app: Application): void {
if (!config.get('persistConf')) {
export interface ConfOptions {
host: string
port: number
log?: {
level?: string
filter?: string
path?: string
}
blockchain: {
provider: string
pinningContractAddress: string
startingBlock: string | number
eventsEmitter?: {
polling: boolean
pollingInterval?: number
confirmations?: number
}
}
newBlockEmitter: {
polling: boolean
pollingInterval?: number
}
}

export default function factory (): Conf {
const configName = config.get<string>('conf.name')

return new Conf<ConfOptions>({ configName })
}

export function configure (app: Application): void {
if (!config.get('conf.persist')) {
logger.info('Clearing all persisted configuration.')
new Conf().clear()

factory().clear()
}
}

0 comments on commit a74baa9

Please sign in to comment.