@backstage/plugin-catalog-backend 1.2.1-next.2 → 1.3.0-next.3

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,56 @@
1
1
  # @backstage/plugin-catalog-backend
2
2
 
3
+ ## 1.3.0-next.3
4
+
5
+ ### Minor Changes
6
+
7
+ - 1dd6c22cc8: Added an option to be able to trigger refreshes on entities based on a prestored arbitrary key.
8
+
9
+ The UrlReaderProcessor, FileReaderProcessor got updated to store the absolute URL of the catalog file as a refresh key. In the format of `<type>:<target>`
10
+ The PlaceholderProcessor got updated to store the resolverValues as refreshKeys for the entities.
11
+
12
+ The custom resolvers will need to be updated to pass in a `CatalogProcessorEmit` function as parameter and they should be updated to emit their refresh processingResults. You can see the updated resolvers in the `PlaceholderProcessor.ts`
13
+
14
+ ```ts
15
+ // yamlPlaceholderResolver
16
+ ...
17
+ const { content, url } = await readTextLocation(params);
18
+
19
+ params.emit(processingResult.refresh(`url:${url}`));
20
+ ...
21
+ ```
22
+
23
+ - 91c1d12123: Export experimental `catalogPlugin` for the new backend system. This export is not considered stable and should not be used in production.
24
+
25
+ ### Patch Changes
26
+
27
+ - 1e02fe46d6: Fixed bug where catalog metrics weren't being tracked.
28
+ - 5f6b847c15: Fix Error Code in Register Component DryRun
29
+ - a70869e775: Updated dependency `msw` to `^0.43.0`.
30
+ - 4e9a90e307: Updated dependency `luxon` to `^3.0.0`.
31
+ - 72622d9143: Updated dependency `yaml` to `^2.0.0`.
32
+ - fa0533e604: CatalogBuilder supports now subscription to processing engine errors.
33
+
34
+ ```ts
35
+ subscribe(options: {
36
+ onProcessingError: (event: { unprocessedEntity: Entity, error: Error }) => Promise<void> | void;
37
+ });
38
+ ```
39
+
40
+ If you want to get notified on errors while processing the entities, you call CatalogBuilder.subscribe
41
+ to get notifications with the parameters defined as above.
42
+
43
+ - 9a6aba1d85: Many symbol declarations have been moved to `@backstage/plugin-catalog-node`. This has no affect on users of this package as they are all re-exported. Modules that build on top of the catalog backend plugin should switch all of their imports to the `@backstage/plugin-catalog-node` package and remove the dependency on `@backstage/plugin-catalog-backend`.
44
+ - Updated dependencies
45
+ - @backstage/backend-plugin-api@0.1.0-next.0
46
+ - @backstage/plugin-catalog-node@1.0.0-next.0
47
+ - @backstage/backend-common@0.14.1-next.3
48
+ - @backstage/catalog-client@1.0.4-next.2
49
+ - @backstage/integration@1.2.2-next.3
50
+ - @backstage/plugin-permission-common@0.6.3-next.1
51
+ - @backstage/plugin-permission-node@0.6.3-next.2
52
+ - @backstage/catalog-model@1.1.0-next.3
53
+
3
54
  ## 1.2.1-next.2
4
55
 
5
56
  ### Patch Changes
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-catalog-backend",
3
- "version": "1.2.1-next.2",
3
+ "version": "1.3.0-next.3",
4
4
  "main": "../dist/index.cjs.js",
5
5
  "types": "../dist/index.alpha.d.ts"
6
6
  }
@@ -6,18 +6,34 @@
6
6
 
7
7
  /// <reference types="node" />
8
8
 
9
+ import { BackendRegistrable } from '@backstage/backend-plugin-api';
9
10
  import { CatalogApi } from '@backstage/catalog-client';
10
11
  import { CatalogEntityDocument } from '@backstage/plugin-catalog-common';
11
- import { CompoundEntityRef } from '@backstage/catalog-model';
12
+ import { CatalogProcessor } from '@backstage/plugin-catalog-node';
13
+ import { CatalogProcessorCache } from '@backstage/plugin-catalog-node';
14
+ import { CatalogProcessorEmit } from '@backstage/plugin-catalog-node';
15
+ import { CatalogProcessorEntityResult } from '@backstage/plugin-catalog-node';
16
+ import { CatalogProcessorErrorResult } from '@backstage/plugin-catalog-node';
17
+ import { CatalogProcessorLocationResult } from '@backstage/plugin-catalog-node';
18
+ import { CatalogProcessorParser } from '@backstage/plugin-catalog-node';
19
+ import { CatalogProcessorRefreshKeysResult } from '@backstage/plugin-catalog-node';
20
+ import { CatalogProcessorRelationResult } from '@backstage/plugin-catalog-node';
21
+ import { CatalogProcessorResult } from '@backstage/plugin-catalog-node';
12
22
  import { ConditionalPolicyDecision } from '@backstage/plugin-permission-common';
13
23
  import { Conditions } from '@backstage/plugin-permission-node';
14
24
  import { Config } from '@backstage/config';
25
+ import { DeferredEntity } from '@backstage/plugin-catalog-node';
15
26
  import { DocumentCollatorFactory } from '@backstage/plugin-search-common';
16
27
  import { Entity } from '@backstage/catalog-model';
17
28
  import { EntityPolicy } from '@backstage/catalog-model';
29
+ import { EntityProvider } from '@backstage/plugin-catalog-node';
30
+ import { EntityProviderConnection } from '@backstage/plugin-catalog-node';
31
+ import { EntityProviderMutation } from '@backstage/plugin-catalog-node';
32
+ import { EntityRelationSpec } from '@backstage/plugin-catalog-node';
18
33
  import { GetEntitiesRequest } from '@backstage/catalog-client';
19
34
  import { JsonValue } from '@backstage/types';
20
35
  import { LocationEntityV1alpha1 } from '@backstage/catalog-model';
36
+ import { LocationSpec } from '@backstage/plugin-catalog-node';
21
37
  import { Logger } from 'winston';
22
38
  import { Permission } from '@backstage/plugin-permission-common';
23
39
  import { PermissionAuthorizer } from '@backstage/plugin-permission-common';
@@ -27,6 +43,7 @@ import { PermissionEvaluator } from '@backstage/plugin-permission-common';
27
43
  import { PermissionRule } from '@backstage/plugin-permission-node';
28
44
  import { PluginDatabaseManager } from '@backstage/backend-common';
29
45
  import { PluginEndpointDiscovery } from '@backstage/backend-common';
46
+ import { processingResult } from '@backstage/plugin-catalog-node';
30
47
  import { Readable } from 'stream';
31
48
  import { ResourcePermission } from '@backstage/plugin-permission-common';
32
49
  import { Router } from 'express';
@@ -151,6 +168,7 @@ export declare class CatalogBuilder {
151
168
  private processors;
152
169
  private processorsReplace;
153
170
  private parser;
171
+ private onProcessingError?;
154
172
  private processingInterval;
155
173
  private locationAnalyzer;
156
174
  private permissionRules;
@@ -282,6 +300,12 @@ export declare class CatalogBuilder {
282
300
  processingEngine: CatalogProcessingEngine;
283
301
  router: Router;
284
302
  }>;
303
+ subscribe(options: {
304
+ onProcessingError: (event: {
305
+ unprocessedEntity: Entity;
306
+ errors: Error[];
307
+ }) => Promise<void> | void;
308
+ }): void;
285
309
  private buildEntityPolicy;
286
310
  private buildProcessors;
287
311
  private checkDeprecatedReaderProcessors;
@@ -321,143 +345,37 @@ export declare type CatalogEnvironment = {
321
345
  */
322
346
  export declare type CatalogPermissionRule<TParams extends unknown[] = unknown[]> = PermissionRule<Entity, EntitiesSearchFilter, 'catalog-entity', TParams>;
323
347
 
348
+ /**
349
+ * Catalog plugin
350
+ * @alpha
351
+ */
352
+ export declare const catalogPlugin: (option: unknown) => BackendRegistrable;
353
+
324
354
  /** @public */
325
355
  export declare interface CatalogProcessingEngine {
326
356
  start(): Promise<void>;
327
357
  stop(): Promise<void>;
328
358
  }
329
359
 
330
- /**
331
- * @public
332
- */
333
- export declare type CatalogProcessor = {
334
- /**
335
- * A unique identifier for the Catalog Processor.
336
- */
337
- getProcessorName(): string;
338
- /**
339
- * Reads the contents of a location.
340
- *
341
- * @param location - The location to read
342
- * @param optional - Whether a missing target should trigger an error
343
- * @param emit - A sink for items resulting from the read
344
- * @param parser - A parser, that is able to take the raw catalog descriptor
345
- * data and turn it into the actual result pieces.
346
- * @param cache - A cache for storing values local to this processor and the current entity.
347
- * @returns True if handled by this processor, false otherwise
348
- */
349
- readLocation?(location: LocationSpec, optional: boolean, emit: CatalogProcessorEmit, parser: CatalogProcessorParser, cache: CatalogProcessorCache): Promise<boolean>;
350
- /**
351
- * Pre-processes an emitted entity, after it has been emitted but before it
352
- * has been validated.
353
- *
354
- * This type of processing usually involves enriching the entity with
355
- * additional data, and the input entity may actually still be incomplete
356
- * when the processor is invoked.
357
- *
358
- * @param entity - The (possibly partial) entity to process
359
- * @param location - The location that the entity came from
360
- * @param emit - A sink for auxiliary items resulting from the processing
361
- * @param originLocation - The location that the entity originally came from.
362
- * While location resolves to the direct parent location, originLocation
363
- * tells which location was used to start the ingestion loop.
364
- * @param cache - A cache for storing values local to this processor and the current entity.
365
- * @returns The same entity or a modified version of it
366
- */
367
- preProcessEntity?(entity: Entity, location: LocationSpec, emit: CatalogProcessorEmit, originLocation: LocationSpec, cache: CatalogProcessorCache): Promise<Entity>;
368
- /**
369
- * Validates the entity as a known entity kind, after it has been pre-
370
- * processed and has passed through basic overall validation.
371
- *
372
- * @param entity - The entity to validate
373
- * @returns Resolves to true, if the entity was of a kind that was known and
374
- * handled by this processor, and was found to be valid. Resolves to false,
375
- * if the entity was not of a kind that was known by this processor.
376
- * Rejects to an Error describing the problem, if the entity was of a kind
377
- * that was known by this processor and was not valid.
378
- */
379
- validateEntityKind?(entity: Entity): Promise<boolean>;
380
- /**
381
- * Post-processes an emitted entity, after it has been validated.
382
- *
383
- * @param entity - The entity to process
384
- * @param location - The location that the entity came from
385
- * @param emit - A sink for auxiliary items resulting from the processing
386
- * @param cache - A cache for storing values local to this processor and the current entity.
387
- * @returns The same entity or a modified version of it
388
- */
389
- postProcessEntity?(entity: Entity, location: LocationSpec, emit: CatalogProcessorEmit, cache: CatalogProcessorCache): Promise<Entity>;
390
- };
360
+ export { CatalogProcessor }
391
361
 
392
- /**
393
- * A cache for storing data during processing.
394
- *
395
- * The values stored in the cache are always local to each processor, meaning
396
- * no processor can see cache values from other processors.
397
- *
398
- * The cache instance provided to the CatalogProcessor is also scoped to the
399
- * entity being processed, meaning that each processor run can't see cache
400
- * values from processing runs for other entities.
401
- *
402
- * Values that are set during a processing run will only be visible in the directly
403
- * following run. The cache will be overwritten every run unless no new cache items
404
- * are written, in which case the existing values remain in the cache.
405
- *
406
- * @public
407
- */
408
- export declare interface CatalogProcessorCache {
409
- /**
410
- * Retrieve a value from the cache.
411
- */
412
- get<ItemType extends JsonValue>(key: string): Promise<ItemType | undefined>;
413
- /**
414
- * Store a value in the cache.
415
- */
416
- set<ItemType extends JsonValue>(key: string, value: ItemType): Promise<void>;
417
- }
362
+ export { CatalogProcessorCache }
418
363
 
419
- /** @public */
420
- export declare type CatalogProcessorEmit = (generated: CatalogProcessorResult) => void;
364
+ export { CatalogProcessorEmit }
421
365
 
422
- /** @public */
423
- export declare type CatalogProcessorEntityResult = {
424
- type: 'entity';
425
- entity: Entity;
426
- location: LocationSpec;
427
- };
366
+ export { CatalogProcessorEntityResult }
428
367
 
429
- /** @public */
430
- export declare type CatalogProcessorErrorResult = {
431
- type: 'error';
432
- error: Error;
433
- location: LocationSpec;
434
- };
368
+ export { CatalogProcessorErrorResult }
435
369
 
436
- /** @public */
437
- export declare type CatalogProcessorLocationResult = {
438
- type: 'location';
439
- location: LocationSpec;
440
- };
370
+ export { CatalogProcessorLocationResult }
441
371
 
442
- /**
443
- * A parser, that is able to take the raw catalog descriptor data and turn it
444
- * into the actual result pieces. The default implementation performs a YAML
445
- * document parsing.
446
- * @public
447
- */
448
- export declare type CatalogProcessorParser = (options: {
449
- data: Buffer;
450
- location: LocationSpec;
451
- }) => AsyncIterable<CatalogProcessorResult>;
372
+ export { CatalogProcessorParser }
452
373
 
453
- /** @public */
454
- export declare type CatalogProcessorRelationResult = {
455
- type: 'relation';
456
- relation: EntityRelationSpec;
457
- };
374
+ export { CatalogProcessorRefreshKeysResult }
458
375
 
459
- /** @public */
460
- export declare type CatalogProcessorResult = CatalogProcessorLocationResult | CatalogProcessorEntityResult | CatalogProcessorRelationResult | CatalogProcessorErrorResult;
376
+ export { CatalogProcessorRelationResult }
377
+
378
+ export { CatalogProcessorResult }
461
379
 
462
380
  /** @public */
463
381
  export declare class CodeOwnersProcessor implements CatalogProcessor {
@@ -585,14 +503,7 @@ export declare type DefaultCatalogCollatorFactoryOptions = {
585
503
  catalogClient?: CatalogApi;
586
504
  };
587
505
 
588
- /**
589
- * Entities that are not yet processed.
590
- * @public
591
- */
592
- export declare type DeferredEntity = {
593
- entity: Entity;
594
- locationKey?: string;
595
- };
506
+ export { DeferredEntity }
596
507
 
597
508
  /**
598
509
  * Matches rows in the search table.
@@ -629,64 +540,13 @@ export declare type EntityFilter = {
629
540
  not: EntityFilter;
630
541
  } | EntitiesSearchFilter;
631
542
 
632
- /**
633
- * An EntityProvider is able to provide entities to the catalog.
634
- * See https://backstage.io/docs/features/software-catalog/life-of-an-entity for more details.
635
- * @public
636
- */
637
- export declare interface EntityProvider {
638
- /** Unique provider name used internally for caching. */
639
- getProviderName(): string;
640
- /** Connect is called upon initialization by the catalog engine. */
641
- connect(connection: EntityProviderConnection): Promise<void>;
642
- }
543
+ export { EntityProvider }
643
544
 
644
- /**
645
- * The EntityProviderConnection is the connection between the catalog and the entity provider.
646
- * The EntityProvider use this connection to add and remove entities from the catalog.
647
- * @public
648
- */
649
- export declare interface EntityProviderConnection {
650
- /**
651
- * Applies either a full or delta update to the catalog engine.
652
- */
653
- applyMutation(mutation: EntityProviderMutation): Promise<void>;
654
- }
545
+ export { EntityProviderConnection }
655
546
 
656
- /**
657
- * @public
658
- * A 'full' mutation replaces all existing entities created by this entity provider with new ones.
659
- * A 'delta' mutation can both add and remove entities provided by this provider. Previously provided
660
- * entities from a 'full' mutation are not removed.
661
- */
662
- export declare type EntityProviderMutation = {
663
- type: 'full';
664
- entities: DeferredEntity[];
665
- } | {
666
- type: 'delta';
667
- added: DeferredEntity[];
668
- removed: DeferredEntity[];
669
- };
547
+ export { EntityProviderMutation }
670
548
 
671
- /**
672
- * Holds the relation data for entities.
673
- *
674
- * @public
675
- */
676
- export declare type EntityRelationSpec = {
677
- /**
678
- * The source entity of this relation.
679
- */
680
- source: CompoundEntityRef;
681
- /**
682
- * The type of the relation.
683
- */
684
- type: string;
685
- /**
686
- * The target entity of this relation.
687
- */
688
- target: CompoundEntityRef;
689
- };
549
+ export { EntityRelationSpec }
690
550
 
691
551
  /** @public */
692
552
  export declare class FileReaderProcessor implements CatalogProcessor {
@@ -718,22 +578,7 @@ export declare type LocationEntityProcessorOptions = {
718
578
  integrations: ScmIntegrationRegistry;
719
579
  };
720
580
 
721
- /**
722
- * Holds the entity location information.
723
- *
724
- * @remarks
725
- *
726
- * `presence` flag: when using repo importer plugin, location is being created before the component yaml file is merged to the main branch.
727
- * This flag is then set to indicate that the file can be not present.
728
- * default value: 'required'.
729
- *
730
- * @public
731
- */
732
- export declare type LocationSpec = {
733
- type: string;
734
- target: string;
735
- presence?: 'optional' | 'required';
736
- };
581
+ export { LocationSpec }
737
582
 
738
583
  /** @public */
739
584
  export declare function locationSpecToLocationEntity(opts: {
@@ -768,7 +613,7 @@ export declare class PlaceholderProcessor implements CatalogProcessor {
768
613
  private readonly options;
769
614
  constructor(options: PlaceholderProcessorOptions);
770
615
  getProcessorName(): string;
771
- preProcessEntity(entity: Entity, location: LocationSpec): Promise<Entity>;
616
+ preProcessEntity(entity: Entity, location: LocationSpec, emit: CatalogProcessorEmit): Promise<Entity>;
772
617
  }
773
618
 
774
619
  /** @public */
@@ -788,6 +633,7 @@ export declare type PlaceholderResolverParams = {
788
633
  baseUrl: string;
789
634
  read: PlaceholderResolverRead;
790
635
  resolveUrl: PlaceholderResolverResolveUrl;
636
+ emit: CatalogProcessorEmit;
791
637
  };
792
638
 
793
639
  /** @public */
@@ -802,19 +648,7 @@ export declare type PlaceholderResolverResolveUrl = (url: string, base: string)
802
648
  */
803
649
  export declare type ProcessingIntervalFunction = () => number;
804
650
 
805
- /**
806
- * Factory functions for the standard processing result types.
807
- *
808
- * @public
809
- */
810
- export declare const processingResult: Readonly<{
811
- readonly notFoundError: (atLocation: LocationSpec, message: string) => CatalogProcessorResult;
812
- readonly inputError: (atLocation: LocationSpec, message: string) => CatalogProcessorResult;
813
- readonly generalError: (atLocation: LocationSpec, message: string) => CatalogProcessorResult;
814
- readonly location: (newLocation: LocationSpec) => CatalogProcessorResult;
815
- readonly entity: (atLocation: LocationSpec, newEntity: Entity) => CatalogProcessorResult;
816
- readonly relation: (spec: EntityRelationSpec) => CatalogProcessorResult;
817
- }>;
651
+ export { processingResult }
818
652
 
819
653
  /**
820
654
  * Makes all keys of an entire hierarchy optional.