0.2.4 • Published 2 years ago

@gallofeliz/application v0.2.4

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Application

npm.io

Note: This module is part of @gallofeliz/js-libs that is a personal project. It is not developed nor tested for applications that need high security or scalability.

Application runner:

  • Easy Dependencies injection
  • Kill signal catched and converted to abortSignal
  • Structured
  • Built-in config (load from files, envs, validation, watches, etc) and logger
import { runApp } from '@gallofeliz/application'

// ...

runApp<Config>({
    name: '@gallofeliz/Pikatchu',
    config: {
        watchChanges: true,
        userProvidedConfigSchema: tsToJsSchema<UserConfig>()
    },
    services: {
        userService({logger, db}): UserService {
            return new UserService(logger, db)
        },
        db({config, configWatcher}): Db {
            const db = new Db(config.dbPath)

            configWatcher.on('change:dbPath', ({value}) => db.setPath(value as string))

            return db
        }
    },
    async run({userService, logger, abortSignal, abortController}) {
        userService.doAJob()
        let st: NodeJS.Timeout

        abortSignal.addEventListener('abort', () => {
            clearTimeout(st)
            console.log('clean')
            userService.clean()
            resolve(undefined)
        })

        await new Promise(resolve => st = setTimeout(resolve, 5000))

        abortController.abort()
    }
})
0.2.4

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.2.3

2 years ago

0.2.2

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago