feathers-solr
Advanced tools
Comparing version 2.7.10 to 2.7.11
@@ -1,18 +0,27 @@ | ||
const fetchClient = require('./fetch'); | ||
const undiciClient = require('./undici'); | ||
const FetchClient = require('./fetch'); | ||
const UndiciClient = require('./undici'); | ||
function SolrClient(fn, host, opts = {}) { | ||
try { | ||
const name = fn.name; | ||
if (name == 'fetch') { | ||
return new fetchClient(fn, host, opts); | ||
} else if (name == 'undici') { | ||
return new undiciClient(fn, host, opts); | ||
function SolrClient (fn, host, opts = {}) { | ||
if(!fn || !fn.name) throw new Error('Client must be one of fetch or undici.'); | ||
if(!host) throw new Error('A host is required'); | ||
const name = fn.name || false; | ||
if (name === 'fetch') { | ||
try { | ||
return new FetchClient(fn, host, opts); | ||
} catch (err) { | ||
throw new Error('Client must be one of fetch or undici.'); | ||
} | ||
throw new Error('Client must be one of fetch or undici.'); | ||
} catch (error) { | ||
throw new Error('Client must be one of fetch or undici.'); | ||
} | ||
if (name === 'undici') { | ||
try { | ||
return new UndiciClient(fn, host, opts); | ||
} catch (err) { | ||
return err; | ||
} | ||
} | ||
} | ||
module.exports = { SolrClient }; |
const qs = require('qs'); | ||
const url = require('url'); | ||
const debug = require('debug')('feathers-solr-client-undici'); | ||
@@ -7,3 +8,3 @@ const debugError = require('debug')('feathers-solr-client-undici'); | ||
class UndiciClient { | ||
constructor(undici, conn, options = {}) { | ||
constructor (undici, conn, options = {}) { | ||
this.options = Object.assign( | ||
@@ -16,7 +17,8 @@ { | ||
); | ||
this.httpOptions = new URL(conn); | ||
this.client = new undici.Client(conn, this.options); | ||
this.client = new undici.Client(`http://${this.httpOptions.hostname}:${this.httpOptions.port}`, this.options); | ||
} | ||
get(api, params = {}) { | ||
get (api, params = {}) { | ||
const { url, options } = this._options(api, null, params); | ||
@@ -27,3 +29,3 @@ debug('GET', url); | ||
post(api, data, params = {}) { | ||
post (api, data, params = {}) { | ||
const { url, options } = this._options(api, data, params); | ||
@@ -34,4 +36,4 @@ debug('POST:', url, data); | ||
_options(api, data, params) { | ||
const url = `${this.client.url.pathname}/${api}?${qs.stringify(params, { encode: false })}`; | ||
_options (api, data, params) { | ||
const url = `${this.httpOptions.pathname}/${api}?${qs.stringify(params, { encode: false })}`; | ||
const options = { | ||
@@ -49,3 +51,3 @@ headers: { | ||
_request(options) { | ||
_request (options) { | ||
const self = this; | ||
@@ -68,3 +70,3 @@ return new Promise(function (resolve, reject) { | ||
} else { | ||
throw new FeathersError(statusCode) | ||
throw new FeathersError(statusCode); | ||
} | ||
@@ -71,0 +73,0 @@ } catch (err) { |
const { _ } = require('@feathersjs/commons'); | ||
const debug = require('debug')('feathers-solr-query'); | ||
const { v4: uuidv4 } = require('uuid'); | ||
_.has = function has(obj, key) { | ||
_.has = function has (obj, key) { | ||
return key.split('.').every(function (x) { | ||
@@ -13,3 +13,3 @@ if (typeof obj !== 'object' || obj === null || !(x in obj)) { | ||
}; | ||
_.get = function get(obj, key) { | ||
_.get = function get (obj, key) { | ||
return key.split('.').reduce(function (o, x) { | ||
@@ -55,6 +55,6 @@ return typeof o === 'undefined' || o === null ? o : o[x]; | ||
}, | ||
$nin(key, value) { | ||
$nin (key, value) { | ||
return Array.isArray(value) ? `!${key}:(${value.join(' OR ')})` : `!${key}:${value}`; | ||
}, | ||
$limit(filters, paginate) { | ||
$limit (filters, paginate) { | ||
const result = {}; | ||
@@ -70,7 +70,7 @@ if (typeof filters.$limit !== 'undefined') { | ||
// eslint-disable-next-line no-unused-vars | ||
$skip(filters, paginate) { | ||
$skip (filters, paginate) { | ||
return filters.$skip ? { offset: filters.$skip } : {}; | ||
}, | ||
// eslint-disable-next-line no-unused-vars | ||
$sort(filters, paginate) { | ||
$sort (filters, paginate) { | ||
const result = {}; | ||
@@ -86,11 +86,11 @@ if (filters.$sort) { | ||
}, | ||
$params(filters, query) { | ||
$params (filters, query) { | ||
if (query.$params) return { params: query.$params }; | ||
return {}; | ||
}, | ||
$facet(filters, query) { | ||
$facet (filters, query) { | ||
if (query.$facet) return { facet: query.$facet }; | ||
return {}; | ||
}, | ||
$filter(filters, query) { | ||
$filter (filters, query) { | ||
if (query.$filter) return { filter: Array.isArray(query.$filter) ? query.$filter : [query.$filter] }; | ||
@@ -101,3 +101,3 @@ return {}; | ||
function jsonQuery(id, filters, query, paginate) { | ||
function jsonQuery (id, filters, query, paginate) { | ||
const adapterQuery = Object.assign({}, query); | ||
@@ -139,3 +139,3 @@ const result = Object.assign( | ||
function convertOperators(query, root = false) { | ||
function convertOperators (query, root = false) { | ||
if (Array.isArray(query)) { | ||
@@ -180,3 +180,3 @@ return query.map(q => { | ||
function deleteQuery(id, params) { | ||
function deleteQuery (id, params) { | ||
if (id) { | ||
@@ -201,3 +201,3 @@ if (id === '*' || id === '*:*') { | ||
function patchQuery(toPatch, patch, idField) { | ||
function patchQuery (toPatch, patch, idField) { | ||
toPatch = Array.isArray(toPatch) ? toPatch : [toPatch]; | ||
@@ -204,0 +204,0 @@ |
@@ -109,3 +109,3 @@ const { _ } = require('@feathersjs/commons'); | ||
// request and return created data or plain solr response | ||
return this._find({ query: query }).then(res => sel(ids.length == 1 ? res[0] : res)); | ||
return this._find({ query: query }).then(res => sel(ids.length === 1 ? res[0] : res)); | ||
} | ||
@@ -126,3 +126,3 @@ | ||
// get patched data | ||
return this._find({ query: { id: { $in: ids } } }).then(res => sel(ids.length == 1 ? res[0] : res)); | ||
return this._find({ query: { id: { $in: ids } } }).then(res => sel(ids.length === 1 ? res[0] : res)); | ||
} | ||
@@ -129,0 +129,0 @@ |
{ | ||
"name": "feathers-solr", | ||
"description": "A service plugin for Solr", | ||
"version": "2.7.10", | ||
"version": "2.7.11", | ||
"homepage": "https://github.com/sajov/feathers-solr", | ||
@@ -57,21 +57,21 @@ "keywords": [ | ||
"@feathersjs/adapter-commons": "^4.5.2", | ||
"@feathersjs/commons": "^4.5.3", | ||
"@feathersjs/errors": "^4.5.3", | ||
"@feathersjs/commons": "^4.5.8", | ||
"@feathersjs/errors": "^4.5.8", | ||
"debug": "^4.1.1", | ||
"qs": "^6.9.4", | ||
"uuid": "^8.1.0" | ||
"uuid": "^8.3.0" | ||
}, | ||
"devDependencies": { | ||
"@feathersjs/adapter-tests": "^4.5.2", | ||
"@feathersjs/express": "^4.5.4", | ||
"@feathersjs/feathers": "^4.5.3", | ||
"dtslint": "^3.6.9", | ||
"@feathersjs/express": "^4.5.8", | ||
"@feathersjs/feathers": "^4.5.8", | ||
"dtslint": "^4.0.0", | ||
"istanbul": "^1.1.0-alpha.1", | ||
"mocha": "^7.2.0", | ||
"mocha": "^8.1.3", | ||
"node-fetch": "^2.6.0", | ||
"semistandard": "^14.2.0", | ||
"tslint": "^6.1.2", | ||
"undici": "^0.5.0", | ||
"semistandard": "^14.2.3", | ||
"tslint": "^6.1.3", | ||
"undici": "^1.3.1", | ||
"minimist": ">=1.2.5" | ||
} | ||
} |
40765
675
Updated@feathersjs/commons@^4.5.8
Updated@feathersjs/errors@^4.5.8
Updateduuid@^8.3.0