| 36 | * ``` |
| 37 | */ |
| 38 | export class SessionCollection { |
| 39 | #config: ResolvedSessionConfig |
| 40 | |
| 41 | /** |
| 42 | * Creates a new SessionCollection instance |
| 43 | * |
| 44 | * @param config - Resolved session configuration |
| 45 | */ |
| 46 | constructor(config: ResolvedSessionConfig) { |
| 47 | this.#config = config |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * A store serves one request and remembers the sessions it read. |
| 52 | * The collection is a singleton, so each operation gets a new store. |
| 53 | */ |
| 54 | get #store(): SessionStoreWithTaggingContract { |
| 55 | const storeFactory = this.#config.stores[this.#config.store] |
| 56 | return storeFactory(null as any, this.#config) as SessionStoreWithTaggingContract |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Checks if the current store supports session tagging. |
| 61 | * Only Memory, Redis, and Database stores support tagging. |
| 62 | * |
| 63 | * @example |
| 64 | * const collection = await app.container.make(SessionCollection) |
| 65 | * if (collection.supportsTagging()) { |
| 66 | * await collection.tag(sessionId, userId) |
| 67 | * } |
| 68 | */ |
| 69 | supportsTagging(): boolean { |
| 70 | return 'tag' in this.#store && 'tagged' in this.#store |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Returns the session data for the given session ID, |
| 75 | * or null if the session does not exist |
| 76 | * |
| 77 | * @param sessionId - Session identifier |
| 78 | * |
| 79 | * @example |
| 80 | * const data = await sessionCollection.get('sess_abc123') |
| 81 | */ |
| 82 | async get(sessionId: string): Promise<SessionData | null> { |
| 83 | debug('session collection: getting session data %s', sessionId) |
| 84 | return this.#store.read(sessionId) |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Destroys a session by its ID |
| 89 | * |
| 90 | * @param sessionId - Session identifier |
| 91 | * |
| 92 | * @example |
| 93 | * await sessionCollection.destroy('sess_abc123') |
| 94 | */ |
| 95 | async destroy(sessionId: string): Promise<void> { |
nothing calls this directly
no outgoing calls
no test coverage detected