import { ClsService } from "nestjs-cls"; import { JsonApiCursorInterface } from "../../../core/jsonapi/interfaces/jsonapi.cursor.interface"; import { AbstractRepository } from "../../../core/neo4j/abstracts/abstract.repository"; import { Neo4jService } from "../../../core/neo4j/services/neo4j.service"; import { SecurityService } from "../../../core/security/services/security.service"; import { TokenUsage, TokenUsageDescriptor } from "../../tokenusage/entities/tokenusage"; /** * A single row of the date + operation-type usage aggregation. * * Not an entity shape: the aggregation returns grouped scalars, so it * deliberately bypasses the serialiser (`readMany`) — there is nothing to map * onto `TokenUsage`. */ export interface TokenUsageAggregated { date: string; tokenUsageType: string; totalCredits: number; totalInputTokens: number; totalOutputTokens: number; totalCost: number; count: number; } /** * The single-row totals of the usage summary. Same non-entity rationale as * `TokenUsageAggregated`. */ export interface TokenUsageSummary { totalCredits: number; totalInputTokens: number; totalOutputTokens: number; totalCost: number; count: number; } /** * TokenUsage repository. * * Extends `AbstractRepository` so a consuming application can subclass it (see * `ExtendedTokenUsageRepository` in a consuming app) and have BOTH the inherited * generic methods AND every method declared here resolve the *extended* * descriptor. Model resolution is by subclass polymorphism — `this.descriptor` — * never by a registry lookup: Nest constructs providers long before * `onModuleInit`, where models are registered. * * `onModuleInit` DELEGATES to `AbstractRepository.onModuleInit` first, which emits * `CREATE CONSTRAINT tokenusage_id IF NOT EXISTS FOR (tokenusage:TokenUsage) * REQUIRE tokenusage.id IS UNIQUE` from `descriptor.constraints` — byte-identical to * the constraint this repository used to declare by hand — plus the FULLTEXT index * derived from the descriptor's string fields. It then adds the one index the * descriptor cannot express; see the override below. */ export declare class TokenUsageRepository extends AbstractRepository { protected readonly descriptor: import("../../..").EntityDescriptor; constructor(neo4j: Neo4jService, securityService: SecurityService, clsService: ClsService); /** * Adds the range index every date-filtered finder here depends on — * findByCompany, findAggregatedByDateAndType, findUsageSummary, and the * cross-tenant admin queries in TokenUsageAdminRepository. Without it each of * them scans the whole :TokenUsage label, which is the fastest-growing label * in the database. * * There is no declarative way to express a non-FULLTEXT index via * defineEntity(): EntityDescriptor.indexes is hard-coded to the string-field * fulltext index, and AbstractRepository.onModuleInit only acts on * type === "FULLTEXT". Hence the explicit override — same pattern, and same * stated reason, as UserActivityRepository. * * super.onModuleInit() MUST be called first: it creates the descriptor-derived * id constraint and fulltext index. Dropping it would silently remove both. */ onModuleInit(): Promise; /** * Custom create (KEPT — "non-standard relationships" rule): USED_FOR's target is * polymorphic (any entity label — Content, Chunk, Conversation, ...), which the * descriptor's fixed-target `relationships` cannot express as a single * relationship. BELONGS_TO (company) and TRIGGERED_BY (currentUser) rely on the * CLS-injected preamble from `Neo4jService.initQuery()` — unchanged from the * pre-migration repository. Cannot be replaced by the inherited * descriptor-driven `create()`, which only knows fixed relationships declared * on the descriptor. */ create(params: { id: string; tokenUsageType: string; inputTokens: number; outputTokens: number; cachedInputTokens?: number; cost?: number; credits?: number; model?: string; provider?: string; relationshipId: string; relationshipType: string; }): Promise; /** * Custom list (KEPT — date-range + tokenUsageType filtering is not expressible via the * inherited descriptor-driven find()). Reuses buildDefaultMatch()/buildReturnStatement() * for company scoping and security consistency. */ findByCompany(params: { startDate?: string; endDate?: string; tokenUsageType?: string; cursor?: JsonApiCursorInterface; }): Promise; /** * Aggregation query (KEPT — "aggregations" rule): returns grouped totals, not * TokenUsage entities, so it intentionally bypasses readMany()/the serialiser — there * is nothing to map onto the entity type. */ findAggregatedByDateAndType(params: { startDate?: string; endDate?: string; }): Promise; /** * Aggregation query (KEPT — see findAggregatedByDateAndType above), single-row totals. */ findUsageSummary(params: { startDate?: string; endDate?: string; }): Promise; private toNumber; } //# sourceMappingURL=tokenusage.repository.d.ts.map