Files
archived-orca/src/preload/api/github-work-item-api.ts
T
Neil 4221f8d429 refactor(preload): split the preload contract into per-domain api modules (#14403)
`src/preload/api-types.ts` was 3,752 raw lines (3,533 counted, 11.8x the
300-line budget) behind an `eslint-disable max-lines`. Almost all of it was a
single `PreloadApi` object type whose ~83 namespace properties were declared
inline, so any IPC surface change meant editing one 2,600-line type.

Give each namespace a named type in its own module under `src/preload/api/`
(`pty-api.ts`, `filesystem-api.ts`, `github-pull-request-api.ts`, ...) and
recompose `PreloadApi` from those names. `api-types.ts` keeps the `declare
global` Window augmentation and re-exports every moved name, so all 52 import
sites are untouched.

Two shapes needed care to stay type-identical rather than merely compatible:

- Three keys (`gh`, `git`, `ui`) are composed from two modules each. A plain
  intersection is NOT identical to the original flat object literal, so those
  use a `Merged<T>` mapped type; a negative control confirmed that dropping it
  fails the parity assertion.
- Keys whose module groups several namespaces use indexed access
  (`fs: FilesystemApi['fs']`) to preserve exact identity and source order.

`config/tsconfig.web.json` and `tsconfig.tc.web.json` enumerate files by path,
so they need `src/preload/api/**/*` alongside the existing `api-types.ts` seed
or the web projects fail TS6307.

Verified by exact type identity, not assignability: 41 assertions of the form
`Equals<Now.X, Before.X>` against a frozen pre-split snapshot, covering every
exported name, plus a per-key pass over all 83 `PreloadApi` keys. All three
projects typecheck clean with those assertions active.

Verification note: these tsconfigs are `composite: true`, and `tsc --noEmit`
will reuse a stale `.tsbuildinfo` and report clean for a state that genuinely
fails. Every result above was produced after deleting the buildinfo, including
a negative control confirming the gate still fails on deliberate drift.

Drops the `max-lines` bypass and its baseline entry (ratchet 346 -> 345).
2026-08-13 20:52:04 -07:00

168 lines
5.6 KiB
TypeScript

import type {
AddIssueCommentBySlugArgs,
ClearProjectItemFieldArgs,
DeleteIssueCommentBySlugArgs,
GetProjectViewTableArgs,
GetProjectViewTableResult,
GitHubProjectCommentMutationResult,
GitHubProjectMutationResult,
ListAccessibleProjectsArgs,
ListAccessibleProjectsResult,
ListAssignableUsersBySlugArgs,
ListAssignableUsersBySlugResult,
ListIssueTypesBySlugArgs,
ListIssueTypesBySlugResult,
ListLabelsBySlugArgs,
ListLabelsBySlugResult,
ListProjectViewsArgs,
ListProjectViewsResult,
ProjectWorkItemDetailsBySlugArgs,
ProjectWorkItemDetailsBySlugResult,
ResolveProjectRefArgs,
ResolveProjectRefResult,
UpdateIssueBySlugArgs,
UpdateIssueCommentBySlugArgs,
UpdateIssueTypeBySlugArgs,
UpdateProjectItemFieldArgs,
UpdatePullRequestBySlugArgs
} from '../../shared/github/project-types'
import type { TaskSourceContext } from '../../shared/task-source-context'
import type {
GitHubAssignableUser,
GitHubCommentResult,
GitHubCreateIssueResult,
GitHubIssueUpdate,
GitHubOwnerRepo,
GitHubWorkItem,
GitHubWorkItemDetails,
IssueInfo,
ListWorkItemsResult
} from '../../shared/types'
export type GitHubRepoSelectorArgs = {
repoPath: string
repoId?: string | null
sourceContext?: TaskSourceContext | null
}
export type GithubWorkItemApi = {
issue: (args: {
repoPath: string
repoId?: string
sourceContext?: TaskSourceContext | null
number: number
}) => Promise<IssueInfo | null>
workItem: (args: {
repoPath: string
repoId?: string
sourceContext?: TaskSourceContext | null
number: number
type?: 'issue' | 'pr'
}) => Promise<Omit<GitHubWorkItem, 'repoId'> | null>
workItemByOwnerRepo: (args: {
repoPath: string
repoId?: string
owner: string
repo: string
host?: string
number: number
type: 'issue' | 'pr'
}) => Promise<Omit<GitHubWorkItem, 'repoId'> | null>
workItemDetails: (
args: GitHubRepoSelectorArgs & {
number: number
type?: 'issue' | 'pr'
}
) => Promise<GitHubWorkItemDetails | null>
notifyWorkItemMutated: (args: {
repoPath: string
repoId?: string
type: 'issue' | 'pr'
number: number
}) => Promise<boolean>
listIssues: (args: { repoPath: string; repoId?: string; limit?: number }) => Promise<IssueInfo[]>
createIssue: (args: {
repoPath: string
repoId?: string
sourceContext?: TaskSourceContext | null
title: string
body: string
labels?: string[]
assignees?: string[]
}) => Promise<GitHubCreateIssueResult>
countWorkItems: (args: { repoPath: string; repoId?: string; query?: string }) => Promise<number>
listWorkItems: (args: {
repoPath: string
repoId?: string
limit?: number
query?: string
page?: number
noCache?: boolean
}) => Promise<ListWorkItemsResult<Omit<GitHubWorkItem, 'repoId'>>>
updateIssue: (
args: GitHubRepoSelectorArgs & {
number: number
updates: GitHubIssueUpdate
}
) => Promise<{ ok: true } | { ok: false; error: string }>
addIssueComment: (
args: GitHubRepoSelectorArgs & {
number: number
body: string
/** Why: scopes the cross-window cache invalidation so a PR and issue sharing the same number don't evict each other. */
type?: 'issue' | 'pr'
prRepo?: GitHubOwnerRepo | null
}
) => Promise<GitHubCommentResult>
listLabels: (args: {
repoPath: string
repoId?: string
sourceContext?: TaskSourceContext | null
}) => Promise<string[]>
listAssignableUsers: (args: {
repoPath: string
repoId?: string
sourceContext?: TaskSourceContext | null
}) => Promise<GitHubAssignableUser[]>
/** Subscribe to local-mutation broadcasts so the work-item-drawer cache can invalidate across windows. Returns an unsubscribe. */
onWorkItemMutated: (
callback: (payload: {
repoPath: string
repoId?: string
type: 'issue' | 'pr'
number: number
}) => void
) => () => void
// ── ProjectV2 (GitHub Projects) ─────────────────────────────────
listAccessibleProjects: (
args?: ListAccessibleProjectsArgs
) => Promise<ListAccessibleProjectsResult>
resolveProjectRef: (args: ResolveProjectRefArgs) => Promise<ResolveProjectRefResult>
listProjectViews: (args: ListProjectViewsArgs) => Promise<ListProjectViewsResult>
getProjectViewTable: (args: GetProjectViewTableArgs) => Promise<GetProjectViewTableResult>
projectWorkItemDetailsBySlug: (
args: ProjectWorkItemDetailsBySlugArgs
) => Promise<ProjectWorkItemDetailsBySlugResult>
updateProjectItemField: (args: UpdateProjectItemFieldArgs) => Promise<GitHubProjectMutationResult>
clearProjectItemField: (args: ClearProjectItemFieldArgs) => Promise<GitHubProjectMutationResult>
updateIssueBySlug: (args: UpdateIssueBySlugArgs) => Promise<GitHubProjectMutationResult>
updatePullRequestBySlug: (
args: UpdatePullRequestBySlugArgs
) => Promise<GitHubProjectMutationResult>
addIssueCommentBySlug: (
args: AddIssueCommentBySlugArgs
) => Promise<GitHubProjectCommentMutationResult>
updateIssueCommentBySlug: (
args: UpdateIssueCommentBySlugArgs
) => Promise<GitHubProjectMutationResult>
deleteIssueCommentBySlug: (
args: DeleteIssueCommentBySlugArgs
) => Promise<GitHubProjectMutationResult>
listLabelsBySlug: (args: ListLabelsBySlugArgs) => Promise<ListLabelsBySlugResult>
listAssignableUsersBySlug: (
args: ListAssignableUsersBySlugArgs
) => Promise<ListAssignableUsersBySlugResult>
listIssueTypesBySlug: (args: ListIssueTypesBySlugArgs) => Promise<ListIssueTypesBySlugResult>
updateIssueTypeBySlug: (args: UpdateIssueTypeBySlugArgs) => Promise<GitHubProjectMutationResult>
}