Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@camptocamp/ogc-client

Package Overview
Dependencies
Maintainers
7
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@camptocamp/ogc-client - npm Package Compare versions

Comparing version 1.1.1-dev.4369f6c to 1.1.1-dev.52f33cd

108

dist/ogc-api/endpoint.js

@@ -7,2 +7,3 @@ import {

parseBaseCollectionInfo,
parseFullStyleInfo,
parseCollectionParameters,

@@ -12,2 +13,3 @@ parseCollections,

parseEndpointInfo,
parseBasicStyleInfo,
parseTileMatrixSets

@@ -45,2 +47,3 @@ } from "./info.js";

tileMatrixSetsFull_;
styles_;
get root() {

@@ -104,2 +107,16 @@ if (!this.root_) {

}
get styles() {
if (!this.styles_) {
this.styles_ = this.root.then(async (root) => {
if (!await this.hasStyles)
return void 0;
return fetchLink(
root,
["styles", "http://www.opengis.net/def/rel/ogc/1.0/styles"],
this.baseUrl
);
});
}
return this.styles_;
}
/**

@@ -201,2 +218,28 @@ * A Promise which resolves to the endpoint information.

}
async getStyleMetadataDocument(styleId, collectionId) {
const doc = collectionId ? await this.getCollectionDocument(collectionId) : await this.root;
const stylesLinkJson = getLinkUrl(
doc,
["styles", "http://www.opengis.net/def/rel/ogc/1.0/styles"],
this.baseUrl,
"application/json"
);
const stylesLink = getLinkUrl(
doc,
["styles", "http://www.opengis.net/def/rel/ogc/1.0/styles"],
this.baseUrl
);
const styleData = await fetchDocument(
stylesLinkJson ?? stylesLink
);
if (!styleData.styles.some((style) => style.id === styleId)) {
throw new EndpointError(`Style not found: "${styleId}".`);
}
const styleDoc = styleData?.styles?.find((style) => style.id === styleId);
if (hasLinks(styleDoc, ["describedby"])) {
return fetchLink(styleDoc, "describedby", this.baseUrl);
} else {
return styleDoc;
}
}
/**

@@ -440,2 +483,67 @@ * Returns a promise resolving to a document describing the specified collection.

}
/**
* A Promise which resolves to an array of all style items. This includes the supported style formats.
* @param collectionId - Optional unique identifier for the collection.
*/
async allStyles(collectionId) {
const doc = collectionId ? await this.getCollectionDocument(collectionId) : await this.root;
const stylesLink = getLinkUrl(
doc,
["styles", "http://www.opengis.net/def/rel/ogc/1.0/styles"],
this.baseUrl
);
if (!stylesLink) {
throw new EndpointError(
'Could not get styles: there is no relation of type "styles"'
);
}
const styleData = await fetchDocument(stylesLink);
return styleData.styles.map(parseBasicStyleInfo);
}
/**
* Returns a promise resolving to a document describing the style. Looks for a relation of type
* "describedby" to fetch metadata. If no relation is found, only basic info will be returned.
* @param styleId - The style identifier
* @param collectionId - Optional unique identifier for the collection.
*/
async getStyle(styleId, collectionId) {
const metadataDoc = await this.getStyleMetadataDocument(
styleId,
collectionId
);
if (!metadataDoc?.stylesheets) {
return parseBasicStyleInfo(metadataDoc);
}
return parseFullStyleInfo(metadataDoc);
}
/**
* Returns a promise resolving to a stylesheet URL for a given style and type.
* @param styleId - The style identifier
* @param mimeType - Stylesheet MIME type
* @param collectionId - Optional unique identifier for the collection.
*/
async getStylesheetUrl(styleId, mimeType, collectionId) {
const stylesDoc = await this.getStyleMetadataDocument(
styleId,
collectionId
);
if (stylesDoc.stylesheets) {
const urlFromMetadata = stylesDoc?.stylesheets?.find(
(s) => s.link.type === mimeType && s.link.rel === "stylesheet"
)?.link?.href;
return urlFromMetadata;
}
const urlFromStyle = getLinkUrl(
stylesDoc,
"stylesheet",
this.baseUrl,
mimeType
);
if (!urlFromStyle) {
throw new EndpointError(
"Could not find stylesheet URL for given style ID and type."
);
}
return urlFromStyle;
}
}

@@ -442,0 +550,0 @@ export {

@@ -68,2 +68,4 @@ import {

"http://www.opengis.net/spec/ogcapi-styles-1/0.0/conf/core"
) > -1 || conformance.indexOf(
"http://www.opengis.net/spec/ogcapi-styles-1/1.0/conf/core"
) > -1;

@@ -147,2 +149,22 @@ }

}
function parseBasicStyleInfo(doc) {
const formats = doc.links.filter((link) => link.rel === "stylesheet").map((link) => link.type).filter((type) => type !== "text/html");
return {
formats,
id: doc.id,
...doc.title && { title: doc.title }
};
}
function parseStylesAsList() {
return (doc) => doc?.styles?.map((style) => style.id);
}
function parseFullStyleInfo(doc) {
const { stylesheets, links, ...props } = doc;
const stylesheetFormats = stylesheets?.filter((stylesheet) => stylesheet.link.rel === "stylesheet")?.map((stylesheet) => stylesheet.link.type);
return {
...stylesheetFormats && { stylesheetFormats },
...stylesheets && { stylesheets },
...props
};
}
export {

@@ -154,2 +176,3 @@ checkHasFeatures,

parseBaseCollectionInfo,
parseBasicStyleInfo,
parseCollectionParameters,

@@ -159,4 +182,6 @@ parseCollections,

parseEndpointInfo,
parseFullStyleInfo,
parseStylesAsList,
parseTileMatrixSets
};
//# sourceMappingURL=info.js.map

12

dist/ogc-api/link-utils.js

@@ -54,9 +54,13 @@ import { EndpointError } from "../shared/errors.js";

}
function getLinks(doc, relType) {
return doc.links?.filter(
function getLinks(doc, relType, mimeType) {
const links = doc.links?.filter(
(link) => Array.isArray(relType) ? relType.indexOf(link.rel) > -1 : link.rel === relType
) || [];
if (mimeType) {
return links.filter((link) => link.type === mimeType);
}
return links;
}
function getLinkUrl(doc, relType, baseUrl) {
const link = getLinks(doc, relType)[0];
function getLinkUrl(doc, relType, baseUrl, mimeType) {
const link = getLinks(doc, relType, mimeType)[0];
if (!link)

@@ -63,0 +67,0 @@ return null;

{
"name": "@camptocamp/ogc-client",
"version": "1.1.1-dev.4369f6c",
"version": "1.1.1-dev.52f33cd",
"description": "A pure JS library for interacting with geospatial services.",

@@ -5,0 +5,0 @@ "main": "./dist/dist-node.js",

@@ -7,2 +7,3 @@ import {

parseBaseCollectionInfo,
parseFullStyleInfo,
parseCollectionParameters,

@@ -12,2 +13,3 @@ parseCollections,

parseEndpointInfo,
parseBasicStyleInfo,
parseTileMatrixSets,

@@ -21,2 +23,6 @@ } from './info.js';

OgcApiEndpointInfo,
OgcApiStyleMetadata,
OgcApiStylesDocument,
OgcStyleBrief,
OgcStyleFull,
TileMatrixSet,

@@ -51,2 +57,3 @@ } from './model.js';

private tileMatrixSetsFull_: Promise<TileMatrixSet[]>;
private styles_: Promise<OgcApiStylesDocument>;

@@ -114,2 +121,16 @@ private get root(): Promise<OgcApiDocument> {

private get styles(): Promise<OgcApiStylesDocument> {
if (!this.styles_) {
this.styles_ = this.root.then(async (root) => {
if (!(await this.hasStyles)) return undefined;
return fetchLink(
root,
['styles', 'http://www.opengis.net/def/rel/ogc/1.0/styles'],
this.baseUrl
) as unknown as OgcApiStylesDocument;
});
}
return this.styles_;
}
/**

@@ -257,2 +278,36 @@ * Creates a new OGC API endpoint.

private async getStyleMetadataDocument(
styleId: string,
collectionId?: string
): Promise<OgcApiDocument> {
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'],
this.baseUrl,
'application/json'
);
const stylesLink = getLinkUrl(
doc as OgcApiDocument,
['styles', 'http://www.opengis.net/def/rel/ogc/1.0/styles'],
this.baseUrl
);
const styleData = (await fetchDocument(
stylesLinkJson ?? stylesLink
)) as OgcApiStylesDocument;
if (!styleData.styles.some((style) => style.id === styleId)) {
throw new EndpointError(`Style not found: "${styleId}".`);
}
const styleDoc = styleData?.styles?.find((style) => style.id === styleId);
if (hasLinks(styleDoc as OgcApiDocument, ['describedby'])) {
return fetchLink(styleDoc as OgcApiDocument, 'describedby', this.baseUrl);
} else {
// fallback: return style document
return styleDoc as OgcApiDocument;
}
}
/**

@@ -569,2 +624,84 @@ * Returns a promise resolving to a document describing the specified collection.

}
/**
* A Promise which resolves to an array of all style items. This includes the supported style formats.
* @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 stylesLink = getLinkUrl(
doc as OgcApiDocument,
['styles', 'http://www.opengis.net/def/rel/ogc/1.0/styles'],
this.baseUrl
);
if (!stylesLink) {
throw new EndpointError(
'Could not get styles: there is no relation of type "styles"'
);
}
const styleData = (await fetchDocument(stylesLink)) as OgcApiStylesDocument;
return styleData.styles.map(parseBasicStyleInfo);
}
/**
* Returns a promise resolving to a document describing the style. Looks for a relation of type
* "describedby" to fetch metadata. If no relation is found, only basic info will be returned.
* @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
);
if (!metadataDoc?.stylesheets) {
return parseBasicStyleInfo(metadataDoc as OgcApiStyleMetadata);
}
return parseFullStyleInfo(metadataDoc as OgcApiStyleMetadata);
}
/**
* Returns a promise resolving to a stylesheet URL for a given style and type.
* @param styleId - The style identifier
* @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
);
if (stylesDoc.stylesheets) {
const urlFromMetadata = (
stylesDoc as OgcApiStyleMetadata
)?.stylesheets?.find(
(s) => s.link.type === mimeType && s.link.rel === 'stylesheet'
)?.link?.href;
return urlFromMetadata;
}
const urlFromStyle = getLinkUrl(
stylesDoc,
'stylesheet',
this.baseUrl,
mimeType
);
if (!urlFromStyle) {
throw new EndpointError(
'Could not find stylesheet URL for given style ID and type.'
);
}
return urlFromStyle;
}
}

@@ -9,2 +9,6 @@ import {

OgcApiEndpointInfo,
OgcApiStyleMetadata,
OgcApiStylesDocument,
OgcStyleBrief,
OgcStyleFull,
TileMatrixSet,

@@ -109,2 +113,5 @@ } from './model.js';

'http://www.opengis.net/spec/ogcapi-styles-1/0.0/conf/core'
) > -1 ||
conformance.indexOf(
'http://www.opengis.net/spec/ogcapi-styles-1/1.0/conf/core'
) > -1

@@ -222,1 +229,31 @@ );

}
export function parseBasicStyleInfo(doc: OgcApiStyleMetadata): OgcStyleBrief {
const formats = doc.links
.filter((link) => link.rel === 'stylesheet')
.map((link) => link.type)
.filter((type) => type !== 'text/html');
return {
formats,
id: doc.id,
...(doc.title && { title: doc.title }),
};
}
export function parseStylesAsList(): (doc: OgcApiStylesDocument) => string[] {
return (doc: OgcApiStylesDocument) =>
doc?.styles?.map((style) => style.id as string);
}
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 }),
...props,
} as OgcStyleFull;
}

@@ -80,5 +80,6 @@ import { OgcApiDocument, OgcApiDocumentLink } from './model.js';

doc: OgcApiDocument,
relType: string | string[]
relType: string | string[],
mimeType?: string
): OgcApiDocumentLink[] {
return (
const links =
doc.links?.filter((link) =>

@@ -88,4 +89,7 @@ Array.isArray(relType)

: link.rel === relType
) || []
);
) || [];
if (mimeType) {
return links.filter((link) => link.type === mimeType);
}
return links;
}

@@ -96,5 +100,6 @@

relType: string | string[],
baseUrl?: string
baseUrl?: string,
mimeType?: string
): string | null {
const link = getLinks(doc, relType)[0];
const link = getLinks(doc, relType, mimeType)[0];
if (!link) return null;

@@ -101,0 +106,0 @@ return new URL(link.href, baseUrl || window.location.toString()).toString();

@@ -176,1 +176,59 @@ import { Geometry } from 'geojson';

}
export type StyleItem = {
title: string;
id: string;
links?: OgcApiDocumentLink[];
formats?: string[];
};
export type OgcStyleFull = {
stylesheetFormats: string[];
} & OgcApiStyleMetadata;
export type OgcStyleBrief = {
id: string;
title?: string;
formats?: string[];
};
export type OgcApiStylesDocument = {
styles: StyleItem[];
links: OgcApiDocumentLink[];
};
export type OgcApiStyleRecord = {
title: string;
id: string;
};
export type OgcApiStylesheet = {
link: OgcApiDocumentLink;
title?: string;
version?: string;
specification?: string;
native?: boolean;
};
export type OgcApiStyleMetadata = {
id: string;
title?: string;
description?: string;
keywords?: string[];
pointOfContact?: string;
license?: string;
created?: string;
updated?: string;
scope?: 'style';
version?: string;
stylesheets?: OgcApiStylesheet[];
layers?: {
id: string;
description?: string;
dataType?: 'vector' | 'map' | 'coverage' | 'model';
geometryType?: 'points' | 'lines' | 'polygons' | 'solids' | 'any';
propertiesSchema?: any; // https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v3.0/schema.json#/definitions/Schema
sampleData?: OgcApiDocumentLink;
}[];
links?: OgcApiDocumentLink[];
};

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc