import { Dict, NNil, Maybe, ReturnType } from "./utils/util-types"; import * as types from "./utils/types"; import * as Knex from "knex"; import { GraphQLInputType, GraphQLOutputType } from "graphql"; import { MappedField } from "./MappedField"; import { MappedAssociation } from "./MappedAssociation"; import { StoreQueryParams } from "./SingleSourceQueryOperationResolver"; import { AliasHierarchyVisitor } from "./AliasHierarchyVisitor"; import { DataSourceMapping } from "./DataSourceMapping"; declare type AssociationsIn = ReturnType>; declare type FieldsIn = ReturnType>; declare type AssociationKeysIn = keyof AssociationsIn; declare type FieldKeysIn = keyof FieldsIn; declare type AssociatedDataSource> = AssociationsIn[K]["target"]; declare type ShallowEntityType = { [K in FieldKeysIn]: FieldsIn[K]["Type"]; }; declare type NestedEntityType = ShallowEntityType & { [K in AssociationKeysIn]: AssociatedDataSource["EntityType"]; }; /** * Represents mapping between a relational data source and associated GraphQL types * originating from the schema of this data source. * * @api-category MapperClass */ export declare class MappedDataSource { private mapping; fields: Dict; associations: Dict; constructor(mapping: T); /** * Knex instance used to connect to data source. * * This can be a data-source specific connector (if provided in the mapping configuration), and if not, * will fall back to global connector. * * Throws if a connector is not found. */ get connector(): Knex; /** * Get a knex query builder for this data source * * This internally aliases tables for ease of reverse-mapping. */ rootQueryBuilder(aliasHierarchyVisitor?: Maybe): Knex.QueryBuilder; /** * Get list of fields representing columns covered by primary key constraint */ get primaryFields(): MappedField[]; get primaryColumnNames(): string[]; /** * Name of the GraphQL output type representing an entity from this data source. Also used in other GraphQL output * types for this data source. */ get mappedName(): string; /** * Name of the GraphQL output type representing a shallow entity (containing only fields and not associations) from this data source. */ get shallowMappedName(): string; /** * Name of the table/view backing this data source */ get storedName(): string; /** * Name of the GraphQL output type representing a page container that wraps page specific metadata along with * entities in the page (in a paginated query) */ get pageContainerName(): string; /** * Name of the GraphQL output type representing a page container that wraps page specific metadata along with * shallow entities in the page (in a paginated query) */ get shallowPageContainerName(): string; /** * Name of the GraphQL output type representing a page that wraps a subset of result entities (in a paginated query) */ get pageName(): string; /** * Name of the GraphQL output type representing a page that wraps a subset of shallow result entities (in a paginated query) */ get shallowPageName(): string; /** * List of names of the columns in the data source which are mapped through the fields in the data source mapping * * It is not necessary that all columns of backing table are covered by fields of the data source. */ get storedColumnNames(): string[]; /** * io-ts type props for field properties of a member entity */ get shallowEntityTypeSpecProps(): Dict; /** * io-ts type props for association properties of a member entity */ get associationTypeSpecProps(): Dict; /** * io-ts type props for all properties (from fields and associations) */ get entityTypeSpecProps(): Dict; /** * io-ts runtime type for shallow member entity (excludes associations) from this data source. */ get shallowEntityTypeSpec(): types.ObjectTypeSpec, types.SourceFromTypeSpecMapping>, any>; /** * io-ts runtime type for member entity from this data source. */ get entityTypeSpec(): types.ObjectTypeSpec, types.SourceFromTypeSpecMapping>, any>; /** * Getter to extract static type of Shallow member entity * * This is only useful in maped types. Throws if invoked directly. */ get ShallowEntityType(): ShallowEntityType; /** * Getter to extract static type of member entity * * This is only useful in maped types. Throws if invoked directly. */ get EntityType(): NestedEntityType; /** * Getter to extract static type of the mapping used to configure the data source * * This is only useful in maped types. Throws if invoked directly. */ get MappingType(): T; /** * Get the default GraphQL output type for a member entity */ get defaultOutputType(): GraphQLOutputType; /** * Get the output type for the response ofa paginated response performed against this data source */ get paginatedOutputType(): import("graphql").GraphQLObjectType; /** * Get the output type for the response of a paginated query (for shallow entities) performed against this data source */ get paginatedShallowOutputType(): import("graphql").GraphQLObjectType; /** * Get the default GraphQL input type for a shallow member entity (excludes associations) */ get defaultShallowInputType(): GraphQLInputType; /** * Get the default GraphQL output type for a shallow member entity (excludes associations) */ get defaultShallowOutputType(): GraphQLOutputType; get defaultIdOutputType(): GraphQLOutputType; /** * Maps member entities (what the application interacts with) to rows (in the format the persistence layer expects) */ mapEntitiesToRows(entities: ShallowEntityType[]): Dict[]; /** * Reverse map the rows obtained from the data source (the persistence layer) to member entities (what the application interacts with) */ mapRowsToEntities(rows: Dict[], storeParams: StoreQueryParams>): Promise; /** * Reverse map the rows obtained from the data source (the persistence layer) to shallow member entities * (what the application interacts with) * * This does not deal with mapping of associations, so is relatively cheaper than mapRowsToEntities */ mapRowsToShallowEntities(rows: Dict[]): Dict[]; /** * Given a query (entity field name -> value mapping), translates it into a query that the persistence * layer can process by mapping entity field names to source column names. */ mapQueryParams(whereArgs: Dict, aliasHierarchyVisitor: AliasHierarchyVisitor): Dict; } /** * Used to map a relational data source using specified configuration (of type [DataSourceMapping](api:DataSourceMapping)). * * Refer the guide on [Mapping Data Sources](guide:mapping-data-sources) for detailed explanation and examples. * * @api-category PrimaryAPI */ export declare const mapDataSource: (mapping: T) => MappedDataSource; export {};