import { type IContainer, type IWithContainer } from "../container"; import {type UndefinableOptional} from "../interface"; import {type IPromiseMapper} from "../mapper"; import {type IMutationSource} from "./IMutationSource"; import {type IWithIdentity} from "./interface"; import {type IQuery} from "./IQuery"; import {type IQuerySource} from "./IQuerySource"; import {type IResolveSource} from "./IResolveSource"; export interface ISource< TContainer extends IContainer, TEntity extends Record, TItem extends Record, TQuery extends IQuery = IQuery, TCreate extends Record = any, > extends IWithContainer, IMutationSource, IQuerySource, IResolveSource { /** * Name of the source. */ readonly name: string; readonly mapper: { toItem: IPromiseMapper; }; /** * Generates hash string for the given query; it's useful for generating cache key for example. */ hashOf(query: TQuery, type?: string): string; /** * Clear cache, if any. */ clearCache(): Promise; } export namespace InferSource { export type Container = T extends ISource ? U : T; export type Entity = T extends ISource ? U : T; export type Item = T extends ISource ? U : T; export type Query = T extends ISource ? U : T; export type Create = T extends ISource ? U : T; export type Patch = T extends ISource ? UndefinableOptional & IWithIdentity : T; }