Skip to content

Commit

Permalink
feat(core): add getInfo method to feature service registry
Browse files Browse the repository at this point in the history
This method is useful when you want to log the currently registered
feature services with their provided versions.
  • Loading branch information
unstubbable committed Feb 13, 2024
1 parent ab79875 commit c7e5311
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/core/src/__tests__/feature-service-registry.test.ts
Expand Up @@ -861,6 +861,36 @@ describe('FeatureServiceRegistry', () => {
});
});

describe('#getInfo', () => {
it('returns info about consumers and registered feature services', () => {
featureServiceRegistry = new FeatureServiceRegistry({logger});

providerDefinitionB = {
id: 'b',
dependencies: {featureServices: {a: '^1.0.0'}},
create: jest.fn(() => ({'1.0.0': binderB, '2.0.0': binderB})),
};

featureServiceRegistry.registerFeatureServices(
[providerDefinitionA, providerDefinitionB],
'test',
);

featureServiceRegistry.bindFeatureServices(
{dependencies: {featureServices: {a: '1.0.0'}}},
'foo',
);

expect(featureServiceRegistry.getInfo()).toEqual({
consumerIds: ['a', 'b', 'foo'],
featureServices: [
{id: 'a', versions: ['1.1.0']},
{id: 'b', versions: ['1.0.0', '2.0.0']},
],
});
});
});

describe('without a custom logger', () => {
let consoleInfoSpy: jest.SpyInstance;

Expand Down
23 changes: 23 additions & 0 deletions packages/core/src/feature-service-registry.ts
Expand Up @@ -90,6 +90,14 @@ export interface FeatureServicesBinding<
unbind(): void;
}

export interface FeatureServiceRegistryInfo {
readonly consumerIds: string[];
readonly featureServices: {
readonly id: string;
readonly versions: string[];
}[];
}

export interface FeatureServiceRegistryOptions {
/**
* If the [[FeatureAppManager]] is configured with a
Expand Down Expand Up @@ -311,6 +319,21 @@ export class FeatureServiceRegistry {
return {featureServices, unbind};
}

/**
* Returns info about consumers and registered feature services.
*/
public getInfo(): FeatureServiceRegistryInfo {
return {
consumerIds: Array.from(this.consumerIds),
featureServices: [...this.sharedFeatureServices.entries()].map(
([id, sharedFeatureService]) => ({
id,
versions: Object.keys(sharedFeatureService),
}),
),
};
}

private registerFeatureService(
providerDefinitionsById: ProviderDefinitionsById,
providerId: string,
Expand Down

0 comments on commit c7e5311

Please sign in to comment.