@shingo/describe2ts
TypeScript icon, indicating that this package has built-in type declarations

0.1.1 • Public • Published

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

Parameter Type Description Required
desc DescribeSObjectResult a DescribeSObjectResult object
resolver string => Option<string> | string | null | undefined a function that resolves the name of a Salesforce Object to a typescript type string
sobjectResolver undefined | (string => Option<DescribeSObjectResult> | DescribeSObjectResult | null | undefined) an optional function that resolves the name of a Salesforce Object to its DescribeSObjectResult
newtype undefined | boolean use newtypes instead of typescript primitives
sfTypeResolver undefined | { readonly [k in FieldType]: (f: Field, newtype?: boolean) => string } a map of functions from salesforce types to typescript types
defaultExport undefined | boolean add a default export line to the output text

Package Sidebar

Install

npm i @shingo/describe2ts

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

23.5 kB

Total Files

24

Last publish

Collaborators

  • eric4bell
  • whiteabelincoln