import * as _ from 'lodash'; import * as memoize from 'memoizee'; import type { AbstractSqlQuery, AbstractSqlModel, AbstractSqlTable, DurationNode, AbstractSqlType, SelectNode, FromNode, WhereNode, OrderByNode, LimitNode, OffsetNode, NumberTypeNodes, FieldsNode, ValuesNode, ReferencedFieldNode, BooleanTypeNodes, UnionQueryNode, SelectQueryNode, BindNode, TableNode } from '@resin/abstract-sql-compiler'; import type { ODataBinds, ODataQuery, SupportedMethod } from '@balena/odata-parser'; export type { ODataBinds, ODataQuery, SupportedMethod }; export declare type ResourceNode = ['Resource', string]; declare module '@resin/abstract-sql-compiler' { interface AbstractSqlTable { definition?: Definition; } type ExtendedFromTypeNodes = SelectQueryNode | UnionQueryNode | TableNode | ResourceNode | AliasNode; interface FromNode { 1: ExtendedFromTypeNodes; } interface InnerJoinNode { 1: ExtendedFromTypeNodes; 2?: OnNode; } interface LeftJoinNode { 1: ExtendedFromTypeNodes; 2?: OnNode; } interface RightJoinNode { 1: ExtendedFromTypeNodes; 2?: OnNode; } interface FullJoinNode { 1: ExtendedFromTypeNodes; 2?: OnNode; } } export interface Definition { extraBinds: ODataBinds; abstractSqlQuery: SelectQueryNode | UnionQueryNode | ResourceNode | TableNode; } interface Resource extends AbstractSqlTable { tableAlias?: string; definition?: Definition; } export declare type ResourceFunction = (this: OData2AbstractSQL, property: any) => BooleanTypeNodes | { resource: Resource; name: string; }; declare class Query { select: Array; from: Array; where: Array; extras: Array; merge(otherQuery: Query): void; fromResource(odataToAbstractSql: OData2AbstractSQL, resource: Resource, args?: { extraBindVars: ODataBinds; bindVarsLength: number; }, bypassDefinition?: boolean): void; compile(queryType: string): AbstractSqlQuery; } export declare const sqlNameToODataName: ((sqlName: string) => string) & memoize.Memoized<(sqlName: string) => string>; export declare const odataNameToSqlName: ((odataName: string) => string) & memoize.Memoized<(odataName: string) => string>; export declare const rewriteBinds: (definition: NonNullable, existingBinds: ODataBinds, inc?: number) => void; export declare class OData2AbstractSQL { private clientModel; private methods; private extraBodyVars; extraBindVars: ODataBinds; private resourceAliases; defaultResource: Resource | undefined; bindVarsLength: number; private checkAlias; constructor(clientModel: AbstractSqlModel, methods?: _.Dictionary); match(path: ODataQuery, method: SupportedMethod, bodyKeys: string[], bindVarsLength: number): { tree: AbstractSqlQuery; extraBodyVars: _.Dictionary; extraBindVars: ODataBinds; }; PathSegment(method: string, bodyKeys: string[], path: any): Query; PathKey(method: string, path: any, resource: Resource, referencedField: ReferencedFieldNode, bodyKeys: string[]): BooleanTypeNodes | void; Bind(bind: any, _optional?: boolean): AbstractSqlType | undefined; SelectFilter(filter: any, query: Query, resource: Resource): void; OrderBy(orderby: any, query: Query, resource: Resource): void; OrderByProperties(orderings: any[]): Array; BindVars(method: string, bodyKeys: string[], resourceName: string, match: Array<[string, [string, string]]>): Array<[string, 'Default' | BindNode]>; Resource(resourceName: string, parentResource?: Resource): Resource; FieldContainedIn(fieldName: string, resource: Resource): boolean; ResourceMapping(resource: Resource): _.Dictionary<[string, string]>; ResolveRelationship(resource: string | Resource, relationship: string): any; AddCountField(path: any, query: Query): void; AddSelectFields(path: any, query: Query, resource: Resource): void; AliasSelectField(resource: Resource, fieldName: string, computed?: AbstractSqlQuery, alias?: string): (string | AbstractSqlQuery)[]; ReferencedField(resource: Resource, resourceField: string): ReferencedFieldNode; BooleanMatch(match: any, optional: true): BooleanTypeNodes | undefined; BooleanMatch(match: any): BooleanTypeNodes; AliasedFunction(odataName: string, sqlName: string, match: any): AbstractSqlType; FunctionMatch(name: string, match: any): AbstractSqlQuery; Operand(match: any): AbstractSqlType; Math(match: any): AbstractSqlType | undefined; Lambda(resourceName: string, lambda: any): BooleanTypeNodes; ReferencedProperty(match: any): BooleanTypeNodes; Method(prop: unknown & { method: Array; }): BooleanTypeNodes | { resource: Resource; name: string; }; Property(prop: any): BooleanTypeNodes | { resource: Resource; name: string; }; NumberMatch(match: any, optional: true): NumberTypeNodes | undefined; NumberMatch(match: any): NumberTypeNodes; NullMatch(match: any): AbstractSqlType | undefined; TextMatch(match: any, optional: true): AbstractSqlType | undefined; TextMatch(match: any): AbstractSqlType; DateMatch(match: any, optional: true): AbstractSqlType | undefined; DateMatch(match: any): AbstractSqlType; DurationMatch(match: DurationNode[1]): AbstractSqlType | undefined; Expands(resource: Resource, query: Query, expands: any): void; AddQueryOptions(resource: Resource, path: any, query: Query): void; NavigateResources(resource: Resource, navigation: string): { resource: Resource; where: BooleanTypeNodes; }; AddExtraFroms(query: Query, parentResource: Resource, match: any): void; AddNavigation(query: Query, resource: Resource, extraResource: string): Resource; reset(): void; putReset(): void; Synonym(sqlName: string): string; rewriteDefinition(definition: Definition, extraBindVars: ODataBinds, bindVarsLength: number): Definition; }