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

atomic-algolia

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

atomic-algolia - npm Package Compare versions

Comparing version 0.3.1 to 0.3.2

11

lib/index.js
#!/usr/bin/env node
var dotenv = require("dotenv").config()

@@ -8,3 +7,3 @@ var update = require("./update")

var index = process.env.ALGOLIA_INDEX_NAME
var indexFile = process.env.ALGOLIA_INDEX_PATH
var indexFile = process.env.ALGOLIA_INDEX_FILE

@@ -17,6 +16,3 @@ if (!index)

// Log output
process.env.VERBOSE = true
update(index, indexFile, function(err, result) {
update(index, indexFile, {verbose: true}, function(err, result) {
if (err) throw err

@@ -27,6 +23,3 @@

} else {
// Don't log output
process.env.VERBOSE = false
module.exports = update
}

9

lib/update.js

@@ -11,5 +11,5 @@ var actionAdd = require("./utils/actionAdd")

var calculateOperations = require("./utils/calculateOperations")
var title = chalk`[{blue Algolia}]`
var title = "[" + chalk.blue("Algolia") + "]"
module.exports = function update(indexName, indexData, cb) {
module.exports = function update(indexName, indexData, options, cb) {
try {

@@ -27,3 +27,2 @@ if (!indexName)

var verbose = process.env.VERBOSE
var index = client.initIndex(indexName)

@@ -37,5 +36,5 @@ var newIndex = getLocalIndex(indexData)

if (verbose === true) {
if (options.verbose === true) {
console.log(title, `Adding ${operations.add.length} hits to ${indexName}`)
onsole.log(title, `Updating ${operations.update.length} hits to ${indexName}`)
console.log(title, `Updating ${operations.update.length} hits to ${indexName}`)
console.log(title, `Removing ${operations.delete.length} hits from ${indexName}`)

@@ -42,0 +41,0 @@ console.log(title, `${operations.ignore.length} hits unchanged in ${indexName}`)

@@ -21,4 +21,2 @@ var idsFromIndex = require("./idsFromIndex")

console.log(operations)
return operations

@@ -28,4 +26,4 @@ }

function findNewHits(newIndexIds, oldIndexIds) {
return newIndexIds.filter(function(hit) {
return oldIndexIds.indexOf(hit) === -1
return newIndexIds.filter(function(id) {
return oldIndexIds.indexOf(id) === -1
})

@@ -35,4 +33,4 @@ }

function findExpiredHits(newIndexIds, oldIndexIds) {
return oldIndexIds.filter(function(hit) {
return newIndexIds.indexOf(hit) === -1
return oldIndexIds.filter(function(id) {
return newIndexIds.indexOf(id) === -1
})

@@ -42,4 +40,4 @@ }

function findExistingHits(newIndexIds, oldIndexIds) {
return newIndexIds.filter(function(hit) {
return oldIndexIds.indexOf(hit) !== -1
return newIndexIds.filter(function(id) {
return oldIndexIds.indexOf(id) !== -1
})

@@ -52,2 +50,4 @@ }

console.log(shouldUpdate)
if (shouldUpdate !== true) {

@@ -63,2 +63,4 @@ return id

console.log(shouldUpdate)
if (shouldUpdate === true) {

@@ -76,8 +78,8 @@ return id

var oldHit = oldIndex.filter(function(hit) {
return hit.objectID === id
return parseInt(hit.objectID) === id
})
if (newHit.length > 0 && oldHit.length > 0 ) {
var newHitSorted = JSON.stringify(newHit, Object.keys(newHit).sort())
var oldHitSorted = JSON.stringify(oldHit, Object.keys(oldHit).sort())
var newHitSorted = JSON.stringify(newHit[0], Object.keys(newHit[0]).sort())
var oldHitSorted = JSON.stringify(oldHit[0], Object.keys(oldHit[0]).sort())
var newHash = md5(newHitSorted)

@@ -84,0 +86,0 @@ var oldHash = md5(oldHitSorted)

@@ -22,2 +22,3 @@ module.exports = async function getRemoteIndex(index) {

content.hits.forEach(function(hit) {
hit.objectID = parseInt(hit.objectID)
hits.push(hit)

@@ -24,0 +25,0 @@ })

@@ -8,5 +8,6 @@ module.exports = function idsFromIndex(index) {

if (hit.objectID !== null && hit.objectID !== undefined) {
return hits.concat(hit.objectID)
var id = parseInt(hit.objectID)
return hits.concat(id)
}
}, [])
}, []).sort()
}
{
"name": "atomic-algolia",
"version": "0.3.1",
"version": "0.3.2",
"description": "An NPM package for running atomic updates to an Algolia index",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

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