From 9ad6d029145bd16d582e017a5a5a70d9c90b4c42 Mon Sep 17 00:00:00 2001 From: Steve Hetzel Date: Mon, 14 May 2018 16:18:09 -0600 Subject: [PATCH] Adds 'success' and 'errors' properties to BatchResultInfo. Changes 'concurrencyMode' property to be optional since 'Parallel' is the default. Adds 'body' property to RequestInfo. Adds the ExecuteAnonymousResult interface. Changes Job.prototype.list() to return a BatchInfo[]. Adds tests. --- types/jsforce/batch.d.ts | 6 ++++-- types/jsforce/bulk.d.ts | 2 +- types/jsforce/connection.d.ts | 15 +++++++++++++-- types/jsforce/job.d.ts | 2 +- types/jsforce/jsforce-tests.ts | 27 ++++++++++++++++++++++++++- 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/types/jsforce/batch.d.ts b/types/jsforce/batch.d.ts index 94a24fa2cd..3314dcd33d 100644 --- a/types/jsforce/batch.d.ts +++ b/types/jsforce/batch.d.ts @@ -12,8 +12,10 @@ export interface BatchInfo { export interface BatchResultInfo { id: string; - batchId: string; - jobId: string; + batchId?: string; + jobId?: string; + success?: boolean; + errors?: string[]; } export class Batch extends Writable { diff --git a/types/jsforce/bulk.d.ts b/types/jsforce/bulk.d.ts index 51708f59f1..0356f1b9c6 100644 --- a/types/jsforce/bulk.d.ts +++ b/types/jsforce/bulk.d.ts @@ -8,7 +8,7 @@ import { Batch, BatchResultInfo } from './batch'; export interface BulkOptions { extIdField: string; - concurrencyMode: 'Serial' | 'Parallel'; + concurrencyMode?: 'Serial' | 'Parallel'; } type BulkLoadOperation = diff --git a/types/jsforce/connection.d.ts b/types/jsforce/connection.d.ts index 2283320912..27d79fdd5b 100644 --- a/types/jsforce/connection.d.ts +++ b/types/jsforce/connection.d.ts @@ -22,9 +22,10 @@ export interface PartialOAuth2Options { } export interface RequestInfo { + body?: string; + headers?: object; method?: string; url?: string; - headers?: object; } export interface ConnectionOptions extends PartialOAuth2Options { @@ -58,6 +59,16 @@ export abstract class RestApi { del(path: string, options: object, callback: () => object): Promise; } +export interface ExecuteAnonymousResult { + compiled: boolean; + compileProblem: string; + success: boolean; + line: number; + column: number; + exceptionMessage: string; + exceptionStackTrace: string; +} + export type ConnectionEvent = "refresh"; /** @@ -135,5 +146,5 @@ export class Tooling extends BaseConnection { _logger: any; // Specific to tooling - executeAnonymous(body: string, callback?: (err: Error, res: any) => void): Promise; + executeAnonymous(body: string, callback?: (err: Error, res: any) => void): Promise; } diff --git a/types/jsforce/job.d.ts b/types/jsforce/job.d.ts index bdad4bf564..519b8b6c10 100644 --- a/types/jsforce/job.d.ts +++ b/types/jsforce/job.d.ts @@ -19,6 +19,6 @@ export class Job extends EventEmitter { close(callback?: (err: Error, jobInfo: JobInfo) => void): Promise; createBatch(): Batch; info(callback?: (err: Error, jobInfo: JobInfo) => void): Promise; - list(callback?: (err: Error, jobInfo: BatchInfo) => void): Promise; + list(callback?: (err: Error, jobInfo: BatchInfo) => void): Promise; open(callback?: (err: Error, jobInfo: JobInfo) => void): Promise; } diff --git a/types/jsforce/jsforce-tests.ts b/types/jsforce/jsforce-tests.ts index 156b0d292b..0aa98d62d1 100644 --- a/types/jsforce/jsforce-tests.ts +++ b/types/jsforce/jsforce-tests.ts @@ -22,6 +22,14 @@ const salesforceConnection: sf.Connection = new sf.Connection({ salesforceConnection.sobject("Dummy").select(["thing", "other"]); +const requestInfo: sf.RequestInfo = { + body: '', + headers: {}, + method: '', + url: '' +}; +salesforceConnection.request(requestInfo); + // note the following should never compile: // salesforceConnection.sobject("Dummy").select(["lol"]); @@ -123,6 +131,17 @@ async function testAnalytics(conn: sf.Connection): Promise { }); } +async function testExecuteAnonymous(conn: sf.Connection): Promise { + const res: sf.ExecuteAnonymousResult = await salesforceConnection.tooling.executeAnonymous(''); + console.log('ExecuteAnonymousResult column: ' + res.column); + console.log('ExecuteAnonymousResult compiled: ' + res.compiled); + console.log('ExecuteAnonymousResult compileProblem: ' + res.compileProblem); + console.log('ExecuteAnonymousResult exceptionMessage: ' + res.exceptionMessage); + console.log('ExecuteAnonymousResult exceptionStackTrace: ' + res.exceptionStackTrace); + console.log('ExecuteAnonymousResult line: ' + res.line); + console.log('ExecuteAnonymousResult success: ' + res.success); +} + async function testMetadata(conn: sf.Connection): Promise { const md: sf.Metadata = conn.metadata; const m: sf.DescribeMetadataResult = await md.describe('34.0'); @@ -281,6 +300,7 @@ async function testChatter(conn: sf.Connection): Promise { await testAnalytics(salesforceConnection); await testChatter(salesforceConnection); await testMetadata(salesforceConnection); + await testExecuteAnonymous(salesforceConnection); })(); const oauth2 = new sf.OAuth2({ @@ -302,7 +322,7 @@ batch.on("queue", (batchInfo) => { // fired when batch request is queued in serv }); job.batch("batchId"); batch.poll(1000, 20000); -batch.on("response", (rets) => { +batch.on("response", (rets: sf.BatchResultInfo[]) => { for (let i = 0; i < rets.length; i++) { if (rets[i].success) { console.log(`# ${(i + 1)} loaded successfully, id = ${rets[i].id}`); @@ -312,6 +332,11 @@ batch.on("response", (rets) => { } }); +(async () => { + const batchInfos: sf.BatchInfo[] = await job.list(); + console.log('batchInfos:', batchInfos); +}); + salesforceConnection.streaming.topic("InvoiceStatementUpdates").subscribe((message) => { console.log('Event Type : ' + message.event.type); console.log('Event Created : ' + message.event.createdDate);