querying and update enhancements

This commit is contained in:
Chet Husk
2017-08-29 16:58:15 -05:00
parent 2e35d2d5c2
commit c7fbc7fe14
4 changed files with 33 additions and 14 deletions

View File

@@ -1,21 +1,26 @@
import { SObjectCreateOptions } from './create-options';
import { DescribeSObjectResult } from './describe-result';
import { Query } from './query';
import { Query, QueryResult } from './query';
import { RecordResult } from './record-result';
import { SObject } from './salesforce-object';
export interface ConnectionOptions {
// These are pulled out because according to http://jsforce.github.io/jsforce/doc/connection.js.html#line49
//the oauth options can either be in the `oauth2` proeprty OR spread across the main connection
interface OAuth2Options {
clientId: string;
clientSecret: string;
loginUrl: string;
redirectUri?: string;
}
export interface ConnectionOptions extends Partial<OAuth2Options> {
accessToken?: string;
callOptions?: Object;
instanceUrl?: string;
loginUrl?: string;
logLevel?: string;
maxRequest?: number;
oauth2?: {
clientId: string,
clientSecret: string,
redirectUri?: string,
};
oauth2?: OAuth2Options;
proxyUrl?: string;
redirectUri?: string;
refreshToken?: string;
@@ -37,6 +42,7 @@ export class Connection {
constructor(params: ConnectionOptions)
accessToken: string;
query<T>(soql: string, callback?: (err: Error, result: QueryResult<T>) => void): QueryResult<T>;
sobject(resource: string): SObject;
login(user: string, password: string, callback?: (err: Error, res: UserInfo) => void): Promise<UserInfo>;
loginByOAuth2(user: string, password: string, callback?: (err: Error, res: UserInfo) => void): Promise<UserInfo>;

View File

@@ -7,7 +7,14 @@ export interface ExecuteOptions {
scanAll?: number;
}
export class Query<T> {
export interface QueryResult<T> {
done: boolean;
nextRecordsUrl?: string;
totalSize: number;
records: T[];
}
export class Query<T> extends Promise<T> {
end(): Query<T>;
filter(filter: Object): Query<T>;
include(include: string): Query<T>;
@@ -27,7 +34,6 @@ export class Query<T> {
map(callback: (currentValue: Object) => void): Promise<any>;
scanAll(value: boolean): Query<T>;
select(fields: Object | string[] | string): Query<T>;
then(onSuccess?: Function, onRejected?: Function): Promise<any>;
thenCall(callback?: (err: Error, records: T) => void): Query<T>;
toSOQL(callback: (err: Error, soql: string) => void): Promise<string>;
update(mapping: any, type: string, callback: (err: Error, records: RecordResult[]) => void): Promise<RecordResult[]>;

View File

@@ -1,7 +1,13 @@
import { SalesforceId } from './salesforce-id';
export interface RecordResult {
id: SalesforceId;
success: boolean;
anys: Object[];
interface ErrorResult {
errors: string[];
success: false;
}
interface SuccessResult {
id: SalesforceId;
success: true;
}
export type RecordResult = SuccessResult | ErrorResult;

View File

@@ -10,7 +10,8 @@ import { SalesforceId } from './salesforce-id';
export class SObject {
record(options: any, callback?: (err: Error, ret: any) => void): void;
update(options: SObjectCreateOptions, callback?: (err: Error, ret: any) => void): void;
update<T>(record: Partial<T>, options?: Object, callback?: (err: Error, ret: RecordResult) => void): Promise<RecordResult>;
update<T>(records: Partial<T>[], options?: Object, callback?: (err: Error, ret: RecordResult[]) => void): Promise<RecordResult[]>;
retrieve(ids: string | string[], callback?: (err: Error, ret: Record | Record[]) => void): Promise<Record | Record[]>;
retrieve(ids: string | string[], options?: Object, callback?: (err: Error, ret: Record | Record[]) => void): Promise<Record | Record[]>;
upsert(records: Record | Record[], extIdField: SalesforceId, options?: Object, callback?: (err: Error, ret: RecordResult) => void): Promise<RecordResult | RecordResult[]>;