Comparing version 1.0.0 to 2.0.0
@@ -6,2 +6,3 @@ /** | ||
exports.Index = require('./lib/index'); | ||
exports.syncManager = require('./lib/sync-manager'); | ||
exports.syncManager = require('./lib/sync-manager'); | ||
exports.replicaManager = require('./lib/replica-manager'); |
@@ -1,3 +0,1 @@ | ||
'use strict'; | ||
/** | ||
@@ -7,6 +5,6 @@ * Module dependencies. | ||
var _ = require('lodash'); | ||
var async = require('async'); | ||
var events = require('events'); | ||
var util = require('util'); | ||
const _ = require('lodash'); | ||
const async = require('async'); | ||
const events = require('events'); | ||
const util = require('util'); | ||
@@ -29,13 +27,13 @@ /** | ||
function Index(options) { | ||
this.name = options.name; | ||
this.searcher = options.searcher; | ||
this.formatters = options.formatters || {}; | ||
this.templates = options.templates || {}; | ||
this.filters = options.filters || {}; | ||
this.joins = options.joins || {}; | ||
this.lang = options.lang || 'ENGLISH'; | ||
function Index({ name, searcher, indexers, formatters = {}, templates = {}, filters = {}, joins = {}, lang = 'ENGLISH' }) { | ||
this.name = name; | ||
this.searcher = searcher; | ||
this.formatters = formatters; | ||
this.templates = templates; | ||
this.filters = filters; | ||
this.joins = joins; | ||
this.lang = lang; | ||
// Accept single indexer. | ||
this.indexers = _.isArray(options.indexers) ? options.indexers : [options.indexers]; | ||
this.indexers = _.isArray(indexers) ? indexers : [indexers]; | ||
@@ -56,3 +54,3 @@ events.EventEmitter.call(this); | ||
Index.prototype.create = function create(documents, options, callback) { | ||
var index = this; | ||
const index = this; | ||
@@ -93,8 +91,8 @@ // search(query, callback) | ||
// Hence the reduce. | ||
fields: _.reduce(document, function (accumulator, values, key) { | ||
fields: _.reduce(document, (accumulator, values, key) => { | ||
// rationalize input | ||
if (!_.isArray(values)) values = [ values ]; | ||
// convert into field entries | ||
values.forEach(function(value) { | ||
accumulator.push({ name: key, value: value }); | ||
values.forEach((value) => { | ||
accumulator.push({ name: key, value }); | ||
}); | ||
@@ -114,3 +112,3 @@ return accumulator; | ||
function createInClient(client, callback) { | ||
client.documents.create(index.name, documents, function (err) { | ||
client.documents.create(index.name, documents, (err) => { | ||
// Errors are not blocking indexation, we just emit an event. | ||
@@ -132,3 +130,3 @@ if (err) index.emit('error', err, client, index.name, documents); | ||
Index.prototype.destroy = function destroy(values, options, callback) { | ||
var index = this; | ||
const index = this; | ||
@@ -158,8 +156,8 @@ // search(query, callback) | ||
function destroyInClient(client, callback) { | ||
var opts = { | ||
const opts = { | ||
field: options.field, | ||
values: values | ||
values | ||
}; | ||
client.documents.destroy(index.name, opts, function (err) { | ||
client.documents.destroy(index.name, opts, (err) => { | ||
// Errors are not blocking indexation, we just emit an event. | ||
@@ -182,3 +180,3 @@ if (err) index.emit('error', err, client, index.name, opts); | ||
Index.prototype.search = function search(query, options, callback) { | ||
var index = this; | ||
const index = this; | ||
@@ -194,3 +192,3 @@ // search(query, callback) | ||
template: 'default', | ||
query: query, | ||
query, | ||
lang: this.lang | ||
@@ -203,4 +201,4 @@ }); | ||
// Map filters. | ||
options.filters = _.reduce(options.filters, function (filters, value, key) { | ||
var transformer = index.filters[key]; | ||
options.filters = _.reduce(options.filters, (filters, value, key) => { | ||
const transformer = index.filters[key]; | ||
@@ -211,3 +209,3 @@ // If transformer doesn't exist, do nothing. | ||
// Map filter. | ||
var ossFilter = transformer(value, options.filterOptions); | ||
const ossFilter = transformer(value, options.filterOptions); | ||
@@ -225,6 +223,6 @@ // Do nothing if filter is not a valid object. | ||
// Map joins. | ||
options.joins = _.map(options.joins, function (join, name) { | ||
options.joins = _.map(options.joins, (join, name) => { | ||
// Get join index options. | ||
var indexJoin = index.joins[name]; | ||
const indexJoin = index.joins[name]; | ||
@@ -241,3 +239,3 @@ // If join is not found on the index, return null. | ||
// Get template. | ||
var template = indexJoin.index.templates[join.template]; | ||
const template = indexJoin.index.templates[join.template]; | ||
@@ -251,4 +249,4 @@ // If template is not found, return null. | ||
// Build query. | ||
var query = _.map(template.searchFields, function (field) { | ||
return field.field + ':(' + join.query + ')^' + field.boost; | ||
let query = _.map(template.searchFields, (field) => { | ||
return `${field.field}:(${join.query})^${field.boost}`; | ||
}) | ||
@@ -259,12 +257,10 @@ .join(' OR '); | ||
// Build filters and append them to query. | ||
query = _.map(join.filters, function (value, key) { | ||
query = _.map(join.filters, (value, key) => { | ||
return indexJoin.index.filters[key](value); | ||
}) | ||
.filter(function (filter) { | ||
return filter.type === 'QueryFilter'; | ||
.filter((filter) => filter.type === 'QueryFilter') | ||
.map((filter) => { | ||
return filter.negative ? `-(${filter.query})` : `(${filter.query})`; | ||
}) | ||
.map(function (filter) { | ||
return filter.negative ? '-(' + filter.query + ')' : '(' + filter.query + ')'; | ||
}) | ||
.concat(['(' + query + ')']) | ||
.concat([`(${query})`]) | ||
.join(' AND '); | ||
@@ -277,5 +273,3 @@ | ||
}) | ||
.filter(function (join) { | ||
return join; | ||
}); | ||
.filter((join) => join) | ||
@@ -285,3 +279,3 @@ // Remove unknown keys. | ||
this.searcher.search(this.name, options, function (err, result) { | ||
this.searcher.search(this.name, options, (err, result) => { | ||
if (err) return callback(err); | ||
@@ -307,3 +301,3 @@ if (! result || ! result.documents) return callback(null, { documents: [] }); | ||
function formatDocument(document) { | ||
return document.fields.reduce(function (obj, field) { | ||
return document.fields.reduce((obj, field) => { | ||
obj[field.fieldName] = field.values && field.values[0] || null; | ||
@@ -313,2 +307,2 @@ return obj; | ||
} | ||
}; | ||
}; |
@@ -5,4 +5,4 @@ /** | ||
var _ = require('lodash'); | ||
var async = require('async'); | ||
const _ = require('lodash'); | ||
const async = require('async'); | ||
@@ -28,3 +28,3 @@ /** | ||
var commands = []; | ||
let commands = []; | ||
@@ -40,3 +40,3 @@ clients.forEach(dropSchemas); | ||
function dropSchemas(client) { | ||
commands = commands.concat(names.map(function (name) { | ||
commands = commands.concat(names.map((name) => { | ||
return client.indexes.destroy.bind(client.indexes, name); | ||
@@ -72,5 +72,5 @@ })); | ||
// Create indexes. | ||
var creationCommands = schemas.map(function (schema) { | ||
return function (callback) { | ||
client.indexes.exists(schema.name, function (err) { | ||
const creationCommands = schemas.map((schema) => { | ||
return (callback) => { | ||
client.indexes.exists(schema.name, (err) => { | ||
if (! err) return callback(); | ||
@@ -83,9 +83,9 @@ client.indexes.create(schema.name, callback); | ||
// Check differences between existing schemas and input schemas. | ||
async.series(creationCommands, function (err) { | ||
async.series(creationCommands, (err) => { | ||
if (err) return callback(err); | ||
async.each(schemas, function (schema, callback) { | ||
client.indexes.fields.list(schema.name, function (err, res) { | ||
async.each(schemas, (schema, callback) => { | ||
client.indexes.fields.list(schema.name, (err, res) => { | ||
if (err) return callback(err); | ||
var commands = []; | ||
let commands = []; | ||
@@ -111,11 +111,12 @@ // Sync templates. | ||
function schemaDiff(ossSchema, inputSchema) { | ||
var formattedInputSchema = { | ||
const formattedInputSchema = { | ||
unique: inputSchema.uniqueField, | ||
default: inputSchema.defaultField, | ||
fields: inputSchema.fields.map(function (field) { | ||
var formattedField = { | ||
name: field.name, | ||
indexed: field.indexed ? 'YES' : 'NO', | ||
stored: field.stored ? 'YES' : 'NO', | ||
termVector: field.termVector ? 'YES' : 'NO' | ||
const { name, indexed, stored, termVector } = field; | ||
let formattedField = { | ||
name, | ||
indexed: indexed ? 'YES' : 'NO', | ||
stored: stored ? 'YES' : 'NO', | ||
termVector: termVector ? 'YES' : 'NO' | ||
}; | ||
@@ -141,3 +142,3 @@ | ||
function syncTemplates(schema, callback) { | ||
var commands = []; | ||
let commands = []; | ||
@@ -147,3 +148,3 @@ schema.templates = schema.templates || []; | ||
// Create / update templates. | ||
commands = commands.concat(schema.templates.map(function (template) { | ||
commands = commands.concat(schema.templates.map((template) => { | ||
return client.templates.createOrUpdate.bind( | ||
@@ -171,3 +172,3 @@ client.templates, | ||
function deleteTemplates(schema, callback) { | ||
client.templates.list(schema.name, function (err, res) { | ||
client.templates.list(schema.name, (err, res) => { | ||
if (err) return callback(err); | ||
@@ -188,3 +189,3 @@ if (! res.templates) return callback(); | ||
function deleteTemplate(schema, template, callback) { | ||
var schemaTemplateNames = _.pluck(schema.templates, 'name'); | ||
const schemaTemplateNames = _.pluck(schema.templates, 'name'); | ||
if(_.contains(schemaTemplateNames, template.name)) return callback(); | ||
@@ -201,6 +202,6 @@ client.templates.destroy(schema.name, template.name, callback); | ||
function syncFields(schema, callback) { | ||
var commands = []; | ||
let commands = []; | ||
// Create / update fields. | ||
commands = commands.concat(schema.fields.map(function (field) { | ||
commands = commands.concat(schema.fields.map((field) => { | ||
return client.fields.createOrUpdate.bind(client.indexes, schema.name, field); | ||
@@ -232,3 +233,3 @@ })); | ||
function deleteFields(schema, callback) { | ||
client.fields.list(schema.name, function (err, res) { | ||
client.fields.list(schema.name, (err, res) => { | ||
if (err) return callback(err); | ||
@@ -249,3 +250,3 @@ if (! res.fields) return callback(); | ||
function deleteField(schema, field, callback) { | ||
var schemaFieldNames = _.pluck(schema.fields, 'name'); | ||
const schemaFieldNames = _.map(schema.fields, 'name'); | ||
if(_.contains(schemaFieldNames, field.name)) return callback(); | ||
@@ -255,2 +256,2 @@ client.fields.destroy(schema.name, field.name, callback); | ||
} | ||
} | ||
} |
{ | ||
"name": "oss-odm", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Object document mapper for Open Search Server.", | ||
@@ -24,7 +24,7 @@ "main": "index.js", | ||
"dependencies": { | ||
"async": "~0.9.0", | ||
"async": "2.1.4", | ||
"lodash": "~3.7.0" | ||
}, | ||
"devDependencies": { | ||
"node-oss-client": "~1.0.0", | ||
"node-oss-client": "2.0.1", | ||
"sinon-chai": "~2.7.0", | ||
@@ -31,0 +31,0 @@ "chai": "~2.3.0", |
@@ -17,6 +17,6 @@ # oss-odm [![Build Status](https://travis-ci.org/lemonde/oss-odm.svg?branch=master)](https://travis-ci.org/lemonde/oss-odm) | ||
```js | ||
var oss = require('node-oss-client'); | ||
var Index = require('oss-odm').Index; | ||
const oss = require('node-oss-client'); | ||
const Index = require('oss-odm').Index; | ||
var index = new Index({ | ||
const index = new Index({ | ||
name: 'my_index', | ||
@@ -28,6 +28,6 @@ indexers: oss.createClient(), | ||
// Insert a new document in "my_index". | ||
index.create({ title: 'My first document' }, function (err) { ... }); | ||
index.create({ title: 'My first document' }, (err) => { ... }); | ||
// Search in "my_index". | ||
index.search('my query', function (err, res) { | ||
index.search('my query', (err, res) => { | ||
console.log(res.documents); // [{ title: 'My first document' }] | ||
@@ -83,3 +83,3 @@ }); | ||
var searcher = oss.createClient({ host: 'searcher' }); | ||
new Index({ searcher: searcher }); | ||
new Index({ searcher }); | ||
``` | ||
@@ -193,3 +193,3 @@ | ||
returnScores: false, | ||
eturnFacets: false | ||
returnFacets: false | ||
} | ||
@@ -216,3 +216,3 @@ } | ||
} | ||
], function (err) { ... }); | ||
], (err) => { ... }); | ||
``` | ||
@@ -231,3 +231,3 @@ | ||
{ title: 'My first document' } | ||
], { lang: 'FRENCH' }, function (err) { ... }); | ||
], { lang: 'FRENCH' }, (err) => { ... }); | ||
``` | ||
@@ -240,3 +240,3 @@ | ||
```js | ||
index.destroy(['182', '85'], function (err) { ... }); | ||
index.destroy(['182', '85'], (err) => { ... }); | ||
``` | ||
@@ -253,3 +253,3 @@ | ||
```js | ||
index.destroy(['bob', 'tom'], { field: 'name' }, function (err) { ... }); | ||
index.destroy(['bob', 'tom'], { field: 'name' }, (err) => { ... }); | ||
``` | ||
@@ -262,3 +262,3 @@ | ||
```js | ||
index.search('my query', function (err, res) { ... }); | ||
index.search('my query', (err, res) => { ... }); | ||
``` | ||
@@ -275,3 +275,3 @@ | ||
```js | ||
index.search('my query', { lang: 'FRENCH' }, function (err, res) { ... }); | ||
index.search('my query', { lang: 'FRENCH' }, (err, res) => { ... }); | ||
``` | ||
@@ -286,3 +286,3 @@ | ||
```js | ||
index.search('my query', { template: 'custom' }, function (err, res) { ... }); | ||
index.search('my query', { template: 'custom' }, (err, res) => { ... }); | ||
``` | ||
@@ -304,3 +304,3 @@ | ||
} | ||
}, function (err, res) { ... }); | ||
}, (err, res) => { ... }); | ||
``` | ||
@@ -335,4 +335,4 @@ | ||
```js | ||
var indexer1 = oss.createClient({ host: 'indexer1' }); | ||
var indexer2 = oss.createClient({ host: 'indexer2' }); | ||
const indexer1 = oss.createClient({ host: 'indexer1' }); | ||
const indexer2 = oss.createClient({ host: 'indexer2' }); | ||
@@ -363,4 +363,4 @@ syncManager.sync([indexer1, indexer2], [ | ||
```js | ||
var indexer1 = oss.createClient({ host: 'indexer1' }); | ||
var indexer2 = oss.createClient({ host: 'indexer2' }); | ||
const indexer1 = oss.createClient({ host: 'indexer1' }); | ||
const indexer2 = oss.createClient({ host: 'indexer2' }); | ||
@@ -370,5 +370,17 @@ syncManager.drop([indexer1, indexer2], ['articles']); | ||
### replicaManager.replicateAllIndexes(clients, schemas, cb) | ||
Creates as many as replication indexes (based on schemas argument) on searchers passed as argument in clients and starts a replication on each of the searchers. | ||
```js | ||
const indexer1 = oss.createClient({ host: 'indexer1' }); | ||
const indexes = [ { name: 'my_index_1' }, { name: 'my_index_2' } ] | ||
replicaManager.replicateAllIndexes(indexer1, indexes, (err, res ) => { | ||
// Code callback here .... | ||
}); | ||
``` | ||
## License | ||
MIT |
@@ -1,14 +0,12 @@ | ||
var oss = require('node-oss-client'); | ||
var Index = require('../lib/index'); | ||
var expect = require('chai').use(require('sinon-chai')).expect; | ||
var sinon = require('sinon'); | ||
var _ = require('lodash'); | ||
const oss = require('node-oss-client'); | ||
const Index = require('../lib/index'); | ||
const _ = require('lodash'); | ||
describe('Index', function () { | ||
describe('Index', () => { | ||
describe('#create', function () { | ||
var indexer1, indexer2, index, documents; | ||
var expectedOssInput, expectedOssInputFields1, expectedOssInputFields2; | ||
describe('#create', () => { | ||
let indexer1, indexer2, index, documents; | ||
let expectedOssInput, expectedOssInputFields1, expectedOssInputFields2; | ||
beforeEach(function () { | ||
beforeEach(() => { | ||
indexer1 = createOssClient(); | ||
@@ -58,3 +56,3 @@ indexer2 = createOssClient(); | ||
function createOssClient() { | ||
var client = oss.createClient(); | ||
const client = oss.createClient(); | ||
sinon.stub(client.documents, 'create').yields(); | ||
@@ -65,4 +63,4 @@ return client; | ||
it('should format to correct OSS inputs', function (done) { | ||
index.create(documents, function (err) { | ||
it('should format to correct OSS inputs', (done) => { | ||
index.create(documents, (err) => { | ||
if (err) return done(err); | ||
@@ -74,10 +72,10 @@ expect(indexer1.documents.create).to.have.been.calledWith('my_index', expectedOssInput); | ||
describe('when given a single document', function() { | ||
it('should format to correct OSS inputs', function (done) { | ||
var singleDocument = documents[1]; | ||
var singleExpectedOssInput = [{ | ||
describe('when given a single document', () => { | ||
it('should format to correct OSS inputs', (done) => { | ||
const singleDocument = documents[1]; | ||
const singleExpectedOssInput = [{ | ||
lang: 'ENGLISH', | ||
fields: expectedOssInputFields2 | ||
}]; | ||
index.create(singleDocument, function (err) { | ||
index.create(singleDocument, (err) => { | ||
if (err) return done(err); | ||
@@ -90,4 +88,4 @@ expect(indexer1.documents.create).to.have.been.calledWith('my_index', singleExpectedOssInput); | ||
it('should create documents on each indexer', function (done) { | ||
index.create(documents, function (err) { | ||
it('should create documents on each indexer', (done) => { | ||
index.create(documents, (err) => { | ||
if (err) return done(err); | ||
@@ -100,7 +98,7 @@ expect(indexer1.documents.create).to.have.been.calledWith('my_index', expectedOssInput); | ||
it('should emit the "create" event', function (done) { | ||
var spy = sinon.spy(); | ||
it('should emit the "create" event', (done) => { | ||
const spy = sinon.spy(); | ||
index.on('create', spy); | ||
index.create(documents, function (err) { | ||
index.create(documents, (err) => { | ||
if (err) return done(err); | ||
@@ -113,12 +111,12 @@ expect(spy).to.have.been.calledWith(indexer1, 'my_index', expectedOssInput); | ||
describe('on error', function() { | ||
it('should emit an "error" event', function (done) { | ||
var spy = sinon.spy(); | ||
describe('on error', () => { | ||
it('should emit an "error" event', (done) => { | ||
const spy = sinon.spy(); | ||
index.on('error', spy); | ||
var indexError = new Error('Indexing error.'); | ||
const indexError = new Error('Indexing error.'); | ||
indexer1.documents.create.restore(); | ||
sinon.stub(indexer1.documents, 'create').yields(indexError); | ||
index.create(documents, function (err) { | ||
index.create(documents,(err) => { | ||
if (err) return done(err); | ||
@@ -131,3 +129,3 @@ expect(spy).to.have.been.calledWith(indexError, indexer1, 'my_index', expectedOssInput); | ||
describe('options', function() { | ||
describe('options', () => { | ||
var specificExpectedOssInput; | ||
@@ -138,8 +136,8 @@ beforeEach(function() { | ||
describe('lang', function() { | ||
it('should be handled', function (done) { | ||
describe('lang', () => { | ||
it('should be handled', (done) => { | ||
specificExpectedOssInput[0].lang = 'FRENCH'; | ||
specificExpectedOssInput[1].lang = 'FRENCH'; | ||
index.create(documents, { lang: 'FRENCH' }, function (err) { | ||
index.create(documents, { lang: 'FRENCH' }, (err) => { | ||
if (err) return done(err); | ||
@@ -153,5 +151,5 @@ expect(indexer1.documents.create).to.have.been.calledWith('my_index', specificExpectedOssInput); | ||
describe('custom formatter', function() { | ||
it('should be handled', function (done) { | ||
index.formatters.input = function (document) { | ||
describe('custom formatter', () => { | ||
it('should be handled', (done) => { | ||
index.formatters.input = (document) => { | ||
document.x = 'y'; | ||
@@ -164,3 +162,3 @@ return document; | ||
index.create(documents, function (err) { | ||
index.create(documents, (err) => { | ||
if (err) return done(err); | ||
@@ -175,6 +173,6 @@ expect(indexer1.documents.create).to.have.been.calledWith('my_index', specificExpectedOssInput); | ||
describe('#destroy', function () { | ||
var indexer1, indexer2, index, values; | ||
describe('#destroy', () => { | ||
let indexer1, indexer2, index, values; | ||
beforeEach(function () { | ||
beforeEach(() => { | ||
indexer1 = createOssClient(); | ||
@@ -191,3 +189,3 @@ indexer2 = createOssClient(); | ||
function createOssClient() { | ||
var client = oss.createClient(); | ||
const client = oss.createClient(); | ||
sinon.stub(client.documents, 'destroy').yields(); | ||
@@ -198,12 +196,12 @@ return client; | ||
it('should destroy documents on each indexer', function (done) { | ||
index.destroy(values, function (err) { | ||
it('should destroy documents on each indexer', (done) => { | ||
index.destroy(values, (err) => { | ||
if (err) return done(err); | ||
expect(indexer1.documents.destroy).to.have.been.calledWith('my_index', { | ||
field: 'id', | ||
values: values | ||
values | ||
}); | ||
expect(indexer2.documents.destroy).to.have.been.calledWith('my_index', { | ||
field: 'id', | ||
values: values | ||
values | ||
}); | ||
@@ -214,15 +212,15 @@ done(); | ||
it('should emit "destroy" event', function (done) { | ||
var spy = sinon.spy(); | ||
it('should emit "destroy" event', (done) => { | ||
const spy = sinon.spy(); | ||
index.on('destroy', spy); | ||
index.destroy(values, function (err) { | ||
index.destroy(values, (err) => { | ||
if (err) return done(err); | ||
expect(spy).to.have.been.calledWith(indexer1, 'my_index', { | ||
field: 'id', | ||
values: values | ||
values | ||
}); | ||
expect(spy).to.have.been.calledWith(indexer2, 'my_index', { | ||
field: 'id', | ||
values: values | ||
values | ||
}); | ||
@@ -233,11 +231,11 @@ done(); | ||
it('should emit an "error" event', function (done) { | ||
var spy = sinon.spy(); | ||
it('should emit an "error" event', (done) => { | ||
const spy = sinon.spy(); | ||
index.on('error', spy); | ||
var indexError = new Error('Indexing error.'); | ||
const indexError = new Error('Indexing error.'); | ||
indexer1.documents.destroy.restore(); | ||
sinon.stub(indexer1.documents, 'destroy').yields(indexError); | ||
index.destroy(values, function (err) { | ||
index.destroy(values, (err) => { | ||
if (err) return done(err); | ||
@@ -252,12 +250,12 @@ expect(spy).to.have.been.calledWith(indexError, indexer1, 'my_index', { | ||
it('should be possible to add options', function (done) { | ||
index.destroy(values, { field: 'id_test' }, function (err) { | ||
it('should be possible to add options', (done) => { | ||
index.destroy(values, { field: 'id_test' }, (err) => { | ||
if (err) return done(err); | ||
expect(indexer1.documents.destroy).to.have.been.calledWith('my_index', { | ||
field: 'id_test', | ||
values: values | ||
values | ||
}); | ||
expect(indexer2.documents.destroy).to.have.been.calledWith('my_index', { | ||
field: 'id_test', | ||
values: values | ||
values | ||
}); | ||
@@ -269,4 +267,4 @@ done(); | ||
describe('#search', function () { | ||
var index, searcher, searchResult; | ||
describe('#search', () => { | ||
let index, searcher, searchResult; | ||
@@ -277,9 +275,6 @@ beforeEach(function () { | ||
index = new Index({ | ||
name: 'my_index', | ||
searcher: searcher | ||
}); | ||
index = new Index({ name: 'my_index', searcher: searcher }); | ||
function createOssClient() { | ||
var client = oss.createClient(); | ||
const client = oss.createClient(); | ||
sinon.stub(client, 'search').yields(null, searchResult); | ||
@@ -290,4 +285,4 @@ return client; | ||
it('should be possible to search without options', function (done) { | ||
index.search('my query', function (err, res) { | ||
it('should be possible to search without options', (done) => { | ||
index.search('my query', (err, res) => { | ||
if (err) return done(err); | ||
@@ -305,4 +300,4 @@ expect(res.documents).to.eql([]); | ||
it('should be possible to search with options', function (done) { | ||
index.search('my query', { foo: 'bar' }, function (err, res) { | ||
it('should be possible to search with options', (done) => { | ||
index.search('my query', { foo: 'bar' }, (err, res) => { | ||
if (err) return done(err); | ||
@@ -321,6 +316,6 @@ expect(res.documents).to.eql([]); | ||
it('should extend with the default template', function (done) { | ||
it('should extend with the default template', (done) => { | ||
index.templates.default = { x: 'y' }; | ||
index.search('my query', { foo: 'bar' }, function (err, res) { | ||
index.search('my query', { foo: 'bar' }, (err, res) => { | ||
if (err) return done(err); | ||
@@ -340,6 +335,6 @@ expect(res.documents).to.eql([]); | ||
it('should extend with a custom template', function (done) { | ||
it('should extend with a custom template', (done) => { | ||
index.templates.custom = { z: 'x' }; | ||
index.search('my query', { template: 'custom' }, function (err, res) { | ||
index.search('my query', { template: 'custom' }, (err, res) => { | ||
if (err) return done(err); | ||
@@ -358,3 +353,3 @@ expect(res.documents).to.eql([]); | ||
it('should be possible to format results', function (done) { | ||
it('should be possible to format results', (done) => { | ||
searchResult.documents = [ | ||
@@ -379,3 +374,3 @@ { | ||
index.search('my query', { template: 'custom' }, function (err, res) { | ||
index.search('my query', { template: 'custom' }, (err, res) => { | ||
if (err) return done(err); | ||
@@ -387,4 +382,4 @@ expect(res.documents).to.eql([{ foo: 'bar', x: 'y' }]); | ||
it('should ignore not defined filters', function (done) { | ||
index.search('my query', { filters: { id: 'x' } }, function (err, res) { | ||
it('should ignore not defined filters', (done) => { | ||
index.search('my query', { filters: { id: 'x' } }, (err, res) => { | ||
if (err) return done(err); | ||
@@ -402,5 +397,5 @@ expect(res.documents).to.eql([]); | ||
it('should map object filter', function (done) { | ||
it('should map object filter', (done) => { | ||
index.filters = { | ||
id: function (value) { | ||
id: (value) => { | ||
return { | ||
@@ -414,3 +409,3 @@ type: 'QueryFilter', | ||
index.search('my query', { filters: { id: 'x' } }, function (err, res) { | ||
index.search('my query', { filters: { id: 'x' } }, (err, res) => { | ||
if (err) return done(err); | ||
@@ -434,5 +429,5 @@ expect(res.documents).to.eql([]); | ||
it('should map array of filters', function (done) { | ||
it('should map array of filters', (done) => { | ||
index.filters = { | ||
id: function (value) { | ||
id: (value) => { | ||
return [ | ||
@@ -453,3 +448,3 @@ { | ||
index.search('my query', { filters: { id: 'x' } }, function (err, res) { | ||
index.search('my query', { filters: { id: 'x' } }, (err, res) => { | ||
if (err) return done(err); | ||
@@ -478,10 +473,6 @@ expect(res.documents).to.eql([]); | ||
it('should ignore it if the filter returns a falsy value', function (done) { | ||
index.filters = { | ||
id: function () { | ||
return false; | ||
} | ||
}; | ||
it('should ignore it if the filter returns a falsy value', (done) => { | ||
index.filters = { id: () => false }; | ||
index.search('my query', { filters: { id: 'x' } }, function (err, res) { | ||
index.search('my query', { filters: { id: 'x' } }, (err, res) => { | ||
if (err) return done(err); | ||
@@ -499,5 +490,5 @@ expect(res.documents).to.eql([]); | ||
it('should transmit options in filters', function (done) { | ||
it('should transmit options in filters', (done) => { | ||
index.filters = { | ||
id: function (value, options) { | ||
id: (value, options) => { | ||
return { | ||
@@ -511,3 +502,3 @@ type: 'QueryFilter', | ||
index.search('my query', { filters: { id: 'x' }, filterOptions: { foo: 'bar' } }, function (err, res) { | ||
index.search('my query', { filters: { id: 'x' }, filterOptions: { foo: 'bar' } }, (err, res) => { | ||
if (err) return done(err); | ||
@@ -531,6 +522,6 @@ expect(res.documents).to.eql([]); | ||
describe('joins', function () { | ||
beforeEach(function () { | ||
describe('joins', () => { | ||
beforeEach(() => { | ||
index.filters = { | ||
id: function (value) { | ||
id: (value) => { | ||
return { | ||
@@ -569,3 +560,3 @@ type: 'QueryFilter', | ||
filters: { | ||
sectionId: function (value) { | ||
sectionId: (value) => { | ||
return { | ||
@@ -577,3 +568,3 @@ type: 'QueryFilter', | ||
}, | ||
roleId: function (value) { | ||
roleId: (value) => { | ||
return { | ||
@@ -598,3 +589,3 @@ type: 'QueryFilter', | ||
it('should support query and filters', function (done) { | ||
it('should support query and filters', (done) => { | ||
index.search('my query', { | ||
@@ -612,3 +603,3 @@ filters: { id: 210384 }, | ||
} | ||
}, function (err, res) { | ||
}, (err, res) => { | ||
if (err) return done(err); | ||
@@ -645,3 +636,3 @@ expect(res.documents).to.eql([]); | ||
it('should support empty query', function (done) { | ||
it('should support empty query', (done) => { | ||
index.search('my query', { | ||
@@ -659,3 +650,3 @@ filters: { id: 210384 }, | ||
} | ||
}, function (err, res) { | ||
}, (err, res) => { | ||
if (err) return done(err); | ||
@@ -693,2 +684,2 @@ expect(res.documents).to.eql([]); | ||
}); | ||
}); | ||
}); |
@@ -1,10 +0,8 @@ | ||
var oss = require('node-oss-client'); | ||
var manager = require('../lib/sync-manager'); | ||
var expect = require('chai').use(require('sinon-chai')).expect; | ||
var sinon = require('sinon'); | ||
const oss = require('node-oss-client'); | ||
const manager = require('../lib/sync-manager'); | ||
describe('Search sync manager', function () { | ||
var client; | ||
describe('Search sync manager', () => { | ||
let client; | ||
beforeEach(function () { | ||
beforeEach(() => { | ||
client = oss.createClient(); | ||
@@ -19,3 +17,3 @@ sinon.stub(client.indexes, 'destroy').yields(); | ||
sinon.stub(client.templates, 'destroy').yields(); | ||
sinon.stub(client.templates, 'list', function (index, callback) { | ||
sinon.stub(client.templates, 'list', (index, callback) => { | ||
if (index === 'idx1') return callback(null, { templates: [{ name: 'my_template' }] }); | ||
@@ -26,3 +24,3 @@ callback(null, { templates: [] }); | ||
afterEach(function () { | ||
afterEach(() => { | ||
client.indexes.destroy.restore(); | ||
@@ -39,4 +37,4 @@ client.indexes.create.restore(); | ||
describe('#drop', function () { | ||
it('should call client methods', function () { | ||
describe('#drop', () => { | ||
it('should call client methods', () => { | ||
manager.drop(client, ['idx1', 'idx2']); | ||
@@ -48,6 +46,6 @@ expect(client.indexes.destroy).to.be.calledWith('idx1'); | ||
describe('#sync', function () { | ||
var schemas; | ||
describe('#sync', () => { | ||
let schemas; | ||
beforeEach(function () { | ||
beforeEach(() => { | ||
schemas = [ | ||
@@ -80,3 +78,3 @@ { | ||
it('should call client methods', function () { | ||
it('should call client methods', () => { | ||
client.fields.list.yields(null, {}); | ||
@@ -105,3 +103,3 @@ | ||
it('should not call indexes.create if indexes already exists', function () { | ||
it('should not call indexes.create if indexes already exists', () => { | ||
client.fields.list.yields(null, {}); | ||
@@ -118,3 +116,3 @@ | ||
it('should do nothing if indexes are already synced', function () { | ||
it('should do nothing if indexes are already synced', () => { | ||
client.fields.list.yields(null, { | ||
@@ -121,0 +119,0 @@ unique: 'unique_field', |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
NPM Shrinkwrap
Supply chain riskPackage contains a shrinkwrap file. This may allow the package to bypass normal install procedures.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
51064
16
1282
372
1
1
+ Addedasync@2.1.4(transitive)
+ Addedlodash@4.17.21(transitive)
- Removedasync@0.9.2(transitive)
Updatedasync@2.1.4