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

combee

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

combee - npm Package Compare versions

Comparing version 1.0.1 to 1.1.0

1

CHANGELOG.md
CHANGELOG
=========
* 1.1.0 Add find(), count() and distinct().
* 1.0.1 Ignore `undefined` output
* 1.0.0 Initial releast

3

package.json
{
"name": "combee",
"version": "1.0.1",
"version": "1.1.0",
"description": "Shell for bee-queue",

@@ -25,2 +25,3 @@ "main": "repl.js",

"bee-queue": "^1.2.2",
"get-value": "^3.0.1",
"redis": "^2.8.0",

@@ -27,0 +28,0 @@ "sift": "^8.5.0",

@@ -66,3 +66,7 @@ combee

combee::>
combee::> combee.foo.find('waiting', {'data.yolo': 'yolo'})
combee::> combee.foo.count('waiting', {'data.yolo': 'yolo'})
combee::> combee.foo.distinct('waiting', 'data.yolo', {})
```

@@ -9,2 +9,3 @@ #!/usr/bin/env node

const sift = require('sift').default;
const getValue = require('get-value');

@@ -184,2 +185,72 @@

}
/**
* Utility function for finding jobs that match the given criteria
* (the job type and filter).
*
* @param {string} jobType The type of job to search.
* @param {Object} filter A sift-compatible filter.
*/
async find(jobType, filter) {
const matches = this._find(jobType, filter);
console.log(matches);
repl.repl.prompt();
}
count(jobType, filter) {
this.countAsync(jobType, filter);
}
async countAsync(jobType, filter) {
const matches = await this._find(jobType, filter);
console.log(`found ${matches.length} jobs`);
repl.repl.prompt();
}
distinct(jobType, field, filter) {
this.distinctAsync(jobType, field, filter);
}
async distinctAsync(jobType, field, filter) {
const matches = await this._find(jobType, filter);
const vals = new Map();
for (const match of matches) {
const val = getValue(match, field);
vals.set(val, (vals.get(val) || 0) + 1)
}
console.log(); // purge to next line for readability
for (const [ key, count ] of vals) {
console.log(`${key}: ${count}`);
}
repl.repl.prompt();
}
async _find(jobType, filter) {
const BATCH_SIZE = 50;
const jobStats = await this.queue.checkHealth();
const count = jobStats[jobType];
const sifted = sift(filter);
let matches = [];
for (let i=0; i < count; i+=BATCH_SIZE) {
const jobs = await this.queue.getJobs(jobType, {
size: BATCH_SIZE,
start: i,
});
const matched = jobs.filter(sifted);
if (matched && matched.length) {
matches = matches.concat(matched);
}
}
return matches.map(this.stripDownJob);
}
}

@@ -186,0 +257,0 @@

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