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

implement Fonts service #416

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

implement Fonts service #416

wants to merge 5 commits into from

Conversation

andrewharvey
Copy link
Collaborator

https://docs.mapbox.com/api/maps/fonts/

getFontGlyphRange still exists in Styles, which I suggest we do for backwards compatibility. However this means this method is now duplicate in the code base. So we can either:

  • leave this duplicated, existing in both Fonts and Styles services
  • omit it from the Fonts service
  • mark as deprecated in Styles service, leaving duplicated code, but giving a path for future removal.

@andrewharvey
Copy link
Collaborator Author

  • I found in some cases I needed to pass fresh=true to listFonts, though at the moment I'm not sure if that forces the cache bypass, or I was just lucky that a new URL resulted in a cache miss and retrieved the latest font list. Needs more testing to understand if this query parameter is actually interpreted.

@andrewharvey
Copy link
Collaborator Author

By the way, I needed this for https://gist.github.com/andrewharvey/ff5e2c15b8a60249a593dc189192eb02 which reports

  • fonts used within an account
  • which fonts each Style is using
  • which Styles are using each font (useful for knowing which fonts you can clear out of your account to keep under the 100 fonts limit)
  • which fonts Styles are using that aren't in your account (or standard Mapbox fonts) - useful if you've accidentally deleted a font from your account that was in use

@andrewharvey
Copy link
Collaborator Author

@katydecorah interested in reviewing?

@katydecorah
Copy link
Contributor

👋 @andrewharvey I shared this PR with the team that works on Fonts API and they'll have someone take a look (hopefully this week)!

Copy link

@jseppi jseppi left a comment

Choose a reason for hiding this comment

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

Thanks for this contribution, @andrewharvey! The one bug I found during review is that the verb used in the putFont method should be POST. The rest of my comments are suggestions around consistency and usability.

Also, I see that there's an existing font method in the styles client: Styles.getFontGlyphRange -- would you mind deleting that one and the associated tests since this PR puts that method in a more appropriate place?

services/fonts.js Outdated Show resolved Hide resolved
bundle.js Outdated Show resolved Hide resolved
* const newFont = response.body;
* });
*/
Fonts.putFont = function(config) {
Copy link

Choose a reason for hiding this comment

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

For consistency with how this method is documented in our public docs, could you rename the method to addFont? https://docs.mapbox.com/api/maps/fonts/#add-a-font

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In docs/development.md it says to use "create" for POST requests, do you think it should still be addFont or createFont?

Copy link

Choose a reason for hiding this comment

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

👍 createFont is a good suggestion for consistency

services/fonts.js Outdated Show resolved Hide resolved
services/__tests__/fonts.test.js Outdated Show resolved Hide resolved
Comment on lines +43 to +44
start: v.required(v.number),
end: v.required(v.number),
Copy link

Choose a reason for hiding this comment

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

Since we know that end is always start + 255, we could make this method a little more ergonomic by only requiring the start parameter. Then, we'd just add 255 to it to come up with the correct fileName:

var fileName = config.start + '-' + (config.start + 255) + '.pbf';

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Must end always equal start+255 or could users still request a larger slice?

Copy link

Choose a reason for hiding this comment

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

Yup, end must always be start + 255

Fonts.updateFontMetadata = function(config) {
v.assertShape({
font: v.required(v.string),
visibility: v.required.oneOf(['public', 'private']),
Copy link

Choose a reason for hiding this comment

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

Ah, sorry I got the syntax wrong in my review suggestion, @andrewharvey, which is why tests are failing. Should be:

v.required(v.oneOf(['public', 'private']))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants