Skip to content

Commit

Permalink
Merge branch 'master' into add-types
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinstardust authored Nov 16, 2024
2 parents a90815b + f1804ea commit 1300372
Show file tree
Hide file tree
Showing 9 changed files with 197 additions and 90 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/testsuite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ jobs:
tests:
name: tests
runs-on: ubuntu-latest
strategy:
matrix:
meteor: [ '2.13.3', '3.0.4' ]
# needs: [lintcode,lintstyle,lintdocs] # we could add prior jobs for linting, if desired
steps:
- name: checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup meteor
uses: meteorengineer/setup-meteor@v1
uses: meteorengineer/setup-meteor@v2
with:
meteor-release: '2.13.3'
meteor-release: ${{ matrix.meteor }}

- name: cache dependencies
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*

- [4.0.4](#404)
- [4.0.3](#403)
- [4.0.2](#402)
- [4.0.1](#401)
- [4.0.0](#400)
Expand Down Expand Up @@ -80,6 +82,19 @@

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

## 4.0.4

- Return unaltered error message when collection isn't being validated and doesn't have simple schema attached thanks to @DmytroSoninLinguahouse
- Update test application to use Meteor release number 3.0.4
- Remove lodash dependencies
- Updated dependencies
- Expanded dependencies compatibility
- Extended test suite

## 4.0.3

- Update Meteor release to 3.0

## 4.0.2

- Make collection2 compatible with the newly released RC
Expand Down
25 changes: 21 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions package/collection2/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,29 @@ export const isUpdateType = function (type) {
export const isUpsertType = function (type) {
return ['upsert', 'upsertAsync'].includes(type);
};

export function isObject(value) {
return typeof value === 'object' && value !== null && !Array.isArray(value);
}

export function isEqual(a, b) {
// Handle primitive types and null/undefined
if (a === b) return true;
if (a == null || b == null) return false;
if (typeof a !== 'object' || typeof b !== 'object') return false;

// Get object keys
const keysA = Object.keys(a);
const keysB = Object.keys(b);

// Check if number of keys match
if (keysA.length !== keysB.length) return false;

// Compare each key-value pair recursively
return keysA.every(key => {
if (!Object.prototype.hasOwnProperty.call(b, key)) return false;
return isEqual(a[key], b[key]);
});
}


25 changes: 16 additions & 9 deletions package/collection2/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import SimpleSchema from "meteor/aldeed:simple-schema";
import { EJSON } from 'meteor/ejson';
import isEmpty from 'lodash.isempty';
import isEqual from 'lodash.isequal';
import isObject from 'lodash.isobject';
import { flattenSelector, isInsertType, isUpdateType, isUpsertType } from './lib';
import { flattenSelector, isInsertType, isUpdateType, isUpsertType, isObject, isEqual } from './lib';


/**
Expand Down Expand Up @@ -228,13 +225,18 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
_super.isCalledFromAsync = true;
return Promise.resolve(_super.apply(this, args));
} catch (err) {
const addValidationErrorsPropName =
typeof validationContext.addValidationErrors === 'function'
? 'addValidationErrors'
if (this._c2) {
const addValidationErrorsPropName =
typeof validationContext.addValidationErrors === 'function'
? 'addValidationErrors'
: 'addInvalidKeys';
parsingServerError([err], validationContext, addValidationErrorsPropName);
const error = getErrorObject(validationContext, err.message, err.code);
return Promise.reject(error);
} else {
// do not change error if collection isn't being validated by collection2
return Promise.reject(err);
}
}
} else {
return _super.apply(this, args);
Expand All @@ -250,12 +252,17 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
try {
return await _super.apply(this, args);
} catch (err) {
if (this._c2) {
const addValidationErrorsPropName =
typeof validationContext.addValidationErrors === 'function'
? 'addValidationErrors'
: 'addInvalidKeys';
parsingServerError([err], validationContext, addValidationErrorsPropName);
throw getErrorObject(validationContext, err.message, err.code);
} else {
// do not change error if collection isn't being validated by collection2
throw err;
}
}
};
}
Expand Down Expand Up @@ -305,7 +312,7 @@ Mongo.Collection.prototype.attachSchema = function c2AttachSchema(ss, options) {
throw new Error('invalid type argument');
}

const validatedObjectWasInitiallyEmpty = isEmpty(doc);
const validatedObjectWasInitiallyEmpty = Object.keys(doc).length === 0;

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

// XXX Maybe move this into SimpleSchema
if (!validatedObjectWasInitiallyEmpty && isEmpty(docToValidate)) {
if (!validatedObjectWasInitiallyEmpty && Object.keys(docToValidate).length === 0) {
throw new Error(
'After filtering out keys not in the schema, your ' +
(isUpdateType(type) ? 'modifier' : 'object') +
Expand Down
14 changes: 4 additions & 10 deletions package/collection2/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,15 @@ Package.describe({
git: 'https://github.com/aldeed/meteor-collection2.git'
});

Npm.depends({
'lodash.isempty': '4.4.0',
'lodash.isequal': '4.5.0',
'lodash.isobject': '3.0.2'
});

Package.onUse(function (api) {
api.versionsFrom(['1.12.1', '2.3', '3.0']);
api.use('mongo');
api.imply('mongo');
api.use('minimongo');
api.use('ejson');
api.use('ecmascript');
api.use('raix:[email protected]');
api.use('aldeed:[email protected] || 2.0.0-rc.300.10');
api.use('raix:[email protected] || 2.0.0');
api.use('aldeed:[email protected] || 2.0.0');
api.use('zodern:types');

api.addFiles(['./collection2.js']);
Expand All @@ -37,7 +31,7 @@ Package.onUse(function (api) {
Package.onTest(function (api) {
api.versionsFrom(['1.12.1', '2.3', '3.0']);
api.use([
'meteortesting:mocha@3.1.0-rc.1',
'aldeed:collection2@4.0.2'
'meteortesting:mocha@2.1.0 || 3.2.0',
'aldeed:collection2'
]);
});
2 changes: 1 addition & 1 deletion tests/.meteor/release
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[email protected]-rc.4
[email protected]
124 changes: 62 additions & 62 deletions tests/.meteor/versions
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
aldeed:[email protected].2
aldeed:[email protected]-beta300.0
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected].0-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected].2-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected].0-rc300.4
[email protected].1-rc300.4
[email protected].0-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected].2-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
aldeed:[email protected].4
aldeed:[email protected]
[email protected]
[email protected]
[email protected]
[email protected].1
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected].2
[email protected]
[email protected].2
[email protected]
[email protected]
[email protected]
[email protected].3
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]-rc300.4
[email protected].0-rc300.4
[email protected]-rc300.4
[email protected]
[email protected].1
[email protected]
meteortesting:[email protected]
meteortesting:[email protected]
meteortesting:[email protected]
[email protected]-rc300.4
[email protected]-rc300.4
[email protected].0-rc300.4
[email protected]-rc300.4
[email protected].1-rc300.4
[email protected]-rc300.4
[email protected].0-rc300.4
[email protected]
[email protected]
[email protected].1
[email protected]
[email protected].2
[email protected]
[email protected].2
[email protected]
[email protected]-rc300.4
[email protected]-rc300.4
npm-mongo@4.16.2-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]
[email protected]
npm-mongo@4.17.4
[email protected]
[email protected]
raix:[email protected]
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected]-rc300.4
[email protected].2-rc300.4
[email protected].0-rc300.4
[email protected]-rc300.4
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected].3
[email protected]
Loading

0 comments on commit 1300372

Please sign in to comment.