UNPKG

3.24 kBTypeScriptView Raw
1// http://jsforce.github.io/jsforce/doc/Query.html
2import { Readable } from "stream";
3import { RecordResult } from "./record-result";
4
5export interface ExecuteOptions {
6 autoFetch?: boolean | undefined;
7 maxFetch?: number | undefined;
8 headers?: object | undefined;
9 scanAll?: boolean | undefined;
10}
11
12export interface QueryResult<T> {
13 done: boolean;
14 nextRecordsUrl?: string | undefined;
15 totalSize: number;
16 records: T[];
17}
18
19// Unfortunately because TypeScript wants you to believe JS has classical inheritance,
20// you can't say that Query "extends Readable" because `filter` and `map` disagree with Readable's own.
21// That can only be fixed by a breaking change in Query's filter and map methods. Your call.
22export class Query<T> extends Readable implements Promise<T> {
23 end(): Query<T>;
24
25 // @ts-ignore conflicts with built-in Readable.filter
26 filter(filter: Object): Query<T>;
27
28 include(include: string): Query<T>;
29
30 hint(hint: Object): Query<T>;
31
32 limit(value: number): Query<T>;
33
34 maxFetch(value: number): Query<T>;
35
36 offset(value: number): Query<T>;
37
38 skip(value: number): Query<T>;
39
40 sort(keyOrList: string | Object[] | Object, direction?: "ASC" | "DESC" | number): Query<T>;
41
42 run(options?: ExecuteOptions, callback?: (err: Error, records: T[]) => void): Query<T>;
43
44 execute(options?: ExecuteOptions, callback?: (err: Error, records: T[]) => void): Query<T>;
45
46 exec(options?: ExecuteOptions, callback?: (err: Error, records: T[]) => void): Query<T>;
47
48 del(type?: string, callback?: (err: Error, ret: RecordResult) => void): any;
49 del(callback?: (err: Error, ret: RecordResult) => void): any;
50
51 delete(type?: string, callback?: (err: Error, ret: RecordResult) => void): any;
52 delete(callback?: (err: Error, ret: RecordResult) => void): any;
53
54 destroy(type?: string, callback?: (err: Error, ret: RecordResult) => void): Promise<RecordResult[]>;
55 destroy(callback?: (err: Error, ret: RecordResult) => void): Promise<RecordResult[]>;
56 destroy(error?: Error): this;
57
58 explain(callback?: (err: Error, info: ExplainInfo) => void): Promise<ExplainInfo>;
59
60 // @ts-ignore conflicts with built-in Readable.map
61 map(callback: (currentValue: Object) => void): Promise<any>;
62
63 scanAll(value: boolean): Query<T>;
64
65 select(fields: Object | string[] | string): Query<T>;
66
67 thenCall(callback?: (err: Error, records: T) => void): Query<T>;
68
69 toSOQL(callback: (err: Error, soql: string) => void): Promise<string>;
70
71 update(
72 mapping: any,
73 type: string,
74 callback?: (err: Error, records: RecordResult[]) => void,
75 ): Promise<RecordResult[]>;
76 update(mapping: any, callback?: (err: Error, records: RecordResult[]) => void): Promise<RecordResult[]>;
77
78 where(conditions: Object | string): Query<T>;
79
80 finally(): Promise<T>;
81
82 [Symbol.toStringTag]: "Promise";
83
84 catch<TResult>(onrejected?: (reason: any) => PromiseLike<TResult> | TResult): Promise<T | TResult>;
85
86 then<TResult1, TResult2>(
87 onfulfilled?: (value: T) => PromiseLike<TResult1> | TResult1,
88 onrejected?: (reason: any) => PromiseLike<TResult2> | TResult2,
89 ): Promise<TResult1 | TResult2>;
90}
91
92export class ExplainInfo {}
93
\No newline at end of file