Merge pull request #15659 from RoadieHQ/make-tech-insights-db-configurable
Expose optional persistenceContext on TechInsights construction
This commit is contained in:
@@ -77,11 +77,22 @@ export interface FactRetrieverRegistry {
|
||||
register(registration: FactRetrieverRegistration): Promise<void>;
|
||||
}
|
||||
|
||||
// @public
|
||||
export const initializePersistenceContext: (
|
||||
database: PluginDatabaseManager,
|
||||
options?: PersistenceContextOptions,
|
||||
) => Promise<PersistenceContext>;
|
||||
|
||||
// @public
|
||||
export type PersistenceContext = {
|
||||
techInsightsStore: TechInsightsStore;
|
||||
};
|
||||
|
||||
// @public
|
||||
export type PersistenceContextOptions = {
|
||||
logger: Logger;
|
||||
};
|
||||
|
||||
// @public
|
||||
export interface RouterOptions<
|
||||
CheckType extends TechInsightCheck,
|
||||
@@ -122,6 +133,7 @@ export interface TechInsightsOptions<
|
||||
factRetrievers?: FactRetrieverRegistration[];
|
||||
// (undocumented)
|
||||
logger: Logger;
|
||||
persistenceContext?: PersistenceContext;
|
||||
// (undocumented)
|
||||
scheduler: PluginTaskScheduler;
|
||||
// (undocumented)
|
||||
|
||||
@@ -18,12 +18,16 @@ export * from './service/router';
|
||||
export type { RouterOptions } from './service/router';
|
||||
|
||||
export { buildTechInsightsContext } from './service/techInsightsContextBuilder';
|
||||
export { initializePersistenceContext } from './service/persistence/persistenceContext';
|
||||
export type {
|
||||
TechInsightsOptions,
|
||||
TechInsightsContext,
|
||||
} from './service/techInsightsContextBuilder';
|
||||
export type { FactRetrieverEngine } from './service/fact/FactRetrieverEngine';
|
||||
export type { PersistenceContext } from './service/persistence/persistenceContext';
|
||||
export type {
|
||||
PersistenceContext,
|
||||
PersistenceContextOptions,
|
||||
} from './service/persistence/persistenceContext';
|
||||
export { createFactRetrieverRegistration } from './service/fact/createFactRetriever';
|
||||
export type { FactRetrieverRegistry } from './service/fact/FactRetrieverRegistry';
|
||||
export type { FactRetrieverRegistrationOptions } from './service/fact/createFactRetriever';
|
||||
|
||||
@@ -46,6 +46,11 @@ type RawDbFactSchemaRow = {
|
||||
entityFilter?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Default TechInsightsDatabase implementation.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export class TechInsightsDatabase implements TechInsightsStore {
|
||||
private readonly CHUNK_SIZE = 50;
|
||||
|
||||
|
||||
@@ -36,22 +36,27 @@ export type PersistenceContext = {
|
||||
techInsightsStore: TechInsightsStore;
|
||||
};
|
||||
|
||||
export type CreateDatabaseOptions = {
|
||||
/**
|
||||
* A Container for persistence context initialization options
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export type PersistenceContextOptions = {
|
||||
logger: Logger;
|
||||
};
|
||||
|
||||
const defaultOptions: CreateDatabaseOptions = {
|
||||
const defaultOptions: PersistenceContextOptions = {
|
||||
logger: getVoidLogger(),
|
||||
};
|
||||
|
||||
/**
|
||||
* A factory method to construct persistence context for running implementation.
|
||||
* A factory function to construct persistence context for running implementation.
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export const initializePersistenceContext = async (
|
||||
database: PluginDatabaseManager,
|
||||
options: CreateDatabaseOptions = defaultOptions,
|
||||
options: PersistenceContextOptions = defaultOptions,
|
||||
): Promise<PersistenceContext> => {
|
||||
const client = await database.getClient();
|
||||
|
||||
|
||||
@@ -74,6 +74,12 @@ export interface TechInsightsOptions<
|
||||
*/
|
||||
factRetrieverRegistry?: FactRetrieverRegistry;
|
||||
|
||||
/**
|
||||
* Optional persistenceContext implementation that replaces the default one.
|
||||
* This can be used to replace underlying database with a more suitable implementation if needed
|
||||
*/
|
||||
persistenceContext?: PersistenceContext;
|
||||
|
||||
logger: Logger;
|
||||
config: Config;
|
||||
discovery: PluginEndpointDiscovery;
|
||||
@@ -139,9 +145,11 @@ export const buildTechInsightsContext = async <
|
||||
|
||||
const factRetrieverRegistry = buildFactRetrieverRegistry();
|
||||
|
||||
const persistenceContext = await initializePersistenceContext(database, {
|
||||
logger,
|
||||
});
|
||||
const persistenceContext =
|
||||
options.persistenceContext ??
|
||||
(await initializePersistenceContext(database, {
|
||||
logger,
|
||||
}));
|
||||
|
||||
const factRetrieverEngine = await DefaultFactRetrieverEngine.create({
|
||||
scheduler,
|
||||
|
||||
Reference in New Issue
Block a user