import { ensureTrailingSlash } from "../../../util/url.js";
import { asTimestamp } from "../../../util/timestamp.js";
import { Datasource } from "../datasource.js";
import "../../versioning/npm/index.js";
//#region lib/modules/datasource/dart/index.ts
var DartDatasource = class DartDatasource extends Datasource {
	static id = "dart";
	constructor() {
		super(DartDatasource.id);
	}
	customRegistrySupport = true;
	defaultRegistryUrls = ["https://pub.dartlang.org/"];
	releaseTimestampSupport = true;
	releaseTimestampNote = "The release timestamp is determined from the `published` field in the results.";
	sourceUrlSupport = "package";
	sourceUrlNote = "The source URL is determined from the `repository` field of the latest release object in the results.";
	defaultVersioning = "npm";
	async getReleases({ packageName, registryUrl }) {
		/* v8 ignore next 3 -- should never happen */
		if (!registryUrl) return null;
		let result = null;
		const pkgUrl = `${ensureTrailingSlash(registryUrl)}api/packages/${packageName}`;
		let raw = null;
		try {
			raw = await this.http.getJsonUnchecked(pkgUrl);
		} catch (err) {
			this.handleGenericErrors(err);
		}
		const body = raw?.body;
		if (body) {
			const { versions, latest } = body;
			const releases = versions?.filter(({ retracted }) => !retracted)?.map(({ version, published }) => ({
				version,
				releaseTimestamp: asTimestamp(published)
			}));
			if (releases && latest) {
				result = { releases };
				const pubspec = latest.pubspec;
				if (pubspec) {
					if (pubspec.homepage) result.homepage = pubspec.homepage;
					if (pubspec.repository) result.sourceUrl = pubspec.repository;
				}
			}
		}
		return result;
	}
};
//#endregion
export { DartDatasource };

//# sourceMappingURL=index.js.map