Skip to content

Commit

Permalink
Applied PR corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
Nataniel López committed Feb 14, 2020
1 parent c992073 commit f59f624
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 25 deletions.
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]
### Added
- Solr DB Driver Package
- Solr DB Driver Package
- `endpoint` helper
- `filters` helper
- `query` helper
- `request` helper
- `response` helper
- `schema` helper
- `utils` helper
- `insert` and `multiInsert` methods
- `remove` and `multiRemove` methods
- `get` and `getTotals` methods
- `distinct` method
- `createSchemas`, `updateSchemas` and `createCore` methods
7 changes: 7 additions & 0 deletions lib/helpers/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ class Endpoint {
};
}

/**
* Creates a Solr endpoint
* @param {String} endpoint The endpoint to create
* @param {String} url The solr url
* @param {String} core The solr core name
* @param {Object} replacements The replacements to apply to the endpoint
*/
static create(endpoint, url, core, replacements) {
return this._buildEndpoint(path.join(ENDPOINT_BASE, endpoint), { url, core, ...replacements });
}
Expand Down
29 changes: 17 additions & 12 deletions lib/helpers/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const DEFAULT_FILTER_TYPE = 'equal';

class Filters {

/**
* Builds the filters for Solr legibility
* @param {Object} filters The filters
* @param {Object} modelFields The model fields
*/
static build(filters, modelFields) {

const filtersGroup = this._parseFilterGroup(filters, modelFields);
Expand Down Expand Up @@ -58,18 +63,6 @@ class Filters {
});
}

static get _formatters() {

return {
equal: this._formatEq.bind(this),
notEqual: this._formatNe.bind(this),
greater: this._formatGt,
greaterOrEqual: this._formatGte,
lesser: this._formatLt,
lesserOrEqual: this._formatLte
};
}

static _formatByType(filtersGroup) {

return Object.entries(filtersGroup).reduce((filtersByType, [field, filterData]) => {
Expand All @@ -94,6 +87,18 @@ class Filters {
}, {});
}

static get _formatters() {

return {
equal: this._formatEq.bind(this),
notEqual: this._formatNe.bind(this),
greater: this._formatGt,
greaterOrEqual: this._formatGte,
lesser: this._formatLt,
lesserOrEqual: this._formatLte
};
}

static _formatEq(field, value) {
return `${field}:"${value}"`;
}
Expand Down
5 changes: 5 additions & 0 deletions lib/helpers/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const FIELD_TYPES = {

class Schema {

/**
* Builds a schema query for Solr
* @param {String} method The method to use for building the schema api query
* @param {Object} schemas The model schemas
*/
static buildQuery(method, schemas) {

const builtSchemas = Object.entries(schemas).reduce((fields, [field, schema]) => {
Expand Down
16 changes: 10 additions & 6 deletions lib/helpers/utils.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
'use strict';

function isObject(object) {
return object !== null && typeof object === 'object' && !Array.isArray(object);
}
/**
* Validates if the received object is an JSON object and not an array
* @param {Object} object The object to validate
*/
const isObject = object => (object !== null && typeof object === 'object' && !Array.isArray(object));

function base64(value) {
return Buffer.from(value).toString('base64');
}
/**
* Encodes the received value into a base64 string
* @param {String} value value
*/
const base64 = value => (Buffer.from(value).toString('base64'));

module.exports = {
isObject,
Expand Down
2 changes: 1 addition & 1 deletion lib/solr.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class Solr {
* @example
* await multiRemove(model, { myField: { type: 'greater', value: 10 } });
*/
async mutliRemove(model, filters) {
async multiRemove(model, filters) {

this._validateModel(model);

Expand Down
9 changes: 4 additions & 5 deletions tests/solr-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ describe('Solr', () => {
});

[

null,
undefined,
'string',
Expand Down Expand Up @@ -677,7 +676,7 @@ describe('Solr', () => {
}
});

await assert.doesNotReject(solr.mutliRemove(model, { field: 'value', otherField: { type: 'lesserOrEqual', value: 10 } }));
await assert.doesNotReject(solr.multiRemove(model, { field: 'value', otherField: { type: 'lesserOrEqual', value: 10 } }));

request.done();
});
Expand All @@ -692,7 +691,7 @@ describe('Solr', () => {
}
});

await assert.rejects(solr.mutliRemove(model), {
await assert.rejects(solr.multiRemove(model), {
name: 'SolrError',
code: SolrError.codes.REQUEST_FAILED
});
Expand All @@ -712,7 +711,7 @@ describe('Solr', () => {
}
});

await assert.rejects(solr.mutliRemove(model, { field: 'value' }), {
await assert.rejects(solr.multiRemove(model, { field: 'value' }), {
name: 'SolrError',
code: SolrError.codes.INTERNAL_SOLR_ERROR
});
Expand All @@ -722,7 +721,7 @@ describe('Solr', () => {

it('Should throw when the received model is invalid', async () => {

await assert.rejects(solr.mutliRemove(), {
await assert.rejects(solr.multiRemove(), {
name: 'SolrError',
code: SolrError.codes.INVALID_MODEL
});
Expand Down

0 comments on commit f59f624

Please sign in to comment.