import * as gql from 'graphql'; import { Dictionary } from 'ts-essentials'; import { FarosClient } from '../client'; import { PathToModel, Query, Reference } from './types'; export type AnyRecord = Record; export type RecordIterable = AsyncOrSyncIterable; type AsyncOrSyncIterable = AsyncIterable | Iterable; export interface PaginatedQuery { readonly query: string; readonly modelName: string; readonly keysetFields?: string[]; } export interface FlattenContext { readonly fieldTypes: Map; readonly params: Map; readonly currentPath: string; readonly leafPaths: ReadonlyArray; readonly leafToDefault: Map; readonly depth: number; readonly listPaths?: ReadonlyArray; } export declare const NODES = "nodes"; export declare const EDGES = "edges"; export declare const REFRESHED_AT = "refreshedAt"; export declare function isObjectListType(type: any): type is gql.GraphQLList; export declare function isModelQuery(parentType: any, type: any): type is gql.GraphQLObjectType; export type QueryPaginator = (query: string) => PaginatedQuery; export declare function paginatedQueryV2(query: string): PaginatedQuery; /** * Paginate queries with where clause and order by on id * https://hasura.io/docs/latest/queries/postgres/pagination/#keyset-cursor-based-pagination */ export declare function paginateWithKeysetV1(query: string): PaginatedQuery; /** * Paginate queries using timestamp and id fields * https://hasura.io/docs/latest/queries/postgres/pagination/#keyset-cursor-based-pagination */ export declare function paginateWithKeysetV2(query: string): PaginatedQuery; export declare function paginateWithOffsetLimit(query: string): PaginatedQuery; /** Flattens nested nodes returned from a V2 query */ export declare function flattenV2(query: string, schema: gql.GraphQLSchema): FlattenContext; /** * Returns an iterable that cross-joins an array of object iterables * and merges each output object array into a single object */ export declare function crossMerge(iters: (AsyncIterable | Iterable)[]): AsyncIterable; /** Flattens an iterable of nested node objects */ export declare function flattenIterable(ctx: FlattenContext, nodes: RecordIterable): AsyncIterable; export interface Reader { execute(args: Map): AsyncIterable; metadata: { name: string; readonly fields: Map; readonly params: Map; readonly modelKeys?: ReadonlyArray; readonly incremental: boolean; }; } interface ReaderFromQueryConfig { readonly client: FarosClient; readonly graph: string; readonly graphSchema: gql.GraphQLSchema; readonly query: Query; readonly pageSize: number; readonly incremental?: boolean; readonly paginator?: QueryPaginator; } export declare function readerFromQuery(cfg: ReaderFromQueryConfig): Reader; interface NonIncrementalReadersConfig { readonly client: FarosClient; readonly graph: string; readonly graphSchema: gql.GraphQLSchema; readonly queries: ReadonlyArray; readonly pageSize: number; readonly paginator?: QueryPaginator; } export declare function createNonIncrementalReaders(cfg: NonIncrementalReadersConfig): ReadonlyArray; export declare function getGraphModels(graphSchema: gql.GraphQLSchema): string[]; interface IncrementalQueryConfig { readonly type: gql.GraphQLObjectType; readonly resolvedPrimaryKeys?: Dictionary; readonly references?: Dictionary; readonly avoidCollisions?: boolean; readonly scalarsOnly?: boolean; } /** * Creates an incremental query from a model type. * The selections will include: * 1. All the scalar fields. * 2. Nested fragments for all referenced models, selecting their IDs. * * By default, it aliases referenced models IDs to prevent collisions * if flattened. * E.g., { id pipeline { id } } => { id pipeline { pipelineId: id } } * The avoidCollisions parameter controls this behavior. * * If resolvedPrimaryKeys is provided, it will use the fully resolved * primary key fragment for referenced models instead of the ID field. */ export declare function buildIncrementalQueryV2(cfg: IncrementalQueryConfig): Query; interface IncrementalReadersConfig { readonly client: FarosClient; readonly graph: string; readonly pageSize: number; readonly graphSchema: gql.GraphQLSchema; readonly avoidCollisions?: boolean; readonly scalarsOnly?: boolean; } export declare function createIncrementalReadersV2(cfg: IncrementalReadersConfig): ReadonlyArray; export interface IncrementalReaderConfig { readonly model: string; readonly client: FarosClient; readonly graph: string; readonly graphSchema: gql.GraphQLSchema; readonly pageSize: number; readonly paginator?: QueryPaginator; readonly avoidCollisions: boolean; readonly scalarsOnly: boolean; } export declare function createIncrementalReader(cfg: IncrementalReaderConfig): Reader | undefined; export interface DataReaderConfig { readonly model: string; readonly client: FarosClient; readonly graph: string; readonly graphSchema: gql.GraphQLSchema; readonly pageSize: number; readonly paginator?: QueryPaginator; } export declare function createDataReader(cfg: DataReaderConfig): Reader | undefined; export interface DeleteReaderConfig { readonly model: string; readonly client: FarosClient; readonly graph: string; readonly graphSchema: gql.GraphQLSchema; readonly pageSize: number; readonly paginator?: QueryPaginator; } export declare function createDeleteReader(cfg: DeleteReaderConfig): Reader | undefined; interface IncrementalQueriesConfig { readonly graphSchema: gql.GraphQLSchema; readonly primaryKeys?: Dictionary>; readonly references?: Dictionary>; readonly avoidCollisions?: boolean; readonly scalarsOnly?: boolean; } export declare function createIncrementalQueriesV2(cfg: IncrementalQueriesConfig): ReadonlyArray; /** * Converts a V2 query into incremental: * Adds "from" and "to" query variables. * Adds a filter "from" <= refreshedAt < "to" to the top level model. * Makes sure refreshedAt is selected. * * Example: * vcs_PullRequest { * title * } * * becomes: * query incrementalQuery($from: timestamptz!, $to: timestamptz!) { * vcs_PullRequest(where: {refreshedAt: {_gte: $from, _lt: $to}}) { * title * refreshedAt * } * } */ export declare function toIncrementalV2(query: string): string; /** * Returns the path to the queried top-level model in a V2 query * * Example, for query: * vcs_PullRequest { * title * } * * returns: * { * modelName: 'vcs_PullRequest', * path: ['vcs_PullRequest'], * } */ export declare function pathToModelV2(query: string, schema: gql.GraphQLSchema): PathToModel; export {};