Kaizen
Browse modulesPersistenceClasses

Abstract Class: BaseRepository<TClient, TTx = `TClient`>

Defined in: server/persistence/base-repository.ts:54

Base repository providing transaction routing, audit-field helpers, and opt-in activity logging. Extend one of the specialized classes instead of using this directly:

  • ReadRepository — read-only
  • WriteRepository — create + update (append-only)
  • CrudRepository — full CRUD (most common)
  • VersionRepository — parent-child versioning

TClient is the consumer's generated Prisma client (for model accessors on this.tx). TTx is the transaction handle type (the inner argument of prisma.$transaction(fn)); it defaults to TClient because modern Prisma transaction handles are structurally compatible with the top-level client apart from the $-prefixed control methods.

Extended by

Type Parameters

Type ParameterDefault type
TClient-
TTxTClient

Constructors

Constructor

new BaseRepository<TClient, TTx = TClient>(prismaClient: PrismaClientLike<TTx> & TClient, options?: RepositoryOptions): BaseRepository<TClient, TTx>;

Defined in: server/persistence/base-repository.ts:68

Parameters

ParameterType
prismaClientPrismaClientLike<TTx> & TClient
optionsRepositoryOptions

Returns

BaseRepository<TClient, TTx>

Properties

ENTITY_TYPE?

protected readonly optional ENTITY_TYPE?: string;

Defined in: server/persistence/base-repository.ts:61

Set ENTITY_TYPE in child repositories to enable automatic activity logging. When set, create/update/delete operations auto-log unless silenced with .silent. Requires an activity model on the consumer's Prisma schema.


logger?

protected readonly optional logger?: Logger;

Defined in: server/persistence/base-repository.ts:64


prismaClient

protected prismaClient: PrismaClientLike<TTx> & TClient;

Defined in: server/persistence/base-repository.ts:69

Accessors

actorId

Get Signature

get protected actorId(): string | null | undefined;

Defined in: server/persistence/base-repository.ts:76

Returns

string | null | undefined


auditCreate

Get Signature

get protected auditCreate(): {
  createdBy: string | null | undefined;
  updatedBy: string | null | undefined;
};

Defined in: server/persistence/base-repository.ts:90

Returns
{
  createdBy: string | null | undefined;
  updatedBy: string | null | undefined;
}
createdBy
createdBy: string | null | undefined = actorId;
updatedBy
updatedBy: string | null | undefined = actorId;

auditDelete

Get Signature

get protected auditDelete(): {
  deletedAt: Date;
  deletedBy: string | null | undefined;
};

Defined in: server/persistence/base-repository.ts:99

Returns
{
  deletedAt: Date;
  deletedBy: string | null | undefined;
}
deletedAt
deletedAt: Date;
deletedBy
deletedBy: string | null | undefined;

auditUpdate

Get Signature

get protected auditUpdate(): {
  updatedBy: string | null | undefined;
};

Defined in: server/persistence/base-repository.ts:95

Returns
{
  updatedBy: string | null | undefined;
}
updatedBy
updatedBy: string | null | undefined;

silent

Get Signature

get silent(): this;

Defined in: server/persistence/base-repository.ts:115

Suppress activity logging for the next mutation call. One-shot: the flag is consumed by the next create/update/delete.

Example
await repo.silent.update(id, data);   // no activity logged
await repo.update(id, data);          // activity logged normally
Returns

this


tx

Get Signature

get protected tx(): TTx;

Defined in: server/persistence/base-repository.ts:86

The current Prisma handle: the active transaction if one is running on this async context, otherwise the raw client.

Returns

TTx

Methods

consumeSilent()

protected consumeSilent(): boolean;

Defined in: server/persistence/base-repository.ts:128

Consume and reset the silent flag. Called by template methods.

Returns

boolean


logActivity()

protected logActivity(
   _entityId: string, 
   _action: string, 
   _metadata?: Record<string, unknown>
): Promise<void>;

Defined in: server/persistence/base-repository.ts:140

Log an activity entry.

NOTE: This is not implemented because there's no activity model implemented in taproot yet! https://linear.app/kaizenlabs/issue/ENG-7846/add-activity-log-tables

Parameters

ParameterType
_entityIdstring
_actionstring
_metadata?Record<string, unknown>

Returns

Promise<void>

On this page