@triagepilot/db 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +105 -0
- package/dist/availability.d.ts +164 -0
- package/dist/availability.js +974 -0
- package/dist/database.d.ts +3 -0
- package/dist/database.js +9 -0
- package/dist/decisions.d.ts +107 -0
- package/dist/decisions.js +435 -0
- package/dist/deliveries.d.ts +30 -0
- package/dist/deliveries.js +82 -0
- package/dist/heartbeat.d.ts +11 -0
- package/dist/heartbeat.js +11 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +13 -0
- package/dist/jobs.d.ts +86 -0
- package/dist/jobs.js +641 -0
- package/dist/kysely.d.ts +202 -0
- package/dist/kysely.js +1 -0
- package/dist/migrate.d.ts +1 -0
- package/dist/migrate.js +45 -0
- package/dist/operations.d.ts +77 -0
- package/dist/operations.js +256 -0
- package/dist/outbox.d.ts +61 -0
- package/dist/outbox.js +230 -0
- package/dist/provider-connections.d.ts +34 -0
- package/dist/provider-connections.js +302 -0
- package/dist/retention.d.ts +6 -0
- package/dist/retention.js +44 -0
- package/dist/routing-recovery.d.ts +55 -0
- package/dist/routing-recovery.js +175 -0
- package/dist/workspaces.d.ts +50 -0
- package/dist/workspaces.js +43 -0
- package/migrations/0001_initial.sql +79 -0
- package/migrations/0002_selected_reviewers.sql +10 -0
- package/migrations/0003_human_review_policy.sql +10 -0
- package/migrations/0004_semantic_routing_deduplication.sql +15 -0
- package/migrations/0005_reviewer_availability.sql +58 -0
- package/migrations/0005_workspace_scope.sql +198 -0
- package/migrations/0006_decision_outbox.sql +24 -0
- package/migrations/0007_workspace_reviewer_availability.sql +192 -0
- package/migrations/0008_reviewer_mutation_intents.sql +160 -0
- package/migrations/0009_provider_connection_revocations.sql +18 -0
- package/migrations/0010_provider_connection_preemptive_revocations.sql +12 -0
- package/package.json +42 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Kysely } from "kysely";
|
|
2
|
+
import type { Database } from "./kysely.js";
|
|
3
|
+
export interface WorkerHeartbeat {
|
|
4
|
+
workerId: string;
|
|
5
|
+
heartbeatAt: Date;
|
|
6
|
+
}
|
|
7
|
+
export declare function updateWorkerHeartbeat(db: Kysely<Database>, input: {
|
|
8
|
+
workerId: string;
|
|
9
|
+
now: Date;
|
|
10
|
+
}): Promise<void>;
|
|
11
|
+
export declare function readWorkerHeartbeat(db: Kysely<Database>): Promise<WorkerHeartbeat | null>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export async function updateWorkerHeartbeat(db, input) {
|
|
2
|
+
await db
|
|
3
|
+
.insertInto("worker_heartbeat")
|
|
4
|
+
.values({ worker_id: input.workerId, heartbeat_at: input.now })
|
|
5
|
+
.onConflict((conflict) => conflict.column("id").doUpdateSet({ worker_id: input.workerId, heartbeat_at: input.now }))
|
|
6
|
+
.execute();
|
|
7
|
+
}
|
|
8
|
+
export async function readWorkerHeartbeat(db) {
|
|
9
|
+
const row = await db.selectFrom("worker_heartbeat").select(["worker_id", "heartbeat_at"]).executeTakeFirst();
|
|
10
|
+
return row ? { workerId: row.worker_id, heartbeatAt: row.heartbeat_at } : null;
|
|
11
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { buildNextRunAt, createJobClaimer, createWorkspaceJobQueue, prepareClaimedReviewerMutationIntent, runClaimedReviewerProviderMutation, type EnqueueJobInput, type JobKind, type JobLease, type JobClaimer, type JobRecord, type JobRecovery, type JobStatus, type JobTransitionResult, ReviewerMutationLeaseUnavailableError, type WorkspaceJobQueue, recoverStaleJobs, } from "./jobs.js";
|
|
2
|
+
export { createDatabase } from "./database.js";
|
|
3
|
+
export { findReviewerReplacementCandidates, markActionFailed, markActionSucceeded, findLatestHumanReviewPolicyDecision, persistDecision, persistDecisionWithEvent, recordPolicyCheck, updatePolicyCheckState, type DecisionInput, type HumanReviewPolicyDecision, type PersistedDecision, type PersistedDecisionEventContext, type ReviewerReplacementCandidateDecision, } from "./decisions.js";
|
|
4
|
+
export { ProviderConnectionUnavailableError, ReviewerAbsenceConflictError, ReviewerAbsenceRevisionError, ReviewerAvailabilityValidationError, createWorkspaceReviewerAvailability, prepareMutationIntentTransaction, type CancelAbsenceInput, type PersistReviewerReplacementInput, type PersistReviewerReplacementResult, type PrepareReviewerMutationIntentInput, type ReviewerAbsence, type ReviewerAbsenceActivation, type ReviewerAbsenceWindow, type ReviewerReplacement, type ReviewerMutationIntent, type ReviewerMutationIntentKey, type ReviewerReplacementState, type ReviseAbsenceInput, type ScheduleAbsenceInput, type WorkspaceOperationalSettings, type WorkspaceReviewerAvailability, } from "./availability.js";
|
|
5
|
+
export { claimPlatformEvents, createPlatformOutboxRepository, markPlatformEventPublished, publishPlatformOutbox, stagePlatformEvent, type PlatformOutboxRecord, type PlatformOutboxRepository, } from "./outbox.js";
|
|
6
|
+
export { acceptHumanReviewPolicyDelivery, acceptRoutingDelivery, type HumanReviewPolicyDeliveryInput, type RoutingDeliveryInput, } from "./deliveries.js";
|
|
7
|
+
export { readWorkerHeartbeat, updateWorkerHeartbeat, type WorkerHeartbeat } from "./heartbeat.js";
|
|
8
|
+
export { createWorkspaceRoutingRecoveryRepository, enqueueRoutingRecovery, findActiveExternalConnectionId, findActiveRecoveryRepository, findRoutingRecoveryTarget, type RoutingRecoveryEnqueueInput, type RoutingRecoveryTarget, type RoutingRecoveryTargetRequest, type WorkspaceRoutingRecoveryRepository, } from "./routing-recovery.js";
|
|
9
|
+
export { findRepositoryConfigurationTarget, readOperationsOverview, type ActionFailureOverview, type DecisionOverview, type JobFailureOverview, type OperationsOverview, type RepositoryConfigurationTarget, type ReadOperationsOverviewInput, type RepositoryOverview, } from "./operations.js";
|
|
10
|
+
export { activateConfiguredProviderConnection, cleanupRevokedProviderConnections, replaceProviderConnectionRepositories, revokeConfiguredProviderConnection, suspendConfiguredProviderConnection, updateProviderConnectionRepositories, upsertConfiguredProviderConnection, type ConfiguredProviderConnectionInput, type ProviderConnectionMetadata, type ProviderConnectionRepositoryUpdateInput, type ProviderRepositoryMetadata, } from "./provider-connections.js";
|
|
11
|
+
export { applyFixedRetention, DECISION_AND_FAILURE_DAYS, RECEIPT_AND_COMPLETED_JOB_DAYS, } from "./retention.js";
|
|
12
|
+
export { runMigrations } from "./migrate.js";
|
|
13
|
+
export type { Database, DecisionOutboxTable, WorkerHeartbeatTable } from "./kysely.js";
|
|
14
|
+
export { createWorkspaceRepositories, ensureLocalWorkspace, LOCAL_WORKSPACE_EXTERNAL_KEY, type WorkspaceRepositories, } from "./workspaces.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { buildNextRunAt, createJobClaimer, createWorkspaceJobQueue, prepareClaimedReviewerMutationIntent, runClaimedReviewerProviderMutation, ReviewerMutationLeaseUnavailableError, recoverStaleJobs, } from "./jobs.js";
|
|
2
|
+
export { createDatabase } from "./database.js";
|
|
3
|
+
export { findReviewerReplacementCandidates, markActionFailed, markActionSucceeded, findLatestHumanReviewPolicyDecision, persistDecision, persistDecisionWithEvent, recordPolicyCheck, updatePolicyCheckState, } from "./decisions.js";
|
|
4
|
+
export { ProviderConnectionUnavailableError, ReviewerAbsenceConflictError, ReviewerAbsenceRevisionError, ReviewerAvailabilityValidationError, createWorkspaceReviewerAvailability, prepareMutationIntentTransaction, } from "./availability.js";
|
|
5
|
+
export { claimPlatformEvents, createPlatformOutboxRepository, markPlatformEventPublished, publishPlatformOutbox, stagePlatformEvent, } from "./outbox.js";
|
|
6
|
+
export { acceptHumanReviewPolicyDelivery, acceptRoutingDelivery, } from "./deliveries.js";
|
|
7
|
+
export { readWorkerHeartbeat, updateWorkerHeartbeat } from "./heartbeat.js";
|
|
8
|
+
export { createWorkspaceRoutingRecoveryRepository, enqueueRoutingRecovery, findActiveExternalConnectionId, findActiveRecoveryRepository, findRoutingRecoveryTarget, } from "./routing-recovery.js";
|
|
9
|
+
export { findRepositoryConfigurationTarget, readOperationsOverview, } from "./operations.js";
|
|
10
|
+
export { activateConfiguredProviderConnection, cleanupRevokedProviderConnections, replaceProviderConnectionRepositories, revokeConfiguredProviderConnection, suspendConfiguredProviderConnection, updateProviderConnectionRepositories, upsertConfiguredProviderConnection, } from "./provider-connections.js";
|
|
11
|
+
export { applyFixedRetention, DECISION_AND_FAILURE_DAYS, RECEIPT_AND_COMPLETED_JOB_DAYS, } from "./retention.js";
|
|
12
|
+
export { runMigrations } from "./migrate.js";
|
|
13
|
+
export { createWorkspaceRepositories, ensureLocalWorkspace, LOCAL_WORKSPACE_EXTERNAL_KEY, } from "./workspaces.js";
|
package/dist/jobs.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { type Kysely } from "kysely";
|
|
2
|
+
import type { ProviderConnectionId, ProviderKind, WorkspaceId } from "@triagepilot/contracts";
|
|
3
|
+
import type { Database } from "./kysely.js";
|
|
4
|
+
import { type PrepareReviewerMutationIntentInput, type ReviewerMutationIntent } from "./availability.js";
|
|
5
|
+
export type JobKind = "process_pull_request" | "evaluate_human_review_policy" | "activate_reviewer_absence";
|
|
6
|
+
export type JobStatus = "queued" | "running" | "succeeded" | "failed";
|
|
7
|
+
export interface JobRecord {
|
|
8
|
+
id: string;
|
|
9
|
+
workspaceId: WorkspaceId;
|
|
10
|
+
provider: ProviderKind;
|
|
11
|
+
providerConnectionId: ProviderConnectionId;
|
|
12
|
+
kind: JobKind;
|
|
13
|
+
status: JobStatus;
|
|
14
|
+
payload: unknown;
|
|
15
|
+
idempotencyKey: string;
|
|
16
|
+
attemptCount: number;
|
|
17
|
+
maxAttempts: number;
|
|
18
|
+
runAt: Date;
|
|
19
|
+
lockedAt: Date | null;
|
|
20
|
+
lockedBy: string | null;
|
|
21
|
+
lastError: string | null;
|
|
22
|
+
}
|
|
23
|
+
export interface EnqueueJobInput {
|
|
24
|
+
provider: ProviderKind;
|
|
25
|
+
providerConnectionId: ProviderConnectionId;
|
|
26
|
+
kind: JobKind;
|
|
27
|
+
payload: unknown;
|
|
28
|
+
idempotencyKey: string;
|
|
29
|
+
runAt?: Date;
|
|
30
|
+
maxAttempts?: number;
|
|
31
|
+
}
|
|
32
|
+
export interface JobLease {
|
|
33
|
+
jobId: string;
|
|
34
|
+
workspaceId: WorkspaceId;
|
|
35
|
+
provider: ProviderKind;
|
|
36
|
+
providerConnectionId: ProviderConnectionId;
|
|
37
|
+
lockedBy: string;
|
|
38
|
+
lockedAt: Date;
|
|
39
|
+
attemptCount: number;
|
|
40
|
+
maxAttempts: number;
|
|
41
|
+
}
|
|
42
|
+
export type JobTransitionResult = {
|
|
43
|
+
updated: true;
|
|
44
|
+
} | {
|
|
45
|
+
updated: false;
|
|
46
|
+
reason: "stale_lease";
|
|
47
|
+
};
|
|
48
|
+
export declare class ReviewerMutationLeaseUnavailableError extends Error {
|
|
49
|
+
}
|
|
50
|
+
export interface ReviewerMutationAuthority {
|
|
51
|
+
signal: AbortSignal;
|
|
52
|
+
assertActive(): Promise<void>;
|
|
53
|
+
}
|
|
54
|
+
export interface JobRecovery {
|
|
55
|
+
payload: unknown;
|
|
56
|
+
maxAttempts: number;
|
|
57
|
+
}
|
|
58
|
+
export interface WorkspaceJobQueue {
|
|
59
|
+
enqueue(input: EnqueueJobInput): Promise<{
|
|
60
|
+
inserted: boolean;
|
|
61
|
+
jobId: string;
|
|
62
|
+
}>;
|
|
63
|
+
markSucceeded(lease: JobLease, now: Date): Promise<JobTransitionResult>;
|
|
64
|
+
markFailed(lease: JobLease, error: string, now: Date, options: {
|
|
65
|
+
retryable: boolean;
|
|
66
|
+
recovery?: JobRecovery;
|
|
67
|
+
}): Promise<JobTransitionResult>;
|
|
68
|
+
exhaustReviewerAbsenceActivation(lease: JobLease, error: string, now: Date): Promise<JobTransitionResult>;
|
|
69
|
+
}
|
|
70
|
+
export interface JobClaimer {
|
|
71
|
+
claimNext(workerId: string, now: Date): Promise<JobRecord | null>;
|
|
72
|
+
}
|
|
73
|
+
export declare function buildNextRunAt(now: Date, attemptCount: number): Date;
|
|
74
|
+
export declare function prepareClaimedReviewerMutationIntent(db: Kysely<Database>, lease: JobLease, input: PrepareReviewerMutationIntentInput): Promise<ReviewerMutationIntent>;
|
|
75
|
+
export declare function runClaimedReviewerProviderMutation<T>(db: Kysely<Database>, lease: JobLease, scope: {
|
|
76
|
+
workspaceId: WorkspaceId;
|
|
77
|
+
provider: ProviderKind;
|
|
78
|
+
providerConnectionId: ProviderConnectionId;
|
|
79
|
+
absenceId: string;
|
|
80
|
+
absenceRevision: number;
|
|
81
|
+
}, mutation: (authority: ReviewerMutationAuthority) => Promise<T>, options?: {
|
|
82
|
+
timeoutMs?: number;
|
|
83
|
+
}): Promise<T>;
|
|
84
|
+
export declare function recoverStaleJobs(db: Kysely<Database>, workspaceId: WorkspaceId, now: Date, staleAfterMs?: number): Promise<void>;
|
|
85
|
+
export declare function createJobClaimer(db: Kysely<Database>): JobClaimer;
|
|
86
|
+
export declare function createWorkspaceJobQueue(db: Kysely<Database>, workspaceId: WorkspaceId): WorkspaceJobQueue;
|