Home / File/ runtime.ts — astro Source File

runtime.ts — astro Source File

Architecture documentation for runtime.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
  fe2aa8a9_1607_64d7_db8e_cda22f1f02c9["runtime.ts"]
  a4f2698c_5256_262a_ba7c_f72b51878d10["../core/app/types.js"]
  fe2aa8a9_1607_64d7_db8e_cda22f1f02c9 --> a4f2698c_5256_262a_ba7c_f72b51878d10
  d34ed003_355b_637d_1578_cba29babbd4c["../../core/csp/config.js"]
  fe2aa8a9_1607_64d7_db8e_cda22f1f02c9 --> d34ed003_355b_637d_1578_cba29babbd4c
  style fe2aa8a9_1607_64d7_db8e_cda22f1f02c9 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import type { SSRManifestCSP } from '../app/types.js';
import type { CspDirective } from './config.js';

/**
 * `existingDirective` is something like `img-src 'self'`. Same as `newDirective`.
 *
 * Returns `undefined` if no directive has been deduped
 * @param existingDirective
 * @param newDirective
 */
export function deduplicateDirectiveValues(
	existingDirective: CspDirective,
	newDirective: CspDirective,
): CspDirective | undefined {
	const [directiveName, ...existingValues] = existingDirective
		// split spaces
		.split(/\s+/)
		// Avoid duplicated spaces
		.filter(Boolean);
	const [newDirectiveName, ...newValues] = newDirective
		// split spaces
		.split(/\s+/)
		// Avoid duplicated spaces
		.filter(Boolean);
	if (directiveName !== newDirectiveName) {
		return undefined;
	}
	const finalDirectives = Array.from(new Set([...existingValues, ...newValues]));

	return `${directiveName} ${finalDirectives.join(' ')}` as CspDirective;
}

export function pushDirective(
	directives: SSRManifestCSP['directives'],
	newDirective: CspDirective,
): SSRManifestCSP['directives'] {
	let deduplicated = false;
	if (directives.length === 0) {
		return [newDirective];
	}
	const finalDirectives: SSRManifestCSP['directives'] = [];
	for (const directive of directives) {
		if (deduplicated) {
			finalDirectives.push(directive);
			continue;
		}
		const result = deduplicateDirectiveValues(directive, newDirective);
		if (result) {
			finalDirectives.push(result);
			deduplicated = true;
		} else {
			finalDirectives.push(directive);
			finalDirectives.push(newDirective);
		}
	}
	return finalDirectives;
}

Domain

Subdomains

Dependencies

  • ../../core/csp/config.js
  • ../core/app/types.js

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): deduplicateDirectiveValues, pushDirective.
What does runtime.ts depend on?
runtime.ts imports 2 module(s): ../../core/csp/config.js, ../core/app/types.js.
Where is runtime.ts in the architecture?
runtime.ts is located at packages/astro/src/core/csp/runtime.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/core/csp).

Analyze Your Own Codebase

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

Try Supermodel Free