Add mechanism for NPM package auto-discovery
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-07-02 21:45:15 -05:00
parent 5d960e6186
commit b3b5b169e8
6 changed files with 204 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
import {Event} from '../event/Event'
import {Awaitable, JSONState, UniversalPath} from '../util'
import {ExtolloAwareNodeModule} from './types'
/**
* An event indicating that an NPM package has been discovered
* by the framework.
*
* Application services can listen for this event to register
* various discovery logic (e.g. automatically boot units
*/
export class PackageDiscovered extends Event {
constructor(
public packageConfig: ExtolloAwareNodeModule,
public packageJson: UniversalPath,
) {
super()
}
dehydrate(): Awaitable<JSONState> {
return {
packageConfig: this.packageConfig as JSONState,
packageJson: this.packageJson.toString(),
}
}
rehydrate(state: JSONState): Awaitable<void> {
if ( typeof state === 'object' ) {
this.packageConfig = (state.packageConfig as ExtolloAwareNodeModule)
this.packageJson = new UniversalPath(String(state.packageJson))
}
}
}