Repository: withastro/astro
File: packages/astro/src/core/base-pipeline.ts (TypeScript)

Code before:
			if (this.manifest.checkOrigin) {
				// this middleware must be placed at the beginning because it needs to block incoming requests
				internalMiddlewares.unshift(createOriginCheckMiddleware());
			}
			this.resolvedMiddleware = sequence(...internalMiddlewares);
			return this.resolvedMiddleware;
		} else {
			this.resolvedMiddleware = NOOP_MIDDLEWARE_FN;
			return this.resolvedMiddleware;
		}
	}

	setActions(actions: SSRActions) {
		this.resolvedActions = actions;
	}

	async getActions(): Promise<SSRActions> {
		if (this.resolvedActions) {
			return this.resolvedActions;
		} else if (this.actions) {
			return this.actions();
		}
		return NOOP_ACTIONS_MOD;
	}

	async getSessionDriver(): Promise<((config: any) => import('unstorage').Driver) | null> {
		// Return cached value if already resolved (including null)
		if (this.resolvedSessionDriver !== undefined) {
			return this.resolvedSessionDriver;
		}

		// Try to load the driver from the manifest
		if (this.sessionDriver) {
			const driverModule = await this.sessionDriver();
			this.resolvedSessionDriver = driverModule?.default || null;
			return this.resolvedSessionDriver;
		}

		// No driver configured
		this.resolvedSessionDriver = null;
		return null;
	}

	async getAction(path: string): Promise<ActionClient<unknown, ActionAccept, ZodType>> {
		const pathKeys = path.split('.').map((key) => decodeURIComponent(key));
		let { server } = await this.getActions();

		if (!server || !(typeof server === 'object')) {
			throw new TypeError(
				`Expected \`server\` export in actions file to be an object. Received ${typeof server}.`,
			);

Review comment (refactor):
This types are repeated a few times, could it be possible to extract the type and reuse it? Eg.
```ts
import type { Driver } from 'unstorage'

export type SessionDriver = (config: any) => Driver

// elsewhere
sessionDriver?: () => Promise<{ default: SessionDriver | null }>;
resolvedSessionDriver:
		| SessionDriver
		| null
		| undefined = undefined;
async getSessionDriver(): Promise<SessionDriver | null> {}
```

Code after:
				internalMiddlewares.unshift(createOriginCheckMiddleware());
			}
			this.resolvedMiddleware = sequence(...internalMiddlewares);
			return this.resolvedMiddleware;
		} else {
			this.resolvedMiddleware = NOOP_MIDDLEWARE_FN;
			return this.resolvedMiddleware;
		}
	}

	setActions(actions: SSRActions) {
		this.resolvedActions = actions;
	}

	async getActions(): Promise<SSRActions> {
		if (this.resolvedActions) {
			return this.resolvedActions;
		} else if (this.actions) {
			return this.actions();
		}
		return NOOP_ACTIONS_MOD;
	}

	async getSessionDriver(): Promise<SessionDriver | null> {
		// Return cached value if already resolved (including null)
		if (this.resolvedSessionDriver !== undefined) {
			return this.resolvedSessionDriver;
		}

		// Try to load the driver from the manifest
		if (this.sessionDriver) {
			const driverModule = await this.sessionDriver();
			this.resolvedSessionDriver = driverModule?.default || null;
			return this.resolvedSessionDriver;
		}

		// No driver configured
		this.resolvedSessionDriver = null;
		return null;
	}

	async getAction(path: string): Promise<ActionClient<unknown, ActionAccept, ZodType>> {
		const pathKeys = path.split('.').map((key) => decodeURIComponent(key));
		let { server } = await this.getActions();

		if (!server || !(typeof server === 'object')) {
			throw new TypeError(
				`Expected \`server\` export in actions file to be an object. Received ${typeof server}.`,
			);
		}