Fix issue where WebSocketBus depends on Session before session factory registered

This commit is contained in:
Garrett Mills 2022-08-09 23:59:43 -05:00
parent e339ec718d
commit 085fe04f90
2 changed files with 10 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@extollo/lib", "name": "@extollo/lib",
"version": "0.13.7", "version": "0.13.8",
"description": "The framework library that lifts up your code.", "description": "The framework library that lifts up your code.",
"main": "lib/index.js", "main": "lib/index.js",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",

View File

@ -19,6 +19,7 @@ import {AsyncResource, executionAsyncId} from 'async_hooks'
import {Session} from '../../http/session/Session' import {Session} from '../../http/session/Session'
import {Config} from '../../service/Config' import {Config} from '../../service/Config'
import {WebSocketHealthCheckEvent} from '../../http/lifecycle/WebSocketHealthCheckEvent' import {WebSocketHealthCheckEvent} from '../../http/lifecycle/WebSocketHealthCheckEvent'
import {Request} from '../../http/lifecycle/Request'
@Injectable() @Injectable()
export class WebSocketBus implements EventBus, AwareOfContainerLifecycle { export class WebSocketBus implements EventBus, AwareOfContainerLifecycle {
@ -40,6 +41,9 @@ export class WebSocketBus implements EventBus, AwareOfContainerLifecycle {
@Inject() @Inject()
protected readonly ws!: WebSocket.WebSocket protected readonly ws!: WebSocket.WebSocket
@Inject()
protected readonly request!: Request
@Inject() @Inject()
protected readonly bus!: Bus protected readonly bus!: Bus
@ -49,9 +53,6 @@ export class WebSocketBus implements EventBus, AwareOfContainerLifecycle {
@Inject() @Inject()
protected readonly logging!: Logging protected readonly logging!: Logging
@Inject()
protected readonly session!: Session
@Inject() @Inject()
protected readonly config!: Config protected readonly config!: Config
@ -118,15 +119,16 @@ export class WebSocketBus implements EventBus, AwareOfContainerLifecycle {
// If configured, re-load the session data since it may have changed outside the // If configured, re-load the session data since it may have changed outside the
// current socket's request. // current socket's request.
if ( this.shouldLoadSessionOnEvent && listeners.isNotEmpty() ) { const session = this.request.hasKey(Session) ? this.request.make<Session>(Session) : undefined
await this.session.load() if ( this.shouldLoadSessionOnEvent && session && listeners.isNotEmpty() ) {
await session.load()
} }
await listeners.awaitMapCall('handler', payload) await listeners.awaitMapCall('handler', payload)
// Persist any changes to the session for other requests. // Persist any changes to the session for other requests.
if ( this.shouldLoadSessionOnEvent && listeners.isNotEmpty() ) { if ( this.shouldLoadSessionOnEvent && session && listeners.isNotEmpty() ) {
await this.session.persist() await session.persist()
} }
} }