From aabb48847bafc8cb8cdc434e7e4df82cee716fbe Mon Sep 17 00:00:00 2001 From: Borys Kupar Date: Mon, 17 Sep 2018 13:53:34 +0200 Subject: [PATCH] [jsforce] Added Apex definitions for the connection --- types/jsforce/api/apex.d.ts | 25 ++++++++++ types/jsforce/connection.d.ts | 2 + types/jsforce/index.d.ts | 2 + types/jsforce/jsforce-tests.ts | 91 ++++++++++++++++++++++++++++++++++ 4 files changed, 120 insertions(+) create mode 100644 types/jsforce/api/apex.d.ts diff --git a/types/jsforce/api/apex.d.ts b/types/jsforce/api/apex.d.ts new file mode 100644 index 0000000000..32cd1e7143 --- /dev/null +++ b/types/jsforce/api/apex.d.ts @@ -0,0 +1,25 @@ +import { Connection, Callback, RestApiOptions } from '../connection'; + +export class Apex { + constructor(conn: Connection); + + get(path: string, options: RestApiOptions, callback?: Callback): Promise; + get(path: string, callback?: Callback): Promise; + + post(path: string, body: object, options: RestApiOptions, callback?: Callback): Promise; + post(path: string, body: object, callback?: Callback): Promise; + post(path: string, callback?: Callback): Promise; + + put(path: string, body: object, options: RestApiOptions, callback?: Callback): Promise; + put(path: string, body: object, callback?: Callback): Promise; + put(path: string, callback?: Callback): Promise; + + patch(path: string, body: object, options: RestApiOptions, callback?: Callback): Promise; + patch(path: string, body: object, callback?: Callback): Promise; + patch(path: string, callback?: Callback): Promise; + + del(path: string, options: RestApiOptions, callback?: Callback): Promise; + del(path: string, callback?: Callback): Promise; + delete(path: string, options: RestApiOptions, callback?: Callback): Promise; + delete(path: string, callback?: Callback): Promise; +} diff --git a/types/jsforce/connection.d.ts b/types/jsforce/connection.d.ts index e7fd593b01..60716753ae 100644 --- a/types/jsforce/connection.d.ts +++ b/types/jsforce/connection.d.ts @@ -7,6 +7,7 @@ import { SObject } from './salesforce-object'; import { Analytics } from './api/analytics'; import { Chatter } from './api/chatter'; import { Metadata } from './api/metadata'; +import { Apex } from './api/apex'; import { Bulk } from './bulk'; import { Cache } from './cache' import { OAuth2, Streaming } from '.'; @@ -141,6 +142,7 @@ export class Connection extends BaseConnection { tooling: Tooling; analytics: Analytics; + apex: Apex; chatter: Chatter; metadata: Metadata; bulk: Bulk; diff --git a/types/jsforce/index.d.ts b/types/jsforce/index.d.ts index d92677a5eb..a45f4dc0f2 100644 --- a/types/jsforce/index.d.ts +++ b/types/jsforce/index.d.ts @@ -5,12 +5,14 @@ // Thomas Dvornik // Tim Noonan // Abraham White +// Borys Kupar // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 export * from './api/analytics'; export * from './api/chatter'; export * from './api/metadata'; +export * from './api/apex'; export * from './batch'; export * from './bulk'; export * from './cache'; diff --git a/types/jsforce/jsforce-tests.ts b/types/jsforce/jsforce-tests.ts index 8e572448b4..08ea888062 100644 --- a/types/jsforce/jsforce-tests.ts +++ b/types/jsforce/jsforce-tests.ts @@ -716,3 +716,94 @@ async function testDescribe() { const correctlyCached = object === cachedObject; }); } + +async function testApex(conn: sf.Connection): Promise { + const apex: sf.Apex = conn.apex; + + // Test GET + { + await apex.get('/custom-get-apex-api'); + + apex.get('/custom-get-apex-api', (err: Error | null, response: object) => { + if (!err) { + console.log(response); + } + }); + + apex.get('/custom-get-apex-api', { headers: { 'X-Custom-Header': 'value' } }); + } + + // Test POST + { + await apex.post('/custom-apex-api', { email: 'test@example.com' }); + + apex.post('/custom-apex-api', (err: Error | null, response: object) => { + if (!err) { + console.log(response); + } + }); + + // Including custom body + apex.post('/custom-apex-api', { email: 'test@example.com' }, (err: Error | null, response: object) => { + if (!err) { + console.log(response); + } + }); + } + + // Test PUT + { + await apex.put('/custom-apex-api', { email: 'test@example.com' }); + + apex.put('/custom-apex-api', (err: Error | null, response: object) => { + if (!err) { + console.log(response); + } + }); + + // Including custom body + apex.put('/custom-apex-api', { email: 'test@example.com' }, (err: Error | null, response: object) => { + if (!err) { + console.log(response); + } + }); + } + + // Test PATCH + { + await apex.patch('/custom-apex-api', { email: 'test@example.com' }); + + apex.patch('/custom-apex-api', (err: Error | null, response: object) => { + if (!err) { + console.log(response); + } + }); + + // Including custom body + apex.patch('/custom-apex-api', { email: 'test@example.com' }, (err: Error | null, response: object) => { + if (!err) { + console.log(response); + } + }); + } + + // Test DELETE + { + await apex.del('/custom-apex-api'); + + apex.del('/custom-apex-api', (err: Error | null, response: object) => { + if (!err) { + console.log(response); + } + }); + + // alias + await apex.delete('/custom-apex-api'); + + apex.delete('/custom-apex-api', (err: Error | null, response: object) => { + if (!err) { + console.log(response); + } + }); + } +}