knifecycle icon indicating copy to clipboard operation
knifecycle copied to clipboard

Consider using an overridable `Services` interface

Open nfroidure opened this issue 2 years ago • 0 comments

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).

nfroidure avatar Aug 13 '23 05:08 nfroidure