import { joinUrlParts } from "../../../util/url.js";
import { id } from "../../versioning/node/index.js";
import { withCache } from "../../../util/cache/package/with-cache.js";
import { asTimestamp } from "../../../util/timestamp.js";
import { Datasource } from "../datasource.js";
import { datasource, defaultRegistryUrl } from "./common.js";
import { NodeReleases } from "./schema.js";
//#region lib/modules/datasource/node-version/index.ts
var NodeVersionDatasource = class extends Datasource {
	static id = datasource;
	constructor() {
		super(datasource);
	}
	defaultRegistryUrls = [defaultRegistryUrl];
	defaultVersioning = id;
	caching = true;
	releaseTimestampSupport = true;
	releaseTimestampNote = "The release timestamp is determined from the `date` field.";
	sourceUrlSupport = "package";
	sourceUrlNote = "We use the URL: https://github.com/nodejs/node";
	async _getReleases({ registryUrl }) {
		/* v8 ignore next 3 -- should never happen */
		if (!registryUrl) return null;
		const result = {
			homepage: "https://nodejs.org",
			sourceUrl: "https://github.com/nodejs/node",
			registryUrl,
			releases: []
		};
		try {
			const resp = await this.http.getJson(joinUrlParts(registryUrl, "index.json"), NodeReleases);
			result.releases.push(...resp.body.map(({ version, date, lts }) => ({
				version,
				releaseTimestamp: asTimestamp(date),
				isStable: lts !== false
			})));
		} catch (err) {
			this.handleGenericErrors(err);
		}
		return result.releases.length ? result : null;
	}
	getReleases(config) {
		return withCache({
			namespace: `datasource-${datasource}`,
			key: `${config.registryUrl}`,
			fallback: true
		}, () => this._getReleases(config));
	}
};
//#endregion
export { NodeVersionDatasource };

//# sourceMappingURL=index.js.map