@backstage/plugin-scaffolder-backend 1.12.0-next.2 → 1.12.0

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/dist/index.cjs.js CHANGED
@@ -291,17 +291,31 @@ const examples$1 = [
291
291
  }
292
292
  ]
293
293
  })
294
+ },
295
+ {
296
+ description: "Fetch multiple entities by referencse",
297
+ example: yaml__default["default"].stringify({
298
+ steps: [
299
+ {
300
+ action: id$1,
301
+ id: "fetchMultiple",
302
+ name: "Fetch catalog entities",
303
+ input: {
304
+ entityRefs: ["component:default/name"]
305
+ }
306
+ }
307
+ ]
308
+ })
294
309
  }
295
310
  ];
296
311
  function createFetchCatalogEntityAction(options) {
297
312
  const { catalogClient } = options;
298
313
  return pluginScaffolderNode.createTemplateAction({
299
314
  id: id$1,
300
- description: "Returns entity from the catalog by entity reference",
315
+ description: "Returns entity or entities from the catalog by entity reference(s)",
301
316
  examples: examples$1,
302
317
  schema: {
303
318
  input: {
304
- required: ["entityRef"],
305
319
  type: "object",
306
320
  properties: {
307
321
  entityRef: {
@@ -309,9 +323,14 @@ function createFetchCatalogEntityAction(options) {
309
323
  title: "Entity reference",
310
324
  description: "Entity reference of the entity to get"
311
325
  },
326
+ entityRefs: {
327
+ type: "array",
328
+ title: "Entity references",
329
+ description: "Entity references of the entities to get"
330
+ },
312
331
  optional: {
313
332
  title: "Optional",
314
- description: "Permit the entity to optionally exist. Default: false",
333
+ description: "Allow the entity or entities to optionally exist. Default: false",
315
334
  type: "boolean"
316
335
  }
317
336
  }
@@ -322,28 +341,50 @@ function createFetchCatalogEntityAction(options) {
322
341
  entity: {
323
342
  title: "Entity found by the entity reference",
324
343
  type: "object",
325
- description: "Object containing same values used in the Entity schema."
344
+ description: "Object containing same values used in the Entity schema. Only when used with `entityRef` parameter."
345
+ },
346
+ entities: {
347
+ title: "Entities found by the entity references",
348
+ type: "array",
349
+ items: { type: "object" },
350
+ description: "Array containing objects with same values used in the Entity schema. Only when used with `entityRefs` parameter."
326
351
  }
327
352
  }
328
353
  }
329
354
  },
330
355
  async handler(ctx) {
331
- var _a;
332
- const { entityRef, optional } = ctx.input;
333
- let entity;
334
- try {
335
- entity = await catalogClient.getEntityByRef(entityRef, {
356
+ var _a, _b;
357
+ const { entityRef, entityRefs, optional } = ctx.input;
358
+ if (!entityRef && !entityRefs) {
359
+ if (optional) {
360
+ return;
361
+ }
362
+ throw new Error("Missing entity reference or references");
363
+ }
364
+ if (entityRef) {
365
+ const entity = await catalogClient.getEntityByRef(entityRef, {
336
366
  token: (_a = ctx.secrets) == null ? void 0 : _a.backstageToken
337
367
  });
338
- } catch (e) {
339
- if (!optional) {
340
- throw e;
368
+ if (!entity && !optional) {
369
+ throw new Error(`Entity ${entityRef} not found`);
341
370
  }
371
+ ctx.output("entity", entity != null ? entity : null);
342
372
  }
343
- if (!entity && !optional) {
344
- throw new Error(`Entity ${entityRef} not found`);
373
+ if (entityRefs) {
374
+ const entities = await catalogClient.getEntitiesByRefs(
375
+ { entityRefs },
376
+ {
377
+ token: (_b = ctx.secrets) == null ? void 0 : _b.backstageToken
378
+ }
379
+ );
380
+ const finalEntities = entities.items.map((e, i) => {
381
+ if (!e && !optional) {
382
+ throw new Error(`Entity ${entityRefs[i]} not found`);
383
+ }
384
+ return e != null ? e : null;
385
+ });
386
+ ctx.output("entities", finalEntities);
345
387
  }
346
- ctx.output("entity", entity != null ? entity : null);
347
388
  }
348
389
  });
349
390
  }