Upgraded to 1.0.7

This commit is contained in:
Theodor Diaconu 2016-09-20 10:02:55 +03:00
parent 446d5eda86
commit e9609b2df0
6 changed files with 59 additions and 3 deletions

View file

@ -1,3 +1,7 @@
## 1.0.7
- Optimized creating link for _id only, by fetching the object with the storage field only
- Added restrictFields in the exposure module to easily restrictFields
## 1.0.6
- Fixed exposure bug for static fetching
- Exporting useful components that allow you to customly build your data graph

View file

@ -70,6 +70,26 @@ const data = query.fetch() // will not care about the firewall at all.
```
### Restrict fields easily
The reason for this function is that MongoDB queries do not allow fields like:
```
{
iWantThisField: 1,
iDontWantThisOne: 0
}
```
Using this function removes a bit of boilerplate code for you.
```
import {restrictFields} from 'meteor/cultofcoders:grapher';
Users.expose((filters, options, userId) => {
restrictFields(options, ['services', 'createdAt'];
});
```
### Next step
[Read about Query](query.md)

View file

@ -0,0 +1,19 @@
/**
* This is used to restrict some fields to some users, by passing the fields as array in the exposure object
* For example in an user exposure: restrictFields(options, ['services', 'createdAt'])
*
* @param options
* @param restrictedFields
*/
export default (options, restrictedFields) => {
if (options.fields) {
options.fields = _.omit(options.fields, ...restrictedFields);
} else {
let restrictingRules = {};
_.each(restrictedFields, field => {
restrictingRules[field] = 0
});
options.fields = _.extend({}, options.fields, restrictingRules)
}
}

View file

@ -37,9 +37,18 @@ _.extend(Mongo.Collection.prototype, {
throw new Meteor.Error(`There is no link ${name} for collection ${this._name}`);
}
const linker = linkData[name];
let object = objectOrId;
if (typeof(objectOrId) == 'string') {
object = this.findOne(objectOrId);
if (!linker.isVirtual()) {
object = this.findOne(objectOrId, {
fields: {
[linker.linkStorageField]: 1
}
});
} else {
object = {_id: objectOrId};
}
}
return linkData[name].createLink(object);

View file

@ -20,3 +20,7 @@ export {
export {
default as applyFilterFunction
} from './lib/query/lib/applyFilterFunction.js';
export {
default as restrictFields
} from './lib/exposure/lib/restrictFields.js';

View file

@ -1,6 +1,6 @@
Package.describe({
name: 'cultofcoders:grapher',
version: '1.0.6',
version: '1.0.7',
// Brief, one-line summary of the package.
summary: 'Grapher is a way of linking/joining collections. And fetching data in a GraphQL style.',
// URL to the Git repository containing the source code for this package.