mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 20:40:20 +00:00
more cleanups and stronger typing
This commit is contained in:
Vendored
+27
-6
@@ -20,7 +20,7 @@ export interface ConnectionOptions extends Partial<OAuth2Options> {
|
||||
loginUrl?: string;
|
||||
logLevel?: string;
|
||||
maxRequest?: number;
|
||||
oauth2?: OAuth2Options;
|
||||
oauth2?: Partial<OAuth2Options>;
|
||||
proxyUrl?: string;
|
||||
redirectUri?: string;
|
||||
refreshToken?: string;
|
||||
@@ -38,12 +38,33 @@ export interface UserInfo {
|
||||
|
||||
export type ConnectionEvent = "refresh";
|
||||
|
||||
export class Connection {
|
||||
constructor(params: ConnectionOptions)
|
||||
|
||||
accessToken: string;
|
||||
/**
|
||||
* the methods exposed here are done so that a client can use 'declaration augmentation' to get intellisense on their own projects.
|
||||
* for example, given a type
|
||||
*
|
||||
* interface Foo {
|
||||
* thing: string;
|
||||
* yes: boolean;
|
||||
* }
|
||||
*
|
||||
* you can write
|
||||
*
|
||||
* declare module "jsforce" {
|
||||
* interface Connection {
|
||||
* sobject(type: 'Foo'): SObject<Foo>
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* to ensure that you have the correct data types for the various collection names.
|
||||
*/
|
||||
export interface Connection {
|
||||
query<T>(soql: string, callback?: (err: Error, result: QueryResult<T>) => void): QueryResult<T>;
|
||||
sobject(resource: string): SObject;
|
||||
sobject<T>(resource: string): SObject<T>;
|
||||
}
|
||||
|
||||
export class Connection implements Connection {
|
||||
constructor(params: ConnectionOptions)
|
||||
accessToken: string;
|
||||
login(user: string, password: string, callback?: (err: Error, res: UserInfo) => void): Promise<UserInfo>;
|
||||
loginByOAuth2(user: string, password: string, callback?: (err: Error, res: UserInfo) => void): Promise<UserInfo>;
|
||||
loginBySoap(user: string, password: string, callback?: (err: Error, res: UserInfo) => void): Promise<UserInfo>;
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import * as sf from 'jsforce';
|
||||
|
||||
export interface DummyRecord {
|
||||
thing: boolean;
|
||||
other: number;
|
||||
person: string;
|
||||
}
|
||||
|
||||
const salesforceConnection: sf.Connection = new sf.Connection({
|
||||
instanceUrl: '',
|
||||
refreshToken: '',
|
||||
@@ -9,6 +15,11 @@ const salesforceConnection: sf.Connection = new sf.Connection({
|
||||
},
|
||||
});
|
||||
|
||||
salesforceConnection.sobject<DummyRecord>("Dummy").select(["thing", "other"]);
|
||||
|
||||
// note the following should never compile:
|
||||
// salesforceConnection.sobject<DummyRecord>("Dummy").select(["lol"]);
|
||||
|
||||
salesforceConnection.sobject("Account").create({
|
||||
Name: "Test Acc 2",
|
||||
BillingStreet: "Maplestory street",
|
||||
@@ -30,9 +41,9 @@ salesforceConnection.sobject("ContentVersion").create({
|
||||
}
|
||||
});
|
||||
|
||||
salesforceConnection.sobject("ContentVersion").retrieve("world", {
|
||||
salesforceConnection.sobject<any>("ContentVersion").retrieve("world", {
|
||||
test: "test"
|
||||
}, (err: Error, ret: sf.Record) => {
|
||||
}, (err: Error, ret) => {
|
||||
if (err) {
|
||||
return;
|
||||
}
|
||||
|
||||
Vendored
+13
-3
@@ -1,6 +1,16 @@
|
||||
import { RecordResult } from './record-result';
|
||||
import { Connection } from './connection';
|
||||
import { SalesforceId } from './salesforce-id';
|
||||
import { Stream } from 'stream';
|
||||
|
||||
export interface Record {
|
||||
Id: SalesforceId;
|
||||
attributes: Object[];
|
||||
export class RecordReference<T> {
|
||||
constructor(conn: Connection, type: string, id: SalesforceId);
|
||||
blob(fieldName: string): Stream;
|
||||
del(options?: Object, callback?: (err: Error, result: RecordResult) => void): Promise<RecordResult>;
|
||||
delete(options?: Object, callback?: (err: Error, result: RecordResult) => void): Promise<RecordResult>;
|
||||
destroy(options?: Object, callback?: (err: Error, result: RecordResult) => void): Promise<RecordResult>;
|
||||
retrieve(options?: Object, callback?: (err: Error, record: Record<T>) => void): Promise<Record<T>>;
|
||||
update(record: Partial<T>, options?: Object, callback?: (err: Error, result: RecordResult) => void): Promise<RecordResult>;
|
||||
}
|
||||
|
||||
export type Record<T> = {Id: SalesforceId } & T;
|
||||
|
||||
Vendored
+34
-22
@@ -3,19 +3,20 @@ import * as stream from 'stream';
|
||||
import { SObjectCreateOptions } from './create-options';
|
||||
import { DescribeSObjectResult } from './describe-result';
|
||||
import { Query } from './query';
|
||||
import { Record } from './record';
|
||||
import { Record, RecordReference } from './record';
|
||||
import { RecordResult } from './record-result';
|
||||
import { Connection } from './connection';
|
||||
import { SalesforceId } from './salesforce-id';
|
||||
|
||||
export class SObject {
|
||||
record(options: any, callback?: (err: Error, ret: any) => void): void;
|
||||
update<T>(record: Partial<T>, options?: Object, callback?: (err: Error, ret: RecordResult) => void): Promise<RecordResult>;
|
||||
update<T>(records: Partial<T>[], options?: Object, callback?: (err: Error, ret: RecordResult[]) => void): Promise<RecordResult[]>;
|
||||
retrieve(ids: string | string[], callback?: (err: Error, ret: Record | Record[]) => void): Promise<Record | Record[]>;
|
||||
retrieve(ids: string | string[], options?: Object, callback?: (err: Error, ret: Record | Record[]) => void): Promise<Record | Record[]>;
|
||||
upsert(records: Record | Record[], extIdField: SalesforceId, options?: Object, callback?: (err: Error, ret: RecordResult) => void): Promise<RecordResult | RecordResult[]>;
|
||||
upsertBulk(input?: Record[] | stream.Stream | string, callback?: (err: Error, ret: RecordResult) => void): Batch;
|
||||
export class SObject<T> {
|
||||
record(id: SalesforceId): RecordReference<T>;
|
||||
retrieve(id: SalesforceId, options?: Object, callback?:(err: Error, record: Record<T>) => void): Promise<Record<T>>;
|
||||
retrieve(ids: SalesforceId[], options?: Object, callback?: (err: Error, ret: Record<T>[]) => void): Promise<Record<T>[]>;
|
||||
update(record: Partial<T>, options?: Object, callback?: (err: Error, ret: RecordResult) => void): Promise<RecordResult>;
|
||||
update(records: Partial<T>[], options?: Object, callback?: (err: Error, ret: RecordResult[]) => void): Promise<RecordResult[]>;
|
||||
upsert(records: Record<T>, extIdField: SalesforceId, options?: Object, callback?: (err: Error, ret: RecordResult) => void): Promise<RecordResult>;
|
||||
upsert(records: Record<T>[], extIdField: SalesforceId, options?: Object, callback?: (err: Error, ret: RecordResult) => void): Promise<RecordResult[]>;
|
||||
upsertBulk(input?: Record<T>[] | stream.Stream | string, callback?: (err: Error, ret: RecordResult[] | BatchResultInfo[]) => void): Batch;
|
||||
describeGlobal(callback: (err: Error, res: any) => void): void;
|
||||
describe$(callback: (err: Error, ret: DescribeSObjectResult) => void): void;
|
||||
describeGlobal$(callback: (err: Error, res: any) => void): void;
|
||||
@@ -29,39 +30,37 @@ export class SObject {
|
||||
findOne<T>(query?: any, fields?: Object | string[] | string, options?: Object, callback?: (err: Error, ret: T) => void): void;
|
||||
|
||||
approvalLayouts(callback?: (layoutInfo: ApprovalLayoutInfo) => void): Promise<ApprovalLayoutInfo>;
|
||||
bulkload(operation: string, options?: { extIdField?: string }, input?: Record[] | stream.Stream[] | string[], callback?: (err: Error, ret: RecordResult) => void): Batch;
|
||||
bulkload(operation: string, options?: { extIdField?: string }, input?: Record<T>[] | stream.Stream[] | string[], callback?: (err: Error, ret: RecordResult) => void): Batch;
|
||||
compactLayouts(callback?: CompactLayoutInfo): Promise<CompactLayoutInfo>;
|
||||
count(conditions?: Object | string, callback?: (err: Error, num: number) => void): Promise<number>;
|
||||
create(options: any | any[], callback?: (err: Error, ret: RecordResult | RecordResult[]) => void): Promise<RecordResult | RecordResult[]>;
|
||||
createBulk(input?: Record[] | stream.Stream | string, callback?: (err: Error, ret: RecordResult) => void): Batch;
|
||||
createBulk(input?: Record<T>[] | stream.Stream | string, callback?: (err: Error, ret: RecordResult) => void): Batch;
|
||||
del(ids: string | string[], callback?: (err: Error, ret: any) => void): void;
|
||||
destroy(ids: string | string[], callback?: (err: Error, ret: any) => void): void;
|
||||
delete(ids: string | string[], callback?: (err: Error, ret: any) => void): void;
|
||||
deleteBulk(input?: Record[] | stream.Stream | string, callback?: (err: Error, ret: RecordResult) => void): Batch;
|
||||
destroyBulk(input?: Record[] | stream.Stream | string, callback?: (err: Error, ret: RecordResult) => void): Batch;
|
||||
destroyHardBulk(input?: Record[] | stream.Stream | string, callback?: (err: Error, ret: RecordResult) => void): Batch;
|
||||
deleteBulk(input?: Record<T>[] | stream.Stream | string, callback?: (err: Error, ret: RecordResult) => void): Batch;
|
||||
destroyBulk(input?: Record<T>[] | stream.Stream | string, callback?: (err: Error, ret: RecordResult) => void): Batch;
|
||||
destroyHardBulk(input?: Record<T>[] | stream.Stream | string, callback?: (err: Error, ret: RecordResult) => void): Batch;
|
||||
deleted(start: Date | string, end: Date | string, callback?: (info: DeletedRecordsInfo) => void): Promise<DeletedRecordsInfo>;
|
||||
deleteHardBulk(input?: Record[] | stream.Stream | string, callback?: (err: Error, ret: RecordResult) => void): Batch;
|
||||
deleteHardBulk(input?: Record<T>[] | stream.Stream | string, callback?: (err: Error, ret: RecordResult) => void): Batch;
|
||||
describe(callback?: (err: Error, ret: DescribeSObjectResult) => void): Promise<DescribeSObjectResult>;
|
||||
insert(options: any | any[], callback?: (err: Error, ret: RecordResult | RecordResult[]) => void): Promise<RecordResult | RecordResult[]>;
|
||||
insertBulk(input?: Record[] | stream.Stream | string, callback?: (err: Error, ret: RecordResult) => void): Batch;
|
||||
insertBulk(input?: Record<T>[] | stream.Stream | string, callback?: (err: Error, ret: RecordResult) => void): Batch;
|
||||
layouts(layoutName?: string, callback?: (err: Error, info: LayoutInfo) => void): Promise<LayoutInfo>;
|
||||
listview(id: string): ListView;
|
||||
listviews(callback?: (err: Error, info: ListViewsInfo) => void): Promise<ListViewsInfo>;
|
||||
quickAction(actionName: string): QuickAction;
|
||||
quickActions(callback?: (err: Error, info: any) => void): Promise<any>;
|
||||
recent(callback?: (err: Error, ret: RecordResult) => void): Promise<RecordResult>;
|
||||
select<T>(field?: Object | string[] | string, callback?: (err: Error, ret: T[]) => void): Query<T[]>;
|
||||
select(callback?: (err: Error, ret: T[]) => void): Promise<T[]>;
|
||||
//TODO:use a typed pluck to turn `fields` into a subset of T's fields so that the output is slimmed down appropriately
|
||||
select(fields?: (keyof T)[] | (keyof T), callback?: (err: Error, ret: Partial<T>[]) => void): Promise<Partial<T>[]>;
|
||||
}
|
||||
|
||||
export interface ApprovalLayoutInfo {
|
||||
approvalLayouts: Object[];
|
||||
}
|
||||
|
||||
export class Record extends Object {
|
||||
constructor(connection: Connection, type: SObject, id: SalesforceId)
|
||||
}
|
||||
|
||||
export class Batch extends stream.Writable {
|
||||
}
|
||||
|
||||
@@ -86,7 +85,20 @@ export interface LayoutInfo {
|
||||
}
|
||||
|
||||
export class ListView {
|
||||
constructor(connection: Connection, type: SObject, id: SalesforceId)
|
||||
constructor(connection: Connection, type: string, id: SalesforceId)
|
||||
}
|
||||
|
||||
export interface BatchInfo {
|
||||
id: string;
|
||||
jobId: string;
|
||||
state: string;
|
||||
stateMessage: string;
|
||||
}
|
||||
|
||||
export interface BatchResultInfo {
|
||||
id: string;
|
||||
batchId: string;
|
||||
jobId: string;
|
||||
}
|
||||
|
||||
export class ListViewsInfo { }
|
||||
|
||||
Reference in New Issue
Block a user