0.1.1 • Published 5 years ago

@shingo/describe2ts v0.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

describe2ts

Converts a salesforce DescribeSObjectResult object (typically produced by jsforce) to a salesforce interface

Usage Example

import describe2ts from 'describe2ts'
import { writeFileSync } from 'fs'

// describe files retrieved from somewhere
const describes: DescribeSObjectResult[] = getDescribes()

const nameMatch = ['Contact', 'Account']

// only create interfaces for the objects in the nameMatch array
const resolver = (name: string) =>
  nameMatch.includes(name) ? `import("./${name}").default` : null

// used for determining nillability of child relationships
// this is optional
const sobjectResolver = (name: string) => describes.find(d => d.name === name)

for (const desc of describes) {
  const iface = describe2ts(desc, resolver, sobjectResolver)
  writeFileSync(`${desc.name}.ts`, iface, 'utf8')
}

API

describe2ts

ParameterTypeDescriptionRequired
descDescribeSObjectResulta DescribeSObjectResult object
resolverstring => Option<string> \| string \| null \| undefineda function that resolves the name of a Salesforce Object to a typescript type string
sobjectResolverundefined \| (string => Option<DescribeSObjectResult> \| DescribeSObjectResult \| null \| undefined)an optional function that resolves the name of a Salesforce Object to its DescribeSObjectResult
newtypeundefined \| booleanuse newtypes instead of typescript primitives
sfTypeResolverundefined \| { readonly [k in FieldType]: (f: Field, newtype?: boolean) => string }a map of functions from salesforce types to typescript types
defaultExportundefined \| booleanadd a default export line to the output text