UNPKG

dt-app

Version:

The Dynatrace App Toolkit is a tool you can use from your command line to create, develop, and deploy apps on your Dynatrace environment.

42 lines (41 loc) 1.67 kB
import type { DtAppPlugin } from './plugin'; import type { BeforeBuildHook, Hook, BeforeServeHook, BeforeBuildCallback, BeforeServeCallBack, NamedCallBackHook, CallBack } from './hooks'; /** * This specifies types that are used to allow type-safe invocation of the * plugins. Background: Different hooks provide different objects for the plugin. * E.g.: The 'before-serve' hook provides a fastify instance - 'before-build' obviously doesn't. * To take care of that, the HookMapTranslator type is used to enforce providing the correct * objects when executing the hook. E.g. when calling pluginProvider.run('before-serve', [...]) you * will need to provide the fastify instance in the argument array. */ type HookMap = { [key in Hook]: NamedCallBackHook<CallBack>[]; }; type HookMapTranslator<T extends Hook> = T extends BeforeBuildHook ? BeforeBuildCallback : T extends BeforeServeHook ? BeforeServeCallBack : never; /** * Run all registered plugins for a hook. */ declare function invoke<T extends Hook>(hook: T, args: Required<Parameters<HookMapTranslator<T>>>): Promise<void>; /** * Register a plugin. * * @param plugin the plugin that should be registered. */ declare function register(plugin: DtAppPlugin): void; /** * Register multiple plugins. * * @param pluginArray the plugins that should be registered. */ declare function registerAll(pluginArray: DtAppPlugin[]): void; /** * A singleton that holds a private state and exposes * functions that can be used. */ export declare const pluginProvider: { registeredHooks: HookMap; register: typeof register; registerAll: typeof registerAll; invoke: typeof invoke; }; export {};