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

feat: improve metadata value types #194

Merged
merged 1 commit into from
Jan 18, 2024

Conversation

davidlj95
Copy link
Owner

@davidlj95 davidlj95 commented Jan 17, 2024

In the metadata set by route + service E2E test, the code to use the MetadataService was a bit awkward in the types sense. We had to cast to unknown and then to MetadataValues. Not a great DX

Rethinking the types referring to metadata values and their usages to provide as good DX as we can

Changes:

This allows to:

  • Use module XMetadata & X types to declare type safe metadata values. Like OpenGraphMetadata & OpenGraph.
  • Add MetadataRouteData<OpenGraphMetadata & TwitterCardMetadata> to ensure route data is properly typed. Either when declaring a var type or using satisfies.
  • All interfaces accept broad MetadataValues / object, so it's open for extension but closed for modification. Consumers can specify a stricter type if they want to ensure types are ok or the IDE to help them write them.

This doesn't allow to:

Copy link
Owner Author

Current dependencies on/for this PR:

This stack of pull requests is managed by Graphite.

@davidlj95 davidlj95 force-pushed the stacked/feat-improve-metadata-value-types branch 2 times, most recently from 80fd0da to 5f35752 Compare January 18, 2024 00:20
Copy link

github-actions bot commented Jan 18, 2024

📦 Bundle size (Angular v15)

Git ref: 8508c47

Module file Size Base size Difference
ngx-meta-core.mjs 3430 bytes (3.4KiB) 3430 bytes (3.4KiB) No change
ngx-meta-json-ld.mjs 402 bytes (402B) 402 bytes (402B) No change
ngx-meta-open-graph-profile.mjs 428 bytes (428B) 428 bytes (428B) No change
ngx-meta-open-graph.mjs 833 bytes (833B) 833 bytes (833B) No change
ngx-meta-routing.mjs 897 bytes (897B) 897 bytes (897B) No change
ngx-meta-standard.mjs 940 bytes (940B) 940 bytes (940B) No change
ngx-meta-twitter-card.mjs 675 bytes (675B) 675 bytes (675B) No change
Total 7605 bytes (7.5KiB) 7605 bytes (7.5KiB) No change

Copy link

github-actions bot commented Jan 18, 2024

📦 Bundle size (Angular v16)

Git ref: 8508c47

Module file Size Base size Difference
ngx-meta-core.mjs 3420 bytes (3.4KiB) Not available Not available
ngx-meta-json-ld.mjs 402 bytes (402B) Not available Not available
ngx-meta-open-graph-profile.mjs 428 bytes (428B) Not available Not available
ngx-meta-open-graph.mjs 833 bytes (833B) Not available Not available
ngx-meta-routing.mjs 897 bytes (897B) Not available Not available
ngx-meta-standard.mjs 940 bytes (940B) Not available Not available
ngx-meta-twitter-card.mjs 675 bytes (675B) Not available Not available
Total 7595 bytes (7.5KiB) Not available Not available

Base size data is not available yet. Try again when the CI/CD has finished running on main branch

Copy link

github-actions bot commented Jan 18, 2024

📦 Bundle size (Angular v17)

Git ref: 8508c47

Module file Size Base size Difference
ngx-meta-core.mjs 3163 bytes (3.1KiB) 3163 bytes (3.1KiB) No change
ngx-meta-json-ld.mjs 236 bytes (236B) 236 bytes (236B) No change
ngx-meta-open-graph-profile.mjs 302 bytes (302B) 302 bytes (302B) No change
ngx-meta-open-graph.mjs 670 bytes (670B) 670 bytes (670B) No change
ngx-meta-routing.mjs 725 bytes (725B) 725 bytes (725B) No change
ngx-meta-standard.mjs 829 bytes (829B) 829 bytes (829B) No change
ngx-meta-twitter-card.mjs 515 bytes (515B) 515 bytes (515B) No change
Total 6440 bytes (6.3KiB) 6440 bytes (6.3KiB) No change

@davidlj95 davidlj95 force-pushed the stacked/feat-improve-metadata-value-types branch from 5f35752 to 8508c47 Compare January 18, 2024 00:45
Comment on lines -1 to -3
export interface MetadataValues {
[key: string]: unknown
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

This was giving issues, as it's a specific type of object. An object that implements an interface without index signature wouldn't comply with this. Despite yet being valid metadata values. So going for a broader definition


export type MetadataRouteStrategy = <T>(
Copy link
Owner Author

Choose a reason for hiding this comment

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

Doesn't make sense to specify type here, given the strategy should load some object from route, without caring what the object contains. It's not its responsibility

@davidlj95 davidlj95 merged commit 7b36ef5 into main Jan 18, 2024
12 checks passed
@davidlj95 davidlj95 deleted the stacked/feat-improve-metadata-value-types branch January 18, 2024 00:47
Copy link

🎉 This PR is included in version 1.0.0-alpha.31 🎉

The release is available on:

Your semantic-release bot 📦🚀

@davidlj95 davidlj95 linked an issue Jan 19, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export non-routing types too
1 participant