deploy1 6 gadi atpakaļ
vecāks
revīzija
ba37c39821
4 mainītis faili ar 1241 papildinājumiem un 0 dzēšanām
  1. 807 0
      electra2020.js
  2. 17 0
      index.js
  3. 18 0
      package.json
  4. 399 0
      test1.js

+ 807 - 0
electra2020.js

@@ -0,0 +1,807 @@
+var EventEmitter = require("events").EventEmitter
+
+var _ = require("lodash");
+var async = require("async");
+
+function uberfactory(uuid, slugger) {
+
+    var ignores = [
+        "uninherits",
+        "inherits",
+        "unextends",
+        "extends",
+        "unisa",
+        "isa",
+        "relatesAsToWith",
+        "test",
+        "emita",
+        "emitas",
+        "data2",
+        "getStuff",
+        "pingup",
+        "data",
+        "metas2",
+        "metas",
+        "metas3",
+        "exporta",
+        "pickdeep",
+        "withAllSync",
+        "withAll",
+        "innerExport",
+        "exportFlatSync",
+        "exportSync",
+        "export2",
+        "export",
+        "domain",
+        "_events",
+        "rawListeners",
+        "_maxListeners",
+        "setMaxListeners",
+        "getMaxListeners",
+        "emit",
+        "addListener",
+        "on",
+        "prependListener",
+        "once",
+        "prependOnceListener",
+        "removeListener",
+        "removeAllListeners",
+        "listeners",
+        "listenerCount",
+        "eventNames",
+        "_data", "path", "name", "children", "parents", "_inherits", "_extends", "_isa",
+        "_hasa", "_relations", "_references", "_created", "_metas",
+        "_rootname", "exportSerialised"
+    ]
+
+
+    return function factory(therootname) {
+        var seed = therootname;
+        console.log("ROOT:", therootname);
+
+        var ROOT = new electra(therootname, true, false)
+
+        function inner(name) {
+            if (typeof(name) == "undefined") {
+                return ROOT;
+            }
+            name = slugger(name);
+
+            if (!ROOT.children[name]) {
+                ROOT.children[name] = new electra(name);
+            }
+            return ROOT.children[name]
+        }
+
+        function electra(name, isroot, parent) {
+            //name = slugger(name);
+            this._data = {}
+            this._metas = {};
+            this.path = (parent ? parent.path : "") + name;
+            this.name = name;
+            //this._id = uuid();
+            this.children = {};
+            this.parents = {};
+            this._inherits = {};
+            this._extends = {};
+            this._isa = {};
+            this._hasa = {};
+            this._relations = {};
+            this._references = {};
+            this._created = new Date();
+            this._rootname = therootname;
+            var self = this;
+            if (parent) {
+                this.parents[parent.name] = parent;
+                this.path = parent.path + "/" + name
+            }
+            if (isroot) {
+                this.isroot = true;
+                return this;
+            }
+
+            function xinner(name) {
+                var args = Array.prototype.slice.apply(arguments, [0]);
+                if (args.length > 1) {
+                    return args.map(function(n) {
+                        return xinner(n)
+                    })
+                }
+                if (typeof(name) == "undefined") {
+                    return self;
+                }
+                name = slugger(name);
+
+                if (name.indexOf("://") > -1) {
+                    if (!self.children[name]) {
+                        self.children[name] = new electra(name, false, self);
+                        self.pingup("created", self.children[name](), name)
+                        self.emit("added", name);
+                    }
+                    return self.children[name]
+                }
+                if (name.indexOf("/") > -1) {
+                    //its a path;
+                    var arr = name.split("/");
+                    var newname = arr.shift();
+                    if (!self.children[newname]) {
+                        self.children[newname] = new electra(newname, false, self);
+                        self.pingup("created", self.children[newname](), newname, arr)
+                        self.emit("added", newname);
+                    }
+                    return self.children[newname](arr.join("/"))
+                }
+                if (!self.children[name]) {
+                    self.children[name] = new electra(name, false, self);
+                    self.pingup("created", self.children[name](), name)
+                }
+                return self.children[name]
+            }
+            return xinner
+        }
+        electra.prototype.__proto__ = EventEmitter.prototype
+
+        electra.prototype.inherits = function(obj_) {
+            var obj = typeof(obj_) === "function" ? obj_() : typeof(obj_) === "object" ? obj_ : typeof(obj_) === "string" ? inner(obj_)() : false
+            if (obj) {
+                this._inherits[obj.path] = obj;
+                obj._extends[this.path] = this;
+            }
+            return this;
+        }
+
+        electra.prototype.uninherits = function(obj_) {
+            var obj = typeof(obj_) === "function" ? obj_() : typeof(obj_) === "object" ? obj_ : typeof(obj_) === "string" ? inner(obj_)() : false
+            if (obj && this._inherits[obj.path]) {
+                delete this._inherits[obj.path]
+                delete obj._extends[this.path]
+            }
+            return this;
+        }
+
+        electra.prototype.extends = function(obj_) {
+            var obj = typeof(obj_) === "function" ? obj_() : typeof(obj_) === "object" ? obj_ : typeof(obj_) === "string" ? inner(obj_)() : false
+            if (obj) {
+                this._extends[obj.path] = obj;
+                obj._inherits[this.path] = this;
+            }
+            return this;
+        }
+        electra.prototype.unextends = function(obj_) {
+            var obj = typeof(obj_) === "function" ? obj_() : typeof(obj_) === "object" ? obj_ : typeof(obj_) === "string" ? inner(obj_)() : false
+            if (obj && this._extends[obj.path]) {
+                delete this._extends[obj.path]
+                delete obj._inherits[this.path]
+            }
+            return this;
+        }
+
+
+
+
+
+        electra.prototype.isa = function(elef) {
+            var self = this;
+            var args = Array.prototype.slice.apply(arguments, [0]);
+            if (args.length > 1) {
+                args.map(function(n) {
+                    var ele = typeof(n) === "function" ? n() : n;
+                    self._isa[ele.path] = ele
+                    ele._hasa[self.path] = self;
+                    self.pingup("isa", self, ele.path)
+                    ele.pingup("isa", self, ele.path)
+
+                })
+            } else {
+                if (typeof(elef) === "object" && elef.length) {
+                    elef.map(function(n) {
+                        var ele = typeof(n) === "function" ? n() : n;
+                        self._isa[ele.path] = ele
+                        ele._hasa[self.path] = self;
+                        self.pingup("isa", self, ele.path)
+                        ele.pingup("isa", self, ele.path)
+                    })
+                } else {
+                    var ele = typeof(elef) === "function" ? elef() : typeof(elef) === "object" ? elef : typeof(elef) === "string" ? inner(elef)() : false
+                    if (ele) {
+                        this._isa[ele.path] = ele
+                        ele._hasa[this.path] = this;
+                        self.pingup("isa", self, ele.path)
+                        ele.pingup("isa", self, ele.path)
+
+                    }
+                }
+            }
+            return this;
+        }
+
+        electra.prototype.unisa = function(elef) {
+            var self = this;
+            var args = Array.prototype.slice.apply(arguments, [0]);
+            if (args.length > 1) {
+                args.map(function(n) {
+                    var ele = typeof(n) === "function" ? n() : n;
+                    delete self._isa[ele.path]
+                    delete ele._hasa[self.path]
+                    self.pingup("isa", self, ele.path)
+                    ele.pingup("isa", self, ele.path)
+
+                })
+            } else {
+                if (typeof(elef) === "object" && elef.length) {
+                    elef.map(function(n) {
+                        var ele = typeof(n) === "function" ? n() : n;
+                        delete self._isa[ele.path]
+                        delete ele._hasa[self.path]
+                        self.pingup("isa", self, ele.path)
+                        ele.pingup("isa", self, ele.path)
+                    })
+                } else {
+                    var ele = typeof(elef) === "function" ? elef() : elef;
+                    delete this._isa[ele.path]
+                    delete ele._hasa[this.path]
+                    self.pingup("isa", self, ele.path)
+                    ele.pingup("isa", self, ele.path)
+                }
+            }
+            return this;
+        }
+
+
+        electra.prototype.relatesAsToWith = function(relationout, elef, relationto, withstuff) {
+            var self = this;
+            if (typeof(relationto) === "undefined") {
+                relationto = relationout;
+            }
+            if (typeof(withstuff) === "undefined") {
+                withstuff = "";
+            }
+            var withstuffOut = Object.assign({
+                "out": relationout,
+                "in": relationto
+            }, withstuff);
+            var withstuffTo = Object.assign({
+                "in": relationout,
+                "out": relationto
+            }, withstuff);
+            if (typeof(elef) === "object" && elef.length) {
+                elef.map(function(n) {
+                    var ele = typeof(n) === "function" ? n() : n;
+                    self._relations[relationout] = self._relations[relationout] || {}
+                    self._relations[relationout][ele.path] = {
+                        ref: ele,
+                        context: withstuffOut
+                    }
+                    ele._relations[relationto] = ele._relations[relationto] || {}
+                    ele._relations[relationto][self.path] = {
+                        ref: self,
+                        context: withstuffTo
+                    }
+                })
+            } else {
+                var ele = typeof(elef) === "function" ? elef() : elef;
+                self._relations[relationout] = self._relations[relationout] || {}
+                self._relations[relationout][ele.path] = {
+                    ref: ele,
+                    context: withstuffOut
+                }
+                ele._relations[relationto] = ele._relations[relationto] || {}
+                ele._relations[relationto][self.path] = {
+                    ref: self,
+                    context: withstuffTo
+                }
+            }
+            return this;
+        }
+
+        electra.prototype.test = function() {
+            return this;
+        }
+        electra.prototype.emita = function() {
+            var self = this;
+            var args = Array.prototype.slice.apply(arguments, [0]);
+
+            var kk = _.keys(this.parents);
+            if (kk.length > 0) {
+                kk.map(function(k) {
+                    self.parents[k].emita.apply(self.parents[k], args)
+                })
+            } else {}
+
+
+            var kk = _.keys(this.children);
+            if (kk.length > 0) {
+                kk.map(function(k) {
+                    //self.children[k].emita.apply(self.children[k],args)
+                })
+            } else {}
+
+            /*    	_.map(this.children,function(child,name){
+    		child().emita.apply(child(),args);
+    	})	**/
+        }
+        electra.prototype.emitas = function() {
+            var self = this;
+            var args = Array.prototype.slice.apply(arguments, [0]);
+
+            var kk = _.keys(this.parents);
+            if (kk.length > 0) {
+                kk.map(function(k) {
+                    self.parents[k].emita.apply(self.parents[k], args)
+                })
+            } else {}
+
+
+            var kk = _.keys(this.children);
+            if (kk.length > 0) {
+                kk.map(function(k) {
+                    //self.children[k].emita.apply(self.children[k],args)
+                })
+            } else {}
+
+            /*    	_.map(this.children,function(child,name){
+    		child().emita.apply(child(),args);
+    	})	**/
+        }
+        electra.prototype.data2 = function(key, value) {
+            var self = this;
+            if (typeof(key) === "undefined") {
+                return this._data;
+            } else {
+                if (typeof(value) === "undefined") {
+                    if (typeof(key) === "object") {
+                        var oldvalue = this._data;
+                        this._data = Object.assign(this._data, key);
+                        _.map(this.parents, function(par, nam) {
+                            par.emit("changed", self, "[[object]]", self._data, oldvalue);
+                        })
+                        this.emit("changed", this, "[[object]]", this._data, oldvalue);
+                        return this;
+                    } else {
+                        return this._data[key];
+                    }
+                } else {
+                    var oldvalue = this._data[key];
+                    this._data[key] = value;
+                    _.map(this.parents, function(par, nam) {
+                        par.emit("changed", self, key, value, oldvalue);
+                    })
+                    this.emit("changed", this, key, value, oldvalue);
+                    return this._data[key];
+                }
+            }
+        }
+
+        electra.prototype.getStuff = function(stuff, applybefore, named_, dd) {
+            var named = named_ || "data";
+            var dd = dd || false;
+            var obj = {
+                name: this.path,
+                from: named,
+                data: applybefore(getpath(this, stuff))
+            }
+
+            var arr = [obj];
+            if (dd) {
+                return arr
+            }
+            arr = [].concat.apply(arr, _.map(this._inherits, function(par, nam) {
+                return par.getStuff.apply(par, [stuff, applybefore, "inherit_" + named_]);
+            }))
+            arr = [].concat.apply(arr, _.map(this.parents, function(par, nam) {
+                return par.getStuff.apply(par, [stuff, applybefore, "parent_" + named_]);
+            }))
+            arr = [].concat.apply(arr, _.map(this._isa, function(par, nam) {
+                return par.getStuff.apply(par, [stuff, applybefore, "isa_" + named_, true]);
+            }))
+            arr = arr.filter(function(a) {
+                return a.data ? a.data.length > 0 : false
+            });
+            return arr
+        }
+
+
+
+        electra.prototype.pingup = function() {
+            var args = Array.prototype.slice.apply(arguments, [0]);
+            _.map(this.parents, function(par, nam) {
+                return par.pingup.apply(par, args);
+            })
+            this.emit.apply(this, args);
+        }
+
+        electra.prototype.data = function(key, value) {
+            var self = this;
+            if (typeof(key) === "undefined") {
+                return this._data;
+            } else {
+                if (typeof(value) === "undefined") {
+                    if (typeof(key) === "object") {
+                        var oldvalue = this._data;
+                        this._data = Object.assign(this._data, key);
+                        this.pingup("changed", self, "[[object]]", self._data, oldvalue)
+                        return this;
+                    } else {
+                        return this._data[key];
+                    }
+                } else {
+                    var oldvalue = getpath(this._data, key); //this._data[key];
+                    setpath(this._data, key, value)
+                    //                    this._data[key] = value;
+                    this.pingup("changed", self, key, value, oldvalue)
+                    return getpath(this._data, key); //this._data[key];
+                }
+            }
+        }
+
+
+        electra.prototype.metas = function(key, value) {
+            var self = this;
+            if (typeof(key) === "undefined") {
+                return this._metas;
+            } else {
+                if (typeof(value) === "undefined") {
+                    if (typeof(key) === "object") {
+                        var oldvalue = this._metas;
+                        this._metas = Object.assign(this._metas, key);
+                        this.pingup("changed:meta", self, "[[object]]", self._metas, oldvalue)
+                        return this;
+                    } else {
+                        return this._metas[key];
+                    }
+                } else {
+                    var oldvalue = this._metas[key];
+                    this._metas[key] = value;
+                    this.pingup("changed:meta", self, key, value, oldvalue)
+                    return this._metas[key];
+                }
+            }
+        }
+
+
+        /*        electra.prototype.metas = function() {
+            var self = this;
+            var args = Array.prototype.slice.apply(arguments, [0]);
+            if (args.length === 0) {
+                return this._metas;
+            }
+            args.map(function(obj_) {
+                var obj = typeof(obj_) === "function" ? obj_() : typeof(obj_) === "object" ? obj_ : typeof(obj_) === "string" ? inner(obj_)() : false
+                if (obj) {
+                    self._metas.push({
+                        "meta": obj,
+                        "data": {}
+                    })
+                }
+            })
+
+            return this;
+        }
+
+
+        electra.prototype.metas3 = function(arr) {
+            var self = this;
+            self._metas = self._metas.concat(arr);
+            return self;
+        }
+*/
+
+
+        electra.prototype.exporta = function(path) {
+            this.export(path, function(err, arr) {
+                //    console.log("EXPORTED", err, JSON.stringify(arr, true, 2));
+            })
+        }
+
+        electra.prototype.pickdeep = function(prop, cb) {
+            var self = this;
+            async.mapLimit(this.children, 10, function(obj, next) {
+                //setTimeout(function(){
+                obj().pickdeep(prop, next)
+                //},1)
+                //	 		next(null,)
+            }, function(err, collect) {
+                cb(err, [].concat.apply([self[prop]], collect));
+            })
+            return this;
+        }
+        electra.prototype.withAllSync = function(func, cb) {
+            var self = this;
+            async.mapLimit(this.children, 10, function(obj, next) {
+                //setTimeout(function(){
+                obj().withAllSync(func, next)
+                //},1)
+                //	 		next(null,)
+            }, function(err, collect) {
+                cb(err, [].concat.apply([func(self)], collect));
+            })
+            return this;
+        }
+        electra.prototype.withAll = function(func, cb) {
+            var self = this;
+            async.mapLimit(this.children, 10, function(obj, next) {
+                obj().withAll(func, next)
+            }, function(err, collect) {
+                func(self, function(err2, result) {
+                    cb(err || err2, [].concat.apply([result], collect));
+                })
+
+            })
+            return this;
+        }
+
+        electra.prototype.exportSync = function(path, serializers) {
+            var self = this;
+
+            var obj = self.innerExport(path, serializers);
+
+            var collect = _.map(self.children, function(child, name) {
+                return child().exportSync(path + "/" + name, serializers)
+            })
+            collect.sort(function(a, b) {
+                return a.name > b.name ? 1 : a.name < b.name ? -1 : 0
+            })
+            obj.children = collect;
+
+            return obj;
+        }
+
+        electra.prototype.exportFlatSync = function(path) {
+            var self = this;
+
+            return [].concat.apply([self.innerExport(path)], _.map(self.children, function(child, name) {
+                return child().exportFlatSync(path + "/" + name)
+            }))
+
+        }
+
+
+        electra.prototype.export2 = function(path, cb) {
+            var self = this;
+            var obj = self.innerExport(path);
+            obj.children = _.map(self.children, function(a, n) {
+                return a().path
+            });
+            cb(null, obj);
+        }
+        electra.prototype.innerExport = function(path, serializers) {
+            var self = this;
+
+            var obj = {};
+            // obj._id = self._id;
+            obj.name = self.name;
+            obj.path = self.path;
+            obj.created = self._created.toJSON();
+
+            obj.data = self._data;
+            obj.meta = self._metas;
+
+            obj.inherits = _.map(self._inherits, function(a, n) {
+                return a.path
+            });
+            obj.extends = _.map(self._extends, function(a, n) {
+                return a.path
+            });
+            /*obj.parents = _.map(self.parents, function(a, n) {
+                return a.path
+            });*/
+            obj.isa = _.map(self._isa, function(a, n) {
+                return a.path
+            });
+            /*obj.hasa = _.map(self._hasa, function(a, n) {
+                return a.path
+            });*/
+
+            obj.rel = {};
+            _.map(self._relations, function(a, n) {
+                obj.rel[n] = {}
+                _.map(a, function(aa, nn) {
+                    obj.rel[n][aa.ref.path] = aa.context;
+                });
+            });
+
+            //clean up
+            obj.inherits = obj.inherits.length ? obj.inherits : undefined;
+            obj.extends = obj.extends.length ? obj.extends : undefined;
+            //obj.parents = obj.parents.length ? obj.parents : undefined;
+            obj.isa = obj.isa.length ? obj.isa : undefined;
+            //obj.hasa = obj.hasa.length ? obj.hasa : undefined;
+            obj.data = _.size(obj.data) ? obj.data : undefined;
+            obj.meta = _.size(obj.meta) ? obj.meta : undefined;
+            obj.rel = _.size(obj.rel) ? obj.rel : undefined;
+
+            _.keys(obj).map(function(k) {
+                if (obj[k] === undefined) {
+                    delete obj[k];
+                    //obj[k] = null /* nope */
+                }
+                674555
+            })
+            var therest = _.omit(self, ignores);
+
+            seriadeep(therest, obj, serializers);
+
+            /*_.map(therest, function(val, ke) {
+                if (typeof(val) === "function") {
+                    obj[ke] = "$$$FUNCTION$$$" + val;
+                } else {
+                    if (serializers && serializers[ke]) {
+                        obj[ke] = serializers[ke](val);
+                    } else {
+                        _.map(val,function(cval,cprop){
+                        })
+                        obj[ke] = val;
+                    }
+                }
+            })
+
+*/
+
+            return obj
+        }
+
+        function seriadeep(rest, obj, serializers) {
+            _.map(rest, function(val, ke) {
+                if (typeof(val) === "function") {
+                    obj[ke] = "$$$FUNCTION$$$" + val;
+                } else if (typeof(val) === "object") {
+                    obj[ke] = seriadeep(val, obj, serializers);
+                } else {
+                    if (serializers && serializers[ke]) {
+                        obj[ke] = serializers[ke](val)
+                    } else {
+                        obj[ke] = val;
+                    }
+                }
+            })
+        }
+
+        electra.prototype.exportSerialised = function(serializers) {
+            var self = this;
+            return function(path, cb) {
+                async.mapLimit(this.children, 10, function(obj, next) {
+                    obj().exportSerialised(serializers)(path + obj().name, next)
+                    //          next(null,)
+                }, function(err, collect) {
+                    var obj = self.innerExport(path, serializers);
+                    collect.sort(function(a, b) {
+                        return a.name > b.name ? 1 : a.name < b.name ? -1 : 0
+                    })
+                    obj.children = collect;
+                    cb(err, obj);
+                })
+                return this;
+            }
+        }
+
+
+        electra.prototype.export = function(path, cb) {
+            var self = this;
+            async.mapLimit(this.children, 10, function(obj, next) {
+                obj().export(path + obj().name, next)
+                //	 		next(null,)
+            }, function(err, collect) {
+                var obj = self.innerExport(path);
+                collect.sort(function(a, b) {
+                    return a.name > b.name ? 1 : a.name < b.name ? -1 : 0
+                })
+                obj.children = collect;
+                cb(err, obj);
+            })
+            return this;
+        }
+
+
+
+        return inner
+    }
+
+}
+
+function getpath(obj, path) {
+    path = path || "";
+    var arr = path.split(".");
+    var t = obj;
+    var done = false;
+    if (arr.length) {
+        while (arr.length && !done) {
+            var check = arr.shift();
+            if (check !== "") {
+                t = t[check];
+            }
+            if (typeof t !== "object") {
+                done = true;
+            }
+        }
+    }
+    return t;
+}
+
+function setpath(obj, path, value) {
+    if (typeof obj !== "object" || !obj) {
+        throw new Error("obj is not Object");
+    }
+    if (typeof path !== "string" || path === "") {
+        throw new Error("path must be string with length > 0");
+    }
+    var arr = path.split(".");
+    var done = false;
+    var t = obj;
+    if (arr.length > 1) {
+        while (arr.length && t && !done) {
+            var check = arr.shift();
+            if (typeof t[check] === "object" && arr.length > 0) {
+                t = t[check];
+            } else {
+                done = true;
+                arr.unshift(check);
+            }
+        }
+        var xt = t;
+        while (arr.length) {
+            var tt = arr.shift();
+            if (arr.length) { //go deeper
+                xt = xt[tt] = {};
+            } else {
+                //last
+                xt[tt] = value;
+            }
+        }
+    } else {
+        if (arr.length === 1 && arr[0] !== "") {
+            t[arr[0]] = value;
+        }
+    }
+}
+
+
+uberfactory.ignores = ignores = [
+    "inherits",
+    "uninherits",
+    "unextends",
+    "extends",
+    "isa",
+    "unisa",
+    "relatesAsToWith",
+    "test",
+    "emita",
+    "emitas",
+    "data2",
+    "getStuff",
+    "pingup",
+    "data",
+    "metas2",
+    "metas",
+    "metas3",
+    "exporta",
+    "pickdeep",
+    "withAllSync",
+    "withAll",
+    "innerExport",
+    "exportFlatSync",
+    "exportSync",
+    "export2",
+    "export",
+    "domain",
+    "_events",
+    "rawListeners",
+    "_maxListeners",
+    "setMaxListeners",
+    "getMaxListeners",
+    "emit",
+    "addListener",
+    "on",
+    "prependListener",
+    "once",
+    "prependOnceListener",
+    "removeListener",
+    "removeAllListeners",
+    "listeners",
+    "listenerCount",
+    "eventNames",
+    "_data", "path", "name", "children", "parents", "_inherits", "_extends", "_isa",
+    "_hasa", "_relations", "_references", "_created", "_metas",
+    "_rootname", "exportSerialised"
+]
+
+module.exports = uberfactory;

+ 17 - 0
index.js

@@ -0,0 +1,17 @@
+var electra = require("./electra2020");
+var slugger = function(str) {
+    var ret = ("" + str).replace(/\/+/g, '/').replace(/[^\x20-\x7E]/g, '')
+        //  ret=decodeURIComponent(ret);
+    ret = ret.replace(/[\<\>]/g, '')
+    if (ret.indexOf("/") == ret.length - 1) {
+        ret = ret.substring(0, ret.length - 1);
+    }
+    return ret
+}
+var nb = require("buffa");
+
+
+
+module.exports = function(name) {
+    return electra(uuid, slugger)(name)
+}

+ 18 - 0
package.json

@@ -0,0 +1,18 @@
+{
+  "name": "eles",
+  "version": "1.0.0",
+  "description": "",
+  "main": "index.js",
+  "scripts": {
+    "test": "echo \"Error: no test specified\" && exit 1"
+  },
+  "repository": {
+    "type": "git",
+    "url": "ssh://git@git.tum.dk/tum.dk/eles.git"
+  },
+  "author": "",
+  "license": "ISC",
+  "dependencies": {
+    "buffa": "git+ssh://git@git.tum.dk/tum.dk/buffa.git"
+  }
+}

+ 399 - 0
test1.js

@@ -0,0 +1,399 @@
+var tool = require("../../clienta")({});
+tool.JSZip = require("jszip");
+tool = require("../lib_src")(tool)
+require("../lib_src1")(tool)
+tool.fs = require("fs-extra");
+
+
+var cmdline = require('repl').start();
+
+for (var i in tool) {
+    global[i] = tool[i];
+    cmdline.context[i] = tool[i];
+}
+
+var fetch = require("node-fetch");
+tool.system = require("../system");
+var oo = require("../system")(tool)
+    //{root: tool.electra(tool.uuid, tool.slugify)("moon")};
+
+var bobo = require("../system")(tool)
+    //
+
+$lib.oo = oo;
+$lib.bobo = bobo;
+
+$lib.loadJS = function(url, callback) {
+    $lib.getAddData(fetch, url, function(str) {
+        var arr = [];
+        var ss = str.split(",\n");
+        ss[0] = ss[0].split("\n").pop();
+        ss.push(ss.pop().split('\n\n]);').shift())
+        ss.map(function(s, ii) {
+            s = s.trim();
+            if (s.substring(0, 1) !== "{") {
+                return
+            }
+            var t;
+            try {
+                t = JSON.parse(s);
+            } catch (e) {
+                console.log(e, s, ii);
+            }
+            if (t) {
+                arr.push(t);
+            }
+        })
+        callback(url, arr);
+    })
+}
+
+
+
+function doleala() {
+    async.mapSeries(("2018 2009 2010 2011 2012 2013 2014 2015 2016 2017").split(" "), function(y, nex) {
+        $lib.loadJS("https://lokal.iske.dk/ex/m/" + y + ".js", function(name, arr) {
+            console.log("url ", name, "loaded", arr.length);
+            $lib.addData2(name, arr, oo)
+            console.log($lib.status());
+            nex()
+        })
+    }, function(err, aa) {
+
+        $lib.testere();
+
+    })
+}
+
+
+$lib.loadara = function loadara(filepath) {
+
+
+    return new Promise(function(resolve, reject) {
+        var rda = fs.readFileSync(filepath)
+        $lib.unpack_thezip(rda)
+            .then(function(obj) {
+                async.mapSeries(obj, function(obja, next) {
+                    console.log(obja.name, obja._rootname)
+                    $lib.rev_conv(obja)
+                    next()
+                }, function(err, done) {
+                    console.log("DONE")
+                    console.log($lib.status());
+                    resolve()
+                })
+
+
+            })
+
+
+    })
+
+
+}
+
+
+
+
+
+
+
+
+$lib.testere = function tester() {
+    $lib.exporter(oo, function(err, data) {
+        $lib.generate_thezip($lib.arrayedToObject(data, "name"), function(err, zz) {
+            console.log(err);
+            console.log(zz.filename, zz.blob)
+            fs.writeFileSync("./" + zz.filename, zz.blob);
+
+
+
+
+            var rda = fs.readFileSync("./" + zz.filename)
+
+            console.log("LLLLLLL", rda.length)
+
+
+
+            $lib.unpack_thezip(rda, function(err, obj) {
+
+                //console.log("OBJ",err,obj);
+
+
+                async.mapSeries(obj, function(obja, next) {
+                    console.log(obja.name, obja._rootname)
+
+                    /*         var roo = oo[obja._rootname]
+                    var dis = roo(obja.name);
+
+                    $lib.rev_conv(obja)
+             */
+
+
+
+                    next()
+                }, function(err, done) {
+                    console.log("DONE")
+                })
+
+
+            })
+
+
+
+        })
+    })
+}
+
+
+
+$lib.blabla = function() {
+    var ini = 0;
+    var arr = [];
+    oo.media().withAll(function(obj, next) {
+        if (obj._metas.amazonS3_info) {
+            var urla = obj._metas.amazonS3_info.key
+            arr.push([obj.path, "https://a.raeson.dk/" + urla]);
+            next()
+        } else {
+            next()
+        }
+    }, function() {
+        console.log("LLLL", arr.length);
+
+        async.mapSeries(arr.slice(0, 1), $lib.convertone, function(err, res) {
+            console.log("FON", err, res)
+        })
+
+    })
+}
+$lib.convertone = function(one, next) {
+    fetch("https://lokal.iske.dk/f/" + one[1])
+        .then(resp => resp.blob())
+        .then(function(blob) {
+            console.log("BBBB", blob)
+            next(null, "")
+
+        })
+
+}
+
+
+/*$lib.loadara("./root-2018-08-08-03-58.zip")
+    .then(function(){
+        console.log("LLLLLLLLLLLLLLLL",arguments);
+    })
+*/
+
+var oa = $lib.apage($lib.oo);
+
+cmdline.context.oa = oa;
+
+function aah() {
+    fs.readFile("/home/jb/repos/aserver-test/jjk.zip")
+        .then($lib.unpack_thezip)
+        .then($lib.loadSiteWithObj(oa))
+        .then(function() {
+            _.keys(oo).filter(function(k) {
+                return k !== "_creater" && typeof(oo[k]) === "function"
+            }).map(function(k) {
+                console.log(oo[k]().isroot ? "r" : " ", _.padEnd(oo[k]()._rootname, 10), "oo." + k);
+
+            })
+
+            /*          oa.oget("posts/20939").isa(oa.oget("cat/1"))
+            oa.oget("posts/20939").inherits(oa.oget("bla/1"))
+            oa.oget("posts/20939").extends(oa.oget("dex/1"))
+
+            oa.oget("mixcat/1").isa(oa.oget("posts/20939"))
+
+
+            oa.omove("posts/20939", "posts/year/2000/20939")
+
+            // console.log(oa.oget("media/images/10168")._relations)
+
+
+            console.log(oa.oget("posts/20939"))
+            console.log(oa.oget("posts/year/2000/20939")._hasa)
+*/
+
+
+            oa.oget("pages/test")
+                .extends(oa.oget("pages/demo"));
+
+            oa.ofind("pages/data");
+
+            oa.oget("system/serializers").serializers = $lib.serializers
+
+
+
+
+
+            oa.oget("pages/test")
+                .unextends(oa.oget("pages/demo"))
+
+
+            oa.oget("pages/test")
+                .isa(oa.oget("system/1"), oa.oget("system/2"), oa.oget("system/3"))
+
+
+            console.log(oa.oget("pages/test"))
+
+
+            oa.oget("pages/test")
+                .unisa(oa.oget("system/1"), oa.oget("system/2"), oa.oget("system/3"))
+            console.log(oa.oget("pages/test"))
+
+            oa.oset("bgbgbg/test/._data.title", "Hello there cruel world")
+
+
+            oa.oget("pages/test")._xkey = {
+                "tester": "tete",
+                "func":function tta(){console.log("tta")},
+                "key": {
+                    "key": "blblb",
+                    "private": "sdsf"
+                }
+            }
+
+
+            oa.oget("pages/test").exportSerialised($lib.serialisers)("", function(err, all) {
+                console.log("LLLLLLLLL", all, "llllllllll");
+
+            })
+
+
+
+            $lib.exporter(oa,function(err,all){
+              //  console.log("ALLLL",JSON.stringify(all,true,2))
+
+
+            })
+
+
+            oa.oget("bgbgbg").withAll(function(obj, next) {
+                next(null, obj)
+            }, function(e, alle) {
+
+
+
+                //console.log(alle);
+
+
+
+
+
+
+            })
+
+
+
+            console.log("DOM")
+        }).then(function() {
+
+
+        }).catch(function() {
+            console.log("ERR", arguments)
+        })
+
+}
+
+
+aah();
+
+/*
+fetch("https://lokal.iske.dk/Raeson.zip")
+    .then(res => res.arrayBuffer())
+    .then($lib.unpack_thezip)
+    .then($lib.loadSiteWithObj(oa))
+    .then(console.log)
+    .catch(console.log)
+*/
+
+
+
+
+
+//loadara(function() {
+//    $lib.blabla();
+//})
+
+/*_.keys(oo).map(function(k){
+ //   console.log(oo[k]().isroot?"r":" ", _.padEnd(oo[k]()._rootname,10), "oo."+k    );
+    var obj=oo[k]();
+    if(!obj.isroot){
+        obj.export("",function(err,all){
+            files[k] = all;
+        })
+    }
+
+})
+*/
+
+
+
+
+
+
+
+
+
+try {
+    if (process.env.GIO_LAUNCHED_DESKTOP_FILE.indexOf("sublime") > -1) {
+        console.log("Auto kill in 30 sec");
+        setTimeout(function() {
+            process.exit()
+        }, 30000)
+
+    } else {
+        console.log("READY");
+    }
+} catch (e) {
+    console.log("READY");
+}
+
+
+
+
+
+
+
+
+// console.log("OA", oa, pp)
+/*        oa.save()
+        .then(function(data){
+            console.log(data)
+            fs.writeFileSync(data.filename, data.blob)
+        })
+*/
+
+
+//          console.log(oa.oget("authors/1")._relations)
+//        console.log(oa.oget("media/images/11679")._relations)
+
+
+//var name = "system/posts/the test demo danan/lklkd/æøå/dsfs !!!"
+//name = "system%2Fposts%2Fthe%20test%20demo%20danan%2Flklkd%2F%C3%A6%C3%B8%C3%A5%2Fdsfs%20!!!"
+//name= name.replace(/[^0-9a-zA-Z\.\_\/]/g,'')
+
+//console.log("name",name )
+//console.log("slug",sluggi(name))
+
+//console.log("escape",escape(name))
+//console.log("url", decodeURIComponent(name)  )
+
+
+//console.log( oa.oget("system/test<>/dfdf") )
+
+
+/*    var str = oa.oo().exportSync("");
+         fs.writeFileSync("./ff.json", JSON.stringify(str,true,2))
+
+        var arr = oa.oo().exportFlatSync("");
+
+        var str = "[\n"+arr.map(function(a){
+            return JSON.stringify(a)
+        }).join(",\n")+"\n]";
+
+         fs.writeFileSync("./ffa.json", str)
+*/