@red-hat-developer-hub/backstage-plugin-scorecard-backend 2.7.1 → 2.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @red-hat-developer-hub/backstage-plugin-scorecard-backend
2
2
 
3
+ ## 2.7.2
4
+
5
+ ### Patch Changes
6
+
7
+ - @red-hat-developer-hub/backstage-plugin-scorecard-common@2.7.2
8
+ - @red-hat-developer-hub/backstage-plugin-scorecard-node@2.7.2
9
+
3
10
  ## 2.7.1
4
11
 
5
12
  ### Patch Changes
@@ -4,7 +4,6 @@ class DatabaseMetricValues {
4
4
  constructor(dbClient) {
5
5
  this.dbClient = dbClient;
6
6
  }
7
- dbClient;
8
7
  tableName = "metric_values";
9
8
  /**
10
9
  * Insert multiple metric values
@@ -1 +1 @@
1
- {"version":3,"file":"DatabaseMetricValues.cjs.js","sources":["../../src/database/DatabaseMetricValues.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Knex } from 'knex';\nimport {\n DbMetricValueCreate,\n DbMetricValue,\n DbAggregatedMetric,\n} from './types';\n\ntype ReadEntityMetricsWithFiltersOptions = {\n status?: string;\n entityName?: string;\n entityKind?: string;\n entityNamespace?: string;\n entityOwner?: string[];\n sortBy?:\n | 'entityName'\n | 'owner'\n | 'entityKind'\n | 'timestamp'\n | 'metricValue'\n | 'namespace'\n | 'status';\n sortOrder?: 'asc' | 'desc';\n pagination?: { limit: number; offset: number };\n};\n\nexport class DatabaseMetricValues {\n private readonly tableName = 'metric_values';\n\n constructor(private readonly dbClient: Knex<any, any[]>) {}\n\n /**\n * Insert multiple metric values\n */\n async createMetricValues(metricValues: DbMetricValueCreate[]): Promise<void> {\n if (metricValues.length === 0) {\n return;\n }\n await this.dbClient(this.tableName).insert(metricValues);\n }\n\n /**\n * Get the latest metric values for a specific entity and metrics\n */\n async readLatestEntityMetricValues(\n catalog_entity_ref: string,\n metric_ids: string[],\n ): Promise<DbMetricValue[]> {\n return await this.dbClient(this.tableName)\n .select('*')\n .whereIn(\n 'id',\n this.dbClient(this.tableName)\n .max('id')\n .whereIn('metric_id', metric_ids)\n .where('catalog_entity_ref', catalog_entity_ref)\n .groupBy('metric_id'),\n );\n }\n\n /**\n * Delete metric values that are older than the given date\n */\n async cleanupExpiredMetrics(olderThan: Date): Promise<number> {\n return await this.dbClient(this.tableName)\n .where('timestamp', '<', olderThan)\n .del();\n }\n\n /**\n * Get aggregated metrics by status for multiple entities and metrics.\n */\n async readAggregatedMetricByEntityRefs(\n catalog_entity_refs: string[],\n metric_id: string,\n ): Promise<DbAggregatedMetric | undefined> {\n if (catalog_entity_refs.length === 0) {\n return undefined;\n }\n\n const latestIdsSubquery = this.dbClient(this.tableName)\n .max('id')\n .where('metric_id', metric_id)\n .whereIn('catalog_entity_ref', catalog_entity_refs)\n .groupBy('catalog_entity_ref');\n\n // `value` is a JSON column. Depending on database/driver, a \"missing\" metric value can\n // arrive either as SQL NULL or as JSON literal null (`CAST(value AS TEXT) = 'null'`).\n const metricValueIsMissingExpr =\n \"(value IS NULL OR CAST(value AS TEXT) = 'null')\";\n\n // One round-trip for latest-row count, calculation-error count, and max timestamp\n // (same latest-id set as the status breakdown query below).\n const statsRow = await this.dbClient(this.tableName)\n .whereIn('id', latestIdsSubquery)\n .select(\n this.dbClient.raw('COUNT(*) as latest_row_count'),\n this.dbClient.raw(\n `SUM(CASE WHEN error_message IS NOT NULL AND ${metricValueIsMissingExpr} THEN 1 ELSE 0 END) as calculation_error_count`,\n ),\n this.dbClient.raw('MAX(timestamp) as max_timestamp'),\n )\n .first();\n\n const latestRowCount = Number(\n (statsRow as { latest_row_count?: string | number } | undefined)\n ?.latest_row_count ?? 0,\n );\n if (latestRowCount === 0) {\n return undefined;\n }\n\n const calculation_error_count = Number(\n (statsRow as { calculation_error_count?: string | number } | undefined)\n ?.calculation_error_count ?? 0,\n );\n\n // Normalize types for cross-database compatibility\n // PostgreSQL returns COUNT/SUM as strings, SQLite returns numbers\n // PostgreSQL returns MAX(timestamp) as Date, SQLite returns number (milliseconds)\n const normalizeTimestamp = (timestamp: unknown): Date => {\n if (timestamp instanceof Date) {\n return timestamp;\n }\n if (typeof timestamp === 'number' || typeof timestamp === 'string') {\n return new Date(timestamp);\n }\n return new Date();\n };\n\n const maxTimestampAllLatest = normalizeTimestamp(\n (statsRow as { max_timestamp?: unknown })?.max_timestamp,\n );\n\n const statusRows = await this.dbClient(this.tableName)\n .select('status')\n .count('* as count')\n .max('timestamp as max_timestamp')\n .whereIn('id', latestIdsSubquery)\n .whereNotNull('status')\n .whereRaw(`NOT ${metricValueIsMissingExpr}`)\n .groupBy('status');\n\n if (!statusRows || statusRows.length === 0) {\n return {\n metric_id,\n total: 0,\n max_timestamp: maxTimestampAllLatest,\n statusCounts: {},\n calculation_error_count,\n latest_entity_count: latestRowCount,\n };\n }\n\n let maxTimestamp = new Date(0);\n let total = 0;\n const statusCounts: Record<string, number> = {};\n for (const row of statusRows) {\n const rowTimestamp = normalizeTimestamp(row.max_timestamp);\n if (rowTimestamp > maxTimestamp) {\n maxTimestamp = rowTimestamp;\n }\n const name = row.status as string;\n const count = Number(row.count);\n statusCounts[name] = count;\n total += count;\n }\n\n const mergedMax =\n maxTimestampAllLatest.getTime() >= maxTimestamp.getTime()\n ? maxTimestampAllLatest\n : maxTimestamp;\n\n return {\n metric_id,\n total,\n max_timestamp: mergedMax,\n statusCounts,\n calculation_error_count,\n latest_entity_count: latestRowCount,\n };\n }\n\n /**\n * Fetch the latest entity metric values for a given metric, with optional filtering\n * by status, name, kind, namespace, or owner, plus sorting and pagination.\n */\n async readEntityMetricsWithFilters(\n metric_id: string,\n options: ReadEntityMetricsWithFiltersOptions,\n ): Promise<DbMetricValue[]> {\n const clientName: string =\n (this.dbClient as any).client?.config?.client ?? '';\n const isPostgres = clientName === 'pg' || clientName.includes('postgres');\n\n const latestIdsSubquery = this.dbClient(this.tableName)\n .max('id')\n .where('metric_id', metric_id)\n .groupBy('catalog_entity_ref');\n\n const query = this.dbClient(this.tableName)\n .select('*')\n .whereIn('id', latestIdsSubquery);\n\n const sortColumnMap: Record<string, string> = {\n entityName: 'catalog_entity_ref',\n owner: 'entity_owner',\n entityKind: 'entity_kind',\n timestamp: 'timestamp',\n metricValue: 'value',\n namespace: 'entity_namespace',\n status: 'status',\n };\n\n const column =\n (options.sortBy && sortColumnMap[options.sortBy]) ?? 'timestamp';\n const direction = options.sortOrder === 'asc' ? 'asc' : 'desc';\n\n this.applySort(query, options.sortBy, column, direction, isPostgres);\n\n if (options.status) {\n query.where('status', options.status);\n }\n\n if (options.entityName) {\n const escaped = options.entityName.replace(/[%_\\\\]/g, '\\\\$&');\n query.whereRaw(\"catalog_entity_ref LIKE ? ESCAPE '\\\\'\", [`%${escaped}%`]);\n }\n\n if (options.entityKind) {\n query.where('entity_kind', options.entityKind);\n }\n\n if (options.entityNamespace) {\n query.where('entity_namespace', options.entityNamespace);\n }\n\n if (options.entityOwner && options.entityOwner.length > 0) {\n query.whereIn('entity_owner', options.entityOwner);\n }\n\n if (options.pagination) {\n query.limit(options.pagination.limit).offset(options.pagination.offset);\n }\n\n return await query;\n }\n\n private applySort(\n query: any,\n sortBy: string | undefined,\n column: string,\n direction: string,\n isPostgres: boolean,\n ): void {\n if (sortBy === 'metricValue') {\n // value is JSON and nullable; cast for numeric sort with NULLs last\n if (isPostgres) {\n query.orderByRaw(\n `CAST(value::text AS DOUBLE PRECISION) ${direction} NULLS LAST, id ASC`,\n );\n } else {\n // SQLite: \"value IS NULL\" puts nulls last; double-cast handles JSON-stored values\n query.orderByRaw(\n `value IS NULL, CAST(CAST(value AS TEXT) AS REAL) ${direction}, id ASC`,\n );\n }\n } else if (sortBy === 'status') {\n // status is nullable; NULLs always sort last regardless of direction\n if (isPostgres) {\n query.orderByRaw(`status ${direction} NULLS LAST, id ASC`);\n } else {\n // SQLite: \"status IS NULL\" evaluates to 1 for NULLs, pushing them to the end\n query.orderByRaw(`status IS NULL, status ${direction}, id ASC`);\n }\n } else {\n query.orderBy(column, direction);\n // Ensure a stable sort when two metrics share the same primary sort value\n query.orderBy('id', 'asc');\n }\n }\n}\n"],"names":[],"mappings":";;AAyCO,MAAM,oBAAqB,CAAA;AAAA,EAGhC,YAA6B,QAA4B,EAAA;AAA5B,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAAA;AAA6B,EAA7B,QAAA;AAAA,EAFZ,SAAY,GAAA,eAAA;AAAA;AAAA;AAAA;AAAA,EAO7B,MAAM,mBAAmB,YAAoD,EAAA;AAC3E,IAAI,IAAA,YAAA,CAAa,WAAW,CAAG,EAAA;AAC7B,MAAA;AAAA;AAEF,IAAA,MAAM,KAAK,QAAS,CAAA,IAAA,CAAK,SAAS,CAAA,CAAE,OAAO,YAAY,CAAA;AAAA;AACzD;AAAA;AAAA;AAAA,EAKA,MAAM,4BACJ,CAAA,kBAAA,EACA,UAC0B,EAAA;AAC1B,IAAO,OAAA,MAAM,KAAK,QAAS,CAAA,IAAA,CAAK,SAAS,CACtC,CAAA,MAAA,CAAO,GAAG,CACV,CAAA,OAAA;AAAA,MACC,IAAA;AAAA,MACA,KAAK,QAAS,CAAA,IAAA,CAAK,SAAS,CAAA,CACzB,IAAI,IAAI,CAAA,CACR,OAAQ,CAAA,WAAA,EAAa,UAAU,CAC/B,CAAA,KAAA,CAAM,sBAAsB,kBAAkB,CAAA,CAC9C,QAAQ,WAAW;AAAA,KACxB;AAAA;AACJ;AAAA;AAAA;AAAA,EAKA,MAAM,sBAAsB,S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AA;AAGxE,IAAA,OAAO,MAAM,KAAA;AAAA;AACf,EAEQ,SACN,CAAA,KAAA,EACA,MACA,EAAA,MAAA,EACA,WACA,UACM,EAAA;AACN,IAAA,IAAI,WAAW,aAAe,EAAA;AAE5B,MAAA,IAAI,UAAY,EAAA;AACd,QAAM,KAAA,CAAA,UAAA;AAAA,UACJ,yCAAyC,SAAS,CAAA,mBAAA;AAAA,SACpD;AAAA,OACK,MAAA;AAEL,QAAM,KAAA,CAAA,UAAA;AAAA,UACJ,oDAAoD,SAAS,CAAA,QAAA;AAAA,SAC/D;AAAA;AACF,KACF,MAAA,IAAW,WAAW,QAAU,EAAA;AAE9B,MAAA,IAAI,UAAY,EAAA;AACd,QAAM,KAAA,CAAA,UAAA,CAAW,CAAU,OAAA,EAAA,SAAS,CAAqB,mBAAA,CAAA,CAAA;AAAA,OACpD,MAAA;AAEL,QAAM,KAAA,CAAA,UAAA,CAAW,CAA0B,uBAAA,EAAA,SAAS,CAAU,QAAA,CAAA,CAAA;AAAA;AAChE,KACK,MAAA;AACL,MAAM,KAAA,CAAA,OAAA,CAAQ,QAAQ,SAAS,CAAA;AAE/B,MAAM,KAAA,CAAA,OAAA,CAAQ,MAAM,KAAK,CAAA;AAAA;AAC3B;AAEJ;;;;"}
1
+ {"version":3,"file":"DatabaseMetricValues.cjs.js","sources":["../../src/database/DatabaseMetricValues.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Knex } from 'knex';\nimport {\n DbMetricValueCreate,\n DbMetricValue,\n DbAggregatedMetric,\n} from './types';\n\ntype ReadEntityMetricsWithFiltersOptions = {\n status?: string;\n entityName?: string;\n entityKind?: string;\n entityNamespace?: string;\n entityOwner?: string[];\n sortBy?:\n | 'entityName'\n | 'owner'\n | 'entityKind'\n | 'timestamp'\n | 'metricValue'\n | 'namespace'\n | 'status';\n sortOrder?: 'asc' | 'desc';\n pagination?: { limit: number; offset: number };\n};\n\nexport class DatabaseMetricValues {\n private readonly tableName = 'metric_values';\n\n constructor(private readonly dbClient: Knex<any, any[]>) {}\n\n /**\n * Insert multiple metric values\n */\n async createMetricValues(metricValues: DbMetricValueCreate[]): Promise<void> {\n if (metricValues.length === 0) {\n return;\n }\n await this.dbClient(this.tableName).insert(metricValues);\n }\n\n /**\n * Get the latest metric values for a specific entity and metrics\n */\n async readLatestEntityMetricValues(\n catalog_entity_ref: string,\n metric_ids: string[],\n ): Promise<DbMetricValue[]> {\n return await this.dbClient(this.tableName)\n .select('*')\n .whereIn(\n 'id',\n this.dbClient(this.tableName)\n .max('id')\n .whereIn('metric_id', metric_ids)\n .where('catalog_entity_ref', catalog_entity_ref)\n .groupBy('metric_id'),\n );\n }\n\n /**\n * Delete metric values that are older than the given date\n */\n async cleanupExpiredMetrics(olderThan: Date): Promise<number> {\n return await this.dbClient(this.tableName)\n .where('timestamp', '<', olderThan)\n .del();\n }\n\n /**\n * Get aggregated metrics by status for multiple entities and metrics.\n */\n async readAggregatedMetricByEntityRefs(\n catalog_entity_refs: string[],\n metric_id: string,\n ): Promise<DbAggregatedMetric | undefined> {\n if (catalog_entity_refs.length === 0) {\n return undefined;\n }\n\n const latestIdsSubquery = this.dbClient(this.tableName)\n .max('id')\n .where('metric_id', metric_id)\n .whereIn('catalog_entity_ref', catalog_entity_refs)\n .groupBy('catalog_entity_ref');\n\n // `value` is a JSON column. Depending on database/driver, a \"missing\" metric value can\n // arrive either as SQL NULL or as JSON literal null (`CAST(value AS TEXT) = 'null'`).\n const metricValueIsMissingExpr =\n \"(value IS NULL OR CAST(value AS TEXT) = 'null')\";\n\n // One round-trip for latest-row count, calculation-error count, and max timestamp\n // (same latest-id set as the status breakdown query below).\n const statsRow = await this.dbClient(this.tableName)\n .whereIn('id', latestIdsSubquery)\n .select(\n this.dbClient.raw('COUNT(*) as latest_row_count'),\n this.dbClient.raw(\n `SUM(CASE WHEN error_message IS NOT NULL AND ${metricValueIsMissingExpr} THEN 1 ELSE 0 END) as calculation_error_count`,\n ),\n this.dbClient.raw('MAX(timestamp) as max_timestamp'),\n )\n .first();\n\n const latestRowCount = Number(\n (statsRow as { latest_row_count?: string | number } | undefined)\n ?.latest_row_count ?? 0,\n );\n if (latestRowCount === 0) {\n return undefined;\n }\n\n const calculation_error_count = Number(\n (statsRow as { calculation_error_count?: string | number } | undefined)\n ?.calculation_error_count ?? 0,\n );\n\n // Normalize types for cross-database compatibility\n // PostgreSQL returns COUNT/SUM as strings, SQLite returns numbers\n // PostgreSQL returns MAX(timestamp) as Date, SQLite returns number (milliseconds)\n const normalizeTimestamp = (timestamp: unknown): Date => {\n if (timestamp instanceof Date) {\n return timestamp;\n }\n if (typeof timestamp === 'number' || typeof timestamp === 'string') {\n return new Date(timestamp);\n }\n return new Date();\n };\n\n const maxTimestampAllLatest = normalizeTimestamp(\n (statsRow as { max_timestamp?: unknown })?.max_timestamp,\n );\n\n const statusRows = await this.dbClient(this.tableName)\n .select('status')\n .count('* as count')\n .max('timestamp as max_timestamp')\n .whereIn('id', latestIdsSubquery)\n .whereNotNull('status')\n .whereRaw(`NOT ${metricValueIsMissingExpr}`)\n .groupBy('status');\n\n if (!statusRows || statusRows.length === 0) {\n return {\n metric_id,\n total: 0,\n max_timestamp: maxTimestampAllLatest,\n statusCounts: {},\n calculation_error_count,\n latest_entity_count: latestRowCount,\n };\n }\n\n let maxTimestamp = new Date(0);\n let total = 0;\n const statusCounts: Record<string, number> = {};\n for (const row of statusRows) {\n const rowTimestamp = normalizeTimestamp(row.max_timestamp);\n if (rowTimestamp > maxTimestamp) {\n maxTimestamp = rowTimestamp;\n }\n const name = row.status as string;\n const count = Number(row.count);\n statusCounts[name] = count;\n total += count;\n }\n\n const mergedMax =\n maxTimestampAllLatest.getTime() >= maxTimestamp.getTime()\n ? maxTimestampAllLatest\n : maxTimestamp;\n\n return {\n metric_id,\n total,\n max_timestamp: mergedMax,\n statusCounts,\n calculation_error_count,\n latest_entity_count: latestRowCount,\n };\n }\n\n /**\n * Fetch the latest entity metric values for a given metric, with optional filtering\n * by status, name, kind, namespace, or owner, plus sorting and pagination.\n */\n async readEntityMetricsWithFilters(\n metric_id: string,\n options: ReadEntityMetricsWithFiltersOptions,\n ): Promise<DbMetricValue[]> {\n const clientName: string =\n (this.dbClient as any).client?.config?.client ?? '';\n const isPostgres = clientName === 'pg' || clientName.includes('postgres');\n\n const latestIdsSubquery = this.dbClient(this.tableName)\n .max('id')\n .where('metric_id', metric_id)\n .groupBy('catalog_entity_ref');\n\n const query = this.dbClient(this.tableName)\n .select('*')\n .whereIn('id', latestIdsSubquery);\n\n const sortColumnMap: Record<string, string> = {\n entityName: 'catalog_entity_ref',\n owner: 'entity_owner',\n entityKind: 'entity_kind',\n timestamp: 'timestamp',\n metricValue: 'value',\n namespace: 'entity_namespace',\n status: 'status',\n };\n\n const column =\n (options.sortBy && sortColumnMap[options.sortBy]) ?? 'timestamp';\n const direction = options.sortOrder === 'asc' ? 'asc' : 'desc';\n\n this.applySort(query, options.sortBy, column, direction, isPostgres);\n\n if (options.status) {\n query.where('status', options.status);\n }\n\n if (options.entityName) {\n const escaped = options.entityName.replace(/[%_\\\\]/g, '\\\\$&');\n query.whereRaw(\"catalog_entity_ref LIKE ? ESCAPE '\\\\'\", [`%${escaped}%`]);\n }\n\n if (options.entityKind) {\n query.where('entity_kind', options.entityKind);\n }\n\n if (options.entityNamespace) {\n query.where('entity_namespace', options.entityNamespace);\n }\n\n if (options.entityOwner && options.entityOwner.length > 0) {\n query.whereIn('entity_owner', options.entityOwner);\n }\n\n if (options.pagination) {\n query.limit(options.pagination.limit).offset(options.pagination.offset);\n }\n\n return await query;\n }\n\n private applySort(\n query: any,\n sortBy: string | undefined,\n column: string,\n direction: string,\n isPostgres: boolean,\n ): void {\n if (sortBy === 'metricValue') {\n // value is JSON and nullable; cast for numeric sort with NULLs last\n if (isPostgres) {\n query.orderByRaw(\n `CAST(value::text AS DOUBLE PRECISION) ${direction} NULLS LAST, id ASC`,\n );\n } else {\n // SQLite: \"value IS NULL\" puts nulls last; double-cast handles JSON-stored values\n query.orderByRaw(\n `value IS NULL, CAST(CAST(value AS TEXT) AS REAL) ${direction}, id ASC`,\n );\n }\n } else if (sortBy === 'status') {\n // status is nullable; NULLs always sort last regardless of direction\n if (isPostgres) {\n query.orderByRaw(`status ${direction} NULLS LAST, id ASC`);\n } else {\n // SQLite: \"status IS NULL\" evaluates to 1 for NULLs, pushing them to the end\n query.orderByRaw(`status IS NULL, status ${direction}, id ASC`);\n }\n } else {\n query.orderBy(column, direction);\n // Ensure a stable sort when two metrics share the same primary sort value\n query.orderBy('id', 'asc');\n }\n }\n}\n"],"names":[],"mappings":";;AAyCO,MAAM,oBAAqB,CAAA;AAAA,EAGhC,YAA6B,QAA4B,EAAA;AAA5B,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAAA;AAA6B,EAFzC,SAAY,GAAA,eAAA;AAAA;AAAA;AAAA;AAAA,EAO7B,MAAM,mBAAmB,YAAoD,EAAA;AAC3E,IAAI,IAAA,YAAA,CAAa,WAAW,CAAG,EAAA;AAC7B,MAAA;AAAA;AAEF,IAAA,MAAM,KAAK,QAAS,CAAA,IAAA,CAAK,SAAS,CAAA,CAAE,OAAO,YAAY,CAAA;AAAA;AACzD;AAAA;AAAA;AAAA,EAKA,MAAM,4BACJ,CAAA,kBAAA,EACA,UAC0B,EAAA;AAC1B,IAAO,OAAA,MAAM,KAAK,QAAS,CAAA,IAAA,CAAK,SAAS,CACtC,CAAA,MAAA,CAAO,GAAG,CACV,CAAA,OAAA;AAAA,MACC,IAAA;AAAA,MACA,KAAK,QAAS,CAAA,IAAA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A,OAAA,CAAQ,cAAgB,EAAA,OAAA,CAAQ,WAAW,CAAA;AAAA;AAGnD,IAAA,IAAI,QAAQ,UAAY,EAAA;AACtB,MAAM,KAAA,CAAA,KAAA,CAAM,QAAQ,UAAW,CAAA,KAAK,EAAE,MAAO,CAAA,OAAA,CAAQ,WAAW,MAAM,CAAA;AAAA;AAGxE,IAAA,OAAO,MAAM,KAAA;AAAA;AACf,EAEQ,SACN,CAAA,KAAA,EACA,MACA,EAAA,MAAA,EACA,WACA,UACM,EAAA;AACN,IAAA,IAAI,WAAW,aAAe,EAAA;AAE5B,MAAA,IAAI,UAAY,EAAA;AACd,QAAM,KAAA,CAAA,UAAA;AAAA,UACJ,yCAAyC,SAAS,CAAA,mBAAA;AAAA,SACpD;AAAA,OACK,MAAA;AAEL,QAAM,KAAA,CAAA,UAAA;AAAA,UACJ,oDAAoD,SAAS,CAAA,QAAA;AAAA,SAC/D;AAAA;AACF,KACF,MAAA,IAAW,WAAW,QAAU,EAAA;AAE9B,MAAA,IAAI,UAAY,EAAA;AACd,QAAM,KAAA,CAAA,UAAA,CAAW,CAAU,OAAA,EAAA,SAAS,CAAqB,mBAAA,CAAA,CAAA;AAAA,OACpD,MAAA;AAEL,QAAM,KAAA,CAAA,UAAA,CAAW,CAA0B,uBAAA,EAAA,SAAS,CAAU,QAAA,CAAA,CAAA;AAAA;AAChE,KACK,MAAA;AACL,MAAM,KAAA,CAAA,OAAA,CAAQ,QAAQ,SAAS,CAAA;AAE/B,MAAM,KAAA,CAAA,OAAA,CAAQ,MAAM,KAAK,CAAA;AAAA;AAC3B;AAEJ;;;;"}
@@ -6,7 +6,6 @@ class AggregatedMetricLoader {
6
6
  constructor(database) {
7
7
  this.database = database;
8
8
  }
9
- database;
10
9
  async loadStatusGroupedMetricByEntityRefs(entityRefs, metricId) {
11
10
  if (entityRefs.length === 0) {
12
11
  return mappers.AggregatedMetricMapper.toAggregatedMetric();
@@ -1 +1 @@
1
- {"version":3,"file":"AggregatedMetricLoader.cjs.js","sources":["../../../src/service/aggregations/AggregatedMetricLoader.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AggregatedMetric } from '@red-hat-developer-hub/backstage-plugin-scorecard-common';\nimport { DatabaseMetricValues } from '../../database/DatabaseMetricValues';\nimport { AggregatedMetricMapper } from '../mappers';\n\nexport class AggregatedMetricLoader {\n constructor(private readonly database: DatabaseMetricValues) {}\n\n async loadStatusGroupedMetricByEntityRefs(\n entityRefs: string[],\n metricId: string,\n ): Promise<AggregatedMetric> {\n if (entityRefs.length === 0) {\n return AggregatedMetricMapper.toAggregatedMetric();\n }\n\n const aggregatedMetric =\n await this.database.readAggregatedMetricByEntityRefs(\n entityRefs,\n metricId,\n );\n\n return AggregatedMetricMapper.toAggregatedMetric(aggregatedMetric);\n }\n}\n"],"names":["AggregatedMetricMapper"],"mappings":";;;;AAoBO,MAAM,sBAAuB,CAAA;AAAA,EAClC,YAA6B,QAAgC,EAAA;AAAhC,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAAA;AAAiC,EAAjC,QAAA;AAAA,EAE7B,MAAM,mCACJ,CAAA,UAAA,EACA,QAC2B,EAAA;AAC3B,IAAI,IAAA,UAAA,CAAW,WAAW,CAAG,EAAA;AAC3B,MAAA,OAAOA,+BAAuB,kBAAmB,EAAA;AAAA;AAGnD,IAAM,MAAA,gBAAA,GACJ,MAAM,IAAA,CAAK,QAAS,CAAA,gCAAA;AAAA,MAClB,UAAA;AAAA,MACA;AAAA,KACF;AAEF,IAAO,OAAAA,8BAAA,CAAuB,mBAAmB,gBAAgB,CAAA;AAAA;AAErE;;;;"}
1
+ {"version":3,"file":"AggregatedMetricLoader.cjs.js","sources":["../../../src/service/aggregations/AggregatedMetricLoader.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type { AggregatedMetric } from '@red-hat-developer-hub/backstage-plugin-scorecard-common';\nimport { DatabaseMetricValues } from '../../database/DatabaseMetricValues';\nimport { AggregatedMetricMapper } from '../mappers';\n\nexport class AggregatedMetricLoader {\n constructor(private readonly database: DatabaseMetricValues) {}\n\n async loadStatusGroupedMetricByEntityRefs(\n entityRefs: string[],\n metricId: string,\n ): Promise<AggregatedMetric> {\n if (entityRefs.length === 0) {\n return AggregatedMetricMapper.toAggregatedMetric();\n }\n\n const aggregatedMetric =\n await this.database.readAggregatedMetricByEntityRefs(\n entityRefs,\n metricId,\n );\n\n return AggregatedMetricMapper.toAggregatedMetric(aggregatedMetric);\n }\n}\n"],"names":["AggregatedMetricMapper"],"mappings":";;;;AAoBO,MAAM,sBAAuB,CAAA;AAAA,EAClC,YAA6B,QAAgC,EAAA;AAAhC,IAAA,IAAA,CAAA,QAAA,GAAA,QAAA;AAAA;AAAiC,EAE9D,MAAM,mCACJ,CAAA,UAAA,EACA,QAC2B,EAAA;AAC3B,IAAI,IAAA,UAAA,CAAW,WAAW,CAAG,EAAA;AAC3B,MAAA,OAAOA,+BAAuB,kBAAmB,EAAA;AAAA;AAGnD,IAAM,MAAA,gBAAA,GACJ,MAAM,IAAA,CAAK,QAAS,CAAA,gCAAA;AAAA,MAClB,UAAA;AAAA,MACA;AAAA,KACF;AAEF,IAAO,OAAAA,8BAAA,CAAuB,mBAAmB,gBAAgB,CAAA;AAAA;AAErE;;;;"}
@@ -9,8 +9,6 @@ class AverageAggregationStrategy {
9
9
  this.loader = loader;
10
10
  this.logger = logger;
11
11
  }
12
- loader;
13
- logger;
14
12
  async aggregate({
15
13
  entityRefs,
16
14
  metric,
@@ -1 +1 @@
1
- {"version":3,"file":"AverageAggregationStrategy.cjs.js","sources":["../../../../src/service/aggregations/strategies/AverageAggregationStrategy.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n type AggregatedMetric,\n type AggregatedMetricAverageResult,\n type AggregatedMetricResult,\n type ThresholdConfig,\n ThresholdRule,\n type AggregationConfigOptions,\n} from '@red-hat-developer-hub/backstage-plugin-scorecard-common';\nimport { DEFAULT_AVERAGE_KPI_RESULT_THRESHOLDS } from '../../../constants/aggregationKPIs';\nimport { AggregatedMetricMapper } from '../../mappers';\nimport type { AggregatedMetricLoader } from '../AggregatedMetricLoader';\nimport type { AggregationOptions } from '../types';\nimport type { AggregationStrategy } from './types';\nimport { LoggerService } from '@backstage/backend-plugin-api';\nimport { ThresholdEvaluator } from '../../../threshold/ThresholdEvaluator';\n\nexport class AverageAggregationStrategy implements AggregationStrategy {\n constructor(\n private readonly loader: AggregatedMetricLoader,\n private readonly logger: LoggerService,\n ) {}\n\n async aggregate({\n entityRefs,\n metric,\n thresholds,\n aggregationConfig,\n }: AggregationOptions): Promise<AggregatedMetricResult> {\n const { options } = aggregationConfig;\n\n if (!options?.statusScores) {\n throw new Error(\n `The \"scorecard.aggregationKPIs.${aggregationConfig.id}.options.statusScores\" is required for average aggregation`,\n );\n }\n\n if (!options.thresholds) {\n this.logger.info(\n `The \"scorecard.aggregationKPIs.${aggregationConfig.id}.options.thresholds\" is not configured for average aggregation; ` +\n 'using the default 0–100% health scale (higher is better).',\n );\n }\n\n const headlineThresholds =\n options.thresholds ?? DEFAULT_AVERAGE_KPI_RESULT_THRESHOLDS;\n\n const aggregatedMetric =\n await this.loader.loadStatusGroupedMetricByEntityRefs(\n entityRefs,\n metric.id,\n );\n\n const weightedSum = this.calculateWeightedSum(\n aggregatedMetric.values,\n options.statusScores,\n metric.id,\n );\n\n const { averageScore, maxPossibleScore } = this.prepareScoreValues(\n aggregatedMetric.total,\n options.statusScores,\n thresholds.rules,\n weightedSum,\n );\n\n const scorePercent = averageScore * 100;\n\n const aggregationChartDisplayColor = this.getAggregationChartDisplayColor(\n scorePercent,\n headlineThresholds,\n );\n\n if (!aggregationChartDisplayColor) {\n throw new Error(\n `The color for percentage '${scorePercent}' metric '${metric.id}' is not configured. Check the 'scorecard.aggregationKPIs.${aggregationConfig.id}.options.thresholds' configuration.`,\n );\n }\n\n const result = {\n total: aggregatedMetric.total,\n timestamp: aggregatedMetric.timestamp,\n entitiesConsidered: aggregatedMetric.entitiesConsidered,\n calculationErrorCount: aggregatedMetric.calculationErrorCount,\n values: thresholds.rules.map(rule => ({\n name: rule.key,\n count: aggregatedMetric.values[rule.key] ?? 0,\n score: options.statusScores[rule.key] ?? 0,\n })),\n thresholds,\n averageScore,\n averageWeightedSum: weightedSum,\n averageMaxPossible: maxPossibleScore,\n aggregationChartDisplayColor,\n } as AggregatedMetricAverageResult;\n\n return AggregatedMetricMapper.toAggregatedMetricResult(\n metric,\n result,\n aggregationConfig,\n );\n }\n\n private calculateWeightedSum(\n values: Pick<AggregatedMetric, 'values'>['values'],\n statusScores: AggregationConfigOptions['statusScores'],\n metricId: string,\n ): number {\n let weightedSum = 0;\n for (const [status, count] of Object.entries(values)) {\n const score = statusScores[status];\n\n if (score === undefined) {\n this.logger.warn(\n `The status \"${status}\" is not in the statusScores for average aggregation of metric \"${metricId}\"`,\n );\n }\n weightedSum += count * (score ?? 0);\n }\n return weightedSum;\n }\n\n private getAggregationChartDisplayColor(\n scorePercent: number,\n thresholds: ThresholdConfig,\n ): string | undefined {\n const thresholdEvaluator = new ThresholdEvaluator();\n\n const matchedThresholdKey = thresholdEvaluator.getFirstMatchingThreshold(\n scorePercent,\n 'number',\n thresholds,\n );\n\n return thresholds.rules.find(r => r.key === matchedThresholdKey)?.color;\n }\n\n private prepareScoreValues(\n numberOfEntities: Pick<AggregatedMetric, 'total'>['total'],\n statusScores: AggregationConfigOptions['statusScores'],\n rules: ThresholdRule[],\n weightedSum: number,\n ): { averageScore: number; maxPossibleScore: number } {\n const statusScoresValues = rules.map(r => statusScores[r.key] ?? 0);\n\n const maxScore = Math.max(0, ...statusScoresValues);\n\n const maxPossibleScore = maxScore * numberOfEntities;\n\n const precision = 1000;\n\n const averageScore =\n numberOfEntities > 0 && maxPossibleScore > 0\n ? Math.round((weightedSum / maxPossibleScore) * precision) / precision\n : 0;\n\n return { averageScore, maxPossibleScore };\n }\n}\n"],"names":["DEFAULT_AVERAGE_KPI_RESULT_THRESHOLDS","AggregatedMetricMapper","ThresholdEvaluator"],"mappings":";;;;;;AAgCO,MAAM,0BAA0D,CAAA;AAAA,EACrE,WAAA,CACmB,QACA,MACjB,EAAA;AAFiB,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AACA,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA;AAChB,EAFgB,MAAA;AAAA,EACA,MAAA;AAAA,EAGnB,MAAM,SAAU,CAAA;AAAA,IACd,UAAA;AAAA,IACA,MAAA;AAAA,IACA,UAAA;AAAA,IACA;AAAA,GACsD,EAAA;AACtD,IAAM,MAAA,EAAE,SAAY,GAAA,iBAAA;AAEpB,IAAI,IAAA,CAAC,SAAS,YAAc,EAAA;AAC1B,MAAA,MAAM,IA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YAAA;AAAA,MACA,QAAA;AAAA,MACA;AAAA,KACF;AAEA,IAAA,OAAO,WAAW,KAAM,CAAA,IAAA,CAAK,OAAK,CAAE,CAAA,GAAA,KAAQ,mBAAmB,CAAG,EAAA,KAAA;AAAA;AACpE,EAEQ,kBACN,CAAA,gBAAA,EACA,YACA,EAAA,KAAA,EACA,WACoD,EAAA;AACpD,IAAM,MAAA,kBAAA,GAAqB,MAAM,GAAI,CAAA,CAAA,CAAA,KAAK,aAAa,CAAE,CAAA,GAAG,KAAK,CAAC,CAAA;AAElE,IAAA,MAAM,QAAW,GAAA,IAAA,CAAK,GAAI,CAAA,CAAA,EAAG,GAAG,kBAAkB,CAAA;AAElD,IAAA,MAAM,mBAAmB,QAAW,GAAA,gBAAA;AAEpC,IAAA,MAAM,SAAY,GAAA,GAAA;AAElB,IAAM,MAAA,YAAA,GACJ,gBAAmB,GAAA,CAAA,IAAK,gBAAmB,GAAA,CAAA,GACvC,IAAK,CAAA,KAAA,CAAO,WAAc,GAAA,gBAAA,GAAoB,SAAS,CAAA,GAAI,SAC3D,GAAA,CAAA;AAEN,IAAO,OAAA,EAAE,cAAc,gBAAiB,EAAA;AAAA;AAE5C;;;;"}
1
+ {"version":3,"file":"AverageAggregationStrategy.cjs.js","sources":["../../../../src/service/aggregations/strategies/AverageAggregationStrategy.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n type AggregatedMetric,\n type AggregatedMetricAverageResult,\n type AggregatedMetricResult,\n type ThresholdConfig,\n ThresholdRule,\n type AggregationConfigOptions,\n} from '@red-hat-developer-hub/backstage-plugin-scorecard-common';\nimport { DEFAULT_AVERAGE_KPI_RESULT_THRESHOLDS } from '../../../constants/aggregationKPIs';\nimport { AggregatedMetricMapper } from '../../mappers';\nimport type { AggregatedMetricLoader } from '../AggregatedMetricLoader';\nimport type { AggregationOptions } from '../types';\nimport type { AggregationStrategy } from './types';\nimport { LoggerService } from '@backstage/backend-plugin-api';\nimport { ThresholdEvaluator } from '../../../threshold/ThresholdEvaluator';\n\nexport class AverageAggregationStrategy implements AggregationStrategy {\n constructor(\n private readonly loader: AggregatedMetricLoader,\n private readonly logger: LoggerService,\n ) {}\n\n async aggregate({\n entityRefs,\n metric,\n thresholds,\n aggregationConfig,\n }: AggregationOptions): Promise<AggregatedMetricResult> {\n const { options } = aggregationConfig;\n\n if (!options?.statusScores) {\n throw new Error(\n `The \"scorecard.aggregationKPIs.${aggregationConfig.id}.options.statusScores\" is required for average aggregation`,\n );\n }\n\n if (!options.thresholds) {\n this.logger.info(\n `The \"scorecard.aggregationKPIs.${aggregationConfig.id}.options.thresholds\" is not configured for average aggregation; ` +\n 'using the default 0–100% health scale (higher is better).',\n );\n }\n\n const headlineThresholds =\n options.thresholds ?? DEFAULT_AVERAGE_KPI_RESULT_THRESHOLDS;\n\n const aggregatedMetric =\n await this.loader.loadStatusGroupedMetricByEntityRefs(\n entityRefs,\n metric.id,\n );\n\n const weightedSum = this.calculateWeightedSum(\n aggregatedMetric.values,\n options.statusScores,\n metric.id,\n );\n\n const { averageScore, maxPossibleScore } = this.prepareScoreValues(\n aggregatedMetric.total,\n options.statusScores,\n thresholds.rules,\n weightedSum,\n );\n\n const scorePercent = averageScore * 100;\n\n const aggregationChartDisplayColor = this.getAggregationChartDisplayColor(\n scorePercent,\n headlineThresholds,\n );\n\n if (!aggregationChartDisplayColor) {\n throw new Error(\n `The color for percentage '${scorePercent}' metric '${metric.id}' is not configured. Check the 'scorecard.aggregationKPIs.${aggregationConfig.id}.options.thresholds' configuration.`,\n );\n }\n\n const result = {\n total: aggregatedMetric.total,\n timestamp: aggregatedMetric.timestamp,\n entitiesConsidered: aggregatedMetric.entitiesConsidered,\n calculationErrorCount: aggregatedMetric.calculationErrorCount,\n values: thresholds.rules.map(rule => ({\n name: rule.key,\n count: aggregatedMetric.values[rule.key] ?? 0,\n score: options.statusScores[rule.key] ?? 0,\n })),\n thresholds,\n averageScore,\n averageWeightedSum: weightedSum,\n averageMaxPossible: maxPossibleScore,\n aggregationChartDisplayColor,\n } as AggregatedMetricAverageResult;\n\n return AggregatedMetricMapper.toAggregatedMetricResult(\n metric,\n result,\n aggregationConfig,\n );\n }\n\n private calculateWeightedSum(\n values: Pick<AggregatedMetric, 'values'>['values'],\n statusScores: AggregationConfigOptions['statusScores'],\n metricId: string,\n ): number {\n let weightedSum = 0;\n for (const [status, count] of Object.entries(values)) {\n const score = statusScores[status];\n\n if (score === undefined) {\n this.logger.warn(\n `The status \"${status}\" is not in the statusScores for average aggregation of metric \"${metricId}\"`,\n );\n }\n weightedSum += count * (score ?? 0);\n }\n return weightedSum;\n }\n\n private getAggregationChartDisplayColor(\n scorePercent: number,\n thresholds: ThresholdConfig,\n ): string | undefined {\n const thresholdEvaluator = new ThresholdEvaluator();\n\n const matchedThresholdKey = thresholdEvaluator.getFirstMatchingThreshold(\n scorePercent,\n 'number',\n thresholds,\n );\n\n return thresholds.rules.find(r => r.key === matchedThresholdKey)?.color;\n }\n\n private prepareScoreValues(\n numberOfEntities: Pick<AggregatedMetric, 'total'>['total'],\n statusScores: AggregationConfigOptions['statusScores'],\n rules: ThresholdRule[],\n weightedSum: number,\n ): { averageScore: number; maxPossibleScore: number } {\n const statusScoresValues = rules.map(r => statusScores[r.key] ?? 0);\n\n const maxScore = Math.max(0, ...statusScoresValues);\n\n const maxPossibleScore = maxScore * numberOfEntities;\n\n const precision = 1000;\n\n const averageScore =\n numberOfEntities > 0 && maxPossibleScore > 0\n ? Math.round((weightedSum / maxPossibleScore) * precision) / precision\n : 0;\n\n return { averageScore, maxPossibleSc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,6 @@ class StatusGroupedAggregationStrategy {
6
6
  constructor(loader) {
7
7
  this.loader = loader;
8
8
  }
9
- loader;
10
9
  async aggregate(options) {
11
10
  const { entityRefs, metric, thresholds, aggregationConfig } = options;
12
11
  const aggregatedMetric = await this.loader.loadStatusGroupedMetricByEntityRefs(
@@ -1 +1 @@
1
- {"version":3,"file":"StatusGroupedAggregationStrategy.cjs.js","sources":["../../../../src/service/aggregations/strategies/StatusGroupedAggregationStrategy.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n AggregatedMetricResult,\n StatusGroupedAggregationResult,\n} from '@red-hat-developer-hub/backstage-plugin-scorecard-common';\nimport { AggregatedMetricMapper } from '../../mappers';\nimport type { AggregatedMetricLoader } from '../AggregatedMetricLoader';\nimport type { AggregationOptions } from '../types';\nimport type { AggregationStrategy } from './types';\n\nexport class StatusGroupedAggregationStrategy implements AggregationStrategy {\n constructor(private readonly loader: AggregatedMetricLoader) {}\n\n async aggregate(\n options: AggregationOptions,\n ): Promise<AggregatedMetricResult> {\n const { entityRefs, metric, thresholds, aggregationConfig } = options;\n\n const aggregatedMetric =\n await this.loader.loadStatusGroupedMetricByEntityRefs(\n entityRefs,\n metric.id,\n );\n\n const result = {\n total: aggregatedMetric.total,\n timestamp: aggregatedMetric.timestamp,\n entitiesConsidered: aggregatedMetric.entitiesConsidered,\n calculationErrorCount: aggregatedMetric.calculationErrorCount,\n values: thresholds.rules.map(rule => ({\n name: rule.key,\n count: aggregatedMetric.values[rule.key] ?? 0,\n })),\n thresholds,\n } as StatusGroupedAggregationResult;\n\n return AggregatedMetricMapper.toAggregatedMetricResult(\n metric,\n result,\n aggregationConfig,\n );\n }\n}\n"],"names":["AggregatedMetricMapper"],"mappings":";;;;AAyBO,MAAM,gCAAgE,CAAA;AAAA,EAC3E,YAA6B,MAAgC,EAAA;AAAhC,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA;AAAiC,EAAjC,MAAA;AAAA,EAE7B,MAAM,UACJ,OACiC,EAAA;AACjC,IAAA,MAAM,EAAE,UAAA,EAAY,MAAQ,EAAA,UAAA,EAAY,mBAAsB,GAAA,OAAA;AAE9D,IAAM,MAAA,gBAAA,GACJ,MAAM,IAAA,CAAK,MAAO,CAAA,mCAAA;AAAA,MAChB,UAAA;AAAA,MACA,MAAO,CAAA;AAAA,KACT;AAEF,IAAA,MAAM,MAAS,GAAA;AAAA,MACb,OAAO,gBAAiB,CAAA,KAAA;AAAA,MACxB,WAAW,gBAAiB,CAAA,SAAA;AAAA,MAC5B,oBAAoB,gBAAiB,CAAA,kBAAA;AAAA,MACrC,uBAAuB,gBAAiB,CAAA,qBAAA;AAAA,MACxC,MAAQ,EAAA,UAAA,CAAW,KAAM,CAAA,GAAA,CAAI,CAAS,IAAA,MAAA;AAAA,QACpC,MAAM,IAAK,CAAA,GAAA;AAAA,QACX,KAAO,EAAA,gBAAA,CAAiB,MAAO,CAAA,IAAA,CAAK,GAAG,CAAK,IAAA;AAAA,OAC5C,CAAA,CAAA;AAAA,MACF;AAAA,KACF;AAEA,IAAA,OAAOA,8BAAuB,CAAA,wBAAA;AAAA,MAC5B,MAAA;AAAA,MACA,MAAA;AAAA,MACA;AAAA,KACF;AAAA;AAEJ;;;;"}
1
+ {"version":3,"file":"StatusGroupedAggregationStrategy.cjs.js","sources":["../../../../src/service/aggregations/strategies/StatusGroupedAggregationStrategy.ts"],"sourcesContent":["/*\n * Copyright Red Hat, Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport type {\n AggregatedMetricResult,\n StatusGroupedAggregationResult,\n} from '@red-hat-developer-hub/backstage-plugin-scorecard-common';\nimport { AggregatedMetricMapper } from '../../mappers';\nimport type { AggregatedMetricLoader } from '../AggregatedMetricLoader';\nimport type { AggregationOptions } from '../types';\nimport type { AggregationStrategy } from './types';\n\nexport class StatusGroupedAggregationStrategy implements AggregationStrategy {\n constructor(private readonly loader: AggregatedMetricLoader) {}\n\n async aggregate(\n options: AggregationOptions,\n ): Promise<AggregatedMetricResult> {\n const { entityRefs, metric, thresholds, aggregationConfig } = options;\n\n const aggregatedMetric =\n await this.loader.loadStatusGroupedMetricByEntityRefs(\n entityRefs,\n metric.id,\n );\n\n const result = {\n total: aggregatedMetric.total,\n timestamp: aggregatedMetric.timestamp,\n entitiesConsidered: aggregatedMetric.entitiesConsidered,\n calculationErrorCount: aggregatedMetric.calculationErrorCount,\n values: thresholds.rules.map(rule => ({\n name: rule.key,\n count: aggregatedMetric.values[rule.key] ?? 0,\n })),\n thresholds,\n } as StatusGroupedAggregationResult;\n\n return AggregatedMetricMapper.toAggregatedMetricResult(\n metric,\n result,\n aggregationConfig,\n );\n }\n}\n"],"names":["AggregatedMetricMapper"],"mappings":";;;;AAyBO,MAAM,gCAAgE,CAAA;AAAA,EAC3E,YAA6B,MAAgC,EAAA;AAAhC,IAAA,IAAA,CAAA,MAAA,GAAA,MAAA;AAAA;AAAiC,EAE9D,MAAM,UACJ,OACiC,EAAA;AACjC,IAAA,MAAM,EAAE,UAAA,EAAY,MAAQ,EAAA,UAAA,EAAY,mBAAsB,GAAA,OAAA;AAE9D,IAAM,MAAA,gBAAA,GACJ,MAAM,IAAA,CAAK,MAAO,CAAA,mCAAA;AAAA,MAChB,UAAA;AAAA,MACA,MAAO,CAAA;AAAA,KACT;AAEF,IAAA,MAAM,MAAS,GAAA;AAAA,MACb,OAAO,gBAAiB,CAAA,KAAA;AAAA,MACxB,WAAW,gBAAiB,CAAA,SAAA;AAAA,MAC5B,oBAAoB,gBAAiB,CAAA,kBAAA;AAAA,MACrC,uBAAuB,gBAAiB,CAAA,qBAAA;AAAA,MACxC,MAAQ,EAAA,UAAA,CAAW,KAAM,CAAA,GAAA,CAAI,CAAS,IAAA,MAAA;AAAA,QACpC,MAAM,IAAK,CAAA,GAAA;AAAA,QACX,KAAO,EAAA,gBAAA,CAAiB,MAAO,CAAA,IAAA,CAAK,GAAG,CAAK,IAAA;AAAA,OAC5C,CAAA,CAAA;AAAA,MACF;AAAA,KACF;AAEA,IAAA,OAAOA,8BAAuB,CAAA,wBAAA;AAAA,MAC5B,MAAA;AAAA,MACA,MAAA;AAAA,MACA;AAAA,KACF;AAAA;AAEJ;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@red-hat-developer-hub/backstage-plugin-scorecard-backend",
3
- "version": "2.7.1",
3
+ "version": "2.7.2",
4
4
  "license": "Apache-2.0",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
@@ -47,8 +47,8 @@
47
47
  "@backstage/plugin-catalog-node": "^2.1.0",
48
48
  "@backstage/plugin-permission-common": "^0.9.7",
49
49
  "@backstage/plugin-permission-node": "^0.10.11",
50
- "@red-hat-developer-hub/backstage-plugin-scorecard-common": "^2.7.1",
51
- "@red-hat-developer-hub/backstage-plugin-scorecard-node": "^2.7.1",
50
+ "@red-hat-developer-hub/backstage-plugin-scorecard-common": "^2.7.2",
51
+ "@red-hat-developer-hub/backstage-plugin-scorecard-node": "^2.7.2",
52
52
  "express": "^4.17.1",
53
53
  "express-promise-router": "^4.1.0",
54
54
  "knex": "^3.1.0",