Skip to content

Instantly share code, notes, and snippets.

@cjdell
Created December 9, 2016 12:13
Show Gist options
  • Save cjdell/35c69fea2125cacfd5172f4e23de7b0e to your computer and use it in GitHub Desktop.
Save cjdell/35c69fea2125cacfd5172f4e23de7b0e to your computer and use it in GitHub Desktop.
/**
* Could eventually be added to TSD, or to jsforce package root...
*/
declare module "jsforce" {
type Partial<T> = {
[P in keyof T]?: T[P];
};
class Connection {
constructor({ loginUrl: string});
login(username: string, password: string, callback: (err: Error, userInfo: UserInfo) => void);
query(soql: string, callback: (err: Error, ret: QueryResponse) => void);
sobject(type: 'Account'): SObjectCollection<Account>;
sobject(type: 'Opportunity'): SObjectCollection<Opportunity>;
sobject(type: 'Contact'): SObjectCollection<Contact>;
}
interface UserInfo {
id: string;
organizationId: string;
url: string;
}
interface SObjectCollection<T> {
retrieve(id: string, callback: (err: Error, ret: T & RetrieveResponseExtra) => void);
retrieve(id: string[], callback: (err: Error, ret: (T & RetrieveResponseExtra)[]) => void);
insert(record: Partial<T>, callback: (err: Error, ret: InsertResponse) => void);
update(record: Partial<T>, callback: (err: Error, ret: UpdateResponse) => void);
upsert(record: Partial<T>, extIdField: string, callback: (err: Error, ret: UpsertResponse) => void);
}
interface QueryResponse {
records: SObject[];
}
interface SObject {
Id: string;
}
interface Account extends SObject {
Name: string;
Phone: string;
// ...
}
interface Opportunity extends SObject {
Name: string;
StageName: string;
CloseDate: string;
// ...
}
interface Contact extends SObject {
FirstName: string;
MiddleName: string;
LastName: string;
Email: string;
// ...
}
interface RetrieveResponseExtra {
attributes: Attributes;
}
interface Attributes {
type: string;
url: string;
}
interface InsertResponse {
id: string;
}
interface UpdateResponse {
}
interface UpsertResponse {
/**
* Id only returned if a new record is created
*/
id?: string;
}
export {
Partial,
Connection,
Account,
Opportunity,
Contact
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment