Skip to content

Commit 282c242

Browse files
authored
Merge pull request #449 from Meteor-Community-Packages/fix-bypasscollection2
Make compatible with the new RC
2 parents a0a3944 + 3a12b53 commit 282c242

File tree

10 files changed

+547
-641
lines changed

10 files changed

+547
-641
lines changed

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
55
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
66

7-
- [4.0.0-beta.5](#400-beta.3)
7+
- [4.0.2](#402)
8+
- [4.0.1](#401)
9+
- [4.0.0](#400)
810
- [3.5.0](#350)
911
- [3.4.1](#341)
1012
- [3.4.0](#340)
@@ -78,6 +80,16 @@
7880

7981
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
8082

83+
## 4.0.2
84+
85+
- Make collection2 compatible with the newly released RC
86+
- Move common code between `_methodMutation` and `_methodMutationAsync` into its own code
87+
88+
## 4.0.1
89+
90+
- Fix dynamic import https://github.com/Meteor-Community-Packages/meteor-collection2/pull/450
91+
92+
8193
## 4.0.0
8294

8395
- Make collection2 compatible with Meteor 3.0 thanks to the [awesome work](https://github.com/Meteor-Community-Packages/meteor-collection2/pull/443) by @klablink

package/collection2/.versions

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
aldeed:collection2@4.0.1
2-
aldeed:simple-schema@1.13.1
1+
aldeed:collection2@4.0.2
2+
aldeed:simple-schema@2.0.0-rc.1
33
allow-deny@1.1.1
44
babel-compiler@7.10.5
55
babel-runtime@1.5.1
66
base64@1.0.12
77
binary-heap@1.0.11
88
boilerplate-generator@1.7.2
99
callback-hook@1.5.1
10-
check@1.3.2
10+
check@1.4.1
1111
ddp@1.4.1
12-
ddp-client@2.6.1
13-
ddp-common@1.4.0
14-
ddp-server@2.7.0
12+
ddp-client@2.6.2
13+
ddp-common@1.4.1
14+
ddp-server@2.7.1
1515
diff-sequence@1.1.2
1616
dynamic-import@0.7.3
1717
ecmascript@0.16.8
@@ -24,17 +24,18 @@ geojson-utils@1.0.11
2424
http@1.0.10
2525
id-map@1.1.1
2626
inter-process-messaging@0.1.1
27-
local-test:aldeed:collection2@4.0.1
28-
logging@1.3.3
27+
local-test:aldeed:collection2@4.0.2
28+
logging@1.3.4
29+
mdg:validation-error@0.5.1
2930
meteor@1.11.5
30-
meteortesting:browser-tests@1.6.0-beta300.0
31-
meteortesting:mocha@3.1.0-beta300.0
32-
meteortesting:mocha-core@8.3.1-beta300.0
33-
minimongo@1.9.3
31+
meteortesting:browser-tests@1.6.0
32+
meteortesting:mocha@3.1.0-rc.1
33+
meteortesting:mocha-core@8.3.1-rc300.1
34+
minimongo@1.9.4
3435
modern-browsers@0.1.10
3536
modules@0.20.0
3637
modules-runtime@0.13.1
37-
mongo@1.16.8
38+
mongo@1.16.10
3839
mongo-decimal@0.1.3
3940
mongo-dev-server@1.1.0
4041
mongo-id@1.0.8
@@ -50,7 +51,7 @@ routepolicy@1.1.1
5051
socket-stream-client@0.5.2
5152
tracker@1.3.3
5253
typescript@4.9.5
53-
underscore@1.6.0
54+
underscore@1.6.1
5455
url@1.3.2
5556
webapp@1.13.8
5657
webapp-hashing@1.1.1

package/collection2/main.js

Lines changed: 79 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -173,121 +173,93 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
173173
return null;
174174
};
175175
});
176+
177+
function getArgumentsAndValidationContext(methodName, args, async) {
178+
let options = isInsertType(methodName) ? args[1] : args[2];
179+
180+
// Support missing options arg
181+
if (!options || typeof options === 'function') {
182+
options = {};
183+
}
184+
185+
let validationContext = {};
186+
if (this._c2 && options.bypassCollection2 !== true) {
187+
let userId = null;
188+
try {
189+
// https://github.com/aldeed/meteor-collection2/issues/175
190+
userId = Meteor.userId();
191+
} catch (err) {}
192+
193+
[args, validationContext] = doValidate(
194+
this,
195+
methodName,
196+
args,
197+
Meteor.isServer || this._connection === null, // getAutoValues
198+
userId,
199+
Meteor.isServer, // isFromTrustedCode
200+
async
201+
);
202+
203+
if (!args) {
204+
// doValidate already called the callback or threw the error, so we're done.
205+
// But insert should always return an ID to match core behavior.
206+
return isInsertType(methodName) ? this._makeNewID() : undefined;
207+
}
208+
} else {
209+
// We still need to adjust args because insert does not take options
210+
if (isInsertType(methodName) && typeof args[1] !== 'function') args.splice(1, 1);
211+
}
212+
213+
return [args, validationContext];
214+
}
176215

177-
function _methodMutation(async, methodName) {
216+
function _methodMutation(async, methodName) {
178217
const _super = Meteor.isFibersDisabled
179-
? Mongo.Collection.prototype[methodName]
180-
: Mongo.Collection.prototype[methodName.replace('Async', '')];
181-
218+
? Mongo.Collection.prototype[methodName]
219+
: Mongo.Collection.prototype[methodName.replace('Async', '')];
220+
182221
if (!_super) return;
183-
184222
Mongo.Collection.prototype[methodName] = function (...args) {
185-
let options = isInsertType(methodName) ? args[1] : args[2];
186-
187-
// Support missing options arg
188-
if (!options || typeof options === 'function') {
189-
options = {};
190-
}
191-
192-
let validationContext = {};
193-
let error;
194-
if (this._c2 && options.bypassCollection2 !== true) {
195-
let userId = null;
196-
try {
197-
// https://github.com/aldeed/meteor-collection2/issues/175
198-
userId = Meteor.userId();
199-
} catch (err) {}
200-
201-
[args, validationContext] = doValidate(
202-
this,
203-
methodName,
204-
args,
205-
Meteor.isServer || this._connection === null, // getAutoValues
206-
userId,
207-
Meteor.isServer, // isFromTrustedCode
208-
async
209-
);
210-
211-
if (!args) {
212-
// doValidate already called the callback or threw the error, so we're done.
213-
// But insert should always return an ID to match core behavior.
214-
return isInsertType(methodName) ? this._makeNewID() : undefined;
215-
}
216-
} else {
217-
// We still need to adjust args because insert does not take options
218-
if (isInsertType(methodName) && typeof args[1] !== 'function') args.splice(1, 1);
219-
}
220-
221-
if (async && !Meteor.isFibersDisabled) {
222-
try {
223-
this[methodName.replace('Async', '')].isCalledFromAsync = true;
224-
_super.isCalledFromAsync = true;
225-
return Promise.resolve(_super.apply(this, args));
226-
} catch (err) {
227-
const addValidationErrorsPropName =
228-
typeof validationContext.addValidationErrors === 'function'
229-
? 'addValidationErrors'
230-
: 'addInvalidKeys';
231-
parsingServerError([err], validationContext, addValidationErrorsPropName);
232-
error = getErrorObject(validationContext, err.message, err.code);
233-
return Promise.reject(error);
234-
}
235-
} else {
236-
return _super.apply(this, args);
237-
}
223+
[args, validationContext] = getArgumentsAndValidationContext.call(this, methodName, args, async);
224+
225+
if (async && !Meteor.isFibersDisabled) {
226+
try {
227+
this[methodName.replace('Async', '')].isCalledFromAsync = true;
228+
_super.isCalledFromAsync = true;
229+
return Promise.resolve(_super.apply(this, args));
230+
} catch (err) {
231+
const addValidationErrorsPropName =
232+
typeof validationContext.addValidationErrors === 'function'
233+
? 'addValidationErrors'
234+
: 'addInvalidKeys';
235+
parsingServerError([err], validationContext, addValidationErrorsPropName);
236+
const error = getErrorObject(validationContext, err.message, err.code);
237+
return Promise.reject(error);
238+
}
239+
} else {
240+
return _super.apply(this, args);
241+
}
238242
};
239-
}
240-
241-
function _methodMutationAsync(methodName) {
243+
}
244+
245+
function _methodMutationAsync(methodName) {
242246
const _super = Mongo.Collection.prototype[methodName];
243247
Mongo.Collection.prototype[methodName] = async function (...args) {
244-
let options = isInsertType(methodName) ? args[1] : args[2];
245-
246-
// Support missing options arg
247-
if (!options || typeof options === 'function') {
248-
options = {};
249-
}
250-
251-
let validationContext = {};
252-
if (this._c2 && options.bypassCollection2 !== true) {
253-
let userId = null;
254-
try {
255-
// https://github.com/aldeed/meteor-collection2/issues/175
256-
userId = Meteor.userId();
257-
} catch (err) {}
258-
259-
[args, validationContext] = doValidate(
260-
this,
261-
methodName,
262-
args,
263-
Meteor.isServer || this._connection === null, // getAutoValues
264-
userId,
265-
Meteor.isServer, // isFromTrustedCode
266-
true
267-
);
268-
269-
if (!args) {
270-
// doValidate already called the callback or threw the error, so we're done.
271-
// But insert should always return an ID to match core behavior.
272-
return isInsertType(methodName) ? this._makeNewID() : undefined;
273-
}
274-
} else {
275-
// We still need to adjust args because insert does not take options
276-
if (methodName === 'insert' && typeof args[1] !== 'function') args.splice(1, 1);
277-
}
278-
279-
try {
280-
return await _super.apply(this, args);
281-
} catch (err) {
282-
const addValidationErrorsPropName =
283-
typeof validationContext.addValidationErrors === 'function'
284-
? 'addValidationErrors'
285-
: 'addInvalidKeys';
286-
parsingServerError([err], validationContext, addValidationErrorsPropName);
287-
throw getErrorObject(validationContext, err.message, err.code);
288-
}
248+
[args, validationContext] = getArgumentsAndValidationContext.call(this, methodName, args, true);
249+
250+
try {
251+
return await _super.apply(this, args);
252+
} catch (err) {
253+
const addValidationErrorsPropName =
254+
typeof validationContext.addValidationErrors === 'function'
255+
? 'addValidationErrors'
256+
: 'addInvalidKeys';
257+
parsingServerError([err], validationContext, addValidationErrorsPropName);
258+
throw getErrorObject(validationContext, err.message, err.code);
259+
}
289260
};
290-
}
261+
}
262+
291263

292264
// Wrap DB write operation methods
293265
if (Mongo.Collection.prototype.insertAsync) {

package/collection2/package.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Package.describe({
44
name: 'aldeed:collection2',
55
summary:
66
'Automatic validation of Meteor Mongo insert and update operations on the client and server',
7-
version: '4.0.1',
7+
version: '4.0.2',
88
documentation: '../../README.md',
99
git: 'https://github.com/aldeed/meteor-collection2.git'
1010
});
@@ -16,14 +16,14 @@ Npm.depends({
1616
});
1717

1818
Package.onUse(function (api) {
19-
api.versionsFrom(['1.12.1', '2.3', '3.0-beta.0']);
19+
api.versionsFrom(['1.12.1', '2.3', '3.0-rc.4']);
2020
api.use('mongo');
2121
api.imply('mongo');
2222
api.use('minimongo');
2323
api.use('ejson');
24-
api.use('raix:eventemitter@1.0.0');
2524
api.use('ecmascript');
26-
api.use('aldeed:simple-schema@2.0.0-beta300.0 || 1.13.1');
25+
api.use('raix:eventemitter@1.0.0');
26+
api.use('aldeed:simple-schema@1.13.1 || 2.0.0-beta300.0');
2727

2828
api.addFiles(['./collection2.js']);
2929

@@ -34,8 +34,9 @@ Package.onUse(function (api) {
3434
});
3535

3636
Package.onTest(function (api) {
37+
api.versionsFrom(['1.12.1', '2.3', '3.0-rc.4']);
3738
api.use([
38-
'meteortesting:mocha@3.1.0-beta300.0',
39-
'aldeed:collection2@4.0.1'
40-
])
41-
});
39+
'meteortesting:mocha@3.1.0-rc.1',
40+
'aldeed:collection2@4.0.2'
41+
]);
42+
});

tests/.meteor/packages

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
# 'meteor add' and 'meteor remove' will edit this file for you,
55
# but you can also edit it by hand.
66

7-
meteor-base@1.5.2-beta300.0 # Packages every Meteor app needs to have
8-
mongo@2.0.0-beta300.0 # The database Meteor supports right now
9-
reactive-var@1.0.13-beta300.0 # Reactive variable for tracker
7+
meteor-base@1.5.2-rc300.4 # Packages every Meteor app needs to have
8+
mongo@2.0.0-rc300.4 # The database Meteor supports right now
9+
reactive-var@1.0.13-rc300.4 # Reactive variable for tracker
1010
jquery # Helpful client-side library
11-
tracker@1.3.3-beta300.0 # Meteor's client-side reactive programming library
11+
tracker@1.3.4-rc300.4 # Meteor's client-side reactive programming library
1212

13-
standard-minifier-css@1.9.3-beta300.0 # CSS minifier run for production mode
14-
standard-minifier-js@3.0.0-beta300.0 # JS minifier run for production mode
15-
es5-shim@4.8.1-beta300.0 # ECMAScript 5 compatibility for older browsers.
16-
ecmascript@0.16.8-beta300.0 # Enable ECMAScript2015+ syntax in app code
17-
shell-server@0.6.0-beta300.0 # Server-side component of the `meteor shell` command
13+
standard-minifier-css@1.9.3-rc300.4 # CSS minifier run for production mode
14+
standard-minifier-js@3.0.0-rc300.4 # JS minifier run for production mode
15+
es5-shim@4.8.1-rc300.4 # ECMAScript 5 compatibility for older browsers.
16+
ecmascript@0.16.9-rc300.4 # Enable ECMAScript2015+ syntax in app code
17+
shell-server@0.6.0-rc300.4 # Server-side component of the `meteor shell` command
1818

19-
autopublish@1.0.8-beta300.0 # Publish all data to the clients (for prototyping)
20-
insecure@1.0.8-beta300.0 # Allow all DB writes from clients (for prototyping)
19+
autopublish@1.0.8-rc300.4 # Publish all data to the clients (for prototyping)
20+
insecure@1.0.8-rc300.4 # Allow all DB writes from clients (for prototyping)
2121

22-
underscore@1.0.14-beta300.0
23-
dynamic-import@0.7.4-beta300.0
22+
underscore@1.6.2-rc300.4
23+
dynamic-import@0.7.4-rc300.4
2424

25-
aldeed:simple-schema
26-
aldeed:collection2@4.0.0
25+
aldeed:simple-schema@2.0.0-beta300.0
26+
aldeed:collection2@4.0.2-beta.2
2727
meteortesting:mocha@3.1.0-beta300.0
2828
meteortesting:mocha-core@8.3.0-beta300.0

tests/.meteor/release

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
METEOR@3.0-beta.0
1+
METEOR@3.0-rc.4

0 commit comments

Comments
 (0)