/*!
 * Copyright (C) 2017 Glayzzle (BSD3 License)
 * @authors https://github.com/glayzzle/php-reflection/graphs/contributors
 * @url http://glayzzle.com
 */
'use strict';

/**
 * This file contains customisations in order to integrate grafine with
 * php-reflection
 */

var grafine = require('grafine');

// replace the point class with the generic node class
grafine.point = require('./node');

// extends constructor
var graphCtor = grafine.graph;
grafine.graph = function(shards, lazyCache) {
    graphCtor.apply(this, [shards]);
    this.lazyCache = lazyCache;
};
inherits(grafine.graph, graphCtor);

// creating the shard
var graphCreateShard = grafine.graph.prototype.createShard;
grafine.graph.prototype.createShard = function(id) {
    if (typeof this.lazyCache === 'function') {
        return this.lazyCache('shard', id);
    }
    return graphCreateShard.apply(this, [id]);
};

// creating the index
var graphCreateIndex = grafine.graph.prototype.createIndex;
grafine.graph.prototype.createIndex = function(id) {
    if (typeof this.lazyCache === 'function') {
        return this.lazyCache('index', id);
    }
    return graphCreateIndex.apply(this, [id]);
};

module.exports = grafine;

@@ -293,24 +293,95 @@
 ('grafine');
+%0Avar inherits = require('util').inherits;%0Avar node = require('./node');
 %0A%0A// replace
@@ -441,33 +441,20 @@
 point = 
-require('./
 node
-')
 ;%0A%0A// ex
@@ -531,25 +531,18 @@
 ion(
-shards, lazyCache
+repository
 ) %7B%0A
@@ -572,48 +572,69 @@
 s, %5B
-shards%5D);%0A    this.lazyCache = lazyCache
+repository.options.shards%5D);%0A    this.repository = repository
 ;%0A%7D;
@@ -814,70 +814,166 @@
     
-if (typeof this.lazyCache === 'function') %7B%0A        return thi
+var shard = graphCreateShard.apply(this, %5Bid%5D);%0A    if (typeof this.repository.options.lazyCache === 'function') %7B%0A        var result = this.repository.option
 s.la
@@ -1002,55 +1002,92 @@
     
-%7D%0A    return graphCreateShard.apply(this, %5Bid%5D)
+    if (result) %7B%0A            shard.import(result);%0A        %7D%0A    %7D%0A    return shard
 ;%0A%7D;
@@ -1227,30 +1227,101 @@
 ) %7B%0A    
-if (typeof thi
+var index = graphCreateIndex.apply(this, %5Bid%5D);%0A    if (typeof this.repository.option
 s.lazyCa
@@ -1354,18 +1354,43 @@
     
-return thi
+var result = this.repository.option
 s.la
@@ -1419,55 +1419,92 @@
     
-%7D%0A
     
-return graphCreateIndex.apply(this, %5Bid%5D)
+if (result) %7B%0A            index.import(result);%0A        %7D%0A    %7D%0A    return index
 ;%0A%7D;

fix function creators