UNPKG

@backstage/plugin-catalog-backend

Version:

The Backstage backend plugin that provides the Backstage catalog

66 lines (60 loc) 2.21 kB
'use strict'; var catalogModel = require('@backstage/catalog-model'); var errors = require('@backstage/errors'); var path = require('path'); function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; } var path__default = /*#__PURE__*/_interopDefaultCompat(path); function isLocationEntity(entity) { return entity.kind === "Location"; } function getEntityLocationRef(entity) { const ref = entity.metadata.annotations?.[catalogModel.ANNOTATION_LOCATION]; if (!ref) { const entityRef = catalogModel.stringifyEntityRef(entity); throw new errors.InputError( `Entity '${entityRef}' does not have the annotation ${catalogModel.ANNOTATION_LOCATION}` ); } return ref; } function getEntityOriginLocationRef(entity) { const ref = entity.metadata.annotations?.[catalogModel.ANNOTATION_ORIGIN_LOCATION]; if (!ref) { const entityRef = catalogModel.stringifyEntityRef(entity); throw new errors.InputError( `Entity '${entityRef}' does not have the annotation ${catalogModel.ANNOTATION_ORIGIN_LOCATION}` ); } return ref; } function toAbsoluteUrl(integrations, base, type, target) { if (base.type !== type) { return target; } try { if (type === "file") { if (target.startsWith(".")) { return path__default.default.join(path__default.default.dirname(base.target), target); } return target; } else if (type === "url") { return integrations.resolveUrl({ url: target, base: base.target }); } return target; } catch (e) { return target; } } function isObject(value) { return typeof value === "object" && value !== null && !Array.isArray(value); } const validateEntity = catalogModel.entitySchemaValidator(); const validateEntityEnvelope = catalogModel.entityEnvelopeSchemaValidator(); exports.getEntityLocationRef = getEntityLocationRef; exports.getEntityOriginLocationRef = getEntityOriginLocationRef; exports.isLocationEntity = isLocationEntity; exports.isObject = isObject; exports.toAbsoluteUrl = toAbsoluteUrl; exports.validateEntity = validateEntity; exports.validateEntityEnvelope = validateEntityEnvelope; //# sourceMappingURL=util.cjs.js.map