Home / File/ runtime.ts — astro Source File

runtime.ts — astro Source File

Architecture documentation for runtime.ts, a typescript file in the astro codebase. 8 imports, 0 dependents.

File typescript CoreAstro RenderingEngine 8 imports 2 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  230f9fcd_500c_0a2e_2316_14bb85a1e99e["runtime.ts"]
  c32d12e2_d85e_28c0_eea7_9b29629857e0["../types/public/config.js"]
  230f9fcd_500c_0a2e_2316_14bb85a1e99e --> c32d12e2_d85e_28c0_eea7_9b29629857e0
  5799bf2d_d18e_6c2e_364a_a825ef7f6e79["../../core/cookies/cookies.js"]
  230f9fcd_500c_0a2e_2316_14bb85a1e99e --> 5799bf2d_d18e_6c2e_364a_a825ef7f6e79
  8df634da_0f30_1e1f_1314_2439b0c9baab["../core/errors/errors-data.js"]
  230f9fcd_500c_0a2e_2316_14bb85a1e99e --> 8df634da_0f30_1e1f_1314_2439b0c9baab
  ef8a1e3f_e350_75a6_b92d_62a8566d8db9["../core/errors/index.js"]
  230f9fcd_500c_0a2e_2316_14bb85a1e99e --> ef8a1e3f_e350_75a6_b92d_62a8566d8db9
  e6591dc4_f998_7dbc_3c66_06ac5ec7fba0["../../core/session/types.js"]
  230f9fcd_500c_0a2e_2316_14bb85a1e99e --> e6591dc4_f998_7dbc_3c66_06ac5ec7fba0
  a4f2698c_5256_262a_ba7c_f72b51878d10["../core/app/types.js"]
  230f9fcd_500c_0a2e_2316_14bb85a1e99e --> a4f2698c_5256_262a_ba7c_f72b51878d10
  ca52ff61_c81f_c2ca_81b6_5a678b65fd31["devalue"]
  230f9fcd_500c_0a2e_2316_14bb85a1e99e --> ca52ff61_c81f_c2ca_81b6_5a678b65fd31
  a56f5589_e3c3_ced2_bdd4_5ad39a3cb093["unstorage"]
  230f9fcd_500c_0a2e_2316_14bb85a1e99e --> a56f5589_e3c3_ced2_bdd4_5ad39a3cb093
  style 230f9fcd_500c_0a2e_2316_14bb85a1e99e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { stringify as rawStringify, unflatten as rawUnflatten } from 'devalue';
import type { RuntimeMode } from '../../types/public/config.js';
import type { AstroCookieSetOptions, AstroCookies } from '../cookies/cookies.js';
import { SessionStorageInitError, SessionStorageSaveError } from '../errors/errors-data.js';
import { AstroError } from '../errors/index.js';
import type { SessionDriverFactory } from './types.js';
import type { SSRManifestSession } from '../app/types.js';
import { createStorage, type Storage } from 'unstorage';

export const PERSIST_SYMBOL = Symbol();

const DEFAULT_COOKIE_NAME = 'astro-session';
const VALID_COOKIE_REGEX = /^[\w-]+$/;

interface SessionEntry {
	data: any;
	expires?: number;
}

const unflatten: typeof rawUnflatten = (parsed, _) => {
	// Revive URL objects
	return rawUnflatten(parsed, {
		URL: (href) => new URL(href),
	});
};

const stringify: typeof rawStringify = (data, _) => {
	return rawStringify(data, {
		// Support URL objects
		URL: (val) => val instanceof URL && val.href,
	});
};

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.
// ... (406 more lines)

Domain

Subdomains

Classes

Types

Dependencies

  • ../../core/cookies/cookies.js
  • ../../core/session/types.js
  • ../core/app/types.js
  • ../core/errors/errors-data.js
  • ../core/errors/index.js
  • ../types/public/config.js
  • devalue
  • unstorage

Frequently Asked Questions

What does runtime.ts do?
runtime.ts is a source file in the astro codebase, written in typescript. It belongs to the CoreAstro domain, RenderingEngine subdomain.
What functions are defined in runtime.ts?
runtime.ts defines 2 function(s): stringify, unflatten.
What does runtime.ts depend on?
runtime.ts imports 8 module(s): ../../core/cookies/cookies.js, ../../core/session/types.js, ../core/app/types.js, ../core/errors/errors-data.js, ../core/errors/index.js, ../types/public/config.js, devalue, unstorage.
Where is runtime.ts in the architecture?
runtime.ts is located at packages/astro/src/core/session/runtime.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/core/session).

Analyze Your Own Codebase

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

Try Supermodel Free