Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(promises): removed support for custom promise libraries #12878

Merged
merged 6 commits into from
Feb 4, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
6.8.4 / 2023-01-17
==================
* fix(collection): handle creating model when connection disconnected with bufferCommands = false #12889
* fix(populate): merge instead of overwrite when match is on _id #12891
* fix: add guard to stop loadClass copying Document if Document is used as base of loaded class (same hack as implemented for Model already) #12820 [sgpinkus](https://github.com/sgpinkus)
* fix(types): correctly infer types on document arrays #12884 #12882 [JavaScriptBach](https://github.com/JavaScriptBach)
* fix(types): added omit for ArraySubdocument type in LeanType declaration #12903 [piyushk96](https://github.com/piyushk96)
* fix(types): add returnDocument type safety #12906 [AbdelrahmanHafez](https://github.com/AbdelrahmanHafez)
* docs(typescript): add notes about virtual context to Mongoose 6 migration and TypeScript virtuals docs #12912 #12806
* docs(schematypes): removed dead link and fixed formatting #12897 #12885 [lpizzinidev](https://github.com/lpizzinidev)
* docs: fix link to lean api #12910 [manniL](https://github.com/manniL)
* docs: list all possible strings for schema.pre in one place #12868
* docs: add list of known incompatible npm packages #12892 [IslandRhythms](https://github.com/IslandRhythms)

6.8.3 / 2023-01-06
==================
* perf: improve performance of assignRawDocsToIdStructure for faster populate on large docs #12867 [Uzlopak](https://github.com/Uzlopak)
Expand Down
11 changes: 0 additions & 11 deletions docs/promises.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,6 @@ better stack traces.
[require:Should You Use `exec\(\)` With `await`]
```

### Plugging in your own Promises Library

If you're an advanced user, you may want to plug in your own promise
library like [bluebird](https://www.npmjs.com/package/bluebird). Just set
`mongoose.Promise` to your favorite
ES6-style promise constructor and mongoose will use it.

```javascript
[require:Plugging in your own Promises Library]
```

<i>
Want to learn how to check whether your favorite npm modules work with
async/await without cobbling together contradictory answers from Google
Expand Down
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ module.exports.SchemaTypes = mongoose.SchemaTypes;
module.exports.VirtualType = mongoose.VirtualType;
module.exports.Types = mongoose.Types;
module.exports.Query = mongoose.Query;
module.exports.Promise = mongoose.Promise;
module.exports.Model = mongoose.Model;
module.exports.Document = mongoose.Document;
module.exports.ObjectId = mongoose.ObjectId;
Expand Down
26 changes: 0 additions & 26 deletions lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,9 @@
require('./driver').set(require('./drivers/browser'));

const DocumentProvider = require('./document_provider.js');
const PromiseProvider = require('./promise_provider');

DocumentProvider.setBrowser(true);

/**
* The Mongoose [Promise](#promise_Promise) constructor.
*
* @method Promise
* @api public
*/

Object.defineProperty(exports, 'Promise', {
get: function() {
return PromiseProvider.get();
},
set: function(lib) {
PromiseProvider.set(lib);
}
});

/**
* Storage layer for mongoose promises
*
* @method PromiseProvider
* @api public
*/

exports.PromiseProvider = PromiseProvider;

/**
* The [MongooseError](#error_MongooseError) constructor.
*
Expand Down
2 changes: 0 additions & 2 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const STATES = require('./connectionstate');
const MongooseError = require('./error/index');
const DisconnectedError = require('./error/disconnected');
const SyncIndexesError = require('./error/syncIndexes');
const PromiseProvider = require('./promise_provider');
const ServerSelectionError = require('./error/serverSelection');
const applyPlugins = require('./helpers/schema/applyPlugins');
const clone = require('./helpers/clone');
Expand Down Expand Up @@ -736,7 +735,6 @@ Connection.prototype.openUri = function(uri, options, callback) {
this.readyState = STATES.connecting;
this._closeCalled = false;

const Promise = PromiseProvider.get();
const _this = this;

options = processConnectionOptions(uri, options);
Expand Down
3 changes: 1 addition & 2 deletions lib/helpers/promiseOrCallback.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const PromiseProvider = require('../promise_provider');
const immediate = require('./immediate');

const emittedSymbol = Symbol('mongoose:emitted');
Expand Down Expand Up @@ -35,7 +34,7 @@ module.exports = function promiseOrCallback(callback, fn, ee, Promise) {
}
}

Promise = Promise || PromiseProvider.get();
Promise = Promise || global.Promise;

return new Promise((resolve, reject) => {
fn(function(error, res) {
Expand Down
28 changes: 0 additions & 28 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const pkg = require('../package.json');
const cast = require('./cast');

const Aggregate = require('./aggregate');
const PromiseProvider = require('./promise_provider');
const trusted = require('./helpers/query/trusted').trusted;
const sanitizeFilter = require('./helpers/query/sanitizeFilter');
const isBsonType = require('./helpers/isBsonType');
Expand Down Expand Up @@ -948,33 +947,6 @@ Mongoose.prototype.Types = Types;

Mongoose.prototype.Query = Query;

/**
* The Mongoose [Promise](#promise_Promise) constructor.
*
* @memberOf Mongoose
* @instance
* @property Promise
* @api public
*/

Object.defineProperty(Mongoose.prototype, 'Promise', {
get: function() {
return PromiseProvider.get();
},
set: function(lib) {
PromiseProvider.set(lib);
}
});

/**
* Storage layer for mongoose promises
*
* @method PromiseProvider
* @api public
*/

Mongoose.prototype.PromiseProvider = PromiseProvider;

/**
* The Mongoose [Model](#model_Model) constructor.
*
Expand Down
2 changes: 0 additions & 2 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const EventEmitter = require('events').EventEmitter;
const MongooseBuffer = require('./types/buffer');
const MongooseError = require('./error/index');
const OverwriteModelError = require('./error/overwriteModel');
const PromiseProvider = require('./promise_provider');
const Query = require('./query');
const RemoveOptions = require('./options/removeOptions');
const SaveOptions = require('./options/saveOptions');
Expand Down Expand Up @@ -1350,7 +1349,6 @@ Model.init = function init(callback) {
return this.$init;
}

const Promise = PromiseProvider.get();
const autoIndex = utils.getOption('autoIndex',
this.schema.options, this.db.config, this.db.base.options);
const autoCreate = utils.getOption('autoCreate',
Expand Down
49 changes: 0 additions & 49 deletions lib/promise_provider.js

This file was deleted.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "mongoose",
"description": "Mongoose MongoDB ODM",
"version": "6.8.3",
"version": "6.8.4",
"author": "Guillermo Rauch <guillermo@learnboost.com>",
"keywords": [
"mongodb",
Expand Down Expand Up @@ -39,7 +39,6 @@
"axios": "1.1.3",
"babel-loader": "8.2.5",
"benchmark": "2.1.4",
"bluebird": "3.7.2",
"buffer": "^5.6.0",
"cheerio": "1.0.0-rc.12",
"crypto-browserify": "3.12.0",
Expand Down
2 changes: 1 addition & 1 deletion test/aggregate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ describe('aggregate: ', function() {
const agg = new Aggregate([], db.model('Employee'));

const promise = agg.exec();
assert.ok(promise instanceof mongoose.Promise);
assert.ok(promise instanceof Promise);

return promise.catch(error => {
assert.ok(error);
Expand Down
3 changes: 1 addition & 2 deletions test/connection.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

const start = require('./common');

const Promise = require('bluebird');
const Q = require('q');
const assert = require('assert');
const sinon = require('sinon');
Expand Down Expand Up @@ -1506,7 +1505,7 @@ describe('connections:', function() {

const [res] = await Promise.all([
Test.findOne().exec(),
new Promise.resolve(resolve => setTimeout(resolve, 100)).then(() => {
Promise.resolve(resolve => setTimeout(resolve, 100)).then(() => {
conn.client.emit('serverDescriptionChanged', { newDescription: { type: 'Single' } });
})
]);
Expand Down
32 changes: 0 additions & 32 deletions test/docs/promises.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ describe('promises docs', function () {
});

after(async function () {
mongoose.Promise = global.Promise;
hasezoey marked this conversation as resolved.
Show resolved Hide resolved

await db.close();
});

Expand Down Expand Up @@ -154,34 +152,4 @@ describe('promises docs', function () {
// acquit:ignore:end
}
});

/**
* If you're an advanced user, you may want to plug in your own promise
* library like [bluebird](https://www.npmjs.com/package/bluebird). Just set
* `mongoose.Promise` to your favorite
* ES6-style promise constructor and mongoose will use it.
*/
it('Plugging in your own Promises Library', function (done) {
// acquit:ignore:start
if (!global.Promise) {
return done();
}
// acquit:ignore:end
// Use bluebird
mongoose.Promise = require('bluebird');
const bluebirdPromise = Band.findOne({name: "Guns N' Roses"}).exec();
assert.equal(bluebirdPromise.constructor, require('bluebird'));

// Use q. Note that you **must** use `require('q').Promise`.
mongoose.Promise = require('q').Promise;
const qPromise = Band.findOne({name: "Guns N' Roses"}).exec();
assert.ok(qPromise instanceof require('q').makePromise);

// acquit:ignore:start
// Wait for promises
bluebirdPromise.then(qPromise).then(function () {
done();
});
// acquit:ignore:end
});
});
2 changes: 0 additions & 2 deletions test/docs/validation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ const assert = require('assert');
const mongoose = require('../../');
const start = require('../common');

const Promise = global.Promise || require('bluebird');

describe('validation docs', function() {
let db;
const Schema = mongoose.Schema;
Expand Down
2 changes: 0 additions & 2 deletions test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4113,8 +4113,6 @@ describe('document', function() {
});

it('supports $where in pre save hook (gh-4004)', function(done) {
const Promise = global.Promise;

const schema = new Schema({
name: String
}, { timestamps: true, versionKey: null });
Expand Down
1 change: 0 additions & 1 deletion test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,6 @@ describe('mongoose module:', function() {
assert.ok(mongoose.Schema.Types);
assert.equal(typeof mongoose.SchemaType, 'function');
assert.equal(typeof mongoose.Query, 'function');
assert.equal(typeof mongoose.Promise, 'function');
assert.equal(typeof mongoose.Model, 'function');
assert.equal(typeof mongoose.Document, 'function');
assert.equal(typeof mongoose.Error, 'function');
Expand Down
2 changes: 1 addition & 1 deletion test/model.aggregate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('model aggregate', function() {

const res = await promise;

assert.ok(promise instanceof mongoose.Promise);
assert.ok(promise instanceof Promise);
assert.ok(res);
assert.equal(res.length, 1);
assert.ok('maxAge' in res[0]);
Expand Down
2 changes: 1 addition & 1 deletion test/model.create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ describe('model', function() {

it('returns a promise', function() {
const p = B.create({ title: 'returns promise' });
assert.ok(p instanceof mongoose.Promise);
assert.ok(p instanceof Promise);
});

it('creates in parallel', async function() {
Expand Down
2 changes: 1 addition & 1 deletion test/model.indexes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ describe('model', function() {
const schema = mongoose.Schema({ x: 'string' });
const Test = mongoose.createConnection().model('ensureIndexes-' + random, schema);
const p = Test.ensureIndexes();
assert.ok(p instanceof mongoose.Promise);
assert.ok(p instanceof Promise);
});

it('creates indexes', async function() {
Expand Down
2 changes: 1 addition & 1 deletion test/model.mapreduce.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ describe('model: mapreduce:', function() {
};

const promise = MR.mapReduce(o);
assert.ok(promise instanceof mongoose.Promise);
assert.ok(promise instanceof Promise);
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/model.populate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2429,7 +2429,7 @@ describe('model: populate:', function() {

it('returns a promise', function(done) {
const p = B.populate(post1, '_creator');
assert.ok(p instanceof mongoose.Promise);
assert.ok(p instanceof Promise);
p.then(success, done);
function success(doc) {
assert.ok(doc);
Expand Down
Loading