| 20 | * without additional plumbing |
| 21 | */ |
| 22 | export class SessionMiddlewareFactory { |
| 23 | #config: Partial<SessionConfig> & { |
| 24 | store: string |
| 25 | stores: Record<string, SessionStoreFactory> |
| 26 | } = { |
| 27 | store: 'memory', |
| 28 | stores: {}, |
| 29 | } |
| 30 | |
| 31 | #emitter?: Emitter<EventsList> |
| 32 | |
| 33 | #getApp() { |
| 34 | return new AppFactory().create(new URL('./', import.meta.url), () => {}) as ApplicationService |
| 35 | } |
| 36 | |
| 37 | #getEmitter() { |
| 38 | return this.#emitter || new Emitter<EventsList>(this.#getApp()) |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Merge custom options |
| 43 | */ |
| 44 | merge(options: { |
| 45 | config?: Partial<SessionConfig> & { |
| 46 | store: string |
| 47 | stores: Record<string, SessionStoreFactory> |
| 48 | } |
| 49 | emitter?: Emitter<EventsList> |
| 50 | }) { |
| 51 | if (options.config) { |
| 52 | this.#config = options.config |
| 53 | } |
| 54 | |
| 55 | if (options.emitter) { |
| 56 | this.#emitter = options.emitter |
| 57 | } |
| 58 | |
| 59 | return this |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Creates an instance of the session middleware |
| 64 | */ |
| 65 | async create() { |
| 66 | const config = await defineConfig(this.#config).resolver(this.#getApp()) |
| 67 | return new SessionMiddleware(config, this.#getEmitter()) |
| 68 | } |
| 69 | } |
nothing calls this directly
no outgoing calls
no test coverage detected