Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ChuckJonas
Last active February 13, 2020 23:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChuckJonas/73b7e1113c70bcdc49eccbe22f3109f2 to your computer and use it in GitHub Desktop.
Save ChuckJonas/73b7e1113c70bcdc49eccbe22f3109f2 to your computer and use it in GitHub Desktop.
ts-force redesign

interfaces

interface SObject{
  id: string;
  name: string;
  // everything else optional
}

interface ServiceFactory<T extends SObject> {
  newService(connection: Auth): SObjectService<T>
}

interface SObjectService<T extends SObject> {

  buildSOQL: (func: (fieldResolver : FieldResolver<T> => SOQLQueryParams)): SOQLQuery
  query(qry: SOQLQuery<T> | string)

  create(obj: T): T
  update(obj: T): T
  delete(id: string)
}

interface Mapper<T extend SObject> {
  toSalesforceObject(obj: T)
  fromSalesforceObject(sfObj: any): T
}

example

Improvements over OG ts-force

  • Operates on serializable POJO
  • Immutable
  • better/more standard exception handling
  • more functional

Concepts carried over:

  • Mapping of API names to standard javascript notation
  • typed query building (FieldResolver)
  • transforms values to make it easier to work with -- Maps picklists to string[] -- Maps Date (only) strings object {d: integer, m: integer, y: integer}
  • Abstracts complexities of working with API -- Composite, CompositeCollection, CompositeBatch, Invokable, Custom endpoints, etc
  • Ability to use mapping with custom endpoints
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment