import type { DBHandlerServer, DboBuilder, PRGLIOSocket } from "../DboBuilder/DboBuilder"; import type { PostgresNotifListenManager } from "../PostgresNotifListenManager"; import type { DB } from "../Prostgles"; import { type AddTriggerParams } from "./addTrigger"; import type { AnyObject, FieldFilter, SelectParams, SyncTableInfo, TableSchema, WAL } from "prostgles-types"; import { type SubscribeOptions } from "prostgles-types"; import type { OnData } from "../DboBuilder/ViewHandler/subscribe"; import type { EventTypes } from "../Logging"; import type { ParsedTableRule } from "../PublishParser/PublishParser"; export type BasicCallback = (err?: any, res?: any) => void; export type SyncParams = { socket_id: string; sid: string | undefined; channel_name: string; table_name: string; table_rules?: ParsedTableRule; synced_field: string; id_fields: string[]; batch_size: number; filter: object; params: { select: FieldFilter; }; condition: string; wal?: WAL; throttle?: number; lr?: AnyObject; last_synced: number; is_syncing: boolean; }; export type AddSyncParams = SyncTableInfo & { socket: PRGLIOSocket; table_info: TableSchema; table_rules: ParsedTableRule; allow_delete?: boolean; filter: object; params: { select: FieldFilter; }; condition: string; throttle?: number; }; export type ViewSubscriptionOptions = ({ type: "view"; viewName: string; definition: string; } | { type: "table"; viewName?: undefined; definition?: undefined; }) & { relatedTables: (Pick & { tableName: string; tableNameEscaped: string; })[]; }; export type SubscriptionParams = { socket_id?: string; channel_name: string; /** * If this is a view then all related tables will be added triggers * */ viewOptions?: ViewSubscriptionOptions; parentSubParams: Omit | undefined; table_info: TableSchema; table_rules?: ParsedTableRule; filter: object; selectParams: SelectParams; subscribeOptions: SubscribeOptions; onData?: OnData; socket: PRGLIOSocket | undefined; lastPushed: number; /** * Prevent out of order pushes */ pushRequestedVersion: number; isPushing?: boolean; reRun?: boolean; is_throttling?: any; is_ready?: boolean; }; export type Subscription = Pick & { triggers: [AddTriggerParams, ...AddTriggerParams[]]; }; export type TableTriggerInfo = { table_condition_id: number; condition: string; hash: string; columnInfo: { join_condition: string; tracked_columns: Record; } | null; }; export type PubSubManagerTriggers = Map>; /** * Used to facilitate table subscribe and sync */ export declare class PubSubManager { static create: (dboBuilder: DboBuilder) => Promise; appInfoWasInserted: boolean; get appId(): `${string}-${string}-${string}-${string}-${string}`; get db(): DB; get dbo(): DBHandlerServer; dboBuilder: DboBuilder; /** * Triggers used for sync/sub that reflect prostgles.app_triggers. * Updated through refreshTriggers() */ _triggers: PubSubManagerTriggers; sockets: Record; subs: Subscription[]; syncs: SyncParams[]; readonly socketChannelPreffix: string; postgresNotifListenManager?: PostgresNotifListenManager; private constructor(); appCheckFrequencyMS: number; appCheck?: ReturnType; destroyed: boolean; destroy: () => Promise; getIsDestroyed: () => boolean; appChecking: boolean; checkedListenerTableCond?: string[]; initialiseEventTriggers: () => Promise; getClientSubs({ channel_name, onData, socket_id, }: Pick): Subscription[]; getTriggerSubs(table_name: string, condition: string): Subscription[]; removeSubscription: (channelName: string, subInfo: { type: "local"; onData: OnData; } | { type: "ws"; socket: PRGLIOSocket; }) => void; getSyncs(table_name: string, condition: string): SyncParams[]; notifListener: (data: { payload: string; }) => Promise; getTriggerInfo: (tableName: string) => { subs: Subscription[]; syncs: SyncParams[]; table_condition_id: number; condition: string; hash: string; columnInfo: { join_condition: string; tracked_columns: Record; } | null; }[] | undefined; getActiveTriggers: (tableName: string) => { subs: Subscription[]; syncs: SyncParams[]; table_condition_id: number; condition: string; hash: string; columnInfo: { join_condition: string; tracked_columns: Record; } | null; }[]; getAllActiveTriggers: () => { tableName: string; subs: Subscription[]; syncs: SyncParams[]; table_condition_id: number; condition: string; hash: string; columnInfo: { join_condition: string; tracked_columns: Record; } | null; }[]; getSubData: (sub: Subscription) => Promise<{ data: AnyObject[]; err?: undefined; } | { err: string | any[] | AnyObject; data?: undefined; }>; pushSubData: (sub: Subscription, err?: any) => Promise; upsertSocket(socket: PRGLIOSocket | undefined): void; get connectedSocketIds(): string[]; _log: (params: EventTypes.Sync | EventTypes.SyncOrSub) => void | Promise | undefined; syncTimeout?: ReturnType; syncData: (sync: SyncParams, clientData: import("../SyncReplication").ClientExpressData | undefined, source: "client" | "trigger") => Promise; addSync: (syncParams: AddSyncParams) => Promise<{ channelName: string; }>; addSub: (subscriptionParams: Omit) => Promise; getActiveListeners: () => { table_name: string; condition: string; }[]; /** * Sync triggers with database * */ refreshTriggers: () => Promise; /** Throttle trigger deletes */ deletingOrphanedTriggers: { tableNames: Set; timeout: NodeJS.Timeout; } | undefined; deleteOrphanedTriggers: (latestTableNames: Set) => void; addingTrigger: any; addTriggerPool?: Record; addTrigger: (params: AddTriggerParams, viewOptions: ViewSubscriptionOptions | undefined, socket: PRGLIOSocket | undefined) => Promise; } | null; }>>; } //# sourceMappingURL=PubSubManager.d.ts.map