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.
29 lines
1.0 KiB
29 lines
1.0 KiB
import SessionFactory from './SessionFactory.ts'
|
|
import SessionInterface from './SessionInterface.ts'
|
|
import {Model} from '../../../../orm/src/model/Model.ts'
|
|
import {StaticClass} from '../../../../di/src/type/StaticClass.ts'
|
|
import {isInstantiable} from '../../../../di/src/type/Instantiable.ts'
|
|
|
|
/**
|
|
* Session factory that builds an ORM model-based session factory.
|
|
* @extends SessionFactory
|
|
*/
|
|
export default class ModelSessionFactory extends SessionFactory {
|
|
constructor(
|
|
/**
|
|
* The base model to use for sessions.
|
|
* @type StaticClass<SessionInterface, typeof Model>
|
|
*/
|
|
protected readonly ModelClass: StaticClass<SessionInterface, typeof Model>,
|
|
) {
|
|
super()
|
|
}
|
|
|
|
produce(dependencies: any[], parameters: any[]): SessionInterface {
|
|
if ( isInstantiable<SessionInterface>(this.ModelClass) )
|
|
return new this.ModelClass() as SessionInterface
|
|
else
|
|
throw new TypeError(`Session model class ${this.ModelClass} is not instantiable.`)
|
|
}
|
|
}
|