mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-11 00:08:30 +01:00
feat: Compositon root for proxy service (#6488)
This commit is contained in:
parent
bf5f38ba1e
commit
48fa39c9fc
108
src/lib/proxy/createProxyService.ts
Normal file
108
src/lib/proxy/createProxyService.ts
Normal file
@ -0,0 +1,108 @@
|
||||
import { ProxyService } from './proxy-service';
|
||||
import { SegmentReadModel } from '../features/segment/segment-read-model';
|
||||
import ClientMetricsServiceV2 from '../features/metrics/client-metrics/metrics-service-v2';
|
||||
import SettingService from '../services/setting-service';
|
||||
import SettingStore from '../db/setting-store';
|
||||
import {
|
||||
createEventsService,
|
||||
createFakeEventsService,
|
||||
createFakeFeatureToggleService,
|
||||
createFeatureToggleService,
|
||||
} from '../features';
|
||||
import ConfigurationRevisionService from '../features/feature-toggle/configuration-revision-service';
|
||||
import EventStore from '../features/events/event-store';
|
||||
import { GlobalFrontendApiCache } from './global-frontend-api-cache';
|
||||
import ClientFeatureToggleReadModel from './client-feature-toggle-read-model';
|
||||
import { FakeSegmentReadModel } from '../features/segment/fake-segment-read-model';
|
||||
import FakeSettingStore from '../../test/fixtures/fake-setting-store';
|
||||
import FakeEventStore from '../../test/fixtures/fake-event-store';
|
||||
import FakeClientFeatureToggleReadModel from './fake-client-feature-toggle-read-model';
|
||||
import { IUnleashConfig } from '../types';
|
||||
import { Db } from '../db/db';
|
||||
|
||||
export const createProxyService = (
|
||||
db: Db,
|
||||
config: IUnleashConfig,
|
||||
// client metrics service needs to be shared because it uses in-memory cache
|
||||
clientMetricsServiceV2: ClientMetricsServiceV2,
|
||||
): ProxyService => {
|
||||
const segmentReadModel = new SegmentReadModel(db);
|
||||
const settingStore = new SettingStore(db, config.getLogger);
|
||||
const eventService = createEventsService(db, config);
|
||||
const settingService = new SettingService(
|
||||
{ settingStore },
|
||||
config,
|
||||
eventService,
|
||||
);
|
||||
// TODO: remove this dependency after we migrate frontend API
|
||||
const featureToggleServiceV2 = createFeatureToggleService(db, config);
|
||||
const eventStore = new EventStore(
|
||||
db,
|
||||
config.getLogger,
|
||||
config.flagResolver,
|
||||
);
|
||||
const configurationRevisionService = new ConfigurationRevisionService(
|
||||
{ eventStore },
|
||||
config,
|
||||
);
|
||||
const clientFeatureToggleReadModel = new ClientFeatureToggleReadModel(
|
||||
db,
|
||||
config.eventBus,
|
||||
);
|
||||
const globalFrontendApiCache = new GlobalFrontendApiCache(
|
||||
config,
|
||||
segmentReadModel,
|
||||
clientFeatureToggleReadModel,
|
||||
configurationRevisionService,
|
||||
);
|
||||
return new ProxyService(
|
||||
config,
|
||||
{ segmentReadModel },
|
||||
{
|
||||
featureToggleServiceV2,
|
||||
clientMetricsServiceV2,
|
||||
settingService,
|
||||
configurationRevisionService,
|
||||
},
|
||||
globalFrontendApiCache,
|
||||
);
|
||||
};
|
||||
|
||||
export const createFakeProxyService = (
|
||||
config: IUnleashConfig,
|
||||
clientMetricsServiceV2: ClientMetricsServiceV2,
|
||||
): ProxyService => {
|
||||
const segmentReadModel = new FakeSegmentReadModel();
|
||||
const settingStore = new FakeSettingStore();
|
||||
const eventService = createFakeEventsService(config);
|
||||
const settingService = new SettingService(
|
||||
{ settingStore },
|
||||
config,
|
||||
eventService,
|
||||
);
|
||||
// TODO: remove this dependency after we migrate frontend API
|
||||
const featureToggleServiceV2 = createFakeFeatureToggleService(config);
|
||||
const eventStore = new FakeEventStore();
|
||||
const configurationRevisionService = new ConfigurationRevisionService(
|
||||
{ eventStore },
|
||||
config,
|
||||
);
|
||||
const clientFeatureToggleReadModel = new FakeClientFeatureToggleReadModel();
|
||||
const globalFrontendApiCache = new GlobalFrontendApiCache(
|
||||
config,
|
||||
segmentReadModel,
|
||||
clientFeatureToggleReadModel,
|
||||
configurationRevisionService,
|
||||
);
|
||||
return new ProxyService(
|
||||
config,
|
||||
{ segmentReadModel },
|
||||
{
|
||||
featureToggleServiceV2,
|
||||
clientMetricsServiceV2,
|
||||
settingService,
|
||||
configurationRevisionService,
|
||||
},
|
||||
globalFrontendApiCache,
|
||||
);
|
||||
};
|
@ -21,10 +21,7 @@ import { PROXY_FEATURES_FOR_TOKEN_TIME } from '../metric-events';
|
||||
|
||||
type Config = Pick<IUnleashConfig, 'getLogger' | 'frontendApi' | 'eventBus'>;
|
||||
|
||||
type Stores = Pick<
|
||||
IUnleashStores,
|
||||
'projectStore' | 'eventStore' | 'segmentReadModel'
|
||||
>;
|
||||
type Stores = Pick<IUnleashStores, 'segmentReadModel'>;
|
||||
|
||||
type Services = Pick<
|
||||
IUnleashServices,
|
||||
|
@ -25,10 +25,7 @@ export type Config = Pick<
|
||||
'getLogger' | 'frontendApi' | 'frontendApiOrigins' | 'eventBus'
|
||||
>;
|
||||
|
||||
export type Stores = Pick<
|
||||
IUnleashStores,
|
||||
'projectStore' | 'eventStore' | 'segmentReadModel'
|
||||
>;
|
||||
export type Stores = Pick<IUnleashStores, 'segmentReadModel'>;
|
||||
|
||||
export type Services = Pick<
|
||||
IUnleashServices,
|
||||
|
@ -111,9 +111,10 @@ import {
|
||||
import { InactiveUsersService } from '../users/inactive/inactive-users-service';
|
||||
import { SegmentReadModel } from '../features/segment/segment-read-model';
|
||||
import { FakeSegmentReadModel } from '../features/segment/fake-segment-read-model';
|
||||
import { GlobalFrontendApiCache } from '../proxy/global-frontend-api-cache';
|
||||
import ClientFeatureToggleReadModel from '../proxy/client-feature-toggle-read-model';
|
||||
import FakeClientFeatureToggleReadModel from '../proxy/fake-client-feature-toggle-read-model';
|
||||
import {
|
||||
createFakeProxyService,
|
||||
createProxyService,
|
||||
} from '../proxy/createProxyService';
|
||||
|
||||
export const createServices = (
|
||||
stores: IUnleashStores,
|
||||
@ -296,27 +297,9 @@ export const createServices = (
|
||||
? createClientFeatureToggleService(db, config)
|
||||
: createFakeClientFeatureToggleService(config);
|
||||
|
||||
const clientFeatureToggleReadModel = db
|
||||
? new ClientFeatureToggleReadModel(db, config.eventBus)
|
||||
: new FakeClientFeatureToggleReadModel();
|
||||
const globalFrontendApiCache = new GlobalFrontendApiCache(
|
||||
config,
|
||||
segmentReadModel,
|
||||
clientFeatureToggleReadModel,
|
||||
configurationRevisionService,
|
||||
);
|
||||
|
||||
const proxyService = new ProxyService(
|
||||
config,
|
||||
stores,
|
||||
{
|
||||
featureToggleServiceV2,
|
||||
clientMetricsServiceV2,
|
||||
settingService,
|
||||
configurationRevisionService,
|
||||
},
|
||||
globalFrontendApiCache,
|
||||
);
|
||||
const proxyService = db
|
||||
? createProxyService(db, config, clientMetricsServiceV2)
|
||||
: createFakeProxyService(config, clientMetricsServiceV2);
|
||||
|
||||
const edgeService = new EdgeService({ apiTokenService }, config);
|
||||
|
||||
|
@ -12,13 +12,17 @@ let app: IUnleashTest;
|
||||
|
||||
beforeAll(async () => {
|
||||
db = await dbInit('config_api_serial', getLogger);
|
||||
app = await setupAppWithCustomConfig(db.stores, {
|
||||
experimental: {
|
||||
flags: {
|
||||
strictSchemaValidation: true,
|
||||
app = await setupAppWithCustomConfig(
|
||||
db.stores,
|
||||
{
|
||||
experimental: {
|
||||
flags: {
|
||||
strictSchemaValidation: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
db.rawDatabase,
|
||||
);
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
|
Loading…
Reference in New Issue
Block a user