diff --git a/packages/data-flow/src/data-loader/dataLoader.ts b/packages/data-flow/src/data-loader/dataLoader.ts index 5aa6cfc..9c1098b 100644 --- a/packages/data-flow/src/data-loader/dataLoader.ts +++ b/packages/data-flow/src/data-loader/dataLoader.ts @@ -62,6 +62,7 @@ export class DataLoader implements IDataLoader { for (const changeset of changesets) { result.numExecuted++; try { + //TODO: inside each handler, we should add zod validation that the args match the expected type await this.handlers[changeset.type](changeset as never); result.changesets.push(changeset.type); result.numSuccessful++; diff --git a/packages/data-flow/src/data-loader/handlers/application.handlers.ts b/packages/data-flow/src/data-loader/handlers/application.handlers.ts index 5e1cbb6..20afd8a 100644 --- a/packages/data-flow/src/data-loader/handlers/application.handlers.ts +++ b/packages/data-flow/src/data-loader/handlers/application.handlers.ts @@ -1,4 +1,4 @@ -import { IApplicationRepository } from "@grants-stack-indexer/repository"; +import { ApplicationChangeset, IApplicationRepository } from "@grants-stack-indexer/repository"; import { ChangesetHandler } from "../types/index.js"; @@ -7,8 +7,7 @@ import { ChangesetHandler } from "../types/index.js"; * Each handler corresponds to a specific Application changeset type. */ export type ApplicationHandlers = { - InsertApplication: ChangesetHandler<"InsertApplication">; - UpdateApplication: ChangesetHandler<"UpdateApplication">; + [K in ApplicationChangeset["type"]]: ChangesetHandler; }; /** diff --git a/packages/data-flow/src/data-loader/handlers/project.handlers.ts b/packages/data-flow/src/data-loader/handlers/project.handlers.ts index 2acbaa2..b32a9db 100644 --- a/packages/data-flow/src/data-loader/handlers/project.handlers.ts +++ b/packages/data-flow/src/data-loader/handlers/project.handlers.ts @@ -1,4 +1,4 @@ -import { IProjectRepository } from "@grants-stack-indexer/repository"; +import { IProjectRepository, ProjectChangeset } from "@grants-stack-indexer/repository"; import { ChangesetHandler } from "../types/index.js"; @@ -7,13 +7,7 @@ import { ChangesetHandler } from "../types/index.js"; * Each handler corresponds to a specific Project changeset type. */ export type ProjectHandlers = { - InsertProject: ChangesetHandler<"InsertProject">; - UpdateProject: ChangesetHandler<"UpdateProject">; - InsertPendingProjectRole: ChangesetHandler<"InsertPendingProjectRole">; - DeletePendingProjectRoles: ChangesetHandler<"DeletePendingProjectRoles">; - InsertProjectRole: ChangesetHandler<"InsertProjectRole">; - DeleteAllProjectRolesByRole: ChangesetHandler<"DeleteAllProjectRolesByRole">; - DeleteAllProjectRolesByRoleAndAddress: ChangesetHandler<"DeleteAllProjectRolesByRoleAndAddress">; + [K in ProjectChangeset["type"]]: ChangesetHandler; }; /** diff --git a/packages/data-flow/src/data-loader/handlers/round.handlers.ts b/packages/data-flow/src/data-loader/handlers/round.handlers.ts index c9b0fde..cb6c831 100644 --- a/packages/data-flow/src/data-loader/handlers/round.handlers.ts +++ b/packages/data-flow/src/data-loader/handlers/round.handlers.ts @@ -1,4 +1,4 @@ -import { IRoundRepository } from "@grants-stack-indexer/repository"; +import { IRoundRepository, RoundChangeset } from "@grants-stack-indexer/repository"; import { ChangesetHandler } from "../types/index.js"; @@ -7,15 +7,7 @@ import { ChangesetHandler } from "../types/index.js"; * Each handler corresponds to a specific Round changeset type. */ export type RoundHandlers = { - InsertRound: ChangesetHandler<"InsertRound">; - UpdateRound: ChangesetHandler<"UpdateRound">; - UpdateRoundByStrategyAddress: ChangesetHandler<"UpdateRoundByStrategyAddress">; - IncrementRoundFundedAmount: ChangesetHandler<"IncrementRoundFundedAmount">; - IncrementRoundTotalDistributed: ChangesetHandler<"IncrementRoundTotalDistributed">; - InsertPendingRoundRole: ChangesetHandler<"InsertPendingRoundRole">; - DeletePendingRoundRoles: ChangesetHandler<"DeletePendingRoundRoles">; - InsertRoundRole: ChangesetHandler<"InsertRoundRole">; - DeleteAllRoundRolesByRoleAndAddress: ChangesetHandler<"DeleteAllRoundRolesByRoleAndAddress">; + [K in RoundChangeset["type"]]: ChangesetHandler; }; /** diff --git a/packages/repository/src/external.ts b/packages/repository/src/external.ts index 8dbf22a..c3cc4d8 100644 --- a/packages/repository/src/external.ts +++ b/packages/repository/src/external.ts @@ -35,7 +35,12 @@ export type { PartialApplication, } from "./types/application.types.js"; -export type { Changeset } from "./types/index.js"; +export type { + Changeset, + ProjectChangeset, + RoundChangeset, + ApplicationChangeset, +} from "./types/index.js"; export { KyselyRoundRepository, diff --git a/packages/repository/src/types/changeset.types.ts b/packages/repository/src/types/changeset.types.ts index 547f7d3..648d111 100644 --- a/packages/repository/src/types/changeset.types.ts +++ b/packages/repository/src/types/changeset.types.ts @@ -18,7 +18,7 @@ import { //TODO: see if in the future we move out of inline object types for changesets -type ProjectChangeset = +export type ProjectChangeset = | { type: "InsertProject"; args: { @@ -64,7 +64,7 @@ type ProjectChangeset = }; }; -type RoundChangeset = +export type RoundChangeset = | { type: "InsertRound"; args: { @@ -129,7 +129,7 @@ type RoundChangeset = }; }; -type ApplicationChangeset = +export type ApplicationChangeset = | { type: "InsertApplication"; args: NewApplication;