mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
Add types for mongodb-queue (#43021)
This commit is contained in:
Vendored
+49
@@ -0,0 +1,49 @@
|
||||
// Type definitions for mongodb-queue 4.0
|
||||
// Project: https://github.com/chilts/mongodb-queue
|
||||
// Definitions by: FiveOFive <https://github.com/FiveOFive>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.0
|
||||
|
||||
import { Db, MongoError } from 'mongodb';
|
||||
|
||||
declare function mongodbQueue(db: Db, name: string, opts?: mongodbQueue.QueueOptions): mongodbQueue.Queue;
|
||||
|
||||
declare namespace mongodbQueue {
|
||||
class Queue {
|
||||
constructor(db: Db, name: string, opts?: QueueOptions);
|
||||
|
||||
createIndexes(callback: QueueCallback<string>): void;
|
||||
add(payload: string, callback: QueueCallback<string>): void;
|
||||
add(payload: string, opts: QueueOptions, callback: QueueCallback<string>): void;
|
||||
get(callback: QueueCallback<QueueMessage | undefined>): void;
|
||||
get(opts: QueueOptions, callback: QueueCallback<QueueMessage | undefined>): void;
|
||||
ping(ack: string, callback: QueueCallback<string>): void;
|
||||
ping(ack: string, opts: QueueOptions, callback: QueueCallback<string>): void;
|
||||
ack(ack: string, callback: QueueCallback<string>): void;
|
||||
clean(callback: QueueCallback<any>): void;
|
||||
total(callback: QueueCallback<number>): void;
|
||||
size(callback: QueueCallback<number>): void;
|
||||
inflight(callback: QueueCallback<number>): void;
|
||||
done(callback: QueueCallback<number>): void;
|
||||
}
|
||||
|
||||
interface QueueOptions {
|
||||
deadQueue?: string;
|
||||
delay?: number;
|
||||
maxRetries?: number;
|
||||
visibility?: number;
|
||||
}
|
||||
|
||||
interface QueueMessage {
|
||||
ack: string;
|
||||
id: string;
|
||||
payload: string;
|
||||
tries: number;
|
||||
}
|
||||
|
||||
interface QueueCallback<T> {
|
||||
(err: MongoError | Error, result: T): void;
|
||||
}
|
||||
}
|
||||
|
||||
export = mongodbQueue;
|
||||
@@ -0,0 +1,88 @@
|
||||
import * as queue from 'mongodb-queue';
|
||||
import { MongoClient } from 'mongodb';
|
||||
|
||||
const mongoClient = new MongoClient('mongodb://localhost:27017');
|
||||
mongoClient.connect().then(() => {
|
||||
const opts: queue.QueueOptions = {
|
||||
delay: 0,
|
||||
maxRetries: 5,
|
||||
visibility: 30,
|
||||
};
|
||||
const mongoQueue = queue(mongoClient.db('test'), 'test-queue', opts);
|
||||
|
||||
mongoQueue.add('foo', (err, res) => {
|
||||
if (err) {
|
||||
console.log('error: ' + err);
|
||||
} else {
|
||||
const msgId: string = res;
|
||||
console.log('msgId: ' + msgId);
|
||||
}
|
||||
});
|
||||
|
||||
mongoQueue.get((err, res) => {
|
||||
if (err) {
|
||||
console.log('error: ' + err);
|
||||
} else {
|
||||
if (res) {
|
||||
const msg: queue.QueueMessage = res;
|
||||
console.log('msg: ' + JSON.stringify(msg));
|
||||
} else {
|
||||
console.log('no messages available');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
mongoQueue.ping('testAck', (err, res) => {
|
||||
if (err) {
|
||||
console.log('error: ' + err);
|
||||
} else {
|
||||
const msgId: string = res;
|
||||
console.log('msgId: ' + msgId);
|
||||
}
|
||||
});
|
||||
|
||||
mongoQueue.ack('testAck', (err, res) => {
|
||||
if (err) {
|
||||
console.log('error: ' + err);
|
||||
} else {
|
||||
const msgId: string = res;
|
||||
console.log('msgId: ' + msgId);
|
||||
}
|
||||
});
|
||||
|
||||
mongoQueue.total((err, res) => {
|
||||
if (err) {
|
||||
console.log('error: ' + err);
|
||||
} else {
|
||||
const total: number = res;
|
||||
console.log('total: ' + total);
|
||||
}
|
||||
});
|
||||
|
||||
mongoQueue.size((err, res) => {
|
||||
if (err) {
|
||||
console.log('error: ' + err);
|
||||
} else {
|
||||
const size: number = res;
|
||||
console.log('size: ' + size);
|
||||
}
|
||||
});
|
||||
|
||||
mongoQueue.inflight((err, res) => {
|
||||
if (err) {
|
||||
console.log('error: ' + err);
|
||||
} else {
|
||||
const inflight: number = res;
|
||||
console.log('inflight: ' + inflight);
|
||||
}
|
||||
});
|
||||
|
||||
mongoQueue.done((err, res) => {
|
||||
if (err) {
|
||||
console.log('error: ' + err);
|
||||
} else {
|
||||
const done: number = res;
|
||||
console.log('done: ' + done);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"mongodb-queue-tests.ts"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user