From e77f5638ae92d6001e528331811217f21ed3772f Mon Sep 17 00:00:00 2001 From: tnoonan-salesforce Date: Thu, 12 Apr 2018 10:59:13 -0600 Subject: [PATCH] New Types for JSForce (#24925) Additional Types added for jsforce analytics metadata chatter --- types/jsforce/api/analytics.d.ts | 82 +++++++++++++ types/jsforce/api/chatter.d.ts | 71 +++++++++++ types/jsforce/api/metadata.d.ts | 178 +++++++++++++++++++++++++++ types/jsforce/connection.d.ts | 69 ++++++++++- types/jsforce/describe-result.d.ts | 28 ++++- types/jsforce/index.d.ts | 14 ++- types/jsforce/jsforce-tests.ts | 190 ++++++++++++++++++++++++++++- types/jsforce/oauth2.d.ts | 35 ++++++ types/jsforce/promise.d.ts | 3 + types/jsforce/query.d.ts | 39 ++++-- 10 files changed, 693 insertions(+), 16 deletions(-) create mode 100644 types/jsforce/api/analytics.d.ts create mode 100644 types/jsforce/api/chatter.d.ts create mode 100644 types/jsforce/api/metadata.d.ts create mode 100644 types/jsforce/oauth2.d.ts create mode 100644 types/jsforce/promise.d.ts diff --git a/types/jsforce/api/analytics.d.ts b/types/jsforce/api/analytics.d.ts new file mode 100644 index 0000000000..02f04fac41 --- /dev/null +++ b/types/jsforce/api/analytics.d.ts @@ -0,0 +1,82 @@ +import { callback } from '../connection'; + +interface ReportInfo { +} + +export class Dashboard { + describe(callback?: callback): Promise; + + del(callback?: callback): Promise; + + destory(callback?: callback): Promise; + + delete(callback?: callback): Promise; + + components(componentIds: () => any | string[] | string, callback?: callback): Promise; + + status(callback?: callback): Promise; + + refresh(callback?: callback): Promise; + + clone(name: string | object, folderid: string, callback?: callback): Promise; +} + +export class ReportInstance { + constructor(report: Report, id: string); + + retrieve(callback: callback): Promise +} + +export class Report { + describe(callback?: callback): Promise; + + del(callback?: callback): Promise; + + destory(callback?: callback): Promise; + + delete(callback?: callback): Promise; + + clone(name: string, callback?: callback): Promise; + + explain(callback?: callback): Promise; + + run(options: () => any | object, callback?: callback): Promise; + + exec(options: () => any | object, callback?: callback): Promise; + + execute(options: () => any | object, callback?: callback): Promise; + + executeAsync(options: () => any | object, callback?: callback): Promise; + + instance(id: string): ReportInstance; + + instances(callback?: callback): Promise; +} + +export interface ReportInstanceAttrs { +} + +export interface ExplainInfo { +} + +export interface ReportMetadata { +} + +export interface ReportResult { +} + +export interface ReportInfo { +} + +export interface DashboardInfo { +} + +export class Analytics { + report(id: string): Promise; + + reports(callback?: callback): Promise; + + dashboard(id: string): Promise; + + dashboards(callback?: callback): Promise; +} diff --git a/types/jsforce/api/chatter.d.ts b/types/jsforce/api/chatter.d.ts new file mode 100644 index 0000000000..05fc4551e0 --- /dev/null +++ b/types/jsforce/api/chatter.d.ts @@ -0,0 +1,71 @@ +import { Connection, callback } from '../connection'; +import { Query } from '../query'; +import { Stream } from 'stream'; + +interface BatchRequestParams extends RequestParams { + method: string; + url: string; + richInput?: string; +} + +interface BatchRequestResult { + statusCode: string; + result: RequestResult; +} + +interface BatchRequestResults { + hasError: boolean; + results: BatchRequestResult[]; +} + +interface RequestParams { + method: string; + url: string; + body?: string; +} + +export class RequestResult { +} + +export class Request implements Promise { + constructor(chatter: Chatter, params: RequestParams); + + batchParams(): BatchRequestParams; + + promise(): Promise; + + stream(): Stream; + + catch(onrejected?: ((reason: any) => (PromiseLike | TResult)) | null | undefined): Promise; + + then(onfulfilled?: ((value: T) => (PromiseLike | TResult1)) | null | undefined, + onrejected?: ((reason: any) => (PromiseLike | TResult2)) | null | undefined): Promise; + + thenCall(callback?: (err: Error, records: T) => void): Query; + + readonly [Symbol.toStringTag]: 'Promise'; +} + +export class Resource extends Request { + constructor(chatter: Chatter, url: string, queryParams?: object); + + create(data: object | string, callback?: callback): Request; + + del(callback?: callback): Request; + + delete(callback?: callback): Request; + + retrieve(callback?: callback): Request; + + update(data: object, callback?: callback): Request; +} + +export class Chatter { + constructor(conn: Connection); + + batch(callback?: callback): Promise; + + request(params: RequestParams, callback?: callback>): Request; + + resource(url: string, queryParams?: object): Resource +} diff --git a/types/jsforce/api/metadata.d.ts b/types/jsforce/api/metadata.d.ts new file mode 100644 index 0000000000..c867ece15b --- /dev/null +++ b/types/jsforce/api/metadata.d.ts @@ -0,0 +1,178 @@ +import { callback, Connection } from '../connection'; +import { EventEmitter } from 'events'; +import { Stream } from 'stream'; + +interface DeployResult { + id: string; + checkOnly: boolean; + completedDate: string; + createdDate: string; + details?: object[]; + done: boolean; + errorMessage?: string; + errorStatusCode?: string; + ignoreWarnings?: boolean; + lastModifiedDate: string; + numberComponentErrors: number; + numberComponentsDeployed: number; + numberComponentsTotal: number; + numberTestErrors: number; + numberTestsCompleted: number; + numberTestsTotal: number; + rollbackOnError?: boolean; + startDate: string; + status: string; + success: boolean; +} + +interface MetadataObject { + childXmlNames: string[]; + directoryName: string; + inFolder: boolean; + metaFile: boolean; + suffix: string; + xmlName: string; +} + +interface DescribeMetadataResult { + metadataObjects: MetadataObject[]; + organizationNamespace: string; + partialSaveAllowed: boolean; + testRequired: boolean; +} + +interface FileProperties { + type: string; + createdById: string; + createdByName: string; + createdDate: string; + fileName: string; + fullName: string; + id: string; + lastModifiedById: string; + lastModifiedByName: string; + lastModifiedDate: string; + manageableState?: string; + namespacePrefix?: string; +} + +interface ListMetadataQuery { + type: string; + folder?: string; +} + +interface MetadataInfo { + fullName: string; +} + +interface RetrieveRequest { +} + +interface RetrieveResult { + fileProperties: FileProperties[]; + id: string; + messages: object[]; + zipFile: string +} + +interface SaveResult { + success: boolean; + fullName: string; +} + +interface UpdateMetadataInfo { + currentName: string; + metadata: MetadataInfo; +} + +interface UpsertResult { + success: boolean; + fullName: string; + created: boolean; +} + +interface AsyncResult { + done: boolean; + id: string; + state: string; + statusCode?: string; + message?: string; +} + +interface DeployOptions { + allowMissingFiles?: boolean; + autoUpdatePackage?: boolean; + checkOnly?: boolean; + ignoreWarnings?: boolean; + performRetrieve?: boolean; + purgeOnDelete?: boolean; + rollbackOnError?: boolean; + runAllTests?: boolean; + runTests?: string[]; + singlePackage?: boolean; +} + +export class AsyncResultLocator extends EventEmitter implements Promise { + check(callback?: callback): Promise + + complete(callback?: callback): Promise + + poll(interval: number, timeout: number): void; + + catch(onrejected?: ((reason: any) => (PromiseLike | TResult)) | null | undefined): Promise; + + then(onfulfilled?: ((value: T) => (PromiseLike | TResult1)) | null | undefined, + onrejected?: ((reason: any) => (PromiseLike | TResult2)) | null | undefined): Promise; + + readonly [Symbol.toStringTag]: "Promise"; +} + +export class DeployResultLocator extends AsyncResultLocator {} +export class RetrieveResultLocator extends AsyncResultLocator {} + +export class Metadata { + pollInterval: number; + pollTimeout: number; + + constructor(conn: Connection); + + checkDeployStatus(id: string, includeDetails?: boolean, callback?: callback): Promise + + checkRetrieveStatus(id: string, callback?: callback): Promise + + checkStatus(ids: string | string[], callback?: callback>): AsyncResultLocator> + + create(type: string, metadata: MetadataInfo | Array, callback?: callback>): Promise> + + createAsync(type: string, metadata: MetadataInfo | Array, callback?: callback>): Promise> + + createSync(type: string, metadata: MetadataInfo | Array, callback?: callback>): Promise>; + + delete(type: string, fullNames: string | string[], callback?: callback>): Promise>; + + deleteAsync(type: string, metadata: string | string[] | MetadataInfo | Array, callback?: callback>): AsyncResultLocator> + + deleteSync(type: string, fullNames: string | string[], callback?: callback>): Promise>; + + deploy(zipInput: Stream | Buffer | string, options: DeployOptions, callback?:callback): DeployResultLocator; + + describe(version?: string, callback?: callback): Promise; + + list(queries: ListMetadataQuery | Array, version?: string, callback?: callback>): Promise>; + + read(type: string, fullNames: string | string[], callback?: callback>): Promise>; + + readSync(type: string, fullNames: string | string[], callback?: callback>): Promise>; + + rename(type: string, oldFullName: string, newFullName: string, callback?: callback): Promise + + retrieve(request: RetrieveRequest, callback: callback): RetrieveResultLocator + + update(type: string, updateMetadata: MetadataInfo | Array, callback?: callback>): Promise> + + updateAsync(type: string, updateMetadata: MetadataInfo, callback?: callback>): AsyncResultLocator> + + updateSync(type: string, updateMetadata: MetadataInfo | Array, callback?: callback>): Promise> + + upsert(type: string, metadata: MetadataInfo | Array, callback?: callback>): Promise> +} diff --git a/types/jsforce/connection.d.ts b/types/jsforce/connection.d.ts index 4c3e1eb5fb..06cda5e29f 100644 --- a/types/jsforce/connection.d.ts +++ b/types/jsforce/connection.d.ts @@ -1,8 +1,14 @@ -import { SObjectCreateOptions } from './create-options'; -import { DescribeSObjectResult } from './describe-result'; +import { EventEmitter } from 'events'; +import { DescribeSObjectResult, DescribeGlobalResult } from './describe-result'; import { Query, QueryResult } from './query'; +import { Record } from './record'; import { RecordResult } from './record-result'; import { SObject } from './salesforce-object'; +import { Analytics } from './api/analytics'; +import { Chatter } from './api/chatter'; +import { Metadata } from './api/metadata'; + +export type callback = (err: Error, result: T) => void; // 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 @@ -13,6 +19,12 @@ export interface OAuth2Options { redirectUri?: string; } +export interface RequestInfo { + method?: string; + url?: string; + headers?: object; +} + export interface ConnectionOptions extends OAuth2Options { accessToken?: string; callOptions?: Object; @@ -36,6 +48,14 @@ export interface UserInfo { url: string; } +export abstract class RestApi { + get(path: string, options: object, callback: () => object): Promise; + post(path: string, body: object, options: object, callback: () => object): Promise; + put(path: string, body: object, options: object, callback: () => object): Promise; + patch(path: string, body: object, options: object, callback: () => object): Promise; + del(path: string, options: object, callback: () => object): Promise; +} + export type ConnectionEvent = "refresh"; /** @@ -57,19 +77,58 @@ export type ConnectionEvent = "refresh"; * * to ensure that you have the correct data types for the various collection names. */ -export interface Connection { +export abstract class BaseConnection extends EventEmitter { + _baseUrl(): string; + request(info: RequestInfo | string, options?: Object, callback?: (err: Error, Object: object) => void): Promise; query(soql: string, callback?: (err: Error, result: QueryResult) => void): Query>; + queryMore(locator: string, options?: object, callback?: (err: Error, result: QueryResult) => void): Promise>; + create(type: string, records: Record|Array>, options?: Object, + callback?: (err: Error, result: RecordResult | RecordResult[]) => void): Promise<(RecordResult | RecordResult[])>; + insert(type: string, records: Record|Array>, options?: Object, + callback?: (err: Error, result: RecordResult | RecordResult[]) => void): Promise<(RecordResult | RecordResult[])>; + retrieve(type: string, ids: string|string[], options?: Object, + callback?: (err: Error, result: Record | Array>) => void): Promise<(Record | Array>)>; + update(type: string, records: Record|Array>, options?: Object, + callback?: (err: Error, result: RecordResult | Array>) => void): Promise<(RecordResult | RecordResult[])>; + upsert(type: string, records: Record|Array>, extIdField: string, options?: Object, + callback?: (err: Error, result: RecordResult | RecordResult[]) => void): Promise<(RecordResult | RecordResult[])>; + del(type: string, ids: string|string[], options?: Object, + callback?: (err: Error, result: RecordResult | RecordResult[]) => void): Promise<(RecordResult | RecordResult[])>; + delete(type: string, ids: string|string[], options?: Object, + callback?: (err: Error, result: RecordResult | RecordResult[]) => void): Promise<(RecordResult | RecordResult[])>; + destroy(type: string, ids: string|string[], options?: Object, + callback?: (err: Error, result: RecordResult | RecordResult[]) => void): Promise<(RecordResult | RecordResult[])>; + describe(type: string, callback?: (err: Error, result: DescribeSObjectResult) => void): Promise; + describeGlobal(callback?: (err: Error, result: DescribeGlobalResult) => void): Promise; sobject(resource: string): SObject; } -export class Connection implements Connection { +export class Connection extends BaseConnection { constructor(params: ConnectionOptions) + + tooling: Tooling; + analytics: Analytics; + chatter: Chatter; + metadata: Metadata; + + // Specific to Connection + instanceUrl: string; + version: string; accessToken: string; + initialize(options?: ConnectionOptions): void; + queryAll(soql: string, options?: object, callback?: (err: Error, result: QueryResult) => void): Query>; + authorize(code: string, callback?: (err: Error, res: UserInfo) => void): Promise; 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: 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; +} + +export class Tooling extends BaseConnection { + _logger: any; + + // Specific to tooling + executeAnonymous(body: string, callback?: (err: Error, res: any) => void): Promise; } diff --git a/types/jsforce/describe-result.d.ts b/types/jsforce/describe-result.d.ts index 584a62d3bf..352c4223a6 100644 --- a/types/jsforce/describe-result.d.ts +++ b/types/jsforce/describe-result.d.ts @@ -1,4 +1,30 @@ export interface DescribeSObjectResult { label: string; - fields: string[]; + fields: object[]; +} + +export interface DescribeGlobalResult { + activateable: boolean; + createable: boolean; + custom: boolean; + customSetting: boolean; + deletable: boolean; + deprecatedAndHidden: boolean; + feedEnabled: boolean; + hasSubtypes: boolean; + isSubtype: boolean; + keyPrefix: string; + label: string; + labelPlural: string; + layoutable: boolean; + mergeable: boolean; + mruEnabled: boolean; + name: string; + queryable: boolean; + replicateable: boolean; + retrieveable: boolean; + searchable: boolean; + triggerable: boolean; + undeletable: boolean; + updateable: boolean; } diff --git a/types/jsforce/index.d.ts b/types/jsforce/index.d.ts index 73a848b79f..edb2830f52 100644 --- a/types/jsforce/index.d.ts +++ b/types/jsforce/index.d.ts @@ -2,6 +2,8 @@ // Project: https://github.com/jsforce/jsforce // Definitions by: Dolan Miu // Kamil Ejsymont +// Thomas Dvornik +// Tim Noonan // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.2 @@ -13,6 +15,16 @@ import * as glob from 'glob'; export { Date } from './date-enum'; export { Record } from './record'; export { RecordResult } from './record-result'; -export { Connection } from './connection'; +export { Connection, ConnectionOptions, RequestInfo, Tooling, callback } from './connection'; export { SObject } from './salesforce-object'; export { SalesforceId } from './salesforce-id'; +export { OAuth2, OAuth2Options } from './oauth2'; +export { Query, QueryResult } from './query'; +export { Promise } from './promise'; +export { Report, Dashboard, Analytics, ReportInstance, DashboardInfo, ReportInfo, ExplainInfo, ReportInstanceAttrs, + ReportMetadata, ReportResult } from './api/analytics'; +export { Chatter, Request, RequestResult, BatchRequestResults, BatchRequestParams, + Resource, BatchRequestResult, RequestParams } from './api/chatter'; +export { Metadata, SaveResult, MetadataInfo, AsyncResult, RetrieveResultLocator, RetrieveRequest, FileProperties, + ListMetadataQuery, DescribeMetadataResult, DeployOptions, AsyncResultLocator, RetrieveResult, MetadataObject, + DeployResult, DeployResultLocator, UpdateMetadataInfo, UpsertResult } from './api/metadata'; diff --git a/types/jsforce/jsforce-tests.ts b/types/jsforce/jsforce-tests.ts index 2c1b5b1f9c..9205d59096 100644 --- a/types/jsforce/jsforce-tests.ts +++ b/types/jsforce/jsforce-tests.ts @@ -79,7 +79,7 @@ salesforceConnection.query('SELECT Id FROM Account') .on('end', (query: any) => { console.log(records); }) - .on('error', (error) => { + .on('error', (error: Error) => { console.log('Error returned from query:', error); }) .run({ autoFetch: true, maxFetch: 25 }); @@ -89,3 +89,191 @@ salesforceConnection.sobject('Coverage__c') salesforceConnection.sobject('Coverage__c') .select(['Id', 'Name']).del("test", () => { }); + +async function testAnalytics(conn: sf.Connection): Promise { + const analytics: sf.Analytics = conn.analytics; + + const dashboards: sf.DashboardInfo[] = await analytics.dashboards(); + const dashboard = dashboards[0] as any; + Object.keys(dashboards[0]) + .forEach((key: string) => console.log(`key: ${key} : ${dashboard[key]}`)); + console.log('dashboard keys from await'); + + analytics.dashboards((err, dashboards: sf.DashboardInfo[]) => { + const _dashboard: any = dashboards[0] as any; + Object.keys(_dashboard) + .forEach((key: string) => console.log(`key: ${key} : ${_dashboard[key]}`)); + console.log('dashboard keys from callback'); + }); + + const reports: sf.ReportInfo[] = await analytics.reports(); + const report: any = reports[0] as any; + Object.keys(reports[0]).forEach((key: string) => console.log(`key: ${key} : ${report[key]}`)); + + analytics.reports((err, reports: sf.ReportInfo[]) => { + const _report: any = reports[0] as any; + Object.keys(reports[0]) + .forEach((key: string) => console.log(`key: ${key} : ${_report[key]}`)); + console.log('report keys from callback'); + }); +} + +async function testMetadata(conn: sf.Connection): Promise { + const md: sf.Metadata = conn.metadata; + const m: sf.DescribeMetadataResult = await md.describe('34.0'); + const pages: sf.MetadataObject[] = + m.metadataObjects.filter((value: sf.MetadataObject) => value.directoryName === 'pages'); + console.log(`ApexPage?: ${pages[0].xmlName === 'ApexPage'}`); + + const types: sf.ListMetadataQuery[] = [{type: 'CustomObject', folder: null}]; + md.list(types, '39.0', (err, properties: sf.FileProperties[]) => { + if (err) { + console.error('err', err); + return; + } + const meta: sf.FileProperties = properties[0]; + console.log('metadata count: ' + properties.length); + console.log('createdById: ' + meta.createdById); + console.log('createdByName: ' + meta.createdByName); + console.log('createdDate: ' + meta.createdDate); + console.log('fileName: ' + meta.fileName); + console.log('fullName: ' + meta.fullName); + console.log('id: ' + meta.id); + console.log('lastModifiedById: ' + meta.lastModifiedById); + console.log('lastModifiedByName: ' + meta.lastModifiedByName); + console.log('lastModifiedDate: ' + meta.lastModifiedDate); + console.log('manageableState: ' + meta.manageableState); + console.log('namespacePrefix: ' + meta.namespacePrefix); + console.log('type: ' + meta.type); + }); + + const fullNames: string[] = [ 'Account', 'Contact' ]; + const info: sf.MetadataInfo | sf.MetadataInfo[] = await md.read('CustomObject', fullNames); + console.log((info as sf.MetadataInfo[])[0].fullName); + console.log((info as sf.MetadataInfo[])[1].fullName); + + const now: number = Date.now(); + const now2: number = now + 1; + const metadata = [{ + fullName: `TestObject${now}__c`, + label: `Test Object ${now}`, + pluralLabel: `Test Object ${now}`, + nameField: { + type: 'Text', + label: `Test Object Name ${now}` + }, + deploymentStatus: 'Deployed', + sharingModel: 'ReadWrite' + }, { + fullName: `TestObject${now2}__c`, + label: `Test Object ${now2}`, + pluralLabel: `Test Object ${now2}`, + nameField: { + type: 'AutoNumber', + label: 'Test Object #' + }, + deploymentStatus: 'InDevelopment', + sharingModel: 'Private' + }]; + + const result: sf.SaveResult | sf.SaveResult[] = await md.create('CustomObject', metadata); + console.log(`created ${(result as sf.SaveResult[])[0].fullName} - ${(result as sf.SaveResult[])[0].success}`); + console.log(`created ${(result as sf.SaveResult[])[1].fullName} - ${(result as sf.SaveResult[])[1].success}`); + + const fullNames2: string[] = [`TestObject${now}__c`, `TestObject${now2}__c`]; + const result2: sf.SaveResult | sf.SaveResult[] = + await (md.delete('CustomObject', fullNames2) as Promise); + console.log(`deleted ${result2[0].fullName} - ${result2[0].success}`); + console.log(`deleted ${result2[1].fullName} - ${result2[1].success}`); +} + +async function testChatter(conn: sf.Connection): Promise { + const chatter: sf.Chatter = conn.chatter; + chatter.resource('/feed-elements').create({ + body: { + messageSegments: [{ + type: 'Text', + text: 'This is new post' + }] + }, + feedElementType : 'FeedItem', + subjectId: 'me' + }, (err: Error, result: any) => { + if (err) { + throw err; + } + const feedMessageUrl = `/feed-elements/${result.id}/capabilities/comments/items`; + chatter.resource(feedMessageUrl).create({ + body: { + messageSegments: [{ + type: 'Text', + text: 'This is new comment on the post' + }] + } + }, (err: Error, result: any) => { + if (err) { + throw err; + } + console.log("Id: " + result.id); + console.log("URL: " + result.url); + console.log("Body: " + result.body.messageSegments[0].text); + }); + }); + + const resourceMe: sf.Resource = chatter.resource('/users/me'); + resourceMe.retrieve((err, res: any) => { + if (err) { + console.error(err); + return; + } + console.log("username: " + res.username); + console.log("email: " + res.email); + console.log("small photo url: " + res.photo.smallPhotoUrl); + }); + + chatter.resource('/users', { q: 'Suzuki' }).retrieve((err, result: any) => { + if (err) { + console.error(err); + return; + } + console.log("current page URL: " + result['currentPageUrl']); + console.log("next page URL: " + result['nextPageUrl']); + console.log("users count: " + result['users'].length); + for (const user of result['users']) { + console.log('User ID: ' + user.id); + console.log('User URL: ' + user.url); + console.log('Username: ' + user.username); + } + }); + + const feedResource: sf.Resource = chatter.resource('/feed-elements'); + + const feedCreateRequest: any = await (feedResource.create({ + body: { + messageSegments: [{ + type: 'Text', + text: 'This is new comment on the post' + }] + }, + feedElementType : 'FeedItem', + subjectId: 'me' + }) as Promise); + + console.log(`feedCreateRequest.id: ${feedCreateRequest.id}`); + const itemLikesUrl = `/feed-elements/${feedCreateRequest.id}/capabilities/chatter-likes/items`; + const itemsLikeResource: sf.Resource = chatter.resource(itemLikesUrl); + + const itemsLikeCreateResult: sf.RequestResult = await (itemsLikeResource.create('') as Promise); + console.log(`itemsLikeCreateResult['likedItem']: ${itemsLikeCreateResult as any ['likedItem']}`); +} + +(async () => { + const query2: sf.QueryResult = + await (salesforceConnection.query("SELECT Id, Name FROM User") as Promise>); + console.log("Query Promise: total in database: " + query2.totalSize); + console.log("Query Promise: total fetched : " + query2.records[0]); + + await testAnalytics(salesforceConnection); + await testChatter(salesforceConnection); + await testMetadata(salesforceConnection); +})(); diff --git a/types/jsforce/oauth2.d.ts b/types/jsforce/oauth2.d.ts new file mode 100644 index 0000000000..833a9d45fd --- /dev/null +++ b/types/jsforce/oauth2.d.ts @@ -0,0 +1,35 @@ +export interface OAuth2Options { + authzServiceUrl?: string; + tokenServiceUrl?: string; + clientId?: string; + clientSecret?: string; + httpProxy?: string; + loginUrl?: string; + proxyUrl?: string; + redirectUri?: string; + refreshToken?: string; + revokeServiceUrl?: string; + authCode?: string; + privateKeyFile?: string; + privateKey?: string; // Used for sfdx auth files for legacy support reasons +} + +export class OAuth2 { + constructor (options? : OAuth2Options); + + protected _postParams(options: any, callback: () => any): void + + loginUrl: string; + authzServiceUrl: string; + tokenServiceUrl: string; + revokeServiceUrl: string; + clientId: string; + clientSecret: string; + redirectUri: string; + + getAuthorizationUrl(params: any): string; + refreshToken(code: string, callback?: () => any): Promise; + requestToken(code: string, callback?: () => any): Promise; + authenticate(username: string, password: string, callback?: () => any): Promise; + revokeToken(accessToken: string, callback?: () => any): Promise; +} diff --git a/types/jsforce/promise.d.ts b/types/jsforce/promise.d.ts new file mode 100644 index 0000000000..f4f6e0660b --- /dev/null +++ b/types/jsforce/promise.d.ts @@ -0,0 +1,3 @@ +export class Promise { + thenCall: (cb: () => void) => void; +} diff --git a/types/jsforce/query.d.ts b/types/jsforce/query.d.ts index 0e7d413cf8..b33af41ede 100644 --- a/types/jsforce/query.d.ts +++ b/types/jsforce/query.d.ts @@ -1,7 +1,5 @@ // http://jsforce.github.io/jsforce/doc/Query.html import { Readable } from 'stream'; - -import { SalesforceId } from './salesforce-id'; import { RecordResult } from './record-result'; export interface ExecuteOptions { @@ -19,38 +17,63 @@ export interface QueryResult { export class Query extends Readable implements Promise { end(): Query; + filter(filter: Object): Query; + include(include: string): Query; + hint(hint: Object): Query; + limit(value: number): Query; + maxFetch(value: number): Query; + offset(value: number): Query; + skip(value: number): Query; - sort(keyOrList: string | Object[] | Object, direction?: "ASC" | "DESC" | number): Query; + + sort(keyOrList: string | Object[] | Object, direction?: 'ASC' | 'DESC' | number): Query; + run(options?: ExecuteOptions, callback?: (err: Error, records: T[]) => void): Query; + execute(options?: ExecuteOptions, callback?: (err: Error, records: T[]) => void): Query; + exec(options?: ExecuteOptions, callback?: (err: Error, records: T[]) => void): Query; + del(type?: string, callback?: (err: Error, ret: RecordResult) => void): any; del(callback?: (err: Error, ret: RecordResult) => void): any; + delete(type?: string, callback?: (err: Error, ret: RecordResult) => void): any; delete(callback?: (err: Error, ret: RecordResult) => void): any; + destroy(type?: string, callback?: (err: Error, ret: RecordResult) => void): Promise; destroy(callback?: (err: Error, ret: RecordResult) => void): Promise; destroy(error?: Error): void; + explain(callback?: (err: Error, info: ExplainInfo) => void): Promise; + map(callback: (currentValue: Object) => void): Promise; + scanAll(value: boolean): Query; + select(fields: Object | string[] | string): Query; + 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; + where(conditions: Object | string): Query; - // Implementing promise methods - then(onfulfilled?: any): Promise; - catch(onrejected?: any): Promise; finally(): Promise; - [Symbol.toStringTag]: "Promise"; + + [Symbol.toStringTag]: 'Promise'; + + catch(onrejected?: ((reason: any) => (PromiseLike | TResult))): Promise; + + then(onfulfilled?: ((value: T) => (PromiseLike | TResult1)), + onrejected?: ((reason: any) => (PromiseLike | TResult2))): Promise; } -export class ExplainInfo { } +export class ExplainInfo {}