Skip to content

Commit 1300372

Browse files
Merge branch 'master' into add-types
2 parents a90815b + f1804ea commit 1300372

File tree

9 files changed

+197
-90
lines changed

9 files changed

+197
-90
lines changed

.github/workflows/testsuite.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@ jobs:
99
tests:
1010
name: tests
1111
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
meteor: [ '2.13.3', '3.0.4' ]
1215
# needs: [lintcode,lintstyle,lintdocs] # we could add prior jobs for linting, if desired
1316
steps:
1417
- name: checkout
15-
uses: actions/checkout@v3
18+
uses: actions/checkout@v4
1619

1720
- name: Setup meteor
18-
uses: meteorengineer/setup-meteor@v1
21+
uses: meteorengineer/setup-meteor@v2
1922
with:
20-
meteor-release: '2.13.3'
23+
meteor-release: ${{ matrix.meteor }}
2124

2225
- name: cache dependencies
23-
uses: actions/cache@v1
26+
uses: actions/cache@v4
2427
with:
2528
path: ~/.npm
2629
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
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.4](#404)
8+
- [4.0.3](#403)
79
- [4.0.2](#402)
810
- [4.0.1](#401)
911
- [4.0.0](#400)
@@ -80,6 +82,19 @@
8082

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

85+
## 4.0.4
86+
87+
- Return unaltered error message when collection isn't being validated and doesn't have simple schema attached thanks to @DmytroSoninLinguahouse
88+
- Update test application to use Meteor release number 3.0.4
89+
- Remove lodash dependencies
90+
- Updated dependencies
91+
- Expanded dependencies compatibility
92+
- Extended test suite
93+
94+
## 4.0.3
95+
96+
- Update Meteor release to 3.0
97+
8398
## 4.0.2
8499

85100
- Make collection2 compatible with the newly released RC

package-lock.json

Lines changed: 21 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package/collection2/lib.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,29 @@ export const isUpdateType = function (type) {
3939
export const isUpsertType = function (type) {
4040
return ['upsert', 'upsertAsync'].includes(type);
4141
};
42+
43+
export function isObject(value) {
44+
return typeof value === 'object' && value !== null && !Array.isArray(value);
45+
}
46+
47+
export function isEqual(a, b) {
48+
// Handle primitive types and null/undefined
49+
if (a === b) return true;
50+
if (a == null || b == null) return false;
51+
if (typeof a !== 'object' || typeof b !== 'object') return false;
52+
53+
// Get object keys
54+
const keysA = Object.keys(a);
55+
const keysB = Object.keys(b);
56+
57+
// Check if number of keys match
58+
if (keysA.length !== keysB.length) return false;
59+
60+
// Compare each key-value pair recursively
61+
return keysA.every(key => {
62+
if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
63+
return isEqual(a[key], b[key]);
64+
});
65+
}
66+
67+

package/collection2/main.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import { Meteor } from 'meteor/meteor';
22
import { Mongo } from 'meteor/mongo';
33
import SimpleSchema from "meteor/aldeed:simple-schema";
44
import { EJSON } from 'meteor/ejson';
5-
import isEmpty from 'lodash.isempty';
6-
import isEqual from 'lodash.isequal';
7-
import isObject from 'lodash.isobject';
8-
import { flattenSelector, isInsertType, isUpdateType, isUpsertType } from './lib';
5+
import { flattenSelector, isInsertType, isUpdateType, isUpsertType, isObject, isEqual } from './lib';
96

107

118
/**
@@ -228,13 +225,18 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
228225
_super.isCalledFromAsync = true;
229226
return Promise.resolve(_super.apply(this, args));
230227
} catch (err) {
231-
const addValidationErrorsPropName =
232-
typeof validationContext.addValidationErrors === 'function'
233-
? 'addValidationErrors'
228+
if (this._c2) {
229+
const addValidationErrorsPropName =
230+
typeof validationContext.addValidationErrors === 'function'
231+
? 'addValidationErrors'
234232
: 'addInvalidKeys';
235233
parsingServerError([err], validationContext, addValidationErrorsPropName);
236234
const error = getErrorObject(validationContext, err.message, err.code);
237235
return Promise.reject(error);
236+
} else {
237+
// do not change error if collection isn't being validated by collection2
238+
return Promise.reject(err);
239+
}
238240
}
239241
} else {
240242
return _super.apply(this, args);
@@ -250,12 +252,17 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
250252
try {
251253
return await _super.apply(this, args);
252254
} catch (err) {
255+
if (this._c2) {
253256
const addValidationErrorsPropName =
254257
typeof validationContext.addValidationErrors === 'function'
255258
? 'addValidationErrors'
256259
: 'addInvalidKeys';
257260
parsingServerError([err], validationContext, addValidationErrorsPropName);
258261
throw getErrorObject(validationContext, err.message, err.code);
262+
} else {
263+
// do not change error if collection isn't being validated by collection2
264+
throw err;
265+
}
259266
}
260267
};
261268
}
@@ -305,7 +312,7 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
305312
throw new Error('invalid type argument');
306313
}
307314

308-
const validatedObjectWasInitiallyEmpty = isEmpty(doc);
315+
const validatedObjectWasInitiallyEmpty = Object.keys(doc).length === 0;
309316

310317
// Support missing options arg
311318
if (!callback && typeof options === 'function') {
@@ -481,7 +488,7 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
481488
}
482489

483490
// XXX Maybe move this into SimpleSchema
484-
if (!validatedObjectWasInitiallyEmpty && isEmpty(docToValidate)) {
491+
if (!validatedObjectWasInitiallyEmpty && Object.keys(docToValidate).length === 0) {
485492
throw new Error(
486493
'After filtering out keys not in the schema, your ' +
487494
(isUpdateType(type) ? 'modifier' : 'object') +

package/collection2/package.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,15 @@ Package.describe({
99
git: 'https://github.com/aldeed/meteor-collection2.git'
1010
});
1111

12-
Npm.depends({
13-
'lodash.isempty': '4.4.0',
14-
'lodash.isequal': '4.5.0',
15-
'lodash.isobject': '3.0.2'
16-
});
17-
1812
Package.onUse(function (api) {
1913
api.versionsFrom(['1.12.1', '2.3', '3.0']);
2014
api.use('mongo');
2115
api.imply('mongo');
2216
api.use('minimongo');
2317
api.use('ejson');
2418
api.use('ecmascript');
25-
api.use('raix:[email protected]');
26-
api.use('aldeed:[email protected] || 2.0.0-rc.300.10');
19+
api.use('raix:[email protected] || 2.0.0');
20+
api.use('aldeed:[email protected] || 2.0.0');
2721
api.use('zodern:types');
2822

2923
api.addFiles(['./collection2.js']);
@@ -37,7 +31,7 @@ Package.onUse(function (api) {
3731
Package.onTest(function (api) {
3832
api.versionsFrom(['1.12.1', '2.3', '3.0']);
3933
api.use([
40-
'meteortesting:mocha@3.1.0-rc.1',
41-
'aldeed:collection2@4.0.2'
34+
'meteortesting:mocha@2.1.0 || 3.2.0',
35+
'aldeed:collection2'
4236
]);
4337
});

tests/.meteor/release

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1+

tests/.meteor/versions

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
1-
2-
aldeed:[email protected]-beta300.0
3-
4-
5-
6-
7-
8-
9-
10-
11-
12-
13-
14-
15-
16-
17-
18-
19-
20-
21-
22-
23-
24-
25-
26-
27-
28-
29-
1+
2+
3+
4+
5+
6+
7+
8+
9+
10+
11+
12+
13+
14+
15+
16+
17+
18+
19+
20+
21+
22+
23+
24+
25+
26+
27+
28+
29+
3030
31-
32-
33-
31+
32+
33+
3434
35-
36-
37-
35+
36+
37+
3838
meteortesting:[email protected]
3939
meteortesting:[email protected]
4040
meteortesting:[email protected]
41-
42-
43-
44-
45-
46-
47-
41+
42+
43+
44+
45+
46+
47+
4848
49-
50-
51-
npm-mongo@4.16.2-rc300.4
52-
53-
49+
50+
51+
npm-mongo@4.17.4
52+
53+
5454
55-
56-
57-
58-
59-
60-
61-
62-
63-
64-
65-
66-
67-
68-
69-
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+

0 commit comments

Comments
 (0)