ObservabilityModule · library/observability/src/repos/errors.ts:118

ErrorsRepo

component

No JSDoc comment in source yet.

API

@Component()
export class ErrorsRepo implements ErrorLog {
  @Use() private readonly db!: Db;
  insert(r: ErrorRecordInsert): void;
  summary(projectId: string, f: ErrorFilter = {}): ErrorSummary;
  topCode(projectId: string, f: ErrorFilter = {}): ErrorCodeCount | null;
  recent(projectId: string, f: ErrorFilter = {}, limit = 20, offset = 0, utcOffsetMinutes?: number): ErrorItem[];
  rowCount(projectId: string, f: ErrorFilter = {}, utcOffsetMinutes?: number): number;
  deleteFiltered(projectId: string, f: ErrorFilter = {}): number;
  deleteByAgent(projectId: string, agentId: string): void;
  deleteByProject(projectId: string): void;
}

Dependencies & Wiring

Extracted from class decorators
implementsinterfaces
@Userequires (1)
db: Db

Methods (8)

insert

insert(r: ErrorRecordInsert): void
@paramrErrorRecordInsert
@returnsvoid

summary

summary(projectId: string, f: ErrorFilter = {}): ErrorSummary

Total count + how many are unexpected.

@paramprojectIdstring
@paramf?ErrorFilter
@returnsErrorSummary

topCode

topCode(projectId: string, f: ErrorFilter = {}): ErrorCodeCount | null

The most frequent source · code (ties broken by code's lexicographic order); null if there are no errors.

@paramprojectIdstring
@paramf?ErrorFilter
@returnsErrorCodeCount | null

recent

recent(projectId: string, f: ErrorFilter = {}, limit = 20, offset = 0, utcOffsetMinutes?: number): ErrorItem[]

One page of the table, newest first: the records of one calendar day that share a source, code, kind and message fold into a single row, with how many there were and the first and last time among them.

A failure that comes back all day — a connection that drops and recovers every few minutes, a send that fails whenever it is asked — reads as one line saying how often, rather than a page of the same line; summary and topCode still count records, which is what measures how often. The day is utcOffsetMinutes's (see dayOf), so the boundary falls at the viewer's midnight. Rows are ordered by their newest record, and a page is limit rows, not records.

@paramprojectIdstring
@paramf?ErrorFilter
@paramlimit?unknown
@paramoffset?unknown
@paramutcOffsetMinutes?number
@returnsErrorItem[]

rowCount

rowCount(projectId: string, f: ErrorFilter = {}, utcOffsetMinutes?: number): number

How many rows recent pages through for the same filter and day — what a pager counts.

@paramprojectIdstring
@paramf?ErrorFilter
@paramutcOffsetMinutes?number
@returnsnumber

deleteFiltered

deleteFiltered(projectId: string, f: ErrorFilter = {}): number

Deletes the rows a matching read would have returned, and answers how many went.

The WHERE comes from the same conds the SELECTs use, includeGlobal included, so the delete reaches exactly the rows the caller's own reads reach and never one more: narrowing a filter narrows both halves together, and there is no second expression to drift. The caller passes the includeGlobal it reads with — an admin's clear takes the unattributed rows an admin's panel shows, and a member's clear, like a member's read, never sees them. Unattributed rows sit in every Project's admin view, so clearing them from one Project's panel clears them from every other's too: that is the one person who can see them anywhere emptying instance-wide noise, not one tenant reaching into another. deleteByProject and deleteByAgent keep leaving them alone — a cascade is not a person deciding to clear.

@paramprojectIdstring
@paramf?ErrorFilter
@returnsnumber

deleteByAgent

deleteByAgent(projectId: string, agentId: string): void

Cascading cleanup on Agent deletion (unattributed errors carry no agent_id and are unaffected).

@paramprojectIdstring
@paramagentIdstring
@returnsvoid

deleteByProject

deleteByProject(projectId: string): void

Cascading cleanup on Project deletion (unattributed errors belong to no Project and are unaffected).

@paramprojectIdstring
@returnsvoid