import type { PickDeferred, Expanded, Resource } from '@balena/abstract-sql-to-typescript' with { 'resolution-mode': 'import' }; export type { Resource }; type ResourceName = `${Letter | Digit}${string}`; export type AnyResourceObject = { [key: ResourceName]: any; }; export type AnyResource = { Read: AnyObject; Write: AnyObject; }; type StringKeyOf = keyof T & string; export type ExpandableStringKeyOf = StringKeyOf>; type ExtractExpand = NonNullable>[number]>; type SelectPropsOf> = U['$select'] extends ReadonlyArray> | ReadonlySet> ? X : U['$select'] extends StringKeyOf ? U['$select'] : Exclude, ExpandPropsOf>; type ExpandPropsOf> = U['$expand'] extends { [key in StringKeyOf]?: any; } ? StringKeyOf : U['$expand'] extends ReadonlyArray> ? X : never; type ExpandToResponse> = U['$expand'] extends { [key in infer X extends StringKeyOf]?: any; } ? { [P in X]-?: OptionsToResponse[number], U['$expand'][P], undefined>; } : U['$expand'] extends ReadonlyArray> ? { [P in X]-?: Array[number]>>; } : {}; type MaybeGetKey = K extends keyof T ? T[K] : undefined; type Equals = (() => T extends X ? 1 : 2) extends () => T extends Y ? 1 : 2 ? true : false; export type OptionsToResponse, ID extends ResourceId | undefined> = U extends { $count: ODataOptions['$count']; } ? number : Equals extends true ? (PickDeferred> & ExpandToResponse) | undefined : ID extends ResourceId ? (PickDeferred> & ExpandToResponse) | undefined : Array> & ExpandToResponse>; export interface Dictionary { [index: string]: T; } type LowerLetter = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z'; type UpperLetter = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z'; type Letter = LowerLetter | UpperLetter; type Digit = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9; /** * It is expected that errors thrown by `_request` will be instances of this class/a subclass of it. */ export declare class StatusError extends Error { statusCode: number; constructor(message: string, statusCode: number); } interface PollOnObj { unsubscribe: () => void; } declare class Poll { private intervalTime; private subscribers; private stopped; private pollInterval?; private requestFn; constructor(requestFn: () => Promise, intervalTime?: number); setPollInterval(intervalTime: number): void; runRequest(): Promise; on(name: 'data', fn: (response: T) => void): PollOnObj; on(name: 'error', fn: (err: any) => void): PollOnObj; start(): void; stop(): void; destroy(): void; private restartTimeout; } declare const validParams: readonly ["apiPrefix", "passthrough", "passthroughByMethod", "retry"]; export type PreparedFn, U, TResource extends Resource = AnyResource> = (parameterAliases?: T, body?: Params['body'], passthrough?: Params['passthrough']) => U; export type RetryParametersObj = { canRetry?: (err: any) => boolean; onRetry?: (prevErr: any, delayMs: number, attempt: number, maxAttempts: number) => void; getRetryAfterHeader?: (err: unknown) => string | undefined; minDelayMs?: number; maxDelayMs?: number; maxAttempts?: number; }; export type RetryParameters = RetryParametersObj | false; export declare abstract class PinejsClientCore { apiPrefix: string; passthrough: AnyObject; passthroughByMethod: AnyObject; backendParams?: AnyObject; retry: RetryParameters; constructor(params: string | ConstructorParams); private canRetryDefaultHandler; protected callWithRetry(fnCall: () => Promise, retry?: RetryParameters): Promise; clone(params: string | ConstructorParams, backendParams?: AnyObject): this; get, TParams extends Params & { resource: TResource; }>(params: { resource: TResource; } & TParams): Promise, MaybeGetKey>>>; protected transformGetResult, TParams extends Params & { resource: TResource; }>(params: TParams, data: AnyObject): NoInfer, MaybeGetKey>>; protected transformGetResult(params: Params & { options: { $count: NonNullable['$count']>; }; }, data: AnyObject): number; protected transformGetResult(params: Params & { id: NonNullable['id']>; }, data: AnyObject): AnyObject | undefined; protected transformGetResult(params: Omit, 'id'>, data: AnyObject): AnyObject[]; subscribe, TParams extends SubscribeParams & { resource: TResource; }>(params: TParams & { resource: TResource; }): Poll, MaybeGetKey>>>; put>(params: { resource: TResource; } & Params): Promise; patch>(params: { resource: TResource; } & Params): Promise; post>(params: { resource: TResource; } & ActionParams & Omit, 'method' | 'url' | 'body'>): Promise; post>(params: { resource: TResource; } & Params): Promise>; delete>(params: { resource: TResource; } & Params): Promise; getOrCreate, TParams extends GetOrCreateParams & { resource: TResource; }>(params: { resource: TResource; } & TParams): Promise, TParams['id']>>>; upsert>(params: { resource: TResource; } & UpsertParams): Promise>; prepare>, TResource extends StringKeyOf, TParams extends Params & { resource: TResource; }>(params: { resource: TResource; method?: 'GET'; } & TParams, /** * If this is passed then all the listed aliases are expected to be used in params and passed to the returned prepared function. */ expectedAliases: TAliases): PreparedFn, Promise, MaybeGetKey>>>, Model[TResource]>; prepare>, TResource extends StringKeyOf>(params: Params & { resource: TResource; method: 'PUT' | 'PATCH' | 'DELETE'; }, /** * If this is passed then all the listed aliases are expected to be used in params and passed to the returned prepared function. */ expectedAliases: TAliases): PreparedFn, Promise, Model[TResource]>; prepare>, TResource extends StringKeyOf>(params: Params & { resource: TResource; method: 'POST'; }, /** * If this is passed then all the listed aliases are expected to be used in params and passed to the returned prepared function. */ expectedAliases: TAliases): PreparedFn, Promise, Model[TResource]>; compile>(params: { resource: TResource; } & Partial & Params): string; compile(params: Params & Partial): string; request(params: Params & { method?: 'GET'; options: { $count: NonNullable['$count']>; }; }): Promise<{ d: number; }>; request(params: Params & { method?: 'GET'; id: NonNullable['id']>; }): Promise<{ d: AnyObject | undefined; }>; request(params: Omit, 'id'> & { method?: 'GET'; }): Promise<{ d: AnyObject[]; }>; request(params: Params & { method?: 'GET'; }): Promise<{ d: PromiseResultTypes; }>; request(params: Params & { method: 'PUT' | 'PATCH' | 'DELETE'; }): Promise; request(params: Params & { method: 'POST'; }): Promise; request(params: Params): Promise; abstract _request(params: { method: string; url: string; body?: AnyObject; } & AnyObject): Promise>; } export type PromiseResultTypes = number | AnyObject | AnyObject[] | undefined; type FilterOperationValue = Filter; type FilterFunctionValue = Filter; type DurationValue = { negative?: boolean; days?: number; hours?: number; minutes?: number; seconds?: number; }; export type NestedFilterOperations = ExpandableStringKeyOf> = { $count?: NestedKey extends ExpandableStringKeyOf ? Filter> | ODataCountOptions> : never; $in?: Filter; $any?: NestedKey extends ExpandableStringKeyOf ? Lambda> : never; $all?: NestedKey extends ExpandableStringKeyOf ? Lambda> : never; }; type FilterOperations = { '@'?: string; $raw?: RawFilter; $?: StringKeyOf | string[]; $and?: Filter; $or?: Filter; $not?: Filter; $ne?: FilterOperationValue; $eq?: FilterOperationValue; $gt?: FilterOperationValue; $ge?: FilterOperationValue; $lt?: FilterOperationValue; $le?: FilterOperationValue; $add?: FilterOperationValue; $sub?: FilterOperationValue; $mul?: FilterOperationValue; $div?: FilterOperationValue; $mod?: FilterOperationValue; $contains?: FilterFunctionValue; $endswith?: FilterFunctionValue; $startswith?: FilterFunctionValue; $length?: FilterFunctionValue; $indexof?: FilterFunctionValue; $substring?: FilterFunctionValue; $tolower?: FilterFunctionValue; $toupper?: FilterFunctionValue; $trim?: FilterFunctionValue; $concat?: FilterFunctionValue; $year?: FilterFunctionValue; $month?: FilterFunctionValue; $day?: FilterFunctionValue; $hour?: FilterFunctionValue; $minute?: FilterFunctionValue; $second?: FilterFunctionValue; $fractionalseconds?: FilterFunctionValue; $date?: FilterFunctionValue; $time?: FilterFunctionValue; $totaloffsetminutes?: FilterFunctionValue; $now?: FilterFunctionValue; $duration?: DurationValue; $maxdatetime?: FilterFunctionValue; $mindatetime?: FilterFunctionValue; $totalseconds?: FilterFunctionValue; $round?: FilterFunctionValue; $floor?: FilterFunctionValue; $ceiling?: FilterFunctionValue; $isof?: FilterFunctionValue; $cast?: FilterFunctionValue; $fn?: { $scope: string; $method: string; $args?: Primitive[]; }; }; export type FilterObj = { [key in StringKeyOf]?: Filter | NestedFilterOperations | undefined; } & FilterOperations; export type FilterArray = ReadonlyArray>; export type FilterBaseType = string | number | null | boolean | Date; export type RawFilter = string | [string, ...Array>] | { $string: string; [index: ResourceName]: Filter; }; export interface Lambda { $alias: Alias; $expr: Filter]: T; }>; } export type Filter = FilterObj | FilterArray | FilterBaseType; export type ResourceExpand = { [resource in StringKeyOf as ExtractExpand extends never ? never : resource]?: ODataOptions>; }; export type BaseExpand = ExpandableStringKeyOf | ResourceExpand; export type Expand = BaseExpand | ReadonlyArray>; /** * This can interact poorly with generics because `field: 'desc'` would be treated as `field: string` which doesn't match */ type OrderByDirection = 'asc' | 'desc'; export type OrderBy = StringKeyOf | ReadonlyArray> | { [k in StringKeyOf]?: OrderByDirection; } | ({ [k in ExpandableStringKeyOf & ResourceName]?: { $count: ODataCountOptions>; }; } & { $dir: OrderByDirection; }); type StringPrimitiveToType = ('null' extends T ? null : never) | ('number' extends T ? number : never) | ('string' extends T ? string : never) | ('boolean' extends T ? boolean : never) | ('Date' extends T ? Date : never); type StringDictionaryToDictType>> = keyof T extends never ? Record : { [key in keyof T]: StringPrimitiveToType; }; export type Primitive = null | string | number | boolean | Date; export type ParameterAlias = Primitive; export interface ODataOptionsWithoutCount { $filter?: Filter; $expand?: Expand; $orderby?: OrderBy; $top?: number; $skip?: number; $select?: StringKeyOf | ReadonlyArray> | ReadonlySet>; $format?: string; [index: string]: undefined | ParameterAlias | string[] | Filter | Expand | OrderBy | ReadonlySet>; } export type ODataCountOptions = Pick, '$filter'>; export interface ODataOptions extends ODataOptionsWithoutCount> { $count?: ODataCountOptions>; [index: string]: ODataOptionsWithoutCount>[string] | ODataCountOptions>; } export type OptionsObject = ODataOptions; export type ODataMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE'; export type BaseResourceId = string | number | Date | { '@': string; }; export type ResourceAlternateKey = { [key in StringKeyOf]?: BaseResourceId; }; export type ResourceId = BaseResourceId | ResourceAlternateKey; export type AnyObject = Dictionary; export interface ActionParams { action: string; body?: unknown; } export interface Params { apiPrefix?: string; method?: ODataMethod; resource?: string; id?: ResourceId; url?: string; body?: Partial; passthrough?: AnyObject; passthroughByMethod?: { [method in ODataMethod]?: AnyObject; }; options?: ODataOptions; retry?: RetryParameters; } export type ConstructorParams = Pick; export interface SubscribeParams extends Params { method?: 'GET'; pollInterval?: number; } export interface GetOrCreateParams extends Omit, 'method' | 'url'> { id: ResourceAlternateKey; resource: string; body: Partial; } export interface UpsertParams extends Omit, 'id' | 'method' | 'url'> { id: { [key in StringKeyOf]?: Primitive; }; resource: string; body: Partial; }