Class: RuleVersionRepository
Defined in: server/rules/rule-version-repository.ts:33
Repository for version entities in parent-child versioning patterns.
Use for entities that:
- link to a parent entity via
parentId - order versions by
versionNumber - are append-only (immutable once created)
Provides findByParentId, findLatestByParentId,
getNextVersionNumber, countByParentId, and an audit-aware create.
Extends
VersionRepository<PrismaClient,RuleVersions,RuleVersionCreateInput,string,Tx<PrismaClient>>
Constructors
Constructor
new RuleVersionRepository(prismaClient: PrismaClientLike<Tx<PrismaClient<PrismaClientOptions, never, DefaultArgs>>> & PrismaClient<PrismaClientOptions, never, DefaultArgs>, options?: RepositoryOptions): RuleVersionRepository;Defined in: server/persistence/base-repository.ts:68
Parameters
| Parameter | Type |
|---|---|
prismaClient | PrismaClientLike<Tx<PrismaClient<PrismaClientOptions, never, DefaultArgs>>> & PrismaClient<PrismaClientOptions, never, DefaultArgs> |
options | RepositoryOptions |
Returns
RuleVersionRepository
Inherited from
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.
Inherited from
logger?
protected readonly optional logger?: Logger;Defined in: server/persistence/base-repository.ts:64
Inherited from
prismaClient
protected prismaClient: PrismaClientLike<Tx<PrismaClient<PrismaClientOptions, never, DefaultArgs>>> & PrismaClient<PrismaClientOptions, never, DefaultArgs>;Defined in: server/persistence/base-repository.ts:69
Inherited from
VersionRepository.prismaClient
Accessors
actorId
Get Signature
get protected actorId(): string | null | undefined;Defined in: server/persistence/base-repository.ts:76
Returns
string | null | undefined
Inherited from
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;Inherited from
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;Inherited from
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;Inherited from
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 normallyReturns
this
Inherited from
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
Inherited from
Methods
_count()
protected _count(): Promise<number>;Defined in: server/rules/rule-version-repository.ts:57
Returns
Promise<number>
Overrides
_countByParentId()
protected _countByParentId(ruleId: string): Promise<number>;Defined in: server/rules/rule-version-repository.ts:85
Parameters
| Parameter | Type |
|---|---|
ruleId | string |
Returns
Promise<number>
Overrides
VersionRepository._countByParentId
_create()
protected _create(input: RuleVersionCreateInput): Promise<{
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}>;Defined in: server/rules/rule-version-repository.ts:91
Parameters
| Parameter | Type |
|---|---|
input | RuleVersionCreateInput |
Returns
Promise<{
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}>
Overrides
_exists()
protected _exists(id: string): Promise<boolean>;Defined in: server/rules/rule-version-repository.ts:50
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Promise<boolean>
Overrides
_findById()
protected _findById(id: string): Promise<
| {
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}
| null>;Defined in: server/rules/rule-version-repository.ts:44
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Promise<
| {
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}
| null>
Overrides
_findByParentId()
protected _findByParentId(ruleId: string): Promise<{
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}[]>;Defined in: server/rules/rule-version-repository.ts:78
Parameters
| Parameter | Type |
|---|---|
ruleId | string |
Returns
Promise<{
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}[]>
Overrides
VersionRepository._findByParentId
_findMany()
protected _findMany(pagination: {
page: number;
pageSize: number;
}): Promise<{
items: {
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}[];
total: number;
}>;Defined in: server/rules/rule-version-repository.ts:61
Parameters
| Parameter | Type |
|---|---|
pagination | { page: number; pageSize: number; } |
pagination.page | number |
pagination.pageSize | number |
Returns
Promise<{
items: {
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}[];
total: number;
}>
Overrides
consumeSilent()
protected consumeSilent(): boolean;Defined in: server/persistence/base-repository.ts:128
Consume and reset the silent flag. Called by template methods.
Returns
boolean
Inherited from
VersionRepository.consumeSilent
count()
count(): Promise<number>;Defined in: server/persistence/base-repository.ts:191
Returns
Promise<number>
Inherited from
countByParentId()
countByParentId(parentId: string): Promise<number>;Defined in: server/persistence/base-repository.ts:261
Parameters
| Parameter | Type |
|---|---|
parentId | string |
Returns
Promise<number>
Inherited from
VersionRepository.countByParentId
create()
create(input: RuleVersionCreateInput): Promise<{
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}>;Defined in: server/persistence/base-repository.ts:265
Parameters
| Parameter | Type |
|---|---|
input | RuleVersionCreateInput |
Returns
Promise<{
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}>
Inherited from
createCopy()
createCopy(
source: {
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
},
versionNumber: number,
overrides: RuleVersionCopyOverrides
): Promise<{
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}>;Defined in: server/rules/rule-version-repository.ts:157
Copy a version verbatim, replacing only explicitly supplied fields.
Builds a RuleVersionCreateInput and goes through create() — the
template method — rather than issuing its own this.tx.ruleVersions.create.
_create stays the ONE place that maps a version onto Prisma's data shape,
which is the whole point of this class's shape (review finding).
The hand-written second payload it replaces had already drifted: _create
populates effectiveStart conditionally, the copy omitted the field
outright. Both reached the same result via @default(now()), so nothing was
broken — but two independent transcriptions of a ~10-field mapping with
nothing keeping them in step is a field-addition away from a real bug, and
the copy's own comment ("mirror _create") documented the duplication
instead of removing it.
effectiveStart is still left out, now deliberately and in one place: a copy
is a NEW version, so it starts now rather than inheriting the source's start.
That is exactly what _create's ...(input.effectiveStart && {...}) does
with an absent value, so routing through it preserves today's behaviour.
fromJsonColumn re-applies the domain types that toJsonColumn erased on
the way in — the paired read boundary, so this adds no new assertion. Its
type argument is left to contextual inference from RuleVersionCreateInput
rather than spelled out: writing <Record<string, unknown>> here would both
restate a type the input already declares and add a no-unknown warning to
the ratchet.
Parameters
| Parameter | Type |
|---|---|
source | { changeReason: string | null; conditionLogic: JsonValue; createdAt: Date; createdBy: string | null; deletedAt: Date | null; deletedBy: string | null; domainConfig: JsonValue; effectiveEnd: Date | null; effectiveStart: Date; id: string; priority: number; ruleEffectiveDate: Date | null; ruleExpirationDate: Date | null; ruleId: string; scopes: JsonValue; versionNumber: number; } |
source.changeReason | string | null |
source.conditionLogic | JsonValue |
source.createdAt | Date |
source.createdBy | string | null |
source.deletedAt | Date | null |
source.deletedBy | string | null |
source.domainConfig | JsonValue |
source.effectiveEnd | Date | null |
source.effectiveStart | Date |
source.id | string |
source.priority | number |
source.ruleEffectiveDate | Date | null |
source.ruleExpirationDate | Date | null |
source.ruleId | string |
source.scopes | JsonValue |
source.versionNumber | number |
versionNumber | number |
overrides | RuleVersionCopyOverrides |
Returns
Promise<{
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}>
exists()
exists(id: string): Promise<boolean>;Defined in: server/persistence/base-repository.ts:187
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Promise<boolean>
Inherited from
findById()
findById(id: string): Promise<
| {
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}
| null>;Defined in: server/persistence/base-repository.ts:177
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Promise<
| {
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}
| null>
Inherited from
findByIdOrThrow()
findByIdOrThrow(id: string): Promise<{
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}>;Defined in: server/persistence/base-repository.ts:181
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Promise<{
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}>
Inherited from
VersionRepository.findByIdOrThrow
findByParentId()
findByParentId(parentId: string): Promise<{
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}[]>;Defined in: server/persistence/base-repository.ts:233
Parameters
| Parameter | Type |
|---|---|
parentId | string |
Returns
Promise<{
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}[]>
Inherited from
VersionRepository.findByParentId
findByRuleId()
findByRuleId(ruleId: string): Promise<{
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}[]>;Defined in: server/rules/rule-version-repository.ts:117
Parameters
| Parameter | Type |
|---|---|
ruleId | string |
Returns
Promise<{
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}[]>
findLatestByParentId()
findLatestByParentId(parentId: string): Promise<
| {
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}
| null>;Defined in: server/persistence/base-repository.ts:237
Parameters
| Parameter | Type |
|---|---|
parentId | string |
Returns
Promise<
| {
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}
| null>
Inherited from
VersionRepository.findLatestByParentId
findLatestByRuleId()
findLatestByRuleId(ruleId: string): Promise<
| {
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}
| null>;Defined in: server/rules/rule-version-repository.ts:121
Parameters
| Parameter | Type |
|---|---|
ruleId | string |
Returns
Promise<
| {
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}
| null>
findMany()
findMany(pagination: {
page: number;
pageSize: number;
}): Promise<OffsetPaginatedResult<{
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}>>;Defined in: server/persistence/base-repository.ts:195
Parameters
| Parameter | Type |
|---|---|
pagination | { page: number; pageSize: number; } |
pagination.page | number |
pagination.pageSize | number |
Returns
Promise<OffsetPaginatedResult<{
changeReason: string | null;
conditionLogic: JsonValue;
createdAt: Date;
createdBy: string | null;
deletedAt: Date | null;
deletedBy: string | null;
domainConfig: JsonValue;
effectiveEnd: Date | null;
effectiveStart: Date;
id: string;
priority: number;
ruleEffectiveDate: Date | null;
ruleExpirationDate: Date | null;
ruleId: string;
scopes: JsonValue;
versionNumber: number;
}>>
Inherited from
getNextVersionNumber()
getNextVersionNumber(parentId: string): Promise<number>;Defined in: server/persistence/base-repository.ts:256
Next version number = highest versionNumber among the rows
_findByParentId returns, plus one. Subclasses typically filter
_findByParentId to deletedAt: null, so this counts only live rows.
That is collision-safe only while the subclass never soft-deletes
version rows. If a subclass gains a discard/soft-delete path AND its
@@unique(parentId, versionNumber) constraint counts soft-deleted rows
(Postgres unique indexes do), reusing a discarded row's number will
violate the constraint. Such a subclass must override to compute the
max over all rows including soft-deleted — see
FormSchemaVersionRepository.nextVersionNumber. Promote that into a
shared abstract hook here once a second repo needs it.
Parameters
| Parameter | Type |
|---|---|
parentId | string |
Returns
Promise<number>
Inherited from
VersionRepository.getNextVersionNumber
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
| Parameter | Type |
|---|---|
_entityId | string |
_action | string |
_metadata? | Record<string, unknown> |
Returns
Promise<void>
Inherited from
nextVersionNumber()
nextVersionNumber(ruleId: string): Promise<number>;Defined in: server/rules/rule-version-repository.ts:125
Parameters
| Parameter | Type |
|---|---|
ruleId | string |
Returns
Promise<number>
notFoundError()
protected notFoundError(id: string): Error;Defined in: server/rules/rule-version-repository.ts:40
Create a not-found error. Override to provide custom error types.
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Error