@aliksend/module
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

modules-for-services

Used to declare modules in your services

Usage example:

// db/knex.ts
const m = Module.declare('knex', 'input', {
  configSchema: z.object({}).passthrough(),
  startArg: null,
  start: async (config, startArg) => {
    return knex(config)
  },
  stop: async (db) => {
    await db.destroy()
  },
})

// now you can use `m`, even while module isn't started
// you can use `m.value` in http-handlers that will be called after module is started

// then you can call `startAll` with config to start all modules, declared in your service
await Module.startAll({
  db: {
    client: 'pg',
    connection: 'TODO'
  }
})

Readme

Keywords

Package Sidebar

Install

npm i @aliksend/module

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

36.3 kB

Total Files

19

Last publish

Collaborators

  • aliksend