-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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
[content management / maps] Create abstract types for saved object usage with content management api #154985
[content management / maps] Create abstract types for saved object usage with content management api #154985
Conversation
…om:mattkime/kibana into content_management_api_so_type_abstraction
Pinging @elastic/kibana-data-discovery (Team:DataDiscovery) |
name: string; | ||
} | ||
|
||
export interface CreateOptions { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it is a good idea to lock the same Options
interface for all content type. The idea was to allow each content to pass different options to the storage layer and type those interface + add a schema for them.
Maybe you are right that all call to create/update/delete/search will have the exact same options object but from where I am standing I can't make such a call. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is specifically aimed at Content Management items backed by Saved Objects. I'm familiar with the Saved Objects api and I don't see a benefit to creating specific Option types for CRUD operations. As best I can tell, only the plugin owner of a particular type should be using the CM api, the plugin can provide whatever API it wants.
This intends to be more of a starting point for consolidating Options rather than what should definitely work for everything. Perhaps we'll find a need to extend the Options and can do so at that time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me see if I understand correctly.
I only added the references
prop to create because that's the only SavedObjectCreateOptions
that map uses. They are more fields in that interface but "map" does not use them so I limited the interface.
Here you are making this decision generic for all SO CM types..
Now if "lens" needs another option to be passed we will allow all other types to provide that other option, even though it is not related to they need and it does not do anything.
It seems to me that we are back in tying different content together and it might be hard to make evolve interfaces with time and version them separately.
- How will we know if we need to up/down transform an option object?
- How will you provide a different validation schema if "lens" need to pass this options object:
{ myLensOptionField: true, references: ['123'] }
. Will now all CM types have to up/down transform this specificmyLensOptionField
, what will be the code line documentation for that "specific to lens" option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you are making this decision generic for all SO CM types..
If you'd like, we could provide functionality to extend the Option types.
How will we know if we need to up/down transform an option object?
I've ignored that since we don't yet know how the Saved Object versioning will work, but perhaps it can be considered separately.
Should we consider Options versioning a necessary part of the current content management api? If so, I can revise this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not have any well defined "options" across all CM types. If there is some field that would be useful for all CM types, it should not be an option, but built into the CM CRUD API directly.
Options should ideally never be used, they are an escape hatch, that can be utilised when some type has some extra behavior that does not fill well into the starndartized CM CURD API.
Having said that, I don't think any database related concern should be standartized in the CM layer. For example, references are a database concern (some database have them, some don't, some content types use them, some don't), the CM system should not know anything about the Saved Object references.
Also, with regards to TypeScript types: in CM plugin and packages there should be no types that deal with SavedObjects, i.e. all names that contain *SO*
, savedObject*
, etc.. do not belong to CM code. Those should be handled on the content provider level.
For example, if AX group thinks it is useful for their content types to standartize some "options" or SO functionality, you are free to do that, but that code should live outside of CM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want it to be unique to each content.
I understand what you're saying, but as someone considering how I'd apply the Content Management API to a number of saved objects, it doesn't make sense.
Why don't we want to reuse code in this circumstance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Applying what I learned from the Maps implementation to the Data Views implementation was a big copy and paste project.
What I'm saying if you feel like you want to standartize "options" across your types, that is all good. But that standartized code should not live in CM, it could be some "AX storage helpers" code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in a new content-management-utils
package - is that good?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in a new
content-management-utils
package - is that good?
Yes, if that package is not expected to be owned by SharedUx.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should clarify, I'm fine defaulting options to an empty object although I'd still want to provide something more detailed that a dev could easily grab.
I think we should find some time to talk. Its unclear why some decisions have been made regarding the CM api and I'd like clarity before I continue work on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks good. I just have some concerns about having a single Option interface for all the CM types and how BWC will be handle for those.
Maybe I am being overly cautious, I'd like to hear other people thoughts on this. 👍
references?: Reference[]; | ||
} | ||
|
||
export type GetResultSO<Item extends object> = GetResult< |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we keep the same generic name and default? It makes it easier to follow IMO
export type GetResultSO<T extends unknown> = GetResult<T, ...>
I moved the option types outside of the main interface as to make them easier to modify. I've taken a guess at which options are most likely to be used. We can encourage devs to only use the option attrs they need. I think it might make more sense if the arguments for a given method call were treated as a single item for upgrade / downgrade purposes. Treating them separately means being unable to alter one based on the content of the other. While its possible that we may never come across a case where its necessary, it would be better to have the option. Its clear that CM needs to be able to do versioning transforms even if the SO api does some of the work. After all, other persistence layers might not take responsibility for this. Next I'd like to put together a PR that focuses on code rather than types, providing necessary separation of concerns and BWCA logic. Hopefully we're better aligned based on the recent changes in this PR and my statements above. |
…om:mattkime/kibana into content_management_api_so_type_abstraction
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Having the possibility to make the options evolve independently from one SO type to another looks much better. thanks 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kibana-gis changes LGTM
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Any counts in public APIs
Async chunks
Page load bundle
Unknown metric groupsAPI count
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @mattkime |
…abstraction (#155342) ## Summary Abstract schema definitions for using Saved Objects with the content management api. For most schema types, this will reduce creation to only the attributes specific to a saved object. For Option types (create options, update options, search options) the saved object api is more complex and its likely that most SO types will only need to use a portion of it. In these cases we recommend using the provided schema definitions as a pattern for creating simpler schemas. Follow up to - #154985 - expresses types in schema form --------- Co-authored-by: kibanamachine <[email protected]>
Summary
Abstract types for using Saved Objects with the content management api. This should significantly reduce the amount of code to use additional saved object types.