import ClickHouse from '@posthog/clickhouse'; import { CacheOptions, Properties } from '@posthog/plugin-scaffold'; import { Pool as GenericPool } from 'generic-pool'; import { StatsD } from 'hot-shots'; import Redis from 'ioredis'; import { ProducerRecord } from 'kafkajs'; import { DateTime } from 'luxon'; import { Pool, PoolClient, QueryConfig, QueryResult, QueryResultRow } from 'pg'; import { Action, ActionEventPair, ClickHouseEvent, ClickhouseGroup, ClickHousePerson, ClickHousePersonDistinctId, Cohort, CohortPeople, Database, DeadLetterQueueEvent, Element, Event, EventDefinitionType, GroupTypeToColumnIndex, Hook, Person, PersonDistinctId, PluginConfig, PluginLogEntry, PluginLogEntrySource, PluginLogEntryType, PostgresSessionRecordingEvent, PropertyDefinitionType, RawOrganization, SessionRecordingEvent, Team, TeamId } from '../../types'; import { UUID, UUIDT } from '../utils'; import { KafkaProducerWrapper } from './kafka-producer-wrapper'; import { PostgresLogsWrapper } from './postgres-logs-wrapper'; export interface LogEntryPayload { pluginConfig: PluginConfig; source: PluginLogEntrySource; type: PluginLogEntryType; message: string; instanceId: UUID; timestamp?: string | null; } export interface ParsedLogEntry { id: string; team_id: number; plugin_id: number; plugin_config_id: number; timestamp: string; source: PluginLogEntrySource; type: PluginLogEntryType; message: string; instance_id: string; } export interface CreateUserPayload { uuid: UUIDT; password: string; first_name: string; last_name: string; email: string; distinct_id: string; is_staff: boolean; is_active: boolean; date_joined: Date; events_column_config: Record | null; organization_id?: RawOrganization['id']; } export interface CreatePersonalApiKeyPayload { id: string; user_id: number; label: string; value: string; created_at: Date; } export declare class DB { postgres: Pool; redisPool: GenericPool; kafkaProducer?: KafkaProducerWrapper; clickhouse?: ClickHouse; statsd: StatsD | undefined; postgresLogsWrapper: PostgresLogsWrapper; MAX_GROUP_TYPES_PER_TEAM: number; constructor(postgres: Pool, redisPool: GenericPool, kafkaProducer: KafkaProducerWrapper | undefined, clickhouse: ClickHouse | undefined, statsd: StatsD | undefined); postgresQuery(queryTextOrConfig: string | QueryConfig, values: I | undefined, tag: string): Promise>; postgresTransaction(transaction: (client: PoolClient) => Promise): Promise; clickhouseQuery(query: string, options?: ClickHouse.QueryOptions): Promise>>; redisGet(key: string, defaultValue: unknown, options?: CacheOptions): Promise; redisSet(key: string, value: unknown, ttlSeconds?: number, options?: CacheOptions): Promise; redisIncr(key: string): Promise; redisExpire(key: string, ttlSeconds: number): Promise; redisLPush(key: string, value: unknown, options?: CacheOptions): Promise; redisLRange(key: string, startIndex: number, endIndex: number): Promise; redisLLen(key: string): Promise; redisBRPop(key1: string, key2: string): Promise<[string, string]>; redisLRem(key: string, count: number, elementKey: string): Promise; redisLPop(key: string, count: number): Promise; fetchPersons(database?: Database.Postgres): Promise; fetchPersons(database: Database.ClickHouse): Promise; fetchPerson(teamId: number, distinctId: string, client?: PoolClient, forUpdate?: boolean): Promise; createPerson(createdAt: DateTime, properties: Properties, propertiesOnce: Properties, teamId: number, isUserId: number | null, isIdentified: boolean, uuid: string, distinctIds?: string[]): Promise; updatePerson(person: Person, update: Partial, client: PoolClient): Promise; updatePerson(person: Person, update: Partial): Promise; private getPropertyLastUpdatedAtDateTimeOrEpoch; private getPropertiesLastOperationOrSet; private updatePropertiesLastOperation; private updatePersonPropertiesLocal; updatePersonProperties(teamId: number, distinctId: string, properties: Properties, propertiesOnce: Properties, timestamp: DateTime): Promise; deletePerson(person: Person, client: PoolClient): Promise; fetchDistinctIds(person: Person, database?: Database.Postgres): Promise; fetchDistinctIds(person: Person, database: Database.ClickHouse): Promise; fetchDistinctIdValues(person: Person, database?: Database): Promise; addDistinctId(person: Person, distinctId: string): Promise; addDistinctIdPooled(client: PoolClient | Pool, person: Person, distinctId: string): Promise; moveDistinctIds(source: Person, target: Person): Promise; createCohort(cohort: Partial): Promise; doesPersonBelongToCohort(cohortId: number, person: Person, teamId: Team['id']): Promise; addPersonToCohort(cohortId: number, personId: Person['id']): Promise; fetchEvents(): Promise; fetchDeadLetterQueueEvents(): Promise; fetchSessionRecordingEvents(): Promise; fetchElements(event?: Event): Promise; createElementGroup(elements: Element[], teamId: number): Promise; fetchPluginLogEntries(): Promise; queuePluginLogEntry(entry: LogEntryPayload): Promise; batchInsertPostgresLogs(entries: ParsedLogEntry[]): Promise; fetchEventDefinitions(): Promise; fetchPropertyDefinitions(): Promise; fetchAllActionsGroupedByTeam(): Promise>>; fetchAction(id: Action['id']): Promise; fetchActionMatches(): Promise; registerActionMatch(eventId: Event['id'], actions: Action[]): Promise; fetchOrganization(organizationId: string): Promise; fetchTeam(teamId: Team['id']): Promise; fetchInternalMetricsTeam(): Promise; fetchRelevantRestHooks(teamId: Hook['team_id'], event: Hook['event'], resourceId: Hook['resource_id']): Promise; deleteRestHook(hookId: Hook['id']): Promise; createUser({ uuid, password, first_name, last_name, email, distinct_id, is_staff, is_active, date_joined, events_column_config, organization_id, }: CreateUserPayload): Promise; createPersonalApiKey({ id, user_id, label, value, created_at, }: CreatePersonalApiKeyPayload): Promise; fetchGroupTypes(teamId: TeamId): Promise; insertGroupType(teamId: TeamId, groupType: string, index: number): Promise<[number | null, boolean]>; upsertGroup(teamId: TeamId, groupTypeIndex: number, groupKey: string, properties: Properties): Promise; fetchGroups(): Promise; }