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 */ protected readonly ModelClass: StaticClass, ) { super() } produce(dependencies: any[], parameters: any[]): SessionInterface { if ( isInstantiable(this.ModelClass) ) return new this.ModelClass() as SessionInterface else throw new TypeError(`Session model class ${this.ModelClass} is not instantiable.`) } }