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.
lib/src/http/session/SessionFactory.ts

50 lines
1.7 KiB

import {
AbstractFactory,
Container,
DependencyRequirement,
PropertyDependency,
DEPENDENCY_KEYS_METADATA_KEY,
DEPENDENCY_KEYS_PROPERTY_METADATA_KEY
} from "@extollo/di"
import {Collection} from "@extollo/util"
import {MemorySession} from "./MemorySession";
import {Session} from "./Session";
import {Logging} from "../../service/Logging";
export class SessionFactory extends AbstractFactory {
protected readonly logging: Logging
constructor() {
super({})
this.logging = Container.getContainer().make<Logging>(Logging)
}
produce(dependencies: any[], parameters: any[]): any {
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
}
match(something: any) {
return something === Session
}
getDependencyKeys(): Collection<DependencyRequirement> {
const meta = Reflect.getMetadata(DEPENDENCY_KEYS_METADATA_KEY, this.token)
if ( meta ) return meta
return new Collection<DependencyRequirement>()
}
getInjectedProperties(): Collection<PropertyDependency> {
const meta = new Collection<PropertyDependency>()
let currentToken = MemorySession // FIXME allow configuring
do {
const loadedMeta = Reflect.getMetadata(DEPENDENCY_KEYS_PROPERTY_METADATA_KEY, currentToken)
if ( loadedMeta ) meta.concat(loadedMeta)
currentToken = Object.getPrototypeOf(currentToken)
} while (Object.getPrototypeOf(currentToken) !== Function.prototype && Object.getPrototypeOf(currentToken) !== Object.prototype)
return meta
}
}