Conversation
|
Pinging @elastic/kibana-app-arch (Team:AppArch) |
lukeelmers
left a comment
There was a problem hiding this comment.
Since we are composing the static utils namespaces as objects now, I wonder if the static.ts file convention is even useful anymore?
Plus, what if we have a situation where there are items that need to live in a namespace that don't live in a common directory? It's possible for other services we may have utils that, for example, rely on specific browser APIs that would only be exported under the namespace from public.
I think what I'd propose in this case is simply building the namespace from the public/index and server/index files. This has a few benefits:
- Lets you combine utils from common and public/server, solving the issue described above
- It's one less level of indirection
- When you look at the index file you will immediately see everything that's publicly exported, less confusion over what is/isn't public.
Would look something like this:
// data/public/index.ts
import { FieldFormat, BytesFormat, ColorFormat, etc } from '../common';
import { BrowserThing } from './field_formats';
// types
export {
FieldFormatsGetConfigFn,
FieldFormatConfig,
FieldFormatsRegistry,
...etc
} from '../common/types';
// utils
export const fieldFormats = {
FieldFormat,
BytesFormat,
ColorFormat,
BrowserThing,
...etc
};| /** | ||
| * Everything the file exports is public | ||
| */ |
There was a problem hiding this comment.
Removing this implies that this file now exports some things that are internal - is that the case?
There was a problem hiding this comment.
Well, it exports just one thing, and we don't import * from it anymore.
So I found the comment irrelevant.
There was a problem hiding this comment.
My overall vote would be to consider the direction I mentioned about composing these objects directly in the public/index and server/index files, in which case it doesn't matter.
That said, if we were to keep this implementation with static.ts I would think it would be important to identify somewhere in the file that this entire namespace is exported publicly, so you don't run the risk of someone adding something internal here accidentally.
There was a problem hiding this comment.
@lukeelmers I update the PR to constructing the namespace in public\server index.ts.
src/plugins/data/server/index.ts
Outdated
| // fieldFormats | ||
| fieldFormats, | ||
| FieldFormatsGetConfigFn, | ||
| FieldFormatConfig, | ||
| FieldFormatsRegistry, |
There was a problem hiding this comment.
Currently (in both public/index and server/index) we have static exports separated from type exports. To avoid confusion maybe we should stick the namespace with the static exports for the time being?
Once we move everything over to this structure, it should be more intuitive whether something is static or a type, but in the interim it may help make things clearer.
There was a problem hiding this comment.
This transition shouldn't take more than a few days, so I don't think it's worth leaving it for later.
What do you think?
There was a problem hiding this comment.
If we're planning to make the transition right away, and you think it's only a couple days, then I have no concerns about keeping it as-is. I only brought it up in the event that the data plugin might sit like this for awhile before we come back to clean up the rest.
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
|
@elasticmachine merge upstream |
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
markov00
left a comment
There was a problem hiding this comment.
Changes in kibana-app owned files LGTM
* Field Formats namespace * Export IFieldFormatsRegistry and FieldFormatsRegistry separately. * remove field_formats export from data plugin and adjust lens test * Updated doc return types * Cleanup fieldFormat namespace and define it index.ts Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
* Field Formats namespace * Export IFieldFormatsRegistry and FieldFormatsRegistry separately. * remove field_formats export from data plugin and adjust lens test * Updated doc return types * Cleanup fieldFormat namespace and define it index.ts Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Summary
Part of #56881
This PR demonstrates a proposed resolution for #52374, trying to balance code readability, API discoverability, DX and documentation generation using ApiExtractor.
The solution involves:
index.ts, with a prefix (consistent withcore)In this PR I applied this approach to fieldFormats:
fieldFormats.FieldFormat⇒IFieldFormatfieldFormats.FieldFormatsRegistry⇒FieldFormatsRegistryfieldFormats.ContentType⇒FieldFormatsContentType,fieldFormats.GetConfigFn⇒FieldFormatsGetConfigFn,fieldFormats.IFieldFormatConfig⇒FieldFormatConfig,fieldFormats.IFieldFormatId⇒FieldFormatIdOther utilities are available, as before, on the
fieldFormatsnamespace and documentation passes for this sub-service.Checklist
Delete any items that are not applicable to this PR.
For maintainers