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

opensearch-browser

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

opensearch-browser - npm Package Compare versions

Comparing version 0.0.12 to 0.0.13

dist/paginator.js

6

dist/description.js

@@ -100,3 +100,7 @@ 'use strict';

var urls = this.urls;
var urls = this.urls.filter(function (url) {
return url.relations.find(function (rel) {
return rel === 'results';
});
});

@@ -103,0 +107,0 @@ if (type) {

15

dist/formats/index.js

@@ -21,2 +21,11 @@ 'use strict';

/**
* @typedef Record
* @type Object
* @property {string} id The id of the record
* @property {object} properties The parsed properties of the record
* @property {object} [geometry] The parsed record geometry
* @property {float[]} [bbox] The parsed record geometry
*/
/**
* @typedef SearchResult

@@ -29,7 +38,3 @@ * @type Object

* @property {object[]} [links] Relevant links of this result
* @property {object[]} records The parsed records
* @property {string} records[].id The id of the record
* @property {object} records[].properties The parsed properties of the record
* @property {object} [records[].geometry] The parsed record geometry
* @property {float[]} [records[].bbox] The parsed record geometry
* @property {Record[]} records The parsed records
*/

@@ -36,0 +41,0 @@

@@ -14,2 +14,4 @@ 'use strict';

var _paginator = require('./paginator');
var _utils = require('./utils');

@@ -48,2 +50,20 @@

/**
* Get the URL for the given parameters.
* @param {object} parameters An object mapping the name or type to the value
* @param {string} [type=null] The preferred transfer type.
* @param {string} [method=null] The preferred HTTP method type.
* @returns {OpenSearchUrl} The resulting URL objec.
*/
}, {
key: 'getUrl',
value: function getUrl(parameters, type, method) {
var url = this.descriptionDocument.getUrl(parameters, type, method);
if (!url) {
throw new Error('No URL found for type \'' + type + '\' and the given parameters.');
}
return url;
}
/**
* Checks whether this URL is compatible with the given parameters

@@ -78,20 +98,14 @@ * @param {object} parameters An object mapping the name or type to the value

} else {
url = this.descriptionDocument.getUrl(parameters, type, method);
if (!url) {
throw new Error('No URL found for type \'' + type + '\' and the given parameters.');
}
url = this.getUrl(parameters, type, method);
}
// actually perform the search
return (0, _utils.fetchAndCheck)(url.createRequest(parameters)).then(function (response) {
if (raw) {
return response;
}
return (0, _utils.search)(url, parameters, type, raw);
}
}, {
key: 'getPaginator',
value: function getPaginator(parameters) {
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
var method = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var format = (0, _formats.getFormat)(type || url.type);
if (!format) {
throw new Error('Could not parse response of type \'' + type + '\'.');
}
return format.parse(response);
});
return new _paginator.OpenSearchPaginator(this.getUrl(parameters, type, method), parameters);
}

@@ -98,0 +112,0 @@ }]);

@@ -48,2 +48,3 @@ 'use strict';

* @param {Number} [pageOffset=1] The page offset of this URL
* @param {string[]} [relations=['results']] The relations of this URL.
*/

@@ -54,7 +55,8 @@ function OpenSearchUrl(type, url) {

var enctype = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'application/x-www-form-urlencoded';
var indexOffset = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 1;
var _this = this;
var indexOffset = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 1;
var pageOffset = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : 1;
var relations = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : ['results'];

@@ -69,2 +71,3 @@ _classCallCheck(this, OpenSearchUrl);

this._pageOffset = pageOffset;
this._relations = relations;

@@ -100,2 +103,14 @@ this._parameters = parameters;

/**
* Get the parameter of the specified type, if available
* @param {string} type The parameter type to check
* @returns {OpenSearchParameter} The parameter of the given type or null
*/
}, {
key: 'getParameter',
value: function getParameter(type) {
return this._parametersByType[type];
}
/**
* Checks whether this URL is compatible with the given parameters

@@ -285,2 +300,13 @@ * @param {object} parameters An object mapping the name or type to the value

/**
* The page offset of this URL
* @readonly
*/
}, {
key: 'relations',
get: function get() {
return this._relations;
}
/**
* The template/request parameters of the URL

@@ -303,2 +329,4 @@ * @readonly

var pageOffset = node.hasAttribute('pageOffset') ? parseInt(node.getAttribute('pageOffset'), 10) : 1;
var rel = node.getAttribute('rel');
var relations = typeof rel === 'undefined' || rel === '' ? undefined : rel.split(' ');

@@ -333,3 +361,3 @@ var parsed = (0, _urlParse2.default)(node.getAttribute('template'), true);

return new OpenSearchUrl(node.getAttribute('type'), node.getAttribute('template'), parameters, method, enctype, indexOffset, pageOffset);
return new OpenSearchUrl(node.getAttribute('type'), node.getAttribute('template'), parameters, method, enctype, indexOffset, pageOffset, relations);
}

@@ -336,0 +364,0 @@

@@ -14,2 +14,3 @@ 'use strict';

exports.isNullOrUndefined = isNullOrUndefined;
exports.search = search;

@@ -22,2 +23,4 @@ require('isomorphic-fetch');

var _formats = require('./formats');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -110,2 +113,28 @@

return typeof value === 'undefined' || value === null;
}
/**
* Performs a search for the given URL and parameters.
* @param {OpenSearchUrl} url The URL to search on.
* @param {object} [parameters={}] The search parameters.
* @param {string} [type=null] The response format.
* @param {boolean} [raw=false] Whether the response shall be parsed or returned raw.
* @returns {Promise<array>|Promise<Response>} The search result as a Promise
*/
function search(url) {
var parameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
var raw = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
return fetchAndCheck(url.createRequest(parameters)).then(function (response) {
if (raw) {
return response;
}
var format = (0, _formats.getFormat)(type || url.type);
if (!format) {
throw new Error('Could not parse response of type \'' + type + '\'.');
}
return format.parse(response);
});
}
{
"name": "opensearch-browser",
"version": "0.0.12",
"version": "0.0.13",
"description": "An OpenSearch client supporting the geo and time extensions.",

@@ -40,3 +40,4 @@ "main": "dist/index.js",

"babel-plugin-transform-object-assign": "^6.8.0",
"babel-polyfill": "^6.16.0",
"babel-plugin-transform-object-rest-spread": "^6.20.2",
"babel-polyfill": "^6.20.0",
"babel-preset-es2015": "^6.18.0",

@@ -46,3 +47,3 @@ "babel-register": "^6.18.0",

"chai": "^3.5.0",
"eslint": "^3.11.1",
"eslint": "^3.12.0",
"eslint-config-airbnb": "^13.0.0",

@@ -52,3 +53,3 @@ "eslint-config-pedant": "^0.8.0",

"eslint-plugin-jsx-a11y": "^2.2.3",
"eslint-plugin-react": "^6.7.1",
"eslint-plugin-react": "^6.8.0",
"fetch-mock": "^5.5.0",

@@ -55,0 +56,0 @@ "mochify": "^2.18.1",

@@ -74,3 +74,3 @@ import { OpenSearchUrl } from './url';

getUrls(parameters = null, type = null, method = null) {
let urls = this.urls;
let urls = this.urls.filter(url => url.relations.find(rel => rel === 'results'));

@@ -77,0 +77,0 @@ if (type) {

@@ -11,2 +11,11 @@ import { AtomFormat } from './atom';

/**
* @typedef Record
* @type Object
* @property {string} id The id of the record
* @property {object} properties The parsed properties of the record
* @property {object} [geometry] The parsed record geometry
* @property {float[]} [bbox] The parsed record geometry
*/
/**
* @typedef SearchResult

@@ -19,7 +28,3 @@ * @type Object

* @property {object[]} [links] Relevant links of this result
* @property {object[]} records The parsed records
* @property {string} records[].id The id of the record
* @property {object} records[].properties The parsed properties of the record
* @property {object} [records[].geometry] The parsed record geometry
* @property {float[]} [records[].bbox] The parsed record geometry
* @property {Record[]} records The parsed records
*/

@@ -26,0 +31,0 @@

import 'isomorphic-fetch';
import { OpenSearchDescription } from './description';
import { fetchAndCheck } from './utils';
import { getFormat, getSupportedTypes } from './formats/';
import { OpenSearchPaginator } from './paginator';
import { search } from './utils';
import { getSupportedTypes } from './formats/';

@@ -28,2 +29,17 @@ /**

/**
* Get the URL for the given parameters.
* @param {object} parameters An object mapping the name or type to the value
* @param {string} [type=null] The preferred transfer type.
* @param {string} [method=null] The preferred HTTP method type.
* @returns {OpenSearchUrl} The resulting URL objec.
*/
getUrl(parameters, type, method) {
const url = this.descriptionDocument.getUrl(parameters, type, method);
if (!url) {
throw new Error(`No URL found for type '${type}' and the given parameters.`);
}
return url;
}
/**
* Checks whether this URL is compatible with the given parameters

@@ -51,22 +67,13 @@ * @param {object} parameters An object mapping the name or type to the value

} else {
url = this.descriptionDocument.getUrl(parameters, type, method);
if (!url) {
throw new Error(`No URL found for type '${type}' and the given parameters.`);
}
url = this.getUrl(parameters, type, method);
}
// actually perform the search
return fetchAndCheck(url.createRequest(parameters))
.then(response => {
if (raw) {
return response;
}
return search(url, parameters, type, raw);
}
const format = getFormat(type || url.type);
if (!format) {
throw new Error(`Could not parse response of type '${type}'.`);
}
return format.parse(response);
});
getPaginator(parameters, type = null, method = null) {
return new OpenSearchPaginator(
this.getUrl(parameters, type, method), parameters
);
}
}

@@ -30,6 +30,7 @@ import parse from 'url-parse';

* @param {Number} [pageOffset=1] The page offset of this URL
* @param {string[]} [relations=['results']] The relations of this URL.
*/
constructor(type, url, parameters = [], method = 'GET',
enctype = 'application/x-www-form-urlencoded',
indexOffset = 1, pageOffset = 1) {
indexOffset = 1, pageOffset = 1, relations = ['results']) {
this._type = type;

@@ -41,2 +42,3 @@ this._url = url;

this._pageOffset = pageOffset;
this._relations = relations;

@@ -101,2 +103,10 @@ this._parameters = parameters;

/**
* The page offset of this URL
* @readonly
*/
get relations() {
return this._relations;
}
/**
* The template/request parameters of the URL

@@ -119,2 +129,11 @@ * @readonly

/**
* Get the parameter of the specified type, if available
* @param {string} type The parameter type to check
* @returns {OpenSearchParameter} The parameter of the given type or null
*/
getParameter(type) {
return this._parametersByType[type];
}
/**
* Checks whether this URL is compatible with the given parameters

@@ -240,2 +259,4 @@ * @param {object} parameters An object mapping the name or type to the value

parseInt(node.getAttribute('pageOffset'), 10) : 1;
const rel = node.getAttribute('rel');
const relations = (typeof rel === 'undefined' || rel === '') ? undefined : rel.split(' ');

@@ -266,3 +287,3 @@ const parsed = parse(node.getAttribute('template'), true);

node.getAttribute('type'), node.getAttribute('template'),
parameters, method, enctype, indexOffset, pageOffset
parameters, method, enctype, indexOffset, pageOffset, relations
);

@@ -269,0 +290,0 @@ }

import 'isomorphic-fetch';
import xpath from 'xpath';
import { getFormat } from './formats'
export function parseURLQuery(url) {

@@ -91,1 +93,24 @@ const search = (url.indexOf('?') === -1) ? url : url.substring(url.indexOf('?'));

}
/**
* Performs a search for the given URL and parameters.
* @param {OpenSearchUrl} url The URL to search on.
* @param {object} [parameters={}] The search parameters.
* @param {string} [type=null] The response format.
* @param {boolean} [raw=false] Whether the response shall be parsed or returned raw.
* @returns {Promise<array>|Promise<Response>} The search result as a Promise
*/
export function search(url, parameters = {}, type = null, raw = false) {
return fetchAndCheck(url.createRequest(parameters))
.then(response => {
if (raw) {
return response;
}
const format = getFormat(type || url.type);
if (!format) {
throw new Error(`Could not parse response of type '${type}'.`);
}
return format.parse(response);
});
}

Sorry, the diff of this file is not supported yet

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