Add mounting for activated routes, route compiling, routing
This commit is contained in:
@@ -3,25 +3,29 @@ import {
|
||||
Container,
|
||||
DependencyRequirement,
|
||||
PropertyDependency,
|
||||
isInstantiable,
|
||||
DEPENDENCY_KEYS_METADATA_KEY,
|
||||
DEPENDENCY_KEYS_PROPERTY_METADATA_KEY
|
||||
} from "@extollo/di"
|
||||
import {Collection} from "@extollo/util"
|
||||
import {Collection, ErrorWithContext} from "@extollo/util"
|
||||
import {MemorySession} from "./MemorySession";
|
||||
import {Session} from "./Session";
|
||||
import {Logging} from "../../service/Logging";
|
||||
import {Config} from "../../service/Config";
|
||||
|
||||
export class SessionFactory extends AbstractFactory {
|
||||
protected readonly logging: Logging
|
||||
protected readonly config: Config
|
||||
|
||||
constructor() {
|
||||
super({})
|
||||
this.logging = Container.getContainer().make<Logging>(Logging)
|
||||
this.config = Container.getContainer().make<Config>(Config)
|
||||
}
|
||||
|
||||
produce(dependencies: any[], parameters: any[]): any {
|
||||
produce(dependencies: any[], parameters: any[]): Session {
|
||||
this.logging.warn(`You are using the default memory-based session driver. It is recommended you configure a persistent session driver instead.`)
|
||||
return new MemorySession() // FIXME allow configuring
|
||||
return new (this.getSessionClass())
|
||||
}
|
||||
|
||||
match(something: any) {
|
||||
@@ -29,14 +33,14 @@ export class SessionFactory extends AbstractFactory {
|
||||
}
|
||||
|
||||
getDependencyKeys(): Collection<DependencyRequirement> {
|
||||
const meta = Reflect.getMetadata(DEPENDENCY_KEYS_METADATA_KEY, this.token)
|
||||
const meta = Reflect.getMetadata(DEPENDENCY_KEYS_METADATA_KEY, this.getSessionClass())
|
||||
if ( meta ) return meta
|
||||
return new Collection<DependencyRequirement>()
|
||||
}
|
||||
|
||||
getInjectedProperties(): Collection<PropertyDependency> {
|
||||
const meta = new Collection<PropertyDependency>()
|
||||
let currentToken = MemorySession // FIXME allow configuring
|
||||
let currentToken = this.getSessionClass()
|
||||
|
||||
do {
|
||||
const loadedMeta = Reflect.getMetadata(DEPENDENCY_KEYS_PROPERTY_METADATA_KEY, currentToken)
|
||||
@@ -46,4 +50,19 @@ export class SessionFactory extends AbstractFactory {
|
||||
|
||||
return meta
|
||||
}
|
||||
|
||||
protected getSessionClass() {
|
||||
const SessionClass = this.config.get('server.session.driver', MemorySession)
|
||||
|
||||
// TODO check that session class is valid
|
||||
if ( !isInstantiable(SessionClass) || !(SessionClass.prototype instanceof Session) ) {
|
||||
const e = new ErrorWithContext('Provided session class does not extend from @extollo/lib.Session');
|
||||
e.context = {
|
||||
config_key: 'server.session.driver',
|
||||
class: SessionClass.toString(),
|
||||
}
|
||||
}
|
||||
|
||||
return SessionClass
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user