nfroidure / nfroidure/knifecycle

Consider using an overridable `Services` interface

Open
#125 0 comments 0 reactions 1 assignee View on GitHub

@nfroidure is already working on this.

Since Aug 13, 2023.

enhancement
Dominant language
TypeScript
Stars
34
Forks
0
PR merge metrics
No merged PRs in 30d

Description

In order to allow users to override it and get auto-completion for services injections, a global Services interface mapping to all services types could be useful.

It would give something like services.d.ts in the root of projects sources:

import type { BaseServices } from 'knifecycle'; // For injector/instance etc...

declare module 'knifecycle' {
  // Eventually override the process env type here
  export interface Services
    extends Services {
      pg: PGService;
      log: LogService;
      // ...
  }

Maybe that using this could help: https://www.typescriptlang.org/docs/handbook/declaration-merging.html

The $autoload service type could be changed to :

{
  get: (serviceName) => Initializer
  list: () => Initializer[]
}

That way the whook-repl / whook create command could suggest new services to use.

Also, would be nice to add a special property to set the import.meta.url value of modules so that the build can refer to it (will avoid the need to use the INITIALIZER_PATH_MAP in the whook autoload service).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.