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

[@kbn/config-schema] Improve extends and rename it to intersection #185018

Closed
maryam-saeidi opened this issue Jun 7, 2024 · 4 comments · Fixed by #186269
Closed

[@kbn/config-schema] Improve extends and rename it to intersection #185018

maryam-saeidi opened this issue Jun 7, 2024 · 4 comments · Fixed by #186269
Labels
kbn/config-schema Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc

Comments

@maryam-saeidi
Copy link
Member

maryam-saeidi commented Jun 7, 2024

🍒 Summary

At the moment, for intersection functionality (similar to what we have in io-ts and zod), we can use extends:

const a = schema.object({ a: schema.string() });
const bKeys = { b: schema.string() };
const b = schema.object(bKeys);

//  C = A & B (intersection of A and B)
const c = a.extends(bKeys);

The idea is to extend extends functionality to support multiple inputs (c = a.extends(b, d, e, f, g)) and use the name intersection to match other libraries for easier discoverability. (example usage in Kibana)

@maryam-saeidi maryam-saeidi added the Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc label Jun 7, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-core (Team:Core)

@pgayvallet
Copy link
Contributor

This one may be a hard one, as intersections are not officially supported by joi: hapijs/joi#2495

@pgayvallet
Copy link
Contributor

Actually, it seems supported via Joi.alternatives(...types).match('all')

@pgayvallet
Copy link
Contributor

I don't think extend and intersection types are the exact same thing or should be using the same API "approach"

instead of

c = a.extends(b, d, e, f, g)

I think I'd rather expose a new intersection mixin and do

c = schema.intersection(a, c, d, e, f, g);

right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kbn/config-schema Team:Core Core services & architecture: plugins, logging, config, saved objects, http, ES client, i18n, etc
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants