import { env, waitUntil } from "cloudflare:workers";
/** Resolved through the binding so importing this module doesn't pull in the Durable Object class. */
export function repoState(repoId: string) {
return env.REPO_STATE.get(env.REPO_STATE.idFromName(repoId));
}
/**
* Tells the repository's RepoState that these issues or pull requests changed (created, retitled, closed,
* reopened, assigned, review requested, hidden, deleted). Runs after the response; a failure only delays
* the involvement index until the next change or the backfill sweep.
*/
export function issuesChanged(repoId: string, issueIds: string[]): void {
if (issueIds.length === 0) return;
try {
waitUntil(
repoState(repoId)
.syncIssues(repoId, issueIds)
.catch((error: unknown) => console.error("Involvement sync failed", repoId, error)),
);
} catch (error) {
console.error("Involvement sync failed to start", repoId, error);
}
}
/** The repository is deleted: its issues leave every user's lists. */
export async function dropRepoState(repoId: string): Promise<void> {
try {
await repoState(repoId).destroy(repoId);
} catch (error) {
console.error("RepoState destroy failed", repoId, error);
}
}