Home / Function/ AstroSession() — astro Function Reference

AstroSession() — astro Function Reference

Architecture documentation for the AstroSession() function in runtime.ts from the astro codebase.

Entity Profile

Dependency Diagram

graph TD
  6a37e7b5_7d47_0edc_22a0_f1b1f4a991bb["AstroSession()"]
  91969197_292d_3b15_21c6_0e876968e961["AstroSession"]
  6a37e7b5_7d47_0edc_22a0_f1b1f4a991bb -->|defined in| 91969197_292d_3b15_21c6_0e876968e961
  8a9e92da_c3c2_384b_2d6b_b1eec8e95109["has()"]
  6a37e7b5_7d47_0edc_22a0_f1b1f4a991bb -->|calls| 8a9e92da_c3c2_384b_2d6b_b1eec8e95109
  f7f62311_5ea1_d1da_6248_79ef0fe49f0e["get()"]
  6a37e7b5_7d47_0edc_22a0_f1b1f4a991bb -->|calls| f7f62311_5ea1_d1da_6248_79ef0fe49f0e
  59668aee_368a_2af5_a60c_273e7404dc42["set()"]
  6a37e7b5_7d47_0edc_22a0_f1b1f4a991bb -->|calls| 59668aee_368a_2af5_a60c_273e7404dc42
  style 6a37e7b5_7d47_0edc_22a0_f1b1f4a991bb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/astro/src/core/session/runtime.ts lines 414–464

	async #ensureStorage(): Promise<Storage> {
		if (this.#storage) {
			return this.#storage;
		}

		// We reuse the storage object if it has already been created.
		// We don't need to worry about the config changing because editing it
		// will always restart the process.
		if (AstroSession.#sharedStorage.has(this.#config.driver)) {
			this.#storage = AstroSession.#sharedStorage.get(this.#config.driver);
			return this.#storage!;
		}

		// Get the driver factory from the pipeline
		if (!this.#driverFactory) {
			throw new AstroError({
				...SessionStorageInitError,
				message: SessionStorageInitError.message(
					'Astro could not load the driver correctly. Does it exist?',
					this.#config.driver,
				),
			});
		}

		const driver = this.#driverFactory;

		try {
			this.#storage = createStorage({
				driver: {
					...driver(this.#config.options),
					// Unused methods
					hasItem() {
						return false;
					},
					getKeys() {
						return [];
					},
				},
			});
			AstroSession.#sharedStorage.set(this.#config.driver, this.#storage);
			return this.#storage;
		} catch (err) {
			throw new AstroError(
				{
					...SessionStorageInitError,
					message: SessionStorageInitError.message('Unknown error', this.#config.driver),
				},
				{ cause: err },
			);
		}
	}

Domain

Subdomains

Frequently Asked Questions

What does AstroSession() do?
AstroSession() is a function 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 414.
What does AstroSession() call?
AstroSession() calls 3 function(s): get, has, set.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free