npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@forcetrails/sobject-types

v0.3.0

Published

SObject and Field Types for Lightning Web Components TypeScript or JSDOC, to enable Type Safety and Intellisense

Downloads

10

Readme

@forcetrails/sobject-types

Overview

The @forcetrails/sobject-types Tool is a command-line utility built to automate the generation of TypeScript definition files (.ts) for Salesforce objects. These definition files are crucial for projects containing TypeScript LWC components or LWC components with JSDocs, providing type safety and autocompletion support.

The tool fetches metadata for specified Salesforce objects, extracts fields and their corresponding data types, and generates TypeScript interfaces that mirror the structure of these Salesforce objects.

Prerequisites

Before installing and using the tool, ensure you have the following prerequisites:

  • Node.js (version >= 12.0.0)
  • npm (Node Package Manager)
  • Salesforce CLI installed and authenticated with at least one Salesforce organization. Install Salesforce CLI from here.

Installation

1. Install using npm

npm i @forcetrails/sobject-types

2. Configure Salesforce Connection:

Update the ./ftypes/ftypesc.json file with your Salesforce credentials and desired configuration (e.g., Salesforce objects to generate .ts files for, output directory).

3. Run the command

npx ftypes

4. Update TypeScript Config (Required if you are using TypeScript LWC Components)

  • Update the tsconfig.json to include the output folder i.e. ./ftypes by default to add paths for @sobject-types.
{
  "compilerOptions": {
    // ...
    "paths": {
      "@sobject-types/*": ["./.ftypes/typings/*"]
    }
  }
  // ... other config.
}

5. Start Using Types - TypeScript (Required if you are using TypeScript LWC Components)

// 1. -----> import type
import { Account } from '@sobject-types/Index';

import { LightningElement, api } from 'lwc';

export default class TodoItem extends LightningElement {
  // 2. -----> use type
  account: Account = {
    ChildAccounts: [],
    CleanStatus: 'NotFound',
    Type: 'Channel Partner / Reseller',
    Industry: '',
    Ownership: 'Other',
    Rating: 'Cold',
  };
}

6. Start Using Types - JavaScript & JSDoc

// 1. -----> Import the type
/**
 * @typedef {import('./.ftypes/typings/Index.ts').Account} Account
 */
import { LightningElement, api } from 'lwc';
export default class TodoItem extends LightningElement {
  // 2. -----> Use the Type
  /**
   * @type Account
   */
  account = {
    ChildAccounts: [],
    CleanStatus: 'NotFound',
    Type: 'Channel Partner / Reseller',
    Industry: '',
    Ownership: 'Other',
    Rating: 'Cold',
  };
}

Usage

Commands

  • ftypes init Initialize the ftypes configuration
  • ftypes list List all sObjects from config file
  • ftypes config Show config contents
  • ftypes set-target-org <orgname> Set the default Salesforce organization username in ./ftypes/ftypesc.json. **This is alias of already authenticated Salesforce org from sf auth
  • ftypes add <objname> Add type definitions for a specific object
  • ftypes refresh <objname...> Add type definitions for a specific object(s)
  • ftypes Generate Typings for all SObjects from config

Examples

1. Init ftypes project with default configuration:

ftypes init

This command creates .ftypes file in the current work directory and adds default configuration for types generation

2. Generate .ts file for all objects mentioned config:

ftypes

3. Add Object a specific to configuration and generate types:

ftypes add Account

This command adds Account object to config list and generates Types for account object

4. Refresh typings of existing Object:

ftypes refresh Account

This command regenerates Account.ts in the specified output directory.

5. List all configured Salesforce objects:

ftypes list

Lists all Salesforce objects configured in config file(./ftypes/ftypesc.json).

6. Set default Salesforce organization username:

ftypes set-target-org my-sf-org

Sets defaultusername in ./ftypes/ftypesc.json to my-sf-org in your sfdx project.

7. Display contents of (./ftypes/ftypesc.json):

ftypes configs

Displays the contents of the configuration file (./ftypes/ftypesc.json).

More features coming soon...