diff --git a/plugins/inventory-backend/src/inventory/AggregatorInventory.ts b/plugins/inventory-backend/src/inventory/AggregatorInventory.ts index b768b8eb23..59ee72067b 100644 --- a/plugins/inventory-backend/src/inventory/AggregatorInventory.ts +++ b/plugins/inventory-backend/src/inventory/AggregatorInventory.ts @@ -18,17 +18,19 @@ import { NotFoundError } from '@backstage/backend-common'; import { Component, Inventory } from './types'; export class AggregatorInventory implements Inventory { - inventories: Inventory[] = []; + #inventories: Inventory[] = []; - async list(): Promise { - const lists = await Promise.all(this.inventories.map((i) => i.list())); + async components(): Promise { + const lists = await Promise.all( + this.#inventories.map((i) => i.components()), + ); return lists.flat(); } - item(id: string): Promise { + component(id: string): Promise { return new Promise((resolve, reject) => { - const promises = this.inventories.map((i) => - i.item(id).then(resolve, () => { + const promises = this.#inventories.map((i) => + i.component(id).then(resolve, () => { // For now, just swallow errors in individual inventories; // should handle partial errors better }), @@ -40,6 +42,6 @@ export class AggregatorInventory implements Inventory { } enlist(inventory: Inventory) { - this.inventories.push(inventory); + this.#inventories.push(inventory); } } diff --git a/plugins/inventory-backend/src/inventory/StaticInventory.ts b/plugins/inventory-backend/src/inventory/StaticInventory.ts index 4569ae8ed2..6b4c29d229 100644 --- a/plugins/inventory-backend/src/inventory/StaticInventory.ts +++ b/plugins/inventory-backend/src/inventory/StaticInventory.ts @@ -18,14 +18,18 @@ import { NotFoundError } from '@backstage/backend-common'; import { Component, Inventory } from './types'; export class StaticInventory implements Inventory { - constructor(private components: Component[]) {} + #components: Component[]; - async list(): Promise { - return this.components.slice(); + constructor(components: Component[]) { + this.#components = components; } - async item(id: string): Promise { - const item = this.components.find((i) => i.id === id); + async components(): Promise { + return this.#components.slice(); + } + + async component(id: string): Promise { + const item = this.#components.find((i) => i.id === id); if (!item) { throw new NotFoundError(`Found no component with ID ${id}`); } diff --git a/plugins/inventory-backend/src/inventory/types.ts b/plugins/inventory-backend/src/inventory/types.ts index 863dccb291..4417035d85 100644 --- a/plugins/inventory-backend/src/inventory/types.ts +++ b/plugins/inventory-backend/src/inventory/types.ts @@ -19,6 +19,6 @@ export type Component = { }; export type Inventory = { - list(): Promise; - item(id: string): Promise; + components(): Promise; + component(id: string): Promise; }; diff --git a/plugins/inventory-backend/src/service/router.ts b/plugins/inventory-backend/src/service/router.ts index a05fac08be..2d093fe41e 100644 --- a/plugins/inventory-backend/src/service/router.ts +++ b/plugins/inventory-backend/src/service/router.ts @@ -32,13 +32,13 @@ export async function createRouter( const router = Router(); router - .get('/', async (req, res) => { - const components = await inventory.list(); + .get('/components', async (req, res) => { + const components = await inventory.components(); res.status(200).send(components); }) - .get('/:id', async (req, res) => { + .get('/components/:id', async (req, res) => { const { id } = req.params; - const component = await inventory.item(id); + const component = await inventory.component(id); res.status(200).send(component); }); diff --git a/plugins/inventory-backend/tsconfig.json b/plugins/inventory-backend/tsconfig.json index dd13cfe1bc..015a967f76 100644 --- a/plugins/inventory-backend/tsconfig.json +++ b/plugins/inventory-backend/tsconfig.json @@ -6,7 +6,7 @@ "sourceMap": true, "declaration": true, "strict": true, - "target": "es5", + "target": "es2019", "module": "commonjs", "esModuleInterop": true, "lib": ["es2019"],