import { RxReplicationWriteToMasterRow } from 'nxdb-old/src/types/replication-protocol'; import { ById, MaybePromise } from 'nxdb-old/src/types/util'; import { ReplicationOptions, ReplicationPullHandlerResult, ReplicationPullOptions, ReplicationPushHandlerResult, ReplicationPushOptions } from 'nxdb-old/src/types/plugins/replication'; export interface RxGraphQLReplicationQueryBuilderResponseObject { query: string; variables: any; } export type RxGraphQLReplicationClientState = { headers: ById; credentials: RequestCredentials | undefined; }; export type RxGraphQLReplicationQueryBuilderResponse = RxGraphQLReplicationQueryBuilderResponseObject | Promise; export type RxGraphQLReplicationPushQueryBuilder = ( // typed 'any' because the data might be modified by the push.modifier. rows: RxReplicationWriteToMasterRow[] ) => RxGraphQLReplicationQueryBuilderResponse; export type RxGraphQLReplicationPullQueryBuilder = ( latestPulledCheckpoint: CheckpointType | null, limit: number ) => RxGraphQLReplicationQueryBuilderResponse; export type GraphQLSyncPullOptions = Omit< ReplicationPullOptions, 'handler' | 'stream$' > & { queryBuilder: RxGraphQLReplicationPullQueryBuilder; streamQueryBuilder?: RxGraphQLReplicationPullStreamQueryBuilder; dataPath?: string; responseModifier?: RxGraphQLPullResponseModifier; includeWsHeaders?: boolean; }; export type RxGraphQLPullResponseModifier = ( // the exact response that was returned from the server plainResponse: ReplicationPullHandlerResult | any, // either 'handler' if it came from the pull.handler, or 'stream' if it came from the pull.stream origin: 'handler' | 'stream', requestCheckpoint?: CheckpointType ) => MaybePromise>; export type RxGraphQLPushResponseModifier = ( // the exact response that was returned from the server plainResponse: ReplicationPushHandlerResult | any, ) => MaybePromise>; export type RxGraphQLReplicationPullStreamQueryBuilder = (headers: { [k: string]: string; }) => RxGraphQLReplicationQueryBuilderResponse; export type GraphQLSyncPushOptions = Omit< ReplicationPushOptions, 'handler' > & { queryBuilder: RxGraphQLReplicationPushQueryBuilder; dataPath?: string; responseModifier?: RxGraphQLPushResponseModifier; }; export type GraphQLServerUrl = { http?: string; ws?: string; }; export type SyncOptionsGraphQL = Omit< ReplicationOptions, 'pull' | 'push' | 'replicationIdentifier' > & { url: GraphQLServerUrl; headers?: { [k: string]: string; }; // send with all requests to the endpoint credentials?: RequestCredentials; pull?: GraphQLSyncPullOptions; push?: GraphQLSyncPushOptions; };