Skip to content

meteor-shuttler/graphs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Graphs

Examples GitHub Atmosphere.js

Oriented graph methods with shema and restrictions.

Install

meteor add shuttler:graphs
Required

Example

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' }

Documentation

Methods

collection.attachGraph

(options?: Options)

Attach to the collection, all methods and all helpers.

Add to collection collection.isGraph = true;.

Options
schema

Boolean

Allows to forbid automatic attach scheme.

collection.attachGraph({ schema: false });

collection.link.insert

(source: Document|Ref, target: Document|Ref, customFields: Object, callback?: Function) => id: String

collection.link.update

(link: Document|Ref|String, source: Document|Ref, target: Document|Ref, customUpdateQuery: Object, callback?: Function) => count: Number

collection.link.update.source

(link: Document|Ref|String, source: Document|Ref, customUpdateQuery: Object, callback?: Function) => count: Number

Aliases
  • collection.link.update.from

collection.link.update.target

(link: Document|Ref|String, target: Document|Ref, customUpdateQuery: Object, callback?: Function) => count: Number

Aliases
  • collection.link.update.to

collection.link.find

(source: Document|Ref|(id: String), target: Document|Ref|(id: String), query: Object, options: Object) => Document|undefined

Aliases
  • collection.link.findOne collection.links.findOne

collection.link.find.target

(target: Document|Ref|(id: String), query: Object, options: Object) => Document|undefined

Aliases
  • collection.*.*.to

collection.link.find.source

(source: Document|Ref|(id: String), query: Object, options: Object) => Document|undefined

Aliases
  • collection.*.*.from

collection.links.find

(source: Document|Ref|(id: String), target: Document|Ref|(id: String), query: Object, options: Object) => Cursor

collection.links.find.target

(target: Document|Ref|(id: String), query: Object, options: Object) => Cursor

Aliases
  • collection.*.*.to

collection.links.find.source

(source: Document|Ref|(id: String), query: Object, options: Object) => Cursor

Aliases
  • collection.*.*.from

Hooks

Used package matb33:collection-hooks.

Available field this.action containing insert update or remove. Available fields this.sourceChanged: Boolean and this.targetChanged: Boolean.

collection.after.link

(handler: (userId, unlinked?, linked, fieldNames, modifier, options) => void)

unlinked is defined only on update.

Wrapper around matb33:collection-hooks .after.update and .after.insert.

collection.after.unlink

(handler: (userId, unlinked, linked?, fieldNames, modifier, options) => void)

linked is defined only on update.

Wrapper around matb33:collection-hooks .after.update and .after.remove.

collection.after.link.source

(handler: (userId, unlinked?, linked, fieldNames, modifier, options) => void)

collection.after.link.target

(handler: (userId, unlinked?, linked, fieldNames, modifier, options) => void)

collection.after.unlink.source

(handler: (userId, unlinked, linked?, fieldNames, modifier, options) => void)

collection.after.unlink.target

(handler: (userId, unlinked, linked?, fieldNames, modifier, options) => void)

Helpers

Used package dburles:collection-helpers.

document.source

() => Document|undefined

document.target

() => Document|undefined

Restrictions

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;
    }
});

Methods

Shuttler.getSelectorByDirection

(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' }

Shuttler.getRefByDirection

(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' }

Shuttler.getDocumentByDirection

(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' } }

Schemas

Shuttler.GraphSidesSchema

Source code

Shuttler.GraphDirectionSchema

Source code

Shuttler.GraphDirectionsSchema

Source code

Versions

0.0.17

  • Fix .link.update arguments bug.

0.0.16

  • collection.attachGraph options argument with schema option.

0.0.14

  • Added .link.update.to .link.update.target .link.update.from``.link.update.source

0.0.12

  • Document transformation on .after hooks.
  • Fix .link.find.* methods.

0.0.9

  • New syntax of hooks with unlinked and linked variables.
  • Little fixes

0.0.8

0.0.6

0.0.5

0.0.4

  • Add .after.link.source, .after.link.target, .after.unlink.source, .after.unlink.target
  • Add to after handler this.sourceChanged and this.targetChanged

0.0.3

  • Rename .insert.link argument query to customFields

About

Oriented graph methods with shema and restrictions.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published