Comparing version 8.0.0-alpha.10 to 8.0.0-alpha.12
@@ -10,5 +10,16 @@ # Contributing to Iridium | ||
Next thing to do is install Gulp on your system, just run `npm install -g gulp` and wait for that to finish. That will add the | ||
`gulp` command line utility which you will use to manage the Iridium development workflow. | ||
You'll also want to ensure that you have an instance of MongoDB running on your system, available at `127.0.0.1:27017`. The | ||
easiest way to do this is to spin up a Docker container: | ||
```bash | ||
# For a standard Docker daemon configuration | ||
docker run --rm -it -p 27017:27017 mongo:3.6 | ||
# Or if you're running Docker in Swarm mode | ||
docker service create --name mongodb -p 27017:27017 mongo:3.6 | ||
``` | ||
You can also install MongoDB using one of the various [Community Server](https://www.mongodb.com/download-center#community) | ||
packages made available by them. | ||
## Project layout | ||
@@ -19,4 +30,4 @@ | ||
TypeScript as it will help with refactoring should the API change. | ||
- **build** holds JavaScript files consumed by Gulp for the various gulp tasks available to you. Files within this folder are | ||
automatically run whenever you execute `gulp` within the project directory. | ||
- **build** holds JavaScript files which provide specific build tooling such as for generating the `CHANGELOG.md` file from our | ||
Git history. These are usually run through `npm run $CMD`. | ||
- **dist** holds the compiled JavaScript and JSMap files, its structure mirrors that of the project's root directory. Generally | ||
@@ -27,12 +38,9 @@ you won't have any need to fiddle in here unless you're debugging a code generation issue. | ||
to create an example of how to do things in JavaScript or any other JS targetting language then go right ahead. | ||
- **lib** *This is where the magic happens!* TypeScript files which make up the heart of Iridium. | ||
- **lib** *>This is where the magic happens!<* TypeScript files which make up the heart of Iridium. | ||
- **test** Probably the second most important folder, it holds all of the unit tests used to ensure that Iridium is working the | ||
way it was intended. | ||
- **typings** holds the TypeScript definition files we use to interface with some of the JavaScript dependencies. These are | ||
primarily pulled in by [tsd](http://definitelytyped.org/tsd/) from the [DefinitelyTyped](http://definitelytyped.org/) | ||
project. | ||
## Developing on Iridium | ||
Iridium's development workflow is almost entirely automated through a combination of Gulp and NPM hooks. The most common command | ||
you'll be using is `gulp watch` which will watch the **lib** and **test** folders for changes, compile the TypeScript files and | ||
Iridium's development workflow is almost entirely automated through NPM hooks. The most common command | ||
you'll be using is `npm run watch` which will watch the **lib** and **test** folders for changes, compile the TypeScript files and | ||
run the unit tests. You'll generally leave this running while you make changes to be notified almost immediately when things | ||
@@ -39,0 +47,0 @@ break. |
@@ -68,3 +68,3 @@ "use strict"; | ||
return new Promise((resolve, reject) => { | ||
iDB.connection.collection("mongodb").deleteMany((err) => { | ||
iDB.db.collection("mongodb").deleteMany((err) => { | ||
if (err) | ||
@@ -78,3 +78,3 @@ return reject(err); | ||
return new Promise((resolve, reject) => { | ||
iDB.connection.collection("mongodb").deleteMany({}, (err) => { | ||
iDB.db.collection("mongodb").deleteMany({}, (err) => { | ||
if (err) | ||
@@ -87,3 +87,3 @@ return reject(err); | ||
return new Promise((resolve, reject) => { | ||
iDB.connection.collection("mongodb").insertMany(objects, (err, objects) => { | ||
iDB.db.collection("mongodb").insertMany(objects, (err, objects) => { | ||
if (err) | ||
@@ -99,3 +99,3 @@ return reject(err); | ||
return new Promise((resolve, reject) => { | ||
iDB.connection.collection("mongodb").find({}).toArray((err, objects) => { | ||
iDB.db.collection("mongodb").find({}).toArray((err, objects) => { | ||
if (err) | ||
@@ -111,3 +111,3 @@ return reject(err); | ||
return new Promise((resolve, reject) => { | ||
iDB.connection.collection("mongodb").deleteMany((err, objects) => { | ||
iDB.db.collection("mongodb").deleteMany((err, objects) => { | ||
if (err) | ||
@@ -121,3 +121,3 @@ return reject(err); | ||
return new Promise((resolve, reject) => { | ||
iDB.connection.collection("mongodb").deleteMany(objects, (err, objects) => { | ||
iDB.db.collection("mongodb").deleteMany(objects, (err, objects) => { | ||
if (err) | ||
@@ -130,3 +130,3 @@ return reject(err); | ||
return new Promise((resolve, reject) => { | ||
iDB.connection.collection("mongodb").deleteMany((err, objects) => { | ||
iDB.db.collection("mongodb").deleteMany((err, objects) => { | ||
if (err) | ||
@@ -133,0 +133,0 @@ return reject(err); |
@@ -34,2 +34,3 @@ import * as MongoDB from "mongodb"; | ||
private _cache; | ||
private _dbName; | ||
private _connectPromise; | ||
@@ -52,4 +53,12 @@ /** | ||
*/ | ||
readonly connection: MongoDB.Db; | ||
readonly connection: MongoDB.MongoClient; | ||
/** | ||
* Gets the name of the database that this Iridium core is connected to | ||
*/ | ||
readonly dbName: string; | ||
/** | ||
* Gets the database that this Iridium core is connected to | ||
*/ | ||
readonly db: MongoDB.Db; | ||
/** | ||
* Gets the URL used to connect to MongoDB | ||
@@ -98,3 +107,3 @@ * @returns {String} | ||
*/ | ||
protected onConnecting(connection: MongoDB.Db): PromiseLike<MongoDB.Db>; | ||
protected onConnecting(connection: MongoDB.MongoClient): PromiseLike<MongoDB.MongoClient>; | ||
/** | ||
@@ -108,2 +117,7 @@ * A method which is called once a database connection has been established and accepted by Iridium | ||
protected onConnected(): PromiseLike<void>; | ||
/** | ||
* Parses the name of a DB from a URL string | ||
* @param urlStr The url string whose path component is the name of the DB | ||
*/ | ||
private parseDbName(urlStr); | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const MongoDB = require("mongodb"); | ||
const url = require("url"); | ||
const Express_1 = require("./middleware/Express"); | ||
@@ -29,5 +30,9 @@ const NoOpCache_1 = require("./caches/NoOpCache"); | ||
this._config = config; | ||
this._dbName = config && config.database || this.parseDbName(this.url); | ||
} | ||
else if (uri) { | ||
this._config = uri; | ||
this._dbName = uri && uri.database || ""; | ||
if (!this._dbName) | ||
throw new Error("Expected the database name to be provided when initializing Iridium"); | ||
} | ||
@@ -64,2 +69,14 @@ else { | ||
/** | ||
* Gets the name of the database that this Iridium core is connected to | ||
*/ | ||
get dbName() { | ||
return this._dbName; | ||
} | ||
/** | ||
* Gets the database that this Iridium core is connected to | ||
*/ | ||
get db() { | ||
return this.connection.db(this.dbName); | ||
} | ||
/** | ||
* Gets the URL used to connect to MongoDB | ||
@@ -115,4 +132,7 @@ * @returns {String} | ||
}, (err) => { | ||
if (this._connection) | ||
this._connection.close(); | ||
if (this._connection && this._connection.close) | ||
return this._connection.close().then(() => { | ||
this._connection = undefined; | ||
this._connectPromise = undefined; | ||
}).then(() => Promise.reject(err)); | ||
this._connection = undefined; | ||
@@ -169,4 +189,16 @@ this._connectPromise = undefined; | ||
} | ||
/** | ||
* Parses the name of a DB from a URL string | ||
* @param urlStr The url string whose path component is the name of the DB | ||
*/ | ||
parseDbName(urlStr) { | ||
const path = (url.parse(urlStr).path || "").replace(/^\/*/, ""); | ||
if (!path) | ||
throw new Error("Database URL does not include the DB name"); | ||
if (!path.match(/^[^\.\s\/\\]*$/)) | ||
throw new Error("Database name provided in the URL is invalid"); | ||
return path; | ||
} | ||
} | ||
exports.Core = Core; | ||
//# sourceMappingURL=Core.js.map |
@@ -86,10 +86,10 @@ "use strict"; | ||
if (this._isNew) { | ||
return new Promise((resolve, reject) => { | ||
let modified = this._model.helpers.cloneDocument(this._modified); | ||
modified = this._model.helpers.transformToDB(modified, { document: true, renames: true }); | ||
this._model.collection.insertOne(modified, { w: "majority" }, (err, doc) => { | ||
if (err) | ||
return reject(err); | ||
this._modified._id = doc.insertedId; | ||
return resolve(!!doc); | ||
return this._model.handlers.creatingDocuments([this._modified]).then((modifiedDocs) => { | ||
return new Promise((resolve, reject) => { | ||
this._model.collection.insertOne(modifiedDocs[0], { w: "majority" }, (err, doc) => { | ||
if (err) | ||
return reject(err); | ||
this._modified._id = doc.insertedId; | ||
return resolve(!!doc); | ||
}); | ||
}); | ||
@@ -96,0 +96,0 @@ }); |
@@ -137,3 +137,3 @@ "use strict"; | ||
get collection() { | ||
return this.core.connection.collection(this._collection); | ||
return this.core.db.collection(this._collection); | ||
} | ||
@@ -333,7 +333,10 @@ /** | ||
}; | ||
const isReplacement = Object.keys(changes).every(key => !!key.indexOf("$")); | ||
_.defaults(opts, { | ||
w: "majority", | ||
multi: true | ||
multi: !isReplacement | ||
}); | ||
return Promise_1.Nodeify(Promise.resolve().then(() => { | ||
if (opts.multi && isReplacement) | ||
return Promise.reject(new Error("You cannot use a replacement document and { multi: true }")); | ||
conditions = this._helpers.convertToDB(conditions, { document: true, properties: true, renames: true }); | ||
@@ -352,2 +355,4 @@ return new Promise((resolve, reject) => { | ||
return this.collection.updateMany(conditions, changes, opts, callback); | ||
if (isReplacement) | ||
return this.collection.replaceOne(conditions, changes, callback); | ||
return this.collection.updateOne(conditions, changes, opts, callback); | ||
@@ -428,9 +433,4 @@ }); | ||
aggregate(pipeline, options) { | ||
return new Promise((resolve, reject) => { | ||
this.collection.aggregate(pipeline, options || {}, (err, results) => { | ||
if (err) | ||
return reject(err); | ||
return resolve(results); | ||
}); | ||
}); | ||
const cursor = this.collection.aggregate(pipeline, options || {}); | ||
return cursor.toArray(); | ||
} | ||
@@ -437,0 +437,0 @@ mapReduce(functions, options) { |
@@ -16,2 +16,3 @@ "use strict"; | ||
} | ||
// TODO: Add documentation | ||
documentReceived(conditions, result, wrapper, options = {}) { | ||
@@ -42,2 +43,3 @@ _.defaults(options, { | ||
} | ||
// TODO: Add documentation | ||
creatingDocuments(documents) { | ||
@@ -57,2 +59,3 @@ return Promise.all(documents.map((document) => { | ||
} | ||
// TODO: Add documentation | ||
savingDocument(instance, changes) { | ||
@@ -59,0 +62,0 @@ return Promise |
@@ -7,5 +7,5 @@ "use strict"; | ||
if (config.username) { | ||
url += config.username; | ||
url += encodeURIComponent(config.username); | ||
if (config.password) | ||
url += ":" + config.password; | ||
url += ":" + encodeURIComponent(config.password); | ||
url += "@"; | ||
@@ -15,3 +15,3 @@ } | ||
if (config.database) | ||
url += "/" + config.database; | ||
url += "/" + encodeURIComponent(config.database); | ||
return url; | ||
@@ -24,5 +24,5 @@ } | ||
if (config.port) | ||
hosts.push(`${config.host}:${config.port}`); | ||
hosts.push(`${encodeURIComponent(config.host)}:${config.port}`); | ||
else | ||
hosts.push(config.host); | ||
hosts.push(encodeURIComponent(config.host)); | ||
} | ||
@@ -32,7 +32,7 @@ if (config.hosts) { | ||
if (host.port) | ||
hosts.push(`${host.address}:${host.port}`); | ||
hosts.push(`${encodeURIComponent(host.address)}:${host.port}`); | ||
else if (config && config.port) | ||
hosts.push(`${host.address}:${config.port}`); | ||
hosts.push(`${(host.address)}:${config.port}`); | ||
else | ||
hosts.push(host.address); | ||
hosts.push((host.address)); | ||
}); | ||
@@ -39,0 +39,0 @@ } |
@@ -5,2 +5,3 @@ "use strict"; | ||
const Skmatc = require("skmatc"); | ||
// TODO: Add documentation | ||
function DefaultValidators() { | ||
@@ -7,0 +8,0 @@ return [ |
@@ -24,5 +24,5 @@ "use strict"; | ||
} | ||
onConnecting(db) { | ||
this.events.emit("connecting", db); | ||
return this.onConnectingResult(db); | ||
onConnecting(client) { | ||
this.events.emit("connecting", client); | ||
return this.onConnectingResult(client.db("test")); | ||
} | ||
@@ -29,0 +29,0 @@ onConnected() { |
@@ -56,6 +56,6 @@ "use strict"; | ||
it("should support just spec indexes", () => { | ||
chai.expect(Test.indexes).to.contain({ spec: { name: 1 }, options: {} }); | ||
chai.expect(Test.indexes).to.deep.include({ spec: { name: 1 }, options: {} }); | ||
}); | ||
it("should support indexes with both a spec and options", () => { | ||
chai.expect(Test.indexes).to.contain({ spec: { email: 1 }, options: { background: true } }); | ||
chai.expect(Test.indexes).to.deep.include({ spec: { email: 1 }, options: { background: true } }); | ||
}); | ||
@@ -62,0 +62,0 @@ it("should not pollute the parent's index object", () => { |
"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()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -49,6 +57,21 @@ const Iridium = require("../iridium"); | ||
}); | ||
it("should be called when a document is being created", (done) => { | ||
hookEmitter.once("creating", () => done()); | ||
model.insert({ answer: 11 }); | ||
}); | ||
it("should be called when a document is being created from Model.insert", () => __awaiter(this, void 0, void 0, function* () { | ||
let onCreatingHit = false; | ||
hookEmitter.once("creating", () => onCreatingHit = true); | ||
yield model.insert({ answer: 11 }); | ||
chai.expect(onCreatingHit).to.be.true; | ||
})); | ||
it("should be called when a document is being created from Model.create", () => __awaiter(this, void 0, void 0, function* () { | ||
let onCreatingHit = false; | ||
hookEmitter.once("creating", () => onCreatingHit = true); | ||
yield model.create({ answer: 11 }); | ||
chai.expect(onCreatingHit).to.be.true; | ||
})); | ||
it("should be called when a document is being created from Instance.save", () => __awaiter(this, void 0, void 0, function* () { | ||
let onCreatingHit = false; | ||
hookEmitter.once("creating", () => onCreatingHit = true); | ||
const testInstance = new model.Instance({ answer: 11 }); | ||
yield testInstance.save(); | ||
chai.expect(onCreatingHit).to.be.true; | ||
})); | ||
it("should be passed the document being created", () => { | ||
@@ -55,0 +78,0 @@ let result; |
@@ -151,5 +151,2 @@ "use strict"; | ||
}); | ||
it("should return a MongoDB DB object", () => { | ||
chai.expect(core.connection).to.exist.and.be.an.instanceof(MongoDB.Db); | ||
}); | ||
}); | ||
@@ -156,0 +153,0 @@ describe("create()", () => { |
{ | ||
"name": "iridium", | ||
"version": "8.0.0-alpha.10", | ||
"version": "8.0.0-alpha.12", | ||
"author": "Benjamin Pannell <admin@sierrasoftworks.com>", | ||
@@ -24,3 +24,3 @@ "description": "A custom lightweight ORM for MongoDB designed for power-users", | ||
"pretest": "npm run build", | ||
"prepublish": "npm run build", | ||
"prepublishOnly": "npm run build", | ||
"test": "mocha --opts test/mocha.opts dist/test", | ||
@@ -54,33 +54,34 @@ "coverage": "istanbul cover node_modules/mocha/bin/_mocha -- --opts test/mocha.opts dist/test", | ||
"dependencies": { | ||
"@types/chai": "^3.5.2", | ||
"@types/lodash": "^4.14.64", | ||
"@types/mongodb": "^2.2.13", | ||
"lodash": "^4.17.4", | ||
"mongodb": "^2.2.31", | ||
"@types/chai": "^4.1.2", | ||
"@types/lodash": "^4.14.101", | ||
"@types/mongodb": "^3.0.5", | ||
"lodash": "^4.17.5", | ||
"mongodb": "^3.0.2", | ||
"skmatc": "~1.2.3" | ||
}, | ||
"peerDependencies": { | ||
"@types/lodash": "^4.14.64", | ||
"@types/mongodb": "^2.2.13", | ||
"@types/chai": "^3.5.2" | ||
"@types/lodash": "^4.14.101", | ||
"@types/mongodb": "^3.0.5", | ||
"@types/chai": "^4.1.2" | ||
}, | ||
"devDependencies": { | ||
"@types/bluebird": "^3.5.19", | ||
"@types/chai": "^3.5.2", | ||
"@types/chai-as-promised": "^0.0.30", | ||
"@types/mocha": "^2.2.41", | ||
"@types/source-map-support": "^0.2.28", | ||
"@types/bluebird": "^3.5.20", | ||
"@types/chai": "^4.1.2", | ||
"@types/chai-as-promised": "^7.1.0", | ||
"@types/mocha": "^2.2.48", | ||
"@types/source-map-support": "^0.4.0", | ||
"bluebird": "^3.5.1", | ||
"chai": "^3.5.0", | ||
"chai-as-promised": "^6.0.0", | ||
"chalk": "^1.1.3", | ||
"concurrently": "^3.4.0", | ||
"coveralls": "^2.13.1", | ||
"chai": "^4.1.2", | ||
"chai-as-promised": "^7.1.1", | ||
"chalk": "^2.3.0", | ||
"concurrently": "^3.5.1", | ||
"coveralls": "^3.0.0", | ||
"debug": "^3.1.0", | ||
"istanbul": "~0.4.5", | ||
"mocha": "^3.4.1", | ||
"remap-istanbul": "^0.9.5", | ||
"source-map-support": "^0.4.15", | ||
"tslint": "^5.2.0", | ||
"typedoc": "~0.7.1", | ||
"typescript": "~2.6.2" | ||
"mocha": "^5.0.0", | ||
"remap-istanbul": "~0.10.1", | ||
"source-map-support": "~0.5.3", | ||
"tslint": "^5.9.1", | ||
"typedoc": "~0.10.0", | ||
"typescript": "~2.7.1" | ||
}, | ||
@@ -87,0 +88,0 @@ "keywords": [ |
@@ -0,0 +0,0 @@ # Iridium |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
847278
8837
0
19
+ Added@types/chai@4.3.20(transitive)
+ Added@types/mongodb@3.6.20(transitive)
+ Addedbl@2.2.1(transitive)
+ Addedbson@1.1.6(transitive)
+ Addeddenque@1.5.1(transitive)
+ Addedmemory-pager@1.5.0(transitive)
+ Addedmongodb@3.7.4(transitive)
+ Addedoptional-require@1.1.8(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedrequire-at@1.0.6(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsaslprep@1.0.3(transitive)
+ Addedsparse-bitfield@3.0.3(transitive)
+ Addedstring_decoder@1.1.1(transitive)
- Removed@types/chai@3.5.2(transitive)
- Removed@types/mongodb@2.2.28(transitive)
- Removedbson@1.0.9(transitive)
- Removedbuffer-shims@1.0.0(transitive)
- Removedes6-promise@3.2.1(transitive)
- Removedmongodb@2.2.36(transitive)
- Removedmongodb-core@2.1.20(transitive)
- Removedprocess-nextick-args@1.0.7(transitive)
- Removedreadable-stream@2.2.7(transitive)
- Removedrequire_optional@1.0.1(transitive)
- Removedresolve-from@2.0.0(transitive)
- Removedsemver@5.7.2(transitive)
- Removedstring_decoder@1.0.3(transitive)
Updated@types/chai@^4.1.2
Updated@types/lodash@^4.14.101
Updated@types/mongodb@^3.0.5
Updatedlodash@^4.17.5
Updatedmongodb@^3.0.2