You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
1009 B
34 lines
1009 B
3 years ago
|
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))
|
||
|
}
|
||
|
}
|
||
|
}
|