Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: generate typings for sobjects #3018

Merged
merged 10 commits into from
Mar 23, 2021
Merged

Conversation

rcoringrato-sfdc
Copy link
Contributor

@rcoringrato-sfdc rcoringrato-sfdc commented Mar 4, 2021

What does this PR do?

Added type generation to the sobject faux object flow.

What issues does this PR fix or reference?

@W-8912288@

@rcoringrato-sfdc rcoringrato-sfdc requested a review from a team as a code owner March 4, 2021 17:04
import { ChildRelationship, Field, SObject } from '../types';

export const MODIFIER = 'global';
export interface FieldDeclaration {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jag-sfdc The static representation could contain a list of these objects with some additional information. That's sufficient to generate apex and type files.

@codecov
Copy link

codecov bot commented Mar 4, 2021

Codecov Report

Merging #3018 (b019ac3) into develop (2771a47) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #3018   +/-   ##
========================================
  Coverage    76.18%   76.18%           
========================================
  Files          276      276           
  Lines        10502    10502           
  Branches      1234     1234           
========================================
  Hits          8001     8001           
  Misses        2157     2157           
  Partials       344      344           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2771a47...b019ac3. Read the comment docs.

@rcoringrato-sfdc rcoringrato-sfdc marked this pull request as draft March 4, 2021 17:21

const TYPING_PATH = ['typings', 'lwc', 'sobjects2'];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't figured out how to do the transition yet. ALS will collide with this typing generation until it is disabled.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have a "local" variable/setting to gate this being enabled but still allow us to write tests, merge it, etc.


public generateTypingForObject(folderPath: string, sobject: SObject): string {
const typingPath = path.join(folderPath, sobject.name + '.d.ts');
if (fs.existsSync(typingPath)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't needed as fs.writeFileSync overwrites the file if it exists

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was getting a permission error before I added this, probably since the perms were set to readonly when the previous contents were written?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, my definition files have permission 644. Yeah it makes sense to remove first if we are writing with permission 444.

@rcoringrato-sfdc rcoringrato-sfdc marked this pull request as ready for review March 19, 2021 22:03
fs.writeFileSync(fauxClassPath, this.generateFauxClassTextFromDecls(sobject.name, sobject.fields), {
const fauxClassPath = path.join(
standardSObjectsFolderPath,
sobject.name + APEX_CLASS_EXTENSION
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
sobject.name + APEX_CLASS_EXTENSION
`${sobject.name}${APEX_CLASS_EXTENSION}`

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this change directly in GitHub so please check that it does work before merging

comment?: string;
}

export interface SObjectDefinition {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could move this and FieldDeclaration to the types folder

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do,

@lcampos
Copy link
Contributor

lcampos commented Mar 23, 2021

@rcoringrato-sfdc if we merge these changes we'll be creating the lwc typings twice (here and from the Apex lang server). Are we going to add something to disable lwc typings from the faux module while we make the changes to the lang server or are we going to wait for the lang server changes before merging this PR ?

@rcoringrato-sfdc
Copy link
Contributor Author

@lcampos I added a class level flag to disable type declarations by default. As part of the story to add the updated ALS jar this flag should be removed. This should prevent the collision that you referred to. This PR could be committed separate from the ALS changes.

@lcampos
Copy link
Contributor

lcampos commented Mar 23, 2021

@lcampos I added a class level flag to disable type declarations by default. As part of the story to add the updated ALS jar this flag should be removed. This should prevent the collision that you referred to. This PR could be committed separate from the ALS changes.

Sounds good, I totally missed shouldGenerateTypes being used in the faux class generator.

@rcoringrato-sfdc rcoringrato-sfdc merged commit f1b9db6 into develop Mar 23, 2021
@rcoringrato-sfdc rcoringrato-sfdc deleted the rc/sobject-typing branch March 23, 2021 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants