npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@map-colonies/csw-client

v1.2.0

Published

TypeScript and JavaScript classes for osm elements

Downloads

45

Readme

CSW-CLIENT

This package provides client-side API for OGC CSW service(s) written in TypeScript.

Suits for Node.JS and React/Angular applications

Package boilerplate based on ts-npm-package-boilerplate

This Client library is based on Jsonix and ogc-schemas libraries.

Code samples are provided by TypeScript.

Installation

Install package by NPM

npm install @map-colonies/csw-client --save

Install package by YARN

yarn add @map-colonies/csw-client --save

!!! IMPORTANT: Apply integrated PATCHES

Add following script to your package.json

"scripts": {
  .
  .
  .
  "patch:deps": "cd ./node_modules/@map-colonies/csw-client && patch-package --patch-dir ./dist/patches"
}

You can add patch:deps script to one of the npm hooks or run it manually.

For example add it to postinstall hook:

"scripts": {
  "postinstall": "yarn run patch:deps && <your_own_postinstall>",
  .
  .
  .
  "patch:deps": "cd ./node_modules/@map-colonies/csw-client && patch-package --patch-dir ./dist/patches"
}

Usage

// import CswClient class 
import { CswClient, ICapabilities } from from '@map-colonies/csw-client';

// later in code
const csw = new CswClient('<YOUR_OGC_CSW_SRV_URL>', <YOUR_REQUEST_EXECUTOR_FUNC>, <CONFIG>);
// trigger one of the exposed methods
csw.GetDomain('<propertyName>').then((data: ICapabilities) => {
  // your code
}); 

Implemented operations/methods

Client library instantiation

  • Instantiation - new
      // import CswClient class 
      import { CswClient } from from '@map-colonies/csw-client';
      import Axios, { Method } from 'axios';
    
      // import desired ADDITIONAL schemas
      const ISO19139_GCO_20060504 = require('ogc-schemas').ISO19139_GCO_20060504;
      const ISO19139_GMD_20060504 = require('ogc-schemas').ISO19139_GMD_20060504;
      const GML_3_2_0 = require('ogc-schemas').GML_3_2_0;
    
      // define your own requestExecutor
      const myRequest = async (url: string, method: string, params: Record<string, unknown>): Promise<any> => {
        const errorMsg = 'CLIENT HTTP ERROR BY AXIOS';
        return Axios.request({
          url,
          method: method as Method,
          ...params,
        })
          .then((res) => res)
          .catch((error) => {
            console.error(errorMsg);
            throw error;
          });
      };
    
      // later in code
      const cswConfig = {
        schemas: [
          GML_3_2_0,
          ISO19139_GCO_20060504,
          ISO19139_GMD_20060504,
        ],
        nameSpaces: {
          namespacePrefixes: { // define ADDITIONAL namespace prefixes
            'http://schema.mapcolonies.com': 'mc',
            'http://www.isotc211.org/2005/gmd': 'gmd',
            'http://www.isotc211.org/2005/gco': 'gco',
          },
        },
        credentials: {},
      };
      const csw = new CswClient('http://127.0.0.1:56477/?version=2.0.2&service=CSW', myRequest, cswConfig);

Basic OWS operations

  • GetCapabilities(): Promise

    Allow clients to retrieve information describing the service instance

      csw.GetCapabilities().then((data: ICapabilities) => {
        ... // your code
      });
  • DescribeRecord(): Promise

    Allows a client to discover elements of the information model supported by the target catalog service

      csw.DescribeRecord().then((data) => {
        ... // your code
      });

CSW queries

  • GetDomain(propertyName: string): Promise

    Obtain runtime information about the range of values of a metadata record element or request parameter.

      csw.GetDomain('title').then((data) => {
        ... // your code
      });
  • GetRecords(start: number, max: number, opts: { filter?: IFilterField[]; sort?: ISortField[] }, outputSchema: string): Promise

    Get metadata records according to defined filter and sort order

     const options = {
       filter: [
         {
           field: 'mcgc:geojson',
           bbox: {
             llat: 31.90,
             llon: 36.80,
             ulat: 31.91,
             ulon: 36.81,
           },
         },
         {
           field: 'mcgc:name',
           like: 'magic_place',
         },
       ],
       sort: [
         {
           field: 'mcgc:name',
           desc: false,
         },
         {
           field: 'mcgc:creation_date',
           desc: true,
         },
    
       ]
     };
     csw.GetRecords(1, 10, options, 'http://schema.myschema.com').then((data) => {
       ... // your code
     });
  • GetRecordsById(id_list: string[]): Promise

    Get metadata records by ID list

     csw.GetRecordsById(['1', '2', '5']).then((data) => {
       ... // your code
     });

CSW CRUD operations

  • InsertRecords(records: any[]): Promise

    Create catalog records

     csw.InsertRecords(records).then((data) => {
       ... // your code
     });
  • UpdateRecord(record: any): Promise

    Modify catalog record

     csw.UpdateRecord(records).then((data) => {
       ... // your code
     });
  • DeleteRecords(filters: IFilterField[]): Promise

    Delete catalog records according to defined filter

     csw.DeleteRecords(filters).then((data) => {
       ... // your code
     });

Utils

  • xmlStringToJson(xmlString: string): any

    Converts XML-like string to JSON object according to defined schemas

     const obj = csw.xmlStringToJson(xmlString);
  • jsonToXml(json: any): XMLDocument
    Converts JSON object to XMLDocument according to defined schemas

     const xmlDoc: XMLDocument = csw.jsonToXml(json);
  • xmlToJson(xml: XMLDocument): any

    Converts XMLDocument to JSON object according to defined schemas

     const obj = csw.xmlToJson(xml);
  • xmlToString(xml: XMLDocument): string

    Converts XMLDocument to XML-like string according to defined schemas

     const str = csw.xmlToString(xml);

OGC Filters

  • Operators:

    • Logical Operators:
      • AND
          let filter: any = new FilterBuilder().PropertyName('dc:title').isLike('%water%');
          filter = filter.and(new FilterBuilder().PropertyName('dc:subject').isLike('%polution%'));
      • OR
          let filter: any = new FilterBuilder().PropertyName('dc:title').isLike('%water%');
          filter = filter.or(new FilterBuilder().PropertyName('dc:title').isLike('%oil%'));
  • Spatial Operatos:

    • BBOX
    let filter: any = new FilterBuilder().PropertyName('dc:title').isLike('%water%');
    filter = filter.and(new FilterBuilder().BBOX(-80, 150, 80, -150));
  • Comparison

    • isLike
    • isBetween
    • isEqualTo
    • isLessThanOrEqualTo
    • isGreaterThan
    • isLessThan
    • isGreaterThanOrEqualTo
    • isNotEqualTo

OGC Sort

  const sort: SortBuilder = new SortBuilder().Sort('dc:title');
  sort.Sort('dc:dummy', true);

Applyed patches ( ./patches/*.patch )

  • Jsonix/ogc-schemas BBOX schema(s) definition
    • Discussion is here: https://github.com/OSGeo/ows.js/issues/9
  • Jsonix webback-dev-server issue
    • Discussion is here: https://github.com/highsource/jsonix/issues/171
    • Applied patch based on: https://github.com/planetfederal/jsonix/commit/d88f68d1a62a14c09562b15cf0e6ce5e1f14fbf2