Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor/separate client and admin store (#5006)
This PR is the first step in separating the client and admin stores. Currently our feature toggle services uses the client store to serve multiple purposes. Admin API uses the feature toggle service to serve both the feature toggle list and playground features, while the client API uses the feature toggle service to serve client features. The admin API can change often and have very different requirements than the client API, which changes infrequently and generally keeps the same stable structure for long periods of time. This architecture is error prone, because when you need to make changes to the admin API, you can very easily affect the client API. I aim to put up a stone wall between the two APIs. Complete separation between the two APIs, at the cost of some duplication. In this PR I have created a feature oriented architecture for client features and disconnected the client API from the feature toggle service. It now goes through it's own service to it's own store. For feature toggle service I have duplicated and replaced the functionality that serves /api/admin/features, I have kept a lot of the ugliness in the code and haven't removed anything in order to avoid breaking changes. Next steps: * Move playground to admin API * Remove client-feature-toggle-store from feature-toggle-service
- Loading branch information
1 parent
7b7a2a7
commit f34d187
Showing
28 changed files
with
627 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/lib/features/client-feature-toggles/client-feature-toggle-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { | ||
IFeatureNaming, | ||
IFeatureToggleClientStore, | ||
IFeatureToggleQuery, | ||
IUnleashConfig, | ||
IUnleashStores, | ||
} from '../../types'; | ||
|
||
import { Logger } from '../../logger'; | ||
|
||
import { FeatureConfigurationClient } from '../feature-toggle/types/feature-toggle-strategies-store-type'; | ||
|
||
export class ClientFeatureToggleService { | ||
private logger: Logger; | ||
|
||
private clientFeatureToggleStore: IFeatureToggleClientStore; | ||
|
||
constructor( | ||
{ | ||
clientFeatureToggleStore, | ||
}: Pick<IUnleashStores, 'clientFeatureToggleStore'>, | ||
{ getLogger }: Pick<IUnleashConfig, 'getLogger' | 'flagResolver'>, | ||
) { | ||
this.logger = getLogger('services/client-feature-toggle-service.ts'); | ||
this.clientFeatureToggleStore = clientFeatureToggleStore; | ||
} | ||
|
||
async getClientFeatures( | ||
query?: IFeatureToggleQuery, | ||
): Promise<FeatureConfigurationClient[]> { | ||
const result = await this.clientFeatureToggleStore.getClient( | ||
query || {}, | ||
); | ||
|
||
return result.map( | ||
({ | ||
name, | ||
type, | ||
enabled, | ||
project, | ||
stale, | ||
strategies, | ||
variants, | ||
description, | ||
impressionData, | ||
dependencies, | ||
}) => ({ | ||
name, | ||
type, | ||
enabled, | ||
project, | ||
stale, | ||
strategies, | ||
variants, | ||
description, | ||
impressionData, | ||
dependencies, | ||
}), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/lib/features/client-feature-toggles/createClientFeatureToggleService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import FeatureToggleClientStore from '../client-feature-toggles/client-feature-toggle-store'; | ||
import { Db } from '../../db/db'; | ||
import { IUnleashConfig } from '../../types'; | ||
import FakeClientFeatureToggleStore from './fakes/fake-client-feature-toggle-store'; | ||
import { ClientFeatureToggleService } from './client-feature-toggle-service'; | ||
|
||
export const createClientFeatureToggleService = ( | ||
db: Db, | ||
config: IUnleashConfig, | ||
): ClientFeatureToggleService => { | ||
const { getLogger, eventBus, flagResolver } = config; | ||
|
||
const featureToggleClientStore = new FeatureToggleClientStore( | ||
db, | ||
eventBus, | ||
getLogger, | ||
flagResolver, | ||
); | ||
|
||
const clientFeatureToggleService = new ClientFeatureToggleService( | ||
{ | ||
clientFeatureToggleStore: featureToggleClientStore, | ||
}, | ||
{ getLogger, flagResolver }, | ||
); | ||
|
||
return clientFeatureToggleService; | ||
}; | ||
|
||
export const createFakeClientFeatureToggleService = ( | ||
config: IUnleashConfig, | ||
): ClientFeatureToggleService => { | ||
const { getLogger, flagResolver } = config; | ||
|
||
const fakeClientFeatureToggleStore = new FakeClientFeatureToggleStore(); | ||
|
||
const clientFeatureToggleService = new ClientFeatureToggleService( | ||
{ | ||
clientFeatureToggleStore: fakeClientFeatureToggleStore, | ||
}, | ||
{ getLogger, flagResolver }, | ||
); | ||
|
||
return clientFeatureToggleService; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.