From c7fbc7fe1456f01d5ec8cb34eb81e4e0a3ada235 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Tue, 29 Aug 2017 16:58:15 -0500 Subject: [PATCH] querying and update enhancements --- types/jsforce/connection.d.ts | 20 +++++++++++++------- types/jsforce/query.d.ts | 10 ++++++++-- types/jsforce/record-result.d.ts | 14 ++++++++++---- types/jsforce/salesforce-object.d.ts | 3 ++- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/types/jsforce/connection.d.ts b/types/jsforce/connection.d.ts index 612bf6fc84..859b6dbdb2 100644 --- a/types/jsforce/connection.d.ts +++ b/types/jsforce/connection.d.ts @@ -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 { 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(soql: string, callback?: (err: Error, result: QueryResult) => void): QueryResult; sobject(resource: string): SObject; login(user: string, password: string, callback?: (err: Error, res: UserInfo) => void): Promise; loginByOAuth2(user: string, password: string, callback?: (err: Error, res: UserInfo) => void): Promise; diff --git a/types/jsforce/query.d.ts b/types/jsforce/query.d.ts index 42d258a48d..00b90a9464 100644 --- a/types/jsforce/query.d.ts +++ b/types/jsforce/query.d.ts @@ -7,7 +7,14 @@ export interface ExecuteOptions { scanAll?: number; } -export class Query { +export interface QueryResult { + done: boolean; + nextRecordsUrl?: string; + totalSize: number; + records: T[]; +} + +export class Query extends Promise { end(): Query; filter(filter: Object): Query; include(include: string): Query; @@ -27,7 +34,6 @@ export class Query { map(callback: (currentValue: Object) => void): Promise; scanAll(value: boolean): Query; select(fields: Object | string[] | string): Query; - then(onSuccess?: Function, onRejected?: Function): Promise; thenCall(callback?: (err: Error, records: T) => void): Query; toSOQL(callback: (err: Error, soql: string) => void): Promise; update(mapping: any, type: string, callback: (err: Error, records: RecordResult[]) => void): Promise; diff --git a/types/jsforce/record-result.d.ts b/types/jsforce/record-result.d.ts index bf53a5bf98..df77ef26d3 100644 --- a/types/jsforce/record-result.d.ts +++ b/types/jsforce/record-result.d.ts @@ -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; diff --git a/types/jsforce/salesforce-object.d.ts b/types/jsforce/salesforce-object.d.ts index 31da3a2c92..2fd097b709 100644 --- a/types/jsforce/salesforce-object.d.ts +++ b/types/jsforce/salesforce-object.d.ts @@ -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(record: Partial, options?: Object, callback?: (err: Error, ret: RecordResult) => void): Promise; + update(records: Partial[], options?: Object, callback?: (err: Error, ret: RecordResult[]) => void): Promise; retrieve(ids: string | string[], callback?: (err: Error, ret: Record | Record[]) => void): Promise; retrieve(ids: string | string[], options?: Object, callback?: (err: Error, ret: Record | Record[]) => void): Promise; upsert(records: Record | Record[], extIdField: SalesforceId, options?: Object, callback?: (err: Error, ret: RecordResult) => void): Promise;