diff --git a/fixtures/ogc-api/sample-data/collections/airports/styles/Tritanopia/metadata.json b/fixtures/ogc-api/sample-data/collections/airports/styles/Tritanopia/metadata.json index 08fc6ed..ed1b35d 100644 --- a/fixtures/ogc-api/sample-data/collections/airports/styles/Tritanopia/metadata.json +++ b/fixtures/ogc-api/sample-data/collections/airports/styles/Tritanopia/metadata.json @@ -1,39 +1,45 @@ { - "title" : "Tritanopia", - "links" : [ { - "rel" : "self", - "type" : "application/json", - "title" : "This document", - "href" : "https://my.server.org/sample-data/collections/airports/styles/Tritanopia/metadata?f=json" - }, { - "rel" : "alternate", - "type" : "text/html", - "title" : "This document as HTML", - "href" : "https://my.server.org/sample-data/collections/airports/styles/Tritanopia/metadata?f=html" - } ], - "id" : "Tritanopia", - "scope" : "style", - "stylesheets" : [ { - "title" : "QGIS", - "version" : "3.16", - "specification" : "https://docs.qgis.org/3.16/en/docs/user_manual/appendices/qgis_file_formats.html#qml-the-qgis-style-file-format", - "native" : true, - "link" : { - "rel" : "stylesheet", - "type" : "application/vnd.qgis.qml", - "title" : "Style in format 'QGIS'", - "href" : "https://my.server.org/sample-data/collections/airports/styles/Tritanopia?f=qml" + "title": "Tritanopia", + "links": [ + { + "rel": "self", + "type": "application/json", + "title": "This document", + "href": "https://my.server.org/sample-data/collections/airports/styles/Tritanopia/metadata?f=json" + }, + { + "rel": "alternate", + "type": "text/html", + "title": "This document as HTML", + "href": "https://my.server.org/sample-data/collections/airports/styles/Tritanopia/metadata?f=html" } - }, { - "title" : "SLD 1.0", - "version" : "1.0", - "specification" : "https://www.ogc.org/standards/sld", - "native" : true, - "link" : { - "rel" : "stylesheet", - "type" : "application/vnd.ogc.sld+xml;version=1.0", - "title" : "Style in format 'SLD 1.0'", - "href" : "https://my.server.org/sample-data/collections/airports/styles/Tritanopia?f=sld10" + ], + "id": "Tritanopia", + "scope": "style", + "stylesheets": [ + { + "title": "QGIS", + "version": "3.16", + "specification": "https://docs.qgis.org/3.16/en/docs/user_manual/appendices/qgis_file_formats.html#qml-the-qgis-style-file-format", + "native": true, + "link": { + "rel": "stylesheet", + "type": "application/vnd.qgis.qml", + "title": "Style in format 'QGIS'", + "href": "https://my.server.org/sample-data/collections/airports/styles/Tritanopia?f=qml" + } + }, + { + "title": "SLD 1.0", + "version": "1.0", + "specification": "https://www.ogc.org/standards/sld", + "native": true, + "link": { + "rel": "stylesheet", + "type": "application/vnd.ogc.sld+xml;version=1.0", + "title": "Style in format 'SLD 1.0'", + "href": "https://my.server.org/sample-data/collections/airports/styles/Tritanopia?f=sld10" + } } - } ] -} \ No newline at end of file + ] +} diff --git a/src/ogc-api/endpoint.spec.ts b/src/ogc-api/endpoint.spec.ts index 7cc68f6..a30cc5a 100644 --- a/src/ogc-api/endpoint.spec.ts +++ b/src/ogc-api/endpoint.spec.ts @@ -2042,7 +2042,8 @@ The document at http://local/nonexisting?f=json could not be fetched.` 'application/vnd.qgis.qml', 'application/vnd.ogc.sld+xml;version=1.0', 'application/vnd.mapbox.style+json', - ], }, + ], + }, { title: 'Tritanopia', id: 'Tritanopia', @@ -2054,9 +2055,7 @@ The document at http://local/nonexisting?f=json could not be fetched.` { title: 'OS Open Zoomstack - Outdoor with Hillshade', id: 'OutdoorHillshade', - formats: [ - 'application/vnd.mapbox.style+json', - ], + formats: ['application/vnd.mapbox.style+json'], }, ]); }); @@ -2087,19 +2086,22 @@ The document at http://local/nonexisting?f=json could not be fetched.` }); describe('#getStyle for a given collection', () => { it('returns style metadata', async () => { - await expect(endpoint.getStyle('Tritanopia', 'airports')).resolves.toEqual({ + await expect( + endpoint.getStyle('Tritanopia', 'airports') + ).resolves.toEqual({ title: 'Tritanopia', id: 'Tritanopia', scope: 'style', stylesheetFormats: [ 'application/vnd.qgis.qml', - 'application/vnd.ogc.sld+xml;version=1.0' + 'application/vnd.ogc.sld+xml;version=1.0', ], stylesheets: [ { title: 'QGIS', version: '3.16', - specification: 'https://docs.qgis.org/3.16/en/docs/user_manual/appendices/qgis_file_formats.html#qml-the-qgis-style-file-format', + specification: + 'https://docs.qgis.org/3.16/en/docs/user_manual/appendices/qgis_file_formats.html#qml-the-qgis-style-file-format', native: true, link: { rel: 'stylesheet', @@ -2135,15 +2137,17 @@ The document at http://local/nonexisting?f=json could not be fetched.` it('returns the correct stylesheet URL', async () => { await expect( endpoint.getStylesheetUrl('Road', 'application/vnd.mapbox.style+json') - ).resolves.toEqual( - 'http://local/zoomstack/styles/Road?f=mbs' - ); + ).resolves.toEqual('http://local/zoomstack/styles/Road?f=mbs'); }); }); describe('#getStylesheetUrl for a given collection', () => { it('returns the correct stylesheet URL', async () => { await expect( - endpoint.getStylesheetUrl('Tritanopia', 'application/vnd.ogc.sld+xml;version=1.0', 'airports') + endpoint.getStylesheetUrl( + 'Tritanopia', + 'application/vnd.ogc.sld+xml;version=1.0', + 'airports' + ) ).resolves.toEqual( 'https://my.server.org/sample-data/collections/airports/styles/Tritanopia?f=sld10' ); diff --git a/src/ogc-api/endpoint.ts b/src/ogc-api/endpoint.ts index 7bd1cf6..58a425e 100644 --- a/src/ogc-api/endpoint.ts +++ b/src/ogc-api/endpoint.ts @@ -274,7 +274,9 @@ ${e.message}`); styleId: string, collectionId?: string ): Promise { - const doc = collectionId ? await this.getCollectionDocument(collectionId) : await this.root; + const doc = collectionId + ? await this.getCollectionDocument(collectionId) + : await this.root; const stylesLinkJson = getLinkUrl( doc as OgcApiDocument, ['styles', 'http://www.opengis.net/def/rel/ogc/1.0/styles'], @@ -286,7 +288,9 @@ ${e.message}`); ['styles', 'http://www.opengis.net/def/rel/ogc/1.0/styles'], this.baseUrl ); - const styleData = await fetchDocument(stylesLinkJson ?? stylesLink) as OgcApiStylesDocument; + const styleData = (await fetchDocument( + stylesLinkJson ?? stylesLink + )) as OgcApiStylesDocument; if (!styleData.styles.some((style) => style.id === styleId)) { throw new EndpointError(`Style not found: "${styleId}".`); @@ -617,7 +621,9 @@ ${e.message}`); * @param collectionId - Optional unique identifier for the collection. */ async allStyles(collectionId?: string): Promise { - const doc = collectionId ? await this.getCollectionDocument(collectionId) : await this.root; + const doc = collectionId + ? await this.getCollectionDocument(collectionId) + : await this.root; const stylesLink = getLinkUrl( doc as OgcApiDocument, ['styles', 'http://www.opengis.net/def/rel/ogc/1.0/styles'], @@ -628,7 +634,7 @@ ${e.message}`); 'Could not get styles: there is no relation of type "styles"' ); } - const styleData = await fetchDocument(stylesLink) as OgcApiStylesDocument; + const styleData = (await fetchDocument(stylesLink)) as OgcApiStylesDocument; return styleData.styles.map(parseBasicStyleInfo); } @@ -638,8 +644,14 @@ ${e.message}`); * @param styleId - The style identifier * @param collectionId - Optional unique identifier for the collection. */ - async getStyle(styleId: string, collectionId?: string): Promise { - const metadataDoc = await this.getStyleMetadataDocument(styleId, collectionId); + async getStyle( + styleId: string, + collectionId?: string + ): Promise { + const metadataDoc = await this.getStyleMetadataDocument( + styleId, + collectionId + ); if (!metadataDoc?.stylesheets) { return parseBasicStyleInfo(metadataDoc as OgcApiStyleMetadata); } @@ -652,8 +664,15 @@ ${e.message}`); * @param mimeType - Stylesheet MIME type * @param collectionId - Optional unique identifier for the collection. */ - async getStylesheetUrl(styleId: string, mimeType: string, collectionId?: string): Promise { - const stylesDoc = await this.getStyleMetadataDocument(styleId, collectionId); + async getStylesheetUrl( + styleId: string, + mimeType: string, + collectionId?: string + ): Promise { + const stylesDoc = await this.getStyleMetadataDocument( + styleId, + collectionId + ); if (stylesDoc.stylesheets) { const urlFromMetadata = ( diff --git a/src/ogc-api/info.ts b/src/ogc-api/info.ts index 5b0a278..0bd9900 100644 --- a/src/ogc-api/info.ts +++ b/src/ogc-api/info.ts @@ -233,7 +233,7 @@ export function parseBasicStyleInfo(doc: OgcApiStyleMetadata): OgcStyleBrief { return { formats, id: doc.id, - ...doc.title && {title: doc.title}, + ...(doc.title && { title: doc.title }), }; } @@ -242,17 +242,15 @@ export function parseStylesAsList(): (doc: OgcApiStylesDocument) => string[] { doc?.styles?.map((style) => style.id as string); } -export function parseFullStyleInfo( - doc: OgcApiStyleMetadata -): OgcStyleFull { +export function parseFullStyleInfo(doc: OgcApiStyleMetadata): OgcStyleFull { // eslint-disable-next-line @typescript-eslint/no-unused-vars const { stylesheets, links, ...props } = doc; const stylesheetFormats = stylesheets ?.filter((stylesheet) => stylesheet.link.rel === 'stylesheet') ?.map((stylesheet) => stylesheet.link.type); return { - ...stylesheetFormats && {stylesheetFormats}, - ...stylesheets && {stylesheets}, + ...(stylesheetFormats && { stylesheetFormats }), + ...(stylesheets && { stylesheets }), ...props, } as OgcStyleFull; }