New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@brainnit/adonisjs-scout

Package Overview
Dependencies
Maintainers
2
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@brainnit/adonisjs-scout - npm Package Compare versions

Comparing version 0.1.7 to 0.1.8

providers/IndexKeeperProvider.js

7

package.json
{
"name": "@brainnit/adonisjs-scout",
"version": "0.1.7",
"version": "0.1.8",
"description": "Adonis Scout provides a driver based solution for searching your Lucid models, just like Laravel Scout.",

@@ -36,5 +36,8 @@ "keywords": [

"lodash": "^4.17.11",
"macroable": "^2.0.1"
"macroable": "^2.0.1",
"pretty-hrtime": "^1.0.3",
"require-all": "^3.0.0"
},
"devDependencies": {
"@adonisjs/ace": "^5.0.8",
"@adonisjs/fold": "^4.0.9",

@@ -41,0 +44,0 @@ "@adonisjs/lucid": "^6.1.3",

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

/**
* Registra namespaces no IoC container.
* Register namespaces on IoC container.
*

@@ -10,0 +10,0 @@ * @method register

@@ -20,3 +20,4 @@ # AdonisJs Scout

// ...
'@brainnit/adonisjs-scout/providers/ScoutProvider'
'@brainnit/adonisjs-scout/providers/ScoutProvider',
'@brainnit/adonisjs-scout/providers/IndexKeeperProvider'
];

@@ -23,0 +24,0 @@ ```

'use strict'
class Import {
const { ioc } = require('@adonisjs/fold')
const { Command } = require('@adonisjs/ace')
const prettyHrTime = require('pretty-hrtime')
class Import extends Command {
constructor (Helpers, Scout) {
super()
this._appRoot = Helpers.appRoot()
this.Scout = Scout
}
/**
* IoC container injections
*
* @method inject
*
* @return {Array}
*/
static get inject () {
return ['Adonis/Src/Helpers', 'Adonis/Addons/Scout']
}
/**
* Command signature required by ace
*
* @method signature
*
* @return {String}
*/
static get signature () {
return `
scout:import { model: Model to sync to index }
{ -c, --chunck: Chunk size }
`
}
/**
* Command description
*
* @method description
*
* @return {String}
*/
static get description () {
return 'Import the given model into the search index'
}
/**
* Method called when command is executed. This method will
* sync all models to index after creating it.
*
* @method handle
*
* @param {Object} args
*
* @return {void|Array}
*/
async handle ({ model }, { chunck }) {
try {
const startTime = process.hrtime()
if (!model) {
return this.viaAce ? this.warn(`Nothing to do`) : `Nothing to do`
}
chunck = chunck || 25
const Model = ioc.make(`App/Models/${model}`)
let lastPage = 1
for (let page = 1; page <= lastPage; page++) {
/**
* Search for first users
*/
let users = await Model.query().paginate(page, chunck)
/**
* Make all users searchable adding them to index
*/
await users.searchable()
lastPage = users.lastPage
this.info(`Imported ${page * chunck} models...`)
}
const endTime = process.hrtime(startTime)
this.success(`Imported all models in ${prettyHrTime(endTime)}`)
} catch (error) {
console.log(error)
process.exit(1)
}
}
}
module.exports = Import

@@ -458,3 +458,3 @@ 'use strict'

const exists = await this.Client.indices.exists(requestPayload)
const method = exists ? '_updateIndex' : '_createIndex'
const method = exists ? 'updateIndex' : 'createIndex'

@@ -474,3 +474,3 @@ return this[method](index, params)

*/
_createIndex (index, params = {}) {
createIndex (index, params = {}) {
const requestPayload = {

@@ -502,3 +502,3 @@ index,

*/
_updateIndex (index, params = {}) {
updateIndex (index, params = {}) {
const requestPayload = {

@@ -505,0 +505,0 @@ index,

@@ -99,2 +99,6 @@ 'use strict'

startCursor () {
if (!this.count()) {
return null
}
return this.constructor.encodeCursor(

@@ -111,2 +115,6 @@ this.getCollection().first().getSearchableCursor(this.cursorColumns)

endCursor () {
if (!this.count()) {
return null
}
return this.constructor.encodeCursor(

@@ -113,0 +121,0 @@ this.getCollection().last().getSearchableCursor(this.cursorColumns)

@@ -62,2 +62,21 @@ 'use strict'

/**
*
*
* By default it is empty.
*
* @override
*
* @method searchableRules
*
* @static
*
* @return {Array|String} ES6 Class
*/
if (!Model.searchableRules) {
Model.searchableRules = function () {
return []
}
}
/**
* The search rules to be used for searching data in reusable ways.

@@ -64,0 +83,0 @@ * The return value(s) must always be ES6 class(es).

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