Skip to content

Commit

Permalink
feat: improve typing
Browse files Browse the repository at this point in the history
  • Loading branch information
0xnigir1 committed Oct 30, 2024
1 parent 3d4df7b commit 87c30f6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 25 deletions.
1 change: 1 addition & 0 deletions packages/data-flow/src/data-loader/dataLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Expand Down
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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<K>;
};

/**
Expand Down
10 changes: 2 additions & 8 deletions packages/data-flow/src/data-loader/handlers/project.handlers.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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<K>;
};

/**
Expand Down
12 changes: 2 additions & 10 deletions packages/data-flow/src/data-loader/handlers/round.handlers.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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<K>;
};

/**
Expand Down
7 changes: 6 additions & 1 deletion packages/repository/src/external.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions packages/repository/src/types/changeset.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -64,7 +64,7 @@ type ProjectChangeset =
};
};

type RoundChangeset =
export type RoundChangeset =
| {
type: "InsertRound";
args: {
Expand Down Expand Up @@ -129,7 +129,7 @@ type RoundChangeset =
};
};

type ApplicationChangeset =
export type ApplicationChangeset =
| {
type: "InsertApplication";
args: NewApplication;
Expand Down

0 comments on commit 87c30f6

Please sign in to comment.