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

[7.x] [IngestManager] Move RequiredPackage type near DefaultPackages (#82188) #82654

Merged
merged 1 commit into from
Nov 4, 2020

Conversation

jfsiii
Copy link
Contributor

@jfsiii jfsiii commented Nov 4, 2020

Backports the following commits to 7.x:

## Summary

- [x] Move the `RequiredPackage` type to the same location as `DefaultPackages` so anyone looking at one will see the other as well
- [x] New approach to defining & using enum-like values. 

## The basic outline of the approach 
  1. Export a JS object `as const` from `common/constants/*` (expose runtime value)
    https://github.com/elastic/kibana/blob/d66cf601bb0466bd36254f40339ac41f9935436c/x-pack/plugins/ingest_manager/common/constants/epm.ts#L12-L15
  1. Import that JS value and convert to a TS type as `type TSType = typeof jsValue` 
    <img width="484" alt="Screen Shot 2020-11-02 at 2 12 27 PM" src="https://user-images.githubusercontent.com/57655/97910756-2e693700-1d18-11eb-9605-e33ceb64e857.png"> 
  1. The values (right-hand side) of that type can be converted to a union type with `ValueOf<X>`
    <img width="557" alt="Screen Shot 2020-11-02 at 3 10 22 PM" src="https://user-images.githubusercontent.com/57655/97914250-99693c80-1d1d-11eb-9605-92379aa4db38.png">
  1. The values can be accessed as TS types `TSType['key']` or JS  `jsValue.key`

This way we
  - still get the readability of TS `enum`s
  - can choose to only import the types of values we need (compile time or runtime) 
  - use the TS utility types like `Pick`, `Omit`, etc

## More detail on 1
  * Value which can be access/iterated at runtime, e.g. `Object.values(requiredPackages)` or `requiredPackages.System`
  * narrows the type those exact values, not `string`
    <img width="823" alt="Screen Shot 2020-11-02 at 2 15 58 PM" src="https://user-images.githubusercontent.com/57655/97910538-e0ecca00-1d17-11eb-9153-71171e9fba75.png">
  * can't be modified (it's `readonly`) 
      <img width="443" alt="Screen Shot 2020-11-02 at 2 12 09 PM" src="https://user-images.githubusercontent.com/57655/97910753-2dd0a080-1d18-11eb-82d4-3fe635ba3071.png">
@jfsiii jfsiii added the backport label Nov 4, 2020
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

page load bundle size

id before after diff
ingestManager 385.5KB 385.8KB +293.0B

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@jfsiii jfsiii merged commit b65c5d5 into elastic:7.x Nov 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants