Skip to content

Commit

Permalink
Added Child relations and updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulgawale committed Jun 20, 2024
1 parent 1d7672e commit c3dde4c
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 107 deletions.
10 changes: 10 additions & 0 deletions .changeset/fluffy-sheep-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@forcetrails/sobject-types': minor
---

- Added Support for Child Relationships
- Fixed Picklist Value autocomplete
- Added Index.ts
- Added base interface for SObject
- Fixed code formatting inconsistency
- Updated Readme.md
17 changes: 9 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
name: CI

on:
push:
branches:
- "**"
- '**'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7
- uses: actions/setup-node@v3

- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: "pnpm"
# Optionally, configure npm cache if needed
# cache: "npm"

- run: pnpm install --frozen-lockfile
- run: pnpm run lint && pnpm run build
- run: npm install --frozen-lockfile
- run: npm run build
19 changes: 11 additions & 8 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
name: Publish

on:
workflow_run:
workflows: [CI]
Expand All @@ -17,20 +18,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2
with:
version: 7
- uses: actions/setup-node@v3

# Remove pnpm setup and replace with npm setup
- name: Setup Node.js environment
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: "pnpm"
# Optionally, configure npm cache if needed
# cache: "npm"

- run: npm install --frozen-lockfile

- run: pnpm install --frozen-lockfile
- name: Create Release Pull Request or Publish
id: changesets
uses: changesets/action@v1
with:
publish: pnpm run release
publish: npm run release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"tabWidth": 2,
"useTabs": false,
"singleQuote": false
"singleQuote": true
}
94 changes: 82 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Overview

The `@forcetrails/sobject-types` Tool is a command-line utility built to automate the generation of TypeScript definition files (.d.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 `@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.

Expand All @@ -24,34 +24,99 @@ 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 .d.ts files for, output directory).
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

```bash
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`.

```json
{
"compilerOptions": {
// ...
"paths": {
"@sobject-types/*": ["./.ftypes/typings/*"]
}
}
// ... other config.
}
```

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

```ts
// 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

```js
// 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
- `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:

```bash
ftypes init
```

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

#### 2. Generate `.d.ts` file for all objects mentioned config:
#### 2. Generate `.ts` file for all objects mentioned config:

```bash
ftypes
```
Expand All @@ -61,34 +126,39 @@ ftypes
```bash
ftypes add Account
```

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

#### 4. Refresh typings of existing Object:

```bash
ftypes refresh Account
```
This command regenerates `Account.d.ts` in the specified output directory.

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

### 5. List all configured Salesforce objects:

```bash
ftypes list
```

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

#### 6. Set default Salesforce organization username:

```bash
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`):

```bash
ftypes configs
```

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

More features coming soon...
More features coming soon...
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@forcetrails/sobject-types",
"version": "0.2.0",
"version": "0.3.0",
"description": "SObject and Field Types for Lightning Web Components TypeScript or JSDOC, to enable Type Safety and Intellisense",
"repository": {
"type": "git",
Expand Down Expand Up @@ -39,4 +39,4 @@
"tsup": "^8.1.0",
"typescript": "^5.4.5"
}
}
}
19 changes: 18 additions & 1 deletion src/data/ftypesc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,21 @@ export const config = {
outputDir: "./.ftypes/typings",
defaultusername: "gunguna-dev",
sfdxDir: "../.sfdx/sfdx-config.json"
};
};

export const BaseTypesFileName = 'BaseTypes.ts';
export const BaseTypes = `// base Types class
export interface SObject {
Id?: string;
Name?: string;
CreatedById?: string;
LastModifiedById?: string;
OwnerId?: string;
CreatedDate?: Date | string;
LastModifiedDate?: Date | string;
SystemModstamp?: Date | string;
IsDeleted?: boolean;
[key: string]: any; // Additional fields
}`;

export const IndexFileName = 'Index.ts';
Loading

0 comments on commit c3dde4c

Please sign in to comment.