AstroSession Class — astro Architecture
Architecture documentation for the AstroSession class in runtime.ts from the astro codebase.
Entity Profile
Dependency Diagram
graph TD 91969197_292d_3b15_21c6_0e876968e961["AstroSession"] 230f9fcd_500c_0a2e_2316_14bb85a1e99e["runtime.ts"] 91969197_292d_3b15_21c6_0e876968e961 -->|defined in| 230f9fcd_500c_0a2e_2316_14bb85a1e99e 41e87dd5_f04f_80e3_ba9e_0d578121251a["constructor()"] 91969197_292d_3b15_21c6_0e876968e961 -->|method| 41e87dd5_f04f_80e3_ba9e_0d578121251a f7f62311_5ea1_d1da_6248_79ef0fe49f0e["get()"] 91969197_292d_3b15_21c6_0e876968e961 -->|method| f7f62311_5ea1_d1da_6248_79ef0fe49f0e 8a9e92da_c3c2_384b_2d6b_b1eec8e95109["has()"] 91969197_292d_3b15_21c6_0e876968e961 -->|method| 8a9e92da_c3c2_384b_2d6b_b1eec8e95109 a59bd5c9_c130_5de2_852f_51fe9e1b0c05["keys()"] 91969197_292d_3b15_21c6_0e876968e961 -->|method| a59bd5c9_c130_5de2_852f_51fe9e1b0c05 10e657ea_3b1b_67af_5344_a5cb79a31b06["values()"] 91969197_292d_3b15_21c6_0e876968e961 -->|method| 10e657ea_3b1b_67af_5344_a5cb79a31b06 02110af4_6f1f_4e17_2fc7_b852043746bd["entries()"] 91969197_292d_3b15_21c6_0e876968e961 -->|method| 02110af4_6f1f_4e17_2fc7_b852043746bd a93368a8_9e65_389c_49b5_51ca39cf4736["delete()"] 91969197_292d_3b15_21c6_0e876968e961 -->|method| a93368a8_9e65_389c_49b5_51ca39cf4736 59668aee_368a_2af5_a60c_273e7404dc42["set()"] 91969197_292d_3b15_21c6_0e876968e961 -->|method| 59668aee_368a_2af5_a60c_273e7404dc42 5c79ae32_65c5_f84c_14bd_7780a03d5e74["destroy()"] 91969197_292d_3b15_21c6_0e876968e961 -->|method| 5c79ae32_65c5_f84c_14bd_7780a03d5e74 e8e68a78_d5fe_8e2a_3ab9_01e62691a6d5["regenerate()"] 91969197_292d_3b15_21c6_0e876968e961 -->|method| e8e68a78_d5fe_8e2a_3ab9_01e62691a6d5 c5fcfb22_1acd_7d18_d142_3d656d477a03["PERSIST_SYMBOL()"] 91969197_292d_3b15_21c6_0e876968e961 -->|method| c5fcfb22_1acd_7d18_d142_3d656d477a03 28ee3aa9_7a7d_5a55_433c_75b3c181f59e["sessionID()"] 91969197_292d_3b15_21c6_0e876968e961 -->|method| 28ee3aa9_7a7d_5a55_433c_75b3c181f59e 05c99671_b865_b426_cd4b_48a29689bac6["load()"] 91969197_292d_3b15_21c6_0e876968e961 -->|method| 05c99671_b865_b426_cd4b_48a29689bac6
Relationship Graph
Source Code
packages/astro/src/core/session/runtime.ts lines 34–465
export class AstroSession {
// The cookies object.
#cookies: AstroCookies;
// The session configuration.
#config: Omit<SSRManifestSession, 'cookie'>;
// The cookie config
#cookieConfig?: AstroCookieSetOptions;
// The cookie name
#cookieName: string;
// The unstorage object for the session driver.
#storage: Storage | undefined;
#data: Map<string, SessionEntry> | undefined;
// The session ID. A v4 UUID.
#sessionID: string | undefined;
// Sessions to destroy. Needed because we won't have the old session ID after it's destroyed locally.
#toDestroy = new Set<string>();
// Session keys to delete. Used for partial data sets to avoid overwriting the deleted value.
#toDelete = new Set<string>();
// Whether the session is dirty and needs to be saved.
#dirty = false;
// Whether the session cookie has been set.
#cookieSet = false;
// The local data is "partial" if it has not been loaded from storage yet and only
// contains values that have been set or deleted in-memory locally.
// We do this to avoid the need to block on loading data when it is only being set.
// When we load the data from storage, we need to merge it with the local partial data,
// preserving in-memory changes and deletions.
#partial = true;
// The driver factory function provided by the pipeline
#driverFactory: SessionDriverFactory | null;
static #sharedStorage = new Map<string, Storage>();
constructor({
cookies,
config,
runtimeMode,
driverFactory,
mockStorage,
}: {
cookies: AstroCookies;
config: SSRManifestSession | undefined;
runtimeMode: RuntimeMode;
driverFactory: SessionDriverFactory | null;
mockStorage: Storage | null;
}) {
if (!config) {
throw new AstroError({
...SessionStorageInitError,
message: SessionStorageInitError.message(
'No driver was defined in the session configuration and the adapter did not provide a default driver.',
),
});
}
this.#cookies = cookies;
this.#driverFactory = driverFactory;
const { cookie: cookieConfig = DEFAULT_COOKIE_NAME, ...configRest } = config;
let cookieConfigObject: AstroCookieSetOptions | undefined;
if (typeof cookieConfig === 'object') {
const { name = DEFAULT_COOKIE_NAME, ...rest } = cookieConfig;
this.#cookieName = name;
cookieConfigObject = rest;
} else {
this.#cookieName = cookieConfig || DEFAULT_COOKIE_NAME;
}
this.#cookieConfig = {
sameSite: 'lax',
secure: runtimeMode === 'production',
path: '/',
...cookieConfigObject,
httpOnly: true,
};
this.#config = configRest;
if (mockStorage) {
this.#storage = mockStorage;
}
}
/**
* Gets a session value. Returns `undefined` if the session or value does not exist.
*/
Domain
Defined In
Source
Frequently Asked Questions
What is the AstroSession class?
AstroSession is a class in the astro codebase, defined in packages/astro/src/core/session/runtime.ts.
Where is AstroSession defined?
AstroSession is defined in packages/astro/src/core/session/runtime.ts at line 34.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free