@algochad/prisma-core
Version:
A comprehensive NestJS library that provides EF-Core-like operations using Prisma and GraphQL. Features LINQ-style query builders, advanced data manipulation, GraphQL integration with genql, and a unified API for both Prisma and GraphQL operations. Includ
141 lines (140 loc) • 13.2 kB
TypeScript
import { IQueryable, IOrderedQueryable, IQueryProvider, IGrouping } from '../efcore/queryable-interfaces';
import { IAsyncEnumerable } from '../linq/interfaces';
import { AsyncEnumerable } from '../linq/async-enumerable';
import { Enumerable } from '../linq/enumerable';
import { List } from '../linq/list';
export interface IGraphQLQueryExpression {
where?: Record<string, any>;
select?: Record<string, any>;
orderBy?: any[];
first?: number;
skip?: number;
distinct?: boolean | string[] | Function[];
inMemoryPredicates?: Array<(item: any) => boolean | Promise<boolean>>;
operationType?: 'query' | 'mutation' | 'subscription';
operationName?: string;
args?: Record<string, any>;
}
export interface IGenQLClient {
query: <T = any>(query: any) => Promise<T>;
mutation?: <T = any>(mutation: any) => Promise<T>;
subscription?: <T = any>(subscription: any) => AsyncIterableIterator<T>;
}
export declare class GraphQLQueryProvider implements IQueryProvider {
private genqlClient;
private operationName;
private operationType;
constructor(genqlClient: IGenQLClient, operationName: string, operationType?: 'query' | 'mutation' | 'subscription');
Execute<TResult>(expression: IGraphQLQueryExpression): Promise<TResult>;
private buildGenqlQuery;
CreateQuery<TModel, TElement, TWhereInput = any, TOrderByInput = any, TInclude = any, TSelectInput = any, TCreateInput = any, TUpdateInput = any, TWhereUniqueInput = any>(expression: IGraphQLQueryExpression): IQueryable<TModel, TElement, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
}
export declare class GraphQLQueryable<TModel = unknown, TSelect = TModel, TWhereInput = any, TOrderByInput = any, TInclude = any, TSelectInput = any, TCreateInput = any, TUpdateInput = any, TWhereUniqueInput = any> implements IQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput> {
protected provider: GraphQLQueryProvider;
protected expression: IGraphQLQueryExpression;
protected elementType: any;
constructor(provider: GraphQLQueryProvider, expression?: IGraphQLQueryExpression, elementType?: any);
get Provider(): IQueryProvider;
get Expression(): any;
get ElementType(): any;
private createNew;
WhereFilter(where: TWhereInput): IQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
SelectFields<TSelectFields extends TSelectInput>(select: TSelectFields): IQueryable<TModel, TSelectFields, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Include(include: TInclude): IQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
OrderBy(orderBy: TOrderByInput): IOrderedQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
SelectMany<TResult>(selector: (item: TSelect) => IQueryable<any, TResult> | IAsyncEnumerable<TResult>): IQueryable<TModel, TResult, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
GroupBy<TKey, TElement = TSelect, TResult = IGrouping<TKey, TElement>>(keySelector: (item: TSelect) => TKey, elementSelector?: (item: TSelect) => TElement, resultSelector?: (key: TKey, group: IQueryable<TModel, TElement>) => TResult): IQueryable<TModel, TResult, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Join<TInner, TKey, TResult>(inner: IQueryable<any, TInner>, outerKeySelector: (outer: TSelect) => TKey, innerKeySelector: (inner: TInner) => TKey, resultSelector: (outer: TSelect, inner: TInner) => TResult): IQueryable<TModel, TResult, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Union(other: IQueryable<TModel, TSelect>): IQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Intersect(other: IQueryable<TModel, TSelect>): IQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Except(other: IQueryable<TModel, TSelect>): IQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Take(count: number): IQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Skip(count: number): IQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Distinct<TKey>(keySelector?: (item: TSelect) => TKey): IQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Where: (where: TWhereInput) => IQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Select: <TSelectFields extends TSelectInput>(select: TSelectFields) => IQueryable<TModel, TSelectFields, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
ExecuteAsync(): Promise<TSelect[]>;
ToArrayAsync(): Promise<TSelect[]>;
ToListAsync(): Promise<List<TSelect>>;
FirstAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect>;
FirstOrDefaultAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect | undefined>;
LastAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect>;
LastOrDefaultAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect | undefined>;
SingleAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect>;
SingleOrDefaultAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect | undefined>;
CountAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<number>;
AnyAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<boolean>;
AllAsync(predicate: (item: TSelect) => boolean | Promise<boolean>): Promise<boolean>;
MinAsync(): Promise<TSelect>;
MinAsync<TResult>(selector: (item: TSelect) => TResult): Promise<TResult>;
MaxAsync(): Promise<TSelect>;
MaxAsync<TResult>(selector: (item: TSelect) => TResult): Promise<TResult>;
SumAsync(selector?: (item: TSelect) => number): Promise<number>;
AverageAsync(selector?: (item: TSelect) => number): Promise<number>;
LongCountAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<number>;
AggregateAsync<TAccumulate>(seed: TAccumulate, func: (accumulate: TAccumulate, item: TSelect) => Promise<TAccumulate> | TAccumulate): Promise<TAccumulate>;
ContainsAsync(item: TSelect): Promise<boolean>;
ForEachAsync(action: (item: TSelect) => void | Promise<void>): Promise<void>;
ToEnumerable(): Promise<Enumerable<TSelect>>;
AsEnumerable(): Promise<Enumerable<TSelect>>;
AsAsyncEnumerable(): Promise<AsyncEnumerable<TSelect>>;
ToEnumerableAsync(): Promise<Enumerable<TSelect>>;
ToAsyncEnumerable(): Promise<AsyncEnumerable<TSelect>>;
}
export declare class GraphQLOrderedQueryable<TModel = unknown, TSelect = TModel, TWhereInput = any, TOrderByInput = any, TInclude = any, TSelectInput = any, TCreateInput = any, TUpdateInput = any, TWhereUniqueInput = any> extends GraphQLQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput> implements IOrderedQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput> {
Take(count: number): IOrderedQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Skip(count: number): IOrderedQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
Distinct<TKey>(keySelector?: (item: TSelect) => TKey): IOrderedQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
ThenBy(orderBy: TOrderByInput): IOrderedQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
ThenByDescending(orderBy: TOrderByInput): IOrderedQueryable<TModel, TSelect, TWhereInput, TOrderByInput, TInclude, TSelectInput, TCreateInput, TUpdateInput, TWhereUniqueInput>;
}
export declare class InMemoryGraphQLQueryable<TModel = unknown, TSelect = TModel> implements IQueryable<TModel, TSelect, any, any, any, any, any, any, any> {
private data;
constructor(data: TSelect[] | Promise<TSelect[]>);
get Provider(): IQueryProvider;
get Expression(): any;
get ElementType(): any;
WhereFilter(where: any): IQueryable<TModel, TSelect, any, any, any, any, any, any, any>;
SelectFields<TSelectFields>(select: TSelectFields): IQueryable<TModel, TSelectFields, any, any, any, any, any, any, any>;
Include(include: any): IQueryable<TModel, TSelect, any, any, any, any, any, any, any>;
OrderBy(orderBy: any): IOrderedQueryable<TModel, TSelect, any, any, any, any, any, any, any>;
SelectMany<TResult>(selector: (item: TSelect) => IQueryable<any, TResult> | IAsyncEnumerable<TResult>): IQueryable<TModel, TResult, any, any, any, any, any, any, any>;
GroupBy<TKey, TElement = TSelect, TResult = IGrouping<TKey, TElement>>(keySelector: (item: TSelect) => TKey, elementSelector?: (item: TSelect) => TElement, resultSelector?: (key: TKey, group: IQueryable<TModel, TElement>) => TResult): IQueryable<TModel, TResult, any, any, any, any, any, any, any>;
Join<TInner, TKey, TResult>(inner: IQueryable<any, TInner>, outerKeySelector: (outer: TSelect) => TKey, innerKeySelector: (inner: TInner) => TKey, resultSelector: (outer: TSelect, inner: TInner) => TResult): IQueryable<TModel, TResult, any, any, any, any, any, any, any>;
Take(count: number): IQueryable<TModel, TSelect, any, any, any, any, any, any, any>;
Skip(count: number): IQueryable<TModel, TSelect, any, any, any, any, any, any, any>;
Distinct<TKey>(keySelector?: (item: TSelect) => TKey): IQueryable<TModel, TSelect, any, any, any, any, any, any, any>;
Union(other: IQueryable<TModel, TSelect>): IQueryable<TModel, TSelect, any, any, any, any, any, any, any>;
Intersect(other: IQueryable<TModel, TSelect>): IQueryable<TModel, TSelect, any, any, any, any, any, any, any>;
Except(other: IQueryable<TModel, TSelect>): IQueryable<TModel, TSelect, any, any, any, any, any, any, any>;
Where: (where: any) => IQueryable<TModel, TSelect, any, any, any, any, any, any, any>;
Select: <TSelectFields>(select: TSelectFields) => IQueryable<TModel, TSelectFields, any, any, any, any, any, any, any>;
ToArrayAsync(): Promise<TSelect[]>;
ToListAsync(): Promise<List<TSelect>>;
FirstAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect>;
FirstOrDefaultAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect | undefined>;
LastAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect>;
LastOrDefaultAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect | undefined>;
SingleAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect>;
SingleOrDefaultAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<TSelect | undefined>;
CountAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<number>;
AnyAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<boolean>;
AllAsync(predicate: (item: TSelect) => boolean | Promise<boolean>): Promise<boolean>;
MinAsync(): Promise<TSelect>;
MinAsync<TResult>(selector: (item: TSelect) => TResult): Promise<TResult>;
MaxAsync(): Promise<TSelect>;
MaxAsync<TResult>(selector: (item: TSelect) => TResult): Promise<TResult>;
SumAsync(selector?: (item: TSelect) => number): Promise<number>;
AverageAsync(selector?: (item: TSelect) => number): Promise<number>;
AggregateAsync<TAccumulate>(seed: TAccumulate, func: (accumulate: TAccumulate, item: TSelect) => Promise<TAccumulate> | TAccumulate): Promise<TAccumulate>;
ContainsAsync(item: TSelect): Promise<boolean>;
ToEnumerable(): Promise<Enumerable<TSelect>>;
AsEnumerable(): Promise<Enumerable<TSelect>>;
AsAsyncEnumerable(): Promise<AsyncEnumerable<TSelect>>;
ToEnumerableAsync(): Promise<Enumerable<TSelect>>;
ToAsyncEnumerable(): Promise<AsyncEnumerable<TSelect>>;
ExecuteAsync(): Promise<TSelect[]>;
LongCountAsync(predicate?: (item: TSelect) => boolean | Promise<boolean>): Promise<number>;
ForEachAsync(action: (item: TSelect) => void | Promise<void>): Promise<void>;
private resolveData;
}