From 4024b374495a8e9ad216fbc93dd2411b63249719 Mon Sep 17 00:00:00 2001 From: "Fernando.Teixeira" Date: Wed, 25 Jan 2023 14:09:15 -0500 Subject: [PATCH 1/4] feat(tech-inights): adds getFactSchemas method to client Signed-off-by: Fernando.Teixeira --- .changeset/four-candles-add.md | 18 ++++++ .../src/service/fact/FactRetrieverRegistry.ts | 2 +- plugins/tech-insights-common/src/index.ts | 57 ++++++++++++++++++ plugins/tech-insights-node/src/facts.ts | 58 +------------------ plugins/tech-insights-node/src/persistence.ts | 2 +- .../tech-insights/src/api/TechInsightsApi.ts | 2 + .../src/api/TechInsightsClient.ts | 5 ++ 7 files changed, 85 insertions(+), 59 deletions(-) create mode 100644 .changeset/four-candles-add.md diff --git a/.changeset/four-candles-add.md b/.changeset/four-candles-add.md new file mode 100644 index 0000000000..bf465181b1 --- /dev/null +++ b/.changeset/four-candles-add.md @@ -0,0 +1,18 @@ +--- +'@backstage/plugin-tech-insights-backend': minor +'@backstage/plugin-tech-insights-common': minor +'@backstage/plugin-tech-insights-node': minor +'@backstage/plugin-tech-insights': minor +--- + +TechInsightsApi interface now has getFactSchemas() method. +TechInsightsClient now implements method getFactSchemas(). + +**BREAKING** FactSchema type moved from @backstage/plugin-tech-insights-node into @backstage/plugin-tech-insights-common + +These changes are **required** if you were importing this type directly. + +```diff +- import { FactSchema } from '@backstage/plugin-tech-insights-node'; ++ import { FactSchema } from '@backstage/plugin-tech-insights-common'; +``` diff --git a/plugins/tech-insights-backend/src/service/fact/FactRetrieverRegistry.ts b/plugins/tech-insights-backend/src/service/fact/FactRetrieverRegistry.ts index 62adbad8e3..8796f1511a 100644 --- a/plugins/tech-insights-backend/src/service/fact/FactRetrieverRegistry.ts +++ b/plugins/tech-insights-backend/src/service/fact/FactRetrieverRegistry.ts @@ -17,8 +17,8 @@ import { FactRetriever, FactRetrieverRegistration, - FactSchema, } from '@backstage/plugin-tech-insights-node'; +import { FactSchema } from '@backstage/plugin-tech-insights-common'; import { ConflictError, NotFoundError } from '@backstage/errors'; /** diff --git a/plugins/tech-insights-common/src/index.ts b/plugins/tech-insights-common/src/index.ts index 66af5c2f93..a74c1f16e9 100644 --- a/plugins/tech-insights-common/src/index.ts +++ b/plugins/tech-insights-common/src/index.ts @@ -134,3 +134,60 @@ export type BulkCheckResponse = Array<{ entity: string; results: CheckResult[]; }>; + +/** + * A record type to specify individual fact shapes + * + * Used as part of a schema to validate, identify and generically construct usage implementations + * of individual fact values in the system. + * + * @public + */ +export type FactSchema = { + /** + * Name of the fact + */ + [name: string]: { + /** + * Type of the individual fact value + * + * Numbers are split into integers and floating point values. + * `set` indicates a collection of values, `object` indicates JSON serializable value + */ + type: + | 'integer' + | 'float' + | 'string' + | 'boolean' + | 'datetime' + | 'set' + | 'object'; + + /** + * A description of this individual fact value + */ + description: string; + + /** + * Optional semver string to indicate when this specific fact definition was added to the schema + */ + since?: string; + + /** + * Metadata related to an individual fact. + * Can contain links, additional description texts and other actionable data. + * + * Currently loosely typed, but in the future when patterns emerge, key shapes can be defined + * + * examples: + * ``` + * \{ + * link: 'https://sonarqube.mycompany.com/fix-these-issues', + * suggestion: 'To affect this value, you can do x, y, z', + * minValue: 0 + * \} + * ``` + */ + metadata?: Record; + }; +}; diff --git a/plugins/tech-insights-node/src/facts.ts b/plugins/tech-insights-node/src/facts.ts index a4a0834970..3619f8b66f 100644 --- a/plugins/tech-insights-node/src/facts.ts +++ b/plugins/tech-insights-node/src/facts.ts @@ -20,6 +20,7 @@ import { PluginEndpointDiscovery, TokenManager, } from '@backstage/backend-common'; +import { FactSchema } from '@backstage/plugin-tech-insights-common'; import { Logger } from 'winston'; /** @@ -79,63 +80,6 @@ export type FlatTechInsightFact = TechInsightFact & { id: string; }; -/** - * A record type to specify individual fact shapes - * - * Used as part of a schema to validate, identify and generically construct usage implementations - * of individual fact values in the system. - * - * @public - */ -export type FactSchema = { - /** - * Name of the fact - */ - [name: string]: { - /** - * Type of the individual fact value - * - * Numbers are split into integers and floating point values. - * `set` indicates a collection of values, `object` indicates JSON serializable value - */ - type: - | 'integer' - | 'float' - | 'string' - | 'boolean' - | 'datetime' - | 'set' - | 'object'; - - /** - * A description of this individual fact value - */ - description: string; - - /** - * Optional semver string to indicate when this specific fact definition was added to the schema - */ - since?: string; - - /** - * Metadata related to an individual fact. - * Can contain links, additional description texts and other actionable data. - * - * Currently loosely typed, but in the future when patterns emerge, key shapes can be defined - * - * examples: - * ``` - * \{ - * link: 'https://sonarqube.mycompany.com/fix-these-issues', - * suggestion: 'To affect this value, you can do x, y, z', - * minValue: 0 - * \} - * ``` - */ - metadata?: Record; - }; -}; - /** * @public * diff --git a/plugins/tech-insights-node/src/persistence.ts b/plugins/tech-insights-node/src/persistence.ts index 31fda403a8..73abb6c5af 100644 --- a/plugins/tech-insights-node/src/persistence.ts +++ b/plugins/tech-insights-node/src/persistence.ts @@ -14,13 +14,13 @@ * limitations under the License. */ import { - FactSchema, TechInsightFact, FlatTechInsightFact, FactSchemaDefinition, FactLifecycle, } from './facts'; import { DateTime } from 'luxon'; +import { FactSchema } from '@backstage/plugin-tech-insights-common'; /** * TechInsights Database diff --git a/plugins/tech-insights/src/api/TechInsightsApi.ts b/plugins/tech-insights/src/api/TechInsightsApi.ts index 166f1d2782..bb915e06dd 100644 --- a/plugins/tech-insights/src/api/TechInsightsApi.ts +++ b/plugins/tech-insights/src/api/TechInsightsApi.ts @@ -18,6 +18,7 @@ import { createApiRef } from '@backstage/core-plugin-api'; import { CheckResult, BulkCheckResponse, + FactSchema, } from '@backstage/plugin-tech-insights-common'; import { Check, InsightFacts } from './types'; import { CheckResultRenderer } from '../components/CheckResultRenderer'; @@ -49,4 +50,5 @@ export interface TechInsightsApi { checks?: Check[], ): Promise; getFacts(entity: CompoundEntityRef, facts: string[]): Promise; + getFactSchemas(): Promise; } diff --git a/plugins/tech-insights/src/api/TechInsightsClient.ts b/plugins/tech-insights/src/api/TechInsightsClient.ts index 6e85769b34..a1a2e7ff77 100644 --- a/plugins/tech-insights/src/api/TechInsightsClient.ts +++ b/plugins/tech-insights/src/api/TechInsightsClient.ts @@ -18,6 +18,7 @@ import { TechInsightsApi } from './TechInsightsApi'; import { BulkCheckResponse, CheckResult, + FactSchema, } from '@backstage/plugin-tech-insights-common'; import { Check, InsightFacts } from './types'; import { DiscoveryApi, IdentityApi } from '@backstage/core-plugin-api'; @@ -69,6 +70,10 @@ export class TechInsightsClient implements TechInsightsApi { return this.api('/checks'); } + async getFactSchemas(): Promise { + return this.api('/fact-schemas'); + } + async runChecks( entityParams: CompoundEntityRef, checks?: string[], From f44199533a02b9e404c3079c4e0b167f96993afc Mon Sep 17 00:00:00 2001 From: "Fernando.Teixeira" Date: Wed, 25 Jan 2023 14:28:51 -0500 Subject: [PATCH 2/4] fix(tech-inisghts): fix reference to FactSchema type Signed-off-by: Fernando.Teixeira --- .../src/service/persistence/TechInsightsDatabase.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/tech-insights-backend/src/service/persistence/TechInsightsDatabase.ts b/plugins/tech-insights-backend/src/service/persistence/TechInsightsDatabase.ts index 7c2ba52717..c8f098a895 100644 --- a/plugins/tech-insights-backend/src/service/persistence/TechInsightsDatabase.ts +++ b/plugins/tech-insights-backend/src/service/persistence/TechInsightsDatabase.ts @@ -16,12 +16,12 @@ import { Knex } from 'knex'; import { FactLifecycle, - FactSchema, FactSchemaDefinition, FlatTechInsightFact, TechInsightFact, TechInsightsStore, } from '@backstage/plugin-tech-insights-node'; +import { FactSchema } from '@backstage/plugin-tech-insights-common'; import { rsort } from 'semver'; import { groupBy, omit } from 'lodash'; import { DateTime } from 'luxon'; From 9d59c101c8d836b1c1a22e695980e724a2c7266d Mon Sep 17 00:00:00 2001 From: "Fernando.Teixeira" Date: Wed, 25 Jan 2023 15:03:16 -0500 Subject: [PATCH 3/4] chore(api-report): update api report for tech-inisghts Signed-off-by: Fernando.Teixeira --- plugins/tech-insights-backend/api-report.md | 2 +- plugins/tech-insights-common/api-report.md | 17 +++++++++++++++++ plugins/tech-insights-node/api-report.md | 18 +----------------- plugins/tech-insights/api-report.md | 5 +++++ 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/plugins/tech-insights-backend/api-report.md b/plugins/tech-insights-backend/api-report.md index a757f0d67c..4b6e5b34dc 100644 --- a/plugins/tech-insights-backend/api-report.md +++ b/plugins/tech-insights-backend/api-report.md @@ -12,7 +12,7 @@ import { FactCheckerFactory } from '@backstage/plugin-tech-insights-node'; import { FactLifecycle } from '@backstage/plugin-tech-insights-node'; import { FactRetriever } from '@backstage/plugin-tech-insights-node'; import { FactRetrieverRegistration } from '@backstage/plugin-tech-insights-node'; -import { FactSchema } from '@backstage/plugin-tech-insights-node'; +import { FactSchema } from '@backstage/plugin-tech-insights-common'; import { HumanDuration } from '@backstage/types'; import { Logger } from 'winston'; import { PluginDatabaseManager } from '@backstage/backend-common'; diff --git a/plugins/tech-insights-common/api-report.md b/plugins/tech-insights-common/api-report.md index 0236c0619a..51ef13a013 100644 --- a/plugins/tech-insights-common/api-report.md +++ b/plugins/tech-insights-common/api-report.md @@ -47,5 +47,22 @@ export type FactResponse = { }; }; +// @public +export type FactSchema = { + [name: string]: { + type: + | 'integer' + | 'float' + | 'string' + | 'boolean' + | 'datetime' + | 'set' + | 'object'; + description: string; + since?: string; + metadata?: Record; + }; +}; + // (No @packageDocumentation comment for this package) ``` diff --git a/plugins/tech-insights-node/api-report.md b/plugins/tech-insights-node/api-report.md index 47e76b07ce..dbb8a8b674 100644 --- a/plugins/tech-insights-node/api-report.md +++ b/plugins/tech-insights-node/api-report.md @@ -8,6 +8,7 @@ import { Config } from '@backstage/config'; import { DateTime } from 'luxon'; import { Duration } from 'luxon'; import { DurationLike } from 'luxon'; +import { FactSchema } from '@backstage/plugin-tech-insights-common'; import { HumanDuration } from '@backstage/types'; import { JsonValue } from '@backstage/types'; import { Logger } from 'winston'; @@ -78,23 +79,6 @@ export type FactRetrieverRegistration = { initialDelay?: Duration | HumanDuration; }; -// @public -export type FactSchema = { - [name: string]: { - type: - | 'integer' - | 'float' - | 'string' - | 'boolean' - | 'datetime' - | 'set' - | 'object'; - description: string; - since?: string; - metadata?: Record; - }; -}; - // @public export type FactSchemaDefinition = Omit; diff --git a/plugins/tech-insights/api-report.md b/plugins/tech-insights/api-report.md index 2d25d6d39d..d7ae337196 100644 --- a/plugins/tech-insights/api-report.md +++ b/plugins/tech-insights/api-report.md @@ -11,6 +11,7 @@ import { BulkCheckResponse } from '@backstage/plugin-tech-insights-common'; import { CheckResult } from '@backstage/plugin-tech-insights-common'; import { CompoundEntityRef } from '@backstage/catalog-model'; import { DiscoveryApi } from '@backstage/core-plugin-api'; +import { FactSchema } from '@backstage/plugin-tech-insights-common'; import { IdentityApi } from '@backstage/core-plugin-api'; import { JsonValue } from '@backstage/types'; import { default as React_2 } from 'react'; @@ -74,6 +75,8 @@ export interface TechInsightsApi { // (undocumented) getFacts(entity: CompoundEntityRef, facts: string[]): Promise; // (undocumented) + getFactSchemas(): Promise; + // (undocumented) runBulkChecks( entities: CompoundEntityRef[], checks?: Check[], @@ -102,6 +105,8 @@ export class TechInsightsClient implements TechInsightsApi { // (undocumented) getFacts(entity: CompoundEntityRef, facts: string[]): Promise; // (undocumented) + getFactSchemas(): Promise; + // (undocumented) runBulkChecks( entities: CompoundEntityRef[], checks?: Check[], From bab5359789f071cc10272fd5aac8de399cb7e5b1 Mon Sep 17 00:00:00 2001 From: "Fernando.Teixeira" Date: Mon, 30 Jan 2023 09:27:07 -0500 Subject: [PATCH 4/4] chore(tech-insights): update changeset for non-breaking packages Signed-off-by: Fernando.Teixeira --- .changeset/four-candles-add.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.changeset/four-candles-add.md b/.changeset/four-candles-add.md index bf465181b1..fa975e0a58 100644 --- a/.changeset/four-candles-add.md +++ b/.changeset/four-candles-add.md @@ -1,8 +1,8 @@ --- -'@backstage/plugin-tech-insights-backend': minor -'@backstage/plugin-tech-insights-common': minor +'@backstage/plugin-tech-insights-backend': patch +'@backstage/plugin-tech-insights-common': patch '@backstage/plugin-tech-insights-node': minor -'@backstage/plugin-tech-insights': minor +'@backstage/plugin-tech-insights': patch --- TechInsightsApi interface now has getFactSchemas() method.