Merge pull request #24376 from marleypowell/marley/provide-default-events-factory

fix: added `eventsServiceFactory` to `defaultServiceFactories`
This commit is contained in:
Ben Lambert
2024-05-07 12:46:35 +02:00
committed by GitHub
11 changed files with 60 additions and 16 deletions
+7
View File
@@ -0,0 +1,7 @@
---
'@backstage/backend-test-utils': patch
'@backstage/backend-defaults': patch
'@backstage/plugin-events-node': patch
---
added `eventsServiceFactory` to `defaultServiceFactories` to resolve issue where different instances of the EventsServices could be used
+2 -1
View File
@@ -33,7 +33,8 @@
},
"dependencies": {
"@backstage/backend-app-api": "workspace:^",
"@backstage/backend-common": "workspace:^"
"@backstage/backend-common": "workspace:^",
"@backstage/plugin-events-node": "workspace:^"
},
"devDependencies": {
"@backstage/backend-plugin-api": "workspace:^",
@@ -36,6 +36,7 @@ import {
httpAuthServiceFactory,
userInfoServiceFactory,
} from '@backstage/backend-app-api';
import { eventsServiceFactory } from '@backstage/plugin-events-node';
export const defaultServiceFactories = [
authServiceFactory(),
@@ -56,6 +57,7 @@ export const defaultServiceFactories = [
tokenManagerServiceFactory(),
userInfoServiceFactory(),
urlReaderServiceFactory(),
eventsServiceFactory(),
];
/**
+10
View File
@@ -17,6 +17,7 @@ import { BackstageUserPrincipal } from '@backstage/backend-plugin-api';
import { CacheService } from '@backstage/backend-plugin-api';
import { DatabaseService } from '@backstage/backend-plugin-api';
import { DiscoveryService } from '@backstage/backend-plugin-api';
import { EventsService } from '@backstage/plugin-events-node';
import { ExtendedHttpServer } from '@backstage/backend-app-api';
import { ExtensionPoint } from '@backstage/backend-plugin-api';
import { HttpAuthService } from '@backstage/backend-plugin-api';
@@ -183,6 +184,15 @@ export namespace mockServices {
partialImpl?: Partial<DiscoveryService> | undefined,
) => ServiceMock<DiscoveryService>;
}
// (undocumented)
export namespace events {
const // (undocumented)
factory: () => ServiceFactory<EventsService, 'plugin'>;
const // (undocumented)
mock: (
partialImpl?: Partial<EventsService> | undefined,
) => ServiceMock<EventsService>;
}
export function httpAuth(options?: {
pluginId?: string;
defaultCredentials?: BackstageCredentials;
+1
View File
@@ -51,6 +51,7 @@
"@backstage/config": "workspace:^",
"@backstage/errors": "workspace:^",
"@backstage/plugin-auth-node": "workspace:^",
"@backstage/plugin-events-node": "workspace:^",
"@backstage/types": "workspace:^",
"better-sqlite3": "^9.0.0",
"cookie": "^0.6.0",
@@ -52,6 +52,10 @@ import { MockAuthService } from './MockAuthService';
import { MockHttpAuthService } from './MockHttpAuthService';
import { mockCredentials } from './mockCredentials';
import { MockUserInfoService } from './MockUserInfoService';
import {
eventsServiceFactory,
eventsServiceRef,
} from '@backstage/plugin-events-node';
/** @internal */
function simpleFactory<
@@ -397,4 +401,12 @@ export namespace mockServices {
search: jest.fn(),
}));
}
export namespace events {
export const factory = eventsServiceFactory;
export const mock = simpleMock(eventsServiceRef, () => ({
publish: jest.fn(),
subscribe: jest.fn(),
}));
}
}
@@ -83,6 +83,7 @@ export const defaultServiceFactories = [
mockServices.tokenManager.factory(),
mockServices.userInfo.factory(),
mockServices.urlReader.factory(),
mockServices.events.factory(),
];
/**
+7
View File
@@ -4,6 +4,7 @@
```ts
import { LoggerService } from '@backstage/backend-plugin-api';
import { ServiceFactory } from '@backstage/backend-plugin-api';
import { ServiceRef } from '@backstage/backend-plugin-api';
// @public
@@ -61,6 +62,12 @@ export interface EventsService {
// @public (undocumented)
export type EventsServiceEventHandler = (params: EventParams) => Promise<void>;
// @public (undocumented)
export const eventsServiceFactory: () => ServiceFactory<
EventsService,
'plugin'
>;
// @public
export const eventsServiceRef: ServiceRef<EventsService, 'plugin'>;
+1 -1
View File
@@ -22,4 +22,4 @@
export * from './api';
export * from './deprecated';
export { eventsServiceRef } from './service';
export { eventsServiceRef, eventsServiceFactory } from './service';
+15 -14
View File
@@ -30,18 +30,19 @@ import { EventsService, DefaultEventsService } from './api';
export const eventsServiceRef = createServiceRef<EventsService>({
id: 'events.service',
scope: 'plugin',
defaultFactory: async service =>
createServiceFactory({
service,
deps: {
pluginMetadata: coreServices.pluginMetadata,
rootLogger: coreServices.rootLogger,
},
async createRootContext({ rootLogger }) {
return DefaultEventsService.create({ logger: rootLogger });
},
async factory({ pluginMetadata }, eventsService) {
return eventsService.forPlugin(pluginMetadata.getId());
},
}),
});
/** @public */
export const eventsServiceFactory = createServiceFactory({
service: eventsServiceRef,
deps: {
pluginMetadata: coreServices.pluginMetadata,
rootLogger: coreServices.rootLogger,
},
async createRootContext({ rootLogger }) {
return DefaultEventsService.create({ logger: rootLogger });
},
async factory({ pluginMetadata }, eventsService) {
return eventsService.forPlugin(pluginMetadata.getId());
},
});
+2
View File
@@ -3432,6 +3432,7 @@ __metadata:
"@backstage/backend-plugin-api": "workspace:^"
"@backstage/backend-test-utils": "workspace:^"
"@backstage/cli": "workspace:^"
"@backstage/plugin-events-node": "workspace:^"
languageName: unknown
linkType: soft
@@ -3550,6 +3551,7 @@ __metadata:
"@backstage/config": "workspace:^"
"@backstage/errors": "workspace:^"
"@backstage/plugin-auth-node": "workspace:^"
"@backstage/plugin-events-node": "workspace:^"
"@backstage/types": "workspace:^"
"@types/supertest": ^2.0.8
better-sqlite3: ^9.0.0