Home / File/ service.ts — astro Source File

service.ts — astro Source File

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

File typescript CoreAstro RenderingEngine 8 imports 14 functions

Entity Profile

Dependency Diagram

graph LR
  f0f55fc4_9c63_b35c_86d8_8eb3e4fa20ee["service.ts"]
  ef8a1e3f_e350_75a6_b92d_62a8566d8db9["../core/errors/index.js"]
  f0f55fc4_9c63_b35c_86d8_8eb3e4fa20ee --> ef8a1e3f_e350_75a6_b92d_62a8566d8db9
  7e4494c0_5563_4329_1bff_a84be66e1bc2["../core/path.js"]
  f0f55fc4_9c63_b35c_86d8_8eb3e4fa20ee --> 7e4494c0_5563_4329_1bff_a84be66e1bc2
  c32d12e2_d85e_28c0_eea7_9b29629857e0["../types/public/config.js"]
  f0f55fc4_9c63_b35c_86d8_8eb3e4fa20ee --> c32d12e2_d85e_28c0_eea7_9b29629857e0
  a19b6b68_b1f2_2d3e_2481_283031d370ff["./consts.js"]
  f0f55fc4_9c63_b35c_86d8_8eb3e4fa20ee --> a19b6b68_b1f2_2d3e_2481_283031d370ff
  416eda3d_47e6_c298_102b_b7a37d86a44e["../../assets/types.js"]
  f0f55fc4_9c63_b35c_86d8_8eb3e4fa20ee --> 416eda3d_47e6_c298_102b_b7a37d86a44e
  885fe8eb_6b3c_f392_ce65_d81fa1101fb3["./imageKind.js"]
  f0f55fc4_9c63_b35c_86d8_8eb3e4fa20ee --> 885fe8eb_6b3c_f392_ce65_d81fa1101fb3
  b8692cae_bcd5_338a_dfc3_de76a0aac53c["../utils/remoteProbe.js"]
  f0f55fc4_9c63_b35c_86d8_8eb3e4fa20ee --> b8692cae_bcd5_338a_dfc3_de76a0aac53c
  21f9daf1_9979_0313_afee_bbb8465c9f69["remote"]
  f0f55fc4_9c63_b35c_86d8_8eb3e4fa20ee --> 21f9daf1_9979_0313_afee_bbb8465c9f69
  style f0f55fc4_9c63_b35c_86d8_8eb3e4fa20ee fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import { isRemoteAllowed } from '@astrojs/internal-helpers/remote';
import { AstroError, AstroErrorData } from '../../core/errors/index.js';
import { isRemotePath, joinPaths } from '../../core/path.js';
import type { AstroConfig } from '../../types/public/config.js';
import { DEFAULT_HASH_PROPS, DEFAULT_OUTPUT_FORMAT, VALID_SUPPORTED_FORMATS } from '../consts.js';
import type {
	ImageFit,
	ImageMetadata,
	ImageOutputFormat,
	ImageTransform,
	UnresolvedSrcSetValue,
} from '../types.js';
import { isESMImportedImage, isRemoteImage } from '../utils/imageKind.js';
import { inferRemoteSize } from '../utils/remoteProbe.js';

export type ImageService = LocalImageService | ExternalImageService;

export function isLocalService(service: ImageService | undefined): service is LocalImageService {
	if (!service) {
		return false;
	}

	return 'transform' in service;
}

export function parseQuality(quality: string): string | number {
	let result = parseInt(quality);
	if (Number.isNaN(result)) {
		return quality;
	}

	return result;
}

type ImageConfig<T> = Omit<AstroConfig['image'], 'service'> & {
	service: { entrypoint: string; config: T };
	assetQueryParams?: URLSearchParams;
};

interface SharedServiceProps<T extends Record<string, any> = Record<string, any>> {
	/**
	 * Return the URL to the endpoint or URL your images are generated from.
	 *
	 * For a local service, your service should expose an endpoint handling the image requests, or use Astro's which by default, is located at `/_image`.
	 *
	 * For external services, this should point to the URL your images are coming from, for instance, `/_vercel/image`
	 *
	 */
	getURL: (options: ImageTransform, imageConfig: ImageConfig<T>) => string | Promise<string>;
	/**
	 * Generate additional `srcset` values for the image.
	 *
	 * While in most cases this is exclusively used for `srcset`, it can also be used in a more generic way to generate
	 * multiple variants of the same image. For instance, you can use this to generate multiple aspect ratios or multiple formats.
	 */
	getSrcSet?: (
		options: ImageTransform,
		imageConfig: ImageConfig<T>,
	) => UnresolvedSrcSetValue[] | Promise<UnresolvedSrcSetValue[]>;
	/**
// ... (396 more lines)

Domain

Subdomains

Dependencies

  • ../../assets/types.js
  • ../core/errors/index.js
  • ../core/path.js
  • ../types/public/config.js
  • ../utils/remoteProbe.js
  • ./consts.js
  • ./imageKind.js
  • remote

Frequently Asked Questions

What does service.ts do?
service.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 service.ts?
service.ts defines 14 function(s): baseService.getHTMLAttributes, baseService.getRemoteSize, baseService.getSrcSet, baseService.getURL, baseService.parseURL, baseService.validateOptions, getTargetDimensions, inputBuffer, isLocalService, options, and 4 more.
What does service.ts depend on?
service.ts imports 8 module(s): ../../assets/types.js, ../core/errors/index.js, ../core/path.js, ../types/public/config.js, ../utils/remoteProbe.js, ./consts.js, ./imageKind.js, remote.
Where is service.ts in the architecture?
service.ts is located at packages/astro/src/assets/services/service.ts (domain: CoreAstro, subdomain: RenderingEngine, directory: packages/astro/src/assets/services).

Analyze Your Own Codebase

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

Try Supermodel Free