Home / File/ types.ts — astro Source File

types.ts — astro Source File

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

File typescript CoreAstro RenderingEngine 2 imports 2 functions

Entity Profile

Dependency Diagram

graph LR
  8a043672_fcb4_880f_4008_7ebf53cfff0a["types.ts"]
  5799bf2d_d18e_6c2e_364a_a825ef7f6e79["../../core/cookies/cookies.js"]
  8a043672_fcb4_880f_4008_7ebf53cfff0a --> 5799bf2d_d18e_6c2e_364a_a825ef7f6e79
  a56f5589_e3c3_ced2_bdd4_5ad39a3cb093["unstorage"]
  8a043672_fcb4_880f_4008_7ebf53cfff0a --> a56f5589_e3c3_ced2_bdd4_5ad39a3cb093
  style 8a043672_fcb4_880f_4008_7ebf53cfff0a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { BuiltinDriverOptions } from 'unstorage';
import type { AstroCookieSetOptions } from '../cookies/cookies.js';

export interface SessionDriver {
	removeItem: (key: string) => Promise<void>;
	getItem: (key: string) => Promise<any>;
	setItem: (key: string, value: any) => Promise<void>;
}

export type SessionDriverFactory = (config: Record<string, any> | undefined) => SessionDriver;

export interface SessionDriverConfig {
	/** Serializable options used by the driver implementation */
	config?: Record<string, any> | undefined;
	/** URL or package import */
	entrypoint: string | URL;
}

export interface NormalizedSessionDriverConfig {
	config: Record<string, any> | undefined;
	entrypoint: string;
}

/** @deprecated */
export type SessionDriverName = keyof BuiltinDriverOptions | (string & {});

export interface BaseSessionConfig {
	/**
	 * Configures the session cookie. If set to a string, it will be used as the cookie name.
	 * Alternatively, you can pass an object with additional options.
	 */
	cookie?:
		| string
		| (Omit<AstroCookieSetOptions, 'httpOnly' | 'expires' | 'encode'> & {
				name?: string;
		  });

	/**
	 * Default session duration in seconds. If not set, the session will be stored until deleted, or until the cookie expires.
	 */
	ttl?: number;
}

interface DriverConfig<TDriver extends SessionDriverConfig> extends BaseSessionConfig {
	/** Config object for a session driver */
	driver: TDriver;
	/** @deprecated Pass options to the driver function directly. This will be removed in Astro 7 */
	options?: never;
}

interface UnstorageConfig<
	TDriver extends keyof BuiltinDriverOptions | undefined,
	TOptions = TDriver extends keyof BuiltinDriverOptions
		? NoInfer<BuiltinDriverOptions[TDriver]>
		: undefined,
> extends BaseSessionConfig {
	/**
	 * Entrypoint for an unstorage session driver
	 * @deprecated Use `import { sessionDrivers } from 'astro/config'` instead. This will be removed in Astro 7
	 */
	driver?: TDriver;
	/**
	 * Options for the unstorage driver
	 * @deprecated Use `import { sessionDrivers } from 'astro/config'` instead. This will be removed in Astro 7
	 */
	options?: TOptions;
}

interface CustomConfig extends BaseSessionConfig {
	/**
	 * Entrypoint for a custom session driver
	 * @deprecated Use the object shape (type `SessionDriverConfig`). This will be removed in Astro 7
	 */
	driver?: string;
	/**
	 * Options for the custom session driver
	 * @deprecated Use the object shape (type `SessionDriverConfig`). This will be removed in Astro 7
	 */
	options?: Record<string, unknown>;
}

export type SessionConfig<TDriver extends SessionDriverName | SessionDriverConfig | undefined> = [
	TDriver,
] extends [never]
	? UnstorageConfig<TDriver>
	: TDriver extends SessionDriverConfig
		? DriverConfig<TDriver>
		: TDriver extends keyof BuiltinDriverOptions
			? UnstorageConfig<TDriver>
			: CustomConfig;

Domain

Subdomains

Dependencies

  • ../../core/cookies/cookies.js
  • unstorage

Frequently Asked Questions

What does types.ts do?
types.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 types.ts?
types.ts defines 2 function(s): SessionDriver, key.
What does types.ts depend on?
types.ts imports 2 module(s): ../../core/cookies/cookies.js, unstorage.
Where is types.ts in the architecture?
types.ts is located at packages/astro/src/core/session/types.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