Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. /**
  2. * Could eventually be added to TSD, or to jsforce package root...
  3. */
  4.  
  5. declare module "jsforce" {
  6. type Partial<T> = {
  7. [P in keyof T]?: T[P];
  8. };
  9.  
  10. class Connection {
  11. constructor({ loginUrl: string});
  12.  
  13. login(username: string, password: string, callback: (err: Error, userInfo: UserInfo) => void);
  14.  
  15. query(soql: string, callback: (err: Error, ret: QueryResponse) => void);
  16.  
  17. sobject(type: 'Account'): SObjectCollection<Account>;
  18. sobject(type: 'Opportunity'): SObjectCollection<Opportunity>;
  19. sobject(type: 'Contact'): SObjectCollection<Contact>;
  20. }
  21.  
  22. interface UserInfo {
  23. id: string;
  24. organizationId: string;
  25. url: string;
  26. }
  27.  
  28. interface SObjectCollection<T> {
  29. retrieve(id: string, callback: (err: Error, ret: T & RetrieveResponseExtra) => void);
  30. retrieve(id: string[], callback: (err: Error, ret: (T & RetrieveResponseExtra)[]) => void);
  31.  
  32. insert(record: Partial<T>, callback: (err: Error, ret: InsertResponse) => void);
  33. update(record: Partial<T>, callback: (err: Error, ret: UpdateResponse) => void);
  34. upsert(record: Partial<T>, extIdField: string, callback: (err: Error, ret: UpsertResponse) => void);
  35. }
  36.  
  37. interface QueryResponse {
  38. records: SObject[];
  39. }
  40.  
  41. interface SObject {
  42. Id: string;
  43. }
  44.  
  45. interface Account extends SObject {
  46. Name: string;
  47. Phone: string;
  48. // ...
  49. }
  50.  
  51. interface Opportunity extends SObject {
  52. Name: string;
  53. StageName: string;
  54. CloseDate: string;
  55. // ...
  56. }
  57.  
  58. interface Contact extends SObject {
  59. FirstName: string;
  60. MiddleName: string;
  61. LastName: string;
  62. Email: string;
  63. // ...
  64. }
  65.  
  66. interface RetrieveResponseExtra {
  67. attributes: Attributes;
  68. }
  69.  
  70. interface Attributes {
  71. type: string;
  72. url: string;
  73. }
  74.  
  75. interface InsertResponse {
  76. id: string;
  77. }
  78.  
  79. interface UpdateResponse {
  80.  
  81. }
  82.  
  83. interface UpsertResponse {
  84. /**
  85. * Id only returned if a new record is created
  86. */
  87. id?: string;
  88. }
  89.  
  90. export {
  91. Partial,
  92. Connection,
  93. Account,
  94. Opportunity,
  95. Contact
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement