Oriented graph methods with shema and restrictions.
meteor add shuttler:graphs
var a = new Mongo.Collection('a');
var a1 = a.insert({ _id: 'a1' });
var a2 = a.insert({ _id: 'a2' );
var b = new Mongo.Collection('b');
b.attachGraph();
b.link.insert(a1, a2); // ~"b1"
b.link.find.to(a2); // { _id: "b1", _source: { id: 'a1', collection: 'a' }, _target: { id: 'a1', collection: 'a' } }
b1.source() // { _id: 'a1' }
(options?: Options)
Attach to the collection, all methods and all helpers.
Add to collection collection.isGraph = true;
.
Boolean
Allows to forbid automatic attach scheme.
collection.attachGraph({ schema: false });
(source: Document|Ref, target: Document|Ref, customFields: Object, callback?: Function) => id: String
(link: Document|Ref|String, source: Document|Ref, target: Document|Ref, customUpdateQuery: Object, callback?: Function) => count: Number
(link: Document|Ref|String, source: Document|Ref, customUpdateQuery: Object, callback?: Function) => count: Number
collection.link.update.from
(link: Document|Ref|String, target: Document|Ref, customUpdateQuery: Object, callback?: Function) => count: Number
collection.link.update.to
(source: Document|Ref|(id: String), target: Document|Ref|(id: String), query: Object, options: Object) => Document|undefined
collection.link.findOne
collection.links.findOne
(target: Document|Ref|(id: String), query: Object, options: Object) => Document|undefined
collection.*.*.to
(source: Document|Ref|(id: String), query: Object, options: Object) => Document|undefined
collection.*.*.from
(source: Document|Ref|(id: String), target: Document|Ref|(id: String), query: Object, options: Object) => Cursor
(target: Document|Ref|(id: String), query: Object, options: Object) => Cursor
collection.*.*.to
(source: Document|Ref|(id: String), query: Object, options: Object) => Cursor
collection.*.*.from
Used package matb33:collection-hooks.
Available field this.action
containing insert
update
or remove
.
Available fields this.sourceChanged: Boolean
and this.targetChanged: Boolean
.
(handler: (userId, unlinked?, linked, fieldNames, modifier, options) => void)
unlinked
is defined only on update
.
Wrapper around matb33:collection-hooks .after.update and .after.insert.
(handler: (userId, unlinked, linked?, fieldNames, modifier, options) => void)
linked
is defined only on update
.
Wrapper around matb33:collection-hooks .after.update and .after.remove.
(handler: (userId, unlinked?, linked, fieldNames, modifier, options) => void)
(handler: (userId, unlinked?, linked, fieldNames, modifier, options) => void)
(handler: (userId, unlinked, linked?, fieldNames, modifier, options) => void)
(handler: (userId, unlinked, linked?, fieldNames, modifier, options) => void)
Used package dburles:collection-helpers.
() => Document|undefined
() => Document|undefined
Used package ivansglazunov:restrict.
Add new restriction checks. In the case of operation insert
the arguments fieldNames
and modifier
are not exists. Available argument action
containing insert
update
or remove
.
handler: (userId, doc, fieldNames, modifier, action) => Boolean
collection.allow({
'link': function(userId, doc, fieldNames, modifier, action) {
return true;
},
'link.source': function(userId, doc, fieldNames, modifier, action) {
return true;
},
'link.target': function(userId, doc, fieldNames, modifier, action) {
return true;
},
'unlink': function(userId, doc, fieldNames, modifier, action) {
return true;
},
'unlink.source': function(userId, doc, fieldNames, modifier, action) {
return true;
},
'unlink.target': function(userId, doc, fieldNames, modifier, action) {
return true;
}
});
collection.deny({
'link': function(userId, doc, fieldNames, modifier, action) {
return false;
},
'link.source': function(userId, doc, fieldNames, modifier, action) {
return false;
},
'link.target': function(userId, doc, fieldNames, modifier, action) {
return false;
},
'unlink': function(userId, doc, fieldNames, modifier, action) {
return false;
},
'unlink.source': function(userId, doc, fieldNames, modifier, action) {
return false;
},
'unlink.target': function(userId, doc, fieldNames, modifier, action) {
return false;
}
});
(direction: 'source'|'target'|'link', link: Document|Ref) => Object
test = Mongo.Collection('test');
test.attachGraph();
test.insert({ _id: '2' });
test.insert({ _id: '3' });
test.link.insert(test.findOne('2'), test.findOne('3'), { _id: '1' });
Shuttler.getSelectorByDirection('source', test.findOne('1'));
// { '_source.collection': 'test', '_source.id': '3' }
Shuttler.getSelectorByDirection('link', test.findOne('1'));
// { '_id': '1' }
(direction: 'source'|'target'|'link', link: Document|Ref) => Object
test = Mongo.Collection('test');
test.attachGraph();
test.insert({ _id: '2' });
test.insert({ _id: '3' });
test.link.insert(test.findOne('2'), test.findOne('3'), { _id: '1' });
Shuttler.getRefByDirection('source', test.findOne('1'));
// { collection: 'test', id: '2' }
Shuttler.getRefByDirection('link', test.findOne('1'));
// { collection: 'test', id: '1' }
(direction: 'source'|'target'|'link', link: Document|Ref) => Object
test = Mongo.Collection('test');
test.attachGraph();
test.insert({ _id: '2' });
test.insert({ _id: '3' });
test.link.insert(test.findOne('2'), test.findOne('3'), { _id: '1' });
Shuttler.getRefByDirection('source', test.findOne('1'));
// { _id: '2' }
Shuttler.getRefByDirection('link', test.findOne('1'));
// { _id: '1', _source: { collection: 'test', id: '2' }, _target: { collection: 'test', id: '3' } }
- Fix
.link.update
arguments bug.
collection.attachGraph
options
argument withschema
option.
- Added
.link.update.to
.link.update.target
.link.update.from``.link.update.source
- Document transformation on
.after
hooks. - Fix
.link.find.*
methods.
- New syntax of hooks with
unlinked
andlinked
variables. - Little fixes
- Support for
ivansglazunov:[email protected]
- Direction and sides schemas and methods.
- Add
.after.link.source
,.after.link.target
,.after.unlink.source
,.after.unlink.target
- Add to after handler
this.sourceChanged
andthis.targetChanged
- Rename
.insert.link
argumentquery
tocustomFields