mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
- small fixes
This commit is contained in:
@@ -608,7 +608,7 @@ CollectionPrototype._callMutatorMethodAsync = async function _callMutatorMethodA
|
||||
}
|
||||
|
||||
const mutatorMethodName = this._prefix + name;
|
||||
return await this._connection.applyAsync(mutatorMethodName, args, { returnStubValue: true , isFromCallAsync: true, ...options });
|
||||
return this._connection.applyAsync(mutatorMethodName, args, { returnStubValue: true , isFromCallAsync: true, ...options });
|
||||
}
|
||||
|
||||
CollectionPrototype._callMutatorMethod = function _callMutatorMethod(name, args, callback) {
|
||||
|
||||
@@ -640,9 +640,7 @@
|
||||
"integrity": "sha512-C6N5s2ZFtuZRj54k2/zyRhNDjJwwcViAM3Nbm8zjBpbqAdZ00mr0CFxvSKeO8Y/e03WVFLpQMdHYVfUd6SB+Hw=="
|
||||
},
|
||||
"acorn": {
|
||||
"version": "8.8.2",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.2.tgz",
|
||||
"integrity": "sha512-xjIYgE8HBrkpd/sJqOGNspf8uHG+NOHGOw6a/Urj8taM2EXfdNAH2oFcPeIFfsv3+kz/mJrS5VuMqbNLjCa2vw=="
|
||||
"version": "6.4.2"
|
||||
},
|
||||
"acorn-dynamic-import": {
|
||||
"version": "4.0.0",
|
||||
@@ -1418,6 +1416,9 @@
|
||||
"resolved": "https://registry.npmjs.org/meteor-babel-helpers/-/meteor-babel-helpers-0.0.3.tgz",
|
||||
"integrity": "sha1-8uXZ+HlvvS6JAQI9dpnlsgLqn7A="
|
||||
},
|
||||
"meteor-promise": {
|
||||
"version": "0.9.0"
|
||||
},
|
||||
"minimatch": {
|
||||
"version": "3.0.4",
|
||||
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
|
||||
|
||||
@@ -701,6 +701,8 @@ export class Connection {
|
||||
);
|
||||
try {
|
||||
stubOptions.stubReturnValue = await stubInvocation();
|
||||
} catch (e) {
|
||||
stubOptions.exception = e;
|
||||
} finally {
|
||||
DDP._CurrentMethodInvocation._set(currentContext);
|
||||
}
|
||||
@@ -737,12 +739,11 @@ export class Connection {
|
||||
stubReturnValue,
|
||||
alreadyInSimulation,
|
||||
randomSeed,
|
||||
stubArgs,
|
||||
} = stubCallValue;
|
||||
|
||||
// Keep our args safe from mutation (eg if we don't send the message for a
|
||||
// while because of a wait method).
|
||||
args = EJSON.clone(stubArgs);
|
||||
args = EJSON.clone(args);
|
||||
// If we're in a simulation, stop and return the result we have,
|
||||
// rather than going on to do an RPC. If there was no stub,
|
||||
// we'll end up returning undefined.
|
||||
@@ -912,7 +913,6 @@ export class Connection {
|
||||
alreadyInSimulation,
|
||||
randomSeed,
|
||||
isFromCallAsync,
|
||||
stubArgs: args,
|
||||
};
|
||||
if (!stub) {
|
||||
return { ...defaultReturn, hasStub: false };
|
||||
@@ -958,10 +958,10 @@ export class Connection {
|
||||
// don't allow stubs to yield.
|
||||
return Meteor._noYieldsAllowed(() => {
|
||||
// re-clone, so that the stub can't affect our caller's values
|
||||
return stub.apply(invocation, args);
|
||||
return stub.apply(invocation, EJSON.clone(args));
|
||||
});
|
||||
} else {
|
||||
return stub.apply(invocation, args);
|
||||
return stub.apply(invocation, EJSON.clone(args));
|
||||
}
|
||||
};
|
||||
return { ...defaultReturn, hasStub: true, stubInvocation, invocation };
|
||||
|
||||
@@ -370,9 +370,7 @@ Object.assign(Session.prototype, {
|
||||
sendReady: function (subscriptionIds) {
|
||||
var self = this;
|
||||
if (self._isSending) {
|
||||
this._checkPublishPromiseBeforeSend(() => {
|
||||
self.send({msg: "ready", subs: subscriptionIds});
|
||||
});
|
||||
self.send({msg: "ready", subs: subscriptionIds});
|
||||
} else {
|
||||
_.each(subscriptionIds, function (subscriptionId) {
|
||||
self._pendingReady.push(subscriptionId);
|
||||
@@ -387,9 +385,7 @@ Object.assign(Session.prototype, {
|
||||
|
||||
sendAdded(collectionName, id, fields) {
|
||||
if (this._canSend(collectionName)) {
|
||||
this._checkPublishPromiseBeforeSend(() => {
|
||||
this.send({ msg: 'added', collection: collectionName, id, fields });
|
||||
});
|
||||
this.send({ msg: 'added', collection: collectionName, id, fields });
|
||||
}
|
||||
},
|
||||
|
||||
@@ -398,22 +394,18 @@ Object.assign(Session.prototype, {
|
||||
return;
|
||||
|
||||
if (this._canSend(collectionName)) {
|
||||
this._checkPublishPromiseBeforeSend(() => {
|
||||
this.send({
|
||||
msg: "changed",
|
||||
collection: collectionName,
|
||||
id,
|
||||
fields
|
||||
});
|
||||
this.send({
|
||||
msg: "changed",
|
||||
collection: collectionName,
|
||||
id,
|
||||
fields
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
sendRemoved(collectionName, id) {
|
||||
if (this._canSend(collectionName)) {
|
||||
this._checkPublishPromiseBeforeSend(() => {
|
||||
this.send({msg: "removed", collection: collectionName, id});
|
||||
});
|
||||
this.send({msg: "removed", collection: collectionName, id});
|
||||
}
|
||||
},
|
||||
|
||||
@@ -527,12 +519,14 @@ Object.assign(Session.prototype, {
|
||||
// Send a message (doing nothing if no socket is connected right now).
|
||||
// It should be a JSON object (it will be stringified).
|
||||
send: function (msg) {
|
||||
var self = this;
|
||||
if (self.socket) {
|
||||
if (Meteor._printSentDDP)
|
||||
Meteor._debug("Sent DDP", DDPCommon.stringifyDDP(msg));
|
||||
self.socket.send(DDPCommon.stringifyDDP(msg));
|
||||
}
|
||||
const self = this;
|
||||
this._checkPublishPromiseBeforeSend(() => {
|
||||
if (self.socket) {
|
||||
if (Meteor._printSentDDP)
|
||||
Meteor._debug('Sent DDP', DDPCommon.stringifyDDP(msg));
|
||||
self.socket.send(DDPCommon.stringifyDDP(msg));
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Send a connection error.
|
||||
@@ -617,11 +611,21 @@ Object.assign(Session.prototype, {
|
||||
return true;
|
||||
});
|
||||
|
||||
if (_.has(self.protocol_handlers, msg.msg))
|
||||
self.protocol_handlers[msg.msg].call(self, msg, unblock);
|
||||
else
|
||||
if (_.has(self.protocol_handlers, msg.msg)) {
|
||||
const result = self.protocol_handlers[msg.msg].call(
|
||||
self,
|
||||
msg,
|
||||
unblock
|
||||
);
|
||||
if (Meteor._isPromise(result)) {
|
||||
result.finally(() => unblock());
|
||||
} else {
|
||||
unblock();
|
||||
}
|
||||
} else {
|
||||
self.sendError('Bad request', msg);
|
||||
unblock(); // in case the handler didn't already do it
|
||||
unblock(); // in case the handler didn't already do it
|
||||
}
|
||||
}
|
||||
|
||||
runHandlers();
|
||||
@@ -783,7 +787,7 @@ Object.assign(Session.prototype, {
|
||||
}
|
||||
|
||||
const getCurrentMethodInvocationResult = () =>
|
||||
DDP._CurrentPublicationInvocation.withValue(
|
||||
DDP._CurrentMethodInvocation.withValue(
|
||||
invocation,
|
||||
() =>
|
||||
maybeAuditArgumentChecks(
|
||||
@@ -818,7 +822,7 @@ Object.assign(Session.prototype, {
|
||||
msg: "result",
|
||||
id: msg.id
|
||||
};
|
||||
promise.then(async result => {
|
||||
return promise.then(async result => {
|
||||
await finish();
|
||||
if (result !== undefined) {
|
||||
payload.result = result;
|
||||
|
||||
@@ -128,9 +128,7 @@ export default class LocalCollection {
|
||||
// XXX possibly enforce that 'undefined' does not appear (we assume
|
||||
// this in our handling of null and $exists)
|
||||
insert(doc, callback) {
|
||||
const docId = doc._id;
|
||||
doc = EJSON.clone(doc);
|
||||
doc._id = docId;
|
||||
const id = this.prepareInsert(doc);
|
||||
const queriesToRecompute = [];
|
||||
|
||||
@@ -173,9 +171,7 @@ export default class LocalCollection {
|
||||
return id;
|
||||
}
|
||||
async insertAsync(doc, callback) {
|
||||
const docId = doc._id;
|
||||
doc = EJSON.clone(doc);
|
||||
doc._id = docId;
|
||||
const id = this.prepareInsert(doc);
|
||||
const queriesToRecompute = [];
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ if (Meteor.isServer) {
|
||||
collection._insecure = insecure;
|
||||
var m = {};
|
||||
m["clear-collection-" + fullName] = async function() {
|
||||
await collection.removeAsync({});
|
||||
await collection.removeAsync({}, { returnServerResultPromise: true });
|
||||
};
|
||||
Meteor.methods(m);
|
||||
}
|
||||
@@ -111,41 +111,41 @@ if (Meteor.isServer) {
|
||||
|
||||
// two calls to allow to verify that either validator is sufficient.
|
||||
var allows = [{
|
||||
insert: function(userId, doc) {
|
||||
insertAsync: function(userId, doc) {
|
||||
return doc.canInsert;
|
||||
},
|
||||
update: function(userId, doc) {
|
||||
updateAsync: function(userId, doc) {
|
||||
return doc.canUpdate;
|
||||
},
|
||||
remove: function (userId, doc) {
|
||||
removeAsync: function (userId, doc) {
|
||||
return doc.canRemove;
|
||||
}
|
||||
}, {
|
||||
insert: function(userId, doc) {
|
||||
insertAsync: function(userId, doc) {
|
||||
return doc.canInsert2;
|
||||
},
|
||||
update: function(userId, doc, fields, modifier) {
|
||||
updateAsync: function(userId, doc, fields, modifier) {
|
||||
return -1 !== _.indexOf(fields, 'canUpdate2');
|
||||
},
|
||||
remove: function(userId, doc) {
|
||||
removeAsync: function(userId, doc) {
|
||||
return doc.canRemove2;
|
||||
}
|
||||
}];
|
||||
|
||||
// two calls to deny to verify that either one blocks the change.
|
||||
var denies = [{
|
||||
insert: function(userId, doc) {
|
||||
insertAsync: function(userId, doc) {
|
||||
return doc.cantInsert;
|
||||
},
|
||||
remove: function (userId, doc) {
|
||||
removeAsync: function (userId, doc) {
|
||||
return doc.cantRemove;
|
||||
}
|
||||
}, {
|
||||
insert: function(userId, doc) {
|
||||
insertAsync: function(userId, doc) {
|
||||
// Don't allow explicit ID to be set by the client.
|
||||
return _.has(doc, '_id');
|
||||
},
|
||||
update: function(userId, doc, fields, modifier) {
|
||||
updateAsync: function(userId, doc, fields, modifier) {
|
||||
return -1 !== _.indexOf(fields, 'verySecret');
|
||||
}
|
||||
}];
|
||||
@@ -571,56 +571,70 @@ if (Meteor.isClient) {
|
||||
var id1, id2;
|
||||
testAsyncMulti("collection - update options, " + idGeneration, [
|
||||
// init
|
||||
function (test, expect) {
|
||||
collection.callClearMethod(expect(function () {
|
||||
test.equal(collection.find().count(), 0);
|
||||
}));
|
||||
async function (test, expect) {
|
||||
await collection.callClearMethod().then(async function() {
|
||||
test.equal(await collection.find().countAsync(), 0);
|
||||
});
|
||||
},
|
||||
// put a few objects
|
||||
function (test, expect) {
|
||||
async function (test, expect) {
|
||||
var doc = {canInsert: true, canUpdate: true};
|
||||
id1 = collection.insert(doc);
|
||||
id2 = collection.insert(doc);
|
||||
collection.insert(doc);
|
||||
collection.insert(doc, expect(function (err, res) {
|
||||
test.isFalse(err);
|
||||
test.equal(collection.find().count(), 4);
|
||||
}));
|
||||
id1 = await collection.insertAsync(doc);
|
||||
id2 = await collection.insertAsync(doc);
|
||||
await collection.insertAsync(doc);
|
||||
await collection.insertAsync(doc, { returnServerResultPromise: true }
|
||||
).then(async function (res) {
|
||||
console.log('fetch after', id1, await collection.find().fetchAsync());
|
||||
test.equal(await collection.find().countAsync(), 4);
|
||||
});
|
||||
|
||||
},
|
||||
// update by id
|
||||
function (test, expect) {
|
||||
collection.update(
|
||||
id1,
|
||||
{$set: {updated: true}},
|
||||
expect(function (err, res) {
|
||||
test.isFalse(err);
|
||||
async function (test, expect) {
|
||||
await collection
|
||||
.updateAsync(id1, { $set: { updated: true } },{ returnServerResultPromise: true })
|
||||
.then(async function(res) {
|
||||
test.equal(res, 1);
|
||||
test.equal(collection.find({updated: true}).count(), 1);
|
||||
}));
|
||||
},
|
||||
console.log('fetch FIST UPD SECO after', id1, res, await collection.find().fetchAsync());
|
||||
test.equal(
|
||||
await collection.find({ updated: true }).countAsync(),
|
||||
1
|
||||
);
|
||||
});
|
||||
},],[
|
||||
// update by id in an object
|
||||
function (test, expect) {
|
||||
collection.update(
|
||||
{_id: id2},
|
||||
{$set: {updated: true}},
|
||||
expect(function (err, res) {
|
||||
test.isFalse(err);
|
||||
async function (test, expect) {
|
||||
await collection
|
||||
.updateAsync({ _id: id2 }, { $set: { updated: true } })
|
||||
.then(async function(res) {
|
||||
test.equal(res, 1);
|
||||
test.equal(collection.find({updated: true}).count(), 2);
|
||||
}));
|
||||
test.equal(
|
||||
await collection.find({ updated: true }).countAsync(),
|
||||
2
|
||||
);
|
||||
});
|
||||
console.log('fetch FIRST UPDATE after', await collection.find().fetchAsync());
|
||||
},
|
||||
// update with replacement operator not allowed, and has nice error.
|
||||
function (test, expect) {
|
||||
collection.update(
|
||||
{_id: id2},
|
||||
{_id: id2, updated: true},
|
||||
expect(function (err, res) {
|
||||
async function (test, expect) {
|
||||
await collection
|
||||
.updateAsync(
|
||||
{ _id: id2 },
|
||||
{ _id: id2, updated: true },
|
||||
{ returnServerResultPromise: true }
|
||||
|
||||
)
|
||||
.catch(async function(err) {
|
||||
console.log('ALLLLOO');
|
||||
test.equal(err.error, 403);
|
||||
test.matches(err.reason, /In a restricted/);
|
||||
// unchanged
|
||||
test.equal(collection.find({updated: true}).count(), 2);
|
||||
}));
|
||||
},
|
||||
test.equal(
|
||||
await collection.find({ updated: true }).countAsync(),
|
||||
2
|
||||
);
|
||||
});
|
||||
},],[
|
||||
// upsert not allowed, and has nice error.
|
||||
function (test, expect) {
|
||||
collection.update(
|
||||
|
||||
Reference in New Issue
Block a user