# @zerotal/audit — public API surface

<!-- AUTO-GENERATED by scripts/api-surface.ts. Do not edit by hand.
     Run `bun run api:surface` to regenerate after an intentional API change. -->

> Not a guide — this is a flat, alphabetical snapshot used to detect unintended
> API changes. For how to use these, read the [documentation](https://zerotal.dev/docs).

## .  `(./src/index.ts)`

class AuditLog = {
  new (): AuditLog
  static _isFillable: (key: string) => boolean
  static _unscopedQuery: <T extends BaseModel>(this: typeof BaseModel & (new () => T)) => ModelQueryBuilder<T>
  static addGlobalScope: <T extends BaseModel>(this: typeof BaseModel & (new () => T), name: string, callback: GlobalScopeCallback) => void
  static all: <T extends BaseModel>(this: typeof BaseModel & (new () => T)) => Promise<T[]>
  static appends: string[]
  static bulkInsert: <T extends BaseModel>(this: typeof BaseModel & (new () => T), records: InsertPayload<T>[]) => Promise<number>
  static byActor: (actorId: number) => ScopeApplicator
  static casts?: Record<string, 'boolean' | 'date' | 'datetime' | 'array' | 'integer' | 'json' | 'float' | 'enum' | 'immutable_datetime' | 'encrypted' | 'encrypted:json' | `decimal:${number}` | {    get?: (dbValue: unknown) => unknown;    set?: (jsValue: unknown) => unknown;} | CastContract<unknown> | undefined>
  static connection?: string
  static count: <T extends BaseModel>(this: typeof BaseModel & (new () => T)) => Promise<number>
  static create: <T extends BaseModel, F extends string = string>(this: (typeof BaseModel & (new () => T)) & {    fillable?: readonly F[] | undefined;}, data: FillablePayload<T, F>) => Promise<T>
  static createMany: <T extends BaseModel>(this: typeof BaseModel & (new () => T), records: InsertPayload<T>[]) => Promise<T[]>
  static dispatchesEvents?: Record<string, new (model: unknown) => object>
  static encryptable?: string[]
  static fillable?: readonly string[]
  static find: <T extends BaseModel>(this: typeof BaseModel & (new () => T), id: number | string) => Promise<T | null>
  static findBy: <T extends BaseModel>(this: typeof BaseModel & (new () => T), column: string, value: unknown) => Promise<T | null>
  static findMany: <T extends BaseModel>(this: typeof BaseModel & (new () => T), ids: (number | string)[]) => Promise<T[]>
  static findOrFail: <T extends BaseModel>(this: typeof BaseModel & (new () => T), id: number | string) => Promise<T>
  static findOrNew: <T extends BaseModel>(this: typeof BaseModel & (new () => T), id: number | string) => Promise<T>
  static first: <T extends BaseModel>(this: typeof BaseModel & (new () => T)) => Promise<T | null>
  static firstOrCreate: <T extends BaseModel>(this: typeof BaseModel & (new () => T), search: UpdatePayload<T>, create?: UpdatePayload<T>) => Promise<T>
  static firstOrFail: <T extends BaseModel>(this: typeof BaseModel & (new () => T)) => Promise<T>
  static firstOrNew: <T extends BaseModel>(this: typeof BaseModel & (new () => T), search: UpdatePayload<T>, values?: UpdatePayload<T>) => Promise<T>
  static forModel: (type: string, id: string | number) => ScopeApplicator
  static forceCreate: <T extends BaseModel>(this: typeof BaseModel & (new () => T), data: Record<string, unknown>) => Promise<T>
  static fromRow: (row: Record<string, unknown>) => BaseModel
  static guarded?: readonly string[]
  static hashable?: string[]
  static hidden: string[]
  static implicitBinding?: boolean
  static implicitBindingKey?: string
  static latest: <T extends BaseModel>(this: typeof BaseModel & (new () => T), column?: string) => ModelQueryBuilder<T>
  static loadCount: <T extends BaseModel>(this: typeof BaseModel, models: T[], relations: string | string[]) => Promise<T[]>
  static massPrune: boolean
  static observe: <T extends BaseModel>(this: typeof BaseModel & (new () => T), ObserverClass: new () => ModelObserver<T>) => void
  static ofEvent: (event: string) => ScopeApplicator
  static oldest: <T extends BaseModel>(this: typeof BaseModel & (new () => T), column?: string) => ModelQueryBuilder<T>
  static orderBy: <T extends BaseModel>(this: typeof BaseModel & (new () => T), column: string, direction?: OrderDirection) => ModelQueryBuilder<T>
  static paginate: <T extends BaseModel>(this: typeof BaseModel & (new () => T), perPage?: number, page?: number, pageName?: string) => Promise<PaginateResult<T>>
  static primaryKey: string
  static prunable?: <T extends BaseModel>(this: typeof BaseModel & (new () => T)) => ModelQueryBuilder<T>
  static prune: <T extends BaseModel>(this: typeof BaseModel & (new () => T), chunkSize?: number) => Promise<number>
  static query: <T extends BaseModel>(this: typeof BaseModel & (new () => T)) => ModelQueryBuilder<T>
  static reactiveCasts: boolean
  static registerConnection: (name: string, conn: SQLInstance, dialect?: Dialect) => void
  static reguard: () => void
  static removeGlobalScope: <T extends BaseModel>(this: typeof BaseModel & (new () => T), name: string) => void
  static saveMany: <T extends BaseModel>(this: typeof BaseModel & (new () => T), models: T[]) => Promise<T[]>
  static scope: <Args extends unknown[]>(fn: (query: QueryBuilder, ...args: Args) => void) => (...args: Args) => ScopeApplicator
  static softDeletes: boolean
  static table: string
  static timestamps: boolean
  static unguard: () => void
  static unguarded: boolean
  static updateOrCreate: <T extends BaseModel>(this: typeof BaseModel & (new () => T), search: UpdatePayload<T>, values?: UpdatePayload<T>) => Promise<T>
  static upsert: <T extends BaseModel>(this: typeof BaseModel & (new () => T), data: InsertPayload<T>, conflictKeys: (keyof T & string)[], updateCols?: (keyof T & string)[]) => Promise<void>
  static using: Compose
  static visible: string[]
  static where: {    <T extends BaseModel>(this: typeof BaseModel & (new () => T), column: string, value: unknown): ModelQueryBuilder<T>;    <T extends BaseModel>(this: typeof BaseModel & (new () => T), column: string, operator: WhereOperator, value: unknown): ModelQueryBuilder<T>;}
  static whereIn: <T extends BaseModel>(this: typeof BaseModel & (new () => T), column: string, values: unknown[]) => ModelQueryBuilder<T>
  static withoutGuard: <T>(callback: () => T | Promise<T>) => Promise<T>
  static withoutTimestamps: <R>(callback: () => Promise<R> | R) => Promise<R>
  $dirty: () => Record<string, unknown>
  actorId: number | null
  actorType: string | null
  append: (...keys: string[]) => AuditLog
  associate: (relation: string, model: BaseModel) => AuditLog
  auditableId: string | null
  auditableType: string
  changedKeys: string[]
  createdAt: Carbon
  decrement: (column: 'id' | 'url' | 'tags' | 'event' | 'createdAt' | 'updatedAt' | 'auditableType' | 'auditableId' | 'actorType' | 'actorId' | 'oldValues' | 'newValues' | 'ipAddress' | 'userAgent' | 'changedKeys' | 'oldParsed' | 'newParsed' | '__isZerotalModel' | 'fill' | 'forceFill' | 'save' | 'delete' | 'load' | 'loadMissing' | 'fresh' | 'refresh' | 'replicate' | 'touch' | 'is' | 'isNot' | 'increment' | 'decrement' | 'loadCount' | 'loadSum' | 'loadAvg' | 'loadMin' | 'loadMax' | 'makeHidden' | 'makeVisible' | 'append' | 'associate' | 'dissociate' | 'isDirty' | '$dirty' | 'markDirty' | 'toJSON', amount?: number) => Promise<AuditLog>
  delete: () => Promise<void>
  dissociate: (relation: string) => AuditLog
  event: string
  fill: (data: Partial<InsertPayload<AuditLog>>) => AuditLog
  forceFill: (data: Record<string, unknown>) => AuditLog
  fresh: () => Promise<AuditLog>
  id: number
  increment: (column: 'id' | 'url' | 'tags' | 'event' | 'createdAt' | 'updatedAt' | 'auditableType' | 'auditableId' | 'actorType' | 'actorId' | 'oldValues' | 'newValues' | 'ipAddress' | 'userAgent' | 'changedKeys' | 'oldParsed' | 'newParsed' | '__isZerotalModel' | 'fill' | 'forceFill' | 'save' | 'delete' | 'load' | 'loadMissing' | 'fresh' | 'refresh' | 'replicate' | 'touch' | 'is' | 'isNot' | 'increment' | 'decrement' | 'loadCount' | 'loadSum' | 'loadAvg' | 'loadMin' | 'loadMax' | 'makeHidden' | 'makeVisible' | 'append' | 'associate' | 'dissociate' | 'isDirty' | '$dirty' | 'markDirty' | 'toJSON', amount?: number) => Promise<AuditLog>
  ipAddress: string | null
  is: (other: BaseModel | null | undefined) => boolean
  isDirty: (column?: string) => boolean
  isNot: (other: BaseModel | null | undefined) => boolean
  load: (relations: string[]) => Promise<AuditLog>
  loadAvg: (relation: string, column: string) => Promise<AuditLog>
  loadCount: (relations: string | string[]) => Promise<AuditLog>
  loadMax: (relation: string, column: string) => Promise<AuditLog>
  loadMin: (relation: string, column: string) => Promise<AuditLog>
  loadMissing: (relations: string[]) => Promise<AuditLog>
  loadSum: (relation: string, column: string) => Promise<AuditLog>
  makeHidden: (...keys: string[]) => AuditLog
  makeVisible: (...keys: string[]) => AuditLog
  markDirty: (property: keyof AuditLog) => AuditLog
  newParsed: Record<string, unknown>
  newValues: Record<string, unknown> | null
  oldParsed: Record<string, unknown>
  oldValues: Record<string, unknown> | null
  readonly __isZerotalModel: true
  refresh: () => Promise<AuditLog>
  replicate: (except?: string[]) => AuditLog
  save: () => Promise<AuditLog>
  tags: Record<string, unknown> | null
  toJSON: () => Record<string, unknown>
  touch: () => Promise<AuditLog>
  updatedAt?: Carbon
  url: string | null
  userAgent: string | null
}

class AuditObserver = {
  new (auditor: Auditor): AuditObserver
  created: (model: AnyModel) => Promise<void>
  deleted: (model: AnyModel) => Promise<void>
  saving: (model: AnyModel) => Promise<void>
  updated: (model: AnyModel) => Promise<void>
}

class Auditor = {
  new (driver: AuditDriver, config: AuditConfigShape): Auditor
  _recordModel: (payload: AuditPayload) => Promise<void>
  historyFor: (type: string, id: string | number, limit?: number) => Promise<AuditRecord[]>
  log: {    (event: AuditEvent, model: BaseModel, payload?: InstanceAuditPayload): Promise<void>;    (event: AuditEvent, payload: Omit<AuditPayload, 'event'>): Promise<void>;}
  logs: (model: AuditableRef, id: string | number) => ModelQueryBuilder<AuditLog>
  logsByActor: (actorId: number) => ModelQueryBuilder<AuditLog>
  logsOfEvent: (event: AuditEvent) => ModelQueryBuilder<AuditLog>
}

class AuditProvider = {
  new (app: Application): AuditProvider
  static dependsOn?: (new (app: Application) => ServiceProvider)[]
  static environments: AppEnvironment[]
  static priority?: number
  static provides: readonly ['audit']
  devProcesses: () => DevProcessDefinition[]
  doctorChecks: () => DoctorCheck[]
  onBooted: () => Promise<void>
  onBooting: () => Promise<void>
  onRegister: () => void
  onRequestProcessed: (_ctx: HttpContext) => Promise<void>
  onRequestReceived: (_ctx: HttpContext) => Promise<void>
  onResponseSent: (_ctx: HttpContext) => Promise<void>
  onStarted: () => Promise<void>
  onStarting: () => Promise<void>
  onStopped: () => Promise<void>
  onStopping: () => Promise<void>
  replContext: () => Record<string, unknown>
}

class DatabaseDriver = {
  new (table?: string): DatabaseDriver
  forModel: (type: string, id: string | number, limit?: number) => Promise<AuditRecord[]>
  record: (payload: AuditPayload) => Promise<void>
}

class NullDriver = {
  new (): NullDriver
  forModel: (_type: string, _id: string | number, _limit?: number) => Promise<AuditRecord[]>
  record: (_payload: AuditPayload) => Promise<void>
}

const Audit = Auditor

function Auditable = <TBase extends Constructor>(Base: TBase) => {    new (...args: any[]): Auditable;    prototype: Auditable<any>.Auditable;} & TBase

function AuditConfig = (options?: Partial<AuditConfigShape>) => {    audit: AuditConfigShape;}

function registerAudit = (ModelClass: ModelClass) => void

interface AuditableOptions = {
  except?: string[] | undefined
  only?: string[] | undefined
  type?: string | undefined
}

interface AuditConfigShape = {
  captureRequest?: boolean | undefined
  driver: 'null' | 'database'
  pruneKeep?: number | undefined
  table?: string | undefined
}

interface AuditDriver = {
  forModel: (type: string, id: string | number, limit?: number) => Promise<AuditRecord[]>
  record: (payload: AuditPayload) => Promise<void>
}

interface AuditPayload = {
  actor_id?: number | null
  actor_type?: string | null
  auditable_id?: string | number | null
  auditable_type: string
  event: string
  ip_address?: string | null
  new_values?: Record<string, unknown> | null
  old_values?: Record<string, unknown> | null
  tags?: Record<string, unknown> | null
  url?: string | null
  user_agent?: string | null
}

interface AuditRecord = {
  actor_id: number | null
  actor_type: string | null
  auditable_id: string | null
  auditable_type: string
  created_at: string
  event: string
  id: number
  ip_address: string | null
  new_values: string | null
  old_values: string | null
  tags: string | null
  url: string | null
  user_agent: string | null
}

type AuditableRef = string | { name: string; auditType?: string }

type AuditEvent = 'created' | 'updated' | 'deleted' | 'restored' | string

type InstanceAuditPayload = {    url?: string | null;    tags?: Record<string, unknown> | null;    actor_type?: string | null;    actor_id?: number | null;    old_values?: Record<string, unknown> | null;    new_values?: Record<string, unknown> | null;    ip_address?: string | null;    user_agent?: string | null;}
