From fc18988b7e3505e60649f2a290d7b6db0a15ba52 Mon Sep 17 00:00:00 2001 From: Kamil Ejsymont Date: Fri, 7 Jul 2017 08:25:04 +0200 Subject: [PATCH 1/7] Add some missing definitions --- types/jsforce/connection.d.ts | 28 ++++++++++++++++++++++++---- types/jsforce/index.d.ts | 1 + types/jsforce/query.d.ts | 3 +++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/types/jsforce/connection.d.ts b/types/jsforce/connection.d.ts index f3864eb5d8..c7f59916c2 100644 --- a/types/jsforce/connection.d.ts +++ b/types/jsforce/connection.d.ts @@ -5,17 +5,30 @@ import { RecordResult } from './record-result'; import { SObject } from './salesforce-object'; export interface ConnectionOptions { - instanceUrl?: string; accessToken?: string; - refreshToken?: string; + callOptions?: Object; + instanceUrl?: string; + loginUrl?: string; + logLevel?: string; + maxRequest?: number; oauth2?: { clientId: string, clientSecret: string, redirectUri?: string, }; - sessionId?: string; - serverUrl?: string; + proxyUrl?: string; redirectUri?: string; + refreshToken?: string; + serverUrl?: string; + sessionId?: string; + signedRequest?: string | Object, + version?: string; +} + +export interface UserInfo { + id: string; + organizationId: string; + url: string; } export type ConnectionEvent = "refresh"; @@ -23,6 +36,13 @@ export type ConnectionEvent = "refresh"; export class Connection { constructor(params: ConnectionOptions) + accessToken: string; 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; + loginBySoap(user: string, password: string, callback?: (err: Error, res: UserInfo) => void): Promise; + logout(callback?: (err: Error, res: void) => void): Promise; + logoutByOAuth2(callback?: (err: Error, res: void) => void): Promise; + logoutBySoap(callback?: (err: Error, res: void) => void): Promise; on(eventName: ConnectionEvent, callback: Function): void; } diff --git a/types/jsforce/index.d.ts b/types/jsforce/index.d.ts index bf8f98b574..9210b5eae4 100644 --- a/types/jsforce/index.d.ts +++ b/types/jsforce/index.d.ts @@ -1,6 +1,7 @@ // Type definitions for jsforce 1.8 // Project: https://github.com/jsforce/jsforce // Definitions by: Dolan Miu +// Kamil Ejsymont // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped import * as fs from 'fs'; diff --git a/types/jsforce/query.d.ts b/types/jsforce/query.d.ts index 0d716c28da..ac59969b08 100644 --- a/types/jsforce/query.d.ts +++ b/types/jsforce/query.d.ts @@ -8,7 +8,10 @@ export interface ExecuteOptions { } export class Query { + end(): Query; filter(filter: Object): Query; + map(map: Object): Query; + include(include: string): Query; hint(hint: Object): Query; limit(value: number): Query; maxFetch(value: number): Query; From e687ec04560482508d244d8c563c130267160c98 Mon Sep 17 00:00:00 2001 From: Kamil Ejsymont Date: Fri, 7 Jul 2017 08:31:51 +0200 Subject: [PATCH 2/7] Fix linter errors --- types/jsforce/connection.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/types/jsforce/connection.d.ts b/types/jsforce/connection.d.ts index c7f59916c2..612bf6fc84 100644 --- a/types/jsforce/connection.d.ts +++ b/types/jsforce/connection.d.ts @@ -21,7 +21,7 @@ export interface ConnectionOptions { refreshToken?: string; serverUrl?: string; sessionId?: string; - signedRequest?: string | Object, + signedRequest?: string | Object; version?: string; } @@ -41,8 +41,8 @@ export class Connection { login(user: string, password: string, callback?: (err: Error, res: UserInfo) => void): Promise; loginByOAuth2(user: string, password: string, callback?: (err: Error, res: UserInfo) => void): Promise; loginBySoap(user: string, password: string, callback?: (err: Error, res: UserInfo) => void): Promise; - logout(callback?: (err: Error, res: void) => void): Promise; - logoutByOAuth2(callback?: (err: Error, res: void) => void): Promise; - logoutBySoap(callback?: (err: Error, res: void) => void): Promise; + logout(callback?: (err: Error, res: undefined) => void): Promise; + logoutByOAuth2(callback?: (err: Error, res: undefined) => void): Promise; + logoutBySoap(callback?: (err: Error, res: undefined) => void): Promise; on(eventName: ConnectionEvent, callback: Function): void; } From b555ee070da48c3cfc0c152f7e21f55d7b392177 Mon Sep 17 00:00:00 2001 From: Kamil Ejsymont Date: Fri, 7 Jul 2017 11:38:39 +0200 Subject: [PATCH 3/7] Fix map property --- types/jsforce/query.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/jsforce/query.d.ts b/types/jsforce/query.d.ts index ac59969b08..a2b10d110a 100644 --- a/types/jsforce/query.d.ts +++ b/types/jsforce/query.d.ts @@ -10,7 +10,6 @@ export interface ExecuteOptions { export class Query { end(): Query; filter(filter: Object): Query; - map(map: Object): Query; include(include: string): Query; hint(hint: Object): Query; limit(value: number): Query; @@ -25,6 +24,7 @@ export class Query { delete(callback?: (err: Error, ret: RecordResult) => void): any; destroy(callback?: (err: Error, ret: RecordResult) => void): Promise; explain(callback?: (err: Error, info: ExplainInfo) => void): Promise; + map(map: Object): Promise; scanAll(value: boolean): Query; select(fields: Object | string[] | string): Query; then(onSuccess?: Function, onRejected?: Function): Promise; From 411f20e3f5e34af494bd194c10ce3df044bbf59a Mon Sep 17 00:00:00 2001 From: Kamil Ejsymont Date: Fri, 7 Jul 2017 11:56:12 +0200 Subject: [PATCH 4/7] Final fix --- types/jsforce/query.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/jsforce/query.d.ts b/types/jsforce/query.d.ts index a2b10d110a..90e5734253 100644 --- a/types/jsforce/query.d.ts +++ b/types/jsforce/query.d.ts @@ -24,7 +24,7 @@ export class Query { delete(callback?: (err: Error, ret: RecordResult) => void): any; destroy(callback?: (err: Error, ret: RecordResult) => void): Promise; explain(callback?: (err: Error, info: ExplainInfo) => void): Promise; - map(map: Object): Promise; + map(callback: (currentValue: Object) => void): Promise; scanAll(value: boolean): Query; select(fields: Object | string[] | string): Query; then(onSuccess?: Function, onRejected?: Function): Promise; From 14602bb57b916d247ee21ae1b94b8d1d89eb270c Mon Sep 17 00:00:00 2001 From: Kamil Ejsymont Date: Fri, 7 Jul 2017 12:50:27 +0200 Subject: [PATCH 5/7] Return promise with 'any' type --- types/jsforce/query.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/jsforce/query.d.ts b/types/jsforce/query.d.ts index 90e5734253..42d258a48d 100644 --- a/types/jsforce/query.d.ts +++ b/types/jsforce/query.d.ts @@ -24,7 +24,7 @@ export class Query { delete(callback?: (err: Error, ret: RecordResult) => void): any; destroy(callback?: (err: Error, ret: RecordResult) => void): Promise; explain(callback?: (err: Error, info: ExplainInfo) => void): Promise; - map(callback: (currentValue: Object) => void): Promise; + map(callback: (currentValue: Object) => void): Promise; scanAll(value: boolean): Query; select(fields: Object | string[] | string): Query; then(onSuccess?: Function, onRejected?: Function): Promise; From 6e277bdfbf6b7fc504574ef93325e392e82efb05 Mon Sep 17 00:00:00 2001 From: Kamil Ejsymont Date: Sun, 9 Jul 2017 21:23:20 +0200 Subject: [PATCH 6/7] Add Record type --- types/jsforce/record.d.ts | 6 ++++++ types/jsforce/salesforce-object.d.ts | 5 +++-- 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 types/jsforce/record.d.ts diff --git a/types/jsforce/record.d.ts b/types/jsforce/record.d.ts new file mode 100644 index 0000000000..3bfec4c65b --- /dev/null +++ b/types/jsforce/record.d.ts @@ -0,0 +1,6 @@ +import { SalesforceId } from './salesforce-id'; + +export interface Record { + Id: SalesforceId; + attributes: Object[]; +} diff --git a/types/jsforce/salesforce-object.d.ts b/types/jsforce/salesforce-object.d.ts index 12c9b97cf7..31da3a2c92 100644 --- a/types/jsforce/salesforce-object.d.ts +++ b/types/jsforce/salesforce-object.d.ts @@ -3,6 +3,7 @@ import * as stream from 'stream'; import { SObjectCreateOptions } from './create-options'; import { DescribeSObjectResult } from './describe-result'; import { Query } from './query'; +import { Record } from './record'; import { RecordResult } from './record-result'; import { Connection } from './connection'; import { SalesforceId } from './salesforce-id'; @@ -10,8 +11,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; - retrieve(ids: string | string[], callback?: (err: Error, ret: any) => void): void; - retrieve(ids: string | string[], options?: Object, callback?: (err: Error, ret: any) => void): void; + 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; upsertBulk(input?: Record[] | stream.Stream | string, callback?: (err: Error, ret: RecordResult) => void): Batch; describeGlobal(callback: (err: Error, res: any) => void): void; From b5531790e3c63fe65336a9dd1642c85ec5a4ab3b Mon Sep 17 00:00:00 2001 From: Kamil Ejsymont Date: Sun, 9 Jul 2017 21:30:58 +0200 Subject: [PATCH 7/7] Fix tests --- types/jsforce/index.d.ts | 1 + types/jsforce/jsforce-tests.ts | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/types/jsforce/index.d.ts b/types/jsforce/index.d.ts index 9210b5eae4..fc7bd017b2 100644 --- a/types/jsforce/index.d.ts +++ b/types/jsforce/index.d.ts @@ -10,6 +10,7 @@ import * as express from 'express'; import * as glob from 'glob'; export { Date } from './date-enum'; +export { Record } from './record'; export { RecordResult } from './record-result'; export { Connection } from './connection'; export { SObject } from './salesforce-object'; diff --git a/types/jsforce/jsforce-tests.ts b/types/jsforce/jsforce-tests.ts index 70a41ec934..3c1657711d 100644 --- a/types/jsforce/jsforce-tests.ts +++ b/types/jsforce/jsforce-tests.ts @@ -32,8 +32,8 @@ salesforceConnection.sobject("ContentVersion").create({ salesforceConnection.sobject("ContentVersion").retrieve("world", { test: "test" -}, (err: Error, ret: sf.RecordResult) => { - if (err || !ret.success) { +}, (err: Error, ret: sf.Record) => { + if (err) { return; } });