Comparing version 0.2.4 to 0.2.5
@@ -22,4 +22,5 @@ /// <reference types="node" /> | ||
}): this; | ||
hasNext(): Promise<boolean>; | ||
fetch(): Promise<T>; | ||
fetchAll(): Promise<T[]>; | ||
} |
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments)).next()); | ||
}); | ||
}; | ||
const events_1 = require("events"); | ||
@@ -14,6 +22,2 @@ class Cursor extends events_1.EventEmitter { | ||
this.cursor = cursor; | ||
this.cursor.on('data', document => this.emit('data', document)); | ||
this.cursor.on('error', err => this.emit('error', err)); | ||
this.cursor.on('end', () => this.emit('end')); | ||
this.cursor.on('readable', () => this.emit('readable')); | ||
} | ||
@@ -54,50 +58,23 @@ clone() { | ||
} | ||
hasNext() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
return this.cursor.hasNext(); | ||
}); | ||
} | ||
fetch() { | ||
return new Promise((resolve, reject) => { | ||
this.cursor.hasNext((err, hasNext) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
else if (hasNext) { | ||
this.cursor.next((err, document) => { | ||
if (err) { | ||
reject(err); | ||
} | ||
else { | ||
resolve(document); | ||
} | ||
}); | ||
} | ||
else { | ||
this.rewind(); | ||
resolve(); | ||
} | ||
}); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (yield this.cursor.hasNext()) { | ||
return yield this.cursor.next(); | ||
} | ||
return null; | ||
}); | ||
} | ||
fetchAll() { | ||
this.rewind(); | ||
return new Promise((resolve, reject) => { | ||
const data = []; | ||
const next = () => { | ||
this.cursor.hasNext((err, hasNext) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
if (hasNext) { | ||
this.cursor.next((err, document) => { | ||
if (err) { | ||
return reject(err); | ||
} | ||
data.push(document); | ||
next(); | ||
}); | ||
} | ||
else { | ||
this.rewind(); | ||
resolve(data); | ||
} | ||
}); | ||
}; | ||
next(); | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this.rewind(); | ||
const result = []; | ||
while (yield this.cursor.hasNext()) { | ||
result.push(yield this.cursor.next()); | ||
} | ||
return result; | ||
}); | ||
@@ -104,0 +81,0 @@ } |
{ | ||
"name": "mongot", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"description": "A lightweight typed MongoDb library for TypeScript.", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
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
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
120002
1846