[jsforce] Added Apex definitions for the connection

This commit is contained in:
Borys Kupar
2018-09-17 13:53:34 +02:00
parent 428a996d6b
commit aabb48847b
4 changed files with 120 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
import { Connection, Callback, RestApiOptions } from '../connection';
export class Apex {
constructor(conn: Connection);
get<T>(path: string, options: RestApiOptions, callback?: Callback<T>): Promise<T>;
get<T>(path: string, callback?: Callback<T>): Promise<T>;
post<T>(path: string, body: object, options: RestApiOptions, callback?: Callback<T>): Promise<T>;
post<T>(path: string, body: object, callback?: Callback<T>): Promise<T>;
post<T>(path: string, callback?: Callback<T>): Promise<T>;
put<T>(path: string, body: object, options: RestApiOptions, callback?: Callback<T>): Promise<T>;
put<T>(path: string, body: object, callback?: Callback<T>): Promise<T>;
put<T>(path: string, callback?: Callback<T>): Promise<T>;
patch<T>(path: string, body: object, options: RestApiOptions, callback?: Callback<T>): Promise<T>;
patch<T>(path: string, body: object, callback?: Callback<T>): Promise<T>;
patch<T>(path: string, callback?: Callback<T>): Promise<T>;
del<T>(path: string, options: RestApiOptions, callback?: Callback<T>): Promise<T>;
del<T>(path: string, callback?: Callback<T>): Promise<T>;
delete<T>(path: string, options: RestApiOptions, callback?: Callback<T>): Promise<T>;
delete<T>(path: string, callback?: Callback<T>): Promise<T>;
}
+2
View File
@@ -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;
+2
View File
@@ -5,12 +5,14 @@
// Thomas Dvornik <https://github.com/amphro>
// Tim Noonan <https://github.com/tnoonan-salesforce>
// Abraham White <https://github.com/whiteabelincoln>
// Borys Kupar <https://github.com/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';
+91
View File
@@ -716,3 +716,94 @@ async function testDescribe() {
const correctlyCached = object === cachedObject;
});
}
async function testApex(conn: sf.Connection): Promise<void> {
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);
}
});
}
}