Giter VIP home page Giter VIP logo

graphs's Introduction

Graphs

Oriented graph methods with shema and restrictions.

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.insertLink(a1, a2); // ~"b1"
var b1 = b.findLinkTo(a2); // { _id: "b1", _source: { id: 'a1', collection: 'a' }, _target: { id: 'a1', collection: 'a' } }
b1.source() // { _id: 'a1' }

Documentation

Methods

collection.attachGraph

()

Attach to the collection, all methods and all helpers.

Add to collection collection.isGraph = true;.

collection.insert.link

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

collection.find.link

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

Aliases
  • collection.findOne.link

collection.find.link.to

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

collection.find.link.from

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

collection.find.links

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

collection.find.links.to

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

collection.find.links.from

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

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, doc, fieldNames, modifier, options) => void)

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

collection.after.unlink

(handler: (userId, doc, fieldNames, modifier, options) => void)

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

collection.after.link.source

(handler: (userId, doc, fieldNames, modifier, options) => void)

collection.after.link.target

(handler: (userId, doc, fieldNames, modifier, options) => void)

collection.after.unlink.source

(handler: (userId, doc, fieldNames, modifier, options) => void)

collection.after.unlink.target

(handler: (userId, doc, 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;
    }
});

Versions

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

graphs's People

Contributors

ivansglazunov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.