Revert "Simplify type params where they aren't needed"

This reverts commit bcb0ff4f90.

Signed-off-by: Damon Kaswell <damon.kaswell1@hp.com>
This commit is contained in:
Damon Kaswell
2023-01-12 09:38:14 -08:00
parent d5415fedea
commit 66d70c7d3c
8 changed files with 28 additions and 23 deletions
@@ -23,7 +23,7 @@ import { v4 } from 'uuid';
import { stringifyError } from '@backstage/errors';
import { EventParams, EventSubscriber } from '@backstage/plugin-events-node';
export class IncrementalIngestionEngine
export class IncrementalIngestionEngine<TInput>
implements IterationEngine, EventSubscriber
{
private readonly restLength: Duration;
@@ -32,7 +32,7 @@ export class IncrementalIngestionEngine
private manager: IncrementalIngestionDatabaseManager;
constructor(private options: IterationEngineOptions) {
constructor(private options: IterationEngineOptions<TInput>) {
this.manager = options.manager;
this.restLength = Duration.fromObject(options.restLength);
this.backoff = options.backoff ?? [
@@ -347,11 +347,13 @@ export class IncrementalIngestionEngine
`incremental-engine: Received ${this.providerEventTopic} event`,
);
const payload = eventPayload as TInput;
if (!provider.deltaMapper) {
return;
}
const update = provider.deltaMapper(eventPayload);
const update = provider.deltaMapper(payload);
if (update.delta) {
if (update.delta.added.length > 0) {
@@ -41,7 +41,7 @@ describe('WrapperProviders', () => {
async databaseId => {
const client = await databases.init(databaseId);
const provider1: IncrementalEntityProvider = {
const provider1: IncrementalEntityProvider<number, {}> = {
getProviderName: () => 'provider1',
around: burst => burst(0),
next: async (_context, cursor) => {
@@ -51,7 +51,7 @@ describe('WrapperProviders', () => {
},
};
const provider2: IncrementalEntityProvider = {
const provider2: IncrementalEntityProvider<number, {}> = {
getProviderName: () => 'provider2',
around: burst => burst(0),
next: async (_context, cursor) => {
@@ -58,7 +58,7 @@ export class WrapperProviders {
) {}
wrap(
provider: IncrementalEntityProvider,
provider: IncrementalEntityProvider<unknown, unknown>,
options: IncrementalEntityProviderOptions,
): EntityProvider {
this.numberOfProvidersToConnect += 1;
@@ -81,8 +81,8 @@ export class WrapperProviders {
).createRouter();
}
private async startProvider(
provider: IncrementalEntityProvider,
private async startProvider<TCursor, TContext, TInput>(
provider: IncrementalEntityProvider<TCursor, TContext, TInput>,
providerOptions: IncrementalEntityProviderOptions,
connection: EntityProviderConnection,
) {
@@ -24,7 +24,7 @@ import { incrementalIngestionEntityProviderCatalogModule } from './incrementalIn
describe('bitbucketServerEntityProviderCatalogModule', () => {
it('should register provider at the catalog extension point', async () => {
const provider1: IncrementalEntityProvider = {
const provider1: IncrementalEntityProvider<number, {}, unknown> = {
getProviderName: () => 'provider1',
around: burst => burst(0),
next: async (cursor, _context) => {
@@ -38,7 +38,7 @@ export const incrementalIngestionEntityProviderCatalogModule =
env,
options: {
providers: Array<{
provider: IncrementalEntityProvider;
provider: IncrementalEntityProvider<unknown, unknown, unknown>;
options: IncrementalEntityProviderOptions;
}>;
},
@@ -36,10 +36,10 @@ import {
incrementalIngestionEntityProviderCatalogModule,
} from '.';
const provider: IncrementalEntityProvider = {
const provider: IncrementalEntityProvider<number, {}, unknown> = {
getProviderName: () => 'test-provider',
around: burst => burst(0),
next: async (_context, cursor: number | undefined) => {
next: async (_context, cursor) => {
await new Promise(resolve => setTimeout(resolve, 500));
if (cursor === undefined || cursor < 3) {
console.log(`### Returning batch #${cursor}`);
@@ -68,8 +68,8 @@ export class IncrementalCatalogBuilder {
return { incrementalAdminRouter };
}
addIncrementalEntityProvider(
provider: IncrementalEntityProvider,
addIncrementalEntityProvider<TCursor, TContext, TInput>(
provider: IncrementalEntityProvider<TCursor, TContext, TInput>,
options: IncrementalEntityProviderOptions,
) {
const { burstInterval, burstLength, restLength } = options;
@@ -46,7 +46,7 @@ import { IncrementalIngestionDatabaseManager } from './database/IncrementalInges
*
* @public
*/
export interface IncrementalEntityProvider {
export interface IncrementalEntityProvider<TCursor, TContext, TInput = null> {
/**
* This name must be unique between all of the entity providers
* operating in the catalog.
@@ -62,7 +62,10 @@ export interface IncrementalEntityProvider {
* @returns The entities to be ingested, as well as the cursor of
* the next page after this one.
*/
next(context: unknown, cursor?: unknown): Promise<EntityIteratorResult>;
next(
context: TContext,
cursor?: TCursor,
): Promise<EntityIteratorResult<TCursor>>;
/**
* Do any setup and teardown necessary in order to provide the
@@ -71,13 +74,13 @@ export interface IncrementalEntityProvider {
*
* @param burst - a function which performs a series of iterations
*/
around(burst: (context: unknown) => Promise<void>): Promise<void>;
around(burst: (context: TContext) => Promise<void>): Promise<void>;
/**
* If present, this method maps incoming payloads to apply updates
* outside of the incremental ingestion schedule.
*/
deltaMapper?: (payload: unknown) => {
deltaMapper?: (payload: TInput) => {
delta:
| {
added: DeferredEntity[];
@@ -93,16 +96,16 @@ export interface IncrementalEntityProvider {
*
* @public
*/
export type EntityIteratorResult =
export type EntityIteratorResult<T> =
| {
done: false;
entities: DeferredEntity[];
cursor: unknown;
cursor: T;
}
| {
done: true;
entities?: DeferredEntity[];
cursor?: unknown;
cursor?: T;
};
/** @public */
@@ -164,11 +167,11 @@ export interface IterationEngine {
taskFn: TaskFunction;
}
export interface IterationEngineOptions {
export interface IterationEngineOptions<TInput> {
logger: Logger;
connection: EntityProviderConnection;
manager: IncrementalIngestionDatabaseManager;
provider: IncrementalEntityProvider;
provider: IncrementalEntityProvider<unknown, unknown, TInput>;
restLength: DurationObjectUnits;
ready: Promise<void>;
backoff?: IncrementalEntityProviderOptions['backoff'];