Skip to content

Commit

Permalink
fix: apply prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasLohoff committed Jul 11, 2024
1 parent e032389 commit 5103e56
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -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"
}
}
} ]
}
]
}
26 changes: 15 additions & 11 deletions src/ogc-api/endpoint.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'],
},
]);
});
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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'
);
Expand Down
35 changes: 27 additions & 8 deletions src/ogc-api/endpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ ${e.message}`);
styleId: string,
collectionId?: string
): Promise<OgcApiDocument> {
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'],
Expand All @@ -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}".`);
Expand Down Expand Up @@ -617,7 +621,9 @@ ${e.message}`);
* @param collectionId - Optional unique identifier for the collection.
*/
async allStyles(collectionId?: string): Promise<OgcStyleBrief[]> {
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'],
Expand All @@ -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);
}

Expand All @@ -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<OgcStyleFull | OgcStyleBrief> {
const metadataDoc = await this.getStyleMetadataDocument(styleId, collectionId);
async getStyle(
styleId: string,
collectionId?: string
): Promise<OgcStyleFull | OgcStyleBrief> {
const metadataDoc = await this.getStyleMetadataDocument(
styleId,
collectionId
);
if (!metadataDoc?.stylesheets) {
return parseBasicStyleInfo(metadataDoc as OgcApiStyleMetadata);
}
Expand All @@ -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<string> {
const stylesDoc = await this.getStyleMetadataDocument(styleId, collectionId);
async getStylesheetUrl(
styleId: string,
mimeType: string,
collectionId?: string
): Promise<string> {
const stylesDoc = await this.getStyleMetadataDocument(
styleId,
collectionId
);

if (stylesDoc.stylesheets) {
const urlFromMetadata = (
Expand Down
10 changes: 4 additions & 6 deletions src/ogc-api/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
};
}

Expand All @@ -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;
}

0 comments on commit 5103e56

Please sign in to comment.