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

HPC-8569 get table columns function #187

Merged
merged 2 commits into from
Nov 20, 2024
Merged

Conversation

manelcecs
Copy link
Contributor

No description provided.

@manelcecs manelcecs added the ready for review All comments have been addressed, and the Pull Request is ready for review label Nov 14, 2024
@manelcecs manelcecs requested a review from a team as a code owner November 14, 2024 08:52
@manelcecs manelcecs force-pushed the HPC-8569-getTableColumns branch 3 times, most recently from 83166cb to db37aee Compare November 19, 2024 09:03
Copy link
Contributor

@Delgee Delgee left a comment

Choose a reason for hiding this comment

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

Since getTableColumns is runtime version of

export type InstanceDataOf<F extends FieldDefinition> = FieldValuesOfSet<

can we do it similar fashion instead of looping through every child.

@Delgee Delgee assigned manelcecs and unassigned Delgee Nov 20, 2024
@Delgee Delgee added needs minor changes There are review or issue comments to address and removed ready for review All comments have been addressed, and the Pull Request is ready for review labels Nov 20, 2024
@manelcecs
Copy link
Contributor Author

Since getTableColumns is runtime version of

export type InstanceDataOf<F extends FieldDefinition> = FieldValuesOfSet<

can we do it similar fashion instead of looping through every child.

Would this code be a better approach?

export const getTableColumns = <
  T extends { _internals: { fields: FieldDefinition } },
>(
  table: T
): string[] => {
  const {
    generated,
    generatedCompositeKey,
    nonNullWithDefault,
    required,
    optional,
    accidentallyOptional,
  } = table._internals.fields;

  // Collect columns from all subsets
  const columns = [
    ...Object.keys(generated ?? {}),
    ...Object.keys(generatedCompositeKey ?? {}),
    ...Object.keys(nonNullWithDefault ?? {}),
    ...Object.keys(required ?? {}),
    ...Object.keys(optional ?? {}),
    ...Object.keys(accidentallyOptional ?? {}),
  ];

  return columns;
};

@Delgee
Copy link
Contributor

Delgee commented Nov 20, 2024

I believe so.

@manelcecs manelcecs force-pushed the HPC-8569-getTableColumns branch from db37aee to e8f149a Compare November 20, 2024 11:30
@manelcecs manelcecs assigned Delgee and unassigned manelcecs Nov 20, 2024
@manelcecs manelcecs added ready for review All comments have been addressed, and the Pull Request is ready for review and removed needs minor changes There are review or issue comments to address labels Nov 20, 2024
@manelcecs manelcecs merged commit 61da672 into develop Nov 20, 2024
2 checks passed
@manelcecs manelcecs deleted the HPC-8569-getTableColumns branch November 20, 2024 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review All comments have been addressed, and the Pull Request is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants