Skip to main content

Class: AuditEngine

Defined in: src/audit/AuditEngine.ts:12

Engine that builds and persists AuditLogEntry rows to the audit changelog table.

This class is used internally by DbSet — it should not be instantiated directly by application code. All writes occur within the same transaction as the originating mutation, guaranteeing atomicity.

Constructors​

Constructor​

new AuditEngine(): AuditEngine

Returns​

AuditEngine

Methods​

shouldLog()​

static shouldLog(target): boolean

Defined in: src/audit/AuditEngine.ts:17

Returns true if the given entity class is decorated with @Auditable and has changelog: true.

Parameters​

ParameterType
targetFunction

Returns​

boolean


getOptions()​

static getOptions(target): AuditOptions | undefined

Defined in: src/audit/AuditEngine.ts:25

Returns the audit options for the given entity class, or undefined.

Parameters​

ParameterType
targetFunction

Returns​

AuditOptions | undefined


buildEntry()​

static buildEntry(operation, entityName, entityKey, newSnapshot, oldSnapshot, currentUser?, includeOld?): AuditLogEntry

Defined in: src/audit/AuditEngine.ts:33

Builds an AuditLogEntry object without persisting it. Used to preview or buffer audit rows.

Parameters​

ParameterTypeDefault value
operation"UPDATE" | "INSERT" | "DELETE"undefined
entityNamestringundefined
entityKeyunknownundefined
newSnapshotRecord<string, unknown> | undefinedundefined
oldSnapshotRecord<string, unknown> | undefinedundefined
currentUser?stringundefined
includeOld?booleantrue

Returns​

AuditLogEntry


write()​

static write(entry, adapter, auditTable?, transaction?): Promise<void>

Defined in: src/audit/AuditEngine.ts:70

Persists a single AuditLogEntry to the audit log table using the provided database adapter and optional transaction.

Parameters​

ParameterTypeDefault valueDescription
entryAuditLogEntryundefinedThe audit log entry to write.
adapterIDbAdapterundefinedThe database adapter to execute the INSERT against.
auditTablestring'_audit_log'Target table name (defaults to _audit_log).
transaction?DbTransactionundefinedOptional active transaction to enlist the INSERT in.

Returns​

Promise<void>


snapshot()​

static snapshot(entity): Record<string, unknown>

Defined in: src/audit/AuditEngine.ts:121

Takes a snapshot of an entity's own (non-relation, non-function) properties for storage as old_values / new_values in the audit log.

Parameters​

ParameterType
entityany

Returns​

Record<string, unknown>