| 32 | }; |
| 33 | |
| 34 | export class AstroSession { |
| 35 | // The cookies object. |
| 36 | #cookies: AstroCookies; |
| 37 | // The session configuration. |
| 38 | #config: Omit<SSRManifestSession, 'cookie'>; |
| 39 | // The cookie config |
| 40 | #cookieConfig?: AstroCookieSetOptions; |
| 41 | // The cookie name |
| 42 | #cookieName: string; |
| 43 | // The unstorage object for the session driver. |
| 44 | #storage: Storage | undefined; |
| 45 | #data: Map<string, SessionEntry> | undefined; |
| 46 | // The session ID. A v4 UUID. |
| 47 | #sessionID: string | undefined; |
| 48 | // Sessions to destroy. Needed because we won't have the old session ID after it's destroyed locally. |
| 49 | #toDestroy = new Set<string>(); |
| 50 | // Session keys to delete. Used for partial data sets to avoid overwriting the deleted value. |
| 51 | #toDelete = new Set<string>(); |
| 52 | // Whether the session is dirty and needs to be saved. |
| 53 | #dirty = false; |
| 54 | // Whether the session cookie has been set. |
| 55 | #cookieSet = false; |
| 56 | // Whether the session ID was sourced from a client cookie rather than freshly generated. |
| 57 | #sessionIDFromCookie = false; |
| 58 | // The local data is "partial" if it has not been loaded from storage yet and only |
| 59 | // contains values that have been set or deleted in-memory locally. |
| 60 | // We do this to avoid the need to block on loading data when it is only being set. |
| 61 | // When we load the data from storage, we need to merge it with the local partial data, |
| 62 | // preserving in-memory changes and deletions. |
| 63 | #partial = true; |
| 64 | // The driver factory function provided by the pipeline |
| 65 | #driverFactory: SessionDriverFactory | null; |
| 66 | |
| 67 | static #sharedStorage = new Map<string, Storage>(); |
| 68 | |
| 69 | constructor({ |
| 70 | cookies, |
| 71 | config, |
| 72 | runtimeMode, |
| 73 | driverFactory, |
| 74 | mockStorage, |
| 75 | }: { |
| 76 | cookies: AstroCookies; |
| 77 | config: SSRManifestSession | undefined; |
| 78 | runtimeMode: RuntimeMode; |
| 79 | driverFactory: SessionDriverFactory | null; |
| 80 | mockStorage: Storage | null; |
| 81 | }) { |
| 82 | if (!config) { |
| 83 | throw new AstroError({ |
| 84 | ...SessionStorageInitError, |
| 85 | message: SessionStorageInitError.message( |
| 86 | 'No driver was defined in the session configuration and the adapter did not provide a default driver.', |
| 87 | ), |
| 88 | }); |
| 89 | } |
| 90 | this.#cookies = cookies; |
| 91 | this.#driverFactory = driverFactory; |
nothing calls this directly
no outgoing calls
no test coverage detected